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