@quillmark/svelte 0.36.0 → 0.37.1

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 (71) 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 +14 -10
  6. package/dist/core/codec/field.js +34 -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 +20 -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 +44 -17
  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 +262 -145
  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 +22 -13
  34. package/dist/visual/FieldLabel.svelte +6 -42
  35. package/dist/visual/FieldLabel.svelte.d.ts +0 -3
  36. package/dist/visual/FormatPopover.svelte +53 -20
  37. package/dist/visual/MatrixAdd.svelte +9 -10
  38. package/dist/visual/MatrixField.svelte +114 -18
  39. package/dist/visual/NumberField.svelte +21 -5
  40. package/dist/visual/ObjectField.svelte +6 -2
  41. package/dist/visual/ProseField.svelte +6 -3
  42. package/dist/visual/ProseField.svelte.d.ts +2 -1
  43. package/dist/visual/ProseValue.svelte +13 -6
  44. package/dist/visual/ProseValue.svelte.d.ts +4 -1
  45. package/dist/visual/ReviewCard.svelte +93 -33
  46. package/dist/visual/ReviewCard.svelte.d.ts +2 -1
  47. package/dist/visual/ReviewProposal.svelte +0 -6
  48. package/dist/visual/TipsCard.svelte +1 -1
  49. package/dist/visual/VariantField.svelte +1 -0
  50. package/dist/visual/VisualEditor.svelte +12 -6
  51. package/dist/visual/VisualEditor.svelte.d.ts +5 -1
  52. package/dist/visual/VisualEditorInner.svelte +218 -302
  53. package/dist/visual/VisualEditorInner.svelte.d.ts +5 -1
  54. package/dist/visual/controls.css +2 -2
  55. package/dist/visual/guidance.d.ts +0 -2
  56. package/dist/visual/guidance.js +0 -10
  57. package/dist/visual/index.d.ts +2 -2
  58. package/dist/visual/proposals.d.ts +14 -4
  59. package/dist/visual/proposals.js +28 -5
  60. package/dist/visual/props.d.ts +1 -1
  61. package/dist/visual/review-order.d.ts +51 -0
  62. package/dist/visual/review-order.js +87 -0
  63. package/dist/visual/review.d.ts +27 -1
  64. package/dist/visual/review.js +1 -1
  65. package/dist/visual/review.svelte.d.ts +34 -17
  66. package/dist/visual/review.svelte.js +187 -44
  67. package/dist/visual/strings.d.ts +38 -19
  68. package/dist/visual/strings.js +81 -24
  69. package/dist/visual/structure.d.ts +17 -3
  70. package/dist/visual/structure.js +71 -5
  71. package/package.json +2 -2
@@ -1,15 +1,24 @@
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 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`). The column is the card's body or its form whole,
14
+ never the one field, so Accept stands at one edge from change to change and a pointer answering
15
+ a run of them does not hunt for it. A field or a property sharing its row with others takes the
16
+ card beside its line only where the card stands within its own slot, and under the row
17
+ otherwise: beside the line of one that ends short of the column's edge the card covers the
18
+ value of the next. Over a change taller than the pane it stays pinned
19
+ at the foot while any of the change shows. A change out of the pane keeps its card where it
20
+ would stand beside it, so the card scrolls out with the text and the pane's edge clips it as it
21
+ clips the text.
13
22
  A change is several elements (struck runs, tinted widgets, added blocks, a row
14
23
  under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
15
24
  redraws its decorations as it likes, and a box measured once parts from the text it stood on.
@@ -21,7 +30,8 @@
21
30
  -->
22
31
  <script lang="ts">
23
32
  import { tick } from 'svelte';
24
- import { chord, wording } from './strings.js';
33
+ import { REVIEW_KEYS } from '../core/codec/index.js';
34
+ import { keycap, keyshortcut, wording } from './strings.js';
25
35
  import './controls.css';
26
36
 
27
37
  interface Props {
@@ -35,10 +45,12 @@
35
45
  hidden: boolean;
36
46
  /** The reader's own writing meets the change. */
37
47
  outdated: boolean;
48
+ /** Why, as the proposal's writer says it. */
49
+ note?: string;
38
50
  onAnswer(action: 'accept' | 'dismiss'): void;
39
- onHover(on: boolean): void;
40
51
  }
41
- let { id, root, inset, hidden, outdated, onAnswer, onHover }: Props = $props();
52
+ let { id, root, inset, hidden, outdated, note, onAnswer }: Props = $props();
53
+ const noteId = $props.id();
42
54
 
43
55
  const t = wording();
44
56
 
@@ -87,7 +99,8 @@
87
99
 
88
100
  function place(): void {
89
101
  const els = parts();
90
- const rects = els.map((e) => e.getBoundingClientRect()).filter((r) => r.width || r.height);
102
+ const blocks = els.map(blockOf);
103
+ const rects = blocks.map((b) => b.getBoundingClientRect()).filter((r) => r.width || r.height);
91
104
  if (!el || !rects.length) {
92
105
  placed = false;
93
106
  return;
@@ -102,11 +115,15 @@
102
115
  const h = el.offsetHeight;
103
116
  const w = el.offsetWidth;
104
117
  const column = (els[0].closest(
105
- '.qm-field, .qm-card, .qm-review-card-add, .qm-review-card-remove'
118
+ '.qm-fields, .qm-card, .qm-review-card-add, .qm-review-card-remove'
106
119
  ) ?? root)!;
107
120
  left = Math.max(view.left + gap, column.getBoundingClientRect().right - w);
108
121
  const at = (root ?? el).getBoundingClientRect();
109
- const below = lower + gap;
122
+ const last = blocks.find((b, i) => b !== els[i] && b.getBoundingClientRect().bottom === lower);
123
+ const tuck = last && lastLine(last, h);
124
+ const slot = last?.closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
125
+ const beside = tuck && tuck.right + gap <= left && (!slot || left + w <= slot.right + 1);
126
+ const below = beside ? tuck.top : lower + gap;
110
127
  const above = upper - gap - h;
111
128
  const fits = below + h <= floor || above >= ceil;
112
129
  const y =
@@ -125,6 +142,31 @@
125
142
  placed = true;
126
143
  }
127
144
 
145
+ /** The block a run of the change flows in, which the card keeps clear of whole: a card on
146
+ * the run's own line covers the lines of its paragraph after it. */
147
+ function blockOf(at: HTMLElement): HTMLElement {
148
+ for (let up: HTMLElement | null = at; up && up !== root; up = up.parentElement)
149
+ if (!/^(inline|contents)/.test(getComputedStyle(up).display)) return up;
150
+ return at;
151
+ }
152
+
153
+ /** Where a card `h` tall stands beside the last line of a block, and where the line's words
154
+ * end: a card beside a short last line covers nothing of the block, and beside a one-line
155
+ * field's text, centred on it, nothing of the field after it. */
156
+ function lastLine(block: HTMLElement, h: number): { top: number; right: number } | undefined {
157
+ const range = document.createRange();
158
+ range.selectNodeContents(block);
159
+ const lines = [...range.getClientRects()].filter((r) => r.width && r.height);
160
+ if (!lines.length) return undefined;
161
+ const from = Math.max(...lines.map((r) => r.top));
162
+ const on = lines.filter((r) => r.bottom > from);
163
+ const top = Math.min(...on.map((r) => r.top));
164
+ const right = Math.max(...on.map((r) => r.right));
165
+ if (on.length < lines.length) return { top, right };
166
+ const bottom = Math.max(...on.map((r) => r.bottom));
167
+ return { top: (top + bottom - h) / 2, right };
168
+ }
169
+
128
170
  function gapPx(): number {
129
171
  const n = Number.parseFloat(getComputedStyle(el ?? root!).getPropertyValue('--_qm-space'));
130
172
  return Number.isFinite(n) ? n : 0;
@@ -231,31 +273,35 @@
231
273
  style:left="{left}px"
232
274
  role="group"
233
275
  aria-label={t.strings.reviewProposal}
276
+ aria-describedby={note ? noteId : undefined}
234
277
  aria-hidden={!shown}
235
278
  inert={!shown}
236
- onpointerenter={() => onHover(true)}
237
- onpointerleave={() => onHover(false)}
238
279
  onmousedown={(e) => e.preventDefault()}
239
280
  {onkeydown}
240
281
  onfocusout={(e) => {
241
282
  if (!el?.contains(e.relatedTarget as Node | null)) from = undefined;
242
283
  }}
243
284
  >
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
- >
285
+ {#if note}<p id={noteId} class="qm-review-card-reason" title={note}>{note}</p>{/if}
286
+ <div class="qm-review-card-answers">
287
+ {#if outdated}<span class="qm-review-card-note">{t.strings.reviewOutdated}</span>{/if}
288
+ <button
289
+ type="button"
290
+ class="qm-review-card-dismiss qm-focus-ring"
291
+ tabindex="-1"
292
+ aria-keyshortcuts={keyshortcut(REVIEW_KEYS.dismiss)}
293
+ onclick={() => answer('dismiss')}
294
+ >{t.strings.reviewDismiss}<kbd>{keycap(REVIEW_KEYS.dismiss)}</kbd></button
295
+ >
296
+ <button
297
+ type="button"
298
+ class="qm-review-card-accept qm-focus-ring"
299
+ tabindex="-1"
300
+ aria-keyshortcuts={keyshortcut(REVIEW_KEYS.accept)}
301
+ onclick={() => answer('accept')}
302
+ >{t.strings.reviewAccept}<kbd>{keycap(REVIEW_KEYS.accept)}</kbd></button
303
+ >
304
+ </div>
259
305
  </div>
260
306
 
261
307
  <style>
@@ -268,7 +314,7 @@
268
314
  z-index: 2;
269
315
  width: max-content;
270
316
  display: flex;
271
- align-items: center;
317
+ flex-direction: column;
272
318
  gap: var(--_qm-space-half);
273
319
  padding: var(--_qm-space-half);
274
320
  font-family: var(--_qm-font);
@@ -324,14 +370,28 @@
324
370
  }
325
371
  kbd {
326
372
  font: inherit;
327
- opacity: var(--_qm-opacity-rest);
373
+ }
374
+ .qm-review-card-answers {
375
+ display: flex;
376
+ align-items: center;
377
+ justify-content: flex-end;
378
+ gap: var(--_qm-space-half);
379
+ }
380
+ .qm-review-card-reason {
381
+ max-width: min(24rem, calc(100vw - 4 * var(--_qm-space-2)));
382
+ margin: 0;
383
+ padding: var(--_qm-space-half) var(--_qm-space-2) 0;
384
+ overflow: hidden;
385
+ white-space: nowrap;
386
+ text-overflow: ellipsis;
387
+ color: var(--_qm-ink);
328
388
  }
329
389
  .qm-review-card-note {
330
390
  padding-inline: var(--_qm-space-2);
331
391
  color: var(--_qm-ink-label);
332
392
  }
333
393
  /* Under a finger the keys are no help, and each answer is a tap target. */
334
- @media (pointer: coarse) {
394
+ @media (pointer: coarse), (hover: none) {
335
395
  kbd {
336
396
  display: none;
337
397
  }
@@ -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>;