@prosekit/core 0.7.0 → 0.7.2

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';
@@ -50,7 +47,14 @@ declare type Action = (options: {
50
47
  *
51
48
  * @public
52
49
  */
53
- 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 {
54
58
  /**
55
59
  * The type of the mark to add.
56
60
  */
@@ -67,9 +71,9 @@ declare function addMark(options: {
67
71
  * The end position of the document. By default it will be the end position of current selection.
68
72
  */
69
73
  to?: number;
70
- }): Command;
71
- export { addMark }
72
- export { addMark as addMark_alias_1 }
74
+ }
75
+ export { AddMarkOptions }
76
+ export { AddMarkOptions as AddMarkOptions_alias_1 }
73
77
 
74
78
  export declare function applyAction(operator: Action): Command;
75
79
 
@@ -169,7 +173,7 @@ declare type ClickHandler = (view: EditorView, pos: number, event: MouseEvent) =
169
173
  export { ClickHandler }
170
174
  export { ClickHandler as ClickHandler_alias_1 }
171
175
 
172
- 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;
173
177
  export { ClickOnHandler }
174
178
  export { ClickOnHandler as ClickOnHandler_alias_1 }
175
179
 
@@ -295,49 +299,16 @@ declare function defineBaseCommands(): Extension<{
295
299
  from?: number;
296
300
  to?: number;
297
301
  }];
298
- insertNode: [options: {
299
- node: Node_2;
300
- pos?: number;
301
- type?: undefined;
302
- attrs?: undefined;
303
- } | {
304
- node?: undefined;
305
- pos?: number;
306
- type: string;
307
- attrs?: Attrs_2;
308
- }];
309
- removeNode: [options: {
310
- type: string | NodeType_2;
311
- pos?: number;
312
- }];
313
- wrap: [{
314
- nodeType: NodeType_2;
315
- attrs?: Attrs_2 | null;
316
- }];
317
- setBlockType: [options: {
318
- type: NodeType_2 | string;
319
- attrs?: Attrs_2 | null;
320
- from?: number;
321
- to?: number;
322
- }];
323
- setNodeAttrs: [options: {
324
- type: string | NodeType_2 | string[] | NodeType_2[];
325
- attrs: Attrs_2;
326
- pos?: number;
327
- }];
302
+ insertNode: [options: InsertNodeOptions];
303
+ removeNode: [options: RemoveNodeOptions];
304
+ wrap: [WrapOptions];
305
+ setBlockType: [options: SetBlockTypeOptions];
306
+ setNodeAttrs: [options: SetNodeAttrsOptions];
328
307
  selectAll: [];
329
- addMark: [options: {
330
- type: string | MarkType_2;
331
- attrs?: Attrs_2 | null;
332
- from?: number;
333
- to?: number;
334
- }];
335
- removeMark: [options: {
336
- type: string | MarkType_2;
337
- attrs?: Attrs_2 | null;
338
- from?: number;
339
- to?: number;
340
- }];
308
+ addMark: [options: AddMarkOptions];
309
+ removeMark: [options: RemoveMarkOptions];
310
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
311
+ unsetMark: [options?: UnsetMarkOptions | undefined];
341
312
  };
342
313
  Nodes: never;
343
314
  Marks: never;
@@ -584,6 +555,13 @@ declare function defineNodeView(options: NodeViewOptions): Extension;
584
555
  export { defineNodeView }
585
556
  export { defineNodeView as defineNodeView_alias_1 }
586
557
 
558
+ /**
559
+ * @internal
560
+ */
561
+ declare function defineNodeViewComponent<T>(options: NodeViewComponentOptions<T>): Extension;
562
+ export { defineNodeViewComponent }
563
+ export { defineNodeViewComponent as defineNodeViewComponent_alias_1 }
564
+
587
565
  /**
588
566
  * @internal
589
567
  */
@@ -650,61 +628,28 @@ export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_
650
628
  /**
651
629
  * @internal
652
630
  */
653
- export declare function defineTestExtension(): Extension< {
654
- Nodes: "text" | "doc" | "paragraph";
655
- Marks: "bold";
656
- Commands: {
657
- undo: [];
658
- redo: [];
659
- insertText: [{
660
- text: string;
661
- from?: number;
662
- to?: number;
663
- }];
664
- insertNode: [options: {
665
- node: Node_2;
666
- pos?: number;
667
- type?: undefined;
668
- attrs?: undefined;
669
- } | {
670
- node?: undefined;
671
- pos?: number;
672
- type: string;
673
- attrs?: Attrs_2;
674
- }];
675
- removeNode: [options: {
676
- type: string | NodeType_2;
677
- pos?: number;
678
- }];
679
- wrap: [{
680
- nodeType: NodeType_2;
681
- attrs?: Attrs_2 | null;
682
- }];
683
- setBlockType: [options: {
684
- type: NodeType_2 | string;
685
- attrs?: Attrs_2 | null;
686
- from?: number;
687
- to?: number;
688
- }];
689
- setNodeAttrs: [options: {
690
- type: string | NodeType_2 | string[] | NodeType_2[];
691
- attrs: Attrs_2;
692
- pos?: number;
693
- }];
694
- selectAll: [];
695
- addMark: [options: {
696
- type: string | MarkType_2;
697
- attrs?: Attrs_2 | null;
698
- from?: number;
699
- to?: number;
700
- }];
701
- removeMark: [options: {
702
- type: string | MarkType_2;
703
- attrs?: Attrs_2 | null;
704
- from?: number;
705
- to?: number;
706
- }];
707
- };
631
+ export declare function defineTestExtension(): Extension<{
632
+ Nodes: "text" | "doc" | "paragraph" | "heading";
633
+ Marks: "bold" | "italic";
634
+ Commands: {
635
+ insertText: [{
636
+ text: string;
637
+ from?: number;
638
+ to?: number;
639
+ }];
640
+ insertNode: [options: InsertNodeOptions];
641
+ removeNode: [options: RemoveNodeOptions];
642
+ wrap: [WrapOptions];
643
+ setBlockType: [options: SetBlockTypeOptions];
644
+ setNodeAttrs: [options: SetNodeAttrsOptions];
645
+ selectAll: [];
646
+ addMark: [options: AddMarkOptions];
647
+ removeMark: [options: RemoveMarkOptions];
648
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
649
+ unsetMark: [options?: UnsetMarkOptions | undefined];
650
+ undo: [];
651
+ redo: [];
652
+ };
708
653
  }>;
709
654
 
710
655
  /**
@@ -831,7 +776,7 @@ declare type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEv
831
776
  export { DoubleClickHandler }
832
777
  export { DoubleClickHandler as DoubleClickHandler_alias_1 }
833
778
 
834
- declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
779
+ declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
835
780
  export { DoubleClickOnHandler }
836
781
  export { DoubleClickOnHandler as DoubleClickOnHandler_alias_1 }
837
782
 
@@ -1005,14 +950,21 @@ export { elementFromNode as elementFromNode_alias_1 }
1005
950
  *
1006
951
  * @public
1007
952
  */
1008
- declare function expandMark(options: {
953
+ declare function expandMark(options: ExpandMarkOptions): Command;
954
+ export { expandMark }
955
+ export { expandMark as expandMark_alias_1 }
956
+
957
+ /**
958
+ * @public
959
+ */
960
+ declare interface ExpandMarkOptions {
1009
961
  /**
1010
962
  * The type of the mark to expand.
1011
963
  */
1012
964
  type: string | MarkType;
1013
- }): Command;
1014
- export { expandMark }
1015
- export { expandMark as expandMark_alias_1 }
965
+ }
966
+ export { ExpandMarkOptions }
967
+ export { ExpandMarkOptions as ExpandMarkOptions_alias_1 }
1016
968
 
1017
969
  /**
1018
970
  * @public
@@ -1248,17 +1200,7 @@ export { htmlFromNode as htmlFromNode_alias_1 }
1248
1200
  *
1249
1201
  * @public
1250
1202
  */
1251
- declare function insertNode(options: {
1252
- node: ProseMirrorNode;
1253
- pos?: number;
1254
- type?: undefined;
1255
- attrs?: undefined;
1256
- } | {
1257
- node?: undefined;
1258
- pos?: number;
1259
- type: string;
1260
- attrs?: Attrs;
1261
- }): Command;
1203
+ declare function insertNode(options: InsertNodeOptions): Command;
1262
1204
  export { insertNode }
1263
1205
  export { insertNode as insertNode_alias_1 }
1264
1206
 
@@ -1267,6 +1209,31 @@ export declare function insertNodeAction({ node, pos, }: {
1267
1209
  pos?: number;
1268
1210
  }): Action;
1269
1211
 
1212
+ /**
1213
+ * @public
1214
+ */
1215
+ declare interface InsertNodeOptions {
1216
+ /**
1217
+ * The node to insert. Either this or `type` must be provided.
1218
+ */
1219
+ node?: ProseMirrorNode;
1220
+ /**
1221
+ * The type of the node to insert. Either this or `node` must be provided.
1222
+ */
1223
+ type?: string | NodeType;
1224
+ /**
1225
+ * When `type` is provided, the attributes of the node to insert.
1226
+ */
1227
+ attrs?: Attrs;
1228
+ /**
1229
+ * The position to insert the node at. By default it will be the anchor
1230
+ * position of current selection.
1231
+ */
1232
+ pos?: number;
1233
+ }
1234
+ export { InsertNodeOptions }
1235
+ export { InsertNodeOptions as InsertNodeOptions_alias_1 }
1236
+
1270
1237
  /**
1271
1238
  * Returns a command that inserts the given text.
1272
1239
  *
@@ -1292,6 +1259,15 @@ declare const isApple: boolean;
1292
1259
  export { isApple }
1293
1260
  export { isApple as isApple_alias_1 }
1294
1261
 
1262
+ /**
1263
+ * Whether the selection is an empty text selection at the start of a block.
1264
+ *
1265
+ * @internal
1266
+ */
1267
+ declare function isAtBlockStart(state: EditorState, view?: EditorView): ResolvedPos | null;
1268
+ export { isAtBlockStart }
1269
+ export { isAtBlockStart as isAtBlockStart_alias_1 }
1270
+
1295
1271
  export declare function isElement(value: unknown): value is Element;
1296
1272
 
1297
1273
  /**
@@ -1611,13 +1587,19 @@ export { NodeSpecOptions as NodeSpecOptions_alias_1 }
1611
1587
  /**
1612
1588
  * @internal
1613
1589
  */
1614
- declare type NodeViewFactoryOptions<T> = {
1590
+ declare type NodeViewComponentOptions<T> = {
1615
1591
  group: string;
1616
1592
  name: string;
1617
1593
  args: T;
1618
- } | {
1594
+ };
1595
+ export { NodeViewComponentOptions }
1596
+ export { NodeViewComponentOptions as NodeViewComponentOptions_alias_1 }
1597
+
1598
+ /**
1599
+ * @internal
1600
+ */
1601
+ declare type NodeViewFactoryOptions<T> = {
1619
1602
  group: string;
1620
- name?: undefined;
1621
1603
  factory: (args: T) => NodeViewConstructor;
1622
1604
  };
1623
1605
  export { NodeViewFactoryOptions }
@@ -1721,7 +1703,14 @@ export { ProseKitError as ProseKitError_alias_1 }
1721
1703
  *
1722
1704
  * @public
1723
1705
  */
1724
- declare function removeMark(options: {
1706
+ declare function removeMark(options: RemoveMarkOptions): Command;
1707
+ export { removeMark }
1708
+ export { removeMark as removeMark_alias_1 }
1709
+
1710
+ /**
1711
+ * @public
1712
+ */
1713
+ declare interface RemoveMarkOptions {
1725
1714
  /**
1726
1715
  * The type of the mark to remove.
1727
1716
  */
@@ -1738,16 +1727,23 @@ declare function removeMark(options: {
1738
1727
  * The end position of the document. By default it will be the end position of current selection.
1739
1728
  */
1740
1729
  to?: number;
1741
- }): Command;
1742
- export { removeMark }
1743
- export { removeMark as removeMark_alias_1 }
1730
+ }
1731
+ export { RemoveMarkOptions }
1732
+ export { RemoveMarkOptions as RemoveMarkOptions_alias_1 }
1744
1733
 
1745
1734
  /**
1746
1735
  * Returns a command to remove the nearest ancestor node of a specific type from the current position.
1747
1736
  *
1748
1737
  * @public
1749
1738
  */
1750
- declare function removeNode(options: {
1739
+ declare function removeNode(options: RemoveNodeOptions): Command;
1740
+ export { removeNode }
1741
+ export { removeNode as removeNode_alias_1 }
1742
+
1743
+ /**
1744
+ * @public
1745
+ */
1746
+ declare interface RemoveNodeOptions {
1751
1747
  /**
1752
1748
  * The type of the node to remove.
1753
1749
  */
@@ -1756,9 +1752,9 @@ declare function removeNode(options: {
1756
1752
  * The document position to start searching node. By default it will be the anchor position of current selection.
1757
1753
  */
1758
1754
  pos?: number;
1759
- }): Command;
1760
- export { removeNode }
1761
- export { removeNode as removeNode_alias_1 }
1755
+ }
1756
+ export { RemoveNodeOptions }
1757
+ export { RemoveNodeOptions as RemoveNodeOptions_alias_1 }
1762
1758
 
1763
1759
  export declare const rootFacet: Facet<RootPayload, RootOutput>;
1764
1760
 
@@ -1812,21 +1808,35 @@ export { SelectionJSON as SelectionJSON_alias_1 }
1812
1808
  *
1813
1809
  * @public
1814
1810
  */
1815
- declare function setBlockType(options: {
1811
+ declare function setBlockType(options: SetBlockTypeOptions): Command;
1812
+ export { setBlockType }
1813
+ export { setBlockType as setBlockType_alias_1 }
1814
+
1815
+ /**
1816
+ * @public
1817
+ */
1818
+ declare interface SetBlockTypeOptions {
1816
1819
  type: NodeType | string;
1817
1820
  attrs?: Attrs | null;
1818
1821
  from?: number;
1819
1822
  to?: number;
1820
- }): Command;
1821
- export { setBlockType }
1822
- export { setBlockType as setBlockType_alias_1 }
1823
+ }
1824
+ export { SetBlockTypeOptions }
1825
+ export { SetBlockTypeOptions as SetBlockTypeOptions_alias_1 }
1823
1826
 
1824
1827
  /**
1825
1828
  * Returns a command that set the attributes of the current node.
1826
1829
  *
1827
1830
  * @public
1828
1831
  */
1829
- declare function setNodeAttrs(options: {
1832
+ declare function setNodeAttrs(options: SetNodeAttrsOptions): Command;
1833
+ export { setNodeAttrs }
1834
+ export { setNodeAttrs as setNodeAttrs_alias_1 }
1835
+
1836
+ /**
1837
+ * @public
1838
+ */
1839
+ declare interface SetNodeAttrsOptions {
1830
1840
  /**
1831
1841
  * The type of node to set the attributes of.
1832
1842
  *
@@ -1842,9 +1852,9 @@ declare function setNodeAttrs(options: {
1842
1852
  * containing the current selection.
1843
1853
  */
1844
1854
  pos?: number;
1845
- }): Command;
1846
- export { setNodeAttrs }
1847
- export { setNodeAttrs as setNodeAttrs_alias_1 }
1855
+ }
1856
+ export { SetNodeAttrsOptions }
1857
+ export { SetNodeAttrsOptions as SetNodeAttrsOptions_alias_1 }
1848
1858
 
1849
1859
  export declare function setSelectionAround(tr: Transaction, pos: number): void;
1850
1860
 
@@ -1858,6 +1868,46 @@ export declare type Setter<T> = (value: T) => void;
1858
1868
  */
1859
1869
  export declare function setupEditorExtension<E extends Extension>(options: EditorOptions<E>): E;
1860
1870
 
1871
+ /**
1872
+ * @internal
1873
+ */
1874
+ export declare function setupTest(): {
1875
+ editor: TestEditor<Extension<{
1876
+ Nodes: "text" | "doc" | "paragraph" | "heading";
1877
+ Marks: "bold" | "italic";
1878
+ Commands: {
1879
+ insertText: [{
1880
+ text: string;
1881
+ from?: number;
1882
+ to?: number;
1883
+ }];
1884
+ insertNode: [options: InsertNodeOptions];
1885
+ removeNode: [options: RemoveNodeOptions];
1886
+ wrap: [WrapOptions];
1887
+ setBlockType: [options: SetBlockTypeOptions];
1888
+ setNodeAttrs: [options: SetNodeAttrsOptions];
1889
+ selectAll: [];
1890
+ addMark: [options: AddMarkOptions];
1891
+ removeMark: [options: RemoveMarkOptions];
1892
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
1893
+ unsetMark: [options?: UnsetMarkOptions | undefined];
1894
+ undo: [];
1895
+ redo: [];
1896
+ };
1897
+ }>>;
1898
+ n: Record<"text" | "doc" | "paragraph" | "heading", NodeBuilder>;
1899
+ m: Record<"bold" | "italic", MarkBuilder>;
1900
+ };
1901
+
1902
+ /**
1903
+ * @internal
1904
+ */
1905
+ export declare function setupTestFromExtension<E extends Extension>(extension: E): {
1906
+ editor: TestEditor<E>;
1907
+ n: Record<ExtractNodes<E>, NodeBuilder>;
1908
+ m: Record<ExtractMarks<E>, MarkBuilder>;
1909
+ };
1910
+
1861
1911
  /**
1862
1912
  * @internal
1863
1913
  */
@@ -1971,33 +2021,53 @@ export declare type ToCommandCreators<T extends CommandTyping> = {
1971
2021
  *
1972
2022
  * @public
1973
2023
  */
1974
- declare function toggleMark({ type, attrs, }: {
1975
- type: string | MarkType;
1976
- attrs?: Attrs | null;
1977
- }): Command;
2024
+ declare function toggleMark({ type, attrs }: ToggleMarkOptions): Command;
1978
2025
  export { toggleMark }
1979
2026
  export { toggleMark as toggleMark_alias_1 }
1980
2027
 
2028
+ /**
2029
+ * @public
2030
+ */
2031
+ declare interface ToggleMarkOptions {
2032
+ type: string | MarkType;
2033
+ attrs?: Attrs | null;
2034
+ }
2035
+ export { ToggleMarkOptions }
2036
+ export { ToggleMarkOptions as ToggleMarkOptions_alias_1 }
2037
+
1981
2038
  /**
1982
2039
  * Returns a command that set the selected textblocks to the given node type
1983
2040
  * with the given attributes.
1984
2041
  *
1985
2042
  * @public
1986
2043
  */
1987
- declare function toggleNode({ type, attrs, }: {
1988
- type: string | NodeType;
1989
- attrs?: Attrs | null;
1990
- }): Command;
2044
+ declare function toggleNode({ type, attrs }: ToggleNodeOptions): Command;
1991
2045
  export { toggleNode }
1992
2046
  export { toggleNode as toggleNode_alias_1 }
1993
2047
 
2048
+ /**
2049
+ * @public
2050
+ */
2051
+ declare interface ToggleNodeOptions {
2052
+ /**
2053
+ * The type of the node to toggle.
2054
+ */
2055
+ type: string | NodeType;
2056
+ /**
2057
+ * The attributes of the node to toggle.
2058
+ */
2059
+ attrs?: Attrs | null;
2060
+ }
2061
+ export { ToggleNodeOptions }
2062
+ export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
2063
+
1994
2064
  export declare function toReversed<T>(arr: T[]): T[];
1995
2065
 
1996
2066
  declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
1997
2067
  export { TripleClickHandler }
1998
2068
  export { TripleClickHandler as TripleClickHandler_alias_1 }
1999
2069
 
2000
- declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_3, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
2070
+ declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
2001
2071
  export { TripleClickOnHandler }
2002
2072
  export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
2003
2073
 
@@ -2074,6 +2144,57 @@ declare type UnmountHandler = () => void;
2074
2144
  export { UnmountHandler }
2075
2145
  export { UnmountHandler as UnmountHandler_alias_1 }
2076
2146
 
2147
+ /**
2148
+ * Returns a command that set the type of all textblocks between the given range
2149
+ * to the default type (usually `paragraph`).
2150
+ *
2151
+ * @public
2152
+ */
2153
+ declare function unsetBlockType(options?: UnsetBlockTypeOptions): Command;
2154
+ export { unsetBlockType }
2155
+ export { unsetBlockType as unsetBlockType_alias_1 }
2156
+
2157
+ /**
2158
+ * @public
2159
+ */
2160
+ declare interface UnsetBlockTypeOptions {
2161
+ /**
2162
+ * The start position of the document. By default it will be the start position of current selection.
2163
+ */
2164
+ from?: number;
2165
+ /**
2166
+ * The end position of the document. By default it will be the end position of current selection.
2167
+ */
2168
+ to?: number;
2169
+ }
2170
+ export { UnsetBlockTypeOptions }
2171
+ export { UnsetBlockTypeOptions as UnsetBlockTypeOptions_alias_1 }
2172
+
2173
+ /**
2174
+ * Returns a command that removes all marks.
2175
+ *
2176
+ * @public
2177
+ */
2178
+ declare function unsetMark(options?: UnsetMarkOptions): Command;
2179
+ export { unsetMark }
2180
+ export { unsetMark as unsetMark_alias_1 }
2181
+
2182
+ /**
2183
+ * @public
2184
+ */
2185
+ declare interface UnsetMarkOptions {
2186
+ /**
2187
+ * The start position of the document. By default it will be the start position of current selection.
2188
+ */
2189
+ from?: number;
2190
+ /**
2191
+ * The end position of the document. By default it will be the end position of current selection.
2192
+ */
2193
+ to?: number;
2194
+ }
2195
+ export { UnsetMarkOptions }
2196
+ export { UnsetMarkOptions as UnsetMarkOptions_alias_1 }
2197
+
2077
2198
  /**
2078
2199
  * A function that is called when the editor state is updated.
2079
2200
  *
@@ -2121,10 +2242,19 @@ export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
2121
2242
  *
2122
2243
  * @public
2123
2244
  */
2124
- export declare function wrap({ nodeType, attrs, }: {
2245
+ declare function wrap({ nodeType, attrs }: WrapOptions): Command;
2246
+ export { wrap }
2247
+ export { wrap as wrap_alias_1 }
2248
+
2249
+ /**
2250
+ * @public
2251
+ */
2252
+ declare interface WrapOptions {
2125
2253
  nodeType: NodeType;
2126
2254
  attrs?: Attrs | null;
2127
- }): Command;
2255
+ }
2256
+ export { WrapOptions }
2257
+ export { WrapOptions as WrapOptions_alias_1 }
2128
2258
 
2129
2259
  export declare function zip<T, P>(a: T[], b: P[]): [T, P][];
2130
2260
 
@@ -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';
@@ -18,8 +33,6 @@ export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-
18
33
  export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
19
34
  export { defineBaseCommands } from './_tsup-dts-rollup';
20
35
  export { defineCommands } from './_tsup-dts-rollup';
21
- export { collectNodes } from './_tsup-dts-rollup';
22
- export { NodeContent } from './_tsup-dts-rollup';
23
36
  export { defineDefaultState } from './_tsup-dts-rollup';
24
37
  export { DefaultStateOptions } from './_tsup-dts-rollup';
25
38
  export { defineDoc } from './_tsup-dts-rollup';
@@ -60,11 +73,11 @@ export { MountHandler } from './_tsup-dts-rollup';
60
73
  export { UnmountHandler } from './_tsup-dts-rollup';
61
74
  export { UpdateHandler } from './_tsup-dts-rollup';
62
75
  export { defineHistory } from './_tsup-dts-rollup';
63
- export { defineBaseKeymap } from './_tsup-dts-rollup';
64
76
  export { defineKeymap } from './_tsup-dts-rollup';
65
77
  export { keymapFacet } from './_tsup-dts-rollup';
66
78
  export { Keymap } from './_tsup-dts-rollup';
67
79
  export { KeymapPayload } from './_tsup-dts-rollup';
80
+ export { defineBaseKeymap } from './_tsup-dts-rollup';
68
81
  export { defineMarkAttr } from './_tsup-dts-rollup';
69
82
  export { defineMarkSpec } from './_tsup-dts-rollup';
70
83
  export { MarkAttrOptions } from './_tsup-dts-rollup';
@@ -75,7 +88,9 @@ export { NodeAttrOptions } from './_tsup-dts-rollup';
75
88
  export { NodeSpecOptions } from './_tsup-dts-rollup';
76
89
  export { defineNodeView } from './_tsup-dts-rollup';
77
90
  export { NodeViewOptions } from './_tsup-dts-rollup';
91
+ export { defineNodeViewComponent } from './_tsup-dts-rollup';
78
92
  export { defineNodeViewFactory } from './_tsup-dts-rollup';
93
+ export { NodeViewComponentOptions } from './_tsup-dts-rollup';
79
94
  export { NodeViewFactoryOptions } from './_tsup-dts-rollup';
80
95
  export { defineParagraph } from './_tsup-dts-rollup';
81
96
  export { definePlugin } from './_tsup-dts-rollup';
@@ -103,11 +118,14 @@ export { SimplifyUnion } from './_tsup-dts-rollup';
103
118
  export { assert } from './_tsup-dts-rollup';
104
119
  export { canUseRegexLookbehind } from './_tsup-dts-rollup';
105
120
  export { clsx } from './_tsup-dts-rollup';
121
+ export { collectNodes } from './_tsup-dts-rollup';
122
+ export { NodeContent } from './_tsup-dts-rollup';
106
123
  export { defaultBlockAt } from './_tsup-dts-rollup';
107
124
  export { isApple } from './_tsup-dts-rollup';
108
125
  export { _getId } from './_tsup-dts-rollup';
109
126
  export { getMarkType } from './_tsup-dts-rollup';
110
127
  export { getNodeType } from './_tsup-dts-rollup';
128
+ export { isAtBlockStart } from './_tsup-dts-rollup';
111
129
  export { isInCodeBlock } from './_tsup-dts-rollup';
112
130
  export { isMarkAbsent } from './_tsup-dts-rollup';
113
131
  export { isMarkActive } from './_tsup-dts-rollup';
@@ -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) }),
@@ -354,26 +389,12 @@ 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
 
361
- // src/utils/collect-nodes.ts
362
- import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
363
- function collectNodes(content) {
364
- if (Array.isArray(content))
365
- return content.flatMap(collectNodes);
366
- if (content instanceof ProseMirrorNode2)
367
- return [content];
368
- if (content instanceof ProseMirrorFragment) {
369
- let nodes = [];
370
- for (let i = 0; i < content.childCount; i++)
371
- nodes.push(content.child(i));
372
- return nodes;
373
- }
374
- throw new ProseKitError(`Invalid node content: ${typeof content}`);
375
- }
376
-
377
398
  // src/extensions/node-spec.ts
378
399
  import OrderedMap2 from "orderedmap";
379
400
 
@@ -715,33 +736,12 @@ import { history, redo, undo } from "@prosekit/pm/history";
715
736
  var isApple = typeof navigator != "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : !1;
716
737
 
717
738
  // src/extensions/keymap.ts
718
- import {
719
- baseKeymap,
720
- chainCommands,
721
- createParagraphNear,
722
- liftEmptyBlock,
723
- newlineInCode
724
- } from "@prosekit/pm/commands";
739
+ import { chainCommands } from "@prosekit/pm/commands";
725
740
  import { keydownHandler } from "@prosekit/pm/keymap";
726
741
  import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state";
727
- import { splitSplittableBlock } from "prosemirror-splittable";
728
- var customBaseKeymap = {
729
- ...baseKeymap,
730
- Enter: chainCommands(
731
- newlineInCode,
732
- createParagraphNear,
733
- liftEmptyBlock,
734
- splitSplittableBlock
735
- )
736
- };
737
742
  function defineKeymap(keymap) {
738
743
  return defineFacetPayload(keymapFacet, [keymap]);
739
744
  }
740
- function defineBaseKeymap(options) {
741
- var _a;
742
- let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
743
- return withPriority(defineKeymap(customBaseKeymap), priority);
744
- }
745
745
  var keymapFacet = defineFacet({
746
746
  reduce: () => {
747
747
  let handler, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin2({
@@ -788,6 +788,38 @@ function defineHistory() {
788
788
  ]);
789
789
  }
790
790
 
791
+ // src/extensions/keymap-base.ts
792
+ import {
793
+ baseKeymap,
794
+ chainCommands as chainCommands2,
795
+ createParagraphNear,
796
+ deleteSelection,
797
+ joinTextblockBackward,
798
+ liftEmptyBlock,
799
+ newlineInCode,
800
+ selectNodeBackward
801
+ } from "@prosekit/pm/commands";
802
+ import { splitSplittableBlock } from "prosemirror-splittable";
803
+ var customEnter = chainCommands2(
804
+ newlineInCode,
805
+ createParagraphNear,
806
+ liftEmptyBlock,
807
+ splitSplittableBlock
808
+ ), customBackspace = chainCommands2(
809
+ deleteSelection,
810
+ joinTextblockBackward,
811
+ selectNodeBackward
812
+ ), customBaseKeymap = {
813
+ ...baseKeymap,
814
+ Enter: customEnter,
815
+ Backspace: customBackspace
816
+ };
817
+ function defineBaseKeymap(options) {
818
+ var _a;
819
+ let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
820
+ return withPriority(defineKeymap(customBaseKeymap), priority);
821
+ }
822
+
791
823
  // src/extensions/mark-spec.ts
792
824
  function defineMarkSpec(options) {
793
825
  return defineFacetPayload(markSpecFacet, [[options, void 0]]);
@@ -875,22 +907,17 @@ var nodeViewFacet = defineFacet({
875
907
  import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
876
908
  import "@prosekit/pm/view";
877
909
  function defineNodeViewFactory(options) {
878
- return defineFacetPayload(nodeViewFactoryFacet, [options]);
910
+ return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]);
911
+ }
912
+ function defineNodeViewComponent(options) {
913
+ return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]);
879
914
  }
880
915
  var nodeViewFactoryFacet = defineFacet({
881
916
  reducer: (inputs) => {
882
- let nodeViews = {}, options = {}, factories = {};
883
- for (let input of inputs) {
884
- let group = input.group;
885
- input.name == null ? factories[group] = input.factory : (options[group] || (options[group] = []), options[group].push({
886
- name: input.name,
887
- args: input.args
888
- }));
889
- }
890
- for (let [group, factory] of Object.entries(factories)) {
891
- let groupOptions = options[group] || [];
892
- for (let { name, args } of groupOptions)
893
- nodeViews[name] = factory(args);
917
+ let nodeViews = {}, factories = inputs.map((x) => x[0]).filter(isNotNull), options = inputs.map((x) => x[1]).filter(isNotNull);
918
+ for (let { group, name, args } of options) {
919
+ let factory = factories.find((factory2) => factory2.group === group);
920
+ factory && (nodeViews[name] = factory.factory(args));
894
921
  }
895
922
  return () => [
896
923
  new ProseMirrorPlugin6({
@@ -945,6 +972,22 @@ var canUseRegexLookbehind = cache(() => {
945
972
  import clsxLite from "clsx/lite";
946
973
  var clsx = clsxLite;
947
974
 
975
+ // src/utils/collect-nodes.ts
976
+ import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
977
+ function collectNodes(content) {
978
+ if (Array.isArray(content))
979
+ return content.flatMap(collectNodes);
980
+ if (content instanceof ProseMirrorNode2)
981
+ return [content];
982
+ if (content instanceof ProseMirrorFragment) {
983
+ let nodes = [];
984
+ for (let i = 0; i < content.childCount; i++)
985
+ nodes.push(content.child(i));
986
+ return nodes;
987
+ }
988
+ throw new ProseKitError(`Invalid node content: ${typeof content}`);
989
+ }
990
+
948
991
  // src/utils/default-block-at.ts
949
992
  function defaultBlockAt(match) {
950
993
  for (let i = 0; i < match.edgeCount; i++) {
@@ -960,6 +1003,12 @@ function getId() {
960
1003
  return id = (id + 1) % Number.MAX_SAFE_INTEGER, `id:${id}`;
961
1004
  }
962
1005
 
1006
+ // src/utils/is-at-block-start.ts
1007
+ function isAtBlockStart(state, view) {
1008
+ let { $cursor } = state.selection;
1009
+ return !$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0) ? null : $cursor;
1010
+ }
1011
+
963
1012
  // src/utils/is-in-code-block.ts
964
1013
  function isCodeBlockType(type) {
965
1014
  return type.spec.code && type.isBlock;
@@ -1019,6 +1068,7 @@ export {
1019
1068
  defineNodeAttr,
1020
1069
  defineNodeSpec,
1021
1070
  defineNodeView,
1071
+ defineNodeViewComponent,
1022
1072
  defineNodeViewFactory,
1023
1073
  defineParagraph,
1024
1074
  definePasteHandler,
@@ -1040,6 +1090,7 @@ export {
1040
1090
  insertNode,
1041
1091
  isAllSelection,
1042
1092
  isApple,
1093
+ isAtBlockStart,
1043
1094
  isInCodeBlock,
1044
1095
  isMark,
1045
1096
  isMarkAbsent,
@@ -1064,6 +1115,9 @@ export {
1064
1115
  toggleMark,
1065
1116
  toggleNode,
1066
1117
  union,
1118
+ unsetBlockType,
1119
+ unsetMark,
1067
1120
  withPriority,
1068
- withSkipCodeBlock
1121
+ withSkipCodeBlock,
1122
+ wrap
1069
1123
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -49,7 +49,7 @@
49
49
  "devDependencies": {
50
50
  "tsup": "^8.1.0",
51
51
  "typescript": "^5.5.3",
52
- "vitest": "^2.0.0-beta.13",
52
+ "vitest": "^2.0.2",
53
53
  "@prosekit/dev": "0.0.0"
54
54
  },
55
55
  "scripts": {