@quillmark/svelte 0.29.3 → 0.31.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 (63) hide show
  1. package/README.md +3 -3
  2. package/dist/core/address.d.ts +3 -3
  3. package/dist/core/address.js +1 -1
  4. package/dist/core/codec/decode.d.ts +4 -5
  5. package/dist/core/codec/decode.js +151 -208
  6. package/dist/core/codec/encode.d.ts +13 -35
  7. package/dist/core/codec/encode.js +127 -408
  8. package/dist/core/codec/field.d.ts +11 -10
  9. package/dist/core/codec/field.js +190 -92
  10. package/dist/core/codec/index.d.ts +2 -2
  11. package/dist/core/codec/index.js +4 -4
  12. package/dist/core/codec/islands.d.ts +13 -9
  13. package/dist/core/codec/islands.js +54 -49
  14. package/dist/core/codec/marks.d.ts +12 -18
  15. package/dist/core/codec/marks.js +16 -26
  16. package/dist/core/codec/positions.d.ts +25 -7
  17. package/dist/core/codec/positions.js +43 -50
  18. package/dist/core/codec/prose.css +0 -8
  19. package/dist/core/codec/schema.d.ts +3 -3
  20. package/dist/core/codec/schema.js +29 -11
  21. package/dist/core/codec/slash.d.ts +4 -2
  22. package/dist/core/codec/slash.js +13 -3
  23. package/dist/core/codec/table-copy.d.ts +3 -3
  24. package/dist/core/codec/table-copy.js +6 -4
  25. package/dist/core/codec/table-paste.js +13 -9
  26. package/dist/core/codec/table-view.js +19 -12
  27. package/dist/core/codec/table.d.ts +77 -43
  28. package/dist/core/codec/table.js +157 -48
  29. package/dist/core/index.d.ts +1 -0
  30. package/dist/core/theme.css +14 -6
  31. package/dist/visual/ArrayField.svelte +168 -83
  32. package/dist/visual/BooleanField.svelte +2 -2
  33. package/dist/visual/Card.svelte +65 -44
  34. package/dist/visual/DateField.svelte +16 -1
  35. package/dist/visual/DiagnosticList.svelte +34 -2
  36. package/dist/visual/EnumField.svelte +58 -44
  37. package/dist/visual/Field.svelte +13 -3
  38. package/dist/visual/Field.svelte.d.ts +3 -1
  39. package/dist/visual/FieldHint.svelte +10 -3
  40. package/dist/visual/FormatPopover.svelte +1 -1
  41. package/dist/visual/MatrixAdd.svelte +3 -18
  42. package/dist/visual/MatrixField.svelte +20 -12
  43. package/dist/visual/ObjectField.svelte +164 -145
  44. package/dist/visual/ProseField.svelte +6 -1
  45. package/dist/visual/ProseValue.svelte +8 -8
  46. package/dist/visual/SlashMenu.svelte +24 -12
  47. package/dist/visual/SlashMenu.svelte.d.ts +2 -0
  48. package/dist/visual/VisualEditor.svelte +1 -1
  49. package/dist/visual/VisualEditor.svelte.d.ts +1 -1
  50. package/dist/visual/VisualEditorInner.svelte +159 -18
  51. package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
  52. package/dist/visual/controls.css +42 -4
  53. package/dist/visual/leaves.d.ts +1 -1
  54. package/dist/visual/leaves.js +1 -1
  55. package/dist/visual/strings.d.ts +27 -10
  56. package/dist/visual/strings.js +40 -6
  57. package/dist/visual/structure.d.ts +17 -9
  58. package/dist/visual/structure.js +20 -26
  59. package/dist/visual/undo.svelte.d.ts +36 -0
  60. package/dist/visual/undo.svelte.js +119 -0
  61. package/package.json +2 -2
  62. package/dist/visual/hold.d.ts +0 -17
  63. package/dist/visual/hold.js +0 -39
@@ -37,7 +37,6 @@
37
37
  import type {
38
38
  Addr,
39
39
  CardAddr,
40
- Delta,
41
40
  Diagnostic,
42
41
  PathStep,
43
42
  PayloadItem,
@@ -46,7 +45,9 @@
46
45
  ResolvedField
47
46
  } from '@quillmark/wasm';
48
47
  import type { VisualEditorProps } from './props.js';
48
+ import type { Delta } from '../core/codec/positions.js';
49
49
  import { mergeStrings, setWording } from './strings.js';
50
+ import { createStructuralUndo, setStructuralUndo } from './undo.svelte.js';
50
51
  import type { CardId, CardOp, ChangeSource } from './signals.js';
51
52
  import type { FieldController, LeafViews } from '../core/codec/index.js';
52
53
  import {
@@ -178,7 +179,8 @@
178
179
  * key is a host's only handle on a card, so a stale one is dropped rather than
179
180
  * reported. */
180
181
  function cardIdOf(addr: Addr): CardId | undefined {
181
- return addr.card == null ? 'main' : cardIds[addr.card];
182
+ if (addr.card == null) return 'main';
183
+ return typeof addr.card === 'number' ? cardIds[addr.card] : undefined;
182
184
  }
183
185
 
184
186
  // ── Teardown (core/teardown.ts: unregister, cancel, then free) ──────────────
@@ -199,6 +201,23 @@
199
201
  // going away as a whole, where a leaf's cleanup order relative to the parent's
200
202
  // is Svelte's business and not something to depend on.
201
203
  span.onEnd(() => leaves.clear());
204
+
205
+ // The removal's one step back (`undo.svelte.ts`), published so an array's row removal
206
+ // offers on the same toast a card's does.
207
+ const undo = createStructuralUndo();
208
+ setStructuralUndo(undo);
209
+ span.onEnd(undo.dispose);
210
+ /** ⌘Z/Ctrl+Z takes the standing offer where the offer accepts it (`undo.accepts`).
211
+ * On the document, since a removal under the pointer leaves the focus on the body, and
212
+ * captured, so a leaf the removal handed the focus to hears the key after the offer. */
213
+ function onUndoKey(e: KeyboardEvent): void {
214
+ if (e.defaultPrevented || e.isComposing || e.shiftKey || e.altKey) return;
215
+ if (!(e.metaKey || e.ctrlKey) || e.key.toLowerCase() !== 'z') return;
216
+ if (!undo.accepts(e.target, rootEl)) return;
217
+ e.preventDefault();
218
+ e.stopPropagation();
219
+ undo.take();
220
+ }
202
221
  // Card handles, for `setCaret`'s reveal hop: the one thing a leaf's own controller
203
222
  // cannot do, since which group is open is the card's state (Card §revealLeaf).
204
223
  type CardHandle = {
@@ -299,7 +318,7 @@
299
318
  let liveTitles = $state<Record<CardId, string>>({});
300
319
  function refreshTitle(addr: Addr, cardId: CardId): void {
301
320
  const { card: at, field } = addr;
302
- if (at == null || field == null) return;
321
+ if (typeof at !== 'number' || field == null) return;
303
322
  const shown = model.cards[at];
304
323
  const cardSchema = shown && quill.schema.card_kinds?.[shown.kind];
305
324
  if (!cardSchema || cardSchema.title?.trim()) return;
@@ -318,7 +337,7 @@
318
337
  // ── Commit routing ──────────────────────────────────────────────────────────
319
338
  // Scalars / arrays / objects → the typed writer (schema-checked); a cleared entry
320
339
  // arrives as `undefined` and takes the unset lane instead. Prose leaves commit
321
- // themselves via the codec (applyChange) and do not pass through here.
340
+ // themselves via the codec (`apply`) and do not pass through here.
322
341
  //
323
342
  // A bad value makes `writer.set` throw a `QuillmarkError` whose `diagnostics[0]`
324
343
  // carries a `code` and a canonical `path` (`edit::field_coercion_failed` at
@@ -419,7 +438,8 @@
419
438
  const card = quill.seedCard(kind, overlay);
420
439
  if (!card) return undefined;
421
440
  const from = document.activeElement;
422
- doc.insertCard(card, atIndex);
441
+ doc.unchecked.insertCard(card, atIndex);
442
+ undo.withdraw();
423
443
  const id = seq.next();
424
444
  arm.arm();
425
445
  cardIds = [...cardIds.slice(0, atIndex), id, ...cardIds.slice(atIndex)];
@@ -482,6 +502,7 @@
482
502
  if (to < 0 || to >= doc.cardCount) return;
483
503
  arm.arm();
484
504
  doc.moveCard(from, to);
505
+ undo.withdraw();
485
506
  const w = cardIds.slice();
486
507
  const [x] = w.splice(from, 1);
487
508
  w.splice(to, 0, x);
@@ -498,6 +519,12 @@
498
519
  // pressed button, and the hand-on is the keyboard's.
499
520
  const focused = document.activeElement;
500
521
  const held = !!focused && !!slotEls[i]?.contains(focused) && focused.matches(':focus-visible');
522
+ const card = doc.card(i);
523
+ const shown = model.cards[i];
524
+ const name =
525
+ shown?.titleOverride ||
526
+ shown?.titlePlaceholder ||
527
+ kindTitle(quill.schema.card_kinds?.[card.kind], card.kind);
501
528
  doc.removeCard(i);
502
529
  arm.arm();
503
530
  cardIds = cardIds.filter((_, k) => k !== i);
@@ -505,8 +532,35 @@
505
532
  // No addr: the removed card has none left and every survivor's shifted. The
506
533
  // stack changed, not a leaf, and the id is the only handle the removal leaves.
507
534
  bump('structure', id, undefined, { op: 'remove', at: i });
535
+ undo.offer(merged.undoRemoved(name), () => restoreCard(card, i));
508
536
  if (held) void focusAfterRemove(i);
509
537
  }
538
+ /** The removal's undo: the card back at the index it left, under a fresh session key
539
+ * (ids are never reused), with the focus on its title. The document holds what it held
540
+ * before the removal, so the insert is the removal's exact inverse. */
541
+ function restoreCard(card: ReturnType<typeof doc.card>, at: number): void {
542
+ if (!span.alive) return;
543
+ const i = Math.min(at, cardIds.length);
544
+ try {
545
+ doc.unchecked.insertCard(card, i);
546
+ } catch (e) {
547
+ reportError(onError, {
548
+ code: 'card-op-failed',
549
+ severity: 'error',
550
+ message: `restoring the ${card.kind} card failed: ${errorMessage(e)}`,
551
+ cause: e
552
+ });
553
+ return;
554
+ }
555
+ const id = seq.next();
556
+ arm.arm();
557
+ cardIds = [...cardIds.slice(0, i), id, ...cardIds.slice(i)];
558
+ bump('structure', id, i, { op: 'insert', at: i });
559
+ void (async () => {
560
+ if (!(await scrollCardIntoView(id, 'nearest'))) return;
561
+ cardRefs[cardIndexOf(id)]?.focusHeader();
562
+ })();
563
+ }
510
564
  /** Drop what the surface holds for a removed card. Ids are never reused, so an entry
511
565
  * keyed to the gone card is unreachable rather than mis-attributed to whichever card
512
566
  * takes this position: it needs dropping because nothing else will ever clear it. */
@@ -526,17 +580,24 @@
526
580
  if (!(await span.resumes(tick()))) return;
527
581
  if (cardIds.length) cardRefs[Math.max(at - 1, 0)]?.focusHeader();
528
582
  else rootEl?.querySelector<HTMLElement>('.qm-add-btn')?.focus();
583
+ undo.hand(document.activeElement);
529
584
  }
530
585
  function retypeCardById(id: string, kind: string): void {
531
586
  const i = cardIndexOf(id);
532
587
  if (i < 0) return;
533
588
  try {
534
- // Insert the retyped card ahead of the original and drop the original after.
535
- // `insertCard` validates the whole card before it mutates and `removeCard`
536
- // cannot throw, so a refusal leaves the document as it was; the reverse order
537
- // would leave it a card short.
538
- doc.insertCard({ ...doc.card(i), kind }, i);
539
- doc.removeCard(i + 1);
589
+ // The retyped card keeps the original's `$id`, which two cards cannot hold at
590
+ // once, so the original goes first and comes back where `insertCard` refuses:
591
+ // it validates the whole card before it mutates, so the document is as it was.
592
+ const card = doc.card(i);
593
+ doc.removeCard(i);
594
+ undo.withdraw();
595
+ try {
596
+ doc.unchecked.insertCard({ ...card, kind }, i);
597
+ } catch (e) {
598
+ doc.unchecked.insertCard(card, i);
599
+ throw e;
600
+ }
540
601
  bump('structure', id, i);
541
602
  } catch (e) {
542
603
  reportError(onError, {
@@ -788,7 +849,7 @@
788
849
  }
789
850
 
790
851
  /**
791
- * Put the caret in a revealed target, at the finest grain it can take: a USV offset
852
+ * Put the caret in a revealed target, at the finest grain it can take: a UTF-16 offset
792
853
  * in a prose leaf or a nested content cell, a bare focus everywhere else. A form
793
854
  * control has no coordinate to spend an offset in (an `<input type="number">`
794
855
  * refuses a selection outright), which is also the whole of what a click on
@@ -889,6 +950,7 @@
889
950
  * order it applied them, so every card that stays keeps its leaves. */
890
951
  export function applyCardOps(ops: readonly CardOp[]): void {
891
952
  if (!span.alive) return;
953
+ undo.withdraw();
892
954
  const ids = cardIds.slice();
893
955
  for (const op of ops) {
894
956
  if (op.op === 'insert') ids.splice(op.at, 0, seq.next());
@@ -951,13 +1013,15 @@
951
1013
  * second reading of the schema beside it. */
952
1014
  function declaredField(addr: Addr): QuillFieldSchema | undefined {
953
1015
  if (addr.field == null) return undefined;
954
- const kind = addr.card == null ? undefined : model.cards[addr.card]?.kind;
1016
+ const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
955
1017
  const schema = quill.schema;
956
1018
  const card = addr.card == null ? schema.main : kind ? schema.card_kinds?.[kind] : undefined;
957
1019
  return card?.fields?.[addr.field];
958
1020
  }
959
1021
  </script>
960
1022
 
1023
+ <svelte:document onkeydowncapture={onUndoKey} />
1024
+
961
1025
  <!-- The keydown is a control's, bubbled: the root resolves which description it raises. -->
962
1026
  <!-- svelte-ignore a11y_no_static_element_interactions -->
963
1027
  <div
@@ -1022,6 +1086,29 @@
1022
1086
  {@render addAffordance(i + 1)}
1023
1087
  </div>
1024
1088
  {/each}
1089
+ <!-- The removal's undo. The region stands empty between offers so the notice it takes is
1090
+ announced: a live region inserted along with its text is one a reader may not hear. -->
1091
+ <div class="qm-toast-slot" role="status">
1092
+ {#if undo.current}
1093
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
1094
+ <!-- The handlers hold the lapse while the toast is in use and add no interaction. -->
1095
+ <div
1096
+ class="qm-toast"
1097
+ onpointerenter={() => undo.pause()}
1098
+ onpointerleave={() => undo.resume()}
1099
+ onfocusin={() => undo.pause()}
1100
+ onfocusout={() => undo.resume()}
1101
+ >
1102
+ <span class="qm-toast-notice">{undo.current.notice}</span>
1103
+ <button
1104
+ type="button"
1105
+ class="qm-toast-action qm-focus-ring"
1106
+ aria-keyshortcuts="Meta+Z Control+Z"
1107
+ onclick={() => undo.take()}>{merged.undoAction}</button
1108
+ >
1109
+ </div>
1110
+ {/if}
1111
+ </div>
1025
1112
  </div>
1026
1113
 
1027
1114
  <FormatPopover {getActiveLeaf} families={fontFamilies} {fontLabels} />
@@ -1093,6 +1180,47 @@
1093
1180
  {/snippet}
1094
1181
 
1095
1182
  <style>
1183
+ /* Pinned to the foot of whatever scrolls the surface, and taking no room in the stack:
1184
+ zero tall, its gap handed back, so an offer raises a toast over the cards without
1185
+ moving one. */
1186
+ .qm-toast-slot {
1187
+ position: sticky;
1188
+ bottom: var(--toast-foot, var(--_qm-space-3));
1189
+ z-index: 1;
1190
+ display: flex;
1191
+ justify-content: center;
1192
+ align-items: flex-end;
1193
+ height: 0;
1194
+ margin-top: calc(-1 * var(--_qm-space-2));
1195
+ pointer-events: none;
1196
+ }
1197
+ .qm-toast {
1198
+ display: flex;
1199
+ align-items: center;
1200
+ gap: var(--_qm-space-3);
1201
+ padding: var(--_qm-space) var(--_qm-space) var(--_qm-space) var(--_qm-space-3);
1202
+ border: var(--_qm-border-width) solid var(--_qm-border);
1203
+ border-radius: var(--_qm-radius-pill);
1204
+ background: var(--_qm-surface-raised);
1205
+ box-shadow: var(--_qm-lift);
1206
+ font-size: var(--_qm-text-label);
1207
+ color: var(--_qm-ink);
1208
+ pointer-events: auto;
1209
+ }
1210
+ .qm-toast-action {
1211
+ min-height: var(--_qm-tap-min);
1212
+ padding-inline: var(--_qm-space-2);
1213
+ border: 0;
1214
+ border-radius: var(--_qm-radius-pill);
1215
+ background: transparent;
1216
+ font: inherit;
1217
+ font-weight: var(--_qm-weight-strong);
1218
+ color: var(--_qm-accent);
1219
+ cursor: pointer;
1220
+ }
1221
+ .qm-toast-action:hover {
1222
+ background: var(--_qm-accent-tint);
1223
+ }
1096
1224
  /* A detached root, carrying `data-qm-root` for the derivation core/theme.css applies
1097
1225
  to one — the baseline font and colour included, so nothing here restates them.
1098
1226
 
@@ -1158,6 +1286,10 @@
1158
1286
  overscroll-behavior: contain;
1159
1287
  padding: var(--_qm-space-4);
1160
1288
  padding-block-end: var(--_qm-tail);
1289
+ /* The pane is the toast's scroller, and a sticky box stops at its scroller's
1290
+ padding: the tail would hold the toast a tail's height off the pane's foot. On a
1291
+ page the viewport scrolls, and the surface's padding is no bar. */
1292
+ --toast-foot: calc(var(--_qm-space-3) - var(--_qm-tail));
1161
1293
  }
1162
1294
  /* The stack's one gapless seam, which `TipsCard` draws and this holds the two
1163
1295
  blocks to. `main` has to paint over the tip: a later sibling paints over an earlier
@@ -1208,8 +1340,8 @@
1208
1340
  `.qm-tap-floor`'s (controls.css); what it overhangs is the card's own inset above and
1209
1341
  below, which holds no target, so the floor costs a neighbour nothing.
1210
1342
 
1211
- Ink is pinned to the label tone in every state, taking back the family's hover step:
1212
- the trigger arrives and leaves on opacity, and a tone moving under an opacity already
1343
+ A gap's ink is pinned to the label tone in every state, taking back the family's hover
1344
+ step: the trigger arrives and leaves on opacity, and a tone moving under an opacity already
1213
1345
  moving reads as two trips at different speeds.
1214
1346
 
1215
1347
  `:global`, because the multi-kind trigger is bits-ui's own element and a `class`
@@ -1227,13 +1359,22 @@
1227
1359
  opacity var(--_qm-duration-fast) var(--_qm-ease-reverse),
1228
1360
  background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
1229
1361
  }
1230
- /* The strip that holds words at rest takes the height that centres them, and rests dim
1231
- rather than absent, having something to be seen. */
1362
+ /* The append point is the one strip read at rest, so it is a pill sized to its words
1363
+ at the ink, outlined by the well's hairline rather than dashed: the document's main
1364
+ structural action stands as plainly as the controls inside a card. */
1365
+ .qm-add-card-marked {
1366
+ justify-content: center;
1367
+ }
1232
1368
  .qm-add-card-marked :global(.qm-add-btn) {
1369
+ width: auto;
1233
1370
  height: var(--_qm-tap-min);
1371
+ padding-inline: var(--_qm-space-3);
1234
1372
  font-size: var(--_qm-text-label);
1235
1373
  font-weight: var(--_qm-weight-mid);
1236
- opacity: var(--_qm-opacity-idle);
1374
+ color: var(--_qm-ink);
1375
+ background: var(--_qm-surface);
1376
+ box-shadow: inset 0 0 0 var(--_qm-border-width) var(--_qm-well-edge);
1377
+ opacity: 1;
1237
1378
  }
1238
1379
  /* One arrival, three ways in. Keyboard focus, because the fill is the only thing that
1239
1380
  reads as the trigger on a bare strip; and an open menu, because it portals out of
@@ -1,6 +1,6 @@
1
1
  import { type DocPath, type Landing } from '../core/address.js';
2
- import type { Delta } from '@quillmark/wasm';
3
2
  import type { VisualEditorProps } from './props.js';
3
+ import type { Delta } from '../core/codec/positions.js';
4
4
  import type { CardId, CardOp } from './signals.js';
5
5
  import { type ActiveProse } from './leaves.js';
6
6
  declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
@@ -90,15 +90,25 @@
90
90
  color: var(--_qm-ink);
91
91
  caret-color: currentColor;
92
92
  }
93
- /* The box is a fill and not an edge (ARCHITECTURE §Styling), and the fill is the
94
- well rung: a field is a hole cut into the card rather than a plane of its own,
95
- and with no edge to carry it the step is the whole of what says so. */
93
+ /* The box is the well rung with a hairline inside it (ARCHITECTURE §Styling): a
94
+ field is a hole cut into the card, and the edge is what finds it at a glance, the
95
+ fill alone standing too close to the card to. Inset, so the edge costs no layout
96
+ and a focus ring draws outside it. */
96
97
  :where(.qm-control-box),
97
98
  :where(.qm-input) {
98
99
  padding: var(--_qm-inset-control);
99
100
  border: none;
100
101
  border-radius: var(--_qm-radius-inner);
101
102
  background: var(--_qm-surface-well);
103
+ box-shadow: inset 0 0 0 var(--_qm-border-width) var(--_qm-well-edge);
104
+ }
105
+ /* A control with an error drawn under it takes the danger hue on its edge and in its
106
+ fill, so the field the message is about is the one that changed. The message stays
107
+ beside it: colour is never the whole of the state. */
108
+ :where(.qm-field-stack:has(> .qm-diag-list) .qm-control-box),
109
+ :where(.qm-prop-stack:has(> .qm-diag-list) .qm-control-box) {
110
+ box-shadow: inset 0 0 0 var(--_qm-ring-width) var(--_qm-danger);
111
+ background-image: linear-gradient(var(--_qm-danger-tint), var(--_qm-danger-tint));
102
112
  }
103
113
  /* What a form control adds over the box: it does not fill its row on its own. */
104
114
  :where(.qm-input) {
@@ -296,21 +306,30 @@
296
306
  of one takes (`--cols-half`) land on a track boundary. A field ends on its track's
297
307
  own edge, so a rung is `n * 220px + gaps`. A subform three rungs in stands three
298
308
  `--_qm-nest` and three verticals narrower than its section, and steps down where the
299
- section does not: the count is the width the tracks actually get. */
309
+ section does not: the count is the width the tracks actually get.
310
+
311
+ The two tails are where a run's last cell takes the row (`RunTail`, `placeFields`): the
312
+ placement a capacity leaves it alone in, so it spans there and shares a row elsewhere. */
300
313
  :where(.qm-tracks) {
301
314
  --cols: 1;
302
315
  --cols-half: 1;
316
+ --tail-odd: span 1;
317
+ --tail-lone: span 1;
303
318
  }
304
319
  @container (min-width: 28rem) {
305
320
  :where(.qm-tracks) {
306
321
  --cols: 2;
307
322
  --cols-half: 1;
323
+ --tail-odd: 1 / -1;
324
+ --tail-lone: 1 / -1;
308
325
  }
309
326
  }
310
327
  @container (min-width: 57rem) {
311
328
  :where(.qm-tracks) {
312
329
  --cols: 4;
313
330
  --cols-half: 2;
331
+ --tail-odd: span 1;
332
+ --tail-lone: 1 / -1;
314
333
  }
315
334
  }
316
335
 
@@ -420,3 +439,22 @@
420
439
  transform: scale(0.94);
421
440
  }
422
441
  }
442
+
443
+ /* Forced colours drop every fill and shadow, which is every edge a field and a chip
444
+ draw here, and keep opacity, which would leave a resting control a ghost against a
445
+ system palette. The system's own strokes stand in for both. */
446
+ @media (forced-colors: active) {
447
+ :where(.qm-control-box),
448
+ :where(.qm-input) {
449
+ border: var(--_qm-border-width) solid CanvasText;
450
+ }
451
+ :where(.qm-chip),
452
+ :where(.qm-add-affordance) {
453
+ border: var(--_qm-border-width) solid ButtonText;
454
+ }
455
+ :where(.qm-icon-btn),
456
+ :where(.qm-add-affordance),
457
+ :where(.qm-chip) {
458
+ opacity: 1;
459
+ }
460
+ }
@@ -20,7 +20,7 @@ export interface FieldControl {
20
20
  /**
21
21
  * Land at `steps` inside a control that has an inside — an array's element, an
22
22
  * object's property, a variant's cell, a matrix's member, and any of them under any
23
- * other — at USV `pos` where the leaf the walk ends in can take one. Each rung
23
+ * other — at UTF-16 offset `pos` where the leaf the walk ends in can take one. Each rung
24
24
  * resolves its own step at the call (an index to a session id, a key to a mounted
25
25
  * cell) and hands the rest to the control it opened, so nothing positional is
26
26
  * carried. A step the tree does not hold falls back to that rung's own
@@ -4,7 +4,7 @@
4
4
  // Two lanes behind one lookup. Every mounted field registers a {@link FieldControl} —
5
5
  // take the caret, and a box to bloom — which is the whole of what a reveal and a
6
6
  // focus need, and the whole of what a form control has. A prose leaf registers its
7
- // `FieldController` instead: a superset, carrying the codec seam (a caret at a USV
7
+ // `FieldController` instead: a superset, carrying the codec seam (a caret at a UTF-16
8
8
  // offset, the formatting popover's observation) that no `<input>` answers. So
9
9
  // `control` covers every field and `prose` covers the leaves that have one, and the
10
10
  // verbs ask for the half they use: `focusField` never needs the codec, and
@@ -14,6 +14,13 @@ export interface VisualStrings extends TableChromeStrings, SlashStrings {
14
14
  cardDelete: string;
15
15
  /** The card-title input's accessible name. */
16
16
  cardTitle: string;
17
+ /** A closed panel's header, spoken after its name (`Layout, has an issue`) when a field
18
+ * inside holds a diagnostic: the leading separator is part of the wording. */
19
+ groupFlagged: string;
20
+ /** The toast's notice, named for what went: `Authors 2 removed`. */
21
+ undoRemoved: (what: string) => string;
22
+ /** The toast's button, which puts it back. */
23
+ undoAction: string;
17
24
  /** The trailing strip's visible words, drawn after a `+`, and every
18
25
  * strip's accessible name. One string over
19
26
  * one kind and many: the trigger seeds a card, and which kind is the menu's word
@@ -42,16 +49,25 @@ export interface VisualStrings extends TableChromeStrings, SlashStrings {
42
49
  */
43
50
  textCount: (count: number, max: number) => string;
44
51
  /**
45
- * A collapsed array element with nothing to summarize itself by: the label and the
46
- * 1-based index, which is what its accessible name already says. Parametric, so
47
- * word order stays the translator's.
52
+ * An `object` array element's title, open or collapsed: the 1-based index, the label
53
+ * standing over the list already. Parametric, so word order stays the translator's.
54
+ */
55
+ elementItem: (index: number) => string;
56
+ /**
57
+ * An `object` array element's accessible name: the label and {@link elementItem},
58
+ * so the words the row draws are inside the name it is spoken by.
48
59
  */
49
60
  elementUntitled: (label: string, index: number) => string;
50
- /** The tag on the unset sentinel's row where it ghosts a member, which is what tells
51
- * it from that member ({@link EnumField}). */
61
+ /** `validation::type_mismatch`: the value is not the declared type (`args.expected`). */
62
+ diagTypeMismatch: (expected: string) => string;
63
+ /** `validation::format_violation`: the value misses a string format (`args.format`). */
64
+ diagFormatViolation: (format: string) => string;
65
+ /** The tag on the `default:` member's row ({@link EnumField}). */
52
66
  enumUnsetTag: string;
53
- /** The same row's tag where it ghosts no member: no `default:`, or a blank one. */
54
- enumUnsetTagNone: string;
67
+ /** The row under a stored value that clears it back to the `default:`. */
68
+ enumReset: string;
69
+ /** The same row where no `default:` prints: no `default:`, a blank one, or an `enum?`. */
70
+ enumClear: string;
55
71
  /** The count in the matrix's label row: how many of its items are held. */
56
72
  matrixHeld: (held: number, total: number) => string;
57
73
  /** An open matrix's add box at rest, naming the list it adds to: `Add to Staff…`. The box
@@ -182,6 +198,7 @@ export declare function setWording(channel: Wording): void;
182
198
  * composing one directly) still has every key.
183
199
  */
184
200
  export declare function wording(): Wording;
185
- /** A diagnostic's displayed text: the consumer's formatter, or its message. The
186
- * fallback arm is permanent, not a courtesy ({@link FormatDiagnostic}). */
187
- export declare function diagnosticText(d: Diagnostic, format: FormatDiagnostic | undefined): string;
201
+ /** A diagnostic's displayed text: the consumer's formatter, else the package's wording for
202
+ * a validation code whose `args` carry what it needs, else its message. The last arm is
203
+ * permanent, not a courtesy ({@link FormatDiagnostic}). */
204
+ export declare function diagnosticText(d: Diagnostic, format: FormatDiagnostic | undefined, strings?: VisualStrings): string;
@@ -39,6 +39,9 @@ export const DEFAULT_VISUAL_STRINGS = {
39
39
  cardMoveDown: 'Move down',
40
40
  cardDelete: 'Delete card',
41
41
  cardTitle: 'Card title',
42
+ groupFlagged: ', has an issue',
43
+ undoRemoved: (what) => `${what} removed`,
44
+ undoAction: 'Undo',
42
45
  addCard: 'Add Card',
43
46
  arrayAdd: '+ Add',
44
47
  arrayRemove: 'Remove',
@@ -46,9 +49,23 @@ export const DEFAULT_VISUAL_STRINGS = {
46
49
  arrayRowAction: (action, row) => `${action} ${row}`,
47
50
  arrayCount: (count, max) => `${count} / ${max}`,
48
51
  textCount: (count, max) => `${count} / ${max}`,
49
- elementUntitled: (label, index) => `${label} ${index}`,
52
+ elementItem: (index) => `Item ${index}`,
53
+ elementUntitled: (label, index) => `${label}, item ${index}`,
54
+ diagTypeMismatch: (expected) => expected === 'boolean'
55
+ ? 'Needs to be on or off.'
56
+ : expected === 'integer'
57
+ ? 'Needs a whole number, like 12.'
58
+ : expected === 'number'
59
+ ? 'Needs a number, like 12.'
60
+ : `Needs a ${expected} value.`,
61
+ diagFormatViolation: (format) => format === 'date'
62
+ ? 'Not a real date. Type it as YYYY-MM-DD, or press Today.'
63
+ : format === 'datetime'
64
+ ? 'Not a real date and time. Type it as YYYY-MM-DDTHH:MM.'
65
+ : `Doesn't match the ${format} format.`,
50
66
  enumUnsetTag: 'Default',
51
- enumUnsetTagNone: 'Unset',
67
+ enumReset: 'Reset to default',
68
+ enumClear: 'Clear',
52
69
  matrixHeld: (held, total) => `${held} of ${total} held`,
53
70
  matrixAdd: (list) => (list ? `Add to ${list}…` : 'Add…'),
54
71
  matrixItemTitle: (list, index) => `${list ? `${list} item` : 'Item'} ${index}`,
@@ -102,8 +119,25 @@ export function setWording(channel) {
102
119
  export function wording() {
103
120
  return (getContext(KEY) ?? { strings: DEFAULT_VISUAL_STRINGS, formatDiagnostic: undefined });
104
121
  }
105
- /** A diagnostic's displayed text: the consumer's formatter, or its message. The
106
- * fallback arm is permanent, not a courtesy ({@link FormatDiagnostic}). */
107
- export function diagnosticText(d, format) {
108
- return (format ? format(d) : undefined) ?? d.message;
122
+ /** A diagnostic's displayed text: the consumer's formatter, else the package's wording for
123
+ * a validation code whose `args` carry what it needs, else its message. The last arm is
124
+ * permanent, not a courtesy ({@link FormatDiagnostic}). */
125
+ export function diagnosticText(d, format, strings) {
126
+ return (format ? format(d) : undefined) ?? (strings && builtIn(d, strings)) ?? d.message;
127
+ }
128
+ function builtIn(d, strings) {
129
+ const args = (d.args ?? {});
130
+ const str = (k) => typeof args[k] === 'string' ? args[k] : undefined;
131
+ switch (d.code) {
132
+ case 'validation::type_mismatch': {
133
+ const expected = str('expected');
134
+ return expected ? strings.diagTypeMismatch(expected) : undefined;
135
+ }
136
+ case 'validation::format_violation': {
137
+ const format = str('format');
138
+ return format ? strings.diagFormatViolation(format) : undefined;
139
+ }
140
+ default:
141
+ return undefined;
142
+ }
109
143
  }
@@ -248,11 +248,9 @@ export declare function matrixMemberSchema(matrix: QuillFieldSchema, id: string)
248
248
  */
249
249
  export declare function schemaAt(field: QuillFieldSchema, steps: readonly PathStep[]): QuillFieldSchema | undefined;
250
250
  /**
251
- * Whether a cell is one line tall by declaration: what a table column and a row summary can hold.
251
+ * Whether a cell is one line tall by declaration: what a table column can hold.
252
252
  */
253
253
  export declare function shortCell(sub: QuillFieldSchema): boolean;
254
- /** A collapsed row's own words ({@link firstShortText}). */
255
- export declare function rowSummary(items: QuillFieldSchema | undefined, row: unknown): string | undefined;
256
254
  /** How an `array` draws its elements. */
257
255
  export type ArrayLayout = 'list' | 'table';
258
256
  /**
@@ -314,27 +312,37 @@ export declare function objectSections(fields: FieldModel[]): GroupSection[];
314
312
  */
315
313
  export declare function cardSections(cardSchema: QuillCardSchema): GroupSection[];
316
314
  /**
317
- * The group section a card's accordion opens on first mount, or `null` when the card declares none.
315
+ * The group section a card opens on first mount, or `null` when the card declares none.
318
316
  * All-collapsed would disclose nothing of what is behind the chevrons, and a rule keyed on document
319
317
  * state would move the opening under a user as they fill.
320
318
  */
321
319
  export declare function initialExpandedGroup(sections: GroupSection[]): string | null;
322
320
  /** How wide a field sits in its section grid. */
323
321
  export type FieldSpan = 'cell' | 'full';
322
+ /**
323
+ * Where a run's last cell would stand alone in its row, by capacity: `odd` at two tracks
324
+ * (an odd run), `lone` at two and four (a run one past a multiple of four). The grid
325
+ * reads it against the capacity it stands at (`--tail-odd`, `--tail-lone`, the ladder in
326
+ * controls.css), so the field takes the row only where it would be alone in it.
327
+ */
328
+ export type RunTail = 'odd' | 'lone';
324
329
  export interface PlacedField {
325
330
  field: FieldModel;
326
331
  span: FieldSpan;
332
+ tail?: RunTail;
327
333
  }
328
334
  /**
329
- * Consecutive packable fields are `cell`s the grid auto-places; a trailing orphan keeps its column
330
- * width. A run of one is `full`: a lone narrow track reads as truncated against the width it leaves
331
- * empty. Everything else is `full`. No width is measured.
335
+ * Consecutive packable fields are `cell`s the grid auto-places, and a run of one is `full`:
336
+ * alone, a field would stand in a narrow track that reads as truncated against the width it
337
+ * leaves empty. A longer run's last cell carries its `tail`, which the grid spends at the
338
+ * capacity it stands at, so the last of three spans the row at two tracks and shares it at
339
+ * four. Everything else is `full`. No width is measured.
332
340
  */
333
341
  export declare function placeFields(fields: FieldModel[]): PlacedField[];
334
342
  /** A card's field values by key, off its payload items. */
335
343
  export declare function fieldValues(items: readonly PayloadItem[]): Record<string, unknown>;
336
- /** A field value as title text. A parsed field rests as the authored string and a
337
- * committed one as `Content`, whose `text` is the same words; a scalar reads as
344
+ /** A field value as title text. A text field rests as the authored string or as
345
+ * `Content`, whose `text` is the same words; a scalar reads as
338
346
  * itself; a variant container reads as its discriminant member, the one cell of it
339
347
  * that names the world; any other container as nothing. */
340
348
  export declare function titleText(v: unknown): string;