@seafile/sdoc-editor 2.0.23 → 2.0.24
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
CHANGED
|
@@ -205,11 +205,14 @@ class SeafileAPI {
|
|
|
205
205
|
form.append('file_uuid', docUuid);
|
|
206
206
|
return this.req.post(url, form);
|
|
207
207
|
}
|
|
208
|
-
writingAssistant(docUuid, text, type) {
|
|
208
|
+
writingAssistant(docUuid, text, type, custom_prompt) {
|
|
209
209
|
const url = '/api/v2.1/ai/writing-assistant/';
|
|
210
210
|
let form = new FormData();
|
|
211
211
|
form.append('text', text);
|
|
212
212
|
form.append('writing_type', type);
|
|
213
|
+
if (custom_prompt) {
|
|
214
|
+
form.append('custom_prompt', custom_prompt);
|
|
215
|
+
}
|
|
213
216
|
form.append('file_uuid', docUuid);
|
|
214
217
|
return this.req.post(url, form);
|
|
215
218
|
}
|
|
@@ -40,6 +40,7 @@ function AIModule(_ref) {
|
|
|
40
40
|
const [opType, setOpType] = (0, _react.useState)('');
|
|
41
41
|
const [selectedValue, setSelectedValue] = (0, _react.useState)('');
|
|
42
42
|
const [searchValue, setSearchValue] = (0, _react.useState)('');
|
|
43
|
+
const [oldSearchValue, setOldSearchValue] = (0, _react.useState)('');
|
|
43
44
|
const [isGenerating, setIsGenerating] = (0, _react.useState)(false);
|
|
44
45
|
const [searchResult, setSearchResult] = (0, _react.useState)(null);
|
|
45
46
|
const [currentLang, setCurrentLang] = (0, _react.useState)('en');
|
|
@@ -160,13 +161,10 @@ function AIModule(_ref) {
|
|
|
160
161
|
}, [onDocumentClick]);
|
|
161
162
|
const onScroll = (0, _react.useCallback)(event => {
|
|
162
163
|
if (!element) {
|
|
163
|
-
console.log(selectDom);
|
|
164
164
|
const newRect = selectDom.getBoundingClientRect();
|
|
165
165
|
const aboveNode = (0, _core.getAboveBlockNode)(editor);
|
|
166
166
|
const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
|
|
167
167
|
const slateRect = slateDom.getBoundingClientRect();
|
|
168
|
-
console.log(newRect);
|
|
169
|
-
console.log(slateRect);
|
|
170
168
|
const el = aiRef.current;
|
|
171
169
|
el.style.top = `${newRect.bottom + 8}px`; // top = Current top + Element height
|
|
172
170
|
el.style.left = `${slateRect.left}px`;
|
|
@@ -203,20 +201,25 @@ function AIModule(_ref) {
|
|
|
203
201
|
if (!searchValue) return;
|
|
204
202
|
setOpType(_constants.OPERATION_TYPES.DEFAULT);
|
|
205
203
|
setIsGenerating(true);
|
|
206
|
-
const defaultContent =
|
|
207
|
-
|
|
204
|
+
const defaultContent = selectedValue;
|
|
205
|
+
const custom_prompt = searchValue;
|
|
206
|
+
if (!custom_prompt) {
|
|
208
207
|
_toast.default.danger(t('Processing_content_cannot_be_empty'));
|
|
209
208
|
return;
|
|
210
209
|
}
|
|
211
|
-
_context.default.writingAssistant(defaultContent, 'ask').then(res => {
|
|
210
|
+
_context.default.writingAssistant(defaultContent, 'ask', custom_prompt).then(res => {
|
|
212
211
|
const {
|
|
213
212
|
content
|
|
214
213
|
} = res.data;
|
|
215
214
|
setSearchResult(content);
|
|
216
215
|
setIsGenerating(false);
|
|
216
|
+
setSearchValue('');
|
|
217
|
+
setOldSearchValue(searchValue);
|
|
217
218
|
}).catch(err => {
|
|
218
219
|
setIsGenerating(false);
|
|
219
220
|
_toast.default.danger('AI_error_message');
|
|
221
|
+
setSearchValue('');
|
|
222
|
+
setOldSearchValue(searchValue);
|
|
220
223
|
});
|
|
221
224
|
}, [searchValue, selectedValue, t]);
|
|
222
225
|
const onKeyDown = (0, _react.useCallback)(event => {
|
|
@@ -233,7 +236,7 @@ function AIModule(_ref) {
|
|
|
233
236
|
const onContinuationClick = (0, _react.useCallback)(() => {
|
|
234
237
|
setOpType(_constants.OPERATION_TYPES.CONTINUATION);
|
|
235
238
|
setIsGenerating(true);
|
|
236
|
-
const defaultContent =
|
|
239
|
+
const defaultContent = selectedValue;
|
|
237
240
|
if (!defaultContent) {
|
|
238
241
|
_toast.default.danger(t('Processing_content_cannot_be_empty'));
|
|
239
242
|
return;
|
|
@@ -248,11 +251,11 @@ function AIModule(_ref) {
|
|
|
248
251
|
setIsGenerating(false);
|
|
249
252
|
_toast.default.danger('AI_error_message');
|
|
250
253
|
});
|
|
251
|
-
}, [
|
|
254
|
+
}, [selectedValue, t]);
|
|
252
255
|
const onMoreDetailsClick = (0, _react.useCallback)(() => {
|
|
253
256
|
setOpType(_constants.OPERATION_TYPES.MORE_DETAILS);
|
|
254
257
|
setIsGenerating(true);
|
|
255
|
-
const defaultContent =
|
|
258
|
+
const defaultContent = selectedValue;
|
|
256
259
|
if (!defaultContent) {
|
|
257
260
|
_toast.default.danger(t('Processing_content_cannot_be_empty'));
|
|
258
261
|
return;
|
|
@@ -267,11 +270,11 @@ function AIModule(_ref) {
|
|
|
267
270
|
setIsGenerating(false);
|
|
268
271
|
_toast.default.danger('AI_error_message');
|
|
269
272
|
});
|
|
270
|
-
}, [
|
|
273
|
+
}, [selectedValue, t]);
|
|
271
274
|
const onMoreConciseClick = (0, _react.useCallback)(() => {
|
|
272
275
|
setOpType(_constants.OPERATION_TYPES.MORE_CONCISE);
|
|
273
276
|
setIsGenerating(true);
|
|
274
|
-
const defaultContent =
|
|
277
|
+
const defaultContent = selectedValue;
|
|
275
278
|
if (!defaultContent) {
|
|
276
279
|
_toast.default.danger(t('Processing_content_cannot_be_empty'));
|
|
277
280
|
return;
|
|
@@ -286,11 +289,11 @@ function AIModule(_ref) {
|
|
|
286
289
|
setIsGenerating(false);
|
|
287
290
|
_toast.default.danger('AI_error_message');
|
|
288
291
|
});
|
|
289
|
-
}, [
|
|
292
|
+
}, [selectedValue, t]);
|
|
290
293
|
const onMoreVividClick = (0, _react.useCallback)(() => {
|
|
291
294
|
setOpType(_constants.OPERATION_TYPES.MORE_VIVID);
|
|
292
295
|
setIsGenerating(true);
|
|
293
|
-
const defaultContent =
|
|
296
|
+
const defaultContent = selectedValue;
|
|
294
297
|
if (!defaultContent) {
|
|
295
298
|
_toast.default.danger(t('Processing_content_cannot_be_empty'));
|
|
296
299
|
return;
|
|
@@ -305,9 +308,9 @@ function AIModule(_ref) {
|
|
|
305
308
|
setIsGenerating(false);
|
|
306
309
|
_toast.default.danger('Translation_error_message');
|
|
307
310
|
});
|
|
308
|
-
}, [
|
|
311
|
+
}, [selectedValue, t]);
|
|
309
312
|
const onTranslateClick = (0, _react.useCallback)(lang => {
|
|
310
|
-
const translateValue =
|
|
313
|
+
const translateValue = selectedValue;
|
|
311
314
|
if (!translateValue) {
|
|
312
315
|
_toast.default.warning(t('The_translation_content_cannot_be_empty'));
|
|
313
316
|
return;
|
|
@@ -326,7 +329,7 @@ function AIModule(_ref) {
|
|
|
326
329
|
setIsGenerating(false);
|
|
327
330
|
_toast.default.danger('Translation_error_message');
|
|
328
331
|
});
|
|
329
|
-
}, [currentLang,
|
|
332
|
+
}, [currentLang, selectedValue, t]);
|
|
330
333
|
const focusToEndPath = (0, _react.useCallback)(path => {
|
|
331
334
|
setTimeout(() => {
|
|
332
335
|
const endOfLastNodePoint = _slate.Editor.end(editor, path);
|
|
@@ -357,7 +360,7 @@ function AIModule(_ref) {
|
|
|
357
360
|
onCloseClick();
|
|
358
361
|
focusToEndPath(nextPath);
|
|
359
362
|
}, [editor, element, focusToEndPath, onCloseClick, searchResult]);
|
|
360
|
-
const onTryAgainClick = (0, _react.useCallback)(
|
|
363
|
+
const onTryAgainClick = (0, _react.useCallback)(event => {
|
|
361
364
|
switch (opType) {
|
|
362
365
|
case _constants.OPERATION_TYPES.TRANSLATE:
|
|
363
366
|
onTranslateClick();
|
|
@@ -374,10 +377,17 @@ function AIModule(_ref) {
|
|
|
374
377
|
case _constants.OPERATION_TYPES.CONTINUATION:
|
|
375
378
|
onContinuationClick();
|
|
376
379
|
return;
|
|
380
|
+
case _constants.OPERATION_TYPES.DEFAULT:
|
|
381
|
+
event.stopPropagation();
|
|
382
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
383
|
+
setSearchValue(oldSearchValue);
|
|
384
|
+
setSearchResult('');
|
|
385
|
+
setOldSearchValue('');
|
|
386
|
+
return;
|
|
377
387
|
default:
|
|
378
388
|
return;
|
|
379
389
|
}
|
|
380
|
-
}, [onContinuationClick, onMoreConciseClick, onMoreDetailsClick, onMoreVividClick, onTranslateClick, opType]);
|
|
390
|
+
}, [oldSearchValue, onContinuationClick, onMoreConciseClick, onMoreDetailsClick, onMoreVividClick, onTranslateClick, opType]);
|
|
381
391
|
const onReplaceClick = (0, _react.useCallback)(() => {
|
|
382
392
|
if (!element) {
|
|
383
393
|
editor.deleteFragment();
|
|
@@ -410,7 +420,8 @@ function AIModule(_ref) {
|
|
|
410
420
|
hasCloseButton: false,
|
|
411
421
|
duration: 2
|
|
412
422
|
});
|
|
413
|
-
|
|
423
|
+
onCloseClick();
|
|
424
|
+
}, [onCloseClick, searchResult, t]);
|
|
414
425
|
const onDeprecationClick = (0, _react.useCallback)(() => {
|
|
415
426
|
onCloseClick();
|
|
416
427
|
}, [onCloseClick]);
|
|
@@ -446,7 +457,7 @@ function AIModule(_ref) {
|
|
|
446
457
|
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
447
458
|
className: `sdocfont sdoc-send-arrow ${!searchValue ? 'disable' : ''}`,
|
|
448
459
|
onClick: onEnter
|
|
449
|
-
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
460
|
+
}))), !searchValue && /*#__PURE__*/_react.default.createElement("div", {
|
|
450
461
|
className: "sdoc-ai-operations sdoc-dropdown-menu"
|
|
451
462
|
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
|
|
452
463
|
className: "op-type"
|
|
@@ -493,7 +504,7 @@ function AIModule(_ref) {
|
|
|
493
504
|
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
494
505
|
className: `sdocfont sdoc-send-arrow ${!searchValue ? 'disable' : ''}`,
|
|
495
506
|
onClick: onEnter
|
|
496
|
-
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
507
|
+
}))), !searchValue && /*#__PURE__*/_react.default.createElement("div", {
|
|
497
508
|
className: "sdoc-ai-operations sdoc-dropdown-menu"
|
|
498
509
|
}, /*#__PURE__*/_react.default.createElement(_dropdownMenuItem.default, {
|
|
499
510
|
menuConfig: _constants.OPERATION_MENUS_CONFIG.ADJUSTMENT,
|
package/dist/context.js
CHANGED
|
@@ -263,9 +263,9 @@ class Context {
|
|
|
263
263
|
const docUuid = this.getDocUuid();
|
|
264
264
|
return this.api.aiTranslate(docUuid, text, lang);
|
|
265
265
|
}
|
|
266
|
-
writingAssistant(text, type) {
|
|
266
|
+
writingAssistant(text, type, custom_prompt) {
|
|
267
267
|
const docUuid = this.getDocUuid();
|
|
268
|
-
return this.api.writingAssistant(docUuid, text, type);
|
|
268
|
+
return this.api.writingAssistant(docUuid, text, type, custom_prompt);
|
|
269
269
|
}
|
|
270
270
|
updateConfigUuid(docUuid) {
|
|
271
271
|
if (!this.config) return;
|
package/package.json
CHANGED
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
"Try_again": "Try again",
|
|
595
595
|
"Deprecation": "Deprecation",
|
|
596
596
|
"Generated_content_x_words": "Generated content {{count}} words",
|
|
597
|
-
"Ask_AI_anything": "
|
|
597
|
+
"Ask_AI_anything": "Please enter the command...",
|
|
598
598
|
"Thinking": "Thinking...",
|
|
599
599
|
"Translation_error_message": "Translation error, please try again.",
|
|
600
600
|
"The_translation_content_cannot_be_empty": "The translation content cannot be empty",
|
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
"Try_again": "再试一次",
|
|
595
595
|
"Deprecation": "弃用",
|
|
596
596
|
"Generated_content_x_words": "已生成内容 {{count}} 字",
|
|
597
|
-
"Ask_AI_anything": "
|
|
597
|
+
"Ask_AI_anything": "请输入指令...",
|
|
598
598
|
"Thinking": "思考中...",
|
|
599
599
|
"Translation_error_message": "翻译出错,请重试",
|
|
600
600
|
"The_translation_content_cannot_be_empty": "翻译内容不能为空",
|