@quillmark/svelte 0.39.0 → 0.39.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.
- package/dist/core/codec/encode.d.ts +10 -0
- package/dist/core/codec/encode.js +101 -0
- package/dist/core/codec/field.js +36 -7
- package/dist/core/codec/index.d.ts +2 -1
- package/dist/core/codec/index.js +2 -1
- package/dist/visual/ProseValue.svelte +11 -1
- package/dist/visual/ReviewCard.svelte +25 -23
- package/dist/visual/ReviewCard.svelte.d.ts +1 -0
- package/dist/visual/VisualEditorInner.svelte +5 -5
- package/package.json +1 -1
|
@@ -41,3 +41,13 @@ export declare function pmToContent(doc: PMNode, anchors?: ContentAnchor[]): Con
|
|
|
41
41
|
* not hold for placeholders (`field.ts`).
|
|
42
42
|
*/
|
|
43
43
|
export declare function lower(oldRt: Content, newRt: Content): Change | null;
|
|
44
|
+
/**
|
|
45
|
+
* The one splice taking `oldRt` to `newRt` where the two differ only in the text of one block
|
|
46
|
+
* and the formatting of what it inserts, or `null`: built here rather than by the store's `diff`,
|
|
47
|
+
* which reads both values whole across the boundary. Exact or absent, never a guess: the value the
|
|
48
|
+
* splice leaves, the store's marks cut at the edit and the insert's own merged back, is checked
|
|
49
|
+
* equal to `newRt`, so a caller that holds `newRt` as the stored value after the write holds it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function spliceOf(oldRt: Content, newRt: Content): Change | null;
|
|
52
|
+
/** Whether `receipt`'s normalized change is `change`, a {@link spliceOf}, as it was sent. */
|
|
53
|
+
export declare function landedAsSent(applied: Change, change: Change): boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { core } from '../lifecycle.js';
|
|
2
2
|
import { HARD_BREAK, ISLAND_SLOT, islandEntryFromNode } from './islands.js';
|
|
3
3
|
import { contentDescriptorFromPM, markKey } from './marks.js';
|
|
4
|
+
import { valueEqual } from './reconcile.js';
|
|
4
5
|
function idsOf(doc) {
|
|
5
6
|
const next = new Map();
|
|
6
7
|
doc.descendants((node) => {
|
|
@@ -244,3 +245,103 @@ export function lower(oldRt, newRt) {
|
|
|
244
245
|
const change = core().diff(oldRt, newRt);
|
|
245
246
|
return change.steps.length ? change : null;
|
|
246
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* The one splice taking `oldRt` to `newRt` where the two differ only in the text of one block
|
|
250
|
+
* and the formatting of what it inserts, or `null`: built here rather than by the store's `diff`,
|
|
251
|
+
* which reads both values whole across the boundary. Exact or absent, never a guess: the value the
|
|
252
|
+
* splice leaves, the store's marks cut at the edit and the insert's own merged back, is checked
|
|
253
|
+
* equal to `newRt`, so a caller that holds `newRt` as the stored value after the write holds it.
|
|
254
|
+
*/
|
|
255
|
+
export function spliceOf(oldRt, newRt) {
|
|
256
|
+
const a = oldRt.text;
|
|
257
|
+
const b = newRt.text;
|
|
258
|
+
if (a === b)
|
|
259
|
+
return null;
|
|
260
|
+
if (oldRt.codec !== newRt.codec ||
|
|
261
|
+
!valueEqual(oldRt.blocks, newRt.blocks) ||
|
|
262
|
+
!valueEqual(oldRt.containers ?? [], newRt.containers ?? []) ||
|
|
263
|
+
!valueEqual(oldRt.islands ?? [], newRt.islands ?? []))
|
|
264
|
+
return null;
|
|
265
|
+
const short = Math.min(a.length, b.length);
|
|
266
|
+
let at = 0;
|
|
267
|
+
while (at < short && a.charCodeAt(at) === b.charCodeAt(at))
|
|
268
|
+
at++;
|
|
269
|
+
let tail = 0;
|
|
270
|
+
while (tail < short - at &&
|
|
271
|
+
a.charCodeAt(a.length - 1 - tail) === b.charCodeAt(b.length - 1 - tail))
|
|
272
|
+
tail++;
|
|
273
|
+
if (splitsPair(a, at) || splitsPair(a, a.length - tail))
|
|
274
|
+
return null;
|
|
275
|
+
const del = a.slice(at, a.length - tail);
|
|
276
|
+
const insert = b.slice(at, b.length - tail);
|
|
277
|
+
if (breaksText(del) || breaksText(insert))
|
|
278
|
+
return null;
|
|
279
|
+
const end = at + del.length;
|
|
280
|
+
const shift = insert.length - del.length;
|
|
281
|
+
const before = oldRt.marks ?? [];
|
|
282
|
+
const after = newRt.marks ?? [];
|
|
283
|
+
if (before.some(isExtMark) || after.some(isExtMark))
|
|
284
|
+
return null;
|
|
285
|
+
const carried = [];
|
|
286
|
+
for (const m of before) {
|
|
287
|
+
if (m.start < at)
|
|
288
|
+
carried.push({ ...m, end: Math.min(m.end, at) });
|
|
289
|
+
if (m.end > end)
|
|
290
|
+
carried.push({ ...m, start: Math.max(m.start, end) + shift, end: m.end + shift });
|
|
291
|
+
}
|
|
292
|
+
const own = [];
|
|
293
|
+
for (const m of after) {
|
|
294
|
+
const lo = Math.max(m.start, at);
|
|
295
|
+
const hi = Math.min(m.end, at + insert.length);
|
|
296
|
+
if (lo < hi)
|
|
297
|
+
own.push({ ...m, start: lo, end: hi });
|
|
298
|
+
}
|
|
299
|
+
if (!valueEqual(mergeMarks([...carried, ...own]), after))
|
|
300
|
+
return null;
|
|
301
|
+
const anchors = [];
|
|
302
|
+
for (const x of oldRt.anchors ?? []) {
|
|
303
|
+
if ((x.start >= at && x.start <= end) || (x.end >= at && x.end <= end))
|
|
304
|
+
return null;
|
|
305
|
+
anchors.push(x.start > end
|
|
306
|
+
? { ...x, start: x.start + shift, end: x.end + shift }
|
|
307
|
+
: x.end > end
|
|
308
|
+
? { ...x, end: x.end + shift }
|
|
309
|
+
: x);
|
|
310
|
+
}
|
|
311
|
+
if (!valueEqual(anchors, newRt.anchors ?? []))
|
|
312
|
+
return null;
|
|
313
|
+
const marks = own.map((m) => ({ ...m, start: m.start - at, end: m.end - at }));
|
|
314
|
+
const step = { at, insert };
|
|
315
|
+
if (del)
|
|
316
|
+
step.delete = del;
|
|
317
|
+
if (marks.length)
|
|
318
|
+
step.marks = marks;
|
|
319
|
+
return { steps: [{ splice: step }] };
|
|
320
|
+
}
|
|
321
|
+
/** Whether `receipt`'s normalized change is `change`, a {@link spliceOf}, as it was sent. */
|
|
322
|
+
export function landedAsSent(applied, change) {
|
|
323
|
+
const [sent] = change.steps;
|
|
324
|
+
const [got] = applied.steps;
|
|
325
|
+
if (applied.steps.length !== 1 || !('splice' in got) || !('splice' in sent))
|
|
326
|
+
return false;
|
|
327
|
+
const s = sent.splice;
|
|
328
|
+
const g = got.splice;
|
|
329
|
+
return (g.at === s.at &&
|
|
330
|
+
(g.delete ?? '') === (s.delete ?? '') &&
|
|
331
|
+
g.insert === s.insert &&
|
|
332
|
+
valueEqual(g.marks ?? [], s.marks ?? []));
|
|
333
|
+
}
|
|
334
|
+
/** Whether offset `i` of `s` falls between the halves of a surrogate pair. */
|
|
335
|
+
function splitsPair(s, i) {
|
|
336
|
+
if (i <= 0 || i >= s.length)
|
|
337
|
+
return false;
|
|
338
|
+
const lo = s.charCodeAt(i);
|
|
339
|
+
return lo >= 0xdc00 && lo <= 0xdfff;
|
|
340
|
+
}
|
|
341
|
+
/** Whether `s` holds a character that ends a block or a line, or stands for an island. */
|
|
342
|
+
function breaksText(s) {
|
|
343
|
+
return s.includes('\n') || s.includes(HARD_BREAK) || s.includes(ISLAND_SLOT);
|
|
344
|
+
}
|
|
345
|
+
function isExtMark(m) {
|
|
346
|
+
return m.type.startsWith('x-');
|
|
347
|
+
}
|
package/dist/core/codec/field.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// The prose leaf: `createField` (INVARIANTS §Surface). One content field, one PM view wired to
|
|
2
2
|
// the WASM edit surface.
|
|
3
3
|
//
|
|
4
|
-
// `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (one
|
|
5
|
+
// splice against the last write's hash for a text edit inside one block, or `replace` for a field
|
|
6
|
+
// not yet at content rest, which has nothing to change), commits via `doc.apply` (a `text` leaf's
|
|
7
|
+
// whole text through the typed writer), then fires `onChange` if it committed and `onCaretMove`.
|
|
8
|
+
// A throw keeps the optimistic PM state and reports through `onError`.
|
|
8
9
|
// An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
|
|
9
10
|
// hold it re-evaluates flips.
|
|
10
11
|
import { baseKeymap } from 'prosemirror-commands';
|
|
@@ -20,7 +21,7 @@ import { tooltips } from '../tooltip.js';
|
|
|
20
21
|
import { reportError, errorMessage } from '../errors.js';
|
|
21
22
|
import { decode, fitsLeaf } from './decode.js';
|
|
22
23
|
import { offsetToPM, pmToOffset, buildLineIndex, lineIndexOf, mapThroughDelta } from './positions.js';
|
|
23
|
-
import { lower, pmToContent, scanContent, scanDoc } from './encode.js';
|
|
24
|
+
import { landedAsSent, lower, pmToContent, scanContent, scanDoc, spliceOf } from './encode.js';
|
|
24
25
|
import { capPlugin } from './cap.js';
|
|
25
26
|
import { islandPastePlugin } from './islands.js';
|
|
26
27
|
import { anchorsFromContent } from './marks.js';
|
|
@@ -252,6 +253,9 @@ export function createField(opts) {
|
|
|
252
253
|
// `known` is the codec's view of what the leaf holds: kept in sync after every
|
|
253
254
|
// own-edit so `reconcile` can tell an external change from the field's own.
|
|
254
255
|
const reconciler = createReconciler(shown());
|
|
256
|
+
/** The hash the leaf's own last write left on the field, while `reconciler.last` is that value:
|
|
257
|
+
* the base a splice commits against. */
|
|
258
|
+
let base;
|
|
255
259
|
let index; // rebuilt on every structural change
|
|
256
260
|
let view;
|
|
257
261
|
// The ghost's live cell: the ghost plugin reads it per pass, so moving it is an
|
|
@@ -472,16 +476,19 @@ export function createField(opts) {
|
|
|
472
476
|
return commitUnset();
|
|
473
477
|
if (plaintext)
|
|
474
478
|
return commitPlain(literalOf(newRt));
|
|
479
|
+
if (commitSplice(at, oldRt, newRt))
|
|
480
|
+
return true;
|
|
481
|
+
base = undefined;
|
|
475
482
|
try {
|
|
476
483
|
// Only a field not yet at content rest replaces by choice: neither an absent declared
|
|
477
484
|
// field nor an authored string has anchors to lose (`changeCommittable`).
|
|
478
485
|
if (!changeCommittable(doc, addr))
|
|
479
|
-
doc.replace(at, newRt);
|
|
486
|
+
base = doc.replace(at, newRt).hash;
|
|
480
487
|
else {
|
|
481
488
|
const change = lower(oldRt, newRt);
|
|
482
489
|
if (change) {
|
|
483
490
|
const asked = askCore(oldRt, change);
|
|
484
|
-
doc.apply(at, change);
|
|
491
|
+
base = doc.apply(at, change).hash;
|
|
485
492
|
if (asked.size || change.steps.some((step) => 'setBlock' in step))
|
|
486
493
|
adopt();
|
|
487
494
|
}
|
|
@@ -516,6 +523,28 @@ export function createField(opts) {
|
|
|
516
523
|
}
|
|
517
524
|
}
|
|
518
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* A text edit inside one block, committed as the one splice it is and against the hash of the
|
|
528
|
+
* value the reconciler holds, so neither side is read or sent whole. A store written since that
|
|
529
|
+
* hash refuses the base, and the commit takes the diff path. Whether it landed.
|
|
530
|
+
*/
|
|
531
|
+
function commitSplice(at, oldRt, newRt) {
|
|
532
|
+
if (base === undefined)
|
|
533
|
+
return false;
|
|
534
|
+
const change = spliceOf(oldRt, newRt);
|
|
535
|
+
if (!change)
|
|
536
|
+
return false;
|
|
537
|
+
let receipt;
|
|
538
|
+
try {
|
|
539
|
+
receipt = doc.apply(at, change, { base });
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
base = receipt.hash;
|
|
545
|
+
reconciler.commit(landedAsSent(receipt.applied, change) ? newRt : readLeaf(reader, addr));
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
519
548
|
/**
|
|
520
549
|
* Each block id the projection minted for a block the store does not hold, swapped in
|
|
521
550
|
* `change` for a placeholder the write fills, so the store is the one minter of block ids:
|
|
@@ -13,7 +13,8 @@ export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
|
13
13
|
export type { LeaveStrings } from './leave.js';
|
|
14
14
|
export type { BlockPlace, LeafUndrawn, ReviewAction, ReviewReport, TextReview } from './review.js';
|
|
15
15
|
export { wordDiff } from './review-diff.js';
|
|
16
|
-
export { valueDiffPlugin } from './value-diff.js';
|
|
16
|
+
export { valueDiffPlugin, valueSpans } from './value-diff.js';
|
|
17
|
+
export { reviewCaretPlugin } from './review-caret.js';
|
|
17
18
|
export type { ValueProposal, ValueState } from './value-diff.js';
|
|
18
19
|
export { asContent, planValue, valueChanges } from './value-plan.js';
|
|
19
20
|
export type { ValuePlan, ValueChange } from './value-plan.js';
|
package/dist/core/codec/index.js
CHANGED
|
@@ -26,7 +26,8 @@ export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
|
26
26
|
// the visual tier's `strings` set its wording.
|
|
27
27
|
export { DEFAULT_LEAVE_STRINGS } from './leave.js';
|
|
28
28
|
export { wordDiff } from './review-diff.js';
|
|
29
|
-
export { valueDiffPlugin } from './value-diff.js';
|
|
29
|
+
export { valueDiffPlugin, valueSpans } from './value-diff.js';
|
|
30
|
+
export { reviewCaretPlugin } from './review-caret.js';
|
|
30
31
|
export { asContent, planValue, valueChanges } from './value-plan.js';
|
|
31
32
|
// The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
|
|
32
33
|
// the visual tier's `strings` set extends their wording, and the formatting popover binds its
|
|
@@ -69,6 +69,8 @@
|
|
|
69
69
|
offsetToPM,
|
|
70
70
|
valueEqual,
|
|
71
71
|
valueDiffPlugin,
|
|
72
|
+
valueSpans,
|
|
73
|
+
reviewCaretPlugin,
|
|
72
74
|
type ValueProposal,
|
|
73
75
|
type LeafViews,
|
|
74
76
|
type TextCap
|
|
@@ -167,6 +169,13 @@
|
|
|
167
169
|
drawnProposals = (proposed ?? []).map((p) => ({ ...p, lit: reviewing.lit === p.id }));
|
|
168
170
|
redraw?.();
|
|
169
171
|
});
|
|
172
|
+
/** The caret names a proposal it arrives at, as a field's own leaf's does (`review-caret.ts`). */
|
|
173
|
+
const reviewCaret = reviewCaretPlugin({
|
|
174
|
+
spans: (state) => valueSpans(state, drawnProposals),
|
|
175
|
+
entered: () => undefined,
|
|
176
|
+
litHere: () => drawnProposals.some((p) => p.lit),
|
|
177
|
+
point: (id) => reviewing.point(id)
|
|
178
|
+
});
|
|
170
179
|
/** A proposal's plan goes when it leaves the list or the leaf goes, not when another in the
|
|
171
180
|
* list is answered, which would leave its own Accept writing its value whole. */
|
|
172
181
|
let plannedIds: readonly string[] = [];
|
|
@@ -303,7 +312,8 @@
|
|
|
303
312
|
valueDiffPlugin(
|
|
304
313
|
() => drawnProposals,
|
|
305
314
|
(id, state) => reviewing.planned(id, state)
|
|
306
|
-
)
|
|
315
|
+
),
|
|
316
|
+
reviewCaret
|
|
307
317
|
]
|
|
308
318
|
})
|
|
309
319
|
});
|
|
@@ -9,16 +9,17 @@
|
|
|
9
9
|
It sits under the block the change flows in, so it covers no line of its paragraph, or beside
|
|
10
10
|
that block's last line where the line ends short of it, centred on a block of one line such as a
|
|
11
11
|
one-line field's, right-aligned to the column the
|
|
12
|
-
change stands in, and
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
change stands in, and never above it: a card that turns over the text as a scroll runs short
|
|
13
|
+
of room moves under the pointer about to answer. Its room under the change is what a step
|
|
14
|
+
scrolls for, and the host's chrome at the pane's foot (`inset`) is kept clear. The column is
|
|
15
|
+
the card's body or its form whole, never the one field, so Accept stands at one edge from
|
|
16
|
+
change to change and a pointer answering a run of them does not hunt for it. A field or a
|
|
17
|
+
property sharing its row with others takes the card beside its line only where the card
|
|
18
|
+
stands within its own slot, and under the row otherwise: beside the line of one that ends
|
|
19
|
+
short of the column's edge the card covers the value of the next. Over a change too tall for
|
|
20
|
+
the pane to show with its card it stays pinned at the foot while any of the change shows. A
|
|
21
|
+
change out of the pane keeps its card where it would stand beside it, so the card scrolls out
|
|
22
|
+
with the text and the pane's edge clips it as it clips the text.
|
|
22
23
|
A change is several elements (struck runs, tinted widgets, added blocks, a row
|
|
23
24
|
under a control, a card's mark), so the box is their union, read anew on each measure: a leaf
|
|
24
25
|
redraws its decorations as it likes, and a box measured once parts from the text it stood on.
|
|
@@ -59,6 +60,8 @@
|
|
|
59
60
|
let left = $state(0);
|
|
60
61
|
/** Pinned at the pane's foot, where every scroll moves it, so it follows without a glide. */
|
|
61
62
|
let pinned = $state(false);
|
|
63
|
+
/** The whole card stands in the pane, clear of the host's chrome at its foot. */
|
|
64
|
+
let stands = false;
|
|
62
65
|
/** The change is drawn, so the card has somewhere to stand. */
|
|
63
66
|
let placed = $state(false);
|
|
64
67
|
/** Where the focus was when the keyboard entered the card, to hand it back. */
|
|
@@ -124,21 +127,12 @@
|
|
|
124
127
|
const slot = last?.closest('.qm-object-prop, .qm-field')?.getBoundingClientRect();
|
|
125
128
|
const beside = tuck && tuck.right + gap <= left && (!slot || left + w <= slot.right + 1);
|
|
126
129
|
const below = beside ? tuck.top : lower + gap;
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
const y =
|
|
130
|
-
|
|
131
|
-
? below
|
|
132
|
-
: above >= ceil
|
|
133
|
-
? above
|
|
134
|
-
: !shows
|
|
135
|
-
? upper > floor
|
|
136
|
-
? above
|
|
137
|
-
: below
|
|
138
|
-
: Math.max(ceil, Math.min(floor - h, below));
|
|
130
|
+
const tall = lower - upper + gap + h > floor - ceil;
|
|
131
|
+
pinned = shows && tall && below + h > floor;
|
|
132
|
+
const y = pinned ? Math.max(ceil, floor - h) : below;
|
|
133
|
+
stands = shows && y >= ceil && y + h <= floor;
|
|
139
134
|
top = y - at.top + (root?.scrollTop ?? 0);
|
|
140
135
|
left = left - at.left + (root?.scrollLeft ?? 0);
|
|
141
|
-
pinned = shows && !fits;
|
|
142
136
|
placed = true;
|
|
143
137
|
}
|
|
144
138
|
|
|
@@ -221,6 +215,14 @@
|
|
|
221
215
|
attributeFilter: ['data-qm-review', 'class', 'open', 'hidden']
|
|
222
216
|
};
|
|
223
217
|
|
|
218
|
+
/** Whether the card stands whole in the pane where the change now is: an answer key answers
|
|
219
|
+
* only a change whose card the reader can see. A change with no box measures nothing, and
|
|
220
|
+
* counts as shown. */
|
|
221
|
+
export function standsInView(): boolean {
|
|
222
|
+
place();
|
|
223
|
+
return !placed || stands;
|
|
224
|
+
}
|
|
225
|
+
|
|
224
226
|
/** Put the focus on Accept, handing it back to where it was on Escape or an answer. False
|
|
225
227
|
* with no card on show. */
|
|
226
228
|
export async function enter(): Promise<boolean> {
|
|
@@ -14,6 +14,7 @@ interface Props {
|
|
|
14
14
|
onAnswer(action: 'accept' | 'dismiss'): void;
|
|
15
15
|
}
|
|
16
16
|
declare const ReviewCard: import("svelte").Component<Props, {
|
|
17
|
+
standsInView: () => boolean;
|
|
17
18
|
enter: () => Promise<boolean>;
|
|
18
19
|
}, "">;
|
|
19
20
|
type ReviewCard = ReturnType<typeof ReviewCard>;
|
|
@@ -661,15 +661,15 @@
|
|
|
661
661
|
const id = reviewing.lit;
|
|
662
662
|
return id !== undefined && answerReview([id], action).length > 0;
|
|
663
663
|
}
|
|
664
|
-
/** An answer key: the card's, so it answers only a change
|
|
665
|
-
* press while the reader types in the editor is the leaf's own key, and any other press
|
|
666
|
-
* with the change out of view or the card out of the way brings both back. */
|
|
664
|
+
/** An answer key: the card's, so it answers only a change whose card stands whole in view.
|
|
665
|
+
* A press while the reader types in the editor is the leaf's own key, and any other press
|
|
666
|
+
* with the change or its card out of view, or the card out of the way, brings both back. */
|
|
667
667
|
function answerByKey(action: 'accept' | 'dismiss'): boolean {
|
|
668
668
|
const id = reviewing.lit;
|
|
669
669
|
if (id === undefined || (typing && inside)) return false;
|
|
670
|
-
if (!typing && inView(id)) return answerCurrent(action);
|
|
670
|
+
if (!typing && inView(id) && (answerCard?.standsInView() ?? true)) return answerCurrent(action);
|
|
671
671
|
typing = false;
|
|
672
|
-
void reveal(id, false,
|
|
672
|
+
void reveal(id, false, false);
|
|
673
673
|
return true;
|
|
674
674
|
}
|
|
675
675
|
/** Whether a key at `target` is the review's: anywhere but a text control outside the editor,
|