@quillmark/svelte 0.30.0 → 0.32.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 +5 -5
- package/dist/core/address.d.ts +1 -1
- package/dist/core/address.js +1 -1
- package/dist/core/codec/atoms.js +1 -1
- package/dist/core/codec/breaks.js +3 -2
- package/dist/core/codec/decode.d.ts +4 -3
- package/dist/core/codec/decode.js +17 -13
- package/dist/core/codec/field.d.ts +5 -4
- package/dist/core/codec/field.js +139 -49
- package/dist/core/codec/index.d.ts +2 -0
- package/dist/core/codec/index.js +5 -1
- package/dist/core/codec/inputrules.js +3 -3
- package/dist/core/codec/islands.d.ts +1 -1
- package/dist/core/codec/islands.js +3 -3
- package/dist/core/codec/keymap.d.ts +1 -1
- package/dist/core/codec/keymap.js +3 -2
- package/dist/core/codec/list-move.js +2 -1
- package/dist/core/codec/list-paste.js +1 -1
- package/dist/core/codec/lists.d.ts +1 -1
- package/dist/core/codec/lists.js +7 -6
- package/dist/core/codec/markdown-paste.js +2 -2
- package/dist/core/codec/positions.d.ts +12 -1
- package/dist/core/codec/prose.css +3 -11
- package/dist/core/codec/schema.d.ts +3 -3
- package/dist/core/codec/schema.js +6 -6
- package/dist/core/codec/shortcuts.d.ts +91 -0
- package/dist/core/codec/shortcuts.js +135 -0
- package/dist/core/codec/slash.d.ts +4 -2
- package/dist/core/codec/slash.js +11 -1
- package/dist/core/codec/table-paste.js +1 -1
- package/dist/core/codec/table-view.d.ts +1 -1
- package/dist/core/codec/table-view.js +27 -37
- package/dist/core/codec/tasks.js +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/theme.css +16 -8
- package/dist/preset/scale.css +1 -1
- package/dist/preview/Preview.svelte +2 -3
- package/dist/preview/bridge.js +2 -2
- package/dist/preview/geometry.d.ts +2 -2
- package/dist/preview/geometry.js +2 -2
- package/dist/preview/paint.js +1 -1
- package/dist/visual/ArrayField.svelte +172 -87
- package/dist/visual/BooleanField.svelte +3 -3
- package/dist/visual/Card.svelte +68 -47
- package/dist/visual/CardControls.svelte +1 -1
- package/dist/visual/DateField.svelte +17 -2
- package/dist/visual/DiagnosticList.svelte +35 -3
- package/dist/visual/EnumField.svelte +59 -45
- package/dist/visual/Field.svelte +16 -6
- package/dist/visual/Field.svelte.d.ts +3 -1
- package/dist/visual/FieldHint.svelte +10 -3
- package/dist/visual/FormatPopover.svelte +9 -3
- package/dist/visual/MatrixAdd.svelte +4 -19
- package/dist/visual/MatrixField.svelte +21 -13
- package/dist/visual/NumberField.svelte +2 -3
- package/dist/visual/ObjectField.svelte +166 -147
- package/dist/visual/ProseField.svelte +8 -3
- package/dist/visual/SlashMenu.svelte +24 -12
- package/dist/visual/SlashMenu.svelte.d.ts +2 -0
- package/dist/visual/TextField.svelte +1 -1
- package/dist/visual/VariantField.svelte +1 -1
- package/dist/visual/VisualEditor.svelte +1 -1
- package/dist/visual/VisualEditor.svelte.d.ts +1 -1
- package/dist/visual/VisualEditorInner.svelte +159 -24
- package/dist/visual/VisualEditorInner.svelte.d.ts +1 -1
- package/dist/visual/controls.css +43 -5
- package/dist/visual/diagnostics.d.ts +2 -2
- package/dist/visual/diagnostics.js +2 -2
- package/dist/visual/index.d.ts +2 -0
- package/dist/visual/index.js +3 -0
- package/dist/visual/leaves.js +1 -1
- package/dist/visual/props.d.ts +2 -2
- package/dist/visual/strings.d.ts +33 -15
- package/dist/visual/strings.js +42 -7
- package/dist/visual/structure.d.ts +27 -18
- package/dist/visual/structure.js +32 -28
- package/dist/visual/tips.js +1 -1
- package/dist/visual/undo.svelte.d.ts +36 -0
- package/dist/visual/undo.svelte.js +119 -0
- package/package.json +2 -2
- package/dist/visual/hold.d.ts +0 -17
- package/dist/visual/hold.js +0 -39
package/README.md
CHANGED
|
@@ -39,21 +39,21 @@ const quill = Quill.fromTree(tree); // tree: Map<string, Uint8Array> of the quil
|
|
|
39
39
|
const doc = quill.seedDocument();
|
|
40
40
|
|
|
41
41
|
// An EXISTING document: parsed back from what you stored.
|
|
42
|
-
const doc = Document.
|
|
42
|
+
const doc = Document.parse(markdown); // canonical Quillmark markdown
|
|
43
43
|
const doc = Document.fromStored(json); // the versioned storage DTO (`doc.toStored()`)
|
|
44
44
|
|
|
45
45
|
const session = await new Engine().open(quill, doc);
|
|
46
46
|
// free() on teardown the handles you MINTED: this quill, this doc, this session.
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
`<VisualEditor>` needs no session, and the first `open` loads the render build, so a host that mounts the editor over `doc` and `quill` first shows it without waiting on that load. The session opens behind it: `await engine.load(quill)`, then `engine.open(quill, doc)`, so its first compile reads what was typed meanwhile ([
|
|
49
|
+
`<VisualEditor>` needs no session, and the first `open` loads the render build, so a host that mounts the editor over `doc` and `quill` first shows it without waiting on that load. The session opens behind it: `await engine.load(quill)`, then `engine.open(quill, doc)`, so its first compile reads what was typed meanwhile ([INVARIANTS.md](prose/INVARIANTS.md#hosting)).
|
|
50
50
|
|
|
51
51
|
## The quill resolves from the document
|
|
52
52
|
|
|
53
53
|
A stored document carries none of its quill's bytes, only a reference: `doc.quillRef` is `name@version`, persisted in the markdown itself. Resolution is **host code**: read the ref, map it to a `Quill`, open. No surface resolves, so one resolution per document holds by construction.
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
const doc = Document.
|
|
56
|
+
const doc = Document.parse(stored); // Document, from the gate above
|
|
57
57
|
const quill = await registry.getQuill(doc.quillRef); // your ref → Quill mapping
|
|
58
58
|
const session = await new Engine().open(quill, doc);
|
|
59
59
|
```
|
|
@@ -164,7 +164,7 @@ The package ships English and a seam to replace it. `strings` is keyed and **par
|
|
|
164
164
|
/>
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
`formatDiagnostic` gets the whole `Diagnostic` and returns `undefined` to take its own message. Validation and edit diagnostics re-word from `code`, `path` and `args`; parse errors and render warnings carry their detail inside English text and stand as they are ([
|
|
167
|
+
`formatDiagnostic` gets the whole `Diagnostic` and returns `undefined` to take its own message. Validation and edit diagnostics re-word from `code`, `path` and `args`; parse errors and render warnings carry their detail inside English text and stand as they are ([INVARIANTS.md](prose/INVARIANTS.md#diagnostics)).
|
|
168
168
|
|
|
169
169
|
### Fonts
|
|
170
170
|
|
|
@@ -265,7 +265,7 @@ The surfaces carry the behavior against a neutral, overridable visual baseline:
|
|
|
265
265
|
|
|
266
266
|
## Development
|
|
267
267
|
|
|
268
|
-
This package is one workspace of [`quillmark-js`](../..); the gates are the root's, and the
|
|
268
|
+
This package is one workspace of [`quillmark-js`](../..); the gates are the root's, and the rules a change must keep live in [`prose/INVARIANTS.md`](prose/INVARIANTS.md).
|
|
269
269
|
|
|
270
270
|
```sh
|
|
271
271
|
npm run build -w packages/svelte # svelte-package → dist/
|
package/dist/core/address.d.ts
CHANGED
|
@@ -63,7 +63,7 @@ export declare function addrForFieldPath(path: DocPath): Addr | undefined;
|
|
|
63
63
|
* The nearest ancestor a commit address can name: {@link addrForFieldPath} where the path has one,
|
|
64
64
|
* else the root and its first field (`main.contact.email` and `main.keywords[0]` land on their
|
|
65
65
|
* field). `undefined` for a field-rooted (config-space) or malformed path. An `Addr` reaches a root
|
|
66
|
-
* and one field, so the truncation is a consumer's to make (
|
|
66
|
+
* and one field, so the truncation is a consumer's to make (INVARIANTS §Diagnostics).
|
|
67
67
|
*/
|
|
68
68
|
export declare function nearestAddrForFieldPath(path: DocPath): Addr | undefined;
|
|
69
69
|
/**
|
package/dist/core/address.js
CHANGED
|
@@ -51,7 +51,7 @@ export function addrForFieldPath(path) {
|
|
|
51
51
|
* The nearest ancestor a commit address can name: {@link addrForFieldPath} where the path has one,
|
|
52
52
|
* else the root and its first field (`main.contact.email` and `main.keywords[0]` land on their
|
|
53
53
|
* field). `undefined` for a field-rooted (config-space) or malformed path. An `Addr` reaches a root
|
|
54
|
-
* and one field, so the truncation is a consumer's to make (
|
|
54
|
+
* and one field, so the truncation is a consumer's to make (INVARIANTS §Diagnostics).
|
|
55
55
|
*/
|
|
56
56
|
export function nearestAddrForFieldPath(path) {
|
|
57
57
|
const segs = segsOf(path);
|
package/dist/core/codec/atoms.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// delete against one edits nothing (§`againstAtom`).
|
|
5
5
|
//
|
|
6
6
|
// This is the neighbour half of the rule the leaf already holds for a key typed over a
|
|
7
|
-
// selection (
|
|
7
|
+
// selection (INVARIANTS §"The table island"): a selection is the subject of the next
|
|
8
8
|
// command, never a thing armed for replacement. Without it the base keymap's
|
|
9
9
|
// `joinBackward` / `joinForward` reach their "the neighbour is an atom, delete it" arm
|
|
10
10
|
// and a table goes in one keystroke, from the paragraph a table insert parks the caret
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Plugin, TextSelection } from 'prosemirror-state';
|
|
2
2
|
import { takesLineBreak } from './schema.js';
|
|
3
|
+
import { BODY_KEYS } from './shortcuts.js';
|
|
3
4
|
/**
|
|
4
5
|
* Rewrite every `\n` a transaction leaves in a non-`code` textblock: to a `hard_break`
|
|
5
6
|
* where the block takes one, to a space where it does not.
|
|
@@ -60,7 +61,7 @@ export function linebreakPlugin(schema) {
|
|
|
60
61
|
*
|
|
61
62
|
* The break takes no marks and the caret keeps them: `decode` mints an unmarked break,
|
|
62
63
|
* so an inherited mark would leave the leaf holding a shape a re-hydrate swaps out
|
|
63
|
-
* (
|
|
64
|
+
* (INVARIANTS §Encode, one spelling of each shape), while dropping the marks from the
|
|
64
65
|
* *caret* would end a bold run at a line break the author only meant to wrap at.
|
|
65
66
|
*/
|
|
66
67
|
function insertBreak(schema) {
|
|
@@ -90,5 +91,5 @@ function insertBreak(schema) {
|
|
|
90
91
|
export function breakKeymap(schema) {
|
|
91
92
|
if (!schema.nodes.hard_break)
|
|
92
93
|
return {};
|
|
93
|
-
return {
|
|
94
|
+
return { [BODY_KEYS.lineBreak]: insertBreak(schema) };
|
|
94
95
|
}
|
|
@@ -12,13 +12,14 @@ export declare function renderContent(rt: Content, schema: Schema): Node;
|
|
|
12
12
|
export declare function decode(rt: Content, schema: Schema): PMNode;
|
|
13
13
|
/**
|
|
14
14
|
* Whether `rt` decodes under an inline schema with nothing but whitespace dropped: upstream's
|
|
15
|
-
* one-line rule, or one plain line and the
|
|
16
|
-
* scalar keeps in a `text` value). Marks are the
|
|
15
|
+
* one-line rule, or one plain line and the break a trailing `\n` spells (the one a YAML `|`
|
|
16
|
+
* scalar keeps in a `text` value), or the empty line a trailing blank line opens. Marks are the
|
|
17
|
+
* schema's business.
|
|
17
18
|
*/
|
|
18
19
|
export declare function fitsInline(rt: Content): boolean;
|
|
19
20
|
/**
|
|
20
21
|
* Whether `rt` decodes under `plainSchema` losing nothing but its marks, which the next commit
|
|
21
|
-
* heals (
|
|
22
|
+
* heals (INVARIANTS §"Inline mode"): upstream's `isPlain` with marks set aside.
|
|
22
23
|
*/
|
|
23
24
|
export declare function fitsPlain(rt: Content): boolean;
|
|
24
25
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Decode: content → PM, a pure function (
|
|
1
|
+
// Decode: content → PM, a pure function (INVARIANTS §Decode). Each `\n`-separated segment is one
|
|
2
2
|
// block, its record's `kind` selecting the node; blocks nest by the containers their paths name,
|
|
3
3
|
// a run of blocks sharing a container id being that container; a `U+2028` is a break inside a
|
|
4
4
|
// block; marks apply over their `[start,end)` ranges; island slots lower to leaf nodes. Anchors are
|
|
@@ -52,22 +52,24 @@ export function decode(rt, schema) {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Whether `rt` decodes under an inline schema with nothing but whitespace dropped: upstream's
|
|
55
|
-
* one-line rule, or one plain line and the
|
|
56
|
-
* scalar keeps in a `text` value). Marks are the
|
|
55
|
+
* one-line rule, or one plain line and the break a trailing `\n` spells (the one a YAML `|`
|
|
56
|
+
* scalar keeps in a `text` value), or the empty line a trailing blank line opens. Marks are the
|
|
57
|
+
* schema's business.
|
|
57
58
|
*/
|
|
58
59
|
export function fitsInline(rt) {
|
|
59
60
|
if (core().isInline(rt))
|
|
60
61
|
return true;
|
|
61
62
|
const plain = (b) => b.kind === 'para' && !b.path?.length;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (rt.islands?.length || !rt.blocks.every(plain))
|
|
64
|
+
return false;
|
|
65
|
+
const breaks = rt.text.split(HARD_BREAK).length - 1;
|
|
66
|
+
if (rt.blocks.length === 1)
|
|
67
|
+
return breaks === 1 && rt.text.endsWith(HARD_BREAK);
|
|
68
|
+
return rt.blocks.length === 2 && rt.text.endsWith('\n') && breaks === 0;
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
69
71
|
* Whether `rt` decodes under `plainSchema` losing nothing but its marks, which the next commit
|
|
70
|
-
* heals (
|
|
72
|
+
* heals (INVARIANTS §"Inline mode"): upstream's `isPlain` with marks set aside.
|
|
71
73
|
*/
|
|
72
74
|
export function fitsPlain(rt) {
|
|
73
75
|
return core().isPlain({ ...rt, marks: [] });
|
|
@@ -91,12 +93,14 @@ export function fitsLeaf(rt, leaf) {
|
|
|
91
93
|
}
|
|
92
94
|
/** Inline decode: one paragraph, containers and islands stripped. */
|
|
93
95
|
function decodeInline(schema, segments, marks, cursor) {
|
|
94
|
-
// An inline field is single-line: stray blocks and breaks join with a space. The
|
|
95
|
-
// trailing `\n`
|
|
96
|
-
// representable inline: the slot char is
|
|
96
|
+
// An inline field is single-line: stray blocks and breaks join with a space. The break a
|
|
97
|
+
// trailing `\n` spells, and the empty block a trailing blank line opens, are dropped, so a first
|
|
98
|
+
// edit stores no space nobody typed. Islands are not representable inline: the slot char is
|
|
99
|
+
// dropped and its entry skipped.
|
|
97
100
|
const inline = [];
|
|
98
101
|
const last = segments.length - 1;
|
|
99
|
-
segments.forEach((
|
|
102
|
+
segments.forEach((at, i) => {
|
|
103
|
+
const seg = i === last && at.text.endsWith(HARD_BREAK) ? { ...at, text: at.text.slice(0, -1) } : at;
|
|
100
104
|
if (i > 0 && i === last && seg.text === '')
|
|
101
105
|
return;
|
|
102
106
|
if (i > 0)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Schema } from 'prosemirror-model';
|
|
2
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
3
|
import { EditorView } from 'prosemirror-view';
|
|
4
|
-
import type { Document, Content, Addr,
|
|
4
|
+
import type { Document, Content, Addr, Quill } from '@quillmark/wasm';
|
|
5
5
|
import type { EditorErrorHandler } from '../errors.js';
|
|
6
|
+
import { type Delta } from './positions.js';
|
|
6
7
|
import { type TextCap } from './cap.js';
|
|
7
8
|
import { type TableChromeStrings } from './table-view.js';
|
|
8
9
|
import { type SlashState, type SlashStrings } from './slash.js';
|
|
@@ -28,7 +29,7 @@ export interface CreateFieldOpts {
|
|
|
28
29
|
* Fired when the leaf holds or releases, and at mount when it mounts held. A one-line or `text`
|
|
29
30
|
* leaf is held over a value its schema cannot hold (`fitsLeaf`): the decode would join lines
|
|
30
31
|
* and drop containers and islands. Any leaf is held over what is read and not edited: a font
|
|
31
|
-
* family, a footnote, an equation (
|
|
32
|
+
* family, a footnote, an equation (INVARIANTS §Decode). A held leaf draws on the block schema,
|
|
32
33
|
* read-only, and commits nothing. Judged on each mount and re-hydrate ({@link
|
|
33
34
|
* FieldController.applyExternal}).
|
|
34
35
|
*/
|
|
@@ -92,7 +93,7 @@ export interface CreateFieldOpts {
|
|
|
92
93
|
/** Recovered failures on the commit path ({@link EditorErrorHandler}). */
|
|
93
94
|
onError?: EditorErrorHandler;
|
|
94
95
|
}
|
|
95
|
-
/** The prose-leaf handle (
|
|
96
|
+
/** The prose-leaf handle (INVARIANTS §Surface). */
|
|
96
97
|
export interface FieldController {
|
|
97
98
|
/** The mounted `container`: the leaf's element, for a caller that has to reach the
|
|
98
99
|
* DOM the view sits in (the arrival wash, `core/bloom.ts`) rather than re-find it. */
|
|
@@ -179,7 +180,7 @@ export declare function heldAttributes(opts: {
|
|
|
179
180
|
}, noteId: string | undefined): Record<string, string>;
|
|
180
181
|
export declare function createField(opts: CreateFieldOpts): FieldController;
|
|
181
182
|
/**
|
|
182
|
-
* The prose-leaf plugin stack (
|
|
183
|
+
* The prose-leaf plugin stack (INVARIANTS §Surface), shared by {@link createField} and
|
|
183
184
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
184
185
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
185
186
|
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
package/dist/core/codec/field.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The prose leaf: `createField` (
|
|
1
|
+
// The prose leaf: `createField` (INVARIANTS §Surface). One content field, one PM view wired to
|
|
2
2
|
// the WASM edit surface.
|
|
3
3
|
//
|
|
4
4
|
// `dispatchTransaction` applies the transaction optimistically, lowers it to a `Change` (or
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
// committed and `onCaretMove`. A throw keeps the optimistic PM state and reports through `onError`.
|
|
8
8
|
// An external change re-hydrates through `applyExternal`, gated by `reconcile` except where the
|
|
9
9
|
// hold it re-evaluates flips.
|
|
10
|
-
import { baseKeymap
|
|
10
|
+
import { baseKeymap } from 'prosemirror-commands';
|
|
11
11
|
import { gapCursor } from 'prosemirror-gapcursor';
|
|
12
|
-
import { history, redo, undo } from 'prosemirror-history';
|
|
12
|
+
import { history, isHistoryTransaction, redo, undo } from 'prosemirror-history';
|
|
13
13
|
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';
|
|
@@ -21,12 +21,13 @@ import { decode, fitsLeaf } from './decode.js';
|
|
|
21
21
|
import { offsetToPM, pmToOffset, buildLineIndex, lineIndexOf, mapThroughDelta } from './positions.js';
|
|
22
22
|
import { lower, pmToContent, scanContent, scanDoc } from './encode.js';
|
|
23
23
|
import { capPlugin } from './cap.js';
|
|
24
|
-
import {
|
|
24
|
+
import { 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';
|
|
28
28
|
import { linebreakPlugin } from './breaks.js';
|
|
29
29
|
import { bodyKeymap } from './keymap.js';
|
|
30
|
+
import { FIELD_KEYS, markKeymap } from './shortcuts.js';
|
|
30
31
|
import { remoteKey } from './remote.js';
|
|
31
32
|
import { blockSchema, isBlockSchema, isInlineSchema, leafSchema, plainSchema } from './schema.js';
|
|
32
33
|
import { linkPastePlugin } from './link-paste.js';
|
|
@@ -42,47 +43,121 @@ import { taskPlugin } from './tasks.js';
|
|
|
42
43
|
import { DEFAULT_TABLE_STRINGS, tableNodeView } from './table-view.js';
|
|
43
44
|
import { DEFAULT_SLASH_STRINGS, focusSlashItem, runSlashItem, slashPlugin } from './slash.js';
|
|
44
45
|
const anchorKey = new PluginKey('quill-anchors');
|
|
46
|
+
const GHOSTS = 100;
|
|
45
47
|
/**
|
|
46
48
|
* Plugin-held anchors (PM coords), mapped through every edit's `StepMap` and mutated by an {@link
|
|
47
49
|
* AnchorEdit} meta. The store's rule, so the commit has nothing to reconcile: a range keeps its
|
|
48
50
|
* 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
|
|
51
|
+
* range whose text is wholly deleted goes, and comes back with its text when history puts the
|
|
52
|
+
* deleted slice back ({@link Ghost}); a point never goes. A range draws as a span carrying
|
|
53
|
+
* `data-qm-anchor`, its id, for a host to style and measure; a point draws nothing.
|
|
50
54
|
*/
|
|
51
55
|
function anchorPlugin(seed) {
|
|
52
56
|
return new Plugin({
|
|
53
57
|
key: anchorKey,
|
|
54
58
|
state: {
|
|
55
|
-
init: () => seed,
|
|
56
|
-
apply: (tr,
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
})
|
|
67
|
-
: anchors;
|
|
59
|
+
init: () => ({ anchors: seed, ghosts: [] }),
|
|
60
|
+
apply: (tr, held) => {
|
|
61
|
+
let { anchors, ghosts } = held;
|
|
62
|
+
if (tr.docChanged) {
|
|
63
|
+
const undoing = isHistoryTransaction(tr);
|
|
64
|
+
for (const map of tr.mapping.maps)
|
|
65
|
+
({ anchors, ghosts } = mapAnchors(map, anchors, ghosts, undoing));
|
|
66
|
+
}
|
|
68
67
|
const edit = tr.getMeta(anchorKey);
|
|
69
68
|
if (edit?.op === 'add')
|
|
70
|
-
|
|
71
|
-
else if (edit?.op === 'remove')
|
|
72
|
-
|
|
69
|
+
anchors = [...anchors, { id: edit.id, start: edit.start, end: edit.end }];
|
|
70
|
+
else if (edit?.op === 'remove') {
|
|
71
|
+
anchors = anchors.filter((a) => a.id !== edit.id);
|
|
72
|
+
ghosts = ghosts.filter((g) => g.id !== edit.id);
|
|
73
|
+
}
|
|
73
74
|
else if (edit?.op === 'reset')
|
|
74
|
-
|
|
75
|
-
return
|
|
75
|
+
anchors = edit.anchors;
|
|
76
|
+
return { anchors, ghosts: ghosts.slice(-GHOSTS) };
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
props: {
|
|
80
|
+
decorations: (state) => {
|
|
81
|
+
const ranged = anchorKey.getState(state)?.anchors.filter((a) => a.end > a.start) ?? [];
|
|
82
|
+
return ranged.length
|
|
83
|
+
? DecorationSet.create(state.doc, ranged.map((a) => Decoration.inline(a.start, a.end, { 'data-qm-anchor': a.id }, { id: a.id })))
|
|
84
|
+
: DecorationSet.empty;
|
|
76
85
|
}
|
|
77
86
|
}
|
|
78
87
|
});
|
|
79
88
|
}
|
|
89
|
+
/** The replaced range of `map` holding `[from, to]`, where one does. */
|
|
90
|
+
function rangeOf(map, from, to) {
|
|
91
|
+
let hit;
|
|
92
|
+
map.forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
93
|
+
if (!hit && oldStart <= from && to <= oldEnd)
|
|
94
|
+
hit = { oldStart, oldEnd, newStart, newEnd };
|
|
95
|
+
});
|
|
96
|
+
return hit;
|
|
97
|
+
}
|
|
98
|
+
/** One step's map over the anchors and ghosts: a range the step deletes whole becomes a ghost,
|
|
99
|
+
* and under a history step a ghost whose slice comes back whole becomes its anchor again. */
|
|
100
|
+
function mapAnchors(map, anchors, ghosts, undoing) {
|
|
101
|
+
const nextAnchors = [];
|
|
102
|
+
const nextGhosts = [];
|
|
103
|
+
for (const g of ghosts) {
|
|
104
|
+
const range = rangeOf(map, g.at, g.at);
|
|
105
|
+
if (!range) {
|
|
106
|
+
nextGhosts.push({ ...g, at: map.map(g.at, -1) });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const { oldStart, oldEnd, newStart, newEnd } = range;
|
|
110
|
+
if (undoing && newEnd - newStart === g.lead + g.len + g.trail) {
|
|
111
|
+
if (g.inner)
|
|
112
|
+
nextGhosts.push({ ...g.inner, at: newStart + g.lead });
|
|
113
|
+
else
|
|
114
|
+
nextAnchors.push({ id: g.id, start: newStart + g.lead, end: newStart + g.lead + g.len });
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (oldEnd === oldStart) {
|
|
118
|
+
nextGhosts.push({ ...g, at: map.map(g.at, -1) });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
nextGhosts.push({
|
|
122
|
+
id: g.id,
|
|
123
|
+
at: newStart,
|
|
124
|
+
lead: g.at - oldStart,
|
|
125
|
+
len: 0,
|
|
126
|
+
trail: oldEnd - g.at,
|
|
127
|
+
inner: g
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
for (const a of anchors) {
|
|
131
|
+
if (a.start === a.end) {
|
|
132
|
+
const at = map.map(a.start, -1);
|
|
133
|
+
nextAnchors.push({ id: a.id, start: at, end: at });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const start = map.map(a.start, 1);
|
|
137
|
+
const end = map.map(a.end, -1);
|
|
138
|
+
if (start < end) {
|
|
139
|
+
nextAnchors.push({ id: a.id, start, end });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const range = rangeOf(map, a.start, a.end);
|
|
143
|
+
nextGhosts.push(range
|
|
144
|
+
? {
|
|
145
|
+
id: a.id,
|
|
146
|
+
at: range.newStart,
|
|
147
|
+
lead: a.start - range.oldStart,
|
|
148
|
+
len: a.end - a.start,
|
|
149
|
+
trail: range.oldEnd - a.end
|
|
150
|
+
}
|
|
151
|
+
: { id: a.id, at: start, lead: 0, len: a.end - a.start, trail: 0 });
|
|
152
|
+
}
|
|
153
|
+
return { anchors: nextAnchors, ghosts: nextGhosts };
|
|
154
|
+
}
|
|
80
155
|
/** An anchor in content offsets at its PM positions over `index`. */
|
|
81
156
|
function toPM(index, a) {
|
|
82
157
|
return { id: a.id, start: offsetToPM(index, a.start), end: offsetToPM(index, a.end) };
|
|
83
158
|
}
|
|
84
159
|
/**
|
|
85
|
-
* Read the leaf's `Content` for `addr` through `reader.getContent` (
|
|
160
|
+
* Read the leaf's `Content` for `addr` through `reader.getContent` (INVARIANTS §"A content field is read through the schema"): the body when
|
|
86
161
|
* `addr.field` is absent. Bound by the declared type rather than a verbatim read, since a string a
|
|
87
162
|
* markdown parse left means markdown for `richtext` and literal text for `text`; reading one as the
|
|
88
163
|
* other eats every `*` the author typed. An absent field (a default-only richtext field before its
|
|
@@ -143,6 +218,11 @@ export function heldAttributes(opts, noteId) {
|
|
|
143
218
|
tabindex: '0'
|
|
144
219
|
};
|
|
145
220
|
}
|
|
221
|
+
/** A plain leaf's value as the literal text its `text` field takes: a paragraph break a blank
|
|
222
|
+
* line and a hard break a lone `\n`, as the engine spells a `codec: "plain"` value. */
|
|
223
|
+
function literalOf(rt) {
|
|
224
|
+
return core().exportMarkdown({ ...rt, codec: 'plain' });
|
|
225
|
+
}
|
|
146
226
|
export function createField(opts) {
|
|
147
227
|
const { doc, addr, container } = opts;
|
|
148
228
|
const inline = !!opts.inline;
|
|
@@ -288,7 +368,7 @@ export function createField(opts) {
|
|
|
288
368
|
if (opts.emptyUnsets && heldAnchors().length === 0 && isEmptyContent(newRt))
|
|
289
369
|
return commitUnset();
|
|
290
370
|
if (plaintext)
|
|
291
|
-
return commitPlain(newRt
|
|
371
|
+
return commitPlain(literalOf(newRt));
|
|
292
372
|
try {
|
|
293
373
|
// Only a field not yet at content rest replaces by choice: neither an absent declared
|
|
294
374
|
// field nor an authored string has anchors to lose (`changeCommittable`).
|
|
@@ -331,7 +411,7 @@ export function createField(opts) {
|
|
|
331
411
|
}
|
|
332
412
|
/**
|
|
333
413
|
* A `text` leaf's commit: its whole text through the typed writer, resting the field as that
|
|
334
|
-
* literal string (
|
|
414
|
+
* literal string (INVARIANTS §"Inline mode"). The content-object rest form would emit markdown
|
|
335
415
|
* (escaped `*`, backslash breaks) and read back changed. A refusal lands nothing and has no
|
|
336
416
|
* fallback; the next edit writes the whole text again.
|
|
337
417
|
*/
|
|
@@ -414,7 +494,7 @@ export function createField(opts) {
|
|
|
414
494
|
}
|
|
415
495
|
}
|
|
416
496
|
/** The anchors the plugin currently holds (PM coords); `[]` before the first apply. */
|
|
417
|
-
const heldAnchors = () => anchorKey.getState(view.state) ?? [];
|
|
497
|
+
const heldAnchors = () => anchorKey.getState(view.state)?.anchors ?? [];
|
|
418
498
|
/** The plugin's anchors as content offsets, against `index` — which `dispatchTransaction`
|
|
419
499
|
* rebuilt over the new document before the commit this reads for. */
|
|
420
500
|
function readAnchors() {
|
|
@@ -545,7 +625,7 @@ export function createField(opts) {
|
|
|
545
625
|
return controller;
|
|
546
626
|
}
|
|
547
627
|
/**
|
|
548
|
-
* The prose-leaf plugin stack (
|
|
628
|
+
* The prose-leaf plugin stack (INVARIANTS §Surface), shared by {@link createField} and
|
|
549
629
|
* `ProseValue` so the two never fork the plugin ordering. History first with the step-splitting
|
|
550
630
|
* plugin (`undo.ts`), then `afterHistory` plugins (the addressed leaf's anchor plugin), {@link
|
|
551
631
|
* linebreakPlugin}, the markdown-shorthand input rules and their Backspace, the field keymap over
|
|
@@ -585,17 +665,36 @@ export function proseLeafPlugins(schema, opts) {
|
|
|
585
665
|
return list;
|
|
586
666
|
}
|
|
587
667
|
/**
|
|
588
|
-
* A plain leaf's clipboard text is literal,
|
|
589
|
-
*
|
|
668
|
+
* A plain leaf's clipboard text is literal both ways, spelled as the engine spells a `text` value:
|
|
669
|
+
* a lone `\n` a hard break, a blank line a paragraph boundary, and a run of `\n` its pairs as
|
|
670
|
+
* paragraph boundaries, an odd one over a hard break before them. Upstream's defaults split pasted
|
|
671
|
+
* text on any run of newlines and write a copy's breaks as nothing.
|
|
590
672
|
*/
|
|
591
673
|
function plainClipboardPlugin() {
|
|
592
|
-
const { paragraph } = plainSchema.nodes;
|
|
674
|
+
const { paragraph, hard_break } = plainSchema.nodes;
|
|
675
|
+
const line = (text) => paragraph.create(null, text
|
|
676
|
+
.split('\n')
|
|
677
|
+
.flatMap((part, i) => [
|
|
678
|
+
...(i ? [hard_break.create()] : []),
|
|
679
|
+
...(part ? [plainSchema.text(part)] : [])
|
|
680
|
+
]));
|
|
593
681
|
return new Plugin({
|
|
594
682
|
props: {
|
|
595
|
-
clipboardTextParser: (text) =>
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
683
|
+
clipboardTextParser: (text) => {
|
|
684
|
+
const paragraphs = [''];
|
|
685
|
+
for (const piece of text.replace(/\r\n?/g, '\n').split(/(\n+)/)) {
|
|
686
|
+
if (!piece.startsWith('\n')) {
|
|
687
|
+
paragraphs[paragraphs.length - 1] += piece;
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
if (piece.length % 2)
|
|
691
|
+
paragraphs[paragraphs.length - 1] += '\n';
|
|
692
|
+
for (let k = 0; k < piece.length >> 1; k++)
|
|
693
|
+
paragraphs.push('');
|
|
694
|
+
}
|
|
695
|
+
return new Slice(Fragment.from(paragraphs.map(line)), 1, 1);
|
|
696
|
+
},
|
|
697
|
+
clipboardTextSerializer: (slice) => slice.content.textBetween(0, slice.content.size, '\n\n', '\n')
|
|
599
698
|
}
|
|
600
699
|
});
|
|
601
700
|
}
|
|
@@ -675,25 +774,16 @@ function ghostPlugin(opts) {
|
|
|
675
774
|
* body's structural keys; Enter suppressed inline.
|
|
676
775
|
*
|
|
677
776
|
* Tab forks on the leaf's role: a one-line or `text` leaf is a form field, Tab unbound so field
|
|
678
|
-
* navigation is open for a shell keymap (
|
|
777
|
+
* navigation is open for a shell keymap (INVARIANTS §Chrome); a block-schema body
|
|
679
778
|
* takes Tab structurally, a chain each nested surface prepends to (`keymap.ts`).
|
|
680
779
|
*/
|
|
681
780
|
function editorKeymap(schema, inline, slash) {
|
|
682
781
|
const map = {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
782
|
+
[FIELD_KEYS.undo]: undo,
|
|
783
|
+
[FIELD_KEYS.redo]: redo,
|
|
784
|
+
[FIELD_KEYS.redoAlt]: redo,
|
|
785
|
+
...markKeymap(schema)
|
|
686
786
|
};
|
|
687
|
-
if (schema.marks.strong)
|
|
688
|
-
map['Mod-b'] = toggleMark(schema.marks.strong);
|
|
689
|
-
if (schema.marks.em)
|
|
690
|
-
map['Mod-i'] = toggleMark(schema.marks.em);
|
|
691
|
-
if (schema.marks.underline)
|
|
692
|
-
map['Mod-u'] = toggleMark(schema.marks.underline);
|
|
693
|
-
if (schema.marks.strike)
|
|
694
|
-
map['Mod-Shift-x'] = toggleMark(schema.marks.strike);
|
|
695
|
-
if (schema.marks.code)
|
|
696
|
-
map['Mod-e'] = toggleMark(schema.marks.code);
|
|
697
787
|
if (inline) {
|
|
698
788
|
// One textblock only: swallow Enter, and Shift-Enter with it (the schema declares no break
|
|
699
789
|
// node; a declined key is the browser's native `<br>`).
|
|
@@ -9,6 +9,8 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
9
9
|
export type { TableChromeStrings } from './table-view.js';
|
|
10
10
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
11
11
|
export type { SlashState, SlashStrings } from './slash.js';
|
|
12
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
|
|
13
|
+
export type { EditorShortcut, ShortcutScope, ShortcutStrings } from './shortcuts.js';
|
|
12
14
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
13
15
|
export { rendersHref, storableUrl } from './urls.js';
|
|
14
16
|
export { decode, fitsInline, fitsLeaf, fitsPlain, renderContent, usvLength } from './decode.js';
|
package/dist/core/codec/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The codec barrel: the bidirectional bridge between one content field (`Content`)
|
|
2
|
-
// and one ProseMirror document (
|
|
2
|
+
// and one ProseMirror document (INVARIANTS §"The codec"). Decode (content → PM), lower (PM doc → a
|
|
3
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
|
|
@@ -22,6 +22,10 @@ export { DEFAULT_TABLE_STRINGS } from './table-view.js';
|
|
|
22
22
|
// The slash menu: the codec owns the model and the picks, the chrome the words and
|
|
23
23
|
// the pixels (`visual/SlashMenu.svelte` is the only off-barrel caller).
|
|
24
24
|
export { DEFAULT_SLASH_STRINGS } from './slash.js';
|
|
25
|
+
// The rich editor's shortcuts as a host lists them, read off the tables the keymaps bind from;
|
|
26
|
+
// the visual tier's `strings` set extends their wording, and the formatting popover binds its
|
|
27
|
+
// link chord from `FIELD_KEYS`.
|
|
28
|
+
export { DEFAULT_SHORTCUT_STRINGS, FIELD_KEYS, editorShortcuts } from './shortcuts.js';
|
|
25
29
|
// Schemas (the decode/encode target; the VisualEditor mounts them). `hasMarks` is
|
|
26
30
|
// what a mark surface asks before offering itself over a leaf.
|
|
27
31
|
export { blockSchema, inlineSchema, plaintextSchema, plainSchema, leafSchema, hasMarks } from './schema.js';
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
//
|
|
10
10
|
// A rule declines only where what it would mint is unrepresentable, or is a shape
|
|
11
11
|
// another gesture owns — never on how a quill renders it. What a quill typesets is not
|
|
12
|
-
// knowable here (a quill this build has not seen is the open-sets case,
|
|
13
|
-
//
|
|
14
|
-
// a document opens carrying a shape the editor refuses to make. So one rule answers
|
|
12
|
+
// knowable here (a quill this build has not seen is the open-sets case,
|
|
13
|
+
// INVARIANTS §Vocabularies), and a construct that arrives through `importMarkdown` must stay
|
|
14
|
+
// authorable or a document opens carrying a shape the editor refuses to make. So one rule answers
|
|
15
15
|
// otherwise: `- ` / `1. ` at the head of an existing item retypes the item's list, where
|
|
16
16
|
// a wrap would nest and Tab owns the nesting. A marker the item already shows, and `a. `,
|
|
17
17
|
// `(1) `, `(a) ` in a nested item, are taken as typed and change nothing.
|
|
@@ -15,7 +15,7 @@ export declare const islandBlockSpec: NodeSpec;
|
|
|
15
15
|
export declare const islandInlineSpec: NodeSpec;
|
|
16
16
|
/**
|
|
17
17
|
* A PM island node's attributes: the content entry, with `islandType` because `type` on a PM node
|
|
18
|
-
* is the node type; its set comes off the entry (
|
|
18
|
+
* is the node type; its set comes off the entry (INVARIANTS §"The boundary").
|
|
19
19
|
*/
|
|
20
20
|
export interface IslandNodeAttrs {
|
|
21
21
|
id: string;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// other type inline. The node carries `id`, `islandType`, `props` and `slots` verbatim, and a block
|
|
4
4
|
// island the id of the block it fills.
|
|
5
5
|
//
|
|
6
|
-
// `ContentIsland.props` is the typed union at the boundary (
|
|
6
|
+
// `ContentIsland.props` is the typed union at the boundary (INVARIANTS §"The boundary"), so a
|
|
7
7
|
// discriminant check narrows it; `props` still crosses the DOM as opaque JSON, which
|
|
8
8
|
// `table.ts` §`tableOfNode` guards.
|
|
9
9
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
@@ -24,7 +24,7 @@ const islandAttrs = {
|
|
|
24
24
|
slots: { default: null }
|
|
25
25
|
};
|
|
26
26
|
// All three attributes cross the DOM, since a copy and a paste inside one body run the document
|
|
27
|
-
// through `toDOM`/`parseDOM` (
|
|
27
|
+
// through `toDOM`/`parseDOM` (INVARIANTS §"Markdown at the edges") and an island's tags alone say only
|
|
28
28
|
// `[table]`. `props` crosses as JSON. The names are `data-qm-*`, and the id is required: an island
|
|
29
29
|
// is a leaf, so a rule reading someone else's tag would swallow that element's whole subtree.
|
|
30
30
|
/** The DOM an island node writes and reads back, for either spec. */
|
|
@@ -160,7 +160,7 @@ export function isTableProps(props) {
|
|
|
160
160
|
/**
|
|
161
161
|
* A minter over one document: the positional `isl-{n}` sequence continued past the highest id the
|
|
162
162
|
* field holds, so a caller placing several islands keeps one minter. A minted id is part of the
|
|
163
|
-
* document's canonical bytes (
|
|
163
|
+
* document's canonical bytes (INVARIANTS §Islands): a counter over the projection in hand, never a UUID
|
|
164
164
|
* or clock reading, and never a re-numbering of existing ids.
|
|
165
165
|
*
|
|
166
166
|
* Reads the PM doc rather than stored content because that is what the caller holds and the commit
|
|
@@ -3,7 +3,7 @@ import type { Command } from 'prosemirror-state';
|
|
|
3
3
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
4
4
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
5
5
|
* the block link and the break link alone. The argument list is the precedence order
|
|
6
|
-
*
|
|
6
|
+
* INVARIANTS §Chrome, so a new link is one more argument at its place in that
|
|
7
7
|
* order rather than a nesting to read inside out.
|
|
8
8
|
*
|
|
9
9
|
* The slash menu is innermost of the three, and it is conditional rather than
|
|
@@ -6,6 +6,7 @@ import { codeKeymap } from './code.js';
|
|
|
6
6
|
import { listKeymap } from './lists.js';
|
|
7
7
|
import { listMoveKeymap } from './list-move.js';
|
|
8
8
|
import { slashKeymap } from './slash.js';
|
|
9
|
+
import { BODY_KEYS } from './shortcuts.js';
|
|
9
10
|
/** One chain per key, the maps taken in precedence order: on a key several bind, an
|
|
10
11
|
* earlier map's command runs first and the next runs only if it declines. A key one
|
|
11
12
|
* map alone binds is its own. No input is mutated. */
|
|
@@ -27,7 +28,7 @@ function exitKeymap(schema) {
|
|
|
27
28
|
return {
|
|
28
29
|
Tab: () => true,
|
|
29
30
|
'Shift-Tab': () => true,
|
|
30
|
-
|
|
31
|
+
[BODY_KEYS.leave]: (_state, _dispatch, view) => {
|
|
31
32
|
if (!view)
|
|
32
33
|
return false;
|
|
33
34
|
view.dom.blur();
|
|
@@ -38,7 +39,7 @@ function exitKeymap(schema) {
|
|
|
38
39
|
/** A multi-block leaf's structural keys, each link binding only what its schema
|
|
39
40
|
* declares: over `plainSchema`, which holds neither lists nor code blocks nor islands,
|
|
40
41
|
* the block link and the break link alone. The argument list is the precedence order
|
|
41
|
-
*
|
|
42
|
+
* INVARIANTS §Chrome, so a new link is one more argument at its place in that
|
|
42
43
|
* order rather than a nesting to read inside out.
|
|
43
44
|
*
|
|
44
45
|
* The slash menu is innermost of the three, and it is conditional rather than
|