@quillmark/svelte 0.37.1 → 0.38.1

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.
@@ -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
  }
@@ -54,7 +59,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
54
59
  };
55
60
  const blocks = (field, from, fromAddr, to, toAddr) => {
56
61
  const was = blocksOf(from, fromAddr);
57
- const now = blocksOf(to, toAddr);
62
+ const now = leading(was, blocksOf(to, toAddr));
58
63
  const nowById = new Map(now.map((b) => [b.id, b]));
59
64
  for (const b of was) {
60
65
  const next = nowById.get(b.id);
@@ -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);
@@ -211,6 +231,33 @@ const addrOf = (card, field) => ({
211
231
  ...(card !== undefined && { card }),
212
232
  ...(field !== undefined && { field })
213
233
  });
234
+ /**
235
+ * `now` with the first block's id on the block that is the first block read: a rewrite keeps that
236
+ * id on whichever block it puts first, so blocks added above the first read as its rewrite.
237
+ *
238
+ * Of the blocks ahead of the next one `now` keeps, the first reading as the first block did is it,
239
+ * or, where the block put first is of another kind, the first of the first block's kind. The block
240
+ * put first then takes an id `was` does not hold, so it and those after it up to that block are
241
+ * added before it.
242
+ */
243
+ function leading(was, now) {
244
+ const first = was[0];
245
+ if (!first || now[0]?.id !== first.id || now[0].markdown === first.markdown)
246
+ return now;
247
+ const held = new Set(was.map((b) => b.id));
248
+ let end = 1;
249
+ while (end < now.length && !held.has(now[end].id))
250
+ end++;
251
+ const ahead = now.slice(1, end);
252
+ const at = ahead.findIndex((b) => b.markdown === first.markdown) + 1 ||
253
+ (now[0].kind !== first.kind && ahead.findIndex((b) => b.kind === first.kind) + 1);
254
+ if (!at)
255
+ return now;
256
+ let added = `${first.id}+`;
257
+ while (held.has(added))
258
+ added += '+';
259
+ return now.map((b, i) => (i === 0 ? { ...b, id: added } : i === at ? { ...b, id: first.id } : b));
260
+ }
214
261
  /** The blocks of the value at `addr`, none where it holds none. */
215
262
  function blocksOf(doc, addr) {
216
263
  try {
@@ -233,8 +280,7 @@ function keysOf(declared, ...values) {
233
280
  /**
234
281
  * The runs where two lists differ, members matched by value along their longest common run:
235
282
  * 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.
283
+ * pairs its members as changes, and takes out, appends or puts in the rest.
238
284
  */
239
285
  function aligned(was, now) {
240
286
  const m = was.length;
@@ -253,16 +299,12 @@ function aligned(was, now) {
253
299
  const close = () => {
254
300
  const removed = i - from;
255
301
  const added = j - to;
256
- if (added > removed && i < m)
257
- return false;
258
302
  if (removed || added)
259
303
  runs.push({ from, to, removed, added });
260
- return true;
261
304
  };
262
305
  while (i < m && j < n) {
263
306
  if (sameValue(was[i], now[j])) {
264
- if (!close())
265
- return undefined;
307
+ close();
266
308
  i++;
267
309
  j++;
268
310
  from = i;
@@ -275,5 +317,6 @@ function aligned(was, now) {
275
317
  }
276
318
  i = m;
277
319
  j = n;
278
- return close() ? runs : undefined;
320
+ close();
321
+ return runs;
279
322
  }
@@ -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,10 @@ 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. A member named with no `before`
22
+ * read nothing there, so it is new: it appends, and the appends of one list stand in their
23
+ * indices' order whichever is taken first.
21
24
  * - `add` or `remove`: a whole card, proposed new or proposed taken out (`CardProposal`).
22
25
  *
23
26
  * A `field` on a card names the card by its index, read against the cards as they stood when
@@ -152,7 +155,15 @@ export type FieldProposal = {
152
155
  card?: string;
153
156
  before?: unknown;
154
157
  after?: unknown;
158
+ /** The member a run of members proposed new inside a list goes in front of, as its writer
159
+ * read the list at the path's index; `after` then holds the members, in order. */
160
+ ahead?: unknown;
155
161
  };
162
+ /** Whether a field item at `steps` puts new members into a list: in front of one it holds
163
+ * (`ahead`), or as a member it names by an index and read nothing at, which appends. */
164
+ export declare const putsIn: (item: FieldProposal, steps: readonly PathStep[]) => boolean;
165
+ /** The members an item that puts some into a list adds, in order. */
166
+ export declare const membersOf: (item: FieldProposal) => unknown[];
156
167
  /** A field item routed past its field: the steps from the rung it is handed to down to the
157
168
  * value it names, a member of a list by its index, a cell of a record by its key. */
158
169
  export interface DeepReview {
@@ -170,13 +181,21 @@ export declare function valueIn(value: unknown, steps: readonly PathStep[]): unk
170
181
  /** `value` with what `steps` reach set to `to`: a list's member past its end appended, and one
171
182
  * set to nothing taken out; a record's cell set to nothing left out. Copies on the way down. */
172
183
  export declare function valueWith(value: unknown, steps: readonly PathStep[], to: unknown): unknown;
184
+ /** `value` with `members` put into the list `steps` reach, in front of the member at its last
185
+ * step, or at its end past the last. */
186
+ export declare function valueInserting(value: unknown, steps: readonly PathStep[], members: readonly unknown[]): unknown;
173
187
  /**
174
188
  * Where a field proposal's steps land in `value` as it stands. A list's member is found by its
175
189
  * index where it holds `before`, else as the nearest member holding `before` that `claimed`
176
190
  * 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.
191
+ * wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
192
+ * none. `found` is false where the proposal has a `before` or an `ahead` nothing holds.
193
+ *
194
+ * An append lands at the list's end, in front of the members at its end that `later` holds in
195
+ * order: what the appends of its run at higher indices add, so appends taken in any order
196
+ * stand in their indices' order.
178
197
  */
179
- export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal, claimed: Set<string>): {
198
+ export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal, claimed: Set<string>, later?: readonly unknown[]): {
180
199
  steps: readonly PathStep[];
181
200
  found: boolean;
182
201
  };
@@ -211,6 +230,9 @@ export interface TextProposal {
211
230
  /** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
212
231
  * is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
213
232
  export declare function textProposal(item: FieldProposal | undefined, cleared?: Content): TextProposal | undefined;
233
+ /** A place's proposals over a leaf of words, each run of one answer, or `undefined` where any
234
+ * of them is not words or there are none. */
235
+ export declare function textsOf(items: readonly FieldProposal[], cleared?: Content): TextProposal[] | undefined;
214
236
  /** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
215
237
  * for one that clears it, which the input shows as what Accept leaves. */
216
238
  export declare function numberProposal(item: FieldProposal | undefined): {
@@ -11,6 +11,12 @@ export const NO_PROJECTION = {
11
11
  toProjection: (at) => at,
12
12
  toLive: (at) => at
13
13
  };
14
+ /** Whether a field item at `steps` puts new members into a list: in front of one it holds
15
+ * (`ahead`), or as a member it names by an index and read nothing at, which appends. */
16
+ export const putsIn = (item, steps) => 'ahead' in item ||
17
+ (typeof steps.at(-1) === 'number' && !('before' in item) && item.after !== undefined);
18
+ /** The members an item that puts some into a list adds, in order. */
19
+ export const membersOf = (item) => 'ahead' in item && Array.isArray(item.after) ? item.after : [item.after];
14
20
  /** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
15
21
  * the step they take next, that step consumed. */
16
22
  export function splitReview(list) {
@@ -64,13 +70,28 @@ export function valueWith(value, steps, to) {
64
70
  record[step] = next;
65
71
  return record;
66
72
  }
73
+ /** `value` with `members` put into the list `steps` reach, in front of the member at its last
74
+ * step, or at its end past the last. */
75
+ export function valueInserting(value, steps, members) {
76
+ const head = steps.slice(0, -1);
77
+ const held = valueIn(value, head);
78
+ const list = Array.isArray(held) ? [...held] : [];
79
+ const at = steps.at(-1);
80
+ list.splice(typeof at === 'number' ? Math.min(at, list.length) : list.length, 0, ...members);
81
+ return valueWith(value, head, list);
82
+ }
67
83
  /**
68
84
  * Where a field proposal's steps land in `value` as it stands. A list's member is found by its
69
85
  * index where it holds `before`, else as the nearest member holding `before` that `claimed`
70
86
  * does not already hold, so one member taken out does not move another's proposal onto the
71
- * wrong row. `found` is false where the proposal has a `before` nothing holds.
87
+ * wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
88
+ * none. `found` is false where the proposal has a `before` or an `ahead` nothing holds.
89
+ *
90
+ * An append lands at the list's end, in front of the members at its end that `later` holds in
91
+ * order: what the appends of its run at higher indices add, so appends taken in any order
92
+ * stand in their indices' order.
72
93
  */
73
- export function locate(value, steps, item, claimed) {
94
+ export function locate(value, steps, item, claimed, later = []) {
74
95
  const read = 'before' in item;
75
96
  const before = read ? item.before : undefined;
76
97
  const at = steps.at(-1);
@@ -80,6 +101,23 @@ export function locate(value, steps, item, claimed) {
80
101
  claimed.add(JSON.stringify(out));
81
102
  return out;
82
103
  };
104
+ if (putsIn(item, steps) && !('ahead' in item)) {
105
+ const members = Array.isArray(list) ? list : [];
106
+ let i = members.length;
107
+ for (const member of [...later].reverse())
108
+ if (i > 0 && sameValue(members[i - 1], member))
109
+ i--;
110
+ return { steps: [...head, i], found: true };
111
+ }
112
+ if ('ahead' in item) {
113
+ if (typeof at !== 'number' || !Array.isArray(list))
114
+ return { steps, found: false };
115
+ for (let d = 0; d <= Math.max(at, list.length - 1 - at); d++)
116
+ for (const i of d ? [at - d, at + d] : [at])
117
+ if (i >= 0 && i < list.length && sameValue(list[i], item.ahead))
118
+ return { steps: [...head, i], found: true };
119
+ return { steps, found: false };
120
+ }
83
121
  if (!read || before === undefined || typeof at !== 'number' || !Array.isArray(list)) {
84
122
  const found = !read || sameValue(valueIn(value, steps), before);
85
123
  return { steps: claim(steps), found };
@@ -244,6 +282,12 @@ export function textProposal(item, cleared) {
244
282
  return undefined;
245
283
  return { id: item.id, after, ...(before && { before }) };
246
284
  }
285
+ /** A place's proposals over a leaf of words, each run of one answer, or `undefined` where any
286
+ * of them is not words or there are none. */
287
+ export function textsOf(items, cleared) {
288
+ const list = items.map((item) => textProposal(item, cleared));
289
+ return list.length && list.every((p) => p !== undefined) ? list : undefined;
290
+ }
247
291
  /** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
248
292
  * for one that clears it, which the input shows as what Accept leaves. */
249
293
  export function numberProposal(item) {
@@ -32,7 +32,8 @@ export interface Review {
32
32
  id: string;
33
33
  reason: ReviewUndrawn;
34
34
  }[];
35
- /** The field proposals whose field no longer holds the value their `before` says was read. */
35
+ /** The field proposals whose field no longer holds the value their `before` says was read,
36
+ * and the removals of a card the reader has written in since they arrived. */
36
37
  readonly fieldOutdated: ReadonlySet<string>;
37
38
  /** The open items drawn, in the page's order. */
38
39
  readonly order: readonly string[];
@@ -48,8 +49,11 @@ export interface Review {
48
49
  * each with the steps to the value it names as the field holds it now. */
49
50
  at(key: string): {
50
51
  proposed?: FieldProposal;
52
+ more?: readonly FieldProposal[];
51
53
  nested?: readonly DeepReview[];
52
54
  };
55
+ /** What the appends of item `id`'s run at higher indices add, in index order (`locate`). */
56
+ later(id: string): readonly unknown[];
53
57
  /** Whether anything draws at leaf `key`: a field's own item, or a text item in its leaf. */
54
58
  marks(key: string): boolean;
55
59
  /** The leaf drawing item `id`, where one does. */
@@ -68,6 +72,9 @@ export interface Review {
68
72
  answer(ids: readonly string[] | 'all', action: 'accept' | 'dismiss'): string[];
69
73
  /** An edit landed that is no answer's: the answers before it can no longer be taken back. */
70
74
  settled(): void;
75
+ /** The reader wrote in a field or the body of the card at session key `card`: a removal
76
+ * standing on it is outdated, an answer's own write excepted. */
77
+ edited(card: string): void;
71
78
  /** A reader's commit of `value` on a control that shows one value, under the proposal `id`:
72
79
  * the proposed value accepts it, any other is written and dismisses it, both one answer.
73
80
  * False where it could not be made, and the commit is the caller's. */
@@ -16,8 +16,16 @@
16
16
  import { getContext, setContext } from 'svelte';
17
17
  import { SvelteMap } from 'svelte/reactivity';
18
18
  import { asContent, planValue } from '../core/codec/index.js';
19
- import { byBlocks, byCard, locate, onField, sameValue, textProposal, valueIn, writesProposed } from './review.js';
19
+ import { byBlocks, byCard, locate, onField, putsIn, sameValue, textProposal, valueIn, writesProposed } from './review.js';
20
20
  import { orderOf } from './review-order.js';
21
+ /** Whether two proposals on one place are runs of one answer over its words: each reads the
22
+ * value its writer read alike, and writes words. A place takes every such run. */
23
+ const runsOfOne = (a, b) => 'before' in a &&
24
+ 'before' in b &&
25
+ sameValue(a.before, b.before) &&
26
+ asContent(a.after) !== undefined &&
27
+ asContent(b.after) !== undefined &&
28
+ asContent(a.before) !== undefined;
21
29
  export function createReview(source) {
22
30
  /** The ids answered, each until a list arrives without it. */
23
31
  const answered = new Set();
@@ -102,6 +110,30 @@ export function createReview(source) {
102
110
  const key = listed[item.after];
103
111
  return key !== undefined && standing.has(key) ? key : 'end';
104
112
  }
113
+ /** What the appends of each append's run at higher indices add, in index order, by its id:
114
+ * read off the host's whole list, answered items with it, since an accepted one's member
115
+ * is what a later-taken one lands in front of. */
116
+ const later = $derived.by(() => {
117
+ const runs = new Map();
118
+ for (const item of source.items() ?? []) {
119
+ if (!onField(item) || source.exact(item.field))
120
+ continue;
121
+ const deep = source.nested(item.field);
122
+ const at = deep?.steps.at(-1);
123
+ if (!deep || typeof at !== 'number' || 'ahead' in item || !putsIn(item, deep.steps))
124
+ continue;
125
+ const run = `${deep.key} ${JSON.stringify(deep.steps.slice(0, -1))}`;
126
+ runs.set(run, [...(runs.get(run) ?? []), { at, id: item.id, after: item.after }]);
127
+ }
128
+ const out = new Map();
129
+ for (const run of runs.values())
130
+ for (const { at, id } of run)
131
+ out.set(id, run
132
+ .filter((other) => other.at > at)
133
+ .sort((a, b) => a.at - b.at)
134
+ .map((other) => other.after));
135
+ return out;
136
+ });
105
137
  const placed = $derived.by(() => {
106
138
  const out = new Map();
107
139
  const undrawn = [...cards.undrawn];
@@ -125,8 +157,10 @@ export function createReview(source) {
125
157
  const claimed = claims.get(deep.key) ?? new Set();
126
158
  claims.set(deep.key, claimed);
127
159
  const held = out.get(deep.key) ?? {};
128
- const { steps, found } = locate(deep.value, deep.steps, item, claimed);
129
- if ((held.nested ?? []).some((e) => sameValue(e.steps, steps))) {
160
+ const adds = putsIn(item, deep.steps);
161
+ const { steps, found } = locate(deep.value, deep.steps, item, claimed, later.get(item.id));
162
+ if (!adds &&
163
+ (held.nested ?? []).some((e) => sameValue(e.steps, steps) && !putsIn(e.item, e.steps) && !runsOfOne(e.item, item))) {
130
164
  undrawn.push({ id: item.id, reason: 'taken' });
131
165
  continue;
132
166
  }
@@ -143,7 +177,10 @@ export function createReview(source) {
143
177
  }
144
178
  const held = out.get(key) ?? {};
145
179
  if (held.proposed !== undefined) {
146
- undrawn.push({ id: item.id, reason: 'taken' });
180
+ if (runsOfOne(held.proposed, item))
181
+ held.more = [...(held.more ?? []), item];
182
+ else
183
+ undrawn.push({ id: item.id, reason: 'taken' });
147
184
  continue;
148
185
  }
149
186
  held.proposed = item;
@@ -152,17 +189,23 @@ export function createReview(source) {
152
189
  return { fields: out, undrawn, moved };
153
190
  });
154
191
  const fields = $derived(placed.fields);
192
+ /** The removals the reader has written in the card of since they arrived, each by the item
193
+ * it was recorded against, so a list set anew reads its removals afresh. */
194
+ const touched = new SvelteMap();
155
195
  /** Each proposal of words a leaf draws, by id: how it stands against what the leaf holds. */
156
196
  const carried = new SvelteMap();
157
- // A proposal made from a value the field no longer holds would write over the reader's. One a
158
- // leaf of words carries is outdated only where the reader's writing meets it.
197
+ // A proposal made from a value the field no longer holds would write over the reader's, as a
198
+ // removal would take what the reader wrote in its card. One a leaf of words carries is
199
+ // outdated only where the reader's writing meets it.
159
200
  const outdated = $derived.by(() => {
160
201
  const out = new Set(placed.moved);
161
- for (const { proposed } of fields.values())
162
- if (proposed &&
163
- 'before' in proposed &&
164
- !sameValue(source.valueAt(proposed.field), proposed.before))
165
- out.add(proposed.id);
202
+ for (const item of cards.removes.values())
203
+ if (touched.get(item.id) === item)
204
+ out.add(item.id);
205
+ for (const { proposed, more } of fields.values())
206
+ for (const p of proposed ? [proposed, ...(more ?? [])] : [])
207
+ if ('before' in p && !sameValue(source.valueAt(p.field), p.before))
208
+ out.add(p.id);
166
209
  for (const [id, state] of carried)
167
210
  if (state === 'outdated')
168
211
  out.add(id);
@@ -330,6 +373,7 @@ export function createReview(source) {
330
373
  return place && valueIn(place.value, place.steps);
331
374
  },
332
375
  at: (key) => fields.get(key) ?? {},
376
+ later: (id) => later.get(id) ?? [],
333
377
  marks: (key) => fields.has(key) || !!drawn.get(key)?.ids.length,
334
378
  keyOf(id) {
335
379
  const item = byId.get(id);
@@ -404,6 +448,13 @@ export function createReview(source) {
404
448
  offer = undefined;
405
449
  source.undo.settle();
406
450
  },
451
+ edited(card) {
452
+ if (writing)
453
+ return;
454
+ const item = cards.removes.get(card);
455
+ if (item && touched.get(item.id) !== item)
456
+ touched.set(item.id, item);
457
+ },
407
458
  answerWith(id, value) {
408
459
  const item = byId.get(id);
409
460
  if (!item || !onField(item))
@@ -462,6 +513,7 @@ const NO_REVIEW = {
462
513
  cards: { adds: new Map(), removes: new Map() },
463
514
  wrote() { },
464
515
  at: () => ({}),
516
+ later: () => [],
465
517
  marks: () => false,
466
518
  keyOf: () => undefined,
467
519
  drew() { },
@@ -469,6 +521,7 @@ const NO_REVIEW = {
469
521
  act: () => false,
470
522
  answer: () => [],
471
523
  settled() { },
524
+ edited() { },
472
525
  answerWith: () => false,
473
526
  planned() { },
474
527
  current: () => undefined,
@@ -18,7 +18,7 @@ export interface FieldModel {
18
18
  label: string;
19
19
  /** Chrome-only; never gates. */
20
20
  description: string | undefined;
21
- /** Prose-leaf flags: {@link oneLine}, {@link literalText} and {@link linesOnly}. */
21
+ /** Prose-leaf flags, from {@link leafFlags}. */
22
22
  inline: boolean;
23
23
  plaintext: boolean;
24
24
  paragraphs: boolean;
@@ -141,13 +141,21 @@ export declare function optionalCell(f: QuillFieldSchema): boolean;
141
141
  * nothing else.
142
142
  */
143
143
  export declare function baseType(f: QuillFieldSchema): QuillFieldType;
144
- /** Whether a content field is one line: one paragraph, no container, no island. A `text`
145
- * or `richtext` field is one line unless it declares a `shape`. */
146
- export declare function oneLine(f: QuillFieldSchema): boolean;
147
- /** Whether a `richtext` field holds formatted lines and no block: `shape: lines`. */
148
- export declare function linesOnly(f: QuillFieldSchema): boolean;
149
- /** Whether a content field's codec is the literal one: `text`. */
150
- export declare function literalText(f: QuillFieldSchema): boolean;
144
+ /** A text field's kind: how its characters read, literally (`text`) or as marks (`richtext`), and
145
+ * how much it holds, each shape holding all the one before it does. */
146
+ export interface TextKind {
147
+ type: 'text' | 'richtext';
148
+ shape: 'line' | 'lines' | 'blocks';
149
+ }
150
+ /** A field's text kind, read once from its schema; `undefined` for a field that is not text. A
151
+ * field that declares no `shape` is one line. */
152
+ export declare function textKind(f: QuillFieldSchema): TextKind | undefined;
153
+ /** What a prose leaf is built from: the kind, spelled as the leaf schema reads it. */
154
+ export declare function leafFlags(f: QuillFieldSchema | undefined): {
155
+ inline: boolean;
156
+ plaintext: boolean;
157
+ paragraphs: boolean;
158
+ };
151
159
  /** The character cap a content field's `max:` declares, `undefined` on any other. */
152
160
  export declare function textCap(f: QuillFieldSchema | undefined): TextCap | undefined;
153
161
  /**
@@ -165,7 +173,7 @@ export declare function printedText(v: unknown): string | undefined;
165
173
  */
166
174
  export declare function declaredContent(v: unknown, markdown: boolean): Content | undefined;
167
175
  /** A field's `{#each}` key: its name and what a mounted leaf reads once, its type,
168
- * {@link oneLine} and `max:`, and its elements'. A retype or a quill swap that changes
176
+ * `shape` and `max:`, and its elements'. A retype or a quill swap that changes
169
177
  * any of them under a name remounts the field, where a kept leaf would commit on the old
170
178
  * schema. */
171
179
  export declare function mountKey(name: string, f: QuillFieldSchema): string;