mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 14:12:36 -05:00
Trying to convert to rx structure
This commit is contained in:
parent
50635ae879
commit
97db3c29ca
2 changed files with 32 additions and 33 deletions
|
@ -20,9 +20,10 @@
|
||||||
[app.main.ui.workspace.tokens.token :as wtt]
|
[app.main.ui.workspace.tokens.token :as wtt]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
|
[beicon.v2.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[promesa.core :as p]
|
[potok.v2.core :as ptk]
|
||||||
[clojure.set :as set]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
;; Helpers ---------------------------------------------------------------------
|
;; Helpers ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -59,31 +60,29 @@
|
||||||
shapes)]
|
shapes)]
|
||||||
(and (empty? with-token) (seq without-token))))
|
(and (empty? with-token) (seq without-token))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn on-add-token [{:keys [token-type-props token shape-ids] :as _props}]
|
(defn on-add-token [{:keys [token-type-props token shape-ids] :as _props}]
|
||||||
(p/let [sd-tokens (sd/resolve-workspace-tokens+)]
|
(ptk/reify ::on-add-token
|
||||||
(let [{:keys [attributes on-update-shape]} token-type-props
|
ptk/WatchEvent
|
||||||
resolved-value (-> (get sd-tokens (:id token))
|
(watch [_ _ _]
|
||||||
(resolve-token-value))
|
(rx/of
|
||||||
tokenized-attributes (->> (map (fn [attr] {attr (:id token)}) attributes)
|
(p/resolved 1)
|
||||||
(into {}))]
|
(dch/update-shapes shape-ids (fn [shape] (assoc shape :applied-tokens {:rx (:id token)})))))))
|
||||||
(st/emit!
|
|
||||||
(dch/update-shapes shape-ids (fn [shape] (update shape :applied-tokens merge tokenized-attributes))))
|
|
||||||
(on-update-shape resolved-value shape-ids attributes))))
|
|
||||||
|
|
||||||
(def remove-keys #(apply dissoc %1 %2))
|
|
||||||
|
|
||||||
(defn on-remove-token [{:keys [token-type-props shapes] :as _props}]
|
|
||||||
(st/emit!
|
|
||||||
(dch/update-shapes (map :id shapes)
|
|
||||||
(fn [shape]
|
|
||||||
(update shape :applied-tokens remove-keys (:attributes token-type-props))))))
|
|
||||||
|
|
||||||
(defn on-toggle-token
|
(defn on-toggle-token
|
||||||
[{:keys [token-type-props token shapes] :as props}]
|
[{:keys [token-type-props token shapes] :as props}]
|
||||||
(let [remove-tokens? (wtt/shapes-token-applied? token shapes (:attributes token-type-props))]
|
(ptk/reify ::on-toggle-token
|
||||||
(if remove-tokens?
|
ptk/WatchEvent
|
||||||
(on-remove-token props)
|
(watch [it state _]
|
||||||
(on-add-token (assoc props :shape-ids (map :id shapes))))))
|
(let [remove-tokens? (wtt/shapes-token-applied? token shapes (:attributes token-type-props))
|
||||||
|
shape-ids (map :id shapes)]
|
||||||
|
(if remove-tokens?
|
||||||
|
(rx/of (dch/update-shapes shape-ids (fn [shape] (assoc shape :applied-tokens {}))))
|
||||||
|
(rx/of (on-add-token (assoc props :shape-ids shape-ids))))))))
|
||||||
|
|
||||||
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
(defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}]
|
||||||
(let [{:keys [attributes on-apply on-update-shape]
|
(let [{:keys [attributes on-apply on-update-shape]
|
||||||
|
@ -103,13 +102,12 @@
|
||||||
(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]
|
(defn update-shape-radius [value shape-ids]
|
||||||
(st/emit!
|
(dch/update-shapes shape-ids
|
||||||
(dch/update-shapes shape-ids
|
(fn [shape]
|
||||||
(fn [shape]
|
(when (ctsr/has-radius? shape)
|
||||||
(when (ctsr/has-radius? shape)
|
(ctsr/set-radius-1 shape value)))
|
||||||
(ctsr/set-radius-1 shape value)))
|
{:reg-objects? true
|
||||||
{:reg-objects? true
|
:attrs ctt/border-radius-keys}))
|
||||||
:attrs ctt/border-radius-keys})))
|
|
||||||
|
|
||||||
(defn update-shape-dimensions [value shape-ids]
|
(defn update-shape-dimensions [value shape-ids]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
|
|
|
@ -99,9 +99,10 @@
|
||||||
(mf/deps selected-shapes token-type-props)
|
(mf/deps selected-shapes token-type-props)
|
||||||
(fn [event token]
|
(fn [event token]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(wtc/on-toggle-token {:token token
|
(st/emit!
|
||||||
:shapes selected-shapes
|
(wtc/on-toggle-token {:token token
|
||||||
:token-type-props token-type-props})))
|
:shapes selected-shapes
|
||||||
|
:token-type-props token-type-props}))))
|
||||||
tokens-count (count tokens)]
|
tokens-count (count tokens)]
|
||||||
[:div {:on-click on-toggle-open-click}
|
[:div {:on-click on-toggle-open-click}
|
||||||
[:& cmm/asset-section {:icon (mf/fnc icon-wrapper [_]
|
[:& cmm/asset-section {:icon (mf/fnc icon-wrapper [_]
|
||||||
|
|
Loading…
Add table
Reference in a new issue