@quillmark/svelte 0.29.2 → 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 +2 -1
- package/THEMING.md +8 -6
- package/dist/core/address.d.ts +3 -3
- package/dist/core/address.js +1 -1
- package/dist/core/bloom.d.ts +3 -2
- package/dist/core/bloom.js +6 -7
- 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 +87 -80
- package/dist/core/codec/index.d.ts +2 -5
- package/dist/core/codec/index.js +4 -4
- package/dist/core/codec/inputrules.d.ts +0 -3
- package/dist/core/codec/inputrules.js +1 -1
- package/dist/core/codec/islands.d.ts +13 -19
- package/dist/core/codec/islands.js +55 -50
- package/dist/core/codec/list-move.d.ts +0 -3
- package/dist/core/codec/list-move.js +2 -2
- package/dist/core/codec/list-node.d.ts +2 -0
- package/dist/core/codec/list-node.js +1 -0
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/markdown-paste.d.ts +0 -9
- package/dist/core/codec/markdown-paste.js +1 -1
- package/dist/core/codec/marks.d.ts +12 -18
- package/dist/core/codec/marks.js +16 -26
- package/dist/core/codec/nesting.d.ts +0 -4
- package/dist/core/codec/nesting.js +1 -1
- package/dist/core/codec/positions.d.ts +14 -7
- package/dist/core/codec/positions.js +43 -50
- package/dist/core/codec/prose.css +1 -1
- package/dist/core/codec/reveal.d.ts +14 -0
- package/dist/core/codec/reveal.js +40 -0
- package/dist/core/codec/schema.d.ts +1 -1
- package/dist/core/codec/schema.js +26 -8
- package/dist/core/codec/slash.js +0 -0
- 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 +22 -15
- package/dist/core/codec/table.d.ts +77 -49
- package/dist/core/codec/table.js +158 -49
- package/dist/core/codec/touching.d.ts +0 -2
- package/dist/core/codec/touching.js +1 -11
- package/dist/preview/Preview.svelte +20 -1
- package/dist/preview/Preview.svelte.d.ts +1 -0
- package/dist/preview/controller.d.ts +5 -0
- package/dist/preview/controller.js +6 -0
- package/dist/preview/viewport.js +19 -1
- package/dist/preview/wash.d.ts +9 -0
- package/dist/preview/wash.js +38 -0
- package/dist/visual/ArrayField.svelte +18 -115
- package/dist/visual/FormatPopover.svelte +1 -1
- package/dist/visual/MatrixField.svelte +15 -19
- package/dist/visual/ObjectField.svelte +10 -13
- package/dist/visual/ProseValue.svelte +8 -8
- package/dist/visual/VisualEditorInner.svelte +17 -11
- package/dist/visual/guidance.d.ts +0 -12
- package/dist/visual/guidance.js +2 -2
- package/dist/visual/leaves.d.ts +1 -1
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/rowdrag.svelte.d.ts +21 -0
- package/dist/visual/rowdrag.svelte.js +118 -0
- package/dist/visual/structure.d.ts +6 -6
- package/dist/visual/structure.js +18 -21
- package/package.json +2 -2
- package/dist/visual/checklists.d.ts +0 -3
- package/dist/visual/checklists.js +0 -7
|
@@ -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';
|
|
@@ -14,13 +14,14 @@ import { keymap } from 'prosemirror-keymap';
|
|
|
14
14
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
15
15
|
import { EditorState, NodeSelection, Plugin, PluginKey, Selection, TextSelection } from 'prosemirror-state';
|
|
16
16
|
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
|
|
17
|
+
import { revealProps } from './reveal.js';
|
|
17
18
|
import { core } from '../lifecycle.js';
|
|
18
19
|
import { reportError, errorMessage } from '../errors.js';
|
|
19
20
|
import { decode, fitsLeaf } from './decode.js';
|
|
20
|
-
import {
|
|
21
|
-
import { lower, pmToContent, scanContent, scanDoc
|
|
21
|
+
import { offsetToPM, pmToOffset, buildLineIndex, lineIndexOf, mapThroughDelta } from './positions.js';
|
|
22
|
+
import { lower, pmToContent, scanContent, scanDoc } from './encode.js';
|
|
22
23
|
import { capPlugin } from './cap.js';
|
|
23
|
-
import { islandPastePlugin } from './islands.js';
|
|
24
|
+
import { HARD_BREAK, islandPastePlugin } from './islands.js';
|
|
24
25
|
import { anchorsFromContent } from './marks.js';
|
|
25
26
|
import { contentEqual, createReconciler } from './reconcile.js';
|
|
26
27
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
@@ -41,12 +42,12 @@ import { taskPlugin } from './tasks.js';
|
|
|
41
42
|
import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
|
|
42
43
|
import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
|
|
43
44
|
const anchorKey = new PluginKey('quill-anchors');
|
|
44
|
-
/**
|
|
45
|
-
* and mutated by an {@link
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
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
|
+
*/
|
|
50
51
|
function anchorPlugin(seed) {
|
|
51
52
|
return new Plugin({
|
|
52
53
|
key: anchorKey,
|
|
@@ -54,11 +55,19 @@ function anchorPlugin(seed) {
|
|
|
54
55
|
init: () => seed,
|
|
55
56
|
apply: (tr, anchors) => {
|
|
56
57
|
let next = tr.docChanged
|
|
57
|
-
? 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
|
+
})
|
|
58
67
|
: anchors;
|
|
59
68
|
const edit = tr.getMeta(anchorKey);
|
|
60
69
|
if (edit?.op === 'add')
|
|
61
|
-
next = [...next, { id: edit.id,
|
|
70
|
+
next = [...next, { id: edit.id, start: edit.start, end: edit.end }];
|
|
62
71
|
else if (edit?.op === 'remove')
|
|
63
72
|
next = next.filter((a) => a.id !== edit.id);
|
|
64
73
|
else if (edit?.op === 'reset')
|
|
@@ -68,6 +77,10 @@ function anchorPlugin(seed) {
|
|
|
68
77
|
}
|
|
69
78
|
});
|
|
70
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
|
+
}
|
|
71
84
|
/**
|
|
72
85
|
* Read the leaf's `Content` for `addr` through `reader.getContent` (DOCUMENT_MODEL): the body when
|
|
73
86
|
* `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
|
|
@@ -79,21 +92,27 @@ function anchorPlugin(seed) {
|
|
|
79
92
|
function readLeaf(reader, addr) {
|
|
80
93
|
return reader.getContent(addr) ?? emptyContent();
|
|
81
94
|
}
|
|
82
|
-
/**
|
|
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. */
|
|
83
102
|
export function emptyContent() {
|
|
84
|
-
return { text: '',
|
|
103
|
+
return { text: '', blocks: [{ id: 'b0', kind: 'para' }] };
|
|
85
104
|
}
|
|
86
105
|
/** Whether `rt` is the empty leaf: {@link emptyContent}, nothing typed and no shape left. */
|
|
87
106
|
export function isEmptyContent(rt) {
|
|
88
107
|
return contentEqual(rt, emptyContent());
|
|
89
108
|
}
|
|
90
109
|
/**
|
|
91
|
-
* Whether
|
|
92
|
-
* exactly what PM shows. The other rest forms take `
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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}).
|
|
95
114
|
*/
|
|
96
|
-
function
|
|
115
|
+
function changeCommittable(doc, addr) {
|
|
97
116
|
const stored = doc.getStored(addr);
|
|
98
117
|
return stored !== null && typeof stored === 'object';
|
|
99
118
|
}
|
|
@@ -175,10 +194,7 @@ export function createField(opts) {
|
|
|
175
194
|
state,
|
|
176
195
|
editable: () => !held,
|
|
177
196
|
attributes: () => (held ? heldNamed : defaulted ? defaultNamed : named),
|
|
178
|
-
|
|
179
|
-
// (`scrollThreshold`) and what it leaves at the edge (`scrollMargin`).
|
|
180
|
-
scrollThreshold: clearance,
|
|
181
|
-
scrollMargin: clearance,
|
|
197
|
+
...revealProps(clearance),
|
|
182
198
|
// Islands are block-schema only, so any other leaf mounts no node view at all.
|
|
183
199
|
nodeViews: block
|
|
184
200
|
? {
|
|
@@ -215,12 +231,13 @@ export function createField(opts) {
|
|
|
215
231
|
// (`docChanged` false), so the `anchorKey` meta routes it.
|
|
216
232
|
if (!held && (tr.docChanged || tr.getMeta(anchorKey))) {
|
|
217
233
|
// (d) the change signal, only for what actually landed.
|
|
218
|
-
const
|
|
234
|
+
const anchors = plaintext ? [] : readAnchors();
|
|
235
|
+
const newRt = scan ? scanContent(scan, anchors) : pmToContent(next.doc, anchors);
|
|
219
236
|
if (commitEdit(oldRt, newRt))
|
|
220
237
|
opts.onChange?.(addr);
|
|
221
238
|
}
|
|
222
239
|
// The caret, for structural and selection-only changes, reported after the commit.
|
|
223
|
-
opts.onCaretMove?.(addr,
|
|
240
|
+
opts.onCaretMove?.(addr, pmToOffset(index, next.selection.head));
|
|
224
241
|
},
|
|
225
242
|
handleDOMEvents: {
|
|
226
243
|
focus: () => {
|
|
@@ -245,10 +262,7 @@ export function createField(opts) {
|
|
|
245
262
|
const anchors = plaintext ? [] : anchorsFromContent(rt);
|
|
246
263
|
// Seed anchor plugin positions in PM coords via a fresh index over pmDoc.
|
|
247
264
|
const seedIndex = buildLineIndex(pmDoc);
|
|
248
|
-
const seededAnchors = anchors.map((a) => (
|
|
249
|
-
id: a.id,
|
|
250
|
-
pos: usvToPM(seedIndex, a.pos)
|
|
251
|
-
}));
|
|
265
|
+
const seededAnchors = anchors.map((a) => toPM(seedIndex, a));
|
|
252
266
|
const built = EditorState.create({
|
|
253
267
|
doc: pmDoc,
|
|
254
268
|
plugins: proseLeafPlugins(schema, {
|
|
@@ -266,45 +280,40 @@ export function createField(opts) {
|
|
|
266
280
|
});
|
|
267
281
|
return { state: built, index: seedIndex };
|
|
268
282
|
}
|
|
269
|
-
// (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.
|
|
270
284
|
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
271
285
|
// branch ran.
|
|
272
286
|
function commitEdit(oldRt, newRt) {
|
|
287
|
+
const at = writeAddr(doc, addr);
|
|
273
288
|
if (opts.emptyUnsets && heldAnchors().length === 0 && isEmptyContent(newRt))
|
|
274
289
|
return commitUnset();
|
|
275
290
|
if (plaintext)
|
|
276
|
-
return commitPlain(newRt.text);
|
|
277
|
-
// The text splice, computed once per keystroke and shared by the gate, both overwrite
|
|
278
|
-
// fallbacks and `lower`.
|
|
279
|
-
const edit = contentEdit(oldRt, newRt);
|
|
291
|
+
return commitPlain(newRt.text.replaceAll(HARD_BREAK, '\n'));
|
|
280
292
|
try {
|
|
281
|
-
// Only a field not yet at content rest
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (!opsCommittable(doc, addr)) {
|
|
286
|
-
doc.overwrite(addr, edit.newRt); // brings the field to content rest
|
|
287
|
-
}
|
|
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);
|
|
288
297
|
else {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
298
|
+
const change = lower(oldRt, newRt);
|
|
299
|
+
if (change)
|
|
300
|
+
doc.apply(at, change);
|
|
292
301
|
}
|
|
293
302
|
reconciler.commit(readLeaf(reader, addr));
|
|
294
303
|
return true;
|
|
295
304
|
}
|
|
296
305
|
catch (e) {
|
|
297
|
-
// Bound the damage: after
|
|
298
|
-
//
|
|
299
|
-
//
|
|
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.
|
|
300
309
|
reportError(opts.onError, {
|
|
301
310
|
code: 'commit-fallback',
|
|
302
311
|
severity: 'error',
|
|
303
|
-
message: `
|
|
312
|
+
message: `apply refused; replaced the whole field: ${errorMessage(e)}`,
|
|
304
313
|
cause: e
|
|
305
314
|
});
|
|
306
315
|
try {
|
|
307
|
-
doc.
|
|
316
|
+
doc.replace(at, newRt);
|
|
308
317
|
reconciler.commit(readLeaf(reader, addr));
|
|
309
318
|
return true;
|
|
310
319
|
}
|
|
@@ -313,7 +322,7 @@ export function createField(opts) {
|
|
|
313
322
|
reportError(opts.onError, {
|
|
314
323
|
code: 'commit-lost',
|
|
315
324
|
severity: 'error',
|
|
316
|
-
message: `
|
|
325
|
+
message: `replace fallback failed; the stored value is stale while the editor keeps the edit: ${errorMessage(e2)}`,
|
|
317
326
|
cause: e2
|
|
318
327
|
});
|
|
319
328
|
return false;
|
|
@@ -331,6 +340,8 @@ export function createField(opts) {
|
|
|
331
340
|
const name = addr.field;
|
|
332
341
|
if (name === undefined)
|
|
333
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');
|
|
334
345
|
(addr.card === undefined ? writer : writer.card(addr.card)).set(name, text);
|
|
335
346
|
reconciler.commit(readLeaf(reader, addr));
|
|
336
347
|
return true;
|
|
@@ -386,14 +397,13 @@ export function createField(opts) {
|
|
|
386
397
|
return false;
|
|
387
398
|
const after = buildLineIndex(tr.doc);
|
|
388
399
|
if (delta && before.selection instanceof TextSelection) {
|
|
389
|
-
const
|
|
390
|
-
const at = (pm) => usvToPM(after, mapPos(delta, pmToUsv(index, pm), 'after'));
|
|
400
|
+
const at = (pm) => offsetToPM(after, mapThroughDelta(delta, pmToOffset(index, pm)));
|
|
391
401
|
tr.setSelection(TextSelection.between(tr.doc.resolve(at(before.selection.anchor)), tr.doc.resolve(at(before.selection.head))));
|
|
392
402
|
}
|
|
393
403
|
if (!plaintext)
|
|
394
404
|
tr.setMeta(anchorKey, {
|
|
395
405
|
op: 'reset',
|
|
396
|
-
anchors: anchorsFromContent(rt).map((a) => (
|
|
406
|
+
anchors: anchorsFromContent(rt).map((a) => toPM(after, a))
|
|
397
407
|
});
|
|
398
408
|
view.updateState(before.apply(tr));
|
|
399
409
|
index = view.state.doc.eq(tr.doc) ? after : buildLineIndex(view.state.doc);
|
|
@@ -405,15 +415,19 @@ export function createField(opts) {
|
|
|
405
415
|
}
|
|
406
416
|
/** The anchors the plugin currently holds (PM coords); `[]` before the first apply. */
|
|
407
417
|
const heldAnchors = () => anchorKey.getState(view.state) ?? [];
|
|
408
|
-
/** The plugin's
|
|
418
|
+
/** The plugin's anchors as content offsets, against `index` — which `dispatchTransaction`
|
|
409
419
|
* rebuilt over the new document before the commit this reads for. */
|
|
410
|
-
function
|
|
411
|
-
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
|
+
}));
|
|
412
426
|
}
|
|
413
427
|
const controller = {
|
|
414
428
|
el: container,
|
|
415
429
|
setCaret(pos) {
|
|
416
|
-
const pm =
|
|
430
|
+
const pm = offsetToPM(index, pos);
|
|
417
431
|
// `Selection.near`: the mapped position can be non-inline, where a raw TextSelection is
|
|
418
432
|
// invalid.
|
|
419
433
|
const sel = Selection.near(view.state.doc.resolve(pm));
|
|
@@ -442,12 +456,12 @@ export function createField(opts) {
|
|
|
442
456
|
}
|
|
443
457
|
if (flipped)
|
|
444
458
|
held = !held;
|
|
445
|
-
const
|
|
459
|
+
const caret = pmToOffset(index, view.state.selection.head);
|
|
446
460
|
const fresh = buildState(current);
|
|
447
461
|
index = fresh.index;
|
|
448
|
-
// Best-effort caret continuity across an external change: keep the
|
|
462
|
+
// Best-effort caret continuity across an external change: keep the offset. Set
|
|
449
463
|
// rather than dispatched, so a leaf the caret is not in reports no caret move.
|
|
450
|
-
const sel = Selection.near(fresh.state.doc.resolve(
|
|
464
|
+
const sel = Selection.near(fresh.state.doc.resolve(offsetToPM(index, caret)));
|
|
451
465
|
view.updateState(fresh.state.apply(fresh.state.tr.setSelection(sel)));
|
|
452
466
|
reconciler.commit(current);
|
|
453
467
|
if (flipped)
|
|
@@ -476,18 +490,14 @@ export function createField(opts) {
|
|
|
476
490
|
getContent() {
|
|
477
491
|
return readLeaf(reader, addr);
|
|
478
492
|
},
|
|
479
|
-
insertAnchor(id, pos) {
|
|
480
|
-
// 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.
|
|
481
495
|
if (plaintext || held)
|
|
482
496
|
return;
|
|
483
497
|
if (heldAnchors().some((a) => a.id === id))
|
|
484
|
-
return; // ids are unique
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (!opsCommittable(doc, addr))
|
|
488
|
-
doc.overwrite(addr, reconciler.last);
|
|
489
|
-
const pm = usvToPM(index, pos);
|
|
490
|
-
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 }));
|
|
491
501
|
},
|
|
492
502
|
removeAnchor(id) {
|
|
493
503
|
if (plaintext)
|
|
@@ -498,10 +508,7 @@ export function createField(opts) {
|
|
|
498
508
|
},
|
|
499
509
|
anchorsInRange(from, to) {
|
|
500
510
|
return heldAnchors()
|
|
501
|
-
.filter((a) =>
|
|
502
|
-
const u = pmToUsv(index, a.pos);
|
|
503
|
-
return u >= from && u <= to;
|
|
504
|
-
})
|
|
511
|
+
.filter((a) => pmToOffset(index, a.end) >= from && pmToOffset(index, a.start) <= to)
|
|
505
512
|
.map((a) => a.id);
|
|
506
513
|
},
|
|
507
514
|
slashFocus(name) {
|
|
@@ -515,8 +522,8 @@ export function createField(opts) {
|
|
|
515
522
|
selectionRange() {
|
|
516
523
|
const { from, to } = view.state.selection;
|
|
517
524
|
return {
|
|
518
|
-
from:
|
|
519
|
-
to:
|
|
525
|
+
from: pmToOffset(index, from),
|
|
526
|
+
to: pmToOffset(index, to)
|
|
520
527
|
};
|
|
521
528
|
},
|
|
522
529
|
destroy() {
|
|
@@ -12,12 +12,9 @@ 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
|
|
17
|
-
export { usvToPM, pmToUsv, buildLineIndex } from './positions.js';
|
|
18
|
-
export type { LineIndex } from './positions.js';
|
|
15
|
+
export { pmToContent, lower } from './encode.js';
|
|
16
|
+
export { offsetToPM, pmToOffset, buildLineIndex } from './positions.js';
|
|
19
17
|
export { createReconciler, contentEqual, valueEqual } from './reconcile.js';
|
|
20
|
-
export type { Reconciler } from './reconcile.js';
|
|
21
18
|
export { inputRulesPlugin } from './inputrules.js';
|
|
22
19
|
export { bodyKeymap } from './keymap.js';
|
|
23
20
|
export { listKeymap } from './lists.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,8 +1,5 @@
|
|
|
1
|
-
import { InputRule } from 'prosemirror-inputrules';
|
|
2
1
|
import type { Schema } from 'prosemirror-model';
|
|
3
2
|
import type { Plugin } from 'prosemirror-state';
|
|
4
|
-
/** The full markdown-shorthand rule set for a block schema. */
|
|
5
|
-
export declare function markdownInputRules(schema: Schema): InputRule[];
|
|
6
3
|
/** The input-rules plugin the field mounts by default (opt-out via createField). */
|
|
7
4
|
export declare function inputRulesPlugin(schema: Schema): Plugin;
|
|
8
5
|
/** Backspace on the press right after a rule fired takes the rule back and leaves the
|
|
@@ -77,7 +77,7 @@ function blockRule(regexp, command) {
|
|
|
77
77
|
return new InputRule(regexp, (state, match, start, end) => consuming(state, start, end, command(match))?.tr.scrollIntoView() ?? null);
|
|
78
78
|
}
|
|
79
79
|
/** The full markdown-shorthand rule set for a block schema. */
|
|
80
|
-
|
|
80
|
+
function markdownInputRules(schema) {
|
|
81
81
|
const rules = [];
|
|
82
82
|
const m = schema.marks;
|
|
83
83
|
// Inline marks. Non-greedy capture between matching delimiters. Built only where the
|
|
@@ -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,30 +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
|
|
36
|
-
/**
|
|
37
|
-
* A minter over one document: the positional `isl-{n}` sequence continued past the highest id the
|
|
38
|
-
* field holds, so a caller placing several islands keeps one minter. A minted id is part of the
|
|
39
|
-
* document's canonical bytes (CODEC §Islands): a counter over the projection in hand, never a UUID
|
|
40
|
-
* or clock reading, and never a re-numbering of existing ids.
|
|
41
|
-
*
|
|
42
|
-
* Reads the PM doc rather than stored content because that is what the caller holds and the commit
|
|
43
|
-
* will project; a stale content could collide with an id the same transaction places.
|
|
44
|
-
*/
|
|
45
|
-
export declare function islandMinter(doc: PMNode): () => string;
|
|
39
|
+
export declare function isTableProps(props: unknown): props is TableProps;
|
|
46
40
|
/** The next island id for a field: one draw from {@link islandMinter}. */
|
|
47
41
|
export declare function mintIslandId(doc: PMNode): string;
|
|
48
42
|
/**
|