@quillmark/svelte 0.33.0 → 0.34.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 (98) hide show
  1. package/README.md +73 -1
  2. package/THEMING.md +11 -10
  3. package/dist/core/codec/anchor.d.ts +12 -0
  4. package/dist/core/codec/anchor.js +39 -0
  5. package/dist/core/codec/drag-move.d.ts +11 -0
  6. package/dist/core/codec/drag-move.js +143 -0
  7. package/dist/core/codec/encode.js +14 -5
  8. package/dist/core/codec/field.d.ts +47 -1
  9. package/dist/core/codec/field.js +147 -38
  10. package/dist/core/codec/index.d.ts +8 -2
  11. package/dist/core/codec/index.js +9 -2
  12. package/dist/core/codec/islands.d.ts +4 -1
  13. package/dist/core/codec/islands.js +6 -0
  14. package/dist/core/codec/keymap.d.ts +3 -0
  15. package/dist/core/codec/keymap.js +13 -12
  16. package/dist/core/codec/leave.d.ts +17 -0
  17. package/dist/core/codec/leave.js +78 -0
  18. package/dist/core/codec/prose.css +217 -0
  19. package/dist/core/codec/review-diff.d.ts +12 -0
  20. package/dist/core/codec/review-diff.js +131 -0
  21. package/dist/core/codec/review.d.ts +131 -0
  22. package/dist/core/codec/review.js +1077 -0
  23. package/dist/core/codec/shortcuts.d.ts +20 -4
  24. package/dist/core/codec/shortcuts.js +27 -7
  25. package/dist/core/codec/slash.d.ts +3 -0
  26. package/dist/core/codec/slash.js +2 -1
  27. package/dist/core/codec/table-view.js +163 -25
  28. package/dist/core/codec/undo.d.ts +6 -0
  29. package/dist/core/codec/undo.js +25 -2
  30. package/dist/core/dragfollow.d.ts +18 -0
  31. package/dist/core/dragfollow.js +63 -0
  32. package/dist/core/theme.css +36 -7
  33. package/dist/preview/controller.js +16 -0
  34. package/dist/preview/strings.d.ts +4 -0
  35. package/dist/preview/strings.js +3 -1
  36. package/dist/visual/ArrayField.svelte +363 -57
  37. package/dist/visual/ArrayField.svelte.d.ts +5 -0
  38. package/dist/visual/BooleanField.svelte +60 -5
  39. package/dist/visual/BooleanField.svelte.d.ts +2 -1
  40. package/dist/visual/Card.svelte +27 -17
  41. package/dist/visual/CardControls.svelte +17 -7
  42. package/dist/visual/CardControls.svelte.d.ts +2 -0
  43. package/dist/visual/DateField.svelte +90 -39
  44. package/dist/visual/DateField.svelte.d.ts +2 -2
  45. package/dist/visual/Field.svelte +126 -6
  46. package/dist/visual/FieldHint.svelte +24 -9
  47. package/dist/visual/FieldLabel.svelte +128 -22
  48. package/dist/visual/FieldLabel.svelte.d.ts +9 -0
  49. package/dist/visual/FormatPopover.svelte +125 -20
  50. package/dist/visual/MatrixAdd.svelte +13 -6
  51. package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
  52. package/dist/visual/MatrixField.svelte +36 -8
  53. package/dist/visual/NumberField.svelte +27 -6
  54. package/dist/visual/NumberField.svelte.d.ts +3 -0
  55. package/dist/visual/ObjectField.svelte +25 -1
  56. package/dist/visual/ObjectField.svelte.d.ts +6 -0
  57. package/dist/visual/ProseField.svelte +23 -0
  58. package/dist/visual/ProseField.svelte.d.ts +3 -0
  59. package/dist/visual/ProseValue.svelte +107 -17
  60. package/dist/visual/ProseValue.svelte.d.ts +18 -4
  61. package/dist/visual/ReviewPopover.svelte +179 -0
  62. package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
  63. package/dist/visual/ReviewProposal.svelte +149 -0
  64. package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
  65. package/dist/visual/ReviewRows.svelte +68 -0
  66. package/dist/visual/ReviewRows.svelte.d.ts +11 -0
  67. package/dist/visual/SlashMenu.svelte +13 -1
  68. package/dist/visual/SlashMenu.svelte.d.ts +2 -0
  69. package/dist/visual/VisualEditor.svelte +23 -0
  70. package/dist/visual/VisualEditor.svelte.d.ts +7 -0
  71. package/dist/visual/VisualEditorInner.svelte +671 -22
  72. package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
  73. package/dist/visual/controls.css +17 -2
  74. package/dist/visual/guidance.d.ts +12 -0
  75. package/dist/visual/guidance.js +37 -2
  76. package/dist/visual/icons/nodes.d.ts +14 -2
  77. package/dist/visual/icons/nodes.js +12 -1
  78. package/dist/visual/index.d.ts +6 -0
  79. package/dist/visual/index.js +2 -0
  80. package/dist/visual/listhistory.d.ts +36 -0
  81. package/dist/visual/listhistory.js +53 -0
  82. package/dist/visual/proposals.d.ts +40 -0
  83. package/dist/visual/proposals.js +219 -0
  84. package/dist/visual/props.d.ts +35 -0
  85. package/dist/visual/removed.d.ts +20 -0
  86. package/dist/visual/removed.js +30 -0
  87. package/dist/visual/review.d.ts +170 -0
  88. package/dist/visual/review.js +269 -0
  89. package/dist/visual/review.svelte.d.ts +106 -0
  90. package/dist/visual/review.svelte.js +356 -0
  91. package/dist/visual/rowdrag.svelte.js +44 -55
  92. package/dist/visual/strings.d.ts +48 -7
  93. package/dist/visual/strings.js +32 -7
  94. package/dist/visual/structure.d.ts +5 -0
  95. package/dist/visual/structure.js +1 -1
  96. package/dist/visual/undo.svelte.d.ts +40 -7
  97. package/dist/visual/undo.svelte.js +98 -25
  98. package/package.json +1 -1
@@ -0,0 +1,170 @@
1
+ import type { PathStep } from '@quillmark/wasm';
2
+ import type { DocPath } from '../core/address.js';
3
+ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
4
+ /**
5
+ * One proposal. `id` is the host's, unique in the list, and is what every event names.
6
+ *
7
+ * An item names its place one of two ways:
8
+ *
9
+ * - `field` with `replace` or `insert`: blocks of a rich text field or a body, by the ids the
10
+ * document gives them. A `proposed` item with `replace` reads the blocks named as rewritten to
11
+ * `after`, Markdown, drawn as a word-level edit of them; `''` proposes their removal. `before`
12
+ * is those blocks as the proposal's writer read them, so what the reader wrote in them since is
13
+ * theirs: kept unstruck, and kept by Accept. One with `insert` proposes new blocks after or
14
+ * before a block, or at the field's end. A paragraph takes one proposal that rewrites it and one
15
+ * that adds after it.
16
+ * - `field` alone: the path of a field. It sets `after` under the control, the value the
17
+ * field's writer would take, an absent one proposing the field cleared, and `before` the value
18
+ * its writer read. A path to a place inside a record or a
19
+ * list names that place: a cell, or a member by its index, which `after` absent takes out
20
+ * and an index past the last appends.
21
+ *
22
+ * An item whose place the editor does not hold draws nothing. A dismissed item is drawn no more,
23
+ * and an accepted proposal the list still holds is drawn as the change it made, with the card
24
+ * that takes it back, until the list lets it go.
25
+ */
26
+ export type ReviewItem = FieldProposal | BlockProposal;
27
+ /** A proposal over blocks of a rich text field, by their ids. */
28
+ export type BlockProposal = {
29
+ id: string;
30
+ field: DocPath;
31
+ replace: readonly string[];
32
+ before?: string;
33
+ after: string;
34
+ } | {
35
+ id: string;
36
+ field: DocPath;
37
+ insert: BlockPlace;
38
+ after: string;
39
+ };
40
+ /** Whether an item names blocks of a rich text field, which its prose leaf draws. */
41
+ export declare const byBlocks: (item: object) => item is BlockProposal;
42
+ /** Whether an item is a field's own, drawn on its control: a proposal, or one accepted there. */
43
+ export declare const onField: (item: object) => item is FieldChange | FieldProposal;
44
+ /**
45
+ * A reader's answer to an item.
46
+ *
47
+ * - `accept`: a proposal taken. The editor has written it by now, as an edit of the reader's.
48
+ * - `dismiss`: a proposal turned down. Nothing is written.
49
+ * - `reopen`: an accept or a dismissal undone. The editor has taken back what an accept wrote,
50
+ * and the item is open again.
51
+ */
52
+ export interface ReviewEvent {
53
+ id: string;
54
+ action: ReviewAction;
55
+ }
56
+ /**
57
+ * Why a listed item draws nothing:
58
+ *
59
+ * - `block`: no block it names stands in its field, or no leaf of the field is mounted.
60
+ * - `field`: its path names no field the editor holds, or a place inside one its schema does
61
+ * not declare.
62
+ * - `parse`: its `after` is not Markdown the leaf holding it reads.
63
+ * - `taken`: an earlier item has its paragraph, or its field.
64
+ * - `applied`: the text already reads as proposed, so it would write nothing.
65
+ */
66
+ export type ReviewUndrawn = 'block' | 'field' | 'parse' | 'taken' | 'applied';
67
+ /** What the editor draws of the host's list. */
68
+ export interface ReviewDrawn {
69
+ /** The proposals the editor draws, in document order: the open ones and the accepted ones. */
70
+ order: readonly string[];
71
+ /** The proposals accepted and still listed, which the editor draws as the changes they made. */
72
+ accepted: readonly string[];
73
+ /** The drawn items still waiting for an answer, in document order: the rest of `order`. A
74
+ * review is answered when it is empty. */
75
+ open: readonly string[];
76
+ /** Drawn proposals the reader's own writing meets: words both changed, a block one names
77
+ * gone or no longer what its writer read, or a field no longer holding its `before`. */
78
+ outdated: readonly string[];
79
+ /** Listed items the editor does not draw, each with why. */
80
+ undrawn: readonly {
81
+ id: string;
82
+ reason: ReviewUndrawn;
83
+ }[];
84
+ }
85
+ /** A field proposal accepted, as the change it made over its control, `before` the value it
86
+ * replaced. The editor's own, tagged as it takes the accept; a host lists proposals alone. */
87
+ export type FieldChange = {
88
+ id: string;
89
+ state: 'changed';
90
+ field: DocPath;
91
+ before?: unknown;
92
+ };
93
+ /** Whether an item is an accepted proposal the editor holds, rather than one the host lists. */
94
+ export declare const isChange: <T extends object>(item: T) => item is Extract<T, {
95
+ state: "changed";
96
+ }>;
97
+ /** A proposal under a field's control. */
98
+ export type FieldProposal = {
99
+ id: string;
100
+ field: DocPath;
101
+ before?: unknown;
102
+ after?: unknown;
103
+ };
104
+ /** A field item routed past its field: the steps from the rung it is handed to down to the
105
+ * value it names, a member of a list by its index, a cell of a record by its key. */
106
+ export interface DeepReview {
107
+ steps: readonly PathStep[];
108
+ item: FieldProposal | FieldChange;
109
+ }
110
+ /** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
111
+ * the step they take next, that step consumed. */
112
+ export declare function splitReview(list: readonly DeepReview[] | undefined): {
113
+ here: DeepReview[];
114
+ below: Map<PathStep, DeepReview[]>;
115
+ };
116
+ /** The value `steps` reach in `value`, `undefined` where they reach nothing. */
117
+ export declare function valueIn(value: unknown, steps: readonly PathStep[]): unknown;
118
+ /** `value` with what `steps` reach set to `to`: a list's member past its end appended, and one
119
+ * set to nothing taken out; a record's cell set to nothing left out. Copies on the way down. */
120
+ export declare function valueWith(value: unknown, steps: readonly PathStep[], to: unknown): unknown;
121
+ /** The members that stood either side of the one `steps` reach in `value`, which put it back. */
122
+ export interface Beside {
123
+ before?: {
124
+ member: unknown;
125
+ };
126
+ after?: {
127
+ member: unknown;
128
+ };
129
+ }
130
+ /** The members either side of the one `steps` reach in `value`. */
131
+ export declare function besideOf(value: unknown, steps: readonly PathStep[]): Beside;
132
+ /**
133
+ * `value` with a member put back at `steps`, the ones from it on moving down one: after the
134
+ * member that stood before it, else before the one that stood after it, the nearest of each to
135
+ * the index, so members put back in any order land where they stood; at the index where
136
+ * neither stands.
137
+ */
138
+ export declare function valueWithInserted(value: unknown, steps: readonly PathStep[], member: unknown, beside?: Beside): unknown;
139
+ /**
140
+ * Where a field proposal's steps land in `value` as it stands. A list's member is found by its
141
+ * index where it holds `before`, else as the nearest member holding `before` that `claimed`
142
+ * does not already hold, so one member taken out does not move another's proposal onto the
143
+ * wrong row. `found` is false where the proposal has a `before` nothing holds.
144
+ */
145
+ export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal | FieldChange, claimed: Set<string>): {
146
+ steps: readonly PathStep[];
147
+ found: boolean;
148
+ };
149
+ /** Whether two values are one, whatever order their keys stand in; absent is `null`, and a
150
+ * plain text value rests as its words, as a writer takes it either way. */
151
+ export declare function sameValue(a: unknown, b: unknown): boolean;
152
+ /** A reviewed value as the words a reader is shown for it: a string as written, a rich text
153
+ * value by its text, a list by its members, a subform by its named cells. `''` for nothing. */
154
+ export declare function reviewText(value: unknown, words: {
155
+ on: string;
156
+ off: string;
157
+ }): string;
158
+ /** A stretch of a proposal as a reader is shown it: kept, struck, or tinted. */
159
+ export interface ReviewRun {
160
+ text: string;
161
+ kind?: 'del' | 'ins';
162
+ }
163
+ type Words = {
164
+ on: string;
165
+ off: string;
166
+ };
167
+ /** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
168
+ * two lists by their members, two records by their keys; any other pair differs whole. */
169
+ export declare function reviewRuns(before: unknown, after: unknown, words: Words): ReviewRun[];
170
+ export {};
@@ -0,0 +1,269 @@
1
+ import { wordDiff } from '../core/codec/index.js';
2
+ /** Whether an item names blocks of a rich text field, which its prose leaf draws. */
3
+ export const byBlocks = (item) => 'replace' in item || 'insert' in item;
4
+ /** Whether an item is a field's own, drawn on its control: a proposal, or one accepted there. */
5
+ export const onField = (item) => 'field' in item && !byBlocks(item);
6
+ /** Whether an item is an accepted proposal the editor holds, rather than one the host lists. */
7
+ export const isChange = (item) => 'state' in item && item.state === 'changed';
8
+ /** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
9
+ * the step they take next, that step consumed. */
10
+ export function splitReview(list) {
11
+ const here = [];
12
+ const below = new Map();
13
+ for (const entry of list ?? []) {
14
+ if (!entry.steps.length) {
15
+ here.push(entry);
16
+ continue;
17
+ }
18
+ const [step, ...steps] = entry.steps;
19
+ const bucket = below.get(step) ?? [];
20
+ bucket.push({ steps, item: entry.item });
21
+ below.set(step, bucket);
22
+ }
23
+ return { here, below };
24
+ }
25
+ /** The value `steps` reach in `value`, `undefined` where they reach nothing. */
26
+ export function valueIn(value, steps) {
27
+ let at = value;
28
+ for (const step of steps) {
29
+ if (at == null || typeof at !== 'object')
30
+ return undefined;
31
+ at = at[step];
32
+ }
33
+ return at;
34
+ }
35
+ /** `value` with what `steps` reach set to `to`: a list's member past its end appended, and one
36
+ * set to nothing taken out; a record's cell set to nothing left out. Copies on the way down. */
37
+ export function valueWith(value, steps, to) {
38
+ if (!steps.length)
39
+ return to;
40
+ const [step, ...rest] = steps;
41
+ if (typeof step === 'number') {
42
+ const list = Array.isArray(value) ? [...value] : [];
43
+ const at = Math.min(step, list.length);
44
+ const next = valueWith(list[at], rest, to);
45
+ if (!rest.length && to === undefined)
46
+ list.splice(at, 1);
47
+ else if (step >= list.length)
48
+ list.push(next);
49
+ else
50
+ list[at] = next;
51
+ return list;
52
+ }
53
+ const record = value && typeof value === 'object' && !Array.isArray(value) ? { ...value } : {};
54
+ const next = valueWith(record[step], rest, to);
55
+ if (next === undefined)
56
+ delete record[step];
57
+ else
58
+ record[step] = next;
59
+ return record;
60
+ }
61
+ /** The members either side of the one `steps` reach in `value`. */
62
+ export function besideOf(value, steps) {
63
+ const at = steps.at(-1);
64
+ const list = valueIn(value, steps.slice(0, -1));
65
+ if (typeof at !== 'number' || !Array.isArray(list))
66
+ return {};
67
+ return {
68
+ ...(at > 0 && at - 1 < list.length && { before: { member: list[at - 1] } }),
69
+ ...(at + 1 < list.length && { after: { member: list[at + 1] } })
70
+ };
71
+ }
72
+ /**
73
+ * `value` with a member put back at `steps`, the ones from it on moving down one: after the
74
+ * member that stood before it, else before the one that stood after it, the nearest of each to
75
+ * the index, so members put back in any order land where they stood; at the index where
76
+ * neither stands.
77
+ */
78
+ export function valueWithInserted(value, steps, member, beside = {}) {
79
+ const head = steps.slice(0, -1);
80
+ const at = steps.at(-1);
81
+ const list = valueIn(value, head);
82
+ if (typeof at !== 'number' || !Array.isArray(list))
83
+ return valueWith(value, steps, member);
84
+ const nearest = (near, to) => {
85
+ if (!near)
86
+ return undefined;
87
+ let found;
88
+ list.forEach((m, i) => {
89
+ if (sameValue(m, near.member) &&
90
+ (found === undefined || Math.abs(i - to) < Math.abs(found - to)))
91
+ found = i;
92
+ });
93
+ return found;
94
+ };
95
+ const after = nearest(beside.before, at - 1);
96
+ const before = after === undefined ? nearest(beside.after, at) : undefined;
97
+ const next = [...list];
98
+ next.splice(after !== undefined ? after + 1 : (before ?? Math.min(at, next.length)), 0, member);
99
+ return valueWith(value, head, next);
100
+ }
101
+ /**
102
+ * Where a field proposal's steps land in `value` as it stands. A list's member is found by its
103
+ * index where it holds `before`, else as the nearest member holding `before` that `claimed`
104
+ * does not already hold, so one member taken out does not move another's proposal onto the
105
+ * wrong row. `found` is false where the proposal has a `before` nothing holds.
106
+ */
107
+ export function locate(value, steps, item, claimed) {
108
+ const read = !isChange(item) && 'before' in item;
109
+ const before = read ? item.before : undefined;
110
+ const at = steps.at(-1);
111
+ const head = steps.slice(0, -1);
112
+ const list = valueIn(value, head);
113
+ const claim = (out) => {
114
+ claimed.add(JSON.stringify(out));
115
+ return out;
116
+ };
117
+ if (!read || before === undefined || typeof at !== 'number' || !Array.isArray(list)) {
118
+ const found = !read || sameValue(valueIn(value, steps), before);
119
+ return { steps: claim(steps), found };
120
+ }
121
+ const free = (i) => sameValue(list[i], before) && !claimed.has(JSON.stringify([...head, i]));
122
+ if (free(at))
123
+ return { steps: claim(steps), found: true };
124
+ for (let d = 1; d < list.length; d++)
125
+ for (const i of [at - d, at + d])
126
+ if (i >= 0 && i < list.length && free(i))
127
+ return { steps: claim([...head, i]), found: true };
128
+ return { steps, found: false };
129
+ }
130
+ /** Whether two values are one, whatever order their keys stand in; absent is `null`, and a
131
+ * plain text value rests as its words, as a writer takes it either way. */
132
+ export function sameValue(a, b) {
133
+ const canonical = (value) => JSON.stringify(value ?? null, (_, v) => {
134
+ if (!v || typeof v !== 'object' || Array.isArray(v))
135
+ return v;
136
+ const { text, codec } = v;
137
+ if (codec === 'plain' && typeof text === 'string')
138
+ return text;
139
+ return Object.fromEntries(Object.entries(v).sort(([x], [y]) => (x < y ? -1 : x > y ? 1 : 0)));
140
+ });
141
+ return canonical(a) === canonical(b);
142
+ }
143
+ /** A reviewed value as the words a reader is shown for it: a string as written, a rich text
144
+ * value by its text, a list by its members, a subform by its named cells. `''` for nothing. */
145
+ export function reviewText(value, words) {
146
+ if (value == null)
147
+ return '';
148
+ if (typeof value === 'boolean')
149
+ return value ? words.on : words.off;
150
+ if (typeof value !== 'object')
151
+ return String(value);
152
+ if (Array.isArray(value))
153
+ return value
154
+ .map((v) => reviewText(v, words))
155
+ .filter(Boolean)
156
+ .join(', ');
157
+ const text = value.text;
158
+ if (typeof text === 'string' && Array.isArray(value.blocks))
159
+ return text;
160
+ return Object.entries(value)
161
+ .map(([key, v]) => [key, reviewText(v, words)])
162
+ .filter(([, v]) => v)
163
+ .map(([key, v]) => `${key}: ${v}`)
164
+ .join('; ');
165
+ }
166
+ const prose = (v) => typeof v === 'string' || (typeof v === 'object' && v !== null && 'text' in v);
167
+ const record = (v) => typeof v === 'object' && v !== null && !Array.isArray(v) && !prose(v);
168
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
169
+ function whole(before, after) {
170
+ return [
171
+ ...(before ? [{ text: before, kind: 'del' }] : []),
172
+ ...(after ? [{ text: after, kind: 'ins' }] : [])
173
+ ];
174
+ }
175
+ function joined(parts, by) {
176
+ return parts.filter((p) => p.length).flatMap((p, i) => (i ? [{ text: by }, ...p] : p));
177
+ }
178
+ /** The keys of two records that differ, each as `key: ` with what goes struck and what comes
179
+ * tinted. */
180
+ function recordRuns(before, after, words) {
181
+ const keys = [...new Set([...Object.keys(after), ...Object.keys(before)])];
182
+ return joined(keys
183
+ .filter((key) => !same(before[key], after[key]))
184
+ .map((key) => {
185
+ const runs = whole(reviewText(before[key], words), reviewText(after[key], words));
186
+ return runs.length ? [{ text: `${key}: ` }, ...runs] : [];
187
+ }), '; ');
188
+ }
189
+ /** Two lists by their members, in order: a member both hold is kept, one only `before` holds is
190
+ * struck, one only `after` holds is tinted. In a list of records a kept record is left out, and a
191
+ * record struck where one is tinted reads as the keys the two differ in. */
192
+ function listRuns(before, after, words) {
193
+ const n = before.length;
194
+ const m = after.length;
195
+ const common = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
196
+ for (let i = n - 1; i >= 0; i--)
197
+ for (let j = m - 1; j >= 0; j--)
198
+ common[i][j] = same(before[i], after[j])
199
+ ? common[i + 1][j + 1] + 1
200
+ : Math.max(common[i + 1][j], common[i][j + 1]);
201
+ const records = [...before, ...after].some(record);
202
+ /** A record edited in place, named by its first value where that stays, so a reader can tell
203
+ * which of the list it is with the records kept left out. */
204
+ const edited = (was, now) => {
205
+ const first = Object.keys(now)[0];
206
+ const name = first !== undefined && same(was[first], now[first]) && reviewText(now[first], words);
207
+ const runs = recordRuns(was, now, words);
208
+ return name ? [{ text: `${name} (` }, ...runs, { text: ')' }] : runs;
209
+ };
210
+ const parts = [];
211
+ let gone = [];
212
+ let come = [];
213
+ const flush = () => {
214
+ const pairs = records ? Math.min(gone.length, come.length) : 0;
215
+ for (let k = 0; k < pairs; k++)
216
+ parts.push(record(gone[k]) && record(come[k])
217
+ ? edited(gone[k], come[k])
218
+ : whole(reviewText(gone[k], words), reviewText(come[k], words)));
219
+ for (const v of gone.slice(pairs))
220
+ parts.push(whole(reviewText(v, words), ''));
221
+ for (const v of come.slice(pairs))
222
+ parts.push(whole('', reviewText(v, words)));
223
+ gone = [];
224
+ come = [];
225
+ };
226
+ let i = 0;
227
+ let j = 0;
228
+ while (i < n || j < m) {
229
+ if (i < n && j < m && same(before[i], after[j])) {
230
+ flush();
231
+ if (!records)
232
+ parts.push([{ text: reviewText(before[i], words) }]);
233
+ i++;
234
+ j++;
235
+ }
236
+ else if (j < m && (i === n || common[i][j + 1] >= common[i + 1][j]))
237
+ come.push(after[j++]);
238
+ else
239
+ gone.push(before[i++]);
240
+ }
241
+ flush();
242
+ return joined(parts, ', ');
243
+ }
244
+ /** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
245
+ * two lists by their members, two records by their keys; any other pair differs whole. */
246
+ export function reviewRuns(before, after, words) {
247
+ if (Array.isArray(before) && Array.isArray(after) && before.length && after.length)
248
+ return listRuns(before, after, words);
249
+ if (record(before) && record(after))
250
+ return recordRuns(before, after, words);
251
+ const was = reviewText(before, words);
252
+ const now = reviewText(after, words);
253
+ if (!prose(before) || !prose(after) || !was || !now)
254
+ return whole(was, now);
255
+ const out = [];
256
+ let at = 0;
257
+ for (const hunk of wordDiff(was, now)) {
258
+ if (hunk.at > at)
259
+ out.push({ text: was.slice(at, hunk.at) });
260
+ if (hunk.end > hunk.at)
261
+ out.push({ text: was.slice(hunk.at, hunk.end), kind: 'del' });
262
+ if (hunk.insert)
263
+ out.push({ text: hunk.insert, kind: 'ins' });
264
+ at = hunk.end;
265
+ }
266
+ if (at < was.length)
267
+ out.push({ text: was.slice(at) });
268
+ return out;
269
+ }
@@ -0,0 +1,106 @@
1
+ import type { PathStep } from '@quillmark/wasm';
2
+ import type { DocPath } from '../core/address.js';
3
+ import type { ReviewAction, ReviewReport, ReviewVia, TextReview } from '../core/codec/index.js';
4
+ import { type DeepReview, type FieldChange, type FieldProposal, type ReviewItem, type ReviewUndrawn } from './review.js';
5
+ /** How long the pointer or the caret rests on a change before its card rises, in ms. */
6
+ export declare const HOVER_MS = 350;
7
+ /** How long a card outlasts the pointer's leaving, in ms: the trip from the mark into the card. */
8
+ export declare const LEAVE_MS = 200;
9
+ /** How long a revealed item with no card stays lit, in ms. */
10
+ export declare const REVEAL_MS = 2400;
11
+ /** The card on show: the accepted proposal it is up for, as its change, and what raised it. */
12
+ export interface ShownReview {
13
+ item: FieldChange | TextChange;
14
+ via: ReviewVia | 'reveal';
15
+ }
16
+ /** A proposal taken in a prose leaf, as the change it made, `before` the text it replaced. */
17
+ export type TextChange = {
18
+ id: string;
19
+ state: 'changed';
20
+ before?: string;
21
+ };
22
+ export interface Review {
23
+ /** The host's list, less what was answered here. */
24
+ readonly items: readonly ReviewItem[];
25
+ /** The proposals accepted and still listed, each as the change it made. */
26
+ readonly accepted: ReadonlyMap<string, FieldChange | TextChange>;
27
+ /** The items the prose leaf at `key` draws, those placed by blocks of its own field. One
28
+ * identity until the list changes. */
29
+ textAt(key: string): readonly TextReview[];
30
+ /** Each mounted prose leaf's report of what it draws, by leaf key. */
31
+ readonly reports: ReadonlyMap<string, ReviewReport>;
32
+ /** The field items no control draws, each with why. */
33
+ readonly fieldUndrawn: readonly {
34
+ id: string;
35
+ reason: ReviewUndrawn;
36
+ }[];
37
+ /** The field proposals whose field no longer holds the value their `before` says was read. */
38
+ readonly fieldOutdated: ReadonlySet<string>;
39
+ /** The item under attention. */
40
+ readonly lit: string | undefined;
41
+ readonly shown: ShownReview | undefined;
42
+ /** The items over the field at leaf `key`: its own, and those naming a place inside it,
43
+ * each with the steps to the value it names as the field holds it now. */
44
+ at(key: string): {
45
+ changed?: FieldChange;
46
+ proposed?: FieldProposal;
47
+ nested?: readonly DeepReview[];
48
+ };
49
+ /** Whether anything draws at leaf `key`: a field's own item, or a text item in its leaf. */
50
+ marks(key: string): boolean;
51
+ /** The leaf drawing item `id`, where one does. */
52
+ keyOf(id: string): string | undefined;
53
+ /** A prose leaf's report of what it draws. */
54
+ drew(key: string, report: ReviewReport): void;
55
+ /** The item the pointer or the caret is in, from leaf `from`: a caret's leaving reported by
56
+ * a leaf the caret has already left for another is old news. */
57
+ point(id: string | undefined, via: ReviewVia, from?: string): void;
58
+ /** A reader's answer, `chord` where a key gave it. False where it could not be made. */
59
+ act(id: string, action: ReviewAction, chord?: boolean): boolean;
60
+ /** An answer leaf `key` has already given, the item listed or not: a reopen and a redo's
61
+ * accept arrive for items the host may have taken off or not yet put back. */
62
+ heard(id: string, action: ReviewAction, key: string, chord?: boolean): void;
63
+ /** A leaf is writing an answer, and is done: its edit is the answer's, not the reader's. */
64
+ writing(on: boolean): void;
65
+ /** Hold the card up while the pointer or the focus is in it, and let it go again. */
66
+ hold(): void;
67
+ release(): void;
68
+ dismiss(): void;
69
+ reveal(id: string): void;
70
+ }
71
+ export interface ReviewSource {
72
+ items(): readonly ReviewItem[] | undefined;
73
+ /** The leaf key a field path names, `undefined` for one the editor does not hold. */
74
+ keyFor(path: DocPath): string | undefined;
75
+ /** Whether a path names a field itself, and not a place inside one. */
76
+ exact(path: DocPath): boolean;
77
+ /** A path naming a place inside a field: the field's leaf key, the steps from it, and the
78
+ * value it holds. `undefined` for a place its schema does not declare. */
79
+ nested(path: DocPath): {
80
+ key: string;
81
+ steps: readonly PathStep[];
82
+ value: unknown;
83
+ } | undefined;
84
+ /** The value the field at `path` holds, as its control is handed it. */
85
+ valueAt(path: DocPath): unknown;
86
+ /** The key of the prose leaf a rich text field's or a body's path names, `undefined` for
87
+ * one the editor does not hold. */
88
+ leafFor(path: DocPath): string | undefined;
89
+ /** A reader's answer, to make and to pass on: `item` where the list holds it, `key` the
90
+ * leaf that gave it where one did. `false` where it could not be made, and the item
91
+ * stands. */
92
+ answer(id: string, item: ReviewItem | FieldChange | TextChange | undefined, action: ReviewAction, key?: string): boolean;
93
+ /** An answer a chord gave, once it is made. */
94
+ chorded?(id: string): void;
95
+ writing?(on: boolean): void;
96
+ /** The field proposals accepted here, each as the change it made. */
97
+ taken?(): ReadonlyMap<string, FieldChange>;
98
+ /** Take back what accepting `id` wrote, so it is open again. */
99
+ putBack?(id: string): boolean;
100
+ }
101
+ export declare function createReview(source: ReviewSource): Review & {
102
+ dispose(): void;
103
+ };
104
+ export declare function setReview(review: Review): void;
105
+ /** The editor's review state, or {@link NO_REVIEW} off-tree. */
106
+ export declare function review(): Review;