@quillmark/svelte 0.34.0 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/FieldHint.svelte +8 -15
- package/dist/visual/ProseField.svelte +0 -2
- package/dist/visual/ReviewProposal.svelte +7 -0
- 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
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);
|
|
@@ -1,29 +1,12 @@
|
|
|
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 DeepReview, type
|
|
5
|
-
/** How long
|
|
6
|
-
export declare const HOVER_MS = 350;
|
|
7
|
-
/** How long a card outlasts the pointer's leaving, in ms: the trip from the mark into the card. */
|
|
8
|
-
export declare const LEAVE_MS = 200;
|
|
9
|
-
/** How long a revealed item with no card stays lit, in ms. */
|
|
4
|
+
import { type DeepReview, type FieldProposal, type ReviewItem, type ReviewUndrawn } from './review.js';
|
|
5
|
+
/** How long a revealed item stays lit, in ms. */
|
|
10
6
|
export declare const REVEAL_MS = 2400;
|
|
11
|
-
/** The card on show: the accepted proposal it is up for, as its change, and what raised it. */
|
|
12
|
-
export interface ShownReview {
|
|
13
|
-
item: FieldChange | TextChange;
|
|
14
|
-
via: ReviewVia | 'reveal';
|
|
15
|
-
}
|
|
16
|
-
/** A proposal taken in a prose leaf, as the change it made, `before` the text it replaced. */
|
|
17
|
-
export type TextChange = {
|
|
18
|
-
id: string;
|
|
19
|
-
state: 'changed';
|
|
20
|
-
before?: string;
|
|
21
|
-
};
|
|
22
7
|
export interface Review {
|
|
23
8
|
/** The host's list, less what was answered here. */
|
|
24
9
|
readonly items: readonly ReviewItem[];
|
|
25
|
-
/** The proposals accepted and still listed, each as the change it made. */
|
|
26
|
-
readonly accepted: ReadonlyMap<string, FieldChange | TextChange>;
|
|
27
10
|
/** The items the prose leaf at `key` draws, those placed by blocks of its own field. One
|
|
28
11
|
* identity until the list changes. */
|
|
29
12
|
textAt(key: string): readonly TextReview[];
|
|
@@ -38,11 +21,9 @@ export interface Review {
|
|
|
38
21
|
readonly fieldOutdated: ReadonlySet<string>;
|
|
39
22
|
/** The item under attention. */
|
|
40
23
|
readonly lit: string | undefined;
|
|
41
|
-
readonly shown: ShownReview | undefined;
|
|
42
24
|
/** The items over the field at leaf `key`: its own, and those naming a place inside it,
|
|
43
25
|
* each with the steps to the value it names as the field holds it now. */
|
|
44
26
|
at(key: string): {
|
|
45
|
-
changed?: FieldChange;
|
|
46
27
|
proposed?: FieldProposal;
|
|
47
28
|
nested?: readonly DeepReview[];
|
|
48
29
|
};
|
|
@@ -62,10 +43,6 @@ export interface Review {
|
|
|
62
43
|
heard(id: string, action: ReviewAction, key: string, chord?: boolean): void;
|
|
63
44
|
/** A leaf is writing an answer, and is done: its edit is the answer's, not the reader's. */
|
|
64
45
|
writing(on: boolean): void;
|
|
65
|
-
/** Hold the card up while the pointer or the focus is in it, and let it go again. */
|
|
66
|
-
hold(): void;
|
|
67
|
-
release(): void;
|
|
68
|
-
dismiss(): void;
|
|
69
46
|
reveal(id: string): void;
|
|
70
47
|
}
|
|
71
48
|
export interface ReviewSource {
|
|
@@ -89,14 +66,10 @@ export interface ReviewSource {
|
|
|
89
66
|
/** A reader's answer, to make and to pass on: `item` where the list holds it, `key` the
|
|
90
67
|
* leaf that gave it where one did. `false` where it could not be made, and the item
|
|
91
68
|
* stands. */
|
|
92
|
-
answer(id: string, item: ReviewItem |
|
|
69
|
+
answer(id: string, item: ReviewItem | undefined, action: ReviewAction, key?: string): boolean;
|
|
93
70
|
/** An answer a chord gave, once it is made. */
|
|
94
71
|
chorded?(id: string): void;
|
|
95
72
|
writing?(on: boolean): void;
|
|
96
|
-
/** The field proposals accepted here, each as the change it made. */
|
|
97
|
-
taken?(): ReadonlyMap<string, FieldChange>;
|
|
98
|
-
/** Take back what accepting `id` wrote, so it is open again. */
|
|
99
|
-
putBack?(id: string): boolean;
|
|
100
73
|
}
|
|
101
74
|
export declare function createReview(source: ReviewSource): Review & {
|
|
102
75
|
dispose(): void;
|
|
@@ -2,28 +2,19 @@
|
|
|
2
2
|
// under attention.
|
|
3
3
|
//
|
|
4
4
|
// Attention has three sources and one answer. The pointer over an item, the caret in one and a
|
|
5
|
-
// host's reveal each name an item; the lit one is the
|
|
6
|
-
//
|
|
7
|
-
// accepted proposal: it rises at once for a reveal, and after a beat for the pointer and the caret,
|
|
8
|
-
// so neither raises one on its way across a paragraph, and it waits a beat on the pointer's
|
|
9
|
-
// leaving so the pointer can travel into it.
|
|
5
|
+
// host's reveal each name an item; the lit one is the revealed, else the caret's, else the
|
|
6
|
+
// pointer's.
|
|
10
7
|
//
|
|
11
|
-
//
|
|
8
|
+
// An answered item is drawn no more, from the answer and not from the host's next list: the
|
|
12
9
|
// reader's press shows at once however long the host takes to hand over a list without it.
|
|
13
10
|
import { getContext, setContext } from 'svelte';
|
|
14
11
|
import { SvelteMap } from 'svelte/reactivity';
|
|
15
|
-
import { byBlocks, locate,
|
|
16
|
-
/** How long
|
|
17
|
-
export const HOVER_MS = 350;
|
|
18
|
-
/** How long a card outlasts the pointer's leaving, in ms: the trip from the mark into the card. */
|
|
19
|
-
export const LEAVE_MS = 200;
|
|
20
|
-
/** How long a revealed item with no card stays lit, in ms. */
|
|
12
|
+
import { byBlocks, locate, onField, sameValue } from './review.js';
|
|
13
|
+
/** How long a revealed item stays lit, in ms. */
|
|
21
14
|
export const REVEAL_MS = 2400;
|
|
22
15
|
export function createReview(source) {
|
|
23
16
|
/** The ids answered, each until a list arrives without it. */
|
|
24
17
|
const answered = new Set();
|
|
25
|
-
/** The field proposals accepted here, drawn while the field still holds what was written. */
|
|
26
|
-
const took = new Set();
|
|
27
18
|
let answers = $state(0);
|
|
28
19
|
const items = $derived.by(() => {
|
|
29
20
|
const listed = source.items() ?? [];
|
|
@@ -33,30 +24,10 @@ export function createReview(source) {
|
|
|
33
24
|
for (const id of answered)
|
|
34
25
|
if (!ids.has(id))
|
|
35
26
|
answered.delete(id);
|
|
36
|
-
|
|
37
|
-
if (!ids.has(id))
|
|
38
|
-
took.delete(id);
|
|
39
|
-
const taken = source.taken?.();
|
|
40
|
-
const gone = (id) => answered.has(id) || (took.has(id) && !taken?.has(id));
|
|
41
|
-
return answered.size || took.size ? listed.filter((item) => !gone(item.id)) : listed;
|
|
27
|
+
return answered.size ? listed.filter((item) => !answered.has(item.id)) : listed;
|
|
42
28
|
});
|
|
43
29
|
const drawn = new SvelteMap();
|
|
44
|
-
|
|
45
|
-
const accepted = $derived.by(() => {
|
|
46
|
-
const out = new Map();
|
|
47
|
-
const listed = new Map((source.items() ?? []).map((item) => [item.id, item]));
|
|
48
|
-
for (const [id, change] of source.taken?.() ?? [])
|
|
49
|
-
if (listed.has(id))
|
|
50
|
-
out.set(id, change);
|
|
51
|
-
for (const report of drawn.values())
|
|
52
|
-
for (const { id, before } of report.accepted ?? []) {
|
|
53
|
-
const item = listed.get(id);
|
|
54
|
-
if (item && byBlocks(item))
|
|
55
|
-
out.set(id, { id, state: 'changed', before });
|
|
56
|
-
}
|
|
57
|
-
return out;
|
|
58
|
-
});
|
|
59
|
-
const byId = $derived(new Map(items.map((item) => [item.id, accepted.get(item.id) ?? item])));
|
|
30
|
+
const byId = $derived(new Map(items.map((item) => [item.id, item])));
|
|
60
31
|
/** The items each prose leaf draws, by leaf key. */
|
|
61
32
|
const text = $derived.by(() => {
|
|
62
33
|
const own = new Map();
|
|
@@ -79,13 +50,12 @@ export function createReview(source) {
|
|
|
79
50
|
/** The nested proposals whose `before` the field no longer holds. */
|
|
80
51
|
const moved = new Set();
|
|
81
52
|
const claims = new Map();
|
|
82
|
-
for (const
|
|
83
|
-
if (byBlocks(
|
|
84
|
-
if (source.leafFor(
|
|
85
|
-
undrawn.push({ id:
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
if (byBlocks(item)) {
|
|
55
|
+
if (source.leafFor(item.field) === undefined)
|
|
56
|
+
undrawn.push({ id: item.id, reason: 'field' });
|
|
86
57
|
continue;
|
|
87
58
|
}
|
|
88
|
-
const item = accepted.get(listed.id) ?? listed;
|
|
89
59
|
if (!onField(item))
|
|
90
60
|
continue;
|
|
91
61
|
if (!source.exact(item.field)) {
|
|
@@ -98,12 +68,11 @@ export function createReview(source) {
|
|
|
98
68
|
claims.set(deep.key, claimed);
|
|
99
69
|
const held = out.get(deep.key) ?? {};
|
|
100
70
|
const { steps, found } = locate(deep.value, deep.steps, item, claimed);
|
|
101
|
-
|
|
102
|
-
if (same) {
|
|
71
|
+
if ((held.nested ?? []).some((e) => sameValue(e.steps, steps))) {
|
|
103
72
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
104
73
|
continue;
|
|
105
74
|
}
|
|
106
|
-
if (!found
|
|
75
|
+
if (!found)
|
|
107
76
|
moved.add(item.id);
|
|
108
77
|
held.nested = [...(held.nested ?? []), { steps, item }];
|
|
109
78
|
out.set(deep.key, held);
|
|
@@ -115,14 +84,11 @@ export function createReview(source) {
|
|
|
115
84
|
continue;
|
|
116
85
|
}
|
|
117
86
|
const held = out.get(key) ?? {};
|
|
118
|
-
if (
|
|
87
|
+
if (held.proposed !== undefined) {
|
|
119
88
|
undrawn.push({ id: item.id, reason: 'taken' });
|
|
120
89
|
continue;
|
|
121
90
|
}
|
|
122
|
-
|
|
123
|
-
held.changed = item;
|
|
124
|
-
else
|
|
125
|
-
held.proposed = item;
|
|
91
|
+
held.proposed = item;
|
|
126
92
|
out.set(key, held);
|
|
127
93
|
}
|
|
128
94
|
return { fields: out, undrawn, moved };
|
|
@@ -142,36 +108,13 @@ export function createReview(source) {
|
|
|
142
108
|
let caret = $state();
|
|
143
109
|
let caretFrom;
|
|
144
110
|
let revealed = $state();
|
|
145
|
-
let card = $state();
|
|
146
|
-
let held = false;
|
|
147
|
-
let timer;
|
|
148
|
-
/** The caret's rest on a change, its own so the pointer's passing does not restart it. */
|
|
149
|
-
let rest;
|
|
150
111
|
let fade;
|
|
151
|
-
const
|
|
152
|
-
clearTimeout(timer);
|
|
153
|
-
timer = setTimeout(then, ms);
|
|
154
|
-
};
|
|
155
|
-
const changed = (id) => id !== undefined && !!byId.get(id) && isChange(byId.get(id));
|
|
156
|
-
const shown = $derived.by(() => {
|
|
157
|
-
const item = card && byId.get(card.id);
|
|
158
|
-
return item && isChange(item) && card ? { item, via: card.via } : undefined;
|
|
159
|
-
});
|
|
160
|
-
const lit = $derived([shown?.item.id, revealed, caret, pointer].find((id) => id !== undefined && byId.has(id)));
|
|
112
|
+
const lit = $derived([revealed, caret, pointer].find((id) => id !== undefined && byId.has(id)));
|
|
161
113
|
const answering = (id, action, chord) => {
|
|
162
|
-
if (action === 'reopen')
|
|
114
|
+
if (action === 'reopen')
|
|
163
115
|
answered.delete(id);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
else {
|
|
167
|
-
if (card?.id === id)
|
|
168
|
-
card = undefined;
|
|
169
|
-
// An accepted proposal stays, drawn as its change, while the list holds it.
|
|
170
|
-
if (action !== 'accept')
|
|
171
|
-
answered.add(id);
|
|
172
|
-
else if (byId.get(id) && onField(byId.get(id)))
|
|
173
|
-
took.add(id);
|
|
174
|
-
}
|
|
116
|
+
else
|
|
117
|
+
answered.add(id);
|
|
175
118
|
answers++;
|
|
176
119
|
if (chord)
|
|
177
120
|
source.chorded?.(id);
|
|
@@ -180,9 +123,6 @@ export function createReview(source) {
|
|
|
180
123
|
get items() {
|
|
181
124
|
return items;
|
|
182
125
|
},
|
|
183
|
-
get accepted() {
|
|
184
|
-
return accepted;
|
|
185
|
-
},
|
|
186
126
|
textAt: (key) => text.get(key) ?? NO_ITEMS,
|
|
187
127
|
get reports() {
|
|
188
128
|
return drawn;
|
|
@@ -196,9 +136,6 @@ export function createReview(source) {
|
|
|
196
136
|
get lit() {
|
|
197
137
|
return lit;
|
|
198
138
|
},
|
|
199
|
-
get shown() {
|
|
200
|
-
return shown;
|
|
201
|
-
},
|
|
202
139
|
at: (key) => fields.get(key) ?? {},
|
|
203
140
|
marks: (key) => fields.has(key) || !!drawn.get(key)?.ids.length,
|
|
204
141
|
keyOf(id) {
|
|
@@ -223,58 +160,18 @@ export function createReview(source) {
|
|
|
223
160
|
drawn.delete(key);
|
|
224
161
|
},
|
|
225
162
|
point(id, via, from) {
|
|
226
|
-
if (via === '
|
|
227
|
-
|
|
228
|
-
return;
|
|
229
|
-
caretFrom = from;
|
|
230
|
-
caret = id;
|
|
231
|
-
clearTimeout(rest);
|
|
232
|
-
if (changed(id)) {
|
|
233
|
-
// A card already up for the item is the caret's from here: it stays while
|
|
234
|
-
// the caret does. The caret's card takes the pointer's place.
|
|
235
|
-
const raise = () => {
|
|
236
|
-
clearTimeout(timer);
|
|
237
|
-
card = { id, via };
|
|
238
|
-
};
|
|
239
|
-
if (card?.id === id)
|
|
240
|
-
raise();
|
|
241
|
-
else
|
|
242
|
-
rest = setTimeout(() => {
|
|
243
|
-
if (caret === id)
|
|
244
|
-
raise();
|
|
245
|
-
}, HOVER_MS);
|
|
246
|
-
}
|
|
247
|
-
else if (card?.via === 'caret' || (id !== undefined && card))
|
|
248
|
-
card = undefined;
|
|
249
|
-
if (id !== undefined)
|
|
250
|
-
revealed = undefined;
|
|
163
|
+
if (via === 'pointer') {
|
|
164
|
+
pointer = id;
|
|
251
165
|
return;
|
|
252
166
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (card)
|
|
260
|
-
card = { id, via };
|
|
261
|
-
else
|
|
262
|
-
wait(HOVER_MS, () => {
|
|
263
|
-
if (pointer === id && (!card || card.via === 'pointer'))
|
|
264
|
-
card = { id, via };
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
else if (card?.via === 'pointer' && !held)
|
|
268
|
-
wait(LEAVE_MS, () => {
|
|
269
|
-
if (card?.via === 'pointer' && card.id !== pointer && !held)
|
|
270
|
-
card = undefined;
|
|
271
|
-
});
|
|
272
|
-
else
|
|
273
|
-
clearTimeout(timer);
|
|
167
|
+
if (id === undefined && from !== undefined && caretFrom !== from)
|
|
168
|
+
return;
|
|
169
|
+
caretFrom = from;
|
|
170
|
+
caret = id;
|
|
171
|
+
if (id !== undefined)
|
|
172
|
+
revealed = undefined;
|
|
274
173
|
},
|
|
275
174
|
act(id, action, chord) {
|
|
276
|
-
if (accepted.has(id) && action === 'reopen')
|
|
277
|
-
return source.putBack?.(id) ?? false;
|
|
278
175
|
const item = byId.get(id);
|
|
279
176
|
if (!item || !source.answer(id, item, action))
|
|
280
177
|
return false;
|
|
@@ -286,28 +183,8 @@ export function createReview(source) {
|
|
|
286
183
|
if (source.answer(id, byId.get(id), action, key))
|
|
287
184
|
answering(id, action, chord);
|
|
288
185
|
},
|
|
289
|
-
hold() {
|
|
290
|
-
held = true;
|
|
291
|
-
clearTimeout(timer);
|
|
292
|
-
},
|
|
293
|
-
release() {
|
|
294
|
-
held = false;
|
|
295
|
-
if (card?.via === 'pointer' && card.id !== pointer)
|
|
296
|
-
wait(LEAVE_MS, () => {
|
|
297
|
-
if (!held && card?.via === 'pointer' && card.id !== pointer)
|
|
298
|
-
card = undefined;
|
|
299
|
-
});
|
|
300
|
-
},
|
|
301
|
-
dismiss() {
|
|
302
|
-
clearTimeout(timer);
|
|
303
|
-
clearTimeout(rest);
|
|
304
|
-
card = undefined;
|
|
305
|
-
},
|
|
306
186
|
reveal(id) {
|
|
307
|
-
clearTimeout(timer);
|
|
308
|
-
clearTimeout(rest);
|
|
309
187
|
clearTimeout(fade);
|
|
310
|
-
card = changed(id) ? { id, via: 'reveal' } : undefined;
|
|
311
188
|
revealed = id;
|
|
312
189
|
fade = setTimeout(() => {
|
|
313
190
|
if (revealed === id)
|
|
@@ -315,8 +192,6 @@ export function createReview(source) {
|
|
|
315
192
|
}, REVEAL_MS);
|
|
316
193
|
},
|
|
317
194
|
dispose() {
|
|
318
|
-
clearTimeout(timer);
|
|
319
|
-
clearTimeout(rest);
|
|
320
195
|
clearTimeout(fade);
|
|
321
196
|
}
|
|
322
197
|
};
|
|
@@ -330,13 +205,11 @@ const NO_ITEMS = [];
|
|
|
330
205
|
/** What a component rendered outside the editor gets: nothing to draw. */
|
|
331
206
|
const NO_REVIEW = {
|
|
332
207
|
items: [],
|
|
333
|
-
accepted: new Map(),
|
|
334
208
|
textAt: () => NO_ITEMS,
|
|
335
209
|
reports: new Map(),
|
|
336
210
|
fieldUndrawn: [],
|
|
337
211
|
fieldOutdated: new Set(),
|
|
338
212
|
lit: undefined,
|
|
339
|
-
shown: undefined,
|
|
340
213
|
at: () => ({}),
|
|
341
214
|
marks: () => false,
|
|
342
215
|
keyOf: () => undefined,
|
|
@@ -345,9 +218,6 @@ const NO_REVIEW = {
|
|
|
345
218
|
act: () => false,
|
|
346
219
|
heard() { },
|
|
347
220
|
writing() { },
|
|
348
|
-
hold() { },
|
|
349
|
-
release() { },
|
|
350
|
-
dismiss() { },
|
|
351
221
|
reveal() { }
|
|
352
222
|
};
|
|
353
223
|
/** The editor's review state, or {@link NO_REVIEW} off-tree. */
|
package/dist/visual/strings.d.ts
CHANGED
|
@@ -26,23 +26,11 @@ export interface VisualStrings extends TableChromeStrings, SlashStrings, Shortcu
|
|
|
26
26
|
groupFlagged: string;
|
|
27
27
|
/** The same header where a field inside holds an item of review. */
|
|
28
28
|
groupReviewed: string;
|
|
29
|
-
/** The card's button, and the row's: takes the change back. */
|
|
30
|
-
reviewUndo: string;
|
|
31
|
-
/** Its tooltip, which names the chord. */
|
|
32
|
-
reviewUndoTitle: string;
|
|
33
|
-
/** The card's accessible name. */
|
|
34
|
-
reviewChange: string;
|
|
35
29
|
/** The toast over a field's proposal taken, beside its way back. */
|
|
36
30
|
reviewAccepted: string;
|
|
37
|
-
/**
|
|
38
|
-
reviewWas: string;
|
|
39
|
-
/** The whole of the card over text that replaced nothing. */
|
|
40
|
-
reviewAdded: string;
|
|
41
|
-
/** Before the text a change took out, or the whole of the card where the host kept none. */
|
|
42
|
-
reviewRemoved: string;
|
|
43
|
-
/** A value that was, or would be, nothing: `Was Empty`. */
|
|
31
|
+
/** A value that was, or would be, nothing. */
|
|
44
32
|
reviewEmpty: string;
|
|
45
|
-
/** A switch's two values, as a
|
|
33
|
+
/** A switch's two values, as a row words them. */
|
|
46
34
|
reviewOn: string;
|
|
47
35
|
reviewOff: string;
|
|
48
36
|
/** The toast's notice, named for what went: `Authors 2 removed`. */
|
package/dist/visual/strings.js
CHANGED
|
@@ -52,13 +52,7 @@ export const DEFAULT_VISUAL_STRINGS = {
|
|
|
52
52
|
...DEFAULT_REVIEW_STRINGS,
|
|
53
53
|
reviewAcceptTitle: `Accept (${chord('↵')})`,
|
|
54
54
|
reviewDismissTitle: `Dismiss (${chord('.')})`,
|
|
55
|
-
reviewUndo: 'Undo',
|
|
56
|
-
reviewUndoTitle: `Undo (${chord('.')})`,
|
|
57
|
-
reviewChange: 'Change',
|
|
58
55
|
reviewAccepted: 'Change accepted',
|
|
59
|
-
reviewWas: 'Was',
|
|
60
|
-
reviewAdded: 'Added',
|
|
61
|
-
reviewRemoved: 'Removed',
|
|
62
56
|
reviewEmpty: 'Empty',
|
|
63
57
|
reviewOn: 'On',
|
|
64
58
|
reviewOff: 'Off',
|
package/package.json
CHANGED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
The card over a change: what the words or the value replaced, and the one button that takes the
|
|
3
|
-
change back. One card, shell-owned, up for whichever `changed` item the review state shows
|
|
4
|
-
(`review.svelte.ts`), over a mark in a prose leaf or over a field's control.
|
|
5
|
-
|
|
6
|
-
Under its anchor, where the format popover rises over a selection: the two can be up at once,
|
|
7
|
-
and what the reader is reading is the line above.
|
|
8
|
-
|
|
9
|
-
Focus discipline is the format popover's: the card never takes the focus, so the caret that
|
|
10
|
-
raised it stays where it was, and its button swallows its own mousedown for the same reason.
|
|
11
|
-
The pointer's card ends on a scroll, the page having moved under a pointer that did not; the
|
|
12
|
-
caret's and a reveal's follow their mark, and hide while it is scrolled out of the pane.
|
|
13
|
-
-->
|
|
14
|
-
<script lang="ts" module>
|
|
15
|
-
import type { RangeAnchor } from '../core/codec/index.js';
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<script lang="ts">
|
|
19
|
-
import { Popover } from 'bits-ui';
|
|
20
|
-
import { spacePx } from '../core/rungs.js';
|
|
21
|
-
import { wording } from './strings.js';
|
|
22
|
-
import { reviewText } from './review.js';
|
|
23
|
-
import type { Review } from './review.svelte.js';
|
|
24
|
-
import './controls.css';
|
|
25
|
-
|
|
26
|
-
/** Where item `id` is drawn. */
|
|
27
|
-
export interface ReviewTarget {
|
|
28
|
-
/** What its card hangs off: a field's control, or a live measure of a mark in a leaf. */
|
|
29
|
-
anchor: Element | RangeAnchor;
|
|
30
|
-
/** The mark is the wedge that stands where text was only removed. */
|
|
31
|
-
removed: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface Props {
|
|
35
|
-
review: Review;
|
|
36
|
-
targetFor: (id: string) => ReviewTarget | undefined;
|
|
37
|
-
}
|
|
38
|
-
let { review, targetFor }: Props = $props();
|
|
39
|
-
|
|
40
|
-
const t = wording();
|
|
41
|
-
|
|
42
|
-
const shown = $derived(review.shown);
|
|
43
|
-
const target = $derived(shown ? targetFor(shown.item.id) : undefined);
|
|
44
|
-
const anchor = $derived(target?.anchor);
|
|
45
|
-
const open = $derived(!!shown && !!anchor);
|
|
46
|
-
const portalTarget = $derived.by(() => {
|
|
47
|
-
const el = anchor && 'contextElement' in anchor ? anchor.contextElement : anchor;
|
|
48
|
-
return el?.closest<HTMLElement>('[data-qm-root]') ?? undefined;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/** What the card says: a lead word, and the old words or value where there were any. */
|
|
52
|
-
const said = $derived.by(() => {
|
|
53
|
-
if (!shown) return undefined;
|
|
54
|
-
const { item } = shown;
|
|
55
|
-
const s = t.strings;
|
|
56
|
-
if ('field' in item) {
|
|
57
|
-
const was = reviewText(item.before, { on: s.reviewOn, off: s.reviewOff });
|
|
58
|
-
return { lead: s.reviewWas, text: was || s.reviewEmpty, empty: !was };
|
|
59
|
-
}
|
|
60
|
-
const before = item.before ?? '';
|
|
61
|
-
if (target?.removed) return { lead: s.reviewRemoved, text: before, empty: false };
|
|
62
|
-
return before
|
|
63
|
-
? { lead: s.reviewWas, text: before, empty: false }
|
|
64
|
-
: { lead: s.reviewAdded, text: '', empty: false };
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
function onScroll(): void {
|
|
68
|
-
if (review.shown?.via === 'pointer') review.dismiss();
|
|
69
|
-
}
|
|
70
|
-
</script>
|
|
71
|
-
|
|
72
|
-
<svelte:document onscrollcapture={onScroll} />
|
|
73
|
-
|
|
74
|
-
<Popover.Root
|
|
75
|
-
{open}
|
|
76
|
-
onOpenChange={(next) => {
|
|
77
|
-
if (!next) review.dismiss();
|
|
78
|
-
}}
|
|
79
|
-
>
|
|
80
|
-
<Popover.Portal to={portalTarget}>
|
|
81
|
-
<Popover.Content
|
|
82
|
-
customAnchor={anchor ?? null}
|
|
83
|
-
collisionBoundary={portalTarget ?? []}
|
|
84
|
-
side="bottom"
|
|
85
|
-
align="start"
|
|
86
|
-
trapFocus={false}
|
|
87
|
-
hideWhenDetached
|
|
88
|
-
sideOffset={spacePx(portalTarget, 1)}
|
|
89
|
-
onOpenAutoFocus={(e: Event) => e.preventDefault()}
|
|
90
|
-
onCloseAutoFocus={(e: Event) => e.preventDefault()}
|
|
91
|
-
onInteractOutside={(e: Event) => {
|
|
92
|
-
// A press on the mark the card is up for is not a press away from it.
|
|
93
|
-
const id = review.shown?.item.id;
|
|
94
|
-
const on = e.target instanceof Element ? e.target.closest('[data-qm-review]') : null;
|
|
95
|
-
if (id !== undefined && on?.getAttribute('data-qm-review') === id) e.preventDefault();
|
|
96
|
-
}}
|
|
97
|
-
>
|
|
98
|
-
{#snippet child({ props, wrapperProps, open: raised })}
|
|
99
|
-
<div {...wrapperProps}>
|
|
100
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
101
|
-
<!-- The handlers hold the card up while it is in use and add no interaction. -->
|
|
102
|
-
<div
|
|
103
|
-
{...props}
|
|
104
|
-
class="qm-review-card qm-popover-surface"
|
|
105
|
-
data-qm-root
|
|
106
|
-
role="group"
|
|
107
|
-
aria-label={t.strings.reviewChange}
|
|
108
|
-
inert={!raised}
|
|
109
|
-
onpointerenter={() => review.hold()}
|
|
110
|
-
onpointerleave={() => review.release()}
|
|
111
|
-
>
|
|
112
|
-
{#if said}
|
|
113
|
-
<span class="qm-review-said">
|
|
114
|
-
<span class="qm-review-lead">{said.lead}</span>
|
|
115
|
-
{#if said.text}
|
|
116
|
-
<span class={['qm-review-before', { 'qm-review-none': said.empty }]}
|
|
117
|
-
>{said.text}</span
|
|
118
|
-
>
|
|
119
|
-
{/if}
|
|
120
|
-
</span>
|
|
121
|
-
{/if}
|
|
122
|
-
<button
|
|
123
|
-
type="button"
|
|
124
|
-
class="qm-chip qm-review-undo qm-focus-ring"
|
|
125
|
-
title={t.strings.reviewUndoTitle}
|
|
126
|
-
onmousedown={(e) => e.preventDefault()}
|
|
127
|
-
onclick={() => shown && review.act(shown.item.id, 'reopen')}
|
|
128
|
-
>{t.strings.reviewUndo}</button
|
|
129
|
-
>
|
|
130
|
-
</div>
|
|
131
|
-
</div>
|
|
132
|
-
{/snippet}
|
|
133
|
-
</Popover.Content>
|
|
134
|
-
</Popover.Portal>
|
|
135
|
-
</Popover.Root>
|
|
136
|
-
|
|
137
|
-
<style>
|
|
138
|
-
/* The lift, the translucency and the scale-in are `.qm-popover-surface`'s (controls.css).
|
|
139
|
-
A row: what was, then the way back, the button holding its place at the top of a card
|
|
140
|
-
whose old words wrap. The measure caps a long passage at a few lines, which is a
|
|
141
|
-
reminder of what stood there rather than a second copy of the page. */
|
|
142
|
-
.qm-review-card {
|
|
143
|
-
display: flex;
|
|
144
|
-
align-items: flex-start;
|
|
145
|
-
gap: var(--_qm-space-3);
|
|
146
|
-
max-width: min(24rem, 90vw);
|
|
147
|
-
padding: var(--_qm-space) var(--_qm-space) var(--_qm-space) var(--_qm-space-3);
|
|
148
|
-
font-size: var(--_qm-text-label);
|
|
149
|
-
line-height: var(--_qm-leading-tight);
|
|
150
|
-
color: var(--_qm-ink);
|
|
151
|
-
}
|
|
152
|
-
.qm-review-said {
|
|
153
|
-
display: -webkit-box;
|
|
154
|
-
-webkit-box-orient: vertical;
|
|
155
|
-
-webkit-line-clamp: 4;
|
|
156
|
-
line-clamp: 4;
|
|
157
|
-
overflow: hidden;
|
|
158
|
-
min-width: 0;
|
|
159
|
-
/* The button's own height less this line's, halved: one line of words centres on it. */
|
|
160
|
-
padding-block: calc((var(--_qm-tap-min) - 1lh) / 2);
|
|
161
|
-
overflow-wrap: anywhere;
|
|
162
|
-
}
|
|
163
|
-
.qm-review-lead {
|
|
164
|
-
color: var(--_qm-ink-label);
|
|
165
|
-
}
|
|
166
|
-
.qm-review-before {
|
|
167
|
-
margin-inline-start: var(--_qm-space);
|
|
168
|
-
white-space: pre-wrap;
|
|
169
|
-
}
|
|
170
|
-
.qm-review-none {
|
|
171
|
-
color: var(--_qm-ink-label);
|
|
172
|
-
font-style: italic;
|
|
173
|
-
}
|
|
174
|
-
.qm-review-undo {
|
|
175
|
-
flex-shrink: 0;
|
|
176
|
-
font-weight: var(--_qm-weight-mid);
|
|
177
|
-
color: var(--_qm-ink);
|
|
178
|
-
}
|
|
179
|
-
</style>
|