mirror of
https://github.com/penpot/penpot.git
synced 2025-07-17 09:07:14 +02:00
🐛 Fix several issues related to pointer-map and components-v2
This commit is contained in:
parent
af2c10f2ab
commit
a455fc015b
7 changed files with 120 additions and 88 deletions
|
@ -37,10 +37,16 @@
|
|||
(reduce migrate-fn data (range (:version data 0) to-version))))))
|
||||
|
||||
(defn migrate-file
|
||||
[file]
|
||||
(-> file
|
||||
(update :data assoc :id (:id file))
|
||||
(update :data migrate-data)))
|
||||
[{:keys [id data] :as file}]
|
||||
(let [data (assoc data :id id)]
|
||||
(-> file
|
||||
(assoc ::orig-version (:version data))
|
||||
(assoc :data (migrate-data data)))))
|
||||
|
||||
(defn migrated?
|
||||
[{:keys [data] :as file}]
|
||||
(> (:version data)
|
||||
(::orig-version file)))
|
||||
|
||||
;; Default handler, noop
|
||||
(defmethod migrate :default [data] data)
|
||||
|
|
|
@ -30,25 +30,19 @@
|
|||
(assoc component :modified-at (dt/now)))
|
||||
|
||||
(defn add-component
|
||||
[file-data {:keys [id name path main-instance-id main-instance-page shapes]}]
|
||||
(let [components-v2 (dm/get-in file-data [:options :components-v2])
|
||||
wrap-object-fn feat/*wrap-with-objects-map-fn*]
|
||||
(cond-> file-data
|
||||
:always
|
||||
(assoc-in [:components id]
|
||||
(touch {:id id
|
||||
:name name
|
||||
:path path}))
|
||||
|
||||
(not components-v2)
|
||||
(assoc-in [:components id :objects]
|
||||
(->> shapes
|
||||
(d/index-by :id)
|
||||
(wrap-object-fn)))
|
||||
components-v2
|
||||
(update-in [:components id] assoc
|
||||
[fdata {:keys [id name path main-instance-id main-instance-page shapes]}]
|
||||
(let [components-v2 (dm/get-in fdata [:options :components-v2])
|
||||
fdata (update fdata :components assoc id (touch {:id id :name name :path path}))]
|
||||
(if components-v2
|
||||
(update-in fdata [:components id] assoc
|
||||
:main-instance-id main-instance-id
|
||||
:main-instance-page main-instance-page))))
|
||||
:main-instance-page main-instance-page)
|
||||
|
||||
(let [wrap-object-fn feat/*wrap-with-objects-map-fn*]
|
||||
(assoc-in fdata [:components id :objects]
|
||||
(->> shapes
|
||||
(d/index-by :id)
|
||||
(wrap-object-fn)))))))
|
||||
|
||||
(defn mod-component
|
||||
[file-data {:keys [id name path objects annotation]}]
|
||||
|
|
|
@ -173,7 +173,8 @@
|
|||
(make-component-instance container component library-data position components-v2 {}))
|
||||
|
||||
([container component library-data position components-v2
|
||||
{:keys [main-instance? force-id] :or {main-instance? false force-id nil}}]
|
||||
{:keys [main-instance? force-id force-frame-id]
|
||||
:or {main-instance? false force-id nil force-frame-id nil}}]
|
||||
(let [component-page (when components-v2
|
||||
(ctpl/get-page library-data (:main-instance-page component)))
|
||||
component-shape (if components-v2
|
||||
|
@ -188,10 +189,11 @@
|
|||
objects (:objects container)
|
||||
unames (volatile! (common/retrieve-used-names objects))
|
||||
|
||||
frame-id (ctst/frame-id-by-position objects
|
||||
(gpt/add orig-pos delta)
|
||||
{:skip-components? true}) ; It'd be weird to make an instance
|
||||
frame-ids-map (volatile! {}) ; inside other component
|
||||
frame-id (or force-frame-id
|
||||
(ctst/frame-id-by-position objects
|
||||
(gpt/add orig-pos delta)
|
||||
{:skip-components? true}))
|
||||
frame-ids-map (volatile! {})
|
||||
|
||||
update-new-shape
|
||||
(fn [new-shape original-shape]
|
||||
|
|
|
@ -345,7 +345,8 @@
|
|||
file-data
|
||||
position
|
||||
false
|
||||
{:main-instance? true})
|
||||
{:main-instance? true
|
||||
:force-frame-id uuid/zero})
|
||||
|
||||
add-shapes
|
||||
(fn [page]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue