diff --git a/frontend/src/app/plugins/library.cljs b/frontend/src/app/plugins/library.cljs index 21c258e95..5be62fbf2 100644 --- a/frontend/src/app/plugins/library.cljs +++ b/frontend/src/app/plugins/library.cljs @@ -7,9 +7,11 @@ (ns app.plugins.library "RPC for plugins runtime." (:require + [app.common.colors :as cc] [app.common.data :as d] [app.common.data.macros :as dm] [app.common.record :as cr] + [app.main.data.workspace.libraries :as dwl] [app.main.store :as st] [app.plugins.utils :as u])) @@ -53,13 +55,32 @@ {:name "id" :get (fn [_] (dm/str id))} {:name "name" - :get #(-> % u/proxy->library-color :name)} + :get #(-> % u/proxy->library-color :name) + :set + (fn [_ value] + (if (and (some? value) (string? value)) + (st/emit! (dwl/rename-color file-id id value)) + (u/display-not-valid :library-color-name value)))} {:name "color" - :get #(-> % u/proxy->library-color :color)} + :get #(-> % u/proxy->library-color :color) + :set + (fn [self value] + (if (and (some? value) (string? value) (cc/valid-hex-color? value)) + (let [color (-> (u/proxy->library-color self) + (assoc :color value))] + (st/emit! (dwl/update-color color file-id))) + (u/display-not-valid :library-color-color value)))} {:name "opacity" - :get #(-> % u/proxy->library-color :opacity)} + :get #(-> % u/proxy->library-color :opacity) + :set + (fn [self value] + (if (and (some? value) (number? value) (>= value 0) (<= value 1)) + (let [color (-> (u/proxy->library-color self) + (assoc :opacity value))] + (st/emit! (dwl/update-color color file-id))) + (u/display-not-valid :library-color-color value)))} {:name "gradient" :get #(-> % u/proxy->library-color :gradient u/to-js)} @@ -96,8 +117,7 @@ {:name "$id" :enumerable false :get (constantly id)} {:name "$file" :enumerable false :get (constantly file-id)} {:name "id" :get (fn [_] (dm/str id))} - {:name "name" - :get #(-> % u/proxy->library-component :name)})) + {:name "name" :get #(-> % u/proxy->library-component :name)})) (deftype Library [$id] Object) diff --git a/frontend/src/app/plugins/shape.cljs b/frontend/src/app/plugins/shape.cljs index 91f6957ad..7e100d8f7 100644 --- a/frontend/src/app/plugins/shape.cljs +++ b/frontend/src/app/plugins/shape.cljs @@ -160,7 +160,7 @@ (let [id (obj/get self "$id") shape (proxy->shape self)] (when (us/safe-int? value) - (when (ctsr/radius-4? shape) + (when (or (not (ctsr/has-radius? shape)) (ctsr/radius-4? shape)) (st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-1))) (st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-1 % value))))))} @@ -170,7 +170,7 @@ (let [id (obj/get self "$id") shape (proxy->shape self)] (when (us/safe-int? value) - (when (ctsr/radius-4? shape) + (when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape))) (st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4))) (st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r1 value))))))} @@ -180,7 +180,7 @@ (let [id (obj/get self "$id") shape (proxy->shape self)] (when (us/safe-int? value) - (when (ctsr/radius-4? shape) + (when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape))) (st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4))) (st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r2 value))))))} @@ -190,7 +190,7 @@ (let [id (obj/get self "$id") shape (proxy->shape self)] (when (us/safe-int? value) - (when (ctsr/radius-4? shape) + (when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape))) (st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4))) (st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r3 value))))))} @@ -200,7 +200,7 @@ (let [id (obj/get self "$id") shape (proxy->shape self)] (when (us/safe-int? value) - (when (ctsr/radius-4? shape) + (when (or (not (ctsr/has-radius? shape)) (not (ctsr/radius-4? shape))) (st/emit! (dwc/update-shapes [id] ctsr/switch-to-radius-4))) (st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r4 value))))))} @@ -360,7 +360,7 @@ :get #(-> % proxy->shape :strokes array-to-js) :set (fn [self value] (let [id (obj/get self "$id") - value (mapv #(utils/from-js %) value)] + value (mapv #(utils/from-js % #{:stroke-style :stroke-alignment}) value)] (st/emit! (dwc/update-shapes [id] #(assoc % :strokes value)))))} {:name "layoutChild" diff --git a/frontend/src/app/plugins/utils.cljs b/frontend/src/app/plugins/utils.cljs index a96c41b48..1f348de22 100644 --- a/frontend/src/app/plugins/utils.cljs +++ b/frontend/src/app/plugins/utils.cljs @@ -188,3 +188,7 @@ (remove-watch ret-v ::watcher) (resolve value)))))] [ret-v ret-p])) + +(defn display-not-valid + [code value] + (.error js/console (dm/str "[PENPOT PLUGIN] Value not valid: " value ". Code: " code)))