@blocklet/editor 2.1.115 → 2.1.117
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.
|
@@ -8,15 +8,13 @@ export class EditorTranslator {
|
|
|
8
8
|
editor;
|
|
9
9
|
options;
|
|
10
10
|
originalEditorState;
|
|
11
|
-
nodeKeyToSidMap;
|
|
12
|
-
sidToNodeKeyMap;
|
|
11
|
+
nodeKeyToSidMap = new Map();
|
|
12
|
+
sidToNodeKeyMap = new Map();
|
|
13
13
|
translations = [];
|
|
14
14
|
constructor(editor, options) {
|
|
15
15
|
this.editor = editor;
|
|
16
16
|
this.options = options;
|
|
17
|
-
this.originalEditorState = editor.getEditorState()
|
|
18
|
-
this.nodeKeyToSidMap = this.editor.getEditorState().read(() => $createNodeKeyToSidMap());
|
|
19
|
-
this.sidToNodeKeyMap = this.editor.getEditorState().read(() => $createSidToNodeKeyMap());
|
|
17
|
+
this.originalEditorState = editor.getEditorState();
|
|
20
18
|
}
|
|
21
19
|
get isTranslated() {
|
|
22
20
|
return this.translations.length > 0;
|
|
@@ -39,6 +37,10 @@ export class EditorTranslator {
|
|
|
39
37
|
}, 10);
|
|
40
38
|
}
|
|
41
39
|
async translate({ targetLanguage, translateService, detectLanguage, useCache, }) {
|
|
40
|
+
// 翻译前备份 editor state (fix 恢复原文时图片路径错误的问题)
|
|
41
|
+
this.originalEditorState = this.editor.getEditorState();
|
|
42
|
+
this.nodeKeyToSidMap = this.editor.getEditorState().read(() => $createNodeKeyToSidMap());
|
|
43
|
+
this.sidToNodeKeyMap = this.editor.getEditorState().read(() => $createSidToNodeKeyMap());
|
|
42
44
|
let nodes = [];
|
|
43
45
|
this.editor.update(() => {
|
|
44
46
|
nodes = $findTranslatableElementNodes()
|
|
@@ -2,7 +2,7 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import { Box } from '@mui/material';
|
|
5
|
-
import { useInViewport } from 'ahooks';
|
|
5
|
+
import { useInViewport, usePrevious } from 'ahooks';
|
|
6
6
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
7
7
|
import { useInlineTranslationStore, useStatus, useTargetLanguage } from './store';
|
|
8
8
|
import { useEditorTranslator } from './EditorTranslator';
|
|
@@ -20,6 +20,7 @@ function InternalInlineTranslationPlugin({ translateService, detectLanguage, onT
|
|
|
20
20
|
const useCache = useInlineTranslationStore((s) => s.editorTranslateStates.get(editor)?.useCache);
|
|
21
21
|
const targetLanguage = useTargetLanguage();
|
|
22
22
|
const status = useStatus(editor);
|
|
23
|
+
const previousStatus = usePrevious(status);
|
|
23
24
|
const editorTranslator = useEditorTranslator({ displayMode });
|
|
24
25
|
const hoveringTranslationElementRef = useHoveringTranslationElement();
|
|
25
26
|
const { locale } = useLocaleContext();
|
|
@@ -53,10 +54,10 @@ function InternalInlineTranslationPlugin({ translateService, detectLanguage, onT
|
|
|
53
54
|
}
|
|
54
55
|
}, [editor, status, inViewport]);
|
|
55
56
|
useEffect(() => {
|
|
56
|
-
if (status === 'idle') {
|
|
57
|
+
if (previousStatus === 'completed' && status === 'idle') {
|
|
57
58
|
handleRestore();
|
|
58
59
|
}
|
|
59
|
-
}, [editor, status]);
|
|
60
|
+
}, [editor, status, previousStatus]);
|
|
60
61
|
useEffect(() => {
|
|
61
62
|
editorTranslator.updateOptions({ displayMode });
|
|
62
63
|
}, [editorTranslator, displayMode]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.117",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@blocklet/code-editor": "^0.4.201",
|
|
28
28
|
"@blocklet/embed": "^0.2.2",
|
|
29
|
-
"@blocklet/js-sdk": "1.16.
|
|
30
|
-
"@blocklet/pages-kit": "^0.3.
|
|
29
|
+
"@blocklet/js-sdk": "^1.16.37",
|
|
30
|
+
"@blocklet/pages-kit": "^0.3.24",
|
|
31
31
|
"@excalidraw/excalidraw": "^0.14.2",
|
|
32
32
|
"@iconify/iconify": "^3.1.1",
|
|
33
33
|
"@iconify/icons-tabler": "^1.2.95",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"ufo": "^1.5.4",
|
|
67
67
|
"url-join": "^4.0.1",
|
|
68
68
|
"zustand": "^4.5.5",
|
|
69
|
-
"@blocklet/pdf": "^2.1.
|
|
69
|
+
"@blocklet/pdf": "^2.1.117"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@babel/core": "^7.25.2",
|