@quillmark/svelte 0.31.0 → 0.33.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.
Files changed (69) hide show
  1. package/README.md +3 -3
  2. package/dist/core/address.d.ts +1 -1
  3. package/dist/core/address.js +1 -1
  4. package/dist/core/codec/atoms.js +1 -1
  5. package/dist/core/codec/breaks.js +3 -2
  6. package/dist/core/codec/decode.d.ts +1 -1
  7. package/dist/core/codec/decode.js +2 -2
  8. package/dist/core/codec/encode.d.ts +2 -1
  9. package/dist/core/codec/encode.js +2 -1
  10. package/dist/core/codec/field.d.ts +3 -3
  11. package/dist/core/codec/field.js +77 -21
  12. package/dist/core/codec/index.d.ts +2 -0
  13. package/dist/core/codec/index.js +5 -1
  14. package/dist/core/codec/inputrules.js +3 -3
  15. package/dist/core/codec/islands.d.ts +1 -1
  16. package/dist/core/codec/islands.js +3 -3
  17. package/dist/core/codec/keymap.d.ts +1 -1
  18. package/dist/core/codec/keymap.js +3 -2
  19. package/dist/core/codec/list-move.js +2 -1
  20. package/dist/core/codec/list-paste.js +1 -1
  21. package/dist/core/codec/lists.d.ts +1 -1
  22. package/dist/core/codec/lists.js +7 -6
  23. package/dist/core/codec/markdown-paste.js +2 -2
  24. package/dist/core/codec/prose.css +3 -3
  25. package/dist/core/codec/schema.d.ts +1 -1
  26. package/dist/core/codec/schema.js +3 -3
  27. package/dist/core/codec/shortcuts.d.ts +91 -0
  28. package/dist/core/codec/shortcuts.js +135 -0
  29. package/dist/core/codec/table-paste.js +1 -1
  30. package/dist/core/codec/table-view.d.ts +1 -1
  31. package/dist/core/codec/table-view.js +27 -37
  32. package/dist/core/codec/tasks.js +1 -1
  33. package/dist/core/theme.css +2 -2
  34. package/dist/preset/scale.css +1 -1
  35. package/dist/preview/Preview.svelte +2 -3
  36. package/dist/preview/bridge.js +2 -2
  37. package/dist/preview/geometry.d.ts +2 -2
  38. package/dist/preview/geometry.js +2 -2
  39. package/dist/preview/paint.js +1 -1
  40. package/dist/visual/ArrayField.svelte +5 -5
  41. package/dist/visual/BooleanField.svelte +1 -1
  42. package/dist/visual/Card.svelte +4 -4
  43. package/dist/visual/CardControls.svelte +1 -1
  44. package/dist/visual/DateField.svelte +1 -1
  45. package/dist/visual/DiagnosticList.svelte +1 -1
  46. package/dist/visual/EnumField.svelte +1 -1
  47. package/dist/visual/Field.svelte +3 -3
  48. package/dist/visual/FormatPopover.svelte +9 -3
  49. package/dist/visual/MatrixAdd.svelte +1 -1
  50. package/dist/visual/MatrixField.svelte +1 -1
  51. package/dist/visual/NumberField.svelte +2 -3
  52. package/dist/visual/ObjectField.svelte +2 -2
  53. package/dist/visual/ProseField.svelte +2 -2
  54. package/dist/visual/TextField.svelte +1 -1
  55. package/dist/visual/VariantField.svelte +1 -1
  56. package/dist/visual/VisualEditorInner.svelte +15 -15
  57. package/dist/visual/controls.css +2 -2
  58. package/dist/visual/diagnostics.d.ts +2 -2
  59. package/dist/visual/diagnostics.js +2 -2
  60. package/dist/visual/index.d.ts +2 -0
  61. package/dist/visual/index.js +3 -0
  62. package/dist/visual/leaves.js +1 -1
  63. package/dist/visual/props.d.ts +2 -2
  64. package/dist/visual/strings.d.ts +6 -5
  65. package/dist/visual/strings.js +2 -1
  66. package/dist/visual/structure.d.ts +10 -9
  67. package/dist/visual/structure.js +13 -12
  68. package/dist/visual/tips.js +1 -1
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -46,7 +46,7 @@ const session = await new Engine().open(quill, doc);
46
46
  // free() on teardown the handles you MINTED: this quill, this doc, this session.
47
47
  ```
48
48
 
49
- `<VisualEditor>` needs no session, and the first `open` loads the render build, so a host that mounts the editor over `doc` and `quill` first shows it without waiting on that load. The session opens behind it: `await engine.load(quill)`, then `engine.open(quill, doc)`, so its first compile reads what was typed meanwhile ([HOSTING.md](prose/canon/HOSTING.md)).
49
+ `<VisualEditor>` needs no session, and the first `open` loads the render build, so a host that mounts the editor over `doc` and `quill` first shows it without waiting on that load. The session opens behind it: `await engine.load(quill)`, then `engine.open(quill, doc)`, so its first compile reads what was typed meanwhile ([INVARIANTS.md](prose/INVARIANTS.md#hosting)).
50
50
 
51
51
  ## The quill resolves from the document
52
52
 
@@ -164,7 +164,7 @@ The package ships English and a seam to replace it. `strings` is keyed and **par
164
164
  />
165
165
  ```
166
166
 
167
- `formatDiagnostic` gets the whole `Diagnostic` and returns `undefined` to take its own message. Validation and edit diagnostics re-word from `code`, `path` and `args`; parse errors and render warnings carry their detail inside English text and stand as they are ([VISUAL_EDITOR.md](prose/canon/VISUAL_EDITOR.md)).
167
+ `formatDiagnostic` gets the whole `Diagnostic` and returns `undefined` to take its own message. Validation and edit diagnostics re-word from `code`, `path` and `args`; parse errors and render warnings carry their detail inside English text and stand as they are ([INVARIANTS.md](prose/INVARIANTS.md#diagnostics)).
168
168
 
169
169
  ### Fonts
170
170
 
@@ -265,7 +265,7 @@ The surfaces carry the behavior against a neutral, overridable visual baseline:
265
265
 
266
266
  ## Development
267
267
 
268
- This package is one workspace of [`quillmark-js`](../..); the gates are the root's, and the settled architecture lives in [`prose/`](prose/).
268
+ This package is one workspace of [`quillmark-js`](../..); the gates are the root's, and the rules a change must keep live in [`prose/INVARIANTS.md`](prose/INVARIANTS.md).
269
269
 
270
270
  ```sh
271
271
  npm run build -w packages/svelte # svelte-package → dist/
@@ -63,7 +63,7 @@ export declare function addrForFieldPath(path: DocPath): Addr | undefined;
63
63
  * The nearest ancestor a commit address can name: {@link addrForFieldPath} where the path has one,
64
64
  * else the root and its first field (`main.contact.email` and `main.keywords[0]` land on their
65
65
  * field). `undefined` for a field-rooted (config-space) or malformed path. An `Addr` reaches a root
66
- * and one field, so the truncation is a consumer's to make (VISUAL_EDITOR §Diagnostics).
66
+ * and one field, so the truncation is a consumer's to make (INVARIANTS §Diagnostics).
67
67
  */
68
68
  export declare function nearestAddrForFieldPath(path: DocPath): Addr | undefined;
69
69
  /**
@@ -51,7 +51,7 @@ export function addrForFieldPath(path) {
51
51
  * The nearest ancestor a commit address can name: {@link addrForFieldPath} where the path has one,
52
52
  * else the root and its first field (`main.contact.email` and `main.keywords[0]` land on their
53
53
  * field). `undefined` for a field-rooted (config-space) or malformed path. An `Addr` reaches a root
54
- * and one field, so the truncation is a consumer's to make (VISUAL_EDITOR §Diagnostics).
54
+ * and one field, so the truncation is a consumer's to make (INVARIANTS §Diagnostics).
55
55
  */
56
56
  export function nearestAddrForFieldPath(path) {
57
57
  const segs = segsOf(path);
@@ -4,7 +4,7 @@
4
4
  // delete against one edits nothing (§`againstAtom`).
5
5
  //
6
6
  // This is the neighbour half of the rule the leaf already holds for a key typed over a
7
- // selection (CODEC §"The table island"): a selection is the subject of the next
7
+ // selection (INVARIANTS §"The table island"): a selection is the subject of the next
8
8
  // command, never a thing armed for replacement. Without it the base keymap's
9
9
  // `joinBackward` / `joinForward` reach their "the neighbour is an atom, delete it" arm
10
10
  // and a table goes in one keystroke, from the paragraph a table insert parks the caret
@@ -1,5 +1,6 @@
1
1
  import { Plugin, TextSelection } from 'prosemirror-state';
2
2
  import { takesLineBreak } from './schema.js';
3
+ import { BODY_KEYS } from './shortcuts.js';
3
4
  /**
4
5
  * Rewrite every `\n` a transaction leaves in a non-`code` textblock: to a `hard_break`
5
6
  * where the block takes one, to a space where it does not.
@@ -60,7 +61,7 @@ export function linebreakPlugin(schema) {
60
61
  *
61
62
  * The break takes no marks and the caret keeps them: `decode` mints an unmarked break,
62
63
  * so an inherited mark would leave the leaf holding a shape a re-hydrate swaps out
63
- * (CODEC §Encode, one spelling of each shape), while dropping the marks from the
64
+ * (INVARIANTS §Encode, one spelling of each shape), while dropping the marks from the
64
65
  * *caret* would end a bold run at a line break the author only meant to wrap at.
65
66
  */
66
67
  function insertBreak(schema) {
@@ -90,5 +91,5 @@ function insertBreak(schema) {
90
91
  export function breakKeymap(schema) {
91
92
  if (!schema.nodes.hard_break)
92
93
  return {};
93
- return { 'Shift-Enter': insertBreak(schema) };
94
+ return { [BODY_KEYS.lineBreak]: insertBreak(schema) };
94
95
  }
@@ -19,7 +19,7 @@ export declare function decode(rt: Content, schema: Schema): PMNode;
19
19
  export declare function fitsInline(rt: Content): boolean;
20
20
  /**
21
21
  * Whether `rt` decodes under `plainSchema` losing nothing but its marks, which the next commit
22
- * heals (CODEC §Inline mode): upstream's `isPlain` with marks set aside.
22
+ * heals (INVARIANTS §"Inline mode"): upstream's `isPlain` with marks set aside.
23
23
  */
24
24
  export declare function fitsPlain(rt: Content): boolean;
25
25
  /**
@@ -1,4 +1,4 @@
1
- // Decode: content → PM, a pure function (CODEC §Decode). Each `\n`-separated segment is one
1
+ // Decode: content → PM, a pure function (INVARIANTS §Decode). Each `\n`-separated segment is one
2
2
  // block, its record's `kind` selecting the node; blocks nest by the containers their paths name,
3
3
  // a run of blocks sharing a container id being that container; a `U+2028` is a break inside a
4
4
  // block; marks apply over their `[start,end)` ranges; island slots lower to leaf nodes. Anchors are
@@ -69,7 +69,7 @@ export function fitsInline(rt) {
69
69
  }
70
70
  /**
71
71
  * Whether `rt` decodes under `plainSchema` losing nothing but its marks, which the next commit
72
- * heals (CODEC §Inline mode): upstream's `isPlain` with marks set aside.
72
+ * heals (INVARIANTS §"Inline mode"): upstream's `isPlain` with marks set aside.
73
73
  */
74
74
  export function fitsPlain(rt) {
75
75
  return core().isPlain({ ...rt, marks: [] });
@@ -37,6 +37,7 @@ export declare function scanContent(s: Scan, anchors?: ContentAnchor[]): Content
37
37
  export declare function pmToContent(doc: PMNode, anchors?: ContentAnchor[]): Content;
38
38
  /**
39
39
  * The change taking `oldRt` to `newRt`, or `null` where the two are one value: the store's own
40
- * `diff`, so what lands is the projection, ids and anchors and all.
40
+ * `diff`, carrying the projection's ids and anchors; a commit swaps the block ids the store does
41
+ * not hold for placeholders (`field.ts`).
41
42
  */
42
43
  export declare function lower(oldRt: Content, newRt: Content): Change | null;
@@ -228,7 +228,8 @@ function mergeMarks(raw) {
228
228
  // ── Lowering ────────────────────────────────────────────────────────────────
229
229
  /**
230
230
  * The change taking `oldRt` to `newRt`, or `null` where the two are one value: the store's own
231
- * `diff`, so what lands is the projection, ids and anchors and all.
231
+ * `diff`, carrying the projection's ids and anchors; a commit swaps the block ids the store does
232
+ * not hold for placeholders (`field.ts`).
232
233
  */
233
234
  export function lower(oldRt, newRt) {
234
235
  const change = core().diff(oldRt, newRt);
@@ -29,7 +29,7 @@ export interface CreateFieldOpts {
29
29
  * Fired when the leaf holds or releases, and at mount when it mounts held. A one-line or `text`
30
30
  * leaf is held over a value its schema cannot hold (`fitsLeaf`): the decode would join lines
31
31
  * and drop containers and islands. Any leaf is held over what is read and not edited: a font
32
- * family, a footnote, an equation (CODEC §Decode). A held leaf draws on the block schema,
32
+ * family, a footnote, an equation (INVARIANTS §Decode). A held leaf draws on the block schema,
33
33
  * read-only, and commits nothing. Judged on each mount and re-hydrate ({@link
34
34
  * FieldController.applyExternal}).
35
35
  */
@@ -93,7 +93,7 @@ export interface CreateFieldOpts {
93
93
  /** Recovered failures on the commit path ({@link EditorErrorHandler}). */
94
94
  onError?: EditorErrorHandler;
95
95
  }
96
- /** The prose-leaf handle (VISUAL_EDITOR §Surface). */
96
+ /** The prose-leaf handle (INVARIANTS §Surface). */
97
97
  export interface FieldController {
98
98
  /** The mounted `container`: the leaf's element, for a caller that has to reach the
99
99
  * DOM the view sits in (the arrival wash, `core/bloom.ts`) rather than re-find it. */
@@ -180,7 +180,7 @@ export declare function heldAttributes(opts: {
180
180
  }, noteId: string | undefined): Record<string, string>;
181
181
  export declare function createField(opts: CreateFieldOpts): FieldController;
182
182
  /**
183
- * The prose-leaf plugin stack (VISUAL_EDITOR §Surface), shared by {@link createField} and
183
+ * The prose-leaf plugin stack (INVARIANTS §Surface), shared by {@link createField} and
184
184
  * `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
185
185
  * plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
186
186
  * linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
@@ -1,4 +1,4 @@
1
- // The prose leaf: `createField` (VISUAL_EDITOR §Surface). One content field, one PM view wired to
1
+ // The prose leaf: `createField` (INVARIANTS §Surface). One content field, one PM view wired to
2
2
  // the WASM edit surface.
3
3
  //
4
4
  // `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (or
@@ -7,7 +7,7 @@
7
7
  // committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through `onError`.
8
8
  // An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
9
9
  // hold it re-evaluates flips.
10
- import { baseKeymap, toggleMark } from 'prosemirror-commands';
10
+ import { baseKeymap } from 'prosemirror-commands';
11
11
  import { gapCursor } from 'prosemirror-gapcursor';
12
12
  import { history, isHistoryTransaction, redo, undo } from 'prosemirror-history';
13
13
  import { keymap } from 'prosemirror-keymap';
@@ -27,6 +27,7 @@ import { contentEqual, createReconciler } from './reconcile.js';
27
27
  import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
28
28
  import { linebreakPlugin } from './breaks.js';
29
29
  import { bodyKeymap } from './keymap.js';
30
+ import { FIELD_KEYS, markKeymap } from './shortcuts.js';
30
31
  import { remoteKey } from './remote.js';
31
32
  import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
32
33
  import { linkPastePlugin } from './link-paste.js';
@@ -48,7 +49,8 @@ const GHOSTS = 100;
48
49
  * AnchorEdit} meta. The store's rule, so the commit has nothing to reconcile: a range keeps its
49
50
  * edges, text typed at either landing outside it, and a point stays left of text typed at it. A
50
51
  * range whose text is wholly deleted goes, and comes back with its text when history puts the
51
- * deleted slice back ({@link Ghost}); a point never goes.
52
+ * deleted slice back ({@link Ghost}); a point never goes. A range draws as a span carrying
53
+ * `data-qm-anchor`, its id, for a host to style and measure; a point draws nothing.
52
54
  */
53
55
  function anchorPlugin(seed) {
54
56
  return new Plugin({
@@ -73,6 +75,14 @@ function anchorPlugin(seed) {
73
75
  anchors = edit.anchors;
74
76
  return { anchors, ghosts: ghosts.slice(-GHOSTS) };
75
77
  }
78
+ },
79
+ props: {
80
+ decorations: (state) => {
81
+ const ranged = anchorKey.getState(state)?.anchors.filter((a) => a.end > a.start) ?? [];
82
+ return ranged.length
83
+ ? DecorationSet.create(state.doc, ranged.map((a) => Decoration.inline(a.start, a.end, { 'data-qm-anchor': a.id }, { id: a.id })))
84
+ : DecorationSet.empty;
85
+ }
76
86
  }
77
87
  });
78
88
  }
@@ -147,7 +157,7 @@ function toPM(index, a) {
147
157
  return { id: a.id, start: offsetToPM(index, a.start), end: offsetToPM(index, a.end) };
148
158
  }
149
159
  /**
150
- * Read the leaf's `Content` for `addr` through `reader.getContent` (DOCUMENT_MODEL): the body when
160
+ * Read the leaf's `Content` for `addr` through `reader.getContent` (INVARIANTS §"A content field is read through the schema"): the body when
151
161
  * `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
152
162
  * markdown parse left means markdown for `richtext` and literal text for `text`; reading one as the
153
163
  * other eats every `*` the author typed. An absent field (a default-only richtext field before its
@@ -366,8 +376,12 @@ export function createField(opts) {
366
376
  doc.replace(at, newRt);
367
377
  else {
368
378
  const change = lower(oldRt, newRt);
369
- if (change)
379
+ if (change) {
380
+ const asked = askCore(oldRt, change);
370
381
  doc.apply(at, change);
382
+ if (asked.size)
383
+ adopt();
384
+ }
371
385
  }
372
386
  reconciler.commit(readLeaf(reader, addr));
373
387
  return true;
@@ -399,9 +413,60 @@ export function createField(opts) {
399
413
  }
400
414
  }
401
415
  }
416
+ /**
417
+ * Each block id the projection minted for a block the store does not hold, swapped in
418
+ * `change` for a placeholder the write fills, so the store is the one minter of block ids:
419
+ * placeholder → projected id.
420
+ */
421
+ function askCore(oldRt, change) {
422
+ const held = new Set(oldRt.blocks.map((b) => b.id));
423
+ const asked = new Map();
424
+ const named = new Map();
425
+ for (const step of change.steps) {
426
+ if (!('splice' in step))
427
+ continue;
428
+ for (const b of step.splice.blocks ?? []) {
429
+ if (held.has(b.id))
430
+ continue;
431
+ const p = `?${asked.size}`;
432
+ asked.set(p, b.id);
433
+ named.set(b.id, p);
434
+ b.id = p;
435
+ }
436
+ }
437
+ for (const step of change.steps)
438
+ if ('setBlock' in step && named.has(step.setBlock.id))
439
+ step.setBlock.id = named.get(step.setBlock.id);
440
+ return asked;
441
+ }
442
+ /** Each block node takes the id the store holds for the block it projects to. */
443
+ function adopt() {
444
+ const stored = readLeaf(reader, addr).blocks.map((b) => b.id);
445
+ const nodes = [];
446
+ view.state.doc.descendants((node, pos) => {
447
+ if (node.type.name === 'island_block') {
448
+ nodes.push({ pos, key: 'block', id: node.attrs.block });
449
+ return false;
450
+ }
451
+ if (node.isTextblock || node.type.name === 'horizontal_rule') {
452
+ nodes.push({ pos, key: 'id', id: node.attrs.id });
453
+ return false;
454
+ }
455
+ return true;
456
+ });
457
+ if (nodes.length !== stored.length)
458
+ return;
459
+ const tr = view.state.tr;
460
+ nodes.forEach((n, i) => {
461
+ if (n.id !== stored[i])
462
+ tr.setNodeAttribute(n.pos, n.key, stored[i]);
463
+ });
464
+ if (tr.docChanged)
465
+ view.updateState(view.state.apply(tr.setMeta('addToHistory', false)));
466
+ }
402
467
  /**
403
468
  * A `text` leaf's commit: its whole text through the typed writer, resting the field as that
404
- * literal string (CODEC §Inline mode). The content-object rest form would emit markdown
469
+ * literal string (INVARIANTS §"Inline mode"). The content-object rest form would emit markdown
405
470
  * (escaped `*`, backslash breaks) and read back changed. A refusal lands nothing and has no
406
471
  * fallback; the next edit writes the whole text again.
407
472
  */
@@ -615,7 +680,7 @@ export function createField(opts) {
615
680
  return controller;
616
681
  }
617
682
  /**
618
- * The prose-leaf plugin stack (VISUAL_EDITOR §Surface), shared by {@link createField} and
683
+ * The prose-leaf plugin stack (INVARIANTS §Surface), shared by {@link createField} and
619
684
  * `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
620
685
  * plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
621
686
  * linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
@@ -764,25 +829,16 @@ function ghostPlugin(opts) {
764
829
  * body's structural keys; Enter suppressed inline.
765
830
  *
766
831
  * Tab forks on the leaf's role: a one-line or `text` leaf is a form field, Tab unbound so field
767
- * navigation is open for a shell keymap (VISUAL_EDITOR §Settled and open); a block-schema body
832
+ * navigation is open for a shell keymap (INVARIANTS §Chrome); a block-schema body
768
833
  * takes Tab structurally, a chain each nested surface prepends to (`keymap.ts`).
769
834
  */
770
835
  function editorKeymap(schema, inline, slash) {
771
836
  const map = {
772
- 'Mod-z': undo,
773
- 'Mod-y': redo,
774
- 'Shift-Mod-z': redo
837
+ [FIELD_KEYS.undo]: undo,
838
+ [FIELD_KEYS.redo]: redo,
839
+ [FIELD_KEYS.redoAlt]: redo,
840
+ ...markKeymap(schema)
775
841
  };
776
- if (schema.marks.strong)
777
- map['Mod-b'] = toggleMark(schema.marks.strong);
778
- if (schema.marks.em)
779
- map['Mod-i'] = toggleMark(schema.marks.em);
780
- if (schema.marks.underline)
781
- map['Mod-u'] = toggleMark(schema.marks.underline);
782
- if (schema.marks.strike)
783
- map['Mod-Shift-x'] = toggleMark(schema.marks.strike);
784
- if (schema.marks.code)
785
- map['Mod-e'] = toggleMark(schema.marks.code);
786
842
  if (inline) {
787
843
  // One textblock only: swallow Enter, and Shift-Enter with it (the schema declares no break
788
844
  // node; a declined key is the browser's native `<br>`).
@@ -9,6 +9,8 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
9
9
  export type { TableChromeStrings } from './table-view.js';
10
10
  export { DEFAULT_SLASH_STRINGS } from './slash.js';
11
11
  export type { SlashState, SlashStrings } from './slash.js';
12
+ export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
13
+ export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
12
14
  export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
13
15
  export { rendersHref, storableUrl } from './urls.js';
14
16
  export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
@@ -1,5 +1,5 @@
1
1
  // The codec barrel: the bidirectional bridge between one content field (`Content`)
2
- // and one ProseMirror document (CODEC.md). Decode (content → PM), lower (PM doc → a
2
+ // and one ProseMirror document (INVARIANTS §"The codec"). Decode (content → PM), lower (PM doc → a
3
3
  // `Change` for `apply`), the UTF-16↔PM position map, and the `createField`
4
4
  // prose leaf. Consumed by the VisualEditor and the codec test suite.
5
5
  // ProseMirror's structural base styles and the gap cursor's, then the retint of the
@@ -22,6 +22,10 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
22
22
  // The slash menu: the codec owns the model and the picks, the chrome the words and
23
23
  // the pixels (`visual/SlashMenu.svelte` is the only off-barrel caller).
24
24
  export { DEFAULT_SLASH_STRINGS } from './slash.js';
25
+ // The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
26
+ // the visual tier's `strings` set extends their wording, and the formatting popover binds its
27
+ // link chord from `FIELD_KEYS`.
28
+ export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
25
29
  // Schemas (the decode/encode target; the VisualEditor mounts them). `hasMarks` is
26
30
  // what a mark surface asks before offering itself over a leaf.
27
31
  export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
@@ -9,9 +9,9 @@
9
9
  //
10
10
  // A rule declines only where what it would mint is unrepresentable, or is a shape
11
11
  // another gesture owns — never on how a quill renders it. What a quill typesets is not
12
- // knowable here (a quill this build has not seen is the open-sets case, CODEC §"Open
13
- // sets"), and a construct that arrives through `importMarkdown` must stay authorable or
14
- // a document opens carrying a shape the editor refuses to make. So one rule answers
12
+ // knowable here (a quill this build has not seen is the open-sets case,
13
+ // INVARIANTS §Vocabularies), and a construct that arrives through `importMarkdown` must stay
14
+ // authorable or a document opens carrying a shape the editor refuses to make. So one rule answers
15
15
  // otherwise: `- ` / `1. ` at the head of an existing item retypes the item's list, where
16
16
  // a wrap would nest and Tab owns the nesting. A marker the item already shows, and `a. `,
17
17
  // `(1) `, `(a) ` in a nested item, are taken as typed and change nothing.
@@ -15,7 +15,7 @@ export declare const islandBlockSpec: NodeSpec;
15
15
  export declare const islandInlineSpec: NodeSpec;
16
16
  /**
17
17
  * A PM island node's attributes: the content entry, with `islandType` because `type` on a PM node
18
- * is the node type; its set comes off the entry (DOCUMENT_MODEL §Stability seams).
18
+ * is the node type; its set comes off the entry (INVARIANTS §"The boundary").
19
19
  */
20
20
  export interface IslandNodeAttrs {
21
21
  id: string;
@@ -3,7 +3,7 @@
3
3
  // other type inline. The node carries `id`, `islandType`, `props` and `slots` verbatim, and a block
4
4
  // island the id of the block it fills.
5
5
  //
6
- // `ContentIsland.props` is the typed union at the boundary (DOCUMENT_MODEL §Stability seams), so a
6
+ // `ContentIsland.props` is the typed union at the boundary (INVARIANTS §"The boundary"), so a
7
7
  // discriminant check narrows it; `props` still crosses the DOM as opaque JSON, which
8
8
  // `table.ts` §`tableOfNode` guards.
9
9
  import { Fragment, Slice } from 'prosemirror-model';
@@ -24,7 +24,7 @@ const islandAttrs = {
24
24
  slots: { default: null }
25
25
  };
26
26
  // All three attributes cross the DOM, since a copy and a paste inside one body run the document
27
- // through `toDOM`/`parseDOM` (CODEC §"Markdown at the edges") and an island's tags alone say only
27
+ // through `toDOM`/`parseDOM` (INVARIANTS §"Markdown at the edges") and an island's tags alone say only
28
28
  // `[table]`. `props` crosses as JSON. The names are `data-qm-*`, and the id is required: an island
29
29
  // is a leaf, so a rule reading someone else's tag would swallow that element's whole subtree.
30
30
  /** The DOM an island node writes and reads back, for either spec. */
@@ -160,7 +160,7 @@ export function isTableProps(props) {
160
160
  /**
161
161
  * A minter over one document: the positional `isl-{n}` sequence continued past the highest id the
162
162
  * field holds, so a caller placing several islands keeps one minter. A minted id is part of the
163
- * document's canonical bytes (CODEC §Islands): a counter over the projection in hand, never a UUID
163
+ * document's canonical bytes (INVARIANTS §Islands): a counter over the projection in hand, never a UUID
164
164
  * or clock reading, and never a re-numbering of existing ids.
165
165
  *
166
166
  * Reads the PM doc rather than stored content because that is what the caller holds and the commit
@@ -3,7 +3,7 @@ import type { Command } from 'prosemirror-state';
3
3
  /** A multi-block leaf's structural keys, each link binding only what its schema
4
4
  * declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
5
5
  * the block link and the break link alone. The argument list is the precedence order
6
- * VISUAL_EDITOR §Chrome states, so a new link is one more argument at its place in that
6
+ * INVARIANTS §Chrome, so a new link is one more argument at its place in that
7
7
  * order rather than a nesting to read inside out.
8
8
  *
9
9
  * The slash menu is innermost of the three, and it is conditional rather than
@@ -6,6 +6,7 @@ import { codeKeymap } from './code.js';
6
6
  import { listKeymap } from './lists.js';
7
7
  import { listMoveKeymap } from './list-move.js';
8
8
  import { slashKeymap } from './slash.js';
9
+ import { BODY_KEYS } from './shortcuts.js';
9
10
  /** One chain per key, the maps taken in precedence order: on a key several bind, an
10
11
  * earlier map's command runs first and the next runs only if it declines. A key one
11
12
  * map alone binds is its own. No input is mutated. */
@@ -27,7 +28,7 @@ function exitKeymap(schema) {
27
28
  return {
28
29
  Tab: () => true,
29
30
  'Shift-Tab': () => true,
30
- Escape: (_state, _dispatch, view) => {
31
+ [BODY_KEYS.leave]: (_state, _dispatch, view) => {
31
32
  if (!view)
32
33
  return false;
33
34
  view.dom.blur();
@@ -38,7 +39,7 @@ function exitKeymap(schema) {
38
39
  /** A multi-block leaf's structural keys, each link binding only what its schema
39
40
  * declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
40
41
  * the block link and the break link alone. The argument list is the precedence order
41
- * VISUAL_EDITOR §Chrome states, so a new link is one more argument at its place in that
42
+ * INVARIANTS §Chrome, so a new link is one more argument at its place in that
42
43
  * order rather than a nesting to read inside out.
43
44
  *
44
45
  * The slash menu is innermost of the three, and it is conditional rather than
@@ -1,4 +1,5 @@
1
1
  import { isList } from './list-node.js';
2
+ import { LIST_KEYS } from './shortcuts.js';
2
3
  /** The items the selection stands in, in the innermost list holding all of them, moved
3
4
  * one place up (`-1`) or down (`1`). */
4
5
  function moveItems(dir) {
@@ -26,5 +27,5 @@ function moveItems(dir) {
26
27
  export function listMoveKeymap(schema) {
27
28
  if (!schema.nodes.list_item)
28
29
  return {};
29
- return { 'Alt-ArrowUp': moveItems(-1), 'Alt-ArrowDown': moveItems(1) };
30
+ return { [LIST_KEYS.moveUp]: moveItems(-1), [LIST_KEYS.moveDown]: moveItems(1) };
30
31
  }
@@ -1,4 +1,4 @@
1
- // A pasted list takes the numbering of where it lands (CODEC §"Markdown at the edges").
1
+ // A pasted list takes the numbering of where it lands (INVARIANTS §"Markdown at the edges").
2
2
  // An item's number is its position, so a paste counts where it stands: items pasted into
3
3
  // a list are that list's next items, of its kind and in its count, and items pasted on
4
4
  // the empty line a list was just left by are the same list's. A list pasted on a line of
@@ -5,7 +5,7 @@ import type { Command } from 'prosemirror-state';
5
5
  * no list nodes.
6
6
  *
7
7
  * `Tab` / `Shift-Tab` hold the list link of the body's Tab chain; surfaces owning Tab more locally
8
- * prepend a link in `keymap.ts` (`prose/canon/VISUAL_EDITOR.md` §Chrome). `Tab` sinks an unnumbered
8
+ * prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
9
9
  * line alone into a sub-list, any other line its whole item, and a block right after a list into
10
10
  * the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
11
11
  * `Mod-Enter` ticks the task item around the caret (`toggleTask`).
@@ -21,6 +21,7 @@ import { withinNesting } from './nesting.js';
21
21
  import { toggleList } from './list-toggle.js';
22
22
  import { splitTaskItem, toggleTask } from './tasks.js';
23
23
  import { joinAll, joinLists, touching } from './touching.js';
24
+ import { LIST_KEYS } from './shortcuts.js';
24
25
  /**
25
26
  * The caret's enclosing `list_item` when it sits at the very start of that item's first block,
26
27
  * where both structural keys branch; `null` otherwise.
@@ -473,7 +474,7 @@ function sinkIntoList(itemType) {
473
474
  * no list nodes.
474
475
  *
475
476
  * `Tab` / `Shift-Tab` hold the list link of the body's Tab chain; surfaces owning Tab more locally
476
- * prepend a link in `keymap.ts` (`prose/canon/VISUAL_EDITOR.md` §Chrome). `Tab` sinks an unnumbered
477
+ * prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
477
478
  * line alone into a sub-list, any other line its whole item, and a block right after a list into
478
479
  * the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
479
480
  * `Mod-Enter` ticks the task item around the caret (`toggleTask`).
@@ -497,11 +498,11 @@ export function listKeymap(schema) {
497
498
  return {};
498
499
  const backspace = chainCommands(markerOff(itemType), joinOntoList(itemType));
499
500
  return {
500
- 'Mod-Shift-7': toggleList(true),
501
- 'Mod-Shift-8': toggleList(false),
502
- Tab: chainCommands(sinkLine(itemType), sinkWithin(itemType), sinkIntoList(itemType)),
503
- 'Shift-Tab': outdent(itemType),
504
- 'Mod-Enter': toggleTask(itemType),
501
+ [LIST_KEYS.numbered]: toggleList(true),
502
+ [LIST_KEYS.bulleted]: toggleList(false),
503
+ [LIST_KEYS.indent]: chainCommands(sinkLine(itemType), sinkWithin(itemType), sinkIntoList(itemType)),
504
+ [LIST_KEYS.outdent]: outdent(itemType),
505
+ [LIST_KEYS.task]: toggleTask(itemType),
505
506
  Enter: chainCommands(lineAbove(itemType, paragraph), lineOutOfMiddle(itemType), markerOn(itemType), splitTaskItem(itemType), liftListItem(itemType)),
506
507
  Backspace: chainCommands(deleteAcross, markerOff(itemType), lineOut(itemType), joinOntoList(itemType)),
507
508
  Delete: chainCommands(deleteAcross, deleteBelow(itemType, backspace))
@@ -1,5 +1,5 @@
1
- // Markdown on the clipboard as text lands parsed in a block leaf (CODEC §"Markdown at the
2
- // edges"). A line opening a block is the shape a draft written in Notepad or copied out of
1
+ // Markdown on the clipboard as text lands parsed in a block leaf (INVARIANTS §"Markdown at
2
+ // the edges"). A line opening a block is the shape a draft written in Notepad or copied out of
3
3
  // an LLM chat carries, and text holding one runs through `importMarkdown` and `decode`, so
4
4
  // the paste stores what the source editor stores of the same text. Text holding none stays
5
5
  // literal: a sentence with a dash in it, or a `**` with no block around it, keeps every
@@ -147,7 +147,7 @@ li.ProseMirror-selectednode::after {
147
147
  pointer-events: none;
148
148
  }
149
149
 
150
- /* A footnote and an equation are read, not edited (CODEC §Decode), and draw as what
150
+ /* A footnote and an equation are read, not edited (INVARIANTS §Decode), and draw as what
151
151
  their markdown writes: a footnote its reference mark, numbered in reading order off a
152
152
  counter each leaf resets, its note the marker's title (`islands.ts`); an equation its
153
153
  TeX between its dollars, in the code face. */
@@ -589,7 +589,7 @@ li.ProseMirror-selectednode::after {
589
589
  top: 100%;
590
590
  height: var(--_qm-tap-min);
591
591
  }
592
- /* The reveal is the control's own (CODEC §"The table island"): one comes up while the
592
+ /* The reveal is the control's own (INVARIANTS §"The table island"): one comes up while the
593
593
  pointer is on that control, or while it is what a gesture is about — the selected line's grip, and the lifted one, which is drawn through a drag the
594
594
  pointer has travelled off. A cell under the pointer draws its row's and its column's
595
595
  grips (`table-view.ts` §`onHover`), one pill on each axis and none anywhere else.
@@ -651,7 +651,7 @@ li.ProseMirror-selectednode::after {
651
651
  first row, the band's top edge being the grips'. Up only while its column is held and
652
652
  absent otherwise (`table-view.ts` §`alignCluster`), so the reveal is `hidden` rather
653
653
  than the band's opacity. It is a row of glyphs floating over text, the format popover's
654
- family (ARCHITECTURE §Styling), and takes that recipe: the popover's translucent
654
+ family (INVARIANTS §Styling), and takes that recipe: the popover's translucent
655
655
  surface over a blur, the edge and `--_qm-lift` for its separation, and a scale-in on
656
656
  arrival, stated from its starting style since the codec shows it by clearing
657
657
  `hidden`. Its geometry is the popover's too, a row of toggles held one rung in from
@@ -11,7 +11,7 @@ export declare const inlineSchema: Schema<string, string>;
11
11
  * The inline schema with no mark types: a `plaintext(inline)` field, whose value is literal text
12
12
  * the boundary refuses to coerce back once it carries a mark. Declaring none makes that structural:
13
13
  * `toggleMark` has no type, the mark input rules build nothing, a paste parses marks away, and
14
- * `decode` drops any a stray content carries (CODEC §Inline mode).
14
+ * `decode` drops any a stray content carries (INVARIANTS §"Inline mode").
15
15
  */
16
16
  export declare const plaintextSchema: Schema<string, never>;
17
17
  /**
@@ -7,7 +7,7 @@
7
7
  // with hard breaks, for a table cell. Anchors are not marks here (decorations).
8
8
  //
9
9
  // `toDOM` and `parseDOM` are one tier: a copy and a paste inside one body run the whole document
10
- // through them (CODEC §"Markdown at the edges"), so every attribute written here is read back here.
10
+ // through them (INVARIANTS §"Markdown at the edges"), so every attribute written here is read back here.
11
11
  // Foreign HTML spells none of this package's `data-qm-*` names; the rules that widen that door on
12
12
  // purpose are the fence's and a span's styled marks, a `<table>` being the block leaf's clipboard
13
13
  // parser's (`table-paste.ts`).
@@ -210,7 +210,7 @@ const blockNodes = {
210
210
  // A list stating no `start` starts at one, the absence `toDOM` writes;
211
211
  // `Number(null)` would read it as zero. A value the store would normalize away
212
212
  // reads as that absence too, since a PM doc keeping one would disagree with the
213
- // store for the session (CODEC §Reconciliation). Zero is not one: `0.` is an
213
+ // store for the session (INVARIANTS §Reconciliation). Zero is not one: `0.` is an
214
214
  // ordinal `importMarkdown` produces.
215
215
  const stated = el.getAttribute('start');
216
216
  const start = stated ? Number(stated) : 1;
@@ -279,7 +279,7 @@ export const inlineSchema = new Schema({ nodes: inlineNodes, marks });
279
279
  * The inline schema with no mark types: a `plaintext(inline)` field, whose value is literal text
280
280
  * the boundary refuses to coerce back once it carries a mark. Declaring none makes that structural:
281
281
  * `toggleMark` has no type, the mark input rules build nothing, a paste parses marks away, and
282
- * `decode` drops any a stray content carries (CODEC §Inline mode).
282
+ * `decode` drops any a stray content carries (INVARIANTS §"Inline mode").
283
283
  */
284
284
  export const plaintextSchema = new Schema({ nodes: inlineNodes, marks: {} });
285
285
  /**