@seafile/sdoc-editor 2.0.38-alph-0.0.1 → 2.0.38-alph-1.1.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';
@@ -25,6 +25,7 @@ var _highlight = require("../highlight");
25
25
  var _constants2 = require("../extension/constants");
26
26
  var _helpers = require("../extension/plugins/table/helpers");
27
27
  var _useForceUpdate = _interopRequireDefault(require("../../basic-sdk/hooks/use-force-update"));
28
+ var _helpers2 = require("../extension/plugins/ai/ai-module/helpers");
28
29
  const EditableArticle = _ref => {
29
30
  let {
30
31
  showComment = true,
@@ -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,
@@ -60,6 +61,7 @@ const SdocEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
60
61
  setSlateValue(document.elements);
61
62
  }, [document.elements]);
62
63
  (0, _react.useEffect)(() => {
64
+ console.log(22);
63
65
  validEditor.readonly = false;
64
66
  return () => {
65
67
  validEditor.selection = null;
@@ -116,8 +118,18 @@ const SdocEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
116
118
 
117
119
  // useMount: refresh document
118
120
  (0, _react.useEffect)(() => {
121
+ console.log(44343);
119
122
  const eventBus = _basicSdk.EventBus.getInstance();
120
123
  eventBus.subscribe(_constants2.EXTERNAL_EVENT.REFRESH_DOCUMENT, onRefreshDocument);
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
+ console.log(999);
130
+ (0, _helpers.removeMarks)(validEditor);
131
+ }
132
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
133
  }, [onRefreshDocument]);
122
134
 
123
135
  // The parent component can call the method of this component through ref
@@ -190,6 +202,7 @@ const SdocEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
190
202
  }))));
191
203
  }
192
204
  const isShowComment = typeof showComment === 'boolean' ? showComment : true;
205
+ console.log(2, validEditor, slateValue, onValueChange, isShowComment);
193
206
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_layout.EditorContainer, {
194
207
  editor: validEditor
195
208
  }, /*#__PURE__*/_react.default.createElement(_useColorContext.ColorProvider, null, isShowHeaderToolbar && /*#__PURE__*/_react.default.createElement(_extension.HeaderToolbar, {
@@ -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
@@ -0,0 +1,22 @@
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,6 +23,7 @@ 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
28
  function AIModule(_ref) {
28
29
  let {
@@ -45,8 +46,9 @@ function AIModule(_ref) {
45
46
  const [searchResult, setSearchResult] = (0, _react.useState)(null);
46
47
  const [currentLang, setCurrentLang] = (0, _react.useState)('en');
47
48
  const [isShowTipDialog, setIsShowTipDialog] = (0, _react.useState)(false);
48
- const [selectDom, setSelectDom] = (0, _react.useState)(null);
49
49
  const toggleAskAI = (0, _react.useCallback)(() => {
50
+ // Add marks for selection
51
+ _slate.Editor.addMark(editor, 'isSelectedInAI', true);
50
52
  scrollRef.current = document.querySelector('.sdoc-scroll-container');
51
53
  const {
52
54
  scrollTop,
@@ -59,7 +61,6 @@ function AIModule(_ref) {
59
61
  }
60
62
  const domSelection = window.getSelection();
61
63
  const domRange = domSelection.getRangeAt(0);
62
- setSelectDom(domRange);
63
64
  const rect = domRange.getBoundingClientRect();
64
65
  const needPaddingBottomHeight = scrollTop + rect.bottom + _constants.AI_MIN_HEIGHT - scrollHeight;
65
66
  if (needPaddingBottomHeight > 0) {
@@ -74,13 +75,17 @@ function AIModule(_ref) {
74
75
  });
75
76
  }
76
77
  setTimeout(() => {
77
- var _inputRef$current;
78
+ var _rect, _inputRef$current;
78
79
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
79
80
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
80
81
  const slateRect = slateDom.getBoundingClientRect();
81
- const newRect = domRange.getBoundingClientRect();
82
+ const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
83
+ let rect;
84
+ if (markedSpan.length) {
85
+ rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
86
+ }
82
87
  const el = aiRef.current;
83
- el.style.top = `${newRect.bottom + 8}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
84
89
  el.style.left = `${slateRect.left}px`;
85
90
  el.style.display = 'block';
86
91
  setIsShowAIPopover(true);
@@ -118,6 +123,7 @@ function AIModule(_ref) {
118
123
  }, 500);
119
124
  }, [editor, element]);
120
125
  const onCloseClick = (0, _react.useCallback)(() => {
126
+ (0, _helpers.removeMarks)(editor);
121
127
  const element = aiRef.current;
122
128
  element.style.display = 'none';
123
129
  const articleDom = document.querySelector('.sdoc-editor__article');
@@ -126,7 +132,7 @@ function AIModule(_ref) {
126
132
  setSearchResult('');
127
133
  setIsShowAIPopover(false);
128
134
  closeModule();
129
- }, [closeModule]);
135
+ }, [closeModule, editor]);
130
136
  const onDocumentClick = (0, _react.useCallback)(event => {
131
137
  // not in ai container
132
138
  if (aiRef.current && aiRef.current.contains(event.target) && aiRef.current !== event.target) return;
@@ -161,12 +167,17 @@ function AIModule(_ref) {
161
167
  }, [onDocumentClick]);
162
168
  const onScroll = (0, _react.useCallback)(event => {
163
169
  if (!element) {
164
- const newRect = selectDom.getBoundingClientRect();
170
+ var _rect2;
171
+ const markedSpan = document.querySelectorAll('span[data-slate-leaf="true"].isSelectedInAI');
172
+ let rect;
173
+ if (markedSpan.length) {
174
+ rect = markedSpan[markedSpan.length - 1].getBoundingClientRect();
175
+ }
165
176
  const aboveNode = (0, _core.getAboveBlockNode)(editor);
166
177
  const slateDom = _slateReact.ReactEditor.toDOMNode(editor, aboveNode[0]);
167
178
  const slateRect = slateDom.getBoundingClientRect();
168
179
  const el = aiRef.current;
169
- el.style.top = `${newRect.bottom + 8}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
170
181
  el.style.left = `${slateRect.left}px`;
171
182
  el.style.display = 'block';
172
183
  } else {
@@ -177,7 +188,7 @@ function AIModule(_ref) {
177
188
  el.style.left = `${slateRect.left}px`;
178
189
  el.style.display = 'block';
179
190
  }
180
- }, [editor, element, selectDom]);
191
+ }, [editor, element]);
181
192
  (0, _react.useEffect)(() => {
182
193
  let observerRefValue = null;
183
194
  if (isShowAIPopover) {
@@ -9,8 +9,7 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _caret = _interopRequireDefault(require("./caret"));
10
10
  var _constants = require("../../constants");
11
11
  var _helpers = require("../font/helpers");
12
- var _InlineBugFixWrapper = _interopRequireDefault(require("../../commons/Inline-bug-fix-wrapper"));
13
- const renderText = (props, editor) => {
12
+ const renderText = props => {
14
13
  const {
15
14
  attributes,
16
15
  children,
@@ -35,6 +34,12 @@ const renderText = (props, editor) => {
35
34
  style['display'] = 'inline-block';
36
35
  style['minWidth'] = '2px';
37
36
  }
37
+
38
+ // Add temporary marks for selection in AI
39
+ if (leaf.isSelectedInAI && leaf.text.trim()) {
40
+ style['padding'] = '3.23px 0';
41
+ style['background'] = '#a9c9ed';
42
+ }
38
43
  if (leaf.computed_background_color) {
39
44
  style['backgroundColor'] = leaf.computed_background_color;
40
45
  }
@@ -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) {
@@ -13,6 +13,8 @@ var _localStorageUtils = _interopRequireDefault(require("../../utils/local-stora
13
13
  var _fullWidthMode = require("../utils/full-width-mode");
14
14
  var _defaultMode = require("../utils/default-mode");
15
15
  var _constants = require("../constants");
16
+ var _slate = require("@seafile/slate");
17
+ var _helpers = require("../extension/plugins/ai/ai-module/helpers");
16
18
  function ArticleContainer(_ref) {
17
19
  let {
18
20
  editor,
@@ -25,6 +27,19 @@ function ArticleContainer(_ref) {
25
27
  editor.width = articleRef.current.children[0].clientWidth;
26
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
27
29
  }, []);
30
+
31
+ // useEffect(() => {
32
+ // const hasAIMark = !Editor.nodes(editor, {
33
+ // at: [],
34
+ // match: n => Text.isText(n) && n.isSelectedInAI === true,
35
+ // }).next().done;
36
+
37
+ // if (hasAIMark) {
38
+ // removeMarks(editor);
39
+ // }
40
+ // // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ // }, []);
42
+
28
43
  const handleWindowResize = (0, _react.useCallback)(function () {
29
44
  let {
30
45
  scrollIntoArticle = false,
@@ -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.1.0",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",