@blocklet/editor 2.1.109 → 2.1.111
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.
|
@@ -2,6 +2,10 @@ import { TranslateService } from './utils';
|
|
|
2
2
|
interface Props {
|
|
3
3
|
translateService: TranslateService;
|
|
4
4
|
detectLanguage: (text: string) => string | null;
|
|
5
|
+
onTranslate?: ({ targetLanguage }: {
|
|
6
|
+
targetLanguage: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
onRestore?: () => void;
|
|
5
9
|
}
|
|
6
10
|
export declare function InlineTranslationPlugin(props: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
7
11
|
export {};
|
|
@@ -7,7 +7,7 @@ import { applyTranslations, translateEditorNodes } from './utils';
|
|
|
7
7
|
import { useInlineTranslationStore, useStatus, useTargetLanguage } from './store';
|
|
8
8
|
// 原始 editor 状态, 用于恢复
|
|
9
9
|
const originalEditorStates = {};
|
|
10
|
-
function InternalInlineTranslationPlugin({ translateService, detectLanguage }) {
|
|
10
|
+
function InternalInlineTranslationPlugin({ translateService, detectLanguage, onTranslate, onRestore }) {
|
|
11
11
|
const [editor] = useLexicalComposerContext();
|
|
12
12
|
const [inViewport] = useInViewport(editor.getRootElement());
|
|
13
13
|
const setStatus = useInlineTranslationStore((s) => s.setStatus);
|
|
@@ -19,6 +19,7 @@ function InternalInlineTranslationPlugin({ translateService, detectLanguage }) {
|
|
|
19
19
|
const handleTranslate = async () => {
|
|
20
20
|
try {
|
|
21
21
|
setStatus(editor, 'processing');
|
|
22
|
+
onTranslate?.({ targetLanguage });
|
|
22
23
|
originalEditorStates[editor.getKey()] = editor.getEditorState();
|
|
23
24
|
const translations = await translateEditorNodes({
|
|
24
25
|
editor,
|
|
@@ -36,6 +37,7 @@ function InternalInlineTranslationPlugin({ translateService, detectLanguage }) {
|
|
|
36
37
|
};
|
|
37
38
|
const handleRestore = () => {
|
|
38
39
|
if (originalEditorStates[editor.getKey()]) {
|
|
40
|
+
onRestore?.();
|
|
39
41
|
editor.setEditorState(originalEditorStates[editor.getKey()]);
|
|
40
42
|
delete originalEditorStates[editor.getKey()];
|
|
41
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.111",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
]
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@blocklet/embed": "^0.2.
|
|
27
|
+
"@blocklet/embed": "^0.2.1",
|
|
28
28
|
"@blocklet/js-sdk": "1.16.33",
|
|
29
|
-
"@blocklet/pages-kit": "^0.3.
|
|
29
|
+
"@blocklet/pages-kit": "^0.3.19",
|
|
30
30
|
"@excalidraw/excalidraw": "^0.14.2",
|
|
31
31
|
"@iconify/iconify": "^3.1.1",
|
|
32
32
|
"@iconify/icons-tabler": "^1.2.95",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"ufo": "^1.5.4",
|
|
66
66
|
"url-join": "^4.0.1",
|
|
67
67
|
"zustand": "^4.5.5",
|
|
68
|
-
"@blocklet/pdf": "^2.1.
|
|
68
|
+
"@blocklet/pdf": "^2.1.111"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@babel/core": "^7.25.2",
|