@seafile/seafile-editor 1.0.85-beta3 → 1.0.85-beta5

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.
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _slateReact = require("slate-react");
11
+ var _slate = require("slate");
12
+ var _extension = require("../../extension");
13
+ var _eventBus = _interopRequireDefault(require("../../utils/event-bus"));
14
+ var _eventHandler = _interopRequireDefault(require("../../utils/event-handler"));
15
+ var _withPropsEditor = _interopRequireDefault(require("./with-props-editor"));
16
+ var _core = require("../../extension/core");
17
+ var _common = require("../../utils/common");
18
+ require("./style.css");
19
+ const isMacOS = (0, _common.isMac)();
20
+ const InlineEditor = _ref => {
21
+ let {
22
+ showTitle,
23
+ focusNodePath,
24
+ value,
25
+ editorApi,
26
+ onSave,
27
+ columns,
28
+ onContentChanged,
29
+ isSupportFormula,
30
+ onExpandEditorToggle
31
+ } = _ref;
32
+ const [slateValue, setSlateValue] = (0, _react.useState)(value);
33
+ const editor = (0, _react.useMemo)(() => {
34
+ if (showTitle) return (0, _withPropsEditor.default)(_extension.inlineEditor, {
35
+ editorApi,
36
+ onSave,
37
+ columns
38
+ });
39
+ return (0, _extension.createSlateEditor)();
40
+ }, [columns, editorApi, onSave, showTitle]);
41
+ const eventProxy = (0, _react.useMemo)(() => {
42
+ return new _eventHandler.default(editor);
43
+ }, [editor]);
44
+ const decorate = (0, _extension.useHighlight)(editor);
45
+ const onChange = (0, _react.useCallback)(value => {
46
+ setSlateValue(value);
47
+ if (editor.forceNormalize) return;
48
+ const operations = editor.operations;
49
+ const modifyOps = operations.filter(o => o.type !== 'set_selection');
50
+ if (modifyOps.length > 0) {
51
+ onContentChanged && onContentChanged(value);
52
+ }
53
+ const eventBus = _eventBus.default.getInstance();
54
+ eventBus.dispatch('change');
55
+ }, [editor, onContentChanged]);
56
+ const focusNode = (0, _react.useCallback)((editor, focusNodePath) => {
57
+ const [firstNode] = editor.children;
58
+ if (!firstNode) return;
59
+ if (focusNodePath) {
60
+ const customFocusNodePath = (0, _core.getNode)(editor, focusNodePath);
61
+ if (customFocusNodePath) {
62
+ const startOfFirstNode = _slate.Editor.start(editor, focusNodePath);
63
+ const range = {
64
+ anchor: startOfFirstNode,
65
+ focus: startOfFirstNode
66
+ };
67
+ (0, _core.focusEditor)(editor, range);
68
+ return;
69
+ }
70
+ }
71
+ const [firstNodeFirstChild] = firstNode.children;
72
+ if (firstNodeFirstChild) {
73
+ const startOfFirstNode = _slate.Editor.start(editor, [0, 0]);
74
+ const range = {
75
+ anchor: startOfFirstNode,
76
+ focus: startOfFirstNode
77
+ };
78
+ (0, _core.focusEditor)(editor, range);
79
+ }
80
+ }, []);
81
+
82
+ // const focusEndNode = useCallback((editor) => {
83
+ // const lastChildIndex = editor.children.length - 1;
84
+ // if (lastChildIndex < 0) return;
85
+ // const lastNode = editor.children[lastChildIndex];
86
+ // if (!lastNode) return;
87
+ // const [lastNodeFirstChild] = lastNode.children;
88
+ // if (lastNodeFirstChild) {
89
+ // const endOfFirstNode = Editor.end(editor, [lastChildIndex, 0]);
90
+ // const range = {
91
+ // anchor: endOfFirstNode,
92
+ // focus: endOfFirstNode,
93
+ // };
94
+ // focusEditor(editor, range);
95
+ // }
96
+ // }, []);
97
+
98
+ // useMount: focus editor
99
+ (0, _react.useEffect)(() => {
100
+ editor.forceNormalize = true;
101
+ _slate.Editor.normalize(editor, {
102
+ force: true
103
+ });
104
+ const timer = setTimeout(() => {
105
+ editor.forceNormalize = false;
106
+ focusNode(editor, focusNodePath);
107
+ }, 300);
108
+ return () => {
109
+ editor.forceNormalize = false;
110
+ clearTimeout(timer);
111
+ };
112
+ // eslint-disable-next-line react-hooks/exhaustive-deps
113
+ }, []);
114
+
115
+ // willUnmount
116
+ (0, _react.useEffect)(() => {
117
+ return () => {
118
+ editor.selection = null;
119
+ editor.history = {
120
+ redos: [],
121
+ undos: []
122
+ };
123
+ };
124
+ // eslint-disable-next-line react-hooks/exhaustive-deps
125
+ }, []);
126
+ const onEditorClick = (0, _react.useCallback)(() => {
127
+ const value = editor.children;
128
+ if (value.length === 1 && _slate.Node.string(value[0]).length === 0) {
129
+ focusNode(editor);
130
+ }
131
+ }, [editor, focusNode]);
132
+ return /*#__PURE__*/_react.default.createElement("div", {
133
+ className: "sf-simple-slate-editor-container"
134
+ }, showTitle && /*#__PURE__*/_react.default.createElement(_extension.InlineToolbar, {
135
+ editor: editor,
136
+ isSupportFormula: isSupportFormula,
137
+ isSupportColumn: !!columns,
138
+ onExpandEditorToggle: onExpandEditorToggle
139
+ }), /*#__PURE__*/_react.default.createElement("div", {
140
+ className: "sf-slate-editor-content",
141
+ onClick: onEditorClick
142
+ }, /*#__PURE__*/_react.default.createElement(_slateReact.Slate, {
143
+ editor: editor,
144
+ initialValue: slateValue,
145
+ onChange: onChange
146
+ }, /*#__PURE__*/_react.default.createElement("div", {
147
+ className: "sf-slate-scroll-container ".concat(isMacOS ? '' : 'isWin')
148
+ }, /*#__PURE__*/_react.default.createElement("div", {
149
+ className: "sf-slate-article-container"
150
+ }, /*#__PURE__*/_react.default.createElement("div", {
151
+ className: "article"
152
+ }, /*#__PURE__*/_react.default.createElement(_extension.SetNodeToDecorations, null), /*#__PURE__*/_react.default.createElement(_slateReact.Editable, {
153
+ decorate: decorate,
154
+ renderElement: _extension.renderElement,
155
+ renderLeaf: _extension.renderLeaf,
156
+ onKeyDown: eventProxy.onKeyDown,
157
+ onCopy: eventProxy.onCopy
158
+ })))))));
159
+ };
160
+ var _default = exports.default = InlineEditor;
@@ -0,0 +1,87 @@
1
+ .sf-simple-slate-editor-container {
2
+ flex: 1;
3
+ display: flex;
4
+ flex-direction: column;
5
+ min-height: 0;
6
+ min-width: 0;
7
+ }
8
+
9
+ .sf-simple-slate-editor-container .sf-slate-editor-toolbar {
10
+ display: flex;
11
+ justify-content: flex-start;
12
+ height: 44px;
13
+ align-items: center;
14
+ padding: 0 10px;
15
+ background-color: #fff;
16
+ user-select: none;
17
+ border-bottom: 1px solid #e5e6e8;
18
+ position: relative;
19
+ z-index: 102;
20
+ }
21
+
22
+ .sf-simple-slate-editor-container .sf-slate-editor-content {
23
+ width: 100%;
24
+ height: calc(100% - 44px);
25
+ display: flex;
26
+ background: #f5f5f5;
27
+ position: relative;
28
+ min-height: 0;
29
+ }
30
+
31
+ .sf-simple-slate-editor-container .sf-slate-scroll-container {
32
+ height: 100%;
33
+ width: 100%;
34
+ overflow: auto;
35
+ }
36
+
37
+ .sf-simple-slate-editor-container .sf-slate-scroll-container.isWin::-webkit-scrollbar {
38
+ width: 8px;
39
+ height: 8px;
40
+ }
41
+
42
+ .sf-simple-slate-editor-container .sf-slate-scroll-container.isWin::-webkit-scrollbar-button {
43
+ display: none;
44
+ }
45
+
46
+ .sf-simple-slate-editor-container .sf-slate-scroll-container.isWin::-webkit-scrollbar-thumb {
47
+ background-color: rgb(206, 206, 212);
48
+ border-radius: 10px;
49
+ }
50
+
51
+ /* .sf-simple-slate-editor-container .sf-slate-article-container {
52
+ flex: 1;
53
+ position: relative;
54
+ max-width: 950px;
55
+ min-width: 400px;
56
+ margin: 0 auto;
57
+ padding-top: 20px;
58
+ padding-bottom: 20px;
59
+ } */
60
+
61
+ .sf-simple-slate-editor-container .sf-slate-article-container {
62
+ height: 100%;
63
+ width: 100%;
64
+ overflow: auto;
65
+ }
66
+
67
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article {
68
+ margin: 0;
69
+ padding: 10px;
70
+ border: none;
71
+ background-color: #fff;
72
+ min-height: 100%;
73
+ color: #212529;
74
+ }
75
+
76
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h1,
77
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h2,
78
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h3,
79
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h4,
80
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h5,
81
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article h6 {
82
+ color: #212529;
83
+ }
84
+
85
+ .sf-simple-slate-editor-container .sf-slate-editor-content .article div:first-child {
86
+ outline: none;
87
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const withPropsEditor = function (editor) {
8
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9
+ let newEditor = editor;
10
+ if (props.editorApi) {
11
+ newEditor.api = props.editorApi;
12
+ }
13
+ if (props.onSave) {
14
+ newEditor.onSave = props.onSave;
15
+ }
16
+ if (props.columns) {
17
+ newEditor.columns = props.columns;
18
+ }
19
+ return newEditor;
20
+ };
21
+ var _default = exports.default = withPropsEditor;
@@ -19,28 +19,23 @@ require("./style.css");
19
19
  const isMacOS = (0, _common.isMac)();
20
20
  const SimpleSlateEditor = _ref => {
21
21
  let {
22
- isInline,
23
22
  focusNodePath,
24
23
  value,
25
24
  editorApi,
26
25
  onSave,
27
26
  columns,
28
27
  onContentChanged,
29
- isSupportFormula,
30
- onExpandEditorToggle
28
+ isSupportFormula
31
29
  } = _ref;
32
30
  const [slateValue, setSlateValue] = (0, _react.useState)(value);
33
- const editor = (0, _react.useMemo)(() => (0, _withPropsEditor.default)(isInline ? _extension.inlineEditor : _extension.baseEditor, {
31
+ const editor = (0, _react.useMemo)(() => (0, _withPropsEditor.default)(_extension.baseEditor, {
34
32
  editorApi,
35
33
  onSave,
36
34
  columns
37
- }), [columns, editorApi, onSave, isInline]);
35
+ }), [columns, editorApi, onSave]);
38
36
  const eventProxy = (0, _react.useMemo)(() => {
39
37
  return new _eventHandler.default(editor);
40
38
  }, [editor]);
41
- const ToolbarComponent = (0, _react.useMemo)(() => {
42
- return isInline ? _extension.InlineToolbar : _extension.Toolbar;
43
- }, [isInline]);
44
39
  const decorate = (0, _extension.useHighlight)(editor);
45
40
  const onChange = (0, _react.useCallback)(value => {
46
41
  setSlateValue(value);
@@ -131,11 +126,10 @@ const SimpleSlateEditor = _ref => {
131
126
  }, [editor, focusNode]);
132
127
  return /*#__PURE__*/_react.default.createElement("div", {
133
128
  className: "sf-simple-slate-editor-container"
134
- }, /*#__PURE__*/_react.default.createElement(ToolbarComponent, {
129
+ }, /*#__PURE__*/_react.default.createElement(_extension.Toolbar, {
135
130
  editor: editor,
136
131
  isSupportFormula: isSupportFormula,
137
- isSupportColumn: !!columns,
138
- onExpandEditorToggle: onExpandEditorToggle
132
+ isSupportColumn: !!columns
139
133
  }), /*#__PURE__*/_react.default.createElement("div", {
140
134
  className: "sf-slate-editor-content",
141
135
  onClick: onEditorClick
@@ -157,7 +151,4 @@ const SimpleSlateEditor = _ref => {
157
151
  onCopy: eventProxy.onCopy
158
152
  })))))));
159
153
  };
160
- SimpleSlateEditor.defaultProps = {
161
- isInline: false
162
- };
163
154
  var _default = exports.default = SimpleSlateEditor;
@@ -16,13 +16,17 @@ const baseEditor = exports.baseEditor = _plugins.default.reduce((editor, pluginI
16
16
  }
17
17
  return editor;
18
18
  }, (0, _slateHistory.withHistory)((0, _slateReact.withReact)((0, _slate.createEditor)())));
19
- const inlineEditor = exports.inlineEditor = _plugins.default.reduce((editor, pluginItem) => {
20
- const withPlugin = pluginItem.editorPlugin;
21
- if (withPlugin) {
22
- return withPlugin(editor);
23
- }
19
+ const inlineEditor = () => {
20
+ const editor = _plugins.default.reduce((editor, pluginItem) => {
21
+ const withPlugin = pluginItem.editorPlugin;
22
+ if (withPlugin) {
23
+ return withPlugin(editor);
24
+ }
25
+ return editor;
26
+ }, (0, _slateHistory.withHistory)((0, _slateReact.withReact)((0, _slate.createEditor)())));
24
27
  return editor;
25
- }, (0, _slateHistory.withHistory)((0, _slateReact.withReact)((0, _slate.createEditor)())));
28
+ };
29
+ exports.inlineEditor = inlineEditor;
26
30
  const createSlateEditor = () => {
27
31
  const editor = _plugins.default.reduce((editor, pluginItem) => {
28
32
  const withPlugin = pluginItem.editorPlugin;
@@ -7,13 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
- var _simpleEditor = _interopRequireDefault(require("../simple-editor"));
10
+ 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
14
  require("./index.css");
15
15
  const Editor = _ref => {
16
16
  let {
17
+ showTitle,
17
18
  lang,
18
19
  headerName,
19
20
  value: propsValue,
@@ -101,6 +102,7 @@ const Editor = _ref => {
101
102
  ref: editorContainerRef
102
103
  }, !showExpandEditor && !isWindowsWechat ? /*#__PURE__*/_react.default.createElement(_simpleEditor.default, {
103
104
  isInline: true,
105
+ showTitle: showTitle,
104
106
  focusNodePath: focusNodePath,
105
107
  ref: editorRef,
106
108
  value: value.text,
@@ -8,7 +8,7 @@ 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 _ClickOutside = _interopRequireDefault(require("./ClickOutside"));
11
+ var _clickOutside = _interopRequireDefault(require("./click-outside"));
12
12
  var _formatter = _interopRequireDefault(require("./formatter"));
13
13
  var _editor = _interopRequireDefault(require("./editor"));
14
14
  var _slateConvert = require("../../slate-convert");
@@ -83,21 +83,18 @@ const LongTextInlineEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) =>
83
83
  closeEditor: closeEditor
84
84
  };
85
85
  }, [openEditor, closeEditor]);
86
- if (!isShowEditor) {
87
- const richValue = (0, _slateConvert.mdStringToSlate)(valueRef.current.text);
88
- return /*#__PURE__*/_react.default.createElement("div", {
89
- className: "sf-long-text-inline-editor-container preview",
90
- onClick: event => previewClick(event, richValue)
91
- }, /*#__PURE__*/_react.default.createElement(_formatter.default, {
92
- value: isWindowsWechat ? valueRef.current : richValue
93
- }));
94
- }
95
- return /*#__PURE__*/_react.default.createElement(_ClickOutside.default, {
86
+ const onClick = (0, _react.useCallback)(() => {
87
+ if (isShowEditor) return;
88
+ setShowEditor(true);
89
+ }, [isShowEditor]);
90
+ return /*#__PURE__*/_react.default.createElement(_clickOutside.default, {
96
91
  onClickOutside: closeEditor
97
92
  }, /*#__PURE__*/_react.default.createElement("div", {
98
93
  className: "w-100",
99
- onKeyDown: onHotKey
94
+ onKeyDown: onHotKey,
95
+ onClick: onClick
100
96
  }, /*#__PURE__*/_react.default.createElement(_editor.default, {
97
+ showTitle: isShowEditor,
101
98
  lang: lang,
102
99
  isWindowsWechat: isWindowsWechat,
103
100
  headerName: headerName,
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _loading = _interopRequireDefault(require("../../containers/loading"));
11
+ var _slateConvert = require("../../slate-convert");
12
+ var _useMathjax = _interopRequireDefault(require("../../hooks/use-mathjax"));
13
+ var _inlineEditor = _interopRequireDefault(require("../../editors/inline-editor"));
14
+ const SimpleEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
15
+ let {
16
+ isFetching,
17
+ value,
18
+ editorApi,
19
+ mathJaxSource,
20
+ onSave: propsOnSave,
21
+ onContentChanged: propsOnContentChanged,
22
+ ...otherProps
23
+ } = _ref;
24
+ const [richValue, setRichValue] = (0, _react.useState)([]);
25
+ const [isLoading, setIsLoading] = (0, _react.useState)(true);
26
+ const {
27
+ isLoadingMathJax
28
+ } = (0, _useMathjax.default)(mathJaxSource);
29
+ (0, _react.useImperativeHandle)(ref, () => {
30
+ return {
31
+ getValue: () => {
32
+ const mdStringValue = (0, _slateConvert.slateToMdString)(richValue);
33
+ return mdStringValue;
34
+ },
35
+ getSlateValue: () => {
36
+ return richValue;
37
+ }
38
+ };
39
+ }, [richValue]);
40
+ (0, _react.useEffect)(() => {
41
+ if (!isFetching) {
42
+ const richValue = (0, _slateConvert.mdStringToSlate)(value);
43
+ setRichValue(richValue);
44
+ setIsLoading(false);
45
+ }
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [isFetching]);
48
+ const onContentChanged = (0, _react.useCallback)(content => {
49
+ setRichValue(content);
50
+ propsOnContentChanged && propsOnContentChanged();
51
+ }, [propsOnContentChanged]);
52
+ const props = {
53
+ isSupportFormula: !!mathJaxSource,
54
+ value: richValue,
55
+ editorApi: editorApi,
56
+ onSave: propsOnSave,
57
+ onContentChanged: onContentChanged,
58
+ ...otherProps
59
+ };
60
+ if (isFetching || isLoading || isLoadingMathJax) {
61
+ return /*#__PURE__*/_react.default.createElement(_loading.default, null);
62
+ }
63
+ return /*#__PURE__*/_react.default.createElement(_inlineEditor.default, props);
64
+ });
65
+ var _default = exports.default = SimpleEditor;
@@ -13,7 +13,6 @@ var _useMathjax = _interopRequireDefault(require("../hooks/use-mathjax"));
13
13
  var _simpleSlateEditor = _interopRequireDefault(require("../editors/simple-slate-editor"));
14
14
  const SimpleEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
15
15
  let {
16
- isInline,
17
16
  isFetching,
18
17
  value,
19
18
  editorApi,
@@ -51,7 +50,6 @@ const SimpleEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
51
50
  propsOnContentChanged && propsOnContentChanged();
52
51
  }, [propsOnContentChanged]);
53
52
  const props = {
54
- isInline,
55
53
  isSupportFormula: !!mathJaxSource,
56
54
  value: richValue,
57
55
  editorApi: editorApi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.85beta3",
3
+ "version": "1.0.85beta5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {