@zm-editor/react 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +47 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9495,6 +9495,21 @@ function findNodePosFromDOM(editor, element) {
9495
9495
  const pos = editor.view.posAtDOM(nodeElement, 0);
9496
9496
  debugLog("findNodePosFromDOM", "posAtDOM for direct child returned:", pos);
9497
9497
  if (pos >= 0) {
9498
+ const isReactNodeView = nodeElement.classList.contains("react-renderer");
9499
+ if (isReactNodeView) {
9500
+ const $pos = editor.state.doc.resolve(pos);
9501
+ if ($pos.depth >= 1) {
9502
+ const nodePos = $pos.before(1);
9503
+ const node = editor.state.doc.nodeAt(nodePos);
9504
+ if (node) {
9505
+ debugLog("findNodePosFromDOM", "Found ReactNodeView node via $pos.before(1):", {
9506
+ type: node.type.name,
9507
+ pos: nodePos
9508
+ });
9509
+ return { pos: nodePos, node };
9510
+ }
9511
+ }
9512
+ }
9498
9513
  const nodeAtPos = editor.state.doc.nodeAt(pos);
9499
9514
  if (nodeAtPos) {
9500
9515
  debugLog("findNodePosFromDOM", "Found node at pos:", {
@@ -9503,9 +9518,9 @@ function findNodePosFromDOM(editor, element) {
9503
9518
  });
9504
9519
  return { pos, node: nodeAtPos };
9505
9520
  }
9506
- const $pos = editor.state.doc.resolve(pos);
9507
- if ($pos.depth >= 1) {
9508
- const nodePos = $pos.before(1);
9521
+ const $posResolved = editor.state.doc.resolve(pos);
9522
+ if ($posResolved.depth >= 1) {
9523
+ const nodePos = $posResolved.before(1);
9509
9524
  const node = editor.state.doc.nodeAt(nodePos);
9510
9525
  if (node) {
9511
9526
  debugLog("findNodePosFromDOM", "Found node via $pos.before(1):", {
@@ -9777,7 +9792,8 @@ function getContentTop(element, nodeTypeName) {
9777
9792
  "metadata",
9778
9793
  "openapi",
9779
9794
  "stackTrace",
9780
- "horizontalRule"
9795
+ "horizontalRule",
9796
+ "callout"
9781
9797
  ];
9782
9798
  if (atomNodeTypes.includes(nodeTypeName)) {
9783
9799
  debugLog("getContentTop", `Atom node (${nodeTypeName}): using rect.top=${rect.top}`);
@@ -9834,7 +9850,8 @@ function getNodeLineHeight(element, nodeTypeName) {
9834
9850
  "metadata",
9835
9851
  "openapi",
9836
9852
  "stackTrace",
9837
- "horizontalRule"
9853
+ "horizontalRule",
9854
+ "callout"
9838
9855
  ];
9839
9856
  if (atomNodeTypes.includes(nodeTypeName)) {
9840
9857
  const atomLineHeight = 24;
@@ -11520,8 +11537,10 @@ var ZmEditor = forwardRef(
11520
11537
  const handleEmojiSelect = useCallback(
11521
11538
  (emoji) => {
11522
11539
  if (!editor) return;
11523
- editor.chain().focus().insertContent(emoji).run();
11524
11540
  setShowEmojiPicker(false);
11541
+ requestAnimationFrame(() => {
11542
+ editor.chain().focus().insertContent(emoji).run();
11543
+ });
11525
11544
  },
11526
11545
  [editor]
11527
11546
  );
@@ -11700,12 +11719,12 @@ var SlashMenuComponent = class {
11700
11719
  this.selectedIndex + 1,
11701
11720
  this.props.items.length - 1
11702
11721
  );
11703
- this.render();
11722
+ this.updateSelection();
11704
11723
  return true;
11705
11724
  }
11706
11725
  if (event.key === "ArrowUp") {
11707
11726
  this.selectedIndex = Math.max(this.selectedIndex - 1, 0);
11708
- this.render();
11727
+ this.updateSelection();
11709
11728
  return true;
11710
11729
  }
11711
11730
  if (event.key === "Enter") {
@@ -11787,6 +11806,15 @@ var SlashMenuComponent = class {
11787
11806
  items.forEach((item, index) => {
11788
11807
  if (index === this.selectedIndex) {
11789
11808
  item.classList.add("selected");
11809
+ const el = item;
11810
+ const container = this.element;
11811
+ const itemTop = el.offsetTop;
11812
+ const itemBottom = itemTop + el.offsetHeight;
11813
+ if (itemTop < container.scrollTop) {
11814
+ container.scrollTop = itemTop;
11815
+ } else if (itemBottom > container.scrollTop + container.clientHeight) {
11816
+ container.scrollTop = itemBottom - container.clientHeight;
11817
+ }
11790
11818
  } else {
11791
11819
  item.classList.remove("selected");
11792
11820
  }
@@ -11846,12 +11874,12 @@ var MentionMenuComponent = class {
11846
11874
  this.selectedIndex + 1,
11847
11875
  this.props.items.length - 1
11848
11876
  );
11849
- this.render();
11877
+ this.updateSelection();
11850
11878
  return true;
11851
11879
  }
11852
11880
  if (event.key === "ArrowUp") {
11853
11881
  this.selectedIndex = Math.max(this.selectedIndex - 1, 0);
11854
- this.render();
11882
+ this.updateSelection();
11855
11883
  return true;
11856
11884
  }
11857
11885
  if (event.key === "Enter") {
@@ -11949,6 +11977,15 @@ var MentionMenuComponent = class {
11949
11977
  items.forEach((item, index) => {
11950
11978
  if (index === this.selectedIndex) {
11951
11979
  item.classList.add("selected");
11980
+ const el = item;
11981
+ const container = this.element;
11982
+ const itemTop = el.offsetTop;
11983
+ const itemBottom = itemTop + el.offsetHeight;
11984
+ if (itemTop < container.scrollTop) {
11985
+ container.scrollTop = itemTop;
11986
+ } else if (itemBottom > container.scrollTop + container.clientHeight) {
11987
+ container.scrollTop = itemBottom - container.clientHeight;
11988
+ }
11952
11989
  } else {
11953
11990
  item.classList.remove("selected");
11954
11991
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zm-editor/react",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "React components for zm-editor - Notion-like rich text editor",
5
5
  "license": "MIT",
6
6
  "type": "module",