@zm-editor/react 0.1.1 → 0.1.3

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/dist/index.js CHANGED
@@ -11729,12 +11729,6 @@ var SlashMenuComponent = class {
11729
11729
  this.element.className = "zm-slash-menu";
11730
11730
  document.body.appendChild(this.element);
11731
11731
  }
11732
- const rect = this.props.clientRect?.();
11733
- if (rect) {
11734
- this.element.style.position = "fixed";
11735
- this.element.style.left = `${rect.left}px`;
11736
- this.element.style.top = `${rect.bottom + 8}px`;
11737
- }
11738
11732
  this.removeEventListeners();
11739
11733
  this.element.innerHTML = "";
11740
11734
  if (this.props.items.length === 0) {
@@ -11742,31 +11736,50 @@ var SlashMenuComponent = class {
11742
11736
  emptyDiv.className = "zm-slash-menu-empty";
11743
11737
  emptyDiv.textContent = this.props.noResultsText ?? "No results found";
11744
11738
  this.element.appendChild(emptyDiv);
11745
- return;
11746
- }
11747
- this.props.items.forEach((item, index) => {
11748
- const itemDiv = document.createElement("div");
11749
- itemDiv.className = `zm-slash-menu-item ${index === this.selectedIndex ? "selected" : ""}`;
11750
- itemDiv.dataset.index = String(index);
11751
- const titleDiv = document.createElement("div");
11752
- titleDiv.className = "zm-slash-menu-item-title";
11753
- titleDiv.textContent = item.title;
11754
- const descDiv = document.createElement("div");
11755
- descDiv.className = "zm-slash-menu-item-description";
11756
- descDiv.textContent = item.description;
11757
- itemDiv.appendChild(titleDiv);
11758
- itemDiv.appendChild(descDiv);
11759
- this.element.appendChild(itemDiv);
11760
- const handler = () => {
11761
- this.props.command(item);
11762
- };
11763
- itemDiv.addEventListener("click", handler);
11764
- this.clickHandlers.push({ element: itemDiv, handler });
11765
- itemDiv.addEventListener("mouseenter", () => {
11766
- this.selectedIndex = index;
11767
- this.updateSelection();
11739
+ } else {
11740
+ this.props.items.forEach((item, index) => {
11741
+ const itemDiv = document.createElement("div");
11742
+ itemDiv.className = `zm-slash-menu-item ${index === this.selectedIndex ? "selected" : ""}`;
11743
+ itemDiv.dataset.index = String(index);
11744
+ const titleDiv = document.createElement("div");
11745
+ titleDiv.className = "zm-slash-menu-item-title";
11746
+ titleDiv.textContent = item.title;
11747
+ const descDiv = document.createElement("div");
11748
+ descDiv.className = "zm-slash-menu-item-description";
11749
+ descDiv.textContent = item.description;
11750
+ itemDiv.appendChild(titleDiv);
11751
+ itemDiv.appendChild(descDiv);
11752
+ this.element.appendChild(itemDiv);
11753
+ const handler = () => {
11754
+ this.props.command(item);
11755
+ };
11756
+ itemDiv.addEventListener("click", handler);
11757
+ this.clickHandlers.push({ element: itemDiv, handler });
11758
+ itemDiv.addEventListener("mouseenter", () => {
11759
+ this.selectedIndex = index;
11760
+ this.updateSelection();
11761
+ });
11768
11762
  });
11769
- });
11763
+ }
11764
+ const rect = this.props.clientRect?.();
11765
+ if (rect) {
11766
+ this.element.style.position = "fixed";
11767
+ this.element.style.left = `${rect.left}px`;
11768
+ const menuMaxHeight = 320;
11769
+ const gap = 8;
11770
+ const menuHeight = Math.min(this.element.scrollHeight, menuMaxHeight);
11771
+ const spaceBelow = window.innerHeight - rect.bottom - gap;
11772
+ const spaceAbove = rect.top - gap;
11773
+ if (spaceAbove >= menuHeight || spaceAbove > spaceBelow) {
11774
+ const availableHeight = Math.min(menuMaxHeight, spaceAbove);
11775
+ this.element.style.top = `${rect.top - Math.min(menuHeight, availableHeight) - gap}px`;
11776
+ this.element.style.maxHeight = `${availableHeight}px`;
11777
+ } else {
11778
+ this.element.style.top = `${rect.bottom + gap}px`;
11779
+ const availableHeight = Math.min(menuMaxHeight, spaceBelow);
11780
+ this.element.style.maxHeight = `${availableHeight}px`;
11781
+ }
11782
+ }
11770
11783
  }
11771
11784
  updateSelection() {
11772
11785
  if (!this.element) return;
@@ -11862,12 +11875,6 @@ var MentionMenuComponent = class {
11862
11875
  this.element.className = "zm-mention-list";
11863
11876
  document.body.appendChild(this.element);
11864
11877
  }
11865
- const rect = this.props.clientRect?.();
11866
- if (rect) {
11867
- this.element.style.position = "fixed";
11868
- this.element.style.left = `${rect.left}px`;
11869
- this.element.style.top = `${rect.bottom + 8}px`;
11870
- }
11871
11878
  this.removeEventListeners();
11872
11879
  this.element.innerHTML = "";
11873
11880
  if (this.props.items.length === 0) {
@@ -11875,47 +11882,66 @@ var MentionMenuComponent = class {
11875
11882
  emptyDiv.className = "zm-mention-list-empty";
11876
11883
  emptyDiv.textContent = "No users found";
11877
11884
  this.element.appendChild(emptyDiv);
11878
- return;
11885
+ } else {
11886
+ this.props.items.forEach((item, index) => {
11887
+ const itemDiv = document.createElement("div");
11888
+ itemDiv.className = `zm-mention-list-item ${index === this.selectedIndex ? "selected" : ""}`;
11889
+ if (item.avatar) {
11890
+ const avatarImg = document.createElement("img");
11891
+ avatarImg.src = item.avatar;
11892
+ avatarImg.alt = item.label;
11893
+ avatarImg.className = "zm-mention-list-avatar";
11894
+ itemDiv.appendChild(avatarImg);
11895
+ } else {
11896
+ const avatarPlaceholder = document.createElement("div");
11897
+ avatarPlaceholder.className = "zm-mention-list-avatar-placeholder";
11898
+ avatarPlaceholder.textContent = item.label.charAt(0).toUpperCase();
11899
+ itemDiv.appendChild(avatarPlaceholder);
11900
+ }
11901
+ const contentDiv = document.createElement("div");
11902
+ contentDiv.className = "zm-mention-list-content";
11903
+ const labelDiv = document.createElement("div");
11904
+ labelDiv.className = "zm-mention-list-label";
11905
+ labelDiv.textContent = item.label;
11906
+ contentDiv.appendChild(labelDiv);
11907
+ if (item.description) {
11908
+ const descDiv = document.createElement("div");
11909
+ descDiv.className = "zm-mention-list-description";
11910
+ descDiv.textContent = item.description;
11911
+ contentDiv.appendChild(descDiv);
11912
+ }
11913
+ itemDiv.appendChild(contentDiv);
11914
+ this.element.appendChild(itemDiv);
11915
+ const handler = () => {
11916
+ this.props.command(item);
11917
+ };
11918
+ itemDiv.addEventListener("click", handler);
11919
+ this.clickHandlers.push({ element: itemDiv, handler });
11920
+ itemDiv.addEventListener("mouseenter", () => {
11921
+ this.selectedIndex = index;
11922
+ this.updateSelection();
11923
+ });
11924
+ });
11879
11925
  }
11880
- this.props.items.forEach((item, index) => {
11881
- const itemDiv = document.createElement("div");
11882
- itemDiv.className = `zm-mention-list-item ${index === this.selectedIndex ? "selected" : ""}`;
11883
- if (item.avatar) {
11884
- const avatarImg = document.createElement("img");
11885
- avatarImg.src = item.avatar;
11886
- avatarImg.alt = item.label;
11887
- avatarImg.className = "zm-mention-list-avatar";
11888
- itemDiv.appendChild(avatarImg);
11926
+ const rect = this.props.clientRect?.();
11927
+ if (rect) {
11928
+ this.element.style.position = "fixed";
11929
+ this.element.style.left = `${rect.left}px`;
11930
+ const menuMaxHeight = 240;
11931
+ const gap = 8;
11932
+ const menuHeight = Math.min(this.element.scrollHeight, menuMaxHeight);
11933
+ const spaceBelow = window.innerHeight - rect.bottom - gap;
11934
+ const spaceAbove = rect.top - gap;
11935
+ if (spaceAbove >= menuHeight || spaceAbove > spaceBelow) {
11936
+ const availableHeight = Math.min(menuMaxHeight, spaceAbove);
11937
+ this.element.style.top = `${rect.top - Math.min(menuHeight, availableHeight) - gap}px`;
11938
+ this.element.style.maxHeight = `${availableHeight}px`;
11889
11939
  } else {
11890
- const avatarPlaceholder = document.createElement("div");
11891
- avatarPlaceholder.className = "zm-mention-list-avatar-placeholder";
11892
- avatarPlaceholder.textContent = item.label.charAt(0).toUpperCase();
11893
- itemDiv.appendChild(avatarPlaceholder);
11894
- }
11895
- const contentDiv = document.createElement("div");
11896
- contentDiv.className = "zm-mention-list-content";
11897
- const labelDiv = document.createElement("div");
11898
- labelDiv.className = "zm-mention-list-label";
11899
- labelDiv.textContent = item.label;
11900
- contentDiv.appendChild(labelDiv);
11901
- if (item.description) {
11902
- const descDiv = document.createElement("div");
11903
- descDiv.className = "zm-mention-list-description";
11904
- descDiv.textContent = item.description;
11905
- contentDiv.appendChild(descDiv);
11940
+ this.element.style.top = `${rect.bottom + gap}px`;
11941
+ const availableHeight = Math.min(menuMaxHeight, spaceBelow);
11942
+ this.element.style.maxHeight = `${availableHeight}px`;
11906
11943
  }
11907
- itemDiv.appendChild(contentDiv);
11908
- this.element.appendChild(itemDiv);
11909
- const handler = () => {
11910
- this.props.command(item);
11911
- };
11912
- itemDiv.addEventListener("click", handler);
11913
- this.clickHandlers.push({ element: itemDiv, handler });
11914
- itemDiv.addEventListener("mouseenter", () => {
11915
- this.selectedIndex = index;
11916
- this.updateSelection();
11917
- });
11918
- });
11944
+ }
11919
11945
  }
11920
11946
  updateSelection() {
11921
11947
  if (!this.element) return;