Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Alejandro Alonso 2024-06-25 15:54:32 +02:00
commit 6e734f2eac
4 changed files with 105 additions and 77 deletions

View file

@ -23,6 +23,7 @@
[app.common.geom.shapes.bounds :as gsb]
[app.common.logging :as l]
[app.common.math :as mth]
[app.common.types.components-list :as ctkl]
[app.common.types.file :as ctf]
[app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst]
@ -484,15 +485,18 @@
path (:path component)
root-id (or (:main-instance-id component)
(:id component))
orig-root (get (:objects component) root-id)
objects (adapt-objects-for-shape (:objects component)
root-id)
root-shape (get objects root-id)
selrect (:selrect root-shape)
main-instance-id (:main-instance-id component)
main-instance-page (:main-instance-page component)
main-instance-x (:main-instance-x component)
main-instance-y (:main-instance-y component)
main-instance-id (:main-instance-id component)
main-instance-page (:main-instance-page component)
main-instance-x (when (:deleted component) (:x orig-root))
main-instance-y (when (:deleted component) (:y orig-root))
main-instance-parent (when (:deleted component) (:parent-id orig-root))
main-instance-frame (when (:deleted component) (:frame-id orig-root))
vbox
(format-viewbox
@ -516,7 +520,9 @@
"penpot:main-instance-id" main-instance-id
"penpot:main-instance-page" main-instance-page
"penpot:main-instance-x" main-instance-x
"penpot:main-instance-y" main-instance-y}
"penpot:main-instance-y" main-instance-y
"penpot:main-instance-parent" main-instance-parent
"penpot:main-instance-frame" main-instance-frame}
[:title name]
[:> shape-container {:shape root-shape}
(case (:type root-shape)
@ -525,8 +531,10 @@
(mf/defc components-svg
{::mf/wrap-props false}
[{:keys [data children embed include-metadata source]}]
(let [source (keyword (d/nilv source "components"))]
[{:keys [data children embed include-metadata deleted?]}]
(let [components (if (not deleted?)
(ctkl/components-seq data)
(ctkl/deleted-components-seq data))]
[:& (mf/provider embed/context) {:value embed}
[:& (mf/provider export/include-metadata-ctx) {:value include-metadata}
[:svg {:version "1.1"
@ -536,9 +544,9 @@
:style {:display (when-not (some? children) "none")}
:fill "none"}
[:defs
(for [[id component] (source data)]
(for [component components]
(let [component (ctf/load-component-objects data component)]
[:& component-symbol {:key (dm/str id) :component component}]))]
[:& component-symbol {:key (dm/str (:id component)) :component component}]))]
children]]]))
@ -595,10 +603,12 @@
(rds/renderToStaticMarkup elem)))))))
(defn render-components
[data source]
[data deleted?]
(let [;; Join all components objects into a single map
objects (->> (source data)
(vals)
components (if (not deleted?)
(ctkl/components-seq data)
(ctkl/deleted-components-seq data))
objects (->> components
(map (partial ctf/load-component-objects data))
(map :objects)
(reduce conj))]
@ -615,7 +625,7 @@
#js {:data data
:embed true
:include-metadata true
:source (name source)})]
:deleted? deleted?})]
(rds/renderToStaticMarkup elem))))))))
(defn render-frame

View file

@ -52,7 +52,7 @@
:libraries (->> (:libraries file) (into #{}) (mapv str))
:exportType (d/name export-type)
:hasComponents (d/not-empty? (ctkl/components-seq (:data file)))
:hasDeletedComponents (d/not-empty? (get-in file [:data :deleted-components]))
:hasDeletedComponents (d/not-empty? (ctkl/deleted-components-seq (:data file)))
:hasMedia (d/not-empty? (get-in file [:data :media]))
:hasColors (d/not-empty? (get-in file [:data :colors]))
:hasTypographies (d/not-empty? (get-in file [:data :typographies]))}))))]
@ -151,12 +151,12 @@
(defn parse-library-components
[file]
(->> (r/render-components (:data file) :components)
(->> (r/render-components (:data file) false)
(rx/map #(vector (str (:id file) "/components.svg") %))))
(defn parse-deleted-components
[file]
(->> (r/render-components (:data file) :deleted-components)
(->> (r/render-components (:data file) true)
(rx/map #(vector (str (:id file) "/deleted-components.svg") %))))
(defn fetch-file-with-libraries
@ -380,7 +380,7 @@
deleted-components-stream
(->> files-stream
(rx/merge-map vals)
(rx/filter #(d/not-empty? (get-in % [:data :deleted-components])))
(rx/filter #(d/not-empty? (ctkl/deleted-components-seq (:data %))))
(rx/merge-map parse-deleted-components))
pages-stream

View file

@ -253,6 +253,7 @@
frame (when (and (some? frame-id) (not= frame-id uuid/zero))
(fb/lookup-shape file frame-id))]
(js/console.log " translate-frame" (clj->js frame))
(if (some? frame)
(-> data
(d/update-when :x + (:x frame))
@ -283,7 +284,13 @@
(cond-> (some? old-id)
(assoc :id (resolve old-id)))
(cond-> (< (:version context 1) 2)
(translate-frame type file)))]
(translate-frame type file))
;; Shapes inside the deleted component should be stored with absolute coordinates
;; so we calculate that with the x and y stored in the context
(cond-> (:x context)
(assoc :x (:x context)))
(cond-> (:y context)
(assoc :y (:y context))))]
(try
(let [file (case type
:frame (fb/add-artboard file data)
@ -455,17 +462,19 @@
(rx/map fb/finish-component))))
(defn import-deleted-component [context file node]
(let [resolve (:resolve context)
content (parser/find-node node :g)
file-id (:id file)
old-id (parser/get-id node)
id (resolve old-id)
path (get-in node [:attrs :penpot:path] "")
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] "")))
main-instance-x (get-in node [:attrs :penpot:main-instance-x] "")
main-instance-y (get-in node [:attrs :penpot:main-instance-y] "")
type (parser/get-type content)
(let [resolve (:resolve context)
content (parser/find-node node :g)
file-id (:id file)
old-id (parser/get-id node)
id (resolve old-id)
path (get-in node [:attrs :penpot:path] "")
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] "")))
main-instance-x (-> (get-in node [:attrs :penpot:main-instance-x] "") (d/parse-double))
main-instance-y (-> (get-in node [:attrs :penpot:main-instance-y] "") (d/parse-double))
main-instance-parent (resolve (uuid (get-in node [:attrs :penpot:main-instance-parent] "")))
main-instance-frame (resolve (uuid (get-in node [:attrs :penpot:main-instance-frame] "")))
type (parser/get-type content)
data (-> (parser/parse-data type content)
(assoc :path path)
@ -473,12 +482,20 @@
(assoc :main-instance-id main-instance-id)
(assoc :main-instance-page main-instance-page)
(assoc :main-instance-x main-instance-x)
(assoc :main-instance-y main-instance-y))
(assoc :main-instance-y main-instance-y)
(assoc :main-instance-parent main-instance-parent)
(assoc :main-instance-frame main-instance-frame))
file (-> file (fb/start-component data))
file (-> file
(fb/start-component data)
(fb/start-deleted-component data))
component-id (:current-component-id file)
children (parser/node-seq node)]
children (parser/node-seq node)
;; Shapes inside the deleted component should be stored with absolute coordinates so we include this info in the context.
context (-> context
(assoc :x main-instance-x)
(assoc :y main-instance-y))]
(->> (rx/from children)
(rx/filter parser/shape?)
(rx/skip 1)
@ -486,11 +503,7 @@
(rx/mapcat (partial resolve-media context file-id))
(rx/reduce (partial process-import-node context) file)
(rx/map fb/finish-component)
(rx/map (partial fb/finish-deleted-component
component-id
main-instance-page
main-instance-x
main-instance-y)))))
(rx/map (partial fb/finish-deleted-component component-id)))))
(defn process-pages
[context file]