@quillmark/svelte 0.38.0 → 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.
- package/dist/core/codec/field.js +7 -3
- package/dist/core/codec/review.d.ts +2 -1
- package/dist/core/codec/review.js +56 -11
- package/dist/visual/ArrayField.svelte +13 -12
- package/dist/visual/VisualEditorInner.svelte +12 -5
- package/dist/visual/proposals.js +28 -1
- package/dist/visual/review.d.ts +14 -5
- package/dist/visual/review.js +21 -5
- package/dist/visual/review.svelte.d.ts +2 -0
- package/dist/visual/review.svelte.js +30 -4
- package/package.json +1 -1
package/dist/core/codec/field.js
CHANGED
|
@@ -470,7 +470,7 @@ export function createField(opts) {
|
|
|
470
470
|
if (change) {
|
|
471
471
|
const asked = askCore(oldRt, change);
|
|
472
472
|
doc.apply(at, change);
|
|
473
|
-
if (asked.size)
|
|
473
|
+
if (asked.size || change.steps.some((step) => 'setBlock' in step))
|
|
474
474
|
adopt();
|
|
475
475
|
}
|
|
476
476
|
}
|
|
@@ -553,8 +553,12 @@ export function createField(opts) {
|
|
|
553
553
|
if (n.id === stored[i])
|
|
554
554
|
return;
|
|
555
555
|
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
556
|
-
|
|
557
|
-
|
|
556
|
+
if (typeof n.id !== 'string')
|
|
557
|
+
return;
|
|
558
|
+
// A split's copy of an id the first half keeps is no rename. A block written above the
|
|
559
|
+
// first takes the first's id, which leaves the block that held it.
|
|
560
|
+
const kept = stored.indexOf(n.id);
|
|
561
|
+
if (kept < 0 || nodes[kept].id !== n.id)
|
|
558
562
|
renamed.push([n.id, stored[i]]);
|
|
559
563
|
});
|
|
560
564
|
renameBlocks(tr, renamed);
|
|
@@ -9,7 +9,8 @@ import { type EditorView } from 'prosemirror-view';
|
|
|
9
9
|
* proposes their removal. Its blocks pair with the paragraphs in order, each drawn as an edit of the one
|
|
10
10
|
* it pairs with while the two are one kind of block; past the first that is not, the paragraphs
|
|
11
11
|
* left are struck whole and the blocks left are added after the outermost block holding the last
|
|
12
|
-
* paragraph, or
|
|
12
|
+
* paragraph, or, where they open a list, as items at the depth the store spells them: a block of a
|
|
13
|
+
* nested list indented two spaces for each list around its own. One that names where it adds, by `insert`, proposes new blocks the same way after the block it names, or before the leaf's
|
|
13
14
|
* first; in a leaf that holds one empty paragraph it proposes that paragraph's text. A paragraph
|
|
14
15
|
* takes one proposal that rewrites it and one that adds after it, and a later item of either kind
|
|
15
16
|
* naming it draws nothing.
|
|
@@ -423,6 +423,25 @@ function placeOf(item, leaves, now) {
|
|
|
423
423
|
return { cover: [beside], beside, ahead: false, missing: false };
|
|
424
424
|
return { cover: [], beside, ahead, missing: false };
|
|
425
425
|
}
|
|
426
|
+
/** A list marker, after the spaces that open a line. */
|
|
427
|
+
const MARKER = /^ *(?:[-*+]|\d{1,9}[.)])(?: |$)/;
|
|
428
|
+
/**
|
|
429
|
+
* Markdown as the store spells a block of a nested list, read back: each line indented two
|
|
430
|
+
* spaces for every list around the block's own, which a parse alone reads as a sibling or as
|
|
431
|
+
* code. `markdown` with that indent taken off, and `nest`, the lists it stood in past the first.
|
|
432
|
+
*/
|
|
433
|
+
function unnest(markdown) {
|
|
434
|
+
const first = markdown.match(/^[ \n]*/)[0];
|
|
435
|
+
const spaces = first.length - first.lastIndexOf('\n') - 1;
|
|
436
|
+
const nest = Math.floor(spaces / 2);
|
|
437
|
+
if (!nest || !MARKER.test(markdown.slice(first.length - spaces)))
|
|
438
|
+
return { markdown, nest: 0 };
|
|
439
|
+
const indent = ' '.repeat(2 * nest);
|
|
440
|
+
const lines = markdown
|
|
441
|
+
.split('\n')
|
|
442
|
+
.map((l) => (l.startsWith(indent) ? l.slice(indent.length) : l));
|
|
443
|
+
return { markdown: lines.join('\n'), nest };
|
|
444
|
+
}
|
|
426
445
|
/** The blocks a proposal's writer read, by the id each was read under; `undefined` where
|
|
427
446
|
* `before` does not read as one block for each id. */
|
|
428
447
|
const reads = new WeakMap();
|
|
@@ -432,7 +451,8 @@ function readOf(ids, before, channel) {
|
|
|
432
451
|
reads.set(ids, (row = new Map()));
|
|
433
452
|
if (row.has(before))
|
|
434
453
|
return row.get(before);
|
|
435
|
-
const
|
|
454
|
+
const read = unnest(before).markdown;
|
|
455
|
+
const doc = read.trim() ? channel.parse(read) : undefined;
|
|
436
456
|
const blocks = doc ? leavesOf(doc) : [];
|
|
437
457
|
const out = blocks.length === ids.length ? new Map(ids.map((id, k) => [id, blocks[k].node])) : undefined;
|
|
438
458
|
row.set(before, out);
|
|
@@ -489,7 +509,8 @@ function draw(state, channel, bases) {
|
|
|
489
509
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
490
510
|
continue;
|
|
491
511
|
}
|
|
492
|
-
const
|
|
512
|
+
const { markdown: after, nest } = unnest(item.after);
|
|
513
|
+
const proposed = after.trim() ? channel.parse(after) : undefined;
|
|
493
514
|
if (item.after.trim() && !proposed) {
|
|
494
515
|
undrawn.push({ id: item.id, reason: 'parse' });
|
|
495
516
|
continue;
|
|
@@ -592,16 +613,13 @@ function draw(state, channel, bases) {
|
|
|
592
613
|
/** Past the outermost block holding the last one, or the head of the leaf. */
|
|
593
614
|
const outer = ahead ? 0 : $last.depth ? $last.after(1) : last.pos + last.node.nodeSize;
|
|
594
615
|
if (added.length) {
|
|
595
|
-
// A proposal that continues the list its paragraph is in adds items to that list.
|
|
596
|
-
const listed = !ahead &&
|
|
597
|
-
$last.parent.type.name === 'list_item' &&
|
|
598
|
-
added[0].type === $last.node($last.depth - 1).type;
|
|
599
616
|
const pieces = [];
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
617
|
+
const into = ahead ? undefined : listPlace($last, last, added[0], nest);
|
|
618
|
+
if (into?.whole)
|
|
619
|
+
pieces.push({ at: into.at, node: added[0] });
|
|
620
|
+
else if (into)
|
|
621
|
+
added[0].forEach((li) => pieces.push({ at: into.at, node: li }));
|
|
622
|
+
for (const node of into ? added.slice(1) : added)
|
|
605
623
|
pieces.push({ at: outer, node });
|
|
606
624
|
for (const piece of pieces) {
|
|
607
625
|
const held = plan.at(-1);
|
|
@@ -636,6 +654,33 @@ function draw(state, channel, bases) {
|
|
|
636
654
|
}
|
|
637
655
|
return { decos, lighting, spans, plans, outdated, undrawn };
|
|
638
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* Where a list a proposal adds after `last` goes, at the depth it was written at: the list it
|
|
659
|
+
* opens with stood in `nest` lists past the first. At the depth of a list `last` is in, its items
|
|
660
|
+
* follow the item of that list holding `last`; one deeper, they open the list under `last` in its
|
|
661
|
+
* item, or are that list, `whole`, where the item holds none. `undefined` where the list is not
|
|
662
|
+
* the kind of the one it would join, or `last` stands in no list.
|
|
663
|
+
*/
|
|
664
|
+
function listPlace($last, last, list, nest) {
|
|
665
|
+
const items = [];
|
|
666
|
+
for (let d = 1; d <= $last.depth; d++)
|
|
667
|
+
if ($last.node(d).type.name === 'list_item')
|
|
668
|
+
items.push(d);
|
|
669
|
+
if (!items.length || !/_list$/.test(list.type.name))
|
|
670
|
+
return undefined;
|
|
671
|
+
const level = Math.min(nest, items.length);
|
|
672
|
+
if (level === items.length) {
|
|
673
|
+
if ($last.parent.type.name !== 'list_item')
|
|
674
|
+
return undefined;
|
|
675
|
+
const end = last.pos + last.node.nodeSize;
|
|
676
|
+
const under = $last.doc.resolve(end).nodeAfter;
|
|
677
|
+
if (under?.type === list.type)
|
|
678
|
+
return { at: end + 1 };
|
|
679
|
+
return { at: end, whole: true };
|
|
680
|
+
}
|
|
681
|
+
const item = items[level];
|
|
682
|
+
return $last.node(item - 1).type === list.type ? { at: $last.after(item) } : undefined;
|
|
683
|
+
}
|
|
639
684
|
/** The item the caret is in: the one it was put into by its id while it holds the caret, else
|
|
640
685
|
* the one that holds it closest, so of a proposal that rewrites a paragraph and one that adds
|
|
641
686
|
* after it, the one that rewrites. */
|
|
@@ -117,6 +117,7 @@
|
|
|
117
117
|
import {
|
|
118
118
|
numberProposal,
|
|
119
119
|
putsIn,
|
|
120
|
+
membersOf,
|
|
120
121
|
textsOf,
|
|
121
122
|
type TextProposal,
|
|
122
123
|
splitReview,
|
|
@@ -264,20 +265,18 @@
|
|
|
264
265
|
unrouted(routed, (step) => typeof step === 'number' && step >= 0 && step < arr.length)
|
|
265
266
|
);
|
|
266
267
|
const reviewed = $derived(splitReview(review));
|
|
267
|
-
/** An item on a row that adds members in front of it, which the row does not draw.
|
|
268
|
-
|
|
268
|
+
/** An item on a row that adds members in front of it, which the row does not draw. Its
|
|
269
|
+
* steps are past the row's, which is a member's index. */
|
|
270
|
+
const inserting = (e: DeepReview): boolean => !e.steps.length && putsIn(e.item, [0]);
|
|
269
271
|
/** A row's review items: the member's own, and those inside it. */
|
|
270
272
|
const rowReview = (k: number): DeepReview[] =>
|
|
271
273
|
k < arr.length ? (reviewed.below.get(k) ?? []).filter((e) => !inserting(e)) : [];
|
|
272
274
|
/** The members a review would put in front of row `k`, each with the item that adds it. */
|
|
273
275
|
const insertedAt = (k: number): { item: FieldProposal; after: unknown }[] =>
|
|
274
276
|
k < arr.length
|
|
275
|
-
? (reviewed.below.get(k) ?? [])
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
after
|
|
279
|
-
}))
|
|
280
|
-
)
|
|
277
|
+
? (reviewed.below.get(k) ?? [])
|
|
278
|
+
.filter(inserting)
|
|
279
|
+
.flatMap(({ item }) => membersOf(item).map((after) => ({ item, after })))
|
|
281
280
|
: [];
|
|
282
281
|
const ownReview = (k: number): DeepReview[] => rowReview(k).filter((e) => !e.steps.length);
|
|
283
282
|
/** A row's own removal: the proposal that takes the member out, drawn on the whole row. */
|
|
@@ -354,7 +353,7 @@
|
|
|
354
353
|
e.steps.length === 1 &&
|
|
355
354
|
typeof e.steps[0] === 'number' &&
|
|
356
355
|
e.steps[0] >= arr.length &&
|
|
357
|
-
!
|
|
356
|
+
!('ahead' in e.item) &&
|
|
358
357
|
e.item.after !== undefined
|
|
359
358
|
)
|
|
360
359
|
);
|
|
@@ -384,6 +383,8 @@
|
|
|
384
383
|
let adding = $state(false);
|
|
385
384
|
const pending = $derived(adding && control === 'number' && ids.length > 0 && !atCap);
|
|
386
385
|
const rowIds = $derived(onStanding ? [standingId] : pending ? [...ids, standingId] : ids);
|
|
386
|
+
/** Whether the rows draw nothing: no row, standing or held, and no member a review adds. */
|
|
387
|
+
const rowless = $derived(rowIds.length === 0 && !added.length);
|
|
387
388
|
/** Whether the element's keys are its control's own, the row wiring none. */
|
|
388
389
|
const scalar = $derived(
|
|
389
390
|
control === 'number' || control === 'enum' || control === 'boolean' || control === 'date'
|
|
@@ -1034,7 +1035,7 @@
|
|
|
1034
1035
|
each block's one child: a branch inside the block would stand between them. -->
|
|
1035
1036
|
{#if table}
|
|
1036
1037
|
<div
|
|
1037
|
-
class={['qm-array-rows qm-array-table qm-wash', { empty:
|
|
1038
|
+
class={['qm-array-rows qm-array-table qm-wash', { empty: rowless }]}
|
|
1038
1039
|
data-default={defaulted ? '' : undefined}
|
|
1039
1040
|
bind:this={rowsEl}
|
|
1040
1041
|
>
|
|
@@ -1109,7 +1110,7 @@
|
|
|
1109
1110
|
</div>
|
|
1110
1111
|
{:else if control === 'object'}
|
|
1111
1112
|
<div
|
|
1112
|
-
class={['qm-array-rows qm-wash', { empty:
|
|
1113
|
+
class={['qm-array-rows qm-wash', { empty: rowless }]}
|
|
1113
1114
|
data-default={defaulted ? '' : undefined}
|
|
1114
1115
|
bind:this={rowsEl}
|
|
1115
1116
|
>
|
|
@@ -1200,7 +1201,7 @@
|
|
|
1200
1201
|
</div>
|
|
1201
1202
|
{:else}
|
|
1202
1203
|
<div
|
|
1203
|
-
class={['qm-array-rows qm-wash', { empty:
|
|
1204
|
+
class={['qm-array-rows qm-wash', { empty: rowless }]}
|
|
1204
1205
|
data-default={defaulted ? '' : undefined}
|
|
1205
1206
|
bind:this={rowsEl}
|
|
1206
1207
|
>
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
byCard,
|
|
69
69
|
locate,
|
|
70
70
|
putsIn,
|
|
71
|
+
membersOf,
|
|
71
72
|
onField,
|
|
72
73
|
reviewText,
|
|
73
74
|
valueIn,
|
|
@@ -472,8 +473,8 @@
|
|
|
472
473
|
const steps = reviewing.at(leaf).nested?.find((e) => e.item.id === item.id)?.steps;
|
|
473
474
|
if (!steps) return undefined;
|
|
474
475
|
const value = current();
|
|
475
|
-
after = putsIn(item)
|
|
476
|
-
? valueInserting(value, steps, item
|
|
476
|
+
after = putsIn(item, steps)
|
|
477
|
+
? valueInserting(value, steps, membersOf(item))
|
|
477
478
|
: valueWith(value, steps, to(valueIn(value, steps)));
|
|
478
479
|
} else after = to(current());
|
|
479
480
|
if (!write(after)) return undefined;
|
|
@@ -1849,15 +1850,21 @@
|
|
|
1849
1850
|
const path =
|
|
1850
1851
|
other === item ? steps : leafTargetFor((other as FieldProposal).field)?.steps;
|
|
1851
1852
|
if (!otherKey || fieldKeyToString(otherKey) !== leaf || !path) continue;
|
|
1852
|
-
const located = locate(
|
|
1853
|
+
const located = locate(
|
|
1854
|
+
held.value,
|
|
1855
|
+
path,
|
|
1856
|
+
other as FieldProposal,
|
|
1857
|
+
claimed,
|
|
1858
|
+
reviewing.later(other.id)
|
|
1859
|
+
);
|
|
1853
1860
|
if (other === item) {
|
|
1854
1861
|
found = located.steps;
|
|
1855
1862
|
break;
|
|
1856
1863
|
}
|
|
1857
1864
|
}
|
|
1858
1865
|
if (!found) continue;
|
|
1859
|
-
held.value = putsIn(item as FieldProposal)
|
|
1860
|
-
? valueInserting(held.value, found, (item as FieldProposal)
|
|
1866
|
+
held.value = putsIn(item as FieldProposal, found)
|
|
1867
|
+
? valueInserting(held.value, found, membersOf(item as FieldProposal))
|
|
1861
1868
|
: valueWith(held.value, found, reviewing.writes(item, valueIn(held.value, found)));
|
|
1862
1869
|
}
|
|
1863
1870
|
held.ids.push(id);
|
package/dist/visual/proposals.js
CHANGED
|
@@ -59,7 +59,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
|
|
|
59
59
|
};
|
|
60
60
|
const blocks = (field, from, fromAddr, to, toAddr) => {
|
|
61
61
|
const was = blocksOf(from, fromAddr);
|
|
62
|
-
const now = blocksOf(to, toAddr);
|
|
62
|
+
const now = leading(was, blocksOf(to, toAddr));
|
|
63
63
|
const nowById = new Map(now.map((b) => [b.id, b]));
|
|
64
64
|
for (const b of was) {
|
|
65
65
|
const next = nowById.get(b.id);
|
|
@@ -231,6 +231,33 @@ const addrOf = (card, field) => ({
|
|
|
231
231
|
...(card !== undefined && { card }),
|
|
232
232
|
...(field !== undefined && { field })
|
|
233
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
|
+
}
|
|
234
261
|
/** The blocks of the value at `addr`, none where it holds none. */
|
|
235
262
|
function blocksOf(doc, addr) {
|
|
236
263
|
try {
|
package/dist/visual/review.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
|
|
|
18
18
|
* its writer read. A path to a place inside a record or a
|
|
19
19
|
* list names that place: a cell, or a member by its index, which `after` absent takes out
|
|
20
20
|
* and an index past the last appends. One with `ahead` puts the members `after` holds in
|
|
21
|
-
* front of `ahead`, the member its writer read at that index.
|
|
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.
|
|
22
24
|
* - `add` or `remove`: a whole card, proposed new or proposed taken out (`CardProposal`).
|
|
23
25
|
*
|
|
24
26
|
* A `field` on a card names the card by its index, read against the cards as they stood when
|
|
@@ -157,8 +159,11 @@ export type FieldProposal = {
|
|
|
157
159
|
* read the list at the path's index; `after` then holds the members, in order. */
|
|
158
160
|
ahead?: unknown;
|
|
159
161
|
};
|
|
160
|
-
/** Whether a field item puts new members into a list in front of one it holds
|
|
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[];
|
|
162
167
|
/** A field item routed past its field: the steps from the rung it is handed to down to the
|
|
163
168
|
* value it names, a member of a list by its index, a cell of a record by its key. */
|
|
164
169
|
export interface DeepReview {
|
|
@@ -178,15 +183,19 @@ export declare function valueIn(value: unknown, steps: readonly PathStep[]): unk
|
|
|
178
183
|
export declare function valueWith(value: unknown, steps: readonly PathStep[], to: unknown): unknown;
|
|
179
184
|
/** `value` with `members` put into the list `steps` reach, in front of the member at its last
|
|
180
185
|
* step, or at its end past the last. */
|
|
181
|
-
export declare function valueInserting(value: unknown, steps: readonly PathStep[], members: unknown): unknown;
|
|
186
|
+
export declare function valueInserting(value: unknown, steps: readonly PathStep[], members: readonly unknown[]): unknown;
|
|
182
187
|
/**
|
|
183
188
|
* Where a field proposal's steps land in `value` as it stands. A list's member is found by its
|
|
184
189
|
* index where it holds `before`, else as the nearest member holding `before` that `claimed`
|
|
185
190
|
* does not already hold, so one member taken out does not move another's proposal onto the
|
|
186
191
|
* wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
|
|
187
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.
|
|
188
197
|
*/
|
|
189
|
-
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[]): {
|
|
190
199
|
steps: readonly PathStep[];
|
|
191
200
|
found: boolean;
|
|
192
201
|
};
|
package/dist/visual/review.js
CHANGED
|
@@ -11,8 +11,12 @@ export const NO_PROJECTION = {
|
|
|
11
11
|
toProjection: (at) => at,
|
|
12
12
|
toLive: (at) => at
|
|
13
13
|
};
|
|
14
|
-
/** Whether a field item puts new members into a list in front of one it holds
|
|
15
|
-
|
|
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];
|
|
16
20
|
/** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
|
|
17
21
|
* the step they take next, that step consumed. */
|
|
18
22
|
export function splitReview(list) {
|
|
@@ -73,7 +77,7 @@ export function valueInserting(value, steps, members) {
|
|
|
73
77
|
const held = valueIn(value, head);
|
|
74
78
|
const list = Array.isArray(held) ? [...held] : [];
|
|
75
79
|
const at = steps.at(-1);
|
|
76
|
-
list.splice(typeof at === 'number' ? Math.min(at, list.length) : list.length, 0, ...
|
|
80
|
+
list.splice(typeof at === 'number' ? Math.min(at, list.length) : list.length, 0, ...members);
|
|
77
81
|
return valueWith(value, head, list);
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
@@ -82,8 +86,12 @@ export function valueInserting(value, steps, members) {
|
|
|
82
86
|
* does not already hold, so one member taken out does not move another's proposal onto the
|
|
83
87
|
* wrong row. An insert lands in front of the nearest member holding its `ahead`, and claims
|
|
84
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.
|
|
85
93
|
*/
|
|
86
|
-
export function locate(value, steps, item, claimed) {
|
|
94
|
+
export function locate(value, steps, item, claimed, later = []) {
|
|
87
95
|
const read = 'before' in item;
|
|
88
96
|
const before = read ? item.before : undefined;
|
|
89
97
|
const at = steps.at(-1);
|
|
@@ -93,7 +101,15 @@ export function locate(value, steps, item, claimed) {
|
|
|
93
101
|
claimed.add(JSON.stringify(out));
|
|
94
102
|
return out;
|
|
95
103
|
};
|
|
96
|
-
if (putsIn(item)) {
|
|
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) {
|
|
97
113
|
if (typeof at !== 'number' || !Array.isArray(list))
|
|
98
114
|
return { steps, found: false };
|
|
99
115
|
for (let d = 0; d <= Math.max(at, list.length - 1 - at); d++)
|
|
@@ -52,6 +52,8 @@ export interface Review {
|
|
|
52
52
|
more?: readonly FieldProposal[];
|
|
53
53
|
nested?: readonly DeepReview[];
|
|
54
54
|
};
|
|
55
|
+
/** What the appends of item `id`'s run at higher indices add, in index order (`locate`). */
|
|
56
|
+
later(id: string): readonly unknown[];
|
|
55
57
|
/** Whether anything draws at leaf `key`: a field's own item, or a text item in its leaf. */
|
|
56
58
|
marks(key: string): boolean;
|
|
57
59
|
/** The leaf drawing item `id`, where one does. */
|
|
@@ -110,6 +110,30 @@ export function createReview(source) {
|
|
|
110
110
|
const key = listed[item.after];
|
|
111
111
|
return key !== undefined && standing.has(key) ? key : 'end';
|
|
112
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
|
+
});
|
|
113
137
|
const placed = $derived.by(() => {
|
|
114
138
|
const out = new Map();
|
|
115
139
|
const undrawn = [...cards.undrawn];
|
|
@@ -133,10 +157,10 @@ export function createReview(source) {
|
|
|
133
157
|
const claimed = claims.get(deep.key) ?? new Set();
|
|
134
158
|
claims.set(deep.key, claimed);
|
|
135
159
|
const held = out.get(deep.key) ?? {};
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
!runsOfOne(e.item, item))) {
|
|
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))) {
|
|
140
164
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
141
165
|
continue;
|
|
142
166
|
}
|
|
@@ -349,6 +373,7 @@ export function createReview(source) {
|
|
|
349
373
|
return place && valueIn(place.value, place.steps);
|
|
350
374
|
},
|
|
351
375
|
at: (key) => fields.get(key) ?? {},
|
|
376
|
+
later: (id) => later.get(id) ?? [],
|
|
352
377
|
marks: (key) => fields.has(key) || !!drawn.get(key)?.ids.length,
|
|
353
378
|
keyOf(id) {
|
|
354
379
|
const item = byId.get(id);
|
|
@@ -488,6 +513,7 @@ const NO_REVIEW = {
|
|
|
488
513
|
cards: { adds: new Map(), removes: new Map() },
|
|
489
514
|
wrote() { },
|
|
490
515
|
at: () => ({}),
|
|
516
|
+
later: () => [],
|
|
491
517
|
marks: () => false,
|
|
492
518
|
keyOf: () => undefined,
|
|
493
519
|
drew() { },
|