@openleaf-editor/core 0.1.0-beta.2 → 0.1.0-beta.4
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 +127 -0
- package/dist/autolink.d.ts +7 -4
- package/dist/autolink.d.ts.map +1 -1
- package/dist/autolink.js +90 -11
- package/dist/autolink.js.map +1 -1
- package/dist/command-helpers.d.ts +8 -0
- package/dist/command-helpers.d.ts.map +1 -0
- package/dist/command-helpers.js +36 -0
- package/dist/command-helpers.js.map +1 -0
- package/dist/commands.d.ts +21 -63
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +430 -346
- package/dist/commands.js.map +1 -1
- package/dist/css.d.ts +1 -175
- package/dist/css.d.ts.map +1 -1
- package/dist/css.js +1 -516
- package/dist/css.js.map +1 -1
- package/dist/disclosure.d.ts +21 -0
- package/dist/disclosure.d.ts.map +1 -0
- package/dist/disclosure.js +144 -0
- package/dist/disclosure.js.map +1 -0
- package/dist/elements.d.ts +2 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +2 -0
- package/dist/elements.js.map +1 -0
- package/dist/embed.d.ts +1 -51
- package/dist/embed.d.ts.map +1 -1
- package/dist/embed.js +1 -115
- package/dist/embed.js.map +1 -1
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions.d.ts +46 -5
- package/dist/extensions.d.ts.map +1 -1
- package/dist/extensions.js +272 -52
- package/dist/extensions.js.map +1 -1
- package/dist/figure-drag.d.ts +26 -0
- package/dist/figure-drag.d.ts.map +1 -0
- package/dist/figure-drag.js +75 -0
- package/dist/figure-drag.js.map +1 -0
- package/dist/formats.d.ts.map +1 -1
- package/dist/formats.js +19 -7
- package/dist/formats.js.map +1 -1
- package/dist/gapcursor.d.ts +14 -0
- package/dist/gapcursor.d.ts.map +1 -0
- package/dist/gapcursor.js +17 -0
- package/dist/gapcursor.js.map +1 -0
- package/dist/html.d.ts +32 -2
- package/dist/html.d.ts.map +1 -1
- package/dist/html.js +185 -31
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -6
- package/dist/index.js.map +1 -1
- package/dist/insert-commands.d.ts +172 -0
- package/dist/insert-commands.d.ts.map +1 -0
- package/dist/insert-commands.js +560 -0
- package/dist/insert-commands.js.map +1 -0
- package/dist/isolating-selection.d.ts +59 -0
- package/dist/isolating-selection.d.ts.map +1 -0
- package/dist/isolating-selection.js +251 -0
- package/dist/isolating-selection.js.map +1 -0
- package/dist/noneditable.d.ts.map +1 -1
- package/dist/noneditable.js +18 -4
- package/dist/noneditable.js.map +1 -1
- package/dist/plugins.d.ts +20 -2
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +27 -2
- package/dist/plugins.js.map +1 -1
- package/dist/preserve.d.ts +48 -17
- package/dist/preserve.d.ts.map +1 -1
- package/dist/preserve.js +214 -43
- package/dist/preserve.js.map +1 -1
- package/dist/schema.d.ts +15 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +157 -28
- package/dist/schema.js.map +1 -1
- package/dist/structure.d.ts +32 -0
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +53 -10
- package/dist/structure.js.map +1 -1
- package/dist/tables.d.ts +47 -1
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +417 -40
- package/dist/tables.js.map +1 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +1 -0
- package/dist/tokens.d.ts +8 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +54 -6
- package/dist/tokens.js.map +1 -1
- package/dist/url.d.ts +1 -25
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js +1 -77
- package/dist/url.js.map +1 -1
- package/dist/visual-aids.d.ts +11 -1
- package/dist/visual-aids.d.ts.map +1 -1
- package/dist/visual-aids.js +124 -36
- package/dist/visual-aids.js.map +1 -1
- package/package.json +17 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dragging the image inside a captioned figure must move the figure.
|
|
3
|
+
*
|
|
4
|
+
* `image` is `draggable: true`; `figure` is not. ProseMirror's dragstart
|
|
5
|
+
* therefore builds a NodeSelection on the `<img>` (`pos.inside` is the image,
|
|
6
|
+
* not the figure), and the default drop moves only that node. The caption
|
|
7
|
+
* stays behind. An image-less `<figure><figcaption>` is illegal on the next
|
|
8
|
+
* parse.
|
|
9
|
+
*
|
|
10
|
+
* Marking `figure` draggable is not enough -- mousedown still resolves to the
|
|
11
|
+
* image. Making figure an atom would kill caption editing. Caption text
|
|
12
|
+
* drags are left alone: only a NodeSelection on the image whose parent is
|
|
13
|
+
* figure is claimed.
|
|
14
|
+
*/
|
|
15
|
+
import { Fragment, Slice } from 'prosemirror-model';
|
|
16
|
+
import { NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
17
|
+
import { dropPoint } from 'prosemirror-transform';
|
|
18
|
+
const key = new PluginKey('openleaf-figure-drag');
|
|
19
|
+
function draggedImageInFigure(view) {
|
|
20
|
+
const dragging = view.dragging;
|
|
21
|
+
if (!dragging)
|
|
22
|
+
return null;
|
|
23
|
+
// dragstart stores the image NodeSelection on `dragging.node` and does not
|
|
24
|
+
// dispatch it. A pre-selected image drag leaves `node` unset and uses the
|
|
25
|
+
// state's NodeSelection instead.
|
|
26
|
+
const sel = dragging.node ??
|
|
27
|
+
(view.state.selection instanceof NodeSelection ? view.state.selection : null);
|
|
28
|
+
if (!sel || sel.node.type.name !== 'image')
|
|
29
|
+
return null;
|
|
30
|
+
if (sel.$from.parent.type.name !== 'figure')
|
|
31
|
+
return null;
|
|
32
|
+
return sel;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* If the drag is a NodeSelection on an image inside a figure, insert (or
|
|
36
|
+
* move) the whole figure at `pos`. Returns true when it handled the drop.
|
|
37
|
+
*
|
|
38
|
+
* `copy` is the inverse of ProseMirror's drop `moved` flag: Alt on Mac / Ctrl
|
|
39
|
+
* elsewhere copies. One transaction so undo is a single step.
|
|
40
|
+
*/
|
|
41
|
+
export function dropFigureForDraggedImage(view, pos, copy) {
|
|
42
|
+
if (!view.editable)
|
|
43
|
+
return false;
|
|
44
|
+
const sel = draggedImageInFigure(view);
|
|
45
|
+
if (!sel)
|
|
46
|
+
return false;
|
|
47
|
+
const figure = sel.$from.parent;
|
|
48
|
+
const from = sel.$from.before(sel.$from.depth);
|
|
49
|
+
const slice = new Slice(Fragment.from(figure), 0, 0);
|
|
50
|
+
const insertPos = dropPoint(view.state.doc, pos, slice);
|
|
51
|
+
if (insertPos == null)
|
|
52
|
+
return false;
|
|
53
|
+
const tr = view.state.tr;
|
|
54
|
+
if (!copy)
|
|
55
|
+
tr.delete(from, from + figure.nodeSize);
|
|
56
|
+
const dest = tr.mapping.map(insertPos);
|
|
57
|
+
tr.insert(dest, figure);
|
|
58
|
+
tr.setSelection(NodeSelection.create(tr.doc, dest));
|
|
59
|
+
view.dispatch(tr.scrollIntoView());
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
export function figureDragPlugin() {
|
|
63
|
+
return new Plugin({
|
|
64
|
+
key,
|
|
65
|
+
props: {
|
|
66
|
+
handleDrop(view, event, _slice, moved) {
|
|
67
|
+
const coords = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
68
|
+
if (!coords)
|
|
69
|
+
return false;
|
|
70
|
+
return dropFigureForDraggedImage(view, coords.pos, !moved);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=figure-drag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"figure-drag.js","sourceRoot":"","sources":["../src/figure-drag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO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C,CAAA;YAC5D,CAAC;SACF;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/formats.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG7D,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;CACd;AAED,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,iFAAiF;IACjF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CActD;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,EAAE,CAgB9E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIxD;
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG7D,MAAM,WAAW,UAAU;IACzB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;CACd;AAED,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,iFAAiF;IACjF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CActD;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,EAAE,CAgB9E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIxD;AAyBD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAMlE;AAYD,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAa/D"}
|
package/dist/formats.js
CHANGED
|
@@ -61,15 +61,27 @@ export function carriedClass(node) {
|
|
|
61
61
|
const value = carried?.['class'];
|
|
62
62
|
return value && value.trim() !== '' ? value : null;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Every text block in the selection, over every selected RANGE.
|
|
66
|
+
*
|
|
67
|
+
* `selection.from`/`to` are one range's bounds, so a table column selection --
|
|
68
|
+
* which is one range per cell -- reported a single cell's paragraph and the
|
|
69
|
+
* format was applied to just that one. See `selectedRanges` in commands.ts.
|
|
70
|
+
*/
|
|
64
71
|
function textBlocks(state) {
|
|
65
72
|
const found = [];
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
for (const range of state.selection.ranges) {
|
|
75
|
+
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
|
76
|
+
if (!node.isTextblock)
|
|
77
|
+
return true;
|
|
78
|
+
if (!seen.has(pos)) {
|
|
79
|
+
seen.add(pos);
|
|
80
|
+
found.push({ pos, node });
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
73
85
|
return found;
|
|
74
86
|
}
|
|
75
87
|
/** The class shared by every selected text block, or null if mixed or absent. */
|
package/dist/formats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAiB9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAChC,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;IACpF,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IAC5C,MAAM,OAAO,GAAG,OAAO;SACpB,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;SACd,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAA;IAChC,OAAO;QACL,OAAO,EAAE,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;QACxC,SAAS,EAAE,OAAO,C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AE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAmC,IAAI,EAAE,CAAC,EAAE,CAAA;IAC1F,IAAI,SAAS;QAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;;QACtC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B,OAAO;QACL,GAAG,IAAI,CAAC,KAAK;QACb,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;KACjE,CAAA;AACH,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,aAAa,CAAC,SAAwB;IACpD,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACzB,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAChC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QACrC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;YACnB,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;gBACnC,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;YAC9D,CAAC;YACD,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,CAAA;QAC/B,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A caret beside a block atom or isolating node.
|
|
3
|
+
*
|
|
4
|
+
* Several core nodes are leaves (`page_break`, `video`, `audio`, `iframe`) or
|
|
5
|
+
* isolating blocks (`details`, preserved unknown blocks). The document can be
|
|
6
|
+
* *only* one of those, or two of them adjacent, and there is then no textblock
|
|
7
|
+
* for the caret. ArrowLeft on a selected page-break stayed a `NodeSelection`;
|
|
8
|
+
* the next keystroke replaced the atom (#164).
|
|
9
|
+
*
|
|
10
|
+
* `prosemirror-gapcursor` is the plugin this schema shape exists for. Tab is
|
|
11
|
+
* not bound by it — that key remains the way out of the editor.
|
|
12
|
+
*/
|
|
13
|
+
export declare function gapCursorPlugin(): import("prosemirror-state").Plugin<any>;
|
|
14
|
+
//# sourceMappingURL=gapcursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gapcursor.d.ts","sourceRoot":"","sources":["../src/gapcursor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,wBAAgB,eAAe,4CAE9B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A caret beside a block atom or isolating node.
|
|
3
|
+
*
|
|
4
|
+
* Several core nodes are leaves (`page_break`, `video`, `audio`, `iframe`) or
|
|
5
|
+
* isolating blocks (`details`, preserved unknown blocks). The document can be
|
|
6
|
+
* *only* one of those, or two of them adjacent, and there is then no textblock
|
|
7
|
+
* for the caret. ArrowLeft on a selected page-break stayed a `NodeSelection`;
|
|
8
|
+
* the next keystroke replaced the atom (#164).
|
|
9
|
+
*
|
|
10
|
+
* `prosemirror-gapcursor` is the plugin this schema shape exists for. Tab is
|
|
11
|
+
* not bound by it — that key remains the way out of the editor.
|
|
12
|
+
*/
|
|
13
|
+
import { gapCursor } from 'prosemirror-gapcursor';
|
|
14
|
+
export function gapCursorPlugin() {
|
|
15
|
+
return gapCursor();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=gapcursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gapcursor.js","sourceRoot":"","sources":["../src/gapcursor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,MAAM,UAAU,eAAe;IAC7B,OAAO,SAAS,EAAE,CAAA;AACpB,CAAC"}
|
package/dist/html.d.ts
CHANGED
|
@@ -13,9 +13,39 @@ export interface HtmlIOOptions {
|
|
|
13
13
|
/** Schema to parse against. Defaults to the built-in one. */
|
|
14
14
|
schema?: Schema;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* How deep a parsed tree may nest.
|
|
18
|
+
*
|
|
19
|
+
* ProseMirror's DOM parser recurses once per element, and so does the serializer
|
|
20
|
+
* on the way back, so a document deep enough overflows the JavaScript stack
|
|
21
|
+
* before either finishes. Measured on Node 26 at the default stack size:
|
|
22
|
+
* `'<div>'.repeat(5000)` -- 30 KB of markup -- throws `RangeError: Maximum call
|
|
23
|
+
* stack size exceeded`, while a 2 MB *flat* document parses without complaint.
|
|
24
|
+
* Depth is the problem, not size, which is what makes it reachable by an
|
|
25
|
+
* attacker with a small payload.
|
|
26
|
+
*
|
|
27
|
+
* 500 is far above anything authored and far below where any engine gives out.
|
|
28
|
+
* The deepest structure real content produces is quoted email, and that runs to
|
|
29
|
+
* tens of levels, not hundreds.
|
|
30
|
+
*/
|
|
31
|
+
export declare const MAX_PARSE_DEPTH = 500;
|
|
32
|
+
/**
|
|
33
|
+
* Parse an HTML string into an OpenLeaf document.
|
|
34
|
+
*
|
|
35
|
+
* Throws `OpenLeafError` with code `invalid-argument` for a non-string, and
|
|
36
|
+
* `depth-limit` for input nested past {@link MAX_PARSE_DEPTH}. It used to coerce
|
|
37
|
+
* anything at all -- `parseHtml(42)` returned an empty document -- which turned
|
|
38
|
+
* a caller's type error into silent content loss.
|
|
39
|
+
*/
|
|
17
40
|
export declare function parseHtml(html: string, opts?: HtmlIOOptions): PMNode;
|
|
18
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Serialize an OpenLeaf document back to an HTML string.
|
|
43
|
+
*
|
|
44
|
+
* Throws `OpenLeafError` with code `invalid-argument` for anything that is not a
|
|
45
|
+
* ProseMirror node. `serializeHtml(null)` used to surface a raw
|
|
46
|
+
* `TypeError: Cannot read properties of null (reading 'type')` from inside
|
|
47
|
+
* ProseMirror, with nothing in it naming OpenLeaf or the call that was wrong.
|
|
48
|
+
*/
|
|
19
49
|
export declare function serializeHtml(node: PMNode, opts?: HtmlIOOptions): string;
|
|
20
50
|
/** Convenience: one full parse/serialize cycle. */
|
|
21
51
|
export declare function roundTrip(html: string, opts?: HtmlIOOptions): string;
|
package/dist/html.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA4B,KAAK,IAAI,IAAI,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA4B,KAAK,IAAI,IAAI,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAuC9F,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAcD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,MAAM,CAAA;AAkClC;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM,CA2BpE;AA8GD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM,CAqBxE;AAED,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,MAAM,CAEpE"}
|
package/dist/html.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
import { DOMParser, DOMSerializer } from 'prosemirror-model';
|
|
10
10
|
import { isInsidePreserved, withSerializationDocument } from './preserve.js';
|
|
11
11
|
import { coreSchema } from './extensions.js';
|
|
12
|
+
import { OpenLeafError } from './errors.js';
|
|
13
|
+
import { tableSectionRowCounts } from './tables.js';
|
|
12
14
|
/**
|
|
13
15
|
* Parsers and serializers are resolved per schema rather than built once.
|
|
14
16
|
*
|
|
@@ -42,61 +44,212 @@ function serializerFor(target) {
|
|
|
42
44
|
function resolveDocument(opts) {
|
|
43
45
|
const doc = opts?.document ?? (typeof document !== 'undefined' ? document : undefined);
|
|
44
46
|
if (!doc) {
|
|
45
|
-
throw new
|
|
47
|
+
throw new OpenLeafError('no-document', '@openleaf-editor/core: no Document available. Pass { document } when ' +
|
|
46
48
|
'running outside a browser.');
|
|
47
49
|
}
|
|
48
50
|
return doc;
|
|
49
51
|
}
|
|
50
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* How deep a parsed tree may nest.
|
|
54
|
+
*
|
|
55
|
+
* ProseMirror's DOM parser recurses once per element, and so does the serializer
|
|
56
|
+
* on the way back, so a document deep enough overflows the JavaScript stack
|
|
57
|
+
* before either finishes. Measured on Node 26 at the default stack size:
|
|
58
|
+
* `'<div>'.repeat(5000)` -- 30 KB of markup -- throws `RangeError: Maximum call
|
|
59
|
+
* stack size exceeded`, while a 2 MB *flat* document parses without complaint.
|
|
60
|
+
* Depth is the problem, not size, which is what makes it reachable by an
|
|
61
|
+
* attacker with a small payload.
|
|
62
|
+
*
|
|
63
|
+
* 500 is far above anything authored and far below where any engine gives out.
|
|
64
|
+
* The deepest structure real content produces is quoted email, and that runs to
|
|
65
|
+
* tens of levels, not hundreds.
|
|
66
|
+
*/
|
|
67
|
+
export const MAX_PARSE_DEPTH = 500;
|
|
68
|
+
/**
|
|
69
|
+
* Reject over-deep input before the recursive parse meets it.
|
|
70
|
+
*
|
|
71
|
+
* An explicit stack, so measuring the depth cannot itself overflow. Two parallel
|
|
72
|
+
* arrays rather than an array of pairs: a 2 MB document has ~110,000 elements
|
|
73
|
+
* and the object churn was measurable where two number pushes are not.
|
|
74
|
+
*/
|
|
75
|
+
function assertDepthWithin(root, limit) {
|
|
76
|
+
const nodes = [];
|
|
77
|
+
const depths = [];
|
|
78
|
+
for (const child of Array.from(root.children)) {
|
|
79
|
+
nodes.push(child);
|
|
80
|
+
depths.push(1);
|
|
81
|
+
}
|
|
82
|
+
while (nodes.length > 0) {
|
|
83
|
+
const node = nodes.pop();
|
|
84
|
+
const depth = depths.pop();
|
|
85
|
+
if (depth > limit) {
|
|
86
|
+
throw new OpenLeafError('depth-limit', `@openleaf-editor/core: HTML nests more than ${limit} elements deep. Parsing it ` +
|
|
87
|
+
'recurses once per level and would overflow the stack. This is almost always ' +
|
|
88
|
+
'adversarial input rather than a document somebody wrote.');
|
|
89
|
+
}
|
|
90
|
+
for (const child of Array.from(node.children)) {
|
|
91
|
+
nodes.push(child);
|
|
92
|
+
depths.push(depth + 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parse an HTML string into an OpenLeaf document.
|
|
98
|
+
*
|
|
99
|
+
* Throws `OpenLeafError` with code `invalid-argument` for a non-string, and
|
|
100
|
+
* `depth-limit` for input nested past {@link MAX_PARSE_DEPTH}. It used to coerce
|
|
101
|
+
* anything at all -- `parseHtml(42)` returned an empty document -- which turned
|
|
102
|
+
* a caller's type error into silent content loss.
|
|
103
|
+
*/
|
|
51
104
|
export function parseHtml(html, opts) {
|
|
105
|
+
if (typeof html !== 'string') {
|
|
106
|
+
throw new OpenLeafError('invalid-argument', `@openleaf-editor/core: parseHtml expects an HTML string, received ${typeof html}.`);
|
|
107
|
+
}
|
|
52
108
|
const doc = resolveDocument(opts);
|
|
53
109
|
const tpl = doc.createElement('template');
|
|
54
|
-
|
|
110
|
+
// The DOM parser is itself recursive and gives out at around 20,000 levels,
|
|
111
|
+
// which is *before* the depth check below could run. Its `RangeError` says
|
|
112
|
+
// nothing about what happened or which call caused it, so it is converted
|
|
113
|
+
// rather than allowed to escape.
|
|
114
|
+
try {
|
|
115
|
+
tpl.innerHTML = html;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new OpenLeafError('depth-limit', '@openleaf-editor/core: the HTML could not be parsed -- it is nested too deeply, or too ' +
|
|
119
|
+
'large, for this DOM implementation to handle.', { cause: error });
|
|
120
|
+
}
|
|
121
|
+
assertDepthWithin(tpl.content, MAX_PARSE_DEPTH);
|
|
55
122
|
return parserFor(opts?.schema ?? coreSchema()).parse(tpl.content, {
|
|
56
123
|
preserveWhitespace: false,
|
|
57
124
|
});
|
|
58
125
|
}
|
|
59
126
|
/**
|
|
60
|
-
* Collapse `<
|
|
127
|
+
* Collapse a sole attribute-free `<p>` back to its container's direct children.
|
|
61
128
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
129
|
+
* Several containers hold block content (`table_cell` is `block+`, `list_item`
|
|
130
|
+
* is `paragraph block*`, `blockquote` is `block+`, `details` is `summary
|
|
131
|
+
* block+`). Parsing the overwhelmingly common legacy form -- `<td>text</td>`,
|
|
132
|
+
* `<li>text</li>`, `<blockquote>quoted</blockquote>`, a details body that is
|
|
133
|
+
* just text -- therefore produces a paragraph, and serializing it back would
|
|
134
|
+
* write the wrapper into every list, quote, disclosure and table in a CMS the
|
|
135
|
+
* first time each post is opened and saved.
|
|
67
136
|
*
|
|
68
137
|
* That is a normalization rather than information loss, but "we changed every
|
|
69
|
-
*
|
|
70
|
-
*
|
|
138
|
+
* list in your archive" is not a thing this project gets to do quietly. So a
|
|
139
|
+
* container whose modelled content is exactly one attribute-free paragraph is
|
|
140
|
+
* unwrapped on the way out. For `<details>` that means the body after
|
|
141
|
+
* `<summary>`, not the whole element.
|
|
71
142
|
*
|
|
72
|
-
* The
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
143
|
+
* The same rule as cells still applies to mixed content: `<li>a<ul><li>b</li>
|
|
144
|
+
* </ul></li>` parses to a paragraph plus a nested list, so the outer paragraph
|
|
145
|
+
* stays. The inner item is a sole paragraph and unwraps.
|
|
146
|
+
*
|
|
147
|
+
* The asymmetry is deliberate and worth stating: a container that was authored
|
|
148
|
+
* as `<li><p>text</p></li>` also comes back as `<li>text</li>`. That form is
|
|
149
|
+
* rare in the content this editor inherits, and the alternative is rewriting
|
|
150
|
+
* the common case instead of the rare one.
|
|
76
151
|
*/
|
|
77
|
-
function
|
|
78
|
-
for (const
|
|
79
|
-
// Never reach inside preserved markup. A
|
|
152
|
+
function unwrapSoleParagraph(host) {
|
|
153
|
+
for (const container of Array.from(host.querySelectorAll('td, th, li, blockquote, details'))) {
|
|
154
|
+
// Never reach inside preserved markup. A list nested in an unrecognised
|
|
80
155
|
// wrapper is content we undertook to return byte-identical, and a
|
|
81
|
-
// normalization that is right for our own
|
|
82
|
-
if (isInsidePreserved(
|
|
156
|
+
// normalization that is right for our own nodes is a broken promise there.
|
|
157
|
+
if (isInsidePreserved(container))
|
|
83
158
|
continue;
|
|
84
|
-
|
|
159
|
+
const only = soleAttributeFreeParagraph(container);
|
|
160
|
+
if (!only)
|
|
85
161
|
continue;
|
|
86
|
-
|
|
87
|
-
|
|
162
|
+
while (only.firstChild)
|
|
163
|
+
container.insertBefore(only.firstChild, only);
|
|
164
|
+
container.removeChild(only);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The paragraph this pass is allowed to unwrap, or null.
|
|
169
|
+
*
|
|
170
|
+
* `details` always has a `<summary>` sibling, so "entire content is one `<p>`"
|
|
171
|
+
* would never fire there. Everything else uses the cell rule: one child node,
|
|
172
|
+
* and it is an attribute-free `<p>`.
|
|
173
|
+
*/
|
|
174
|
+
function soleAttributeFreeParagraph(container) {
|
|
175
|
+
const candidates = container.nodeName === 'DETAILS'
|
|
176
|
+
? Array.from(container.childNodes).filter((node) => !(node.nodeType === 1 && node.nodeName === 'SUMMARY'))
|
|
177
|
+
: Array.from(container.childNodes);
|
|
178
|
+
if (candidates.length !== 1)
|
|
179
|
+
return null;
|
|
180
|
+
const only = candidates[0];
|
|
181
|
+
if (!only || only.nodeType !== 1)
|
|
182
|
+
return null;
|
|
183
|
+
const el = only;
|
|
184
|
+
if (el.nodeName !== 'P' || el.attributes.length > 0)
|
|
185
|
+
return null;
|
|
186
|
+
return el;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Put a table's rows back into the `<thead>` and `<tfoot>` they came from.
|
|
190
|
+
*
|
|
191
|
+
* A table node holds nothing but rows -- `prosemirror-tables` requires that, see
|
|
192
|
+
* tables.ts -- and a node renders through a single `contentDOM`, so `toDOM` can
|
|
193
|
+
* emit one section and no more. The grouping is therefore restored here, from
|
|
194
|
+
* the row counts tables.ts recorded against the element it built.
|
|
195
|
+
*
|
|
196
|
+
* Only for tables that HAD a section. Deriving a `<thead>` from the presence of
|
|
197
|
+
* `<th>` cells would look like an improvement and would rewrite every table in
|
|
198
|
+
* an archive that never used one, which is the change `unwrapSoleParagraph`
|
|
199
|
+
* argues at length this project does not get to make quietly.
|
|
200
|
+
*
|
|
201
|
+
* The counts are clamped rather than trusted, because the document can have
|
|
202
|
+
* changed since it was parsed: an author who deletes the header row of a table
|
|
203
|
+
* whose node still says `headerRows: 1` gets a table with one fewer section, not
|
|
204
|
+
* a `<thead>` built out of their first data row and not a thrown error. The
|
|
205
|
+
* `<tbody>` goes away entirely if every row left it, so a table that was all
|
|
206
|
+
* `<thead>` does not come back with an empty body it never had.
|
|
207
|
+
*/
|
|
208
|
+
function restoreTableSections(host, doc) {
|
|
209
|
+
for (const table of Array.from(host.querySelectorAll('table'))) {
|
|
210
|
+
// Same rule as the cell pass: a table inside preserved markup is content we
|
|
211
|
+
// undertook to hand back byte-identical, and its sections are already in the
|
|
212
|
+
// preserved string. Restructuring there would be a broken promise.
|
|
213
|
+
if (isInsidePreserved(table))
|
|
88
214
|
continue;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (cell.childNodes.length !== 1)
|
|
215
|
+
const counts = tableSectionRowCounts(table);
|
|
216
|
+
if (!counts)
|
|
92
217
|
continue;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
218
|
+
const tbody = Array.from(table.children).find((child) => child.nodeName === 'TBODY');
|
|
219
|
+
if (!tbody)
|
|
220
|
+
continue;
|
|
221
|
+
const rows = Array.from(tbody.children).filter((child) => child.nodeName === 'TR');
|
|
222
|
+
const header = Math.min(counts.header, rows.length);
|
|
223
|
+
const footer = Math.min(counts.footer, rows.length - header);
|
|
224
|
+
if (header > 0) {
|
|
225
|
+
const thead = doc.createElement('thead');
|
|
226
|
+
for (const row of rows.slice(0, header))
|
|
227
|
+
thead.appendChild(row);
|
|
228
|
+
table.insertBefore(thead, tbody);
|
|
229
|
+
}
|
|
230
|
+
if (footer > 0) {
|
|
231
|
+
const tfoot = doc.createElement('tfoot');
|
|
232
|
+
for (const row of rows.slice(rows.length - footer))
|
|
233
|
+
tfoot.appendChild(row);
|
|
234
|
+
table.insertBefore(tfoot, tbody.nextSibling);
|
|
235
|
+
}
|
|
236
|
+
if (!tbody.hasChildNodes())
|
|
237
|
+
table.removeChild(tbody);
|
|
96
238
|
}
|
|
97
239
|
}
|
|
98
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* Serialize an OpenLeaf document back to an HTML string.
|
|
242
|
+
*
|
|
243
|
+
* Throws `OpenLeafError` with code `invalid-argument` for anything that is not a
|
|
244
|
+
* ProseMirror node. `serializeHtml(null)` used to surface a raw
|
|
245
|
+
* `TypeError: Cannot read properties of null (reading 'type')` from inside
|
|
246
|
+
* ProseMirror, with nothing in it naming OpenLeaf or the call that was wrong.
|
|
247
|
+
*/
|
|
99
248
|
export function serializeHtml(node, opts) {
|
|
249
|
+
if (node === null || typeof node !== 'object' || !('type' in node) || !('content' in node)) {
|
|
250
|
+
throw new OpenLeafError('invalid-argument', '@openleaf-editor/core: serializeHtml expects a ProseMirror node, such as ' +
|
|
251
|
+
'`view.state.doc`.');
|
|
252
|
+
}
|
|
100
253
|
const doc = resolveDocument(opts);
|
|
101
254
|
return withSerializationDocument(doc, () => {
|
|
102
255
|
// Taken from the document itself, so a document built on an extended schema
|
|
@@ -106,7 +259,8 @@ export function serializeHtml(node, opts) {
|
|
|
106
259
|
const fragment = serializerFor(target).serializeFragment(node.content, { document: doc });
|
|
107
260
|
const host = doc.createElement('div');
|
|
108
261
|
host.appendChild(fragment);
|
|
109
|
-
|
|
262
|
+
unwrapSoleParagraph(host);
|
|
263
|
+
restoreTableSections(host, doc);
|
|
110
264
|
return host.innerHTML;
|
|
111
265
|
});
|
|
112
266
|
}
|
package/dist/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAoC,MAAM,mBAAmB,CAAA;AAC9F,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAoC,MAAM,mBAAmB,CAAA;AAC9F,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,GAAG,IAAI,OA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AA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;IACjC,OAAO,yBAAyB,CAAC,GAAG,EAAE,GAAG,EAAE;QACzC,4EAA4E;QAC5E,4EAA4E;QAC5E,uEAAuE;QACvE,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA;QAC/C,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAA;QACzF,MAAM,IAAI,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QACrC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC1B,mBAAmB,CAAC,IAAI,CAAC,CAAA;QACzB,oBAAoB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAoB;IAC1D,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;AACnD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProseMirror types re-exported so a plugin needs no direct dependency on
|
|
3
|
+
* ProseMirror to be written against this API.
|
|
4
|
+
*
|
|
5
|
+
* Type-only, so they add nothing to any bundle. Without them, writing a
|
|
6
|
+
* `Command` or a `NodeSpec` meant adding `prosemirror-state` and
|
|
7
|
+
* `prosemirror-model` to the plugin's own package -- and getting a *second*
|
|
8
|
+
* copy of either of them is how a node built by one schema stops being a node
|
|
9
|
+
* type the editor accepts.
|
|
10
|
+
*/
|
|
11
|
+
export type { Command } from 'prosemirror-state';
|
|
12
|
+
export type { MarkSpec, NodeSpec, Schema } from 'prosemirror-model';
|
|
13
|
+
export { OpenLeafError, isOpenLeafError, type OpenLeafErrorCode } from './errors.js';
|
|
1
14
|
export { baseSchema, coreMarks, coreNodes } from './schema.js';
|
|
2
15
|
export { ALIGNMENTS, COLOUR_PROPERTIES, FONT_FAMILIES, FONT_SIZE_PRESETS, INDENT_EM, INLINE_STYLE_PROPERTIES, LINE_HEIGHT_PRESETS, LIST_STYLES, MAX_INDENT, MODELLED_PROPERTIES, indentCss, indentLevels, isFullyModelledStyle, modelledValue, parseDeclarations, safeAlign, safeColor, safeDir, safeFontFamily, safeFontSize, safeLang, safeLineHeight, safeListStyle, serializeDeclarations, type Align, type Dir, type ListStyle, } from './css.js';
|
|
3
|
-
export { parseHtml, serializeHtml, roundTrip, type HtmlIOOptions } from './html.js';
|
|
4
|
-
export { isLosslesslyUnwrappable, unknownBlock, unknownInline } from './preserve.js';
|
|
16
|
+
export { MAX_PARSE_DEPTH, parseHtml, serializeHtml, roundTrip, type HtmlIOOptions } from './html.js';
|
|
17
|
+
export { isLosslesslyUnwrappable, isInsidePreserved, unknownBlock, unknownInline, } from './preserve.js';
|
|
5
18
|
export { URL_ATTRIBUTES, isEventHandlerAttribute, isSafeUrl, safeUrlOrNull, } from './url.js';
|
|
6
|
-
export { EMBED_HOSTS, isAllowedEmbedSrc, safeAllowList, safeEmbedSrc, type EmbedHostRule, } from './embed.js';
|
|
19
|
+
export { EMBED_HOSTS, embedSrcFor, isAllowedEmbedSrc, safeAllowList, safeEmbedSrc, type EmbedHostRule, } from './embed.js';
|
|
7
20
|
export { IMAGE_ALIGNMENTS, IMAGE_ALIGN_CLASS, IMAGE_ALIGN_CLASSES, imageAlignFromClass, safeClassList, safeId, type ImageAlign, } from './tokens.js';
|
|
8
|
-
export { activeBackgroundColor, activeDir, activeFontFamily, activeFontSize, activeHeadingLevel, activeIndent, activeLanguage, activeLineHeight, activeLink, activeListStyle, activeTextAlign, activeTextColor, canInsert, canRedo, canUndo, isMarkActive, isNodeActive, toggleBold, toggleInlineCode, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, clearBackgroundColor, clearTextColor, setBackgroundColor, setTextColor, setFontFamily, setFontSize, setLanguage, clearFormatting, insertHorizontalRule, setDir, setHeading, setLineHeight, setParagraph, setTextAlign, toggleBlockquote, toggleCodeBlock, toggleDir, toggleHeading, toggleTextAlign, wrapInBlockquote, insertAudio, insertDetails, insertHtml, insertIframe, insertNamedAnchor, insertNonBreakingSpace, insertPageBreak, insertText, insertVideo, setHeadingId, indent, indentListItem, outdent, outdentListItem, setListStyle, splitListItemCommand, toggleBulletList, toggleOrderedList, insertImage, setLink, unsetLink, type ImageAttrs, type LinkAttrs, type MediaAttrs, redo, undo, } from './commands.js';
|
|
21
|
+
export { activeBackgroundColor, activeDir, activeFontFamily, activeFontSize, activeHeadingLevel, activeIndent, activeLanguage, activeLineHeight, activeLink, activeListStyle, activeTextAlign, activeTextColor, canInsert, canRedo, canUndo, isMarkActive, isNodeActive, toggleBold, toggleInlineCode, toggleItalic, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline, clearBackgroundColor, clearTextColor, setBackgroundColor, setTextColor, setFontFamily, setFontSize, setLanguage, clearFormatting, insertHorizontalRule, setDir, setHeading, setLineHeight, setParagraph, setTextAlign, toggleBlockquote, toggleCodeBlock, toggleDir, toggleHeading, toggleTextAlign, wrapInBlockquote, insertAudio, insertDetails, insertHtml, insertIframe, insertNamedAnchor, insertNonBreakingSpace, insertPageBreak, insertText, insertVideo, setHeadingId, indent, indentListItem, outdent, outdentListItem, setListStyle, splitListItemCommand, toggleBulletList, toggleOrderedList, insertImage, selectedImage, selectedMedia, setLink, unsetLink, updateImage, updateMedia, type ImageAttrs, type LinkAttrs, type MediaAttrs, type MediaSource, type SelectedImage, type SelectedMedia, redo, undo, } from './commands.js';
|
|
9
22
|
export { buildKeymap, shortcutFor, shortcuts, type Shortcut, } from './keymap.js';
|
|
10
23
|
export { autolinkPlugin, hrefFromTypedUrl } from './autolink.js';
|
|
11
24
|
export { visualAidsPlugin } from './visual-aids.js';
|
|
25
|
+
export { disclosurePlugin } from './disclosure.js';
|
|
26
|
+
export { gapCursorPlugin } from './gapcursor.js';
|
|
27
|
+
export { clampIsolatingTextSelection, innermostIsolatingDepth, isolatingSelectionPlugin, textSelectionCrossesIsolating, } from './isolating-selection.js';
|
|
28
|
+
export { figureDragPlugin } from './figure-drag.js';
|
|
12
29
|
export { isNonEditableNode, nonEditablePlugin } from './noneditable.js';
|
|
13
30
|
export { activeBlockClass, carriedClass, formatParts, parseFormatList, setBlockClass, type FormatParts, type FormatSpec, } from './formats.js';
|
|
14
31
|
export { createRegisteredPlugins, onEditorPluginsChange, registerEditorPlugin, type EditorPluginFactory, } from './plugins.js';
|
|
15
|
-
export { safeTableStyleValue,
|
|
16
|
-
export {
|
|
32
|
+
export { safeTableStyleValue, tableCaptionPlugin } from './tables.js';
|
|
33
|
+
export { coreSchema, createSchema, onSchemaExtensionsChange, registerSchemaExtension, registeredSchemaExtensions, type SchemaExtension, } from './extensions.js';
|
|
17
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,OAAO,EACP,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,KAAK,KAAK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