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.
- package/dist/{index.d.mts → index.d.ts} +8 -819
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +40 -205
- package/dist/index.js.map +1 -0
- package/dist/settings.d.ts +761 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +134 -0
- package/dist/settings.js.map +1 -0
- package/dist/words.d.ts +61 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +42 -0
- package/dist/words.js.map +1 -0
- package/package.json +14 -14
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/settings.ts","../src/words.ts","../src/index.ts"],"sourcesContent":["/**\n * A node's values as `foldkit-form` forms: a Block's props, and the input of\n * each action an event runs. The inspector edits a node through them. The\n * Document owns the values; a form holds only what a field shows, including\n * text that does not decode yet (a number typed as \"1.\"), and each change\n * that decodes becomes one Operation.\n */\nimport { Option, Result, Schema } from 'effect'\nimport { fieldsOf, spaced, type AnyBlock, type CatalogAction } from 'foldkit-composition'\nimport { Entity, Words } from 'foldkit-entity'\nimport { Form, Input, type Control } from 'foldkit-form'\nimport { Metadata } from 'foldkit-metadata'\n\nconst controlsKey = Metadata.key<Readonly<Record<string, Control>>>('foldkit-builder/controls', {\n // One record per Block: a later annotation's prop replaces an earlier one's.\n merge: records => [Object.assign({}, ...records)],\n summarize: record =>\n Object.entries(record)\n .map(([key, control]) => `${key}: ${control.kind}`)\n .join(', '),\n})\n\n/**\n * Block metadata: the control the inspector draws a prop with, where its\n * Schema alone does not say, as\n * `Heading.pipe(Block.annotate(Builder.controls({ text: Input.multiline() })))`.\n * `Input.hidden()` leaves a prop out of the inspector.\n */\nexport const controls = (given: Readonly<Record<string, Control>>): Metadata =>\n controlsKey.of(given)\n\n/** A prop's words: its Schema's `title`, else its key spaced, and its description. */\nconst wordsOf = (key: string, schema: Schema.Top) => {\n const { title, description } = Words.of(schema)\n return { label: Option.getOrElse(title, () => spaced(key)), description }\n}\n\n/** A form over `fields`, named `name`, with the controls `hints` asks for. */\nconst make = (\n name: string,\n fields: Readonly<Record<string, Schema.Top>>,\n hints: Readonly<Record<string, Control>>,\n) => {\n const resolve = (key: string, schema: Schema.Top): Control | undefined =>\n hints[key] ?? Input.resolve(Entity.unmapped, schema)\n // A value is edited as the Document stores it, so a control fits it or not there:\n // an `Option` of an id is a picker or text; a struct, or a list that is not a\n // relation, fits none and is shown, not edited.\n const editable = Object.entries(fields).filter(\n ([key, schema]) => resolve(key, Schema.toEncoded(schema)) !== undefined,\n )\n // Checked against the whole Schema, so what it says (a brand, a length, a check\n // past a transformation, which the encoded side drops) is said at the field.\n const decoders = Object.fromEntries(\n editable.map(([key, schema]) => [\n key,\n // A Block's props are stored JSON: decoding one needs no services.\n Schema.decodeUnknownResult(schema as Schema.Codec<unknown, unknown>),\n ]),\n )\n const Props = Schema.Struct(\n Object.fromEntries(\n editable.map(([key, schema]) => [\n key,\n Schema.toEncoded(schema).check(\n Schema.makeFilter(value =>\n Result.match(decoders[key]!(value), {\n onSuccess: () => undefined,\n onFailure: error => error.message,\n }),\n ),\n ),\n ]),\n ) as Readonly<Record<string, Schema.Top>>,\n )\n // The encoded side has no words of its own to read, so they come from the prop.\n const labels = Object.fromEntries(\n editable.map(([key, schema]) => {\n const { label, description } = wordsOf(key, schema)\n return [key, Form.label(label, Option.getOrUndefined(description))]\n }),\n )\n const entity = Entity.define(name, Props).pipe(Entity.annotateMembers(labels))\n const form = Form.make(name, Entity.input(entity, Props), { inputs: hints })\n // The Builder runs a form as functions, so nothing would start these: fail here,\n // not with a picker whose popover never closes.\n if (form.bundle.subscriptions !== undefined || form.bundle.resources !== undefined)\n throw new Error(\n `Builder: \"${name}\" has a control with Subscriptions or Resources (an Input.bundle), which the inspector cannot run; give it a control that needs neither`,\n )\n const encodeModel = Schema.encodeSync(form.bundle.Model)\n const decodeModel = Schema.decodeUnknownResult(form.bundle.Model)\n const encodeMessage = Schema.encodeSync(form.bundle.Message)\n // Strict, as every boundary here: a held Message with a key its variant lacks is not one.\n const decodeMessage = Schema.decodeUnknownResult(form.bundle.Message, {\n onExcessProperty: 'error',\n })\n type FormModel = typeof form.initial\n\n return {\n form,\n /** Every key the form's Schema names, edited or shown. */\n keys: Object.keys(fields),\n /** The props the form does not edit, labelled as its fields are, and as stored: shown, not changed. */\n shown: (\n stored: Readonly<Record<string, unknown>>,\n ): ReadonlyArray<{ readonly key: string; readonly label: string; readonly value: unknown }> =>\n Object.entries(fields)\n .filter(([key]) => !Object.hasOwn(decoders, key))\n .map(([key, schema]) => ({ key, label: wordsOf(key, schema).label, value: stored[key] })),\n /**\n * `model` with the fields `keep` spares filled from a node's stored props.\n * A stored prop that does not decode is shown as it is, with its error.\n */\n fill: (\n model: FormModel,\n stored: Readonly<Record<string, unknown>>,\n keep: (key: string) => boolean = () => false,\n ): FormModel => {\n const keys = Object.keys(decoders).filter(key => !keep(key))\n const filled = form.fill(model, Object.fromEntries(keys.map(key => [key, stored[key]]))).model\n return keys\n .filter(key => stored[key] !== undefined && Result.isFailure(decoders[key]!(stored[key])))\n .reduce(\n (next, key) => form.bundle.update(next, form.Message.Blurred({ key }), undefined).model,\n filled,\n )\n },\n /** The form's Model as the Builder's Model holds it: JSON. */\n encode: (model: FormModel): Schema.Json => encodeModel(model) as Schema.Json,\n /** A held form Model read back; none if it no longer fits, which a refill then replaces. */\n decode: (held: Schema.Json): Option.Option<FormModel> => Result.getSuccess(decodeModel(held)),\n encodeMessage: (message: typeof form.Message.Type): Schema.Json =>\n encodeMessage(message) as Schema.Json,\n decodeMessage: (held: Schema.Json): Option.Option<typeof form.Message.Type> =>\n Result.getSuccess(decodeMessage(held)),\n /**\n * A Message of the Bundle behind `key`'s control (an `Input.bundle`), as the\n * form's own. Built from runtime fields, the form's type names no such key,\n * so it is checked here: a key not edited by one throws.\n */\n control: (key: string, message: unknown): typeof form.Message.Type =>\n // `never`: the form's type knows no Bundle-backed key; `control` refuses a key\n // that is not one, and the Bundle drops a Message it does not take.\n form.control(key as never).send(message as never),\n /**\n * What a new value starts from, as the Document stores it: each field's\n * empty value where it decodes (`''`, `null`, `false`), else a number's\n * zero or a select's first choice; a field with neither is left out. It is\n * not checked: a zero a number's check refuses, or a field left out, makes\n * a value the Document refuses when it is set.\n */\n seed: (): Readonly<Record<string, Schema.Json>> => {\n const empty: Readonly<Record<string, unknown>> = form.partial(form.initial)\n return Object.fromEntries(\n editable.flatMap(([key, schema]): ReadonlyArray<readonly [string, Schema.Json]> => {\n if (Object.hasOwn(empty, key)) return [[key, empty[key] as Schema.Json]]\n const control = resolve(key, Schema.toEncoded(schema))\n if (control !== undefined && Input.Number.is(control)) return [[key, 0]]\n const [first] =\n control !== undefined && Input.Select.is(control) ? control.data.options : []\n return first === undefined ? [] : [[key, first]]\n }),\n )\n },\n /** A value from the form, as the Document stores it; none for a prop the form does not edit. */\n stored: (key: string, value: unknown): Option.Option<Schema.Json> =>\n Object.hasOwn(decoders, key) ? Option.some(value as Schema.Json) : Option.none(),\n }\n}\n\n/** A form over a node's values and the codecs the Builder holds it with. */\nexport type Settings = ReturnType<typeof make>\n\nconst made = new WeakMap<AnyBlock, Settings>()\n\n/** A Block's props as a form, made at the first use and kept: one per Block. */\nexport const settingsOf = (block: AnyBlock): Settings => {\n const known = made.get(block)\n if (known !== undefined) return known\n const settings = make(\n `${block.name}Settings`,\n fieldsOf(block.Props),\n controlsKey.get(block.metadata)[0] ?? {},\n )\n made.set(block, settings)\n return settings\n}\n\nconst inputs = new WeakMap<CatalogAction, Map<string, Settings>>()\n\n/**\n * The input an event of a Block runs an action with, as a form, made at the\n * first use and kept. One per Block, event and action, so two events of one\n * node that run the same action draw their fields under ids of their own.\n */\nexport const inputOf = (block: AnyBlock, event: string, action: CatalogAction): Settings => {\n const name = `${block.name}-${event}-${action.name}`\n const known = inputs.get(action) ?? new Map<string, Settings>()\n inputs.set(action, known)\n const held = known.get(name)\n if (held !== undefined) return held\n const settings = make(name, fieldsOf(action.input), {})\n known.set(name, settings)\n return settings\n}\n\n/** The control a prop is drawn with: the Block's hint, else what its Schema says. */\nexport const controlOf = (block: AnyBlock, key: string, schema: Schema.Top): Control | undefined =>\n controlsKey.get(block.metadata)[0]?.[key] ?? Input.resolve(Entity.unmapped, schema)\n","/**\n * The Builder's own words: what it says to assistive technology of each edit,\n * its commands' labels, and the refusals it makes itself. Words are text; a\n * word that takes a value names it as a blank (`'Moved {label}{at}'`), as a\n * form's and a view's words do, so one object can hold them all. A Block is\n * named by its label (`Block.words`), the Catalog's word.\n */\nexport interface EditWords {\n /** Where a node is after an edit, after its name: \", 2 of 3 in Section body\". Blanks `{position}`, `{count}`, `{container}`. */\n readonly at: string\n /** The container of a root. */\n readonly thePage: string\n /** The container of a node in a Region: the holder's `{label}` and the `{region}`. */\n readonly inRegion: string\n /** An edit, said: its node's `{label}` and where it is now, `{at}`. */\n readonly moved: string\n readonly added: string\n readonly duplicated: string\n /** A removal, said: the node's `{label}`. */\n readonly removed: string\n readonly editedPage: string\n readonly undone: string\n readonly redone: string\n /** A drag that ended with nothing done: a node, or a new one from the palette. */\n readonly notMoved: string\n readonly notAdded: string\n /** A copy and a cut, said: the node's `{label}`. */\n readonly copied: string\n readonly cut: string\n\n /** The refusals the Builder makes itself: nothing to paste, as nothing copied or not a page. */\n readonly nothingCopied: string\n readonly notAPage: string\n /** A Block that cannot be inserted: `{block}`. */\n readonly noStartingProps: string\n readonly startingPropsFail: string\n /** A node the page does not hold, or one changed while its copy was made: `{id}`. */\n readonly notANode: string\n readonly copyChanged: string\n /** A pattern the Catalog lacks: `{name}`. */\n readonly unknownPattern: string\n /** A paste the page has no place for: its root's Block, `{label}`. */\n readonly noPlace: string\n /** A refusal `apply` made: blanks `{code}` and `{message}`, by default its own message. */\n readonly refusal: string\n\n /** The commands' labels. */\n readonly moveUp: string\n readonly moveDown: string\n readonly moveOut: string\n readonly moveIn: string\n readonly duplicate: string\n readonly copy: string\n readonly cutCommand: string\n readonly delete: string\n readonly undo: string\n readonly redo: string\n readonly paste: string\n readonly editText: string\n readonly deselect: string\n}\n\nexport const editWords: EditWords = Object.freeze({\n at: ', {position} of {count} in {container}',\n thePage: 'the page',\n inRegion: '{label} {region}',\n moved: 'Moved {label}{at}',\n added: 'Added {label}{at}',\n duplicated: 'Duplicated {label}{at}',\n removed: 'Removed {label}',\n editedPage: 'Edited the page',\n undone: 'Undone',\n redone: 'Redone',\n notMoved: 'Not moved',\n notAdded: 'Not added',\n copied: 'Copied {label}',\n cut: 'Cut {label}',\n nothingCopied: 'Nothing has been copied',\n notAPage: 'The clipboard holds no part of a page',\n noStartingProps: '\"{block}\" has no starting props, so it cannot be inserted',\n startingPropsFail: '\"{block}\"\\'s starting props do not encode',\n notANode: '\"{id}\" is not a node',\n unknownPattern: 'the Catalog has no pattern \"{name}\"',\n noPlace: 'There is no place on this page for a {label}',\n copyChanged: '\"{id}\" changed while its copy was being made; copy it again',\n refusal: '{message}',\n moveUp: 'Move up',\n moveDown: 'Move down',\n moveOut: 'Move out',\n moveIn: 'Move in',\n duplicate: 'Duplicate',\n copy: 'Copy',\n cutCommand: 'Cut',\n delete: 'Delete',\n undo: 'Undo',\n redo: 'Redo',\n paste: 'Paste',\n editText: 'Edit its text',\n deselect: 'Select nothing',\n})\n","/**\n * `foldkit-builder`: the page builder's state, as an ordinary Bundle.\n *\n * The Builder edits a `foldkit-composition` Document by Operations. Its Model\n * holds the page as an undo history (`foldkit-primitives/state`) whose present\n * is the Document, with the editor's state beside it (what is selected, the\n * open panel, the viewport), so an edit and the undo step that records it are\n * one value, changed in one transition. The Catalog and the Renderer are\n * vocabulary, not state: the Builder closes over them where it is made, and\n * they never enter the Model or a placement's args.\n *\n * Placed as a form key's control (`builder.input`), the Document is that key's\n * value: the form validates it, submits it, and a CMS autosaves it, while a\n * selection or an open panel is not an edit. Placed alone, with\n * `Bundle.withChild`, its parent owns the Model instead.\n */\nimport { Effect, Option, Result, Schema } from 'effect'\nimport { Bundle } from 'foldkit-bundle'\nimport {\n Block,\n Catalog,\n Composition,\n NodeId,\n type AnyBlock,\n type Document,\n type Operation,\n type Position,\n type PropsOf,\n type Refusal,\n type Tree,\n} from 'foldkit-composition'\nimport { Renderer, fieldName, fieldOf } from 'foldkit-composition/foldkit'\nimport { Input, fillWords } from 'foldkit-form'\nimport { controls, inputOf, settingsOf, type Settings } from './settings.js'\nimport { editWords, type EditWords } from './words.js'\nimport { copyText, readText } from 'foldkit-primitives/dom'\nimport { LiveAnnounce, TreeNavigation } from 'foldkit-primitives/interaction'\nimport { History, HistoryModel } from 'foldkit-primitives/state'\nimport * as Command from 'foldkit/command'\nimport type { Command as CommandOf } from 'foldkit/command'\nimport { inertHtml, type Html, type HtmlBuilder, type KeyboardModifiers } from 'foldkit/html'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Submodel from 'foldkit/submodel'\n\nexport const Panel = Schema.Literals(['insert', 'layers', 'properties'])\nexport const Viewport = Schema.Literals(['wide', 'medium', 'narrow'])\n\n/** The layers panel's keyboard focus and which rows are open: a tree that starts open. */\nexport const Layers = Bundle.declare(TreeNavigation.bundle, 'layers')\nexport const layersArgs: TreeNavigation.Args = { openByDefault: true }\n\n/** What the editor says to assistive technology: a move, an insert, a refusal. */\nexport const Announcer = Bundle.declare(LiveAnnounce.bundle, 'announcer')\nconst announcerArgs: LiveAnnounce.Args = { debounceMs: 150, clearAfterMs: 5000 }\n\n/** Where over a node a drop lands: before it, inside it, or after it. */\nexport const DropZone = Schema.Literals(['before', 'inside', 'after'])\nexport type DropZone = typeof DropZone.Type\n\n/** What a drag carries: a node on the page, or a new node of a Block, from the palette. */\nexport const DragSource = Schema.Union([\n Schema.TaggedStruct('Existing', { id: NodeId }),\n Schema.TaggedStruct('New', { block: Schema.String }),\n])\nexport type DragSource = typeof DragSource.Type\n\n/** A drag under way: what is dragged, what it is over, and where it would go. */\nexport const Drag = Schema.Struct({\n source: DragSource,\n /**\n * The node it is over and the zone of it; none while it is over nothing, or\n * over the page's own space, which `at` then tells apart.\n */\n over: Schema.OptionFromNullOr(\n Schema.Struct({\n id: NodeId,\n zone: DropZone,\n /** The empty Region of the node it is over, which a drop goes into. */\n region: Schema.OptionFromNullOr(Schema.String),\n }),\n ),\n /**\n * Where a drop now puts it; none where a drop there would be refused.\n * `over.zone` is where it lands: `inside` a node that takes nothing is `after`.\n */\n at: Schema.OptionFromNullOr(Composition.Position),\n})\nexport type Drag = typeof Drag.Type\n\n/** A value of the page's context, as the editor previews it. */\nexport const ContextValue = Schema.Union([\n Schema.String,\n Schema.Number,\n Schema.Boolean,\n Schema.Null,\n])\nexport type ContextValue = typeof ContextValue.Type\n\nexport const Model = Schema.Struct({\n ...Layers.fields,\n ...Announcer.fields,\n /** The page and its undo steps: `page.present` is the Document being edited. */\n page: HistoryModel(Composition.Document),\n /** The node the inspector and the node actions work on. */\n selected: Schema.OptionFromNullOr(NodeId),\n /** The node under the pointer on the canvas or in the layers. */\n hovered: Schema.OptionFromNullOr(NodeId),\n panel: Panel,\n viewport: Viewport,\n /** Why the last edit was refused, until the next one goes through. */\n refused: Schema.OptionFromNullOr(Schema.Struct({ code: Schema.String, message: Schema.String })),\n /** A pointer drag under way. */\n drag: Schema.OptionFromNullOr(Drag),\n /**\n * The context the page is drawn for in the editor, by the Catalog's context\n * keys: what an author previews it as. A node whose `when` fails here is\n * drawn marked, not left out.\n */\n preview: Schema.Record(Schema.String, ContextValue),\n /**\n * What the inspector's fields hold for the node they show: each form's Model\n * encoded to JSON, by the form's key (`props`, or `on:<event>:<action>`), so\n * text that does not decode yet stays here, not in the page. None until a\n * field is changed, and after the selection moves; a form it does not hold is\n * filled from the node. Stored only when some, so a Builder saved before\n * there was one still reads.\n */\n inspector: Schema.OptionFromOptionalNullOr(\n Schema.Struct({ id: NodeId, forms: Schema.Record(Schema.String, Schema.Json) }),\n ),\n /**\n * The last node copied or cut, and all it holds: what a paste inserts when\n * the system clipboard cannot be read. Kept across pages, so a copy on one\n * pastes on another.\n */\n clipboard: Schema.OptionFromOptionalNullOr(Composition.Tree),\n /**\n * The text prop being edited in place on the canvas; its text when editing\n * began, which the canvas keeps the field at; and whether anything has been\n * typed, since only then does ending it write. Stored only when some.\n */\n editing: Schema.OptionFromOptionalNullOr(\n Schema.Struct({\n id: NodeId,\n key: Schema.String,\n initial: Schema.String,\n typed: Schema.Boolean,\n }),\n ),\n})\nexport type Model = typeof Model.Type\n\n/** One form the inspector draws for the selected node, and its Model. */\nexport interface InspectedForm {\n /** Which it is, as `Inspected` names it: `props`, or `on:<event>:<action>`. */\n readonly key: string\n readonly settings: Settings\n readonly model: Settings['form']['initial']\n}\n\n/** The selected node as the inspector edits it: its Block and its forms. */\nexport interface Inspecting {\n readonly id: NodeId\n readonly block: AnyBlock\n /** Its props. */\n readonly props: InspectedForm\n /**\n * The input of the action each event runs, by event: none for an event that\n * runs nothing, or an action the Catalog lacks.\n */\n readonly on: Readonly<Record<string, InspectedForm>>\n}\n\nexport { controlOf, inputOf, settingsOf, type Settings } from './settings.js'\nexport { editWords, type EditWords } from './words.js'\n\n/** An edit that creates nodes and waits for their new ids. */\nconst Request = Schema.Union([\n Schema.TaggedStruct('Insert', { block: Schema.String, at: Composition.Position }),\n Schema.TaggedStruct('Duplicate', { id: NodeId, at: Composition.Position }),\n Schema.TaggedStruct('Paste', { tree: Composition.Tree, at: Composition.Position }),\n Schema.TaggedStruct('Pattern', { pattern: Schema.String, at: Composition.Position }),\n])\n\n/**\n * A copied node as the system clipboard holds it: JSON, tagged, so text that\n * is not part of a page is not pasted as one.\n */\nconst Clip = Schema.fromJsonString(\n Schema.Struct({ format: Schema.Literal('foldkit-composition'), tree: Composition.Tree }),\n)\nconst clipText = (tree: Tree): string =>\n Schema.encodeSync(Clip)({ format: 'foldkit-composition', tree })\n// Strict: a clipboard is anyone's text, and a key misspelled is refused, not dropped.\nconst clipOf = Schema.decodeUnknownResult(Clip, { onExcessProperty: 'error' })\n\nexport const Message = defineMessageUnion({\n ...Layers.cases,\n ...Announcer.cases,\n Selected: { id: NodeId },\n /** Nothing is selected. */\n Deselected: {},\n Hovered: { id: NodeId },\n /** The pointer left every node. */\n Unhovered: {},\n /** An Operation, from a button, a key, a drag, or an agent. */\n Applied: { op: Composition.Operation },\n /** A new node of a Block, with the Block's starting props, once an id is minted. */\n InsertAsked: { block: Schema.String, at: Composition.Position },\n /** A copy of a node and everything it holds, once ids are minted. */\n DuplicateAsked: { id: NodeId, at: Composition.Position },\n /** One of the Catalog's patterns, once ids are minted for its nodes. */\n PatternAsked: { pattern: Schema.String, at: Composition.Position },\n /** The selected node and all it holds, copied. */\n CopyAsked: { id: NodeId },\n /** The selected node and all it holds, copied and removed. */\n CutAsked: { id: NodeId },\n /** A paste: the system clipboard is read, and what it holds goes in by the selection. */\n PasteAsked: {},\n /** What the system clipboard held for a paste; none when it could not be read. */\n ClipboardRead: { text: Schema.OptionFromNullOr(Schema.String) },\n /**\n * Text on the page is asked to be edited in place: a double-click on it, or\n * Enter on its node. Each of these names the field as the canvas marks it\n * (`data-composition-field`), which is checked here.\n */\n EditingAsked: { field: Schema.String },\n /** What the field being edited holds now. */\n FieldTyped: { field: Schema.String, text: Schema.String },\n /** Editing ended with the text kept: Enter, or leaving the field. */\n EditingCommitted: { field: Schema.String, text: Schema.String },\n /** Editing ended with the text put back as it began: Escape. */\n EditingCancelled: { field: Schema.String },\n /** The ids a request waited for. */\n Minted: { ids: Schema.Array(NodeId), request: Request },\n /**\n * A key a command binds, pressed on the layers or the canvas: which command\n * it runs is decided in `update`, from the Model as it is then.\n */\n KeyPressed: {\n key: Schema.String,\n modifiers: Schema.Struct({\n shiftKey: Schema.Boolean,\n ctrlKey: Schema.Boolean,\n altKey: Schema.Boolean,\n metaKey: Schema.Boolean,\n }),\n },\n Undid: {},\n Redid: {},\n PanelChosen: { panel: Panel },\n ViewportChosen: { viewport: Viewport },\n /** A pointer drag of a node began: it is selected, and nothing moves until the drop. */\n DragStarted: { source: DragSource },\n /** The dragged node is over another, in a zone of it. */\n DraggedOver: { id: NodeId, zone: DropZone },\n /** The dragged node is over a node's empty Region, by name: a drop goes into it. */\n DraggedOverRegion: { id: NodeId, region: Schema.String },\n /** The dragged node is over nothing. */\n DraggedOff: {},\n /**\n * A palette tile is over the page but over none of its nodes, as an empty\n * page or the space below the last node: it goes last where the page takes it.\n */\n DraggedOverPage: {},\n /** The drag ended where it is: the node moves there, when it may. */\n DragDropped: {},\n DragCancelled: {},\n /** The author previews the page with one context key set. */\n PreviewChosen: { key: Schema.String, value: ContextValue },\n /** The author previews the page with one context key unset. */\n PreviewCleared: { key: Schema.String },\n /**\n * A Message of one of a node's forms (`Inspecting`), encoded to JSON. One for\n * a node no longer selected, or a form it no longer draws, such as a form's\n * Command answering late, is ignored.\n */\n Inspected: { id: NodeId, form: Schema.String, message: Schema.Json },\n})\nexport type Message = typeof Message.Type\n\nconst Parent = Bundle.parent({ Model, Message })\n/** The layers' tree and the announcer, placed in the Builder's own Model. */\nconst placements = Parent.assemble(\n Parent.at(Layers, { args: layersArgs }),\n Parent.at(Announcer, { args: announcerArgs }),\n)\n\n/** Props as a Document stores them, read from what a Block's Schema encoded. */\nconst storedProps = Schema.decodeUnknownResult(Composition.Node.fields.props)\n\n/** What a new node of each Block starts with. A Block without starting props is not offered. */\nexport type Starters<Blocks extends AnyBlock> = {\n readonly [B in Blocks as B['name']]?: PropsOf<B>\n}\n\n/**\n * Where a new node of `block` goes, given what is selected: inside it, after\n * it, or last, among the roots or, for a Block that is no root, in the last\n * Region on the page with room that accepts it. None where it fits nowhere.\n */\nconst placeFor = (\n catalog: Catalog,\n document: Document,\n selected: Option.Option<NodeId>,\n blockName: string,\n): Option.Option<Position> => {\n const block = Catalog.block(catalog, blockName)\n if (block === undefined) return Option.none()\n const fits = (accepted: ReadonlyArray<unknown>) =>\n block.provides.some(content => accepted.includes(content))\n /** Last in the first of a node's Regions with room that accepts the Block. */\n const inside = (id: NodeId): Option.Option<Position> => {\n const node = document.nodes[id]\n const owner = node === undefined ? undefined : Catalog.block(catalog, node.block)\n if (node !== undefined && owner !== undefined)\n for (const [name, region] of Object.entries(owner.regions)) {\n const children = node.regions[name] ?? []\n if (fits(region.accepts) && children.length < region.max)\n return Option.some(Composition.region(id, name, children.length))\n }\n return Option.none()\n }\n if (Option.isSome(selected)) {\n const within = inside(selected.value)\n if (Option.isSome(within)) return within\n }\n const place = Option.isSome(selected)\n ? Composition.index(document).get(selected.value)\n : undefined\n if (place !== undefined && place.parent !== undefined && place.region !== undefined) {\n const parent = document.nodes[place.parent]\n const parentBlock = parent === undefined ? undefined : Catalog.block(catalog, parent.block)\n const region = parentBlock?.regions[place.region]\n const siblings = parent?.regions[place.region] ?? []\n if (region !== undefined && fits(region.accepts) && siblings.length < region.max)\n return Option.some(Composition.region(place.parent, place.region, place.index + 1))\n }\n if (fits(catalog.roots))\n return Option.some(\n Composition.root(\n place !== undefined && place.parent === undefined ? place.index + 1 : document.roots.length,\n ),\n )\n // Nodes in page order, last first, so the place found is the last one on the page.\n const order: Array<NodeId> = []\n const visit = (id: NodeId): void => {\n order.push(id)\n for (const ids of Object.values(document.nodes[id]?.regions ?? {})) ids.forEach(visit)\n }\n document.roots.forEach(visit)\n for (const id of order.reverse()) {\n const last = inside(id)\n if (Option.isSome(last)) return last\n }\n return Option.none()\n}\n\n/** Whether a place has room for one more node: a root always, a Region below its most. */\nconst hasRoom = (catalog: Catalog, document: Document, at: Position): boolean => {\n if (at._tag === 'Root') return true\n const holder = document.nodes[at.parent]\n const region =\n holder === undefined ? undefined : Catalog.block(catalog, holder.block)?.regions[at.region]\n return region !== undefined && (holder?.regions[at.region] ?? []).length < region.max\n}\n\n/** The Operation that moves a node `delta` places among its siblings; none at an end. */\nconst moveBy = (document: Document, id: NodeId, delta: number): Option.Option<Operation> => {\n const place = Composition.index(document).get(id)\n if (place === undefined) return Option.none()\n const to = place.index + delta\n const siblings =\n place.parent === undefined\n ? document.roots\n : (document.nodes[place.parent]?.regions[place.region ?? ''] ?? [])\n if (to < 0 || to >= siblings.length) return Option.none()\n return Option.some(\n Composition.Op.move(\n id,\n place.parent === undefined\n ? Composition.root(to)\n : Composition.region(place.parent, place.region ?? '', to),\n ),\n )\n}\n\n/** The first of a holder's Regions that accepts a Block, by name: where \"inside it\" goes. */\nconst regionTaking = (catalog: Catalog, holder: string, block: string): Option.Option<string> => {\n const owner = Catalog.block(catalog, holder)\n const taken = Catalog.block(catalog, block)\n return Option.map(\n Option.fromUndefinedOr(\n Object.entries(owner?.regions ?? {}).find(([, candidate]) =>\n (taken?.provides ?? []).some(content => candidate.accepts.includes(content)),\n ),\n ),\n ([name]) => name,\n )\n}\n\n/**\n * What is dragged, as `landing` weighs it: its Block, the node it is if it is\n * on the page already, and the Operation that would put it at a place.\n */\ninterface Dragged {\n readonly block: string\n readonly id: Option.Option<NodeId>\n readonly to: (at: Position) => Operation\n}\n\n/**\n * Where something dragged over `target`, in `zone`, lands beside or inside\n * that one node: before or after it among its siblings, or last in the first\n * of its Regions that accepts it, with the zone it landed in. `inside` a node\n * that takes it nowhere lands after it. None when the page would refuse it\n * there, such as a node into itself: each place is tried, a move for a node\n * and an insert for a new one. `stays` where it would land on its own place.\n */\nconst landingBy = (\n catalog: Catalog,\n document: Document,\n dragged: Dragged,\n target: NodeId,\n zone: DropZone,\n /** For `inside`, the Region it goes into, in place of the first that accepts it. */\n region: Option.Option<string>,\n): Option.Option<{ readonly at: Position; readonly zone: DropZone }> | 'stays' => {\n const place = Composition.index(document).get(target)\n if (Option.contains(dragged.id, target) || place === undefined) return Option.none()\n // A move takes the node out before putting it back, so places count without it.\n const without = (ids: ReadonlyArray<NodeId>) => ids.filter(id => !Option.contains(dragged.id, id))\n const beside = (offset: 0 | 1): Option.Option<Position> => {\n const siblings =\n place.parent === undefined\n ? document.roots\n : (document.nodes[place.parent]?.regions[place.region ?? ''] ?? [])\n const at = without(siblings).indexOf(target) + offset\n return Option.some(\n place.parent === undefined\n ? Composition.root(at)\n : Composition.region(place.parent, place.region ?? '', at),\n )\n }\n const inside = (): Option.Option<Position> => {\n const holder = document.nodes[target]\n if (holder === undefined) return Option.none()\n const named = Option.orElse(region, () => regionTaking(catalog, holder.block, dragged.block))\n return Option.map(named, regionName =>\n Composition.region(target, regionName, without(holder.regions[regionName] ?? []).length),\n )\n }\n // Where the dragged node is now, counted the same way: a drop there moves nothing.\n const current = Option.flatMap(dragged.id, id =>\n Option.fromUndefinedOr(Composition.index(document).get(id)),\n ).pipe(Option.getOrUndefined)\n const stays = (at: Position) =>\n current !== undefined &&\n at.index === current.index &&\n (at._tag === 'Root'\n ? current.parent === undefined\n : at.parent === current.parent && at.region === current.region)\n const candidates: ReadonlyArray<{\n readonly at: Option.Option<Position>\n readonly zone: DropZone\n }> =\n zone === 'before'\n ? [{ at: beside(0), zone }]\n : zone === 'after'\n ? [{ at: beside(1), zone }]\n : [\n { at: inside(), zone },\n { at: beside(1), zone: 'after' },\n ]\n for (const candidate of candidates) {\n if (Option.isNone(candidate.at)) continue\n const at = candidate.at.value\n // Onto its own place is not a move, and no later candidate is meant instead.\n if (stays(at)) return 'stays'\n if (Result.isSuccess(Composition.apply(catalog, document, dragged.to(at))))\n return Option.some({ at, zone: candidate.zone })\n }\n return Option.none()\n}\n\n/** The Document being edited. */\nconst documentOf = (model: Pick<Model, 'page'>): Document => model.page.present\n\n/**\n * The undo group an Operation joins: consecutive edits of one prop of one node\n * are one step, so typing a heading undoes as a whole. Everything else stands\n * alone, which `History.push` takes as a `null` group.\n */\nconst groupOf = (op: Operation): string | null =>\n op._tag === 'SetProp' ? `SetProp:${op.id}:${op.prop}` : null\n\n/** The position right after a node, among its siblings. */\nconst after = (document: Document, id: NodeId): Option.Option<Position> => {\n const place = Composition.index(document).get(id)\n if (place === undefined) return Option.none()\n return Option.some(\n place.parent === undefined\n ? Composition.root(place.index + 1)\n : Composition.region(place.parent, place.region ?? '', place.index + 1),\n )\n}\n\n/** The Operation that moves a node out of its parent, to just after it; none at the top. */\nconst outdent = (document: Document, id: NodeId): Option.Option<Operation> => {\n const parent = Composition.index(document).get(id)?.parent\n if (parent === undefined) return Option.none()\n return Option.map(after(document, parent), to => Composition.Op.move(id, to))\n}\n\n/**\n * The Operation that moves a node into the sibling above it, last in the first\n * of its Regions that accepts it; none when there is none. Whether it fits is\n * `apply`'s to check; this only picks the Region.\n */\nconst indent = (catalog: Catalog, document: Document, id: NodeId): Option.Option<Operation> => {\n const place = Composition.index(document).get(id)\n const node = document.nodes[id]\n if (place === undefined || node === undefined || place.index === 0) return Option.none()\n const siblings =\n place.parent === undefined\n ? document.roots\n : (document.nodes[place.parent]?.regions[place.region ?? ''] ?? [])\n const above = siblings[place.index - 1]\n const target = above === undefined ? undefined : document.nodes[above]\n if (above === undefined || target === undefined) return Option.none()\n return Option.map(regionTaking(catalog, target.block, node.block), regionName =>\n Composition.Op.move(\n id,\n Composition.region(above, regionName, (target.regions[regionName] ?? []).length),\n ),\n )\n}\n\n/** The node a pattern's use makes its root; none for a pattern the Catalog lacks. */\nconst patternRoot = (\n catalog: Catalog,\n op: { readonly pattern: string; readonly ids: Readonly<Record<NodeId, NodeId>> },\n): Option.Option<NodeId> =>\n Option.flatMap(Catalog.pattern(catalog, op.pattern), pattern =>\n Option.fromUndefinedOr(op.ids[pattern.tree.root]),\n )\n\n/** A Block's label, the Catalog's word; one the Catalog lacks by its stored name. */\nconst blockLabel = (catalog: Catalog, block: string): string =>\n Catalog.block(catalog, block)?.words.label ?? block\n\n/** What an applied edit says to assistive technology; none for a prop change. */\nconst describeEdit = (\n catalog: Catalog,\n words: EditWords,\n before: Document,\n after: Document,\n op: Operation,\n): Option.Option<string> => {\n const labelOf = (document: Document, id: NodeId): string =>\n Option.match(Option.fromUndefinedOr(document.nodes[id]), {\n onNone: () => id,\n onSome: node => blockLabel(catalog, node.block),\n })\n const where = (id: NodeId): string => {\n const place = Composition.index(after).get(id)\n if (place === undefined) return ''\n const siblings =\n place.parent === undefined\n ? after.roots.length\n : (after.nodes[place.parent]?.regions[place.region ?? '']?.length ?? 0)\n const container =\n place.parent === undefined\n ? words.thePage\n : fillWords(words.inRegion, {\n label: labelOf(after, place.parent),\n region: place.region ?? '',\n })\n return fillWords(words.at, { position: place.index + 1, count: siblings, container })\n }\n const said = (template: string, id: NodeId) =>\n fillWords(template, { label: labelOf(after, id), at: where(id) })\n switch (op._tag) {\n case 'Move':\n return Option.some(said(words.moved, op.id))\n case 'Insert':\n return Option.some(said(words.added, op.id))\n case 'InsertTree':\n return Option.some(said(words.added, op.tree.root))\n case 'Duplicate':\n return Option.map(Option.fromUndefinedOr(op.ids[op.id]), copy => said(words.duplicated, copy))\n case 'UsePattern':\n return Option.map(patternRoot(catalog, op), root => said(words.added, root))\n case 'Remove':\n return Option.some(fillWords(words.removed, { label: labelOf(before, op.id) }))\n case 'Batch':\n return op.ops.length === 0 ? Option.none() : Option.some(words.editedPage)\n case 'SetProp':\n case 'UnsetProp':\n case 'SetWhen':\n case 'SetAppearance':\n case 'SetAction':\n return Option.none()\n }\n}\n\n/** The selection, kept only while the Document still holds it. */\nconst keptIn = (document: Document, selected: Option.Option<NodeId>): Option.Option<NodeId> =>\n Option.filter(selected, id => document.nodes[id] !== undefined)\n\n/** The Model showing another Document: what a fill, a reset or a restored revision does. */\nconst replace = (model: Model, document: Document): Model => ({\n ...model,\n page: History.start(document),\n selected: keptIn(document, model.selected),\n hovered: Option.none(),\n refused: Option.none(),\n drag: Option.none(),\n inspector: Option.none(),\n editing: Option.none(),\n})\n\n/** The Model with nothing in flight, as a stored draft is shown again: no hover, no drag, no undo, no refusal. */\nconst settle = (model: Model): Model => ({\n ...model,\n hovered: Option.none(),\n refused: Option.none(),\n drag: Option.none(),\n editing: Option.none(),\n page: History.clear(model.page),\n})\n\n/** The undo group of one editing session: its steps are one, and ending it cancelled takes them back. */\nconst editingGroup = (editing: { readonly id: NodeId; readonly key: string }): string =>\n `Editing:${fieldName(editing.id, editing.key)}`\n\n/**\n * Where something dragged over `target`, in `zone`, lands: by `target`, else\n * by the nearest node holding it where it fits, before it for `before` and\n * after it otherwise, so a Section dropped on the last Heading of a Section\n * lands after that Section. It climbs no further than a node being dragged.\n * With the node it landed by.\n */\nconst landing = (\n catalog: Catalog,\n document: Document,\n dragged: Dragged,\n target: NodeId,\n zone: DropZone,\n region: Option.Option<string> = Option.none(),\n): Option.Option<{\n readonly at: Position\n readonly zone: DropZone\n readonly by: NodeId\n readonly region: Option.Option<string>\n}> => {\n const places = Composition.index(document)\n for (\n let by: NodeId | undefined = target, at: DropZone = zone, into = region;\n by !== undefined && !Option.contains(dragged.id, by);\n by = places.get(by)?.parent, at = zone === 'before' ? 'before' : 'after', into = Option.none()\n ) {\n const landed = landingBy(catalog, document, dragged, by, at, into)\n // Its own place is no move, and no holder's place is meant instead.\n if (landed === 'stays') return Option.none()\n if (Option.isSome(landed))\n return Option.some({\n ...landed.value,\n by,\n // Marked on the Region only where it went into the one it was over.\n region: landed.value.zone === 'inside' ? into : Option.none(),\n })\n }\n return Option.none()\n}\n\n/** The node an Operation that creates nodes creates first, to select it. */\nconst created = (catalog: Catalog, op: Operation): Option.Option<NodeId> =>\n op._tag === 'Insert'\n ? Option.some(op.id)\n : op._tag === 'InsertTree'\n ? Option.some(op.tree.root)\n : op._tag === 'Duplicate'\n ? Option.fromUndefinedOr(op.ids[op.id])\n : op._tag === 'UsePattern'\n ? patternRoot(catalog, op)\n : Option.none()\n\n/**\n * A key that runs a command, named as `KeyboardEvent.key` names it. `mod` is\n * Ctrl, or ⌘ on a Mac. `mod` and `alt` must be as given; `shift` must be as\n * given only where it is given, so a key that leaves it out takes either.\n */\nexport interface CommandKey {\n readonly key: string\n readonly mod?: boolean\n readonly alt?: boolean\n readonly shift?: boolean\n}\n\n/** One thing the editor does, and every way to ask for it. */\nexport interface BuilderCommand {\n readonly id: string\n /** What it is called, on its button and in the list of shortcuts. */\n readonly label: string\n /** The keys that run it; the first is the one shown. None for one run only by a button. */\n readonly keys: ReadonlyArray<CommandKey>\n /** Where a drawn Builder offers it: with the selected node's actions, in the toolbar, or by key only. */\n readonly placement: ReadonlyArray<'node' | 'toolbar' | 'keyboard'>\n /** The Message it sends now; none while it has nothing to do, which disables its button. */\n readonly run: (model: Pick<Model, 'page' | 'selected'>) => Option.Option<Message>\n}\n\n/** Whether a key press is `spec`. A letter is matched as either case. */\nconst pressed = (spec: CommandKey, key: string, modifiers: KeyboardModifiers): boolean =>\n spec.key.toLowerCase() === key.toLowerCase() &&\n (spec.mod ?? false) === (modifiers.ctrlKey || modifiers.metaKey) &&\n (spec.alt ?? false) === modifiers.altKey &&\n (spec.shift === undefined || spec.shift === modifiers.shiftKey)\n\nexport const Builder = {\n /**\n * Block metadata: the control the inspector draws a prop with, where its\n * Schema alone does not say, as\n * `Heading.pipe(Block.annotate(Builder.controls({ text: Input.multiline() })))`.\n * `Input.hidden()` leaves a prop out of the inspector.\n */\n controls,\n\n /**\n * A Builder for a Catalog: its Bundle, the form control that places it as a\n * key, and the helpers a view uses. `starters` gives the props a new node of\n * each Block starts with; the insert panel offers exactly those Blocks.\n */\n make: <const Name extends string, Blocks extends AnyBlock>(\n name: Name,\n config: {\n readonly catalog: Catalog<Blocks>\n readonly renderer: Renderer<Blocks, never>\n readonly starters: NoInfer<Starters<Blocks>>\n /** Undo steps kept. Default 200. */\n readonly capacity?: number\n /** The context the editor previews the page as at first, by the Catalog's context keys. */\n readonly preview?: Readonly<Record<string, ContextValue>>\n /**\n * The editor's commands, given the built ones: another key for one, one\n * left out, another order. What runs a key, the node's actions and the\n * toolbar are all drawn from the table this returns.\n */\n readonly commands?: (built: ReadonlyArray<BuilderCommand>) => ReadonlyArray<BuilderCommand>\n /** What it says of each edit, its commands' labels and its refusals, over the English ones. */\n readonly words?: Partial<EditWords>\n },\n ) => {\n const { catalog, renderer } = config\n const words: EditWords = { ...editWords, ...config.words }\n const starters = config.starters as Readonly<Record<string, unknown>>\n // Each Block's props form, made now, so a control the inspector cannot run\n // is refused where the Builder is made, not at the first selection.\n for (const block of catalog.blocks) settingsOf(block)\n type Commands = ReadonlyArray<CommandOf<Message>>\n\n const capacity = config.capacity ?? 200\n const initial: Model = placements.initial({\n page: History.start(Composition.empty()),\n selected: Option.none(),\n hovered: Option.none(),\n panel: 'insert',\n viewport: 'wide',\n refused: Option.none(),\n drag: Option.none(),\n preview: { ...config.preview },\n inspector: Option.none(),\n clipboard: Option.none(),\n editing: Option.none(),\n }).model\n\n /** Says `text` to assistive technology, once the Builder's transition is done. */\n const announce = (text: string, politeness: LiveAnnounce.Politeness = 'polite'): Commands => [\n {\n name: `${name}.announce`,\n effect: Effect.succeed(LiveAnnounce.say(Announcer)<Message>(text, politeness)),\n },\n ]\n\n const refuse = (\n model: Model,\n // An Operation `apply` refused, or a paste of nothing: no Operation at all.\n refusal:\n | Refusal\n | {\n readonly code: 'builder:nothing-to-paste' | 'builder:no-place'\n readonly message: string\n },\n ): { readonly model: Model; readonly commands: Commands } => ({\n model: { ...model, refused: Option.some(refusal) },\n commands: announce(refusal.message, 'assertive'),\n })\n\n const applyOp = (\n model: Model,\n op: Operation,\n group: string | null = groupOf(op),\n ): { readonly model: Model; readonly commands?: Commands } => {\n const result = Composition.apply(catalog, documentOf(model), op)\n if (Result.isFailure(result))\n return refuse(model, {\n ...result.failure,\n message: fillWords(words.refusal, {\n code: result.failure.code,\n message: result.failure.message,\n }),\n })\n const { document, removed } = result.success\n const kept = Option.filter(model.selected, id => !removed.includes(id))\n return {\n model: {\n ...model,\n page: History.push(model.page, document, { capacity, group }),\n selected: Option.orElse(created(catalog, op), () => kept),\n refused: Option.none(),\n },\n ...Option.match(describeEdit(catalog, words, documentOf(model), document, op), {\n onNone: () => ({}),\n onSome: said => ({ commands: announce(said) }),\n }),\n }\n }\n\n /** A Block's starting props, encoded as the Document stores them; none for a Block with none. */\n const startingProps = (name: string): Option.Option<Readonly<Record<string, Schema.Json>>> => {\n // Read as any Block: the starting props were checked against theirs in `make`.\n const block: AnyBlock | undefined = Catalog.block(catalog, name)\n // A Block the Catalog lacks has none; one given no starting props fails to encode, below.\n if (block === undefined) return Option.none()\n return Result.getSuccess(Result.flatMap(Block.encode(block, starters[name]), storedProps))\n }\n\n /**\n * Where a palette tile dropped on the page's own space goes: last where the\n * page takes its Block, as a press with nothing selected puts it. None for\n * a node on the page, which is moved only onto another.\n */\n const onPage = (document: Document, source: DragSource): Option.Option<Position> =>\n source._tag === 'New'\n ? placeFor(catalog, document, Option.none(), source.block)\n : Option.none()\n\n /** What a drag carries, as `landing` weighs it; none for a node gone or a Block not offered. */\n const draggedOf = (document: Document, source: DragSource): Option.Option<Dragged> => {\n if (source._tag === 'Existing') {\n const node = document.nodes[source.id]\n return node === undefined\n ? Option.none()\n : Option.some({\n block: node.block,\n id: Option.some(source.id),\n to: at => Composition.Op.move(source.id, at),\n })\n }\n // Tried with an id no node on this page has; the drop asks for a real one.\n let unused = 'dragged'\n while (document.nodes[NodeId.make(unused)] !== undefined) unused = `${unused}-`\n const trial = NodeId.make(unused)\n return Option.map(startingProps(source.block), props => ({\n block: source.block,\n id: Option.none(),\n to: at => Composition.Op.insert({ id: trial, block: source.block, props, at }),\n }))\n }\n\n /**\n * The drag, over `id` in `zone` (or its empty `region`), marked where it\n * lands: a drop inside a node that takes nothing is after it, and one its\n * holder takes instead is marked on the holder.\n */\n const draggedOver = (\n model: Model,\n id: NodeId,\n zone: DropZone,\n region: Option.Option<string>,\n ): { readonly model: Model } => {\n if (Option.isNone(model.drag)) return { model }\n const drag = model.drag.value\n const landed = Option.flatMap(draggedOf(documentOf(model), drag.source), dragged =>\n landing(catalog, documentOf(model), dragged, id, zone, region),\n )\n return {\n model: {\n ...model,\n drag: Option.some({\n ...drag,\n over: Option.some(\n Option.match(landed, {\n onNone: () => ({ id, zone, region }),\n onSome: ({ by, zone, region }) => ({ id: by, zone, region }),\n }),\n ),\n at: Option.map(landed, ({ at }) => at),\n }),\n },\n }\n }\n\n /** Puts a node's tree on the system clipboard, then says `said`, whether it could or not. */\n const copy = (tree: Tree, said: string): Commands => [\n {\n name: `${name}.copy`,\n effect: Effect.as(\n copyText(clipText(tree)).effect,\n LiveAnnounce.say(Announcer)<Message>(said, 'polite'),\n ),\n },\n ]\n\n /** The edit under way of the field a canvas Message names; none for any other. */\n const editingOf = (model: Model, field: string) =>\n Option.flatMap(fieldOf(field), named =>\n Option.filter(\n model.editing,\n editing => editing.id === named.id && editing.key === named.key,\n ),\n )\n\n /** What is said when a drag ends with nothing done. */\n const unmoved = (source: DragSource): string =>\n source._tag === 'Existing' ? words.notMoved : words.notAdded\n\n /** Asks for `count` new ids; the request goes through once they arrive. */\n const mint = (count: number, request: typeof Request.Type): Commands => [\n {\n name: `${name}.mint`,\n effect: Effect.map(Composition.newIds(count), ids => Message.Minted({ ids, request })),\n },\n ]\n\n /** A stored value that is a record of JSON, as props and an action's input are; else empty. */\n const recordOf = (value: unknown): Readonly<Record<string, Schema.Json>> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n ? (value as Readonly<Record<string, Schema.Json>>)\n : {}\n\n /**\n * A node's forms, each with the stored values it fills from and the\n * Operations that write its changed values back and take away those\n * cleared.\n */\n const formsOf = (id: NodeId, node: Document['nodes'][NodeId], block: AnyBlock) => {\n const props = {\n key: 'props',\n settings: settingsOf(block),\n stored: recordOf(node.props),\n write: (\n changed: Readonly<Record<string, Schema.Json>>,\n cleared: ReadonlyArray<string>,\n ): ReadonlyArray<Operation> => [\n ...Object.entries(changed).map(([key, value]) => Composition.Op.setProp(id, key, value)),\n ...cleared.map(key => Composition.Op.unsetProp(id, key)),\n ],\n }\n const refs = recordOf(node.actions)\n const on = block.events.flatMap(event => {\n const ref = recordOf(refs[event])\n const action = catalog.actions.find(each => each.name === ref['action'])\n if (action === undefined) return []\n const input = recordOf(ref['input'])\n const settings = inputOf(block, event, action)\n return [\n {\n event,\n key: `on:${event}:${action.name}`,\n settings,\n stored: input,\n // The action's input is one value: the changed keys over what it held, less\n // those cleared and any its Schema no longer names, which would be refused.\n write: (\n changed: Readonly<Record<string, Schema.Json>>,\n cleared: ReadonlyArray<string>,\n ): ReadonlyArray<Operation> => [\n Composition.Op.setAction(id, event, {\n action: action.name,\n input: Object.fromEntries(\n Object.entries({ ...input, ...changed }).filter(\n ([key]) => settings.keys.includes(key) && !cleared.includes(key),\n ),\n ),\n }),\n ],\n },\n ]\n })\n return { props, on }\n }\n\n /**\n * The selected node's forms and their Models: the Model the inspector\n * holds for each, else one filled from the node. None when nothing is\n * selected or its Block is not in the Catalog.\n */\n const inspecting = (\n model: Pick<Model, 'page' | 'selected' | 'inspector'>,\n ): Option.Option<Inspecting> =>\n Option.flatMap(model.selected, id => {\n const node = documentOf(model).nodes[id]\n const block: AnyBlock | undefined =\n node === undefined ? undefined : Catalog.block(catalog, node.block)\n if (node === undefined || block === undefined) return Option.none()\n const held: Readonly<Record<string, Schema.Json>> = Option.match(\n Option.filter(model.inspector, inspector => inspector.id === id),\n { onNone: () => ({}), onSome: inspector => inspector.forms },\n )\n const drawn = (form: {\n readonly key: string\n readonly settings: Settings\n readonly stored: Readonly<Record<string, Schema.Json>>\n }): InspectedForm => ({\n key: form.key,\n settings: form.settings,\n model: Option.getOrElse(\n Option.flatMap(Option.fromUndefinedOr(held[form.key]), form.settings.decode),\n () => form.settings.fill(form.settings.form.initial, form.stored),\n ),\n })\n const { props, on } = formsOf(id, node, block)\n return Option.some({\n id,\n block,\n props: drawn(props),\n on: Object.fromEntries(on.map(form => [form.event, drawn(form)])),\n })\n })\n\n /** A form's Model refilled from what the node stores, but for a field that does not decode. */\n const refill = (\n settings: Settings,\n model: InspectedForm['model'],\n stored: Readonly<Record<string, Schema.Json>>,\n ) => settings.fill(model, stored, key => settings.form.field(model, key)._tag === 'Invalid')\n\n /**\n * A Message of one of the selected node's forms: the form takes it, and\n * each value it changed, and that the node does not already hold, is\n * written back: a prop by one `setProp` each, an action's input by one\n * `setAction`; a value cleared that the node held is taken away. A field\n * that does not decode writes nothing and shows its error; a value the\n * node refuses is said, and the form shows what the node holds again.\n */\n const inspect = (\n model: Model,\n message: { readonly id: NodeId; readonly form: string; readonly message: Schema.Json },\n ): { readonly model: Model; readonly commands?: Commands } => {\n const target = Option.filter(inspecting(model), each => each.id === message.id)\n const node = documentOf(model).nodes[message.id]\n if (Option.isNone(target) || node === undefined) return { model }\n const { id, block, props, on } = target.value\n const forms = formsOf(id, node, block)\n const known = [\n { ...forms.props, model: props.model },\n ...forms.on.flatMap(form => {\n const drawn = on[form.event]\n return drawn === undefined ? [] : [{ ...form, model: drawn.model }]\n }),\n ].find(form => form.key === message.form)\n if (known === undefined) return { model }\n const { settings, stored, write } = known\n return Option.match(settings.decodeMessage(message.message), {\n onNone: () => ({ model }),\n onSome: formMessage => {\n const next = settings.form.bundle.update(known.model, formMessage, undefined)\n // Stored values are JSON, so their text tells two apart.\n const text = (value: unknown) => JSON.stringify(value)\n const before: Readonly<Record<string, unknown>> = settings.form.partial(known.model)\n const after: Readonly<Record<string, unknown>> = settings.form.partial(next.model)\n // Only what this Message changed: a field left alone is never written\n // back, even where its draft does not give back the stored value exactly.\n const changed = Object.fromEntries(\n Object.entries(after).flatMap(([key, value]) =>\n Object.hasOwn(before, key) && text(before[key]) === text(value)\n ? []\n : Option.match(settings.stored(key, value), {\n onNone: () => [],\n onSome: json => (text(json) === text(stored[key]) ? [] : [[key, json]]),\n }),\n ),\n )\n // A value that left the form without its field failing, as an optional\n // one emptied does: the node holds it no longer.\n const cleared = Object.keys(before).filter(\n key =>\n !Object.hasOwn(after, key) && settings.form.field(next.model, key)._tag !== 'Invalid',\n )\n const held = Option.match(model.inspector, {\n onNone: () => ({}),\n onSome: inspector => (inspector.id === id ? inspector.forms : {}),\n })\n let result: { readonly model: Model; readonly commands?: Commands } = {\n model: {\n ...model,\n inspector: Option.some({\n id,\n forms: { ...held, [known.key]: settings.encode(next.model) },\n }),\n },\n }\n const commands: Array<CommandOf<Message>> = [\n ...Command.mapMessages(next.commands, sent =>\n Message.Inspected({ id, form: known.key, message: settings.encodeMessage(sent) }),\n ),\n ]\n let refused = false\n if (Object.keys(changed).length > 0 || cleared.length > 0)\n for (const op of write(changed, cleared)) {\n result = applyOp(result.model, op)\n // A write that went through clears the refusal: one left is this one's.\n refused ||= Option.isSome(result.model.refused)\n commands.push(...(result.commands ?? []))\n }\n if (!refused) return { model: result.model, commands }\n // Refused: the form shows what the node holds, not a value it never took.\n const now = formsOf(id, documentOf(result.model).nodes[id] ?? node, block)\n const holds = [now.props, ...now.on].find(form => form.key === known.key)\n return {\n model: {\n ...result.model,\n inspector: Option.some({\n id,\n forms: {\n ...held,\n [known.key]: settings.encode(\n refill(settings, next.model, holds?.stored ?? stored),\n ),\n },\n }),\n },\n commands,\n }\n },\n })\n }\n\n /**\n * The inspector after a transition not its own: dropped when the selection\n * moved; when the page changed by another way (an undo, the canvas, an\n * agent), each form it holds is refilled from the node, except a field the\n * author is typing into that does not decode, and a form the node no\n * longer draws is let go.\n */\n const reconciled = (before: Model, after: Model): Model => {\n if (Option.isNone(after.inspector)) return after\n const { id, forms: held } = after.inspector.value\n if (!Option.contains(after.selected, id)) return { ...after, inspector: Option.none() }\n if (documentOf(after) === documentOf(before)) return after\n const node = documentOf(after).nodes[id]\n const block: AnyBlock | undefined =\n node === undefined ? undefined : Catalog.block(catalog, node.block)\n if (node === undefined || block === undefined) return { ...after, inspector: Option.none() }\n const { props, on } = formsOf(id, node, block)\n const refilled = [props, ...on].flatMap(form =>\n Option.match(Option.flatMap(Option.fromUndefinedOr(held[form.key]), form.settings.decode), {\n onNone: () => [],\n onSome: model => [\n [form.key, form.settings.encode(refill(form.settings, model, form.stored))] as const,\n ],\n }),\n )\n return {\n ...after,\n inspector:\n refilled.length === 0\n ? Option.none()\n : Option.some({ id, forms: Object.fromEntries(refilled) }),\n }\n }\n\n const own = (\n model: Model,\n message: Message,\n ): { readonly model: Model; readonly commands?: Commands } => {\n switch (message._tag) {\n // Judged against the Model as it is, not as last drawn: a key pressed\n // before the frame that draws a new selection acts on that selection.\n case 'KeyPressed':\n return Option.match(keyCommand(model, message.key, message.modifiers), {\n onNone: () => ({ model }),\n onSome: sent => own(model, sent),\n })\n case 'Selected':\n // A node the page does not hold selects nothing.\n return documentOf(model).nodes[message.id] === undefined\n ? { model: { ...model, selected: Option.none() } }\n : { model: { ...model, selected: Option.some(message.id), panel: 'properties' } }\n case 'Deselected':\n return { model: { ...model, selected: Option.none() } }\n case 'Hovered':\n return { model: { ...model, hovered: Option.some(message.id) } }\n case 'Unhovered':\n return { model: { ...model, hovered: Option.none() } }\n case 'Applied':\n return applyOp(model, message.op)\n case 'InsertAsked':\n return !Object.hasOwn(starters, message.block)\n ? refuse(model, {\n code: 'composition:unknown-block',\n message: fillWords(words.noStartingProps, { block: message.block }),\n })\n : { model, commands: mint(1, { _tag: 'Insert', block: message.block, at: message.at }) }\n case 'DuplicateAsked': {\n if (documentOf(model).nodes[message.id] === undefined)\n return refuse(model, {\n code: 'composition:missing-node',\n message: fillWords(words.notANode, { id: message.id }),\n })\n const count = Object.keys(\n Composition.takeTree(documentOf(model), message.id).nodes,\n ).length\n return {\n model,\n commands: mint(count, { _tag: 'Duplicate', id: message.id, at: message.at }),\n }\n }\n case 'CopyAsked':\n case 'CutAsked': {\n const node = documentOf(model).nodes[message.id]\n if (node === undefined)\n return refuse(model, {\n code: 'composition:missing-node',\n message: fillWords(words.notANode, { id: message.id }),\n })\n const tree = Composition.takeTree(documentOf(model), message.id)\n const copied = { ...model, clipboard: Option.some(tree) }\n if (message._tag === 'CopyAsked')\n return {\n model: copied,\n commands: copy(\n tree,\n fillWords(words.copied, { label: blockLabel(catalog, node.block) }),\n ),\n }\n const cut = applyOp(copied, Composition.Op.remove(message.id))\n // A node its Region cannot do without is not cut: nothing is copied either.\n return cut.model.page === model.page\n ? { ...cut, model: { ...cut.model, clipboard: model.clipboard } }\n : {\n model: cut.model,\n commands: copy(\n tree,\n fillWords(words.cut, { label: blockLabel(catalog, node.block) }),\n ),\n }\n }\n case 'PasteAsked':\n return {\n model,\n commands: [\n {\n name: `${name}.paste`,\n effect: Effect.map(readText().effect, read =>\n Message.ClipboardRead({\n text: read._tag === 'Read' ? Option.some(read.text) : Option.none(),\n }),\n ),\n },\n ],\n }\n case 'ClipboardRead': {\n // Text read wins, so a copy made in another tab pastes here; the\n // Builder's own copy is for a browser that would not let it be read.\n const tree = Option.match(message.text, {\n onNone: () => model.clipboard,\n onSome: text => Option.map(Result.getSuccess(clipOf(text)), ({ tree }) => tree),\n })\n if (Option.isNone(tree))\n return refuse(model, {\n code: 'builder:nothing-to-paste',\n message: Option.isSome(message.text) ? words.notAPage : words.nothingCopied,\n })\n // Checked by its own ids, before new ones are minted, so a refusal names what was copied.\n const wrong = Composition.treeRefusal(catalog, tree.value)\n if (Option.isSome(wrong))\n return refuse(model, {\n ...wrong.value,\n message: fillWords(words.refusal, {\n code: wrong.value.code,\n message: wrong.value.message,\n }),\n })\n // `treeRefusal` found the root and its Block, so only a full page leaves no place.\n const block = tree.value.nodes[tree.value.root]?.block ?? ''\n const place = placeFor(catalog, documentOf(model), model.selected, block)\n if (Option.isNone(place))\n return refuse(model, {\n code: 'builder:no-place',\n message: fillWords(words.noPlace, { label: blockLabel(catalog, block) }),\n })\n const at = place.value\n return {\n model,\n commands: mint(Object.keys(tree.value.nodes).length, {\n _tag: 'Paste',\n tree: tree.value,\n at,\n }),\n }\n }\n case 'PatternAsked':\n return Option.match(Catalog.pattern(catalog, message.pattern), {\n onNone: () =>\n refuse(model, {\n code: 'composition:unknown-pattern',\n message: fillWords(words.unknownPattern, { name: message.pattern }),\n }),\n onSome: pattern => ({\n model,\n commands: mint(Object.keys(pattern.tree.nodes).length, {\n _tag: 'Pattern',\n pattern: message.pattern,\n at: message.at,\n }),\n }),\n })\n case 'EditingAsked':\n // A second ask for the field being edited, a double-click inside it, begins nothing.\n if (Option.isSome(editingOf(model, message.field))) return { model }\n return Option.match(fieldOf(message.field), {\n onNone: () => ({ model }),\n onSome: ({ id, key }) => {\n const stored = documentOf(model).nodes[id]?.props[key]\n // Only text the page draws as a field, so what is edited is what shows.\n if (\n typeof stored !== 'string' ||\n !Renderer.fields(renderer, documentOf(model), id).includes(key)\n )\n return { model }\n return {\n model: {\n ...model,\n editing: Option.some({ id, key, initial: stored, typed: false }),\n selected: Option.some(id),\n // Its steps are one, apart from any edit of the same prop before.\n page: History.close(model.page),\n },\n }\n },\n })\n case 'FieldTyped':\n return Option.match(editingOf(model, message.field), {\n onNone: () => ({ model }),\n onSome: editing =>\n applyOp(\n { ...model, editing: Option.some({ ...editing, typed: true }) },\n Composition.Op.setProp(editing.id, editing.key, message.text),\n editingGroup(editing),\n ),\n })\n case 'EditingCommitted':\n case 'EditingCancelled':\n return Option.match(editingOf(model, message.field), {\n onNone: () => ({ model }),\n onSome: editing => {\n const kept = message._tag === 'EditingCommitted' ? message.text : editing.initial\n // Nothing typed and nothing new: the field only showed the text, so another\n // edit that came between is not overwritten with what it showed.\n if (!editing.typed && kept === editing.initial)\n return { model: { ...model, editing: Option.none() } }\n const group = editingGroup(editing)\n // Back where it began, the session's step is taken back, while it is still the last.\n const page = kept === editing.initial ? History.revert(model.page, group) : model.page\n const ended = { ...model, page, editing: Option.none() }\n // Written only where the page does not hold it yet, so no step is empty; and\n // written where another edit came between, so Escape still puts the text back.\n return documentOf(ended).nodes[editing.id]?.props[editing.key] === kept\n ? { model: ended }\n : applyOp(ended, Composition.Op.setProp(editing.id, editing.key, kept), group)\n },\n })\n case 'Minted': {\n const { request, ids } = message\n switch (request._tag) {\n case 'Insert': {\n const props = startingProps(request.block)\n if (ids[0] === undefined || Option.isNone(props))\n return refuse(model, {\n code: 'composition:invalid-props',\n message: fillWords(words.startingPropsFail, { block: request.block }),\n })\n return applyOp(\n model,\n Composition.Op.insert({\n id: ids[0],\n block: request.block,\n props: props.value,\n at: request.at,\n }),\n )\n }\n case 'Pattern': {\n // Asked for by name, so it is the Catalog's still: its ids, in its order.\n const held = Option.match(Catalog.pattern(catalog, request.pattern), {\n onNone: () => [],\n onSome: pattern => Object.keys(pattern.tree.nodes),\n })\n return applyOp(\n model,\n Composition.Op.usePattern({\n pattern: request.pattern,\n ids: Object.fromEntries(held.map((id, at) => [id, ids[at]!])),\n at: request.at,\n }),\n )\n }\n case 'Paste': {\n // Its own ids are kept out of the page: each node gets a new one.\n const renamed = Composition.rekey(\n request.tree,\n Object.fromEntries(Object.keys(request.tree.nodes).map((id, at) => [id, ids[at]!])),\n )\n return applyOp(model, Composition.Op.insertTree({ tree: renamed, at: request.at }))\n }\n case 'Duplicate': {\n if (documentOf(model).nodes[request.id] === undefined)\n return refuse(model, {\n code: 'composition:missing-node',\n message: fillWords(words.notANode, { id: request.id }),\n })\n const held = Object.keys(Composition.takeTree(documentOf(model), request.id).nodes)\n if (held.length !== ids.length)\n return refuse(model, {\n code: 'composition:malformed-tree',\n message: fillWords(words.copyChanged, { id: request.id }),\n })\n return applyOp(\n model,\n Composition.Op.duplicate({\n id: request.id,\n ids: Object.fromEntries(held.map((id, at) => [id, ids[at]!])),\n at: request.at,\n }),\n )\n }\n }\n }\n case 'Undid':\n case 'Redid': {\n const page = (message._tag === 'Undid' ? History.undo : History.redo)(model.page)\n if (page === model.page) return { model }\n return {\n model: {\n ...model,\n page,\n selected: keptIn(page.present, model.selected),\n refused: Option.none(),\n // The page changed under the field being edited: it is drawn from the page again.\n editing: Option.none(),\n },\n commands: announce(message._tag === 'Undid' ? words.undone : words.redone),\n }\n }\n case 'DragStarted':\n // A node gone, or a Block with nothing to start from, starts no drag.\n return Option.isNone(draggedOf(documentOf(model), message.source))\n ? { model }\n : {\n model: {\n ...model,\n drag: Option.some({\n source: message.source,\n over: Option.none(),\n at: Option.none(),\n }),\n // A node dragged is the one worked on; a new one is selected once it is added.\n selected:\n message.source._tag === 'Existing'\n ? Option.some(message.source.id)\n : model.selected,\n },\n }\n case 'DraggedOver':\n return draggedOver(model, message.id, message.zone, Option.none())\n case 'DraggedOverRegion':\n return draggedOver(model, message.id, 'inside', Option.some(message.region))\n case 'DraggedOverPage': {\n if (Option.isNone(model.drag)) return { model }\n const drag = model.drag.value\n return {\n model: {\n ...model,\n drag: Option.some({\n ...drag,\n over: Option.none(),\n at: onPage(documentOf(model), drag.source),\n }),\n },\n }\n }\n case 'DraggedOff':\n return Option.isNone(model.drag)\n ? { model }\n : {\n model: {\n ...model,\n drag: Option.some({\n ...model.drag.value,\n over: Option.none(),\n at: Option.none(),\n }),\n },\n }\n case 'DragDropped': {\n if (Option.isNone(model.drag)) return { model }\n const { source, over, at } = model.drag.value\n const ended = { ...model, drag: Option.none() }\n // Worked out again: the page may have changed since the pointer got here.\n // Over no node with a place is over the page's own space.\n const landed = Option.match(over, {\n onNone: () =>\n Option.isSome(at)\n ? Option.map(onPage(documentOf(model), source), place => ({ at: place }))\n : Option.none(),\n onSome: target =>\n Option.flatMap(draggedOf(documentOf(model), source), dragged =>\n landing(catalog, documentOf(model), dragged, target.id, target.zone, target.region),\n ),\n })\n return Option.match(landed, {\n onNone: () => ({ model: ended, commands: announce(unmoved(source)) }),\n onSome: ({ at }) =>\n source._tag === 'Existing'\n ? applyOp(ended, Composition.Op.move(source.id, at))\n : // A new node needs an id: the same request a press on the palette makes.\n { model: ended, commands: mint(1, { _tag: 'Insert', block: source.block, at }) },\n })\n }\n case 'DragCancelled':\n return Option.isNone(model.drag)\n ? { model }\n : {\n model: { ...model, drag: Option.none() },\n commands: announce(unmoved(model.drag.value.source)),\n }\n case 'PreviewChosen':\n return {\n model: { ...model, preview: { ...model.preview, [message.key]: message.value } },\n }\n case 'PreviewCleared': {\n const { [message.key]: _, ...others } = model.preview\n return { model: { ...model, preview: others } }\n }\n case 'Inspected':\n return inspect(model, message)\n case 'PanelChosen':\n return { model: { ...model, panel: message.panel } }\n case 'ViewportChosen':\n return { model: { ...model, viewport: message.viewport } }\n // The placements' own: the layers and the announcer update themselves.\n case 'GotLayersMessage':\n case 'GotAnnouncerMessage':\n return { model }\n }\n }\n\n const assembled = placements.update(own)\n /**\n * Editing in place kept only while its node is the one selected: another\n * selected, or the node removed (which deselects it), ends it.\n */\n const stillEditing = (model: Model): Model =>\n Option.isSome(model.editing) && !Option.contains(model.selected, model.editing.value.id)\n ? { ...model, editing: Option.none() }\n : model\n /**\n * The layers' keys, once the node they were on is removed and nothing is\n * selected, start from where it was: its next sibling left, else the one\n * before, else the nearest holder left; not the first row.\n */\n const keptCurrent = <R extends { readonly model: Model }>(before: Model, next: R): R => {\n const { current } = next.model.layers\n const after = documentOf(next.model)\n if (current === null || Composition.index(after).has(NodeId.make(current))) return next\n const was = documentOf(before)\n const place = Composition.index(was).get(NodeId.make(current))\n if (place === undefined) return next\n const left = (id: NodeId) => Composition.index(after).has(id)\n const siblings =\n place.parent === undefined\n ? was.roots\n : (was.nodes[place.parent]?.regions[place.region ?? ''] ?? [])\n const beside = [\n ...siblings.slice(place.index + 1),\n ...siblings.slice(0, place.index).reverse(),\n ].find(left)\n let holder = place.parent\n while (holder !== undefined && !left(holder))\n holder = Composition.index(was).get(holder)?.parent\n const kept = beside ?? holder ?? null\n return { ...next, model: { ...next.model, layers: { ...next.model.layers, current: kept } } }\n }\n const update = (model: Model, message: Message) => {\n const moved = assembled(model, message)\n const next = {\n ...moved,\n model: stillEditing(\n message._tag === 'Inspected' ? moved.model : reconciled(model, moved.model),\n ),\n }\n // Moving focus in the layers moves the selection with it.\n if (message._tag === Layers.wrapper.tag && message.message._tag === 'Focused') {\n const id = NodeId.make(message.message.id)\n return documentOf(next.model).nodes[id] === undefined\n ? next\n : { ...next, model: { ...next.model, selected: Option.some(id) } }\n }\n // A selection made elsewhere (an insert, the canvas, a row click) is where\n // the layers' keys start from, with the rows above it open so it shows.\n if (Option.isNone(next.model.selected)) return keptCurrent(model, next)\n const selected = next.model.selected.value\n if (selected === next.model.layers.current) return next\n const places = Composition.index(documentOf(next.model))\n const above = new Set<string>()\n for (let at = places.get(selected)?.parent; at !== undefined; at = places.get(at)?.parent)\n above.add(at)\n const { layers } = next.model\n return {\n ...next,\n model: {\n ...next.model,\n layers: {\n ...layers,\n current: selected,\n // Rows start open, so a closed one is one toggled: opening it untoggles it.\n toggled: layersArgs.openByDefault\n ? layers.toggled.filter(id => !above.has(id))\n : [...new Set([...layers.toggled, ...above])],\n },\n },\n }\n }\n\n const view = Submodel.defineView<Model, Message>((model, h) => drawBuilder(model, h))\n\n /** The crude editor: a palette, the layers, the selected node's text props, and the page. */\n const drawBuilder = (model: Model, h: HtmlBuilder<Message>): Html => {\n // Type `button`: inside a form, a plain button would submit it.\n const button = (label: string, message: Option.Option<Message>) =>\n h.button(\n [\n h.Type('button'),\n h.Disabled(Option.isNone(message)),\n ...Option.match(message, { onNone: () => [], onSome: sent => [h.OnClick(sent)] }),\n ],\n [label],\n )\n const palette = h.nav(\n [h.Class('builder-palette'), h.AriaLabel('Insert')],\n catalog.blocks\n .filter(block => Object.hasOwn(starters, block.name))\n .map(block => {\n return button(\n `Add ${block.name}`,\n Option.map(placeFor(catalog, documentOf(model), model.selected, block.name), at =>\n Message.InsertAsked({ block: block.name, at }),\n ),\n )\n }),\n )\n const layer = (id: NodeId): Html => {\n const node = documentOf(model).nodes[id]\n if (node === undefined) return null\n const known = Catalog.block(catalog, node.block) !== undefined\n const children = Object.values(node.regions).flat()\n return h.li(\n [...(Option.contains(model.selected, id) ? [h.AriaCurrent('true')] : [])],\n [\n button(`${known ? '' : '? '}${node.block}`, Option.some(Message.Selected({ id }))),\n ...(children.length === 0 ? [] : [h.ul([], children.map(layer))]),\n ],\n )\n }\n const layers = h.ul(\n [h.Class('builder-layers'), h.AriaLabel('Layers')],\n documentOf(model).roots.map(layer),\n )\n const actions = Option.match(model.selected, {\n onNone: () => [],\n onSome: selected => [\n h.div(\n [h.Class('builder-actions')],\n [\n button(words.moveUp, applied(moveBy(documentOf(model), selected, -1))),\n button(words.moveDown, applied(moveBy(documentOf(model), selected, 1))),\n button(\n words.duplicate,\n Option.map(after(documentOf(model), selected), at =>\n Message.DuplicateAsked({ id: selected, at }),\n ),\n ),\n button(\n words.delete,\n Option.some(Message.Applied({ op: Composition.Op.remove(selected) })),\n ),\n ],\n ),\n ],\n })\n const inspect = (id: NodeId): Html => {\n const node = documentOf(model).nodes[id]\n if (node === undefined) return null\n const fields = Object.entries(node.props).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string',\n )\n return h.div(\n [h.Class('builder-properties'), h.AriaLabel('Properties')],\n fields.map(([key, value]) =>\n h.label(\n [],\n [\n key,\n h.input([\n h.Value(value),\n h.OnInput(text => Message.Applied({ op: Composition.Op.setProp(id, key, text) })),\n ]),\n ],\n ),\n ),\n )\n }\n const inspector = Option.match(model.selected, {\n onNone: () => [],\n onSome: selected => [inspect(selected)],\n })\n return h.div(\n [h.Class('builder')],\n [\n palette,\n layers,\n ...actions,\n ...inspector,\n h.div(\n [h.Class('builder-history')],\n [\n button(\n words.undo,\n History.canUndo(model.page) ? Option.some(Message.Undid()) : Option.none(),\n ),\n button(\n words.redo,\n History.canRedo(model.page) ? Option.some(Message.Redid()) : Option.none(),\n ),\n ],\n ),\n ...Option.match(model.refused, {\n onNone: () => [],\n onSome: refused => [h.p([h.Role('alert')], [refused.message])],\n }),\n h.div(\n [h.Class('builder-canvas'), h.DataAttribute('viewport', model.viewport)],\n [\n ...Renderer.render(renderer, documentOf(model), inertHtml, {\n mode: 'edit',\n context: model.preview,\n }),\n ],\n ),\n ],\n )\n }\n\n const applied = (op: Option.Option<Operation>): Option.Option<Message> =>\n Option.map(op, found => Message.Applied({ op: found }))\n\n const bundle = Bundle.make(name, {\n Model,\n Message,\n init: () => ({ model: initial }),\n update,\n view,\n })\n\n /** Undo and redo, which need no selection. */\n const history = (model: Pick<Model, 'page'>) => ({\n undo: History.canUndo(model.page) ? Option.some(Message.Undid()) : Option.none(),\n redo: History.canRedo(model.page) ? Option.some(Message.Redid()) : Option.none(),\n })\n /** A command on the selected node, which runs nothing while none is selected. */\n const onSelected =\n (run: (document: Document, selected: NodeId) => Option.Option<Message>) =>\n (model: Pick<Model, 'page' | 'selected'>): Option.Option<Message> =>\n Option.flatMap(model.selected, selected => run(documentOf(model), selected))\n\n const built: ReadonlyArray<BuilderCommand> = [\n {\n id: 'move-up',\n label: words.moveUp,\n keys: [{ key: 'ArrowUp', alt: true }],\n placement: ['node'],\n run: onSelected((document, selected) => applied(moveBy(document, selected, -1))),\n },\n {\n id: 'move-down',\n label: words.moveDown,\n keys: [{ key: 'ArrowDown', alt: true }],\n placement: ['node'],\n run: onSelected((document, selected) => applied(moveBy(document, selected, 1))),\n },\n {\n id: 'move-out',\n label: words.moveOut,\n keys: [{ key: 'ArrowLeft', alt: true }],\n placement: ['node'],\n run: onSelected((document, selected) => applied(outdent(document, selected))),\n },\n {\n id: 'move-in',\n label: words.moveIn,\n keys: [{ key: 'ArrowRight', alt: true }],\n placement: ['node'],\n run: onSelected((document, selected) => applied(indent(catalog, document, selected))),\n },\n {\n id: 'duplicate',\n label: words.duplicate,\n keys: [{ key: 'd', mod: true }],\n placement: ['node'],\n // Offered only where its Region has room for the copy.\n run: onSelected((document, selected) =>\n Option.map(\n Option.filter(after(document, selected), at => hasRoom(catalog, document, at)),\n at => Message.DuplicateAsked({ id: selected, at }),\n ),\n ),\n },\n {\n id: 'copy',\n label: words.copy,\n keys: [{ key: 'c', mod: true }],\n placement: ['node'],\n run: onSelected((_, selected) => Option.some(Message.CopyAsked({ id: selected }))),\n },\n {\n id: 'cut',\n label: words.cutCommand,\n keys: [{ key: 'x', mod: true }],\n placement: ['node'],\n run: onSelected((_, selected) => Option.some(Message.CutAsked({ id: selected }))),\n },\n {\n id: 'delete',\n label: words.delete,\n keys: [{ key: 'Delete' }, { key: 'Backspace' }],\n placement: ['node'],\n run: onSelected((_, selected) =>\n Option.some(Message.Applied({ op: Composition.Op.remove(selected) })),\n ),\n },\n {\n id: 'undo',\n label: words.undo,\n keys: [{ key: 'z', mod: true, shift: false }],\n placement: ['toolbar'],\n run: model => history(model).undo,\n },\n {\n id: 'redo',\n label: words.redo,\n keys: [\n { key: 'z', mod: true, shift: true },\n { key: 'y', mod: true },\n ],\n placement: ['toolbar'],\n run: model => history(model).redo,\n },\n {\n id: 'paste',\n label: words.paste,\n keys: [{ key: 'v', mod: true }],\n placement: ['toolbar'],\n run: () => Option.some(Message.PasteAsked()),\n },\n {\n id: 'edit-text',\n label: words.editText,\n keys: [{ key: 'Enter' }],\n placement: ['keyboard'],\n // The first text the node draws as a field; none for a node that draws none.\n run: onSelected((document, selected) =>\n Option.map(\n Option.fromUndefinedOr(Renderer.fields(renderer, document, selected)[0]),\n key => Message.EditingAsked({ field: fieldName(selected, key) }),\n ),\n ),\n },\n {\n id: 'deselect',\n label: words.deselect,\n keys: [{ key: 'Escape' }],\n placement: ['keyboard'],\n run: onSelected(() => Option.some(Message.Deselected())),\n },\n ]\n const commands = config.commands === undefined ? built : config.commands(built)\n\n /**\n * The Message a key sends, for the layers panel and the canvas: the first\n * command one of whose keys it is, and whose run has one. None for a key\n * no command takes, or one whose command has nothing to do, and none at\n * all while text is edited in place: its keys are the text's.\n */\n const keyCommand = (\n model: Pick<Model, 'page' | 'selected' | 'editing'>,\n key: string,\n modifiers: KeyboardModifiers,\n ): Option.Option<Message> => {\n if (Option.isSome(model.editing)) return Option.none()\n for (const command of commands) {\n if (!command.keys.some(spec => pressed(spec, key, modifiers))) continue\n const sent = command.run(model)\n if (Option.isSome(sent)) return sent\n }\n return Option.none()\n }\n\n /**\n * What a key press on the layers or the canvas sends, for the view: a\n * `KeyPressed` for any key a command binds, so its default is held back\n * and `update` decides with the Model as it is; nothing for another key,\n * or while text is edited in place, where the key is the text's.\n */\n const keyPressed = (\n model: Pick<Model, 'editing'>,\n key: string,\n modifiers: KeyboardModifiers,\n ): Option.Option<Message> =>\n Option.isNone(model.editing) &&\n commands.some(command => command.keys.some(spec => pressed(spec, key, modifiers)))\n ? Option.some(Message.KeyPressed({ key, modifiers }))\n : Option.none()\n\n /** The form control that places this Builder as a key, drawn by `drawn`. */\n const inputWith = <ViewInputs>(drawn: Submodel.View<Model, Message, ViewInputs>) =>\n Input.bundle('Composition', {\n bundle: bundle.pipe(Bundle.withView(drawn)),\n value: documentOf,\n fill: replace,\n settled: settle,\n })\n\n return {\n name,\n catalog,\n renderer,\n bundle,\n initial,\n /** The form control that places this Builder as a key: its value is the Document. */\n input: inputWith(view),\n /**\n * The same control, drawn by another view, such as\n * `BuilderView.submodel(view)` from `foldkit-mixins-builder`.\n */\n inputWith,\n /** Where a new node of a Block goes, given the selection; none where it may not go. */\n placeFor: (document: Document, selected: Option.Option<NodeId>, block: Blocks['name']) =>\n placeFor(catalog, document, selected, block),\n /** Where a pattern goes, as a new node of its root's Block would; none where it may not. */\n patternAt: (document: Document, selected: Option.Option<NodeId>, pattern: string) =>\n Option.flatMap(Catalog.pattern(catalog, pattern), found =>\n Option.flatMap(Option.fromUndefinedOr(found.tree.nodes[found.tree.root]), root =>\n placeFor(catalog, document, selected, root.block),\n ),\n ),\n moveBy,\n /** Where what is dragged over `target`, in `zone`, would go; none where it may not. */\n dropAt: (document: Document, dragged: DragSource, target: NodeId, zone: DropZone) =>\n Option.map(\n Option.flatMap(draggedOf(document, dragged), each =>\n landing(catalog, document, each, target, zone),\n ),\n ({ at }) => at,\n ),\n replace,\n settle,\n /** The editor's commands: what a key, a node's action or the toolbar runs. */\n commands,\n keyCommand,\n keyPressed,\n /**\n * The selected node's settings form and its Model, for the inspector to\n * draw: the Model it holds for the node, else one filled from the props.\n */\n inspecting,\n /** The Blocks a new node may be, in the Catalog's order: those with starting props. */\n offered: catalog.blocks\n .filter(block => Object.hasOwn(starters, block.name))\n .map(block => block.name),\n /** The Document a Builder Model is editing: its history's present. */\n document: documentOf,\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,cAAc,SAAS,IAAuC,4BAA4B;CAE9F,QAAO,YAAW,CAAC,OAAO,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC;CAChD,YAAW,WACT,OAA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