@prosekit/core 0.6.0 → 0.7.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/dist/_tsup-dts-rollup.d.ts +293 -48
- package/dist/chunk-YWQGKV6X.js +863 -0
- package/dist/prosekit-core-test.d.ts +2 -0
- package/dist/prosekit-core-test.js +101 -0
- package/dist/prosekit-core.d.ts +6 -1
- package/dist/prosekit-core.js +81 -821
- package/package.json +12 -4
@@ -0,0 +1,101 @@
|
|
1
|
+
import {
|
2
|
+
Editor,
|
3
|
+
EditorInstance,
|
4
|
+
assert,
|
5
|
+
createMarkBuilders,
|
6
|
+
createNodeBuilders,
|
7
|
+
setupEditorExtension
|
8
|
+
} from "./chunk-YWQGKV6X.js";
|
9
|
+
|
10
|
+
// src/test/test-editor.ts
|
11
|
+
import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
|
12
|
+
|
13
|
+
// src/test/test-builder.ts
|
14
|
+
var createNodeForTest = (type, attrs, children) => {
|
15
|
+
let tags = {}, pos = type === type.schema.topNodeType ? 0 : 1, normalizedChildren = [];
|
16
|
+
for (let child of children)
|
17
|
+
if (child.tags) {
|
18
|
+
for (let [key, value] of Object.entries(child.tags))
|
19
|
+
tags[key] = pos + value;
|
20
|
+
normalizedChildren.push(child), pos += child.nodeSize;
|
21
|
+
} else if (child.isText) {
|
22
|
+
let text = child.text, re = /<(a|b)>/g, i = 0, out = "";
|
23
|
+
for (let match of text.matchAll(re))
|
24
|
+
out += text.slice(i, match.index), tags[match[1]] = pos + out.length, i = match.index + match[0].length;
|
25
|
+
out += text.slice(i), out && (normalizedChildren.push(child.type.schema.text(out).mark(child.marks)), pos += out.length);
|
26
|
+
} else
|
27
|
+
normalizedChildren.push(child), pos += child.nodeSize;
|
28
|
+
let node = type.createAndFill(
|
29
|
+
attrs,
|
30
|
+
normalizedChildren
|
31
|
+
);
|
32
|
+
return assert(node, `Failed to create node ${type.name}`), node.tags = tags, node;
|
33
|
+
}, applyMarkForTest = (mark, children) => children.map((node) => {
|
34
|
+
let newNode = node.mark([mark]);
|
35
|
+
return newNode.tags = node.tags, newNode;
|
36
|
+
});
|
37
|
+
|
38
|
+
// src/test/test-editor.ts
|
39
|
+
function maybeResolve(doc, pos) {
|
40
|
+
if (pos != null)
|
41
|
+
return doc.resolve(pos);
|
42
|
+
}
|
43
|
+
function getSelection(doc) {
|
44
|
+
let tags = doc.tags, $a = maybeResolve(doc, tags == null ? void 0 : tags.a), $b = maybeResolve(doc, tags == null ? void 0 : tags.b);
|
45
|
+
return $a ? $a.parent.inlineContent ? new TextSelection($a, $b) : new NodeSelection($a) : TextSelection.atStart(doc);
|
46
|
+
}
|
47
|
+
var TestEditorInstance = class extends EditorInstance {
|
48
|
+
constructor(extension) {
|
49
|
+
super(extension), this.nodeBuilders = createNodeBuilders(
|
50
|
+
this.schema,
|
51
|
+
this.getState,
|
52
|
+
createNodeForTest
|
53
|
+
), this.markBuilders = createMarkBuilders(
|
54
|
+
this.schema,
|
55
|
+
this.getState,
|
56
|
+
applyMarkForTest
|
57
|
+
);
|
58
|
+
}
|
59
|
+
}, TestEditor = class extends Editor {
|
60
|
+
constructor(instance) {
|
61
|
+
super(instance);
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* Set the editor state to the given document. You can use special tokens
|
65
|
+
* `<a>` and `<b>` to set the anchor and head positions of the selection.
|
66
|
+
*
|
67
|
+
* @example
|
68
|
+
*
|
69
|
+
* ```ts
|
70
|
+
* const editor = createTestEditor({ extension })
|
71
|
+
* const n = editor.nodes
|
72
|
+
* const doc = n.doc(n.paragraph('<a>Hello<b> world!'))
|
73
|
+
* editor.set(doc) // "Hello" is selected.
|
74
|
+
* ```
|
75
|
+
*/
|
76
|
+
set(doc) {
|
77
|
+
assert(
|
78
|
+
doc.type.schema === this.schema,
|
79
|
+
"Document schema does not match editor schema"
|
80
|
+
), assert(
|
81
|
+
doc.type === this.schema.topNodeType,
|
82
|
+
"Document type does not match editor top node type"
|
83
|
+
);
|
84
|
+
let selection = getSelection(doc), state = EditorState.create({
|
85
|
+
doc,
|
86
|
+
selection,
|
87
|
+
plugins: this.state.plugins
|
88
|
+
});
|
89
|
+
this.updateState(state);
|
90
|
+
}
|
91
|
+
dispatchEvent(event) {
|
92
|
+
this.view.dispatchEvent(event);
|
93
|
+
}
|
94
|
+
};
|
95
|
+
function createTestEditor(options) {
|
96
|
+
let extension = setupEditorExtension(options);
|
97
|
+
return new TestEditor(new TestEditorInstance(extension));
|
98
|
+
}
|
99
|
+
export {
|
100
|
+
createTestEditor
|
101
|
+
};
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
export { addMark } from './_tsup-dts-rollup';
|
2
2
|
export { expandMark } from './_tsup-dts-rollup';
|
3
3
|
export { insertNode } from './_tsup-dts-rollup';
|
4
|
-
export { removeNode } from './_tsup-dts-rollup';
|
5
4
|
export { removeMark } from './_tsup-dts-rollup';
|
5
|
+
export { removeNode } from './_tsup-dts-rollup';
|
6
6
|
export { setBlockType } from './_tsup-dts-rollup';
|
7
7
|
export { setNodeAttrs } from './_tsup-dts-rollup';
|
8
8
|
export { toggleMark } from './_tsup-dts-rollup';
|
9
9
|
export { toggleNode } from './_tsup-dts-rollup';
|
10
|
+
export { MarkBuilder } from './_tsup-dts-rollup';
|
11
|
+
export { NodeBuilder } from './_tsup-dts-rollup';
|
10
12
|
export { Editor } from './_tsup-dts-rollup';
|
11
13
|
export { createEditor } from './_tsup-dts-rollup';
|
12
14
|
export { EditorOptions } from './_tsup-dts-rollup';
|
@@ -16,6 +18,8 @@ export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-
|
|
16
18
|
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
17
19
|
export { defineBaseCommands } from './_tsup-dts-rollup';
|
18
20
|
export { defineCommands } from './_tsup-dts-rollup';
|
21
|
+
export { collectNodes } from './_tsup-dts-rollup';
|
22
|
+
export { NodeContent } from './_tsup-dts-rollup';
|
19
23
|
export { defineDefaultState } from './_tsup-dts-rollup';
|
20
24
|
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
21
25
|
export { defineDoc } from './_tsup-dts-rollup';
|
@@ -93,6 +97,7 @@ export { UnionExtension } from './_tsup-dts-rollup';
|
|
93
97
|
export { NodeJSON } from './_tsup-dts-rollup';
|
94
98
|
export { SelectionJSON } from './_tsup-dts-rollup';
|
95
99
|
export { StateJSON } from './_tsup-dts-rollup';
|
100
|
+
export { StepJSON } from './_tsup-dts-rollup';
|
96
101
|
export { Priority } from './_tsup-dts-rollup';
|
97
102
|
export { SimplifyUnion } from './_tsup-dts-rollup';
|
98
103
|
export { assert } from './_tsup-dts-rollup';
|