@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
|
@@ -54,7 +54,16 @@
|
|
|
54
54
|
textCap
|
|
55
55
|
} from './structure.js';
|
|
56
56
|
import { splitDeep, unrouted, type DeepDiagnostic } from './diagnostics.js';
|
|
57
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
numberProposal,
|
|
59
|
+
shownValue,
|
|
60
|
+
splitReview,
|
|
61
|
+
textProposal,
|
|
62
|
+
type DeepReview,
|
|
63
|
+
type FieldProposal
|
|
64
|
+
} from './review.js';
|
|
65
|
+
import { review as reviewState } from './review.svelte.js';
|
|
66
|
+
import { asContent } from '../core/codec/index.js';
|
|
58
67
|
import ReviewRows from './ReviewRows.svelte';
|
|
59
68
|
import type { LandingBox } from './leaves.js';
|
|
60
69
|
import { isEmptyContent } from '../core/codec/index.js';
|
|
@@ -266,6 +275,13 @@
|
|
|
266
275
|
return !!el;
|
|
267
276
|
}
|
|
268
277
|
|
|
278
|
+
const reviewing = reviewState();
|
|
279
|
+
/** A commit on a cell that shows one value answers the proposal on it: the proposed value
|
|
280
|
+
* accepts it, any other dismisses it. */
|
|
281
|
+
function answerOrCommit(item: FieldProposal | undefined, key: string, v: unknown): void {
|
|
282
|
+
if (item && reviewing.answerWith(item.id, v)) return;
|
|
283
|
+
commitProp(key, v);
|
|
284
|
+
}
|
|
269
285
|
function commitProp(key: string, v: unknown): void {
|
|
270
286
|
if (v === undefined) {
|
|
271
287
|
// A nested control cleared (the unset rung): drop the key so the property
|
|
@@ -298,7 +314,17 @@
|
|
|
298
314
|
sub.description && idBase ? propertyDomIds(idBase, key).description : undefined}
|
|
299
315
|
{@const deep = routed.below.get(key)}
|
|
300
316
|
{@const reviewHere = reviewed.below.get(key)}
|
|
301
|
-
{@const handsDown = kind
|
|
317
|
+
{@const handsDown = isContainer(kind)}
|
|
318
|
+
{@const ownItem = handsDown ? undefined : reviewHere?.find((e) => !e.steps.length)?.item}
|
|
319
|
+
{@const textOwn =
|
|
320
|
+
kind === 'prose' && (shortCell(sub) || literalText(sub))
|
|
321
|
+
? textProposal(ownItem, contentDefault(sub))
|
|
322
|
+
: undefined}
|
|
323
|
+
{@const numberOwn = kind === 'number' ? numberProposal(ownItem) : undefined}
|
|
324
|
+
{@const worded = textOwn ?? numberOwn}
|
|
325
|
+
{@const shownItem = worded ? undefined : ownItem}
|
|
326
|
+
{@const shown = shownValue(shownItem, obj[key])}
|
|
327
|
+
{@const commitCell = (v: unknown) => answerOrCommit(shownItem, key, v)}
|
|
302
328
|
{@const own = isContainer(kind) ? undefined : deep?.map((d) => d.diagnostic)}
|
|
303
329
|
<!-- `for` reaches the labelable controls, a variant through its discriminant; the
|
|
304
330
|
date field's focus lives on a segment and a prose cell is a `contenteditable`,
|
|
@@ -350,19 +376,21 @@
|
|
|
350
376
|
label={named}
|
|
351
377
|
id={ids?.control}
|
|
352
378
|
describedBy={describes}
|
|
353
|
-
value={
|
|
379
|
+
value={shown as string | undefined}
|
|
354
380
|
values={sub.values ?? []}
|
|
355
381
|
fallback={sub.default as string | undefined}
|
|
356
382
|
blankTitle={sub.ui?.blank_title}
|
|
357
383
|
optional={optionalCell(sub)}
|
|
358
|
-
onCommit={
|
|
384
|
+
onCommit={commitCell}
|
|
385
|
+
proposing={!!shownItem}
|
|
359
386
|
/>
|
|
360
387
|
{:else if kind === 'number'}
|
|
361
388
|
<NumberField
|
|
362
389
|
label={named}
|
|
363
390
|
id={ids?.control}
|
|
364
391
|
describedBy={describes}
|
|
365
|
-
value={
|
|
392
|
+
value={shown as number | undefined}
|
|
393
|
+
proposed={numberOwn}
|
|
366
394
|
integer={baseType(sub) === 'integer'}
|
|
367
395
|
fallback={textDefault(sub)}
|
|
368
396
|
placeholder={noneOf(key, sub)}
|
|
@@ -373,27 +401,27 @@
|
|
|
373
401
|
label={named}
|
|
374
402
|
id={ids?.control}
|
|
375
403
|
describedBy={describes}
|
|
376
|
-
value={renderedBoolean(
|
|
404
|
+
value={renderedBoolean(shown)}
|
|
377
405
|
fallback={sub.default as boolean | undefined}
|
|
378
406
|
optional={optionalCell(sub)}
|
|
379
|
-
onCommit={
|
|
407
|
+
onCommit={commitCell}
|
|
380
408
|
/>
|
|
381
409
|
{:else if kind === 'date'}
|
|
382
410
|
<DateField
|
|
383
411
|
label={named}
|
|
384
412
|
labelledBy={ids?.label}
|
|
385
413
|
describedBy={describes}
|
|
386
|
-
value={
|
|
414
|
+
value={shown as string | undefined}
|
|
387
415
|
fallback={sub.default != null ? String(sub.default) : undefined}
|
|
388
416
|
datetime={baseType(sub) === 'datetime'}
|
|
389
|
-
onCommit={
|
|
417
|
+
onCommit={commitCell}
|
|
390
418
|
/>
|
|
391
419
|
{:else if kind === 'text'}
|
|
392
420
|
<TextField
|
|
393
421
|
label={named}
|
|
394
422
|
id={ids?.control}
|
|
395
423
|
describedBy={describes}
|
|
396
|
-
value={
|
|
424
|
+
value={shown as string | undefined}
|
|
397
425
|
fallback={textDefault(sub)}
|
|
398
426
|
placeholder={noneOf(key, sub)}
|
|
399
427
|
onCommit={(v) => commitProp(key, v)}
|
|
@@ -404,19 +432,25 @@
|
|
|
404
432
|
leaves the leaf mounted and the caret in it. -->
|
|
405
433
|
<ProseValue
|
|
406
434
|
bind:this={proseEls[key]}
|
|
407
|
-
content={() =>
|
|
408
|
-
|
|
435
|
+
content={() =>
|
|
436
|
+
shownItem
|
|
437
|
+
? shownItem.after === undefined
|
|
438
|
+
? undefined
|
|
439
|
+
: asContent(shownItem.after)
|
|
440
|
+
: contentAt([key])}
|
|
441
|
+
value={shown}
|
|
409
442
|
fallback={contentDefault(sub)}
|
|
410
443
|
plaintext={literalText(sub)}
|
|
411
|
-
placeholder={noneOf(key, sub)}
|
|
444
|
+
placeholder={ownItem ? undefined : noneOf(key, sub)}
|
|
412
445
|
{block}
|
|
413
446
|
label={named}
|
|
414
447
|
labelledBy={ids?.label}
|
|
415
448
|
describedBy={countId ? [describes, countId].filter(Boolean).join(' ') : describes}
|
|
416
449
|
cap={cap && { ...cap, onCount: (n) => (counts[key] = n) }}
|
|
417
450
|
onChange={(rt) =>
|
|
418
|
-
|
|
451
|
+
commitCell(optionalCell(sub) && isEmptyContent(rt) ? undefined : rt)}
|
|
419
452
|
onKey={onCellKey ? (e) => onCellKey(e, key) : undefined}
|
|
453
|
+
proposed={textOwn}
|
|
420
454
|
/>
|
|
421
455
|
{:else if kind === 'array'}
|
|
422
456
|
<!-- The repeater owns its label row, the add chip sharing it (`Field` skips
|
|
@@ -468,6 +502,7 @@
|
|
|
468
502
|
contentAt={(path) => contentAt([key, ...path])}
|
|
469
503
|
onCommit={(v) => commitProp(key, v)}
|
|
470
504
|
diagnostics={deep}
|
|
505
|
+
review={reviewHere}
|
|
471
506
|
/>
|
|
472
507
|
{:else if kind === 'variant'}
|
|
473
508
|
<VariantField
|
|
@@ -482,6 +517,7 @@
|
|
|
482
517
|
contentAt={(path) => contentAt([key, ...path])}
|
|
483
518
|
onCommit={(v) => commitProp(key, v)}
|
|
484
519
|
diagnostics={deep}
|
|
520
|
+
review={reviewHere}
|
|
485
521
|
/>
|
|
486
522
|
{:else}
|
|
487
523
|
<TextField
|
|
@@ -494,14 +530,16 @@
|
|
|
494
530
|
{/if}
|
|
495
531
|
<DiagnosticList diagnostics={own} />
|
|
496
532
|
{#if !handsDown}
|
|
497
|
-
<ReviewRows
|
|
533
|
+
<ReviewRows
|
|
534
|
+
entries={worded ? reviewHere?.filter((e) => e.item !== ownItem) : reviewHere}
|
|
535
|
+
/>
|
|
498
536
|
{/if}
|
|
499
537
|
</div>
|
|
500
538
|
</div>
|
|
501
539
|
{/each}
|
|
502
540
|
</div>
|
|
503
541
|
<DiagnosticList diagnostics={foot} />
|
|
504
|
-
<ReviewRows entries={reviewFoot}
|
|
542
|
+
<ReviewRows entries={reviewFoot} />
|
|
505
543
|
</div>
|
|
506
544
|
|
|
507
545
|
<style>
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import SlashMenu from './SlashMenu.svelte';
|
|
17
17
|
import { wording } from './strings.js';
|
|
18
18
|
import { review } from './review.svelte.js';
|
|
19
|
+
import type { TextProposal } from './review.js';
|
|
19
20
|
import './controls.css';
|
|
20
21
|
import type { Document, Quill, Addr, Content, Diagnostic } from '@quillmark/wasm';
|
|
21
22
|
import type { EditorErrorHandler } from '../core/errors.js';
|
|
@@ -61,6 +62,8 @@
|
|
|
61
62
|
cap?: TextCap;
|
|
62
63
|
/** Registry identity, stamped on the DOM node so a remount is visible as one. */
|
|
63
64
|
leafKey: string;
|
|
65
|
+
/** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
|
|
66
|
+
proposed?: TextProposal;
|
|
64
67
|
onFocus?: (addr: Addr) => void;
|
|
65
68
|
onCaretMove?: (addr: Addr, pos: number) => void;
|
|
66
69
|
/** A commit landed on this leaf: the prose change lane. */
|
|
@@ -91,6 +94,7 @@
|
|
|
91
94
|
emptyUnsets,
|
|
92
95
|
cap,
|
|
93
96
|
leafKey,
|
|
97
|
+
proposed,
|
|
94
98
|
onFocus,
|
|
95
99
|
onCaretMove,
|
|
96
100
|
onChange,
|
|
@@ -152,11 +156,11 @@
|
|
|
152
156
|
onSlash: (next) => {
|
|
153
157
|
slash = next;
|
|
154
158
|
},
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
onReviewPoint: (id, via) => reviewing.point(id, via, leafKey),
|
|
159
|
+
onReview: (id, action) => reviewing.heard(id, action, leafKey),
|
|
160
|
+
onReviewPoint: (id, via) => reviewing.point(id, via),
|
|
158
161
|
onReviewWriting: (on) => reviewing.writing(on),
|
|
159
162
|
onReviewDrawn: (report) => reviewing.drew(leafKey, report),
|
|
163
|
+
onValuePlanned: (id, state) => reviewing.planned(id, state),
|
|
160
164
|
onFocus,
|
|
161
165
|
onCaretMove,
|
|
162
166
|
onChange,
|
|
@@ -189,6 +193,15 @@
|
|
|
189
193
|
$effect(() => {
|
|
190
194
|
controller?.setReview(reviewing.textAt(leafKey), reviewing.lit);
|
|
191
195
|
});
|
|
196
|
+
$effect(() => {
|
|
197
|
+
controller?.setValueProposal(proposed && { ...proposed, lit: reviewing.lit === proposed.id });
|
|
198
|
+
});
|
|
199
|
+
$effect(() => {
|
|
200
|
+
const id = proposed?.id;
|
|
201
|
+
return () => {
|
|
202
|
+
if (id !== undefined) reviewing.planned(id, undefined);
|
|
203
|
+
};
|
|
204
|
+
});
|
|
192
205
|
|
|
193
206
|
// Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
|
|
194
207
|
$effect(() => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type TextCap } from '../core/codec/index.js';
|
|
2
2
|
import type { LeafRegistry } from './leaves.js';
|
|
3
|
+
import type { TextProposal } from './review.js';
|
|
3
4
|
import type { Document, Quill, Addr, Content, Diagnostic } from '@quillmark/wasm';
|
|
4
5
|
import type { EditorErrorHandler } from '../core/errors.js';
|
|
5
6
|
interface Props {
|
|
@@ -43,6 +44,8 @@ interface Props {
|
|
|
43
44
|
cap?: TextCap;
|
|
44
45
|
/** Registry identity, stamped on the DOM node so a remount is visible as one. */
|
|
45
46
|
leafKey: string;
|
|
47
|
+
/** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
|
|
48
|
+
proposed?: TextProposal;
|
|
46
49
|
onFocus?: (addr: Addr) => void;
|
|
47
50
|
onCaretMove?: (addr: Addr, pos: number) => void;
|
|
48
51
|
/** A commit landed on this leaf: the prose change lane. */
|
|
@@ -66,10 +66,14 @@
|
|
|
66
66
|
pmToOffset,
|
|
67
67
|
offsetToPM,
|
|
68
68
|
valueEqual,
|
|
69
|
+
valueDiffPlugin,
|
|
70
|
+
type ValueProposal,
|
|
69
71
|
type LeafViews,
|
|
70
72
|
type TextCap
|
|
71
73
|
} from '../core/codec/index.js';
|
|
72
74
|
import { valueLeafSeat } from './leaves.js';
|
|
75
|
+
import { review } from './review.svelte.js';
|
|
76
|
+
import type { TextProposal } from './review.js';
|
|
73
77
|
import { wording } from './strings.js';
|
|
74
78
|
import './controls.css';
|
|
75
79
|
import type { Content } from '@quillmark/wasm';
|
|
@@ -128,6 +132,8 @@
|
|
|
128
132
|
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
129
133
|
* keymap, so the state it reads is the one this keystroke has yet to change. */
|
|
130
134
|
onKey?: (e: KeyboardEvent) => void;
|
|
135
|
+
/** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
|
|
136
|
+
proposed?: TextProposal;
|
|
131
137
|
}
|
|
132
138
|
let {
|
|
133
139
|
content,
|
|
@@ -142,9 +148,28 @@
|
|
|
142
148
|
cap,
|
|
143
149
|
onChange,
|
|
144
150
|
lines,
|
|
145
|
-
onKey
|
|
151
|
+
onKey,
|
|
152
|
+
proposed
|
|
146
153
|
}: Props = $props();
|
|
147
154
|
|
|
155
|
+
const reviewing = review();
|
|
156
|
+
/** The proposal the value-diff plugin reads, and the view it redraws. */
|
|
157
|
+
let drawnProposal: ValueProposal | undefined;
|
|
158
|
+
let redraw: (() => void) | undefined;
|
|
159
|
+
$effect(() => {
|
|
160
|
+
drawnProposal =
|
|
161
|
+
proposed && (!block || plaintext)
|
|
162
|
+
? { ...proposed, lit: reviewing.lit === proposed.id }
|
|
163
|
+
: undefined;
|
|
164
|
+
redraw?.();
|
|
165
|
+
});
|
|
166
|
+
$effect(() => {
|
|
167
|
+
const id = proposed?.id;
|
|
168
|
+
return () => {
|
|
169
|
+
if (id !== undefined) reviewing.planned(id, undefined);
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
|
|
148
173
|
const t = wording();
|
|
149
174
|
const seat = valueLeafSeat();
|
|
150
175
|
const uid = $props.id();
|
|
@@ -263,7 +288,16 @@
|
|
|
263
288
|
inline,
|
|
264
289
|
placeholder: () => drawn.placeholder,
|
|
265
290
|
leaveStrings: () => t.strings,
|
|
266
|
-
cap
|
|
291
|
+
cap,
|
|
292
|
+
afterHistory:
|
|
293
|
+
inline || plaintext
|
|
294
|
+
? [
|
|
295
|
+
valueDiffPlugin(
|
|
296
|
+
() => drawnProposal,
|
|
297
|
+
(id, state) => reviewing.planned(id, state)
|
|
298
|
+
)
|
|
299
|
+
]
|
|
300
|
+
: []
|
|
267
301
|
})
|
|
268
302
|
});
|
|
269
303
|
};
|
|
@@ -360,6 +394,7 @@
|
|
|
360
394
|
}
|
|
361
395
|
}
|
|
362
396
|
);
|
|
397
|
+
redraw = () => mounted.setProps({});
|
|
363
398
|
const views: LeafViews = {
|
|
364
399
|
view: mounted,
|
|
365
400
|
focusedView: () => mounted,
|
|
@@ -392,6 +427,7 @@
|
|
|
392
427
|
seat?.release(views);
|
|
393
428
|
follow = undefined;
|
|
394
429
|
view = undefined;
|
|
430
|
+
redraw = undefined;
|
|
395
431
|
mounted.destroy();
|
|
396
432
|
};
|
|
397
433
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TextCap } from '../core/codec/index.js';
|
|
2
|
+
import type { TextProposal } from './review.js';
|
|
2
3
|
import type { Content } from '@quillmark/wasm';
|
|
3
4
|
interface Props {
|
|
4
5
|
/** This leaf's content (the parent's boundary read), `undefined` where nothing is
|
|
@@ -54,6 +55,8 @@ interface Props {
|
|
|
54
55
|
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
55
56
|
* keymap, so the state it reads is the one this keystroke has yet to change. */
|
|
56
57
|
onKey?: (e: KeyboardEvent) => void;
|
|
58
|
+
/** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
|
|
59
|
+
proposed?: TextProposal;
|
|
57
60
|
}
|
|
58
61
|
declare const ProseValue: import("svelte").Component<Props, {
|
|
59
62
|
focus: () => void;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The answer card: one floating surface on the current change of a review, and the one place a
|
|
3
|
+
change is answered by pointer. A quiet Dismiss and a primary Accept, each with its key, and a
|
|
4
|
+
note where the reader's own writing meets the change. The change itself is drawn where it
|
|
5
|
+
stands, so the card is the same two answers on every change. It carries no position: the count
|
|
6
|
+
is the host's bar's.
|
|
7
|
+
|
|
8
|
+
It sits under the change, right-aligned to the text column the change stands in, and flips
|
|
9
|
+
above it where there is no room below, keeping clear of the host's chrome at the pane's foot
|
|
10
|
+
(`inset`). Over a change taller than the pane it stays pinned at the foot while any of the
|
|
11
|
+
change shows. A change out of the pane keeps its card where it would stand beside it, so the
|
|
12
|
+
card scrolls out with the text and the pane's edge clips it as it clips the text.
|
|
13
|
+
A change is several elements (struck runs, tinted widgets, added blocks, a row
|
|
14
|
+
under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
|
|
15
|
+
redraws its decorations as it likes, and a box measured once parts from the text it stood on.
|
|
16
|
+
What it watches is the card holding the change, not the editor: a mutation there, a scroll
|
|
17
|
+
anywhere, a resize of the editor.
|
|
18
|
+
|
|
19
|
+
It never takes the focus. A press on it keeps the focus where it is, and the keyboard reaches
|
|
20
|
+
it only by `enter`, from which Escape and every answer hand the focus back.
|
|
21
|
+
-->
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { tick } from 'svelte';
|
|
24
|
+
import { chord, wording } from './strings.js';
|
|
25
|
+
import './controls.css';
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
/** The current change, `undefined` for no card. */
|
|
29
|
+
id: string | undefined;
|
|
30
|
+
/** The editor's root, which every element of the change is under. */
|
|
31
|
+
root: HTMLElement | undefined;
|
|
32
|
+
/** The room, in px, the host's chrome takes at the pane's foot. */
|
|
33
|
+
inset: number;
|
|
34
|
+
/** Held out of the way: the reader is typing. */
|
|
35
|
+
hidden: boolean;
|
|
36
|
+
/** The reader's own writing meets the change. */
|
|
37
|
+
outdated: boolean;
|
|
38
|
+
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
39
|
+
onHover(on: boolean): void;
|
|
40
|
+
}
|
|
41
|
+
let { id, root, inset, hidden, outdated, onAnswer, onHover }: Props = $props();
|
|
42
|
+
|
|
43
|
+
const t = wording();
|
|
44
|
+
|
|
45
|
+
let el = $state<HTMLElement | undefined>();
|
|
46
|
+
let top = $state(0);
|
|
47
|
+
let left = $state(0);
|
|
48
|
+
/** Pinned at the pane's foot, where every scroll moves it, so it follows without a glide. */
|
|
49
|
+
let pinned = $state(false);
|
|
50
|
+
/** The change is drawn, so the card has somewhere to stand. */
|
|
51
|
+
let placed = $state(false);
|
|
52
|
+
/** Where the focus was when the keyboard entered the card, to hand it back. */
|
|
53
|
+
let from: HTMLElement | undefined;
|
|
54
|
+
|
|
55
|
+
const shown = $derived(placed && !hidden && id !== undefined);
|
|
56
|
+
|
|
57
|
+
/** The elements the change draws. */
|
|
58
|
+
const parts = (): HTMLElement[] =>
|
|
59
|
+
id === undefined || !root
|
|
60
|
+
? []
|
|
61
|
+
: [...root.querySelectorAll<HTMLElement>(`[data-qm-review~="${CSS.escape(id)}"]`)];
|
|
62
|
+
|
|
63
|
+
/** The box the pane shows the editor through: its nearest scroller's, within the window. */
|
|
64
|
+
function band(): { top: number; bottom: number; left: number; right: number } {
|
|
65
|
+
let box = { top: 0, bottom: window.innerHeight, left: 0, right: window.innerWidth };
|
|
66
|
+
for (let at = root ?? null; at; at = at.parentElement) {
|
|
67
|
+
const { overflowY } = getComputedStyle(at);
|
|
68
|
+
if (overflowY !== 'auto' && overflowY !== 'scroll') continue;
|
|
69
|
+
const r = at.getBoundingClientRect();
|
|
70
|
+
box = {
|
|
71
|
+
top: Math.max(r.top, 0),
|
|
72
|
+
bottom: Math.min(r.bottom, window.innerHeight),
|
|
73
|
+
left: Math.max(r.left, 0),
|
|
74
|
+
right: Math.min(r.right, window.innerWidth)
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
return box;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Whether any of `at` shows in the pane, clear of the host's chrome at its foot. */
|
|
82
|
+
function inView(at: HTMLElement): boolean {
|
|
83
|
+
const r = at.getBoundingClientRect();
|
|
84
|
+
const view = band();
|
|
85
|
+
return r.bottom > view.top && r.top < view.bottom - inset;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function place(): void {
|
|
89
|
+
const els = parts();
|
|
90
|
+
const rects = els.map((e) => e.getBoundingClientRect()).filter((r) => r.width || r.height);
|
|
91
|
+
if (!el || !rects.length) {
|
|
92
|
+
placed = false;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const gap = gapPx();
|
|
96
|
+
const view = band();
|
|
97
|
+
const ceil = view.top + gap;
|
|
98
|
+
const floor = view.bottom - inset - gap;
|
|
99
|
+
const upper = Math.min(...rects.map((r) => r.top));
|
|
100
|
+
const lower = Math.max(...rects.map((r) => r.bottom));
|
|
101
|
+
const shows = lower >= ceil && upper <= floor;
|
|
102
|
+
const h = el.offsetHeight;
|
|
103
|
+
const w = el.offsetWidth;
|
|
104
|
+
const column = (els[0].closest(
|
|
105
|
+
'.qm-field, .qm-card, .qm-review-card-add, .qm-review-card-remove'
|
|
106
|
+
) ?? root)!;
|
|
107
|
+
left = Math.max(view.left + gap, column.getBoundingClientRect().right - w);
|
|
108
|
+
const at = (root ?? el).getBoundingClientRect();
|
|
109
|
+
const below = lower + gap;
|
|
110
|
+
const above = upper - gap - h;
|
|
111
|
+
const fits = below + h <= floor || above >= ceil;
|
|
112
|
+
const y =
|
|
113
|
+
below + h <= floor
|
|
114
|
+
? below
|
|
115
|
+
: above >= ceil
|
|
116
|
+
? above
|
|
117
|
+
: !shows
|
|
118
|
+
? upper > floor
|
|
119
|
+
? above
|
|
120
|
+
: below
|
|
121
|
+
: Math.max(ceil, Math.min(floor - h, below));
|
|
122
|
+
top = y - at.top + (root?.scrollTop ?? 0);
|
|
123
|
+
left = left - at.left + (root?.scrollLeft ?? 0);
|
|
124
|
+
pinned = shows && !fits;
|
|
125
|
+
placed = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function gapPx(): number {
|
|
129
|
+
const n = Number.parseFloat(getComputedStyle(el ?? root!).getPropertyValue('--_qm-space'));
|
|
130
|
+
return Number.isFinite(n) ? n : 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let frame = 0;
|
|
134
|
+
function schedule(): void {
|
|
135
|
+
if (frame) return;
|
|
136
|
+
frame = requestAnimationFrame(() => {
|
|
137
|
+
frame = 0;
|
|
138
|
+
place();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// What moves the change: its own card's subtree, and the editor's size. Until the change has
|
|
143
|
+
// drawn, the editor as a whole, which an advance to a change not yet redrawn needs.
|
|
144
|
+
$effect(() => {
|
|
145
|
+
void id;
|
|
146
|
+
void inset;
|
|
147
|
+
void hidden;
|
|
148
|
+
if (!root || id === undefined) {
|
|
149
|
+
placed = false;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
schedule();
|
|
153
|
+
const home = (): Element =>
|
|
154
|
+
parts()[0]?.closest('.qm-card-slot, .qm-primary, .qm-review-head') ?? root!;
|
|
155
|
+
let watched = home();
|
|
156
|
+
const mutations = new MutationObserver(() => {
|
|
157
|
+
const now = home();
|
|
158
|
+
if (now !== watched) {
|
|
159
|
+
mutations.disconnect();
|
|
160
|
+
watched = now;
|
|
161
|
+
mutations.observe(watched, WATCH);
|
|
162
|
+
}
|
|
163
|
+
schedule();
|
|
164
|
+
});
|
|
165
|
+
mutations.observe(watched, WATCH);
|
|
166
|
+
const sizes = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);
|
|
167
|
+
sizes?.observe(root);
|
|
168
|
+
return () => {
|
|
169
|
+
mutations.disconnect();
|
|
170
|
+
sizes?.disconnect();
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
$effect(() => () => cancelAnimationFrame(frame));
|
|
174
|
+
|
|
175
|
+
const WATCH: MutationObserverInit = {
|
|
176
|
+
subtree: true,
|
|
177
|
+
childList: true,
|
|
178
|
+
attributes: true,
|
|
179
|
+
attributeFilter: ['data-qm-review', 'class', 'open', 'hidden']
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/** Put the focus on Accept, handing it back to where it was on Escape or an answer. False
|
|
183
|
+
* with no card on show. */
|
|
184
|
+
export async function enter(): Promise<boolean> {
|
|
185
|
+
if (!shown || !el || !inView(el)) return false;
|
|
186
|
+
from = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
|
|
187
|
+
await tick();
|
|
188
|
+
el.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function leave(): void {
|
|
193
|
+
const back = from;
|
|
194
|
+
from = undefined;
|
|
195
|
+
if (back?.isConnected) back.focus({ preventScroll: true });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function answer(action: 'accept' | 'dismiss'): void {
|
|
199
|
+
const held = !!el?.contains(document.activeElement);
|
|
200
|
+
onAnswer(action);
|
|
201
|
+
if (held) leave();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function onkeydown(e: KeyboardEvent): void {
|
|
205
|
+
if (e.key === 'Escape') {
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
leave();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (e.key !== 'Tab' && e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
211
|
+
const buttons = [...(el?.querySelectorAll<HTMLElement>('button') ?? [])];
|
|
212
|
+
const at = buttons.indexOf(document.activeElement as HTMLElement);
|
|
213
|
+
if (at < 0) return;
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const back = e.key === 'ArrowLeft' || (e.key === 'Tab' && e.shiftKey);
|
|
216
|
+
buttons[(at + (back ? -1 : 1) + buttons.length) % buttons.length].focus();
|
|
217
|
+
}
|
|
218
|
+
</script>
|
|
219
|
+
|
|
220
|
+
<svelte:window onscrollcapture={schedule} onresize={schedule} />
|
|
221
|
+
|
|
222
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
223
|
+
<!-- The press keeps the focus where it is: the answer is about the text, not a move off it. -->
|
|
224
|
+
<div
|
|
225
|
+
bind:this={el}
|
|
226
|
+
class={[
|
|
227
|
+
'qm-review-card qm-popover-surface',
|
|
228
|
+
{ 'qm-review-card-on': shown, 'qm-review-card-pinned': pinned }
|
|
229
|
+
]}
|
|
230
|
+
style:top="{top}px"
|
|
231
|
+
style:left="{left}px"
|
|
232
|
+
role="group"
|
|
233
|
+
aria-label={t.strings.reviewProposal}
|
|
234
|
+
aria-hidden={!shown}
|
|
235
|
+
inert={!shown}
|
|
236
|
+
onpointerenter={() => onHover(true)}
|
|
237
|
+
onpointerleave={() => onHover(false)}
|
|
238
|
+
onmousedown={(e) => e.preventDefault()}
|
|
239
|
+
{onkeydown}
|
|
240
|
+
onfocusout={(e) => {
|
|
241
|
+
if (!el?.contains(e.relatedTarget as Node | null)) from = undefined;
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
{#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
|
|
245
|
+
<button
|
|
246
|
+
type="button"
|
|
247
|
+
class="qm-review-card-dismiss qm-focus-ring"
|
|
248
|
+
tabindex="-1"
|
|
249
|
+
aria-keyshortcuts="Meta+. Control+."
|
|
250
|
+
onclick={() => answer('dismiss')}>{t.strings.reviewDismiss}<kbd>{chord('.')}</kbd></button
|
|
251
|
+
>
|
|
252
|
+
<button
|
|
253
|
+
type="button"
|
|
254
|
+
class="qm-review-card-accept qm-focus-ring"
|
|
255
|
+
tabindex="-1"
|
|
256
|
+
aria-keyshortcuts="Meta+Enter Control+Enter"
|
|
257
|
+
onclick={() => answer('accept')}>{t.strings.reviewAccept}<kbd>{chord('↵')}</kbd></button
|
|
258
|
+
>
|
|
259
|
+
</div>
|
|
260
|
+
|
|
261
|
+
<style>
|
|
262
|
+
/* Out of flow and over the text, at the popover's lift, translucency and blur. Placed in the
|
|
263
|
+
editor's own coordinates, so it scrolls with the change it stands on rather than chasing it
|
|
264
|
+
frame by frame. Hidden by opacity rather than unmounted, so a step glides it from one change
|
|
265
|
+
to the next. */
|
|
266
|
+
.qm-review-card {
|
|
267
|
+
position: absolute;
|
|
268
|
+
z-index: 2;
|
|
269
|
+
width: max-content;
|
|
270
|
+
display: flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
gap: var(--_qm-space-half);
|
|
273
|
+
padding: var(--_qm-space-half);
|
|
274
|
+
font-family: var(--_qm-font);
|
|
275
|
+
font-size: var(--_qm-text-label);
|
|
276
|
+
line-height: var(--_qm-leading-tight);
|
|
277
|
+
color: var(--_qm-ink);
|
|
278
|
+
opacity: 0;
|
|
279
|
+
pointer-events: none;
|
|
280
|
+
animation: none;
|
|
281
|
+
transition:
|
|
282
|
+
opacity var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
283
|
+
top var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
284
|
+
left var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
285
|
+
}
|
|
286
|
+
.qm-review-card-pinned {
|
|
287
|
+
transition: opacity var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
288
|
+
}
|
|
289
|
+
.qm-review-card-on {
|
|
290
|
+
opacity: 1;
|
|
291
|
+
pointer-events: auto;
|
|
292
|
+
}
|
|
293
|
+
@media (prefers-reduced-motion: reduce) {
|
|
294
|
+
.qm-review-card {
|
|
295
|
+
transition: opacity var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
button {
|
|
299
|
+
display: inline-flex;
|
|
300
|
+
align-items: center;
|
|
301
|
+
gap: var(--_qm-space);
|
|
302
|
+
min-height: var(--_qm-tap-min);
|
|
303
|
+
padding: var(--_qm-space-half) var(--_qm-space-2);
|
|
304
|
+
border: none;
|
|
305
|
+
border-radius: var(--_qm-radius-inner);
|
|
306
|
+
background: transparent;
|
|
307
|
+
font: inherit;
|
|
308
|
+
font-weight: var(--_qm-weight-mid);
|
|
309
|
+
color: inherit;
|
|
310
|
+
cursor: pointer;
|
|
311
|
+
transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
312
|
+
}
|
|
313
|
+
.qm-review-card-dismiss {
|
|
314
|
+
color: var(--_qm-ink-label);
|
|
315
|
+
}
|
|
316
|
+
.qm-review-card-dismiss:hover {
|
|
317
|
+
background: var(--_qm-surface-hover);
|
|
318
|
+
color: var(--_qm-ink);
|
|
319
|
+
}
|
|
320
|
+
.qm-review-card-accept {
|
|
321
|
+
padding-inline: var(--_qm-space-3);
|
|
322
|
+
background: var(--_qm-accent);
|
|
323
|
+
color: var(--_qm-bg);
|
|
324
|
+
}
|
|
325
|
+
kbd {
|
|
326
|
+
font: inherit;
|
|
327
|
+
opacity: var(--_qm-opacity-rest);
|
|
328
|
+
}
|
|
329
|
+
.qm-review-card-note {
|
|
330
|
+
padding-inline: var(--_qm-space-2);
|
|
331
|
+
color: var(--_qm-ink-label);
|
|
332
|
+
}
|
|
333
|
+
/* Under a finger the keys are no help, and each answer is a tap target. */
|
|
334
|
+
@media (pointer: coarse) {
|
|
335
|
+
kbd {
|
|
336
|
+
display: none;
|
|
337
|
+
}
|
|
338
|
+
button {
|
|
339
|
+
padding-inline: var(--_qm-space-3);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
@media (forced-colors: active) {
|
|
343
|
+
button {
|
|
344
|
+
border: var(--_qm-border-width) solid ButtonText;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
</style>
|