@prosekit/core 0.4.2 → 0.5.0

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.
@@ -30,7 +30,7 @@ import { Plugin as Plugin_2 } from '@prosekit/pm/state';
30
30
  import { ProseMirrorFragment } from '@prosekit/pm/model';
31
31
  import { ProseMirrorNode } from '@prosekit/pm/model';
32
32
  import { Schema } from '@prosekit/pm/model';
33
- import type { SchemaSpec } from '@prosekit/pm/model';
33
+ import { SchemaSpec } from '@prosekit/pm/model';
34
34
  import { Selection as Selection_2 } from '@prosekit/pm/state';
35
35
  import { Selection as Selection_3 } from 'prosemirror-state';
36
36
  import type { Simplify } from 'type-fest';
@@ -72,6 +72,23 @@ export { addMark as addMark_alias_1 }
72
72
 
73
73
  export declare function applyAction(operator: Action): Command;
74
74
 
75
+ /**
76
+ * @internal
77
+ */
78
+ export declare function arrayRemove<T>(array: T[], item: T): void;
79
+
80
+ /**
81
+ * @internal
82
+ */
83
+ export declare function arraySubstract<T>(a: T[], b: T[]): T[];
84
+
85
+ /**
86
+ * @internal
87
+ */
88
+ declare function assert(condition: unknown, message?: string): asserts condition;
89
+ export { assert }
90
+ export { assert as assert_alias_1 }
91
+
75
92
  /**
76
93
  * Utility function assert that two types are equal in tests.
77
94
  */
@@ -79,26 +96,27 @@ export declare function assertTypeEqual<T, U>(_val: IsEqual<T, U>): void;
79
96
 
80
97
  export declare function attrsMatch(nodeOrMark: ProseMirrorNode | Mark, attrs: Attrs): boolean;
81
98
 
99
+ /**
100
+ * @internal
101
+ */
82
102
  export declare abstract class BaseExtension<T extends ExtensionTyping = ExtensionTyping> implements Extension<T> {
83
103
  extension: Extension | Extension[];
84
104
  priority?: Priority;
85
105
  _type?: T;
106
+ private trees;
86
107
  /**
87
108
  * @internal
88
- *
89
- * Whether this extension has payload that can be converted to a schema.
90
- *
91
- * Notice that this does not mean that the extension has a schema. For
92
- * example, a `FacetExtension` with a `schemaFacet` will return `true` for
93
- * this property, but will return `null` for `schema`.
94
109
  */
95
- abstract hasSchema: boolean;
110
+ abstract createTree(priority: Priority): FacetNode;
111
+ /**
112
+ * @internal
113
+ */
114
+ getTree(priority?: Priority): FacetNode;
96
115
  /**
97
116
  * @internal
98
- *
99
- * The schema that this extension represents.
100
117
  */
101
- abstract schema: Schema | null;
118
+ findFacetOutput<I, O>(facet: Facet<I, O>): Tuple5<O | null> | null;
119
+ get schema(): Schema | null;
102
120
  }
103
121
 
104
122
  /**
@@ -180,14 +198,10 @@ export declare interface CommandCreators {
180
198
  [name: string]: CommandCreator;
181
199
  }
182
200
 
183
- export declare const commandFacet: Facet<CommandCreators, CommandCreators>;
201
+ export declare const commandFacet: Facet<CommandCreators, RootPayload>;
184
202
 
185
203
  export declare type CommandPayload = CommandCreators;
186
204
 
187
- export declare type Converters = ConverterTuple[];
188
-
189
- declare type ConverterTuple = Tuple5<FacetConverter | undefined>;
190
-
191
205
  /**
192
206
  * @public
193
207
  */
@@ -199,6 +213,8 @@ export declare function createMarkBuilder(getState: () => EditorState | null | u
199
213
 
200
214
  export declare function createNodeBuilder(getState: () => EditorState | null | undefined, type: NodeType): NodeBuilder;
201
215
 
216
+ export declare function deepEquals<T>(a: T, b: T): boolean;
217
+
202
218
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
203
219
 
204
220
  export declare const default_alias_1: {
@@ -268,7 +284,7 @@ declare function defineBaseCommands(): Extension<{
268
284
  to?: number | undefined;
269
285
  }];
270
286
  setNodeAttrs: [options: {
271
- type: string | NodeType_2;
287
+ type: string | NodeType_2 | string[] | NodeType_2[];
272
288
  attrs: Attrs_2;
273
289
  pos?: number | undefined;
274
290
  }];
@@ -390,6 +406,40 @@ declare function defineDropHandler(handler: DropHandler): Extension<ExtensionTyp
390
406
  export { defineDropHandler }
391
407
  export { defineDropHandler as defineDropHandler_alias_1 }
392
408
 
409
+ /**
410
+ * @internal
411
+ */
412
+ declare function defineFacet<Input, Output>(options: {
413
+ /**
414
+ * The parent facet in the tree.
415
+ */
416
+ parent: Facet<Output, any>;
417
+ /**
418
+ * Set this to true if you only want to keep one facet payload. For example,
419
+ * this facet corresponds to a ProseMirror plugin with a key.
420
+ */
421
+ singleton?: boolean;
422
+ /**
423
+ * A reducer is a function that accepts an array of input and produce a single
424
+ * output.
425
+ */
426
+ reducer?: FacetReducer<Input, Output>;
427
+ /**
428
+ * A callback function that returns a reducer. This is useful if you want to
429
+ * store something in the closure.
430
+ */
431
+ reduce?: () => FacetReducer<Input, Output>;
432
+ }): Facet<Input, Output>;
433
+ export { defineFacet }
434
+ export { defineFacet as defineFacet_alias_1 }
435
+
436
+ /**
437
+ * @internal
438
+ */
439
+ declare function defineFacetPayload<Input>(facet: Facet<Input, any>, payloads: Input[]): Extension;
440
+ export { defineFacetPayload }
441
+ export { defineFacetPayload as defineFacetPayload_alias_1 }
442
+
393
443
  /**
394
444
  * Registers a event handler that is called when the editor gains or loses focus.
395
445
  *
@@ -884,9 +934,11 @@ export declare type ExtractNodesFromTyping<T extends ExtensionTyping> = ExtractK
884
934
  export declare type ExtractTyping<E extends Extension> = E extends Extension<infer T> ? T : never;
885
935
 
886
936
  /**
887
- * @public
937
+ * @internal
888
938
  */
889
939
  declare class Facet<Input, Output> {
940
+ private _reducer?;
941
+ private _reduce?;
890
942
  /**
891
943
  * @internal
892
944
  */
@@ -894,61 +946,61 @@ declare class Facet<Input, Output> {
894
946
  /**
895
947
  * @internal
896
948
  */
897
- readonly converter: () => FacetConverter<Input, Output>;
898
- /**
899
- * @internal
900
- */
901
- readonly next: Facet<Output, any> | null;
949
+ readonly parent: Facet<Output, any> | null;
902
950
  /**
903
951
  * @internal
904
952
  */
905
953
  readonly singleton: boolean;
906
954
  /**
955
+ * A index path to retrieve the current facet in a tree from the root.
956
+ *
907
957
  * @internal
908
958
  */
909
- isSchema: boolean;
910
- private constructor();
911
- static define<Input, Output>({ converter, convert, next, singleton, }: FacetOptions<Input, Output>): Facet<Input, Output>;
959
+ readonly path: number[];
912
960
  /**
913
961
  * @internal
914
962
  */
915
- static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
916
- extension(payloads: Input[]): Extension;
963
+ constructor(parent: Facet<Output, any> | null, singleton: boolean, _reducer?: FacetReducer<Input, Output> | undefined, _reduce?: (() => FacetReducer<Input, Output>) | undefined);
964
+ get reducer(): FacetReducer<Input, Output>;
917
965
  }
918
966
  export { Facet }
919
967
  export { Facet as Facet_alias_1 }
920
968
 
921
969
  /**
922
- * @public
923
- */
924
- export declare interface FacetConverter<Input = any, Output = any> {
925
- create: (inputs: Input[]) => Output;
926
- update: (inputs: Input[]) => Output | null;
927
- }
928
-
929
- /**
930
- * @public
970
+ * @internal
931
971
  */
932
972
  export declare class FacetExtensionImpl<Input, Output> extends BaseExtension {
933
973
  readonly facet: Facet<Input, Output>;
934
974
  readonly payloads: Input[];
935
975
  extension: Extension;
936
- hasSchema: boolean;
937
- schema: null;
976
+ /**
977
+ * @internal
978
+ */
938
979
  constructor(facet: Facet<Input, Output>, payloads: Input[]);
980
+ /**
981
+ * @internal
982
+ */
983
+ createTree(priority: Priority): FacetNode<any, any>;
984
+ }
985
+
986
+ export declare class FacetNode<I = any, O = any> {
987
+ readonly facet: Facet<I, O>;
988
+ readonly inputs: Tuple5<I[] | null>;
989
+ readonly children: Map<number, FacetNode>;
990
+ reducers: Tuple5<FacetReducer<I, O> | null>;
991
+ output: Tuple5<O | null> | null;
992
+ constructor(facet: Facet<I, O>, inputs?: Tuple5<I[] | null>, children?: Map<number, FacetNode>);
993
+ private calcOutput;
994
+ getOutput(): Tuple5<O | null>;
995
+ getSingletonOutput(): O | null;
996
+ getRootOutput(): RootOutput;
997
+ isRoot(): boolean;
939
998
  }
940
999
 
941
1000
  /**
942
- * @public
1001
+ * @internal
943
1002
  */
944
- declare interface FacetOptions<Input, Output> {
945
- convert?: (payloads: Input[]) => Output;
946
- converter?: () => FacetConverter<Input, Output>;
947
- next: Facet<Output, any>;
948
- singleton?: boolean;
949
- }
950
- export { FacetOptions }
951
- export { FacetOptions as FacetOptions_alias_1 }
1003
+ export declare type FacetReducer<Input, Output> = (input: Input[]) => Output;
952
1004
 
953
1005
  export declare function findBrowserDocument(options?: {
954
1006
  document?: Document;
@@ -979,8 +1031,6 @@ export declare function getBrowserWindow(options?: {
979
1031
 
980
1032
  export declare function getCustomSelection(state: EditorState, from?: number | null, to?: number | null): Selection_3;
981
1033
 
982
- export declare function getFacetCount(): number;
983
-
984
1034
  /**
985
1035
  * Returns a unique id in the current process that can be used in various places.
986
1036
  *
@@ -1004,6 +1054,11 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
1004
1054
  export { getNodeType }
1005
1055
  export { getNodeType as getNodeType_alias_1 }
1006
1056
 
1057
+ /**
1058
+ * @internal
1059
+ */
1060
+ export declare function getNodeTypes(schema: Schema, types: string | NodeType | string[] | NodeType[]): NodeType[];
1061
+
1007
1062
  export declare type GroupedEntries<T extends Record<string, any>> = {
1008
1063
  [K in keyof T]?: T[K][];
1009
1064
  };
@@ -1076,6 +1131,13 @@ declare function isAllSelection(sel: Selection_2): sel is AllSelection;
1076
1131
  export { isAllSelection }
1077
1132
  export { isAllSelection as isAllSelection_alias_1 }
1078
1133
 
1134
+ /**
1135
+ * @private
1136
+ */
1137
+ declare const isApple: boolean;
1138
+ export { isApple }
1139
+ export { isApple as isApple_alias_1 }
1140
+
1079
1141
  export declare function isElement(value: unknown): value is Element;
1080
1142
 
1081
1143
  /**
@@ -1087,8 +1149,6 @@ declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
1087
1149
  export { isInCodeBlock }
1088
1150
  export { isInCodeBlock as isInCodeBlock_alias_1 }
1089
1151
 
1090
- export declare const isMac: boolean;
1091
-
1092
1152
  /**
1093
1153
  * @internal
1094
1154
  */
@@ -1291,8 +1351,19 @@ declare interface NodeAttrOptions {
1291
1351
  * of a type that has them is created.
1292
1352
  */
1293
1353
  default?: any;
1354
+ /**
1355
+ * Whether the attribute should be kept when the node is split. Set it to
1356
+ * `true` if you want to inherit the attribute from the previous node when
1357
+ * splitting the node by pressing `Enter`.
1358
+ *
1359
+ * @default undefined
1360
+ */
1361
+ splittable?: boolean;
1294
1362
  /**
1295
1363
  * Returns the attribute key and value to be set on the DOM node.
1364
+ *
1365
+ * If the `key` is `"style"`, the value is a string of CSS properties and will
1366
+ * be prepended to the existing `style` attribute on the DOM node.
1296
1367
  */
1297
1368
  toDOM?: (value: any) => [key: string, value: string] | null | void;
1298
1369
  /**
@@ -1415,11 +1486,10 @@ declare type PasteHandler = (view: EditorView, event: ClipboardEvent, slice: Sli
1415
1486
  export { PasteHandler }
1416
1487
  export { PasteHandler as PasteHandler_alias_1 }
1417
1488
 
1418
- declare type Payload = unknown;
1419
-
1420
- export declare type Payloads = PayloadTuple[];
1421
-
1422
- declare type PayloadTuple = Tuple5<Payload[]>;
1489
+ /**
1490
+ * @internal
1491
+ */
1492
+ export declare type Payloads<T> = Tuple5<T[]>;
1423
1493
 
1424
1494
  /**
1425
1495
  * @internal
@@ -1431,9 +1501,9 @@ export { pluginFacet as pluginFacet_alias_1 }
1431
1501
  /**
1432
1502
  * @internal
1433
1503
  */
1434
- declare type PluginPayload = (context: {
1504
+ declare type PluginPayload = Plugin_2 | Plugin_2[] | ((context: {
1435
1505
  schema: Schema;
1436
- }) => Plugin_2 | Plugin_2[];
1506
+ }) => Plugin_2 | Plugin_2[]);
1437
1507
  export { PluginPayload }
1438
1508
  export { PluginPayload as PluginPayload_alias_1 }
1439
1509
 
@@ -1443,11 +1513,11 @@ export { PluginPayload as PluginPayload_alias_1 }
1443
1513
  * @public
1444
1514
  */
1445
1515
  declare enum Priority {
1446
- lowest = 4,
1447
- low = 3,
1516
+ lowest = 0,
1517
+ low = 1,
1448
1518
  default = 2,
1449
- high = 1,
1450
- highest = 0
1519
+ high = 3,
1520
+ highest = 4
1451
1521
  }
1452
1522
  export { Priority }
1453
1523
  export { Priority as Priority_alias_1 }
@@ -1488,9 +1558,27 @@ declare function removeMark(options: {
1488
1558
  export { removeMark }
1489
1559
  export { removeMark as removeMark_alias_1 }
1490
1560
 
1491
- export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
1561
+ export declare const rootFacet: Facet<RootPayload, RootOutput>;
1562
+
1563
+ export declare type RootOutput = {
1564
+ schema?: Schema | null;
1565
+ commands?: CommandCreators;
1566
+ state?: EditorStateConfig;
1567
+ view?: Omit<DirectEditorProps, 'state'>;
1568
+ };
1569
+
1570
+ export declare type RootPayload = {
1571
+ schema?: Schema | null;
1572
+ commands?: CommandCreators;
1573
+ state?: (ctx: {
1574
+ schema: Schema;
1575
+ }) => EditorStateConfig;
1576
+ view?: Omit<DirectEditorProps, 'state'>;
1577
+ };
1578
+
1579
+ export declare const schemaFacet: Facet<SchemaSpec<any, any>, RootPayload>;
1492
1580
 
1493
- export declare type SchemaPayload = SchemaSpec;
1581
+ export declare const schemaSpecFacet: Facet<SchemaSpec<any, any>, SchemaSpec<any, any>>;
1494
1582
 
1495
1583
  declare type ScrollToSelectionHandler = (view: EditorView) => boolean;
1496
1584
  export { ScrollToSelectionHandler }
@@ -1542,7 +1630,7 @@ declare function setNodeAttrs(options: {
1542
1630
  *
1543
1631
  * If current node is not of this type, the command will do nothing.
1544
1632
  */
1545
- type: string | NodeType;
1633
+ type: string | NodeType | string[] | NodeType[];
1546
1634
  /**
1547
1635
  * The attributes to set.
1548
1636
  */
@@ -1581,7 +1669,14 @@ declare type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
1581
1669
  export { SimplifyUnion }
1582
1670
  export { SimplifyUnion as SimplifyUnion_alias_1 }
1583
1671
 
1584
- export declare const stateFacet: Facet<StatePayload, StatePayload>;
1672
+ export declare function splitBlockAs(splitNode?: (node: ProseMirrorNode, deflt: NodeType | null, atEnd: boolean) => {
1673
+ type: NodeType;
1674
+ attrs?: Attrs;
1675
+ } | null): Command;
1676
+
1677
+ export declare const splitBlockEnter: Command;
1678
+
1679
+ export declare const stateFacet: Facet<StatePayload, RootPayload>;
1585
1680
 
1586
1681
  /**
1587
1682
  * Parse a JSON object to a ProseMirror state.
@@ -1614,6 +1709,8 @@ export declare type StatePayload = (ctx: {
1614
1709
  schema: Schema;
1615
1710
  }) => EditorStateConfig;
1616
1711
 
1712
+ export declare function subtractFacetNode<I, O>(a: FacetNode<I, O>, b: FacetNode<I, O>): FacetNode<I, O>;
1713
+
1617
1714
  declare type TextInputHandler = (view: EditorView, from: number, to: number, text: string) => boolean | void;
1618
1715
  export { TextInputHandler }
1619
1716
  export { TextInputHandler as TextInputHandler_alias_1 }
@@ -1655,6 +1752,8 @@ declare function toggleNode({ type, attrs, }: {
1655
1752
  export { toggleNode }
1656
1753
  export { toggleNode as toggleNode_alias_1 }
1657
1754
 
1755
+ export declare function toReversed<T>(arr: T[]): T[];
1756
+
1658
1757
  declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
1659
1758
  export { TripleClickHandler }
1660
1759
  export { TripleClickHandler as TripleClickHandler_alias_1 }
@@ -1663,7 +1762,10 @@ declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_3
1663
1762
  export { TripleClickOnHandler }
1664
1763
  export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
1665
1764
 
1666
- declare type Tuple5<T> = [T, T, T, T, T];
1765
+ /**
1766
+ * @internal
1767
+ */
1768
+ export declare type Tuple5<T> = [T, T, T, T, T];
1667
1769
 
1668
1770
  /**
1669
1771
  * Merge multiple extensions into one.
@@ -1676,13 +1778,18 @@ export { union as union_alias_1 }
1676
1778
 
1677
1779
  export declare class UnionExtensionImpl<T extends ExtensionTyping = ExtensionTyping> extends BaseExtension<T> implements Extension<T> {
1678
1780
  extension: BaseExtension[];
1679
- private _schema;
1680
- private hasSchemaCount;
1781
+ /**
1782
+ * @internal
1783
+ */
1681
1784
  constructor(extension?: BaseExtension[]);
1682
- get hasSchema(): boolean;
1683
- get schema(): Schema | null;
1785
+ /**
1786
+ * @internal
1787
+ */
1788
+ createTree(priority: Priority): FacetNode;
1684
1789
  }
1685
1790
 
1791
+ export declare function unionFacetNode<I, O>(a: FacetNode<I, O>, b: FacetNode<I, O>): FacetNode<I, O>;
1792
+
1686
1793
  export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[];
1687
1794
 
1688
1795
  export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
@@ -1696,13 +1803,6 @@ declare type UnmountHandler = () => void;
1696
1803
  export { UnmountHandler }
1697
1804
  export { UnmountHandler as UnmountHandler_alias_1 }
1698
1805
 
1699
- export declare function updateExtension(prevInputs: Payloads, prevConverters: Converters, extension: Extension, mode: 'add' | 'remove'): {
1700
- schemaInput: SchemaPayload | null;
1701
- stateInput: StatePayload | null;
1702
- viewInput: ViewPayload | null;
1703
- commandInput: CommandCreators | null;
1704
- };
1705
-
1706
1806
  /**
1707
1807
  * A function that is called when the editor state is updated.
1708
1808
  *
@@ -1715,7 +1815,7 @@ declare type UpdateHandler = (view: EditorView, prevState: EditorState) => void;
1715
1815
  export { UpdateHandler }
1716
1816
  export { UpdateHandler as UpdateHandler_alias_1 }
1717
1817
 
1718
- export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
1818
+ export declare const viewFacet: Facet<ViewPayload, RootPayload>;
1719
1819
 
1720
1820
  export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
1721
1821
 
@@ -1746,4 +1846,6 @@ export declare function wrap({ nodeType, attrs, }: {
1746
1846
  attrs?: Attrs | null;
1747
1847
  }): Command;
1748
1848
 
1849
+ export declare function zip<T, P>(a: T[], b: P[]): [T, P][];
1850
+
1749
1851
  export { }
@@ -77,8 +77,9 @@ export { definePlugin } from './_tsup-dts-rollup';
77
77
  export { pluginFacet } from './_tsup-dts-rollup';
78
78
  export { PluginPayload } from './_tsup-dts-rollup';
79
79
  export { defineText } from './_tsup-dts-rollup';
80
+ export { defineFacet } from './_tsup-dts-rollup';
80
81
  export { Facet } from './_tsup-dts-rollup';
81
- export { FacetOptions } from './_tsup-dts-rollup';
82
+ export { defineFacetPayload } from './_tsup-dts-rollup';
82
83
  export { BaseNodeViewOptions } from './_tsup-dts-rollup';
83
84
  export { CommandArgs } from './_tsup-dts-rollup';
84
85
  export { Extension } from './_tsup-dts-rollup';
@@ -93,9 +94,11 @@ export { SelectionJSON } from './_tsup-dts-rollup';
93
94
  export { StateJSON } from './_tsup-dts-rollup';
94
95
  export { Priority } from './_tsup-dts-rollup';
95
96
  export { SimplifyUnion } from './_tsup-dts-rollup';
97
+ export { assert } from './_tsup-dts-rollup';
96
98
  export { canUseRegexLookbehind } from './_tsup-dts-rollup';
97
99
  export { clsx } from './_tsup-dts-rollup';
98
100
  export { defaultBlockAt } from './_tsup-dts-rollup';
101
+ export { isApple } from './_tsup-dts-rollup';
99
102
  export { _getId } from './_tsup-dts-rollup';
100
103
  export { getMarkType } from './_tsup-dts-rollup';
101
104
  export { getNodeType } from './_tsup-dts-rollup';