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

This commit is contained in:
Andrey Antukh 2024-04-04 14:19:45 +02:00
commit e813fcb9b7
7 changed files with 91 additions and 30 deletions

View file

@ -197,6 +197,12 @@
(or (= slot-main slot-inst) (or (= slot-main slot-inst)
(= (:id shape-main) slot-inst))))) (= (:id shape-main) slot-inst)))))
(defn remove-swap-slot
[shape]
(update shape :touched
(fn [touched]
(into #{} (remove #(str/starts-with? (name %) "swap-slot-") touched)))))
(defn get-component-root (defn get-component-root
[component] [component]
(if (true? (:main-instance-id component)) (if (true? (:main-instance-id component))

View file

@ -211,20 +211,33 @@
:else :else
(get-instance-root objects (get objects (:parent-id shape))))) (get-instance-root objects (get objects (:parent-id shape)))))
(defn find-component-main
"If the shape is a component main instance or is inside one, return that instance"
([objects shape]
(find-component-main objects shape true))
([objects shape only-direct-child?]
(cond
(or (nil? shape) (cfh/root? shape))
nil
(nil? (:parent-id shape)) ; This occurs in the root of components v1
shape
(ctk/main-instance? shape)
shape
(and only-direct-child? ;; If we are asking only for direct childs of a component-main,
(ctk/instance-head? shape)) ;; stop when we found a instance-head that isn't main-instance
nil
(and (not only-direct-child?)
(ctk/instance-root? shape))
nil
:else
(find-component-main objects (get objects (:parent-id shape))))))
(defn inside-component-main? (defn inside-component-main?
"Check if the shape is a component main instance or is inside one." "Check if the shape is a component main instance or is inside one."
[objects shape] ([objects shape]
(cond (inside-component-main? objects shape true))
(or (nil? shape) (cfh/root? shape)) ([objects shape only-direct-child?]
false (some? (find-component-main objects shape only-direct-child?))))
(nil? (:parent-id shape)) ; This occurs in the root of components v1
true
(ctk/main-instance? shape)
true
(ctk/instance-head? shape)
false
:else
(inside-component-main? objects (get objects (:parent-id shape)))))
(defn in-any-component? (defn in-any-component?
"Check if the shape is part of any component (main or copy), wether it's "Check if the shape is part of any component (main or copy), wether it's

View file

@ -36,6 +36,7 @@
<script src="{{& polyfills}}"></script> <script src="{{& polyfills}}"></script>
{{/manifest}} {{/manifest}}
<!--cookie-consent-->
</head> </head>
<body> <body>
{{> ../public/images/sprites/symbol/icons.svg }} {{> ../public/images/sprites/symbol/icons.svg }}

View file

@ -789,9 +789,14 @@
(defn relocate-shapes-changes [it objects parents parent-id page-id to-index ids (defn relocate-shapes-changes [it objects parents parent-id page-id to-index ids
groups-to-delete groups-to-unmask shapes-to-detach groups-to-delete groups-to-unmask shapes-to-detach
shapes-to-reroot shapes-to-deroot shapes-to-unconstraint] shapes-to-reroot shapes-to-deroot shapes-to-unconstraint]
(let [ordered-indexes (cfh/order-by-indexed-shapes objects ids) (let [ordered-indexes (cfh/order-by-indexed-shapes objects ids)
shapes (map (d/getf objects) ordered-indexes) shapes (map (d/getf objects) ordered-indexes)
parent (get objects parent-id)] parent (get objects parent-id)
component-main-parent (ctn/find-component-main objects parent false)
child-heads
(->> ordered-indexes
(mapcat #(ctn/get-child-heads objects %))
(map :id))]
(-> (pcb/empty-changes it page-id) (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects) (pcb/with-objects objects)
@ -804,6 +809,17 @@
(cond-> (and (not= uuid/zero parent-id) (cfh/frame-shape? parent)) (cond-> (and (not= uuid/zero parent-id) (cfh/frame-shape? parent))
(pcb/update-shapes ordered-indexes #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true)))) (pcb/update-shapes ordered-indexes #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true))))
;; Remove the swap slots if it is moving to a different component
(pcb/update-shapes child-heads
(fn [shape]
(cond-> shape
(not= component-main-parent (ctn/find-component-main objects shape false))
(ctk/remove-swap-slot))))
;; Add component-root property when moving a component outside a component
(cond-> (not (ctn/get-instance-root objects parent))
(pcb/update-shapes child-heads #(assoc % :component-root true)))
;; Move the shapes ;; Move the shapes
(pcb/change-parent parent-id (pcb/change-parent parent-id
shapes shapes

View file

@ -937,12 +937,14 @@
(ptk/reify ::add-component-for-swap (ptk/reify ::add-component-for-swap
ptk/WatchEvent ptk/WatchEvent
(watch [it _ _] (watch [it _ _]
(let [objects (:objects page) (let [objects (:objects page)
position (gpt/point (:x shape) (:y shape)) position (gpt/point (:x shape) (:y shape))
changes (-> (pcb/empty-changes it (:id page)) changes (-> (pcb/empty-changes it (:id page))
(pcb/set-undo-group undo-group) (pcb/set-undo-group undo-group)
(pcb/with-objects objects)) (pcb/with-objects objects))
position (-> position (with-meta {:cell target-cell})) position (-> position (with-meta {:cell target-cell}))
parent (get objects (:parent-id shape))
inside-comp? (ctn/in-any-component? objects parent)
[new-shape changes] [new-shape changes]
(dwlh/generate-instantiate-component changes (dwlh/generate-instantiate-component changes
@ -958,7 +960,9 @@
{:force-frame? true}) {:force-frame? true})
new-shape (cond-> new-shape new-shape (cond-> new-shape
(nil? (ctk/get-swap-slot new-shape)) ; if the shape isn't inside a main component, it shouldn't have a swap slot
(and (nil? (ctk/get-swap-slot new-shape))
inside-comp?)
(update :touched cfh/set-touched-group (-> (ctf/find-swap-slot shape (update :touched cfh/set-touched-group (-> (ctf/find-swap-slot shape
page page
{:id (:id file) {:id (:id file)

View file

@ -460,9 +460,9 @@
;; TODO: move to common.files.shape-helpers ;; TODO: move to common.files.shape-helpers
(defn- prepare-duplicate-shape-change (defn- prepare-duplicate-shape-change
([changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id] ([changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id]
(prepare-duplicate-shape-change changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id (:frame-id obj) (:parent-id obj) false false)) (prepare-duplicate-shape-change changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id (:frame-id obj) (:parent-id obj) false false true))
([changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id frame-id parent-id duplicating-component? child?] ([changes objects page unames update-unames! ids-map obj delta level-delta libraries library-data it file-id frame-id parent-id duplicating-component? child? remove-swap-slot?]
(cond (cond
(nil? obj) (nil? obj)
changes changes
@ -485,6 +485,7 @@
(ctk/instance-root? obj)) (ctk/instance-root? obj))
duplicating-component? (or duplicating-component? (ctk/instance-head? obj)) duplicating-component? (or duplicating-component? (ctk/instance-head? obj))
is-component-main? (ctk/main-instance? obj) is-component-main? (ctk/main-instance? obj)
subinstance-head? (ctk/subinstance-head? obj)
into-component? (and duplicating-component? into-component? (and duplicating-component?
(ctn/in-any-component? objects parent)) (ctn/in-any-component? objects parent))
@ -507,6 +508,9 @@
:parent-id parent-id :parent-id parent-id
:frame-id frame-id) :frame-id frame-id)
(cond-> (and subinstance-head? remove-swap-slot?)
(ctk/remove-swap-slot))
(dissoc :shapes (dissoc :shapes
:main-instance :main-instance
:use-for-thumbnail) :use-for-thumbnail)
@ -572,7 +576,11 @@
(if frame? new-id frame-id) (if frame? new-id frame-id)
new-id new-id
duplicating-component? duplicating-component?
true)) true
(and remove-swap-slot?
;; only remove swap slot of children when the current shape
;; is not a subinstance head
(not subinstance-head?))))
changes changes
(map (d/getf objects) (:shapes obj))))))) (map (d/getf objects) (:shapes obj)))))))

View file

@ -505,7 +505,9 @@
ids (if (nil? ids) selected ids) ids (if (nil? ids) selected ids)
shapes (into [] shapes (into []
(comp (map (d/getf objects)) (comp (map (d/getf objects))
(remove ctk/in-component-copy-not-head?)) (remove #(let [parent (get objects (:parent-id %))]
(and (ctk/in-component-copy? parent)
(ctl/any-layout? parent)))))
ids) ids)
duplicate-move-started? (get-in state [:workspace-local :duplicate-move-started?] false) duplicate-move-started? (get-in state [:workspace-local :duplicate-move-started?] false)
@ -842,7 +844,13 @@
frame (get objects frame-id) frame (get objects frame-id)
layout? (:layout frame) layout? (:layout frame)
shapes (->> ids (cfh/clean-loops objects) (keep lookup)) component-main-frame (ctn/find-component-main objects frame false)
shapes (->> ids
(cfh/clean-loops objects)
(keep lookup)
;;remove shapes inside copies, because we can't change the structure of copies
(remove #(ctk/in-component-copy? (get objects (:parent-id %)))))
moving-shapes moving-shapes
(cond->> shapes (cond->> shapes
@ -906,9 +914,8 @@
(map :id moving-shapes) (map :id moving-shapes)
moving-shapes-children-ids moving-shapes-children-ids
(->> moving-shapes (->> moving-shapes-ids
(mapcat #(cfh/get-children-with-self objects (:id %))) (mapcat #(cfh/get-children-ids-with-self objects %)))
(map :id))
child-heads child-heads
(->> moving-shapes-ids (->> moving-shapes-ids
@ -921,6 +928,12 @@
;; Remove layout-item properties when moving a shape outside a layout ;; Remove layout-item properties when moving a shape outside a layout
(cond-> (not (ctl/any-layout? objects frame-id)) (cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data)) (pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data))
;; Remove the swap slots if it is moving to a different component
(pcb/update-shapes child-heads
(fn [shape]
(cond-> shape
(not= component-main-frame (ctn/find-component-main objects shape false))
(ctk/remove-swap-slot))))
;; Remove component-root property when moving a shape inside a component ;; Remove component-root property when moving a shape inside a component
(cond-> (ctn/get-instance-root objects frame) (cond-> (ctn/get-instance-root objects frame)
(pcb/update-shapes moving-shapes-children-ids #(dissoc % :component-root))) (pcb/update-shapes moving-shapes-children-ids #(dissoc % :component-root)))