@tiptap/vue-2 3.0.0-beta.3 → 3.0.0-beta.30

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.
@@ -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
  };
@@ -1707,6 +1732,7 @@ var BubbleMenuView = class {
1707
1732
  ...this.floatingUIOptions,
1708
1733
  ...options
1709
1734
  };
1735
+ this.element.tabIndex = 0;
1710
1736
  if (shouldShow) {
1711
1737
  this.shouldShow = shouldShow;
1712
1738
  }
@@ -1714,14 +1740,7 @@ var BubbleMenuView = class {
1714
1740
  this.view.dom.addEventListener("dragstart", this.dragstartHandler);
1715
1741
  this.editor.on("focus", this.focusHandler);
1716
1742
  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
- });
1743
+ window.addEventListener("resize", this.resizeHandler);
1725
1744
  this.update(view, view.state);
1726
1745
  if (this.getShouldShow()) {
1727
1746
  this.show();
@@ -1767,9 +1786,26 @@ var BubbleMenuView = class {
1767
1786
  }
1768
1787
  updatePosition() {
1769
1788
  const { selection } = this.editor.state;
1770
- const virtualElement = {
1789
+ let virtualElement = {
1771
1790
  getBoundingClientRect: () => (0, import_core3.posToDOMRect)(this.view, selection.from, selection.to)
1772
1791
  };
1792
+ if (selection instanceof import_tables.CellSelection) {
1793
+ const { $anchorCell, $headCell } = selection;
1794
+ const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
1795
+ const to = $headCell ? $headCell.pos : $anchorCell.pos;
1796
+ const fromDOM = this.view.nodeDOM(from);
1797
+ const toDOM = this.view.nodeDOM(to);
1798
+ if (!fromDOM || !toDOM) {
1799
+ return;
1800
+ }
1801
+ const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
1802
+ fromDOM.getBoundingClientRect(),
1803
+ toDOM.getBoundingClientRect()
1804
+ );
1805
+ virtualElement = {
1806
+ getBoundingClientRect: () => clientRect
1807
+ };
1808
+ }
1773
1809
  computePosition2(virtualElement, this.element, {
1774
1810
  placement: this.floatingUIOptions.placement,
1775
1811
  strategy: this.floatingUIOptions.strategy,
@@ -1779,6 +1815,9 @@ var BubbleMenuView = class {
1779
1815
  this.element.style.position = strategy;
1780
1816
  this.element.style.left = `${x}px`;
1781
1817
  this.element.style.top = `${y}px`;
1818
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
1819
+ this.floatingUIOptions.onUpdate();
1820
+ }
1782
1821
  });
1783
1822
  }
1784
1823
  update(view, oldState) {
@@ -1812,21 +1851,39 @@ var BubbleMenuView = class {
1812
1851
  }
1813
1852
  show() {
1814
1853
  var _a;
1854
+ if (this.isVisible) {
1855
+ return;
1856
+ }
1815
1857
  this.element.style.visibility = "visible";
1816
1858
  this.element.style.opacity = "1";
1817
1859
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
1860
+ if (this.floatingUIOptions.onShow) {
1861
+ this.floatingUIOptions.onShow();
1862
+ }
1863
+ this.isVisible = true;
1818
1864
  }
1819
1865
  hide() {
1866
+ if (!this.isVisible) {
1867
+ return;
1868
+ }
1820
1869
  this.element.style.visibility = "hidden";
1821
1870
  this.element.style.opacity = "0";
1822
1871
  this.element.remove();
1872
+ if (this.floatingUIOptions.onHide) {
1873
+ this.floatingUIOptions.onHide();
1874
+ }
1875
+ this.isVisible = false;
1823
1876
  }
1824
1877
  destroy() {
1825
1878
  this.hide();
1826
1879
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
1827
1880
  this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
1881
+ window.removeEventListener("resize", this.resizeHandler);
1828
1882
  this.editor.off("focus", this.focusHandler);
1829
1883
  this.editor.off("blur", this.blurHandler);
1884
+ if (this.floatingUIOptions.onDestroy) {
1885
+ this.floatingUIOptions.onDestroy();
1886
+ }
1830
1887
  }
1831
1888
  };
1832
1889
  var BubbleMenuPlugin = (options) => {
@@ -1930,6 +1987,7 @@ var import_state2 = require("@tiptap/pm/state");
1930
1987
  var FloatingMenuView = class {
1931
1988
  constructor({ editor, element, view, options, shouldShow }) {
1932
1989
  this.preventHide = false;
1990
+ this.isVisible = false;
1933
1991
  this.shouldShow = ({ view: view2, state }) => {
1934
1992
  const { selection } = state;
1935
1993
  const { $anchor, empty } = selection;
@@ -1993,6 +2051,7 @@ var FloatingMenuView = class {
1993
2051
  ...this.floatingUIOptions,
1994
2052
  ...options
1995
2053
  };
2054
+ this.element.tabIndex = 0;
1996
2055
  if (shouldShow) {
1997
2056
  this.shouldShow = shouldShow;
1998
2057
  }
@@ -2076,6 +2135,9 @@ var FloatingMenuView = class {
2076
2135
  this.element.style.position = strategy;
2077
2136
  this.element.style.left = `${x}px`;
2078
2137
  this.element.style.top = `${y}px`;
2138
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
2139
+ this.floatingUIOptions.onUpdate();
2140
+ }
2079
2141
  });
2080
2142
  }
2081
2143
  update(view, oldState) {
@@ -2085,20 +2147,37 @@ var FloatingMenuView = class {
2085
2147
  }
2086
2148
  show() {
2087
2149
  var _a;
2150
+ if (this.isVisible) {
2151
+ return;
2152
+ }
2088
2153
  this.element.style.visibility = "visible";
2089
2154
  this.element.style.opacity = "1";
2090
2155
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
2156
+ if (this.floatingUIOptions.onShow) {
2157
+ this.floatingUIOptions.onShow();
2158
+ }
2159
+ this.isVisible = true;
2091
2160
  }
2092
2161
  hide() {
2162
+ if (!this.isVisible) {
2163
+ return;
2164
+ }
2093
2165
  this.element.style.visibility = "hidden";
2094
2166
  this.element.style.opacity = "0";
2095
2167
  this.element.remove();
2168
+ if (this.floatingUIOptions.onHide) {
2169
+ this.floatingUIOptions.onHide();
2170
+ }
2171
+ this.isVisible = false;
2096
2172
  }
2097
2173
  destroy() {
2098
2174
  this.hide();
2099
2175
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2100
2176
  this.editor.off("focus", this.focusHandler);
2101
2177
  this.editor.off("blur", this.blurHandler);
2178
+ if (this.floatingUIOptions.onDestroy) {
2179
+ this.floatingUIOptions.onDestroy();
2180
+ }
2102
2181
  }
2103
2182
  };
2104
2183
  var FloatingMenuPlugin = (options) => {