mirror of
https://github.com/penpot/penpot.git
synced 2025-07-04 22:37:17 +02:00
🐛 Refactor shape attrs updating.
This commit is contained in:
parent
6d6e0ecd21
commit
e84a462dde
2 changed files with 35 additions and 28 deletions
|
@ -607,6 +607,11 @@
|
||||||
[id attrs]
|
[id attrs]
|
||||||
(us/verify ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/verify ::shape-attrs attrs)
|
(us/verify ::shape-attrs attrs)
|
||||||
|
(letfn [(update-shape [shape]
|
||||||
|
(cond-> (merge shape attrs)
|
||||||
|
(and (= :text (:type shape))
|
||||||
|
(string? (:fill-color attrs)))
|
||||||
|
(dwtxt/impl-update-shape-attrs {:fill (:fill-color attrs)})))]
|
||||||
(ptk/reify ::update-shape
|
(ptk/reify ::update-shape
|
||||||
dwc/IBatchedChange
|
dwc/IBatchedChange
|
||||||
dwc/IUpdateGroup
|
dwc/IUpdateGroup
|
||||||
|
@ -618,14 +623,10 @@
|
||||||
grouped #{:frame :group}]
|
grouped #{:frame :group}]
|
||||||
(update-in state [:workspace-data page-id :objects]
|
(update-in state [:workspace-data page-id :objects]
|
||||||
(fn [objects]
|
(fn [objects]
|
||||||
(let [childs (d/concat [id] (helpers/get-children id objects))]
|
(->> (d/concat [id] (helpers/get-children id objects))
|
||||||
(reduce (fn [objects id]
|
(map #(get objects %))
|
||||||
(let [obj (get objects id)]
|
(remove #(grouped (:type %)))
|
||||||
(if (contains? grouped (:type obj))
|
(reduce #(update %1 (:id %2) update-shape) objects)))))))))
|
||||||
objects
|
|
||||||
(update objects id merge attrs))))
|
|
||||||
objects
|
|
||||||
childs))))))))
|
|
||||||
|
|
||||||
;; --- Update Page Options
|
;; --- Update Page Options
|
||||||
|
|
||||||
|
@ -660,11 +661,7 @@
|
||||||
page-id (get-in state [:workspace-page :id])]
|
page-id (get-in state [:workspace-page :id])]
|
||||||
(->> (rx/from selected)
|
(->> (rx/from selected)
|
||||||
(rx/map (fn [id]
|
(rx/map (fn [id]
|
||||||
(let [shape (get-in state [:workspace-data page-id :objects id])]
|
(update-shape-recursive id attrs))))))))
|
||||||
(if (and (string? fill-color)
|
|
||||||
(= :text (:type shape)))
|
|
||||||
(dwtxt/update-text-attrs {:id id :attrs {:fill fill-color}})
|
|
||||||
(update-shape-recursive id attrs))))))))))
|
|
||||||
|
|
||||||
;; --- Shape Movement (using keyboard shorcuts)
|
;; --- Shape Movement (using keyboard shorcuts)
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,20 @@
|
||||||
node
|
node
|
||||||
attrs))
|
attrs))
|
||||||
|
|
||||||
(defn- update-attrs
|
(defn impl-update-shape-attrs
|
||||||
[{:keys [id editor attrs pred split]}]
|
([shape attrs]
|
||||||
|
;; NOTE: this arity is used in workspace for properly update the
|
||||||
|
;; fill color using colorpalette, then the predicate should be
|
||||||
|
;; defined.
|
||||||
|
(impl-update-shape-attrs shape attrs is-text-node?))
|
||||||
|
([{:keys [type content] :as shape} attrs pred]
|
||||||
|
(assert (= :text type) "should be shape type")
|
||||||
|
(let [merge-attrs #(merge-attrs % attrs)]
|
||||||
|
(update shape :content #(transform-nodes pred merge-attrs %)))))
|
||||||
|
|
||||||
|
(defn update-attrs
|
||||||
|
[{:keys [id editor attrs pred split]
|
||||||
|
:or {pred is-text-node?}}]
|
||||||
(if editor
|
(if editor
|
||||||
(ptk/reify ::update-attrs
|
(ptk/reify ::update-attrs
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
|
@ -156,9 +168,7 @@
|
||||||
(let [page-id (get-in state [:workspace-page :id])
|
(let [page-id (get-in state [:workspace-page :id])
|
||||||
merge-attrs #(merge-attrs % attrs)]
|
merge-attrs #(merge-attrs % attrs)]
|
||||||
(update-in state [:workspace-data page-id :objects id]
|
(update-in state [:workspace-data page-id :objects id]
|
||||||
(fn [{:keys [type content] :as shape}]
|
#(impl-update-shape-attrs % attrs pred)))))))
|
||||||
(assert (= :text type) "should be shape type")
|
|
||||||
(update shape :content #(transform-nodes pred merge-attrs %)))))))))
|
|
||||||
|
|
||||||
(defn update-text-attrs
|
(defn update-text-attrs
|
||||||
[options]
|
[options]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue