@prosekit/core 0.0.8 → 0.0.10
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 +45 -0
- package/dist/prosekit-core.d.ts +1 -0
- package/dist/prosekit-core.js +225 -61
- package/package.json +2 -2
- package/src/index.ts +1 -0
@@ -8,6 +8,7 @@ import { EditorView } from '@prosekit/pm/view';
|
|
8
8
|
import type { EmptyObject } from 'type-fest';
|
9
9
|
import { InputRule } from '@prosekit/pm/inputrules';
|
10
10
|
import type { IsEqual } from 'type-fest';
|
11
|
+
import { Mark } from '@prosekit/pm/model';
|
11
12
|
import type { MarkSpec } from '@prosekit/pm/model';
|
12
13
|
import { MarkType } from '@prosekit/pm/model';
|
13
14
|
import type { NodeSpec } from '@prosekit/pm/model';
|
@@ -15,6 +16,7 @@ import { NodeType } from '@prosekit/pm/model';
|
|
15
16
|
import { NodeViewConstructor } from '@prosekit/pm/view';
|
16
17
|
import { Options } from 'tsup';
|
17
18
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
19
|
+
import { ProseMirrorFragment } from '@prosekit/pm/model';
|
18
20
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
19
21
|
import { Schema } from '@prosekit/pm/model';
|
20
22
|
import type { SchemaSpec } from '@prosekit/pm/model';
|
@@ -84,6 +86,15 @@ NODES: "doc";
|
|
84
86
|
export { addDoc }
|
85
87
|
export { addDoc as addDoc_alias_1 }
|
86
88
|
|
89
|
+
/**
|
90
|
+
* @internal
|
91
|
+
*/
|
92
|
+
declare function addEventHandler(options: {
|
93
|
+
update?: VoidFunction;
|
94
|
+
}): FacetExtension<VoidFunction, PluginFacetInput>;
|
95
|
+
export { addEventHandler }
|
96
|
+
export { addEventHandler as addEventHandler_alias_1 }
|
97
|
+
|
87
98
|
/**
|
88
99
|
* @public
|
89
100
|
*/
|
@@ -176,6 +187,8 @@ export declare function applyAction(operator: Action): Command;
|
|
176
187
|
*/
|
177
188
|
export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
|
178
189
|
|
190
|
+
export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
|
191
|
+
|
179
192
|
/** @internal */
|
180
193
|
declare interface CommandArgs {
|
181
194
|
[name: string]: any[];
|
@@ -200,6 +213,10 @@ declare function createEditor<E extends Extension>({ extension, defaultDoc, defa
|
|
200
213
|
export { createEditor }
|
201
214
|
export { createEditor as createEditor_alias_1 }
|
202
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
|
+
|
203
220
|
export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
|
204
221
|
|
205
222
|
export declare const default_alias_1: UserProjectConfigExport;
|
@@ -235,8 +252,16 @@ declare class Editor<E extends Extension = any> {
|
|
235
252
|
mount(place: HTMLElement | null | undefined | void): void;
|
236
253
|
unmount(): void;
|
237
254
|
use(extension: Extension): VoidFunction;
|
255
|
+
/**
|
256
|
+
* @deprecated
|
257
|
+
*/
|
238
258
|
isNodeActive(nodeType: string | NodeType, attrs?: Attrs): boolean;
|
259
|
+
/**
|
260
|
+
* @deprecated
|
261
|
+
*/
|
239
262
|
isMarkActive(markType: string | MarkType, attrs?: Attrs): boolean;
|
263
|
+
get nodes(): Record<ExtractNodes<E>, NodeBuilder>;
|
264
|
+
get marks(): Record<ExtractMarks<E>, MarkBuilder>;
|
240
265
|
}
|
241
266
|
export { Editor }
|
242
267
|
export { Editor as Editor_alias_1 }
|
@@ -396,10 +421,14 @@ export declare function insertNode({ node, pos, }: {
|
|
396
421
|
pos?: number;
|
397
422
|
}): Action;
|
398
423
|
|
424
|
+
export declare function isMark(mark: unknown): mark is Mark;
|
425
|
+
|
399
426
|
export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;
|
400
427
|
|
401
428
|
export declare function isNodeActive(state: EditorState, type: string | NodeType, attrs?: Attrs | null): boolean;
|
402
429
|
|
430
|
+
export declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
|
431
|
+
|
403
432
|
/** @public */
|
404
433
|
declare interface Keymap {
|
405
434
|
[key: string]: Command;
|
@@ -407,6 +436,12 @@ declare interface Keymap {
|
|
407
436
|
export { Keymap }
|
408
437
|
export { Keymap as Keymap_alias_1 }
|
409
438
|
|
439
|
+
export declare interface MarkBuilder {
|
440
|
+
(attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode[];
|
441
|
+
(...children: NodeChild[]): ProseMirrorNode[];
|
442
|
+
isActive(attrs?: Attrs): boolean;
|
443
|
+
}
|
444
|
+
|
410
445
|
/**
|
411
446
|
* @public
|
412
447
|
*/
|
@@ -416,6 +451,16 @@ declare interface MarkSpecOptions<MarkName extends string = string> extends Mark
|
|
416
451
|
export { MarkSpecOptions }
|
417
452
|
export { MarkSpecOptions as MarkSpecOptions_alias_1 }
|
418
453
|
|
454
|
+
export declare interface NodeBuilder {
|
455
|
+
(attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode;
|
456
|
+
(...children: NodeChild[]): ProseMirrorNode;
|
457
|
+
isActive(attrs?: Attrs): boolean;
|
458
|
+
}
|
459
|
+
|
460
|
+
export declare type NodeChild = ProseMirrorNode | string | NodeChild[];
|
461
|
+
|
462
|
+
export declare type NodeContent = ProseMirrorNode | ProseMirrorFragment | NodeContent[];
|
463
|
+
|
419
464
|
/**
|
420
465
|
* A JSON representation of the prosemirror node.
|
421
466
|
*
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -18,6 +18,7 @@ export { addCommands } from './_tsup-dts-rollup';
|
|
18
18
|
export { addDefaultState } from './_tsup-dts-rollup';
|
19
19
|
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
20
20
|
export { addDoc } from './_tsup-dts-rollup';
|
21
|
+
export { addEventHandler } from './_tsup-dts-rollup';
|
21
22
|
export { addInputRule } from './_tsup-dts-rollup';
|
22
23
|
export { addBaseKeymap } from './_tsup-dts-rollup';
|
23
24
|
export { addKeymap } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -127,27 +127,15 @@ function toggleNode(options) {
|
|
127
127
|
}
|
128
128
|
|
129
129
|
// src/editor/editor.ts
|
130
|
-
import { Schema as
|
130
|
+
import { Schema as Schema4 } from "@prosekit/pm/model";
|
131
131
|
import { EditorState } from "@prosekit/pm/state";
|
132
132
|
import { EditorView } from "@prosekit/pm/view";
|
133
133
|
|
134
|
-
// src/
|
135
|
-
|
136
|
-
const markType = getMarkType(state.schema, type);
|
137
|
-
const mark = attrs ? markType.create(attrs) : markType;
|
138
|
-
const { from, to } = state.selection;
|
139
|
-
return state.doc.rangeHasMark(from, to, mark);
|
140
|
-
}
|
134
|
+
// src/extensions/default-state.ts
|
135
|
+
import { Selection } from "@prosekit/pm/state";
|
141
136
|
|
142
|
-
// src/
|
143
|
-
|
144
|
-
Priority2[Priority2["lowest"] = 4] = "lowest";
|
145
|
-
Priority2[Priority2["low"] = 3] = "low";
|
146
|
-
Priority2[Priority2["default"] = 2] = "default";
|
147
|
-
Priority2[Priority2["high"] = 1] = "high";
|
148
|
-
Priority2[Priority2["highest"] = 0] = "highest";
|
149
|
-
return Priority2;
|
150
|
-
})(Priority || {});
|
137
|
+
// src/editor/slots.ts
|
138
|
+
import OrderedMap from "orderedmap";
|
151
139
|
|
152
140
|
// src/utils/uniq-array.ts
|
153
141
|
function uniqPush(prev, next) {
|
@@ -257,13 +245,12 @@ function sortFacets(unsorted) {
|
|
257
245
|
}
|
258
246
|
}
|
259
247
|
if (facetCount !== sortedFacets.length) {
|
260
|
-
throw new
|
248
|
+
throw new ProseKitError(`Facet has circular dependency`);
|
261
249
|
}
|
262
250
|
return sortedFacets;
|
263
251
|
}
|
264
252
|
|
265
253
|
// src/editor/slots.ts
|
266
|
-
import OrderedMap from "orderedmap";
|
267
254
|
var schemaSlot = Facet.defineSlot({
|
268
255
|
combine: (specs) => {
|
269
256
|
var _a;
|
@@ -296,7 +283,9 @@ var stateSlot = Facet.defineSlot({
|
|
296
283
|
config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
|
297
284
|
}
|
298
285
|
if (!config.doc && !config.schema) {
|
299
|
-
throw new
|
286
|
+
throw new ProseKitError(
|
287
|
+
"Can't create state without a schema nor a document"
|
288
|
+
);
|
300
289
|
}
|
301
290
|
if (config.doc) {
|
302
291
|
config.schema = void 0;
|
@@ -316,6 +305,128 @@ var commandSlot = Facet.defineSlot({
|
|
316
305
|
}
|
317
306
|
});
|
318
307
|
|
308
|
+
// src/extensions/default-state.ts
|
309
|
+
function addDefaultState(options) {
|
310
|
+
return stateSlot.extension([
|
311
|
+
({ schema }) => {
|
312
|
+
const config = {};
|
313
|
+
if (options.doc) {
|
314
|
+
config.doc = schema.nodeFromJSON(options.doc);
|
315
|
+
if (options.selection) {
|
316
|
+
config.selection = Selection.fromJSON(config.doc, options.selection);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
return config;
|
320
|
+
}
|
321
|
+
]);
|
322
|
+
}
|
323
|
+
|
324
|
+
// src/utils/type-assertion.ts
|
325
|
+
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
326
|
+
function isProseMirrorNode(node) {
|
327
|
+
return node instanceof ProseMirrorNode;
|
328
|
+
}
|
329
|
+
function isMark(mark) {
|
330
|
+
return mark instanceof Mark;
|
331
|
+
}
|
332
|
+
|
333
|
+
// src/utils/is-mark-active.ts
|
334
|
+
function isMarkActive(state, type, attrs) {
|
335
|
+
var _a;
|
336
|
+
const markType = getMarkType(state.schema, type);
|
337
|
+
const mark = attrs ? markType.create(attrs) : markType;
|
338
|
+
const { from, to, $from, $to } = state.selection;
|
339
|
+
return state.doc.rangeHasMark(from, to, mark) || hasMark(
|
340
|
+
[...$from.marks(), ...$to.marks(), ...(_a = state.storedMarks) != null ? _a : []],
|
341
|
+
mark
|
342
|
+
);
|
343
|
+
}
|
344
|
+
function hasMark(marks, mark) {
|
345
|
+
if (marks.length === 0) {
|
346
|
+
return false;
|
347
|
+
}
|
348
|
+
if (isMark(mark)) {
|
349
|
+
return marks.some((m) => m.eq(mark));
|
350
|
+
} else {
|
351
|
+
return marks.some((m) => m.type === mark);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
// src/editor/builder.ts
|
356
|
+
import "@prosekit/pm/model";
|
357
|
+
function createNodeBuilder(getState, type) {
|
358
|
+
const builder = (...args) => buildNode(type, args);
|
359
|
+
builder.isActive = (attrs) => {
|
360
|
+
const state = getState();
|
361
|
+
return state ? isNodeActive(state, type, attrs) : false;
|
362
|
+
};
|
363
|
+
return builder;
|
364
|
+
}
|
365
|
+
function createMarkBuilder(getState, type) {
|
366
|
+
const builder = (...args) => buildMark(type, args);
|
367
|
+
builder.isActive = (attrs) => {
|
368
|
+
const state = getState();
|
369
|
+
return state ? isMarkActive(state, type, attrs) : false;
|
370
|
+
};
|
371
|
+
return builder;
|
372
|
+
}
|
373
|
+
function buildMark(type, args) {
|
374
|
+
const [attrs, children] = normalizeArgs(args);
|
375
|
+
return flattenChildren(type.schema, children, type.create(attrs));
|
376
|
+
}
|
377
|
+
function buildNode(type, args) {
|
378
|
+
const [attrs, children] = normalizeArgs(args);
|
379
|
+
const node = type.createAndFill(attrs, flattenChildren(type.schema, children));
|
380
|
+
if (!node) {
|
381
|
+
throw new ProseKitError(`Couldn't create node ${type.name}`);
|
382
|
+
}
|
383
|
+
return node;
|
384
|
+
}
|
385
|
+
function flattenChildren(schema, children, mark) {
|
386
|
+
const nodes = [];
|
387
|
+
for (const child of children) {
|
388
|
+
if (typeof child === "string") {
|
389
|
+
if (child) {
|
390
|
+
nodes.push(schema.text(child, mark ? [mark] : null));
|
391
|
+
}
|
392
|
+
} else if (Array.isArray(child)) {
|
393
|
+
nodes.push(...flattenChildren(schema, child, mark));
|
394
|
+
} else if (isProseMirrorNode(child)) {
|
395
|
+
nodes.push(mark ? child.mark(mark.addToSet(child.marks)) : child);
|
396
|
+
} else {
|
397
|
+
throw new ProseKitError(`Invalid node child: ${typeof child}`);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
return nodes;
|
401
|
+
}
|
402
|
+
function normalizeArgs(args) {
|
403
|
+
const [attrs, ...children] = args;
|
404
|
+
if (isNodeChild(args)) {
|
405
|
+
children.unshift(args);
|
406
|
+
return [null, children];
|
407
|
+
} else if (typeof attrs === "object") {
|
408
|
+
return [attrs, children];
|
409
|
+
} else {
|
410
|
+
return [null, children];
|
411
|
+
}
|
412
|
+
}
|
413
|
+
function isNodeChild(value) {
|
414
|
+
if (!value) {
|
415
|
+
return false;
|
416
|
+
}
|
417
|
+
return typeof value === "string" || Array.isArray(value) || isProseMirrorNode(value);
|
418
|
+
}
|
419
|
+
|
420
|
+
// src/types/priority.ts
|
421
|
+
var Priority = /* @__PURE__ */ ((Priority2) => {
|
422
|
+
Priority2[Priority2["lowest"] = 4] = "lowest";
|
423
|
+
Priority2[Priority2["low"] = 3] = "low";
|
424
|
+
Priority2[Priority2["default"] = 2] = "default";
|
425
|
+
Priority2[Priority2["high"] = 1] = "high";
|
426
|
+
Priority2[Priority2["highest"] = 0] = "highest";
|
427
|
+
return Priority2;
|
428
|
+
})(Priority || {});
|
429
|
+
|
319
430
|
// src/editor/flatten.ts
|
320
431
|
function flattenInputTuple(inputTuple) {
|
321
432
|
return [
|
@@ -385,7 +496,7 @@ function extractFacets(root) {
|
|
385
496
|
priorities.push(p);
|
386
497
|
}
|
387
498
|
} else {
|
388
|
-
throw new
|
499
|
+
throw new ProseKitError("Invalid extension");
|
389
500
|
}
|
390
501
|
}
|
391
502
|
return [facets, inputs];
|
@@ -477,7 +588,7 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
477
588
|
commandInput = output;
|
478
589
|
break;
|
479
590
|
default:
|
480
|
-
throw new
|
591
|
+
throw new ProseKitError("Invalid facet");
|
481
592
|
}
|
482
593
|
}
|
483
594
|
}
|
@@ -485,6 +596,14 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
485
596
|
return { schemaInput, stateInput, viewInput, commandInput };
|
486
597
|
}
|
487
598
|
|
599
|
+
// src/editor/type-utils.ts
|
600
|
+
function defineExtension(extension) {
|
601
|
+
if (extension && Array.isArray(extension)) {
|
602
|
+
return { extension };
|
603
|
+
}
|
604
|
+
return extension;
|
605
|
+
}
|
606
|
+
|
488
607
|
// src/editor/editor.ts
|
489
608
|
function createEditor({
|
490
609
|
extension,
|
@@ -512,9 +631,9 @@ var EditorInstance = class {
|
|
512
631
|
this.unmount = this.unmount.bind(this);
|
513
632
|
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.inputs, this.slots, extension, "add");
|
514
633
|
if (!schemaInput) {
|
515
|
-
throw new
|
634
|
+
throw new ProseKitError("Schema must be defined");
|
516
635
|
}
|
517
|
-
const schema = new
|
636
|
+
const schema = new Schema4(schemaInput);
|
518
637
|
const stateConfig = stateInput ? stateInput({ schema }) : { schema };
|
519
638
|
const state = EditorState.create(stateConfig);
|
520
639
|
if (commandInput) {
|
@@ -524,6 +643,22 @@ var EditorInstance = class {
|
|
524
643
|
}
|
525
644
|
this.directEditorProps = { state, ...viewInput };
|
526
645
|
this.schema = this.directEditorProps.state.schema;
|
646
|
+
const getState = () => {
|
647
|
+
var _a;
|
648
|
+
return (_a = this.view) == null ? void 0 : _a.state;
|
649
|
+
};
|
650
|
+
this.nodeBuilders = Object.fromEntries(
|
651
|
+
Object.values(this.schema.nodes).map((type) => [
|
652
|
+
type.name,
|
653
|
+
createNodeBuilder(getState, type)
|
654
|
+
])
|
655
|
+
);
|
656
|
+
this.markBuilders = Object.fromEntries(
|
657
|
+
Object.values(this.schema.marks).map((type) => [
|
658
|
+
type.name,
|
659
|
+
createMarkBuilder(getState, type)
|
660
|
+
])
|
661
|
+
);
|
527
662
|
}
|
528
663
|
updateExtension(extension, mode) {
|
529
664
|
var _a;
|
@@ -553,23 +688,23 @@ var EditorInstance = class {
|
|
553
688
|
}
|
554
689
|
mount(place) {
|
555
690
|
if (this.view) {
|
556
|
-
throw new
|
691
|
+
throw new ProseKitError("Editor is already mounted");
|
557
692
|
}
|
558
693
|
if (!place) {
|
559
|
-
throw new
|
694
|
+
throw new ProseKitError("Can't mount editor without a place");
|
560
695
|
}
|
561
696
|
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
562
697
|
}
|
563
698
|
unmount() {
|
564
699
|
if (!this.view) {
|
565
|
-
throw new
|
700
|
+
throw new ProseKitError("Editor is not mounted yet");
|
566
701
|
}
|
567
702
|
this.view.destroy();
|
568
703
|
this.view = null;
|
569
704
|
}
|
570
705
|
get assertView() {
|
571
706
|
if (!this.view)
|
572
|
-
throw new
|
707
|
+
throw new ProseKitError("Editor is not mounted");
|
573
708
|
return this.view;
|
574
709
|
}
|
575
710
|
addPlugins(plugins) {
|
@@ -653,21 +788,25 @@ var Editor = class _Editor {
|
|
653
788
|
this.instance.updateExtension(extension, "add");
|
654
789
|
return () => this.instance.updateExtension(extension, "remove");
|
655
790
|
}
|
791
|
+
/**
|
792
|
+
* @deprecated
|
793
|
+
*/
|
656
794
|
isNodeActive(nodeType, attrs) {
|
657
795
|
return isNodeActive(this.view.state, nodeType, attrs);
|
658
796
|
}
|
797
|
+
/**
|
798
|
+
* @deprecated
|
799
|
+
*/
|
659
800
|
isMarkActive(markType, attrs) {
|
660
801
|
return isMarkActive(this.view.state, markType, attrs);
|
661
802
|
}
|
662
|
-
|
663
|
-
|
664
|
-
// src/editor/type-utils.ts
|
665
|
-
function defineExtension(extension) {
|
666
|
-
if (extension && Array.isArray(extension)) {
|
667
|
-
return { extension };
|
803
|
+
get nodes() {
|
804
|
+
return this.instance.nodeBuilders;
|
668
805
|
}
|
669
|
-
|
670
|
-
|
806
|
+
get marks() {
|
807
|
+
return this.instance.markBuilders;
|
808
|
+
}
|
809
|
+
};
|
671
810
|
|
672
811
|
// src/editor/with-priority.ts
|
673
812
|
function withPriority(extension, priority) {
|
@@ -749,23 +888,6 @@ function addBaseCommands() {
|
|
749
888
|
});
|
750
889
|
}
|
751
890
|
|
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
|
-
|
769
891
|
// src/extensions/node-spec.ts
|
770
892
|
function addNodeSpec(options) {
|
771
893
|
return nodeSpecFacet.extension([options]);
|
@@ -776,7 +898,7 @@ var nodeSpecFacet = Facet.define({
|
|
776
898
|
let topNodeName = void 0;
|
777
899
|
for (const { name, topNode, ...spec } of options) {
|
778
900
|
if (nodes[name]) {
|
779
|
-
throw new
|
901
|
+
throw new ProseKitError(`Node type ${name} has already been defined`);
|
780
902
|
}
|
781
903
|
if (topNodeName && !topNode) {
|
782
904
|
topNodeName = name;
|
@@ -796,10 +918,12 @@ function addDoc() {
|
|
796
918
|
});
|
797
919
|
}
|
798
920
|
|
799
|
-
// src/extensions/
|
800
|
-
import {
|
801
|
-
|
802
|
-
|
921
|
+
// src/extensions/event-handler.ts
|
922
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
923
|
+
|
924
|
+
// src/types/void-function.ts
|
925
|
+
function voidFunction() {
|
926
|
+
}
|
803
927
|
|
804
928
|
// src/extensions/plugin.ts
|
805
929
|
import "@prosekit/pm/model";
|
@@ -826,7 +950,46 @@ var pluginFacet = Facet.define({
|
|
826
950
|
next: stateSlot
|
827
951
|
});
|
828
952
|
|
953
|
+
// src/extensions/event-handler.ts
|
954
|
+
function addEventHandler(options) {
|
955
|
+
var _a;
|
956
|
+
const updateHandler = (_a = options == null ? void 0 : options.update) != null ? _a : voidFunction;
|
957
|
+
return eventFacet.extension([updateHandler]);
|
958
|
+
}
|
959
|
+
var eventFacet = Facet.define({
|
960
|
+
slot: () => {
|
961
|
+
let updateHandlers = [];
|
962
|
+
const plugin = new ProseMirrorPlugin({
|
963
|
+
key: pluginKey,
|
964
|
+
view: () => {
|
965
|
+
return {
|
966
|
+
update: (_view, _prevState) => {
|
967
|
+
updateHandlers.forEach((fn) => fn());
|
968
|
+
}
|
969
|
+
};
|
970
|
+
}
|
971
|
+
});
|
972
|
+
const pluginFunc = () => [plugin];
|
973
|
+
return {
|
974
|
+
create: (handlers) => {
|
975
|
+
updateHandlers = handlers;
|
976
|
+
return pluginFunc;
|
977
|
+
},
|
978
|
+
update: (handlers) => {
|
979
|
+
updateHandlers = handlers;
|
980
|
+
return null;
|
981
|
+
}
|
982
|
+
};
|
983
|
+
},
|
984
|
+
next: pluginFacet,
|
985
|
+
single: true
|
986
|
+
});
|
987
|
+
var pluginKey = new PluginKey("prosekit-event-handler");
|
988
|
+
|
829
989
|
// src/extensions/input-rules.ts
|
990
|
+
import { inputRules } from "@prosekit/pm/inputrules";
|
991
|
+
import "@prosekit/pm/model";
|
992
|
+
import "@prosekit/pm/state";
|
830
993
|
function addInputRule(rules) {
|
831
994
|
return inputRuleFacet.extension([rules]);
|
832
995
|
}
|
@@ -843,7 +1006,7 @@ var inputRuleFacet = Facet.define({
|
|
843
1006
|
// src/extensions/keymap.ts
|
844
1007
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
845
1008
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
846
|
-
import { Plugin as Plugin4, PluginKey } from "@prosekit/pm/state";
|
1009
|
+
import { Plugin as Plugin4, PluginKey as PluginKey2 } from "@prosekit/pm/state";
|
847
1010
|
function addKeymap(keymap) {
|
848
1011
|
return keymapFacet.extension([keymap]);
|
849
1012
|
}
|
@@ -892,7 +1055,7 @@ function mergeKeymaps(keymaps) {
|
|
892
1055
|
])
|
893
1056
|
);
|
894
1057
|
}
|
895
|
-
var keymapPluginKey = new
|
1058
|
+
var keymapPluginKey = new PluginKey2("prosekit-keymap");
|
896
1059
|
|
897
1060
|
// src/extensions/mark-spec.ts
|
898
1061
|
function addMarkSpec(options) {
|
@@ -903,7 +1066,7 @@ var markSpecFacet = Facet.define({
|
|
903
1066
|
const marks = {};
|
904
1067
|
for (const { name, ...spec } of options) {
|
905
1068
|
if (marks[name]) {
|
906
|
-
throw new
|
1069
|
+
throw new ProseKitError(`Mark type ${name} has already been defined`);
|
907
1070
|
}
|
908
1071
|
marks[name] = spec;
|
909
1072
|
}
|
@@ -962,6 +1125,7 @@ export {
|
|
962
1125
|
addCommands,
|
963
1126
|
addDefaultState,
|
964
1127
|
addDoc,
|
1128
|
+
addEventHandler,
|
965
1129
|
addInputRule,
|
966
1130
|
addKeymap,
|
967
1131
|
addMark,
|
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.10",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -38,7 +38,7 @@
|
|
38
38
|
"dist"
|
39
39
|
],
|
40
40
|
"dependencies": {
|
41
|
-
"@prosekit/pm": "^0.0.
|
41
|
+
"@prosekit/pm": "^0.0.5",
|
42
42
|
"orderedmap": "^2.1.1",
|
43
43
|
"type-fest": "^4.3.1"
|
44
44
|
},
|
package/src/index.ts
CHANGED
@@ -12,6 +12,7 @@ export {
|
|
12
12
|
type DefaultStateOptions,
|
13
13
|
} from './extensions/default-state'
|
14
14
|
export { addDoc } from './extensions/doc'
|
15
|
+
export { addEventHandler } from './extensions/event-handler'
|
15
16
|
export { addInputRule } from './extensions/input-rules'
|
16
17
|
export { addBaseKeymap, addKeymap, type Keymap } from './extensions/keymap'
|
17
18
|
export { addMarkSpec, type MarkSpecOptions } from './extensions/mark-spec'
|