@quillmark/svelte 0.36.0 → 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 (66) hide show
  1. package/README.md +18 -14
  2. package/THEMING.md +1 -1
  3. package/dist/core/codec/decode.d.ts +4 -2
  4. package/dist/core/codec/decode.js +5 -2
  5. package/dist/core/codec/field.d.ts +13 -10
  6. package/dist/core/codec/field.js +30 -24
  7. package/dist/core/codec/index.d.ts +3 -3
  8. package/dist/core/codec/index.js +2 -2
  9. package/dist/core/codec/prose.css +14 -4
  10. package/dist/core/codec/review.d.ts +4 -5
  11. package/dist/core/codec/review.js +6 -21
  12. package/dist/core/codec/schema.d.ts +12 -2
  13. package/dist/core/codec/schema.js +27 -5
  14. package/dist/core/codec/shortcuts.d.ts +3 -2
  15. package/dist/core/codec/shortcuts.js +3 -2
  16. package/dist/core/codec/table-view.js +15 -3
  17. package/dist/core/theme.css +39 -13
  18. package/dist/core/tooltip.css +49 -0
  19. package/dist/core/tooltip.d.ts +6 -0
  20. package/dist/core/tooltip.js +176 -0
  21. package/dist/preview/Preview.svelte +22 -1
  22. package/dist/preview/controller.js +38 -0
  23. package/dist/preview/strings.d.ts +2 -0
  24. package/dist/preview/strings.js +1 -0
  25. package/dist/visual/ArrayField.svelte +190 -86
  26. package/dist/visual/Card.svelte +21 -11
  27. package/dist/visual/CardControls.svelte +3 -3
  28. package/dist/visual/DateField.svelte +47 -5
  29. package/dist/visual/DiagnosticList.svelte +3 -2
  30. package/dist/visual/EnumField.svelte +6 -1
  31. package/dist/visual/EnumField.svelte.d.ts +2 -0
  32. package/dist/visual/Field.svelte +3 -3
  33. package/dist/visual/FieldHint.svelte +19 -8
  34. package/dist/visual/FormatPopover.svelte +53 -20
  35. package/dist/visual/MatrixField.svelte +7 -3
  36. package/dist/visual/NumberField.svelte +21 -5
  37. package/dist/visual/ObjectField.svelte +6 -2
  38. package/dist/visual/ProseField.svelte +6 -3
  39. package/dist/visual/ProseField.svelte.d.ts +2 -1
  40. package/dist/visual/ProseValue.svelte +11 -6
  41. package/dist/visual/ProseValue.svelte.d.ts +4 -1
  42. package/dist/visual/ReviewCard.svelte +85 -32
  43. package/dist/visual/ReviewCard.svelte.d.ts +2 -1
  44. package/dist/visual/ReviewProposal.svelte +0 -6
  45. package/dist/visual/TipsCard.svelte +1 -1
  46. package/dist/visual/VariantField.svelte +1 -0
  47. package/dist/visual/VisualEditor.svelte +12 -6
  48. package/dist/visual/VisualEditor.svelte.d.ts +5 -1
  49. package/dist/visual/VisualEditorInner.svelte +187 -275
  50. package/dist/visual/VisualEditorInner.svelte.d.ts +5 -1
  51. package/dist/visual/controls.css +2 -2
  52. package/dist/visual/index.d.ts +2 -2
  53. package/dist/visual/proposals.d.ts +14 -4
  54. package/dist/visual/proposals.js +28 -5
  55. package/dist/visual/props.d.ts +1 -1
  56. package/dist/visual/review-order.d.ts +51 -0
  57. package/dist/visual/review-order.js +87 -0
  58. package/dist/visual/review.d.ts +27 -1
  59. package/dist/visual/review.js +1 -1
  60. package/dist/visual/review.svelte.d.ts +34 -17
  61. package/dist/visual/review.svelte.js +187 -44
  62. package/dist/visual/strings.d.ts +36 -19
  63. package/dist/visual/strings.js +80 -24
  64. package/dist/visual/structure.d.ts +17 -3
  65. package/dist/visual/structure.js +71 -5
  66. package/package.json +2 -2
@@ -28,8 +28,9 @@
28
28
  it, so the echo replaces nothing and the caret and the history stay.
29
29
 
30
30
  The schema is the declared type's where the parent has room for it: a subform cell
31
- declaring `multiline: true` takes the full row ({@link ObjectField}), a `richtext` one
32
- on the block schema and a `text` one on the plain schema, paragraphs and hard breaks.
31
+ declaring a `shape` takes the full row ({@link ObjectField}), a `richtext` of blocks
32
+ on the block schema, a `richtext` of lines on the lines schema and a `text` one on the
33
+ plain schema, paragraphs and hard breaks.
33
34
  An array element is one textblock whatever it declares, since Enter there is the
34
35
  repeater's, and a paste or a drop of several lines into one is a row per line, as Enter
35
36
  would open them, up to the array's `max:`, the last row taking what is left joined and
@@ -95,8 +96,11 @@
95
96
  * as the field of that type mounts. */
96
97
  plaintext?: boolean;
97
98
  /** A multi-block schema, for a cell the parent draws at full width: the block
98
- * schema, or the plain one with `plaintext`. Absent, the leaf is one textblock. */
99
+ * schema, the plain one with `plaintext`, or the lines one with `paragraphs`.
100
+ * Absent, the leaf is one textblock. */
99
101
  block?: boolean;
102
+ /** A `richtext` cell of `shape: lines`: formatted paragraphs and hard breaks. */
103
+ paragraphs?: boolean;
100
104
  /** Accessible name for the editable region, where nothing else names it: an
101
105
  * array has no per-element label. A cell with a label element takes
102
106
  * `labelledBy`. */
@@ -141,6 +145,7 @@
141
145
  fallback,
142
146
  plaintext = false,
143
147
  block = false,
148
+ paragraphs = false,
144
149
  label,
145
150
  labelledBy,
146
151
  describedBy,
@@ -243,7 +248,7 @@
243
248
  function mountView(mount: HTMLDivElement): () => void {
244
249
  return untrack(() => {
245
250
  const inline = !block;
246
- const leaf = { inline, plaintext, islands: false };
251
+ const leaf = { inline, plaintext, paragraphs, islands: false };
247
252
  // Read per attribute pass, not captured: an element's name carries its index,
248
253
  // which a remove above it moves.
249
254
  const names = () => drawn;
@@ -273,13 +278,13 @@
273
278
  // Which of `aria-label` / `aria-labelledby` wins is the codec's one answer
274
279
  // (`proseAttributes`), so a cell carrying a label element and a row carrying
275
280
  // none cannot name their regions by different rules.
276
- const plainNamed = () => proseAttributes(names()) ?? {};
281
+ const plainNamed = () => proseAttributes(names(), !inline);
277
282
  const heldNamed = () => heldAttributes(names(), heldId);
278
283
  const build = (rt: Content): EditorState => {
279
284
  // The same keymap and plugin stack a `createField` leaf mounts (shared
280
285
  // `proseLeafPlugins`), minus the anchor-position plugin: anchors are dropped on
281
286
  // the parent's value write, per the header.
282
- const schema = held ? blockSchema : leafSchema({ plaintext, inline });
287
+ const schema = held ? blockSchema : leafSchema({ plaintext, inline, paragraphs });
283
288
  return EditorState.create({
284
289
  doc: decode(rt, schema),
285
290
  plugins: held
@@ -18,8 +18,11 @@ interface Props {
18
18
  * as the field of that type mounts. */
19
19
  plaintext?: boolean;
20
20
  /** A multi-block schema, for a cell the parent draws at full width: the block
21
- * schema, or the plain one with `plaintext`. Absent, the leaf is one textblock. */
21
+ * schema, the plain one with `plaintext`, or the lines one with `paragraphs`.
22
+ * Absent, the leaf is one textblock. */
22
23
  block?: boolean;
24
+ /** A `richtext` cell of `shape: lines`: formatted paragraphs and hard breaks. */
25
+ paragraphs?: boolean;
23
26
  /** Accessible name for the editable region, where nothing else names it: an
24
27
  * array has no per-element label. A cell with a label element takes
25
28
  * `labelledBy`. */
@@ -1,15 +1,19 @@
1
1
  <!--
2
2
  The answer card: one floating surface on the current change of a review, and the one place a
3
- change is answered by pointer. A quiet Dismiss and a primary Accept, each with its key, and a
4
- note where the reader's own writing meets the change. The change itself is drawn where it
3
+ change is answered by pointer. A quiet Dismiss and a primary Accept, each with its key, a note
4
+ where the reader's own writing meets the change, and above them the line the proposal's writer
5
+ gave for it, cut to one line. The change itself is drawn where it
5
6
  stands, so the card is the same two answers on every change. It carries no position: the count
6
7
  is the host's bar's.
7
8
 
8
- It sits under the change, right-aligned to the text column the change stands in, and flips
9
- above it where there is no room below, keeping clear of the host's chrome at the pane's foot
10
- (`inset`). Over a change taller than the pane it stays pinned at the foot while any of the
11
- change shows. A change out of the pane keeps its card where it would stand beside it, so the
12
- card scrolls out with the text and the pane's edge clips it as it clips the text.
9
+ It sits under the block the change flows in, so it covers no line of its paragraph, or beside
10
+ that block's last line where the line ends short of it, centred on a block of one line such as a
11
+ one-line field's, right-aligned to the text column the
12
+ change stands in, and flips above that block where there is no room below, keeping clear of the
13
+ host's chrome at the pane's foot (`inset`). Over a change taller than the pane it stays pinned
14
+ at the foot while any of the change shows. A change out of the pane keeps its card where it
15
+ would stand beside it, so the card scrolls out with the text and the pane's edge clips it as it
16
+ clips the text.
13
17
  A change is several elements (struck runs, tinted widgets, added blocks, a row
14
18
  under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
15
19
  redraws its decorations as it likes, and a box measured once parts from the text it stood on.
@@ -21,7 +25,8 @@
21
25
  -->
22
26
  <script lang="ts">
23
27
  import { tick } from 'svelte';
24
- import { chord, wording } from './strings.js';
28
+ import { REVIEW_KEYS } from '../core/codec/index.js';
29
+ import { keycap, keyshortcut, wording } from './strings.js';
25
30
  import './controls.css';
26
31
 
27
32
  interface Props {
@@ -35,10 +40,12 @@
35
40
  hidden: boolean;
36
41
  /** The reader's own writing meets the change. */
37
42
  outdated: boolean;
43
+ /** Why, as the proposal's writer says it. */
44
+ note?: string;
38
45
  onAnswer(action: 'accept' | 'dismiss'): void;
39
- onHover(on: boolean): void;
40
46
  }
41
- let { id, root, inset, hidden, outdated, onAnswer, onHover }: Props = $props();
47
+ let { id, root, inset, hidden, outdated, note, onAnswer }: Props = $props();
48
+ const noteId = $props.id();
42
49
 
43
50
  const t = wording();
44
51
 
@@ -87,7 +94,8 @@
87
94
 
88
95
  function place(): void {
89
96
  const els = parts();
90
- const rects = els.map((e) => e.getBoundingClientRect()).filter((r) => r.width || r.height);
97
+ const blocks = els.map(blockOf);
98
+ const rects = blocks.map((b) => b.getBoundingClientRect()).filter((r) => r.width || r.height);
91
99
  if (!el || !rects.length) {
92
100
  placed = false;
93
101
  return;
@@ -106,7 +114,9 @@
106
114
  ) ?? root)!;
107
115
  left = Math.max(view.left + gap, column.getBoundingClientRect().right - w);
108
116
  const at = (root ?? el).getBoundingClientRect();
109
- const below = lower + gap;
117
+ const last = blocks.find((b, i) => b !== els[i] && b.getBoundingClientRect().bottom === lower);
118
+ const tuck = last && lastLine(last, h);
119
+ const below = tuck && tuck.right + gap <= left ? tuck.top : lower + gap;
110
120
  const above = upper - gap - h;
111
121
  const fits = below + h <= floor || above >= ceil;
112
122
  const y =
@@ -125,6 +135,31 @@
125
135
  placed = true;
126
136
  }
127
137
 
138
+ /** The block a run of the change flows in, which the card keeps clear of whole: a card on
139
+ * the run's own line covers the lines of its paragraph after it. */
140
+ function blockOf(at: HTMLElement): HTMLElement {
141
+ for (let up: HTMLElement | null = at; up && up !== root; up = up.parentElement)
142
+ if (!/^(inline|contents)/.test(getComputedStyle(up).display)) return up;
143
+ return at;
144
+ }
145
+
146
+ /** Where a card `h` tall stands beside the last line of a block, and where the line's words
147
+ * end: a card beside a short last line covers nothing of the block, and beside a one-line
148
+ * field's text, centred on it, nothing of the field after it. */
149
+ function lastLine(block: HTMLElement, h: number): { top: number; right: number } | undefined {
150
+ const range = document.createRange();
151
+ range.selectNodeContents(block);
152
+ const lines = [...range.getClientRects()].filter((r) => r.width && r.height);
153
+ if (!lines.length) return undefined;
154
+ const from = Math.max(...lines.map((r) => r.top));
155
+ const on = lines.filter((r) => r.bottom > from);
156
+ const top = Math.min(...on.map((r) => r.top));
157
+ const right = Math.max(...on.map((r) => r.right));
158
+ if (on.length < lines.length) return { top, right };
159
+ const bottom = Math.max(...on.map((r) => r.bottom));
160
+ return { top: (top + bottom - h) / 2, right };
161
+ }
162
+
128
163
  function gapPx(): number {
129
164
  const n = Number.parseFloat(getComputedStyle(el ?? root!).getPropertyValue('--_qm-space'));
130
165
  return Number.isFinite(n) ? n : 0;
@@ -231,31 +266,35 @@
231
266
  style:left="{left}px"
232
267
  role="group"
233
268
  aria-label={t.strings.reviewProposal}
269
+ aria-describedby={note ? noteId : undefined}
234
270
  aria-hidden={!shown}
235
271
  inert={!shown}
236
- onpointerenter={() => onHover(true)}
237
- onpointerleave={() => onHover(false)}
238
272
  onmousedown={(e) => e.preventDefault()}
239
273
  {onkeydown}
240
274
  onfocusout={(e) => {
241
275
  if (!el?.contains(e.relatedTarget as Node | null)) from = undefined;
242
276
  }}
243
277
  >
244
- {#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
245
- <button
246
- type="button"
247
- class="qm-review-card-dismiss qm-focus-ring"
248
- tabindex="-1"
249
- aria-keyshortcuts="Meta+. Control+."
250
- onclick={() => answer('dismiss')}>{t.strings.reviewDismiss}<kbd>{chord('.')}</kbd></button
251
- >
252
- <button
253
- type="button"
254
- class="qm-review-card-accept qm-focus-ring"
255
- tabindex="-1"
256
- aria-keyshortcuts="Meta+Enter Control+Enter"
257
- onclick={() => answer('accept')}>{t.strings.reviewAccept}<kbd>{chord('↵')}</kbd></button
258
- >
278
+ {#if note}<p id={noteId} class="qm-review-card-reason" title={note}>{note}</p>{/if}
279
+ <div class="qm-review-card-answers">
280
+ {#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
281
+ <button
282
+ type="button"
283
+ class="qm-review-card-dismiss qm-focus-ring"
284
+ tabindex="-1"
285
+ aria-keyshortcuts={keyshortcut(REVIEW_KEYS.dismiss)}
286
+ onclick={() => answer('dismiss')}
287
+ >{t.strings.reviewDismiss}<kbd>{keycap(REVIEW_KEYS.dismiss)}</kbd></button
288
+ >
289
+ <button
290
+ type="button"
291
+ class="qm-review-card-accept qm-focus-ring"
292
+ tabindex="-1"
293
+ aria-keyshortcuts={keyshortcut(REVIEW_KEYS.accept)}
294
+ onclick={() => answer('accept')}
295
+ >{t.strings.reviewAccept}<kbd>{keycap(REVIEW_KEYS.accept)}</kbd></button
296
+ >
297
+ </div>
259
298
  </div>
260
299
 
261
300
  <style>
@@ -268,7 +307,7 @@
268
307
  z-index: 2;
269
308
  width: max-content;
270
309
  display: flex;
271
- align-items: center;
310
+ flex-direction: column;
272
311
  gap: var(--_qm-space-half);
273
312
  padding: var(--_qm-space-half);
274
313
  font-family: var(--_qm-font);
@@ -324,14 +363,28 @@
324
363
  }
325
364
  kbd {
326
365
  font: inherit;
327
- opacity: var(--_qm-opacity-rest);
366
+ }
367
+ .qm-review-card-answers {
368
+ display: flex;
369
+ align-items: center;
370
+ justify-content: flex-end;
371
+ gap: var(--_qm-space-half);
372
+ }
373
+ .qm-review-card-reason {
374
+ max-width: min(24rem, calc(100vw - 4 * var(--_qm-space-2)));
375
+ margin: 0;
376
+ padding: var(--_qm-space-half) var(--_qm-space-2) 0;
377
+ overflow: hidden;
378
+ white-space: nowrap;
379
+ text-overflow: ellipsis;
380
+ color: var(--_qm-ink);
328
381
  }
329
382
  .qm-review-card-note {
330
383
  padding-inline: var(--_qm-space-2);
331
384
  color: var(--_qm-ink-label);
332
385
  }
333
386
  /* Under a finger the keys are no help, and each answer is a tap target. */
334
- @media (pointer: coarse) {
387
+ @media (pointer: coarse), (hover: none) {
335
388
  kbd {
336
389
  display: none;
337
390
  }
@@ -9,8 +9,9 @@ interface Props {
9
9
  hidden: boolean;
10
10
  /** The reader's own writing meets the change. */
11
11
  outdated: boolean;
12
+ /** Why, as the proposal's writer says it. */
13
+ note?: string;
12
14
  onAnswer(action: 'accept' | 'dismiss'): void;
13
- onHover(on: boolean): void;
14
15
  }
15
16
  declare const ReviewCard: import("svelte").Component<Props, {
16
17
  enter: () => Promise<boolean>;
@@ -65,10 +65,6 @@
65
65
  target.setAttribute('data-qm-review', [...tokens(), id].join(' '));
66
66
  target.setAttribute('data-qm-proposed', '');
67
67
  if (removes) target.setAttribute('data-qm-removes', '');
68
- const enter = () => reviewing.point(id, 'pointer');
69
- const leave = () => reviewing.point(undefined, 'pointer');
70
- target.addEventListener('pointerenter', enter);
71
- target.addEventListener('pointerleave', leave);
72
68
  const by = (el: HTMLElement) =>
73
69
  (el.getAttribute('aria-describedby') ?? '').split(' ').filter(Boolean);
74
70
  const described = new Set<HTMLElement>();
@@ -103,8 +99,6 @@
103
99
  if (rest.length) el.setAttribute('aria-describedby', rest.join(' '));
104
100
  else el.removeAttribute('aria-describedby');
105
101
  }
106
- target.removeEventListener('pointerenter', enter);
107
- target.removeEventListener('pointerleave', leave);
108
102
  const rest = tokens().filter((t) => t !== id);
109
103
  if (rest.length) {
110
104
  target.setAttribute('data-qm-review', rest.join(' '));
@@ -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}
@@ -154,6 +154,7 @@
154
154
  fallback={ghostMember}
155
155
  blankTitle={schema.ui?.blank_title}
156
156
  {id}
157
+ {labelledBy}
157
158
  {describedBy}
158
159
  onCommit={commitPick}
159
160
  proposing={!!pick}
@@ -77,6 +77,10 @@
77
77
  export async function focusField(field: DocPath): Promise<void> {
78
78
  await inner?.focusField(field);
79
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
+ }
80
84
  /** Wash the field at `field` where it is on show, without focusing or revealing it. */
81
85
  export function washField(field: DocPath): void {
82
86
  inner?.washField(field);
@@ -114,11 +118,12 @@
114
118
  export async function revealReview(id: string, opts?: { focus?: boolean }): Promise<boolean> {
115
119
  return (await inner?.revealReview(id, opts)) ?? false;
116
120
  }
117
- /** Answer items as the answer card would, in document order (`'all'`: every item drawn),
118
- * moving neither the focus nor the caret; where the current change is among them, the next
119
- * open one is current. 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. */
120
125
  export function answerReview(
121
- ids: readonly string[] | 'all',
126
+ ids: readonly string[] | 'all' | { group: string },
122
127
  action: 'accept' | 'dismiss'
123
128
  ): string[] {
124
129
  return inner?.answerReview(ids, action) ?? [];
@@ -130,10 +135,11 @@
130
135
  return inner?.projectReview(target) ?? NO_PROJECTION;
131
136
  }
132
137
  /** Make the next or previous open item current, round from either end, the caret or the
133
- * focus in it unless `focus` is false. Resolves its id, `undefined` for none. */
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. */
134
140
  export async function stepReview(
135
141
  dir: 1 | -1,
136
- opts?: { focus?: boolean }
142
+ opts?: { focus?: boolean; group?: string }
137
143
  ): Promise<string | undefined> {
138
144
  return (await inner?.stepReview(dir, opts)) ?? undefined;
139
145
  }
@@ -7,6 +7,7 @@ import { type ReviewProjection } from './review.js';
7
7
  declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
8
8
  setCaret: (at: Landing) => Promise<void>;
9
9
  focusField: (field: DocPath) => Promise<void>;
10
+ revealField: (field: DocPath) => Promise<void>;
10
11
  washField: (field: DocPath) => void;
11
12
  insertCard: (kind: string, at?: number) => CardId | undefined;
12
13
  removeCard: (cardId: CardId) => void;
@@ -18,10 +19,13 @@ declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
18
19
  revealReview: (id: string, opts?: {
19
20
  focus?: boolean;
20
21
  }) => Promise<boolean>;
21
- answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
22
+ answerReview: (ids: readonly string[] | "all" | {
23
+ group: string;
24
+ }, action: "accept" | "dismiss") => string[];
22
25
  projectReview: (target: Document) => ReviewProjection;
23
26
  stepReview: (dir: 1 | -1, opts?: {
24
27
  focus?: boolean;
28
+ group?: string;
25
29
  }) => Promise<string | undefined>;
26
30
  }, "">;
27
31
  type VisualEditor = ReturnType<typeof VisualEditor>;