@quillmark/svelte 0.39.0 → 0.40.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 +1 -1
- package/dist/core/codec/encode.d.ts +10 -0
- package/dist/core/codec/encode.js +101 -0
- package/dist/core/codec/field.js +38 -10
- package/dist/core/codec/index.d.ts +2 -1
- package/dist/core/codec/index.js +2 -1
- package/dist/core/codec/lists.d.ts +2 -2
- package/dist/core/codec/lists.js +32 -3
- package/dist/core/codec/shortcuts.d.ts +11 -6
- package/dist/core/codec/shortcuts.js +24 -10
- package/dist/core/codec/table-view.js +3 -3
- package/dist/core/codec/tasks.d.ts +2 -2
- package/dist/core/codec/tasks.js +3 -3
- package/dist/core/frame.d.ts +3 -0
- package/dist/core/frame.js +3 -2
- package/dist/visual/ArrayField.svelte +6 -4
- package/dist/visual/Card.svelte +1 -1
- package/dist/visual/ProseValue.svelte +11 -1
- package/dist/visual/ReviewCard.svelte +116 -32
- package/dist/visual/ReviewCard.svelte.d.ts +9 -0
- package/dist/visual/VisualEditorInner.svelte +241 -76
- package/dist/visual/hears.d.ts +14 -0
- package/dist/visual/hears.js +58 -0
- package/dist/visual/index.d.ts +2 -0
- package/dist/visual/index.js +1 -0
- package/dist/visual/proposals.js +1 -1
- package/dist/visual/review.svelte.d.ts +2 -0
- package/dist/visual/review.svelte.js +9 -2
- package/dist/visual/structure.d.ts +2 -2
- package/dist/visual/undo.svelte.js +6 -3
- package/package.json +2 -2
|
@@ -69,6 +69,8 @@
|
|
|
69
69
|
offsetToPM,
|
|
70
70
|
valueEqual,
|
|
71
71
|
valueDiffPlugin,
|
|
72
|
+
valueSpans,
|
|
73
|
+
reviewCaretPlugin,
|
|
72
74
|
type ValueProposal,
|
|
73
75
|
type LeafViews,
|
|
74
76
|
type TextCap
|
|
@@ -167,6 +169,13 @@
|
|
|
167
169
|
drawnProposals = (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }));
|
|
168
170
|
redraw?.();
|
|
169
171
|
});
|
|
172
|
+
/** The caret names a proposal it arrives at, as a field's own leaf's does (`review-caret.ts`). */
|
|
173
|
+
const reviewCaret = reviewCaretPlugin({
|
|
174
|
+
spans: (state) => valueSpans(state, drawnProposals),
|
|
175
|
+
entered: () => undefined,
|
|
176
|
+
litHere: () => drawnProposals.some((p) => p.lit),
|
|
177
|
+
point: (id) => reviewing.point(id)
|
|
178
|
+
});
|
|
170
179
|
/** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
|
|
171
180
|
* list is answered, which would leave its own Accept writing its value whole. */
|
|
172
181
|
let plannedIds: readonly string[] = [];
|
|
@@ -303,7 +312,8 @@
|
|
|
303
312
|
valueDiffPlugin(
|
|
304
313
|
() => drawnProposals,
|
|
305
314
|
(id, state) => reviewing.planned(id, state)
|
|
306
|
-
)
|
|
315
|
+
),
|
|
316
|
+
reviewCaret
|
|
307
317
|
]
|
|
308
318
|
})
|
|
309
319
|
});
|
|
@@ -9,16 +9,20 @@
|
|
|
9
9
|
It sits under the block the change flows in, so it covers no line of its paragraph, or beside
|
|
10
10
|
that block's last line where the line ends short of it, centred on a block of one line such as a
|
|
11
11
|
one-line field's, right-aligned to the column the
|
|
12
|
-
change stands in, and
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
change stands in, and never above it: a card that turns over the text as a scroll runs short
|
|
13
|
+
of room moves under the pointer about to answer. Its room under the change is what a step
|
|
14
|
+
scrolls for, and the host's chrome at the pane's foot (`inset`) is kept clear. The column is
|
|
15
|
+
the card's body or its form whole, so Accept stands at one edge from change to change and a
|
|
16
|
+
pointer answering a run of them does not hunt for it. A field or a property sharing its row
|
|
17
|
+
takes its own right edge instead, reaching past it only as far as the card is wide and never
|
|
18
|
+
past the column's: a card at the column's edge stands under the row's last field, which reads
|
|
19
|
+
as the change it answers whatever field the change is in. A field or a
|
|
20
|
+
property sharing its row with others takes the card beside its line only where the card
|
|
21
|
+
stands within its own slot, and under the row otherwise: beside the line of one that ends
|
|
22
|
+
short of the column's edge the card covers the value of the next. Over a change too tall for
|
|
23
|
+
the pane to show with its card it stays pinned at the foot while any of the change shows. A
|
|
24
|
+
change out of the pane keeps its card where it would stand beside it, so the card scrolls out
|
|
25
|
+
with the text and the pane's edge clips it as it clips the text.
|
|
22
26
|
A change is several elements (struck runs, tinted widgets, added blocks, a row
|
|
23
27
|
under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
|
|
24
28
|
redraws its decorations as it likes, and a box measured once parts from the text it stood on.
|
|
@@ -26,7 +30,9 @@
|
|
|
26
30
|
anywhere, a resize of the editor.
|
|
27
31
|
|
|
28
32
|
It never takes the focus. A press on it keeps the focus where it is, and the keyboard reaches
|
|
29
|
-
it only by `enter
|
|
33
|
+
it only by `enter`. There its keys are bare: Enter on a button, Backspace or Delete to dismiss,
|
|
34
|
+
the arrows up and down to step. The focus rides the card from change to change, and Escape or
|
|
35
|
+
the last answer hands it back.
|
|
30
36
|
-->
|
|
31
37
|
<script lang="ts">
|
|
32
38
|
import { tick } from 'svelte';
|
|
@@ -47,9 +53,13 @@
|
|
|
47
53
|
outdated: boolean;
|
|
48
54
|
/** Why, as the proposal's writer says it. */
|
|
49
55
|
note?: string;
|
|
56
|
+
/** The answer key whose press only brought the card, whose hint says to press it again. */
|
|
57
|
+
asked?: 'accept' | 'dismiss';
|
|
50
58
|
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
59
|
+
/** Go to the next change, or the previous. */
|
|
60
|
+
onStep(dir: 1 | -1): void;
|
|
51
61
|
}
|
|
52
|
-
let { id, root, inset, hidden, outdated, note, onAnswer }: Props = $props();
|
|
62
|
+
let { id, root, inset, hidden, outdated, note, asked, onAnswer, onStep }: Props = $props();
|
|
53
63
|
const noteId = $props.id();
|
|
54
64
|
|
|
55
65
|
const t = wording();
|
|
@@ -59,10 +69,18 @@
|
|
|
59
69
|
let left = $state(0);
|
|
60
70
|
/** Pinned at the pane's foot, where every scroll moves it, so it follows without a glide. */
|
|
61
71
|
let pinned = $state(false);
|
|
72
|
+
/** The whole card stands in the pane, clear of the host's chrome at its foot. */
|
|
73
|
+
let stands = false;
|
|
62
74
|
/** The change is drawn, so the card has somewhere to stand. */
|
|
63
75
|
let placed = $state(false);
|
|
76
|
+
/** The span, in viewport px, of the change's blocks and the card where it stands unpinned. */
|
|
77
|
+
let reach: { top: number; bottom: number } = { top: 0, bottom: 0 };
|
|
64
78
|
/** Where the focus was when the keyboard entered the card, to hand it back. */
|
|
65
79
|
let from: HTMLElement | undefined;
|
|
80
|
+
/** The keyboard is on the card, from `enter` until the reader takes the focus off it. The
|
|
81
|
+
* card is inert between two changes, which drops the focus to the body: that is no move of
|
|
82
|
+
* the reader's, and the focus is put back as the card shows again. */
|
|
83
|
+
let riding = $state(false);
|
|
66
84
|
|
|
67
85
|
const shown = $derived(placed && !hidden && id !== undefined);
|
|
68
86
|
|
|
@@ -117,28 +135,24 @@
|
|
|
117
135
|
const column = (els[0].closest(
|
|
118
136
|
'.qm-fields, .qm-card, .qm-review-card-add, .qm-review-card-remove'
|
|
119
137
|
) ?? root)!;
|
|
120
|
-
|
|
138
|
+
const edge = column.getBoundingClientRect().right;
|
|
139
|
+
const home = els[0].closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
|
|
140
|
+
const right =
|
|
141
|
+
home && home.right < edge ? Math.min(edge, Math.max(home.right, home.left + w)) : edge;
|
|
142
|
+
left = Math.max(view.left + gap, right - w);
|
|
121
143
|
const at = (root ?? el).getBoundingClientRect();
|
|
122
144
|
const last = blocks.find((b, i) => b !== els[i] && b.getBoundingClientRect().bottom === lower);
|
|
123
145
|
const tuck = last && lastLine(last, h);
|
|
124
146
|
const slot = last?.closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
|
|
125
147
|
const beside = tuck && tuck.right + gap <= left && (!slot || left + w <= slot.right + 1);
|
|
126
148
|
const below = beside ? tuck.top : lower + gap;
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
: above >= ceil
|
|
133
|
-
? above
|
|
134
|
-
: !shows
|
|
135
|
-
? upper > floor
|
|
136
|
-
? above
|
|
137
|
-
: below
|
|
138
|
-
: Math.max(ceil, Math.min(floor - h, below));
|
|
149
|
+
reach = { top: upper, bottom: Math.max(lower, below + h) };
|
|
150
|
+
const tall = lower - upper + gap + h > floor - ceil;
|
|
151
|
+
pinned = shows && tall && below + h > floor;
|
|
152
|
+
const y = pinned ? Math.max(ceil, floor - h) : below;
|
|
153
|
+
stands = shows && y >= ceil && y + h <= floor;
|
|
139
154
|
top = y - at.top + (root?.scrollTop ?? 0);
|
|
140
155
|
left = left - at.left + (root?.scrollLeft ?? 0);
|
|
141
|
-
pinned = shows && !fits;
|
|
142
156
|
placed = true;
|
|
143
157
|
}
|
|
144
158
|
|
|
@@ -221,11 +235,27 @@
|
|
|
221
235
|
attributeFilter: ['data-qm-review', 'class', 'open', 'hidden']
|
|
222
236
|
};
|
|
223
237
|
|
|
238
|
+
/** Whether the card stands whole in the pane where the change now is: an answer key answers
|
|
239
|
+
* only a change whose card the reader can see. A change with no box measures nothing, and
|
|
240
|
+
* counts as shown. */
|
|
241
|
+
export function standsInView(): boolean {
|
|
242
|
+
place();
|
|
243
|
+
return !placed || stands;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** What a reveal frames for the change: its blocks and the card under or beside them, as
|
|
247
|
+
* the card stands where nothing pins it. `undefined` while the change draws nothing. */
|
|
248
|
+
export function extent(): { top: number; bottom: number } | undefined {
|
|
249
|
+
place();
|
|
250
|
+
return placed ? reach : undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
224
253
|
/** Put the focus on Accept, handing it back to where it was on Escape or an answer. False
|
|
225
254
|
* with no card on show. */
|
|
226
255
|
export async function enter(): Promise<boolean> {
|
|
227
256
|
if (!shown || !el || !inView(el)) return false;
|
|
228
257
|
from = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
|
|
258
|
+
riding = true;
|
|
229
259
|
await tick();
|
|
230
260
|
el.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
|
|
231
261
|
return true;
|
|
@@ -234,21 +264,50 @@
|
|
|
234
264
|
function leave(): void {
|
|
235
265
|
const back = from;
|
|
236
266
|
from = undefined;
|
|
267
|
+
riding = false;
|
|
237
268
|
if (back?.isConnected) back.focus({ preventScroll: true });
|
|
238
269
|
}
|
|
239
270
|
|
|
240
271
|
function answer(action: 'accept' | 'dismiss'): void {
|
|
241
|
-
const held = !!el?.contains(document.activeElement);
|
|
242
272
|
onAnswer(action);
|
|
243
|
-
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
$effect(() => {
|
|
276
|
+
if (!riding) return;
|
|
277
|
+
if (id === undefined) leave();
|
|
278
|
+
else if (shown && document.activeElement === document.body)
|
|
279
|
+
el?.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
/** The reader took the focus off the card: to `to`, or by a press outside it. */
|
|
283
|
+
function tookOff(to: EventTarget | null): void {
|
|
284
|
+
if (to instanceof Node && el?.contains(to)) return;
|
|
285
|
+
riding = false;
|
|
286
|
+
from = undefined;
|
|
244
287
|
}
|
|
245
288
|
|
|
246
289
|
function onkeydown(e: KeyboardEvent): void {
|
|
290
|
+
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
247
291
|
if (e.key === 'Escape') {
|
|
248
292
|
e.preventDefault();
|
|
249
293
|
leave();
|
|
250
294
|
return;
|
|
251
295
|
}
|
|
296
|
+
if (e.key === 'Backspace' || e.key === 'Delete') {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
if (!e.repeat) answer('dismiss');
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
302
|
+
e.preventDefault();
|
|
303
|
+
onStep(e.key === 'ArrowUp' ? -1 : 1);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// A held Enter clicks its button on every repeat, and a held key answers once.
|
|
307
|
+
if (e.key === 'Enter' && e.repeat) {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
252
311
|
if (e.key !== 'Tab' && e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
253
312
|
const buttons = [...(el?.querySelectorAll<HTMLElement>('button') ?? [])];
|
|
254
313
|
const at = buttons.indexOf(document.activeElement as HTMLElement);
|
|
@@ -259,7 +318,11 @@
|
|
|
259
318
|
}
|
|
260
319
|
</script>
|
|
261
320
|
|
|
262
|
-
<svelte:window
|
|
321
|
+
<svelte:window
|
|
322
|
+
onscrollcapture={schedule}
|
|
323
|
+
onresize={schedule}
|
|
324
|
+
onpointerdowncapture={(e) => tookOff(e.target)}
|
|
325
|
+
/>
|
|
263
326
|
|
|
264
327
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
265
328
|
<!-- The press keeps the focus where it is: the answer is about the text, not a move off it. -->
|
|
@@ -279,7 +342,8 @@
|
|
|
279
342
|
onmousedown={(e) => e.preventDefault()}
|
|
280
343
|
{onkeydown}
|
|
281
344
|
onfocusout={(e) => {
|
|
282
|
-
if (
|
|
345
|
+
if (e.relatedTarget) tookOff(e.relatedTarget);
|
|
346
|
+
else if (!riding) from = undefined;
|
|
283
347
|
}}
|
|
284
348
|
>
|
|
285
349
|
{#if note}<p id={noteId} class="qm-review-card-reason" title={note}>{note}</p>{/if}
|
|
@@ -291,7 +355,9 @@
|
|
|
291
355
|
tabindex="-1"
|
|
292
356
|
aria-keyshortcuts={keyshortcut(REVIEW_KEYS.dismiss)}
|
|
293
357
|
onclick={() => answer('dismiss')}
|
|
294
|
-
>{t.strings.reviewDismiss}<kbd
|
|
358
|
+
>{t.strings.reviewDismiss}<kbd class={{ 'qm-review-card-asked': asked === 'dismiss' }}
|
|
359
|
+
>{keycap(REVIEW_KEYS.dismiss)}</kbd
|
|
360
|
+
></button
|
|
295
361
|
>
|
|
296
362
|
<button
|
|
297
363
|
type="button"
|
|
@@ -299,7 +365,9 @@
|
|
|
299
365
|
tabindex="-1"
|
|
300
366
|
aria-keyshortcuts={keyshortcut(REVIEW_KEYS.accept)}
|
|
301
367
|
onclick={() => answer('accept')}
|
|
302
|
-
>{t.strings.reviewAccept}<kbd
|
|
368
|
+
>{t.strings.reviewAccept}<kbd class={{ 'qm-review-card-asked': asked === 'accept' }}
|
|
369
|
+
>{keycap(REVIEW_KEYS.accept)}</kbd
|
|
370
|
+
></button
|
|
303
371
|
>
|
|
304
372
|
</div>
|
|
305
373
|
</div>
|
|
@@ -370,6 +438,22 @@
|
|
|
370
438
|
}
|
|
371
439
|
kbd {
|
|
372
440
|
font: inherit;
|
|
441
|
+
border-radius: var(--_qm-radius-inner);
|
|
442
|
+
}
|
|
443
|
+
/* The press that brought the card asks for another: its key's hint rings once. */
|
|
444
|
+
.qm-review-card-asked {
|
|
445
|
+
outline: var(--_qm-border-width) solid currentColor;
|
|
446
|
+
outline-offset: 2px;
|
|
447
|
+
}
|
|
448
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
449
|
+
.qm-review-card-asked {
|
|
450
|
+
animation: qm-review-card-ask var(--_qm-duration-slow) var(--_qm-ease-reverse) 2;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
@keyframes qm-review-card-ask {
|
|
454
|
+
50% {
|
|
455
|
+
outline-offset: 4px;
|
|
456
|
+
}
|
|
373
457
|
}
|
|
374
458
|
.qm-review-card-answers {
|
|
375
459
|
display: flex;
|
|
@@ -11,9 +11,18 @@ interface Props {
|
|
|
11
11
|
outdated: boolean;
|
|
12
12
|
/** Why, as the proposal's writer says it. */
|
|
13
13
|
note?: string;
|
|
14
|
+
/** The answer key whose press only brought the card, whose hint says to press it again. */
|
|
15
|
+
asked?: 'accept' | 'dismiss';
|
|
14
16
|
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
17
|
+
/** Go to the next change, or the previous. */
|
|
18
|
+
onStep(dir: 1 | -1): void;
|
|
15
19
|
}
|
|
16
20
|
declare const ReviewCard: import("svelte").Component<Props, {
|
|
21
|
+
standsInView: () => boolean;
|
|
22
|
+
extent: () => {
|
|
23
|
+
top: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
} | undefined;
|
|
17
26
|
enter: () => Promise<boolean>;
|
|
18
27
|
}, "">;
|
|
19
28
|
type ReviewCard = ReturnType<typeof ReviewCard>;
|