@tiptap/vue-2 3.0.0-beta.10 → 3.0.0-beta.12

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;
@@ -1767,9 +1784,26 @@ var BubbleMenuView = class {
1767
1784
  }
1768
1785
  updatePosition() {
1769
1786
  const { selection } = this.editor.state;
1770
- const virtualElement = {
1787
+ let virtualElement = {
1771
1788
  getBoundingClientRect: () => (0, import_core3.posToDOMRect)(this.view, selection.from, selection.to)
1772
1789
  };
1790
+ if (selection instanceof import_tables.CellSelection) {
1791
+ const { $anchorCell, $headCell } = selection;
1792
+ const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
1793
+ const to = $headCell ? $headCell.pos : $anchorCell.pos;
1794
+ const fromDOM = this.view.nodeDOM(from);
1795
+ const toDOM = this.view.nodeDOM(to);
1796
+ if (!fromDOM || !toDOM) {
1797
+ return;
1798
+ }
1799
+ const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
1800
+ fromDOM.getBoundingClientRect(),
1801
+ toDOM.getBoundingClientRect()
1802
+ );
1803
+ virtualElement = {
1804
+ getBoundingClientRect: () => clientRect
1805
+ };
1806
+ }
1773
1807
  computePosition2(virtualElement, this.element, {
1774
1808
  placement: this.floatingUIOptions.placement,
1775
1809
  strategy: this.floatingUIOptions.strategy,
@@ -1779,6 +1813,9 @@ var BubbleMenuView = class {
1779
1813
  this.element.style.position = strategy;
1780
1814
  this.element.style.left = `${x}px`;
1781
1815
  this.element.style.top = `${y}px`;
1816
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
1817
+ this.floatingUIOptions.onUpdate();
1818
+ }
1782
1819
  });
1783
1820
  }
1784
1821
  update(view, oldState) {
@@ -1812,14 +1849,28 @@ var BubbleMenuView = class {
1812
1849
  }
1813
1850
  show() {
1814
1851
  var _a;
1852
+ if (this.isVisible) {
1853
+ return;
1854
+ }
1815
1855
  this.element.style.visibility = "visible";
1816
1856
  this.element.style.opacity = "1";
1817
1857
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
1858
+ if (this.floatingUIOptions.onShow) {
1859
+ this.floatingUIOptions.onShow();
1860
+ }
1861
+ this.isVisible = true;
1818
1862
  }
1819
1863
  hide() {
1864
+ if (!this.isVisible) {
1865
+ return;
1866
+ }
1820
1867
  this.element.style.visibility = "hidden";
1821
1868
  this.element.style.opacity = "0";
1822
1869
  this.element.remove();
1870
+ if (this.floatingUIOptions.onHide) {
1871
+ this.floatingUIOptions.onHide();
1872
+ }
1873
+ this.isVisible = false;
1823
1874
  }
1824
1875
  destroy() {
1825
1876
  this.hide();
@@ -1827,6 +1878,9 @@ var BubbleMenuView = class {
1827
1878
  this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
1828
1879
  this.editor.off("focus", this.focusHandler);
1829
1880
  this.editor.off("blur", this.blurHandler);
1881
+ if (this.floatingUIOptions.onDestroy) {
1882
+ this.floatingUIOptions.onDestroy();
1883
+ }
1830
1884
  }
1831
1885
  };
1832
1886
  var BubbleMenuPlugin = (options) => {
@@ -1930,6 +1984,7 @@ var import_state2 = require("@tiptap/pm/state");
1930
1984
  var FloatingMenuView = class {
1931
1985
  constructor({ editor, element, view, options, shouldShow }) {
1932
1986
  this.preventHide = false;
1987
+ this.isVisible = false;
1933
1988
  this.shouldShow = ({ view: view2, state }) => {
1934
1989
  const { selection } = state;
1935
1990
  const { $anchor, empty } = selection;
@@ -2076,6 +2131,9 @@ var FloatingMenuView = class {
2076
2131
  this.element.style.position = strategy;
2077
2132
  this.element.style.left = `${x}px`;
2078
2133
  this.element.style.top = `${y}px`;
2134
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
2135
+ this.floatingUIOptions.onUpdate();
2136
+ }
2079
2137
  });
2080
2138
  }
2081
2139
  update(view, oldState) {
@@ -2085,20 +2143,37 @@ var FloatingMenuView = class {
2085
2143
  }
2086
2144
  show() {
2087
2145
  var _a;
2146
+ if (this.isVisible) {
2147
+ return;
2148
+ }
2088
2149
  this.element.style.visibility = "visible";
2089
2150
  this.element.style.opacity = "1";
2090
2151
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
2152
+ if (this.floatingUIOptions.onShow) {
2153
+ this.floatingUIOptions.onShow();
2154
+ }
2155
+ this.isVisible = true;
2091
2156
  }
2092
2157
  hide() {
2158
+ if (!this.isVisible) {
2159
+ return;
2160
+ }
2093
2161
  this.element.style.visibility = "hidden";
2094
2162
  this.element.style.opacity = "0";
2095
2163
  this.element.remove();
2164
+ if (this.floatingUIOptions.onHide) {
2165
+ this.floatingUIOptions.onHide();
2166
+ }
2167
+ this.isVisible = false;
2096
2168
  }
2097
2169
  destroy() {
2098
2170
  this.hide();
2099
2171
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2100
2172
  this.editor.off("focus", this.focusHandler);
2101
2173
  this.editor.off("blur", this.blurHandler);
2174
+ if (this.floatingUIOptions.onDestroy) {
2175
+ this.floatingUIOptions.onDestroy();
2176
+ }
2102
2177
  }
2103
2178
  };
2104
2179
  var FloatingMenuPlugin = (options) => {