1/**2 * Selecting in the workbench.3 *4 * A lesson teaches that each click builds on the selection, and5 * `chooseMember` is that rule. The workbench is for an author who has not6 * read the lesson: a click selects the one thing clicked, and building on7 * the selection is something the author asks for.8 *9 * The workbench's inspector always describes something, so its selection is10 * never empty. With nothing else selected, the whole composition is.11 */12importtype { Composition } from"./composition.ts";13import { chooseMember } from"./composition-editing.ts";14import { atPath } from"./grouping.ts";1516/** The whole composition's path. */17constwhole="0";1819/** A selection the inspector can describe: `chosen`, or the whole composition. */20exportfunctionsubjectOf(chosen:readonlystring[]):readonlystring[] {21returnchosen.length?chosen: [whole];22}2324/**25 * The selection after the author chooses `path`.26 *27 * Without `extend` it is that one node. With `extend` the choice builds on28 * the selection as `chooseMember` does: a neighbor joins it, a selected29 * member leaves it, and anything else starts again. A member that is the30 * only one selected stays selected. A path that names nothing changes31 * nothing.32 */33exportfunctionselectionAfter(34tree:Composition,35chosen:readonlystring[],36path:string,37extend:boolean,38):readonlystring[] {39if (!atPath(tree, path)) returnchosen;40if (!extend) return [path];41constnext=chooseMember(tree, chosen, path);42returnnext.length?next: [path];43}