mirror of
https://github.com/penpot/penpot.git
synced 2025-06-09 00:01:38 +02:00
✨ New plugin attributes
This commit is contained in:
parent
80e17f8cfc
commit
a8463f349a
3 changed files with 54 additions and 5 deletions
|
@ -23,6 +23,7 @@
|
||||||
[app.main.data.workspace.colors :as dwc]
|
[app.main.data.workspace.colors :as dwc]
|
||||||
[app.main.data.workspace.groups :as dwg]
|
[app.main.data.workspace.groups :as dwg]
|
||||||
[app.main.data.workspace.media :as dwm]
|
[app.main.data.workspace.media :as dwm]
|
||||||
|
[app.main.data.workspace.selection :as dws]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.plugins.events :as events]
|
[app.plugins.events :as events]
|
||||||
[app.plugins.file :as file]
|
[app.plugins.file :as file]
|
||||||
|
@ -356,7 +357,19 @@
|
||||||
{:name "root" :get #(.getRoot ^js %)}
|
{:name "root" :get #(.getRoot ^js %)}
|
||||||
{:name "currentFile" :get #(.getFile ^js %)}
|
{:name "currentFile" :get #(.getFile ^js %)}
|
||||||
{:name "currentPage" :get #(.getPage ^js %)}
|
{:name "currentPage" :get #(.getPage ^js %)}
|
||||||
{:name "selection" :get #(.getSelectedShapes ^js %)}
|
|
||||||
|
{:name "selection"
|
||||||
|
:get #(.getSelectedShapes ^js %)
|
||||||
|
:set
|
||||||
|
(fn [_ shapes]
|
||||||
|
(cond
|
||||||
|
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||||
|
(u/display-not-valid :selection shapes)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [ids (into (d/ordered-set) (map #(obj/get % "$id")) shapes)]
|
||||||
|
(st/emit! (dws/select-shapes ids)))))}
|
||||||
|
|
||||||
{:name "viewport" :get #(.getViewport ^js %)}
|
{:name "viewport" :get #(.getViewport ^js %)}
|
||||||
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
{:name "currentUser" :get #(.getCurrentUser ^js %)}
|
||||||
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
{:name "activeUsers" :get #(.getActiveUsers ^js %)}
|
||||||
|
|
|
@ -229,8 +229,8 @@
|
||||||
(when (some? export)
|
(when (some? export)
|
||||||
(d/without-nils
|
(d/without-nils
|
||||||
{:type (-> (obj/get export "type") parse-keyword)
|
{:type (-> (obj/get export "type") parse-keyword)
|
||||||
:scale (obj/get export "scale")
|
:scale (obj/get export "scale" 1)
|
||||||
:suffix (obj/get export "suffix")})))
|
:suffix (obj/get export "suffix" "")})))
|
||||||
|
|
||||||
(defn parse-exports
|
(defn parse-exports
|
||||||
[^js exports]
|
[^js exports]
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
[app.main.data.workspace.shape-layout :as dwsl]
|
[app.main.data.workspace.shape-layout :as dwsl]
|
||||||
[app.main.data.workspace.shapes :as dwsh]
|
[app.main.data.workspace.shapes :as dwsh]
|
||||||
[app.main.data.workspace.texts :as dwt]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.plugins.flex :as flex]
|
[app.plugins.flex :as flex]
|
||||||
[app.plugins.format :as format]
|
[app.plugins.format :as format]
|
||||||
|
@ -46,7 +47,9 @@
|
||||||
[app.plugins.utils :as u]
|
[app.plugins.utils :as u]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.path.format :as upf]
|
[app.util.path.format :as upf]
|
||||||
[cuerdas.core :as str]))
|
[beicon.v2.core :as rx]
|
||||||
|
[cuerdas.core :as str]
|
||||||
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(def lib-typography-proxy? nil)
|
(def lib-typography-proxy? nil)
|
||||||
(def lib-component-proxy nil)
|
(def lib-component-proxy nil)
|
||||||
|
@ -436,7 +439,34 @@
|
||||||
shape (u/proxy->shape self)]
|
shape (u/proxy->shape self)]
|
||||||
(when (ctn/in-any-component? objects shape)
|
(when (ctn/in-any-component? objects shape)
|
||||||
(let [[root component] (u/locate-component objects shape)]
|
(let [[root component] (u/locate-component objects shape)]
|
||||||
(lib-component-proxy $plugin (:component-file root) (:id component)))))))
|
(lib-component-proxy $plugin (:component-file root) (:id component))))))
|
||||||
|
|
||||||
|
(export
|
||||||
|
[self value]
|
||||||
|
(let [value (parser/parse-export value)]
|
||||||
|
(cond
|
||||||
|
(not (sm/validate ::ctse/export value))
|
||||||
|
(u/display-not-valid :export value)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [payload
|
||||||
|
{:cmd :export-shapes
|
||||||
|
:profile-id (:profile-id @st/state)
|
||||||
|
:wait true
|
||||||
|
:exports [{:file-id $file
|
||||||
|
:page-id $page
|
||||||
|
:object-id $id
|
||||||
|
:name (obj/get self "name")
|
||||||
|
:type (:type value :png)
|
||||||
|
:suffix (:suffix value "")
|
||||||
|
:scale (:scale value 1)}]}]
|
||||||
|
(p/create
|
||||||
|
(fn [resolve reject]
|
||||||
|
(->> (rp/cmd! :export payload)
|
||||||
|
(rx/mapcat #(rp/cmd! :export {:cmd :get-resource :wait true :id (:id %) :blob? true}))
|
||||||
|
(rx/mapcat #(.arrayBuffer %))
|
||||||
|
(rx/map #(js/Uint8Array. %))
|
||||||
|
(rx/subs! resolve reject)))))))))
|
||||||
|
|
||||||
(defn shape-proxy? [p]
|
(defn shape-proxy? [p]
|
||||||
(instance? ShapeProxy p))
|
(instance? ShapeProxy p))
|
||||||
|
@ -886,6 +916,12 @@
|
||||||
{:name "height"
|
{:name "height"
|
||||||
:get #(-> % u/proxy->shape :height)}
|
:get #(-> % u/proxy->shape :height)}
|
||||||
|
|
||||||
|
{:name "bounds"
|
||||||
|
:get #(-> % u/proxy->shape :points grc/points->rect format/format-bounds)}
|
||||||
|
|
||||||
|
{:name "center"
|
||||||
|
:get #(-> % u/proxy->shape gsh/shape->center format/format-point)}
|
||||||
|
|
||||||
{:name "rotation"
|
{:name "rotation"
|
||||||
:get #(-> % u/proxy->shape :rotation)
|
:get #(-> % u/proxy->shape :rotation)
|
||||||
:set
|
:set
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue