@tiptap/vue-3 3.0.0-next.0 → 3.0.0-next.2

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 (190) hide show
  1. package/dist/index.cjs +589 -477
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +303 -0
  4. package/dist/index.d.ts +303 -0
  5. package/dist/index.js +591 -464
  6. package/dist/index.js.map +1 -1
  7. package/package.json +10 -12
  8. package/src/Editor.ts +17 -6
  9. package/src/EditorContent.ts +0 -19
  10. package/src/VueNodeViewRenderer.ts +90 -26
  11. package/src/useEditor.ts +6 -0
  12. package/dist/index.umd.js +0 -521
  13. package/dist/index.umd.js.map +0 -1
  14. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  15. package/dist/packages/core/src/Editor.d.ts +0 -159
  16. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  17. package/dist/packages/core/src/Extension.d.ts +0 -343
  18. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  19. package/dist/packages/core/src/InputRule.d.ts +0 -42
  20. package/dist/packages/core/src/Mark.d.ts +0 -451
  21. package/dist/packages/core/src/Node.d.ts +0 -611
  22. package/dist/packages/core/src/NodePos.d.ts +0 -44
  23. package/dist/packages/core/src/NodeView.d.ts +0 -31
  24. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  25. package/dist/packages/core/src/Tracker.d.ts +0 -11
  26. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  27. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  28. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  29. package/dist/packages/core/src/commands/command.d.ts +0 -18
  30. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  31. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  32. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  33. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  34. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  35. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  36. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  37. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  38. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  39. package/dist/packages/core/src/commands/first.d.ts +0 -14
  40. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  41. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  42. package/dist/packages/core/src/commands/index.d.ts +0 -55
  43. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  44. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  45. package/dist/packages/core/src/commands/join.d.ts +0 -41
  46. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  47. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  48. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  49. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  50. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  51. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  52. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  53. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  54. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  55. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  56. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  57. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  58. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  59. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  60. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  61. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  62. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  63. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  64. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  65. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  66. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  67. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  68. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  69. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  70. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  71. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  72. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  73. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  74. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  75. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  76. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  77. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  78. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  79. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  80. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  81. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  82. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  83. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  84. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  85. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  86. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  87. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  88. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  89. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  90. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  91. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  92. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  93. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  94. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  95. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  96. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  97. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  98. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  99. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  100. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  101. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  102. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  103. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  104. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  105. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  106. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  107. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  108. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  109. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  110. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  111. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  112. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  113. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  114. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  115. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  116. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  117. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  118. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  120. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  121. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  122. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  123. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  124. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  125. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  126. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  129. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  130. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  131. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  132. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  133. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  134. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  136. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  138. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  139. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  140. package/dist/packages/core/src/index.d.ts +0 -24
  141. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  142. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  143. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  144. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  145. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  146. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  147. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  148. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  149. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  150. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  151. package/dist/packages/core/src/style.d.ts +0 -1
  152. package/dist/packages/core/src/types.d.ts +0 -253
  153. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  154. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  155. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  156. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  157. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  158. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  159. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  160. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  161. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  162. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  164. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  174. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  175. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -99
  176. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
  177. package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
  178. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -81
  179. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
  180. package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
  181. package/dist/packages/vue-3/src/BubbleMenu.d.ts +0 -79
  182. package/dist/packages/vue-3/src/Editor.d.ts +0 -23
  183. package/dist/packages/vue-3/src/EditorContent.d.ts +0 -17
  184. package/dist/packages/vue-3/src/FloatingMenu.d.ts +0 -62
  185. package/dist/packages/vue-3/src/NodeViewContent.d.ts +0 -13
  186. package/dist/packages/vue-3/src/NodeViewWrapper.d.ts +0 -13
  187. package/dist/packages/vue-3/src/VueNodeViewRenderer.d.ts +0 -48
  188. package/dist/packages/vue-3/src/VueRenderer.d.ts +0 -36
  189. package/dist/packages/vue-3/src/index.d.ts +0 -10
  190. package/dist/packages/vue-3/src/useEditor.d.ts +0 -3
package/dist/index.cjs CHANGED
@@ -1,520 +1,632 @@
1
- 'use strict';
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
20
 
3
- var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
4
- var vue = require('vue');
5
- var core = require('@tiptap/core');
6
- var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ BubbleMenu: () => BubbleMenu,
25
+ Editor: () => Editor,
26
+ EditorContent: () => EditorContent,
27
+ FloatingMenu: () => FloatingMenu,
28
+ NodeViewContent: () => NodeViewContent,
29
+ NodeViewWrapper: () => NodeViewWrapper,
30
+ VueNodeViewRenderer: () => VueNodeViewRenderer,
31
+ VueRenderer: () => VueRenderer,
32
+ nodeViewProps: () => nodeViewProps,
33
+ useEditor: () => useEditor
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
7
36
 
8
- const BubbleMenu = vue.defineComponent({
9
- name: 'BubbleMenu',
10
- props: {
11
- pluginKey: {
12
- type: [String, Object],
13
- default: 'bubbleMenu',
14
- },
15
- editor: {
16
- type: Object,
17
- required: true,
18
- },
19
- updateDelay: {
20
- type: Number,
21
- default: undefined,
22
- },
23
- resizeDelay: {
24
- type: Number,
25
- default: undefined,
26
- },
27
- options: {
28
- type: Object,
29
- default: () => ({}),
30
- },
31
- shouldShow: {
32
- type: Function,
33
- default: null,
34
- },
37
+ // src/BubbleMenu.ts
38
+ var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
39
+ var import_vue = require("vue");
40
+ var BubbleMenu = (0, import_vue.defineComponent)({
41
+ name: "BubbleMenu",
42
+ props: {
43
+ pluginKey: {
44
+ type: [String, Object],
45
+ default: "bubbleMenu"
35
46
  },
36
- setup(props, { slots }) {
37
- const root = vue.ref(null);
38
- vue.onMounted(() => {
39
- const { editor, options, pluginKey, resizeDelay, shouldShow, updateDelay, } = props;
40
- if (!root.value) {
41
- return;
42
- }
43
- root.value.style.visibility = 'hidden';
44
- root.value.style.position = 'absolute';
45
- // remove the element from the DOM
46
- root.value.remove();
47
- editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
48
- editor,
49
- element: root.value,
50
- options,
51
- pluginKey,
52
- resizeDelay,
53
- shouldShow,
54
- updateDelay,
55
- }));
56
- });
57
- vue.onBeforeUnmount(() => {
58
- const { pluginKey, editor } = props;
59
- editor.unregisterPlugin(pluginKey);
60
- });
61
- return () => { var _a; return vue.h(vue.Teleport, { to: 'body' }, vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots))); };
47
+ editor: {
48
+ type: Object,
49
+ required: true
50
+ },
51
+ updateDelay: {
52
+ type: Number,
53
+ default: void 0
54
+ },
55
+ resizeDelay: {
56
+ type: Number,
57
+ default: void 0
62
58
  },
59
+ options: {
60
+ type: Object,
61
+ default: () => ({})
62
+ },
63
+ shouldShow: {
64
+ type: Function,
65
+ default: null
66
+ }
67
+ },
68
+ setup(props, { slots }) {
69
+ const root = (0, import_vue.ref)(null);
70
+ (0, import_vue.onMounted)(() => {
71
+ const {
72
+ editor,
73
+ options,
74
+ pluginKey,
75
+ resizeDelay,
76
+ shouldShow,
77
+ updateDelay
78
+ } = props;
79
+ if (!root.value) {
80
+ return;
81
+ }
82
+ root.value.style.visibility = "hidden";
83
+ root.value.style.position = "absolute";
84
+ root.value.remove();
85
+ editor.registerPlugin((0, import_extension_bubble_menu.BubbleMenuPlugin)({
86
+ editor,
87
+ element: root.value,
88
+ options,
89
+ pluginKey,
90
+ resizeDelay,
91
+ shouldShow,
92
+ updateDelay
93
+ }));
94
+ });
95
+ (0, import_vue.onBeforeUnmount)(() => {
96
+ const { pluginKey, editor } = props;
97
+ editor.unregisterPlugin(pluginKey);
98
+ });
99
+ return () => {
100
+ var _a;
101
+ return (0, import_vue.h)(import_vue.Teleport, { to: "body" }, (0, import_vue.h)("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
102
+ };
103
+ }
63
104
  });
64
105
 
106
+ // src/Editor.ts
107
+ var import_core = require("@tiptap/core");
108
+ var import_vue2 = require("vue");
65
109
  function useDebouncedRef(value) {
66
- return vue.customRef((track, trigger) => {
67
- return {
68
- get() {
69
- track();
70
- return value;
71
- },
72
- set(newValue) {
73
- // update state
74
- value = newValue;
75
- // update view as soon as possible
76
- requestAnimationFrame(() => {
77
- requestAnimationFrame(() => {
78
- trigger();
79
- });
80
- });
81
- },
82
- };
83
- });
84
- }
85
- class Editor extends core.Editor {
86
- constructor(options = {}) {
87
- super(options);
88
- this.contentComponent = null;
89
- this.appContext = null;
90
- this.reactiveState = useDebouncedRef(this.view.state);
91
- this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
92
- this.on('beforeTransaction', ({ nextState }) => {
93
- this.reactiveState.value = nextState;
94
- this.reactiveExtensionStorage.value = this.extensionStorage;
110
+ return (0, import_vue2.customRef)((track, trigger) => {
111
+ return {
112
+ get() {
113
+ track();
114
+ return value;
115
+ },
116
+ set(newValue) {
117
+ value = newValue;
118
+ requestAnimationFrame(() => {
119
+ requestAnimationFrame(() => {
120
+ trigger();
121
+ });
95
122
  });
96
- return vue.markRaw(this); // eslint-disable-line
97
- }
98
- get state() {
99
- return this.reactiveState ? this.reactiveState.value : this.view.state;
100
- }
101
- get storage() {
102
- return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
103
- }
104
- /**
105
- * Register a ProseMirror plugin.
106
- */
107
- registerPlugin(plugin, handlePlugins) {
108
- super.registerPlugin(plugin, handlePlugins);
109
- this.reactiveState.value = this.view.state;
123
+ }
124
+ };
125
+ });
126
+ }
127
+ var Editor = class extends import_core.Editor {
128
+ constructor(options = {}) {
129
+ super(options);
130
+ this.contentComponent = null;
131
+ this.appContext = null;
132
+ this.reactiveState = useDebouncedRef(this.view.state);
133
+ this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
134
+ this.on("beforeTransaction", ({ nextState }) => {
135
+ this.reactiveState.value = nextState;
136
+ this.reactiveExtensionStorage.value = this.extensionStorage;
137
+ });
138
+ return (0, import_vue2.markRaw)(this);
139
+ }
140
+ get state() {
141
+ return this.reactiveState ? this.reactiveState.value : this.view.state;
142
+ }
143
+ get storage() {
144
+ return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
145
+ }
146
+ /**
147
+ * Register a ProseMirror plugin.
148
+ */
149
+ registerPlugin(plugin, handlePlugins) {
150
+ const nextState = super.registerPlugin(plugin, handlePlugins);
151
+ if (this.reactiveState) {
152
+ this.reactiveState.value = nextState;
110
153
  }
111
- /**
112
- * Unregister a ProseMirror plugin.
113
- */
114
- unregisterPlugin(nameOrPluginKey) {
115
- super.unregisterPlugin(nameOrPluginKey);
116
- this.reactiveState.value = this.view.state;
154
+ return nextState;
155
+ }
156
+ /**
157
+ * Unregister a ProseMirror plugin.
158
+ */
159
+ unregisterPlugin(nameOrPluginKey) {
160
+ const nextState = super.unregisterPlugin(nameOrPluginKey);
161
+ if (this.reactiveState && nextState) {
162
+ this.reactiveState.value = nextState;
117
163
  }
118
- }
164
+ return nextState;
165
+ }
166
+ };
119
167
 
120
- const EditorContent = vue.defineComponent({
121
- name: 'EditorContent',
122
- props: {
123
- editor: {
124
- default: null,
125
- type: Object,
126
- },
127
- },
128
- setup(props) {
129
- const rootEl = vue.ref();
130
- const instance = vue.getCurrentInstance();
131
- vue.watchEffect(() => {
132
- const editor = props.editor;
133
- if (editor && editor.options.element && rootEl.value) {
134
- vue.nextTick(() => {
135
- if (!rootEl.value || !editor.options.element.firstChild) {
136
- return;
137
- }
138
- const element = vue.unref(rootEl.value);
139
- rootEl.value.append(...editor.options.element.childNodes);
140
- // @ts-ignore
141
- editor.contentComponent = instance.ctx._;
142
- if (instance) {
143
- editor.appContext = {
144
- ...instance.appContext,
145
- // Vue internally uses prototype chain to forward/shadow injects across the entire component chain
146
- // so don't use object spread operator or 'Object.assign' and just set `provides` as is on editor's appContext
147
- // @ts-expect-error forward instance's 'provides' into appContext
148
- provides: instance.provides,
149
- };
150
- }
151
- editor.setOptions({
152
- element,
153
- });
154
- editor.createNodeViews();
155
- });
156
- }
157
- });
158
- vue.onBeforeUnmount(() => {
159
- const editor = props.editor;
160
- if (!editor) {
161
- return;
162
- }
163
- // destroy nodeviews before vue removes dom element
164
- if (!editor.isDestroyed) {
165
- editor.view.setProps({
166
- nodeViews: {},
167
- });
168
- }
169
- editor.contentComponent = null;
170
- editor.appContext = null;
171
- if (!editor.options.element.firstChild) {
172
- return;
173
- }
174
- const newElement = document.createElement('div');
175
- newElement.append(...editor.options.element.childNodes);
176
- editor.setOptions({
177
- element: newElement,
178
- });
179
- });
180
- return { rootEl };
181
- },
182
- render() {
183
- return vue.h('div', {
184
- ref: (el) => { this.rootEl = el; },
168
+ // src/EditorContent.ts
169
+ var import_vue3 = require("vue");
170
+ var EditorContent = (0, import_vue3.defineComponent)({
171
+ name: "EditorContent",
172
+ props: {
173
+ editor: {
174
+ default: null,
175
+ type: Object
176
+ }
177
+ },
178
+ setup(props) {
179
+ const rootEl = (0, import_vue3.ref)();
180
+ const instance = (0, import_vue3.getCurrentInstance)();
181
+ (0, import_vue3.watchEffect)(() => {
182
+ const editor = props.editor;
183
+ if (editor && editor.options.element && rootEl.value) {
184
+ (0, import_vue3.nextTick)(() => {
185
+ if (!rootEl.value || !editor.options.element.firstChild) {
186
+ return;
187
+ }
188
+ const element = (0, import_vue3.unref)(rootEl.value);
189
+ rootEl.value.append(...editor.options.element.childNodes);
190
+ editor.contentComponent = instance.ctx._;
191
+ if (instance) {
192
+ editor.appContext = {
193
+ ...instance.appContext,
194
+ // Vue internally uses prototype chain to forward/shadow injects across the entire component chain
195
+ // so don't use object spread operator or 'Object.assign' and just set `provides` as is on editor's appContext
196
+ // @ts-expect-error forward instance's 'provides' into appContext
197
+ provides: instance.provides
198
+ };
199
+ }
200
+ editor.setOptions({
201
+ element
202
+ });
203
+ editor.createNodeViews();
185
204
  });
186
- },
205
+ }
206
+ });
207
+ (0, import_vue3.onBeforeUnmount)(() => {
208
+ const editor = props.editor;
209
+ if (!editor) {
210
+ return;
211
+ }
212
+ editor.contentComponent = null;
213
+ editor.appContext = null;
214
+ });
215
+ return { rootEl };
216
+ },
217
+ render() {
218
+ return (0, import_vue3.h)(
219
+ "div",
220
+ {
221
+ ref: (el) => {
222
+ this.rootEl = el;
223
+ }
224
+ }
225
+ );
226
+ }
187
227
  });
188
228
 
189
- const FloatingMenu = vue.defineComponent({
190
- name: 'FloatingMenu',
191
- props: {
192
- pluginKey: {
193
- // TODO: TypeScript breaks :(
194
- // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
195
- type: null,
196
- default: 'floatingMenu',
197
- },
198
- editor: {
199
- type: Object,
200
- required: true,
201
- },
202
- options: {
203
- type: Object,
204
- default: () => ({}),
205
- },
206
- shouldShow: {
207
- type: Function,
208
- default: null,
209
- },
229
+ // src/FloatingMenu.ts
230
+ var import_extension_floating_menu = require("@tiptap/extension-floating-menu");
231
+ var import_vue4 = require("vue");
232
+ var FloatingMenu = (0, import_vue4.defineComponent)({
233
+ name: "FloatingMenu",
234
+ props: {
235
+ pluginKey: {
236
+ // TODO: TypeScript breaks :(
237
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
238
+ type: null,
239
+ default: "floatingMenu"
210
240
  },
211
- setup(props, { slots }) {
212
- const root = vue.ref(null);
213
- vue.onMounted(() => {
214
- const { pluginKey, editor, options, shouldShow, } = props;
215
- if (!root.value) {
216
- return;
217
- }
218
- root.value.style.visibility = 'hidden';
219
- root.value.style.position = 'absolute';
220
- // remove the element from the DOM
221
- root.value.remove();
222
- editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
223
- pluginKey,
224
- editor,
225
- element: root.value,
226
- options,
227
- shouldShow,
228
- }));
229
- });
230
- vue.onBeforeUnmount(() => {
231
- const { pluginKey, editor } = props;
232
- editor.unregisterPlugin(pluginKey);
233
- });
234
- return () => { var _a; return vue.h(vue.Teleport, { to: 'body' }, vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots))); };
241
+ editor: {
242
+ type: Object,
243
+ required: true
244
+ },
245
+ options: {
246
+ type: Object,
247
+ default: () => ({})
235
248
  },
249
+ shouldShow: {
250
+ type: Function,
251
+ default: null
252
+ }
253
+ },
254
+ setup(props, { slots }) {
255
+ const root = (0, import_vue4.ref)(null);
256
+ (0, import_vue4.onMounted)(() => {
257
+ const {
258
+ pluginKey,
259
+ editor,
260
+ options,
261
+ shouldShow
262
+ } = props;
263
+ if (!root.value) {
264
+ return;
265
+ }
266
+ root.value.style.visibility = "hidden";
267
+ root.value.style.position = "absolute";
268
+ root.value.remove();
269
+ editor.registerPlugin((0, import_extension_floating_menu.FloatingMenuPlugin)({
270
+ pluginKey,
271
+ editor,
272
+ element: root.value,
273
+ options,
274
+ shouldShow
275
+ }));
276
+ });
277
+ (0, import_vue4.onBeforeUnmount)(() => {
278
+ const { pluginKey, editor } = props;
279
+ editor.unregisterPlugin(pluginKey);
280
+ });
281
+ return () => {
282
+ var _a;
283
+ return (0, import_vue4.h)(import_vue4.Teleport, { to: "body" }, (0, import_vue4.h)("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
284
+ };
285
+ }
236
286
  });
237
287
 
238
- const NodeViewContent = vue.defineComponent({
239
- name: 'NodeViewContent',
240
- props: {
241
- as: {
242
- type: String,
243
- default: 'div',
244
- },
245
- },
246
- render() {
247
- return vue.h(this.as, {
248
- style: {
249
- whiteSpace: 'pre-wrap',
250
- },
251
- 'data-node-view-content': '',
252
- });
253
- },
288
+ // src/NodeViewContent.ts
289
+ var import_vue5 = require("vue");
290
+ var NodeViewContent = (0, import_vue5.defineComponent)({
291
+ name: "NodeViewContent",
292
+ props: {
293
+ as: {
294
+ type: String,
295
+ default: "div"
296
+ }
297
+ },
298
+ render() {
299
+ return (0, import_vue5.h)(this.as, {
300
+ style: {
301
+ whiteSpace: "pre-wrap"
302
+ },
303
+ "data-node-view-content": ""
304
+ });
305
+ }
254
306
  });
255
307
 
256
- const NodeViewWrapper = vue.defineComponent({
257
- name: 'NodeViewWrapper',
258
- props: {
259
- as: {
260
- type: String,
261
- default: 'div',
308
+ // src/NodeViewWrapper.ts
309
+ var import_vue6 = require("vue");
310
+ var NodeViewWrapper = (0, import_vue6.defineComponent)({
311
+ name: "NodeViewWrapper",
312
+ props: {
313
+ as: {
314
+ type: String,
315
+ default: "div"
316
+ }
317
+ },
318
+ inject: ["onDragStart", "decorationClasses"],
319
+ render() {
320
+ var _a, _b;
321
+ return (0, import_vue6.h)(
322
+ this.as,
323
+ {
324
+ // @ts-ignore
325
+ class: this.decorationClasses,
326
+ style: {
327
+ whiteSpace: "normal"
262
328
  },
263
- },
264
- inject: ['onDragStart', 'decorationClasses'],
265
- render() {
266
- var _a, _b;
267
- return vue.h(this.as, {
268
- // @ts-ignore
269
- class: this.decorationClasses,
270
- style: {
271
- whiteSpace: 'normal',
272
- },
273
- 'data-node-view-wrapper': '',
274
- // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
275
- onDragstart: this.onDragStart,
276
- }, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
277
- },
329
+ "data-node-view-wrapper": "",
330
+ // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
331
+ onDragstart: this.onDragStart
332
+ },
333
+ (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)
334
+ );
335
+ }
278
336
  });
279
337
 
280
- const useEditor = (options = {}) => {
281
- const editor = vue.shallowRef();
282
- vue.onMounted(() => {
283
- editor.value = new Editor(options);
284
- });
285
- vue.onBeforeUnmount(() => {
286
- var _a;
287
- (_a = editor.value) === null || _a === void 0 ? void 0 : _a.destroy();
288
- });
289
- return editor;
338
+ // src/useEditor.ts
339
+ var import_vue7 = require("vue");
340
+ var useEditor = (options = {}) => {
341
+ const editor = (0, import_vue7.shallowRef)();
342
+ (0, import_vue7.onMounted)(() => {
343
+ editor.value = new Editor(options);
344
+ });
345
+ (0, import_vue7.onBeforeUnmount)(() => {
346
+ var _a, _b, _c;
347
+ const nodes = (_a = editor.value) == null ? void 0 : _a.options.element;
348
+ const newEl = nodes == null ? void 0 : nodes.cloneNode(true);
349
+ (_b = nodes == null ? void 0 : nodes.parentNode) == null ? void 0 : _b.replaceChild(newEl, nodes);
350
+ (_c = editor.value) == null ? void 0 : _c.destroy();
351
+ });
352
+ return editor;
290
353
  };
291
354
 
292
- /**
293
- * This class is used to render Vue components inside the editor.
294
- */
295
- class VueRenderer {
296
- constructor(component, { props = {}, editor }) {
297
- this.editor = editor;
298
- this.component = vue.markRaw(component);
299
- this.el = document.createElement('div');
300
- this.props = vue.reactive(props);
301
- this.renderedComponent = this.renderComponent();
302
- }
303
- get element() {
304
- return this.renderedComponent.el;
305
- }
306
- get ref() {
307
- var _a, _b, _c, _d;
308
- // Composition API
309
- if ((_b = (_a = this.renderedComponent.vNode) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.exposed) {
310
- return this.renderedComponent.vNode.component.exposed;
311
- }
312
- // Option API
313
- return (_d = (_c = this.renderedComponent.vNode) === null || _c === void 0 ? void 0 : _c.component) === null || _d === void 0 ? void 0 : _d.proxy;
355
+ // src/VueNodeViewRenderer.ts
356
+ var import_core2 = require("@tiptap/core");
357
+ var import_vue9 = require("vue");
358
+
359
+ // src/VueRenderer.ts
360
+ var import_vue8 = require("vue");
361
+ var VueRenderer = class {
362
+ constructor(component, { props = {}, editor }) {
363
+ this.editor = editor;
364
+ this.component = (0, import_vue8.markRaw)(component);
365
+ this.el = document.createElement("div");
366
+ this.props = (0, import_vue8.reactive)(props);
367
+ this.renderedComponent = this.renderComponent();
368
+ }
369
+ get element() {
370
+ return this.renderedComponent.el;
371
+ }
372
+ get ref() {
373
+ var _a, _b, _c, _d;
374
+ if ((_b = (_a = this.renderedComponent.vNode) == null ? void 0 : _a.component) == null ? void 0 : _b.exposed) {
375
+ return this.renderedComponent.vNode.component.exposed;
314
376
  }
315
- renderComponent() {
316
- let vNode = vue.h(this.component, this.props);
317
- if (this.editor.appContext) {
318
- vNode.appContext = this.editor.appContext;
319
- }
320
- if (typeof document !== 'undefined' && this.el) {
321
- vue.render(vNode, this.el);
322
- }
323
- const destroy = () => {
324
- if (this.el) {
325
- vue.render(null, this.el);
326
- }
327
- this.el = null;
328
- vNode = null;
329
- };
330
- return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };
377
+ return (_d = (_c = this.renderedComponent.vNode) == null ? void 0 : _c.component) == null ? void 0 : _d.proxy;
378
+ }
379
+ renderComponent() {
380
+ let vNode = (0, import_vue8.h)(this.component, this.props);
381
+ if (this.editor.appContext) {
382
+ vNode.appContext = this.editor.appContext;
331
383
  }
332
- updateProps(props = {}) {
333
- Object.entries(props).forEach(([key, value]) => {
334
- this.props[key] = value;
335
- });
336
- this.renderComponent();
384
+ if (typeof document !== "undefined" && this.el) {
385
+ (0, import_vue8.render)(vNode, this.el);
337
386
  }
338
- destroy() {
339
- this.renderedComponent.destroy();
340
- }
341
- }
387
+ const destroy = () => {
388
+ if (this.el) {
389
+ (0, import_vue8.render)(null, this.el);
390
+ }
391
+ this.el = null;
392
+ vNode = null;
393
+ };
394
+ return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };
395
+ }
396
+ updateProps(props = {}) {
397
+ Object.entries(props).forEach(([key, value]) => {
398
+ this.props[key] = value;
399
+ });
400
+ this.renderComponent();
401
+ }
402
+ destroy() {
403
+ this.renderedComponent.destroy();
404
+ }
405
+ };
342
406
 
343
- const nodeViewProps = {
344
- editor: {
345
- type: Object,
346
- required: true,
347
- },
348
- node: {
349
- type: Object,
350
- required: true,
351
- },
352
- decorations: {
353
- type: Object,
354
- required: true,
355
- },
356
- selected: {
357
- type: Boolean,
358
- required: true,
359
- },
360
- extension: {
361
- type: Object,
362
- required: true,
363
- },
364
- getPos: {
365
- type: Function,
366
- required: true,
367
- },
368
- updateAttributes: {
369
- type: Function,
370
- required: true,
371
- },
372
- deleteNode: {
373
- type: Function,
374
- required: true,
375
- },
407
+ // src/VueNodeViewRenderer.ts
408
+ var nodeViewProps = {
409
+ editor: {
410
+ type: Object,
411
+ required: true
412
+ },
413
+ node: {
414
+ type: Object,
415
+ required: true
416
+ },
417
+ decorations: {
418
+ type: Object,
419
+ required: true
420
+ },
421
+ selected: {
422
+ type: Boolean,
423
+ required: true
424
+ },
425
+ extension: {
426
+ type: Object,
427
+ required: true
428
+ },
429
+ getPos: {
430
+ type: Function,
431
+ required: true
432
+ },
433
+ updateAttributes: {
434
+ type: Function,
435
+ required: true
436
+ },
437
+ deleteNode: {
438
+ type: Function,
439
+ required: true
440
+ }
376
441
  };
377
- class VueNodeView extends core.NodeView {
378
- mount() {
379
- const props = {
380
- editor: this.editor,
381
- node: this.node,
382
- decorations: this.decorations,
383
- selected: false,
384
- extension: this.extension,
385
- getPos: () => this.getPos(),
386
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
387
- deleteNode: () => this.deleteNode(),
388
- };
389
- const onDragStart = this.onDragStart.bind(this);
390
- this.decorationClasses = vue.ref(this.getDecorationClasses());
391
- const extendedComponent = vue.defineComponent({
392
- extends: { ...this.component },
393
- props: Object.keys(props),
394
- template: this.component.template,
395
- setup: reactiveProps => {
396
- var _a, _b;
397
- vue.provide('onDragStart', onDragStart);
398
- vue.provide('decorationClasses', this.decorationClasses);
399
- return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {
400
- expose: () => undefined,
401
- });
402
- },
403
- // add support for scoped styles
404
- // @ts-ignore
405
- // eslint-disable-next-line
406
- __scopeId: this.component.__scopeId,
407
- // add support for CSS Modules
408
- // @ts-ignore
409
- // eslint-disable-next-line
410
- __cssModules: this.component.__cssModules,
411
- // add support for vue devtools
412
- // @ts-ignore
413
- // eslint-disable-next-line
414
- __name: this.component.__name,
415
- // @ts-ignore
416
- // eslint-disable-next-line
417
- __file: this.component.__file,
418
- });
419
- this.renderer = new VueRenderer(extendedComponent, {
420
- editor: this.editor,
421
- props,
442
+ var VueNodeView = class extends import_core2.NodeView {
443
+ mount() {
444
+ const props = {
445
+ editor: this.editor,
446
+ node: this.node,
447
+ decorations: this.decorations,
448
+ innerDecorations: this.innerDecorations,
449
+ view: this.view,
450
+ selected: false,
451
+ extension: this.extension,
452
+ HTMLAttributes: this.HTMLAttributes,
453
+ getPos: () => this.getPos(),
454
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
455
+ deleteNode: () => this.deleteNode()
456
+ };
457
+ const onDragStart = this.onDragStart.bind(this);
458
+ this.decorationClasses = (0, import_vue9.ref)(this.getDecorationClasses());
459
+ const extendedComponent = (0, import_vue9.defineComponent)({
460
+ extends: { ...this.component },
461
+ props: Object.keys(props),
462
+ template: this.component.template,
463
+ setup: (reactiveProps) => {
464
+ var _a, _b;
465
+ (0, import_vue9.provide)("onDragStart", onDragStart);
466
+ (0, import_vue9.provide)("decorationClasses", this.decorationClasses);
467
+ return (_b = (_a = this.component).setup) == null ? void 0 : _b.call(_a, reactiveProps, {
468
+ expose: () => void 0
422
469
  });
470
+ },
471
+ // add support for scoped styles
472
+ // @ts-ignore
473
+ // eslint-disable-next-line
474
+ __scopeId: this.component.__scopeId,
475
+ // add support for CSS Modules
476
+ // @ts-ignore
477
+ // eslint-disable-next-line
478
+ __cssModules: this.component.__cssModules,
479
+ // add support for vue devtools
480
+ // @ts-ignore
481
+ // eslint-disable-next-line
482
+ __name: this.component.__name,
483
+ // @ts-ignore
484
+ // eslint-disable-next-line
485
+ __file: this.component.__file
486
+ });
487
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
488
+ this.editor.on("selectionUpdate", this.handleSelectionUpdate);
489
+ this.renderer = new VueRenderer(extendedComponent, {
490
+ editor: this.editor,
491
+ props
492
+ });
493
+ }
494
+ /**
495
+ * Return the DOM element.
496
+ * This is the element that will be used to display the node view.
497
+ */
498
+ get dom() {
499
+ if (!this.renderer.element || !this.renderer.element.hasAttribute("data-node-view-wrapper")) {
500
+ throw Error("Please use the NodeViewWrapper component for your node view.");
423
501
  }
424
- get dom() {
425
- if (!this.renderer.element || !this.renderer.element.hasAttribute('data-node-view-wrapper')) {
426
- throw Error('Please use the NodeViewWrapper component for your node view.');
427
- }
428
- return this.renderer.element;
502
+ return this.renderer.element;
503
+ }
504
+ /**
505
+ * Return the content DOM element.
506
+ * This is the element that will be used to display the rich-text content of the node.
507
+ */
508
+ get contentDOM() {
509
+ if (this.node.isLeaf) {
510
+ return null;
429
511
  }
430
- get contentDOM() {
431
- if (this.node.isLeaf) {
432
- return null;
433
- }
434
- return this.dom.querySelector('[data-node-view-content]');
512
+ return this.dom.querySelector("[data-node-view-content]");
513
+ }
514
+ /**
515
+ * On editor selection update, check if the node is selected.
516
+ * If it is, call `selectNode`, otherwise call `deselectNode`.
517
+ */
518
+ handleSelectionUpdate() {
519
+ const { from, to } = this.editor.state.selection;
520
+ const pos = this.getPos();
521
+ if (typeof pos !== "number") {
522
+ return;
435
523
  }
436
- update(node, decorations) {
437
- const updateProps = (props) => {
438
- this.decorationClasses.value = this.getDecorationClasses();
439
- this.renderer.updateProps(props);
440
- };
441
- if (typeof this.options.update === 'function') {
442
- const oldNode = this.node;
443
- const oldDecorations = this.decorations;
444
- this.node = node;
445
- this.decorations = decorations;
446
- return this.options.update({
447
- oldNode,
448
- oldDecorations,
449
- newNode: node,
450
- newDecorations: decorations,
451
- updateProps: () => updateProps({ node, decorations }),
452
- });
453
- }
454
- if (node.type !== this.node.type) {
455
- return false;
456
- }
457
- if (node === this.node && this.decorations === decorations) {
458
- return true;
459
- }
460
- this.node = node;
461
- this.decorations = decorations;
462
- updateProps({ node, decorations });
463
- return true;
524
+ if (from <= pos && to >= pos + this.node.nodeSize) {
525
+ if (this.renderer.props.selected) {
526
+ return;
527
+ }
528
+ this.selectNode();
529
+ } else {
530
+ if (!this.renderer.props.selected) {
531
+ return;
532
+ }
533
+ this.deselectNode();
464
534
  }
465
- selectNode() {
466
- this.renderer.updateProps({
467
- selected: true,
468
- });
469
- if (this.renderer.element) {
470
- this.renderer.element.classList.add('ProseMirror-selectednode');
471
- }
535
+ }
536
+ /**
537
+ * On update, update the React component.
538
+ * To prevent unnecessary updates, the `update` option can be used.
539
+ */
540
+ update(node, decorations, innerDecorations) {
541
+ const rerenderComponent = (props) => {
542
+ this.decorationClasses.value = this.getDecorationClasses();
543
+ this.renderer.updateProps(props);
544
+ };
545
+ if (typeof this.options.update === "function") {
546
+ const oldNode = this.node;
547
+ const oldDecorations = this.decorations;
548
+ const oldInnerDecorations = this.innerDecorations;
549
+ this.node = node;
550
+ this.decorations = decorations;
551
+ this.innerDecorations = innerDecorations;
552
+ return this.options.update({
553
+ oldNode,
554
+ oldDecorations,
555
+ newNode: node,
556
+ newDecorations: decorations,
557
+ oldInnerDecorations,
558
+ innerDecorations,
559
+ updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
560
+ });
472
561
  }
473
- deselectNode() {
474
- this.renderer.updateProps({
475
- selected: false,
476
- });
477
- if (this.renderer.element) {
478
- this.renderer.element.classList.remove('ProseMirror-selectednode');
479
- }
562
+ if (node.type !== this.node.type) {
563
+ return false;
480
564
  }
481
- getDecorationClasses() {
482
- return (this.decorations
483
- // @ts-ignore
484
- .map(item => item.type.attrs.class)
485
- .flat()
486
- .join(' '));
565
+ if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
566
+ return true;
487
567
  }
488
- destroy() {
489
- this.renderer.destroy();
568
+ this.node = node;
569
+ this.decorations = decorations;
570
+ this.innerDecorations = innerDecorations;
571
+ rerenderComponent({ node, decorations, innerDecorations });
572
+ return true;
573
+ }
574
+ /**
575
+ * Select the node.
576
+ * Add the `selected` prop and the `ProseMirror-selectednode` class.
577
+ */
578
+ selectNode() {
579
+ this.renderer.updateProps({
580
+ selected: true
581
+ });
582
+ if (this.renderer.element) {
583
+ this.renderer.element.classList.add("ProseMirror-selectednode");
490
584
  }
491
- }
585
+ }
586
+ /**
587
+ * Deselect the node.
588
+ * Remove the `selected` prop and the `ProseMirror-selectednode` class.
589
+ */
590
+ deselectNode() {
591
+ this.renderer.updateProps({
592
+ selected: false
593
+ });
594
+ if (this.renderer.element) {
595
+ this.renderer.element.classList.remove("ProseMirror-selectednode");
596
+ }
597
+ }
598
+ getDecorationClasses() {
599
+ return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
600
+ }
601
+ destroy() {
602
+ this.renderer.destroy();
603
+ this.editor.off("selectionUpdate", this.handleSelectionUpdate);
604
+ }
605
+ };
492
606
  function VueNodeViewRenderer(component, options) {
493
- return (props) => {
494
- // try to get the parent component
495
- // this is important for vue devtools to show the component hierarchy correctly
496
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
497
- if (!props.editor.contentComponent) {
498
- return {};
499
- }
500
- return new VueNodeView(component, props, options);
501
- };
607
+ return (props) => {
608
+ if (!props.editor.contentComponent) {
609
+ return {};
610
+ }
611
+ const normalizedComponent = typeof component === "function" && "__vccOpts" in component ? component.__vccOpts : component;
612
+ return new VueNodeView(normalizedComponent, props, options);
613
+ };
502
614
  }
503
615
 
504
- exports.BubbleMenu = BubbleMenu;
505
- exports.Editor = Editor;
506
- exports.EditorContent = EditorContent;
507
- exports.FloatingMenu = FloatingMenu;
508
- exports.NodeViewContent = NodeViewContent;
509
- exports.NodeViewWrapper = NodeViewWrapper;
510
- exports.VueNodeViewRenderer = VueNodeViewRenderer;
511
- exports.VueRenderer = VueRenderer;
512
- exports.nodeViewProps = nodeViewProps;
513
- exports.useEditor = useEditor;
514
- Object.keys(core).forEach(function (k) {
515
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
516
- enumerable: true,
517
- get: function () { return core[k]; }
518
- });
616
+ // src/index.ts
617
+ __reExport(src_exports, require("@tiptap/core"), module.exports);
618
+ // Annotate the CommonJS export names for ESM import in node:
619
+ 0 && (module.exports = {
620
+ BubbleMenu,
621
+ Editor,
622
+ EditorContent,
623
+ FloatingMenu,
624
+ NodeViewContent,
625
+ NodeViewWrapper,
626
+ VueNodeViewRenderer,
627
+ VueRenderer,
628
+ nodeViewProps,
629
+ useEditor,
630
+ ...require("@tiptap/core")
519
631
  });
520
- //# sourceMappingURL=index.cjs.map
632
+ //# sourceMappingURL=index.cjs.map