@quillmark/svelte 0.35.1 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -18
- package/THEMING.md +1 -1
- package/dist/core/address.d.ts +5 -0
- package/dist/core/address.js +14 -0
- package/dist/core/codec/decode.d.ts +4 -2
- package/dist/core/codec/decode.js +5 -2
- package/dist/core/codec/field.d.ts +42 -16
- package/dist/core/codec/field.js +97 -28
- package/dist/core/codec/index.d.ts +8 -5
- package/dist/core/codec/index.js +4 -5
- package/dist/core/codec/prose.css +25 -81
- package/dist/core/codec/review.d.ts +31 -26
- package/dist/core/codec/review.js +93 -169
- package/dist/core/codec/schema.d.ts +12 -2
- package/dist/core/codec/schema.js +27 -5
- package/dist/core/codec/shortcuts.d.ts +5 -4
- package/dist/core/codec/shortcuts.js +9 -8
- package/dist/core/codec/table-view.js +15 -3
- package/dist/core/codec/value-diff.d.ts +21 -0
- package/dist/core/codec/value-diff.js +83 -0
- package/dist/core/codec/value-plan.d.ts +29 -0
- package/dist/core/codec/value-plan.js +157 -0
- package/dist/core/theme.css +46 -15
- package/dist/core/tooltip.css +49 -0
- package/dist/core/tooltip.d.ts +6 -0
- package/dist/core/tooltip.js +176 -0
- package/dist/preview/Preview.svelte +22 -1
- package/dist/preview/controller.js +38 -0
- package/dist/preview/strings.d.ts +2 -0
- package/dist/preview/strings.js +1 -0
- package/dist/visual/ArrayField.svelte +374 -96
- package/dist/visual/Card.svelte +33 -12
- package/dist/visual/Card.svelte.d.ts +3 -0
- package/dist/visual/CardControls.svelte +3 -3
- package/dist/visual/DateField.svelte +47 -5
- package/dist/visual/DiagnosticList.svelte +3 -2
- package/dist/visual/EnumField.svelte +20 -5
- package/dist/visual/EnumField.svelte.d.ts +5 -0
- package/dist/visual/Field.svelte +56 -47
- package/dist/visual/FieldHint.svelte +20 -8
- package/dist/visual/FormatPopover.svelte +54 -20
- package/dist/visual/MatrixField.svelte +48 -6
- package/dist/visual/MatrixField.svelte.d.ts +5 -0
- package/dist/visual/NumberField.svelte +131 -6
- package/dist/visual/NumberField.svelte.d.ts +5 -0
- package/dist/visual/ObjectField.svelte +60 -18
- package/dist/visual/ProseField.svelte +21 -5
- package/dist/visual/ProseField.svelte.d.ts +5 -1
- package/dist/visual/ProseValue.svelte +49 -8
- package/dist/visual/ProseValue.svelte.d.ts +7 -1
- package/dist/visual/ReviewCard.svelte +400 -0
- package/dist/visual/ReviewCard.svelte.d.ts +20 -0
- package/dist/visual/ReviewProposal.svelte +98 -138
- package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
- package/dist/visual/ReviewRows.svelte +6 -25
- package/dist/visual/ReviewRows.svelte.d.ts +1 -3
- package/dist/visual/SlashMenu.svelte +1 -0
- package/dist/visual/TipsCard.svelte +1 -1
- package/dist/visual/VariantField.svelte +45 -4
- package/dist/visual/VariantField.svelte.d.ts +5 -0
- package/dist/visual/VisualEditor.svelte +24 -9
- package/dist/visual/VisualEditor.svelte.d.ts +8 -1
- package/dist/visual/VisualEditorInner.svelte +917 -280
- package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
- package/dist/visual/controls.css +2 -2
- package/dist/visual/index.d.ts +2 -2
- package/dist/visual/proposals.d.ts +25 -24
- package/dist/visual/proposals.js +92 -32
- package/dist/visual/props.d.ts +18 -18
- package/dist/visual/review-order.d.ts +51 -0
- package/dist/visual/review-order.js +87 -0
- package/dist/visual/review.d.ts +94 -3
- package/dist/visual/review.js +37 -2
- package/dist/visual/review.svelte.d.ts +77 -20
- package/dist/visual/review.svelte.js +306 -49
- package/dist/visual/strings.d.ts +59 -25
- package/dist/visual/strings.js +90 -29
- package/dist/visual/structure.d.ts +17 -3
- package/dist/visual/structure.js +71 -5
- package/dist/visual/undo.svelte.d.ts +3 -1
- package/dist/visual/undo.svelte.js +7 -3
- package/package.json +2 -2
|
@@ -0,0 +1,400 @@
|
|
|
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, a note
|
|
4
|
+
where the reader's own writing meets the change, and above them the line the proposal's writer
|
|
5
|
+
gave for it, cut to one line. The change itself is drawn where it
|
|
6
|
+
stands, so the card is the same two answers on every change. It carries no position: the count
|
|
7
|
+
is the host's bar's.
|
|
8
|
+
|
|
9
|
+
It sits under the block the change flows in, so it covers no line of its paragraph, or beside
|
|
10
|
+
that block's last line where the line ends short of it, centred on a block of one line such as a
|
|
11
|
+
one-line field's, right-aligned to the text column the
|
|
12
|
+
change stands in, and flips above that block where there is no room below, keeping clear of the
|
|
13
|
+
host's chrome at the pane's foot (`inset`). Over a change taller than the pane it stays pinned
|
|
14
|
+
at the foot while any of the change shows. A change out of the pane keeps its card where it
|
|
15
|
+
would stand beside it, so the card scrolls out with the text and the pane's edge clips it as it
|
|
16
|
+
clips the text.
|
|
17
|
+
A change is several elements (struck runs, tinted widgets, added blocks, a row
|
|
18
|
+
under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
|
|
19
|
+
redraws its decorations as it likes, and a box measured once parts from the text it stood on.
|
|
20
|
+
What it watches is the card holding the change, not the editor: a mutation there, a scroll
|
|
21
|
+
anywhere, a resize of the editor.
|
|
22
|
+
|
|
23
|
+
It never takes the focus. A press on it keeps the focus where it is, and the keyboard reaches
|
|
24
|
+
it only by `enter`, from which Escape and every answer hand the focus back.
|
|
25
|
+
-->
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { tick } from 'svelte';
|
|
28
|
+
import { REVIEW_KEYS } from '../core/codec/index.js';
|
|
29
|
+
import { keycap, keyshortcut, wording } from './strings.js';
|
|
30
|
+
import './controls.css';
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
/** The current change, `undefined` for no card. */
|
|
34
|
+
id: string | undefined;
|
|
35
|
+
/** The editor's root, which every element of the change is under. */
|
|
36
|
+
root: HTMLElement | undefined;
|
|
37
|
+
/** The room, in px, the host's chrome takes at the pane's foot. */
|
|
38
|
+
inset: number;
|
|
39
|
+
/** Held out of the way: the reader is typing. */
|
|
40
|
+
hidden: boolean;
|
|
41
|
+
/** The reader's own writing meets the change. */
|
|
42
|
+
outdated: boolean;
|
|
43
|
+
/** Why, as the proposal's writer says it. */
|
|
44
|
+
note?: string;
|
|
45
|
+
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
46
|
+
}
|
|
47
|
+
let { id, root, inset, hidden, outdated, note, onAnswer }: Props = $props();
|
|
48
|
+
const noteId = $props.id();
|
|
49
|
+
|
|
50
|
+
const t = wording();
|
|
51
|
+
|
|
52
|
+
let el = $state<HTMLElement | undefined>();
|
|
53
|
+
let top = $state(0);
|
|
54
|
+
let left = $state(0);
|
|
55
|
+
/** Pinned at the pane's foot, where every scroll moves it, so it follows without a glide. */
|
|
56
|
+
let pinned = $state(false);
|
|
57
|
+
/** The change is drawn, so the card has somewhere to stand. */
|
|
58
|
+
let placed = $state(false);
|
|
59
|
+
/** Where the focus was when the keyboard entered the card, to hand it back. */
|
|
60
|
+
let from: HTMLElement | undefined;
|
|
61
|
+
|
|
62
|
+
const shown = $derived(placed && !hidden && id !== undefined);
|
|
63
|
+
|
|
64
|
+
/** The elements the change draws. */
|
|
65
|
+
const parts = (): HTMLElement[] =>
|
|
66
|
+
id === undefined || !root
|
|
67
|
+
? []
|
|
68
|
+
: [...root.querySelectorAll<HTMLElement>(`[data-qm-review~="${CSS.escape(id)}"]`)];
|
|
69
|
+
|
|
70
|
+
/** The box the pane shows the editor through: its nearest scroller's, within the window. */
|
|
71
|
+
function band(): { top: number; bottom: number; left: number; right: number } {
|
|
72
|
+
let box = { top: 0, bottom: window.innerHeight, left: 0, right: window.innerWidth };
|
|
73
|
+
for (let at = root ?? null; at; at = at.parentElement) {
|
|
74
|
+
const { overflowY } = getComputedStyle(at);
|
|
75
|
+
if (overflowY !== 'auto' && overflowY !== 'scroll') continue;
|
|
76
|
+
const r = at.getBoundingClientRect();
|
|
77
|
+
box = {
|
|
78
|
+
top: Math.max(r.top, 0),
|
|
79
|
+
bottom: Math.min(r.bottom, window.innerHeight),
|
|
80
|
+
left: Math.max(r.left, 0),
|
|
81
|
+
right: Math.min(r.right, window.innerWidth)
|
|
82
|
+
};
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return box;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Whether any of `at` shows in the pane, clear of the host's chrome at its foot. */
|
|
89
|
+
function inView(at: HTMLElement): boolean {
|
|
90
|
+
const r = at.getBoundingClientRect();
|
|
91
|
+
const view = band();
|
|
92
|
+
return r.bottom > view.top && r.top < view.bottom - inset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function place(): void {
|
|
96
|
+
const els = parts();
|
|
97
|
+
const blocks = els.map(blockOf);
|
|
98
|
+
const rects = blocks.map((b) => b.getBoundingClientRect()).filter((r) => r.width || r.height);
|
|
99
|
+
if (!el || !rects.length) {
|
|
100
|
+
placed = false;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const gap = gapPx();
|
|
104
|
+
const view = band();
|
|
105
|
+
const ceil = view.top + gap;
|
|
106
|
+
const floor = view.bottom - inset - gap;
|
|
107
|
+
const upper = Math.min(...rects.map((r) => r.top));
|
|
108
|
+
const lower = Math.max(...rects.map((r) => r.bottom));
|
|
109
|
+
const shows = lower >= ceil && upper <= floor;
|
|
110
|
+
const h = el.offsetHeight;
|
|
111
|
+
const w = el.offsetWidth;
|
|
112
|
+
const column = (els[0].closest(
|
|
113
|
+
'.qm-field, .qm-card, .qm-review-card-add, .qm-review-card-remove'
|
|
114
|
+
) ?? root)!;
|
|
115
|
+
left = Math.max(view.left + gap, column.getBoundingClientRect().right - w);
|
|
116
|
+
const at = (root ?? el).getBoundingClientRect();
|
|
117
|
+
const last = blocks.find((b, i) => b !== els[i] && b.getBoundingClientRect().bottom === lower);
|
|
118
|
+
const tuck = last && lastLine(last, h);
|
|
119
|
+
const below = tuck && tuck.right + gap <= left ? tuck.top : lower + gap;
|
|
120
|
+
const above = upper - gap - h;
|
|
121
|
+
const fits = below + h <= floor || above >= ceil;
|
|
122
|
+
const y =
|
|
123
|
+
below + h <= floor
|
|
124
|
+
? below
|
|
125
|
+
: above >= ceil
|
|
126
|
+
? above
|
|
127
|
+
: !shows
|
|
128
|
+
? upper > floor
|
|
129
|
+
? above
|
|
130
|
+
: below
|
|
131
|
+
: Math.max(ceil, Math.min(floor - h, below));
|
|
132
|
+
top = y - at.top + (root?.scrollTop ?? 0);
|
|
133
|
+
left = left - at.left + (root?.scrollLeft ?? 0);
|
|
134
|
+
pinned = shows && !fits;
|
|
135
|
+
placed = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The block a run of the change flows in, which the card keeps clear of whole: a card on
|
|
139
|
+
* the run's own line covers the lines of its paragraph after it. */
|
|
140
|
+
function blockOf(at: HTMLElement): HTMLElement {
|
|
141
|
+
for (let up: HTMLElement | null = at; up && up !== root; up = up.parentElement)
|
|
142
|
+
if (!/^(inline|contents)/.test(getComputedStyle(up).display)) return up;
|
|
143
|
+
return at;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Where a card `h` tall stands beside the last line of a block, and where the line's words
|
|
147
|
+
* end: a card beside a short last line covers nothing of the block, and beside a one-line
|
|
148
|
+
* field's text, centred on it, nothing of the field after it. */
|
|
149
|
+
function lastLine(block: HTMLElement, h: number): { top: number; right: number } | undefined {
|
|
150
|
+
const range = document.createRange();
|
|
151
|
+
range.selectNodeContents(block);
|
|
152
|
+
const lines = [...range.getClientRects()].filter((r) => r.width && r.height);
|
|
153
|
+
if (!lines.length) return undefined;
|
|
154
|
+
const from = Math.max(...lines.map((r) => r.top));
|
|
155
|
+
const on = lines.filter((r) => r.bottom > from);
|
|
156
|
+
const top = Math.min(...on.map((r) => r.top));
|
|
157
|
+
const right = Math.max(...on.map((r) => r.right));
|
|
158
|
+
if (on.length < lines.length) return { top, right };
|
|
159
|
+
const bottom = Math.max(...on.map((r) => r.bottom));
|
|
160
|
+
return { top: (top + bottom - h) / 2, right };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function gapPx(): number {
|
|
164
|
+
const n = Number.parseFloat(getComputedStyle(el ?? root!).getPropertyValue('--_qm-space'));
|
|
165
|
+
return Number.isFinite(n) ? n : 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let frame = 0;
|
|
169
|
+
function schedule(): void {
|
|
170
|
+
if (frame) return;
|
|
171
|
+
frame = requestAnimationFrame(() => {
|
|
172
|
+
frame = 0;
|
|
173
|
+
place();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// What moves the change: its own card's subtree, and the editor's size. Until the change has
|
|
178
|
+
// drawn, the editor as a whole, which an advance to a change not yet redrawn needs.
|
|
179
|
+
$effect(() => {
|
|
180
|
+
void id;
|
|
181
|
+
void inset;
|
|
182
|
+
void hidden;
|
|
183
|
+
if (!root || id === undefined) {
|
|
184
|
+
placed = false;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
schedule();
|
|
188
|
+
const home = (): Element =>
|
|
189
|
+
parts()[0]?.closest('.qm-card-slot, .qm-primary, .qm-review-head') ?? root!;
|
|
190
|
+
let watched = home();
|
|
191
|
+
const mutations = new MutationObserver(() => {
|
|
192
|
+
const now = home();
|
|
193
|
+
if (now !== watched) {
|
|
194
|
+
mutations.disconnect();
|
|
195
|
+
watched = now;
|
|
196
|
+
mutations.observe(watched, WATCH);
|
|
197
|
+
}
|
|
198
|
+
schedule();
|
|
199
|
+
});
|
|
200
|
+
mutations.observe(watched, WATCH);
|
|
201
|
+
const sizes = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);
|
|
202
|
+
sizes?.observe(root);
|
|
203
|
+
return () => {
|
|
204
|
+
mutations.disconnect();
|
|
205
|
+
sizes?.disconnect();
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
$effect(() => () => cancelAnimationFrame(frame));
|
|
209
|
+
|
|
210
|
+
const WATCH: MutationObserverInit = {
|
|
211
|
+
subtree: true,
|
|
212
|
+
childList: true,
|
|
213
|
+
attributes: true,
|
|
214
|
+
attributeFilter: ['data-qm-review', 'class', 'open', 'hidden']
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** Put the focus on Accept, handing it back to where it was on Escape or an answer. False
|
|
218
|
+
* with no card on show. */
|
|
219
|
+
export async function enter(): Promise<boolean> {
|
|
220
|
+
if (!shown || !el || !inView(el)) return false;
|
|
221
|
+
from = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
|
|
222
|
+
await tick();
|
|
223
|
+
el.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function leave(): void {
|
|
228
|
+
const back = from;
|
|
229
|
+
from = undefined;
|
|
230
|
+
if (back?.isConnected) back.focus({ preventScroll: true });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function answer(action: 'accept' | 'dismiss'): void {
|
|
234
|
+
const held = !!el?.contains(document.activeElement);
|
|
235
|
+
onAnswer(action);
|
|
236
|
+
if (held) leave();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function onkeydown(e: KeyboardEvent): void {
|
|
240
|
+
if (e.key === 'Escape') {
|
|
241
|
+
e.preventDefault();
|
|
242
|
+
leave();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (e.key !== 'Tab' && e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
246
|
+
const buttons = [...(el?.querySelectorAll<HTMLElement>('button') ?? [])];
|
|
247
|
+
const at = buttons.indexOf(document.activeElement as HTMLElement);
|
|
248
|
+
if (at < 0) return;
|
|
249
|
+
e.preventDefault();
|
|
250
|
+
const back = e.key === 'ArrowLeft' || (e.key === 'Tab' && e.shiftKey);
|
|
251
|
+
buttons[(at + (back ? -1 : 1) + buttons.length) % buttons.length].focus();
|
|
252
|
+
}
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
<svelte:window onscrollcapture={schedule} onresize={schedule} />
|
|
256
|
+
|
|
257
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
258
|
+
<!-- The press keeps the focus where it is: the answer is about the text, not a move off it. -->
|
|
259
|
+
<div
|
|
260
|
+
bind:this={el}
|
|
261
|
+
class={[
|
|
262
|
+
'qm-review-card qm-popover-surface',
|
|
263
|
+
{ 'qm-review-card-on': shown, 'qm-review-card-pinned': pinned }
|
|
264
|
+
]}
|
|
265
|
+
style:top="{top}px"
|
|
266
|
+
style:left="{left}px"
|
|
267
|
+
role="group"
|
|
268
|
+
aria-label={t.strings.reviewProposal}
|
|
269
|
+
aria-describedby={note ? noteId : undefined}
|
|
270
|
+
aria-hidden={!shown}
|
|
271
|
+
inert={!shown}
|
|
272
|
+
onmousedown={(e) => e.preventDefault()}
|
|
273
|
+
{onkeydown}
|
|
274
|
+
onfocusout={(e) => {
|
|
275
|
+
if (!el?.contains(e.relatedTarget as Node | null)) from = undefined;
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{#if note}<p id={noteId} class="qm-review-card-reason" title={note}>{note}</p>{/if}
|
|
279
|
+
<div class="qm-review-card-answers">
|
|
280
|
+
{#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
|
|
281
|
+
<button
|
|
282
|
+
type="button"
|
|
283
|
+
class="qm-review-card-dismiss qm-focus-ring"
|
|
284
|
+
tabindex="-1"
|
|
285
|
+
aria-keyshortcuts={keyshortcut(REVIEW_KEYS.dismiss)}
|
|
286
|
+
onclick={() => answer('dismiss')}
|
|
287
|
+
>{t.strings.reviewDismiss}<kbd>{keycap(REVIEW_KEYS.dismiss)}</kbd></button
|
|
288
|
+
>
|
|
289
|
+
<button
|
|
290
|
+
type="button"
|
|
291
|
+
class="qm-review-card-accept qm-focus-ring"
|
|
292
|
+
tabindex="-1"
|
|
293
|
+
aria-keyshortcuts={keyshortcut(REVIEW_KEYS.accept)}
|
|
294
|
+
onclick={() => answer('accept')}
|
|
295
|
+
>{t.strings.reviewAccept}<kbd>{keycap(REVIEW_KEYS.accept)}</kbd></button
|
|
296
|
+
>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<style>
|
|
301
|
+
/* Out of flow and over the text, at the popover's lift, translucency and blur. Placed in the
|
|
302
|
+
editor's own coordinates, so it scrolls with the change it stands on rather than chasing it
|
|
303
|
+
frame by frame. Hidden by opacity rather than unmounted, so a step glides it from one change
|
|
304
|
+
to the next. */
|
|
305
|
+
.qm-review-card {
|
|
306
|
+
position: absolute;
|
|
307
|
+
z-index: 2;
|
|
308
|
+
width: max-content;
|
|
309
|
+
display: flex;
|
|
310
|
+
flex-direction: column;
|
|
311
|
+
gap: var(--_qm-space-half);
|
|
312
|
+
padding: var(--_qm-space-half);
|
|
313
|
+
font-family: var(--_qm-font);
|
|
314
|
+
font-size: var(--_qm-text-label);
|
|
315
|
+
line-height: var(--_qm-leading-tight);
|
|
316
|
+
color: var(--_qm-ink);
|
|
317
|
+
opacity: 0;
|
|
318
|
+
pointer-events: none;
|
|
319
|
+
animation: none;
|
|
320
|
+
transition:
|
|
321
|
+
opacity var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
322
|
+
top var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
323
|
+
left var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
324
|
+
}
|
|
325
|
+
.qm-review-card-pinned {
|
|
326
|
+
transition: opacity var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
327
|
+
}
|
|
328
|
+
.qm-review-card-on {
|
|
329
|
+
opacity: 1;
|
|
330
|
+
pointer-events: auto;
|
|
331
|
+
}
|
|
332
|
+
@media (prefers-reduced-motion: reduce) {
|
|
333
|
+
.qm-review-card {
|
|
334
|
+
transition: opacity var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
button {
|
|
338
|
+
display: inline-flex;
|
|
339
|
+
align-items: center;
|
|
340
|
+
gap: var(--_qm-space);
|
|
341
|
+
min-height: var(--_qm-tap-min);
|
|
342
|
+
padding: var(--_qm-space-half) var(--_qm-space-2);
|
|
343
|
+
border: none;
|
|
344
|
+
border-radius: var(--_qm-radius-inner);
|
|
345
|
+
background: transparent;
|
|
346
|
+
font: inherit;
|
|
347
|
+
font-weight: var(--_qm-weight-mid);
|
|
348
|
+
color: inherit;
|
|
349
|
+
cursor: pointer;
|
|
350
|
+
transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
351
|
+
}
|
|
352
|
+
.qm-review-card-dismiss {
|
|
353
|
+
color: var(--_qm-ink-label);
|
|
354
|
+
}
|
|
355
|
+
.qm-review-card-dismiss:hover {
|
|
356
|
+
background: var(--_qm-surface-hover);
|
|
357
|
+
color: var(--_qm-ink);
|
|
358
|
+
}
|
|
359
|
+
.qm-review-card-accept {
|
|
360
|
+
padding-inline: var(--_qm-space-3);
|
|
361
|
+
background: var(--_qm-accent);
|
|
362
|
+
color: var(--_qm-bg);
|
|
363
|
+
}
|
|
364
|
+
kbd {
|
|
365
|
+
font: inherit;
|
|
366
|
+
}
|
|
367
|
+
.qm-review-card-answers {
|
|
368
|
+
display: flex;
|
|
369
|
+
align-items: center;
|
|
370
|
+
justify-content: flex-end;
|
|
371
|
+
gap: var(--_qm-space-half);
|
|
372
|
+
}
|
|
373
|
+
.qm-review-card-reason {
|
|
374
|
+
max-width: min(24rem, calc(100vw - 4 * var(--_qm-space-2)));
|
|
375
|
+
margin: 0;
|
|
376
|
+
padding: var(--_qm-space-half) var(--_qm-space-2) 0;
|
|
377
|
+
overflow: hidden;
|
|
378
|
+
white-space: nowrap;
|
|
379
|
+
text-overflow: ellipsis;
|
|
380
|
+
color: var(--_qm-ink);
|
|
381
|
+
}
|
|
382
|
+
.qm-review-card-note {
|
|
383
|
+
padding-inline: var(--_qm-space-2);
|
|
384
|
+
color: var(--_qm-ink-label);
|
|
385
|
+
}
|
|
386
|
+
/* Under a finger the keys are no help, and each answer is a tap target. */
|
|
387
|
+
@media (pointer: coarse), (hover: none) {
|
|
388
|
+
kbd {
|
|
389
|
+
display: none;
|
|
390
|
+
}
|
|
391
|
+
button {
|
|
392
|
+
padding-inline: var(--_qm-space-3);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
@media (forced-colors: active) {
|
|
396
|
+
button {
|
|
397
|
+
border: var(--_qm-border-width) solid ButtonText;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** The current change, `undefined` for no card. */
|
|
3
|
+
id: string | undefined;
|
|
4
|
+
/** The editor's root, which every element of the change is under. */
|
|
5
|
+
root: HTMLElement | undefined;
|
|
6
|
+
/** The room, in px, the host's chrome takes at the pane's foot. */
|
|
7
|
+
inset: number;
|
|
8
|
+
/** Held out of the way: the reader is typing. */
|
|
9
|
+
hidden: boolean;
|
|
10
|
+
/** The reader's own writing meets the change. */
|
|
11
|
+
outdated: boolean;
|
|
12
|
+
/** Why, as the proposal's writer says it. */
|
|
13
|
+
note?: string;
|
|
14
|
+
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
15
|
+
}
|
|
16
|
+
declare const ReviewCard: import("svelte").Component<Props, {
|
|
17
|
+
enter: () => Promise<boolean>;
|
|
18
|
+
}, "">;
|
|
19
|
+
type ReviewCard = ReturnType<typeof ReviewCard>;
|
|
20
|
+
export default ReviewCard;
|
|
@@ -1,156 +1,116 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
A proposed value
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
A proposed value whose control cannot draw it as words, marked on that control. The control
|
|
3
|
+
shows the value it would hold (its caller hands it `after`) and takes the review tint, so a
|
|
4
|
+
proposal moves nothing around it; a member a proposal takes out is struck where it stands. A
|
|
5
|
+
one-line text leaf draws its proposal itself, as a word diff (`value-diff.ts`), and takes no
|
|
6
|
+
mark.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
It draws nothing of its own. Its anchor holds what the mark says to assistive tech, the proposed
|
|
9
|
+
value being the one the control shows, and each focusable part of the control is described by it. Its anchor stands after the control it marks, and the control is
|
|
10
|
+
the nearest element before it that is neither another anchor, a diagnostic list nor a row's
|
|
11
|
+
actions; with none, its parent. The mark sits on that control's own box (`BOX`) where the
|
|
12
|
+
element found is a cell or a row holding one, so the tint never spreads past the control. The control carries the item's id among its `data-qm-review`
|
|
13
|
+
tokens, so the card stands on the control and a press on it names the item.
|
|
10
14
|
-->
|
|
11
15
|
<script lang="ts">
|
|
12
|
-
import {
|
|
13
|
-
import { reviewRuns, reviewText, type FieldProposal } from './review.js';
|
|
16
|
+
import { reviewText, type FieldProposal } from './review.js';
|
|
14
17
|
import { review } from './review.svelte.js';
|
|
18
|
+
import { wording } from './strings.js';
|
|
15
19
|
|
|
16
20
|
interface Props {
|
|
17
21
|
item: FieldProposal;
|
|
18
|
-
/** The value the control holds. */
|
|
19
|
-
value: unknown;
|
|
20
|
-
/** Take the focus back to the control: an answer given from the row unmounts it. */
|
|
21
|
-
refocus?: () => void;
|
|
22
|
-
/** Where the value is, for one drawn under a control that is not its own. */
|
|
23
|
-
label?: string;
|
|
24
22
|
/** It takes a list's member out, so nothing comes in its place. */
|
|
25
23
|
removes?: boolean;
|
|
24
|
+
/** The value the control would show without the proposal, where the caller knows it: a
|
|
25
|
+
* default an unset field prints. Else the value the place holds. */
|
|
26
|
+
current?: unknown;
|
|
26
27
|
}
|
|
27
|
-
let { item,
|
|
28
|
+
let { item, removes = false, current }: Props = $props();
|
|
28
29
|
|
|
29
|
-
let row = $state<HTMLElement>();
|
|
30
|
-
function answer(action: 'accept' | 'dismiss'): void {
|
|
31
|
-
const held = !!row?.contains(document.activeElement);
|
|
32
|
-
reviewing.act(item.id, action);
|
|
33
|
-
if (held) refocus?.();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const t = wording();
|
|
37
30
|
const reviewing = review();
|
|
31
|
+
const t = wording();
|
|
32
|
+
const describer = $props.id();
|
|
33
|
+
const description = $derived.by(() => {
|
|
34
|
+
if (removes) return t.strings.reviewRemoveCard;
|
|
35
|
+
const words = { on: t.strings.reviewOn, off: t.strings.reviewOff };
|
|
36
|
+
const now = current ?? reviewing.current(item);
|
|
37
|
+
const shown = now == null && typeof item.after === 'boolean' ? false : now;
|
|
38
|
+
return t.strings.reviewCurrently(reviewText(shown, words) || t.strings.reviewEmpty);
|
|
39
|
+
});
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
/** What a reader lands on in the control: the control itself where it takes focus, else each
|
|
42
|
+
* part of it that does, a date's segments. */
|
|
43
|
+
const FOCUSABLE =
|
|
44
|
+
'button, input, select, [contenteditable="true"], [tabindex]:not([tabindex="-1"])';
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
<div
|
|
46
|
-
bind:this={row}
|
|
47
|
-
class={['qm-review-proposal', { 'qm-review-lit': reviewing.lit === item.id }]}
|
|
48
|
-
data-qm-review={item.id}
|
|
49
|
-
role="group"
|
|
50
|
-
aria-label={t.strings.reviewProposal}
|
|
51
|
-
onpointerenter={() => reviewing.point(item.id, 'pointer')}
|
|
52
|
-
onpointerleave={() => reviewing.point(undefined, 'pointer')}
|
|
53
|
-
>
|
|
54
|
-
<span class="qm-review-value">
|
|
55
|
-
{#if label}<span class="qm-review-where">{label}: </span>{/if}
|
|
56
|
-
{#each runs as run, i (i)}
|
|
57
|
-
{#if run.kind === 'del'}<del class="qm-review-del">{run.text}</del
|
|
58
|
-
>{:else if run.kind === 'ins'}<ins class="qm-review-ins">{run.text}</ins
|
|
59
|
-
>{:else}{run.text}{/if}
|
|
60
|
-
{/each}
|
|
61
|
-
{#if !after && !removes}
|
|
62
|
-
<span class="qm-review-none">{t.strings.reviewEmpty}</span>
|
|
63
|
-
{/if}
|
|
64
|
-
</span>
|
|
65
|
-
<span class="qm-review-answers">
|
|
66
|
-
{#if reviewing.fieldOutdated.has(item.id)}
|
|
67
|
-
<span class="qm-review-outdated-label">{t.strings.reviewOutdated}</span>
|
|
68
|
-
{/if}
|
|
69
|
-
<button
|
|
70
|
-
type="button"
|
|
71
|
-
class="qm-review-act qm-review-accept qm-focus-ring"
|
|
72
|
-
title={t.strings.reviewAcceptTitle}
|
|
73
|
-
onclick={() => answer('accept')}>{t.strings.reviewAccept}</button
|
|
74
|
-
>
|
|
75
|
-
<button
|
|
76
|
-
type="button"
|
|
77
|
-
class="qm-review-act qm-review-dismiss qm-focus-ring"
|
|
78
|
-
title={t.strings.reviewDismissTitle}
|
|
79
|
-
onclick={() => answer('dismiss')}>{t.strings.reviewDismiss}</button
|
|
80
|
-
>
|
|
81
|
-
</span>
|
|
82
|
-
</div>
|
|
46
|
+
const SKIP = '.qm-review-anchor, .qm-diag-list, .qm-row-actions';
|
|
83
47
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
padding-inline-start: var(--_qm-space-3);
|
|
95
|
-
font-size: var(--_qm-text-body);
|
|
96
|
-
}
|
|
97
|
-
.qm-review-value {
|
|
98
|
-
min-width: 0;
|
|
99
|
-
overflow-wrap: anywhere;
|
|
100
|
-
white-space: pre-wrap;
|
|
101
|
-
}
|
|
102
|
-
.qm-review-del {
|
|
103
|
-
color: var(--_qm-ink-label);
|
|
104
|
-
text-decoration: line-through;
|
|
105
|
-
text-decoration-color: var(--_qm-review-line);
|
|
106
|
-
}
|
|
107
|
-
.qm-review-ins {
|
|
108
|
-
text-decoration: none;
|
|
109
|
-
background: var(--_qm-review-tint);
|
|
110
|
-
box-shadow:
|
|
111
|
-
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-tint),
|
|
112
|
-
var(--_qm-space-half) 0 0 var(--_qm-review-tint);
|
|
113
|
-
border-radius: var(--_qm-radius-inner);
|
|
114
|
-
-webkit-box-decoration-break: clone;
|
|
115
|
-
box-decoration-break: clone;
|
|
116
|
-
transition:
|
|
117
|
-
background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
118
|
-
box-shadow var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
119
|
-
}
|
|
120
|
-
.qm-review-del + .qm-review-ins {
|
|
121
|
-
margin-inline-start: calc(var(--_qm-space) + var(--_qm-space-half));
|
|
122
|
-
}
|
|
123
|
-
.qm-review-lit .qm-review-ins {
|
|
124
|
-
background: var(--_qm-review-lit);
|
|
125
|
-
box-shadow:
|
|
126
|
-
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-lit),
|
|
127
|
-
var(--_qm-space-half) 0 0 var(--_qm-review-lit);
|
|
128
|
-
}
|
|
129
|
-
/* Forced colours drop the tint, so the proposed words take the line prose's take
|
|
130
|
-
(`codec/prose.css`). */
|
|
131
|
-
@media (forced-colors: active) {
|
|
132
|
-
.qm-review-ins {
|
|
133
|
-
text-decoration: underline;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
.qm-review-where {
|
|
137
|
-
color: var(--_qm-ink-label);
|
|
138
|
-
}
|
|
139
|
-
.qm-review-none {
|
|
140
|
-
color: var(--_qm-ink-label);
|
|
141
|
-
font-style: italic;
|
|
142
|
-
}
|
|
143
|
-
.qm-review-answers {
|
|
144
|
-
display: inline-flex;
|
|
145
|
-
flex-shrink: 0;
|
|
146
|
-
gap: var(--_qm-space-half);
|
|
147
|
-
font-size: var(--_qm-text-label);
|
|
148
|
-
font-weight: var(--_qm-weight-mid);
|
|
149
|
-
line-height: var(--_qm-leading-tight);
|
|
48
|
+
/** A control's own box: what the tint and the ring sit on, at any depth, where the control
|
|
49
|
+
* found is the cell or the row around it. */
|
|
50
|
+
const BOX = '.qm-control-box, .qm-toggle, .qm-tick';
|
|
51
|
+
|
|
52
|
+
function control(anchor: HTMLElement): HTMLElement | undefined {
|
|
53
|
+
let at = anchor.previousElementSibling;
|
|
54
|
+
while (at && at.matches(SKIP)) at = at.previousElementSibling;
|
|
55
|
+
const found = (at as HTMLElement | null) ?? anchor.parentElement ?? undefined;
|
|
56
|
+
if (!found || removes || found.matches(BOX)) return found;
|
|
57
|
+
return found.querySelector<HTMLElement>(BOX) ?? found;
|
|
150
58
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
59
|
+
|
|
60
|
+
function mark(anchor: HTMLElement) {
|
|
61
|
+
const target = control(anchor);
|
|
62
|
+
const id = item.id;
|
|
63
|
+
if (!target) return;
|
|
64
|
+
const tokens = () => (target.getAttribute('data-qm-review') ?? '').split(' ').filter(Boolean);
|
|
65
|
+
target.setAttribute('data-qm-review', [...tokens(), id].join(' '));
|
|
66
|
+
target.setAttribute('data-qm-proposed', '');
|
|
67
|
+
if (removes) target.setAttribute('data-qm-removes', '');
|
|
68
|
+
const by = (el: HTMLElement) =>
|
|
69
|
+
(el.getAttribute('aria-describedby') ?? '').split(' ').filter(Boolean);
|
|
70
|
+
const described = new Set<HTMLElement>();
|
|
71
|
+
// A control draws some of its parts after this mark is laid, a date its segments, and
|
|
72
|
+
// writes their attributes again as it renders, so each is described as it appears.
|
|
73
|
+
const describe = (): void => {
|
|
74
|
+
const parts = target.matches(FOCUSABLE)
|
|
75
|
+
? [target]
|
|
76
|
+
: target.querySelectorAll<HTMLElement>(FOCUSABLE);
|
|
77
|
+
for (const el of parts) {
|
|
78
|
+
described.add(el);
|
|
79
|
+
if (!by(el).includes(describer))
|
|
80
|
+
el.setAttribute('aria-describedby', [...by(el), describer].join(' '));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
describe();
|
|
84
|
+
const watch = new MutationObserver(describe);
|
|
85
|
+
watch.observe(target, {
|
|
86
|
+
subtree: true,
|
|
87
|
+
childList: true,
|
|
88
|
+
attributes: true,
|
|
89
|
+
attributeFilter: ['tabindex', 'aria-describedby', 'contenteditable']
|
|
90
|
+
});
|
|
91
|
+
$effect(() => {
|
|
92
|
+
const lit = reviewing.lit !== undefined && tokens().includes(reviewing.lit);
|
|
93
|
+
target.toggleAttribute('data-qm-proposed-lit', lit);
|
|
94
|
+
});
|
|
95
|
+
return () => {
|
|
96
|
+
watch.disconnect();
|
|
97
|
+
for (const el of described) {
|
|
98
|
+
const rest = by(el).filter((d) => d !== describer);
|
|
99
|
+
if (rest.length) el.setAttribute('aria-describedby', rest.join(' '));
|
|
100
|
+
else el.removeAttribute('aria-describedby');
|
|
101
|
+
}
|
|
102
|
+
const rest = tokens().filter((t) => t !== id);
|
|
103
|
+
if (rest.length) {
|
|
104
|
+
target.setAttribute('data-qm-review', rest.join(' '));
|
|
105
|
+
target.toggleAttribute('data-qm-proposed-lit', rest.includes(reviewing.lit ?? ''));
|
|
106
|
+
} else {
|
|
107
|
+
target.removeAttribute('data-qm-review');
|
|
108
|
+
target.removeAttribute('data-qm-proposed');
|
|
109
|
+
target.removeAttribute('data-qm-removes');
|
|
110
|
+
target.removeAttribute('data-qm-proposed-lit');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
155
113
|
}
|
|
156
|
-
</
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<span class="qm-review-anchor" id={describer} hidden {@attach mark}>{description}</span>
|