@seafile/sdoc-editor 0.1.170 → 0.1.171
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.
- package/dist/basic-sdk/editor/sdoc-editor.js +72 -8
- package/dist/basic-sdk/extension/render/render-element.js +1 -0
- package/dist/basic-sdk/index.js +1 -1
- package/package.json +1 -1
- package/dist/basic-sdk/editor/index.js +0 -84
- /package/dist/basic-sdk/{editor/index.css → extension/render/rebase-style.css} +0 -0
|
@@ -1,16 +1,53 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
4
|
+
import React, { useEffect, useState, useImperativeHandle, forwardRef, useMemo } from 'react';
|
|
3
5
|
import { Editor } from '@seafile/slate';
|
|
6
|
+
import deepCopy from 'deep-copy';
|
|
7
|
+
import context from '../../context';
|
|
8
|
+
import CommonLoading from '../../components/common-loading';
|
|
9
|
+
import { PAGE_EDIT_AREA_WIDTH } from '../constants';
|
|
10
|
+
import { createDefaultEditor } from '../extension';
|
|
11
|
+
import withNodeId from '../node-id';
|
|
12
|
+
import { withSocketIO } from '../socket';
|
|
4
13
|
import { focusEditor } from '../extension/core';
|
|
5
|
-
import { EditorContainer, EditorContent } from '../layout';
|
|
6
14
|
import InsertElementDialog from '../extension/commons/insert-element-dialog';
|
|
15
|
+
import { EditorContainer, EditorContent } from '../layout';
|
|
7
16
|
import EditableArticle from './editable-article';
|
|
8
17
|
import { ColorProvider } from '../hooks/use-color-context';
|
|
9
18
|
import { HeaderToolbar } from '../extension';
|
|
10
|
-
var SdocEditor = function
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
var SdocEditor = forwardRef(function (_ref, ref) {
|
|
20
|
+
var document = _ref.document,
|
|
21
|
+
isReloading = _ref.isReloading;
|
|
22
|
+
var editor = useMemo(function () {
|
|
23
|
+
var defaultEditor = createDefaultEditor();
|
|
24
|
+
var editorConfig = context.getEditorConfig();
|
|
25
|
+
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
26
|
+
document: document,
|
|
27
|
+
config: editorConfig
|
|
28
|
+
}));
|
|
29
|
+
var cursors = document.cursors;
|
|
30
|
+
newEditor.cursors = cursors || {};
|
|
31
|
+
newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
|
|
32
|
+
return newEditor;
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
}, []);
|
|
36
|
+
var _useState = useState(document.children),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
slateValue = _useState2[0],
|
|
39
|
+
_setSlateValue = _useState2[1];
|
|
40
|
+
|
|
41
|
+
// useMount: init socket connection
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
editor.openConnection();
|
|
44
|
+
return function () {
|
|
45
|
+
editor.closeConnection();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
14
51
|
// useMount: focus editor
|
|
15
52
|
useEffect(function () {
|
|
16
53
|
var timer = setTimeout(function () {
|
|
@@ -34,6 +71,33 @@ var SdocEditor = function SdocEditor(_ref) {
|
|
|
34
71
|
};
|
|
35
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
73
|
}, []);
|
|
74
|
+
|
|
75
|
+
// The parent component can call the method of this component through ref
|
|
76
|
+
useImperativeHandle(ref, function () {
|
|
77
|
+
return {
|
|
78
|
+
setSlateValue: function setSlateValue(document) {
|
|
79
|
+
// Force update of editor's child elements
|
|
80
|
+
editor.children = document.children;
|
|
81
|
+
_setSlateValue(_toConsumableArray(document.children));
|
|
82
|
+
},
|
|
83
|
+
updateDocumentVersion: function updateDocumentVersion(document) {
|
|
84
|
+
editor.updateDocumentVersion(document);
|
|
85
|
+
},
|
|
86
|
+
// get value
|
|
87
|
+
getSlateValue: function getSlateValue() {
|
|
88
|
+
return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
89
|
+
children: slateValue
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
};
|
|
95
|
+
}, [document, editor, slateValue]);
|
|
96
|
+
if (isReloading) {
|
|
97
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
98
|
+
className: "h-100 w-100 d-flex align-items-center justify-content-center"
|
|
99
|
+
}, /*#__PURE__*/React.createElement(CommonLoading, null));
|
|
100
|
+
}
|
|
37
101
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
|
|
38
102
|
editor: editor
|
|
39
103
|
}, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(HeaderToolbar, {
|
|
@@ -44,9 +108,9 @@ var SdocEditor = function SdocEditor(_ref) {
|
|
|
44
108
|
}, /*#__PURE__*/React.createElement(EditableArticle, {
|
|
45
109
|
editor: editor,
|
|
46
110
|
slateValue: slateValue,
|
|
47
|
-
updateSlateValue:
|
|
111
|
+
updateSlateValue: _setSlateValue
|
|
48
112
|
})))), /*#__PURE__*/React.createElement(InsertElementDialog, {
|
|
49
113
|
editor: editor
|
|
50
114
|
}));
|
|
51
|
-
};
|
|
115
|
+
});
|
|
52
116
|
export default SdocEditor;
|
|
@@ -11,6 +11,7 @@ import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin
|
|
|
11
11
|
import EventBus from '../../utils/event-bus';
|
|
12
12
|
import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY, REBASE_ORIGIN } from '../../constants';
|
|
13
13
|
import { findPath, getNode, replaceNode, deleteNodeMark } from '../../extension/core';
|
|
14
|
+
import './rebase-style.css';
|
|
14
15
|
var CustomElement = function CustomElement(props) {
|
|
15
16
|
var editor = useSlateStatic();
|
|
16
17
|
var element = props.element,
|
package/dist/basic-sdk/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
|
|
5
|
-
import deepCopy from 'deep-copy';
|
|
6
|
-
import context from '../../context';
|
|
7
|
-
import CommonLoading from '../../components/common-loading';
|
|
8
|
-
import { PAGE_EDIT_AREA_WIDTH } from '../constants';
|
|
9
|
-
import { createDefaultEditor } from '../extension';
|
|
10
|
-
import withNodeId from '../node-id';
|
|
11
|
-
import { withSocketIO } from '../socket';
|
|
12
|
-
import SDocEditor from './sdoc-editor';
|
|
13
|
-
import './index.css';
|
|
14
|
-
var Editor = forwardRef(function (_ref, ref) {
|
|
15
|
-
var document = _ref.document,
|
|
16
|
-
_ref$isReloading = _ref.isReloading,
|
|
17
|
-
isReloading = _ref$isReloading === void 0 ? false : _ref$isReloading;
|
|
18
|
-
var editor = useMemo(function () {
|
|
19
|
-
var defaultEditor = createDefaultEditor();
|
|
20
|
-
var editorConfig = context.getEditorConfig();
|
|
21
|
-
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
22
|
-
document: document,
|
|
23
|
-
config: editorConfig
|
|
24
|
-
}));
|
|
25
|
-
var cursors = document.cursors;
|
|
26
|
-
newEditor.cursors = cursors || {};
|
|
27
|
-
newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
|
|
28
|
-
return newEditor;
|
|
29
|
-
|
|
30
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
-
}, []);
|
|
32
|
-
var _useState = useState(document.children),
|
|
33
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
-
slateValue = _useState2[0],
|
|
35
|
-
_setSlateValue = _useState2[1];
|
|
36
|
-
|
|
37
|
-
// useMount: init socket connection
|
|
38
|
-
useEffect(function () {
|
|
39
|
-
editor.openConnection();
|
|
40
|
-
return function () {
|
|
41
|
-
editor.closeConnection();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
-
}, []);
|
|
46
|
-
var updateSlateValue = useCallback(function (value) {
|
|
47
|
-
_setSlateValue(value);
|
|
48
|
-
|
|
49
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
// The parent component can call the method of this component through ref
|
|
53
|
-
useImperativeHandle(ref, function () {
|
|
54
|
-
return {
|
|
55
|
-
setSlateValue: function setSlateValue(document) {
|
|
56
|
-
// Force update of editor's child elements
|
|
57
|
-
editor.children = document.children;
|
|
58
|
-
_setSlateValue(_toConsumableArray(document.children));
|
|
59
|
-
},
|
|
60
|
-
updateDocumentVersion: function updateDocumentVersion(document) {
|
|
61
|
-
editor.updateDocumentVersion(document);
|
|
62
|
-
},
|
|
63
|
-
// get value
|
|
64
|
-
getSlateValue: function getSlateValue() {
|
|
65
|
-
return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
66
|
-
children: slateValue
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
-
};
|
|
72
|
-
}, [document, editor, slateValue]);
|
|
73
|
-
if (isReloading) {
|
|
74
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
75
|
-
className: "h-100 w-100 d-flex align-items-center justify-content-center"
|
|
76
|
-
}, /*#__PURE__*/React.createElement(CommonLoading, null));
|
|
77
|
-
}
|
|
78
|
-
return /*#__PURE__*/React.createElement(SDocEditor, {
|
|
79
|
-
slateValue: slateValue,
|
|
80
|
-
editor: editor,
|
|
81
|
-
updateSlateValue: updateSlateValue
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
export default Editor;
|
|
File without changes
|