🐛 Avoid crash when applying a token with no active value

This commit is contained in:
Andrés Moya 2025-03-03 09:56:00 +01:00 committed by Andrés Moya
parent c807e37525
commit f06f11ad7a

View file

@ -107,24 +107,26 @@
(defn update-shape-radius-all (defn update-shape-radius-all
([value shape-ids attributes] (update-shape-radius-all value shape-ids attributes nil)) ([value shape-ids attributes] (update-shape-radius-all value shape-ids attributes nil))
([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions ([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions
(dwsh/update-shapes shape-ids (when (number? value)
(fn [shape] (dwsh/update-shapes shape-ids
(ctsr/set-radius-to-all-corners shape value)) (fn [shape]
{:reg-objects? true (ctsr/set-radius-to-all-corners shape value))
:ignore-touched true {:reg-objects? true
:page-id page-id :ignore-touched true
:attrs ctt/border-radius-keys}))) :page-id page-id
:attrs ctt/border-radius-keys}))))
(defn update-shape-radius-for-corners (defn update-shape-radius-for-corners
([value shape-ids attributes] (update-shape-radius-for-corners value shape-ids attributes nil)) ([value shape-ids attributes] (update-shape-radius-for-corners value shape-ids attributes nil))
([value shape-ids attributes page-id] ([value shape-ids attributes page-id]
(dwsh/update-shapes shape-ids (when (number? value)
(fn [shape] (dwsh/update-shapes shape-ids
(ctsr/set-radius-for-corners shape attributes value)) (fn [shape]
{:reg-objects? true (ctsr/set-radius-for-corners shape attributes value))
:ignore-touched true {:reg-objects? true
:page-id page-id :ignore-touched true
:attrs ctt/border-radius-keys}))) :page-id page-id
:attrs ctt/border-radius-keys}))))
(defn update-opacity (defn update-opacity
([value shape-ids attributes] (update-opacity value shape-ids attributes nil)) ([value shape-ids attributes] (update-opacity value shape-ids attributes nil))
@ -145,23 +147,25 @@
(ptk/reify ::update-shape-rotation (ptk/reify ::update-shape-rotation
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (when (number? value)
(udw/trigger-bounding-box-cloaking shape-ids) (rx/of
(udw/increase-rotation shape-ids value nil (udw/trigger-bounding-box-cloaking shape-ids)
{:page-id page-id (udw/increase-rotation shape-ids value nil
:ignore-touched true})))))) {:page-id page-id
:ignore-touched true})))))))
(defn update-stroke-width (defn update-stroke-width
([value shape-ids attributes] (update-stroke-width value shape-ids attributes nil)) ([value shape-ids attributes] (update-stroke-width value shape-ids attributes nil))
([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions ([value shape-ids _attributes page-id] ; The attributes param is needed to have the same arity that other update functions
(dwsh/update-shapes shape-ids (when (number? value)
(fn [shape] (dwsh/update-shapes shape-ids
(when (seq (:strokes shape)) (fn [shape]
(assoc-in shape [:strokes 0 :stroke-width] value))) (when (seq (:strokes shape))
{:reg-objects? true (assoc-in shape [:strokes 0 :stroke-width] value)))
:ignore-touched true {:reg-objects? true
:page-id page-id :ignore-touched true
:attrs [:strokes]}))) :page-id page-id
:attrs [:strokes]}))))
(defn update-color [f value shape-ids page-id] (defn update-color [f value shape-ids page-id]
(when-let [tc (tinycolor/valid-color value)] (when-let [tc (tinycolor/valid-color value)]
@ -220,9 +224,10 @@
(ptk/reify ::update-shape-dimensions (ptk/reify ::update-shape-dimensions
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/of (when (number? value)
(when (:width attributes) (dwt/update-dimensions shape-ids :width value {:ignore-touched true :page-id page-id})) (rx/of
(when (:height attributes) (dwt/update-dimensions shape-ids :height value {:ignore-touched true :page-id page-id}))))))) (when (:width attributes) (dwt/update-dimensions shape-ids :width value {:ignore-touched true :page-id page-id}))
(when (:height attributes) (dwt/update-dimensions shape-ids :height value {:ignore-touched true :page-id page-id}))))))))
(defn- attributes->layout-gap [attributes value] (defn- attributes->layout-gap [attributes value]
(let [layout-gap (-> (set/intersection attributes #{:column-gap :row-gap}) (let [layout-gap (-> (set/intersection attributes #{:column-gap :row-gap})
@ -248,12 +253,13 @@
(ptk/reify ::update-layout-item-margin (ptk/reify ::update-layout-item-margin
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [ids-with-layout-parent (shape-ids-with-layout-parent state (or page-id (:current-page-id state)) shape-ids)] (when (number? value)
(rx/of (let [ids-with-layout-parent (shape-ids-with-layout-parent state (or page-id (:current-page-id state)) shape-ids)]
(dwsl/update-layout ids-with-layout-parent (rx/of
{:layout-item-margin (zipmap attrs (repeat value))} (dwsl/update-layout ids-with-layout-parent
{:ignore-touched true {:layout-item-margin (zipmap attrs (repeat value))}
:page-id page-id}))))))) {:ignore-touched true
:page-id page-id}))))))))
(defn update-layout-padding (defn update-layout-padding
([value shape-ids attrs] (update-layout-padding value shape-ids attrs nil)) ([value shape-ids attrs] (update-layout-padding value shape-ids attrs nil))
@ -261,12 +267,13 @@
(ptk/reify ::update-layout-padding (ptk/reify ::update-layout-padding
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [ids-with-layout (shape-ids-with-layout state (or page-id (:current-page-id state)) shape-ids)] (when (number? value)
(rx/of (let [ids-with-layout (shape-ids-with-layout state (or page-id (:current-page-id state)) shape-ids)]
(dwsl/update-layout ids-with-layout (rx/of
{:layout-padding (zipmap attrs (repeat value))} (dwsl/update-layout ids-with-layout
{:ignore-touched true {:layout-padding (zipmap attrs (repeat value))}
:page-id page-id}))))))) {:ignore-touched true
:page-id page-id}))))))))
(defn update-layout-spacing (defn update-layout-spacing
([value shape-ids attributes] (update-layout-spacing value shape-ids attributes nil)) ([value shape-ids attributes] (update-layout-spacing value shape-ids attributes nil))
@ -274,13 +281,14 @@
(ptk/reify ::update-layout-spacing (ptk/reify ::update-layout-spacing
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [ids-with-layout (shape-ids-with-layout state (or page-id (:current-page-id state)) shape-ids) (when (number? value)
layout-attributes (attributes->layout-gap attributes value)] (let [ids-with-layout (shape-ids-with-layout state (or page-id (:current-page-id state)) shape-ids)
(rx/of layout-attributes (attributes->layout-gap attributes value)]
(dwsl/update-layout ids-with-layout (rx/of
layout-attributes (dwsl/update-layout ids-with-layout
{:ignore-touched true layout-attributes
:page-id page-id}))))))) {:ignore-touched true
:page-id page-id}))))))))
(defn update-shape-position (defn update-shape-position
([value shape-ids attributes] (update-shape-position value shape-ids attributes nil)) ([value shape-ids attributes] (update-shape-position value shape-ids attributes nil))
@ -288,8 +296,9 @@
(ptk/reify ::update-shape-position (ptk/reify ::update-shape-position
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(rx/concat (when (number? value)
(map #(dwt/update-position % (zipmap attributes (repeat value)) {:ignore-touched true :page-id page-id}) shape-ids)))))) (rx/concat
(map #(dwt/update-position % (zipmap attributes (repeat value)) {:ignore-touched true :page-id page-id}) shape-ids)))))))
(defn update-layout-sizing-limits (defn update-layout-sizing-limits
([value shape-ids attributes] (update-layout-sizing-limits value shape-ids attributes nil)) ([value shape-ids attributes] (update-layout-sizing-limits value shape-ids attributes nil))
@ -297,14 +306,15 @@
(ptk/reify ::update-layout-sizing-limits (ptk/reify ::update-layout-sizing-limits
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(let [props (-> {:layout-item-min-w value (when (number? value)
:layout-item-min-h value (let [props (-> {:layout-item-min-w value
:layout-item-max-w value :layout-item-min-h value
:layout-item-max-h value} :layout-item-max-w value
(select-keys attributes))] :layout-item-max-h value}
(rx/of (select-keys attributes))]
(dwsl/update-layout-child shape-ids props {:ignore-touched true (rx/of
:page-id page-id}))))))) (dwsl/update-layout-child shape-ids props {:ignore-touched true
:page-id page-id}))))))))
;; Token Types ----------------------------------------------------------------- ;; Token Types -----------------------------------------------------------------