@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.
- package/dist/core/codec/field.d.ts +3 -3
- package/dist/core/codec/field.js +14 -20
- package/dist/core/codec/review.d.ts +2 -1
- package/dist/core/codec/review.js +64 -15
- package/dist/core/codec/value-diff.d.ts +4 -3
- package/dist/core/codec/value-diff.js +12 -7
- package/dist/core/codec/value-plan.d.ts +9 -0
- package/dist/core/codec/value-plan.js +110 -0
- package/dist/visual/ArrayField.svelte +77 -24
- package/dist/visual/Card.svelte +4 -3
- package/dist/visual/Card.svelte.d.ts +3 -2
- package/dist/visual/Field.svelte +12 -10
- package/dist/visual/Field.svelte.d.ts +3 -3
- package/dist/visual/ObjectField.svelte +24 -12
- package/dist/visual/ObjectField.svelte.d.ts +5 -0
- package/dist/visual/ProseField.svelte +16 -8
- package/dist/visual/ProseField.svelte.d.ts +3 -2
- package/dist/visual/ProseValue.svelte +22 -22
- package/dist/visual/ProseValue.svelte.d.ts +3 -2
- package/dist/visual/VisualEditorInner.svelte +37 -9
- package/dist/visual/proposals.d.ts +14 -11
- package/dist/visual/proposals.js +72 -29
- package/dist/visual/props.d.ts +6 -4
- package/dist/visual/review-order.d.ts +1 -0
- package/dist/visual/review-order.js +4 -3
- package/dist/visual/review.d.ts +25 -3
- package/dist/visual/review.js +46 -2
- package/dist/visual/review.svelte.d.ts +8 -1
- package/dist/visual/review.svelte.js +64 -11
- package/dist/visual/structure.d.ts +17 -9
- package/dist/visual/structure.js +20 -17
- package/package.json +1 -1
|
@@ -172,9 +172,9 @@ export interface FieldController {
|
|
|
172
172
|
* `text` leaf holds no anchors and draws none.
|
|
173
173
|
*/
|
|
174
174
|
setReview(items: readonly TextReview[], lit?: string): void;
|
|
175
|
-
/** Draw
|
|
176
|
-
* (`value-diff.ts`).
|
|
177
|
-
|
|
175
|
+
/** Draw proposed values over the leaf as a word diff, a whole value or each run of one
|
|
176
|
+
* answer, or none (`value-diff.ts`). */
|
|
177
|
+
setValueProposals(proposals: readonly ValueProposal[]): void;
|
|
178
178
|
/** The elements the review item `id` draws, in document order; `[]` for one not drawn. */
|
|
179
179
|
reviewElements(id: string): HTMLElement[];
|
|
180
180
|
/** Put the caret in the review item `id` and focus the leaf; false for one not drawn. */
|
package/dist/core/codec/field.js
CHANGED
|
@@ -287,10 +287,8 @@ export function createField(opts) {
|
|
|
287
287
|
point: (id) => opts.onReviewPoint?.(id),
|
|
288
288
|
drew: (report) => opts.onReviewDrawn?.(report)
|
|
289
289
|
});
|
|
290
|
-
let
|
|
291
|
-
const valueDiff =
|
|
292
|
-
? valueDiffPlugin(() => valueProposal, (id, state) => opts.onValuePlanned?.(id, state))
|
|
293
|
-
: undefined;
|
|
290
|
+
let valueProposals = [];
|
|
291
|
+
const valueDiff = valueDiffPlugin(() => valueProposals, (id, state) => opts.onValuePlanned?.(id, state));
|
|
294
292
|
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
295
293
|
const slash = block ? opts.onSlash : undefined;
|
|
296
294
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
@@ -416,11 +414,7 @@ export function createField(opts) {
|
|
|
416
414
|
placeholder: () => placeholderText,
|
|
417
415
|
placeholderUntilEdit: opts.placeholderUntilEdit,
|
|
418
416
|
cap: opts.cap,
|
|
419
|
-
afterHistory: [
|
|
420
|
-
anchorPlugin(seededAnchors),
|
|
421
|
-
...(review ? [review.plugin] : []),
|
|
422
|
-
...(valueDiff ? [valueDiff] : [])
|
|
423
|
-
]
|
|
417
|
+
afterHistory: [anchorPlugin(seededAnchors), ...(review ? [review.plugin] : []), valueDiff]
|
|
424
418
|
})
|
|
425
419
|
});
|
|
426
420
|
return { state: built, index: seedIndex };
|
|
@@ -476,7 +470,7 @@ export function createField(opts) {
|
|
|
476
470
|
if (change) {
|
|
477
471
|
const asked = askCore(oldRt, change);
|
|
478
472
|
doc.apply(at, change);
|
|
479
|
-
if (asked.size)
|
|
473
|
+
if (asked.size || change.steps.some((step) => 'setBlock' in step))
|
|
480
474
|
adopt();
|
|
481
475
|
}
|
|
482
476
|
}
|
|
@@ -559,8 +553,12 @@ export function createField(opts) {
|
|
|
559
553
|
if (n.id === stored[i])
|
|
560
554
|
return;
|
|
561
555
|
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
562
|
-
|
|
563
|
-
|
|
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)
|
|
564
562
|
renamed.push([n.id, stored[i]]);
|
|
565
563
|
});
|
|
566
564
|
renameBlocks(tr, renamed);
|
|
@@ -738,15 +736,11 @@ export function createField(opts) {
|
|
|
738
736
|
parsed.delete(markdown);
|
|
739
737
|
review.refresh(view);
|
|
740
738
|
},
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (p?.id === valueProposal?.id &&
|
|
745
|
-
p?.lit === valueProposal?.lit &&
|
|
746
|
-
JSON.stringify([p?.after, p?.before]) ===
|
|
747
|
-
JSON.stringify([valueProposal?.after, valueProposal?.before]))
|
|
739
|
+
setValueProposals(proposals) {
|
|
740
|
+
const key = (list) => JSON.stringify(list.map((p) => [p.id, p.lit, p.after, p.before]));
|
|
741
|
+
if (key(proposals) === key(valueProposals))
|
|
748
742
|
return;
|
|
749
|
-
|
|
743
|
+
valueProposals = proposals;
|
|
750
744
|
view.setProps({});
|
|
751
745
|
},
|
|
752
746
|
reviewElements(id) {
|
|
@@ -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.
|
|
@@ -136,13 +136,17 @@ function reach(leaf) {
|
|
|
136
136
|
? [leaf.pos + 1, leaf.pos + leaf.node.nodeSize - 1]
|
|
137
137
|
: [leaf.pos, leaf.pos + leaf.node.nodeSize];
|
|
138
138
|
}
|
|
139
|
+
/** `node`'s attributes without the id of the stored part it decodes from. */
|
|
140
|
+
const unnamed = (node) => 'id' in node.attrs ? { ...node.attrs, id: null } : node.attrs;
|
|
139
141
|
/** `doc`'s blocks from its `from`th leaf on, in the containers they sat in. A numbered list
|
|
140
|
-
* that lost its head keeps counting from where the kept items stood.
|
|
142
|
+
* that lost its head keeps counting from where the kept items stood. They carry no ids: the
|
|
143
|
+
* ones `doc` was read under are its own, and a leaf's block wearing one would lose it to an
|
|
144
|
+
* added block that stands ahead of it. */
|
|
141
145
|
function tail(doc, from) {
|
|
142
146
|
let seen = 0;
|
|
143
147
|
const keep = (node) => {
|
|
144
148
|
if (node.isTextblock || node.isAtom)
|
|
145
|
-
return seen++ >= from ? node : undefined;
|
|
149
|
+
return seen++ >= from ? node.type.create(unnamed(node), node.content, node.marks) : undefined;
|
|
146
150
|
const kids = [];
|
|
147
151
|
let dropped = 0;
|
|
148
152
|
node.forEach((child) => {
|
|
@@ -155,8 +159,8 @@ function tail(doc, from) {
|
|
|
155
159
|
if (!kids.length)
|
|
156
160
|
return undefined;
|
|
157
161
|
const attrs = node.type.name === 'ordered_list'
|
|
158
|
-
? { ...node
|
|
159
|
-
: node
|
|
162
|
+
? { ...unnamed(node), start: node.attrs.start + dropped }
|
|
163
|
+
: unnamed(node);
|
|
160
164
|
return node.type.create(attrs, kids);
|
|
161
165
|
};
|
|
162
166
|
const out = [];
|
|
@@ -419,6 +423,25 @@ function placeOf(item, leaves, now) {
|
|
|
419
423
|
return { cover: [beside], beside, ahead: false, missing: false };
|
|
420
424
|
return { cover: [], beside, ahead, missing: false };
|
|
421
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
|
+
}
|
|
422
445
|
/** The blocks a proposal's writer read, by the id each was read under; `undefined` where
|
|
423
446
|
* `before` does not read as one block for each id. */
|
|
424
447
|
const reads = new WeakMap();
|
|
@@ -428,7 +451,8 @@ function readOf(ids, before, channel) {
|
|
|
428
451
|
reads.set(ids, (row = new Map()));
|
|
429
452
|
if (row.has(before))
|
|
430
453
|
return row.get(before);
|
|
431
|
-
const
|
|
454
|
+
const read = unnest(before).markdown;
|
|
455
|
+
const doc = read.trim() ? channel.parse(read) : undefined;
|
|
432
456
|
const blocks = doc ? leavesOf(doc) : [];
|
|
433
457
|
const out = blocks.length === ids.length ? new Map(ids.map((id, k) => [id, blocks[k].node])) : undefined;
|
|
434
458
|
row.set(before, out);
|
|
@@ -485,7 +509,8 @@ function draw(state, channel, bases) {
|
|
|
485
509
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
486
510
|
continue;
|
|
487
511
|
}
|
|
488
|
-
const
|
|
512
|
+
const { markdown: after, nest } = unnest(item.after);
|
|
513
|
+
const proposed = after.trim() ? channel.parse(after) : undefined;
|
|
489
514
|
if (item.after.trim() && !proposed) {
|
|
490
515
|
undrawn.push({ id: item.id, reason: 'parse' });
|
|
491
516
|
continue;
|
|
@@ -588,16 +613,13 @@ function draw(state, channel, bases) {
|
|
|
588
613
|
/** Past the outermost block holding the last one, or the head of the leaf. */
|
|
589
614
|
const outer = ahead ? 0 : $last.depth ? $last.after(1) : last.pos + last.node.nodeSize;
|
|
590
615
|
if (added.length) {
|
|
591
|
-
// A proposal that continues the list its paragraph is in adds items to that list.
|
|
592
|
-
const listed = !ahead &&
|
|
593
|
-
$last.parent.type.name === 'list_item' &&
|
|
594
|
-
added[0].type === $last.node($last.depth - 1).type;
|
|
595
616
|
const pieces = [];
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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)
|
|
601
623
|
pieces.push({ at: outer, node });
|
|
602
624
|
for (const piece of pieces) {
|
|
603
625
|
const held = plan.at(-1);
|
|
@@ -632,6 +654,33 @@ function draw(state, channel, bases) {
|
|
|
632
654
|
}
|
|
633
655
|
return { decos, lighting, spans, plans, outdated, undrawn };
|
|
634
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
|
+
}
|
|
635
684
|
/** The item the caret is in: the one it was put into by its id while it holds the caret, else
|
|
636
685
|
* the one that holds it closest, so of a proposal that rewrites a paragraph and one that adds
|
|
637
686
|
* after it, the one that rewrites. */
|
|
@@ -15,7 +15,8 @@ export interface ValueProposal {
|
|
|
15
15
|
export type ValueState = 'open' | 'outdated' | 'applied';
|
|
16
16
|
export declare const valueDiffKey: PluginKey<void>;
|
|
17
17
|
/**
|
|
18
|
-
* The plugin, reading the
|
|
19
|
-
* `planned` hears, on each draw, how
|
|
18
|
+
* The plugin, reading the proposals live: a caller that moves them redraws with `setProps`.
|
|
19
|
+
* Each is a run of one answer or a whole value, drawn apart. `planned` hears, on each draw, how
|
|
20
|
+
* each stands against what the leaf holds.
|
|
20
21
|
*/
|
|
21
|
-
export declare function valueDiffPlugin(read: () => ValueProposal
|
|
22
|
+
export declare function valueDiffPlugin(read: () => readonly ValueProposal[], planned?: (id: string, state: ValueState) => void): Plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A field's whole
|
|
1
|
+
// A field's proposed values, a whole one or each run of one answer, drawn as a word diff over a leaf of lines: the words Accept would
|
|
2
2
|
// strike struck where they stand, the words it would write tinted beside them in their own
|
|
3
3
|
// formatting, nothing written. What is drawn is the difference between the leaf as it reads and
|
|
4
4
|
// what Accept would write (`planValue`), so the reader's words beside a proposal stay unstruck.
|
|
@@ -31,11 +31,15 @@ function inserted(schema, c, from, to) {
|
|
|
31
31
|
const inline = doc.firstChild?.isTextblock ? doc.firstChild.content : doc.content;
|
|
32
32
|
return DOMSerializer.fromSchema(schema).serializeFragment(inline);
|
|
33
33
|
}
|
|
34
|
-
function draw(state,
|
|
34
|
+
function draw(state, proposals, planned) {
|
|
35
35
|
const scan = scanDoc(state.doc);
|
|
36
36
|
const live = scanContent(scan);
|
|
37
37
|
const index = lineIndexOf(scan);
|
|
38
38
|
const at = (offset) => offsetToPM(index, offset);
|
|
39
|
+
return DecorationSet.create(state.doc, proposals.flatMap((p) => decorations(state, live, at, p, planned)));
|
|
40
|
+
}
|
|
41
|
+
/** One proposal's marks over the leaf as it reads, `live`. */
|
|
42
|
+
function decorations(state, live, at, p, planned) {
|
|
39
43
|
const { merged, outdated } = planValue(p.before, live, p.after);
|
|
40
44
|
const changes = valueChanges(live, merged);
|
|
41
45
|
planned?.(p.id, !changes.length ? 'applied' : outdated ? 'outdated' : 'open');
|
|
@@ -64,19 +68,20 @@ function draw(state, p, planned) {
|
|
|
64
68
|
key: `value:${p.id}:${n}:${start}:${JSON.stringify(slice(merged, start, to).marks)}:${text}:${p.lit}`
|
|
65
69
|
}));
|
|
66
70
|
});
|
|
67
|
-
return
|
|
71
|
+
return decos;
|
|
68
72
|
}
|
|
69
73
|
/**
|
|
70
|
-
* The plugin, reading the
|
|
71
|
-
* `planned` hears, on each draw, how
|
|
74
|
+
* The plugin, reading the proposals live: a caller that moves them redraws with `setProps`.
|
|
75
|
+
* Each is a run of one answer or a whole value, drawn apart. `planned` hears, on each draw, how
|
|
76
|
+
* each stands against what the leaf holds.
|
|
72
77
|
*/
|
|
73
78
|
export function valueDiffPlugin(read, planned) {
|
|
74
79
|
return new Plugin({
|
|
75
80
|
key: valueDiffKey,
|
|
76
81
|
props: {
|
|
77
82
|
decorations(state) {
|
|
78
|
-
const
|
|
79
|
-
return
|
|
83
|
+
const proposals = read();
|
|
84
|
+
return proposals.length ? draw(state, proposals, planned) : null;
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
});
|
|
@@ -27,3 +27,12 @@ export declare function valueChanges(a: Content, b: Content): ValueChange[];
|
|
|
27
27
|
* the value already reads as `after`.
|
|
28
28
|
*/
|
|
29
29
|
export declare function planValue(before: Content | undefined, live: Content, after: Content): ValuePlan;
|
|
30
|
+
/**
|
|
31
|
+
* `after` as one proposal per run of lines it changes in `before`: each `before` with that run
|
|
32
|
+
* alone written as `after` has it, in reading order. Lines pair by their words and formatting
|
|
33
|
+
* along their longest common run, so a line added or taken out is one run, never every line below
|
|
34
|
+
* it. By `'run'`, runs at most two unchanged lines apart are one; by `'paragraph'`, a run that
|
|
35
|
+
* rewrites as many lines as it reads is one proposal per line, as the body proposes paragraphs. A
|
|
36
|
+
* value that holds more than lines of words, or one that changes a single line or run, is `[after]`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function lineRuns(before: Content, after: Content, unit?: 'run' | 'paragraph'): Content[];
|
|
@@ -155,3 +155,113 @@ export function planValue(before, live, after) {
|
|
|
155
155
|
}
|
|
156
156
|
return { merged, outdated: false };
|
|
157
157
|
}
|
|
158
|
+
/** Unchanged lines that may stand between two runs of changed lines on one proposal. */
|
|
159
|
+
const RUN_GAP = 2;
|
|
160
|
+
/** Line `k` of `c`, as a value of its own. */
|
|
161
|
+
function lineOf(c, starts, k) {
|
|
162
|
+
const from = starts[k];
|
|
163
|
+
const to = k + 1 < starts.length ? starts[k + 1] - 1 : c.text.length;
|
|
164
|
+
return { text: c.text.slice(from, to), marks: marksIn(c, from, to, 0) };
|
|
165
|
+
}
|
|
166
|
+
/** Where each line of `c` starts. */
|
|
167
|
+
function lineStarts(c) {
|
|
168
|
+
const out = [0];
|
|
169
|
+
for (let i = 0; i < c.text.length; i++)
|
|
170
|
+
if (c.text[i] === '\n')
|
|
171
|
+
out.push(i + 1);
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* `after` as one proposal per run of lines it changes in `before`: each `before` with that run
|
|
176
|
+
* alone written as `after` has it, in reading order. Lines pair by their words and formatting
|
|
177
|
+
* along their longest common run, so a line added or taken out is one run, never every line below
|
|
178
|
+
* it. By `'run'`, runs at most two unchanged lines apart are one; by `'paragraph'`, a run that
|
|
179
|
+
* rewrites as many lines as it reads is one proposal per line, as the body proposes paragraphs. A
|
|
180
|
+
* value that holds more than lines of words, or one that changes a single line or run, is `[after]`.
|
|
181
|
+
*/
|
|
182
|
+
export function lineRuns(before, after, unit = 'run') {
|
|
183
|
+
if ([before, after].some(structured))
|
|
184
|
+
return [after];
|
|
185
|
+
const bs = lineStarts(before);
|
|
186
|
+
const as = lineStarts(after);
|
|
187
|
+
if (bs.length !== before.blocks.length || as.length !== after.blocks.length)
|
|
188
|
+
return [after];
|
|
189
|
+
const key = (c, starts, k) => JSON.stringify(lineOf(c, starts, k));
|
|
190
|
+
const bk = bs.map((_, k) => key(before, bs, k));
|
|
191
|
+
const ak = as.map((_, k) => key(after, as, k));
|
|
192
|
+
const m = bk.length;
|
|
193
|
+
const n = ak.length;
|
|
194
|
+
const lcs = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
195
|
+
for (let i = m - 1; i >= 0; i--)
|
|
196
|
+
for (let j = n - 1; j >= 0; j--)
|
|
197
|
+
lcs[i][j] = bk[i] === ak[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
198
|
+
const runs = [];
|
|
199
|
+
let i = 0;
|
|
200
|
+
let j = 0;
|
|
201
|
+
let open;
|
|
202
|
+
const close = () => {
|
|
203
|
+
if (!open)
|
|
204
|
+
return;
|
|
205
|
+
const last = runs.at(-1);
|
|
206
|
+
if (unit === 'run' && last && open.b - last.be <= RUN_GAP) {
|
|
207
|
+
last.be = i;
|
|
208
|
+
last.ae = j;
|
|
209
|
+
}
|
|
210
|
+
else
|
|
211
|
+
runs.push({ b: open.b, be: i, a: open.a, ae: j });
|
|
212
|
+
open = undefined;
|
|
213
|
+
};
|
|
214
|
+
while (i < m || j < n) {
|
|
215
|
+
if (i < m && j < n && bk[i] === ak[j]) {
|
|
216
|
+
close();
|
|
217
|
+
i++;
|
|
218
|
+
j++;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
open ??= { b: i, a: j };
|
|
222
|
+
if (j >= n || (i < m && lcs[i + 1][j] >= lcs[i][j + 1]))
|
|
223
|
+
i++;
|
|
224
|
+
else
|
|
225
|
+
j++;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
close();
|
|
229
|
+
const apart = unit === 'paragraph'
|
|
230
|
+
? runs.flatMap((r) => r.be - r.b === r.ae - r.a && r.be - r.b > 1
|
|
231
|
+
? Array.from({ length: r.be - r.b }, (_, k) => ({
|
|
232
|
+
b: r.b + k,
|
|
233
|
+
be: r.b + k + 1,
|
|
234
|
+
a: r.a + k,
|
|
235
|
+
ae: r.a + k + 1
|
|
236
|
+
}))
|
|
237
|
+
: [r])
|
|
238
|
+
: runs;
|
|
239
|
+
if (apart.length < 2)
|
|
240
|
+
return [after];
|
|
241
|
+
return apart.map((run) => {
|
|
242
|
+
const lines = [
|
|
243
|
+
...bs.slice(0, run.b).map((_, k) => lineOf(before, bs, k)),
|
|
244
|
+
...as.slice(run.a, run.ae).map((_, k) => lineOf(after, as, run.a + k)),
|
|
245
|
+
...bs.slice(run.be).map((_, k) => lineOf(before, bs, run.be + k))
|
|
246
|
+
];
|
|
247
|
+
const blocks = [
|
|
248
|
+
...before.blocks.slice(0, run.b),
|
|
249
|
+
...after.blocks.slice(run.a, run.ae),
|
|
250
|
+
...before.blocks.slice(run.be)
|
|
251
|
+
].map((b, k) => ({ ...b, id: `b${k}` }));
|
|
252
|
+
let at = 0;
|
|
253
|
+
const marks = [];
|
|
254
|
+
for (const line of lines) {
|
|
255
|
+
for (const mark of line.marks)
|
|
256
|
+
marks.push({ ...mark, start: mark.start + at, end: mark.end + at });
|
|
257
|
+
at += line.text.length + 1;
|
|
258
|
+
}
|
|
259
|
+
const out = { ...before, text: lines.map((l) => l.text).join('\n'), blocks };
|
|
260
|
+
if (marks.length)
|
|
261
|
+
out.marks = marks;
|
|
262
|
+
else
|
|
263
|
+
delete out.marks;
|
|
264
|
+
delete out.anchors;
|
|
265
|
+
return out;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
@@ -108,9 +108,7 @@
|
|
|
108
108
|
firstShortText,
|
|
109
109
|
declaredContent,
|
|
110
110
|
fieldTitle,
|
|
111
|
-
|
|
112
|
-
literalText,
|
|
113
|
-
oneLine,
|
|
111
|
+
leafFlags,
|
|
114
112
|
renderedBoolean,
|
|
115
113
|
schemaAt,
|
|
116
114
|
textCap,
|
|
@@ -118,7 +116,9 @@
|
|
|
118
116
|
} from './structure.js';
|
|
119
117
|
import {
|
|
120
118
|
numberProposal,
|
|
121
|
-
|
|
119
|
+
putsIn,
|
|
120
|
+
membersOf,
|
|
121
|
+
textsOf,
|
|
122
122
|
type TextProposal,
|
|
123
123
|
splitReview,
|
|
124
124
|
valueIn,
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
const control = $derived(items ? controlKind(items) : 'text');
|
|
225
225
|
/** A prose element whose `items` declares a `shape`: its own lines, which Enter breaks and
|
|
226
226
|
* ⌘/Ctrl+Enter leaves for a sibling. */
|
|
227
|
-
const multiline = $derived(control === 'prose' &&
|
|
227
|
+
const multiline = $derived(control === 'prose' && !leafFlags(items).inline);
|
|
228
228
|
const table = $derived(layout === 'table' && control === 'object');
|
|
229
229
|
const columns = $derived(Object.entries(items?.properties ?? {}));
|
|
230
230
|
/** A column's track. A cell that fills its width takes a share of what the field has
|
|
@@ -265,9 +265,19 @@
|
|
|
265
265
|
unrouted(routed, (step) => typeof step === 'number' && step >= 0 && step < arr.length)
|
|
266
266
|
);
|
|
267
267
|
const reviewed = $derived(splitReview(review));
|
|
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]);
|
|
268
271
|
/** A row's review items: the member's own, and those inside it. */
|
|
269
272
|
const rowReview = (k: number): DeepReview[] =>
|
|
270
|
-
k < arr.length ? (reviewed.below.get(k) ?? []) : [];
|
|
273
|
+
k < arr.length ? (reviewed.below.get(k) ?? []).filter((e) => !inserting(e)) : [];
|
|
274
|
+
/** The members a review would put in front of row `k`, each with the item that adds it. */
|
|
275
|
+
const insertedAt = (k: number): { item: FieldProposal; after: unknown }[] =>
|
|
276
|
+
k < arr.length
|
|
277
|
+
? (reviewed.below.get(k) ?? [])
|
|
278
|
+
.filter(inserting)
|
|
279
|
+
.flatMap(({ item }) => membersOf(item).map((after) => ({ item, after })))
|
|
280
|
+
: [];
|
|
271
281
|
const ownReview = (k: number): DeepReview[] => rowReview(k).filter((e) => !e.steps.length);
|
|
272
282
|
/** A row's own removal: the proposal that takes the member out, drawn on the whole row. */
|
|
273
283
|
const removal = (k: number): FieldProposal | undefined =>
|
|
@@ -284,11 +294,17 @@
|
|
|
284
294
|
scalar || control === 'prose'
|
|
285
295
|
? ownReview(k).find((e) => e.item.after !== undefined)?.item
|
|
286
296
|
: undefined;
|
|
287
|
-
const rowText = (k: number): TextProposal | undefined =>
|
|
288
|
-
control === 'prose'
|
|
297
|
+
const rowText = (k: number): TextProposal[] | undefined =>
|
|
298
|
+
control === 'prose'
|
|
299
|
+
? textsOf(
|
|
300
|
+
ownReview(k)
|
|
301
|
+
.filter((e) => e.item.after !== undefined)
|
|
302
|
+
.map((e) => e.item)
|
|
303
|
+
)
|
|
304
|
+
: undefined;
|
|
289
305
|
const rowNumber = (k: number): { id: string; after: string } | undefined =>
|
|
290
306
|
control === 'number' ? numberProposal(rowOwn(k)) : undefined;
|
|
291
|
-
const rowWorded = (k: number): { id: string } | undefined => rowText(k) ?? rowNumber(k);
|
|
307
|
+
const rowWorded = (k: number): { id: string } | undefined => rowText(k)?.[0] ?? rowNumber(k);
|
|
292
308
|
const rowShown = (k: number): unknown => {
|
|
293
309
|
const own = rowWorded(k) ? undefined : rowOwn(k);
|
|
294
310
|
return own ? own.after : arr[k];
|
|
@@ -302,8 +318,8 @@
|
|
|
302
318
|
};
|
|
303
319
|
/** A row's marks: its proposals less the one its control draws as words. */
|
|
304
320
|
const rowMarks = (k: number): DeepReview[] => {
|
|
305
|
-
const
|
|
306
|
-
return
|
|
321
|
+
const drawn = new Set([...(rowText(k) ?? []), rowNumber(k)].map((p) => p?.id));
|
|
322
|
+
return rowKept(k).filter((e) => !drawn.has(e.item.id));
|
|
307
323
|
};
|
|
308
324
|
/** What a row taken out carries: its item's id and the current one lit, so the row is where
|
|
309
325
|
* the answer card stands. */
|
|
@@ -324,7 +340,9 @@
|
|
|
324
340
|
...[...reviewed.below].flatMap(([step, list]) => {
|
|
325
341
|
const held = typeof step === 'number' && step >= 0 && step < arr.length;
|
|
326
342
|
return list
|
|
327
|
-
.filter(
|
|
343
|
+
.filter(
|
|
344
|
+
(e) => !held || (table && !inserting(e) && !e.steps.length && e.item.after !== undefined)
|
|
345
|
+
)
|
|
328
346
|
.map((e) => ({ steps: [step, ...e.steps], item: e.item }));
|
|
329
347
|
})
|
|
330
348
|
]);
|
|
@@ -335,6 +353,7 @@
|
|
|
335
353
|
e.steps.length === 1 &&
|
|
336
354
|
typeof e.steps[0] === 'number' &&
|
|
337
355
|
e.steps[0] >= arr.length &&
|
|
356
|
+
!('ahead' in e.item) &&
|
|
338
357
|
e.item.after !== undefined
|
|
339
358
|
)
|
|
340
359
|
);
|
|
@@ -364,6 +383,8 @@
|
|
|
364
383
|
let adding = $state(false);
|
|
365
384
|
const pending = $derived(adding && control === 'number' && ids.length > 0 && !atCap);
|
|
366
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);
|
|
367
388
|
/** Whether the element's keys are its control's own, the row wiring none. */
|
|
368
389
|
const scalar = $derived(
|
|
369
390
|
control === 'number' || control === 'enum' || control === 'boolean' || control === 'date'
|
|
@@ -1014,7 +1035,7 @@
|
|
|
1014
1035
|
each block's one child: a branch inside the block would stand between them. -->
|
|
1015
1036
|
{#if table}
|
|
1016
1037
|
<div
|
|
1017
|
-
class={['qm-array-rows qm-array-table qm-wash', { empty:
|
|
1038
|
+
class={['qm-array-rows qm-array-table qm-wash', { empty: rowless }]}
|
|
1018
1039
|
data-default={defaulted ? '' : undefined}
|
|
1019
1040
|
bind:this={rowsEl}
|
|
1020
1041
|
>
|
|
@@ -1049,6 +1070,11 @@
|
|
|
1049
1070
|
<span class="qm-array-table-head-end"></span>
|
|
1050
1071
|
</div>
|
|
1051
1072
|
{#each ids as id, k (id)}
|
|
1073
|
+
{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1074
|
+
item,
|
|
1075
|
+
after,
|
|
1076
|
+
k
|
|
1077
|
+
)}{/each}
|
|
1052
1078
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1053
1079
|
<div
|
|
1054
1080
|
class={['qm-array-row qm-array-table-row qm-wash', { lifted: drag.lifted(k) }]}
|
|
@@ -1075,15 +1101,21 @@
|
|
|
1075
1101
|
{@render removeButton(k, true)}
|
|
1076
1102
|
</div>
|
|
1077
1103
|
{/each}
|
|
1078
|
-
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1104
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1105
|
+
item,
|
|
1106
|
+
item.after,
|
|
1107
|
+
arr.length + n
|
|
1108
|
+
)}{/each}
|
|
1079
1109
|
</div>
|
|
1080
1110
|
</div>
|
|
1081
1111
|
{:else if control === 'object'}
|
|
1082
1112
|
<div
|
|
1083
|
-
class={['qm-array-rows qm-wash', { empty:
|
|
1113
|
+
class={['qm-array-rows qm-wash', { empty: rowless }]}
|
|
1084
1114
|
data-default={defaulted ? '' : undefined}
|
|
1085
1115
|
bind:this={rowsEl}
|
|
1086
1116
|
>
|
|
1117
|
+
<!-- A row animates its moves, so it is its keyed block's only child, and a member a review
|
|
1118
|
+
puts in front of it is drawn after the rows and set in place by its flex order. -->
|
|
1087
1119
|
{#each ids as id, k (id)}
|
|
1088
1120
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1089
1121
|
<!-- The handler catches a key from the controls inside the row and adds no
|
|
@@ -1093,6 +1125,7 @@
|
|
|
1093
1125
|
'qm-array-row qm-element qm-wash',
|
|
1094
1126
|
{ open: open.has(id), lifted: drag.lifted(k) }
|
|
1095
1127
|
]}
|
|
1128
|
+
style:order={2 * k + 1}
|
|
1096
1129
|
data-drop={drag.dropSide(k)}
|
|
1097
1130
|
data-qm-index={k}
|
|
1098
1131
|
bind:this={rowEls[id]}
|
|
@@ -1153,15 +1186,31 @@
|
|
|
1153
1186
|
{/if}
|
|
1154
1187
|
</div>
|
|
1155
1188
|
{/each}
|
|
1156
|
-
{#each
|
|
1189
|
+
{#each ids as _, k (k)}{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1190
|
+
item,
|
|
1191
|
+
after,
|
|
1192
|
+
k,
|
|
1193
|
+
2 * k
|
|
1194
|
+
)}{/each}{/each}
|
|
1195
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1196
|
+
item,
|
|
1197
|
+
item.after,
|
|
1198
|
+
arr.length + n,
|
|
1199
|
+
2 * arr.length + 1
|
|
1200
|
+
)}{/each}
|
|
1157
1201
|
</div>
|
|
1158
1202
|
{:else}
|
|
1159
1203
|
<div
|
|
1160
|
-
class={['qm-array-rows qm-wash', { empty:
|
|
1204
|
+
class={['qm-array-rows qm-wash', { empty: rowless }]}
|
|
1161
1205
|
data-default={defaulted ? '' : undefined}
|
|
1162
1206
|
bind:this={rowsEl}
|
|
1163
1207
|
>
|
|
1164
1208
|
{#each rowIds as id, k (id)}
|
|
1209
|
+
{#each insertedAt(k) as { item, after }, n (`${item.id}:${n}`)}{@render addedRow(
|
|
1210
|
+
item,
|
|
1211
|
+
after,
|
|
1212
|
+
k
|
|
1213
|
+
)}{/each}
|
|
1165
1214
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1166
1215
|
<div
|
|
1167
1216
|
class={['qm-array-row qm-wash', { standing: id === standingId, lifted: drag.lifted(k) }]}
|
|
@@ -1178,9 +1227,9 @@
|
|
|
1178
1227
|
content={() => readAt([k])}
|
|
1179
1228
|
value={arr[k]}
|
|
1180
1229
|
proposed={rowText(k)}
|
|
1181
|
-
plaintext={
|
|
1230
|
+
plaintext={leafFlags(items).plaintext}
|
|
1182
1231
|
block={multiline}
|
|
1183
|
-
paragraphs={
|
|
1232
|
+
paragraphs={leafFlags(items).paragraphs}
|
|
1184
1233
|
cap={textCap(items)}
|
|
1185
1234
|
label={rowName(k)}
|
|
1186
1235
|
placeholder={id === standingId ? t.strings.arrayStanding : undefined}
|
|
@@ -1247,7 +1296,11 @@
|
|
|
1247
1296
|
<ReviewRows entries={rowMarks(k)} member />
|
|
1248
1297
|
</div>
|
|
1249
1298
|
{/each}
|
|
1250
|
-
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1299
|
+
{#each added as { item }, n (item.id)}{@render addedRow(
|
|
1300
|
+
item,
|
|
1301
|
+
item.after,
|
|
1302
|
+
arr.length + n
|
|
1303
|
+
)}{/each}
|
|
1251
1304
|
</div>
|
|
1252
1305
|
{/if}
|
|
1253
1306
|
<DiagnosticList diagnostics={foot} />
|
|
@@ -1258,8 +1311,7 @@
|
|
|
1258
1311
|
the value, tinted and inert: a table's as a row of its cells under the same headers, a record
|
|
1259
1312
|
list's collapsed to its summary. The row, not the control, hears the pointer and carries the
|
|
1260
1313
|
item, so a press on it names the item and the answer card stands on it. -->
|
|
1261
|
-
{#snippet addedRow(item: FieldProposal, k: number)}
|
|
1262
|
-
{@const after = item.after}
|
|
1314
|
+
{#snippet addedRow(item: FieldProposal, after: unknown, k: number, order?: number)}
|
|
1263
1315
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
1264
1316
|
<div
|
|
1265
1317
|
class={[
|
|
@@ -1270,6 +1322,7 @@
|
|
|
1270
1322
|
'qm-review-lit': reviewing.lit === item.id
|
|
1271
1323
|
}
|
|
1272
1324
|
]}
|
|
1325
|
+
style:order
|
|
1273
1326
|
data-qm-review={item.id}
|
|
1274
1327
|
role="group"
|
|
1275
1328
|
aria-label={t.strings.reviewNewItem}
|
|
@@ -1302,9 +1355,9 @@
|
|
|
1302
1355
|
<ProseValue
|
|
1303
1356
|
content={() => asContent(after)}
|
|
1304
1357
|
value={after}
|
|
1305
|
-
plaintext={
|
|
1358
|
+
plaintext={leafFlags(items).plaintext}
|
|
1306
1359
|
block={multiline}
|
|
1307
|
-
paragraphs={
|
|
1360
|
+
paragraphs={leafFlags(items).paragraphs}
|
|
1308
1361
|
label={rowName(k)}
|
|
1309
1362
|
onChange={() => {}}
|
|
1310
1363
|
/>
|