@quillmark/svelte 0.33.0 → 0.35.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.
- package/README.md +73 -1
- package/THEMING.md +11 -10
- package/dist/core/address.d.ts +6 -0
- package/dist/core/address.js +16 -0
- package/dist/core/codec/anchor.d.ts +12 -0
- package/dist/core/codec/anchor.js +39 -0
- package/dist/core/codec/drag-move.d.ts +11 -0
- package/dist/core/codec/drag-move.js +143 -0
- package/dist/core/codec/encode.js +14 -5
- package/dist/core/codec/field.d.ts +44 -1
- package/dist/core/codec/field.js +137 -38
- package/dist/core/codec/index.d.ts +8 -2
- package/dist/core/codec/index.js +9 -2
- package/dist/core/codec/islands.d.ts +4 -1
- package/dist/core/codec/islands.js +6 -0
- package/dist/core/codec/keymap.d.ts +3 -0
- package/dist/core/codec/keymap.js +13 -12
- package/dist/core/codec/leave.d.ts +17 -0
- package/dist/core/codec/leave.js +78 -0
- package/dist/core/codec/prose.css +172 -0
- package/dist/core/codec/review-diff.d.ts +12 -0
- package/dist/core/codec/review-diff.js +131 -0
- package/dist/core/codec/review.d.ts +116 -0
- package/dist/core/codec/review.js +920 -0
- package/dist/core/codec/shortcuts.d.ts +20 -4
- package/dist/core/codec/shortcuts.js +27 -7
- package/dist/core/codec/slash.d.ts +3 -0
- package/dist/core/codec/slash.js +2 -1
- package/dist/core/codec/table-view.js +163 -25
- package/dist/core/codec/undo.d.ts +6 -0
- package/dist/core/codec/undo.js +25 -2
- package/dist/core/dragfollow.d.ts +18 -0
- package/dist/core/dragfollow.js +63 -0
- package/dist/core/theme.css +34 -7
- package/dist/preview/controller.js +16 -0
- package/dist/preview/strings.d.ts +4 -0
- package/dist/preview/strings.js +3 -1
- package/dist/visual/ArrayField.svelte +363 -57
- package/dist/visual/ArrayField.svelte.d.ts +5 -0
- package/dist/visual/BooleanField.svelte +60 -5
- package/dist/visual/BooleanField.svelte.d.ts +2 -1
- package/dist/visual/Card.svelte +27 -17
- package/dist/visual/CardControls.svelte +17 -7
- package/dist/visual/CardControls.svelte.d.ts +2 -0
- package/dist/visual/DateField.svelte +90 -39
- package/dist/visual/DateField.svelte.d.ts +2 -2
- package/dist/visual/Field.svelte +98 -6
- package/dist/visual/FieldHint.svelte +24 -9
- package/dist/visual/FieldLabel.svelte +128 -22
- package/dist/visual/FieldLabel.svelte.d.ts +9 -0
- package/dist/visual/FormatPopover.svelte +125 -20
- package/dist/visual/MatrixAdd.svelte +13 -6
- package/dist/visual/MatrixAdd.svelte.d.ts +3 -2
- package/dist/visual/MatrixField.svelte +36 -8
- package/dist/visual/NumberField.svelte +27 -6
- package/dist/visual/NumberField.svelte.d.ts +3 -0
- package/dist/visual/ObjectField.svelte +25 -1
- package/dist/visual/ObjectField.svelte.d.ts +6 -0
- package/dist/visual/ProseField.svelte +21 -0
- package/dist/visual/ProseField.svelte.d.ts +3 -0
- package/dist/visual/ProseValue.svelte +107 -17
- package/dist/visual/ProseValue.svelte.d.ts +18 -4
- package/dist/visual/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +43 -0
- package/dist/visual/ReviewRows.svelte.d.ts +11 -0
- package/dist/visual/SlashMenu.svelte +13 -1
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/VisualEditor.svelte +22 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +591 -27
- package/dist/visual/VisualEditorInner.svelte.d.ts +7 -0
- package/dist/visual/controls.css +17 -2
- package/dist/visual/guidance.d.ts +12 -0
- package/dist/visual/guidance.js +37 -2
- package/dist/visual/icons/nodes.d.ts +14 -2
- package/dist/visual/icons/nodes.js +12 -1
- package/dist/visual/index.d.ts +6 -0
- package/dist/visual/index.js +2 -0
- package/dist/visual/listhistory.d.ts +36 -0
- package/dist/visual/listhistory.js +53 -0
- package/dist/visual/proposals.d.ts +40 -0
- package/dist/visual/proposals.js +219 -0
- package/dist/visual/props.d.ts +36 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +135 -0
- package/dist/visual/review.js +227 -0
- package/dist/visual/review.svelte.d.ts +79 -0
- package/dist/visual/review.svelte.js +226 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +36 -7
- package/dist/visual/strings.js +26 -7
- package/dist/visual/structure.d.ts +5 -0
- package/dist/visual/structure.js +1 -1
- package/dist/visual/undo.svelte.d.ts +40 -7
- package/dist/visual/undo.svelte.js +98 -25
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { LeafRegistry } from './leaves.js';
|
|
16
16
|
import SlashMenu from './SlashMenu.svelte';
|
|
17
17
|
import { wording } from './strings.js';
|
|
18
|
+
import { review } from './review.svelte.js';
|
|
18
19
|
import './controls.css';
|
|
19
20
|
import type { Document, Quill, Addr, Content, Diagnostic } from '@quillmark/wasm';
|
|
20
21
|
import type { EditorErrorHandler } from '../core/errors.js';
|
|
@@ -43,6 +44,9 @@
|
|
|
43
44
|
labelledBy?: string;
|
|
44
45
|
/** The parked `description` (FieldLabel) → `aria-describedby`. */
|
|
45
46
|
describedBy?: string;
|
|
47
|
+
/** The default tag's id (FieldLabel), which describes the leaf while it holds its
|
|
48
|
+
* unwritten default (`createField`). */
|
|
49
|
+
defaultNoteId?: string;
|
|
46
50
|
/** The resolved `default:` where it prints: what an unset field's leaf holds
|
|
47
51
|
* until an edit takes it (`createField`). */
|
|
48
52
|
fallback?: Content;
|
|
@@ -80,6 +84,7 @@
|
|
|
80
84
|
label,
|
|
81
85
|
labelledBy,
|
|
82
86
|
describedBy,
|
|
87
|
+
defaultNoteId,
|
|
83
88
|
fallback,
|
|
84
89
|
placeholder,
|
|
85
90
|
placeholderUntilEdit,
|
|
@@ -102,6 +107,10 @@
|
|
|
102
107
|
// locale swap reaches a mounted table without remounting the leaf and losing the caret.
|
|
103
108
|
const t = wording();
|
|
104
109
|
|
|
110
|
+
// The editor's review state: this leaf draws the items whose anchors it holds and those
|
|
111
|
+
// placed by its own blocks, and says which it drew.
|
|
112
|
+
const reviewing = review();
|
|
113
|
+
|
|
105
114
|
/** Pushed by the leaf's trigger plugin: the menu is the leaf's surface rather than
|
|
106
115
|
* the shell's (INVARIANTS §Chrome). A constrained leaf never receives one, the
|
|
107
116
|
* trigger mounting on the block schema alone. */
|
|
@@ -131,6 +140,7 @@
|
|
|
131
140
|
label,
|
|
132
141
|
labelledBy,
|
|
133
142
|
describedBy,
|
|
143
|
+
defaultNoteId,
|
|
134
144
|
fallback,
|
|
135
145
|
placeholder,
|
|
136
146
|
placeholderUntilEdit,
|
|
@@ -138,9 +148,15 @@
|
|
|
138
148
|
cap,
|
|
139
149
|
tableStrings: () => t.strings,
|
|
140
150
|
slashStrings: () => t.strings,
|
|
151
|
+
leaveStrings: () => t.strings,
|
|
141
152
|
onSlash: (next) => {
|
|
142
153
|
slash = next;
|
|
143
154
|
},
|
|
155
|
+
reviewStrings: () => t.strings,
|
|
156
|
+
onReview: (id, action, chord) => reviewing.heard(id, action, leafKey, chord),
|
|
157
|
+
onReviewPoint: (id, via) => reviewing.point(id, via, leafKey),
|
|
158
|
+
onReviewWriting: (on) => reviewing.writing(on),
|
|
159
|
+
onReviewDrawn: (report) => reviewing.drew(leafKey, report),
|
|
144
160
|
onFocus,
|
|
145
161
|
onCaretMove,
|
|
146
162
|
onChange,
|
|
@@ -170,6 +186,10 @@
|
|
|
170
186
|
controller?.setFallback(fallback);
|
|
171
187
|
});
|
|
172
188
|
|
|
189
|
+
$effect(() => {
|
|
190
|
+
controller?.setReview(reviewing.textAt(leafKey), reviewing.lit);
|
|
191
|
+
});
|
|
192
|
+
|
|
173
193
|
// Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
|
|
174
194
|
$effect(() => {
|
|
175
195
|
void diagnostics;
|
|
@@ -194,6 +214,7 @@
|
|
|
194
214
|
leaf={() => controller}
|
|
195
215
|
label={t.strings.slashLabel}
|
|
196
216
|
name={t.strings.slashName}
|
|
217
|
+
position={t.strings.slashPosition}
|
|
197
218
|
/>
|
|
198
219
|
|
|
199
220
|
<style>
|
|
@@ -26,6 +26,9 @@ interface Props {
|
|
|
26
26
|
labelledBy?: string;
|
|
27
27
|
/** The parked `description` (FieldLabel) → `aria-describedby`. */
|
|
28
28
|
describedBy?: string;
|
|
29
|
+
/** The default tag's id (FieldLabel), which describes the leaf while it holds its
|
|
30
|
+
* unwritten default (`createField`). */
|
|
31
|
+
defaultNoteId?: string;
|
|
29
32
|
/** The resolved `default:` where it prints: what an unset field's leaf holds
|
|
30
33
|
* until an edit takes it (`createField`). */
|
|
31
34
|
fallback?: Content;
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
declaring `multiline: true` takes the full row ({@link ObjectField}), a `richtext` one
|
|
32
32
|
on the block schema and a `text` one on the plain schema, paragraphs and hard breaks.
|
|
33
33
|
An array element is one textblock whatever it declares, since Enter there is the
|
|
34
|
-
repeater's, and a paste of several lines into one is a row per line, as Enter
|
|
35
|
-
open them, up to the array's `max:`, the last row taking what is left joined
|
|
36
|
-
(`lines`). There is no slash menu at either width, and no island view.
|
|
34
|
+
repeater's, and a paste or a drop of several lines into one is a row per line, as Enter
|
|
35
|
+
would open them, up to the array's `max:`, the last row taking what is left joined and
|
|
36
|
+
then the row's text after the landing point (`lines`). There is no slash menu at either width, and no island view.
|
|
37
37
|
|
|
38
38
|
A leaf over content it cannot edit is held (`fitsLeaf`): a narrowed one over anything
|
|
39
39
|
but one plain paragraph, a plain one over anything but plain lines, where the decode
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
-->
|
|
46
46
|
<script lang="ts">
|
|
47
47
|
import { untrack } from 'svelte';
|
|
48
|
-
import { Slice, type Node as PMNode } from 'prosemirror-model';
|
|
48
|
+
import { Fragment, Slice, type Node as PMNode } from 'prosemirror-model';
|
|
49
49
|
import { EditorState, Selection } from 'prosemirror-state';
|
|
50
50
|
import { EditorView } from 'prosemirror-view';
|
|
51
51
|
import {
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
proseAttributes,
|
|
63
63
|
proseLeafPlugins,
|
|
64
64
|
buildLineIndex,
|
|
65
|
+
capCount,
|
|
65
66
|
pmToOffset,
|
|
66
67
|
offsetToPM,
|
|
67
68
|
valueEqual,
|
|
@@ -108,10 +109,21 @@
|
|
|
108
109
|
/** The declared `max:`, a character count no edit takes the leaf past. */
|
|
109
110
|
cap?: TextCap;
|
|
110
111
|
onChange: (rt: Content) => void;
|
|
111
|
-
/** Where a paste's lines past the first go: rows of their own below this
|
|
112
|
-
* most `room()` of them, the last taking the rest joined
|
|
113
|
-
*
|
|
114
|
-
|
|
112
|
+
/** Where a paste's or a drop's lines past the first go: rows of their own below this
|
|
113
|
+
* one, at most `room()` of them, the last taking the rest joined and then what
|
|
114
|
+
* followed the landing point in this row. The row's own edit comes up beside them,
|
|
115
|
+
* the two one commit, with `caret` the offset in the last row where the lines end.
|
|
116
|
+
* Absent, the leaf joins them into its line.
|
|
117
|
+
*
|
|
118
|
+
* Enter short of the line's end splits it there, the rest of the line going to a
|
|
119
|
+
* row of its own below with the caret at its start, by `onLines` too. Backspace at
|
|
120
|
+
* the line's start and Delete at its end ask `onJoin` to join this row onto the
|
|
121
|
+
* one above (`-1`) or the one below onto this (`1`), which answers whether it did. */
|
|
122
|
+
lines?: {
|
|
123
|
+
room: () => number;
|
|
124
|
+
onLines: (rt: Content, below: Content[], caret: number) => void;
|
|
125
|
+
onJoin?: (dir: -1 | 1) => boolean;
|
|
126
|
+
};
|
|
115
127
|
/** Raw keydown, for a container whose own keys run through this leaf: the
|
|
116
128
|
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
117
129
|
* keymap, so the state it reads is the one this keystroke has yet to change. */
|
|
@@ -170,6 +182,28 @@
|
|
|
170
182
|
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
171
183
|
}
|
|
172
184
|
|
|
185
|
+
/** The caret's UTF-16 offset in this leaf's content, `undefined` while it is held. */
|
|
186
|
+
export function caret(): number | undefined {
|
|
187
|
+
return view && !held
|
|
188
|
+
? pmToOffset(buildLineIndex(view.state.doc), view.state.selection.head)
|
|
189
|
+
: undefined;
|
|
190
|
+
}
|
|
191
|
+
/** This leaf's content as its view holds it, `undefined` while it is held. */
|
|
192
|
+
export function current(): Content | undefined {
|
|
193
|
+
return view && !held ? pmToContent(view.state.doc) : undefined;
|
|
194
|
+
}
|
|
195
|
+
/** This leaf's line with `tail`'s after it, and the offset between the two: a join's
|
|
196
|
+
* row, which the parent commits. `undefined` while held, or where the joined line
|
|
197
|
+
* would pass the cap. */
|
|
198
|
+
export function appended(tail: Content): { content: Content; caret: number } | undefined {
|
|
199
|
+
if (!view || held) return undefined;
|
|
200
|
+
const { doc, schema } = view.state;
|
|
201
|
+
const end = doc.content.size - 1;
|
|
202
|
+
const joined = doc.replace(end, end, new Slice(decode(tail, schema).content, 1, 1));
|
|
203
|
+
if (cap && capCount(joined, cap.trimEnd) > cap.max) return undefined;
|
|
204
|
+
return { content: pmToContent(joined), caret: pmToOffset(buildLineIndex(doc), end) };
|
|
205
|
+
}
|
|
206
|
+
|
|
173
207
|
/** What the view draws from the props. The effect below writes it and the view reads
|
|
174
208
|
* it, never the props: ProseMirror's `destroy` redraws the decorations and attributes
|
|
175
209
|
* once more, and a prop read there re-derives the card over handles the host has
|
|
@@ -193,13 +227,22 @@
|
|
|
193
227
|
let seen = value;
|
|
194
228
|
let defaulted = stored === undefined && !!fallback;
|
|
195
229
|
const reconciler = createReconciler(shown(stored));
|
|
196
|
-
// The
|
|
197
|
-
// lands the first line.
|
|
198
|
-
let spill:
|
|
199
|
-
|
|
230
|
+
// The line groups a paste's later lines become rows of, held from the parse to the
|
|
231
|
+
// edit that lands the first line.
|
|
232
|
+
let spill: PMNode[][] | undefined;
|
|
233
|
+
// The rest of a line Enter splits, held from the key to the edit that cuts it.
|
|
234
|
+
let split: Fragment | undefined;
|
|
235
|
+
/** `groups` as rows, the last carrying `tail` after its lines, and the caret
|
|
236
|
+
* offset in the last between the two. */
|
|
237
|
+
const rows = (groups: PMNode[][], tail: Fragment): { below: Content[]; caret: number } => {
|
|
200
238
|
const { schema } = mounted.state;
|
|
201
|
-
const
|
|
202
|
-
|
|
239
|
+
const doc = (inline: Fragment) =>
|
|
240
|
+
schema.node('doc', null, [schema.nodes.paragraph.create(null, inline)]);
|
|
241
|
+
const below = groups.map((g) => pmToContent(doc(joinLines(g, schema))));
|
|
242
|
+
const joined = joinLines(groups.at(-1)!, schema);
|
|
243
|
+
const last = doc(joined.append(tail));
|
|
244
|
+
below[below.length - 1] = pmToContent(last);
|
|
245
|
+
return { below, caret: pmToOffset(buildLineIndex(last), 1 + joined.size) };
|
|
203
246
|
};
|
|
204
247
|
held = !fitsLeaf(reconciler.last, leaf);
|
|
205
248
|
// Which of `aria-label` / `aria-labelledby` wins is the codec's one answer
|
|
@@ -219,10 +262,35 @@
|
|
|
219
262
|
: proseLeafPlugins(schema, {
|
|
220
263
|
inline,
|
|
221
264
|
placeholder: () => drawn.placeholder,
|
|
265
|
+
leaveStrings: () => t.strings,
|
|
222
266
|
cap
|
|
223
267
|
})
|
|
224
268
|
});
|
|
225
269
|
};
|
|
270
|
+
/** Enter's split and the edge keys' join, where a row has `lines` to take them.
|
|
271
|
+
* Enter at the line's end is left to the repeater's insert, as is any key
|
|
272
|
+
* past the array's `max:`. */
|
|
273
|
+
const lineKey = (e: KeyboardEvent): boolean => {
|
|
274
|
+
if (!lines || held || e.isComposing || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey)
|
|
275
|
+
return false;
|
|
276
|
+
const { selection, doc } = mounted.state;
|
|
277
|
+
const end = doc.content.size - 1;
|
|
278
|
+
if (e.key === 'Enter') {
|
|
279
|
+
if (selection.empty && selection.head === end) return false;
|
|
280
|
+
if (lines.room() < 1) return false;
|
|
281
|
+
const tr = mounted.state.tr.deleteSelection();
|
|
282
|
+
const at = tr.doc.resolve(tr.selection.from);
|
|
283
|
+
split = at.parent.content.cut(at.parentOffset);
|
|
284
|
+
tr.delete(at.pos, at.end()).setMeta('addToHistory', false);
|
|
285
|
+
mounted.dispatch(tr);
|
|
286
|
+
split = undefined;
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
if (e.repeat || !selection.empty || doc.textContent.length === 0) return false;
|
|
290
|
+
if (e.key === 'Backspace' && selection.head === 1) return !!lines.onJoin?.(-1);
|
|
291
|
+
if (e.key === 'Delete' && selection.head === end) return !!lines.onJoin?.(1);
|
|
292
|
+
return false;
|
|
293
|
+
};
|
|
226
294
|
const mounted = new EditorView(
|
|
227
295
|
{ mount },
|
|
228
296
|
{
|
|
@@ -239,20 +307,38 @@
|
|
|
239
307
|
const room = Math.min(pasted.length - 1, lines.room());
|
|
240
308
|
if (room < 1) return slice;
|
|
241
309
|
const below = pasted.slice(1);
|
|
242
|
-
spill = [...below.slice(0, room - 1).map((l) =>
|
|
310
|
+
spill = [...below.slice(0, room - 1).map((l) => [l]), below.slice(room - 1)];
|
|
243
311
|
return new Slice(pasted[0]!.content, 0, 0);
|
|
244
312
|
},
|
|
245
313
|
dispatchTransaction(tr) {
|
|
246
314
|
const event = tr.getMeta('uiEvent');
|
|
247
|
-
const
|
|
315
|
+
const groups = event === 'paste' || event === 'drop' ? spill : undefined;
|
|
316
|
+
const rest = split;
|
|
248
317
|
spill = undefined;
|
|
318
|
+
split = undefined;
|
|
319
|
+
// What followed the landing point goes on with the last line, as a
|
|
320
|
+
// textarea's split leaves it, rather than staying behind the first.
|
|
321
|
+
let below: { below: Content[]; caret: number } | undefined;
|
|
322
|
+
if (rest) below = rows([[]], rest);
|
|
323
|
+
else if (groups && lines) {
|
|
324
|
+
const landed = tr.doc.resolve(tr.selection.to);
|
|
325
|
+
const tail = landed.parent.isTextblock
|
|
326
|
+
? landed.parent.content.cut(landed.parentOffset)
|
|
327
|
+
: Fragment.empty;
|
|
328
|
+
if (tail.size) tr.delete(landed.pos, landed.end());
|
|
329
|
+
below = rows(groups, tail);
|
|
330
|
+
}
|
|
331
|
+
// A split or a paste over rows is the list's step to undo, so this row's half
|
|
332
|
+
// of it is no step of its own. A drop keeps its step: a move between two
|
|
333
|
+
// leaves pairs it with the source's (`drag-move.ts`).
|
|
334
|
+
if (below && event !== 'drop') tr.setMeta('addToHistory', false);
|
|
249
335
|
const next = mounted.state.apply(tr);
|
|
250
336
|
if (next === mounted.state) return;
|
|
251
337
|
const edit = tr.docChanged && !held;
|
|
252
338
|
if (edit) defaulted = false;
|
|
253
339
|
mounted.updateState(next);
|
|
254
340
|
if (!edit && !below) return;
|
|
255
|
-
if (below && lines) lines.onLines(pmToContent(next.doc), below);
|
|
341
|
+
if (below && lines) lines.onLines(pmToContent(next.doc), below.below, below.caret);
|
|
256
342
|
else onChange(pmToContent(next.doc));
|
|
257
343
|
// The commit as the store took it, so its echo through the re-derive is no move.
|
|
258
344
|
seen = value;
|
|
@@ -264,6 +350,10 @@
|
|
|
264
350
|
return false;
|
|
265
351
|
},
|
|
266
352
|
keydown: (_v, e) => {
|
|
353
|
+
if (lineKey(e)) {
|
|
354
|
+
e.preventDefault();
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
267
357
|
onKey?.(e);
|
|
268
358
|
return false;
|
|
269
359
|
}
|
|
@@ -35,12 +35,20 @@ interface Props {
|
|
|
35
35
|
/** The declared `max:`, a character count no edit takes the leaf past. */
|
|
36
36
|
cap?: TextCap;
|
|
37
37
|
onChange: (rt: Content) => void;
|
|
38
|
-
/** Where a paste's lines past the first go: rows of their own below this
|
|
39
|
-
* most `room()` of them, the last taking the rest joined
|
|
40
|
-
*
|
|
38
|
+
/** Where a paste's or a drop's lines past the first go: rows of their own below this
|
|
39
|
+
* one, at most `room()` of them, the last taking the rest joined and then what
|
|
40
|
+
* followed the landing point in this row. The row's own edit comes up beside them,
|
|
41
|
+
* the two one commit, with `caret` the offset in the last row where the lines end.
|
|
42
|
+
* Absent, the leaf joins them into its line.
|
|
43
|
+
*
|
|
44
|
+
* Enter short of the line's end splits it there, the rest of the line going to a
|
|
45
|
+
* row of its own below with the caret at its start, by `onLines` too. Backspace at
|
|
46
|
+
* the line's start and Delete at its end ask `onJoin` to join this row onto the
|
|
47
|
+
* one above (`-1`) or the one below onto this (`1`), which answers whether it did. */
|
|
41
48
|
lines?: {
|
|
42
49
|
room: () => number;
|
|
43
|
-
onLines: (rt: Content, below: Content[]) => void;
|
|
50
|
+
onLines: (rt: Content, below: Content[], caret: number) => void;
|
|
51
|
+
onJoin?: (dir: -1 | 1) => boolean;
|
|
44
52
|
};
|
|
45
53
|
/** Raw keydown, for a container whose own keys run through this leaf: the
|
|
46
54
|
* array repeater's Enter/Backspace (`ArrayField`). Fires before the view's own
|
|
@@ -50,6 +58,12 @@ interface Props {
|
|
|
50
58
|
declare const ProseValue: import("svelte").Component<Props, {
|
|
51
59
|
focus: () => void;
|
|
52
60
|
setCaret: (pos: number) => void;
|
|
61
|
+
caret: () => number | undefined;
|
|
62
|
+
current: () => Content | undefined;
|
|
63
|
+
appended: (tail: Content) => {
|
|
64
|
+
content: Content;
|
|
65
|
+
caret: number;
|
|
66
|
+
} | undefined;
|
|
53
67
|
}, "">;
|
|
54
68
|
type ProseValue = ReturnType<typeof ProseValue>;
|
|
55
69
|
export default ProseValue;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A proposed value, under the control whose value it would replace: the value as words, and the
|
|
3
|
+
two answers. In flow, as a diagnostic is, so the proposal stands with its field and takes no
|
|
4
|
+
surface of its own. It is drawn as a prose proposal is, what would go struck and what would
|
|
5
|
+
come tinted: two lines of words by the words they differ in, two lists by their members, two
|
|
6
|
+
records by their keys, any other pair of values whole.
|
|
7
|
+
|
|
8
|
+
The buttons are in the tab order, a form control having no caret for a chord to follow; the
|
|
9
|
+
chords answer too while the focus is in the field (`Field.svelte`).
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { wording } from './strings.js';
|
|
13
|
+
import { reviewRuns, reviewText, type FieldProposal } from './review.js';
|
|
14
|
+
import { review } from './review.svelte.js';
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
item: FieldProposal;
|
|
18
|
+
/** The value the control holds. */
|
|
19
|
+
value: unknown;
|
|
20
|
+
/** Take the focus back to the control: an answer given from the row unmounts it. */
|
|
21
|
+
refocus?: () => void;
|
|
22
|
+
/** Where the value is, for one drawn under a control that is not its own. */
|
|
23
|
+
label?: string;
|
|
24
|
+
/** It takes a list's member out, so nothing comes in its place. */
|
|
25
|
+
removes?: boolean;
|
|
26
|
+
}
|
|
27
|
+
let { item, value, refocus, label, removes = false }: Props = $props();
|
|
28
|
+
|
|
29
|
+
let row = $state<HTMLElement>();
|
|
30
|
+
function answer(action: 'accept' | 'dismiss'): void {
|
|
31
|
+
const held = !!row?.contains(document.activeElement);
|
|
32
|
+
reviewing.act(item.id, action);
|
|
33
|
+
if (held) refocus?.();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const t = wording();
|
|
37
|
+
const reviewing = review();
|
|
38
|
+
|
|
39
|
+
const words = $derived({ on: t.strings.reviewOn, off: t.strings.reviewOff });
|
|
40
|
+
const after = $derived(reviewText(item.after, words));
|
|
41
|
+
const runs = $derived(reviewRuns(value, item.after, words));
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
45
|
+
<div
|
|
46
|
+
bind:this={row}
|
|
47
|
+
class={['qm-review-proposal', { 'qm-review-lit': reviewing.lit === item.id }]}
|
|
48
|
+
data-qm-review={item.id}
|
|
49
|
+
role="group"
|
|
50
|
+
aria-label={t.strings.reviewProposal}
|
|
51
|
+
onpointerenter={() => reviewing.point(item.id, 'pointer')}
|
|
52
|
+
onpointerleave={() => reviewing.point(undefined, 'pointer')}
|
|
53
|
+
>
|
|
54
|
+
<span class="qm-review-value">
|
|
55
|
+
{#if label}<span class="qm-review-where">{label}: </span>{/if}
|
|
56
|
+
{#each runs as run, i (i)}
|
|
57
|
+
{#if run.kind === 'del'}<del class="qm-review-del">{run.text}</del
|
|
58
|
+
>{:else if run.kind === 'ins'}<ins class="qm-review-ins">{run.text}</ins
|
|
59
|
+
>{:else}{run.text}{/if}
|
|
60
|
+
{/each}
|
|
61
|
+
{#if !after && !removes}
|
|
62
|
+
<span class="qm-review-none">{t.strings.reviewEmpty}</span>
|
|
63
|
+
{/if}
|
|
64
|
+
</span>
|
|
65
|
+
<span class="qm-review-answers">
|
|
66
|
+
{#if reviewing.fieldOutdated.has(item.id)}
|
|
67
|
+
<span class="qm-review-outdated-label">{t.strings.reviewOutdated}</span>
|
|
68
|
+
{/if}
|
|
69
|
+
<button
|
|
70
|
+
type="button"
|
|
71
|
+
class="qm-review-act qm-review-accept qm-focus-ring"
|
|
72
|
+
title={t.strings.reviewAcceptTitle}
|
|
73
|
+
onclick={() => answer('accept')}>{t.strings.reviewAccept}</button
|
|
74
|
+
>
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
class="qm-review-act qm-review-dismiss qm-focus-ring"
|
|
78
|
+
title={t.strings.reviewDismissTitle}
|
|
79
|
+
onclick={() => answer('dismiss')}>{t.strings.reviewDismiss}</button
|
|
80
|
+
>
|
|
81
|
+
</span>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<style>
|
|
85
|
+
/* The value starts on the control's own text column, so the proposal reads as the line the
|
|
86
|
+
control would hold, and the answers trail it as they trail a paragraph's last line. No
|
|
87
|
+
fill on the row: the tint is on the proposed words, as it is in prose, and a row is not a
|
|
88
|
+
second well. */
|
|
89
|
+
.qm-review-proposal {
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-wrap: wrap;
|
|
92
|
+
align-items: baseline;
|
|
93
|
+
gap: var(--_qm-space-half) var(--_qm-space-3);
|
|
94
|
+
padding-inline-start: var(--_qm-space-3);
|
|
95
|
+
font-size: var(--_qm-text-body);
|
|
96
|
+
}
|
|
97
|
+
.qm-review-value {
|
|
98
|
+
min-width: 0;
|
|
99
|
+
overflow-wrap: anywhere;
|
|
100
|
+
white-space: pre-wrap;
|
|
101
|
+
}
|
|
102
|
+
.qm-review-del {
|
|
103
|
+
color: var(--_qm-ink-label);
|
|
104
|
+
text-decoration: line-through;
|
|
105
|
+
text-decoration-color: var(--_qm-review-line);
|
|
106
|
+
}
|
|
107
|
+
.qm-review-ins {
|
|
108
|
+
text-decoration: none;
|
|
109
|
+
background: var(--_qm-review-tint);
|
|
110
|
+
box-shadow:
|
|
111
|
+
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-tint),
|
|
112
|
+
var(--_qm-space-half) 0 0 var(--_qm-review-tint);
|
|
113
|
+
border-radius: var(--_qm-radius-inner);
|
|
114
|
+
-webkit-box-decoration-break: clone;
|
|
115
|
+
box-decoration-break: clone;
|
|
116
|
+
transition:
|
|
117
|
+
background-color var(--_qm-duration-fast) var(--_qm-ease-reverse),
|
|
118
|
+
box-shadow var(--_qm-duration-fast) var(--_qm-ease-reverse);
|
|
119
|
+
}
|
|
120
|
+
.qm-review-del + .qm-review-ins {
|
|
121
|
+
margin-inline-start: calc(var(--_qm-space) + var(--_qm-space-half));
|
|
122
|
+
}
|
|
123
|
+
.qm-review-lit .qm-review-ins {
|
|
124
|
+
background: var(--_qm-review-lit);
|
|
125
|
+
box-shadow:
|
|
126
|
+
calc(-1 * var(--_qm-space-half)) 0 0 var(--_qm-review-lit),
|
|
127
|
+
var(--_qm-space-half) 0 0 var(--_qm-review-lit);
|
|
128
|
+
}
|
|
129
|
+
.qm-review-where {
|
|
130
|
+
color: var(--_qm-ink-label);
|
|
131
|
+
}
|
|
132
|
+
.qm-review-none {
|
|
133
|
+
color: var(--_qm-ink-label);
|
|
134
|
+
font-style: italic;
|
|
135
|
+
}
|
|
136
|
+
.qm-review-answers {
|
|
137
|
+
display: inline-flex;
|
|
138
|
+
flex-shrink: 0;
|
|
139
|
+
gap: var(--_qm-space-half);
|
|
140
|
+
font-size: var(--_qm-text-label);
|
|
141
|
+
font-weight: var(--_qm-weight-mid);
|
|
142
|
+
line-height: var(--_qm-leading-tight);
|
|
143
|
+
}
|
|
144
|
+
@media (pointer: coarse) {
|
|
145
|
+
.qm-review-answers {
|
|
146
|
+
gap: var(--_qm-space-2);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FieldProposal } from './review.js';
|
|
2
|
+
interface Props {
|
|
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
|
+
/** It takes a list's member out, so nothing comes in its place. */
|
|
11
|
+
removes?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const ReviewProposal: import("svelte").Component<Props, {}, "">;
|
|
14
|
+
type ReviewProposal = ReturnType<typeof ReviewProposal>;
|
|
15
|
+
export default ReviewProposal;
|
|
@@ -0,0 +1,43 @@
|
|
|
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.
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import type { PathStep } from '@quillmark/wasm';
|
|
10
|
+
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';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
entries: readonly DeepReview[] | undefined;
|
|
17
|
+
/** The value the place holds, which the entries' steps walk from. */
|
|
18
|
+
value: unknown;
|
|
19
|
+
/** The place is a list's member, which a proposal of nothing takes out. */
|
|
20
|
+
member?: boolean;
|
|
21
|
+
}
|
|
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;
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#each entries ?? [] as { steps, item } (item.id)}
|
|
37
|
+
<ReviewProposal
|
|
38
|
+
{item}
|
|
39
|
+
value={valueIn(value, steps)}
|
|
40
|
+
label={where(steps)}
|
|
41
|
+
removes={item.after === undefined && (steps.length ? typeof steps.at(-1) === 'number' : member)}
|
|
42
|
+
/>
|
|
43
|
+
{/each}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DeepReview } from './review.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
entries: readonly DeepReview[] | undefined;
|
|
4
|
+
/** The value the place holds, which the entries' steps walk from. */
|
|
5
|
+
value: unknown;
|
|
6
|
+
/** The place is a list's member, which a proposal of nothing takes out. */
|
|
7
|
+
member?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const ReviewRows: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type ReviewRows = ReturnType<typeof ReviewRows>;
|
|
11
|
+
export default ReviewRows;
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
second highlight the keyboard cannot reach (controls.css, the shared menu recipe).
|
|
17
17
|
The keyboard's one claim here is the scroll: the arrows move an index, and only the
|
|
18
18
|
chrome knows the port that index has to stay inside.
|
|
19
|
+
|
|
20
|
+
Focus never reaches an item, so nothing a screen reader follows says which one is
|
|
21
|
+
highlighted: a polite live region beside the menu speaks the highlighted row and its
|
|
22
|
+
place as the index moves. It is mounted with the leaf, since a region inserted with the
|
|
23
|
+
text it carries is not announced.
|
|
19
24
|
-->
|
|
20
25
|
<script lang="ts">
|
|
21
26
|
import { Popover } from 'bits-ui';
|
|
@@ -32,10 +37,15 @@
|
|
|
32
37
|
label: string;
|
|
33
38
|
/** A command's row name, by its token. */
|
|
34
39
|
name: (command: string) => string;
|
|
40
|
+
/** What the live region says of the highlighted row. */
|
|
41
|
+
position: (name: string, index: number, count: number) => string;
|
|
35
42
|
}
|
|
36
|
-
let { menu, leaf, label, name: nameOf }: Props = $props();
|
|
43
|
+
let { menu, leaf, label, name: nameOf, position }: Props = $props();
|
|
37
44
|
|
|
38
45
|
let open = $derived(!!menu && menu.items.length > 0);
|
|
46
|
+
const announced = $derived(
|
|
47
|
+
open && menu ? position(nameOf(menu.items[menu.index]), menu.index + 1, menu.items.length) : ''
|
|
48
|
+
);
|
|
39
49
|
|
|
40
50
|
/** The root to portal into, resolved from the leaf's own DOM so the menu lands
|
|
41
51
|
* inside whichever `[data-qm-root]` raised it and inherits the consumer's dials;
|
|
@@ -57,6 +67,8 @@
|
|
|
57
67
|
}
|
|
58
68
|
</script>
|
|
59
69
|
|
|
70
|
+
<span class="qm-visually-hidden" aria-live="polite">{announced}</span>
|
|
71
|
+
|
|
60
72
|
<Popover.Root bind:open>
|
|
61
73
|
<Popover.Portal to={portalTarget}>
|
|
62
74
|
<!-- Hung off the trigger and flush against it: the anchor is the `/` itself
|
|
@@ -9,6 +9,8 @@ interface Props {
|
|
|
9
9
|
label: string;
|
|
10
10
|
/** A command's row name, by its token. */
|
|
11
11
|
name: (command: string) => string;
|
|
12
|
+
/** What the live region says of the highlighted row. */
|
|
13
|
+
position: (name: string, index: number, count: number) => string;
|
|
12
14
|
}
|
|
13
15
|
declare const SlashMenu: import("svelte").Component<Props, {}, "">;
|
|
14
16
|
type SlashMenu = ReturnType<typeof SlashMenu>;
|
|
@@ -106,6 +106,28 @@
|
|
|
106
106
|
export function applyCardOps(ops: readonly CardOp[]): void {
|
|
107
107
|
inner?.applyCardOps(ops);
|
|
108
108
|
}
|
|
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. */
|
|
112
|
+
export async function revealReview(id: string, opts?: { focus?: boolean }): Promise<boolean> {
|
|
113
|
+
return (await inner?.revealReview(id, opts)) ?? false;
|
|
114
|
+
}
|
|
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. */
|
|
117
|
+
export function answerReview(
|
|
118
|
+
ids: readonly string[] | 'all',
|
|
119
|
+
action: 'accept' | 'dismiss'
|
|
120
|
+
): string[] {
|
|
121
|
+
return inner?.answerReview(ids, action) ?? [];
|
|
122
|
+
}
|
|
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. */
|
|
125
|
+
export async function stepReview(
|
|
126
|
+
dir: 1 | -1,
|
|
127
|
+
opts?: { focus?: boolean }
|
|
128
|
+
): Promise<string | undefined> {
|
|
129
|
+
return (await inner?.stepReview(dir, opts)) ?? undefined;
|
|
130
|
+
}
|
|
109
131
|
</script>
|
|
110
132
|
|
|
111
133
|
{#key props.doc}
|
|
@@ -13,6 +13,13 @@ declare const VisualEditor: import("svelte").Component<VisualEditorProps, {
|
|
|
13
13
|
applyExternal: (field: DocPath, delta?: Delta) => void;
|
|
14
14
|
refresh: () => void;
|
|
15
15
|
applyCardOps: (ops: readonly CardOp[]) => void;
|
|
16
|
+
revealReview: (id: string, opts?: {
|
|
17
|
+
focus?: boolean;
|
|
18
|
+
}) => Promise<boolean>;
|
|
19
|
+
answerReview: (ids: readonly string[] | "all", action: "accept" | "dismiss") => string[];
|
|
20
|
+
stepReview: (dir: 1 | -1, opts?: {
|
|
21
|
+
focus?: boolean;
|
|
22
|
+
}) => Promise<string | undefined>;
|
|
16
23
|
}, "">;
|
|
17
24
|
type VisualEditor = ReturnType<typeof VisualEditor>;
|
|
18
25
|
export default VisualEditor;
|