@seafile/sdoc-editor 2.0.37 → 2.0.38-alph-1.0.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,9 +42,12 @@ 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);
45
46
  if (event.button === 0) {
47
+ // console.log(444)
46
48
  const isPreventReset = (0, _helpers.isPreventResetTableSelectedRange)(event);
47
49
  if (!isPreventReset) {
50
+ // console.log(5)
48
51
  editor.reSetTableSelectedRange();
49
52
  const eventBus = _eventBus.default.getInstance();
50
53
  eventBus.dispatch(_constants.INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
@@ -29,6 +29,7 @@ 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);
32
33
  onMouseDown(event, type);
33
34
 
34
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -24,6 +24,8 @@ var _core = require("../../../core");
24
24
  var _constants2 = require("../../../constants");
25
25
  var _aiIcon = _interopRequireDefault(require("../ai-icon"));
26
26
  require("./style.css");
27
+ // import { highlightSelection } from './helpers';
28
+
27
29
  function AIModule(_ref) {
28
30
  let {
29
31
  editor,
@@ -46,13 +48,20 @@ function AIModule(_ref) {
46
48
  const [currentLang, setCurrentLang] = (0, _react.useState)('en');
47
49
  const [isShowTipDialog, setIsShowTipDialog] = (0, _react.useState)(false);
48
50
  const [selectDom, setSelectDom] = (0, _react.useState)(null);
51
+ // const [highlightedSpan, setHighlightedSpan] = useState(null);
52
+ console.log(2, element);
49
53
  const toggleAskAI = (0, _react.useCallback)(() => {
54
+ // const selectionBeforeMark = editor.selection;
55
+ console.log(0);
56
+ _slate.Editor.addMark(editor, 'isSelectedInAI', true);
57
+ console.log(1, editor.selection);
50
58
  scrollRef.current = document.querySelector('.sdoc-scroll-container');
51
59
  const {
52
60
  scrollTop,
53
61
  scrollHeight
54
62
  } = scrollRef.current;
55
63
  if (!element) {
64
+ console.log(44444);
56
65
  const content = window.getSelection().toString();
57
66
  if (content) {
58
67
  setSelectedValue(content);
@@ -74,15 +83,25 @@ function AIModule(_ref) {
74
83
  });
75
84
  }
76
85
  setTimeout(() => {
77
- var _inputRef$current;
86
+ var _rect, _inputRef$current;
78
87
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
88
+ // console.log(1, aboveNode)
79
89
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
80
90
  const slateRect = slateDom.getBoundingClientRect();
81
- const newRect = domRange.getBoundingClientRect();
91
+ const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
92
+ console.log(3, markedSpan);
93
+ let rect;
94
+ if (markedSpan.length) {
95
+ rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
96
+ console.log(4, rect, markedSpan);
97
+ }
98
+ // const newRect = domRange.getBoundingClientRect();
82
99
  const el = aiRef.current;
83
- el.style.top = `${newRect.bottom + 8}px`; // top = Current top + Element height
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
84
102
  el.style.left = `${slateRect.left}px`;
85
103
  el.style.display = 'block';
104
+ console.log(2, slateDom, slateRect, el, el.style.top);
86
105
  setIsShowAIPopover(true);
87
106
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
88
107
  }, 500);
@@ -90,6 +109,7 @@ function AIModule(_ref) {
90
109
  }
91
110
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, element);
92
111
  const slateRect = slateDom.getBoundingClientRect();
112
+ console.log(555);
93
113
  const content = _slate.Node.string(element);
94
114
  if (content) {
95
115
  setSelectedValue(content);
@@ -120,13 +140,28 @@ function AIModule(_ref) {
120
140
  const onCloseClick = (0, _react.useCallback)(() => {
121
141
  const element = aiRef.current;
122
142
  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
+ }
123
158
  const articleDom = document.querySelector('.sdoc-editor__article');
124
159
  articleDom.style.removeProperty('padding-bottom');
125
160
  setSearchValue('');
126
161
  setSearchResult('');
127
162
  setIsShowAIPopover(false);
128
163
  closeModule();
129
- }, [closeModule]);
164
+ }, [closeModule, editor]);
130
165
  const onDocumentClick = (0, _react.useCallback)(event => {
131
166
  // not in ai container
132
167
  if (aiRef.current && aiRef.current.contains(event.target) && aiRef.current !== event.target) return;
@@ -161,12 +196,19 @@ function AIModule(_ref) {
161
196
  }, [onDocumentClick]);
162
197
  const onScroll = (0, _react.useCallback)(event => {
163
198
  if (!element) {
199
+ var _rect2;
200
+ const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
201
+ let rect;
202
+ if (markedSpan.length) {
203
+ rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
204
+ }
164
205
  const newRect = selectDom.getBoundingClientRect();
165
206
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
166
207
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
167
208
  const slateRect = slateDom.getBoundingClientRect();
168
209
  const el = aiRef.current;
169
- el.style.top = `${newRect.bottom + 8}px`; // top = Current top + Element height
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
170
212
  el.style.left = `${slateRect.left}px`;
171
213
  el.style.display = 'block';
172
214
  } else {
@@ -32,7 +32,7 @@ const LinkHover = _ref => {
32
32
  location.href = element.href;
33
33
  }
34
34
  }, [element.href]);
35
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
35
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement("div", {
36
36
  id: "link-op-menu",
37
37
  className: "link-op-menu",
38
38
  style: menuPosition
@@ -54,7 +54,7 @@ const SearchReplaceMenu = _ref => {
54
54
  const canvasList = [];
55
55
  for (let index = 0; index < generateCount; index++) {
56
56
  const top = index * 5000;
57
- canvasList.push( /*#__PURE__*/_react.default.createElement("canvas", {
57
+ canvasList.push(/*#__PURE__*/_react.default.createElement("canvas", {
58
58
  key: 'sdoc-find-search-' + index,
59
59
  id: `sdoc-find-search-${index}`,
60
60
  className: "sdoc-find-search-highlight-canvas",
@@ -79,7 +79,7 @@ const SearchReplaceMenu = _ref => {
79
79
  readonly: readonly,
80
80
  isOpen: isOpenPopover,
81
81
  closePopover: onMouseDown
82
- }), isOpenPopover && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
82
+ }), isOpenPopover && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement("div", {
83
83
  style: {
84
84
  height: articleContainerSize.clientHeight
85
85
  },
@@ -168,7 +168,7 @@ const SearchReplacePopover = _ref => {
168
168
  if ((0, _isHotkey.default)('enter', e)) handleNext();
169
169
  if ((0, _isHotkey.default)('enter+shift', e)) handleLast();
170
170
  };
171
- return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
171
+ return /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
172
172
  className: "sdoc-search-replace-popover-container",
173
173
  onMouseDown: handleStartMove,
174
174
  onMouseMove: handleMouseMove,
@@ -78,7 +78,7 @@ class RowCardHeader extends _react.default.Component {
78
78
  // Start from the second column without name
79
79
  for (let i = 1; i < renderedColumns.length; i++) {
80
80
  const renderedColumn = renderedColumns[i];
81
- cardHeaderCells.push( /*#__PURE__*/_react.default.createElement(_rowCardHeaderCell.default, {
81
+ cardHeaderCells.push(/*#__PURE__*/_react.default.createElement(_rowCardHeaderCell.default, {
82
82
  key: renderedColumn.key,
83
83
  column: renderedColumn,
84
84
  rowCardType: rowCardType,
@@ -70,7 +70,7 @@ class DtableSearchInput extends _react.Component {
70
70
  const {
71
71
  ClearIndicator
72
72
  } = components;
73
- if ( /*#__PURE__*/_react.default.isValidElement(ClearIndicator)) {
73
+ if (/*#__PURE__*/_react.default.isValidElement(ClearIndicator)) {
74
74
  return /*#__PURE__*/_react.default.cloneElement(ClearIndicator, {
75
75
  clearValue: this.clearSearch
76
76
  });
@@ -310,7 +310,7 @@ class FilterItem extends _react.default.Component {
310
310
  background: inOption.color,
311
311
  color: inOption.textColor || null
312
312
  };
313
- labelArray.push( /*#__PURE__*/_react.default.createElement("span", {
313
+ labelArray.push(/*#__PURE__*/_react.default.createElement("span", {
314
314
  className: className,
315
315
  style: optionStyle,
316
316
  key: 'option_' + item,
@@ -205,7 +205,7 @@ const TableSizePopover = _ref => {
205
205
  });
206
206
  children.push(child);
207
207
  }
208
- tableSize.push( /*#__PURE__*/_react.default.createElement("div", {
208
+ tableSize.push(/*#__PURE__*/_react.default.createElement("div", {
209
209
  key: `sdoc-table-size-row-${i}`,
210
210
  className: "sdoc-table-size-row d-flex"
211
211
  }, children));
@@ -61,6 +61,7 @@ const TextStyleMenuList = _ref => {
61
61
  });
62
62
  }, [editor]);
63
63
  const onMouseDown = (0, _react.useCallback)((event, type) => {
64
+ console.log(2, type);
64
65
  event.preventDefault();
65
66
  event.stopPropagation();
66
67
  if (isDisabled()) return;
@@ -76,12 +77,14 @@ const TextStyleMenuList = _ref => {
76
77
  if (active) {
77
78
  (0, _helpers2.removeMark)(editor, type);
78
79
  } else {
80
+ console.log(3, type);
79
81
  (0, _helpers2.addMark)(editor, type);
80
82
  }
81
83
  (0, _core.focusEditor)(editor);
82
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
83
85
  }, [editor]);
84
86
  const setColor = (0, _react.useCallback)((type, color) => {
87
+ // console.log(1, type, color);
85
88
  _slate.Editor.addMark(editor, type, color);
86
89
  (0, _core.focusEditor)(editor);
87
90
 
@@ -132,6 +135,7 @@ const TextStyleMenuList = _ref => {
132
135
  // eslint-disable-next-line react-hooks/exhaustive-deps
133
136
  }, [editor, lastUsedFontColor, lastUsedHighlightColor, readonly]);
134
137
  let list = getTextStyleList(_constants.TEXT_STYLE);
138
+ // console.log(3, list);
135
139
  const dropdownList = getTextStyleList(_constants.TEXT_STYLE_MORE);
136
140
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, list.map((itemProps, index) => {
137
141
  const Component = itemProps.isColor ? _commons.ColorMenu : _commons.MenuItem;
@@ -1,11 +1,12 @@
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;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
+ var _react = _interopRequireWildcard(require("react"));
9
10
  var _caret = _interopRequireDefault(require("./caret"));
10
11
  var _constants = require("../../constants");
11
12
  var _helpers = require("../font/helpers");
@@ -20,6 +21,24 @@ const renderText = (props, editor) => {
20
21
  text,
21
22
  ...rest
22
23
  } = 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
+
23
42
  let markedChildren = /*#__PURE__*/_react.default.cloneElement(children);
24
43
  let style = {};
25
44
  // The following is a workaround for a Chromium bug where,
@@ -35,6 +54,10 @@ const renderText = (props, editor) => {
35
54
  style['display'] = 'inline-block';
36
55
  style['minWidth'] = '2px';
37
56
  }
57
+ if (leaf.isSelectedInAI && leaf.text.trim()) {
58
+ style['padding'] = '3.23px 0';
59
+ style['background'] = '#a9c9ed';
60
+ }
38
61
  if (leaf.computed_background_color) {
39
62
  style['backgroundColor'] = leaf.computed_background_color;
40
63
  }
@@ -62,7 +62,7 @@ const ContextToolbar = () => {
62
62
  el.removeAttribute('style');
63
63
  }
64
64
  }, []);
65
- return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
65
+ return /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement("div", {
66
66
  ref: ref,
67
67
  className: "sdoc-context-toolbar",
68
68
  onMouseDown: onMouseDown,
@@ -63,20 +63,22 @@ const onSetNodeType = (editor, element, type) => {
63
63
  // Callout, List-item, Blockquote in multi_column
64
64
  if ([_constants.CALL_OUT].includes(currentNodeInColumn.type)) {
65
65
  (0, _helper.unwrapCallout)(editor);
66
+ return;
66
67
  }
67
68
  if ([_constants.ORDERED_LIST, _constants.UNORDERED_LIST].includes(currentNodeInColumn.type)) {
68
69
  (0, _transforms.toggleList)(editor, currentNodeInColumn.type);
69
70
  if ([..._constants.HEADERS].includes(type)) {
70
71
  (0, _helpers5.setHeaderType)(editor, type);
71
72
  }
73
+ return;
72
74
  }
73
75
  if ([_constants.BLOCKQUOTE].includes(currentNodeInColumn.type)) {
74
76
  if ([..._constants.HEADERS].includes(type)) {
75
77
  (0, _helpers5.setHeaderType)(editor, type);
76
78
  }
77
79
  (0, _helpers4.setBlockQuoteType)(editor, true);
80
+ return;
78
81
  }
79
- return;
80
82
  } else {
81
83
  // List-item, blockquote, callout is top node
82
84
  if ([_constants.ORDERED_LIST, _constants.UNORDERED_LIST].includes(topNodeType)) {
@@ -84,17 +86,19 @@ const onSetNodeType = (editor, element, type) => {
84
86
  if ([..._constants.HEADERS].includes(type)) {
85
87
  (0, _helpers5.setHeaderType)(editor, type);
86
88
  }
89
+ return;
87
90
  }
88
91
  if ([_constants.BLOCKQUOTE].includes(topNodeType)) {
89
92
  if ([..._constants.HEADERS].includes(type)) {
90
93
  (0, _helpers5.setHeaderType)(editor, type);
91
94
  }
92
95
  (0, _helpers4.setBlockQuoteType)(editor, true);
96
+ return;
93
97
  }
94
98
  if ([_constants.CALL_OUT].includes(topNodeType)) {
95
99
  (0, _helper.unwrapCallout)(editor);
100
+ return;
96
101
  }
97
- return;
98
102
  }
99
103
  }
100
104
  if (type === _constants.CHECK_LIST_ITEM) {
@@ -67,7 +67,7 @@ class Toaster {
67
67
  container.setAttribute('data-evergreen-toaster-container', '');
68
68
  document.body.appendChild(container);
69
69
  const root = (0, _client.createRoot)(container);
70
- root.render( /*#__PURE__*/_react.default.createElement(_toastManager.default, {
70
+ root.render(/*#__PURE__*/_react.default.createElement(_toastManager.default, {
71
71
  bindNotify: this._bindNotify,
72
72
  bindGetToasts: this._bindGetToasts,
73
73
  bindCloseAll: this._bindCloseAll
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.37",
3
+ "version": "2.0.38-alph-1.0.0",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "remark-parse": "11.0.0",
39
39
  "remark-rehype": "11.0.0",
40
40
  "remark-stringify": "11.0.0",
41
- "sea-chart": "^2.0.5",
41
+ "sea-chart": "2.0.7",
42
42
  "slugid": "3.2.0",
43
43
  "socket.io-client": "4.8.1",
44
44
  "type-of": "2.0.1",