mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
✨ Generate variant sets made from components and library set edits
The variant programs now also make sets: transform a component into a variant set (kind make-variant) and combine two components as variants (kind combine), each paired with a switch. The pure runner runs both actions through their common generators with what the frontend events do after them: the reflow of the new board's layout, and a combined board sized 30 px past its mains on each side. Each must leave the components it names as members of one new set in the board, with the same property names; a transform adds a member with a value of its own. The library editor of the stale library programs edits its variant sets too: property edits, added variants, transforms and combines, followed by a library sync and a switch in the consuming file. Their requested results are checked on the library, and an added member takes on the model of the main it duplicates. The test of undoing a library variant a consumer switched to belongs to the previous commit's fix. The stale library programs must cover only the library steps and the operations they are tested with, as the variant programs do; the structure and swap programs cover the rest. A frontend step also waits briefly for an undo transaction its events close on a later tick, as combining variants does, and the golden master transcripts record the components a variant action makes. Harness only; the benchmark is not run. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
9cf5af4aaf
commit
e1decc4812
@ -1870,24 +1870,103 @@
|
||||
(:component-id (tm/node-data situation node)))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Variant actions with no common generator (frontend only)
|
||||
;; Variant actions of the frontend events
|
||||
;;
|
||||
;; Transform a component into a variant, combine components as variants,
|
||||
;; rename a variant, and the shortcuts that add a variant to selected
|
||||
;; members. Their logic is in the `dwv` events, so the frontend
|
||||
;; interpreter sends them and the pure runner rejects them. A set these
|
||||
;; actions build has no `variant-set` record: read it from the file
|
||||
;; (`component-of`, `variant-component-ids`).
|
||||
;; members. The frontend interpreter sends their `dwv` events. The pure
|
||||
;; runner runs the transform and the combine through their common
|
||||
;; generators, with what the events do after them: the reflow of the new
|
||||
;; board's layout, and the size of a combined board; it rejects the rest.
|
||||
;; A set these actions build has no `variant-set` record: read it from the
|
||||
;; file (`component-of`, `variant-component-ids`).
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
(defn- variant-action-changes
|
||||
"The changes of `page` with its objects and the data of `file`."
|
||||
[file page]
|
||||
(-> (pcb/empty-changes nil (:id page))
|
||||
(pcb/with-library-data (:data file))
|
||||
(pcb/with-objects (:objects page))))
|
||||
|
||||
(defn- transform-in-variant-changes
|
||||
"The changes of `transform-in-variant` on the main `main-id` of `file`: a
|
||||
set with a second member, its board laid out."
|
||||
[file main-id]
|
||||
(let [page (thf/current-page file)
|
||||
variant-id (uuid/next)]
|
||||
(-> (variant-action-changes file page)
|
||||
(clv/generate-transform-in-variant main-id variant-id
|
||||
{:layout? true
|
||||
:new-component-id (uuid/next)
|
||||
:new-shape-id (uuid/next)})
|
||||
(with-layouts-reflow [variant-id]))))
|
||||
|
||||
(defn- combine-as-variants-file
|
||||
"The file and changes of `combine-as-variants` on the mains `ids` of
|
||||
`file`, as `[file changes]`: the set, the layouts its mains leave, and
|
||||
its board sized 30 px larger than the mains on each side."
|
||||
[file libraries ids]
|
||||
(let [page (thf/current-page file)
|
||||
objects (:objects page)
|
||||
ids (->> ids
|
||||
(cfh/clean-loops objects)
|
||||
(remove #(let [shape (get objects %)]
|
||||
(or (not (ctk/main-instance? shape)) (ctk/is-variant? shape))))
|
||||
vec)
|
||||
rect (grc/join-rects (map #(:selrect (get objects %)) ids))
|
||||
variant-id (uuid/next)
|
||||
changes (-> (variant-action-changes file page)
|
||||
(clv/generate-combine-as-variants ids variant-id)
|
||||
(with-layouts-reflow (into [variant-id] (map #(:parent-id (get objects %))) ids)))
|
||||
file (thf/apply-changes file changes :validate? false)
|
||||
resize (fn [[file changes] attr value]
|
||||
(let [page (thf/current-page file)
|
||||
board (get (:objects page) variant-id)
|
||||
next (transform-changes page board (geometry-modifiers board attr value)
|
||||
{:file file :libraries libraries})]
|
||||
[(thf/apply-changes file next :validate? false) (pcb/concat-changes changes next)]))]
|
||||
(if (> (count ids) 1)
|
||||
(-> [file changes]
|
||||
(resize :width (+ (:width rect) 60))
|
||||
(resize :height (+ (:height rect) 60)))
|
||||
[file nil])))
|
||||
|
||||
(defn- new-component-ids
|
||||
"The ids of the components that `file-after` has and `file-before` has not."
|
||||
[file-before file-after]
|
||||
(let [before (set (map :id (ctkl/components-seq (:data file-before))))]
|
||||
(into [] (comp (map :id) (remove before)) (ctkl/components-seq (:data file-after)))))
|
||||
|
||||
(defrecord VariantAction [action params]
|
||||
IComponentOperation
|
||||
(op-kind [_] :frontend-only)
|
||||
(op-kind [_] (if (#{:transform :combine} action) :user :frontend-only))
|
||||
|
||||
IAppliedResult
|
||||
(applied-result [_ file-before file-after]
|
||||
{:component-ids (new-component-ids file-before file-after)})
|
||||
|
||||
tm/IOperation
|
||||
(apply-to [_ _]
|
||||
(throw (ex-info (str "variant action " action " runs only in the frontend")
|
||||
{:action action}))))
|
||||
(apply-to [this situation]
|
||||
(let [the-file (tm/file situation)
|
||||
id #(tm/target-shape-id situation %)
|
||||
[file' changes]
|
||||
(case action
|
||||
:transform (let [changes (transform-in-variant-changes the-file (id (:target params)))]
|
||||
[(thf/apply-changes the-file changes :validate? false) changes])
|
||||
;; a selection combines in the order of the layers
|
||||
:combine (let [ids (mapv id (:targets params))
|
||||
ids (if (:selected? params)
|
||||
(vec (cfh/order-by-indexed-shapes (:objects (thf/current-page the-file)) ids))
|
||||
ids)]
|
||||
(combine-as-variants-file the-file (libraries situation) ids))
|
||||
(throw (ex-info (str "variant action " action " runs only in the frontend")
|
||||
{:action action})))]
|
||||
(-> situation
|
||||
(tm/with-file file')
|
||||
(record-changes changes)
|
||||
(tm/record-application this (merge {:action action}
|
||||
(applied-result this the-file file')))))))
|
||||
|
||||
(defn- variant-action
|
||||
[action params]
|
||||
|
||||
@ -371,6 +371,11 @@
|
||||
:variant-property (ctk/is-variant-container? shape)
|
||||
:add-variant (and (ctk/main-instance? shape) (:variant-id shape) (live-component shape)
|
||||
(< (count objects) (get situation :shape-budget 120)))
|
||||
(:make-variant :combine)
|
||||
(and (ctk/main-instance? shape) (not (:variant-id shape)) (live-component shape)
|
||||
(= (:component-file shape) (:id file))
|
||||
(nil? (get-in file [:data :components (:component-id shape) :variant-id]))
|
||||
(< (count objects) (get situation :shape-budget 120)))
|
||||
false))
|
||||
(tree situation))]
|
||||
(case kind
|
||||
@ -412,6 +417,9 @@
|
||||
:shape {:id (:main-instance-id component)
|
||||
:component-id (:id component)}}))
|
||||
vec)
|
||||
:combine (vec (for [[index entry] (map-indexed vector eligible)
|
||||
other (subvec eligible (inc index))]
|
||||
(assoc entry :with other)))
|
||||
:nest (vec (for [entry eligible
|
||||
parent (tree situation)
|
||||
:let [parent-shape (:shape parent)]
|
||||
@ -424,7 +432,13 @@
|
||||
|
||||
(def library-source-kinds
|
||||
#{:library-edit :library-add-child :library-remove-child :library-delete :library-restore
|
||||
:library-undo :library-redo :library-accept :library-transform :library-text :library-text-style})
|
||||
:library-undo :library-redo :library-accept :library-transform :library-text :library-text-style
|
||||
:library-variant-property :library-add-variant :library-make-variant :library-combine})
|
||||
|
||||
(def ^:private local-variant-kind
|
||||
"The local kind of each library variant kind."
|
||||
{:library-variant-property :variant-property :library-add-variant :add-variant
|
||||
:library-make-variant :make-variant :library-combine :combine})
|
||||
|
||||
(defn- library-candidates
|
||||
[situation kind scope]
|
||||
@ -450,21 +464,37 @@
|
||||
:shape {:id (:main-instance-id component) :component-id (:id component)}})
|
||||
(sort-by (comp str :id) (filter :deleted (vals (get-in library [:data :components])))))
|
||||
:else
|
||||
(filter (fn [{:keys [shape]}]
|
||||
(case kind
|
||||
(:library-edit :library-remove-child)
|
||||
(and (= :rect (:type shape)) (nil? (:shape-ref shape)))
|
||||
:library-transform
|
||||
(and (not= :text (:type shape)) (nil? (:shape-ref shape))
|
||||
(if (even? (or scope 0))
|
||||
(ctk/main-instance? shape)
|
||||
(and (not (ctk/main-instance? shape))
|
||||
(some ctk/main-instance?
|
||||
(cfh/get-parents (:objects (thf/current-page library)) (:id shape))))))
|
||||
(:library-text :library-text-style)
|
||||
(and (= :text (:type shape)) (nil? (:shape-ref shape)))
|
||||
(:library-add-child :library-delete) (ctk/main-instance? shape)))
|
||||
(tree (tm/with-file situation library))))]
|
||||
(cond->>
|
||||
(filter (fn [{:keys [shape]}]
|
||||
(case kind
|
||||
:library-variant-property (ctk/is-variant-container? shape)
|
||||
:library-add-variant
|
||||
(and (ctk/main-instance? shape) (:variant-id shape)
|
||||
(not (get-in library [:data :components (:component-id shape) :deleted])))
|
||||
(:library-make-variant :library-combine)
|
||||
(and (ctk/main-instance? shape) (not (:variant-id shape))
|
||||
(= (:component-file shape) library-id)
|
||||
(let [component (get-in library [:data :components (:component-id shape)])]
|
||||
(and component (not (:deleted component)) (nil? (:variant-id component)))))
|
||||
(:library-edit :library-remove-child)
|
||||
(and (= :rect (:type shape)) (nil? (:shape-ref shape)))
|
||||
:library-transform
|
||||
(and (not= :text (:type shape)) (nil? (:shape-ref shape))
|
||||
(if (even? (or scope 0))
|
||||
(ctk/main-instance? shape)
|
||||
(and (not (ctk/main-instance? shape))
|
||||
(some ctk/main-instance?
|
||||
(cfh/get-parents (:objects (thf/current-page library)) (:id shape))))))
|
||||
(:library-text :library-text-style)
|
||||
(and (= :text (:type shape)) (nil? (:shape-ref shape)))
|
||||
(:library-add-child :library-delete) (ctk/main-instance? shape)))
|
||||
(tree (tm/with-file situation library)))
|
||||
(= kind :library-combine)
|
||||
((fn [eligible]
|
||||
(let [eligible (vec eligible)]
|
||||
(for [[index entry] (map-indexed vector eligible)
|
||||
other (subvec eligible (inc index))]
|
||||
(assoc entry :with (update other :path #(into [:library library-index] %)))))))))]
|
||||
(-> entry
|
||||
(assoc :library-id library-id)
|
||||
(update :path #(into [:library library-index] %))))))
|
||||
@ -604,8 +634,11 @@
|
||||
[:data :components (:component-id shape) :variant-id])))))
|
||||
selected (when (seq items) (nth items (mod index (count items))))
|
||||
target (when selected (constantly (get-in selected [:shape :id])))
|
||||
set-edit (when (and selected (= kind :variant-property))
|
||||
(variants/property-edit (variants/set-components (tm/file situation) (get-in selected [:shape :id]))
|
||||
set-edit (when (and selected (#{:variant-property :library-variant-property} kind))
|
||||
(variants/property-edit (variants/set-components (if-let [library-id (:library-id selected)]
|
||||
(get (cf/all-files situation) library-id)
|
||||
(tm/file situation))
|
||||
(get-in selected [:shape :id]))
|
||||
(or property 0) (or value 0) (or scope 0)))
|
||||
property (if (= kind :style) style-property
|
||||
(nth [:fills :opacity :name] (mod (or property 0) 3)))
|
||||
@ -676,11 +709,14 @@
|
||||
:swap (n/swap-shape target (constantly (get-in selected [:destination :shape :component-id])))
|
||||
:switch (n/switch-variant target (:variant-value selected) :pos (:variant-pos selected))
|
||||
:restore (n/restore-component (n/delete-component target))
|
||||
:variant-property (when set-edit
|
||||
(n/edit-variant-set (get-in selected [:shape :id]) (:edit set-edit) (:params set-edit)))
|
||||
:add-variant (n/add-variant nil (get-in selected [:shape :component-id])))))]
|
||||
(:variant-property :library-variant-property) (when set-edit
|
||||
(n/edit-variant-set (get-in selected [:shape :id]) (:edit set-edit) (:params set-edit)))
|
||||
(:add-variant :library-add-variant) (n/add-variant nil (get-in selected [:shape :component-id]))
|
||||
(:make-variant :library-make-variant) (n/transform-in-variant target)
|
||||
(:combine :library-combine) (n/combine-as-variants [target (constantly (get-in selected [:with :shape :id]))]))))]
|
||||
{:op op :library-id (:library-id selected) :shape (:shape selected)
|
||||
:destination (:shape (:destination selected)) :property property :value value :set-edit set-edit
|
||||
:with (:shape (:with selected))
|
||||
:opportunities (if (seq items) (count items) (if (or op (= kind :sync)) 1 0))
|
||||
:trace (cond-> {:kind kind :tuple tuple
|
||||
:status (if (or op (= kind :sync)) :executed :skip)}
|
||||
@ -689,6 +725,7 @@
|
||||
(:destination selected) (assoc :to (get-in selected [:destination :path]))
|
||||
(= kind :switch) (assoc :property-pos (:variant-pos selected))
|
||||
set-edit (assoc :edit (:edit set-edit))
|
||||
(:with selected) (assoc :with (get-in selected [:with :path]))
|
||||
(and (nil? op) (not= kind :sync))
|
||||
(assoc :reason (str "No eligible " (name kind) " target")))}))
|
||||
|
||||
@ -843,10 +880,16 @@
|
||||
tree (gm/set-objects-modifiers {(:id shape) {:modifiers modifiers}} objects)]
|
||||
(gsh/transform-shape shape (get-in tree [(:id shape) :modifiers]))))
|
||||
|
||||
(defn- kind-file
|
||||
"The file an operation edits: the library `library-id`, or the current one."
|
||||
[situation library-id]
|
||||
(if library-id (get (cf/all-files situation) library-id) (tm/file situation)))
|
||||
|
||||
(defn- update-model
|
||||
[model before after {:keys [shape property value op]} kind]
|
||||
[model before after {:keys [shape property value op library-id]} kind]
|
||||
(let [objects (all-objects before)
|
||||
id (:id shape)]
|
||||
id (:id shape)
|
||||
kind (get local-variant-kind kind kind)]
|
||||
(case kind
|
||||
(:edit :style)
|
||||
(cond-> (shadow/edit model shape property value)
|
||||
@ -876,10 +919,12 @@
|
||||
new-main (get-in (cf/libraries after) [(:component-file head) :data :components
|
||||
(:component-id head) :main-instance-id])]
|
||||
(shadow/swap model objects after-objects id old-main new-main (= kind :switch)))
|
||||
:add-variant
|
||||
(let [file (tm/file after)
|
||||
added (:component-id (n/applied-result op (tm/file before) file))]
|
||||
(shadow/duplicate model objects id (:objects (thf/current-page file))
|
||||
(:make-variant :add-variant)
|
||||
(let [file-before (kind-file before library-id)
|
||||
file (kind-file after library-id)
|
||||
result (n/applied-result op file-before file)
|
||||
added (or (:component-id result) (first (:component-ids result)))]
|
||||
(shadow/duplicate model objects id (all-objects after)
|
||||
(get-in file [:data :components added :main-instance-id])))
|
||||
(:resize :rotate :transform)
|
||||
(let [shape-after (requested-geometry before {:shape shape :op op} kind)
|
||||
@ -902,10 +947,10 @@
|
||||
(defn- check-requested-variant-properties
|
||||
"The properties of every member of the edited set are those the edit
|
||||
requested."
|
||||
[after {:keys [shape set-edit]}]
|
||||
[file {:keys [shape set-edit]}]
|
||||
(let [expected (:expected set-edit)
|
||||
actual (into {} (map (juxt :id #(vec (:variant-properties %))))
|
||||
(variants/set-components (tm/file after) (:id shape)))]
|
||||
(variants/set-components file (:id shape)))]
|
||||
(when-not (and (= (set (keys expected)) (set (keys actual)))
|
||||
(every? (fn [[id props]] (variants/properties-match? props (get actual id))) expected))
|
||||
(oracle/fail :I9 {:phase :requested-variant-properties :edit (:edit set-edit)
|
||||
@ -914,14 +959,14 @@
|
||||
(defn- check-requested-variant
|
||||
"The added member is in the set of its source, with the source's
|
||||
properties but a new value of the last one."
|
||||
[before after {:keys [shape op]}]
|
||||
(let [source (get-in (tm/file before) [:data :components (:component-id shape)])
|
||||
added-id (:component-id (n/applied-result op (tm/file before) (tm/file after)))
|
||||
added (some #(when (= added-id (:id %)) %) (variants/set-components (tm/file after) (:variant-id source)))
|
||||
[file-before file {:keys [shape op]}]
|
||||
(let [source (get-in file-before [:data :components (:component-id shape)])
|
||||
added-id (:component-id (n/applied-result op file-before file))
|
||||
added (some #(when (= added-id (:id %)) %) (variants/set-components file (:variant-id source)))
|
||||
source-props (vec (:variant-properties source))
|
||||
props (vec (:variant-properties added))
|
||||
taken (set (map #(:value (peek (vec (:variant-properties %))))
|
||||
(variants/set-components (tm/file before) (:variant-id source))))]
|
||||
(variants/set-components file-before (:variant-id source))))]
|
||||
(when-not (and added
|
||||
(= (mapv :name source-props) (mapv :name props))
|
||||
(= (pop source-props) (pop props))
|
||||
@ -929,6 +974,29 @@
|
||||
(not (contains? taken (:value (peek props)))))
|
||||
(oracle/fail :I9 {:phase :requested-variant :source source-props :added props :taken taken}))))
|
||||
|
||||
(defn- check-requested-variant-set
|
||||
"The components of the mains a transform or a combine names are the
|
||||
members of one new set, whose board holds their mains, with the same
|
||||
property names; a transform adds a member with a value of its own."
|
||||
[file-before file {:keys [shape with op]} kind]
|
||||
(let [added (:component-ids (n/applied-result op file-before file))
|
||||
ids (cond-> [(:component-id shape)]
|
||||
(= kind :combine) (conj (:component-id with))
|
||||
(= kind :make-variant) (into added))
|
||||
components (mapv #(get-in file [:data :components %]) ids)
|
||||
variant-id (:variant-id (first components))
|
||||
members (variants/set-components file variant-id)
|
||||
values (map #(:value (peek (vec (:variant-properties %)))) members)]
|
||||
(when-not (and (some? variant-id)
|
||||
(some #(get-in % [:objects variant-id :is-variant-container]) (vals (get-in file [:data :pages-index])))
|
||||
(every? #(= variant-id (:variant-id %)) components)
|
||||
(= (set ids) (set (map :id members)))
|
||||
(seq (:variant-properties (first members)))
|
||||
(apply = (map #(mapv :name (:variant-properties %)) members))
|
||||
(or (= kind :combine) (apply distinct? values)))
|
||||
(oracle/fail :I9 {:phase :requested-variant-set :kind kind :ids ids
|
||||
:members (mapv (juxt :id :variant-id :variant-properties) members)}))))
|
||||
|
||||
(defn step
|
||||
[state tuple]
|
||||
(let [[kind index] tuple
|
||||
@ -1011,10 +1079,14 @@
|
||||
(when (#{:grid-cell :grid-direction} kind)
|
||||
(oracle/check-requested-grid (tm/shape-by-id after (get-in resolved [:shape :id]))
|
||||
(:shape resolved) (:action op) (:value op)))
|
||||
(when (= kind :variant-property)
|
||||
(check-requested-variant-properties after resolved))
|
||||
(when (= kind :add-variant)
|
||||
(check-requested-variant situation after resolved))
|
||||
(let [variant-kind (get local-variant-kind kind kind)
|
||||
file-before (kind-file situation library-id)
|
||||
file (kind-file after library-id)]
|
||||
(case variant-kind
|
||||
:variant-property (check-requested-variant-properties file resolved)
|
||||
:add-variant (check-requested-variant file-before file resolved)
|
||||
(:make-variant :combine) (check-requested-variant-set file-before file resolved variant-kind)
|
||||
nil))
|
||||
(when (#{:swap :switch} kind)
|
||||
(let [head (tm/shape-by-id after (get-in resolved [:shape :id]))]
|
||||
(when-not (= (get-in resolved [:destination :component-id]) (:component-id head))
|
||||
@ -1214,6 +1286,23 @@
|
||||
(conj [3 (gen/fmap (fn [[index selector choice other target]]
|
||||
[[:variant-property index selector choice other] [:switch target]])
|
||||
(gen/tuple gen/nat gen/nat gen/nat gen/nat gen/nat))])
|
||||
(every? (set kinds) [:library-variant-property :library-sync :switch])
|
||||
(conj [3 (gen/fmap (fn [[index selector choice other target]]
|
||||
[[:library-variant-property index selector choice other]
|
||||
[:library-sync] [:switch target]])
|
||||
(gen/tuple gen/nat gen/nat gen/nat gen/nat gen/nat))])
|
||||
(every? (set kinds) [:library-add-variant :library-make-variant :library-combine
|
||||
:library-sync :switch])
|
||||
(conj [2 (gen/fmap (fn [[kind index target]] [[kind index] [:library-sync] [:switch target]])
|
||||
(gen/tuple (gen/elements [:library-add-variant :library-make-variant
|
||||
:library-combine])
|
||||
gen/nat gen/nat))])
|
||||
(every? (set kinds) [:make-variant :switch])
|
||||
(conj [1 (gen/fmap (fn [[index target]] [[:make-variant index] [:switch target]])
|
||||
(gen/tuple gen/nat gen/nat))])
|
||||
(every? (set kinds) [:combine :switch])
|
||||
(conj [1 (gen/fmap (fn [[index target]] [[:combine index] [:switch target]])
|
||||
(gen/tuple gen/nat gen/nat))])
|
||||
(every? (set kinds) [:add-variant :switch])
|
||||
(conj [1 (gen/fmap (fn [[index target]] [[:add-variant index] [:switch target]])
|
||||
(gen/tuple gen/nat gen/nat))])
|
||||
@ -1266,11 +1355,11 @@
|
||||
:grid-square (= grid :square) :grid-empty (= grid :empty)}]
|
||||
:ops ops}))
|
||||
|
||||
(def variant-kinds (into swap-kinds [:variant-property :add-variant]))
|
||||
(def variant-kinds (into swap-kinds [:variant-property :add-variant :make-variant :combine]))
|
||||
|
||||
(def variant-coverage-kinds
|
||||
"The kinds the variant programs must cover; the swap programs cover the rest."
|
||||
[:variant-property :add-variant :switch :undo :redo :sync])
|
||||
[:variant-property :add-variant :make-variant :combine :switch :undo :redo :sync])
|
||||
|
||||
(def variant-program-gen
|
||||
(gen/let [components (gen/choose 2 3)
|
||||
@ -1304,6 +1393,13 @@
|
||||
(def stale-library-kinds
|
||||
(into (vec (remove #{:update-main} library-kinds)) (sort (disj library-source-kinds :library-accept))))
|
||||
|
||||
(def stale-library-coverage-kinds
|
||||
"The kinds the stale library programs must cover: the library editor's and
|
||||
the consumer's library steps; the structure and swap programs cover the
|
||||
rest."
|
||||
(into [:edit :reset :swap :switch :detach :sync :undo :redo :library-sync]
|
||||
(sort (disj library-source-kinds :library-accept))))
|
||||
|
||||
(def stale-library-program-gen
|
||||
(gen/let [depth (gen/choose 0 2)
|
||||
library-depth (gen/choose 1 2)
|
||||
|
||||
@ -89,10 +89,11 @@
|
||||
|
||||
(defn set-components
|
||||
"The live components of the variant set `variant-id` of `file`, in the
|
||||
order of its container's children."
|
||||
order of the children of its container, on whatever page it is."
|
||||
[file variant-id]
|
||||
(let [data (:data file)
|
||||
objects (:objects (thf/current-page file))]
|
||||
objects (some #(when (contains? (:objects %) variant-id) (:objects %))
|
||||
(vals (:pages-index data)))]
|
||||
(->> (get-in objects [variant-id :shapes])
|
||||
(keep #(get-in data [:components (get-in objects [% :component-id])]))
|
||||
(remove :deleted)
|
||||
|
||||
@ -1726,6 +1726,29 @@
|
||||
[:add-variant 0] [:switch 0] [:variant-property 0 0 0 0] [:switch 14]
|
||||
[:sync 0 0 0 0]]}))))
|
||||
|
||||
(t/deftest generated-transforms-and-combines-make-sets-to-switch-in
|
||||
(let [spec [2 2 {:variants true :rich-variants true :text true}]]
|
||||
(doseq [kind [:make-variant :combine]]
|
||||
(let [result (cg/run {:world spec :ops [[kind 0] [:switch 0] [:variant-property 0 0 0 0]
|
||||
[:undo] [:redo] [:sync 0]]})]
|
||||
(t/is (= 1 (get-in result [:executed kind])))))))
|
||||
|
||||
(t/deftest generated-library-set-edits-reach-the-consumer
|
||||
(let [spec [2 1 {:library true :stale-libraries true :library-variants true :library-text true
|
||||
:library-depth 1 :variants true :rich-variants true :text true :text-styles true}]]
|
||||
(doseq [ops (concat (for [selector (range 5)] [[:library-variant-property 0 selector 1 1]])
|
||||
[[[:library-add-variant 0]] [[:library-make-variant 0]] [[:library-combine 0]]])]
|
||||
(let [result (cg/run {:world spec :ops (into ops [[:library-sync] [:switch 0] [:library-undo]
|
||||
[:library-redo] [:library-sync] [:sync 0]])})]
|
||||
(t/is (= 1 (get-in result [:executed (ffirst ops)])))))))
|
||||
|
||||
(t/deftest undoing-a-library-variant-a-consumer-switched-to-keeps-it-deleted
|
||||
(t/is (map? (cg/run {:world [2 0 {:variants true :text-styles true :library-variants true :stale-libraries true
|
||||
:layout nil :layout-item-margins false :grid-square false :library-depth 1
|
||||
:library true :rich-variants true :layout-children false :library-text true
|
||||
:grid-empty false :layout-copies true :text true}]
|
||||
:ops [[:swap 0 0 0 0] [:library-add-variant 0 0 0 0] [:library-sync] [:switch 0]]}))))
|
||||
|
||||
(t/deftest random-variant-compositions
|
||||
(let [coverage (atom {})
|
||||
failure (atom nil)]
|
||||
@ -1784,8 +1807,8 @@
|
||||
(cg/check-program program coverage failure))
|
||||
:max-size 30)
|
||||
(println "Stale library operation coverage:" (pr-str @coverage))
|
||||
(t/is (empty? (cg/coverage-errors @coverage cg/stale-library-kinds #{:sync}))
|
||||
(pr-str (cg/coverage-errors @coverage cg/stale-library-kinds #{:sync})))))
|
||||
(t/is (empty? (cg/coverage-errors @coverage cg/stale-library-coverage-kinds #{:sync}))
|
||||
(pr-str (cg/coverage-errors @coverage cg/stale-library-coverage-kinds #{:sync})))))
|
||||
|
||||
(t/deftest random-library-dependency-compositions
|
||||
(let [coverage (atom {})
|
||||
|
||||
@ -59,23 +59,23 @@
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"a\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "6d809ac935ee93e1" "144104054c2e6b3e"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :member \"b\", :component-id 7}\n \n {:target #fn, :value \"Value 3\", :pos 0}", :states ["df9a042b9d59d699" "06e9af57624cd581" "55609c964d15c784" "c8d9eaf05aa22931"]}]
|
||||
:case-at-transformed-component-keeps-its-copies
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :transform, :params {:target #fn}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:action :transform, :params {:target #fn}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "cfce0b246967964a" "2c3ef0411b35a158" "0d456e1108bb1756"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "cfce0b246967964a" "2c3ef0411b35a158" "0d456e1108bb1756"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :transform, :params {:target #fn}, :component-ids [6]}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:target #fn, :property :name, :value \"Button/Primary\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}, :component-ids [6]}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "865741f5dae8819e" "7f7bd28b4563fabd" "bca3e99455b8e931" "f8be77e905b63d2f"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:action :transform, :params {:target #fn}, :component-ids [6]}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "cfce0b246967964a" "2c3ef0411b35a158" "0d456e1108bb1756"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n one-of -> \n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}, :component-ids [6]}\n \n {:target #fn, :value \"Value 2\", :pos 0}", :states ["19168567c3f4c8b1" "cfce0b246967964a" "2c3ef0411b35a158" "0d456e1108bb1756"]}]
|
||||
:case-au-combined-components-keep-their-copies
|
||||
[{:transcript " {:component \"first\", :id sync-first-component}\n {:component \"second\", :id sync-second-component}\n {:component \"first\", :copy sync-first-copyhead-0}\n {:component \"second\", :copy sync-second-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :combine, :params {:targets [#fn #fn], :selected? nil}}\n \n {:target #fn, :value #fn, :pos 0}", :states ["61c776d9e973c9dd" "0f68af4cace0f325" "97651ebcd2334fe5" "47fc4c7f440fdc13"]}
|
||||
{:transcript " {:component \"first\", :id sync-first-component}\n {:component \"second\", :id sync-second-component}\n {:component \"first\", :copy sync-first-copyhead-0}\n {:component \"second\", :copy sync-second-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :combine, :params {:targets [#fn #fn], :selected? true}}\n \n {:target #fn, :value #fn, :pos 0}", :states ["61c776d9e973c9dd" "0f68af4cace0f325" "97651ebcd2334fe5" "47fc4c7f440fdc13"]}]
|
||||
[{:transcript " {:component \"first\", :id sync-first-component}\n {:component \"second\", :id sync-second-component}\n {:component \"first\", :copy sync-first-copyhead-0}\n {:component \"second\", :copy sync-second-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :combine, :params {:targets [#fn #fn], :selected? nil}, :component-ids []}\n \n {:target #fn, :value #fn, :pos 0}", :states ["61c776d9e973c9dd" "0f68af4cace0f325" "97651ebcd2334fe5" "47fc4c7f440fdc13"]}
|
||||
{:transcript " {:component \"first\", :id sync-first-component}\n {:component \"second\", :id sync-second-component}\n {:component \"first\", :copy sync-first-copyhead-0}\n {:component \"second\", :copy sync-second-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :combine, :params {:targets [#fn #fn], :selected? true}, :component-ids []}\n \n {:target #fn, :value #fn, :pos 0}", :states ["61c776d9e973c9dd" "0f68af4cace0f325" "97651ebcd2334fe5" "47fc4c7f440fdc13"]}]
|
||||
:case-av-variant-rename-reaches-copy-names
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :name, :value \"Mine\"}\n {:action :rename, :params {:target #fn, :name \"Renamed\"}}", :states ["c6e889ca261596ce" "940f36855f4f991d" "92ebbb582ece2af2"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:action :rename, :params {:target #fn, :name \"Renamed\"}}", :states ["5eb544d7e28709d7" "e76ffcfb4eccd16d"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :name, :value \"Mine\"}\n {:action :rename, :params {:target #fn, :name \"Renamed\"}, :component-ids []}", :states ["c6e889ca261596ce" "940f36855f4f991d" "92ebbb582ece2af2"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n one-of -> \n {:action :rename, :params {:target #fn, :name \"Renamed\"}, :component-ids []}", :states ["5eb544d7e28709d7" "e76ffcfb4eccd16d"]}]
|
||||
:case-aw-variant-layer-rename-and-cleanup
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2, Size=S\"}}\n \n {:set-name \"vset\", :edit :add, :params {:property-name \"Empty\"}}\n {:set-name \"vset\", :edit :remove-empty, :params {}}\n \n {:set-name \"vset\", :edit :rename-in-layers, :params {:member \"a\", :name \"Property 1=a2\"}}\n \n {:set-name \"vset\", :edit :error, :params {:member \"b\", :value \"Duplicated\"}}\n \n {:set-name \"vset\", :edit :error, :params {:member \"b\", :value nil}}\n \n {:target #fn, :value \"b\", :pos 0}", :states ["df9a042b9d59d699" "4b53486972986d97" "8553f89a9ebbcf54" "4b53486972986d97" "d65ad905aa97d661" "6daf5f692c6595f1" "d65ad905aa97d661" "cc7d2dfd618fc8cb" "6390b4d83995b629"]}]
|
||||
:case-ax-variant-shortcuts-add-members
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn]}}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn #fn]}}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}]
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn]}, :component-ids [7]}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn]}, :component-ids [7]}", :states ["df9a042b9d59d699" "43d53bfb72ea0e0c" "419f9e2fc8ad2835"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :create-component, :targets [#fn #fn]}, :component-ids [9 10]}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:variant-set \"vset\", :variant-id sync-vset-vcontainer, :count 2}\n {:component \"main\", :level 0, :outer sync-main-outercomp-0}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :property :fills, :value \"#00ff00\"}\n {:action :shortcut, :params {:kind :duplicate, :targets [#fn #fn]}, :component-ids [9 10]}", :states ["df9a042b9d59d699" "cc394d17823fd4a0" "c3e08163f30218ee"]}]
|
||||
:case-ay-token-on-a-main-reaches-copies
|
||||
[{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :token-name \"radius.s\", :value 10}\n {:target #fn, :token-name \"radius.l\", :value 30}\n \n {:target #fn, :token-name \"radius.l\"}", :states ["04cddffca776d7fb" "24756b13d210f3a5" "8e8c0c21d4a0638b" "f656f9c8188793cf"]}
|
||||
{:transcript " {:component \"main\", :id sync-main-component}\n {:tokens [[\"radius.s\" 10] [\"radius.l\" 30]]}\n {:component \"main\", :copy sync-main-copyhead-0}\n {:target #fn, :token-name \"radius.s\", :value 10}\n {:target #fn, :token-name \"radius.l\", :value 30}\n \n one-of -> ", :states ["04cddffca776d7fb" "24756b13d210f3a5" "8fb17ce46cb883c8"]}
|
||||
|
||||
@ -432,6 +432,11 @@
|
||||
:undo-changes (:undo-changes changes)}
|
||||
opts))))
|
||||
|
||||
(def ^:private undo-transaction-ms
|
||||
"How long a step waits for an undo transaction its events left open; some
|
||||
steps keep one open on purpose, so the wait ends without failing."
|
||||
200)
|
||||
|
||||
(defn- await-ready
|
||||
"A promise that resolves with true once `ready?` holds, polling, or with
|
||||
false after `timeout-ms`."
|
||||
@ -462,6 +467,10 @@
|
||||
(.then (fn [ready]
|
||||
(if ready
|
||||
(-> (pwrf/wait-for-layout-update nil timeout-ms)
|
||||
;; an event may close its undo transaction on a later
|
||||
;; tick, as combining variants does
|
||||
(.then #(await-ready (fn [] (nil? (get-in @st/state [:workspace-undo :transaction])))
|
||||
undo-transaction-ms))
|
||||
(.then (constantly :settled))
|
||||
(.catch (fn [_] {:timeout (wrf/pending)})))
|
||||
{:timeout {:not-ready (wrf/pending)}}))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user