@quillmark/svelte 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/THEMING.md +1 -1
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- package/dist/core/codec/field.d.ts +3 -6
- package/dist/core/codec/field.js +0 -10
- package/dist/core/codec/prose.css +1 -46
- package/dist/core/codec/review.d.ts +5 -20
- package/dist/core/codec/review.js +42 -199
- package/dist/core/theme.css +5 -7
- package/dist/visual/Field.svelte +10 -38
- package/dist/visual/ProseField.svelte +0 -2
- package/dist/visual/ReviewRows.svelte +11 -36
- package/dist/visual/VisualEditor.svelte +3 -4
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +61 -146
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/props.d.ts +10 -9
- package/dist/visual/review.d.ts +10 -45
- package/dist/visual/review.js +2 -44
- package/dist/visual/review.svelte.d.ts +3 -30
- package/dist/visual/review.svelte.js +27 -157
- package/dist/visual/strings.d.ts +2 -14
- package/dist/visual/strings.js +0 -6
- package/package.json +1 -1
- package/dist/visual/ReviewPopover.svelte +0 -179
- package/dist/visual/ReviewPopover.svelte.d.ts +0 -16
|
@@ -16,7 +16,7 @@ declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
|
|
|
16
16
|
revealReview: (id: string, opts?: {
|
|
17
17
|
focus?: boolean;
|
|
18
18
|
}) => Promise<boolean>;
|
|
19
|
-
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss"
|
|
19
|
+
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
|
|
20
20
|
stepReview: (dir: 1 | -1, opts?: {
|
|
21
21
|
focus?: boolean;
|
|
22
22
|
}) => Promise<string | undefined>;
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import { isQuillmarkError, MAIN_CARD_ADDR } from '@quillmark/wasm';
|
|
31
31
|
import {
|
|
32
32
|
addrForFieldPath,
|
|
33
|
+
cardMoved,
|
|
33
34
|
nearestAddrForFieldPath,
|
|
34
35
|
cardPath,
|
|
35
36
|
nestedAddrForFieldPath,
|
|
@@ -60,24 +61,14 @@
|
|
|
60
61
|
import { createReview, setReview } from './review.svelte.js';
|
|
61
62
|
import {
|
|
62
63
|
byBlocks,
|
|
63
|
-
isChange,
|
|
64
64
|
onField,
|
|
65
|
-
sameValue,
|
|
66
65
|
valueIn,
|
|
67
66
|
valueWith,
|
|
68
|
-
valueWithInserted,
|
|
69
|
-
besideOf,
|
|
70
|
-
type FieldChange,
|
|
71
67
|
type FieldProposal,
|
|
72
68
|
type ReviewDrawn
|
|
73
69
|
} from './review.js';
|
|
74
70
|
import type { CardId, CardOp, ChangeSource } from './signals.js';
|
|
75
|
-
import {
|
|
76
|
-
markAnchor,
|
|
77
|
-
REVIEW_KEYS,
|
|
78
|
-
type FieldController,
|
|
79
|
-
type LeafViews
|
|
80
|
-
} from '../core/codec/index.js';
|
|
71
|
+
import { REVIEW_KEYS, type FieldController, type LeafViews } from '../core/codec/index.js';
|
|
81
72
|
import {
|
|
82
73
|
IdSeq,
|
|
83
74
|
controlKind,
|
|
@@ -116,7 +107,6 @@
|
|
|
116
107
|
import Card from './Card.svelte';
|
|
117
108
|
import TipsCard from './TipsCard.svelte';
|
|
118
109
|
import FormatPopover from './FormatPopover.svelte';
|
|
119
|
-
import ReviewPopover, { type ReviewTarget } from './ReviewPopover.svelte';
|
|
120
110
|
// The add trigger and the kind menu draw shared recipes; a component carrying a
|
|
121
111
|
// shared class without also pulling its rule ships unstyled (controls.css).
|
|
122
112
|
import './controls.css';
|
|
@@ -174,6 +164,19 @@
|
|
|
174
164
|
// Session ids, one per composable card, reordered in lockstep with structure ops.
|
|
175
165
|
// svelte-ignore state_referenced_locally
|
|
176
166
|
let cardIds = $state<string[]>(seq.take(doc.cardCount));
|
|
167
|
+
/** The card keys as they stood when the host set its review list: an item names its card by
|
|
168
|
+
* index into these, so it stays on that card through every card op since. */
|
|
169
|
+
let listed: { list: VisualEditorProps['review']; cards: readonly string[] } | undefined;
|
|
170
|
+
function cardsListed(): readonly string[] {
|
|
171
|
+
const held = listed;
|
|
172
|
+
if (held && held.list === review) return held.cards;
|
|
173
|
+
listed = { list: review, cards: cardIds };
|
|
174
|
+
return cardIds;
|
|
175
|
+
}
|
|
176
|
+
function setCards(next: string[]): void {
|
|
177
|
+
cardsListed();
|
|
178
|
+
cardIds = next;
|
|
179
|
+
}
|
|
177
180
|
|
|
178
181
|
// Local commit-error diagnostics (INVARIANTS §Diagnostics, producer #2),
|
|
179
182
|
// id-keyed rather than positional so an error stays pinned to its field across a
|
|
@@ -314,31 +317,23 @@
|
|
|
314
317
|
const addr = nearestAddrForFieldPath(path);
|
|
315
318
|
return addr && declaredField(addr) ? resolveCardKey(addr, cardIds) : undefined;
|
|
316
319
|
};
|
|
317
|
-
/** The field proposals accepted here: the change each made, the leaf it is at, the write
|
|
318
|
-
* back, and whether the value is still the one written. */
|
|
319
|
-
const taken = new SvelteMap<
|
|
320
|
-
string,
|
|
321
|
-
{ change: FieldChange; leaf: string; back: () => void; holds: () => boolean }
|
|
322
|
-
>();
|
|
323
|
-
const takenChanges = $derived(new Map([...taken].map(([id, t]) => [id, t.change])));
|
|
324
320
|
/** Take a field's answer back: the value it replaced written back, if any, and the item
|
|
325
321
|
* reopened. */
|
|
326
322
|
const giveBack = (id: string, leaf: string, back?: () => void): void => {
|
|
327
323
|
back?.();
|
|
328
324
|
reviewing.heard(id, 'reopen', leaf);
|
|
329
325
|
};
|
|
326
|
+
/** The host's list with each card it names by index moved to where that card stands now. */
|
|
327
|
+
const reviewItems = $derived.by(() => {
|
|
328
|
+
const was = cardsListed();
|
|
329
|
+
if (!review?.length || was === cardIds) return review;
|
|
330
|
+
return review.map((item) => {
|
|
331
|
+
const field = cardMoved(item.field, was, cardIds);
|
|
332
|
+
return field === item.field ? item : { ...item, field };
|
|
333
|
+
});
|
|
334
|
+
});
|
|
330
335
|
const reviewing = createReview({
|
|
331
|
-
items: () =>
|
|
332
|
-
taken: () => takenChanges,
|
|
333
|
-
putBack(id) {
|
|
334
|
-
const field = taken.get(id);
|
|
335
|
-
if (field) {
|
|
336
|
-
giveBack(id, field.leaf, field.back);
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
const key = reviewing.keyOf(id);
|
|
340
|
-
return key !== undefined && !!leaves.prose(key)?.answerReview(id, 'reopen');
|
|
341
|
-
},
|
|
336
|
+
items: () => reviewItems,
|
|
342
337
|
keyFor: (path) => {
|
|
343
338
|
const key = reviewed(path);
|
|
344
339
|
return key && fieldKeyToString(key);
|
|
@@ -378,15 +373,9 @@
|
|
|
378
373
|
},
|
|
379
374
|
answer(id, item, action, key) {
|
|
380
375
|
let back: (() => void) | undefined;
|
|
381
|
-
if (action === '
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (!took) return false;
|
|
385
|
-
back = took.back;
|
|
386
|
-
taken.set(id, {
|
|
387
|
-
...took,
|
|
388
|
-
change: { id, state: 'changed', field: item.field, before: took.before }
|
|
389
|
-
});
|
|
376
|
+
if (action === 'accept' && item && onField(item)) {
|
|
377
|
+
back = takeField(item);
|
|
378
|
+
if (!back) return false;
|
|
390
379
|
}
|
|
391
380
|
onReview?.({ id, action });
|
|
392
381
|
if (action !== 'accept' && action !== 'dismiss') return true;
|
|
@@ -424,8 +413,6 @@
|
|
|
424
413
|
let writing = 0;
|
|
425
414
|
function settled(): void {
|
|
426
415
|
if (writing) return;
|
|
427
|
-
// A field set to another value since it was accepted no longer shows that change.
|
|
428
|
-
for (const [id, field] of taken) if (!field.holds()) taken.delete(id);
|
|
429
416
|
journal = [];
|
|
430
417
|
journalOffer = undefined;
|
|
431
418
|
undo.settle();
|
|
@@ -466,14 +453,13 @@
|
|
|
466
453
|
|
|
467
454
|
/**
|
|
468
455
|
* Take a field's proposal: its value down the lane the field's own control commits by, so
|
|
469
|
-
* the writer checks it and `onChange` reports it. A text leaf re-reads what was written.
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
456
|
+
* the writer checks it and `onChange` reports it. A text leaf re-reads what was written. A
|
|
457
|
+
* place inside the field is written as the whole value with that place alone changed, down
|
|
458
|
+
* the lane an edit of the place takes. Returns the write back to the value it replaced,
|
|
459
|
+
* which the journal runs before any older answer's, or `undefined` where the writer refused
|
|
460
|
+
* the value, which the field then says as it says any refused commit.
|
|
473
461
|
*/
|
|
474
|
-
function takeField(
|
|
475
|
-
item: FieldProposal
|
|
476
|
-
): { leaf: string; before: unknown; back: () => void; holds: () => boolean } | undefined {
|
|
462
|
+
function takeField(item: FieldProposal): (() => void) | undefined {
|
|
477
463
|
const key = reviewed(item.field);
|
|
478
464
|
if (!key?.field || typeof key.card === 'number') return undefined;
|
|
479
465
|
const isMain = key.card === undefined;
|
|
@@ -489,16 +475,15 @@
|
|
|
489
475
|
};
|
|
490
476
|
writing++;
|
|
491
477
|
try {
|
|
492
|
-
if (!addrForFieldPath(item.field)) return takeInside(item, leaf, write);
|
|
493
478
|
const before = doc.getStored(addr);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
479
|
+
let after = item.after;
|
|
480
|
+
if (!addrForFieldPath(item.field)) {
|
|
481
|
+
const steps = reviewing.at(leaf).nested?.find((e) => e.item.id === item.id)?.steps;
|
|
482
|
+
if (!steps) return undefined;
|
|
483
|
+
after = valueWith(current(), steps, item.after);
|
|
484
|
+
}
|
|
485
|
+
if (!write(after)) return undefined;
|
|
486
|
+
return () => void write(before);
|
|
502
487
|
} finally {
|
|
503
488
|
writing--;
|
|
504
489
|
}
|
|
@@ -509,40 +494,6 @@
|
|
|
509
494
|
if (at < 0) return undefined;
|
|
510
495
|
return fieldValues((isMain ? doc.main : doc.card(at)).payloadItems)[name];
|
|
511
496
|
}
|
|
512
|
-
/**
|
|
513
|
-
* A proposal for a place inside the field: the whole value written with that place
|
|
514
|
-
* changed, down the lane an edit of the place takes, and taken back by writing that
|
|
515
|
-
* place alone back, so another place accepted since keeps its change.
|
|
516
|
-
*/
|
|
517
|
-
function takeInside(
|
|
518
|
-
item: FieldProposal,
|
|
519
|
-
leaf: string,
|
|
520
|
-
write: (value: unknown) => boolean
|
|
521
|
-
): { leaf: string; before: unknown; back: () => void; holds: () => boolean } | undefined {
|
|
522
|
-
const steps = reviewing.at(leaf).nested?.find((e) => e.item.id === item.id)?.steps;
|
|
523
|
-
if (!steps) return undefined;
|
|
524
|
-
const value = current();
|
|
525
|
-
const last = steps.at(-1);
|
|
526
|
-
const list = typeof last === 'number' ? valueIn(value, steps.slice(0, -1)) : undefined;
|
|
527
|
-
const length = Array.isArray(list) ? list.length : 0;
|
|
528
|
-
const adds = typeof last === 'number' && last >= length && item.after !== undefined;
|
|
529
|
-
const removes = typeof last === 'number' && !adds && item.after === undefined;
|
|
530
|
-
const landed = adds ? [...steps.slice(0, -1), length] : steps;
|
|
531
|
-
const before = valueIn(value, steps);
|
|
532
|
-
const beside = removes ? besideOf(value, steps) : {};
|
|
533
|
-
if (!write(valueWith(value, steps, item.after))) return undefined;
|
|
534
|
-
return {
|
|
535
|
-
leaf,
|
|
536
|
-
before,
|
|
537
|
-
back: () =>
|
|
538
|
-
void write(
|
|
539
|
-
removes
|
|
540
|
-
? valueWithInserted(current(), steps, before, beside)
|
|
541
|
-
: valueWith(current(), landed, adds ? undefined : before)
|
|
542
|
-
),
|
|
543
|
-
holds: () => removes || sameValue(valueIn(current(), landed), item.after)
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
497
|
}
|
|
547
498
|
setReview(reviewing);
|
|
548
499
|
span.onEnd(reviewing.dispose);
|
|
@@ -593,12 +544,10 @@
|
|
|
593
544
|
if (!reported.has(item.id) && !why.has(item.id)) {
|
|
594
545
|
if (byBlocks(item)) why.set(item.id, 'block');
|
|
595
546
|
}
|
|
596
|
-
const
|
|
547
|
+
const open = reviewOrder();
|
|
597
548
|
return {
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
open: order.filter((id) => !reviewing.accepted.has(id)),
|
|
601
|
-
outdated: order.filter((id) => outdated.has(id) && !reviewing.accepted.has(id)),
|
|
549
|
+
open,
|
|
550
|
+
outdated: open.filter((id) => outdated.has(id)),
|
|
602
551
|
undrawn: reviewing.items.flatMap((item) => {
|
|
603
552
|
const reason = why.get(item.id);
|
|
604
553
|
return reason ? [{ id: item.id, reason }] : [];
|
|
@@ -607,18 +556,11 @@
|
|
|
607
556
|
}
|
|
608
557
|
// The report, to a host counting its own list: each change, read once the leaves the change
|
|
609
558
|
// mounted have drawn, so a list just handed over is not reported as anchored nowhere.
|
|
610
|
-
const NO_REPORT = JSON.stringify({
|
|
611
|
-
order: [],
|
|
612
|
-
accepted: [],
|
|
613
|
-
open: [],
|
|
614
|
-
outdated: [],
|
|
615
|
-
undrawn: []
|
|
616
|
-
} satisfies ReviewDrawn);
|
|
559
|
+
const NO_REPORT = JSON.stringify({ open: [], outdated: [], undrawn: [] } satisfies ReviewDrawn);
|
|
617
560
|
let drewReport = NO_REPORT;
|
|
618
561
|
let drewOrder: readonly string[] = [];
|
|
619
562
|
$effect(() => {
|
|
620
563
|
void reviewing.items;
|
|
621
|
-
void reviewing.accepted;
|
|
622
564
|
void reviewing.fieldUndrawn;
|
|
623
565
|
for (const id of reviewing.fieldOutdated) void id;
|
|
624
566
|
for (const report of reviewing.reports.values()) void report;
|
|
@@ -626,7 +568,7 @@
|
|
|
626
568
|
void tick().then(() => {
|
|
627
569
|
if (!live || !span.alive) return;
|
|
628
570
|
const report = reviewReport();
|
|
629
|
-
drewOrder = report.
|
|
571
|
+
drewOrder = report.open;
|
|
630
572
|
const joined = JSON.stringify(report);
|
|
631
573
|
if (joined === drewReport) return;
|
|
632
574
|
drewReport = joined;
|
|
@@ -675,24 +617,6 @@
|
|
|
675
617
|
e.preventDefault();
|
|
676
618
|
e.stopPropagation();
|
|
677
619
|
}
|
|
678
|
-
/** Where item `id` is drawn, for the card that hangs off it. */
|
|
679
|
-
function reviewTarget(id: string): ReviewTarget | undefined {
|
|
680
|
-
const key = reviewing.keyOf(id);
|
|
681
|
-
if (key === undefined) return undefined;
|
|
682
|
-
const prose = leaves.prose(key);
|
|
683
|
-
const mark = prose?.reviewElements(id)[0];
|
|
684
|
-
if (prose && mark)
|
|
685
|
-
return {
|
|
686
|
-
anchor: markAnchor(prose.el, () => prose.reviewElements(id)[0]),
|
|
687
|
-
removed: mark.classList.contains('qm-review-gone')
|
|
688
|
-
};
|
|
689
|
-
const control = leaves.control(key);
|
|
690
|
-
const own = [...(control?.el.querySelectorAll<HTMLElement>('[data-qm-review]') ?? [])].find(
|
|
691
|
-
(el) => el.getAttribute('data-qm-review') === id
|
|
692
|
-
);
|
|
693
|
-
return control && { anchor: own ?? control.el, removed: false };
|
|
694
|
-
}
|
|
695
|
-
|
|
696
620
|
// Card handles, for `setCaret`'s reveal hop: the one thing a leaf's own controller
|
|
697
621
|
// cannot do, since which group is open is the card's state (Card §revealLeaf).
|
|
698
622
|
type CardHandle = {
|
|
@@ -919,7 +843,7 @@
|
|
|
919
843
|
undo.withdraw();
|
|
920
844
|
const id = seq.next();
|
|
921
845
|
arm.arm();
|
|
922
|
-
|
|
846
|
+
setCards([...cardIds.slice(0, atIndex), id, ...cardIds.slice(atIndex)]);
|
|
923
847
|
bump('structure', id, atIndex, { op: 'insert', at: atIndex });
|
|
924
848
|
// Centred: the new card is the subject, and the neighbours it landed between
|
|
925
849
|
// are what say where it went.
|
|
@@ -985,7 +909,7 @@
|
|
|
985
909
|
const w = cardIds.slice();
|
|
986
910
|
const [x] = w.splice(from, 1);
|
|
987
911
|
w.splice(to, 0, x);
|
|
988
|
-
|
|
912
|
+
setCards(w);
|
|
989
913
|
bump('structure', id, to, { op: 'move', from, to });
|
|
990
914
|
if (held) void keepFocus(focused);
|
|
991
915
|
// `nearest`: the card was already in view and only needs to stay there, so one
|
|
@@ -1015,7 +939,7 @@
|
|
|
1015
939
|
const gone = removed.remove(id, card, cardIds, i);
|
|
1016
940
|
doc.removeCard(i);
|
|
1017
941
|
arm.arm();
|
|
1018
|
-
cardIds
|
|
942
|
+
setCards(cardIds.filter((_, k) => k !== i));
|
|
1019
943
|
forget(id);
|
|
1020
944
|
// No addr: the removed card has none left and every survivor's shifted. The
|
|
1021
945
|
// stack changed, not a leaf, and the id is the only handle the removal leaves.
|
|
@@ -1053,7 +977,7 @@
|
|
|
1053
977
|
const id = seq.next();
|
|
1054
978
|
removed.restored(gone, id);
|
|
1055
979
|
arm.arm();
|
|
1056
|
-
|
|
980
|
+
setCards([...cardIds.slice(0, i), id, ...cardIds.slice(i)]);
|
|
1057
981
|
bump('structure', id, i, { op: 'insert', at: i });
|
|
1058
982
|
void (async () => {
|
|
1059
983
|
if (!(await scrollCardIntoView(id, 'nearest'))) return;
|
|
@@ -1462,7 +1386,7 @@
|
|
|
1462
1386
|
else if (op.op === 'remove') forget(ids.splice(op.at, 1)[0]);
|
|
1463
1387
|
else ids.splice(op.to, 0, ...ids.splice(op.from, 1));
|
|
1464
1388
|
}
|
|
1465
|
-
|
|
1389
|
+
setCards(ids);
|
|
1466
1390
|
rederive();
|
|
1467
1391
|
}
|
|
1468
1392
|
|
|
@@ -1470,10 +1394,9 @@
|
|
|
1470
1394
|
|
|
1471
1395
|
/**
|
|
1472
1396
|
* Bring the review item `id` to the reader: open the panel holding it, scroll it to the
|
|
1473
|
-
* middle of the view, light it
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
* an item the editor does not draw.
|
|
1397
|
+
* middle of the view, and light it. The focus stays where it is, the reader having asked
|
|
1398
|
+
* to look, unless `focus` asks for it: the caret then goes into the item, or the focus to
|
|
1399
|
+
* its field, so the chords answer it. False for an item the editor does not draw.
|
|
1477
1400
|
*/
|
|
1478
1401
|
export function revealReview(id: string, opts: { focus?: boolean } = {}): Promise<boolean> {
|
|
1479
1402
|
return reveal(id, opts.focus ?? false, false);
|
|
@@ -1508,33 +1431,26 @@
|
|
|
1508
1431
|
|
|
1509
1432
|
/**
|
|
1510
1433
|
* Answer items as their buttons would, in document order: `'all'` is every item drawn. An
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
*
|
|
1514
|
-
*
|
|
1515
|
-
* caret moves. The batch raises no toast, the host's to word if it wants one, and ⌘Z takes
|
|
1516
|
-
* it back whole. Returns the ids answered.
|
|
1434
|
+
* item that cannot be answered (a proposal that no longer writes, a value the field's writer
|
|
1435
|
+
* refuses) stands. `onReview` hears each answer, and neither the focus nor the caret moves.
|
|
1436
|
+
* The batch raises no toast, the host's to word if it wants one, and ⌘Z takes it back whole.
|
|
1437
|
+
* Returns the ids answered.
|
|
1517
1438
|
*/
|
|
1518
1439
|
export function answerReview(
|
|
1519
1440
|
ids: readonly string[] | 'all',
|
|
1520
|
-
action: 'accept' | 'dismiss'
|
|
1441
|
+
action: 'accept' | 'dismiss'
|
|
1521
1442
|
): string[] {
|
|
1522
1443
|
if (!span.alive) return [];
|
|
1523
1444
|
const order = reviewOrder();
|
|
1524
1445
|
const asked = ids === 'all' ? order : order.filter((id) => ids.includes(id));
|
|
1525
1446
|
const out: string[] = [];
|
|
1526
|
-
if (action === 'reopen') {
|
|
1527
|
-
for (const id of asked)
|
|
1528
|
-
if (reviewing.accepted.has(id) && reviewing.act(id, 'reopen')) out.push(id);
|
|
1529
|
-
return out;
|
|
1530
|
-
}
|
|
1531
1447
|
const entry: Answered = { ids: [], inverses: [] };
|
|
1532
1448
|
batching = entry;
|
|
1533
1449
|
writing++;
|
|
1534
1450
|
try {
|
|
1535
1451
|
for (const id of asked) {
|
|
1536
1452
|
const item = reviewing.items.find((it) => it.id === id);
|
|
1537
|
-
if (!item
|
|
1453
|
+
if (!item) continue;
|
|
1538
1454
|
const key = reviewing.keyOf(id);
|
|
1539
1455
|
// Each one is planned against the document the one before it left.
|
|
1540
1456
|
const answered = !onField(item)
|
|
@@ -1739,7 +1655,6 @@
|
|
|
1739
1655
|
</div>
|
|
1740
1656
|
|
|
1741
1657
|
<FormatPopover {getActiveLeaf} families={fontFamilies} {fontLabels} />
|
|
1742
|
-
<ReviewPopover review={reviewing} targetFor={reviewTarget} />
|
|
1743
1658
|
|
|
1744
1659
|
<!-- The add affordance is gated on the schema declaring `card_kinds`, there being
|
|
1745
1660
|
nothing to seed otherwise. Cards render regardless: a kind with no schema degrades to
|
|
@@ -18,7 +18,7 @@ declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
|
|
|
18
18
|
revealReview: (id: string, opts?: {
|
|
19
19
|
focus?: boolean;
|
|
20
20
|
}) => Promise<boolean>;
|
|
21
|
-
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss"
|
|
21
|
+
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
|
|
22
22
|
stepReview: (dir: 1 | -1, opts?: {
|
|
23
23
|
focus?: boolean;
|
|
24
24
|
}) => Promise<string | undefined>;
|
package/dist/visual/props.d.ts
CHANGED
|
@@ -111,23 +111,24 @@ export interface VisualEditorProps {
|
|
|
111
111
|
/**
|
|
112
112
|
* What someone other than the reader proposes, for the editor to draw where each item sits
|
|
113
113
|
* ({@link ReviewItem}): a proposal as a word-level edit of its own blocks with Accept and
|
|
114
|
-
* Dismiss at its end, a field's proposed value under its control
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* item
|
|
114
|
+
* Dismiss at its end, and a field's proposed value under its control. Declarative: the host
|
|
115
|
+
* sets the list once and clears it once, and the editor draws every answer while the list
|
|
116
|
+
* holds the item: an answered item is drawn no more, and an accepted one is plain text. A
|
|
117
|
+
* card an item names by index is read against the cards as they stood when the list was
|
|
118
|
+
* set, so the item stays on its card through `applyCardOps` and the reader's own card
|
|
119
|
+
* edits; an item whose card is gone draws nothing.
|
|
118
120
|
*/
|
|
119
121
|
review?: readonly ReviewItem[];
|
|
120
122
|
/**
|
|
121
123
|
* A reader answered an item: a button on it, `Mod-Enter` / `Mod-.` with the caret or the
|
|
122
|
-
* focus in it, or a host's `answerReview`; or undid an answer
|
|
123
|
-
* change's Undo, `reopen`. The editor has made every write an answer asks for and draws it,
|
|
124
|
+
* focus in it, or a host's `answerReview`; or undid an answer with ⌘Z, `reopen`. The editor has made every write an answer asks for and draws it,
|
|
124
125
|
* so the host leaves `review` as it set it.
|
|
125
126
|
*/
|
|
126
127
|
onReview?: (event: ReviewEvent) => void;
|
|
127
128
|
/**
|
|
128
|
-
* What the editor draws of `review`, on each change once the leaves have drawn: the
|
|
129
|
-
* in document order, the
|
|
130
|
-
*
|
|
129
|
+
* What the editor draws of `review`, on each change once the leaves have drawn: the open
|
|
130
|
+
* items in document order, the proposals the reader has written past since, and every
|
|
131
|
+
* listed item it does not draw with why. What a
|
|
131
132
|
* host counts and steps its own list by.
|
|
132
133
|
*/
|
|
133
134
|
onReviewDrawn?: (drawn: ReviewDrawn) => void;
|
package/dist/visual/review.d.ts
CHANGED
|
@@ -19,9 +19,8 @@ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
|
|
|
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.
|
|
21
21
|
*
|
|
22
|
-
* An item whose place the editor does not hold draws nothing.
|
|
23
|
-
*
|
|
24
|
-
* that takes it back, until the list lets it go.
|
|
22
|
+
* An item whose place the editor does not hold draws nothing. An answered item is drawn no
|
|
23
|
+
* more: a dismissed one wrote nothing, and an accepted one is plain text in the document.
|
|
25
24
|
*/
|
|
26
25
|
export type ReviewItem = FieldProposal | BlockProposal;
|
|
27
26
|
/** A proposal over blocks of a rich text field, by their ids. */
|
|
@@ -39,15 +38,15 @@ export type BlockProposal = {
|
|
|
39
38
|
};
|
|
40
39
|
/** Whether an item names blocks of a rich text field, which its prose leaf draws. */
|
|
41
40
|
export declare const byBlocks: (item: object) => item is BlockProposal;
|
|
42
|
-
/** Whether an item is a field's own, drawn
|
|
43
|
-
export declare const onField: (item: object) => item is
|
|
41
|
+
/** Whether an item is a field's own, drawn under its control. */
|
|
42
|
+
export declare const onField: (item: object) => item is FieldProposal;
|
|
44
43
|
/**
|
|
45
44
|
* A reader's answer to an item.
|
|
46
45
|
*
|
|
47
46
|
* - `accept`: a proposal taken. The editor has written it by now, as an edit of the reader's.
|
|
48
47
|
* - `dismiss`: a proposal turned down. Nothing is written.
|
|
49
|
-
* - `reopen`: an accept or a dismissal undone. The editor has taken back what an accept
|
|
50
|
-
* and the item is open again.
|
|
48
|
+
* - `reopen`: an accept or a dismissal undone by ⌘Z. The editor has taken back what an accept
|
|
49
|
+
* wrote, and the item is open again.
|
|
51
50
|
*/
|
|
52
51
|
export interface ReviewEvent {
|
|
53
52
|
id: string;
|
|
@@ -66,12 +65,8 @@ export interface ReviewEvent {
|
|
|
66
65
|
export type ReviewUndrawn = 'block' | 'field' | 'parse' | 'taken' | 'applied';
|
|
67
66
|
/** What the editor draws of the host's list. */
|
|
68
67
|
export interface ReviewDrawn {
|
|
69
|
-
/** The proposals the editor draws, in document order
|
|
70
|
-
|
|
71
|
-
/** The proposals accepted and still listed, which the editor draws as the changes they made. */
|
|
72
|
-
accepted: readonly string[];
|
|
73
|
-
/** The drawn items still waiting for an answer, in document order: the rest of `order`. A
|
|
74
|
-
* review is answered when it is empty. */
|
|
68
|
+
/** The proposals the editor draws, in document order, each waiting for an answer. A review
|
|
69
|
+
* is answered when it is empty. */
|
|
75
70
|
open: readonly string[];
|
|
76
71
|
/** Drawn proposals the reader's own writing meets: words both changed, a block one names
|
|
77
72
|
* gone or no longer what its writer read, or a field no longer holding its `before`. */
|
|
@@ -82,18 +77,6 @@ export interface ReviewDrawn {
|
|
|
82
77
|
reason: ReviewUndrawn;
|
|
83
78
|
}[];
|
|
84
79
|
}
|
|
85
|
-
/** A field proposal accepted, as the change it made over its control, `before` the value it
|
|
86
|
-
* replaced. The editor's own, tagged as it takes the accept; a host lists proposals alone. */
|
|
87
|
-
export type FieldChange = {
|
|
88
|
-
id: string;
|
|
89
|
-
state: 'changed';
|
|
90
|
-
field: DocPath;
|
|
91
|
-
before?: unknown;
|
|
92
|
-
};
|
|
93
|
-
/** Whether an item is an accepted proposal the editor holds, rather than one the host lists. */
|
|
94
|
-
export declare const isChange: <T extends object>(item: T) => item is Extract<T, {
|
|
95
|
-
state: "changed";
|
|
96
|
-
}>;
|
|
97
80
|
/** A proposal under a field's control. */
|
|
98
81
|
export type FieldProposal = {
|
|
99
82
|
id: string;
|
|
@@ -105,7 +88,7 @@ export type FieldProposal = {
|
|
|
105
88
|
* value it names, a member of a list by its index, a cell of a record by its key. */
|
|
106
89
|
export interface DeepReview {
|
|
107
90
|
steps: readonly PathStep[];
|
|
108
|
-
item: FieldProposal
|
|
91
|
+
item: FieldProposal;
|
|
109
92
|
}
|
|
110
93
|
/** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
|
|
111
94
|
* the step they take next, that step consumed. */
|
|
@@ -118,31 +101,13 @@ export declare function valueIn(value: unknown, steps: readonly PathStep[]): unk
|
|
|
118
101
|
/** `value` with what `steps` reach set to `to`: a list's member past its end appended, and one
|
|
119
102
|
* set to nothing taken out; a record's cell set to nothing left out. Copies on the way down. */
|
|
120
103
|
export declare function valueWith(value: unknown, steps: readonly PathStep[], to: unknown): unknown;
|
|
121
|
-
/** The members that stood either side of the one `steps` reach in `value`, which put it back. */
|
|
122
|
-
export interface Beside {
|
|
123
|
-
before?: {
|
|
124
|
-
member: unknown;
|
|
125
|
-
};
|
|
126
|
-
after?: {
|
|
127
|
-
member: unknown;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/** The members either side of the one `steps` reach in `value`. */
|
|
131
|
-
export declare function besideOf(value: unknown, steps: readonly PathStep[]): Beside;
|
|
132
|
-
/**
|
|
133
|
-
* `value` with a member put back at `steps`, the ones from it on moving down one: after the
|
|
134
|
-
* member that stood before it, else before the one that stood after it, the nearest of each to
|
|
135
|
-
* the index, so members put back in any order land where they stood; at the index where
|
|
136
|
-
* neither stands.
|
|
137
|
-
*/
|
|
138
|
-
export declare function valueWithInserted(value: unknown, steps: readonly PathStep[], member: unknown, beside?: Beside): unknown;
|
|
139
104
|
/**
|
|
140
105
|
* Where a field proposal's steps land in `value` as it stands. A list's member is found by its
|
|
141
106
|
* index where it holds `before`, else as the nearest member holding `before` that `claimed`
|
|
142
107
|
* does not already hold, so one member taken out does not move another's proposal onto the
|
|
143
108
|
* wrong row. `found` is false where the proposal has a `before` nothing holds.
|
|
144
109
|
*/
|
|
145
|
-
export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal
|
|
110
|
+
export declare function locate(value: unknown, steps: readonly PathStep[], item: FieldProposal, claimed: Set<string>): {
|
|
146
111
|
steps: readonly PathStep[];
|
|
147
112
|
found: boolean;
|
|
148
113
|
};
|
package/dist/visual/review.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { wordDiff } from '../core/codec/index.js';
|
|
2
2
|
/** Whether an item names blocks of a rich text field, which its prose leaf draws. */
|
|
3
3
|
export const byBlocks = (item) => 'replace' in item || 'insert' in item;
|
|
4
|
-
/** Whether an item is a field's own, drawn
|
|
4
|
+
/** Whether an item is a field's own, drawn under its control. */
|
|
5
5
|
export const onField = (item) => 'field' in item && !byBlocks(item);
|
|
6
|
-
/** Whether an item is an accepted proposal the editor holds, rather than one the host lists. */
|
|
7
|
-
export const isChange = (item) => 'state' in item && item.state === 'changed';
|
|
8
6
|
/** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
|
|
9
7
|
* the step they take next, that step consumed. */
|
|
10
8
|
export function splitReview(list) {
|
|
@@ -58,46 +56,6 @@ export function valueWith(value, steps, to) {
|
|
|
58
56
|
record[step] = next;
|
|
59
57
|
return record;
|
|
60
58
|
}
|
|
61
|
-
/** The members either side of the one `steps` reach in `value`. */
|
|
62
|
-
export function besideOf(value, steps) {
|
|
63
|
-
const at = steps.at(-1);
|
|
64
|
-
const list = valueIn(value, steps.slice(0, -1));
|
|
65
|
-
if (typeof at !== 'number' || !Array.isArray(list))
|
|
66
|
-
return {};
|
|
67
|
-
return {
|
|
68
|
-
...(at > 0 && at - 1 < list.length && { before: { member: list[at - 1] } }),
|
|
69
|
-
...(at + 1 < list.length && { after: { member: list[at + 1] } })
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* `value` with a member put back at `steps`, the ones from it on moving down one: after the
|
|
74
|
-
* member that stood before it, else before the one that stood after it, the nearest of each to
|
|
75
|
-
* the index, so members put back in any order land where they stood; at the index where
|
|
76
|
-
* neither stands.
|
|
77
|
-
*/
|
|
78
|
-
export function valueWithInserted(value, steps, member, beside = {}) {
|
|
79
|
-
const head = steps.slice(0, -1);
|
|
80
|
-
const at = steps.at(-1);
|
|
81
|
-
const list = valueIn(value, head);
|
|
82
|
-
if (typeof at !== 'number' || !Array.isArray(list))
|
|
83
|
-
return valueWith(value, steps, member);
|
|
84
|
-
const nearest = (near, to) => {
|
|
85
|
-
if (!near)
|
|
86
|
-
return undefined;
|
|
87
|
-
let found;
|
|
88
|
-
list.forEach((m, i) => {
|
|
89
|
-
if (sameValue(m, near.member) &&
|
|
90
|
-
(found === undefined || Math.abs(i - to) < Math.abs(found - to)))
|
|
91
|
-
found = i;
|
|
92
|
-
});
|
|
93
|
-
return found;
|
|
94
|
-
};
|
|
95
|
-
const after = nearest(beside.before, at - 1);
|
|
96
|
-
const before = after === undefined ? nearest(beside.after, at) : undefined;
|
|
97
|
-
const next = [...list];
|
|
98
|
-
next.splice(after !== undefined ? after + 1 : (before ?? Math.min(at, next.length)), 0, member);
|
|
99
|
-
return valueWith(value, head, next);
|
|
100
|
-
}
|
|
101
59
|
/**
|
|
102
60
|
* Where a field proposal's steps land in `value` as it stands. A list's member is found by its
|
|
103
61
|
* index where it holds `before`, else as the nearest member holding `before` that `claimed`
|
|
@@ -105,7 +63,7 @@ export function valueWithInserted(value, steps, member, beside = {}) {
|
|
|
105
63
|
* wrong row. `found` is false where the proposal has a `before` nothing holds.
|
|
106
64
|
*/
|
|
107
65
|
export function locate(value, steps, item, claimed) {
|
|
108
|
-
const read =
|
|
66
|
+
const read = 'before' in item;
|
|
109
67
|
const before = read ? item.before : undefined;
|
|
110
68
|
const at = steps.at(-1);
|
|
111
69
|
const head = steps.slice(0, -1);
|