@quillmark/svelte 0.42.0 → 0.43.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.
@@ -22,10 +22,3 @@ export declare function rangeAnchor(view: EditorView, from: number, to: number):
22
22
  * clears every one, as a surface over a selection in a table cell clears the cell's row.
23
23
  */
24
24
  export declare function across(anchor: RangeAnchor, boxes: readonly Element[]): RangeAnchor;
25
- /**
26
- * A virtual anchor over the first line box of the element `find` returns when asked: a mark a
27
- * view redraws under every edit, so no element outlives the surface hung off it. `context` is
28
- * the view's own element, which does. Total as {@link rangeAnchor} is: with nothing to measure
29
- * it returns the last rect that measured.
30
- */
31
- export declare function markAnchor(context: Element, find: () => Element | undefined): RangeAnchor;
@@ -78,22 +78,3 @@ export function across(anchor, boxes) {
78
78
  }
79
79
  };
80
80
  }
81
- /**
82
- * A virtual anchor over the first line box of the element `find` returns when asked: a mark a
83
- * view redraws under every edit, so no element outlives the surface hung off it. `context` is
84
- * the view's own element, which does. Total as {@link rangeAnchor} is: with nothing to measure
85
- * it returns the last rect that measured.
86
- */
87
- export function markAnchor(context, find) {
88
- let last;
89
- return {
90
- contextElement: context,
91
- getBoundingClientRect: () => {
92
- const el = find();
93
- const rect = el?.getClientRects()[0] ?? el?.getBoundingClientRect();
94
- if (rect)
95
- last = rect;
96
- return last ?? new DOMRect();
97
- }
98
- };
99
- }
@@ -177,7 +177,7 @@ function readLeaf(reader, addr) {
177
177
  function writeAddr(doc, addr) {
178
178
  if (typeof addr.card !== 'number')
179
179
  return addr;
180
- return { ...addr, card: doc.card(addr.card).id ?? addr.card };
180
+ return { ...addr, card: doc.cardId(addr.card) };
181
181
  }
182
182
  /** The canonical empty `Content`: one empty `para` block. */
183
183
  export function emptyContent() {
@@ -1,4 +1,4 @@
1
- export { markAnchor, rangeAnchor } from './anchor.js';
1
+ export { rangeAnchor } from './anchor.js';
2
2
  export type { RangeAnchor } from './anchor.js';
3
3
  export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
4
4
  export type { CreateFieldOpts, FieldController, LeafProjection, LeafViews } from './field.js';
@@ -11,19 +11,16 @@ export { DEFAULT_SLASH_STRINGS } from './slash.js';
11
11
  export type { SlashState, SlashStrings } from './slash.js';
12
12
  export { DEFAULT_LEAVE_STRINGS } from './leave.js';
13
13
  export type { LeaveStrings } from './leave.js';
14
- export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, TextReview } from './review.js';
15
- export { wordDiff } from './review-diff.js';
14
+ export type { BlockPlace, ReviewAction, ReviewReport, TextReview } from './review.js';
16
15
  export { valueDiffPlugin, valueSpans } from './value-diff.js';
17
16
  export { reviewCaretPlugin } from './review-caret.js';
18
17
  export type { ValueProposal, ValueState } from './value-diff.js';
19
18
  export { asContent, planValue, valueChanges } from './value-plan.js';
20
- export type { ValuePlan, ValueChange } from './value-plan.js';
21
- export type { DiffHunk } from './review-diff.js';
22
19
  export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, LIST_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
23
20
  export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
24
- export { blockSchema, inlineSchema, plaintextSchema, plainSchema, linesSchema, leafSchema, isParagraphsSchema, hasMarks } from './schema.js';
21
+ export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, isParagraphsSchema, hasMarks } from './schema.js';
25
22
  export { rendersHref, storableUrl } from './urls.js';
26
- export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
23
+ export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent } from './decode.js';
27
24
  export { pmToContent, lower } from './encode.js';
28
25
  export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
29
26
  export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
@@ -11,7 +11,7 @@ import 'prosemirror-gapcursor/style/gapcursor.css';
11
11
  import './prose.css';
12
12
  // What a floating surface anchors to. The visual tier's own surfaces mint one over a
13
13
  // selection (`visual/FormatPopover.svelte`), so it is reached off-barrel.
14
- export { markAnchor, rangeAnchor } from './anchor.js';
14
+ export { rangeAnchor } from './anchor.js';
15
15
  // The prose leaf.
16
16
  export { createField, emptyContent, heldAttributes, isEmptyContent, proseAttributes, proseLeafPlugins } from './field.js';
17
17
  export { capCount } from './cap.js';
@@ -25,7 +25,6 @@ export { DEFAULT_SLASH_STRINGS } from './slash.js';
25
25
  // The body's way out by the keyboard: the codec owns the keys and the hint's element,
26
26
  // the visual tier's `strings` set its wording.
27
27
  export { DEFAULT_LEAVE_STRINGS } from './leave.js';
28
- export { wordDiff } from './review-diff.js';
29
28
  export { valueDiffPlugin, valueSpans } from './value-diff.js';
30
29
  export { reviewCaretPlugin } from './review-caret.js';
31
30
  export { asContent, planValue, valueChanges } from './value-plan.js';
@@ -35,7 +34,7 @@ export { asContent, planValue, valueChanges } from './value-plan.js';
35
34
  export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, LIST_KEYS, REVIEW_KEYS, editorShortcuts } from './shortcuts.js';
36
35
  // Schemas (the decode/encode target; the VisualEditor mounts them). `hasMarks` is
37
36
  // what a mark surface asks before offering itself over a leaf.
38
- export { blockSchema, inlineSchema, plaintextSchema, plainSchema, linesSchema, leafSchema, isParagraphsSchema, hasMarks } from './schema.js';
37
+ export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, isParagraphsSchema, hasMarks } from './schema.js';
39
38
  // The url edge: `rendersHref` is the link gate the prompt re-asks on submit, and
40
39
  // `storableUrl` the encode the store's own refusal requires of the value it takes
41
40
  // (`visual/links.ts`).
@@ -45,7 +44,7 @@ export { rendersHref, storableUrl } from './urls.js';
45
44
  // The barrel carries what has an off-barrel caller, and nothing else. A symbol
46
45
  // reached only by relative import within `codec/` stays off it: an export nothing
47
46
  // imports is surface that still has to stay honest.
48
- export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
47
+ export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent } from './decode.js';
49
48
  export { pmToContent, lower } from './encode.js';
50
49
  export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
51
50
  // Reconciliation gate.
@@ -0,0 +1,6 @@
1
+ import type { Quill } from '@quillmark/wasm';
2
+ type QuillSchema = Quill['schema'];
3
+ /** `quill.schema`, built once per handle: the getter rebuilds and serializes the whole schema on
4
+ * every read, and a handle's schema never changes. Shared, so read-only. */
5
+ export declare function schemaOf(quill: Quill): QuillSchema;
6
+ export {};
@@ -0,0 +1,9 @@
1
+ const schemas = new WeakMap();
2
+ /** `quill.schema`, built once per handle: the getter rebuilds and serializes the whole schema on
3
+ * every read, and a handle's schema never changes. Shared, so read-only. */
4
+ export function schemaOf(quill) {
5
+ let schema = schemas.get(quill);
6
+ if (!schema)
7
+ schemas.set(quill, (schema = quill.schema));
8
+ return schema;
9
+ }
@@ -130,7 +130,7 @@
130
130
  import ReviewRows from './ReviewRows.svelte';
131
131
  import { splitDeep, unrouted, type DeepDiagnostic } from './diagnostics.js';
132
132
  import { propertyDomIds } from './domid.js';
133
- import type { LandingBox } from './leaves.js';
133
+ import type { LandingBox, Subform } from './leaves.js';
134
134
  import { reorder, reorderArm } from './motion.js';
135
135
  import { rowDrag } from './rowdrag.svelte.js';
136
136
  import {
@@ -444,11 +444,6 @@
444
444
  // A table row's cells, on the same key: the subform a landing and the column-keeping
445
445
  // Enter hop reach into. Every table row is open, so there is one per row where the
446
446
  // list holds one per open row.
447
- type Subform = {
448
- focus: () => void;
449
- focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
450
- openPath: (steps: readonly PathStep[]) => Promise<void>;
451
- };
452
447
  const cellEls: Record<string, Subform | undefined> = $state({});
453
448
  let addEl: HTMLButtonElement | undefined = $state();
454
449
  let rowsEl: HTMLElement | undefined = $state();
@@ -13,6 +13,7 @@
13
13
  import Icon from './icons/Icon.svelte';
14
14
  import type { Document, Quill, Addr, Diagnostic, PathStep } from '@quillmark/wasm';
15
15
  import type { EditorErrorHandler } from '../core/errors.js';
16
+ import { schemaOf } from '../core/schema.js';
16
17
  import type { LeafRegistry } from './leaves.js';
17
18
  import type { CardModel, FieldModel } from './structure.js';
18
19
  import { placeFields, humanize, initialExpandedGroup, kindTitle, mountKey } from './structure.js';
@@ -462,7 +463,7 @@
462
463
 
463
464
  {#snippet kindOptions()}
464
465
  {#each kinds as k (k)}
465
- <option value={k}>{kindTitle(quill.schema[k], k)}</option>
466
+ <option value={k}>{kindTitle(schemaOf(quill)[k], k)}</option>
466
467
  {/each}
467
468
  {/snippet}
468
469
 
@@ -62,7 +62,7 @@
62
62
  schemaAt
63
63
  } from './structure.js';
64
64
  import { splitDeep, unrouted, type DeepDiagnostic } from './diagnostics.js';
65
- import type { LandingBox } from './leaves.js';
65
+ import type { LandingBox, Subform } from './leaves.js';
66
66
  import { propertyDomIds } from './domid.js';
67
67
  import { bloom } from '../core/bloom.js';
68
68
  import Icon from './icons/Icon.svelte';
@@ -198,11 +198,6 @@
198
198
  // The item boxes, the ticks, the title inputs and the column subforms, keyed by
199
199
  // member id — stable for the item's life. `$state` for the binding's sake
200
200
  // (`ArrayField` keeps its element refs the same way).
201
- type Subform = {
202
- focus: () => void;
203
- focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
204
- openPath: (steps: readonly PathStep[]) => Promise<void>;
205
- };
206
201
  const memberEls: Record<string, HTMLElement | undefined> = $state({});
207
202
  const tickEls: Record<string, HTMLInputElement | undefined> = $state({});
208
203
  const titleEls: Record<string, HTMLInputElement | undefined> = $state({});
@@ -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 { onDestroy, untrack } from 'svelte';
8
+ import { untrack } from 'svelte';
9
9
  import {
10
10
  createField,
11
11
  type FieldController,
@@ -15,7 +15,7 @@
15
15
  import type { LeafRegistry } from './leaves.js';
16
16
  import SlashMenu from './SlashMenu.svelte';
17
17
  import { wording } from './strings.js';
18
- import { review } from './review.svelte.js';
18
+ import { dropPlansOnLeave, review } from './review.svelte.js';
19
19
  import type { TextProposal } from './review.js';
20
20
  import './controls.css';
21
21
  import type { Document, Quill, Addr, Content, Diagnostic } from '@quillmark/wasm';
@@ -202,17 +202,7 @@
202
202
  (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }))
203
203
  );
204
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[] = [];
208
- $effect(() => {
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);
215
- });
205
+ dropPlansOnLeave(reviewing, () => proposed);
216
206
 
217
207
  // Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
218
208
  $effect(() => {
@@ -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 { onDestroy, untrack } from 'svelte';
48
+ import { 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';
@@ -76,7 +76,7 @@
76
76
  type TextCap
77
77
  } from '../core/codec/index.js';
78
78
  import { valueLeafSeat } from './leaves.js';
79
- import { review } from './review.svelte.js';
79
+ import { dropPlansOnLeave, review } from './review.svelte.js';
80
80
  import type { TextProposal } from './review.js';
81
81
  import { wording } from './strings.js';
82
82
  import './controls.css';
@@ -176,17 +176,7 @@
176
176
  litHere: () => drawnProposals.some((p) => p.lit),
177
177
  point: (id) => reviewing.point(id)
178
178
  });
179
- /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
180
- * list is answered, which would leave its own Accept writing its value whole. */
181
- let plannedIds: readonly string[] = [];
182
- $effect(() => {
183
- const ids = (proposed ?? []).map((p) => p.id);
184
- for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
185
- plannedIds = ids;
186
- });
187
- onDestroy(() => {
188
- for (const id of plannedIds) reviewing.planned(id, undefined);
189
- });
179
+ dropPlansOnLeave(reviewing, () => proposed);
190
180
 
191
181
  const t = wording();
192
182
  const seat = valueLeafSeat();
@@ -22,7 +22,7 @@
22
22
  import type { DeepDiagnostic } from './diagnostics.js';
23
23
  import { shownValue, splitReview, type DeepReview } from './review.js';
24
24
  import { review as reviewState } from './review.svelte.js';
25
- import type { LandingBox } from './leaves.js';
25
+ import type { LandingBox, Subform } from './leaves.js';
26
26
  import {
27
27
  VARIANT_DISCRIMINANT,
28
28
  commitDiscriminant,
@@ -107,11 +107,6 @@
107
107
  onCommit(next);
108
108
  }
109
109
 
110
- type Subform = {
111
- focus: () => void;
112
- focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
113
- openPath: (steps: readonly PathStep[]) => Promise<void>;
114
- };
115
110
  let cellsEl = $state<Subform | undefined>();
116
111
 
117
112
  /** Whether a step names a cell the live world draws. The one test the landing and
@@ -46,16 +46,15 @@
46
46
  import { createLifespan } from '../core/teardown.js';
47
47
  import { spacePx } from '../core/rungs.js';
48
48
  import { tooltips } from '../core/tooltip.js';
49
+ import { schemaOf } from '../core/schema.js';
49
50
  import type {
50
51
  Addr,
51
- CardAddr,
52
52
  Diagnostic,
53
53
  Document,
54
54
  PathStep,
55
55
  PayloadItem,
56
56
  QuillFieldSchema,
57
- Resolved,
58
- ResolvedField
57
+ Resolved
59
58
  } from '@quillmark/wasm';
60
59
  import type { VisualEditorProps } from './props.js';
61
60
  import type { Delta } from '../core/codec/positions.js';
@@ -215,7 +214,7 @@
215
214
  // card reorder.
216
215
  const commitErrors = new SvelteMap<string, RoutedDiagnostic>();
217
216
 
218
- const kinds = $derived(Object.keys(quill.schema).filter((k) => k !== 'main'));
217
+ const kinds = $derived(Object.keys(schemaOf(quill)).filter((k) => k !== 'main'));
219
218
 
220
219
  // The removal's step back (`undo.svelte.ts`), published so an array's row removal
221
220
  // offers on the same toast a card's does.
@@ -279,7 +278,7 @@
279
278
  if (!running || value === undefined || !shown || !Object.hasOwn(shown.values, name))
280
279
  return rederive();
281
280
  const fresh = fieldValues((isMain ? doc.main : doc.card(at)).payloadItems);
282
- const cardSchema = isMain ? quill.schema.main : quill.schema[shown.kind];
281
+ const cardSchema = schemaOf(quill)[isMain ? 'main' : shown.kind];
283
282
  patched = {
284
283
  ...patched,
285
284
  [id]: {
@@ -366,7 +365,7 @@
366
365
  };
367
366
  /** The session key of the card holding `$id` `id`. */
368
367
  function cardKeyFor(id: string): string | undefined {
369
- return cardIds.find((_, k) => doc.card(k).id === id);
368
+ return cardIds.find((_, k) => doc.cardId(k) === id);
370
369
  }
371
370
  /** The host's list with each card a path names moved to where that card stands now: the card
372
371
  * holding the item's `card`, else the one at the path's index when the list was set. */
@@ -376,12 +375,24 @@
376
375
  if (!review?.length) return review;
377
376
  if (was === now && !review.some((item) => 'card' in item && item.card !== undefined))
378
377
  return review;
378
+ let keys: Map<string, string> | undefined;
379
+ const keyOf = (id: string): string | undefined => {
380
+ if (!keys) {
381
+ keys = new Map();
382
+ const cards = doc.cards;
383
+ for (const [k, key] of now.entries()) {
384
+ const at = cards[k]?.id;
385
+ if (at != null && !keys.has(at)) keys.set(at, key);
386
+ }
387
+ }
388
+ return keys.get(id);
389
+ };
379
390
  return review.map((item) => {
380
391
  if (byCard(item)) return item;
381
392
  let field: DocPath;
382
393
  if (item.card === undefined) field = cardMoved(item.field, was, now);
383
394
  else {
384
- const key = cardKeyFor(item.card);
395
+ const key = keyOf(item.card);
385
396
  field = pathOnCard(item.field, key === undefined ? now.length : now.indexOf(key));
386
397
  }
387
398
  return field === item.field ? item : { ...item, field };
@@ -566,7 +577,7 @@
566
577
  text: string;
567
578
  } {
568
579
  const { add } = item;
569
- const schema = quill.schema[add.kind];
580
+ const schema = schemaOf(quill)[add.kind];
570
581
  const values = fieldValues(add.payloadItems);
571
582
  const named = (add.ext?.editor as { title?: unknown } | undefined)?.title;
572
583
  const title = cardTitle(
@@ -921,7 +932,7 @@
921
932
  if (!key?.field) return '';
922
933
  const isMain = key.card === undefined;
923
934
  const card = isMain ? model.main : model.cards[cardIndexOf(key.card as CardId)];
924
- const schema = isMain ? quill.schema.main : quill.schema[card?.kind ?? ''];
935
+ const schema = schemaOf(quill)[isMain ? 'main' : (card?.kind ?? '')];
925
936
  const sub = schema?.fields[key.field];
926
937
  return sub ? fieldTitle(key.field, sub) : humanize(key.field);
927
938
  }
@@ -1036,7 +1047,7 @@
1036
1047
  const { card: at, field } = addr;
1037
1048
  if (typeof at !== 'number' || field == null) return;
1038
1049
  const shown = model.cards[at];
1039
- const cardSchema = shown && quill.schema[shown.kind];
1050
+ const cardSchema = shown && schemaOf(quill)[shown.kind];
1040
1051
  if (!cardSchema || cardSchema.title?.trim()) return;
1041
1052
  const sub = Object.hasOwn(cardSchema.fields, field) ? cardSchema.fields[field] : undefined;
1042
1053
  if (!sub || !shortCell(sub)) return;
@@ -1251,7 +1262,7 @@
1251
1262
  const name =
1252
1263
  shown?.titleOverride ||
1253
1264
  shown?.titlePlaceholder ||
1254
- kindTitle(quill.schema[card.kind], card.kind);
1265
+ kindTitle(schemaOf(quill)[card.kind], card.kind);
1255
1266
  const gone = removed.remove(id, card, cardIds, i);
1256
1267
  doc.removeCard(i);
1257
1268
  arm.arm();
@@ -1476,7 +1487,7 @@
1476
1487
 
1477
1488
  const tree = $derived.by(() => {
1478
1489
  revision; // re-derive on every mutation
1479
- const schema = quill.schema;
1490
+ const schema = schemaOf(quill);
1480
1491
  const main = doc.main;
1481
1492
  const cards = doc.cards;
1482
1493
  // The provenance channel (FIELD_PROVENANCE): one whole-doc resolve per
@@ -2158,7 +2169,7 @@
2158
2169
  function declaredField(addr: Addr): QuillFieldSchema | undefined {
2159
2170
  if (addr.field == null) return undefined;
2160
2171
  const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
2161
- const schema = quill.schema;
2172
+ const schema = schemaOf(quill);
2162
2173
  const card = addr.card == null ? schema.main : kind ? schema[kind] : undefined;
2163
2174
  return card?.fields?.[addr.field];
2164
2175
  }
@@ -2420,7 +2431,7 @@
2420
2431
  <div class="qm-menu-surface" data-qm-root>
2421
2432
  {#each kinds as k (k)}
2422
2433
  <DropdownMenu.Item class="qm-menu-item" onSelect={() => addPicked(atIndex, k)}
2423
- >{kindTitle(quill.schema[k], k)}</DropdownMenu.Item
2434
+ >{kindTitle(schemaOf(quill)[k], k)}</DropdownMenu.Item
2424
2435
  >
2425
2436
  {/each}
2426
2437
  </div>
@@ -7,6 +7,12 @@ import type { FieldController, LeafViews } from '../core/codec/index.js';
7
7
  * the walk had to open something on the way.
8
8
  */
9
9
  export type LandingBox = HTMLElement | undefined | Promise<HTMLElement | undefined>;
10
+ /** A nested form's handle, as a container field holds one per row, column or variant. */
11
+ export type Subform = {
12
+ focus: () => void;
13
+ focusPath: (steps: readonly PathStep[], pos?: number) => LandingBox;
14
+ openPath: (steps: readonly PathStep[]) => Promise<void>;
15
+ };
10
16
  /**
11
17
  * A mounted field's landing handle: focus it, and the `.qm-wash` box the arrival wash
12
18
  * plays over ({@link import('../core/bloom.js').bloom}).
@@ -1,4 +1,5 @@
1
1
  import { addrForFieldPath, fieldPathForAddr } from '../core/address.js';
2
+ import { schemaOf } from '../core/schema.js';
2
3
  import { asContent, lineRuns } from '../core/codec/value-plan.js';
3
4
  import { byBlocks, sameValue } from './review.js';
4
5
  import { VARIANT_DISCRIMINANT, baseType, fieldValues, textKind } from './structure.js';
@@ -37,9 +38,12 @@ let minted = 0;
37
38
  export function proposalsBetween(quill, base, answer, opts = {}) {
38
39
  const { mint = () => `review-${minted++}`, label } = typeof opts === 'function' ? { mint: opts } : opts;
39
40
  const items = [];
40
- const kinds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).kind);
41
- const baseIds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).id ?? '');
42
- const answerIds = Array.from({ length: answer.cardCount }, (_, i) => answer.card(i).id ?? '');
41
+ const schemas = schemaOf(quill);
42
+ const baseCards = base.cards;
43
+ const answerCards = answer.cards;
44
+ const kinds = baseCards.map((c) => c.kind);
45
+ const baseIds = baseCards.map((c) => c.id ?? '');
46
+ const answerIds = answerCards.map((c) => c.id ?? '');
43
47
  const pathOf = (at, field, steps = []) => fieldPathForAddr(addrOf(at, field), kinds, steps);
44
48
  const diffCard = (schema, at, was, now, answerAt) => {
45
49
  const before = fieldValues(was.payloadItems);
@@ -182,21 +186,21 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
182
186
  });
183
187
  }
184
188
  };
185
- diffCard(quill.schema.main, undefined, base.main, answer.main, undefined);
189
+ diffCard(schemas.main, undefined, base.main, answer.main, undefined);
186
190
  /** The base's index of each card the answer keeps as it was, by its answer index. */
187
191
  const kept = new Map();
188
192
  const removed = [];
189
193
  for (const [at, id] of baseIds.entries()) {
190
194
  const answerAt = answerIds.indexOf(id);
191
- const was = base.card(at);
192
- const now = answerAt < 0 ? undefined : answer.card(answerAt);
195
+ const was = baseCards[at];
196
+ const now = answerAt < 0 ? undefined : answerCards[answerAt];
193
197
  if (!now || now.kind !== was.kind) {
194
198
  removed.push(at);
195
199
  continue;
196
200
  }
197
201
  kept.set(answerAt, at);
198
202
  const first = items.length;
199
- diffCard(quill.schema[was.kind], at, was, now, answerAt);
203
+ diffCard(schemas[was.kind], at, was, now, answerAt);
200
204
  if (id)
201
205
  for (const item of items.slice(first))
202
206
  Object.assign(item, { card: id });
@@ -210,7 +214,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
210
214
  const after = kept.get(lead);
211
215
  items.push({
212
216
  id: mint(),
213
- add: answer.card(at),
217
+ add: answerCards[at],
214
218
  ...(after !== undefined && { after }),
215
219
  ...(after !== undefined && baseIds[after] && { afterCard: baseIds[after] })
216
220
  });
@@ -208,18 +208,6 @@ export declare function reviewText(value: unknown, words: {
208
208
  on: string;
209
209
  off: string;
210
210
  }): string;
211
- /** A stretch of a proposal as a reader is shown it: kept, struck, or tinted. */
212
- export interface ReviewRun {
213
- text: string;
214
- kind?: 'del' | 'ins';
215
- }
216
- type Words = {
217
- on: string;
218
- off: string;
219
- };
220
- /** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
221
- * two lists by their members, two records by their keys; any other pair differs whole. */
222
- export declare function reviewRuns(before: unknown, after: unknown, words: Words): ReviewRun[];
223
211
  /** A proposal a leaf of words draws over its own value: what it would write, and the value its
224
212
  * writer read where it says, each as the leaf's content. */
225
213
  export interface TextProposal {
@@ -245,4 +233,3 @@ export declare function shownValue(item: FieldProposal | undefined, stored: unkn
245
233
  /** Whether a value a reader commits is the one a proposal would write: a blank and an unset value
246
234
  * are one, since a control cleared over a default commits `''`. */
247
235
  export declare function writesProposed(value: unknown, after: unknown): boolean;
248
- export {};
@@ -1,4 +1,4 @@
1
- import { asContent, wordDiff } from '../core/codec/index.js';
1
+ import { asContent } from '../core/codec/index.js';
2
2
  /** Whether an item proposes a whole card. */
3
3
  export const byCard = (item) => 'add' in item || 'remove' in item;
4
4
  /** Whether an item names blocks of a rich text field, which its prose leaf draws. */
@@ -167,110 +167,6 @@ export function reviewText(value, words) {
167
167
  .map(([key, v]) => `${key}: ${v}`)
168
168
  .join('; ');
169
169
  }
170
- const prose = (v) => typeof v === 'string' || (typeof v === 'object' && v !== null && 'text' in v);
171
- const record = (v) => typeof v === 'object' && v !== null && !Array.isArray(v) && !prose(v);
172
- const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
173
- function whole(before, after) {
174
- return [
175
- ...(before ? [{ text: before, kind: 'del' }] : []),
176
- ...(after ? [{ text: after, kind: 'ins' }] : [])
177
- ];
178
- }
179
- function joined(parts, by) {
180
- return parts.filter((p) => p.length).flatMap((p, i) => (i ? [{ text: by }, ...p] : p));
181
- }
182
- /** The keys of two records that differ, each as `key: ` with what goes struck and what comes
183
- * tinted. */
184
- function recordRuns(before, after, words) {
185
- const keys = [...new Set([...Object.keys(after), ...Object.keys(before)])];
186
- return joined(keys
187
- .filter((key) => !same(before[key], after[key]))
188
- .map((key) => {
189
- const runs = whole(reviewText(before[key], words), reviewText(after[key], words));
190
- return runs.length ? [{ text: `${key}: ` }, ...runs] : [];
191
- }), '; ');
192
- }
193
- /** Two lists by their members, in order: a member both hold is kept, one only `before` holds is
194
- * struck, one only `after` holds is tinted. In a list of records a kept record is left out, and a
195
- * record struck where one is tinted reads as the keys the two differ in. */
196
- function listRuns(before, after, words) {
197
- const n = before.length;
198
- const m = after.length;
199
- const common = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
200
- for (let i = n - 1; i >= 0; i--)
201
- for (let j = m - 1; j >= 0; j--)
202
- common[i][j] = same(before[i], after[j])
203
- ? common[i + 1][j + 1] + 1
204
- : Math.max(common[i + 1][j], common[i][j + 1]);
205
- const records = [...before, ...after].some(record);
206
- /** A record edited in place, named by its first value where that stays, so a reader can tell
207
- * which of the list it is with the records kept left out. */
208
- const edited = (was, now) => {
209
- const first = Object.keys(now)[0];
210
- const name = first !== undefined && same(was[first], now[first]) && reviewText(now[first], words);
211
- const runs = recordRuns(was, now, words);
212
- return name ? [{ text: `${name} (` }, ...runs, { text: ')' }] : runs;
213
- };
214
- const parts = [];
215
- let gone = [];
216
- let come = [];
217
- const flush = () => {
218
- const pairs = records ? Math.min(gone.length, come.length) : 0;
219
- for (let k = 0; k < pairs; k++)
220
- parts.push(record(gone[k]) && record(come[k])
221
- ? edited(gone[k], come[k])
222
- : whole(reviewText(gone[k], words), reviewText(come[k], words)));
223
- for (const v of gone.slice(pairs))
224
- parts.push(whole(reviewText(v, words), ''));
225
- for (const v of come.slice(pairs))
226
- parts.push(whole('', reviewText(v, words)));
227
- gone = [];
228
- come = [];
229
- };
230
- let i = 0;
231
- let j = 0;
232
- while (i < n || j < m) {
233
- if (i < n && j < m && same(before[i], after[j])) {
234
- flush();
235
- if (!records)
236
- parts.push([{ text: reviewText(before[i], words) }]);
237
- i++;
238
- j++;
239
- }
240
- else if (j < m && (i === n || common[i][j + 1] >= common[i + 1][j]))
241
- come.push(after[j++]);
242
- else
243
- gone.push(before[i++]);
244
- }
245
- flush();
246
- return joined(parts, ', ');
247
- }
248
- /** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
249
- * two lists by their members, two records by their keys; any other pair differs whole. */
250
- export function reviewRuns(before, after, words) {
251
- if (Array.isArray(before) && Array.isArray(after) && before.length && after.length)
252
- return listRuns(before, after, words);
253
- if (record(before) && record(after))
254
- return recordRuns(before, after, words);
255
- const was = reviewText(before, words);
256
- const now = reviewText(after, words);
257
- if (!prose(before) || !prose(after) || !was || !now)
258
- return whole(was, now);
259
- const out = [];
260
- let at = 0;
261
- for (const hunk of wordDiff(was, now)) {
262
- if (hunk.at > at)
263
- out.push({ text: was.slice(at, hunk.at) });
264
- if (hunk.end > hunk.at)
265
- out.push({ text: was.slice(hunk.at, hunk.end), kind: 'del' });
266
- if (hunk.insert)
267
- out.push({ text: hunk.insert, kind: 'ins' });
268
- at = hunk.end;
269
- }
270
- if (at < was.length)
271
- out.push({ text: was.slice(at) });
272
- return out;
273
- }
274
170
  /** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
275
171
  * is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
276
172
  export function textProposal(item, cleared) {
@@ -143,3 +143,9 @@ export declare function createReview(source: ReviewSource): Review;
143
143
  export declare function setReview(review: Review): void;
144
144
  /** The editor's review state, or {@link NO_REVIEW} off-tree. */
145
145
  export declare function review(): Review;
146
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
147
+ * list is answered, which would leave its own Accept writing its value whole. Called during
148
+ * a leaf's init. */
149
+ export declare function dropPlansOnLeave(reviewing: Review, proposed: () => readonly {
150
+ id: string;
151
+ }[] | undefined): void;
@@ -13,7 +13,7 @@
13
13
  // empties it: an inverse is good against the document it was recorded over. An answer's own
14
14
  // writes, and an inverse's, go down the lanes an edit does, so they are flagged while they are
15
15
  // made.
16
- import { getContext, setContext } from 'svelte';
16
+ import { getContext, onDestroy, setContext } from 'svelte';
17
17
  import { SvelteMap } from 'svelte/reactivity';
18
18
  import { asContent, planValue } from '../core/codec/index.js';
19
19
  import { byBlocks, byCard, locate, onField, putsIn, sameValue, textProposal, valueIn, writesProposed } from './review.js';
@@ -541,3 +541,20 @@ const NO_REVIEW = {
541
541
  export function review() {
542
542
  return getContext(KEY) ?? NO_REVIEW;
543
543
  }
544
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
545
+ * list is answered, which would leave its own Accept writing its value whole. Called during
546
+ * a leaf's init. */
547
+ export function dropPlansOnLeave(reviewing, proposed) {
548
+ let plannedIds = [];
549
+ $effect(() => {
550
+ const ids = (proposed() ?? []).map((p) => p.id);
551
+ for (const id of plannedIds)
552
+ if (!ids.includes(id))
553
+ reviewing.planned(id, undefined);
554
+ plannedIds = ids;
555
+ });
556
+ onDestroy(() => {
557
+ for (const id of plannedIds)
558
+ reviewing.planned(id, undefined);
559
+ });
560
+ }
@@ -735,7 +735,7 @@ export class IdSeq {
735
735
  export function placeCardInto(target, card, at) {
736
736
  const { id, ...bare } = card;
737
737
  const free = id !== undefined &&
738
- !Array.from({ length: target.cardCount }, (_, k) => target.card(k).id).includes(id);
738
+ !Array.from({ length: target.cardCount }, (_, k) => target.cardId(k)).includes(id);
739
739
  try {
740
740
  target.unchecked.insertCard(free ? card : bare, at);
741
741
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quillmark/svelte",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "Editor, live-preview and source surfaces over a Quillmark WASM session.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -69,7 +69,7 @@
69
69
  "check": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings"
70
70
  },
71
71
  "peerDependencies": {
72
- "@quillmark/wasm": ">=0.140.0-0",
72
+ "@quillmark/wasm": ">=0.142.0-0",
73
73
  "svelte": "^5.33.0"
74
74
  },
75
75
  "dependencies": {