@tiptap/vue-3 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 (48) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +562 -528
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +219 -0
  6. package/dist/index.d.ts +218 -10
  7. package/dist/index.js +526 -516
  8. package/dist/index.js.map +1 -1
  9. package/dist/menus/index.cjs +613 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +257 -0
  12. package/dist/menus/index.d.ts +257 -0
  13. package/dist/menus/index.js +605 -0
  14. package/dist/menus/index.js.map +1 -0
  15. package/package.json +27 -16
  16. package/src/Editor.ts +6 -11
  17. package/src/EditorContent.ts +10 -20
  18. package/src/VueMarkViewRenderer.ts +114 -0
  19. package/src/VueNodeViewRenderer.ts +19 -30
  20. package/src/VueRenderer.ts +10 -11
  21. package/src/index.ts +1 -2
  22. package/src/menus/BubbleMenu.ts +78 -0
  23. package/src/menus/FloatingMenu.ts +68 -0
  24. package/src/menus/index.ts +2 -0
  25. package/src/useEditor.ts +1 -1
  26. package/dist/BubbleMenu.d.ts +0 -61
  27. package/dist/BubbleMenu.d.ts.map +0 -1
  28. package/dist/Editor.d.ts +0 -24
  29. package/dist/Editor.d.ts.map +0 -1
  30. package/dist/EditorContent.d.ts +0 -18
  31. package/dist/EditorContent.d.ts.map +0 -1
  32. package/dist/FloatingMenu.d.ts +0 -49
  33. package/dist/FloatingMenu.d.ts.map +0 -1
  34. package/dist/NodeViewContent.d.ts +0 -14
  35. package/dist/NodeViewContent.d.ts.map +0 -1
  36. package/dist/NodeViewWrapper.d.ts +0 -14
  37. package/dist/NodeViewWrapper.d.ts.map +0 -1
  38. package/dist/VueNodeViewRenderer.d.ts +0 -63
  39. package/dist/VueNodeViewRenderer.d.ts.map +0 -1
  40. package/dist/VueRenderer.d.ts +0 -37
  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 -570
  44. package/dist/index.umd.js.map +0 -1
  45. package/dist/useEditor.d.ts +0 -4
  46. package/dist/useEditor.d.ts.map +0 -1
  47. package/src/BubbleMenu.ts +0 -71
  48. package/src/FloatingMenu.ts +0 -66
@@ -0,0 +1,605 @@
1
+ // ../extension-bubble-menu/dist/index.js
2
+ import { Extension } from "@tiptap/core";
3
+ import {
4
+ arrow,
5
+ autoPlacement,
6
+ computePosition,
7
+ flip,
8
+ hide,
9
+ inline,
10
+ offset,
11
+ shift,
12
+ size
13
+ } from "@floating-ui/dom";
14
+ import { isTextSelection, posToDOMRect } from "@tiptap/core";
15
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
16
+ var BubbleMenuView = class {
17
+ constructor({
18
+ editor,
19
+ element,
20
+ view,
21
+ updateDelay = 250,
22
+ resizeDelay = 60,
23
+ shouldShow,
24
+ options
25
+ }) {
26
+ this.preventHide = false;
27
+ this.floatingUIOptions = {
28
+ strategy: "absolute",
29
+ placement: "top",
30
+ offset: 8,
31
+ flip: {},
32
+ shift: {},
33
+ arrow: false,
34
+ size: false,
35
+ autoPlacement: false,
36
+ hide: false,
37
+ inline: false
38
+ };
39
+ this.shouldShow = ({ view: view2, state, from, to }) => {
40
+ const { doc, selection } = state;
41
+ const { empty } = selection;
42
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
43
+ const isChildOfMenu = this.element.contains(document.activeElement);
44
+ const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
45
+ if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
46
+ return false;
47
+ }
48
+ return true;
49
+ };
50
+ this.mousedownHandler = () => {
51
+ this.preventHide = true;
52
+ };
53
+ this.dragstartHandler = () => {
54
+ this.hide();
55
+ };
56
+ this.focusHandler = () => {
57
+ setTimeout(() => this.update(this.editor.view));
58
+ };
59
+ this.blurHandler = ({ event }) => {
60
+ var _a;
61
+ if (this.preventHide) {
62
+ this.preventHide = false;
63
+ return;
64
+ }
65
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
66
+ return;
67
+ }
68
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
69
+ return;
70
+ }
71
+ this.hide();
72
+ };
73
+ this.handleDebouncedUpdate = (view2, oldState) => {
74
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
75
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
76
+ if (!selectionChanged && !docChanged) {
77
+ return;
78
+ }
79
+ if (this.updateDebounceTimer) {
80
+ clearTimeout(this.updateDebounceTimer);
81
+ }
82
+ this.updateDebounceTimer = window.setTimeout(() => {
83
+ this.updateHandler(view2, selectionChanged, docChanged, oldState);
84
+ }, this.updateDelay);
85
+ };
86
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
87
+ const { composing } = view2;
88
+ const isSame = !selectionChanged && !docChanged;
89
+ if (composing || isSame) {
90
+ return;
91
+ }
92
+ const shouldShow2 = this.getShouldShow(oldState);
93
+ if (!shouldShow2) {
94
+ this.hide();
95
+ return;
96
+ }
97
+ this.updatePosition();
98
+ this.show();
99
+ };
100
+ this.editor = editor;
101
+ this.element = element;
102
+ this.view = view;
103
+ this.updateDelay = updateDelay;
104
+ this.resizeDelay = resizeDelay;
105
+ this.floatingUIOptions = {
106
+ ...this.floatingUIOptions,
107
+ ...options
108
+ };
109
+ if (shouldShow) {
110
+ this.shouldShow = shouldShow;
111
+ }
112
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
113
+ this.view.dom.addEventListener("dragstart", this.dragstartHandler);
114
+ this.editor.on("focus", this.focusHandler);
115
+ this.editor.on("blur", this.blurHandler);
116
+ window.addEventListener("resize", () => {
117
+ if (this.resizeDebounceTimer) {
118
+ clearTimeout(this.resizeDebounceTimer);
119
+ }
120
+ this.resizeDebounceTimer = window.setTimeout(() => {
121
+ this.updatePosition();
122
+ }, this.resizeDelay);
123
+ });
124
+ this.update(view, view.state);
125
+ if (this.getShouldShow()) {
126
+ this.show();
127
+ }
128
+ }
129
+ get middlewares() {
130
+ const middlewares = [];
131
+ if (this.floatingUIOptions.flip) {
132
+ middlewares.push(flip(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
133
+ }
134
+ if (this.floatingUIOptions.shift) {
135
+ middlewares.push(
136
+ shift(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
137
+ );
138
+ }
139
+ if (this.floatingUIOptions.offset) {
140
+ middlewares.push(
141
+ offset(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
142
+ );
143
+ }
144
+ if (this.floatingUIOptions.arrow) {
145
+ middlewares.push(arrow(this.floatingUIOptions.arrow));
146
+ }
147
+ if (this.floatingUIOptions.size) {
148
+ middlewares.push(size(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
149
+ }
150
+ if (this.floatingUIOptions.autoPlacement) {
151
+ middlewares.push(
152
+ autoPlacement(
153
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
154
+ )
155
+ );
156
+ }
157
+ if (this.floatingUIOptions.hide) {
158
+ middlewares.push(hide(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
159
+ }
160
+ if (this.floatingUIOptions.inline) {
161
+ middlewares.push(
162
+ inline(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
163
+ );
164
+ }
165
+ return middlewares;
166
+ }
167
+ updatePosition() {
168
+ const { selection } = this.editor.state;
169
+ const virtualElement = {
170
+ getBoundingClientRect: () => posToDOMRect(this.view, selection.from, selection.to)
171
+ };
172
+ computePosition(virtualElement, this.element, {
173
+ placement: this.floatingUIOptions.placement,
174
+ strategy: this.floatingUIOptions.strategy,
175
+ middleware: this.middlewares
176
+ }).then(({ x, y, strategy }) => {
177
+ this.element.style.width = "max-content";
178
+ this.element.style.position = strategy;
179
+ this.element.style.left = `${x}px`;
180
+ this.element.style.top = `${y}px`;
181
+ });
182
+ }
183
+ update(view, oldState) {
184
+ const { state } = view;
185
+ const hasValidSelection = state.selection.from !== state.selection.to;
186
+ if (this.updateDelay > 0 && hasValidSelection) {
187
+ this.handleDebouncedUpdate(view, oldState);
188
+ return;
189
+ }
190
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
191
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
192
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
193
+ }
194
+ getShouldShow(oldState) {
195
+ var _a;
196
+ const { state } = this.view;
197
+ const { selection } = state;
198
+ const { ranges } = selection;
199
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
200
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
201
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
202
+ editor: this.editor,
203
+ element: this.element,
204
+ view: this.view,
205
+ state,
206
+ oldState,
207
+ from,
208
+ to
209
+ });
210
+ return shouldShow;
211
+ }
212
+ show() {
213
+ var _a;
214
+ this.element.style.visibility = "visible";
215
+ this.element.style.opacity = "1";
216
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
217
+ }
218
+ hide() {
219
+ this.element.style.visibility = "hidden";
220
+ this.element.style.opacity = "0";
221
+ this.element.remove();
222
+ }
223
+ destroy() {
224
+ this.hide();
225
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
226
+ this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
227
+ this.editor.off("focus", this.focusHandler);
228
+ this.editor.off("blur", this.blurHandler);
229
+ }
230
+ };
231
+ var BubbleMenuPlugin = (options) => {
232
+ return new Plugin({
233
+ key: typeof options.pluginKey === "string" ? new PluginKey(options.pluginKey) : options.pluginKey,
234
+ view: (view) => new BubbleMenuView({ view, ...options })
235
+ });
236
+ };
237
+ var BubbleMenu = Extension.create({
238
+ name: "bubbleMenu",
239
+ addOptions() {
240
+ return {
241
+ element: null,
242
+ pluginKey: "bubbleMenu",
243
+ updateDelay: void 0,
244
+ shouldShow: null
245
+ };
246
+ },
247
+ addProseMirrorPlugins() {
248
+ if (!this.options.element) {
249
+ return [];
250
+ }
251
+ return [
252
+ BubbleMenuPlugin({
253
+ pluginKey: this.options.pluginKey,
254
+ editor: this.editor,
255
+ element: this.options.element,
256
+ updateDelay: this.options.updateDelay,
257
+ shouldShow: this.options.shouldShow
258
+ })
259
+ ];
260
+ }
261
+ });
262
+
263
+ // src/menus/BubbleMenu.ts
264
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, Teleport } from "vue";
265
+ var BubbleMenu2 = defineComponent({
266
+ name: "BubbleMenu",
267
+ props: {
268
+ pluginKey: {
269
+ type: [String, Object],
270
+ default: "bubbleMenu"
271
+ },
272
+ editor: {
273
+ type: Object,
274
+ required: true
275
+ },
276
+ updateDelay: {
277
+ type: Number,
278
+ default: void 0
279
+ },
280
+ resizeDelay: {
281
+ type: Number,
282
+ default: void 0
283
+ },
284
+ options: {
285
+ type: Object,
286
+ default: () => ({})
287
+ },
288
+ shouldShow: {
289
+ type: Function,
290
+ default: null
291
+ }
292
+ },
293
+ setup(props, { slots }) {
294
+ const root = ref(null);
295
+ onMounted(() => {
296
+ const { editor, options, pluginKey, resizeDelay, shouldShow, updateDelay } = props;
297
+ if (!root.value) {
298
+ return;
299
+ }
300
+ root.value.style.visibility = "hidden";
301
+ root.value.style.position = "absolute";
302
+ root.value.remove();
303
+ editor.registerPlugin(
304
+ BubbleMenuPlugin({
305
+ editor,
306
+ element: root.value,
307
+ options,
308
+ pluginKey,
309
+ resizeDelay,
310
+ shouldShow,
311
+ updateDelay
312
+ })
313
+ );
314
+ });
315
+ onBeforeUnmount(() => {
316
+ const { pluginKey, editor } = props;
317
+ editor.unregisterPlugin(pluginKey);
318
+ });
319
+ return () => {
320
+ var _a;
321
+ return h(Teleport, { to: "body" }, h("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
322
+ };
323
+ }
324
+ });
325
+
326
+ // ../extension-floating-menu/dist/index.js
327
+ import { Extension as Extension2 } from "@tiptap/core";
328
+ import {
329
+ arrow as arrow2,
330
+ autoPlacement as autoPlacement2,
331
+ computePosition as computePosition2,
332
+ flip as flip2,
333
+ hide as hide2,
334
+ inline as inline2,
335
+ offset as offset2,
336
+ shift as shift2,
337
+ size as size2
338
+ } from "@floating-ui/dom";
339
+ import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
340
+ import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
341
+ var FloatingMenuView = class {
342
+ constructor({ editor, element, view, options, shouldShow }) {
343
+ this.preventHide = false;
344
+ this.shouldShow = ({ view: view2, state }) => {
345
+ const { selection } = state;
346
+ const { $anchor, empty } = selection;
347
+ const isRootDepth = $anchor.depth === 1;
348
+ const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
349
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
350
+ return false;
351
+ }
352
+ return true;
353
+ };
354
+ this.floatingUIOptions = {
355
+ strategy: "absolute",
356
+ placement: "right",
357
+ offset: 8,
358
+ flip: {},
359
+ shift: {},
360
+ arrow: false,
361
+ size: false,
362
+ autoPlacement: false,
363
+ hide: false,
364
+ inline: false
365
+ };
366
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
367
+ const { composing } = view2;
368
+ const isSame = !selectionChanged && !docChanged;
369
+ if (composing || isSame) {
370
+ return;
371
+ }
372
+ const shouldShow2 = this.getShouldShow(oldState);
373
+ if (!shouldShow2) {
374
+ this.hide();
375
+ return;
376
+ }
377
+ this.updatePosition();
378
+ this.show();
379
+ };
380
+ this.mousedownHandler = () => {
381
+ this.preventHide = true;
382
+ };
383
+ this.focusHandler = () => {
384
+ setTimeout(() => this.update(this.editor.view));
385
+ };
386
+ this.blurHandler = ({ event }) => {
387
+ var _a;
388
+ if (this.preventHide) {
389
+ this.preventHide = false;
390
+ return;
391
+ }
392
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
393
+ return;
394
+ }
395
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
396
+ return;
397
+ }
398
+ this.hide();
399
+ };
400
+ this.editor = editor;
401
+ this.element = element;
402
+ this.view = view;
403
+ this.floatingUIOptions = {
404
+ ...this.floatingUIOptions,
405
+ ...options
406
+ };
407
+ if (shouldShow) {
408
+ this.shouldShow = shouldShow;
409
+ }
410
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
411
+ this.editor.on("focus", this.focusHandler);
412
+ this.editor.on("blur", this.blurHandler);
413
+ this.update(view, view.state);
414
+ if (this.getShouldShow()) {
415
+ this.show();
416
+ }
417
+ }
418
+ getTextContent(node) {
419
+ return getText(node, { textSerializers: getTextSerializersFromSchema(this.editor.schema) });
420
+ }
421
+ get middlewares() {
422
+ const middlewares = [];
423
+ if (this.floatingUIOptions.flip) {
424
+ middlewares.push(flip2(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
425
+ }
426
+ if (this.floatingUIOptions.shift) {
427
+ middlewares.push(
428
+ shift2(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
429
+ );
430
+ }
431
+ if (this.floatingUIOptions.offset) {
432
+ middlewares.push(
433
+ offset2(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
434
+ );
435
+ }
436
+ if (this.floatingUIOptions.arrow) {
437
+ middlewares.push(arrow2(this.floatingUIOptions.arrow));
438
+ }
439
+ if (this.floatingUIOptions.size) {
440
+ middlewares.push(size2(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
441
+ }
442
+ if (this.floatingUIOptions.autoPlacement) {
443
+ middlewares.push(
444
+ autoPlacement2(
445
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
446
+ )
447
+ );
448
+ }
449
+ if (this.floatingUIOptions.hide) {
450
+ middlewares.push(hide2(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
451
+ }
452
+ if (this.floatingUIOptions.inline) {
453
+ middlewares.push(
454
+ inline2(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
455
+ );
456
+ }
457
+ return middlewares;
458
+ }
459
+ getShouldShow(oldState) {
460
+ var _a;
461
+ const { state } = this.view;
462
+ const { selection } = state;
463
+ const { ranges } = selection;
464
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
465
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
466
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
467
+ editor: this.editor,
468
+ view: this.view,
469
+ state,
470
+ oldState,
471
+ from,
472
+ to
473
+ });
474
+ return shouldShow;
475
+ }
476
+ updatePosition() {
477
+ const { selection } = this.editor.state;
478
+ const virtualElement = {
479
+ getBoundingClientRect: () => posToDOMRect2(this.view, selection.from, selection.to)
480
+ };
481
+ computePosition2(virtualElement, this.element, {
482
+ placement: this.floatingUIOptions.placement,
483
+ strategy: this.floatingUIOptions.strategy,
484
+ middleware: this.middlewares
485
+ }).then(({ x, y, strategy }) => {
486
+ this.element.style.width = "max-content";
487
+ this.element.style.position = strategy;
488
+ this.element.style.left = `${x}px`;
489
+ this.element.style.top = `${y}px`;
490
+ });
491
+ }
492
+ update(view, oldState) {
493
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
494
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
495
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
496
+ }
497
+ show() {
498
+ var _a;
499
+ this.element.style.visibility = "visible";
500
+ this.element.style.opacity = "1";
501
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
502
+ }
503
+ hide() {
504
+ this.element.style.visibility = "hidden";
505
+ this.element.style.opacity = "0";
506
+ this.element.remove();
507
+ }
508
+ destroy() {
509
+ this.hide();
510
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
511
+ this.editor.off("focus", this.focusHandler);
512
+ this.editor.off("blur", this.blurHandler);
513
+ }
514
+ };
515
+ var FloatingMenuPlugin = (options) => {
516
+ return new Plugin2({
517
+ key: typeof options.pluginKey === "string" ? new PluginKey2(options.pluginKey) : options.pluginKey,
518
+ view: (view) => new FloatingMenuView({ view, ...options })
519
+ });
520
+ };
521
+ var FloatingMenu = Extension2.create({
522
+ name: "floatingMenu",
523
+ addOptions() {
524
+ return {
525
+ element: null,
526
+ options: {},
527
+ pluginKey: "floatingMenu",
528
+ shouldShow: null
529
+ };
530
+ },
531
+ addProseMirrorPlugins() {
532
+ if (!this.options.element) {
533
+ return [];
534
+ }
535
+ return [
536
+ FloatingMenuPlugin({
537
+ pluginKey: this.options.pluginKey,
538
+ editor: this.editor,
539
+ element: this.options.element,
540
+ options: this.options.options,
541
+ shouldShow: this.options.shouldShow
542
+ })
543
+ ];
544
+ }
545
+ });
546
+
547
+ // src/menus/FloatingMenu.ts
548
+ import { defineComponent as defineComponent2, h as h2, onBeforeUnmount as onBeforeUnmount2, onMounted as onMounted2, ref as ref2, Teleport as Teleport2 } from "vue";
549
+ var FloatingMenu2 = defineComponent2({
550
+ name: "FloatingMenu",
551
+ props: {
552
+ pluginKey: {
553
+ // TODO: TypeScript breaks :(
554
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
555
+ type: null,
556
+ default: "floatingMenu"
557
+ },
558
+ editor: {
559
+ type: Object,
560
+ required: true
561
+ },
562
+ options: {
563
+ type: Object,
564
+ default: () => ({})
565
+ },
566
+ shouldShow: {
567
+ type: Function,
568
+ default: null
569
+ }
570
+ },
571
+ setup(props, { slots }) {
572
+ const root = ref2(null);
573
+ onMounted2(() => {
574
+ const { pluginKey, editor, options, shouldShow } = props;
575
+ if (!root.value) {
576
+ return;
577
+ }
578
+ root.value.style.visibility = "hidden";
579
+ root.value.style.position = "absolute";
580
+ root.value.remove();
581
+ editor.registerPlugin(
582
+ FloatingMenuPlugin({
583
+ pluginKey,
584
+ editor,
585
+ element: root.value,
586
+ options,
587
+ shouldShow
588
+ })
589
+ );
590
+ });
591
+ onBeforeUnmount2(() => {
592
+ const { pluginKey, editor } = props;
593
+ editor.unregisterPlugin(pluginKey);
594
+ });
595
+ return () => {
596
+ var _a;
597
+ return h2(Teleport2, { to: "body" }, h2("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
598
+ };
599
+ }
600
+ });
601
+ export {
602
+ BubbleMenu2 as BubbleMenu,
603
+ FloatingMenu2 as FloatingMenu
604
+ };
605
+ //# sourceMappingURL=index.js.map