@tiptap/vue-2 3.4.6 → 3.5.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.
@@ -93,12 +93,25 @@ interface BubbleMenuPluginProps {
93
93
  scrollTarget?: HTMLElement | Window;
94
94
  };
95
95
  }
96
+ declare module '@tiptap/core' {
97
+ interface Commands<ReturnType> {
98
+ bubbleMenu: {
99
+ /**
100
+ * Update the position of the bubble menu. This command is useful to force
101
+ * the bubble menu to update its position in response to certain events
102
+ * (for example, when the bubble menu is resized).
103
+ */
104
+ updateBubbleMenuPosition: () => ReturnType;
105
+ };
106
+ }
107
+ }
96
108
 
97
109
  interface BubbleMenuInterface extends Vue {
98
110
  pluginKey: BubbleMenuPluginProps['pluginKey'];
99
111
  editor: BubbleMenuPluginProps['editor'];
100
112
  updateDelay: BubbleMenuPluginProps['updateDelay'];
101
113
  resizeDelay: BubbleMenuPluginProps['resizeDelay'];
114
+ appendTo: BubbleMenuPluginProps['appendTo'];
102
115
  shouldShow: BubbleMenuPluginProps['shouldShow'];
103
116
  getReferencedVirtualElement: BubbleMenuPluginProps['getReferencedVirtualElement'];
104
117
  options: BubbleMenuPluginProps['options'];
@@ -121,6 +134,15 @@ interface FloatingMenuPluginProps {
121
134
  * @default null
122
135
  */
123
136
  element: HTMLElement;
137
+ /**
138
+ * The DOM element to append your menu to. Default is the editor's parent element.
139
+ *
140
+ * Sometimes the menu needs to be appended to a different DOM context due to accessibility, clipping, or z-index issues.
141
+ *
142
+ * @type {HTMLElement}
143
+ * @default null
144
+ */
145
+ appendTo?: HTMLElement;
124
146
  /**
125
147
  * A function that determines whether the menu should be shown or not.
126
148
  * If this function returns `false`, the menu will be hidden, otherwise it will be shown.
@@ -161,6 +183,7 @@ interface FloatingMenuInterface extends Vue {
161
183
  pluginKey: FloatingMenuPluginProps['pluginKey'];
162
184
  options: FloatingMenuPluginProps['options'];
163
185
  editor: FloatingMenuPluginProps['editor'];
186
+ appendTo: FloatingMenuPluginProps['appendTo'];
164
187
  shouldShow: FloatingMenuPluginProps['shouldShow'];
165
188
  }
166
189
  declare const FloatingMenu: Component;
@@ -93,12 +93,25 @@ interface BubbleMenuPluginProps {
93
93
  scrollTarget?: HTMLElement | Window;
94
94
  };
95
95
  }
96
+ declare module '@tiptap/core' {
97
+ interface Commands<ReturnType> {
98
+ bubbleMenu: {
99
+ /**
100
+ * Update the position of the bubble menu. This command is useful to force
101
+ * the bubble menu to update its position in response to certain events
102
+ * (for example, when the bubble menu is resized).
103
+ */
104
+ updateBubbleMenuPosition: () => ReturnType;
105
+ };
106
+ }
107
+ }
96
108
 
97
109
  interface BubbleMenuInterface extends Vue {
98
110
  pluginKey: BubbleMenuPluginProps['pluginKey'];
99
111
  editor: BubbleMenuPluginProps['editor'];
100
112
  updateDelay: BubbleMenuPluginProps['updateDelay'];
101
113
  resizeDelay: BubbleMenuPluginProps['resizeDelay'];
114
+ appendTo: BubbleMenuPluginProps['appendTo'];
102
115
  shouldShow: BubbleMenuPluginProps['shouldShow'];
103
116
  getReferencedVirtualElement: BubbleMenuPluginProps['getReferencedVirtualElement'];
104
117
  options: BubbleMenuPluginProps['options'];
@@ -121,6 +134,15 @@ interface FloatingMenuPluginProps {
121
134
  * @default null
122
135
  */
123
136
  element: HTMLElement;
137
+ /**
138
+ * The DOM element to append your menu to. Default is the editor's parent element.
139
+ *
140
+ * Sometimes the menu needs to be appended to a different DOM context due to accessibility, clipping, or z-index issues.
141
+ *
142
+ * @type {HTMLElement}
143
+ * @default null
144
+ */
145
+ appendTo?: HTMLElement;
124
146
  /**
125
147
  * A function that determines whether the menu should be shown or not.
126
148
  * If this function returns `false`, the menu will be hidden, otherwise it will be shown.
@@ -161,6 +183,7 @@ interface FloatingMenuInterface extends Vue {
161
183
  pluginKey: FloatingMenuPluginProps['pluginKey'];
162
184
  options: FloatingMenuPluginProps['options'];
163
185
  editor: FloatingMenuPluginProps['editor'];
186
+ appendTo: FloatingMenuPluginProps['appendTo'];
164
187
  shouldShow: FloatingMenuPluginProps['shouldShow'];
165
188
  }
166
189
  declare const FloatingMenu: Component;
@@ -1720,6 +1720,7 @@ var BubbleMenuView = class {
1720
1720
  this.view.dom.addEventListener("dragstart", this.dragstartHandler);
1721
1721
  this.editor.on("focus", this.focusHandler);
1722
1722
  this.editor.on("blur", this.blurHandler);
1723
+ this.editor.on("transaction", this.transactionHandler);
1723
1724
  window.addEventListener("resize", this.resizeHandler);
1724
1725
  this.scrollTarget.addEventListener("scroll", this.resizeHandler);
1725
1726
  this.update(view, view.state);
@@ -1883,6 +1884,12 @@ var BubbleMenuView = class {
1883
1884
  }
1884
1885
  this.isVisible = false;
1885
1886
  }
1887
+ transactionHandler({ transaction: tr }) {
1888
+ const meta = tr.getMeta("bubbleMenu");
1889
+ if (meta === "updatePosition") {
1890
+ this.updatePosition();
1891
+ }
1892
+ }
1886
1893
  destroy() {
1887
1894
  this.hide();
1888
1895
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
@@ -1891,6 +1898,7 @@ var BubbleMenuView = class {
1891
1898
  this.scrollTarget.removeEventListener("scroll", this.resizeHandler);
1892
1899
  this.editor.off("focus", this.focusHandler);
1893
1900
  this.editor.off("blur", this.blurHandler);
1901
+ this.editor.off("transaction", this.transactionHandler);
1894
1902
  if (this.floatingUIOptions.onDestroy) {
1895
1903
  this.floatingUIOptions.onDestroy();
1896
1904
  }
@@ -1929,6 +1937,13 @@ var BubbleMenu = Extension.create({
1929
1937
  shouldShow: this.options.shouldShow
1930
1938
  })
1931
1939
  ];
1940
+ },
1941
+ addCommands() {
1942
+ return {
1943
+ updateBubbleMenuPosition: () => ({ commands }) => {
1944
+ return commands.setMeta("bubbleMenu", "updatePosition");
1945
+ }
1946
+ };
1932
1947
  }
1933
1948
  });
1934
1949
 
@@ -1954,6 +1969,10 @@ var BubbleMenu2 = {
1954
1969
  resizeDelay: {
1955
1970
  type: Number
1956
1971
  },
1972
+ appendTo: {
1973
+ type: Object,
1974
+ default: void 0
1975
+ },
1957
1976
  shouldShow: {
1958
1977
  type: Function,
1959
1978
  default: null
@@ -1979,6 +1998,7 @@ var BubbleMenu2 = {
1979
1998
  editor,
1980
1999
  element: this.$el,
1981
2000
  pluginKey: this.pluginKey,
2001
+ appendTo: this.appendTo,
1982
2002
  shouldShow: this.shouldShow,
1983
2003
  getReferencedVirtualElement: this.getReferencedVirtualElement
1984
2004
  })
@@ -1988,7 +2008,7 @@ var BubbleMenu2 = {
1988
2008
  }
1989
2009
  },
1990
2010
  render(createElement) {
1991
- return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
2011
+ return createElement("div", {}, this.$slots.default);
1992
2012
  },
1993
2013
  beforeDestroy() {
1994
2014
  this.editor.unregisterPlugin(this.pluginKey);
@@ -2000,7 +2020,7 @@ import { Extension as Extension2 } from "@tiptap/core";
2000
2020
  import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
2001
2021
  import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
2002
2022
  var FloatingMenuView = class {
2003
- constructor({ editor, element, view, options, shouldShow }) {
2023
+ constructor({ editor, element, view, options, appendTo, shouldShow }) {
2004
2024
  this.preventHide = false;
2005
2025
  this.isVisible = false;
2006
2026
  this.shouldShow = ({ view: view2, state }) => {
@@ -2062,6 +2082,7 @@ var FloatingMenuView = class {
2062
2082
  this.editor = editor;
2063
2083
  this.element = element;
2064
2084
  this.view = view;
2085
+ this.appendTo = appendTo;
2065
2086
  this.floatingUIOptions = {
2066
2087
  ...this.floatingUIOptions,
2067
2088
  ...options
@@ -2163,13 +2184,13 @@ var FloatingMenuView = class {
2163
2184
  this.updateHandler(view, selectionChanged, docChanged, oldState);
2164
2185
  }
2165
2186
  show() {
2166
- var _a;
2187
+ var _a, _b;
2167
2188
  if (this.isVisible) {
2168
2189
  return;
2169
2190
  }
2170
2191
  this.element.style.visibility = "visible";
2171
2192
  this.element.style.opacity = "1";
2172
- (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
2193
+ (_b = (_a = this.appendTo) != null ? _a : this.view.dom.parentElement) == null ? void 0 : _b.appendChild(this.element);
2173
2194
  if (this.floatingUIOptions.onShow) {
2174
2195
  this.floatingUIOptions.onShow();
2175
2196
  }
@@ -2210,6 +2231,7 @@ var FloatingMenu = Extension2.create({
2210
2231
  element: null,
2211
2232
  options: {},
2212
2233
  pluginKey: "floatingMenu",
2234
+ appendTo: void 0,
2213
2235
  shouldShow: null
2214
2236
  };
2215
2237
  },
@@ -2223,6 +2245,7 @@ var FloatingMenu = Extension2.create({
2223
2245
  editor: this.editor,
2224
2246
  element: this.options.element,
2225
2247
  options: this.options.options,
2248
+ appendTo: this.options.appendTo,
2226
2249
  shouldShow: this.options.shouldShow
2227
2250
  })
2228
2251
  ];
@@ -2245,6 +2268,10 @@ var FloatingMenu2 = {
2245
2268
  type: Object,
2246
2269
  default: () => ({})
2247
2270
  },
2271
+ appendTo: {
2272
+ type: Object,
2273
+ default: void 0
2274
+ },
2248
2275
  shouldShow: {
2249
2276
  type: Function,
2250
2277
  default: null
@@ -2268,6 +2295,7 @@ var FloatingMenu2 = {
2268
2295
  editor,
2269
2296
  element: this.$el,
2270
2297
  options: this.options,
2298
+ appendTo: this.appendTo,
2271
2299
  shouldShow: this.shouldShow
2272
2300
  })
2273
2301
  );
@@ -2276,7 +2304,7 @@ var FloatingMenu2 = {
2276
2304
  }
2277
2305
  },
2278
2306
  render(createElement) {
2279
- return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
2307
+ return createElement("div", {}, this.$slots.default);
2280
2308
  },
2281
2309
  beforeDestroy() {
2282
2310
  this.editor.unregisterPlugin(this.pluginKey);