@lobehub/editor 1.9.2 → 1.10.0

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.
@@ -162,6 +162,10 @@ export function registerCursorNode(editor) {
162
162
  }), editor.registerUpdateListener(function () {
163
163
  editor.read(function () {
164
164
  var selection = $getSelection();
165
+ var isComposing = editor.isComposing();
166
+ if (isComposing) {
167
+ return false;
168
+ }
165
169
  if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
166
170
  return false;
167
171
  }
@@ -1,5 +1,5 @@
1
1
  import { $wrapNodeInElement } from '@lexical/utils';
2
- import { $createParagraphNode, $createTextNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from 'lexical';
2
+ import { $createParagraphNode, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from 'lexical';
3
3
  import { $createMentionNode } from "../node/MentionNode";
4
4
  export var INSERT_MENTION_COMMAND = createCommand('INSERT_MENTION_COMMAND');
5
5
  export function registerMentionCommand(editor) {
@@ -11,12 +11,8 @@ export function registerMentionCommand(editor) {
11
11
  $insertNodes([mentionNode]);
12
12
  // Ensure mention is inside a paragraph when inserted at root
13
13
  if ($isRootOrShadowRoot(mentionNode.getParentOrThrow())) {
14
- $wrapNodeInElement(mentionNode, $createParagraphNode);
14
+ $wrapNodeInElement(mentionNode, $createParagraphNode).selectEnd();
15
15
  }
16
- // Insert a trailing text node and move caret into it to enable IME input
17
- var trailingText = $createTextNode("\u200B");
18
- mentionNode.insertAfter(trailingText);
19
- trailingText.selectEnd();
20
16
  });
21
17
  return true;
22
18
  }, COMMAND_PRIORITY_HIGH // Priority
@@ -12,6 +12,7 @@ import { Children, useCallback, useLayoutEffect, useRef, useState } from 'react'
12
12
  import { useLexicalEditor } from "../../../editor-kernel/react";
13
13
  import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
14
14
  import { SlashPlugin } from "../plugin/index";
15
+ import { ISlashService } from "../service/i-slash-service";
15
16
  import { $splitNodeContainingQuery } from "../utils/utils";
16
17
  import SlashMenu from "./components/SlashMenu";
17
18
  import { setCancelablePromise } from "./utils";
@@ -118,6 +119,19 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
118
119
  }
119
120
  });
120
121
  }, [activeKey, editor, close]);
122
+ useLayoutEffect(function () {
123
+ var slash = editor.requireService(ISlashService);
124
+ if (slash) {
125
+ var _Children$map2;
126
+ var _options = ((_Children$map2 = Children.map(children, function (child) {
127
+ if (!child) return null;
128
+ var option = child.props;
129
+ triggerMapRef.current.set(option.trigger, option);
130
+ return option;
131
+ })) === null || _Children$map2 === void 0 ? void 0 : _Children$map2.filter(Boolean)) || [];
132
+ slash.updateOptions(_options);
133
+ }
134
+ }, [children]);
121
135
  var handleMenuSelect = useCallback(function (option) {
122
136
  // ISlashMenuOption should not have divider type, but adding check for safety
123
137
  if ('type' in option && option.type === 'divider') {
@@ -42,6 +42,7 @@ export interface SlashOptions {
42
42
  }
43
43
  export interface ISlashService {
44
44
  registerSlash(options: SlashOptions): void;
45
+ updateOptions(options: SlashOptions[]): void;
45
46
  }
46
47
  export declare const ISlashService: IServiceID<ISlashService>;
47
48
  export declare class SlashService implements ISlashService {
@@ -51,7 +52,9 @@ export declare class SlashService implements ISlashService {
51
52
  private triggerFuseMap;
52
53
  private logger;
53
54
  constructor(kernel: IEditorKernel);
54
- registerSlash(options: SlashOptions): void;
55
+ registerSlash(options: SlashOptions, update?: boolean): void;
56
+ removeAllOptions(): void;
57
+ updateOptions(options: SlashOptions[]): void;
55
58
  getSlashOptions(trigger: string): SlashOptions | undefined;
56
59
  getSlashTriggerFn(trigger: string): ReturnType<typeof getBasicTypeaheadTriggerMatch> | undefined;
57
60
  getSlashFuse(trigger: string): Fuse<ISlashOption> | undefined;
@@ -26,7 +26,8 @@ export var SlashService = /*#__PURE__*/function () {
26
26
  _createClass(SlashService, [{
27
27
  key: "registerSlash",
28
28
  value: function registerSlash(options) {
29
- if (this.triggerMap.has(options.trigger)) {
29
+ var update = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
30
+ if (this.triggerMap.has(options.trigger) && !update) {
30
31
  if (this.kernel.isHotReloadMode()) {
31
32
  this.logger.warn("\uD83D\uDD04 Overriding slash trigger \"".concat(options.trigger, "\""));
32
33
  } else {
@@ -54,6 +55,22 @@ export var SlashService = /*#__PURE__*/function () {
54
55
  this.triggerFuseMap.set(options.trigger, new Fuse(searchableItems, fuseConfig));
55
56
  }
56
57
  }
58
+ }, {
59
+ key: "removeAllOptions",
60
+ value: function removeAllOptions() {
61
+ this.triggerMap.clear();
62
+ this.triggerFnMap.clear();
63
+ this.triggerFuseMap.clear();
64
+ }
65
+ }, {
66
+ key: "updateOptions",
67
+ value: function updateOptions(options) {
68
+ var _this = this;
69
+ this.removeAllOptions();
70
+ options.forEach(function (option) {
71
+ _this.registerSlash(option);
72
+ });
73
+ }
57
74
  }, {
58
75
  key: "getSlashOptions",
59
76
  value: function getSlashOptions(trigger) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.9.2",
3
+ "version": "1.10.0",
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",