@prosekit/core 0.0.0-next-20240504152243 → 0.0.0-next-20240519080336

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
  };
@@ -1296,8 +1351,19 @@ declare interface NodeAttrOptions {
1296
1351
  * of a type that has them is created.
1297
1352
  */
1298
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;
1299
1362
  /**
1300
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.
1301
1367
  */
1302
1368
  toDOM?: (value: any) => [key: string, value: string] | null | void;
1303
1369
  /**
@@ -1420,11 +1486,10 @@ declare type PasteHandler = (view: EditorView, event: ClipboardEvent, slice: Sli
1420
1486
  export { PasteHandler }
1421
1487
  export { PasteHandler as PasteHandler_alias_1 }
1422
1488
 
1423
- declare type Payload = unknown;
1424
-
1425
- export declare type Payloads = PayloadTuple[];
1426
-
1427
- declare type PayloadTuple = Tuple5<Payload[]>;
1489
+ /**
1490
+ * @internal
1491
+ */
1492
+ export declare type Payloads<T> = Tuple5<T[]>;
1428
1493
 
1429
1494
  /**
1430
1495
  * @internal
@@ -1436,9 +1501,9 @@ export { pluginFacet as pluginFacet_alias_1 }
1436
1501
  /**
1437
1502
  * @internal
1438
1503
  */
1439
- declare type PluginPayload = (context: {
1504
+ declare type PluginPayload = Plugin_2 | Plugin_2[] | ((context: {
1440
1505
  schema: Schema;
1441
- }) => Plugin_2 | Plugin_2[];
1506
+ }) => Plugin_2 | Plugin_2[]);
1442
1507
  export { PluginPayload }
1443
1508
  export { PluginPayload as PluginPayload_alias_1 }
1444
1509
 
@@ -1448,11 +1513,11 @@ export { PluginPayload as PluginPayload_alias_1 }
1448
1513
  * @public
1449
1514
  */
1450
1515
  declare enum Priority {
1451
- lowest = 4,
1452
- low = 3,
1516
+ lowest = 0,
1517
+ low = 1,
1453
1518
  default = 2,
1454
- high = 1,
1455
- highest = 0
1519
+ high = 3,
1520
+ highest = 4
1456
1521
  }
1457
1522
  export { Priority }
1458
1523
  export { Priority as Priority_alias_1 }
@@ -1493,9 +1558,27 @@ declare function removeMark(options: {
1493
1558
  export { removeMark }
1494
1559
  export { removeMark as removeMark_alias_1 }
1495
1560
 
1496
- 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>;
1497
1580
 
1498
- export declare type SchemaPayload = SchemaSpec;
1581
+ export declare const schemaSpecFacet: Facet<SchemaSpec<any, any>, SchemaSpec<any, any>>;
1499
1582
 
1500
1583
  declare type ScrollToSelectionHandler = (view: EditorView) => boolean;
1501
1584
  export { ScrollToSelectionHandler }
@@ -1547,7 +1630,7 @@ declare function setNodeAttrs(options: {
1547
1630
  *
1548
1631
  * If current node is not of this type, the command will do nothing.
1549
1632
  */
1550
- type: string | NodeType;
1633
+ type: string | NodeType | string[] | NodeType[];
1551
1634
  /**
1552
1635
  * The attributes to set.
1553
1636
  */
@@ -1586,7 +1669,14 @@ declare type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
1586
1669
  export { SimplifyUnion }
1587
1670
  export { SimplifyUnion as SimplifyUnion_alias_1 }
1588
1671
 
1589
- 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>;
1590
1680
 
1591
1681
  /**
1592
1682
  * Parse a JSON object to a ProseMirror state.
@@ -1619,6 +1709,8 @@ export declare type StatePayload = (ctx: {
1619
1709
  schema: Schema;
1620
1710
  }) => EditorStateConfig;
1621
1711
 
1712
+ export declare function subtractFacetNode<I, O>(a: FacetNode<I, O>, b: FacetNode<I, O>): FacetNode<I, O>;
1713
+
1622
1714
  declare type TextInputHandler = (view: EditorView, from: number, to: number, text: string) => boolean | void;
1623
1715
  export { TextInputHandler }
1624
1716
  export { TextInputHandler as TextInputHandler_alias_1 }
@@ -1660,6 +1752,8 @@ declare function toggleNode({ type, attrs, }: {
1660
1752
  export { toggleNode }
1661
1753
  export { toggleNode as toggleNode_alias_1 }
1662
1754
 
1755
+ export declare function toReversed<T>(arr: T[]): T[];
1756
+
1663
1757
  declare type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
1664
1758
  export { TripleClickHandler }
1665
1759
  export { TripleClickHandler as TripleClickHandler_alias_1 }
@@ -1668,7 +1762,10 @@ declare type TripleClickOnHandler = (view: EditorView, pos: number, node: Node_3
1668
1762
  export { TripleClickOnHandler }
1669
1763
  export { TripleClickOnHandler as TripleClickOnHandler_alias_1 }
1670
1764
 
1671
- declare type Tuple5<T> = [T, T, T, T, T];
1765
+ /**
1766
+ * @internal
1767
+ */
1768
+ export declare type Tuple5<T> = [T, T, T, T, T];
1672
1769
 
1673
1770
  /**
1674
1771
  * Merge multiple extensions into one.
@@ -1681,13 +1778,18 @@ export { union as union_alias_1 }
1681
1778
 
1682
1779
  export declare class UnionExtensionImpl<T extends ExtensionTyping = ExtensionTyping> extends BaseExtension<T> implements Extension<T> {
1683
1780
  extension: BaseExtension[];
1684
- private _schema;
1685
- private hasSchemaCount;
1781
+ /**
1782
+ * @internal
1783
+ */
1686
1784
  constructor(extension?: BaseExtension[]);
1687
- get hasSchema(): boolean;
1688
- get schema(): Schema | null;
1785
+ /**
1786
+ * @internal
1787
+ */
1788
+ createTree(priority: Priority): FacetNode;
1689
1789
  }
1690
1790
 
1791
+ export declare function unionFacetNode<I, O>(a: FacetNode<I, O>, b: FacetNode<I, O>): FacetNode<I, O>;
1792
+
1691
1793
  export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[];
1692
1794
 
1693
1795
  export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
@@ -1701,13 +1803,6 @@ declare type UnmountHandler = () => void;
1701
1803
  export { UnmountHandler }
1702
1804
  export { UnmountHandler as UnmountHandler_alias_1 }
1703
1805
 
1704
- export declare function updateExtension(prevInputs: Payloads, prevConverters: Converters, extension: Extension, mode: 'add' | 'remove'): {
1705
- schemaInput: SchemaPayload | null;
1706
- stateInput: StatePayload | null;
1707
- viewInput: ViewPayload | null;
1708
- commandInput: CommandCreators | null;
1709
- };
1710
-
1711
1806
  /**
1712
1807
  * A function that is called when the editor state is updated.
1713
1808
  *
@@ -1720,7 +1815,7 @@ declare type UpdateHandler = (view: EditorView, prevState: EditorState) => void;
1720
1815
  export { UpdateHandler }
1721
1816
  export { UpdateHandler as UpdateHandler_alias_1 }
1722
1817
 
1723
- export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
1818
+ export declare const viewFacet: Facet<ViewPayload, RootPayload>;
1724
1819
 
1725
1820
  export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
1726
1821
 
@@ -1751,4 +1846,6 @@ export declare function wrap({ nodeType, attrs, }: {
1751
1846
  attrs?: Attrs | null;
1752
1847
  }): Command;
1753
1848
 
1849
+ export declare function zip<T, P>(a: T[], b: P[]): [T, P][];
1850
+
1754
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,6 +94,7 @@ 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';