@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.
Files changed (66) hide show
  1. package/README.md +18 -14
  2. package/THEMING.md +1 -1
  3. package/dist/core/codec/decode.d.ts +4 -2
  4. package/dist/core/codec/decode.js +5 -2
  5. package/dist/core/codec/field.d.ts +13 -10
  6. package/dist/core/codec/field.js +30 -24
  7. package/dist/core/codec/index.d.ts +3 -3
  8. package/dist/core/codec/index.js +2 -2
  9. package/dist/core/codec/prose.css +14 -4
  10. package/dist/core/codec/review.d.ts +4 -5
  11. package/dist/core/codec/review.js +6 -21
  12. package/dist/core/codec/schema.d.ts +12 -2
  13. package/dist/core/codec/schema.js +27 -5
  14. package/dist/core/codec/shortcuts.d.ts +3 -2
  15. package/dist/core/codec/shortcuts.js +3 -2
  16. package/dist/core/codec/table-view.js +15 -3
  17. package/dist/core/theme.css +39 -13
  18. package/dist/core/tooltip.css +49 -0
  19. package/dist/core/tooltip.d.ts +6 -0
  20. package/dist/core/tooltip.js +176 -0
  21. package/dist/preview/Preview.svelte +22 -1
  22. package/dist/preview/controller.js +38 -0
  23. package/dist/preview/strings.d.ts +2 -0
  24. package/dist/preview/strings.js +1 -0
  25. package/dist/visual/ArrayField.svelte +190 -86
  26. package/dist/visual/Card.svelte +21 -11
  27. package/dist/visual/CardControls.svelte +3 -3
  28. package/dist/visual/DateField.svelte +47 -5
  29. package/dist/visual/DiagnosticList.svelte +3 -2
  30. package/dist/visual/EnumField.svelte +6 -1
  31. package/dist/visual/EnumField.svelte.d.ts +2 -0
  32. package/dist/visual/Field.svelte +3 -3
  33. package/dist/visual/FieldHint.svelte +19 -8
  34. package/dist/visual/FormatPopover.svelte +53 -20
  35. package/dist/visual/MatrixField.svelte +7 -3
  36. package/dist/visual/NumberField.svelte +21 -5
  37. package/dist/visual/ObjectField.svelte +6 -2
  38. package/dist/visual/ProseField.svelte +6 -3
  39. package/dist/visual/ProseField.svelte.d.ts +2 -1
  40. package/dist/visual/ProseValue.svelte +11 -6
  41. package/dist/visual/ProseValue.svelte.d.ts +4 -1
  42. package/dist/visual/ReviewCard.svelte +85 -32
  43. package/dist/visual/ReviewCard.svelte.d.ts +2 -1
  44. package/dist/visual/ReviewProposal.svelte +0 -6
  45. package/dist/visual/TipsCard.svelte +1 -1
  46. package/dist/visual/VariantField.svelte +1 -0
  47. package/dist/visual/VisualEditor.svelte +12 -6
  48. package/dist/visual/VisualEditor.svelte.d.ts +5 -1
  49. package/dist/visual/VisualEditorInner.svelte +187 -275
  50. package/dist/visual/VisualEditorInner.svelte.d.ts +5 -1
  51. package/dist/visual/controls.css +2 -2
  52. package/dist/visual/index.d.ts +2 -2
  53. package/dist/visual/proposals.d.ts +14 -4
  54. package/dist/visual/proposals.js +28 -5
  55. package/dist/visual/props.d.ts +1 -1
  56. package/dist/visual/review-order.d.ts +51 -0
  57. package/dist/visual/review-order.js +87 -0
  58. package/dist/visual/review.d.ts +27 -1
  59. package/dist/visual/review.js +1 -1
  60. package/dist/visual/review.svelte.d.ts +34 -17
  61. package/dist/visual/review.svelte.js +187 -44
  62. package/dist/visual/strings.d.ts +36 -19
  63. package/dist/visual/strings.js +80 -24
  64. package/dist/visual/structure.d.ts +17 -3
  65. package/dist/visual/structure.js +71 -5
  66. package/package.json +2 -2
@@ -44,6 +44,7 @@
44
44
  import { bloom } from '../core/bloom.js';
45
45
  import { createLifespan } from '../core/teardown.js';
46
46
  import { spacePx } from '../core/rungs.js';
47
+ import { tooltips } from '../core/tooltip.js';
47
48
  import type {
48
49
  Addr,
49
50
  CardAddr,
@@ -57,8 +58,8 @@
57
58
  } from '@quillmark/wasm';
58
59
  import type { VisualEditorProps } from './props.js';
59
60
  import type { Delta } from '../core/codec/positions.js';
60
- import { mergeStrings, setWording } from './strings.js';
61
- import { createStructuralUndo, setStructuralUndo, type UndoOffer } from './undo.svelte.js';
61
+ import { diagnosticText, mergeStrings, setWording } from './strings.js';
62
+ import { createStructuralUndo, setStructuralUndo } from './undo.svelte.js';
62
63
  import { undoChord } from './listhistory.js';
63
64
  import { removedCards, type RemovedCard } from './removed.js';
64
65
  import { createReview, setReview, type CardAdd } from './review.svelte.js';
@@ -78,6 +79,7 @@
78
79
  type ReviewProjection
79
80
  } from './review.js';
80
81
  import ReviewCard from './ReviewCard.svelte';
82
+ import { cardLayout, nextOpen, stepIn } from './review-order.js';
81
83
  import type { CardId, CardOp, ChangeSource } from './signals.js';
82
84
  import {
83
85
  REVIEW_KEYS,
@@ -97,6 +99,7 @@
97
99
  fieldValues,
98
100
  fieldTitle,
99
101
  humanize,
102
+ placeCardInto,
100
103
  bodyEnabled,
101
104
  provenanceMap,
102
105
  resolvedByCardIndex,
@@ -231,7 +234,7 @@
231
234
  function report(source: ChangeSource, cardId?: CardId, at?: Addr | number, op?: CardOp): void {
232
235
  const path =
233
236
  at == null ? undefined : typeof at === 'number' ? cardPath(at, liveKinds()) : pathFor(at);
234
- settled();
237
+ reviewing.settled();
235
238
  onChange?.({ source, cardId, path, ...(op ? { op } : {}) });
236
239
  }
237
240
  function rederive(): void {
@@ -355,13 +358,26 @@
355
358
  reviewing.heard(id, 'reopen', leaf);
356
359
  void reveal(id, false, true);
357
360
  };
358
- /** The host's list with each card it names by index moved to where that card stands now. */
361
+ /** The session key of the card holding `$id` `id`. */
362
+ function cardKeyFor(id: string): string | undefined {
363
+ return cardIds.find((_, k) => doc.card(k).id === id);
364
+ }
365
+ /** The host's list with each card a path names moved to where that card stands now: the card
366
+ * holding the item's `card`, else the one at the path's index when the list was set. */
359
367
  const reviewItems = $derived.by(() => {
360
368
  const was = cardsListed();
361
- if (!review?.length || was === cardIds) return review;
369
+ const now = cardIds;
370
+ if (!review?.length) return review;
371
+ if (was === now && !review.some((item) => 'card' in item && item.card !== undefined))
372
+ return review;
362
373
  return review.map((item) => {
363
374
  if (byCard(item)) return item;
364
- const field = cardMoved(item.field, was, cardIds);
375
+ let field: DocPath;
376
+ if (item.card === undefined) field = cardMoved(item.field, was, now);
377
+ else {
378
+ const key = cardKeyFor(item.card);
379
+ field = pathOnCard(item.field, key === undefined ? now.length : now.indexOf(key));
380
+ }
365
381
  return field === item.field ? item : { ...item, field };
366
382
  });
367
383
  });
@@ -388,16 +404,13 @@
388
404
  return card?.values[key.field];
389
405
  },
390
406
  leafFor: proseKeyFor,
407
+ layout: () => [cardLayout(model.main), ...model.cards.map(cardLayout)],
391
408
  listedCards: () => cardsListed(),
392
409
  liveCards: () => cardIds,
393
- answered(id, current) {
394
- if (!current) return;
395
- if (batching) advancing = id;
396
- else advanceFrom(id, drewOrder);
397
- },
398
- writing(on) {
399
- writing += on ? 1 : -1;
400
- },
410
+ cardFor: cardKeyFor,
411
+ undo,
412
+ answered: (id, order) => advanceFrom(id, order ?? drewOrder),
413
+ answerProse: (key, id, action) => !!leaves.prose(key)?.answerReview(id, action),
401
414
  answer(id, item, action, key, write) {
402
415
  let back: (() => void) | undefined;
403
416
  if (write && item && onField(item)) {
@@ -409,73 +422,19 @@
409
422
  }
410
423
  onReview?.({ id, action });
411
424
  if (action !== 'accept' && action !== 'dismiss') return true;
412
- if (item && byCard(item)) {
413
- record(id, () => giveBack(id, '', back));
414
- return true;
415
- }
425
+ if (item && byCard(item)) return () => giveBack(id, '', back);
416
426
  const field = item && onField(item) ? reviewed(item.field) : undefined;
417
427
  const leaf = key ?? (field && fieldKeyToString(field));
418
428
  if (leaf === undefined) return true;
419
429
  const prose = key !== undefined && !field;
420
- record(
421
- id,
422
- prose
423
- ? action === 'accept'
424
- ? () => void leaves.prose(leaf)?.undoReview()
425
- : () => void leaves.prose(leaf)?.reopenReview(id)
426
- : () => giveBack(id, leaf, back)
427
- );
428
- return true;
430
+ return prose
431
+ ? action === 'accept'
432
+ ? () => void leaves.prose(leaf)?.undoReview()
433
+ : () => void leaves.prose(leaf)?.reopenReview(id)
434
+ : () => giveBack(id, leaf, back);
429
435
  }
430
436
  });
431
437
 
432
- // ── The answer journal: the review answers since the reader's last edit, each undone by
433
- // ⌘Z from anywhere in the editor, newest first, its item reopened with it. An edit that is
434
- // not an answer empties it: an inverse is good against the document it was recorded over. An answer's own writes, and an inverse's, go down the
435
- // lanes an edit does, so they are flagged while they are made.
436
- interface Answered {
437
- ids: string[];
438
- inverses: (() => void)[];
439
- }
440
- let journal: Answered[] = [];
441
- /** The entry a batch of answers records into. */
442
- let batching: Answered | undefined;
443
- let journalOffer: UndoOffer | undefined;
444
- let writing = 0;
445
- function settled(): void {
446
- if (writing) return;
447
- journal = [];
448
- journalOffer = undefined;
449
- undo.settle();
450
- }
451
- function offerJournal(): void {
452
- const top = journal.at(-1);
453
- journalOffer = top && undo.offer('', unanswer, { standing: true, quiet: true, answer: true });
454
- }
455
- function unanswer(): void {
456
- const top = journal.pop();
457
- if (!top) return;
458
- writing++;
459
- try {
460
- for (const inverse of [...top.inverses].reverse()) inverse();
461
- } finally {
462
- writing--;
463
- }
464
- offerJournal();
465
- }
466
- function record(id: string, inverse: () => void): void {
467
- if (batching) {
468
- batching.ids.push(id);
469
- batching.inverses.push(inverse);
470
- return;
471
- }
472
- // Another step took the key since: the answers before it are no longer the last thing
473
- // that happened.
474
- if (!journalOffer || !undo.holds(journalOffer)) journal = [];
475
- journal.push({ ids: [id], inverses: [inverse] });
476
- offerJournal();
477
- }
478
-
479
438
  /**
480
439
  * Take a field's proposal: its value down the lane the field's own control commits by, so
481
440
  * the writer checks it and `onChange` reports it, or `edit`, the value a reader's own commit
@@ -499,7 +458,7 @@
499
458
  leaves.prose(leaf)?.applyExternal();
500
459
  return true;
501
460
  };
502
- writing++;
461
+ reviewing.writing(true);
503
462
  try {
504
463
  const before = doc.getStored(addr);
505
464
  const to = (place: unknown): unknown => (edit ? edit.value : reviewing.writes(item, place));
@@ -513,7 +472,7 @@
513
472
  if (!write(after)) return undefined;
514
473
  return () => void write(before);
515
474
  } finally {
516
- writing--;
475
+ reviewing.writing(false);
517
476
  }
518
477
 
519
478
  /** The field's value as its control is handed it, read anew. */
@@ -532,9 +491,9 @@
532
491
  */
533
492
  function takeCard(item: CardProposal): (() => void) | undefined {
534
493
  if ('remove' in item) {
535
- const key = cardsListed()[item.remove];
494
+ const key = item.card === undefined ? cardsListed()[item.remove] : cardKeyFor(item.card);
536
495
  const at = key === undefined ? -1 : cardIndexOf(key);
537
- if (at < 0) return undefined;
496
+ if (key === undefined || at < 0) return undefined;
538
497
  const card = doc.card(at);
539
498
  doc.removeCard(at);
540
499
  undo.withdraw();
@@ -576,15 +535,8 @@
576
535
  }
577
536
  /** Write `card` into the document at `at`, with its `$id` where no card holds that one. */
578
537
  function placeCard(card: CardAdd['add'], at: number): boolean {
579
- const { id, ...bare } = card;
580
- const free = id !== undefined && !cardIds.some((_, k) => doc.card(k).id === id);
581
538
  try {
582
- try {
583
- doc.unchecked.insertCard(free ? card : bare, at);
584
- } catch (e) {
585
- if (!free) throw e;
586
- doc.unchecked.insertCard(bare, at);
587
- }
539
+ placeCardInto(doc, card, at);
588
540
  return true;
589
541
  } catch (e) {
590
542
  reportError(onError, {
@@ -622,7 +574,6 @@
622
574
  return { title, fields, text: add.body?.text?.trim() ?? '' };
623
575
  }
624
576
  setReview(reviewing);
625
- span.onEnd(reviewing.dispose);
626
577
  // The current change, to a host counting its place: each change, and not the nothing a
627
578
  // mount starts from.
628
579
  let reported: string | undefined;
@@ -633,56 +584,6 @@
633
584
  typing = false;
634
585
  onReviewFocus?.(id);
635
586
  });
636
- /** The open items drawn, in document order: each id's first element under the root, then
637
- * any drawn one not yet in the DOM, in list order. */
638
- function reviewOrder(): string[] {
639
- const fieldUndrawn = new Set(reviewing.fieldUndrawn.map((u) => u.id));
640
- const drawn = new Set<string>();
641
- for (const report of reviewing.reports.values()) for (const id of report.ids) drawn.add(id);
642
- for (const item of reviewing.items)
643
- if (onField(item) && !fieldUndrawn.has(item.id)) drawn.add(item.id);
644
- for (const list of reviewing.cards.adds.values()) for (const item of list) drawn.add(item.id);
645
- for (const item of reviewing.cards.removes.values()) drawn.add(item.id);
646
- const order: string[] = [];
647
- const seen = new Set<string>();
648
- const take = (id: string | null): void => {
649
- if (id === null || !drawn.has(id) || seen.has(id)) return;
650
- seen.add(id);
651
- order.push(id);
652
- };
653
- for (const el of rootEl?.querySelectorAll('[data-qm-review]') ?? [])
654
- for (const id of reviewIds(el)) take(id);
655
- for (const item of reviewing.items) take(item.id);
656
- return order;
657
- }
658
- /** What the editor draws of the host's list, and why it draws what it does not. */
659
- function reviewReport(): ReviewDrawn {
660
- const reported = new Set<string>();
661
- const outdated = new Set(reviewing.fieldOutdated);
662
- const why = new Map<string, ReviewDrawn['undrawn'][number]['reason']>();
663
- for (const report of reviewing.reports.values()) {
664
- for (const id of report.ids) reported.add(id);
665
- for (const id of report.outdated) outdated.add(id);
666
- for (const { id, reason } of report.undrawn) {
667
- reported.add(id);
668
- why.set(id, reason);
669
- }
670
- }
671
- for (const { id, reason } of reviewing.fieldUndrawn) why.set(id, reason);
672
- for (const item of reviewing.items)
673
- if (!reported.has(item.id) && !why.has(item.id)) {
674
- if (byBlocks(item)) why.set(item.id, 'block');
675
- }
676
- const open = reviewOrder();
677
- return {
678
- open,
679
- outdated: open.filter((id) => outdated.has(id)),
680
- undrawn: reviewing.items.flatMap((item) => {
681
- const reason = why.get(item.id);
682
- return reason ? [{ id: item.id, reason }] : [];
683
- })
684
- };
685
- }
686
587
  // The report, to a host counting its own list: each change, read once the leaves the change
687
588
  // mounted have drawn, so a list just handed over is not reported as anchored nowhere. A
688
589
  // review starts on its first change, and goes on to the first open one wherever the current
@@ -692,15 +593,11 @@
692
593
  let drewOrder = $state.raw<readonly string[]>([]);
693
594
  let drewOutdated = $state.raw<readonly string[]>([]);
694
595
  $effect(() => {
695
- void reviewing.items;
696
- void reviewing.fieldUndrawn;
697
- void reviewing.cards;
698
- for (const id of reviewing.fieldOutdated) void id;
699
- for (const report of reviewing.reports.values()) void report;
596
+ void reviewing.report;
700
597
  let live = true;
701
598
  void tick().then(() => {
702
599
  if (!live || !span.alive) return;
703
- const report = reviewReport();
600
+ const report = reviewing.report;
704
601
  drewOrder = report.open;
705
602
  drewOutdated = report.outdated;
706
603
  if (reviewing.lit === undefined && report.open.length) reviewing.reveal(report.open[0]);
@@ -713,19 +610,13 @@
713
610
  live = false;
714
611
  };
715
612
  });
716
- /** The current change answered by a host's batch, to move on from once the batch is done. */
717
- let advancing: string | undefined;
718
613
  /**
719
614
  * Make the next open change current after `id`'s answer, in `order` as it stood before the
720
615
  * answer, round from the end. The pane scrolls only where that change is out of comfortable
721
616
  * view, and neither the focus nor the caret moves.
722
617
  */
723
618
  function advanceFrom(id: string, order: readonly string[]): void {
724
- const open = new Set(reviewing.items.map((item) => item.id));
725
- const at = order.indexOf(id);
726
- const next = [...order.slice(at + 1), ...order.slice(0, Math.max(at, 0))].find((n) =>
727
- open.has(n)
728
- );
619
+ const next = nextOpen(order, id, new Set(reviewing.items.map((item) => item.id)));
729
620
  if (next === undefined) return;
730
621
  typing = false;
731
622
  reviewing.reveal(next);
@@ -734,22 +625,17 @@
734
625
  /** The item a step last went to, and where it stood in the order then, so a step from an
735
626
  * item since answered goes on from its place. */
736
627
  let stepped: { id: string; index: number } | undefined;
737
- async function step(dir: 1 | -1, focus: boolean): Promise<string | undefined> {
628
+ async function step(dir: 1 | -1, focus: boolean, group?: string): Promise<string | undefined> {
738
629
  if (!span.alive) return undefined;
739
- const order = reviewOrder();
740
- if (!order.length) return undefined;
741
- const at = order.indexOf(reviewing.lit ?? stepped?.id ?? '');
742
- const next =
743
- at >= 0
744
- ? at + dir
745
- : stepped
746
- ? dir > 0
747
- ? stepped.index
748
- : stepped.index - 1
749
- : dir > 0
750
- ? 0
751
- : -1;
752
- const index = ((next % order.length) + order.length) % order.length;
630
+ const order = reviewing.order;
631
+ const index = stepIn(
632
+ order,
633
+ dir,
634
+ reviewing.lit ?? stepped?.id,
635
+ stepped?.index,
636
+ group === undefined ? undefined : inGroup(group)
637
+ );
638
+ if (index === undefined) return undefined;
753
639
  const id = order[index];
754
640
  stepped = { id, index };
755
641
  typing = false;
@@ -763,6 +649,17 @@
763
649
  const id = reviewing.lit;
764
650
  return id !== undefined && answerReview([id], action).length > 0;
765
651
  }
652
+ /** An answer key: the card's, so it answers only a change the card stands on in view. A
653
+ * press while the reader types in the editor is the leaf's own key, and any other press
654
+ * with the change out of view or the card out of the way brings both back. */
655
+ function answerByKey(action: 'accept' | 'dismiss'): boolean {
656
+ const id = reviewing.lit;
657
+ if (id === undefined || (typing && inside)) return false;
658
+ if (!typing && inView(id)) return answerCurrent(action);
659
+ typing = false;
660
+ void reveal(id, false, true);
661
+ return true;
662
+ }
766
663
  /** Whether a key at `target` is the review's: anywhere but a text control outside the editor,
767
664
  * which keeps its own keys, or another editor. */
768
665
  function reviewHears(target: EventTarget | null): boolean {
@@ -773,8 +670,8 @@
773
670
  }
774
671
  let answerCard = $state<ReviewCard | undefined>();
775
672
  const reviewKeys = keydownHandler({
776
- [REVIEW_KEYS.accept]: () => answerCurrent('accept'),
777
- [REVIEW_KEYS.dismiss]: () => answerCurrent('dismiss'),
673
+ [REVIEW_KEYS.accept]: () => answerByKey('accept'),
674
+ [REVIEW_KEYS.dismiss]: () => answerByKey('dismiss'),
778
675
  [REVIEW_KEYS.next]: () => {
779
676
  void step(1, inside);
780
677
  return true;
@@ -955,7 +852,7 @@
955
852
  const cardId = cardIdOf(plain);
956
853
  if (cardId == null) return;
957
854
  refreshTitle(plain, cardId);
958
- settled();
855
+ reviewing.settled();
959
856
  onChange?.({ source: 'prose', cardId, path: pathFor(plain) });
960
857
  }
961
858
 
@@ -1209,10 +1106,7 @@
1209
1106
  const { card } = gone;
1210
1107
  const i = removed.place(gone, cardIds);
1211
1108
  try {
1212
- const taken = card.id !== undefined && cardIds.some((_, k) => doc.card(k).id === card.id);
1213
- const back = { ...card };
1214
- if (taken) delete back.id;
1215
- doc.unchecked.insertCard(back, i);
1109
+ placeCardInto(doc, card, i);
1216
1110
  } catch (e) {
1217
1111
  reportError(onError, {
1218
1112
  code: 'card-op-failed',
@@ -1458,6 +1352,38 @@
1458
1352
  cards: tree.cards.map((c) => patched[c.id] ?? c)
1459
1353
  });
1460
1354
 
1355
+ // ── What a screen reader hears of the diagnostics (INVARIANTS §Diagnostics) ──
1356
+ /** How long the drawn errors hold before they are spoken, so an edit's validation and
1357
+ * the diagnostics a host raises for it are one announcement, and a set that returns
1358
+ * to what was last said meanwhile says nothing. */
1359
+ const SPOKEN_MS = 500;
1360
+ /** Every error a leaf of the page draws, in the page's order, under its field's label. */
1361
+ const issues = $derived(
1362
+ [model.main, ...model.cards].flatMap((card) =>
1363
+ cardLayout(card).leaves.flatMap(({ key, name, schema }) => {
1364
+ const field = name !== undefined && schema ? fieldTitle(name, schema) : merged.bodyLabel;
1365
+ return (diagByKey.get(key) ?? []).map((d) => ({
1366
+ field,
1367
+ message: diagnosticText(d, formatDiagnostic, merged)
1368
+ }));
1369
+ })
1370
+ )
1371
+ );
1372
+ const issuesKey = $derived(JSON.stringify(issues));
1373
+ // What a mount starts from is not a change, so the first set is held as said.
1374
+ let spokenKey: string | undefined;
1375
+ let spoken = $state('');
1376
+ $effect(() => {
1377
+ const key = issuesKey;
1378
+ spokenKey ??= key;
1379
+ if (key === spokenKey) return;
1380
+ const timer = setTimeout(() => {
1381
+ spokenKey = issuesKey;
1382
+ spoken = merged.diagAnnounced(issues);
1383
+ }, SPOKEN_MS);
1384
+ return () => clearTimeout(timer);
1385
+ });
1386
+
1461
1387
  // ── Public entry points ─────────────────────────────────────────────────────
1462
1388
  /**
1463
1389
  * Resolve a preview {@link Landing} to a mounted leaf and land in it.
@@ -1574,6 +1500,16 @@
1574
1500
  const box = await land(found, undefined);
1575
1501
  if (span.alive) bloom(box);
1576
1502
  }
1503
+ /** Reveal the field at `field`, scroll it into the fold and wash it, taking no focus:
1504
+ * the landing a host makes on a touch screen, where a focus raises the keyboard. A
1505
+ * nested address reveals and washes its field, a row being something only a focus
1506
+ * opens. */
1507
+ export async function revealField(field: DocPath): Promise<void> {
1508
+ const found = await revealLeaf(field);
1509
+ if (!found) return missed(`no mounted field at ${field}`, field);
1510
+ found.control.el.scrollIntoView({ block: 'nearest', behavior: 'instant' });
1511
+ bloom(found.control.el);
1512
+ }
1577
1513
  /** Play the arrival wash over the field at `field` and touch nothing else: no focus,
1578
1514
  * no reveal, no scroll. A field in a closed panel is skipped, its box clipped to
1579
1515
  * nothing; a nested address washes its field's box, a row being something only a
@@ -1667,9 +1603,7 @@
1667
1603
  leaves.control(key)?.focus();
1668
1604
  // The current item is drawn again, so its element is read once it has been.
1669
1605
  if (!(await span.resumes(tick()))) return false;
1670
- const els = [...(rootEl?.querySelectorAll<HTMLElement>('[data-qm-review]') ?? [])].filter(
1671
- (el) => reviewIds(el).includes(id)
1672
- );
1606
+ const els = reviewEls(id);
1673
1607
  const at =
1674
1608
  (key !== undefined ? leaves.prose(key)?.reviewElements(id)[0] : undefined) ??
1675
1609
  els[0] ??
@@ -1686,78 +1620,72 @@
1686
1620
  for (const item of reviewing.cards.removes.values()) if (item.id === id) return true;
1687
1621
  return false;
1688
1622
  }
1689
- /** Whether `els` stand in the view the editor scrolls in, clear of the host's chrome at its
1690
- * foot, with the answer card's room under them. */
1691
- function comfortable(els: readonly HTMLElement[]): boolean {
1692
- const rects = els.map((el) => el.getBoundingClientRect()).filter((r) => r.width || r.height);
1693
- if (!rects.length) return false;
1694
- let top = 0;
1695
- let bottom = window.innerHeight;
1623
+ /** The elements that draw the item `id`. */
1624
+ function reviewEls(id: string): HTMLElement[] {
1625
+ return [...(rootEl?.querySelectorAll<HTMLElement>('[data-qm-review]') ?? [])].filter((el) =>
1626
+ reviewIds(el).includes(id)
1627
+ );
1628
+ }
1629
+ /** The band of the window the editor shows through: its nearest scroller's. */
1630
+ function pane(): { top: number; bottom: number } {
1696
1631
  for (let at = rootEl ?? null; at; at = at.parentElement) {
1697
1632
  const { overflowY } = getComputedStyle(at);
1698
1633
  if (overflowY !== 'auto' && overflowY !== 'scroll') continue;
1699
1634
  const box = at.getBoundingClientRect();
1700
- top = Math.max(box.top, 0);
1701
- bottom = Math.min(box.bottom, window.innerHeight);
1702
- break;
1635
+ return { top: Math.max(box.top, 0), bottom: Math.min(box.bottom, window.innerHeight) };
1703
1636
  }
1637
+ return { top: 0, bottom: window.innerHeight };
1638
+ }
1639
+ const boxes = (els: readonly HTMLElement[]): DOMRect[] =>
1640
+ els.map((el) => el.getBoundingClientRect()).filter((r) => r.width || r.height);
1641
+ /** Whether `els` stand in the view the editor scrolls in, clear of the host's chrome at its
1642
+ * foot, with the answer card's room under them. */
1643
+ function comfortable(els: readonly HTMLElement[]): boolean {
1644
+ const rects = boxes(els);
1645
+ if (!rects.length) return false;
1646
+ const { top, bottom } = pane();
1704
1647
  const room = (spacePx(rootEl, 1) ?? 0) * CARD_ROOM;
1705
1648
  return (
1706
1649
  Math.min(...rects.map((r) => r.top)) >= top &&
1707
1650
  Math.max(...rects.map((r) => r.bottom)) <= bottom - reviewInset - room
1708
1651
  );
1709
1652
  }
1653
+ /** Whether any of the item `id` shows in that view, which is where its answer card stands.
1654
+ * An editor with no box of its own measures nothing, and every item counts as shown. */
1655
+ function inView(id: string): boolean {
1656
+ if (!rootEl || !boxes([rootEl]).length) return true;
1657
+ const { top, bottom } = pane();
1658
+ return boxes(reviewEls(id)).some((r) => r.bottom > top && r.top < bottom - reviewInset);
1659
+ }
1710
1660
  /** The room the answer card takes under a change, in `--_qm-space` rungs. */
1711
1661
  const CARD_ROOM = 7;
1712
1662
 
1663
+ /** Whether the item `id` is listed in `group`. */
1664
+ function inGroup(group: string): (id: string) => boolean {
1665
+ const ids = new Set(reviewing.items.filter((i) => i.group === group).map((i) => i.id));
1666
+ return (id) => ids.has(id);
1667
+ }
1668
+
1713
1669
  /**
1714
- * Answer items as the answer card would, in document order: `'all'` is every item drawn. An
1670
+ * Answer items as the answer card would, in document order: `'all'` is every item drawn, and
1671
+ * `{ group }` every item drawn in that group, which as `'all'` does accepts none outdated. An
1715
1672
  * item that cannot be answered (a proposal that no longer writes, a value the field's writer
1716
1673
  * refuses) stands. `onReview` hears each answer, and neither the focus nor the caret moves;
1717
1674
  * where the current change is answered, the next open one is current. ⌘Z takes the call
1718
1675
  * back whole. Returns the ids answered.
1719
1676
  */
1720
1677
  export function answerReview(
1721
- ids: readonly string[] | 'all',
1678
+ ids: readonly string[] | 'all' | { group: string },
1722
1679
  action: 'accept' | 'dismiss'
1723
1680
  ): string[] {
1724
1681
  if (!span.alive) return [];
1725
- const order = reviewOrder();
1726
- // Accepting every item leaves the outdated ones open: each would write over the reader.
1727
- const outdated = new Set(ids === 'all' && action === 'accept' ? reviewReport().outdated : []);
1728
- const asked =
1729
- ids === 'all'
1730
- ? order.filter((id) => !outdated.has(id))
1731
- : order.filter((id) => ids.includes(id));
1732
- const out: string[] = [];
1733
- const entry: Answered = { ids: [], inverses: [] };
1734
- batching = entry;
1735
- writing++;
1736
- try {
1737
- for (const id of asked) {
1738
- const item = reviewing.items.find((it) => it.id === id);
1739
- if (!item) continue;
1740
- const key = reviewing.keyOf(id);
1741
- // Each one is planned against the document the one before it left.
1742
- const answered =
1743
- onField(item) || byCard(item)
1744
- ? reviewing.act(id, action)
1745
- : key !== undefined && !!leaves.prose(key)?.answerReview(id, action);
1746
- if (answered) out.push(id);
1747
- }
1748
- } finally {
1749
- writing--;
1750
- batching = undefined;
1751
- }
1752
- if (entry.ids.length) {
1753
- if (!journalOffer || !undo.holds(journalOffer)) journal = [];
1754
- journal.push(entry);
1755
- offerJournal();
1756
- }
1757
- const from = advancing;
1758
- advancing = undefined;
1759
- if (from !== undefined) advanceFrom(from, order);
1760
- return out;
1682
+ if (ids === 'all' || Array.isArray(ids)) return reviewing.answer(ids, action);
1683
+ const has = inGroup((ids as { group: string }).group);
1684
+ const stale = new Set(action === 'accept' ? drewOutdated : []);
1685
+ return reviewing.answer(
1686
+ reviewing.order.filter((id) => has(id) && !stale.has(id)),
1687
+ action
1688
+ );
1761
1689
  }
1762
1690
 
1763
1691
  /**
@@ -1770,7 +1698,7 @@
1770
1698
  */
1771
1699
  export function projectReview(target: Document): ReviewProjection {
1772
1700
  if (!span.alive) return NO_PROJECTION;
1773
- const order = reviewOrder();
1701
+ const order = reviewing.order;
1774
1702
  if (!order.length) return NO_PROJECTION;
1775
1703
  const open = new Set(order);
1776
1704
  const byId = new Map(reviewing.items.map((item) => [item.id, item]));
@@ -1928,17 +1856,8 @@
1928
1856
  /** Write `card` into `target` at `at`, with its `$id` where no card there holds that one,
1929
1857
  * as {@link placeCard} writes it into the document. */
1930
1858
  function placeCardIn(target: Document, card: CardAdd['add'], at: number): boolean {
1931
- const { id, ...bare } = card;
1932
- const free =
1933
- id !== undefined &&
1934
- !Array.from({ length: target.cardCount }, (_, k) => target.card(k).id).includes(id);
1935
1859
  try {
1936
- try {
1937
- target.unchecked.insertCard(free ? card : bare, at);
1938
- } catch (e) {
1939
- if (!free) throw e;
1940
- target.unchecked.insertCard(bare, at);
1941
- }
1860
+ placeCardInto(target, card, at);
1942
1861
  return true;
1943
1862
  } catch {
1944
1863
  return false;
@@ -1947,12 +1866,13 @@
1947
1866
 
1948
1867
  /** Make the next or previous open item current, in document order and round from either
1949
1868
  * end, from the current item or the one last stepped to: the caret in it, or the focus in
1950
- * its field, unless `focus` is false. Resolves its id, `undefined` when none is drawn. */
1869
+ * its field, unless `focus` is false. With `group`, only that group's items are stepped to.
1870
+ * Resolves its id, `undefined` when none is drawn. */
1951
1871
  export function stepReview(
1952
1872
  dir: 1 | -1,
1953
- opts: { focus?: boolean } = {}
1873
+ opts: { focus?: boolean; group?: string } = {}
1954
1874
  ): Promise<string | undefined> {
1955
- return step(dir, opts.focus ?? true);
1875
+ return step(dir, opts.focus ?? true, opts.group);
1956
1876
  }
1957
1877
 
1958
1878
  function holds(cardId: CardId): boolean {
@@ -2038,6 +1958,7 @@
2038
1958
  {style}
2039
1959
  data-qm-root
2040
1960
  bind:this={rootEl}
1961
+ {@attach tooltips}
2041
1962
  onkeydowncapture={onTyped}
2042
1963
  onpointerdowncapture={onPick}
2043
1964
  onkeydown={raiseGuidance}
@@ -2092,8 +2013,6 @@
2092
2013
  data-qm-review={removal?.id}
2093
2014
  role={removal ? 'group' : undefined}
2094
2015
  aria-label={removal ? merged.reviewRemoveCard : undefined}
2095
- onpointerenter={removal && (() => reviewing.point(removal.id, 'pointer'))}
2096
- onpointerleave={removal && (() => reviewing.point(undefined, 'pointer'))}
2097
2016
  >
2098
2017
  <Card
2099
2018
  bind:this={cardRefs[i]}
@@ -2125,10 +2044,15 @@
2125
2044
  inset={reviewInset}
2126
2045
  hidden={typing}
2127
2046
  outdated={reviewing.lit !== undefined && drewOutdated.includes(reviewing.lit)}
2047
+ note={reviewing.lit === undefined
2048
+ ? undefined
2049
+ : reviewing.items.find((i) => i.id === reviewing.lit)?.note}
2128
2050
  onAnswer={answerCurrent}
2129
- onHover={(on) => reviewing.hoverCard(on)}
2130
2051
  />
2131
2052
  <div class="qm-visually-hidden" role="status">{reviewPlace}</div>
2053
+ <!-- Beside the review's region rather than in it or in the toast's: a status is read whole,
2054
+ so a shared one would repeat what the other said. -->
2055
+ <div class="qm-visually-hidden qm-diag-live" role="status">{spoken}</div>
2132
2056
  <!-- The way back to a removed card once its toast has gone: the newest kept step, by
2133
2057
  name, at the stack's foot, where the control that adds a card is looked for. -->
2134
2058
  {#if undo.kept}
@@ -2156,7 +2080,7 @@
2156
2080
  <span class="qm-toast-notice">{undo.current.notice}</span>
2157
2081
  <button
2158
2082
  type="button"
2159
- class="qm-toast-action qm-focus-ring"
2083
+ class="qm-toast-action qm-chip qm-focus-ring"
2160
2084
  aria-keyshortcuts="Meta+Z Control+Z"
2161
2085
  onclick={() => undo.take()}>{merged.undoAction}</button
2162
2086
  >
@@ -2186,9 +2110,7 @@
2186
2110
  class={['qm-review-card-add', { 'qm-review-lit': reviewing.lit === item.id }]}
2187
2111
  data-qm-review={item.id}
2188
2112
  role="group"
2189
- aria-label={merged.reviewNewCard}
2190
- onpointerenter={() => reviewing.point(item.id, 'pointer')}
2191
- onpointerleave={() => reviewing.point(undefined, 'pointer')}
2113
+ aria-label={`${merged.reviewNewCard}, ${preview.title}`}
2192
2114
  >
2193
2115
  <div class="qm-review-card-add-head">
2194
2116
  <span class="qm-review-card-add-title">{preview.title}</span>
@@ -2217,14 +2139,14 @@
2217
2139
  on hover is the space the new card takes. -->
2218
2140
  {@const marked = atIndex === model.cards.length}
2219
2141
  <div class={['qm-add-card', { 'qm-add-card-marked': marked }]}>
2220
- <!-- Marked, the words are the accessible name and no `aria-label` doubles
2221
- them; bare, the same words land as the label, the strip having no
2222
- content to carry them. -->
2142
+ <!-- The string is the name on every strip: marked, the strip draws a `+` ahead
2143
+ of the words, which is the template's glyph and no part of the name; bare,
2144
+ it has no content to carry them. -->
2223
2145
  {#if kinds.length === 1}
2224
2146
  <button
2225
2147
  type="button"
2226
2148
  class="qm-add-btn qm-add-affordance qm-tap-floor qm-focus-ring"
2227
- aria-label={marked ? undefined : merged.addCard}
2149
+ aria-label={merged.addCard}
2228
2150
  onclick={() => addCard(atIndex, kinds[0], true)}
2229
2151
  >{#if marked}{`+ ${merged.addCard}`}{/if}</button
2230
2152
  >
@@ -2237,7 +2159,7 @@
2237
2159
  <DropdownMenu.Root>
2238
2160
  <DropdownMenu.Trigger
2239
2161
  class="qm-add-btn qm-add-affordance qm-tap-floor qm-focus-ring"
2240
- aria-label={marked ? undefined : merged.addCard}
2162
+ aria-label={merged.addCard}
2241
2163
  >{#if marked}{`+ ${merged.addCard}`}{/if}</DropdownMenu.Trigger
2242
2164
  >
2243
2165
  <DropdownMenu.Portal to={rootEl}>
@@ -2298,19 +2220,14 @@
2298
2220
  color: var(--_qm-ink);
2299
2221
  pointer-events: auto;
2300
2222
  }
2223
+ /* A chip (controls.css), in the toast's own corner. It stands at the ink and the chrome's
2224
+ weight where a chip rests at the label rung: it is the one action here, and the notice
2225
+ beside it is at the ink, so a rung under that would set the action quieter than the
2226
+ sentence it acts on. */
2301
2227
  .qm-toast-action {
2302
- min-height: var(--_qm-tap-min);
2303
- padding-inline: var(--_qm-space-2);
2304
- border: 0;
2305
2228
  border-radius: var(--_qm-radius-pill);
2306
- background: transparent;
2307
- font: inherit;
2308
- font-weight: var(--_qm-weight-strong);
2309
- color: var(--_qm-accent);
2310
- cursor: pointer;
2311
- }
2312
- .qm-toast-action:hover {
2313
- background: var(--_qm-accent-tint);
2229
+ font-weight: var(--_qm-weight-mid);
2230
+ color: var(--_qm-ink);
2314
2231
  }
2315
2232
  /* Words at the label ink, unboxed: the stack's foot already holds one outlined pill, and
2316
2233
  a second would stand as its equal. */
@@ -2430,7 +2347,7 @@
2430
2347
  }
2431
2348
  /* A card proposed new and a card proposed taken out, in the review's one hue: a preview
2432
2349
  where the new card would stand, the card's own ground under the tint, and a mark round
2433
- the whole of a card that would go, its words receding as a struck word's do. The
2350
+ the whole of a card that would go, its values struck as a removed row's are. The
2434
2351
  current one's mark is a step stronger, as a current proposal's words are. */
2435
2352
  .qm-review-card-remove {
2436
2353
  display: contents;
@@ -2440,9 +2357,6 @@
2440
2357
  border-radius: var(--_qm-radius);
2441
2358
  box-shadow: 0 0 0 var(--_qm-border-width) var(--_qm-review-line);
2442
2359
  }
2443
- .qm-review-card-remove.qm-review-on > :global(.qm-card) {
2444
- opacity: var(--_qm-opacity-muted);
2445
- }
2446
2360
  .qm-review-card-remove.qm-review-lit {
2447
2361
  box-shadow: 0 0 0 var(--_qm-vertical-width) var(--_qm-review-line);
2448
2362
  }
@@ -2515,8 +2429,8 @@
2515
2429
  box-shadow: inset 0 0 0 var(--_qm-vertical-width) var(--_qm-review-line);
2516
2430
  }
2517
2431
  /* A row a proposal would take out: no tint, which only ever means "would come", but a ring
2518
- in the review line laid outside the row so it takes no room, its values dimmed and struck
2519
- and its labels left alone. The current one's ring is a step stronger, as a removed card's. */
2432
+ in the review line laid outside the row so it takes no room, its values struck and its
2433
+ labels left alone. The current one's ring is a step stronger, as a removed card's. */
2520
2434
  :global([data-qm-removed]) {
2521
2435
  border-radius: var(--_qm-radius-inner);
2522
2436
  box-shadow: 0 0 0 var(--_qm-border-width) var(--_qm-review-line);
@@ -2524,17 +2438,15 @@
2524
2438
  :global([data-qm-removed-lit]) {
2525
2439
  box-shadow: 0 0 0 var(--_qm-vertical-width) var(--_qm-review-line);
2526
2440
  }
2441
+ /* What a removed row or card holds is what the reader reads to answer it, so its words
2442
+ step back to the label ink under the strike, as a struck word does in a paragraph
2443
+ (`codec/prose.css`), and no further: the ring, the strike and the tag say removed. A
2444
+ switch and a tick have no word to strike and keep their state as drawn. */
2527
2445
  :global(
2528
- [data-qm-removed]
2529
- :is(
2530
- .qm-control-box:not(.qm-element-summary),
2531
- .qm-toggle,
2532
- .qm-tick,
2533
- .qm-input,
2534
- .qm-element-preview
2535
- )
2446
+ :is([data-qm-removed], .qm-review-card-remove.qm-review-on)
2447
+ :is(.qm-control-box:not(.qm-element-summary), .qm-input, .qm-prose, .qm-element-preview)
2536
2448
  ) {
2537
- opacity: var(--_qm-opacity-muted);
2449
+ color: var(--_qm-ink-label);
2538
2450
  text-decoration: line-through;
2539
2451
  text-decoration-color: var(--_qm-review-line);
2540
2452
  }