@tiptap/vue-2 2.11.7 → 3.0.0-beta.1

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 (45) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +340 -407
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +79 -0
  6. package/dist/index.d.ts +78 -9
  7. package/dist/index.js +298 -391
  8. package/dist/index.js.map +1 -1
  9. package/dist/menus/index.cjs +2140 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +131 -0
  12. package/dist/menus/index.d.ts +131 -0
  13. package/dist/menus/index.js +2112 -0
  14. package/dist/menus/index.js.map +1 -0
  15. package/package.json +25 -13
  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 +18 -29
  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/BubbleMenu.d.ts +0 -11
  27. package/dist/BubbleMenu.d.ts.map +0 -1
  28. package/dist/Editor.d.ts +0 -6
  29. package/dist/Editor.d.ts.map +0 -1
  30. package/dist/EditorContent.d.ts +0 -7
  31. package/dist/EditorContent.d.ts.map +0 -1
  32. package/dist/FloatingMenu.d.ts +0 -10
  33. package/dist/FloatingMenu.d.ts.map +0 -1
  34. package/dist/NodeViewContent.d.ts +0 -6
  35. package/dist/NodeViewContent.d.ts.map +0 -1
  36. package/dist/NodeViewWrapper.d.ts +0 -10
  37. package/dist/NodeViewWrapper.d.ts.map +0 -1
  38. package/dist/VueNodeViewRenderer.d.ts +0 -40
  39. package/dist/VueNodeViewRenderer.d.ts.map +0 -1
  40. package/dist/VueRenderer.d.ts +0 -13
  41. package/dist/VueRenderer.d.ts.map +0 -1
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.umd.js +0 -433
  44. package/dist/index.umd.js.map +0 -1
  45. package/src/BubbleMenu.ts +0 -70
package/dist/index.cjs CHANGED
@@ -1,437 +1,370 @@
1
- 'use strict';
2
-
3
- var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
4
- var core = require('@tiptap/core');
5
- var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
6
- var Vue = require('vue');
7
- var vueTsTypes = require('vue-ts-types');
8
-
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
10
30
 
11
- var Vue__default = /*#__PURE__*/_interopDefaultCompat(Vue);
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ Editor: () => Editor,
35
+ EditorContent: () => EditorContent,
36
+ NodeViewContent: () => NodeViewContent,
37
+ NodeViewWrapper: () => NodeViewWrapper,
38
+ VueNodeViewRenderer: () => VueNodeViewRenderer,
39
+ VueRenderer: () => VueRenderer,
40
+ nodeViewProps: () => nodeViewProps
41
+ });
42
+ module.exports = __toCommonJS(index_exports);
12
43
 
13
- const BubbleMenu = {
14
- name: 'BubbleMenu',
15
- props: {
16
- pluginKey: {
17
- type: [String, Object],
18
- default: 'bubbleMenu',
19
- },
20
- editor: {
21
- type: Object,
22
- required: true,
23
- },
24
- updateDelay: {
25
- type: Number,
26
- },
27
- tippyOptions: {
28
- type: Object,
29
- default: () => ({}),
30
- },
31
- shouldShow: {
32
- type: Function,
33
- default: null,
34
- },
35
- },
36
- watch: {
37
- editor: {
38
- immediate: true,
39
- handler(editor) {
40
- if (!editor) {
41
- return;
42
- }
43
- this.$nextTick(() => {
44
- editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
45
- updateDelay: this.updateDelay,
46
- editor,
47
- element: this.$el,
48
- pluginKey: this.pluginKey,
49
- shouldShow: this.shouldShow,
50
- tippyOptions: this.tippyOptions,
51
- }));
52
- });
53
- },
54
- },
55
- },
56
- render(createElement) {
57
- return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
58
- },
59
- beforeDestroy() {
60
- this.editor.unregisterPlugin(this.pluginKey);
61
- },
44
+ // src/Editor.ts
45
+ var import_core = require("@tiptap/core");
46
+ var Editor = class extends import_core.Editor {
47
+ constructor() {
48
+ super(...arguments);
49
+ this.contentComponent = null;
50
+ }
62
51
  };
63
52
 
64
- class Editor extends core.Editor {
65
- constructor() {
66
- super(...arguments);
67
- this.contentComponent = null;
53
+ // src/EditorContent.ts
54
+ var EditorContent = {
55
+ name: "EditorContent",
56
+ props: {
57
+ editor: {
58
+ default: null,
59
+ type: Object
68
60
  }
69
- }
70
-
71
- const EditorContent = {
72
- name: 'EditorContent',
73
- props: {
74
- editor: {
75
- default: null,
76
- type: Object,
77
- },
78
- },
79
- watch: {
80
- editor: {
81
- immediate: true,
82
- handler(editor) {
83
- if (editor && editor.options.element) {
84
- this.$nextTick(() => {
85
- const element = this.$el;
86
- if (!element || !editor.options.element.firstChild) {
87
- return;
88
- }
89
- element.append(...editor.options.element.childNodes);
90
- editor.contentComponent = this;
91
- editor.setOptions({
92
- element,
93
- });
94
- editor.createNodeViews();
95
- });
96
- }
97
- },
98
- },
99
- },
100
- render(createElement) {
101
- return createElement('div');
102
- },
103
- beforeDestroy() {
104
- const { editor } = this;
105
- if (!editor) {
106
- return;
107
- }
108
- if (!editor.isDestroyed) {
109
- editor.view.setProps({
110
- nodeViews: {},
61
+ },
62
+ watch: {
63
+ editor: {
64
+ immediate: true,
65
+ handler(editor) {
66
+ if (editor && editor.options.element) {
67
+ this.$nextTick(() => {
68
+ var _a;
69
+ const element = this.$el;
70
+ if (!element || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
71
+ return;
72
+ }
73
+ element.append(...editor.options.element.childNodes);
74
+ editor.contentComponent = this;
75
+ editor.setOptions({
76
+ element
111
77
  });
78
+ editor.createNodeViews();
79
+ });
112
80
  }
113
- editor.contentComponent = null;
114
- if (!editor.options.element.firstChild) {
115
- return;
116
- }
117
- const newElement = document.createElement('div');
118
- newElement.append(...editor.options.element.childNodes);
119
- editor.setOptions({
120
- element: newElement,
121
- });
122
- },
81
+ }
82
+ }
83
+ },
84
+ render(createElement) {
85
+ return createElement("div");
86
+ },
87
+ beforeDestroy() {
88
+ var _a;
89
+ const { editor } = this;
90
+ if (!editor) {
91
+ return;
92
+ }
93
+ if (!editor.isDestroyed) {
94
+ editor.view.setProps({
95
+ nodeViews: {}
96
+ });
97
+ }
98
+ editor.contentComponent = null;
99
+ if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
100
+ return;
101
+ }
102
+ const newElement = document.createElement("div");
103
+ newElement.append(...editor.options.element.childNodes);
104
+ editor.setOptions({
105
+ element: newElement
106
+ });
107
+ }
123
108
  };
124
109
 
125
- const FloatingMenu = {
126
- name: 'FloatingMenu',
127
- props: {
128
- pluginKey: {
129
- type: [String, Object],
130
- default: 'floatingMenu',
131
- },
132
- editor: {
133
- type: Object,
134
- required: true,
135
- },
136
- tippyOptions: {
137
- type: Object,
138
- default: () => ({}),
139
- },
140
- shouldShow: {
141
- type: Function,
142
- default: null,
143
- },
144
- },
145
- watch: {
146
- editor: {
147
- immediate: true,
148
- handler(editor) {
149
- if (!editor) {
150
- return;
151
- }
152
- this.$nextTick(() => {
153
- editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
154
- pluginKey: this.pluginKey,
155
- editor,
156
- element: this.$el,
157
- tippyOptions: this.tippyOptions,
158
- shouldShow: this.shouldShow,
159
- }));
160
- });
161
- },
162
- },
163
- },
164
- render(createElement) {
165
- return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
166
- },
167
- beforeDestroy() {
168
- this.editor.unregisterPlugin(this.pluginKey);
169
- },
110
+ // src/NodeViewContent.ts
111
+ var NodeViewContent = {
112
+ props: {
113
+ as: {
114
+ type: String,
115
+ default: "div"
116
+ }
117
+ },
118
+ render(createElement) {
119
+ return createElement(this.as, {
120
+ style: {
121
+ whiteSpace: "pre-wrap"
122
+ },
123
+ attrs: {
124
+ "data-node-view-content": ""
125
+ }
126
+ });
127
+ }
170
128
  };
171
129
 
172
- const NodeViewContent = {
173
- props: {
174
- as: {
175
- type: String,
176
- default: 'div',
130
+ // src/NodeViewWrapper.ts
131
+ var NodeViewWrapper = {
132
+ props: {
133
+ as: {
134
+ type: String,
135
+ default: "div"
136
+ }
137
+ },
138
+ inject: ["onDragStart", "decorationClasses"],
139
+ render(createElement) {
140
+ return createElement(
141
+ this.as,
142
+ {
143
+ class: this.decorationClasses.value,
144
+ style: {
145
+ whiteSpace: "normal"
177
146
  },
178
- },
179
- render(createElement) {
180
- return createElement(this.as, {
181
- style: {
182
- whiteSpace: 'pre-wrap',
183
- },
184
- attrs: {
185
- 'data-node-view-content': '',
186
- },
187
- });
188
- },
189
- };
190
-
191
- const NodeViewWrapper = {
192
- props: {
193
- as: {
194
- type: String,
195
- default: 'div',
147
+ attrs: {
148
+ "data-node-view-wrapper": ""
196
149
  },
197
- },
198
- inject: ['onDragStart', 'decorationClasses'],
199
- render(createElement) {
200
- return createElement(this.as, {
201
- class: this.decorationClasses.value,
202
- style: {
203
- whiteSpace: 'normal',
204
- },
205
- attrs: {
206
- 'data-node-view-wrapper': '',
207
- },
208
- on: {
209
- dragstart: this.onDragStart,
210
- },
211
- }, this.$slots.default);
212
- },
150
+ on: {
151
+ dragstart: this.onDragStart
152
+ }
153
+ },
154
+ this.$slots.default
155
+ );
156
+ }
213
157
  };
214
158
 
215
- /**
216
- * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.
217
- */
218
- class VueRenderer {
219
- constructor(component, props) {
220
- const Component = (typeof component === 'function') ? component : Vue__default.default.extend(component);
221
- this.ref = new Component(props).$mount();
222
- }
223
- get element() {
224
- return this.ref.$el;
225
- }
226
- updateProps(props = {}) {
227
- var _a, _b, _c;
228
- if (!this.ref.$props) {
229
- return;
230
- }
231
- // prevents `Avoid mutating a prop directly` error message
232
- // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working
233
- 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__default.default; // eslint-disable-line
234
- const originalSilent = currentVueConstructor.config.silent;
235
- currentVueConstructor.config.silent = true;
236
- Object
237
- .entries(props)
238
- .forEach(([key, value]) => {
239
- this.ref.$props[key] = value;
240
- });
241
- currentVueConstructor.config.silent = originalSilent;
242
- }
243
- destroy() {
244
- this.ref.$destroy();
159
+ // src/VueNodeViewRenderer.ts
160
+ var import_core2 = require("@tiptap/core");
161
+ var import_vue2 = __toESM(require("vue"), 1);
162
+ var import_vue_ts_types = require("vue-ts-types");
163
+
164
+ // src/VueRenderer.ts
165
+ var import_vue = __toESM(require("vue"), 1);
166
+ var VueRenderer = class {
167
+ constructor(component, props) {
168
+ const Component = typeof component === "function" ? component : import_vue.default.extend(component);
169
+ this.ref = new Component(props).$mount();
170
+ }
171
+ get element() {
172
+ return this.ref.$el;
173
+ }
174
+ updateProps(props = {}) {
175
+ var _a, _b, _c;
176
+ if (!this.ref.$props) {
177
+ return;
245
178
  }
246
- }
179
+ const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.$options._base) != null ? _c : import_vue.default;
180
+ const originalSilent = currentVueConstructor.config.silent;
181
+ currentVueConstructor.config.silent = true;
182
+ Object.entries(props).forEach(([key, value]) => {
183
+ this.ref.$props[key] = value;
184
+ });
185
+ currentVueConstructor.config.silent = originalSilent;
186
+ }
187
+ destroy() {
188
+ this.ref.$destroy();
189
+ }
190
+ };
247
191
 
248
- const nodeViewProps = {
249
- editor: vueTsTypes.objectProp().required,
250
- node: vueTsTypes.objectProp().required,
251
- decorations: vueTsTypes.objectProp().required,
252
- selected: vueTsTypes.booleanProp().required,
253
- extension: vueTsTypes.objectProp().required,
254
- getPos: vueTsTypes.functionProp().required,
255
- updateAttributes: vueTsTypes.functionProp().required,
256
- deleteNode: vueTsTypes.functionProp().required,
192
+ // src/VueNodeViewRenderer.ts
193
+ var nodeViewProps = {
194
+ editor: (0, import_vue_ts_types.objectProp)().required,
195
+ node: (0, import_vue_ts_types.objectProp)().required,
196
+ decorations: (0, import_vue_ts_types.objectProp)().required,
197
+ selected: (0, import_vue_ts_types.booleanProp)().required,
198
+ extension: (0, import_vue_ts_types.objectProp)().required,
199
+ getPos: (0, import_vue_ts_types.functionProp)().required,
200
+ updateAttributes: (0, import_vue_ts_types.functionProp)().required,
201
+ deleteNode: (0, import_vue_ts_types.functionProp)().required
257
202
  };
258
- class VueNodeView extends core.NodeView {
259
- mount() {
260
- var _a, _b;
261
- const props = {
262
- editor: this.editor,
263
- node: this.node,
264
- decorations: this.decorations,
265
- innerDecorations: this.innerDecorations,
266
- view: this.view,
267
- selected: false,
268
- extension: this.extension,
269
- HTMLAttributes: this.HTMLAttributes,
270
- getPos: () => this.getPos(),
271
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
272
- deleteNode: () => this.deleteNode(),
203
+ var VueNodeView = class extends import_core2.NodeView {
204
+ mount() {
205
+ var _a, _b;
206
+ const props = {
207
+ editor: this.editor,
208
+ node: this.node,
209
+ decorations: this.decorations,
210
+ innerDecorations: this.innerDecorations,
211
+ view: this.view,
212
+ selected: false,
213
+ extension: this.extension,
214
+ HTMLAttributes: this.HTMLAttributes,
215
+ getPos: () => this.getPos(),
216
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
217
+ deleteNode: () => this.deleteNode()
218
+ };
219
+ const onDragStart = this.onDragStart.bind(this);
220
+ this.decorationClasses = import_vue2.default.observable({
221
+ value: this.getDecorationClasses()
222
+ });
223
+ const vue = (_b = (_a = this.editor.contentComponent) == null ? void 0 : _a.$options._base) != null ? _b : import_vue2.default;
224
+ const Component = vue.extend(this.component).extend({
225
+ props: Object.keys(props),
226
+ provide: () => {
227
+ return {
228
+ onDragStart,
229
+ decorationClasses: this.decorationClasses
273
230
  };
274
- const onDragStart = this.onDragStart.bind(this);
275
- this.decorationClasses = Vue__default.default.observable({
276
- value: this.getDecorationClasses(),
277
- });
278
- // @ts-ignore
279
- const vue = (_b = (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.$options._base) !== null && _b !== void 0 ? _b : Vue__default.default; // eslint-disable-line
280
- const Component = vue.extend(this.component).extend({
281
- props: Object.keys(props),
282
- provide: () => {
283
- return {
284
- onDragStart,
285
- decorationClasses: this.decorationClasses,
286
- };
287
- },
288
- });
289
- this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
290
- this.editor.on('selectionUpdate', this.handleSelectionUpdate);
291
- this.renderer = new VueRenderer(Component, {
292
- parent: this.editor.contentComponent,
293
- propsData: props,
294
- });
295
- }
296
- /**
297
- * Return the DOM element.
298
- * This is the element that will be used to display the node view.
299
- */
300
- get dom() {
301
- if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
302
- throw Error('Please use the NodeViewWrapper component for your node view.');
303
- }
304
- return this.renderer.element;
231
+ }
232
+ });
233
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
234
+ this.editor.on("selectionUpdate", this.handleSelectionUpdate);
235
+ this.renderer = new VueRenderer(Component, {
236
+ parent: this.editor.contentComponent,
237
+ propsData: props
238
+ });
239
+ }
240
+ /**
241
+ * Return the DOM element.
242
+ * This is the element that will be used to display the node view.
243
+ */
244
+ get dom() {
245
+ if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
246
+ throw Error("Please use the NodeViewWrapper component for your node view.");
305
247
  }
306
- /**
307
- * Return the content DOM element.
308
- * This is the element that will be used to display the rich-text content of the node.
309
- */
310
- get contentDOM() {
311
- if (this.node.isLeaf) {
312
- return null;
313
- }
314
- const contentElement = this.dom.querySelector('[data-node-view-content]');
315
- return (contentElement || this.dom);
316
- }
317
- /**
318
- * On editor selection update, check if the node is selected.
319
- * If it is, call `selectNode`, otherwise call `deselectNode`.
320
- */
321
- handleSelectionUpdate() {
322
- const { from, to } = this.editor.state.selection;
323
- const pos = this.getPos();
324
- if (typeof pos !== 'number') {
325
- return;
326
- }
327
- if (from <= pos && to >= pos + this.node.nodeSize) {
328
- if (this.renderer.ref.$props.selected) {
329
- return;
330
- }
331
- this.selectNode();
332
- }
333
- else {
334
- if (!this.renderer.ref.$props.selected) {
335
- return;
336
- }
337
- this.deselectNode();
338
- }
248
+ return this.renderer.element;
249
+ }
250
+ /**
251
+ * Return the content DOM element.
252
+ * This is the element that will be used to display the rich-text content of the node.
253
+ */
254
+ get contentDOM() {
255
+ if (this.node.isLeaf) {
256
+ return null;
339
257
  }
340
- /**
341
- * On update, update the React component.
342
- * To prevent unnecessary updates, the `update` option can be used.
343
- */
344
- update(node, decorations, innerDecorations) {
345
- const rerenderComponent = (props) => {
346
- this.decorationClasses.value = this.getDecorationClasses();
347
- this.renderer.updateProps(props);
348
- };
349
- if (typeof this.options.update === 'function') {
350
- const oldNode = this.node;
351
- const oldDecorations = this.decorations;
352
- const oldInnerDecorations = this.innerDecorations;
353
- this.node = node;
354
- this.decorations = decorations;
355
- this.innerDecorations = innerDecorations;
356
- return this.options.update({
357
- oldNode,
358
- oldDecorations,
359
- newNode: node,
360
- newDecorations: decorations,
361
- oldInnerDecorations,
362
- innerDecorations,
363
- updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),
364
- });
365
- }
366
- if (node.type !== this.node.type) {
367
- return false;
368
- }
369
- if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
370
- return true;
371
- }
372
- this.node = node;
373
- this.decorations = decorations;
374
- this.innerDecorations = innerDecorations;
375
- rerenderComponent({ node, decorations, innerDecorations });
376
- return true;
258
+ return this.dom.querySelector("[data-node-view-content]");
259
+ }
260
+ /**
261
+ * On editor selection update, check if the node is selected.
262
+ * If it is, call `selectNode`, otherwise call `deselectNode`.
263
+ */
264
+ handleSelectionUpdate() {
265
+ const { from, to } = this.editor.state.selection;
266
+ const pos = this.getPos();
267
+ if (typeof pos !== "number") {
268
+ return;
377
269
  }
378
- /**
379
- * Select the node.
380
- * Add the `selected` prop and the `ProseMirror-selectednode` class.
381
- */
382
- selectNode() {
383
- this.renderer.updateProps({
384
- selected: true,
385
- });
386
- this.renderer.element.classList.add('ProseMirror-selectednode');
270
+ if (from <= pos && to >= pos + this.node.nodeSize) {
271
+ if (this.renderer.ref.$props.selected) {
272
+ return;
273
+ }
274
+ this.selectNode();
275
+ } else {
276
+ if (!this.renderer.ref.$props.selected) {
277
+ return;
278
+ }
279
+ this.deselectNode();
387
280
  }
388
- /**
389
- * Deselect the node.
390
- * Remove the `selected` prop and the `ProseMirror-selectednode` class.
391
- */
392
- deselectNode() {
393
- this.renderer.updateProps({
394
- selected: false,
395
- });
396
- this.renderer.element.classList.remove('ProseMirror-selectednode');
281
+ }
282
+ /**
283
+ * On update, update the React component.
284
+ * To prevent unnecessary updates, the `update` option can be used.
285
+ */
286
+ update(node, decorations, innerDecorations) {
287
+ const rerenderComponent = (props) => {
288
+ this.decorationClasses.value = this.getDecorationClasses();
289
+ this.renderer.updateProps(props);
290
+ };
291
+ if (typeof this.options.update === "function") {
292
+ const oldNode = this.node;
293
+ const oldDecorations = this.decorations;
294
+ const oldInnerDecorations = this.innerDecorations;
295
+ this.node = node;
296
+ this.decorations = decorations;
297
+ this.innerDecorations = innerDecorations;
298
+ return this.options.update({
299
+ oldNode,
300
+ oldDecorations,
301
+ newNode: node,
302
+ newDecorations: decorations,
303
+ oldInnerDecorations,
304
+ innerDecorations,
305
+ updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
306
+ });
397
307
  }
398
- getDecorationClasses() {
399
- return (this.decorations
400
- // @ts-ignore
401
- .map(item => item.type.attrs.class)
402
- .flat()
403
- .join(' '));
308
+ if (node.type !== this.node.type) {
309
+ return false;
404
310
  }
405
- destroy() {
406
- this.renderer.destroy();
407
- this.editor.off('selectionUpdate', this.handleSelectionUpdate);
311
+ if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
312
+ return true;
408
313
  }
409
- }
314
+ this.node = node;
315
+ this.decorations = decorations;
316
+ this.innerDecorations = innerDecorations;
317
+ rerenderComponent({ node, decorations, innerDecorations });
318
+ return true;
319
+ }
320
+ /**
321
+ * Select the node.
322
+ * Add the `selected` prop and the `ProseMirror-selectednode` class.
323
+ */
324
+ selectNode() {
325
+ this.renderer.updateProps({
326
+ selected: true
327
+ });
328
+ this.renderer.element.classList.add("ProseMirror-selectednode");
329
+ }
330
+ /**
331
+ * Deselect the node.
332
+ * Remove the `selected` prop and the `ProseMirror-selectednode` class.
333
+ */
334
+ deselectNode() {
335
+ this.renderer.updateProps({
336
+ selected: false
337
+ });
338
+ this.renderer.element.classList.remove("ProseMirror-selectednode");
339
+ }
340
+ getDecorationClasses() {
341
+ return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
342
+ }
343
+ destroy() {
344
+ this.renderer.destroy();
345
+ this.editor.off("selectionUpdate", this.handleSelectionUpdate);
346
+ }
347
+ };
410
348
  function VueNodeViewRenderer(component, options) {
411
- return props => {
412
- // try to get the parent component
413
- // this is important for vue devtools to show the component hierarchy correctly
414
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
415
- if (!props.editor.contentComponent) {
416
- return {};
417
- }
418
- return new VueNodeView(component, props, options);
419
- };
349
+ return (props) => {
350
+ if (!props.editor.contentComponent) {
351
+ return {};
352
+ }
353
+ return new VueNodeView(component, props, options);
354
+ };
420
355
  }
421
356
 
422
- exports.BubbleMenu = BubbleMenu;
423
- exports.Editor = Editor;
424
- exports.EditorContent = EditorContent;
425
- exports.FloatingMenu = FloatingMenu;
426
- exports.NodeViewContent = NodeViewContent;
427
- exports.NodeViewWrapper = NodeViewWrapper;
428
- exports.VueNodeViewRenderer = VueNodeViewRenderer;
429
- exports.VueRenderer = VueRenderer;
430
- exports.nodeViewProps = nodeViewProps;
431
- Object.keys(core).forEach(function (k) {
432
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
433
- enumerable: true,
434
- get: function () { return core[k]; }
435
- });
357
+ // src/index.ts
358
+ __reExport(index_exports, require("@tiptap/core"), module.exports);
359
+ // Annotate the CommonJS export names for ESM import in node:
360
+ 0 && (module.exports = {
361
+ Editor,
362
+ EditorContent,
363
+ NodeViewContent,
364
+ NodeViewWrapper,
365
+ VueNodeViewRenderer,
366
+ VueRenderer,
367
+ nodeViewProps,
368
+ ...require("@tiptap/core")
436
369
  });
437
- //# sourceMappingURL=index.cjs.map
370
+ //# sourceMappingURL=index.cjs.map