0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-01 11:59:17 -05:00
This commit is contained in:
Florian Schroedl 2024-07-04 14:31:50 +02:00
parent 55713275b6
commit 785961f7c6

View file

@ -42,31 +42,59 @@
(->> (vals tokens) (->> (vals tokens)
(group-by :type))) (group-by :type)))
(defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] (defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}]
(->> (wtt/token-names-map tokens) (->> (wtt/token-names-map tokens)
(map (fn [[_k {:keys [name] :as item}]] (map (fn [[_k {:keys [name] :as item}]]
(cond-> (assoc item :label name) (cond-> (assoc item :label name)
(wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true)))))) (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true))))))
;; Update functions ------------------------------------------------------------ ;; Shape Update Functions ------------------------------------------------------
(defn apply-tokens? (defn update-shape-radius [value shape-ids]
[{:keys [attributes token shapes] :as _props}] (dch/update-shapes shape-ids
(let [{:keys [with-token without-token]} (group-by (fn [shape]
(fn [shape] (when (ctsr/has-radius? shape)
(if (wtt/shapes-token-applied? token shape attributes) (ctsr/set-radius-1 shape value)))
:with-token {:reg-objects? true
:without-token)) :attrs ctt/border-radius-keys}))
shapes)]
(and (empty? with-token) (seq without-token))))
(defn done (defn update-shape-dimensions [value shape-ids]
[] (ptk/reify ::update-shape-dimensions
(ptk/reify ::done
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of :the/end)))) (rx/of
(dwt/update-dimensions shape-ids :width value)
(dwt/update-dimensions shape-ids :height value)))))
(defn update-opacity [value shape-ids]
(dch/update-shapes shape-ids #(assoc % :opacity value)))
(defn update-stroke-width
[value shape-ids]
(st/emit!
(dch/update-shapes shape-ids (fn [shape]
(when (seq (:strokes shape))
(assoc-in shape [:strokes 0 :stroke-width] value))))))
(defn update-rotation [value shape-ids]
(ptk/reify ::update-shape-dimensions
ptk/WatchEvent
(watch [_ _ _]
(rx/of
(udw/trigger-bounding-box-cloaking shape-ids)
(udw/increase-rotation shape-ids value)))))
(defn update-layout-spacing-column [value shape-ids]
(doseq [shape-id shape-ids]
(let [shape (dt/get-shape-from-state shape-id @st/state)
layout-direction (:layout-flex-dir shape)
layout-update (if (or (= layout-direction :row-reverse) (= layout-direction :row))
{:layout-gap {:column-gap value}}
{:layout-gap {:row-gap value}})]
(st/emit!
(dwsl/update-layout [shape-id] layout-update)))))
;; Events ----------------------------------------------------------------------
(defn apply-token (defn apply-token
[{:keys [attributes shape-ids token on-update-shape] :as _props}] [{:keys [attributes shape-ids token on-update-shape] :as _props}]
@ -88,8 +116,6 @@
(on-update-shape resolved-value shape-ids attributes)) (on-update-shape resolved-value shape-ids attributes))
(dwu/commit-undo-transaction undo-id))))))))) (dwu/commit-undo-transaction undo-id)))))))))
(def remove-keys #(apply dissoc %1 %2))
(defn unapply-token (defn unapply-token
"Removes `attributes` that match `token` for `shape-ids`. "Removes `attributes` that match `token` for `shape-ids`.
@ -141,50 +167,6 @@
:attributes attributes})) :attributes attributes}))
(on-update-shape resolved-token-value shape-ids attributes)))))) (on-update-shape resolved-token-value shape-ids attributes))))))
(defn update-shape-radius [value shape-ids]
(dch/update-shapes shape-ids
(fn [shape]
(when (ctsr/has-radius? shape)
(ctsr/set-radius-1 shape value)))
{:reg-objects? true
:attrs ctt/border-radius-keys}))
(defn update-shape-dimensions [value shape-ids]
(ptk/reify ::update-shape-dimensions
ptk/WatchEvent
(watch [_ _ _]
(rx/of
(dwt/update-dimensions shape-ids :width value)
(dwt/update-dimensions shape-ids :height value)))))
(defn update-opacity [value shape-ids]
(dch/update-shapes shape-ids #(assoc % :opacity value)))
(defn update-stroke-width
[value shape-ids]
(st/emit!
(dch/update-shapes shape-ids (fn [shape]
(when (seq (:strokes shape))
(assoc-in shape [:strokes 0 :stroke-width] value))))))
(defn update-rotation [value shape-ids]
(ptk/reify ::update-shape-dimensions
ptk/WatchEvent
(watch [_ _ _]
(rx/of
(udw/trigger-bounding-box-cloaking shape-ids)
(udw/increase-rotation shape-ids value)))))
(defn update-layout-spacing-column [value shape-ids]
(doseq [shape-id shape-ids]
(let [shape (dt/get-shape-from-state shape-id @st/state)
layout-direction (:layout-flex-dir shape)
layout-update (if (or (= layout-direction :row-reverse) (= layout-direction :row))
{:layout-gap {:column-gap value}}
{:layout-gap {:row-gap value}})]
(st/emit!
(dwsl/update-layout [shape-id] layout-update)))))
;; JSON export functions ------------------------------------------------------- ;; JSON export functions -------------------------------------------------------
(defn encode-tokens (defn encode-tokens