@quillmark/svelte 0.36.0 → 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 +18 -14
- package/THEMING.md +1 -1
- package/dist/core/codec/decode.d.ts +4 -2
- package/dist/core/codec/decode.js +5 -2
- package/dist/core/codec/field.d.ts +13 -10
- package/dist/core/codec/field.js +30 -24
- package/dist/core/codec/index.d.ts +3 -3
- package/dist/core/codec/index.js +2 -2
- package/dist/core/codec/prose.css +14 -4
- package/dist/core/codec/review.d.ts +4 -5
- package/dist/core/codec/review.js +6 -21
- package/dist/core/codec/schema.d.ts +12 -2
- package/dist/core/codec/schema.js +27 -5
- package/dist/core/codec/shortcuts.d.ts +3 -2
- package/dist/core/codec/shortcuts.js +3 -2
- package/dist/core/codec/table-view.js +15 -3
- package/dist/core/theme.css +39 -13
- 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 +190 -86
- package/dist/visual/Card.svelte +21 -11
- 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 +6 -1
- package/dist/visual/EnumField.svelte.d.ts +2 -0
- package/dist/visual/Field.svelte +3 -3
- package/dist/visual/FieldHint.svelte +19 -8
- package/dist/visual/FormatPopover.svelte +53 -20
- package/dist/visual/MatrixField.svelte +7 -3
- package/dist/visual/NumberField.svelte +21 -5
- package/dist/visual/ObjectField.svelte +6 -2
- package/dist/visual/ProseField.svelte +6 -3
- package/dist/visual/ProseField.svelte.d.ts +2 -1
- package/dist/visual/ProseValue.svelte +11 -6
- package/dist/visual/ProseValue.svelte.d.ts +4 -1
- package/dist/visual/ReviewCard.svelte +85 -32
- package/dist/visual/ReviewCard.svelte.d.ts +2 -1
- package/dist/visual/ReviewProposal.svelte +0 -6
- package/dist/visual/TipsCard.svelte +1 -1
- package/dist/visual/VariantField.svelte +1 -0
- package/dist/visual/VisualEditor.svelte +12 -6
- package/dist/visual/VisualEditor.svelte.d.ts +5 -1
- package/dist/visual/VisualEditorInner.svelte +187 -275
- package/dist/visual/VisualEditorInner.svelte.d.ts +5 -1
- package/dist/visual/controls.css +2 -2
- package/dist/visual/index.d.ts +2 -2
- package/dist/visual/proposals.d.ts +14 -4
- package/dist/visual/proposals.js +28 -5
- package/dist/visual/props.d.ts +1 -1
- package/dist/visual/review-order.d.ts +51 -0
- package/dist/visual/review-order.js +87 -0
- package/dist/visual/review.d.ts +27 -1
- package/dist/visual/review.js +1 -1
- package/dist/visual/review.svelte.d.ts +34 -17
- package/dist/visual/review.svelte.js +187 -44
- package/dist/visual/strings.d.ts +36 -19
- package/dist/visual/strings.js +80 -24
- package/dist/visual/structure.d.ts +17 -3
- package/dist/visual/structure.js +71 -5
- package/package.json +2 -2
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// formatting set. Each set is closed upstream, so the schema names its whole vocabulary.
|
|
4
4
|
// `blockSchema` is the full field; `inlineSchema` the single-textblock form for a one-line
|
|
5
5
|
// `richtext`; `plaintextSchema` that without marks, for a one-line `text`; `plainSchema` a `text`
|
|
6
|
-
// field declaring `
|
|
7
|
-
//
|
|
6
|
+
// field declaring `shape: lines` (paragraphs and hard breaks only); `linesSchema` that with marks,
|
|
7
|
+
// for a `richtext` field declaring `shape: lines`; `cellSchema` the inline form with hard breaks,
|
|
8
|
+
// for a table cell. Anchors are not marks here (decorations).
|
|
8
9
|
//
|
|
9
10
|
// `toDOM` and `parseDOM` are one tier: a copy and a paste inside one body run the whole document
|
|
10
11
|
// through them (INVARIANTS §"Markdown at the edges"), so every attribute written here is read back here.
|
|
@@ -292,7 +293,7 @@ export const cellSchema = new Schema({
|
|
|
292
293
|
marks
|
|
293
294
|
});
|
|
294
295
|
/**
|
|
295
|
-
* A `text` field declaring `
|
|
296
|
+
* A `text` field declaring `shape: lines`: paragraphs and hard breaks, no marks, islands or
|
|
296
297
|
* containers, the shape `Content::is_plain` admits. Its literal text spells a break as a `\n` and a
|
|
297
298
|
* paragraph boundary as a blank line.
|
|
298
299
|
*/
|
|
@@ -305,12 +306,33 @@ export const plainSchema = new Schema({
|
|
|
305
306
|
},
|
|
306
307
|
marks: {}
|
|
307
308
|
});
|
|
309
|
+
/**
|
|
310
|
+
* A `richtext` field declaring `shape: lines`: the plain schema with the full mark set, the shape
|
|
311
|
+
* `Content::is_lines` admits. Formatted lines with no list, heading, quote, code block or island.
|
|
312
|
+
*/
|
|
313
|
+
export const linesSchema = new Schema({
|
|
314
|
+
nodes: {
|
|
315
|
+
doc: { content: 'paragraph+' },
|
|
316
|
+
paragraph: blockNodes.paragraph,
|
|
317
|
+
text: inlineLeafNodes.text,
|
|
318
|
+
hard_break: inlineLeafNodes.hard_break
|
|
319
|
+
},
|
|
320
|
+
marks
|
|
321
|
+
});
|
|
308
322
|
/** The schema a leaf of the declared type mounts: `inline` narrows either type to one
|
|
309
|
-
* textblock,
|
|
323
|
+
* textblock, `plaintext` takes its marks away, and `paragraphs` holds a `richtext` to
|
|
324
|
+
* paragraphs and hard breaks. */
|
|
310
325
|
export function leafSchema(opts) {
|
|
311
326
|
if (opts.plaintext)
|
|
312
327
|
return opts.inline ? plaintextSchema : plainSchema;
|
|
313
|
-
|
|
328
|
+
if (opts.inline)
|
|
329
|
+
return inlineSchema;
|
|
330
|
+
return opts.paragraphs ? linesSchema : blockSchema;
|
|
331
|
+
}
|
|
332
|
+
/** True for the two schemas of paragraphs and hard breaks alone, {@link plainSchema} and
|
|
333
|
+
* {@link linesSchema}: what a leaf's literal clipboard mounts on. */
|
|
334
|
+
export function isParagraphsSchema(schema) {
|
|
335
|
+
return schema === plainSchema || schema === linesSchema;
|
|
314
336
|
}
|
|
315
337
|
/** Whether `schema` can carry formatting at all: false for the two mark-free schemas.
|
|
316
338
|
* What a mark command asks before it offers itself. */
|
|
@@ -47,10 +47,11 @@ export declare const TABLE_KEYS: {
|
|
|
47
47
|
};
|
|
48
48
|
/** The review's keys, the editor's wherever the focus is while a review is open and ahead of
|
|
49
49
|
* every other binding of them, so `accept` takes the current change over a task item's
|
|
50
|
-
* `LIST_KEYS.task
|
|
50
|
+
* `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
|
|
51
|
+
* through the changes. */
|
|
51
52
|
export declare const REVIEW_KEYS: {
|
|
52
53
|
readonly accept: "Mod-Enter";
|
|
53
|
-
readonly dismiss: "Mod
|
|
54
|
+
readonly dismiss: "Mod-Backspace";
|
|
54
55
|
readonly next: "Mod-Alt-ArrowDown";
|
|
55
56
|
readonly previous: "Mod-Alt-ArrowUp";
|
|
56
57
|
};
|
|
@@ -53,10 +53,11 @@ export const TABLE_KEYS = {
|
|
|
53
53
|
};
|
|
54
54
|
/** The review's keys, the editor's wherever the focus is while a review is open and ahead of
|
|
55
55
|
* every other binding of them, so `accept` takes the current change over a task item's
|
|
56
|
-
* `LIST_KEYS.task
|
|
56
|
+
* `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
|
|
57
|
+
* through the changes. */
|
|
57
58
|
export const REVIEW_KEYS = {
|
|
58
59
|
accept: 'Mod-Enter',
|
|
59
|
-
dismiss: 'Mod
|
|
60
|
+
dismiss: 'Mod-Backspace',
|
|
60
61
|
next: 'Mod-Alt-ArrowDown',
|
|
61
62
|
previous: 'Mod-Alt-ArrowUp'
|
|
62
63
|
};
|
|
@@ -113,12 +113,13 @@ function el(tag, className) {
|
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* A band button. It swallows its own `mousedown` (prosemirror-menu's trick) so the browser does not
|
|
116
|
-
* focus it and blur the cell whose caret the op is measured against.
|
|
116
|
+
* focus it and blur the cell whose caret the op is measured against. Its label is its accessible
|
|
117
|
+
* name and, the button drawing a glyph or nothing, its tip (`core/tooltip.ts`).
|
|
117
118
|
*/
|
|
118
119
|
function chromeButton(className, label, run) {
|
|
119
120
|
const btn = el('button', className);
|
|
120
121
|
btn.type = 'button';
|
|
121
|
-
btn.
|
|
122
|
+
btn.setAttribute('data-qm-tip', label);
|
|
122
123
|
btn.setAttribute('aria-label', label);
|
|
123
124
|
btn.addEventListener('mousedown', (e) => e.preventDefault());
|
|
124
125
|
btn.addEventListener('click', (e) => {
|
|
@@ -1376,6 +1377,7 @@ class TableIslandView {
|
|
|
1376
1377
|
const cluster = el('div', 'qm-table-align');
|
|
1377
1378
|
cluster.setAttribute('role', 'group');
|
|
1378
1379
|
cluster.setAttribute('aria-label', s.tableColumn(c + 1));
|
|
1380
|
+
cluster.setAttribute('data-qm-tip-side', 'bottom');
|
|
1379
1381
|
cluster.hidden = true;
|
|
1380
1382
|
// The cluster's own edge is no button, and a press on it would otherwise take the
|
|
1381
1383
|
// focus off the caret the write lands back on.
|
|
@@ -1403,6 +1405,7 @@ class TableIslandView {
|
|
|
1403
1405
|
headerToggle(header, s) {
|
|
1404
1406
|
const cluster = el('div', 'qm-table-align');
|
|
1405
1407
|
cluster.setAttribute('data-header', '');
|
|
1408
|
+
cluster.setAttribute('data-qm-tip-side', 'bottom');
|
|
1406
1409
|
cluster.hidden = true;
|
|
1407
1410
|
cluster.addEventListener('mousedown', (e) => e.preventDefault());
|
|
1408
1411
|
const btn = chromeButton('qm-table-align-option', s.tableHeaderToggle, () => {
|
|
@@ -1433,6 +1436,8 @@ class TableIslandView {
|
|
|
1433
1436
|
const btn = chromeButton('qm-table-cells-option', label, run);
|
|
1434
1437
|
btn.tabIndex = -1;
|
|
1435
1438
|
btn.textContent = label;
|
|
1439
|
+
// The label is drawn, and a tip would say it twice.
|
|
1440
|
+
btn.removeAttribute('data-qm-tip');
|
|
1436
1441
|
cluster.appendChild(btn);
|
|
1437
1442
|
}
|
|
1438
1443
|
return cluster;
|
|
@@ -1453,6 +1458,8 @@ class TableIslandView {
|
|
|
1453
1458
|
this.write(insertColumn(props, columnCount(props) - 1), { r: 0, c: columnCount(props) });
|
|
1454
1459
|
});
|
|
1455
1460
|
btn.setAttribute('data-axis', axis);
|
|
1461
|
+
if (axis === 'row')
|
|
1462
|
+
btn.setAttribute('data-qm-tip-side', 'bottom');
|
|
1456
1463
|
btn.tabIndex = -1;
|
|
1457
1464
|
btn.appendChild(el('span', 'qm-table-add-bar'));
|
|
1458
1465
|
return btn;
|
|
@@ -1468,7 +1475,12 @@ class TableIslandView {
|
|
|
1468
1475
|
doc: decode(cellContent(seed), cellSchema),
|
|
1469
1476
|
plugins: cellPlugins(this.cellKeys(r, c), () => this.outer)
|
|
1470
1477
|
}),
|
|
1471
|
-
attributes: {
|
|
1478
|
+
attributes: {
|
|
1479
|
+
role: 'textbox',
|
|
1480
|
+
'aria-multiline': 'true',
|
|
1481
|
+
'aria-label': name,
|
|
1482
|
+
class: 'qm-table-cell-editor'
|
|
1483
|
+
},
|
|
1472
1484
|
// A cell is one of the leaf's lines, so a reveal keeps the leaf's clearance, not PM's
|
|
1473
1485
|
// 5px default, and the same scroll padding (`reveal.ts`).
|
|
1474
1486
|
...revealProps(this.deps.clearance),
|
package/dist/core/theme.css
CHANGED
|
@@ -198,6 +198,17 @@
|
|
|
198
198
|
--_qm-ink: var(--_qm-fg);
|
|
199
199
|
--_qm-ink-default: color-mix(in oklab, var(--_qm-fg), var(--_qm-bg) 20%);
|
|
200
200
|
--_qm-ink-label: color-mix(in oklab, var(--_qm-fg), var(--_qm-bg) 35%);
|
|
201
|
+
/* `label` over a floating surface. `raised` lifts the plane off the card while the rung
|
|
202
|
+
stays where the card put it, so it stands that much nearer the plane: under 4.5:1 on
|
|
203
|
+
the dark default. Here the rung lifts by the plane's own step and keeps over `raised`
|
|
204
|
+
the distance it keeps over the card. The card's share of the mix is 35%, so the card
|
|
205
|
+
going 23% toward white under it moves the rung the 8% `raised` moves. No step over a
|
|
206
|
+
white card, where `raised` takes none. */
|
|
207
|
+
--_qm-ink-label-raised: color-mix(
|
|
208
|
+
in oklab,
|
|
209
|
+
var(--_qm-fg),
|
|
210
|
+
color-mix(in oklab, var(--_qm-bg), #fff 23%) 35%
|
|
211
|
+
);
|
|
201
212
|
/* The arrival wash (`core/bloom.ts`). Its alpha is a peak, not a tint: the
|
|
202
213
|
wash animates from and back to zero, never held, so it reads over the leaf it
|
|
203
214
|
lands on while the leaf rests clean. */
|
|
@@ -327,8 +338,9 @@
|
|
|
327
338
|
control resting at nothing reads as arriving rather than as switching. */
|
|
328
339
|
--_qm-reveal: 500ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
329
340
|
/* A wait rather than a trip: how long a caret rests on an empty line before the
|
|
330
|
-
slash hint comes up
|
|
331
|
-
|
|
341
|
+
slash hint comes up, and a pointer on a glyph control before its tip does
|
|
342
|
+
(`core/tooltip.ts`). Longer than the gap between two keystrokes, so typing on
|
|
343
|
+
through an Enter never draws it, and than a pointer takes to cross a control. */
|
|
332
344
|
--_qm-hint-wait: 500ms;
|
|
333
345
|
|
|
334
346
|
/* ── Geometry ──────────────────────────────────────────────────────────*/
|
|
@@ -414,18 +426,17 @@
|
|
|
414
426
|
`vector-effect: non-scaling-stroke`, so every glyph strokes at one weight. */
|
|
415
427
|
--_qm-glyph-stroke: calc(var(--_qm-glyph-control) / 12);
|
|
416
428
|
/* The narrowest track a control that fills its width stays usable in: a table's
|
|
417
|
-
column floors at it,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
(`
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
name it and no label of its own to fit. A threshold rather than a rhythm choice,
|
|
424
|
-
so it does not move with `--qm-space`. */
|
|
429
|
+
column floors at it, and a row of them scrolls sideways rather than crushing a
|
|
430
|
+
cell. A column drawing a mark takes no floor — a switch is one width at every
|
|
431
|
+
width, so there is no width for it to be usable in (`ArrayField`). Under the field
|
|
432
|
+
minimum the capacity ladder steps at (`.qm-tracks`), since a cell in a row has the
|
|
433
|
+
header to name it and no label of its own to fit. A threshold rather than a rhythm
|
|
434
|
+
choice, so it does not move with `--qm-space`. */
|
|
425
435
|
--_qm-track-min: 7rem;
|
|
426
|
-
/* A prose column's floor: its cell wraps, and at
|
|
427
|
-
word, standing the row many lines tall beside cells
|
|
428
|
-
|
|
436
|
+
/* A prose column's floor while the field has the width: its cell wraps, and at
|
|
437
|
+
`--_qm-track-min` a line holds a word, standing the row many lines tall beside cells
|
|
438
|
+
one line tall. Short of the width it gives way down to `--_qm-track-min` before the
|
|
439
|
+
table scrolls (`ArrayField`). A multiple of the floor, so the two move together. */
|
|
429
440
|
--_qm-track-prose: calc(var(--_qm-track-min) * 2);
|
|
430
441
|
|
|
431
442
|
/* ── Type ────────────────────────────────────────────────────────────────
|
|
@@ -512,6 +523,21 @@
|
|
|
512
523
|
line-height: var(--_qm-leading-body);
|
|
513
524
|
}
|
|
514
525
|
|
|
526
|
+
/* A floating surface holds the label rung against its own plane, so what it carries at
|
|
527
|
+
that rung — a row's shortcut, a tag, a note, a quiet answer — reads over it as it does
|
|
528
|
+
over a card, and no component on one has to know where it stands. Stated here and not
|
|
529
|
+
in the recipes (`visual/controls.css`): a floating surface is mostly a root itself, so
|
|
530
|
+
a declaration from another sheet would tie with the rule above and leave the rung to
|
|
531
|
+
the order a bundler emits the two in. */
|
|
532
|
+
:where(.qm-menu-surface, .qm-popover-surface) {
|
|
533
|
+
--_qm-ink-label: var(--_qm-ink-label-raised);
|
|
534
|
+
}
|
|
535
|
+
/* A menu's cursor fills its row, which takes that distance back, so under it the rung
|
|
536
|
+
steps to the ink: the ladder a chip takes under the pointer (`visual/controls.css`). */
|
|
537
|
+
:where(.qm-menu-item[data-highlighted]) {
|
|
538
|
+
--_qm-ink-label: var(--_qm-ink);
|
|
539
|
+
}
|
|
540
|
+
|
|
515
541
|
/* More contrast steps the two rungs that identify a control rather than a list of
|
|
516
542
|
selectors: the well's edge to 3:1 against the card at both poles (WCAG 1.4.11),
|
|
517
543
|
which half the ink over the well clears, and the ring a pixel wider. */
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* The tip a glyph control raises (`core/tooltip.ts`), which imports this sheet, so the
|
|
2
|
+
editor's chrome and a leaf mounted on its own draw the same one.
|
|
3
|
+
|
|
4
|
+
A floating surface, so it takes the stroke and the lift a surface with no plane under
|
|
5
|
+
it stands on (INVARIANTS §Styling), on the raised rung and opaque: it is a word or two
|
|
6
|
+
over glyphs, and nothing behind it is worth reading through. One rung in from a
|
|
7
|
+
control's own corner and at the label size, so it reads as a note on a control and
|
|
8
|
+
never as one more control.
|
|
9
|
+
|
|
10
|
+
Placed in the root it is appended to, over every other floating surface, the format
|
|
11
|
+
bar and the table island's clusters being where half its controls stand. It takes no
|
|
12
|
+
pointer: a tip between the pointer and the next control would be a tip in the way.
|
|
13
|
+
|
|
14
|
+
It arrives by a fade and leaves at once. A scale would move a surface this small more
|
|
15
|
+
than it shows it, and a tip is lowered by the press or the key that makes it stale. A
|
|
16
|
+
tip that follows another along a row of controls does not arrive again. */
|
|
17
|
+
:where(.qm-tip) {
|
|
18
|
+
position: absolute;
|
|
19
|
+
z-index: 4;
|
|
20
|
+
display: flex;
|
|
21
|
+
gap: var(--_qm-space-2);
|
|
22
|
+
width: max-content;
|
|
23
|
+
padding: var(--_qm-space-half) var(--_qm-space-2);
|
|
24
|
+
border: var(--_qm-border-width) solid var(--_qm-border);
|
|
25
|
+
border-radius: var(--_qm-radius-inner);
|
|
26
|
+
background: var(--_qm-surface-raised);
|
|
27
|
+
box-shadow: var(--_qm-lift);
|
|
28
|
+
font-family: var(--_qm-font);
|
|
29
|
+
font-size: var(--_qm-text-label);
|
|
30
|
+
line-height: var(--_qm-leading-tight);
|
|
31
|
+
color: var(--_qm-ink);
|
|
32
|
+
white-space: nowrap;
|
|
33
|
+
pointer-events: none;
|
|
34
|
+
user-select: none;
|
|
35
|
+
}
|
|
36
|
+
:where(.qm-tip[data-arriving]) {
|
|
37
|
+
animation: qm-tip-in var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
38
|
+
}
|
|
39
|
+
/* The shortcut, a step off the name it follows: the name is what the control is, the
|
|
40
|
+
keys a way to it. */
|
|
41
|
+
:where(.qm-tip kbd) {
|
|
42
|
+
font: inherit;
|
|
43
|
+
color: var(--_qm-ink-label-raised);
|
|
44
|
+
}
|
|
45
|
+
@keyframes qm-tip-in {
|
|
46
|
+
from {
|
|
47
|
+
opacity: 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serve the tips of every control under `root`, the `[data-qm-root]` a tip is appended to and
|
|
3
|
+
* kept inside. One install per root however many callers ask; the returned function releases this
|
|
4
|
+
* caller's.
|
|
5
|
+
*/
|
|
6
|
+
export declare function tooltips(root: HTMLElement): () => void;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// The name of a control that draws only a glyph, raised beside it: one surface per root, where the
|
|
2
|
+
// native `title` reaches no dial, waits a second, answers a pointer alone and cannot be dismissed.
|
|
3
|
+
//
|
|
4
|
+
// A control opts in by attribute rather than by a wrapper, so chrome built without a framework
|
|
5
|
+
// (the table island's) and chrome built with one are served by the same listeners on the root
|
|
6
|
+
// they stand in, and a control costs no listener of its own:
|
|
7
|
+
//
|
|
8
|
+
// data-qm-tip the control's name
|
|
9
|
+
// data-qm-tip-keys its shortcut, as the platform prints it
|
|
10
|
+
// data-qm-tip-side on the control or an ancestor: the box the tip stands clear of, and
|
|
11
|
+
// `bottom` to stand under it. A floating row of controls names itself here,
|
|
12
|
+
// so its tips fall on the side away from what the row is about.
|
|
13
|
+
//
|
|
14
|
+
// The tip is decoration for a reader who can see it. It is `aria-hidden` and nothing points at it:
|
|
15
|
+
// the control's `aria-label` is its name and `aria-keyshortcuts` its shortcut. It takes no pointer
|
|
16
|
+
// and holds nothing to press.
|
|
17
|
+
//
|
|
18
|
+
// It comes up once the pointer has rested on the control (`--_qm-hint-wait`), at once under
|
|
19
|
+
// keyboard focus, and at once and without its fade on the control after one that just showed its
|
|
20
|
+
// own, so a tip carried along a row of glyphs reads as one tip moving. A press, a key or
|
|
21
|
+
// a scroll lowers it until the pointer or the focus comes back to the control: each can move the
|
|
22
|
+
// control, and the tip is placed once, from where the control stood.
|
|
23
|
+
import { rungMs, rungStyle, spacePx } from './rungs.js';
|
|
24
|
+
import './tooltip.css';
|
|
25
|
+
const TIP = 'data-qm-tip';
|
|
26
|
+
const KEYS = 'data-qm-tip-keys';
|
|
27
|
+
const SIDE = 'data-qm-tip-side';
|
|
28
|
+
const installed = new WeakMap();
|
|
29
|
+
/**
|
|
30
|
+
* Serve the tips of every control under `root`, the `[data-qm-root]` a tip is appended to and
|
|
31
|
+
* kept inside. One install per root however many callers ask; the returned function releases this
|
|
32
|
+
* caller's.
|
|
33
|
+
*/
|
|
34
|
+
export function tooltips(root) {
|
|
35
|
+
let entry = installed.get(root);
|
|
36
|
+
if (!entry)
|
|
37
|
+
installed.set(root, (entry = { users: 0, remove: install(root) }));
|
|
38
|
+
entry.users++;
|
|
39
|
+
const held = entry;
|
|
40
|
+
let released = false;
|
|
41
|
+
return () => {
|
|
42
|
+
if (released)
|
|
43
|
+
return;
|
|
44
|
+
released = true;
|
|
45
|
+
if (--held.users > 0)
|
|
46
|
+
return;
|
|
47
|
+
held.remove();
|
|
48
|
+
installed.delete(root);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const clamp = (n, min, max) => Math.max(min, Math.min(max, n));
|
|
52
|
+
function install(root) {
|
|
53
|
+
const doc = root.ownerDocument;
|
|
54
|
+
const tip = doc.createElement('div');
|
|
55
|
+
tip.className = 'qm-tip';
|
|
56
|
+
tip.setAttribute('aria-hidden', 'true');
|
|
57
|
+
/** The control the pointer or the focus is on, whether or not its tip is up. */
|
|
58
|
+
let anchor;
|
|
59
|
+
let by = 'pointer';
|
|
60
|
+
let pending;
|
|
61
|
+
/** Until when the next control's tip skips the wait: a reader moving along a row of
|
|
62
|
+
* glyphs is reading them, not resting. */
|
|
63
|
+
let warm = 0;
|
|
64
|
+
const wait = () => rungMs(rungStyle(root), '--_qm-hint-wait') ?? 0;
|
|
65
|
+
function place(control) {
|
|
66
|
+
const holder = control.closest(`[${SIDE}]`) ?? control;
|
|
67
|
+
const across = control.getBoundingClientRect();
|
|
68
|
+
const along = holder.getBoundingClientRect();
|
|
69
|
+
const frame = root.getBoundingClientRect();
|
|
70
|
+
// The root is positioned wherever the editor mounts it; a leaf mounted on its own may
|
|
71
|
+
// stand in one that is not, and the tip is then placed in whatever is.
|
|
72
|
+
const origin = tip.offsetParent ?? root;
|
|
73
|
+
const from = origin.getBoundingClientRect();
|
|
74
|
+
const view = doc.defaultView;
|
|
75
|
+
const top = Math.max(frame.top, 0);
|
|
76
|
+
const bottom = Math.min(frame.bottom, view?.innerHeight ?? frame.bottom);
|
|
77
|
+
const left = Math.max(frame.left, 0);
|
|
78
|
+
const right = Math.min(frame.right, view?.innerWidth ?? frame.right);
|
|
79
|
+
const gap = spacePx(root) ?? 0;
|
|
80
|
+
const w = tip.offsetWidth;
|
|
81
|
+
const h = tip.offsetHeight;
|
|
82
|
+
const over = along.top - gap - h;
|
|
83
|
+
const under = along.bottom + gap;
|
|
84
|
+
const overFits = over >= top;
|
|
85
|
+
const underFits = under + h <= bottom;
|
|
86
|
+
const below = holder.getAttribute(SIDE) === 'bottom' ? underFits || !overFits : !overFits && underFits;
|
|
87
|
+
const x = clamp(across.left + (across.width - w) / 2, left + gap, right - gap - w);
|
|
88
|
+
const y = clamp(below ? under : over, top, bottom - h);
|
|
89
|
+
tip.style.left = `${x - from.left - origin.clientLeft + origin.scrollLeft}px`;
|
|
90
|
+
tip.style.top = `${y - from.top - origin.clientTop + origin.scrollTop}px`;
|
|
91
|
+
}
|
|
92
|
+
function raise(control, arriving = true) {
|
|
93
|
+
pending = undefined;
|
|
94
|
+
const name = control.getAttribute(TIP);
|
|
95
|
+
if (!name || !control.isConnected)
|
|
96
|
+
return;
|
|
97
|
+
const keys = control.getAttribute(KEYS);
|
|
98
|
+
tip.replaceChildren(name);
|
|
99
|
+
if (keys) {
|
|
100
|
+
const cap = doc.createElement('kbd');
|
|
101
|
+
cap.textContent = keys;
|
|
102
|
+
tip.appendChild(cap);
|
|
103
|
+
}
|
|
104
|
+
tip.toggleAttribute('data-arriving', arriving);
|
|
105
|
+
root.appendChild(tip);
|
|
106
|
+
place(control);
|
|
107
|
+
}
|
|
108
|
+
/** Take the tip down, the control still the one attended to, so it stays down. */
|
|
109
|
+
function lower() {
|
|
110
|
+
clearTimeout(pending);
|
|
111
|
+
pending = undefined;
|
|
112
|
+
if (tip.isConnected)
|
|
113
|
+
warm = performance.now() + wait();
|
|
114
|
+
tip.remove();
|
|
115
|
+
doc.removeEventListener('scroll', lower, true);
|
|
116
|
+
doc.removeEventListener('keydown', lower, true);
|
|
117
|
+
}
|
|
118
|
+
function leave() {
|
|
119
|
+
lower();
|
|
120
|
+
anchor = undefined;
|
|
121
|
+
}
|
|
122
|
+
function attend(control, from) {
|
|
123
|
+
leave();
|
|
124
|
+
anchor = control;
|
|
125
|
+
by = from;
|
|
126
|
+
doc.addEventListener('scroll', lower, { capture: true, passive: true });
|
|
127
|
+
doc.addEventListener('keydown', lower, true);
|
|
128
|
+
if (performance.now() < warm)
|
|
129
|
+
raise(control, false);
|
|
130
|
+
else if (from === 'focus')
|
|
131
|
+
raise(control);
|
|
132
|
+
else
|
|
133
|
+
pending = setTimeout(() => raise(control), wait());
|
|
134
|
+
}
|
|
135
|
+
const tipped = (target) => (target instanceof Element && target.closest(`[${TIP}]`)) || undefined;
|
|
136
|
+
function onOver(e) {
|
|
137
|
+
if (e.pointerType === 'touch')
|
|
138
|
+
return;
|
|
139
|
+
const control = tipped(e.target);
|
|
140
|
+
if (control === anchor)
|
|
141
|
+
return;
|
|
142
|
+
if (control)
|
|
143
|
+
attend(control, 'pointer');
|
|
144
|
+
else if (by === 'pointer')
|
|
145
|
+
leave();
|
|
146
|
+
}
|
|
147
|
+
function onOut(e) {
|
|
148
|
+
if (by !== 'pointer' || !anchor)
|
|
149
|
+
return;
|
|
150
|
+
if (e.relatedTarget instanceof Node && anchor.contains(e.relatedTarget))
|
|
151
|
+
return;
|
|
152
|
+
leave();
|
|
153
|
+
}
|
|
154
|
+
function onFocusIn(e) {
|
|
155
|
+
const control = tipped(e.target);
|
|
156
|
+
if (control && control.matches(':focus-visible'))
|
|
157
|
+
attend(control, 'focus');
|
|
158
|
+
}
|
|
159
|
+
function onFocusOut() {
|
|
160
|
+
if (by === 'focus')
|
|
161
|
+
leave();
|
|
162
|
+
}
|
|
163
|
+
root.addEventListener('pointerover', onOver);
|
|
164
|
+
root.addEventListener('pointerout', onOut);
|
|
165
|
+
root.addEventListener('pointerdown', lower, true);
|
|
166
|
+
root.addEventListener('focusin', onFocusIn);
|
|
167
|
+
root.addEventListener('focusout', onFocusOut);
|
|
168
|
+
return () => {
|
|
169
|
+
leave();
|
|
170
|
+
root.removeEventListener('pointerover', onOver);
|
|
171
|
+
root.removeEventListener('pointerout', onOut);
|
|
172
|
+
root.removeEventListener('pointerdown', lower, true);
|
|
173
|
+
root.removeEventListener('focusin', onFocusIn);
|
|
174
|
+
root.removeEventListener('focusout', onFocusOut);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
@@ -129,6 +129,27 @@
|
|
|
129
129
|
padding: var(--_qm-space-4);
|
|
130
130
|
background: var(--_qm-surface-sunken);
|
|
131
131
|
}
|
|
132
|
+
/* Inset, so the scrollport does not clip it. */
|
|
133
|
+
:global(:where(.qm-preview:focus-visible)) {
|
|
134
|
+
outline: var(--_qm-ring);
|
|
135
|
+
outline-offset: calc(-1 * var(--_qm-ring-reach));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* The message in place of the pages (controller.ts): words about the pane, at the chrome's
|
|
139
|
+
label size, where a page would stand. */
|
|
140
|
+
:global(:where(.qm-preview-message)) {
|
|
141
|
+
padding: var(--_qm-space-5) var(--_qm-space-4);
|
|
142
|
+
font-family: var(--_qm-font);
|
|
143
|
+
font-size: var(--_qm-text-label);
|
|
144
|
+
line-height: var(--_qm-leading-body);
|
|
145
|
+
text-align: center;
|
|
146
|
+
}
|
|
147
|
+
:global(:where(.qm-preview-empty)) {
|
|
148
|
+
color: var(--_qm-ink-label);
|
|
149
|
+
}
|
|
150
|
+
:global(:where(.qm-preview-error)) {
|
|
151
|
+
color: var(--_qm-danger);
|
|
152
|
+
}
|
|
132
153
|
|
|
133
154
|
/* The arrival wash on the page (`wash.ts`): a plane at a field's box, its tone the editor's,
|
|
134
155
|
reaching a hair past the ink's tight box and rounded, as a control's wash is a box's own. Over
|
|
@@ -175,7 +196,7 @@
|
|
|
175
196
|
background: var(--_qm-surface-popover);
|
|
176
197
|
backdrop-filter: blur(var(--_qm-blur));
|
|
177
198
|
box-shadow: var(--_qm-lift);
|
|
178
|
-
color: var(--_qm-ink-label);
|
|
199
|
+
color: var(--_qm-ink-label-raised);
|
|
179
200
|
font-family: var(--_qm-font);
|
|
180
201
|
font-size: var(--_qm-text-label);
|
|
181
202
|
font-variant-numeric: tabular-nums;
|
|
@@ -8,6 +8,10 @@ const CONTAINER_CLASS = 'qm-preview';
|
|
|
8
8
|
const MESSAGE_CLASS = 'qm-preview-message';
|
|
9
9
|
const EMPTY_CLASS = 'qm-preview-empty';
|
|
10
10
|
const ERROR_CLASS = 'qm-preview-error';
|
|
11
|
+
const LIVE_CLASS = 'qm-preview-live';
|
|
12
|
+
/** How long the pane's state holds before it is spoken: a recompile over a page that still fails
|
|
13
|
+
* clears the message and raises it again, and that is no change to hear. */
|
|
14
|
+
const SPOKEN_MS = 500;
|
|
11
15
|
export function createPreview(session, opts) {
|
|
12
16
|
const container = opts.container;
|
|
13
17
|
const margin = opts.margin ?? 1;
|
|
@@ -21,6 +25,36 @@ export function createPreview(session, opts) {
|
|
|
21
25
|
container.setAttribute('role', 'region');
|
|
22
26
|
if (ownsName)
|
|
23
27
|
container.setAttribute('aria-label', t.previewLabel);
|
|
28
|
+
// What a screen reader hears of the message below. The region stands empty from the mount,
|
|
29
|
+
// since one inserted with its text already in it may not be heard, and takes the message once
|
|
30
|
+
// it has held still. Pages standing again are said only after a message was, and the state a
|
|
31
|
+
// mount starts from is not a change, so a fresh seed's empty pane says nothing. Hidden by its
|
|
32
|
+
// own style rather than a sheet's, as a slot is drawn (`paint.ts`), so it leaves no ink where
|
|
33
|
+
// no sheet reaches it (INVARIANTS §"The preview").
|
|
34
|
+
const live = document.createElement('div');
|
|
35
|
+
live.className = LIVE_CLASS;
|
|
36
|
+
live.setAttribute('role', 'status');
|
|
37
|
+
Object.assign(live.style, {
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
width: '1px',
|
|
40
|
+
height: '1px',
|
|
41
|
+
overflow: 'hidden',
|
|
42
|
+
clipPath: 'inset(50%)',
|
|
43
|
+
whiteSpace: 'nowrap'
|
|
44
|
+
});
|
|
45
|
+
container.appendChild(live);
|
|
46
|
+
let heard = session.pageCount === 0 ? t.noPages : '';
|
|
47
|
+
let settling;
|
|
48
|
+
function settle() {
|
|
49
|
+
clearTimeout(settling);
|
|
50
|
+
settling = setTimeout(() => {
|
|
51
|
+
const shown = message?.textContent ?? '';
|
|
52
|
+
if (shown === heard)
|
|
53
|
+
return;
|
|
54
|
+
heard = shown;
|
|
55
|
+
live.textContent = shown || (live.textContent ? t.restored : '');
|
|
56
|
+
}, SPOKEN_MS);
|
|
57
|
+
}
|
|
24
58
|
// One element, restamped: the message states are mutually exclusive.
|
|
25
59
|
let message;
|
|
26
60
|
function showMessage(text, state) {
|
|
@@ -30,10 +64,12 @@ export function createPreview(session, opts) {
|
|
|
30
64
|
}
|
|
31
65
|
message.className = `${MESSAGE_CLASS} ${state}`;
|
|
32
66
|
message.textContent = text;
|
|
67
|
+
settle();
|
|
33
68
|
}
|
|
34
69
|
function hideMessage() {
|
|
35
70
|
message?.remove();
|
|
36
71
|
message = undefined;
|
|
72
|
+
settle();
|
|
37
73
|
}
|
|
38
74
|
// A paint that throws is caught per slot and surfaced through the message rather than aborting
|
|
39
75
|
// the observer callback mid-sweep.
|
|
@@ -123,6 +159,8 @@ export function createPreview(session, opts) {
|
|
|
123
159
|
viewport.destroy();
|
|
124
160
|
paintLoop.destroy();
|
|
125
161
|
hideMessage();
|
|
162
|
+
clearTimeout(settling);
|
|
163
|
+
live.remove();
|
|
126
164
|
container.classList.remove(CONTAINER_CLASS);
|
|
127
165
|
if (ownsRole)
|
|
128
166
|
container.removeAttribute('role');
|
|
@@ -3,6 +3,8 @@ export interface PreviewStrings {
|
|
|
3
3
|
renderFailed: string;
|
|
4
4
|
/** A compile with zero pages: recoverable, and the commonest state of a fresh seed. */
|
|
5
5
|
noPages: string;
|
|
6
|
+
/** What a screen reader hears when pages stand again after it heard either of the two. */
|
|
7
|
+
restored: string;
|
|
6
8
|
/** The zoom pill's action, after the percentage it shows. */
|
|
7
9
|
resetZoom: string;
|
|
8
10
|
/** The pane's accessible name, where the container carries none of its own. */
|
package/dist/preview/strings.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
export const DEFAULT_PREVIEW_STRINGS = {
|
|
4
4
|
renderFailed: 'Preview failed to render.',
|
|
5
5
|
noPages: 'No pages to preview.',
|
|
6
|
+
restored: 'Preview restored.',
|
|
6
7
|
resetZoom: 'reset zoom',
|
|
7
8
|
previewLabel: 'Document preview',
|
|
8
9
|
pageLabel: (page, count) => `Page ${page} of ${count}`
|