@quillmark/svelte 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,7 @@
61
61
  import type { Delta } from '../core/codec/positions.js';
62
62
  import { diagnosticText, mergeStrings, setWording } from './strings.js';
63
63
  import { createStructuralUndo, setStructuralUndo } from './undo.svelte.js';
64
+ import { reviewKeysHeard, type ReviewKeyName } from './hears.js';
64
65
  import { undoChord } from './listhistory.js';
65
66
  import { removedCards, type RemovedCard } from './removed.js';
66
67
  import { createReview, setReview, type CardAdd } from './review.svelte.js';
@@ -214,7 +215,7 @@
214
215
  // card reorder.
215
216
  const commitErrors = new SvelteMap<string, RoutedDiagnostic>();
216
217
 
217
- const kinds = $derived(Object.keys(quill.schema.card_kinds ?? {}));
218
+ const kinds = $derived(Object.keys(quill.schema).filter((k) => k !== 'main'));
218
219
 
219
220
  // The removal's step back (`undo.svelte.ts`), published so an array's row removal
220
221
  // offers on the same toast a card's does.
@@ -278,7 +279,7 @@
278
279
  if (!running || value === undefined || !shown || !Object.hasOwn(shown.values, name))
279
280
  return rederive();
280
281
  const fresh = fieldValues((isMain ? doc.main : doc.card(at)).payloadItems);
281
- const cardSchema = isMain ? quill.schema.main : quill.schema.card_kinds?.[shown.kind];
282
+ const cardSchema = isMain ? quill.schema.main : quill.schema[shown.kind];
282
283
  patched = {
283
284
  ...patched,
284
285
  [id]: {
@@ -565,7 +566,7 @@
565
566
  text: string;
566
567
  } {
567
568
  const { add } = item;
568
- const schema = quill.schema.card_kinds?.[add.kind];
569
+ const schema = quill.schema[add.kind];
569
570
  const values = fieldValues(add.payloadItems);
570
571
  const named = (add.ext?.editor as { title?: unknown } | undefined)?.title;
571
572
  const title = cardTitle(
@@ -593,6 +594,12 @@
593
594
  typing = false;
594
595
  onReviewFocus?.(id);
595
596
  });
597
+ // The caret landing on a change brings back the card typing put aside, the same change
598
+ // included once the caret has left it and come back.
599
+ $effect(() => {
600
+ void reviewing.landed;
601
+ typing = false;
602
+ });
596
603
  // The report, to a host counting its own list: each change, read once the leaves the change
597
604
  // mounted have drawn, so a list just handed over is not reported as anchored nowhere. A
598
605
  // review starts on its first change, and goes on to the first open one wherever the current
@@ -659,31 +666,59 @@
659
666
  /** Answer the current change, as its card would. False with none open. */
660
667
  function answerCurrent(action: 'accept' | 'dismiss'): boolean {
661
668
  const id = reviewing.lit;
662
- return id !== undefined && answerReview([id], action).length > 0;
669
+ if (id === undefined) return false;
670
+ const at = document.activeElement;
671
+ const held = at instanceof Element && reviewIds(at.closest(THING)).includes(id);
672
+ if (!answerReview([id], action).length) return false;
673
+ // A change that is a thing goes with its answer, and the focus it held with it: the focus
674
+ // goes on to the next change, as a step would take it.
675
+ if (held)
676
+ void tick().then(() => {
677
+ const next = reviewing.lit;
678
+ if (next !== undefined && !rootEl?.contains(document.activeElement))
679
+ void reveal(next, true, true);
680
+ });
681
+ return true;
663
682
  }
664
- /** An answer key: the card's, so it answers only a change the card stands on in view. A
665
- * press while the reader types in the editor is the leaf's own key, and any other press
666
- * with the change out of view or the card out of the way brings both back. */
683
+ /** An answer key: the card's, so it answers only a change whose card stands whole in view. A
684
+ * press with the change or its card out of view, or the card out of the way of the reader's
685
+ * typing, brings both back, and the next answers. */
667
686
  function answerByKey(action: 'accept' | 'dismiss'): boolean {
668
687
  const id = reviewing.lit;
669
- if (id === undefined || (typing && inside)) return false;
670
- if (!typing && inView(id)) return answerCurrent(action);
688
+ if (id === undefined) return false;
689
+ if (!typing && inView(id) && (answerCard?.standsInView() ?? true)) {
690
+ answerCurrent(action);
691
+ return true;
692
+ }
671
693
  typing = false;
672
- void reveal(id, false, true);
694
+ asked = action;
695
+ void reveal(id, false, false);
673
696
  return true;
674
697
  }
675
- /** Whether a key at `target` is the review's: anywhere but a text control outside the editor,
676
- * which keeps its own keys, or another editor. */
677
- function reviewHears(target: EventTarget | null): boolean {
678
- if (!(target instanceof Element) || !rootEl) return false;
679
- if (rootEl.contains(target)) return true;
680
- if (target.closest('.qm-editor')) return false;
681
- return !target.closest('input, textarea, select, [contenteditable="true"]');
682
- }
698
+ /** The answer key whose press only brought the card, which the card's hint for it shows. */
699
+ let asked = $state<'accept' | 'dismiss' | undefined>();
700
+ $effect(() => {
701
+ void reviewing.lit;
702
+ asked = undefined;
703
+ });
704
+ /** An answer key's fresh press. Its repeats are never an answer: a held key answers once. */
705
+ function answerKey(action: 'accept' | 'dismiss'): boolean {
706
+ if (repeat) return false;
707
+ answered = answerByKey(action);
708
+ return answered;
709
+ }
710
+ /** The review took the press being matched as an answer key's. */
711
+ let answered = false;
712
+ /** The chord of the answer key the review took and the keyboard may still repeat, whose
713
+ * repeats it swallows even once no change is left, so none falls through to a leaf. */
714
+ let heldChord: string | undefined;
715
+ const chordOf = (e: KeyboardEvent): string =>
716
+ `${e.key}:${+e.metaKey}${+e.ctrlKey}${+e.altKey}${+e.shiftKey}`;
683
717
  let answerCard = $state<ReviewCard | undefined>();
684
718
  const reviewKeys = keydownHandler({
685
- [REVIEW_KEYS.accept]: () => answerByKey('accept'),
686
- [REVIEW_KEYS.dismiss]: () => answerByKey('dismiss'),
719
+ [REVIEW_KEYS.accept]: () => answerKey('accept'),
720
+ [REVIEW_KEYS.acceptAlt]: () => answerKey('accept'),
721
+ [REVIEW_KEYS.dismiss]: () => answerKey('dismiss'),
687
722
  [REVIEW_KEYS.next]: () => {
688
723
  void step(1, inside);
689
724
  return true;
@@ -693,35 +728,82 @@
693
728
  return true;
694
729
  },
695
730
  'Alt-F10': () => {
696
- if (!answerCard || document.getSelection()?.isCollapsed === false) return false;
697
- void answerCard.enter();
731
+ const id = reviewing.lit;
732
+ if (!answerCard || id === undefined || document.getSelection()?.isCollapsed === false)
733
+ return false;
734
+ void enterCard(id);
698
735
  return true;
699
736
  }
700
737
  });
738
+ /** The review key being matched, by the name a host's text box hands it over by. */
739
+ let named: ReviewKeyName | undefined;
740
+ const reviewKeyName = keydownHandler(
741
+ Object.fromEntries(
742
+ (['accept', 'acceptAlt', 'dismiss', 'next', 'previous'] as const).map((key) => [
743
+ REVIEW_KEYS[key],
744
+ () => {
745
+ named = key === 'acceptAlt' ? 'accept' : key;
746
+ return true;
747
+ }
748
+ ])
749
+ )
750
+ );
751
+ /** Alt-F10: the card brought back from wherever typing or a scroll put it, then entered. */
752
+ async function enterCard(id: string): Promise<void> {
753
+ typing = false;
754
+ if (!inView(id) || !(answerCard?.standsInView() ?? true)) await reveal(id, false, false);
755
+ await tick();
756
+ // A reveal glides, and the card is entered once it stands in the pane.
757
+ for (let frame = 0; frame < ENTER_FRAMES && reviewing.lit === id; frame++) {
758
+ if (await answerCard?.enter()) return;
759
+ await new Promise(requestAnimationFrame);
760
+ }
761
+ }
762
+ /** How many frames Alt-F10 waits for a reveal's scroll to bring the card into the pane. */
763
+ const ENTER_FRAMES = 90;
701
764
  /** Whether the key being matched was pressed inside the editor, where a step takes the caret
702
765
  * with it. */
703
766
  let inside = false;
704
- /** The review keys, captured on the document ahead of every other binding of them: a task
705
- * item's tick, a leaf's arrows, a host's own. */
767
+ /** Whether the key being matched is the keyboard's repeat of a held one. */
768
+ let repeat = false;
769
+ /** The review keys, captured on the document ahead of a leaf's arrows and a host's own keys. */
706
770
  function onReviewKey(e: KeyboardEvent): void {
707
- if (e.isComposing || reviewing.lit === undefined || !reviewHears(e.target)) return;
708
- inside = !!rootEl?.contains(e.target as Node);
771
+ if (!e.repeat) {
772
+ asked = undefined;
773
+ heldChord = undefined;
774
+ } else if (heldChord === chordOf(e)) {
775
+ e.preventDefault();
776
+ e.stopPropagation();
777
+ return;
778
+ }
779
+ if (e.defaultPrevented || e.isComposing || e.keyCode === 229) return;
780
+ if (reviewing.lit === undefined || !rootEl) return;
781
+ named = undefined;
782
+ reviewKeyName({} as never, e);
783
+ if (!reviewKeysHeard(e.target, rootEl, named)) return;
784
+ inside = rootEl.contains(e.target as Node);
785
+ repeat = e.repeat;
786
+ answered = false;
709
787
  // The bindings read no view: this is `prosemirror-keymap`'s chord matcher alone.
710
788
  if (!reviewKeys({} as never, e)) return;
789
+ if (answered) heldChord = chordOf(e);
711
790
  e.preventDefault();
712
791
  e.stopPropagation();
713
792
  }
714
793
 
715
- /** The reader is typing: the card keeps out of the way until the pointer moves or the
716
- * current change does. */
794
+ /** The reader is typing: the card keeps out of the way until the pointer moves, the caret
795
+ * lands on a change, the focus moves to another leaf or place, or an answer key or Alt-F10
796
+ * asks for it. */
717
797
  let typing = $state(false);
718
798
  let pointerAt = { x: NaN, y: NaN };
719
799
  function onTyped(e: KeyboardEvent): void {
720
800
  if (reviewing.lit === undefined || e.metaKey || e.ctrlKey || e.altKey) return;
801
+ if (e.target instanceof Element && e.target.closest('.qm-review-card')) return;
721
802
  if (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter')
722
803
  typing = true;
723
804
  }
724
805
  function onPointerMove(e: PointerEvent): void {
806
+ asked = undefined;
725
807
  if (!typing) {
726
808
  pointerAt = { x: e.clientX, y: e.clientY };
727
809
  return;
@@ -738,42 +820,73 @@
738
820
  function reviewIds(el: Element | null | undefined): string[] {
739
821
  return el?.getAttribute('data-qm-review')?.split(' ').filter(Boolean) ?? [];
740
822
  }
741
- /** A press on a change makes it current at once, and a press elsewhere in a field the
742
- * nearest change in it, the current item being another field's. */
823
+ /** A press on a change makes it current at once, and a press elsewhere the change nearest it
824
+ * in its place (`placeOf`). */
743
825
  function onPick(e: PointerEvent): void {
744
826
  const target = e.target instanceof Element ? e.target : null;
745
- const ids = reviewIds(target?.closest('[data-qm-review]'));
746
- const id = ids.includes(reviewing.lit ?? '') ? reviewing.lit : ids[0];
747
- if (id && reviewing.items.some((item) => item.id === id)) {
748
- typing = false;
749
- reviewing.reveal(id);
750
- } else if (target) pickNear(target);
827
+ if (target && !nameAt(target)) pickNear(target);
751
828
  }
752
- /** The reader arrived at `target` from outside its field, not handed back from a surface
753
- * floating over it: the nearest change in the field becomes current. */
829
+ /** The focus arriving from elsewhere on the page, not handed back from a surface floating over
830
+ * the editor, is a press by another hand: on a change it names it, and elsewhere the change
831
+ * nearest it in its place. Moving from one leaf or place to another ends the writing the
832
+ * card stood aside for. A leaf of words that draws changes of its own names them from its
833
+ * caret (`review-caret.ts`). */
754
834
  function onArrive(e: FocusEvent): void {
755
835
  const target = e.target instanceof Element ? e.target : null;
756
836
  const from = e.relatedTarget instanceof Element ? e.relatedTarget : null;
757
837
  if (!target || !from || from.closest('.qm-popover-surface')) return;
758
- const field = outerField(target);
759
- if (field && !field.contains(from) && !target.closest('[data-qm-review]')) pickNear(target);
760
- }
761
- /** The outermost field holding `el`: the one a list's rows and a record's cells are of. */
762
- function outerField(el: Element): Element | undefined {
763
- let field: Element | undefined;
764
- for (let at = el.closest('.qm-field'); at; at = at.parentElement?.closest('.qm-field') ?? null)
765
- field = at;
766
- return field;
767
- }
768
- /** Make the change in `target`'s field nearest it current, the fewest rows away and then the
769
- * fewest pixels across, the current item being another field's. A leaf of words that draws
838
+ if (
839
+ from.closest('.ProseMirror') !== target.closest('.ProseMirror') ||
840
+ placeOf(from) !== placeOf(target)
841
+ )
842
+ typing = false;
843
+ if (target.closest('.ProseMirror')?.querySelector('[data-qm-review]')) return;
844
+ const marked = target.closest('[data-qm-review]');
845
+ if (marked && openIds(marked).length) {
846
+ if (!marked.contains(from)) nameAt(target);
847
+ return;
848
+ }
849
+ const place = placeOf(target);
850
+ if (place && !place.contains(from)) pickNear(target);
851
+ }
852
+ /** The focus left the editor: the reader is no longer writing in it. */
853
+ function onLeave(e: FocusEvent): void {
854
+ if (!(e.relatedTarget instanceof Node && rootEl?.contains(e.relatedTarget))) typing = false;
855
+ }
856
+ /** The open items `el` draws. */
857
+ function openIds(el: Element): string[] {
858
+ return reviewIds(el).filter((id) => reviewing.items.some((item) => item.id === id));
859
+ }
860
+ /** Make current the open change `el` stands in, the current one where it stands in several.
861
+ * False where it stands in none. */
862
+ function nameAt(el: Element): boolean {
863
+ const ids = openIds(el.closest('[data-qm-review]') ?? el);
864
+ if (!ids.length) return false;
865
+ typing = false;
866
+ reviewing.reveal(ids.includes(reviewing.lit ?? '') ? reviewing.lit! : ids[0]);
867
+ return true;
868
+ }
869
+ /** Where a reader arriving at `el` means to work: the list it is a row of, else the control it
870
+ * is in, a record's property as much as a field. A group or a record holding properties is
871
+ * no place, so its header and the gaps between its properties name nothing. */
872
+ function placeOf(el: Element): Element | undefined {
873
+ const row = el.closest('.qm-array-row');
874
+ if (row?.parentElement)
875
+ return row.parentElement.closest('.qm-object-prop, .qm-field') ?? undefined;
876
+ const place = el.closest('.qm-object-prop, .qm-field');
877
+ return place?.matches('.qm-field') && place.querySelector('.qm-object-prop')
878
+ ? undefined
879
+ : (place ?? undefined);
880
+ }
881
+ /** Make the change in `target`'s place nearest it current, the fewest rows away and then the
882
+ * fewest pixels across, the current item being another place's. A leaf of words that draws
770
883
  * changes of its own names them from its caret (`review-caret.ts`). */
771
884
  function pickNear(target: Element): void {
772
885
  if (target.closest('.ProseMirror')?.querySelector('[data-qm-review]')) return;
773
- const field = outerField(target);
774
- if (!field) return;
886
+ const place = placeOf(target);
887
+ if (!place) return;
775
888
  const open = new Set(reviewing.order);
776
- const marks = [...field.querySelectorAll('[data-qm-review]')].filter((el) =>
889
+ const marks = [...place.querySelectorAll('[data-qm-review]')].filter((el) =>
777
890
  reviewIds(el).some((id) => open.has(id))
778
891
  );
779
892
  if (!marks.length) return;
@@ -809,7 +922,7 @@
809
922
  if (!key?.field) return '';
810
923
  const isMain = key.card === undefined;
811
924
  const card = isMain ? model.main : model.cards[cardIndexOf(key.card as CardId)];
812
- const schema = isMain ? quill.schema.main : quill.schema.card_kinds?.[card?.kind ?? ''];
925
+ const schema = isMain ? quill.schema.main : quill.schema[card?.kind ?? ''];
813
926
  const sub = schema?.fields[key.field];
814
927
  return sub ? fieldTitle(key.field, sub) : humanize(key.field);
815
928
  }
@@ -924,7 +1037,7 @@
924
1037
  const { card: at, field } = addr;
925
1038
  if (typeof at !== 'number' || field == null) return;
926
1039
  const shown = model.cards[at];
927
- const cardSchema = shown && quill.schema.card_kinds?.[shown.kind];
1040
+ const cardSchema = shown && quill.schema[shown.kind];
928
1041
  if (!cardSchema || cardSchema.title?.trim()) return;
929
1042
  const sub = Object.hasOwn(cardSchema.fields, field) ? cardSchema.fields[field] : undefined;
930
1043
  if (!sub || !shortCell(sub)) return;
@@ -1139,7 +1252,7 @@
1139
1252
  const name =
1140
1253
  shown?.titleOverride ||
1141
1254
  shown?.titlePlaceholder ||
1142
- kindTitle(quill.schema.card_kinds?.[card.kind], card.kind);
1255
+ kindTitle(quill.schema[card.kind], card.kind);
1143
1256
  const gone = removed.remove(id, card, cardIds, i);
1144
1257
  doc.removeCard(i);
1145
1258
  arm.arm();
@@ -1398,7 +1511,7 @@
1398
1511
  false,
1399
1512
  c.kind,
1400
1513
  c,
1401
- schema.card_kinds?.[c.kind],
1514
+ schema[c.kind],
1402
1515
  byCard.get(i) ?? NO_RESOLVED_ROWS
1403
1516
  )
1404
1517
  )
@@ -1662,11 +1775,15 @@
1662
1775
  }
1663
1776
  if (!(await span.resumes(tick()))) return false;
1664
1777
  reviewing.reveal(id);
1665
- if (focus && key !== undefined && !leaves.prose(key)?.enterReview(id)) {
1778
+ const thing = focus ? reviewEls(id).find((el) => el.matches(THING)) : undefined;
1779
+ if (thing) thing.focus({ preventScroll: true });
1780
+ else if (focus && key !== undefined && !leaves.prose(key)?.enterReview(id)) {
1666
1781
  const control = leaves.control(key);
1667
1782
  const steps = reviewing.at(key).nested?.find((e) => e.item.id === id)?.steps;
1668
- if (steps && control?.focusPath) control.focusPath(steps);
1783
+ if (steps && control?.focusPath) await control.focusPath(steps);
1669
1784
  else control?.focus();
1785
+ if (!span.alive) return false;
1786
+ caretToEnd(id);
1670
1787
  }
1671
1788
  // The current item is drawn again, so its element is read once it has been.
1672
1789
  if (!(await span.resumes(tick()))) return false;
@@ -1675,11 +1792,50 @@
1675
1792
  (key !== undefined ? leaves.prose(key)?.reviewElements(id)[0] : undefined) ??
1676
1793
  els[0] ??
1677
1794
  (key !== undefined ? leaves.control(key)?.el : undefined);
1678
- if (!at || (stepping && comfortable(els.length ? els : [at]))) return true;
1795
+ if (!at) return true;
1796
+ const extent = framing(answerCard?.extent());
1797
+ if (stepping && comfortable(els.length ? els : [at], extent)) return true;
1679
1798
  const reduce = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
1680
- frame(at, { block: 'center', foot: reviewInset, behavior: reduce ? 'instant' : 'smooth' });
1799
+ frame(at, {
1800
+ block: 'center',
1801
+ foot: reviewInset,
1802
+ behavior: reduce ? 'instant' : 'smooth',
1803
+ extent
1804
+ });
1681
1805
  return true;
1682
1806
  }
1807
+ /** What a reveal frames beside the change: `whole`, the change's blocks and its card, where
1808
+ * they fit in the pane together. Where they do not, the card pins at the pane's foot and the
1809
+ * change's own words are what to show, so nothing is framed beside them. */
1810
+ function framing(
1811
+ whole: { top: number; bottom: number } | undefined
1812
+ ): { top: number; bottom: number } | undefined {
1813
+ if (!whole) return undefined;
1814
+ const { top, bottom } = pane();
1815
+ const room = bottom - reviewInset - top - 2 * (spacePx(rootEl, 1) ?? 0);
1816
+ return whole.bottom - whole.top <= room ? whole : undefined;
1817
+ }
1818
+ /** What a change that is a thing draws, which takes the focus as one stop: a row or a card
1819
+ * proposed new, and a card proposed for removal. */
1820
+ const THING = '.qm-review-added, .qm-review-card-add, .qm-review-card-remove.qm-review-on';
1821
+ /** Put the caret at the end of the words of `id` in the leaf holding the focus: past its last
1822
+ * run, or ahead of a piece it adds, which stands at the end of the line it follows. */
1823
+ function caretToEnd(id: string): void {
1824
+ const leaf = document.activeElement?.closest('.ProseMirror');
1825
+ const last = leaf
1826
+ ? [...leaf.querySelectorAll('[data-qm-review]')]
1827
+ .filter((el) => reviewIds(el).includes(id))
1828
+ .at(-1)
1829
+ : undefined;
1830
+ const selection = document.getSelection();
1831
+ if (!last || !selection) return;
1832
+ const range = document.createRange();
1833
+ if (last.getAttribute('contenteditable') === 'false') range.setStartBefore(last);
1834
+ else range.selectNodeContents(last);
1835
+ range.collapse(last.getAttribute('contenteditable') === 'false');
1836
+ selection.removeAllRanges();
1837
+ selection.addRange(range);
1838
+ }
1683
1839
  /** Whether the open card item `id` is drawn. */
1684
1840
  function byCardId(id: string): boolean {
1685
1841
  for (const list of reviewing.cards.adds.values())
@@ -1706,16 +1862,17 @@
1706
1862
  const boxes = (els: readonly HTMLElement[]): DOMRect[] =>
1707
1863
  els.map((el) => el.getBoundingClientRect()).filter((r) => r.width || r.height);
1708
1864
  /** Whether `els` stand in the view the editor scrolls in, clear of the host's chrome at its
1709
- * foot, with the answer card's room under them. */
1710
- function comfortable(els: readonly HTMLElement[]): boolean {
1865
+ * foot, with `extent`, the change and its answer card as the card stands, inside it too. */
1866
+ function comfortable(
1867
+ els: readonly HTMLElement[],
1868
+ extent: { top: number; bottom: number } | undefined
1869
+ ): boolean {
1711
1870
  const rects = boxes(els);
1712
1871
  if (!rects.length) return false;
1713
1872
  const { top, bottom } = pane();
1714
- const room = (spacePx(rootEl, 1) ?? 0) * CARD_ROOM;
1715
- const band = { top, bottom: bottom - reviewInset - room };
1716
- return (
1717
- (framedTop(els, band) ?? top) >= top && Math.max(...rects.map((r) => r.bottom)) <= band.bottom
1718
- );
1873
+ const band = { top, bottom: bottom - reviewInset - (spacePx(rootEl, 1) ?? 0) };
1874
+ const lowest = Math.max(extent?.bottom ?? -Infinity, ...rects.map((r) => r.bottom));
1875
+ return (framedTop(els, band) ?? top) >= top && lowest <= band.bottom;
1719
1876
  }
1720
1877
  /** Whether any of the item `id` shows in that view, which is where its answer card stands.
1721
1878
  * An editor with no box of its own measures nothing, and every item counts as shown. */
@@ -1724,8 +1881,6 @@
1724
1881
  const { top, bottom } = pane();
1725
1882
  return boxes(reviewEls(id)).some((r) => r.bottom > top && r.top < bottom - reviewInset);
1726
1883
  }
1727
- /** The room the answer card takes under a change, in `--_qm-space` rungs. */
1728
- const CARD_ROOM = 7;
1729
1884
 
1730
1885
  /** Whether the item `id` is listed in `group`. */
1731
1886
  function inGroup(group: string): (id: string) => boolean {
@@ -2000,7 +2155,7 @@
2000
2155
  if (addr.field == null) return undefined;
2001
2156
  const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
2002
2157
  const schema = quill.schema;
2003
- const card = addr.card == null ? schema.main : kind ? schema.card_kinds?.[kind] : undefined;
2158
+ const card = addr.card == null ? schema.main : kind ? schema[kind] : undefined;
2004
2159
  return card?.fields?.[addr.field];
2005
2160
  }
2006
2161
 
@@ -2033,6 +2188,7 @@
2033
2188
  onkeydowncapture={onTyped}
2034
2189
  onpointerdowncapture={onPick}
2035
2190
  onfocusin={onArrive}
2191
+ onfocusout={onLeave}
2036
2192
  onkeydown={raiseGuidance}
2037
2193
  ondragover={refuseFiles}
2038
2194
  ondrop={refuseFiles}
@@ -2076,13 +2232,16 @@
2076
2232
  {@const removal = reviewing.cards.removes.get(c.id)}
2077
2233
  <div class="qm-card-slot" bind:this={slotEls[i]} animate:reorder={arm.armed} in:slot out:slot>
2078
2234
  <!-- A removal's mark wraps the whole card it would take out, so the answer card
2079
- stands under the card and not on it. -->
2235
+ stands under the card and not on it. A step lands the focus on it, out of the Tab
2236
+ walk. -->
2237
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
2080
2238
  <div
2081
2239
  class={[
2082
- 'qm-review-card-remove',
2240
+ 'qm-review-card-remove qm-focus-ring',
2083
2241
  { 'qm-review-on': !!removal, 'qm-review-lit': !!removal && reviewing.lit === removal.id }
2084
2242
  ]}
2085
2243
  data-qm-review={removal?.id}
2244
+ tabindex={removal ? -1 : undefined}
2086
2245
  role={removal ? 'group' : undefined}
2087
2246
  aria-label={removal ? merged.reviewRemoveCard : undefined}
2088
2247
  >
@@ -2115,11 +2274,13 @@
2115
2274
  root={rootEl}
2116
2275
  inset={reviewInset}
2117
2276
  hidden={typing}
2277
+ {asked}
2118
2278
  outdated={reviewing.lit !== undefined && drewOutdated.includes(reviewing.lit)}
2119
2279
  note={reviewing.lit === undefined
2120
2280
  ? undefined
2121
2281
  : reviewing.items.find((i) => i.id === reviewing.lit)?.note}
2122
2282
  onAnswer={answerCurrent}
2283
+ onStep={(dir) => void step(dir, false)}
2123
2284
  />
2124
2285
  <div class="qm-visually-hidden" role="status">{reviewPlace}</div>
2125
2286
  <!-- Beside the review's region rather than in it or in the toast's: a status is read whole,
@@ -2163,7 +2324,7 @@
2163
2324
 
2164
2325
  <FormatPopover {getActiveLeaf} families={fontFamilies} {fontLabels} />
2165
2326
 
2166
- <!-- The add affordance is gated on the schema declaring `card_kinds`, there being
2327
+ <!-- The add affordance is gated on the schema declaring a card kind, there being
2167
2328
  nothing to seed otherwise. Cards render regardless: a kind with no schema degrades to
2168
2329
  a recovery shell inside <Card> (retype + delete), never gated away, so its content is
2169
2330
  neither dropped nor trapped. The gate lives here rather than at each call site: the
@@ -2179,8 +2340,12 @@
2179
2340
  {@const preview = previewOf(item)}
2180
2341
  <!-- svelte-ignore a11y_no_static_element_interactions -->
2181
2342
  <div
2182
- class={['qm-review-card-add', { 'qm-review-lit': reviewing.lit === item.id }]}
2343
+ class={[
2344
+ 'qm-review-card-add qm-focus-ring',
2345
+ { 'qm-review-lit': reviewing.lit === item.id }
2346
+ ]}
2183
2347
  data-qm-review={item.id}
2348
+ tabindex="-1"
2184
2349
  role="group"
2185
2350
  aria-label={`${merged.reviewNewCard}, ${preview.title}`}
2186
2351
  >
@@ -2252,7 +2417,7 @@
2252
2417
  <div class="qm-menu-surface" data-qm-root>
2253
2418
  {#each kinds as k (k)}
2254
2419
  <DropdownMenu.Item class="qm-menu-item" onSelect={() => addPicked(atIndex, k)}
2255
- >{kindTitle(quill.schema.card_kinds?.[k], k)}</DropdownMenu.Item
2420
+ >{kindTitle(quill.schema[k], k)}</DropdownMenu.Item
2256
2421
  >
2257
2422
  {/each}
2258
2423
  </div>
@@ -0,0 +1,14 @@
1
+ /** A control that keeps its own keys: a form control, or anything the reader types in under
2
+ * any spelling of `contenteditable` but `false`, which the nearest one holding it decides. */
3
+ export declare function textBox(target: Element): boolean;
4
+ /** A review key by name, as a host lists the ones a text box hands over. */
5
+ export type ReviewKeyName = 'accept' | 'dismiss' | 'next' | 'previous' | 'undo';
6
+ /**
7
+ * Whether review key `key` pressed at `target` is the review's: anywhere on the page but under
8
+ * a modal the editor stands outside, inside another editor, or in a text box outside the editor.
9
+ * A text box the host marks `data-qm-review-keys` hands over the keys it has no use for: all of
10
+ * them with the attribute empty, the ones it names otherwise, so a prompt holding a draft can
11
+ * hand over accept and keep dismiss for its own delete. With no `root`, every editor on the
12
+ * page counts as the one asking.
13
+ */
14
+ export declare function reviewKeysHeard(target: EventTarget | null, root?: Element, key?: ReviewKeyName): boolean;
@@ -0,0 +1,58 @@
1
+ /** A control that keeps its own keys: a form control, or anything the reader types in under
2
+ * any spelling of `contenteditable` but `false`, which the nearest one holding it decides. */
3
+ export function textBox(target) {
4
+ if (target.closest('input, textarea, select'))
5
+ return true;
6
+ const editable = target.closest('[contenteditable]');
7
+ return !!editable && editable.getAttribute('contenteditable')?.toLowerCase() !== 'false';
8
+ }
9
+ const MODALS = '[aria-modal="true"], dialog[open]';
10
+ /** Whether `el` is a modal on show. A `<dialog>` is one only as `showModal` opens it, and
11
+ * counts as one where the engine has no `:modal` to ask. */
12
+ function modal(el) {
13
+ if (el.checkVisibility?.() === false)
14
+ return false;
15
+ if (!(el instanceof HTMLDialogElement))
16
+ return true;
17
+ try {
18
+ return el.matches(':modal');
19
+ }
20
+ catch {
21
+ return true;
22
+ }
23
+ }
24
+ /** Whether a modal on show stands over the editor: one holding neither `root` nor, with no
25
+ * `root`, any editor. A key under it is the dialog's wherever the focus is, on the page behind
26
+ * it included. */
27
+ function underModal(root) {
28
+ for (const el of document.querySelectorAll(MODALS))
29
+ if (modal(el) && !(root ? el.contains(root) : el.querySelector('.qm-editor')))
30
+ return true;
31
+ return false;
32
+ }
33
+ /** Whether the text box holding `target` hands the review `key`: `data-qm-review-keys` empty
34
+ * hands every key over, and a list of names hands those alone. */
35
+ function handedOver(target, key) {
36
+ const box = target.closest('[data-qm-review-keys]');
37
+ if (!box)
38
+ return false;
39
+ const names = box.getAttribute('data-qm-review-keys').split(/\s+/).filter(Boolean);
40
+ return !names.length || (key !== undefined && names.includes(key));
41
+ }
42
+ /**
43
+ * Whether review key `key` pressed at `target` is the review's: anywhere on the page but under
44
+ * a modal the editor stands outside, inside another editor, or in a text box outside the editor.
45
+ * A text box the host marks `data-qm-review-keys` hands over the keys it has no use for: all of
46
+ * them with the attribute empty, the ones it names otherwise, so a prompt holding a draft can
47
+ * hand over accept and keep dismiss for its own delete. With no `root`, every editor on the
48
+ * page counts as the one asking.
49
+ */
50
+ export function reviewKeysHeard(target, root, key) {
51
+ if (!(target instanceof Element) || underModal(root))
52
+ return false;
53
+ if (root ? root.contains(target) : target.closest('.qm-editor'))
54
+ return true;
55
+ if (target.closest('.qm-editor'))
56
+ return false;
57
+ return !textBox(target) || handedOver(target, key);
58
+ }
@@ -13,5 +13,7 @@ export { proposalsBetween, reviewRevised } from './proposals.js';
13
13
  export type { Proposed, ProposalsOpts } from './proposals.js';
14
14
  export type { ReviewAction } from '../core/codec/index.js';
15
15
  export { REVIEW_KEYS } from '../core/codec/index.js';
16
+ export { reviewKeysHeard } from './hears.js';
17
+ export type { ReviewKeyName } from './hears.js';
16
18
  export { patchEditorExt } from './ext.js';
17
19
  export type { ActiveLeaf, CardId, CardOp, ChangeSource, EditorChange } from './signals.js';
@@ -27,6 +27,7 @@ export { DEFAULT_VISUAL_STRINGS } from './strings.js';
27
27
  export { editorShortcuts } from '../core/codec/index.js';
28
28
  export { proposalsBetween, reviewRevised } from './proposals.js';
29
29
  export { REVIEW_KEYS } from '../core/codec/index.js';
30
+ export { reviewKeysHeard } from './hears.js';
30
31
  // The `$ext.editor` write unit. A consumer seeding editor-side chrome
31
32
  // state (a card title, the tips channel) goes through this rather than `storeExt`,
32
33
  // which replaces the whole map and takes every sibling with it.
@@ -196,7 +196,7 @@ export function proposalsBetween(quill, base, answer, opts = {}) {
196
196
  }
197
197
  kept.set(answerAt, at);
198
198
  const first = items.length;
199
- diffCard(quill.schema.card_kinds?.[was.kind], at, was, now, answerAt);
199
+ diffCard(quill.schema[was.kind], at, was, now, answerAt);
200
200
  if (id)
201
201
  for (const item of items.slice(first))
202
202
  Object.assign(item, { card: id });
@@ -63,6 +63,8 @@ export interface Review {
63
63
  /** The item the caret is in, `undefined` where it left one: arriving names it at once, and
64
64
  * leaving names nothing. */
65
65
  point(id: string | undefined): void;
66
+ /** A count that moves each time the caret lands on a change, the current one included. */
67
+ readonly landed: number;
66
68
  /** A reader's answer. False where it could not be made. */
67
69
  act(id: string, action: ReviewAction): boolean;
68
70
  /** Answer items as the answer card would, in the page's order: `'all'` is every item drawn,