@quillmark/svelte 0.35.0 → 0.36.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 +21 -13
- package/dist/core/address.d.ts +5 -0
- package/dist/core/address.js +14 -0
- package/dist/core/codec/field.d.ts +30 -7
- package/dist/core/codec/field.js +67 -4
- package/dist/core/codec/index.d.ts +6 -3
- package/dist/core/codec/index.js +2 -3
- package/dist/core/codec/prose.css +11 -77
- package/dist/core/codec/review.d.ts +27 -21
- package/dist/core/codec/review.js +87 -148
- package/dist/core/codec/shortcuts.d.ts +3 -3
- package/dist/core/codec/shortcuts.js +7 -7
- 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 +7 -2
- package/dist/visual/ArrayField.svelte +191 -17
- package/dist/visual/Card.svelte +12 -1
- package/dist/visual/Card.svelte.d.ts +3 -0
- package/dist/visual/EnumField.svelte +14 -4
- package/dist/visual/EnumField.svelte.d.ts +3 -0
- package/dist/visual/Field.svelte +56 -47
- package/dist/visual/FieldHint.svelte +9 -15
- package/dist/visual/FormatPopover.svelte +1 -0
- package/dist/visual/MatrixField.svelte +43 -5
- package/dist/visual/MatrixField.svelte.d.ts +5 -0
- package/dist/visual/NumberField.svelte +112 -3
- package/dist/visual/NumberField.svelte.d.ts +5 -0
- package/dist/visual/ObjectField.svelte +54 -16
- package/dist/visual/ProseField.svelte +16 -3
- package/dist/visual/ProseField.svelte.d.ts +3 -0
- package/dist/visual/ProseValue.svelte +38 -2
- package/dist/visual/ProseValue.svelte.d.ts +3 -0
- package/dist/visual/ReviewCard.svelte +347 -0
- package/dist/visual/ReviewCard.svelte.d.ts +19 -0
- package/dist/visual/ReviewProposal.svelte +104 -131
- 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/VariantField.svelte +44 -4
- package/dist/visual/VariantField.svelte.d.ts +5 -0
- package/dist/visual/VisualEditor.svelte +16 -7
- package/dist/visual/VisualEditor.svelte.d.ts +3 -0
- package/dist/visual/VisualEditorInner.svelte +840 -115
- package/dist/visual/VisualEditorInner.svelte.d.ts +3 -0
- package/dist/visual/index.d.ts +2 -2
- package/dist/visual/proposals.d.ts +13 -22
- package/dist/visual/proposals.js +69 -32
- package/dist/visual/props.d.ts +18 -18
- package/dist/visual/review.d.ts +68 -3
- package/dist/visual/review.js +36 -1
- package/dist/visual/review.svelte.d.ts +55 -15
- package/dist/visual/review.svelte.js +156 -42
- package/dist/visual/strings.d.ts +23 -6
- package/dist/visual/strings.js +10 -5
- package/dist/visual/undo.svelte.d.ts +3 -1
- package/dist/visual/undo.svelte.js +7 -3
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type DocPath, type Landing } from '../core/address.js';
|
|
2
|
+
import type { Document } from '@quillmark/wasm';
|
|
2
3
|
import type { VisualEditorProps } from './props.js';
|
|
3
4
|
import type { Delta } from '../core/codec/positions.js';
|
|
5
|
+
import { type ReviewProjection } from './review.js';
|
|
4
6
|
import type { CardId, CardOp } from './signals.js';
|
|
5
7
|
import { type ActiveProse } from './leaves.js';
|
|
6
8
|
declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
|
|
@@ -19,6 +21,7 @@ declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
|
|
|
19
21
|
focus?: boolean;
|
|
20
22
|
}) => Promise<boolean>;
|
|
21
23
|
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
|
|
24
|
+
projectReview: (target: Document) => ReviewProjection;
|
|
22
25
|
stepReview: (dir: 1 | -1, opts?: {
|
|
23
26
|
focus?: boolean;
|
|
24
27
|
}) => Promise<string | undefined>;
|
package/dist/visual/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export type { VisualStrings, VisualStringsInput, FormatDiagnostic } from './stri
|
|
|
7
7
|
export type { BodyPlaceholder, BodyPlaceholderContext } from './structure.js';
|
|
8
8
|
export { editorShortcuts } from '../core/codec/index.js';
|
|
9
9
|
export type { EditorShortcut, ShortcutScope } from '../core/codec/index.js';
|
|
10
|
-
export type { BlockProposal, ReviewDrawn, ReviewEvent, ReviewItem, ReviewUndrawn } from './review.js';
|
|
10
|
+
export type { BlockProposal, CardProposal, FieldProposal, ReviewDrawn, ReviewEvent, ReviewItem, ReviewProjection, ReviewUndrawn } from './review.js';
|
|
11
11
|
export type { BlockPlace } from '../core/codec/index.js';
|
|
12
12
|
export { proposalsBetween } from './proposals.js';
|
|
13
|
-
export type {
|
|
13
|
+
export type { Proposed } from './proposals.js';
|
|
14
14
|
export type { ReviewAction } from '../core/codec/index.js';
|
|
15
15
|
export { REVIEW_KEYS } from '../core/codec/index.js';
|
|
16
16
|
export { patchEditorExt } from './ext.js';
|
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Document, Quill } from '@quillmark/wasm';
|
|
2
2
|
import { type ReviewItem } from './review.js';
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
/** `card` as the answer holds it. `after` is the id of the card it follows in the answer,
|
|
6
|
-
* absent at the head; it can be a card added before it, so a host adds them in list order. */
|
|
7
|
-
{
|
|
8
|
-
type: 'add';
|
|
9
|
-
card: Card;
|
|
10
|
-
after?: string;
|
|
11
|
-
}
|
|
12
|
-
/** The base's card `id`, of `kind`. */
|
|
13
|
-
| {
|
|
14
|
-
type: 'remove';
|
|
15
|
-
id: string;
|
|
16
|
-
kind: string;
|
|
17
|
-
};
|
|
18
|
-
/** The review an answer makes: the items the editor draws, and the cards it adds or removes. */
|
|
3
|
+
/** The review an answer makes: the items the editor draws, the cards it adds or takes out
|
|
4
|
+
* among them. */
|
|
19
5
|
export interface Proposed {
|
|
20
6
|
items: ReviewItem[];
|
|
21
|
-
cards: CardProposal[];
|
|
22
7
|
}
|
|
23
8
|
/**
|
|
24
9
|
* The review list from `base`, the document as the answer's writer read it, to `answer`, the
|
|
@@ -30,11 +15,17 @@ export interface Proposed {
|
|
|
30
15
|
* per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
|
|
31
16
|
* Every other field takes an item per place that changed: a record's cell, and a list's member,
|
|
32
17
|
* changed, taken out, or appended past the end, two appends to one list at successive indices.
|
|
33
|
-
* A
|
|
34
|
-
*
|
|
18
|
+
* A list that gains members anywhere but its end is compared member by member at each index, so
|
|
19
|
+
* each place its controls draw says its own change; a record or a list written where none was is
|
|
20
|
+
* compared with an empty one. A choice with variants is compared as a record, its discriminant a
|
|
21
|
+
* cell of it, and a checklist member by member: one ticked or unticked is proposed whole, and one
|
|
22
|
+
* held on both sides cell by cell. A one-line rich text field, a value of a type nothing nests in, a
|
|
23
|
+
* field the answer clears, and a rich text value inside a record or a list are proposed whole. Values
|
|
35
24
|
* are in the form the editor's controls are handed, a text cell as its `Content`.
|
|
36
25
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
26
|
+
* A card the answer adds is an `add` item after the nearest card before it that the answer
|
|
27
|
+
* keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
|
|
28
|
+
* Paths and card indexes are `base`'s. A card the answer retypes is listed as taken out and
|
|
29
|
+
* added; one it moves is not listed. `mint` names each item, and by default names it uniquely for the page.
|
|
39
30
|
*/
|
|
40
31
|
export declare function proposalsBetween(quill: Quill, base: Document, answer: Document, mint?: () => string): Proposed;
|
package/dist/visual/proposals.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fieldPathForAddr } from '../core/address.js';
|
|
2
2
|
import { sameValue } from './review.js';
|
|
3
|
-
import { baseType, fieldValues, oneLine } from './structure.js';
|
|
3
|
+
import { VARIANT_DISCRIMINANT, baseType, fieldValues, oneLine } from './structure.js';
|
|
4
4
|
let minted = 0;
|
|
5
5
|
/**
|
|
6
6
|
* The review list from `base`, the document as the answer's writer read it, to `answer`, the
|
|
@@ -12,16 +12,21 @@ let minted = 0;
|
|
|
12
12
|
* per block the answer rewrote or took out, and one `insert` item per run of blocks it added.
|
|
13
13
|
* Every other field takes an item per place that changed: a record's cell, and a list's member,
|
|
14
14
|
* changed, taken out, or appended past the end, two appends to one list at successive indices.
|
|
15
|
-
* A
|
|
16
|
-
*
|
|
15
|
+
* A list that gains members anywhere but its end is compared member by member at each index, so
|
|
16
|
+
* each place its controls draw says its own change; a record or a list written where none was is
|
|
17
|
+
* compared with an empty one. A choice with variants is compared as a record, its discriminant a
|
|
18
|
+
* cell of it, and a checklist member by member: one ticked or unticked is proposed whole, and one
|
|
19
|
+
* held on both sides cell by cell. A one-line rich text field, a value of a type nothing nests in, a
|
|
20
|
+
* field the answer clears, and a rich text value inside a record or a list are proposed whole. Values
|
|
17
21
|
* are in the form the editor's controls are handed, a text cell as its `Content`.
|
|
18
22
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
23
|
+
* A card the answer adds is an `add` item after the nearest card before it that the answer
|
|
24
|
+
* keeps, so cards it adds in a run stand in list order; one it takes out is a `remove` item.
|
|
25
|
+
* Paths and card indexes are `base`'s. A card the answer retypes is listed as taken out and
|
|
26
|
+
* added; one it moves is not listed. `mint` names each item, and by default names it uniquely for the page.
|
|
21
27
|
*/
|
|
22
28
|
export function proposalsBetween(quill, base, answer, mint = () => `review-${minted++}`) {
|
|
23
29
|
const items = [];
|
|
24
|
-
const cards = [];
|
|
25
30
|
const kinds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).kind);
|
|
26
31
|
const baseIds = Array.from({ length: base.cardCount }, (_, i) => base.card(i).id ?? '');
|
|
27
32
|
const answerIds = Array.from({ length: answer.cardCount }, (_, i) => answer.card(i).id ?? '');
|
|
@@ -91,26 +96,57 @@ export function proposalsBetween(quill, base, answer, mint = () => `review-${min
|
|
|
91
96
|
...(now !== undefined && { after: now })
|
|
92
97
|
});
|
|
93
98
|
const kind = f && baseType(f);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
const records = isRecord(now) && (was == null || isRecord(was));
|
|
100
|
+
const cells = isRecord(was) ? was : {};
|
|
101
|
+
if (kind === 'object' && f?.properties && records) {
|
|
102
|
+
for (const key of keysOf(f.properties, cells, now))
|
|
103
|
+
value(pathAt, f.properties[key], [...steps, key], cells[key], now[key]);
|
|
97
104
|
return;
|
|
98
105
|
}
|
|
99
|
-
if (kind
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if (kind === 'enum' && f?.variants && records) {
|
|
107
|
+
const cell = (key) => key === VARIANT_DISCRIMINANT
|
|
108
|
+
? { ...f, variants: undefined }
|
|
109
|
+
: Object.values(f.variants ?? {}).find((world) => world && key in world)?.[key];
|
|
110
|
+
for (const key of keysOf({ [VARIANT_DISCRIMINANT]: null }, cells, now))
|
|
111
|
+
value(pathAt, cell(key), [...steps, key], cells[key], now[key]);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (kind === 'matrix' && records) {
|
|
115
|
+
const next = now;
|
|
116
|
+
for (const member of keysOf({}, cells, next)) {
|
|
117
|
+
const a = cells[member];
|
|
118
|
+
const b = next[member];
|
|
119
|
+
if (sameValue(a, b))
|
|
120
|
+
continue;
|
|
121
|
+
if (isRecord(a) && isRecord(b))
|
|
122
|
+
for (const key of keysOf(f?.properties ?? {}, a, b))
|
|
123
|
+
value(pathAt, f?.properties?.[key], [...steps, member, key], a[key], b[key]);
|
|
124
|
+
else
|
|
125
|
+
items.push({
|
|
126
|
+
id: mint(),
|
|
127
|
+
field: pathAt([...steps, member]),
|
|
128
|
+
...(a !== undefined && { before: a }),
|
|
129
|
+
...(b !== undefined && { after: b })
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (kind !== 'array' || !Array.isArray(now) || !(was == null || Array.isArray(was)))
|
|
103
135
|
return whole();
|
|
104
|
-
|
|
136
|
+
const held = Array.isArray(was) ? was : [];
|
|
137
|
+
const runs = aligned(held, now) ?? [
|
|
138
|
+
{ from: 0, to: 0, removed: held.length, added: now.length }
|
|
139
|
+
];
|
|
140
|
+
let appended = held.length;
|
|
105
141
|
for (const { from, to, removed, added } of runs) {
|
|
106
142
|
const paired = Math.min(removed, added);
|
|
107
143
|
for (let k = 0; k < paired; k++)
|
|
108
|
-
value(pathAt, f?.items, [...steps, from + k],
|
|
144
|
+
value(pathAt, f?.items, [...steps, from + k], held[from + k], now[to + k]);
|
|
109
145
|
for (let k = paired; k < removed; k++)
|
|
110
146
|
items.push({
|
|
111
147
|
id: mint(),
|
|
112
148
|
field: pathAt([...steps, from + k]),
|
|
113
|
-
before:
|
|
149
|
+
before: held[from + k]
|
|
114
150
|
});
|
|
115
151
|
for (let k = paired; k < added; k++)
|
|
116
152
|
items.push({
|
|
@@ -121,31 +157,32 @@ export function proposalsBetween(quill, base, answer, mint = () => `review-${min
|
|
|
121
157
|
}
|
|
122
158
|
};
|
|
123
159
|
diffCard(quill.schema.main, undefined, base.main, answer.main, undefined);
|
|
160
|
+
/** The base's index of each card the answer keeps as it was, by its answer index. */
|
|
161
|
+
const kept = new Map();
|
|
162
|
+
const removed = [];
|
|
124
163
|
for (const [at, id] of baseIds.entries()) {
|
|
125
164
|
const answerAt = answerIds.indexOf(id);
|
|
126
165
|
const was = base.card(at);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
const now = answer.card(answerAt);
|
|
132
|
-
if (now.kind !== was.kind) {
|
|
133
|
-
cards.push({ type: 'remove', id, kind: was.kind });
|
|
166
|
+
const now = answerAt < 0 ? undefined : answer.card(answerAt);
|
|
167
|
+
if (!now || now.kind !== was.kind) {
|
|
168
|
+
removed.push(at);
|
|
134
169
|
continue;
|
|
135
170
|
}
|
|
171
|
+
kept.set(answerAt, at);
|
|
136
172
|
diffCard(quill.schema.card_kinds?.[was.kind], at, was, now, answerAt);
|
|
137
173
|
}
|
|
138
|
-
for (const
|
|
139
|
-
|
|
140
|
-
if (at0 >= 0 && base.card(at0).kind === answer.card(at).kind)
|
|
174
|
+
for (const at of answerIds.keys()) {
|
|
175
|
+
if (kept.has(at))
|
|
141
176
|
continue;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
177
|
+
let lead = at - 1;
|
|
178
|
+
while (lead >= 0 && !kept.has(lead))
|
|
179
|
+
lead--;
|
|
180
|
+
const after = kept.get(lead);
|
|
181
|
+
items.push({ id: mint(), add: answer.card(at), ...(after !== undefined && { after }) });
|
|
147
182
|
}
|
|
148
|
-
|
|
183
|
+
for (const at of removed)
|
|
184
|
+
items.push({ id: mint(), remove: at });
|
|
185
|
+
return { items };
|
|
149
186
|
}
|
|
150
187
|
const addrOf = (card, field) => ({
|
|
151
188
|
...(card !== undefined && { card }),
|
package/dist/visual/props.d.ts
CHANGED
|
@@ -110,19 +110,21 @@ export interface VisualEditorProps {
|
|
|
110
110
|
formatDiagnostic?: FormatDiagnostic;
|
|
111
111
|
/**
|
|
112
112
|
* What someone other than the reader proposes, for the editor to draw where each item sits
|
|
113
|
-
* ({@link ReviewItem}): a proposal as a word-level edit of its own blocks
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
113
|
+
* ({@link ReviewItem}): a proposal as a word-level edit of its own blocks, a field's proposed
|
|
114
|
+
* value under its control, a new card as a preview where it would stand, and a removal as a
|
|
115
|
+
* mark on its card. One change is current while any is open, and the answer card on it is
|
|
116
|
+
* where a change is answered. Declarative: the host sets the list once and clears it once,
|
|
117
|
+
* and the editor draws every answer while the list holds the item: an answered item is drawn
|
|
118
|
+
* no more, and an accepted one is plain text. A card an item names by index is read against
|
|
119
|
+
* the cards as they stood when the list was set, so the item stays on its card through
|
|
120
|
+
* `applyCardOps` and the reader's own card edits; an item whose card is gone draws nothing.
|
|
120
121
|
*/
|
|
121
122
|
review?: readonly ReviewItem[];
|
|
122
123
|
/**
|
|
123
|
-
* A reader answered an item:
|
|
124
|
-
*
|
|
125
|
-
* so the host leaves `review` as
|
|
124
|
+
* A reader answered an item: the answer card, `Mod-Enter` / `Mod-.` on the current change,
|
|
125
|
+
* or a host's `answerReview`; or undid an answer with ⌘Z, `reopen`. The editor has made every
|
|
126
|
+
* write an answer asks for, a card's included, and draws it, so the host leaves `review` as
|
|
127
|
+
* it set it.
|
|
126
128
|
*/
|
|
127
129
|
onReview?: (event: ReviewEvent) => void;
|
|
128
130
|
/**
|
|
@@ -132,15 +134,13 @@ export interface VisualEditorProps {
|
|
|
132
134
|
* host counts and steps its own list by.
|
|
133
135
|
*/
|
|
134
136
|
onReviewDrawn?: (drawn: ReviewDrawn) => void;
|
|
137
|
+
/** The room, in px, the host's chrome takes at the foot of the pane the editor scrolls in,
|
|
138
|
+
* which the answer card keeps clear of. Default `0`. */
|
|
139
|
+
reviewInset?: number;
|
|
135
140
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*/
|
|
140
|
-
reviewAdvance?: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* The item under attention, `undefined` once nothing is: the pointer over one, the caret
|
|
143
|
-
* in one, or one a `revealReview` named. What a host lights its own list by.
|
|
141
|
+
* The current change, `undefined` once none is open: the one the answer card and the review
|
|
142
|
+
* keys answer. A review starts on its first change, and every answer moves on to the next.
|
|
143
|
+
* What a host counts its place in the review by.
|
|
144
144
|
*/
|
|
145
145
|
onReviewFocus?: (id: string | undefined) => void;
|
|
146
146
|
/** Appended to the root's own class: the surface is a mounted element the
|
package/dist/visual/review.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PathStep } from '@quillmark/wasm';
|
|
2
|
-
import type { DocPath } from '../core/address.js';
|
|
1
|
+
import type { Card, Content, PathStep } from '@quillmark/wasm';
|
|
2
|
+
import type { DocPath, Landing } from '../core/address.js';
|
|
3
3
|
import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* One proposal. `id` is the host's, unique in the list, and is what every event names.
|
|
@@ -18,11 +18,32 @@ import { type BlockPlace, type ReviewAction } from '../core/codec/index.js';
|
|
|
18
18
|
* its writer read. A path to a place inside a record or a
|
|
19
19
|
* list names that place: a cell, or a member by its index, which `after` absent takes out
|
|
20
20
|
* and an index past the last appends.
|
|
21
|
+
* - `add` or `remove`: a whole card, proposed new or proposed taken out (`CardProposal`).
|
|
21
22
|
*
|
|
22
23
|
* An item whose place the editor does not hold draws nothing. An answered item is drawn no
|
|
23
24
|
* more: a dismissed one wrote nothing, and an accepted one is plain text in the document.
|
|
24
25
|
*/
|
|
25
|
-
export type ReviewItem = FieldProposal | BlockProposal;
|
|
26
|
+
export type ReviewItem = FieldProposal | BlockProposal | CardProposal;
|
|
27
|
+
/**
|
|
28
|
+
* A card proposed new or taken out, naming cards by their index into the composable cards as they
|
|
29
|
+
* stood when the list was set, as a path does.
|
|
30
|
+
*
|
|
31
|
+
* - `add`: the card, drawn as a preview where it would stand: after the card at `after`, at the
|
|
32
|
+
* head of the cards where `after` is absent, and last where that card is gone. Two proposals
|
|
33
|
+
* after one card stand in list order. Taken, it is written with its `$id` where no card holds
|
|
34
|
+
* that one.
|
|
35
|
+
* - `remove`: the card at that index, marked whole where it stands.
|
|
36
|
+
*/
|
|
37
|
+
export type CardProposal = {
|
|
38
|
+
id: string;
|
|
39
|
+
add: Card;
|
|
40
|
+
after?: number;
|
|
41
|
+
} | {
|
|
42
|
+
id: string;
|
|
43
|
+
remove: number;
|
|
44
|
+
};
|
|
45
|
+
/** Whether an item proposes a whole card. */
|
|
46
|
+
export declare const byCard: (item: object) => item is CardProposal;
|
|
26
47
|
/** A proposal over blocks of a rich text field, by their ids. */
|
|
27
48
|
export type BlockProposal = {
|
|
28
49
|
id: string;
|
|
@@ -77,6 +98,28 @@ export interface ReviewDrawn {
|
|
|
77
98
|
reason: ReviewUndrawn;
|
|
78
99
|
}[];
|
|
79
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Every open proposal written into a copy of the document, as the page would read with each one
|
|
103
|
+
* taken, and the way between places in the live document and places in the copy
|
|
104
|
+
* (`VisualEditor.projectReview`). A proposal that adds or takes out a card moves the index of
|
|
105
|
+
* every card after it, and one that adds or rewrites words moves the offsets after them, so a
|
|
106
|
+
* host bridging the editor to a preview of the copy routes each hop through this.
|
|
107
|
+
*/
|
|
108
|
+
export interface ReviewProjection {
|
|
109
|
+
/** The proposals written, every one the editor draws, in the page's order. */
|
|
110
|
+
readonly ids: readonly string[];
|
|
111
|
+
/** A place in the live document, as the copy holds it; `undefined` where a proposal takes
|
|
112
|
+
* its card out. */
|
|
113
|
+
toProjection<T extends DocPath | Landing>(at: T): T | undefined;
|
|
114
|
+
/** A place in the copy, as the live document holds it, or the proposal that adds it: a card
|
|
115
|
+
* or a block that only the copy holds. Inside words a proposal rewrites, the offset is the
|
|
116
|
+
* nearest the live text holds. `undefined` for a card the copy does not hold. */
|
|
117
|
+
toLive<T extends DocPath | Landing>(at: T): T | {
|
|
118
|
+
review: string;
|
|
119
|
+
} | undefined;
|
|
120
|
+
}
|
|
121
|
+
/** The projection of a review with nothing open: every place is where it is. */
|
|
122
|
+
export declare const NO_PROJECTION: ReviewProjection;
|
|
80
123
|
/** A proposal under a field's control. */
|
|
81
124
|
export type FieldProposal = {
|
|
82
125
|
id: string;
|
|
@@ -132,4 +175,26 @@ type Words = {
|
|
|
132
175
|
/** A proposal as runs, what it keeps, strikes and tints. Two lines of words differ by their words,
|
|
133
176
|
* two lists by their members, two records by their keys; any other pair differs whole. */
|
|
134
177
|
export declare function reviewRuns(before: unknown, after: unknown, words: Words): ReviewRun[];
|
|
178
|
+
/** A proposal a leaf of words draws over its own value: what it would write, and the value its
|
|
179
|
+
* writer read where it says, each as the leaf's content. */
|
|
180
|
+
export interface TextProposal {
|
|
181
|
+
id: string;
|
|
182
|
+
after: Content;
|
|
183
|
+
before?: Content;
|
|
184
|
+
}
|
|
185
|
+
/** A proposal over a leaf of words, `undefined` where its values are not words. A cleared value
|
|
186
|
+
* is drawn as what Accept leaves: `cleared`, the default that would print, else nothing. */
|
|
187
|
+
export declare function textProposal(item: FieldProposal | undefined, cleared?: Content): TextProposal | undefined;
|
|
188
|
+
/** A number's proposal, drawn over its input as the struck and the proposed figures; `undefined`
|
|
189
|
+
* for one that clears it, which the input shows as what Accept leaves. */
|
|
190
|
+
export declare function numberProposal(item: FieldProposal | undefined): {
|
|
191
|
+
id: string;
|
|
192
|
+
after: string;
|
|
193
|
+
} | undefined;
|
|
194
|
+
/** What a control that shows one value shows while `item` stands: the value Accept would write,
|
|
195
|
+
* nothing where it clears the control, which then draws its default or its empty face. */
|
|
196
|
+
export declare function shownValue(item: FieldProposal | undefined, stored: unknown): unknown;
|
|
197
|
+
/** Whether a value a reader commits is the one a proposal would write: a blank and an unset value
|
|
198
|
+
* are one, since a control cleared over a default commits `''`. */
|
|
199
|
+
export declare function writesProposed(value: unknown, after: unknown): boolean;
|
|
135
200
|
export {};
|
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) {
|
|
@@ -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
3
|
import type { ReviewAction, ReviewReport, ReviewVia, TextReview } from '../core/codec/index.js';
|
|
4
|
-
import { type
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { type ValueState } from '../core/codec/index.js';
|
|
5
|
+
import { type CardProposal, type DeepReview, type FieldProposal, type ReviewItem, type ReviewUndrawn } from './review.js';
|
|
6
|
+
/** How long the pointer rests on an item before it is current, in ms. */
|
|
7
|
+
export declare const DWELL_MS = 160;
|
|
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,12 @@ 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 item
|
|
37
|
+
/** The current item: open, drawn, and what the answer card and the review keys answer. */
|
|
23
38
|
readonly lit: string | undefined;
|
|
39
|
+
/** Where the open card items draw. */
|
|
40
|
+
readonly cards: CardsReviewed;
|
|
41
|
+
/** The card an accepted `add` wrote, by its session key, or none once it is taken back. */
|
|
42
|
+
wrote(id: string, key: string | undefined): void;
|
|
24
43
|
/** The items over the field at leaf `key`: its own, and those naming a place inside it,
|
|
25
44
|
* each with the steps to the value it names as the field holds it now. */
|
|
26
45
|
at(key: string): {
|
|
@@ -33,17 +52,32 @@ export interface Review {
|
|
|
33
52
|
keyOf(id: string): string | undefined;
|
|
34
53
|
/** A prose leaf's report of what it draws. */
|
|
35
54
|
drew(key: string, report: ReviewReport): void;
|
|
36
|
-
/** The item the pointer or the caret is in,
|
|
37
|
-
*
|
|
38
|
-
point(id: string | undefined, via: ReviewVia
|
|
39
|
-
/** A reader's answer
|
|
40
|
-
act(id: string, action: ReviewAction
|
|
55
|
+
/** The item the pointer or the caret is in, `undefined` where it left one: the caret
|
|
56
|
+
* arriving names it at once, the pointer once it has rested, and leaving names nothing. */
|
|
57
|
+
point(id: string | undefined, via: ReviewVia): void;
|
|
58
|
+
/** A reader's answer. False where it could not be made. */
|
|
59
|
+
act(id: string, action: ReviewAction): boolean;
|
|
60
|
+
/** A reader's commit of `value` on a control that shows one value, under the proposal `id`:
|
|
61
|
+
* the proposed value accepts it, any other is written and dismisses it, both one answer.
|
|
62
|
+
* False where it could not be made, and the commit is the caller's. */
|
|
63
|
+
answerWith(id: string, value: unknown): boolean;
|
|
64
|
+
/** A leaf of words drawing proposal `id` over what it holds: how it stands against it,
|
|
65
|
+
* `undefined` once it draws it no more. One the leaf already reads as is `applied`. */
|
|
66
|
+
planned(id: string, state: ValueState | undefined): void;
|
|
67
|
+
/** The value the place `item` names holds now, as its control is handed it. */
|
|
68
|
+
current(item: FieldProposal): unknown;
|
|
69
|
+
/** What Accept of `item` writes at a place holding `value`: a proposal of words a leaf draws
|
|
70
|
+
* carried onto what the reader wrote since its writer read it, else its `after`. */
|
|
71
|
+
writes(item: FieldProposal, value: unknown): unknown;
|
|
41
72
|
/** An answer leaf `key` has already given, the item listed or not: a reopen and a redo's
|
|
42
73
|
* accept arrive for items the host may have taken off or not yet put back. */
|
|
43
|
-
heard(id: string, action: ReviewAction, key: string
|
|
74
|
+
heard(id: string, action: ReviewAction, key: string): void;
|
|
44
75
|
/** A leaf is writing an answer, and is done: its edit is the answer's, not the reader's. */
|
|
45
76
|
writing(on: boolean): void;
|
|
77
|
+
/** Make `id` current at once: a step, a reveal, or a click or tap on it. */
|
|
46
78
|
reveal(id: string): void;
|
|
79
|
+
/** The pointer is over the answer card, which holds the current item where it is. */
|
|
80
|
+
hoverCard(on: boolean): void;
|
|
47
81
|
}
|
|
48
82
|
export interface ReviewSource {
|
|
49
83
|
items(): readonly ReviewItem[] | undefined;
|
|
@@ -64,11 +98,17 @@ export interface ReviewSource {
|
|
|
64
98
|
* one the editor does not hold. */
|
|
65
99
|
leafFor(path: DocPath): string | undefined;
|
|
66
100
|
/** 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
|
-
answer(id: string, item: ReviewItem | undefined, action: ReviewAction, key?: string
|
|
70
|
-
|
|
71
|
-
|
|
101
|
+
* leaf that gave it where one did, `write` the value a dismissal made by an edit writes.
|
|
102
|
+
* `false` where it could not be made, and the item stands. */
|
|
103
|
+
answer(id: string, item: ReviewItem | undefined, action: ReviewAction, key?: string, write?: {
|
|
104
|
+
value: unknown;
|
|
105
|
+
}): boolean;
|
|
106
|
+
/** The session keys of the cards as they stood when the list was set, by index. */
|
|
107
|
+
listedCards(): readonly string[];
|
|
108
|
+
/** The session keys of the cards as they stand. */
|
|
109
|
+
liveCards(): readonly string[];
|
|
110
|
+
/** An accept or a dismissal, once it is made, `current` where the item was the current one. */
|
|
111
|
+
answered?(id: string, current: boolean): void;
|
|
72
112
|
writing?(on: boolean): void;
|
|
73
113
|
}
|
|
74
114
|
export declare function createReview(source: ReviewSource): Review & {
|