@quillmark/svelte 0.37.1 → 0.38.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.
@@ -43,8 +43,7 @@
43
43
  fieldModels,
44
44
  fieldTitle,
45
45
  isContainer,
46
- linesOnly,
47
- literalText,
46
+ leafFlags,
48
47
  mountKey,
49
48
  optionalCell,
50
49
  own,
@@ -59,7 +58,7 @@
59
58
  numberProposal,
60
59
  shownValue,
61
60
  splitReview,
62
- textProposal,
61
+ textsOf,
63
62
  type DeepReview,
64
63
  type FieldProposal
65
64
  } from './review.js';
@@ -130,6 +129,11 @@
130
129
  * one naming a property draws under that property's control, and one naming
131
130
  * nothing this subform holds draws at its foot (`diagnostics.ts`). */
132
131
  diagnostics?: readonly DeepDiagnostic[];
132
+ /** Enum-option policy for an enum property at any depth of this subform, `steps` the
133
+ * properties from here down to it. */
134
+ optionAllowed?: (value: string, steps: readonly PathStep[]) => boolean;
135
+ /** How a refused option draws: greyed (default) or left out. */
136
+ enumDisallowed?: 'hide' | 'disable';
133
137
  /** The review items naming a place inside this subform, each with its steps still to
134
138
  * walk: one naming a cell draws under the cell's control, one naming a place inside a
135
139
  * record or a list cell is handed to it, and the rest draw under the cell they are in
@@ -150,6 +154,8 @@
150
154
  placed = false,
151
155
  onCellKey,
152
156
  diagnostics,
157
+ optionAllowed,
158
+ enumDisallowed,
153
159
  review
154
160
  }: Props = $props();
155
161
 
@@ -316,13 +322,13 @@
316
322
  {@const deep = routed.below.get(key)}
317
323
  {@const reviewHere = reviewed.below.get(key)}
318
324
  {@const handsDown = isContainer(kind)}
319
- {@const ownItem = handsDown ? undefined : reviewHere?.find((e) => !e.steps.length)?.item}
320
- {@const textOwn =
321
- kind === 'prose' && (shortCell(sub) || literalText(sub))
322
- ? textProposal(ownItem, contentDefault(sub))
323
- : undefined}
325
+ {@const ownItems = handsDown
326
+ ? []
327
+ : (reviewHere ?? []).filter((e) => !e.steps.length).map((e) => e.item)}
328
+ {@const ownItem = ownItems[0]}
329
+ {@const textOwn = kind === 'prose' ? textsOf(ownItems, contentDefault(sub)) : undefined}
324
330
  {@const numberOwn = kind === 'number' ? numberProposal(ownItem) : undefined}
325
- {@const worded = textOwn ?? numberOwn}
331
+ {@const worded = textOwn?.[0] ?? numberOwn}
326
332
  {@const shownItem = worded ? undefined : ownItem}
327
333
  {@const shown = shownValue(shownItem, obj[key])}
328
334
  {@const commitCell = (v: unknown) => answerOrCommit(shownItem, key, v)}
@@ -385,6 +391,8 @@
385
391
  optional={optionalCell(sub)}
386
392
  onCommit={commitCell}
387
393
  proposing={!!shownItem}
394
+ optionAllowed={optionAllowed && ((v) => optionAllowed(v, [key]))}
395
+ {enumDisallowed}
388
396
  />
389
397
  {:else if kind === 'number'}
390
398
  <NumberField
@@ -442,8 +450,8 @@
442
450
  : contentAt([key])}
443
451
  value={shown}
444
452
  fallback={contentDefault(sub)}
445
- plaintext={literalText(sub)}
446
- paragraphs={linesOnly(sub)}
453
+ plaintext={leafFlags(sub).plaintext}
454
+ paragraphs={leafFlags(sub).paragraphs}
447
455
  placeholder={ownItem ? undefined : noneOf(key, sub)}
448
456
  {block}
449
457
  label={named}
@@ -483,6 +491,8 @@
483
491
  value={obj[key] as Record<string, unknown> | undefined}
484
492
  properties={sub.properties}
485
493
  {placed}
494
+ optionAllowed={optionAllowed && ((v, steps) => optionAllowed(v, [key, ...steps]))}
495
+ {enumDisallowed}
486
496
  label={ids ? undefined : fallbackName(key, sub)}
487
497
  idBase={ids?.control}
488
498
  labelledBy={ids?.label}
@@ -513,6 +523,8 @@
513
523
  value={obj[key] as Record<string, unknown> | undefined}
514
524
  schema={sub}
515
525
  ghostMember={sub.default as string | undefined}
526
+ optionAllowed={optionAllowed && ((v) => optionAllowed(v, [key]))}
527
+ {enumDisallowed}
516
528
  label={fieldTitle(key, sub)}
517
529
  id={ids?.control}
518
530
  labelledBy={ids?.label}
@@ -534,7 +546,7 @@
534
546
  <DiagnosticList diagnostics={own} />
535
547
  {#if !handsDown}
536
548
  <ReviewRows
537
- entries={worded ? reviewHere?.filter((e) => e.item !== ownItem) : reviewHere}
549
+ entries={worded ? reviewHere?.filter((e) => !ownItems.includes(e.item)) : reviewHere}
538
550
  />
539
551
  {/if}
540
552
  </div>
@@ -49,6 +49,11 @@ interface Props {
49
49
  * one naming a property draws under that property's control, and one naming
50
50
  * nothing this subform holds draws at its foot (`diagnostics.ts`). */
51
51
  diagnostics?: readonly DeepDiagnostic[];
52
+ /** Enum-option policy for an enum property at any depth of this subform, `steps` the
53
+ * properties from here down to it. */
54
+ optionAllowed?: (value: string, steps: readonly PathStep[]) => boolean;
55
+ /** How a refused option draws: greyed (default) or left out. */
56
+ enumDisallowed?: 'hide' | 'disable';
52
57
  /** The review items naming a place inside this subform, each with its steps still to
53
58
  * walk: one naming a cell draws under the cell's control, one naming a place inside a
54
59
  * record or a list cell is handed to it, and the rest draw under the cell they are in
@@ -5,7 +5,7 @@
5
5
  this leaf's commits with the caret riding the untouched view.
6
6
  -->
7
7
  <script lang="ts">
8
- import { untrack } from 'svelte';
8
+ import { onDestroy, untrack } from 'svelte';
9
9
  import {
10
10
  createField,
11
11
  type FieldController,
@@ -63,8 +63,9 @@
63
63
  cap?: TextCap;
64
64
  /** Registry identity, stamped on the DOM node so a remount is visible as one. */
65
65
  leafKey: string;
66
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
67
- proposed?: TextProposal;
66
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
67
+ * over its text as a word diff. */
68
+ proposed?: readonly TextProposal[];
68
69
  onFocus?: (addr: Addr) => void;
69
70
  onCaretMove?: (addr: Addr, pos: number) => void;
70
71
  /** A commit landed on this leaf: the prose change lane. */
@@ -197,13 +198,20 @@
197
198
  controller?.setReview(reviewing.textAt(leafKey), reviewing.lit);
198
199
  });
199
200
  $effect(() => {
200
- controller?.setValueProposal(proposed && { ...proposed, lit: reviewing.lit === proposed.id });
201
+ controller?.setValueProposals(
202
+ (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }))
203
+ );
201
204
  });
205
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
206
+ * list is answered, which would leave its own Accept writing its value whole. */
207
+ let plannedIds: readonly string[] = [];
202
208
  $effect(() => {
203
- const id = proposed?.id;
204
- return () => {
205
- if (id !== undefined) reviewing.planned(id, undefined);
206
- };
209
+ const ids = (proposed ?? []).map((p) => p.id);
210
+ for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
211
+ plannedIds = ids;
212
+ });
213
+ onDestroy(() => {
214
+ for (const id of plannedIds) reviewing.planned(id, undefined);
207
215
  });
208
216
 
209
217
  // Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
@@ -45,8 +45,9 @@ interface Props {
45
45
  cap?: TextCap;
46
46
  /** Registry identity, stamped on the DOM node so a remount is visible as one. */
47
47
  leafKey: string;
48
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
49
- proposed?: TextProposal;
48
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
49
+ * over its text as a word diff. */
50
+ proposed?: readonly TextProposal[];
50
51
  onFocus?: (addr: Addr) => void;
51
52
  onCaretMove?: (addr: Addr, pos: number) => void;
52
53
  /** A commit landed on this leaf: the prose change lane. */
@@ -45,7 +45,7 @@
45
45
  replacement reads, so a write moving the value takes it or releases it.
46
46
  -->
47
47
  <script lang="ts">
48
- import { untrack } from 'svelte';
48
+ import { onDestroy, untrack } from 'svelte';
49
49
  import { Fragment, Slice, type Node as PMNode } from 'prosemirror-model';
50
50
  import { EditorState, Selection } from 'prosemirror-state';
51
51
  import { EditorView } from 'prosemirror-view';
@@ -137,8 +137,9 @@
137
137
  * array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
138
138
  * keymap, so the state it reads is the one this keystroke has yet to change. */
139
139
  onKey?: (e: KeyboardEvent) => void;
140
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
141
- proposed?: TextProposal;
140
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
141
+ * over its text as a word diff. */
142
+ proposed?: readonly TextProposal[];
142
143
  }
143
144
  let {
144
145
  content,
@@ -159,21 +160,23 @@
159
160
  }: Props = $props();
160
161
 
161
162
  const reviewing = review();
162
- /** The proposal the value-diff plugin reads, and the view it redraws. */
163
- let drawnProposal: ValueProposal | undefined;
163
+ /** The proposals the value-diff plugin reads, and the view it redraws. */
164
+ let drawnProposals: readonly ValueProposal[] = [];
164
165
  let redraw: (() => void) | undefined;
165
166
  $effect(() => {
166
- drawnProposal =
167
- proposed && (!block || plaintext)
168
- ? { ...proposed, lit: reviewing.lit === proposed.id }
169
- : undefined;
167
+ drawnProposals = (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }));
170
168
  redraw?.();
171
169
  });
170
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
171
+ * list is answered, which would leave its own Accept writing its value whole. */
172
+ let plannedIds: readonly string[] = [];
172
173
  $effect(() => {
173
- const id = proposed?.id;
174
- return () => {
175
- if (id !== undefined) reviewing.planned(id, undefined);
176
- };
174
+ const ids = (proposed ?? []).map((p) => p.id);
175
+ for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
176
+ plannedIds = ids;
177
+ });
178
+ onDestroy(() => {
179
+ for (const id of plannedIds) reviewing.planned(id, undefined);
177
180
  });
178
181
 
179
182
  const t = wording();
@@ -296,15 +299,12 @@
296
299
  placeholder: () => drawn.placeholder,
297
300
  leaveStrings: () => t.strings,
298
301
  cap,
299
- afterHistory:
300
- inline || plaintext
301
- ? [
302
- valueDiffPlugin(
303
- () => drawnProposal,
304
- (id, state) => reviewing.planned(id, state)
305
- )
306
- ]
307
- : []
302
+ afterHistory: [
303
+ valueDiffPlugin(
304
+ () => drawnProposals,
305
+ (id, state) => reviewing.planned(id, state)
306
+ )
307
+ ]
308
308
  })
309
309
  });
310
310
  };
@@ -58,8 +58,9 @@ interface Props {
58
58
  * array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
59
59
  * keymap, so the state it reads is the one this keystroke has yet to change. */
60
60
  onKey?: (e: KeyboardEvent) => void;
61
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
62
- proposed?: TextProposal;
61
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
62
+ * over its text as a word diff. */
63
+ proposed?: readonly TextProposal[];
63
64
  }
64
65
  declare const ProseValue: import("svelte").Component<Props, {
65
66
  focus: () => void;
@@ -67,9 +67,11 @@
67
67
  byBlocks,
68
68
  byCard,
69
69
  locate,
70
+ putsIn,
70
71
  onField,
71
72
  reviewText,
72
73
  valueIn,
74
+ valueInserting,
73
75
  valueWith,
74
76
  NO_PROJECTION,
75
77
  type CardProposal,
@@ -234,6 +236,7 @@
234
236
  function report(source: ChangeSource, cardId?: CardId, at?: Addr | number, op?: CardOp): void {
235
237
  const path =
236
238
  at == null ? undefined : typeof at === 'number' ? cardPath(at, liveKinds()) : pathFor(at);
239
+ if (source !== 'structure' && cardId !== undefined) reviewing.edited(cardId);
237
240
  reviewing.settled();
238
241
  onChange?.({ source, cardId, path, ...(op ? { op } : {}) });
239
242
  }
@@ -416,6 +419,8 @@
416
419
  if (write && item && onField(item)) {
417
420
  back = takeField(item, write);
418
421
  if (!back) return false;
422
+ const card = reviewed(item.field)?.card;
423
+ if (typeof card === 'string') reviewing.edited(card);
419
424
  } else if (action === 'accept' && item && (onField(item) || byCard(item))) {
420
425
  back = onField(item) ? takeField(item) : takeCard(item);
421
426
  if (!back) return false;
@@ -467,7 +472,9 @@
467
472
  const steps = reviewing.at(leaf).nested?.find((e) => e.item.id === item.id)?.steps;
468
473
  if (!steps) return undefined;
469
474
  const value = current();
470
- after = valueWith(value, steps, to(valueIn(value, steps)));
475
+ after = putsIn(item)
476
+ ? valueInserting(value, steps, item.after)
477
+ : valueWith(value, steps, to(valueIn(value, steps)));
471
478
  } else after = to(current());
472
479
  if (!write(after)) return undefined;
473
480
  return () => void write(before);
@@ -852,6 +859,7 @@
852
859
  const cardId = cardIdOf(plain);
853
860
  if (cardId == null) return;
854
861
  refreshTitle(plain, cardId);
862
+ reviewing.edited(cardId);
855
863
  reviewing.settled();
856
864
  onChange?.({ source: 'prose', cardId, path: pathFor(plain) });
857
865
  }
@@ -1255,8 +1263,8 @@
1255
1263
  retype: (kind: string) => retypeCardById(id, kind),
1256
1264
  rename: (title: string) => renameCardById(id, title),
1257
1265
  diagFor: (field?: string) => diagByKey.get(leafKey(field)),
1258
- enumAllowed: (field: string, value: string) =>
1259
- enumOptionAllowed?.(makeAddr(id, isMain, field), value) ?? true
1266
+ enumAllowed: (field: string, value: string, steps?: readonly PathStep[]) =>
1267
+ enumOptionAllowed?.(makeAddr(id, isMain, field), value, steps) ?? true
1260
1268
  };
1261
1269
  }
1262
1270
 
@@ -1848,11 +1856,9 @@
1848
1856
  }
1849
1857
  }
1850
1858
  if (!found) continue;
1851
- held.value = valueWith(
1852
- held.value,
1853
- found,
1854
- reviewing.writes(item, valueIn(held.value, found))
1855
- );
1859
+ held.value = putsIn(item as FieldProposal)
1860
+ ? valueInserting(held.value, found, (item as FieldProposal).after)
1861
+ : valueWith(held.value, found, reviewing.writes(item, valueIn(held.value, found)));
1856
1862
  }
1857
1863
  held.ids.push(id);
1858
1864
  }
@@ -2461,6 +2467,21 @@
2461
2467
  :is(.qm-control-box:not(.qm-element-summary), .qm-input, .qm-prose, .qm-element-preview)
2462
2468
  ) {
2463
2469
  color: var(--_qm-ink-label);
2470
+ }
2471
+ /* The strike falls on a value alone, never on the box holding it, which would carry it onto
2472
+ an empty field's hint and a button's label: a strike drawn on a box reaches every word
2473
+ in it. A date's segments are a value only once none of them is a hint. */
2474
+ :global(
2475
+ :is([data-qm-removed], .qm-review-card-remove.qm-review-on)
2476
+ :is(
2477
+ .qm-input:not(:placeholder-shown),
2478
+ .ProseMirror > :not(.qm-prose-placeholder),
2479
+ .qm-select:not([data-ghosted='']) .qm-select-shown,
2480
+ .qm-date:not(:has([data-ghosted='hint'])) .qm-date-segment,
2481
+ .qm-date-unread,
2482
+ .qm-element-preview
2483
+ )
2484
+ ) {
2464
2485
  text-decoration: line-through;
2465
2486
  text-decoration-color: var(--_qm-review-line);
2466
2487
  }
@@ -11,17 +11,20 @@ export interface Proposed {
11
11
  * block ids. Each item carries `before`, what the writer read, so the editor keeps what the
12
12
  * reader has written since and reports a place both changed as outdated.
13
13
  *
14
- * Cards pair by id. Each paired card's body and block rich text fields take one `replace` item
15
- * per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
16
- * Every other field takes an item per place that changed: a record's cell, and a list's member,
17
- * changed, taken out, or appended past the end, two appends to one list at successive indices.
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
24
- * are in the form the editor's controls are handed, a text cell as its `Content`.
14
+ * Cards pair by id. Each paired card's body and its rich text fields of `blocks` take one
15
+ * `replace` item per block the answer rewrote or took out, and one `insert` item per run of blocks
16
+ * it added. A text field of one line or of lines, at the top of a card or inside a record or a
17
+ * list, takes one item per run of lines the answer changed, lines paired by their words: each the
18
+ * value read with that run alone written, runs at most two unchanged lines apart one item, and a
19
+ * value that changes one run proposed whole. Every other field takes an item per place that
20
+ * changed: a record's cell, and a list's member, changed, taken out, or appended past the end, two
21
+ * appends to one list at successive indices. Members a list gains anywhere but its end are one
22
+ * item per run, `ahead` naming the member that follows them. A record or a list written where none
23
+ * was is compared with an empty one. A choice with variants is compared as a record, its
24
+ * discriminant a cell of it, and a checklist member by member: one ticked or unticked is proposed
25
+ * whole, and one held on both sides cell by cell. A value of a type nothing nests in, a field the
26
+ * answer clears, and a rich text value of `blocks` inside a record or a list are proposed whole.
27
+ * Values are in the form the editor's controls are handed, a text cell as its `Content`.
25
28
  *
26
29
  * A card the answer adds is an `add` item after the nearest card before it that the answer
27
30
  * keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
@@ -1,6 +1,7 @@
1
1
  import { fieldPathForAddr } from '../core/address.js';
2
+ import { asContent, lineRuns } from '../core/codec/value-plan.js';
2
3
  import { sameValue } from './review.js';
3
- import { VARIANT_DISCRIMINANT, baseType, fieldValues, oneLine } from './structure.js';
4
+ import { VARIANT_DISCRIMINANT, baseType, fieldValues, textKind } from './structure.js';
4
5
  let minted = 0;
5
6
  /**
6
7
  * The review list from `base`, the document as the answer's writer read it, to `answer`, the
@@ -8,17 +9,20 @@ let minted = 0;
8
9
  * block ids. Each item carries `before`, what the writer read, so the editor keeps what the
9
10
  * reader has written since and reports a place both changed as outdated.
10
11
  *
11
- * Cards pair by id. Each paired card's body and block rich text fields take one `replace` item
12
- * per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
13
- * Every other field takes an item per place that changed: a record's cell, and a list's member,
14
- * changed, taken out, or appended past the end, two appends to one list at successive indices.
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
21
- * are in the form the editor's controls are handed, a text cell as its `Content`.
12
+ * Cards pair by id. Each paired card's body and its rich text fields of `blocks` take one
13
+ * `replace` item per block the answer rewrote or took out, and one `insert` item per run of blocks
14
+ * it added. A text field of one line or of lines, at the top of a card or inside a record or a
15
+ * list, takes one item per run of lines the answer changed, lines paired by their words: each the
16
+ * value read with that run alone written, runs at most two unchanged lines apart one item, and a
17
+ * value that changes one run proposed whole. Every other field takes an item per place that
18
+ * changed: a record's cell, and a list's member, changed, taken out, or appended past the end, two
19
+ * appends to one list at successive indices. Members a list gains anywhere but its end are one
20
+ * item per run, `ahead` naming the member that follows them. A record or a list written where none
21
+ * was is compared with an empty one. A choice with variants is compared as a record, its
22
+ * discriminant a cell of it, and a checklist member by member: one ticked or unticked is proposed
23
+ * whole, and one held on both sides cell by cell. A value of a type nothing nests in, a field the
24
+ * answer clears, and a rich text value of `blocks` inside a record or a list are proposed whole.
25
+ * Values are in the form the editor's controls are handed, a text cell as its `Content`.
22
26
  *
23
27
  * A card the answer adds is an `add` item after the nearest card before it that the answer
24
28
  * keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
@@ -43,7 +47,8 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
43
47
  const fields = schema?.fields ?? {};
44
48
  for (const name of keysOf(fields, before, after)) {
45
49
  const f = fields[name];
46
- if (f && baseType(f) === 'richtext' && !oneLine(f)) {
50
+ const kind = f && textKind(f);
51
+ if (kind?.type === 'richtext' && kind.shape === 'blocks') {
47
52
  blocks(pathOf(at, name), base, addrOf(at, name), answer, addrOf(answerAt, name));
48
53
  continue;
49
54
  }
@@ -101,6 +106,16 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
101
106
  ...(was !== undefined && { before: was }),
102
107
  ...(now !== undefined && { after: now })
103
108
  });
109
+ const text = f && textKind(f);
110
+ const words = text ? [asContent(was), asContent(now)] : [];
111
+ if (text && words[0] && words[1] && now != null) {
112
+ const runs = lineRuns(words[0], words[1], text.shape === 'blocks' ? 'paragraph' : 'run');
113
+ if (runs.length > 1) {
114
+ for (const run of runs)
115
+ items.push({ id: mint(), field: pathAt(steps), before: was, after: run });
116
+ return;
117
+ }
118
+ }
104
119
  const kind = f && baseType(f);
105
120
  const records = isRecord(now) && (was == null || isRecord(was));
106
121
  const cells = isRecord(was) ? was : {};
@@ -140,11 +155,8 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
140
155
  if (kind !== 'array' || !Array.isArray(now) || !(was == null || Array.isArray(was)))
141
156
  return whole();
142
157
  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
158
  let appended = held.length;
147
- for (const { from, to, removed, added } of runs) {
159
+ for (const { from, to, removed, added } of aligned(held, now)) {
148
160
  const paired = Math.min(removed, added);
149
161
  for (let k = 0; k < paired; k++)
150
162
  value(pathAt, f?.items, [...steps, from + k], held[from + k], now[to + k]);
@@ -154,12 +166,20 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
154
166
  field: pathAt([...steps, from + k]),
155
167
  before: held[from + k]
156
168
  });
157
- for (let k = paired; k < added; k++)
169
+ if (added > paired && from + removed < held.length)
158
170
  items.push({
159
171
  id: mint(),
160
- field: pathAt([...steps, appended++]),
161
- after: now[to + k]
172
+ field: pathAt([...steps, from + removed]),
173
+ ahead: held[from + removed],
174
+ after: now.slice(to + paired, to + added)
162
175
  });
176
+ else
177
+ for (let k = paired; k < added; k++)
178
+ items.push({
179
+ id: mint(),
180
+ field: pathAt([...steps, appended++]),
181
+ after: now[to + k]
182
+ });
163
183
  }
164
184
  };
165
185
  diffCard(quill.schema.main, undefined, base.main, answer.main, undefined);
@@ -233,8 +253,7 @@ function keysOf(declared, ...values) {
233
253
  /**
234
254
  * The runs where two lists differ, members matched by value along their longest common run:
235
255
  * at each, `removed` members of `was` from `from` and `added` members of `now` from `to`. A run
236
- * pairs its members as changes, and takes out or appends the rest. `undefined` where a run adds
237
- * more members than it takes out anywhere but the end, which no index names.
256
+ * pairs its members as changes, and takes out, appends or puts in the rest.
238
257
  */
239
258
  function aligned(was, now) {
240
259
  const m = was.length;
@@ -253,16 +272,12 @@ function aligned(was, now) {
253
272
  const close = () => {
254
273
  const removed = i - from;
255
274
  const added = j - to;
256
- if (added > removed && i < m)
257
- return false;
258
275
  if (removed || added)
259
276
  runs.push({ from, to, removed, added });
260
- return true;
261
277
  };
262
278
  while (i < m && j < n) {
263
279
  if (sameValue(was[i], now[j])) {
264
- if (!close())
265
- return undefined;
280
+ close();
266
281
  i++;
267
282
  j++;
268
283
  from = i;
@@ -275,5 +290,6 @@ function aligned(was, now) {
275
290
  }
276
291
  i = m;
277
292
  j = n;
278
- return close() ? runs : undefined;
293
+ close();
294
+ return runs;
279
295
  }
@@ -1,4 +1,4 @@
1
- import type { Document, Quill, Addr, Diagnostic, FontFace } from '@quillmark/wasm';
1
+ import type { Document, Quill, Addr, Diagnostic, FontFace, PathStep } from '@quillmark/wasm';
2
2
  import type { Place } from '../core/address.js';
3
3
  import type { EditorErrorHandler } from '../core/errors.js';
4
4
  import type { ActiveLeaf, EditorChange } from './signals.js';
@@ -70,10 +70,12 @@ export interface VisualEditorProps {
70
70
  * return `false` to mark that option unavailable; `enumDisallowed` decides how
71
71
  * the control then draws it. The stored payload is untouched either way: the
72
72
  * schema is unchanged, this is runtime policy. Absent → every schema option is
73
- * offered. It reaches a field's own enum control; an enum inside an object
74
- * subform has no `Addr` to pass and is offered whole.
73
+ * offered. It reaches a field's own enum control, where `steps` is absent, and an
74
+ * enum inside the field's object subform, at any depth, where `steps` names the
75
+ * properties from the field down to it (`['level']` for `classification.level`).
76
+ * An enum inside a list or matrix cell is offered whole.
75
77
  */
76
- enumOptionAllowed?: (addr: Addr, value: string) => boolean;
78
+ enumOptionAllowed?: (addr: Addr, value: string, steps?: readonly PathStep[]) => boolean;
77
79
  /**
78
80
  * How an `enumOptionAllowed: false` option draws: `'disable'` (the default) greys
79
81
  * it in place, `'hide'` leaves it out of the list. One policy for the surface, not
@@ -32,6 +32,7 @@ export interface Drawn {
32
32
  /** The field items over the leaf at `key`. */
33
33
  at(key: string): {
34
34
  proposed?: FieldProposal;
35
+ more?: readonly FieldProposal[];
35
36
  nested?: readonly DeepReview[];
36
37
  };
37
38
  /** What each prose leaf draws, by leaf key, its ids in the leaf's order. */
@@ -36,9 +36,10 @@ export function orderOf(drawn) {
36
36
  out.push(id);
37
37
  };
38
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);
39
+ const { proposed, more, nested } = drawn.at(key);
40
+ for (const p of proposed ? [proposed, ...(more ?? [])] : [])
41
+ if (!drawn.undrawn.has(p.id))
42
+ take(p.id);
42
43
  const inside = (nested ?? [])
43
44
  .filter((e) => !drawn.undrawn.has(e.item.id))
44
45
  .map((e) => ({ id: e.item.id, rank: schema ? rankAt(schema, e.steps, value) : [] }));
@@ -17,7 +17,8 @@ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
17
17
  * field's writer would take, an absent one proposing the field cleared, and `before` the value
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
- * and an index past the last appends.
20
+ * and an index past the last appends. One with `ahead` puts the members `after` holds in
21
+ * front of `ahead`, the member its writer read at that index.
21
22
  * - `add` or `remove`: a whole card, proposed new or proposed taken out (`CardProposal`).
22
23
  *
23
24
  * A `field` on a card names the card by its index, read against the cards as they stood when
@@ -152,7 +153,12 @@ export type FieldProposal = {
152
153
  card?: string;
153
154
  before?: unknown;
154
155
  after?: unknown;
156
+ /** The member a run of members proposed new inside a list goes in front of, as its writer
157
+ * read the list at the path's index; `after` then holds the members, in order. */
158
+ ahead?: unknown;
155
159
  };
160
+ /** Whether a field item puts new members into a list in front of one it holds. */
161
+ export declare const putsIn: (item: FieldProposal) => boolean;
156
162
  /** A field item routed past its field: the steps from the rung it is handed to down to the
157
163
  * value it names, a member of a list by its index, a cell of a record by its key. */
158
164
  export interface DeepReview {
@@ -170,11 +176,15 @@ export declare function valueIn(value: unknown, steps: readonly PathStep[]): unk
170
176
  /** `value` with what `steps` reach set to `to`: a list's member past its end appended, and one
171
177
  * set to nothing taken out; a record's cell set to nothing left out. Copies on the way down. */
172
178
  export declare function valueWith(value: unknown, steps: readonly PathStep[], to: unknown): unknown;
179
+ /** `value` with `members` put into the list `steps` reach, in front of the member at its last
180
+ * step, or at its end past the last. */
181
+ export declare function valueInserting(value: unknown, steps: readonly PathStep[], members: unknown): unknown;
173
182
  /**
174
183
  * Where a field proposal's steps land in `value` as it stands. A list's member is found by its
175
184
  * index where it holds `before`, else as the nearest member holding `before` that `claimed`
176
185
  * does not already hold, so one member taken out does not move another's proposal onto the
177
- * wrong row. `found` is false where the proposal has a `before` nothing holds.
186
+ * wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
187
+ * none. `found` is false where the proposal has a `before` or an `ahead` nothing holds.
178
188
  */
179
189
  export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal, claimed: Set<string>): {
180
190
  steps: readonly PathStep[];
@@ -211,6 +221,9 @@ export interface TextProposal {
211
221
  /** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
212
222
  * is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
213
223
  export declare function textProposal(item: FieldProposal | undefined, cleared?: Content): TextProposal | undefined;
224
+ /** A place's proposals over a leaf of words, each run of one answer, or `undefined` where any
225
+ * of them is not words or there are none. */
226
+ export declare function textsOf(items: readonly FieldProposal[], cleared?: Content): TextProposal[] | undefined;
214
227
  /** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
215
228
  * for one that clears it, which the input shows as what Accept leaves. */
216
229
  export declare function numberProposal(item: FieldProposal | undefined): {