@tiptap/vue-2 3.0.0-beta.2 → 3.0.0-beta.21
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 +87 -10
- package/dist/menus/index.cjs.map +1 -1
- package/dist/menus/index.d.cts +8 -0
- package/dist/menus/index.d.ts +8 -0
- package/dist/menus/index.js +87 -10
- package/dist/menus/index.js.map +1 -1
- package/package.json +9 -9
package/dist/menus/index.cjs
CHANGED
|
@@ -1614,6 +1614,18 @@ var computePosition2 = (reference, floating, options) => {
|
|
|
1614
1614
|
// ../extension-bubble-menu/dist/index.js
|
|
1615
1615
|
var import_core3 = require("@tiptap/core");
|
|
1616
1616
|
var import_state = require("@tiptap/pm/state");
|
|
1617
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
1618
|
+
function combineDOMRects(rect1, rect2) {
|
|
1619
|
+
const top = Math.min(rect1.top, rect2.top);
|
|
1620
|
+
const bottom = Math.max(rect1.bottom, rect2.bottom);
|
|
1621
|
+
const left = Math.min(rect1.left, rect2.left);
|
|
1622
|
+
const right = Math.max(rect1.right, rect2.right);
|
|
1623
|
+
const width = right - left;
|
|
1624
|
+
const height = bottom - top;
|
|
1625
|
+
const x = left;
|
|
1626
|
+
const y = top;
|
|
1627
|
+
return new DOMRect(x, y, width, height);
|
|
1628
|
+
}
|
|
1617
1629
|
var BubbleMenuView = class {
|
|
1618
1630
|
constructor({
|
|
1619
1631
|
editor,
|
|
@@ -1625,6 +1637,7 @@ var BubbleMenuView = class {
|
|
|
1625
1637
|
options
|
|
1626
1638
|
}) {
|
|
1627
1639
|
this.preventHide = false;
|
|
1640
|
+
this.isVisible = false;
|
|
1628
1641
|
this.floatingUIOptions = {
|
|
1629
1642
|
strategy: "absolute",
|
|
1630
1643
|
placement: "top",
|
|
@@ -1635,7 +1648,11 @@ var BubbleMenuView = class {
|
|
|
1635
1648
|
size: false,
|
|
1636
1649
|
autoPlacement: false,
|
|
1637
1650
|
hide: false,
|
|
1638
|
-
inline: false
|
|
1651
|
+
inline: false,
|
|
1652
|
+
onShow: void 0,
|
|
1653
|
+
onHide: void 0,
|
|
1654
|
+
onUpdate: void 0,
|
|
1655
|
+
onDestroy: void 0
|
|
1639
1656
|
};
|
|
1640
1657
|
this.shouldShow = ({ view: view2, state, from, to }) => {
|
|
1641
1658
|
const { doc, selection } = state;
|
|
@@ -1654,6 +1671,14 @@ var BubbleMenuView = class {
|
|
|
1654
1671
|
this.dragstartHandler = () => {
|
|
1655
1672
|
this.hide();
|
|
1656
1673
|
};
|
|
1674
|
+
this.resizeHandler = () => {
|
|
1675
|
+
if (this.resizeDebounceTimer) {
|
|
1676
|
+
clearTimeout(this.resizeDebounceTimer);
|
|
1677
|
+
}
|
|
1678
|
+
this.resizeDebounceTimer = window.setTimeout(() => {
|
|
1679
|
+
this.updatePosition();
|
|
1680
|
+
}, this.resizeDelay);
|
|
1681
|
+
};
|
|
1657
1682
|
this.focusHandler = () => {
|
|
1658
1683
|
setTimeout(() => this.update(this.editor.view));
|
|
1659
1684
|
};
|
|
@@ -1714,14 +1739,7 @@ var BubbleMenuView = class {
|
|
|
1714
1739
|
this.view.dom.addEventListener("dragstart", this.dragstartHandler);
|
|
1715
1740
|
this.editor.on("focus", this.focusHandler);
|
|
1716
1741
|
this.editor.on("blur", this.blurHandler);
|
|
1717
|
-
window.addEventListener("resize",
|
|
1718
|
-
if (this.resizeDebounceTimer) {
|
|
1719
|
-
clearTimeout(this.resizeDebounceTimer);
|
|
1720
|
-
}
|
|
1721
|
-
this.resizeDebounceTimer = window.setTimeout(() => {
|
|
1722
|
-
this.updatePosition();
|
|
1723
|
-
}, this.resizeDelay);
|
|
1724
|
-
});
|
|
1742
|
+
window.addEventListener("resize", this.resizeHandler);
|
|
1725
1743
|
this.update(view, view.state);
|
|
1726
1744
|
if (this.getShouldShow()) {
|
|
1727
1745
|
this.show();
|
|
@@ -1767,9 +1785,26 @@ var BubbleMenuView = class {
|
|
|
1767
1785
|
}
|
|
1768
1786
|
updatePosition() {
|
|
1769
1787
|
const { selection } = this.editor.state;
|
|
1770
|
-
|
|
1788
|
+
let virtualElement = {
|
|
1771
1789
|
getBoundingClientRect: () => (0, import_core3.posToDOMRect)(this.view, selection.from, selection.to)
|
|
1772
1790
|
};
|
|
1791
|
+
if (selection instanceof import_tables.CellSelection) {
|
|
1792
|
+
const { $anchorCell, $headCell } = selection;
|
|
1793
|
+
const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
|
|
1794
|
+
const to = $headCell ? $headCell.pos : $anchorCell.pos;
|
|
1795
|
+
const fromDOM = this.view.nodeDOM(from);
|
|
1796
|
+
const toDOM = this.view.nodeDOM(to);
|
|
1797
|
+
if (!fromDOM || !toDOM) {
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
|
|
1801
|
+
fromDOM.getBoundingClientRect(),
|
|
1802
|
+
toDOM.getBoundingClientRect()
|
|
1803
|
+
);
|
|
1804
|
+
virtualElement = {
|
|
1805
|
+
getBoundingClientRect: () => clientRect
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1773
1808
|
computePosition2(virtualElement, this.element, {
|
|
1774
1809
|
placement: this.floatingUIOptions.placement,
|
|
1775
1810
|
strategy: this.floatingUIOptions.strategy,
|
|
@@ -1779,6 +1814,9 @@ var BubbleMenuView = class {
|
|
|
1779
1814
|
this.element.style.position = strategy;
|
|
1780
1815
|
this.element.style.left = `${x}px`;
|
|
1781
1816
|
this.element.style.top = `${y}px`;
|
|
1817
|
+
if (this.isVisible && this.floatingUIOptions.onUpdate) {
|
|
1818
|
+
this.floatingUIOptions.onUpdate();
|
|
1819
|
+
}
|
|
1782
1820
|
});
|
|
1783
1821
|
}
|
|
1784
1822
|
update(view, oldState) {
|
|
@@ -1812,21 +1850,39 @@ var BubbleMenuView = class {
|
|
|
1812
1850
|
}
|
|
1813
1851
|
show() {
|
|
1814
1852
|
var _a;
|
|
1853
|
+
if (this.isVisible) {
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1815
1856
|
this.element.style.visibility = "visible";
|
|
1816
1857
|
this.element.style.opacity = "1";
|
|
1817
1858
|
(_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
|
|
1859
|
+
if (this.floatingUIOptions.onShow) {
|
|
1860
|
+
this.floatingUIOptions.onShow();
|
|
1861
|
+
}
|
|
1862
|
+
this.isVisible = true;
|
|
1818
1863
|
}
|
|
1819
1864
|
hide() {
|
|
1865
|
+
if (!this.isVisible) {
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1820
1868
|
this.element.style.visibility = "hidden";
|
|
1821
1869
|
this.element.style.opacity = "0";
|
|
1822
1870
|
this.element.remove();
|
|
1871
|
+
if (this.floatingUIOptions.onHide) {
|
|
1872
|
+
this.floatingUIOptions.onHide();
|
|
1873
|
+
}
|
|
1874
|
+
this.isVisible = false;
|
|
1823
1875
|
}
|
|
1824
1876
|
destroy() {
|
|
1825
1877
|
this.hide();
|
|
1826
1878
|
this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
|
|
1827
1879
|
this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
|
|
1880
|
+
window.removeEventListener("resize", this.resizeHandler);
|
|
1828
1881
|
this.editor.off("focus", this.focusHandler);
|
|
1829
1882
|
this.editor.off("blur", this.blurHandler);
|
|
1883
|
+
if (this.floatingUIOptions.onDestroy) {
|
|
1884
|
+
this.floatingUIOptions.onDestroy();
|
|
1885
|
+
}
|
|
1830
1886
|
}
|
|
1831
1887
|
};
|
|
1832
1888
|
var BubbleMenuPlugin = (options) => {
|
|
@@ -1930,6 +1986,7 @@ var import_state2 = require("@tiptap/pm/state");
|
|
|
1930
1986
|
var FloatingMenuView = class {
|
|
1931
1987
|
constructor({ editor, element, view, options, shouldShow }) {
|
|
1932
1988
|
this.preventHide = false;
|
|
1989
|
+
this.isVisible = false;
|
|
1933
1990
|
this.shouldShow = ({ view: view2, state }) => {
|
|
1934
1991
|
const { selection } = state;
|
|
1935
1992
|
const { $anchor, empty } = selection;
|
|
@@ -2076,6 +2133,9 @@ var FloatingMenuView = class {
|
|
|
2076
2133
|
this.element.style.position = strategy;
|
|
2077
2134
|
this.element.style.left = `${x}px`;
|
|
2078
2135
|
this.element.style.top = `${y}px`;
|
|
2136
|
+
if (this.isVisible && this.floatingUIOptions.onUpdate) {
|
|
2137
|
+
this.floatingUIOptions.onUpdate();
|
|
2138
|
+
}
|
|
2079
2139
|
});
|
|
2080
2140
|
}
|
|
2081
2141
|
update(view, oldState) {
|
|
@@ -2085,20 +2145,37 @@ var FloatingMenuView = class {
|
|
|
2085
2145
|
}
|
|
2086
2146
|
show() {
|
|
2087
2147
|
var _a;
|
|
2148
|
+
if (this.isVisible) {
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2088
2151
|
this.element.style.visibility = "visible";
|
|
2089
2152
|
this.element.style.opacity = "1";
|
|
2090
2153
|
(_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
|
|
2154
|
+
if (this.floatingUIOptions.onShow) {
|
|
2155
|
+
this.floatingUIOptions.onShow();
|
|
2156
|
+
}
|
|
2157
|
+
this.isVisible = true;
|
|
2091
2158
|
}
|
|
2092
2159
|
hide() {
|
|
2160
|
+
if (!this.isVisible) {
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2093
2163
|
this.element.style.visibility = "hidden";
|
|
2094
2164
|
this.element.style.opacity = "0";
|
|
2095
2165
|
this.element.remove();
|
|
2166
|
+
if (this.floatingUIOptions.onHide) {
|
|
2167
|
+
this.floatingUIOptions.onHide();
|
|
2168
|
+
}
|
|
2169
|
+
this.isVisible = false;
|
|
2096
2170
|
}
|
|
2097
2171
|
destroy() {
|
|
2098
2172
|
this.hide();
|
|
2099
2173
|
this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
|
|
2100
2174
|
this.editor.off("focus", this.focusHandler);
|
|
2101
2175
|
this.editor.off("blur", this.blurHandler);
|
|
2176
|
+
if (this.floatingUIOptions.onDestroy) {
|
|
2177
|
+
this.floatingUIOptions.onDestroy();
|
|
2178
|
+
}
|
|
2102
2179
|
}
|
|
2103
2180
|
};
|
|
2104
2181
|
var FloatingMenuPlugin = (options) => {
|