@haklex/rich-plugin-floating-toolbar 0.0.35 → 0.0.37

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 +1 @@
1
- {"version":3,"file":"FloatingToolbarPlugin.d.ts","sourceRoot":"","sources":["../src/FloatingToolbarPlugin.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAyIzC,wBAAgB,qBAAqB,IAAI,YAAY,GAAG,IAAI,CAoO3D"}
1
+ {"version":3,"file":"FloatingToolbarPlugin.d.ts","sourceRoot":"","sources":["../src/FloatingToolbarPlugin.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AA0IzC,wBAAgB,qBAAqB,IAAI,YAAY,GAAG,IAAI,CAuP3D"}
package/dist/index.mjs CHANGED
@@ -50,13 +50,13 @@ function computePosition(nativeSelection, toolbar2) {
50
50
  if (rect.width === 0 && rect.height === 0) return null;
51
51
  const toolbarWidth = toolbar2.offsetWidth;
52
52
  const toolbarHeight = toolbar2.offsetHeight;
53
- const rawLeft = rect.left + rect.width / 2 - toolbarWidth / 2 + window.scrollX;
53
+ const rawLeft = rect.left + rect.width / 2 - toolbarWidth / 2;
54
54
  const clampedLeft = Math.max(
55
55
  8,
56
- Math.min(rawLeft, window.innerWidth - toolbarWidth - 8 + window.scrollX)
56
+ Math.min(rawLeft, window.innerWidth - toolbarWidth - 8)
57
57
  );
58
58
  return {
59
- top: rect.top - toolbarHeight - 10 + window.scrollY,
59
+ top: rect.top - toolbarHeight - 10,
60
60
  left: clampedLeft
61
61
  };
62
62
  }
@@ -174,7 +174,22 @@ function FloatingToolbarPlugin() {
174
174
  toolbar2.style.left = `${pos.left}px`;
175
175
  };
176
176
  requestAnimationFrame(positionToolbar);
177
- }, [applyThemeVars, visible, state]);
177
+ const rootElement = editor.getRootElement();
178
+ if (!rootElement) return;
179
+ let scrollParent = window;
180
+ let el = rootElement.parentElement;
181
+ while (el) {
182
+ const { overflowY } = window.getComputedStyle(el);
183
+ if (overflowY === "auto" || overflowY === "scroll") {
184
+ scrollParent = el;
185
+ break;
186
+ }
187
+ el = el.parentElement;
188
+ }
189
+ const onScroll = () => requestAnimationFrame(positionToolbar);
190
+ scrollParent.addEventListener("scroll", onScroll, { passive: true });
191
+ return () => scrollParent.removeEventListener("scroll", onScroll);
192
+ }, [applyThemeVars, editor, visible, state]);
178
193
  const handleFormat = useCallback(
179
194
  (format) => {
180
195
  editor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
@@ -220,7 +235,7 @@ function FloatingToolbarPlugin() {
220
235
  className: toolbarClassName,
221
236
  role: "toolbar",
222
237
  "aria-label": "Text formatting",
223
- style: { position: "absolute", zIndex: 50 },
238
+ style: { position: "fixed", zIndex: 50 },
224
239
  children: [
225
240
  /* @__PURE__ */ jsx(
226
241
  ToolbarButton,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-plugin-floating-toolbar",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "Floating toolbar plugin",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "@haklex/rich-editor-ui": "0.0.35",
20
- "@haklex/rich-style-token": "0.0.35"
19
+ "@haklex/rich-editor-ui": "0.0.37",
20
+ "@haklex/rich-style-token": "0.0.37"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@lexical/link": "^0.41.0",