@tiptap/vue-2 3.0.0-next.8 → 3.0.1

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
 
@@ -1,3 +1,6 @@
1
+ // ../extension-bubble-menu/dist/index.js
2
+ import { Extension } from "@tiptap/core";
3
+
1
4
  // ../../node_modules/.pnpm/@floating-ui+utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
2
5
  var sides = ["top", "right", "bottom", "left"];
3
6
  var alignments = ["start", "end"];
@@ -1581,9 +1584,21 @@ var computePosition2 = (reference, floating, options) => {
1581
1584
  });
1582
1585
  };
1583
1586
 
1584
- // ../extension-bubble-menu/src/bubble-menu-plugin.ts
1587
+ // ../extension-bubble-menu/dist/index.js
1585
1588
  import { isTextSelection, posToDOMRect } from "@tiptap/core";
1586
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
+ }
1587
1602
  var BubbleMenuView = class {
1588
1603
  constructor({
1589
1604
  editor,
@@ -1595,6 +1610,7 @@ var BubbleMenuView = class {
1595
1610
  options
1596
1611
  }) {
1597
1612
  this.preventHide = false;
1613
+ this.isVisible = false;
1598
1614
  this.floatingUIOptions = {
1599
1615
  strategy: "absolute",
1600
1616
  placement: "top",
@@ -1605,14 +1621,18 @@ var BubbleMenuView = class {
1605
1621
  size: false,
1606
1622
  autoPlacement: false,
1607
1623
  hide: false,
1608
- inline: false
1624
+ inline: false,
1625
+ onShow: void 0,
1626
+ onHide: void 0,
1627
+ onUpdate: void 0,
1628
+ onDestroy: void 0
1609
1629
  };
1610
- this.shouldShow = ({ view, state, from, to }) => {
1630
+ this.shouldShow = ({ view: view2, state, from, to }) => {
1611
1631
  const { doc, selection } = state;
1612
1632
  const { empty } = selection;
1613
1633
  const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
1614
1634
  const isChildOfMenu = this.element.contains(document.activeElement);
1615
- const hasEditorFocus = view.hasFocus() || isChildOfMenu;
1635
+ const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
1616
1636
  if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
1617
1637
  return false;
1618
1638
  }
@@ -1624,6 +1644,14 @@ var BubbleMenuView = class {
1624
1644
  this.dragstartHandler = () => {
1625
1645
  this.hide();
1626
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
+ };
1627
1655
  this.focusHandler = () => {
1628
1656
  setTimeout(() => this.update(this.editor.view));
1629
1657
  };
@@ -1641,9 +1669,9 @@ var BubbleMenuView = class {
1641
1669
  }
1642
1670
  this.hide();
1643
1671
  };
1644
- this.handleDebouncedUpdate = (view, oldState) => {
1645
- const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
1646
- const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
1672
+ this.handleDebouncedUpdate = (view2, oldState) => {
1673
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
1674
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
1647
1675
  if (!selectionChanged && !docChanged) {
1648
1676
  return;
1649
1677
  }
@@ -1651,17 +1679,17 @@ var BubbleMenuView = class {
1651
1679
  clearTimeout(this.updateDebounceTimer);
1652
1680
  }
1653
1681
  this.updateDebounceTimer = window.setTimeout(() => {
1654
- this.updateHandler(view, selectionChanged, docChanged, oldState);
1682
+ this.updateHandler(view2, selectionChanged, docChanged, oldState);
1655
1683
  }, this.updateDelay);
1656
1684
  };
1657
- this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
1658
- const { composing } = view;
1685
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
1686
+ const { composing } = view2;
1659
1687
  const isSame = !selectionChanged && !docChanged;
1660
1688
  if (composing || isSame) {
1661
1689
  return;
1662
1690
  }
1663
- const shouldShow = this.getShouldShow(oldState);
1664
- if (!shouldShow) {
1691
+ const shouldShow2 = this.getShouldShow(oldState);
1692
+ if (!shouldShow2) {
1665
1693
  this.hide();
1666
1694
  return;
1667
1695
  }
@@ -1677,6 +1705,7 @@ var BubbleMenuView = class {
1677
1705
  ...this.floatingUIOptions,
1678
1706
  ...options
1679
1707
  };
1708
+ this.element.tabIndex = 0;
1680
1709
  if (shouldShow) {
1681
1710
  this.shouldShow = shouldShow;
1682
1711
  }
@@ -1684,14 +1713,7 @@ var BubbleMenuView = class {
1684
1713
  this.view.dom.addEventListener("dragstart", this.dragstartHandler);
1685
1714
  this.editor.on("focus", this.focusHandler);
1686
1715
  this.editor.on("blur", this.blurHandler);
1687
- window.addEventListener("resize", () => {
1688
- if (this.resizeDebounceTimer) {
1689
- clearTimeout(this.resizeDebounceTimer);
1690
- }
1691
- this.resizeDebounceTimer = window.setTimeout(() => {
1692
- this.updatePosition();
1693
- }, this.resizeDelay);
1694
- });
1716
+ window.addEventListener("resize", this.resizeHandler);
1695
1717
  this.update(view, view.state);
1696
1718
  if (this.getShouldShow()) {
1697
1719
  this.show();
@@ -1737,9 +1759,26 @@ var BubbleMenuView = class {
1737
1759
  }
1738
1760
  updatePosition() {
1739
1761
  const { selection } = this.editor.state;
1740
- const virtualElement = {
1762
+ let virtualElement = {
1741
1763
  getBoundingClientRect: () => posToDOMRect(this.view, selection.from, selection.to)
1742
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
+ }
1743
1782
  computePosition2(virtualElement, this.element, {
1744
1783
  placement: this.floatingUIOptions.placement,
1745
1784
  strategy: this.floatingUIOptions.strategy,
@@ -1749,6 +1788,9 @@ var BubbleMenuView = class {
1749
1788
  this.element.style.position = strategy;
1750
1789
  this.element.style.left = `${x}px`;
1751
1790
  this.element.style.top = `${y}px`;
1791
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
1792
+ this.floatingUIOptions.onUpdate();
1793
+ }
1752
1794
  });
1753
1795
  }
1754
1796
  update(view, oldState) {
@@ -1782,21 +1824,39 @@ var BubbleMenuView = class {
1782
1824
  }
1783
1825
  show() {
1784
1826
  var _a;
1827
+ if (this.isVisible) {
1828
+ return;
1829
+ }
1785
1830
  this.element.style.visibility = "visible";
1786
1831
  this.element.style.opacity = "1";
1787
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;
1788
1837
  }
1789
1838
  hide() {
1839
+ if (!this.isVisible) {
1840
+ return;
1841
+ }
1790
1842
  this.element.style.visibility = "hidden";
1791
1843
  this.element.style.opacity = "0";
1792
1844
  this.element.remove();
1845
+ if (this.floatingUIOptions.onHide) {
1846
+ this.floatingUIOptions.onHide();
1847
+ }
1848
+ this.isVisible = false;
1793
1849
  }
1794
1850
  destroy() {
1795
1851
  this.hide();
1796
1852
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
1797
1853
  this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
1854
+ window.removeEventListener("resize", this.resizeHandler);
1798
1855
  this.editor.off("focus", this.focusHandler);
1799
1856
  this.editor.off("blur", this.blurHandler);
1857
+ if (this.floatingUIOptions.onDestroy) {
1858
+ this.floatingUIOptions.onDestroy();
1859
+ }
1800
1860
  }
1801
1861
  };
1802
1862
  var BubbleMenuPlugin = (options) => {
@@ -1805,9 +1865,34 @@ var BubbleMenuPlugin = (options) => {
1805
1865
  view: (view) => new BubbleMenuView({ view, ...options })
1806
1866
  });
1807
1867
  };
1868
+ var BubbleMenu = Extension.create({
1869
+ name: "bubbleMenu",
1870
+ addOptions() {
1871
+ return {
1872
+ element: null,
1873
+ pluginKey: "bubbleMenu",
1874
+ updateDelay: void 0,
1875
+ shouldShow: null
1876
+ };
1877
+ },
1878
+ addProseMirrorPlugins() {
1879
+ if (!this.options.element) {
1880
+ return [];
1881
+ }
1882
+ return [
1883
+ BubbleMenuPlugin({
1884
+ pluginKey: this.options.pluginKey,
1885
+ editor: this.editor,
1886
+ element: this.options.element,
1887
+ updateDelay: this.options.updateDelay,
1888
+ shouldShow: this.options.shouldShow
1889
+ })
1890
+ ];
1891
+ }
1892
+ });
1808
1893
 
1809
1894
  // src/menus/BubbleMenu.ts
1810
- var BubbleMenu = {
1895
+ var BubbleMenu2 = {
1811
1896
  name: "BubbleMenu",
1812
1897
  props: {
1813
1898
  pluginKey: {
@@ -1868,18 +1953,20 @@ var BubbleMenu = {
1868
1953
  }
1869
1954
  };
1870
1955
 
1871
- // ../extension-floating-menu/src/floating-menu-plugin.ts
1956
+ // ../extension-floating-menu/dist/index.js
1957
+ import { Extension as Extension2 } from "@tiptap/core";
1872
1958
  import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
1873
1959
  import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1874
1960
  var FloatingMenuView = class {
1875
1961
  constructor({ editor, element, view, options, shouldShow }) {
1876
1962
  this.preventHide = false;
1877
- this.shouldShow = ({ view, state }) => {
1963
+ this.isVisible = false;
1964
+ this.shouldShow = ({ view: view2, state }) => {
1878
1965
  const { selection } = state;
1879
1966
  const { $anchor, empty } = selection;
1880
1967
  const isRootDepth = $anchor.depth === 1;
1881
1968
  const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
1882
- if (!view.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
1969
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
1883
1970
  return false;
1884
1971
  }
1885
1972
  return true;
@@ -1896,14 +1983,14 @@ var FloatingMenuView = class {
1896
1983
  hide: false,
1897
1984
  inline: false
1898
1985
  };
1899
- this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
1900
- const { composing } = view;
1986
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
1987
+ const { composing } = view2;
1901
1988
  const isSame = !selectionChanged && !docChanged;
1902
1989
  if (composing || isSame) {
1903
1990
  return;
1904
1991
  }
1905
- const shouldShow = this.getShouldShow(oldState);
1906
- if (!shouldShow) {
1992
+ const shouldShow2 = this.getShouldShow(oldState);
1993
+ if (!shouldShow2) {
1907
1994
  this.hide();
1908
1995
  return;
1909
1996
  }
@@ -1937,6 +2024,7 @@ var FloatingMenuView = class {
1937
2024
  ...this.floatingUIOptions,
1938
2025
  ...options
1939
2026
  };
2027
+ this.element.tabIndex = 0;
1940
2028
  if (shouldShow) {
1941
2029
  this.shouldShow = shouldShow;
1942
2030
  }
@@ -2020,6 +2108,9 @@ var FloatingMenuView = class {
2020
2108
  this.element.style.position = strategy;
2021
2109
  this.element.style.left = `${x}px`;
2022
2110
  this.element.style.top = `${y}px`;
2111
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
2112
+ this.floatingUIOptions.onUpdate();
2113
+ }
2023
2114
  });
2024
2115
  }
2025
2116
  update(view, oldState) {
@@ -2029,20 +2120,37 @@ var FloatingMenuView = class {
2029
2120
  }
2030
2121
  show() {
2031
2122
  var _a;
2123
+ if (this.isVisible) {
2124
+ return;
2125
+ }
2032
2126
  this.element.style.visibility = "visible";
2033
2127
  this.element.style.opacity = "1";
2034
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;
2035
2133
  }
2036
2134
  hide() {
2135
+ if (!this.isVisible) {
2136
+ return;
2137
+ }
2037
2138
  this.element.style.visibility = "hidden";
2038
2139
  this.element.style.opacity = "0";
2039
2140
  this.element.remove();
2141
+ if (this.floatingUIOptions.onHide) {
2142
+ this.floatingUIOptions.onHide();
2143
+ }
2144
+ this.isVisible = false;
2040
2145
  }
2041
2146
  destroy() {
2042
2147
  this.hide();
2043
2148
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2044
2149
  this.editor.off("focus", this.focusHandler);
2045
2150
  this.editor.off("blur", this.blurHandler);
2151
+ if (this.floatingUIOptions.onDestroy) {
2152
+ this.floatingUIOptions.onDestroy();
2153
+ }
2046
2154
  }
2047
2155
  };
2048
2156
  var FloatingMenuPlugin = (options) => {
@@ -2051,9 +2159,34 @@ var FloatingMenuPlugin = (options) => {
2051
2159
  view: (view) => new FloatingMenuView({ view, ...options })
2052
2160
  });
2053
2161
  };
2162
+ var FloatingMenu = Extension2.create({
2163
+ name: "floatingMenu",
2164
+ addOptions() {
2165
+ return {
2166
+ element: null,
2167
+ options: {},
2168
+ pluginKey: "floatingMenu",
2169
+ shouldShow: null
2170
+ };
2171
+ },
2172
+ addProseMirrorPlugins() {
2173
+ if (!this.options.element) {
2174
+ return [];
2175
+ }
2176
+ return [
2177
+ FloatingMenuPlugin({
2178
+ pluginKey: this.options.pluginKey,
2179
+ editor: this.editor,
2180
+ element: this.options.element,
2181
+ options: this.options.options,
2182
+ shouldShow: this.options.shouldShow
2183
+ })
2184
+ ];
2185
+ }
2186
+ });
2054
2187
 
2055
2188
  // src/menus/FloatingMenu.ts
2056
- var FloatingMenu = {
2189
+ var FloatingMenu2 = {
2057
2190
  name: "FloatingMenu",
2058
2191
  props: {
2059
2192
  pluginKey: {
@@ -2106,7 +2239,7 @@ var FloatingMenu = {
2106
2239
  }
2107
2240
  };
2108
2241
  export {
2109
- BubbleMenu,
2110
- FloatingMenu
2242
+ BubbleMenu2 as BubbleMenu,
2243
+ FloatingMenu2 as FloatingMenu
2111
2244
  };
2112
2245
  //# sourceMappingURL=index.js.map