0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

Add library edition mode for plugins

This commit is contained in:
alonso.torres 2024-05-29 12:43:15 +02:00 committed by Andrey Antukh
parent b95cb3d4c5
commit 007ab3d909
3 changed files with 35 additions and 11 deletions

View file

@ -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)

View file

@ -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"

View file

@ -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)))