@prosekit/core 0.0.7 → 0.0.8
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 +627 -0
- package/dist/prosekit-core.d.ts +53 -320
- package/dist/prosekit-core.js +65 -35
- package/package.json +4 -4
- package/src/index.ts +7 -3
@@ -0,0 +1,627 @@
|
|
1
|
+
import { Attrs } from '@prosekit/pm/model';
|
2
|
+
import { Command } from '@prosekit/pm/state';
|
3
|
+
import type { ConditionalExcept } from 'type-fest';
|
4
|
+
import type { DirectEditorProps } from '@prosekit/pm/view';
|
5
|
+
import type { EditorState } from '@prosekit/pm/state';
|
6
|
+
import type { EditorStateConfig } from '@prosekit/pm/state';
|
7
|
+
import { EditorView } from '@prosekit/pm/view';
|
8
|
+
import type { EmptyObject } from 'type-fest';
|
9
|
+
import { InputRule } from '@prosekit/pm/inputrules';
|
10
|
+
import type { IsEqual } from 'type-fest';
|
11
|
+
import type { MarkSpec } from '@prosekit/pm/model';
|
12
|
+
import { MarkType } from '@prosekit/pm/model';
|
13
|
+
import type { NodeSpec } from '@prosekit/pm/model';
|
14
|
+
import { NodeType } from '@prosekit/pm/model';
|
15
|
+
import { NodeViewConstructor } from '@prosekit/pm/view';
|
16
|
+
import { Options } from 'tsup';
|
17
|
+
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
18
|
+
import { ProseMirrorNode } from '@prosekit/pm/model';
|
19
|
+
import { Schema } from '@prosekit/pm/model';
|
20
|
+
import type { SchemaSpec } from '@prosekit/pm/model';
|
21
|
+
import type { Simplify } from 'type-fest';
|
22
|
+
import { Transaction } from '@prosekit/pm/state';
|
23
|
+
import type { UnionToIntersection } from 'type-fest';
|
24
|
+
import { UserProjectConfigExport } from 'vitest/dist/config.js';
|
25
|
+
|
26
|
+
declare type Action = (options: {
|
27
|
+
tr: Transaction;
|
28
|
+
view?: EditorView;
|
29
|
+
}) => boolean;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Add some base commands
|
33
|
+
*
|
34
|
+
* @public
|
35
|
+
*/
|
36
|
+
declare function addBaseCommands(): Extension<{
|
37
|
+
COMMAND_ARGS: {
|
38
|
+
insertText: [{
|
39
|
+
text: string;
|
40
|
+
from?: number | undefined;
|
41
|
+
to?: number | undefined;
|
42
|
+
}];
|
43
|
+
insertNode: [{
|
44
|
+
node: ProseMirrorNode;
|
45
|
+
pos?: number | undefined;
|
46
|
+
}];
|
47
|
+
wrap: [{
|
48
|
+
nodeType: NodeType;
|
49
|
+
attrs?: Attrs | null | undefined;
|
50
|
+
}];
|
51
|
+
setBlockType: [{
|
52
|
+
nodeType: NodeType;
|
53
|
+
attrs?: Attrs | null | undefined;
|
54
|
+
from?: number | undefined;
|
55
|
+
to?: number | undefined;
|
56
|
+
}];
|
57
|
+
selectAll: [];
|
58
|
+
};
|
59
|
+
}>;
|
60
|
+
export { addBaseCommands }
|
61
|
+
export { addBaseCommands as addBaseCommands_alias_1 }
|
62
|
+
|
63
|
+
/** @public */
|
64
|
+
declare function addBaseKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
65
|
+
export { addBaseKeymap }
|
66
|
+
export { addBaseKeymap as addBaseKeymap_alias_1 }
|
67
|
+
|
68
|
+
declare function addCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
|
69
|
+
COMMAND_ARGS: {
|
70
|
+
[K in keyof T]: Parameters<T[K]>;
|
71
|
+
};
|
72
|
+
}>;
|
73
|
+
export { addCommands }
|
74
|
+
export { addCommands as addCommands_alias_1 }
|
75
|
+
|
76
|
+
declare function addDefaultState(options: DefaultStateOptions): Extension;
|
77
|
+
export { addDefaultState }
|
78
|
+
export { addDefaultState as addDefaultState_alias_1 }
|
79
|
+
|
80
|
+
/** @public */
|
81
|
+
declare function addDoc(): Extension< {
|
82
|
+
NODES: "doc";
|
83
|
+
}>;
|
84
|
+
export { addDoc }
|
85
|
+
export { addDoc as addDoc_alias_1 }
|
86
|
+
|
87
|
+
/**
|
88
|
+
* @public
|
89
|
+
*/
|
90
|
+
declare function addInputRule(rules: (context: {
|
91
|
+
schema: Schema;
|
92
|
+
}) => InputRule[]): Extension;
|
93
|
+
export { addInputRule }
|
94
|
+
export { addInputRule as addInputRule_alias_1 }
|
95
|
+
|
96
|
+
/** @public */
|
97
|
+
declare function addKeymap(keymap: Keymap): Extension;
|
98
|
+
export { addKeymap }
|
99
|
+
export { addKeymap as addKeymap_alias_1 }
|
100
|
+
|
101
|
+
declare function addMark(options: AddMarkOptions): Command;
|
102
|
+
export { addMark }
|
103
|
+
export { addMark as addMark_alias_1 }
|
104
|
+
|
105
|
+
declare interface AddMarkOptions {
|
106
|
+
type: string | MarkType;
|
107
|
+
attrs?: Attrs | null;
|
108
|
+
/**
|
109
|
+
* The start position of the mark. By default it will be the start position of current selection.
|
110
|
+
*/
|
111
|
+
from?: number;
|
112
|
+
/**
|
113
|
+
* The end position of the mark. By default it will be the end position of current selection.
|
114
|
+
*/
|
115
|
+
to?: number;
|
116
|
+
}
|
117
|
+
export { AddMarkOptions }
|
118
|
+
export { AddMarkOptions as AddMarkOptions_alias_1 }
|
119
|
+
|
120
|
+
/**
|
121
|
+
* @public
|
122
|
+
*/
|
123
|
+
declare function addMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>): Extension<{
|
124
|
+
MARKS: Mark;
|
125
|
+
}>;
|
126
|
+
export { addMarkSpec }
|
127
|
+
export { addMarkSpec as addMarkSpec_alias_1 }
|
128
|
+
|
129
|
+
/**
|
130
|
+
* @public
|
131
|
+
*/
|
132
|
+
declare function addNodeSpec<NodeName extends string>(options: NodeSpecOptions<NodeName>): Extension<{
|
133
|
+
NODES: NodeName;
|
134
|
+
}>;
|
135
|
+
export { addNodeSpec }
|
136
|
+
export { addNodeSpec as addNodeSpec_alias_1 }
|
137
|
+
|
138
|
+
declare function addNodeView(options: NodeViewOptions): Extension;
|
139
|
+
export { addNodeView }
|
140
|
+
export { addNodeView as addNodeView_alias_1 }
|
141
|
+
|
142
|
+
/** @public */
|
143
|
+
declare function addParagraph(): Extension< {
|
144
|
+
NODES: "paragraph";
|
145
|
+
}>;
|
146
|
+
export { addParagraph }
|
147
|
+
export { addParagraph as addParagraph_alias_1 }
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Adds a ProseMirror plugin to the editor.
|
151
|
+
*
|
152
|
+
* @param plugin - The ProseMirror plugin to add, or an array of plugins, or a
|
153
|
+
* function that returns an array of plugins.
|
154
|
+
*
|
155
|
+
* @public
|
156
|
+
*/
|
157
|
+
declare function addPlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
|
158
|
+
schema: Schema;
|
159
|
+
}) => Plugin_2[])): Extension;
|
160
|
+
export { addPlugin }
|
161
|
+
export { addPlugin as addPlugin_alias_1 }
|
162
|
+
|
163
|
+
/** @public */
|
164
|
+
declare function addText(): Extension< {
|
165
|
+
NODES: "text";
|
166
|
+
}>;
|
167
|
+
export { addText }
|
168
|
+
export { addText as addText_alias_1 }
|
169
|
+
|
170
|
+
export declare type AnySlot = Slot<any, any>;
|
171
|
+
|
172
|
+
export declare function applyAction(operator: Action): Command;
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Utility function assert that two types are equal in tests.
|
176
|
+
*/
|
177
|
+
export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
|
178
|
+
|
179
|
+
/** @internal */
|
180
|
+
declare interface CommandArgs {
|
181
|
+
[name: string]: any[];
|
182
|
+
}
|
183
|
+
export { CommandArgs }
|
184
|
+
export { CommandArgs as CommandArgs_alias_1 }
|
185
|
+
|
186
|
+
export declare type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
|
187
|
+
|
188
|
+
export declare interface CommandCreators {
|
189
|
+
[name: string]: CommandCreator;
|
190
|
+
}
|
191
|
+
|
192
|
+
export declare type CommandDispatcher<Args extends any[] = any[]> = (...arg: Args) => boolean;
|
193
|
+
|
194
|
+
export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>;
|
195
|
+
|
196
|
+
export declare type CommandSlotInput = Record<string, CommandCreator<any>>;
|
197
|
+
|
198
|
+
/** @public */
|
199
|
+
declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;
|
200
|
+
export { createEditor }
|
201
|
+
export { createEditor as createEditor_alias_1 }
|
202
|
+
|
203
|
+
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
204
|
+
|
205
|
+
export declare const default_alias_1: UserProjectConfigExport;
|
206
|
+
|
207
|
+
declare interface DefaultStateOptions {
|
208
|
+
/**
|
209
|
+
* A JSON representation of a ProseMirror document.
|
210
|
+
*/
|
211
|
+
doc?: NodeJson;
|
212
|
+
/**
|
213
|
+
* A JSON representation of a ProseMirror selection.
|
214
|
+
*/
|
215
|
+
selection?: SelectionJson;
|
216
|
+
}
|
217
|
+
export { DefaultStateOptions }
|
218
|
+
export { DefaultStateOptions as DefaultStateOptions_alias_1 }
|
219
|
+
|
220
|
+
declare function defineExtension<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
221
|
+
export { defineExtension }
|
222
|
+
export { defineExtension as defineExtension_alias_1 }
|
223
|
+
|
224
|
+
/** @public */
|
225
|
+
declare class Editor<E extends Extension = any> {
|
226
|
+
private instance;
|
227
|
+
private constructor();
|
228
|
+
private afterMounted;
|
229
|
+
/** @internal */
|
230
|
+
static create(instance: any): Editor<any>;
|
231
|
+
get mounted(): boolean;
|
232
|
+
get view(): EditorView;
|
233
|
+
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
|
234
|
+
get commands(): ExtractCommandDispatchers<E>;
|
235
|
+
mount(place: HTMLElement | null | undefined | void): void;
|
236
|
+
unmount(): void;
|
237
|
+
use(extension: Extension): VoidFunction;
|
238
|
+
isNodeActive(nodeType: string | NodeType, attrs?: Attrs): boolean;
|
239
|
+
isMarkActive(markType: string | MarkType, attrs?: Attrs): boolean;
|
240
|
+
}
|
241
|
+
export { Editor }
|
242
|
+
export { Editor as Editor_alias_1 }
|
243
|
+
|
244
|
+
/** @public */
|
245
|
+
declare interface EditorOptions<E extends Extension> {
|
246
|
+
/**
|
247
|
+
* The extension to use when creating the editor.
|
248
|
+
*/
|
249
|
+
extension: E;
|
250
|
+
/**
|
251
|
+
* A JSON object representing the starting document to use when creating the
|
252
|
+
* editor.
|
253
|
+
*/
|
254
|
+
defaultDoc?: NodeJson;
|
255
|
+
/**
|
256
|
+
* A JSON object representing the starting selection to use when creating the
|
257
|
+
* editor. It's only used when `defaultDoc` is also provided.
|
258
|
+
*/
|
259
|
+
defaultSelection?: SelectionJson;
|
260
|
+
}
|
261
|
+
export { EditorOptions }
|
262
|
+
export { EditorOptions as EditorOptions_alias_1 }
|
263
|
+
|
264
|
+
declare type EmptyValue = never | undefined | null | EmptyObject;
|
265
|
+
|
266
|
+
export declare type ExceptEmptyValue<T> = ConditionalExcept<T, EmptyValue>;
|
267
|
+
|
268
|
+
/**
|
269
|
+
* @public
|
270
|
+
*/
|
271
|
+
declare interface Extension<T extends ExtensionTyping = ExtensionTyping> {
|
272
|
+
extension: Extension | Extension[];
|
273
|
+
priority?: Priority;
|
274
|
+
_type?: T;
|
275
|
+
}
|
276
|
+
export { Extension }
|
277
|
+
export { Extension as Extension_alias_1 }
|
278
|
+
|
279
|
+
/**
|
280
|
+
* @internal
|
281
|
+
*/
|
282
|
+
declare interface ExtensionTyping<Node extends string = string, Mark extends string = string, Commands extends CommandArgs = CommandArgs> {
|
283
|
+
NODES?: Node;
|
284
|
+
MARKS?: Mark;
|
285
|
+
COMMAND_ARGS?: Commands;
|
286
|
+
}
|
287
|
+
export { ExtensionTyping }
|
288
|
+
export { ExtensionTyping as ExtensionTyping_alias_1 }
|
289
|
+
|
290
|
+
/**
|
291
|
+
* @internal
|
292
|
+
*/
|
293
|
+
export declare type ExtractCommandArgs<E extends Extension> = ExtractCommandArgsFromTyping<ExtractTyping<E>>;
|
294
|
+
|
295
|
+
export declare type ExtractCommandArgsFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'COMMAND_ARGS'>;
|
296
|
+
|
297
|
+
/**
|
298
|
+
* @public
|
299
|
+
*/
|
300
|
+
declare type ExtractCommandCreators<E extends Extension> = ToCommandCreators<ExtractCommandArgs<E>>;
|
301
|
+
export { ExtractCommandCreators }
|
302
|
+
export { ExtractCommandCreators as ExtractCommandCreators_alias_1 }
|
303
|
+
|
304
|
+
/**
|
305
|
+
* @public
|
306
|
+
*/
|
307
|
+
declare type ExtractCommandDispatchers<E extends Extension> = ToCommandDispatcher<ExtractCommandArgs<E>>;
|
308
|
+
export { ExtractCommandDispatchers }
|
309
|
+
export { ExtractCommandDispatchers as ExtractCommandDispatchers_alias_1 }
|
310
|
+
|
311
|
+
/**
|
312
|
+
* @intneral
|
313
|
+
*/
|
314
|
+
export declare type ExtractKey<T, K extends string> = Extract<T, Record<K, any>>[K];
|
315
|
+
|
316
|
+
/**
|
317
|
+
* @public
|
318
|
+
*/
|
319
|
+
declare type ExtractMarks<E extends Extension> = ExtractMarksFromTyping<ExtractTyping<E>>;
|
320
|
+
export { ExtractMarks }
|
321
|
+
export { ExtractMarks as ExtractMarks_alias_1 }
|
322
|
+
|
323
|
+
export declare type ExtractMarksFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'MARKS'>;
|
324
|
+
|
325
|
+
/**
|
326
|
+
* @public
|
327
|
+
*/
|
328
|
+
declare type ExtractNodes<E extends Extension> = ExtractNodesFromTyping<ExtractTyping<E>>;
|
329
|
+
export { ExtractNodes }
|
330
|
+
export { ExtractNodes as ExtractNodes_alias_1 }
|
331
|
+
|
332
|
+
export declare type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'NODES'>;
|
333
|
+
|
334
|
+
/**
|
335
|
+
* @internal
|
336
|
+
*/
|
337
|
+
export declare type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
|
338
|
+
|
339
|
+
/** @public */
|
340
|
+
declare class Facet<Input, Output> {
|
341
|
+
/** @internal */
|
342
|
+
readonly index: number;
|
343
|
+
/** @internal */
|
344
|
+
readonly slot: () => Slot<Input, Output>;
|
345
|
+
/** @internal */
|
346
|
+
readonly next: Facet<Output, any> | null;
|
347
|
+
/** @internal */
|
348
|
+
readonly single: boolean;
|
349
|
+
private constructor();
|
350
|
+
static define<Input, Output>({ slot, combine, next, single, }: FacetOptions<Input, Output>): Facet<Input, Output>;
|
351
|
+
/** @internal */
|
352
|
+
static defineSlot<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
|
353
|
+
extension(inputs: Input[]): FacetExtension<Input, Output>;
|
354
|
+
}
|
355
|
+
export { Facet }
|
356
|
+
export { Facet as Facet_alias_1 }
|
357
|
+
|
358
|
+
/** @public */
|
359
|
+
declare class FacetExtension<Input, Output> {
|
360
|
+
readonly facet: Facet<Input, Output>;
|
361
|
+
readonly inputs: Input[];
|
362
|
+
extension: Extension;
|
363
|
+
constructor(facet: Facet<Input, Output>, inputs: Input[]);
|
364
|
+
}
|
365
|
+
export { FacetExtension }
|
366
|
+
export { FacetExtension as FacetExtension_alias_1 }
|
367
|
+
|
368
|
+
/** @public */
|
369
|
+
declare interface FacetOptions<Input, Output> {
|
370
|
+
combine?: (inputs: Input[]) => Output;
|
371
|
+
slot?: () => Slot<Input, Output>;
|
372
|
+
next: Facet<Output, any>;
|
373
|
+
single?: boolean;
|
374
|
+
}
|
375
|
+
export { FacetOptions }
|
376
|
+
export { FacetOptions as FacetOptions_alias_1 }
|
377
|
+
|
378
|
+
/** @internal */
|
379
|
+
declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
|
380
|
+
export { getMarkType }
|
381
|
+
export { getMarkType as getMarkType_alias_1 }
|
382
|
+
|
383
|
+
/** @internal */
|
384
|
+
declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
385
|
+
export { getNodeType }
|
386
|
+
export { getNodeType as getNodeType_alias_1 }
|
387
|
+
|
388
|
+
declare type Input = unknown;
|
389
|
+
|
390
|
+
export declare type Inputs = InputTuple[];
|
391
|
+
|
392
|
+
declare type InputTuple = [Input[], Input[], Input[], Input[], Input[]];
|
393
|
+
|
394
|
+
export declare function insertNode({ node, pos, }: {
|
395
|
+
node: ProseMirrorNode;
|
396
|
+
pos?: number;
|
397
|
+
}): Action;
|
398
|
+
|
399
|
+
export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;
|
400
|
+
|
401
|
+
export declare function isNodeActive(state: EditorState, type: string | NodeType, attrs?: Attrs | null): boolean;
|
402
|
+
|
403
|
+
/** @public */
|
404
|
+
declare interface Keymap {
|
405
|
+
[key: string]: Command;
|
406
|
+
}
|
407
|
+
export { Keymap }
|
408
|
+
export { Keymap as Keymap_alias_1 }
|
409
|
+
|
410
|
+
/**
|
411
|
+
* @public
|
412
|
+
*/
|
413
|
+
declare interface MarkSpecOptions<MarkName extends string = string> extends MarkSpec {
|
414
|
+
name: MarkName;
|
415
|
+
}
|
416
|
+
export { MarkSpecOptions }
|
417
|
+
export { MarkSpecOptions as MarkSpecOptions_alias_1 }
|
418
|
+
|
419
|
+
/**
|
420
|
+
* A JSON representation of the prosemirror node.
|
421
|
+
*
|
422
|
+
* @public
|
423
|
+
*/
|
424
|
+
declare interface NodeJson {
|
425
|
+
type: string;
|
426
|
+
marks?: Array<any>;
|
427
|
+
text?: string;
|
428
|
+
content?: NodeJson[];
|
429
|
+
attrs?: Record<string, any>;
|
430
|
+
}
|
431
|
+
export { NodeJson }
|
432
|
+
export { NodeJson as NodeJson_alias_1 }
|
433
|
+
|
434
|
+
/**
|
435
|
+
* @public
|
436
|
+
*/
|
437
|
+
declare interface NodeSpecOptions<NodeName extends string = string> extends NodeSpec {
|
438
|
+
name: NodeName;
|
439
|
+
topNode?: boolean;
|
440
|
+
}
|
441
|
+
export { NodeSpecOptions }
|
442
|
+
export { NodeSpecOptions as NodeSpecOptions_alias_1 }
|
443
|
+
|
444
|
+
declare interface NodeViewOptions {
|
445
|
+
name: string;
|
446
|
+
constructor: NodeViewConstructor;
|
447
|
+
}
|
448
|
+
export { NodeViewOptions }
|
449
|
+
export { NodeViewOptions as NodeViewOptions_alias_1 }
|
450
|
+
|
451
|
+
export declare function objectEqual<T>(a: T, b: T): boolean;
|
452
|
+
|
453
|
+
/** @internal */
|
454
|
+
declare const pluginFacet: Facet<PluginFacetInput, StateConfigCallback>;
|
455
|
+
export { pluginFacet }
|
456
|
+
export { pluginFacet as pluginFacet_alias_1 }
|
457
|
+
|
458
|
+
/** @internal */
|
459
|
+
declare type PluginFacetInput = (context: {
|
460
|
+
schema: Schema;
|
461
|
+
}) => Plugin_2[];
|
462
|
+
export { PluginFacetInput }
|
463
|
+
export { PluginFacetInput as PluginFacetInput_alias_1 }
|
464
|
+
|
465
|
+
/**
|
466
|
+
* @public
|
467
|
+
*/
|
468
|
+
declare const enum Priority {
|
469
|
+
lowest = 4,
|
470
|
+
low = 3,
|
471
|
+
default = 2,
|
472
|
+
high = 1,
|
473
|
+
highest = 0
|
474
|
+
}
|
475
|
+
export { Priority }
|
476
|
+
export { Priority as Priority_alias_1 }
|
477
|
+
|
478
|
+
/**
|
479
|
+
* Base class for all ProseKit errors.
|
480
|
+
*/
|
481
|
+
declare class ProseKitError extends Error {
|
482
|
+
}
|
483
|
+
export { ProseKitError }
|
484
|
+
export { ProseKitError as ProseKitError_alias_1 }
|
485
|
+
|
486
|
+
export declare const schemaSlot: Facet<SchemaSpec<any, any>, SchemaSpec<any, any>>;
|
487
|
+
|
488
|
+
/**
|
489
|
+
* A JSON representation of the prosemirror selection.
|
490
|
+
*
|
491
|
+
* @public
|
492
|
+
*/
|
493
|
+
declare interface SelectionJson {
|
494
|
+
from: number;
|
495
|
+
to: number;
|
496
|
+
type: string;
|
497
|
+
}
|
498
|
+
export { SelectionJson }
|
499
|
+
export { SelectionJson as SelectionJson_alias_1 }
|
500
|
+
|
501
|
+
/**
|
502
|
+
* @internal
|
503
|
+
*/
|
504
|
+
declare type SimplifyExtension<E extends Extension | Extension[]> = E extends Extension[] ? Extension<ExceptEmptyValue<{
|
505
|
+
NODES: ExtractNodes<E[number]>;
|
506
|
+
MARKS: ExtractMarks<E[number]>;
|
507
|
+
COMMAND_ARGS: SimplifyUnion<ExtractCommandArgs<E[number]>>;
|
508
|
+
}>> : E;
|
509
|
+
export { SimplifyExtension }
|
510
|
+
export { SimplifyExtension as SimplifyExtension_alias_1 }
|
511
|
+
|
512
|
+
/**
|
513
|
+
* @intneral
|
514
|
+
*/
|
515
|
+
declare type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
|
516
|
+
export { SimplifyUnion }
|
517
|
+
export { SimplifyUnion as SimplifyUnion_alias_1 }
|
518
|
+
|
519
|
+
export declare interface Slot<Input, Output> {
|
520
|
+
create: (inputs: Input[]) => Output;
|
521
|
+
update: (inputs: Input[]) => Output | null;
|
522
|
+
}
|
523
|
+
|
524
|
+
export declare type Slots = SlotTuple[];
|
525
|
+
|
526
|
+
declare type SlotTuple = [
|
527
|
+
AnySlot | undefined,
|
528
|
+
AnySlot | undefined,
|
529
|
+
AnySlot | undefined,
|
530
|
+
AnySlot | undefined,
|
531
|
+
AnySlot | undefined
|
532
|
+
];
|
533
|
+
|
534
|
+
/**
|
535
|
+
* Use topological sort algorithm to sort facets.
|
536
|
+
*/
|
537
|
+
export declare function sortFacets(unsorted: readonly Facet<any, any>[]): Facet<any, any>[];
|
538
|
+
|
539
|
+
declare type StateConfigCallback = (ctx: StateConfigContext) => EditorStateConfig;
|
540
|
+
export { StateConfigCallback }
|
541
|
+
export { StateConfigCallback as StateConfigCallback_alias_1 }
|
542
|
+
|
543
|
+
declare interface StateConfigContext {
|
544
|
+
schema: Schema;
|
545
|
+
}
|
546
|
+
export { StateConfigContext }
|
547
|
+
export { StateConfigContext as StateConfigContext_alias_1 }
|
548
|
+
|
549
|
+
/**
|
550
|
+
* A JSON representation of the prosemirror state.
|
551
|
+
*
|
552
|
+
* @public
|
553
|
+
*/
|
554
|
+
declare interface StateJson {
|
555
|
+
/**
|
556
|
+
* The main `ProseMirror` doc.
|
557
|
+
*/
|
558
|
+
doc: NodeJson;
|
559
|
+
/**
|
560
|
+
* The current selection.
|
561
|
+
*/
|
562
|
+
selection: SelectionJson;
|
563
|
+
}
|
564
|
+
export { StateJson }
|
565
|
+
export { StateJson as StateJson_alias_1 }
|
566
|
+
|
567
|
+
export declare const stateSlot: Facet<StateConfigCallback, StateConfigCallback>;
|
568
|
+
|
569
|
+
export declare type ToCommandArgs<T extends CommandCreators> = {
|
570
|
+
[K in keyof T]: Parameters<T[K]>;
|
571
|
+
};
|
572
|
+
|
573
|
+
export declare type ToCommandCreators<T extends CommandArgs> = {
|
574
|
+
[K in keyof T]: CommandCreator<T[K]>;
|
575
|
+
};
|
576
|
+
|
577
|
+
export declare type ToCommandDispatcher<T extends CommandArgs> = {
|
578
|
+
[K in keyof T]: CommandDispatcher<T[K]>;
|
579
|
+
};
|
580
|
+
|
581
|
+
declare function toggleMark(options: ToggleMarkOptions): Command;
|
582
|
+
export { toggleMark }
|
583
|
+
export { toggleMark as toggleMark_alias_1 }
|
584
|
+
|
585
|
+
declare interface ToggleMarkOptions {
|
586
|
+
type: string | MarkType;
|
587
|
+
attrs?: Attrs | null;
|
588
|
+
}
|
589
|
+
export { ToggleMarkOptions }
|
590
|
+
export { ToggleMarkOptions as ToggleMarkOptions_alias_1 }
|
591
|
+
|
592
|
+
declare function toggleNode(options: ToggleNodeOptions): Command;
|
593
|
+
export { toggleNode }
|
594
|
+
export { toggleNode as toggleNode_alias_1 }
|
595
|
+
|
596
|
+
declare interface ToggleNodeOptions {
|
597
|
+
type: string | NodeType;
|
598
|
+
attrs?: Attrs | null;
|
599
|
+
}
|
600
|
+
export { ToggleNodeOptions }
|
601
|
+
export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
|
602
|
+
|
603
|
+
export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[];
|
604
|
+
|
605
|
+
export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
|
606
|
+
|
607
|
+
export declare function updateExtension(prevInputs: Inputs, prevSlots: Slots, extension: Extension, mode: 'add' | 'remove'): {
|
608
|
+
schemaInput: SchemaSpec<any, any> | null;
|
609
|
+
stateInput: StateConfigCallback | null;
|
610
|
+
viewInput: ViewProps | null;
|
611
|
+
commandInput: CommandSlotInput | null;
|
612
|
+
};
|
613
|
+
|
614
|
+
declare type ViewProps = Omit<DirectEditorProps, 'state'>;
|
615
|
+
export { ViewProps }
|
616
|
+
export { ViewProps as ViewProps_alias_1 }
|
617
|
+
|
618
|
+
export declare const viewSlot: Facet<ViewProps, ViewProps>;
|
619
|
+
|
620
|
+
export declare function voidFunction(): void;
|
621
|
+
|
622
|
+
/** @public */
|
623
|
+
declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
|
624
|
+
export { withPriority }
|
625
|
+
export { withPriority as withPriority_alias_1 }
|
626
|
+
|
627
|
+
export { }
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -1,320 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
};
|
42
|
-
|
43
|
-
|
44
|
-
};
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
/**
|
55
|
-
* @internal
|
56
|
-
*/
|
57
|
-
interface ExtensionTyping<Node extends string = string, Mark extends string = string, Commands extends CommandArgs = CommandArgs> {
|
58
|
-
NODES?: Node;
|
59
|
-
MARKS?: Mark;
|
60
|
-
COMMAND_ARGS?: Commands;
|
61
|
-
}
|
62
|
-
type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'NODES'>;
|
63
|
-
type ExtractMarksFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'MARKS'>;
|
64
|
-
type ExtractCommandArgsFromTyping<T extends ExtensionTyping> = ExtractKey<T, 'COMMAND_ARGS'>;
|
65
|
-
|
66
|
-
/**
|
67
|
-
* @public
|
68
|
-
*/
|
69
|
-
declare const enum Priority {
|
70
|
-
lowest = 4,
|
71
|
-
low = 3,
|
72
|
-
default = 2,
|
73
|
-
high = 1,
|
74
|
-
highest = 0
|
75
|
-
}
|
76
|
-
|
77
|
-
/**
|
78
|
-
* @intneral
|
79
|
-
*/
|
80
|
-
type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
|
81
|
-
|
82
|
-
/**
|
83
|
-
* @public
|
84
|
-
*/
|
85
|
-
interface Extension<T extends ExtensionTyping = ExtensionTyping> {
|
86
|
-
extension: Extension | Extension[];
|
87
|
-
priority?: Priority;
|
88
|
-
_type?: T;
|
89
|
-
}
|
90
|
-
/**
|
91
|
-
* @internal
|
92
|
-
*/
|
93
|
-
type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
|
94
|
-
/**
|
95
|
-
* @public
|
96
|
-
*/
|
97
|
-
type ExtractNodes<E extends Extension> = ExtractNodesFromTyping<ExtractTyping<E>>;
|
98
|
-
/**
|
99
|
-
* @public
|
100
|
-
*/
|
101
|
-
type ExtractMarks<E extends Extension> = ExtractMarksFromTyping<ExtractTyping<E>>;
|
102
|
-
/**
|
103
|
-
* @internal
|
104
|
-
*/
|
105
|
-
type ExtractCommandArgs<E extends Extension> = ExtractCommandArgsFromTyping<ExtractTyping<E>>;
|
106
|
-
/**
|
107
|
-
* @public
|
108
|
-
*/
|
109
|
-
type ExtractCommandCreators<E extends Extension> = ToCommandCreators<ExtractCommandArgs<E>>;
|
110
|
-
/**
|
111
|
-
* @public
|
112
|
-
*/
|
113
|
-
type ExtractCommandDispatchers<E extends Extension> = ToCommandDispatcher<ExtractCommandArgs<E>>;
|
114
|
-
/**
|
115
|
-
* @internal
|
116
|
-
*/
|
117
|
-
type SimplifyExtension<E extends Extension | Extension[]> = E extends Extension[] ? Extension<ExceptEmptyValue<{
|
118
|
-
NODES: ExtractNodes<E[number]>;
|
119
|
-
MARKS: ExtractMarks<E[number]>;
|
120
|
-
COMMAND_ARGS: SimplifyUnion<ExtractCommandArgs<E[number]>>;
|
121
|
-
}>> : E;
|
122
|
-
|
123
|
-
/** @public */
|
124
|
-
interface EditorOptions<E extends Extension> {
|
125
|
-
extension: E;
|
126
|
-
}
|
127
|
-
/** @public */
|
128
|
-
declare function createEditor<E extends Extension>({ extension, }: EditorOptions<E>): Editor<E>;
|
129
|
-
/** @public */
|
130
|
-
declare class Editor<E extends Extension = any> {
|
131
|
-
private instance;
|
132
|
-
private constructor();
|
133
|
-
private afterMounted;
|
134
|
-
/** @internal */
|
135
|
-
static create(instance: any): Editor<any>;
|
136
|
-
get mounted(): boolean;
|
137
|
-
get view(): EditorView;
|
138
|
-
get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
|
139
|
-
get commands(): ExtractCommandDispatchers<E>;
|
140
|
-
mount(place: HTMLElement | null | undefined | void): void;
|
141
|
-
unmount(): void;
|
142
|
-
use(extension: Extension): VoidFunction;
|
143
|
-
isNodeActive(nodeType: string | NodeType, attrs?: Attrs): boolean;
|
144
|
-
isMarkActive(markType: string | MarkType, attrs?: Attrs): boolean;
|
145
|
-
}
|
146
|
-
|
147
|
-
interface Slot<Input, Output> {
|
148
|
-
create: (inputs: Input[]) => Output;
|
149
|
-
update: (inputs: Input[]) => Output | null;
|
150
|
-
}
|
151
|
-
|
152
|
-
/** @public */
|
153
|
-
interface FacetOptions<Input, Output> {
|
154
|
-
combine?: (inputs: Input[]) => Output;
|
155
|
-
slot?: () => Slot<Input, Output>;
|
156
|
-
next: Facet<Output, any>;
|
157
|
-
single?: boolean;
|
158
|
-
}
|
159
|
-
/** @public */
|
160
|
-
declare class Facet<Input, Output> {
|
161
|
-
/** @internal */
|
162
|
-
readonly index: number;
|
163
|
-
/** @internal */
|
164
|
-
readonly slot: () => Slot<Input, Output>;
|
165
|
-
/** @internal */
|
166
|
-
readonly next: Facet<Output, any> | null;
|
167
|
-
/** @internal */
|
168
|
-
readonly single: boolean;
|
169
|
-
private constructor();
|
170
|
-
static define<Input, Output>({ slot, combine, next, single, }: FacetOptions<Input, Output>): Facet<Input, Output>;
|
171
|
-
/** @internal */
|
172
|
-
static defineSlot<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
|
173
|
-
extension(inputs: Input[]): FacetExtension<Input, Output>;
|
174
|
-
}
|
175
|
-
/** @public */
|
176
|
-
declare class FacetExtension<Input, Output> {
|
177
|
-
readonly facet: Facet<Input, Output>;
|
178
|
-
readonly inputs: Input[];
|
179
|
-
extension: Extension;
|
180
|
-
constructor(facet: Facet<Input, Output>, inputs: Input[]);
|
181
|
-
}
|
182
|
-
|
183
|
-
declare function defineExtension<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
|
184
|
-
|
185
|
-
/** @public */
|
186
|
-
declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
|
187
|
-
|
188
|
-
/**
|
189
|
-
* Base class for all ProseKit errors.
|
190
|
-
*/
|
191
|
-
declare class ProseKitError extends Error {
|
192
|
-
}
|
193
|
-
|
194
|
-
declare function addCommands<T extends Record<string, CommandCreator> = Record<string, CommandCreator>>(commands: T): Extension<{
|
195
|
-
COMMAND_ARGS: {
|
196
|
-
[K in keyof T]: Parameters<T[K]>;
|
197
|
-
};
|
198
|
-
}>;
|
199
|
-
/**
|
200
|
-
* Add some base commands
|
201
|
-
*
|
202
|
-
* @public
|
203
|
-
*/
|
204
|
-
declare function addBaseCommands(): Extension<{
|
205
|
-
COMMAND_ARGS: {
|
206
|
-
insertText: [{
|
207
|
-
text: string;
|
208
|
-
from?: number | undefined;
|
209
|
-
to?: number | undefined;
|
210
|
-
}];
|
211
|
-
insertNode: [{
|
212
|
-
node: ProseMirrorNode;
|
213
|
-
pos?: number | undefined;
|
214
|
-
}];
|
215
|
-
wrap: [{
|
216
|
-
nodeType: NodeType;
|
217
|
-
attrs?: Attrs | null | undefined;
|
218
|
-
}];
|
219
|
-
setBlockType: [{
|
220
|
-
nodeType: NodeType;
|
221
|
-
attrs?: Attrs | null | undefined;
|
222
|
-
from?: number | undefined;
|
223
|
-
to?: number | undefined;
|
224
|
-
}];
|
225
|
-
selectAll: [];
|
226
|
-
};
|
227
|
-
}>;
|
228
|
-
|
229
|
-
/** @public */
|
230
|
-
declare function addDoc(): Extension<{
|
231
|
-
NODES: "doc";
|
232
|
-
}>;
|
233
|
-
|
234
|
-
/**
|
235
|
-
* @public
|
236
|
-
*/
|
237
|
-
declare function addInputRule(rules: (context: {
|
238
|
-
schema: Schema;
|
239
|
-
}) => InputRule[]): Extension;
|
240
|
-
|
241
|
-
/** @public */
|
242
|
-
interface Keymap {
|
243
|
-
[key: string]: Command;
|
244
|
-
}
|
245
|
-
/** @public */
|
246
|
-
declare function addKeymap(keymap: Keymap): Extension;
|
247
|
-
/** @public */
|
248
|
-
declare function addBaseKeymap(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
249
|
-
|
250
|
-
/**
|
251
|
-
* @public
|
252
|
-
*/
|
253
|
-
interface MarkSpecOptions<MarkName extends string = string> extends MarkSpec {
|
254
|
-
name: MarkName;
|
255
|
-
}
|
256
|
-
/**
|
257
|
-
* @public
|
258
|
-
*/
|
259
|
-
declare function addMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>): Extension<{
|
260
|
-
MARKS: Mark;
|
261
|
-
}>;
|
262
|
-
|
263
|
-
/**
|
264
|
-
* @public
|
265
|
-
*/
|
266
|
-
interface NodeSpecOptions<NodeName extends string = string> extends NodeSpec {
|
267
|
-
name: NodeName;
|
268
|
-
topNode?: boolean;
|
269
|
-
}
|
270
|
-
/**
|
271
|
-
* @public
|
272
|
-
*/
|
273
|
-
declare function addNodeSpec<NodeName extends string>(options: NodeSpecOptions<NodeName>): Extension<{
|
274
|
-
NODES: NodeName;
|
275
|
-
}>;
|
276
|
-
|
277
|
-
interface NodeViewOptions {
|
278
|
-
name: string;
|
279
|
-
constructor: NodeViewConstructor;
|
280
|
-
}
|
281
|
-
declare function addNodeView(options: NodeViewOptions): Extension;
|
282
|
-
|
283
|
-
/** @public */
|
284
|
-
declare function addParagraph(): Extension<{
|
285
|
-
NODES: "paragraph";
|
286
|
-
}>;
|
287
|
-
|
288
|
-
interface StateConfigContext {
|
289
|
-
schema: Schema;
|
290
|
-
}
|
291
|
-
type StateConfigCallback = (ctx: StateConfigContext) => EditorStateConfig;
|
292
|
-
type ViewProps = Omit<DirectEditorProps, 'state'>;
|
293
|
-
|
294
|
-
/** @public */
|
295
|
-
interface PluginOptions {
|
296
|
-
plugins: Plugin[] | ((context: {
|
297
|
-
schema: Schema;
|
298
|
-
}) => Plugin[]);
|
299
|
-
}
|
300
|
-
/** @public */
|
301
|
-
declare function addPlugin({ plugins }: PluginOptions): Extension;
|
302
|
-
/** @internal */
|
303
|
-
type PluginFacetInput = (context: {
|
304
|
-
schema: Schema;
|
305
|
-
}) => Plugin[];
|
306
|
-
/** @internal */
|
307
|
-
declare const pluginFacet: Facet<PluginFacetInput, StateConfigCallback>;
|
308
|
-
|
309
|
-
/** @public */
|
310
|
-
declare function addText(): Extension<{
|
311
|
-
NODES: "text";
|
312
|
-
}>;
|
313
|
-
|
314
|
-
/** @internal */
|
315
|
-
declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
|
316
|
-
|
317
|
-
/** @internal */
|
318
|
-
declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
|
319
|
-
|
320
|
-
export { AddMarkOptions, CommandArgs, Editor, EditorOptions, Extension, ExtensionTyping, ExtractCommandCreators, ExtractCommandDispatchers, ExtractMarks, ExtractNodes, Facet, FacetExtension, FacetOptions, Keymap, MarkSpecOptions, NodeSpecOptions, NodeViewOptions, PluginFacetInput, PluginOptions, Priority, ProseKitError, SimplifyExtension, SimplifyUnion, StateConfigCallback, StateConfigContext, ToggleMarkOptions, ToggleNodeOptions, ViewProps, addBaseCommands, addBaseKeymap, addCommands, addDoc, addInputRule, addKeymap, addMark, addMarkSpec, addNodeSpec, addNodeView, addParagraph, addPlugin, addText, createEditor, defineExtension, getMarkType, getNodeType, pluginFacet, toggleMark, toggleNode, withPriority };
|
1
|
+
export { addMark } from './_tsup-dts-rollup';
|
2
|
+
export { AddMarkOptions } from './_tsup-dts-rollup';
|
3
|
+
export { toggleMark } from './_tsup-dts-rollup';
|
4
|
+
export { ToggleMarkOptions } from './_tsup-dts-rollup';
|
5
|
+
export { toggleNode } from './_tsup-dts-rollup';
|
6
|
+
export { ToggleNodeOptions } from './_tsup-dts-rollup';
|
7
|
+
export { Editor } from './_tsup-dts-rollup';
|
8
|
+
export { createEditor } from './_tsup-dts-rollup';
|
9
|
+
export { EditorOptions } from './_tsup-dts-rollup';
|
10
|
+
export { Facet } from './_tsup-dts-rollup';
|
11
|
+
export { FacetExtension } from './_tsup-dts-rollup';
|
12
|
+
export { FacetOptions } from './_tsup-dts-rollup';
|
13
|
+
export { defineExtension } from './_tsup-dts-rollup';
|
14
|
+
export { withPriority } from './_tsup-dts-rollup';
|
15
|
+
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
16
|
+
export { addBaseCommands } from './_tsup-dts-rollup';
|
17
|
+
export { addCommands } from './_tsup-dts-rollup';
|
18
|
+
export { addDefaultState } from './_tsup-dts-rollup';
|
19
|
+
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
20
|
+
export { addDoc } from './_tsup-dts-rollup';
|
21
|
+
export { addInputRule } from './_tsup-dts-rollup';
|
22
|
+
export { addBaseKeymap } from './_tsup-dts-rollup';
|
23
|
+
export { addKeymap } from './_tsup-dts-rollup';
|
24
|
+
export { Keymap } from './_tsup-dts-rollup';
|
25
|
+
export { addMarkSpec } from './_tsup-dts-rollup';
|
26
|
+
export { MarkSpecOptions } from './_tsup-dts-rollup';
|
27
|
+
export { addNodeSpec } from './_tsup-dts-rollup';
|
28
|
+
export { NodeSpecOptions } from './_tsup-dts-rollup';
|
29
|
+
export { addNodeView } from './_tsup-dts-rollup';
|
30
|
+
export { NodeViewOptions } from './_tsup-dts-rollup';
|
31
|
+
export { addParagraph } from './_tsup-dts-rollup';
|
32
|
+
export { addPlugin } from './_tsup-dts-rollup';
|
33
|
+
export { pluginFacet } from './_tsup-dts-rollup';
|
34
|
+
export { PluginFacetInput } from './_tsup-dts-rollup';
|
35
|
+
export { addText } from './_tsup-dts-rollup';
|
36
|
+
export { CommandArgs } from './_tsup-dts-rollup';
|
37
|
+
export { Extension } from './_tsup-dts-rollup';
|
38
|
+
export { ExtractCommandCreators } from './_tsup-dts-rollup';
|
39
|
+
export { ExtractCommandDispatchers } from './_tsup-dts-rollup';
|
40
|
+
export { ExtractMarks } from './_tsup-dts-rollup';
|
41
|
+
export { ExtractNodes } from './_tsup-dts-rollup';
|
42
|
+
export { SimplifyExtension } from './_tsup-dts-rollup';
|
43
|
+
export { ExtensionTyping } from './_tsup-dts-rollup';
|
44
|
+
export { NodeJson } from './_tsup-dts-rollup';
|
45
|
+
export { SelectionJson } from './_tsup-dts-rollup';
|
46
|
+
export { StateJson } from './_tsup-dts-rollup';
|
47
|
+
export { Priority } from './_tsup-dts-rollup';
|
48
|
+
export { SimplifyUnion } from './_tsup-dts-rollup';
|
49
|
+
export { getMarkType } from './_tsup-dts-rollup';
|
50
|
+
export { getNodeType } from './_tsup-dts-rollup';
|
51
|
+
export { StateConfigContext } from './_tsup-dts-rollup';
|
52
|
+
export { StateConfigCallback } from './_tsup-dts-rollup';
|
53
|
+
export { ViewProps } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
// src/commands/
|
2
|
-
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
1
|
+
// src/commands/add-mark.ts
|
3
2
|
import "@prosekit/pm/model";
|
4
3
|
import "@prosekit/pm/state";
|
5
4
|
|
@@ -22,7 +21,25 @@ function getMarkType(schema, type) {
|
|
22
21
|
return type;
|
23
22
|
}
|
24
23
|
|
24
|
+
// src/commands/add-mark.ts
|
25
|
+
function addMark(options) {
|
26
|
+
return (state, dispatch) => {
|
27
|
+
var _a, _b;
|
28
|
+
const mark = getMarkType(state.schema, options.type).create(options.attrs);
|
29
|
+
const from = (_a = options.from) != null ? _a : state.selection.from;
|
30
|
+
const to = (_b = options.to) != null ? _b : state.selection.to;
|
31
|
+
if (from > to) {
|
32
|
+
return false;
|
33
|
+
}
|
34
|
+
dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
|
35
|
+
return true;
|
36
|
+
};
|
37
|
+
}
|
38
|
+
|
25
39
|
// src/commands/toggle-mark.ts
|
40
|
+
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
41
|
+
import "@prosekit/pm/model";
|
42
|
+
import "@prosekit/pm/state";
|
26
43
|
function toggleMark(options) {
|
27
44
|
return (state, dispatch, view) => {
|
28
45
|
return baseToggleMark(
|
@@ -109,23 +126,6 @@ function toggleNode(options) {
|
|
109
126
|
};
|
110
127
|
}
|
111
128
|
|
112
|
-
// src/commands/add-mark.ts
|
113
|
-
import "@prosekit/pm/model";
|
114
|
-
import "@prosekit/pm/state";
|
115
|
-
function addMark(options) {
|
116
|
-
return (state, dispatch) => {
|
117
|
-
var _a, _b;
|
118
|
-
const mark = getMarkType(state.schema, options.type).create(options.attrs);
|
119
|
-
const from = (_a = options.from) != null ? _a : state.selection.from;
|
120
|
-
const to = (_b = options.to) != null ? _b : state.selection.to;
|
121
|
-
if (from > to) {
|
122
|
-
return false;
|
123
|
-
}
|
124
|
-
dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
|
125
|
-
return true;
|
126
|
-
};
|
127
|
-
}
|
128
|
-
|
129
129
|
// src/editor/editor.ts
|
130
130
|
import { Schema as Schema3 } from "@prosekit/pm/model";
|
131
131
|
import { EditorState } from "@prosekit/pm/state";
|
@@ -487,11 +487,20 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
487
487
|
|
488
488
|
// src/editor/editor.ts
|
489
489
|
function createEditor({
|
490
|
-
extension
|
490
|
+
extension,
|
491
|
+
defaultDoc,
|
492
|
+
defaultSelection
|
491
493
|
}) {
|
492
|
-
|
493
|
-
|
494
|
-
|
494
|
+
if (defaultDoc) {
|
495
|
+
extension = defineExtension([
|
496
|
+
extension,
|
497
|
+
addDefaultState({
|
498
|
+
doc: defaultDoc,
|
499
|
+
selection: defaultSelection
|
500
|
+
})
|
501
|
+
]);
|
502
|
+
}
|
503
|
+
return Editor.create(new EditorInstance(extension));
|
495
504
|
}
|
496
505
|
var EditorInstance = class {
|
497
506
|
constructor(extension) {
|
@@ -740,6 +749,23 @@ function addBaseCommands() {
|
|
740
749
|
});
|
741
750
|
}
|
742
751
|
|
752
|
+
// src/extensions/default-state.ts
|
753
|
+
import { Selection } from "@prosekit/pm/state";
|
754
|
+
function addDefaultState(options) {
|
755
|
+
return stateSlot.extension([
|
756
|
+
({ schema }) => {
|
757
|
+
const config = {};
|
758
|
+
if (options.doc) {
|
759
|
+
config.doc = schema.nodeFromJSON(options.doc);
|
760
|
+
if (options.selection) {
|
761
|
+
config.selection = Selection.fromJSON(config.doc, options.selection);
|
762
|
+
}
|
763
|
+
}
|
764
|
+
return config;
|
765
|
+
}
|
766
|
+
]);
|
767
|
+
}
|
768
|
+
|
743
769
|
// src/extensions/node-spec.ts
|
744
770
|
function addNodeSpec(options) {
|
745
771
|
return nodeSpecFacet.extension([options]);
|
@@ -777,15 +803,18 @@ import "@prosekit/pm/state";
|
|
777
803
|
|
778
804
|
// src/extensions/plugin.ts
|
779
805
|
import "@prosekit/pm/model";
|
780
|
-
import "@prosekit/pm/state";
|
781
|
-
function addPlugin(
|
782
|
-
if (
|
783
|
-
return pluginFacet.extension([
|
784
|
-
}
|
785
|
-
|
786
|
-
|
787
|
-
|
806
|
+
import { Plugin as Plugin2 } from "@prosekit/pm/state";
|
807
|
+
function addPlugin(plugin) {
|
808
|
+
if (plugin instanceof Plugin2) {
|
809
|
+
return pluginFacet.extension([() => [plugin]]);
|
810
|
+
}
|
811
|
+
if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin2)) {
|
812
|
+
return pluginFacet.extension([() => plugin]);
|
813
|
+
}
|
814
|
+
if (typeof plugin === "function") {
|
815
|
+
return pluginFacet.extension([plugin]);
|
788
816
|
}
|
817
|
+
throw new TypeError("Invalid plugin");
|
789
818
|
}
|
790
819
|
var pluginFacet = Facet.define({
|
791
820
|
combine: (callbacks) => {
|
@@ -814,7 +843,7 @@ var inputRuleFacet = Facet.define({
|
|
814
843
|
// src/extensions/keymap.ts
|
815
844
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
816
845
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
817
|
-
import { Plugin as
|
846
|
+
import { Plugin as Plugin4, PluginKey } from "@prosekit/pm/state";
|
818
847
|
function addKeymap(keymap) {
|
819
848
|
return keymapFacet.extension([keymap]);
|
820
849
|
}
|
@@ -829,7 +858,7 @@ var keymapFacet = Facet.define({
|
|
829
858
|
return handler(view, event);
|
830
859
|
return false;
|
831
860
|
};
|
832
|
-
const plugin = new
|
861
|
+
const plugin = new Plugin4({
|
833
862
|
key: keymapPluginKey,
|
834
863
|
props: { handleKeyDown: handlerWrapper }
|
835
864
|
});
|
@@ -884,7 +913,7 @@ var markSpecFacet = Facet.define({
|
|
884
913
|
});
|
885
914
|
|
886
915
|
// src/extensions/node-view.ts
|
887
|
-
import { Plugin as
|
916
|
+
import { Plugin as Plugin5 } from "@prosekit/pm/state";
|
888
917
|
import "@prosekit/pm/view";
|
889
918
|
function addNodeView(options) {
|
890
919
|
return nodeViewFacet.extension([options]);
|
@@ -897,7 +926,7 @@ var nodeViewFacet = Facet.define({
|
|
897
926
|
nodeViews[input.name] = input.constructor;
|
898
927
|
}
|
899
928
|
}
|
900
|
-
return () => [new
|
929
|
+
return () => [new Plugin5({ props: { nodeViews } })];
|
901
930
|
},
|
902
931
|
next: pluginFacet
|
903
932
|
});
|
@@ -931,6 +960,7 @@ export {
|
|
931
960
|
addBaseCommands,
|
932
961
|
addBaseKeymap,
|
933
962
|
addCommands,
|
963
|
+
addDefaultState,
|
934
964
|
addDoc,
|
935
965
|
addInputRule,
|
936
966
|
addKeymap,
|
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.8",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -40,13 +40,13 @@
|
|
40
40
|
"dependencies": {
|
41
41
|
"@prosekit/pm": "^0.0.3",
|
42
42
|
"orderedmap": "^2.1.1",
|
43
|
-
"type-fest": "^4.
|
43
|
+
"type-fest": "^4.3.1"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
46
46
|
"@prosekit/dev": "*",
|
47
47
|
"tsup": "^7.2.0",
|
48
|
-
"typescript": "^5.
|
49
|
-
"vitest": "^0.34.
|
48
|
+
"typescript": "^5.2.2",
|
49
|
+
"vitest": "^0.34.3"
|
50
50
|
},
|
51
51
|
"scripts": {
|
52
52
|
"build:tsup": "tsup",
|
package/src/index.ts
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
export { addMark, type AddMarkOptions } from './commands/add-mark'
|
1
2
|
export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
|
2
3
|
export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
|
3
|
-
export { addMark, type AddMarkOptions } from './commands/add-mark'
|
4
4
|
export { Editor, createEditor, type EditorOptions } from './editor/editor'
|
5
5
|
export { Facet, FacetExtension, type FacetOptions } from './editor/facet'
|
6
6
|
export { defineExtension } from './editor/type-utils'
|
7
7
|
export { withPriority } from './editor/with-priority'
|
8
8
|
export { ProseKitError } from './error'
|
9
9
|
export { addBaseCommands, addCommands } from './extensions/command'
|
10
|
+
export {
|
11
|
+
addDefaultState,
|
12
|
+
type DefaultStateOptions,
|
13
|
+
} from './extensions/default-state'
|
10
14
|
export { addDoc } from './extensions/doc'
|
11
15
|
export { addInputRule } from './extensions/input-rules'
|
12
16
|
export { addBaseKeymap, addKeymap, type Keymap } from './extensions/keymap'
|
@@ -16,9 +20,8 @@ export { addNodeView, type NodeViewOptions } from './extensions/node-view'
|
|
16
20
|
export { addParagraph } from './extensions/paragraph'
|
17
21
|
export {
|
18
22
|
addPlugin,
|
19
|
-
type PluginOptions,
|
20
|
-
type PluginFacetInput,
|
21
23
|
pluginFacet,
|
24
|
+
type PluginFacetInput,
|
22
25
|
} from './extensions/plugin'
|
23
26
|
export { addText } from './extensions/text'
|
24
27
|
export { type CommandArgs as CommandArgs } from './types/command'
|
@@ -32,6 +35,7 @@ export {
|
|
32
35
|
type SimplifyExtension,
|
33
36
|
} from './types/extension'
|
34
37
|
export { type ExtensionTyping } from './types/extension-typing'
|
38
|
+
export type { NodeJson, SelectionJson, StateJson } from './types/model'
|
35
39
|
export { Priority } from './types/priority'
|
36
40
|
export { type SimplifyUnion } from './types/simplify-union'
|
37
41
|
export { getMarkType } from './utils/get-mark-type'
|