@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.
@@ -2014,9 +2014,19 @@ var BubbleMenu = {
2014
2014
  var import_core3 = require("@tiptap/core");
2015
2015
  var import_state2 = require("@tiptap/pm/state");
2016
2016
  var FloatingMenuView = class {
2017
- constructor({ editor, element, view, options, appendTo, shouldShow }) {
2017
+ constructor({
2018
+ editor,
2019
+ element,
2020
+ view,
2021
+ updateDelay = 250,
2022
+ resizeDelay = 60,
2023
+ options,
2024
+ appendTo,
2025
+ shouldShow
2026
+ }) {
2018
2027
  this.preventHide = false;
2019
2028
  this.isVisible = false;
2029
+ this.scrollTarget = window;
2020
2030
  this.shouldShow = ({ view, state }) => {
2021
2031
  const { selection } = state;
2022
2032
  const { $anchor, empty } = selection;
@@ -2073,10 +2083,38 @@ var FloatingMenuView = class {
2073
2083
  }
2074
2084
  this.hide();
2075
2085
  };
2086
+ /**
2087
+ * Handles the transaction event to update the position of the floating menu.
2088
+ * This allows external code to trigger a position update via:
2089
+ * `editor.view.dispatch(editor.state.tr.setMeta('floatingMenu', 'updatePosition'))`
2090
+ */
2091
+ this.transactionHandler = ({ transaction: tr }) => {
2092
+ const meta = tr.getMeta("floatingMenu");
2093
+ if (meta === "updatePosition") {
2094
+ this.updatePosition();
2095
+ }
2096
+ };
2097
+ /**
2098
+ * Handles the window resize event to update the position of the floating menu.
2099
+ * It uses a debounce mechanism to prevent excessive updates.
2100
+ * The delay is defined by the `resizeDelay` property.
2101
+ */
2102
+ this.resizeHandler = () => {
2103
+ if (this.resizeDebounceTimer) {
2104
+ clearTimeout(this.resizeDebounceTimer);
2105
+ }
2106
+ this.resizeDebounceTimer = window.setTimeout(() => {
2107
+ this.updatePosition();
2108
+ }, this.resizeDelay);
2109
+ };
2110
+ var _a;
2076
2111
  this.editor = editor;
2077
2112
  this.element = element;
2078
2113
  this.view = view;
2114
+ this.updateDelay = updateDelay;
2115
+ this.resizeDelay = resizeDelay;
2079
2116
  this.appendTo = appendTo;
2117
+ this.scrollTarget = (_a = options == null ? void 0 : options.scrollTarget) != null ? _a : window;
2080
2118
  this.floatingUIOptions = {
2081
2119
  ...this.floatingUIOptions,
2082
2120
  ...options
@@ -2088,6 +2126,9 @@ var FloatingMenuView = class {
2088
2126
  this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
2089
2127
  this.editor.on("focus", this.focusHandler);
2090
2128
  this.editor.on("blur", this.blurHandler);
2129
+ this.editor.on("transaction", this.transactionHandler);
2130
+ window.addEventListener("resize", this.resizeHandler);
2131
+ this.scrollTarget.addEventListener("scroll", this.resizeHandler);
2091
2132
  this.update(view, view.state);
2092
2133
  if (this.getShouldShow()) {
2093
2134
  this.show();
@@ -2207,8 +2248,11 @@ var FloatingMenuView = class {
2207
2248
  destroy() {
2208
2249
  this.hide();
2209
2250
  this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
2251
+ window.removeEventListener("resize", this.resizeHandler);
2252
+ this.scrollTarget.removeEventListener("scroll", this.resizeHandler);
2210
2253
  this.editor.off("focus", this.focusHandler);
2211
2254
  this.editor.off("blur", this.blurHandler);
2255
+ this.editor.off("transaction", this.transactionHandler);
2212
2256
  if (this.floatingUIOptions.onDestroy) {
2213
2257
  this.floatingUIOptions.onDestroy();
2214
2258
  }
@@ -2233,6 +2277,12 @@ var FloatingMenu = {
2233
2277
  type: Object,
2234
2278
  required: true
2235
2279
  },
2280
+ updateDelay: {
2281
+ type: Number
2282
+ },
2283
+ resizeDelay: {
2284
+ type: Number
2285
+ },
2236
2286
  options: {
2237
2287
  type: Object,
2238
2288
  default: () => ({})
@@ -2266,6 +2316,8 @@ var FloatingMenu = {
2266
2316
  pluginKey: this.pluginKey,
2267
2317
  editor,
2268
2318
  element: this.$el,
2319
+ updateDelay: this.updateDelay,
2320
+ resizeDelay: this.resizeDelay,
2269
2321
  options: this.options,
2270
2322
  appendTo: this.appendTo,
2271
2323
  shouldShow: this.shouldShow