@tiptap/vue-2 3.15.2 → 3.16.0

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.
@@ -127,6 +127,20 @@ interface FloatingMenuPluginProps {
127
127
  * @default null
128
128
  */
129
129
  element: HTMLElement;
130
+ /**
131
+ * The delay in milliseconds before the menu should be updated.
132
+ * This can be useful to prevent performance issues.
133
+ * @type {number}
134
+ * @default 250
135
+ */
136
+ updateDelay?: number;
137
+ /**
138
+ * The delay in milliseconds before the menu position should be updated on window resize.
139
+ * This can be useful to prevent performance issues.
140
+ * @type {number}
141
+ * @default 60
142
+ */
143
+ resizeDelay?: number;
130
144
  /**
131
145
  * The DOM element to append your menu to. Default is the editor's parent element.
132
146
  *
@@ -169,13 +183,33 @@ interface FloatingMenuPluginProps {
169
183
  onHide?: () => void;
170
184
  onUpdate?: () => void;
171
185
  onDestroy?: () => void;
186
+ /**
187
+ * The scrollable element that should be listened to when updating the position of the floating menu.
188
+ * If not provided, the window will be used.
189
+ * @type {HTMLElement | Window}
190
+ */
191
+ scrollTarget?: HTMLElement | Window;
172
192
  };
173
193
  }
174
194
 
195
+ declare module '@tiptap/core' {
196
+ interface Commands<ReturnType> {
197
+ floatingMenu: {
198
+ /**
199
+ * Update the position of the floating menu.
200
+ * @example editor.commands.updateFloatingMenuPosition()
201
+ */
202
+ updateFloatingMenuPosition: () => ReturnType;
203
+ };
204
+ }
205
+ }
206
+
175
207
  interface FloatingMenuInterface extends Vue {
176
208
  pluginKey: FloatingMenuPluginProps['pluginKey'];
177
- options: FloatingMenuPluginProps['options'];
178
209
  editor: FloatingMenuPluginProps['editor'];
210
+ updateDelay: FloatingMenuPluginProps['updateDelay'];
211
+ resizeDelay: FloatingMenuPluginProps['resizeDelay'];
212
+ options: FloatingMenuPluginProps['options'];
179
213
  appendTo: FloatingMenuPluginProps['appendTo'];
180
214
  shouldShow: FloatingMenuPluginProps['shouldShow'];
181
215
  }
@@ -127,6 +127,20 @@ interface FloatingMenuPluginProps {
127
127
  * @default null
128
128
  */
129
129
  element: HTMLElement;
130
+ /**
131
+ * The delay in milliseconds before the menu should be updated.
132
+ * This can be useful to prevent performance issues.
133
+ * @type {number}
134
+ * @default 250
135
+ */
136
+ updateDelay?: number;
137
+ /**
138
+ * The delay in milliseconds before the menu position should be updated on window resize.
139
+ * This can be useful to prevent performance issues.
140
+ * @type {number}
141
+ * @default 60
142
+ */
143
+ resizeDelay?: number;
130
144
  /**
131
145
  * The DOM element to append your menu to. Default is the editor's parent element.
132
146
  *
@@ -169,13 +183,33 @@ interface FloatingMenuPluginProps {
169
183
  onHide?: () => void;
170
184
  onUpdate?: () => void;
171
185
  onDestroy?: () => void;
186
+ /**
187
+ * The scrollable element that should be listened to when updating the position of the floating menu.
188
+ * If not provided, the window will be used.
189
+ * @type {HTMLElement | Window}
190
+ */
191
+ scrollTarget?: HTMLElement | Window;
172
192
  };
173
193
  }
174
194
 
195
+ declare module '@tiptap/core' {
196
+ interface Commands<ReturnType> {
197
+ floatingMenu: {
198
+ /**
199
+ * Update the position of the floating menu.
200
+ * @example editor.commands.updateFloatingMenuPosition()
201
+ */
202
+ updateFloatingMenuPosition: () => ReturnType;
203
+ };
204
+ }
205
+ }
206
+
175
207
  interface FloatingMenuInterface extends Vue {
176
208
  pluginKey: FloatingMenuPluginProps['pluginKey'];
177
- options: FloatingMenuPluginProps['options'];
178
209
  editor: FloatingMenuPluginProps['editor'];
210
+ updateDelay: FloatingMenuPluginProps['updateDelay'];
211
+ resizeDelay: FloatingMenuPluginProps['resizeDelay'];
212
+ options: FloatingMenuPluginProps['options'];
179
213
  appendTo: FloatingMenuPluginProps['appendTo'];
180
214
  shouldShow: FloatingMenuPluginProps['shouldShow'];
181
215
  }
@@ -1987,9 +1987,19 @@ var BubbleMenu = {
1987
1987
  import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
1988
1988
  import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
1989
1989
  var FloatingMenuView = class {
1990
- constructor({ editor, element, view, options, appendTo, shouldShow }) {
1990
+ constructor({
1991
+ editor,
1992
+ element,
1993
+ view,
1994
+ updateDelay = 250,
1995
+ resizeDelay = 60,
1996
+ options,
1997
+ appendTo,
1998
+ shouldShow
1999
+ }) {
1991
2000
  this.preventHide = false;
1992
2001
  this.isVisible = false;
2002
+ this.scrollTarget = window;
1993
2003
  this.shouldShow = ({ view, state }) => {
1994
2004
  const { selection } = state;
1995
2005
  const { $anchor, empty } = selection;
@@ -2046,10 +2056,38 @@ var FloatingMenuView = class {
2046
2056
  }
2047
2057
  this.hide();
2048
2058
  };
2059
+ /**
2060
+ * Handles the transaction event to update the position of the floating menu.
2061
+ * This allows external code to trigger a position update via:
2062
+ * `editor.view.dispatch(editor.state.tr.setMeta('floatingMenu', 'updatePosition'))`
2063
+ */
2064
+ this.transactionHandler = ({ transaction: tr }) => {
2065
+ const meta = tr.getMeta("floatingMenu");
2066
+ if (meta === "updatePosition") {
2067
+ this.updatePosition();
2068
+ }
2069
+ };
2070
+ /**
2071
+ * Handles the window resize event to update the position of the floating menu.
2072
+ * It uses a debounce mechanism to prevent excessive updates.
2073
+ * The delay is defined by the `resizeDelay` property.
2074
+ */
2075
+ this.resizeHandler = () => {
2076
+ if (this.resizeDebounceTimer) {
2077
+ clearTimeout(this.resizeDebounceTimer);
2078
+ }
2079
+ this.resizeDebounceTimer = window.setTimeout(() => {
2080
+ this.updatePosition();
2081
+ }, this.resizeDelay);
2082
+ };
2083
+ var _a;
2049
2084
  this.editor = editor;
2050
2085
  this.element = element;
2051
2086
  this.view = view;
2087
+ this.updateDelay = updateDelay;
2088
+ this.resizeDelay = resizeDelay;
2052
2089
  this.appendTo = appendTo;
2090
+ this.scrollTarget = (_a = options == null ? void 0 : options.scrollTarget) != null ? _a : window;
2053
2091
  this.floatingUIOptions = {
2054
2092
  ...this.floatingUIOptions,
2055
2093
  ...options
@@ -2061,6 +2099,9 @@ var FloatingMenuView = class {
2061
2099
  this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
2062
2100
  this.editor.on("focus", this.focusHandler);
2063
2101
  this.editor.on("blur", this.blurHandler);
2102
+ this.editor.on("transaction", this.transactionHandler);
2103
+ window.addEventListener("resize", this.resizeHandler);
2104
+ this.scrollTarget.addEventListener("scroll", this.resizeHandler);
2064
2105
  this.update(view, view.state);
2065
2106
  if (this.getShouldShow()) {
2066
2107
  this.show();
@@ -2180,8 +2221,11 @@ var FloatingMenuView = class {
2180
2221
  destroy() {
2181
2222
  this.hide();
2182
2223
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2224
+ window.removeEventListener("resize", this.resizeHandler);
2225
+ this.scrollTarget.removeEventListener("scroll", this.resizeHandler);
2183
2226
  this.editor.off("focus", this.focusHandler);
2184
2227
  this.editor.off("blur", this.blurHandler);
2228
+ this.editor.off("transaction", this.transactionHandler);
2185
2229
  if (this.floatingUIOptions.onDestroy) {
2186
2230
  this.floatingUIOptions.onDestroy();
2187
2231
  }
@@ -2206,6 +2250,12 @@ var FloatingMenu = {
2206
2250
  type: Object,
2207
2251
  required: true
2208
2252
  },
2253
+ updateDelay: {
2254
+ type: Number
2255
+ },
2256
+ resizeDelay: {
2257
+ type: Number
2258
+ },
2209
2259
  options: {
2210
2260
  type: Object,
2211
2261
  default: () => ({})
@@ -2239,6 +2289,8 @@ var FloatingMenu = {
2239
2289
  pluginKey: this.pluginKey,
2240
2290
  editor,
2241
2291
  element: this.$el,
2292
+ updateDelay: this.updateDelay,
2293
+ resizeDelay: this.resizeDelay,
2242
2294
  options: this.options,
2243
2295
  appendTo: this.appendTo,
2244
2296
  shouldShow: this.shouldShow