@quillmark/svelte 0.29.2 → 0.30.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 (70) hide show
  1. package/README.md +2 -1
  2. package/THEMING.md +8 -6
  3. package/dist/core/address.d.ts +3 -3
  4. package/dist/core/address.js +1 -1
  5. package/dist/core/bloom.d.ts +3 -2
  6. package/dist/core/bloom.js +6 -7
  7. package/dist/core/codec/decode.d.ts +1 -3
  8. package/dist/core/codec/decode.js +145 -206
  9. package/dist/core/codec/encode.d.ts +13 -35
  10. package/dist/core/codec/encode.js +127 -408
  11. package/dist/core/codec/field.d.ts +9 -9
  12. package/dist/core/codec/field.js +87 -80
  13. package/dist/core/codec/index.d.ts +2 -5
  14. package/dist/core/codec/index.js +4 -4
  15. package/dist/core/codec/inputrules.d.ts +0 -3
  16. package/dist/core/codec/inputrules.js +1 -1
  17. package/dist/core/codec/islands.d.ts +13 -19
  18. package/dist/core/codec/islands.js +55 -50
  19. package/dist/core/codec/list-move.d.ts +0 -3
  20. package/dist/core/codec/list-move.js +2 -2
  21. package/dist/core/codec/list-node.d.ts +2 -0
  22. package/dist/core/codec/list-node.js +1 -0
  23. package/dist/core/codec/list-paste.js +1 -1
  24. package/dist/core/codec/markdown-paste.d.ts +0 -9
  25. package/dist/core/codec/markdown-paste.js +1 -1
  26. package/dist/core/codec/marks.d.ts +12 -18
  27. package/dist/core/codec/marks.js +16 -26
  28. package/dist/core/codec/nesting.d.ts +0 -4
  29. package/dist/core/codec/nesting.js +1 -1
  30. package/dist/core/codec/positions.d.ts +14 -7
  31. package/dist/core/codec/positions.js +43 -50
  32. package/dist/core/codec/prose.css +1 -1
  33. package/dist/core/codec/reveal.d.ts +14 -0
  34. package/dist/core/codec/reveal.js +40 -0
  35. package/dist/core/codec/schema.d.ts +1 -1
  36. package/dist/core/codec/schema.js +26 -8
  37. package/dist/core/codec/slash.js +0 -0
  38. package/dist/core/codec/table-copy.d.ts +3 -3
  39. package/dist/core/codec/table-copy.js +6 -4
  40. package/dist/core/codec/table-paste.js +13 -9
  41. package/dist/core/codec/table-view.js +22 -15
  42. package/dist/core/codec/table.d.ts +77 -49
  43. package/dist/core/codec/table.js +158 -49
  44. package/dist/core/codec/touching.d.ts +0 -2
  45. package/dist/core/codec/touching.js +1 -11
  46. package/dist/preview/Preview.svelte +20 -1
  47. package/dist/preview/Preview.svelte.d.ts +1 -0
  48. package/dist/preview/controller.d.ts +5 -0
  49. package/dist/preview/controller.js +6 -0
  50. package/dist/preview/viewport.js +19 -1
  51. package/dist/preview/wash.d.ts +9 -0
  52. package/dist/preview/wash.js +38 -0
  53. package/dist/visual/ArrayField.svelte +18 -115
  54. package/dist/visual/FormatPopover.svelte +1 -1
  55. package/dist/visual/MatrixField.svelte +15 -19
  56. package/dist/visual/ObjectField.svelte +10 -13
  57. package/dist/visual/ProseValue.svelte +8 -8
  58. package/dist/visual/VisualEditorInner.svelte +17 -11
  59. package/dist/visual/guidance.d.ts +0 -12
  60. package/dist/visual/guidance.js +2 -2
  61. package/dist/visual/leaves.d.ts +1 -1
  62. package/dist/visual/leaves.js +1 -1
  63. package/dist/visual/props.d.ts +2 -2
  64. package/dist/visual/rowdrag.svelte.d.ts +21 -0
  65. package/dist/visual/rowdrag.svelte.js +118 -0
  66. package/dist/visual/structure.d.ts +6 -6
  67. package/dist/visual/structure.js +18 -21
  68. package/package.json +2 -2
  69. package/dist/visual/checklists.d.ts +0 -3
  70. package/dist/visual/checklists.js +0 -7
@@ -80,7 +80,7 @@ export interface CreateFieldOpts {
80
80
  * unanswered `none` is what the empty leaf draws and an empty answer would hide. */
81
81
  emptyUnsets?: boolean;
82
82
  onFocus?(addr: Addr): void;
83
- /** Fired with the new USV caret after an edit or a selection move. */
83
+ /** Fired with the new caret offset after an edit or a selection move. */
84
84
  onCaretMove?(addr: Addr, pos: number): void;
85
85
  /**
86
86
  * Fired after an edit committed to the document: the leaf's change signal. Unlike `onCaretMove`
@@ -97,7 +97,7 @@ export interface FieldController {
97
97
  /** The mounted `container`: the leaf's element, for a caller that has to reach the
98
98
  * DOM the view sits in (the arrival wash, `core/bloom.ts`) rather than re-find it. */
99
99
  readonly el: HTMLElement;
100
- /** Place the caret at USV `pos` (preview onPick → usvToPM → here). */
100
+ /** Place the caret at content offset `pos` (preview onPick → offsetToPM → here). */
101
101
  setCaret(pos: number): void;
102
102
  /**
103
103
  * External content change → re-hydrate this leaf (gated by reconcile), and re-evaluate its
@@ -119,14 +119,14 @@ export interface FieldController {
119
119
  /** The current stored content for this addr (for tests / reconcile). */
120
120
  getContent(): Content;
121
121
  /**
122
- * Insert an identity anchor `id` at USV `pos`. Zero-width; it folds into the plugin's position
123
- * set and commits through the mark-diff `anchor` op. The id is caller-supplied and must be
124
- * unique and invariant; a duplicate id is a no-op.
122
+ * Insert an identity anchor `id` over content offsets `[pos, end)`, a point where `end` is
123
+ * absent. It folds into the plugin's set and commits with the next change. The id is
124
+ * caller-supplied and must be unique and invariant; a duplicate id is a no-op.
125
125
  */
126
- insertAnchor(id: string, pos: number): void;
126
+ insertAnchor(id: string, pos: number, end?: number): void;
127
127
  /** Remove the identity anchor `id` (the inverse of {@link insertAnchor}); a no-op if absent. */
128
128
  removeAnchor(id: string): void;
129
- /** Ids of the anchors within USV range `[from, to]`: a selection's anchor state. */
129
+ /** Ids of the anchors touching content range `[from, to]`: a selection's anchor state. */
130
130
  anchorsInRange(from: number, to: number): string[];
131
131
  /**
132
132
  * Move the slash menu's cursor onto the command `name` (a pointer entering an item): the
@@ -136,7 +136,7 @@ export interface FieldController {
136
136
  /** Run the command `name` (a click on its item): the same path Enter takes. A no-op
137
137
  * with no menu open, which is the state a stale click lands in. */
138
138
  slashPick(name: string): void;
139
- /** The current PM selection as a USV `{ from, to }` range (the boundary currency). */
139
+ /** The current PM selection as a content `{ from, to }` range (the boundary currency). */
140
140
  selectionRange(): {
141
141
  from: number;
142
142
  to: number;
@@ -156,7 +156,7 @@ export interface LeafViews {
156
156
  /** Every view nested inside this leaf, in mount order: one per table cell. */
157
157
  nestedViews(): EditorView[];
158
158
  }
159
- /** The canonical empty `Content`: one empty `para` line. */
159
+ /** The canonical empty `Content`: one empty `para` block. */
160
160
  export declare function emptyContent(): Content;
161
161
  /** Whether `rt` is the empty leaf: {@link emptyContent}, nothing typed and no shape left. */
162
162
  export declare function isEmptyContent(rt: Content): boolean;
@@ -1,12 +1,12 @@
1
1
  // The prose leaf: `createField` (VISUAL_EDITOR §Surface). One content field, one PM view wired to
2
2
  // the WASM edit surface.
3
3
  //
4
- // `dispatchTransaction` applies the transaction optimistically, lowers it to a `ChangeBundle` (or
5
- // `overwrite` for a field not yet at content rest, which has nothing to splice), commits via
6
- // `doc.applyChange` (a `text` leaf's whole text through the typed writer), then fires `onChange` if
7
- // it committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through
8
- // `onError`. An external change re-hydrates through `applyExternal`, gated by `reconcile` except
9
- // where the hold it re-evaluates flips.
4
+ // `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (or
5
+ // `replace` for a field not yet at content rest, which has nothing to change), commits via
6
+ // `doc.apply` (a `text` leaf's whole text through the typed writer), then fires `onChange` if it
7
+ // committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through `onError`.
8
+ // An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
9
+ // hold it re-evaluates flips.
10
10
  import { baseKeymap, toggleMark } from 'prosemirror-commands';
11
11
  import { gapCursor } from 'prosemirror-gapcursor';
12
12
  import { history, redo, undo } from 'prosemirror-history';
@@ -14,13 +14,14 @@ import { keymap } from 'prosemirror-keymap';
14
14
  import { Fragment, Slice } from 'prosemirror-model';
15
15
  import { EditorState, NodeSelection, Plugin, PluginKey, Selection, TextSelection } from 'prosemirror-state';
16
16
  import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
17
+ import { revealProps } from './reveal.js';
17
18
  import { core } from '../lifecycle.js';
18
19
  import { reportError, errorMessage } from '../errors.js';
19
20
  import { decode, fitsLeaf } from './decode.js';
20
- import { usvToPM, pmToUsv, buildLineIndex, lineIndexOf } from './positions.js';
21
- import { lower, pmToContent, scanContent, scanDoc, contentEdit } from './encode.js';
21
+ import { offsetToPM, pmToOffset, buildLineIndex, lineIndexOf, mapThroughDelta } from './positions.js';
22
+ import { lower, pmToContent, scanContent, scanDoc } from './encode.js';
22
23
  import { capPlugin } from './cap.js';
23
- import { islandPastePlugin } from './islands.js';
24
+ import { HARD_BREAK, islandPastePlugin } from './islands.js';
24
25
  import { anchorsFromContent } from './marks.js';
25
26
  import { contentEqual, createReconciler } from './reconcile.js';
26
27
  import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
@@ -41,12 +42,12 @@ import { taskPlugin } from './tasks.js';
41
42
  import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
42
43
  import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
43
44
  const anchorKey = new PluginKey('quill-anchors');
44
- /** Plugin-held anchor positions (PM coords), mapped through every edit's `StepMap`
45
- * and mutated by an {@link AnchorEdit} meta (an insert/remove at a selection).
46
- *
47
- * The `-1` is the store's rule for a point, not PM's default: `applyChange` rebases a
48
- * zero-width mark `before`, so text typed at an anchor's own position lands after it
49
- * and the mark diff has no op to spend reconciling this set with the store. */
45
+ /**
46
+ * Plugin-held anchors (PM coords), mapped through every edit's `StepMap` and mutated by an {@link
47
+ * AnchorEdit} meta. The store's rule, so the commit has nothing to reconcile: a range keeps its
48
+ * edges, text typed at either landing outside it, and a point stays left of text typed at it. A
49
+ * range whose text is wholly deleted goes; a point never does.
50
+ */
50
51
  function anchorPlugin(seed) {
51
52
  return new Plugin({
52
53
  key: anchorKey,
@@ -54,11 +55,19 @@ function anchorPlugin(seed) {
54
55
  init: () => seed,
55
56
  apply: (tr, anchors) => {
56
57
  let next = tr.docChanged
57
- ? anchors.map((a) => ({ id: a.id, pos: tr.mapping.map(a.pos, -1) }))
58
+ ? anchors.flatMap((a) => {
59
+ if (a.start === a.end) {
60
+ const at = tr.mapping.map(a.start, -1);
61
+ return [{ id: a.id, start: at, end: at }];
62
+ }
63
+ const start = tr.mapping.map(a.start, 1);
64
+ const end = tr.mapping.map(a.end, -1);
65
+ return start < end ? [{ id: a.id, start, end }] : [];
66
+ })
58
67
  : anchors;
59
68
  const edit = tr.getMeta(anchorKey);
60
69
  if (edit?.op === 'add')
61
- next = [...next, { id: edit.id, pos: edit.pos }];
70
+ next = [...next, { id: edit.id, start: edit.start, end: edit.end }];
62
71
  else if (edit?.op === 'remove')
63
72
  next = next.filter((a) => a.id !== edit.id);
64
73
  else if (edit?.op === 'reset')
@@ -68,6 +77,10 @@ function anchorPlugin(seed) {
68
77
  }
69
78
  });
70
79
  }
80
+ /** An anchor in content offsets at its PM positions over `index`. */
81
+ function toPM(index, a) {
82
+ return { id: a.id, start: offsetToPM(index, a.start), end: offsetToPM(index, a.end) };
83
+ }
71
84
  /**
72
85
  * Read the leaf's `Content` for `addr` through `reader.getContent` (DOCUMENT_MODEL): the body when
73
86
  * `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
@@ -79,21 +92,27 @@ function anchorPlugin(seed) {
79
92
  function readLeaf(reader, addr) {
80
93
  return reader.getContent(addr) ?? emptyContent();
81
94
  }
82
- /** The canonical empty `Content`: one empty `para` line. */
95
+ /** `addr` as a content write takes it: a card named by its `$id`, which a write requires. */
96
+ function writeAddr(doc, addr) {
97
+ if (typeof addr.card !== 'number')
98
+ return addr;
99
+ return { ...addr, card: doc.card(addr.card).id ?? addr.card };
100
+ }
101
+ /** The canonical empty `Content`: one empty `para` block. */
83
102
  export function emptyContent() {
84
- return { text: '', lines: [{ containers: [], kind: 'para' }], marks: [], islands: [] };
103
+ return { text: '', blocks: [{ id: 'b0', kind: 'para' }] };
85
104
  }
86
105
  /** Whether `rt` is the empty leaf: {@link emptyContent}, nothing typed and no shape left. */
87
106
  export function isEmptyContent(rt) {
88
107
  return contentEqual(rt, emptyContent());
89
108
  }
90
109
  /**
91
- * Whether ops may commit here: the stored value is a `Content` object, so `applyChange` splices
92
- * exactly what PM shows. The other rest forms take `overwrite`: an unset field has nothing to
93
- * splice, and an authored string carries no anchors to pay. A body always rests as `Content`; a
94
- * `text` leaf commits through the writer ({@link createField}).
110
+ * Whether a change may commit here: the stored value is a `Content` object, so `apply` changes
111
+ * exactly what PM shows. The other rest forms take `replace`: an unset field has nothing to change,
112
+ * and an authored string carries no anchors to pay. A body always rests as `Content`; a `text` leaf
113
+ * commits through the writer ({@link createField}).
95
114
  */
96
- function opsCommittable(doc, addr) {
115
+ function changeCommittable(doc, addr) {
97
116
  const stored = doc.getStored(addr);
98
117
  return stored !== null && typeof stored === 'object';
99
118
  }
@@ -175,10 +194,7 @@ export function createField(opts) {
175
194
  state,
176
195
  editable: () => !held,
177
196
  attributes: () => (held ? heldNamed : defaulted ? defaultNamed : named),
178
- // Both terms, one line each: when a flagged dispatch moves the scrollport
179
- // (`scrollThreshold`) and what it leaves at the edge (`scrollMargin`).
180
- scrollThreshold: clearance,
181
- scrollMargin: clearance,
197
+ ...revealProps(clearance),
182
198
  // Islands are block-schema only, so any other leaf mounts no node view at all.
183
199
  nodeViews: block
184
200
  ? {
@@ -215,12 +231,13 @@ export function createField(opts) {
215
231
  // (`docChanged` false), so the `anchorKey` meta routes it.
216
232
  if (!held && (tr.docChanged || tr.getMeta(anchorKey))) {
217
233
  // (d) the change signal, only for what actually landed.
218
- const newRt = scan ? scanContent(scan) : pmToContent(next.doc);
234
+ const anchors = plaintext ? [] : readAnchors();
235
+ const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
219
236
  if (commitEdit(oldRt, newRt))
220
237
  opts.onChange?.(addr);
221
238
  }
222
239
  // The caret, for structural and selection-only changes, reported after the commit.
223
- opts.onCaretMove?.(addr, pmToUsv(index, next.selection.head));
240
+ opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
224
241
  },
225
242
  handleDOMEvents: {
226
243
  focus: () => {
@@ -245,10 +262,7 @@ export function createField(opts) {
245
262
  const anchors = plaintext ? [] : anchorsFromContent(rt);
246
263
  // Seed anchor plugin positions in PM coords via a fresh index over pmDoc.
247
264
  const seedIndex = buildLineIndex(pmDoc);
248
- const seededAnchors = anchors.map((a) => ({
249
- id: a.id,
250
- pos: usvToPM(seedIndex, a.pos)
251
- }));
265
+ const seededAnchors = anchors.map((a) => toPM(seedIndex, a));
252
266
  const built = EditorState.create({
253
267
  doc: pmDoc,
254
268
  plugins: proseLeafPlugins(schema, {
@@ -266,45 +280,40 @@ export function createField(opts) {
266
280
  });
267
281
  return { state: built, index: seedIndex };
268
282
  }
269
- // (b)+(c): lower the edit to ops and commit, or `overwrite` a field not yet at content rest.
283
+ // (b)+(c): lower the edit to a change and commit, or `replace` a field not yet at content rest.
270
284
  // Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
271
285
  // branch ran.
272
286
  function commitEdit(oldRt, newRt) {
287
+ const at = writeAddr(doc, addr);
273
288
  if (opts.emptyUnsets && heldAnchors().length === 0 && isEmptyContent(newRt))
274
289
  return commitUnset();
275
290
  if (plaintext)
276
- return commitPlain(newRt.text);
277
- // The text splice, computed once per keystroke and shared by the gate, both overwrite
278
- // fallbacks and `lower`.
279
- const edit = contentEdit(oldRt, newRt);
291
+ return commitPlain(newRt.text.replaceAll(HARD_BREAK, '\n'));
280
292
  try {
281
- // Only a field not yet at content rest overwrites by choice: `applyChange` throws on an
282
- // absent declared field, and neither it nor an authored string has anchors to lose
283
- // (`opsCommittable`). Every structural edit lowers; the island channel places a slot
284
- // the `delta` may not carry.
285
- if (!opsCommittable(doc, addr)) {
286
- doc.overwrite(addr, edit.newRt); // brings the field to content rest
287
- }
293
+ // Only a field not yet at content rest replaces by choice: neither an absent declared
294
+ // field nor an authored string has anchors to lose (`changeCommittable`).
295
+ if (!changeCommittable(doc, addr))
296
+ doc.replace(at, newRt);
288
297
  else {
289
- // Post-edit anchors are the plugin's positions (mapped through the tr) as
290
- // USV; the pre-edit set is `oldRt`'s own, which `lower` reads for itself.
291
- doc.applyChange(addr, lower(edit, { newAnchors: readAnchorsUsv() }));
298
+ const change = lower(oldRt, newRt);
299
+ if (change)
300
+ doc.apply(at, change);
292
301
  }
293
302
  reconciler.commit(readLeaf(reader, addr));
294
303
  return true;
295
304
  }
296
305
  catch (e) {
297
- // Bound the damage: after an op path the gates missed, the reconciler re-diffs from
298
- // stale content and every later edit would re-throw. Install the full projection
299
- // (correct store, pays this field's anchors).
306
+ // Bound the damage: after a change the store refused, the reconciler re-diffs from stale
307
+ // content and every later edit would re-throw. Replace with the full projection, which
308
+ // carries each anchor where its text survives.
300
309
  reportError(opts.onError, {
301
310
  code: 'commit-fallback',
302
311
  severity: 'error',
303
- message: `applyChange refused; overwrote the whole field: ${errorMessage(e)}`,
312
+ message: `apply refused; replaced the whole field: ${errorMessage(e)}`,
304
313
  cause: e
305
314
  });
306
315
  try {
307
- doc.overwrite(addr, edit.newRt);
316
+ doc.replace(at, newRt);
308
317
  reconciler.commit(readLeaf(reader, addr));
309
318
  return true;
310
319
  }
@@ -313,7 +322,7 @@ export function createField(opts) {
313
322
  reportError(opts.onError, {
314
323
  code: 'commit-lost',
315
324
  severity: 'error',
316
- message: `overwrite fallback failed; the stored value is stale while the editor keeps the edit: ${errorMessage(e2)}`,
325
+ message: `replace fallback failed; the stored value is stale while the editor keeps the edit: ${errorMessage(e2)}`,
317
326
  cause: e2
318
327
  });
319
328
  return false;
@@ -331,6 +340,8 @@ export function createField(opts) {
331
340
  const name = addr.field;
332
341
  if (name === undefined)
333
342
  throw new Error('a text leaf names a field');
343
+ if (typeof addr.card === 'string')
344
+ throw new Error('a text leaf names its card by index');
334
345
  (addr.card === undefined ? writer : writer.card(addr.card)).set(name, text);
335
346
  reconciler.commit(readLeaf(reader, addr));
336
347
  return true;
@@ -386,14 +397,13 @@ export function createField(opts) {
386
397
  return false;
387
398
  const after = buildLineIndex(tr.doc);
388
399
  if (delta && before.selection instanceof TextSelection) {
389
- const { mapPos } = core();
390
- const at = (pm) => usvToPM(after, mapPos(delta, pmToUsv(index, pm), 'after'));
400
+ const at = (pm) => offsetToPM(after, mapThroughDelta(delta, pmToOffset(index, pm)));
391
401
  tr.setSelection(TextSelection.between(tr.doc.resolve(at(before.selection.anchor)), tr.doc.resolve(at(before.selection.head))));
392
402
  }
393
403
  if (!plaintext)
394
404
  tr.setMeta(anchorKey, {
395
405
  op: 'reset',
396
- anchors: anchorsFromContent(rt).map((a) => ({ id: a.id, pos: usvToPM(after, a.pos) }))
406
+ anchors: anchorsFromContent(rt).map((a) => toPM(after, a))
397
407
  });
398
408
  view.updateState(before.apply(tr));
399
409
  index = view.state.doc.eq(tr.doc) ? after : buildLineIndex(view.state.doc);
@@ -405,15 +415,19 @@ export function createField(opts) {
405
415
  }
406
416
  /** The anchors the plugin currently holds (PM coords); `[]` before the first apply. */
407
417
  const heldAnchors = () => anchorKey.getState(view.state) ?? [];
408
- /** The plugin's anchor positions as USV, against `index` — which `dispatchTransaction`
418
+ /** The plugin's anchors as content offsets, against `index` — which `dispatchTransaction`
409
419
  * rebuilt over the new document before the commit this reads for. */
410
- function readAnchorsUsv() {
411
- return heldAnchors().map((a) => ({ id: a.id, pos: pmToUsv(index, a.pos) }));
420
+ function readAnchors() {
421
+ return heldAnchors().map((a) => ({
422
+ id: a.id,
423
+ start: pmToOffset(index, a.start),
424
+ end: pmToOffset(index, a.end)
425
+ }));
412
426
  }
413
427
  const controller = {
414
428
  el: container,
415
429
  setCaret(pos) {
416
- const pm = usvToPM(index, pos);
430
+ const pm = offsetToPM(index, pos);
417
431
  // `Selection.near`: the mapped position can be non-inline, where a raw TextSelection is
418
432
  // invalid.
419
433
  const sel = Selection.near(view.state.doc.resolve(pm));
@@ -442,12 +456,12 @@ export function createField(opts) {
442
456
  }
443
457
  if (flipped)
444
458
  held = !held;
445
- const caretUsv = pmToUsv(index, view.state.selection.head);
459
+ const caret = pmToOffset(index, view.state.selection.head);
446
460
  const fresh = buildState(current);
447
461
  index = fresh.index;
448
- // Best-effort caret continuity across an external change: keep the USV. Set
462
+ // Best-effort caret continuity across an external change: keep the offset. Set
449
463
  // rather than dispatched, so a leaf the caret is not in reports no caret move.
450
- const sel = Selection.near(fresh.state.doc.resolve(usvToPM(index, caretUsv)));
464
+ const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
451
465
  view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
452
466
  reconciler.commit(current);
453
467
  if (flipped)
@@ -476,18 +490,14 @@ export function createField(opts) {
476
490
  getContent() {
477
491
  return readLeaf(reader, addr);
478
492
  },
479
- insertAnchor(id, pos) {
480
- // A text field carries no marks (§Inline mode), and a held one commits nothing.
493
+ insertAnchor(id, pos, end = pos) {
494
+ // A text field carries no anchors (§Inline mode), and a held one commits nothing.
481
495
  if (plaintext || held)
482
496
  return;
483
497
  if (heldAnchors().some((a) => a.id === id))
484
- return; // ids are unique + invariant (0.97 policy)
485
- // An anchor commits through `applyChange`, so the field is brought to content rest
486
- // first or the overwrite branch would drop it.
487
- if (!opsCommittable(doc, addr))
488
- doc.overwrite(addr, reconciler.last);
489
- const pm = usvToPM(index, pos);
490
- view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'add', id, pos: pm }));
498
+ return; // ids are unique and invariant
499
+ const at = toPM(index, { id, start: Math.min(pos, end), end: Math.max(pos, end) });
500
+ view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'add', ...at }));
491
501
  },
492
502
  removeAnchor(id) {
493
503
  if (plaintext)
@@ -498,10 +508,7 @@ export function createField(opts) {
498
508
  },
499
509
  anchorsInRange(from, to) {
500
510
  return heldAnchors()
501
- .filter((a) => {
502
- const u = pmToUsv(index, a.pos);
503
- return u >= from && u <= to;
504
- })
511
+ .filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
505
512
  .map((a) => a.id);
506
513
  },
507
514
  slashFocus(name) {
@@ -515,8 +522,8 @@ export function createField(opts) {
515
522
  selectionRange() {
516
523
  const { from, to } = view.state.selection;
517
524
  return {
518
- from: pmToUsv(index, from),
519
- to: pmToUsv(index, to)
525
+ from: pmToOffset(index, from),
526
+ to: pmToOffset(index, to)
520
527
  };
521
528
  },
522
529
  destroy() {
@@ -12,12 +12,9 @@ export type { SlashState, SlashStrings } from './slash.js';
12
12
  export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
13
13
  export { rendersHref, storableUrl } from './urls.js';
14
14
  export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
15
- export { pmToContent, contentEdit, lower } from './encode.js';
16
- export type { ContentEdit } from './encode.js';
17
- export { usvToPM, pmToUsv, buildLineIndex } from './positions.js';
18
- export type { LineIndex } from './positions.js';
15
+ export { pmToContent, lower } from './encode.js';
16
+ export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
19
17
  export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
20
- export type { Reconciler } from './reconcile.js';
21
18
  export { inputRulesPlugin } from './inputrules.js';
22
19
  export { bodyKeymap } from './keymap.js';
23
20
  export { listKeymap } from './lists.js';
@@ -1,6 +1,6 @@
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 tr → a
3
- // `ChangeBundle` for `applyChange`), the USV↔PM position map, and the `createField`
2
+ // and one ProseMirror document (CODEC.md). Decode (content → PM), lower (PM doc → a
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
6
6
  // hues they mint. Imported here because `createField` is what mounts a view: a
@@ -35,8 +35,8 @@ export { rendersHref, storableUrl } from './urls.js';
35
35
  // reached only by relative import within `codec/` stays off it: an export nothing
36
36
  // imports is surface that still has to stay honest.
37
37
  export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
38
- export { pmToContent, contentEdit, lower } from './encode.js';
39
- export { usvToPM, pmToUsv, buildLineIndex } from './positions.js';
38
+ export { pmToContent, lower } from './encode.js';
39
+ export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
40
40
  // Reconciliation gate.
41
41
  export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
42
42
  // Input rules (`createField` mounts them unless `noInputRules`, or over a mark-free schema).
@@ -1,8 +1,5 @@
1
- import { InputRule } from 'prosemirror-inputrules';
2
1
  import type { Schema } from 'prosemirror-model';
3
2
  import type { Plugin } from 'prosemirror-state';
4
- /** The full markdown-shorthand rule set for a block schema. */
5
- export declare function markdownInputRules(schema: Schema): InputRule[];
6
3
  /** The input-rules plugin the field mounts by default (opt-out via createField). */
7
4
  export declare function inputRulesPlugin(schema: Schema): Plugin;
8
5
  /** Backspace on the press right after a rule fired takes the rule back and leaves the
@@ -77,7 +77,7 @@ function blockRule(regexp, command) {
77
77
  return new InputRule(regexp, (state, match, start, end) => consuming(state, start, end, command(match))?.tr.scrollIntoView() ?? null);
78
78
  }
79
79
  /** The full markdown-shorthand rule set for a block schema. */
80
- export function markdownInputRules(schema) {
80
+ function markdownInputRules(schema) {
81
81
  const rules = [];
82
82
  const m = schema.marks;
83
83
  // Inline marks. Non-greedy capture between matching delimiters. Built only where the
@@ -1,15 +1,17 @@
1
1
  import { type Node as PMNode, type NodeSpec } from 'prosemirror-model';
2
2
  import { Plugin } from 'prosemirror-state';
3
- import type { ContentIsland, TableProps } from '@quillmark/wasm';
3
+ import type { Content, ContentIsland, TableProps } from '@quillmark/wasm';
4
+ /** The `U+2028` line separator that is a break inside a block's text. */
5
+ export declare const HARD_BREAK = "\u2028";
4
6
  /** The `U+FFFC` object-replacement char that occupies one island slot in `text`. */
5
7
  export declare const ISLAND_SLOT = "\uFFFC";
6
- /** Whether an island of `type` is block markup: a `table` stands alone on its line. */
8
+ /** Whether an island of `type` is block markup: a `table` stands alone in its block. */
7
9
  export declare function isBlockIsland(type: ContentIsland['type']): boolean;
8
10
  /** Whether a leaf edits an island of `type`; one holding any other is held (`fitsLeaf`). */
9
11
  export declare function isEditedIsland(type: ContentIsland['type']): boolean;
10
- /** Block island node (a table): a `U+FFFC` slot alone on its `para` line. Atom. */
12
+ /** Block island node (a table): a `U+FFFC` slot alone in its `para` block. Atom. */
11
13
  export declare const islandBlockSpec: NodeSpec;
12
- /** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para` line. */
14
+ /** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para` block. */
13
15
  export declare const islandInlineSpec: NodeSpec;
14
16
  /**
15
17
  * A PM island node's attributes: the content entry, with `islandType` because `type` on a PM node
@@ -19,30 +21,22 @@ export interface IslandNodeAttrs {
19
21
  id: string;
20
22
  islandType: ContentIsland['type'];
21
23
  props: unknown;
24
+ slots: Record<string, Content> | null;
25
+ /** A block island's: the id of the block its slot fills. */
26
+ block?: string | null;
22
27
  }
23
28
  /**
24
29
  * Build a content island entry from a PM island node's attrs. The cast pairs a closed `type` with a
25
30
  * `props` that crossed the DOM as opaque JSON. The store is lenient about a table's shape, so a
26
31
  * payload the arm does not hold is stored, and `undefined` at its reader draws the placeholder
27
- * (§`tablePropsOfNode`).
32
+ * (`table.ts` §`tableOfNode`).
28
33
  */
29
34
  export declare function islandEntryFromNode(attrs: IslandNodeAttrs): ContentIsland;
30
35
  /**
31
- * A node's `TableProps`, or `undefined` for any other island and for a payload of the wrong shape:
32
- * the boundary's guard, so a `props` that crossed the DOM is read once here. Every caller draws the
33
- * placeholder for `undefined` (`table-view.ts` §`render`).
36
+ * The `TableProps` shape over a value that reached the node off the DOM: the column ids and the
37
+ * rows mapping each to a slot id, which every reader indexes (`table.ts`).
34
38
  */
35
- export declare function tablePropsOfNode(node: PMNode): TableProps | undefined;
36
- /**
37
- * A minter over one document: the positional `isl-{n}` sequence continued past the highest id the
38
- * field holds, so a caller placing several islands keeps one minter. A minted id is part of the
39
- * document's canonical bytes (CODEC §Islands): a counter over the projection in hand, never a UUID
40
- * or clock reading, and never a re-numbering of existing ids.
41
- *
42
- * Reads the PM doc rather than stored content because that is what the caller holds and the commit
43
- * will project; a stale content could collide with an id the same transaction places.
44
- */
45
- export declare function islandMinter(doc: PMNode): () => string;
39
+ export declare function isTableProps(props: unknown): props is TableProps;
46
40
  /** The next island id for a field: one draw from {@link islandMinter}. */
47
41
  export declare function mintIslandId(doc: PMNode): string;
48
42
  /**