mirror of
https://github.com/penpot/penpot.git
synced 2025-02-01 11:59:17 -05:00
Cleanup
This commit is contained in:
parent
0166c38486
commit
d22234fe2a
1 changed files with 42 additions and 40 deletions
|
@ -8,8 +8,37 @@
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.data :as data]))
|
[clojure.data :as data]))
|
||||||
|
|
||||||
|
;; Constants -------------------------------------------------------------------
|
||||||
|
|
||||||
(def filter-existing-values? false)
|
(def filter-existing-values? false)
|
||||||
|
|
||||||
|
(def attributes->shape-update
|
||||||
|
{#{:rx :ry} wtch/update-shape-radius-single-corner
|
||||||
|
#{:r1 :r2 :r3 :r4} wtch/update-shape-radius-single-corner
|
||||||
|
ctt/stroke-width-keys wtch/update-stroke-width
|
||||||
|
ctt/sizing-keys wtch/update-shape-dimensions
|
||||||
|
ctt/opacity-keys wtch/update-opacity
|
||||||
|
#{:p1 :p2 :p3 :p4} (fn [resolved-value shape-ids attrs]
|
||||||
|
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat resolved-value))}))
|
||||||
|
#{:column-gap :row-gap} wtch/update-layout-spacing
|
||||||
|
#{:width :height} wtch/update-shape-dimensions
|
||||||
|
#{:layout-item-min-w :layout-item-min-h :layout-item-max-w :layout-item-max-h} wtch/update-layout-sizing-limits
|
||||||
|
ctt/rotation-keys wtch/update-rotation})
|
||||||
|
|
||||||
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(defn deep-merge
|
||||||
|
"Like d/deep-merge but unions set values."
|
||||||
|
([a b]
|
||||||
|
(cond
|
||||||
|
(map? a) (merge-with deep-merge a b)
|
||||||
|
(set? a) (set/union a b)
|
||||||
|
:else b))
|
||||||
|
([a b & rest]
|
||||||
|
(reduce deep-merge a (cons b rest))))
|
||||||
|
|
||||||
|
;; Data flows ------------------------------------------------------------------
|
||||||
|
|
||||||
(defn invert-collect-key-vals
|
(defn invert-collect-key-vals
|
||||||
[xs resolved-tokens shape]
|
[xs resolved-tokens shape]
|
||||||
(-> (reduce
|
(-> (reduce
|
||||||
|
@ -47,51 +76,24 @@
|
||||||
(->> (map (fn [[value attrs]] [attrs {value #{object-id}}]) attrs-values-map)
|
(->> (map (fn [[value attrs]] [attrs {value #{object-id}}]) attrs-values-map)
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(defn deep-merge
|
(defn collect-shape-update-info [resolved-tokens shapes]
|
||||||
"Like d/deep-merge but unions set values."
|
(reduce
|
||||||
([a b]
|
(fn [acc [object-id {:keys [applied-tokens] :as shape}]]
|
||||||
(cond
|
(if (seq applied-tokens)
|
||||||
(map? a) (merge-with deep-merge a b)
|
(let [applied-tokens (->
|
||||||
(set? a) (set/union a b)
|
(invert-collect-key-vals applied-tokens resolved-tokens shape)
|
||||||
:else b))
|
(shape-ids-by-values object-id)
|
||||||
([a b & rest]
|
(split-attribute-groups))]
|
||||||
(reduce deep-merge a (cons b rest))))
|
(deep-merge acc applied-tokens))
|
||||||
|
acc))
|
||||||
|
{} shapes))
|
||||||
|
|
||||||
|
|
||||||
(defn update-workspace-tokens []
|
(defn update-workspace-tokens []
|
||||||
(let [resolved-tokens (wtsd/get-cached-tokens @refs/workspace-tokens)]
|
(let [resolved-tokens (wtsd/get-cached-tokens @refs/workspace-tokens)]
|
||||||
(->> @refs/workspace-page-objects
|
(->> @refs/workspace-page-objects
|
||||||
(reduce
|
(collect-shape-update-info resolved-tokens))))
|
||||||
(fn [acc [object-id {:keys [applied-tokens] :as shape}]]
|
|
||||||
(if (seq applied-tokens)
|
|
||||||
(let [applied-tokens (->
|
|
||||||
(invert-collect-key-vals applied-tokens resolved-tokens shape)
|
|
||||||
(shape-ids-by-values object-id)
|
|
||||||
(split-attribute-groups))]
|
|
||||||
(deep-merge acc applied-tokens))
|
|
||||||
acc))
|
|
||||||
{}))))
|
|
||||||
|
|
||||||
(def attributes->shape-update
|
|
||||||
{#{:rx :ry} wtch/update-shape-radius-single-corner
|
|
||||||
#{:r1 :r2 :r3 :r4} wtch/update-shape-radius-single-corner
|
|
||||||
ctt/stroke-width-keys wtch/update-stroke-width
|
|
||||||
ctt/sizing-keys wtch/update-shape-dimensions
|
|
||||||
ctt/opacity-keys wtch/update-opacity
|
|
||||||
#{:p1 :p2 :p3 :p4} (fn [resolved-value shape-ids attrs]
|
|
||||||
(dwsl/update-layout shape-ids {:layout-padding (zipmap attrs (repeat resolved-value))}))
|
|
||||||
#{:column-gap :row-gap} wtch/update-layout-spacing
|
|
||||||
#{:width :height} wtch/update-shape-dimensions
|
|
||||||
#{:layout-item-min-w :layout-item-min-h :layout-item-max-w :layout-item-max-h} wtch/update-layout-sizing-limits
|
|
||||||
ctt/rotation-keys wtch/update-rotation})
|
|
||||||
|
|
||||||
|
|
||||||
(def attributes-collect-by-pairs
|
|
||||||
(reduce
|
|
||||||
(fn [acc [ks _]]
|
|
||||||
(into acc (map (fn [k] [k ks]) ks)))
|
|
||||||
{} attributes->shape-update))
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(update-workspace-tokens)
|
(update-workspace-tokens)
|
||||||
|
|
||||||
nil)
|
nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue