@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
@@ -1,13 +1,16 @@
1
1
  // Islands: the `U+FFFC` slot + `ContentIsland` entry ↔ a PM leaf node. Every slot sits in a `para`
2
- // line; the island's type says which node it is, a `table` a block alone on its line and every
3
- // other type inline. The node carries `id`, `islandType` and `props` verbatim.
2
+ // block; the island's type says which node it is, a `table` a block alone in its block and every
3
+ // other type inline. The node carries `id`, `islandType`, `props` and `slots` verbatim, and a block
4
+ // island the id of the block it fills.
4
5
  //
5
6
  // `ContentIsland.props` is the typed union at the boundary (DOCUMENT_MODEL §Stability seams), so a
6
7
  // discriminant check narrows it; `props` still crosses the DOM as opaque JSON, which
7
- // §`tablePropsOfNode` guards.
8
+ // `table.ts` §`tableOfNode` guards.
8
9
  import { Fragment, Slice } from 'prosemirror-model';
9
10
  import { Plugin } from 'prosemirror-state';
10
11
  import { storableUrl } from './urls.js';
12
+ /** The `U+2028` line separator that is a break inside a block's text. */
13
+ export const HARD_BREAK = '\u2028';
11
14
  /** The `U+FFFC` object-replacement char that occupies one island slot in `text`. */
12
15
  export const ISLAND_SLOT = '';
13
16
  // The three island node attributes carry the content entry verbatim: `id` is the stable identity
@@ -17,7 +20,8 @@ export const ISLAND_SLOT = '';
17
20
  const islandAttrs = {
18
21
  id: { default: '' },
19
22
  islandType: {},
20
- props: {}
23
+ props: {},
24
+ slots: { default: null }
21
25
  };
22
26
  // All three attributes cross the DOM, since a copy and a paste inside one body run the document
23
27
  // through `toDOM`/`parseDOM` (CODEC §"Markdown at the edges") and an island's tags alone say only
@@ -28,54 +32,56 @@ function islandDOM(node) {
28
32
  return {
29
33
  'data-qm-island': node.attrs.islandType,
30
34
  'data-qm-island-id': node.attrs.id,
31
- 'data-qm-island-props': JSON.stringify(node.attrs.props ?? null)
35
+ 'data-qm-island-props': JSON.stringify(node.attrs.props ?? null),
36
+ 'data-qm-island-slots': JSON.stringify(node.attrs.slots ?? null)
32
37
  };
33
38
  }
34
- /**
35
- * The island types the content model names, each with whether its markup is a block (deciding the
36
- * node its slot decodes to) and whether a leaf edits it. A `Record` over the boundary's union, so a
37
- * member added upstream is a missing key here. A footnote and an equation are read, not edited
38
- * (CODEC §Decode): a leaf holding one is held.
39
- */
40
39
  const ISLANDS = {
41
40
  table: { block: true, edited: true },
42
41
  image: { block: false, edited: true },
43
42
  footnote: { block: false, edited: false },
44
43
  math: { block: false, edited: false }
45
44
  };
46
- /** Whether an island of `type` is block markup: a `table` stands alone on its line. */
45
+ /** Whether an island of `type` is block markup: a `table` stands alone in its block. */
47
46
  export function isBlockIsland(type) {
48
- return ISLANDS[type].block;
47
+ return Object.hasOwn(ISLANDS, type) && ISLANDS[type].block;
49
48
  }
50
49
  /** Whether a leaf edits an island of `type`; one holding any other is held (`fitsLeaf`). */
51
50
  export function isEditedIsland(type) {
52
- return ISLANDS[type].edited;
51
+ return Object.hasOwn(ISLANDS, type) && ISLANDS[type].edited;
53
52
  }
54
53
  /**
55
54
  * An island node's attributes off that DOM, or `false` where the id is absent or the type is one no
56
55
  * leaf edits (an unknown name, a footnote, an equation), so the element's text arrives as text. A
57
56
  * `props` that is not the JSON written above reads as `null`, one of the wrong shape `undefined` at
58
- * its reader (§`tablePropsOfNode`): the entry survives as an island of its type.
57
+ * its reader (`table.ts` §`tableOfNode`): the entry survives as an island of its type.
59
58
  */
60
59
  function islandAttrsFromDOM(el) {
61
60
  const id = el.getAttribute('data-qm-island-id');
62
61
  // Asserted off an untrusted attribute and checked against the set on the next line.
63
62
  const type = el.getAttribute('data-qm-island');
64
- if (id == null || type == null || !Object.hasOwn(ISLANDS, type) || !isEditedIsland(type))
63
+ if (id == null || type == null || !isEditedIsland(type))
65
64
  return false;
66
- const raw = el.getAttribute('data-qm-island-props');
67
- let props = null;
68
- try {
69
- props = raw == null ? null : JSON.parse(raw);
70
- }
71
- catch {
72
- props = null;
73
- }
74
- return { id, islandType: type, props: storableProps(type, props) };
65
+ const json = (name) => {
66
+ const raw = el.getAttribute(name);
67
+ try {
68
+ return raw == null ? null : JSON.parse(raw);
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ };
74
+ const slots = json('data-qm-island-slots');
75
+ return {
76
+ id,
77
+ islandType: type,
78
+ props: storableProps(type, json('data-qm-island-props')),
79
+ slots: typeof slots === 'object' && slots !== null ? slots : null
80
+ };
75
81
  }
76
82
  /**
77
83
  * `props` with the one key the authored lane refuses made storable: an `image`'s `url` carrying a
78
- * line ending, which `IslandOp` and `overwrite` throw on.
84
+ * line ending, which a write refuses.
79
85
  */
80
86
  function storableProps(type, props) {
81
87
  if (type !== 'image' || typeof props !== 'object' || props === null)
@@ -83,16 +89,16 @@ function storableProps(type, props) {
83
89
  const url = props.url;
84
90
  return typeof url === 'string' ? { ...props, url: storableUrl(url) } : props;
85
91
  }
86
- /** Block island node (a table): a `U+FFFC` slot alone on its `para` line. Atom. */
92
+ /** Block island node (a table): a `U+FFFC` slot alone in its `para` block. Atom. */
87
93
  export const islandBlockSpec = {
88
94
  group: 'block',
89
95
  atom: true,
90
96
  selectable: true,
91
- attrs: islandAttrs,
97
+ attrs: { ...islandAttrs, block: { default: null } },
92
98
  parseDOM: [{ tag: 'div[data-qm-island]', getAttrs: (el) => islandAttrsFromDOM(el) }],
93
99
  toDOM: (node) => ['div', islandDOM(node), `[${node.attrs.islandType || 'island'}]`]
94
100
  };
95
- /** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para` line. */
101
+ /** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para` block. */
96
102
  export const islandInlineSpec = {
97
103
  group: 'inline',
98
104
  inline: true,
@@ -110,8 +116,10 @@ function inlineIslandDOM(node) {
110
116
  const attrs = node.attrs;
111
117
  const dom = islandDOM(node);
112
118
  const props = attrs.props;
113
- if (attrs.islandType === 'footnote')
114
- return ['sup', typeof props?.text === 'string' ? { ...dom, title: props.text } : dom];
119
+ if (attrs.islandType === 'footnote') {
120
+ const note = attrs.slots?.note?.text;
121
+ return ['sup', typeof note === 'string' ? { ...dom, title: note } : dom];
122
+ }
115
123
  if (attrs.islandType === 'math' && typeof props?.tex === 'string') {
116
124
  const fence = props.display ? '$$' : '$';
117
125
  return ['span', dom, `${fence}${props.tex}${fence}`];
@@ -122,35 +130,32 @@ function inlineIslandDOM(node) {
122
130
  * Build a content island entry from a PM island node's attrs. The cast pairs a closed `type` with a
123
131
  * `props` that crossed the DOM as opaque JSON. The store is lenient about a table's shape, so a
124
132
  * payload the arm does not hold is stored, and `undefined` at its reader draws the placeholder
125
- * (§`tablePropsOfNode`).
133
+ * (`table.ts` §`tableOfNode`).
126
134
  */
127
135
  export function islandEntryFromNode(attrs) {
128
136
  return {
129
137
  id: attrs.id,
130
138
  type: attrs.islandType,
131
- props: attrs.props
139
+ props: attrs.props,
140
+ ...(attrs.slots && Object.keys(attrs.slots).length ? { slots: attrs.slots } : {})
132
141
  };
133
142
  }
134
143
  /**
135
- * The `TableProps` shape over a value that reached the node off the DOM: the rectangle every reader
136
- * indexes (`table.ts`), down to the `text` a row's emptiness is read off.
144
+ * The `TableProps` shape over a value that reached the node off the DOM: the column ids and the
145
+ * rows mapping each to a slot id, which every reader indexes (`table.ts`).
137
146
  */
138
- function isTableProps(props) {
147
+ export function isTableProps(props) {
139
148
  if (typeof props !== 'object' || props === null)
140
149
  return false;
141
- const { header, rows, aligns } = props;
142
- const cells = (v) => Array.isArray(v) &&
143
- v.every((c) => typeof c === 'object' && c !== null && typeof c.text === 'string');
144
- return (cells(header) && Array.isArray(aligns) && Array.isArray(rows) && rows.every((row) => cells(row)));
145
- }
146
- /**
147
- * A node's `TableProps`, or `undefined` for any other island and for a payload of the wrong shape:
148
- * the boundary's guard, so a `props` that crossed the DOM is read once here. Every caller draws the
149
- * placeholder for `undefined` (`table-view.ts` §`render`).
150
- */
151
- export function tablePropsOfNode(node) {
152
- const attrs = node.attrs;
153
- return attrs.islandType === 'table' && isTableProps(attrs.props) ? attrs.props : undefined;
150
+ const { columns, rows } = props;
151
+ const ids = (v) => Array.isArray(v) && v.every((c) => typeof c === 'string');
152
+ return (ids(columns) &&
153
+ Array.isArray(rows) &&
154
+ rows.every((row) => typeof row === 'object' &&
155
+ row !== null &&
156
+ typeof row.id === 'string' &&
157
+ typeof row.cells === 'object' &&
158
+ row.cells !== null));
154
159
  }
155
160
  /**
156
161
  * A minter over one document: the positional `isl-{n}` sequence continued past the highest id the
@@ -161,7 +166,7 @@ export function tablePropsOfNode(node) {
161
166
  * Reads the PM doc rather than stored content because that is what the caller holds and the commit
162
167
  * will project; a stale content could collide with an id the same transaction places.
163
168
  */
164
- export function islandMinter(doc) {
169
+ function islandMinter(doc) {
165
170
  return islandState(doc).mint;
166
171
  }
167
172
  /**
@@ -1,6 +1,3 @@
1
1
  import type { Schema } from 'prosemirror-model';
2
2
  import type { Command } from 'prosemirror-state';
3
- /** The items the selection stands in, in the innermost list holding all of them, moved
4
- * one place up (`-1`) or down (`1`). */
5
- export declare function moveItems(dir: -1 | 1): Command;
6
3
  export declare function listMoveKeymap(schema: Schema): Record<string, Command>;
@@ -1,7 +1,7 @@
1
- const isList = (node) => node.type.name === 'ordered_list' || node.type.name === 'bullet_list';
1
+ import { isList } from './list-node.js';
2
2
  /** The items the selection stands in, in the innermost list holding all of them, moved
3
3
  * one place up (`-1`) or down (`1`). */
4
- export function moveItems(dir) {
4
+ function moveItems(dir) {
5
5
  return (state, dispatch) => {
6
6
  const { $from, $to } = state.selection;
7
7
  const range = $from.blockRange($to, isList);
@@ -0,0 +1,2 @@
1
+ import type { Node as PMNode } from 'prosemirror-model';
2
+ export declare const isList: (node: PMNode | null | undefined) => node is PMNode;
@@ -0,0 +1 @@
1
+ export const isList = (node) => !!node && (node.type.name === 'ordered_list' || node.type.name === 'bullet_list');
@@ -11,7 +11,7 @@
11
11
  // out of, and paragraphs pasted into a numbered line are numbered lines.
12
12
  import { Fragment, Slice } from 'prosemirror-model';
13
13
  import { Plugin, Selection } from 'prosemirror-state';
14
- const isList = (node) => !!node && (node.type.name === 'ordered_list' || node.type.name === 'bullet_list');
14
+ import { isList } from './list-node.js';
15
15
  /** The one list a slice is, if it is one: whole, or open where a run of its items was
16
16
  * copied. */
17
17
  function soleList(slice) {
@@ -1,13 +1,4 @@
1
1
  import { Plugin } from 'prosemirror-state';
2
- /**
3
- * `text` with every item line spelled as markdown, where some line marks its item as
4
- * markdown does not; otherwise `text` as it stands. A line's level is the open one of its
5
- * kind at its indent, give or take a column, the levels below it closing; a marker no open
6
- * level holds opens one beneath the deepest. Markdown nests by indent alone, so each line
7
- * is indented past the markers of the levels above it. A letter's ordinal is its place in
8
- * the alphabet. Lines in a fence and lines opening no item stand as they are.
9
- */
10
- export declare function plainTextList(text: string): string;
11
2
  /**
12
3
  * A block leaf's markdown paste, consulted after the table paste: ProseMirror hands text
13
4
  * over only where the clipboard holds no HTML, whose DOM parse reads the source's own
@@ -40,7 +40,7 @@ const BLOCK_HEAD = new RegExp([
40
40
  * is indented past the markers of the levels above it. A letter's ordinal is its place in
41
41
  * the alphabet. Lines in a fence and lines opening no item stand as they are.
42
42
  */
43
- export function plainTextList(text) {
43
+ function plainTextList(text) {
44
44
  if (!LOOSE_ITEM.test(text))
45
45
  return text;
46
46
  const levels = [];
@@ -1,9 +1,7 @@
1
1
  import type { Mark, Schema } from 'prosemirror-model';
2
2
  import type { ContentMark, ContentMarkKind } from '@quillmark/wasm';
3
- /** A PM mark from a content formatting mark, or `null` for an anchor, which no PM mark
4
- * draws (`field.ts` holds it as a decoration). Exhaustive over
5
- * the closed mark vocabulary, so a member added upstream is a compile error here rather
6
- * than an index into a PM mark this schema does not declare. */
3
+ /** A PM mark from a content formatting mark, or `null` where the schema declares none for it. An
4
+ * `x-` type rides `ext`. */
7
5
  export declare function pmMarkFromContent(schema: Schema, m: ContentMark): Mark | null;
8
6
  /**
9
7
  * A content mark descriptor from a PM mark (range-free): the `{ type, … }` half
@@ -14,29 +12,25 @@ export declare function pmMarkFromContent(schema: Schema, m: ContentMark): Mark
14
12
  export declare function contentDescriptorFromPM(mark: Mark): ContentMarkKind;
15
13
  /**
16
14
  * The range-free `{ type, … }` half of a content mark: `contentDescriptorFromPM`'s
17
- * content-side twin, and what a `MarkOp` carries beside its range. Lifted off the
15
+ * content-side twin, and what a splice's mark carries beside its range. Lifted off the
18
16
  * range envelope rather than rebuilt arm by arm, so a payload crosses whole and an
19
17
  * arm added upstream reaches this by construction.
20
18
  */
21
19
  export declare function descriptorOf(m: ContentMark): ContentMarkKind;
22
20
  /**
23
- * A stable grouping key for the mark diff: marks sharing a key union into one
24
- * coverage set. Payload-free formatting keys on its type, everything else on
25
- * type+attrs, because `applyChange`'s `remove` matches type and attrs (verified),
26
- * so two links differing in url are independent mark families. This is the seam's
27
- * own `(type, attrs)` tie-break, which is why no arm needs a case of its own.
21
+ * A stable grouping key for marks: marks sharing a key union into one coverage set.
22
+ * Payload-free formatting keys on its type, everything else on type+attrs, so two
23
+ * links differing in url are independent mark families: the store's own `(type,
24
+ * attrs)` union rule, which is why no arm needs a case of its own.
28
25
  */
29
26
  export declare function markKey(descriptor: ContentMarkKind): string;
30
- /** A held anchor position: an identity id at a USV content offset (zero-width). */
27
+ /** A held anchor: an identity id over `[start, end)` content offsets, a point where they meet. */
31
28
  export interface AnchorPos {
32
29
  id: string;
33
- pos: number;
30
+ start: number;
31
+ end: number;
34
32
  }
35
- /**
36
- * The identity anchors of a `Content` as `{ id, pos }` in USV: the seed for the
37
- * field's anchor-position plugin and the `oldAnchors` the mark diff rebases.
38
- * Anchors are zero-width, so `start` is the position.
39
- */
33
+ /** The identity anchors of a `Content`: the seed for the field's anchor plugin. */
40
34
  export declare function anchorsFromContent(rt: {
41
- marks: ContentMark[];
35
+ anchors?: AnchorPos[];
42
36
  }): AnchorPos[];
@@ -1,12 +1,8 @@
1
1
  import { canonicalJson } from './reconcile.js';
2
- /** A PM mark from a content formatting mark, or `null` for an anchor, which no PM mark
3
- * draws (`field.ts` holds it as a decoration). Exhaustive over
4
- * the closed mark vocabulary, so a member added upstream is a compile error here rather
5
- * than an index into a PM mark this schema does not declare. */
2
+ /** A PM mark from a content formatting mark, or `null` where the schema declares none for it. An
3
+ * `x-` type rides `ext`. */
6
4
  export function pmMarkFromContent(schema, m) {
7
5
  switch (m.type) {
8
- case 'anchor':
9
- return null;
10
6
  case 'font_family':
11
7
  return schema.marks.font_family.create({ name: m.attrs.name });
12
8
  case 'emph':
@@ -18,10 +14,8 @@ export function pmMarkFromContent(schema, m) {
18
14
  case 'strike':
19
15
  case 'code':
20
16
  return schema.marks[m.type].create();
21
- default: {
22
- const unreached = m;
23
- return unreached;
24
- }
17
+ default:
18
+ return schema.marks.ext?.create({ type: m.type, attrs: m.attrs ?? null }) ?? null;
25
19
  }
26
20
  }
27
21
  /**
@@ -38,11 +32,16 @@ export function contentDescriptorFromPM(mark) {
38
32
  return { type: 'link', attrs: { url: mark.attrs.href } };
39
33
  if (name === 'font_family')
40
34
  return { type: 'font_family', attrs: { name: mark.attrs.name } };
35
+ if (name === 'ext') {
36
+ const type = mark.attrs.type;
37
+ const attrs = mark.attrs.attrs;
38
+ return attrs && Object.keys(attrs).length ? { type, attrs } : { type };
39
+ }
41
40
  return { type: name };
42
41
  }
43
42
  /**
44
43
  * The range-free `{ type, … }` half of a content mark: `contentDescriptorFromPM`'s
45
- * content-side twin, and what a `MarkOp` carries beside its range. Lifted off the
44
+ * content-side twin, and what a splice's mark carries beside its range. Lifted off the
46
45
  * range envelope rather than rebuilt arm by arm, so a payload crosses whole and an
47
46
  * arm added upstream reaches this by construction.
48
47
  */
@@ -51,26 +50,17 @@ export function descriptorOf(m) {
51
50
  return kind;
52
51
  }
53
52
  /**
54
- * A stable grouping key for the mark diff: marks sharing a key union into one
55
- * coverage set. Payload-free formatting keys on its type, everything else on
56
- * type+attrs, because `applyChange`'s `remove` matches type and attrs (verified),
57
- * so two links differing in url are independent mark families. This is the seam's
58
- * own `(type, attrs)` tie-break, which is why no arm needs a case of its own.
53
+ * A stable grouping key for marks: marks sharing a key union into one coverage set.
54
+ * Payload-free formatting keys on its type, everything else on type+attrs, so two
55
+ * links differing in url are independent mark families: the store's own `(type,
56
+ * attrs)` union rule, which is why no arm needs a case of its own.
59
57
  */
60
58
  export function markKey(descriptor) {
61
59
  if ('attrs' in descriptor)
62
60
  return `${descriptor.type}\u0000${canonicalJson(descriptor.attrs)}`;
63
61
  return descriptor.type;
64
62
  }
65
- /**
66
- * The identity anchors of a `Content` as `{ id, pos }` in USV: the seed for the
67
- * field's anchor-position plugin and the `oldAnchors` the mark diff rebases.
68
- * Anchors are zero-width, so `start` is the position.
69
- */
63
+ /** The identity anchors of a `Content`: the seed for the field's anchor plugin. */
70
64
  export function anchorsFromContent(rt) {
71
- const out = [];
72
- for (const m of rt.marks)
73
- if (m.type === 'anchor')
74
- out.push({ id: m.attrs.id, pos: m.start });
75
- return out;
65
+ return (rt.anchors ?? []).map(({ id, start, end }) => ({ id, start, end }));
76
66
  }
@@ -3,10 +3,6 @@ import { Plugin, type Transaction } from 'prosemirror-state';
3
3
  /** The store's bound on the containers around one line: a commit nesting past it is
4
4
  * refused, and `@quillmark/wasm` exports no constant to read it from. */
5
5
  export declare const MAX_NESTING_DEPTH = 12;
6
- /** The most containers any block in `doc` stands inside, counted as the store counts
7
- * them: a `list_item` or a `blockquote` is one, the list around an item none, and no
8
- * node holds an element (`decode.ts`). */
9
- export declare function nestingDepth(doc: PMNode): number;
10
6
  /** Whether `doc` nests within {@link MAX_NESTING_DEPTH}: what a command that nests asks
11
7
  * of the doc it would dispatch. */
12
8
  export declare function withinNesting(doc: PMNode): boolean;
@@ -7,7 +7,7 @@ export const MAX_NESTING_DEPTH = 12;
7
7
  /** The most containers any block in `doc` stands inside, counted as the store counts
8
8
  * them: a `list_item` or a `blockquote` is one, the list around an item none, and no
9
9
  * node holds an element (`decode.ts`). */
10
- export function nestingDepth(doc) {
10
+ function nestingDepth(doc) {
11
11
  const walk = (node, depth) => {
12
12
  let deepest = depth;
13
13
  node.forEach((child) => {
@@ -1,12 +1,14 @@
1
1
  import type { Node as PMNode } from 'prosemirror-model';
2
+ import type { Delta } from '@quillmark/wasm';
2
3
  import { type PosRun, type Scan } from './encode.js';
3
- /** A prebuilt line→position index for a PM doc, rebuilt on structural change. */
4
+ /** A prebuilt position index for a PM doc, rebuilt on structural change. */
4
5
  export interface LineIndex {
5
6
  runs: PosRun[];
6
- usvEnd: number;
7
+ /** Length of the content text. */
8
+ end: number;
7
9
  /** PM position at the end of the last content run (the caret-max). */
8
10
  pmEndContent: number;
9
- /** PM content position of the first line (the caret for an empty doc). */
11
+ /** PM content position of the first block (the caret for an empty doc). */
10
12
  firstContentStart: number;
11
13
  }
12
14
  /** Build the position index for `doc` (walks it once via the shared scanner). */
@@ -14,7 +16,12 @@ export declare function buildLineIndex(doc: PMNode): LineIndex;
14
16
  /** The index a scan's runs make. The commit path takes this one: it wants the
15
17
  * content projection off the same walk (`encode.ts`, `scanContent`). */
16
18
  export declare function lineIndexOf(s: Scan): LineIndex;
17
- /** USV content offset → PM position. */
18
- export declare function usvToPM(index: LineIndex, usvPos: number): number;
19
- /** PM position → USV content offset. */
20
- export declare function pmToUsv(index: LineIndex, pmPos: number): number;
19
+ /** Content offset → PM position. */
20
+ export declare function offsetToPM(index: LineIndex, offset: number): number;
21
+ /** PM position → content offset. */
22
+ export declare function pmToOffset(index: LineIndex, pmPos: number): number;
23
+ /**
24
+ * Where content offset `pos` lands after `delta`, its ops counting UTF-16 code units: text
25
+ * inserted at `pos` lands before it, so a caret at an edit's edge follows the text typed there.
26
+ */
27
+ export declare function mapThroughDelta(delta: Delta, pos: number): number;
@@ -15,7 +15,7 @@ export function lineIndexOf(s) {
15
15
  const last = runs[runs.length - 1];
16
16
  pmEndContent = runEndPm(last);
17
17
  }
18
- return { runs, usvEnd: s.usvEnd, pmEndContent, firstContentStart };
18
+ return { runs, end: s.text.length, pmEndContent, firstContentStart };
19
19
  }
20
20
  /** PM position just past a run (its exclusive end). */
21
21
  function runEndPm(run) {
@@ -25,13 +25,13 @@ function runEndPm(run) {
25
25
  return run.pmEnd;
26
26
  return run.pmStart + 1;
27
27
  }
28
- const usvStartOf = (run) => run.usvStart;
28
+ const atOf = (run) => run.at;
29
29
  const pmStartOf = (run) => run.pmStart;
30
30
  /**
31
31
  * Index of the last run whose `coord` is ≤ `pos`, or `-1` when `pos` precedes the
32
32
  * first run. The walk emits runs in document order and every run owns at least one
33
33
  * position in each space, so both coordinates increase strictly across the list and
34
- * the lookup bisects. Bulk conversion is what wants it: `readAnchorsUsv` converts
34
+ * the lookup bisects. Bulk conversion is what wants it: `readAnchors` converts
35
35
  * once per anchor on every commit, and a scan would make that O(anchors × runs).
36
36
  */
37
37
  function lastRunAtOrBefore(runs, pos, coord) {
@@ -50,63 +50,56 @@ function lastRunAtOrBefore(runs, pos, coord) {
50
50
  }
51
51
  return found;
52
52
  }
53
- /** USV content offset → PM position. */
54
- export function usvToPM(index, usvPos) {
55
- const usv = clamp(usvPos, 0, index.usvEnd);
56
- if (usv >= index.usvEnd)
57
- return index.usvEnd === 0 ? index.firstContentStart : index.pmEndContent;
58
- // The runs tile the USV space from 0 (every text the walk appends pushes its run
59
- // first), so below `usvEnd` the run at or before `usv` is the run that owns it.
60
- const run = index.runs[lastRunAtOrBefore(index.runs, usv, usvStartOf)];
53
+ /** Content offset → PM position. */
54
+ export function offsetToPM(index, offset) {
55
+ const at = clamp(offset, 0, index.end);
56
+ if (at >= index.end)
57
+ return index.end === 0 ? index.firstContentStart : index.pmEndContent;
58
+ // The runs tile the content from 0 (every text the walk appends pushes its run first), so
59
+ // below `end` the run at or before `at` is the run that owns it.
60
+ const run = index.runs[lastRunAtOrBefore(index.runs, at, atOf)];
61
61
  if (run.kind === 'text')
62
- return run.pmStart + utf16OfCodePoints(run.s, usv - run.usvStart);
62
+ return run.pmStart + (at - run.at);
63
63
  return run.pmStart; // nl / atom: the run's single owned position
64
64
  }
65
- /** PM position → USV content offset. */
66
- export function pmToUsv(index, pmPos) {
65
+ /** PM position → content offset. */
66
+ export function pmToOffset(index, pmPos) {
67
67
  const i = lastRunAtOrBefore(index.runs, pmPos, pmStartOf);
68
68
  if (i < 0)
69
69
  return 0; // before the first run's PM position (or no runs at all)
70
70
  const run = index.runs[i];
71
- // PM coverage, unlike USV, has gaps no run owns (a rule's own token). A position
72
- // in one is past every run that could answer it → the end of the content text.
71
+ // PM coverage has gaps no run owns (a rule's own token). A position in one is past every run
72
+ // that could answer it → the end of the content text.
73
73
  if (pmPos >= runEndPm(run))
74
- return index.usvEnd;
74
+ return index.end;
75
75
  if (run.kind === 'text')
76
- return run.usvStart + codePointsOfUtf16(run.s, pmPos - run.pmStart);
77
- return run.usvStart;
78
- }
79
- // ── UTF-16 ↔ USV conversions within one text run ────────────────────────────
80
- /** UTF-16 length of the first `n` code points of `s`. */
81
- function utf16OfCodePoints(s, n) {
82
- let cp = 0;
83
- let i = 0;
84
- while (cp < n && i < s.length) {
85
- i += charUnitLen(s, i);
86
- cp++;
87
- }
88
- return i;
89
- }
90
- /** Number of whole code points within the first `k` UTF-16 units of `s`. */
91
- function codePointsOfUtf16(s, k) {
92
- let cp = 0;
93
- let i = 0;
94
- while (i < k && i < s.length) {
95
- i += charUnitLen(s, i);
96
- cp++;
97
- }
98
- return cp;
99
- }
100
- /** UTF-16 unit length (1 or 2) of the code point starting at `i`. */
101
- function charUnitLen(s, i) {
102
- const code = s.charCodeAt(i);
103
- if (code >= 0xd800 && code <= 0xdbff && i + 1 < s.length) {
104
- const next = s.charCodeAt(i + 1);
105
- if (next >= 0xdc00 && next <= 0xdfff)
106
- return 2;
107
- }
108
- return 1;
76
+ return run.at + (pmPos - run.pmStart);
77
+ return run.at;
109
78
  }
110
79
  function clamp(n, lo, hi) {
111
80
  return n < lo ? lo : n > hi ? hi : n;
112
81
  }
82
+ /**
83
+ * Where content offset `pos` lands after `delta`, its ops counting UTF-16 code units: text
84
+ * inserted at `pos` lands before it, so a caret at an edit's edge follows the text typed there.
85
+ */
86
+ export function mapThroughDelta(delta, pos) {
87
+ let at = 0;
88
+ let out = pos;
89
+ for (const op of delta.ops) {
90
+ if (at > pos)
91
+ break;
92
+ if ('retain' in op)
93
+ at += op.retain;
94
+ else if ('insert' in op)
95
+ out += op.insert.length;
96
+ else {
97
+ const gone = Math.min(op.delete, Math.max(0, pos - at));
98
+ out -= gone;
99
+ if (pos < at + op.delete)
100
+ break;
101
+ at += op.delete;
102
+ }
103
+ }
104
+ return out;
105
+ }
@@ -68,7 +68,7 @@ li.ProseMirror-selectednode::after {
68
68
  blank line that doubles the leading and makes a short document read as a list of
69
69
  fragments. */
70
70
  .ProseMirror > * + *,
71
- .ProseMirror :is(blockquote, [data-qm-unknown-container]) > * + * {
71
+ .ProseMirror blockquote > * + * {
72
72
  margin-top: var(--_qm-space-3);
73
73
  }
74
74
 
@@ -0,0 +1,14 @@
1
+ import type { EditorView } from 'prosemirror-view';
2
+ type Sides = {
3
+ top: number;
4
+ right: number;
5
+ bottom: number;
6
+ left: number;
7
+ };
8
+ export interface RevealProps {
9
+ scrollThreshold: Sides;
10
+ scrollMargin: Sides;
11
+ handleScrollToSelection: (view: EditorView) => boolean;
12
+ }
13
+ export declare function revealProps(clearance: number | undefined): RevealProps;
14
+ export {};
@@ -0,0 +1,40 @@
1
+ function padding(value, extent) {
2
+ const n = Number.parseFloat(value);
3
+ if (!Number.isFinite(n))
4
+ return 0;
5
+ return value.endsWith('%') ? (n / 100) * extent : n;
6
+ }
7
+ function scrollInset(dom) {
8
+ const inset = { top: 0, bottom: 0 };
9
+ const view = dom.ownerDocument.defaultView;
10
+ if (!view)
11
+ return inset;
12
+ for (let el = dom.parentElement; el; el = el.parentElement) {
13
+ const style = view.getComputedStyle(el);
14
+ const extent = el === dom.ownerDocument.documentElement ? view.innerHeight : el.clientHeight;
15
+ inset.top = Math.max(inset.top, padding(style.scrollPaddingTop, extent));
16
+ inset.bottom = Math.max(inset.bottom, padding(style.scrollPaddingBottom, extent));
17
+ }
18
+ return inset;
19
+ }
20
+ export function revealProps(clearance) {
21
+ let inset = { top: 0, bottom: 0 };
22
+ const sides = (base) => ({
23
+ get top() {
24
+ return base + inset.top;
25
+ },
26
+ right: base,
27
+ get bottom() {
28
+ return base + inset.bottom;
29
+ },
30
+ left: base
31
+ });
32
+ return {
33
+ scrollThreshold: sides(clearance ?? 0),
34
+ scrollMargin: sides(clearance ?? 5),
35
+ handleScrollToSelection: (view) => {
36
+ inset = scrollInset(view.dom);
37
+ return false;
38
+ }
39
+ };
40
+ }