@seafile/sdoc-editor 1.0.182 → 1.0.184

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.
@@ -5,6 +5,7 @@
5
5
  }
6
6
 
7
7
  .sdoc-context-menu-divider {
8
+ margin-right: 8px;
8
9
  border-left: 1px solid #e5e5e5;
9
10
  width: 1px;
10
11
  height: 24px;
@@ -44,6 +44,7 @@ function AIModule(_ref) {
44
44
  const [searchResult, setSearchResult] = (0, _react.useState)(null);
45
45
  const [currentLang, setCurrentLang] = (0, _react.useState)('en');
46
46
  const [isShowTipDialog, setIsShowTipDialog] = (0, _react.useState)(false);
47
+ const [selectDom, setSelectDom] = (0, _react.useState)(null);
47
48
  const toggleAskAI = (0, _react.useCallback)(() => {
48
49
  scrollRef.current = document.querySelector('.sdoc-scroll-container');
49
50
  const {
@@ -57,6 +58,7 @@ function AIModule(_ref) {
57
58
  }
58
59
  const domSelection = window.getSelection();
59
60
  const domRange = domSelection.getRangeAt(0);
61
+ setSelectDom(domRange);
60
62
  const rect = domRange.getBoundingClientRect();
61
63
  const needPaddingBottomHeight = scrollTop + rect.bottom + _constants.AI_MIN_HEIGHT - scrollHeight;
62
64
  if (needPaddingBottomHeight > 0) {
@@ -66,7 +68,7 @@ function AIModule(_ref) {
66
68
  const heightDiff = rect.bottom + _constants.AI_MIN_HEIGHT - window.innerHeight;
67
69
  if (heightDiff > 0) {
68
70
  scrollRef.current.scrollTo({
69
- top: scrollRef.current.scrollTop + heightDiff + 100,
71
+ top: scrollRef.current.scrollTop + heightDiff + 32,
70
72
  behavior: 'smooth'
71
73
  });
72
74
  }
@@ -99,7 +101,7 @@ function AIModule(_ref) {
99
101
  const heightDiff = slateRect.bottom + _constants.AI_MIN_HEIGHT - window.innerHeight;
100
102
  if (heightDiff > 0) {
101
103
  scrollRef.current.scrollTo({
102
- top: scrollRef.current.scrollTop + heightDiff + 100,
104
+ top: scrollRef.current.scrollTop + heightDiff + 32,
103
105
  behavior: 'smooth'
104
106
  });
105
107
  }
@@ -156,33 +158,55 @@ function AIModule(_ref) {
156
158
  window.removeEventListener('click', onDocumentClick);
157
159
  };
158
160
  }, [onDocumentClick]);
161
+ const onScroll = (0, _react.useCallback)(event => {
162
+ if (!element) {
163
+ console.log(selectDom);
164
+ const newRect = selectDom.getBoundingClientRect();
165
+ const aboveNode = (0, _core.getAboveBlockNode)(editor);
166
+ const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
167
+ const slateRect = slateDom.getBoundingClientRect();
168
+ console.log(newRect);
169
+ console.log(slateRect);
170
+ const el = aiRef.current;
171
+ el.style.top = `${newRect.bottom + 8}px`; // top = Current top + Element height
172
+ el.style.left = `${slateRect.left}px`;
173
+ el.style.display = 'block';
174
+ } else {
175
+ const slateDom = _slateReact.ReactEditor.toDOMNode(editor, element);
176
+ const slateRect = slateDom.getBoundingClientRect();
177
+ const el = aiRef.current;
178
+ el.style.top = `${slateRect.bottom + 8}px`; // top = Current top + Element height
179
+ el.style.left = `${slateRect.left}px`;
180
+ el.style.display = 'block';
181
+ }
182
+ }, [editor, element, selectDom]);
159
183
  (0, _react.useEffect)(() => {
160
184
  let observerRefValue = null;
161
185
  if (isShowAIPopover) {
162
- scrollRef.current && scrollRef.current.addEventListener('scroll', onCloseClick);
186
+ scrollRef.current && scrollRef.current.addEventListener('scroll', onScroll);
163
187
  observerRefValue = scrollRef.current;
164
188
  } else {
165
- scrollRef.current && scrollRef.current.removeEventListener('scroll', onCloseClick);
189
+ scrollRef.current && scrollRef.current.removeEventListener('scroll', onScroll);
166
190
  }
167
191
  return () => {
168
192
  if (observerRefValue) {
169
- observerRefValue.removeEventListener('scroll', onCloseClick);
193
+ observerRefValue.removeEventListener('scroll', onScroll);
170
194
  }
171
195
  };
172
- }, [isShowAIPopover, onCloseClick]);
196
+ }, [isShowAIPopover, onScroll]);
173
197
  const onSearchValueChanged = (0, _react.useCallback)(event => {
174
198
  const value = event.target.value;
175
199
  if (value === searchValue) return;
176
200
  setSearchValue(value);
177
201
  }, [searchValue]);
178
- const onEnter = (0, _react.useCallback)(() => {
202
+ const onEnter = (0, _react.useCallback)(event => {
179
203
  if (!searchValue) return;
180
204
  setOpType(_constants.OPERATION_TYPES.DEFAULT);
181
205
  setIsGenerating(true);
182
206
  setTimeout(() => {
183
207
  setIsGenerating(false);
184
208
  setSearchResult('[Feature is under development...]Thank you, the world becomes more beautiful because of you!');
185
- });
209
+ }, 2000);
186
210
  }, [searchValue]);
187
211
  const onKeyDown = (0, _react.useCallback)(event => {
188
212
  if ((0, _isHotkey.default)('enter', event)) {
@@ -335,20 +359,14 @@ function AIModule(_ref) {
335
359
  const isShowReplace = (0, _react.useMemo)(() => {
336
360
  return opType !== _constants.OPERATION_TYPES.DEFAULT;
337
361
  }, [opType]);
338
- const resultMenu = (0, _react.useMemo)(() => {
339
- const type = opType && opType.toUpperCase();
340
- if (opType === _constants.OPERATION_TYPES.TRANSLATE) {
341
- return _constants.LANG_MENU_CONFIG[currentLang.toUpperCase()];
342
- }
343
- return _constants.OPERATION_MENUS_CONFIG[type];
344
- }, [currentLang, opType]);
345
362
  const closeTipDialog = (0, _react.useCallback)(() => {
346
363
  setIsShowTipDialog(false);
347
364
  }, []);
348
365
  const discardCurrentContent = (0, _react.useCallback)(() => {
349
366
  onCloseClick();
350
367
  setIsShowTipDialog(false);
351
- }, [onCloseClick]);
368
+ (0, _core.focusEditor)(editor);
369
+ }, [editor, onCloseClick]);
352
370
  return /*#__PURE__*/_react.default.createElement(_commons.ElementPopover, null, /*#__PURE__*/_react.default.createElement("div", {
353
371
  className: "sdoc-ai-module-container",
354
372
  ref: aiRef
@@ -402,18 +420,9 @@ function AIModule(_ref) {
402
420
  className: "sdoc-ai-content has-result"
403
421
  }, /*#__PURE__*/_react.default.createElement("div", {
404
422
  className: "sdoc-ai-result"
405
- }, resultMenu && /*#__PURE__*/_react.default.createElement("div", {
406
- className: "sdoc-ai-result-header"
407
- }, /*#__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", {
408
- className: "sdocfont sdoc-close",
409
- onClick: onDeprecationClick
410
- })), /*#__PURE__*/_react.default.createElement("div", {
423
+ }, /*#__PURE__*/_react.default.createElement("div", {
411
424
  className: "sdoc-ai-result-content"
412
- }, isGenerating ? t('Processing_message') : searchResult), /*#__PURE__*/_react.default.createElement("div", {
413
- className: "sdoc-ai-statistic"
414
- }, t('Generated_content_x_words', {
415
- count: searchResult.length
416
- }))), /*#__PURE__*/_react.default.createElement("div", {
425
+ }, isGenerating ? t('Processing_message') : searchResult)), /*#__PURE__*/_react.default.createElement("div", {
417
426
  className: "sdoc-ai-search"
418
427
  }, /*#__PURE__*/_react.default.createElement(_aiIcon.default, null), /*#__PURE__*/_react.default.createElement("input", {
419
428
  placeholder: t('Ask_AI_anything'),
@@ -421,7 +430,7 @@ function AIModule(_ref) {
421
430
  onKeyDown: onKeyDown,
422
431
  onChange: onSearchValueChanged
423
432
  }), /*#__PURE__*/_react.default.createElement("span", {
424
- className: "sdocfont sdoc-send-arrow",
433
+ className: `sdocfont sdoc-send-arrow ${!searchValue ? 'disable' : ''}`,
425
434
  onClick: onEnter
426
435
  }))), /*#__PURE__*/_react.default.createElement("div", {
427
436
  className: "sdoc-ai-operations sdoc-dropdown-menu"
@@ -1,6 +1,6 @@
1
1
  .sdoc-ai-module-container {
2
2
  position: absolute;
3
- z-index: 1000;
3
+ z-index: 101;
4
4
  width: 100%;
5
5
  max-width: 672px;
6
6
  display: none;
@@ -40,13 +40,17 @@
40
40
  position: absolute;
41
41
  right: 16px;
42
42
  color: #ff9800;
43
- cursor: pointer;
43
+
44
44
  }
45
45
 
46
46
  .sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow.disable {
47
47
  color: #BDBDBD;
48
48
  }
49
49
 
50
+ .sdoc-ai-content .sdoc-ai-search .sdoc-send-arrow:not(.disable) {
51
+ cursor: pointer;
52
+ }
53
+
50
54
  .sdoc-ai-content .sdoc-ai-result {
51
55
  position: relative;
52
56
  height: 50px;
@@ -56,9 +60,9 @@
56
60
  width: 200px;
57
61
  margin-top: 8px;
58
62
  padding: 8px 0;
59
- border: 1px solid #eee;
60
- border-radius: 10px;
61
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
63
+ border: 1px solid #e5e6e8;
64
+ border-radius: 2px;
65
+ box-shadow: 0 0 10px #ccc;
62
66
  background-color: #fff;
63
67
  }
64
68
 
@@ -83,6 +87,10 @@
83
87
  align-items: center;
84
88
  }
85
89
 
90
+ .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header span {
91
+ color: #666;
92
+ }
93
+
86
94
  .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-header .sdocfont {
87
95
  font-size: 14px;
88
96
  }
@@ -99,6 +107,15 @@
99
107
  color: #555;
100
108
  }
101
109
 
102
- .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-content {
103
- padding: 16px 0;
110
+ .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-statistic {
111
+ color: #666;
112
+ }
113
+
114
+ .ai-lang-sub-menu .popover,
115
+ .ai-adjust-sub-menu .popover {
116
+ padding: 8px 0;
117
+ border: 1px solid #e5e6e8;
118
+ border-radius: 2px;
119
+ box-shadow: 0 0 10px #ccc;
120
+ background-color: #fff;
104
121
  }
@@ -125,4 +125,4 @@ const LANG_MENU_CONFIG = exports.LANG_MENU_CONFIG = {
125
125
  iconClass: 'sdocfont sdoc-ai-translate'
126
126
  }
127
127
  };
128
- const AI_MIN_HEIGHT = exports.AI_MIN_HEIGHT = 474;
128
+ const AI_MIN_HEIGHT = exports.AI_MIN_HEIGHT = 358;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.182",
3
+ "version": "1.0.184",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
7
7
  "dependencies": {
8
8
  "@seafile/print-js": "1.6.6",
9
- "@seafile/react-image-lightbox": "3.0.4",
9
+ "@seafile/react-image-lightbox": "2.0.5",
10
10
  "@seafile/slate": "0.91.8",
11
11
  "@seafile/slate-history": "0.86.2",
12
12
  "@seafile/slate-hyperscript": "0.81.7",
@@ -16,7 +16,7 @@
16
16
  "copy-to-clipboard": "^3.3.3",
17
17
  "dayjs": "1.10.7",
18
18
  "deep-copy": "1.4.2",
19
- "dtable-ui-component": "^5.2.10",
19
+ "dtable-ui-component": "^5.1.9",
20
20
  "is-hotkey": "0.2.0",
21
21
  "is-url": "^1.2.4",
22
22
  "lodash.isequal": "4.5.0",