@quillmark/svelte 0.32.0 → 0.34.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/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.d.ts +2 -1
- package/dist/core/codec/encode.js +16 -6
- package/dist/core/codec/field.d.ts +47 -1
- package/dist/core/codec/field.js +201 -37
- 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 +217 -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 +131 -0
- package/dist/core/codec/review.js +1077 -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 +36 -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 +126 -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 +23 -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/ReviewPopover.svelte +179 -0
- package/dist/visual/ReviewPopover.svelte.d.ts +16 -0
- package/dist/visual/ReviewProposal.svelte +149 -0
- package/dist/visual/ReviewProposal.svelte.d.ts +15 -0
- package/dist/visual/ReviewRows.svelte +68 -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 +23 -0
- package/dist/visual/VisualEditor.svelte.d.ts +7 -0
- package/dist/visual/VisualEditorInner.svelte +671 -22
- 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 +35 -0
- package/dist/visual/removed.d.ts +20 -0
- package/dist/visual/removed.js +30 -0
- package/dist/visual/review.d.ts +170 -0
- package/dist/visual/review.js +269 -0
- package/dist/visual/review.svelte.d.ts +106 -0
- package/dist/visual/review.svelte.js +356 -0
- package/dist/visual/rowdrag.svelte.js +44 -55
- package/dist/visual/strings.d.ts +48 -7
- package/dist/visual/strings.js +32 -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,17 @@
|
|
|
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
|
+
reviewShown: () => reviewing.shown?.item.id,
|
|
157
|
+
onReviewDismiss: () => reviewing.dismiss(),
|
|
158
|
+
onReview: (id, action, chord) => reviewing.heard(id, action, leafKey, chord),
|
|
159
|
+
onReviewPoint: (id, via) => reviewing.point(id, via, leafKey),
|
|
160
|
+
onReviewWriting: (on) => reviewing.writing(on),
|
|
161
|
+
onReviewDrawn: (report) => reviewing.drew(leafKey, report),
|
|
144
162
|
onFocus,
|
|
145
163
|
onCaretMove,
|
|
146
164
|
onChange,
|
|
@@ -170,6 +188,10 @@
|
|
|
170
188
|
controller?.setFallback(fallback);
|
|
171
189
|
});
|
|
172
190
|
|
|
191
|
+
$effect(() => {
|
|
192
|
+
controller?.setReview(reviewing.textAt(leafKey), reviewing.lit);
|
|
193
|
+
});
|
|
194
|
+
|
|
173
195
|
// Only a narrowed or a plain leaf holds by what a re-validation says, so only one of them asks.
|
|
174
196
|
$effect(() => {
|
|
175
197
|
void diagnostics;
|
|
@@ -194,6 +216,7 @@
|
|
|
194
216
|
leaf={() => controller}
|
|
195
217
|
label={t.strings.slashLabel}
|
|
196
218
|
name={t.strings.slashName}
|
|
219
|
+
position={t.strings.slashPosition}
|
|
197
220
|
/>
|
|
198
221
|
|
|
199
222
|
<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,179 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The card over a change: what the words or the value replaced, and the one button that takes the
|
|
3
|
+
change back. One card, shell-owned, up for whichever `changed` item the review state shows
|
|
4
|
+
(`review.svelte.ts`), over a mark in a prose leaf or over a field's control.
|
|
5
|
+
|
|
6
|
+
Under its anchor, where the format popover rises over a selection: the two can be up at once,
|
|
7
|
+
and what the reader is reading is the line above.
|
|
8
|
+
|
|
9
|
+
Focus discipline is the format popover's: the card never takes the focus, so the caret that
|
|
10
|
+
raised it stays where it was, and its button swallows its own mousedown for the same reason.
|
|
11
|
+
The pointer's card ends on a scroll, the page having moved under a pointer that did not; the
|
|
12
|
+
caret's and a reveal's follow their mark, and hide while it is scrolled out of the pane.
|
|
13
|
+
-->
|
|
14
|
+
<script lang="ts" module>
|
|
15
|
+
import type { RangeAnchor } from '../core/codec/index.js';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { Popover } from 'bits-ui';
|
|
20
|
+
import { spacePx } from '../core/rungs.js';
|
|
21
|
+
import { wording } from './strings.js';
|
|
22
|
+
import { reviewText } from './review.js';
|
|
23
|
+
import type { Review } from './review.svelte.js';
|
|
24
|
+
import './controls.css';
|
|
25
|
+
|
|
26
|
+
/** Where item `id` is drawn. */
|
|
27
|
+
export interface ReviewTarget {
|
|
28
|
+
/** What its card hangs off: a field's control, or a live measure of a mark in a leaf. */
|
|
29
|
+
anchor: Element | RangeAnchor;
|
|
30
|
+
/** The mark is the wedge that stands where text was only removed. */
|
|
31
|
+
removed: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface Props {
|
|
35
|
+
review: Review;
|
|
36
|
+
targetFor: (id: string) => ReviewTarget | undefined;
|
|
37
|
+
}
|
|
38
|
+
let { review, targetFor }: Props = $props();
|
|
39
|
+
|
|
40
|
+
const t = wording();
|
|
41
|
+
|
|
42
|
+
const shown = $derived(review.shown);
|
|
43
|
+
const target = $derived(shown ? targetFor(shown.item.id) : undefined);
|
|
44
|
+
const anchor = $derived(target?.anchor);
|
|
45
|
+
const open = $derived(!!shown && !!anchor);
|
|
46
|
+
const portalTarget = $derived.by(() => {
|
|
47
|
+
const el = anchor && 'contextElement' in anchor ? anchor.contextElement : anchor;
|
|
48
|
+
return el?.closest<HTMLElement>('[data-qm-root]') ?? undefined;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** What the card says: a lead word, and the old words or value where there were any. */
|
|
52
|
+
const said = $derived.by(() => {
|
|
53
|
+
if (!shown) return undefined;
|
|
54
|
+
const { item } = shown;
|
|
55
|
+
const s = t.strings;
|
|
56
|
+
if ('field' in item) {
|
|
57
|
+
const was = reviewText(item.before, { on: s.reviewOn, off: s.reviewOff });
|
|
58
|
+
return { lead: s.reviewWas, text: was || s.reviewEmpty, empty: !was };
|
|
59
|
+
}
|
|
60
|
+
const before = item.before ?? '';
|
|
61
|
+
if (target?.removed) return { lead: s.reviewRemoved, text: before, empty: false };
|
|
62
|
+
return before
|
|
63
|
+
? { lead: s.reviewWas, text: before, empty: false }
|
|
64
|
+
: { lead: s.reviewAdded, text: '', empty: false };
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function onScroll(): void {
|
|
68
|
+
if (review.shown?.via === 'pointer') review.dismiss();
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<svelte:document onscrollcapture={onScroll} />
|
|
73
|
+
|
|
74
|
+
<Popover.Root
|
|
75
|
+
{open}
|
|
76
|
+
onOpenChange={(next) => {
|
|
77
|
+
if (!next) review.dismiss();
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<Popover.Portal to={portalTarget}>
|
|
81
|
+
<Popover.Content
|
|
82
|
+
customAnchor={anchor ?? null}
|
|
83
|
+
collisionBoundary={portalTarget ?? []}
|
|
84
|
+
side="bottom"
|
|
85
|
+
align="start"
|
|
86
|
+
trapFocus={false}
|
|
87
|
+
hideWhenDetached
|
|
88
|
+
sideOffset={spacePx(portalTarget, 1)}
|
|
89
|
+
onOpenAutoFocus={(e: Event) => e.preventDefault()}
|
|
90
|
+
onCloseAutoFocus={(e: Event) => e.preventDefault()}
|
|
91
|
+
onInteractOutside={(e: Event) => {
|
|
92
|
+
// A press on the mark the card is up for is not a press away from it.
|
|
93
|
+
const id = review.shown?.item.id;
|
|
94
|
+
const on = e.target instanceof Element ? e.target.closest('[data-qm-review]') : null;
|
|
95
|
+
if (id !== undefined && on?.getAttribute('data-qm-review') === id) e.preventDefault();
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
{#snippet child({ props, wrapperProps, open: raised })}
|
|
99
|
+
<div {...wrapperProps}>
|
|
100
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
101
|
+
<!-- The handlers hold the card up while it is in use and add no interaction. -->
|
|
102
|
+
<div
|
|
103
|
+
{...props}
|
|
104
|
+
class="qm-review-card qm-popover-surface"
|
|
105
|
+
data-qm-root
|
|
106
|
+
role="group"
|
|
107
|
+
aria-label={t.strings.reviewChange}
|
|
108
|
+
inert={!raised}
|
|
109
|
+
onpointerenter={() => review.hold()}
|
|
110
|
+
onpointerleave={() => review.release()}
|
|
111
|
+
>
|
|
112
|
+
{#if said}
|
|
113
|
+
<span class="qm-review-said">
|
|
114
|
+
<span class="qm-review-lead">{said.lead}</span>
|
|
115
|
+
{#if said.text}
|
|
116
|
+
<span class={['qm-review-before', { 'qm-review-none': said.empty }]}
|
|
117
|
+
>{said.text}</span
|
|
118
|
+
>
|
|
119
|
+
{/if}
|
|
120
|
+
</span>
|
|
121
|
+
{/if}
|
|
122
|
+
<button
|
|
123
|
+
type="button"
|
|
124
|
+
class="qm-chip qm-review-undo qm-focus-ring"
|
|
125
|
+
title={t.strings.reviewUndoTitle}
|
|
126
|
+
onmousedown={(e) => e.preventDefault()}
|
|
127
|
+
onclick={() => shown && review.act(shown.item.id, 'reopen')}
|
|
128
|
+
>{t.strings.reviewUndo}</button
|
|
129
|
+
>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
{/snippet}
|
|
133
|
+
</Popover.Content>
|
|
134
|
+
</Popover.Portal>
|
|
135
|
+
</Popover.Root>
|
|
136
|
+
|
|
137
|
+
<style>
|
|
138
|
+
/* The lift, the translucency and the scale-in are `.qm-popover-surface`'s (controls.css).
|
|
139
|
+
A row: what was, then the way back, the button holding its place at the top of a card
|
|
140
|
+
whose old words wrap. The measure caps a long passage at a few lines, which is a
|
|
141
|
+
reminder of what stood there rather than a second copy of the page. */
|
|
142
|
+
.qm-review-card {
|
|
143
|
+
display: flex;
|
|
144
|
+
align-items: flex-start;
|
|
145
|
+
gap: var(--_qm-space-3);
|
|
146
|
+
max-width: min(24rem, 90vw);
|
|
147
|
+
padding: var(--_qm-space) var(--_qm-space) var(--_qm-space) var(--_qm-space-3);
|
|
148
|
+
font-size: var(--_qm-text-label);
|
|
149
|
+
line-height: var(--_qm-leading-tight);
|
|
150
|
+
color: var(--_qm-ink);
|
|
151
|
+
}
|
|
152
|
+
.qm-review-said {
|
|
153
|
+
display: -webkit-box;
|
|
154
|
+
-webkit-box-orient: vertical;
|
|
155
|
+
-webkit-line-clamp: 4;
|
|
156
|
+
line-clamp: 4;
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
min-width: 0;
|
|
159
|
+
/* The button's own height less this line's, halved: one line of words centres on it. */
|
|
160
|
+
padding-block: calc((var(--_qm-tap-min) - 1lh) / 2);
|
|
161
|
+
overflow-wrap: anywhere;
|
|
162
|
+
}
|
|
163
|
+
.qm-review-lead {
|
|
164
|
+
color: var(--_qm-ink-label);
|
|
165
|
+
}
|
|
166
|
+
.qm-review-before {
|
|
167
|
+
margin-inline-start: var(--_qm-space);
|
|
168
|
+
white-space: pre-wrap;
|
|
169
|
+
}
|
|
170
|
+
.qm-review-none {
|
|
171
|
+
color: var(--_qm-ink-label);
|
|
172
|
+
font-style: italic;
|
|
173
|
+
}
|
|
174
|
+
.qm-review-undo {
|
|
175
|
+
flex-shrink: 0;
|
|
176
|
+
font-weight: var(--_qm-weight-mid);
|
|
177
|
+
color: var(--_qm-ink);
|
|
178
|
+
}
|
|
179
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RangeAnchor } from '../core/codec/index.js';
|
|
2
|
+
import type { Review } from './review.svelte.js';
|
|
3
|
+
/** Where item `id` is drawn. */
|
|
4
|
+
export interface ReviewTarget {
|
|
5
|
+
/** What its card hangs off: a field's control, or a live measure of a mark in a leaf. */
|
|
6
|
+
anchor: Element | RangeAnchor;
|
|
7
|
+
/** The mark is the wedge that stands where text was only removed. */
|
|
8
|
+
removed: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface Props {
|
|
11
|
+
review: Review;
|
|
12
|
+
targetFor: (id: string) => ReviewTarget | undefined;
|
|
13
|
+
}
|
|
14
|
+
declare const ReviewPopover: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type ReviewPopover = ReturnType<typeof ReviewPopover>;
|
|
16
|
+
export default ReviewPopover;
|
|
@@ -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>
|