@prosekit/extensions 0.7.8 → 0.7.10

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 { Attrs } from '@prosekit/pm/model';
2
2
  import { Attrs as Attrs_2 } from 'prosemirror-model';
3
+ import { Awareness } from 'y-protocols/awareness';
3
4
  import { BaseCommandsExtension } from '@prosekit/core';
4
5
  import { BundledLanguage } from 'shiki';
5
6
  import { BundledLanguageInfo } from 'shiki';
@@ -48,6 +49,10 @@ import { Transaction } from '@prosekit/pm/state';
48
49
  import { Union } from '@prosekit/core';
49
50
  import { UnwrapListOptions } from 'prosemirror-flat-list';
50
51
  import { WrapInListGetAttrs } from 'prosemirror-flat-list';
52
+ import * as Y from 'yjs';
53
+ import { yCursorPlugin } from 'y-prosemirror';
54
+ import { ySyncPlugin } from 'y-prosemirror';
55
+ import { yUndoPlugin } from 'y-prosemirror';
51
56
 
52
57
  export declare function applyMarkRules(rules: MarkRuleOptions[], transactions: readonly Transaction[], oldState: EditorState, newState: EditorState): Transaction | null;
53
58
 
@@ -174,6 +179,15 @@ CodeBlockCommandsExtension
174
179
  export { CodeBlockExtension }
175
180
  export { CodeBlockExtension as CodeBlockExtension_alias_1 }
176
181
 
182
+ /**
183
+ * @public
184
+ */
185
+ declare type CodeBlockHighlightOptions = {
186
+ parser: HighlightParser;
187
+ };
188
+ export { CodeBlockHighlightOptions }
189
+ export { CodeBlockHighlightOptions as CodeBlockHighlightOptions_alias_1 }
190
+
177
191
  /**
178
192
  * @public
179
193
  */
@@ -379,11 +393,11 @@ export { defineCodeBlockEnterRule as defineCodeBlockEnterRule_alias_1 }
379
393
  * [documentation](https://github.com/ocavue/prosemirror-highlight) for more
380
394
  * information.
381
395
  *
396
+ * @param options
397
+ *
382
398
  * @public
383
399
  */
384
- declare function defineCodeBlockHighlight({ parser, }: {
385
- parser: HighlightParser;
386
- }): Extension;
400
+ declare function defineCodeBlockHighlight({ parser, }: CodeBlockHighlightOptions): Extension;
387
401
  export { defineCodeBlockHighlight }
388
402
  export { defineCodeBlockHighlight as defineCodeBlockHighlight_alias_1 }
389
403
 
@@ -404,6 +418,8 @@ export declare function defineCodeBlockKeymap(): PlainExtension;
404
418
  /**
405
419
  * Adds syntax highlighting to code blocks using the [shiki](https://github.com/shikijs/shiki) package.
406
420
  *
421
+ * @param options
422
+ *
407
423
  * @public
408
424
  */
409
425
  declare function defineCodeBlockShiki({ themes, langs, langAlias, }?: CodeBlockShikiOptions): Extension;
@@ -463,9 +479,11 @@ export declare function defineDropCursor(options?: DropCursorOptions): DropCurso
463
479
  * the cursor matches `regex` and user presses Enter. The `regex` should end
464
480
  * with `$`.
465
481
  *
482
+ * @param options
483
+ *
466
484
  * @public
467
485
  */
468
- export declare function defineEnterRule(options: EnterRuleOptions): PlainExtension;
486
+ export declare function defineEnterRule({ regex, handler, stop, }: EnterRuleOptions): PlainExtension;
469
487
 
470
488
  /**
471
489
  * Capture clicks near and arrow-key-motion past places that don't have a
@@ -836,9 +854,11 @@ export declare function defineTextAlignKeymap(types: string[]): PlainExtension;
836
854
  *
837
855
  * See also {@link defineEnterRule}.
838
856
  *
857
+ * @param options
858
+ *
839
859
  * @public
840
860
  */
841
- export declare function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension;
861
+ export declare function defineTextBlockEnterRule({ regex, type, attrs, stop, }: TextBlockEnterRuleOptions): PlainExtension;
842
862
 
843
863
  /**
844
864
  * Defines an input rule that changes the type of a textblock when the matched
@@ -846,6 +866,8 @@ export declare function defineTextBlockEnterRule(options: TextBlockEnterRuleOpti
846
866
  *
847
867
  * See also [textblockTypeInputRule](https://prosemirror.net/docs/ref/#inputrules.textblockTypeInputRule)
848
868
  *
869
+ * @param options
870
+ *
849
871
  * @public
850
872
  */
851
873
  export declare function defineTextBlockInputRule({ regex, type, attrs, }: {
@@ -903,6 +925,8 @@ export declare function defineVirtualSelection(): VirtualSelectionExtension;
903
925
  *
904
926
  * See also [wrappingInputRule](https://prosemirror.net/docs/ref/#inputrules.wrappingInputRule)
905
927
  *
928
+ * @param options
929
+ *
906
930
  * @public
907
931
  */
908
932
  export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
@@ -931,6 +955,31 @@ export declare function defineWrappingInputRule({ regex, type, attrs, join, }: {
931
955
  join?: (match: RegExpMatchArray, node: ProseMirrorNode) => boolean;
932
956
  }): PlainExtension;
933
957
 
958
+ /**
959
+ * @public
960
+ */
961
+ export declare function defineYjs(options: YjsOptions): YjsExtension;
962
+
963
+ declare function defineYjsCommands(): YjsCommandsExtension;
964
+ export { defineYjsCommands }
965
+ export { defineYjsCommands as defineYjsCommands_alias_1 }
966
+
967
+ declare function defineYjsCursorPlugin(options: YjsCursorOptions): PlainExtension;
968
+ export { defineYjsCursorPlugin }
969
+ export { defineYjsCursorPlugin as defineYjsCursorPlugin_alias_1 }
970
+
971
+ declare function defineYjsKeymap(): PlainExtension;
972
+ export { defineYjsKeymap }
973
+ export { defineYjsKeymap as defineYjsKeymap_alias_1 }
974
+
975
+ declare function defineYjsSyncPlugin(options: YjsSyncOptions): PlainExtension;
976
+ export { defineYjsSyncPlugin }
977
+ export { defineYjsSyncPlugin as defineYjsSyncPlugin_alias_1 }
978
+
979
+ declare function defineYjsUndoPlugin(options: YjsUndoOptions): PlainExtension;
980
+ export { defineYjsUndoPlugin }
981
+ export { defineYjsUndoPlugin as defineYjsUndoPlugin_alias_1 }
982
+
934
983
  /**
935
984
  * @internal
936
985
  */
@@ -1372,6 +1421,11 @@ export declare function prepareHighlighter(options: HighlighterOptions): Highlig
1372
1421
  */
1373
1422
  export declare function pressKey(input: string): Promise<void>;
1374
1423
 
1424
+ /**
1425
+ * @internal
1426
+ */
1427
+ export declare const redo: Command;
1428
+
1375
1429
  /**
1376
1430
  * Options for {@link defineSearchQuery}
1377
1431
  *
@@ -1485,13 +1539,13 @@ export declare function setupTest(): {
1485
1539
  level: number;
1486
1540
  }>;
1487
1541
  image: NodeAction< {
1488
- src?: string | null;
1542
+ src?: (string | null) | undefined;
1489
1543
  }>;
1490
1544
  list: NodeAction< {
1491
- kind?: "bullet" | "ordered" | "task" | "toggle";
1492
- order?: number | null;
1493
- checked?: boolean;
1494
- collapsed?: boolean;
1545
+ kind?: ("bullet" | "ordered" | "task" | "toggle") | undefined;
1546
+ order?: (number | null) | undefined;
1547
+ checked?: boolean | undefined;
1548
+ collapsed?: boolean | undefined;
1495
1549
  }>;
1496
1550
  table: NodeAction< {
1497
1551
  readonly [x: string]: any;
@@ -1717,6 +1771,11 @@ export declare type UnderlineSpecExtension = Extension<{
1717
1771
  };
1718
1772
  }>;
1719
1773
 
1774
+ /**
1775
+ * @internal
1776
+ */
1777
+ export declare const undo: Command;
1778
+
1720
1779
  export { UnwrapListOptions }
1721
1780
 
1722
1781
  /**
@@ -1726,4 +1785,85 @@ export declare type VirtualSelectionExtension = PlainExtension;
1726
1785
 
1727
1786
  export { WrapInListGetAttrs }
1728
1787
 
1788
+ /**
1789
+ * @internal
1790
+ */
1791
+ export declare type YjsCommandsExtension = Extension<{
1792
+ Commands: {
1793
+ undo: [];
1794
+ redo: [];
1795
+ };
1796
+ }>;
1797
+
1798
+ declare interface YjsCursorOptions extends YjsCursorPluginOptions {
1799
+ awareness: Awareness;
1800
+ }
1801
+ export { YjsCursorOptions }
1802
+ export { YjsCursorOptions as YjsCursorOptions_alias_1 }
1803
+
1804
+ /**
1805
+ * Options for `y-prosemirror`'s `yCursorPlugin`.
1806
+ */
1807
+ declare type YjsCursorPluginOptions = NonNullable<Parameters<typeof yCursorPlugin>[1]>;
1808
+ export { YjsCursorPluginOptions }
1809
+ export { YjsCursorPluginOptions as YjsCursorPluginOptions_alias_1 }
1810
+
1811
+ /**
1812
+ * @internal
1813
+ */
1814
+ export declare type YjsExtension = Union<[YjsCommandsExtension, PlainExtension]>;
1815
+
1816
+ export declare interface YjsOptions {
1817
+ /**
1818
+ * The Yjs instance handles the state of shared data.
1819
+ */
1820
+ doc: Y.Doc;
1821
+ /**
1822
+ * The Awareness instance.
1823
+ */
1824
+ awareness: Awareness;
1825
+ /**
1826
+ * The Yjs XmlFragment to use. If not provided,
1827
+ * `doc.getXmlFragment('prosemirror')` will be used.
1828
+ */
1829
+ fragment?: Y.XmlFragment;
1830
+ /**
1831
+ * Options for `y-prosemirror`'s `ySyncPlugin`.
1832
+ */
1833
+ sync?: YjsSyncPluginOptions;
1834
+ /**
1835
+ * Options for the `y-prosemirror`'s `yUndoPlugin`.
1836
+ */
1837
+ undo?: YjsUndoPluginOptions;
1838
+ /**
1839
+ * Options for `y-prosemirror`'s `yCursorPlugin`.
1840
+ */
1841
+ cursor?: YjsCursorPluginOptions;
1842
+ }
1843
+
1844
+ declare interface YjsSyncOptions extends YjsSyncPluginOptions {
1845
+ fragment: Y.XmlFragment;
1846
+ }
1847
+ export { YjsSyncOptions }
1848
+ export { YjsSyncOptions as YjsSyncOptions_alias_1 }
1849
+
1850
+ /**
1851
+ * Options for `y-prosemirror`'s `ySyncPlugin`.
1852
+ */
1853
+ declare type YjsSyncPluginOptions = NonNullable<Parameters<typeof ySyncPlugin>[1]>;
1854
+ export { YjsSyncPluginOptions }
1855
+ export { YjsSyncPluginOptions as YjsSyncPluginOptions_alias_1 }
1856
+
1857
+ declare interface YjsUndoOptions extends YjsUndoPluginOptions {
1858
+ }
1859
+ export { YjsUndoOptions }
1860
+ export { YjsUndoOptions as YjsUndoOptions_alias_1 }
1861
+
1862
+ /**
1863
+ * Options for the `y-prosemirror`'s `yUndoPlugin`.
1864
+ */
1865
+ declare type YjsUndoPluginOptions = NonNullable<Parameters<typeof yUndoPlugin>[0]>;
1866
+ export { YjsUndoPluginOptions }
1867
+ export { YjsUndoPluginOptions as YjsUndoPluginOptions_alias_1 }
1868
+
1729
1869
  export { }
@@ -13,13 +13,20 @@ import {
13
13
  PluginKey,
14
14
  ProseMirrorPlugin
15
15
  } from "@prosekit/pm/state";
16
- function defineEnterRule(options) {
17
- const { regex, handler, stop = false } = options;
16
+ function defineEnterRule({
17
+ regex,
18
+ handler,
19
+ stop = false
20
+ }) {
18
21
  const rule = new EnterRule(regex, handler, stop);
19
22
  return defineFacetPayload(enterRule, [rule]);
20
23
  }
21
- function defineTextBlockEnterRule(options) {
22
- const { regex, type, attrs, stop = true } = options;
24
+ function defineTextBlockEnterRule({
25
+ regex,
26
+ type,
27
+ attrs,
28
+ stop = true
29
+ }) {
23
30
  return defineEnterRule({
24
31
  regex,
25
32
  handler: ({ state, from, to, match }) => {
@@ -26,7 +26,7 @@ function defineBlockquoteInputRule() {
26
26
  });
27
27
  }
28
28
  function defineBlockquote() {
29
- return union([defineBlockquoteSpec(), defineBlockquoteInputRule()]);
29
+ return union(defineBlockquoteSpec(), defineBlockquoteInputRule());
30
30
  }
31
31
  export {
32
32
  defineBlockquote,
@@ -55,12 +55,12 @@ function defineBoldInputRule() {
55
55
  });
56
56
  }
57
57
  function defineBold() {
58
- return union([
58
+ return union(
59
59
  defineBoldSpec(),
60
60
  defineBoldCommands(),
61
61
  defineBoldKeymap(),
62
62
  defineBoldInputRule()
63
- ]);
63
+ );
64
64
  }
65
65
  export {
66
66
  defineBold,
@@ -3,6 +3,7 @@ export { CodeBlockExtension_alias_1 as CodeBlockExtension } from './_tsup-dts-ro
3
3
  export { defineCodeBlockCommands_alias_1 as defineCodeBlockCommands } from './_tsup-dts-rollup';
4
4
  export { CodeBlockCommandsExtension_alias_1 as CodeBlockCommandsExtension } from './_tsup-dts-rollup';
5
5
  export { defineCodeBlockHighlight_alias_1 as defineCodeBlockHighlight } from './_tsup-dts-rollup';
6
+ export { CodeBlockHighlightOptions_alias_1 as CodeBlockHighlightOptions } from './_tsup-dts-rollup';
6
7
  export { HighlightParser_alias_1 as HighlightParser } from './_tsup-dts-rollup';
7
8
  export { defineCodeBlockEnterRule_alias_1 as defineCodeBlockEnterRule } from './_tsup-dts-rollup';
8
9
  export { defineCodeBlockInputRule_alias_1 as defineCodeBlockInputRule } from './_tsup-dts-rollup';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineTextBlockEnterRule
3
- } from "./chunk-5H7DHO2K.js";
3
+ } from "./chunk-RE23OQPF.js";
4
4
  import {
5
5
  defineTextBlockInputRule
6
6
  } from "./chunk-J57QWYYX.js";
@@ -118,13 +118,13 @@ function defineCodeBlockSpec() {
118
118
 
119
119
  // src/code-block/code-block.ts
120
120
  function defineCodeBlock() {
121
- return union([
121
+ return union(
122
122
  defineCodeBlockSpec(),
123
123
  defineCodeBlockInputRule(),
124
124
  defineCodeBlockEnterRule(),
125
125
  defineCodeBlockKeymap(),
126
126
  defineCodeBlockCommands()
127
- ]);
127
+ );
128
128
  }
129
129
 
130
130
  // src/code-block/code-block-highlight.ts
@@ -37,12 +37,12 @@ function defineCodeInputRule() {
37
37
  });
38
38
  }
39
39
  function defineCode() {
40
- return union([
40
+ return union(
41
41
  defineCodeSpec(),
42
42
  defineCodeCommands(),
43
43
  defineCodeKeymap(),
44
44
  defineCodeInputRule()
45
- ]);
45
+ );
46
46
  }
47
47
  export {
48
48
  defineCode,
@@ -1,6 +1,6 @@
1
1
  // src/commit/index.ts
2
2
  import {
3
- collectNodes,
3
+ collectChildren,
4
4
  defineDefaultState,
5
5
  definePlugin,
6
6
  jsonFromNode,
@@ -48,7 +48,7 @@ function decorateDeletionSlice(slice) {
48
48
  ];
49
49
  }
50
50
  if (openStart > 0 && content.childCount >= 2) {
51
- const nodes = collectNodes(content);
51
+ const nodes = collectChildren(content);
52
52
  const head = Fragment.from(nodes.slice(0, 1));
53
53
  const body = Fragment.from(nodes.slice(1));
54
54
  return [
@@ -57,7 +57,7 @@ function decorateDeletionSlice(slice) {
57
57
  ];
58
58
  }
59
59
  if (openEnd > 0 && content.childCount >= 2) {
60
- const nodes = collectNodes(content);
60
+ const nodes = collectChildren(content);
61
61
  const body = Fragment.from(nodes.slice(0, -1));
62
62
  const tail = Fragment.from(nodes.slice(-1));
63
63
  return [
@@ -134,10 +134,10 @@ function defineCommitDecoration(commit) {
134
134
  });
135
135
  }
136
136
  function defineCommitViewer(commit) {
137
- return union([
137
+ return union(
138
138
  defineDefaultState({ defaultDoc: commit.doc }),
139
139
  defineCommitDecoration(commit)
140
- ]);
140
+ );
141
141
  }
142
142
  var CommitRecorder = class {
143
143
  constructor() {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineEnterRule,
3
3
  defineTextBlockEnterRule
4
- } from "./chunk-5H7DHO2K.js";
4
+ } from "./chunk-RE23OQPF.js";
5
5
  export {
6
6
  defineEnterRule,
7
7
  defineTextBlockEnterRule
@@ -94,12 +94,12 @@ function defineHeadingSpec() {
94
94
 
95
95
  // src/heading/index.ts
96
96
  function defineHeading() {
97
- return union([
97
+ return union(
98
98
  defineHeadingSpec(),
99
99
  defineHeadingInputRule(),
100
100
  defineHeadingKeymap(),
101
101
  defineHeadingCommands()
102
- ]);
102
+ );
103
103
  }
104
104
  export {
105
105
  defineHeading,
@@ -40,7 +40,7 @@ function defineImageCommands() {
40
40
  });
41
41
  }
42
42
  function defineImage() {
43
- return union([defineImageSpec(), defineImageCommands()]);
43
+ return union(defineImageSpec(), defineImageCommands());
44
44
  }
45
45
  export {
46
46
  defineImage,
@@ -45,12 +45,12 @@ function defineItalicInputRule() {
45
45
  });
46
46
  }
47
47
  function defineItalic() {
48
- return union([
48
+ return union(
49
49
  defineItalicSpec(),
50
50
  defineItalicCommands(),
51
51
  defineItalicKeymap(),
52
52
  defineItalicInputRule()
53
- ]);
53
+ );
54
54
  }
55
55
  export {
56
56
  defineItalic,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-GPSAJOJA.js";
4
4
  import {
5
5
  defineEnterRule
6
- } from "./chunk-5H7DHO2K.js";
6
+ } from "./chunk-RE23OQPF.js";
7
7
  import {
8
8
  defineInputRule
9
9
  } from "./chunk-J57QWYYX.js";
@@ -98,12 +98,12 @@ function defineLinkMarkRule() {
98
98
  });
99
99
  }
100
100
  function defineLink() {
101
- return union([
101
+ return union(
102
102
  defineLinkSpec(),
103
103
  defineLinkCommands(),
104
104
  defineLinkInputRule(),
105
105
  defineLinkEnterRule()
106
- ]);
106
+ );
107
107
  }
108
108
  export {
109
109
  defineLink,
@@ -94,13 +94,13 @@ function defineListSpec() {
94
94
  // src/list/index.ts
95
95
  import { ListDOMSerializer } from "prosemirror-flat-list";
96
96
  function defineList() {
97
- return union2([
97
+ return union2(
98
98
  defineListSpec(),
99
99
  defineListPlugins(),
100
100
  defineListKeymap(),
101
101
  defineListInputRules(),
102
102
  defineListCommands()
103
- ]);
103
+ );
104
104
  }
105
105
  export {
106
106
  ListDOMSerializer,
@@ -47,7 +47,7 @@ function defineMentionCommands() {
47
47
  });
48
48
  }
49
49
  function defineMention() {
50
- return union([defineMentionSpec(), defineMentionCommands()]);
50
+ return union(defineMentionSpec(), defineMentionCommands());
51
51
  }
52
52
  export {
53
53
  defineMention,
@@ -44,12 +44,12 @@ function defineStrikeInputRule() {
44
44
  });
45
45
  }
46
46
  function defineStrike() {
47
- return union([
47
+ return union(
48
48
  defineStrikeSpec(),
49
49
  defineStrikeCommands(),
50
50
  defineStrikeKeymap(),
51
51
  defineStrikeInputRule()
52
- ]);
52
+ );
53
53
  }
54
54
  export {
55
55
  defineStrike,
@@ -172,14 +172,14 @@ function defineTableHeaderCellSpec() {
172
172
 
173
173
  // src/table/index.ts
174
174
  function defineTable() {
175
- return union([
175
+ return union(
176
176
  defineTableSpec(),
177
177
  defineTableRowSpec(),
178
178
  defineTableCellSpec(),
179
179
  defineTableHeaderCellSpec(),
180
180
  defineTablePlugins(),
181
181
  defineTableCommands()
182
- ]);
182
+ );
183
183
  }
184
184
  export {
185
185
  defineTable,
@@ -41,11 +41,11 @@ function defineTextAlignKeymap(types) {
41
41
  });
42
42
  }
43
43
  function defineTextAlign(options) {
44
- return union([
44
+ return union(
45
45
  defineTextAlignAttrs(options.types, options.default || "left"),
46
46
  defineTextAlignKeymap(options.types),
47
47
  defineTextAlignCommands(options.types)
48
- ]);
48
+ );
49
49
  }
50
50
  export {
51
51
  defineTextAlign,
@@ -31,11 +31,11 @@ function defineUnderlineKeymap() {
31
31
  });
32
32
  }
33
33
  function defineUnderline() {
34
- return union([
34
+ return union(
35
35
  defineUnderlineSpec(),
36
36
  defineUnderlineCommands(),
37
37
  defineUnderlineKeymap()
38
- ]);
38
+ );
39
39
  }
40
40
  export {
41
41
  defineUnderline,
@@ -0,0 +1,14 @@
1
+ export { defineYjs } from './_tsup-dts-rollup';
2
+ export { YjsOptions } from './_tsup-dts-rollup';
3
+ export { YjsExtension } from './_tsup-dts-rollup';
4
+ export { defineYjsCommands_alias_1 as defineYjsCommands } from './_tsup-dts-rollup';
5
+ export { defineYjsCursorPlugin_alias_1 as defineYjsCursorPlugin } from './_tsup-dts-rollup';
6
+ export { defineYjsKeymap } from './_tsup-dts-rollup';
7
+ export { defineYjsSyncPlugin } from './_tsup-dts-rollup';
8
+ export { defineYjsUndoPlugin } from './_tsup-dts-rollup';
9
+ export { YjsCursorOptions_alias_1 as YjsCursorOptions } from './_tsup-dts-rollup';
10
+ export { YjsCursorPluginOptions_alias_1 as YjsCursorPluginOptions } from './_tsup-dts-rollup';
11
+ export { YjsSyncOptions } from './_tsup-dts-rollup';
12
+ export { YjsSyncPluginOptions } from './_tsup-dts-rollup';
13
+ export { YjsUndoOptions } from './_tsup-dts-rollup';
14
+ export { YjsUndoPluginOptions } from './_tsup-dts-rollup';
@@ -0,0 +1,150 @@
1
+ // src/yjs/index.ts
2
+ import {
3
+ Priority,
4
+ union,
5
+ withPriority
6
+ } from "@prosekit/core";
7
+
8
+ // ../../node_modules/.pnpm/y-protocols@1.0.6_yjs@13.6.18/node_modules/y-protocols/awareness.js
9
+ import * as Y from "yjs";
10
+
11
+ // src/yjs/index.ts
12
+ import "yjs";
13
+
14
+ // src/yjs/commands.ts
15
+ import { defineCommands } from "@prosekit/core";
16
+
17
+ // src/yjs/undo-plugin.ts
18
+ import { definePlugin } from "@prosekit/core";
19
+ import {
20
+ yUndoPluginKey,
21
+ yUndoPlugin as originalYUndoPlugin,
22
+ undo as yUndo,
23
+ redo as yRedo
24
+ } from "y-prosemirror";
25
+ function fixYUndoPlugin(yUndoPluginInstance) {
26
+ const originalUndoPluginView = yUndoPluginInstance.spec.view;
27
+ yUndoPluginInstance.spec.view = (view) => {
28
+ const { undoManager } = yUndoPluginKey.getState(view.state);
29
+ if (undoManager.restore) {
30
+ undoManager.restore();
31
+ undoManager.restore = () => {
32
+ };
33
+ }
34
+ const viewRet = originalUndoPluginView ? originalUndoPluginView(view) : void 0;
35
+ return {
36
+ destroy: () => {
37
+ const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager);
38
+ const observers = undoManager._observers;
39
+ undoManager.restore = () => {
40
+ if (hasUndoManSelf) {
41
+ undoManager.trackedOrigins.add(undoManager);
42
+ }
43
+ undoManager.doc.on(
44
+ "afterTransaction",
45
+ undoManager.afterTransactionHandler
46
+ );
47
+ undoManager._observers = observers;
48
+ };
49
+ if (viewRet == null ? void 0 : viewRet.destroy) {
50
+ viewRet.destroy();
51
+ }
52
+ }
53
+ };
54
+ };
55
+ }
56
+ function yUndoPlugin(options) {
57
+ const yUndoPluginInstance = originalYUndoPlugin(options);
58
+ fixYUndoPlugin(yUndoPluginInstance);
59
+ return yUndoPluginInstance;
60
+ }
61
+ var undo = (state, dispatch) => {
62
+ const { undoManager } = yUndoPluginKey.getState(state);
63
+ if (undoManager.undoStack.length === 0) {
64
+ return false;
65
+ }
66
+ if (!dispatch) {
67
+ return true;
68
+ }
69
+ return yUndo(state);
70
+ };
71
+ var redo = (state, dispatch) => {
72
+ const { undoManager } = yUndoPluginKey.getState(state);
73
+ if (undoManager.redoStack.length === 0) {
74
+ return false;
75
+ }
76
+ if (!dispatch) {
77
+ return true;
78
+ }
79
+ return yRedo(state);
80
+ };
81
+ function defineYjsUndoPlugin(options) {
82
+ return definePlugin(yUndoPlugin(options));
83
+ }
84
+
85
+ // src/yjs/commands.ts
86
+ var commands = {
87
+ undo: () => undo,
88
+ redo: () => redo
89
+ };
90
+ function defineYjsCommands() {
91
+ return defineCommands(commands);
92
+ }
93
+
94
+ // src/yjs/cursor-plugin.ts
95
+ import { definePlugin as definePlugin2 } from "@prosekit/core";
96
+ import { yCursorPlugin } from "y-prosemirror";
97
+ function defineYjsCursorPlugin(options) {
98
+ const { awareness, ...rest } = options;
99
+ return definePlugin2(yCursorPlugin(awareness, rest));
100
+ }
101
+
102
+ // src/yjs/keymap.ts
103
+ import {
104
+ defineKeymap,
105
+ isApple
106
+ } from "@prosekit/core";
107
+ var keymap = {
108
+ "Mod-z": undo,
109
+ "Shift-Mod-z": redo
110
+ };
111
+ if (!isApple) {
112
+ keymap["Mod-y"] = redo;
113
+ }
114
+ function defineYjsKeymap() {
115
+ return defineKeymap(keymap);
116
+ }
117
+
118
+ // src/yjs/sync-plugin.ts
119
+ import { definePlugin as definePlugin3 } from "@prosekit/core";
120
+ import { ySyncPlugin } from "y-prosemirror";
121
+ import "yjs";
122
+ function defineYjsSyncPlugin(options) {
123
+ const { fragment, ...rest } = options;
124
+ return definePlugin3(ySyncPlugin(fragment, rest));
125
+ }
126
+
127
+ // src/yjs/index.ts
128
+ function defineYjs(options) {
129
+ var _a;
130
+ const { doc, awareness, sync, undo: undo2, cursor } = options;
131
+ const fragment = (_a = options.fragment) != null ? _a : doc.getXmlFragment("prosemirror");
132
+ return withPriority(
133
+ union([
134
+ defineYjsKeymap(),
135
+ defineYjsCommands(),
136
+ defineYjsCursorPlugin({ ...cursor, awareness }),
137
+ defineYjsUndoPlugin({ ...undo2 }),
138
+ defineYjsSyncPlugin({ ...sync, fragment })
139
+ ]),
140
+ Priority.high
141
+ );
142
+ }
143
+ export {
144
+ defineYjs,
145
+ defineYjsCommands,
146
+ defineYjsCursorPlugin,
147
+ defineYjsKeymap,
148
+ defineYjsSyncPlugin,
149
+ defineYjsUndoPlugin
150
+ };
@@ -0,0 +1,31 @@
1
+ /* src/yjs/style.css */
2
+ .ProseMirror .ProseMirror-yjs-cursor {
3
+ position: absolute;
4
+ border-left: black;
5
+ border-left-style: solid;
6
+ border-left-width: 2px;
7
+ border-color: orange;
8
+ height: 1em;
9
+ word-break: normal;
10
+ pointer-events: none;
11
+ }
12
+ .ProseMirror .ProseMirror-yjs-cursor > div {
13
+ position: relative;
14
+ top: -1.05em;
15
+ font-size: 13px;
16
+ background-color: rgb(250, 129, 0);
17
+ font-family: serif;
18
+ font-style: normal;
19
+ font-weight: normal;
20
+ line-height: normal;
21
+ -webkit-user-select: none;
22
+ -moz-user-select: none;
23
+ -ms-user-select: none;
24
+ user-select: none;
25
+ color: white;
26
+ padding-left: 2px;
27
+ padding-right: 2px;
28
+ }
29
+ .ProseMirror > .ProseMirror-yjs-cursor:first-child {
30
+ margin-top: 16px;
31
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.7.8",
4
+ "version": "0.7.10",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -180,6 +180,14 @@
180
180
  },
181
181
  "./virtual-selection/style.css": {
182
182
  "default": "./dist/virtual-selection/style.css"
183
+ },
184
+ "./yjs": {
185
+ "types": "./dist/prosekit-extensions-yjs.d.ts",
186
+ "import": "./dist/prosekit-extensions-yjs.js",
187
+ "default": "./dist/prosekit-extensions-yjs.js"
188
+ },
189
+ "./yjs/style.css": {
190
+ "default": "./dist/yjs/style.css"
183
191
  }
184
192
  },
185
193
  "files": [
@@ -193,16 +201,31 @@
193
201
  "prosemirror-highlight": "^0.8.0",
194
202
  "prosemirror-search": "^1.0.0",
195
203
  "prosemirror-tables": "^1.4.0",
196
- "shiki": "^1.11.1",
197
- "@prosekit/core": "^0.7.7",
198
- "@prosekit/pm": "^0.1.7"
204
+ "shiki": "^1.12.1",
205
+ "@prosekit/core": "^0.7.8",
206
+ "@prosekit/pm": "^0.1.8"
207
+ },
208
+ "peerDependencies": {
209
+ "y-prosemirror": ">= 1.2.9",
210
+ "yjs": ">= 13.6.18"
211
+ },
212
+ "peerDependenciesMeta": {
213
+ "y-prosemirror": {
214
+ "optional": true
215
+ },
216
+ "yjs": {
217
+ "optional": true
218
+ }
199
219
  },
200
220
  "devDependencies": {
201
- "@vitest/browser": "^2.0.4",
202
- "tsup": "^8.2.2",
221
+ "@vitest/browser": "^2.0.5",
222
+ "tsup": "^8.2.4",
203
223
  "type-fest": "^4.23.0",
204
- "typescript": "^5.5.3",
205
- "vitest": "^2.0.4",
224
+ "typescript": "^5.5.4",
225
+ "vitest": "^2.0.5",
226
+ "y-prosemirror": "^1.2.9",
227
+ "y-protocols": "^1.0.6",
228
+ "yjs": "^13.6.18",
206
229
  "@prosekit/dev": "0.0.0"
207
230
  },
208
231
  "scripts": {
@@ -292,6 +315,9 @@
292
315
  ],
293
316
  "virtual-selection": [
294
317
  "./dist/prosekit-extensions-virtual-selection.d.ts"
318
+ ],
319
+ "yjs": [
320
+ "./dist/prosekit-extensions-yjs.d.ts"
295
321
  ]
296
322
  }
297
323
  }