@prosekit/core 0.0.10 → 0.0.12
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 +151 -134
- package/dist/prosekit-core.d.ts +17 -16
- package/dist/prosekit-core.js +102 -64
- package/dist/style.css +4 -1
- package/package.json +4 -4
- package/src/index.ts +19 -14
@@ -30,12 +30,90 @@ declare type Action = (options: {
|
|
30
30
|
view?: EditorView;
|
31
31
|
}) => boolean;
|
32
32
|
|
33
|
+
declare function addMark(options: AddMarkOptions): Command;
|
34
|
+
export { addMark }
|
35
|
+
export { addMark as addMark_alias_1 }
|
36
|
+
|
37
|
+
declare interface AddMarkOptions {
|
38
|
+
type: string | MarkType;
|
39
|
+
attrs?: Attrs | null;
|
40
|
+
/**
|
41
|
+
* The start position of the mark. By default it will be the start position of current selection.
|
42
|
+
*/
|
43
|
+
from?: number;
|
44
|
+
/**
|
45
|
+
* The end position of the mark. By default it will be the end position of current selection.
|
46
|
+
*/
|
47
|
+
to?: number;
|
48
|
+
}
|
49
|
+
export { AddMarkOptions }
|
50
|
+
export { AddMarkOptions as AddMarkOptions_alias_1 }
|
51
|
+
|
52
|
+
export declare type AnySlot = Slot<any, any>;
|
53
|
+
|
54
|
+
export declare function applyAction(operator: Action): Command;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Utility function assert that two types are equal in tests.
|
58
|
+
*/
|
59
|
+
export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
|
60
|
+
|
61
|
+
export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
62
|
+
|
63
|
+
export declare interface CommandApplier<Args extends any[] = any[]> {
|
64
|
+
(...args: Args): boolean;
|
65
|
+
canApply(...args: Args): boolean;
|
66
|
+
}
|
67
|
+
|
68
|
+
/** @internal */
|
69
|
+
declare interface CommandArgs {
|
70
|
+
[name: string]: any[];
|
71
|
+
}
|
72
|
+
export { CommandArgs }
|
73
|
+
export { CommandArgs as CommandArgs_alias_1 }
|
74
|
+
|
75
|
+
export declare type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
|
76
|
+
|
77
|
+
export declare interface CommandCreators {
|
78
|
+
[name: string]: CommandCreator;
|
79
|
+
}
|
80
|
+
|
81
|
+
export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>;
|
82
|
+
|
83
|
+
export declare type CommandSlotInput = Record<string, CommandCreator<any>>;
|
84
|
+
|
85
|
+
/** @public */
|
86
|
+
declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;
|
87
|
+
export { createEditor }
|
88
|
+
export { createEditor as createEditor_alias_1 }
|
89
|
+
|
90
|
+
export declare function createMarkBuilder(getState: () => EditorState | null | undefined, type: MarkType): MarkBuilder;
|
91
|
+
|
92
|
+
export declare function createNodeBuilder(getState: () => EditorState | null | undefined, type: NodeType): NodeBuilder;
|
93
|
+
|
94
|
+
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
95
|
+
|
96
|
+
export declare const default_alias_1: UserProjectConfigExport;
|
97
|
+
|
98
|
+
declare interface DefaultStateOptions {
|
99
|
+
/**
|
100
|
+
* A JSON representation of a ProseMirror document.
|
101
|
+
*/
|
102
|
+
doc?: NodeJson;
|
103
|
+
/**
|
104
|
+
* A JSON representation of a ProseMirror selection.
|
105
|
+
*/
|
106
|
+
selection?: SelectionJson;
|
107
|
+
}
|
108
|
+
export { DefaultStateOptions }
|
109
|
+
export { DefaultStateOptions as DefaultStateOptions_alias_1 }
|
110
|
+
|
33
111
|
/**
|
34
112
|
* Add some base commands
|
35
113
|
*
|
36
114
|
* @public
|
37
115
|
*/
|
38
|
-
declare function
|
116
|
+
declare function defineBaseCommands(): Extension<{
|
39
117
|
COMMAND_ARGS: {
|
40
118
|
insertText: [{
|
41
119
|
text: string;
|
@@ -59,103 +137,96 @@ declare function addBaseCommands(): Extension<{
|
|
59
137
|
selectAll: [];
|
60
138
|
};
|
61
139
|
}>;
|
62
|
-
export {
|
63
|
-
export {
|
140
|
+
export { defineBaseCommands }
|
141
|
+
export { defineBaseCommands as defineBaseCommands_alias_1 }
|
64
142
|
|
65
143
|
/** @public */
|
66
|
-
declare function
|
67
|
-
export {
|
68
|
-
export {
|
144
|
+
declare function defineBaseKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
145
|
+
export { defineBaseKeymap }
|
146
|
+
export { defineBaseKeymap as defineBaseKeymap_alias_1 }
|
69
147
|
|
70
|
-
declare function
|
148
|
+
declare function defineCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
|
71
149
|
COMMAND_ARGS: {
|
72
150
|
[K in keyof T]: Parameters<T[K]>;
|
73
151
|
};
|
74
152
|
}>;
|
75
|
-
export {
|
76
|
-
export {
|
153
|
+
export { defineCommands }
|
154
|
+
export { defineCommands as defineCommands_alias_1 }
|
77
155
|
|
78
|
-
declare function
|
79
|
-
export {
|
80
|
-
export {
|
156
|
+
declare function defineDefaultState(options: DefaultStateOptions): Extension;
|
157
|
+
export { defineDefaultState }
|
158
|
+
export { defineDefaultState as defineDefaultState_alias_1 }
|
81
159
|
|
82
160
|
/** @public */
|
83
|
-
declare function
|
161
|
+
declare function defineDoc(): Extension< {
|
84
162
|
NODES: "doc";
|
85
163
|
}>;
|
86
|
-
export {
|
87
|
-
export {
|
164
|
+
export { defineDoc }
|
165
|
+
export { defineDoc as defineDoc_alias_1 }
|
88
166
|
|
89
167
|
/**
|
90
168
|
* @internal
|
91
169
|
*/
|
92
|
-
declare function
|
170
|
+
declare function defineEventHandler(options: {
|
93
171
|
update?: VoidFunction;
|
94
172
|
}): FacetExtension<VoidFunction, PluginFacetInput>;
|
95
|
-
export {
|
96
|
-
export {
|
173
|
+
export { defineEventHandler }
|
174
|
+
export { defineEventHandler as defineEventHandler_alias_1 }
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Add undo/redo history to the editor.
|
178
|
+
*/
|
179
|
+
declare function defineHistory(): Extension< {
|
180
|
+
COMMAND_ARGS: {
|
181
|
+
undo: [];
|
182
|
+
redo: [];
|
183
|
+
};
|
184
|
+
}>;
|
185
|
+
export { defineHistory }
|
186
|
+
export { defineHistory as defineHistory_alias_1 }
|
97
187
|
|
98
188
|
/**
|
99
189
|
* @public
|
100
190
|
*/
|
101
|
-
declare function
|
191
|
+
declare function defineInputRule(rules: (context: {
|
102
192
|
schema: Schema;
|
103
193
|
}) => InputRule[]): Extension;
|
104
|
-
export {
|
105
|
-
export {
|
194
|
+
export { defineInputRule }
|
195
|
+
export { defineInputRule as defineInputRule_alias_1 }
|
106
196
|
|
107
197
|
/** @public */
|
108
|
-
declare function
|
109
|
-
export {
|
110
|
-
export {
|
111
|
-
|
112
|
-
declare function addMark(options: AddMarkOptions): Command;
|
113
|
-
export { addMark }
|
114
|
-
export { addMark as addMark_alias_1 }
|
115
|
-
|
116
|
-
declare interface AddMarkOptions {
|
117
|
-
type: string | MarkType;
|
118
|
-
attrs?: Attrs | null;
|
119
|
-
/**
|
120
|
-
* The start position of the mark. By default it will be the start position of current selection.
|
121
|
-
*/
|
122
|
-
from?: number;
|
123
|
-
/**
|
124
|
-
* The end position of the mark. By default it will be the end position of current selection.
|
125
|
-
*/
|
126
|
-
to?: number;
|
127
|
-
}
|
128
|
-
export { AddMarkOptions }
|
129
|
-
export { AddMarkOptions as AddMarkOptions_alias_1 }
|
198
|
+
declare function defineKeymap(keymap: Keymap): Extension;
|
199
|
+
export { defineKeymap }
|
200
|
+
export { defineKeymap as defineKeymap_alias_1 }
|
130
201
|
|
131
202
|
/**
|
132
203
|
* @public
|
133
204
|
*/
|
134
|
-
declare function
|
205
|
+
declare function defineMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>): Extension<{
|
135
206
|
MARKS: Mark;
|
136
207
|
}>;
|
137
|
-
export {
|
138
|
-
export {
|
208
|
+
export { defineMarkSpec }
|
209
|
+
export { defineMarkSpec as defineMarkSpec_alias_1 }
|
139
210
|
|
140
211
|
/**
|
141
212
|
* @public
|
142
213
|
*/
|
143
|
-
declare function
|
214
|
+
declare function defineNodeSpec<NodeName extends string>(options: NodeSpecOptions<NodeName>): Extension<{
|
144
215
|
NODES: NodeName;
|
145
216
|
}>;
|
146
|
-
export {
|
147
|
-
export {
|
217
|
+
export { defineNodeSpec }
|
218
|
+
export { defineNodeSpec as defineNodeSpec_alias_1 }
|
148
219
|
|
149
|
-
declare function
|
150
|
-
export {
|
151
|
-
export {
|
220
|
+
declare function defineNodeView(options: NodeViewOptions): Extension;
|
221
|
+
export { defineNodeView }
|
222
|
+
export { defineNodeView as defineNodeView_alias_1 }
|
152
223
|
|
153
224
|
/** @public */
|
154
|
-
declare function
|
225
|
+
declare function defineParagraph(): Extension< {
|
155
226
|
NODES: "paragraph";
|
156
227
|
}>;
|
157
|
-
export {
|
158
|
-
export {
|
228
|
+
export { defineParagraph }
|
229
|
+
export { defineParagraph as defineParagraph_alias_1 }
|
159
230
|
|
160
231
|
/**
|
161
232
|
* Adds a ProseMirror plugin to the editor.
|
@@ -165,78 +236,18 @@ export { addParagraph as addParagraph_alias_1 }
|
|
165
236
|
*
|
166
237
|
* @public
|
167
238
|
*/
|
168
|
-
declare function
|
239
|
+
declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
|
169
240
|
schema: Schema;
|
170
241
|
}) => Plugin_2[])): Extension;
|
171
|
-
export {
|
172
|
-
export {
|
242
|
+
export { definePlugin }
|
243
|
+
export { definePlugin as definePlugin_alias_1 }
|
173
244
|
|
174
245
|
/** @public */
|
175
|
-
declare function
|
246
|
+
declare function defineText(): Extension< {
|
176
247
|
NODES: "text";
|
177
248
|
}>;
|
178
|
-
export {
|
179
|
-
export {
|
180
|
-
|
181
|
-
export declare type AnySlot = Slot<any, any>;
|
182
|
-
|
183
|
-
export declare function applyAction(operator: Action): Command;
|
184
|
-
|
185
|
-
/**
|
186
|
-
* Utility function assert that two types are equal in tests.
|
187
|
-
*/
|
188
|
-
export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
|
189
|
-
|
190
|
-
export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
191
|
-
|
192
|
-
/** @internal */
|
193
|
-
declare interface CommandArgs {
|
194
|
-
[name: string]: any[];
|
195
|
-
}
|
196
|
-
export { CommandArgs }
|
197
|
-
export { CommandArgs as CommandArgs_alias_1 }
|
198
|
-
|
199
|
-
export declare type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
|
200
|
-
|
201
|
-
export declare interface CommandCreators {
|
202
|
-
[name: string]: CommandCreator;
|
203
|
-
}
|
204
|
-
|
205
|
-
export declare type CommandDispatcher<Args extends any[] = any[]> = (...arg: Args) => boolean;
|
206
|
-
|
207
|
-
export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>;
|
208
|
-
|
209
|
-
export declare type CommandSlotInput = Record<string, CommandCreator<any>>;
|
210
|
-
|
211
|
-
/** @public */
|
212
|
-
declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;
|
213
|
-
export { createEditor }
|
214
|
-
export { createEditor as createEditor_alias_1 }
|
215
|
-
|
216
|
-
export declare function createMarkBuilder(getState: () => EditorState | null | undefined, type: MarkType): MarkBuilder;
|
217
|
-
|
218
|
-
export declare function createNodeBuilder(getState: () => EditorState | null | undefined, type: NodeType): NodeBuilder;
|
219
|
-
|
220
|
-
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
221
|
-
|
222
|
-
export declare const default_alias_1: UserProjectConfigExport;
|
223
|
-
|
224
|
-
declare interface DefaultStateOptions {
|
225
|
-
/**
|
226
|
-
* A JSON representation of a ProseMirror document.
|
227
|
-
*/
|
228
|
-
doc?: NodeJson;
|
229
|
-
/**
|
230
|
-
* A JSON representation of a ProseMirror selection.
|
231
|
-
*/
|
232
|
-
selection?: SelectionJson;
|
233
|
-
}
|
234
|
-
export { DefaultStateOptions }
|
235
|
-
export { DefaultStateOptions as DefaultStateOptions_alias_1 }
|
236
|
-
|
237
|
-
declare function defineExtension<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
238
|
-
export { defineExtension }
|
239
|
-
export { defineExtension as defineExtension_alias_1 }
|
249
|
+
export { defineText }
|
250
|
+
export { defineText as defineText_alias_1 }
|
240
251
|
|
241
252
|
/** @public */
|
242
253
|
declare class Editor<E extends Extension = any> {
|
@@ -248,7 +259,7 @@ declare class Editor<E extends Extension = any> {
|
|
248
259
|
get mounted(): boolean;
|
249
260
|
get view(): EditorView;
|
250
261
|
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
|
251
|
-
get commands():
|
262
|
+
get commands(): ExtractCommandAppliers<E>;
|
252
263
|
mount(place: HTMLElement | null | undefined | void): void;
|
253
264
|
unmount(): void;
|
254
265
|
use(extension: Extension): VoidFunction;
|
@@ -286,7 +297,7 @@ declare interface EditorOptions<E extends Extension> {
|
|
286
297
|
export { EditorOptions }
|
287
298
|
export { EditorOptions as EditorOptions_alias_1 }
|
288
299
|
|
289
|
-
declare type EmptyValue =
|
300
|
+
declare type EmptyValue = undefined | null | EmptyObject;
|
290
301
|
|
291
302
|
export declare type ExceptEmptyValue<T> = ConditionalExcept<T, EmptyValue>;
|
292
303
|
|
@@ -312,6 +323,13 @@ declare interface ExtensionTyping<Node extends string = string, Mark extends str
|
|
312
323
|
export { ExtensionTyping }
|
313
324
|
export { ExtensionTyping as ExtensionTyping_alias_1 }
|
314
325
|
|
326
|
+
/**
|
327
|
+
* @public
|
328
|
+
*/
|
329
|
+
declare type ExtractCommandAppliers<E extends Extension> = ToCommandApplier<ExtractCommandArgs<E>>;
|
330
|
+
export { ExtractCommandAppliers }
|
331
|
+
export { ExtractCommandAppliers as ExtractCommandAppliers_alias_1 }
|
332
|
+
|
315
333
|
/**
|
316
334
|
* @internal
|
317
335
|
*/
|
@@ -326,13 +344,6 @@ declare type ExtractCommandCreators<E extends Extension> = ToCommandCreators<Ext
|
|
326
344
|
export { ExtractCommandCreators }
|
327
345
|
export { ExtractCommandCreators as ExtractCommandCreators_alias_1 }
|
328
346
|
|
329
|
-
/**
|
330
|
-
* @public
|
331
|
-
*/
|
332
|
-
declare type ExtractCommandDispatchers<E extends Extension> = ToCommandDispatcher<ExtractCommandArgs<E>>;
|
333
|
-
export { ExtractCommandDispatchers }
|
334
|
-
export { ExtractCommandDispatchers as ExtractCommandDispatchers_alias_1 }
|
335
|
-
|
336
347
|
/**
|
337
348
|
* @intneral
|
338
349
|
*/
|
@@ -421,6 +432,8 @@ export declare function insertNode({ node, pos, }: {
|
|
421
432
|
pos?: number;
|
422
433
|
}): Action;
|
423
434
|
|
435
|
+
export declare const isMac: boolean;
|
436
|
+
|
424
437
|
export declare function isMark(mark: unknown): mark is Mark;
|
425
438
|
|
426
439
|
export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;
|
@@ -611,6 +624,10 @@ export { StateJson as StateJson_alias_1 }
|
|
611
624
|
|
612
625
|
export declare const stateSlot: Facet<StateConfigCallback, StateConfigCallback>;
|
613
626
|
|
627
|
+
export declare type ToCommandApplier<T extends CommandArgs> = {
|
628
|
+
[K in keyof T]: CommandApplier<T[K]>;
|
629
|
+
};
|
630
|
+
|
614
631
|
export declare type ToCommandArgs<T extends CommandCreators> = {
|
615
632
|
[K in keyof T]: Parameters<T[K]>;
|
616
633
|
};
|
@@ -619,10 +636,6 @@ export declare type ToCommandCreators<T extends CommandArgs> = {
|
|
619
636
|
[K in keyof T]: CommandCreator<T[K]>;
|
620
637
|
};
|
621
638
|
|
622
|
-
export declare type ToCommandDispatcher<T extends CommandArgs> = {
|
623
|
-
[K in keyof T]: CommandDispatcher<T[K]>;
|
624
|
-
};
|
625
|
-
|
626
639
|
declare function toggleMark(options: ToggleMarkOptions): Command;
|
627
640
|
export { toggleMark }
|
628
641
|
export { toggleMark as toggleMark_alias_1 }
|
@@ -645,6 +658,10 @@ declare interface ToggleNodeOptions {
|
|
645
658
|
export { ToggleNodeOptions }
|
646
659
|
export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
|
647
660
|
|
661
|
+
declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
662
|
+
export { union }
|
663
|
+
export { union as union_alias_1 }
|
664
|
+
|
648
665
|
export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[];
|
649
666
|
|
650
667
|
export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -10,34 +10,35 @@ export { EditorOptions } from './_tsup-dts-rollup';
|
|
10
10
|
export { Facet } from './_tsup-dts-rollup';
|
11
11
|
export { FacetExtension } from './_tsup-dts-rollup';
|
12
12
|
export { FacetOptions } from './_tsup-dts-rollup';
|
13
|
-
export {
|
13
|
+
export { union } from './_tsup-dts-rollup';
|
14
14
|
export { withPriority } from './_tsup-dts-rollup';
|
15
15
|
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
16
|
-
export {
|
17
|
-
export {
|
18
|
-
export {
|
16
|
+
export { defineBaseCommands } from './_tsup-dts-rollup';
|
17
|
+
export { defineCommands } from './_tsup-dts-rollup';
|
18
|
+
export { defineDefaultState } from './_tsup-dts-rollup';
|
19
19
|
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
20
|
-
export {
|
21
|
-
export {
|
22
|
-
export {
|
23
|
-
export {
|
24
|
-
export {
|
20
|
+
export { defineDoc } from './_tsup-dts-rollup';
|
21
|
+
export { defineEventHandler } from './_tsup-dts-rollup';
|
22
|
+
export { defineHistory } from './_tsup-dts-rollup';
|
23
|
+
export { defineInputRule } from './_tsup-dts-rollup';
|
24
|
+
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
25
|
+
export { defineKeymap } from './_tsup-dts-rollup';
|
25
26
|
export { Keymap } from './_tsup-dts-rollup';
|
26
|
-
export {
|
27
|
+
export { defineMarkSpec } from './_tsup-dts-rollup';
|
27
28
|
export { MarkSpecOptions } from './_tsup-dts-rollup';
|
28
|
-
export {
|
29
|
+
export { defineNodeSpec } from './_tsup-dts-rollup';
|
29
30
|
export { NodeSpecOptions } from './_tsup-dts-rollup';
|
30
|
-
export {
|
31
|
+
export { defineNodeView } from './_tsup-dts-rollup';
|
31
32
|
export { NodeViewOptions } from './_tsup-dts-rollup';
|
32
|
-
export {
|
33
|
-
export {
|
33
|
+
export { defineParagraph } from './_tsup-dts-rollup';
|
34
|
+
export { definePlugin } from './_tsup-dts-rollup';
|
34
35
|
export { pluginFacet } from './_tsup-dts-rollup';
|
35
36
|
export { PluginFacetInput } from './_tsup-dts-rollup';
|
36
|
-
export {
|
37
|
+
export { defineText } from './_tsup-dts-rollup';
|
37
38
|
export { CommandArgs } from './_tsup-dts-rollup';
|
38
39
|
export { Extension } from './_tsup-dts-rollup';
|
40
|
+
export { ExtractCommandAppliers } from './_tsup-dts-rollup';
|
39
41
|
export { ExtractCommandCreators } from './_tsup-dts-rollup';
|
40
|
-
export { ExtractCommandDispatchers } from './_tsup-dts-rollup';
|
41
42
|
export { ExtractMarks } from './_tsup-dts-rollup';
|
42
43
|
export { ExtractNodes } from './_tsup-dts-rollup';
|
43
44
|
export { SimplifyExtension } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -306,7 +306,7 @@ var commandSlot = Facet.defineSlot({
|
|
306
306
|
});
|
307
307
|
|
308
308
|
// src/extensions/default-state.ts
|
309
|
-
function
|
309
|
+
function defineDefaultState(options) {
|
310
310
|
return stateSlot.extension([
|
311
311
|
({ schema }) => {
|
312
312
|
const config = {};
|
@@ -597,7 +597,7 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
597
597
|
}
|
598
598
|
|
599
599
|
// src/editor/type-utils.ts
|
600
|
-
function
|
600
|
+
function union(extension) {
|
601
601
|
if (extension && Array.isArray(extension)) {
|
602
602
|
return { extension };
|
603
603
|
}
|
@@ -611,9 +611,9 @@ function createEditor({
|
|
611
611
|
defaultSelection
|
612
612
|
}) {
|
613
613
|
if (defaultDoc) {
|
614
|
-
extension =
|
614
|
+
extension = union([
|
615
615
|
extension,
|
616
|
-
|
616
|
+
defineDefaultState({
|
617
617
|
doc: defaultDoc,
|
618
618
|
selection: defaultSelection
|
619
619
|
})
|
@@ -624,7 +624,7 @@ function createEditor({
|
|
624
624
|
var EditorInstance = class {
|
625
625
|
constructor(extension) {
|
626
626
|
this.view = null;
|
627
|
-
this.
|
627
|
+
this.commandAppliers = {};
|
628
628
|
this.inputs = [];
|
629
629
|
this.slots = [];
|
630
630
|
this.mount = this.mount.bind(this);
|
@@ -638,7 +638,7 @@ var EditorInstance = class {
|
|
638
638
|
const state = EditorState.create(stateConfig);
|
639
639
|
if (commandInput) {
|
640
640
|
for (const [name, commandCreator] of Object.entries(commandInput)) {
|
641
|
-
this.
|
641
|
+
this.defineCommand(name, commandCreator);
|
642
642
|
}
|
643
643
|
}
|
644
644
|
this.directEditorProps = { state, ...viewInput };
|
@@ -682,7 +682,7 @@ var EditorInstance = class {
|
|
682
682
|
if (commandInput) {
|
683
683
|
const names = Object.keys(commandInput);
|
684
684
|
for (const name of names) {
|
685
|
-
this.
|
685
|
+
this.defineCommand(name, commandInput[name]);
|
686
686
|
}
|
687
687
|
}
|
688
688
|
}
|
@@ -707,7 +707,7 @@ var EditorInstance = class {
|
|
707
707
|
throw new ProseKitError("Editor is not mounted");
|
708
708
|
return this.view;
|
709
709
|
}
|
710
|
-
|
710
|
+
definePlugins(plugins) {
|
711
711
|
const view = this.assertView;
|
712
712
|
const state = view.state;
|
713
713
|
const newPlugins = [...plugins, ...state.plugins];
|
@@ -723,16 +723,27 @@ var EditorInstance = class {
|
|
723
723
|
const newState = state.reconfigure({ plugins: newPlugins });
|
724
724
|
view.setProps({ state: newState });
|
725
725
|
}
|
726
|
-
|
727
|
-
const
|
728
|
-
const view = this.
|
726
|
+
defineCommand(name, commandCreator) {
|
727
|
+
const applier = (...args) => {
|
728
|
+
const view = this.view;
|
729
|
+
if (!view) {
|
730
|
+
return false;
|
731
|
+
}
|
729
732
|
const command = commandCreator(...args);
|
730
733
|
return command(view.state, view.dispatch.bind(view), view);
|
731
734
|
};
|
732
|
-
|
735
|
+
applier.canApply = (...args) => {
|
736
|
+
const view = this.view;
|
737
|
+
if (!view) {
|
738
|
+
return false;
|
739
|
+
}
|
740
|
+
const command = commandCreator(...args);
|
741
|
+
return command(view.state, void 0, view);
|
742
|
+
};
|
743
|
+
this.commandAppliers[name] = applier;
|
733
744
|
}
|
734
745
|
removeCommand(name) {
|
735
|
-
delete this.
|
746
|
+
delete this.commandAppliers[name];
|
736
747
|
}
|
737
748
|
};
|
738
749
|
var Editor = class _Editor {
|
@@ -760,7 +771,7 @@ var Editor = class _Editor {
|
|
760
771
|
return this.instance.schema;
|
761
772
|
}
|
762
773
|
get commands() {
|
763
|
-
return this.instance.
|
774
|
+
return this.instance.commandAppliers;
|
764
775
|
}
|
765
776
|
mount(place) {
|
766
777
|
if (!place) {
|
@@ -817,11 +828,11 @@ function withPriority(extension, priority) {
|
|
817
828
|
import "@prosekit/pm/model";
|
818
829
|
import { AllSelection } from "@prosekit/pm/state";
|
819
830
|
import { findWrapping, insertPoint } from "@prosekit/pm/transform";
|
820
|
-
function
|
831
|
+
function defineCommands(commands) {
|
821
832
|
return commandSlot.extension([commands]);
|
822
833
|
}
|
823
|
-
function
|
824
|
-
return
|
834
|
+
function defineBaseCommands() {
|
835
|
+
return defineCommands({
|
825
836
|
insertText: ({
|
826
837
|
text,
|
827
838
|
from,
|
@@ -889,7 +900,7 @@ function addBaseCommands() {
|
|
889
900
|
}
|
890
901
|
|
891
902
|
// src/extensions/node-spec.ts
|
892
|
-
function
|
903
|
+
function defineNodeSpec(options) {
|
893
904
|
return nodeSpecFacet.extension([options]);
|
894
905
|
}
|
895
906
|
var nodeSpecFacet = Facet.define({
|
@@ -911,8 +922,8 @@ var nodeSpecFacet = Facet.define({
|
|
911
922
|
});
|
912
923
|
|
913
924
|
// src/extensions/doc.ts
|
914
|
-
function
|
915
|
-
return
|
925
|
+
function defineDoc() {
|
926
|
+
return defineNodeSpec({
|
916
927
|
name: "doc",
|
917
928
|
content: "block+"
|
918
929
|
});
|
@@ -928,7 +939,7 @@ function voidFunction() {
|
|
928
939
|
// src/extensions/plugin.ts
|
929
940
|
import "@prosekit/pm/model";
|
930
941
|
import { Plugin as Plugin2 } from "@prosekit/pm/state";
|
931
|
-
function
|
942
|
+
function definePlugin(plugin) {
|
932
943
|
if (plugin instanceof Plugin2) {
|
933
944
|
return pluginFacet.extension([() => [plugin]]);
|
934
945
|
}
|
@@ -951,7 +962,7 @@ var pluginFacet = Facet.define({
|
|
951
962
|
});
|
952
963
|
|
953
964
|
// src/extensions/event-handler.ts
|
954
|
-
function
|
965
|
+
function defineEventHandler(options) {
|
955
966
|
var _a;
|
956
967
|
const updateHandler = (_a = options == null ? void 0 : options.update) != null ? _a : voidFunction;
|
957
968
|
return eventFacet.extension([updateHandler]);
|
@@ -962,6 +973,7 @@ var eventFacet = Facet.define({
|
|
962
973
|
const plugin = new ProseMirrorPlugin({
|
963
974
|
key: pluginKey,
|
964
975
|
view: () => {
|
976
|
+
updateHandlers.forEach((fn) => fn());
|
965
977
|
return {
|
966
978
|
update: (_view, _prevState) => {
|
967
979
|
updateHandlers.forEach((fn) => fn());
|
@@ -986,32 +998,21 @@ var eventFacet = Facet.define({
|
|
986
998
|
});
|
987
999
|
var pluginKey = new PluginKey("prosekit-event-handler");
|
988
1000
|
|
989
|
-
// src/extensions/
|
990
|
-
import {
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
return inputRuleFacet.extension([rules]);
|
995
|
-
}
|
996
|
-
var inputRuleFacet = Facet.define({
|
997
|
-
combine: (inputs) => {
|
998
|
-
return (context) => {
|
999
|
-
const rules = inputs.flatMap((callback) => callback(context));
|
1000
|
-
return [inputRules({ rules })];
|
1001
|
-
};
|
1002
|
-
},
|
1003
|
-
next: pluginFacet
|
1004
|
-
});
|
1001
|
+
// src/extensions/history.ts
|
1002
|
+
import { history, redo, undo } from "@prosekit/pm/history";
|
1003
|
+
|
1004
|
+
// src/utils/env.ts
|
1005
|
+
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1005
1006
|
|
1006
1007
|
// src/extensions/keymap.ts
|
1007
1008
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1008
1009
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1009
|
-
import { Plugin as
|
1010
|
-
function
|
1010
|
+
import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state";
|
1011
|
+
function defineKeymap(keymap) {
|
1011
1012
|
return keymapFacet.extension([keymap]);
|
1012
1013
|
}
|
1013
|
-
function
|
1014
|
-
return
|
1014
|
+
function defineBaseKeymap() {
|
1015
|
+
return defineKeymap(baseKeymap);
|
1015
1016
|
}
|
1016
1017
|
var keymapFacet = Facet.define({
|
1017
1018
|
slot: () => {
|
@@ -1021,7 +1022,7 @@ var keymapFacet = Facet.define({
|
|
1021
1022
|
return handler(view, event);
|
1022
1023
|
return false;
|
1023
1024
|
};
|
1024
|
-
const plugin = new
|
1025
|
+
const plugin = new Plugin3({
|
1025
1026
|
key: keymapPluginKey,
|
1026
1027
|
props: { handleKeyDown: handlerWrapper }
|
1027
1028
|
});
|
@@ -1057,8 +1058,44 @@ function mergeKeymaps(keymaps) {
|
|
1057
1058
|
}
|
1058
1059
|
var keymapPluginKey = new PluginKey2("prosekit-keymap");
|
1059
1060
|
|
1061
|
+
// src/extensions/history.ts
|
1062
|
+
function defineHistory() {
|
1063
|
+
const keymap = {
|
1064
|
+
"Mod-z": undo,
|
1065
|
+
"Shift-Mod-z": redo
|
1066
|
+
};
|
1067
|
+
if (!isMac) {
|
1068
|
+
keymap["Mod-y"] = redo;
|
1069
|
+
}
|
1070
|
+
return union([
|
1071
|
+
definePlugin(history()),
|
1072
|
+
defineKeymap(keymap),
|
1073
|
+
defineCommands({
|
1074
|
+
undo: () => undo,
|
1075
|
+
redo: () => redo
|
1076
|
+
})
|
1077
|
+
]);
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
// src/extensions/input-rules.ts
|
1081
|
+
import { inputRules } from "@prosekit/pm/inputrules";
|
1082
|
+
import "@prosekit/pm/model";
|
1083
|
+
import "@prosekit/pm/state";
|
1084
|
+
function defineInputRule(rules) {
|
1085
|
+
return inputRuleFacet.extension([rules]);
|
1086
|
+
}
|
1087
|
+
var inputRuleFacet = Facet.define({
|
1088
|
+
combine: (inputs) => {
|
1089
|
+
return (context) => {
|
1090
|
+
const rules = inputs.flatMap((callback) => callback(context));
|
1091
|
+
return [inputRules({ rules })];
|
1092
|
+
};
|
1093
|
+
},
|
1094
|
+
next: pluginFacet
|
1095
|
+
});
|
1096
|
+
|
1060
1097
|
// src/extensions/mark-spec.ts
|
1061
|
-
function
|
1098
|
+
function defineMarkSpec(options) {
|
1062
1099
|
return markSpecFacet.extension([options]);
|
1063
1100
|
}
|
1064
1101
|
var markSpecFacet = Facet.define({
|
@@ -1078,7 +1115,7 @@ var markSpecFacet = Facet.define({
|
|
1078
1115
|
// src/extensions/node-view.ts
|
1079
1116
|
import { Plugin as Plugin5 } from "@prosekit/pm/state";
|
1080
1117
|
import "@prosekit/pm/view";
|
1081
|
-
function
|
1118
|
+
function defineNodeView(options) {
|
1082
1119
|
return nodeViewFacet.extension([options]);
|
1083
1120
|
}
|
1084
1121
|
var nodeViewFacet = Facet.define({
|
@@ -1095,8 +1132,8 @@ var nodeViewFacet = Facet.define({
|
|
1095
1132
|
});
|
1096
1133
|
|
1097
1134
|
// src/extensions/paragraph.ts
|
1098
|
-
function
|
1099
|
-
return
|
1135
|
+
function defineParagraph() {
|
1136
|
+
return defineNodeSpec({
|
1100
1137
|
name: "paragraph",
|
1101
1138
|
content: "inline*",
|
1102
1139
|
group: "block",
|
@@ -1108,8 +1145,8 @@ function addParagraph() {
|
|
1108
1145
|
}
|
1109
1146
|
|
1110
1147
|
// src/extensions/text.ts
|
1111
|
-
function
|
1112
|
-
return
|
1148
|
+
function defineText() {
|
1149
|
+
return defineNodeSpec({
|
1113
1150
|
name: "text",
|
1114
1151
|
group: "inline"
|
1115
1152
|
});
|
@@ -1120,27 +1157,28 @@ export {
|
|
1120
1157
|
FacetExtension,
|
1121
1158
|
Priority,
|
1122
1159
|
ProseKitError,
|
1123
|
-
addBaseCommands,
|
1124
|
-
addBaseKeymap,
|
1125
|
-
addCommands,
|
1126
|
-
addDefaultState,
|
1127
|
-
addDoc,
|
1128
|
-
addEventHandler,
|
1129
|
-
addInputRule,
|
1130
|
-
addKeymap,
|
1131
1160
|
addMark,
|
1132
|
-
addMarkSpec,
|
1133
|
-
addNodeSpec,
|
1134
|
-
addNodeView,
|
1135
|
-
addParagraph,
|
1136
|
-
addPlugin,
|
1137
|
-
addText,
|
1138
1161
|
createEditor,
|
1139
|
-
|
1162
|
+
defineBaseCommands,
|
1163
|
+
defineBaseKeymap,
|
1164
|
+
defineCommands,
|
1165
|
+
defineDefaultState,
|
1166
|
+
defineDoc,
|
1167
|
+
defineEventHandler,
|
1168
|
+
defineHistory,
|
1169
|
+
defineInputRule,
|
1170
|
+
defineKeymap,
|
1171
|
+
defineMarkSpec,
|
1172
|
+
defineNodeSpec,
|
1173
|
+
defineNodeView,
|
1174
|
+
defineParagraph,
|
1175
|
+
definePlugin,
|
1176
|
+
defineText,
|
1140
1177
|
getMarkType,
|
1141
1178
|
getNodeType,
|
1142
1179
|
pluginFacet,
|
1143
1180
|
toggleMark,
|
1144
1181
|
toggleNode,
|
1182
|
+
union,
|
1145
1183
|
withPriority
|
1146
1184
|
};
|
package/dist/style.css
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* ../../node_modules/.pnpm/prosemirror-view@1.
|
1
|
+
/* ../../node_modules/.pnpm/prosemirror-view@1.32.1/node_modules/prosemirror-view/style/prosemirror.css */
|
2
2
|
.ProseMirror {
|
3
3
|
position: relative;
|
4
4
|
}
|
@@ -25,6 +25,9 @@
|
|
25
25
|
.ProseMirror-hideselection {
|
26
26
|
caret-color: transparent;
|
27
27
|
}
|
28
|
+
.ProseMirror [draggable][contenteditable=false] {
|
29
|
+
user-select: text;
|
30
|
+
}
|
28
31
|
.ProseMirror-selectednode {
|
29
32
|
outline: 2px solid #8cf;
|
30
33
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/core",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.12",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -38,15 +38,15 @@
|
|
38
38
|
"dist"
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
|
-
"@prosekit/pm": "^0.0.
|
41
|
+
"@prosekit/pm": "^0.0.6",
|
42
42
|
"orderedmap": "^2.1.1",
|
43
|
-
"type-fest": "^4.
|
43
|
+
"type-fest": "^4.4.0"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
46
|
"@prosekit/dev": "*",
|
47
47
|
"tsup": "^7.2.0",
|
48
48
|
"typescript": "^5.2.2",
|
49
|
-
"vitest": "^0.34.
|
49
|
+
"vitest": "^0.34.6"
|
50
50
|
},
|
51
51
|
"scripts": {
|
52
52
|
"build:tsup": "tsup",
|
package/src/index.ts
CHANGED
@@ -3,34 +3,39 @@ export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
|
|
3
3
|
export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
|
4
4
|
export { Editor, createEditor, type EditorOptions } from './editor/editor'
|
5
5
|
export { Facet, FacetExtension, type FacetOptions } from './editor/facet'
|
6
|
-
export {
|
6
|
+
export { union } from './editor/type-utils'
|
7
7
|
export { withPriority } from './editor/with-priority'
|
8
8
|
export { ProseKitError } from './error'
|
9
|
-
export {
|
9
|
+
export { defineBaseCommands, defineCommands } from './extensions/command'
|
10
10
|
export {
|
11
|
-
|
11
|
+
defineDefaultState,
|
12
12
|
type DefaultStateOptions,
|
13
13
|
} from './extensions/default-state'
|
14
|
-
export {
|
15
|
-
export {
|
16
|
-
export {
|
17
|
-
export {
|
18
|
-
export { addMarkSpec, type MarkSpecOptions } from './extensions/mark-spec'
|
19
|
-
export { addNodeSpec, type NodeSpecOptions } from './extensions/node-spec'
|
20
|
-
export { addNodeView, type NodeViewOptions } from './extensions/node-view'
|
21
|
-
export { addParagraph } from './extensions/paragraph'
|
14
|
+
export { defineDoc } from './extensions/doc'
|
15
|
+
export { defineEventHandler } from './extensions/event-handler'
|
16
|
+
export { defineHistory } from './extensions/history'
|
17
|
+
export { defineInputRule } from './extensions/input-rules'
|
22
18
|
export {
|
23
|
-
|
19
|
+
defineBaseKeymap,
|
20
|
+
defineKeymap,
|
21
|
+
type Keymap,
|
22
|
+
} from './extensions/keymap'
|
23
|
+
export { defineMarkSpec, type MarkSpecOptions } from './extensions/mark-spec'
|
24
|
+
export { defineNodeSpec, type NodeSpecOptions } from './extensions/node-spec'
|
25
|
+
export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
|
26
|
+
export { defineParagraph } from './extensions/paragraph'
|
27
|
+
export {
|
28
|
+
definePlugin,
|
24
29
|
pluginFacet,
|
25
30
|
type PluginFacetInput,
|
26
31
|
} from './extensions/plugin'
|
27
|
-
export {
|
32
|
+
export { defineText } from './extensions/text'
|
28
33
|
export { type CommandArgs as CommandArgs } from './types/command'
|
29
34
|
export * from './types/editor'
|
30
35
|
export {
|
31
36
|
type Extension,
|
37
|
+
type ExtractCommandAppliers,
|
32
38
|
type ExtractCommandCreators,
|
33
|
-
type ExtractCommandDispatchers,
|
34
39
|
type ExtractMarks,
|
35
40
|
type ExtractNodes,
|
36
41
|
type SimplifyExtension,
|