mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
✨ Transform shapes in the groups and bools of copies
The random histories never transformed a copy shape inside a group or a bool. They now do, where the board around the group has no layout. Inside a layout, a move of a group's shape makes the layout move the group back, and its siblings with it, with nothing authored; that stays out until it is decided. The oracle learns: - the shapes of a group or bool take their place from the board around it, or from the nearest group or bool on the way that authors its geometry; - the geometry check leaves groups and bools out, as their bounds come from their children, which it checks. The frontend replay realises the token value edit as the token form commits it, with its propagation. Test: the-shapes-of-a-moved-copy-group-follow-it; shape structure programs pass (seeds 8101 at 150, 8102 at 300). Harness only; the benchmark is not run. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
6a5aa99f79
commit
47603c4aa9
@ -388,9 +388,11 @@
|
||||
(not (ctk/main-instance? shape))
|
||||
(some ctk/main-instance? (cfh/get-parents objects (:id shape))))
|
||||
;; the model places the children of a group in a
|
||||
;; copy only as far as the group's board lets it
|
||||
;; copy through the board around it, and only when
|
||||
;; no layout places that group
|
||||
2 (and (:shape-ref shape) (nil? (:component-id shape))
|
||||
(not (#{:group :bool} (:type (get objects (:parent-id shape))))))
|
||||
(or (not (#{:group :bool} (:type (get objects (:parent-id shape)))))
|
||||
(not (ctl/any-layout? (get objects (:frame-id shape))))))
|
||||
3 (and (copy-head shape) (not (top-copy shape)))
|
||||
4 (top-copy shape)))
|
||||
(:text :text-style) (= :text (:type shape))
|
||||
|
||||
@ -433,12 +433,17 @@
|
||||
(d/without-nils (select-keys shape [:constraints-h :constraints-v]))))
|
||||
main-parent (get main-objects (:parent-id main))
|
||||
;; a group or bool takes its bounds and turn from its children,
|
||||
;; so they take their place from the board around it
|
||||
board? (and (#{:group :bool} (:type parent)) main-parent
|
||||
(#{:group :bool} (:type main-parent))
|
||||
(not (ctl/any-layout? (get objects (:frame-id shape)))))
|
||||
parent (if board? (get objects (:frame-id shape)) parent)
|
||||
main-parent (if board? (get main-objects (:frame-id main)) main-parent)
|
||||
;; so they take their place from the board around it, or from
|
||||
;; the nearest group or bool on the way that authors its geometry
|
||||
[parent main-parent]
|
||||
(if (ctl/any-layout? (get objects (:frame-id shape)))
|
||||
[parent main-parent]
|
||||
(loop [parent parent main-parent main-parent]
|
||||
(if (and (#{:group :bool} (:type parent))
|
||||
(#{:group :bool} (:type main-parent))
|
||||
(not (contains? (:touched parent) :geometry-group)))
|
||||
(recur (get objects (:parent-id parent)) (get main-objects (:parent-id main-parent)))
|
||||
[parent main-parent])))
|
||||
;; a reset refreshes its subtree from the loaded library while
|
||||
;; the parent keeps the version it accepted, which may lack a turn;
|
||||
;; a swapped parent holds the child in the main of its content
|
||||
@ -838,7 +843,8 @@
|
||||
:let [group (some (fn [[group candidate]] (when (= unit candidate) group)) shadow/text-groups)]
|
||||
:when (not (contains? touched group))]
|
||||
(fail :I4 {:shape (:name shape) :group group :unit unit})))))
|
||||
(when-not (contains? touched :geometry-group)
|
||||
;; a group or bool takes its bounds from its children, which are checked
|
||||
(when-not (or (contains? touched :geometry-group) (#{:group :bool} (:type shape)))
|
||||
(let [expected (expected-geometry file container libraries shape
|
||||
#(cf/reference-libraries situation %))
|
||||
attrs (cond-> (geometry-differences (:objects page) shape expected)
|
||||
|
||||
@ -2477,21 +2477,26 @@
|
||||
:layout-copies false :layout-children true}]
|
||||
:ops [[:add-child 5] [:structure 12] [:transform 12 10 0 12]]}))))
|
||||
|
||||
(t/deftest the-shapes-of-a-moved-copy-group-follow-it
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants false :rich-variants false :text false :layout :flex
|
||||
:layout-copies false :layout-children true}]
|
||||
:ops [[:add-child] [:structure 9] [:transform 10 0 0 12]]}))))
|
||||
|
||||
(t/deftest syncing-a-copy-group-keeps-the-place-its-shape-authors
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid
|
||||
:layout-copies false :layout-children false}]
|
||||
:ops [[:add-child 1] [:structure 2] [:transform 2 0 0 2]]}))))
|
||||
|
||||
(t/deftest syncing-a-copy-group-keeps-the-size-its-shape-authors
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid
|
||||
:layout-copies false :layout-children false}]
|
||||
:ops [[:add-child 1] [:structure 2] [:transform 2 2 0 2]]}))))
|
||||
|
||||
(t/deftest undoing-a-turn-of-a-copy-group-gives-the-groups-of-its-copies-their-bounds-back
|
||||
(t/is (map? (cg/run {:world [2 2 {:variants true :rich-variants true :text true :layout nil
|
||||
:layout-copies false :layout-children false}]
|
||||
:ops [[:add-child 7] [:add-child 7] [:structure 13] [:transform 10 15 0 12]]}))))
|
||||
|
||||
(t/deftest syncing-a-copy-group-keeps-the-size-its-shape-authors
|
||||
(t/is (map? (cg/run {:world [1 0 {:variants true :rich-variants false :text false :layout :grid
|
||||
:layout-copies false :layout-children false}]
|
||||
:ops [[:add-child 1] [:structure 2] [:transform 2 2 0 2]]}))))
|
||||
|
||||
(t/deftest settling-a-bool-in-a-grid-copy-twice-keeps-its-shapes-in-place
|
||||
(t/is (map? (cg/run {:world [3 0 {:variants true :rich-variants true :text true :layout :grid
|
||||
:layout-copies true :layout-children true}]
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
[app.common.test-helpers.ids-map :as cthi]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.changes :as dch]
|
||||
[app.main.data.workspace :as dw]
|
||||
@ -40,6 +41,8 @@
|
||||
[app.main.data.workspace.texts :as dwtx]
|
||||
[app.main.data.workspace.thumbnails :as dwth]
|
||||
[app.main.data.workspace.tokens.application :as dwta]
|
||||
[app.main.data.workspace.tokens.library-edit :as dwtl]
|
||||
[app.main.data.workspace.tokens.propagation :as dwtp]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.main.data.workspace.variants :as dwv]
|
||||
@ -257,6 +260,15 @@
|
||||
:token token
|
||||
:on-update-shape dwta/update-shape-radius})])
|
||||
|
||||
(instance? n/EditTokenValue op)
|
||||
;; as the token form commits an edit: the token, then its propagation
|
||||
(let [data (:data (current-file))
|
||||
lib (cfo/get-tokens-lib data)
|
||||
token-set (ctob/get-set-by-name lib "composable")
|
||||
token (ctob/get-token-by-name lib "composable" (:token-name op))]
|
||||
[(dwtl/update-token (ctob/get-id token-set) (:id token) {:value (:value op)})
|
||||
(dwtp/propagate-workspace-tokens)])
|
||||
|
||||
(instance? n/UnapplyToken op)
|
||||
[(dwta/unapply-token {:shape-ids [(tm/target-shape-id situation (:target op))]
|
||||
:attributes n/radius-attrs
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user