@tiptap/vue-3 2.0.0-beta.213 → 2.0.0-beta.215

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.
package/dist/index.cjs CHANGED
@@ -1,523 +1,476 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/BubbleMenu.ts
2
- var _extensionbubblemenu = require('@tiptap/extension-bubble-menu');
3
-
4
-
5
-
6
-
7
-
8
-
9
- var _vue = require('vue');
10
- var BubbleMenu = _vue.defineComponent.call(void 0, {
11
- name: "BubbleMenu",
12
- props: {
13
- pluginKey: {
14
- type: null,
15
- default: "bubbleMenu"
16
- },
17
- editor: {
18
- type: Object,
19
- required: true
20
- },
21
- updateDelay: {
22
- type: Number,
23
- default: void 0
24
- },
25
- tippyOptions: {
26
- type: Object,
27
- default: () => ({})
28
- },
29
- shouldShow: {
30
- type: Function,
31
- default: null
32
- }
33
- },
34
- setup(props, { slots }) {
35
- const root = _vue.ref.call(void 0, null);
36
- _vue.onMounted.call(void 0, () => {
37
- const {
38
- updateDelay,
39
- editor,
40
- pluginKey,
41
- shouldShow,
42
- tippyOptions
43
- } = props;
44
- editor.registerPlugin(_extensionbubblemenu.BubbleMenuPlugin.call(void 0, {
45
- updateDelay,
46
- editor,
47
- element: root.value,
48
- pluginKey,
49
- shouldShow,
50
- tippyOptions
51
- }));
52
- });
53
- _vue.onBeforeUnmount.call(void 0, () => {
54
- const { pluginKey, editor } = props;
55
- editor.unregisterPlugin(pluginKey);
56
- });
57
- return () => {
58
- var _a;
59
- return _vue.h.call(void 0, "div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots));
60
- };
61
- }
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
6
+ var vue = require('vue');
7
+ var core = require('@tiptap/core');
8
+ var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
9
+
10
+ const BubbleMenu = vue.defineComponent({
11
+ name: 'BubbleMenu',
12
+ props: {
13
+ pluginKey: {
14
+ // TODO: TypeScript breaks :(
15
+ // type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
16
+ type: null,
17
+ default: 'bubbleMenu',
18
+ },
19
+ editor: {
20
+ type: Object,
21
+ required: true,
22
+ },
23
+ updateDelay: {
24
+ type: Number,
25
+ default: undefined,
26
+ },
27
+ tippyOptions: {
28
+ type: Object,
29
+ default: () => ({}),
30
+ },
31
+ shouldShow: {
32
+ type: Function,
33
+ default: null,
34
+ },
35
+ },
36
+ setup(props, { slots }) {
37
+ const root = vue.ref(null);
38
+ vue.onMounted(() => {
39
+ const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;
40
+ editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
41
+ updateDelay,
42
+ editor,
43
+ element: root.value,
44
+ pluginKey,
45
+ shouldShow,
46
+ tippyOptions,
47
+ }));
48
+ });
49
+ vue.onBeforeUnmount(() => {
50
+ const { pluginKey, editor } = props;
51
+ editor.unregisterPlugin(pluginKey);
52
+ });
53
+ return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
54
+ },
62
55
  });
63
56
 
64
- // src/Editor.ts
65
- var _core = require('@tiptap/core'); _createStarExport(_core);
66
-
67
-
68
-
69
-
70
-
71
- function useDebouncedRef(value) {
72
- return _vue.customRef.call(void 0, (track, trigger) => {
73
- return {
74
- get() {
75
- track();
76
- return value;
77
- },
78
- set(newValue) {
79
- value = newValue;
80
- requestAnimationFrame(() => {
81
- requestAnimationFrame(() => {
82
- trigger();
83
- });
84
- });
85
- }
86
- };
87
- });
57
+ function useDebouncedRef(value) {
58
+ return vue.customRef((track, trigger) => {
59
+ return {
60
+ get() {
61
+ track();
62
+ return value;
63
+ },
64
+ set(newValue) {
65
+ // update state
66
+ value = newValue;
67
+ // update view as soon as possible
68
+ requestAnimationFrame(() => {
69
+ requestAnimationFrame(() => {
70
+ trigger();
71
+ });
72
+ });
73
+ },
74
+ };
75
+ });
76
+ }
77
+ class Editor extends core.Editor {
78
+ constructor(options = {}) {
79
+ super(options);
80
+ this.vueRenderers = vue.reactive(new Map());
81
+ this.contentComponent = null;
82
+ this.reactiveState = useDebouncedRef(this.view.state);
83
+ this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
84
+ this.on('transaction', () => {
85
+ this.reactiveState.value = this.view.state;
86
+ this.reactiveExtensionStorage.value = this.extensionStorage;
87
+ });
88
+ return vue.markRaw(this); // eslint-disable-line
89
+ }
90
+ get state() {
91
+ return this.reactiveState ? this.reactiveState.value : this.view.state;
92
+ }
93
+ get storage() {
94
+ return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
95
+ }
96
+ /**
97
+ * Register a ProseMirror plugin.
98
+ */
99
+ registerPlugin(plugin, handlePlugins) {
100
+ super.registerPlugin(plugin, handlePlugins);
101
+ this.reactiveState.value = this.view.state;
102
+ }
103
+ /**
104
+ * Unregister a ProseMirror plugin.
105
+ */
106
+ unregisterPlugin(nameOrPluginKey) {
107
+ super.unregisterPlugin(nameOrPluginKey);
108
+ this.reactiveState.value = this.view.state;
109
+ }
88
110
  }
89
- var Editor = class extends _core.Editor {
90
- constructor(options = {}) {
91
- super(options);
92
- this.vueRenderers = _vue.reactive.call(void 0, /* @__PURE__ */ new Map());
93
- this.contentComponent = null;
94
- this.reactiveState = useDebouncedRef(this.view.state);
95
- this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
96
- this.on("transaction", () => {
97
- this.reactiveState.value = this.view.state;
98
- this.reactiveExtensionStorage.value = this.extensionStorage;
99
- });
100
- return _vue.markRaw.call(void 0, this);
101
- }
102
- get state() {
103
- return this.reactiveState ? this.reactiveState.value : this.view.state;
104
- }
105
- get storage() {
106
- return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
107
- }
108
- registerPlugin(plugin, handlePlugins) {
109
- super.registerPlugin(plugin, handlePlugins);
110
- this.reactiveState.value = this.view.state;
111
- }
112
- unregisterPlugin(nameOrPluginKey) {
113
- super.unregisterPlugin(nameOrPluginKey);
114
- this.reactiveState.value = this.view.state;
115
- }
116
- };
117
-
118
- // src/EditorContent.ts
119
-
120
-
121
111
 
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
- var EditorContent = _vue.defineComponent.call(void 0, {
131
- name: "EditorContent",
132
- props: {
133
- editor: {
134
- default: null,
135
- type: Object
136
- }
137
- },
138
- setup(props) {
139
- const rootEl = _vue.ref.call(void 0, );
140
- const instance = _vue.getCurrentInstance.call(void 0, );
141
- _vue.watchEffect.call(void 0, () => {
142
- const editor = props.editor;
143
- if (editor && editor.options.element && rootEl.value) {
144
- _vue.nextTick.call(void 0, () => {
145
- if (!rootEl.value || !editor.options.element.firstChild) {
146
- return;
147
- }
148
- const element = _vue.unref.call(void 0, rootEl.value);
149
- rootEl.value.append(...editor.options.element.childNodes);
150
- editor.contentComponent = instance.ctx._;
151
- editor.setOptions({
152
- element
153
- });
154
- editor.createNodeViews();
155
- });
156
- }
157
- });
158
- _vue.onBeforeUnmount.call(void 0, () => {
159
- const editor = props.editor;
160
- if (!editor) {
161
- return;
162
- }
163
- if (!editor.isDestroyed) {
164
- editor.view.setProps({
165
- nodeViews: {}
166
- });
167
- }
168
- editor.contentComponent = null;
169
- if (!editor.options.element.firstChild) {
170
- return;
171
- }
172
- const newElement = document.createElement("div");
173
- newElement.append(...editor.options.element.childNodes);
174
- editor.setOptions({
175
- element: newElement
176
- });
177
- });
178
- return { rootEl };
179
- },
180
- render() {
181
- const vueRenderers = [];
182
- if (this.editor) {
183
- this.editor.vueRenderers.forEach((vueRenderer) => {
184
- const node = _vue.h.call(void 0,
185
- _vue.Teleport,
186
- {
187
- to: vueRenderer.teleportElement,
188
- key: vueRenderer.id
189
- },
190
- _vue.h.call(void 0,
191
- vueRenderer.component,
192
- {
193
- ref: vueRenderer.id,
194
- ...vueRenderer.props
195
- }
196
- )
197
- );
198
- vueRenderers.push(node);
199
- });
200
- }
201
- return _vue.h.call(void 0,
202
- "div",
203
- {
204
- ref: (el) => {
205
- this.rootEl = el;
206
- }
207
- },
208
- ...vueRenderers
209
- );
210
- }
112
+ const EditorContent = vue.defineComponent({
113
+ name: 'EditorContent',
114
+ props: {
115
+ editor: {
116
+ default: null,
117
+ type: Object,
118
+ },
119
+ },
120
+ setup(props) {
121
+ const rootEl = vue.ref();
122
+ const instance = vue.getCurrentInstance();
123
+ vue.watchEffect(() => {
124
+ const editor = props.editor;
125
+ if (editor && editor.options.element && rootEl.value) {
126
+ vue.nextTick(() => {
127
+ if (!rootEl.value || !editor.options.element.firstChild) {
128
+ return;
129
+ }
130
+ const element = vue.unref(rootEl.value);
131
+ rootEl.value.append(...editor.options.element.childNodes);
132
+ // @ts-ignore
133
+ editor.contentComponent = instance.ctx._;
134
+ editor.setOptions({
135
+ element,
136
+ });
137
+ editor.createNodeViews();
138
+ });
139
+ }
140
+ });
141
+ vue.onBeforeUnmount(() => {
142
+ const editor = props.editor;
143
+ if (!editor) {
144
+ return;
145
+ }
146
+ // destroy nodeviews before vue removes dom element
147
+ if (!editor.isDestroyed) {
148
+ editor.view.setProps({
149
+ nodeViews: {},
150
+ });
151
+ }
152
+ editor.contentComponent = null;
153
+ if (!editor.options.element.firstChild) {
154
+ return;
155
+ }
156
+ const newElement = document.createElement('div');
157
+ newElement.append(...editor.options.element.childNodes);
158
+ editor.setOptions({
159
+ element: newElement,
160
+ });
161
+ });
162
+ return { rootEl };
163
+ },
164
+ render() {
165
+ const vueRenderers = [];
166
+ if (this.editor) {
167
+ this.editor.vueRenderers.forEach(vueRenderer => {
168
+ const node = vue.h(vue.Teleport, {
169
+ to: vueRenderer.teleportElement,
170
+ key: vueRenderer.id,
171
+ }, vue.h(vueRenderer.component, {
172
+ ref: vueRenderer.id,
173
+ ...vueRenderer.props,
174
+ }));
175
+ vueRenderers.push(node);
176
+ });
177
+ }
178
+ return vue.h('div', {
179
+ ref: (el) => { this.rootEl = el; },
180
+ }, ...vueRenderers);
181
+ },
211
182
  });
212
183
 
213
- // src/FloatingMenu.ts
214
- var _extensionfloatingmenu = require('@tiptap/extension-floating-menu');
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
- var FloatingMenu = _vue.defineComponent.call(void 0, {
223
- name: "FloatingMenu",
224
- props: {
225
- pluginKey: {
226
- type: null,
227
- default: "floatingMenu"
228
- },
229
- editor: {
230
- type: Object,
231
- required: true
232
- },
233
- tippyOptions: {
234
- type: Object,
235
- default: () => ({})
236
- },
237
- shouldShow: {
238
- type: Function,
239
- default: null
240
- }
241
- },
242
- setup(props, { slots }) {
243
- const root = _vue.ref.call(void 0, null);
244
- _vue.onMounted.call(void 0, () => {
245
- const {
246
- pluginKey,
247
- editor,
248
- tippyOptions,
249
- shouldShow
250
- } = props;
251
- editor.registerPlugin(_extensionfloatingmenu.FloatingMenuPlugin.call(void 0, {
252
- pluginKey,
253
- editor,
254
- element: root.value,
255
- tippyOptions,
256
- shouldShow
257
- }));
258
- });
259
- _vue.onBeforeUnmount.call(void 0, () => {
260
- const { pluginKey, editor } = props;
261
- editor.unregisterPlugin(pluginKey);
262
- });
263
- return () => {
264
- var _a;
265
- return _vue.h.call(void 0, "div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots));
266
- };
267
- }
184
+ const FloatingMenu = vue.defineComponent({
185
+ name: 'FloatingMenu',
186
+ props: {
187
+ pluginKey: {
188
+ // TODO: TypeScript breaks :(
189
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
190
+ type: null,
191
+ default: 'floatingMenu',
192
+ },
193
+ editor: {
194
+ type: Object,
195
+ required: true,
196
+ },
197
+ tippyOptions: {
198
+ type: Object,
199
+ default: () => ({}),
200
+ },
201
+ shouldShow: {
202
+ type: Function,
203
+ default: null,
204
+ },
205
+ },
206
+ setup(props, { slots }) {
207
+ const root = vue.ref(null);
208
+ vue.onMounted(() => {
209
+ const { pluginKey, editor, tippyOptions, shouldShow, } = props;
210
+ editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
211
+ pluginKey,
212
+ editor,
213
+ element: root.value,
214
+ tippyOptions,
215
+ shouldShow,
216
+ }));
217
+ });
218
+ vue.onBeforeUnmount(() => {
219
+ const { pluginKey, editor } = props;
220
+ editor.unregisterPlugin(pluginKey);
221
+ });
222
+ return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
223
+ },
268
224
  });
269
225
 
270
- // src/NodeViewContent.ts
271
-
272
- var NodeViewContent = _vue.defineComponent.call(void 0, {
273
- props: {
274
- as: {
275
- type: String,
276
- default: "div"
277
- }
278
- },
279
- render() {
280
- return _vue.h.call(void 0, this.as, {
281
- style: {
282
- whiteSpace: "pre-wrap"
283
- },
284
- "data-node-view-content": ""
285
- });
286
- }
226
+ const NodeViewContent = vue.defineComponent({
227
+ props: {
228
+ as: {
229
+ type: String,
230
+ default: 'div',
231
+ },
232
+ },
233
+ render() {
234
+ return vue.h(this.as, {
235
+ style: {
236
+ whiteSpace: 'pre-wrap',
237
+ },
238
+ 'data-node-view-content': '',
239
+ });
240
+ },
287
241
  });
288
242
 
289
- // src/NodeViewWrapper.ts
290
-
291
- var NodeViewWrapper = _vue.defineComponent.call(void 0, {
292
- props: {
293
- as: {
294
- type: String,
295
- default: "div"
296
- }
297
- },
298
- inject: ["onDragStart", "decorationClasses"],
299
- render() {
300
- var _a, _b;
301
- return _vue.h.call(void 0,
302
- this.as,
303
- {
304
- class: this.decorationClasses,
305
- style: {
306
- whiteSpace: "normal"
307
- },
308
- "data-node-view-wrapper": "",
309
- onDragstart: this.onDragStart
310
- },
311
- (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)
312
- );
313
- }
243
+ const NodeViewWrapper = vue.defineComponent({
244
+ props: {
245
+ as: {
246
+ type: String,
247
+ default: 'div',
248
+ },
249
+ },
250
+ inject: ['onDragStart', 'decorationClasses'],
251
+ render() {
252
+ var _a, _b;
253
+ return vue.h(this.as, {
254
+ // @ts-ignore
255
+ class: this.decorationClasses,
256
+ style: {
257
+ whiteSpace: 'normal',
258
+ },
259
+ 'data-node-view-wrapper': '',
260
+ // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
261
+ onDragstart: this.onDragStart,
262
+ }, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
263
+ },
314
264
  });
315
265
 
316
- // src/useEditor.ts
317
-
318
- var useEditor = (options = {}) => {
319
- const editor = _vue.shallowRef.call(void 0, );
320
- _vue.onMounted.call(void 0, () => {
321
- editor.value = new Editor(options);
322
- });
323
- _vue.onBeforeUnmount.call(void 0, () => {
324
- var _a;
325
- (_a = editor.value) == null ? void 0 : _a.destroy();
326
- });
327
- return editor;
328
- };
329
-
330
- // src/VueNodeViewRenderer.ts
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
- // src/VueRenderer.ts
341
-
342
- var VueRenderer = class {
343
- constructor(component, { props = {}, editor }) {
344
- this.id = Math.floor(Math.random() * 4294967295).toString();
345
- this.editor = editor;
346
- this.component = _vue.markRaw.call(void 0, component);
347
- this.teleportElement = document.createElement("div");
348
- this.element = this.teleportElement;
349
- this.props = _vue.reactive.call(void 0, props);
350
- this.editor.vueRenderers.set(this.id, this);
351
- if (this.editor.contentComponent) {
352
- this.editor.contentComponent.update();
353
- if (this.teleportElement.children.length !== 1) {
354
- throw Error("VueRenderer doesn\u2019t support multiple child elements.");
355
- }
356
- this.element = this.teleportElement.firstElementChild;
357
- }
358
- }
359
- get ref() {
360
- var _a;
361
- return (_a = this.editor.contentComponent) == null ? void 0 : _a.refs[this.id];
362
- }
363
- updateProps(props = {}) {
364
- Object.entries(props).forEach(([key, value]) => {
365
- this.props[key] = value;
366
- });
367
- }
368
- destroy() {
369
- this.editor.vueRenderers.delete(this.id);
370
- }
266
+ const useEditor = (options = {}) => {
267
+ const editor = vue.shallowRef();
268
+ vue.onMounted(() => {
269
+ editor.value = new Editor(options);
270
+ });
271
+ vue.onBeforeUnmount(() => {
272
+ var _a;
273
+ (_a = editor.value) === null || _a === void 0 ? void 0 : _a.destroy();
274
+ });
275
+ return editor;
371
276
  };
372
277
 
373
- // src/VueNodeViewRenderer.ts
374
- var nodeViewProps = {
375
- editor: {
376
- type: Object,
377
- required: true
378
- },
379
- node: {
380
- type: Object,
381
- required: true
382
- },
383
- decorations: {
384
- type: Object,
385
- required: true
386
- },
387
- selected: {
388
- type: Boolean,
389
- required: true
390
- },
391
- extension: {
392
- type: Object,
393
- required: true
394
- },
395
- getPos: {
396
- type: Function,
397
- required: true
398
- },
399
- updateAttributes: {
400
- type: Function,
401
- required: true
402
- },
403
- deleteNode: {
404
- type: Function,
405
- required: true
406
- }
407
- };
408
- var VueNodeView = class extends _core.NodeView {
409
- mount() {
410
- const props = {
411
- editor: this.editor,
412
- node: this.node,
413
- decorations: this.decorations,
414
- selected: false,
415
- extension: this.extension,
416
- getPos: () => this.getPos(),
417
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
418
- deleteNode: () => this.deleteNode()
419
- };
420
- const onDragStart = this.onDragStart.bind(this);
421
- this.decorationClasses = _vue.ref.call(void 0, this.getDecorationClasses());
422
- const extendedComponent = _vue.defineComponent.call(void 0, {
423
- extends: { ...this.component },
424
- props: Object.keys(props),
425
- template: this.component.template,
426
- setup: (reactiveProps) => {
427
- var _a, _b;
428
- _vue.provide.call(void 0, "onDragStart", onDragStart);
429
- _vue.provide.call(void 0, "decorationClasses", this.decorationClasses);
430
- return (_b = (_a = this.component).setup) == null ? void 0 : _b.call(_a, reactiveProps, {
431
- expose: () => void 0
432
- });
433
- },
434
- __scopeId: this.component.__scopeId,
435
- __cssModules: this.component.__cssModules
436
- });
437
- this.renderer = new VueRenderer(extendedComponent, {
438
- editor: this.editor,
439
- props
440
- });
441
- }
442
- get dom() {
443
- if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
444
- throw Error("Please use the NodeViewWrapper component for your node view.");
445
- }
446
- return this.renderer.element;
447
- }
448
- get contentDOM() {
449
- if (this.node.isLeaf) {
450
- return null;
451
- }
452
- const contentElement = this.dom.querySelector("[data-node-view-content]");
453
- return contentElement || this.dom;
454
- }
455
- update(node, decorations) {
456
- const updateProps = (props) => {
457
- this.decorationClasses.value = this.getDecorationClasses();
458
- this.renderer.updateProps(props);
459
- };
460
- if (typeof this.options.update === "function") {
461
- const oldNode = this.node;
462
- const oldDecorations = this.decorations;
463
- this.node = node;
464
- this.decorations = decorations;
465
- return this.options.update({
466
- oldNode,
467
- oldDecorations,
468
- newNode: node,
469
- newDecorations: decorations,
470
- updateProps: () => updateProps({ node, decorations })
471
- });
472
- }
473
- if (node.type !== this.node.type) {
474
- return false;
475
- }
476
- if (node === this.node && this.decorations === decorations) {
477
- return true;
478
- }
479
- this.node = node;
480
- this.decorations = decorations;
481
- updateProps({ node, decorations });
482
- return true;
483
- }
484
- selectNode() {
485
- this.renderer.updateProps({
486
- selected: true
487
- });
488
- }
489
- deselectNode() {
490
- this.renderer.updateProps({
491
- selected: false
492
- });
493
- }
494
- getDecorationClasses() {
495
- return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
496
- }
497
- destroy() {
498
- this.renderer.destroy();
499
- }
500
- };
501
- function VueNodeViewRenderer(component, options) {
502
- return (props) => {
503
- if (!props.editor.contentComponent) {
504
- return {};
505
- }
506
- return new VueNodeView(component, props, options);
507
- };
278
+ class VueRenderer {
279
+ constructor(component, { props = {}, editor }) {
280
+ this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
281
+ this.editor = editor;
282
+ this.component = vue.markRaw(component);
283
+ this.teleportElement = document.createElement('div');
284
+ this.element = this.teleportElement;
285
+ this.props = vue.reactive(props);
286
+ this.editor.vueRenderers.set(this.id, this);
287
+ if (this.editor.contentComponent) {
288
+ this.editor.contentComponent.update();
289
+ if (this.teleportElement.children.length !== 1) {
290
+ throw Error('VueRenderer doesn’t support multiple child elements.');
291
+ }
292
+ this.element = this.teleportElement.firstElementChild;
293
+ }
294
+ }
295
+ get ref() {
296
+ var _a;
297
+ return (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.refs[this.id];
298
+ }
299
+ updateProps(props = {}) {
300
+ Object
301
+ .entries(props)
302
+ .forEach(([key, value]) => {
303
+ this.props[key] = value;
304
+ });
305
+ }
306
+ destroy() {
307
+ this.editor.vueRenderers.delete(this.id);
308
+ }
508
309
  }
509
310
 
510
- // src/index.ts
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
311
+ const nodeViewProps = {
312
+ editor: {
313
+ type: Object,
314
+ required: true,
315
+ },
316
+ node: {
317
+ type: Object,
318
+ required: true,
319
+ },
320
+ decorations: {
321
+ type: Object,
322
+ required: true,
323
+ },
324
+ selected: {
325
+ type: Boolean,
326
+ required: true,
327
+ },
328
+ extension: {
329
+ type: Object,
330
+ required: true,
331
+ },
332
+ getPos: {
333
+ type: Function,
334
+ required: true,
335
+ },
336
+ updateAttributes: {
337
+ type: Function,
338
+ required: true,
339
+ },
340
+ deleteNode: {
341
+ type: Function,
342
+ required: true,
343
+ },
344
+ };
345
+ class VueNodeView extends core.NodeView {
346
+ mount() {
347
+ const props = {
348
+ editor: this.editor,
349
+ node: this.node,
350
+ decorations: this.decorations,
351
+ selected: false,
352
+ extension: this.extension,
353
+ getPos: () => this.getPos(),
354
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
355
+ deleteNode: () => this.deleteNode(),
356
+ };
357
+ const onDragStart = this.onDragStart.bind(this);
358
+ this.decorationClasses = vue.ref(this.getDecorationClasses());
359
+ const extendedComponent = vue.defineComponent({
360
+ extends: { ...this.component },
361
+ props: Object.keys(props),
362
+ template: this.component.template,
363
+ setup: reactiveProps => {
364
+ var _a, _b;
365
+ vue.provide('onDragStart', onDragStart);
366
+ vue.provide('decorationClasses', this.decorationClasses);
367
+ return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {
368
+ expose: () => undefined,
369
+ });
370
+ },
371
+ // add support for scoped styles
372
+ // @ts-ignore
373
+ // eslint-disable-next-line
374
+ __scopeId: this.component.__scopeId,
375
+ // add support for CSS Modules
376
+ // @ts-ignore
377
+ // eslint-disable-next-line
378
+ __cssModules: this.component.__cssModules,
379
+ });
380
+ this.renderer = new VueRenderer(extendedComponent, {
381
+ editor: this.editor,
382
+ props,
383
+ });
384
+ }
385
+ get dom() {
386
+ if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
387
+ throw Error('Please use the NodeViewWrapper component for your node view.');
388
+ }
389
+ return this.renderer.element;
390
+ }
391
+ get contentDOM() {
392
+ if (this.node.isLeaf) {
393
+ return null;
394
+ }
395
+ const contentElement = this.dom.querySelector('[data-node-view-content]');
396
+ return (contentElement || this.dom);
397
+ }
398
+ update(node, decorations) {
399
+ const updateProps = (props) => {
400
+ this.decorationClasses.value = this.getDecorationClasses();
401
+ this.renderer.updateProps(props);
402
+ };
403
+ if (typeof this.options.update === 'function') {
404
+ const oldNode = this.node;
405
+ const oldDecorations = this.decorations;
406
+ this.node = node;
407
+ this.decorations = decorations;
408
+ return this.options.update({
409
+ oldNode,
410
+ oldDecorations,
411
+ newNode: node,
412
+ newDecorations: decorations,
413
+ updateProps: () => updateProps({ node, decorations }),
414
+ });
415
+ }
416
+ if (node.type !== this.node.type) {
417
+ return false;
418
+ }
419
+ if (node === this.node && this.decorations === decorations) {
420
+ return true;
421
+ }
422
+ this.node = node;
423
+ this.decorations = decorations;
424
+ updateProps({ node, decorations });
425
+ return true;
426
+ }
427
+ selectNode() {
428
+ this.renderer.updateProps({
429
+ selected: true,
430
+ });
431
+ }
432
+ deselectNode() {
433
+ this.renderer.updateProps({
434
+ selected: false,
435
+ });
436
+ }
437
+ getDecorationClasses() {
438
+ return (this.decorations
439
+ // @ts-ignore
440
+ .map(item => item.type.attrs.class)
441
+ .flat()
442
+ .join(' '));
443
+ }
444
+ destroy() {
445
+ this.renderer.destroy();
446
+ }
447
+ }
448
+ function VueNodeViewRenderer(component, options) {
449
+ return (props) => {
450
+ // try to get the parent component
451
+ // this is important for vue devtools to show the component hierarchy correctly
452
+ // maybe it’s `undefined` because <editor-content> isn’t rendered yet
453
+ if (!props.editor.contentComponent) {
454
+ return {};
455
+ }
456
+ return new VueNodeView(component, props, options);
457
+ };
458
+ }
522
459
 
523
- exports.BubbleMenu = BubbleMenu; exports.Editor = Editor; exports.EditorContent = EditorContent; exports.FloatingMenu = FloatingMenu; exports.NodeViewContent = NodeViewContent; exports.NodeViewWrapper = NodeViewWrapper; exports.VueNodeViewRenderer = VueNodeViewRenderer; exports.VueRenderer = VueRenderer; exports.nodeViewProps = nodeViewProps; exports.useEditor = useEditor;
460
+ exports.BubbleMenu = BubbleMenu;
461
+ exports.Editor = Editor;
462
+ exports.EditorContent = EditorContent;
463
+ exports.FloatingMenu = FloatingMenu;
464
+ exports.NodeViewContent = NodeViewContent;
465
+ exports.NodeViewWrapper = NodeViewWrapper;
466
+ exports.VueNodeViewRenderer = VueNodeViewRenderer;
467
+ exports.VueRenderer = VueRenderer;
468
+ exports.nodeViewProps = nodeViewProps;
469
+ exports.useEditor = useEditor;
470
+ Object.keys(core).forEach(function (k) {
471
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
472
+ enumerable: true,
473
+ get: function () { return core[k]; }
474
+ });
475
+ });
476
+ //# sourceMappingURL=index.cjs.map