@quillmark/svelte 0.35.1 → 0.37.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 (82) hide show
  1. package/README.md +30 -18
  2. package/THEMING.md +1 -1
  3. package/dist/core/address.d.ts +5 -0
  4. package/dist/core/address.js +14 -0
  5. package/dist/core/codec/decode.d.ts +4 -2
  6. package/dist/core/codec/decode.js +5 -2
  7. package/dist/core/codec/field.d.ts +42 -16
  8. package/dist/core/codec/field.js +97 -28
  9. package/dist/core/codec/index.d.ts +8 -5
  10. package/dist/core/codec/index.js +4 -5
  11. package/dist/core/codec/prose.css +25 -81
  12. package/dist/core/codec/review.d.ts +31 -26
  13. package/dist/core/codec/review.js +93 -169
  14. package/dist/core/codec/schema.d.ts +12 -2
  15. package/dist/core/codec/schema.js +27 -5
  16. package/dist/core/codec/shortcuts.d.ts +5 -4
  17. package/dist/core/codec/shortcuts.js +9 -8
  18. package/dist/core/codec/table-view.js +15 -3
  19. package/dist/core/codec/value-diff.d.ts +21 -0
  20. package/dist/core/codec/value-diff.js +83 -0
  21. package/dist/core/codec/value-plan.d.ts +29 -0
  22. package/dist/core/codec/value-plan.js +157 -0
  23. package/dist/core/theme.css +46 -15
  24. package/dist/core/tooltip.css +49 -0
  25. package/dist/core/tooltip.d.ts +6 -0
  26. package/dist/core/tooltip.js +176 -0
  27. package/dist/preview/Preview.svelte +22 -1
  28. package/dist/preview/controller.js +38 -0
  29. package/dist/preview/strings.d.ts +2 -0
  30. package/dist/preview/strings.js +1 -0
  31. package/dist/visual/ArrayField.svelte +374 -96
  32. package/dist/visual/Card.svelte +33 -12
  33. package/dist/visual/Card.svelte.d.ts +3 -0
  34. package/dist/visual/CardControls.svelte +3 -3
  35. package/dist/visual/DateField.svelte +47 -5
  36. package/dist/visual/DiagnosticList.svelte +3 -2
  37. package/dist/visual/EnumField.svelte +20 -5
  38. package/dist/visual/EnumField.svelte.d.ts +5 -0
  39. package/dist/visual/Field.svelte +56 -47
  40. package/dist/visual/FieldHint.svelte +20 -8
  41. package/dist/visual/FormatPopover.svelte +54 -20
  42. package/dist/visual/MatrixField.svelte +48 -6
  43. package/dist/visual/MatrixField.svelte.d.ts +5 -0
  44. package/dist/visual/NumberField.svelte +131 -6
  45. package/dist/visual/NumberField.svelte.d.ts +5 -0
  46. package/dist/visual/ObjectField.svelte +60 -18
  47. package/dist/visual/ProseField.svelte +21 -5
  48. package/dist/visual/ProseField.svelte.d.ts +5 -1
  49. package/dist/visual/ProseValue.svelte +49 -8
  50. package/dist/visual/ProseValue.svelte.d.ts +7 -1
  51. package/dist/visual/ReviewCard.svelte +400 -0
  52. package/dist/visual/ReviewCard.svelte.d.ts +20 -0
  53. package/dist/visual/ReviewProposal.svelte +98 -138
  54. package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
  55. package/dist/visual/ReviewRows.svelte +6 -25
  56. package/dist/visual/ReviewRows.svelte.d.ts +1 -3
  57. package/dist/visual/SlashMenu.svelte +1 -0
  58. package/dist/visual/TipsCard.svelte +1 -1
  59. package/dist/visual/VariantField.svelte +45 -4
  60. package/dist/visual/VariantField.svelte.d.ts +5 -0
  61. package/dist/visual/VisualEditor.svelte +24 -9
  62. package/dist/visual/VisualEditor.svelte.d.ts +8 -1
  63. package/dist/visual/VisualEditorInner.svelte +917 -280
  64. package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
  65. package/dist/visual/controls.css +2 -2
  66. package/dist/visual/index.d.ts +2 -2
  67. package/dist/visual/proposals.d.ts +25 -24
  68. package/dist/visual/proposals.js +92 -32
  69. package/dist/visual/props.d.ts +18 -18
  70. package/dist/visual/review-order.d.ts +51 -0
  71. package/dist/visual/review-order.js +87 -0
  72. package/dist/visual/review.d.ts +94 -3
  73. package/dist/visual/review.js +37 -2
  74. package/dist/visual/review.svelte.d.ts +77 -20
  75. package/dist/visual/review.svelte.js +306 -49
  76. package/dist/visual/strings.d.ts +59 -25
  77. package/dist/visual/strings.js +90 -29
  78. package/dist/visual/structure.d.ts +17 -3
  79. package/dist/visual/structure.js +71 -5
  80. package/dist/visual/undo.svelte.d.ts +3 -1
  81. package/dist/visual/undo.svelte.js +7 -3
  82. package/package.json +2 -2
@@ -1,12 +1,15 @@
1
1
  import { type DocPath, type Landing } from '../core/address.js';
2
+ import type { Document } from '@quillmark/wasm';
2
3
  import type { VisualEditorProps } from './props.js';
3
4
  import type { Delta } from '../core/codec/positions.js';
5
+ import { type ReviewProjection } from './review.js';
4
6
  import type { CardId, CardOp } from './signals.js';
5
7
  import { type ActiveProse } from './leaves.js';
6
8
  declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
7
9
  setCaret: (at: Landing) => Promise<void>;
8
10
  getActiveLeaf: () => ActiveProse | undefined;
9
11
  focusField: (field: DocPath) => Promise<void>;
12
+ revealField: (field: DocPath) => Promise<void>;
10
13
  washField: (field: DocPath) => void;
11
14
  insertCard: (kind: string, at?: number) => CardId | undefined;
12
15
  removeCard: (cardId: CardId) => void;
@@ -18,9 +21,13 @@ declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
18
21
  revealReview: (id: string, opts?: {
19
22
  focus?: boolean;
20
23
  }) => Promise<boolean>;
21
- answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
24
+ answerReview: (ids: readonly string[] | "all" | {
25
+ group: string;
26
+ }, action: "accept" | "dismiss") => string[];
27
+ projectReview: (target: Document) => ReviewProjection;
22
28
  stepReview: (dir: 1 | -1, opts?: {
23
29
  focus?: boolean;
30
+ group?: string;
24
31
  }) => Promise<string | undefined>;
25
32
  }, "">;
26
33
  type VisualEditorInner = ReturnType<typeof VisualEditorInner>;
@@ -240,8 +240,8 @@
240
240
  :where(.qm-chip) {
241
241
  color: var(--_qm-ink-label);
242
242
  }
243
- :where(.qm-add-affordance:hover),
244
- :where(.qm-chip:hover) {
243
+ :where(.qm-add-affordance:hover:not(:disabled)),
244
+ :where(.qm-chip:hover:not(:disabled, [aria-disabled='true'])) {
245
245
  color: var(--_qm-ink);
246
246
  }
247
247
  :where(.qm-chip svg),
@@ -7,10 +7,10 @@ export type { VisualStrings, VisualStringsInput, FormatDiagnostic } from './stri
7
7
  export type { BodyPlaceholder, BodyPlaceholderContext } from './structure.js';
8
8
  export { editorShortcuts } from '../core/codec/index.js';
9
9
  export type { EditorShortcut, ShortcutScope } from '../core/codec/index.js';
10
- export type { BlockProposal, ReviewDrawn, ReviewEvent, ReviewItem, ReviewUndrawn } from './review.js';
10
+ export type { BlockProposal, CardProposal, FieldProposal, ReviewDrawn, ReviewEvent, ReviewItem, ReviewLabel, ReviewProjection, ReviewUndrawn } from './review.js';
11
11
  export type { BlockPlace } from '../core/codec/index.js';
12
12
  export { proposalsBetween } from './proposals.js';
13
- export type { CardProposal, Proposed } from './proposals.js';
13
+ export type { Proposed, ProposalsOpts } from './proposals.js';
14
14
  export type { ReviewAction } from '../core/codec/index.js';
15
15
  export { REVIEW_KEYS } from '../core/codec/index.js';
16
16
  export { patchEditorExt } from './ext.js';
@@ -1,24 +1,9 @@
1
- import type { Card, Document, Quill } from '@quillmark/wasm';
2
- import { type ReviewItem } from './review.js';
3
- /** A card the answer adds or takes out, which no item draws: a row the host answers itself. */
4
- export type CardProposal =
5
- /** `card` as the answer holds it. `after` is the id of the card it follows in the answer,
6
- * absent at the head; it can be a card added before it, so a host adds them in list order. */
7
- {
8
- type: 'add';
9
- card: Card;
10
- after?: string;
11
- }
12
- /** The base's card `id`, of `kind`. */
13
- | {
14
- type: 'remove';
15
- id: string;
16
- kind: string;
17
- };
18
- /** The review an answer makes: the items the editor draws, and the cards it adds or removes. */
1
+ import type { Document, Quill } from '@quillmark/wasm';
2
+ import { type ReviewItem, type ReviewLabel } from './review.js';
3
+ /** The review an answer makes: the items the editor draws, the cards it adds or takes out
4
+ * among them. */
19
5
  export interface Proposed {
20
6
  items: ReviewItem[];
21
- cards: CardProposal[];
22
7
  }
23
8
  /**
24
9
  * The review list from `base`, the document as the answer's writer read it, to `answer`, the
@@ -30,11 +15,27 @@ export interface Proposed {
30
15
  * per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
31
16
  * Every other field takes an item per place that changed: a record's cell, and a list's member,
32
17
  * changed, taken out, or appended past the end, two appends to one list at successive indices.
33
- * A one-line rich text field, a list that gains members anywhere but its end, a value of a type
34
- * nothing nests in, and a rich text value inside a record or a list are proposed whole. Values
18
+ * A list that gains members anywhere but its end is compared member by member at each index, so
19
+ * each place its controls draw says its own change; a record or a list written where none was is
20
+ * compared with an empty one. A choice with variants is compared as a record, its discriminant a
21
+ * cell of it, and a checklist member by member: one ticked or unticked is proposed whole, and one
22
+ * held on both sides cell by cell. A one-line rich text field, a value of a type nothing nests in, a
23
+ * field the answer clears, and a rich text value inside a record or a list are proposed whole. Values
35
24
  * are in the form the editor's controls are handed, a text cell as its `Content`.
36
25
  *
37
- * Paths are `base`'s. A card the answer retypes is listed as taken out and added; one it moves
38
- * is not listed. `mint` names each item, and by default names it uniquely for the page.
26
+ * A card the answer adds is an `add` item after the nearest card before it that the answer
27
+ * keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
28
+ * Paths and card indexes are `base`'s, and an item on a card, after one or taking one out names
29
+ * it by its `$id` too where it has one. A card the answer retypes is listed as taken out and
30
+ * added; one it moves is not listed.
31
+ *
32
+ * `mint`, or `opts.mint`, names each item, and by default names it uniquely for the page.
33
+ * `opts.label` is handed each item once the list is made and returns its `note` and `group`,
34
+ * from what the host knows of the edit that made it: a block id or a field path it wrote.
39
35
  */
40
- export declare function proposalsBetween(quill: Quill, base: Document, answer: Document, mint?: () => string): Proposed;
36
+ export declare function proposalsBetween(quill: Quill, base: Document, answer: Document, opts?: (() => string) | ProposalsOpts): Proposed;
37
+ /** How `proposalsBetween` names and labels the items it makes. */
38
+ export interface ProposalsOpts {
39
+ mint?: () => string;
40
+ label?: (item: Readonly<ReviewItem>) => ReviewLabel | undefined;
41
+ }
@@ -1,6 +1,6 @@
1
1
  import { fieldPathForAddr } from '../core/address.js';
2
2
  import { sameValue } from './review.js';
3
- import { baseType, fieldValues, oneLine } from './structure.js';
3
+ import { VARIANT_DISCRIMINANT, baseType, fieldValues, oneLine } from './structure.js';
4
4
  let minted = 0;
5
5
  /**
6
6
  * The review list from `base`, the document as the answer's writer read it, to `answer`, the
@@ -12,16 +12,27 @@ let minted = 0;
12
12
  * per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
13
13
  * Every other field takes an item per place that changed: a record's cell, and a list's member,
14
14
  * changed, taken out, or appended past the end, two appends to one list at successive indices.
15
- * A one-line rich text field, a list that gains members anywhere but its end, a value of a type
16
- * nothing nests in, and a rich text value inside a record or a list are proposed whole. Values
15
+ * A list that gains members anywhere but its end is compared member by member at each index, so
16
+ * each place its controls draw says its own change; a record or a list written where none was is
17
+ * compared with an empty one. A choice with variants is compared as a record, its discriminant a
18
+ * cell of it, and a checklist member by member: one ticked or unticked is proposed whole, and one
19
+ * held on both sides cell by cell. A one-line rich text field, a value of a type nothing nests in, a
20
+ * field the answer clears, and a rich text value inside a record or a list are proposed whole. Values
17
21
  * are in the form the editor's controls are handed, a text cell as its `Content`.
18
22
  *
19
- * Paths are `base`'s. A card the answer retypes is listed as taken out and added; one it moves
20
- * is not listed. `mint` names each item, and by default names it uniquely for the page.
23
+ * A card the answer adds is an `add` item after the nearest card before it that the answer
24
+ * keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
25
+ * Paths and card indexes are `base`'s, and an item on a card, after one or taking one out names
26
+ * it by its `$id` too where it has one. A card the answer retypes is listed as taken out and
27
+ * added; one it moves is not listed.
28
+ *
29
+ * `mint`, or `opts.mint`, names each item, and by default names it uniquely for the page.
30
+ * `opts.label` is handed each item once the list is made and returns its `note` and `group`,
31
+ * from what the host knows of the edit that made it: a block id or a field path it wrote.
21
32
  */
22
- export function proposalsBetween(quill, base, answer, mint = () => `review-${minted++}`) {
33
+ export function proposalsBetween(quill, base, answer, opts = {}) {
34
+ const { mint = () => `review-${minted++}`, label } = typeof opts === 'function' ? { mint: opts } : opts;
23
35
  const items = [];
24
- const cards = [];
25
36
  const kinds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).kind);
26
37
  const baseIds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).id ?? '');
27
38
  const answerIds = Array.from({ length: answer.cardCount }, (_, i) => answer.card(i).id ?? '');
@@ -91,26 +102,57 @@ export function proposalsBetween(quill, base, answer, mint = () => `review-${min
91
102
  ...(now !== undefined && { after: now })
92
103
  });
93
104
  const kind = f && baseType(f);
94
- if (kind === 'object' && f?.properties && isRecord(was) && isRecord(now)) {
95
- for (const key of keysOf(f.properties, was, now))
96
- value(pathAt, f.properties[key], [...steps, key], was[key], now[key]);
105
+ const records = isRecord(now) && (was == null || isRecord(was));
106
+ const cells = isRecord(was) ? was : {};
107
+ if (kind === 'object' && f?.properties && records) {
108
+ for (const key of keysOf(f.properties, cells, now))
109
+ value(pathAt, f.properties[key], [...steps, key], cells[key], now[key]);
97
110
  return;
98
111
  }
99
- if (kind !== 'array' || !Array.isArray(was) || !Array.isArray(now))
100
- return whole();
101
- const runs = aligned(was, now);
102
- if (!runs)
112
+ if (kind === 'enum' && f?.variants && records) {
113
+ const cell = (key) => key === VARIANT_DISCRIMINANT
114
+ ? { ...f, variants: undefined }
115
+ : Object.values(f.variants ?? {}).find((world) => world && key in world)?.[key];
116
+ for (const key of keysOf({ [VARIANT_DISCRIMINANT]: null }, cells, now))
117
+ value(pathAt, cell(key), [...steps, key], cells[key], now[key]);
118
+ return;
119
+ }
120
+ if (kind === 'matrix' && records) {
121
+ const next = now;
122
+ for (const member of keysOf({}, cells, next)) {
123
+ const a = cells[member];
124
+ const b = next[member];
125
+ if (sameValue(a, b))
126
+ continue;
127
+ if (isRecord(a) && isRecord(b))
128
+ for (const key of keysOf(f?.properties ?? {}, a, b))
129
+ value(pathAt, f?.properties?.[key], [...steps, member, key], a[key], b[key]);
130
+ else
131
+ items.push({
132
+ id: mint(),
133
+ field: pathAt([...steps, member]),
134
+ ...(a !== undefined && { before: a }),
135
+ ...(b !== undefined && { after: b })
136
+ });
137
+ }
138
+ return;
139
+ }
140
+ if (kind !== 'array' || !Array.isArray(now) || !(was == null || Array.isArray(was)))
103
141
  return whole();
104
- let appended = was.length;
142
+ const held = Array.isArray(was) ? was : [];
143
+ const runs = aligned(held, now) ?? [
144
+ { from: 0, to: 0, removed: held.length, added: now.length }
145
+ ];
146
+ let appended = held.length;
105
147
  for (const { from, to, removed, added } of runs) {
106
148
  const paired = Math.min(removed, added);
107
149
  for (let k = 0; k < paired; k++)
108
- value(pathAt, f?.items, [...steps, from + k], was[from + k], now[to + k]);
150
+ value(pathAt, f?.items, [...steps, from + k], held[from + k], now[to + k]);
109
151
  for (let k = paired; k < removed; k++)
110
152
  items.push({
111
153
  id: mint(),
112
154
  field: pathAt([...steps, from + k]),
113
- before: was[from + k]
155
+ before: held[from + k]
114
156
  });
115
157
  for (let k = paired; k < added; k++)
116
158
  items.push({
@@ -121,31 +163,49 @@ export function proposalsBetween(quill, base, answer, mint = () => `review-${min
121
163
  }
122
164
  };
123
165
  diffCard(quill.schema.main, undefined, base.main, answer.main, undefined);
166
+ /** The base's index of each card the answer keeps as it was, by its answer index. */
167
+ const kept = new Map();
168
+ const removed = [];
124
169
  for (const [at, id] of baseIds.entries()) {
125
170
  const answerAt = answerIds.indexOf(id);
126
171
  const was = base.card(at);
127
- if (answerAt < 0) {
128
- cards.push({ type: 'remove', id, kind: was.kind });
129
- continue;
130
- }
131
- const now = answer.card(answerAt);
132
- if (now.kind !== was.kind) {
133
- cards.push({ type: 'remove', id, kind: was.kind });
172
+ const now = answerAt < 0 ? undefined : answer.card(answerAt);
173
+ if (!now || now.kind !== was.kind) {
174
+ removed.push(at);
134
175
  continue;
135
176
  }
177
+ kept.set(answerAt, at);
178
+ const first = items.length;
136
179
  diffCard(quill.schema.card_kinds?.[was.kind], at, was, now, answerAt);
180
+ if (id)
181
+ for (const item of items.slice(first))
182
+ Object.assign(item, { card: id });
137
183
  }
138
- for (const [at, id] of answerIds.entries()) {
139
- const at0 = baseIds.indexOf(id);
140
- if (at0 >= 0 && base.card(at0).kind === answer.card(at).kind)
184
+ for (const at of answerIds.keys()) {
185
+ if (kept.has(at))
141
186
  continue;
142
- cards.push({
143
- type: 'add',
144
- card: answer.card(at),
145
- ...(at > 0 && { after: answerIds[at - 1] })
187
+ let lead = at - 1;
188
+ while (lead >= 0 && !kept.has(lead))
189
+ lead--;
190
+ const after = kept.get(lead);
191
+ items.push({
192
+ id: mint(),
193
+ add: answer.card(at),
194
+ ...(after !== undefined && { after }),
195
+ ...(after !== undefined && baseIds[after] && { afterCard: baseIds[after] })
146
196
  });
147
197
  }
148
- return { items, cards };
198
+ for (const at of removed)
199
+ items.push({ id: mint(), remove: at, ...(baseIds[at] && { card: baseIds[at] }) });
200
+ if (label)
201
+ for (const item of items) {
202
+ const { note, group } = label(item) ?? {};
203
+ if (note !== undefined)
204
+ item.note = note;
205
+ if (group !== undefined)
206
+ item.group = group;
207
+ }
208
+ return { items };
149
209
  }
150
210
  const addrOf = (card, field) => ({
151
211
  ...(card !== undefined && { card }),
@@ -110,19 +110,21 @@ export interface VisualEditorProps {
110
110
  formatDiagnostic?: FormatDiagnostic;
111
111
  /**
112
112
  * What someone other than the reader proposes, for the editor to draw where each item sits
113
- * ({@link ReviewItem}): a proposal as a word-level edit of its own blocks with Accept and
114
- * Dismiss at its end, and a field's proposed value under its control. Declarative: the host
115
- * sets the list once and clears it once, and the editor draws every answer while the list
116
- * holds the item: an answered item is drawn no more, and an accepted one is plain text. A
117
- * card an item names by index is read against the cards as they stood when the list was
118
- * set, so the item stays on its card through `applyCardOps` and the reader's own card
119
- * edits; an item whose card is gone draws nothing.
113
+ * ({@link ReviewItem}): a proposal as a word-level edit of its own blocks, a field's proposed
114
+ * value under its control, a new card as a preview where it would stand, and a removal as a
115
+ * mark on its card. One change is current while any is open, and the answer card on it is
116
+ * where a change is answered. Declarative: the host sets the list once and clears it once,
117
+ * and the editor draws every answer while the list holds the item: an answered item is drawn
118
+ * no more, and an accepted one is plain text. A card an item names by index is read against
119
+ * the cards as they stood when the list was set, so the item stays on its card through
120
+ * `applyCardOps` and the reader's own card edits; an item whose card is gone draws nothing.
120
121
  */
121
122
  review?: readonly ReviewItem[];
122
123
  /**
123
- * A reader answered an item: a button on it, `Mod-Enter` / `Mod-.` with the caret or the
124
- * focus in it, or a host's `answerReview`; or undid an answer with ⌘Z, `reopen`. The editor has made every write an answer asks for and draws it,
125
- * so the host leaves `review` as it set it.
124
+ * A reader answered an item: the answer card, the `REVIEW_KEYS` on the current change,
125
+ * or a host's `answerReview`; or undid an answer with ⌘Z, `reopen`. The editor has made every
126
+ * write an answer asks for, a card's included, and draws it, so the host leaves `review` as
127
+ * it set it.
126
128
  */
127
129
  onReview?: (event: ReviewEvent) => void;
128
130
  /**
@@ -132,15 +134,13 @@ export interface VisualEditorProps {
132
134
  * host counts and steps its own list by.
133
135
  */
134
136
  onReviewDrawn?: (drawn: ReviewDrawn) => void;
137
+ /** The room, in px, the host's chrome takes at the foot of the pane the editor scrolls in,
138
+ * which the answer card keeps clear of. Default `0`. */
139
+ reviewInset?: number;
135
140
  /**
136
- * Whether an answer given by a chord goes on to the next item, the caret in it, so a held
137
- * walk down a batch answers each in turn. An answer by pointer stays where it was given.
138
- * Default `true`.
139
- */
140
- reviewAdvance?: boolean;
141
- /**
142
- * The item under attention, `undefined` once nothing is: the pointer over one, the caret
143
- * in one, or one a `revealReview` named. What a host lights its own list by.
141
+ * The current change, `undefined` once none is open: the one the answer card and the review
142
+ * keys answer. A review starts on its first change, and every answer moves on to the next.
143
+ * What a host counts its place in the review by.
144
144
  */
145
145
  onReviewFocus?: (id: string | undefined) => void;
146
146
  /** Appended to the root's own class: the surface is a mounted element the
@@ -0,0 +1,51 @@
1
+ import type { QuillFieldSchema } from '@quillmark/wasm';
2
+ import type { ReviewReport } from '../core/codec/index.js';
3
+ import { type CardModel } from './structure.js';
4
+ import type { DeepReview, FieldProposal } from './review.js';
5
+ /** A leaf as its card draws it: its key, and for a field its name, and the schema and the value
6
+ * it holds, which place what is drawn inside it. */
7
+ export interface LeafLayout {
8
+ key: string;
9
+ name?: string;
10
+ schema?: QuillFieldSchema;
11
+ value?: unknown;
12
+ }
13
+ /** A card as the page stands it: its session key, and its leaves in the order it draws them. */
14
+ export interface CardLayout {
15
+ key: string;
16
+ leaves: readonly LeafLayout[];
17
+ }
18
+ /** The leaves of `card` in the order it draws them: its ungrouped sections, its panels, then
19
+ * its body. */
20
+ export declare function cardLayout(card: CardModel): CardLayout;
21
+ export interface Drawn {
22
+ /** The main card, then each card of the stack. */
23
+ layout: readonly CardLayout[];
24
+ /** The cards proposed new after each card, by its key, `head` and `end` at either end. */
25
+ adds: ReadonlyMap<string, readonly {
26
+ id: string;
27
+ }[]>;
28
+ /** The removal marking each card, by its key. */
29
+ removes: ReadonlyMap<string, {
30
+ id: string;
31
+ }>;
32
+ /** The field items over the leaf at `key`. */
33
+ at(key: string): {
34
+ proposed?: FieldProposal;
35
+ nested?: readonly DeepReview[];
36
+ };
37
+ /** What each prose leaf draws, by leaf key, its ids in the leaf's order. */
38
+ reports: ReadonlyMap<string, ReviewReport>;
39
+ /** The field items no control draws. */
40
+ undrawn: ReadonlySet<string>;
41
+ }
42
+ /** The ids drawn, in the page's order. */
43
+ export declare function orderOf(drawn: Drawn): string[];
44
+ /** The open item an answer to `id` moves on to: the next one after it in `order`, as it stood
45
+ * before the answer, round from the end. `undefined` where none is left. */
46
+ export declare function nextOpen(order: readonly string[], id: string, open: ReadonlySet<string>): string | undefined;
47
+ /** Where a step in `dir` lands in `order`, round from either end: from `from` where the order
48
+ * holds it, else from the place `stepped` held when it was last stepped to, which a later item
49
+ * has taken, else from the nearer end. With `keep`, the step passes over every item it refuses.
50
+ * `undefined` where no item is left to land on. */
51
+ export declare function stepIn(order: readonly string[], dir: 1 | -1, from: string | undefined, stepped?: number, keep?: (id: string) => boolean): number | undefined;
@@ -0,0 +1,87 @@
1
+ import { rankAt } from './structure.js';
2
+ /** The leaves of `card` in the order it draws them: its ungrouped sections, its panels, then
3
+ * its body. */
4
+ export function cardLayout(card) {
5
+ const leaves = [];
6
+ if (!card.unschemable) {
7
+ const ungrouped = card.sections.filter((s) => s.group == null);
8
+ const grouped = card.sections.filter((s) => s.group != null);
9
+ for (const section of [...ungrouped, ...grouped])
10
+ for (const field of section.fields)
11
+ leaves.push({
12
+ key: `${card.id}:${field.name}`,
13
+ name: field.name,
14
+ schema: field.schema,
15
+ value: card.values[field.name]
16
+ });
17
+ if (card.hasBody)
18
+ leaves.push({ key: `${card.id}:$body` });
19
+ }
20
+ return { key: card.id, leaves };
21
+ }
22
+ const byRank = (a, b) => {
23
+ for (let i = 0; i < Math.min(a.length, b.length); i++)
24
+ if (a[i] !== b[i])
25
+ return a[i] - b[i];
26
+ return a.length - b.length;
27
+ };
28
+ /** The ids drawn, in the page's order. */
29
+ export function orderOf(drawn) {
30
+ const out = [];
31
+ const seen = new Set();
32
+ const take = (id) => {
33
+ if (seen.has(id))
34
+ return;
35
+ seen.add(id);
36
+ out.push(id);
37
+ };
38
+ const leaf = ({ key, schema, value }) => {
39
+ const { proposed, nested } = drawn.at(key);
40
+ if (proposed && !drawn.undrawn.has(proposed.id))
41
+ take(proposed.id);
42
+ const inside = (nested ?? [])
43
+ .filter((e) => !drawn.undrawn.has(e.item.id))
44
+ .map((e) => ({ id: e.item.id, rank: schema ? rankAt(schema, e.steps, value) : [] }));
45
+ for (const { id } of inside.sort((a, b) => byRank(a.rank, b.rank)))
46
+ take(id);
47
+ for (const id of drawn.reports.get(key)?.ids ?? [])
48
+ take(id);
49
+ };
50
+ const adds = (lead) => {
51
+ for (const item of drawn.adds.get(lead) ?? [])
52
+ take(item.id);
53
+ };
54
+ drawn.layout.forEach((card, n) => {
55
+ const removal = drawn.removes.get(card.key);
56
+ if (removal)
57
+ take(removal.id);
58
+ for (const at of card.leaves)
59
+ leaf(at);
60
+ adds(n === 0 ? 'head' : card.key);
61
+ });
62
+ adds('end');
63
+ return out;
64
+ }
65
+ /** The open item an answer to `id` moves on to: the next one after it in `order`, as it stood
66
+ * before the answer, round from the end. `undefined` where none is left. */
67
+ export function nextOpen(order, id, open) {
68
+ const at = order.indexOf(id);
69
+ return [...order.slice(at + 1), ...order.slice(0, Math.max(at, 0))].find((n) => open.has(n));
70
+ }
71
+ /** Where a step in `dir` lands in `order`, round from either end: from `from` where the order
72
+ * holds it, else from the place `stepped` held when it was last stepped to, which a later item
73
+ * has taken, else from the nearer end. With `keep`, the step passes over every item it refuses.
74
+ * `undefined` where no item is left to land on. */
75
+ export function stepIn(order, dir, from, stepped, keep = () => true) {
76
+ const n = order.length;
77
+ if (!n)
78
+ return undefined;
79
+ const at = from === undefined ? -1 : order.indexOf(from);
80
+ const first = at >= 0 ? at + dir : dir > 0 ? (stepped ?? 0) : (stepped ?? 0) - 1;
81
+ for (let k = 0; k < n; k++) {
82
+ const index = (((first + dir * k) % n) + n) % n;
83
+ if (keep(order[index]))
84
+ return index;
85
+ }
86
+ return undefined;
87
+ }
@@ -1,5 +1,5 @@
1
- import type { PathStep } from '@quillmark/wasm';
2
- import type { DocPath } from '../core/address.js';
1
+ import type { Card, Content, PathStep } from '@quillmark/wasm';
2
+ import type { DocPath, Landing } from '../core/address.js';
3
3
  import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
4
4
  /**
5
5
  * One proposal. `id` is the host's, unique in the list, and is what every event names.
@@ -18,21 +18,67 @@ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
18
18
  * its writer read. A path to a place inside a record or a
19
19
  * list names that place: a cell, or a member by its index, which `after` absent takes out
20
20
  * and an index past the last appends.
21
+ * - `add` or `remove`: a whole card, proposed new or proposed taken out (`CardProposal`).
22
+ *
23
+ * A `field` on a card names the card by its index, read against the cards as they stood when
24
+ * the list was set. `card` beside it names the card by its `$id` instead, wherever it stands
25
+ * now: the path's index is then not read, and an id no card holds is a place the editor does
26
+ * not hold.
21
27
  *
22
28
  * An item whose place the editor does not hold draws nothing. An answered item is drawn no
23
29
  * more: a dismissed one wrote nothing, and an accepted one is plain text in the document.
30
+ *
31
+ * Every item may carry `note` and `group` (`ReviewLabel`).
32
+ */
33
+ export type ReviewItem = (FieldProposal | BlockProposal | CardProposal) & ReviewLabel;
34
+ /**
35
+ * What the proposal's writer says of an item, beside where it stands.
36
+ *
37
+ * - `note`: why, in one line. The answer card shows it above its answers, cut to one line.
38
+ * - `group`: the kind of change it is, a name of the host's. `stepReview` and `answerReview`
39
+ * take a group to step through or answer its items alone.
24
40
  */
25
- export type ReviewItem = FieldProposal | BlockProposal;
41
+ export interface ReviewLabel {
42
+ note?: string;
43
+ group?: string;
44
+ }
45
+ /**
46
+ * A card proposed new or taken out, naming cards by their index into the composable cards as they
47
+ * stood when the list was set, as a path does.
48
+ *
49
+ * - `add`: the card, drawn as a preview where it would stand: after the card at `after`, at the
50
+ * head of the cards where `after` is absent, and last where that card is gone. Two proposals
51
+ * after one card stand in list order. Taken, it is written with its `$id` where no card holds
52
+ * that one.
53
+ * - `remove`: the card at that index, marked whole where it stands.
54
+ *
55
+ * `afterCard` and `card` name that card by its `$id` instead, wherever it stands now, and the
56
+ * index beside one is then not read: an id no card holds is the card gone.
57
+ */
58
+ export type CardProposal = {
59
+ id: string;
60
+ add: Card;
61
+ after?: number;
62
+ afterCard?: string;
63
+ } | {
64
+ id: string;
65
+ remove: number;
66
+ card?: string;
67
+ };
68
+ /** Whether an item proposes a whole card. */
69
+ export declare const byCard: (item: object) => item is CardProposal;
26
70
  /** A proposal over blocks of a rich text field, by their ids. */
27
71
  export type BlockProposal = {
28
72
  id: string;
29
73
  field: DocPath;
74
+ card?: string;
30
75
  replace: readonly string[];
31
76
  before?: string;
32
77
  after: string;
33
78
  } | {
34
79
  id: string;
35
80
  field: DocPath;
81
+ card?: string;
36
82
  insert: BlockPlace;
37
83
  after: string;
38
84
  };
@@ -77,10 +123,33 @@ export interface ReviewDrawn {
77
123
  reason: ReviewUndrawn;
78
124
  }[];
79
125
  }
126
+ /**
127
+ * Every open proposal written into a copy of the document, as the page would read with each one
128
+ * taken, and the way between places in the live document and places in the copy
129
+ * (`VisualEditor.projectReview`). A proposal that adds or takes out a card moves the index of
130
+ * every card after it, and one that adds or rewrites words moves the offsets after them, so a
131
+ * host bridging the editor to a preview of the copy routes each hop through this.
132
+ */
133
+ export interface ReviewProjection {
134
+ /** The proposals written, every one the editor draws, in the page's order. */
135
+ readonly ids: readonly string[];
136
+ /** A place in the live document, as the copy holds it; `undefined` where a proposal takes
137
+ * its card out. */
138
+ toProjection<T extends DocPath | Landing>(at: T): T | undefined;
139
+ /** A place in the copy, as the live document holds it, or the proposal that adds it: a card
140
+ * or a block that only the copy holds. Inside words a proposal rewrites, the offset is the
141
+ * nearest the live text holds. `undefined` for a card the copy does not hold. */
142
+ toLive<T extends DocPath | Landing>(at: T): T | {
143
+ review: string;
144
+ } | undefined;
145
+ }
146
+ /** The projection of a review with nothing open: every place is where it is. */
147
+ export declare const NO_PROJECTION: ReviewProjection;
80
148
  /** A proposal under a field's control. */
81
149
  export type FieldProposal = {
82
150
  id: string;
83
151
  field: DocPath;
152
+ card?: string;
84
153
  before?: unknown;
85
154
  after?: unknown;
86
155
  };
@@ -132,4 +201,26 @@ type Words = {
132
201
  /** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
133
202
  * two lists by their members, two records by their keys; any other pair differs whole. */
134
203
  export declare function reviewRuns(before: unknown, after: unknown, words: Words): ReviewRun[];
204
+ /** A proposal a leaf of words draws over its own value: what it would write, and the value its
205
+ * writer read where it says, each as the leaf's content. */
206
+ export interface TextProposal {
207
+ id: string;
208
+ after: Content;
209
+ before?: Content;
210
+ }
211
+ /** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
212
+ * is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
213
+ export declare function textProposal(item: FieldProposal | undefined, cleared?: Content): TextProposal | undefined;
214
+ /** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
215
+ * for one that clears it, which the input shows as what Accept leaves. */
216
+ export declare function numberProposal(item: FieldProposal | undefined): {
217
+ id: string;
218
+ after: string;
219
+ } | undefined;
220
+ /** What a control that shows one value shows while `item` stands: the value Accept would write,
221
+ * nothing where it clears the control, which then draws its default or its empty face. */
222
+ export declare function shownValue(item: FieldProposal | undefined, stored: unknown): unknown;
223
+ /** Whether a value a reader commits is the one a proposal would write: a blank and an unset value
224
+ * are one, since a control cleared over a default commits `''`. */
225
+ export declare function writesProposed(value: unknown, after: unknown): boolean;
135
226
  export {};