The pool is a tree of what places what, and deletes

A drawing is named by where it is drawn, `body 12`, until it is given a
name of its own. The pool lists each symbol under what places it, with
the root's lanes always showing and anything placed nowhere at the top,
where it wants looking at. Delete or the cross removes a symbol and its
placements, asking first when it is used anywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-10-10 21:38:35 -04:00
parent 4fe620f50a
commit fbcbcd0321
10 changed files with 285 additions and 68 deletions

View file

@ -66,10 +66,56 @@
[sym] [sym]
(= :trace (:type sym))) (= :trace (:type sym)))
(defn symbol-name (defonce ^:private placed-cache (atom nil))
"What to call a symbol: its `:name`, or its id when it has none."
(defn placements
"Where every symbol is placed: `{sid [[owner frame] ...]}`, earliest first,
where `owner` is the symbol whose node places it and `frame` is where in the
owner that node starts.
Cached by IDENTITY of the document, as `raster` caches a palette: a document
is a value, so the same object means the same answer, and names and the pool
ask this once per symbol per render."
[clip]
(let [cached @placed-cache]
(if (identical? clip (:clip cached))
(:index cached)
(let [index (-> (reduce (fn [m [owner sym]]
(reduce (fn [m [_ n]]
(if-let [sid (node/source n)]
(update m sid (fnil conj [])
[owner (:at (node/time-of n))])
m))
m (:nodes sym)))
{} (:symbols clip))
(update-vals #(vec (sort-by second %))))]
(reset! placed-cache {:clip clip :index index})
index))))
(defn owners
"The symbols that place `sid`, each once."
[clip sid] [clip sid]
(or (:name (symbol clip sid)) (name sid))) (into [] (comp (map first) (distinct)) (get (placements clip) sid)))
(defn symbol-name
"What to call a symbol: its `:name`, or where it is when it has none.
A DRAWING IS NAMED BY WHERE IT IS DRAWN. One placed by exactly one symbol
reads as that symbol's name and the frame it starts on — `body 12` — worked
out on every read, so renaming the lane renames its drawings and moving one
renames it. A symbol placed nowhere, or in two places, has no one place to be
named by and reads as its id. A `:name` that is just the id is no name: older
documents stored one on every drawing."
([clip sid] (symbol-name clip sid #{}))
([clip sid seen]
(let [given (:name (symbol clip sid))
[owner :as os] (owners clip sid)]
(cond
(and given (not= given (name sid))) given
(and (= 1 (count os)) (not (seen owner)))
(str (symbol-name clip owner (conj seen sid)) " "
(js/Math.floor (second (first (get (placements clip) sid)))))
:else (name sid)))))
(defn node-label (defn node-label
"What to call node `n` on screen. "What to call node `n` on screen.

View file

@ -253,6 +253,23 @@
[clip sid id] [clip sid id]
(clip/update-symbol clip sid update :nodes #(apply dissoc % (subtree % id)))) (clip/update-symbol clip sid update :nodes #(apply dissoc % (subtree % id))))
(defn delete-symbol
"Symbol `sid` gone from the library, with every node that places it — as
deleting a library item in Flash takes its instances with it. What it placed
stays, placed nowhere now, for whoever deletes it next. `{:clip}`, or
`{:refused why}` for the root, which is what the document opens on."
[clip sid]
(cond
(not (clip/symbol clip sid)) {:refused "there is no such symbol"}
(= sid (clip/opens-on clip)) {:refused "the project opens on this symbol; it cannot be deleted"}
:else
{:clip (reduce (fn [c [owner _]]
(reduce (fn [c [id n]]
(if (= sid (node/source n)) (delete-node c owner id) c))
c (:nodes (clip/symbol c owner))))
(update clip :symbols dissoc sid)
(:symbols clip))}))
(defn- transplant (defn- transplant
"Move node `id` from symbol `host`, where frame `frame` is showing, into symbol "Move node `id` from symbol `host`, where frame `frame` is showing, into symbol
`target`, keeping where it is on screen and when. `carry` is the matrix from `target`, keeping where it is on screen and when. `carry` is the matrix from

View file

@ -701,7 +701,7 @@
(when (clip/symbol clip drawing-id) "the new drawing ID is already used"))] (when (clip/symbol clip drawing-id) "the new drawing ID is already used"))]
{:refused why} {:refused why}
(place (assoc-in clip [:symbols drawing-id] (place (assoc-in clip [:symbols drawing-id]
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}}) {:id drawing-id :frames 1 :nodes {}})
sid id drawing-id at extent true))) sid id drawing-id at extent true)))
(defn reuse-drawing (defn reuse-drawing
@ -774,7 +774,7 @@
(clip/symbol clip drawing-id) "the new drawing ID is already used")] (clip/symbol clip drawing-id) "the new drawing ID is already used")]
{:refused why} {:refused why}
(let [c (assoc-in clip [:symbols drawing-id] (let [c (assoc-in clip [:symbols drawing-id]
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}}) {:id drawing-id :frames 1 :nodes {}})
nodes (assoc nodes id (held id drawing-id at))] nodes (assoc nodes id (held id drawing-id at))]
(claim c sid nodes id extent remainder-id))))) (claim c sid nodes id extent remainder-id)))))
@ -810,10 +810,10 @@
:else :else
(let [c (assoc-in clip [:symbols drawing-id] (let [c (assoc-in clip [:symbols drawing-id]
(if from (if from
;; Its own name: it is a new drawing, and two of one ;; No name: it is a new drawing, named by where it
;; name in the library is a question nobody asked. ;; is drawn, and two of one name is a question nobody asked.
(assoc (clip/symbol clip from) :id drawing-id :name (name drawing-id)) (-> (clip/symbol clip from) (assoc :id drawing-id) (dissoc :name))
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}}))] {:id drawing-id :frames 1 :nodes {}}))]
(if (= f next-lo) (if (= f next-lo)
;; A cel starts right here, so there is no room: make some. ;; A cel starts right here, so there is no room: make some.
(place c sid new-id drawing-id f extent true) (place c sid new-id drawing-id f extent true)

View file

@ -694,9 +694,9 @@
;; a rename coalesce with whatever edit happened next. ;; a rename coalesce with whatever edit happened next.
;; ;;
;; BLANK REMOVES THE NAME rather than storing an empty one. `clip/symbol-name` ;; BLANK REMOVES THE NAME rather than storing an empty one. `clip/symbol-name`
;; falls back to the id, so a symbol cleared of its name reads as `main` ;; falls back to where the symbol is drawn, or its id, so a symbol cleared of
;; again instead of as a row with nothing on it — and the document carries no ;; its name reads as `body 12` or `main` again instead of as a row with
;; field it did not need. ;; nothing on it — and the document carries no field it did not need.
(let [value (not-empty (str/trim (str value)))] (let [value (not-empty (str/trim (str value)))]
(if-not (clip/symbol (:clip (store/entry (:clip/current db))) sid) (if-not (clip/symbol (:clip (store/entry (:clip/current db))) sid)
db db

View file

@ -1163,10 +1163,8 @@
(if (:refused where) (if (:refused where)
(update db :project merge {:status (:refused where)}) (update db :project merge {:status (:refused where)})
(let [seeded (assoc-in document [:symbols sid] (let [seeded (assoc-in document [:symbols sid]
(cond-> {:id sid (cond-> {:id sid :frames 1 :nodes {}}
:name (if palette? "palette transition" (name sid)) palette? (assoc :type :palette :name "palette transition")))
:frames 1 :nodes {}}
palette? (assoc :type :palette)))
result (span/place-symbol seeded st (:sid where) uuid sid (:at where) result (span/place-symbol seeded st (:sid where) uuid sid (:at where)
{:extent :grow-symbol {:extent :grow-symbol
:remainder-id (random-uuid) :remainder-id (random-uuid)
@ -1441,30 +1439,73 @@
(boolean (get-in db [:ui :auto-key?])) st)) (boolean (get-in db [:ui :auto-key?])) st))
% edits)))))) % edits))))))
(rf/reg-event-db (rf/reg-fx
::confirm
(fn [{:keys [message then]}]
(when (js/confirm message) (rf/dispatch then))))
(rf/reg-event-fx
::delete-symbol
;; Out of the library, with its placements; see `nest/delete-symbol`. Its tab
;; closes, and if it was on screen the root takes its place.
;;
;; ASKED FIRST WHEN IT IS PLACED, because then the delete reaches past the row
;; you pointed at, into every symbol that uses it. One placed nowhere goes
;; without a question; undo is there either way.
(fn [{:keys [db]} [_ sid sure?]]
(let [clip (:clip (store/entry (:clip/current db)))
{gone :clip why :refused} (nest/delete-symbol clip sid)
uses (clip/uses clip sid)]
(cond
why
{:db (refused db why)}
(and (pos? uses) (not sure?))
{::confirm {:message (str "Delete " (clip/symbol-name clip sid) "? It is used "
(if (= 1 uses) "once" (str uses " times")) ", in "
(str/join ", " (map #(clip/symbol-name clip %)
(clip/owners clip sid)))
", and every use of it goes too.")
:then [::delete-symbol sid true]}}
:else
(cond-> {:db (-> db
(edit/transaction (constantly gone))
(update-in [:ui :tabs] #(vec (remove #{sid} %)))
(update :ui (fn [ui]
(cond-> ui
(= [:symbol sid] (:selection ui))
(assoc :selection nil :selections [])))))}
(= sid (get-in db [:ui :open]))
(assoc :dispatch [::playback/open-symbol (clip/opens-on gone)]))))))
(rf/reg-event-fx
::delete-selected ::delete-selected
;; Backspace while drawing takes the last point back, as in Illustrator; on ;; Backspace while drawing takes the last point back, as in Illustrator; on
;; the pen, with a point of the selected shape picked, it takes that point. ;; the pen, with a point of the selected shape picked, it takes that point. A
(fn [db _] ;; symbol picked in the pool is deleted from the library.
(fn [{:keys [db]} _]
(let [[vsid vid i] (get-in db [:ui :vertex]) (let [[vsid vid i] (get-in db [:ui :vertex])
primary (get-in db [:ui :selection])] primary (get-in db [:ui :selection])]
(cond (cond
(seq (get-in db [:ui :draft])) (seq (get-in db [:ui :draft]))
(update-in db [:ui :draft] #(subvec % 0 (- (count %) 2))) {:db (update-in db [:ui :draft] #(subvec % 0 (- (count %) 2)))}
(and i (= :pen (get-in db [:ui :tool])) (= [:node vsid vid] (take 3 primary))) (and i (= :pen (get-in db [:ui :tool])) (= [:node vsid vid] (take 3 primary)))
(deleting-vertex db vsid vid i) {:db (deleting-vertex db vsid vid i)}
(= :symbol (first primary))
{:dispatch [::delete-symbol (second primary)]}
:else :else
(let [many (vec (get-in db [:ui :selections])) (let [many (vec (get-in db [:ui :selections]))
selections (if (some #{primary} many) many (if primary [primary] [])) selections (if (some #{primary} many) many (if primary [primary] []))
nodes (distinct (keep (fn [[kind sid id]] (when (= :node kind) [sid id])) selections))] nodes (distinct (keep (fn [[kind sid id]] (when (= :node kind) [sid id])) selections))]
(if (seq nodes) (when (seq nodes)
(-> db {:db (-> db
(edit/transaction #(reduce (fn [c [sid id]] (nest/delete-node c sid id)) % nodes)) (edit/transaction #(reduce (fn [c [sid id]] (nest/delete-node c sid id)) % nodes))
(assoc-in [:ui :selection] nil) (assoc-in [:ui :selection] nil)
(assoc-in [:ui :selections] [])) (assoc-in [:ui :selections] []))}))))))
db))))))
(rf/reg-event-db (rf/reg-event-db
::restack ::restack

View file

@ -15,13 +15,12 @@
looking at and puts the number on its tab. looking at and puts the number on its tab.
THE MAIN TIMELINE LEADS, and it is `clip/opens-on`'s answer rather than a THE MAIN TIMELINE LEADS, and it is `clip/opens-on`'s answer rather than a
name: the longest symbol nothing else places is the one the project plays and name: the symbol the project plays and the one the work happens in, so it gets
the one the work happens in, so it gets the top of the pane and a row drawn at the top of the pane and a row drawn at a size you can read a pose off. Every
a size you can read a pose off. Every other symbol is the list under it. That other symbol is the tree under it: what nothing places beside it at the top,
is one list and not two — every symbol here IS a timeline, and heading a and the rest under whatever places it — see `this-project`. None of it is
section TIMELINES and the next one SYMBOLS would name the same thing twice. `:main` being special either: rename it, place it inside something else, and
None of it is `:main` being special either: rename it, place it inside the pool follows the document.
something else, and the pool follows the document.
Every row is a drag source, and what it carries says what it is: Every row is a drag source, and what it carries says what it is:
`symbol:<id>` for a symbol of this document, `import:<project>|<cid>|<id>` for `symbol:<id>` for a symbol of this document, `import:<project>|<cid>|<id>` for
@ -199,13 +198,27 @@
its own under the name — `sub2` — rather than one of them out at the edge. its own under the name — `sub2` — rather than one of them out at the edge.
`rename` is `{:key :value :begin! :commit!}` and is what makes a row `rename` is `{:key :value :begin! :commit!}` and is what makes a row
renameable at all: a row without one has no pencil and does not answer F2." renameable at all: a row without one has no pencil and does not answer F2.
[{:keys [label sub sub2 title thumb on? open? main? disabled? rename] :as opts}]
`depth` puts a row in a tree: indented that far, with a twisty ahead of it.
`inside` is `{:count :open? :flip!}` for a row with rows under it; a row with
none keeps the twisty's room, so names line up down a level.
`delete!` puts a cross beside the pencil, on hover as the pencil is."
[{:keys [label sub sub2 title thumb on? open? main? disabled? rename depth inside delete!]
:as opts}]
(let [{:keys [key value begin! commit!]} rename (let [{:keys [key value begin! commit!]} rename
editing? (boolean (and key (= key (:editing rename))))] editing? (boolean (and key (= key (:editing rename))))]
[:div.pool-row {:class (str (when main? "main ") (when on? "on ") [:div.pool-row {:class (str (when main? "main ") (when on? "on ")
(when open? "open ") (when disabled? "disabled ") (when open? "open ") (when disabled? "disabled ")
(when editing? "editing"))} (when editing? "editing"))
:style (when depth {:padding-left (+ 4 (* 10 depth))})}
(when depth
(if-let [{:keys [count open? flip!]} inside]
[:span.pool-twisty {:title (str count " inside")
:on-click (fn [^js e] (.stopPropagation e) (flip!))}
(if open? "\u25BE" "\u25B8")]
[:span.pool-twisty]))
(if editing? (if editing?
;; The input REPLACES the row rather than floating over it, so the list ;; The input REPLACES the row rather than floating over it, so the list
;; does not change height while you type in it. ;; does not change height while you type in it.
@ -235,7 +248,7 @@
(.preventDefault e) (.preventDefault e)
(begin! key))))} (begin! key))))}
(dissoc opts :label :sub :sub2 :title :on? :open? :main? (dissoc opts :label :sub :sub2 :title :on? :open? :main?
:disabled? :thumb :rename)) :disabled? :thumb :rename :depth :inside :delete!))
thumb thumb
[:span.text [:span.text
;; The label is `.text`'s first child and stays that way: it is how ;; The label is `.text`'s first child and stays that way: it is how
@ -250,13 +263,19 @@
;; being avoided, and F2 already reaches it from the keyboard. ;; being avoided, and F2 already reaches it from the keyboard.
:on-click (fn [^js e] (.stopPropagation e) (begin! key))} :on-click (fn [^js e] (.stopPropagation e) (begin! key))}
"\u270E"]) "\u270E"])
(when delete!
[:span.pool-rename.pool-delete
{:title (str "delete " label " (Delete)")
:on-click (fn [^js e] (.stopPropagation e) (delete!))}
"\u00D7"])
;; The main row says both its facts under the name instead. ;; The main row says both its facts under the name instead.
(when (and sub (not main?)) [:span.sub sub])]])])) (when (and sub (not main?)) [:span.sub sub])]])]))
;; --------------------------------------------------------------------------- ;; ---------------------------------------------------------------------------
;; the rows of each kind ;; the rows of each kind
(defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename]}] (defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename
depth inside]}]
(let [sym (clip/symbol document sid) (let [sym (clip/symbol document sid)
label (clip/symbol-name document sid) label (clip/symbol-name document sid)
nodes (count (:nodes sym))] nodes (count (:nodes sym))]
@ -276,6 +295,9 @@
:on? (= selection [:symbol sid]) :on? (= selection [:symbol sid])
:open? (= sid open) :open? (= sid open)
:main? (= sid main) :main? (= sid main)
:depth depth
:inside inside
:delete! (when-not (= sid main) #(rf/dispatch [::ui/delete-symbol sid]))
:rename (assoc rename :rename (assoc rename
:key [:symbol sid] :key [:symbol sid]
:value label :value label
@ -427,23 +449,62 @@
[:div.pool-empty "no match in this scope"] [:div.pool-empty "no match in this scope"]
(into [:<>] (map section) children))) (into [:<>] (map section) children)))
(def ^:private own-section?
"Symbols with a section of their own, kept out of the tree."
#{:palette :palette-track :trace})
(defn- listed? [document sid]
(not (own-section? (:type (clip/symbol document sid)))))
(defn- placed-in
"What each symbol places, as `{owner [sid ...]}`: each once, in the order they
first start in it."
[document]
(reduce-kv (fn [m sid at]
(if (listed? document sid)
(reduce-kv (fn [m owner [[_ f]]] (update m owner (fnil conj []) [f sid]))
m (group-by first at))
m))
{} (clip/placements document)))
(defn- tree
"`sid`'s row and, while it is open, the rows of what it places under it. A
symbol placed in two symbols is under both. `path` is what this row is under,
which keys the row and stops a cycle."
[{:keys [document placed expanded flip! main] :as ctx} sid depth path]
(let [kids (->> (get placed sid) (sort-by (juxt first (comp str second)))
(map second) (remove (set (conj path sid))))
root? (and (= main sid) (empty? path))
open? (and (seq kids) (or root? (contains? expanded [path sid])))]
(into [(with-meta (symbol-row document sid
(assoc ctx :depth depth
:inside (when (and (seq kids) (not root?))
{:count (count kids) :open? open?
:flip! #(flip! [path sid])})))
{:key (str (conj path sid))})]
(when open?
(mapcat #(tree ctx % (inc depth) (conj path sid)) kids)))))
(defn- this-project (defn- this-project
"The open document's own, with the main timeline at the top and every other "The open document's own: its symbols as the tree of what places what, then
symbol under it. each kind with a section of its own.
NOT \"TIMELINES AND SYMBOLS\". Every symbol in this model IS a timeline — it WHAT NOTHING PLACES IS AT THE TOP, and everything else is under what places
has frames and nodes and you open it and work in it — so a pair of headings it. Drawing makes a symbol per drawing, and a flat list of every one buries the
naming those two things names one thing twice, and invites a reader to go few that matter; a drawing is under its lane, its lane under its scene. What
looking for the difference. There is one list of symbols. What is true is that is left at the top is the root the project opens on, drawn big and first with
exactly one of them is where the work happens: `clip/opens-on`'s answer, the what it places always showing under it, and
longest symbol nothing else places. That gets the top of the pane and a row whatever is placed nowhere — a scene, something made to be placed later, or
drawn like the thing it is, and the rest of the library is the list below it. something left behind — which is what wants looking at: keep it, place it, or
delete it. Nothing is ever cleared away for you.
Still not `:main` being special. The document says which symbol that is by its One rule for every symbol, worked out from the document on each render and
structure; rename it, place it inside something else, and the pool follows." stored nowhere: place it, unplace it, and the pool follows.
A SEARCH IS FLAT: you asked for it by name, and a hit inside a closed twisty is
a hit you cannot see."
[{:keys [document query searching? media sounds images chosen rename main selection] :as ctx}] [{:keys [document query searching? media sounds images chosen rename main selection] :as ctx}]
(let [named? #(hit? query (clip/symbol-name document %)) (let [named? #(hit? query (clip/symbol-name document %))
top (when (and main (named? main)) main)
symbol-ids (sort-by str (keys (:symbols document))) symbol-ids (sort-by str (keys (:symbols document)))
transition-ids (into #{} (mapcat (fn [sym] transition-ids (into #{} (mapcat (fn [sym]
(when (= :palette-track (:type sym)) (when (= :palette-track (:type sym))
@ -454,22 +515,24 @@
transitions (filterv #(and (named? %) (transition? %)) symbol-ids) transitions (filterv #(and (named? %) (transition? %)) symbol-ids)
tracing (filterv #(and (named? %) (clip/trace? (clip/symbol document %))) tracing (filterv #(and (named? %) (clip/trace? (clip/symbol document %)))
symbol-ids) symbol-ids)
rest (filterv #(and (named? %) (not= main %) listed (filterv #(listed? document %) symbol-ids)
(not (#{:palette :palette-track :trace} symbols (if searching?
(:type (clip/symbol document %))))) (mapv #(symbol-row document % ctx) (filterv named? listed))
symbol-ids) (let [ctx (assoc ctx :placed (placed-in document))
top (cond->> (filterv #(and (not= main %)
(empty? (clip/owners document %)))
listed)
(contains? (:symbols document) main) (into [main]))]
(into [] (mapcat #(tree ctx % 0 [])) top)))
media (filterv #(hit? query (:label %)) media) media (filterv #(hit? query (:label %)) media)
sounds (filterv #(hit? query (:label %)) sounds) sounds (filterv #(hit? query (:label %)) sounds)
images (filterv #(hit? query (:label %)) images)] images (filterv #(hit? query (:label %)) images)]
[sections searching? [sections searching?
(+ (if top 1 0) (count rest) (count transitions) (count tracing) (+ (count symbols) (count transitions) (count tracing)
(count media) (count sounds) (count images)) (count media) (count sounds) (count images))
[{:title "project" :searching? searching? [{:title "symbols" :searching? searching?
:blank "nothing to open yet" :blank "nothing to open yet"
:rows (when top [(symbol-row document top ctx)])} :rows symbols}
{:title "symbols" :searching? searching?
:blank "nothing else in the library"
:rows (mapv #(symbol-row document % ctx) rest)}
{:title "tracing layers" :searching? searching? {:title "tracing layers" :searching? searching?
:blank "no tracing layers yet" :blank "no tracing layers yet"
:rows (mapv #(symbol-row document % ctx) tracing)} :rows (mapv #(symbol-row document % ctx) tracing)}
@ -559,7 +622,10 @@
;; Which row is being renamed, as `[kind id]`. One atom rather ;; Which row is being renamed, as `[kind id]`. One atom rather
;; than a flag per row: exactly one name is ever being edited, and ;; than a flag per row: exactly one name is ever being edited, and
;; opening a second input has to close the first. ;; opening a second input has to close the first.
editing (r/atom nil)] editing (r/atom nil)
;; Which tree rows are open, as `[path sid]`. Everything under
;; the root's own children starts shut — see `tree`.
expanded (r/atom #{})]
(let [{:keys [loading? status available sounds images uploaded chosen]} (let [{:keys [loading? status available sounds images uploaded chosen]}
@(rf/subscribe [::playback/footage]) @(rf/subscribe [::playback/footage])
document @(rf/subscribe [::sub/settled-clip]) document @(rf/subscribe [::sub/settled-clip])
@ -596,7 +662,9 @@
;; else places is the timeline the work happens in, and it is the ;; else places is the timeline the work happens in, and it is the
;; one row in this pane drawn big enough to read a pose off. ;; one row in this pane drawn big enough to read a pose off.
:main (clip/opens-on document) :main (clip/opens-on document)
:rename {:editing @editing :begin! #(reset! editing %)}} :rename {:editing @editing :begin! #(reset! editing %)}
:expanded @expanded
:flip! #(swap! expanded (fn [open] (if (open %) (disj open %) (conj open %))))}
tallies (counts ctx) tallies (counts ctx)
files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))] files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))]
[:section.pane.pool [:section.pane.pool

View file

@ -267,6 +267,25 @@
(is (= (get-in c [:symbols :outer :nodes]) (is (= (get-in c [:symbols :outer :nodes])
(get-in (leaf/clip "c" (leaf/leaves "c" c)) [:symbols :outer :nodes])))))) (get-in (leaf/clip "c" (leaf/leaves "c" c)) [:symbols :outer :nodes]))))))
(deftest a-drawing-is-named-by-where-it-is-drawn
(let [c (assoc-in (nested) [:symbols :outer :name] "body")]
(testing "placed by one symbol: that symbol's name and the frame it starts on"
(is (= [:outer] (clip/owners c :inner)))
(is (= "body 5" (clip/symbol-name c :inner)))
(is (= "lane 5" (clip/symbol-name (assoc-in c [:symbols :outer :name] "lane") :inner))
"renaming the lane renames its drawings"))
(testing "a name of its own wins, and one that is only the id is no name"
(is (= "hand" (clip/symbol-name (assoc-in c [:symbols :inner :name] "hand") :inner)))
(is (= "body 5" (clip/symbol-name (assoc-in c [:symbols :inner :name] "inner") :inner))))
(testing "placed nowhere, or in two symbols, it is its id"
(is (= "loose" (clip/symbol-name c :loose)))
(is (= "inner" (clip/symbol-name (clip/place-symbol c nil :loose :inner 0 (random-uuid) nil)
:inner))))
(testing "a cycle of unnamed symbols ends rather than recurring"
(let [loop (clip/place-symbol (update-in c [:symbols :outer] dissoc :name)
nil :inner :outer 0 (random-uuid) nil)]
(is (string? (clip/symbol-name loop :inner)))))))
(deftest an-instance-is-labelled-by-what-it-places (deftest an-instance-is-labelled-by-what-it-places
(let [c (-> (nested) (let [c (-> (nested)
(assoc-in [:symbols :inner :name] "mouth")) (assoc-in [:symbols :inner :name] "mouth"))
@ -278,9 +297,9 @@
(is (= "mouth" (clip/node-label c id n))) (is (= "mouth" (clip/node-label c id n)))
(is (= "jaw" (clip/node-label (assoc-in c [:symbols :inner :name] "jaw") id n)) (is (= "jaw" (clip/node-label (assoc-in c [:symbols :inner :name] "jaw") id n))
"renaming the symbol renames every row that shows an instance of it")) "renaming the symbol renames every row that shows an instance of it"))
(testing "an unnamed symbol falls back to its id, not to the node's uuid" (testing "an unnamed symbol is named by where it is drawn, not by the node's uuid"
(is (= "inner" (clip/node-label (update-in c [:symbols :inner] dissoc :name) (is (= "outer 5" (clip/node-label (update-in c [:symbols :inner] dissoc :name)
id n)))) id n))))
(testing "and a name left on the instance is not read: it has none of its own" (testing "and a name left on the instance is not read: it has none of its own"
(is (= "mouth" (clip/node-label c id (assoc n :name "left eye"))))) (is (= "mouth" (clip/node-label c id (assoc n :name "left eye")))))
(testing "every placement of a symbol is counted" (testing "every placement of a symbol is counted"

View file

@ -560,3 +560,16 @@
(is (near? [10 90] (piv c))) (is (near? [10 90] (piv c)))
(is (near? [10 90] (piv grown)) (is (near? [10 90] (piv grown))
"the pivot moved because something else was drawn, which is the bug"))) "the pivot moved because something else was drawn, which is the bug")))
(deftest deleting-a-symbol-takes-its-placements-and-leaves-what-it-placed
(let [c (-> (clip/blank)
(assoc-in [:symbols :lane] {:id :lane :frames 10 :nodes {}})
(assoc-in [:symbols :cel] {:id :cel :frames 1 :nodes {}})
(clip/place-symbol nil :main :lane 0 (random-uuid) nil)
(clip/place-symbol nil :lane :cel 3 (random-uuid) nil))
{gone :clip} (nest/delete-symbol c :lane)]
(is (nil? (clip/symbol gone :lane)))
(is (empty? (:nodes (clip/symbol gone :main))) "its instance in the root went with it")
(is (clip/symbol gone :cel) "what it placed stays")
(is (empty? (clip/owners gone :cel)) "placed nowhere now")
(is (:refused (nest/delete-symbol c :main)) "the root cannot be deleted")))

View file

@ -67,11 +67,11 @@
:kind :instance :parent :root :z "a1" :kind :instance :parent :root :z "a1"
:source {:symbol :sym/face}} :source {:symbol :sym/face}}
:a-rect {:id :a-rect :kind :rect :parent :root :z "a3"}}} :a-rect {:id :a-rect :kind :rect :parent :root :z "a3"}}}
:sym/face {:frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}}) :sym/face {:name "head" :frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}})
(deftest the-picker-offers-every-symbol-then-every-instance-in-the-open-one (deftest the-picker-offers-every-symbol-then-every-instance-in-the-open-one
(let [ts (export/targets clip :main)] (let [ts (export/targets clip :main)]
(is (= ["main" "face" "face 1" "face 2"] (mapv :label ts)) (is (= ["main" "face" "head 1" "head 2"] (mapv :label ts))
"every symbol, then the instances in the open one") "every symbol, then the instances in the open one")
(testing "the instances isolate a node in the open symbol and the symbols do not" (testing "the instances isolate a node in the open symbol and the symbols do not"
(is (= [nil nil] (mapv :isolate (take 2 ts)))) (is (= [nil nil] (mapv :isolate (take 2 ts))))

View file

@ -600,6 +600,19 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
} }
.pool-row:hover:not(.disabled) { background: #fff; } .pool-row:hover:not(.disabled) { background: #fff; }
/* A tree row's disclosure: what this symbol places, shut until asked. A row
with nothing under it keeps the width, so names line up down a level. */
.pool-twisty {
flex: none;
width: 10px;
color: var(--dim);
cursor: pointer;
text-align: center;
user-select: none;
}
.pool-twisty:empty { cursor: default; }
.pool-twisty:hover:not(:empty) { color: var(--fg); }
.pool-row.on { background: var(--sel-bg); border-color: var(--sel); } .pool-row.on { background: var(--sel-bg); border-color: var(--sel); }
/* WHICH ONE IS OPEN, as a mark and not as the word "open" — a list this narrow /* WHICH ONE IS OPEN, as a mark and not as the word "open" — a list this narrow