mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 19:21:37 +02:00
🐛 Change to patch-object
This commit is contained in:
parent
3db04e1e2b
commit
caee3160f2
3 changed files with 59 additions and 27 deletions
|
@ -223,20 +223,6 @@
|
||||||
([data]
|
([data]
|
||||||
(into {} (without-nils) data)))
|
(into {} (without-nils) data)))
|
||||||
|
|
||||||
(defn without-nils-deep
|
|
||||||
"Given a map remove the `nil` values and when a child map is found
|
|
||||||
recursively removes them as well."
|
|
||||||
[data]
|
|
||||||
(let [data (without-nils
|
|
||||||
(c/update-vals
|
|
||||||
data
|
|
||||||
(fn [value]
|
|
||||||
(cond-> value
|
|
||||||
(map? value)
|
|
||||||
(without-nils-deep)))))]
|
|
||||||
(when (not-empty? data)
|
|
||||||
data)))
|
|
||||||
|
|
||||||
(defn without-qualified
|
(defn without-qualified
|
||||||
([]
|
([]
|
||||||
(remove (comp qualified-keyword? key)))
|
(remove (comp qualified-keyword? key)))
|
||||||
|
@ -251,6 +237,36 @@
|
||||||
(persistent! (reduce dissoc! (transient data) keys))
|
(persistent! (reduce dissoc! (transient data) keys))
|
||||||
(reduce dissoc data keys)))
|
(reduce dissoc data keys)))
|
||||||
|
|
||||||
|
(defn patch-object
|
||||||
|
"Changes is some attributes that need to change in object.
|
||||||
|
When the attribute is nil it will be removed.
|
||||||
|
|
||||||
|
For example
|
||||||
|
- object: {:a 1 :b {:foo 1 :bar 2} :c 10}
|
||||||
|
- changes: {:a 2 :b {:foo nil :k 3}}
|
||||||
|
- result: {:a 2 :b {:bar 2 :k 3} :c 10}
|
||||||
|
"
|
||||||
|
([changes]
|
||||||
|
#(patch-object % changes))
|
||||||
|
|
||||||
|
([object changes]
|
||||||
|
(->> changes
|
||||||
|
(reduce-kv
|
||||||
|
(fn [object key value]
|
||||||
|
(cond
|
||||||
|
(map? value)
|
||||||
|
(update object key patch-object value)
|
||||||
|
|
||||||
|
(and (nil? value) (record? object))
|
||||||
|
(assoc object key nil)
|
||||||
|
|
||||||
|
(nil? value)
|
||||||
|
(dissoc object key value)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(assoc object key value)))
|
||||||
|
object))))
|
||||||
|
|
||||||
(defn remove-at-index
|
(defn remove-at-index
|
||||||
"Takes a vector and returns a vector with an element in the
|
"Takes a vector and returns a vector with an element in the
|
||||||
specified index removed."
|
specified index removed."
|
||||||
|
|
|
@ -369,7 +369,7 @@
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(let [undo-id (js/Symbol)]
|
(let [undo-id (js/Symbol)]
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(dwc/update-shapes ids #(d/deep-merge % changes))
|
(dwc/update-shapes ids (d/patch-object changes))
|
||||||
(ptk/data-event :layout/update ids)
|
(ptk/data-event :layout/update ids)
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
||||||
|
@ -553,9 +553,10 @@
|
||||||
parent-ids (->> ids (map #(cph/get-parent-id objects %)))
|
parent-ids (->> ids (map #(cph/get-parent-id objects %)))
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(dwc/update-shapes ids #(d/without-nils-deep (d/deep-merge (or % {}) changes)))
|
(dwc/update-shapes ids (d/patch-object changes))
|
||||||
(dwc/update-shapes children-ids (partial fix-child-sizing objects changes))
|
(dwc/update-shapes children-ids (partial fix-child-sizing objects changes))
|
||||||
(dwc/update-shapes parent-ids
|
(dwc/update-shapes
|
||||||
|
parent-ids
|
||||||
(fn [parent]
|
(fn [parent]
|
||||||
(-> parent
|
(-> parent
|
||||||
(fix-parent-sizing objects (set ids) changes)
|
(fix-parent-sizing objects (set ids) changes)
|
||||||
|
@ -577,10 +578,12 @@
|
||||||
[layout-id]
|
[layout-id]
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(->> ids
|
(->> ids
|
||||||
(reduce (fn [shape cell-id]
|
(reduce
|
||||||
(-> shape
|
(fn [shape cell-id]
|
||||||
(d/update-in-when [:layout-grid-cells cell-id]
|
(d/update-in-when
|
||||||
#(d/without-nils (merge % props)))))
|
shape
|
||||||
|
[:layout-grid-cells cell-id]
|
||||||
|
d/patch-object props))
|
||||||
shape))))
|
shape))))
|
||||||
(ptk/data-event :layout/update [layout-id])
|
(ptk/data-event :layout/update [layout-id])
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
|
@ -525,6 +525,7 @@
|
||||||
:on-focus #(do
|
:on-focus #(do
|
||||||
(dom/select-target %)
|
(dom/select-target %)
|
||||||
(select-paddings true false true false))
|
(select-paddings true false true false))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value p1}]]
|
:value p1}]]
|
||||||
[:div {:class (stl/css :padding-simple)
|
[:div {:class (stl/css :padding-simple)
|
||||||
|
@ -539,6 +540,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-paddings false true false true))
|
(select-paddings false true false true))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value p2}]]]
|
:value p2}]]]
|
||||||
(= padding-type :multiple)
|
(= padding-type :multiple)
|
||||||
|
@ -555,6 +557,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-padding :p1))
|
(select-padding :p1))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:p1 (:layout-padding values))}]]
|
:value (:p1 (:layout-padding values))}]]
|
||||||
|
|
||||||
|
@ -569,6 +572,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-padding :p2))
|
(select-padding :p2))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:p2 (:layout-padding values))}]]
|
:value (:p2 (:layout-padding values))}]]
|
||||||
|
|
||||||
|
@ -583,6 +587,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-padding :p3))
|
(select-padding :p3))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:p3 (:layout-padding values))}]]
|
:value (:p3 (:layout-padding values))}]]
|
||||||
|
|
||||||
|
@ -597,6 +602,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-padding :p4))
|
(select-padding :p4))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:p4 (:layout-padding values))}]]])]
|
:value (:p4 (:layout-padding values))}]]])]
|
||||||
[:button {:class (stl/css-case :padding-toggle true
|
[:button {:class (stl/css-case :padding-toggle true
|
||||||
|
@ -618,6 +624,7 @@
|
||||||
:on-focus #(do
|
:on-focus #(do
|
||||||
(dom/select-target %)
|
(dom/select-target %)
|
||||||
(select-paddings true false true false))
|
(select-paddings true false true false))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value p1}]]
|
:value p1}]]
|
||||||
|
|
||||||
|
@ -630,6 +637,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-paddings false true false true))
|
(select-paddings false true false true))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value p2}]]]
|
:value p2}]]]
|
||||||
|
|
||||||
|
@ -650,6 +658,7 @@
|
||||||
:on-focus #(do (dom/select-target %)
|
:on-focus #(do (dom/select-target %)
|
||||||
(select-padding num))
|
(select-padding num))
|
||||||
:on-blur #(select-paddings false false false false)
|
:on-blur #(select-paddings false false false false)
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (num (:layout-padding values))}]]])])
|
:value (num (:layout-padding values))}]]])])
|
||||||
|
|
||||||
|
@ -691,6 +700,7 @@
|
||||||
:on-blur (fn [_]
|
:on-blur (fn [_]
|
||||||
(select-gap nil)
|
(select-gap nil)
|
||||||
(reset! gap-selected? :none))
|
(reset! gap-selected? :none))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:row-gap gap-value)
|
:value (:row-gap gap-value)
|
||||||
:disabled (and (= :nowrap wrap-type) (not is-col?))}]]
|
:disabled (and (= :nowrap wrap-type) (not is-col?))}]]
|
||||||
|
@ -710,6 +720,7 @@
|
||||||
:on-blur (fn [_]
|
:on-blur (fn [_]
|
||||||
(select-gap nil)
|
(select-gap nil)
|
||||||
(reset! gap-selected? :none))
|
(reset! gap-selected? :none))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:column-gap gap-value)
|
:value (:column-gap gap-value)
|
||||||
:disabled (and (= :nowrap wrap-type) is-col?)}]]]
|
:disabled (and (= :nowrap wrap-type) is-col?)}]]]
|
||||||
|
@ -731,6 +742,7 @@
|
||||||
:on-blur (fn [_]
|
:on-blur (fn [_]
|
||||||
(select-gap nil)
|
(select-gap nil)
|
||||||
(reset! gap-selected? :none))
|
(reset! gap-selected? :none))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:column-gap gap-value)
|
:value (:column-gap gap-value)
|
||||||
:disabled (and (= :nowrap wrap-type) is-col?)}]]
|
:disabled (and (= :nowrap wrap-type) is-col?)}]]
|
||||||
|
@ -749,6 +761,7 @@
|
||||||
:on-blur (fn [_]
|
:on-blur (fn [_]
|
||||||
(select-gap nil)
|
(select-gap nil)
|
||||||
(reset! gap-selected? :none))
|
(reset! gap-selected? :none))
|
||||||
|
:nillable true
|
||||||
:min 0
|
:min 0
|
||||||
:value (:row-gap gap-value)
|
:value (:row-gap gap-value)
|
||||||
:disabled (and (= :nowrap wrap-type) (not is-col?))}]]]])))
|
:disabled (and (= :nowrap wrap-type) (not is-col?))}]]]])))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue