@seafile/sdoc-editor 1.0.177 → 1.0.178
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.
- package/dist/api/seafile-api.js +12 -0
- package/dist/basic-sdk/assets/images/sdoc-ask-ai.png +0 -0
- package/dist/basic-sdk/constants/index.js +2 -1
- package/dist/basic-sdk/extension/commons/file-insert-dialog/index.js +28 -18
- package/dist/basic-sdk/extension/commons/file-insert-dialog/style.css +12 -9
- package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +10 -0
- package/dist/basic-sdk/extension/commons/select-file-dialog/helpers.js +9 -2
- package/dist/basic-sdk/extension/commons/select-file-dialog/index.css +115 -0
- package/dist/basic-sdk/extension/commons/select-file-dialog/index.js +68 -5
- package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.css +42 -0
- package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.js +49 -12
- package/dist/basic-sdk/extension/constants/element-type.js +2 -1
- package/dist/basic-sdk/extension/constants/menus-config.js +1 -1
- package/dist/basic-sdk/extension/core/queries/index.js +12 -1
- package/dist/basic-sdk/extension/plugins/ai/ai-icon/index.js +26 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-icon/style.css +22 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/ai-context-menu.js +39 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/ai-dropdown-menu.js +35 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/index.js +20 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/menu-item.js +62 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-menu/style.css +3 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-module/adjust-sub-menu.js +40 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-module/index.js +452 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-module/lang-sub-menu.js +55 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-module/style.css +104 -0
- package/dist/basic-sdk/extension/plugins/ai/ai-module/tip-dialog.js +32 -0
- package/dist/basic-sdk/extension/plugins/ai/constants/index.js +128 -0
- package/dist/basic-sdk/extension/plugins/ai/index.js +1 -0
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +2 -2
- package/dist/basic-sdk/extension/plugins/image/helpers.js +25 -16
- package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +7 -2
- package/dist/basic-sdk/extension/plugins/sdoc-link/render/render-elem.css +19 -3
- package/dist/basic-sdk/extension/plugins/sdoc-link/render/render-elem.js +8 -3
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -1
- package/dist/basic-sdk/extension/plugins/video/helpers.js +1 -0
- package/dist/basic-sdk/extension/plugins/video/plugin.js +26 -1
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +7 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +4 -1
- package/dist/context.js +8 -0
- package/package.json +1 -1
- package/public/locales/cs/sdoc-editor.json +23 -1
- package/public/locales/de/sdoc-editor.json +23 -1
- package/public/locales/en/sdoc-editor.json +23 -1
- package/public/locales/es/sdoc-editor.json +23 -1
- package/public/locales/es_AR/sdoc-editor.json +23 -1
- package/public/locales/es_MX/sdoc-editor.json +23 -1
- package/public/locales/fr/sdoc-editor.json +23 -1
- package/public/locales/it/sdoc-editor.json +23 -1
- package/public/locales/ru/sdoc-editor.json +24 -2
- package/public/locales/zh_CN/sdoc-editor.json +23 -1
- package/public/media/sdoc-editor-font/iconfont.css +14 -8
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +4 -2
- package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
- package/public/media/sdoc-editor-font.css +14 -10
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = AIModule;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _slateReact = require("@seafile/slate-react");
|
|
11
|
+
var _slate = require("@seafile/slate");
|
|
12
|
+
var _reactI18next = require("react-i18next");
|
|
13
|
+
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
14
|
+
var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));
|
|
15
|
+
var _commons = require("../../../commons");
|
|
16
|
+
var _constants = require("../constants");
|
|
17
|
+
var _dropdownMenuItem = _interopRequireDefault(require("../../../commons/dropdown-menu-item"));
|
|
18
|
+
var _toast = _interopRequireDefault(require("../../../../../components/toast"));
|
|
19
|
+
var _context = _interopRequireDefault(require("../../../../../context"));
|
|
20
|
+
var _langSubMenu = _interopRequireDefault(require("./lang-sub-menu"));
|
|
21
|
+
var _adjustSubMenu = _interopRequireDefault(require("./adjust-sub-menu"));
|
|
22
|
+
var _tipDialog = _interopRequireDefault(require("./tip-dialog"));
|
|
23
|
+
var _core = require("../../../core");
|
|
24
|
+
var _constants2 = require("../../../constants");
|
|
25
|
+
var _aiIcon = _interopRequireDefault(require("../ai-icon"));
|
|
26
|
+
require("./style.css");
|
|
27
|
+
function AIModule(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
editor,
|
|
30
|
+
element,
|
|
31
|
+
closeModule
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
t
|
|
35
|
+
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
36
|
+
const aiRef = (0, _react.useRef)(null);
|
|
37
|
+
const inputRef = (0, _react.useRef)(null);
|
|
38
|
+
const scrollRef = (0, _react.useRef)(null);
|
|
39
|
+
const [isShowAIPopover, setIsShowAIPopover] = (0, _react.useState)(false);
|
|
40
|
+
const [opType, setOpType] = (0, _react.useState)('');
|
|
41
|
+
const [searchValue, setSearchValue] = (0, _react.useState)('');
|
|
42
|
+
const [isGenerating, setIsGenerating] = (0, _react.useState)(false);
|
|
43
|
+
const [searchResult, setSearchResult] = (0, _react.useState)(null);
|
|
44
|
+
const [currentLang, setCurrentLang] = (0, _react.useState)('en');
|
|
45
|
+
const [isShowTipDialog, setIsShowTipDialog] = (0, _react.useState)(false);
|
|
46
|
+
const toggleAskAI = (0, _react.useCallback)(() => {
|
|
47
|
+
const content = window.getSelection().toString();
|
|
48
|
+
if (content) {
|
|
49
|
+
setSearchValue(content);
|
|
50
|
+
}
|
|
51
|
+
scrollRef.current = document.querySelector('.sdoc-scroll-container');
|
|
52
|
+
const {
|
|
53
|
+
scrollTop,
|
|
54
|
+
scrollHeight
|
|
55
|
+
} = scrollRef.current;
|
|
56
|
+
if (!element) {
|
|
57
|
+
const domSelection = window.getSelection();
|
|
58
|
+
const domRange = domSelection.getRangeAt(0);
|
|
59
|
+
const rect = domRange.getBoundingClientRect();
|
|
60
|
+
const needPaddingBottomHeight = scrollTop + rect.bottom + _constants.AI_MIN_HEIGHT - scrollHeight;
|
|
61
|
+
if (needPaddingBottomHeight > 0) {
|
|
62
|
+
const articleDom = document.querySelector('.sdoc-editor__article');
|
|
63
|
+
articleDom.style.paddingBottom = needPaddingBottomHeight + 'px';
|
|
64
|
+
}
|
|
65
|
+
const heightDiff = rect.bottom + _constants.AI_MIN_HEIGHT - window.innerHeight;
|
|
66
|
+
if (heightDiff > 0) {
|
|
67
|
+
scrollRef.current.scrollTo({
|
|
68
|
+
top: scrollRef.current.scrollTop + heightDiff + 100,
|
|
69
|
+
behavior: 'smooth'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
var _inputRef$current;
|
|
74
|
+
const aboveNode = (0, _core.getAboveBlockNode)(editor);
|
|
75
|
+
const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
|
|
76
|
+
const slateRect = slateDom.getBoundingClientRect();
|
|
77
|
+
const newRect = domRange.getBoundingClientRect();
|
|
78
|
+
const el = aiRef.current;
|
|
79
|
+
el.style.top = `${newRect.bottom + 8}px`; // top = Current top + Element height
|
|
80
|
+
el.style.left = `${slateRect.left}px`;
|
|
81
|
+
el.style.display = 'block';
|
|
82
|
+
setIsShowAIPopover(true);
|
|
83
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
84
|
+
}, 500);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const slateDom = _slateReact.ReactEditor.toDOMNode(editor, element);
|
|
88
|
+
const slateRect = slateDom.getBoundingClientRect();
|
|
89
|
+
const needPaddingBottomHeight = scrollTop + slateRect.bottom + _constants.AI_MIN_HEIGHT - scrollHeight;
|
|
90
|
+
if (needPaddingBottomHeight > 0) {
|
|
91
|
+
const articleDom = document.querySelector('.sdoc-editor__article');
|
|
92
|
+
articleDom.style.paddingBottom = needPaddingBottomHeight + 'px';
|
|
93
|
+
}
|
|
94
|
+
const heightDiff = slateRect.bottom + _constants.AI_MIN_HEIGHT - window.innerHeight;
|
|
95
|
+
if (heightDiff > 0) {
|
|
96
|
+
scrollRef.current.scrollTo({
|
|
97
|
+
top: scrollRef.current.scrollTop + heightDiff + 100,
|
|
98
|
+
behavior: 'smooth'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
var _inputRef$current2;
|
|
103
|
+
const slateRect = slateDom.getBoundingClientRect();
|
|
104
|
+
const el = aiRef.current;
|
|
105
|
+
el.style.top = `${slateRect.bottom + 8}px`; // top = Current top + Element height
|
|
106
|
+
el.style.left = `${slateRect.left}px`;
|
|
107
|
+
el.style.display = 'block';
|
|
108
|
+
setIsShowAIPopover(true);
|
|
109
|
+
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
|
|
110
|
+
}, 500);
|
|
111
|
+
}, [editor, element]);
|
|
112
|
+
const onCloseClick = (0, _react.useCallback)(() => {
|
|
113
|
+
const element = aiRef.current;
|
|
114
|
+
element.style.display = 'none';
|
|
115
|
+
const articleDom = document.querySelector('.sdoc-editor__article');
|
|
116
|
+
articleDom.style.removeProperty('padding-bottom');
|
|
117
|
+
setSearchValue('');
|
|
118
|
+
setSearchResult('');
|
|
119
|
+
setIsShowAIPopover(false);
|
|
120
|
+
closeModule();
|
|
121
|
+
}, [closeModule]);
|
|
122
|
+
const onDocumentClick = (0, _react.useCallback)(event => {
|
|
123
|
+
// not in ai container
|
|
124
|
+
if (aiRef.current && aiRef.current.contains(event.target) && aiRef.current !== event.target) return;
|
|
125
|
+
// context menu toggle
|
|
126
|
+
const contextAskAI = document.querySelector('#context-toolbar-ai');
|
|
127
|
+
if (contextAskAI && contextAskAI.contains(event.target)) return;
|
|
128
|
+
const sideAskAI = document.querySelector('#side-toolbar-ai');
|
|
129
|
+
if (sideAskAI && sideAskAI.contains(event.target)) return;
|
|
130
|
+
|
|
131
|
+
// click in submenu
|
|
132
|
+
const adjustSubMenu = document.querySelector('.ai-adjust-sub-menu');
|
|
133
|
+
if (adjustSubMenu && adjustSubMenu.contains(event.target)) return;
|
|
134
|
+
const langSubMenu = document.querySelector('.ai-lang-sub-menu');
|
|
135
|
+
if (langSubMenu && langSubMenu.contains(event.target)) return;
|
|
136
|
+
if (!searchResult) {
|
|
137
|
+
onCloseClick();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (searchResult) {
|
|
141
|
+
setIsShowTipDialog(true);
|
|
142
|
+
}
|
|
143
|
+
}, [onCloseClick, searchResult]);
|
|
144
|
+
(0, _react.useEffect)(() => {
|
|
145
|
+
toggleAskAI();
|
|
146
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
147
|
+
}, []);
|
|
148
|
+
(0, _react.useEffect)(() => {
|
|
149
|
+
window.addEventListener('click', onDocumentClick);
|
|
150
|
+
return () => {
|
|
151
|
+
window.removeEventListener('click', onDocumentClick);
|
|
152
|
+
};
|
|
153
|
+
}, [onDocumentClick]);
|
|
154
|
+
(0, _react.useEffect)(() => {
|
|
155
|
+
let observerRefValue = null;
|
|
156
|
+
if (isShowAIPopover) {
|
|
157
|
+
scrollRef.current && scrollRef.current.addEventListener('scroll', onCloseClick);
|
|
158
|
+
observerRefValue = scrollRef.current;
|
|
159
|
+
} else {
|
|
160
|
+
scrollRef.current && scrollRef.current.removeEventListener('scroll', onCloseClick);
|
|
161
|
+
}
|
|
162
|
+
return () => {
|
|
163
|
+
if (observerRefValue) {
|
|
164
|
+
observerRefValue.removeEventListener('scroll', onCloseClick);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}, [isShowAIPopover, onCloseClick]);
|
|
168
|
+
const onSearchValueChanged = (0, _react.useCallback)(event => {
|
|
169
|
+
const value = event.target.value;
|
|
170
|
+
if (value === searchValue) return;
|
|
171
|
+
setSearchValue(value);
|
|
172
|
+
}, [searchValue]);
|
|
173
|
+
const onEnter = (0, _react.useCallback)(() => {
|
|
174
|
+
if (!searchValue) return;
|
|
175
|
+
setOpType(_constants.OPERATION_TYPES.DEFAULT);
|
|
176
|
+
setIsGenerating(true);
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
setIsGenerating(false);
|
|
179
|
+
setSearchResult('1 + 1 等于2.');
|
|
180
|
+
});
|
|
181
|
+
}, [searchValue]);
|
|
182
|
+
const onKeyDown = (0, _react.useCallback)(event => {
|
|
183
|
+
if ((0, _isHotkey.default)('enter', event)) {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
onEnter();
|
|
186
|
+
}
|
|
187
|
+
}, [onEnter]);
|
|
188
|
+
const inputValue = (0, _react.useMemo)(() => {
|
|
189
|
+
const generatingPlaceHolder = t('Thinking');
|
|
190
|
+
if (isGenerating) return generatingPlaceHolder;
|
|
191
|
+
if (!isGenerating) return searchValue;
|
|
192
|
+
}, [isGenerating, searchValue, t]);
|
|
193
|
+
const onContinuationClick = (0, _react.useCallback)(() => {
|
|
194
|
+
setOpType(_constants.OPERATION_TYPES.CONTINUATION);
|
|
195
|
+
setIsGenerating(true);
|
|
196
|
+
setTimeout(() => {
|
|
197
|
+
setSearchResult('[Feature is under development...]Thank you, the world becomes more beautiful because of you!');
|
|
198
|
+
setIsGenerating(false);
|
|
199
|
+
}, 2000);
|
|
200
|
+
}, []);
|
|
201
|
+
const onMoreDetailsClick = (0, _react.useCallback)(() => {
|
|
202
|
+
setOpType(_constants.OPERATION_TYPES.MORE_DETAILS);
|
|
203
|
+
setIsGenerating(true);
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
setSearchResult('[Function is under development...]Thank you, because of you, the world becomes more beautiful! Thank you for your attention, we will continue to provide you with high-quality services');
|
|
206
|
+
setIsGenerating(false);
|
|
207
|
+
}, 2000);
|
|
208
|
+
}, []);
|
|
209
|
+
const onMoreConciseClick = (0, _react.useCallback)(() => {
|
|
210
|
+
setOpType(_constants.OPERATION_TYPES.MORE_CONCISE);
|
|
211
|
+
setIsGenerating(true);
|
|
212
|
+
setTimeout(() => {
|
|
213
|
+
setSearchResult('[Functions are under development...] Because of you, the world becomes more beautiful!');
|
|
214
|
+
setIsGenerating(false);
|
|
215
|
+
}, 2000);
|
|
216
|
+
}, []);
|
|
217
|
+
const onMoreVividClick = (0, _react.useCallback)(() => {
|
|
218
|
+
setOpType(_constants.OPERATION_TYPES.MORE_VIVID);
|
|
219
|
+
setIsGenerating(true);
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
setSearchResult('[Functions are under development...] Because of you, the world has become full of flowers and seasons, allowing people to live in a happy time!');
|
|
222
|
+
setIsGenerating(false);
|
|
223
|
+
}, 2000);
|
|
224
|
+
}, []);
|
|
225
|
+
const onTranslateClick = (0, _react.useCallback)(lang => {
|
|
226
|
+
if (!searchValue) {
|
|
227
|
+
_toast.default.warning(t('The_translation_content_cannot_be_empty'));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
setOpType(_constants.OPERATION_TYPES.TRANSLATE);
|
|
231
|
+
const translateLang = lang ? lang : currentLang;
|
|
232
|
+
setCurrentLang(translateLang);
|
|
233
|
+
setIsGenerating(true);
|
|
234
|
+
_context.default.aiTranslate(searchValue, translateLang).then(res => {
|
|
235
|
+
const {
|
|
236
|
+
translation
|
|
237
|
+
} = res.data;
|
|
238
|
+
setSearchResult(translation);
|
|
239
|
+
setIsGenerating(false);
|
|
240
|
+
}).catch(err => {
|
|
241
|
+
setIsGenerating(false);
|
|
242
|
+
_toast.default.danger('Translation_error_message');
|
|
243
|
+
});
|
|
244
|
+
}, [currentLang, searchValue, t]);
|
|
245
|
+
const focusToEndPath = (0, _react.useCallback)(path => {
|
|
246
|
+
setTimeout(() => {
|
|
247
|
+
const endOfLastNodePoint = _slate.Editor.end(editor, path);
|
|
248
|
+
const range = {
|
|
249
|
+
anchor: endOfLastNodePoint,
|
|
250
|
+
focus: endOfLastNodePoint
|
|
251
|
+
};
|
|
252
|
+
(0, _core.focusEditor)(editor, range);
|
|
253
|
+
}, 0);
|
|
254
|
+
}, [editor]);
|
|
255
|
+
const onInsertClick = (0, _react.useCallback)(() => {
|
|
256
|
+
let nextPath = null;
|
|
257
|
+
if (!element) {
|
|
258
|
+
const aboveNode = (0, _core.getAboveBlockNode)(editor);
|
|
259
|
+
nextPath = _slate.Path.next(aboveNode[1]);
|
|
260
|
+
} else {
|
|
261
|
+
const path = _slateReact.ReactEditor.findPath(editor, element);
|
|
262
|
+
nextPath = _slate.Path.next(path);
|
|
263
|
+
}
|
|
264
|
+
const p = (0, _core.generateEmptyElement)(_constants2.PARAGRAPH);
|
|
265
|
+
p.children[0].text = searchResult;
|
|
266
|
+
_slate.Transforms.insertNodes(editor, p, {
|
|
267
|
+
at: nextPath
|
|
268
|
+
});
|
|
269
|
+
onCloseClick();
|
|
270
|
+
focusToEndPath(nextPath);
|
|
271
|
+
}, [editor, element, focusToEndPath, onCloseClick, searchResult]);
|
|
272
|
+
const onTryAgainClick = (0, _react.useCallback)(() => {
|
|
273
|
+
switch (opType) {
|
|
274
|
+
case _constants.OPERATION_TYPES.TRANSLATE:
|
|
275
|
+
onTranslateClick();
|
|
276
|
+
return;
|
|
277
|
+
case _constants.OPERATION_TYPES.MORE_DETAILS:
|
|
278
|
+
onMoreDetailsClick();
|
|
279
|
+
return;
|
|
280
|
+
case _constants.OPERATION_TYPES.MORE_CONCISE:
|
|
281
|
+
onMoreConciseClick();
|
|
282
|
+
return;
|
|
283
|
+
case _constants.OPERATION_TYPES.MORE_VIVID:
|
|
284
|
+
onMoreVividClick();
|
|
285
|
+
return;
|
|
286
|
+
case _constants.OPERATION_TYPES.CONTINUATION:
|
|
287
|
+
onContinuationClick();
|
|
288
|
+
return;
|
|
289
|
+
default:
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}, [onContinuationClick, onMoreConciseClick, onMoreDetailsClick, onMoreVividClick, onTranslateClick, opType]);
|
|
293
|
+
const onReplaceClick = (0, _react.useCallback)(() => {
|
|
294
|
+
if (!element) {
|
|
295
|
+
editor.deleteFragment();
|
|
296
|
+
if (searchResult) {
|
|
297
|
+
editor.insertText(searchResult);
|
|
298
|
+
}
|
|
299
|
+
onCloseClick();
|
|
300
|
+
const aboveNode = (0, _core.getAboveBlockNode)(editor);
|
|
301
|
+
focusToEndPath(aboveNode[1]);
|
|
302
|
+
} else {
|
|
303
|
+
const path = _slateReact.ReactEditor.findPath(editor, element);
|
|
304
|
+
_slate.Transforms.removeNodes(editor, {
|
|
305
|
+
at: path
|
|
306
|
+
});
|
|
307
|
+
const p = (0, _core.generateEmptyElement)(_constants2.PARAGRAPH);
|
|
308
|
+
p.children[0].text = searchResult;
|
|
309
|
+
_slate.Transforms.insertNodes(editor, p, {
|
|
310
|
+
at: path
|
|
311
|
+
});
|
|
312
|
+
onCloseClick();
|
|
313
|
+
focusToEndPath(path);
|
|
314
|
+
}
|
|
315
|
+
}, [editor, element, focusToEndPath, onCloseClick, searchResult]);
|
|
316
|
+
const onCopyClick = (0, _react.useCallback)(() => {
|
|
317
|
+
(0, _copyToClipboard.default)(searchResult);
|
|
318
|
+
_toast.default.success(t('Copied'), {
|
|
319
|
+
hasCloseButton: false,
|
|
320
|
+
duration: 2
|
|
321
|
+
});
|
|
322
|
+
}, [searchResult, t]);
|
|
323
|
+
const onDeprecationClick = (0, _react.useCallback)(() => {
|
|
324
|
+
setIsShowTipDialog(true);
|
|
325
|
+
}, []);
|
|
326
|
+
const isShowAdjust = (0, _react.useMemo)(() => {
|
|
327
|
+
return ![_constants.OPERATION_TYPES.DEFAULT, _constants.OPERATION_TYPES.TRANSLATE].includes(opType);
|
|
328
|
+
}, [opType]);
|
|
329
|
+
const isShowReplace = (0, _react.useMemo)(() => {
|
|
330
|
+
return opType !== _constants.OPERATION_TYPES.DEFAULT;
|
|
331
|
+
}, [opType]);
|
|
332
|
+
const resultMenu = (0, _react.useMemo)(() => {
|
|
333
|
+
const type = opType && opType.toUpperCase();
|
|
334
|
+
if (opType === _constants.OPERATION_TYPES.TRANSLATE) {
|
|
335
|
+
return _constants.LANG_MENU_CONFIG[currentLang.toUpperCase()];
|
|
336
|
+
}
|
|
337
|
+
return _constants.OPERATION_MENUS_CONFIG[type];
|
|
338
|
+
}, [currentLang, opType]);
|
|
339
|
+
const closeTipDialog = (0, _react.useCallback)(() => {
|
|
340
|
+
setIsShowTipDialog(false);
|
|
341
|
+
}, []);
|
|
342
|
+
const discardCurrentContent = (0, _react.useCallback)(() => {
|
|
343
|
+
onCloseClick();
|
|
344
|
+
setIsShowTipDialog(false);
|
|
345
|
+
}, [onCloseClick]);
|
|
346
|
+
return /*#__PURE__*/_react.default.createElement(_commons.ElementPopover, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
347
|
+
className: "sdoc-ai-module-container",
|
|
348
|
+
ref: aiRef
|
|
349
|
+
}, !searchResult && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
350
|
+
className: "sdoc-ai-content"
|
|
351
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
352
|
+
className: "sdoc-ai-search"
|
|
353
|
+
}, /*#__PURE__*/_react.default.createElement(_aiIcon.default, null), /*#__PURE__*/_react.default.createElement("input", {
|
|
354
|
+
type: "text",
|
|
355
|
+
ref: inputRef,
|
|
356
|
+
autoFocus: true,
|
|
357
|
+
placeholder: t('Ask_AI_anything'),
|
|
358
|
+
value: inputValue,
|
|
359
|
+
onKeyDown: onKeyDown,
|
|
360
|
+
onChange: onSearchValueChanged
|
|
361
|
+
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
362
|
+
className: `sdocfont sdoc-send-arrow ${!searchValue ? 'disable' : ''}`,
|
|
363
|
+
onClick: onEnter
|
|
364
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
365
|
+
className: "sdoc-ai-operations sdoc-dropdown-menu"
|
|
366
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
367
|
+
className: "op-type"
|
|
368
|
+
}, t('Suggestion')), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
369
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.CONTINUATION,
|
|
370
|
+
onClick: onContinuationClick
|
|
371
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
372
|
+
className: "sdoc-dropdown-menu-divider"
|
|
373
|
+
}), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
374
|
+
className: "op-type"
|
|
375
|
+
}, t('Edit')), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
376
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.MORE_DETAILS,
|
|
377
|
+
onClick: onMoreDetailsClick
|
|
378
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
379
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.MORE_CONCISE,
|
|
380
|
+
onClick: onMoreConciseClick
|
|
381
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
382
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.MORE_VIVID,
|
|
383
|
+
onClick: onMoreVividClick
|
|
384
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
385
|
+
className: "sdoc-dropdown-menu-divider"
|
|
386
|
+
}), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
387
|
+
className: "op-type"
|
|
388
|
+
}, t('Translate')), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
389
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.TRANSLATE
|
|
390
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
391
|
+
className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
|
|
392
|
+
}), /*#__PURE__*/_react.default.createElement(_langSubMenu.default, {
|
|
393
|
+
target: _constants.OPERATION_MENUS_CONFIG.TRANSLATE.id,
|
|
394
|
+
onTranslateClick: onTranslateClick
|
|
395
|
+
}))))), searchResult && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
396
|
+
className: "sdoc-ai-content has-result"
|
|
397
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
398
|
+
className: "sdoc-ai-result"
|
|
399
|
+
}, resultMenu && /*#__PURE__*/_react.default.createElement("div", {
|
|
400
|
+
className: "sdoc-ai-result-header"
|
|
401
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_aiIcon.default, null), /*#__PURE__*/_react.default.createElement("span", null, t(resultMenu.text))), /*#__PURE__*/_react.default.createElement("span", {
|
|
402
|
+
className: "sdocfont sdoc-close",
|
|
403
|
+
onClick: onDeprecationClick
|
|
404
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
405
|
+
className: "sdoc-ai-result-content"
|
|
406
|
+
}, isGenerating ? t('Processing_message') : searchResult), /*#__PURE__*/_react.default.createElement("div", {
|
|
407
|
+
className: "sdoc-ai-statistic"
|
|
408
|
+
}, t('Generated_content_x_words', {
|
|
409
|
+
count: searchResult.length
|
|
410
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
411
|
+
className: "sdoc-ai-search"
|
|
412
|
+
}, /*#__PURE__*/_react.default.createElement(_aiIcon.default, null), /*#__PURE__*/_react.default.createElement("input", {
|
|
413
|
+
placeholder: t('Ask_AI_anything'),
|
|
414
|
+
value: inputValue,
|
|
415
|
+
onKeyDown: onKeyDown,
|
|
416
|
+
onChange: onSearchValueChanged
|
|
417
|
+
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
418
|
+
className: "sdocfont sdoc-send-arrow",
|
|
419
|
+
onClick: onEnter
|
|
420
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
421
|
+
className: "sdoc-ai-operations sdoc-dropdown-menu"
|
|
422
|
+
}, /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
423
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.ADJUSTMENT,
|
|
424
|
+
isHidden: !isShowAdjust
|
|
425
|
+
}, /*#__PURE__*/_react.default.createElement("i", {
|
|
426
|
+
className: "sdocfont sdoc-right-slide sdoc-dropdown-item-right-icon"
|
|
427
|
+
}), /*#__PURE__*/_react.default.createElement(_adjustSubMenu.default, {
|
|
428
|
+
target: _constants.OPERATION_MENUS_CONFIG.ADJUSTMENT.id,
|
|
429
|
+
onMoreDetailsClick: onMoreDetailsClick,
|
|
430
|
+
onMoreConciseClick: onMoreConciseClick,
|
|
431
|
+
onMoreVividClick: onMoreVividClick
|
|
432
|
+
})), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
433
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.INSERT_BELOW,
|
|
434
|
+
onClick: onInsertClick
|
|
435
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
436
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.TRY_AGAIN,
|
|
437
|
+
onClick: onTryAgainClick
|
|
438
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
439
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.REPLACE,
|
|
440
|
+
isHidden: !isShowReplace,
|
|
441
|
+
onClick: onReplaceClick
|
|
442
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
443
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.COPY,
|
|
444
|
+
onClick: onCopyClick
|
|
445
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
446
|
+
menuConfig: _constants.OPERATION_MENUS_CONFIG.DEPRECATION,
|
|
447
|
+
onClick: onDeprecationClick
|
|
448
|
+
})))), isShowTipDialog && /*#__PURE__*/_react.default.createElement(_tipDialog.default, {
|
|
449
|
+
closeDialog: closeTipDialog,
|
|
450
|
+
discardCurrentContent: discardCurrentContent
|
|
451
|
+
}));
|
|
452
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactstrap = require("reactstrap");
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _dropdownMenuItem = _interopRequireDefault(require("../../../commons/dropdown-menu-item"));
|
|
13
|
+
const LangSubMenu = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
target,
|
|
16
|
+
onTranslateClick
|
|
17
|
+
} = _ref;
|
|
18
|
+
const onEnClick = (0, _react.useCallback)(() => {
|
|
19
|
+
onTranslateClick('en');
|
|
20
|
+
}, [onTranslateClick]);
|
|
21
|
+
const onZhcnClick = (0, _react.useCallback)(() => {
|
|
22
|
+
onTranslateClick('zh-cn');
|
|
23
|
+
}, [onTranslateClick]);
|
|
24
|
+
|
|
25
|
+
// const onFrClick = useCallback(() => {
|
|
26
|
+
// onTranslateClick('fr');
|
|
27
|
+
// }, [onTranslateClick]);
|
|
28
|
+
|
|
29
|
+
// const onDeClick = useCallback(() => {
|
|
30
|
+
// onTranslateClick('de');
|
|
31
|
+
// }, [onTranslateClick]);
|
|
32
|
+
|
|
33
|
+
// const onRuClick = useCallback(() => {
|
|
34
|
+
// onTranslateClick('ru');
|
|
35
|
+
// }, [onTranslateClick]);
|
|
36
|
+
|
|
37
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.UncontrolledPopover, {
|
|
38
|
+
boundariesElement: "viewport",
|
|
39
|
+
target: target,
|
|
40
|
+
className: "ai-lang-sub-menu sdoc-sub-dropdown-menu sdoc-dropdown-menu",
|
|
41
|
+
trigger: "hover",
|
|
42
|
+
placement: "right-start",
|
|
43
|
+
hideArrow: true,
|
|
44
|
+
fade: false
|
|
45
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
46
|
+
className: "sdoc-dropdown-menu-container"
|
|
47
|
+
}, /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
48
|
+
menuConfig: _constants.LANG_MENU_CONFIG.EN,
|
|
49
|
+
onClick: onEnClick
|
|
50
|
+
}), /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
51
|
+
menuConfig: _constants.LANG_MENU_CONFIG.ZH_CN,
|
|
52
|
+
onClick: onZhcnClick
|
|
53
|
+
})));
|
|
54
|
+
};
|
|
55
|
+
var _default = exports.default = LangSubMenu;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
.sdoc-ai-module-container {
|
|
2
|
+
position: absolute;
|
|
3
|
+
z-index: 1000;
|
|
4
|
+
width: 100%;
|
|
5
|
+
max-width: 672px;
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sdoc-ai-module-container .sdoc-ai-content {
|
|
10
|
+
background-color: #fff;
|
|
11
|
+
border: 1px solid #eee;
|
|
12
|
+
border-radius: 10px;
|
|
13
|
+
box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.sdoc-ai-content .sdoc-ai-search {
|
|
17
|
+
position: relative;
|
|
18
|
+
height: 50px;
|
|
19
|
+
line-height: 50px;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sdoc-ai-content .sdoc-ai-search input {
|
|
25
|
+
border: none;
|
|
26
|
+
padding: 0 44px;
|
|
27
|
+
border-radius: 10px;
|
|
28
|
+
width: 100%;
|
|
29
|
+
outline: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.sdoc-ai-content .sdoc-ai-search input {
|
|
33
|
+
border: none;
|
|
34
|
+
padding: 0 44px;
|
|
35
|
+
border-radius: 10px;
|
|
36
|
+
width: 100%;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow {
|
|
40
|
+
position: absolute;
|
|
41
|
+
right: 16px;
|
|
42
|
+
color: #ff9800;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow.disable {
|
|
47
|
+
color: #BDBDBD;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.sdoc-ai-content .sdoc-ai-result {
|
|
51
|
+
position: relative;
|
|
52
|
+
height: 50px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.sdoc-ai-module-container .sdoc-ai-operations {
|
|
56
|
+
width: 200px;
|
|
57
|
+
margin-top: 8px;
|
|
58
|
+
padding: 8px 0;
|
|
59
|
+
border: 1px solid #eee;
|
|
60
|
+
border-radius: 10px;
|
|
61
|
+
box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
|
|
62
|
+
background-color: #fff;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.sdoc-ai-module-container .sdoc-ai-operations .op-type {
|
|
66
|
+
color: #666;
|
|
67
|
+
font-size: 14px;
|
|
68
|
+
min-height: 32px;
|
|
69
|
+
padding: 3px 12px;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.sdoc-ai-module-container .sdoc-ai-result {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: column;
|
|
75
|
+
padding: 16px;
|
|
76
|
+
height: auto;
|
|
77
|
+
max-height: 300px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header {
|
|
81
|
+
display: flex;
|
|
82
|
+
justify-content: space-between;
|
|
83
|
+
align-items: center;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header .sdocfont {
|
|
87
|
+
font-size: 14px;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header .sdoc-ask-ai {
|
|
91
|
+
margin-right: 10px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header .sdoc-close {
|
|
95
|
+
color: #999;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header .sdoc-close:hover {
|
|
99
|
+
color: #555;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-content {
|
|
103
|
+
padding: 16px 0;
|
|
104
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = TipDialog;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactI18next = require("react-i18next");
|
|
10
|
+
var _reactstrap = require("reactstrap");
|
|
11
|
+
function TipDialog(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
closeDialog,
|
|
14
|
+
discardCurrentContent
|
|
15
|
+
} = _ref;
|
|
16
|
+
const {
|
|
17
|
+
t
|
|
18
|
+
} = (0, _reactI18next.useTranslation)('sdoc-editor');
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Modal, {
|
|
20
|
+
isOpen: true,
|
|
21
|
+
toggle: closeDialog
|
|
22
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.ModalHeader, {
|
|
23
|
+
toggle: closeDialog
|
|
24
|
+
}, t('Tip')), /*#__PURE__*/_react.default.createElement(_reactstrap.ModalBody, null, t('AI_tip_content')), /*#__PURE__*/_react.default.createElement(_reactstrap.ModalFooter, null, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
25
|
+
color: "secondary",
|
|
26
|
+
className: "mr-2",
|
|
27
|
+
onClick: closeDialog
|
|
28
|
+
}, t('Cancel')), /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
29
|
+
color: "primary",
|
|
30
|
+
onClick: discardCurrentContent
|
|
31
|
+
}, t('Discard'))));
|
|
32
|
+
}
|