@seafile/sdoc-editor 2.0.38-alph-1.0.0 → 2.0.38-alph-1.2.0

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.
@@ -42,12 +42,9 @@ const EditableArticle = _ref => {
42
42
  // eslint-disable-next-line react-hooks/exhaustive-deps
43
43
  const eventProxy = (0, _react.useMemo)(() => new _eventHandler.default(editor), []);
44
44
  const onMouseDown = (0, _react.useCallback)(event => {
45
- // console.log(44);
46
45
  if (event.button === 0) {
47
- // console.log(444)
48
46
  const isPreventReset = (0, _helpers.isPreventResetTableSelectedRange)(event);
49
47
  if (!isPreventReset) {
50
- // console.log(5)
51
48
  editor.reSetTableSelectedRange();
52
49
  const eventBus = _eventBus.default.getInstance();
53
50
  eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
@@ -26,6 +26,7 @@ var _basicSdk = require("../../basic-sdk");
26
26
  var _constants2 = require("../../constants");
27
27
  var _outlineModule = require("../../android/outline-module");
28
28
  var _jsBridge = _interopRequireDefault(require("../../android/js-bridge"));
29
+ var _helpers = require("../extension/plugins/ai/ai-module/helpers");
29
30
  const SdocEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
30
31
  let {
31
32
  editor: propsEditor,
@@ -118,6 +119,16 @@ const SdocEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
118
119
  (0, _react.useEffect)(() => {
119
120
  const eventBus = _basicSdk.EventBus.getInstance();
120
121
  eventBus.subscribe(_constants2.EXTERNAL_EVENT.REFRESH_DOCUMENT, onRefreshDocument);
122
+
123
+ // Remove aiMarks on special conditions like unexpected exit or refresh page using AI
124
+ const hasAIMark = !_slate.Editor.nodes(validEditor, {
125
+ at: [],
126
+ match: n => _slate.Text.isText(n) && n.isSelectedInAI === true
127
+ }).next().done;
128
+ if (hasAIMark) {
129
+ (0, _helpers.removeMarks)(validEditor);
130
+ }
131
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
132
  }, [onRefreshDocument]);
122
133
 
123
134
  // The parent component can call the method of this component through ref
@@ -29,7 +29,6 @@ const MenuItem = _ref => {
29
29
  } = (0, _reactI18next.useTranslation)('sdoc-editor');
30
30
  const onClick = (0, _react.useCallback)(event => {
31
31
  if (disabled) return;
32
- console.log(3, type);
33
32
  onMouseDown(event, type);
34
33
 
35
34
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1 +1,22 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeMarks = void 0;
7
+ var _slate = require("@seafile/slate");
8
+ const removeMarks = editor => {
9
+ const {
10
+ selection
11
+ } = editor;
12
+ _slate.Transforms.unsetNodes(editor, 'isSelectedInAI', {
13
+ at: [],
14
+ match: n => _slate.Text.isText(n) && n.isSelectedInAI === true
15
+ });
16
+ if (selection) {
17
+ _slate.Transforms.select(editor, selection);
18
+ } else {
19
+ _slate.Transforms.deselect(editor);
20
+ }
21
+ };
22
+ exports.removeMarks = removeMarks;
@@ -23,9 +23,8 @@ var _tipDialog = _interopRequireDefault(require("./tip-dialog"));
23
23
  var _core = require("../../../core");
24
24
  var _constants2 = require("../../../constants");
25
25
  var _aiIcon = _interopRequireDefault(require("../ai-icon"));
26
+ var _helpers = require("./helpers");
26
27
  require("./style.css");
27
- // import { highlightSelection } from './helpers';
28
-
29
28
  function AIModule(_ref) {
30
29
  let {
31
30
  editor,
@@ -47,28 +46,21 @@ function AIModule(_ref) {
47
46
  const [searchResult, setSearchResult] = (0, _react.useState)(null);
48
47
  const [currentLang, setCurrentLang] = (0, _react.useState)('en');
49
48
  const [isShowTipDialog, setIsShowTipDialog] = (0, _react.useState)(false);
50
- const [selectDom, setSelectDom] = (0, _react.useState)(null);
51
- // const [highlightedSpan, setHighlightedSpan] = useState(null);
52
- console.log(2, element);
53
49
  const toggleAskAI = (0, _react.useCallback)(() => {
54
- // const selectionBeforeMark = editor.selection;
55
- console.log(0);
50
+ // Add marks for selection
56
51
  _slate.Editor.addMark(editor, 'isSelectedInAI', true);
57
- console.log(1, editor.selection);
58
52
  scrollRef.current = document.querySelector('.sdoc-scroll-container');
59
53
  const {
60
54
  scrollTop,
61
55
  scrollHeight
62
56
  } = scrollRef.current;
63
57
  if (!element) {
64
- console.log(44444);
65
58
  const content = window.getSelection().toString();
66
59
  if (content) {
67
60
  setSelectedValue(content);
68
61
  }
69
62
  const domSelection = window.getSelection();
70
63
  const domRange = domSelection.getRangeAt(0);
71
- setSelectDom(domRange);
72
64
  const rect = domRange.getBoundingClientRect();
73
65
  const needPaddingBottomHeight = scrollTop + rect.bottom + _constants.AI_MIN_HEIGHT - scrollHeight;
74
66
  if (needPaddingBottomHeight > 0) {
@@ -85,23 +77,17 @@ function AIModule(_ref) {
85
77
  setTimeout(() => {
86
78
  var _rect, _inputRef$current;
87
79
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
88
- // console.log(1, aboveNode)
89
80
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
90
81
  const slateRect = slateDom.getBoundingClientRect();
91
82
  const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
92
- console.log(3, markedSpan);
93
83
  let rect;
94
84
  if (markedSpan.length) {
95
85
  rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
96
- console.log(4, rect, markedSpan);
97
86
  }
98
- // const newRect = domRange.getBoundingClientRect();
99
87
  const el = aiRef.current;
100
- // el.style.top = `${newRect.bottom + 8}px`;
101
- el.style.top = `${((_rect = rect) === null || _rect === void 0 ? void 0 : _rect.bottom) + 8 - 3}px`; // top = Current top + Element height
88
+ el.style.top = `${((_rect = rect) === null || _rect === void 0 ? void 0 : _rect.bottom) + 8 - 3.23}px`; // top = Current top + Element height - Element padding bottom
102
89
  el.style.left = `${slateRect.left}px`;
103
90
  el.style.display = 'block';
104
- console.log(2, slateDom, slateRect, el, el.style.top);
105
91
  setIsShowAIPopover(true);
106
92
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
107
93
  }, 500);
@@ -109,7 +95,6 @@ function AIModule(_ref) {
109
95
  }
110
96
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, element);
111
97
  const slateRect = slateDom.getBoundingClientRect();
112
- console.log(555);
113
98
  const content = _slate.Node.string(element);
114
99
  if (content) {
115
100
  setSelectedValue(content);
@@ -138,23 +123,9 @@ function AIModule(_ref) {
138
123
  }, 500);
139
124
  }, [editor, element]);
140
125
  const onCloseClick = (0, _react.useCallback)(() => {
126
+ (0, _helpers.removeMarks)(editor);
141
127
  const element = aiRef.current;
142
128
  element.style.display = 'none';
143
- console.log(2, element);
144
- const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
145
- if (markedSpan.length) {
146
- console.log(1, markedSpan);
147
- markedSpan.forEach(dom => {
148
- dom.style.removeProperty('padding');
149
- dom.style.removeProperty('background');
150
- dom.classList.remove('isSelectedInAI');
151
- });
152
- console.log('Before remove:', _slate.Editor.marks(editor));
153
- _slate.Editor.removeMark(editor, 'isSelectedInAI');
154
- console.log('after remove:', _slate.Editor.marks(editor));
155
- // ReactEditor.focus(editor);
156
- console.log(99);
157
- }
158
129
  const articleDom = document.querySelector('.sdoc-editor__article');
159
130
  articleDom.style.removeProperty('padding-bottom');
160
131
  setSearchValue('');
@@ -202,13 +173,11 @@ function AIModule(_ref) {
202
173
  if (markedSpan.length) {
203
174
  rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
204
175
  }
205
- const newRect = selectDom.getBoundingClientRect();
206
176
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
207
177
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
208
178
  const slateRect = slateDom.getBoundingClientRect();
209
179
  const el = aiRef.current;
210
- el.style.top = `${((_rect2 = rect) === null || _rect2 === void 0 ? void 0 : _rect2.bottom) + 8 - 3}px`;
211
- // el.style.top = `${newRect.bottom + 8 - 3}px`; // top = Current top + Element height
180
+ el.style.top = `${((_rect2 = rect) === null || _rect2 === void 0 ? void 0 : _rect2.bottom) + 8 - 3.23}px`; // top = Current top + Element height - Element padding bottom
212
181
  el.style.left = `${slateRect.left}px`;
213
182
  el.style.display = 'block';
214
183
  } else {
@@ -219,7 +188,7 @@ function AIModule(_ref) {
219
188
  el.style.left = `${slateRect.left}px`;
220
189
  el.style.display = 'block';
221
190
  }
222
- }, [editor, element, selectDom]);
191
+ }, [editor, element]);
223
192
  (0, _react.useEffect)(() => {
224
193
  let observerRefValue = null;
225
194
  if (isShowAIPopover) {
@@ -61,7 +61,6 @@ const TextStyleMenuList = _ref => {
61
61
  });
62
62
  }, [editor]);
63
63
  const onMouseDown = (0, _react.useCallback)((event, type) => {
64
- console.log(2, type);
65
64
  event.preventDefault();
66
65
  event.stopPropagation();
67
66
  if (isDisabled()) return;
@@ -77,14 +76,12 @@ const TextStyleMenuList = _ref => {
77
76
  if (active) {
78
77
  (0, _helpers2.removeMark)(editor, type);
79
78
  } else {
80
- console.log(3, type);
81
79
  (0, _helpers2.addMark)(editor, type);
82
80
  }
83
81
  (0, _core.focusEditor)(editor);
84
82
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
83
  }, [editor]);
86
84
  const setColor = (0, _react.useCallback)((type, color) => {
87
- // console.log(1, type, color);
88
85
  _slate.Editor.addMark(editor, type, color);
89
86
  (0, _core.focusEditor)(editor);
90
87
 
@@ -135,7 +132,6 @@ const TextStyleMenuList = _ref => {
135
132
  // eslint-disable-next-line react-hooks/exhaustive-deps
136
133
  }, [editor, lastUsedFontColor, lastUsedHighlightColor, readonly]);
137
134
  let list = getTextStyleList(_constants.TEXT_STYLE);
138
- // console.log(3, list);
139
135
  const dropdownList = getTextStyleList(_constants.TEXT_STYLE_MORE);
140
136
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, list.map((itemProps, index) => {
141
137
  const Component = itemProps.isColor ? _commons.ColorMenu : _commons.MenuItem;
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
10
9
  var _caret = _interopRequireDefault(require("./caret"));
11
10
  var _constants = require("../../constants");
12
11
  var _helpers = require("../font/helpers");
13
- var _InlineBugFixWrapper = _interopRequireDefault(require("../../commons/Inline-bug-fix-wrapper"));
14
- const renderText = (props, editor) => {
12
+ const renderText = props => {
15
13
  const {
16
14
  attributes,
17
15
  children,
@@ -21,24 +19,6 @@ const renderText = (props, editor) => {
21
19
  text,
22
20
  ...rest
23
21
  } = leaf;
24
- console.log(1, leaf);
25
-
26
- // eslint-disable-next-line react-hooks/rules-of-hooks
27
- // useEffect(() => {
28
- // if (leaf.isSelectedInAI) {
29
- // console.log('origin');
30
- // const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
31
- // if (markedSpan.length) {
32
- // console.log(1, markedSpan);
33
- // markedSpan.forEach((dom) => {
34
- // dom.style.removeProperty('padding');
35
- // dom.style.removeProperty('background');
36
- // dom.classList.remove('isSelectedInAI');
37
- // });
38
- // }
39
- // }
40
- // }, []);
41
-
42
22
  let markedChildren = /*#__PURE__*/_react.default.cloneElement(children);
43
23
  let style = {};
44
24
  // The following is a workaround for a Chromium bug where,
@@ -54,6 +34,8 @@ const renderText = (props, editor) => {
54
34
  style['display'] = 'inline-block';
55
35
  style['minWidth'] = '2px';
56
36
  }
37
+
38
+ // Add temporary marks for selection in AI
57
39
  if (leaf.isSelectedInAI && leaf.text.trim()) {
58
40
  style['padding'] = '3.23px 0';
59
41
  style['background'] = '#a9c9ed';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.38-alph-1.0.0",
3
+ "version": "2.0.38-alph-1.2.0",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",