@prosekit/core 0.8.0 → 0.8.2
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/dist/editor-CjVyjJqw.d.ts +739 -0
- package/dist/editor-DbMrpnmL.js +1319 -0
- package/dist/prosekit-core-test.d.ts +33 -2
- package/dist/prosekit-core-test.js +94 -116
- package/dist/prosekit-core.d.ts +1451 -203
- package/dist/prosekit-core.js +1441 -1438
- package/package.json +21 -11
- package/dist/_tsup-dts-rollup.d.ts +0 -3063
- package/dist/chunk-B3WEP4DD.js +0 -1188
@@ -1,2 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { Editor, EditorInstance, EditorOptions, Extension } from "./editor-CjVyjJqw.js";
|
2
|
+
import { ProseMirrorNode } from "@prosekit/pm/model";
|
3
|
+
|
4
|
+
//#region src/test/test-editor.d.ts
|
5
|
+
|
6
|
+
/**
|
7
|
+
* An editor for testing purposes.
|
8
|
+
* @public
|
9
|
+
*/
|
10
|
+
declare class TestEditor<E extends Extension = Extension> extends Editor<E> {
|
11
|
+
constructor(instance: EditorInstance);
|
12
|
+
/**
|
13
|
+
* Set the editor state to the given document. You can use special tokens
|
14
|
+
* `<a>` and `<b>` to set the anchor and head positions of the selection.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
*
|
18
|
+
* ```ts
|
19
|
+
* const editor = createTestEditor({ extension })
|
20
|
+
* const n = editor.nodes
|
21
|
+
* const doc = n.doc(n.paragraph('<a>Hello<b> world!'))
|
22
|
+
* editor.set(doc) // "Hello" is selected.
|
23
|
+
* ```
|
24
|
+
*/
|
25
|
+
set(doc: ProseMirrorNode): void;
|
26
|
+
dispatchEvent(event: Event): void;
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* @public
|
30
|
+
*/
|
31
|
+
declare function createTestEditor<E extends Extension>(options: EditorOptions<E>): TestEditor<E>;
|
32
|
+
//#endregion
|
33
|
+
export { TestEditor, createTestEditor };
|
@@ -1,130 +1,108 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
EditorInstance,
|
4
|
-
assert,
|
5
|
-
createMarkActions,
|
6
|
-
createNodeActions,
|
7
|
-
isProseMirrorNode,
|
8
|
-
setupEditorExtension
|
9
|
-
} from "./chunk-B3WEP4DD.js";
|
1
|
+
import { Editor, EditorInstance, assert, createMarkActions, createNodeActions, isProseMirrorNode, setupEditorExtension } from "./editor-DbMrpnmL.js";
|
2
|
+
import { NodeSelection, TextSelection } from "@prosekit/pm/state";
|
10
3
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
} else {
|
46
|
-
normalizedChildren.push(child);
|
47
|
-
pos += child.nodeSize;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
const node = type.createAndFill(
|
51
|
-
attrs,
|
52
|
-
normalizedChildren
|
53
|
-
);
|
54
|
-
assert(node, `Failed to create node ${type.name}`);
|
55
|
-
node.tags = tags;
|
56
|
-
return node;
|
4
|
+
//#region src/test/test-builder.ts
|
5
|
+
const createNodeForTest = (type, attrs, children) => {
|
6
|
+
const tags = {};
|
7
|
+
const isTopNode = type === type.schema.topNodeType;
|
8
|
+
let pos = isTopNode ? 0 : 1;
|
9
|
+
const normalizedChildren = [];
|
10
|
+
for (const child of children) if (child.tags) {
|
11
|
+
for (const [key, value] of Object.entries(child.tags)) tags[key] = pos + value;
|
12
|
+
normalizedChildren.push(child);
|
13
|
+
pos += child.nodeSize;
|
14
|
+
} else if (child.isText) {
|
15
|
+
const text = child.text;
|
16
|
+
const re = /<(a|b)>/g;
|
17
|
+
let i = 0;
|
18
|
+
let out = "";
|
19
|
+
for (const match of text.matchAll(re)) {
|
20
|
+
out += text.slice(i, match.index);
|
21
|
+
tags[match[1]] = pos + out.length;
|
22
|
+
i = match.index + match[0].length;
|
23
|
+
}
|
24
|
+
out += text.slice(i);
|
25
|
+
if (out) {
|
26
|
+
normalizedChildren.push(child.type.schema.text(out).mark(child.marks));
|
27
|
+
pos += out.length;
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
normalizedChildren.push(child);
|
31
|
+
pos += child.nodeSize;
|
32
|
+
}
|
33
|
+
const node = type.createAndFill(attrs, normalizedChildren);
|
34
|
+
assert(node, `Failed to create node ${type.name}`);
|
35
|
+
node.tags = tags;
|
36
|
+
return node;
|
57
37
|
};
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
38
|
+
const applyMarkForTest = (mark, children) => {
|
39
|
+
return children.map((node) => {
|
40
|
+
const newNode = node.mark(mark.addToSet(node.marks));
|
41
|
+
newNode.tags = node.tags;
|
42
|
+
return newNode;
|
43
|
+
});
|
64
44
|
};
|
65
45
|
|
66
|
-
|
46
|
+
//#endregion
|
47
|
+
//#region src/test/test-editor.ts
|
67
48
|
function maybeResolve(doc, pos) {
|
68
|
-
|
69
|
-
|
70
|
-
}
|
71
|
-
return void 0;
|
49
|
+
if (pos != null) return doc.resolve(pos);
|
50
|
+
return void 0;
|
72
51
|
}
|
73
52
|
function getSelection(doc) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
} else {
|
81
|
-
return new NodeSelection($a);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
return TextSelection.atStart(doc);
|
53
|
+
const tags = doc.tags;
|
54
|
+
const $a = maybeResolve(doc, tags?.a);
|
55
|
+
const $b = maybeResolve(doc, tags?.b);
|
56
|
+
if ($a) if ($a.parent.inlineContent) return new TextSelection($a, $b);
|
57
|
+
else return new NodeSelection($a);
|
58
|
+
return TextSelection.atStart(doc);
|
85
59
|
}
|
86
60
|
var TestEditorInstance = class extends EditorInstance {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
isProseMirrorNode(content) && !selection ? getSelection(content) : selection
|
96
|
-
);
|
97
|
-
}
|
61
|
+
constructor(extension) {
|
62
|
+
super(extension);
|
63
|
+
this.nodes = createNodeActions(this.schema, this.getState, createNodeForTest);
|
64
|
+
this.marks = createMarkActions(this.schema, this.getState, applyMarkForTest);
|
65
|
+
}
|
66
|
+
setContent(content, selection) {
|
67
|
+
return super.setContent(content, isProseMirrorNode(content) && !selection ? getSelection(content) : selection);
|
68
|
+
}
|
98
69
|
};
|
70
|
+
/**
|
71
|
+
* An editor for testing purposes.
|
72
|
+
* @public
|
73
|
+
*/
|
99
74
|
var TestEditor = class extends Editor {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
75
|
+
constructor(instance) {
|
76
|
+
super(instance);
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Set the editor state to the given document. You can use special tokens
|
80
|
+
* `<a>` and `<b>` to set the anchor and head positions of the selection.
|
81
|
+
*
|
82
|
+
* @example
|
83
|
+
*
|
84
|
+
* ```ts
|
85
|
+
* const editor = createTestEditor({ extension })
|
86
|
+
* const n = editor.nodes
|
87
|
+
* const doc = n.doc(n.paragraph('<a>Hello<b> world!'))
|
88
|
+
* editor.set(doc) // "Hello" is selected.
|
89
|
+
* ```
|
90
|
+
*/
|
91
|
+
set(doc) {
|
92
|
+
return this.setContent(doc);
|
93
|
+
}
|
94
|
+
dispatchEvent(event) {
|
95
|
+
this.view.dispatchEvent(event);
|
96
|
+
}
|
122
97
|
};
|
98
|
+
/**
|
99
|
+
* @public
|
100
|
+
*/
|
123
101
|
function createTestEditor(options) {
|
124
|
-
|
125
|
-
|
126
|
-
|
102
|
+
const extension = setupEditorExtension(options);
|
103
|
+
const instance = new TestEditorInstance(extension);
|
104
|
+
return new TestEditor(instance);
|
127
105
|
}
|
128
|
-
|
129
|
-
|
130
|
-
};
|
106
|
+
|
107
|
+
//#endregion
|
108
|
+
export { createTestEditor };
|