🐛 Fix text shape edition mode.

This commit is contained in:
Andrey Antukh 2019-08-24 12:41:11 +02:00
parent eebd56d738
commit 5af263c70e

View file

@ -39,30 +39,25 @@
(declare text-shape-wrapper) (declare text-shape-wrapper)
(declare text-shape-edit) (declare text-shape-edit)
(mf/def text-component (mf/defc text-component
:mixins [mf/memo mf/reactive] [{:keys [shape] :as props}]
:render (let [{:keys [id x1 y1 content group]} shape
(fn [own {:keys [shape] :as props}] selected (mf/deref refs/selected-shapes)
(let [{:keys [id x1 y1 content group]} shape edition (mf/deref refs/selected-edition)
modifiers (mf/react (refs/selected-modifiers id)) edition? (= edition id)
selected (mf/react refs/selected-shapes) selected? (and (contains? selected id)
edition? (= (mf/react refs/selected-edition) id) (= (count selected) 1))]
selected? (and (contains? selected id) (letfn [(on-mouse-down [event]
(= (count selected) 1)) (handle-mouse-down event shape selected))
shape (assoc shape :modifiers modifiers)] (on-double-click [event]
(letfn [(on-mouse-down [event] (dom/stop-propagation event)
(handle-mouse-down event shape selected)) (st/emit! (udw/start-edition-mode id)))]
(on-double-click [event] [:g.shape {:class (when selected? "selected")
;; TODO: handle grouping event propagation :on-double-click on-double-click
;; TODO: handle actions locking properly :on-mouse-down on-mouse-down}
(dom/stop-propagation event) (if edition?
(st/emit! (udw/start-edition-mode id)))] [:& text-shape-edit {:shape shape}]
[:g.shape {:class (when selected? "selected") [:& text-shape-wrapper {:shape shape}])])))
:on-double-click on-double-click
:on-mouse-down on-mouse-down}
(if edition?
[:& text-shape-edit {:shape shape}]
[:& text-shape-wrapper {:shape shape}])]))))
;; --- Text Styles Helpers ;; --- Text Styles Helpers