feat(frontend): add many adaptations to rumext breaking changes

This commit is contained in:
Andrey Antukh 2019-07-18 12:30:20 +02:00
parent 9ddd9f317d
commit 321c8d14e1
14 changed files with 149 additions and 174 deletions

View file

@ -31,10 +31,10 @@
(mx/defcs image-component
{:mixins [mx/static mx/reactive]
:will-mount (fn [own]
:init (fn [own]
;; TODO: maybe do it conditionally
;; (only fetch when it's not fetched)
(when-let [id (-> own :rum/args first :image)]
(when-let [id (-> own ::mx/props first :image)]
(st/emit! (udi/fetch-image id)))
own)}
[own {:keys [id image] :as shape}]

View file

@ -120,7 +120,6 @@
:cy cy}])
(mx/defc controls
{:mixins [mx/static]}
[{:keys [x1 y1 width height] :as shape} zoom on-mouse-down]
(let [radius (if (> (max width height) handler-size-threshold) 6.0 4.0)]
[:g.controls
@ -226,7 +225,6 @@
(controls selection zoom on-click)))
(mx/defc single-selection-handlers
{:mixins [mx/static]}
[{:keys [id] :as shape} zoom]
(let [on-click #(do (dom/stop-propagation %2)
(start-resize %1 #{id} shape))
@ -247,35 +245,37 @@
:stroke-opacity "0.5"
:fill "transparent"}}]]))
(mx/defc selection-handlers
{:mixins [mx/reactive mx/static]}
[]
(let [shapes (mx/react selected-shapes-ref)
modifiers (mx/react selected-modifers-ref)
;; Edition is a workspace global flag
;; because only one shape can be on
;; the edition mode.
edition? (mx/react refs/selected-edition)
zoom (mx/react refs/selected-zoom)
num (count shapes)
{:keys [id type] :as shape} (first shapes)]
(cond
(zero? num)
nil
(mx/def selection-handlers
:mixins [mx/reactive mx/static]
:render
(fn [own props]
(let [shapes (mx/react selected-shapes-ref)
modifiers (mx/react selected-modifers-ref)
;; Edition is a workspace global flag
;; because only one shape can be on
;; the edition mode.
edition? (mx/react refs/selected-edition)
zoom (mx/react refs/selected-zoom)
num (count shapes)
{:keys [id type] :as shape} (first shapes)]
(> num 1)
(multiple-selection-handlers shapes modifiers zoom)
(cond
(zero? num)
nil
(and (= type :text) edition?)
(-> (assoc shape :modifiers (get modifiers id))
(text-edition-selection-handlers zoom))
(> num 1)
(multiple-selection-handlers shapes modifiers zoom)
(= type :path)
(if (= @refs/selected-edition (:id shape))
(path-edition-selection-handlers shape zoom)
(and (= type :text) edition?)
(-> (assoc shape :modifiers (get modifiers id))
(single-selection-handlers zoom)))
(text-edition-selection-handlers zoom))
:else
(-> (assoc shape :modifiers (get modifiers id))
(single-selection-handlers zoom)))))
(= type :path)
(if (= @refs/selected-edition (:id shape))
(path-edition-selection-handlers shape zoom)
(-> (assoc shape :modifiers (get modifiers id))
(single-selection-handlers zoom)))
:else
(-> (assoc shape :modifiers (get modifiers id))
(single-selection-handlers zoom))))))

View file

@ -106,7 +106,7 @@
(defn- text-shape-edit-did-mount
[own]
(let [[shape] (:rum/args own)
(let [[shape] (::mx/props own)
dom (mx/ref-node own "container")]
(set! (.-textContent dom) (:content shape ""))
(.focus dom)
@ -140,25 +140,15 @@
(defn text-shape-wrapper-did-mount
[own]
(let [[shape] (:rum/args own)
(let [[shape] (::mx/props own)
dom (mx/ref-node own "fobject")
html (dom/render-to-html (text-shape-html shape))]
(set! (.-innerHTML dom) html))
own)
(defn text-shape-wrapper-did-remount
[old own]
(let [[old-shape] (:rum/args old)
[shape] (:rum/args own)]
(when (not= shape old-shape)
(let [dom (mx/ref-node own "fobject")
html (dom/render-to-html (text-shape-html shape))]
(set! (.-innerHTML dom) html)))
own))
(mx/defc text-shape-wrapper
{:did-mount text-shape-wrapper-did-mount
:did-remount text-shape-wrapper-did-remount}
:key-fn #(pr-str %1)}
[{:keys [id modifiers] :as shape}]
(let [{:keys [displacement resize]} modifiers
xfmt (cond-> (gmt/matrix)
@ -188,7 +178,7 @@
(mx/defc text-shape
{:mixins [mx/static]
:did-mount text-shape-wrapper-did-mount
:did-remount text-shape-wrapper-did-remount}
:key-fn #(pr-str %1)}
[{:keys [id content modifiers] :as shape}]
(let [{:keys [displacement resize]} modifiers
xfmt (cond-> (gmt/matrix)