mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
✨ Add library edition mode for plugins
This commit is contained in:
parent
b95cb3d4c5
commit
007ab3d909
3 changed files with 35 additions and 11 deletions
|
@ -7,9 +7,11 @@
|
||||||
(ns app.plugins.library
|
(ns app.plugins.library
|
||||||
"RPC for plugins runtime."
|
"RPC for plugins runtime."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.colors :as cc]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.record :as cr]
|
[app.common.record :as cr]
|
||||||
|
[app.main.data.workspace.libraries :as dwl]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.plugins.utils :as u]))
|
[app.plugins.utils :as u]))
|
||||||
|
|
||||||
|
@ -53,13 +55,32 @@
|
||||||
{:name "id" :get (fn [_] (dm/str id))}
|
{:name "id" :get (fn [_] (dm/str id))}
|
||||||
|
|
||||||
{:name "name"
|
{: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"
|
{: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"
|
{: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"
|
{:name "gradient"
|
||||||
:get #(-> % u/proxy->library-color :gradient u/to-js)}
|
:get #(-> % u/proxy->library-color :gradient u/to-js)}
|
||||||
|
@ -96,8 +117,7 @@
|
||||||
{:name "$id" :enumerable false :get (constantly id)}
|
{:name "$id" :enumerable false :get (constantly id)}
|
||||||
{:name "$file" :enumerable false :get (constantly file-id)}
|
{:name "$file" :enumerable false :get (constantly file-id)}
|
||||||
{:name "id" :get (fn [_] (dm/str id))}
|
{:name "id" :get (fn [_] (dm/str id))}
|
||||||
{:name "name"
|
{:name "name" :get #(-> % u/proxy->library-component :name)}))
|
||||||
:get #(-> % u/proxy->library-component :name)}))
|
|
||||||
|
|
||||||
(deftype Library [$id]
|
(deftype Library [$id]
|
||||||
Object)
|
Object)
|
||||||
|
|
|
@ -160,7 +160,7 @@
|
||||||
(let [id (obj/get self "$id")
|
(let [id (obj/get self "$id")
|
||||||
shape (proxy->shape self)]
|
shape (proxy->shape self)]
|
||||||
(when (us/safe-int? value)
|
(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/switch-to-radius-1)))
|
||||||
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-1 % value))))))}
|
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-1 % value))))))}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
(let [id (obj/get self "$id")
|
(let [id (obj/get self "$id")
|
||||||
shape (proxy->shape self)]
|
shape (proxy->shape self)]
|
||||||
(when (us/safe-int? value)
|
(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/switch-to-radius-4)))
|
||||||
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r1 value))))))}
|
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r1 value))))))}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
(let [id (obj/get self "$id")
|
(let [id (obj/get self "$id")
|
||||||
shape (proxy->shape self)]
|
shape (proxy->shape self)]
|
||||||
(when (us/safe-int? value)
|
(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/switch-to-radius-4)))
|
||||||
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r2 value))))))}
|
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r2 value))))))}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@
|
||||||
(let [id (obj/get self "$id")
|
(let [id (obj/get self "$id")
|
||||||
shape (proxy->shape self)]
|
shape (proxy->shape self)]
|
||||||
(when (us/safe-int? value)
|
(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/switch-to-radius-4)))
|
||||||
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r3 value))))))}
|
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r3 value))))))}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@
|
||||||
(let [id (obj/get self "$id")
|
(let [id (obj/get self "$id")
|
||||||
shape (proxy->shape self)]
|
shape (proxy->shape self)]
|
||||||
(when (us/safe-int? value)
|
(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/switch-to-radius-4)))
|
||||||
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r4 value))))))}
|
(st/emit! (dwc/update-shapes [id] #(ctsr/set-radius-4 % :r4 value))))))}
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@
|
||||||
:get #(-> % proxy->shape :strokes array-to-js)
|
:get #(-> % proxy->shape :strokes array-to-js)
|
||||||
:set (fn [self value]
|
:set (fn [self value]
|
||||||
(let [id (obj/get self "$id")
|
(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)))))}
|
(st/emit! (dwc/update-shapes [id] #(assoc % :strokes value)))))}
|
||||||
|
|
||||||
{:name "layoutChild"
|
{:name "layoutChild"
|
||||||
|
|
|
@ -188,3 +188,7 @@
|
||||||
(remove-watch ret-v ::watcher)
|
(remove-watch ret-v ::watcher)
|
||||||
(resolve value)))))]
|
(resolve value)))))]
|
||||||
[ret-v ret-p]))
|
[ret-v ret-p]))
|
||||||
|
|
||||||
|
(defn display-not-valid
|
||||||
|
[code value]
|
||||||
|
(.error js/console (dm/str "[PENPOT PLUGIN] Value not valid: " value ". Code: " code)))
|
||||||
|
|
Loading…
Reference in a new issue