@quillmark/svelte 0.35.1 → 0.37.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 (82) hide show
  1. package/README.md +30 -18
  2. package/THEMING.md +1 -1
  3. package/dist/core/address.d.ts +5 -0
  4. package/dist/core/address.js +14 -0
  5. package/dist/core/codec/decode.d.ts +4 -2
  6. package/dist/core/codec/decode.js +5 -2
  7. package/dist/core/codec/field.d.ts +42 -16
  8. package/dist/core/codec/field.js +97 -28
  9. package/dist/core/codec/index.d.ts +8 -5
  10. package/dist/core/codec/index.js +4 -5
  11. package/dist/core/codec/prose.css +25 -81
  12. package/dist/core/codec/review.d.ts +31 -26
  13. package/dist/core/codec/review.js +93 -169
  14. package/dist/core/codec/schema.d.ts +12 -2
  15. package/dist/core/codec/schema.js +27 -5
  16. package/dist/core/codec/shortcuts.d.ts +5 -4
  17. package/dist/core/codec/shortcuts.js +9 -8
  18. package/dist/core/codec/table-view.js +15 -3
  19. package/dist/core/codec/value-diff.d.ts +21 -0
  20. package/dist/core/codec/value-diff.js +83 -0
  21. package/dist/core/codec/value-plan.d.ts +29 -0
  22. package/dist/core/codec/value-plan.js +157 -0
  23. package/dist/core/theme.css +46 -15
  24. package/dist/core/tooltip.css +49 -0
  25. package/dist/core/tooltip.d.ts +6 -0
  26. package/dist/core/tooltip.js +176 -0
  27. package/dist/preview/Preview.svelte +22 -1
  28. package/dist/preview/controller.js +38 -0
  29. package/dist/preview/strings.d.ts +2 -0
  30. package/dist/preview/strings.js +1 -0
  31. package/dist/visual/ArrayField.svelte +374 -96
  32. package/dist/visual/Card.svelte +33 -12
  33. package/dist/visual/Card.svelte.d.ts +3 -0
  34. package/dist/visual/CardControls.svelte +3 -3
  35. package/dist/visual/DateField.svelte +47 -5
  36. package/dist/visual/DiagnosticList.svelte +3 -2
  37. package/dist/visual/EnumField.svelte +20 -5
  38. package/dist/visual/EnumField.svelte.d.ts +5 -0
  39. package/dist/visual/Field.svelte +56 -47
  40. package/dist/visual/FieldHint.svelte +20 -8
  41. package/dist/visual/FormatPopover.svelte +54 -20
  42. package/dist/visual/MatrixField.svelte +48 -6
  43. package/dist/visual/MatrixField.svelte.d.ts +5 -0
  44. package/dist/visual/NumberField.svelte +131 -6
  45. package/dist/visual/NumberField.svelte.d.ts +5 -0
  46. package/dist/visual/ObjectField.svelte +60 -18
  47. package/dist/visual/ProseField.svelte +21 -5
  48. package/dist/visual/ProseField.svelte.d.ts +5 -1
  49. package/dist/visual/ProseValue.svelte +49 -8
  50. package/dist/visual/ProseValue.svelte.d.ts +7 -1
  51. package/dist/visual/ReviewCard.svelte +400 -0
  52. package/dist/visual/ReviewCard.svelte.d.ts +20 -0
  53. package/dist/visual/ReviewProposal.svelte +98 -138
  54. package/dist/visual/ReviewProposal.svelte.d.ts +3 -6
  55. package/dist/visual/ReviewRows.svelte +6 -25
  56. package/dist/visual/ReviewRows.svelte.d.ts +1 -3
  57. package/dist/visual/SlashMenu.svelte +1 -0
  58. package/dist/visual/TipsCard.svelte +1 -1
  59. package/dist/visual/VariantField.svelte +45 -4
  60. package/dist/visual/VariantField.svelte.d.ts +5 -0
  61. package/dist/visual/VisualEditor.svelte +24 -9
  62. package/dist/visual/VisualEditor.svelte.d.ts +8 -1
  63. package/dist/visual/VisualEditorInner.svelte +917 -280
  64. package/dist/visual/VisualEditorInner.svelte.d.ts +8 -1
  65. package/dist/visual/controls.css +2 -2
  66. package/dist/visual/index.d.ts +2 -2
  67. package/dist/visual/proposals.d.ts +25 -24
  68. package/dist/visual/proposals.js +92 -32
  69. package/dist/visual/props.d.ts +18 -18
  70. package/dist/visual/review-order.d.ts +51 -0
  71. package/dist/visual/review-order.js +87 -0
  72. package/dist/visual/review.d.ts +94 -3
  73. package/dist/visual/review.js +37 -2
  74. package/dist/visual/review.svelte.d.ts +77 -20
  75. package/dist/visual/review.svelte.js +306 -49
  76. package/dist/visual/strings.d.ts +59 -25
  77. package/dist/visual/strings.js +90 -29
  78. package/dist/visual/structure.d.ts +17 -3
  79. package/dist/visual/structure.js +71 -5
  80. package/dist/visual/undo.svelte.d.ts +3 -1
  81. package/dist/visual/undo.svelte.js +7 -3
  82. package/package.json +2 -2
@@ -1,14 +1,11 @@
1
1
  import { type FieldProposal } from './review.js';
2
2
  interface Props {
3
3
  item: FieldProposal;
4
- /** The value the control holds. */
5
- value: unknown;
6
- /** Take the focus back to the control: an answer given from the row unmounts it. */
7
- refocus?: () => void;
8
- /** Where the value is, for one drawn under a control that is not its own. */
9
- label?: string;
10
4
  /** It takes a list's member out, so nothing comes in its place. */
11
5
  removes?: boolean;
6
+ /** The value the control would show without the proposal, where the caller knows it: a
7
+ * default an unset field prints. Else the value the place holds. */
8
+ current?: unknown;
12
9
  }
13
10
  declare const ReviewProposal: import("svelte").Component<Props, {}, "">;
14
11
  type ReviewProposal = ReturnType<typeof ReviewProposal>;
@@ -1,43 +1,24 @@
1
1
  <!--
2
- The review items a container hands to one of its places, drawn under that place's control:
3
- each a proposal, as the value that would go and the value that would come with its two
4
- answers. An item naming a place deeper than the control under which it is drawn, which no
5
- control of its own draws, leads with where it is: the cells and members between, by name and
6
- number.
2
+ The review items a container hands to one of its places, each marked on that place's control:
3
+ the review tint where the control shows the value it would hold, struck where a member would be
4
+ taken out. An item naming a place deeper than the control it marks, which no control of its own
5
+ draws, tints the nearest control that holds it.
7
6
  -->
8
7
  <script lang="ts">
9
- import type { PathStep } from '@quillmark/wasm';
10
8
  import ReviewProposal from './ReviewProposal.svelte';
11
- import { valueIn, type DeepReview } from './review.js';
12
- import { wording } from './strings.js';
13
- import { humanize } from './structure.js';
9
+ import type { DeepReview } from './review.js';
14
10
 
15
11
  interface Props {
16
12
  entries: readonly DeepReview[] | undefined;
17
- /** The value the place holds, which the entries' steps walk from. */
18
- value: unknown;
19
13
  /** The place is a list's member, which a proposal of nothing takes out. */
20
14
  member?: boolean;
21
15
  }
22
- let { entries, value, member = false }: Props = $props();
23
-
24
- const t = wording();
25
-
26
- const where = (steps: readonly PathStep[]): string | undefined =>
27
- steps.length
28
- ? steps
29
- .map((step) =>
30
- typeof step === 'number' ? t.strings.elementItem(step + 1) : humanize(step)
31
- )
32
- .join(' · ')
33
- : undefined;
16
+ let { entries, member = false }: Props = $props();
34
17
  </script>
35
18
 
36
19
  {#each entries ?? [] as { steps, item } (item.id)}
37
20
  <ReviewProposal
38
21
  {item}
39
- value={valueIn(value, steps)}
40
- label={where(steps)}
41
22
  removes={item.after === undefined && (steps.length ? typeof steps.at(-1) === 'number' : member)}
42
23
  />
43
24
  {/each}
@@ -1,8 +1,6 @@
1
- import { type DeepReview } from './review.js';
1
+ import type { DeepReview } from './review.js';
2
2
  interface Props {
3
3
  entries: readonly DeepReview[] | undefined;
4
- /** The value the place holds, which the entries' steps walk from. */
5
- value: unknown;
6
4
  /** The place is a list's member, which a proposal of nothing takes out. */
7
5
  member?: boolean;
8
6
  }
@@ -85,6 +85,7 @@
85
85
  <Popover.Content
86
86
  customAnchor={menu?.anchor ?? null}
87
87
  collisionBoundary={portalTarget ?? []}
88
+ strategy="absolute"
88
89
  side="bottom"
89
90
  align="start"
90
91
  trapFocus={false}
@@ -79,7 +79,7 @@
79
79
  {/if}
80
80
  <button type="button" class="qm-icon-btn qm-tips-action qm-focus-ring" onclick={advance}>
81
81
  {#if isLast}
82
- {t.strings.tipsDismiss} <Icon name="trash-2" />
82
+ {t.strings.tipsDismiss} <Icon name="x" />
83
83
  {:else}
84
84
  {t.strings.tipsNext} <Icon name="arrow-right" />
85
85
  {/if}
@@ -18,7 +18,10 @@
18
18
  import EnumField from './EnumField.svelte';
19
19
  import ObjectField from './ObjectField.svelte';
20
20
  import DiagnosticList from './DiagnosticList.svelte';
21
+ import ReviewRows from './ReviewRows.svelte';
21
22
  import type { DeepDiagnostic } from './diagnostics.js';
23
+ import { shownValue, splitReview, type DeepReview } from './review.js';
24
+ import { review as reviewState } from './review.svelte.js';
22
25
  import type { LandingBox } from './leaves.js';
23
26
  import {
24
27
  VARIANT_DISCRIMINANT,
@@ -51,6 +54,10 @@
51
54
  * naming a live cell draws under it; the rest — the discriminant's, a dormant
52
55
  * world's — draw at the field's foot. */
53
56
  diagnostics?: readonly DeepDiagnostic[];
57
+ /** The review items naming a place inside this field, each with its steps still to
58
+ * walk: the discriminant's drawn on its select, a live cell's in that cell, and the
59
+ * rest at the field's foot. */
60
+ review?: readonly DeepReview[];
54
61
  }
55
62
  let {
56
63
  value,
@@ -64,12 +71,41 @@
64
71
  onCommit,
65
72
  optionAllowed,
66
73
  enumDisallowed,
67
- diagnostics
74
+ diagnostics,
75
+ review
68
76
  }: Props = $props();
69
77
 
70
- const member = $derived(variantMember(value, ghostMember));
78
+ const reviewing = reviewState();
79
+ const reviewed = $derived(splitReview(review));
80
+ /** The discriminant's own proposal: the select shows the member it would pick, and the
81
+ * cells of that member's world. */
82
+ const pick = $derived(reviewed.below.get(VARIANT_DISCRIMINANT)?.find((e) => !e.steps.length));
83
+ const discriminant = $derived(
84
+ shownValue(pick?.item, value?.[VARIANT_DISCRIMINANT]) as string | undefined
85
+ );
86
+ const member = $derived(
87
+ variantMember(pick ? { ...value, [VARIANT_DISCRIMINANT]: discriminant } : value, ghostMember)
88
+ );
71
89
  const cells = $derived(variantCells(schema, member));
72
- const discriminant = $derived(value?.[VARIANT_DISCRIMINANT] as string | undefined);
90
+ /** The cells' items, by the live world's keys; the rest stand at the foot. */
91
+ const cellReview = $derived(
92
+ [...reviewed.below]
93
+ .filter(([step]) => live(step))
94
+ .flatMap(([step, list]) => list.map((e) => ({ steps: [step, ...e.steps], item: e.item })))
95
+ );
96
+ const reviewFoot = $derived([
97
+ ...reviewed.here,
98
+ ...[...reviewed.below]
99
+ .filter(([step]) => !live(step) && step !== VARIANT_DISCRIMINANT)
100
+ .flatMap(([step, list]) => list.map((e) => ({ steps: [step, ...e.steps], item: e.item })))
101
+ ]);
102
+ /** A pick under the discriminant's proposal answers it: its member accepts, any other is
103
+ * written and dismisses it. */
104
+ function commitPick(v: string | undefined): void {
105
+ const next = commitDiscriminant(value, v);
106
+ if (pick && reviewing.answerWith(pick.item.id, next?.[VARIANT_DISCRIMINANT])) return;
107
+ onCommit(next);
108
+ }
73
109
 
74
110
  type Subform = {
75
111
  focus: () => void;
@@ -118,11 +154,14 @@
118
154
  fallback={ghostMember}
119
155
  blankTitle={schema.ui?.blank_title}
120
156
  {id}
157
+ {labelledBy}
121
158
  {describedBy}
122
- onCommit={(v) => onCommit(commitDiscriminant(value, v))}
159
+ onCommit={commitPick}
160
+ proposing={!!pick}
123
161
  {optionAllowed}
124
162
  {enumDisallowed}
125
163
  />
164
+ <ReviewRows entries={reviewed.below.get(VARIANT_DISCRIMINANT)} />
126
165
  <!-- Keyed on the member so a flip remounts the cells rather than re-targeting
127
166
  them: two worlds' cells are different fields that happen to occupy one place,
128
167
  and a control carrying local state (an unreconciled pick, a caret) across the
@@ -140,12 +179,14 @@
140
179
  {contentAt}
141
180
  onCommit={(obj) => onCommit(obj)}
142
181
  diagnostics={inside}
182
+ review={cellReview}
143
183
  />
144
184
  {/key}
145
185
  {/if}
146
186
  <!-- The field's own foot, drawn whether or not a world is: what the live world
147
187
  cannot hold belongs under the field rather than inside the box its cells sit in. -->
148
188
  <DiagnosticList diagnostics={foot} />
189
+ <ReviewRows entries={reviewFoot} />
149
190
  </div>
150
191
 
151
192
  <style>
@@ -1,5 +1,6 @@
1
1
  import type { Content, PathStep, QuillFieldSchema } from '@quillmark/wasm';
2
2
  import type { DeepDiagnostic } from './diagnostics.js';
3
+ import { type DeepReview } from './review.js';
3
4
  import type { LandingBox } from './leaves.js';
4
5
  interface Props {
5
6
  /** The stored container, or undefined while the field is unset. */
@@ -25,6 +26,10 @@ interface Props {
25
26
  * naming a live cell draws under it; the rest — the discriminant's, a dormant
26
27
  * world's — draw at the field's foot. */
27
28
  diagnostics?: readonly DeepDiagnostic[];
29
+ /** The review items naming a place inside this field, each with its steps still to
30
+ * walk: the discriminant's drawn on its select, a live cell's in that cell, and the
31
+ * rest at the field's foot. */
32
+ review?: readonly DeepReview[];
28
33
  }
29
34
  declare const VariantField: import("svelte").Component<Props, {
30
35
  focus: () => void;
@@ -28,7 +28,9 @@
28
28
  import type { DocPath, Landing } from '../core/address.js';
29
29
  import type { Delta } from '../core/codec/positions.js';
30
30
  import type { CardId, CardOp } from './signals.js';
31
+ import type { Document } from '@quillmark/wasm';
31
32
  import type { VisualEditorProps } from './props.js';
33
+ import { NO_PROJECTION, type ReviewProjection } from './review.js';
32
34
  import VisualEditorInner from './VisualEditorInner.svelte';
33
35
 
34
36
  let props: VisualEditorProps = $props();
@@ -75,6 +77,10 @@
75
77
  export async function focusField(field: DocPath): Promise<void> {
76
78
  await inner?.focusField(field);
77
79
  }
80
+ /** Reveal, scroll to and wash the field at `field` without focusing it. */
81
+ export async function revealField(field: DocPath): Promise<void> {
82
+ await inner?.revealField(field);
83
+ }
78
84
  /** Wash the field at `field` where it is on show, without focusing or revealing it. */
79
85
  export function washField(field: DocPath): void {
80
86
  inner?.washField(field);
@@ -106,25 +112,34 @@
106
112
  export function applyCardOps(ops: readonly CardOp[]): void {
107
113
  inner?.applyCardOps(ops);
108
114
  }
109
- /** Bring the review item `id` to the reader: its panel opened, scrolled to the middle of
110
- * the view, lit. The focus stays put unless `focus` sends the caret into
111
- * the item, where its chords answer. False for an item not drawn. */
115
+ /** Bring the review item `id` to the reader as the current change: its panel opened,
116
+ * scrolled to the middle of the view. The focus stays put unless `focus` sends the caret
117
+ * into the item. False for an item not drawn. */
112
118
  export async function revealReview(id: string, opts?: { focus?: boolean }): Promise<boolean> {
113
119
  return (await inner?.revealReview(id, opts)) ?? false;
114
120
  }
115
- /** Answer items as their buttons would, in document order (`'all'`: every item drawn),
116
- * moving neither the focus nor the caret and raising no toast. Returns the ids answered. */
121
+ /** Answer items as the answer card would, in document order (`'all'`: every item drawn;
122
+ * `{ group }`: every item drawn in that group, accepting none outdated), moving neither the
123
+ * focus nor the caret; where the current change is among them, the next open one is current.
124
+ * Returns the ids answered. */
117
125
  export function answerReview(
118
- ids: readonly string[] | 'all',
126
+ ids: readonly string[] | 'all' | { group: string },
119
127
  action: 'accept' | 'dismiss'
120
128
  ): string[] {
121
129
  return inner?.answerReview(ids, action) ?? [];
122
130
  }
123
- /** Bring the next or previous open item to the reader, round from either end, the caret
124
- * or the focus in it unless `focus` is false. Resolves its id, `undefined` for none. */
131
+ /** Write every open item the editor draws into `target`, a copy of `doc` the host made, as
132
+ * accepting them all would, without writing to `doc` or raising a hook. Returns the way
133
+ * between places in `doc` and places in `target`, good until either changes. */
134
+ export function projectReview(target: Document): ReviewProjection {
135
+ return inner?.projectReview(target) ?? NO_PROJECTION;
136
+ }
137
+ /** Make the next or previous open item current, round from either end, the caret or the
138
+ * focus in it unless `focus` is false, and among the items of `group` alone where it is
139
+ * given. Resolves its id, `undefined` for none. */
125
140
  export async function stepReview(
126
141
  dir: 1 | -1,
127
- opts?: { focus?: boolean }
142
+ opts?: { focus?: boolean; group?: string }
128
143
  ): Promise<string | undefined> {
129
144
  return (await inner?.stepReview(dir, opts)) ?? undefined;
130
145
  }
@@ -1,10 +1,13 @@
1
1
  import type { DocPath, Landing } from '../core/address.js';
2
2
  import type { Delta } from '../core/codec/positions.js';
3
3
  import type { CardId, CardOp } from './signals.js';
4
+ import type { Document } from '@quillmark/wasm';
4
5
  import type { VisualEditorProps } from './props.js';
6
+ import { type ReviewProjection } from './review.js';
5
7
  declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
6
8
  setCaret: (at: Landing) => Promise<void>;
7
9
  focusField: (field: DocPath) => Promise<void>;
10
+ revealField: (field: DocPath) => Promise<void>;
8
11
  washField: (field: DocPath) => void;
9
12
  insertCard: (kind: string, at?: number) => CardId | undefined;
10
13
  removeCard: (cardId: CardId) => void;
@@ -16,9 +19,13 @@ declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
16
19
  revealReview: (id: string, opts?: {
17
20
  focus?: boolean;
18
21
  }) => Promise<boolean>;
19
- answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
22
+ answerReview: (ids: readonly string[] | "all" | {
23
+ group: string;
24
+ }, action: "accept" | "dismiss") => string[];
25
+ projectReview: (target: Document) => ReviewProjection;
20
26
  stepReview: (dir: 1 | -1, opts?: {
21
27
  focus?: boolean;
28
+ group?: string;
22
29
  }) => Promise<string | undefined>;
23
30
  }, "">;
24
31
  type VisualEditor = ReturnType<typeof VisualEditor>;