@prosekit/core 0.7.1 → 0.7.3
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 +295 -152
- package/dist/{chunk-YWQGKV6X.js → chunk-UDQXAK7F.js} +379 -195
- package/dist/prosekit-core-test.js +66 -26
- package/dist/prosekit-core.d.ts +18 -1
- package/dist/prosekit-core.js +690 -327
- package/package.json +3 -3
@@ -5,58 +5,96 @@ import {
|
|
5
5
|
createMarkBuilders,
|
6
6
|
createNodeBuilders,
|
7
7
|
setupEditorExtension
|
8
|
-
} from "./chunk-
|
8
|
+
} from "./chunk-UDQXAK7F.js";
|
9
9
|
|
10
10
|
// src/test/test-editor.ts
|
11
11
|
import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
|
12
12
|
|
13
13
|
// src/test/test-builder.ts
|
14
14
|
var createNodeForTest = (type, attrs, children) => {
|
15
|
-
|
16
|
-
|
15
|
+
const tags = {};
|
16
|
+
const isTopNode = type === type.schema.topNodeType;
|
17
|
+
let pos = isTopNode ? 0 : 1;
|
18
|
+
const normalizedChildren = [];
|
19
|
+
for (const child of children) {
|
17
20
|
if (child.tags) {
|
18
|
-
for (
|
21
|
+
for (const [key, value] of Object.entries(child.tags)) {
|
19
22
|
tags[key] = pos + value;
|
20
|
-
|
23
|
+
}
|
24
|
+
normalizedChildren.push(child);
|
25
|
+
pos += child.nodeSize;
|
21
26
|
} else if (child.isText) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
const text = child.text;
|
28
|
+
const re = /<(a|b)>/g;
|
29
|
+
let i = 0;
|
30
|
+
let out = "";
|
31
|
+
for (const match of text.matchAll(re)) {
|
32
|
+
out += text.slice(i, match.index);
|
33
|
+
tags[match[1]] = pos + out.length;
|
34
|
+
i = match.index + match[0].length;
|
35
|
+
}
|
36
|
+
out += text.slice(i);
|
37
|
+
if (out) {
|
38
|
+
normalizedChildren.push(child.type.schema.text(out).mark(child.marks));
|
39
|
+
pos += out.length;
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
normalizedChildren.push(child);
|
43
|
+
pos += child.nodeSize;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
const node = type.createAndFill(
|
29
47
|
attrs,
|
30
48
|
normalizedChildren
|
31
49
|
);
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
50
|
+
assert(node, `Failed to create node ${type.name}`);
|
51
|
+
node.tags = tags;
|
52
|
+
return node;
|
53
|
+
};
|
54
|
+
var applyMarkForTest = (mark, children) => {
|
55
|
+
return children.map((node) => {
|
56
|
+
const newNode = node.mark([mark]);
|
57
|
+
newNode.tags = node.tags;
|
58
|
+
return newNode;
|
59
|
+
});
|
60
|
+
};
|
37
61
|
|
38
62
|
// src/test/test-editor.ts
|
39
63
|
function maybeResolve(doc, pos) {
|
40
|
-
if (pos != null)
|
64
|
+
if (pos != null) {
|
41
65
|
return doc.resolve(pos);
|
66
|
+
}
|
67
|
+
return void 0;
|
42
68
|
}
|
43
69
|
function getSelection(doc) {
|
44
|
-
|
45
|
-
|
70
|
+
const tags = doc.tags;
|
71
|
+
const $a = maybeResolve(doc, tags == null ? void 0 : tags.a);
|
72
|
+
const $b = maybeResolve(doc, tags == null ? void 0 : tags.b);
|
73
|
+
if ($a) {
|
74
|
+
if ($a.parent.inlineContent) {
|
75
|
+
return new TextSelection($a, $b);
|
76
|
+
} else {
|
77
|
+
return new NodeSelection($a);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
return TextSelection.atStart(doc);
|
46
81
|
}
|
47
82
|
var TestEditorInstance = class extends EditorInstance {
|
48
83
|
constructor(extension) {
|
49
|
-
super(extension)
|
84
|
+
super(extension);
|
85
|
+
this.nodeBuilders = createNodeBuilders(
|
50
86
|
this.schema,
|
51
87
|
this.getState,
|
52
88
|
createNodeForTest
|
53
|
-
)
|
89
|
+
);
|
90
|
+
this.markBuilders = createMarkBuilders(
|
54
91
|
this.schema,
|
55
92
|
this.getState,
|
56
93
|
applyMarkForTest
|
57
94
|
);
|
58
95
|
}
|
59
|
-
}
|
96
|
+
};
|
97
|
+
var TestEditor = class extends Editor {
|
60
98
|
constructor(instance) {
|
61
99
|
super(instance);
|
62
100
|
}
|
@@ -77,11 +115,13 @@ var TestEditorInstance = class extends EditorInstance {
|
|
77
115
|
assert(
|
78
116
|
doc.type.schema === this.schema,
|
79
117
|
"Document schema does not match editor schema"
|
80
|
-
)
|
118
|
+
);
|
119
|
+
assert(
|
81
120
|
doc.type === this.schema.topNodeType,
|
82
121
|
"Document type does not match editor top node type"
|
83
122
|
);
|
84
|
-
|
123
|
+
const selection = getSelection(doc);
|
124
|
+
const state = EditorState.create({
|
85
125
|
doc,
|
86
126
|
selection,
|
87
127
|
plugins: this.state.plugins
|
@@ -93,7 +133,7 @@ var TestEditorInstance = class extends EditorInstance {
|
|
93
133
|
}
|
94
134
|
};
|
95
135
|
function createTestEditor(options) {
|
96
|
-
|
136
|
+
const extension = setupEditorExtension(options);
|
97
137
|
return new TestEditor(new TestEditorInstance(extension));
|
98
138
|
}
|
99
139
|
export {
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -1,12 +1,27 @@
|
|
1
1
|
export { addMark } from './_tsup-dts-rollup';
|
2
|
+
export { AddMarkOptions } from './_tsup-dts-rollup';
|
2
3
|
export { expandMark } from './_tsup-dts-rollup';
|
4
|
+
export { ExpandMarkOptions } from './_tsup-dts-rollup';
|
3
5
|
export { insertNode } from './_tsup-dts-rollup';
|
6
|
+
export { InsertNodeOptions } from './_tsup-dts-rollup';
|
4
7
|
export { removeMark } from './_tsup-dts-rollup';
|
8
|
+
export { RemoveMarkOptions } from './_tsup-dts-rollup';
|
5
9
|
export { removeNode } from './_tsup-dts-rollup';
|
10
|
+
export { RemoveNodeOptions } from './_tsup-dts-rollup';
|
6
11
|
export { setBlockType } from './_tsup-dts-rollup';
|
12
|
+
export { SetBlockTypeOptions } from './_tsup-dts-rollup';
|
7
13
|
export { setNodeAttrs } from './_tsup-dts-rollup';
|
14
|
+
export { SetNodeAttrsOptions } from './_tsup-dts-rollup';
|
8
15
|
export { toggleMark } from './_tsup-dts-rollup';
|
16
|
+
export { ToggleMarkOptions } from './_tsup-dts-rollup';
|
9
17
|
export { toggleNode } from './_tsup-dts-rollup';
|
18
|
+
export { ToggleNodeOptions } from './_tsup-dts-rollup';
|
19
|
+
export { unsetBlockType } from './_tsup-dts-rollup';
|
20
|
+
export { UnsetBlockTypeOptions } from './_tsup-dts-rollup';
|
21
|
+
export { unsetMark } from './_tsup-dts-rollup';
|
22
|
+
export { UnsetMarkOptions } from './_tsup-dts-rollup';
|
23
|
+
export { wrap } from './_tsup-dts-rollup';
|
24
|
+
export { WrapOptions } from './_tsup-dts-rollup';
|
10
25
|
export { MarkBuilder } from './_tsup-dts-rollup';
|
11
26
|
export { NodeBuilder } from './_tsup-dts-rollup';
|
12
27
|
export { Editor } from './_tsup-dts-rollup';
|
@@ -58,11 +73,12 @@ export { MountHandler } from './_tsup-dts-rollup';
|
|
58
73
|
export { UnmountHandler } from './_tsup-dts-rollup';
|
59
74
|
export { UpdateHandler } from './_tsup-dts-rollup';
|
60
75
|
export { defineHistory } from './_tsup-dts-rollup';
|
61
|
-
export {
|
76
|
+
export { HistoryOptions } from './_tsup-dts-rollup';
|
62
77
|
export { defineKeymap } from './_tsup-dts-rollup';
|
63
78
|
export { keymapFacet } from './_tsup-dts-rollup';
|
64
79
|
export { Keymap } from './_tsup-dts-rollup';
|
65
80
|
export { KeymapPayload } from './_tsup-dts-rollup';
|
81
|
+
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
66
82
|
export { defineMarkAttr } from './_tsup-dts-rollup';
|
67
83
|
export { defineMarkSpec } from './_tsup-dts-rollup';
|
68
84
|
export { MarkAttrOptions } from './_tsup-dts-rollup';
|
@@ -110,6 +126,7 @@ export { isApple } from './_tsup-dts-rollup';
|
|
110
126
|
export { _getId } from './_tsup-dts-rollup';
|
111
127
|
export { getMarkType } from './_tsup-dts-rollup';
|
112
128
|
export { getNodeType } from './_tsup-dts-rollup';
|
129
|
+
export { isAtBlockStart } from './_tsup-dts-rollup';
|
113
130
|
export { isInCodeBlock } from './_tsup-dts-rollup';
|
114
131
|
export { isMarkAbsent } from './_tsup-dts-rollup';
|
115
132
|
export { isMarkActive } from './_tsup-dts-rollup';
|