@tiptap/vue-2 3.10.6 → 3.10.8

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,8 +1,8 @@
1
- import { Editor } from '@tiptap/core';
2
1
  import { VirtualElement, offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
2
+ import { Editor } from '@tiptap/core';
3
3
  import { PluginKey, EditorState } from '@tiptap/pm/state';
4
4
  import { EditorView } from '@tiptap/pm/view';
5
- import Vue, { Component } from 'vue';
5
+ import { VNode, Component } from 'vue';
6
6
 
7
7
  interface BubbleMenuPluginProps {
8
8
  /**
@@ -94,7 +94,12 @@ interface BubbleMenuPluginProps {
94
94
  };
95
95
  }
96
96
 
97
- interface BubbleMenuInterface extends Vue {
97
+ interface BubbleMenuInterface {
98
+ $el: HTMLElement;
99
+ $nextTick: (callback: () => void) => void;
100
+ $slots: {
101
+ default?: VNode[];
102
+ };
98
103
  pluginKey: BubbleMenuPluginProps['pluginKey'];
99
104
  editor: BubbleMenuPluginProps['editor'];
100
105
  updateDelay: BubbleMenuPluginProps['updateDelay'];
@@ -1,8 +1,8 @@
1
- import { Editor } from '@tiptap/core';
2
1
  import { VirtualElement, offset, flip, shift, arrow, size, autoPlacement, hide, inline } from '@floating-ui/dom';
2
+ import { Editor } from '@tiptap/core';
3
3
  import { PluginKey, EditorState } from '@tiptap/pm/state';
4
4
  import { EditorView } from '@tiptap/pm/view';
5
- import Vue, { Component } from 'vue';
5
+ import { VNode, Component } from 'vue';
6
6
 
7
7
  interface BubbleMenuPluginProps {
8
8
  /**
@@ -94,7 +94,12 @@ interface BubbleMenuPluginProps {
94
94
  };
95
95
  }
96
96
 
97
- interface BubbleMenuInterface extends Vue {
97
+ interface BubbleMenuInterface {
98
+ $el: HTMLElement;
99
+ $nextTick: (callback: () => void) => void;
100
+ $slots: {
101
+ default?: VNode[];
102
+ };
98
103
  pluginKey: BubbleMenuPluginProps['pluginKey'];
99
104
  editor: BubbleMenuPluginProps['editor'];
100
105
  updateDelay: BubbleMenuPluginProps['updateDelay'];
@@ -1,6 +1,3 @@
1
- // ../extension-bubble-menu/dist/index.js
2
- import { Extension } from "@tiptap/core";
3
-
4
1
  // ../../node_modules/.pnpm/@floating-ui+utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
5
2
  var sides = ["top", "right", "bottom", "left"];
6
3
  var alignments = ["start", "end"];
@@ -1584,7 +1581,7 @@ var computePosition2 = (reference, floating, options) => {
1584
1581
  });
1585
1582
  };
1586
1583
 
1587
- // ../extension-bubble-menu/dist/index.js
1584
+ // ../extension-bubble-menu/src/bubble-menu-plugin.ts
1588
1585
  import { isTextSelection, posToDOMRect } from "@tiptap/core";
1589
1586
  import { NodeSelection, Plugin, PluginKey } from "@tiptap/pm/state";
1590
1587
  import { CellSelection } from "@tiptap/pm/tables";
@@ -1630,12 +1627,12 @@ var BubbleMenuView = class {
1630
1627
  onUpdate: void 0,
1631
1628
  onDestroy: void 0
1632
1629
  };
1633
- this.shouldShow = ({ view: view2, state, from, to }) => {
1630
+ this.shouldShow = ({ view, state, from, to }) => {
1634
1631
  const { doc, selection } = state;
1635
1632
  const { empty } = selection;
1636
1633
  const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
1637
1634
  const isChildOfMenu = this.element.contains(document.activeElement);
1638
- const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
1635
+ const hasEditorFocus = view.hasFocus() || isChildOfMenu;
1639
1636
  if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
1640
1637
  return false;
1641
1638
  }
@@ -1647,6 +1644,11 @@ var BubbleMenuView = class {
1647
1644
  this.dragstartHandler = () => {
1648
1645
  this.hide();
1649
1646
  };
1647
+ /**
1648
+ * Handles the window resize event to update the position of the bubble menu.
1649
+ * It uses a debounce mechanism to prevent excessive updates.
1650
+ * The delay is defined by the `resizeDelay` property.
1651
+ */
1650
1652
  this.resizeHandler = () => {
1651
1653
  if (this.resizeDebounceTimer) {
1652
1654
  clearTimeout(this.resizeDebounceTimer);
@@ -1659,7 +1661,7 @@ var BubbleMenuView = class {
1659
1661
  setTimeout(() => this.update(this.editor.view));
1660
1662
  };
1661
1663
  this.blurHandler = ({ event }) => {
1662
- var _a2;
1664
+ var _a;
1663
1665
  if (this.editor.isDestroyed) {
1664
1666
  this.destroy();
1665
1667
  return;
@@ -1668,7 +1670,7 @@ var BubbleMenuView = class {
1668
1670
  this.preventHide = false;
1669
1671
  return;
1670
1672
  }
1671
- if ((event == null ? void 0 : event.relatedTarget) && ((_a2 = this.element.parentNode) == null ? void 0 : _a2.contains(event.relatedTarget))) {
1673
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
1672
1674
  return;
1673
1675
  }
1674
1676
  if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
@@ -1676,9 +1678,9 @@ var BubbleMenuView = class {
1676
1678
  }
1677
1679
  this.hide();
1678
1680
  };
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));
1681
+ this.handleDebouncedUpdate = (view, oldState) => {
1682
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
1683
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
1682
1684
  if (!selectionChanged && !docChanged) {
1683
1685
  return;
1684
1686
  }
@@ -1686,17 +1688,17 @@ var BubbleMenuView = class {
1686
1688
  clearTimeout(this.updateDebounceTimer);
1687
1689
  }
1688
1690
  this.updateDebounceTimer = window.setTimeout(() => {
1689
- this.updateHandler(view2, selectionChanged, docChanged, oldState);
1691
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
1690
1692
  }, this.updateDelay);
1691
1693
  };
1692
- this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
1693
- const { composing } = view2;
1694
+ this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
1695
+ const { composing } = view;
1694
1696
  const isSame = !selectionChanged && !docChanged;
1695
1697
  if (composing || isSame) {
1696
1698
  return;
1697
1699
  }
1698
- const shouldShow2 = this.getShouldShow(oldState);
1699
- if (!shouldShow2) {
1700
+ const shouldShow = this.getShouldShow(oldState);
1701
+ if (!shouldShow) {
1700
1702
  this.hide();
1701
1703
  return;
1702
1704
  }
@@ -1916,38 +1918,9 @@ var BubbleMenuPlugin = (options) => {
1916
1918
  view: (view) => new BubbleMenuView({ view, ...options })
1917
1919
  });
1918
1920
  };
1919
- var BubbleMenu = Extension.create({
1920
- name: "bubbleMenu",
1921
- addOptions() {
1922
- return {
1923
- element: null,
1924
- pluginKey: "bubbleMenu",
1925
- updateDelay: void 0,
1926
- appendTo: void 0,
1927
- shouldShow: null
1928
- };
1929
- },
1930
- addProseMirrorPlugins() {
1931
- if (!this.options.element) {
1932
- return [];
1933
- }
1934
- return [
1935
- BubbleMenuPlugin({
1936
- pluginKey: this.options.pluginKey,
1937
- editor: this.editor,
1938
- element: this.options.element,
1939
- updateDelay: this.options.updateDelay,
1940
- options: this.options.options,
1941
- appendTo: this.options.appendTo,
1942
- getReferencedVirtualElement: this.options.getReferencedVirtualElement,
1943
- shouldShow: this.options.shouldShow
1944
- })
1945
- ];
1946
- }
1947
- });
1948
1921
 
1949
1922
  // src/menus/BubbleMenu.ts
1950
- var BubbleMenu2 = {
1923
+ var BubbleMenu = {
1951
1924
  name: "BubbleMenu",
1952
1925
  props: {
1953
1926
  pluginKey: {
@@ -1977,37 +1950,30 @@ var BubbleMenu2 = {
1977
1950
  default: null
1978
1951
  }
1979
1952
  },
1980
- watch: {
1981
- editor: {
1982
- immediate: true,
1983
- handler(editor) {
1984
- if (!editor) {
1985
- return;
1986
- }
1987
- if (!this.$el) {
1988
- return;
1989
- }
1990
- ;
1991
- this.$el.style.visibility = "hidden";
1992
- this.$el.style.position = "absolute";
1993
- this.$el.remove();
1994
- this.$nextTick(() => {
1995
- editor.registerPlugin(
1996
- BubbleMenuPlugin({
1997
- updateDelay: this.updateDelay,
1998
- resizeDelay: this.resizeDelay,
1999
- options: this.options,
2000
- editor,
2001
- element: this.$el,
2002
- pluginKey: this.pluginKey,
2003
- appendTo: this.appendTo,
2004
- shouldShow: this.shouldShow,
2005
- getReferencedVirtualElement: this.getReferencedVirtualElement
2006
- })
2007
- );
2008
- });
2009
- }
1953
+ mounted() {
1954
+ const editor = this.editor;
1955
+ const el = this.$el;
1956
+ if (!editor || !el) {
1957
+ return;
2010
1958
  }
1959
+ el.style.visibility = "hidden";
1960
+ el.style.position = "absolute";
1961
+ el.remove();
1962
+ this.$nextTick(() => {
1963
+ editor.registerPlugin(
1964
+ BubbleMenuPlugin({
1965
+ updateDelay: this.updateDelay,
1966
+ resizeDelay: this.resizeDelay,
1967
+ options: this.options,
1968
+ editor,
1969
+ element: el,
1970
+ pluginKey: this.pluginKey,
1971
+ appendTo: this.appendTo,
1972
+ shouldShow: this.shouldShow,
1973
+ getReferencedVirtualElement: this.getReferencedVirtualElement
1974
+ })
1975
+ );
1976
+ });
2011
1977
  },
2012
1978
  render(createElement) {
2013
1979
  return createElement("div", {}, this.$slots.default);
@@ -2017,20 +1983,19 @@ var BubbleMenu2 = {
2017
1983
  }
2018
1984
  };
2019
1985
 
2020
- // ../extension-floating-menu/dist/index.js
2021
- import { Extension as Extension2 } from "@tiptap/core";
1986
+ // ../extension-floating-menu/src/floating-menu-plugin.ts
2022
1987
  import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
2023
1988
  import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
2024
1989
  var FloatingMenuView = class {
2025
1990
  constructor({ editor, element, view, options, appendTo, shouldShow }) {
2026
1991
  this.preventHide = false;
2027
1992
  this.isVisible = false;
2028
- this.shouldShow = ({ view: view2, state }) => {
1993
+ this.shouldShow = ({ view, state }) => {
2029
1994
  const { selection } = state;
2030
1995
  const { $anchor, empty } = selection;
2031
1996
  const isRootDepth = $anchor.depth === 1;
2032
1997
  const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
2033
- if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
1998
+ if (!view.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
2034
1999
  return false;
2035
2000
  }
2036
2001
  return true;
@@ -2047,14 +2012,14 @@ var FloatingMenuView = class {
2047
2012
  hide: false,
2048
2013
  inline: false
2049
2014
  };
2050
- this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
2051
- const { composing } = view2;
2015
+ this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
2016
+ const { composing } = view;
2052
2017
  const isSame = !selectionChanged && !docChanged;
2053
2018
  if (composing || isSame) {
2054
2019
  return;
2055
2020
  }
2056
- const shouldShow2 = this.getShouldShow(oldState);
2057
- if (!shouldShow2) {
2021
+ const shouldShow = this.getShouldShow(oldState);
2022
+ if (!shouldShow) {
2058
2023
  this.hide();
2059
2024
  return;
2060
2025
  }
@@ -2228,36 +2193,9 @@ var FloatingMenuPlugin = (options) => {
2228
2193
  view: (view) => new FloatingMenuView({ view, ...options })
2229
2194
  });
2230
2195
  };
2231
- var FloatingMenu = Extension2.create({
2232
- name: "floatingMenu",
2233
- addOptions() {
2234
- return {
2235
- element: null,
2236
- options: {},
2237
- pluginKey: "floatingMenu",
2238
- appendTo: void 0,
2239
- shouldShow: null
2240
- };
2241
- },
2242
- addProseMirrorPlugins() {
2243
- if (!this.options.element) {
2244
- return [];
2245
- }
2246
- return [
2247
- FloatingMenuPlugin({
2248
- pluginKey: this.options.pluginKey,
2249
- editor: this.editor,
2250
- element: this.options.element,
2251
- options: this.options.options,
2252
- appendTo: this.options.appendTo,
2253
- shouldShow: this.options.shouldShow
2254
- })
2255
- ];
2256
- }
2257
- });
2258
2196
 
2259
2197
  // src/menus/FloatingMenu.ts
2260
- var FloatingMenu2 = {
2198
+ var FloatingMenu = {
2261
2199
  name: "FloatingMenu",
2262
2200
  props: {
2263
2201
  pluginKey: {
@@ -2318,7 +2256,7 @@ var FloatingMenu2 = {
2318
2256
  }
2319
2257
  };
2320
2258
  export {
2321
- BubbleMenu2 as BubbleMenu,
2322
- FloatingMenu2 as FloatingMenu
2259
+ BubbleMenu,
2260
+ FloatingMenu
2323
2261
  };
2324
2262
  //# sourceMappingURL=index.js.map