@tiptap/vue-2 3.4.1 → 3.4.3
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/menus/index.cjs +25 -4
- package/dist/menus/index.cjs.map +1 -1
- package/dist/menus/index.d.cts +15 -1
- package/dist/menus/index.d.ts +15 -1
- package/dist/menus/index.js +25 -4
- package/dist/menus/index.js.map +1 -1
- package/package.json +7 -7
- package/src/menus/BubbleMenu.ts +2 -0
package/dist/menus/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/core';
|
|
2
|
-
import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
|
|
2
|
+
import { VirtualElement, offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
|
|
3
3
|
import { PluginKey, EditorState } from '@tiptap/pm/state';
|
|
4
4
|
import { EditorView } from '@tiptap/pm/view';
|
|
5
5
|
import Vue, { Component } from 'vue';
|
|
@@ -57,6 +57,13 @@ interface BubbleMenuPluginProps {
|
|
|
57
57
|
* @default null
|
|
58
58
|
*/
|
|
59
59
|
appendTo?: HTMLElement;
|
|
60
|
+
/**
|
|
61
|
+
* A function that returns the virtual element for the menu.
|
|
62
|
+
* This is useful when the menu needs to be positioned relative to a specific DOM element.
|
|
63
|
+
* @type {() => VirtualElement | null}
|
|
64
|
+
* @default Position based on the selection.
|
|
65
|
+
*/
|
|
66
|
+
getReferencedVirtualElement?: () => VirtualElement | null;
|
|
60
67
|
/**
|
|
61
68
|
* The options for the bubble menu. Those are passed to Floating UI and include options for the placement, offset, flip, shift, arrow, size, autoPlacement,
|
|
62
69
|
* hide, and inline middlewares.
|
|
@@ -78,6 +85,12 @@ interface BubbleMenuPluginProps {
|
|
|
78
85
|
onHide?: () => void;
|
|
79
86
|
onUpdate?: () => void;
|
|
80
87
|
onDestroy?: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* The scrollable element that should be listened to when updating the position of the bubble menu.
|
|
90
|
+
* If not provided, the window will be used.
|
|
91
|
+
* @type {HTMLElement | Window}
|
|
92
|
+
*/
|
|
93
|
+
scrollTarget?: HTMLElement | Window;
|
|
81
94
|
};
|
|
82
95
|
}
|
|
83
96
|
|
|
@@ -87,6 +100,7 @@ interface BubbleMenuInterface extends Vue {
|
|
|
87
100
|
updateDelay: BubbleMenuPluginProps['updateDelay'];
|
|
88
101
|
resizeDelay: BubbleMenuPluginProps['resizeDelay'];
|
|
89
102
|
shouldShow: BubbleMenuPluginProps['shouldShow'];
|
|
103
|
+
getReferencedVirtualElement: BubbleMenuPluginProps['getReferencedVirtualElement'];
|
|
90
104
|
options: BubbleMenuPluginProps['options'];
|
|
91
105
|
}
|
|
92
106
|
declare const BubbleMenu: Component;
|
package/dist/menus/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/core';
|
|
2
|
-
import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
|
|
2
|
+
import { VirtualElement, offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
|
|
3
3
|
import { PluginKey, EditorState } from '@tiptap/pm/state';
|
|
4
4
|
import { EditorView } from '@tiptap/pm/view';
|
|
5
5
|
import Vue, { Component } from 'vue';
|
|
@@ -57,6 +57,13 @@ interface BubbleMenuPluginProps {
|
|
|
57
57
|
* @default null
|
|
58
58
|
*/
|
|
59
59
|
appendTo?: HTMLElement;
|
|
60
|
+
/**
|
|
61
|
+
* A function that returns the virtual element for the menu.
|
|
62
|
+
* This is useful when the menu needs to be positioned relative to a specific DOM element.
|
|
63
|
+
* @type {() => VirtualElement | null}
|
|
64
|
+
* @default Position based on the selection.
|
|
65
|
+
*/
|
|
66
|
+
getReferencedVirtualElement?: () => VirtualElement | null;
|
|
60
67
|
/**
|
|
61
68
|
* The options for the bubble menu. Those are passed to Floating UI and include options for the placement, offset, flip, shift, arrow, size, autoPlacement,
|
|
62
69
|
* hide, and inline middlewares.
|
|
@@ -78,6 +85,12 @@ interface BubbleMenuPluginProps {
|
|
|
78
85
|
onHide?: () => void;
|
|
79
86
|
onUpdate?: () => void;
|
|
80
87
|
onDestroy?: () => void;
|
|
88
|
+
/**
|
|
89
|
+
* The scrollable element that should be listened to when updating the position of the bubble menu.
|
|
90
|
+
* If not provided, the window will be used.
|
|
91
|
+
* @type {HTMLElement | Window}
|
|
92
|
+
*/
|
|
93
|
+
scrollTarget?: HTMLElement | Window;
|
|
81
94
|
};
|
|
82
95
|
}
|
|
83
96
|
|
|
@@ -87,6 +100,7 @@ interface BubbleMenuInterface extends Vue {
|
|
|
87
100
|
updateDelay: BubbleMenuPluginProps['updateDelay'];
|
|
88
101
|
resizeDelay: BubbleMenuPluginProps['resizeDelay'];
|
|
89
102
|
shouldShow: BubbleMenuPluginProps['shouldShow'];
|
|
103
|
+
getReferencedVirtualElement: BubbleMenuPluginProps['getReferencedVirtualElement'];
|
|
90
104
|
options: BubbleMenuPluginProps['options'];
|
|
91
105
|
}
|
|
92
106
|
declare const BubbleMenu: Component;
|
package/dist/menus/index.js
CHANGED
|
@@ -1608,10 +1608,12 @@ var BubbleMenuView = class {
|
|
|
1608
1608
|
resizeDelay = 60,
|
|
1609
1609
|
shouldShow,
|
|
1610
1610
|
appendTo,
|
|
1611
|
+
getReferencedVirtualElement,
|
|
1611
1612
|
options
|
|
1612
1613
|
}) {
|
|
1613
1614
|
this.preventHide = false;
|
|
1614
1615
|
this.isVisible = false;
|
|
1616
|
+
this.scrollTarget = window;
|
|
1615
1617
|
this.floatingUIOptions = {
|
|
1616
1618
|
strategy: "absolute",
|
|
1617
1619
|
placement: "top",
|
|
@@ -1657,12 +1659,12 @@ var BubbleMenuView = class {
|
|
|
1657
1659
|
setTimeout(() => this.update(this.editor.view));
|
|
1658
1660
|
};
|
|
1659
1661
|
this.blurHandler = ({ event }) => {
|
|
1660
|
-
var
|
|
1662
|
+
var _a2;
|
|
1661
1663
|
if (this.preventHide) {
|
|
1662
1664
|
this.preventHide = false;
|
|
1663
1665
|
return;
|
|
1664
1666
|
}
|
|
1665
|
-
if ((event == null ? void 0 : event.relatedTarget) && ((
|
|
1667
|
+
if ((event == null ? void 0 : event.relatedTarget) && ((_a2 = this.element.parentNode) == null ? void 0 : _a2.contains(event.relatedTarget))) {
|
|
1666
1668
|
return;
|
|
1667
1669
|
}
|
|
1668
1670
|
if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
|
|
@@ -1697,12 +1699,15 @@ var BubbleMenuView = class {
|
|
|
1697
1699
|
this.updatePosition();
|
|
1698
1700
|
this.show();
|
|
1699
1701
|
};
|
|
1702
|
+
var _a;
|
|
1700
1703
|
this.editor = editor;
|
|
1701
1704
|
this.element = element;
|
|
1702
1705
|
this.view = view;
|
|
1703
1706
|
this.updateDelay = updateDelay;
|
|
1704
1707
|
this.resizeDelay = resizeDelay;
|
|
1705
1708
|
this.appendTo = appendTo;
|
|
1709
|
+
this.scrollTarget = (_a = options == null ? void 0 : options.scrollTarget) != null ? _a : window;
|
|
1710
|
+
this.getReferencedVirtualElement = getReferencedVirtualElement;
|
|
1706
1711
|
this.floatingUIOptions = {
|
|
1707
1712
|
...this.floatingUIOptions,
|
|
1708
1713
|
...options
|
|
@@ -1716,6 +1721,7 @@ var BubbleMenuView = class {
|
|
|
1716
1721
|
this.editor.on("focus", this.focusHandler);
|
|
1717
1722
|
this.editor.on("blur", this.blurHandler);
|
|
1718
1723
|
window.addEventListener("resize", this.resizeHandler);
|
|
1724
|
+
this.scrollTarget.addEventListener("scroll", this.resizeHandler);
|
|
1719
1725
|
this.update(view, view.state);
|
|
1720
1726
|
if (this.getShouldShow()) {
|
|
1721
1727
|
this.show();
|
|
@@ -1759,8 +1765,13 @@ var BubbleMenuView = class {
|
|
|
1759
1765
|
}
|
|
1760
1766
|
return middlewares;
|
|
1761
1767
|
}
|
|
1762
|
-
|
|
1768
|
+
get virtualElement() {
|
|
1769
|
+
var _a;
|
|
1763
1770
|
const { selection } = this.editor.state;
|
|
1771
|
+
const referencedVirtualElement = (_a = this.getReferencedVirtualElement) == null ? void 0 : _a.call(this);
|
|
1772
|
+
if (referencedVirtualElement) {
|
|
1773
|
+
return referencedVirtualElement;
|
|
1774
|
+
}
|
|
1764
1775
|
const domRect = posToDOMRect(this.view, selection.from, selection.to);
|
|
1765
1776
|
let virtualElement = {
|
|
1766
1777
|
getBoundingClientRect: () => domRect,
|
|
@@ -1797,6 +1808,13 @@ var BubbleMenuView = class {
|
|
|
1797
1808
|
getClientRects: () => [clientRect]
|
|
1798
1809
|
};
|
|
1799
1810
|
}
|
|
1811
|
+
return virtualElement;
|
|
1812
|
+
}
|
|
1813
|
+
updatePosition() {
|
|
1814
|
+
const virtualElement = this.virtualElement;
|
|
1815
|
+
if (!virtualElement) {
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1800
1818
|
computePosition2(virtualElement, this.element, {
|
|
1801
1819
|
placement: this.floatingUIOptions.placement,
|
|
1802
1820
|
strategy: this.floatingUIOptions.strategy,
|
|
@@ -1870,6 +1888,7 @@ var BubbleMenuView = class {
|
|
|
1870
1888
|
this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
|
|
1871
1889
|
this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
|
|
1872
1890
|
window.removeEventListener("resize", this.resizeHandler);
|
|
1891
|
+
this.scrollTarget.removeEventListener("scroll", this.resizeHandler);
|
|
1873
1892
|
this.editor.off("focus", this.focusHandler);
|
|
1874
1893
|
this.editor.off("blur", this.blurHandler);
|
|
1875
1894
|
if (this.floatingUIOptions.onDestroy) {
|
|
@@ -1906,6 +1925,7 @@ var BubbleMenu = Extension.create({
|
|
|
1906
1925
|
updateDelay: this.options.updateDelay,
|
|
1907
1926
|
options: this.options.options,
|
|
1908
1927
|
appendTo: this.options.appendTo,
|
|
1928
|
+
getReferencedVirtualElement: this.options.getReferencedVirtualElement,
|
|
1909
1929
|
shouldShow: this.options.shouldShow
|
|
1910
1930
|
})
|
|
1911
1931
|
];
|
|
@@ -1959,7 +1979,8 @@ var BubbleMenu2 = {
|
|
|
1959
1979
|
editor,
|
|
1960
1980
|
element: this.$el,
|
|
1961
1981
|
pluginKey: this.pluginKey,
|
|
1962
|
-
shouldShow: this.shouldShow
|
|
1982
|
+
shouldShow: this.shouldShow,
|
|
1983
|
+
getReferencedVirtualElement: this.getReferencedVirtualElement
|
|
1963
1984
|
})
|
|
1964
1985
|
);
|
|
1965
1986
|
});
|