0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

Abstract functions

This commit is contained in:
Florian Schroedl 2024-05-22 16:20:40 +02:00
parent 2eb5efb274
commit 5806ae7426
2 changed files with 7 additions and 3 deletions

View file

@ -6,6 +6,7 @@
(ns app.main.data.tokens (ns app.main.data.tokens
(:require (:require
[app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb] [app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
@ -57,6 +58,9 @@
(->> (map (fn [attr] [attr token-id]) attributes) (->> (map (fn [attr] [attr token-id]) attributes)
(into {}))) (into {})))
(defn unapply-token-id [shape attributes]
(update shape :applied-tokens d/without-keys attributes))
(defn apply-token-id-to-attributes [{:keys [shape token-id attributes]}] (defn apply-token-id-to-attributes [{:keys [shape token-id attributes]}]
(let [token (token-from-attributes token-id attributes)] (let [token (token-from-attributes token-id attributes)]
(toggle-or-apply-token shape token))) (toggle-or-apply-token shape token)))

View file

@ -291,14 +291,14 @@
(on-switch-to-radius-4) (on-switch-to-radius-4)
(on-switch-to-radius-1)))) (on-switch-to-radius-1))))
on-border-radius-token-unlink on-border-radius-token-unapply
(mf/use-fn (mf/use-fn
(mf/deps ids change-radius border-radius-tokens) (mf/deps ids change-radius border-radius-tokens)
(fn [token] (fn [token]
(let [token-value (some-> token wtc/resolve-token-value)] (let [token-value (some-> token wtc/resolve-token-value)]
(st/emit! (st/emit!
(change-radius (fn [shape] (change-radius (fn [shape]
(-> (update shape :applied-tokens d/without-keys #{:rx :ry :r1 :r2 :r3 :r4}) (-> (dt/unapply-token-id shape (wtc/token-attributes :border-radius))
(ctsr/set-radius-1 token-value)))))))) (ctsr/set-radius-1 token-value))))))))
on-radius-1-change on-radius-1-change
@ -498,7 +498,7 @@
[:span {:class (stl/css :icon)} i/corner-radius] [:span {:class (stl/css :icon)} i/corner-radius]
[:& editable-select [:& editable-select
{:placeholder (if (= :multiple (:rx values)) (tr "settings.multiple") "--") {:placeholder (if (= :multiple (:rx values)) (tr "settings.multiple") "--")
:on-token-remove on-border-radius-token-unlink :on-token-remove on-border-radius-token-unapply
:class (stl/css :token-select) :class (stl/css :token-select)
:type "number" :type "number"
:min 0 :min 0