@quillmark/svelte 0.39.1 → 0.41.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 CHANGED
@@ -231,7 +231,7 @@ The verbs complete it. `answerReview(ids | 'all' | { group }, 'accept' | 'dismis
231
231
 
232
232
  The **answer card** floats on the current item, below the paragraph or block it stands in, beside that paragraph's last line where the line ends short of it, centred on the line of a one-line field so it stands inside the field rather than over the next field's label, or above it where there is no room, so it covers none of the item's own paragraph, with **Dismiss** and **Accept** and their keys, and the item's `note` above them on one line. It scrolls with the item and is clipped at the pane's edge as the text is. It keeps clear of `reviewInset`, the px the host's chrome takes at the foot of the pane, while the item shows, steps aside while the reader types, and never takes the focus: a press on it leaves the focus where it was, and Alt+F10 puts the keyboard on it, Escape handing the focus back. Under a finger, or on a screen with no hover, it drops the key hints and its buttons are tap-sized.
233
233
 
234
- While a review is open, `REVIEW_KEYS` answer the current item from anywhere on the page but another editor or a text box outside this one: ⌘/Ctrl+Enter accepts it, ⌘/Ctrl+Backspace dismisses it, and ⌘/Ctrl+⌥/Alt+↓ and ↑ step to the next and previous item, moving the caret along when pressed in the editor. The two answer keys are the card's, so they answer an item the card stands on in view: with the item scrolled out of the pane the first press brings it back and the next answers it, and while the reader types in the editor, where the card steps aside, both stay the leaf's own keys. A proposal that only adds blocks is current from anywhere in the paragraph it adds after; where a proposal also rewrites that paragraph, the caret names the rewrite, and `revealReview(id, { focus: true })` puts it in the one asked for. Every word the review draws is a `strings` key, and its one hue is `--qm-review` ([THEMING.md](THEMING.md)).
234
+ While a review is open, `REVIEW_KEYS` answer the current item from anywhere on the page but another editor or a text box outside this one: ⌘/Ctrl+Enter accepts it, ⌘/Ctrl+⌥/Alt+Backspace dismisses it, and ⌘/Ctrl+⌥/Alt+↓ and ↑ step to the next and previous item, moving the caret along when pressed in the editor. The two answer keys are the card's, so they answer an item the card stands on in view: with the item scrolled out of the pane, or the card aside while the reader types, the first press brings it back and the next answers it. No leaf binds a review key: ⌘/Ctrl+Enter is the review's alone, and Alt+Enter ticks a task item, takes a sibling from a list element of several lines and leaves a code block. A proposal that only adds blocks is current from anywhere in the paragraph it adds after; where a proposal also rewrites that paragraph, the caret names the rewrite, and `revealReview(id, { focus: true })` puts it in the one asked for. Every word the review draws is a `strings` key, and its one hue is `--qm-review` ([THEMING.md](THEMING.md)).
235
235
 
236
236
  ### Wording
237
237
 
@@ -8,7 +8,6 @@
8
8
  // A throw keeps the optimistic PM state and reports through `onError`.
9
9
  // An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
10
10
  // hold it re-evaluates flips.
11
- import { baseKeymap } from 'prosemirror-commands';
12
11
  import { gapCursor } from 'prosemirror-gapcursor';
13
12
  import { history, isHistoryTransaction, redo, undo } from 'prosemirror-history';
14
13
  import { keymap } from 'prosemirror-keymap';
@@ -30,7 +29,7 @@ import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
30
29
  import { linebreakPlugin } from './breaks.js';
31
30
  import { bodyKeymap, holdsTab } from './keymap.js';
32
31
  import { DEFAULT_LEAVE_STRINGS, leavePlugin } from './leave.js';
33
- import { FIELD_KEYS, markKeymap } from './shortcuts.js';
32
+ import { FIELD_KEYS, leafBaseKeymap, markKeymap } from './shortcuts.js';
34
33
  import { remoteKey } from './remote.js';
35
34
  import { renameBlocks, reviewLayer } from './review.js';
36
35
  import { valueDiffPlugin, valueSpans } from './value-diff.js';
@@ -911,7 +910,7 @@ export function proseLeafPlugins(schema, opts) {
911
910
  if (!opts.noInputRules)
912
911
  list.push(inputRulesPlugin(schema), undoRuleKeymap());
913
912
  list.push(keymap(editorKeymap(schema, opts.inline, !!opts.slash)));
914
- list.push(keymap(baseKeymap));
913
+ list.push(keymap(leafBaseKeymap));
915
914
  if (schema.marks.link)
916
915
  list.push(linkPastePlugin(schema.marks.link));
917
916
  list.push(dragMovePlugin());
@@ -8,11 +8,11 @@ import type { Command } from 'prosemirror-state';
8
8
  * prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
9
9
  * line alone into a sub-list, any other line its whole item, and a block right after a list into
10
10
  * the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
11
- * `Mod-Enter` ticks the task item around the caret (`toggleTask`).
11
+ * `LIST_KEYS.task` ticks the task item around the caret (`toggleTask`).
12
12
  *
13
13
  * `Enter` is a chain in precedence order: the empty line above an unnumbered one, an empty top-level
14
14
  * middle item out of the list, the marker back on an empty continuation line, `splitListItem` (`splitTaskItem` for
15
- * tasks), then `liftListItem`. The split link splits a non-empty item, and on an empty last item
15
+ * tasks, `paragraphAbove` over a heading), then `liftListItem`. The split link splits a non-empty item, and on an empty last item
16
16
  * either splits the wrapping item (a nested one, so Enter lifts one level) or bails so the last
17
17
  * link lifts a top-level one to a paragraph.
18
18
  *
@@ -72,6 +72,35 @@ function lineAbove(itemType, paragraph) {
72
72
  return true;
73
73
  };
74
74
  }
75
+ /**
76
+ * Enter at the head of an item's first line that holds text and is no paragraph, a heading → the
77
+ * item `split` opens above it holds an empty paragraph, as `splitBlock` leaves one above a heading
78
+ * outside a list. `splitListItem` gives the new item the line's own type.
79
+ */
80
+ function paragraphAbove(itemType, paragraph, split) {
81
+ return (state, dispatch, view) => {
82
+ const { $from, empty } = state.selection;
83
+ const line = $from.parent;
84
+ if (!dispatch ||
85
+ !empty ||
86
+ $from.parentOffset !== 0 ||
87
+ $from.depth < 2 ||
88
+ line.type === paragraph ||
89
+ line.type.spec.code ||
90
+ line.content.size === 0 ||
91
+ $from.node(-1).type !== itemType ||
92
+ $from.index(-1) !== 0)
93
+ return split(state, dispatch, view);
94
+ return split(state, (tr) => {
95
+ const $at = tr.selection.$from;
96
+ const below = $at.before($at.depth - 1);
97
+ const above = tr.doc.resolve(below).nodeBefore;
98
+ if (above?.type === itemType)
99
+ tr.setBlockType(below - above.nodeSize, below, paragraph);
100
+ dispatch(tr);
101
+ }, view);
102
+ };
103
+ }
75
104
  /** Whether `item` holds nothing but one empty textblock. */
76
105
  function emptyItem(item) {
77
106
  return (item.childCount === 1 && !!item.firstChild?.isTextblock && item.firstChild.content.size === 0);
@@ -477,11 +506,11 @@ function sinkIntoList(itemType) {
477
506
  * prepend a link in `keymap.ts` (INVARIANTS §Chrome). `Tab` sinks an unnumbered
478
507
  * line alone into a sub-list, any other line its whole item, and a block right after a list into
479
508
  * the list's last item. `Mod-Shift-7` / `Mod-Shift-8` are the list toggle (`list-toggle.ts`).
480
- * `Mod-Enter` ticks the task item around the caret (`toggleTask`).
509
+ * `LIST_KEYS.task` ticks the task item around the caret (`toggleTask`).
481
510
  *
482
511
  * `Enter` is a chain in precedence order: the empty line above an unnumbered one, an empty top-level
483
512
  * middle item out of the list, the marker back on an empty continuation line, `splitListItem` (`splitTaskItem` for
484
- * tasks), then `liftListItem`. The split link splits a non-empty item, and on an empty last item
513
+ * tasks, `paragraphAbove` over a heading), then `liftListItem`. The split link splits a non-empty item, and on an empty last item
485
514
  * either splits the wrapping item (a nested one, so Enter lifts one level) or bails so the last
486
515
  * link lifts a top-level one to a paragraph.
487
516
  *
@@ -503,7 +532,7 @@ export function listKeymap(schema) {
503
532
  [LIST_KEYS.indent]: chainCommands(sinkLine(itemType), sinkWithin(itemType), sinkIntoList(itemType)),
504
533
  [LIST_KEYS.outdent]: outdent(itemType),
505
534
  [LIST_KEYS.task]: toggleTask(itemType),
506
- Enter: chainCommands(lineAbove(itemType, paragraph), lineOutOfMiddle(itemType), markerOn(itemType), splitTaskItem(itemType), liftListItem(itemType)),
535
+ Enter: chainCommands(lineAbove(itemType, paragraph), lineOutOfMiddle(itemType), markerOn(itemType), paragraphAbove(itemType, paragraph, splitTaskItem(itemType)), liftListItem(itemType)),
507
536
  Backspace: chainCommands(deleteAcross, markerOff(itemType), lineOut(itemType), joinOntoList(itemType)),
508
537
  Delete: chainCommands(deleteAcross, deleteBelow(itemType, backspace))
509
538
  };
@@ -18,6 +18,7 @@ export declare const FIELD_KEYS: {
18
18
  export declare const BODY_KEYS: {
19
19
  readonly lineBreak: "Shift-Enter";
20
20
  readonly leave: "Escape";
21
+ readonly exitCode: "Alt-Enter";
21
22
  };
22
23
  /** A list item (`lists.ts`, `list-move.ts`). */
23
24
  export declare const LIST_KEYS: {
@@ -25,7 +26,7 @@ export declare const LIST_KEYS: {
25
26
  readonly bulleted: "Mod-Shift-8";
26
27
  readonly indent: "Tab";
27
28
  readonly outdent: "Shift-Tab";
28
- readonly task: "Mod-Enter";
29
+ readonly task: "Alt-Enter";
29
30
  readonly moveUp: "Alt-ArrowUp";
30
31
  readonly moveDown: "Alt-ArrowDown";
31
32
  };
@@ -45,16 +46,17 @@ export declare const TABLE_KEYS: {
45
46
  readonly erase: "Backspace";
46
47
  readonly eraseAlt: "Delete";
47
48
  };
48
- /** The review's keys, the editor's wherever the focus is while a review is open and ahead of
49
- * every other binding of them, so `accept` takes the current change over a task item's
50
- * `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
51
- * through the changes. */
49
+ /** The review's keys, the editor's wherever the focus is while a review is open. No leaf binds
50
+ * one of them, `accept` included, so each answers alike in every field. */
52
51
  export declare const REVIEW_KEYS: {
53
52
  readonly accept: "Mod-Enter";
54
- readonly dismiss: "Mod-Backspace";
53
+ readonly dismiss: "Mod-Alt-Backspace";
55
54
  readonly next: "Mod-Alt-ArrowDown";
56
55
  readonly previous: "Mod-Alt-ArrowUp";
57
56
  };
57
+ /** A leaf's last keymap: `baseKeymap` with a fence left by `BODY_KEYS.exitCode`. The review's
58
+ * accept is held inside a fence, so it does nothing there with no review open either. */
59
+ export declare const leafBaseKeymap: Record<string, Command>;
58
60
  /** The mark toggles, each bound only where the schema declares its mark. */
59
61
  export declare function markKeymap(schema: Schema): Record<string, Command>;
60
62
  /** Where a shortcut answers: any prose field, a multi-block body, a list item, a table cell, an
@@ -81,6 +83,7 @@ export interface ShortcutStrings {
81
83
  shortcutFormatBar: string;
82
84
  shortcutLineBreak: string;
83
85
  shortcutLeave: string;
86
+ shortcutExitCode: string;
84
87
  shortcutNumberedList: string;
85
88
  shortcutBulletedList: string;
86
89
  shortcutIndent: string;
@@ -5,7 +5,7 @@
5
5
  // A key a surface takes only to decline, hold or pass on (Backspace at a block edge, the
6
6
  // body's Tab hold, a code fence's Tab) is not a shortcut a writer looks up, and stays a
7
7
  // literal in its keymap.
8
- import { toggleMark } from 'prosemirror-commands';
8
+ import { baseKeymap, exitCode, toggleMark } from 'prosemirror-commands';
9
9
  /** Every prose leaf, a table cell included: history and the marks. `link` and `formatBar`
10
10
  * bind in the formatting popover, the surface one prompts from and the other enters. */
11
11
  export const FIELD_KEYS = {
@@ -23,7 +23,8 @@ export const FIELD_KEYS = {
23
23
  /** A multi-block body, outside any surface nested in it. */
24
24
  export const BODY_KEYS = {
25
25
  lineBreak: 'Shift-Enter',
26
- leave: 'Escape'
26
+ leave: 'Escape',
27
+ exitCode: 'Alt-Enter'
27
28
  };
28
29
  /** A list item (`lists.ts`, `list-move.ts`). */
29
30
  export const LIST_KEYS = {
@@ -31,7 +32,7 @@ export const LIST_KEYS = {
31
32
  bulleted: 'Mod-Shift-8',
32
33
  indent: 'Tab',
33
34
  outdent: 'Shift-Tab',
34
- task: 'Mod-Enter',
35
+ task: 'Alt-Enter',
35
36
  moveUp: 'Alt-ArrowUp',
36
37
  moveDown: 'Alt-ArrowDown'
37
38
  };
@@ -51,16 +52,21 @@ export const TABLE_KEYS = {
51
52
  erase: 'Backspace',
52
53
  eraseAlt: 'Delete'
53
54
  };
54
- /** The review's keys, the editor's wherever the focus is while a review is open and ahead of
55
- * every other binding of them, so `accept` takes the current change over a task item's
56
- * `LIST_KEYS.task` and `dismiss` over a text leaf's own delete; `next` and `previous` step
57
- * through the changes. */
55
+ /** The review's keys, the editor's wherever the focus is while a review is open. No leaf binds
56
+ * one of them, `accept` included, so each answers alike in every field. */
58
57
  export const REVIEW_KEYS = {
59
58
  accept: 'Mod-Enter',
60
- dismiss: 'Mod-Backspace',
59
+ dismiss: 'Mod-Alt-Backspace',
61
60
  next: 'Mod-Alt-ArrowDown',
62
61
  previous: 'Mod-Alt-ArrowUp'
63
62
  };
63
+ /** A leaf's last keymap: `baseKeymap` with a fence left by `BODY_KEYS.exitCode`. The review's
64
+ * accept is held inside a fence, so it does nothing there with no review open either. */
65
+ export const leafBaseKeymap = {
66
+ ...baseKeymap,
67
+ [REVIEW_KEYS.accept]: (state) => !!state.selection.$from.parent.type.spec.code,
68
+ [BODY_KEYS.exitCode]: exitCode
69
+ };
64
70
  /** The mark toggles, each bound only where the schema declares its mark. */
65
71
  export function markKeymap(schema) {
66
72
  const map = {};
@@ -88,11 +94,12 @@ export const DEFAULT_SHORTCUT_STRINGS = {
88
94
  shortcutFormatBar: 'Move to the format bar over a selection',
89
95
  shortcutLineBreak: 'Line break within a paragraph',
90
96
  shortcutLeave: 'Let Tab leave the editor',
97
+ shortcutExitCode: 'Leave a code block',
91
98
  shortcutNumberedList: 'Numbered list',
92
99
  shortcutBulletedList: 'Bulleted list',
93
100
  shortcutIndent: 'Nest under the item above',
94
101
  shortcutOutdent: 'Move back up a level',
95
- shortcutTask: 'Check or uncheck a task, outside a review',
102
+ shortcutTask: 'Check or uncheck a task',
96
103
  shortcutMoveItem: 'Move the item up or down',
97
104
  shortcutNextCell: 'Next cell, adding a row past the last',
98
105
  shortcutPreviousCell: 'Previous cell',
@@ -123,6 +130,7 @@ const SHORTCUTS = [
123
130
  { scope: 'field', label: 'shortcutFormatBar', keys: [F.formatBar] },
124
131
  { scope: 'body', label: 'shortcutLineBreak', keys: [BODY_KEYS.lineBreak] },
125
132
  { scope: 'body', label: 'shortcutLeave', keys: [BODY_KEYS.leave] },
133
+ { scope: 'body', label: 'shortcutExitCode', keys: [BODY_KEYS.exitCode] },
126
134
  { scope: 'list', label: 'shortcutNumberedList', keys: [L.numbered] },
127
135
  { scope: 'list', label: 'shortcutBulletedList', keys: [L.bulleted] },
128
136
  { scope: 'list', label: 'shortcutIndent', keys: [L.indent] },
@@ -9,13 +9,13 @@
9
9
  //
10
10
  // Every control is absolutely positioned out of the grid; `codec/prose.css` draws the band, the
11
11
  // clusters and the selection wash.
12
- import { baseKeymap, chainCommands, selectAll } from 'prosemirror-commands';
12
+ import { chainCommands, selectAll } from 'prosemirror-commands';
13
13
  import { redo, undo } from 'prosemirror-history';
14
14
  import { keymap } from 'prosemirror-keymap';
15
15
  import { EditorState, NodeSelection, Selection, TextSelection } from 'prosemirror-state';
16
16
  import { EditorView } from 'prosemirror-view';
17
17
  import { decode } from './decode.js';
18
- import { FIELD_KEYS, markKeymap, TABLE_KEYS as T } from './shortcuts.js';
18
+ import { FIELD_KEYS, leafBaseKeymap, markKeymap, TABLE_KEYS as T } from './shortcuts.js';
19
19
  import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
20
20
  import { linkPastePlugin } from './link-paste.js';
21
21
  import { dragMovePlugin } from './drag-move.js';
@@ -137,7 +137,7 @@ function cellPlugins(keys, outer) {
137
137
  linkPastePlugin(cellSchema.marks.link),
138
138
  dragMovePlugin(outer),
139
139
  keymap(keys),
140
- keymap(baseKeymap)
140
+ keymap(leafBaseKeymap)
141
141
  ];
142
142
  }
143
143
  /**
@@ -19,7 +19,7 @@ export declare function taskPlugin(): Plugin;
19
19
  export declare function splitTaskItem(itemType: NodeType): Command;
20
20
  /**
21
21
  * `checked` flipped on the nearest task item around the caret, or on a selected task item,
22
- * as one transaction. It declines outside a task item and inside a fence, where `baseKeymap`'s `exitCode` is the
23
- * nearer answer to `Mod-Enter`.
22
+ * as one transaction. It declines outside a task item and inside a fence, where leaving the fence is the
23
+ * nearer answer to the key the two share.
24
24
  */
25
25
  export declare function toggleTask(itemType: NodeType): Command;
@@ -1,7 +1,7 @@
1
1
  // A task item is a `list_item` whose `checked` is a boolean (INVARIANTS §"Task items"). Its
2
2
  // `toDOM` draws a checkbox ahead of the item's blocks, disabled, which is the drawing a
3
3
  // held leaf, a copy and `renderContent` take; a leaf that edits mounts the item through
4
- // `taskItemView`, whose checkbox toggles, as `Mod-Enter` does (`toggleTask`). A task item
4
+ // `taskItemView`, whose checkbox toggles, as `LIST_KEYS.task` does (`toggleTask`). A task item
5
5
  // is minted by source mode and by a paste alone: no shorthand, command or key makes one.
6
6
  import { DOMSerializer } from 'prosemirror-model';
7
7
  import { NodeSelection, Plugin } from 'prosemirror-state';
@@ -140,8 +140,8 @@ export function splitTaskItem(itemType) {
140
140
  }
141
141
  /**
142
142
  * `checked` flipped on the nearest task item around the caret, or on a selected task item,
143
- * as one transaction. It declines outside a task item and inside a fence, where `baseKeymap`'s `exitCode` is the
144
- * nearer answer to `Mod-Enter`.
143
+ * as one transaction. It declines outside a task item and inside a fence, where leaving the fence is the
144
+ * nearer answer to the key the two share.
145
145
  */
146
146
  export function toggleTask(itemType) {
147
147
  return (state, dispatch) => {
@@ -9,6 +9,9 @@ export interface FrameOptions {
9
9
  /** Room held clear at the band's foot, where it is more than the scroller's own `scroll-padding`. */
10
10
  foot?: number;
11
11
  behavior?: ScrollBehavior;
12
+ /** The extent framed in place of the target's own box, in viewport px, where more than the
13
+ * target has to show with it. */
14
+ extent?: Band;
12
15
  }
13
16
  /**
14
17
  * The scroll, in px down, that frames `target` in `band` with `gap` clear of each edge. `top` is
@@ -82,9 +82,10 @@ function frameInline(target, stop, behavior) {
82
82
  * where it is.
83
83
  */
84
84
  export function frame(target, opts) {
85
- const box = target.getBoundingClientRect();
86
- if (!box.width && !box.height)
85
+ const own = target.getBoundingClientRect();
86
+ if (!own.width && !own.height)
87
87
  return;
88
+ const box = opts.extent ?? own;
88
89
  const field = target.closest('.qm-field');
89
90
  const top = Math.min(field?.getBoundingClientRect().top ?? box.top, box.top);
90
91
  const scroller = scrollerOf(target);
@@ -51,7 +51,7 @@
51
51
  caret there, and short of a prose line's end splits the line there, as a bulleted list
52
52
  does; a paste of several lines into a prose row opens a row per line; Backspace at a
53
53
  prose line's start joins it onto the line above and Delete at its end joins the next
54
- onto it, each one commit. A prose element whose `items` declares a `shape` holds lines of its own, so Enter breaks a line inside it and ⌘/Ctrl+Enter inserts the sibling, and a paste stays in the element. Backspace on an empty element removes it and hands focus back up the list, Alt+↑/↓
54
+ onto it, each one commit. A prose element whose `items` declares a `shape` holds lines of its own, so Enter breaks a line inside it and Alt+Enter inserts the sibling, and a paste stays in the element. Backspace on an empty element removes it and hands focus back up the list, Alt+↑/↓
55
55
  anywhere in a row of the list moves it, the nearest row answering and never
56
56
  the record around a nested one: the twin of the handle's drag. A move is one splice of the ids
57
57
  and of the values together, the mechanism insert and remove use, so an element keeps
@@ -223,7 +223,7 @@
223
223
  // has text elements.
224
224
  const control = $derived(items ? controlKind(items) : 'text');
225
225
  /** A prose element whose `items` declares a `shape`: its own lines, which Enter breaks and
226
- * ⌘/Ctrl+Enter leaves for a sibling. */
226
+ * Alt+Enter leaves for a sibling. */
227
227
  const multiline = $derived(control === 'prose' && !leafFlags(items).inline);
228
228
  const table = $derived(layout === 'table' && control === 'object');
229
229
  const columns = $derived(Object.entries(items?.properties ?? {}));
@@ -922,7 +922,8 @@
922
922
  return;
923
923
  }
924
924
  if (e.key === 'Enter') {
925
- if (multiline && !(e.ctrlKey || e.metaKey)) return;
925
+ if (e.ctrlKey || e.metaKey) return;
926
+ if (multiline && (!e.altKey || e.defaultPrevented)) return;
926
927
  e.preventDefault();
927
928
  insertAfter(k, column);
928
929
  } else if (e.key === 'Backspace' && !e.repeat && elementEmpty(k, e.target, column)) {
@@ -1315,7 +1316,7 @@
1315
1316
  <!-- svelte-ignore a11y_no_static_element_interactions -->
1316
1317
  <div
1317
1318
  class={[
1318
- 'qm-array-row qm-review-added',
1319
+ 'qm-array-row qm-review-added qm-focus-ring',
1319
1320
  {
1320
1321
  'qm-array-table-row': table,
1321
1322
  'qm-element': control === 'object' && !table,
@@ -1324,6 +1325,7 @@
1324
1325
  ]}
1325
1326
  style:order
1326
1327
  data-qm-review={item.id}
1328
+ tabindex="-1"
1327
1329
  role="group"
1328
1330
  aria-label={t.strings.reviewNewItem}
1329
1331
  >
@@ -462,7 +462,7 @@
462
462
 
463
463
  {#snippet kindOptions()}
464
464
  {#each kinds as k (k)}
465
- <option value={k}>{kindTitle(quill.schema.card_kinds?.[k], k)}</option>
465
+ <option value={k}>{kindTitle(quill.schema[k], k)}</option>
466
466
  {/each}
467
467
  {/snippet}
468
468
 
@@ -1,6 +1,6 @@
1
1
  <!--
2
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
3
+ change is answered by pointer. A quiet Dismiss and a primary Accept with its key, a note
4
4
  where the reader's own writing meets the change, and above them the line the proposal's writer
5
5
  gave for it, cut to one line. The change itself is drawn where it
6
6
  stands, so the card is the same two answers on every change. It carries no position: the count
@@ -12,8 +12,11 @@
12
12
  change stands in, and never above it: a card that turns over the text as a scroll runs short
13
13
  of room moves under the pointer about to answer. Its room under the change is what a step
14
14
  scrolls for, and the host's chrome at the pane's foot (`inset`) is kept clear. The column is
15
- the card's body or its form whole, never the one field, so Accept stands at one edge from
16
- change to change and a pointer answering a run of them does not hunt for it. A field or a
15
+ the card's body or its form whole, so Accept stands at one edge from change to change and a
16
+ pointer answering a run of them does not hunt for it. A field or a property sharing its row
17
+ takes its own right edge instead, reaching past it only as far as the card is wide and never
18
+ past the column's: a card at the column's edge stands under the row's last field, which reads
19
+ as the change it answers whatever field the change is in. A field or a
17
20
  property sharing its row with others takes the card beside its line only where the card
18
21
  stands within its own slot, and under the row otherwise: beside the line of one that ends
19
22
  short of the column's edge the card covers the value of the next. Over a change too tall for
@@ -27,7 +30,9 @@
27
30
  anywhere, a resize of the editor.
28
31
 
29
32
  It never takes the focus. A press on it keeps the focus where it is, and the keyboard reaches
30
- it only by `enter`, from which Escape and every answer hand the focus back.
33
+ it only by `enter`. There Enter presses a button as on any, and no other key answers or
34
+ steps but the review's own. The focus rides the card from change to change, and Escape or the
35
+ last answer hands it back.
31
36
  -->
32
37
  <script lang="ts">
33
38
  import { tick } from 'svelte';
@@ -48,9 +53,11 @@
48
53
  outdated: boolean;
49
54
  /** Why, as the proposal's writer says it. */
50
55
  note?: string;
56
+ /** The answer key whose press only brought the card, whose hint says to press it again. */
57
+ asked?: 'accept' | 'dismiss';
51
58
  onAnswer(action: 'accept' | 'dismiss'): void;
52
59
  }
53
- let { id, root, inset, hidden, outdated, note, onAnswer }: Props = $props();
60
+ let { id, root, inset, hidden, outdated, note, asked, onAnswer }: Props = $props();
54
61
  const noteId = $props.id();
55
62
 
56
63
  const t = wording();
@@ -64,8 +71,14 @@
64
71
  let stands = false;
65
72
  /** The change is drawn, so the card has somewhere to stand. */
66
73
  let placed = $state(false);
74
+ /** The span, in viewport px, of the change's blocks and the card where it stands unpinned. */
75
+ let reach: { top: number; bottom: number } = { top: 0, bottom: 0 };
67
76
  /** Where the focus was when the keyboard entered the card, to hand it back. */
68
77
  let from: HTMLElement | undefined;
78
+ /** The keyboard is on the card, from `enter` until the reader takes the focus off it. The
79
+ * card is inert between two changes, which drops the focus to the body: that is no move of
80
+ * the reader's, and the focus is put back as the card shows again. */
81
+ let riding = $state(false);
69
82
 
70
83
  const shown = $derived(placed && !hidden && id !== undefined);
71
84
 
@@ -120,13 +133,18 @@
120
133
  const column = (els[0].closest(
121
134
  '.qm-fields, .qm-card, .qm-review-card-add, .qm-review-card-remove'
122
135
  ) ?? root)!;
123
- left = Math.max(view.left + gap, column.getBoundingClientRect().right - w);
136
+ const edge = column.getBoundingClientRect().right;
137
+ const home = els[0].closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
138
+ const right =
139
+ home && home.right < edge ? Math.min(edge, Math.max(home.right, home.left + w)) : edge;
140
+ left = Math.max(view.left + gap, right - w);
124
141
  const at = (root ?? el).getBoundingClientRect();
125
142
  const last = blocks.find((b, i) => b !== els[i] && b.getBoundingClientRect().bottom === lower);
126
143
  const tuck = last && lastLine(last, h);
127
144
  const slot = last?.closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
128
145
  const beside = tuck && tuck.right + gap <= left && (!slot || left + w <= slot.right + 1);
129
146
  const below = beside ? tuck.top : lower + gap;
147
+ reach = { top: upper, bottom: Math.max(lower, below + h) };
130
148
  const tall = lower - upper + gap + h > floor - ceil;
131
149
  pinned = shows && tall && below + h > floor;
132
150
  const y = pinned ? Math.max(ceil, floor - h) : below;
@@ -223,11 +241,19 @@
223
241
  return !placed || stands;
224
242
  }
225
243
 
244
+ /** What a reveal frames for the change: its blocks and the card under or beside them, as
245
+ * the card stands where nothing pins it. `undefined` while the change draws nothing. */
246
+ export function extent(): { top: number; bottom: number } | undefined {
247
+ place();
248
+ return placed ? reach : undefined;
249
+ }
250
+
226
251
  /** Put the focus on Accept, handing it back to where it was on Escape or an answer. False
227
252
  * with no card on show. */
228
253
  export async function enter(): Promise<boolean> {
229
254
  if (!shown || !el || !inView(el)) return false;
230
255
  from = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
256
+ riding = true;
231
257
  await tick();
232
258
  el.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
233
259
  return true;
@@ -236,21 +262,40 @@
236
262
  function leave(): void {
237
263
  const back = from;
238
264
  from = undefined;
265
+ riding = false;
239
266
  if (back?.isConnected) back.focus({ preventScroll: true });
240
267
  }
241
268
 
242
269
  function answer(action: 'accept' | 'dismiss'): void {
243
- const held = !!el?.contains(document.activeElement);
244
270
  onAnswer(action);
245
- if (held) leave();
271
+ }
272
+
273
+ $effect(() => {
274
+ if (!riding) return;
275
+ if (id === undefined) leave();
276
+ else if (shown && document.activeElement === document.body)
277
+ el?.querySelector<HTMLElement>('.qm-review-card-accept')?.focus({ preventScroll: true });
278
+ });
279
+
280
+ /** The reader took the focus off the card: to `to`, or by a press outside it. */
281
+ function tookOff(to: EventTarget | null): void {
282
+ if (to instanceof Node && el?.contains(to)) return;
283
+ riding = false;
284
+ from = undefined;
246
285
  }
247
286
 
248
287
  function onkeydown(e: KeyboardEvent): void {
288
+ if (e.ctrlKey || e.metaKey || e.altKey) return;
249
289
  if (e.key === 'Escape') {
250
290
  e.preventDefault();
251
291
  leave();
252
292
  return;
253
293
  }
294
+ // A held Enter clicks its button on every repeat, and a held key answers once.
295
+ if (e.key === 'Enter' && e.repeat) {
296
+ e.preventDefault();
297
+ return;
298
+ }
254
299
  if (e.key !== 'Tab' && e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
255
300
  const buttons = [...(el?.querySelectorAll<HTMLElement>('button') ?? [])];
256
301
  const at = buttons.indexOf(document.activeElement as HTMLElement);
@@ -261,7 +306,11 @@
261
306
  }
262
307
  </script>
263
308
 
264
- <svelte:window onscrollcapture={schedule} onresize={schedule} />
309
+ <svelte:window
310
+ onscrollcapture={schedule}
311
+ onresize={schedule}
312
+ onpointerdowncapture={(e) => tookOff(e.target)}
313
+ />
265
314
 
266
315
  <!-- svelte-ignore a11y_no_static_element_interactions -->
267
316
  <!-- The press keeps the focus where it is: the answer is about the text, not a move off it. -->
@@ -281,7 +330,8 @@
281
330
  onmousedown={(e) => e.preventDefault()}
282
331
  {onkeydown}
283
332
  onfocusout={(e) => {
284
- if (!el?.contains(e.relatedTarget as Node | null)) from = undefined;
333
+ if (e.relatedTarget) tookOff(e.relatedTarget);
334
+ else if (!riding) from = undefined;
285
335
  }}
286
336
  >
287
337
  {#if note}<p id={noteId} class="qm-review-card-reason" title={note}>{note}</p>{/if}
@@ -289,11 +339,14 @@
289
339
  {#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
290
340
  <button
291
341
  type="button"
292
- class="qm-review-card-dismiss qm-focus-ring"
342
+ class={[
343
+ 'qm-review-card-dismiss qm-focus-ring',
344
+ { 'qm-review-card-asked': asked === 'dismiss' }
345
+ ]}
293
346
  tabindex="-1"
347
+ title={keycap(REVIEW_KEYS.dismiss)}
294
348
  aria-keyshortcuts={keyshortcut(REVIEW_KEYS.dismiss)}
295
- onclick={() => answer('dismiss')}
296
- >{t.strings.reviewDismiss}<kbd>{keycap(REVIEW_KEYS.dismiss)}</kbd></button
349
+ onclick={() => answer('dismiss')}>{t.strings.reviewDismiss}</button
297
350
  >
298
351
  <button
299
352
  type="button"
@@ -301,7 +354,9 @@
301
354
  tabindex="-1"
302
355
  aria-keyshortcuts={keyshortcut(REVIEW_KEYS.accept)}
303
356
  onclick={() => answer('accept')}
304
- >{t.strings.reviewAccept}<kbd>{keycap(REVIEW_KEYS.accept)}</kbd></button
357
+ >{t.strings.reviewAccept}<kbd class={{ 'qm-review-card-asked': asked === 'accept' }}
358
+ >{keycap(REVIEW_KEYS.accept)}</kbd
359
+ ></button
305
360
  >
306
361
  </div>
307
362
  </div>
@@ -372,6 +427,23 @@
372
427
  }
373
428
  kbd {
374
429
  font: inherit;
430
+ border-radius: var(--_qm-radius-inner);
431
+ }
432
+ /* The press that brought the card asks for another: Accept's key hint rings once, and
433
+ Dismiss itself, which shows no key. */
434
+ .qm-review-card-asked {
435
+ outline: var(--_qm-border-width) solid currentColor;
436
+ outline-offset: 2px;
437
+ }
438
+ @media (prefers-reduced-motion: no-preference) {
439
+ .qm-review-card-asked {
440
+ animation: qm-review-card-ask var(--_qm-duration-slow) var(--_qm-ease-reverse) 2;
441
+ }
442
+ }
443
+ @keyframes qm-review-card-ask {
444
+ 50% {
445
+ outline-offset: 4px;
446
+ }
375
447
  }
376
448
  .qm-review-card-answers {
377
449
  display: flex;
@@ -11,10 +11,16 @@ interface Props {
11
11
  outdated: boolean;
12
12
  /** Why, as the proposal's writer says it. */
13
13
  note?: string;
14
+ /** The answer key whose press only brought the card, whose hint says to press it again. */
15
+ asked?: 'accept' | 'dismiss';
14
16
  onAnswer(action: 'accept' | 'dismiss'): void;
15
17
  }
16
18
  declare const ReviewCard: import("svelte").Component<Props, {
17
19
  standsInView: () => boolean;
20
+ extent: () => {
21
+ top: number;
22
+ bottom: number;
23
+ } | undefined;
18
24
  enter: () => Promise<boolean>;
19
25
  }, "">;
20
26
  type ReviewCard = ReturnType<typeof ReviewCard>;