@lobehub/editor 1.9.3 → 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.
|
@@ -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
|
-
|
|
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