@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.
@@ -62,6 +62,10 @@ interface BubbleMenuPluginProps {
62
62
  autoPlacement?: Parameters<typeof autoPlacement>[0] | boolean;
63
63
  hide?: Parameters<typeof hide>[0] | boolean;
64
64
  inline?: Parameters<typeof inline>[0] | boolean;
65
+ onShow?: () => void;
66
+ onHide?: () => void;
67
+ onUpdate?: () => void;
68
+ onDestroy?: () => void;
65
69
  };
66
70
  }
67
71
 
@@ -117,6 +121,10 @@ interface FloatingMenuPluginProps {
117
121
  autoPlacement?: Parameters<typeof autoPlacement>[0] | boolean;
118
122
  hide?: Parameters<typeof hide>[0] | boolean;
119
123
  inline?: Parameters<typeof inline>[0] | boolean;
124
+ onShow?: () => void;
125
+ onHide?: () => void;
126
+ onUpdate?: () => void;
127
+ onDestroy?: () => void;
120
128
  };
121
129
  }
122
130
 
@@ -62,6 +62,10 @@ interface BubbleMenuPluginProps {
62
62
  autoPlacement?: Parameters<typeof autoPlacement>[0] | boolean;
63
63
  hide?: Parameters<typeof hide>[0] | boolean;
64
64
  inline?: Parameters<typeof inline>[0] | boolean;
65
+ onShow?: () => void;
66
+ onHide?: () => void;
67
+ onUpdate?: () => void;
68
+ onDestroy?: () => void;
65
69
  };
66
70
  }
67
71
 
@@ -117,6 +121,10 @@ interface FloatingMenuPluginProps {
117
121
  autoPlacement?: Parameters<typeof autoPlacement>[0] | boolean;
118
122
  hide?: Parameters<typeof hide>[0] | boolean;
119
123
  inline?: Parameters<typeof inline>[0] | boolean;
124
+ onShow?: () => void;
125
+ onHide?: () => void;
126
+ onUpdate?: () => void;
127
+ onDestroy?: () => void;
120
128
  };
121
129
  }
122
130
 
@@ -1587,6 +1587,18 @@ var computePosition2 = (reference, floating, options) => {
1587
1587
  // ../extension-bubble-menu/dist/index.js
1588
1588
  import { isTextSelection, posToDOMRect } from "@tiptap/core";
1589
1589
  import { Plugin, PluginKey } from "@tiptap/pm/state";
1590
+ import { CellSelection } from "@tiptap/pm/tables";
1591
+ function combineDOMRects(rect1, rect2) {
1592
+ const top = Math.min(rect1.top, rect2.top);
1593
+ const bottom = Math.max(rect1.bottom, rect2.bottom);
1594
+ const left = Math.min(rect1.left, rect2.left);
1595
+ const right = Math.max(rect1.right, rect2.right);
1596
+ const width = right - left;
1597
+ const height = bottom - top;
1598
+ const x = left;
1599
+ const y = top;
1600
+ return new DOMRect(x, y, width, height);
1601
+ }
1590
1602
  var BubbleMenuView = class {
1591
1603
  constructor({
1592
1604
  editor,
@@ -1598,6 +1610,7 @@ var BubbleMenuView = class {
1598
1610
  options
1599
1611
  }) {
1600
1612
  this.preventHide = false;
1613
+ this.isVisible = false;
1601
1614
  this.floatingUIOptions = {
1602
1615
  strategy: "absolute",
1603
1616
  placement: "top",
@@ -1608,7 +1621,11 @@ var BubbleMenuView = class {
1608
1621
  size: false,
1609
1622
  autoPlacement: false,
1610
1623
  hide: false,
1611
- inline: false
1624
+ inline: false,
1625
+ onShow: void 0,
1626
+ onHide: void 0,
1627
+ onUpdate: void 0,
1628
+ onDestroy: void 0
1612
1629
  };
1613
1630
  this.shouldShow = ({ view: view2, state, from, to }) => {
1614
1631
  const { doc, selection } = state;
@@ -1627,6 +1644,14 @@ var BubbleMenuView = class {
1627
1644
  this.dragstartHandler = () => {
1628
1645
  this.hide();
1629
1646
  };
1647
+ this.resizeHandler = () => {
1648
+ if (this.resizeDebounceTimer) {
1649
+ clearTimeout(this.resizeDebounceTimer);
1650
+ }
1651
+ this.resizeDebounceTimer = window.setTimeout(() => {
1652
+ this.updatePosition();
1653
+ }, this.resizeDelay);
1654
+ };
1630
1655
  this.focusHandler = () => {
1631
1656
  setTimeout(() => this.update(this.editor.view));
1632
1657
  };
@@ -1680,6 +1705,7 @@ var BubbleMenuView = class {
1680
1705
  ...this.floatingUIOptions,
1681
1706
  ...options
1682
1707
  };
1708
+ this.element.tabIndex = 0;
1683
1709
  if (shouldShow) {
1684
1710
  this.shouldShow = shouldShow;
1685
1711
  }
@@ -1687,14 +1713,7 @@ var BubbleMenuView = class {
1687
1713
  this.view.dom.addEventListener("dragstart", this.dragstartHandler);
1688
1714
  this.editor.on("focus", this.focusHandler);
1689
1715
  this.editor.on("blur", this.blurHandler);
1690
- window.addEventListener("resize", () => {
1691
- if (this.resizeDebounceTimer) {
1692
- clearTimeout(this.resizeDebounceTimer);
1693
- }
1694
- this.resizeDebounceTimer = window.setTimeout(() => {
1695
- this.updatePosition();
1696
- }, this.resizeDelay);
1697
- });
1716
+ window.addEventListener("resize", this.resizeHandler);
1698
1717
  this.update(view, view.state);
1699
1718
  if (this.getShouldShow()) {
1700
1719
  this.show();
@@ -1740,9 +1759,26 @@ var BubbleMenuView = class {
1740
1759
  }
1741
1760
  updatePosition() {
1742
1761
  const { selection } = this.editor.state;
1743
- const virtualElement = {
1762
+ let virtualElement = {
1744
1763
  getBoundingClientRect: () => posToDOMRect(this.view, selection.from, selection.to)
1745
1764
  };
1765
+ if (selection instanceof CellSelection) {
1766
+ const { $anchorCell, $headCell } = selection;
1767
+ const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
1768
+ const to = $headCell ? $headCell.pos : $anchorCell.pos;
1769
+ const fromDOM = this.view.nodeDOM(from);
1770
+ const toDOM = this.view.nodeDOM(to);
1771
+ if (!fromDOM || !toDOM) {
1772
+ return;
1773
+ }
1774
+ const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
1775
+ fromDOM.getBoundingClientRect(),
1776
+ toDOM.getBoundingClientRect()
1777
+ );
1778
+ virtualElement = {
1779
+ getBoundingClientRect: () => clientRect
1780
+ };
1781
+ }
1746
1782
  computePosition2(virtualElement, this.element, {
1747
1783
  placement: this.floatingUIOptions.placement,
1748
1784
  strategy: this.floatingUIOptions.strategy,
@@ -1752,6 +1788,9 @@ var BubbleMenuView = class {
1752
1788
  this.element.style.position = strategy;
1753
1789
  this.element.style.left = `${x}px`;
1754
1790
  this.element.style.top = `${y}px`;
1791
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
1792
+ this.floatingUIOptions.onUpdate();
1793
+ }
1755
1794
  });
1756
1795
  }
1757
1796
  update(view, oldState) {
@@ -1785,21 +1824,39 @@ var BubbleMenuView = class {
1785
1824
  }
1786
1825
  show() {
1787
1826
  var _a;
1827
+ if (this.isVisible) {
1828
+ return;
1829
+ }
1788
1830
  this.element.style.visibility = "visible";
1789
1831
  this.element.style.opacity = "1";
1790
1832
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
1833
+ if (this.floatingUIOptions.onShow) {
1834
+ this.floatingUIOptions.onShow();
1835
+ }
1836
+ this.isVisible = true;
1791
1837
  }
1792
1838
  hide() {
1839
+ if (!this.isVisible) {
1840
+ return;
1841
+ }
1793
1842
  this.element.style.visibility = "hidden";
1794
1843
  this.element.style.opacity = "0";
1795
1844
  this.element.remove();
1845
+ if (this.floatingUIOptions.onHide) {
1846
+ this.floatingUIOptions.onHide();
1847
+ }
1848
+ this.isVisible = false;
1796
1849
  }
1797
1850
  destroy() {
1798
1851
  this.hide();
1799
1852
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
1800
1853
  this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
1854
+ window.removeEventListener("resize", this.resizeHandler);
1801
1855
  this.editor.off("focus", this.focusHandler);
1802
1856
  this.editor.off("blur", this.blurHandler);
1857
+ if (this.floatingUIOptions.onDestroy) {
1858
+ this.floatingUIOptions.onDestroy();
1859
+ }
1803
1860
  }
1804
1861
  };
1805
1862
  var BubbleMenuPlugin = (options) => {
@@ -1903,6 +1960,7 @@ import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1903
1960
  var FloatingMenuView = class {
1904
1961
  constructor({ editor, element, view, options, shouldShow }) {
1905
1962
  this.preventHide = false;
1963
+ this.isVisible = false;
1906
1964
  this.shouldShow = ({ view: view2, state }) => {
1907
1965
  const { selection } = state;
1908
1966
  const { $anchor, empty } = selection;
@@ -1966,6 +2024,7 @@ var FloatingMenuView = class {
1966
2024
  ...this.floatingUIOptions,
1967
2025
  ...options
1968
2026
  };
2027
+ this.element.tabIndex = 0;
1969
2028
  if (shouldShow) {
1970
2029
  this.shouldShow = shouldShow;
1971
2030
  }
@@ -2049,6 +2108,9 @@ var FloatingMenuView = class {
2049
2108
  this.element.style.position = strategy;
2050
2109
  this.element.style.left = `${x}px`;
2051
2110
  this.element.style.top = `${y}px`;
2111
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
2112
+ this.floatingUIOptions.onUpdate();
2113
+ }
2052
2114
  });
2053
2115
  }
2054
2116
  update(view, oldState) {
@@ -2058,20 +2120,37 @@ var FloatingMenuView = class {
2058
2120
  }
2059
2121
  show() {
2060
2122
  var _a;
2123
+ if (this.isVisible) {
2124
+ return;
2125
+ }
2061
2126
  this.element.style.visibility = "visible";
2062
2127
  this.element.style.opacity = "1";
2063
2128
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
2129
+ if (this.floatingUIOptions.onShow) {
2130
+ this.floatingUIOptions.onShow();
2131
+ }
2132
+ this.isVisible = true;
2064
2133
  }
2065
2134
  hide() {
2135
+ if (!this.isVisible) {
2136
+ return;
2137
+ }
2066
2138
  this.element.style.visibility = "hidden";
2067
2139
  this.element.style.opacity = "0";
2068
2140
  this.element.remove();
2141
+ if (this.floatingUIOptions.onHide) {
2142
+ this.floatingUIOptions.onHide();
2143
+ }
2144
+ this.isVisible = false;
2069
2145
  }
2070
2146
  destroy() {
2071
2147
  this.hide();
2072
2148
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2073
2149
  this.editor.off("focus", this.focusHandler);
2074
2150
  this.editor.off("blur", this.blurHandler);
2151
+ if (this.floatingUIOptions.onDestroy) {
2152
+ this.floatingUIOptions.onDestroy();
2153
+ }
2075
2154
  }
2076
2155
  };
2077
2156
  var FloatingMenuPlugin = (options) => {