@lobehub/editor 4.26.2 → 4.27.1

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/es/headless.js CHANGED
@@ -10492,10 +10492,19 @@ const INSERT_MENTION_COMMAND = createCommand("INSERT_MENTION_COMMAND");
10492
10492
  function registerMentionCommand(editor) {
10493
10493
  return editor.registerCommand(INSERT_MENTION_COMMAND, (payload) => {
10494
10494
  const { metadata, label } = payload;
10495
+ const hasCursorNode = editor.hasNodes([CursorNode]);
10495
10496
  editor.update(() => {
10496
10497
  const mentionNode = $createMentionNode(label, metadata);
10497
10498
  $insertNodes([mentionNode]);
10498
- if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) $wrapNodeInElement(mentionNode, $createParagraphNode).selectEnd();
10499
+ if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {
10500
+ const paragraph = $wrapNodeInElement(mentionNode, $createParagraphNode);
10501
+ if (!hasCursorNode) paragraph.selectEnd();
10502
+ }
10503
+ if (hasCursorNode) {
10504
+ const cursorNode = $createCursorNode();
10505
+ mentionNode.insertAfter(cursorNode);
10506
+ cursorNode.selectEnd();
10507
+ }
10499
10508
  });
10500
10509
  return true;
10501
10510
  }, COMMAND_PRIORITY_HIGH);
@@ -1,3 +1,4 @@
1
+ import { $createCursorNode, CursorNode } from "../../common/node/cursor.js";
1
2
  import { $createMentionNode } from "../node/MentionNode.js";
2
3
  import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from "lexical";
3
4
  import { $wrapNodeInElement } from "@lexical/utils";
@@ -6,10 +7,19 @@ const INSERT_MENTION_COMMAND = createCommand("INSERT_MENTION_COMMAND");
6
7
  function registerMentionCommand(editor) {
7
8
  return editor.registerCommand(INSERT_MENTION_COMMAND, (payload) => {
8
9
  const { metadata, label } = payload;
10
+ const hasCursorNode = editor.hasNodes([CursorNode]);
9
11
  editor.update(() => {
10
12
  const mentionNode = $createMentionNode(label, metadata);
11
13
  $insertNodes([mentionNode]);
12
- if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) $wrapNodeInElement(mentionNode, $createParagraphNode).selectEnd();
14
+ if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {
15
+ const paragraph = $wrapNodeInElement(mentionNode, $createParagraphNode);
16
+ if (!hasCursorNode) paragraph.selectEnd();
17
+ }
18
+ if (hasCursorNode) {
19
+ const cursorNode = $createCursorNode();
20
+ mentionNode.insertAfter(cursorNode);
21
+ cursorNode.selectEnd();
22
+ }
13
23
  });
14
24
  return true;
15
25
  }, COMMAND_PRIORITY_HIGH);
@@ -133,8 +133,7 @@ const SlashPlugin = class extends KernelPlugin {
133
133
  return;
134
134
  }
135
135
  const slashOptions = this.service?.getSlashOptions(triggerText);
136
- const maxLength = slashOptions?.maxLength || 75;
137
- if (text.length - lastIndex > maxLength || !slashOptions) {
136
+ if (!slashOptions) {
138
137
  this.triggerClose();
139
138
  return;
140
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "4.26.2",
3
+ "version": "4.27.1",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -42,6 +42,10 @@
42
42
  "types": "./es/react.d.ts",
43
43
  "import": "./es/react.js"
44
44
  },
45
+ "./react/EditorProvider": {
46
+ "types": "./es/react/EditorProvider/index.d.ts",
47
+ "import": "./es/react/EditorProvider/index.js"
48
+ },
45
49
  "./renderer": {
46
50
  "types": "./es/renderer.d.ts",
47
51
  "import": "./es/renderer.js"