mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 07:46:38 +02:00
commit
ac2310f71f
21 changed files with 172 additions and 125 deletions
|
@ -1003,21 +1003,6 @@
|
||||||
:operations ops2
|
:operations ops2
|
||||||
:id (:id curr)})))))))))
|
:id (:id curr)})))))))))
|
||||||
|
|
||||||
;; --- Update Dimensions
|
|
||||||
|
|
||||||
;; Event mainly used for handling user modification of the size of the
|
|
||||||
;; object from workspace sidebar options inputs.
|
|
||||||
|
|
||||||
(defn update-dimensions
|
|
||||||
[ids attr value]
|
|
||||||
(us/verify (s/coll-of ::us/uuid) ids)
|
|
||||||
(us/verify #{:width :height} attr)
|
|
||||||
(us/verify ::us/number value)
|
|
||||||
(ptk/reify ::update-dimensions
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ state stream]
|
|
||||||
(rx/of (dwc/update-shapes ids #(gsh/resize-rect % attr value) {:reg-objects? true})))))
|
|
||||||
|
|
||||||
;; --- Shape Proportions
|
;; --- Shape Proportions
|
||||||
|
|
||||||
(defn set-shape-proportion-lock
|
(defn set-shape-proportion-lock
|
||||||
|
@ -1348,10 +1333,10 @@
|
||||||
:height height
|
:height height
|
||||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||||
:content (as-content text)})]
|
:content (as-content text)})]
|
||||||
(rx/of dwc/start-undo-transaction
|
(rx/of (dwc/start-undo-transaction)
|
||||||
(dws/deselect-all)
|
(dws/deselect-all)
|
||||||
(dwc/add-shape shape)
|
(dwc/add-shape shape)
|
||||||
dwc/commit-undo-transaction)))))
|
(dwc/commit-undo-transaction))))))
|
||||||
|
|
||||||
(defn- image-uploaded
|
(defn- image-uploaded
|
||||||
[image]
|
[image]
|
||||||
|
@ -1610,6 +1595,7 @@
|
||||||
(d/export dwt/set-rotation)
|
(d/export dwt/set-rotation)
|
||||||
(d/export dwt/set-modifiers)
|
(d/export dwt/set-modifiers)
|
||||||
(d/export dwt/apply-modifiers)
|
(d/export dwt/apply-modifiers)
|
||||||
|
(d/export dwt/update-dimensions)
|
||||||
|
|
||||||
;; Persistence
|
;; Persistence
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,7 @@
|
||||||
|
|
||||||
(defonce empty-tx {:undo-changes [] :redo-changes []})
|
(defonce empty-tx {:undo-changes [] :redo-changes []})
|
||||||
|
|
||||||
(def start-undo-transaction
|
(defn start-undo-transaction []
|
||||||
(ptk/reify ::start-undo-transaction
|
(ptk/reify ::start-undo-transaction
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -297,13 +297,13 @@
|
||||||
(cond-> state
|
(cond-> state
|
||||||
(nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx))))))
|
(nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx))))))
|
||||||
|
|
||||||
(def discard-undo-transaction
|
(defn discard-undo-transaction []
|
||||||
(ptk/reify ::discard-undo-transaction
|
(ptk/reify ::discard-undo-transaction
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update state :workspace-undo dissoc :transaction))))
|
(update state :workspace-undo dissoc :transaction))))
|
||||||
|
|
||||||
(def commit-undo-transaction
|
(defn commit-undo-transaction []
|
||||||
(ptk/reify ::commit-undo-transaction
|
(ptk/reify ::commit-undo-transaction
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
;; Add & select the created shape to the workspace
|
;; Add & select the created shape to the workspace
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(if (= :text (:type shape))
|
(if (= :text (:type shape))
|
||||||
(rx/of dwc/start-undo-transaction)
|
(rx/of (dwc/start-undo-transaction))
|
||||||
(rx/empty))
|
(rx/empty))
|
||||||
|
|
||||||
(rx/of (dws/deselect-all)
|
(rx/of (dws/deselect-all)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
[app.common.geom.shapes :as geom]
|
[app.common.geom.shapes :as geom]
|
||||||
[app.common.attrs :as attrs]
|
[app.common.attrs :as attrs]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.transforms :as dwt]
|
||||||
[app.main.fonts :as fonts]
|
[app.main.fonts :as fonts]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.text :as ut]))
|
[app.util.text :as ut]))
|
||||||
|
@ -210,3 +211,44 @@
|
||||||
(and (= 1 (count selected))
|
(and (= 1 (count selected))
|
||||||
(= (-> selected first :type) :text))
|
(= (-> selected first :type) :text))
|
||||||
(assoc-in [:workspace-local :edition] (-> selected first :id)))))))
|
(assoc-in [:workspace-local :edition] (-> selected first :id)))))))
|
||||||
|
|
||||||
|
(defn resize-text [id new-width new-height]
|
||||||
|
(ptk/reify ::resize-text
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [page-id (:current-page-id state)
|
||||||
|
shape (get-in state [:workspace-data :pages-index page-id :objects id])
|
||||||
|
{:keys [selrect grow-type overflow-text]} shape
|
||||||
|
{shape-width :width shape-height :height} selrect
|
||||||
|
undo-transaction (get-in state [:workspace-undo :transaction])
|
||||||
|
|
||||||
|
events (when (and (> new-width 0) (> new-height 0))
|
||||||
|
(cond
|
||||||
|
(and overflow-text (not= :fixed grow-type))
|
||||||
|
[(update-overflow-text id false)]
|
||||||
|
|
||||||
|
(and (= :fixed grow-type) (not overflow-text) (> new-height shape-height))
|
||||||
|
[(update-overflow-text id true)]
|
||||||
|
|
||||||
|
(and (= :fixed grow-type) overflow-text (<= new-height shape-height))
|
||||||
|
[(update-overflow-text id false)]
|
||||||
|
|
||||||
|
(and (or (not= shape-width new-width)
|
||||||
|
(not= shape-height new-height))
|
||||||
|
(= grow-type :auto-width))
|
||||||
|
(when (and (pos? shape-width)
|
||||||
|
(pos? shape-height))
|
||||||
|
[(dwt/update-dimensions [id] :width new-width)
|
||||||
|
(dwt/update-dimensions [id] :height new-height)])
|
||||||
|
|
||||||
|
(and (not= shape-height new-height) (= grow-type :auto-height))
|
||||||
|
(when (pos? shape-height)
|
||||||
|
[(dwt/update-dimensions [id] :height new-height)])))]
|
||||||
|
|
||||||
|
(if (not (empty? events))
|
||||||
|
(rx/concat
|
||||||
|
(when (not undo-transaction)
|
||||||
|
(rx/of (dwc/start-undo-transaction)))
|
||||||
|
(rx/from events)
|
||||||
|
(when (not undo-transaction)
|
||||||
|
(rx/of (dwc/discard-undo-transaction)))))))))
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
[app.common.pages-helpers :as cph]
|
[app.common.pages-helpers :as cph]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.main.data.workspace.common :as dwc]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.snap :as snap]
|
[app.main.snap :as snap]
|
||||||
|
@ -266,7 +265,7 @@
|
||||||
(when-not (empty? rch)
|
(when-not (empty? rch)
|
||||||
(rx/of dwc/pop-undo-into-transaction
|
(rx/of dwc/pop-undo-into-transaction
|
||||||
(dwc/commit-changes rch uch {:commit-local? true})
|
(dwc/commit-changes rch uch {:commit-local? true})
|
||||||
dwc/commit-undo-transaction
|
(dwc/commit-undo-transaction)
|
||||||
(dwc/expand-collapse frame-id)))))))
|
(dwc/expand-collapse frame-id)))))))
|
||||||
|
|
||||||
(defn start-move
|
(defn start-move
|
||||||
|
@ -472,6 +471,22 @@
|
||||||
rchanges (conj (dwc/generate-changes page-id objects1 objects2) regchg)
|
rchanges (conj (dwc/generate-changes page-id objects1 objects2) regchg)
|
||||||
uchanges (conj (dwc/generate-changes page-id objects2 objects0) regchg)]
|
uchanges (conj (dwc/generate-changes page-id objects2 objects0) regchg)]
|
||||||
|
|
||||||
(rx/of dwc/start-undo-transaction
|
(rx/of (dwc/start-undo-transaction)
|
||||||
(dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
dwc/commit-undo-transaction)))))
|
(dwc/commit-undo-transaction))))))
|
||||||
|
|
||||||
|
;; --- Update Dimensions
|
||||||
|
|
||||||
|
;; Event mainly used for handling user modification of the size of the
|
||||||
|
;; object from workspace sidebar options inputs.
|
||||||
|
|
||||||
|
(defn update-dimensions
|
||||||
|
[ids attr value]
|
||||||
|
(us/verify (s/coll-of ::us/uuid) ids)
|
||||||
|
(us/verify #{:width :height} attr)
|
||||||
|
(us/verify ::us/number value)
|
||||||
|
(ptk/reify ::update-dimensions
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
#_(prn "??? update-dimensions" ids attr value)
|
||||||
|
(rx/of (dwc/update-shapes ids #(gsh/resize-rect % attr value) {:reg-objects? true})))))
|
||||||
|
|
|
@ -152,8 +152,8 @@
|
||||||
[ids]
|
[ids]
|
||||||
(l/derived (fn [objects]
|
(l/derived (fn [objects]
|
||||||
(into [] (comp (map #(get objects %))
|
(into [] (comp (map #(get objects %))
|
||||||
(filter identity))
|
(remove nil?))
|
||||||
(set ids)))
|
ids))
|
||||||
workspace-page-objects =))
|
workspace-page-objects =))
|
||||||
|
|
||||||
(defn is-child-selected?
|
(defn is-child-selected?
|
||||||
|
|
|
@ -214,3 +214,10 @@
|
||||||
(mf/use-effect (fn []
|
(mf/use-effect (fn []
|
||||||
(let [sub (->> stream (rx/subs on-subscribe))]
|
(let [sub (->> stream (rx/subs on-subscribe))]
|
||||||
#(rx/dispose! sub)))))
|
#(rx/dispose! sub)))))
|
||||||
|
|
||||||
|
;; https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
|
||||||
|
(defn use-previous [value]
|
||||||
|
(let [ref (mf/use-ref)]
|
||||||
|
(mf/use-effect
|
||||||
|
#(mf/set-ref-val! ref value))
|
||||||
|
(mf/ref-val ref)))
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[app.main.ui.shapes.attrs :as attrs]
|
[app.main.ui.shapes.attrs :as attrs]
|
||||||
[app.util.debug :refer [debug?]]
|
|
||||||
[app.common.geom.shapes :as geom]))
|
[app.common.geom.shapes :as geom]))
|
||||||
|
|
||||||
(def mask-id-ctx (mf/create-context nil))
|
(def mask-id-ctx (mf/create-context nil))
|
||||||
|
@ -32,7 +31,6 @@
|
||||||
childs (if (and (:masked-group? shape) (not expand-mask))
|
childs (if (and (:masked-group? shape) (not expand-mask))
|
||||||
(rest childs)
|
(rest childs)
|
||||||
childs)
|
childs)
|
||||||
is-child-selected? (unchecked-get props "is-child-selected?")
|
|
||||||
{:keys [id x y width height]} shape
|
{:keys [id x y width height]} shape
|
||||||
transform (geom/transform-matrix shape)]
|
transform (geom/transform-matrix shape)]
|
||||||
[:g
|
[:g
|
||||||
|
@ -48,13 +46,6 @@
|
||||||
[:& shape-wrapper {:frame frame
|
[:& shape-wrapper {:frame frame
|
||||||
:shape item
|
:shape item
|
||||||
:key (:id item)}])]
|
:key (:id item)}])]
|
||||||
(when (not is-child-selected?)
|
])))
|
||||||
[:rect {:transform transform
|
|
||||||
:x x
|
|
||||||
:y y
|
|
||||||
:fill (if (debug? :group) "red" "transparent")
|
|
||||||
:opacity 0.5
|
|
||||||
:width width
|
|
||||||
:height height}])])))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
group-props (-> (obj/clone props)
|
group-props (-> (obj/clone props)
|
||||||
(obj/without ["shape" "children"])
|
(obj/without ["shape" "children"])
|
||||||
(obj/set! "id" (str "shape-" (:id shape)))
|
(obj/set! "id" (str "shape-" (:id shape)))
|
||||||
(obj/set! "className" "shape")
|
(obj/set! "className" (str "shape " (:type shape)))
|
||||||
(obj/set! "filter" (filters/filter-str filter-id shape)))]
|
(obj/set! "filter" (filters/filter-str filter-id shape)))]
|
||||||
[:& (mf/provider muc/render-ctx) {:value render-id}
|
[:& (mf/provider muc/render-ctx) {:value render-id}
|
||||||
[:> :g group-props
|
[:> :g group-props
|
||||||
|
|
|
@ -100,6 +100,7 @@
|
||||||
:width (if (#{:auto-width} grow-type) 10000 width)
|
:width (if (#{:auto-width} grow-type) 10000 width)
|
||||||
:height (if (#{:auto-height :auto-width} grow-type) 10000 height)
|
:height (if (#{:auto-height :auto-width} grow-type) 10000 height)
|
||||||
:mask mask-id
|
:mask mask-id
|
||||||
:ref ref}
|
:ref ref
|
||||||
|
:pointer-events "none"}
|
||||||
[:& text-content {:shape shape
|
[:& text-content {:shape shape
|
||||||
:content (:content shape)}]]))
|
:content (:content shape)}]]))
|
||||||
|
|
|
@ -71,10 +71,10 @@
|
||||||
do-detach-component #(st/emit! (dwl/detach-component id))
|
do-detach-component #(st/emit! (dwl/detach-component id))
|
||||||
do-reset-component #(st/emit! (dwl/reset-component id))
|
do-reset-component #(st/emit! (dwl/reset-component id))
|
||||||
do-update-component #(do
|
do-update-component #(do
|
||||||
(st/emit! dwc/start-undo-transaction)
|
(st/emit! (dwc/start-undo-transaction))
|
||||||
(st/emit! (dwl/update-component id))
|
(st/emit! (dwl/update-component id))
|
||||||
(st/emit! (dwl/sync-file nil))
|
(st/emit! (dwl/sync-file nil))
|
||||||
(st/emit! dwc/commit-undo-transaction))
|
(st/emit! (dwc/commit-undo-transaction)))
|
||||||
do-show-component #(st/emit! (dw/go-to-layout :assets))
|
do-show-component #(st/emit! (dw/go-to-layout :assets))
|
||||||
do-navigate-component-file #(st/emit! (dwl/nav-to-component-file
|
do-navigate-component-file #(st/emit! (dwl/nav-to-component-file
|
||||||
(:component-file shape)))]
|
(:component-file shape)))]
|
||||||
|
|
|
@ -60,11 +60,10 @@
|
||||||
nil
|
nil
|
||||||
|
|
||||||
(= type :frame)
|
(= type :frame)
|
||||||
(if selected?
|
(when selected?
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(st/emit! (dw/start-move-selected)))
|
(st/emit! (dw/start-move-selected))))
|
||||||
(st/emit! (dw/deselect-all)))
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
[app.main.ui.shapes.shape :refer [shape-container]]
|
[app.main.ui.shapes.shape :refer [shape-container]]
|
||||||
[app.main.ui.workspace.effects :as we]
|
[app.main.ui.workspace.effects :as we]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.util.debug :refer [debug?]]))
|
||||||
|
|
||||||
(defn- group-wrapper-factory-equals?
|
(defn- group-wrapper-factory-equals?
|
||||||
[np op]
|
[np op]
|
||||||
|
@ -46,6 +48,9 @@
|
||||||
(let [shape (unchecked-get props "shape")
|
(let [shape (unchecked-get props "shape")
|
||||||
frame (unchecked-get props "frame")
|
frame (unchecked-get props "frame")
|
||||||
|
|
||||||
|
{:keys [id x y width height]} shape
|
||||||
|
transform (gsh/transform-matrix shape)
|
||||||
|
|
||||||
childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape)))
|
childs-ref (mf/use-memo (mf/deps shape) #(refs/objects-by-id (:shapes shape)))
|
||||||
childs (mf/deref childs-ref)
|
childs (mf/deref childs-ref)
|
||||||
|
|
||||||
|
@ -69,16 +74,26 @@
|
||||||
handle-pointer-leave (we/use-pointer-leave shape)
|
handle-pointer-leave (we/use-pointer-leave shape)
|
||||||
handle-double-click (use-double-click shape)]
|
handle-double-click (use-double-click shape)]
|
||||||
|
|
||||||
[:> shape-container {:shape shape
|
[:> shape-container {:shape shape}
|
||||||
:on-mouse-down handle-mouse-down
|
[:g.group-shape
|
||||||
:on-context-menu handle-context-menu
|
|
||||||
:on-pointer-enter handle-pointer-enter
|
|
||||||
:on-pointer-leave handle-pointer-leave
|
|
||||||
:on-double-click handle-double-click}
|
|
||||||
[:& group-shape
|
[:& group-shape
|
||||||
{:frame frame
|
{:frame frame
|
||||||
:shape shape
|
:shape shape
|
||||||
:childs childs
|
:childs childs
|
||||||
:is-child-selected? is-child-selected?
|
:expand-mask is-mask-selected?}]
|
||||||
:expand-mask is-mask-selected?}]]))))
|
|
||||||
|
(when-not is-child-selected?
|
||||||
|
[:rect.group-actions
|
||||||
|
{:x x
|
||||||
|
:y y
|
||||||
|
:fill (if (debug? :group) "red" "transparent")
|
||||||
|
:opacity 0.5
|
||||||
|
:transform transform
|
||||||
|
:width width
|
||||||
|
:height height
|
||||||
|
:on-mouse-down handle-mouse-down
|
||||||
|
:on-context-menu handle-context-menu
|
||||||
|
:on-pointer-enter handle-pointer-enter
|
||||||
|
:on-pointer-leave handle-pointer-leave
|
||||||
|
:on-double-click handle-double-click}])]]))))
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,15 @@
|
||||||
[app.main.ui.workspace.shapes.common :as common]
|
[app.main.ui.workspace.shapes.common :as common]
|
||||||
[app.main.ui.workspace.shapes.text.editor :as editor]
|
[app.main.ui.workspace.shapes.text.editor :as editor]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
|
[app.util.logging :as log]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.timers :as timers]
|
[app.util.timers :as timers]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
|
;; Change this to :info :debug or :trace to debug this module
|
||||||
|
(log/set-level! :warn)
|
||||||
|
|
||||||
;; --- Events
|
;; --- Events
|
||||||
|
|
||||||
(defn use-double-click [{:keys [id]} selected?]
|
(defn use-double-click [{:keys [id]} selected?]
|
||||||
|
@ -41,56 +45,10 @@
|
||||||
|
|
||||||
;; --- Text Wrapper for workspace
|
;; --- Text Wrapper for workspace
|
||||||
|
|
||||||
(defn handle-shape-resize
|
|
||||||
[{:keys [id selrect grow-type overflow-text]} new-width new-height]
|
|
||||||
(let [{shape-width :width shape-height :height} selrect
|
|
||||||
undo-transaction (get-in @st/state [:workspace-undo :transaction])]
|
|
||||||
(when (not undo-transaction) (st/emit! dwc/start-undo-transaction))
|
|
||||||
(when (and (> new-width 0) (> new-height 0))
|
|
||||||
(cond
|
|
||||||
(and overflow-text (not= :fixed grow-type))
|
|
||||||
(st/emit! (dwt/update-overflow-text id false))
|
|
||||||
|
|
||||||
(and (= :fixed grow-type) (not overflow-text) (> new-height shape-height))
|
|
||||||
(st/emit! (dwt/update-overflow-text id true))
|
|
||||||
|
|
||||||
(and (= :fixed grow-type) overflow-text (<= new-height shape-height))
|
|
||||||
(st/emit! (dwt/update-overflow-text id false))
|
|
||||||
|
|
||||||
(and (or (not= shape-width new-width)
|
|
||||||
(not= shape-height new-height))
|
|
||||||
(= grow-type :auto-width))
|
|
||||||
(when (and (pos? shape-width)
|
|
||||||
(pos? shape-height))
|
|
||||||
(st/emit! (dw/update-dimensions [id] :width new-width)
|
|
||||||
(dw/update-dimensions [id] :height new-height)))
|
|
||||||
|
|
||||||
(and (not= shape-height new-height) (= grow-type :auto-height))
|
|
||||||
(when (pos? shape-height)
|
|
||||||
(st/emit! (dw/update-dimensions [id] :height new-height)))))
|
|
||||||
(when (not undo-transaction) (st/emit! dwc/discard-undo-transaction))))
|
|
||||||
|
|
||||||
(defn resize-observer [{:keys [id selrect grow-type overflow-text] :as shape} root query]
|
|
||||||
(mf/use-effect
|
|
||||||
(mf/deps id selrect grow-type overflow-text root query)
|
|
||||||
(fn []
|
|
||||||
(let [on-change (fn [entries]
|
|
||||||
(when (seq entries)
|
|
||||||
;; RequestAnimationFrame so the "loop limit error" error is not thrown
|
|
||||||
;; https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
|
|
||||||
(timers/raf
|
|
||||||
#(let [width (obj/get-in entries [0 "contentRect" "width"])
|
|
||||||
height (obj/get-in entries [0 "contentRect" "height"])]
|
|
||||||
(handle-shape-resize shape (mth/ceil width) (mth/ceil height))))))
|
|
||||||
observer (js/ResizeObserver. on-change)
|
|
||||||
node (when root (dom/query root query))]
|
|
||||||
(when node (.observe observer node))
|
|
||||||
#(.disconnect observer)))))
|
|
||||||
|
|
||||||
(mf/defc text-wrapper
|
(mf/defc text-wrapper
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
[props]
|
[props]
|
||||||
(let [{:keys [id x y width height] :as shape} (unchecked-get props "shape")
|
(let [{:keys [id name x y width height] :as shape} (unchecked-get props "shape")
|
||||||
selected-iref (mf/use-memo (mf/deps (:id shape))
|
selected-iref (mf/use-memo (mf/deps (:id shape))
|
||||||
#(refs/make-selected-ref (:id shape)))
|
#(refs/make-selected-ref (:id shape)))
|
||||||
selected? (mf/deref selected-iref)
|
selected? (mf/deref selected-iref)
|
||||||
|
@ -109,21 +67,50 @@
|
||||||
handle-pointer-leave (we/use-pointer-leave shape)
|
handle-pointer-leave (we/use-pointer-leave shape)
|
||||||
handle-double-click (use-double-click shape selected?)
|
handle-double-click (use-double-click shape selected?)
|
||||||
|
|
||||||
text-ref (mf/use-ref nil)
|
paragraph-ref (mf/use-state nil)
|
||||||
text-node (mf/ref-val text-ref)]
|
|
||||||
|
|
||||||
(resize-observer shape text-node ".paragraph-set")
|
handle-resize-text
|
||||||
|
(mf/use-callback
|
||||||
|
(mf/deps id)
|
||||||
|
(fn [entries]
|
||||||
|
(when (seq entries)
|
||||||
|
;; RequestAnimationFrame so the "loop limit error" error is not thrown
|
||||||
|
;; https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
|
||||||
|
(timers/raf
|
||||||
|
#(let [width (obj/get-in entries [0 "contentRect" "width"])
|
||||||
|
height (obj/get-in entries [0 "contentRect" "height"])]
|
||||||
|
(st/emit! (dwt/resize-text id (mth/ceil width) (mth/ceil height))))))))
|
||||||
|
|
||||||
|
text-ref-cb
|
||||||
|
(mf/use-callback
|
||||||
|
(mf/deps handle-resize-text)
|
||||||
|
(fn [node]
|
||||||
|
(when node
|
||||||
|
(let [obs-ref (atom nil)]
|
||||||
|
(timers/schedule
|
||||||
|
(fn []
|
||||||
|
(when-let [ps-node (dom/query node ".paragraph-set")]
|
||||||
|
(reset! paragraph-ref ps-node))))))))]
|
||||||
|
|
||||||
|
(mf/use-effect
|
||||||
|
(mf/deps @paragraph-ref handle-resize-text)
|
||||||
|
(fn []
|
||||||
|
(when-let [paragraph-node @paragraph-ref]
|
||||||
|
(let [observer (js/ResizeObserver. handle-resize-text)]
|
||||||
|
(log/debug :msg "Attach resize observer" :shape-id id :shape-name name)
|
||||||
|
(.observe observer paragraph-node)
|
||||||
|
#(.disconnect observer)))))
|
||||||
|
|
||||||
[:> shape-container {:shape shape}
|
[:> shape-container {:shape shape}
|
||||||
;; We keep hidden the shape when we're editing so it keeps track of the size
|
;; We keep hidden the shape when we're editing so it keeps track of the size
|
||||||
;; and updates the selrect acordingly
|
;; and updates the selrect acordingly
|
||||||
[:g.text-shape {:opacity (when edition? 0)}
|
[:g.text-shape {:opacity (when edition? 0)}
|
||||||
[:& text/text-shape {:key "text-shape"
|
[:& text/text-shape {:key (str "text-shape" (:id shape))
|
||||||
:ref text-ref
|
:ref text-ref-cb
|
||||||
:shape shape
|
:shape shape
|
||||||
:selected? selected?}]]
|
:selected? selected?}]]
|
||||||
(when edition?
|
(when edition?
|
||||||
[:& editor/text-shape-edit {:key "editor"
|
[:& editor/text-shape-edit {:key (str "editor" (:id shape))
|
||||||
:shape shape}])
|
:shape shape}])
|
||||||
|
|
||||||
(when-not edition?
|
(when-not edition?
|
||||||
|
|
|
@ -204,11 +204,11 @@
|
||||||
(let [lkey1 (events/listen (dom/get-root) EventType.CLICK on-click-outside)
|
(let [lkey1 (events/listen (dom/get-root) EventType.CLICK on-click-outside)
|
||||||
lkey2 (events/listen (dom/get-root) EventType.KEYUP on-key-up)]
|
lkey2 (events/listen (dom/get-root) EventType.KEYUP on-key-up)]
|
||||||
(st/emit! (dwt/assign-editor id editor)
|
(st/emit! (dwt/assign-editor id editor)
|
||||||
dwc/start-undo-transaction)
|
(dwc/start-undo-transaction))
|
||||||
|
|
||||||
#(do
|
#(do
|
||||||
(st/emit! (dwt/assign-editor id nil)
|
(st/emit! (dwt/assign-editor id nil)
|
||||||
dwc/commit-undo-transaction)
|
(dwc/commit-undo-transaction))
|
||||||
(events/unlistenByKey lkey1)
|
(events/unlistenByKey lkey1)
|
||||||
(events/unlistenByKey lkey2))))
|
(events/unlistenByKey lkey2))))
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,10 @@
|
||||||
do-detach-component #(st/emit! (dwl/detach-component id))
|
do-detach-component #(st/emit! (dwl/detach-component id))
|
||||||
do-reset-component #(st/emit! (dwl/reset-component id))
|
do-reset-component #(st/emit! (dwl/reset-component id))
|
||||||
do-update-component #(do
|
do-update-component #(do
|
||||||
(st/emit! dwc/start-undo-transaction)
|
(st/emit! (dwc/start-undo-transaction))
|
||||||
(st/emit! (dwl/update-component id))
|
(st/emit! (dwl/update-component id))
|
||||||
(st/emit! (dwl/sync-file nil))
|
(st/emit! (dwl/sync-file nil))
|
||||||
(st/emit! dwc/commit-undo-transaction))
|
(st/emit! (dwc/commit-undo-transaction)))
|
||||||
do-show-component #(st/emit! (dw/go-to-layout :assets))
|
do-show-component #(st/emit! (dw/go-to-layout :assets))
|
||||||
do-navigate-component-file #(st/emit! (dwl/nav-to-component-file
|
do-navigate-component-file #(st/emit! (dwl/nav-to-component-file
|
||||||
(:component-file values)))]
|
(:component-file values)))]
|
||||||
|
|
|
@ -81,13 +81,13 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps ids)
|
(mf/deps ids)
|
||||||
(fn [value opacity id file-id]
|
(fn [value opacity id file-id]
|
||||||
(st/emit! dwc/start-undo-transaction)))
|
(st/emit! (dwc/start-undo-transaction))))
|
||||||
|
|
||||||
on-close-picker
|
on-close-picker
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps ids)
|
(mf/deps ids)
|
||||||
(fn [value opacity id file-id]
|
(fn [value opacity id file-id]
|
||||||
(st/emit! dwc/commit-undo-transaction)))]
|
(st/emit! (dwc/commit-undo-transaction))))]
|
||||||
|
|
||||||
(if show?
|
(if show?
|
||||||
[:div.element-set
|
[:div.element-set
|
||||||
|
|
|
@ -34,12 +34,12 @@
|
||||||
on-open
|
on-open
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps page-id)
|
(mf/deps page-id)
|
||||||
#(st/emit! dwc/start-undo-transaction))
|
#(st/emit! (dwc/start-undo-transaction)))
|
||||||
|
|
||||||
on-close
|
on-close
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps page-id)
|
(mf/deps page-id)
|
||||||
#(st/emit! dwc/commit-undo-transaction))]
|
#(st/emit! (dwc/commit-undo-transaction)))]
|
||||||
|
|
||||||
[:div.element-set
|
[:div.element-set
|
||||||
[:div.element-set-title (t locale "workspace.options.canvas-background")]
|
[:div.element-set-title (t locale "workspace.options.canvas-background")]
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
[app.util.color :as uc]
|
[app.util.color :as uc]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
|
[app.main.ui.hooks :as h]
|
||||||
[app.main.ui.components.color-bullet :as cb]
|
[app.main.ui.components.color-bullet :as cb]
|
||||||
[app.main.ui.components.numeric-input :refer [numeric-input]]))
|
[app.main.ui.components.numeric-input :refer [numeric-input]]))
|
||||||
|
|
||||||
|
@ -120,12 +121,15 @@
|
||||||
disable-opacity
|
disable-opacity
|
||||||
handle-pick-color
|
handle-pick-color
|
||||||
handle-open
|
handle-open
|
||||||
handle-close)))]
|
handle-close)))
|
||||||
|
|
||||||
|
prev-color (h/use-previous color)]
|
||||||
|
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps color)
|
(mf/deps color prev-color)
|
||||||
(fn []
|
(fn []
|
||||||
(modal/update-props! :colorpicker {:data (parse-color color)})))
|
(when (not= prev-color color)
|
||||||
|
(modal/update-props! :colorpicker {:data (parse-color color)}))))
|
||||||
|
|
||||||
[:div.row-flex.color-data
|
[:div.row-flex.color-data
|
||||||
[:& cb/color-bullet {:color color
|
[:& cb/color-bullet {:color color
|
||||||
|
|
|
@ -172,8 +172,8 @@
|
||||||
(:color value))
|
(:color value))
|
||||||
:disable-gradient true
|
:disable-gradient true
|
||||||
:on-change (update-color index)
|
:on-change (update-color index)
|
||||||
:on-open #(st/emit! dwc/start-undo-transaction)
|
:on-open #(st/emit! (dwc/start-undo-transaction))
|
||||||
:on-close #(st/emit! dwc/commit-undo-transaction)}]]]]))
|
:on-close #(st/emit! (dwc/commit-undo-transaction))}]]]]))
|
||||||
(mf/defc shadow-menu
|
(mf/defc shadow-menu
|
||||||
[{:keys [ids values] :as props}]
|
[{:keys [ids values] :as props}]
|
||||||
|
|
||||||
|
|
|
@ -116,13 +116,13 @@
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps ids)
|
(mf/deps ids)
|
||||||
(fn [value opacity id file-id]
|
(fn [value opacity id file-id]
|
||||||
(st/emit! dwc/start-undo-transaction)))
|
(st/emit! (dwc/start-undo-transaction))))
|
||||||
|
|
||||||
on-close-picker
|
on-close-picker
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(mf/deps ids)
|
(mf/deps ids)
|
||||||
(fn [value opacity id file-id]
|
(fn [value opacity id file-id]
|
||||||
(st/emit! dwc/commit-undo-transaction)))]
|
(st/emit! (dwc/commit-undo-transaction))))]
|
||||||
|
|
||||||
(if show-options
|
(if show-options
|
||||||
[:div.element-set
|
[:div.element-set
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue