@quillmark/svelte 0.27.0 → 0.29.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/NOTICE +4 -4
- package/README.md +26 -8
- package/THEMING.md +10 -8
- package/dist/core/address.d.ts +35 -64
- package/dist/core/address.js +35 -55
- package/dist/core/bloom.d.ts +4 -10
- package/dist/core/bloom.js +14 -27
- package/dist/core/codec/blocks.d.ts +41 -43
- package/dist/core/codec/blocks.js +97 -130
- package/dist/core/codec/cap.js +2 -1
- package/dist/core/codec/code.d.ts +7 -10
- package/dist/core/codec/code.js +37 -46
- package/dist/core/codec/decode.d.ts +19 -23
- package/dist/core/codec/decode.js +76 -111
- package/dist/core/codec/encode.d.ts +11 -15
- package/dist/core/codec/encode.js +60 -67
- package/dist/core/codec/field.d.ts +70 -99
- package/dist/core/codec/field.js +159 -180
- package/dist/core/codec/islands.d.ts +33 -41
- package/dist/core/codec/islands.js +76 -86
- package/dist/core/codec/lists.d.ts +17 -26
- package/dist/core/codec/lists.js +117 -157
- package/dist/core/codec/marks.d.ts +4 -3
- package/dist/core/codec/marks.js +8 -3
- package/dist/core/codec/nesting.js +2 -1
- package/dist/core/codec/prose.css +84 -46
- package/dist/core/codec/remote.d.ts +3 -0
- package/dist/core/codec/remote.js +7 -0
- package/dist/core/codec/schema.d.ts +18 -23
- package/dist/core/codec/schema.js +84 -76
- package/dist/core/codec/slash.d.ts +42 -48
- package/dist/core/codec/slash.js +0 -0
- package/dist/core/codec/table-copy.d.ts +4 -3
- package/dist/core/codec/table-copy.js +25 -7
- package/dist/core/codec/table-view.d.ts +12 -12
- package/dist/core/codec/table-view.js +460 -383
- package/dist/core/codec/table.d.ts +94 -61
- package/dist/core/codec/table.js +331 -83
- package/dist/core/codec/tasks.d.ts +6 -0
- package/dist/core/codec/tasks.js +30 -3
- package/dist/core/codec/undo.js +5 -1
- package/dist/core/errors.d.ts +15 -30
- package/dist/core/errors.js +2 -6
- package/dist/core/index.js +7 -12
- package/dist/core/lifecycle.d.ts +7 -16
- package/dist/core/lifecycle.js +10 -21
- package/dist/core/rebind.svelte.d.ts +10 -20
- package/dist/core/rebind.svelte.js +15 -27
- package/dist/core/rungs.d.ts +14 -11
- package/dist/core/rungs.js +17 -19
- package/dist/core/teardown.d.ts +4 -6
- package/dist/core/teardown.js +7 -10
- package/dist/core/theme.css +74 -54
- package/dist/index.js +3 -8
- package/dist/preset/app.css +3 -1
- package/dist/preset/index.css +6 -8
- package/dist/preset/recipes.css +12 -15
- package/dist/preset/scale.css +18 -17
- package/dist/preset/shell.css +10 -0
- package/dist/preview/bridge.d.ts +18 -22
- package/dist/preview/bridge.js +29 -58
- package/dist/preview/controller.d.ts +21 -29
- package/dist/preview/controller.js +14 -39
- package/dist/preview/geometry.d.ts +13 -34
- package/dist/preview/geometry.js +13 -34
- package/dist/preview/index.js +4 -16
- package/dist/preview/paint.d.ts +3 -3
- package/dist/preview/paint.js +28 -68
- package/dist/preview/strings.d.ts +1 -1
- package/dist/preview/strings.js +2 -14
- package/dist/preview/zoom.d.ts +18 -23
- package/dist/preview/zoom.js +28 -27
- package/dist/visual/ArrayField.svelte +77 -16
- package/dist/visual/BooleanField.svelte +27 -14
- package/dist/visual/Card.svelte +61 -48
- package/dist/visual/CardControls.svelte +5 -11
- package/dist/visual/DateField.svelte +20 -4
- package/dist/visual/EnumField.svelte +3 -0
- package/dist/visual/FieldHint.svelte +2 -1
- package/dist/visual/FormatPopover.svelte +82 -15
- package/dist/visual/FormatPopover.svelte.d.ts +4 -0
- package/dist/visual/MatrixAdd.svelte +30 -12
- package/dist/visual/MatrixField.svelte +24 -16
- package/dist/visual/NumberField.svelte +7 -0
- package/dist/visual/ObjectField.svelte +4 -4
- package/dist/visual/ProseField.svelte +0 -5
- package/dist/visual/TipsCard.svelte +11 -10
- package/dist/visual/VariantField.svelte +3 -1
- package/dist/visual/VisualEditor.svelte +15 -1
- package/dist/visual/VisualEditor.svelte.d.ts +5 -1
- package/dist/visual/VisualEditorInner.svelte +72 -17
- package/dist/visual/VisualEditorInner.svelte.d.ts +5 -1
- package/dist/visual/controls.css +7 -2
- package/dist/visual/fonts.d.ts +18 -0
- package/dist/visual/fonts.js +59 -0
- package/dist/visual/icons/nodes.d.ts +0 -5
- package/dist/visual/icons/nodes.js +0 -4
- package/dist/visual/index.d.ts +1 -1
- package/dist/visual/props.d.ts +14 -1
- package/dist/visual/signals.d.ts +19 -5
- package/dist/visual/strings.d.ts +7 -0
- package/dist/visual/strings.js +5 -2
- package/dist/visual/structure.d.ts +43 -87
- package/dist/visual/structure.js +42 -83
- package/package.json +2 -2
package/dist/core/codec/field.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
// The prose leaf: `createField` (VISUAL_EDITOR §Surface). One content field, one
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// (d) fire `onChange` when the transaction committed, then `onCaretMove` with
|
|
11
|
-
// the new USV caret, which a bare selection move fires on its own.
|
|
12
|
-
// On an `applyChange` throw the optimistic PM state stays and the failure reports
|
|
13
|
-
// through `onError`: never a crash. Caret continuity across own-edits is the PM
|
|
14
|
-
// `StepMap`; an external content change re-hydrates through `applyExternal`, gated
|
|
15
|
-
// by `reconcile` except where the hold it re-evaluates flips.
|
|
1
|
+
// The prose leaf: `createField` (VISUAL_EDITOR §Surface). One content field, one PM view wired to
|
|
2
|
+
// the WASM edit surface.
|
|
3
|
+
//
|
|
4
|
+
// `dispatchTransaction` applies the transaction optimistically, lowers it to a `ChangeBundle` (or
|
|
5
|
+
// `overwrite` for a field not yet at content rest, which has nothing to splice), commits via
|
|
6
|
+
// `doc.applyChange` (a `text` leaf's whole text through the typed writer), then fires `onChange` if
|
|
7
|
+
// it committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through
|
|
8
|
+
// `onError`. An external change re-hydrates through `applyExternal`, gated by `reconcile` except
|
|
9
|
+
// where the hold it re-evaluates flips.
|
|
16
10
|
import { baseKeymap, toggleMark } from 'prosemirror-commands';
|
|
17
11
|
import { gapCursor } from 'prosemirror-gapcursor';
|
|
18
12
|
import { history, redo, undo } from 'prosemirror-history';
|
|
@@ -20,6 +14,7 @@ import { keymap } from 'prosemirror-keymap';
|
|
|
20
14
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
21
15
|
import { EditorState, NodeSelection, Plugin, PluginKey, Selection, TextSelection } from 'prosemirror-state';
|
|
22
16
|
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
|
|
17
|
+
import { core } from '../lifecycle.js';
|
|
23
18
|
import { reportError, errorMessage } from '../errors.js';
|
|
24
19
|
import { decode, fitsLeaf } from './decode.js';
|
|
25
20
|
import { usvToPM, pmToUsv, buildLineIndex, lineIndexOf } from './positions.js';
|
|
@@ -31,6 +26,7 @@ import { contentEqual, createReconciler } from './reconcile.js';
|
|
|
31
26
|
import { inputRulesPlugin, undoRuleKeymap } from './inputrules.js';
|
|
32
27
|
import { linebreakPlugin } from './breaks.js';
|
|
33
28
|
import { bodyKeymap } from './keymap.js';
|
|
29
|
+
import { remoteKey } from './remote.js';
|
|
34
30
|
import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
|
|
35
31
|
import { linkPastePlugin } from './link-paste.js';
|
|
36
32
|
import { linePastePlugin } from './line-paste.js';
|
|
@@ -65,31 +61,25 @@ function anchorPlugin(seed) {
|
|
|
65
61
|
next = [...next, { id: edit.id, pos: edit.pos }];
|
|
66
62
|
else if (edit?.op === 'remove')
|
|
67
63
|
next = next.filter((a) => a.id !== edit.id);
|
|
64
|
+
else if (edit?.op === 'reset')
|
|
65
|
+
next = edit.anchors;
|
|
68
66
|
return next;
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
});
|
|
72
70
|
}
|
|
73
|
-
/**
|
|
74
|
-
* the
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* field
|
|
78
|
-
* first
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* Bound rather than verbatim, because the storage form is not the leaf's business
|
|
83
|
-
* and the verbatim read cannot answer it alone. A field the editor committed rests
|
|
84
|
-
* as `Content`; a field a markdown parse left rests as the authored string, and
|
|
85
|
-
* what that string means is the declared type's to say: `richtext` is markdown,
|
|
86
|
-
* `text` is literal text, and reading one as the other silently eats every `*` the
|
|
87
|
-
* author typed. */
|
|
71
|
+
/**
|
|
72
|
+
* Read the leaf's `Content` for `addr` through `reader.getContent` (DOCUMENT_MODEL): the body when
|
|
73
|
+
* `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
|
|
74
|
+
* markdown parse left means markdown for `richtext` and literal text for `text`; reading one as the
|
|
75
|
+
* other eats every `*` the author typed. An absent field (a default-only richtext field before its
|
|
76
|
+
* first edit) reads `undefined` and decodes empty; the first edit overwrites it. Only an
|
|
77
|
+
* out-of-range `addr.card` throws, unreachable since a removed card unmounts its keyed leaf.
|
|
78
|
+
*/
|
|
88
79
|
function readLeaf(reader, addr) {
|
|
89
80
|
return reader.getContent(addr) ?? emptyContent();
|
|
90
81
|
}
|
|
91
|
-
/** The canonical empty `Content`: one empty `para` line.
|
|
92
|
-
* leaf (or an array's prose element) seeds from. */
|
|
82
|
+
/** The canonical empty `Content`: one empty `para` line. */
|
|
93
83
|
export function emptyContent() {
|
|
94
84
|
return { text: '', lines: [{ containers: [], kind: 'para' }], marks: [], islands: [] };
|
|
95
85
|
}
|
|
@@ -97,24 +87,21 @@ export function emptyContent() {
|
|
|
97
87
|
export function isEmptyContent(rt) {
|
|
98
88
|
return contentEqual(rt, emptyContent());
|
|
99
89
|
}
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
* string carries no anchors to pay. A body always rests as `Content`. A `text` leaf
|
|
107
|
-
* never asks: it commits through the writer ({@link createField}). */
|
|
90
|
+
/**
|
|
91
|
+
* Whether ops may commit here: the stored value is a `Content` object, so `applyChange` splices
|
|
92
|
+
* exactly what PM shows. The other rest forms take `overwrite`: an unset field has nothing to
|
|
93
|
+
* splice, and an authored string carries no anchors to pay. A body always rests as `Content`; a
|
|
94
|
+
* `text` leaf commits through the writer ({@link createField}).
|
|
95
|
+
*/
|
|
108
96
|
function opsCommittable(doc, addr) {
|
|
109
97
|
const stored = doc.getStored(addr);
|
|
110
98
|
return stored !== null && typeof stored === 'object';
|
|
111
99
|
}
|
|
112
|
-
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
* the absence, not an empty object. */
|
|
100
|
+
/**
|
|
101
|
+
* The naming attributes for the `contenteditable`, shared with `ProseValue`. `aria-labelledby`
|
|
102
|
+
* supersedes `aria-label`, and `undefined` is returned whole when a leaf takes neither, since
|
|
103
|
+
* ProseMirror reads the absence.
|
|
104
|
+
*/
|
|
118
105
|
export function proseAttributes(opts) {
|
|
119
106
|
const attrs = {};
|
|
120
107
|
if (opts.labelledBy)
|
|
@@ -141,13 +128,10 @@ export function createField(opts) {
|
|
|
141
128
|
const { doc, addr, container } = opts;
|
|
142
129
|
const inline = !!opts.inline;
|
|
143
130
|
const plaintext = !!opts.plaintext;
|
|
144
|
-
// The declared type picks the schema
|
|
145
|
-
// `plaintext` suppresses: no mark types to toggle, to paste in, or to mint a
|
|
146
|
-
// shorthand with (`schema.ts`).
|
|
131
|
+
// The declared type picks the schema; `plaintext` suppresses every mark (`schema.ts`).
|
|
147
132
|
const schema = leafSchema({ plaintext, inline });
|
|
148
133
|
const block = isBlockSchema(schema);
|
|
149
|
-
// Bound once
|
|
150
|
-
// every read below sees the commit before it.
|
|
134
|
+
// Bound once: the reader reads live, so every read sees the commit before it.
|
|
151
135
|
const reader = opts.quill.reader(doc);
|
|
152
136
|
const writer = opts.quill.writer(doc);
|
|
153
137
|
let fallback = opts.fallback;
|
|
@@ -164,13 +148,10 @@ export function createField(opts) {
|
|
|
164
148
|
// The ghost's live cell: the ghost plugin reads it per pass, so moving it is an
|
|
165
149
|
// assignment plus a re-render rather than a rebuilt plugin stack.
|
|
166
150
|
let placeholderText = opts.placeholder;
|
|
167
|
-
// The views nested inside this leaf
|
|
168
|
-
//
|
|
169
|
-
// holds the caret: the format popover raises over a cell exactly as over the
|
|
170
|
-
// body, and only the leaf knows both.
|
|
151
|
+
// The views nested inside this leaf, one per table cell (`table-view.ts`): chrome asks the leaf
|
|
152
|
+
// which view holds the caret.
|
|
171
153
|
const nested = new Set();
|
|
172
|
-
// The menu's report channel
|
|
173
|
-
// vocabulary is the codec's own constant (`slash.ts`), not a wording to derive.
|
|
154
|
+
// The menu's report channel; the vocabulary is the codec's own constant (`slash.ts`).
|
|
174
155
|
const slash = block ? opts.onSlash : undefined;
|
|
175
156
|
// Judged of the value being mounted rather than read off a diagnostic: a routed set
|
|
176
157
|
// can predate the value it arrives with, and `validation::not_plain` stands in for
|
|
@@ -183,13 +164,9 @@ export function createField(opts) {
|
|
|
183
164
|
const seeded = buildState(reconciler.last);
|
|
184
165
|
const state = seeded.state;
|
|
185
166
|
index = seeded.index;
|
|
186
|
-
// The clearance PM's reveal keeps around the caret, in this leaf's own line box
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
// target's height (PREVIEW.md §"Follow-the-caret scroll"). Measured off the
|
|
190
|
-
// mounted box rather than restated from the rung, and dropped where the
|
|
191
|
-
// derivation is out of reach (jsdom), a fallback there being the scale written
|
|
192
|
-
// where `check:style` cannot read it.
|
|
167
|
+
// The clearance PM's reveal keeps around the caret, in this leaf's own line box: PM's 5px
|
|
168
|
+
// default leaves the next typed line past the fold. Measured off the mounted box and dropped
|
|
169
|
+
// where the derivation is out of reach (jsdom).
|
|
193
170
|
const lineBox = Number.parseFloat(getComputedStyle(container).lineHeight);
|
|
194
171
|
const clearance = Number.isFinite(lineBox) ? lineBox : undefined;
|
|
195
172
|
// Prepended, so what the caller draws inside `container` (a held leaf's note)
|
|
@@ -211,9 +188,8 @@ export function createField(opts) {
|
|
|
211
188
|
nested.add(cellView);
|
|
212
189
|
return () => nested.delete(cellView);
|
|
213
190
|
},
|
|
214
|
-
// A focus event does not bubble, so the leaf's
|
|
215
|
-
//
|
|
216
|
-
// follow a caret clicked straight into a table.
|
|
191
|
+
// A focus event does not bubble, so the leaf's `focus` handler never fires
|
|
192
|
+
// for a cell.
|
|
217
193
|
onCellFocus: () => opts.onFocus?.(addr),
|
|
218
194
|
clearance
|
|
219
195
|
})
|
|
@@ -230,25 +206,20 @@ export function createField(opts) {
|
|
|
230
206
|
if (!held && (tr.docChanged || tr.getMeta(anchorKey)))
|
|
231
207
|
defaulted = false;
|
|
232
208
|
view.updateState(next); // (a) optimistic
|
|
233
|
-
// One walk per structural change
|
|
234
|
-
//
|
|
235
|
-
// it was built from, so the index over it still holds.
|
|
209
|
+
// One walk per structural change; a selection-only transaction leaves the document, so
|
|
210
|
+
// the index still holds.
|
|
236
211
|
const scan = tr.docChanged ? scanDoc(next.doc) : undefined;
|
|
237
212
|
if (scan)
|
|
238
213
|
index = lineIndexOf(scan);
|
|
239
|
-
// Commit a content edit or an anchor mutation
|
|
240
|
-
//
|
|
241
|
-
// routes it through the same commit path (the diff emits the anchor op).
|
|
214
|
+
// Commit a content edit or an anchor mutation; an anchor edit is zero-width
|
|
215
|
+
// (`docChanged` false), so the `anchorKey` meta routes it.
|
|
242
216
|
if (!held && (tr.docChanged || tr.getMeta(anchorKey))) {
|
|
243
217
|
// (d) the change signal, only for what actually landed.
|
|
244
218
|
const newRt = scan ? scanContent(scan) : pmToContent(next.doc);
|
|
245
219
|
if (commitEdit(oldRt, newRt))
|
|
246
220
|
opts.onChange?.(addr);
|
|
247
221
|
}
|
|
248
|
-
// The caret, for
|
|
249
|
-
// following the caret wants an arrow key, and a host recompiling wants
|
|
250
|
-
// `onChange`. Reported after the commit, so the edit has landed by the
|
|
251
|
-
// time the caret names where it is.
|
|
222
|
+
// The caret, for structural and selection-only changes, reported after the commit.
|
|
252
223
|
opts.onCaretMove?.(addr, pmToUsv(index, next.selection.head));
|
|
253
224
|
},
|
|
254
225
|
handleDOMEvents: {
|
|
@@ -258,8 +229,10 @@ export function createField(opts) {
|
|
|
258
229
|
}
|
|
259
230
|
}
|
|
260
231
|
});
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
232
|
+
/**
|
|
233
|
+
* The state, and the index over the document it was built from (`buildLineIndex` is a whole
|
|
234
|
+
* walk).
|
|
235
|
+
*/
|
|
263
236
|
function buildState(rt) {
|
|
264
237
|
if (held) {
|
|
265
238
|
const pmDoc = decode(rt, blockSchema);
|
|
@@ -293,25 +266,22 @@ export function createField(opts) {
|
|
|
293
266
|
});
|
|
294
267
|
return { state: built, index: seedIndex };
|
|
295
268
|
}
|
|
296
|
-
// (b)+(c): lower the edit to ops and commit, or `overwrite` a field not yet at
|
|
297
|
-
//
|
|
298
|
-
//
|
|
299
|
-
// be a property of which branch the commit took.
|
|
269
|
+
// (b)+(c): lower the edit to ops and commit, or `overwrite` a field not yet at content rest.
|
|
270
|
+
// Keeps the optimistic PM on throw. Returns whether anything landed, independent of which
|
|
271
|
+
// branch ran.
|
|
300
272
|
function commitEdit(oldRt, newRt) {
|
|
301
273
|
if (opts.emptyUnsets && heldAnchors().length === 0 && isEmptyContent(newRt))
|
|
302
274
|
return commitUnset();
|
|
303
275
|
if (plaintext)
|
|
304
276
|
return commitPlain(newRt.text);
|
|
305
|
-
// The text splice, computed once per keystroke
|
|
306
|
-
// fallbacks
|
|
307
|
-
// caller's, off the same walk that rebuilt the index.
|
|
277
|
+
// The text splice, computed once per keystroke and shared by the gate, both overwrite
|
|
278
|
+
// fallbacks and `lower`.
|
|
308
279
|
const edit = contentEdit(oldRt, newRt);
|
|
309
280
|
try {
|
|
310
|
-
//
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
// places a slot the `delta` may not carry.
|
|
281
|
+
// Only a field not yet at content rest overwrites by choice: `applyChange` throws on an
|
|
282
|
+
// absent declared field, and neither it nor an authored string has anchors to lose
|
|
283
|
+
// (`opsCommittable`). Every structural edit lowers; the island channel places a slot
|
|
284
|
+
// the `delta` may not carry.
|
|
315
285
|
if (!opsCommittable(doc, addr)) {
|
|
316
286
|
doc.overwrite(addr, edit.newRt); // brings the field to content rest
|
|
317
287
|
}
|
|
@@ -324,10 +294,8 @@ export function createField(opts) {
|
|
|
324
294
|
return true;
|
|
325
295
|
}
|
|
326
296
|
catch (e) {
|
|
327
|
-
// Bound the damage: an op path the gates missed
|
|
328
|
-
//
|
|
329
|
-
// from that stale content, every later edit re-throws and the field
|
|
330
|
-
// silently stops persisting. Install the full projection instead
|
|
297
|
+
// Bound the damage: after an op path the gates missed, the reconciler re-diffs from
|
|
298
|
+
// stale content and every later edit would re-throw. Install the full projection
|
|
331
299
|
// (correct store, pays this field's anchors).
|
|
332
300
|
reportError(opts.onError, {
|
|
333
301
|
code: 'commit-fallback',
|
|
@@ -353,14 +321,10 @@ export function createField(opts) {
|
|
|
353
321
|
}
|
|
354
322
|
}
|
|
355
323
|
/**
|
|
356
|
-
* A `text` leaf's commit: its whole text through the typed writer,
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* reads back changed. The leaf carries no anchors, so the op path has none to keep.
|
|
361
|
-
*
|
|
362
|
-
* A refusal lands nothing and has no fallback, the other rest form being the
|
|
363
|
-
* corruption; the next edit writes the whole text again.
|
|
324
|
+
* A `text` leaf's commit: its whole text through the typed writer, resting the field as that
|
|
325
|
+
* literal string (CODEC §Inline mode). The content-object rest form would emit markdown
|
|
326
|
+
* (escaped `*`, backslash breaks) and read back changed. A refusal lands nothing and has no
|
|
327
|
+
* fallback; the next edit writes the whole text again.
|
|
364
328
|
*/
|
|
365
329
|
function commitPlain(text) {
|
|
366
330
|
try {
|
|
@@ -398,6 +362,47 @@ export function createField(opts) {
|
|
|
398
362
|
return false;
|
|
399
363
|
}
|
|
400
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Land `rt` as one replace over the span where it differs from the leaf, outside history and
|
|
367
|
+
* past the filters (`remote.ts`), with the anchors reset to the ones `rt` holds. False where
|
|
368
|
+
* the replace does not fit, which a rebuild answers instead.
|
|
369
|
+
*/
|
|
370
|
+
function landRemote(rt, delta) {
|
|
371
|
+
const before = view.state;
|
|
372
|
+
const next = decode(rt, schema);
|
|
373
|
+
const tr = before.tr.setMeta('addToHistory', false).setMeta(remoteKey, true);
|
|
374
|
+
const start = before.doc.content.findDiffStart(next.content);
|
|
375
|
+
try {
|
|
376
|
+
if (start != null) {
|
|
377
|
+
let { a: endA, b: endB } = before.doc.content.findDiffEnd(next.content);
|
|
378
|
+
const overlap = start - Math.min(endA, endB);
|
|
379
|
+
if (overlap > 0) {
|
|
380
|
+
endA += overlap;
|
|
381
|
+
endB += overlap;
|
|
382
|
+
}
|
|
383
|
+
tr.replace(start, endA, next.slice(start, endB));
|
|
384
|
+
}
|
|
385
|
+
if (!tr.doc.eq(next))
|
|
386
|
+
return false;
|
|
387
|
+
const after = buildLineIndex(tr.doc);
|
|
388
|
+
if (delta && before.selection instanceof TextSelection) {
|
|
389
|
+
const { mapPos } = core();
|
|
390
|
+
const at = (pm) => usvToPM(after, mapPos(delta, pmToUsv(index, pm), 'after'));
|
|
391
|
+
tr.setSelection(TextSelection.between(tr.doc.resolve(at(before.selection.anchor)), tr.doc.resolve(at(before.selection.head))));
|
|
392
|
+
}
|
|
393
|
+
if (!plaintext)
|
|
394
|
+
tr.setMeta(anchorKey, {
|
|
395
|
+
op: 'reset',
|
|
396
|
+
anchors: anchorsFromContent(rt).map((a) => ({ id: a.id, pos: usvToPM(after, a.pos) }))
|
|
397
|
+
});
|
|
398
|
+
view.updateState(before.apply(tr));
|
|
399
|
+
index = view.state.doc.eq(tr.doc) ? after : buildLineIndex(view.state.doc);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
401
406
|
/** The anchors the plugin currently holds (PM coords); `[]` before the first apply. */
|
|
402
407
|
const heldAnchors = () => anchorKey.getState(view.state) ?? [];
|
|
403
408
|
/** The plugin's anchor positions as USV, against `index` — which `dispatchTransaction`
|
|
@@ -409,21 +414,16 @@ export function createField(opts) {
|
|
|
409
414
|
el: container,
|
|
410
415
|
setCaret(pos) {
|
|
411
416
|
const pm = usvToPM(index, pos);
|
|
412
|
-
// `Selection.near
|
|
413
|
-
//
|
|
414
|
-
// nested textblock), where a raw TextSelection is invalid.
|
|
417
|
+
// `Selection.near`: the mapped position can be non-inline, where a raw TextSelection is
|
|
418
|
+
// invalid.
|
|
415
419
|
const sel = Selection.near(view.state.doc.resolve(pm));
|
|
416
|
-
// Focus first, then the caret
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
//
|
|
420
|
-
// Flagged, because PM focuses with `preventScroll` and a landing is a caret
|
|
421
|
-
// move like any other: unflagged, the caret an arrow key would have revealed
|
|
422
|
-
// is left off screen by the click that placed it.
|
|
420
|
+
// Focus first, then the caret, the order a click arrives in: the other way round the
|
|
421
|
+
// arrival ends the follow this call just started. Flagged, since PM focuses with
|
|
422
|
+
// `preventScroll` and an unflagged landing leaves the caret off screen.
|
|
423
423
|
view.focus();
|
|
424
424
|
view.dispatch(view.state.tr.setSelection(sel).scrollIntoView());
|
|
425
425
|
},
|
|
426
|
-
applyExternal() {
|
|
426
|
+
applyExternal(delta) {
|
|
427
427
|
const current = shown();
|
|
428
428
|
const flipped = holds(current) !== held;
|
|
429
429
|
const wasDefaulted = defaulted;
|
|
@@ -434,6 +434,12 @@ export function createField(opts) {
|
|
|
434
434
|
view.setProps({});
|
|
435
435
|
return;
|
|
436
436
|
}
|
|
437
|
+
if (!flipped && !held && landRemote(current, delta)) {
|
|
438
|
+
reconciler.commit(current);
|
|
439
|
+
if (defaulted !== wasDefaulted)
|
|
440
|
+
view.setProps({});
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
437
443
|
if (flipped)
|
|
438
444
|
held = !held;
|
|
439
445
|
const caretUsv = pmToUsv(index, view.state.selection.head);
|
|
@@ -463,9 +469,8 @@ export function createField(opts) {
|
|
|
463
469
|
},
|
|
464
470
|
focus() {
|
|
465
471
|
view.focus();
|
|
466
|
-
// The placement rung's reveal: no caret to flag a transaction with, so the
|
|
467
|
-
//
|
|
468
|
-
// lane's own focus takes, for the landing that means the same thing there.
|
|
472
|
+
// The placement rung's reveal: no caret to flag a transaction with, so the trip is the
|
|
473
|
+
// element's, `nearest`, no clearance.
|
|
469
474
|
view.dom.scrollIntoView({ block: 'nearest' });
|
|
470
475
|
},
|
|
471
476
|
getContent() {
|
|
@@ -477,9 +482,8 @@ export function createField(opts) {
|
|
|
477
482
|
return;
|
|
478
483
|
if (heldAnchors().some((a) => a.id === id))
|
|
479
484
|
return; // ids are unique + invariant (0.97 policy)
|
|
480
|
-
// An anchor commits through `applyChange`, so the field is brought to content
|
|
481
|
-
//
|
|
482
|
-
// the just-added anchor.
|
|
485
|
+
// An anchor commits through `applyChange`, so the field is brought to content rest
|
|
486
|
+
// first or the overwrite branch would drop it.
|
|
483
487
|
if (!opsCommittable(doc, addr))
|
|
484
488
|
doc.overwrite(addr, reconciler.last);
|
|
485
489
|
const pm = usvToPM(index, pos);
|
|
@@ -519,8 +523,7 @@ export function createField(opts) {
|
|
|
519
523
|
view.destroy();
|
|
520
524
|
}
|
|
521
525
|
};
|
|
522
|
-
// The underlying views, exposed
|
|
523
|
-
// VisualEditor composes views, and tests drive edits through them.
|
|
526
|
+
// The underlying views, exposed for VisualEditor and tests.
|
|
524
527
|
const handles = controller;
|
|
525
528
|
handles.view = view;
|
|
526
529
|
handles.nestedViews = () => [...nested];
|
|
@@ -535,24 +538,17 @@ export function createField(opts) {
|
|
|
535
538
|
return controller;
|
|
536
539
|
}
|
|
537
540
|
/**
|
|
538
|
-
* The prose-leaf plugin stack (VISUAL_EDITOR §Surface)
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
* that links a selection (`link-paste.ts`), and last the ones that answer to a block
|
|
547
|
-
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste pass
|
|
548
|
-
* (`islands.ts`), the table paste (`table-paste.ts`), the markdown paste
|
|
549
|
-
* (`markdown-paste.ts`) and the task item's checkbox (`tasks.ts`). A one-line leaf's
|
|
550
|
-
* paste joins its lines (`line-paste.ts`).
|
|
541
|
+
* The prose-leaf plugin stack (VISUAL_EDITOR §Surface), shared by {@link createField} and
|
|
542
|
+
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
543
|
+
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
544
|
+
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
|
545
|
+
* the base keymap, the URL paste that links a selection (`link-paste.ts`), and last the block
|
|
546
|
+
* leaf's own shapes: the gap cursor, {@link pastAtomPlugin}, the island paste (`islands.ts`), table
|
|
547
|
+
* paste (`table-paste.ts`), markdown paste (`markdown-paste.ts`) and the task checkbox
|
|
548
|
+
* (`tasks.ts`). A one-line leaf's paste joins its lines (`line-paste.ts`).
|
|
551
549
|
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* toggles bind no key and a pasted URL stays text, so a `**bold**` keeps the delimiters
|
|
555
|
-
* its author typed without a second rule saying so.
|
|
550
|
+
* Mark-shaped plugins read the schema rather than a flag: over a mark-free schema the shorthand
|
|
551
|
+
* rules build nothing, the toggles bind no key and a pasted URL stays text.
|
|
556
552
|
*/
|
|
557
553
|
export function proseLeafPlugins(schema, opts) {
|
|
558
554
|
const list = [
|
|
@@ -570,8 +566,7 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
570
566
|
list.push(keymap(baseKeymap));
|
|
571
567
|
if (schema.marks.link)
|
|
572
568
|
list.push(linkPastePlugin(schema.marks.link));
|
|
573
|
-
// Each answers to something only the block schema holds
|
|
574
|
-
// textblocks alone, with no island and no gap to put a cursor in.
|
|
569
|
+
// Each answers to something only the block schema holds.
|
|
575
570
|
if (isBlockSchema(schema))
|
|
576
571
|
list.push(gapCursor(), pastAtomPlugin(), islandPastePlugin(), tablePastePlugin(), tableCopyPlugin(), markdownPastePlugin(), wordPastePlugin(), listPastePlugin(), taskPlugin(), nestingPlugin());
|
|
577
572
|
if (schema === plainSchema)
|
|
@@ -583,10 +578,8 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
583
578
|
return list;
|
|
584
579
|
}
|
|
585
580
|
/**
|
|
586
|
-
* A plain leaf's clipboard text is literal, one line per `\n` both ways
|
|
587
|
-
*
|
|
588
|
-
* blank line the value holds as content, and write a copy's blocks joined by a blank
|
|
589
|
-
* line and its breaks as nothing.
|
|
581
|
+
* A plain leaf's clipboard text is literal, one line per `\n` both ways; upstream's defaults split
|
|
582
|
+
* pasted text on any run of newlines and write a copy's blocks joined by a blank line.
|
|
590
583
|
*/
|
|
591
584
|
function plainClipboardPlugin() {
|
|
592
585
|
const { paragraph } = plainSchema.nodes;
|
|
@@ -600,18 +593,11 @@ function plainClipboardPlugin() {
|
|
|
600
593
|
});
|
|
601
594
|
}
|
|
602
595
|
/**
|
|
603
|
-
* A printable key over a selected atom writes past it
|
|
604
|
-
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* types. Only a paragraph is reused, since an empty heading or fence would set the
|
|
609
|
-
* text in a shape the key never asked for.
|
|
610
|
-
*
|
|
611
|
-
* PM routes text input over a non-`TextSelection` through `handleTextInput` before
|
|
612
|
-
* falling back to replacing the selection, so this one prop is the whole of it.
|
|
613
|
-
* Paste keeps replacing: a paste is deliberate, and it is the gesture that swaps one
|
|
614
|
-
* island for another.
|
|
596
|
+
* A printable key over a selected atom writes past it: a selection is the subject of the next
|
|
597
|
+
* command, not armed for replacement. A block island takes the empty paragraph after it, or a new
|
|
598
|
+
* one; an inline one the caret after the image. Only a paragraph is reused. PM routes text input
|
|
599
|
+
* over a non-`TextSelection` through `handleTextInput`, so this one prop is the whole of it. Paste
|
|
600
|
+
* keeps replacing, as the gesture that swaps one island for another.
|
|
615
601
|
*/
|
|
616
602
|
function pastAtomPlugin() {
|
|
617
603
|
return new Plugin({
|
|
@@ -641,17 +627,11 @@ function pastAtomPlugin() {
|
|
|
641
627
|
});
|
|
642
628
|
}
|
|
643
629
|
/**
|
|
644
|
-
* The empty leaf's ghost
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
* Under `placeholderUntilEdit` it is stamped only until the state's first edit, after
|
|
650
|
-
* which the leaf has been answered. An inline leaf's ghost keeps to the one line the
|
|
651
|
-
* leaf is (`qm-prose-placeholder-line`).
|
|
652
|
-
*
|
|
653
|
-
* The text is read per decoration pass rather than closed over, so moving the ghost is
|
|
654
|
-
* a re-render and never a document edit.
|
|
630
|
+
* The empty leaf's ghost: a node decoration stamps the sole empty textblock with a class and the
|
|
631
|
+
* ghost text, which `prose.css` draws from the attribute, so the text never enters the document or
|
|
632
|
+
* a `pmToContent` export. Under `placeholderUntilEdit` it is stamped only until the state's first
|
|
633
|
+
* edit. An inline leaf's ghost keeps to one line (`qm-prose-placeholder-line`). The text is read
|
|
634
|
+
* per decoration pass, so moving the ghost is a re-render.
|
|
655
635
|
*/
|
|
656
636
|
function ghostPlugin(opts) {
|
|
657
637
|
const key = new PluginKey('qm-ghost');
|
|
@@ -684,15 +664,12 @@ function ghostPlugin(opts) {
|
|
|
684
664
|
});
|
|
685
665
|
}
|
|
686
666
|
/**
|
|
687
|
-
* The field's keymap: history, mark toggles
|
|
688
|
-
*
|
|
689
|
-
* `text` leaf leaves Mod-b/i/u to the browser.
|
|
667
|
+
* The field's keymap: history, mark toggles (bound per mark type the schema declares), and the
|
|
668
|
+
* body's structural keys; Enter suppressed inline.
|
|
690
669
|
*
|
|
691
|
-
* Tab forks on the leaf's role
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
* is structural, a chain each nested surface prepends to (`keymap.ts`). One key
|
|
695
|
-
* never means two things within one surface.
|
|
670
|
+
* Tab forks on the leaf's role: a one-line or `text` leaf is a form field, Tab unbound so field
|
|
671
|
+
* navigation is open for a shell keymap (VISUAL_EDITOR §Settled and open); a block-schema body
|
|
672
|
+
* takes Tab structurally, a chain each nested surface prepends to (`keymap.ts`).
|
|
696
673
|
*/
|
|
697
674
|
function editorKeymap(schema, inline, slash) {
|
|
698
675
|
const map = {
|
|
@@ -706,11 +683,13 @@ function editorKeymap(schema, inline, slash) {
|
|
|
706
683
|
map['Mod-i'] = toggleMark(schema.marks.em);
|
|
707
684
|
if (schema.marks.underline)
|
|
708
685
|
map['Mod-u'] = toggleMark(schema.marks.underline);
|
|
686
|
+
if (schema.marks.strike)
|
|
687
|
+
map['Mod-Shift-x'] = toggleMark(schema.marks.strike);
|
|
688
|
+
if (schema.marks.code)
|
|
689
|
+
map['Mod-e'] = toggleMark(schema.marks.code);
|
|
709
690
|
if (inline) {
|
|
710
|
-
// One textblock only: swallow Enter
|
|
711
|
-
//
|
|
712
|
-
// declares no break node, and a declined key is the browser's, whose native
|
|
713
|
-
// `<br>` is the one thing that could put a second line in a field that holds one.
|
|
691
|
+
// One textblock only: swallow Enter, and Shift-Enter with it (the schema declares no break
|
|
692
|
+
// node; a declined key is the browser's native `<br>`).
|
|
714
693
|
map['Enter'] = () => true;
|
|
715
694
|
map['Shift-Enter'] = () => true;
|
|
716
695
|
}
|