@tiptap/vue-2 3.0.0-beta.1 → 3.0.0-beta.11

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.
@@ -1,5 +1,5 @@
1
- import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
2
1
  import { Editor } from '@tiptap/core';
2
+ import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
3
3
  import { PluginKey, EditorState } from '@tiptap/pm/state';
4
4
  import { EditorView } from '@tiptap/pm/view';
5
5
  import Vue, { Component } from 'vue';
@@ -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,5 +1,5 @@
1
- import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
2
1
  import { Editor } from '@tiptap/core';
2
+ import { offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
3
3
  import { PluginKey, EditorState } from '@tiptap/pm/state';
4
4
  import { EditorView } from '@tiptap/pm/view';
5
5
  import Vue, { Component } from 'vue';
@@ -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,7 +1584,7 @@ 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";
1587
1590
  var BubbleMenuView = class {
@@ -1595,6 +1598,7 @@ var BubbleMenuView = class {
1595
1598
  options
1596
1599
  }) {
1597
1600
  this.preventHide = false;
1601
+ this.isVisible = false;
1598
1602
  this.floatingUIOptions = {
1599
1603
  strategy: "absolute",
1600
1604
  placement: "top",
@@ -1605,14 +1609,18 @@ var BubbleMenuView = class {
1605
1609
  size: false,
1606
1610
  autoPlacement: false,
1607
1611
  hide: false,
1608
- inline: false
1612
+ inline: false,
1613
+ onShow: void 0,
1614
+ onHide: void 0,
1615
+ onUpdate: void 0,
1616
+ onDestroy: void 0
1609
1617
  };
1610
- this.shouldShow = ({ view, state, from, to }) => {
1618
+ this.shouldShow = ({ view: view2, state, from, to }) => {
1611
1619
  const { doc, selection } = state;
1612
1620
  const { empty } = selection;
1613
1621
  const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
1614
1622
  const isChildOfMenu = this.element.contains(document.activeElement);
1615
- const hasEditorFocus = view.hasFocus() || isChildOfMenu;
1623
+ const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
1616
1624
  if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
1617
1625
  return false;
1618
1626
  }
@@ -1641,9 +1649,9 @@ var BubbleMenuView = class {
1641
1649
  }
1642
1650
  this.hide();
1643
1651
  };
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));
1652
+ this.handleDebouncedUpdate = (view2, oldState) => {
1653
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
1654
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
1647
1655
  if (!selectionChanged && !docChanged) {
1648
1656
  return;
1649
1657
  }
@@ -1651,17 +1659,17 @@ var BubbleMenuView = class {
1651
1659
  clearTimeout(this.updateDebounceTimer);
1652
1660
  }
1653
1661
  this.updateDebounceTimer = window.setTimeout(() => {
1654
- this.updateHandler(view, selectionChanged, docChanged, oldState);
1662
+ this.updateHandler(view2, selectionChanged, docChanged, oldState);
1655
1663
  }, this.updateDelay);
1656
1664
  };
1657
- this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
1658
- const { composing } = view;
1665
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
1666
+ const { composing } = view2;
1659
1667
  const isSame = !selectionChanged && !docChanged;
1660
1668
  if (composing || isSame) {
1661
1669
  return;
1662
1670
  }
1663
- const shouldShow = this.getShouldShow(oldState);
1664
- if (!shouldShow) {
1671
+ const shouldShow2 = this.getShouldShow(oldState);
1672
+ if (!shouldShow2) {
1665
1673
  this.hide();
1666
1674
  return;
1667
1675
  }
@@ -1749,6 +1757,9 @@ var BubbleMenuView = class {
1749
1757
  this.element.style.position = strategy;
1750
1758
  this.element.style.left = `${x}px`;
1751
1759
  this.element.style.top = `${y}px`;
1760
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
1761
+ this.floatingUIOptions.onUpdate();
1762
+ }
1752
1763
  });
1753
1764
  }
1754
1765
  update(view, oldState) {
@@ -1782,14 +1793,28 @@ var BubbleMenuView = class {
1782
1793
  }
1783
1794
  show() {
1784
1795
  var _a;
1796
+ if (this.isVisible) {
1797
+ return;
1798
+ }
1785
1799
  this.element.style.visibility = "visible";
1786
1800
  this.element.style.opacity = "1";
1787
1801
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
1802
+ if (this.floatingUIOptions.onShow) {
1803
+ this.floatingUIOptions.onShow();
1804
+ }
1805
+ this.isVisible = true;
1788
1806
  }
1789
1807
  hide() {
1808
+ if (!this.isVisible) {
1809
+ return;
1810
+ }
1790
1811
  this.element.style.visibility = "hidden";
1791
1812
  this.element.style.opacity = "0";
1792
1813
  this.element.remove();
1814
+ if (this.floatingUIOptions.onHide) {
1815
+ this.floatingUIOptions.onHide();
1816
+ }
1817
+ this.isVisible = false;
1793
1818
  }
1794
1819
  destroy() {
1795
1820
  this.hide();
@@ -1797,6 +1822,9 @@ var BubbleMenuView = class {
1797
1822
  this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
1798
1823
  this.editor.off("focus", this.focusHandler);
1799
1824
  this.editor.off("blur", this.blurHandler);
1825
+ if (this.floatingUIOptions.onDestroy) {
1826
+ this.floatingUIOptions.onDestroy();
1827
+ }
1800
1828
  }
1801
1829
  };
1802
1830
  var BubbleMenuPlugin = (options) => {
@@ -1805,9 +1833,34 @@ var BubbleMenuPlugin = (options) => {
1805
1833
  view: (view) => new BubbleMenuView({ view, ...options })
1806
1834
  });
1807
1835
  };
1836
+ var BubbleMenu = Extension.create({
1837
+ name: "bubbleMenu",
1838
+ addOptions() {
1839
+ return {
1840
+ element: null,
1841
+ pluginKey: "bubbleMenu",
1842
+ updateDelay: void 0,
1843
+ shouldShow: null
1844
+ };
1845
+ },
1846
+ addProseMirrorPlugins() {
1847
+ if (!this.options.element) {
1848
+ return [];
1849
+ }
1850
+ return [
1851
+ BubbleMenuPlugin({
1852
+ pluginKey: this.options.pluginKey,
1853
+ editor: this.editor,
1854
+ element: this.options.element,
1855
+ updateDelay: this.options.updateDelay,
1856
+ shouldShow: this.options.shouldShow
1857
+ })
1858
+ ];
1859
+ }
1860
+ });
1808
1861
 
1809
1862
  // src/menus/BubbleMenu.ts
1810
- var BubbleMenu = {
1863
+ var BubbleMenu2 = {
1811
1864
  name: "BubbleMenu",
1812
1865
  props: {
1813
1866
  pluginKey: {
@@ -1868,18 +1921,20 @@ var BubbleMenu = {
1868
1921
  }
1869
1922
  };
1870
1923
 
1871
- // ../extension-floating-menu/src/floating-menu-plugin.ts
1924
+ // ../extension-floating-menu/dist/index.js
1925
+ import { Extension as Extension2 } from "@tiptap/core";
1872
1926
  import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
1873
1927
  import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1874
1928
  var FloatingMenuView = class {
1875
1929
  constructor({ editor, element, view, options, shouldShow }) {
1876
1930
  this.preventHide = false;
1877
- this.shouldShow = ({ view, state }) => {
1931
+ this.isVisible = false;
1932
+ this.shouldShow = ({ view: view2, state }) => {
1878
1933
  const { selection } = state;
1879
1934
  const { $anchor, empty } = selection;
1880
1935
  const isRootDepth = $anchor.depth === 1;
1881
1936
  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) {
1937
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
1883
1938
  return false;
1884
1939
  }
1885
1940
  return true;
@@ -1896,14 +1951,14 @@ var FloatingMenuView = class {
1896
1951
  hide: false,
1897
1952
  inline: false
1898
1953
  };
1899
- this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
1900
- const { composing } = view;
1954
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
1955
+ const { composing } = view2;
1901
1956
  const isSame = !selectionChanged && !docChanged;
1902
1957
  if (composing || isSame) {
1903
1958
  return;
1904
1959
  }
1905
- const shouldShow = this.getShouldShow(oldState);
1906
- if (!shouldShow) {
1960
+ const shouldShow2 = this.getShouldShow(oldState);
1961
+ if (!shouldShow2) {
1907
1962
  this.hide();
1908
1963
  return;
1909
1964
  }
@@ -2020,6 +2075,9 @@ var FloatingMenuView = class {
2020
2075
  this.element.style.position = strategy;
2021
2076
  this.element.style.left = `${x}px`;
2022
2077
  this.element.style.top = `${y}px`;
2078
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
2079
+ this.floatingUIOptions.onUpdate();
2080
+ }
2023
2081
  });
2024
2082
  }
2025
2083
  update(view, oldState) {
@@ -2029,20 +2087,37 @@ var FloatingMenuView = class {
2029
2087
  }
2030
2088
  show() {
2031
2089
  var _a;
2090
+ if (this.isVisible) {
2091
+ return;
2092
+ }
2032
2093
  this.element.style.visibility = "visible";
2033
2094
  this.element.style.opacity = "1";
2034
2095
  (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
2096
+ if (this.floatingUIOptions.onShow) {
2097
+ this.floatingUIOptions.onShow();
2098
+ }
2099
+ this.isVisible = true;
2035
2100
  }
2036
2101
  hide() {
2102
+ if (!this.isVisible) {
2103
+ return;
2104
+ }
2037
2105
  this.element.style.visibility = "hidden";
2038
2106
  this.element.style.opacity = "0";
2039
2107
  this.element.remove();
2108
+ if (this.floatingUIOptions.onHide) {
2109
+ this.floatingUIOptions.onHide();
2110
+ }
2111
+ this.isVisible = false;
2040
2112
  }
2041
2113
  destroy() {
2042
2114
  this.hide();
2043
2115
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2044
2116
  this.editor.off("focus", this.focusHandler);
2045
2117
  this.editor.off("blur", this.blurHandler);
2118
+ if (this.floatingUIOptions.onDestroy) {
2119
+ this.floatingUIOptions.onDestroy();
2120
+ }
2046
2121
  }
2047
2122
  };
2048
2123
  var FloatingMenuPlugin = (options) => {
@@ -2051,9 +2126,34 @@ var FloatingMenuPlugin = (options) => {
2051
2126
  view: (view) => new FloatingMenuView({ view, ...options })
2052
2127
  });
2053
2128
  };
2129
+ var FloatingMenu = Extension2.create({
2130
+ name: "floatingMenu",
2131
+ addOptions() {
2132
+ return {
2133
+ element: null,
2134
+ options: {},
2135
+ pluginKey: "floatingMenu",
2136
+ shouldShow: null
2137
+ };
2138
+ },
2139
+ addProseMirrorPlugins() {
2140
+ if (!this.options.element) {
2141
+ return [];
2142
+ }
2143
+ return [
2144
+ FloatingMenuPlugin({
2145
+ pluginKey: this.options.pluginKey,
2146
+ editor: this.editor,
2147
+ element: this.options.element,
2148
+ options: this.options.options,
2149
+ shouldShow: this.options.shouldShow
2150
+ })
2151
+ ];
2152
+ }
2153
+ });
2054
2154
 
2055
2155
  // src/menus/FloatingMenu.ts
2056
- var FloatingMenu = {
2156
+ var FloatingMenu2 = {
2057
2157
  name: "FloatingMenu",
2058
2158
  props: {
2059
2159
  pluginKey: {
@@ -2106,7 +2206,7 @@ var FloatingMenu = {
2106
2206
  }
2107
2207
  };
2108
2208
  export {
2109
- BubbleMenu,
2110
- FloatingMenu
2209
+ BubbleMenu2 as BubbleMenu,
2210
+ FloatingMenu2 as FloatingMenu
2111
2211
  };
2112
2212
  //# sourceMappingURL=index.js.map