@seafile/sdoc-editor 2.0.38-alph-0.0.1 → 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.
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "PLUGIN_DISPLAY_TYPE", {
17
17
  return _plugin.PLUGIN_DISPLAY_TYPE;
18
18
  }
19
19
  });
20
- exports.Z_INDEX = exports.WIKI_OUTLINE = exports.WIKI_EDITOR_EDIT_AREA_WIDTH = exports.WIKI_EDITOR = exports.SDOC_STORAGE = exports.REVISION_DIFF_VALUE = exports.REVISION_DIFF_KEY = exports.REBASE_TYPES = exports.REBASE_TYPE = exports.REBASE_ORIGIN = exports.REBASE_MARK_KEY = exports.REBASE_MARKS = void 0;
20
+ exports.Z_INDEX = exports.WIKI_OUTLINE = exports.WIKI_EDITOR = exports.SDOC_STORAGE = exports.REVISION_DIFF_VALUE = exports.REVISION_DIFF_KEY = exports.REBASE_TYPES = exports.REBASE_TYPE = exports.REBASE_ORIGIN = exports.REBASE_MARK_KEY = exports.REBASE_MARKS = void 0;
21
21
  var Z_INDEX = _interopRequireWildcard(require("./z-index"));
22
22
  exports.Z_INDEX = Z_INDEX;
23
23
  var _plugin = require("./plugin");
@@ -55,7 +55,6 @@ const REVISION_DIFF_KEY = exports.REVISION_DIFF_KEY = 'diff';
55
55
  const REVISION_DIFF_VALUE = exports.REVISION_DIFF_VALUE = '1';
56
56
  const PAGE_EDIT_AREA_WIDTH = exports.PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
57
57
  const COMMENT_EDITOR_EDIT_AREA_WIDTH = exports.COMMENT_EDITOR_EDIT_AREA_WIDTH = 364;
58
- const WIKI_EDITOR_EDIT_AREA_WIDTH = exports.WIKI_EDITOR_EDIT_AREA_WIDTH = 714;
59
58
  const COMMENT_EDITOR = exports.COMMENT_EDITOR = 'comment_editor';
60
59
  const WIKI_EDITOR = exports.WIKI_EDITOR = 'wiki_editor';
61
60
  const DOCUMENT_PLUGIN_EDITOR = exports.DOCUMENT_PLUGIN_EDITOR = 'document_plugin_editor';
@@ -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);
@@ -47,7 +47,7 @@ const WikiEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
47
47
  cursors
48
48
  } = document;
49
49
  newEditor.cursors = cursors || {};
50
- newEditor.width = _constants.WIKI_EDITOR_EDIT_AREA_WIDTH; // default width
50
+ newEditor.width = _constants.PAGE_EDIT_AREA_WIDTH; // default width
51
51
  return newEditor;
52
52
 
53
53
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -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 {
@@ -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
  }
@@ -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) {
@@ -42,7 +42,7 @@ const SdocWikiEditor = _ref => {
42
42
  cursors
43
43
  } = document;
44
44
  newEditor.cursors = cursors || {};
45
- newEditor.width = _constants.WIKI_EDITOR_EDIT_AREA_WIDTH; // default width
45
+ newEditor.width = _constants.PAGE_EDIT_AREA_WIDTH; // default width
46
46
  newEditor.editorType = _constants.WIKI_EDITOR;
47
47
  return newEditor;
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "2.0.38-alph-0.0.1",
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",