mirror of
https://github.com/penpot/penpot.git
synced 2025-03-19 11:11:21 -05:00
wip
This commit is contained in:
parent
c2ba7cdbc7
commit
c239b5868e
3 changed files with 43 additions and 21 deletions
|
@ -276,12 +276,19 @@
|
|||
"Validate that the referenced shape exists in the near component."
|
||||
[shape file page libraries]
|
||||
(let [library-exists (library-exists? file libraries shape)
|
||||
has-swap-slot? (some? (ctk/get-swap-slot shape))
|
||||
ref-shape (when library-exists
|
||||
(ctf/find-ref-shape file page libraries shape :include-deleted? true))]
|
||||
(ctf/find-ref-shape file page libraries shape
|
||||
:include-deleted? true
|
||||
:only-lower? has-swap-slot?))]
|
||||
(when (and library-exists (nil? ref-shape))
|
||||
(report-error :ref-shape-not-found
|
||||
(str/ffmt "Referenced shape % not found in near component" (:shape-ref shape))
|
||||
shape file page))))
|
||||
(if has-swap-slot?
|
||||
(report-error :ref-shape-not-found
|
||||
(str/ffmt "Referenced shape % not found in near component" (:shape-ref shape))
|
||||
shape file page)
|
||||
(report-error :ref-shape-not-found
|
||||
(str/ffmt "Referenced shape % not found in component" (:shape-ref shape))
|
||||
shape file page)))))
|
||||
|
||||
(defn- check-component-not-ref
|
||||
"Validate that this shape does not reference other one."
|
||||
|
@ -364,13 +371,16 @@
|
|||
- :component-file
|
||||
- :shape-ref"
|
||||
[shape file page libraries library-exists]
|
||||
(check-component-not-main-head shape file page libraries)
|
||||
(check-component-not-root shape file page)
|
||||
;; We can have situations where the nested copy and the ancestor copy come from different libraries and some of them have been dettached
|
||||
;; so we only validate the shape-ref if the ancestor is from a valid library
|
||||
(when library-exists
|
||||
(check-component-ref shape file page libraries))
|
||||
(run! #(check-shape % file page libraries :context :copy-nested) (:shapes shape)))
|
||||
(let [library-exists (or library-exists (library-exists? file libraries shape))]
|
||||
(when (= (:id shape) #uuid "81f32503-7638-8059-8005-1883e6d1a4fa")
|
||||
(prn "ok1" library-exists))
|
||||
(check-component-not-main-head shape file page libraries)
|
||||
(check-component-not-root shape file page)
|
||||
;; We can have situations where the nested copy and the ancestor copy come from different libraries and some of them have been dettached
|
||||
;; so we only validate the shape-ref if the ancestor is from a valid library
|
||||
(when library-exists
|
||||
(check-component-ref shape file page libraries))
|
||||
(run! #(check-shape % file page libraries :context :copy-nested) (:shapes shape))))
|
||||
|
||||
(defn- check-shape-main-not-root
|
||||
"Not-root shape of a main instance (not any attribute)"
|
||||
|
|
|
@ -259,20 +259,24 @@
|
|||
(defn- generate-detach-recursive
|
||||
[changes container libraries shape-id first component-root?]
|
||||
(let [shape (ctn/get-shape container shape-id)]
|
||||
(prn "shape-id" (:id shape))
|
||||
(if (and (ctk/instance-head? shape) (not first))
|
||||
; Subinstances are not detached
|
||||
(cond-> changes
|
||||
component-root?
|
||||
(do
|
||||
(when (= (:id shape) #uuid "81f32503-7638-8059-8005-1883e6d1a4fa")
|
||||
(prn "wurxt" (ctk/get-swap-slot shape)))
|
||||
(cond-> changes
|
||||
component-root?
|
||||
; If the initial shape was component-root, first level subinstances are converted in top instances
|
||||
(pcb/update-shapes [shape-id] #(assoc % :component-root true))
|
||||
(pcb/update-shapes [shape-id] #(assoc % :component-root true))
|
||||
|
||||
:always
|
||||
:always
|
||||
; First level subinstances of a detached component can't have swap-slot
|
||||
(pcb/update-shapes [shape-id] ctk/remove-swap-slot)
|
||||
(pcb/update-shapes [shape-id] ctk/remove-swap-slot)
|
||||
|
||||
(nil? (ctk/get-swap-slot shape))
|
||||
(nil? (ctk/get-swap-slot shape))
|
||||
; Near shape-refs need to be advanced one level (except if the head is already swapped)
|
||||
(generate-advance-nesting-level nil container libraries (:id shape)))
|
||||
(generate-advance-nesting-level nil container libraries (:id shape))))
|
||||
|
||||
;; Otherwise, detach the shape and all children
|
||||
(let [children-ids (:shapes shape)]
|
||||
|
|
|
@ -262,16 +262,24 @@
|
|||
(defn find-ref-shape
|
||||
"Locate the nearest component in the local file or libraries, and retrieve the shape
|
||||
referenced by the instance shape."
|
||||
[file container libraries shape & {:keys [include-deleted? with-context?] :or {include-deleted? false with-context? false}}]
|
||||
[file container libraries shape & {:keys [include-deleted? with-context? only-lower?]
|
||||
:or {include-deleted? false with-context? false only-lower? false}}]
|
||||
(let [find-ref-shape-in-head
|
||||
(fn [head-shape]
|
||||
(let [component-file (find-component-file file libraries (:component-file head-shape))
|
||||
component (when (some? component-file)
|
||||
(ctkl/get-component (:data component-file) (:component-id head-shape) include-deleted?))]
|
||||
(when (some? component)
|
||||
(get-ref-shape (:data component-file) component shape :with-context? with-context?))))]
|
||||
(get-ref-shape (:data component-file) component shape :with-context? with-context?))))
|
||||
|
||||
parent-heads (ctn/get-parent-heads (:objects container) shape)]
|
||||
;; (when (= (:id shape) #uuid "805fa3b6-a357-808b-8004-58bccaa27dca")
|
||||
;; (js/console.log "shape" (clj->js shape))
|
||||
;; (js/console.log "parent-heads" (clj->js parent-heads)))
|
||||
|
||||
(some find-ref-shape-in-head (ctn/get-parent-heads (:objects container) shape))))
|
||||
(if only-lower?
|
||||
(find-ref-shape-in-head (last parent-heads))
|
||||
(some find-ref-shape-in-head parent-heads))))
|
||||
|
||||
(defn advance-shape-ref
|
||||
"Get the shape-ref of the near main of the shape, recursively repeated as many times
|
||||
|
|
Loading…
Add table
Reference in a new issue