@quillmark/svelte 0.35.1 → 0.36.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 (60) hide show
  1. package/README.md +21 -13
  2. package/dist/core/address.d.ts +5 -0
  3. package/dist/core/address.js +14 -0
  4. package/dist/core/codec/field.d.ts +30 -7
  5. package/dist/core/codec/field.js +67 -4
  6. package/dist/core/codec/index.d.ts +6 -3
  7. package/dist/core/codec/index.js +2 -3
  8. package/dist/core/codec/prose.css +11 -77
  9. package/dist/core/codec/review.d.ts +27 -21
  10. package/dist/core/codec/review.js +87 -148
  11. package/dist/core/codec/shortcuts.d.ts +3 -3
  12. package/dist/core/codec/shortcuts.js +7 -7
  13. package/dist/core/codec/value-diff.d.ts +21 -0
  14. package/dist/core/codec/value-diff.js +83 -0
  15. package/dist/core/codec/value-plan.d.ts +29 -0
  16. package/dist/core/codec/value-plan.js +157 -0
  17. package/dist/core/theme.css +7 -2
  18. package/dist/visual/ArrayField.svelte +191 -17
  19. package/dist/visual/Card.svelte +12 -1
  20. package/dist/visual/Card.svelte.d.ts +3 -0
  21. package/dist/visual/EnumField.svelte +14 -4
  22. package/dist/visual/EnumField.svelte.d.ts +3 -0
  23. package/dist/visual/Field.svelte +56 -47
  24. package/dist/visual/FieldHint.svelte +1 -0
  25. package/dist/visual/FormatPopover.svelte +1 -0
  26. package/dist/visual/MatrixField.svelte +43 -5
  27. package/dist/visual/MatrixField.svelte.d.ts +5 -0
  28. package/dist/visual/NumberField.svelte +112 -3
  29. package/dist/visual/NumberField.svelte.d.ts +5 -0
  30. package/dist/visual/ObjectField.svelte +54 -16
  31. package/dist/visual/ProseField.svelte +16 -3
  32. package/dist/visual/ProseField.svelte.d.ts +3 -0
  33. package/dist/visual/ProseValue.svelte +38 -2
  34. package/dist/visual/ProseValue.svelte.d.ts +3 -0
  35. package/dist/visual/ReviewCard.svelte +347 -0
  36. package/dist/visual/ReviewCard.svelte.d.ts +19 -0
  37. package/dist/visual/ReviewProposal.svelte +104 -138
  38. package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
  39. package/dist/visual/ReviewRows.svelte +6 -25
  40. package/dist/visual/ReviewRows.svelte.d.ts +1 -3
  41. package/dist/visual/SlashMenu.svelte +1 -0
  42. package/dist/visual/VariantField.svelte +44 -4
  43. package/dist/visual/VariantField.svelte.d.ts +5 -0
  44. package/dist/visual/VisualEditor.svelte +16 -7
  45. package/dist/visual/VisualEditor.svelte.d.ts +3 -0
  46. package/dist/visual/VisualEditorInner.svelte +840 -115
  47. package/dist/visual/VisualEditorInner.svelte.d.ts +3 -0
  48. package/dist/visual/index.d.ts +2 -2
  49. package/dist/visual/proposals.d.ts +13 -22
  50. package/dist/visual/proposals.js +69 -32
  51. package/dist/visual/props.d.ts +18 -18
  52. package/dist/visual/review.d.ts +68 -3
  53. package/dist/visual/review.js +36 -1
  54. package/dist/visual/review.svelte.d.ts +55 -15
  55. package/dist/visual/review.svelte.js +156 -42
  56. package/dist/visual/strings.d.ts +23 -6
  57. package/dist/visual/strings.js +10 -5
  58. package/dist/visual/undo.svelte.d.ts +3 -1
  59. package/dist/visual/undo.svelte.js +7 -3
  60. package/package.json +1 -1
@@ -60,8 +60,7 @@
60
60
  import ReviewProposal from './ReviewProposal.svelte';
61
61
  import ReviewRows from './ReviewRows.svelte';
62
62
  import { review } from './review.svelte.js';
63
- import { REVIEW_KEYS } from '../core/codec/index.js';
64
- import { keydownHandler } from 'prosemirror-keymap';
63
+ import { numberProposal, shownValue, textProposal } from './review.js';
65
64
 
66
65
  interface Props {
67
66
  field: FieldModel;
@@ -147,8 +146,14 @@
147
146
  // resolves to digits, and the control has to know it follows the render date.
148
147
  const declared = $derived(printedText(field.schema.default));
149
148
  const optional = $derived(optionalCell(field.schema));
149
+ // A proposal is drawn in the control. The focus arriving in the control makes it current, as
150
+ // the caret arriving in a leaf's words makes theirs.
151
+ const reviewing = review();
152
+ const reviewed = $derived(reviewing.at(leafKey));
153
+ const proposed = $derived(reviewed.proposed);
150
154
  // Where the field stands against its default, for the label row's end (`FieldLabel`):
151
- // unset with the default printing, or written over one that would. A container's
155
+ // unset with the default printing, or written over one that would. A proposal standing on
156
+ // the field says the value it would hold, so the default goes unsaid meanwhile. A container's
152
157
  // source is its cells' composed, so only a control holding one value says either.
153
158
  const scalar = $derived(!isContainer(field.control));
154
159
  // A prose leaf commits past the derive (`VisualEditorInner` `proseChanged`), so its
@@ -159,7 +164,7 @@
159
164
  since && since.row === provenance ? since.written : provenance?.source === 'authored'
160
165
  );
161
166
  const defaulted = $derived(
162
- scalar && !written && provenance?.source === 'default' && printed !== undefined
167
+ scalar && !written && provenance?.source === 'default' && printed !== undefined && !proposed
163
168
  );
164
169
  const resettable = $derived(scalar && written && declared !== undefined);
165
170
  const defaultId = $derived(`${domIds.control}-default`);
@@ -318,33 +323,29 @@
318
323
  * rather than counted twice.
319
324
  */
320
325
  // ── Review: this field's own items (`review.svelte.ts`) ──────────────────────
321
- // A proposal rests as a row under the control. The focus in the control attends to it, as
322
- // the caret in a leaf's words attends to theirs.
323
- const reviewing = review();
324
- const reviewed = $derived(reviewing.at(leafKey));
325
- const proposed = $derived(reviewed.proposed);
326
+ /** A whole proposed value drawn as words over the control's own: a leaf of lines' as a word
327
+ * diff, carried onto what the reader wrote since its writer read it, a number's as the struck
328
+ * and the proposed figures. */
329
+ const texted = $derived(
330
+ field.control === 'prose' && (field.inline || field.plaintext)
331
+ ? textProposal(proposed, printed ? (ghost as Content) : undefined)
332
+ : undefined
333
+ );
334
+ const numbered = $derived(field.control === 'number' ? numberProposal(proposed) : undefined);
335
+ const worded = $derived(texted ?? numbered);
336
+ /** What a control that cannot draw a proposal as words shows while one stands: the value
337
+ * Accept would write, tinted (`ReviewProposal`), or its default or empty face where Accept
338
+ * clears it. */
339
+ const display = $derived(proposed && !worded ? shownValue(proposed, value) : value);
340
+ /** A commit on a control that shows one value answers the proposal on it: the proposed value
341
+ * accepts it, any other dismisses it (INVARIANTS §Review). */
342
+ function answerOrCommit(v: unknown): void {
343
+ if (proposed && reviewing.answerWith(proposed.id, v)) return;
344
+ onCommitScalar(v);
345
+ }
326
346
  /** The items naming a place inside this field: a record's and a list's own controls draw
327
347
  * them where they are, any other's under this one. */
328
348
  const nestedReview = $derived(reviewed.nested);
329
- /** The chords, with the focus anywhere in the field: the proposal's answers. A prose leaf's
330
- * own items answer first, in the leaf. */
331
- const reviewKeys = keydownHandler({
332
- [REVIEW_KEYS.accept]: () => {
333
- if (!proposed) return false;
334
- reviewing.act(proposed.id, 'accept', true);
335
- return true;
336
- },
337
- [REVIEW_KEYS.dismiss]: () => {
338
- if (!proposed) return false;
339
- reviewing.act(proposed.id, 'dismiss', true);
340
- return true;
341
- }
342
- });
343
- function onReviewKey(e: KeyboardEvent): void {
344
- if (e.defaultPrevented || !proposed) return;
345
- // The bindings read no view: this is `prosemirror-keymap`'s chord matcher alone.
346
- if (reviewKeys({} as never, e)) e.preventDefault();
347
- }
348
349
 
349
350
  const reportFocus = $derived(
350
351
  field.control === 'prose'
@@ -354,9 +355,7 @@
354
355
  );
355
356
  </script>
356
357
 
357
- <!-- svelte-ignore a11y_no_static_element_interactions -->
358
- <!-- The keydown is a control's, bubbled: the field answers the review chords for it. -->
359
- <div class={['qm-field', { cell: span === 'cell' }]} data-tail={tail} onkeydown={onReviewKey}>
358
+ <div class={['qm-field', { cell: span === 'cell' }]} data-tail={tail}>
360
359
  {#if !ownsLabel && !headed}
361
360
  <FieldLabel
362
361
  label={field.label}
@@ -377,14 +376,16 @@
377
376
  rule below holds why). One markup for both spans; a field owning its row nests a
378
377
  level and measures the same. -->
379
378
  <div class="qm-field-stack">
379
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
380
380
  <div
381
381
  class="qm-field-control qm-wash"
382
382
  {@attach registerControl}
383
383
  onfocusin={(e) => {
384
384
  reportFocus?.(e);
385
- if (proposed) reviewing.point(proposed.id, 'caret', leafKey);
385
+ if (proposed) reviewing.point(proposed.id, 'caret');
386
386
  }}
387
- onfocusout={() => proposed && reviewing.point(undefined, 'caret', leafKey)}
387
+ onpointerenter={() => worded && reviewing.point(worded.id, 'pointer')}
388
+ onpointerleave={() => worded && reviewing.point(undefined, 'pointer')}
388
389
  >
389
390
  {#if field.control === 'prose'}
390
391
  <ProseField
@@ -395,13 +396,14 @@
395
396
  inline={field.inline}
396
397
  plaintext={field.plaintext}
397
398
  fallback={printed ? (ghost as Content) : undefined}
398
- placeholder={none}
399
+ placeholder={proposed ? undefined : none}
399
400
  emptyUnsets={optional}
400
401
  labelledBy={domIds.label}
401
402
  describedBy={proseDescribedBy}
402
403
  defaultNoteId={defaultId}
403
404
  cap={cap && { ...cap, onCount: (n) => (chars = n) }}
404
405
  {leafKey}
406
+ proposed={texted}
405
407
  {onFocus}
406
408
  {onCaretMove}
407
409
  onChange={proseCommitted}
@@ -411,21 +413,22 @@
411
413
  />
412
414
  {:else if field.control === 'enum'}
413
415
  <EnumField
414
- value={value as string | undefined}
416
+ value={display as string | undefined}
415
417
  values={field.schema.values ?? []}
416
418
  fallback={(ghost as string | undefined) ?? declared}
417
419
  blankTitle={field.schema.ui?.blank_title}
418
420
  {optional}
419
421
  id={domIds.control}
420
422
  {describedBy}
421
- onCommit={onCommitScalar}
423
+ onCommit={answerOrCommit}
424
+ proposing={!!proposed}
422
425
  {optionAllowed}
423
426
  {enumDisallowed}
424
427
  />
425
428
  {:else if field.control === 'variant'}
426
429
  <VariantField
427
430
  bind:this={variantEl}
428
- value={value as Record<string, unknown> | undefined}
431
+ value={display as Record<string, unknown> | undefined}
429
432
  schema={field.schema}
430
433
  {ghostMember}
431
434
  label={field.label}
@@ -437,10 +440,12 @@
437
440
  {optionAllowed}
438
441
  {enumDisallowed}
439
442
  diagnostics={deep}
443
+ review={nestedReview}
440
444
  />
441
445
  {:else if field.control === 'number'}
442
446
  <NumberField
443
- value={value as number | undefined}
447
+ value={display as number | undefined}
448
+ proposed={numbered}
444
449
  integer={baseType(field.schema) === 'integer'}
445
450
  fallback={declared}
446
451
  placeholder={none}
@@ -450,22 +455,22 @@
450
455
  />
451
456
  {:else if field.control === 'boolean'}
452
457
  <BooleanField
453
- value={renderedBoolean(value)}
458
+ value={renderedBoolean(display)}
454
459
  fallback={ghost as boolean | undefined}
455
460
  {optional}
456
461
  id={domIds.control}
457
462
  {describedBy}
458
- onCommit={onCommitScalar}
463
+ onCommit={answerOrCommit}
459
464
  />
460
465
  {:else if field.control === 'date'}
461
466
  <DateField
462
467
  bind:this={dateEl}
463
- value={value as string | undefined}
468
+ value={display as string | undefined}
464
469
  fallback={stringifyGhost(field.schema.default)}
465
470
  datetime={baseType(field.schema) === 'datetime'}
466
471
  labelledBy={domIds.label}
467
472
  {describedBy}
468
- onCommit={onCommitScalar}
473
+ onCommit={answerOrCommit}
469
474
  />
470
475
  {:else if field.control === 'array'}
471
476
  <ArrayField
@@ -514,10 +519,11 @@
514
519
  {contentAt}
515
520
  onCommit={onCommitScalar}
516
521
  diagnostics={deep}
522
+ review={nestedReview}
517
523
  />
518
524
  {:else}
519
525
  <TextField
520
- value={value as string | undefined}
526
+ value={display as string | undefined}
521
527
  fallback={declared}
522
528
  placeholder={none}
523
529
  id={domIds.control}
@@ -527,11 +533,14 @@
527
533
  {/if}
528
534
  </div>
529
535
 
530
- {#if field.control !== 'object' && field.control !== 'array'}
531
- <ReviewRows entries={nestedReview} {value} />
536
+ {#if !isContainer(field.control)}
537
+ <ReviewRows entries={nestedReview} />
532
538
  {/if}
533
- {#if proposed}
534
- <ReviewProposal item={proposed} {value} refocus={focusControl} />
539
+ {#if proposed && !worded}
540
+ <ReviewProposal
541
+ item={proposed}
542
+ current={value ?? ghost ?? (field.control === 'boolean' ? false : undefined)}
543
+ />
535
544
  {/if}
536
545
  {#if scalar}
537
546
  <DiagnosticList {diagnostics} />
@@ -210,6 +210,7 @@
210
210
  <Popover.Content
211
211
  customAnchor={triggerEl ?? null}
212
212
  collisionBoundary={bounds}
213
+ strategy="absolute"
213
214
  side={beside ? 'right' : 'top'}
214
215
  align={beside ? 'center' : 'start'}
215
216
  sideOffset={(spacePx(triggerEl) ?? 0) + reach}
@@ -495,6 +495,7 @@
495
495
  <Popover.Content
496
496
  customAnchor={anchor ?? null}
497
497
  collisionBoundary={portalTarget ?? []}
498
+ strategy="absolute"
498
499
  {side}
499
500
  align="center"
500
501
  trapFocus={false}
@@ -65,6 +65,9 @@
65
65
  import ObjectField from './ObjectField.svelte';
66
66
  import MatrixAdd from './MatrixAdd.svelte';
67
67
  import DiagnosticList from './DiagnosticList.svelte';
68
+ import ReviewRows from './ReviewRows.svelte';
69
+ import { splitReview, type DeepReview } from './review.js';
70
+ import { review as reviewState } from './review.svelte.js';
68
71
  import './controls.css';
69
72
 
70
73
  interface Props {
@@ -91,6 +94,10 @@
91
94
  /** The diagnostics routed into this field, each with its steps still to walk: one
92
95
  * naming a drawn item draws under it, any other at the field's foot. */
93
96
  diagnostics?: readonly DeepDiagnostic[];
97
+ /** The review items naming a member or a cell inside one, each with its steps still to
98
+ * walk: a member's tick shows the state it would come to, its cells take their own,
99
+ * and an item no drawn member holds stands at the field's foot. */
100
+ review?: readonly DeepReview[];
94
101
  }
95
102
  let {
96
103
  value,
@@ -102,7 +109,8 @@
102
109
  idBase,
103
110
  contentAt,
104
111
  onCommit,
105
- diagnostics
112
+ diagnostics,
113
+ review
106
114
  }: Props = $props();
107
115
 
108
116
  const members = $derived(matrixMembers(schema.members));
@@ -120,6 +128,30 @@
120
128
  const routed = $derived(splitDeep(diagnostics));
121
129
  const foot = $derived(unrouted(routed, (step) => typeof step === 'string' && drawn(step)));
122
130
 
131
+ const reviewing = reviewState();
132
+ const reviewed = $derived(splitReview(review));
133
+ /** A member's own proposal: it ticks or unticks the member whole. */
134
+ const proposal = (id: string) => reviewed.below.get(id)?.find((e) => !e.steps.length)?.item;
135
+ /** Whether a member shows as held: as its proposal would leave it, else as stored. */
136
+ const shownHeld = (id: string): boolean => {
137
+ const item = proposal(id);
138
+ return item ? matrixHeld(item.after) : held(id);
139
+ };
140
+ /** The member's columns as shown: its proposal's where one ticks it, else the stored. */
141
+ const shownColumns = (id: string): Record<string, unknown> => {
142
+ const item = proposal(id);
143
+ return matrixColumns(item ? item.after : own(map, id));
144
+ };
145
+ /** The items inside a member's columns, one step down. */
146
+ const cellReview = (id: string): DeepReview[] =>
147
+ (reviewed.below.get(id) ?? []).filter((e) => e.steps.length);
148
+ const reviewFoot = $derived([
149
+ ...reviewed.here,
150
+ ...[...reviewed.below]
151
+ .filter(([step]) => typeof step !== 'string' || !drawn(step))
152
+ .flatMap(([step, list]) => list.map((e) => ({ steps: [step, ...e.steps], item: e.item })))
153
+ ]);
154
+
123
155
  // A member with no field id space around it still needs an id: the tick is what its
124
156
  // title's `for` names. Stable across SSR and hydration, which a counter is not.
125
157
  const uid = $props.id();
@@ -180,9 +212,12 @@
180
212
  * new to write. The reassert after the flush is what the styled controls get from
181
213
  * their local, a `$derived` of the value: the document is what the face reads. */
182
214
  async function tick(id: string, on: boolean, el: HTMLInputElement): Promise<void> {
183
- commit(on ? commitMember(map, id, ticked(id)) : unticked(id));
215
+ const item = proposal(id);
216
+ if (item && on === matrixHeld(item.after)) reviewing.act(item.id, 'accept');
217
+ else if (!item || !reviewing.answerWith(item.id, on ? ticked(id) : undefined))
218
+ commit(on ? commitMember(map, id, ticked(id)) : unticked(id));
184
219
  await flush();
185
- if (el.isConnected) el.checked = held(id);
220
+ if (el.isConnected) el.checked = shownHeld(id);
186
221
  }
187
222
  /** A column edit lands on a held item, an added one keeping its `title`. */
188
223
  function commitColumns(id: string, columns: Record<string, unknown>): void {
@@ -301,7 +336,7 @@
301
336
  bind:this={rosterEl}
302
337
  >
303
338
  {#each members as m (m.id)}
304
- {@const on = held(m.id)}
339
+ {@const on = shownHeld(m.id)}
305
340
  <div
306
341
  class={['qm-member qm-wash', { held: on, open: on && hasColumns }]}
307
342
  data-qm-prop={m.id}
@@ -323,6 +358,7 @@
323
358
  />
324
359
  <Icon name="check" class="qm-tick-mark" />
325
360
  </span>
361
+ <ReviewRows entries={reviewed.below.get(m.id)?.filter((e) => !e.steps.length)} />
326
362
  <label class="qm-member-title" id={titleId(m.id)} for={tickId(m.id)}>{m.title}</label>
327
363
  </div>
328
364
  {@render columns(m.id, m.title, on)}
@@ -373,6 +409,7 @@
373
409
  />
374
410
  {/if}
375
411
  <DiagnosticList diagnostics={foot} />
412
+ <ReviewRows entries={reviewFoot} />
376
413
  </div>
377
414
 
378
415
  <!-- A held item's columns, one rung in, the way a variant's cells unfold under the
@@ -383,7 +420,7 @@
383
420
  {#if on && hasColumns}
384
421
  <ObjectField
385
422
  bind:this={colEls[id]}
386
- value={matrixColumns(own(map, id))}
423
+ value={shownColumns(id)}
387
424
  properties={schema.properties}
388
425
  label={`${label ?? ''} ${title}`.trim()}
389
426
  idBase={memberBase(id)}
@@ -391,6 +428,7 @@
391
428
  contentAt={(path) => readAt([id, ...path])}
392
429
  onCommit={(cols) => commitColumns(id, cols)}
393
430
  diagnostics={deep?.filter((d) => d.steps[0] !== MATRIX_TITLE)}
431
+ review={cellReview(id)}
394
432
  />
395
433
  <DiagnosticList
396
434
  diagnostics={deep?.filter((d) => d.steps[0] === MATRIX_TITLE).map((d) => d.diagnostic)}
@@ -1,6 +1,7 @@
1
1
  import type { Content, PathStep, QuillFieldSchema } from '@quillmark/wasm';
2
2
  import { type DeepDiagnostic } from './diagnostics.js';
3
3
  import type { LandingBox } from './leaves.js';
4
+ import { type DeepReview } from './review.js';
4
5
  interface Props {
5
6
  /** The stored sparse map, or undefined while the field is unset. */
6
7
  value: Record<string, unknown> | undefined;
@@ -25,6 +26,10 @@ interface Props {
25
26
  /** The diagnostics routed into this field, each with its steps still to walk: one
26
27
  * naming a drawn item draws under it, any other at the field's foot. */
27
28
  diagnostics?: readonly DeepDiagnostic[];
29
+ /** The review items naming a member or a cell inside one, each with its steps still to
30
+ * walk: a member's tick shows the state it would come to, its cells take their own,
31
+ * and an item no drawn member holds stands at the field's foot. */
32
+ review?: readonly DeepReview[];
28
33
  }
29
34
  declare const MatrixField: import("svelte").Component<Props, {
30
35
  focus: () => void;
@@ -29,9 +29,16 @@
29
29
  string to `onCommit`: the boundary's `writer.set` coercion is the judge (throws a
30
30
  `QuillmarkError` the parent turns into a field diagnostic, INVARIANTS §Diagnostics). `Number()` alone is no gate: it reads `0x1F` and `Infinity` as
31
31
  numbers, and `1.000` as a whole one.
32
+
33
+ A proposed value is drawn over the input, the text it holds struck where it stands and the
34
+ proposed one tinted beside it, as a one-line text leaf draws its own. The input holds its own
35
+ text throughout, so the caret moves through the struck text and an edit writes what the field
36
+ holds; once an entry is pending the input shows it, and the drawing keeps its place unseen, so
37
+ the answer card standing on it stays.
32
38
  -->
33
39
  <script lang="ts">
34
40
  import './controls.css';
41
+ import { review } from './review.svelte.js';
35
42
 
36
43
  interface Props {
37
44
  value: number | undefined;
@@ -54,13 +61,45 @@
54
61
  /** Enter settled the entry as a number: a list's row moves on from it. Enter
55
62
  * claimed here commits at once rather than at the browser's own `change`. */
56
63
  onEnter?: () => void;
64
+ /** A proposed value, drawn over the input at rest. */
65
+ proposed?: { id: string; after: string };
66
+ }
67
+ let {
68
+ value,
69
+ integer,
70
+ fallback,
71
+ placeholder,
72
+ label,
73
+ id,
74
+ describedBy,
75
+ onCommit,
76
+ onEnter,
77
+ proposed
78
+ }: Props = $props();
79
+
80
+ const reviewing = review();
81
+
82
+ /** The face stands over the input's own box, wherever the input stands in its parent. */
83
+ function over(face: HTMLElement) {
84
+ const input = face.previousElementSibling as HTMLElement | null;
85
+ if (!input) return;
86
+ const place = () => {
87
+ face.style.insetBlockStart = `${input.offsetTop}px`;
88
+ face.style.insetInlineStart = `${input.offsetLeft}px`;
89
+ face.style.width = `${input.offsetWidth}px`;
90
+ face.style.height = `${input.offsetHeight}px`;
91
+ };
92
+ place();
93
+ if (typeof ResizeObserver === 'undefined') return;
94
+ const watch = new ResizeObserver(place);
95
+ watch.observe(input);
96
+ return () => watch.disconnect();
57
97
  }
58
- let { value, integer, fallback, placeholder, label, id, describedBy, onCommit, onEnter }: Props =
59
- $props();
60
98
 
61
99
  const resting = $derived(value != null ? String(value) : (fallback ?? ''));
62
100
  let local = $derived(resting);
63
101
  const defaulted = $derived(value == null && !!fallback && local === fallback);
102
+ const drawn = $derived(proposed && proposed.after !== resting ? proposed : undefined);
64
103
 
65
104
  const partial = $derived(
66
105
  integer ? /^\s*[+-]?\d*\s*$/ : /^\s*[+-]?\d*\.?\d*(?:[eE][+-]?\d*)?\s*$/
@@ -145,6 +184,9 @@
145
184
  {id}
146
185
  {placeholder}
147
186
  data-default={defaulted ? '' : undefined}
187
+ data-proposed-over={drawn && local === resting ? '' : undefined}
188
+ onpointerenter={() => drawn && reviewing.point(drawn.id, 'pointer')}
189
+ onpointerleave={() => drawn && reviewing.point(undefined, 'pointer')}
148
190
  aria-label={id ? undefined : label}
149
191
  aria-describedby={describedBy}
150
192
  onbeforeinput={filter}
@@ -159,10 +201,77 @@
159
201
  if (el.value !== settled) commit(el);
160
202
  }}
161
203
  />
204
+ {#if drawn}
205
+ {@const lit = reviewing.lit === drawn.id}
206
+ <span
207
+ class={['qm-number-review', { pending: local !== resting }]}
208
+ aria-hidden="true"
209
+ {@attach over}
210
+ >
211
+ {#if resting}<del class={['qm-review-del', { 'qm-review-lit': lit }]}>{resting}</del>{/if}<ins
212
+ class={['qm-review-ins', { 'qm-review-lit': lit }]}
213
+ data-qm-review={drawn.id}>{drawn.after}</ins
214
+ >
215
+ </span>
216
+ {/if}
162
217
 
163
218
  <style>
164
219
  /* Tabular figures, so numbers stacked in a column line up digit for digit. */
165
- .qm-input {
220
+ .qm-input,
221
+ .qm-number-review {
166
222
  font-variant-numeric: tabular-nums;
167
223
  }
224
+ :global(:has(> .qm-number-review)) {
225
+ position: relative;
226
+ }
227
+ .qm-input[data-proposed-over] {
228
+ color: transparent;
229
+ caret-color: var(--_qm-ink);
230
+ }
231
+ .qm-number-review.pending {
232
+ visibility: hidden;
233
+ }
234
+ .qm-number-review {
235
+ position: absolute;
236
+ display: flex;
237
+ align-items: center;
238
+ box-sizing: border-box;
239
+ padding: var(--_qm-inset-control);
240
+ overflow: hidden;
241
+ font-size: var(--_qm-text-body);
242
+ line-height: var(--_qm-leading-body);
243
+ white-space: nowrap;
244
+ pointer-events: none;
245
+ }
246
+ .qm-review-del {
247
+ color: var(--_qm-ink-label);
248
+ text-decoration: line-through;
249
+ text-decoration-color: var(--_qm-review-line);
250
+ }
251
+ .qm-review-ins {
252
+ color: var(--_qm-ink);
253
+ text-decoration: underline;
254
+ text-decoration-color: var(--_qm-review-line);
255
+ text-decoration-thickness: var(--_qm-border-width);
256
+ text-underline-offset: 0.2em;
257
+ background: var(--_qm-review-tint);
258
+ box-shadow:
259
+ calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-tint),
260
+ var(--_qm-space-half) 0 0 var(--_qm-review-tint);
261
+ border-radius: var(--_qm-radius-inner);
262
+ }
263
+ .qm-review-ins.qm-review-lit {
264
+ background: var(--_qm-review-lit);
265
+ box-shadow:
266
+ calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-lit),
267
+ var(--_qm-space-half) 0 0 var(--_qm-review-lit);
268
+ }
269
+ .qm-review-del + .qm-review-ins {
270
+ margin-inline-start: calc(var(--_qm-space) + var(--_qm-space-half));
271
+ }
272
+ @media (forced-colors: active) {
273
+ .qm-review-ins {
274
+ text-decoration-color: currentColor;
275
+ }
276
+ }
168
277
  </style>
@@ -19,6 +19,11 @@ interface Props {
19
19
  /** Enter settled the entry as a number: a list's row moves on from it. Enter
20
20
  * claimed here commits at once rather than at the browser's own `change`. */
21
21
  onEnter?: () => void;
22
+ /** A proposed value, drawn over the input at rest. */
23
+ proposed?: {
24
+ id: string;
25
+ after: string;
26
+ };
22
27
  }
23
28
  declare const NumberField: import("svelte").Component<Props, {}, "">;
24
29
  type NumberField = ReturnType<typeof NumberField>;