@seafile/seafile-editor 1.0.86-beta1 → 1.0.86-beta3

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,8 +19,7 @@ require("./index.css");
19
19
  const isMacOS = (0, _common.isMac)();
20
20
  const InlineEditor = _ref => {
21
21
  let {
22
- isShowEditor,
23
- focusNodePath,
22
+ enableEdit,
24
23
  value,
25
24
  editorApi,
26
25
  onSave,
@@ -28,9 +27,10 @@ const InlineEditor = _ref => {
28
27
  onContentChanged,
29
28
  isSupportFormula,
30
29
  onExpandEditorToggle,
31
- updateFocus
30
+ handelEnableEdit
32
31
  } = _ref;
33
32
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
33
+ const [focusRange, setFocusRange] = (0, _react.useState)(null);
34
34
  const editor = (0, _react.useMemo)(() => {
35
35
  const baseEditor = (0, _extension.inlineEditor)();
36
36
  return (0, _withPropsEditor.default)(baseEditor, {
@@ -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 && 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);
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 (!enableEdit) return;
98
+ focusNode(editor, focusRange);
111
99
  // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, [focusNodePath]);
100
+ }, [enableEdit, focusRange]);
113
101
 
114
102
  // willUnmount
115
103
  (0, _react.useEffect)(() => {
@@ -123,17 +111,19 @@ const InlineEditor = _ref => {
123
111
  // eslint-disable-next-line react-hooks/exhaustive-deps
124
112
  }, []);
125
113
  const onEditorClick = (0, _react.useCallback)(() => {
114
+ if (!enableEdit) {
115
+ setFocusRange(editor.selection);
116
+ handelEnableEdit();
117
+ return;
118
+ }
126
119
  const value = editor.children;
127
120
  if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
128
121
  focusNode(editor);
129
122
  }
130
- if (!isShowEditor) {
131
- updateFocus(editor.selection);
132
- }
133
- }, [isShowEditor, editor, focusNode, updateFocus]);
123
+ }, [enableEdit, editor, focusNode, handelEnableEdit]);
134
124
  return /*#__PURE__*/_react.default.createElement("div", {
135
125
  className: "sf-simple-slate-editor-container"
136
- }, isShowEditor && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
126
+ }, enableEdit && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
137
127
  editor: editor,
138
128
  isSupportFormula: isSupportFormula,
139
129
  isSupportColumn: !!columns,
@@ -152,6 +142,7 @@ const InlineEditor = _ref => {
152
142
  }, /*#__PURE__*/_react.default.createElement("div", {
153
143
  className: "article"
154
144
  }, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
145
+ readOnly: !enableEdit,
155
146
  decorate: decorate,
156
147
  renderElement: _extension.renderElement,
157
148
  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,46 +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)(null);
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
-
65
- // openEditor(getNodePathById({ children: richValue }, nodeId));
66
- }, [onPreviewClick, openEditor, getAttributeNode]);
67
47
  const onEditorValueChanged = (0, _react.useCallback)(value => {
68
48
  valueRef.current = value;
69
49
  longTextValueChangedRef.current = true;
@@ -84,36 +64,25 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
84
64
  closeEditor: closeEditor
85
65
  };
86
66
  }, [openEditor, closeEditor]);
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
-
67
+ const handelEnableEdit = (0, _react.useCallback)(() => {
68
+ onClick && onClick();
69
+ openEditor();
70
+ }, [openEditor, onClick]);
101
71
  return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
102
72
  onClickOutside: closeEditor
103
73
  }, /*#__PURE__*/_react.default.createElement("div", {
104
74
  className: "w-100",
105
75
  onKeyDown: onHotKey
106
76
  }, isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_fallbackEditor.default, {
107
- isShowEditor: isShowEditor,
77
+ enableEdit: enableEdit,
108
78
  value: valueRef.current.text,
109
79
  onChange: onEditorValueChanged,
110
80
  closeEditor: closeEditor
111
81
  }) : /*#__PURE__*/_react.default.createElement(_normalEditor.default, {
112
- isShowEditor: isShowEditor,
113
- updateFocus: updateFocus,
82
+ enableEdit: enableEdit,
83
+ handelEnableEdit: handelEnableEdit,
114
84
  lang: lang,
115
85
  headerName: headerName,
116
- focusNodePath: focusNodePath,
117
86
  value: valueRef.current.text,
118
87
  autoSave: autoSave,
119
88
  saveDelay: saveDelay,
@@ -14,9 +14,8 @@ var _longtextEditorDialog = _interopRequireDefault(require("../longtext-editor-d
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
  const NormalEditor = _ref => {
16
16
  let {
17
- isShowEditor,
18
- updateFocus,
19
- focusNodePath,
17
+ enableEdit,
18
+ handelEnableEdit,
20
19
  lang,
21
20
  headerName,
22
21
  value: propsValue,
@@ -100,17 +99,16 @@ const NormalEditor = _ref => {
100
99
  }, [autoSave, saveDelay, handelAutoSave]);
101
100
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
102
101
  className: (0, _classnames.default)('sf-long-text-inline-editor-container', {
103
- 'preview': !isShowEditor
102
+ 'preview': !enableEdit
104
103
  }),
105
104
  style: style,
106
105
  ref: editorContainerRef
107
106
  }, !showExpandEditor ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
108
107
  ref: editorRef,
109
- isShowEditor: isShowEditor,
110
- updateFocus: updateFocus,
108
+ enableEdit: enableEdit,
111
109
  isInline: true,
112
- focusNodePath: focusNodePath,
113
110
  value: valueRef.current.text,
111
+ handelEnableEdit: handelEnableEdit,
114
112
  onSave: handelAutoSave,
115
113
  editorApi: editorApi,
116
114
  onContentChanged: onContentChanged,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.86beta1",
3
+ "version": "1.0.86beta3",
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;