@quillmark/svelte 0.29.3 → 0.30.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 +1 -1
- package/dist/core/address.d.ts +3 -3
- package/dist/core/address.js +1 -1
- package/dist/core/codec/decode.d.ts +1 -3
- package/dist/core/codec/decode.js +145 -206
- package/dist/core/codec/encode.d.ts +13 -35
- package/dist/core/codec/encode.js +127 -408
- package/dist/core/codec/field.d.ts +9 -9
- package/dist/core/codec/field.js +85 -76
- package/dist/core/codec/index.d.ts +2 -2
- package/dist/core/codec/index.js +4 -4
- package/dist/core/codec/islands.d.ts +13 -9
- package/dist/core/codec/islands.js +54 -49
- package/dist/core/codec/marks.d.ts +12 -18
- package/dist/core/codec/marks.js +16 -26
- package/dist/core/codec/positions.d.ts +14 -7
- package/dist/core/codec/positions.js +43 -50
- package/dist/core/codec/schema.d.ts +1 -1
- package/dist/core/codec/schema.js +26 -8
- package/dist/core/codec/slash.js +2 -2
- package/dist/core/codec/table-copy.d.ts +3 -3
- package/dist/core/codec/table-copy.js +6 -4
- package/dist/core/codec/table-paste.js +13 -9
- package/dist/core/codec/table-view.js +19 -12
- package/dist/core/codec/table.d.ts +77 -43
- package/dist/core/codec/table.js +157 -48
- package/dist/visual/ArrayField.svelte +1 -1
- package/dist/visual/FormatPopover.svelte +1 -1
- package/dist/visual/ProseValue.svelte +8 -8
- package/dist/visual/VisualEditorInner.svelte +17 -11
- package/dist/visual/leaves.d.ts +1 -1
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/structure.js +1 -10
- package/package.json +2 -2
|
@@ -80,7 +80,7 @@ export interface CreateFieldOpts {
|
|
|
80
80
|
* unanswered `none` is what the empty leaf draws and an empty answer would hide. */
|
|
81
81
|
emptyUnsets?: boolean;
|
|
82
82
|
onFocus?(addr: Addr): void;
|
|
83
|
-
/** Fired with the new
|
|
83
|
+
/** Fired with the new caret offset after an edit or a selection move. */
|
|
84
84
|
onCaretMove?(addr: Addr, pos: number): void;
|
|
85
85
|
/**
|
|
86
86
|
* Fired after an edit committed to the document: the leaf's change signal. Unlike `onCaretMove`
|
|
@@ -97,7 +97,7 @@ export interface FieldController {
|
|
|
97
97
|
/** The mounted `container`: the leaf's element, for a caller that has to reach the
|
|
98
98
|
* DOM the view sits in (the arrival wash, `core/bloom.ts`) rather than re-find it. */
|
|
99
99
|
readonly el: HTMLElement;
|
|
100
|
-
/** Place the caret at
|
|
100
|
+
/** Place the caret at content offset `pos` (preview onPick → offsetToPM → here). */
|
|
101
101
|
setCaret(pos: number): void;
|
|
102
102
|
/**
|
|
103
103
|
* External content change → re-hydrate this leaf (gated by reconcile), and re-evaluate its
|
|
@@ -119,14 +119,14 @@ export interface FieldController {
|
|
|
119
119
|
/** The current stored content for this addr (for tests / reconcile). */
|
|
120
120
|
getContent(): Content;
|
|
121
121
|
/**
|
|
122
|
-
* Insert an identity anchor `id`
|
|
123
|
-
* set and commits
|
|
124
|
-
* unique and invariant; a duplicate id is a no-op.
|
|
122
|
+
* Insert an identity anchor `id` over content offsets `[pos, end)`, a point where `end` is
|
|
123
|
+
* absent. It folds into the plugin's set and commits with the next change. The id is
|
|
124
|
+
* caller-supplied and must be unique and invariant; a duplicate id is a no-op.
|
|
125
125
|
*/
|
|
126
|
-
insertAnchor(id: string, pos: number): void;
|
|
126
|
+
insertAnchor(id: string, pos: number, end?: number): void;
|
|
127
127
|
/** Remove the identity anchor `id` (the inverse of {@link insertAnchor}); a no-op if absent. */
|
|
128
128
|
removeAnchor(id: string): void;
|
|
129
|
-
/** Ids of the anchors
|
|
129
|
+
/** Ids of the anchors touching content range `[from, to]`: a selection's anchor state. */
|
|
130
130
|
anchorsInRange(from: number, to: number): string[];
|
|
131
131
|
/**
|
|
132
132
|
* Move the slash menu's cursor onto the command `name` (a pointer entering an item): the
|
|
@@ -136,7 +136,7 @@ export interface FieldController {
|
|
|
136
136
|
/** Run the command `name` (a click on its item): the same path Enter takes. A no-op
|
|
137
137
|
* with no menu open, which is the state a stale click lands in. */
|
|
138
138
|
slashPick(name: string): void;
|
|
139
|
-
/** The current PM selection as a
|
|
139
|
+
/** The current PM selection as a content `{ from, to }` range (the boundary currency). */
|
|
140
140
|
selectionRange(): {
|
|
141
141
|
from: number;
|
|
142
142
|
to: number;
|
|
@@ -156,7 +156,7 @@ export interface LeafViews {
|
|
|
156
156
|
/** Every view nested inside this leaf, in mount order: one per table cell. */
|
|
157
157
|
nestedViews(): EditorView[];
|
|
158
158
|
}
|
|
159
|
-
/** The canonical empty `Content`: one empty `para`
|
|
159
|
+
/** The canonical empty `Content`: one empty `para` block. */
|
|
160
160
|
export declare function emptyContent(): Content;
|
|
161
161
|
/** Whether `rt` is the empty leaf: {@link emptyContent}, nothing typed and no shape left. */
|
|
162
162
|
export declare function isEmptyContent(rt: Content): boolean;
|
package/dist/core/codec/field.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// The prose leaf: `createField` (VISUAL_EDITOR §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 `
|
|
5
|
-
// `
|
|
6
|
-
// `doc.
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
4
|
+
// `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (or
|
|
5
|
+
// `replace` for a field not yet at content rest, which has nothing to change), commits via
|
|
6
|
+
// `doc.apply` (a `text` leaf's whole text through the typed writer), then fires `onChange` if it
|
|
7
|
+
// committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through `onError`.
|
|
8
|
+
// An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
|
|
9
|
+
// hold it re-evaluates flips.
|
|
10
10
|
import { baseKeymap, toggleMark } from 'prosemirror-commands';
|
|
11
11
|
import { gapCursor } from 'prosemirror-gapcursor';
|
|
12
12
|
import { history, redo, undo } from 'prosemirror-history';
|
|
@@ -18,10 +18,10 @@ import { revealProps } from './reveal.js';
|
|
|
18
18
|
import { core } from '../lifecycle.js';
|
|
19
19
|
import { reportError, errorMessage } from '../errors.js';
|
|
20
20
|
import { decode, fitsLeaf } from './decode.js';
|
|
21
|
-
import {
|
|
22
|
-
import { lower, pmToContent, scanContent, scanDoc
|
|
21
|
+
import { offsetToPM, pmToOffset, buildLineIndex, lineIndexOf, mapThroughDelta } from './positions.js';
|
|
22
|
+
import { lower, pmToContent, scanContent, scanDoc } from './encode.js';
|
|
23
23
|
import { capPlugin } from './cap.js';
|
|
24
|
-
import { islandPastePlugin } from './islands.js';
|
|
24
|
+
import { HARD_BREAK, islandPastePlugin } from './islands.js';
|
|
25
25
|
import { anchorsFromContent } from './marks.js';
|
|
26
26
|
import { contentEqual, createReconciler } from './reconcile.js';
|
|
27
27
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
@@ -42,12 +42,12 @@ import { taskPlugin } from './tasks.js';
|
|
|
42
42
|
import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
|
|
43
43
|
import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
|
|
44
44
|
const anchorKey = new PluginKey('quill-anchors');
|
|
45
|
-
/**
|
|
46
|
-
* and mutated by an {@link
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Plugin-held anchors (PM coords), mapped through every edit's `StepMap` and mutated by an {@link
|
|
47
|
+
* AnchorEdit} meta. The store's rule, so the commit has nothing to reconcile: a range keeps its
|
|
48
|
+
* edges, text typed at either landing outside it, and a point stays left of text typed at it. A
|
|
49
|
+
* range whose text is wholly deleted goes; a point never does.
|
|
50
|
+
*/
|
|
51
51
|
function anchorPlugin(seed) {
|
|
52
52
|
return new Plugin({
|
|
53
53
|
key: anchorKey,
|
|
@@ -55,11 +55,19 @@ function anchorPlugin(seed) {
|
|
|
55
55
|
init: () => seed,
|
|
56
56
|
apply: (tr, anchors) => {
|
|
57
57
|
let next = tr.docChanged
|
|
58
|
-
? anchors.
|
|
58
|
+
? anchors.flatMap((a) => {
|
|
59
|
+
if (a.start === a.end) {
|
|
60
|
+
const at = tr.mapping.map(a.start, -1);
|
|
61
|
+
return [{ id: a.id, start: at, end: at }];
|
|
62
|
+
}
|
|
63
|
+
const start = tr.mapping.map(a.start, 1);
|
|
64
|
+
const end = tr.mapping.map(a.end, -1);
|
|
65
|
+
return start < end ? [{ id: a.id, start, end }] : [];
|
|
66
|
+
})
|
|
59
67
|
: anchors;
|
|
60
68
|
const edit = tr.getMeta(anchorKey);
|
|
61
69
|
if (edit?.op === 'add')
|
|
62
|
-
next = [...next, { id: edit.id,
|
|
70
|
+
next = [...next, { id: edit.id, start: edit.start, end: edit.end }];
|
|
63
71
|
else if (edit?.op === 'remove')
|
|
64
72
|
next = next.filter((a) => a.id !== edit.id);
|
|
65
73
|
else if (edit?.op === 'reset')
|
|
@@ -69,6 +77,10 @@ function anchorPlugin(seed) {
|
|
|
69
77
|
}
|
|
70
78
|
});
|
|
71
79
|
}
|
|
80
|
+
/** An anchor in content offsets at its PM positions over `index`. */
|
|
81
|
+
function toPM(index, a) {
|
|
82
|
+
return { id: a.id, start: offsetToPM(index, a.start), end: offsetToPM(index, a.end) };
|
|
83
|
+
}
|
|
72
84
|
/**
|
|
73
85
|
* Read the leaf's `Content` for `addr` through `reader.getContent` (DOCUMENT_MODEL): the body when
|
|
74
86
|
* `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
|
|
@@ -80,21 +92,27 @@ function anchorPlugin(seed) {
|
|
|
80
92
|
function readLeaf(reader, addr) {
|
|
81
93
|
return reader.getContent(addr) ?? emptyContent();
|
|
82
94
|
}
|
|
83
|
-
/**
|
|
95
|
+
/** `addr` as a content write takes it: a card named by its `$id`, which a write requires. */
|
|
96
|
+
function writeAddr(doc, addr) {
|
|
97
|
+
if (typeof addr.card !== 'number')
|
|
98
|
+
return addr;
|
|
99
|
+
return { ...addr, card: doc.card(addr.card).id ?? addr.card };
|
|
100
|
+
}
|
|
101
|
+
/** The canonical empty `Content`: one empty `para` block. */
|
|
84
102
|
export function emptyContent() {
|
|
85
|
-
return { text: '',
|
|
103
|
+
return { text: '', blocks: [{ id: 'b0', kind: 'para' }] };
|
|
86
104
|
}
|
|
87
105
|
/** Whether `rt` is the empty leaf: {@link emptyContent}, nothing typed and no shape left. */
|
|
88
106
|
export function isEmptyContent(rt) {
|
|
89
107
|
return contentEqual(rt, emptyContent());
|
|
90
108
|
}
|
|
91
109
|
/**
|
|
92
|
-
* Whether
|
|
93
|
-
* exactly what PM shows. The other rest forms take `
|
|
94
|
-
*
|
|
95
|
-
*
|
|
110
|
+
* Whether a change may commit here: the stored value is a `Content` object, so `apply` changes
|
|
111
|
+
* exactly what PM shows. The other rest forms take `replace`: an unset field has nothing to change,
|
|
112
|
+
* and an authored string carries no anchors to pay. A body always rests as `Content`; a `text` leaf
|
|
113
|
+
* commits through the writer ({@link createField}).
|
|
96
114
|
*/
|
|
97
|
-
function
|
|
115
|
+
function changeCommittable(doc, addr) {
|
|
98
116
|
const stored = doc.getStored(addr);
|
|
99
117
|
return stored !== null && typeof stored === 'object';
|
|
100
118
|
}
|
|
@@ -213,12 +231,13 @@ export function createField(opts) {
|
|
|
213
231
|
// (`docChanged` false), so the `anchorKey` meta routes it.
|
|
214
232
|
if (!held && (tr.docChanged || tr.getMeta(anchorKey))) {
|
|
215
233
|
// (d) the change signal, only for what actually landed.
|
|
216
|
-
const
|
|
234
|
+
const anchors = plaintext ? [] : readAnchors();
|
|
235
|
+
const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
|
|
217
236
|
if (commitEdit(oldRt, newRt))
|
|
218
237
|
opts.onChange?.(addr);
|
|
219
238
|
}
|
|
220
239
|
// The caret, for structural and selection-only changes, reported after the commit.
|
|
221
|
-
opts.onCaretMove?.(addr,
|
|
240
|
+
opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
|
|
222
241
|
},
|
|
223
242
|
handleDOMEvents: {
|
|
224
243
|
focus: () => {
|
|
@@ -243,10 +262,7 @@ export function createField(opts) {
|
|
|
243
262
|
const anchors = plaintext ? [] : anchorsFromContent(rt);
|
|
244
263
|
// Seed anchor plugin positions in PM coords via a fresh index over pmDoc.
|
|
245
264
|
const seedIndex = buildLineIndex(pmDoc);
|
|
246
|
-
const seededAnchors = anchors.map((a) => (
|
|
247
|
-
id: a.id,
|
|
248
|
-
pos: usvToPM(seedIndex, a.pos)
|
|
249
|
-
}));
|
|
265
|
+
const seededAnchors = anchors.map((a) => toPM(seedIndex, a));
|
|
250
266
|
const built = EditorState.create({
|
|
251
267
|
doc: pmDoc,
|
|
252
268
|
plugins: proseLeafPlugins(schema, {
|
|
@@ -264,45 +280,40 @@ export function createField(opts) {
|
|
|
264
280
|
});
|
|
265
281
|
return { state: built, index: seedIndex };
|
|
266
282
|
}
|
|
267
|
-
// (b)+(c): lower the edit to
|
|
283
|
+
// (b)+(c): lower the edit to a change and commit, or `replace` a field not yet at content rest.
|
|
268
284
|
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
269
285
|
// branch ran.
|
|
270
286
|
function commitEdit(oldRt, newRt) {
|
|
287
|
+
const at = writeAddr(doc, addr);
|
|
271
288
|
if (opts.emptyUnsets && heldAnchors().length === 0 && isEmptyContent(newRt))
|
|
272
289
|
return commitUnset();
|
|
273
290
|
if (plaintext)
|
|
274
|
-
return commitPlain(newRt.text);
|
|
275
|
-
// The text splice, computed once per keystroke and shared by the gate, both overwrite
|
|
276
|
-
// fallbacks and `lower`.
|
|
277
|
-
const edit = contentEdit(oldRt, newRt);
|
|
291
|
+
return commitPlain(newRt.text.replaceAll(HARD_BREAK, '\n'));
|
|
278
292
|
try {
|
|
279
|
-
// Only a field not yet at content rest
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (!opsCommittable(doc, addr)) {
|
|
284
|
-
doc.overwrite(addr, edit.newRt); // brings the field to content rest
|
|
285
|
-
}
|
|
293
|
+
// Only a field not yet at content rest replaces by choice: neither an absent declared
|
|
294
|
+
// field nor an authored string has anchors to lose (`changeCommittable`).
|
|
295
|
+
if (!changeCommittable(doc, addr))
|
|
296
|
+
doc.replace(at, newRt);
|
|
286
297
|
else {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
298
|
+
const change = lower(oldRt, newRt);
|
|
299
|
+
if (change)
|
|
300
|
+
doc.apply(at, change);
|
|
290
301
|
}
|
|
291
302
|
reconciler.commit(readLeaf(reader, addr));
|
|
292
303
|
return true;
|
|
293
304
|
}
|
|
294
305
|
catch (e) {
|
|
295
|
-
// Bound the damage: after
|
|
296
|
-
//
|
|
297
|
-
//
|
|
306
|
+
// Bound the damage: after a change the store refused, the reconciler re-diffs from stale
|
|
307
|
+
// content and every later edit would re-throw. Replace with the full projection, which
|
|
308
|
+
// carries each anchor where its text survives.
|
|
298
309
|
reportError(opts.onError, {
|
|
299
310
|
code: 'commit-fallback',
|
|
300
311
|
severity: 'error',
|
|
301
|
-
message: `
|
|
312
|
+
message: `apply refused; replaced the whole field: ${errorMessage(e)}`,
|
|
302
313
|
cause: e
|
|
303
314
|
});
|
|
304
315
|
try {
|
|
305
|
-
doc.
|
|
316
|
+
doc.replace(at, newRt);
|
|
306
317
|
reconciler.commit(readLeaf(reader, addr));
|
|
307
318
|
return true;
|
|
308
319
|
}
|
|
@@ -311,7 +322,7 @@ export function createField(opts) {
|
|
|
311
322
|
reportError(opts.onError, {
|
|
312
323
|
code: 'commit-lost',
|
|
313
324
|
severity: 'error',
|
|
314
|
-
message: `
|
|
325
|
+
message: `replace fallback failed; the stored value is stale while the editor keeps the edit: ${errorMessage(e2)}`,
|
|
315
326
|
cause: e2
|
|
316
327
|
});
|
|
317
328
|
return false;
|
|
@@ -329,6 +340,8 @@ export function createField(opts) {
|
|
|
329
340
|
const name = addr.field;
|
|
330
341
|
if (name === undefined)
|
|
331
342
|
throw new Error('a text leaf names a field');
|
|
343
|
+
if (typeof addr.card === 'string')
|
|
344
|
+
throw new Error('a text leaf names its card by index');
|
|
332
345
|
(addr.card === undefined ? writer : writer.card(addr.card)).set(name, text);
|
|
333
346
|
reconciler.commit(readLeaf(reader, addr));
|
|
334
347
|
return true;
|
|
@@ -384,14 +397,13 @@ export function createField(opts) {
|
|
|
384
397
|
return false;
|
|
385
398
|
const after = buildLineIndex(tr.doc);
|
|
386
399
|
if (delta && before.selection instanceof TextSelection) {
|
|
387
|
-
const
|
|
388
|
-
const at = (pm) => usvToPM(after, mapPos(delta, pmToUsv(index, pm), 'after'));
|
|
400
|
+
const at = (pm) => offsetToPM(after, mapThroughDelta(delta, pmToOffset(index, pm)));
|
|
389
401
|
tr.setSelection(TextSelection.between(tr.doc.resolve(at(before.selection.anchor)), tr.doc.resolve(at(before.selection.head))));
|
|
390
402
|
}
|
|
391
403
|
if (!plaintext)
|
|
392
404
|
tr.setMeta(anchorKey, {
|
|
393
405
|
op: 'reset',
|
|
394
|
-
anchors: anchorsFromContent(rt).map((a) => (
|
|
406
|
+
anchors: anchorsFromContent(rt).map((a) => toPM(after, a))
|
|
395
407
|
});
|
|
396
408
|
view.updateState(before.apply(tr));
|
|
397
409
|
index = view.state.doc.eq(tr.doc) ? after : buildLineIndex(view.state.doc);
|
|
@@ -403,15 +415,19 @@ export function createField(opts) {
|
|
|
403
415
|
}
|
|
404
416
|
/** The anchors the plugin currently holds (PM coords); `[]` before the first apply. */
|
|
405
417
|
const heldAnchors = () => anchorKey.getState(view.state) ?? [];
|
|
406
|
-
/** The plugin's
|
|
418
|
+
/** The plugin's anchors as content offsets, against `index` — which `dispatchTransaction`
|
|
407
419
|
* rebuilt over the new document before the commit this reads for. */
|
|
408
|
-
function
|
|
409
|
-
return heldAnchors().map((a) => ({
|
|
420
|
+
function readAnchors() {
|
|
421
|
+
return heldAnchors().map((a) => ({
|
|
422
|
+
id: a.id,
|
|
423
|
+
start: pmToOffset(index, a.start),
|
|
424
|
+
end: pmToOffset(index, a.end)
|
|
425
|
+
}));
|
|
410
426
|
}
|
|
411
427
|
const controller = {
|
|
412
428
|
el: container,
|
|
413
429
|
setCaret(pos) {
|
|
414
|
-
const pm =
|
|
430
|
+
const pm = offsetToPM(index, pos);
|
|
415
431
|
// `Selection.near`: the mapped position can be non-inline, where a raw TextSelection is
|
|
416
432
|
// invalid.
|
|
417
433
|
const sel = Selection.near(view.state.doc.resolve(pm));
|
|
@@ -440,12 +456,12 @@ export function createField(opts) {
|
|
|
440
456
|
}
|
|
441
457
|
if (flipped)
|
|
442
458
|
held = !held;
|
|
443
|
-
const
|
|
459
|
+
const caret = pmToOffset(index, view.state.selection.head);
|
|
444
460
|
const fresh = buildState(current);
|
|
445
461
|
index = fresh.index;
|
|
446
|
-
// Best-effort caret continuity across an external change: keep the
|
|
462
|
+
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
447
463
|
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
448
|
-
const sel = Selection.near(fresh.state.doc.resolve(
|
|
464
|
+
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
449
465
|
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
450
466
|
reconciler.commit(current);
|
|
451
467
|
if (flipped)
|
|
@@ -474,18 +490,14 @@ export function createField(opts) {
|
|
|
474
490
|
getContent() {
|
|
475
491
|
return readLeaf(reader, addr);
|
|
476
492
|
},
|
|
477
|
-
insertAnchor(id, pos) {
|
|
478
|
-
// A text field carries no
|
|
493
|
+
insertAnchor(id, pos, end = pos) {
|
|
494
|
+
// A text field carries no anchors (§Inline mode), and a held one commits nothing.
|
|
479
495
|
if (plaintext || held)
|
|
480
496
|
return;
|
|
481
497
|
if (heldAnchors().some((a) => a.id === id))
|
|
482
|
-
return; // ids are unique
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (!opsCommittable(doc, addr))
|
|
486
|
-
doc.overwrite(addr, reconciler.last);
|
|
487
|
-
const pm = usvToPM(index, pos);
|
|
488
|
-
view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'add', id, pos: pm }));
|
|
498
|
+
return; // ids are unique and invariant
|
|
499
|
+
const at = toPM(index, { id, start: Math.min(pos, end), end: Math.max(pos, end) });
|
|
500
|
+
view.dispatch(view.state.tr.setMeta(anchorKey, { op: 'add', ...at }));
|
|
489
501
|
},
|
|
490
502
|
removeAnchor(id) {
|
|
491
503
|
if (plaintext)
|
|
@@ -496,10 +508,7 @@ export function createField(opts) {
|
|
|
496
508
|
},
|
|
497
509
|
anchorsInRange(from, to) {
|
|
498
510
|
return heldAnchors()
|
|
499
|
-
.filter((a) =>
|
|
500
|
-
const u = pmToUsv(index, a.pos);
|
|
501
|
-
return u >= from && u <= to;
|
|
502
|
-
})
|
|
511
|
+
.filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
|
|
503
512
|
.map((a) => a.id);
|
|
504
513
|
},
|
|
505
514
|
slashFocus(name) {
|
|
@@ -513,8 +522,8 @@ export function createField(opts) {
|
|
|
513
522
|
selectionRange() {
|
|
514
523
|
const { from, to } = view.state.selection;
|
|
515
524
|
return {
|
|
516
|
-
from:
|
|
517
|
-
to:
|
|
525
|
+
from: pmToOffset(index, from),
|
|
526
|
+
to: pmToOffset(index, to)
|
|
518
527
|
};
|
|
519
528
|
},
|
|
520
529
|
destroy() {
|
|
@@ -12,8 +12,8 @@ export type { SlashState, SlashStrings } from './slash.js';
|
|
|
12
12
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
13
13
|
export { rendersHref, storableUrl } from './urls.js';
|
|
14
14
|
export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
|
|
15
|
-
export { pmToContent,
|
|
16
|
-
export {
|
|
15
|
+
export { pmToContent, lower } from './encode.js';
|
|
16
|
+
export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
|
|
17
17
|
export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
|
|
18
18
|
export { inputRulesPlugin } from './inputrules.js';
|
|
19
19
|
export { bodyKeymap } from './keymap.js';
|
package/dist/core/codec/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The codec barrel: the bidirectional bridge between one content field (`Content`)
|
|
2
|
-
// and one ProseMirror document (CODEC.md). Decode (content → PM), lower (PM
|
|
3
|
-
// `
|
|
2
|
+
// and one ProseMirror document (CODEC.md). Decode (content → PM), lower (PM doc → a
|
|
3
|
+
// `Change` for `apply`), the UTF-16↔PM position map, and the `createField`
|
|
4
4
|
// prose leaf. Consumed by the VisualEditor and the codec test suite.
|
|
5
5
|
// ProseMirror's structural base styles and the gap cursor's, then the retint of the
|
|
6
6
|
// hues they mint. Imported here because `createField` is what mounts a view: a
|
|
@@ -35,8 +35,8 @@ export { rendersHref, storableUrl } from './urls.js';
|
|
|
35
35
|
// reached only by relative import within `codec/` stays off it: an export nothing
|
|
36
36
|
// imports is surface that still has to stay honest.
|
|
37
37
|
export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
|
|
38
|
-
export { pmToContent,
|
|
39
|
-
export {
|
|
38
|
+
export { pmToContent, lower } from './encode.js';
|
|
39
|
+
export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
|
|
40
40
|
// Reconciliation gate.
|
|
41
41
|
export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
|
|
42
42
|
// Input rules (`createField` mounts them unless `noInputRules`, or over a mark-free schema).
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { type Node as PMNode, type NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
|
-
import type { ContentIsland, TableProps } from '@quillmark/wasm';
|
|
3
|
+
import type { Content, ContentIsland, TableProps } from '@quillmark/wasm';
|
|
4
|
+
/** The `U+2028` line separator that is a break inside a block's text. */
|
|
5
|
+
export declare const HARD_BREAK = "\u2028";
|
|
4
6
|
/** The `U+FFFC` object-replacement char that occupies one island slot in `text`. */
|
|
5
7
|
export declare const ISLAND_SLOT = "\uFFFC";
|
|
6
|
-
/** Whether an island of `type` is block markup: a `table` stands alone
|
|
8
|
+
/** Whether an island of `type` is block markup: a `table` stands alone in its block. */
|
|
7
9
|
export declare function isBlockIsland(type: ContentIsland['type']): boolean;
|
|
8
10
|
/** Whether a leaf edits an island of `type`; one holding any other is held (`fitsLeaf`). */
|
|
9
11
|
export declare function isEditedIsland(type: ContentIsland['type']): boolean;
|
|
10
|
-
/** Block island node (a table): a `U+FFFC` slot alone
|
|
12
|
+
/** Block island node (a table): a `U+FFFC` slot alone in its `para` block. Atom. */
|
|
11
13
|
export declare const islandBlockSpec: NodeSpec;
|
|
12
|
-
/** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para`
|
|
14
|
+
/** Inline island node (an image, a footnote, an equation): a `U+FFFC` slot inside a `para` block. */
|
|
13
15
|
export declare const islandInlineSpec: NodeSpec;
|
|
14
16
|
/**
|
|
15
17
|
* A PM island node's attributes: the content entry, with `islandType` because `type` on a PM node
|
|
@@ -19,20 +21,22 @@ export interface IslandNodeAttrs {
|
|
|
19
21
|
id: string;
|
|
20
22
|
islandType: ContentIsland['type'];
|
|
21
23
|
props: unknown;
|
|
24
|
+
slots: Record<string, Content> | null;
|
|
25
|
+
/** A block island's: the id of the block its slot fills. */
|
|
26
|
+
block?: string | null;
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Build a content island entry from a PM island node's attrs. The cast pairs a closed `type` with a
|
|
25
30
|
* `props` that crossed the DOM as opaque JSON. The store is lenient about a table's shape, so a
|
|
26
31
|
* payload the arm does not hold is stored, and `undefined` at its reader draws the placeholder
|
|
27
|
-
* (§`
|
|
32
|
+
* (`table.ts` §`tableOfNode`).
|
|
28
33
|
*/
|
|
29
34
|
export declare function islandEntryFromNode(attrs: IslandNodeAttrs): ContentIsland;
|
|
30
35
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* placeholder for `undefined` (`table-view.ts` §`render`).
|
|
36
|
+
* The `TableProps` shape over a value that reached the node off the DOM: the column ids and the
|
|
37
|
+
* rows mapping each to a slot id, which every reader indexes (`table.ts`).
|
|
34
38
|
*/
|
|
35
|
-
export declare function
|
|
39
|
+
export declare function isTableProps(props: unknown): props is TableProps;
|
|
36
40
|
/** The next island id for a field: one draw from {@link islandMinter}. */
|
|
37
41
|
export declare function mintIslandId(doc: PMNode): string;
|
|
38
42
|
/**
|