@quillmark/svelte 0.37.0 → 0.38.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 (45) hide show
  1. package/dist/core/codec/field.d.ts +6 -5
  2. package/dist/core/codec/field.js +15 -21
  3. package/dist/core/codec/index.d.ts +1 -1
  4. package/dist/core/codec/index.js +1 -1
  5. package/dist/core/codec/prose.css +6 -0
  6. package/dist/core/codec/review.js +8 -4
  7. package/dist/core/codec/value-diff.d.ts +4 -3
  8. package/dist/core/codec/value-diff.js +12 -7
  9. package/dist/core/codec/value-plan.d.ts +9 -0
  10. package/dist/core/codec/value-plan.js +110 -0
  11. package/dist/core/theme.css +5 -4
  12. package/dist/visual/ArrayField.svelte +143 -78
  13. package/dist/visual/Card.svelte +4 -3
  14. package/dist/visual/Card.svelte.d.ts +3 -2
  15. package/dist/visual/Field.svelte +12 -10
  16. package/dist/visual/Field.svelte.d.ts +3 -3
  17. package/dist/visual/FieldHint.svelte +3 -5
  18. package/dist/visual/FieldLabel.svelte +6 -42
  19. package/dist/visual/FieldLabel.svelte.d.ts +0 -3
  20. package/dist/visual/MatrixAdd.svelte +9 -10
  21. package/dist/visual/MatrixField.svelte +107 -15
  22. package/dist/visual/ObjectField.svelte +24 -12
  23. package/dist/visual/ObjectField.svelte.d.ts +5 -0
  24. package/dist/visual/ProseField.svelte +16 -8
  25. package/dist/visual/ProseField.svelte.d.ts +3 -2
  26. package/dist/visual/ProseValue.svelte +25 -23
  27. package/dist/visual/ProseValue.svelte.d.ts +3 -2
  28. package/dist/visual/ReviewCard.svelte +11 -4
  29. package/dist/visual/VisualEditorInner.svelte +63 -38
  30. package/dist/visual/guidance.d.ts +0 -2
  31. package/dist/visual/guidance.js +0 -10
  32. package/dist/visual/proposals.d.ts +14 -11
  33. package/dist/visual/proposals.js +44 -28
  34. package/dist/visual/props.d.ts +6 -4
  35. package/dist/visual/review-order.d.ts +1 -0
  36. package/dist/visual/review-order.js +4 -3
  37. package/dist/visual/review.d.ts +15 -2
  38. package/dist/visual/review.js +29 -1
  39. package/dist/visual/review.svelte.d.ts +6 -1
  40. package/dist/visual/review.svelte.js +37 -10
  41. package/dist/visual/strings.d.ts +2 -0
  42. package/dist/visual/strings.js +1 -0
  43. package/dist/visual/structure.d.ts +17 -9
  44. package/dist/visual/structure.js +20 -17
  45. package/package.json +1 -1
@@ -10,9 +10,8 @@
10
10
  hands the click to `onActivate`. Both halves are needed: `for` on a non-labelable
11
11
  element is inert and invalid.
12
12
 
13
- One non-gating label decoration: the `description`. A short one (`isBrief`) stands in
14
- flow under the label, the row's second line, and is itself the node that describes the
15
- control. A longer one is an info marker raising a themed popover ({@link FieldHint}).
13
+ One non-gating label decoration: the `description`, an info marker raising a themed
14
+ popover ({@link FieldHint}), whatever its length.
16
15
 
17
16
  The row's end says where the field stands against its `default:` (INVARIANTS §"The
18
17
  commitment ladder"). While the default is what prints, a tag says so in words, and the
@@ -20,7 +19,7 @@
20
19
  holds the way back: one button for every control, arriving with the field's hover or
21
20
  focus as the guidance marker does, and named for its field.
22
21
 
23
- The description describes, it does not name. Behind a marker it is parked in an
22
+ The description describes, it does not name. It is parked in an
24
23
  always-present visually-hidden node here and the control carries `aria-describedby`: name then
25
24
  role then description, which is the announcement the markup visually implies. In
26
25
  the name it would instead prepend ~110 characters of guidance (the reference
@@ -33,7 +32,7 @@
33
32
  -->
34
33
  <script lang="ts">
35
34
  import FieldHint from './FieldHint.svelte';
36
- import { guidanceText, isBrief, renderGuidance } from './guidance.js';
35
+ import { guidanceText } from './guidance.js';
37
36
  import { wording } from './strings.js';
38
37
  import './controls.css';
39
38
 
@@ -52,9 +51,6 @@
52
51
  onActivate?: () => void;
53
52
  /** Schema `description`, or undefined: the affordance renders only when set. */
54
53
  description?: string;
55
- /** A short description stands under the label ({@link isBrief}). Off where the
56
- * row has no second line to give, a table column's head. */
57
- brief?: boolean;
58
54
  /** A capped field's character count, drawn at the row's end. */
59
55
  count?: string;
60
56
  /** The count's own id, for the control's `aria-describedby`. */
@@ -73,7 +69,6 @@
73
69
  descriptionId,
74
70
  onActivate,
75
71
  description,
76
- brief = true,
77
72
  count,
78
73
  countId,
79
74
  defaulted = false,
@@ -82,14 +77,9 @@
82
77
  }: Props = $props();
83
78
 
84
79
  const resetId = $props.id();
85
- const inFlow = $derived(brief && description != null && isBrief(description));
86
- /** The description is DOM, not text (`renderGuidance`), so it is written in. */
87
- function paint(line: HTMLElement): void {
88
- line.replaceChildren(renderGuidance(description ?? ''));
89
- }
90
80
  </script>
91
81
 
92
- <div class={['qm-field-label-row', { briefed: inFlow }]}>
82
+ <div class="qm-field-label-row">
93
83
  <!-- svelte-ignore a11y_no_noninteractive_element_interactions, a11y_click_events_have_key_events -->
94
84
  <!-- The handler stands in for exactly what `for` would have done, on the controls
95
85
  where `for` is inert. It adds no keyboard surface because it needs none: a
@@ -103,10 +93,7 @@
103
93
  >
104
94
  <span>{label}</span>
105
95
  </label>
106
- {#if inFlow}
107
- <!-- The node that describes the control is the line a reader sees. -->
108
- <div class="qm-field-brief" id={descriptionId} {@attach paint}></div>
109
- {:else if description}
96
+ {#if description}
110
97
  <!-- Outside the `<label>`, both of them: a trigger inside it would put its own
111
98
  name in the control's, and the parked copy would put all ~110 characters
112
99
  there. A `<button>` in a label is at least safe from the other hazard:
@@ -154,29 +141,6 @@
154
141
  color: var(--_qm-ink-label);
155
142
  min-width: 0;
156
143
  }
157
- /* A short description, in flow: the row's own second line, so the field's grid still
158
- counts one label track and a row-sharing neighbour's control starts level. Last
159
- whatever stands at the first line's end. One weight under the label, which names
160
- where this only describes. */
161
- .qm-field-label-row.briefed {
162
- flex-wrap: wrap;
163
- row-gap: 0;
164
- }
165
- .qm-field-brief {
166
- order: 1;
167
- flex: 0 0 100%;
168
- min-width: 0;
169
- font-size: var(--_qm-text-label);
170
- line-height: var(--_qm-leading-body);
171
- color: var(--_qm-ink-label);
172
- }
173
- .qm-field-brief :global(p) {
174
- margin: 0;
175
- }
176
- .qm-field-brief :global(code) {
177
- font-family: var(--_qm-font-mono);
178
- font-size: inherit;
179
- }
180
144
  .qm-field-count {
181
145
  margin-inline-start: auto;
182
146
  font-size: var(--_qm-text-label);
@@ -11,9 +11,6 @@ interface Props {
11
11
  onActivate?: () => void;
12
12
  /** Schema `description`, or undefined: the affordance renders only when set. */
13
13
  description?: string;
14
- /** A short description stands under the label ({@link isBrief}). Off where the
15
- * row has no second line to give, a table column's head. */
16
- brief?: boolean;
17
14
  /** A capped field's character count, drawn at the row's end. */
18
15
  count?: string;
19
16
  /** The count's own id, for the control's `aria-describedby`. */
@@ -2,8 +2,7 @@
2
2
  An open matrix's add box (INVARIANTS §"The matrix"): a plain text input. Enter adds
3
3
  what was typed, trimmed, and clears the box, and so does the focus leaving it: words
4
4
  typed there are an item, not a draft a click elsewhere discards. Escape clears it
5
- unadded. It is drawn as the item
6
- it adds, unwritten: the plus in the tick's column and the words in the title's.
5
+ unadded. It is a box the width of the list, the plus inside it at its start.
7
6
  -->
8
7
  <script lang="ts">
9
8
  import Icon from './icons/Icon.svelte';
@@ -66,21 +65,22 @@
66
65
  .qm-matrix-add {
67
66
  min-width: 0;
68
67
  }
69
- /* An added item's head (`MatrixField.svelte`): the glyph a tick's width at the
70
- tick's place, the gap after it the head's, and the input pulled back over that gap
71
- by its own inset, so its words start where the titles above them do. A `<label>`,
72
- so a press on the glyph lands in the box. */
68
+ /* The glyph stands inside the box, at its start inset, as a list's standing row draws
69
+ its words inside its own: the box is the whole row, and the input's words start a
70
+ gap past the glyph. A `<label>`, so a press on the glyph lands in the box. */
73
71
  .qm-matrix-add-field {
72
+ position: relative;
74
73
  display: flex;
75
74
  align-items: center;
76
- gap: var(--_qm-space-2);
77
75
  min-width: 0;
78
76
  }
79
77
  .qm-matrix-add :global(.qm-matrix-add-glyph) {
80
- flex-shrink: 0;
78
+ position: absolute;
79
+ inset-inline-start: var(--_qm-space-3);
81
80
  width: var(--_qm-glyph-control);
82
81
  height: var(--_qm-glyph-control);
83
82
  color: var(--_qm-ink-label);
83
+ pointer-events: none;
84
84
  }
85
85
  /* At rest the box is the add chip it stands in for: no well, and its words at the
86
86
  label ink in full, as the add chip's are: words take the text floor, not the rest rung
@@ -88,8 +88,7 @@
88
88
  .qm-matrix-add-field .qm-input {
89
89
  flex: 1;
90
90
  min-width: 0;
91
- margin-inline-start: calc(-1 * var(--_qm-space-2));
92
- padding-inline-start: var(--_qm-space-2);
91
+ padding-inline-start: calc(var(--_qm-space-3) + var(--_qm-glyph-control) + var(--_qm-space-2));
93
92
  transition: background-color var(--_qm-duration-fast) var(--_qm-ease-reverse);
94
93
  }
95
94
  .qm-matrix-add-field .qm-input:placeholder-shown:not(:focus) {
@@ -4,9 +4,12 @@
4
4
  list, one member to a row, or abreast on the section's track ladder under
5
5
  `ui.compact`; each member is a real checkbox whose checked state is the member's
6
6
  presence, with its title as the `<label for>`, an unheld member reading at the label
7
- ink and a held one at the value ink. A held member unfolds its columns beneath its
8
- title, drawn by {@link ObjectField} over the matrix's `properties` at the member's key;
9
- zero columns is a checklist and unfolds nothing.
7
+ ink and a held one at the value ink. A held member rests as one line, its title then
8
+ the words of its first one-line text column at the label ink, and a disclosure there
9
+ unfolds its columns beneath it, drawn by {@link ObjectField} over the matrix's
10
+ `properties` at the member's key, in the member's own track, so opening one moves no
11
+ other. A tick, an add and a landing unfold the member, as does a proposal or a
12
+ diagnostic on one of its columns; zero columns is a checklist and unfolds nothing.
10
13
 
11
14
  An open matrix's added items follow the roster in id order, as the plate prints them:
12
15
  held by being present, so each draws a fixed tick, its `title` as an input, a remove,
@@ -27,6 +30,7 @@
27
30
  -->
28
31
  <script lang="ts">
29
32
  import { onDestroy, tick as flush } from 'svelte';
33
+ import { SvelteSet } from 'svelte/reactivity';
30
34
  import { wording } from './strings.js';
31
35
  import { structuralUndo } from './undo.svelte.js';
32
36
 
@@ -45,6 +49,7 @@
45
49
  baseType,
46
50
  commitMember,
47
51
  declaredContent,
52
+ firstShortText,
48
53
  matrixColumns,
49
54
  matrixDeclares,
50
55
  matrixEmpty,
@@ -165,6 +170,25 @@
165
170
  /** An added item's title input: the `title` cell's own control id. */
166
171
  const itemTitleId = (id: string): string => propertyDomIds(memberBase(id), MATRIX_TITLE).control;
167
172
 
173
+ /** The disclosure glyph, at the size an array row's takes. */
174
+ const CHEVRON = 16;
175
+ /** The held items whose details are unfolded, for this mount: a held item rests as one
176
+ * line, and a tick or an add opens it, its details being what the author came to fill. */
177
+ const expanded = new SvelteSet<string>();
178
+ /** Whether a held item's details are drawn: unfolded by the reader, or holding a
179
+ * proposal or a diagnostic for one of its cells, each drawn on its cell. */
180
+ const isOpen = (id: string): boolean =>
181
+ hasColumns &&
182
+ (expanded.has(id) ||
183
+ cellReview(id).length > 0 ||
184
+ (routed.below.get(id)?.some((d) => d.steps[0] !== MATRIX_TITLE) ?? false));
185
+ /** What a folded item shows of its details: the words an array row's summary reads. */
186
+ const tail = (id: string): string | undefined =>
187
+ firstShortText(schema.properties, shownColumns(id));
188
+ function toggle(id: string): void {
189
+ if (expanded.has(id)) expanded.delete(id);
190
+ else expanded.add(id);
191
+ }
168
192
  /** The columns an untick took, by member id, for a retick in this mount to restore. */
169
193
  const stash = new Map<string, Record<string, unknown>>();
170
194
  /** Commit the map; one holding nothing is the field's empty answer (`matrixEmpty`). */
@@ -215,6 +239,8 @@
215
239
  async function tick(id: string, on: boolean, el: HTMLInputElement): Promise<void> {
216
240
  const item = proposal(id);
217
241
  const cells = cellReview(id);
242
+ if (on) expanded.add(id);
243
+ else expanded.delete(id);
218
244
  if (item && on === matrixHeld(item.after)) reviewing.act(item.id, 'accept');
219
245
  else if (!item && !on && !held(id) && cells.length)
220
246
  for (const { item: cell } of cells) reviewing.act(cell.id, 'dismiss');
@@ -268,6 +294,7 @@
268
294
  undo.withdraw();
269
295
  const id = addedId(title, taken);
270
296
  commit(commitMember(map, id, memberWrite({}, title)));
297
+ expanded.add(id);
271
298
  await flush();
272
299
  const box = own(memberEls, id);
273
300
  // The item's columns are what the author came to fill; a checklist has none, and
@@ -307,11 +334,16 @@
307
334
  return undefined;
308
335
  }
309
336
  const column = rest[0];
310
- const cells = own(colEls, id);
311
337
  const member = own(memberEls, id);
312
- if (column !== undefined && column !== MATRIX_TITLE && cells) {
313
- const inner = cells.focusPath(rest, pos);
314
- return inner instanceof Promise ? inner.then((box) => box ?? member) : (inner ?? member);
338
+ if (column !== undefined && column !== MATRIX_TITLE && hasColumns && shownHeld(id)) {
339
+ const into = (cells: Subform | undefined): LandingBox => {
340
+ if (!cells) return member;
341
+ const inner = cells.focusPath(rest, pos);
342
+ return inner instanceof Promise ? inner.then((box) => box ?? member) : (inner ?? member);
343
+ };
344
+ if (own(colEls, id)) return into(own(colEls, id));
345
+ expanded.add(id);
346
+ return flush().then(() => into(own(colEls, id)));
315
347
  }
316
348
  (own(tickEls, id) ?? own(titleEls, id))?.focus();
317
349
  return member;
@@ -342,7 +374,7 @@
342
374
  {#each members as m (m.id)}
343
375
  {@const on = shownHeld(m.id)}
344
376
  <div
345
- class={['qm-member qm-wash', { held: on, open: on && hasColumns }]}
377
+ class={['qm-member qm-wash', { held: on, open: on && isOpen(m.id) }]}
346
378
  data-qm-prop={m.id}
347
379
  bind:this={memberEls[m.id]}
348
380
  >
@@ -364,6 +396,9 @@
364
396
  </span>
365
397
  <ReviewRows entries={reviewed.below.get(m.id)?.filter((e) => !e.steps.length)} />
366
398
  <label class="qm-member-title" id={titleId(m.id)} for={tickId(m.id)}>{m.title}</label>
399
+ {#if on && hasColumns}
400
+ {@render disclosure(m.id, m.title)}
401
+ {/if}
367
402
  </div>
368
403
  {@render columns(m.id, m.title, on)}
369
404
  </div>
@@ -371,7 +406,7 @@
371
406
  {#each added as item, k (item.id)}
372
407
  {@const name = item.title || t.strings.matrixItemTitle(label ?? '', k + 1)}
373
408
  <div
374
- class={['qm-member qm-wash held added', { open: hasColumns }]}
409
+ class={['qm-member qm-wash held added', { open: isOpen(item.id) }]}
375
410
  data-qm-prop={item.id}
376
411
  bind:this={memberEls[item.id]}
377
412
  >
@@ -392,6 +427,9 @@
392
427
  oninput={(e) => retitle(item.id, e.currentTarget.value)}
393
428
  />
394
429
  <span class="qm-member-title" id={titleId(item.id)} hidden>{name}</span>
430
+ {#if hasColumns}
431
+ {@render disclosure(item.id, name)}
432
+ {/if}
395
433
  <button
396
434
  type="button"
397
435
  class="qm-icon-btn qm-focus-ring qm-member-remove"
@@ -421,7 +459,7 @@
421
459
  a tick elsewhere leaves this subform mounted and the caret in it. -->
422
460
  {#snippet columns(id: string, title: string, on: boolean)}
423
461
  {@const deep = routed.below.get(id)}
424
- {#if on && hasColumns}
462
+ {#if on && isOpen(id)}
425
463
  <ObjectField
426
464
  bind:this={colEls[id]}
427
465
  value={shownColumns(id)}
@@ -442,6 +480,22 @@
442
480
  {/if}
443
481
  {/snippet}
444
482
 
483
+ <!-- A held item's disclosure: its details' first line of words, muted after the name,
484
+ and the chevron that unfolds them, the way a record row opens. -->
485
+ {#snippet disclosure(id: string, title: string)}
486
+ {@const words = isOpen(id) ? undefined : tail(id)}
487
+ <button
488
+ type="button"
489
+ class="qm-focus-ring qm-member-summary"
490
+ aria-expanded={isOpen(id)}
491
+ aria-label={t.strings.matrixDetails(title)}
492
+ onclick={() => toggle(id)}
493
+ >
494
+ <span class="qm-member-tail">{words ?? ''}</span>
495
+ <Icon name="chevron-right" class="qm-member-chevron" size={CHEVRON} />
496
+ </button>
497
+ {/snippet}
498
+
445
499
  <style>
446
500
  .qm-matrix {
447
501
  display: flex;
@@ -456,11 +510,6 @@
456
510
  justify-content: space-between;
457
511
  gap: var(--_qm-space-2);
458
512
  }
459
- /* Under a label that carries its description in flow, the count keeps the label's
460
- line rather than centring on the two. */
461
- .qm-matrix-header:has(> :global(.qm-field-label-row.briefed)) {
462
- align-items: baseline;
463
- }
464
513
  /* The count reads at the label rung: a fact about the field, never a value. */
465
514
  .qm-matrix-count {
466
515
  font-size: var(--_qm-text-label);
@@ -500,6 +549,49 @@
500
549
  .qm-matrix-roster:not(.compact) > .qm-member.open {
501
550
  margin-block: var(--_qm-space);
502
551
  }
552
+ /* The rest of the line is the disclosure: the details' words at the label ink, cut
553
+ to the line, then the chevron, which turns down as the details open. */
554
+ .qm-member-summary {
555
+ flex: 1;
556
+ min-width: 0;
557
+ align-self: stretch;
558
+ display: flex;
559
+ align-items: center;
560
+ gap: var(--_qm-space);
561
+ padding: 0;
562
+ margin: 0;
563
+ border: none;
564
+ border-radius: var(--_qm-radius-inner);
565
+ background: transparent;
566
+ font: inherit;
567
+ color: var(--_qm-ink-label);
568
+ text-align: start;
569
+ cursor: pointer;
570
+ }
571
+ .qm-member-tail {
572
+ flex: 1;
573
+ min-width: 0;
574
+ overflow: hidden;
575
+ white-space: nowrap;
576
+ text-overflow: ellipsis;
577
+ font-size: var(--_qm-text-body);
578
+ line-height: var(--_qm-leading-tight);
579
+ }
580
+ .qm-member-summary :global(.qm-member-chevron) {
581
+ flex-shrink: 0;
582
+ stroke-width: var(--_qm-glyph-stroke);
583
+ opacity: var(--_qm-opacity-rest);
584
+ transition:
585
+ transform var(--_qm-duration-slow) var(--_qm-ease-reverse),
586
+ opacity var(--_qm-duration-fast) var(--_qm-ease-reverse);
587
+ }
588
+ .qm-member-summary:hover :global(.qm-member-chevron),
589
+ .qm-member-summary:focus-visible :global(.qm-member-chevron) {
590
+ opacity: 1;
591
+ }
592
+ .qm-member-summary[aria-expanded='true'] :global(.qm-member-chevron) {
593
+ transform: rotate(90deg);
594
+ }
503
595
  /* The tick and its title on one line, the line holding the tap floor a tick alone
504
596
  would not reach: the title is the target, the `for` carrying its press to the input. */
505
597
  .qm-member-head {
@@ -43,8 +43,7 @@
43
43
  fieldModels,
44
44
  fieldTitle,
45
45
  isContainer,
46
- linesOnly,
47
- literalText,
46
+ leafFlags,
48
47
  mountKey,
49
48
  optionalCell,
50
49
  own,
@@ -59,7 +58,7 @@
59
58
  numberProposal,
60
59
  shownValue,
61
60
  splitReview,
62
- textProposal,
61
+ textsOf,
63
62
  type DeepReview,
64
63
  type FieldProposal
65
64
  } from './review.js';
@@ -130,6 +129,11 @@
130
129
  * one naming a property draws under that property's control, and one naming
131
130
  * nothing this subform holds draws at its foot (`diagnostics.ts`). */
132
131
  diagnostics?: readonly DeepDiagnostic[];
132
+ /** Enum-option policy for an enum property at any depth of this subform, `steps` the
133
+ * properties from here down to it. */
134
+ optionAllowed?: (value: string, steps: readonly PathStep[]) => boolean;
135
+ /** How a refused option draws: greyed (default) or left out. */
136
+ enumDisallowed?: 'hide' | 'disable';
133
137
  /** The review items naming a place inside this subform, each with its steps still to
134
138
  * walk: one naming a cell draws under the cell's control, one naming a place inside a
135
139
  * record or a list cell is handed to it, and the rest draw under the cell they are in
@@ -150,6 +154,8 @@
150
154
  placed = false,
151
155
  onCellKey,
152
156
  diagnostics,
157
+ optionAllowed,
158
+ enumDisallowed,
153
159
  review
154
160
  }: Props = $props();
155
161
 
@@ -316,13 +322,13 @@
316
322
  {@const deep = routed.below.get(key)}
317
323
  {@const reviewHere = reviewed.below.get(key)}
318
324
  {@const handsDown = isContainer(kind)}
319
- {@const ownItem = handsDown ? undefined : reviewHere?.find((e) => !e.steps.length)?.item}
320
- {@const textOwn =
321
- kind === 'prose' && (shortCell(sub) || literalText(sub))
322
- ? textProposal(ownItem, contentDefault(sub))
323
- : undefined}
325
+ {@const ownItems = handsDown
326
+ ? []
327
+ : (reviewHere ?? []).filter((e) => !e.steps.length).map((e) => e.item)}
328
+ {@const ownItem = ownItems[0]}
329
+ {@const textOwn = kind === 'prose' ? textsOf(ownItems, contentDefault(sub)) : undefined}
324
330
  {@const numberOwn = kind === 'number' ? numberProposal(ownItem) : undefined}
325
- {@const worded = textOwn ?? numberOwn}
331
+ {@const worded = textOwn?.[0] ?? numberOwn}
326
332
  {@const shownItem = worded ? undefined : ownItem}
327
333
  {@const shown = shownValue(shownItem, obj[key])}
328
334
  {@const commitCell = (v: unknown) => answerOrCommit(shownItem, key, v)}
@@ -385,6 +391,8 @@
385
391
  optional={optionalCell(sub)}
386
392
  onCommit={commitCell}
387
393
  proposing={!!shownItem}
394
+ optionAllowed={optionAllowed && ((v) => optionAllowed(v, [key]))}
395
+ {enumDisallowed}
388
396
  />
389
397
  {:else if kind === 'number'}
390
398
  <NumberField
@@ -442,8 +450,8 @@
442
450
  : contentAt([key])}
443
451
  value={shown}
444
452
  fallback={contentDefault(sub)}
445
- plaintext={literalText(sub)}
446
- paragraphs={linesOnly(sub)}
453
+ plaintext={leafFlags(sub).plaintext}
454
+ paragraphs={leafFlags(sub).paragraphs}
447
455
  placeholder={ownItem ? undefined : noneOf(key, sub)}
448
456
  {block}
449
457
  label={named}
@@ -483,6 +491,8 @@
483
491
  value={obj[key] as Record<string, unknown> | undefined}
484
492
  properties={sub.properties}
485
493
  {placed}
494
+ optionAllowed={optionAllowed && ((v, steps) => optionAllowed(v, [key, ...steps]))}
495
+ {enumDisallowed}
486
496
  label={ids ? undefined : fallbackName(key, sub)}
487
497
  idBase={ids?.control}
488
498
  labelledBy={ids?.label}
@@ -513,6 +523,8 @@
513
523
  value={obj[key] as Record<string, unknown> | undefined}
514
524
  schema={sub}
515
525
  ghostMember={sub.default as string | undefined}
526
+ optionAllowed={optionAllowed && ((v) => optionAllowed(v, [key]))}
527
+ {enumDisallowed}
516
528
  label={fieldTitle(key, sub)}
517
529
  id={ids?.control}
518
530
  labelledBy={ids?.label}
@@ -534,7 +546,7 @@
534
546
  <DiagnosticList diagnostics={own} />
535
547
  {#if !handsDown}
536
548
  <ReviewRows
537
- entries={worded ? reviewHere?.filter((e) => e.item !== ownItem) : reviewHere}
549
+ entries={worded ? reviewHere?.filter((e) => !ownItems.includes(e.item)) : reviewHere}
538
550
  />
539
551
  {/if}
540
552
  </div>
@@ -49,6 +49,11 @@ interface Props {
49
49
  * one naming a property draws under that property's control, and one naming
50
50
  * nothing this subform holds draws at its foot (`diagnostics.ts`). */
51
51
  diagnostics?: readonly DeepDiagnostic[];
52
+ /** Enum-option policy for an enum property at any depth of this subform, `steps` the
53
+ * properties from here down to it. */
54
+ optionAllowed?: (value: string, steps: readonly PathStep[]) => boolean;
55
+ /** How a refused option draws: greyed (default) or left out. */
56
+ enumDisallowed?: 'hide' | 'disable';
52
57
  /** The review items naming a place inside this subform, each with its steps still to
53
58
  * walk: one naming a cell draws under the cell's control, one naming a place inside a
54
59
  * record or a list cell is handed to it, and the rest draw under the cell they are in
@@ -5,7 +5,7 @@
5
5
  this leaf's commits with the caret riding the untouched view.
6
6
  -->
7
7
  <script lang="ts">
8
- import { untrack } from 'svelte';
8
+ import { onDestroy, untrack } from 'svelte';
9
9
  import {
10
10
  createField,
11
11
  type FieldController,
@@ -63,8 +63,9 @@
63
63
  cap?: TextCap;
64
64
  /** Registry identity, stamped on the DOM node so a remount is visible as one. */
65
65
  leafKey: string;
66
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
67
- proposed?: TextProposal;
66
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
67
+ * over its text as a word diff. */
68
+ proposed?: readonly TextProposal[];
68
69
  onFocus?: (addr: Addr) => void;
69
70
  onCaretMove?: (addr: Addr, pos: number) => void;
70
71
  /** A commit landed on this leaf: the prose change lane. */
@@ -197,13 +198,20 @@
197
198
  controller?.setReview(reviewing.textAt(leafKey), reviewing.lit);
198
199
  });
199
200
  $effect(() => {
200
- controller?.setValueProposal(proposed && { ...proposed, lit: reviewing.lit === proposed.id });
201
+ controller?.setValueProposals(
202
+ (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }))
203
+ );
201
204
  });
205
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
206
+ * list is answered, which would leave its own Accept writing its value whole. */
207
+ let plannedIds: readonly string[] = [];
202
208
  $effect(() => {
203
- const id = proposed?.id;
204
- return () => {
205
- if (id !== undefined) reviewing.planned(id, undefined);
206
- };
209
+ const ids = (proposed ?? []).map((p) => p.id);
210
+ for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
211
+ plannedIds = ids;
212
+ });
213
+ onDestroy(() => {
214
+ for (const id of plannedIds) reviewing.planned(id, undefined);
207
215
  });
208
216
 
209
217
  // Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
@@ -45,8 +45,9 @@ interface Props {
45
45
  cap?: TextCap;
46
46
  /** Registry identity, stamped on the DOM node so a remount is visible as one. */
47
47
  leafKey: string;
48
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
49
- proposed?: TextProposal;
48
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
49
+ * over its text as a word diff. */
50
+ proposed?: readonly TextProposal[];
50
51
  onFocus?: (addr: Addr) => void;
51
52
  onCaretMove?: (addr: Addr, pos: number) => void;
52
53
  /** A commit landed on this leaf: the prose change lane. */
@@ -45,7 +45,7 @@
45
45
  replacement reads, so a write moving the value takes it or releases it.
46
46
  -->
47
47
  <script lang="ts">
48
- import { untrack } from 'svelte';
48
+ import { onDestroy, untrack } from 'svelte';
49
49
  import { Fragment, Slice, type Node as PMNode } from 'prosemirror-model';
50
50
  import { EditorState, Selection } from 'prosemirror-state';
51
51
  import { EditorView } from 'prosemirror-view';
@@ -58,6 +58,7 @@
58
58
  heldAttributes,
59
59
  joinLines,
60
60
  leafSchema,
61
+ isParagraphsSchema,
61
62
  pastedLines,
62
63
  pmToContent,
63
64
  proseAttributes,
@@ -136,8 +137,9 @@
136
137
  * array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
137
138
  * keymap, so the state it reads is the one this keystroke has yet to change. */
138
139
  onKey?: (e: KeyboardEvent) => void;
139
- /** A whole proposed value for a leaf of lines, drawn over its text as a word diff. */
140
- proposed?: TextProposal;
140
+ /** Proposed values over the leaf's words, a whole one or each run of one answer, drawn
141
+ * over its text as a word diff. */
142
+ proposed?: readonly TextProposal[];
141
143
  }
142
144
  let {
143
145
  content,
@@ -158,21 +160,23 @@
158
160
  }: Props = $props();
159
161
 
160
162
  const reviewing = review();
161
- /** The proposal the value-diff plugin reads, and the view it redraws. */
162
- let drawnProposal: ValueProposal | undefined;
163
+ /** The proposals the value-diff plugin reads, and the view it redraws. */
164
+ let drawnProposals: readonly ValueProposal[] = [];
163
165
  let redraw: (() => void) | undefined;
164
166
  $effect(() => {
165
- drawnProposal =
166
- proposed && (!block || plaintext)
167
- ? { ...proposed, lit: reviewing.lit === proposed.id }
168
- : undefined;
167
+ drawnProposals = (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }));
169
168
  redraw?.();
170
169
  });
170
+ /** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
171
+ * list is answered, which would leave its own Accept writing its value whole. */
172
+ let plannedIds: readonly string[] = [];
171
173
  $effect(() => {
172
- const id = proposed?.id;
173
- return () => {
174
- if (id !== undefined) reviewing.planned(id, undefined);
175
- };
174
+ const ids = (proposed ?? []).map((p) => p.id);
175
+ for (const id of plannedIds) if (!ids.includes(id)) reviewing.planned(id, undefined);
176
+ plannedIds = ids;
177
+ });
178
+ onDestroy(() => {
179
+ for (const id of plannedIds) reviewing.planned(id, undefined);
176
180
  });
177
181
 
178
182
  const t = wording();
@@ -278,7 +282,8 @@
278
282
  // Which of `aria-label` / `aria-labelledby` wins is the codec's one answer
279
283
  // (`proseAttributes`), so a cell carrying a label element and a row carrying
280
284
  // none cannot name their regions by different rules.
281
- const plainNamed = () => proseAttributes(names(), !inline);
285
+ const lineLeaf = isParagraphsSchema(leafSchema({ plaintext, inline, paragraphs }));
286
+ const plainNamed = () => proseAttributes(names(), !inline, lineLeaf);
282
287
  const heldNamed = () => heldAttributes(names(), heldId);
283
288
  const build = (rt: Content): EditorState => {
284
289
  // The same keymap and plugin stack a `createField` leaf mounts (shared
@@ -294,15 +299,12 @@
294
299
  placeholder: () => drawn.placeholder,
295
300
  leaveStrings: () => t.strings,
296
301
  cap,
297
- afterHistory:
298
- inline || plaintext
299
- ? [
300
- valueDiffPlugin(
301
- () => drawnProposal,
302
- (id, state) => reviewing.planned(id, state)
303
- )
304
- ]
305
- : []
302
+ afterHistory: [
303
+ valueDiffPlugin(
304
+ () => drawnProposals,
305
+ (id, state) => reviewing.planned(id, state)
306
+ )
307
+ ]
306
308
  })
307
309
  });
308
310
  };