@quillmark/svelte 0.35.1 → 0.37.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 +30 -18
- package/THEMING.md +1 -1
- package/dist/core/address.d.ts +5 -0
- package/dist/core/address.js +14 -0
- package/dist/core/codec/decode.d.ts +4 -2
- package/dist/core/codec/decode.js +5 -2
- package/dist/core/codec/field.d.ts +42 -16
- package/dist/core/codec/field.js +97 -28
- package/dist/core/codec/index.d.ts +8 -5
- package/dist/core/codec/index.js +4 -5
- package/dist/core/codec/prose.css +25 -81
- package/dist/core/codec/review.d.ts +31 -26
- package/dist/core/codec/review.js +93 -169
- package/dist/core/codec/schema.d.ts +12 -2
- package/dist/core/codec/schema.js +27 -5
- package/dist/core/codec/shortcuts.d.ts +5 -4
- package/dist/core/codec/shortcuts.js +9 -8
- package/dist/core/codec/table-view.js +15 -3
- package/dist/core/codec/value-diff.d.ts +21 -0
- package/dist/core/codec/value-diff.js +83 -0
- package/dist/core/codec/value-plan.d.ts +29 -0
- package/dist/core/codec/value-plan.js +157 -0
- package/dist/core/theme.css +46 -15
- package/dist/core/tooltip.css +49 -0
- package/dist/core/tooltip.d.ts +6 -0
- package/dist/core/tooltip.js +176 -0
- package/dist/preview/Preview.svelte +22 -1
- package/dist/preview/controller.js +38 -0
- package/dist/preview/strings.d.ts +2 -0
- package/dist/preview/strings.js +1 -0
- package/dist/visual/ArrayField.svelte +374 -96
- package/dist/visual/Card.svelte +33 -12
- package/dist/visual/Card.svelte.d.ts +3 -0
- package/dist/visual/CardControls.svelte +3 -3
- package/dist/visual/DateField.svelte +47 -5
- package/dist/visual/DiagnosticList.svelte +3 -2
- package/dist/visual/EnumField.svelte +20 -5
- package/dist/visual/EnumField.svelte.d.ts +5 -0
- package/dist/visual/Field.svelte +56 -47
- package/dist/visual/FieldHint.svelte +20 -8
- package/dist/visual/FormatPopover.svelte +54 -20
- package/dist/visual/MatrixField.svelte +48 -6
- package/dist/visual/MatrixField.svelte.d.ts +5 -0
- package/dist/visual/NumberField.svelte +131 -6
- package/dist/visual/NumberField.svelte.d.ts +5 -0
- package/dist/visual/ObjectField.svelte +60 -18
- package/dist/visual/ProseField.svelte +21 -5
- package/dist/visual/ProseField.svelte.d.ts +5 -1
- package/dist/visual/ProseValue.svelte +49 -8
- package/dist/visual/ProseValue.svelte.d.ts +7 -1
- package/dist/visual/ReviewCard.svelte +400 -0
- package/dist/visual/ReviewCard.svelte.d.ts +20 -0
- package/dist/visual/ReviewProposal.svelte +98 -138
- package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
- package/dist/visual/ReviewRows.svelte +6 -25
- package/dist/visual/ReviewRows.svelte.d.ts +1 -3
- package/dist/visual/SlashMenu.svelte +1 -0
- package/dist/visual/TipsCard.svelte +1 -1
- package/dist/visual/VariantField.svelte +45 -4
- package/dist/visual/VariantField.svelte.d.ts +5 -0
- package/dist/visual/VisualEditor.svelte +24 -9
- package/dist/visual/VisualEditor.svelte.d.ts +8 -1
- package/dist/visual/VisualEditorInner.svelte +917 -280
- package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
- package/dist/visual/controls.css +2 -2
- package/dist/visual/index.d.ts +2 -2
- package/dist/visual/proposals.d.ts +25 -24
- package/dist/visual/proposals.js +92 -32
- package/dist/visual/props.d.ts +18 -18
- package/dist/visual/review-order.d.ts +51 -0
- package/dist/visual/review-order.js +87 -0
- package/dist/visual/review.d.ts +94 -3
- package/dist/visual/review.js +37 -2
- package/dist/visual/review.svelte.d.ts +77 -20
- package/dist/visual/review.svelte.js +306 -49
- package/dist/visual/strings.d.ts +59 -25
- package/dist/visual/strings.js +90 -29
- package/dist/visual/structure.d.ts +17 -3
- package/dist/visual/structure.js +71 -5
- package/dist/visual/undo.svelte.d.ts +3 -1
- package/dist/visual/undo.svelte.js +7 -3
- package/package.json +2 -2
package/dist/visual/review.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { wordDiff } from '../core/codec/index.js';
|
|
1
|
+
import { asContent, wordDiff } from '../core/codec/index.js';
|
|
2
|
+
/** Whether an item proposes a whole card. */
|
|
3
|
+
export const byCard = (item) => 'add' in item || 'remove' in item;
|
|
2
4
|
/** Whether an item names blocks of a rich text field, which its prose leaf draws. */
|
|
3
5
|
export const byBlocks = (item) => 'replace' in item || 'insert' in item;
|
|
4
6
|
/** Whether an item is a field's own, drawn under its control. */
|
|
5
7
|
export const onField = (item) => 'field' in item && !byBlocks(item);
|
|
8
|
+
/** The projection of a review with nothing open: every place is where it is. */
|
|
9
|
+
export const NO_PROJECTION = {
|
|
10
|
+
ids: [],
|
|
11
|
+
toProjection: (at) => at,
|
|
12
|
+
toLive: (at) => at
|
|
13
|
+
};
|
|
6
14
|
/** One rung of a nested item's walk: the items naming this rung's own value, and the rest by
|
|
7
15
|
* the step they take next, that step consumed. */
|
|
8
16
|
export function splitReview(list) {
|
|
@@ -79,7 +87,7 @@ export function locate(value, steps, item, claimed) {
|
|
|
79
87
|
const free = (i) => sameValue(list[i], before) && !claimed.has(JSON.stringify([...head, i]));
|
|
80
88
|
if (free(at))
|
|
81
89
|
return { steps: claim(steps), found: true };
|
|
82
|
-
for (let d = 1; d
|
|
90
|
+
for (let d = 1; d <= Math.max(at, list.length - 1 - at); d++)
|
|
83
91
|
for (const i of [at - d, at + d])
|
|
84
92
|
if (i >= 0 && i < list.length && free(i))
|
|
85
93
|
return { steps: claim([...head, i]), found: true };
|
|
@@ -225,3 +233,30 @@ export function reviewRuns(before, after, words) {
|
|
|
225
233
|
out.push({ text: was.slice(at) });
|
|
226
234
|
return out;
|
|
227
235
|
}
|
|
236
|
+
/** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
|
|
237
|
+
* is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
|
|
238
|
+
export function textProposal(item, cleared) {
|
|
239
|
+
if (!item)
|
|
240
|
+
return undefined;
|
|
241
|
+
const after = item.after === undefined && cleared ? cleared : asContent(item.after);
|
|
242
|
+
const before = 'before' in item ? asContent(item.before) : undefined;
|
|
243
|
+
if (!after || ('before' in item && !before))
|
|
244
|
+
return undefined;
|
|
245
|
+
return { id: item.id, after, ...(before && { before }) };
|
|
246
|
+
}
|
|
247
|
+
/** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
|
|
248
|
+
* for one that clears it, which the input shows as what Accept leaves. */
|
|
249
|
+
export function numberProposal(item) {
|
|
250
|
+
return item && item.after != null ? { id: item.id, after: String(item.after) } : undefined;
|
|
251
|
+
}
|
|
252
|
+
/** What a control that shows one value shows while `item` stands: the value Accept would write,
|
|
253
|
+
* nothing where it clears the control, which then draws its default or its empty face. */
|
|
254
|
+
export function shownValue(item, stored) {
|
|
255
|
+
return item ? item.after : stored;
|
|
256
|
+
}
|
|
257
|
+
/** Whether a value a reader commits is the one a proposal would write: a blank and an unset value
|
|
258
|
+
* are one, since a control cleared over a default commits `''`. */
|
|
259
|
+
export function writesProposed(value, after) {
|
|
260
|
+
const blank = (v) => v == null || v === '';
|
|
261
|
+
return blank(value) ? blank(after) : sameValue(value, after);
|
|
262
|
+
}
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import type { PathStep } from '@quillmark/wasm';
|
|
2
2
|
import type { DocPath } from '../core/address.js';
|
|
3
|
-
import type { ReviewAction, ReviewReport,
|
|
4
|
-
import { type
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { ReviewAction, ReviewReport, TextReview } from '../core/codec/index.js';
|
|
4
|
+
import { type ValueState } from '../core/codec/index.js';
|
|
5
|
+
import { type CardProposal, type DeepReview, type FieldProposal, type ReviewDrawn, type ReviewItem, type ReviewUndrawn } from './review.js';
|
|
6
|
+
import { type CardLayout } from './review-order.js';
|
|
7
|
+
import type { StructuralUndo } from './undo.svelte.js';
|
|
8
|
+
/** A card proposed new, drawn after the card it follows. */
|
|
9
|
+
export type CardAdd = Extract<CardProposal, {
|
|
10
|
+
add: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
/** Where the open card items draw, by the session keys of the cards as they stand. */
|
|
13
|
+
export interface CardsReviewed {
|
|
14
|
+
/** The new cards after each card, by its key, `head` ahead of every card and `end` past the
|
|
15
|
+
* last, in list order. */
|
|
16
|
+
adds: ReadonlyMap<string, readonly CardAdd[]>;
|
|
17
|
+
/** The card each removal marks, by its key. */
|
|
18
|
+
removes: ReadonlyMap<string, Extract<CardProposal, {
|
|
19
|
+
remove: number;
|
|
20
|
+
}>>;
|
|
21
|
+
}
|
|
7
22
|
export interface Review {
|
|
8
23
|
/** The host's list, less what was answered here. */
|
|
9
24
|
readonly items: readonly ReviewItem[];
|
|
@@ -19,8 +34,16 @@ export interface Review {
|
|
|
19
34
|
}[];
|
|
20
35
|
/** The field proposals whose field no longer holds the value their `before` says was read. */
|
|
21
36
|
readonly fieldOutdated: ReadonlySet<string>;
|
|
22
|
-
/** The
|
|
37
|
+
/** The open items drawn, in the page's order. */
|
|
38
|
+
readonly order: readonly string[];
|
|
39
|
+
/** What the editor draws of the host's list, and why it draws what it does not. */
|
|
40
|
+
readonly report: ReviewDrawn;
|
|
41
|
+
/** The current item: open, drawn, and what the answer card and the review keys answer. */
|
|
23
42
|
readonly lit: string | undefined;
|
|
43
|
+
/** Where the open card items draw. */
|
|
44
|
+
readonly cards: CardsReviewed;
|
|
45
|
+
/** The card an accepted `add` wrote, by its session key, or none once it is taken back. */
|
|
46
|
+
wrote(id: string, key: string | undefined): void;
|
|
24
47
|
/** The items over the field at leaf `key`: its own, and those naming a place inside it,
|
|
25
48
|
* each with the steps to the value it names as the field holds it now. */
|
|
26
49
|
at(key: string): {
|
|
@@ -33,16 +56,36 @@ export interface Review {
|
|
|
33
56
|
keyOf(id: string): string | undefined;
|
|
34
57
|
/** A prose leaf's report of what it draws. */
|
|
35
58
|
drew(key: string, report: ReviewReport): void;
|
|
36
|
-
/** The item the
|
|
37
|
-
*
|
|
38
|
-
point(id: string | undefined
|
|
39
|
-
/** A reader's answer
|
|
40
|
-
act(id: string, action: ReviewAction
|
|
59
|
+
/** The item the caret is in, `undefined` where it left one: arriving names it at once, and
|
|
60
|
+
* leaving names nothing. */
|
|
61
|
+
point(id: string | undefined): void;
|
|
62
|
+
/** A reader's answer. False where it could not be made. */
|
|
63
|
+
act(id: string, action: ReviewAction): boolean;
|
|
64
|
+
/** Answer items as the answer card would, in the page's order: `'all'` is every item drawn,
|
|
65
|
+
* less on Accept the outdated ones, each of which would write over the reader. Each is
|
|
66
|
+
* planned against the document the one before it left, and one that cannot be answered
|
|
67
|
+
* stands. ⌘Z takes the call back whole. Returns the ids answered. */
|
|
68
|
+
answer(ids: readonly string[] | 'all', action: 'accept' | 'dismiss'): string[];
|
|
69
|
+
/** An edit landed that is no answer's: the answers before it can no longer be taken back. */
|
|
70
|
+
settled(): void;
|
|
71
|
+
/** A reader's commit of `value` on a control that shows one value, under the proposal `id`:
|
|
72
|
+
* the proposed value accepts it, any other is written and dismisses it, both one answer.
|
|
73
|
+
* False where it could not be made, and the commit is the caller's. */
|
|
74
|
+
answerWith(id: string, value: unknown): boolean;
|
|
75
|
+
/** A leaf of words drawing proposal `id` over what it holds: how it stands against it,
|
|
76
|
+
* `undefined` once it draws it no more. One the leaf already reads as is `applied`. */
|
|
77
|
+
planned(id: string, state: ValueState | undefined): void;
|
|
78
|
+
/** The value the place `item` names holds now, as its control is handed it. */
|
|
79
|
+
current(item: FieldProposal): unknown;
|
|
80
|
+
/** What Accept of `item` writes at a place holding `value`: a proposal of words a leaf draws
|
|
81
|
+
* carried onto what the reader wrote since its writer read it, else its `after`. */
|
|
82
|
+
writes(item: FieldProposal, value: unknown): unknown;
|
|
41
83
|
/** An answer leaf `key` has already given, the item listed or not: a reopen and a redo's
|
|
42
84
|
* accept arrive for items the host may have taken off or not yet put back. */
|
|
43
|
-
heard(id: string, action: ReviewAction, key: string
|
|
85
|
+
heard(id: string, action: ReviewAction, key: string): void;
|
|
44
86
|
/** A leaf is writing an answer, and is done: its edit is the answer's, not the reader's. */
|
|
45
87
|
writing(on: boolean): void;
|
|
88
|
+
/** Make `id` current at once: a step, a reveal, or a click or tap on it. */
|
|
46
89
|
reveal(id: string): void;
|
|
47
90
|
}
|
|
48
91
|
export interface ReviewSource {
|
|
@@ -64,16 +107,30 @@ export interface ReviewSource {
|
|
|
64
107
|
* one the editor does not hold. */
|
|
65
108
|
leafFor(path: DocPath): string | undefined;
|
|
66
109
|
/** A reader's answer, to make and to pass on: `item` where the list holds it, `key` the
|
|
67
|
-
* leaf that gave it where one did
|
|
68
|
-
* stands
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
* leaf that gave it where one did, `write` the value a dismissal made by an edit writes.
|
|
111
|
+
* `false` where it could not be made, and the item stands; a function is the way back, which
|
|
112
|
+
* takes back what the answer wrote and reopens the item. */
|
|
113
|
+
answer(id: string, item: ReviewItem | undefined, action: ReviewAction, key?: string, write?: {
|
|
114
|
+
value: unknown;
|
|
115
|
+
}): boolean | (() => void);
|
|
116
|
+
/** Answer the item the prose leaf at `key` draws, as its answer card would. False where the
|
|
117
|
+
* leaf could not. */
|
|
118
|
+
answerProse(key: string, id: string, action: 'accept' | 'dismiss'): boolean;
|
|
119
|
+
/** The editor's undo, which holds the newest journal entry for the key. */
|
|
120
|
+
undo: StructuralUndo;
|
|
121
|
+
/** The main card, then each card of the stack, each with its leaves as it draws them. */
|
|
122
|
+
layout(): readonly CardLayout[];
|
|
123
|
+
/** The session keys of the cards as they stood when the list was set, by index. */
|
|
124
|
+
listedCards(): readonly string[];
|
|
125
|
+
/** The session keys of the cards as they stand. */
|
|
126
|
+
liveCards(): readonly string[];
|
|
127
|
+
/** The session key of the card holding `$id` `id`, `undefined` where none does. */
|
|
128
|
+
cardFor(id: string): string | undefined;
|
|
129
|
+
/** The current item was answered: move on from it, in `order` where a batch of answers gives
|
|
130
|
+
* the order it stood in before them. */
|
|
131
|
+
answered?(id: string, order?: readonly string[]): void;
|
|
73
132
|
}
|
|
74
|
-
export declare function createReview(source: ReviewSource): Review
|
|
75
|
-
dispose(): void;
|
|
76
|
-
};
|
|
133
|
+
export declare function createReview(source: ReviewSource): Review;
|
|
77
134
|
export declare function setReview(review: Review): void;
|
|
78
135
|
/** The editor's review state, or {@link NO_REVIEW} off-tree. */
|
|
79
136
|
export declare function review(): Review;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
// The editor's review state: the host's list split by where each item draws, and the one
|
|
2
|
-
//
|
|
1
|
+
// The editor's review state: the host's list split by where each item draws, and the one current
|
|
2
|
+
// item, which the answer card and the review keys answer.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// The current item is sticky: a step, a reveal, a click or the caret arriving in an item names
|
|
5
|
+
// it, and it stays until another is named or it is answered. The pointer passing over an item
|
|
6
|
+
// names nothing.
|
|
7
7
|
//
|
|
8
8
|
// An answered item is drawn no more, from the answer and not from the host's next list: the
|
|
9
9
|
// reader's press shows at once however long the host takes to hand over a list without it.
|
|
10
|
+
//
|
|
11
|
+
// The answer journal holds the answers since the reader's last edit, each undone by ⌘Z from
|
|
12
|
+
// anywhere in the editor, newest first, its item reopened with it. An edit that is not an answer
|
|
13
|
+
// empties it: an inverse is good against the document it was recorded over. An answer's own
|
|
14
|
+
// writes, and an inverse's, go down the lanes an edit does, so they are flagged while they are
|
|
15
|
+
// made.
|
|
10
16
|
import { getContext, setContext } from 'svelte';
|
|
11
17
|
import { SvelteMap } from 'svelte/reactivity';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
import { asContent, planValue } from '../core/codec/index.js';
|
|
19
|
+
import { byBlocks, byCard, locate, onField, sameValue, textProposal, valueIn, writesProposed } from './review.js';
|
|
20
|
+
import { orderOf } from './review-order.js';
|
|
15
21
|
export function createReview(source) {
|
|
16
22
|
/** The ids answered, each until a list arrives without it. */
|
|
17
23
|
const answered = new Set();
|
|
@@ -44,9 +50,61 @@ export function createReview(source) {
|
|
|
44
50
|
}
|
|
45
51
|
return own;
|
|
46
52
|
});
|
|
53
|
+
/** The card each accepted `add` wrote, by item id. */
|
|
54
|
+
const written = new SvelteMap();
|
|
55
|
+
const cards = $derived.by(() => {
|
|
56
|
+
const listed = source.listedCards();
|
|
57
|
+
const live = source.liveCards();
|
|
58
|
+
const standing = new Set(live);
|
|
59
|
+
const all = source.items() ?? [];
|
|
60
|
+
const adds = new Map();
|
|
61
|
+
const removes = new Map();
|
|
62
|
+
const undrawn = [];
|
|
63
|
+
const open = new Set(items.map((item) => item.id));
|
|
64
|
+
for (const [at, item] of all.entries()) {
|
|
65
|
+
if (!byCard(item) || !open.has(item.id))
|
|
66
|
+
continue;
|
|
67
|
+
if ('remove' in item) {
|
|
68
|
+
const key = item.card === undefined ? listed[item.remove] : source.cardFor(item.card);
|
|
69
|
+
if (key !== undefined && standing.has(key))
|
|
70
|
+
removes.set(key, item);
|
|
71
|
+
else
|
|
72
|
+
undrawn.push({ id: item.id, reason: 'applied' });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const lead = leadOf(all, at, listed, standing);
|
|
76
|
+
adds.set(lead, [...(adds.get(lead) ?? []), item]);
|
|
77
|
+
}
|
|
78
|
+
return { adds, removes, undrawn };
|
|
79
|
+
});
|
|
80
|
+
/** Where the `add` at `at` of `all` stands: after the card the nearest earlier add of the same
|
|
81
|
+
* place wrote, else after the card it names, the head, or the end where that card is gone. */
|
|
82
|
+
function leadOf(all, at, listed, standing) {
|
|
83
|
+
const item = all[at];
|
|
84
|
+
for (let k = at - 1; k >= 0; k--) {
|
|
85
|
+
const before = all[k];
|
|
86
|
+
if (!byCard(before) || !('add' in before))
|
|
87
|
+
continue;
|
|
88
|
+
if (before.afterCard !== item.afterCard)
|
|
89
|
+
continue;
|
|
90
|
+
if (item.afterCard === undefined && before.after !== item.after)
|
|
91
|
+
continue;
|
|
92
|
+
const key = written.get(before.id);
|
|
93
|
+
if (key !== undefined && standing.has(key))
|
|
94
|
+
return key;
|
|
95
|
+
}
|
|
96
|
+
if (item.afterCard !== undefined) {
|
|
97
|
+
const key = source.cardFor(item.afterCard);
|
|
98
|
+
return key !== undefined && standing.has(key) ? key : 'end';
|
|
99
|
+
}
|
|
100
|
+
if (item.after === undefined || item.after < 0)
|
|
101
|
+
return 'head';
|
|
102
|
+
const key = listed[item.after];
|
|
103
|
+
return key !== undefined && standing.has(key) ? key : 'end';
|
|
104
|
+
}
|
|
47
105
|
const placed = $derived.by(() => {
|
|
48
106
|
const out = new Map();
|
|
49
|
-
const undrawn = [];
|
|
107
|
+
const undrawn = [...cards.undrawn];
|
|
50
108
|
/** The nested proposals whose `before` the field no longer holds. */
|
|
51
109
|
const moved = new Set();
|
|
52
110
|
const claims = new Map();
|
|
@@ -94,7 +152,10 @@ export function createReview(source) {
|
|
|
94
152
|
return { fields: out, undrawn, moved };
|
|
95
153
|
});
|
|
96
154
|
const fields = $derived(placed.fields);
|
|
97
|
-
|
|
155
|
+
/** Each proposal of words a leaf draws, by id: how it stands against what the leaf holds. */
|
|
156
|
+
const carried = new SvelteMap();
|
|
157
|
+
// A proposal made from a value the field no longer holds would write over the reader's. One a
|
|
158
|
+
// leaf of words carries is outdated only where the reader's writing meets it.
|
|
98
159
|
const outdated = $derived.by(() => {
|
|
99
160
|
const out = new Set(placed.moved);
|
|
100
161
|
for (const { proposed } of fields.values())
|
|
@@ -102,22 +163,133 @@ export function createReview(source) {
|
|
|
102
163
|
'before' in proposed &&
|
|
103
164
|
!sameValue(source.valueAt(proposed.field), proposed.before))
|
|
104
165
|
out.add(proposed.id);
|
|
166
|
+
for (const [id, state] of carried)
|
|
167
|
+
if (state === 'outdated')
|
|
168
|
+
out.add(id);
|
|
169
|
+
else
|
|
170
|
+
out.delete(id);
|
|
171
|
+
return out;
|
|
172
|
+
});
|
|
173
|
+
/** The field items no control draws, those a leaf already reads as proposed among them. */
|
|
174
|
+
const undrawnFields = $derived.by(() => {
|
|
175
|
+
const applied = [...carried].filter(([, state]) => state === 'applied');
|
|
176
|
+
if (!applied.length)
|
|
177
|
+
return placed.undrawn;
|
|
178
|
+
return [...placed.undrawn, ...applied.map(([id]) => ({ id, reason: 'applied' }))];
|
|
179
|
+
});
|
|
180
|
+
/** The open items drawn, in the page's order; one whose leaf no card lays out, last, in the
|
|
181
|
+
* list's order. */
|
|
182
|
+
const order = $derived.by(() => {
|
|
183
|
+
const undrawn = new Set(undrawnFields.map((u) => u.id));
|
|
184
|
+
const out = orderOf({
|
|
185
|
+
layout: source.layout(),
|
|
186
|
+
adds: cards.adds,
|
|
187
|
+
removes: cards.removes,
|
|
188
|
+
at: (key) => fields.get(key) ?? {},
|
|
189
|
+
reports: drawn,
|
|
190
|
+
undrawn
|
|
191
|
+
});
|
|
192
|
+
const placed = new Set(out);
|
|
193
|
+
const reported = new Set();
|
|
194
|
+
for (const report of drawn.values())
|
|
195
|
+
for (const id of report.ids)
|
|
196
|
+
reported.add(id);
|
|
197
|
+
for (const item of items) {
|
|
198
|
+
if (placed.has(item.id) || byCard(item))
|
|
199
|
+
continue;
|
|
200
|
+
if (onField(item) ? !undrawn.has(item.id) : reported.has(item.id))
|
|
201
|
+
out.push(item.id);
|
|
202
|
+
}
|
|
105
203
|
return out;
|
|
106
204
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
205
|
+
const report = $derived.by(() => {
|
|
206
|
+
const reported = new Set();
|
|
207
|
+
const stale = new Set(outdated);
|
|
208
|
+
const why = new Map();
|
|
209
|
+
for (const leaf of drawn.values()) {
|
|
210
|
+
for (const id of leaf.ids)
|
|
211
|
+
reported.add(id);
|
|
212
|
+
for (const id of leaf.outdated)
|
|
213
|
+
stale.add(id);
|
|
214
|
+
for (const { id, reason } of leaf.undrawn) {
|
|
215
|
+
reported.add(id);
|
|
216
|
+
why.set(id, reason);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
for (const { id, reason } of undrawnFields)
|
|
220
|
+
why.set(id, reason);
|
|
221
|
+
for (const item of items)
|
|
222
|
+
if (!reported.has(item.id) && !why.has(item.id) && byBlocks(item))
|
|
223
|
+
why.set(item.id, 'block');
|
|
224
|
+
return {
|
|
225
|
+
open: order,
|
|
226
|
+
outdated: order.filter((id) => stale.has(id)),
|
|
227
|
+
undrawn: items.flatMap((item) => {
|
|
228
|
+
const reason = why.get(item.id);
|
|
229
|
+
return reason ? [{ id: item.id, reason }] : [];
|
|
230
|
+
})
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
let current = $state();
|
|
234
|
+
const lit = $derived(current !== undefined && byId.has(current) ? current : undefined);
|
|
235
|
+
const name = (id) => {
|
|
236
|
+
current = id;
|
|
237
|
+
};
|
|
238
|
+
let journal = [];
|
|
239
|
+
/** The entry a batch of answers records into, and the current item it answered. */
|
|
240
|
+
let batching;
|
|
241
|
+
let offer;
|
|
242
|
+
let writing = 0;
|
|
243
|
+
const offerJournal = () => {
|
|
244
|
+
offer = journal.length
|
|
245
|
+
? source.undo.offer('', unanswer, { standing: true, quiet: true, answer: true })
|
|
246
|
+
: undefined;
|
|
247
|
+
};
|
|
248
|
+
const unanswer = () => {
|
|
249
|
+
const top = journal.pop();
|
|
250
|
+
if (!top)
|
|
251
|
+
return;
|
|
252
|
+
writing++;
|
|
253
|
+
try {
|
|
254
|
+
for (const inverse of [...top.inverses].reverse())
|
|
255
|
+
inverse();
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
writing--;
|
|
259
|
+
}
|
|
260
|
+
offerJournal();
|
|
261
|
+
};
|
|
262
|
+
const record = (entry) => {
|
|
263
|
+
// Another step took the key since: the answers before it are no longer the last thing
|
|
264
|
+
// that happened.
|
|
265
|
+
if (!offer || !source.undo.holds(offer))
|
|
266
|
+
journal = [];
|
|
267
|
+
journal.push(entry);
|
|
268
|
+
offerJournal();
|
|
269
|
+
};
|
|
270
|
+
const answering = (id, action, made) => {
|
|
271
|
+
if (made !== true) {
|
|
272
|
+
if (batching) {
|
|
273
|
+
batching.ids.push(id);
|
|
274
|
+
batching.inverses.push(made);
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
record({ ids: [id], inverses: [made] });
|
|
278
|
+
}
|
|
279
|
+
const was = current === id;
|
|
114
280
|
if (action === 'reopen')
|
|
115
281
|
answered.delete(id);
|
|
116
282
|
else
|
|
117
283
|
answered.add(id);
|
|
118
284
|
answers++;
|
|
119
|
-
if (
|
|
120
|
-
|
|
285
|
+
if (action === 'reopen')
|
|
286
|
+
name(id);
|
|
287
|
+
else if (!was)
|
|
288
|
+
return;
|
|
289
|
+
else if (batching)
|
|
290
|
+
batching.moved = id;
|
|
291
|
+
else
|
|
292
|
+
source.answered?.(id);
|
|
121
293
|
};
|
|
122
294
|
const self = {
|
|
123
295
|
get items() {
|
|
@@ -128,19 +300,40 @@ export function createReview(source) {
|
|
|
128
300
|
return drawn;
|
|
129
301
|
},
|
|
130
302
|
get fieldUndrawn() {
|
|
131
|
-
return
|
|
303
|
+
return undrawnFields;
|
|
132
304
|
},
|
|
133
305
|
get fieldOutdated() {
|
|
134
306
|
return outdated;
|
|
135
307
|
},
|
|
308
|
+
get order() {
|
|
309
|
+
return order;
|
|
310
|
+
},
|
|
311
|
+
get report() {
|
|
312
|
+
return report;
|
|
313
|
+
},
|
|
136
314
|
get lit() {
|
|
137
315
|
return lit;
|
|
138
316
|
},
|
|
317
|
+
get cards() {
|
|
318
|
+
return cards;
|
|
319
|
+
},
|
|
320
|
+
wrote(id, key) {
|
|
321
|
+
if (key === undefined)
|
|
322
|
+
written.delete(id);
|
|
323
|
+
else
|
|
324
|
+
written.set(id, key);
|
|
325
|
+
},
|
|
326
|
+
current(item) {
|
|
327
|
+
if (source.exact(item.field))
|
|
328
|
+
return source.valueAt(item.field);
|
|
329
|
+
const place = source.nested(item.field);
|
|
330
|
+
return place && valueIn(place.value, place.steps);
|
|
331
|
+
},
|
|
139
332
|
at: (key) => fields.get(key) ?? {},
|
|
140
333
|
marks: (key) => fields.has(key) || !!drawn.get(key)?.ids.length,
|
|
141
334
|
keyOf(id) {
|
|
142
335
|
const item = byId.get(id);
|
|
143
|
-
if (!item)
|
|
336
|
+
if (!item || byCard(item))
|
|
144
337
|
return undefined;
|
|
145
338
|
if (byBlocks(item)) {
|
|
146
339
|
const key = source.leafFor(item.field);
|
|
@@ -159,41 +352,95 @@ export function createReview(source) {
|
|
|
159
352
|
else
|
|
160
353
|
drawn.delete(key);
|
|
161
354
|
},
|
|
162
|
-
point(id
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
355
|
+
point(id) {
|
|
356
|
+
if (id !== undefined)
|
|
357
|
+
name(id);
|
|
358
|
+
},
|
|
359
|
+
act(id, action) {
|
|
360
|
+
const item = byId.get(id);
|
|
361
|
+
const made = item && source.answer(id, item, action);
|
|
362
|
+
if (!made)
|
|
363
|
+
return false;
|
|
364
|
+
answering(id, action, made);
|
|
365
|
+
return true;
|
|
366
|
+
},
|
|
367
|
+
answer(ids, action) {
|
|
368
|
+
const before = order;
|
|
369
|
+
const stale = new Set(ids === 'all' && action === 'accept' ? report.outdated : []);
|
|
370
|
+
const asked = ids === 'all'
|
|
371
|
+
? before.filter((id) => !stale.has(id))
|
|
372
|
+
: before.filter((id) => ids.includes(id));
|
|
373
|
+
const out = [];
|
|
374
|
+
const entry = { ids: [], inverses: [] };
|
|
375
|
+
batching = entry;
|
|
376
|
+
writing++;
|
|
377
|
+
try {
|
|
378
|
+
for (const id of asked) {
|
|
379
|
+
const item = byId.get(id);
|
|
380
|
+
if (!item)
|
|
381
|
+
continue;
|
|
382
|
+
const key = self.keyOf(id);
|
|
383
|
+
const made = onField(item) || byCard(item)
|
|
384
|
+
? self.act(id, action)
|
|
385
|
+
: key !== undefined && source.answerProse(key, id, action);
|
|
386
|
+
if (made)
|
|
387
|
+
out.push(id);
|
|
388
|
+
}
|
|
166
389
|
}
|
|
167
|
-
|
|
390
|
+
finally {
|
|
391
|
+
writing--;
|
|
392
|
+
batching = undefined;
|
|
393
|
+
}
|
|
394
|
+
if (entry.ids.length)
|
|
395
|
+
record({ ids: entry.ids, inverses: entry.inverses });
|
|
396
|
+
if (entry.moved !== undefined)
|
|
397
|
+
source.answered?.(entry.moved, before);
|
|
398
|
+
return out;
|
|
399
|
+
},
|
|
400
|
+
settled() {
|
|
401
|
+
if (writing)
|
|
168
402
|
return;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
revealed = undefined;
|
|
403
|
+
journal = [];
|
|
404
|
+
offer = undefined;
|
|
405
|
+
source.undo.settle();
|
|
173
406
|
},
|
|
174
|
-
|
|
407
|
+
answerWith(id, value) {
|
|
175
408
|
const item = byId.get(id);
|
|
176
|
-
if (!item || !
|
|
409
|
+
if (!item || !onField(item))
|
|
410
|
+
return false;
|
|
411
|
+
const action = writesProposed(value, item.after) ? 'accept' : 'dismiss';
|
|
412
|
+
const write = action === 'dismiss' ? { value } : undefined;
|
|
413
|
+
const made = source.answer(id, item, action, undefined, write);
|
|
414
|
+
if (!made)
|
|
177
415
|
return false;
|
|
178
|
-
answering(id, action,
|
|
416
|
+
answering(id, action, made);
|
|
179
417
|
return true;
|
|
180
418
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
419
|
+
planned(id, state) {
|
|
420
|
+
if (state === undefined)
|
|
421
|
+
carried.delete(id);
|
|
422
|
+
else if (carried.get(id) !== state)
|
|
423
|
+
carried.set(id, state);
|
|
424
|
+
},
|
|
425
|
+
writes(item, value) {
|
|
426
|
+
const text = carried.has(item.id) ? textProposal(item) : undefined;
|
|
427
|
+
const live = asContent(value);
|
|
428
|
+
if (!text?.before || !live || item.after === undefined)
|
|
429
|
+
return item.after;
|
|
430
|
+
const { merged } = planValue(text.before, live, text.after);
|
|
431
|
+
if (merged === text.after)
|
|
432
|
+
return item.after;
|
|
433
|
+
return typeof item.after === 'string' ? merged.text : merged;
|
|
434
|
+
},
|
|
435
|
+
writing(on) {
|
|
436
|
+
writing += on ? 1 : -1;
|
|
437
|
+
},
|
|
438
|
+
heard(id, action, key) {
|
|
439
|
+
const made = source.answer(id, byId.get(id), action, key);
|
|
440
|
+
if (made)
|
|
441
|
+
answering(id, action, made);
|
|
442
|
+
},
|
|
443
|
+
reveal: name
|
|
197
444
|
};
|
|
198
445
|
return self;
|
|
199
446
|
}
|
|
@@ -209,13 +456,23 @@ const NO_REVIEW = {
|
|
|
209
456
|
reports: new Map(),
|
|
210
457
|
fieldUndrawn: [],
|
|
211
458
|
fieldOutdated: new Set(),
|
|
459
|
+
order: [],
|
|
460
|
+
report: { open: [], outdated: [], undrawn: [] },
|
|
212
461
|
lit: undefined,
|
|
462
|
+
cards: { adds: new Map(), removes: new Map() },
|
|
463
|
+
wrote() { },
|
|
213
464
|
at: () => ({}),
|
|
214
465
|
marks: () => false,
|
|
215
466
|
keyOf: () => undefined,
|
|
216
467
|
drew() { },
|
|
217
468
|
point() { },
|
|
218
469
|
act: () => false,
|
|
470
|
+
answer: () => [],
|
|
471
|
+
settled() { },
|
|
472
|
+
answerWith: () => false,
|
|
473
|
+
planned() { },
|
|
474
|
+
current: () => undefined,
|
|
475
|
+
writes: (item) => item.after,
|
|
219
476
|
heard() { },
|
|
220
477
|
writing() { },
|
|
221
478
|
reveal() { }
|