@tiptap/vue-2 3.0.0 → 3.0.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 (204) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +340 -349
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +79 -0
  6. package/dist/index.d.ts +79 -0
  7. package/dist/index.js +298 -337
  8. package/dist/index.js.map +1 -1
  9. package/dist/menus/index.cjs +2274 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +145 -0
  12. package/dist/menus/index.d.ts +145 -0
  13. package/dist/menus/index.js +2246 -0
  14. package/dist/menus/index.js.map +1 -0
  15. package/package.json +28 -16
  16. package/src/Editor.ts +1 -1
  17. package/src/EditorContent.ts +7 -5
  18. package/src/NodeViewContent.ts +3 -2
  19. package/src/NodeViewWrapper.ts +6 -5
  20. package/src/VueNodeViewRenderer.ts +80 -27
  21. package/src/VueRenderer.ts +5 -7
  22. package/src/index.ts +0 -2
  23. package/src/menus/BubbleMenu.ts +85 -0
  24. package/src/{FloatingMenu.ts → menus/FloatingMenu.ts} +24 -15
  25. package/src/menus/index.ts +2 -0
  26. package/dist/index.umd.js +0 -379
  27. package/dist/index.umd.js.map +0 -1
  28. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  29. package/dist/packages/core/src/Editor.d.ts +0 -161
  30. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  31. package/dist/packages/core/src/Extension.d.ts +0 -343
  32. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  33. package/dist/packages/core/src/InputRule.d.ts +0 -42
  34. package/dist/packages/core/src/Mark.d.ts +0 -451
  35. package/dist/packages/core/src/Node.d.ts +0 -611
  36. package/dist/packages/core/src/NodePos.d.ts +0 -44
  37. package/dist/packages/core/src/NodeView.d.ts +0 -31
  38. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  39. package/dist/packages/core/src/Tracker.d.ts +0 -11
  40. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  41. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  42. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  43. package/dist/packages/core/src/commands/command.d.ts +0 -18
  44. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  45. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  46. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  47. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  48. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  49. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  50. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  51. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  52. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  53. package/dist/packages/core/src/commands/first.d.ts +0 -14
  54. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  55. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  56. package/dist/packages/core/src/commands/index.d.ts +0 -55
  57. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  58. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  59. package/dist/packages/core/src/commands/join.d.ts +0 -41
  60. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  61. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  62. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  63. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  64. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  65. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  66. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  67. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  68. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  69. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  70. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  71. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  72. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  73. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  74. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  75. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  76. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  77. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  78. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  79. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  80. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  81. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  82. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  83. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  84. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  85. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  86. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  87. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  88. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  89. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  90. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  91. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  92. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  93. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  94. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  95. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  96. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  97. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  98. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  99. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  100. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  101. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  102. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  103. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  104. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  105. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  106. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  107. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  108. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  109. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  110. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  111. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  112. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  113. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  114. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  115. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  116. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  117. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  118. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  120. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  121. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  122. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  123. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  125. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  126. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  127. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  130. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  131. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  132. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  133. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  134. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  135. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  136. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  137. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  138. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  139. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  140. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  141. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  142. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  143. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  144. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  145. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  146. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  147. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  148. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  149. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  150. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  151. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  152. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  153. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  154. package/dist/packages/core/src/index.d.ts +0 -24
  155. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  156. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  157. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  158. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  159. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  160. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  161. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  162. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  163. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  164. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  165. package/dist/packages/core/src/style.d.ts +0 -1
  166. package/dist/packages/core/src/types.d.ts +0 -255
  167. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  168. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  170. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  174. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  175. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  176. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  177. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  178. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  179. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  180. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  181. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  182. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  183. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  184. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  185. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  186. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  187. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  188. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  189. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
  190. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
  191. package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
  192. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
  193. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
  194. package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
  195. package/dist/packages/vue-2/src/BubbleMenu.d.ts +0 -10
  196. package/dist/packages/vue-2/src/Editor.d.ts +0 -5
  197. package/dist/packages/vue-2/src/EditorContent.d.ts +0 -6
  198. package/dist/packages/vue-2/src/FloatingMenu.d.ts +0 -9
  199. package/dist/packages/vue-2/src/NodeViewContent.d.ts +0 -5
  200. package/dist/packages/vue-2/src/NodeViewWrapper.d.ts +0 -9
  201. package/dist/packages/vue-2/src/VueNodeViewRenderer.d.ts +0 -37
  202. package/dist/packages/vue-2/src/VueRenderer.d.ts +0 -12
  203. package/dist/packages/vue-2/src/index.d.ts +0 -9
  204. package/src/BubbleMenu.ts +0 -70
package/dist/index.js CHANGED
@@ -1,364 +1,325 @@
1
- import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu';
2
- import { Editor as Editor$1, NodeView } from '@tiptap/core';
3
- export * from '@tiptap/core';
4
- import { FloatingMenuPlugin } from '@tiptap/extension-floating-menu';
5
- import Vue from 'vue';
6
- import { objectProp, booleanProp, functionProp } from 'vue-ts-types';
7
-
8
- const BubbleMenu = {
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
- },
22
- tippyOptions: {
23
- type: Object,
24
- default: () => ({}),
25
- },
26
- shouldShow: {
27
- type: Function,
28
- default: null,
29
- },
30
- },
31
- watch: {
32
- editor: {
33
- immediate: true,
34
- handler(editor) {
35
- if (!editor) {
36
- return;
37
- }
38
- this.$nextTick(() => {
39
- editor.registerPlugin(BubbleMenuPlugin({
40
- updateDelay: this.updateDelay,
41
- editor,
42
- element: this.$el,
43
- pluginKey: this.pluginKey,
44
- shouldShow: this.shouldShow,
45
- tippyOptions: this.tippyOptions,
46
- }));
47
- });
48
- },
49
- },
50
- },
51
- render(createElement) {
52
- return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
53
- },
54
- beforeDestroy() {
55
- this.editor.unregisterPlugin(this.pluginKey);
56
- },
1
+ // src/Editor.ts
2
+ import { Editor as CoreEditor } from "@tiptap/core";
3
+ var Editor = class extends CoreEditor {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.contentComponent = null;
7
+ }
57
8
  };
58
9
 
59
- class Editor extends Editor$1 {
60
- constructor() {
61
- super(...arguments);
62
- this.contentComponent = null;
10
+ // src/EditorContent.ts
11
+ var EditorContent = {
12
+ name: "EditorContent",
13
+ props: {
14
+ editor: {
15
+ default: null,
16
+ type: Object
63
17
  }
64
- }
65
-
66
- const EditorContent = {
67
- name: 'EditorContent',
68
- props: {
69
- editor: {
70
- default: null,
71
- type: Object,
72
- },
73
- },
74
- watch: {
75
- editor: {
76
- immediate: true,
77
- handler(editor) {
78
- if (editor && editor.options.element) {
79
- this.$nextTick(() => {
80
- const element = this.$el;
81
- if (!element || !editor.options.element.firstChild) {
82
- return;
83
- }
84
- element.append(...editor.options.element.childNodes);
85
- editor.contentComponent = this;
86
- editor.setOptions({
87
- element,
88
- });
89
- editor.createNodeViews();
90
- });
91
- }
92
- },
93
- },
94
- },
95
- render(createElement) {
96
- return createElement('div');
97
- },
98
- beforeDestroy() {
99
- const { editor } = this;
100
- if (!editor) {
101
- return;
102
- }
103
- if (!editor.isDestroyed) {
104
- editor.view.setProps({
105
- nodeViews: {},
18
+ },
19
+ watch: {
20
+ editor: {
21
+ immediate: true,
22
+ handler(editor) {
23
+ if (editor && editor.options.element) {
24
+ this.$nextTick(() => {
25
+ var _a;
26
+ const element = this.$el;
27
+ if (!element || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
28
+ return;
29
+ }
30
+ element.append(...editor.options.element.childNodes);
31
+ editor.contentComponent = this;
32
+ editor.setOptions({
33
+ element
106
34
  });
35
+ editor.createNodeViews();
36
+ });
107
37
  }
108
- editor.contentComponent = null;
109
- if (!editor.options.element.firstChild) {
110
- return;
111
- }
112
- const newElement = document.createElement('div');
113
- newElement.append(...editor.options.element.childNodes);
114
- editor.setOptions({
115
- element: newElement,
116
- });
117
- },
38
+ }
39
+ }
40
+ },
41
+ render(createElement) {
42
+ return createElement("div");
43
+ },
44
+ beforeDestroy() {
45
+ var _a;
46
+ const { editor } = this;
47
+ if (!editor) {
48
+ return;
49
+ }
50
+ if (!editor.isDestroyed) {
51
+ editor.view.setProps({
52
+ nodeViews: {}
53
+ });
54
+ }
55
+ editor.contentComponent = null;
56
+ if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
57
+ return;
58
+ }
59
+ const newElement = document.createElement("div");
60
+ newElement.append(...editor.options.element.childNodes);
61
+ editor.setOptions({
62
+ element: newElement
63
+ });
64
+ }
118
65
  };
119
66
 
120
- const FloatingMenu = {
121
- name: 'FloatingMenu',
122
- props: {
123
- pluginKey: {
124
- type: [String, Object],
125
- default: 'floatingMenu',
126
- },
127
- editor: {
128
- type: Object,
129
- required: true,
130
- },
131
- tippyOptions: {
132
- type: Object,
133
- default: () => ({}),
134
- },
135
- shouldShow: {
136
- type: Function,
137
- default: null,
138
- },
139
- },
140
- watch: {
141
- editor: {
142
- immediate: true,
143
- handler(editor) {
144
- if (!editor) {
145
- return;
146
- }
147
- this.$nextTick(() => {
148
- editor.registerPlugin(FloatingMenuPlugin({
149
- pluginKey: this.pluginKey,
150
- editor,
151
- element: this.$el,
152
- tippyOptions: this.tippyOptions,
153
- shouldShow: this.shouldShow,
154
- }));
155
- });
156
- },
157
- },
158
- },
159
- render(createElement) {
160
- return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
161
- },
162
- beforeDestroy() {
163
- this.editor.unregisterPlugin(this.pluginKey);
164
- },
67
+ // src/NodeViewContent.ts
68
+ var NodeViewContent = {
69
+ props: {
70
+ as: {
71
+ type: String,
72
+ default: "div"
73
+ }
74
+ },
75
+ render(createElement) {
76
+ return createElement(this.as, {
77
+ style: {
78
+ whiteSpace: "pre-wrap"
79
+ },
80
+ attrs: {
81
+ "data-node-view-content": ""
82
+ }
83
+ });
84
+ }
165
85
  };
166
86
 
167
- const NodeViewContent = {
168
- props: {
169
- as: {
170
- type: String,
171
- default: 'div',
87
+ // src/NodeViewWrapper.ts
88
+ var NodeViewWrapper = {
89
+ props: {
90
+ as: {
91
+ type: String,
92
+ default: "div"
93
+ }
94
+ },
95
+ inject: ["onDragStart", "decorationClasses"],
96
+ render(createElement) {
97
+ return createElement(
98
+ this.as,
99
+ {
100
+ class: this.decorationClasses.value,
101
+ style: {
102
+ whiteSpace: "normal"
172
103
  },
173
- },
174
- render(createElement) {
175
- return createElement(this.as, {
176
- style: {
177
- whiteSpace: 'pre-wrap',
178
- },
179
- attrs: {
180
- 'data-node-view-content': '',
181
- },
182
- });
183
- },
184
- };
185
-
186
- const NodeViewWrapper = {
187
- props: {
188
- as: {
189
- type: String,
190
- default: 'div',
104
+ attrs: {
105
+ "data-node-view-wrapper": ""
191
106
  },
192
- },
193
- inject: ['onDragStart', 'decorationClasses'],
194
- render(createElement) {
195
- return createElement(this.as, {
196
- class: this.decorationClasses.value,
197
- style: {
198
- whiteSpace: 'normal',
199
- },
200
- attrs: {
201
- 'data-node-view-wrapper': '',
202
- },
203
- on: {
204
- dragstart: this.onDragStart,
205
- },
206
- }, this.$slots.default);
207
- },
107
+ on: {
108
+ dragstart: this.onDragStart
109
+ }
110
+ },
111
+ this.$slots.default
112
+ );
113
+ }
208
114
  };
209
115
 
210
- /**
211
- * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.
212
- */
213
- class VueRenderer {
214
- constructor(component, props) {
215
- const Component = (typeof component === 'function') ? component : Vue.extend(component);
216
- this.ref = new Component(props).$mount();
217
- }
218
- get element() {
219
- return this.ref.$el;
220
- }
221
- updateProps(props = {}) {
222
- var _a, _b, _c;
223
- if (!this.ref.$props) {
224
- return;
225
- }
226
- // prevents `Avoid mutating a prop directly` error message
227
- // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working
228
- const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.$options._base) !== null && _c !== void 0 ? _c : Vue; // eslint-disable-line
229
- const originalSilent = currentVueConstructor.config.silent;
230
- currentVueConstructor.config.silent = true;
231
- Object
232
- .entries(props)
233
- .forEach(([key, value]) => {
234
- this.ref.$props[key] = value;
235
- });
236
- currentVueConstructor.config.silent = originalSilent;
237
- }
238
- destroy() {
239
- this.ref.$destroy();
116
+ // src/VueNodeViewRenderer.ts
117
+ import { NodeView } from "@tiptap/core";
118
+ import Vue2 from "vue";
119
+ import { booleanProp, functionProp, objectProp } from "vue-ts-types";
120
+
121
+ // src/VueRenderer.ts
122
+ import Vue from "vue";
123
+ var VueRenderer = class {
124
+ constructor(component, props) {
125
+ const Component = typeof component === "function" ? component : Vue.extend(component);
126
+ this.ref = new Component(props).$mount();
127
+ }
128
+ get element() {
129
+ return this.ref.$el;
130
+ }
131
+ updateProps(props = {}) {
132
+ var _a, _b, _c;
133
+ if (!this.ref.$props) {
134
+ return;
240
135
  }
241
- }
136
+ const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.$options._base) != null ? _c : Vue;
137
+ const originalSilent = currentVueConstructor.config.silent;
138
+ currentVueConstructor.config.silent = true;
139
+ Object.entries(props).forEach(([key, value]) => {
140
+ this.ref.$props[key] = value;
141
+ });
142
+ currentVueConstructor.config.silent = originalSilent;
143
+ }
144
+ destroy() {
145
+ this.ref.$destroy();
146
+ }
147
+ };
242
148
 
243
- const nodeViewProps = {
244
- editor: objectProp().required,
245
- node: objectProp().required,
246
- decorations: objectProp().required,
247
- selected: booleanProp().required,
248
- extension: objectProp().required,
249
- getPos: functionProp().required,
250
- updateAttributes: functionProp().required,
251
- deleteNode: functionProp().required,
149
+ // src/VueNodeViewRenderer.ts
150
+ var nodeViewProps = {
151
+ editor: objectProp().required,
152
+ node: objectProp().required,
153
+ decorations: objectProp().required,
154
+ selected: booleanProp().required,
155
+ extension: objectProp().required,
156
+ getPos: functionProp().required,
157
+ updateAttributes: functionProp().required,
158
+ deleteNode: functionProp().required
252
159
  };
253
- class VueNodeView extends NodeView {
254
- mount() {
255
- var _a, _b;
256
- const props = {
257
- editor: this.editor,
258
- node: this.node,
259
- decorations: this.decorations,
260
- selected: false,
261
- extension: this.extension,
262
- getPos: () => this.getPos(),
263
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
264
- deleteNode: () => this.deleteNode(),
160
+ var VueNodeView = class extends NodeView {
161
+ mount() {
162
+ var _a, _b;
163
+ const props = {
164
+ editor: this.editor,
165
+ node: this.node,
166
+ decorations: this.decorations,
167
+ innerDecorations: this.innerDecorations,
168
+ view: this.view,
169
+ selected: false,
170
+ extension: this.extension,
171
+ HTMLAttributes: this.HTMLAttributes,
172
+ getPos: () => this.getPos(),
173
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
174
+ deleteNode: () => this.deleteNode()
175
+ };
176
+ const onDragStart = this.onDragStart.bind(this);
177
+ this.decorationClasses = Vue2.observable({
178
+ value: this.getDecorationClasses()
179
+ });
180
+ const vue = (_b = (_a = this.editor.contentComponent) == null ? void 0 : _a.$options._base) != null ? _b : Vue2;
181
+ const Component = vue.extend(this.component).extend({
182
+ props: Object.keys(props),
183
+ provide: () => {
184
+ return {
185
+ onDragStart,
186
+ decorationClasses: this.decorationClasses
265
187
  };
266
- const onDragStart = this.onDragStart.bind(this);
267
- this.decorationClasses = Vue.observable({
268
- value: this.getDecorationClasses(),
269
- });
270
- // @ts-ignore
271
- const vue = (_b = (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.$options._base) !== null && _b !== void 0 ? _b : Vue; // eslint-disable-line
272
- const Component = vue.extend(this.component).extend({
273
- props: Object.keys(props),
274
- provide: () => {
275
- return {
276
- onDragStart,
277
- decorationClasses: this.decorationClasses,
278
- };
279
- },
280
- });
281
- this.renderer = new VueRenderer(Component, {
282
- parent: this.editor.contentComponent,
283
- propsData: props,
284
- });
188
+ }
189
+ });
190
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
191
+ this.editor.on("selectionUpdate", this.handleSelectionUpdate);
192
+ this.renderer = new VueRenderer(Component, {
193
+ parent: this.editor.contentComponent,
194
+ propsData: props
195
+ });
196
+ }
197
+ /**
198
+ * Return the DOM element.
199
+ * This is the element that will be used to display the node view.
200
+ */
201
+ get dom() {
202
+ if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
203
+ throw Error("Please use the NodeViewWrapper component for your node view.");
285
204
  }
286
- get dom() {
287
- if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
288
- throw Error('Please use the NodeViewWrapper component for your node view.');
289
- }
290
- return this.renderer.element;
205
+ return this.renderer.element;
206
+ }
207
+ /**
208
+ * Return the content DOM element.
209
+ * This is the element that will be used to display the rich-text content of the node.
210
+ */
211
+ get contentDOM() {
212
+ if (this.node.isLeaf) {
213
+ return null;
291
214
  }
292
- get contentDOM() {
293
- if (this.node.isLeaf) {
294
- return null;
295
- }
296
- const contentElement = this.dom.querySelector('[data-node-view-content]');
297
- return (contentElement || this.dom);
215
+ return this.dom.querySelector("[data-node-view-content]");
216
+ }
217
+ /**
218
+ * On editor selection update, check if the node is selected.
219
+ * If it is, call `selectNode`, otherwise call `deselectNode`.
220
+ */
221
+ handleSelectionUpdate() {
222
+ const { from, to } = this.editor.state.selection;
223
+ const pos = this.getPos();
224
+ if (typeof pos !== "number") {
225
+ return;
298
226
  }
299
- update(node, decorations) {
300
- const updateProps = (props) => {
301
- this.decorationClasses.value = this.getDecorationClasses();
302
- this.renderer.updateProps(props);
303
- };
304
- if (typeof this.options.update === 'function') {
305
- const oldNode = this.node;
306
- const oldDecorations = this.decorations;
307
- this.node = node;
308
- this.decorations = decorations;
309
- return this.options.update({
310
- oldNode,
311
- oldDecorations,
312
- newNode: node,
313
- newDecorations: decorations,
314
- updateProps: () => updateProps({ node, decorations }),
315
- });
316
- }
317
- if (node.type !== this.node.type) {
318
- return false;
319
- }
320
- if (node === this.node && this.decorations === decorations) {
321
- return true;
322
- }
323
- this.node = node;
324
- this.decorations = decorations;
325
- updateProps({ node, decorations });
326
- return true;
327
- }
328
- selectNode() {
329
- this.renderer.updateProps({
330
- selected: true,
331
- });
332
- this.renderer.element.classList.add('ProseMirror-selectednode');
227
+ if (from <= pos && to >= pos + this.node.nodeSize) {
228
+ if (this.renderer.ref.$props.selected) {
229
+ return;
230
+ }
231
+ this.selectNode();
232
+ } else {
233
+ if (!this.renderer.ref.$props.selected) {
234
+ return;
235
+ }
236
+ this.deselectNode();
333
237
  }
334
- deselectNode() {
335
- this.renderer.updateProps({
336
- selected: false,
337
- });
338
- this.renderer.element.classList.remove('ProseMirror-selectednode');
238
+ }
239
+ /**
240
+ * On update, update the React component.
241
+ * To prevent unnecessary updates, the `update` option can be used.
242
+ */
243
+ update(node, decorations, innerDecorations) {
244
+ const rerenderComponent = (props) => {
245
+ this.decorationClasses.value = this.getDecorationClasses();
246
+ this.renderer.updateProps(props);
247
+ };
248
+ if (typeof this.options.update === "function") {
249
+ const oldNode = this.node;
250
+ const oldDecorations = this.decorations;
251
+ const oldInnerDecorations = this.innerDecorations;
252
+ this.node = node;
253
+ this.decorations = decorations;
254
+ this.innerDecorations = innerDecorations;
255
+ return this.options.update({
256
+ oldNode,
257
+ oldDecorations,
258
+ newNode: node,
259
+ newDecorations: decorations,
260
+ oldInnerDecorations,
261
+ innerDecorations,
262
+ updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
263
+ });
339
264
  }
340
- getDecorationClasses() {
341
- return (this.decorations
342
- // @ts-ignore
343
- .map(item => item.type.attrs.class)
344
- .flat()
345
- .join(' '));
265
+ if (node.type !== this.node.type) {
266
+ return false;
346
267
  }
347
- destroy() {
348
- this.renderer.destroy();
268
+ if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
269
+ return true;
349
270
  }
350
- }
271
+ this.node = node;
272
+ this.decorations = decorations;
273
+ this.innerDecorations = innerDecorations;
274
+ rerenderComponent({ node, decorations, innerDecorations });
275
+ return true;
276
+ }
277
+ /**
278
+ * Select the node.
279
+ * Add the `selected` prop and the `ProseMirror-selectednode` class.
280
+ */
281
+ selectNode() {
282
+ this.renderer.updateProps({
283
+ selected: true
284
+ });
285
+ this.renderer.element.classList.add("ProseMirror-selectednode");
286
+ }
287
+ /**
288
+ * Deselect the node.
289
+ * Remove the `selected` prop and the `ProseMirror-selectednode` class.
290
+ */
291
+ deselectNode() {
292
+ this.renderer.updateProps({
293
+ selected: false
294
+ });
295
+ this.renderer.element.classList.remove("ProseMirror-selectednode");
296
+ }
297
+ getDecorationClasses() {
298
+ return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
299
+ }
300
+ destroy() {
301
+ this.renderer.destroy();
302
+ this.editor.off("selectionUpdate", this.handleSelectionUpdate);
303
+ }
304
+ };
351
305
  function VueNodeViewRenderer(component, options) {
352
- return (props) => {
353
- // try to get the parent component
354
- // this is important for vue devtools to show the component hierarchy correctly
355
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
356
- if (!props.editor.contentComponent) {
357
- return {};
358
- }
359
- return new VueNodeView(component, props, options);
360
- };
306
+ return (props) => {
307
+ if (!props.editor.contentComponent) {
308
+ return {};
309
+ }
310
+ return new VueNodeView(component, props, options);
311
+ };
361
312
  }
362
313
 
363
- export { BubbleMenu, Editor, EditorContent, FloatingMenu, NodeViewContent, NodeViewWrapper, VueNodeViewRenderer, VueRenderer, nodeViewProps };
364
- //# sourceMappingURL=index.js.map
314
+ // src/index.ts
315
+ export * from "@tiptap/core";
316
+ export {
317
+ Editor,
318
+ EditorContent,
319
+ NodeViewContent,
320
+ NodeViewWrapper,
321
+ VueNodeViewRenderer,
322
+ VueRenderer,
323
+ nodeViewProps
324
+ };
325
+ //# sourceMappingURL=index.js.map