@prosekit/core 0.0.0-next-20240626133927 → 0.0.0-next-20240715024943

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,6 +1,5 @@
1
1
  import { AllSelection } from '@prosekit/pm/state';
2
2
  import { Attrs } from '@prosekit/pm/model';
3
- import { Attrs as Attrs_2 } from 'prosemirror-model';
4
3
  import { Command } from '@prosekit/pm/state';
5
4
  import type { ContentMatch } from '@prosekit/pm/model';
6
5
  import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
@@ -15,9 +14,7 @@ import type { IsEqual } from 'type-fest';
15
14
  import { Mark } from '@prosekit/pm/model';
16
15
  import type { MarkSpec } from '@prosekit/pm/model';
17
16
  import { MarkType } from '@prosekit/pm/model';
18
- import { MarkType as MarkType_2 } from 'prosemirror-model';
19
- import { Node as Node_2 } from 'prosemirror-model';
20
- import type { Node as Node_3 } from '@prosekit/pm/model';
17
+ import type { Node as Node_2 } from '@prosekit/pm/model';
21
18
  import { NodeSelection } from '@prosekit/pm/state';
22
19
  import type { NodeSpec } from '@prosekit/pm/model';
23
20
  import { NodeType } from '@prosekit/pm/model';
@@ -25,6 +22,7 @@ import { NodeType as NodeType_2 } from 'prosemirror-model';
25
22
  import { NodeView } from '@prosekit/pm/view';
26
23
  import { NodeViewConstructor } from '@prosekit/pm/view';
27
24
  import { Options } from 'tsup';
25
+ import type { ParseOptions } from '@prosekit/pm/model';
28
26
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
29
27
  import { ProseMirrorFragment } from '@prosekit/pm/model';
30
28
  import { ProseMirrorNode } from '@prosekit/pm/model';
@@ -49,7 +47,14 @@ declare type Action = (options: {
49
47
  *
50
48
  * @public
51
49
  */
52
- declare function addMark(options: {
50
+ declare function addMark(options: AddMarkOptions): Command;
51
+ export { addMark }
52
+ export { addMark as addMark_alias_1 }
53
+
54
+ /**
55
+ * @public
56
+ */
57
+ declare interface AddMarkOptions {
53
58
  /**
54
59
  * The type of the mark to add.
55
60
  */
@@ -66,9 +71,9 @@ declare function addMark(options: {
66
71
  * The end position of the document. By default it will be the end position of current selection.
67
72
  */
68
73
  to?: number;
69
- }): Command;
70
- export { addMark }
71
- export { addMark as addMark_alias_1 }
74
+ }
75
+ export { AddMarkOptions }
76
+ export { AddMarkOptions as AddMarkOptions_alias_1 }
72
77
 
73
78
  export declare function applyAction(operator: Action): Command;
74
79
 
@@ -168,7 +173,7 @@ declare type ClickHandler = (view: EditorView, pos: number, event: MouseEvent) =
168
173
  export { ClickHandler }
169
174
  export { ClickHandler as ClickHandler_alias_1 }
170
175
 
171
- declare type ClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
176
+ declare type ClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
172
177
  export { ClickOnHandler }
173
178
  export { ClickOnHandler as ClickOnHandler_alias_1 }
174
179
 
@@ -183,7 +188,14 @@ declare const clsx: (...args: Array<string | boolean | null | undefined>) => str
183
188
  export { clsx }
184
189
  export { clsx as clsx_alias_1 }
185
190
 
186
- export declare function collectNodes(content: NodeContent): ProseMirrorNode[];
191
+ /**
192
+ * Collects all nodes from a given content.
193
+ *
194
+ * @public
195
+ */
196
+ declare function collectNodes(content: NodeContent): ProseMirrorNode[];
197
+ export { collectNodes }
198
+ export { collectNodes as collectNodes_alias_1 }
187
199
 
188
200
  export declare function combineEventHandlers<Handler extends (...args: any[]) => boolean | void, Args extends Parameters<Handler> = Parameters<Handler>>(): readonly [(handlers: Handler[]) => void, (...args: Args) => boolean];
189
201
 
@@ -287,49 +299,16 @@ declare function defineBaseCommands(): Extension<{
287
299
  from?: number;
288
300
  to?: number;
289
301
  }];
290
- insertNode: [options: {
291
- node: Node_2;
292
- pos?: number;
293
- type?: undefined;
294
- attrs?: undefined;
295
- } | {
296
- node?: undefined;
297
- pos?: number;
298
- type: string;
299
- attrs?: Attrs_2;
300
- }];
301
- removeNode: [options: {
302
- type: string | NodeType_2;
303
- pos?: number;
304
- }];
305
- wrap: [{
306
- nodeType: NodeType_2;
307
- attrs?: Attrs_2 | null;
308
- }];
309
- setBlockType: [options: {
310
- type: NodeType_2 | string;
311
- attrs?: Attrs_2 | null;
312
- from?: number;
313
- to?: number;
314
- }];
315
- setNodeAttrs: [options: {
316
- type: string | NodeType_2 | string[] | NodeType_2[];
317
- attrs: Attrs_2;
318
- pos?: number;
319
- }];
302
+ insertNode: [options: InsertNodeOptions];
303
+ removeNode: [options: RemoveNodeOptions];
304
+ wrap: [WrapOptions];
305
+ setBlockType: [options: SetBlockTypeOptions];
306
+ setNodeAttrs: [options: SetNodeAttrsOptions];
320
307
  selectAll: [];
321
- addMark: [options: {
322
- type: string | MarkType_2;
323
- attrs?: Attrs_2 | null;
324
- from?: number;
325
- to?: number;
326
- }];
327
- removeMark: [options: {
328
- type: string | MarkType_2;
329
- attrs?: Attrs_2 | null;
330
- from?: number;
331
- to?: number;
332
- }];
308
+ addMark: [options: AddMarkOptions];
309
+ removeMark: [options: RemoveMarkOptions];
310
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
311
+ unsetMark: [options?: UnsetMarkOptions | undefined];
333
312
  };
334
313
  Nodes: never;
335
314
  Marks: never;
@@ -486,13 +465,15 @@ export { defineFocusChangeHandler as defineFocusChangeHandler_alias_1 }
486
465
 
487
466
  /**
488
467
  * Add undo/redo history to the editor.
468
+ *
469
+ * @public
489
470
  */
490
- declare function defineHistory(): Extension< {
471
+ declare function defineHistory({ depth, newGroupDelay, }?: HistoryOptions): Extension< {
491
472
  Nodes: never;
492
473
  Marks: never;
493
474
  Commands: {
494
- undo: [];
495
- redo: [];
475
+ readonly undo: [];
476
+ readonly redo: [];
496
477
  };
497
478
  }>;
498
479
  export { defineHistory }
@@ -576,6 +557,13 @@ declare function defineNodeView(options: NodeViewOptions): Extension;
576
557
  export { defineNodeView }
577
558
  export { defineNodeView as defineNodeView_alias_1 }
578
559
 
560
+ /**
561
+ * @internal
562
+ */
563
+ declare function defineNodeViewComponent<T>(options: NodeViewComponentOptions<T>): Extension;
564
+ export { defineNodeViewComponent }
565
+ export { defineNodeViewComponent as defineNodeViewComponent_alias_1 }
566
+
579
567
  /**
580
568
  * @internal
581
569
  */
@@ -642,61 +630,28 @@ export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_
642
630
  /**
643
631
  * @internal
644
632
  */
645
- export declare function defineTestExtension(): Extension< {
646
- Nodes: "text" | "doc" | "paragraph";
647
- Marks: "bold";
648
- Commands: {
649
- undo: [];
650
- redo: [];
651
- insertText: [{
652
- text: string;
653
- from?: number;
654
- to?: number;
655
- }];
656
- insertNode: [options: {
657
- node: Node_2;
658
- pos?: number;
659
- type?: undefined;
660
- attrs?: undefined;
661
- } | {
662
- node?: undefined;
663
- pos?: number;
664
- type: string;
665
- attrs?: Attrs_2;
666
- }];
667
- removeNode: [options: {
668
- type: string | NodeType_2;
669
- pos?: number;
670
- }];
671
- wrap: [{
672
- nodeType: NodeType_2;
673
- attrs?: Attrs_2 | null;
674
- }];
675
- setBlockType: [options: {
676
- type: NodeType_2 | string;
677
- attrs?: Attrs_2 | null;
678
- from?: number;
679
- to?: number;
680
- }];
681
- setNodeAttrs: [options: {
682
- type: string | NodeType_2 | string[] | NodeType_2[];
683
- attrs: Attrs_2;
684
- pos?: number;
685
- }];
686
- selectAll: [];
687
- addMark: [options: {
688
- type: string | MarkType_2;
689
- attrs?: Attrs_2 | null;
690
- from?: number;
691
- to?: number;
692
- }];
693
- removeMark: [options: {
694
- type: string | MarkType_2;
695
- attrs?: Attrs_2 | null;
696
- from?: number;
697
- to?: number;
698
- }];
699
- };
633
+ export declare function defineTestExtension(): Extension<{
634
+ Nodes: "text" | "doc" | "paragraph" | "heading";
635
+ Marks: "bold" | "italic";
636
+ Commands: {
637
+ insertText: [{
638
+ text: string;
639
+ from?: number;
640
+ to?: number;
641
+ }];
642
+ insertNode: [options: InsertNodeOptions];
643
+ removeNode: [options: RemoveNodeOptions];
644
+ wrap: [WrapOptions];
645
+ setBlockType: [options: SetBlockTypeOptions];
646
+ setNodeAttrs: [options: SetNodeAttrsOptions];
647
+ selectAll: [];
648
+ addMark: [options: AddMarkOptions];
649
+ removeMark: [options: RemoveMarkOptions];
650
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
651
+ unsetMark: [options?: UnsetMarkOptions | undefined];
652
+ readonly undo: [];
653
+ readonly redo: [];
654
+ };
700
655
  }>;
701
656
 
702
657
  /**
@@ -775,9 +730,9 @@ export declare class DOMDocumentNotFoundError extends ProseKitError {
775
730
  }
776
731
 
777
732
  /** @public */
778
- declare type DOMDocumentOptions = {
733
+ declare interface DOMDocumentOptions {
779
734
  document?: Document;
780
- };
735
+ }
781
736
  export { DOMDocumentOptions }
782
737
  export { DOMDocumentOptions as DOMDocumentOptions_alias_1 }
783
738
 
@@ -806,16 +761,16 @@ export declare type DOMEventPayload = [event: string, handler: DOMEventHandler];
806
761
  export declare type DOMNode = InstanceType<typeof window.Node>;
807
762
 
808
763
  /** @public */
809
- declare type DOMParserOptions = {
764
+ declare interface DOMParserOptions extends ParseOptions {
810
765
  DOMParser?: typeof DOMParser_2;
811
- };
766
+ }
812
767
  export { DOMParserOptions }
813
768
  export { DOMParserOptions as DOMParserOptions_alias_1 }
814
769
 
815
770
  /** @public */
816
- declare type DOMSerializerOptions = {
771
+ declare interface DOMSerializerOptions {
817
772
  DOMSerializer?: typeof DOMSerializer;
818
- };
773
+ }
819
774
  export { DOMSerializerOptions }
820
775
  export { DOMSerializerOptions as DOMSerializerOptions_alias_1 }
821
776
 
@@ -823,7 +778,7 @@ declare type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEv
823
778
  export { DoubleClickHandler }
824
779
  export { DoubleClickHandler as DoubleClickHandler_alias_1 }
825
780
 
826
- declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
781
+ declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
827
782
  export { DoubleClickOnHandler }
828
783
  export { DoubleClickOnHandler as DoubleClickOnHandler_alias_1 }
829
784
 
@@ -997,14 +952,21 @@ export { elementFromNode as elementFromNode_alias_1 }
997
952
  *
998
953
  * @public
999
954
  */
1000
- declare function expandMark(options: {
955
+ declare function expandMark(options: ExpandMarkOptions): Command;
956
+ export { expandMark }
957
+ export { expandMark as expandMark_alias_1 }
958
+
959
+ /**
960
+ * @public
961
+ */
962
+ declare interface ExpandMarkOptions {
1001
963
  /**
1002
964
  * The type of the mark to expand.
1003
965
  */
1004
966
  type: string | MarkType;
1005
- }): Command;
1006
- export { expandMark }
1007
- export { expandMark as expandMark_alias_1 }
967
+ }
968
+ export { ExpandMarkOptions }
969
+ export { ExpandMarkOptions as ExpandMarkOptions_alias_1 }
1008
970
 
1009
971
  /**
1010
972
  * @public
@@ -1211,6 +1173,30 @@ export declare type GroupedEntries<T extends Record<string, any>> = {
1211
1173
 
1212
1174
  export declare function groupEntries<T extends Record<string, any>>(entries: ObjectEntries<T>[]): GroupedEntries<T>;
1213
1175
 
1176
+ /**
1177
+ * Options for {@link defineHistory}.
1178
+ *
1179
+ * @public
1180
+ */
1181
+ declare interface HistoryOptions {
1182
+ /**
1183
+ * The amount of history events that are collected before the oldest events
1184
+ * are discarded.
1185
+ *
1186
+ * @default 200
1187
+ */
1188
+ depth?: number;
1189
+ /**
1190
+ * The delay in milliseconds between changes after which a new group should be
1191
+ * started.
1192
+ *
1193
+ * @default 250
1194
+ */
1195
+ newGroupDelay?: number;
1196
+ }
1197
+ export { HistoryOptions }
1198
+ export { HistoryOptions as HistoryOptions_alias_1 }
1199
+
1214
1200
  /**
1215
1201
  * @internal
1216
1202
  */
@@ -1240,17 +1226,7 @@ export { htmlFromNode as htmlFromNode_alias_1 }
1240
1226
  *
1241
1227
  * @public
1242
1228
  */
1243
- declare function insertNode(options: {
1244
- node: ProseMirrorNode;
1245
- pos?: number;
1246
- type?: undefined;
1247
- attrs?: undefined;
1248
- } | {
1249
- node?: undefined;
1250
- pos?: number;
1251
- type: string;
1252
- attrs?: Attrs;
1253
- }): Command;
1229
+ declare function insertNode(options: InsertNodeOptions): Command;
1254
1230
  export { insertNode }
1255
1231
  export { insertNode as insertNode_alias_1 }
1256
1232
 
@@ -1259,6 +1235,31 @@ export declare function insertNodeAction({ node, pos, }: {
1259
1235
  pos?: number;
1260
1236
  }): Action;
1261
1237
 
1238
+ /**
1239
+ * @public
1240
+ */
1241
+ declare interface InsertNodeOptions {
1242
+ /**
1243
+ * The node to insert. Either this or `type` must be provided.
1244
+ */
1245
+ node?: ProseMirrorNode;
1246
+ /**
1247
+ * The type of the node to insert. Either this or `node` must be provided.
1248
+ */
1249
+ type?: string | NodeType;
1250
+ /**
1251
+ * When `type` is provided, the attributes of the node to insert.
1252
+ */
1253
+ attrs?: Attrs;
1254
+ /**
1255
+ * The position to insert the node at. By default it will be the anchor
1256
+ * position of current selection.
1257
+ */
1258
+ pos?: number;
1259
+ }
1260
+ export { InsertNodeOptions }
1261
+ export { InsertNodeOptions as InsertNodeOptions_alias_1 }
1262
+
1262
1263
  /**
1263
1264
  * Returns a command that inserts the given text.
1264
1265
  *
@@ -1284,6 +1285,15 @@ declare const isApple: boolean;
1284
1285
  export { isApple }
1285
1286
  export { isApple as isApple_alias_1 }
1286
1287
 
1288
+ /**
1289
+ * Whether the selection is an empty text selection at the start of a block.
1290
+ *
1291
+ * @internal
1292
+ */
1293
+ declare function isAtBlockStart(state: EditorState, view?: EditorView): ResolvedPos | null;
1294
+ export { isAtBlockStart }
1295
+ export { isAtBlockStart as isAtBlockStart_alias_1 }
1296
+
1287
1297
  export declare function isElement(value: unknown): value is Element;
1288
1298
 
1289
1299
  /**
@@ -1379,9 +1389,9 @@ export { jsonFromState }
1379
1389
  export { jsonFromState as jsonFromState_alias_1 }
1380
1390
 
1381
1391
  /** @public */
1382
- declare type JSONParserOptions = {
1392
+ declare interface JSONParserOptions {
1383
1393
  schema: Schema;
1384
- };
1394
+ }
1385
1395
  export { JSONParserOptions }
1386
1396
  export { JSONParserOptions as JSONParserOptions_alias_1 }
1387
1397
 
@@ -1541,7 +1551,12 @@ export { NodeBuilder as NodeBuilder_alias_1 }
1541
1551
  */
1542
1552
  export declare type NodeChild = ProseMirrorNode | string | NodeChild[];
1543
1553
 
1544
- export declare type NodeContent = ProseMirrorNode | ProseMirrorFragment | NodeContent[];
1554
+ /**
1555
+ * @public
1556
+ */
1557
+ declare type NodeContent = ProseMirrorNode | ProseMirrorFragment | NodeContent[];
1558
+ export { NodeContent }
1559
+ export { NodeContent as NodeContent_alias_1 }
1545
1560
 
1546
1561
  /**
1547
1562
  * Parse a HTML element to a ProseMirror node.
@@ -1598,13 +1613,19 @@ export { NodeSpecOptions as NodeSpecOptions_alias_1 }
1598
1613
  /**
1599
1614
  * @internal
1600
1615
  */
1601
- declare type NodeViewFactoryOptions<T> = {
1616
+ declare type NodeViewComponentOptions<T> = {
1602
1617
  group: string;
1603
1618
  name: string;
1604
1619
  args: T;
1605
- } | {
1620
+ };
1621
+ export { NodeViewComponentOptions }
1622
+ export { NodeViewComponentOptions as NodeViewComponentOptions_alias_1 }
1623
+
1624
+ /**
1625
+ * @internal
1626
+ */
1627
+ declare type NodeViewFactoryOptions<T> = {
1606
1628
  group: string;
1607
- name?: undefined;
1608
1629
  factory: (args: T) => NodeViewConstructor;
1609
1630
  };
1610
1631
  export { NodeViewFactoryOptions }
@@ -1708,7 +1729,14 @@ export { ProseKitError as ProseKitError_alias_1 }
1708
1729
  *
1709
1730
  * @public
1710
1731
  */
1711
- declare function removeMark(options: {
1732
+ declare function removeMark(options: RemoveMarkOptions): Command;
1733
+ export { removeMark }
1734
+ export { removeMark as removeMark_alias_1 }
1735
+
1736
+ /**
1737
+ * @public
1738
+ */
1739
+ declare interface RemoveMarkOptions {
1712
1740
  /**
1713
1741
  * The type of the mark to remove.
1714
1742
  */
@@ -1725,16 +1753,23 @@ declare function removeMark(options: {
1725
1753
  * The end position of the document. By default it will be the end position of current selection.
1726
1754
  */
1727
1755
  to?: number;
1728
- }): Command;
1729
- export { removeMark }
1730
- export { removeMark as removeMark_alias_1 }
1756
+ }
1757
+ export { RemoveMarkOptions }
1758
+ export { RemoveMarkOptions as RemoveMarkOptions_alias_1 }
1731
1759
 
1732
1760
  /**
1733
1761
  * Returns a command to remove the nearest ancestor node of a specific type from the current position.
1734
1762
  *
1735
1763
  * @public
1736
1764
  */
1737
- declare function removeNode(options: {
1765
+ declare function removeNode(options: RemoveNodeOptions): Command;
1766
+ export { removeNode }
1767
+ export { removeNode as removeNode_alias_1 }
1768
+
1769
+ /**
1770
+ * @public
1771
+ */
1772
+ declare interface RemoveNodeOptions {
1738
1773
  /**
1739
1774
  * The type of the node to remove.
1740
1775
  */
@@ -1743,9 +1778,9 @@ declare function removeNode(options: {
1743
1778
  * The document position to start searching node. By default it will be the anchor position of current selection.
1744
1779
  */
1745
1780
  pos?: number;
1746
- }): Command;
1747
- export { removeNode }
1748
- export { removeNode as removeNode_alias_1 }
1781
+ }
1782
+ export { RemoveNodeOptions }
1783
+ export { RemoveNodeOptions as RemoveNodeOptions_alias_1 }
1749
1784
 
1750
1785
  export declare const rootFacet: Facet<RootPayload, RootOutput>;
1751
1786
 
@@ -1799,21 +1834,35 @@ export { SelectionJSON as SelectionJSON_alias_1 }
1799
1834
  *
1800
1835
  * @public
1801
1836
  */
1802
- declare function setBlockType(options: {
1837
+ declare function setBlockType(options: SetBlockTypeOptions): Command;
1838
+ export { setBlockType }
1839
+ export { setBlockType as setBlockType_alias_1 }
1840
+
1841
+ /**
1842
+ * @public
1843
+ */
1844
+ declare interface SetBlockTypeOptions {
1803
1845
  type: NodeType | string;
1804
1846
  attrs?: Attrs | null;
1805
1847
  from?: number;
1806
1848
  to?: number;
1807
- }): Command;
1808
- export { setBlockType }
1809
- export { setBlockType as setBlockType_alias_1 }
1849
+ }
1850
+ export { SetBlockTypeOptions }
1851
+ export { SetBlockTypeOptions as SetBlockTypeOptions_alias_1 }
1810
1852
 
1811
1853
  /**
1812
1854
  * Returns a command that set the attributes of the current node.
1813
1855
  *
1814
1856
  * @public
1815
1857
  */
1816
- declare function setNodeAttrs(options: {
1858
+ declare function setNodeAttrs(options: SetNodeAttrsOptions): Command;
1859
+ export { setNodeAttrs }
1860
+ export { setNodeAttrs as setNodeAttrs_alias_1 }
1861
+
1862
+ /**
1863
+ * @public
1864
+ */
1865
+ declare interface SetNodeAttrsOptions {
1817
1866
  /**
1818
1867
  * The type of node to set the attributes of.
1819
1868
  *
@@ -1829,9 +1878,9 @@ declare function setNodeAttrs(options: {
1829
1878
  * containing the current selection.
1830
1879
  */
1831
1880
  pos?: number;
1832
- }): Command;
1833
- export { setNodeAttrs }
1834
- export { setNodeAttrs as setNodeAttrs_alias_1 }
1881
+ }
1882
+ export { SetNodeAttrsOptions }
1883
+ export { SetNodeAttrsOptions as SetNodeAttrsOptions_alias_1 }
1835
1884
 
1836
1885
  export declare function setSelectionAround(tr: Transaction, pos: number): void;
1837
1886
 
@@ -1845,6 +1894,46 @@ export declare type Setter<T> = (value: T) => void;
1845
1894
  */
1846
1895
  export declare function setupEditorExtension<E extends Extension>(options: EditorOptions<E>): E;
1847
1896
 
1897
+ /**
1898
+ * @internal
1899
+ */
1900
+ export declare function setupTest(): {
1901
+ editor: TestEditor<Extension<{
1902
+ Nodes: "text" | "doc" | "paragraph" | "heading";
1903
+ Marks: "bold" | "italic";
1904
+ Commands: {
1905
+ insertText: [{
1906
+ text: string;
1907
+ from?: number;
1908
+ to?: number;
1909
+ }];
1910
+ insertNode: [options: InsertNodeOptions];
1911
+ removeNode: [options: RemoveNodeOptions];
1912
+ wrap: [WrapOptions];
1913
+ setBlockType: [options: SetBlockTypeOptions];
1914
+ setNodeAttrs: [options: SetNodeAttrsOptions];
1915
+ selectAll: [];
1916
+ addMark: [options: AddMarkOptions];
1917
+ removeMark: [options: RemoveMarkOptions];
1918
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
1919
+ unsetMark: [options?: UnsetMarkOptions | undefined];
1920
+ readonly undo: [];
1921
+ readonly redo: [];
1922
+ };
1923
+ }>>;
1924
+ n: Record<"text" | "doc" | "paragraph" | "heading", NodeBuilder>;
1925
+ m: Record<"bold" | "italic", MarkBuilder>;
1926
+ };
1927
+
1928
+ /**
1929
+ * @internal
1930
+ */
1931
+ export declare function setupTestFromExtension<E extends Extension>(extension: E): {
1932
+ editor: TestEditor<E>;
1933
+ n: Record<ExtractNodes<E>, NodeBuilder>;
1934
+ m: Record<ExtractMarks<E>, MarkBuilder>;
1935
+ };
1936
+
1848
1937
  /**
1849
1938
  * @internal
1850
1939
  */
@@ -1885,6 +1974,21 @@ export declare type StatePayload = (ctx: {
1885
1974
  schema: Schema;
1886
1975
  }) => EditorStateConfig;
1887
1976
 
1977
+ /**
1978
+ * A JSON representation of the prosemirror step.
1979
+ *
1980
+ * @public
1981
+ */
1982
+ declare interface StepJSON {
1983
+ /**
1984
+ * The type of the step.
1985
+ */
1986
+ stepType: string;
1987
+ [x: string]: unknown;
1988
+ }
1989
+ export { StepJSON }
1990
+ export { StepJSON as StepJSON_alias_1 }
1991
+
1888
1992
  /**
1889
1993
  * Takes two facet nodes and returns a new facet node containing inputs and
1890
1994
  * children from the first node but not the second.
@@ -1943,33 +2047,53 @@ export declare type ToCommandCreators<T extends CommandTyping> = {
1943
2047
  *
1944
2048
  * @public
1945
2049
  */
1946
- declare function toggleMark({ type, attrs, }: {
1947
- type: string | MarkType;
1948
- attrs?: Attrs | null;
1949
- }): Command;
2050
+ declare function toggleMark({ type, attrs }: ToggleMarkOptions): Command;
1950
2051
  export { toggleMark }
1951
2052
  export { toggleMark as toggleMark_alias_1 }
1952
2053
 
2054
+ /**
2055
+ * @public
2056
+ */
2057
+ declare interface ToggleMarkOptions {
2058
+ type: string | MarkType;
2059
+ attrs?: Attrs | null;
2060
+ }
2061
+ export { ToggleMarkOptions }
2062
+ export { ToggleMarkOptions as ToggleMarkOptions_alias_1 }
2063
+
1953
2064
  /**
1954
2065
  * Returns a command that set the selected textblocks to the given node type
1955
2066
  * with the given attributes.
1956
2067
  *
1957
2068
  * @public
1958
2069
  */
1959
- declare function toggleNode({ type, attrs, }: {
1960
- type: string | NodeType;
1961
- attrs?: Attrs | null;
1962
- }): Command;
2070
+ declare function toggleNode({ type, attrs }: ToggleNodeOptions): Command;
1963
2071
  export { toggleNode }
1964
2072
  export { toggleNode as toggleNode_alias_1 }
1965
2073
 
2074
+ /**
2075
+ * @public
2076
+ */
2077
+ declare interface ToggleNodeOptions {
2078
+ /**
2079
+ * The type of the node to toggle.
2080
+ */
2081
+ type: string | NodeType;
2082
+ /**
2083
+ * The attributes of the node to toggle.
2084
+ */
2085
+ attrs?: Attrs | null;
2086
+ }
2087
+ export { ToggleNodeOptions }
2088
+ export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
2089
+
1966
2090
  export declare function toReversed<T>(arr: T[]): T[];
1967
2091
 
1968
2092
  declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
1969
2093
  export { TripleClickHandler }
1970
2094
  export { TripleClickHandler as TripleClickHandler_alias_1 }
1971
2095
 
1972
- declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
2096
+ declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
1973
2097
  export { TripleClickOnHandler }
1974
2098
  export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
1975
2099
 
@@ -1983,6 +2107,17 @@ export declare type Tuple5<T> = [T, T, T, T, T];
1983
2107
  *
1984
2108
  * @throws If no extensions are provided.
1985
2109
  *
2110
+ * @example
2111
+ *
2112
+ * ```ts
2113
+ * function defineFancyNodes() {
2114
+ * return union([
2115
+ * defineFancyParagraph(),
2116
+ * defineFancyHeading(),
2117
+ * ])
2118
+ * }
2119
+ * ```
2120
+ *
1986
2121
  * @public
1987
2122
  */
1988
2123
  declare function union<const E extends Extension | readonly Extension[]>(extension: E): UnionExtension<E>;
@@ -2035,6 +2170,57 @@ declare type UnmountHandler = () => void;
2035
2170
  export { UnmountHandler }
2036
2171
  export { UnmountHandler as UnmountHandler_alias_1 }
2037
2172
 
2173
+ /**
2174
+ * Returns a command that set the type of all textblocks between the given range
2175
+ * to the default type (usually `paragraph`).
2176
+ *
2177
+ * @public
2178
+ */
2179
+ declare function unsetBlockType(options?: UnsetBlockTypeOptions): Command;
2180
+ export { unsetBlockType }
2181
+ export { unsetBlockType as unsetBlockType_alias_1 }
2182
+
2183
+ /**
2184
+ * @public
2185
+ */
2186
+ declare interface UnsetBlockTypeOptions {
2187
+ /**
2188
+ * The start position of the document. By default it will be the start position of current selection.
2189
+ */
2190
+ from?: number;
2191
+ /**
2192
+ * The end position of the document. By default it will be the end position of current selection.
2193
+ */
2194
+ to?: number;
2195
+ }
2196
+ export { UnsetBlockTypeOptions }
2197
+ export { UnsetBlockTypeOptions as UnsetBlockTypeOptions_alias_1 }
2198
+
2199
+ /**
2200
+ * Returns a command that removes all marks.
2201
+ *
2202
+ * @public
2203
+ */
2204
+ declare function unsetMark(options?: UnsetMarkOptions): Command;
2205
+ export { unsetMark }
2206
+ export { unsetMark as unsetMark_alias_1 }
2207
+
2208
+ /**
2209
+ * @public
2210
+ */
2211
+ declare interface UnsetMarkOptions {
2212
+ /**
2213
+ * The start position of the document. By default it will be the start position of current selection.
2214
+ */
2215
+ from?: number;
2216
+ /**
2217
+ * The end position of the document. By default it will be the end position of current selection.
2218
+ */
2219
+ to?: number;
2220
+ }
2221
+ export { UnsetMarkOptions }
2222
+ export { UnsetMarkOptions as UnsetMarkOptions_alias_1 }
2223
+
2038
2224
  /**
2039
2225
  * A function that is called when the editor state is updated.
2040
2226
  *
@@ -2054,6 +2240,15 @@ export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
2054
2240
  export declare function voidFunction(): void;
2055
2241
 
2056
2242
  /**
2243
+ * Return an new extension with the given priority.
2244
+ *
2245
+ * @example
2246
+ * ```ts
2247
+ * import { Priority, withPriority } from 'prosekit/core'
2248
+ *
2249
+ * const extension = withPriority(defineMyExtension(), Priority.high)
2250
+ * ```
2251
+ *
2057
2252
  * @public
2058
2253
  */
2059
2254
  declare function withPriority<T extends Extension>(extension: T, priority: Priority): T;
@@ -2073,10 +2268,19 @@ export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
2073
2268
  *
2074
2269
  * @public
2075
2270
  */
2076
- export declare function wrap({ nodeType, attrs, }: {
2271
+ declare function wrap({ nodeType, attrs }: WrapOptions): Command;
2272
+ export { wrap }
2273
+ export { wrap as wrap_alias_1 }
2274
+
2275
+ /**
2276
+ * @public
2277
+ */
2278
+ declare interface WrapOptions {
2077
2279
  nodeType: NodeType;
2078
2280
  attrs?: Attrs | null;
2079
- }): Command;
2281
+ }
2282
+ export { WrapOptions }
2283
+ export { WrapOptions as WrapOptions_alias_1 }
2080
2284
 
2081
2285
  export declare function zip<T, P>(a: T[], b: P[]): [T, P][];
2082
2286
 
@@ -341,8 +341,8 @@ function nodeFromJSON(json, options) {
341
341
  return options.schema.nodeFromJSON(json);
342
342
  }
343
343
  function nodeFromElement(element, options) {
344
- let Parser = options.DOMParser || DOMParser, schema = options.schema;
345
- return Parser.fromSchema(schema).parse(element);
344
+ let { DOMParser: CustomDOMParser, schema, ...parseOptions } = options;
345
+ return (CustomDOMParser || DOMParser).fromSchema(schema).parse(element, parseOptions);
346
346
  }
347
347
  function elementFromNode(node, options) {
348
348
  let Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer, document2 = getBrowserDocument(options), schema = node.type.schema, serializer = Serializer.fromSchema(schema);
@@ -5,7 +5,7 @@ import {
5
5
  createMarkBuilders,
6
6
  createNodeBuilders,
7
7
  setupEditorExtension
8
- } from "./chunk-W4AZKLNQ.js";
8
+ } from "./chunk-YWQGKV6X.js";
9
9
 
10
10
  // src/test/test-editor.ts
11
11
  import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
@@ -1,12 +1,27 @@
1
1
  export { addMark } from './_tsup-dts-rollup';
2
+ export { AddMarkOptions } from './_tsup-dts-rollup';
2
3
  export { expandMark } from './_tsup-dts-rollup';
4
+ export { ExpandMarkOptions } from './_tsup-dts-rollup';
3
5
  export { insertNode } from './_tsup-dts-rollup';
6
+ export { InsertNodeOptions } from './_tsup-dts-rollup';
4
7
  export { removeMark } from './_tsup-dts-rollup';
8
+ export { RemoveMarkOptions } from './_tsup-dts-rollup';
5
9
  export { removeNode } from './_tsup-dts-rollup';
10
+ export { RemoveNodeOptions } from './_tsup-dts-rollup';
6
11
  export { setBlockType } from './_tsup-dts-rollup';
12
+ export { SetBlockTypeOptions } from './_tsup-dts-rollup';
7
13
  export { setNodeAttrs } from './_tsup-dts-rollup';
14
+ export { SetNodeAttrsOptions } from './_tsup-dts-rollup';
8
15
  export { toggleMark } from './_tsup-dts-rollup';
16
+ export { ToggleMarkOptions } from './_tsup-dts-rollup';
9
17
  export { toggleNode } from './_tsup-dts-rollup';
18
+ export { ToggleNodeOptions } from './_tsup-dts-rollup';
19
+ export { unsetBlockType } from './_tsup-dts-rollup';
20
+ export { UnsetBlockTypeOptions } from './_tsup-dts-rollup';
21
+ export { unsetMark } from './_tsup-dts-rollup';
22
+ export { UnsetMarkOptions } from './_tsup-dts-rollup';
23
+ export { wrap } from './_tsup-dts-rollup';
24
+ export { WrapOptions } from './_tsup-dts-rollup';
10
25
  export { MarkBuilder } from './_tsup-dts-rollup';
11
26
  export { NodeBuilder } from './_tsup-dts-rollup';
12
27
  export { Editor } from './_tsup-dts-rollup';
@@ -58,11 +73,12 @@ export { MountHandler } from './_tsup-dts-rollup';
58
73
  export { UnmountHandler } from './_tsup-dts-rollup';
59
74
  export { UpdateHandler } from './_tsup-dts-rollup';
60
75
  export { defineHistory } from './_tsup-dts-rollup';
61
- export { defineBaseKeymap } from './_tsup-dts-rollup';
76
+ export { HistoryOptions } from './_tsup-dts-rollup';
62
77
  export { defineKeymap } from './_tsup-dts-rollup';
63
78
  export { keymapFacet } from './_tsup-dts-rollup';
64
79
  export { Keymap } from './_tsup-dts-rollup';
65
80
  export { KeymapPayload } from './_tsup-dts-rollup';
81
+ export { defineBaseKeymap } from './_tsup-dts-rollup';
66
82
  export { defineMarkAttr } from './_tsup-dts-rollup';
67
83
  export { defineMarkSpec } from './_tsup-dts-rollup';
68
84
  export { MarkAttrOptions } from './_tsup-dts-rollup';
@@ -73,7 +89,9 @@ export { NodeAttrOptions } from './_tsup-dts-rollup';
73
89
  export { NodeSpecOptions } from './_tsup-dts-rollup';
74
90
  export { defineNodeView } from './_tsup-dts-rollup';
75
91
  export { NodeViewOptions } from './_tsup-dts-rollup';
92
+ export { defineNodeViewComponent } from './_tsup-dts-rollup';
76
93
  export { defineNodeViewFactory } from './_tsup-dts-rollup';
94
+ export { NodeViewComponentOptions } from './_tsup-dts-rollup';
77
95
  export { NodeViewFactoryOptions } from './_tsup-dts-rollup';
78
96
  export { defineParagraph } from './_tsup-dts-rollup';
79
97
  export { definePlugin } from './_tsup-dts-rollup';
@@ -95,16 +113,20 @@ export { UnionExtension } from './_tsup-dts-rollup';
95
113
  export { NodeJSON } from './_tsup-dts-rollup';
96
114
  export { SelectionJSON } from './_tsup-dts-rollup';
97
115
  export { StateJSON } from './_tsup-dts-rollup';
116
+ export { StepJSON } from './_tsup-dts-rollup';
98
117
  export { Priority } from './_tsup-dts-rollup';
99
118
  export { SimplifyUnion } from './_tsup-dts-rollup';
100
119
  export { assert } from './_tsup-dts-rollup';
101
120
  export { canUseRegexLookbehind } from './_tsup-dts-rollup';
102
121
  export { clsx } from './_tsup-dts-rollup';
122
+ export { collectNodes } from './_tsup-dts-rollup';
123
+ export { NodeContent } from './_tsup-dts-rollup';
103
124
  export { defaultBlockAt } from './_tsup-dts-rollup';
104
125
  export { isApple } from './_tsup-dts-rollup';
105
126
  export { _getId } from './_tsup-dts-rollup';
106
127
  export { getMarkType } from './_tsup-dts-rollup';
107
128
  export { getNodeType } from './_tsup-dts-rollup';
129
+ export { isAtBlockStart } from './_tsup-dts-rollup';
108
130
  export { isInCodeBlock } from './_tsup-dts-rollup';
109
131
  export { isMarkAbsent } from './_tsup-dts-rollup';
110
132
  export { isMarkActive } from './_tsup-dts-rollup';
@@ -35,7 +35,7 @@ import {
35
35
  stateFromJSON,
36
36
  toReversed,
37
37
  union
38
- } from "./chunk-W4AZKLNQ.js";
38
+ } from "./chunk-YWQGKV6X.js";
39
39
 
40
40
  // src/commands/add-mark.ts
41
41
  import "@prosekit/pm/model";
@@ -94,7 +94,7 @@ function insertNode(options) {
94
94
  assert(node, "You must provide either a node or a type");
95
95
  let insertPos = insertPoint(
96
96
  state.doc,
97
- (_a = options.pos) != null ? _a : state.selection.to,
97
+ (_a = options.pos) != null ? _a : state.selection.anchor,
98
98
  node.type
99
99
  );
100
100
  if (insertPos == null) return !1;
@@ -268,10 +268,7 @@ function baseToggleMark(markType, attrs = null, options) {
268
268
  return !0;
269
269
  };
270
270
  }
271
- function toggleMark({
272
- type,
273
- attrs
274
- }) {
271
+ function toggleMark({ type, attrs }) {
275
272
  return (state, dispatch, view) => baseToggleMark(getMarkType(state.schema, type), attrs, {
276
273
  removeWhenPresent: !1
277
274
  })(state, dispatch, view);
@@ -281,10 +278,7 @@ function toggleMark({
281
278
  import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
282
279
  import "@prosekit/pm/model";
283
280
  import "@prosekit/pm/state";
284
- function toggleNode({
285
- type,
286
- attrs
287
- }) {
281
+ function toggleNode({ type, attrs }) {
288
282
  return (state, dispatch, view) => {
289
283
  if (isNodeActive(state, type, attrs)) {
290
284
  let defaultType = state.schema.topNodeType.contentMatch.defaultType;
@@ -296,6 +290,63 @@ function toggleNode({
296
290
  };
297
291
  }
298
292
 
293
+ // src/commands/unset-block-type.ts
294
+ import { Fragment, Slice } from "@prosekit/pm/model";
295
+ import "@prosekit/pm/state";
296
+ import { ReplaceAroundStep } from "@prosekit/pm/transform";
297
+ function unsetBlockType(options) {
298
+ return (state, dispatch) => {
299
+ var _a, _b;
300
+ let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
301
+ if (from > to) return !1;
302
+ let tr = state.tr;
303
+ return unsetTextBlockType(tr, from, to) ? (dispatch == null || dispatch(tr), !0) : !1;
304
+ };
305
+ }
306
+ function unsetTextBlockType(tr, from, to) {
307
+ let mapFrom = tr.steps.length;
308
+ return tr.doc.nodesBetween(from, to, (node, pos, parent, index) => {
309
+ if (!parent || !node.isTextblock) return !0;
310
+ let defaultType = parent.contentMatchAt(index).defaultType;
311
+ if (defaultType && defaultType.isTextblock && node.type !== defaultType && defaultType.validContent(node.content)) {
312
+ let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos, 1), end = mapping.map(pos + node.nodeSize, 1), step = new ReplaceAroundStep(
313
+ start,
314
+ end,
315
+ start + 1,
316
+ end - 1,
317
+ new Slice(Fragment.from(defaultType.create()), 0, 0),
318
+ 1,
319
+ !0
320
+ );
321
+ tr.step(step);
322
+ }
323
+ return !1;
324
+ }), tr.steps.length > mapFrom;
325
+ }
326
+
327
+ // src/commands/unset-mark.ts
328
+ import "@prosekit/pm/state";
329
+ function unsetMark(options) {
330
+ return (state, dispatch) => {
331
+ var _a, _b;
332
+ let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
333
+ return from > to ? !1 : (dispatch == null || dispatch(state.tr.removeMark(from, to)), !0);
334
+ };
335
+ }
336
+
337
+ // src/commands/wrap.ts
338
+ import "@prosekit/pm/model";
339
+ import "@prosekit/pm/state";
340
+ import { findWrapping } from "@prosekit/pm/transform";
341
+ function wrap({ nodeType, attrs }) {
342
+ return (state, dispatch) => {
343
+ let { $from, $to } = state.selection, range = $from.blockRange($to);
344
+ if (!range) return !1;
345
+ let wrapping = findWrapping(range, nodeType, attrs);
346
+ return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1;
347
+ };
348
+ }
349
+
299
350
  // src/editor/with-priority.ts
300
351
  function withPriority(extension, priority) {
301
352
  let result = union(extension);
@@ -317,22 +368,6 @@ function selectAll() {
317
368
  return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new AllSelection(state.doc))), !0);
318
369
  }
319
370
 
320
- // src/commands/wrap.ts
321
- import "@prosekit/pm/model";
322
- import "@prosekit/pm/state";
323
- import { findWrapping } from "@prosekit/pm/transform";
324
- function wrap({
325
- nodeType,
326
- attrs
327
- }) {
328
- return (state, dispatch) => {
329
- let { $from, $to } = state.selection, range = $from.blockRange($to);
330
- if (!range) return !1;
331
- let wrapping = findWrapping(range, nodeType, attrs);
332
- return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1;
333
- };
334
- }
335
-
336
371
  // src/facets/command.ts
337
372
  var commandFacet = defineFacet({
338
373
  reducer: (inputs) => ({ commands: Object.assign({}, ...inputs) }),
@@ -341,8 +376,8 @@ var commandFacet = defineFacet({
341
376
  });
342
377
 
343
378
  // src/extensions/command.ts
344
- function defineCommands(commands) {
345
- return defineFacetPayload(commandFacet, [commands]);
379
+ function defineCommands(commands2) {
380
+ return defineFacetPayload(commandFacet, [commands2]);
346
381
  }
347
382
  function defineBaseCommands() {
348
383
  return defineCommands({
@@ -354,7 +389,9 @@ function defineBaseCommands() {
354
389
  setNodeAttrs,
355
390
  selectAll,
356
391
  addMark,
357
- removeMark
392
+ removeMark,
393
+ unsetBlockType,
394
+ unsetMark
358
395
  });
359
396
  }
360
397
 
@@ -584,7 +621,7 @@ function defineDOMEventHandler(event, handler) {
584
621
  }
585
622
  var domEventFacet = defineFacet({
586
623
  reduce: () => {
587
- let setHandlersMap = {}, combinedHandlerMap = {}, plugin = null, update = (payloads) => {
624
+ let setHandlersMap = {}, combinedHandlerMap = {}, plugin, update = (payloads) => {
588
625
  var _a;
589
626
  let hasNewEvent = !1;
590
627
  for (let [event] of payloads)
@@ -699,36 +736,15 @@ import { history, redo, undo } from "@prosekit/pm/history";
699
736
  var isApple = typeof navigator != "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : !1;
700
737
 
701
738
  // src/extensions/keymap.ts
702
- import {
703
- baseKeymap,
704
- chainCommands,
705
- createParagraphNear,
706
- liftEmptyBlock,
707
- newlineInCode
708
- } from "@prosekit/pm/commands";
739
+ import { chainCommands } from "@prosekit/pm/commands";
709
740
  import { keydownHandler } from "@prosekit/pm/keymap";
710
741
  import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state";
711
- import { splitSplittableBlock } from "prosemirror-splittable";
712
- var customBaseKeymap = {
713
- ...baseKeymap,
714
- Enter: chainCommands(
715
- newlineInCode,
716
- createParagraphNear,
717
- liftEmptyBlock,
718
- splitSplittableBlock
719
- )
720
- };
721
- function defineKeymap(keymap) {
722
- return defineFacetPayload(keymapFacet, [keymap]);
723
- }
724
- function defineBaseKeymap(options) {
725
- var _a;
726
- let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
727
- return withPriority(defineKeymap(customBaseKeymap), priority);
742
+ function defineKeymap(keymap2) {
743
+ return defineFacetPayload(keymapFacet, [keymap2]);
728
744
  }
729
745
  var keymapFacet = defineFacet({
730
746
  reduce: () => {
731
- let handler = null, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin2({
747
+ let handler, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin2({
732
748
  key: keymapPluginKey,
733
749
  props: { handleKeyDown: handlerWrapper }
734
750
  });
@@ -744,34 +760,71 @@ var keymapFacet = defineFacet({
744
760
  });
745
761
  function mergeKeymaps(keymaps) {
746
762
  let bindings = {};
747
- for (let keymap of keymaps)
748
- for (let [key, command] of Object.entries(keymap))
763
+ for (let keymap2 of keymaps)
764
+ for (let [key, command] of Object.entries(keymap2))
749
765
  (bindings[key] || (bindings[key] = [])).push(command);
750
766
  return Object.fromEntries(
751
- Object.entries(bindings).map(([key, commands]) => [
767
+ Object.entries(bindings).map(([key, commands2]) => [
752
768
  key,
753
- chainCommands(...commands)
769
+ chainCommands(...commands2)
754
770
  ])
755
771
  );
756
772
  }
757
773
  var keymapPluginKey = new PluginKey4("prosekit-keymap");
758
774
 
759
775
  // src/extensions/history.ts
760
- function defineHistory() {
761
- let keymap = {
762
- "Mod-z": undo,
763
- "Shift-Mod-z": redo
764
- };
765
- return isApple || (keymap["Mod-y"] = redo), union([
766
- definePlugin(history()),
776
+ var keymap = {
777
+ "Mod-z": undo,
778
+ "Shift-Mod-z": redo
779
+ };
780
+ isApple || (keymap["Mod-y"] = redo);
781
+ var commands = {
782
+ undo: () => undo,
783
+ redo: () => redo
784
+ };
785
+ function defineHistory({
786
+ depth = 200,
787
+ newGroupDelay = 250
788
+ } = {}) {
789
+ return union([
790
+ definePlugin(history({ depth, newGroupDelay })),
767
791
  defineKeymap(keymap),
768
- defineCommands({
769
- undo: () => undo,
770
- redo: () => redo
771
- })
792
+ defineCommands(commands)
772
793
  ]);
773
794
  }
774
795
 
796
+ // src/extensions/keymap-base.ts
797
+ import {
798
+ baseKeymap,
799
+ chainCommands as chainCommands2,
800
+ createParagraphNear,
801
+ deleteSelection,
802
+ joinTextblockBackward,
803
+ liftEmptyBlock,
804
+ newlineInCode,
805
+ selectNodeBackward
806
+ } from "@prosekit/pm/commands";
807
+ import { splitSplittableBlock } from "prosemirror-splittable";
808
+ var customEnter = chainCommands2(
809
+ newlineInCode,
810
+ createParagraphNear,
811
+ liftEmptyBlock,
812
+ splitSplittableBlock
813
+ ), customBackspace = chainCommands2(
814
+ deleteSelection,
815
+ joinTextblockBackward,
816
+ selectNodeBackward
817
+ ), customBaseKeymap = {
818
+ ...baseKeymap,
819
+ Enter: customEnter,
820
+ Backspace: customBackspace
821
+ };
822
+ function defineBaseKeymap(options) {
823
+ var _a;
824
+ let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
825
+ return withPriority(defineKeymap(customBaseKeymap), priority);
826
+ }
827
+
775
828
  // src/extensions/mark-spec.ts
776
829
  function defineMarkSpec(options) {
777
830
  return defineFacetPayload(markSpecFacet, [[options, void 0]]);
@@ -859,22 +912,17 @@ var nodeViewFacet = defineFacet({
859
912
  import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
860
913
  import "@prosekit/pm/view";
861
914
  function defineNodeViewFactory(options) {
862
- return defineFacetPayload(nodeViewFactoryFacet, [options]);
915
+ return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]);
916
+ }
917
+ function defineNodeViewComponent(options) {
918
+ return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]);
863
919
  }
864
920
  var nodeViewFactoryFacet = defineFacet({
865
921
  reducer: (inputs) => {
866
- let nodeViews = {}, options = {}, factories = {};
867
- for (let input of inputs) {
868
- let group = input.group;
869
- input.name == null ? factories[group] = input.factory : (options[group] || (options[group] = []), options[group].push({
870
- name: input.name,
871
- args: input.args
872
- }));
873
- }
874
- for (let [group, factory] of Object.entries(factories)) {
875
- let groupOptions = options[group] || [];
876
- for (let { name, args } of groupOptions)
877
- nodeViews[name] = factory(args);
922
+ let nodeViews = {}, factories = inputs.map((x) => x[0]).filter(isNotNull), options = inputs.map((x) => x[1]).filter(isNotNull);
923
+ for (let { group, name, args } of options) {
924
+ let factory = factories.find((factory2) => factory2.group === group);
925
+ factory && (nodeViews[name] = factory.factory(args));
878
926
  }
879
927
  return () => [
880
928
  new ProseMirrorPlugin6({
@@ -929,6 +977,22 @@ var canUseRegexLookbehind = cache(() => {
929
977
  import clsxLite from "clsx/lite";
930
978
  var clsx = clsxLite;
931
979
 
980
+ // src/utils/collect-nodes.ts
981
+ import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
982
+ function collectNodes(content) {
983
+ if (Array.isArray(content))
984
+ return content.flatMap(collectNodes);
985
+ if (content instanceof ProseMirrorNode2)
986
+ return [content];
987
+ if (content instanceof ProseMirrorFragment) {
988
+ let nodes = [];
989
+ for (let i = 0; i < content.childCount; i++)
990
+ nodes.push(content.child(i));
991
+ return nodes;
992
+ }
993
+ throw new ProseKitError(`Invalid node content: ${typeof content}`);
994
+ }
995
+
932
996
  // src/utils/default-block-at.ts
933
997
  function defaultBlockAt(match) {
934
998
  for (let i = 0; i < match.edgeCount; i++) {
@@ -944,6 +1008,12 @@ function getId() {
944
1008
  return id = (id + 1) % Number.MAX_SAFE_INTEGER, `id:${id}`;
945
1009
  }
946
1010
 
1011
+ // src/utils/is-at-block-start.ts
1012
+ function isAtBlockStart(state, view) {
1013
+ let { $cursor } = state.selection;
1014
+ return !$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0) ? null : $cursor;
1015
+ }
1016
+
947
1017
  // src/utils/is-in-code-block.ts
948
1018
  function isCodeBlockType(type) {
949
1019
  return type.spec.code && type.isBlock;
@@ -975,6 +1045,7 @@ export {
975
1045
  assert,
976
1046
  canUseRegexLookbehind,
977
1047
  clsx,
1048
+ collectNodes,
978
1049
  createEditor,
979
1050
  defaultBlockAt,
980
1051
  defineBaseCommands,
@@ -1002,6 +1073,7 @@ export {
1002
1073
  defineNodeAttr,
1003
1074
  defineNodeSpec,
1004
1075
  defineNodeView,
1076
+ defineNodeViewComponent,
1005
1077
  defineNodeViewFactory,
1006
1078
  defineParagraph,
1007
1079
  definePasteHandler,
@@ -1023,6 +1095,7 @@ export {
1023
1095
  insertNode,
1024
1096
  isAllSelection,
1025
1097
  isApple,
1098
+ isAtBlockStart,
1026
1099
  isInCodeBlock,
1027
1100
  isMark,
1028
1101
  isMarkAbsent,
@@ -1047,6 +1120,9 @@ export {
1047
1120
  toggleMark,
1048
1121
  toggleNode,
1049
1122
  union,
1123
+ unsetBlockType,
1124
+ unsetMark,
1050
1125
  withPriority,
1051
- withSkipCodeBlock
1126
+ withSkipCodeBlock,
1127
+ wrap
1052
1128
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.0-next-20240626133927",
4
+ "version": "0.0.0-next-20240715024943",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -43,13 +43,13 @@
43
43
  "clsx": "^2.1.1",
44
44
  "orderedmap": "^2.1.1",
45
45
  "prosemirror-splittable": "^0.1.1",
46
- "type-fest": "^4.20.1",
47
- "@prosekit/pm": "^0.0.0-next-20240626133927"
46
+ "type-fest": "^4.21.0",
47
+ "@prosekit/pm": "^0.0.0-next-20240715024943"
48
48
  },
49
49
  "devDependencies": {
50
50
  "tsup": "^8.1.0",
51
- "typescript": "^5.5.2",
52
- "vitest": "^2.0.0-beta.12",
51
+ "typescript": "^5.5.3",
52
+ "vitest": "^2.0.2",
53
53
  "@prosekit/dev": "0.0.0"
54
54
  },
55
55
  "scripts": {