@seafile/sdoc-editor 1.0.183 → 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.
@@ -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,13 +359,6 @@ 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
  }, []);
@@ -403,18 +420,9 @@ function AIModule(_ref) {
403
420
  className: "sdoc-ai-content has-result"
404
421
  }, /*#__PURE__*/_react.default.createElement("div", {
405
422
  className: "sdoc-ai-result"
406
- }, resultMenu && /*#__PURE__*/_react.default.createElement("div", {
407
- className: "sdoc-ai-result-header"
408
- }, /*#__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", {
409
- className: "sdocfont sdoc-close",
410
- onClick: onDeprecationClick
411
- })), /*#__PURE__*/_react.default.createElement("div", {
423
+ }, /*#__PURE__*/_react.default.createElement("div", {
412
424
  className: "sdoc-ai-result-content"
413
- }, isGenerating ? t('Processing_message') : searchResult), /*#__PURE__*/_react.default.createElement("div", {
414
- className: "sdoc-ai-statistic"
415
- }, t('Generated_content_x_words', {
416
- count: searchResult.length
417
- }))), /*#__PURE__*/_react.default.createElement("div", {
425
+ }, isGenerating ? t('Processing_message') : searchResult)), /*#__PURE__*/_react.default.createElement("div", {
418
426
  className: "sdoc-ai-search"
419
427
  }, /*#__PURE__*/_react.default.createElement(_aiIcon.default, null), /*#__PURE__*/_react.default.createElement("input", {
420
428
  placeholder: t('Ask_AI_anything'),
@@ -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
 
@@ -103,10 +107,6 @@
103
107
  color: #555;
104
108
  }
105
109
 
106
- .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-result-content {
107
- padding: 16px 0;
108
- }
109
-
110
110
  .sdoc-ai-module-container .sdoc-ai-result .sdoc-ai-statistic {
111
111
  color: #666;
112
112
  }
@@ -114,8 +114,8 @@
114
114
  .ai-lang-sub-menu .popover,
115
115
  .ai-adjust-sub-menu .popover {
116
116
  padding: 8px 0;
117
- border: 1px solid #eee;
118
- border-radius: 10px;
119
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
117
+ border: 1px solid #e5e6e8;
118
+ border-radius: 2px;
119
+ box-shadow: 0 0 10px #ccc;
120
120
  background-color: #fff;
121
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.183",
3
+ "version": "1.0.184",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",