@quillmark/svelte 0.29.2 → 0.30.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 (70) hide show
  1. package/README.md +2 -1
  2. package/THEMING.md +8 -6
  3. package/dist/core/address.d.ts +3 -3
  4. package/dist/core/address.js +1 -1
  5. package/dist/core/bloom.d.ts +3 -2
  6. package/dist/core/bloom.js +6 -7
  7. package/dist/core/codec/decode.d.ts +1 -3
  8. package/dist/core/codec/decode.js +145 -206
  9. package/dist/core/codec/encode.d.ts +13 -35
  10. package/dist/core/codec/encode.js +127 -408
  11. package/dist/core/codec/field.d.ts +9 -9
  12. package/dist/core/codec/field.js +87 -80
  13. package/dist/core/codec/index.d.ts +2 -5
  14. package/dist/core/codec/index.js +4 -4
  15. package/dist/core/codec/inputrules.d.ts +0 -3
  16. package/dist/core/codec/inputrules.js +1 -1
  17. package/dist/core/codec/islands.d.ts +13 -19
  18. package/dist/core/codec/islands.js +55 -50
  19. package/dist/core/codec/list-move.d.ts +0 -3
  20. package/dist/core/codec/list-move.js +2 -2
  21. package/dist/core/codec/list-node.d.ts +2 -0
  22. package/dist/core/codec/list-node.js +1 -0
  23. package/dist/core/codec/list-paste.js +1 -1
  24. package/dist/core/codec/markdown-paste.d.ts +0 -9
  25. package/dist/core/codec/markdown-paste.js +1 -1
  26. package/dist/core/codec/marks.d.ts +12 -18
  27. package/dist/core/codec/marks.js +16 -26
  28. package/dist/core/codec/nesting.d.ts +0 -4
  29. package/dist/core/codec/nesting.js +1 -1
  30. package/dist/core/codec/positions.d.ts +14 -7
  31. package/dist/core/codec/positions.js +43 -50
  32. package/dist/core/codec/prose.css +1 -1
  33. package/dist/core/codec/reveal.d.ts +14 -0
  34. package/dist/core/codec/reveal.js +40 -0
  35. package/dist/core/codec/schema.d.ts +1 -1
  36. package/dist/core/codec/schema.js +26 -8
  37. package/dist/core/codec/slash.js +0 -0
  38. package/dist/core/codec/table-copy.d.ts +3 -3
  39. package/dist/core/codec/table-copy.js +6 -4
  40. package/dist/core/codec/table-paste.js +13 -9
  41. package/dist/core/codec/table-view.js +22 -15
  42. package/dist/core/codec/table.d.ts +77 -49
  43. package/dist/core/codec/table.js +158 -49
  44. package/dist/core/codec/touching.d.ts +0 -2
  45. package/dist/core/codec/touching.js +1 -11
  46. package/dist/preview/Preview.svelte +20 -1
  47. package/dist/preview/Preview.svelte.d.ts +1 -0
  48. package/dist/preview/controller.d.ts +5 -0
  49. package/dist/preview/controller.js +6 -0
  50. package/dist/preview/viewport.js +19 -1
  51. package/dist/preview/wash.d.ts +9 -0
  52. package/dist/preview/wash.js +38 -0
  53. package/dist/visual/ArrayField.svelte +18 -115
  54. package/dist/visual/FormatPopover.svelte +1 -1
  55. package/dist/visual/MatrixField.svelte +15 -19
  56. package/dist/visual/ObjectField.svelte +10 -13
  57. package/dist/visual/ProseValue.svelte +8 -8
  58. package/dist/visual/VisualEditorInner.svelte +17 -11
  59. package/dist/visual/guidance.d.ts +0 -12
  60. package/dist/visual/guidance.js +2 -2
  61. package/dist/visual/leaves.d.ts +1 -1
  62. package/dist/visual/leaves.js +1 -1
  63. package/dist/visual/props.d.ts +2 -2
  64. package/dist/visual/rowdrag.svelte.d.ts +21 -0
  65. package/dist/visual/rowdrag.svelte.js +118 -0
  66. package/dist/visual/structure.d.ts +6 -6
  67. package/dist/visual/structure.js +18 -21
  68. package/package.json +2 -2
  69. package/dist/visual/checklists.d.ts +0 -3
  70. package/dist/visual/checklists.js +0 -7
@@ -8,7 +8,7 @@
8
8
  raises it over that leaf's selection rect; each button dispatches a PM `toggleMark`
9
9
  command straight at the leaf's `EditorView`, whose own `dispatchTransaction` commits
10
10
  the result as it commits a keystroke: a field's lowers it to `markOps` through
11
- `applyChange` (field.ts), a by-value leaf's hands the re-encoded value to its parent
11
+ `apply` (field.ts), a by-value leaf's hands the re-encoded value to its parent
12
12
  (`ProseValue`). This component never touches the content. The keymap mirror
13
13
  (Mod-b/i/u, Mod-Shift-x, Mod-e) lives in the codec's keymap (field.ts); this is
14
14
  the pointer affordance for all six marks. Mod-K is this surface's own key, the
@@ -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}
@@ -2,7 +2,7 @@
2
2
  A prose leaf the parent commits by value: an element of a `richtext` (fixture
3
3
  `keywords`) or `text` (`authors`, `errata`) array, and a content cell of a subform — an
4
4
  `object`'s property, a variant's cell ({@link ObjectField}). None of them is
5
- `applyChange`-addressable: `Addr.field` is a flat name, so `keywords[0]` and
5
+ `apply`-addressable: `Addr.field` is a flat name, so `keywords[0]` and
6
6
  `contact.note` have no op address. So this is not a `createField` leaf: it mounts a
7
7
  minimal PM view over the codec's decode/encode and a leaf schema, and on every edit
8
8
  hands the re-encoded `Content` up to the parent — {@link ArrayField}, which commits
@@ -62,8 +62,8 @@
62
62
  proseAttributes,
63
63
  proseLeafPlugins,
64
64
  buildLineIndex,
65
- pmToUsv,
66
- usvToPM,
65
+ pmToOffset,
66
+ offsetToPM,
67
67
  valueEqual,
68
68
  type LeafViews,
69
69
  type TextCap
@@ -151,12 +151,12 @@
151
151
  view.focus();
152
152
  view.dom.scrollIntoView({ block: 'nearest' });
153
153
  }
154
- /** Take the caret to USV `pos` in this leaf's own content: what a landing on an
154
+ /** Take the caret to UTF-16 offset `pos` in this leaf's own content: what a landing on an
155
155
  * element address resolves to when the compile answered a cluster-exact offset
156
156
  * (`leaves.ts`). `createField`'s body over the view this component owns.
157
157
  *
158
158
  * The index is built here rather than held: a landing is a discrete act, and one
159
- * doc walk per click is cheaper than a cache to invalidate per keystroke. `usvToPM`
159
+ * doc walk per click is cheaper than a cache to invalidate per keystroke. `offsetToPM`
160
160
  * clamps, so an offset past a value the compile has moved on from lands the end.
161
161
  *
162
162
  * `Selection.near`, not `TextSelection.create`: the mapped position can be
@@ -164,7 +164,7 @@
164
164
  * reasons are `FieldController.setCaret`'s (`codec/field.ts`). */
165
165
  export function setCaret(pos: number): void {
166
166
  if (!view) return;
167
- const pm = usvToPM(buildLineIndex(view.state.doc), pos);
167
+ const pm = offsetToPM(buildLineIndex(view.state.doc), pos);
168
168
  const sel = Selection.near(view.state.doc.resolve(pm));
169
169
  view.focus();
170
170
  view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
@@ -292,9 +292,9 @@
292
292
  if (held) seat?.release(views);
293
293
  else if (mounted.hasFocus()) seat?.focus(views);
294
294
  // The caret keeps its offset, clamped, as a field's re-hydrate keeps it.
295
- const caret = pmToUsv(buildLineIndex(mounted.state.doc), mounted.state.selection.head);
295
+ const caret = pmToOffset(buildLineIndex(mounted.state.doc), mounted.state.selection.head);
296
296
  const fresh = build(current);
297
- const sel = Selection.near(fresh.doc.resolve(usvToPM(buildLineIndex(fresh.doc), caret)));
297
+ const sel = Selection.near(fresh.doc.resolve(offsetToPM(buildLineIndex(fresh.doc), caret)));
298
298
  mounted.updateState(fresh.apply(fresh.tr.setSelection(sel)));
299
299
  reconciler.commit(current);
300
300
  };
@@ -178,7 +178,8 @@
178
178
  * key is a host's only handle on a card, so a stale one is dropped rather than
179
179
  * reported. */
180
180
  function cardIdOf(addr: Addr): CardId | undefined {
181
- return addr.card == null ? 'main' : cardIds[addr.card];
181
+ if (addr.card == null) return 'main';
182
+ return typeof addr.card === 'number' ? cardIds[addr.card] : undefined;
182
183
  }
183
184
 
184
185
  // ── Teardown (core/teardown.ts: unregister, cancel, then free) ──────────────
@@ -299,7 +300,7 @@
299
300
  let liveTitles = $state<Record<CardId, string>>({});
300
301
  function refreshTitle(addr: Addr, cardId: CardId): void {
301
302
  const { card: at, field } = addr;
302
- if (at == null || field == null) return;
303
+ if (typeof at !== 'number' || field == null) return;
303
304
  const shown = model.cards[at];
304
305
  const cardSchema = shown && quill.schema.card_kinds?.[shown.kind];
305
306
  if (!cardSchema || cardSchema.title?.trim()) return;
@@ -318,7 +319,7 @@
318
319
  // ── Commit routing ──────────────────────────────────────────────────────────
319
320
  // Scalars / arrays / objects → the typed writer (schema-checked); a cleared entry
320
321
  // arrives as `undefined` and takes the unset lane instead. Prose leaves commit
321
- // themselves via the codec (applyChange) and do not pass through here.
322
+ // themselves via the codec (`apply`) and do not pass through here.
322
323
  //
323
324
  // A bad value makes `writer.set` throw a `QuillmarkError` whose `diagnostics[0]`
324
325
  // carries a `code` and a canonical `path` (`edit::field_coercion_failed` at
@@ -531,12 +532,17 @@
531
532
  const i = cardIndexOf(id);
532
533
  if (i < 0) return;
533
534
  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);
535
+ // The retyped card keeps the original's `$id`, which two cards cannot hold at
536
+ // once, so the original goes first and comes back where `insertCard` refuses:
537
+ // it validates the whole card before it mutates, so the document is as it was.
538
+ const card = doc.card(i);
539
+ doc.removeCard(i);
540
+ try {
541
+ doc.insertCard({ ...card, kind }, i);
542
+ } catch (e) {
543
+ doc.insertCard(card, i);
544
+ throw e;
545
+ }
540
546
  bump('structure', id, i);
541
547
  } catch (e) {
542
548
  reportError(onError, {
@@ -788,7 +794,7 @@
788
794
  }
789
795
 
790
796
  /**
791
- * Put the caret in a revealed target, at the finest grain it can take: a USV offset
797
+ * Put the caret in a revealed target, at the finest grain it can take: a UTF-16 offset
792
798
  * in a prose leaf or a nested content cell, a bare focus everywhere else. A form
793
799
  * control has no coordinate to spend an offset in (an `<input type="number">`
794
800
  * refuses a selection outright), which is also the whole of what a click on
@@ -951,7 +957,7 @@
951
957
  * second reading of the schema beside it. */
952
958
  function declaredField(addr: Addr): QuillFieldSchema | undefined {
953
959
  if (addr.field == null) return undefined;
954
- const kind = addr.card == null ? undefined : model.cards[addr.card]?.kind;
960
+ const kind = typeof addr.card === 'number' ? model.cards[addr.card]?.kind : undefined;
955
961
  const schema = quill.schema;
956
962
  const card = addr.card == null ? schema.main : kind ? schema.card_kinds?.[kind] : undefined;
957
963
  return card?.fields?.[addr.field];
@@ -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}"]`);
@@ -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
@@ -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[];