@lobehub/editor 1.9.3 → 1.11.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.
@@ -77,7 +77,9 @@ function updateCodeGutter(node, editor) {
77
77
  // in both cases we'll rerun whole reformatting over CodeNode, which is redundant.
78
78
  // Especially when pasting code into CodeBlock.
79
79
 
80
+ var MAX_CONCURRENT_HIGHLIGHTING = 2;
80
81
  var nodesCurrentlyHighlighting = new Set();
82
+ var waitingNodesCurrentlyHighlighting = new Set();
81
83
  function codeNodeTransform(node, editor, tokenizer) {
82
84
  var nodeKey = node.getKey();
83
85
 
@@ -118,6 +120,10 @@ function codeNodeTransform(node, editor, tokenizer) {
118
120
  if (nodesCurrentlyHighlighting.has(nodeKey)) {
119
121
  return;
120
122
  }
123
+ if (nodesCurrentlyHighlighting.size > MAX_CONCURRENT_HIGHLIGHTING) {
124
+ waitingNodesCurrentlyHighlighting.add(nodeKey);
125
+ return;
126
+ }
121
127
  nodesCurrentlyHighlighting.add(nodeKey);
122
128
 
123
129
  // Using nested update call to pass `skipTransforms` since we don't want
@@ -146,6 +152,16 @@ function codeNodeTransform(node, editor, tokenizer) {
146
152
  }, {
147
153
  onUpdate: function onUpdate() {
148
154
  nodesCurrentlyHighlighting.delete(nodeKey);
155
+ if (nodesCurrentlyHighlighting.size < MAX_CONCURRENT_HIGHLIGHTING && waitingNodesCurrentlyHighlighting.size) {
156
+ var next = waitingNodesCurrentlyHighlighting.values().next().value;
157
+ if (!next) return;
158
+ waitingNodesCurrentlyHighlighting.delete(next);
159
+ requestAnimationFrame(function () {
160
+ editor.read(function () {
161
+ codeNodeTransform($getNodeByKey(next), editor, tokenizer);
162
+ });
163
+ });
164
+ }
149
165
  },
150
166
  skipTransforms: true
151
167
  });
@@ -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.3",
3
+ "version": "1.11.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",