@prosekit/core 0.0.0-next-20240707065442 → 0.0.0-next-20240715033214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.ts +311 -155
- package/dist/prosekit-core.d.ts +22 -3
- package/dist/prosekit-core.js +156 -97
- package/package.json +3 -3
@@ -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 {
|
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
|
-
}
|
71
|
-
export {
|
72
|
-
export {
|
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:
|
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
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
331
|
-
|
332
|
-
|
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;
|
@@ -494,13 +465,15 @@ export { defineFocusChangeHandler as defineFocusChangeHandler_alias_1 }
|
|
494
465
|
|
495
466
|
/**
|
496
467
|
* Add undo/redo history to the editor.
|
468
|
+
*
|
469
|
+
* @public
|
497
470
|
*/
|
498
|
-
declare function defineHistory(): Extension< {
|
471
|
+
declare function defineHistory({ depth, newGroupDelay, }?: HistoryOptions): Extension< {
|
499
472
|
Nodes: never;
|
500
473
|
Marks: never;
|
501
474
|
Commands: {
|
502
|
-
undo: [];
|
503
|
-
redo: [];
|
475
|
+
readonly undo: [];
|
476
|
+
readonly redo: [];
|
504
477
|
};
|
505
478
|
}>;
|
506
479
|
export { defineHistory }
|
@@ -584,6 +557,13 @@ declare function defineNodeView(options: NodeViewOptions): Extension;
|
|
584
557
|
export { defineNodeView }
|
585
558
|
export { defineNodeView as defineNodeView_alias_1 }
|
586
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
|
+
|
587
567
|
/**
|
588
568
|
* @internal
|
589
569
|
*/
|
@@ -650,61 +630,28 @@ export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_
|
|
650
630
|
/**
|
651
631
|
* @internal
|
652
632
|
*/
|
653
|
-
export declare function defineTestExtension(): Extension<
|
654
|
-
Nodes: "text" | "doc" | "paragraph";
|
655
|
-
Marks: "bold";
|
656
|
-
Commands: {
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
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
|
-
};
|
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
|
+
};
|
708
655
|
}>;
|
709
656
|
|
710
657
|
/**
|
@@ -831,7 +778,7 @@ declare type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEv
|
|
831
778
|
export { DoubleClickHandler }
|
832
779
|
export { DoubleClickHandler as DoubleClickHandler_alias_1 }
|
833
780
|
|
834
|
-
declare type DoubleClickOnHandler = (view: EditorView, pos: number, node:
|
781
|
+
declare type DoubleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
|
835
782
|
export { DoubleClickOnHandler }
|
836
783
|
export { DoubleClickOnHandler as DoubleClickOnHandler_alias_1 }
|
837
784
|
|
@@ -1005,14 +952,21 @@ export { elementFromNode as elementFromNode_alias_1 }
|
|
1005
952
|
*
|
1006
953
|
* @public
|
1007
954
|
*/
|
1008
|
-
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 {
|
1009
963
|
/**
|
1010
964
|
* The type of the mark to expand.
|
1011
965
|
*/
|
1012
966
|
type: string | MarkType;
|
1013
|
-
}
|
1014
|
-
export {
|
1015
|
-
export {
|
967
|
+
}
|
968
|
+
export { ExpandMarkOptions }
|
969
|
+
export { ExpandMarkOptions as ExpandMarkOptions_alias_1 }
|
1016
970
|
|
1017
971
|
/**
|
1018
972
|
* @public
|
@@ -1219,6 +1173,30 @@ export declare type GroupedEntries<T extends Record<string, any>> = {
|
|
1219
1173
|
|
1220
1174
|
export declare function groupEntries<T extends Record<string, any>>(entries: ObjectEntries<T>[]): GroupedEntries<T>;
|
1221
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
|
+
|
1222
1200
|
/**
|
1223
1201
|
* @internal
|
1224
1202
|
*/
|
@@ -1248,17 +1226,7 @@ export { htmlFromNode as htmlFromNode_alias_1 }
|
|
1248
1226
|
*
|
1249
1227
|
* @public
|
1250
1228
|
*/
|
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;
|
1229
|
+
declare function insertNode(options: InsertNodeOptions): Command;
|
1262
1230
|
export { insertNode }
|
1263
1231
|
export { insertNode as insertNode_alias_1 }
|
1264
1232
|
|
@@ -1267,6 +1235,31 @@ export declare function insertNodeAction({ node, pos, }: {
|
|
1267
1235
|
pos?: number;
|
1268
1236
|
}): Action;
|
1269
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
|
+
|
1270
1263
|
/**
|
1271
1264
|
* Returns a command that inserts the given text.
|
1272
1265
|
*
|
@@ -1292,6 +1285,15 @@ declare const isApple: boolean;
|
|
1292
1285
|
export { isApple }
|
1293
1286
|
export { isApple as isApple_alias_1 }
|
1294
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
|
+
|
1295
1297
|
export declare function isElement(value: unknown): value is Element;
|
1296
1298
|
|
1297
1299
|
/**
|
@@ -1611,13 +1613,19 @@ export { NodeSpecOptions as NodeSpecOptions_alias_1 }
|
|
1611
1613
|
/**
|
1612
1614
|
* @internal
|
1613
1615
|
*/
|
1614
|
-
declare type
|
1616
|
+
declare type NodeViewComponentOptions<T> = {
|
1615
1617
|
group: string;
|
1616
1618
|
name: string;
|
1617
1619
|
args: T;
|
1618
|
-
}
|
1620
|
+
};
|
1621
|
+
export { NodeViewComponentOptions }
|
1622
|
+
export { NodeViewComponentOptions as NodeViewComponentOptions_alias_1 }
|
1623
|
+
|
1624
|
+
/**
|
1625
|
+
* @internal
|
1626
|
+
*/
|
1627
|
+
declare type NodeViewFactoryOptions<T> = {
|
1619
1628
|
group: string;
|
1620
|
-
name?: undefined;
|
1621
1629
|
factory: (args: T) => NodeViewConstructor;
|
1622
1630
|
};
|
1623
1631
|
export { NodeViewFactoryOptions }
|
@@ -1721,7 +1729,14 @@ export { ProseKitError as ProseKitError_alias_1 }
|
|
1721
1729
|
*
|
1722
1730
|
* @public
|
1723
1731
|
*/
|
1724
|
-
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 {
|
1725
1740
|
/**
|
1726
1741
|
* The type of the mark to remove.
|
1727
1742
|
*/
|
@@ -1738,16 +1753,23 @@ declare function removeMark(options: {
|
|
1738
1753
|
* The end position of the document. By default it will be the end position of current selection.
|
1739
1754
|
*/
|
1740
1755
|
to?: number;
|
1741
|
-
}
|
1742
|
-
export {
|
1743
|
-
export {
|
1756
|
+
}
|
1757
|
+
export { RemoveMarkOptions }
|
1758
|
+
export { RemoveMarkOptions as RemoveMarkOptions_alias_1 }
|
1744
1759
|
|
1745
1760
|
/**
|
1746
1761
|
* Returns a command to remove the nearest ancestor node of a specific type from the current position.
|
1747
1762
|
*
|
1748
1763
|
* @public
|
1749
1764
|
*/
|
1750
|
-
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 {
|
1751
1773
|
/**
|
1752
1774
|
* The type of the node to remove.
|
1753
1775
|
*/
|
@@ -1756,9 +1778,9 @@ declare function removeNode(options: {
|
|
1756
1778
|
* The document position to start searching node. By default it will be the anchor position of current selection.
|
1757
1779
|
*/
|
1758
1780
|
pos?: number;
|
1759
|
-
}
|
1760
|
-
export {
|
1761
|
-
export {
|
1781
|
+
}
|
1782
|
+
export { RemoveNodeOptions }
|
1783
|
+
export { RemoveNodeOptions as RemoveNodeOptions_alias_1 }
|
1762
1784
|
|
1763
1785
|
export declare const rootFacet: Facet<RootPayload, RootOutput>;
|
1764
1786
|
|
@@ -1812,21 +1834,35 @@ export { SelectionJSON as SelectionJSON_alias_1 }
|
|
1812
1834
|
*
|
1813
1835
|
* @public
|
1814
1836
|
*/
|
1815
|
-
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 {
|
1816
1845
|
type: NodeType | string;
|
1817
1846
|
attrs?: Attrs | null;
|
1818
1847
|
from?: number;
|
1819
1848
|
to?: number;
|
1820
|
-
}
|
1821
|
-
export {
|
1822
|
-
export {
|
1849
|
+
}
|
1850
|
+
export { SetBlockTypeOptions }
|
1851
|
+
export { SetBlockTypeOptions as SetBlockTypeOptions_alias_1 }
|
1823
1852
|
|
1824
1853
|
/**
|
1825
1854
|
* Returns a command that set the attributes of the current node.
|
1826
1855
|
*
|
1827
1856
|
* @public
|
1828
1857
|
*/
|
1829
|
-
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 {
|
1830
1866
|
/**
|
1831
1867
|
* The type of node to set the attributes of.
|
1832
1868
|
*
|
@@ -1842,9 +1878,9 @@ declare function setNodeAttrs(options: {
|
|
1842
1878
|
* containing the current selection.
|
1843
1879
|
*/
|
1844
1880
|
pos?: number;
|
1845
|
-
}
|
1846
|
-
export {
|
1847
|
-
export {
|
1881
|
+
}
|
1882
|
+
export { SetNodeAttrsOptions }
|
1883
|
+
export { SetNodeAttrsOptions as SetNodeAttrsOptions_alias_1 }
|
1848
1884
|
|
1849
1885
|
export declare function setSelectionAround(tr: Transaction, pos: number): void;
|
1850
1886
|
|
@@ -1858,6 +1894,46 @@ export declare type Setter<T> = (value: T) => void;
|
|
1858
1894
|
*/
|
1859
1895
|
export declare function setupEditorExtension<E extends Extension>(options: EditorOptions<E>): E;
|
1860
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
|
+
|
1861
1937
|
/**
|
1862
1938
|
* @internal
|
1863
1939
|
*/
|
@@ -1971,33 +2047,53 @@ export declare type ToCommandCreators<T extends CommandTyping> = {
|
|
1971
2047
|
*
|
1972
2048
|
* @public
|
1973
2049
|
*/
|
1974
|
-
declare function toggleMark({ type, attrs
|
1975
|
-
type: string | MarkType;
|
1976
|
-
attrs?: Attrs | null;
|
1977
|
-
}): Command;
|
2050
|
+
declare function toggleMark({ type, attrs }: ToggleMarkOptions): Command;
|
1978
2051
|
export { toggleMark }
|
1979
2052
|
export { toggleMark as toggleMark_alias_1 }
|
1980
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
|
+
|
1981
2064
|
/**
|
1982
2065
|
* Returns a command that set the selected textblocks to the given node type
|
1983
2066
|
* with the given attributes.
|
1984
2067
|
*
|
1985
2068
|
* @public
|
1986
2069
|
*/
|
1987
|
-
declare function toggleNode({ type, attrs
|
1988
|
-
type: string | NodeType;
|
1989
|
-
attrs?: Attrs | null;
|
1990
|
-
}): Command;
|
2070
|
+
declare function toggleNode({ type, attrs }: ToggleNodeOptions): Command;
|
1991
2071
|
export { toggleNode }
|
1992
2072
|
export { toggleNode as toggleNode_alias_1 }
|
1993
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
|
+
|
1994
2090
|
export declare function toReversed<T>(arr: T[]): T[];
|
1995
2091
|
|
1996
2092
|
declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
|
1997
2093
|
export { TripleClickHandler }
|
1998
2094
|
export { TripleClickHandler as TripleClickHandler_alias_1 }
|
1999
2095
|
|
2000
|
-
declare type TripleClickOnHandler = (view: EditorView, pos: number, node:
|
2096
|
+
declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_2, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
|
2001
2097
|
export { TripleClickOnHandler }
|
2002
2098
|
export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
|
2003
2099
|
|
@@ -2074,6 +2170,57 @@ declare type UnmountHandler = () => void;
|
|
2074
2170
|
export { UnmountHandler }
|
2075
2171
|
export { UnmountHandler as UnmountHandler_alias_1 }
|
2076
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
|
+
|
2077
2224
|
/**
|
2078
2225
|
* A function that is called when the editor state is updated.
|
2079
2226
|
*
|
@@ -2121,10 +2268,19 @@ export { withSkipCodeBlock as withSkipCodeBlock_alias_1 }
|
|
2121
2268
|
*
|
2122
2269
|
* @public
|
2123
2270
|
*/
|
2124
|
-
|
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 {
|
2125
2279
|
nodeType: NodeType;
|
2126
2280
|
attrs?: Attrs | null;
|
2127
|
-
}
|
2281
|
+
}
|
2282
|
+
export { WrapOptions }
|
2283
|
+
export { WrapOptions as WrapOptions_alias_1 }
|
2128
2284
|
|
2129
2285
|
export declare function zip<T, P>(a: T[], b: P[]): [T, P][];
|
2130
2286
|
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -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,12 @@ 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 {
|
76
|
+
export { HistoryOptions } from './_tsup-dts-rollup';
|
64
77
|
export { defineKeymap } from './_tsup-dts-rollup';
|
65
78
|
export { keymapFacet } from './_tsup-dts-rollup';
|
66
79
|
export { Keymap } from './_tsup-dts-rollup';
|
67
80
|
export { KeymapPayload } from './_tsup-dts-rollup';
|
81
|
+
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
68
82
|
export { defineMarkAttr } from './_tsup-dts-rollup';
|
69
83
|
export { defineMarkSpec } from './_tsup-dts-rollup';
|
70
84
|
export { MarkAttrOptions } from './_tsup-dts-rollup';
|
@@ -75,7 +89,9 @@ export { NodeAttrOptions } from './_tsup-dts-rollup';
|
|
75
89
|
export { NodeSpecOptions } from './_tsup-dts-rollup';
|
76
90
|
export { defineNodeView } from './_tsup-dts-rollup';
|
77
91
|
export { NodeViewOptions } from './_tsup-dts-rollup';
|
92
|
+
export { defineNodeViewComponent } from './_tsup-dts-rollup';
|
78
93
|
export { defineNodeViewFactory } from './_tsup-dts-rollup';
|
94
|
+
export { NodeViewComponentOptions } from './_tsup-dts-rollup';
|
79
95
|
export { NodeViewFactoryOptions } from './_tsup-dts-rollup';
|
80
96
|
export { defineParagraph } from './_tsup-dts-rollup';
|
81
97
|
export { definePlugin } from './_tsup-dts-rollup';
|
@@ -103,11 +119,14 @@ export { SimplifyUnion } from './_tsup-dts-rollup';
|
|
103
119
|
export { assert } from './_tsup-dts-rollup';
|
104
120
|
export { canUseRegexLookbehind } from './_tsup-dts-rollup';
|
105
121
|
export { clsx } from './_tsup-dts-rollup';
|
122
|
+
export { collectNodes } from './_tsup-dts-rollup';
|
123
|
+
export { NodeContent } from './_tsup-dts-rollup';
|
106
124
|
export { defaultBlockAt } from './_tsup-dts-rollup';
|
107
125
|
export { isApple } from './_tsup-dts-rollup';
|
108
126
|
export { _getId } from './_tsup-dts-rollup';
|
109
127
|
export { getMarkType } from './_tsup-dts-rollup';
|
110
128
|
export { getNodeType } from './_tsup-dts-rollup';
|
129
|
+
export { isAtBlockStart } from './_tsup-dts-rollup';
|
111
130
|
export { isInCodeBlock } from './_tsup-dts-rollup';
|
112
131
|
export { isMarkAbsent } from './_tsup-dts-rollup';
|
113
132
|
export { isMarkActive } from './_tsup-dts-rollup';
|
package/dist/prosekit-core.js
CHANGED
@@ -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.
|
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(
|
345
|
-
return defineFacetPayload(commandFacet, [
|
379
|
+
function defineCommands(commands2) {
|
380
|
+
return defineFacetPayload(commandFacet, [commands2]);
|
346
381
|
}
|
347
382
|
function defineBaseCommands() {
|
348
383
|
return defineCommands({
|
@@ -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,32 +736,11 @@ 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
|
-
|
728
|
-
|
729
|
-
...baseKeymap,
|
730
|
-
Enter: chainCommands(
|
731
|
-
newlineInCode,
|
732
|
-
createParagraphNear,
|
733
|
-
liftEmptyBlock,
|
734
|
-
splitSplittableBlock
|
735
|
-
)
|
736
|
-
};
|
737
|
-
function defineKeymap(keymap) {
|
738
|
-
return defineFacetPayload(keymapFacet, [keymap]);
|
739
|
-
}
|
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);
|
742
|
+
function defineKeymap(keymap2) {
|
743
|
+
return defineFacetPayload(keymapFacet, [keymap2]);
|
744
744
|
}
|
745
745
|
var keymapFacet = defineFacet({
|
746
746
|
reduce: () => {
|
@@ -760,34 +760,71 @@ var keymapFacet = defineFacet({
|
|
760
760
|
});
|
761
761
|
function mergeKeymaps(keymaps) {
|
762
762
|
let bindings = {};
|
763
|
-
for (let
|
764
|
-
for (let [key, command] of Object.entries(
|
763
|
+
for (let keymap2 of keymaps)
|
764
|
+
for (let [key, command] of Object.entries(keymap2))
|
765
765
|
(bindings[key] || (bindings[key] = [])).push(command);
|
766
766
|
return Object.fromEntries(
|
767
|
-
Object.entries(bindings).map(([key,
|
767
|
+
Object.entries(bindings).map(([key, commands2]) => [
|
768
768
|
key,
|
769
|
-
chainCommands(...
|
769
|
+
chainCommands(...commands2)
|
770
770
|
])
|
771
771
|
);
|
772
772
|
}
|
773
773
|
var keymapPluginKey = new PluginKey4("prosekit-keymap");
|
774
774
|
|
775
775
|
// src/extensions/history.ts
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
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 })),
|
783
791
|
defineKeymap(keymap),
|
784
|
-
defineCommands(
|
785
|
-
undo: () => undo,
|
786
|
-
redo: () => redo
|
787
|
-
})
|
792
|
+
defineCommands(commands)
|
788
793
|
]);
|
789
794
|
}
|
790
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
|
+
|
791
828
|
// src/extensions/mark-spec.ts
|
792
829
|
function defineMarkSpec(options) {
|
793
830
|
return defineFacetPayload(markSpecFacet, [[options, void 0]]);
|
@@ -875,22 +912,17 @@ var nodeViewFacet = defineFacet({
|
|
875
912
|
import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
|
876
913
|
import "@prosekit/pm/view";
|
877
914
|
function defineNodeViewFactory(options) {
|
878
|
-
return defineFacetPayload(nodeViewFactoryFacet, [options]);
|
915
|
+
return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]);
|
916
|
+
}
|
917
|
+
function defineNodeViewComponent(options) {
|
918
|
+
return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]);
|
879
919
|
}
|
880
920
|
var nodeViewFactoryFacet = defineFacet({
|
881
921
|
reducer: (inputs) => {
|
882
|
-
let nodeViews = {},
|
883
|
-
for (let
|
884
|
-
let
|
885
|
-
|
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);
|
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));
|
894
926
|
}
|
895
927
|
return () => [
|
896
928
|
new ProseMirrorPlugin6({
|
@@ -945,6 +977,22 @@ var canUseRegexLookbehind = cache(() => {
|
|
945
977
|
import clsxLite from "clsx/lite";
|
946
978
|
var clsx = clsxLite;
|
947
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
|
+
|
948
996
|
// src/utils/default-block-at.ts
|
949
997
|
function defaultBlockAt(match) {
|
950
998
|
for (let i = 0; i < match.edgeCount; i++) {
|
@@ -960,6 +1008,12 @@ function getId() {
|
|
960
1008
|
return id = (id + 1) % Number.MAX_SAFE_INTEGER, `id:${id}`;
|
961
1009
|
}
|
962
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
|
+
|
963
1017
|
// src/utils/is-in-code-block.ts
|
964
1018
|
function isCodeBlockType(type) {
|
965
1019
|
return type.spec.code && type.isBlock;
|
@@ -1019,6 +1073,7 @@ export {
|
|
1019
1073
|
defineNodeAttr,
|
1020
1074
|
defineNodeSpec,
|
1021
1075
|
defineNodeView,
|
1076
|
+
defineNodeViewComponent,
|
1022
1077
|
defineNodeViewFactory,
|
1023
1078
|
defineParagraph,
|
1024
1079
|
definePasteHandler,
|
@@ -1040,6 +1095,7 @@ export {
|
|
1040
1095
|
insertNode,
|
1041
1096
|
isAllSelection,
|
1042
1097
|
isApple,
|
1098
|
+
isAtBlockStart,
|
1043
1099
|
isInCodeBlock,
|
1044
1100
|
isMark,
|
1045
1101
|
isMarkAbsent,
|
@@ -1064,6 +1120,9 @@ export {
|
|
1064
1120
|
toggleMark,
|
1065
1121
|
toggleNode,
|
1066
1122
|
union,
|
1123
|
+
unsetBlockType,
|
1124
|
+
unsetMark,
|
1067
1125
|
withPriority,
|
1068
|
-
withSkipCodeBlock
|
1126
|
+
withSkipCodeBlock,
|
1127
|
+
wrap
|
1069
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-
|
4
|
+
"version": "0.0.0-next-20240715033214",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -44,12 +44,12 @@
|
|
44
44
|
"orderedmap": "^2.1.1",
|
45
45
|
"prosemirror-splittable": "^0.1.1",
|
46
46
|
"type-fest": "^4.21.0",
|
47
|
-
"@prosekit/pm": "^0.0.0-next-
|
47
|
+
"@prosekit/pm": "^0.0.0-next-20240715033214"
|
48
48
|
},
|
49
49
|
"devDependencies": {
|
50
50
|
"tsup": "^8.1.0",
|
51
51
|
"typescript": "^5.5.3",
|
52
|
-
"vitest": "^2.0.
|
52
|
+
"vitest": "^2.0.2",
|
53
53
|
"@prosekit/dev": "0.0.0"
|
54
54
|
},
|
55
55
|
"scripts": {
|