@prosekit/core 0.0.0-next-20230627094841 → 0.0.1
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/README.md +1 -0
- package/dist/prosekit-core.d.ts +283 -0
- package/dist/prosekit-core.js +13 -5
- package/package.json +5 -5
package/README.md
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# @prosekit/core
|
@@ -0,0 +1,283 @@
|
|
1
|
+
import { MarkType, Attrs, Schema, ProseMirrorNode, NodeType, MarkSpec, NodeSpec } from '@prosekit/pm/model';
|
2
|
+
import { Command, EditorStateConfig, Plugin } from '@prosekit/pm/state';
|
3
|
+
import { EditorView, NodeViewConstructor, DirectEditorProps } from '@prosekit/pm/view';
|
4
|
+
import { ConditionalExcept, EmptyObject, Simplify, UnionToIntersection } from 'type-fest';
|
5
|
+
import { InputRule } from '@prosekit/pm/inputrules';
|
6
|
+
|
7
|
+
interface ToggleMarkOptions {
|
8
|
+
type: string | MarkType;
|
9
|
+
attrs?: Attrs | null;
|
10
|
+
}
|
11
|
+
declare function toggleMark(options: ToggleMarkOptions): Command;
|
12
|
+
|
13
|
+
type CommandDispatcher<Args extends any[] = any[]> = (...arg: Args) => boolean;
|
14
|
+
type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
|
15
|
+
/** @internal */
|
16
|
+
interface CommandArgs {
|
17
|
+
[name: string]: any[];
|
18
|
+
}
|
19
|
+
type ToCommandCreators<T extends CommandArgs> = {
|
20
|
+
[K in keyof T]: CommandCreator<T[K]>;
|
21
|
+
};
|
22
|
+
type ToCommandDispatcher<T extends CommandArgs> = {
|
23
|
+
[K in keyof T]: CommandDispatcher<T[K]>;
|
24
|
+
};
|
25
|
+
|
26
|
+
type EmptyValue = never | undefined | null | EmptyObject;
|
27
|
+
type ExceptEmptyValue<T> = ConditionalExcept<T, EmptyValue>;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @intneral
|
31
|
+
*/
|
32
|
+
type ExtractKey<T, K extends string> = Extract<T, Record<K, any>>[K];
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @internal
|
36
|
+
*/
|
37
|
+
interface ExtensionTyping<Node extends string = string, Mark extends string = string, Commands extends CommandArgs = CommandArgs> {
|
38
|
+
NODES?: Node;
|
39
|
+
MARKS?: Mark;
|
40
|
+
COMMAND_ARGS?: Commands;
|
41
|
+
}
|
42
|
+
type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'NODES'>;
|
43
|
+
type ExtractMarksFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'MARKS'>;
|
44
|
+
type ExtractCommandArgsFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'COMMAND_ARGS'>;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @public
|
48
|
+
*/
|
49
|
+
declare const enum Priority {
|
50
|
+
lowest = 4,
|
51
|
+
low = 3,
|
52
|
+
default = 2,
|
53
|
+
high = 1,
|
54
|
+
highest = 0
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @public
|
59
|
+
*/
|
60
|
+
interface Extension<T extends ExtensionTyping = ExtensionTyping> {
|
61
|
+
extension: Extension | Extension[];
|
62
|
+
priority?: Priority;
|
63
|
+
_type?: T;
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* @internal
|
67
|
+
*/
|
68
|
+
type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
|
69
|
+
/**
|
70
|
+
* @public
|
71
|
+
*/
|
72
|
+
type ExtractNodes<E extends Extension> = ExtractNodesFromTyping<ExtractTyping<E>>;
|
73
|
+
/**
|
74
|
+
* @public
|
75
|
+
*/
|
76
|
+
type ExtractMarks<E extends Extension> = ExtractMarksFromTyping<ExtractTyping<E>>;
|
77
|
+
/**
|
78
|
+
* @internal
|
79
|
+
*/
|
80
|
+
type ExtractCommandArgs<E extends Extension> = ExtractCommandArgsFromTyping<ExtractTyping<E>>;
|
81
|
+
/**
|
82
|
+
* @public
|
83
|
+
*/
|
84
|
+
type ExtractCommandCreators<E extends Extension> = ToCommandCreators<ExtractCommandArgs<E>>;
|
85
|
+
/**
|
86
|
+
* @public
|
87
|
+
*/
|
88
|
+
type ExtractCommandDispatchers<E extends Extension> = ToCommandDispatcher<ExtractCommandArgs<E>>;
|
89
|
+
/**
|
90
|
+
* @internal
|
91
|
+
*/
|
92
|
+
type SimplifyExtension<E extends Extension | Extension[]> = E extends Extension[] ? Extension<ExceptEmptyValue<{
|
93
|
+
NODES: ExtractNodes<E[number]>;
|
94
|
+
MARKS: ExtractMarks<E[number]>;
|
95
|
+
COMMAND_ARGS: SimplifyUnion<ExtractCommandArgs<E[number]>>;
|
96
|
+
}>> : E;
|
97
|
+
|
98
|
+
/** @public */
|
99
|
+
interface EditorOptions<E extends Extension> {
|
100
|
+
extension: E;
|
101
|
+
}
|
102
|
+
/** @public */
|
103
|
+
declare function createEditor<E extends Extension>({ extension, }: EditorOptions<E>): Editor<E>;
|
104
|
+
/** @public */
|
105
|
+
declare class Editor<E extends Extension = any> {
|
106
|
+
private instance;
|
107
|
+
private constructor();
|
108
|
+
private afterMounted;
|
109
|
+
/** @internal */
|
110
|
+
static create(instance: any): Editor<any>;
|
111
|
+
get mounted(): boolean;
|
112
|
+
get view(): EditorView;
|
113
|
+
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
|
114
|
+
get commands(): ExtractCommandDispatchers<E>;
|
115
|
+
mount(place: HTMLElement | null | undefined | void): void;
|
116
|
+
unmount(): void;
|
117
|
+
use(extension: Extension): VoidFunction;
|
118
|
+
}
|
119
|
+
|
120
|
+
/** @public */
|
121
|
+
interface FacetOptions<Input, Output> {
|
122
|
+
combine: (inputs: Input[]) => Output;
|
123
|
+
next: Facet<Output, any>;
|
124
|
+
}
|
125
|
+
/** @public */
|
126
|
+
declare class Facet<Input, Output> {
|
127
|
+
/** @internal */
|
128
|
+
readonly index: number;
|
129
|
+
/** @internal */
|
130
|
+
readonly combine: (inputs: Input[]) => Output;
|
131
|
+
/** @internal */
|
132
|
+
readonly next: Facet<Output, any> | null;
|
133
|
+
private constructor();
|
134
|
+
static define<Input, Output>({ combine, next }: FacetOptions<Input, Output>): Facet<Input, Output>;
|
135
|
+
/** @internal */
|
136
|
+
static defineSlot<Input>({ combine, }: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
|
137
|
+
extension(inputs: Input[]): FacetExtension<Input, Output>;
|
138
|
+
}
|
139
|
+
/** @public */
|
140
|
+
declare class FacetExtension<Input, Output> {
|
141
|
+
readonly facet: Facet<Input, Output>;
|
142
|
+
readonly inputs: Input[];
|
143
|
+
extension: Extension;
|
144
|
+
constructor(facet: Facet<Input, Output>, inputs: Input[]);
|
145
|
+
}
|
146
|
+
|
147
|
+
declare function defineExtension<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
148
|
+
|
149
|
+
/** @public */
|
150
|
+
declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Base class for all ProseKit errors.
|
154
|
+
*/
|
155
|
+
declare class ProseKitError extends Error {
|
156
|
+
}
|
157
|
+
|
158
|
+
declare function addCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
|
159
|
+
COMMAND_ARGS: {
|
160
|
+
[K in keyof T]: Parameters<T[K]>;
|
161
|
+
};
|
162
|
+
}>;
|
163
|
+
/**
|
164
|
+
* Add some base commands
|
165
|
+
*
|
166
|
+
* @public
|
167
|
+
*/
|
168
|
+
declare function addBaseCommands(): Extension<{
|
169
|
+
COMMAND_ARGS: {
|
170
|
+
insertText: [{
|
171
|
+
text: string;
|
172
|
+
from?: number | undefined;
|
173
|
+
to?: number | undefined;
|
174
|
+
}];
|
175
|
+
insertNode: [{
|
176
|
+
node: ProseMirrorNode;
|
177
|
+
pos?: number | undefined;
|
178
|
+
}];
|
179
|
+
wrap: [{
|
180
|
+
nodeType: NodeType;
|
181
|
+
attrs?: Attrs | null | undefined;
|
182
|
+
}];
|
183
|
+
setBlockType: [{
|
184
|
+
nodeType: NodeType;
|
185
|
+
attrs?: Attrs | null | undefined;
|
186
|
+
from?: number | undefined;
|
187
|
+
to?: number | undefined;
|
188
|
+
}];
|
189
|
+
selectAll: [];
|
190
|
+
};
|
191
|
+
}>;
|
192
|
+
|
193
|
+
/** @public */
|
194
|
+
declare function addDoc(): Extension<{
|
195
|
+
NODES: "doc";
|
196
|
+
}>;
|
197
|
+
|
198
|
+
/** @public */
|
199
|
+
declare function addInputRule(rules: (context: {
|
200
|
+
schema: Schema;
|
201
|
+
}) => InputRule[]): Extension;
|
202
|
+
|
203
|
+
/** @public */
|
204
|
+
interface Keymap {
|
205
|
+
[key: string]: Command;
|
206
|
+
}
|
207
|
+
/** @public */
|
208
|
+
declare function addKeymap(keymap: Keymap): Extension;
|
209
|
+
/** @public */
|
210
|
+
declare function addBaseKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
211
|
+
|
212
|
+
/**
|
213
|
+
* @public
|
214
|
+
*/
|
215
|
+
interface MarkSpecOptions<M extends string = string> {
|
216
|
+
name: M;
|
217
|
+
spec: MarkSpec;
|
218
|
+
}
|
219
|
+
/**
|
220
|
+
* @public
|
221
|
+
*/
|
222
|
+
declare function addMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>): Extension<{
|
223
|
+
MARKS: Mark;
|
224
|
+
}>;
|
225
|
+
|
226
|
+
/**
|
227
|
+
* @public
|
228
|
+
*/
|
229
|
+
interface NodeSpecOptions<N extends string = string> {
|
230
|
+
name: N;
|
231
|
+
spec: NodeSpec;
|
232
|
+
topNode?: boolean;
|
233
|
+
}
|
234
|
+
/**
|
235
|
+
* @public
|
236
|
+
*/
|
237
|
+
declare function addNodeSpec<Node extends string>(options: NodeSpecOptions<Node>): Extension<{
|
238
|
+
NODES: Node;
|
239
|
+
}>;
|
240
|
+
|
241
|
+
interface NodeViewOptions {
|
242
|
+
name: string;
|
243
|
+
constructor: NodeViewConstructor;
|
244
|
+
}
|
245
|
+
declare function addNodeView(options: NodeViewOptions): Extension;
|
246
|
+
|
247
|
+
/** @public */
|
248
|
+
declare function addParagraph(): Extension<{
|
249
|
+
NODES: "paragraph";
|
250
|
+
}>;
|
251
|
+
|
252
|
+
interface StateConfigContext {
|
253
|
+
schema: Schema;
|
254
|
+
}
|
255
|
+
type StateConfigCallback = (ctx: StateConfigContext) => EditorStateConfig;
|
256
|
+
type ViewProps = Omit<DirectEditorProps, 'state'>;
|
257
|
+
|
258
|
+
/** @public */
|
259
|
+
interface PluginOptions {
|
260
|
+
plugins: Plugin[] | ((context: {
|
261
|
+
schema: Schema;
|
262
|
+
}) => Plugin[]);
|
263
|
+
}
|
264
|
+
/** @public */
|
265
|
+
declare function addPlugin({ plugins }: PluginOptions): Extension;
|
266
|
+
|
267
|
+
/** @public */
|
268
|
+
declare function addText(): Extension<{
|
269
|
+
NODES: "text";
|
270
|
+
}>;
|
271
|
+
|
272
|
+
/**
|
273
|
+
* @intneral
|
274
|
+
*/
|
275
|
+
type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
|
276
|
+
|
277
|
+
/** @internal */
|
278
|
+
declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
|
279
|
+
|
280
|
+
/** @internal */
|
281
|
+
declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
282
|
+
|
283
|
+
export { CommandArgs, Editor, EditorOptions, Extension, ExtensionTyping, ExtractCommandCreators, ExtractCommandDispatchers, ExtractMarks, ExtractNodes, Facet, FacetExtension, FacetOptions, Keymap, MarkSpecOptions, NodeSpecOptions, NodeViewOptions, PluginOptions, Priority, ProseKitError, SimplifyUnion, StateConfigCallback, StateConfigContext, ViewProps, addBaseCommands, addBaseKeymap, addCommands, addDoc, addInputRule, addKeymap, addMarkSpec, addNodeSpec, addNodeView, addParagraph, addPlugin, addText, createEditor, defineExtension, getMarkType, getNodeType, toggleMark, withPriority };
|
package/dist/prosekit-core.js
CHANGED
@@ -280,8 +280,8 @@ var EditorInstance = class {
|
|
280
280
|
this.directEditorProps = directEditorProps;
|
281
281
|
this.view = null;
|
282
282
|
this.commandDispatchers = {};
|
283
|
-
this.mount.bind(this);
|
284
|
-
this.unmount.bind(this);
|
283
|
+
this.mount = this.mount.bind(this);
|
284
|
+
this.unmount = this.unmount.bind(this);
|
285
285
|
this.schema = directEditorProps.state.schema;
|
286
286
|
}
|
287
287
|
mount(place) {
|
@@ -291,7 +291,7 @@ var EditorInstance = class {
|
|
291
291
|
if (!place) {
|
292
292
|
throw new Error("Can't mount editor without a place");
|
293
293
|
}
|
294
|
-
this.view = new EditorView(place, this.directEditorProps);
|
294
|
+
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
295
295
|
}
|
296
296
|
unmount() {
|
297
297
|
if (!this.view) {
|
@@ -337,6 +337,9 @@ var Editor = class _Editor {
|
|
337
337
|
constructor(instance) {
|
338
338
|
this.afterMounted = [];
|
339
339
|
this.instance = instance;
|
340
|
+
this.mount = this.mount.bind(this);
|
341
|
+
this.unmount = this.unmount.bind(this);
|
342
|
+
this.use = this.use.bind(this);
|
340
343
|
}
|
341
344
|
/** @internal */
|
342
345
|
static create(instance) {
|
@@ -358,11 +361,16 @@ var Editor = class _Editor {
|
|
358
361
|
return this.instance.commandDispatchers;
|
359
362
|
}
|
360
363
|
mount(place) {
|
364
|
+
if (!place) {
|
365
|
+
return this.unmount();
|
366
|
+
}
|
361
367
|
this.instance.mount(place);
|
362
368
|
this.afterMounted.forEach((callback) => callback());
|
363
369
|
}
|
364
370
|
unmount() {
|
365
|
-
this.
|
371
|
+
if (this.mounted) {
|
372
|
+
this.instance.unmount();
|
373
|
+
}
|
366
374
|
}
|
367
375
|
use(extension) {
|
368
376
|
if (!this.mounted) {
|
@@ -663,7 +671,7 @@ function getNodeType(schema, type) {
|
|
663
671
|
if (typeof type === "string") {
|
664
672
|
const nodeType = schema.nodes[type];
|
665
673
|
if (!nodeType) {
|
666
|
-
throw new ProseKitError(`Cannot find node type "${type}"`);
|
674
|
+
throw new ProseKitError(`Cannot find ProseMirror node type "${type}"`);
|
667
675
|
}
|
668
676
|
return nodeType;
|
669
677
|
}
|
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.1",
|
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.1",
|
42
42
|
"orderedmap": "^2.1.1",
|
43
43
|
"type-fest": "^3.12.0"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
|
+
"@prosekit/dev": "^0.0.0",
|
46
47
|
"tsup": "^7.1.0",
|
47
|
-
"typescript": "^5.1.
|
48
|
-
"vitest": "^0.
|
49
|
-
"@prosekit/dev": "0.0.0"
|
48
|
+
"typescript": "^5.1.6",
|
49
|
+
"vitest": "^0.33.0"
|
50
50
|
},
|
51
51
|
"scripts": {
|
52
52
|
"build:tsup": "tsup",
|