@seafile/seafile-editor 1.0.85-beta9 → 1.0.86-beta

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.
@@ -19,25 +19,26 @@ require("./index.css");
19
19
  const isMacOS = (0, _common.isMac)();
20
20
  const InlineEditor = _ref => {
21
21
  let {
22
- isFocus,
22
+ isShowEditor,
23
+ focusNodePath,
23
24
  value,
24
25
  editorApi,
25
26
  onSave,
26
27
  columns,
27
28
  onContentChanged,
28
29
  isSupportFormula,
29
- onExpandEditorToggle
30
+ onExpandEditorToggle,
31
+ updateFocus
30
32
  } = _ref;
31
33
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
32
34
  const editor = (0, _react.useMemo)(() => {
33
35
  const baseEditor = (0, _extension.inlineEditor)();
34
- if (isFocus) return (0, _withPropsEditor.default)(baseEditor, {
36
+ return (0, _withPropsEditor.default)(baseEditor, {
35
37
  editorApi,
36
38
  onSave,
37
39
  columns
38
40
  });
39
- return baseEditor;
40
- }, [columns, editorApi, onSave, isFocus]);
41
+ }, [columns, editorApi, onSave]);
41
42
  const eventProxy = (0, _react.useMemo)(() => {
42
43
  return new _eventHandler.default(editor);
43
44
  }, [editor]);
@@ -53,9 +54,25 @@ const InlineEditor = _ref => {
53
54
  const eventBus = _eventBus.default.getInstance();
54
55
  eventBus.dispatch('change');
55
56
  }, [editor, onContentChanged]);
56
- const focusFirstNode = (0, _react.useCallback)(editor => {
57
+ const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
57
58
  const [firstNode] = editor.children;
58
59
  if (!firstNode) return;
60
+ if (focusNodePath && Array.isArray(focusNodePath)) {
61
+ const customFocusNodePath = (0, _core.getNode)(editor, focusNodePath);
62
+ if (customFocusNodePath) {
63
+ const startOfFirstNode = _slate.Editor.start(editor, focusNodePath);
64
+ const range = {
65
+ anchor: startOfFirstNode,
66
+ focus: startOfFirstNode
67
+ };
68
+ (0, _core.focusEditor)(editor, range);
69
+ return;
70
+ }
71
+ }
72
+ if (focusNodePath && typeof focusNodePath === 'object' && focusNodePath.anchor) {
73
+ (0, _core.focusEditor)(editor, focusNodePath);
74
+ return;
75
+ }
59
76
  const [firstNodeFirstChild] = firstNode.children;
60
77
  if (firstNodeFirstChild) {
61
78
  const startOfFirstNode = _slate.Editor.start(editor, [0, 0]);
@@ -67,22 +84,6 @@ const InlineEditor = _ref => {
67
84
  }
68
85
  }, []);
69
86
 
70
- // const focusEndNode = useCallback((editor) => {
71
- // const lastChildIndex = editor.children.length - 1;
72
- // if (lastChildIndex < 0) return;
73
- // const lastNode = editor.children[lastChildIndex];
74
- // if (!lastNode) return;
75
- // const [lastNodeFirstChild] = lastNode.children;
76
- // if (lastNodeFirstChild) {
77
- // const endOfFirstNode = Editor.end(editor, [lastChildIndex, 0]);
78
- // const range = {
79
- // anchor: endOfFirstNode,
80
- // focus: endOfFirstNode,
81
- // };
82
- // focusEditor(editor, range);
83
- // }
84
- // }, []);
85
-
86
87
  // useMount: focus editor
87
88
  (0, _react.useEffect)(() => {
88
89
  editor.forceNormalize = true;
@@ -91,7 +92,9 @@ const InlineEditor = _ref => {
91
92
  });
92
93
  const timer = setTimeout(() => {
93
94
  editor.forceNormalize = false;
94
- focusFirstNode(editor);
95
+ if (isShowEditor) {
96
+ focusNode(editor, focusNodePath);
97
+ }
95
98
  }, 300);
96
99
  return () => {
97
100
  editor.forceNormalize = false;
@@ -99,6 +102,14 @@ const InlineEditor = _ref => {
99
102
  };
100
103
  // eslint-disable-next-line react-hooks/exhaustive-deps
101
104
  }, []);
105
+ (0, _react.useEffect)(() => {
106
+ if (focusNodePath) {
107
+ console.log(focusNodePath);
108
+ focusNode(editor, focusNodePath);
109
+ }
110
+
111
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
+ }, [focusNodePath]);
102
113
 
103
114
  // willUnmount
104
115
  (0, _react.useEffect)(() => {
@@ -114,12 +125,15 @@ const InlineEditor = _ref => {
114
125
  const onEditorClick = (0, _react.useCallback)(() => {
115
126
  const value = editor.children;
116
127
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
117
- focusFirstNode(editor);
128
+ focusNode(editor);
129
+ }
130
+ if (!isShowEditor) {
131
+ updateFocus(editor.selection);
118
132
  }
119
- }, [editor, focusFirstNode]);
133
+ }, [isShowEditor, editor, focusNode, updateFocus]);
120
134
  return /*#__PURE__*/_react.default.createElement("div", {
121
135
  className: "sf-simple-slate-editor-container"
122
- }, isFocus && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
136
+ }, isShowEditor && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
123
137
  editor: editor,
124
138
  isSupportFormula: isSupportFormula,
125
139
  isSupportColumn: !!columns,
@@ -24,7 +24,8 @@ const SimpleSlateEditor = _ref => {
24
24
  onSave,
25
25
  columns,
26
26
  onContentChanged,
27
- isSupportFormula
27
+ isSupportFormula,
28
+ onExpandEditorToggle
28
29
  } = _ref;
29
30
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
30
31
  const editor = (0, _react.useMemo)(() => (0, _withPropsEditor.default)(_extension.baseEditor, {
@@ -47,7 +48,7 @@ const SimpleSlateEditor = _ref => {
47
48
  const eventBus = _eventBus.default.getInstance();
48
49
  eventBus.dispatch('change');
49
50
  }, [editor, onContentChanged]);
50
- const focusFirstNode = (0, _react.useCallback)(editor => {
51
+ const focusNode = (0, _react.useCallback)(editor => {
51
52
  const [firstNode] = editor.children;
52
53
  if (!firstNode) return;
53
54
  const [firstNodeFirstChild] = firstNode.children;
@@ -85,7 +86,7 @@ const SimpleSlateEditor = _ref => {
85
86
  });
86
87
  const timer = setTimeout(() => {
87
88
  editor.forceNormalize = false;
88
- focusFirstNode(editor);
89
+ focusNode(editor);
89
90
  }, 300);
90
91
  return () => {
91
92
  editor.forceNormalize = false;
@@ -108,9 +109,9 @@ const SimpleSlateEditor = _ref => {
108
109
  const onEditorClick = (0, _react.useCallback)(() => {
109
110
  const value = editor.children;
110
111
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
111
- focusFirstNode(editor);
112
+ focusNode(editor);
112
113
  }
113
- }, [editor, focusFirstNode]);
114
+ }, [editor, focusNode]);
114
115
  return /*#__PURE__*/_react.default.createElement("div", {
115
116
  className: "sf-simple-slate-editor-container"
116
117
  }, /*#__PURE__*/_react.default.createElement(_extension.Toolbar, {
@@ -28,6 +28,9 @@ const renderLink = (_ref, editor) => {
28
28
  left: 0
29
29
  });
30
30
  const isReadonly = (0, _slateReact.useReadOnly)();
31
+
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ const isLinkActive = (0, _react.useMemo)(() => (0, _helper.isLinkType)(editor), [editor.selection]);
31
34
  const onClosePopover = (0, _react.useCallback)(e => {
32
35
  unregisterClickEvent();
33
36
  setIsShowPopover(false);
@@ -77,7 +80,7 @@ const renderLink = (_ref, editor) => {
77
80
  }, attributes), /*#__PURE__*/_react.default.createElement("a", {
78
81
  href: element.url,
79
82
  onClick: onHrefClick
80
- }, children)), isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
83
+ }, children)), isLinkActive && isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
81
84
  popoverPosition: popoverPosition,
82
85
  linkUrl: element.url,
83
86
  editor: editor,
@@ -14,7 +14,6 @@ var _helper = require("../helper");
14
14
  var _common = require("../../../../utils/common");
15
15
  var _eventTypes = require("../../../../constants/event-types");
16
16
  var _constants = require("../../../../constants");
17
- require("./style.css");
18
17
  const LinkPopover = _ref => {
19
18
  let {
20
19
  linkUrl,
@@ -59,4 +59,4 @@
59
59
 
60
60
  .sf-link-op-icon:hover {
61
61
  background: #f2f2f2;
62
- }
62
+ }
@@ -286,7 +286,20 @@ const withTable = editor => {
286
286
  // selected only one cell
287
287
  const tableCell = (0, _core.getSelectedNodeByType)(newEditor, _elementTypes.TABLE_CELL);
288
288
  if (tableCell) {
289
- (0, _setEventTransfer.default)(event, 'fragment', tableCell.children);
289
+ const selection = window.getSelection();
290
+ const range = selection.getRangeAt(0);
291
+ const selectedContent = range.cloneContents();
292
+ const div = document.createElement('div');
293
+ // Unwrap image wrapper
294
+ selectedContent.childNodes.forEach(node => {
295
+ if (node.classList && node.classList.contains('sf-image-wrapper')) {
296
+ const img = node.querySelector('img');
297
+ div.appendChild(img.cloneNode(true));
298
+ return;
299
+ }
300
+ div.appendChild(node.cloneNode(true));
301
+ });
302
+ (0, _setEventTransfer.default)(event, 'html', div.innerHTML.toString());
290
303
  return true;
291
304
  }
292
305
  return false;
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _isHotkey = _interopRequireDefault(require("is-hotkey"));
11
- var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
12
11
  const FallbackEditor = _ref => {
13
12
  let {
14
13
  isShowEditor,
@@ -56,18 +55,6 @@ const FallbackEditor = _ref => {
56
55
  const onCut = (0, _react.useCallback)(e => {
57
56
  e.stopPropagation();
58
57
  }, []);
59
- if (!isShowEditor) {
60
- return /*#__PURE__*/_react.default.createElement("div", {
61
- className: "sf-long-text-inline-fallback-editor-container"
62
- }, /*#__PURE__*/_react.default.createElement("div", {
63
- className: "sf-simple-slate-editor-container"
64
- }, /*#__PURE__*/_react.default.createElement("div", {
65
- className: "sf-slate-editor-content"
66
- }, /*#__PURE__*/_react.default.createElement(_markdownPreview.default, {
67
- value: value,
68
- isShowOutline: false
69
- }))));
70
- }
71
58
  return /*#__PURE__*/_react.default.createElement("textarea", {
72
59
  className: "form-control sf-long-text-inline-fallback-editor-container",
73
60
  ref: inputRef,
@@ -0,0 +1,68 @@
1
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container {
2
+ width: 100%;
3
+ height: 100%;
4
+ overflow: hidden;
5
+ border-radius: 3px;
6
+ cursor: pointer;
7
+ padding: 16px 12px;
8
+ background-color: #FFF;
9
+ }
10
+
11
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-scroll-container {
12
+ overflow-y: auto;
13
+ height: fit-content;
14
+ padding: 0;
15
+ background: #fff;
16
+ }
17
+
18
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-article-container {
19
+ height: 100%;
20
+ width: 100%;
21
+ margin: 0;
22
+ }
23
+
24
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container .sf-slate-viewer-article-container .article {
25
+ padding: 0;
26
+ height: auto;
27
+ min-height: 100% !important;
28
+ border: 0;
29
+ color: #212529;
30
+ }
31
+
32
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ol,
33
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ul {
34
+ padding-inline-start: 40px;
35
+ margin-bottom: 1em;
36
+ }
37
+
38
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ol li a,
39
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ul li a {
40
+ word-break: break-all;
41
+ }
42
+
43
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ul.contains-task-list,
44
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ol.contains-task-list {
45
+ padding-inline-start: 20px;
46
+ }
47
+
48
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ul li.task-list-item,
49
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container ol li.task-list-item {
50
+ min-height: 20px;
51
+ }
52
+
53
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container li.task-list-item input[type=checkbox] {
54
+ position: absolute;
55
+ left: -1.4em;
56
+ top: .4em;
57
+ display: inline-block;
58
+ }
59
+
60
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container thead tr {
61
+ min-height: 42px;
62
+ }
63
+
64
+ .sf-long-text-inline-editor-container.preview .longtext-preview-container tbody tr {
65
+ font-weight: normal;
66
+ min-height: 42px;
67
+ }
68
+
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _loading = _interopRequireDefault(require("../../../containers/loading"));
11
+ var _slateConvert = require("../../../slate-convert");
12
+ var _slateViewer = _interopRequireDefault(require("../../../editors/slate-viewer"));
13
+ require("./index.css");
14
+ // Windows old Wechat (3.0 or earlier) inner core is chrome 53 and don't support ECMA6, can't use seafile-editor markdownViewer
15
+ // Windows new Wechat (lastest version 3.3.5) support seafile-editor markdownViewer
16
+ // so use dangerouslySetInnerHTML to preview
17
+ class Formatter extends _react.default.PureComponent {
18
+ constructor(props) {
19
+ super(props);
20
+ (0, _defineProperty2.default)(this, "convertMarkdown", mdFile => {
21
+ _slateConvert.processor.process(mdFile).then(result => {
22
+ let innerHtml = String(result).replace(/<a /ig, '<a target="_blank" tabindex="-1"');
23
+ this.setState({
24
+ innerHtml
25
+ });
26
+ });
27
+ });
28
+ this.state = {
29
+ innerHtml: null
30
+ };
31
+ }
32
+ componentDidMount() {
33
+ const {
34
+ isWindowsWechat,
35
+ value
36
+ } = this.props;
37
+ if (isWindowsWechat) {
38
+ this.convertMarkdown(value);
39
+ }
40
+ }
41
+ render() {
42
+ const {
43
+ isWindowsWechat,
44
+ value,
45
+ isShowOutline
46
+ } = this.props;
47
+ const {
48
+ innerHtml
49
+ } = this.state;
50
+ if (isWindowsWechat && innerHtml === null) {
51
+ return /*#__PURE__*/_react.default.createElement(_loading.default, null);
52
+ }
53
+ return /*#__PURE__*/_react.default.createElement("div", {
54
+ className: "longtext-preview-container"
55
+ }, isWindowsWechat && /*#__PURE__*/_react.default.createElement("div", {
56
+ className: "article",
57
+ dangerouslySetInnerHTML: {
58
+ __html: this.state.innerHtml
59
+ }
60
+ }), !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_slateViewer.default, {
61
+ value: value,
62
+ isShowOutline: isShowOutline
63
+ }));
64
+ }
65
+ }
66
+ var _default = exports.default = Formatter;
@@ -1,6 +1,7 @@
1
1
  .sf-long-text-inline-editor-container {
2
2
  width: 100%;
3
3
  height: 100%;
4
+ min-height: 38px;
4
5
  border: 1px solid rgba(0, 40, 100, .12);
5
6
  border-radius: 3px;
6
7
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
@@ -37,16 +38,6 @@
37
38
  padding: 16px !important;
38
39
  }
39
40
 
40
- /* preview */
41
- .sf-long-text-inline-editor-container .longtext-preview-container {
42
- padding: 10px;
43
- background-color: #fff;
44
- }
45
-
46
- .sf-long-text-inline-editor-container .sf-slate-editor-content .article > div[role="textbox"] > :first-child {
47
- margin-top: 0 !important;
48
- }
49
-
50
41
  .sf-long-text-inline-editor-container .sf-slate-editor-toolbar .sf-menu-group,
51
42
  .sf-editor-menu-popover .popover-inner .sf-menu-group {
52
43
  padding: 4px 0 4px 8px !important;
@@ -70,8 +61,6 @@
70
61
  display: flex;
71
62
  }
72
63
 
73
- /* weixin editor */
74
- .sf-long-text-inline-fallback-editor-container {
75
- width: 100%;
76
- resize: none;
64
+ .sf-long-text-inline-editor-container:not(.preview) .article>div[role=textbox]>:first-child {
65
+ margin-top: 0;
77
66
  }
@@ -9,9 +9,12 @@ exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _isHotkey = _interopRequireDefault(require("is-hotkey"));
11
11
  var _clickOutside = _interopRequireDefault(require("./click-outside"));
12
- var _normalEditor = _interopRequireDefault(require("./normal-editor"));
12
+ var _formatter = _interopRequireDefault(require("./formatter"));
13
13
  var _fallbackEditor = _interopRequireDefault(require("./fallback-editor"));
14
+ var _normalEditor = _interopRequireDefault(require("./normal-editor"));
15
+ var _slateConvert = require("../../slate-convert");
14
16
  var _getBrowserInfo = _interopRequireDefault(require("../../utils/get-browser-Info"));
17
+ var _extension = require("../../extension");
15
18
  require("./index.css");
16
19
  const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
17
20
  let {
@@ -25,25 +28,42 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
25
28
  onSaveEditorValue,
26
29
  editorApi
27
30
  } = _ref;
28
- const [isFocusEditor, setFocusEditor] = (0, _react.useState)(false);
31
+ const [isShowEditor, setShowEditor] = (0, _react.useState)(false);
29
32
  const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
30
33
  text: value
31
34
  } : value);
32
35
  const longTextValueChangedRef = (0, _react.useRef)(false);
36
+ const [focusNodePath, setFocusNodePath] = (0, _react.useState)(null);
33
37
  const {
34
38
  isWindowsWechat
35
39
  } = (0, _react.useMemo)(() => {
36
40
  return (0, _getBrowserInfo.default)(isCheckBrowser);
37
41
  }, [isCheckBrowser]);
38
- const openEditor = (0, _react.useCallback)(() => {
39
- setFocusEditor(true);
42
+ const openEditor = (0, _react.useCallback)(function () {
43
+ let focusNodePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
44
+ setFocusNodePath(focusNodePath);
45
+ setShowEditor(true);
40
46
  }, []);
41
47
  const closeEditor = (0, _react.useCallback)(() => {
42
48
  if (longTextValueChangedRef.current) {
43
49
  onSaveEditorValue(valueRef.current);
44
50
  }
45
- setFocusEditor(false);
51
+ setShowEditor(false);
46
52
  }, [longTextValueChangedRef, valueRef, onSaveEditorValue]);
53
+ const getAttributeNode = (0, _react.useCallback)(function (node, attribute) {
54
+ let deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
55
+ if (!node || !node.getAttribute) return null;
56
+ if (deep === -1) return null;
57
+ if (node.getAttribute(attribute)) return node.getAttribute(attribute);
58
+ if (node.parentNode) return getAttributeNode(node.parentNode, attribute, deep--);
59
+ }, []);
60
+ const previewClick = (0, _react.useCallback)((event, richValue) => {
61
+ if (event.target.nodeName === 'A') return;
62
+ // const nodeId = getAttributeNode(event.target, 'data-id');
63
+ onPreviewClick && onPreviewClick();
64
+
65
+ // openEditor(getNodePathById({ children: richValue }, nodeId));
66
+ }, [onPreviewClick, openEditor, getAttributeNode]);
47
67
  const onEditorValueChanged = (0, _react.useCallback)(value => {
48
68
  valueRef.current = value;
49
69
  longTextValueChangedRef.current = true;
@@ -64,27 +84,36 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
64
84
  closeEditor: closeEditor
65
85
  };
66
86
  }, [openEditor, closeEditor]);
67
- const onClick = (0, _react.useCallback)(() => {
68
- if (isFocusEditor) return;
69
- onPreviewClick && onPreviewClick();
70
- setFocusEditor(true);
71
- }, [isFocusEditor, onPreviewClick]);
87
+ const updateFocus = (0, _react.useCallback)(focusRange => {
88
+ console.log(focusRange);
89
+ openEditor(focusRange);
90
+ }, [openEditor]);
91
+
92
+ // if (!isShowEditor) {
93
+ // const richValue = mdStringToSlate(valueRef.current.text);
94
+ // return (
95
+ // <div className="sf-long-text-inline-editor-container preview" onClick={(event) => previewClick(event, richValue)} >
96
+ // {valueRef.current.text && (<Formatter value={isWindowsWechat ? valueRef.current : richValue} />)}
97
+ // </div>
98
+ // );
99
+ // }
100
+
72
101
  return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
73
102
  onClickOutside: closeEditor
74
103
  }, /*#__PURE__*/_react.default.createElement("div", {
75
104
  className: "w-100",
76
- onKeyDown: onHotKey,
77
- onClick: onClick
105
+ onKeyDown: onHotKey
78
106
  }, isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_fallbackEditor.default, {
79
- isShowEditor: isFocusEditor,
107
+ isShowEditor: isShowEditor,
80
108
  value: valueRef.current.text,
81
109
  onChange: onEditorValueChanged,
82
110
  closeEditor: closeEditor
83
111
  }) : /*#__PURE__*/_react.default.createElement(_normalEditor.default, {
84
- isFocus: isFocusEditor,
112
+ isShowEditor: isShowEditor,
113
+ updateFocus: updateFocus,
85
114
  lang: lang,
86
- isWindowsWechat: isWindowsWechat,
87
115
  headerName: headerName,
116
+ focusNodePath: focusNodePath,
88
117
  value: valueRef.current.text,
89
118
  autoSave: autoSave,
90
119
  saveDelay: saveDelay,
@@ -7,14 +7,15 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
10
  var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
12
11
  var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
13
12
  var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
14
13
  var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-dialog"));
15
14
  const NormalEditor = _ref => {
16
15
  let {
17
- isFocus,
16
+ isShowEditor,
17
+ updateFocus,
18
+ focusNodePath,
18
19
  lang,
19
20
  headerName,
20
21
  value: propsValue,
@@ -28,24 +29,23 @@ const NormalEditor = _ref => {
28
29
  const editorContainerRef = (0, _react.useRef)(null);
29
30
  const editorRef = (0, _react.useRef)(null);
30
31
  const [style, setStyle] = (0, _react.useState)({});
31
- const [isValueChanged, setValueChanged] = (0, _react.useState)(false);
32
32
  const [showExpandEditor, setShowExpandEditor] = (0, _react.useState)(false);
33
- const [value, setValue] = (0, _react.useState)(typeof propsValue === 'string' ? {
33
+ const valueRef = (0, _react.useRef)(typeof propsValue === 'string' ? {
34
34
  text: propsValue
35
35
  } : propsValue);
36
+ const valueChangedRef = (0, _react.useRef)(false);
36
37
  const saveValue = (0, _react.useCallback)(function (value) {
37
38
  let save = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
38
- setValueChanged(true);
39
- setValue(value);
39
+ valueChangedRef.current = true;
40
40
  onEditorValueChanged && onEditorValueChanged(value);
41
41
  if (!save) return;
42
42
  onSaveEditorValue && onSaveEditorValue(value);
43
- setValueChanged(false);
43
+ valueChangedRef.current = false;
44
44
  }, [onSaveEditorValue, onEditorValueChanged]);
45
45
  const handelAutoSave = (0, _react.useCallback)(() => {
46
- if (!isValueChanged) return;
47
- saveValue(value, true);
48
- }, [isValueChanged, value, saveValue]);
46
+ if (!valueChangedRef.current) return;
47
+ saveValue(valueRef.current, true);
48
+ }, [saveValue]);
49
49
  const onContentChanged = (0, _react.useCallback)(() => {
50
50
  // delay to update editor's content
51
51
  setTimeout(() => {
@@ -59,14 +59,14 @@ const NormalEditor = _ref => {
59
59
  links,
60
60
  checklist
61
61
  } = (0, _getPreviewContent.default)(slateNodes, false);
62
- const value = {
62
+ valueRef.current = {
63
63
  text: markdownString,
64
64
  preview: previewText,
65
65
  images: images,
66
66
  links: links,
67
67
  checklist
68
68
  };
69
- saveValue(value);
69
+ saveValue(valueRef.current);
70
70
  }, 0);
71
71
  }, [saveValue]);
72
72
  const openEditorDialog = (0, _react.useCallback)(() => {
@@ -79,7 +79,10 @@ const NormalEditor = _ref => {
79
79
  setShowExpandEditor(true);
80
80
  }, [editorContainerRef]);
81
81
  const onCloseEditorDialog = (0, _react.useCallback)(value => {
82
- value && saveValue(value);
82
+ if (value) {
83
+ valueRef.current = value;
84
+ saveValue(value);
85
+ }
83
86
  setStyle({});
84
87
  setShowExpandEditor(false);
85
88
  }, [saveValue]);
@@ -95,16 +98,16 @@ const NormalEditor = _ref => {
95
98
  };
96
99
  }, [autoSave, saveDelay, handelAutoSave]);
97
100
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
98
- className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
99
- 'preview': !isFocus
100
- }),
101
+ className: "sf-long-text-inline-editor-container",
101
102
  style: style,
102
103
  ref: editorContainerRef
103
104
  }, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
104
105
  ref: editorRef,
105
- isFocus: isFocus,
106
+ isShowEditor: isShowEditor,
107
+ updateFocus: updateFocus,
106
108
  isInline: true,
107
- value: value.text,
109
+ focusNodePath: focusNodePath,
110
+ value: valueRef.current.text,
108
111
  onSave: handelAutoSave,
109
112
  editorApi: editorApi,
110
113
  onContentChanged: onContentChanged,
@@ -116,13 +119,13 @@ const NormalEditor = _ref => {
116
119
  }), /*#__PURE__*/_react.default.createElement("div", {
117
120
  className: "sf-slate-editor-content"
118
121
  }, /*#__PURE__*/_react.default.createElement(_markdownPreview.default, {
119
- value: value.text,
122
+ value: valueRef.current.text,
120
123
  isShowOutline: false
121
124
  })))), showExpandEditor && /*#__PURE__*/_react.default.createElement(_longtextEditorDialog.default, {
122
125
  lang: lang,
123
126
  readOnly: false,
124
127
  headerName: headerName,
125
- value: value.text,
128
+ value: valueRef.current.text,
126
129
  autoSave: autoSave,
127
130
  saveDelay: saveDelay,
128
131
  isCheckBrowser: isCheckBrowser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.85beta9",
3
+ "version": "1.0.86beta",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {