0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Merge pull request #4824 from penpot/alotor-fix-plugins

🐛 Fix problem with recursive properties
This commit is contained in:
Andrey Antukh 2024-06-28 16:21:58 +02:00 committed by GitHub
commit de1d154e9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 68 deletions

View file

@ -594,7 +594,15 @@
:else :else
(let [component (u/proxy->library-component self)] (let [component (u/proxy->library-component self)]
(apply array (keys (dm/get-in component [:plugin-data (keyword "shared" namespace)]))))))) (apply array (keys (dm/get-in component [:plugin-data (keyword "shared" namespace)]))))))
(mainInstance
[self]
(let [file (u/locate-file $file)
component (u/proxy->library-component self)
root (ctf/get-component-root (:data file) component)]
(when (some? root)
(shape/shape-proxy $plugin $file (:main-instance-page component) (:id root))))))
(defn lib-component-proxy? [p] (defn lib-component-proxy? [p]
(instance? LibraryComponentProxy p)) (instance? LibraryComponentProxy p))
@ -635,17 +643,7 @@
:else :else
(let [component (u/proxy->library-component self) (let [component (u/proxy->library-component self)
value (dm/str value " / " (:name component))] value (dm/str value " / " (:name component))]
(st/emit! (dwl/rename-component id value)))))} (st/emit! (dwl/rename-component id value)))))}))
{:name "mainInstance"
:get
(fn [self]
(let [file-id (obj/get self "$file")
file (u/locate-file file-id)
component (u/proxy->library-component self)
root (ctf/get-component-root (:data file) component)]
(when (some? root)
(shape/shape-proxy plugin-id file-id (:main-instance-page component) (:id root)))))}))
(set! shape/lib-component-proxy lib-component-proxy) (set! shape/lib-component-proxy lib-component-proxy)

View file

@ -515,7 +515,44 @@
(isComponentHead (isComponentHead
[self] [self]
(let [shape (u/proxy->shape self)] (let [shape (u/proxy->shape self)]
(ctk/instance-head? shape)))) (ctk/instance-head? shape)))
(componentRefShape
[self]
(let [objects (u/locate-objects $file $page)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [plugin-id (obj/get self "$plugin")
[root component] (u/locate-component objects shape)
component-page-id (:main-instance-page component)
component-file (u/locate-file (:component-file root))
ref-shape (ctf/get-ref-shape (:data component-file) component shape)]
(when (and (not (:deleted component)) (some? ref-shape) (some? component-file))
(shape-proxy plugin-id (:id component-file) component-page-id (:id ref-shape)))))))
(componentRoot
[self]
(let [objects (u/locate-objects $file $page)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [[root component] (u/locate-component objects shape)]
(shape-proxy $plugin (:component-file root) (:main-instance-page component) (:id root))))))
(componentHead
[self]
(let [objects (u/locate-objects $file $page)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [head (ctn/get-head-shape (u/locate-objects $file $page) shape)]
(shape-proxy $plugin $file $page (:id head))))))
(component
[self]
(let [objects (u/locate-objects $file $page)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [[root component] (u/locate-component objects shape)]
(lib-component-proxy $plugin (:component-file root) (:id component)))))))
(crc/define-properties! (crc/define-properties!
ShapeProxy ShapeProxy
@ -553,7 +590,7 @@
:get #(-> % u/proxy->shape :id str)} :get #(-> % u/proxy->shape :id str)}
{:name "type" {:name "type"
:get #(-> % u/proxy->shape :type name)} :get #(-> % u/proxy->shape :type d/name)}
{:name "name" {:name "name"
:get #(-> % u/proxy->shape :name) :get #(-> % u/proxy->shape :name)
@ -1000,60 +1037,7 @@
id (obj/get self "$id") id (obj/get self "$id")
objects (u/locate-objects file-id page-id)] objects (u/locate-objects file-id page-id)]
(when (ctl/grid-layout-immediate-child-id? objects id) (when (ctl/grid-layout-immediate-child-id? objects id)
(grid/layout-cell-proxy plugin-id file-id page-id id))))} (grid/layout-cell-proxy plugin-id file-id page-id id))))})
;; Components
{:name "componentRefShape"
:get
(fn [self]
(let [file-id (obj/get self "$file")
page-id (obj/get self "$page")
objects (u/locate-objects file-id page-id)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [plugin-id (obj/get self "$plugin")
[root component] (u/locate-component objects shape)
component-page-id (:main-instance-page component)
component-file (u/locate-file (:component-file root))
ref-shape (ctf/get-ref-shape (:data component-file) component shape)]
(when (and (not (:deleted component)) (some? ref-shape) (some? component-file))
(shape-proxy plugin-id (:id component-file) component-page-id (:id ref-shape)))))))}
{:name "componentRoot"
:get
(fn [self]
(let [file-id (obj/get self "$file")
page-id (obj/get self "$page")
objects (u/locate-objects file-id page-id)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [plugin-id (obj/get self "$plugin")
[root component] (u/locate-component objects shape)]
(shape-proxy plugin-id (:component-file root) (:main-instance-page component) (:id root))))))}
{:name "componentHead"
:get
(fn [self]
(let [file-id (obj/get self "$file")
objects (u/locate-objects file-id page-id)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [plugin-id (obj/get self "$plugin")
page-id (obj/get self "$page")
head (ctn/get-head-shape (u/locate-objects file-id page-id) shape)]
(shape-proxy plugin-id file-id page-id (:id head))))))}
{:name "component"
:get
(fn [self]
(let [file-id (obj/get self "$file")
page-id (obj/get self "$page")
objects (u/locate-objects file-id page-id)
shape (u/proxy->shape self)]
(when (ctn/in-any-component? objects shape)
(let [plugin-id (obj/get self "$plugin")
[root component] (u/locate-component objects shape)]
(lib-component-proxy plugin-id (:component-file root) (:id component))))))})
(cond-> (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data)) (cond-> (or (cfh/frame-shape? data) (cfh/group-shape? data) (cfh/svg-raw-shape? data) (cfh/bool-shape? data))
(crc/add-properties! (crc/add-properties!