@seafile/sdoc-editor 1.0.189 → 1.0.190-alpha2

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.
@@ -198,12 +198,20 @@ class SeafileAPI {
198
198
  return this.req.put(url);
199
199
  }
200
200
  aiTranslate(docUuid, text, lang) {
201
- const url = '/api/v2.1/ai/translate/?file_uuid=' + docUuid;
201
+ const url = '/api/v2.1/ai/translate/';
202
202
  let form = new FormData();
203
203
  form.append('text', text);
204
204
  form.append('lang', lang);
205
205
  form.append('file_uuid', docUuid);
206
206
  return this.req.post(url, form);
207
207
  }
208
+ writingAssistant(docUuid, text, type) {
209
+ const url = '/api/v2.1/ai/writing-assistant/';
210
+ let form = new FormData();
211
+ form.append('text', text);
212
+ form.append('writing_type', type);
213
+ form.append('file_uuid', docUuid);
214
+ return this.req.post(url, form);
215
+ }
208
216
  }
209
217
  var _default = exports.default = SeafileAPI;
@@ -203,11 +203,22 @@ function AIModule(_ref) {
203
203
  if (!searchValue) return;
204
204
  setOpType(_constants.OPERATION_TYPES.DEFAULT);
205
205
  setIsGenerating(true);
206
- setTimeout(() => {
206
+ const defaultContent = searchValue || selectedValue;
207
+ if (!defaultContent) {
208
+ _toast.default.danger(t('Processing_content_cannot_be_empty'));
209
+ return;
210
+ }
211
+ _context.default.writingAssistant(defaultContent, 'ask').then(res => {
212
+ const {
213
+ content
214
+ } = res.data;
215
+ setSearchResult(content);
207
216
  setIsGenerating(false);
208
- setSearchResult('[Feature is under development...]Thank you, the world becomes more beautiful because of you!');
209
- }, 2000);
210
- }, [searchValue]);
217
+ }).catch(err => {
218
+ setIsGenerating(false);
219
+ _toast.default.danger('AI_error_message');
220
+ });
221
+ }, [searchValue, selectedValue, t]);
211
222
  const onKeyDown = (0, _react.useCallback)(event => {
212
223
  if ((0, _isHotkey.default)('enter', event)) {
213
224
  event.preventDefault();
@@ -222,35 +233,79 @@ function AIModule(_ref) {
222
233
  const onContinuationClick = (0, _react.useCallback)(() => {
223
234
  setOpType(_constants.OPERATION_TYPES.CONTINUATION);
224
235
  setIsGenerating(true);
225
- setTimeout(() => {
226
- setSearchResult('[Feature is under development...]Thank you, the world becomes more beautiful because of you!');
236
+ const defaultContent = searchValue || selectedValue;
237
+ if (!defaultContent) {
238
+ _toast.default.danger(t('Processing_content_cannot_be_empty'));
239
+ return;
240
+ }
241
+ _context.default.writingAssistant(defaultContent, 'continue_writing').then(res => {
242
+ const {
243
+ content
244
+ } = res.data;
245
+ setSearchResult(content);
227
246
  setIsGenerating(false);
228
- }, 2000);
229
- }, []);
247
+ }).catch(err => {
248
+ setIsGenerating(false);
249
+ _toast.default.danger('AI_error_message');
250
+ });
251
+ }, [searchValue, selectedValue, t]);
230
252
  const onMoreDetailsClick = (0, _react.useCallback)(() => {
231
253
  setOpType(_constants.OPERATION_TYPES.MORE_DETAILS);
232
254
  setIsGenerating(true);
233
- setTimeout(() => {
234
- 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');
255
+ const defaultContent = searchValue || selectedValue;
256
+ if (!defaultContent) {
257
+ _toast.default.danger(t('Processing_content_cannot_be_empty'));
258
+ return;
259
+ }
260
+ _context.default.writingAssistant(defaultContent, _constants.OPERATION_TYPES.MORE_DETAILS).then(res => {
261
+ const {
262
+ content
263
+ } = res.data;
264
+ setSearchResult(content);
235
265
  setIsGenerating(false);
236
- }, 2000);
237
- }, []);
266
+ }).catch(err => {
267
+ setIsGenerating(false);
268
+ _toast.default.danger('AI_error_message');
269
+ });
270
+ }, [searchValue, selectedValue, t]);
238
271
  const onMoreConciseClick = (0, _react.useCallback)(() => {
239
272
  setOpType(_constants.OPERATION_TYPES.MORE_CONCISE);
240
273
  setIsGenerating(true);
241
- setTimeout(() => {
242
- setSearchResult('[Functions are under development...] Because of you, the world becomes more beautiful!');
274
+ const defaultContent = searchValue || selectedValue;
275
+ if (!defaultContent) {
276
+ _toast.default.danger(t('Processing_content_cannot_be_empty'));
277
+ return;
278
+ }
279
+ _context.default.writingAssistant(defaultContent, _constants.OPERATION_TYPES.MORE_CONCISE).then(res => {
280
+ const {
281
+ content
282
+ } = res.data;
283
+ setSearchResult(content);
243
284
  setIsGenerating(false);
244
- }, 2000);
245
- }, []);
285
+ }).catch(err => {
286
+ setIsGenerating(false);
287
+ _toast.default.danger('AI_error_message');
288
+ });
289
+ }, [searchValue, selectedValue, t]);
246
290
  const onMoreVividClick = (0, _react.useCallback)(() => {
247
291
  setOpType(_constants.OPERATION_TYPES.MORE_VIVID);
248
292
  setIsGenerating(true);
249
- setTimeout(() => {
250
- 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!');
293
+ const defaultContent = searchValue || selectedValue;
294
+ if (!defaultContent) {
295
+ _toast.default.danger(t('Processing_content_cannot_be_empty'));
296
+ return;
297
+ }
298
+ _context.default.writingAssistant(defaultContent, _constants.OPERATION_TYPES.MORE_VIVID).then(res => {
299
+ const {
300
+ content
301
+ } = res.data;
302
+ setSearchResult(content);
251
303
  setIsGenerating(false);
252
- }, 2000);
253
- }, []);
304
+ }).catch(err => {
305
+ setIsGenerating(false);
306
+ _toast.default.danger('Translation_error_message');
307
+ });
308
+ }, [searchValue, selectedValue, t]);
254
309
  const onTranslateClick = (0, _react.useCallback)(lang => {
255
310
  const translateValue = searchValue ? searchValue : selectedValue;
256
311
  if (!translateValue) {
@@ -42,15 +42,13 @@
42
42
  position: absolute;
43
43
  right: 16px;
44
44
  color: #ff9800;
45
-
45
+ cursor: pointer;
46
+ pointer-events: auto;
46
47
  }
47
48
 
48
49
  .sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow.disable {
49
50
  color: #BDBDBD;
50
- }
51
-
52
- .sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow:not(.disable) {
53
- cursor: pointer;
51
+ cursor: text;
54
52
  }
55
53
 
56
54
  .sdoc-ai-content .sdoc-ai-result {
@@ -18,6 +18,7 @@ var _constants2 = require("../constants");
18
18
  var _core = require("../../../core");
19
19
  var _elementType = require("../../../constants/element-type");
20
20
  var _helpers2 = require("../../wiki-link/helpers");
21
+ var _context = _interopRequireDefault(require("../../../../context"));
21
22
  require("./render-elem.css");
22
23
  const SdocFileLink = _ref => {
23
24
  let {
@@ -85,6 +86,11 @@ const SdocFileLink = _ref => {
85
86
  // eslint-disable-next-line react-hooks/exhaustive-deps
86
87
  }, [isShowInsertHoverMenu]);
87
88
  const onClickFile = (0, _react.useCallback)(e => {
89
+ if (_context.default.getSetting('isWikiReadOnly')) {
90
+ console.log('wiki readonly', element.doc_uuid);
91
+ window.open(element.doc_uuid);
92
+ return;
93
+ }
88
94
  if (readOnly) {
89
95
  window.open((0, _helpers.getUrl)(element.doc_uuid));
90
96
  return;
@@ -10,6 +10,7 @@ var _slugid = _interopRequireDefault(require("slugid"));
10
10
  var _constants = require("../../constants");
11
11
  var _helpers = require("../sdoc-link/helpers");
12
12
  var _elementType = require("../../constants/element-type");
13
+ var _context = _interopRequireDefault(require("../../../../context"));
13
14
  const insertWikiPageLink = (editor, text, wikiRepoId, pageId, icon, isDir) => {
14
15
  if ((0, _helpers.isMenuDisabled)(editor)) return;
15
16
  // Selection folded or not
@@ -64,9 +65,7 @@ const generateWikiFileNode = function (wikiRepoId, pageId) {
64
65
  };
65
66
  exports.generateWikiFileNode = generateWikiFileNode;
66
67
  const getWikiUrl = (wikiRepoId, pageId) => {
67
- const {
68
- origin
69
- } = window.location;
70
- return `${origin}/wikis/${wikiRepoId}/?page_id=${pageId}`;
68
+ const siteRoot = _context.default.getSetting('siteRoot');
69
+ return `${siteRoot}wikis/${wikiRepoId}/${pageId}/`;
71
70
  };
72
71
  exports.getWikiUrl = getWikiUrl;
package/dist/context.js CHANGED
@@ -56,7 +56,7 @@ class Context {
56
56
  this.api = null;
57
57
  this.config = null;
58
58
  }
59
- initApi() {
59
+ initApi(customKeys) {
60
60
  this.initSettings(); // lazy init context class
61
61
  const server = this.getSetting('serviceUrl');
62
62
  const token = this.getSetting('accessToken');
@@ -65,6 +65,11 @@ class Context {
65
65
  if (isOpenSocket) {
66
66
  this.sdocServerApi = new _sdocServerApi.default(this.settings);
67
67
  }
68
+ if (customKeys) {
69
+ for (let key in customKeys) {
70
+ this.settings[key] = customKeys[key];
71
+ }
72
+ }
68
73
  }
69
74
  getSettings() {
70
75
  return this.settings;
@@ -263,6 +268,10 @@ class Context {
263
268
  const docUuid = this.getDocUuid();
264
269
  return this.api.aiTranslate(docUuid, text, lang);
265
270
  }
271
+ writingAssistant(text, type) {
272
+ const docUuid = this.getDocUuid();
273
+ return this.api.writingAssistant(docUuid, text, type);
274
+ }
266
275
  updateConfigUuid(docUuid) {
267
276
  if (!this.config) return;
268
277
  this.config['docUuid'] = docUuid;
@@ -23,7 +23,9 @@ const SdocWikiEditor = _ref => {
23
23
  isWikiReadOnly,
24
24
  scrollRef
25
25
  } = _ref;
26
- _context.default.initApi();
26
+ _context.default.initApi({
27
+ isWikiReadOnly
28
+ });
27
29
  const validEditor = (0, _react.useMemo)(() => {
28
30
  const defaultEditor = (0, _extension.createWikiEditor)();
29
31
  // getEditorConfig cashe the config, so we need to update the uuid,for wiki editor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.189",
3
+ "version": "1.0.190-alpha2",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -17,14 +17,14 @@
17
17
  "Ordered_list": "Seřazený seznam",
18
18
  "Unordered_list": "Neseřazený seznam",
19
19
  "Check_list": "Check list",
20
- "Insert_image": "Insert image",
20
+ "Insert_image": "Vložit obrázek",
21
21
  "Insert_formula": "Vložit vzorec",
22
22
  "Formula": "Vzorec",
23
- "Insert_file": "Insert file",
23
+ "Insert_file": "Vložit soubor",
24
24
  "Code": "Řádkový kód",
25
25
  "Code_block": "Code block",
26
- "Insert_link": "Insert link",
27
- "Insert_table": "Insert table",
26
+ "Insert_link": "Vložit odkaz",
27
+ "Insert_table": "Vložit tabulku",
28
28
  "Valid_values_for_rows_and_columns": "Valid values for the number of rows and columns are 0 to 50",
29
29
  "Save": "Uložit",
30
30
  "More": "Více",
@@ -39,9 +39,9 @@
39
39
  "Help": "Pomoc",
40
40
  "Column": "Sloupec",
41
41
  "Row": "Řádek",
42
- "Delete_table": "Delete table",
43
- "Delete_row": "Delete row",
44
- "Delete_column": "Delete column",
42
+ "Delete_table": "Smazat tabulku",
43
+ "Delete_row": "Smazat řádek",
44
+ "Delete_column": "Smazat sloupec",
45
45
  "Insert_row": "Vložit řádek",
46
46
  "Set_align": "Nastavit zarovnání",
47
47
  "Left": "Vlevo",
@@ -257,8 +257,8 @@
257
257
  "Columns": "Sloupce",
258
258
  "Please_enter_title": "Please enter title",
259
259
  "Please_enter_text": "Please enter text",
260
- "Row(s)": "row(s)",
261
- "Column(s)": "column(s)",
260
+ "Row(s)": "řádek(ů)",
261
+ "Column(s)": "sloupec(ů)",
262
262
  "Insert_below": "Insert below",
263
263
  "Insert_above": "Insert above",
264
264
  "Insert_on_the_right": "Insert on the right",
@@ -444,16 +444,16 @@
444
444
  "Recent_visited": "Recent visited",
445
445
  "The_document_does_not_exist": "The document does not exist",
446
446
  "Create_a_new_sdoc_file": "Create a new sdoc file",
447
- "New_page": "New page",
447
+ "New_page": "Nová stránka",
448
448
  "Create": "Vytvořit",
449
449
  "Top_align": "Top",
450
450
  "Center_align": "Middle",
451
451
  "Bottom_align": "Bottom",
452
452
  "Move_column_count": "Moving {{count}} column(s)",
453
453
  "Move_row_count": "Moving {{count}} row(s)",
454
- "Mark_all_as_read": "Mark all as read",
454
+ "Mark_all_as_read": "Označit vše jako přečtené",
455
455
  "Alignment_type": "Alignment",
456
- "Print": "Print",
456
+ "Print": "Vytisknout",
457
457
  "Enter_more_character_start_search": "Enter more characters to start search",
458
458
  "Create_file_name_sdoc": "Create {{file_name_sdoc}}",
459
459
  "Source_document_changed_tip": "Original document has concurrent modifications. Do you like to merge these modifications to the revision?",
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "KI fragen",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Chinese",
606
606
  "Ask_AI": "Ask AI",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Enter reply",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -604,5 +604,7 @@
604
604
  "English": "English",
605
605
  "Chinese": "Китайский",
606
606
  "Ask_AI": "Спросить ИИ",
607
- "Enter_reply": "Enter reply"
607
+ "Enter_reply": "Введите ответ",
608
+ "Processing_content_cannot_be_empty": "Processing content cannot be empty",
609
+ "AI_error_message": "Request error, please try again"
608
610
  }
@@ -595,7 +595,7 @@
595
595
  "Deprecation": "弃用",
596
596
  "Generated_content_x_words": "已生成内容 {{count}} 字",
597
597
  "Ask_AI_anything": "询问 AI 任何事情...",
598
- "Thinking": "思考...",
598
+ "Thinking": "思考中...",
599
599
  "Translation_error_message": "翻译出错,请重试",
600
600
  "The_translation_content_cannot_be_empty": "翻译内容不能为空",
601
601
  "Processing_message": "正在处理,请稍侯...",
@@ -604,5 +604,7 @@
604
604
  "English": "英语",
605
605
  "Chinese": "中文",
606
606
  "Ask_AI": "询问 AI",
607
- "Enter_reply": "输入回复"
607
+ "Enter_reply": "输入回复",
608
+ "Processing_content_cannot_be_empty": "处理内容不能为空",
609
+ "AI_error_message": "请求错误,请重试"
608
610
  }