@prosekit/core 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { AllSelection } from '@prosekit/pm/state';
1
2
  import { Attrs } from '@prosekit/pm/model';
2
3
  import { Attrs as Attrs_2 } from 'prosemirror-model';
3
4
  import { Command } from '@prosekit/pm/state';
@@ -14,6 +15,7 @@ import type { MarkSpec } from '@prosekit/pm/model';
14
15
  import { MarkType } from '@prosekit/pm/model';
15
16
  import { MarkType as MarkType_2 } from 'prosemirror-model';
16
17
  import { Node as Node_2 } from 'prosemirror-model';
18
+ import { NodeSelection } from '@prosekit/pm/state';
17
19
  import type { NodeSpec } from '@prosekit/pm/model';
18
20
  import { NodeType } from '@prosekit/pm/model';
19
21
  import { NodeType as NodeType_2 } from 'prosemirror-model';
@@ -24,8 +26,10 @@ import { ProseMirrorFragment } from '@prosekit/pm/model';
24
26
  import { ProseMirrorNode } from '@prosekit/pm/model';
25
27
  import { Schema } from '@prosekit/pm/model';
26
28
  import type { SchemaSpec } from '@prosekit/pm/model';
27
- import { Selection as Selection_2 } from 'prosemirror-state';
29
+ import { Selection as Selection_2 } from '@prosekit/pm/state';
30
+ import { Selection as Selection_3 } from 'prosemirror-state';
28
31
  import type { Simplify } from 'type-fest';
32
+ import { TextSelection } from '@prosekit/pm/state';
29
33
  import { Transaction } from '@prosekit/pm/state';
30
34
  import type { UnionToIntersection } from 'type-fest';
31
35
  import { UserProjectConfigExport } from 'vitest/dist/config.js';
@@ -140,17 +144,17 @@ declare interface DefaultStateOptions {
140
144
  * A JSON object representing the starting document to use when creating the
141
145
  * editor.
142
146
  */
143
- defaultDoc?: NodeJson;
147
+ defaultDoc?: NodeJSON;
144
148
  /**
145
- * A HTML string representing the starting document to use when creating the
146
- * editor.
149
+ * A HTML element or a HTML string representing the starting document to use
150
+ * when creating the editor.
147
151
  */
148
- defaultHTML?: string;
152
+ defaultHTML?: string | HTMLElement;
149
153
  /**
150
154
  * A JSON object representing the starting selection to use when creating the
151
155
  * editor. It's only used when `defaultDoc` or `defaultHTML` is also provided.
152
156
  */
153
- defaultSelection?: SelectionJson;
157
+ defaultSelection?: SelectionJSON;
154
158
  }
155
159
  export { DefaultStateOptions }
156
160
  export { DefaultStateOptions as DefaultStateOptions_alias_1 }
@@ -227,15 +231,6 @@ NODES: "doc";
227
231
  export { defineDoc }
228
232
  export { defineDoc as defineDoc_alias_1 }
229
233
 
230
- /**
231
- * @internal
232
- */
233
- declare function defineEventHandler(options: {
234
- update?: VoidFunction;
235
- }): Extension<ExtensionTyping<string, string, CommandArgs>>;
236
- export { defineEventHandler }
237
- export { defineEventHandler as defineEventHandler_alias_1 }
238
-
239
234
  /**
240
235
  * Add undo/redo history to the editor.
241
236
  */
@@ -249,11 +244,16 @@ export { defineHistory }
249
244
  export { defineHistory as defineHistory_alias_1 }
250
245
 
251
246
  /**
247
+ * Defines an input rule extension.
248
+ *
249
+ * @param rule - The ProseMirror input rule to add, or an array of input rules,
250
+ * or a function that returns one or multiple input rules.
251
+ *
252
252
  * @public
253
253
  */
254
- declare function defineInputRule(rules: (context: {
254
+ declare function defineInputRule(rule: InputRule | InputRule[] | ((context: {
255
255
  schema: Schema;
256
- }) => InputRule[]): Extension;
256
+ }) => InputRule | InputRule[])): Extension;
257
257
  export { defineInputRule }
258
258
  export { defineInputRule as defineInputRule_alias_1 }
259
259
 
@@ -314,13 +314,13 @@ NODES: "paragraph";
314
314
  * Adds a ProseMirror plugin to the editor.
315
315
  *
316
316
  * @param plugin - The ProseMirror plugin to add, or an array of plugins, or a
317
- * function that returns an array of plugins.
317
+ * function that returns one or multiple plugins.
318
318
  *
319
319
  * @public
320
320
  */
321
321
  declare function definePlugin(plugin: Plugin_2 | Plugin_2[] | ((context: {
322
322
  schema: Schema;
323
- }) => Plugin_2[])): Extension;
323
+ }) => Plugin_2 | Plugin_2[])): Extension;
324
324
  export { definePlugin }
325
325
  export { definePlugin as definePlugin_alias_1 }
326
326
 
@@ -333,6 +333,13 @@ NODES: "text";
333
333
  export { defineText }
334
334
  export { defineText as defineText_alias_1 }
335
335
 
336
+ /**
337
+ * @internal
338
+ */
339
+ declare function defineUpdateHandler(handler: UpdateHandler): Extension<ExtensionTyping<string, string, CommandArgs>>;
340
+ export { defineUpdateHandler }
341
+ export { defineUpdateHandler as defineUpdateHandler_alias_1 }
342
+
336
343
  /**
337
344
  * @public
338
345
  */
@@ -377,34 +384,27 @@ declare interface EditorOptions<E extends Extension> {
377
384
  * A JSON object representing the starting document to use when creating the
378
385
  * editor.
379
386
  */
380
- defaultDoc?: NodeJson;
387
+ defaultDoc?: NodeJSON;
381
388
  /**
382
- * A HTML string representing the starting document to use when creating the
383
- * editor.
389
+ * A HTML element or a HTML string representing the starting document to use
390
+ * when creating the editor.
384
391
  */
385
- defaultHTML?: string;
392
+ defaultHTML?: string | HTMLElement;
386
393
  /**
387
394
  * A JSON object representing the starting selection to use when creating the
388
395
  * editor. It's only used when `defaultDoc` or `defaultHTML` is also provided.
389
396
  */
390
- defaultSelection?: SelectionJson;
397
+ defaultSelection?: SelectionJSON;
391
398
  }
392
399
  export { EditorOptions }
393
400
  export { EditorOptions as EditorOptions_alias_1 }
394
401
 
395
402
  /**
396
- * Parse a HTML element to a ProseMirror document JSON.
397
- */
398
- declare function elementToJSON(element: HTMLElement, schema: Schema): NodeJson;
399
- export { elementToJSON }
400
- export { elementToJSON as elementToJSON_alias_1 }
401
-
402
- /**
403
- * Parse a HTML element to a ProseMirror node.
403
+ * Parse a HTML string to a HTML element.
404
+ *
405
+ * @internal
404
406
  */
405
- declare function elementToNode(element: HTMLElement, schema: Schema): ProseMirrorNode;
406
- export { elementToNode }
407
- export { elementToNode as elementToNode_alias_1 }
407
+ export declare function elementFromHTML(html: string): HTMLElement;
408
408
 
409
409
  declare type EmptyValue = undefined | null | EmptyObject;
410
410
 
@@ -558,7 +558,7 @@ export declare function getBrowserDocument(): Document | undefined;
558
558
 
559
559
  export declare function getBrowserWindow(): (Window & typeof globalThis) | null | undefined;
560
560
 
561
- export declare function getCustomSelection(state: EditorState, from?: number | null, to?: number | null): Selection_2;
561
+ export declare function getCustomSelection(state: EditorState, from?: number | null, to?: number | null): Selection_3;
562
562
 
563
563
  export declare function getFacetCount(): number;
564
564
 
@@ -576,20 +576,6 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
576
576
  export { getNodeType }
577
577
  export { getNodeType as getNodeType_alias_1 }
578
578
 
579
- /**
580
- * Parse a HTML element to a ProseMirror document JSON.
581
- */
582
- declare function htmlToJSON(html: string, schema: Schema): NodeJson;
583
- export { htmlToJSON }
584
- export { htmlToJSON as htmlToJSON_alias_1 }
585
-
586
- /**
587
- * Parse a HTML string to a ProseMirror node.
588
- */
589
- declare function htmlToNode(html: string, schema: Schema): ProseMirrorNode;
590
- export { htmlToNode }
591
- export { htmlToNode as htmlToNode_alias_1 }
592
-
593
579
  declare function insertNode(options: {
594
580
  node: ProseMirrorNode;
595
581
  pos?: number;
@@ -614,15 +600,84 @@ export declare function insertText({ text, from, to, }: {
614
600
  to?: number;
615
601
  }): Command;
616
602
 
603
+ /**
604
+ * @internal
605
+ */
606
+ declare function isAllSelection(sel: Selection_2): sel is AllSelection;
607
+ export { isAllSelection }
608
+ export { isAllSelection as isAllSelection_alias_1 }
609
+
617
610
  export declare const isMac: boolean;
618
611
 
619
- export declare function isMark(mark: unknown): mark is Mark;
612
+ /**
613
+ * @internal
614
+ */
615
+ declare function isMark(mark: unknown): mark is Mark;
616
+ export { isMark }
617
+ export { isMark as isMark_alias_1 }
620
618
 
621
619
  export declare function isMarkActive(state: EditorState, type: string | MarkType, attrs?: Attrs | null): boolean;
622
620
 
623
621
  export declare function isNodeActive(state: EditorState, type: string | NodeType, attrs?: Attrs | null): boolean;
624
622
 
625
- export declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
623
+ /**
624
+ * @internal
625
+ */
626
+ declare function isNodeSelection(sel: Selection_2): sel is NodeSelection;
627
+ export { isNodeSelection }
628
+ export { isNodeSelection as isNodeSelection_alias_1 }
629
+
630
+ export declare function isNotNull<T>(value: T | null | undefined): value is T;
631
+
632
+ /**
633
+ * @internal
634
+ */
635
+ declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
636
+ export { isProseMirrorNode }
637
+ export { isProseMirrorNode as isProseMirrorNode_alias_1 }
638
+
639
+ /**
640
+ * @internal
641
+ */
642
+ declare function isTextSelection(sel: Selection_2): sel is TextSelection;
643
+ export { isTextSelection }
644
+ export { isTextSelection as isTextSelection_alias_1 }
645
+
646
+ /**
647
+ * Parse a HTML element to a ProseMirror document JSON.
648
+ *
649
+ * @public
650
+ */
651
+ declare function jsonFromElement(element: HTMLElement, schema: Schema): NodeJSON;
652
+ export { jsonFromElement }
653
+ export { jsonFromElement as jsonFromElement_alias_1 }
654
+
655
+ /**
656
+ * Parse a HTML string to a ProseMirror document JSON.
657
+ *
658
+ * @public
659
+ */
660
+ declare function jsonFromHTML(html: string, schema: Schema): NodeJSON;
661
+ export { jsonFromHTML }
662
+ export { jsonFromHTML as jsonFromHTML_alias_1 }
663
+
664
+ /**
665
+ * Return a JSON object representing this node.
666
+ *
667
+ * @public
668
+ */
669
+ declare function jsonFromNode(node: ProseMirrorNode): NodeJSON;
670
+ export { jsonFromNode }
671
+ export { jsonFromNode as jsonFromNode_alias_1 }
672
+
673
+ /**
674
+ * Return a JSON object representing this state.
675
+ *
676
+ * @public
677
+ */
678
+ declare function jsonFromState(state: EditorState): StateJSON;
679
+ export { jsonFromState }
680
+ export { jsonFromState as jsonFromState_alias_1 }
626
681
 
627
682
  /**
628
683
  * @public
@@ -658,20 +713,38 @@ export declare type NodeChild = ProseMirrorNode | string | NodeChild[];
658
713
 
659
714
  export declare type NodeContent = ProseMirrorNode | ProseMirrorFragment | NodeContent[];
660
715
 
716
+ /**
717
+ * Parse a HTML element to a ProseMirror node.
718
+ *
719
+ * @public
720
+ */
721
+ declare function nodeFromElement(element: HTMLElement, schema: Schema): ProseMirrorNode;
722
+ export { nodeFromElement }
723
+ export { nodeFromElement as nodeFromElement_alias_1 }
724
+
725
+ /**
726
+ * Parse a HTML string to a ProseMirror node.
727
+ *
728
+ * @public
729
+ */
730
+ declare function nodeFromHTML(html: string, schema: Schema): ProseMirrorNode;
731
+ export { nodeFromHTML }
732
+ export { nodeFromHTML as nodeFromHTML_alias_1 }
733
+
661
734
  /**
662
735
  * A JSON representation of the prosemirror node.
663
736
  *
664
737
  * @public
665
738
  */
666
- declare interface NodeJson {
739
+ declare interface NodeJSON {
667
740
  type: string;
668
741
  marks?: Array<any>;
669
742
  text?: string;
670
- content?: NodeJson[];
743
+ content?: NodeJSON[];
671
744
  attrs?: Record<string, any>;
672
745
  }
673
- export { NodeJson }
674
- export { NodeJson as NodeJson_alias_1 }
746
+ export { NodeJSON }
747
+ export { NodeJSON as NodeJSON_alias_1 }
675
748
 
676
749
  /**
677
750
  * @public
@@ -702,8 +775,6 @@ declare interface NodeViewOptions {
702
775
  export { NodeViewOptions }
703
776
  export { NodeViewOptions as NodeViewOptions_alias_1 }
704
777
 
705
- export declare function notNull<T>(value: T | null | undefined): value is T;
706
-
707
778
  export declare function objectEqual<T>(a: T, b: T): boolean;
708
779
 
709
780
  declare type Payload = unknown;
@@ -724,7 +795,7 @@ export { pluginFacet as pluginFacet_alias_1 }
724
795
  */
725
796
  declare type PluginPayload = (context: {
726
797
  schema: Schema;
727
- }) => Plugin_2[];
798
+ }) => Plugin_2 | Plugin_2[];
728
799
  export { PluginPayload }
729
800
  export { PluginPayload as PluginPayload_alias_1 }
730
801
 
@@ -784,13 +855,13 @@ export declare function selectAll(): Command;
784
855
  *
785
856
  * @public
786
857
  */
787
- declare interface SelectionJson {
788
- from: number;
789
- to: number;
858
+ declare interface SelectionJSON {
859
+ anchor: number;
860
+ head: number;
790
861
  type: string;
791
862
  }
792
- export { SelectionJson }
793
- export { SelectionJson as SelectionJson_alias_1 }
863
+ export { SelectionJSON }
864
+ export { SelectionJSON as SelectionJSON_alias_1 }
794
865
 
795
866
  /**
796
867
  * Returns a command that tries to set the selected textblocks to the given node
@@ -830,18 +901,18 @@ export declare const stateFacet: Facet<StatePayload, StatePayload>;
830
901
  *
831
902
  * @public
832
903
  */
833
- declare interface StateJson {
904
+ declare interface StateJSON {
834
905
  /**
835
906
  * The main `ProseMirror` doc.
836
907
  */
837
- doc: NodeJson;
908
+ doc: NodeJSON;
838
909
  /**
839
910
  * The current selection.
840
911
  */
841
- selection: SelectionJson;
912
+ selection: SelectionJSON;
842
913
  }
843
- export { StateJson }
844
- export { StateJson as StateJson_alias_1 }
914
+ export { StateJSON }
915
+ export { StateJSON as StateJSON_alias_1 }
845
916
 
846
917
  export declare type StatePayload = (ctx: {
847
918
  schema: Schema;
@@ -899,6 +970,11 @@ export declare function updateExtension(prevInputs: Payloads, prevConverters: Co
899
970
  commandInput: CommandCreators | null;
900
971
  };
901
972
 
973
+ export declare type UpdateHandler = (options: {
974
+ view: EditorView;
975
+ prevState: EditorState;
976
+ }) => void;
977
+
902
978
  export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
903
979
 
904
980
  export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
@@ -15,7 +15,6 @@ export { defineCommands } from './_tsup-dts-rollup';
15
15
  export { defineDefaultState } from './_tsup-dts-rollup';
16
16
  export { DefaultStateOptions } from './_tsup-dts-rollup';
17
17
  export { defineDoc } from './_tsup-dts-rollup';
18
- export { defineEventHandler } from './_tsup-dts-rollup';
19
18
  export { defineHistory } from './_tsup-dts-rollup';
20
19
  export { defineInputRule } from './_tsup-dts-rollup';
21
20
  export { defineBaseKeymap } from './_tsup-dts-rollup';
@@ -34,6 +33,7 @@ export { definePlugin } from './_tsup-dts-rollup';
34
33
  export { pluginFacet } from './_tsup-dts-rollup';
35
34
  export { PluginPayload } from './_tsup-dts-rollup';
36
35
  export { defineText } from './_tsup-dts-rollup';
36
+ export { defineUpdateHandler } from './_tsup-dts-rollup';
37
37
  export { Facet } from './_tsup-dts-rollup';
38
38
  export { FacetOptions } from './_tsup-dts-rollup';
39
39
  export { CommandArgs } from './_tsup-dts-rollup';
@@ -44,14 +44,21 @@ export { ExtractMarks } from './_tsup-dts-rollup';
44
44
  export { ExtractNodes } from './_tsup-dts-rollup';
45
45
  export { SimplifyExtension } from './_tsup-dts-rollup';
46
46
  export { ExtensionTyping } from './_tsup-dts-rollup';
47
- export { NodeJson } from './_tsup-dts-rollup';
48
- export { SelectionJson } from './_tsup-dts-rollup';
49
- export { StateJson } from './_tsup-dts-rollup';
47
+ export { NodeJSON } from './_tsup-dts-rollup';
48
+ export { SelectionJSON } from './_tsup-dts-rollup';
49
+ export { StateJSON } from './_tsup-dts-rollup';
50
50
  export { Priority } from './_tsup-dts-rollup';
51
51
  export { SimplifyUnion } from './_tsup-dts-rollup';
52
52
  export { getMarkType } from './_tsup-dts-rollup';
53
53
  export { getNodeType } from './_tsup-dts-rollup';
54
- export { elementToJSON } from './_tsup-dts-rollup';
55
- export { elementToNode } from './_tsup-dts-rollup';
56
- export { htmlToJSON } from './_tsup-dts-rollup';
57
- export { htmlToNode } from './_tsup-dts-rollup';
54
+ export { jsonFromElement } from './_tsup-dts-rollup';
55
+ export { jsonFromHTML } from './_tsup-dts-rollup';
56
+ export { jsonFromNode } from './_tsup-dts-rollup';
57
+ export { jsonFromState } from './_tsup-dts-rollup';
58
+ export { nodeFromElement } from './_tsup-dts-rollup';
59
+ export { nodeFromHTML } from './_tsup-dts-rollup';
60
+ export { isAllSelection } from './_tsup-dts-rollup';
61
+ export { isMark } from './_tsup-dts-rollup';
62
+ export { isNodeSelection } from './_tsup-dts-rollup';
63
+ export { isProseMirrorNode } from './_tsup-dts-rollup';
64
+ export { isTextSelection } from './_tsup-dts-rollup';
@@ -368,19 +368,19 @@ function getBrowserWindow() {
368
368
  }
369
369
 
370
370
  // src/utils/parse.ts
371
- function elementToNode(element, schema) {
371
+ function nodeFromElement(element, schema) {
372
372
  return DOMParser.fromSchema(schema).parse(element);
373
373
  }
374
- function elementToJSON(element, schema) {
375
- return elementToNode(element, schema).toJSON();
374
+ function jsonFromElement(element, schema) {
375
+ return jsonFromNode(nodeFromElement(element, schema));
376
376
  }
377
- function htmlToNode(html, schema) {
378
- return elementToNode(htmlToElement(html), schema);
377
+ function nodeFromHTML(html, schema) {
378
+ return nodeFromElement(elementFromHTML(html), schema);
379
379
  }
380
- function htmlToJSON(html, schema) {
381
- return elementToJSON(htmlToElement(html), schema);
380
+ function jsonFromHTML(html, schema) {
381
+ return jsonFromElement(elementFromHTML(html), schema);
382
382
  }
383
- function htmlToElement(html) {
383
+ function elementFromHTML(html) {
384
384
  const win = getBrowserWindow();
385
385
  if (!win) {
386
386
  throw new ProseKitError(
@@ -390,6 +390,12 @@ function htmlToElement(html) {
390
390
  const parser = new win.DOMParser();
391
391
  return parser.parseFromString(`<body>${html}</body>`, "text/html").body;
392
392
  }
393
+ function jsonFromState(state) {
394
+ return state.toJSON();
395
+ }
396
+ function jsonFromNode(node) {
397
+ return node.toJSON();
398
+ }
393
399
 
394
400
  // src/extensions/default-state.ts
395
401
  function defineDefaultState({
@@ -406,7 +412,11 @@ function defineDefaultState({
406
412
  ({ schema }) => {
407
413
  const config = {};
408
414
  if (defaultHTML) {
409
- defaultDoc = htmlToJSON(defaultHTML, schema);
415
+ if (typeof defaultHTML === "string") {
416
+ defaultDoc = jsonFromHTML(defaultHTML, schema);
417
+ } else {
418
+ defaultDoc = jsonFromElement(defaultHTML, schema);
419
+ }
410
420
  }
411
421
  if (defaultDoc) {
412
422
  config.doc = schema.nodeFromJSON(defaultDoc);
@@ -637,12 +647,26 @@ function updateExtension(prevInputs, prevConverters, extension, mode) {
637
647
 
638
648
  // src/utils/type-assertion.ts
639
649
  import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
650
+ import {
651
+ AllSelection,
652
+ NodeSelection,
653
+ TextSelection as TextSelection2
654
+ } from "@prosekit/pm/state";
640
655
  function isProseMirrorNode(node) {
641
656
  return node instanceof ProseMirrorNode;
642
657
  }
643
658
  function isMark(mark) {
644
659
  return mark instanceof Mark;
645
660
  }
661
+ function isTextSelection(sel) {
662
+ return sel instanceof TextSelection2;
663
+ }
664
+ function isNodeSelection(sel) {
665
+ return sel instanceof NodeSelection;
666
+ }
667
+ function isAllSelection(sel) {
668
+ return sel instanceof AllSelection;
669
+ }
646
670
 
647
671
  // src/utils/is-mark-active.ts
648
672
  function isMarkActive(state, type, attrs) {
@@ -1022,10 +1046,10 @@ function insertText({
1022
1046
  }
1023
1047
 
1024
1048
  // src/commands/select-all.ts
1025
- import { AllSelection } from "@prosekit/pm/state";
1049
+ import { AllSelection as AllSelection2 } from "@prosekit/pm/state";
1026
1050
  function selectAll() {
1027
1051
  return (state, dispatch) => {
1028
- dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
1052
+ dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection2(state.doc)));
1029
1053
  return true;
1030
1054
  };
1031
1055
  }
@@ -1118,12 +1142,16 @@ function defineDoc() {
1118
1142
  });
1119
1143
  }
1120
1144
 
1121
- // src/extensions/event-handler.ts
1122
- import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
1145
+ // src/extensions/history.ts
1146
+ import { history, redo, undo } from "@prosekit/pm/history";
1123
1147
 
1124
- // src/types/void-function.ts
1125
- function voidFunction() {
1126
- }
1148
+ // src/utils/env.ts
1149
+ var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
1150
+
1151
+ // src/extensions/keymap.ts
1152
+ import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
1153
+ import { keydownHandler } from "@prosekit/pm/keymap";
1154
+ import { Plugin as Plugin3, PluginKey } from "@prosekit/pm/state";
1127
1155
 
1128
1156
  // src/extensions/plugin.ts
1129
1157
  import "@prosekit/pm/model";
@@ -1150,53 +1178,7 @@ var pluginFacet = Facet.define({
1150
1178
  next: stateFacet
1151
1179
  });
1152
1180
 
1153
- // src/extensions/event-handler.ts
1154
- function defineEventHandler(options) {
1155
- var _a;
1156
- const updateHandler = (_a = options == null ? void 0 : options.update) != null ? _a : voidFunction;
1157
- return eventFacet.extension([updateHandler]);
1158
- }
1159
- var eventFacet = Facet.define({
1160
- converter: () => {
1161
- let updateHandlers = [];
1162
- const plugin = new ProseMirrorPlugin({
1163
- key: pluginKey,
1164
- view: () => {
1165
- updateHandlers.forEach((fn) => fn());
1166
- return {
1167
- update: (_view, _prevState) => {
1168
- updateHandlers.forEach((fn) => fn());
1169
- }
1170
- };
1171
- }
1172
- });
1173
- const pluginFunc = () => [plugin];
1174
- return {
1175
- create: (handlers) => {
1176
- updateHandlers = handlers;
1177
- return pluginFunc;
1178
- },
1179
- update: (handlers) => {
1180
- updateHandlers = handlers;
1181
- return null;
1182
- }
1183
- };
1184
- },
1185
- next: pluginFacet,
1186
- singleton: true
1187
- });
1188
- var pluginKey = new PluginKey("prosekit-event-handler");
1189
-
1190
- // src/extensions/history.ts
1191
- import { history, redo, undo } from "@prosekit/pm/history";
1192
-
1193
- // src/utils/env.ts
1194
- var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
1195
-
1196
1181
  // src/extensions/keymap.ts
1197
- import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
1198
- import { keydownHandler } from "@prosekit/pm/keymap";
1199
- import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state";
1200
1182
  function defineKeymap(keymap) {
1201
1183
  return keymapFacet.extension([keymap]);
1202
1184
  }
@@ -1245,7 +1227,7 @@ function mergeKeymaps(keymaps) {
1245
1227
  ])
1246
1228
  );
1247
1229
  }
1248
- var keymapPluginKey = new PluginKey2("prosekit-keymap");
1230
+ var keymapPluginKey = new PluginKey("prosekit-keymap");
1249
1231
 
1250
1232
  // src/extensions/history.ts
1251
1233
  function defineHistory() {
@@ -1267,11 +1249,20 @@ function defineHistory() {
1267
1249
  }
1268
1250
 
1269
1251
  // src/extensions/input-rules.ts
1270
- import { inputRules } from "@prosekit/pm/inputrules";
1252
+ import { InputRule, inputRules } from "@prosekit/pm/inputrules";
1271
1253
  import "@prosekit/pm/model";
1272
1254
  import "@prosekit/pm/state";
1273
- function defineInputRule(rules) {
1274
- return inputRuleFacet.extension([rules]);
1255
+ function defineInputRule(rule) {
1256
+ if (rule instanceof InputRule) {
1257
+ return inputRuleFacet.extension([() => rule]);
1258
+ }
1259
+ if (Array.isArray(rule) && rule.every((r) => r instanceof InputRule)) {
1260
+ return inputRuleFacet.extension([() => rule]);
1261
+ }
1262
+ if (typeof rule === "function") {
1263
+ return inputRuleFacet.extension([rule]);
1264
+ }
1265
+ throw new TypeError("Invalid input rule");
1275
1266
  }
1276
1267
  var inputRuleFacet = Facet.define({
1277
1268
  convert: (inputs) => {
@@ -1302,7 +1293,7 @@ var markSpecFacet = Facet.define({
1302
1293
  });
1303
1294
 
1304
1295
  // src/extensions/node-view.ts
1305
- import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
1296
+ import { ProseMirrorPlugin } from "@prosekit/pm/state";
1306
1297
  import "@prosekit/pm/view";
1307
1298
  function defineNodeView(options) {
1308
1299
  return nodeViewFacet.extension([options]);
@@ -1315,13 +1306,13 @@ var nodeViewFacet = Facet.define({
1315
1306
  nodeViews[input.name] = input.constructor;
1316
1307
  }
1317
1308
  }
1318
- return () => [new ProseMirrorPlugin2({ props: { nodeViews } })];
1309
+ return () => [new ProseMirrorPlugin({ props: { nodeViews } })];
1319
1310
  },
1320
1311
  next: pluginFacet
1321
1312
  });
1322
1313
 
1323
1314
  // src/extensions/node-view-effect.ts
1324
- import { ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
1315
+ import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
1325
1316
  import "@prosekit/pm/view";
1326
1317
  function defineNodeViewEffect(options) {
1327
1318
  return nodeViewEffectFacet.extension([options]);
@@ -1349,7 +1340,7 @@ var nodeViewEffectFacet = Facet.define({
1349
1340
  nodeViews[name] = factory(args);
1350
1341
  }
1351
1342
  }
1352
- return () => Object.keys(nodeViews).length > 0 ? [new ProseMirrorPlugin3({ props: { nodeViews } })] : [];
1343
+ return () => Object.keys(nodeViews).length > 0 ? [new ProseMirrorPlugin2({ props: { nodeViews } })] : [];
1353
1344
  },
1354
1345
  next: pluginFacet
1355
1346
  });
@@ -1377,6 +1368,48 @@ function defineText() {
1377
1368
  group: "inline"
1378
1369
  });
1379
1370
  }
1371
+
1372
+ // src/extensions/update-handler.ts
1373
+ import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
1374
+
1375
+ // src/utils/is-not-null.ts
1376
+ function isNotNull(value) {
1377
+ return value != null;
1378
+ }
1379
+
1380
+ // src/extensions/update-handler.ts
1381
+ function defineUpdateHandler(handler) {
1382
+ return updateHandlerFacet.extension([handler]);
1383
+ }
1384
+ var updateHandlerFacet = Facet.define({
1385
+ converter: () => {
1386
+ let updateHandlers = [];
1387
+ const plugin = new ProseMirrorPlugin3({
1388
+ key: pluginKey,
1389
+ view: () => {
1390
+ return {
1391
+ update: (view, prevState) => {
1392
+ updateHandlers.forEach((fn) => fn({ view, prevState }));
1393
+ }
1394
+ };
1395
+ }
1396
+ });
1397
+ const pluginFunc = () => [plugin];
1398
+ return {
1399
+ create: (handlers) => {
1400
+ updateHandlers = handlers.filter(isNotNull);
1401
+ return pluginFunc;
1402
+ },
1403
+ update: (handlers) => {
1404
+ updateHandlers = handlers.filter(isNotNull);
1405
+ return null;
1406
+ }
1407
+ };
1408
+ },
1409
+ next: pluginFacet,
1410
+ singleton: true
1411
+ });
1412
+ var pluginKey = new PluginKey2("prosekit-event-handler");
1380
1413
  export {
1381
1414
  Editor,
1382
1415
  Facet,
@@ -1389,7 +1422,6 @@ export {
1389
1422
  defineCommands,
1390
1423
  defineDefaultState,
1391
1424
  defineDoc,
1392
- defineEventHandler,
1393
1425
  defineHistory,
1394
1426
  defineInputRule,
1395
1427
  defineKeymap,
@@ -1400,13 +1432,21 @@ export {
1400
1432
  defineParagraph,
1401
1433
  definePlugin,
1402
1434
  defineText,
1403
- elementToJSON,
1404
- elementToNode,
1435
+ defineUpdateHandler,
1405
1436
  getMarkType,
1406
1437
  getNodeType,
1407
- htmlToJSON,
1408
- htmlToNode,
1409
1438
  insertNode,
1439
+ isAllSelection,
1440
+ isMark,
1441
+ isNodeSelection,
1442
+ isProseMirrorNode,
1443
+ isTextSelection,
1444
+ jsonFromElement,
1445
+ jsonFromHTML,
1446
+ jsonFromNode,
1447
+ jsonFromState,
1448
+ nodeFromElement,
1449
+ nodeFromHTML,
1410
1450
  pluginFacet,
1411
1451
  removeMark,
1412
1452
  setBlockType,
package/dist/style.css CHANGED
@@ -1,4 +1,4 @@
1
- /* ../../node_modules/.pnpm/prosemirror-view@1.32.3/node_modules/prosemirror-view/style/prosemirror.css */
1
+ /* ../../node_modules/.pnpm/prosemirror-view@1.32.4/node_modules/prosemirror-view/style/prosemirror.css */
2
2
  .ProseMirror {
3
3
  position: relative;
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@prosekit/pm": "^0.0.7",
42
42
  "orderedmap": "^2.1.1",
43
- "type-fest": "^4.6.0"
43
+ "type-fest": "^4.7.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@prosekit/dev": "*",