@quillmark/svelte 0.29.1 → 0.29.3

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 (52) hide show
  1. package/README.md +2 -1
  2. package/THEMING.md +8 -6
  3. package/dist/core/bloom.d.ts +3 -2
  4. package/dist/core/bloom.js +6 -7
  5. package/dist/core/codec/field.js +2 -4
  6. package/dist/core/codec/index.d.ts +0 -3
  7. package/dist/core/codec/inputrules.d.ts +0 -3
  8. package/dist/core/codec/inputrules.js +1 -1
  9. package/dist/core/codec/islands.d.ts +0 -10
  10. package/dist/core/codec/islands.js +1 -1
  11. package/dist/core/codec/list-move.d.ts +0 -3
  12. package/dist/core/codec/list-move.js +2 -2
  13. package/dist/core/codec/list-node.d.ts +2 -0
  14. package/dist/core/codec/list-node.js +1 -0
  15. package/dist/core/codec/list-paste.js +1 -1
  16. package/dist/core/codec/markdown-paste.d.ts +0 -9
  17. package/dist/core/codec/markdown-paste.js +1 -1
  18. package/dist/core/codec/nesting.d.ts +0 -4
  19. package/dist/core/codec/nesting.js +1 -1
  20. package/dist/core/codec/prose.css +1 -1
  21. package/dist/core/codec/reveal.d.ts +14 -0
  22. package/dist/core/codec/reveal.js +40 -0
  23. package/dist/core/codec/slash.js +0 -0
  24. package/dist/core/codec/table-view.js +3 -3
  25. package/dist/core/codec/table.d.ts +0 -6
  26. package/dist/core/codec/table.js +1 -1
  27. package/dist/core/codec/touching.d.ts +0 -2
  28. package/dist/core/codec/touching.js +1 -11
  29. package/dist/preview/Preview.svelte +20 -1
  30. package/dist/preview/Preview.svelte.d.ts +1 -0
  31. package/dist/preview/controller.d.ts +5 -0
  32. package/dist/preview/controller.js +6 -0
  33. package/dist/preview/viewport.js +19 -1
  34. package/dist/preview/wash.d.ts +9 -0
  35. package/dist/preview/wash.js +38 -0
  36. package/dist/visual/ArrayField.svelte +17 -114
  37. package/dist/visual/MatrixField.svelte +15 -19
  38. package/dist/visual/ObjectField.svelte +10 -13
  39. package/dist/visual/VisualEditor.svelte +4 -0
  40. package/dist/visual/VisualEditor.svelte.d.ts +1 -0
  41. package/dist/visual/VisualEditorInner.svelte +12 -0
  42. package/dist/visual/VisualEditorInner.svelte.d.ts +1 -0
  43. package/dist/visual/guidance.d.ts +0 -12
  44. package/dist/visual/guidance.js +2 -2
  45. package/dist/visual/props.d.ts +2 -2
  46. package/dist/visual/rowdrag.svelte.d.ts +21 -0
  47. package/dist/visual/rowdrag.svelte.js +118 -0
  48. package/dist/visual/structure.d.ts +6 -6
  49. package/dist/visual/structure.js +17 -11
  50. package/package.json +2 -2
  51. package/dist/visual/checklists.d.ts +0 -3
  52. package/dist/visual/checklists.js +0 -7
@@ -70,7 +70,7 @@
70
70
  baseType,
71
71
  controlKind,
72
72
  declaredContent,
73
- humanize,
73
+ fieldTitle,
74
74
  literalText,
75
75
  rowSummary,
76
76
  schemaAt,
@@ -81,6 +81,7 @@
81
81
  import { propertyDomIds } from './domid.js';
82
82
  import type { LandingBox } from './leaves.js';
83
83
  import { reorder, reorderArm } from './motion.js';
84
+ import { rowDrag } from './rowdrag.svelte.js';
84
85
  import Icon from './icons/Icon.svelte';
85
86
  import TextField from './TextField.svelte';
86
87
  import ObjectField from './ObjectField.svelte';
@@ -266,7 +267,6 @@
266
267
  // one, else this instance's own.
267
268
  const uid = $props.id();
268
269
  const countId = $derived(`${idBase ?? `qm-${uid}`}-count`);
269
- const columnTitle = (key: string, sub: QuillFieldSchema): string => sub.title ?? humanize(key);
270
270
 
271
271
  // The awaited flush below is the only work that outlives a gesture here, so the
272
272
  // span carries the reorder's frame and nothing else: it is the liveness
@@ -536,7 +536,7 @@
536
536
  * moves nothing, and never the record around it. A held drag owns the row until its
537
537
  * release. */
538
538
  function onRowKey(e: KeyboardEvent, k: number): void {
539
- if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag) return;
539
+ if (!e.altKey || e.shiftKey || e.ctrlKey || e.metaKey || e.isComposing || drag.held()) return;
540
540
  // A cell that took the key — a select opening, a date segment stepping, a prose
541
541
  // leaf joining — owns it.
542
542
  if (e.defaultPrevented) return;
@@ -549,109 +549,12 @@
549
549
  move(k, k + dir);
550
550
  }
551
551
 
552
- // ── The drag handle ──────────────────────────────────────────────────────────
553
- // Press-and-drag the handle moves its row; a press that does not travel past the dead
554
- // zone does nothing. The drop is the row under the pointer, read off the rows where
555
- // they stand, so a scroll by any hand re-picks it. Held in an edge band of its
556
- // scrollport, the drag scrolls it toward the rows out of view, once the pointer has
557
- // been outside the band: a press on a row already in the band does not scroll. Nothing
558
- // reflows until the release (the lift is a tone and the drop rule is out of flow), and
559
- // the release is the one splice `move` makes. A handle that loses the pointer, or
560
- // leaves the DOM, ends the drag with no move.
561
- const DEAD_ZONE = 3;
562
- /** The band at a scrollport's top and bottom edges that scrolls it under a held drag,
563
- * and the most one frame scrolls, reached at the edge itself. */
564
- const EDGE = 48;
565
- const STEP = 16;
566
- type RowDrag = { k: number; origin: number; y: number; engaged: boolean; drop: number };
567
- let drag = $state<RowDrag | undefined>();
568
- let follow: { grip: Element; port: Element; armed: boolean; frame: number } | undefined;
569
- function onHandleDown(e: PointerEvent, k: number): void {
570
- if (e.button !== 0) return;
571
- e.preventDefault();
572
- release();
573
- const grip = e.currentTarget as HTMLElement;
574
- grip.setPointerCapture?.(e.pointerId);
575
- drag = { k, origin: e.clientY, y: e.clientY, engaged: false, drop: k };
576
- follow = { grip, port: scrollport(grip), armed: false, frame: 0 };
577
- }
578
- function onHandleMove(e: PointerEvent): void {
579
- if (!drag) return;
580
- drag.y = e.clientY;
581
- if (!drag.engaged) {
582
- if (Math.abs(e.clientY - drag.origin) < DEAD_ZONE) return;
583
- drag.engaged = true;
584
- addEventListener('scroll', repick, { capture: true, passive: true });
585
- if (follow) follow.frame = requestAnimationFrame(edgeScroll);
586
- }
587
- repick();
588
- }
589
- function repick(): void {
590
- if (drag?.engaged) drag.drop = dropIndex(drag.k, drag.y);
591
- }
592
- const rowBox = (i: number): DOMRect | undefined => rowEls[ids[i]]?.getBoundingClientRect();
593
- /** The row the pointer is over, or the nearest one past either end. */
594
- function dropIndex(k: number, y: number): number {
595
- let best = k;
596
- let nearest = Infinity;
597
- ids.forEach((_, i) => {
598
- const box = rowBox(i);
599
- if (!box) return;
600
- const gap = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
601
- if (gap < nearest) {
602
- nearest = gap;
603
- best = i;
604
- }
605
- });
606
- return best;
607
- }
608
- const page = (): Element => document.scrollingElement ?? document.documentElement;
609
- /** The nearest ancestor that scrolls vertically, else the page. */
610
- function scrollport(from: Element): Element {
611
- for (let el = from.parentElement; el; el = el.parentElement) {
612
- const { overflowY } = getComputedStyle(el);
613
- if (/auto|scroll/.test(overflowY) && el.scrollHeight > el.clientHeight) return el;
614
- }
615
- return page();
616
- }
617
- function edgeScroll(): void {
618
- if (!follow || !drag?.engaged) return;
619
- if (!follow.grip.isConnected) {
620
- drag = undefined;
621
- release();
622
- return;
623
- }
624
- const { port } = follow;
625
- const box = port === page() ? undefined : port.getBoundingClientRect();
626
- const top = Math.max(box?.top ?? 0, 0);
627
- const bottom = Math.min(box?.bottom ?? innerHeight, innerHeight);
628
- const into = Math.min(drag.y - top - EDGE, 0) + Math.max(drag.y - bottom + EDGE, 0);
629
- if (!into) follow.armed = true;
630
- // Only toward rows still out of view: past the list's end there is nothing to reach.
631
- const beyond =
632
- into < 0 ? (rowBox(0)?.top ?? top) < top : (rowBox(ids.length - 1)?.bottom ?? 0) > bottom;
633
- if (into && follow.armed && beyond)
634
- port.scrollBy({ top: STEP * Math.max(-1, Math.min(1, into / EDGE)), behavior: 'instant' });
635
- follow.frame = requestAnimationFrame(edgeScroll);
636
- }
637
- function release(): void {
638
- if (follow) cancelAnimationFrame(follow.frame);
639
- follow = undefined;
640
- removeEventListener('scroll', repick, { capture: true });
641
- }
642
- onDestroy(release);
643
- function onHandleUp(e: PointerEvent): void {
644
- const done = drag;
645
- drag = undefined;
646
- release();
647
- if (!done?.engaged || e.type !== 'pointerup') return;
648
- move(done.k, done.drop);
649
- }
650
- /** Where the drop rule draws on row `k`, while a drag would land the row there. */
651
- function dropSide(k: number): 'before' | 'after' | undefined {
652
- if (!drag?.engaged || drag.drop !== k || drag.drop === drag.k) return undefined;
653
- return drag.drop > drag.k ? 'after' : 'before';
654
- }
552
+ const drag = rowDrag({
553
+ count: () => ids.length,
554
+ box: (i) => rowEls[ids[i]]?.getBoundingClientRect(),
555
+ move
556
+ });
557
+ onDestroy(drag.release);
655
558
 
656
559
  /** Whether cells stand past the table scroller's end edge, under the pinned remove,
657
560
  * which is what the fade before the remove draws on. */
@@ -731,7 +634,7 @@
731
634
  ]}
732
635
  >
733
636
  <FieldLabel
734
- label={columnTitle(key, sub)}
637
+ label={fieldTitle(key, sub)}
735
638
  descriptionId={idBase != null ? propertyDomIds(idBase, key).description : undefined}
736
639
  description={sub.description}
737
640
  />
@@ -775,9 +678,9 @@
775
678
  <div
776
679
  class={[
777
680
  'qm-array-row qm-element qm-wash',
778
- { open: open.has(id), lifted: drag?.engaged && drag.k === k }
681
+ { open: open.has(id), lifted: drag.lifted(k) }
779
682
  ]}
780
- data-drop={dropSide(k)}
683
+ data-drop={drag.dropSide(k)}
781
684
  data-qm-index={k}
782
685
  bind:this={rowEls[id]}
783
686
  animate:reorder={arm.armed}
@@ -893,11 +796,11 @@
893
796
  class="qm-row-handle"
894
797
  aria-hidden="true"
895
798
  title={t.strings.arrayDrag}
896
- onpointerdown={(e) => onHandleDown(e, k)}
897
- onpointermove={onHandleMove}
898
- onpointerup={onHandleUp}
899
- onpointercancel={onHandleUp}
900
- onlostpointercapture={onHandleUp}
799
+ onpointerdown={(e) => drag.down(e, k)}
800
+ onpointermove={drag.move}
801
+ onpointerup={drag.up}
802
+ onpointercancel={drag.up}
803
+ onlostpointercapture={drag.up}
901
804
  ><span class="qm-row-handle-bar"><Icon name="grip-vertical" /></span></span
902
805
  >
903
806
  {/snippet}
@@ -44,12 +44,12 @@
44
44
  matrixEmpty,
45
45
  matrixHeld,
46
46
  matrixMembers,
47
- memberValue,
47
+ matrixPrinted,
48
+ own,
48
49
  memberWrite,
49
50
  onRoster,
50
51
  schemaAt
51
52
  } from './structure.js';
52
- import { matrixPrinted } from './checklists.js';
53
53
  import { splitDeep, unrouted, type DeepDiagnostic } from './diagnostics.js';
54
54
  import type { LandingBox } from './leaves.js';
55
55
  import { propertyDomIds } from './domid.js';
@@ -106,7 +106,7 @@
106
106
  const map = $derived(matrixPrinted(value, schema));
107
107
  const defaulted = $derived(value == null && map != null && Object.keys(map).length > 0);
108
108
  const added = $derived(addedItems(schema, map));
109
- const held = (id: string): boolean => matrixHeld(memberValue(map, id));
109
+ const held = (id: string): boolean => matrixHeld(own(map, id));
110
110
  const heldCount = $derived(members.filter((m) => held(m.id)).length + added.length);
111
111
  /** Whether `id` is an item this control draws: a roster member or a held added item. */
112
112
  const drawn = (id: string): boolean =>
@@ -145,10 +145,6 @@
145
145
  const colEls: Record<string, Subform | undefined> = $state({});
146
146
  let rosterEl = $state<HTMLElement | undefined>();
147
147
  let addEl = $state<{ focus: () => void } | undefined>();
148
- /** A ref by member id, own keys only: an id can be spelled `constructor`. */
149
- const ref = <T,>(refs: Record<string, T | undefined>, id: string): T | undefined =>
150
- Object.hasOwn(refs, id) ? refs[id] : undefined;
151
-
152
148
  /** The rows' content read: the boundary's, or, while the set is the default, the
153
149
  * literal's own leaf at the codec its declared type names. */
154
150
  function readAt(path: PathStep[]): Content | undefined {
@@ -167,7 +163,7 @@
167
163
  }
168
164
  /** The map with `id` unticked, its columns stashed for a retick. */
169
165
  function unticked(id: string): Record<string, unknown> | undefined {
170
- const columns = matrixColumns(memberValue(map, id));
166
+ const columns = matrixColumns(own(map, id));
171
167
  if (Object.keys(columns).length) stash.set(id, columns);
172
168
  else stash.delete(id);
173
169
  return commitMember(map, id, undefined);
@@ -188,11 +184,11 @@
188
184
  commit(commitMember(map, id, memberWrite(columns, title)));
189
185
  }
190
186
  function itemTitle(id: string): string {
191
- const stored = memberValue(map, id) as Record<string, unknown> | undefined;
187
+ const stored = own(map, id) as Record<string, unknown> | undefined;
192
188
  return String(stored?.[MATRIX_TITLE] ?? '');
193
189
  }
194
190
  function retitle(id: string, title: string): void {
195
- commit(commitMember(map, id, memberWrite(matrixColumns(memberValue(map, id)), title)));
191
+ commit(commitMember(map, id, memberWrite(matrixColumns(own(map, id)), title)));
196
192
  }
197
193
  async function removeItem(id: string): Promise<void> {
198
194
  const at = added.findIndex((item) => item.id === id);
@@ -200,7 +196,7 @@
200
196
  await flush();
201
197
  // The caret goes where the row was: the next added item, else the add box.
202
198
  const next = added[at] ?? added[at - 1];
203
- if (next) ref(titleEls, next.id)?.focus();
199
+ if (next) own(titleEls, next.id)?.focus();
204
200
  else addEl?.focus();
205
201
  }
206
202
 
@@ -210,20 +206,20 @@
210
206
  const id = addedId(title, taken);
211
207
  commit(commitMember(map, id, memberWrite({}, title)));
212
208
  await flush();
213
- const box = ref(memberEls, id);
209
+ const box = own(memberEls, id);
214
210
  // The item's columns are what the author came to fill; a checklist has none, and
215
211
  // the box stays where the next item is typed.
216
212
  const first = Object.keys(schema.properties ?? {})[0];
217
- if (first !== undefined) ref(colEls, id)?.focusPath([first]);
213
+ if (first !== undefined) own(colEls, id)?.focusPath([first]);
218
214
  if (box) bloom(box);
219
215
  }
220
216
 
221
217
  /** Take the caret: the first item's control, else the add box. */
222
218
  export function focus(): void {
223
219
  const first = members[0];
224
- if (first) return ref(tickEls, first.id)?.focus();
220
+ if (first) return own(tickEls, first.id)?.focus();
225
221
  const item = added[0];
226
- if (item) return ref(titleEls, item.id)?.focus();
222
+ if (item) return own(titleEls, item.id)?.focus();
227
223
  addEl?.focus();
228
224
  }
229
225
  /** The box an arrival wash blooms in: the roster, not the label row above it, this
@@ -248,13 +244,13 @@
248
244
  return undefined;
249
245
  }
250
246
  const column = rest[0];
251
- const cells = ref(colEls, id);
252
- const member = ref(memberEls, id);
247
+ const cells = own(colEls, id);
248
+ const member = own(memberEls, id);
253
249
  if (column !== undefined && column !== MATRIX_TITLE && cells) {
254
250
  const inner = cells.focusPath(rest, pos);
255
251
  return inner instanceof Promise ? inner.then((box) => box ?? member) : (inner ?? member);
256
252
  }
257
- (ref(tickEls, id) ?? ref(titleEls, id))?.focus();
253
+ (own(tickEls, id) ?? own(titleEls, id))?.focus();
258
254
  return member;
259
255
  }
260
256
  </script>
@@ -363,7 +359,7 @@
363
359
  {#if on && hasColumns}
364
360
  <ObjectField
365
361
  bind:this={colEls[id]}
366
- value={matrixColumns(memberValue(map, id))}
362
+ value={matrixColumns(own(map, id))}
367
363
  properties={schema.properties}
368
364
  label={`${label ?? ''} ${title}`.trim()}
369
365
  idBase={memberBase(id)}
@@ -41,11 +41,12 @@
41
41
  controlKind,
42
42
  declaredContent,
43
43
  fieldModels,
44
- humanize,
44
+ fieldTitle,
45
45
  isContainer,
46
46
  literalText,
47
47
  mountKey,
48
48
  optionalCell,
49
+ own,
49
50
  placeFields,
50
51
  printedText,
51
52
  renderedBoolean,
@@ -150,7 +151,6 @@
150
151
  const routed = $derived(splitDeep(diagnostics));
151
152
  const foot = $derived(unrouted(routed, (step) => typeof step === 'string' && has(step)));
152
153
 
153
- const title = (key: string, sub: QuillFieldSchema): string => sub.title ?? humanize(key);
154
154
  /** What an unset optional cell ghosts, which is what it prints: `none`. An answered
155
155
  * cell ghosts nothing, an empty answer printing empty. */
156
156
  const noneOf = (key: string, sub: QuillFieldSchema): string | undefined =>
@@ -163,7 +163,7 @@
163
163
  /** The `aria-label` fallback, for a subform mounted without a field's id space:
164
164
  * the field's name and the property's, since nothing else names the control. */
165
165
  const fallbackName = (key: string, sub: QuillFieldSchema): string =>
166
- `${label != null ? `${label} ` : ''}${title(key, sub)}`;
166
+ `${label != null ? `${label} ` : ''}${fieldTitle(key, sub)}`;
167
167
 
168
168
  /** The handles of the cells the DOM cannot answer for, keyed by property name —
169
169
  * which is stable, a subform drawing its properties by declaration and never by
@@ -186,9 +186,6 @@
186
186
  | undefined
187
187
  > = $state({});
188
188
  let rootEl = $state<HTMLElement | undefined>();
189
- /** A handle by property name, own keys only: a property can be named `constructor`. */
190
- const ref = <T,>(map: Record<string, T | undefined>, key: string): T | undefined =>
191
- Object.hasOwn(map, key) ? map[key] : undefined;
192
189
  const FOCUSABLE = 'input, select, button, [tabindex]:not([tabindex="-1"])';
193
190
  /** Take the caret: the first property that has somewhere to put it, in document
194
191
  * order — a subform has no single control of its own to land on. An empty subform
@@ -210,9 +207,9 @@
210
207
  focus();
211
208
  return undefined;
212
209
  }
213
- const nested = ref(nestedEls, key);
210
+ const nested = own(nestedEls, key);
214
211
  if (nested) return nested.focusPath(rest, pos);
215
- const prose = ref(proseEls, key);
212
+ const prose = own(proseEls, key);
216
213
  if (prose) {
217
214
  if (pos != null) prose.setCaret(pos);
218
215
  else prose.focus();
@@ -239,7 +236,7 @@
239
236
  /** Land in one property's cell, answering whether it took the caret. */
240
237
  function landOn(cell: HTMLElement): boolean {
241
238
  const key = cell.dataset.qmProp ?? '';
242
- const owned = ref(nestedEls, key) ?? ref(proseEls, key);
239
+ const owned = own(nestedEls, key) ?? own(proseEls, key);
243
240
  if (owned) {
244
241
  owned.focus();
245
242
  return true;
@@ -313,7 +310,7 @@
313
310
  >
314
311
  {#if ids && kind !== 'array' && kind !== 'matrix'}
315
312
  <FieldLabel
316
- label={title(key, sub)}
313
+ label={fieldTitle(key, sub)}
317
314
  controlId={labelable ? ids.control : undefined}
318
315
  id={ids.label}
319
316
  descriptionId={describes}
@@ -410,7 +407,7 @@
410
407
  items={sub.items}
411
408
  layout={arrayLayout(sub)}
412
409
  max={sub.max}
413
- label={title(key, sub)}
410
+ label={fieldTitle(key, sub)}
414
411
  description={sub.description}
415
412
  labelId={ids?.label}
416
413
  descriptionId={describes}
@@ -438,7 +435,7 @@
438
435
  bind:this={nestedEls[key]}
439
436
  value={obj[key] as Record<string, unknown> | undefined}
440
437
  schema={sub}
441
- label={title(key, sub)}
438
+ label={fieldTitle(key, sub)}
442
439
  description={sub.description}
443
440
  labelId={ids?.label}
444
441
  descriptionId={describes}
@@ -453,7 +450,7 @@
453
450
  value={obj[key] as Record<string, unknown> | undefined}
454
451
  schema={sub}
455
452
  ghostMember={sub.default as string | undefined}
456
- label={title(key, sub)}
453
+ label={fieldTitle(key, sub)}
457
454
  id={ids?.control}
458
455
  labelledBy={ids?.label}
459
456
  describedBy={describes}
@@ -75,6 +75,10 @@
75
75
  export async function focusField(field: DocPath): Promise<void> {
76
76
  await inner?.focusField(field);
77
77
  }
78
+ /** Wash the field at `field` where it is on show, without focusing or revealing it. */
79
+ export function washField(field: DocPath): void {
80
+ inner?.washField(field);
81
+ }
78
82
  /** Seed a card of `kind` at `at` (default: the end); the new card's session key. */
79
83
  export function insertCard(kind: string, at?: number): CardId | undefined {
80
84
  return inner?.insertCard(kind, at);
@@ -5,6 +5,7 @@ import type { VisualEditorProps } from './props.js';
5
5
  declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
6
6
  setCaret: (at: Landing) => Promise<void>;
7
7
  focusField: (field: DocPath) => Promise<void>;
8
+ washField: (field: DocPath) => void;
8
9
  insertCard: (kind: string, at?: number) => CardId | undefined;
9
10
  removeCard: (cardId: CardId) => void;
10
11
  moveCard: (cardId: CardId, dir: -1 | 1) => void;
@@ -836,6 +836,18 @@
836
836
  const box = await land(found, undefined);
837
837
  if (span.alive) bloom(box);
838
838
  }
839
+ /** Play the arrival wash over the field at `field` and touch nothing else: no focus,
840
+ * no reveal, no scroll. A field in a closed panel is skipped, its box clipped to
841
+ * nothing; a nested address washes its field's box, a row being something only a
842
+ * landing opens. */
843
+ export function washField(field: DocPath): void {
844
+ if (!span.alive) return;
845
+ const target = leafTargetFor(field);
846
+ const control = target && leaves.control(target.key);
847
+ if (!control) return missed(`no mounted field at ${field}`, field);
848
+ for (let n: HTMLElement | null = control.el; n; n = n.parentElement) if (n.inert) return;
849
+ bloom(control.el);
850
+ }
839
851
  /** Seed a card of `kind` and insert it at `at` (default: the end). Returns the new
840
852
  * card's session key, or `undefined` when the quill seeds no card of that kind. */
841
853
  export function insertCard(kind: string, at: number = cardIds.length): CardId | undefined {
@@ -7,6 +7,7 @@ declare const VisualEditorInner: import("svelte").Component<VisualEditorProps, {
7
7
  setCaret: (at: Landing) => Promise<void>;
8
8
  getActiveLeaf: () => ActiveProse | undefined;
9
9
  focusField: (field: DocPath) => Promise<void>;
10
+ washField: (field: DocPath) => void;
10
11
  insertCard: (kind: string, at?: number) => CardId | undefined;
11
12
  removeCard: (cardId: CardId) => void;
12
13
  moveCard: (cardId: CardId, dir: -1 | 1) => void;
@@ -1,15 +1,3 @@
1
- /** `Mod-/`, read off `key` so a layout that shifts to reach `/` still matches; either
2
- * modifier stands for `Mod`. */
3
- export declare function isGuidanceKey(e: KeyboardEvent): boolean;
4
- /**
5
- * The guidance trigger for the description nearest `from`: the innermost element
6
- * carrying `aria-describedby` whose ids name a parked description with a trigger
7
- * beside it. A trigger points at its own parked node through that same attribute,
8
- * which is the relation read here; ids that are not a description (an array's count,
9
- * a prose leaf's note) are skipped, and an undescribed property falls through to the
10
- * group around it.
11
- */
12
- export declare function guidanceTrigger(from: Element, root: Element): HTMLElement | undefined;
13
1
  /** Root keydown: the key raises (or lowers) the nearest guidance. A trigger's `click()`
14
2
  * is an activation with no pointer behind it, which `FieldHint` toggles on. */
15
3
  export declare function raiseGuidance(e: KeyboardEvent): void;
@@ -2,7 +2,7 @@
2
2
  // the keyboard's way in to a `FieldHint` whose glyph is out of the tab order.
3
3
  /** `Mod-/`, read off `key` so a layout that shifts to reach `/` still matches; either
4
4
  * modifier stands for `Mod`. */
5
- export function isGuidanceKey(e) {
5
+ function isGuidanceKey(e) {
6
6
  return e.key === '/' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.isComposing;
7
7
  }
8
8
  /**
@@ -13,7 +13,7 @@ export function isGuidanceKey(e) {
13
13
  * a prose leaf's note) are skipped, and an undescribed property falls through to the
14
14
  * group around it.
15
15
  */
16
- export function guidanceTrigger(from, root) {
16
+ function guidanceTrigger(from, root) {
17
17
  for (let el = from.closest('[aria-describedby]'); el;) {
18
18
  for (const id of el.getAttribute('aria-describedby').split(/\s+/)) {
19
19
  const trigger = root.querySelector(`.qm-field-hint[aria-describedby="${id}"]`);
@@ -110,7 +110,7 @@ export interface VisualEditorProps {
110
110
  /** Appended to the root's own class: the surface is a mounted element the
111
111
  * consumer positions, so it needs a handle for layout it owns. */
112
112
  class?: string;
113
- /** Merged onto the root. Free because the derivation moved off this attribute
114
- * and onto `data-qm-root` (core/theme.css). */
113
+ /** Merged onto the root. The theme derivation hangs off `data-qm-root`
114
+ * (core/theme.css), not this attribute. */
115
115
  style?: string;
116
116
  }
@@ -0,0 +1,21 @@
1
+ /** The list a drag reads and moves: its row count, row `i`'s box where it stands, and the
2
+ * splice a release makes. */
3
+ export interface DragRows {
4
+ count(): number;
5
+ box(i: number): DOMRect | undefined;
6
+ move(k: number, to: number): void;
7
+ }
8
+ export interface RowDrag {
9
+ /** Whether a press on a handle is held, engaged or not. */
10
+ held(): boolean;
11
+ /** Whether row `k` is the one an engaged drag carries. */
12
+ lifted(k: number): boolean;
13
+ /** Where the drop rule draws on row `k`, while a drag would land the row there. */
14
+ dropSide(k: number): 'before' | 'after' | undefined;
15
+ down(e: PointerEvent, k: number): void;
16
+ move(e: PointerEvent): void;
17
+ up(e: PointerEvent): void;
18
+ /** Stop following the pointer, for the list's teardown. */
19
+ release(): void;
20
+ }
21
+ export declare function rowDrag(rows: DragRows): RowDrag;
@@ -0,0 +1,118 @@
1
+ // A record list's drag handle. Press-and-drag the handle moves its row; a press that does
2
+ // not travel past the dead zone does nothing. The drop is the row under the pointer, read
3
+ // off the rows where they stand, so a scroll by any hand re-picks it. Held in an edge band
4
+ // of its scrollport, the drag scrolls it toward the rows out of view, once the pointer has
5
+ // been outside the band: a press on a row already in the band does not scroll. Nothing
6
+ // reflows until the release (the lift is a tone and the drop rule is out of flow), and the
7
+ // release is the one splice `move` makes. A handle that loses the pointer, or leaves the
8
+ // DOM, ends the drag with no move.
9
+ const DEAD_ZONE = 3;
10
+ /** The band at a scrollport's top and bottom edges that scrolls it under a held drag, and
11
+ * the most one frame scrolls, reached at the edge itself. */
12
+ const EDGE = 48;
13
+ const STEP = 16;
14
+ const page = () => document.scrollingElement ?? document.documentElement;
15
+ /** The nearest ancestor that scrolls vertically, else the page. */
16
+ function scrollport(from) {
17
+ for (let el = from.parentElement; el; el = el.parentElement) {
18
+ const { overflowY } = getComputedStyle(el);
19
+ if (/auto|scroll/.test(overflowY) && el.scrollHeight > el.clientHeight)
20
+ return el;
21
+ }
22
+ return page();
23
+ }
24
+ export function rowDrag(rows) {
25
+ let drag = $state();
26
+ let follow;
27
+ /** The row the pointer is over, or the nearest one past either end. */
28
+ function dropIndex(k, y) {
29
+ let best = k;
30
+ let nearest = Infinity;
31
+ for (let i = 0; i < rows.count(); i++) {
32
+ const box = rows.box(i);
33
+ if (!box)
34
+ continue;
35
+ const gap = y < box.top ? box.top - y : y > box.bottom ? y - box.bottom : 0;
36
+ if (gap < nearest) {
37
+ nearest = gap;
38
+ best = i;
39
+ }
40
+ }
41
+ return best;
42
+ }
43
+ function repick() {
44
+ if (drag?.engaged)
45
+ drag.drop = dropIndex(drag.k, drag.y);
46
+ }
47
+ function edgeScroll() {
48
+ if (!follow || !drag?.engaged)
49
+ return;
50
+ if (!follow.grip.isConnected) {
51
+ drag = undefined;
52
+ release();
53
+ return;
54
+ }
55
+ const { port } = follow;
56
+ const box = port === page() ? undefined : port.getBoundingClientRect();
57
+ const top = Math.max(box?.top ?? 0, 0);
58
+ const bottom = Math.min(box?.bottom ?? innerHeight, innerHeight);
59
+ const into = Math.min(drag.y - top - EDGE, 0) + Math.max(drag.y - bottom + EDGE, 0);
60
+ if (!into)
61
+ follow.armed = true;
62
+ // Only toward rows still out of view: past the list's end there is nothing to reach.
63
+ const beyond = into < 0
64
+ ? (rows.box(0)?.top ?? top) < top
65
+ : (rows.box(rows.count() - 1)?.bottom ?? 0) > bottom;
66
+ if (into && follow.armed && beyond)
67
+ port.scrollBy({ top: STEP * Math.max(-1, Math.min(1, into / EDGE)), behavior: 'instant' });
68
+ follow.frame = requestAnimationFrame(edgeScroll);
69
+ }
70
+ function release() {
71
+ if (follow)
72
+ cancelAnimationFrame(follow.frame);
73
+ follow = undefined;
74
+ removeEventListener('scroll', repick, { capture: true });
75
+ }
76
+ return {
77
+ held: () => drag !== undefined,
78
+ lifted: (k) => !!drag?.engaged && drag.k === k,
79
+ dropSide(k) {
80
+ if (!drag?.engaged || drag.drop !== k || drag.drop === drag.k)
81
+ return undefined;
82
+ return drag.drop > drag.k ? 'after' : 'before';
83
+ },
84
+ down(e, k) {
85
+ if (e.button !== 0)
86
+ return;
87
+ e.preventDefault();
88
+ release();
89
+ const grip = e.currentTarget;
90
+ grip.setPointerCapture?.(e.pointerId);
91
+ drag = { k, origin: e.clientY, y: e.clientY, engaged: false, drop: k };
92
+ follow = { grip, port: scrollport(grip), armed: false, frame: 0 };
93
+ },
94
+ move(e) {
95
+ if (!drag)
96
+ return;
97
+ drag.y = e.clientY;
98
+ if (!drag.engaged) {
99
+ if (Math.abs(e.clientY - drag.origin) < DEAD_ZONE)
100
+ return;
101
+ drag.engaged = true;
102
+ addEventListener('scroll', repick, { capture: true, passive: true });
103
+ if (follow)
104
+ follow.frame = requestAnimationFrame(edgeScroll);
105
+ }
106
+ repick();
107
+ },
108
+ up(e) {
109
+ const done = drag;
110
+ drag = undefined;
111
+ release();
112
+ if (!done?.engaged || e.type !== 'pointerup')
113
+ return;
114
+ rows.move(done.k, done.drop);
115
+ },
116
+ release
117
+ };
118
+ }
@@ -183,9 +183,10 @@ export interface MatrixMember {
183
183
  /** The roster's members, in declaration order. Own keys only: a schema map is indexed
184
184
  * by a document-supplied id, and `'toString' in members` is true of every roster. */
185
185
  export declare function matrixMembers(roster: Record<string, string> | undefined): MatrixMember[];
186
- /** A member's stored payload, off the sparse map by own key: a document key can be
187
- * spelled `constructor`. */
188
- export declare function memberValue(map: Record<string, unknown> | undefined, id: string): unknown;
186
+ /** A value by own key: a document key or a declared id can be spelled `constructor`. */
187
+ export declare function own<T>(map: Record<string, T> | undefined, key: string): T | undefined;
188
+ /** The value a matrix prints: the stored map, else a mapping `default:`. */
189
+ export declare function matrixPrinted(value: unknown, schema: QuillFieldSchema): Record<string, unknown> | undefined;
189
190
  /**
190
191
  * Whether a stored member is held: by being present. A mapping is held whatever it
191
192
  * carries, `{}` included, and a bare scalar is the tick itself, read as Quillmark's
@@ -212,9 +213,6 @@ export declare function commitMember(map: Record<string, unknown> | undefined, i
212
213
  * ({@link commitMember} with `undefined`), never a write.
213
214
  */
214
215
  export declare function memberWrite(columns: Record<string, unknown>, title?: string): unknown;
215
- /** Whether `id` is spelled as a matrix id: snake_case, the rule the roster's ids and
216
- * an added item's key share. */
217
- export declare function matrixId(id: string): boolean;
218
216
  export declare function onRoster(matrix: QuillFieldSchema, id: string): boolean;
219
217
  /**
220
218
  * Whether a step under the matrix names a member, judged on the schema alone as an
@@ -285,6 +283,8 @@ export declare function variantCells(schema: QuillFieldSchema, member: string |
285
283
  export declare function commitDiscriminant(value: Record<string, unknown> | undefined, member: string | undefined): Record<string, unknown> | undefined;
286
284
  /** `foo_bar` → `Foo bar`. */
287
285
  export declare function humanize(name: string): string;
286
+ /** What a field or property is called: its `title:`, else its key humanized. */
287
+ export declare function fieldTitle(key: string, schema: QuillFieldSchema): string;
288
288
  /** Project a card schema's `fields` map (declaration = key order) into models. A
289
289
  * card-level object's `properties` project the same way. */
290
290
  export declare function fieldModels(cardSchema: Pick<QuillCardSchema, 'fields'>): FieldModel[];