@mzeahmed/rich-editor 0.1.1 → 0.1.2

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.
package/CHANGELOG.md CHANGED
@@ -11,6 +11,14 @@ Before a release, the pending entries below `[Unreleased]` are moved under a hea
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [0.1.2] - 2026-11-20
15
+
16
+ ### Fixed
17
+
18
+ - The mention bubble now follows the writing area when the page (or a scrolling container such as a
19
+ modal) scrolls or the window is resized. It used to stay where it opened. It is hidden while the
20
+ writing area is out of the viewport.
21
+
14
22
  ## [0.1.1] - 2026-11-20
15
23
 
16
24
  ### Fixed
package/README.md CHANGED
@@ -146,6 +146,8 @@ profileUrl: string}`.
146
146
  address, does not.
147
147
  - Choosing a user inserts `<a class="mention" href="/path/of/profile" data-user-id="…"
148
148
  target="_blank">First Last</a>`. Only the **path** of `profileUrl` is kept in the link.
149
+ - The bubble stays next to the writing area while the page or a scrolling container moves, and is
150
+ hidden while the writing area is out of view.
149
151
  - The bubble closes when you choose a user, press Space, Enter or Escape, click its **×** button, or
150
152
  click anywhere outside of it.
151
153
  - Users without a usable `profileUrl` (`http(s)` or relative) are not offered. An avatar that is not
package/dist/Editor.d.ts CHANGED
@@ -225,6 +225,13 @@ export default class Editor {
225
225
  */
226
226
  private static _showMentionDropdown;
227
227
  private static _positionDropdown;
228
+ /**
229
+ * Keeps the bubble next to the writing area while the page scrolls or the window is resized. The
230
+ * bubble is fixed on `document.body`, so it does not move with the page by itself. `scroll` does
231
+ * not bubble: listening in the capture phase of the window also catches the scroll of a container
232
+ * (a modal, a panel). The listeners are removed by _closeMentionDropdown().
233
+ */
234
+ private static _followWritingArea;
228
235
  /**
229
236
  * Closes the bubble as soon as the user presses (mouse or finger) anywhere but on it, including in the text
230
237
  * of the editor. The listener is added on open and removed by _closeMentionDropdown().
package/dist/Editor.js CHANGED
@@ -600,6 +600,7 @@ export default class Editor {
600
600
  listId: null,
601
601
  stopOutsideClose: null,
602
602
  dismissed: null,
603
+ stopFollow: null,
603
604
  };
604
605
  // In capture phase: before the editor's handler (otherwise Tab inserts spaces).
605
606
  content.addEventListener('keydown', (e) => {
@@ -653,6 +654,7 @@ export default class Editor {
653
654
  state.previousTerm = null;
654
655
  state.dropdown = Editor._showMentionDropdown(content, state, integration);
655
656
  Editor._closeOnOutsidePointer(state);
657
+ Editor._followWritingArea(state, content);
656
658
  }
657
659
  if (trigger.term.length >= 2 && trigger.term !== state.previousTerm) {
658
660
  state.previousTerm = trigger.term;
@@ -704,6 +706,8 @@ export default class Editor {
704
706
  const dropH = 300; // estimated max height of the dropdown
705
707
  dropdown.style.left = `${Math.round(rect.left)}px`;
706
708
  dropdown.style.width = `${width}px`;
709
+ // The bubble is fixed on the page: out of sight while the writing area is, instead of floating alone.
710
+ dropdown.style.visibility = rect.bottom > 0 && rect.top < window.innerHeight ? '' : 'hidden';
707
711
  const spaceBelow = window.innerHeight - rect.bottom;
708
712
  if (spaceBelow >= dropH || spaceBelow >= 150) {
709
713
  // Below the writing area
@@ -716,6 +720,32 @@ export default class Editor {
716
720
  dropdown.style.top = 'auto';
717
721
  }
718
722
  }
723
+ /**
724
+ * Keeps the bubble next to the writing area while the page scrolls or the window is resized. The
725
+ * bubble is fixed on `document.body`, so it does not move with the page by itself. `scroll` does
726
+ * not bubble: listening in the capture phase of the window also catches the scroll of a container
727
+ * (a modal, a panel). The listeners are removed by _closeMentionDropdown().
728
+ */
729
+ static _followWritingArea(state, content) {
730
+ let frame = 0;
731
+ // At most one repositioning per frame, however many scroll events the browser sends.
732
+ const update = () => {
733
+ if (frame)
734
+ return;
735
+ frame = requestAnimationFrame(() => {
736
+ frame = 0;
737
+ if (state.dropdown)
738
+ Editor._positionDropdown(state.dropdown, content);
739
+ });
740
+ };
741
+ window.addEventListener('scroll', update, true);
742
+ window.addEventListener('resize', update);
743
+ state.stopFollow = () => {
744
+ cancelAnimationFrame(frame);
745
+ window.removeEventListener('scroll', update, true);
746
+ window.removeEventListener('resize', update);
747
+ };
748
+ }
719
749
  /**
720
750
  * Closes the bubble as soon as the user presses (mouse or finger) anywhere but on it, including in the text
721
751
  * of the editor. The listener is added on open and removed by _closeMentionDropdown().
@@ -737,6 +767,8 @@ export default class Editor {
737
767
  state.previousTerm = null;
738
768
  state.stopOutsideClose?.();
739
769
  state.stopOutsideClose = null;
770
+ state.stopFollow?.();
771
+ state.stopFollow = null;
740
772
  state.dropdown?.remove();
741
773
  state.dropdown = null;
742
774
  state.activeIndex = -1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mzeahmed/rich-editor",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "mzeahmed",