foldkit-builder 0.3.13 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["Settings","EditWords"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;qBA4Ca,OAAK,OAAA;qBACL,UAAQ,OAAA;;qBAGR,QAAM,OAAA,SAAA,OAAA;;;;;;;;;;;;;;;qBACN,YAAY,eAAe;;qBAG3B,WAAS,OAAA,SAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;qBAIT,UAAQ,OAAA;YACT,kBAAkB,SAAS;;qBAG1B,YAAU,OAAA,gBAAA,OAAA;;;;;YAIX,oBAAoB,WAAW;;qBAG9B,MAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoBL,cAAc,KAAK;;qBAGlB,cAAY,OAAA,gBAAA,OAAA,QAAA,OAAA,QAAA,OAAA,SAAA,OAAA;YAMb,sBAAsB,aAAa;qBAElC,OAAK,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoDN,eAAe,MAAM;;iBAGhB;;WAEN;WACA,UAAUA;WACV,OAAOA;;;iBAID;WACN,IAAI;WACJ,OAAO;;WAEP,OAAO;;;;;WAKP,IAAI,SAAS,eAAe;;qBA0B1B,mCAAO;;IAGN,IAAE,OAAA,MAAA,OAAA;;;;;IAGH,IAAE,OAAA,MAAA,OAAA;;;;;;IAIF,IAAE,OAAA,MAAA;;;;IAEE,OAAK,OAAA;IAAiB,IAAE,OAAA,gBAAA,OAAA;;;;;;;;;;IAErB,IAAE,OAAA,MAAA,OAAA;IAAU,IAAE,OAAA,gBAAA,OAAA;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkqCR,YAAA,YAAU,OAAS,SAAS,KAAK,OAAO,SAAS,uCAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsBxD,WAAA,UAAA,UAAQ,UAAY,OAAO,OAAO,SAAO,OAAS,mBAAc,OAAA;;;;;;;;;;IAG/D,YAAA,UAAA,UAAQ,UAAY,OAAO,OAAO,SAAO,oBAAiB,OAAA;;;;;;;;;;;IAS7D,SAAA,UAAA,UAAQ,SAAW,YAAU,QAAU,QAAM,MAAQ,aAAQ,OAAA;;;;;;;;;;;;;IAhEzE,aAAA,OAAA,KAAK,yCAAuC,aACxC,WACA,sBACV,OAAO,OAAO;IAiBR,aAAA,OAAA,KAAK,mBAAiB,aAClB,WACA,sBACV,OAAO,OAAO;;;;;IAl6BR,aAAA,OAAA,KAAK,8CACX,OAAO,OAAO"}
@@ -1,10 +1,10 @@
1
1
  import { Effect, Option, Result, Schema } from "effect";
2
2
  import { Bundle } from "foldkit-bundle";
3
- import { Block, Catalog, Composition, NodeId, fieldsOf, spaced } from "foldkit-composition";
3
+ import { Block, Catalog, Composition, NodeId } from "foldkit-composition";
4
4
  import { Renderer, fieldName, fieldOf } from "foldkit-composition/foldkit";
5
- import { Form, Input, fillWords } from "foldkit-form";
6
- import { Entity, Words } from "foldkit-entity";
7
- import { Metadata } from "foldkit-metadata";
5
+ import { Input, fillWords } from "foldkit-form";
6
+ import { controlOf, controls, inputOf, inputOf as inputOf$1, settingsOf, settingsOf as settingsOf$1 } from "./settings.js";
7
+ import { editWords, editWords as editWords$1 } from "./words.js";
8
8
  import { copyText, readText } from "foldkit-primitives/dom";
9
9
  import { LiveAnnounce, TreeNavigation } from "foldkit-primitives/interaction";
10
10
  import { History, HistoryModel } from "foldkit-primitives/state";
@@ -12,171 +12,6 @@ import * as Command from "foldkit/command";
12
12
  import { inertHtml } from "foldkit/html";
13
13
  import { defineMessageUnion } from "foldkit/message";
14
14
  import * as Submodel from "foldkit/submodel";
15
- // src/settings.ts
16
- /**
17
- * A node's values as `foldkit-form` forms: a Block's props, and the input of
18
- * each action an event runs. The inspector edits a node through them. The
19
- * Document owns the values; a form holds only what a field shows, including
20
- * text that does not decode yet (a number typed as "1."), and each change
21
- * that decodes becomes one Operation.
22
- */
23
- const controlsKey = Metadata.key("foldkit-builder/controls", {
24
- merge: (records) => [Object.assign({}, ...records)],
25
- summarize: (record) => Object.entries(record).map(([key, control]) => `${key}: ${control.kind}`).join(", ")
26
- });
27
- /**
28
- * Block metadata: the control the inspector draws a prop with, where its
29
- * Schema alone does not say, as
30
- * `Heading.pipe(Block.annotate(Builder.controls({ text: Input.multiline() })))`.
31
- * `Input.hidden()` leaves a prop out of the inspector.
32
- */
33
- const controls = (given) => controlsKey.of(given);
34
- /** A prop's words: its Schema's `title`, else its key spaced, and its description. */
35
- const wordsOf = (key, schema) => {
36
- const { title, description } = Words.of(schema);
37
- return {
38
- label: Option.getOrElse(title, () => spaced(key)),
39
- description
40
- };
41
- };
42
- /** A form over `fields`, named `name`, with the controls `hints` asks for. */
43
- const make = (name, fields, hints) => {
44
- const resolve = (key, schema) => hints[key] ?? Input.resolve(Entity.unmapped, schema);
45
- const editable = Object.entries(fields).filter(([key, schema]) => resolve(key, Schema.toEncoded(schema)) !== void 0);
46
- const decoders = Object.fromEntries(editable.map(([key, schema]) => [key, Schema.decodeUnknownResult(schema)]));
47
- const Props = Schema.Struct(Object.fromEntries(editable.map(([key, schema]) => [key, Schema.toEncoded(schema).check(Schema.makeFilter((value) => Result.match(decoders[key](value), {
48
- onSuccess: () => void 0,
49
- onFailure: (error) => error.message
50
- })))])));
51
- const labels = Object.fromEntries(editable.map(([key, schema]) => {
52
- const { label, description } = wordsOf(key, schema);
53
- return [key, Form.label(label, Option.getOrUndefined(description))];
54
- }));
55
- const entity = Entity.define(name, Props).pipe(Entity.annotateMembers(labels));
56
- const form = Form.make(name, Entity.input(entity, Props), { inputs: hints });
57
- if (form.bundle.subscriptions !== void 0 || form.bundle.resources !== void 0) throw new Error(`Builder: "${name}" has a control with Subscriptions or Resources (an Input.bundle), which the inspector cannot run; give it a control that needs neither`);
58
- const encodeModel = Schema.encodeSync(form.bundle.Model);
59
- const decodeModel = Schema.decodeUnknownResult(form.bundle.Model);
60
- const encodeMessage = Schema.encodeSync(form.bundle.Message);
61
- const decodeMessage = Schema.decodeUnknownResult(form.bundle.Message, { onExcessProperty: "error" });
62
- return {
63
- form,
64
- /** Every key the form's Schema names, edited or shown. */
65
- keys: Object.keys(fields),
66
- /** The props the form does not edit, labelled as its fields are, and as stored: shown, not changed. */
67
- shown: (stored) => Object.entries(fields).filter(([key]) => !Object.hasOwn(decoders, key)).map(([key, schema]) => ({
68
- key,
69
- label: wordsOf(key, schema).label,
70
- value: stored[key]
71
- })),
72
- /**
73
- * `model` with the fields `keep` spares filled from a node's stored props.
74
- * A stored prop that does not decode is shown as it is, with its error.
75
- */
76
- fill: (model, stored, keep = () => false) => {
77
- const keys = Object.keys(decoders).filter((key) => !keep(key));
78
- const filled = form.fill(model, Object.fromEntries(keys.map((key) => [key, stored[key]]))).model;
79
- return keys.filter((key) => stored[key] !== void 0 && Result.isFailure(decoders[key](stored[key]))).reduce((next, key) => form.bundle.update(next, form.Message.Blurred({ key }), void 0).model, filled);
80
- },
81
- /** The form's Model as the Builder's Model holds it: JSON. */
82
- encode: (model) => encodeModel(model),
83
- /** A held form Model read back; none if it no longer fits, which a refill then replaces. */
84
- decode: (held) => Result.getSuccess(decodeModel(held)),
85
- encodeMessage: (message) => encodeMessage(message),
86
- decodeMessage: (held) => Result.getSuccess(decodeMessage(held)),
87
- /**
88
- * A Message of the Bundle behind `key`'s control (an `Input.bundle`), as the
89
- * form's own. Built from runtime fields, the form's type names no such key,
90
- * so it is checked here: a key not edited by one throws.
91
- */
92
- control: (key, message) => form.control(key).send(message),
93
- /**
94
- * What a new value starts from, as the Document stores it: each field's
95
- * empty value where it decodes (`''`, `null`, `false`), else a number's
96
- * zero or a select's first choice; a field with neither is left out. It is
97
- * not checked: a zero a number's check refuses, or a field left out, makes
98
- * a value the Document refuses when it is set.
99
- */
100
- seed: () => {
101
- const empty = form.partial(form.initial);
102
- return Object.fromEntries(editable.flatMap(([key, schema]) => {
103
- if (Object.hasOwn(empty, key)) return [[key, empty[key]]];
104
- const control = resolve(key, Schema.toEncoded(schema));
105
- if (control !== void 0 && Input.Number.is(control)) return [[key, 0]];
106
- const [first] = control !== void 0 && Input.Select.is(control) ? control.data.options : [];
107
- return first === void 0 ? [] : [[key, first]];
108
- }));
109
- },
110
- /** A value from the form, as the Document stores it; none for a prop the form does not edit. */
111
- stored: (key, value) => Object.hasOwn(decoders, key) ? Option.some(value) : Option.none()
112
- };
113
- };
114
- const made = /* @__PURE__ */ new WeakMap();
115
- /** A Block's props as a form, made at the first use and kept: one per Block. */
116
- const settingsOf = (block) => {
117
- const known = made.get(block);
118
- if (known !== void 0) return known;
119
- const settings = make(`${block.name}Settings`, fieldsOf(block.Props), controlsKey.get(block.metadata)[0] ?? {});
120
- made.set(block, settings);
121
- return settings;
122
- };
123
- const inputs = /* @__PURE__ */ new WeakMap();
124
- /**
125
- * The input an event of a Block runs an action with, as a form, made at the
126
- * first use and kept. One per Block, event and action, so two events of one
127
- * node that run the same action draw their fields under ids of their own.
128
- */
129
- const inputOf = (block, event, action) => {
130
- const name = `${block.name}-${event}-${action.name}`;
131
- const known = inputs.get(action) ?? /* @__PURE__ */ new Map();
132
- inputs.set(action, known);
133
- const held = known.get(name);
134
- if (held !== void 0) return held;
135
- const settings = make(name, fieldsOf(action.input), {});
136
- known.set(name, settings);
137
- return settings;
138
- };
139
- /** The control a prop is drawn with: the Block's hint, else what its Schema says. */
140
- const controlOf = (block, key, schema) => controlsKey.get(block.metadata)[0]?.[key] ?? Input.resolve(Entity.unmapped, schema);
141
- // src/words.ts
142
- const editWords = Object.freeze({
143
- at: ", {position} of {count} in {container}",
144
- thePage: "the page",
145
- inRegion: "{label} {region}",
146
- moved: "Moved {label}{at}",
147
- added: "Added {label}{at}",
148
- duplicated: "Duplicated {label}{at}",
149
- removed: "Removed {label}",
150
- editedPage: "Edited the page",
151
- undone: "Undone",
152
- redone: "Redone",
153
- notMoved: "Not moved",
154
- notAdded: "Not added",
155
- copied: "Copied {label}",
156
- cut: "Cut {label}",
157
- nothingCopied: "Nothing has been copied",
158
- notAPage: "The clipboard holds no part of a page",
159
- noStartingProps: "\"{block}\" has no starting props, so it cannot be inserted",
160
- startingPropsFail: "\"{block}\"'s starting props do not encode",
161
- notANode: "\"{id}\" is not a node",
162
- unknownPattern: "the Catalog has no pattern \"{name}\"",
163
- noPlace: "There is no place on this page for a {label}",
164
- copyChanged: "\"{id}\" changed while its copy was being made; copy it again",
165
- refusal: "{message}",
166
- moveUp: "Move up",
167
- moveDown: "Move down",
168
- moveOut: "Move out",
169
- moveIn: "Move in",
170
- duplicate: "Duplicate",
171
- copy: "Copy",
172
- cutCommand: "Cut",
173
- delete: "Delete",
174
- undo: "Undo",
175
- redo: "Redo",
176
- paste: "Paste",
177
- editText: "Edit its text",
178
- deselect: "Select nothing"
179
- });
180
15
  // src/index.ts
181
16
  /**
182
17
  * `foldkit-builder`: the page builder's state, as an ordinary Bundle.
@@ -466,7 +301,7 @@ const placeFor = (catalog, document, selected, blockName) => {
466
301
  const fits = (accepted) => block.provides.some((content) => accepted.includes(content));
467
302
  /** Last in the first of a node's Regions with room that accepts the Block. */
468
303
  const inside = (id) => {
469
- const node = document.nodes[id];
304
+ const node = Composition.nodeAt(document, id);
470
305
  const owner = node === void 0 ? void 0 : Catalog.block(catalog, node.block);
471
306
  if (node !== void 0 && owner !== void 0) for (const [name, region] of Object.entries(owner.regions)) {
472
307
  const children = node.regions[name] ?? [];
@@ -480,7 +315,7 @@ const placeFor = (catalog, document, selected, blockName) => {
480
315
  }
481
316
  const place = Option.isSome(selected) ? Composition.index(document).get(selected.value) : void 0;
482
317
  if (place !== void 0 && place.parent !== void 0 && place.region !== void 0) {
483
- const parent = document.nodes[place.parent];
318
+ const parent = Composition.nodeAt(document, place.parent);
484
319
  const region = (parent === void 0 ? void 0 : Catalog.block(catalog, parent.block))?.regions[place.region];
485
320
  const siblings = parent?.regions[place.region] ?? [];
486
321
  if (region !== void 0 && fits(region.accepts) && siblings.length < region.max) return Option.some(Composition.region(place.parent, place.region, place.index + 1));
@@ -489,7 +324,7 @@ const placeFor = (catalog, document, selected, blockName) => {
489
324
  const order = [];
490
325
  const visit = (id) => {
491
326
  order.push(id);
492
- for (const ids of Object.values(document.nodes[id]?.regions ?? {})) ids.forEach(visit);
327
+ for (const ids of Object.values(Composition.nodeAt(document, id)?.regions ?? {})) ids.forEach(visit);
493
328
  };
494
329
  document.roots.forEach(visit);
495
330
  for (const id of order.reverse()) {
@@ -501,7 +336,7 @@ const placeFor = (catalog, document, selected, blockName) => {
501
336
  /** Whether a place has room for one more node: a root always, a Region below its most. */
502
337
  const hasRoom = (catalog, document, at) => {
503
338
  if (at._tag === "Root") return true;
504
- const holder = document.nodes[at.parent];
339
+ const holder = Composition.nodeAt(document, at.parent);
505
340
  const region = holder === void 0 ? void 0 : Catalog.block(catalog, holder.block)?.regions[at.region];
506
341
  return region !== void 0 && (holder?.regions[at.region] ?? []).length < region.max;
507
342
  };
@@ -510,7 +345,7 @@ const moveBy = (document, id, delta) => {
510
345
  const place = Composition.index(document).get(id);
511
346
  if (place === void 0) return Option.none();
512
347
  const to = place.index + delta;
513
- const siblings = place.parent === void 0 ? document.roots : document.nodes[place.parent]?.regions[place.region ?? ""] ?? [];
348
+ const siblings = place.parent === void 0 ? document.roots : Composition.nodeAt(document, place.parent)?.regions[place.region ?? ""] ?? [];
514
349
  if (to < 0 || to >= siblings.length) return Option.none();
515
350
  return Option.some(Composition.Op.move(id, place.parent === void 0 ? Composition.root(to) : Composition.region(place.parent, place.region ?? "", to)));
516
351
  };
@@ -533,12 +368,12 @@ const landingBy = (catalog, document, dragged, target, zone, region) => {
533
368
  if (Option.contains(dragged.id, target) || place === void 0) return Option.none();
534
369
  const without = (ids) => ids.filter((id) => !Option.contains(dragged.id, id));
535
370
  const beside = (offset) => {
536
- const siblings = place.parent === void 0 ? document.roots : document.nodes[place.parent]?.regions[place.region ?? ""] ?? [];
371
+ const siblings = place.parent === void 0 ? document.roots : Composition.nodeAt(document, place.parent)?.regions[place.region ?? ""] ?? [];
537
372
  const at = without(siblings).indexOf(target) + offset;
538
373
  return Option.some(place.parent === void 0 ? Composition.root(at) : Composition.region(place.parent, place.region ?? "", at));
539
374
  };
540
375
  const inside = () => {
541
- const holder = document.nodes[target];
376
+ const holder = Composition.nodeAt(document, target);
542
377
  if (holder === void 0) return Option.none();
543
378
  const named = Option.orElse(region, () => regionTaking(catalog, holder.block, dragged.block));
544
379
  return Option.map(named, (regionName) => Composition.region(target, regionName, without(holder.regions[regionName] ?? []).length));
@@ -596,10 +431,10 @@ const outdent = (document, id) => {
596
431
  */
597
432
  const indent = (catalog, document, id) => {
598
433
  const place = Composition.index(document).get(id);
599
- const node = document.nodes[id];
434
+ const node = Composition.nodeAt(document, id);
600
435
  if (place === void 0 || node === void 0 || place.index === 0) return Option.none();
601
- const above = (place.parent === void 0 ? document.roots : document.nodes[place.parent]?.regions[place.region ?? ""] ?? [])[place.index - 1];
602
- const target = above === void 0 ? void 0 : document.nodes[above];
436
+ const above = (place.parent === void 0 ? document.roots : Composition.nodeAt(document, place.parent)?.regions[place.region ?? ""] ?? [])[place.index - 1];
437
+ const target = above === void 0 ? void 0 : Composition.nodeAt(document, above);
603
438
  if (above === void 0 || target === void 0) return Option.none();
604
439
  return Option.map(regionTaking(catalog, target.block, node.block), (regionName) => Composition.Op.move(id, Composition.region(above, regionName, (target.regions[regionName] ?? []).length)));
605
440
  };
@@ -609,14 +444,14 @@ const patternRoot = (catalog, op) => Option.flatMap(Catalog.pattern(catalog, op.
609
444
  const blockLabel = (catalog, block) => Catalog.block(catalog, block)?.words.label ?? block;
610
445
  /** What an applied edit says to assistive technology; none for a prop change. */
611
446
  const describeEdit = (catalog, words, before, after, op) => {
612
- const labelOf = (document, id) => Option.match(Option.fromUndefinedOr(document.nodes[id]), {
447
+ const labelOf = (document, id) => Option.match(Option.fromUndefinedOr(Composition.nodeAt(document, id)), {
613
448
  onNone: () => id,
614
449
  onSome: (node) => blockLabel(catalog, node.block)
615
450
  });
616
451
  const where = (id) => {
617
452
  const place = Composition.index(after).get(id);
618
453
  if (place === void 0) return "";
619
- const siblings = place.parent === void 0 ? after.roots.length : after.nodes[place.parent]?.regions[place.region ?? ""]?.length ?? 0;
454
+ const siblings = place.parent === void 0 ? after.roots.length : Composition.nodeAt(after, place.parent)?.regions[place.region ?? ""]?.length ?? 0;
620
455
  const container = place.parent === void 0 ? words.thePage : fillWords(words.inRegion, {
621
456
  label: labelOf(after, place.parent),
622
457
  region: place.region ?? ""
@@ -647,7 +482,7 @@ const describeEdit = (catalog, words, before, after, op) => {
647
482
  }
648
483
  };
649
484
  /** The selection, kept only while the Document still holds it. */
650
- const keptIn = (document, selected) => Option.filter(selected, (id) => document.nodes[id] !== void 0);
485
+ const keptIn = (document, selected) => Option.filter(selected, (id) => Composition.nodeAt(document, id) !== void 0);
651
486
  /** The Model showing another Document: what a fill, a reset or a restored revision does. */
652
487
  const replace = (model, document) => ({
653
488
  ...model,
@@ -710,11 +545,11 @@ const Builder = {
710
545
  make: (name, config) => {
711
546
  const { catalog, renderer } = config;
712
547
  const words = {
713
- ...editWords,
548
+ ...editWords$1,
714
549
  ...config.words
715
550
  };
716
551
  const starters = config.starters;
717
- for (const block of catalog.blocks) settingsOf(block);
552
+ for (const block of catalog.blocks) settingsOf$1(block);
718
553
  const capacity = config.capacity ?? 200;
719
554
  const initial = placements.initial({
720
555
  page: History.start(Composition.empty()),
@@ -783,7 +618,7 @@ const Builder = {
783
618
  /** What a drag carries, as `landing` weighs it; none for a node gone or a Block not offered. */
784
619
  const draggedOf = (document, source) => {
785
620
  if (source._tag === "Existing") {
786
- const node = document.nodes[source.id];
621
+ const node = Composition.nodeAt(document, source.id);
787
622
  return node === void 0 ? Option.none() : Option.some({
788
623
  block: node.block,
789
624
  id: Option.some(source.id),
@@ -791,7 +626,7 @@ const Builder = {
791
626
  });
792
627
  }
793
628
  let unused = "dragged";
794
- while (document.nodes[NodeId.make(unused)] !== void 0) unused = `${unused}-`;
629
+ while (Composition.nodeAt(document, NodeId.make(unused)) !== void 0) unused = `${unused}-`;
795
630
  const trial = NodeId.make(unused);
796
631
  return Option.map(startingProps(source.block), (props) => ({
797
632
  block: source.block,
@@ -860,7 +695,7 @@ const Builder = {
860
695
  const formsOf = (id, node, block) => {
861
696
  const props = {
862
697
  key: "props",
863
- settings: settingsOf(block),
698
+ settings: settingsOf$1(block),
864
699
  stored: recordOf(node.props),
865
700
  write: (changed, cleared) => [...Object.entries(changed).map(([key, value]) => Composition.Op.setProp(id, key, value)), ...cleared.map((key) => Composition.Op.unsetProp(id, key))]
866
701
  };
@@ -872,7 +707,7 @@ const Builder = {
872
707
  const action = catalog.actions.find((each) => each.name === ref["action"]);
873
708
  if (action === void 0) return [];
874
709
  const input = recordOf(ref["input"]);
875
- const settings = inputOf(block, event, action);
710
+ const settings = inputOf$1(block, event, action);
876
711
  return [{
877
712
  event,
878
713
  key: `on:${event}:${action.name}`,
@@ -895,7 +730,7 @@ const Builder = {
895
730
  * selected or its Block is not in the Catalog.
896
731
  */
897
732
  const inspecting = (model) => Option.flatMap(model.selected, (id) => {
898
- const node = documentOf(model).nodes[id];
733
+ const node = Composition.nodeAt(documentOf(model), id);
899
734
  const block = node === void 0 ? void 0 : Catalog.block(catalog, node.block);
900
735
  if (node === void 0 || block === void 0) return Option.none();
901
736
  const held = Option.match(Option.filter(model.inspector, (inspector) => inspector.id === id), {
@@ -927,7 +762,7 @@ const Builder = {
927
762
  */
928
763
  const inspect = (model, message) => {
929
764
  const target = Option.filter(inspecting(model), (each) => each.id === message.id);
930
- const node = documentOf(model).nodes[message.id];
765
+ const node = Composition.nodeAt(documentOf(model), message.id);
931
766
  if (Option.isNone(target) || node === void 0) return { model };
932
767
  const { id, block, props, on } = target.value;
933
768
  const forms = formsOf(id, node, block);
@@ -984,7 +819,7 @@ const Builder = {
984
819
  model: result.model,
985
820
  commands
986
821
  };
987
- const now = formsOf(id, documentOf(result.model).nodes[id] ?? node, block);
822
+ const now = formsOf(id, Composition.nodeAt(documentOf(result.model), id) ?? node, block);
988
823
  const holds = [now.props, ...now.on].find((form) => form.key === known.key);
989
824
  return {
990
825
  model: {
@@ -1017,7 +852,7 @@ const Builder = {
1017
852
  inspector: Option.none()
1018
853
  };
1019
854
  if (documentOf(after) === documentOf(before)) return after;
1020
- const node = documentOf(after).nodes[id];
855
+ const node = Composition.nodeAt(documentOf(after), id);
1021
856
  const block = node === void 0 ? void 0 : Catalog.block(catalog, node.block);
1022
857
  if (node === void 0 || block === void 0) return {
1023
858
  ...after,
@@ -1042,7 +877,7 @@ const Builder = {
1042
877
  onNone: () => ({ model }),
1043
878
  onSome: (sent) => own(model, sent)
1044
879
  });
1045
- case "Selected": return documentOf(model).nodes[message.id] === void 0 ? { model: {
880
+ case "Selected": return Composition.nodeAt(documentOf(model), message.id) === void 0 ? { model: {
1046
881
  ...model,
1047
882
  selected: Option.none()
1048
883
  } } : { model: {
@@ -1075,7 +910,7 @@ const Builder = {
1075
910
  })
1076
911
  };
1077
912
  case "DuplicateAsked": {
1078
- if (documentOf(model).nodes[message.id] === void 0) return refuse(model, {
913
+ if (Composition.nodeAt(documentOf(model), message.id) === void 0) return refuse(model, {
1079
914
  code: "composition:missing-node",
1080
915
  message: fillWords(words.notANode, { id: message.id })
1081
916
  });
@@ -1091,7 +926,7 @@ const Builder = {
1091
926
  }
1092
927
  case "CopyAsked":
1093
928
  case "CutAsked": {
1094
- const node = documentOf(model).nodes[message.id];
929
+ const node = Composition.nodeAt(documentOf(model), message.id);
1095
930
  if (node === void 0) return refuse(model, {
1096
931
  code: "composition:missing-node",
1097
932
  message: fillWords(words.notANode, { id: message.id })
@@ -1141,7 +976,7 @@ const Builder = {
1141
976
  message: wrong.value.message
1142
977
  })
1143
978
  });
1144
- const block = tree.value.nodes[tree.value.root]?.block ?? "";
979
+ const block = Composition.nodeAt(tree.value, tree.value.root)?.block ?? "";
1145
980
  const place = placeFor(catalog, documentOf(model), model.selected, block);
1146
981
  if (Option.isNone(place)) return refuse(model, {
1147
982
  code: "builder:no-place",
@@ -1176,7 +1011,7 @@ const Builder = {
1176
1011
  return Option.match(fieldOf(message.field), {
1177
1012
  onNone: () => ({ model }),
1178
1013
  onSome: ({ id, key }) => {
1179
- const stored = documentOf(model).nodes[id]?.props[key];
1014
+ const stored = Composition.nodeAt(documentOf(model), id)?.props[key];
1180
1015
  if (typeof stored !== "string" || !Renderer.fields(renderer, documentOf(model), id).includes(key)) return { model };
1181
1016
  return { model: {
1182
1017
  ...model,
@@ -1217,7 +1052,7 @@ const Builder = {
1217
1052
  page,
1218
1053
  editing: Option.none()
1219
1054
  };
1220
- return documentOf(ended).nodes[editing.id]?.props[editing.key] === kept ? { model: ended } : applyOp(ended, Composition.Op.setProp(editing.id, editing.key, kept), group);
1055
+ return Composition.nodeAt(documentOf(ended), editing.id)?.props[editing.key] === kept ? { model: ended } : applyOp(ended, Composition.Op.setProp(editing.id, editing.key, kept), group);
1221
1056
  }
1222
1057
  });
1223
1058
  case "Minted": {
@@ -1255,7 +1090,7 @@ const Builder = {
1255
1090
  }));
1256
1091
  }
1257
1092
  case "Duplicate": {
1258
- if (documentOf(model).nodes[request.id] === void 0) return refuse(model, {
1093
+ if (Composition.nodeAt(documentOf(model), request.id) === void 0) return refuse(model, {
1259
1094
  code: "composition:missing-node",
1260
1095
  message: fillWords(words.notANode, { id: request.id })
1261
1096
  });
@@ -1400,7 +1235,7 @@ const Builder = {
1400
1235
  const place = Composition.index(was).get(NodeId.make(current));
1401
1236
  if (place === void 0) return next;
1402
1237
  const left = (id) => Composition.index(after).has(id);
1403
- const siblings = place.parent === void 0 ? was.roots : was.nodes[place.parent]?.regions[place.region ?? ""] ?? [];
1238
+ const siblings = place.parent === void 0 ? was.roots : Composition.nodeAt(was, place.parent)?.regions[place.region ?? ""] ?? [];
1404
1239
  const beside = [...siblings.slice(place.index + 1), ...siblings.slice(0, place.index).reverse()].find(left);
1405
1240
  let holder = place.parent;
1406
1241
  while (holder !== void 0 && !left(holder)) holder = Composition.index(was).get(holder)?.parent;
@@ -1424,7 +1259,7 @@ const Builder = {
1424
1259
  };
1425
1260
  if (message._tag === Layers.wrapper.tag && message.message._tag === "Focused") {
1426
1261
  const id = NodeId.make(message.message.id);
1427
- return documentOf(next.model).nodes[id] === void 0 ? next : {
1262
+ return Composition.nodeAt(documentOf(next.model), id) === void 0 ? next : {
1428
1263
  ...next,
1429
1264
  model: {
1430
1265
  ...next.model,
@@ -1469,7 +1304,7 @@ const Builder = {
1469
1304
  })));
1470
1305
  }));
1471
1306
  const layer = (id) => {
1472
- const node = documentOf(model).nodes[id];
1307
+ const node = Composition.nodeAt(documentOf(model), id);
1473
1308
  if (node === void 0) return null;
1474
1309
  const known = Catalog.block(catalog, node.block) !== void 0;
1475
1310
  const children = Object.values(node.regions).flat();
@@ -1489,7 +1324,7 @@ const Builder = {
1489
1324
  ])]
1490
1325
  });
1491
1326
  const inspect = (id) => {
1492
- const node = documentOf(model).nodes[id];
1327
+ const node = Composition.nodeAt(documentOf(model), id);
1493
1328
  if (node === void 0) return null;
1494
1329
  const fields = Object.entries(node.props).filter((entry) => typeof entry[1] === "string");
1495
1330
  return h.div([h.Class("builder-properties"), h.AriaLabel("Properties")], fields.map(([key, value]) => h.label([], [key, h.input([h.Value(value), h.OnInput((text) => Message.Applied({ op: Composition.Op.setProp(id, key, text) }))])])));
@@ -1709,7 +1544,7 @@ const Builder = {
1709
1544
  /** Where a new node of a Block goes, given the selection; none where it may not go. */
1710
1545
  placeFor: (document, selected, block) => placeFor(catalog, document, selected, block),
1711
1546
  /** Where a pattern goes, as a new node of its root's Block would; none where it may not. */
1712
- patternAt: (document, selected, pattern) => Option.flatMap(Catalog.pattern(catalog, pattern), (found) => Option.flatMap(Option.fromUndefinedOr(found.tree.nodes[found.tree.root]), (root) => placeFor(catalog, document, selected, root.block))),
1547
+ patternAt: (document, selected, pattern) => Option.flatMap(Catalog.pattern(catalog, pattern), (found) => Option.flatMap(Option.fromUndefinedOr(Composition.nodeAt(found.tree, found.tree.root)), (root) => placeFor(catalog, document, selected, root.block))),
1713
1548
  moveBy,
1714
1549
  /** Where what is dragged over `target`, in `zone`, would go; none where it may not. */
1715
1550
  dropAt: (document, dragged, target, zone) => Option.map(Option.flatMap(draggedOf(document, dragged), (each) => landing(catalog, document, each, target, zone)), ({ at }) => at),
@@ -1733,4 +1568,4 @@ const Builder = {
1733
1568
  };
1734
1569
  export { Announcer, Builder, ContextValue, Drag, DragSource, DropZone, Layers, Message, Model, Panel, Viewport, controlOf, editWords, inputOf, layersArgs, settingsOf };
1735
1570
 
1736
- //# sourceMappingURL=index.mjs.map
1571
+ //# sourceMappingURL=index.js.map