@tiptap/vue-2 3.0.0-beta.1 → 3.0.0-beta.3
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 +82 -28
- package/dist/menus/index.cjs.map +1 -1
- package/dist/menus/index.d.cts +1 -1
- package/dist/menus/index.d.ts +1 -1
- package/dist/menus/index.js +76 -22
- 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({
|
|
@@ -1634,12 +1637,12 @@ var BubbleMenuView = class {
|
|
|
1634
1637
|
hide: false,
|
|
1635
1638
|
inline: false
|
|
1636
1639
|
};
|
|
1637
|
-
this.shouldShow = ({ view, state, from, to }) => {
|
|
1640
|
+
this.shouldShow = ({ view: view2, state, from, to }) => {
|
|
1638
1641
|
const { doc, selection } = state;
|
|
1639
1642
|
const { empty } = selection;
|
|
1640
|
-
const isEmptyTextBlock = !doc.textBetween(from, to).length && (0,
|
|
1643
|
+
const isEmptyTextBlock = !doc.textBetween(from, to).length && (0, import_core3.isTextSelection)(state.selection);
|
|
1641
1644
|
const isChildOfMenu = this.element.contains(document.activeElement);
|
|
1642
|
-
const hasEditorFocus =
|
|
1645
|
+
const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
|
|
1643
1646
|
if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
|
|
1644
1647
|
return false;
|
|
1645
1648
|
}
|
|
@@ -1668,9 +1671,9 @@ var BubbleMenuView = class {
|
|
|
1668
1671
|
}
|
|
1669
1672
|
this.hide();
|
|
1670
1673
|
};
|
|
1671
|
-
this.handleDebouncedUpdate = (
|
|
1672
|
-
const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(
|
|
1673
|
-
const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(
|
|
1674
|
+
this.handleDebouncedUpdate = (view2, oldState) => {
|
|
1675
|
+
const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
|
|
1676
|
+
const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
|
|
1674
1677
|
if (!selectionChanged && !docChanged) {
|
|
1675
1678
|
return;
|
|
1676
1679
|
}
|
|
@@ -1678,17 +1681,17 @@ var BubbleMenuView = class {
|
|
|
1678
1681
|
clearTimeout(this.updateDebounceTimer);
|
|
1679
1682
|
}
|
|
1680
1683
|
this.updateDebounceTimer = window.setTimeout(() => {
|
|
1681
|
-
this.updateHandler(
|
|
1684
|
+
this.updateHandler(view2, selectionChanged, docChanged, oldState);
|
|
1682
1685
|
}, this.updateDelay);
|
|
1683
1686
|
};
|
|
1684
|
-
this.updateHandler = (
|
|
1685
|
-
const { composing } =
|
|
1687
|
+
this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
|
|
1688
|
+
const { composing } = view2;
|
|
1686
1689
|
const isSame = !selectionChanged && !docChanged;
|
|
1687
1690
|
if (composing || isSame) {
|
|
1688
1691
|
return;
|
|
1689
1692
|
}
|
|
1690
|
-
const
|
|
1691
|
-
if (!
|
|
1693
|
+
const shouldShow2 = this.getShouldShow(oldState);
|
|
1694
|
+
if (!shouldShow2) {
|
|
1692
1695
|
this.hide();
|
|
1693
1696
|
return;
|
|
1694
1697
|
}
|
|
@@ -1765,7 +1768,7 @@ var BubbleMenuView = class {
|
|
|
1765
1768
|
updatePosition() {
|
|
1766
1769
|
const { selection } = this.editor.state;
|
|
1767
1770
|
const virtualElement = {
|
|
1768
|
-
getBoundingClientRect: () => (0,
|
|
1771
|
+
getBoundingClientRect: () => (0, import_core3.posToDOMRect)(this.view, selection.from, selection.to)
|
|
1769
1772
|
};
|
|
1770
1773
|
computePosition2(virtualElement, this.element, {
|
|
1771
1774
|
placement: this.floatingUIOptions.placement,
|
|
@@ -1832,9 +1835,34 @@ var BubbleMenuPlugin = (options) => {
|
|
|
1832
1835
|
view: (view) => new BubbleMenuView({ view, ...options })
|
|
1833
1836
|
});
|
|
1834
1837
|
};
|
|
1838
|
+
var BubbleMenu = import_core2.Extension.create({
|
|
1839
|
+
name: "bubbleMenu",
|
|
1840
|
+
addOptions() {
|
|
1841
|
+
return {
|
|
1842
|
+
element: null,
|
|
1843
|
+
pluginKey: "bubbleMenu",
|
|
1844
|
+
updateDelay: void 0,
|
|
1845
|
+
shouldShow: null
|
|
1846
|
+
};
|
|
1847
|
+
},
|
|
1848
|
+
addProseMirrorPlugins() {
|
|
1849
|
+
if (!this.options.element) {
|
|
1850
|
+
return [];
|
|
1851
|
+
}
|
|
1852
|
+
return [
|
|
1853
|
+
BubbleMenuPlugin({
|
|
1854
|
+
pluginKey: this.options.pluginKey,
|
|
1855
|
+
editor: this.editor,
|
|
1856
|
+
element: this.options.element,
|
|
1857
|
+
updateDelay: this.options.updateDelay,
|
|
1858
|
+
shouldShow: this.options.shouldShow
|
|
1859
|
+
})
|
|
1860
|
+
];
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1835
1863
|
|
|
1836
1864
|
// src/menus/BubbleMenu.ts
|
|
1837
|
-
var
|
|
1865
|
+
var BubbleMenu2 = {
|
|
1838
1866
|
name: "BubbleMenu",
|
|
1839
1867
|
props: {
|
|
1840
1868
|
pluginKey: {
|
|
@@ -1895,18 +1923,19 @@ var BubbleMenu = {
|
|
|
1895
1923
|
}
|
|
1896
1924
|
};
|
|
1897
1925
|
|
|
1898
|
-
// ../extension-floating-menu/
|
|
1899
|
-
var
|
|
1926
|
+
// ../extension-floating-menu/dist/index.js
|
|
1927
|
+
var import_core4 = require("@tiptap/core");
|
|
1928
|
+
var import_core5 = require("@tiptap/core");
|
|
1900
1929
|
var import_state2 = require("@tiptap/pm/state");
|
|
1901
1930
|
var FloatingMenuView = class {
|
|
1902
1931
|
constructor({ editor, element, view, options, shouldShow }) {
|
|
1903
1932
|
this.preventHide = false;
|
|
1904
|
-
this.shouldShow = ({ view, state }) => {
|
|
1933
|
+
this.shouldShow = ({ view: view2, state }) => {
|
|
1905
1934
|
const { selection } = state;
|
|
1906
1935
|
const { $anchor, empty } = selection;
|
|
1907
1936
|
const isRootDepth = $anchor.depth === 1;
|
|
1908
1937
|
const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
|
|
1909
|
-
if (!
|
|
1938
|
+
if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
|
|
1910
1939
|
return false;
|
|
1911
1940
|
}
|
|
1912
1941
|
return true;
|
|
@@ -1923,14 +1952,14 @@ var FloatingMenuView = class {
|
|
|
1923
1952
|
hide: false,
|
|
1924
1953
|
inline: false
|
|
1925
1954
|
};
|
|
1926
|
-
this.updateHandler = (
|
|
1927
|
-
const { composing } =
|
|
1955
|
+
this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
|
|
1956
|
+
const { composing } = view2;
|
|
1928
1957
|
const isSame = !selectionChanged && !docChanged;
|
|
1929
1958
|
if (composing || isSame) {
|
|
1930
1959
|
return;
|
|
1931
1960
|
}
|
|
1932
|
-
const
|
|
1933
|
-
if (!
|
|
1961
|
+
const shouldShow2 = this.getShouldShow(oldState);
|
|
1962
|
+
if (!shouldShow2) {
|
|
1934
1963
|
this.hide();
|
|
1935
1964
|
return;
|
|
1936
1965
|
}
|
|
@@ -1976,7 +2005,7 @@ var FloatingMenuView = class {
|
|
|
1976
2005
|
}
|
|
1977
2006
|
}
|
|
1978
2007
|
getTextContent(node) {
|
|
1979
|
-
return (0,
|
|
2008
|
+
return (0, import_core5.getText)(node, { textSerializers: (0, import_core5.getTextSerializersFromSchema)(this.editor.schema) });
|
|
1980
2009
|
}
|
|
1981
2010
|
get middlewares() {
|
|
1982
2011
|
const middlewares = [];
|
|
@@ -2036,7 +2065,7 @@ var FloatingMenuView = class {
|
|
|
2036
2065
|
updatePosition() {
|
|
2037
2066
|
const { selection } = this.editor.state;
|
|
2038
2067
|
const virtualElement = {
|
|
2039
|
-
getBoundingClientRect: () => (0,
|
|
2068
|
+
getBoundingClientRect: () => (0, import_core5.posToDOMRect)(this.view, selection.from, selection.to)
|
|
2040
2069
|
};
|
|
2041
2070
|
computePosition2(virtualElement, this.element, {
|
|
2042
2071
|
placement: this.floatingUIOptions.placement,
|
|
@@ -2078,9 +2107,34 @@ var FloatingMenuPlugin = (options) => {
|
|
|
2078
2107
|
view: (view) => new FloatingMenuView({ view, ...options })
|
|
2079
2108
|
});
|
|
2080
2109
|
};
|
|
2110
|
+
var FloatingMenu = import_core4.Extension.create({
|
|
2111
|
+
name: "floatingMenu",
|
|
2112
|
+
addOptions() {
|
|
2113
|
+
return {
|
|
2114
|
+
element: null,
|
|
2115
|
+
options: {},
|
|
2116
|
+
pluginKey: "floatingMenu",
|
|
2117
|
+
shouldShow: null
|
|
2118
|
+
};
|
|
2119
|
+
},
|
|
2120
|
+
addProseMirrorPlugins() {
|
|
2121
|
+
if (!this.options.element) {
|
|
2122
|
+
return [];
|
|
2123
|
+
}
|
|
2124
|
+
return [
|
|
2125
|
+
FloatingMenuPlugin({
|
|
2126
|
+
pluginKey: this.options.pluginKey,
|
|
2127
|
+
editor: this.editor,
|
|
2128
|
+
element: this.options.element,
|
|
2129
|
+
options: this.options.options,
|
|
2130
|
+
shouldShow: this.options.shouldShow
|
|
2131
|
+
})
|
|
2132
|
+
];
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2081
2135
|
|
|
2082
2136
|
// src/menus/FloatingMenu.ts
|
|
2083
|
-
var
|
|
2137
|
+
var FloatingMenu2 = {
|
|
2084
2138
|
name: "FloatingMenu",
|
|
2085
2139
|
props: {
|
|
2086
2140
|
pluginKey: {
|