@seafile/seafile-editor 1.0.86 → 1.0.87

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,16 +19,18 @@ require("./index.css");
19
19
  const isMacOS = (0, _common.isMac)();
20
20
  const InlineEditor = _ref => {
21
21
  let {
22
- focusNodePath,
22
+ enableEdit,
23
23
  value,
24
24
  editorApi,
25
25
  onSave,
26
26
  columns,
27
27
  onContentChanged,
28
28
  isSupportFormula,
29
- onExpandEditorToggle
29
+ onExpandEditorToggle,
30
+ handelEnableEdit
30
31
  } = _ref;
31
32
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
33
+ const focusRangeRef = (0, _react.useRef)(null);
32
34
  const editor = (0, _react.useMemo)(() => {
33
35
  const baseEditor = (0, _extension.inlineEditor)();
34
36
  return (0, _withPropsEditor.default)(baseEditor, {
@@ -52,20 +54,19 @@ const InlineEditor = _ref => {
52
54
  const eventBus = _eventBus.default.getInstance();
53
55
  eventBus.dispatch('change');
54
56
  }, [editor, onContentChanged]);
55
- const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
57
+ const focusNode = (0, _react.useCallback)((editor, focusRange) => {
56
58
  const [firstNode] = editor.children;
57
59
  if (!firstNode) return;
58
- if (focusNodePath) {
59
- const customFocusNodePath = (0, _core.getNode)(editor, focusNodePath);
60
- if (customFocusNodePath) {
61
- const startOfFirstNode = _slate.Editor.start(editor, focusNodePath);
62
- const range = {
63
- anchor: startOfFirstNode,
64
- focus: startOfFirstNode
65
- };
66
- (0, _core.focusEditor)(editor, range);
67
- return;
68
- }
60
+ if (focusRange && focusRange !== null && focusRange !== void 0 && 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);
68
+ focusRangeRef.current = null;
69
+ return;
69
70
  }
70
71
  const [firstNodeFirstChild] = firstNode.children;
71
72
  if (firstNodeFirstChild) {
@@ -86,7 +87,8 @@ const InlineEditor = _ref => {
86
87
  });
87
88
  const timer = setTimeout(() => {
88
89
  editor.forceNormalize = false;
89
- focusNode(editor, focusNodePath);
90
+ if (!enableEdit) return;
91
+ focusNode(editor);
90
92
  }, 300);
91
93
  return () => {
92
94
  editor.forceNormalize = false;
@@ -94,6 +96,11 @@ const InlineEditor = _ref => {
94
96
  };
95
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
96
98
  }, []);
99
+ (0, _react.useEffect)(() => {
100
+ if (!enableEdit) return;
101
+ focusNode(editor, focusRangeRef.current);
102
+ // eslint-disable-next-line react-hooks/exhaustive-deps
103
+ }, [enableEdit]);
97
104
 
98
105
  // willUnmount
99
106
  (0, _react.useEffect)(() => {
@@ -107,14 +114,19 @@ const InlineEditor = _ref => {
107
114
  // eslint-disable-next-line react-hooks/exhaustive-deps
108
115
  }, []);
109
116
  const onEditorClick = (0, _react.useCallback)(() => {
117
+ if (!enableEdit) {
118
+ focusRangeRef.current = editor.selection;
119
+ handelEnableEdit();
120
+ return;
121
+ }
110
122
  const value = editor.children;
111
123
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
112
124
  focusNode(editor);
113
125
  }
114
- }, [editor, focusNode]);
126
+ }, [enableEdit, editor, focusNode, handelEnableEdit]);
115
127
  return /*#__PURE__*/_react.default.createElement("div", {
116
128
  className: "sf-simple-slate-editor-container"
117
- }, /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
129
+ }, enableEdit && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
118
130
  editor: editor,
119
131
  isSupportFormula: isSupportFormula,
120
132
  isSupportColumn: !!columns,
@@ -133,6 +145,7 @@ const InlineEditor = _ref => {
133
145
  }, /*#__PURE__*/_react.default.createElement("div", {
134
146
  className: "article"
135
147
  }, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
148
+ readOnly: !enableEdit,
136
149
  decorate: decorate,
137
150
  renderElement: _extension.renderElement,
138
151
  renderLeaf: _extension.renderLeaf,
@@ -10,7 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
10
10
  var _isHotkey = _interopRequireDefault(require("is-hotkey"));
11
11
  const FallbackEditor = _ref => {
12
12
  let {
13
- isShowEditor,
13
+ enableEdit,
14
14
  value: propsValue,
15
15
  onChange: propsOnChange,
16
16
  closeEditor
@@ -19,11 +19,11 @@ const FallbackEditor = _ref => {
19
19
  const showEditorRef = (0, _react.useRef)(false);
20
20
  const inputRef = (0, _react.useRef)(null);
21
21
  (0, _react.useEffect)(() => {
22
- if (isShowEditor === showEditorRef.current) return;
23
- if (isShowEditor && !showEditorRef.current) {
22
+ if (enableEdit === showEditorRef.current) return;
23
+ if (enableEdit && !showEditorRef.current) {
24
24
  setTimeout(() => inputRef.current.focus());
25
25
  }
26
- }, [isShowEditor]);
26
+ }, [enableEdit]);
27
27
  const onChange = (0, _react.useCallback)(event => {
28
28
  const newValue = event.target.value;
29
29
  if (newValue === value) return;
@@ -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 {
@@ -24,47 +21,29 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
24
21
  value,
25
22
  lang,
26
23
  headerName,
27
- onPreviewClick,
24
+ onClick,
28
25
  onSaveEditorValue,
29
26
  editorApi
30
27
  } = _ref;
31
- const [isShowEditor, setShowEditor] = (0, _react.useState)(false);
28
+ const [enableEdit, setEnableEdit] = (0, _react.useState)(false);
32
29
  const valueRef = (0, _react.useRef)(typeof value === 'string' ? {
33
30
  text: value
34
31
  } : value);
35
32
  const longTextValueChangedRef = (0, _react.useRef)(false);
36
- const [focusNodePath, setFocusNodePath] = (0, _react.useState)([0, 0]);
37
33
  const {
38
34
  isWindowsWechat
39
35
  } = (0, _react.useMemo)(() => {
40
36
  return (0, _getBrowserInfo.default)(isCheckBrowser);
41
37
  }, [isCheckBrowser]);
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);
38
+ const openEditor = (0, _react.useCallback)(() => {
39
+ setEnableEdit(true);
46
40
  }, []);
47
41
  const closeEditor = (0, _react.useCallback)(() => {
48
42
  if (longTextValueChangedRef.current) {
49
43
  onSaveEditorValue(valueRef.current);
50
44
  }
51
- setShowEditor(false);
45
+ setEnableEdit(false);
52
46
  }, [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
- openEditor((0, _extension.getNodePathById)({
65
- children: richValue
66
- }, nodeId));
67
- }, [onPreviewClick, openEditor, getAttributeNode]);
68
47
  const onEditorValueChanged = (0, _react.useCallback)(value => {
69
48
  valueRef.current = value;
70
49
  longTextValueChangedRef.current = true;
@@ -85,29 +64,25 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
85
64
  closeEditor: closeEditor
86
65
  };
87
66
  }, [openEditor, closeEditor]);
88
- if (!isShowEditor) {
89
- const richValue = (0, _slateConvert.mdStringToSlate)(valueRef.current.text);
90
- return /*#__PURE__*/_react.default.createElement("div", {
91
- className: "sf-long-text-inline-editor-container preview",
92
- onClick: event => previewClick(event, richValue)
93
- }, valueRef.current.text && /*#__PURE__*/_react.default.createElement(_formatter.default, {
94
- value: isWindowsWechat ? valueRef.current : richValue
95
- }));
96
- }
67
+ const handelEnableEdit = (0, _react.useCallback)(() => {
68
+ onClick && onClick();
69
+ openEditor();
70
+ }, [openEditor, onClick]);
97
71
  return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
98
72
  onClickOutside: closeEditor
99
73
  }, /*#__PURE__*/_react.default.createElement("div", {
100
74
  className: "w-100",
101
75
  onKeyDown: onHotKey
102
76
  }, isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_fallbackEditor.default, {
103
- isShowEditor: isShowEditor,
77
+ enableEdit: enableEdit,
104
78
  value: valueRef.current.text,
105
79
  onChange: onEditorValueChanged,
106
80
  closeEditor: closeEditor
107
81
  }) : /*#__PURE__*/_react.default.createElement(_normalEditor.default, {
82
+ enableEdit: enableEdit,
83
+ handelEnableEdit: handelEnableEdit,
108
84
  lang: lang,
109
85
  headerName: headerName,
110
- focusNodePath: focusNodePath,
111
86
  value: valueRef.current.text,
112
87
  autoSave: autoSave,
113
88
  saveDelay: saveDelay,
@@ -11,9 +11,11 @@ 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
- focusNodePath,
17
+ enableEdit,
18
+ handelEnableEdit,
17
19
  lang,
18
20
  headerName,
19
21
  value: propsValue,
@@ -95,15 +97,27 @@ const NormalEditor = _ref => {
95
97
  timer && clearTimeout(timer);
96
98
  };
97
99
  }, [autoSave, saveDelay, handelAutoSave]);
100
+ if (!enableEdit && !valueRef.current.text) {
101
+ return /*#__PURE__*/_react.default.createElement("div", {
102
+ className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
103
+ 'preview': !enableEdit
104
+ }),
105
+ ref: editorContainerRef,
106
+ onClick: handelEnableEdit
107
+ });
108
+ }
98
109
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
99
- className: "sf-long-text-inline-editor-container",
110
+ className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
111
+ 'preview': !enableEdit
112
+ }),
100
113
  style: style,
101
114
  ref: editorContainerRef
102
115
  }, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
103
116
  ref: editorRef,
117
+ enableEdit: enableEdit,
104
118
  isInline: true,
105
- focusNodePath: focusNodePath,
106
119
  value: valueRef.current.text,
120
+ handelEnableEdit: handelEnableEdit,
107
121
  onSave: handelAutoSave,
108
122
  editorApi: editorApi,
109
123
  onContentChanged: onContentChanged,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.86",
3
+ "version": "1.0.87",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,68 +0,0 @@
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
-
@@ -1,66 +0,0 @@
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;