@prosekit/core 0.7.8 → 0.7.9
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.
@@ -1,5 +1,5 @@
|
|
1
1
|
import { AllSelection } from '@prosekit/pm/state';
|
2
|
-
import { Attrs } from '@prosekit/pm/model';
|
2
|
+
import type { Attrs } from '@prosekit/pm/model';
|
3
3
|
import { Command } from '@prosekit/pm/state';
|
4
4
|
import type { ContentMatch } from '@prosekit/pm/model';
|
5
5
|
import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
|
@@ -15,16 +15,16 @@ import { Fragment } from '@prosekit/pm/model';
|
|
15
15
|
import type { IsEqual } from 'type-fest';
|
16
16
|
import { Mark } from '@prosekit/pm/model';
|
17
17
|
import type { MarkSpec } from '@prosekit/pm/model';
|
18
|
-
import { MarkType } from '@prosekit/pm/model';
|
18
|
+
import type { MarkType } from '@prosekit/pm/model';
|
19
19
|
import type { Node as Node_2 } from '@prosekit/pm/model';
|
20
20
|
import { NodeSelection } from '@prosekit/pm/state';
|
21
21
|
import type { NodeSpec } from '@prosekit/pm/model';
|
22
|
-
import { NodeType } from '@prosekit/pm/model';
|
22
|
+
import type { NodeType } from '@prosekit/pm/model';
|
23
23
|
import { NodeType as NodeType_2 } from 'prosemirror-model';
|
24
24
|
import type { NodeView } from '@prosekit/pm/view';
|
25
25
|
import type { NodeViewConstructor } from '@prosekit/pm/view';
|
26
26
|
import { Options } from 'tsup';
|
27
|
-
import
|
27
|
+
import { ParseOptions } from '@prosekit/pm/model';
|
28
28
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
29
29
|
import { ProseMirrorFragment } from '@prosekit/pm/model';
|
30
30
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
@@ -294,7 +294,7 @@ declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
|
294
294
|
export { collectNodes }
|
295
295
|
export { collectNodes as collectNodes_alias_1 }
|
296
296
|
|
297
|
-
export declare function combineEventHandlers<Handler extends (...args: any[]) => boolean | void, Args extends Parameters<Handler> = Parameters<Handler>>(): readonly [(
|
297
|
+
export declare function combineEventHandlers<Handler extends (...args: any[]) => boolean | void, Args extends Parameters<Handler> = Parameters<Handler>>(): readonly [(eventHandlers: Handler[]) => void, (...args: Args) => boolean];
|
298
298
|
|
299
299
|
/**
|
300
300
|
* A function to apply a command to the editor. It will return `true` if the command was applied, and `false` otherwise.
|
@@ -304,7 +304,21 @@ export declare function combineEventHandlers<Handler extends (...args: any[]) =>
|
|
304
304
|
* @public
|
305
305
|
*/
|
306
306
|
declare interface CommandAction<Args extends any[] = any[]> {
|
307
|
+
/**
|
308
|
+
* Execute the current command. Return `true` if the command was successfully
|
309
|
+
* executed, otherwise `false`.
|
310
|
+
*/
|
307
311
|
(...args: Args): boolean;
|
312
|
+
/**
|
313
|
+
* Check if the current command can be executed. Return `true` if the command
|
314
|
+
* can be executed, otherwise `false`.
|
315
|
+
*/
|
316
|
+
canExec(...args: Args): boolean;
|
317
|
+
/**
|
318
|
+
* An alias for `canExec`.
|
319
|
+
*
|
320
|
+
* @deprecated Use `canExec` instead.
|
321
|
+
*/
|
308
322
|
canApply(...args: Args): boolean;
|
309
323
|
}
|
310
324
|
export { CommandAction }
|
@@ -953,6 +967,16 @@ declare class Editor<E extends Extension = any> {
|
|
953
967
|
* - The string "end" (to set selection at the end)
|
954
968
|
*/
|
955
969
|
setContent: (content: ProseMirrorNode | NodeJSON | string | HTMLElement, selection?: SelectionJSON | Selection_2 | "start" | "end") => void;
|
970
|
+
/**
|
971
|
+
* Execute the given command. Return `true` if the command was successfully
|
972
|
+
* executed, otherwise `false`.
|
973
|
+
*/
|
974
|
+
exec: (command: Command) => boolean;
|
975
|
+
/**
|
976
|
+
* Check if the given command can be executed. Return `true` if the command
|
977
|
+
* can be executed, otherwise `false`.
|
978
|
+
*/
|
979
|
+
canExec: (command: Command) => boolean;
|
956
980
|
/**
|
957
981
|
* All {@link CommandAction}s defined by the editor.
|
958
982
|
*/
|
@@ -986,6 +1010,7 @@ export declare class EditorInstance {
|
|
986
1010
|
constructor(extension: Extension);
|
987
1011
|
getState: () => EditorState;
|
988
1012
|
updateState(state: EditorState): void;
|
1013
|
+
private dispatch;
|
989
1014
|
setContent(content: NodeJSON | string | HTMLElement | ProseMirrorNode, selection?: SelectionJSON | Selection_2 | 'start' | 'end'): void;
|
990
1015
|
private updateExtension;
|
991
1016
|
use(extension: Extension): VoidFunction;
|
@@ -995,6 +1020,8 @@ export declare class EditorInstance {
|
|
995
1020
|
get assertView(): EditorView;
|
996
1021
|
definePlugins(plugins: readonly Plugin_2[]): void;
|
997
1022
|
removePlugins(plugins: readonly Plugin_2[]): void;
|
1023
|
+
exec(command: Command): boolean;
|
1024
|
+
canExec(command: Command): boolean;
|
998
1025
|
defineCommand<Args extends any[] = any[]>(name: string, commandCreator: CommandCreator<Args>): void;
|
999
1026
|
removeCommand(name: string): void;
|
1000
1027
|
}
|
@@ -1296,7 +1323,7 @@ export { findParentNode as findParentNode_alias_1 }
|
|
1296
1323
|
*/
|
1297
1324
|
declare function findParentNodeOfType(
|
1298
1325
|
/**
|
1299
|
-
* The type of the node to
|
1326
|
+
* The type of the node to find.
|
1300
1327
|
*/
|
1301
1328
|
type: NodeType | string,
|
1302
1329
|
/**
|
@@ -2620,7 +2647,8 @@ export { Union }
|
|
2620
2647
|
export { Union as Union_alias_1 }
|
2621
2648
|
|
2622
2649
|
/**
|
2623
|
-
*
|
2650
|
+
* Merges multiple extensions into one. You can pass multiple extensions as
|
2651
|
+
* arguments or a single array containing multiple extensions.
|
2624
2652
|
*
|
2625
2653
|
* @throws If no extensions are provided.
|
2626
2654
|
*
|
@@ -2628,6 +2656,17 @@ export { Union as Union_alias_1 }
|
|
2628
2656
|
*
|
2629
2657
|
* ```ts
|
2630
2658
|
* function defineFancyNodes() {
|
2659
|
+
* return union(
|
2660
|
+
* defineFancyParagraph(),
|
2661
|
+
* defineFancyHeading(),
|
2662
|
+
* )
|
2663
|
+
* }
|
2664
|
+
* ```
|
2665
|
+
*
|
2666
|
+
* @example
|
2667
|
+
*
|
2668
|
+
* ```ts
|
2669
|
+
* function defineFancyNodes() {
|
2631
2670
|
* return union([
|
2632
2671
|
* defineFancyParagraph(),
|
2633
2672
|
* defineFancyHeading(),
|
@@ -2804,7 +2843,7 @@ declare interface WrapOptions {
|
|
2804
2843
|
/**
|
2805
2844
|
* @deprecated Use `nodeSpec` instead.
|
2806
2845
|
*/
|
2807
|
-
nodeType
|
2846
|
+
nodeType?: NodeType;
|
2808
2847
|
/**
|
2809
2848
|
* Optional attributes to apply to the node.
|
2810
2849
|
*/
|
@@ -17,7 +17,6 @@ var DOMDocumentNotFoundError = class extends ProseKitError {
|
|
17
17
|
};
|
18
18
|
|
19
19
|
// src/utils/get-mark-type.ts
|
20
|
-
import "@prosekit/pm/model";
|
21
20
|
function getMarkType(schema, type) {
|
22
21
|
if (typeof type === "string") {
|
23
22
|
const markType = schema.marks[type];
|
@@ -37,7 +36,6 @@ function assert(condition, message = "Assertion failed") {
|
|
37
36
|
}
|
38
37
|
|
39
38
|
// src/utils/get-node-type.ts
|
40
|
-
import "@prosekit/pm/model";
|
41
39
|
function getNodeType(schema, type) {
|
42
40
|
if (typeof type === "string") {
|
43
41
|
const nodeType = schema.nodes[type];
|
@@ -59,6 +57,39 @@ var Priority = /* @__PURE__ */ ((Priority2) => {
|
|
59
57
|
return Priority2;
|
60
58
|
})(Priority || {});
|
61
59
|
|
60
|
+
// src/facets/facet.ts
|
61
|
+
var facetCount = 0;
|
62
|
+
var Facet = class {
|
63
|
+
/**
|
64
|
+
* @internal
|
65
|
+
*/
|
66
|
+
constructor(parent, singleton, _reducer, _reduce) {
|
67
|
+
this._reducer = _reducer;
|
68
|
+
this._reduce = _reduce;
|
69
|
+
/**
|
70
|
+
* @internal
|
71
|
+
*/
|
72
|
+
this.index = facetCount++;
|
73
|
+
assert((_reduce || _reducer) && !(_reduce && _reducer));
|
74
|
+
this.parent = parent;
|
75
|
+
this.singleton = singleton;
|
76
|
+
this.path = parent ? [...parent.path, this.index] : [];
|
77
|
+
}
|
78
|
+
get reducer() {
|
79
|
+
var _a, _b;
|
80
|
+
return (_b = this._reducer) != null ? _b : (_a = this._reduce) == null ? void 0 : _a.call(this);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
function defineFacet(options) {
|
84
|
+
var _a;
|
85
|
+
return new Facet(
|
86
|
+
options.parent,
|
87
|
+
(_a = options.singleton) != null ? _a : false,
|
88
|
+
options.reducer,
|
89
|
+
options.reduce
|
90
|
+
);
|
91
|
+
}
|
92
|
+
|
62
93
|
// src/utils/type-assertion.ts
|
63
94
|
import { Fragment, Mark, ProseMirrorNode, Slice } from "@prosekit/pm/model";
|
64
95
|
import {
|
@@ -95,41 +126,74 @@ function isNotNullish(value) {
|
|
95
126
|
return value != null;
|
96
127
|
}
|
97
128
|
|
98
|
-
// src/facets/
|
99
|
-
|
100
|
-
|
129
|
+
// src/facets/schema.ts
|
130
|
+
import { Schema } from "@prosekit/pm/model";
|
131
|
+
|
132
|
+
// src/facets/root.ts
|
133
|
+
function rootReducer(inputs) {
|
134
|
+
var _a;
|
135
|
+
let schema;
|
136
|
+
let commands;
|
137
|
+
let stateFunc;
|
138
|
+
let view;
|
139
|
+
for (const input of inputs) {
|
140
|
+
schema = input.schema || schema;
|
141
|
+
commands = input.commands || commands;
|
142
|
+
stateFunc = input.state || stateFunc;
|
143
|
+
view = input.view || view;
|
144
|
+
}
|
145
|
+
const state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
146
|
+
return { schema, state, commands, view };
|
147
|
+
}
|
148
|
+
var rootFacet = new Facet(
|
149
|
+
null,
|
150
|
+
true,
|
151
|
+
rootReducer
|
152
|
+
);
|
153
|
+
|
154
|
+
// src/facets/schema.ts
|
155
|
+
var schemaFacet = defineFacet({
|
156
|
+
reducer: (specs) => {
|
157
|
+
assert(specs.length <= 1);
|
158
|
+
const spec = specs[0];
|
159
|
+
const schema = spec ? new Schema(spec) : null;
|
160
|
+
return { schema };
|
161
|
+
},
|
162
|
+
parent: rootFacet,
|
163
|
+
singleton: true
|
164
|
+
});
|
165
|
+
|
166
|
+
// src/facets/base-extension.ts
|
167
|
+
var BaseExtension = class {
|
168
|
+
constructor() {
|
169
|
+
this.extension = [];
|
170
|
+
this.trees = [null, null, null, null, null];
|
171
|
+
}
|
101
172
|
/**
|
102
173
|
* @internal
|
103
174
|
*/
|
104
|
-
|
105
|
-
|
106
|
-
this.
|
107
|
-
|
108
|
-
* @internal
|
109
|
-
*/
|
110
|
-
this.index = facetCount++;
|
111
|
-
assert((_reduce || _reducer) && !(_reduce && _reducer));
|
112
|
-
this.parent = parent;
|
113
|
-
this.singleton = singleton;
|
114
|
-
this.path = parent ? [...parent.path, this.index] : [];
|
175
|
+
getTree(priority) {
|
176
|
+
var _a, _b;
|
177
|
+
const pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
178
|
+
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
115
179
|
}
|
116
|
-
|
180
|
+
/**
|
181
|
+
* @internal
|
182
|
+
*/
|
183
|
+
findFacetOutput(facet) {
|
184
|
+
var _a;
|
185
|
+
let node = this.getTree();
|
186
|
+
for (const index of facet.path) {
|
187
|
+
node = node == null ? void 0 : node.children.get(index);
|
188
|
+
}
|
189
|
+
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
190
|
+
}
|
191
|
+
get schema() {
|
117
192
|
var _a, _b;
|
118
|
-
|
193
|
+
const output = this.findFacetOutput(schemaFacet);
|
194
|
+
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
119
195
|
}
|
120
196
|
};
|
121
|
-
function defineFacet(options) {
|
122
|
-
var _a;
|
123
|
-
return new Facet(
|
124
|
-
options.parent,
|
125
|
-
(_a = options.singleton) != null ? _a : false,
|
126
|
-
options.reducer,
|
127
|
-
options.reduce
|
128
|
-
);
|
129
|
-
}
|
130
|
-
|
131
|
-
// src/facets/base-extension.ts
|
132
|
-
import "@prosekit/pm/model";
|
133
197
|
|
134
198
|
// src/utils/array.ts
|
135
199
|
function uniqPush(prev, next) {
|
@@ -273,75 +337,6 @@ var FacetNode = class {
|
|
273
337
|
}
|
274
338
|
};
|
275
339
|
|
276
|
-
// src/facets/schema.ts
|
277
|
-
import { Schema as Schema3 } from "@prosekit/pm/model";
|
278
|
-
|
279
|
-
// src/facets/root.ts
|
280
|
-
function rootReducer(inputs) {
|
281
|
-
var _a;
|
282
|
-
let schema;
|
283
|
-
let commands;
|
284
|
-
let stateFunc;
|
285
|
-
let view;
|
286
|
-
for (const input of inputs) {
|
287
|
-
schema = input.schema || schema;
|
288
|
-
commands = input.commands || commands;
|
289
|
-
stateFunc = input.state || stateFunc;
|
290
|
-
view = input.view || view;
|
291
|
-
}
|
292
|
-
const state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
293
|
-
return { schema, state, commands, view };
|
294
|
-
}
|
295
|
-
var rootFacet = new Facet(
|
296
|
-
null,
|
297
|
-
true,
|
298
|
-
rootReducer
|
299
|
-
);
|
300
|
-
|
301
|
-
// src/facets/schema.ts
|
302
|
-
var schemaFacet = defineFacet({
|
303
|
-
reducer: (specs) => {
|
304
|
-
assert(specs.length <= 1);
|
305
|
-
const spec = specs[0];
|
306
|
-
const schema = spec ? new Schema3(spec) : null;
|
307
|
-
return { schema };
|
308
|
-
},
|
309
|
-
parent: rootFacet,
|
310
|
-
singleton: true
|
311
|
-
});
|
312
|
-
|
313
|
-
// src/facets/base-extension.ts
|
314
|
-
var BaseExtension = class {
|
315
|
-
constructor() {
|
316
|
-
this.extension = [];
|
317
|
-
this.trees = [null, null, null, null, null];
|
318
|
-
}
|
319
|
-
/**
|
320
|
-
* @internal
|
321
|
-
*/
|
322
|
-
getTree(priority) {
|
323
|
-
var _a, _b;
|
324
|
-
const pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
325
|
-
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
326
|
-
}
|
327
|
-
/**
|
328
|
-
* @internal
|
329
|
-
*/
|
330
|
-
findFacetOutput(facet) {
|
331
|
-
var _a;
|
332
|
-
let node = this.getTree();
|
333
|
-
for (const index of facet.path) {
|
334
|
-
node = node == null ? void 0 : node.children.get(index);
|
335
|
-
}
|
336
|
-
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
337
|
-
}
|
338
|
-
get schema() {
|
339
|
-
var _a, _b;
|
340
|
-
const output = this.findFacetOutput(schemaFacet);
|
341
|
-
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
342
|
-
}
|
343
|
-
};
|
344
|
-
|
345
340
|
// src/facets/facet-extension.ts
|
346
341
|
var FacetExtensionImpl = class extends BaseExtension {
|
347
342
|
/**
|
@@ -373,7 +368,10 @@ function defineFacetPayload(facet, payloads) {
|
|
373
368
|
}
|
374
369
|
|
375
370
|
// src/utils/parse.ts
|
376
|
-
import {
|
371
|
+
import {
|
372
|
+
DOMParser,
|
373
|
+
DOMSerializer
|
374
|
+
} from "@prosekit/pm/model";
|
377
375
|
import { EditorState } from "@prosekit/pm/state";
|
378
376
|
|
379
377
|
// src/utils/get-dom-api.ts
|
@@ -672,8 +670,9 @@ function union(...exts) {
|
|
672
670
|
}
|
673
671
|
|
674
672
|
// src/editor/editor.ts
|
675
|
-
import
|
676
|
-
|
673
|
+
import {
|
674
|
+
EditorState as EditorState2
|
675
|
+
} from "@prosekit/pm/state";
|
677
676
|
import { EditorView } from "@prosekit/pm/view";
|
678
677
|
|
679
678
|
// src/utils/deep-equals.ts
|
@@ -700,7 +699,6 @@ function deepEquals(a, b) {
|
|
700
699
|
}
|
701
700
|
|
702
701
|
// src/editor/action.ts
|
703
|
-
import "@prosekit/pm/model";
|
704
702
|
import mapValues from "just-map-values";
|
705
703
|
|
706
704
|
// src/utils/attrs-match.ts
|
@@ -811,10 +809,10 @@ function isNodeChild(value) {
|
|
811
809
|
// src/editor/editor.ts
|
812
810
|
function setupEditorExtension(options) {
|
813
811
|
if (options.defaultContent || options.defaultDoc || options.defaultHTML) {
|
814
|
-
return union(
|
812
|
+
return union(
|
815
813
|
options.extension,
|
816
814
|
defineDefaultState(options)
|
817
|
-
|
815
|
+
);
|
818
816
|
}
|
819
817
|
return options.extension;
|
820
818
|
}
|
@@ -832,6 +830,13 @@ var EditorInstance = class {
|
|
832
830
|
var _a;
|
833
831
|
return ((_a = this.view) == null ? void 0 : _a.state) || this.directEditorProps.state;
|
834
832
|
};
|
833
|
+
this.dispatch = (tr) => {
|
834
|
+
if (this.view) {
|
835
|
+
this.view.dispatch(tr);
|
836
|
+
} else {
|
837
|
+
this.directEditorProps.state = this.directEditorProps.state.apply(tr);
|
838
|
+
}
|
839
|
+
};
|
835
840
|
this.tree = extension.getTree();
|
836
841
|
const payload = this.tree.getRootOutput();
|
837
842
|
const schema = payload.schema;
|
@@ -956,21 +961,27 @@ var EditorInstance = class {
|
|
956
961
|
const newState = state.reconfigure({ plugins: newPlugins });
|
957
962
|
view.setProps({ state: newState });
|
958
963
|
}
|
964
|
+
exec(command) {
|
965
|
+
var _a;
|
966
|
+
const state = this.getState();
|
967
|
+
return command(state, this.dispatch, (_a = this.view) != null ? _a : void 0);
|
968
|
+
}
|
969
|
+
canExec(command) {
|
970
|
+
var _a;
|
971
|
+
const state = this.getState();
|
972
|
+
return command(state, void 0, (_a = this.view) != null ? _a : void 0);
|
973
|
+
}
|
959
974
|
defineCommand(name, commandCreator) {
|
960
975
|
const action = (...args) => {
|
961
|
-
const view = this.view;
|
962
|
-
assert(view, `Cannot call command "${name}" before the editor is mounted`);
|
963
976
|
const command = commandCreator(...args);
|
964
|
-
return
|
977
|
+
return this.exec(command);
|
965
978
|
};
|
966
|
-
|
967
|
-
const view = this.view;
|
968
|
-
if (!view) {
|
969
|
-
return false;
|
970
|
-
}
|
979
|
+
const canExec = (...args) => {
|
971
980
|
const command = commandCreator(...args);
|
972
|
-
return command
|
981
|
+
return this.canExec(command);
|
973
982
|
};
|
983
|
+
action.canApply = canExec;
|
984
|
+
action.canExec = canExec;
|
974
985
|
this.commands[name] = action;
|
975
986
|
}
|
976
987
|
removeCommand(name) {
|
@@ -1048,6 +1059,20 @@ var Editor = class {
|
|
1048
1059
|
this.setContent = (content, selection) => {
|
1049
1060
|
return this.instance.setContent(content, selection);
|
1050
1061
|
};
|
1062
|
+
/**
|
1063
|
+
* Execute the given command. Return `true` if the command was successfully
|
1064
|
+
* executed, otherwise `false`.
|
1065
|
+
*/
|
1066
|
+
this.exec = (command) => {
|
1067
|
+
return this.instance.exec(command);
|
1068
|
+
};
|
1069
|
+
/**
|
1070
|
+
* Check if the given command can be executed. Return `true` if the command
|
1071
|
+
* can be executed, otherwise `false`.
|
1072
|
+
*/
|
1073
|
+
this.canExec = (command) => {
|
1074
|
+
return this.instance.canExec(command);
|
1075
|
+
};
|
1051
1076
|
if (!(instance instanceof EditorInstance)) {
|
1052
1077
|
throw new TypeError("Invalid EditorInstance");
|
1053
1078
|
}
|
@@ -1112,6 +1137,9 @@ export {
|
|
1112
1137
|
getNodeType,
|
1113
1138
|
isNodeActive,
|
1114
1139
|
Priority,
|
1140
|
+
defineFacet,
|
1141
|
+
rootFacet,
|
1142
|
+
schemaFacet,
|
1115
1143
|
toReversed,
|
1116
1144
|
isProseMirrorNode,
|
1117
1145
|
isMark,
|
@@ -1122,9 +1150,6 @@ export {
|
|
1122
1150
|
isNodeSelection,
|
1123
1151
|
isAllSelection,
|
1124
1152
|
isNotNullish,
|
1125
|
-
defineFacet,
|
1126
|
-
rootFacet,
|
1127
|
-
schemaFacet,
|
1128
1153
|
defineFacetPayload,
|
1129
1154
|
stateFacet,
|
1130
1155
|
isElement,
|
@@ -6,10 +6,13 @@ import {
|
|
6
6
|
createNodeActions,
|
7
7
|
isProseMirrorNode,
|
8
8
|
setupEditorExtension
|
9
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-RNBMCB5M.js";
|
10
10
|
|
11
11
|
// src/test/test-editor.ts
|
12
|
-
import {
|
12
|
+
import {
|
13
|
+
NodeSelection,
|
14
|
+
TextSelection
|
15
|
+
} from "@prosekit/pm/state";
|
13
16
|
|
14
17
|
// src/test/test-builder.ts
|
15
18
|
var createNodeForTest = (type, attrs, children) => {
|
package/dist/prosekit-core.js
CHANGED
@@ -39,10 +39,9 @@ import {
|
|
39
39
|
stateFromJSON,
|
40
40
|
toReversed,
|
41
41
|
union
|
42
|
-
} from "./chunk-
|
42
|
+
} from "./chunk-RNBMCB5M.js";
|
43
43
|
|
44
44
|
// src/commands/add-mark.ts
|
45
|
-
import "@prosekit/pm/model";
|
46
45
|
function addMark(options) {
|
47
46
|
return (state, dispatch) => {
|
48
47
|
var _a, _b;
|
@@ -144,7 +143,6 @@ function insertNode(options) {
|
|
144
143
|
}
|
145
144
|
|
146
145
|
// src/commands/remove-mark.ts
|
147
|
-
import "@prosekit/pm/model";
|
148
146
|
function removeMark(options) {
|
149
147
|
return (state, dispatch) => {
|
150
148
|
var _a, _b;
|
@@ -242,7 +240,6 @@ function setBlockType(options) {
|
|
242
240
|
}
|
243
241
|
|
244
242
|
// src/utils/get-node-types.ts
|
245
|
-
import "@prosekit/pm/model";
|
246
243
|
function getNodeTypes(schema, types) {
|
247
244
|
if (Array.isArray(types)) {
|
248
245
|
return types.map((type) => getNodeType(schema, type));
|
@@ -284,7 +281,6 @@ function setNodeAttrs(options) {
|
|
284
281
|
|
285
282
|
// src/commands/toggle-mark.ts
|
286
283
|
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
287
|
-
import "@prosekit/pm/model";
|
288
284
|
function toggleMark({
|
289
285
|
type,
|
290
286
|
attrs,
|
@@ -301,7 +297,6 @@ function toggleMark({
|
|
301
297
|
|
302
298
|
// src/commands/toggle-node.ts
|
303
299
|
import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
|
304
|
-
import "@prosekit/pm/model";
|
305
300
|
function toggleNode({ type, attrs }) {
|
306
301
|
return (state, dispatch, view) => {
|
307
302
|
if (isNodeActive(state, type, attrs)) {
|
@@ -319,7 +314,6 @@ function toggleNode({ type, attrs }) {
|
|
319
314
|
|
320
315
|
// src/commands/unset-block-type.ts
|
321
316
|
import { Fragment, Slice } from "@prosekit/pm/model";
|
322
|
-
import "@prosekit/pm/state";
|
323
317
|
import { ReplaceAroundStep } from "@prosekit/pm/transform";
|
324
318
|
function unsetBlockType(options) {
|
325
319
|
return (state, dispatch) => {
|
@@ -373,14 +367,13 @@ function unsetMark(options) {
|
|
373
367
|
}
|
374
368
|
|
375
369
|
// src/commands/wrap.ts
|
376
|
-
import "@prosekit/pm/model";
|
377
370
|
import { findWrapping } from "@prosekit/pm/transform";
|
378
371
|
function wrap(options) {
|
379
372
|
return (state, dispatch) => {
|
380
373
|
const { $from, $to } = state.selection;
|
381
374
|
const range = $from.blockRange($to);
|
382
375
|
if (!range) return false;
|
383
|
-
const nodeType = getNodeType(state.schema, options.
|
376
|
+
const nodeType = getNodeType(state.schema, options.nodeType || options.type);
|
384
377
|
const wrapping = findWrapping(range, nodeType, options.attrs);
|
385
378
|
if (!wrapping) return false;
|
386
379
|
dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
|
@@ -449,7 +442,6 @@ import clone from "just-clone";
|
|
449
442
|
import OrderedMap2 from "orderedmap";
|
450
443
|
|
451
444
|
// src/facets/schema-spec.ts
|
452
|
-
import "@prosekit/pm/model";
|
453
445
|
import OrderedMap from "orderedmap";
|
454
446
|
var schemaSpecFacet = defineFacet({
|
455
447
|
reducer: (specs) => {
|
@@ -669,10 +661,12 @@ function defineDoc() {
|
|
669
661
|
}
|
670
662
|
|
671
663
|
// src/extensions/events/plugin-view.ts
|
672
|
-
import {
|
664
|
+
import {
|
665
|
+
PluginKey,
|
666
|
+
ProseMirrorPlugin
|
667
|
+
} from "@prosekit/pm/state";
|
673
668
|
|
674
669
|
// src/extensions/plugin.ts
|
675
|
-
import "@prosekit/pm/model";
|
676
670
|
import { Plugin } from "@prosekit/pm/state";
|
677
671
|
function definePlugin(plugin) {
|
678
672
|
if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
|
@@ -726,7 +720,7 @@ var pluginViewFacet = defineFacet({
|
|
726
720
|
let mountHandlers = [];
|
727
721
|
let updateHandlers = [];
|
728
722
|
let unmountHandlers = [];
|
729
|
-
const plugin = new
|
723
|
+
const plugin = new ProseMirrorPlugin({
|
730
724
|
key: pluginKey,
|
731
725
|
view: (view) => {
|
732
726
|
mountHandlers.forEach((fn) => fn(view));
|
@@ -778,16 +772,16 @@ function defineDocChangeHandler(handler) {
|
|
778
772
|
}
|
779
773
|
|
780
774
|
// src/extensions/events/dom-event.ts
|
781
|
-
import { PluginKey as PluginKey2, ProseMirrorPlugin as
|
775
|
+
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
782
776
|
|
783
777
|
// src/utils/combine-event-handlers.ts
|
784
778
|
function combineEventHandlers() {
|
785
|
-
let
|
786
|
-
function setHandlers(
|
787
|
-
|
779
|
+
let handlers = [];
|
780
|
+
function setHandlers(eventHandlers) {
|
781
|
+
handlers = toReversed(eventHandlers);
|
788
782
|
}
|
789
783
|
function combinedEventHandler(...args) {
|
790
|
-
for (const handler of
|
784
|
+
for (const handler of handlers) {
|
791
785
|
if (handler(...args)) {
|
792
786
|
return true;
|
793
787
|
}
|
@@ -828,7 +822,7 @@ var domEventFacet = defineFacet({
|
|
828
822
|
setHandlers(handlers);
|
829
823
|
}
|
830
824
|
if (hasNewEvent) {
|
831
|
-
plugin = new
|
825
|
+
plugin = new ProseMirrorPlugin2({
|
832
826
|
key: new PluginKey2("prosekit-dom-event-handler"),
|
833
827
|
props: { handleDOMEvents: combinedHandlerMap }
|
834
828
|
});
|
@@ -844,7 +838,7 @@ var domEventFacet = defineFacet({
|
|
844
838
|
});
|
845
839
|
|
846
840
|
// src/extensions/events/editor-event.ts
|
847
|
-
import { PluginKey as PluginKey3, ProseMirrorPlugin as
|
841
|
+
import { PluginKey as PluginKey3, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
848
842
|
function defineKeyDownHandler(handler) {
|
849
843
|
return defineFacetPayload(editorEventFacet, [["keyDown", handler]]);
|
850
844
|
}
|
@@ -921,7 +915,7 @@ function setupEditorEventPlugin() {
|
|
921
915
|
setDropHandlers((_k = map.drop) != null ? _k : []);
|
922
916
|
setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
923
917
|
};
|
924
|
-
const plugin = new
|
918
|
+
const plugin = new ProseMirrorPlugin3({
|
925
919
|
key: new PluginKey3("prosekit-editor-event"),
|
926
920
|
props: {
|
927
921
|
handleKeyDown,
|
@@ -1020,11 +1014,11 @@ function defineHistory({
|
|
1020
1014
|
depth = 200,
|
1021
1015
|
newGroupDelay = 250
|
1022
1016
|
} = {}) {
|
1023
|
-
return union(
|
1017
|
+
return union(
|
1024
1018
|
definePlugin(history({ depth, newGroupDelay })),
|
1025
1019
|
defineKeymap(keymap),
|
1026
1020
|
defineCommands(commands)
|
1027
|
-
|
1021
|
+
);
|
1028
1022
|
}
|
1029
1023
|
|
1030
1024
|
// src/extensions/keymap-base.ts
|
@@ -1126,7 +1120,7 @@ function wrapParseRuleAttrs(rule, attrs) {
|
|
1126
1120
|
}
|
1127
1121
|
|
1128
1122
|
// src/extensions/node-view.ts
|
1129
|
-
import { PluginKey as PluginKey5, ProseMirrorPlugin as
|
1123
|
+
import { PluginKey as PluginKey5, ProseMirrorPlugin as ProseMirrorPlugin4 } from "@prosekit/pm/state";
|
1130
1124
|
function defineNodeView(options) {
|
1131
1125
|
return defineFacetPayload(nodeViewFacet, [options]);
|
1132
1126
|
}
|
@@ -1139,7 +1133,7 @@ var nodeViewFacet = defineFacet({
|
|
1139
1133
|
}
|
1140
1134
|
}
|
1141
1135
|
return () => [
|
1142
|
-
new
|
1136
|
+
new ProseMirrorPlugin4({
|
1143
1137
|
key: new PluginKey5("prosekit-node-view"),
|
1144
1138
|
props: { nodeViews }
|
1145
1139
|
})
|
@@ -1149,7 +1143,7 @@ var nodeViewFacet = defineFacet({
|
|
1149
1143
|
});
|
1150
1144
|
|
1151
1145
|
// src/extensions/node-view-effect.ts
|
1152
|
-
import { PluginKey as PluginKey6, ProseMirrorPlugin as
|
1146
|
+
import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin5 } from "@prosekit/pm/state";
|
1153
1147
|
function defineNodeViewFactory(options) {
|
1154
1148
|
const input = [options, null];
|
1155
1149
|
return defineFacetPayload(nodeViewFactoryFacet, [input]);
|
@@ -1171,7 +1165,7 @@ var nodeViewFactoryFacet = defineFacet({
|
|
1171
1165
|
nodeViews[name] = factory.factory(args);
|
1172
1166
|
}
|
1173
1167
|
return () => [
|
1174
|
-
new
|
1168
|
+
new ProseMirrorPlugin5({
|
1175
1169
|
key: new PluginKey6("prosekit-node-view-effect"),
|
1176
1170
|
props: { nodeViews }
|
1177
1171
|
})
|
@@ -1219,7 +1213,7 @@ function cache(fn) {
|
|
1219
1213
|
var canUseRegexLookbehind = cache(() => {
|
1220
1214
|
try {
|
1221
1215
|
return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
|
1222
|
-
} catch (
|
1216
|
+
} catch (e) {
|
1223
1217
|
return false;
|
1224
1218
|
}
|
1225
1219
|
});
|
@@ -1229,7 +1223,6 @@ import clsxLite from "clsx/lite";
|
|
1229
1223
|
var clsx = clsxLite;
|
1230
1224
|
|
1231
1225
|
// src/utils/collect-children.ts
|
1232
|
-
import "@prosekit/pm/model";
|
1233
1226
|
function collectChildren(parent) {
|
1234
1227
|
const children = [];
|
1235
1228
|
for (let i = 0; i < parent.childCount; i++) {
|
@@ -1239,12 +1232,12 @@ function collectChildren(parent) {
|
|
1239
1232
|
}
|
1240
1233
|
|
1241
1234
|
// src/utils/collect-nodes.ts
|
1242
|
-
import { ProseMirrorFragment, ProseMirrorNode
|
1235
|
+
import { ProseMirrorFragment, ProseMirrorNode } from "@prosekit/pm/model";
|
1243
1236
|
function collectNodes(content) {
|
1244
1237
|
if (Array.isArray(content)) {
|
1245
1238
|
return content.flatMap(collectNodes);
|
1246
1239
|
}
|
1247
|
-
if (content instanceof
|
1240
|
+
if (content instanceof ProseMirrorNode) {
|
1248
1241
|
return [content];
|
1249
1242
|
}
|
1250
1243
|
if (content instanceof ProseMirrorFragment) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.7.
|
4
|
+
"version": "0.7.9",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -45,13 +45,13 @@
|
|
45
45
|
"just-map-values": "^3.2.0",
|
46
46
|
"orderedmap": "^2.1.1",
|
47
47
|
"prosemirror-splittable": "^0.1.1",
|
48
|
-
"type-fest": "^4.
|
48
|
+
"type-fest": "^4.25.0",
|
49
49
|
"@prosekit/pm": "^0.1.8"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
|
-
"tsup": "^8.2.
|
53
|
-
"typescript": "^5.5.
|
54
|
-
"vitest": "^2.0.
|
52
|
+
"tsup": "^8.2.4",
|
53
|
+
"typescript": "^5.5.4",
|
54
|
+
"vitest": "^2.0.5",
|
55
55
|
"@prosekit/dev": "0.0.0"
|
56
56
|
},
|
57
57
|
"scripts": {
|