@tiptap/extensions 3.0.0-beta.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.
Files changed (74) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +18 -0
  3. package/dist/character-count/index.cjs +129 -0
  4. package/dist/character-count/index.cjs.map +1 -0
  5. package/dist/character-count/index.d.cts +62 -0
  6. package/dist/character-count/index.d.ts +62 -0
  7. package/dist/character-count/index.js +102 -0
  8. package/dist/character-count/index.js.map +1 -0
  9. package/dist/drop-cursor/index.cjs +47 -0
  10. package/dist/drop-cursor/index.cjs.map +1 -0
  11. package/dist/drop-cursor/index.d.cts +31 -0
  12. package/dist/drop-cursor/index.d.ts +31 -0
  13. package/dist/drop-cursor/index.js +20 -0
  14. package/dist/drop-cursor/index.js.map +1 -0
  15. package/dist/focus/index.cjs +95 -0
  16. package/dist/focus/index.cjs.map +1 -0
  17. package/dist/focus/index.d.cts +28 -0
  18. package/dist/focus/index.d.ts +28 -0
  19. package/dist/focus/index.js +68 -0
  20. package/dist/focus/index.js.map +1 -0
  21. package/dist/gap-cursor/index.cjs +51 -0
  22. package/dist/gap-cursor/index.cjs.map +1 -0
  23. package/dist/gap-cursor/index.d.cts +25 -0
  24. package/dist/gap-cursor/index.d.ts +25 -0
  25. package/dist/gap-cursor/index.js +24 -0
  26. package/dist/gap-cursor/index.js.map +1 -0
  27. package/dist/index.cjs +421 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +272 -0
  30. package/dist/index.d.ts +272 -0
  31. package/dist/index.js +387 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/placeholder/index.cjs +88 -0
  34. package/dist/placeholder/index.cjs.map +1 -0
  35. package/dist/placeholder/index.d.cts +59 -0
  36. package/dist/placeholder/index.d.ts +59 -0
  37. package/dist/placeholder/index.js +61 -0
  38. package/dist/placeholder/index.js.map +1 -0
  39. package/dist/selection/index.cjs +63 -0
  40. package/dist/selection/index.cjs.map +1 -0
  41. package/dist/selection/index.d.cts +17 -0
  42. package/dist/selection/index.d.ts +17 -0
  43. package/dist/selection/index.js +36 -0
  44. package/dist/selection/index.js.map +1 -0
  45. package/dist/trailing-node/index.cjs +78 -0
  46. package/dist/trailing-node/index.cjs.map +1 -0
  47. package/dist/trailing-node/index.d.cts +28 -0
  48. package/dist/trailing-node/index.d.ts +28 -0
  49. package/dist/trailing-node/index.js +51 -0
  50. package/dist/trailing-node/index.js.map +1 -0
  51. package/dist/undo-redo/index.cjs +66 -0
  52. package/dist/undo-redo/index.cjs.map +1 -0
  53. package/dist/undo-redo/index.d.cts +44 -0
  54. package/dist/undo-redo/index.d.ts +44 -0
  55. package/dist/undo-redo/index.js +39 -0
  56. package/dist/undo-redo/index.js.map +1 -0
  57. package/package.json +114 -0
  58. package/src/character-count/character-count.ts +195 -0
  59. package/src/character-count/index.ts +1 -0
  60. package/src/drop-cursor/drop-cursor.ts +47 -0
  61. package/src/drop-cursor/index.ts +1 -0
  62. package/src/focus/focus.ts +110 -0
  63. package/src/focus/index.ts +1 -0
  64. package/src/gap-cursor/gap-cursor.ts +47 -0
  65. package/src/gap-cursor/index.ts +1 -0
  66. package/src/index.ts +8 -0
  67. package/src/placeholder/index.ts +1 -0
  68. package/src/placeholder/placeholder.ts +129 -0
  69. package/src/selection/index.ts +1 -0
  70. package/src/selection/selection.ts +51 -0
  71. package/src/trailing-node/index.ts +1 -0
  72. package/src/trailing-node/trailing-node.ts +84 -0
  73. package/src/undo-redo/index.ts +1 -0
  74. package/src/undo-redo/undo-redo.ts +86 -0
@@ -0,0 +1,61 @@
1
+ // src/placeholder/placeholder.ts
2
+ import { Extension, isNodeEmpty } from "@tiptap/core";
3
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
4
+ import { Decoration, DecorationSet } from "@tiptap/pm/view";
5
+ var Placeholder = Extension.create({
6
+ name: "placeholder",
7
+ addOptions() {
8
+ return {
9
+ emptyEditorClass: "is-editor-empty",
10
+ emptyNodeClass: "is-empty",
11
+ placeholder: "Write something \u2026",
12
+ showOnlyWhenEditable: true,
13
+ showOnlyCurrent: true,
14
+ includeChildren: false
15
+ };
16
+ },
17
+ addProseMirrorPlugins() {
18
+ return [
19
+ new Plugin({
20
+ key: new PluginKey("placeholder"),
21
+ props: {
22
+ decorations: ({ doc, selection }) => {
23
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
24
+ const { anchor } = selection;
25
+ const decorations = [];
26
+ if (!active) {
27
+ return null;
28
+ }
29
+ const isEmptyDoc = this.editor.isEmpty;
30
+ doc.descendants((node, pos) => {
31
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
32
+ const isEmpty = !node.isLeaf && isNodeEmpty(node);
33
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
34
+ const classes = [this.options.emptyNodeClass];
35
+ if (isEmptyDoc) {
36
+ classes.push(this.options.emptyEditorClass);
37
+ }
38
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
39
+ class: classes.join(" "),
40
+ "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
41
+ editor: this.editor,
42
+ node,
43
+ pos,
44
+ hasAnchor
45
+ }) : this.options.placeholder
46
+ });
47
+ decorations.push(decoration);
48
+ }
49
+ return this.options.includeChildren;
50
+ });
51
+ return DecorationSet.create(doc, decorations);
52
+ }
53
+ }
54
+ })
55
+ ];
56
+ }
57
+ });
58
+ export {
59
+ Placeholder
60
+ };
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/placeholder/placeholder.ts"],"sourcesContent":["import type { Editor } from '@tiptap/core'\nimport { Extension, isNodeEmpty } from '@tiptap/core'\nimport type { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: { editor: Editor; node: ProsemirrorNode; pos: number; hasAnchor: boolean }) => string)\n | string\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('placeholder'),\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n const isEmptyDoc = this.editor.isEmpty\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";AACA,SAAS,WAAW,mBAAmB;AAEvC,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AA0DnC,IAAM,cAAc,UAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,aAAa;AAAA,QAChC,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,SAAS,KAAK,OAAO,cAAc,CAAC,KAAK,QAAQ;AACvD,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,QAAQ;AACX,qBAAO;AAAA,YACT;AAEA,kBAAM,aAAa,KAAK,OAAO;AAE/B,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK;AACxD,oBAAM,UAAU,CAAC,KAAK,UAAU,YAAY,IAAI;AAEhD,mBAAK,aAAa,CAAC,KAAK,QAAQ,oBAAoB,SAAS;AAC3D,sBAAM,UAAU,CAAC,KAAK,QAAQ,cAAc;AAE5C,oBAAI,YAAY;AACd,0BAAQ,KAAK,KAAK,QAAQ,gBAAgB;AAAA,gBAC5C;AAEA,sBAAM,aAAa,WAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBAC3D,OAAO,QAAQ,KAAK,GAAG;AAAA,kBACvB,oBACE,OAAO,KAAK,QAAQ,gBAAgB,aAChC,KAAK,QAAQ,YAAY;AAAA,oBACvB,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF,CAAC,IACD,KAAK,QAAQ;AAAA,gBACrB,CAAC;AAED,4BAAY,KAAK,UAAU;AAAA,cAC7B;AAEA,qBAAO,KAAK,QAAQ;AAAA,YACtB,CAAC;AAED,mBAAO,cAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/selection/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Selection: () => Selection
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/selection/selection.ts
28
+ var import_core = require("@tiptap/core");
29
+ var import_state = require("@tiptap/pm/state");
30
+ var import_view = require("@tiptap/pm/view");
31
+ var Selection = import_core.Extension.create({
32
+ name: "selection",
33
+ addOptions() {
34
+ return {
35
+ className: "selection"
36
+ };
37
+ },
38
+ addProseMirrorPlugins() {
39
+ const { editor, options } = this;
40
+ return [
41
+ new import_state.Plugin({
42
+ key: new import_state.PluginKey("selection"),
43
+ props: {
44
+ decorations(state) {
45
+ if (state.selection.empty || editor.isFocused || !editor.isEditable || (0, import_core.isNodeSelection)(state.selection)) {
46
+ return null;
47
+ }
48
+ return import_view.DecorationSet.create(state.doc, [
49
+ import_view.Decoration.inline(state.selection.from, state.selection.to, {
50
+ class: options.className
51
+ })
52
+ ]);
53
+ }
54
+ }
55
+ })
56
+ ];
57
+ }
58
+ });
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Selection
62
+ });
63
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/selection/index.ts","../../src/selection/selection.ts"],"sourcesContent":["export * from './selection.js'\n","import { Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2C;AAC3C,mBAAkC;AAClC,kBAA0C;AAenC,IAAM,YAAY,sBAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,MAAM,UAAU,SAAS,OAAO,aAAa,CAAC,OAAO,kBAAc,6BAAgB,MAAM,SAAS,GAAG;AACvG,qBAAO;AAAA,YACT;AAEA,mBAAO,0BAAc,OAAO,MAAM,KAAK;AAAA,cACrC,uBAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ type SelectionOptions = {
4
+ /**
5
+ * The class name that should be added to the selected text.
6
+ * @default 'selection'
7
+ * @example 'is-selected'
8
+ */
9
+ className: string;
10
+ };
11
+ /**
12
+ * This extension allows you to add a class to the selected text.
13
+ * @see https://www.tiptap.dev/api/extensions/selection
14
+ */
15
+ declare const Selection: Extension<any, any>;
16
+
17
+ export { Selection, type SelectionOptions };
@@ -0,0 +1,17 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ type SelectionOptions = {
4
+ /**
5
+ * The class name that should be added to the selected text.
6
+ * @default 'selection'
7
+ * @example 'is-selected'
8
+ */
9
+ className: string;
10
+ };
11
+ /**
12
+ * This extension allows you to add a class to the selected text.
13
+ * @see https://www.tiptap.dev/api/extensions/selection
14
+ */
15
+ declare const Selection: Extension<any, any>;
16
+
17
+ export { Selection, type SelectionOptions };
@@ -0,0 +1,36 @@
1
+ // src/selection/selection.ts
2
+ import { Extension, isNodeSelection } from "@tiptap/core";
3
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
4
+ import { Decoration, DecorationSet } from "@tiptap/pm/view";
5
+ var Selection = Extension.create({
6
+ name: "selection",
7
+ addOptions() {
8
+ return {
9
+ className: "selection"
10
+ };
11
+ },
12
+ addProseMirrorPlugins() {
13
+ const { editor, options } = this;
14
+ return [
15
+ new Plugin({
16
+ key: new PluginKey("selection"),
17
+ props: {
18
+ decorations(state) {
19
+ if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection)) {
20
+ return null;
21
+ }
22
+ return DecorationSet.create(state.doc, [
23
+ Decoration.inline(state.selection.from, state.selection.to, {
24
+ class: options.className
25
+ })
26
+ ]);
27
+ }
28
+ }
29
+ })
30
+ ];
31
+ }
32
+ });
33
+ export {
34
+ Selection
35
+ };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/selection/selection.ts"],"sourcesContent":["import { Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";AAAA,SAAS,WAAW,uBAAuB;AAC3C,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AAenC,IAAM,YAAY,UAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,MAAM,UAAU,SAAS,OAAO,aAAa,CAAC,OAAO,cAAc,gBAAgB,MAAM,SAAS,GAAG;AACvG,qBAAO;AAAA,YACT;AAEA,mBAAO,cAAc,OAAO,MAAM,KAAK;AAAA,cACrC,WAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/trailing-node/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TrailingNode: () => TrailingNode
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/trailing-node/trailing-node.ts
28
+ var import_core = require("@tiptap/core");
29
+ var import_state = require("@tiptap/pm/state");
30
+ function nodeEqualsType({ types, node }) {
31
+ return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
32
+ }
33
+ var TrailingNode = import_core.Extension.create({
34
+ name: "trailingNode",
35
+ addOptions() {
36
+ return {
37
+ node: "paragraph",
38
+ notAfter: []
39
+ };
40
+ },
41
+ addProseMirrorPlugins() {
42
+ const plugin = new import_state.PluginKey(this.name);
43
+ const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(this.options.node).includes(node.name));
44
+ return [
45
+ new import_state.Plugin({
46
+ key: plugin,
47
+ appendTransaction: (_, __, state) => {
48
+ const { doc, tr, schema } = state;
49
+ const shouldInsertNodeAtEnd = plugin.getState(state);
50
+ const endPosition = doc.content.size;
51
+ const type = schema.nodes[this.options.node];
52
+ if (!shouldInsertNodeAtEnd) {
53
+ return;
54
+ }
55
+ return tr.insert(endPosition, type.create());
56
+ },
57
+ state: {
58
+ init: (_, state) => {
59
+ const lastNode = state.tr.doc.lastChild;
60
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
61
+ },
62
+ apply: (tr, value) => {
63
+ if (!tr.docChanged) {
64
+ return value;
65
+ }
66
+ const lastNode = tr.doc.lastChild;
67
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
68
+ }
69
+ }
70
+ })
71
+ ];
72
+ }
73
+ });
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ TrailingNode
77
+ });
78
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/trailing-node/index.ts","../../src/trailing-node/trailing-node.ts"],"sourcesContent":["export * from './trailing-node.js'\n","import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nfunction nodeEqualsType({ types, node }: { types: NodeType | NodeType[]; node: Node | null | undefined }) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default 'paragraph'\n */\n node: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: 'paragraph',\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(this.options.node).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (_, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[this.options.node]\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAE1B,mBAAkC;AAElC,SAAS,eAAe,EAAE,OAAO,KAAK,GAAoE;AACxG,SAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,6BAAM,UAAS;AACvF;AA2BO,IAAM,eAAe,sBAAU,OAA4B;AAAA,EAChE,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,SAAS,IAAI,uBAAU,KAAK,IAAI;AACtC,UAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO,OAAO,KAAK,EAC1D,IAAI,CAAC,CAAC,EAAE,KAAK,MAAM,KAAK,EACxB,OAAO,WAAS,KAAK,QAAQ,YAAY,CAAC,GAAG,OAAO,KAAK,QAAQ,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AAE7F,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK;AAAA,QACL,mBAAmB,CAAC,GAAG,IAAI,UAAU;AACnC,gBAAM,EAAE,KAAK,IAAI,OAAO,IAAI;AAC5B,gBAAM,wBAAwB,OAAO,SAAS,KAAK;AACnD,gBAAM,cAAc,IAAI,QAAQ;AAChC,gBAAM,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI;AAE3C,cAAI,CAAC,uBAAuB;AAC1B;AAAA,UACF;AAEA,iBAAO,GAAG,OAAO,aAAa,KAAK,OAAO,CAAC;AAAA,QAC7C;AAAA,QACA,OAAO;AAAA,UACL,MAAM,CAAC,GAAG,UAAU;AAClB,kBAAM,WAAW,MAAM,GAAG,IAAI;AAE9B,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,UACA,OAAO,CAAC,IAAI,UAAU;AACpB,gBAAI,CAAC,GAAG,YAAY;AAClB,qBAAO;AAAA,YACT;AAEA,kBAAM,WAAW,GAAG,IAAI;AAExB,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,28 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ /**
4
+ * Extension based on:
5
+ * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js
6
+ * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
7
+ */
8
+ interface TrailingNodeOptions {
9
+ /**
10
+ * The node type that should be inserted at the end of the document.
11
+ * @note the node will always be added to the `notAfter` lists to
12
+ * prevent an infinite loop.
13
+ * @default 'paragraph'
14
+ */
15
+ node: string;
16
+ /**
17
+ * The node types after which the trailing node should not be inserted.
18
+ * @default ['paragraph']
19
+ */
20
+ notAfter?: string | string[];
21
+ }
22
+ /**
23
+ * This extension allows you to add an extra node at the end of the document.
24
+ * @see https://www.tiptap.dev/api/extensions/trailing-node
25
+ */
26
+ declare const TrailingNode: Extension<TrailingNodeOptions, any>;
27
+
28
+ export { TrailingNode, type TrailingNodeOptions };
@@ -0,0 +1,28 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ /**
4
+ * Extension based on:
5
+ * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js
6
+ * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
7
+ */
8
+ interface TrailingNodeOptions {
9
+ /**
10
+ * The node type that should be inserted at the end of the document.
11
+ * @note the node will always be added to the `notAfter` lists to
12
+ * prevent an infinite loop.
13
+ * @default 'paragraph'
14
+ */
15
+ node: string;
16
+ /**
17
+ * The node types after which the trailing node should not be inserted.
18
+ * @default ['paragraph']
19
+ */
20
+ notAfter?: string | string[];
21
+ }
22
+ /**
23
+ * This extension allows you to add an extra node at the end of the document.
24
+ * @see https://www.tiptap.dev/api/extensions/trailing-node
25
+ */
26
+ declare const TrailingNode: Extension<TrailingNodeOptions, any>;
27
+
28
+ export { TrailingNode, type TrailingNodeOptions };
@@ -0,0 +1,51 @@
1
+ // src/trailing-node/trailing-node.ts
2
+ import { Extension } from "@tiptap/core";
3
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
4
+ function nodeEqualsType({ types, node }) {
5
+ return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
6
+ }
7
+ var TrailingNode = Extension.create({
8
+ name: "trailingNode",
9
+ addOptions() {
10
+ return {
11
+ node: "paragraph",
12
+ notAfter: []
13
+ };
14
+ },
15
+ addProseMirrorPlugins() {
16
+ const plugin = new PluginKey(this.name);
17
+ const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(this.options.node).includes(node.name));
18
+ return [
19
+ new Plugin({
20
+ key: plugin,
21
+ appendTransaction: (_, __, state) => {
22
+ const { doc, tr, schema } = state;
23
+ const shouldInsertNodeAtEnd = plugin.getState(state);
24
+ const endPosition = doc.content.size;
25
+ const type = schema.nodes[this.options.node];
26
+ if (!shouldInsertNodeAtEnd) {
27
+ return;
28
+ }
29
+ return tr.insert(endPosition, type.create());
30
+ },
31
+ state: {
32
+ init: (_, state) => {
33
+ const lastNode = state.tr.doc.lastChild;
34
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
35
+ },
36
+ apply: (tr, value) => {
37
+ if (!tr.docChanged) {
38
+ return value;
39
+ }
40
+ const lastNode = tr.doc.lastChild;
41
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
42
+ }
43
+ }
44
+ })
45
+ ];
46
+ }
47
+ });
48
+ export {
49
+ TrailingNode
50
+ };
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/trailing-node/trailing-node.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nfunction nodeEqualsType({ types, node }: { types: NodeType | NodeType[]; node: Node | null | undefined }) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default 'paragraph'\n */\n node: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: 'paragraph',\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(this.options.node).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (_, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[this.options.node]\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAE1B,SAAS,QAAQ,iBAAiB;AAElC,SAAS,eAAe,EAAE,OAAO,KAAK,GAAoE;AACxG,SAAQ,QAAQ,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,KAAK,IAAI,MAAM,6BAAM,UAAS;AACvF;AA2BO,IAAM,eAAe,UAAU,OAA4B;AAAA,EAChE,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,SAAS,IAAI,UAAU,KAAK,IAAI;AACtC,UAAM,gBAAgB,OAAO,QAAQ,KAAK,OAAO,OAAO,KAAK,EAC1D,IAAI,CAAC,CAAC,EAAE,KAAK,MAAM,KAAK,EACxB,OAAO,WAAS,KAAK,QAAQ,YAAY,CAAC,GAAG,OAAO,KAAK,QAAQ,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;AAE7F,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK;AAAA,QACL,mBAAmB,CAAC,GAAG,IAAI,UAAU;AACnC,gBAAM,EAAE,KAAK,IAAI,OAAO,IAAI;AAC5B,gBAAM,wBAAwB,OAAO,SAAS,KAAK;AACnD,gBAAM,cAAc,IAAI,QAAQ;AAChC,gBAAM,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI;AAE3C,cAAI,CAAC,uBAAuB;AAC1B;AAAA,UACF;AAEA,iBAAO,GAAG,OAAO,aAAa,KAAK,OAAO,CAAC;AAAA,QAC7C;AAAA,QACA,OAAO;AAAA,UACL,MAAM,CAAC,GAAG,UAAU;AAClB,kBAAM,WAAW,MAAM,GAAG,IAAI;AAE9B,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,UACA,OAAO,CAAC,IAAI,UAAU;AACpB,gBAAI,CAAC,GAAG,YAAY;AAClB,qBAAO;AAAA,YACT;AAEA,kBAAM,WAAW,GAAG,IAAI;AAExB,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/undo-redo/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ UndoRedo: () => UndoRedo
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/undo-redo/undo-redo.ts
28
+ var import_core = require("@tiptap/core");
29
+ var import_history = require("@tiptap/pm/history");
30
+ var UndoRedo = import_core.Extension.create({
31
+ name: "undoRedo",
32
+ addOptions() {
33
+ return {
34
+ depth: 100,
35
+ newGroupDelay: 500
36
+ };
37
+ },
38
+ addCommands() {
39
+ return {
40
+ undo: () => ({ state, dispatch }) => {
41
+ return (0, import_history.undo)(state, dispatch);
42
+ },
43
+ redo: () => ({ state, dispatch }) => {
44
+ return (0, import_history.redo)(state, dispatch);
45
+ }
46
+ };
47
+ },
48
+ addProseMirrorPlugins() {
49
+ return [(0, import_history.history)(this.options)];
50
+ },
51
+ addKeyboardShortcuts() {
52
+ return {
53
+ "Mod-z": () => this.editor.commands.undo(),
54
+ "Shift-Mod-z": () => this.editor.commands.redo(),
55
+ "Mod-y": () => this.editor.commands.redo(),
56
+ // Russian keyboard layouts
57
+ "Mod-\u044F": () => this.editor.commands.undo(),
58
+ "Shift-Mod-\u044F": () => this.editor.commands.redo()
59
+ };
60
+ }
61
+ });
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ UndoRedo
65
+ });
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/undo-redo/index.ts","../../src/undo-redo/undo-redo.ts"],"sourcesContent":["export * from './undo-redo.js'\n","import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAC1B,qBAAoC;AA4C7B,IAAM,WAAW,sBAAU,OAAwB;AAAA,EACxD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,eAAe;AAAA,IACjB;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,MACF,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,KAAC,wBAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":[]}
@@ -0,0 +1,44 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ interface UndoRedoOptions {
4
+ /**
5
+ * The amount of history events that are collected before the oldest events are discarded.
6
+ * @default 100
7
+ * @example 50
8
+ */
9
+ depth: number;
10
+ /**
11
+ * The delay (in milliseconds) between changes after which a new group should be started.
12
+ * @default 500
13
+ * @example 1000
14
+ */
15
+ newGroupDelay: number;
16
+ }
17
+ declare module '@tiptap/core' {
18
+ interface Commands<ReturnType> {
19
+ undoRedo: {
20
+ /**
21
+ * Undo recent changes
22
+ * @example editor.commands.undo()
23
+ */
24
+ undo: () => ReturnType;
25
+ /**
26
+ * Reapply reverted changes
27
+ * @example editor.commands.redo()
28
+ */
29
+ redo: () => ReturnType;
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * This extension allows you to undo and redo recent changes.
35
+ * @see https://www.tiptap.dev/api/extensions/undo-redo
36
+ *
37
+ * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove
38
+ * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.
39
+ *
40
+ * `@tiptap/extension-collaboration` uses its own history implementation.
41
+ */
42
+ declare const UndoRedo: Extension<UndoRedoOptions, any>;
43
+
44
+ export { UndoRedo, type UndoRedoOptions };
@@ -0,0 +1,44 @@
1
+ import { Extension } from '@tiptap/core';
2
+
3
+ interface UndoRedoOptions {
4
+ /**
5
+ * The amount of history events that are collected before the oldest events are discarded.
6
+ * @default 100
7
+ * @example 50
8
+ */
9
+ depth: number;
10
+ /**
11
+ * The delay (in milliseconds) between changes after which a new group should be started.
12
+ * @default 500
13
+ * @example 1000
14
+ */
15
+ newGroupDelay: number;
16
+ }
17
+ declare module '@tiptap/core' {
18
+ interface Commands<ReturnType> {
19
+ undoRedo: {
20
+ /**
21
+ * Undo recent changes
22
+ * @example editor.commands.undo()
23
+ */
24
+ undo: () => ReturnType;
25
+ /**
26
+ * Reapply reverted changes
27
+ * @example editor.commands.redo()
28
+ */
29
+ redo: () => ReturnType;
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * This extension allows you to undo and redo recent changes.
35
+ * @see https://www.tiptap.dev/api/extensions/undo-redo
36
+ *
37
+ * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove
38
+ * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.
39
+ *
40
+ * `@tiptap/extension-collaboration` uses its own history implementation.
41
+ */
42
+ declare const UndoRedo: Extension<UndoRedoOptions, any>;
43
+
44
+ export { UndoRedo, type UndoRedoOptions };
@@ -0,0 +1,39 @@
1
+ // src/undo-redo/undo-redo.ts
2
+ import { Extension } from "@tiptap/core";
3
+ import { history, redo, undo } from "@tiptap/pm/history";
4
+ var UndoRedo = Extension.create({
5
+ name: "undoRedo",
6
+ addOptions() {
7
+ return {
8
+ depth: 100,
9
+ newGroupDelay: 500
10
+ };
11
+ },
12
+ addCommands() {
13
+ return {
14
+ undo: () => ({ state, dispatch }) => {
15
+ return undo(state, dispatch);
16
+ },
17
+ redo: () => ({ state, dispatch }) => {
18
+ return redo(state, dispatch);
19
+ }
20
+ };
21
+ },
22
+ addProseMirrorPlugins() {
23
+ return [history(this.options)];
24
+ },
25
+ addKeyboardShortcuts() {
26
+ return {
27
+ "Mod-z": () => this.editor.commands.undo(),
28
+ "Shift-Mod-z": () => this.editor.commands.redo(),
29
+ "Mod-y": () => this.editor.commands.redo(),
30
+ // Russian keyboard layouts
31
+ "Mod-\u044F": () => this.editor.commands.undo(),
32
+ "Shift-Mod-\u044F": () => this.editor.commands.redo()
33
+ };
34
+ }
35
+ });
36
+ export {
37
+ UndoRedo
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/undo-redo/undo-redo.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,MAAM,YAAY;AA4C7B,IAAM,WAAW,UAAU,OAAwB;AAAA,EACxD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,eAAe;AAAA,IACjB;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,eAAO,KAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,MACF,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,eAAO,KAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":[]}