@prosekit/core 0.7.2 → 0.7.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/dist/_tsup-dts-rollup.d.ts +359 -84
- package/dist/{chunk-YWQGKV6X.js → chunk-52BNHWWJ.js} +402 -212
- package/dist/prosekit-core-test.js +67 -35
- package/dist/prosekit-core.d.ts +17 -1
- package/dist/prosekit-core.js +608 -314
- package/package.json +5 -5
@@ -2,61 +2,91 @@ import {
|
|
2
2
|
Editor,
|
3
3
|
EditorInstance,
|
4
4
|
assert,
|
5
|
-
|
6
|
-
|
5
|
+
createMarkActions,
|
6
|
+
createNodeActions,
|
7
7
|
setupEditorExtension
|
8
|
-
} from "./chunk-
|
8
|
+
} from "./chunk-52BNHWWJ.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)
|
50
|
-
|
51
|
-
|
52
|
-
createNodeForTest
|
53
|
-
), this.markBuilders = createMarkBuilders(
|
54
|
-
this.schema,
|
55
|
-
this.getState,
|
56
|
-
applyMarkForTest
|
57
|
-
);
|
84
|
+
super(extension);
|
85
|
+
this.nodes = createNodeActions(this.schema, this.getState, createNodeForTest);
|
86
|
+
this.marks = createMarkActions(this.schema, this.getState, applyMarkForTest);
|
58
87
|
}
|
59
|
-
}
|
88
|
+
};
|
89
|
+
var TestEditor = class extends Editor {
|
60
90
|
constructor(instance) {
|
61
91
|
super(instance);
|
62
92
|
}
|
@@ -77,11 +107,13 @@ var TestEditorInstance = class extends EditorInstance {
|
|
77
107
|
assert(
|
78
108
|
doc.type.schema === this.schema,
|
79
109
|
"Document schema does not match editor schema"
|
80
|
-
)
|
110
|
+
);
|
111
|
+
assert(
|
81
112
|
doc.type === this.schema.topNodeType,
|
82
113
|
"Document type does not match editor top node type"
|
83
114
|
);
|
84
|
-
|
115
|
+
const selection = getSelection(doc);
|
116
|
+
const state = EditorState.create({
|
85
117
|
doc,
|
86
118
|
selection,
|
87
119
|
plugins: this.state.plugins
|
@@ -93,7 +125,7 @@ var TestEditorInstance = class extends EditorInstance {
|
|
93
125
|
}
|
94
126
|
};
|
95
127
|
function createTestEditor(options) {
|
96
|
-
|
128
|
+
const extension = setupEditorExtension(options);
|
97
129
|
return new TestEditor(new TestEditorInstance(extension));
|
98
130
|
}
|
99
131
|
export {
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -22,8 +22,11 @@ export { unsetMark } from './_tsup-dts-rollup';
|
|
22
22
|
export { UnsetMarkOptions } from './_tsup-dts-rollup';
|
23
23
|
export { wrap } from './_tsup-dts-rollup';
|
24
24
|
export { WrapOptions } from './_tsup-dts-rollup';
|
25
|
+
export { MarkAction } from './_tsup-dts-rollup';
|
25
26
|
export { MarkBuilder } from './_tsup-dts-rollup';
|
27
|
+
export { NodeAction } from './_tsup-dts-rollup';
|
26
28
|
export { NodeBuilder } from './_tsup-dts-rollup';
|
29
|
+
export { NodeChild } from './_tsup-dts-rollup';
|
27
30
|
export { Editor } from './_tsup-dts-rollup';
|
28
31
|
export { createEditor } from './_tsup-dts-rollup';
|
29
32
|
export { EditorOptions } from './_tsup-dts-rollup';
|
@@ -73,6 +76,7 @@ export { MountHandler } from './_tsup-dts-rollup';
|
|
73
76
|
export { UnmountHandler } from './_tsup-dts-rollup';
|
74
77
|
export { UpdateHandler } from './_tsup-dts-rollup';
|
75
78
|
export { defineHistory } from './_tsup-dts-rollup';
|
79
|
+
export { HistoryOptions } from './_tsup-dts-rollup';
|
76
80
|
export { defineKeymap } from './_tsup-dts-rollup';
|
77
81
|
export { keymapFacet } from './_tsup-dts-rollup';
|
78
82
|
export { Keymap } from './_tsup-dts-rollup';
|
@@ -100,20 +104,32 @@ export { defineText } from './_tsup-dts-rollup';
|
|
100
104
|
export { defineFacet } from './_tsup-dts-rollup';
|
101
105
|
export { Facet } from './_tsup-dts-rollup';
|
102
106
|
export { defineFacetPayload } from './_tsup-dts-rollup';
|
107
|
+
export { AnyAttrs } from './_tsup-dts-rollup';
|
108
|
+
export { AttrSpec } from './_tsup-dts-rollup';
|
103
109
|
export { BaseNodeViewOptions } from './_tsup-dts-rollup';
|
104
|
-
export { CommandTyping } from './_tsup-dts-rollup';
|
105
110
|
export { Extension } from './_tsup-dts-rollup';
|
106
111
|
export { ExtensionTyping } from './_tsup-dts-rollup';
|
112
|
+
export { ExtractCommandActions } from './_tsup-dts-rollup';
|
107
113
|
export { ExtractCommandAppliers } from './_tsup-dts-rollup';
|
108
114
|
export { ExtractCommandCreators } from './_tsup-dts-rollup';
|
115
|
+
export { ExtractMarkActions } from './_tsup-dts-rollup';
|
109
116
|
export { ExtractMarks } from './_tsup-dts-rollup';
|
117
|
+
export { ExtractNodeActions } from './_tsup-dts-rollup';
|
110
118
|
export { ExtractNodes } from './_tsup-dts-rollup';
|
111
119
|
export { UnionExtension } from './_tsup-dts-rollup';
|
120
|
+
export { CommandAction } from './_tsup-dts-rollup';
|
121
|
+
export { CommandTyping } from './_tsup-dts-rollup';
|
122
|
+
export { MarkTyping } from './_tsup-dts-rollup';
|
123
|
+
export { ToMarkAction } from './_tsup-dts-rollup';
|
124
|
+
export { NodeTyping } from './_tsup-dts-rollup';
|
125
|
+
export { ToNodeAction } from './_tsup-dts-rollup';
|
112
126
|
export { NodeJSON } from './_tsup-dts-rollup';
|
113
127
|
export { SelectionJSON } from './_tsup-dts-rollup';
|
114
128
|
export { StateJSON } from './_tsup-dts-rollup';
|
115
129
|
export { StepJSON } from './_tsup-dts-rollup';
|
130
|
+
export { PickSubType } from './_tsup-dts-rollup';
|
116
131
|
export { Priority } from './_tsup-dts-rollup';
|
132
|
+
export { SimplifyDeeper } from './_tsup-dts-rollup';
|
117
133
|
export { SimplifyUnion } from './_tsup-dts-rollup';
|
118
134
|
export { assert } from './_tsup-dts-rollup';
|
119
135
|
export { canUseRegexLookbehind } from './_tsup-dts-rollup';
|