@seafile/sdoc-editor 0.1.142 → 0.1.143-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.
Files changed (45) hide show
  1. package/dist/api/sdoc-server-api.js +10 -0
  2. package/dist/api/seafile-api.js +27 -5
  3. package/dist/basic-sdk/assets/css/dropdown-menu.css +5 -1
  4. package/dist/basic-sdk/constants/index.js +14 -1
  5. package/dist/basic-sdk/editor/common-editor.js +45 -0
  6. package/dist/basic-sdk/editor/index.js +135 -0
  7. package/dist/basic-sdk/editor/rebase-editor/index.css +29 -0
  8. package/dist/basic-sdk/editor/rebase-editor/index.js +272 -0
  9. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  10. package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +12 -3
  11. package/dist/basic-sdk/extension/constants/index.js +2 -0
  12. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  13. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +2 -20
  14. package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -6
  15. package/dist/basic-sdk/extension/plugins/html/plugin.js +23 -2
  16. package/dist/basic-sdk/extension/plugins/image/helpers.js +13 -3
  17. package/dist/basic-sdk/extension/plugins/link/dialog/add-link-dialog/index.js +2 -1
  18. package/dist/basic-sdk/extension/plugins/link/helpers.js +14 -4
  19. package/dist/basic-sdk/extension/plugins/link/plugin.js +8 -13
  20. package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +30 -2
  21. package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -3
  22. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +5 -2
  23. package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +13 -8
  24. package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +7 -4
  25. package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +13 -2
  26. package/dist/basic-sdk/socket/helpers.js +1 -0
  27. package/dist/basic-sdk/socket/socket-client.js +15 -0
  28. package/dist/basic-sdk/socket/socket-manager.js +11 -2
  29. package/dist/basic-sdk/socket/with-socket-io.js +25 -12
  30. package/dist/basic-sdk/utils/diff.js +2 -2
  31. package/dist/basic-sdk/utils/rebase.js +193 -0
  32. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  33. package/dist/basic-sdk/views/viewer.js +8 -11
  34. package/dist/components/doc-operations/index.js +8 -2
  35. package/dist/components/doc-operations/revision-operations/index.js +11 -3
  36. package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
  37. package/dist/components/tip-dialog/index.css +0 -0
  38. package/dist/components/tip-dialog/index.js +45 -0
  39. package/dist/constants/index.js +8 -1
  40. package/dist/context.js +28 -4
  41. package/dist/pages/simple-editor.js +228 -71
  42. package/package.json +1 -1
  43. package/public/locales/en/sdoc-editor.json +8 -1
  44. package/public/locales/zh_CN/sdoc-editor.json +7 -1
  45. package/dist/basic-sdk/editor.js +0 -105
@@ -1,9 +1,6 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
4
3
  import { withTranslation } from 'react-i18next';
5
- import deepCopy from 'deep-copy';
6
- import { SDocEditor, DiffViewer } from '../basic-sdk';
7
4
  import Loading from '../components/loading';
8
5
  import DocInfo from '../components/doc-info';
9
6
  import DocOperations from '../components/doc-operations';
@@ -11,6 +8,11 @@ import Layout, { Header, Content } from '../layout';
11
8
  import { generateDefaultDocContent } from '../utils';
12
9
  import context from '../context';
13
10
  import ErrorBoundary from './error-boundary';
11
+ import TipDialog from '../components/tip-dialog';
12
+ import { EXTERNAL_EVENT, MODE } from '../constants';
13
+ import { getRebase } from '../basic-sdk/utils/rebase';
14
+ import toaster from '../components/toast';
15
+ import { EventBus, SDocEditor } from '../basic-sdk';
14
16
  import '../assets/css/simple-editor.css';
15
17
  var SimpleEditor = function SimpleEditor(_ref) {
16
18
  var isStarred = _ref.isStarred,
@@ -19,39 +21,71 @@ var SimpleEditor = function SimpleEditor(_ref) {
19
21
  var editorRef = useRef(null);
20
22
  var _useState = useState(true),
21
23
  _useState2 = _slicedToArray(_useState, 2),
22
- isFirstLoad = _useState2[0],
23
- setFirstLoad = _useState2[1];
24
- var _useState3 = useState(true),
24
+ isLoadingSdoc = _useState2[0],
25
+ setLoadingSdoc = _useState2[1];
26
+ var _useState3 = useState(''),
25
27
  _useState4 = _slicedToArray(_useState3, 2),
26
- isLoadingSdoc = _useState4[0],
27
- setLoadingSdoc = _useState4[1];
28
- var _useState5 = useState(''),
28
+ errorMessage = _useState4[0],
29
+ setErrorMessage = _useState4[1];
30
+ var _useState5 = useState(false),
29
31
  _useState6 = _slicedToArray(_useState5, 2),
30
- errorMessage = _useState6[0],
31
- setErrorMessage = _useState6[1];
32
- var _useState7 = useState(false),
32
+ isShowChanges = _useState6[0],
33
+ setShowChanges = _useState6[1];
34
+ var _useState7 = useState(null),
33
35
  _useState8 = _slicedToArray(_useState7, 2),
34
- isShowChanges = _useState8[0],
35
- setShowChanges = _useState8[1];
36
- var _useState9 = useState(null),
36
+ document = _useState8[0],
37
+ setDocument = _useState8[1];
38
+ var _useState9 = useState(MODE.EDITOR),
37
39
  _useState10 = _slicedToArray(_useState9, 2),
38
- document = _useState10[0],
39
- setDocument = _useState10[1];
40
- var _useState11 = useState(null),
40
+ mode = _useState10[0],
41
+ setMode = _useState10[1];
42
+ var _useState11 = useState([]),
41
43
  _useState12 = _slicedToArray(_useState11, 2),
42
- currentContent = _useState12[0],
43
- setCurrentContent = _useState12[1];
44
- var _useState13 = useState(null),
44
+ changes = _useState12[0],
45
+ setChanges = _useState12[1];
46
+ var _useState13 = useState(false),
45
47
  _useState14 = _slicedToArray(_useState13, 2),
46
- lastContent = _useState14[0],
47
- setLastContent = _useState14[1];
48
+ showTip = _useState14[0],
49
+ setShowTip = _useState14[1];
48
50
  useEffect(function () {
49
51
  context.initApi();
50
- initDocumentData(true);
52
+ initDocumentData();
51
53
 
52
54
  // eslint-disable-next-line react-hooks/exhaustive-deps
53
55
  }, []);
54
- var initDocumentData = useCallback(function (isFirstLoad) {
56
+ var rebaseDocument = useCallback(function (document) {
57
+ toaster.warning(t('Document_has_rebased'));
58
+ editorRef.current.setLoading(true);
59
+ setShowChanges(false);
60
+ setMode(MODE.EDITOR);
61
+ editorRef.current.setEditorMode(MODE.EDITOR);
62
+ setDocument(document);
63
+ editorRef.current.setSlateValue(document);
64
+ editorRef.current.setLoading(false);
65
+
66
+ // eslint-disable-next-line react-hooks/exhaustive-deps
67
+ }, [editorRef]);
68
+ useEffect(function () {
69
+ var eventBus = EventBus.getInstance();
70
+ var rebaseDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.REBASE_DOCUMENT, rebaseDocument);
71
+ return function () {
72
+ rebaseDocumentSubscribe();
73
+ };
74
+
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ }, []);
77
+
78
+ // useMount: reset title
79
+ useEffect(function () {
80
+ var isSdocRevision = context.getSetting('isSdocRevision');
81
+ var originFilename = context.getSetting('originFilename');
82
+ if (isSdocRevision) {
83
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
84
+ }
85
+
86
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
+ }, []);
88
+ var initDocumentData = useCallback(function () {
55
89
  setShowChanges(false);
56
90
  setLoadingSdoc(true);
57
91
  context.getFileContent().then(function (res) {
@@ -65,7 +99,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
65
99
  }
66
100
  setDocument(result);
67
101
  setLoadingSdoc(false);
68
- isFirstLoad && setFirstLoad(false);
69
102
  }).catch(function (error) {
70
103
  // eslint-disable-next-line
71
104
  console.log(error);
@@ -83,54 +116,181 @@ var SimpleEditor = function SimpleEditor(_ref) {
83
116
 
84
117
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
118
  }, []);
86
- var initChangesData = useCallback(function () {
87
- setShowChanges(true);
88
- setLoadingSdoc(true);
89
- context.getSeadocRevisionDownloadLinks().then(function (res) {
119
+ var setFileContent = useCallback(function () {
120
+ context.getFileContent().then(function (res) {
121
+ var result = res.data || generateDefaultDocContent();
122
+ if (result && !result.children) {
123
+ result = {
124
+ version: 0,
125
+ children: result.content,
126
+ cursors: result.cursors || {}
127
+ };
128
+ }
129
+ setDocument(result);
130
+ editorRef.current.setSlateValue(result);
131
+ editorRef.current.setLoading(false);
132
+ }).catch(function (error) {
133
+ // eslint-disable-next-line
134
+ console.log(error);
135
+ setErrorMessage('Load_doc_content_error');
136
+ editorRef.current.setLoading(false);
137
+ });
138
+
139
+ // eslint-disable-next-line no-trailing-spaces
140
+ }, []);
141
+ var setDiffContent = useCallback(function () {
142
+ context.getSeadocOriginFileDownloadLink().then(function (res) {
90
143
  var originFileDownloadLink = res.data.origin_file_download_link;
91
144
  return fetch(originFileDownloadLink);
92
145
  }).then(function (res) {
93
146
  return res.json();
94
147
  }).then(function (originContent) {
95
- setLastContent(originContent);
96
- setErrorMessage(null);
97
- setLoadingSdoc(false);
148
+ editorRef.current.setDiffContent(originContent);
149
+ editorRef.current.setLoading(false);
98
150
  }).catch(function (error) {
99
- setErrorMessage('Load_doc_content_error');
100
- setLoadingSdoc(false);
151
+ console.log('error');
101
152
  });
102
-
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [document]);
153
+ }, []);
105
154
  var toggleViewChanges = useCallback(function (isShowChanges) {
106
- if (isShowChanges) {
107
- var newestValue = editorRef.current.getValue();
108
- setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
109
- children: newestValue
110
- })));
155
+ var needFetchNewContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
156
+ editorRef.current.setLoading(true);
157
+ setShowChanges(isShowChanges);
158
+ var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
159
+ setMode(mode);
160
+ editorRef.current.setEditorMode(mode);
161
+ if (!isShowChanges) {
162
+ setFileContent();
163
+ return;
111
164
  }
112
- if (isShowChanges) {
113
- initChangesData();
165
+ if (!needFetchNewContent) {
166
+ setDiffContent();
114
167
  return;
115
168
  }
116
- setChanges([]);
117
- initDocumentData(false);
169
+ context.getFileContent().then(function (res) {
170
+ var result = res.data || generateDefaultDocContent();
171
+ if (result && !result.children) {
172
+ result = {
173
+ version: 0,
174
+ children: result.content,
175
+ cursors: result.cursors || {}
176
+ };
177
+ }
178
+ setDocument(result);
179
+ editorRef.current.setSlateValue(result);
180
+ }).then(function () {
181
+ setDiffContent();
182
+ }).catch(function (error) {
183
+ // eslint-disable-next-line
184
+ console.log(error);
185
+ setErrorMessage('Load_doc_content_error');
186
+ editorRef.current.setLoading(false);
187
+ });
118
188
 
119
189
  // eslint-disable-next-line react-hooks/exhaustive-deps
120
190
  }, [document]);
121
- var _useState15 = useState([]),
122
- _useState16 = _slicedToArray(_useState15, 2),
123
- changes = _useState16[0],
124
- setChanges = _useState16[1];
191
+ var publishRevision = useCallback(function () {
192
+ var repoID = context.getSetting('repoID');
193
+ var siteRoot = context.getSetting('siteRoot');
194
+ var originFileVersion = context.getSetting('originFileVersion');
195
+ var originFilePath = context.getSetting('originFilePath');
196
+ var revisionCurrentContent;
197
+ var revisionMasterContent;
198
+ var masterContent;
199
+ context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
200
+ var fileHistoryRevisionContent = res.data.content; // commit content
201
+ revisionMasterContent = JSON.parse(fileHistoryRevisionContent);
202
+ return context.getSeadocOriginFileDownloadLink();
203
+ }).then(function (res) {
204
+ var originFileDownloadLink = res.data.origin_file_download_link;
205
+ return fetch(originFileDownloadLink);
206
+ }).then(function (res) {
207
+ return res.json();
208
+ }).then(function (content) {
209
+ masterContent = content;
210
+ return context.getFileContent();
211
+ }).then(function (res) {
212
+ var result = res.data || generateDefaultDocContent();
213
+ if (result && !result.children) {
214
+ result = {
215
+ version: 0,
216
+ children: result.content,
217
+ cursors: result.cursors || {}
218
+ };
219
+ }
220
+ revisionCurrentContent = result;
221
+ var _getRebase = getRebase(masterContent, revisionMasterContent, revisionCurrentContent),
222
+ canMerge = _getRebase.canMerge,
223
+ isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
224
+ value = _getRebase.value;
225
+ if (canMerge && isNeedReplaceMaster) {
226
+ context.publishSdocRevision().then(function (res) {
227
+ var origin_file_path = res.data.origin_file_path;
228
+ window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
229
+ }).catch(function (error) {
230
+ toaster.danger(t('Error'));
231
+ });
232
+ return;
233
+ }
234
+ if (canMerge && !isNeedReplaceMaster) {
235
+ setShowTip(true);
236
+ return;
237
+ }
238
+ toaster.warning(t('Need_rebase'));
239
+ editorRef.current.setLoading(true);
240
+ editorRef.current.setSlateValue(value);
241
+ setMode(MODE.REBASE);
242
+ editorRef.current.setEditorMode(MODE.REBASE);
243
+ editorRef.current.setLoading(false);
244
+ }).catch(function (error) {
245
+ toaster.danger(t('Error'));
246
+ });
247
+
248
+ // eslint-disable-next-line react-hooks/exhaustive-deps
249
+ }, [document, isShowChanges, mode]);
250
+ var rebaseEnd = useCallback(function () {
251
+ editorRef.current.setLoading(true);
252
+ setShowChanges(false);
253
+ setMode(MODE.EDITOR);
254
+ editorRef.current.setEditorMode(MODE.EDITOR);
255
+ setFileContent();
256
+
257
+ // eslint-disable-next-line react-hooks/exhaustive-deps
258
+ }, []);
259
+ var abortRebase = useCallback(function () {
260
+ toggleViewChanges(isShowChanges, true);
261
+
262
+ // eslint-disable-next-line react-hooks/exhaustive-deps
263
+ }, [isShowChanges, document]);
125
264
  var setDiffChanges = useCallback(function (diff) {
126
265
  setChanges(diff.changes);
127
266
 
128
267
  // eslint-disable-next-line react-hooks/exhaustive-deps
129
268
  }, [isShowChanges]);
130
- if (isFirstLoad && !errorMessage) {
269
+ var closeTipDialog = useCallback(function () {
270
+ setShowTip(false);
271
+
272
+ // eslint-disable-next-line react-hooks/exhaustive-deps
273
+ }, []);
274
+ var deleteRevision = useCallback(function () {
275
+ context.deleteRevision().then(function (res) {
276
+ if (res.data.success) {
277
+ var repoID = context.getSetting('repoID');
278
+ var siteRoot = context.getSetting('siteRoot');
279
+ var originFilePath = context.getSetting('originFilePath');
280
+ window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(originFilePath);
281
+ setShowTip(false);
282
+ }
283
+ }).catch(function (error) {
284
+ toaster.danger(t('Error'));
285
+ setShowTip(false);
286
+ });
287
+
288
+ // eslint-disable-next-line react-hooks/exhaustive-deps
289
+ }, []);
290
+ if (isLoadingSdoc) {
131
291
  return /*#__PURE__*/React.createElement(Loading, null);
132
292
  }
133
- if (isFirstLoad && errorMessage) {
293
+ if (errorMessage) {
134
294
  return /*#__PURE__*/React.createElement("div", {
135
295
  className: "error-page"
136
296
  }, /*#__PURE__*/React.createElement("div", {
@@ -143,25 +303,22 @@ var SimpleEditor = function SimpleEditor(_ref) {
143
303
  isEditMode: !isShowChanges
144
304
  }), /*#__PURE__*/React.createElement(DocOperations, {
145
305
  isShowChanges: isShowChanges,
306
+ mode: mode,
146
307
  changes: changes,
147
- toggleViewChanges: toggleViewChanges
148
- })), /*#__PURE__*/React.createElement(Content, null, isLoadingSdoc && /*#__PURE__*/React.createElement("div", {
149
- className: "w-100 h-100 d-flex align-items-center justify-content-center"
150
- }, /*#__PURE__*/React.createElement(Loading, null)), !isLoadingSdoc && errorMessage && /*#__PURE__*/React.createElement("div", {
151
- className: "error-page"
152
- }, /*#__PURE__*/React.createElement("div", {
153
- className: "error-tip"
154
- }, t(errorMessage))), !isLoadingSdoc && !errorMessage && /*#__PURE__*/React.createElement(React.Fragment, null, isShowChanges ? /*#__PURE__*/React.createElement(DiffViewer, {
155
- showToolbar: true,
156
- showOutline: true,
157
- currentContent: currentContent,
158
- lastContent: lastContent,
159
- didMountCallback: setDiffChanges
160
- }) : /*#__PURE__*/React.createElement(SDocEditor, {
161
- config: context.getEditorConfig(),
162
- document: document,
308
+ toggleViewChanges: toggleViewChanges,
309
+ publishRevision: publishRevision,
310
+ abortRebase: abortRebase
311
+ })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
163
312
  ref: editorRef,
164
- isOpenSocket: context.getSetting('isOpenSocket')
165
- })))));
313
+ document: document,
314
+ mode: mode,
315
+ setDiffChanges: setDiffChanges,
316
+ toggleViewChanges: toggleViewChanges,
317
+ rebaseEnd: rebaseEnd
318
+ }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
319
+ toggle: closeTipDialog,
320
+ submit: deleteRevision,
321
+ title: t('Tip')
322
+ }, t('Rebase_delete_no_change_revision_tip')));
166
323
  };
167
324
  export default withTranslation('sdoc-editor')(SimpleEditor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.142",
3
+ "version": "0.1.143beta2",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -362,5 +362,12 @@
362
362
  "No_changes": "No changes",
363
363
  "Title": "Title",
364
364
  "Subtitle": "Subtitle",
365
- "Link_sdoc": "Link sdoc"
365
+ "Link_sdoc": "Link sdoc",
366
+ "Keep_my_modification": "Keep my modification",
367
+ "Keep_other_modification": "Keep other's modification",
368
+ "Keep_both_modification": "Keep my modification",
369
+ "Need_rebase": "Need rebase",
370
+ "Abort": "Abort",
371
+ "Tip": "Tip",
372
+ "Rebase_delete_no_change_revision_tip": "No changes have been made in the revision, should the revision be deleted directly ?"
366
373
  }
@@ -362,5 +362,11 @@
362
362
  "No_changes": "没有变化",
363
363
  "Title": "标题",
364
364
  "Subtitle": "副标题",
365
- "Link_sdoc": "链接 sdoc"
365
+ "Link_sdoc": "链接 sdoc",
366
+ "Keep_my_modification": "保留我的更改",
367
+ "Keep_other_modification": "保留其他的更改",
368
+ "Keep_both_modification": "保留两个更改",
369
+ "Need_rebase": "需要变基",
370
+ "Abort": "中止",
371
+ "Rebase_delete_no_change_revision_tip": "修订稿未做任何改动,是否直接删除修订稿?"
366
372
  }
@@ -1,105 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
3
- import { Editor } from '@seafile/slate';
4
- import { useTranslation } from 'react-i18next';
5
- import { createDefaultEditor } from './extension';
6
- import { focusEditor } from './extension/core';
7
- import { withSocketIO } from './socket';
8
- import withNodeId from './node-id';
9
- import { PAGE_EDIT_AREA_WIDTH } from './constants';
10
- import context from '../context';
11
- import { EditorContainer, EditorContent } from './layout';
12
- import SlateEditor from './slate-editor';
13
- import InsertElementDialog from './extension/commons/insert-element-dialog';
14
- var SDocEditor = forwardRef(function (_ref, ref) {
15
- var document = _ref.document,
16
- config = _ref.config;
17
- var _useTranslation = useTranslation(),
18
- t = _useTranslation.t;
19
-
20
- // init editor
21
- var editor = useMemo(function () {
22
- var defaultEditor = createDefaultEditor();
23
- var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
- document: document,
25
- config: config
26
- }));
27
- var cursors = document.cursors;
28
- newEditor.cursors = cursors || {};
29
- newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
- newEditor.readonly = false;
31
- return newEditor;
32
- // eslint-disable-next-line react-hooks/exhaustive-deps
33
- }, []);
34
- var _useState = useState(document.children),
35
- _useState2 = _slicedToArray(_useState, 2),
36
- slateValue = _useState2[0],
37
- setSlateValue = _useState2[1];
38
-
39
- // The parent component can call the method of this component through ref
40
- useImperativeHandle(ref, function () {
41
- return {
42
- // get latest value
43
- getValue: function getValue() {
44
- return slateValue;
45
- }
46
- };
47
- }, [slateValue]);
48
-
49
- // useMount: init socket connection
50
- useEffect(function () {
51
- editor.openConnection();
52
- return function () {
53
- editor.closeConnection();
54
- };
55
- // eslint-disable-next-line react-hooks/exhaustive-deps
56
- }, []);
57
-
58
- // useMount: focus editor
59
- useEffect(function () {
60
- var timer = setTimeout(function () {
61
- var _editor$children = _slicedToArray(editor.children, 1),
62
- firstNode = _editor$children[0];
63
- if (firstNode) {
64
- var _firstNode$children = _slicedToArray(firstNode.children, 1),
65
- firstNodeFirstChild = _firstNode$children[0];
66
- if (firstNodeFirstChild) {
67
- var endOfFirstNode = Editor.end(editor, [0, 0]);
68
- var range = {
69
- anchor: endOfFirstNode,
70
- focus: endOfFirstNode
71
- };
72
- focusEditor(editor, range);
73
- }
74
- }
75
- }, 300);
76
- return function () {
77
- clearTimeout(timer);
78
- };
79
- // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, []);
81
-
82
- // useMount: reset title
83
- useEffect(function () {
84
- var isSdocRevision = context.getSetting('isSdocRevision');
85
- var originFilename = context.getSetting('originFilename');
86
- if (isSdocRevision) {
87
- window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
88
- }
89
-
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, []);
92
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
93
- editor: editor
94
- }, /*#__PURE__*/React.createElement(EditorContent, {
95
- docValue: slateValue,
96
- showOutline: true
97
- }, /*#__PURE__*/React.createElement(SlateEditor, {
98
- editor: editor,
99
- slateValue: slateValue,
100
- setSlateValue: setSlateValue
101
- }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
102
- editor: editor
103
- }));
104
- });
105
- export default SDocEditor;