@prosekit/extensions 0.0.0-next-20240626133927 → 0.0.0-next-20240715024943

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,5 @@
1
+ import { AddMarkOptions } from '@prosekit/core';
1
2
  import { Attrs } from '@prosekit/pm/model';
2
- import { Attrs as Attrs_2 } from 'prosemirror-model';
3
3
  import { BundledLanguage } from 'shiki';
4
4
  import { BundledLanguageInfo } from 'shiki';
5
5
  import { bundledLanguagesInfo } from 'shiki';
@@ -18,26 +18,33 @@ import { getSingletonHighlighter } from 'shiki/bundle/full';
18
18
  import type { Highlighter } from 'shiki';
19
19
  import { IndentListOptions } from 'prosemirror-flat-list';
20
20
  import { InputRule } from '@prosekit/pm/inputrules';
21
+ import { InsertNodeOptions } from '@prosekit/core';
21
22
  import { ListAttributes } from 'prosemirror-flat-list';
22
23
  import { ListDOMSerializer } from 'prosemirror-flat-list';
23
24
  import { MarkBuilder } from '@prosekit/core';
24
25
  import { MarkType } from '@prosekit/pm/model';
25
- import { MarkType as MarkType_2 } from 'prosemirror-model';
26
- import { Node as Node_2 } from 'prosemirror-model';
27
26
  import { NodeBuilder } from '@prosekit/core';
28
- import { NodeRange } from 'prosemirror-model';
27
+ import { NodeJSON } from '@prosekit/core';
29
28
  import { NodeType } from '@prosekit/pm/model';
30
- import { NodeType as NodeType_2 } from 'prosemirror-model';
31
29
  import { Options } from 'tsup';
32
30
  import { Parser } from 'prosemirror-highlight';
33
31
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
34
32
  import { PluginKey } from '@prosekit/pm/state';
35
33
  import { ProseMirrorNode } from '@prosekit/pm/model';
34
+ import { RemoveMarkOptions } from '@prosekit/core';
35
+ import { RemoveNodeOptions } from '@prosekit/core';
36
+ import { SetBlockTypeOptions } from '@prosekit/core';
37
+ import { SetNodeAttrsOptions } from '@prosekit/core';
36
38
  import type { SpecialLanguage } from 'shiki';
39
+ import { StepJSON } from '@prosekit/core';
37
40
  import { TestEditor } from '@prosekit/core/test';
38
41
  import { ToggleCollapsedOptions } from 'prosemirror-flat-list';
39
42
  import { Transaction } from '@prosekit/pm/state';
43
+ import { UnsetBlockTypeOptions } from '@prosekit/core';
44
+ import { UnsetMarkOptions } from '@prosekit/core';
40
45
  import { UnwrapListOptions } from 'prosemirror-flat-list';
46
+ import { WrapInListGetAttrs } from 'prosemirror-flat-list';
47
+ import { WrapOptions } from '@prosekit/core';
41
48
 
42
49
  export declare function applyMarkRules(rules: MarkRuleOptions[], transactions: readonly Transaction[], oldState: EditorState, newState: EditorState): Transaction | null;
43
50
 
@@ -120,6 +127,44 @@ export declare interface CodeBlockShikiOptions {
120
127
  langAlias?: Record<string, BundledLanguage>;
121
128
  }
122
129
 
130
+ /**
131
+ * A JSON representation of a commit.
132
+ */
133
+ export declare interface Commit {
134
+ /**
135
+ * The current doc node in the JSON format
136
+ */
137
+ doc: NodeJSON;
138
+ /**
139
+ * The parent node in the JSON format
140
+ */
141
+ parent: NodeJSON;
142
+ /**
143
+ * An array of steps in the JSON format that transform the parent node to the
144
+ * current doc node.
145
+ */
146
+ steps: StepJSON[];
147
+ }
148
+
149
+ export declare class CommitRecorder {
150
+ private parent;
151
+ private doc;
152
+ private steps;
153
+ /**
154
+ * Return a commit object including all changes since the last commit. `null`
155
+ * will be returned if there is no change.
156
+ */
157
+ commit(): Commit | null;
158
+ /**
159
+ * @internal
160
+ */
161
+ init(doc: ProseMirrorNode): void;
162
+ /**
163
+ * @internal
164
+ */
165
+ apply(tr: Transaction): void;
166
+ }
167
+
123
168
  export declare function createAutocompletePlugin({ getRules, }: {
124
169
  getRules: () => AutocompleteRule[];
125
170
  }): Plugin_2;
@@ -134,6 +179,8 @@ export declare function createLazyParser(highlighterOptions: HighlighterOptions)
134
179
  */
135
180
  export declare function createMarkInputRule({ regex, type, attrs, }: MarkInputRuleOptions): InputRule;
136
181
 
182
+ export { DedentListOptions }
183
+
137
184
  export declare const default_alias: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
138
185
 
139
186
  export { default_alias_1 }
@@ -327,6 +374,20 @@ Nodes: never;
327
374
  Commands: never;
328
375
  }>;
329
376
 
377
+ /**
378
+ * Define an extension that can record the changes in the editor.
379
+ */
380
+ export declare function defineCommitRecorder(commitRecorder: CommitRecorder): Extension<ExtensionTyping<any, any, any>>;
381
+
382
+ /**
383
+ * Define an extension to display the changes from the given commit in the editor.
384
+ */
385
+ export declare function defineCommitViewer(commit: Commit): Extension< {
386
+ Nodes: never;
387
+ Marks: never;
388
+ Commands: never;
389
+ }>;
390
+
330
391
  /**
331
392
  * Show up a decoration at the drop position when something is dragged over the editor.
332
393
  *
@@ -358,7 +419,7 @@ toggleHeading: [attrs?: HeadingAttrs | undefined];
358
419
  };
359
420
  }>;
360
421
 
361
- export declare function defineHeadingCommands(): Extension< {
422
+ declare function defineHeadingCommands(): Extension< {
362
423
  Commands: {
363
424
  setHeading: [attrs?: HeadingAttrs | undefined];
364
425
  insertHeading: [attrs?: HeadingAttrs | undefined];
@@ -367,20 +428,28 @@ toggleHeading: [attrs?: HeadingAttrs | undefined];
367
428
  Nodes: never;
368
429
  Marks: never;
369
430
  }>;
431
+ export { defineHeadingCommands }
432
+ export { defineHeadingCommands as defineHeadingCommands_alias_1 }
370
433
 
371
434
  /**
372
435
  * Converts the text block to a heading when `#` is typed at the start of a new
373
436
  * line followed by a space.
374
437
  */
375
- export declare function defineHeadingInputRule(): Extension<ExtensionTyping<any, any, any>>;
438
+ declare function defineHeadingInputRule(): Extension<ExtensionTyping<any, any, any>>;
439
+ export { defineHeadingInputRule }
440
+ export { defineHeadingInputRule as defineHeadingInputRule_alias_1 }
376
441
 
377
- export declare function defineHeadingKeymap(): Extension<ExtensionTyping<any, any, any>>;
442
+ declare function defineHeadingKeymap(): Extension<ExtensionTyping<any, any, any>>;
443
+ export { defineHeadingKeymap }
444
+ export { defineHeadingKeymap as defineHeadingKeymap_alias_1 }
378
445
 
379
- export declare function defineHeadingSpec(): Extension< {
446
+ declare function defineHeadingSpec(): Extension< {
380
447
  Nodes: "heading";
381
448
  Marks: never;
382
449
  Commands: never;
383
450
  }>;
451
+ export { defineHeadingSpec }
452
+ export { defineHeadingSpec as defineHeadingSpec_alias_1 }
384
453
 
385
454
  /**
386
455
  * @public
@@ -505,26 +574,31 @@ export declare function defineList(): Extension<{
505
574
  toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
506
575
  toggleList: [attrs: ListAttributes];
507
576
  unwrapList: [options?: UnwrapListOptions | undefined];
508
- wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
577
+ wrapInList: [getAttrs: WrapInListGetAttrs<ListAttributes>];
509
578
  insertList: [attrs?: ListAttributes | undefined];
510
579
  };
511
580
  }>;
512
581
 
513
- export declare function defineListCommands(): Extension<{
514
- Commands: {
515
- dedentList: [options?: DedentListOptions | undefined];
516
- indentList: [options?: IndentListOptions | undefined];
517
- moveList: [direction: "up" | "down"];
518
- splitList: [];
519
- toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
520
- toggleList: [attrs: ListAttributes];
521
- unwrapList: [options?: UnwrapListOptions | undefined];
522
- wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
523
- insertList: [attrs?: ListAttributes | undefined];
524
- };
525
- Nodes: never;
526
- Marks: never;
582
+ /**
583
+ * Defines list commands
584
+ */
585
+ declare function defineListCommands(): Extension< {
586
+ Commands: {
587
+ dedentList: [options?: DedentListOptions | undefined];
588
+ indentList: [options?: IndentListOptions | undefined];
589
+ moveList: [direction: "up" | "down"];
590
+ splitList: [];
591
+ toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
592
+ toggleList: [attrs: ListAttributes];
593
+ unwrapList: [options?: UnwrapListOptions | undefined];
594
+ wrapInList: [getAttrs: WrapInListGetAttrs<ListAttributes>];
595
+ insertList: [attrs?: ListAttributes | undefined];
596
+ };
597
+ Nodes: never;
598
+ Marks: never;
527
599
  }>;
600
+ export { defineListCommands }
601
+ export { defineListCommands as defineListCommands_alias_1 }
528
602
 
529
603
  export declare function defineListInputRules(): Extension;
530
604
 
@@ -533,7 +607,9 @@ export declare function defineListInputRules(): Extension;
533
607
  *
534
608
  * @public
535
609
  */
536
- export declare function defineListKeymap(): Extension<ExtensionTyping<any, any, any>>;
610
+ declare function defineListKeymap(): Extension<ExtensionTyping<any, any, any>>;
611
+ export { defineListKeymap }
612
+ export { defineListKeymap as defineListKeymap_alias_1 }
537
613
 
538
614
  export declare function defineListPlugins(): Extension<ExtensionTyping<any, any, any>>;
539
615
 
@@ -749,58 +825,25 @@ export declare function defineTestExtension(): Extension<{
749
825
  from?: number;
750
826
  to?: number;
751
827
  }];
752
- insertNode: [options: {
753
- node: Node_2;
754
- pos?: number;
755
- type?: undefined;
756
- attrs?: undefined;
757
- } | {
758
- node?: undefined;
759
- pos?: number;
760
- type: string;
761
- attrs?: Attrs_2;
762
- }];
763
- removeNode: [options: {
764
- type: string | NodeType_2;
765
- pos?: number;
766
- }];
767
- wrap: [{
768
- nodeType: NodeType_2;
769
- attrs?: Attrs_2 | null;
770
- }];
771
- setBlockType: [options: {
772
- type: NodeType_2 | string;
773
- attrs?: Attrs_2 | null;
774
- from?: number;
775
- to?: number;
776
- }];
777
- setNodeAttrs: [options: {
778
- type: string | NodeType_2 | string[] | NodeType_2[];
779
- attrs: Attrs_2;
780
- pos?: number;
781
- }];
828
+ insertNode: [options: InsertNodeOptions];
829
+ removeNode: [options: RemoveNodeOptions];
830
+ wrap: [WrapOptions];
831
+ setBlockType: [options: SetBlockTypeOptions];
832
+ setNodeAttrs: [options: SetNodeAttrsOptions];
782
833
  selectAll: [];
783
- addMark: [options: {
784
- type: string | MarkType_2;
785
- attrs?: Attrs_2 | null;
786
- from?: number;
787
- to?: number;
788
- }];
789
- removeMark: [options: {
790
- type: string | MarkType_2;
791
- attrs?: Attrs_2 | null;
792
- from?: number;
793
- to?: number;
794
- }];
795
- toggleItalic: [];
796
- undo: [];
797
- redo: [];
834
+ addMark: [options: AddMarkOptions];
835
+ removeMark: [options: RemoveMarkOptions];
836
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
837
+ unsetMark: [options?: UnsetMarkOptions | undefined];
838
+ readonly undo: [];
839
+ readonly redo: [];
798
840
  toggleBold: [];
799
841
  toggleCode: [];
800
842
  setHeading: [attrs?: HeadingAttrs | undefined];
801
843
  insertHeading: [attrs?: HeadingAttrs | undefined];
802
844
  toggleHeading: [attrs?: HeadingAttrs | undefined];
803
845
  insertImage: [attrs?: ImageAttrs | undefined];
846
+ toggleItalic: [];
804
847
  addLink: [attrs: LinkAttrs];
805
848
  removeLink: [];
806
849
  toggleLink: [attrs: LinkAttrs];
@@ -812,7 +855,7 @@ export declare function defineTestExtension(): Extension<{
812
855
  toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
813
856
  toggleList: [attrs: ListAttributes];
814
857
  unwrapList: [options?: UnwrapListOptions | undefined];
815
- wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
858
+ wrapInList: [getAttrs: WrapInListGetAttrs<ListAttributes>];
816
859
  insertList: [attrs?: ListAttributes | undefined];
817
860
  toggleStrike: [];
818
861
  insertTable: [{
@@ -1041,9 +1084,11 @@ export { getSingletonHighlighter }
1041
1084
 
1042
1085
  export declare function getTrMeta(tr: Transaction): PredictionPluginState;
1043
1086
 
1044
- export declare interface HeadingAttrs {
1087
+ declare interface HeadingAttrs {
1045
1088
  level: number;
1046
1089
  }
1090
+ export { HeadingAttrs }
1091
+ export { HeadingAttrs as HeadingAttrs_alias_1 }
1047
1092
 
1048
1093
  export declare type HighlighterOptions = {
1049
1094
  themes: BundledTheme[];
@@ -1072,6 +1117,8 @@ export declare interface ImageAttrs {
1072
1117
  src?: string | null;
1073
1118
  }
1074
1119
 
1120
+ export { IndentListOptions }
1121
+
1075
1122
  /**
1076
1123
  * Insert a table node with the given number of rows and columns, and optionally
1077
1124
  * a header row.
@@ -1097,6 +1144,8 @@ export declare interface LinkAttrs {
1097
1144
  href: string;
1098
1145
  }
1099
1146
 
1147
+ export { ListAttributes }
1148
+
1100
1149
  export { ListDOMSerializer }
1101
1150
 
1102
1151
  /**
@@ -1194,6 +1243,18 @@ export declare interface PredictionPluginState {
1194
1243
 
1195
1244
  export declare function prepareHighlighter(options: HighlighterOptions): HighlighterResult;
1196
1245
 
1246
+ /**
1247
+ * @example
1248
+ *
1249
+ * ```ts
1250
+ * await pressKey('mod-1')
1251
+ * await pressKey('Backspace')
1252
+ * ```
1253
+ *
1254
+ * @internal
1255
+ */
1256
+ export declare function pressKey(input: string): Promise<void>;
1257
+
1197
1258
  /**
1198
1259
  * Options for {@link defineSearchQuery}
1199
1260
  *
@@ -1249,7 +1310,7 @@ export declare function setTrMeta(tr: Transaction, meta: PredictionPluginState):
1249
1310
  /**
1250
1311
  * @internal
1251
1312
  */
1252
- export declare function setupDefaultTest(): {
1313
+ export declare function setupTest(): {
1253
1314
  editor: TestEditor<Extension<{
1254
1315
  Nodes: "blockquote" | "table" | "text" | "doc" | "paragraph" | "heading" | "image" | "list" | "tableRow" | "tableCell" | "tableHeaderCell";
1255
1316
  Marks: "code" | "link" | "bold" | "strike" | "italic" | "underline";
@@ -1259,58 +1320,25 @@ export declare function setupDefaultTest(): {
1259
1320
  from?: number;
1260
1321
  to?: number;
1261
1322
  }];
1262
- insertNode: [options: {
1263
- node: Node_2;
1264
- pos?: number;
1265
- type?: undefined;
1266
- attrs?: undefined;
1267
- } | {
1268
- node?: undefined;
1269
- pos?: number;
1270
- type: string;
1271
- attrs?: Attrs_2;
1272
- }];
1273
- removeNode: [options: {
1274
- type: string | NodeType_2;
1275
- pos?: number;
1276
- }];
1277
- wrap: [{
1278
- nodeType: NodeType_2;
1279
- attrs?: Attrs_2 | null;
1280
- }];
1281
- setBlockType: [options: {
1282
- type: NodeType_2 | string;
1283
- attrs?: Attrs_2 | null;
1284
- from?: number;
1285
- to?: number;
1286
- }];
1287
- setNodeAttrs: [options: {
1288
- type: string | NodeType_2 | string[] | NodeType_2[];
1289
- attrs: Attrs_2;
1290
- pos?: number;
1291
- }];
1323
+ insertNode: [options: InsertNodeOptions];
1324
+ removeNode: [options: RemoveNodeOptions];
1325
+ wrap: [WrapOptions];
1326
+ setBlockType: [options: SetBlockTypeOptions];
1327
+ setNodeAttrs: [options: SetNodeAttrsOptions];
1292
1328
  selectAll: [];
1293
- addMark: [options: {
1294
- type: string | MarkType_2;
1295
- attrs?: Attrs_2 | null;
1296
- from?: number;
1297
- to?: number;
1298
- }];
1299
- removeMark: [options: {
1300
- type: string | MarkType_2;
1301
- attrs?: Attrs_2 | null;
1302
- from?: number;
1303
- to?: number;
1304
- }];
1305
- toggleItalic: [];
1306
- undo: [];
1307
- redo: [];
1329
+ addMark: [options: AddMarkOptions];
1330
+ removeMark: [options: RemoveMarkOptions];
1331
+ unsetBlockType: [options?: UnsetBlockTypeOptions | undefined];
1332
+ unsetMark: [options?: UnsetMarkOptions | undefined];
1333
+ readonly undo: [];
1334
+ readonly redo: [];
1308
1335
  toggleBold: [];
1309
1336
  toggleCode: [];
1310
1337
  setHeading: [attrs?: HeadingAttrs | undefined];
1311
1338
  insertHeading: [attrs?: HeadingAttrs | undefined];
1312
1339
  toggleHeading: [attrs?: HeadingAttrs | undefined];
1313
1340
  insertImage: [attrs?: ImageAttrs | undefined];
1341
+ toggleItalic: [];
1314
1342
  addLink: [attrs: LinkAttrs];
1315
1343
  removeLink: [];
1316
1344
  toggleLink: [attrs: LinkAttrs];
@@ -1322,7 +1350,7 @@ export declare function setupDefaultTest(): {
1322
1350
  toggleCollapsed: [(ToggleCollapsedOptions | undefined)?];
1323
1351
  toggleList: [attrs: ListAttributes];
1324
1352
  unwrapList: [options?: UnwrapListOptions | undefined];
1325
- wrapInList: [getAttrs: ListAttributes | ((range: NodeRange) => ListAttributes | null)];
1353
+ wrapInList: [getAttrs: WrapInListGetAttrs<ListAttributes>];
1326
1354
  insertList: [attrs?: ListAttributes | undefined];
1327
1355
  toggleStrike: [];
1328
1356
  insertTable: [{
@@ -1341,7 +1369,7 @@ export declare function setupDefaultTest(): {
1341
1369
  /**
1342
1370
  * @internal
1343
1371
  */
1344
- export declare function setupTest<E extends Extension>(extension: E): {
1372
+ export declare function setupTestFromExtension<E extends Extension>(extension: E): {
1345
1373
  editor: TestEditor<E>;
1346
1374
  n: Record<ExtractNodes<E>, NodeBuilder>;
1347
1375
  m: Record<ExtractMarks<E>, MarkBuilder>;
@@ -1391,4 +1419,10 @@ export declare type TextBlockEnterRuleOptions = {
1391
1419
  stop?: boolean;
1392
1420
  };
1393
1421
 
1422
+ export { ToggleCollapsedOptions }
1423
+
1424
+ export { UnwrapListOptions }
1425
+
1426
+ export { WrapInListGetAttrs }
1427
+
1394
1428
  export { }
@@ -0,0 +1,8 @@
1
+ /* src/commit/style.css */
2
+ .prosekit-commit-deletion {
3
+ background-color: #e5534b80;
4
+ text-decoration: line-through;
5
+ }
6
+ .prosekit-commit-addition {
7
+ background-color: #53e54b80;
8
+ }
@@ -1,4 +1,4 @@
1
- /* ../../node_modules/.pnpm/prosemirror-flat-list@0.5.0/node_modules/prosemirror-flat-list/dist/style.css */
1
+ /* ../../node_modules/.pnpm/prosemirror-flat-list@0.5.2/node_modules/prosemirror-flat-list/dist/style.css */
2
2
  .prosemirror-flat-list {
3
3
  padding: 0;
4
4
  margin-top: 0;
@@ -1,9 +1,9 @@
1
- import {
2
- defineTextBlockInputRule
3
- } from "./chunk-PYT3MOTF.js";
4
1
  import {
5
2
  defineTextBlockEnterRule
6
3
  } from "./chunk-2JYT2MT7.js";
4
+ import {
5
+ defineTextBlockInputRule
6
+ } from "./chunk-PYT3MOTF.js";
7
7
 
8
8
  // src/code-block/code-block.ts
9
9
  import { union } from "@prosekit/core";
@@ -0,0 +1,4 @@
1
+ export { CommitRecorder } from './_tsup-dts-rollup';
2
+ export { defineCommitRecorder } from './_tsup-dts-rollup';
3
+ export { defineCommitViewer } from './_tsup-dts-rollup';
4
+ export { Commit } from './_tsup-dts-rollup';
@@ -0,0 +1,160 @@
1
+ // src/commit/index.ts
2
+ import {
3
+ collectNodes,
4
+ defineDefaultState,
5
+ definePlugin,
6
+ jsonFromNode,
7
+ union
8
+ } from "@prosekit/core";
9
+ import {
10
+ DOMSerializer,
11
+ Fragment,
12
+ Slice
13
+ } from "@prosekit/pm/model";
14
+ import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
15
+ import { Step } from "@prosekit/pm/transform";
16
+ import { Decoration, DecorationSet } from "@prosekit/pm/view";
17
+ import { ChangeSet } from "prosemirror-changeset";
18
+ function getChanges(doc, parent, steps) {
19
+ return ChangeSet.create(parent).addSteps(
20
+ doc,
21
+ steps.map((step) => step.getMap()),
22
+ null
23
+ ).changes;
24
+ }
25
+ function renderDivWeight(view) {
26
+ return view.dom.ownerDocument.createElement("div");
27
+ }
28
+ function decorateDeletionSlice(slice) {
29
+ let { openStart, openEnd, content } = slice;
30
+ for (; openStart > 0 && openEnd > 0 && content.childCount === 1; )
31
+ openStart--, openEnd--, content = content.child(0).content;
32
+ if (content.childCount === 0)
33
+ return [];
34
+ if (openStart > 0 && openEnd > 0 && content.childCount === 2) {
35
+ let head = Fragment.from([content.child(0)]), tail = Fragment.from([content.child(1)]);
36
+ return [
37
+ ...decorateDeletionSlice(new Slice(head, openStart, openStart)),
38
+ renderDivWeight,
39
+ ...decorateDeletionSlice(new Slice(tail, openEnd, openEnd))
40
+ ];
41
+ }
42
+ if (openStart > 0 && content.childCount >= 2) {
43
+ let nodes = collectNodes(content), head = Fragment.from(nodes.slice(0, 1)), body = Fragment.from(nodes.slice(1));
44
+ return [
45
+ ...decorateDeletionSlice(new Slice(head, openStart, openStart)),
46
+ ...decorateDeletionSlice(new Slice(body, 0, openEnd))
47
+ ];
48
+ }
49
+ if (openEnd > 0 && content.childCount >= 2) {
50
+ let nodes = collectNodes(content), body = Fragment.from(nodes.slice(0, -1)), tail = Fragment.from(nodes.slice(-1));
51
+ return [
52
+ ...decorateDeletionSlice(new Slice(body, openStart, 0)),
53
+ ...decorateDeletionSlice(new Slice(tail, openEnd, openEnd))
54
+ ];
55
+ }
56
+ let schema = content.child(0).type.schema, isInline = content.child(0).isInline;
57
+ return [(view) => {
58
+ let document = view.dom.ownerDocument, element = document.createElement(isInline ? "span" : "div");
59
+ return DOMSerializer.fromSchema(schema).serializeFragment(content, { document }, element), element.classList.add("prosekit-commit-deletion"), element;
60
+ }];
61
+ }
62
+ function decorateDeletion(doc, from, to, pos) {
63
+ let slice = doc.slice(from, to), renders = decorateDeletionSlice(slice), count = renders.length;
64
+ return renders.map(
65
+ (render, index) => Decoration.widget(pos, render, {
66
+ side: -20 - count + index,
67
+ // Ensure the text in the decoration is able to be selected.
68
+ ignoreSelection: !0
69
+ })
70
+ );
71
+ }
72
+ function decorateAddition(from, to) {
73
+ return Decoration.inline(from, to, { class: "prosekit-commit-addition" });
74
+ }
75
+ function decorateChange(prev, change) {
76
+ let { fromA, toA, fromB, toB } = change, decorations = [];
77
+ return fromA < toA && decorations.push(...decorateDeletion(prev, fromA, toA, fromB)), fromB < toB && decorations.push(decorateAddition(fromB, toB)), decorations;
78
+ }
79
+ function decorateCommit(doc, parent, steps) {
80
+ let decorations = getChanges(doc, parent, steps).flatMap(
81
+ (change) => decorateChange(parent, change)
82
+ );
83
+ return DecorationSet.create(doc, decorations);
84
+ }
85
+ function defineCommitDecoration(commit) {
86
+ let key = new PluginKey("prosekit-commit-decoration");
87
+ return definePlugin(({ schema }) => {
88
+ let parent = schema.nodeFromJSON(commit.parent), steps = commit.steps.map((step) => Step.fromJSON(schema, step));
89
+ return new ProseMirrorPlugin({
90
+ key,
91
+ state: {
92
+ init: (_, instance) => decorateCommit(instance.doc, parent, steps),
93
+ apply: (tr, deco) => deco.map(tr.mapping, tr.doc)
94
+ },
95
+ props: {
96
+ decorations: (state) => key.getState(state)
97
+ }
98
+ });
99
+ });
100
+ }
101
+ function defineCommitViewer(commit) {
102
+ return union([
103
+ defineDefaultState({ defaultDoc: commit.doc }),
104
+ defineCommitDecoration(commit)
105
+ ]);
106
+ }
107
+ var CommitRecorder = class {
108
+ constructor() {
109
+ this.parent = null;
110
+ this.doc = null;
111
+ this.steps = [];
112
+ }
113
+ /**
114
+ * Return a commit object including all changes since the last commit. `null`
115
+ * will be returned if there is no change.
116
+ */
117
+ commit() {
118
+ if (!this.parent || !this.doc || this.steps.length === 0 || this.parent.eq(this.doc))
119
+ return null;
120
+ let commit = {
121
+ doc: jsonFromNode(this.doc),
122
+ parent: jsonFromNode(this.parent),
123
+ steps: this.steps.map((step) => step.toJSON())
124
+ };
125
+ return this.init(this.doc), commit;
126
+ }
127
+ /**
128
+ * @internal
129
+ */
130
+ init(doc) {
131
+ this.doc = doc, this.parent = doc, this.steps = [];
132
+ }
133
+ /**
134
+ * @internal
135
+ */
136
+ apply(tr) {
137
+ this.steps.push(...tr.steps), this.doc = tr.doc;
138
+ }
139
+ };
140
+ function defineCommitRecorder(commitRecorder) {
141
+ let key = new PluginKey("prosekit-commit-recorder");
142
+ return definePlugin(
143
+ new ProseMirrorPlugin({
144
+ key,
145
+ state: {
146
+ init: (_, state) => {
147
+ commitRecorder.init(state.doc);
148
+ },
149
+ apply: (tr) => {
150
+ commitRecorder.apply(tr);
151
+ }
152
+ }
153
+ })
154
+ );
155
+ }
156
+ export {
157
+ CommitRecorder,
158
+ defineCommitRecorder,
159
+ defineCommitViewer
160
+ };
@@ -1,6 +1,6 @@
1
- export { defineHeadingSpec } from './_tsup-dts-rollup';
2
- export { defineHeadingKeymap } from './_tsup-dts-rollup';
3
- export { defineHeadingInputRule } from './_tsup-dts-rollup';
4
- export { defineHeadingCommands } from './_tsup-dts-rollup';
5
1
  export { defineHeading } from './_tsup-dts-rollup';
2
+ export { defineHeadingCommands_alias_1 as defineHeadingCommands } from './_tsup-dts-rollup';
3
+ export { defineHeadingInputRule } from './_tsup-dts-rollup';
4
+ export { defineHeadingKeymap } from './_tsup-dts-rollup';
5
+ export { defineHeadingSpec } from './_tsup-dts-rollup';
6
6
  export { HeadingAttrs } from './_tsup-dts-rollup';
@@ -3,16 +3,64 @@ import {
3
3
  } from "./chunk-PYT3MOTF.js";
4
4
 
5
5
  // src/heading/index.ts
6
+ import { union } from "@prosekit/core";
7
+
8
+ // src/heading/commands.ts
6
9
  import {
7
10
  defineCommands,
8
- defineKeymap,
9
- defineNodeSpec,
10
11
  insertNode,
11
12
  setBlockType,
12
- toggleNode,
13
- union,
13
+ toggleNode
14
+ } from "@prosekit/core";
15
+ function defineHeadingCommands() {
16
+ return defineCommands({
17
+ setHeading: (attrs) => setBlockType({ type: "heading", attrs }),
18
+ insertHeading: (attrs) => insertNode({ type: "heading", attrs }),
19
+ toggleHeading: (attrs) => toggleNode({ type: "heading", attrs })
20
+ });
21
+ }
22
+
23
+ // src/heading/input-rule.ts
24
+ function defineHeadingInputRule() {
25
+ return defineTextBlockInputRule({
26
+ regex: /^(#{1,6})\s$/,
27
+ type: "heading",
28
+ attrs: (match) => {
29
+ var _a, _b;
30
+ return { level: (_b = (_a = match[1]) == null ? void 0 : _a.length) != null ? _b : 1 };
31
+ }
32
+ });
33
+ }
34
+
35
+ // src/heading/keymap.ts
36
+ import {
37
+ defineKeymap,
38
+ isAtBlockStart,
39
+ toggleNode as toggleNode2,
40
+ unsetBlockType,
14
41
  withSkipCodeBlock
15
42
  } from "@prosekit/core";
43
+ function toggleHeadingKeybinding(level) {
44
+ return withSkipCodeBlock(toggleNode2({ type: "heading", attrs: { level } }));
45
+ }
46
+ var backspaceUnsetHeading = (state, dispatch, view) => {
47
+ let $pos = isAtBlockStart(state, view);
48
+ return ($pos == null ? void 0 : $pos.parent.type.name) === "heading" ? unsetBlockType()(state, dispatch, view) : !1;
49
+ };
50
+ function defineHeadingKeymap() {
51
+ return defineKeymap({
52
+ "mod-1": toggleHeadingKeybinding(1),
53
+ "mod-2": toggleHeadingKeybinding(2),
54
+ "mod-3": toggleHeadingKeybinding(3),
55
+ "mod-4": toggleHeadingKeybinding(4),
56
+ "mod-5": toggleHeadingKeybinding(5),
57
+ "mod-6": toggleHeadingKeybinding(6),
58
+ Backspace: backspaceUnsetHeading
59
+ });
60
+ }
61
+
62
+ // src/heading/spec.ts
63
+ import { defineNodeSpec } from "@prosekit/core";
16
64
  function defineHeadingSpec() {
17
65
  return defineNodeSpec({
18
66
  name: "heading",
@@ -33,36 +81,8 @@ function defineHeadingSpec() {
33
81
  }
34
82
  });
35
83
  }
36
- function defineHeadingKeymap() {
37
- return defineKeymap({
38
- "mod-1": toggleHeadingKeybinding(1),
39
- "mod-2": toggleHeadingKeybinding(2),
40
- "mod-3": toggleHeadingKeybinding(3),
41
- "mod-4": toggleHeadingKeybinding(4),
42
- "mod-5": toggleHeadingKeybinding(5),
43
- "mod-6": toggleHeadingKeybinding(6)
44
- });
45
- }
46
- function toggleHeadingKeybinding(level) {
47
- return withSkipCodeBlock(toggleNode({ type: "heading", attrs: { level } }));
48
- }
49
- function defineHeadingInputRule() {
50
- return defineTextBlockInputRule({
51
- regex: /^(#{1,6})\s$/,
52
- type: "heading",
53
- attrs: (match) => {
54
- var _a, _b;
55
- return { level: (_b = (_a = match[1]) == null ? void 0 : _a.length) != null ? _b : 1 };
56
- }
57
- });
58
- }
59
- function defineHeadingCommands() {
60
- return defineCommands({
61
- setHeading: (attrs) => setBlockType({ type: "heading", attrs }),
62
- insertHeading: (attrs) => insertNode({ type: "heading", attrs }),
63
- toggleHeading: (attrs) => toggleNode({ type: "heading", attrs })
64
- });
65
- }
84
+
85
+ // src/heading/index.ts
66
86
  function defineHeading() {
67
87
  return union([
68
88
  defineHeadingSpec(),
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  defineMarkRule
3
3
  } from "./chunk-ZPEMHYTU.js";
4
- import {
5
- defineInputRule
6
- } from "./chunk-PYT3MOTF.js";
7
4
  import {
8
5
  defineEnterRule
9
6
  } from "./chunk-2JYT2MT7.js";
7
+ import {
8
+ defineInputRule
9
+ } from "./chunk-PYT3MOTF.js";
10
10
 
11
11
  // src/link/index.ts
12
12
  import {
@@ -1,7 +1,13 @@
1
1
  export { defineListSpec } from './_tsup-dts-rollup';
2
2
  export { defineListPlugins } from './_tsup-dts-rollup';
3
- export { defineListKeymap } from './_tsup-dts-rollup';
4
3
  export { defineListInputRules } from './_tsup-dts-rollup';
5
- export { defineListCommands } from './_tsup-dts-rollup';
6
4
  export { defineList } from './_tsup-dts-rollup';
7
5
  export { ListDOMSerializer } from './_tsup-dts-rollup';
6
+ export { DedentListOptions } from './_tsup-dts-rollup';
7
+ export { IndentListOptions } from './_tsup-dts-rollup';
8
+ export { ListAttributes } from './_tsup-dts-rollup';
9
+ export { ToggleCollapsedOptions } from './_tsup-dts-rollup';
10
+ export { UnwrapListOptions } from './_tsup-dts-rollup';
11
+ export { WrapInListGetAttrs } from './_tsup-dts-rollup';
12
+ export { defineListCommands_alias_1 as defineListCommands } from './_tsup-dts-rollup';
13
+ export { defineListKeymap } from './_tsup-dts-rollup';
@@ -4,29 +4,74 @@ import {
4
4
 
5
5
  // src/list/index.ts
6
6
  import {
7
- Priority,
8
- defineCommands,
9
- defineKeymap,
10
7
  defineNodeSpec,
11
8
  definePlugin,
12
- insertNode,
13
- union,
14
- withPriority
9
+ union
15
10
  } from "@prosekit/core";
16
11
  import {
17
- createDedentListCommand,
18
- createIndentListCommand,
19
12
  createListPlugins,
20
13
  createListSpec,
21
- createMoveListCommand,
22
- createSplitListCommand,
23
- createToggleCollapsedCommand,
24
- createToggleListCommand,
25
- createUnwrapListCommand,
26
- createWrapInListCommand,
27
- listInputRules,
28
- listKeymap
14
+ listInputRules
15
+ } from "prosemirror-flat-list";
16
+
17
+ // src/list/commands.ts
18
+ import { defineCommands, insertNode } from "@prosekit/core";
19
+ import {
20
+ createDedentListCommand as dedentList,
21
+ createIndentListCommand as indentList,
22
+ createMoveListCommand as moveList,
23
+ createSplitListCommand as splitList,
24
+ createToggleCollapsedCommand as toggleCollapsed,
25
+ createToggleListCommand as toggleList,
26
+ createUnwrapListCommand as unwrapList,
27
+ createWrapInListCommand as wrapInList
28
+ } from "prosemirror-flat-list";
29
+ function insertList(attrs) {
30
+ return insertNode({ type: "list", attrs });
31
+ }
32
+ function defineListCommands() {
33
+ return defineCommands({
34
+ dedentList,
35
+ indentList,
36
+ moveList,
37
+ splitList,
38
+ toggleCollapsed,
39
+ toggleList,
40
+ unwrapList,
41
+ wrapInList,
42
+ insertList
43
+ });
44
+ }
45
+
46
+ // src/list/keymap.ts
47
+ import { defineKeymap } from "@prosekit/core";
48
+ import { chainCommands, deleteSelection } from "@prosekit/pm/commands";
49
+ import {
50
+ createDedentListCommand,
51
+ createIndentListCommand,
52
+ deleteCommand,
53
+ enterCommand,
54
+ joinCollapsedListBackward,
55
+ joinListUp,
56
+ protectCollapsed
29
57
  } from "prosemirror-flat-list";
58
+ var backspaceCommand = chainCommands(
59
+ protectCollapsed,
60
+ deleteSelection,
61
+ joinListUp,
62
+ joinCollapsedListBackward
63
+ ), listKeymap = {
64
+ Enter: enterCommand,
65
+ Backspace: backspaceCommand,
66
+ Delete: deleteCommand,
67
+ "Mod-[": createDedentListCommand(),
68
+ "Mod-]": createIndentListCommand()
69
+ };
70
+ function defineListKeymap() {
71
+ return defineKeymap(listKeymap);
72
+ }
73
+
74
+ // src/list/index.ts
30
75
  import { ListDOMSerializer } from "prosemirror-flat-list";
31
76
  function defineListSpec() {
32
77
  return defineNodeSpec({ ...createListSpec(), name: "list" });
@@ -34,31 +79,14 @@ function defineListSpec() {
34
79
  function defineListPlugins() {
35
80
  return definePlugin(({ schema }) => createListPlugins({ schema }));
36
81
  }
37
- function defineListKeymap() {
38
- return defineKeymap(listKeymap);
39
- }
40
82
  function defineListInputRules() {
41
83
  return union(listInputRules.map(defineInputRule));
42
84
  }
43
- function defineListCommands() {
44
- return defineCommands({
45
- dedentList: createDedentListCommand,
46
- indentList: createIndentListCommand,
47
- moveList: createMoveListCommand,
48
- splitList: createSplitListCommand,
49
- toggleCollapsed: createToggleCollapsedCommand,
50
- toggleList: createToggleListCommand,
51
- unwrapList: createUnwrapListCommand,
52
- wrapInList: createWrapInListCommand,
53
- insertList: (attrs) => insertNode({ type: "list", attrs })
54
- });
55
- }
56
85
  function defineList() {
57
86
  return union([
58
87
  defineListSpec(),
59
88
  defineListPlugins(),
60
- // Use a high priority to override the default key bindings.
61
- withPriority(defineListKeymap(), Priority.high),
89
+ defineListKeymap(),
62
90
  defineListInputRules(),
63
91
  defineListCommands()
64
92
  ]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.0.0-next-20240626133927",
4
+ "version": "0.0.0-next-20240715024943",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -55,6 +55,14 @@
55
55
  "import": "./dist/prosekit-extensions-code-block.js",
56
56
  "default": "./dist/prosekit-extensions-code-block.js"
57
57
  },
58
+ "./commit": {
59
+ "types": "./dist/prosekit-extensions-commit.d.ts",
60
+ "import": "./dist/prosekit-extensions-commit.js",
61
+ "default": "./dist/prosekit-extensions-commit.js"
62
+ },
63
+ "./commit/style.css": {
64
+ "default": "./dist/commit/style.css"
65
+ },
58
66
  "./drop-cursor": {
59
67
  "types": "./dist/prosekit-extensions-drop-cursor.d.ts",
60
68
  "import": "./dist/prosekit-extensions-drop-cursor.js",
@@ -170,20 +178,21 @@
170
178
  "dist"
171
179
  ],
172
180
  "dependencies": {
181
+ "prosemirror-changeset": "^2.2.1",
173
182
  "prosemirror-dropcursor": "^1.8.1",
174
- "prosemirror-flat-list": "^0.5.0",
183
+ "prosemirror-flat-list": "^0.5.2",
175
184
  "prosemirror-highlight": "^0.8.0",
176
- "prosemirror-search": "^0.1.0",
185
+ "prosemirror-search": "^1.0.0",
177
186
  "prosemirror-tables": "^1.3.7",
178
- "shiki": "^1.9.0",
179
- "@prosekit/pm": "^0.0.0-next-20240626133927",
180
- "@prosekit/core": "^0.0.0-next-20240626133927"
187
+ "shiki": "^1.10.3",
188
+ "@prosekit/core": "^0.0.0-next-20240715024943",
189
+ "@prosekit/pm": "^0.0.0-next-20240715024943"
181
190
  },
182
191
  "devDependencies": {
183
- "@vitest/browser": "^2.0.0-beta.12",
192
+ "@vitest/browser": "^2.0.2",
184
193
  "tsup": "^8.1.0",
185
- "typescript": "^5.5.2",
186
- "vitest": "^2.0.0-beta.12",
194
+ "typescript": "^5.5.3",
195
+ "vitest": "^2.0.2",
187
196
  "@prosekit/dev": "0.0.0"
188
197
  },
189
198
  "scripts": {
@@ -211,6 +220,9 @@
211
220
  "code-block": [
212
221
  "./dist/prosekit-extensions-code-block.d.ts"
213
222
  ],
223
+ "commit": [
224
+ "./dist/prosekit-extensions-commit.d.ts"
225
+ ],
214
226
  "drop-cursor": [
215
227
  "./dist/prosekit-extensions-drop-cursor.d.ts"
216
228
  ],