@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
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ Each subpath is its own module root; a bundler pulls only what the entry you imp
|
|
|
20
20
|
| `@quillmark/svelte/preview` | The live preview: `createPreview` + `<Preview>`. Reaches nothing editor-side. |
|
|
21
21
|
| `@quillmark/svelte/visual` | The federated WYSIWYG: `<VisualEditor>`, the codec's `createField` prose leaf. |
|
|
22
22
|
| `@quillmark/svelte` | Re-exports `/core`. |
|
|
23
|
+
| `@quillmark/svelte/preset` | The opt-in stylesheet for the page around a surface ([THEMING.md](THEMING.md)). |
|
|
23
24
|
|
|
24
25
|
## Open a session
|
|
25
26
|
|
|
@@ -111,7 +112,7 @@ In Svelte, `<Preview {session} onPick={…} />` exposes the same verbs (`refresh
|
|
|
111
112
|
/* the active leaf: `active.field` (a DocPath), and `active.cardId` for its card */
|
|
112
113
|
}}
|
|
113
114
|
onCaretMove={(at) => {
|
|
114
|
-
/* the caret moved to `at.field` (a DocPath) at `at.pos` (
|
|
115
|
+
/* the caret moved to `at.field` (a DocPath) at `at.pos` (UTF-16) */
|
|
115
116
|
}}
|
|
116
117
|
onError={(err) => {
|
|
117
118
|
/* a failure the editor recovered from; editing continues */
|
package/THEMING.md
CHANGED
|
@@ -22,6 +22,8 @@ Nothing to import and nothing to set. The package pulls its own stylesheet, and
|
|
|
22
22
|
|
|
23
23
|
`.qm-pane` is opt-in on the editor rather than the default because the editor is what its own popovers portal into, and a scroll container clips them. In a pane you would have had that clipping from your own scrolling frame anyway; in a page you should not have it at all.
|
|
24
24
|
|
|
25
|
+
**Something drawn over the bottom of the pane**: set `scroll-padding-block-end` on the `.qm-pane` element to the height it covers. A caret revealed in a rich-text field, by typing or by a landing, keeps its line of clearance above that inset, as the browser's own focus scroll does for a form control. `scroll-padding-block-start` does the same at the top.
|
|
26
|
+
|
|
25
27
|
**Placing and sizing**: each surface carries a stable root class (`.qm-editor`, `.qm-preview`), so you can place it from your own stylesheet without a wrapper. Each also takes a `class` prop that merges onto the same element, which is the better handle when you have one to give.
|
|
26
28
|
|
|
27
29
|
A surface's width is the one you give it. Each contains its own inline size, so what a document holds — a table is as wide as its columns — scrolls inside the mount rather than widening the column the mount stands in.
|
|
@@ -145,21 +147,21 @@ It carries a `--qmh-*` scale for the page, derived from the same nine dials and
|
|
|
145
147
|
|
|
146
148
|
An app that mounts an editor beside a preview over one session needs a screen to put them in, and the shape of that screen is the same every time. Five more classes are that shape, so what you write is the wiring rather than the grid:
|
|
147
149
|
|
|
148
|
-
```
|
|
150
|
+
```svelte
|
|
149
151
|
<div class="qm-workspace">
|
|
150
152
|
<header class="qm-bar site-head">
|
|
151
153
|
<span class="site-mark">acme<span class="site-slash">/</span>studio</span>
|
|
152
154
|
</header>
|
|
153
155
|
<div class="site-body">
|
|
154
156
|
<div class="qm-switch" role="group" aria-label="Visible pane">
|
|
155
|
-
<button class="qm-control" aria-pressed=
|
|
156
|
-
|
|
157
|
+
<button class="qm-control" aria-pressed={shown === 1} onclick={() => (shown = 1)}>
|
|
158
|
+
Editor
|
|
157
159
|
</button>
|
|
158
|
-
<button class="qm-control" aria-pressed=
|
|
159
|
-
|
|
160
|
+
<button class="qm-control" aria-pressed={shown === 2} onclick={() => (shown = 2)}>
|
|
161
|
+
Preview
|
|
160
162
|
</button>
|
|
161
163
|
</div>
|
|
162
|
-
<div class="qm-split" data-qm-show=
|
|
164
|
+
<div class="qm-split" data-qm-show={shown}>
|
|
163
165
|
<section class="qm-frame"><!-- <VisualEditor class="qm-pane" /> --></section>
|
|
164
166
|
<section class="qm-frame"><!-- <Preview /> --></section>
|
|
165
167
|
</div>
|
package/dist/core/address.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ export type DocPath = string;
|
|
|
9
9
|
/**
|
|
10
10
|
* A place in the document: a field and a caret within it. What the editor reports when its caret
|
|
11
11
|
* moves and what the preview scrolls to, so `onCaretMove={preview.focusPosition}` translates
|
|
12
|
-
* nothing. `pos` is
|
|
12
|
+
* nothing. `pos` is a UTF-16 offset, the coordinate shared on both sides of the boundary; a `ContentHit` is a
|
|
13
13
|
* `Place` with extras.
|
|
14
14
|
*/
|
|
15
15
|
export interface Place {
|
|
16
16
|
field: DocPath;
|
|
17
|
-
/** The caret
|
|
17
|
+
/** The caret, a UTF-16 offset. */
|
|
18
18
|
pos: number;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -25,7 +25,7 @@ export interface Place {
|
|
|
25
25
|
*/
|
|
26
26
|
export interface Landing {
|
|
27
27
|
field: DocPath;
|
|
28
|
-
/** The caret
|
|
28
|
+
/** The caret, a UTF-16 offset, absent on the placement rung. */
|
|
29
29
|
pos?: number;
|
|
30
30
|
/** Whether `pos` is cluster-exact or floored to a segment start; the boundary's
|
|
31
31
|
* own marker, carried through untouched. */
|
package/dist/core/address.js
CHANGED
|
@@ -126,7 +126,7 @@ function addrForSegs(segs) {
|
|
|
126
126
|
function cardHead(index, kinds) {
|
|
127
127
|
if (index == null)
|
|
128
128
|
return { seg: 'main' };
|
|
129
|
-
if (!Number.isInteger(index) || index < 0 || index >= kinds.length)
|
|
129
|
+
if (typeof index !== 'number' || !Number.isInteger(index) || index < 0 || index >= kinds.length)
|
|
130
130
|
return undefined;
|
|
131
131
|
return { seg: 'card', kind: kinds[index] || null, index };
|
|
132
132
|
}
|
package/dist/core/bloom.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Run one wash over `host`, a `.qm-wash` box, resolving the dwell off its root so the number is
|
|
3
3
|
* single-sourced in CSS (`core/rungs.ts`). `--_qm-bloom-dwell` already shortens under
|
|
4
4
|
* `prefers-reduced-motion`, so `matchMedia` here only picks the frame list. A run in flight on the
|
|
5
|
-
* same host is cancelled first, so two quick landings do not stack alphas.
|
|
5
|
+
* same host is cancelled first, so two quick landings do not stack alphas. Answers the run, or
|
|
6
|
+
* `undefined` where there is no animation to play it.
|
|
6
7
|
*/
|
|
7
|
-
export declare function bloom(host: HTMLElement):
|
|
8
|
+
export declare function bloom(host: HTMLElement): Animation | undefined;
|
package/dist/core/bloom.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Opacity is the animated property, never the colour: the wash's alpha is a peak fixed by
|
|
6
6
|
// `--_qm-accent-wash`, so the scale stays in CSS where `color-mix` resolves. The wash is the host's
|
|
7
7
|
// `::after` (`.qm-wash`, controls.css); this module plays it and adds nothing to the tree.
|
|
8
|
-
import { rungStyle } from './rungs.js';
|
|
8
|
+
import { rungMs, rungStyle } from './rungs.js';
|
|
9
9
|
const WASH = '::after';
|
|
10
10
|
/** The dwell used when the derivation is out of reach (an unstyled root, or jsdom). */
|
|
11
11
|
const FALLBACK_MS = 1100;
|
|
@@ -23,19 +23,18 @@ const FRAMES_REDUCED = [{ opacity: 1 }, { opacity: 1 }];
|
|
|
23
23
|
* Run one wash over `host`, a `.qm-wash` box, resolving the dwell off its root so the number is
|
|
24
24
|
* single-sourced in CSS (`core/rungs.ts`). `--_qm-bloom-dwell` already shortens under
|
|
25
25
|
* `prefers-reduced-motion`, so `matchMedia` here only picks the frame list. A run in flight on the
|
|
26
|
-
* same host is cancelled first, so two quick landings do not stack alphas.
|
|
26
|
+
* same host is cancelled first, so two quick landings do not stack alphas. Answers the run, or
|
|
27
|
+
* `undefined` where there is no animation to play it.
|
|
27
28
|
*/
|
|
28
29
|
export function bloom(host) {
|
|
29
30
|
if (typeof host.animate !== 'function')
|
|
30
|
-
return;
|
|
31
|
+
return undefined;
|
|
31
32
|
for (const a of host.getAnimations({ subtree: true })) {
|
|
32
33
|
const effect = a.effect;
|
|
33
34
|
if (effect?.target === host && effect.pseudoElement === WASH)
|
|
34
35
|
a.cancel();
|
|
35
36
|
}
|
|
36
37
|
const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const duration = !Number.isFinite(n) ? FALLBACK_MS : raw.endsWith('ms') ? n : n * 1000;
|
|
40
|
-
host.animate(reduced ? FRAMES_REDUCED : FRAMES, { duration, pseudoElement: WASH });
|
|
38
|
+
const duration = rungMs(rungStyle(host), '--_qm-bloom-dwell') ?? FALLBACK_MS;
|
|
39
|
+
return host.animate(reduced ? FRAMES_REDUCED : FRAMES, { duration, pseudoElement: WASH });
|
|
41
40
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type Node as PMNode, type Schema } from 'prosemirror-model';
|
|
2
2
|
import type { Content } from '@quillmark/wasm';
|
|
3
|
-
/**
|
|
4
|
-
export declare function codePoints(s: string): string[];
|
|
5
|
-
/** USV length of `s` (code points, not UTF-16 units). */
|
|
3
|
+
/** USV length of `s` (code points, not UTF-16 units): what a character cap counts. */
|
|
6
4
|
export declare function usvLength(s: string): number;
|
|
7
5
|
/**
|
|
8
6
|
* A `Content` as read-only DOM: decode under `schema`, then the nodes' own `toDOM`, for chrome that
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
// Decode: content → PM, a pure function (CODEC §Decode).
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// over their `[start,end)`
|
|
5
|
-
// decorations (field.ts).
|
|
6
|
-
//
|
|
1
|
+
// Decode: content → PM, a pure function (CODEC §Decode). Each `\n`-separated segment is one
|
|
2
|
+
// block, its record's `kind` selecting the node; blocks nest by the containers their paths name,
|
|
3
|
+
// a run of blocks sharing a container id being that container; a `U+2028` is a break inside a
|
|
4
|
+
// block; marks apply over their `[start,end)` ranges; island slots lower to leaf nodes. Anchors are
|
|
5
|
+
// decorations (field.ts). Offsets are UTF-16 code units, JavaScript string indices, so a PM text
|
|
6
|
+
// run and its content span advance together.
|
|
7
7
|
import { DOMSerializer } from 'prosemirror-model';
|
|
8
|
-
import { ISLAND_SLOT, isBlockIsland, isEditedIsland } from './islands.js';
|
|
8
|
+
import { HARD_BREAK, ISLAND_SLOT, isBlockIsland, isEditedIsland } from './islands.js';
|
|
9
9
|
import { descriptorOf, markKey, pmMarkFromContent } from './marks.js';
|
|
10
10
|
import { core } from '../lifecycle.js';
|
|
11
11
|
import { hasMarks, isBlockSchema, isInlineSchema, takesLineBreak } from './schema.js';
|
|
12
|
-
/**
|
|
13
|
-
export function codePoints(s) {
|
|
14
|
-
return Array.from(s);
|
|
15
|
-
}
|
|
16
|
-
/** USV length of `s` (code points, not UTF-16 units). */
|
|
12
|
+
/** USV length of `s` (code points, not UTF-16 units): what a character cap counts. */
|
|
17
13
|
export function usvLength(s) {
|
|
18
14
|
let n = 0;
|
|
19
15
|
for (const _ of s)
|
|
@@ -28,39 +24,30 @@ export function usvLength(s) {
|
|
|
28
24
|
export function renderContent(rt, schema) {
|
|
29
25
|
return DOMSerializer.fromSchema(schema).serializeFragment(decode(rt, schema).content);
|
|
30
26
|
}
|
|
27
|
+
/** Each block of `rt` with its text and start. */
|
|
28
|
+
function segmentsOf(rt) {
|
|
29
|
+
const texts = rt.text.split('\n');
|
|
30
|
+
const out = [];
|
|
31
|
+
let at = 0;
|
|
32
|
+
texts.forEach((text, i) => {
|
|
33
|
+
out.push({ block: rt.blocks[i] ?? { id: '', kind: 'para' }, text, start: at });
|
|
34
|
+
at += text.length + 1;
|
|
35
|
+
});
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
31
38
|
/** Decode a `Content` to a PM document under `schema`. */
|
|
32
39
|
export function decode(rt, schema) {
|
|
33
|
-
const
|
|
34
|
-
// Per-line USV start: line i begins after all earlier lines and their `\n`s.
|
|
35
|
-
const starts = [];
|
|
36
|
-
let acc = 0;
|
|
37
|
-
for (let i = 0; i < lineTexts.length; i++) {
|
|
38
|
-
starts.push(acc);
|
|
39
|
-
acc += usvLength(lineTexts[i]) + 1; // +1 for the `\n` boundary
|
|
40
|
-
}
|
|
40
|
+
const segments = segmentsOf(rt);
|
|
41
41
|
// A mark-free schema has nothing to apply marks with, and a `text` field that acquired one
|
|
42
42
|
// anyway (a hand-written document) must open and heal on the next commit, not throw.
|
|
43
|
-
const marks = hasMarks(schema) ? rt.marks
|
|
43
|
+
const marks = hasMarks(schema) ? (rt.marks ?? []) : [];
|
|
44
44
|
const cursor = { i: 0, rt };
|
|
45
|
-
if (isInlineSchema(schema))
|
|
46
|
-
return decodeInline(schema,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// Build leaves (fold `continues` runs), then nest by container prefix.
|
|
52
|
-
const leaves = [];
|
|
53
|
-
for (let i = 0; i < rt.lines.length; i++) {
|
|
54
|
-
const line = rt.lines[i];
|
|
55
|
-
const seg = { text: lineTexts[i] ?? '', startUSV: starts[i] };
|
|
56
|
-
if (line.continues && leaves.length > 0) {
|
|
57
|
-
leaves[leaves.length - 1].segments.push(seg);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
leaves.push({ line, containers: line.containers, segments: [seg] });
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const blocks = groupBlocks(schema, leaves, 0, marks, cursor);
|
|
45
|
+
if (isInlineSchema(schema))
|
|
46
|
+
return decodeInline(schema, segments, marks, cursor);
|
|
47
|
+
if (!isBlockSchema(schema))
|
|
48
|
+
return decodePlain(schema, segments, marks, cursor);
|
|
49
|
+
const containers = new Map((rt.containers ?? []).map((c) => [c.id, c]));
|
|
50
|
+
const blocks = groupBlocks(schema, segments, 0, containers, marks, cursor);
|
|
64
51
|
return schema.nodes.doc.create(null, blocks.length ? blocks : schema.nodes.paragraph.create());
|
|
65
52
|
}
|
|
66
53
|
/**
|
|
@@ -71,12 +58,12 @@ export function decode(rt, schema) {
|
|
|
71
58
|
export function fitsInline(rt) {
|
|
72
59
|
if (core().isInline(rt))
|
|
73
60
|
return true;
|
|
74
|
-
const plain = (
|
|
75
|
-
return (rt.islands
|
|
76
|
-
rt.
|
|
77
|
-
rt.
|
|
78
|
-
|
|
79
|
-
rt.text.
|
|
61
|
+
const plain = (b) => b.kind === 'para' && !b.path?.length;
|
|
62
|
+
return (!rt.islands?.length &&
|
|
63
|
+
rt.blocks.length === 2 &&
|
|
64
|
+
rt.blocks.every(plain) &&
|
|
65
|
+
rt.text.endsWith('\n') &&
|
|
66
|
+
!rt.text.includes(HARD_BREAK));
|
|
80
67
|
}
|
|
81
68
|
/**
|
|
82
69
|
* Whether `rt` decodes under `plainSchema` losing nothing but its marks, which the next commit
|
|
@@ -97,186 +84,127 @@ export function fitsLeaf(rt, leaf) {
|
|
|
97
84
|
return fitsInline(rt);
|
|
98
85
|
if (leaf.plaintext)
|
|
99
86
|
return fitsPlain(rt);
|
|
100
|
-
|
|
87
|
+
const islands = rt.islands ?? [];
|
|
88
|
+
if (!leaf.islands && islands.length)
|
|
101
89
|
return false;
|
|
102
|
-
return
|
|
90
|
+
return islands.every((isl) => isEditedIsland(isl.type));
|
|
103
91
|
}
|
|
104
92
|
/** Inline decode: one paragraph, containers and islands stripped. */
|
|
105
|
-
function decodeInline(schema,
|
|
106
|
-
// An inline field is single-line: stray
|
|
107
|
-
// opens is dropped, so a first edit stores no space nobody typed. Islands are not
|
|
108
|
-
// inline: the slot char is dropped and its entry skipped.
|
|
93
|
+
function decodeInline(schema, segments, marks, cursor) {
|
|
94
|
+
// An inline field is single-line: stray blocks and breaks join with a space. The empty block a
|
|
95
|
+
// trailing `\n` opens is dropped, so a first edit stores no space nobody typed. Islands are not
|
|
96
|
+
// representable inline: the slot char is dropped and its entry skipped.
|
|
109
97
|
const inline = [];
|
|
110
|
-
const last =
|
|
111
|
-
|
|
112
|
-
if (i > 0 && i === last &&
|
|
113
|
-
|
|
98
|
+
const last = segments.length - 1;
|
|
99
|
+
segments.forEach((seg, i) => {
|
|
100
|
+
if (i > 0 && i === last && seg.text === '')
|
|
101
|
+
return;
|
|
114
102
|
if (i > 0)
|
|
115
103
|
inline.push(schema.text(' '));
|
|
116
|
-
inline.push(...buildInline(schema,
|
|
117
|
-
}
|
|
104
|
+
inline.push(...buildInline(schema, seg, marks, cursor, 'inline'));
|
|
105
|
+
});
|
|
118
106
|
const para = schema.nodes.paragraph.create(null, inline);
|
|
119
107
|
return schema.nodes.doc.create(null, para);
|
|
120
108
|
}
|
|
121
109
|
/**
|
|
122
|
-
* Plain decode: a
|
|
123
|
-
*
|
|
124
|
-
* opens flattened.
|
|
110
|
+
* Plain decode: every block a paragraph, a break a `hard_break` in it. Block kinds, containers and
|
|
111
|
+
* islands are dropped, so content {@link fitsPlain} refuses opens flattened.
|
|
125
112
|
*/
|
|
126
|
-
function decodePlain(
|
|
127
|
-
const
|
|
128
|
-
for (let i = 0; i < rt.lines.length; i++) {
|
|
129
|
-
const inline = buildInline(schema, lineTexts[i] ?? '', starts[i], marks, cursor, true);
|
|
130
|
-
const open = paras[paras.length - 1];
|
|
131
|
-
if (rt.lines[i].continues && open)
|
|
132
|
-
open.push(schema.nodes.hard_break.create(), ...inline);
|
|
133
|
-
else
|
|
134
|
-
paras.push(inline);
|
|
135
|
-
}
|
|
136
|
-
const blocks = paras.map((inline) => schema.nodes.paragraph.create(null, inline));
|
|
113
|
+
function decodePlain(schema, segments, marks, cursor) {
|
|
114
|
+
const blocks = segments.map((seg) => schema.nodes.paragraph.create(null, buildInline(schema, seg, marks, cursor, 'plain')));
|
|
137
115
|
return schema.nodes.doc.create(null, blocks.length ? blocks : schema.nodes.paragraph.create());
|
|
138
116
|
}
|
|
139
|
-
/** Nest
|
|
140
|
-
function groupBlocks(schema,
|
|
117
|
+
/** Nest the blocks whose paths agree to `depth` into nodes, one per child of that prefix. */
|
|
118
|
+
function groupBlocks(schema, segments, depth, containers, marks, cursor) {
|
|
141
119
|
const out = [];
|
|
142
120
|
let i = 0;
|
|
143
|
-
while (i <
|
|
144
|
-
const path =
|
|
121
|
+
while (i < segments.length) {
|
|
122
|
+
const path = segments[i].block.path ?? [];
|
|
145
123
|
if (path.length <= depth) {
|
|
146
|
-
out.push(makeLeaf(schema,
|
|
124
|
+
out.push(makeLeaf(schema, segments[i], marks, cursor));
|
|
147
125
|
i++;
|
|
148
126
|
continue;
|
|
149
127
|
}
|
|
150
|
-
const
|
|
151
|
-
if (here.container === 'list_item') {
|
|
152
|
-
// Gather the maximal run of sibling `list_item` leaves at this depth
|
|
153
|
-
// (same ordered/start), then split it into items by `ordinal`.
|
|
154
|
-
const { ordered, start } = here.attrs;
|
|
155
|
-
const instance = instanceOf(here);
|
|
156
|
-
let j = i + 1;
|
|
157
|
-
while (j < leaves.length) {
|
|
158
|
-
const c = atDepth(leaves[j], depth);
|
|
159
|
-
if (!c || c.container !== 'list_item')
|
|
160
|
-
break;
|
|
161
|
-
if (c.attrs.ordered !== ordered || c.attrs.start !== start)
|
|
162
|
-
break;
|
|
163
|
-
// `instance` is the boundary between two adjacent lists; the normalizer
|
|
164
|
-
// numbers a run's `ordinal`s gaplessly from 0, so a reset carries none.
|
|
165
|
-
if (instanceOf(c) !== instance)
|
|
166
|
-
break;
|
|
167
|
-
j++;
|
|
168
|
-
}
|
|
169
|
-
const run = leaves.slice(i, j);
|
|
170
|
-
const items = [];
|
|
171
|
-
let k = 0;
|
|
172
|
-
while (k < run.length) {
|
|
173
|
-
const ord = ordinalAt(run[k], depth);
|
|
174
|
-
let l = k + 1;
|
|
175
|
-
while (l < run.length && ordinalAt(run[l], depth) === ord)
|
|
176
|
-
l++;
|
|
177
|
-
items.push(schema.nodes.list_item.create({ checked: checkedAt(run[k], depth) }, groupBlocks(schema, run.slice(k, l), depth + 1, marks, cursor)));
|
|
178
|
-
k = l;
|
|
179
|
-
}
|
|
180
|
-
const listType = ordered ? schema.nodes.ordered_list : schema.nodes.bullet_list;
|
|
181
|
-
out.push(listType.create(ordered ? { start } : null, items));
|
|
182
|
-
i = j;
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
// The quote, and the whole of what is left: `satisfies` makes a container added upstream a
|
|
186
|
-
// compile error. A wrapper over the run of leaves carrying the identical container
|
|
187
|
-
// (`containerKey`).
|
|
188
|
-
here.container;
|
|
189
|
-
const key = containerKey(here);
|
|
128
|
+
const id = path[depth];
|
|
190
129
|
let j = i + 1;
|
|
191
|
-
while (j <
|
|
192
|
-
const c = atDepth(leaves[j], depth);
|
|
193
|
-
if (!c || containerKey(c) !== key)
|
|
194
|
-
break;
|
|
130
|
+
while (j < segments.length && segments[j].block.path?.[depth] === id)
|
|
195
131
|
j++;
|
|
132
|
+
const run = segments.slice(i, j);
|
|
133
|
+
const container = containers.get(id);
|
|
134
|
+
const inner = (d) => groupBlocks(schema, run, d, containers, marks, cursor);
|
|
135
|
+
switch (container?.kind) {
|
|
136
|
+
case 'list': {
|
|
137
|
+
const items = groupItems(schema, run, depth + 1, containers, marks, cursor);
|
|
138
|
+
out.push(container.attrs.ordered
|
|
139
|
+
? schema.nodes.ordered_list.create({ id, start: container.attrs.start }, items)
|
|
140
|
+
: schema.nodes.bullet_list.create({ id }, items));
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 'quote':
|
|
144
|
+
out.push(schema.nodes.blockquote.create({ id }, inner(depth + 1)));
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
// An item outside a list or a container no record names: a value nothing renders, so its
|
|
148
|
+
// blocks decode in place and the projection settles it.
|
|
149
|
+
out.push(...inner(depth + 1));
|
|
196
150
|
}
|
|
197
|
-
const inner = groupBlocks(schema, leaves.slice(i, j), depth + 1, marks, cursor);
|
|
198
|
-
out.push(schema.nodes.blockquote.create(null, inner));
|
|
199
151
|
i = j;
|
|
200
152
|
}
|
|
201
153
|
return out;
|
|
202
154
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* A container's `instance`, absent meaning the zero a canonical read omits. It tells one container
|
|
222
|
-
* from an adjacent sibling of identical shape, so absent and `0` answer alike.
|
|
223
|
-
*/
|
|
224
|
-
function instanceOf(c) {
|
|
225
|
-
return c.instance ?? 0;
|
|
226
|
-
}
|
|
227
|
-
/** Identity of a container for run gathering: its name and its `instance`, NUL-joined
|
|
228
|
-
* as `markKey` joins a mark's. `list_item` carries its own run rule, so the rest are what
|
|
229
|
-
* key here. */
|
|
230
|
-
function containerKey(c) {
|
|
231
|
-
return `${c.container}\u0000${instanceOf(c)}`;
|
|
155
|
+
/** The items of one list: a `list_item` per run of blocks sharing the item id at `depth`. */
|
|
156
|
+
function groupItems(schema, run, depth, containers, marks, cursor) {
|
|
157
|
+
const items = [];
|
|
158
|
+
let i = 0;
|
|
159
|
+
while (i < run.length) {
|
|
160
|
+
const id = run[i].block.path?.[depth];
|
|
161
|
+
let j = i + 1;
|
|
162
|
+
while (j < run.length && run[j].block.path?.[depth] === id)
|
|
163
|
+
j++;
|
|
164
|
+
const item = id === undefined ? undefined : containers.get(id);
|
|
165
|
+
const checked = item?.kind === 'item' ? (item.attrs?.checked ?? null) : null;
|
|
166
|
+
const body = groupBlocks(schema, run.slice(i, j), depth + 1, containers, marks, cursor);
|
|
167
|
+
items.push(schema.nodes.list_item.create({ id: id ?? null, checked }, body));
|
|
168
|
+
i = j;
|
|
169
|
+
}
|
|
170
|
+
return items;
|
|
232
171
|
}
|
|
233
172
|
/**
|
|
234
|
-
* A single leaf block node from its
|
|
235
|
-
* added upstream is a compile error.
|
|
173
|
+
* A single leaf block node from its record, exhaustive over the closed block vocabulary so a kind
|
|
174
|
+
* added upstream is a compile error. A kind spelled `x-` reads as a paragraph that holds its kind.
|
|
236
175
|
*/
|
|
237
|
-
function makeLeaf(schema,
|
|
238
|
-
const
|
|
239
|
-
|
|
176
|
+
function makeLeaf(schema, seg, marks, cursor) {
|
|
177
|
+
const block = seg.block;
|
|
178
|
+
const id = block.id || null;
|
|
179
|
+
switch (block.kind) {
|
|
240
180
|
case 'rule':
|
|
241
|
-
return schema.nodes.horizontal_rule.create();
|
|
181
|
+
return schema.nodes.horizontal_rule.create({ id });
|
|
242
182
|
case 'code': {
|
|
243
|
-
|
|
244
|
-
const text = leaf.segments.map((s) => s.text).join('\n');
|
|
183
|
+
const text = seg.text.replaceAll(HARD_BREAK, '\n');
|
|
245
184
|
const content = text.length ? [schema.text(text)] : [];
|
|
246
|
-
return schema.nodes.code_block.create({ lang:
|
|
185
|
+
return schema.nodes.code_block.create({ id, lang: block.attrs?.lang ?? null }, content);
|
|
247
186
|
}
|
|
248
|
-
case '
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// no continuation, so the space keeps hand-built content decodable.
|
|
255
|
-
const type = line.kind === 'heading' ? schema.nodes.heading : schema.nodes.paragraph;
|
|
256
|
-
const inline = [];
|
|
257
|
-
leaf.segments.forEach((seg, idx) => {
|
|
258
|
-
if (idx > 0)
|
|
259
|
-
inline.push(takesLineBreak(type) ? schema.nodes.hard_break.create() : schema.text(' '));
|
|
260
|
-
inline.push(...buildInline(schema, seg.text, seg.startUSV, marks, cursor, false));
|
|
261
|
-
});
|
|
262
|
-
return line.kind === 'heading'
|
|
263
|
-
? type.create({ level: line.attrs.level }, inline)
|
|
264
|
-
: type.create(null, inline);
|
|
187
|
+
case 'heading':
|
|
188
|
+
return schema.nodes.heading.create({ id, level: block.attrs.level }, buildInline(schema, seg, marks, cursor, 'heading'));
|
|
189
|
+
case 'para': {
|
|
190
|
+
if (blockIslandSegment(seg, cursor))
|
|
191
|
+
return schema.nodes.island_block.create({ ...islandAttrs(cursor), block: id });
|
|
192
|
+
return schema.nodes.paragraph.create({ id }, buildInline(schema, seg, marks, cursor, 'paragraph'));
|
|
265
193
|
}
|
|
266
194
|
default: {
|
|
267
|
-
const
|
|
268
|
-
return
|
|
195
|
+
const ext = { kind: block.kind, attrs: block.attrs ?? {} };
|
|
196
|
+
return schema.nodes.paragraph.create({ id, ext }, buildInline(schema, seg, marks, cursor, 'paragraph'));
|
|
269
197
|
}
|
|
270
198
|
}
|
|
271
199
|
}
|
|
272
200
|
/**
|
|
273
|
-
* Whether a `para`
|
|
274
|
-
*
|
|
201
|
+
* Whether a `para` block is one block island: its slot alone, backed by an island whose markup is a
|
|
202
|
+
* block.
|
|
275
203
|
*/
|
|
276
|
-
function
|
|
277
|
-
if (
|
|
204
|
+
function blockIslandSegment(seg, cursor) {
|
|
205
|
+
if (seg.text !== ISLAND_SLOT)
|
|
278
206
|
return false;
|
|
279
|
-
const isl = cursor.rt.islands[cursor.i];
|
|
207
|
+
const isl = cursor.rt.islands?.[cursor.i];
|
|
280
208
|
return isl != null && isBlockIsland(isl.type);
|
|
281
209
|
}
|
|
282
210
|
/**
|
|
@@ -285,17 +213,21 @@ function blockIslandLine(leaf, cursor) {
|
|
|
285
213
|
* content): the slot draws nothing, keeping the decode total.
|
|
286
214
|
*/
|
|
287
215
|
function islandAttrs(cursor) {
|
|
288
|
-
const isl = cursor.rt.islands[cursor.i++];
|
|
289
|
-
return isl
|
|
216
|
+
const isl = cursor.rt.islands?.[cursor.i++];
|
|
217
|
+
return isl
|
|
218
|
+
? { id: isl.id, islandType: isl.type, props: isl.props, slots: isl.slots ?? null }
|
|
219
|
+
: null;
|
|
290
220
|
}
|
|
291
221
|
/**
|
|
292
222
|
* Inline nodes for one segment: split text into maximal runs of a constant mark set, lower each
|
|
293
|
-
* `U+FFFC` to an inline island node
|
|
294
|
-
*
|
|
223
|
+
* `U+FFFC` to an inline island node and each `U+2028` to a `hard_break`, or to a space in a host
|
|
224
|
+
* that takes none (`schema.ts` §`takesLineBreak`). An inline host drops slots, keeping the island
|
|
225
|
+
* cursor in step.
|
|
295
226
|
*/
|
|
296
|
-
function buildInline(schema,
|
|
297
|
-
const cps = codePoints(segText);
|
|
227
|
+
function buildInline(schema, seg, marks, cursor, host) {
|
|
298
228
|
const out = [];
|
|
229
|
+
const breaks = host !== 'inline' &&
|
|
230
|
+
takesLineBreak(host === 'heading' ? schema.nodes.heading : schema.nodes.paragraph);
|
|
299
231
|
let runText = '';
|
|
300
232
|
let runKey = '';
|
|
301
233
|
let runMarks = [];
|
|
@@ -305,30 +237,37 @@ function buildInline(schema, segText, segStartUSV, marks, cursor, stripIslands)
|
|
|
305
237
|
runText = '';
|
|
306
238
|
};
|
|
307
239
|
// A mark set changes only where a mark starts or ends; `marks` is the whole list, so resolving
|
|
308
|
-
// per
|
|
309
|
-
const
|
|
310
|
-
const
|
|
240
|
+
// per character would cost the text against every mark.
|
|
241
|
+
const segStart = seg.start;
|
|
242
|
+
const segEnd = segStart + seg.text.length;
|
|
243
|
+
const spanning = marks.filter((m) => m.start < segEnd && m.end > segStart);
|
|
311
244
|
const edges = new Set();
|
|
312
245
|
for (const m of spanning) {
|
|
313
|
-
if (m.start >
|
|
246
|
+
if (m.start > segStart)
|
|
314
247
|
edges.add(m.start);
|
|
315
|
-
if (m.end <
|
|
248
|
+
if (m.end < segEnd)
|
|
316
249
|
edges.add(m.end);
|
|
317
250
|
}
|
|
318
251
|
let active = [];
|
|
319
252
|
let key = '';
|
|
320
253
|
let unresolved = true;
|
|
321
|
-
for (let k = 0; k <
|
|
322
|
-
const
|
|
323
|
-
const pos =
|
|
324
|
-
if (
|
|
254
|
+
for (let k = 0; k < seg.text.length; k++) {
|
|
255
|
+
const ch = seg.text[k];
|
|
256
|
+
const pos = segStart + k;
|
|
257
|
+
if (ch === ISLAND_SLOT) {
|
|
325
258
|
flush();
|
|
326
259
|
const attrs = islandAttrs(cursor);
|
|
327
|
-
if (attrs &&
|
|
260
|
+
if (attrs && host !== 'inline' && host !== 'plain' && schema.nodes.island_inline)
|
|
328
261
|
out.push(schema.nodes.island_inline.create(attrs));
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
262
|
+
runKey = '\0slot';
|
|
263
|
+
unresolved = true;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (ch === HARD_BREAK && breaks) {
|
|
267
|
+
flush();
|
|
268
|
+
out.push(schema.nodes.hard_break.create());
|
|
269
|
+
runKey = '\0break';
|
|
270
|
+
unresolved = true;
|
|
332
271
|
continue;
|
|
333
272
|
}
|
|
334
273
|
if (unresolved || edges.has(pos)) {
|
|
@@ -342,7 +281,7 @@ function buildInline(schema, segText, segStartUSV, marks, cursor, stripIslands)
|
|
|
342
281
|
runKey = key;
|
|
343
282
|
runMarks = buildMarkSet(schema, active);
|
|
344
283
|
}
|
|
345
|
-
runText +=
|
|
284
|
+
runText += ch === HARD_BREAK ? ' ' : ch;
|
|
346
285
|
}
|
|
347
286
|
flush();
|
|
348
287
|
return out;
|
|
@@ -355,7 +294,7 @@ function markSetKey(active) {
|
|
|
355
294
|
// groups by. JSON-joined so a `link:a|strong` url stays distinct from `{link:a} + {strong}`.
|
|
356
295
|
return JSON.stringify(active.map((m) => markKey(descriptorOf(m))).sort());
|
|
357
296
|
}
|
|
358
|
-
/** The PM mark array for an active content mark set
|
|
297
|
+
/** The PM mark array for an active content mark set. */
|
|
359
298
|
function buildMarkSet(schema, active) {
|
|
360
299
|
let set = [];
|
|
361
300
|
for (const m of active) {
|