@seafile/sdoc-editor 0.2.23-beta → 0.2.23-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.
- package/dist/components/doc-info/index.js +4 -4
- package/dist/components/doc-operations/index.js +3 -3
- package/dist/components/doc-operations/revision-operations/index.js +11 -7
- package/dist/hooks/index.js +3 -3
- package/dist/hooks/use-config.js +26 -2
- package/dist/hooks/use-document.js +2 -7
- package/dist/pages/simple-editor.js +19 -5
- package/package.json +1 -1
|
@@ -7,15 +7,15 @@ import { EXTERNAL_EVENT } from '../../constants';
|
|
|
7
7
|
import { DateUtils } from '../../utils';
|
|
8
8
|
import DraftDropdown from '../draft-dropdown';
|
|
9
9
|
import RevisionAvatar from '../../assets/images/revision-avatar.png';
|
|
10
|
-
import {
|
|
10
|
+
import { useConfig } from '../../hooks';
|
|
11
11
|
import './index.css';
|
|
12
12
|
var DocInfo = function DocInfo(_ref) {
|
|
13
13
|
var t = _ref.t,
|
|
14
14
|
isStarred = _ref.isStarred,
|
|
15
15
|
isDraft = _ref.isDraft,
|
|
16
16
|
isEditMode = _ref.isEditMode;
|
|
17
|
-
var
|
|
18
|
-
isPublished =
|
|
17
|
+
var _useConfig = useConfig(),
|
|
18
|
+
isPublished = _useConfig.isPublished;
|
|
19
19
|
var onInternalLinkClick = useCallback(function () {
|
|
20
20
|
var eventBus = EventBus.getInstance();
|
|
21
21
|
eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK);
|
|
@@ -70,7 +70,7 @@ var DocInfo = function DocInfo(_ref) {
|
|
|
70
70
|
className: "sdoc-revision-order"
|
|
71
71
|
}, t('Revision') + ' ' + revisionId), isPublished && /*#__PURE__*/React.createElement("div", {
|
|
72
72
|
className: "sdoc-revision-order"
|
|
73
|
-
}, t('Published')), /*#__PURE__*/React.createElement(TipMessage, {
|
|
73
|
+
}, t('Published')), !isPublished && /*#__PURE__*/React.createElement(TipMessage, {
|
|
74
74
|
isEditMode: isEditMode
|
|
75
75
|
})), /*#__PURE__*/React.createElement("div", {
|
|
76
76
|
className: "doc-state"
|
|
@@ -9,7 +9,7 @@ import CommentsOperation from './comments-operation';
|
|
|
9
9
|
import ShareOperation from './share-operation';
|
|
10
10
|
import TagOperation from './tag-operation';
|
|
11
11
|
import { isMobile } from '../../utils';
|
|
12
|
-
import {
|
|
12
|
+
import { useConfig } from '../../hooks';
|
|
13
13
|
import './style.css';
|
|
14
14
|
var DocOperations = function DocOperations(_ref) {
|
|
15
15
|
var isShowChanges = _ref.isShowChanges,
|
|
@@ -17,8 +17,8 @@ var DocOperations = function DocOperations(_ref) {
|
|
|
17
17
|
handleViewChangesToggle = _ref.handleViewChangesToggle,
|
|
18
18
|
handleRevisionPublished = _ref.handleRevisionPublished;
|
|
19
19
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
20
|
-
var
|
|
21
|
-
isPublished =
|
|
20
|
+
var _useConfig = useConfig(),
|
|
21
|
+
isPublished = _useConfig.isPublished;
|
|
22
22
|
if (isMobile) {
|
|
23
23
|
return /*#__PURE__*/React.createElement("div", {
|
|
24
24
|
className: "doc-ops"
|
|
@@ -4,7 +4,6 @@ import { EventBus } from '../../../basic-sdk';
|
|
|
4
4
|
import { getRebase, hasConflict } from '../../../basic-sdk/utils/rebase';
|
|
5
5
|
import context from '../../../context';
|
|
6
6
|
import { EXTERNAL_EVENT, TIP_TYPE } from '../../../constants';
|
|
7
|
-
import { useDocument } from '../../../hooks/use-document';
|
|
8
7
|
import toaster from '../../toast';
|
|
9
8
|
import TipDialog from '../../tip-dialog';
|
|
10
9
|
import { useTranslation } from 'react-i18next';
|
|
@@ -13,6 +12,7 @@ import ViewChanges from './view-changes';
|
|
|
13
12
|
import MoreRevisionOperations from './more-revision-operations';
|
|
14
13
|
import Revisions from './revisions';
|
|
15
14
|
import ChangesCount from './changes-count';
|
|
15
|
+
import { useConfig, useDocument } from '../../../hooks';
|
|
16
16
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
17
17
|
var isShowChanges = _ref.isShowChanges,
|
|
18
18
|
changes = _ref.changes,
|
|
@@ -25,7 +25,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
25
25
|
_useState2 = _slicedToArray(_useState, 2),
|
|
26
26
|
isShowTip = _useState2[0],
|
|
27
27
|
setShowTip = _useState2[1];
|
|
28
|
-
var _useState3 = useState(
|
|
28
|
+
var _useState3 = useState(''),
|
|
29
29
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
30
30
|
tipType = _useState4[0],
|
|
31
31
|
setTipType = _useState4[1];
|
|
@@ -34,9 +34,10 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
34
34
|
mergeValue = _useState6[0],
|
|
35
35
|
setMergeValue = _useState6[1];
|
|
36
36
|
var _useDocument = useDocument(),
|
|
37
|
-
loadDocument = _useDocument.loadDocument
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
loadDocument = _useDocument.loadDocument;
|
|
38
|
+
var _useConfig = useConfig(),
|
|
39
|
+
isPublished = _useConfig.isPublished,
|
|
40
|
+
setPublished = _useConfig.setPublished;
|
|
40
41
|
var onDocumentReplaced = useCallback(function () {
|
|
41
42
|
if (isShowTip) return;
|
|
42
43
|
setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
|
|
@@ -123,7 +124,10 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
123
124
|
if (canMerge && isNeedReplaceMaster) {
|
|
124
125
|
setTipType(TIP_TYPE.PUBLISHING);
|
|
125
126
|
context.publishRevision().then(function (res) {
|
|
126
|
-
|
|
127
|
+
setShowTip(false);
|
|
128
|
+
setTipType('');
|
|
129
|
+
setPublished(true);
|
|
130
|
+
toaster.success(t('Revision published'));
|
|
127
131
|
}).catch(function (error) {
|
|
128
132
|
toaster.danger(t('Error'));
|
|
129
133
|
});
|
|
@@ -146,7 +150,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
146
150
|
}
|
|
147
151
|
toaster.danger(t('Error'));
|
|
148
152
|
});
|
|
149
|
-
}, [loadDocument, t]);
|
|
153
|
+
}, [loadDocument, t, setPublished]);
|
|
150
154
|
|
|
151
155
|
// confirm publish
|
|
152
156
|
var onSubmit = useCallback(function () {
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { CollaboratorsProvider, useCollaborators } from './use-collaborators';
|
|
2
|
+
export { useDocument } from './use-document';
|
|
3
|
+
export { ConfigContext, useConfig } from './use-config';
|
package/dist/hooks/use-config.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
export var ConfigContext = React.createContext(null);
|
|
3
|
+
|
|
4
|
+
// export const ConfigProvider = (props) => {
|
|
5
|
+
// const initIsPublished = context.getSetting('isPublished');
|
|
6
|
+
// const [isPublished, setPublished] = useState(initIsPublished);
|
|
7
|
+
|
|
8
|
+
// return (
|
|
9
|
+
// <ConfigContext.Provider value={{ isPublished, setPublished }}>
|
|
10
|
+
// {props.children}
|
|
11
|
+
// </ConfigContext.Provider>
|
|
12
|
+
// );
|
|
13
|
+
// };
|
|
14
|
+
|
|
15
|
+
export var useConfig = function useConfig() {
|
|
16
|
+
var context = useContext(ConfigContext);
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error('\'ConfigContext\' is null');
|
|
19
|
+
}
|
|
20
|
+
var isPublished = context.isPublished,
|
|
21
|
+
setPublished = context.setPublished;
|
|
22
|
+
return {
|
|
23
|
+
isPublished: isPublished,
|
|
24
|
+
setPublished: setPublished
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -3,6 +3,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
3
3
|
import context from '../context';
|
|
4
4
|
export var useDocument = function useDocument() {
|
|
5
5
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
6
|
+
var isPublished = context.getSetting('isPublished');
|
|
6
7
|
var _useState = useState(true),
|
|
7
8
|
_useState2 = _slicedToArray(_useState, 2),
|
|
8
9
|
isFirstLoading = _useState2[0],
|
|
@@ -23,10 +24,6 @@ export var useDocument = function useDocument() {
|
|
|
23
24
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
24
25
|
errorMessage = _useState8[0],
|
|
25
26
|
setErrorMessage = _useState8[1];
|
|
26
|
-
var _useState9 = useState(context.getSetting('isPublished')),
|
|
27
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
28
|
-
isPublished = _useState10[0],
|
|
29
|
-
setPublished = _useState10[1];
|
|
30
27
|
var loadDocument = useCallback(function () {
|
|
31
28
|
return new Promise(function (resolve, reject) {
|
|
32
29
|
context.getFileContent().then(function (res) {
|
|
@@ -85,8 +82,6 @@ export var useDocument = function useDocument() {
|
|
|
85
82
|
errorMessage: errorMessage,
|
|
86
83
|
document: document,
|
|
87
84
|
loadDocument: loadDocument,
|
|
88
|
-
reloadDocument: reloadDocument
|
|
89
|
-
isPublished: isPublished,
|
|
90
|
-
setPublished: setPublished
|
|
85
|
+
reloadDocument: reloadDocument
|
|
91
86
|
};
|
|
92
87
|
};
|
|
@@ -9,7 +9,7 @@ import context from '../context';
|
|
|
9
9
|
import ErrorBoundary from './error-boundary';
|
|
10
10
|
import { SDocEditor } from '../basic-sdk';
|
|
11
11
|
import { PublishedRevisionDiffViewer, RevisionDiffViewer } from '../basic-sdk/views';
|
|
12
|
-
import { useDocument } from '../hooks';
|
|
12
|
+
import { useDocument, ConfigContext } from '../hooks';
|
|
13
13
|
import { resetWebTitleAndURL } from '../utils';
|
|
14
14
|
import '../assets/css/simple-editor.css';
|
|
15
15
|
var SimpleEditor = function SimpleEditor(_ref) {
|
|
@@ -23,8 +23,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
23
23
|
isReloading = _useDocument.isReloading,
|
|
24
24
|
errorMessage = _useDocument.errorMessage,
|
|
25
25
|
document = _useDocument.document,
|
|
26
|
-
reloadDocument = _useDocument.reloadDocument
|
|
27
|
-
isPublished = _useDocument.isPublished;
|
|
26
|
+
reloadDocument = _useDocument.reloadDocument;
|
|
28
27
|
var _useState = useState(false),
|
|
29
28
|
_useState2 = _slicedToArray(_useState, 2),
|
|
30
29
|
isShowChanges = _useState2[0],
|
|
@@ -37,6 +36,11 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
37
36
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
38
37
|
changes = _useState6[0],
|
|
39
38
|
setChanges = _useState6[1];
|
|
39
|
+
var initIsPublished = context.getSetting('isPublished');
|
|
40
|
+
var _useState7 = useState(initIsPublished),
|
|
41
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
42
|
+
isPublished = _useState8[0],
|
|
43
|
+
setPublished = _useState8[1];
|
|
40
44
|
|
|
41
45
|
// useMount: reset title
|
|
42
46
|
useEffect(function () {
|
|
@@ -69,6 +73,11 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
69
73
|
editorRef.current.setSlateValue(value);
|
|
70
74
|
editorRef.current.updateDocumentVersion(value);
|
|
71
75
|
}, []);
|
|
76
|
+
|
|
77
|
+
// const setPublished = useCallback(() => {
|
|
78
|
+
|
|
79
|
+
// }, []);
|
|
80
|
+
|
|
72
81
|
if (isFirstLoading) {
|
|
73
82
|
return /*#__PURE__*/React.createElement(Loading, null);
|
|
74
83
|
}
|
|
@@ -79,7 +88,12 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
79
88
|
className: "error-tip"
|
|
80
89
|
}, t(errorMessage)));
|
|
81
90
|
}
|
|
82
|
-
return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(
|
|
91
|
+
return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(ConfigContext.Provider, {
|
|
92
|
+
value: {
|
|
93
|
+
isPublished: isPublished,
|
|
94
|
+
setPublished: setPublished
|
|
95
|
+
}
|
|
96
|
+
}, /*#__PURE__*/React.createElement(DocInfo, {
|
|
83
97
|
isStarred: isStarred,
|
|
84
98
|
isDraft: isDraft,
|
|
85
99
|
isEditMode: isPublished ? false : !isShowChanges
|
|
@@ -88,7 +102,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
|
|
|
88
102
|
changes: changes,
|
|
89
103
|
handleViewChangesToggle: handleViewChangesToggle,
|
|
90
104
|
handleRevisionPublished: handleRevisionPublished
|
|
91
|
-
})), /*#__PURE__*/React.createElement(Content, null, isPublished && /*#__PURE__*/React.createElement(PublishedRevisionDiffViewer, {
|
|
105
|
+
}))), /*#__PURE__*/React.createElement(Content, null, isPublished && /*#__PURE__*/React.createElement(PublishedRevisionDiffViewer, {
|
|
92
106
|
isShowChanges: isShowChanges,
|
|
93
107
|
revisionContent: revisionContent,
|
|
94
108
|
didMountCallback: setDiffChanges
|