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