@prosekit/core 0.7.3 → 0.7.4

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,5 +1,6 @@
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';
3
4
  import { Command } from '@prosekit/pm/state';
4
5
  import type { ContentMatch } from '@prosekit/pm/model';
5
6
  import { config as default_alias_1 } from '@prosekit/dev/config-vitest';
@@ -19,8 +20,8 @@ import { NodeSelection } from '@prosekit/pm/state';
19
20
  import type { NodeSpec } from '@prosekit/pm/model';
20
21
  import { NodeType } from '@prosekit/pm/model';
21
22
  import { NodeType as NodeType_2 } from 'prosemirror-model';
22
- import { NodeView } from '@prosekit/pm/view';
23
- import { NodeViewConstructor } from '@prosekit/pm/view';
23
+ import type { NodeView } from '@prosekit/pm/view';
24
+ import type { NodeViewConstructor } from '@prosekit/pm/view';
24
25
  import { Options } from 'tsup';
25
26
  import type { ParseOptions } from '@prosekit/pm/model';
26
27
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
@@ -75,6 +76,15 @@ declare interface AddMarkOptions {
75
76
  export { AddMarkOptions }
76
77
  export { AddMarkOptions as AddMarkOptions_alias_1 }
77
78
 
79
+ /**
80
+ * An object holding the attributes of a node.
81
+
82
+ * @public
83
+ */
84
+ declare type AnyAttrs = Attrs;
85
+ export { AnyAttrs }
86
+ export { AnyAttrs as AnyAttrs_alias_1 }
87
+
78
88
  export declare function applyAction(operator: Action): Command;
79
89
 
80
90
  export declare const applyMarkForTest: ApplyMarkFunction;
@@ -106,8 +116,38 @@ export { assert as assert_alias_1 }
106
116
  */
107
117
  export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
108
118
 
119
+ /**
120
+ * Utility function assert that two types are equal in tests.
121
+ */
122
+ export declare function assertTypeEqual_alias_1<T, U>(_val: IsEqual<T, U>): void;
123
+
109
124
  export declare function attrsMatch(nodeOrMark: ProseMirrorNode | Mark, attrs: Attrs): boolean;
110
125
 
126
+ /**
127
+ * @public
128
+ */
129
+ declare type AttrSpec<AttrType = any> = {
130
+ /**
131
+ * The default value for this attribute, to use when no explicit value is
132
+ * provided. Attributes that have no default must be provided whenever a node
133
+ * or mark of a type that has them is created.
134
+ */
135
+ default?: AttrType;
136
+ /**
137
+ * A function or type name used to validate values of this attribute. This
138
+ * will be used when deserializing the attribute from JSON, and when running
139
+ * [`Node.check`](https://prosemirror.net/docs/ref/#model.Node.check). When a
140
+ * function, it should raise an exception if the value isn't of the expected
141
+ * type or shape. When a string, it should be a `|`-separated string of
142
+ * primitive types (`"number"`, `"string"`, `"boolean"`, `"null"`, and
143
+ * `"undefined"`), and the library will raise an error when the value is not
144
+ * one of those types.
145
+ */
146
+ validate?: string | ((value: unknown) => void);
147
+ };
148
+ export { AttrSpec }
149
+ export { AttrSpec as AttrSpec_alias_1 }
150
+
111
151
  /**
112
152
  * @internal
113
153
  */
@@ -199,10 +239,19 @@ export { collectNodes as collectNodes_alias_1 }
199
239
 
200
240
  export declare function combineEventHandlers<Handler extends (...args: any[]) => boolean | void, Args extends Parameters<Handler> = Parameters<Handler>>(): readonly [(handlers: Handler[]) => void, (...args: Args) => boolean];
201
241
 
202
- export declare interface CommandApplier<Args extends any[] = any[]> {
242
+ /**
243
+ * A function to apply a command to the editor. It will return `true` if the command was applied, and `false` otherwise.
244
+ *
245
+ * It also has a `canApply` method to check if the command can be applied.
246
+ *
247
+ * @public
248
+ */
249
+ declare interface CommandAction<Args extends any[] = any[]> {
203
250
  (...args: Args): boolean;
204
251
  canApply(...args: Args): boolean;
205
252
  }
253
+ export { CommandAction }
254
+ export { CommandAction as CommandAction_alias_1 }
206
255
 
207
256
  export declare type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
208
257
 
@@ -233,12 +282,12 @@ export { createEditor as createEditor_alias_1 }
233
282
  /**
234
283
  * @internal
235
284
  */
236
- export declare function createMarkBuilders(schema: Schema, getState: () => EditorState | null | undefined, applyMark?: ApplyMarkFunction): Record<string, MarkBuilder>;
285
+ export declare function createMarkActions(schema: Schema, getState: () => EditorState | null | undefined, applyMark?: ApplyMarkFunction): Record<string, MarkAction>;
237
286
 
238
287
  /**
239
288
  * @internal
240
289
  */
241
- export declare function createNodeBuilders(schema: Schema, getState: () => EditorState | null | undefined, createNode?: CreateNodeFunction): Record<string, NodeBuilder>;
290
+ export declare function createNodeActions(schema: Schema, getState: () => EditorState | null | undefined, createNode?: CreateNodeFunction): Record<string, NodeAction>;
242
291
 
243
292
  export declare const createNodeForTest: CreateNodeFunction;
244
293
 
@@ -368,7 +417,9 @@ export { defineDefaultState as defineDefaultState_alias_1 }
368
417
  * @public
369
418
  */
370
419
  declare function defineDoc(): Extension< {
371
- Nodes: "doc";
420
+ Nodes: {
421
+ doc: Attrs_2;
422
+ };
372
423
  Marks: never;
373
424
  Commands: never;
374
425
  }>;
@@ -507,15 +558,23 @@ export { defineKeyPressHandler as defineKeyPressHandler_alias_1 }
507
558
  /**
508
559
  * @public
509
560
  */
510
- declare function defineMarkAttr(options: MarkAttrOptions): Extension;
561
+ declare function defineMarkAttr<MarkType extends string = string, AttrName extends string = string, AttrType = any>(options: MarkAttrOptions<MarkType, AttrName, AttrType>): Extension<{
562
+ Nodes: never;
563
+ Marks: {
564
+ [K in MarkType]: AttrType;
565
+ };
566
+ Commands: never;
567
+ }>;
511
568
  export { defineMarkAttr }
512
569
  export { defineMarkAttr as defineMarkAttr_alias_1 }
513
570
 
514
571
  /**
515
572
  * @public
516
573
  */
517
- declare function defineMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>): Extension<{
518
- Marks: Mark;
574
+ declare function defineMarkSpec<Mark extends string, Attrs extends AnyAttrs = AnyAttrs>(options: MarkSpecOptions<Mark, Attrs>): Extension<{
575
+ Marks: {
576
+ [K in Mark]: Attrs;
577
+ };
519
578
  Nodes: never;
520
579
  Commands: never;
521
580
  }>;
@@ -536,7 +595,15 @@ export { defineMountHandler as defineMountHandler_alias_1 }
536
595
  *
537
596
  * @public
538
597
  */
539
- declare function defineNodeAttr(options: NodeAttrOptions): Extension;
598
+ declare function defineNodeAttr<NodeType extends string = string, AttrName extends string = string, AttrType = any>(options: NodeAttrOptions<NodeType, AttrName, AttrType>): Extension<{
599
+ Nodes: {
600
+ [K in NodeType]: {
601
+ [K in AttrName]: AttrType;
602
+ };
603
+ };
604
+ Marks: never;
605
+ Commands: never;
606
+ }>;
540
607
  export { defineNodeAttr }
541
608
  export { defineNodeAttr as defineNodeAttr_alias_1 }
542
609
 
@@ -545,8 +612,10 @@ export { defineNodeAttr as defineNodeAttr_alias_1 }
545
612
  *
546
613
  * @public
547
614
  */
548
- declare function defineNodeSpec<Node extends string>(options: NodeSpecOptions<Node>): Extension<{
549
- Nodes: Node;
615
+ declare function defineNodeSpec<Node extends string, Attrs extends AnyAttrs = AnyAttrs>(options: NodeSpecOptions<Node, Attrs>): Extension<{
616
+ Nodes: {
617
+ [K in Node]: Attrs;
618
+ };
550
619
  Marks: never;
551
620
  Commands: never;
552
621
  }>;
@@ -577,7 +646,9 @@ export { defineNodeViewFactory as defineNodeViewFactory_alias_1 }
577
646
  * Defines a paragraph node spec as the highest priority, because it should be the default block node for most cases.
578
647
  */
579
648
  declare function defineParagraph(): Extension< {
580
- Nodes: "paragraph";
649
+ Nodes: {
650
+ paragraph: Attrs_2;
651
+ };
581
652
  Marks: never;
582
653
  Commands: never;
583
654
  }>;
@@ -590,7 +661,9 @@ export { defineParagraph as defineParagraph_alias_1 }
590
661
  * Defines a paragraph node spec.
591
662
  */
592
663
  export declare function defineParagraphSpec(): Extension< {
593
- Nodes: "paragraph";
664
+ Nodes: {
665
+ paragraph: Attrs_2;
666
+ };
594
667
  Marks: never;
595
668
  Commands: never;
596
669
  }>;
@@ -631,8 +704,16 @@ export { defineScrollToSelectionHandler as defineScrollToSelectionHandler_alias_
631
704
  * @internal
632
705
  */
633
706
  export declare function defineTestExtension(): Extension<{
634
- Nodes: "text" | "doc" | "paragraph" | "heading";
635
- Marks: "bold" | "italic";
707
+ Nodes: SimplifyDeeper< {
708
+ paragraph: Attrs_2;
709
+ doc: Attrs_2;
710
+ text: Attrs_2;
711
+ heading: Attrs_2;
712
+ }>;
713
+ Marks: SimplifyDeeper< {
714
+ bold: Attrs_2;
715
+ italic: Attrs_2;
716
+ }>;
636
717
  Commands: {
637
718
  insertText: [{
638
719
  text: string;
@@ -658,7 +739,9 @@ export declare function defineTestExtension(): Extension<{
658
739
  * @public
659
740
  */
660
741
  declare function defineText(): Extension< {
661
- Nodes: "text";
742
+ Nodes: {
743
+ text: Attrs_2;
744
+ };
662
745
  Marks: never;
663
746
  Commands: never;
664
747
  }>;
@@ -811,11 +894,7 @@ declare class Editor<E extends Extension = any> {
811
894
  /**
812
895
  * The editor schema.
813
896
  */
814
- get schema(): Schema<ExtractNodes<E>, ExtractMarks<E>>;
815
- /**
816
- * All commands defined by the editor.
817
- */
818
- get commands(): ExtractCommandAppliers<E>;
897
+ get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>;
819
898
  /**
820
899
  * Whether the editor is focused.
821
900
  */
@@ -855,8 +934,18 @@ declare class Editor<E extends Extension = any> {
855
934
  * directly manipulate the editor's state.
856
935
  */
857
936
  updateState(state: EditorState): void;
858
- get nodes(): Record<ExtractNodes<E>, NodeBuilder>;
859
- get marks(): Record<ExtractMarks<E>, MarkBuilder>;
937
+ /**
938
+ * All {@link CommandAction}s defined by the editor.
939
+ */
940
+ get commands(): ExtractCommandActions<E>;
941
+ /**
942
+ * All {@link NodeAction}s defined by the editor.
943
+ */
944
+ get nodes(): ExtractNodeActions<E>;
945
+ /**
946
+ * All {@link MarkAction}s defined by the editor.
947
+ */
948
+ get marks(): ExtractMarkActions<E>;
860
949
  }
861
950
  export { Editor }
862
951
  export { Editor as Editor_alias_1 }
@@ -867,9 +956,9 @@ export { Editor as Editor_alias_1 }
867
956
  export declare class EditorInstance {
868
957
  view: EditorView | null;
869
958
  schema: Schema;
870
- nodeBuilders: Record<string, NodeBuilder>;
871
- markBuilders: Record<string, MarkBuilder>;
872
- commandAppliers: Record<string, CommandApplier>;
959
+ nodes: Record<string, NodeAction>;
960
+ marks: Record<string, MarkAction>;
961
+ commands: Record<string, CommandAction>;
873
962
  private tree;
874
963
  private directEditorProps;
875
964
  constructor(extension: Extension);
@@ -988,7 +1077,7 @@ export { Extension as Extension_alias_1 }
988
1077
  /**
989
1078
  * @internal
990
1079
  */
991
- declare interface ExtensionTyping<N extends string | never = never, M extends string | never = never, C extends CommandTyping | never = never> {
1080
+ declare interface ExtensionTyping<N extends NodeTyping | never = never, M extends MarkTyping | never = never, C extends CommandTyping | never = never> {
992
1081
  Nodes: N;
993
1082
  Marks: M;
994
1083
  Commands: C;
@@ -997,9 +1086,18 @@ export { ExtensionTyping }
997
1086
  export { ExtensionTyping as ExtensionTyping_alias_1 }
998
1087
 
999
1088
  /**
1089
+ * Extracts the {@link CommandAction}s from an extension type.
1090
+ *
1000
1091
  * @public
1001
1092
  */
1002
- declare type ExtractCommandAppliers<E extends Extension> = ToCommandApplier<ExtractCommands<E>>;
1093
+ declare type ExtractCommandActions<E extends Extension> = ToCommandAction<ExtractCommands<E>>;
1094
+ export { ExtractCommandActions }
1095
+ export { ExtractCommandActions as ExtractCommandActions_alias_1 }
1096
+
1097
+ /**
1098
+ * @deprecated Use `ExtractCommandActions` instead.
1099
+ */
1100
+ declare type ExtractCommandAppliers<E extends Extension> = ExtractCommandActions<E>;
1003
1101
  export { ExtractCommandAppliers }
1004
1102
  export { ExtractCommandAppliers as ExtractCommandAppliers_alias_1 }
1005
1103
 
@@ -1015,17 +1113,45 @@ export { ExtractCommandCreators as ExtractCommandCreators_alias_1 }
1015
1113
  */
1016
1114
  export declare type ExtractCommands<E extends Extension> = SimplifyUnion<ExtractTyping<E>['Commands']>;
1017
1115
 
1116
+ /**
1117
+ * Extracts the {@link MarkAction}s from an extension type.
1118
+ *
1119
+ * @public
1120
+ */
1121
+ declare type ExtractMarkActions<E extends Extension> = ToMarkAction<ExtractMarks<E>>;
1122
+ export { ExtractMarkActions }
1123
+ export { ExtractMarkActions as ExtractMarkActions_alias_1 }
1124
+
1125
+ /**
1126
+ * @public
1127
+ */
1128
+ export declare type ExtractMarkNames<E extends Extension> = PickStringLiteral<keyof ExtractMarks<E>>;
1129
+
1018
1130
  /**
1019
1131
  * @public
1020
1132
  */
1021
- declare type ExtractMarks<E extends Extension> = ExtractTyping<E>['Marks'];
1133
+ declare type ExtractMarks<E extends Extension> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>['Marks']>>;
1022
1134
  export { ExtractMarks }
1023
1135
  export { ExtractMarks as ExtractMarks_alias_1 }
1024
1136
 
1137
+ /**
1138
+ * Extracts the {@link NodeAction}s from an extension type.
1139
+ *
1140
+ * @public
1141
+ */
1142
+ declare type ExtractNodeActions<E extends Extension> = ToNodeAction<ExtractNodes<E>>;
1143
+ export { ExtractNodeActions }
1144
+ export { ExtractNodeActions as ExtractNodeActions_alias_1 }
1145
+
1025
1146
  /**
1026
1147
  * @public
1027
1148
  */
1028
- declare type ExtractNodes<E extends Extension> = ExtractTyping<E>['Nodes'];
1149
+ export declare type ExtractNodeNames<E extends Extension> = PickStringLiteral<keyof ExtractNodes<E>>;
1150
+
1151
+ /**
1152
+ * @public
1153
+ */
1154
+ declare type ExtractNodes<E extends Extension> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>['Nodes']>>;
1029
1155
  export { ExtractNodes }
1030
1156
  export { ExtractNodes as ExtractNodes_alias_1 }
1031
1157
 
@@ -1034,7 +1160,7 @@ export declare function extractTags(node: TaggedProseMirrorNode): Record<string,
1034
1160
  /**
1035
1161
  * @internal
1036
1162
  */
1037
- export declare type ExtractTyping<E extends Extension> = E extends Extension<ExtensionTyping<infer N, infer M, infer C>> ? ExtensionTyping<PickStringLiteral<N>, PickStringLiteral<M>, PickKnownCommandTyping<C>> : never;
1163
+ export declare type ExtractTyping<E extends Extension> = E extends Extension<ExtensionTyping<infer N, infer M, infer C>> ? ExtensionTyping<PickSubType<N, NodeTyping>, PickSubType<M, MarkTyping>, PickSubType<C, CommandTyping>> : never;
1038
1164
 
1039
1165
  /**
1040
1166
  * @internal
@@ -1427,23 +1553,39 @@ export { KeyPressHandler }
1427
1553
  export { KeyPressHandler as KeyPressHandler_alias_1 }
1428
1554
 
1429
1555
  /**
1556
+ * A function for creating a mark with optional attributes and any number of
1557
+ * children.
1558
+ *
1559
+ * It also has a `isActive` method for checking if the mark is active in the
1560
+ * current editor selection.
1561
+ *
1430
1562
  * @public
1431
1563
  */
1432
- declare interface MarkAttrOptions {
1564
+ declare interface MarkAction<Attrs extends AnyAttrs = AnyAttrs> {
1565
+ (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode[];
1566
+ (...children: NodeChild[]): ProseMirrorNode[];
1433
1567
  /**
1434
- * The name of the mark type.
1568
+ * Checks if the mark is active in the current editor selection. If the
1569
+ * optional `attrs` parameter is provided, it will check if the mark is active
1570
+ * with the given attributes.
1435
1571
  */
1436
- type: string;
1572
+ isActive: (attrs?: Attrs) => boolean;
1573
+ }
1574
+ export { MarkAction }
1575
+ export { MarkAction as MarkAction_alias_1 }
1576
+
1577
+ /**
1578
+ * @public
1579
+ */
1580
+ declare interface MarkAttrOptions<MarkName extends string = string, AttrName extends string = string, AttrType = any> extends AttrSpec<AttrType> {
1437
1581
  /**
1438
- * The name of the attribute.
1582
+ * The name of the mark type.
1439
1583
  */
1440
- attr: string;
1584
+ type: MarkName;
1441
1585
  /**
1442
- * The default value for this attribute, to use when no explicit value is
1443
- * provided. Attributes that have no default must be provided whenever a mark
1444
- * of a type that has them is created.
1586
+ * The name of the attribute.
1445
1587
  */
1446
- default?: any;
1588
+ attr: AttrName;
1447
1589
  /**
1448
1590
  * Returns the attribute key and value to be set on the DOM node.
1449
1591
  */
@@ -1457,25 +1599,39 @@ export { MarkAttrOptions }
1457
1599
  export { MarkAttrOptions as MarkAttrOptions_alias_1 }
1458
1600
 
1459
1601
  /**
1460
- * @public
1602
+ * @deprecated Use type {@link MarkAction} instead.
1461
1603
  */
1462
- declare interface MarkBuilder {
1463
- (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode[];
1464
- (...children: NodeChild[]): ProseMirrorNode[];
1465
- isActive: (attrs?: Attrs) => boolean;
1466
- }
1604
+ declare type MarkBuilder = MarkAction;
1467
1605
  export { MarkBuilder }
1468
1606
  export { MarkBuilder as MarkBuilder_alias_1 }
1469
1607
 
1470
1608
  /**
1471
1609
  * @public
1472
1610
  */
1473
- declare interface MarkSpecOptions<MarkName extends string = string> extends MarkSpec {
1611
+ declare interface MarkSpecOptions<MarkName extends string = string, Attrs extends AnyAttrs = AnyAttrs> extends MarkSpec {
1612
+ /**
1613
+ * The name of the mark type.
1614
+ */
1474
1615
  name: MarkName;
1616
+ /**
1617
+ * The attributes that marks of this type get.
1618
+ */
1619
+ attrs?: {
1620
+ [K in keyof Attrs]: AttrSpec<Attrs[K]>;
1621
+ };
1475
1622
  }
1476
1623
  export { MarkSpecOptions }
1477
1624
  export { MarkSpecOptions as MarkSpecOptions_alias_1 }
1478
1625
 
1626
+ /**
1627
+ * @internal
1628
+ */
1629
+ declare interface MarkTyping {
1630
+ [name: string]: Record<string, any>;
1631
+ }
1632
+ export { MarkTyping }
1633
+ export { MarkTyping as MarkTyping_alias_1 }
1634
+
1479
1635
  /**
1480
1636
  * @internal
1481
1637
  */
@@ -1495,23 +1651,39 @@ export { MountHandler }
1495
1651
  export { MountHandler as MountHandler_alias_1 }
1496
1652
 
1497
1653
  /**
1654
+ * A function for creating a node with optional attributes and any number of
1655
+ * children.
1656
+ *
1657
+ * It also has a `isActive` method for checking if the node is active in the
1658
+ * current editor selection.
1659
+ *
1498
1660
  * @public
1499
1661
  */
1500
- declare interface NodeAttrOptions {
1662
+ declare interface NodeAction<Attrs extends AnyAttrs = AnyAttrs> {
1663
+ (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode;
1664
+ (...children: NodeChild[]): ProseMirrorNode;
1501
1665
  /**
1502
- * The name of the node type.
1666
+ * Checks if the node is active in the current editor selection. If the
1667
+ * optional `attrs` parameter is provided, it will check if the node is active
1668
+ * with the given attributes.
1503
1669
  */
1504
- type: string;
1670
+ isActive: (attrs?: Attrs) => boolean;
1671
+ }
1672
+ export { NodeAction }
1673
+ export { NodeAction as NodeAction_alias_1 }
1674
+
1675
+ /**
1676
+ * @public
1677
+ */
1678
+ declare interface NodeAttrOptions<NodeName extends string = string, AttrName extends string = string, AttrType = any> extends AttrSpec<AttrType> {
1505
1679
  /**
1506
- * The name of the attribute.
1680
+ * The name of the node type.
1507
1681
  */
1508
- attr: string;
1682
+ type: NodeName;
1509
1683
  /**
1510
- * The default value for this attribute, to use when no explicit value is
1511
- * provided. Attributes that have no default must be provided whenever a node
1512
- * of a type that has them is created.
1684
+ * The name of the attribute.
1513
1685
  */
1514
- default?: any;
1686
+ attr: AttrName;
1515
1687
  /**
1516
1688
  * Whether the attribute should be kept when the node is split. Set it to
1517
1689
  * `true` if you want to inherit the attribute from the previous node when
@@ -1536,20 +1708,20 @@ export { NodeAttrOptions }
1536
1708
  export { NodeAttrOptions as NodeAttrOptions_alias_1 }
1537
1709
 
1538
1710
  /**
1539
- * @public
1711
+ * @deprecated Use type {@link NodeAction} instead.
1540
1712
  */
1541
- declare interface NodeBuilder {
1542
- (attrs: Attrs | null, ...children: NodeChild[]): ProseMirrorNode;
1543
- (...children: NodeChild[]): ProseMirrorNode;
1544
- isActive: (attrs?: Attrs) => boolean;
1545
- }
1713
+ declare type NodeBuilder = NodeAction;
1546
1714
  export { NodeBuilder }
1547
1715
  export { NodeBuilder as NodeBuilder_alias_1 }
1548
1716
 
1549
1717
  /**
1718
+ * Available children parameters for {@link NodeAction} and {@link MarkAction}.
1719
+ *
1550
1720
  * @public
1551
1721
  */
1552
- export declare type NodeChild = ProseMirrorNode | string | NodeChild[];
1722
+ declare type NodeChild = ProseMirrorNode | string | NodeChild[];
1723
+ export { NodeChild }
1724
+ export { NodeChild as NodeChild_alias_1 }
1553
1725
 
1554
1726
  /**
1555
1727
  * @public
@@ -1603,13 +1775,35 @@ export { NodeJSON as NodeJSON_alias_1 }
1603
1775
  /**
1604
1776
  * @public
1605
1777
  */
1606
- declare interface NodeSpecOptions<NodeName extends string = string> extends NodeSpec {
1778
+ declare interface NodeSpecOptions<NodeName extends string = string, Attrs extends AnyAttrs = AnyAttrs> extends NodeSpec {
1779
+ /**
1780
+ * The name of the node type.
1781
+ */
1607
1782
  name: NodeName;
1783
+ /**
1784
+ * Whether this is the top-level node type. Only one node type can be the
1785
+ * top-level node type in a schema.
1786
+ */
1608
1787
  topNode?: boolean;
1788
+ /**
1789
+ * The attributes that nodes of this type get.
1790
+ */
1791
+ attrs?: {
1792
+ [key in keyof Attrs]: AttrSpec<Attrs[key]>;
1793
+ };
1609
1794
  }
1610
1795
  export { NodeSpecOptions }
1611
1796
  export { NodeSpecOptions as NodeSpecOptions_alias_1 }
1612
1797
 
1798
+ /**
1799
+ * @internal
1800
+ */
1801
+ declare interface NodeTyping {
1802
+ [name: string]: Record<string, any>;
1803
+ }
1804
+ export { NodeTyping }
1805
+ export { NodeTyping as NodeTyping_alias_1 }
1806
+
1613
1807
  /**
1614
1808
  * @internal
1615
1809
  */
@@ -1674,14 +1868,14 @@ export declare type Payloads<T> = Tuple5<T[]>;
1674
1868
  /**
1675
1869
  * @internal
1676
1870
  */
1677
- export declare type PickKnownCommandTyping<T extends CommandTyping> = [
1678
- CommandTyping
1679
- ] extends [T] ? never : T;
1871
+ export declare type PickStringLiteral<T> = PickSubType<T, string>;
1680
1872
 
1681
1873
  /**
1682
1874
  * @internal
1683
1875
  */
1684
- export declare type PickStringLiteral<T extends string> = [string] extends [T] ? never : T;
1876
+ declare type PickSubType<Type, ParentType> = Type extends ParentType ? [ParentType] extends [Type] ? never : Type : never;
1877
+ export { PickSubType }
1878
+ export { PickSubType as PickSubType_alias_1 }
1685
1879
 
1686
1880
  /**
1687
1881
  * @internal
@@ -1899,8 +2093,16 @@ export declare function setupEditorExtension<E extends Extension>(options: Edito
1899
2093
  */
1900
2094
  export declare function setupTest(): {
1901
2095
  editor: TestEditor<Extension<{
1902
- Nodes: "text" | "doc" | "paragraph" | "heading";
1903
- Marks: "bold" | "italic";
2096
+ Nodes: SimplifyDeeper< {
2097
+ paragraph: Attrs_2;
2098
+ doc: Attrs_2;
2099
+ text: Attrs_2;
2100
+ heading: Attrs_2;
2101
+ }>;
2102
+ Marks: SimplifyDeeper< {
2103
+ bold: Attrs_2;
2104
+ italic: Attrs_2;
2105
+ }>;
1904
2106
  Commands: {
1905
2107
  insertText: [{
1906
2108
  text: string;
@@ -1921,8 +2123,28 @@ export declare function setupTest(): {
1921
2123
  readonly redo: [];
1922
2124
  };
1923
2125
  }>>;
1924
- n: Record<"text" | "doc" | "paragraph" | "heading", NodeBuilder>;
1925
- m: Record<"bold" | "italic", MarkBuilder>;
2126
+ n: ToNodeAction<SimplifyDeeper< {
2127
+ paragraph: {
2128
+ readonly [x: string]: any;
2129
+ };
2130
+ doc: {
2131
+ readonly [x: string]: any;
2132
+ };
2133
+ text: {
2134
+ readonly [x: string]: any;
2135
+ };
2136
+ heading: {
2137
+ readonly [x: string]: any;
2138
+ };
2139
+ }>>;
2140
+ m: ToMarkAction<SimplifyDeeper< {
2141
+ bold: {
2142
+ readonly [x: string]: any;
2143
+ };
2144
+ italic: {
2145
+ readonly [x: string]: any;
2146
+ };
2147
+ }>>;
1926
2148
  };
1927
2149
 
1928
2150
  /**
@@ -1930,9 +2152,18 @@ export declare function setupTest(): {
1930
2152
  */
1931
2153
  export declare function setupTestFromExtension<E extends Extension>(extension: E): {
1932
2154
  editor: TestEditor<E>;
1933
- n: Record<ExtractNodes<E>, NodeBuilder>;
1934
- m: Record<ExtractMarks<E>, MarkBuilder>;
2155
+ n: ExtractNodeActions<E>;
2156
+ m: ExtractMarkActions<E>;
2157
+ };
2158
+
2159
+ /**
2160
+ * @internal
2161
+ */
2162
+ declare type SimplifyDeeper<T> = {
2163
+ [KeyType in keyof T]: Simplify<T[KeyType]>;
1935
2164
  };
2165
+ export { SimplifyDeeper }
2166
+ export { SimplifyDeeper as SimplifyDeeper_alias_1 }
1936
2167
 
1937
2168
  /**
1938
2169
  * @internal
@@ -2034,8 +2265,8 @@ declare type TextInputHandler = (view: EditorView, from: number, to: number, tex
2034
2265
  export { TextInputHandler }
2035
2266
  export { TextInputHandler as TextInputHandler_alias_1 }
2036
2267
 
2037
- export declare type ToCommandApplier<T extends CommandTyping> = {
2038
- [K in keyof T]: CommandApplier<T[K]>;
2268
+ export declare type ToCommandAction<T extends CommandTyping> = {
2269
+ [K in keyof T]: CommandAction<T[K]>;
2039
2270
  };
2040
2271
 
2041
2272
  export declare type ToCommandCreators<T extends CommandTyping> = {
@@ -2087,6 +2318,24 @@ declare interface ToggleNodeOptions {
2087
2318
  export { ToggleNodeOptions }
2088
2319
  export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
2089
2320
 
2321
+ /**
2322
+ * @internal
2323
+ */
2324
+ declare type ToMarkAction<T extends MarkTyping> = {
2325
+ [K in keyof T]: MarkAction<T[K]>;
2326
+ };
2327
+ export { ToMarkAction }
2328
+ export { ToMarkAction as ToMarkAction_alias_1 }
2329
+
2330
+ /**
2331
+ * @internal
2332
+ */
2333
+ declare type ToNodeAction<T extends NodeTyping> = {
2334
+ [K in keyof T]: NodeAction<T[K]>;
2335
+ };
2336
+ export { ToNodeAction }
2337
+ export { ToNodeAction as ToNodeAction_alias_1 }
2338
+
2090
2339
  export declare function toReversed<T>(arr: T[]): T[];
2091
2340
 
2092
2341
  declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
@@ -625,7 +625,7 @@ function deepEquals(a, b) {
625
625
  return false;
626
626
  }
627
627
 
628
- // src/editor/builder.ts
628
+ // src/editor/action.ts
629
629
  import "@prosekit/pm/model";
630
630
 
631
631
  // src/utils/attrs-match.ts
@@ -652,8 +652,8 @@ function isNodeActive(state, type, attrs) {
652
652
  return false;
653
653
  }
654
654
 
655
- // src/editor/builder.ts
656
- function createNodeBuilders(schema, getState, createNode = defaultCreateNode) {
655
+ // src/editor/action.ts
656
+ function createNodeActions(schema, getState, createNode = defaultCreateNode) {
657
657
  const builders = {};
658
658
  for (const type of Object.values(schema.nodes)) {
659
659
  const builder = (...args) => buildNode(type, args, createNode);
@@ -665,7 +665,7 @@ function createNodeBuilders(schema, getState, createNode = defaultCreateNode) {
665
665
  }
666
666
  return builders;
667
667
  }
668
- function createMarkBuilders(schema, getState, applyMark = defaultApplyMark) {
668
+ function createMarkActions(schema, getState, applyMark = defaultApplyMark) {
669
669
  const builders = {};
670
670
  for (const type of Object.values(schema.marks)) {
671
671
  const builder = (...args) => buildMark(type, args, applyMark);
@@ -751,7 +751,7 @@ function createEditor(options) {
751
751
  var EditorInstance = class {
752
752
  constructor(extension) {
753
753
  this.view = null;
754
- this.commandAppliers = {};
754
+ this.commands = {};
755
755
  this.getState = () => {
756
756
  var _a;
757
757
  return ((_a = this.view) == null ? void 0 : _a.state) || this.directEditorProps.state;
@@ -767,8 +767,8 @@ var EditorInstance = class {
767
767
  this.defineCommand(name, commandCreator);
768
768
  }
769
769
  }
770
- this.nodeBuilders = createNodeBuilders(state.schema, this.getState);
771
- this.markBuilders = createMarkBuilders(state.schema, this.getState);
770
+ this.nodes = createNodeActions(state.schema, this.getState);
771
+ this.marks = createMarkActions(state.schema, this.getState);
772
772
  this.schema = state.schema;
773
773
  this.directEditorProps = { state, ...payload.view };
774
774
  }
@@ -852,13 +852,13 @@ var EditorInstance = class {
852
852
  view.setProps({ state: newState });
853
853
  }
854
854
  defineCommand(name, commandCreator) {
855
- const applier = (...args) => {
855
+ const action = (...args) => {
856
856
  const view = this.view;
857
857
  assert(view, `Cannot call command "${name}" before the editor is mounted`);
858
858
  const command = commandCreator(...args);
859
859
  return command(view.state, view.dispatch.bind(view), view);
860
860
  };
861
- applier.canApply = (...args) => {
861
+ action.canApply = (...args) => {
862
862
  const view = this.view;
863
863
  if (!view) {
864
864
  return false;
@@ -866,10 +866,10 @@ var EditorInstance = class {
866
866
  const command = commandCreator(...args);
867
867
  return command(view.state, void 0, view);
868
868
  };
869
- this.commandAppliers[name] = applier;
869
+ this.commands[name] = action;
870
870
  }
871
871
  removeCommand(name) {
872
- delete this.commandAppliers[name];
872
+ delete this.commands[name];
873
873
  }
874
874
  };
875
875
  var Editor = class _Editor {
@@ -910,12 +910,6 @@ var Editor = class _Editor {
910
910
  get schema() {
911
911
  return this.instance.schema;
912
912
  }
913
- /**
914
- * All commands defined by the editor.
915
- */
916
- get commands() {
917
- return this.instance.commandAppliers;
918
- }
919
913
  /**
920
914
  * Whether the editor is focused.
921
915
  */
@@ -995,11 +989,23 @@ var Editor = class _Editor {
995
989
  updateState(state) {
996
990
  this.instance.updateState(state);
997
991
  }
992
+ /**
993
+ * All {@link CommandAction}s defined by the editor.
994
+ */
995
+ get commands() {
996
+ return this.instance.commands;
997
+ }
998
+ /**
999
+ * All {@link NodeAction}s defined by the editor.
1000
+ */
998
1001
  get nodes() {
999
- return this.instance.nodeBuilders;
1002
+ return this.instance.nodes;
1000
1003
  }
1004
+ /**
1005
+ * All {@link MarkAction}s defined by the editor.
1006
+ */
1001
1007
  get marks() {
1002
- return this.instance.markBuilders;
1008
+ return this.instance.marks;
1003
1009
  }
1004
1010
  };
1005
1011
 
@@ -1037,8 +1043,8 @@ export {
1037
1043
  isTextSelection,
1038
1044
  isNodeSelection,
1039
1045
  isAllSelection,
1040
- createNodeBuilders,
1041
- createMarkBuilders,
1046
+ createNodeActions,
1047
+ createMarkActions,
1042
1048
  union,
1043
1049
  setupEditorExtension,
1044
1050
  createEditor,
@@ -2,10 +2,10 @@ import {
2
2
  Editor,
3
3
  EditorInstance,
4
4
  assert,
5
- createMarkBuilders,
6
- createNodeBuilders,
5
+ createMarkActions,
6
+ createNodeActions,
7
7
  setupEditorExtension
8
- } from "./chunk-UDQXAK7F.js";
8
+ } from "./chunk-52BNHWWJ.js";
9
9
 
10
10
  // src/test/test-editor.ts
11
11
  import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
@@ -82,16 +82,8 @@ function getSelection(doc) {
82
82
  var TestEditorInstance = class extends EditorInstance {
83
83
  constructor(extension) {
84
84
  super(extension);
85
- this.nodeBuilders = createNodeBuilders(
86
- this.schema,
87
- this.getState,
88
- createNodeForTest
89
- );
90
- this.markBuilders = createMarkBuilders(
91
- this.schema,
92
- this.getState,
93
- applyMarkForTest
94
- );
85
+ this.nodes = createNodeActions(this.schema, this.getState, createNodeForTest);
86
+ this.marks = createMarkActions(this.schema, this.getState, applyMarkForTest);
95
87
  }
96
88
  };
97
89
  var TestEditor = class extends Editor {
@@ -22,8 +22,11 @@ export { unsetMark } from './_tsup-dts-rollup';
22
22
  export { UnsetMarkOptions } from './_tsup-dts-rollup';
23
23
  export { wrap } from './_tsup-dts-rollup';
24
24
  export { WrapOptions } from './_tsup-dts-rollup';
25
+ export { MarkAction } from './_tsup-dts-rollup';
25
26
  export { MarkBuilder } from './_tsup-dts-rollup';
27
+ export { NodeAction } from './_tsup-dts-rollup';
26
28
  export { NodeBuilder } from './_tsup-dts-rollup';
29
+ export { NodeChild } from './_tsup-dts-rollup';
27
30
  export { Editor } from './_tsup-dts-rollup';
28
31
  export { createEditor } from './_tsup-dts-rollup';
29
32
  export { EditorOptions } from './_tsup-dts-rollup';
@@ -101,20 +104,32 @@ export { defineText } from './_tsup-dts-rollup';
101
104
  export { defineFacet } from './_tsup-dts-rollup';
102
105
  export { Facet } from './_tsup-dts-rollup';
103
106
  export { defineFacetPayload } from './_tsup-dts-rollup';
107
+ export { AnyAttrs } from './_tsup-dts-rollup';
108
+ export { AttrSpec } from './_tsup-dts-rollup';
104
109
  export { BaseNodeViewOptions } from './_tsup-dts-rollup';
105
- export { CommandTyping } from './_tsup-dts-rollup';
106
110
  export { Extension } from './_tsup-dts-rollup';
107
111
  export { ExtensionTyping } from './_tsup-dts-rollup';
112
+ export { ExtractCommandActions } from './_tsup-dts-rollup';
108
113
  export { ExtractCommandAppliers } from './_tsup-dts-rollup';
109
114
  export { ExtractCommandCreators } from './_tsup-dts-rollup';
115
+ export { ExtractMarkActions } from './_tsup-dts-rollup';
110
116
  export { ExtractMarks } from './_tsup-dts-rollup';
117
+ export { ExtractNodeActions } from './_tsup-dts-rollup';
111
118
  export { ExtractNodes } from './_tsup-dts-rollup';
112
119
  export { UnionExtension } from './_tsup-dts-rollup';
120
+ export { CommandAction } from './_tsup-dts-rollup';
121
+ export { CommandTyping } from './_tsup-dts-rollup';
122
+ export { MarkTyping } from './_tsup-dts-rollup';
123
+ export { ToMarkAction } from './_tsup-dts-rollup';
124
+ export { NodeTyping } from './_tsup-dts-rollup';
125
+ export { ToNodeAction } from './_tsup-dts-rollup';
113
126
  export { NodeJSON } from './_tsup-dts-rollup';
114
127
  export { SelectionJSON } from './_tsup-dts-rollup';
115
128
  export { StateJSON } from './_tsup-dts-rollup';
116
129
  export { StepJSON } from './_tsup-dts-rollup';
130
+ export { PickSubType } from './_tsup-dts-rollup';
117
131
  export { Priority } from './_tsup-dts-rollup';
132
+ export { SimplifyDeeper } from './_tsup-dts-rollup';
118
133
  export { SimplifyUnion } from './_tsup-dts-rollup';
119
134
  export { assert } from './_tsup-dts-rollup';
120
135
  export { canUseRegexLookbehind } from './_tsup-dts-rollup';
@@ -35,11 +35,10 @@ import {
35
35
  stateFromJSON,
36
36
  toReversed,
37
37
  union
38
- } from "./chunk-UDQXAK7F.js";
38
+ } from "./chunk-52BNHWWJ.js";
39
39
 
40
40
  // src/commands/add-mark.ts
41
41
  import "@prosekit/pm/model";
42
- import "@prosekit/pm/state";
43
42
  function addMark(options) {
44
43
  return (state, dispatch) => {
45
44
  var _a, _b;
@@ -108,7 +107,6 @@ function expandMarkAfter($pos, predicate) {
108
107
  }
109
108
 
110
109
  // src/commands/insert-node.ts
111
- import "@prosekit/pm/state";
112
110
  import { insertPoint } from "@prosekit/pm/transform";
113
111
 
114
112
  // src/utils/set-selection-around.ts
@@ -143,7 +141,6 @@ function insertNode(options) {
143
141
 
144
142
  // src/commands/remove-mark.ts
145
143
  import "@prosekit/pm/model";
146
- import "@prosekit/pm/state";
147
144
  function removeMark(options) {
148
145
  return (state, dispatch) => {
149
146
  var _a, _b;
@@ -192,9 +189,6 @@ function removeNode(options) {
192
189
  };
193
190
  }
194
191
 
195
- // src/commands/set-block-type.ts
196
- import "@prosekit/pm/state";
197
-
198
192
  // src/utils/get-custom-selection.ts
199
193
  import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
200
194
  function getCustomSelection(state, from, to) {
@@ -366,7 +360,6 @@ function toggleMark({ type, attrs }) {
366
360
  // src/commands/toggle-node.ts
367
361
  import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
368
362
  import "@prosekit/pm/model";
369
- import "@prosekit/pm/state";
370
363
  function toggleNode({ type, attrs }) {
371
364
  return (state, dispatch, view) => {
372
365
  if (isNodeActive(state, type, attrs)) {
@@ -426,7 +419,6 @@ function unsetTextBlockType(tr, from, to) {
426
419
  }
427
420
 
428
421
  // src/commands/unset-mark.ts
429
- import "@prosekit/pm/state";
430
422
  function unsetMark(options) {
431
423
  return (state, dispatch) => {
432
424
  var _a, _b;
@@ -440,7 +432,6 @@ function unsetMark(options) {
440
432
 
441
433
  // src/commands/wrap.ts
442
434
  import "@prosekit/pm/model";
443
- import "@prosekit/pm/state";
444
435
  import { findWrapping } from "@prosekit/pm/transform";
445
436
  function wrap({ nodeType, attrs }) {
446
437
  return (state, dispatch) => {
@@ -1163,7 +1154,6 @@ var markSpecFacet = defineFacet({
1163
1154
 
1164
1155
  // src/extensions/node-view.ts
1165
1156
  import { PluginKey as PluginKey5, ProseMirrorPlugin as ProseMirrorPlugin5 } from "@prosekit/pm/state";
1166
- import "@prosekit/pm/view";
1167
1157
  function defineNodeView(options) {
1168
1158
  return defineFacetPayload(nodeViewFacet, [options]);
1169
1159
  }
@@ -1187,7 +1177,6 @@ var nodeViewFacet = defineFacet({
1187
1177
 
1188
1178
  // src/extensions/node-view-effect.ts
1189
1179
  import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
1190
- import "@prosekit/pm/view";
1191
1180
  function defineNodeViewFactory(options) {
1192
1181
  const input = [options, null];
1193
1182
  return defineFacetPayload(nodeViewFactoryFacet, [input]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.7.4",
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.21.0",
46
+ "type-fest": "^4.22.1",
47
47
  "@prosekit/pm": "^0.1.6"
48
48
  },
49
49
  "devDependencies": {
50
- "tsup": "^8.1.0",
50
+ "tsup": "^8.1.2",
51
51
  "typescript": "^5.5.3",
52
- "vitest": "^2.0.2",
52
+ "vitest": "^2.0.3",
53
53
  "@prosekit/dev": "0.0.0"
54
54
  },
55
55
  "scripts": {