@seafile/seafile-editor 1.0.86-beta → 1.0.86-beta2

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.
@@ -20,7 +20,7 @@ const isMacOS = (0, _common.isMac)();
20
20
  const InlineEditor = _ref => {
21
21
  let {
22
22
  isShowEditor,
23
- focusNodePath,
23
+ focusRange,
24
24
  value,
25
25
  editorApi,
26
26
  onSave,
@@ -54,23 +54,17 @@ const InlineEditor = _ref => {
54
54
  const eventBus = _eventBus.default.getInstance();
55
55
  eventBus.dispatch('change');
56
56
  }, [editor, onContentChanged]);
57
- const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
57
+ const focusNode = (0, _react.useCallback)((editor, focusRange) => {
58
58
  const [firstNode] = editor.children;
59
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);
60
+ if (focusRange && typeof focusRange === 'object' && focusRange.anchor) {
61
+ const startOfFirstNode = _slate.Editor.start(editor, focusRange.anchor.path);
62
+ const range = {
63
+ anchor: startOfFirstNode,
64
+ focus: startOfFirstNode
65
+ };
66
+ (0, _core.focusEditor)(editor, range);
67
+ setTimeout(() => (0, _core.focusEditor)(editor, focusRange), 0);
74
68
  return;
75
69
  }
76
70
  const [firstNodeFirstChild] = firstNode.children;
@@ -92,9 +86,6 @@ const InlineEditor = _ref => {
92
86
  });
93
87
  const timer = setTimeout(() => {
94
88
  editor.forceNormalize = false;
95
- if (isShowEditor) {
96
- focusNode(editor, focusNodePath);
97
- }
98
89
  }, 300);
99
90
  return () => {
100
91
  editor.forceNormalize = false;
@@ -103,13 +94,10 @@ const InlineEditor = _ref => {
103
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
104
95
  }, []);
105
96
  (0, _react.useEffect)(() => {
106
- if (focusNodePath) {
107
- console.log(focusNodePath);
108
- focusNode(editor, focusNodePath);
109
- }
110
-
97
+ if (!isShowEditor) return;
98
+ focusNode(editor, focusRange);
111
99
  // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, [focusNodePath]);
100
+ }, [isShowEditor, focusRange]);
113
101
 
114
102
  // willUnmount
115
103
  (0, _react.useEffect)(() => {
@@ -123,13 +111,14 @@ const InlineEditor = _ref => {
123
111
  // eslint-disable-next-line react-hooks/exhaustive-deps
124
112
  }, []);
125
113
  const onEditorClick = (0, _react.useCallback)(() => {
114
+ if (!isShowEditor) {
115
+ updateFocus(editor.selection);
116
+ return;
117
+ }
126
118
  const value = editor.children;
127
119
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
128
120
  focusNode(editor);
129
121
  }
130
- if (!isShowEditor) {
131
- updateFocus(editor.selection);
132
- }
133
122
  }, [isShowEditor, editor, focusNode, updateFocus]);
134
123
  return /*#__PURE__*/_react.default.createElement("div", {
135
124
  className: "sf-simple-slate-editor-container"
@@ -152,6 +141,7 @@ const InlineEditor = _ref => {
152
141
  }, /*#__PURE__*/_react.default.createElement("div", {
153
142
  className: "article"
154
143
  }, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
144
+ readOnly: !isShowEditor,
155
145
  decorate: decorate,
156
146
  renderElement: _extension.renderElement,
157
147
  renderLeaf: _extension.renderLeaf,
@@ -61,6 +61,6 @@
61
61
  display: flex;
62
62
  }
63
63
 
64
- .sf-long-text-inline-editor-container:not(.preview) .article>div[role=textbox]>:first-child {
64
+ .sf-long-text-inline-editor-container .article>div>:first-child {
65
65
  margin-top: 0;
66
66
  }
@@ -9,12 +9,9 @@ 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 _formatter = _interopRequireDefault(require("./formatter"));
13
12
  var _fallbackEditor = _interopRequireDefault(require("./fallback-editor"));
14
13
  var _normalEditor = _interopRequireDefault(require("./normal-editor"));
15
- var _slateConvert = require("../../slate-convert");
16
14
  var _getBrowserInfo = _interopRequireDefault(require("../../utils/get-browser-Info"));
17
- var _extension = require("../../extension");
18
15
  require("./index.css");
19
16
  const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
20
17
  let {
@@ -33,15 +30,15 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
33
30
  text: value
34
31
  } : value);
35
32
  const longTextValueChangedRef = (0, _react.useRef)(false);
36
- const [focusNodePath, setFocusNodePath] = (0, _react.useState)(null);
33
+ const [focusRange, setFocusRange] = (0, _react.useState)(null);
37
34
  const {
38
35
  isWindowsWechat
39
36
  } = (0, _react.useMemo)(() => {
40
37
  return (0, _getBrowserInfo.default)(isCheckBrowser);
41
38
  }, [isCheckBrowser]);
42
39
  const openEditor = (0, _react.useCallback)(function () {
43
- let focusNodePath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
44
- setFocusNodePath(focusNodePath);
40
+ let focusRange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
41
+ setFocusRange(focusRange);
45
42
  setShowEditor(true);
46
43
  }, []);
47
44
  const closeEditor = (0, _react.useCallback)(() => {
@@ -57,13 +54,6 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
57
54
  if (node.getAttribute(attribute)) return node.getAttribute(attribute);
58
55
  if (node.parentNode) return getAttributeNode(node.parentNode, attribute, deep--);
59
56
  }, []);
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]);
67
57
  const onEditorValueChanged = (0, _react.useCallback)(value => {
68
58
  valueRef.current = value;
69
59
  longTextValueChangedRef.current = true;
@@ -85,19 +75,9 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
85
75
  };
86
76
  }, [openEditor, closeEditor]);
87
77
  const updateFocus = (0, _react.useCallback)(focusRange => {
88
- console.log(focusRange);
78
+ onPreviewClick && onPreviewClick();
89
79
  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
-
80
+ }, [openEditor, onPreviewClick]);
101
81
  return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
102
82
  onClickOutside: closeEditor
103
83
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -113,7 +93,7 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
113
93
  updateFocus: updateFocus,
114
94
  lang: lang,
115
95
  headerName: headerName,
116
- focusNodePath: focusNodePath,
96
+ focusRange: focusRange,
117
97
  value: valueRef.current.text,
118
98
  autoSave: autoSave,
119
99
  saveDelay: saveDelay,
@@ -11,11 +11,12 @@ var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
11
11
  var _getPreviewContent = _interopRequireDefault(require("../../utils/get-preview-content"));
12
12
  var _markdownPreview = _interopRequireDefault(require("../markdown-preview"));
13
13
  var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-dialog"));
14
+ var _classnames = _interopRequireDefault(require("classnames"));
14
15
  const NormalEditor = _ref => {
15
16
  let {
16
17
  isShowEditor,
17
18
  updateFocus,
18
- focusNodePath,
19
+ focusRange,
19
20
  lang,
20
21
  headerName,
21
22
  value: propsValue,
@@ -98,7 +99,9 @@ const NormalEditor = _ref => {
98
99
  };
99
100
  }, [autoSave, saveDelay, handelAutoSave]);
100
101
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
101
- className: "sf-long-text-inline-editor-container",
102
+ className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
103
+ 'preview': !isShowEditor
104
+ }),
102
105
  style: style,
103
106
  ref: editorContainerRef
104
107
  }, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
@@ -106,7 +109,7 @@ const NormalEditor = _ref => {
106
109
  isShowEditor: isShowEditor,
107
110
  updateFocus: updateFocus,
108
111
  isInline: true,
109
- focusNodePath: focusNodePath,
112
+ focusRange: focusRange,
110
113
  value: valueRef.current.text,
111
114
  onSave: handelAutoSave,
112
115
  editorApi: editorApi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.86beta",
3
+ "version": "1.0.86beta2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {