🐛 Fix import/export components with boards inside

This commit is contained in:
Andrés Moya 2023-01-05 16:06:41 +01:00 committed by Alonso Torres
parent 28114b166c
commit 2b978777d7
8 changed files with 113 additions and 81 deletions

View file

@ -397,11 +397,13 @@
group-wrapper
(mf/use-memo
(mf/deps objects root-shape)
(fn []
(case (:type root-shape)
:group (group-wrapper-factory objects)
:frame (frame-wrapper-factory objects))))]
(mf/deps objects)
(fn [] (group-wrapper-factory objects)))
frame-wrapper
(mf/use-memo
(mf/deps objects)
(fn [] (frame-wrapper-factory objects)))]
[:> "symbol" #js {:id (str id)
:viewBox vbox
@ -412,7 +414,9 @@
"penpot:main-instance-y" main-instance-y}
[:title name]
[:> shape-container {:shape root-shape}
[:& group-wrapper {:shape root-shape :view-box vbox}]]]))
(case (:type root-shape)
:group [:& group-wrapper {:shape root-shape :view-box vbox}]
:frame [:& frame-wrapper {:shape root-shape :view-box vbox}])]]))
(mf/defc components-sprite-svg
{::mf/wrap-props false}

View file

@ -64,9 +64,9 @@
(or (find-node node :penpot:shape)
(find-node node :penpot:page)))
([node tag]
(-> (get-data node)
(find-node tag))))
([node tag]
(-> (get-data node)
(find-node tag))))
(defn get-type
[node]
@ -217,10 +217,10 @@
(let [;; Old .penpot files doesn't have "g" nodes. They have a clipPath reference as a node attribute
to-url #(dm/str "url(#" % ")")
frame-clip-rect-node (->> (find-all-nodes node :defs)
(mapcat #(find-all-nodes % :clipPath))
(filter #(= (to-url (:id (:attrs %))) (:clip-path node-attrs)))
(mapcat #(find-all-nodes % #{:rect :path}))
(first))
(mapcat #(find-all-nodes % :clipPath))
(filter #(= (to-url (:id (:attrs %))) (:clip-path node-attrs)))
(mapcat #(find-all-nodes % #{:rect :path}))
(first))
;; The nodes with the "frame-background" class can have some anidation depending on the strokes they have
g-nodes (find-all-nodes node :g)
@ -1007,8 +1007,8 @@
(ctsi/has-overlay-opts interaction)
(assoc :overlay-pos-type (get-meta node :overlay-pos-type keyword)
:overlay-position (gpt/point
(get-meta node :overlay-position-x d/parse-double)
(get-meta node :overlay-position-y d/parse-double))
(get-meta node :overlay-position-x d/parse-double)
(get-meta node :overlay-position-y d/parse-double))
:close-click-outside (get-meta node :close-click-outside str->bool)
:background-overlay (get-meta node :background-overlay str->bool)))))))))

View file

@ -389,21 +389,22 @@
old-id (cip/get-id node)
id (resolve old-id)
path (get-in node [:attrs :penpot:path] "")
type (cip/get-type content)
main-instance-id (resolve (uuid (get-in node [:attrs :penpot:main-instance-id] "")))
main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] "")))
data (-> (cip/parse-data :group content)
data (-> (cip/parse-data type content)
(assoc :path path)
(assoc :id id)
(assoc :main-instance-id main-instance-id)
(assoc :main-instance-page main-instance-page))
file (-> file (fb/start-component data))
children (cip/node-seq node)]
file (-> file (fb/start-component data type))
children (cip/node-seq node)]
(->> (rx/from children)
(rx/filter cip/shape?)
(rx/skip 1)
(rx/skip-last 1)
(rx/skip 1) ;; Skip the outer component and the respective closint tag
(rx/skip-last 1) ;; because they are handled in start-component an finish-component
(rx/mapcat (partial resolve-media context file-id))
(rx/reduce (partial process-import-node context) file)
(rx/map fb/finish-component))))
@ -419,8 +420,9 @@
main-instance-page (resolve (uuid (get-in node [:attrs :penpot:main-instance-page] "")))
main-instance-x (get-in node [:attrs :penpot:main-instance-x] "")
main-instance-y (get-in node [:attrs :penpot:main-instance-y] "")
type (cip/get-type content)
data (-> (cip/parse-data :group content)
data (-> (cip/parse-data type content)
(assoc :path path)
(assoc :id id)
(assoc :main-instance-id main-instance-id)