@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.
- package/dist/menus/index.cjs +129 -29
- package/dist/menus/index.cjs.map +1 -1
- package/dist/menus/index.d.cts +9 -1
- package/dist/menus/index.d.ts +9 -1
- package/dist/menus/index.js +123 -23
- package/dist/menus/index.js.map +1 -1
- package/package.json +9 -9
package/dist/menus/index.cjs
CHANGED
|
@@ -20,11 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/menus/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BubbleMenu: () =>
|
|
24
|
-
FloatingMenu: () =>
|
|
23
|
+
BubbleMenu: () => BubbleMenu2,
|
|
24
|
+
FloatingMenu: () => FloatingMenu2
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
|
+
// ../extension-bubble-menu/dist/index.js
|
|
29
|
+
var import_core2 = require("@tiptap/core");
|
|
30
|
+
|
|
28
31
|
// ../../node_modules/.pnpm/@floating-ui+utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
|
29
32
|
var sides = ["top", "right", "bottom", "left"];
|
|
30
33
|
var alignments = ["start", "end"];
|
|
@@ -1608,8 +1611,8 @@ var computePosition2 = (reference, floating, options) => {
|
|
|
1608
1611
|
});
|
|
1609
1612
|
};
|
|
1610
1613
|
|
|
1611
|
-
// ../extension-bubble-menu/
|
|
1612
|
-
var
|
|
1614
|
+
// ../extension-bubble-menu/dist/index.js
|
|
1615
|
+
var import_core3 = require("@tiptap/core");
|
|
1613
1616
|
var import_state = require("@tiptap/pm/state");
|
|
1614
1617
|
var BubbleMenuView = class {
|
|
1615
1618
|
constructor({
|
|
@@ -1622,6 +1625,7 @@ var BubbleMenuView = class {
|
|
|
1622
1625
|
options
|
|
1623
1626
|
}) {
|
|
1624
1627
|
this.preventHide = false;
|
|
1628
|
+
this.isVisible = false;
|
|
1625
1629
|
this.floatingUIOptions = {
|
|
1626
1630
|
strategy: "absolute",
|
|
1627
1631
|
placement: "top",
|
|
@@ -1632,14 +1636,18 @@ var BubbleMenuView = class {
|
|
|
1632
1636
|
size: false,
|
|
1633
1637
|
autoPlacement: false,
|
|
1634
1638
|
hide: false,
|
|
1635
|
-
inline: false
|
|
1639
|
+
inline: false,
|
|
1640
|
+
onShow: void 0,
|
|
1641
|
+
onHide: void 0,
|
|
1642
|
+
onUpdate: void 0,
|
|
1643
|
+
onDestroy: void 0
|
|
1636
1644
|
};
|
|
1637
|
-
this.shouldShow = ({ view, state, from, to }) => {
|
|
1645
|
+
this.shouldShow = ({ view: view2, state, from, to }) => {
|
|
1638
1646
|
const { doc, selection } = state;
|
|
1639
1647
|
const { empty } = selection;
|
|
1640
|
-
const isEmptyTextBlock = !doc.textBetween(from, to).length && (0,
|
|
1648
|
+
const isEmptyTextBlock = !doc.textBetween(from, to).length && (0, import_core3.isTextSelection)(state.selection);
|
|
1641
1649
|
const isChildOfMenu = this.element.contains(document.activeElement);
|
|
1642
|
-
const hasEditorFocus =
|
|
1650
|
+
const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
|
|
1643
1651
|
if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
|
|
1644
1652
|
return false;
|
|
1645
1653
|
}
|
|
@@ -1668,9 +1676,9 @@ var BubbleMenuView = class {
|
|
|
1668
1676
|
}
|
|
1669
1677
|
this.hide();
|
|
1670
1678
|
};
|
|
1671
|
-
this.handleDebouncedUpdate = (
|
|
1672
|
-
const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(
|
|
1673
|
-
const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(
|
|
1679
|
+
this.handleDebouncedUpdate = (view2, oldState) => {
|
|
1680
|
+
const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
|
|
1681
|
+
const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
|
|
1674
1682
|
if (!selectionChanged && !docChanged) {
|
|
1675
1683
|
return;
|
|
1676
1684
|
}
|
|
@@ -1678,17 +1686,17 @@ var BubbleMenuView = class {
|
|
|
1678
1686
|
clearTimeout(this.updateDebounceTimer);
|
|
1679
1687
|
}
|
|
1680
1688
|
this.updateDebounceTimer = window.setTimeout(() => {
|
|
1681
|
-
this.updateHandler(
|
|
1689
|
+
this.updateHandler(view2, selectionChanged, docChanged, oldState);
|
|
1682
1690
|
}, this.updateDelay);
|
|
1683
1691
|
};
|
|
1684
|
-
this.updateHandler = (
|
|
1685
|
-
const { composing } =
|
|
1692
|
+
this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
|
|
1693
|
+
const { composing } = view2;
|
|
1686
1694
|
const isSame = !selectionChanged && !docChanged;
|
|
1687
1695
|
if (composing || isSame) {
|
|
1688
1696
|
return;
|
|
1689
1697
|
}
|
|
1690
|
-
const
|
|
1691
|
-
if (!
|
|
1698
|
+
const shouldShow2 = this.getShouldShow(oldState);
|
|
1699
|
+
if (!shouldShow2) {
|
|
1692
1700
|
this.hide();
|
|
1693
1701
|
return;
|
|
1694
1702
|
}
|
|
@@ -1765,7 +1773,7 @@ var BubbleMenuView = class {
|
|
|
1765
1773
|
updatePosition() {
|
|
1766
1774
|
const { selection } = this.editor.state;
|
|
1767
1775
|
const virtualElement = {
|
|
1768
|
-
getBoundingClientRect: () => (0,
|
|
1776
|
+
getBoundingClientRect: () => (0, import_core3.posToDOMRect)(this.view, selection.from, selection.to)
|
|
1769
1777
|
};
|
|
1770
1778
|
computePosition2(virtualElement, this.element, {
|
|
1771
1779
|
placement: this.floatingUIOptions.placement,
|
|
@@ -1776,6 +1784,9 @@ var BubbleMenuView = class {
|
|
|
1776
1784
|
this.element.style.position = strategy;
|
|
1777
1785
|
this.element.style.left = `${x}px`;
|
|
1778
1786
|
this.element.style.top = `${y}px`;
|
|
1787
|
+
if (this.isVisible && this.floatingUIOptions.onUpdate) {
|
|
1788
|
+
this.floatingUIOptions.onUpdate();
|
|
1789
|
+
}
|
|
1779
1790
|
});
|
|
1780
1791
|
}
|
|
1781
1792
|
update(view, oldState) {
|
|
@@ -1809,14 +1820,28 @@ var BubbleMenuView = class {
|
|
|
1809
1820
|
}
|
|
1810
1821
|
show() {
|
|
1811
1822
|
var _a;
|
|
1823
|
+
if (this.isVisible) {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1812
1826
|
this.element.style.visibility = "visible";
|
|
1813
1827
|
this.element.style.opacity = "1";
|
|
1814
1828
|
(_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
|
|
1829
|
+
if (this.floatingUIOptions.onShow) {
|
|
1830
|
+
this.floatingUIOptions.onShow();
|
|
1831
|
+
}
|
|
1832
|
+
this.isVisible = true;
|
|
1815
1833
|
}
|
|
1816
1834
|
hide() {
|
|
1835
|
+
if (!this.isVisible) {
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1817
1838
|
this.element.style.visibility = "hidden";
|
|
1818
1839
|
this.element.style.opacity = "0";
|
|
1819
1840
|
this.element.remove();
|
|
1841
|
+
if (this.floatingUIOptions.onHide) {
|
|
1842
|
+
this.floatingUIOptions.onHide();
|
|
1843
|
+
}
|
|
1844
|
+
this.isVisible = false;
|
|
1820
1845
|
}
|
|
1821
1846
|
destroy() {
|
|
1822
1847
|
this.hide();
|
|
@@ -1824,6 +1849,9 @@ var BubbleMenuView = class {
|
|
|
1824
1849
|
this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
|
|
1825
1850
|
this.editor.off("focus", this.focusHandler);
|
|
1826
1851
|
this.editor.off("blur", this.blurHandler);
|
|
1852
|
+
if (this.floatingUIOptions.onDestroy) {
|
|
1853
|
+
this.floatingUIOptions.onDestroy();
|
|
1854
|
+
}
|
|
1827
1855
|
}
|
|
1828
1856
|
};
|
|
1829
1857
|
var BubbleMenuPlugin = (options) => {
|
|
@@ -1832,9 +1860,34 @@ var BubbleMenuPlugin = (options) => {
|
|
|
1832
1860
|
view: (view) => new BubbleMenuView({ view, ...options })
|
|
1833
1861
|
});
|
|
1834
1862
|
};
|
|
1863
|
+
var BubbleMenu = import_core2.Extension.create({
|
|
1864
|
+
name: "bubbleMenu",
|
|
1865
|
+
addOptions() {
|
|
1866
|
+
return {
|
|
1867
|
+
element: null,
|
|
1868
|
+
pluginKey: "bubbleMenu",
|
|
1869
|
+
updateDelay: void 0,
|
|
1870
|
+
shouldShow: null
|
|
1871
|
+
};
|
|
1872
|
+
},
|
|
1873
|
+
addProseMirrorPlugins() {
|
|
1874
|
+
if (!this.options.element) {
|
|
1875
|
+
return [];
|
|
1876
|
+
}
|
|
1877
|
+
return [
|
|
1878
|
+
BubbleMenuPlugin({
|
|
1879
|
+
pluginKey: this.options.pluginKey,
|
|
1880
|
+
editor: this.editor,
|
|
1881
|
+
element: this.options.element,
|
|
1882
|
+
updateDelay: this.options.updateDelay,
|
|
1883
|
+
shouldShow: this.options.shouldShow
|
|
1884
|
+
})
|
|
1885
|
+
];
|
|
1886
|
+
}
|
|
1887
|
+
});
|
|
1835
1888
|
|
|
1836
1889
|
// src/menus/BubbleMenu.ts
|
|
1837
|
-
var
|
|
1890
|
+
var BubbleMenu2 = {
|
|
1838
1891
|
name: "BubbleMenu",
|
|
1839
1892
|
props: {
|
|
1840
1893
|
pluginKey: {
|
|
@@ -1895,18 +1948,20 @@ var BubbleMenu = {
|
|
|
1895
1948
|
}
|
|
1896
1949
|
};
|
|
1897
1950
|
|
|
1898
|
-
// ../extension-floating-menu/
|
|
1899
|
-
var
|
|
1951
|
+
// ../extension-floating-menu/dist/index.js
|
|
1952
|
+
var import_core4 = require("@tiptap/core");
|
|
1953
|
+
var import_core5 = require("@tiptap/core");
|
|
1900
1954
|
var import_state2 = require("@tiptap/pm/state");
|
|
1901
1955
|
var FloatingMenuView = class {
|
|
1902
1956
|
constructor({ editor, element, view, options, shouldShow }) {
|
|
1903
1957
|
this.preventHide = false;
|
|
1904
|
-
this.
|
|
1958
|
+
this.isVisible = false;
|
|
1959
|
+
this.shouldShow = ({ view: view2, state }) => {
|
|
1905
1960
|
const { selection } = state;
|
|
1906
1961
|
const { $anchor, empty } = selection;
|
|
1907
1962
|
const isRootDepth = $anchor.depth === 1;
|
|
1908
1963
|
const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
|
|
1909
|
-
if (!
|
|
1964
|
+
if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
|
|
1910
1965
|
return false;
|
|
1911
1966
|
}
|
|
1912
1967
|
return true;
|
|
@@ -1923,14 +1978,14 @@ var FloatingMenuView = class {
|
|
|
1923
1978
|
hide: false,
|
|
1924
1979
|
inline: false
|
|
1925
1980
|
};
|
|
1926
|
-
this.updateHandler = (
|
|
1927
|
-
const { composing } =
|
|
1981
|
+
this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
|
|
1982
|
+
const { composing } = view2;
|
|
1928
1983
|
const isSame = !selectionChanged && !docChanged;
|
|
1929
1984
|
if (composing || isSame) {
|
|
1930
1985
|
return;
|
|
1931
1986
|
}
|
|
1932
|
-
const
|
|
1933
|
-
if (!
|
|
1987
|
+
const shouldShow2 = this.getShouldShow(oldState);
|
|
1988
|
+
if (!shouldShow2) {
|
|
1934
1989
|
this.hide();
|
|
1935
1990
|
return;
|
|
1936
1991
|
}
|
|
@@ -1976,7 +2031,7 @@ var FloatingMenuView = class {
|
|
|
1976
2031
|
}
|
|
1977
2032
|
}
|
|
1978
2033
|
getTextContent(node) {
|
|
1979
|
-
return (0,
|
|
2034
|
+
return (0, import_core5.getText)(node, { textSerializers: (0, import_core5.getTextSerializersFromSchema)(this.editor.schema) });
|
|
1980
2035
|
}
|
|
1981
2036
|
get middlewares() {
|
|
1982
2037
|
const middlewares = [];
|
|
@@ -2036,7 +2091,7 @@ var FloatingMenuView = class {
|
|
|
2036
2091
|
updatePosition() {
|
|
2037
2092
|
const { selection } = this.editor.state;
|
|
2038
2093
|
const virtualElement = {
|
|
2039
|
-
getBoundingClientRect: () => (0,
|
|
2094
|
+
getBoundingClientRect: () => (0, import_core5.posToDOMRect)(this.view, selection.from, selection.to)
|
|
2040
2095
|
};
|
|
2041
2096
|
computePosition2(virtualElement, this.element, {
|
|
2042
2097
|
placement: this.floatingUIOptions.placement,
|
|
@@ -2047,6 +2102,9 @@ var FloatingMenuView = class {
|
|
|
2047
2102
|
this.element.style.position = strategy;
|
|
2048
2103
|
this.element.style.left = `${x}px`;
|
|
2049
2104
|
this.element.style.top = `${y}px`;
|
|
2105
|
+
if (this.isVisible && this.floatingUIOptions.onUpdate) {
|
|
2106
|
+
this.floatingUIOptions.onUpdate();
|
|
2107
|
+
}
|
|
2050
2108
|
});
|
|
2051
2109
|
}
|
|
2052
2110
|
update(view, oldState) {
|
|
@@ -2056,20 +2114,37 @@ var FloatingMenuView = class {
|
|
|
2056
2114
|
}
|
|
2057
2115
|
show() {
|
|
2058
2116
|
var _a;
|
|
2117
|
+
if (this.isVisible) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2059
2120
|
this.element.style.visibility = "visible";
|
|
2060
2121
|
this.element.style.opacity = "1";
|
|
2061
2122
|
(_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
|
|
2123
|
+
if (this.floatingUIOptions.onShow) {
|
|
2124
|
+
this.floatingUIOptions.onShow();
|
|
2125
|
+
}
|
|
2126
|
+
this.isVisible = true;
|
|
2062
2127
|
}
|
|
2063
2128
|
hide() {
|
|
2129
|
+
if (!this.isVisible) {
|
|
2130
|
+
return;
|
|
2131
|
+
}
|
|
2064
2132
|
this.element.style.visibility = "hidden";
|
|
2065
2133
|
this.element.style.opacity = "0";
|
|
2066
2134
|
this.element.remove();
|
|
2135
|
+
if (this.floatingUIOptions.onHide) {
|
|
2136
|
+
this.floatingUIOptions.onHide();
|
|
2137
|
+
}
|
|
2138
|
+
this.isVisible = false;
|
|
2067
2139
|
}
|
|
2068
2140
|
destroy() {
|
|
2069
2141
|
this.hide();
|
|
2070
2142
|
this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
|
|
2071
2143
|
this.editor.off("focus", this.focusHandler);
|
|
2072
2144
|
this.editor.off("blur", this.blurHandler);
|
|
2145
|
+
if (this.floatingUIOptions.onDestroy) {
|
|
2146
|
+
this.floatingUIOptions.onDestroy();
|
|
2147
|
+
}
|
|
2073
2148
|
}
|
|
2074
2149
|
};
|
|
2075
2150
|
var FloatingMenuPlugin = (options) => {
|
|
@@ -2078,9 +2153,34 @@ var FloatingMenuPlugin = (options) => {
|
|
|
2078
2153
|
view: (view) => new FloatingMenuView({ view, ...options })
|
|
2079
2154
|
});
|
|
2080
2155
|
};
|
|
2156
|
+
var FloatingMenu = import_core4.Extension.create({
|
|
2157
|
+
name: "floatingMenu",
|
|
2158
|
+
addOptions() {
|
|
2159
|
+
return {
|
|
2160
|
+
element: null,
|
|
2161
|
+
options: {},
|
|
2162
|
+
pluginKey: "floatingMenu",
|
|
2163
|
+
shouldShow: null
|
|
2164
|
+
};
|
|
2165
|
+
},
|
|
2166
|
+
addProseMirrorPlugins() {
|
|
2167
|
+
if (!this.options.element) {
|
|
2168
|
+
return [];
|
|
2169
|
+
}
|
|
2170
|
+
return [
|
|
2171
|
+
FloatingMenuPlugin({
|
|
2172
|
+
pluginKey: this.options.pluginKey,
|
|
2173
|
+
editor: this.editor,
|
|
2174
|
+
element: this.options.element,
|
|
2175
|
+
options: this.options.options,
|
|
2176
|
+
shouldShow: this.options.shouldShow
|
|
2177
|
+
})
|
|
2178
|
+
];
|
|
2179
|
+
}
|
|
2180
|
+
});
|
|
2081
2181
|
|
|
2082
2182
|
// src/menus/FloatingMenu.ts
|
|
2083
|
-
var
|
|
2183
|
+
var FloatingMenu2 = {
|
|
2084
2184
|
name: "FloatingMenu",
|
|
2085
2185
|
props: {
|
|
2086
2186
|
pluginKey: {
|