@seafile/sdoc-editor 0.2.11 → 0.2.13-beta

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.
@@ -110,6 +110,12 @@ var SeafileAPI = /*#__PURE__*/function () {
110
110
  var url = 'api/v2.1/seadoc/revision/base-version-content/' + docUuid + '/';
111
111
  return this.req.get(url);
112
112
  }
113
+ }, {
114
+ key: "getPublishedRevisionContent",
115
+ value: function getPublishedRevisionContent(docUuid) {
116
+ var url = 'api/v2.1/seadoc/revision/published-content/' + docUuid + '/';
117
+ return this.req.get(url);
118
+ }
113
119
 
114
120
  // local files
115
121
  }, {
@@ -5,7 +5,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import slugid from 'slugid';
6
6
  import isHotkey from 'is-hotkey';
7
7
  import { Transforms, Node, Range, Editor } from '@seafile/slate';
8
- import { getNodeType, isLastNode, getSelectedNodeByType, generateEmptyElement } from '../../core';
8
+ import { getNodeType, isLastNode, getSelectedNodeByType, generateEmptyElement, isSelectionAtBlockStart } from '../../core';
9
9
  import { deleteBackwardByLength } from './helpers';
10
10
  import { CODE_BLOCK, PARAGRAPH, CODE_LINE, BLOCKQUOTE } from '../../constants';
11
11
  var withCodeBlock = function withCodeBlock(editor) {
@@ -13,7 +13,8 @@ var withCodeBlock = function withCodeBlock(editor) {
13
13
  insertFragment = editor.insertFragment,
14
14
  insertText = editor.insertText,
15
15
  insertBreak = editor.insertBreak,
16
- insertData = editor.insertData;
16
+ insertData = editor.insertData,
17
+ deleteBackward = editor.deleteBackward;
17
18
  var newEditor = editor;
18
19
 
19
20
  // If you enter two Spaces in quick succession, a period and a space appear (Default Settings for mac)
@@ -23,6 +24,13 @@ var withCodeBlock = function withCodeBlock(editor) {
23
24
  }
24
25
  return insertText(data);
25
26
  };
27
+ newEditor.deleteBackward = function (unit) {
28
+ var node = getSelectedNodeByType(editor, CODE_BLOCK);
29
+ if (node) {
30
+ if (isSelectionAtBlockStart(editor)) return;
31
+ }
32
+ deleteBackward(unit);
33
+ };
26
34
  newEditor.insertData = function (data) {
27
35
  // Paste a single code block element somewhere other than a code block
28
36
  if (data.types.includes('text/code-block') && !getSelectedNodeByType(editor, CODE_BLOCK)) {
@@ -1,5 +1,5 @@
1
1
  import SDocEditor from './editor/sdoc-editor';
2
- import { DiffViewer, SDocViewer } from './views';
2
+ import { DiffViewer, SDocViewer, PublishedRevisionDiffViewer } from './views';
3
3
  import SDocOutline from './outline';
4
4
  import EventBus from './utils/event-bus';
5
- export { SDocEditor, SDocViewer, SDocOutline, EventBus, DiffViewer };
5
+ export { SDocEditor, SDocViewer, SDocOutline, EventBus, DiffViewer, PublishedRevisionDiffViewer };
@@ -1,4 +1,5 @@
1
1
  import SDocViewer from './sdoc-viewer';
2
2
  import DiffViewer from './sdoc-diff-viewer';
3
3
  import RevisionDiffViewer from './revision-diff-viewer';
4
- export { SDocViewer, DiffViewer, RevisionDiffViewer };
4
+ import PublishedRevisionDiffViewer from './published-revision-diff-viewer';
5
+ export { SDocViewer, DiffViewer, RevisionDiffViewer, PublishedRevisionDiffViewer };
@@ -0,0 +1,56 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect, useState } from 'react';
3
+ import context from '../../context';
4
+ import { getDiff } from '../utils/diff';
5
+ import SDocViewer from './sdoc-viewer';
6
+ import Loading from '../../components/loading';
7
+ import '../../assets/css/diff-viewer.css';
8
+ var PublishedRevisionDiffViewer = function PublishedRevisionDiffViewer(_ref) {
9
+ var isShowChanges = _ref.isShowChanges,
10
+ revisionContent = _ref.revisionContent,
11
+ didMountCallback = _ref.didMountCallback;
12
+ var _useState = useState(true),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ isLoading = _useState2[0],
15
+ setIsLoading = _useState2[1];
16
+ var _useState3 = useState(null),
17
+ _useState4 = _slicedToArray(_useState3, 2),
18
+ diff = _useState4[0],
19
+ setDiff = _useState4[1];
20
+ useEffect(function () {
21
+ setIsLoading(true);
22
+ if (isShowChanges) {
23
+ if (diff) {
24
+ setDiff(diff);
25
+ didMountCallback && didMountCallback(diff);
26
+ setIsLoading(false);
27
+ return;
28
+ }
29
+ context.getRevisionBaseVersionContent().then(function (res) {
30
+ var baseContentString = res.data.content;
31
+ var baseContent = JSON.parse(baseContentString);
32
+ var diff = getDiff(revisionContent, baseContent);
33
+ setDiff(diff);
34
+ didMountCallback && didMountCallback(diff);
35
+ setIsLoading(false);
36
+ }).catch(function (error) {
37
+ console.log('error');
38
+ setIsLoading(false);
39
+ });
40
+ return;
41
+ }
42
+ setDiff(null);
43
+ setIsLoading(false);
44
+ }, [revisionContent, didMountCallback, isShowChanges, diff]);
45
+ if (isLoading) {
46
+ return /*#__PURE__*/React.createElement(Loading, null);
47
+ }
48
+ return /*#__PURE__*/React.createElement(SDocViewer, {
49
+ showToolbar: true,
50
+ showOutline: true,
51
+ document: {
52
+ children: diff ? diff.value : revisionContent.children
53
+ }
54
+ });
55
+ };
56
+ export default PublishedRevisionDiffViewer;
@@ -7,9 +7,9 @@ var DiffViewer = function DiffViewer(_ref) {
7
7
  var currentContent = _ref.currentContent,
8
8
  lastContent = _ref.lastContent,
9
9
  didMountCallback = _ref.didMountCallback;
10
+ context.initApi();
10
11
  var diff = getDiff(currentContent, lastContent);
11
12
  useEffect(function () {
12
- context.initApi();
13
13
  didMountCallback && didMountCallback(diff);
14
14
 
15
15
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -78,7 +78,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
78
78
 
79
79
  // solve show change view in revision editor
80
80
  var onViewChangesToggle = useCallback(function (isShowChanges) {
81
- if (isShowChanges) {
81
+ if (!isPublished && isShowChanges) {
82
82
  // The trick here is to send one more api request in order to use the same information box.
83
83
  loadDocument().then(function (revisionContent) {
84
84
  // Prevent users from switching if document contains conflicting content
@@ -94,7 +94,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
94
94
  return;
95
95
  }
96
96
  handleViewChangesToggle(isShowChanges);
97
- }, [handleViewChangesToggle, loadDocument, t]);
97
+ }, [handleViewChangesToggle, loadDocument, t, isPublished]);
98
98
 
99
99
  // publish revision
100
100
  var publishRevision = useCallback(function () {
@@ -135,9 +135,10 @@ var RevisionsDialog = function RevisionsDialog(_ref) {
135
135
  updateRevisionsCount(newRevisions.length);
136
136
  setRevisions(newRevisions);
137
137
  closeDeleteTipDialog();
138
- toaster.success(t('Delete_Successfully'));
138
+ toaster.success(t('Revision_deleted'));
139
139
  }).catch(function (error) {
140
- toaster.danger(t('Delete_failed'));
140
+ var errorMessage = getErrorMsg(error);
141
+ toaster.danger(t(errorMessage));
141
142
  });
142
143
 
143
144
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/dist/context.js CHANGED
@@ -216,6 +216,12 @@ var Context = /*#__PURE__*/function () {
216
216
  var docUuid = this.getSetting('docUuid');
217
217
  return this.api.getRevisionBaseVersionContent(docUuid);
218
218
  }
219
+ }, {
220
+ key: "getPublishedRevisionContent",
221
+ value: function getPublishedRevisionContent() {
222
+ var docUuid = this.getSetting('docUuid');
223
+ return this.api.getPublishedRevisionContent(docUuid);
224
+ }
219
225
 
220
226
  // local files
221
227
  }, {
package/dist/index.js CHANGED
@@ -3,4 +3,5 @@ import { EXTERNAL_EVENT } from './constants';
3
3
  import SimpleEditor from './pages/simple-editor';
4
4
  import SimpleViewer from './pages/simple-viewer';
5
5
  import DiffViewer from './pages/diff-viewer';
6
- export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer };
6
+ import PublishedRevisionViewer from './pages/published-revision-viewer';
7
+ export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer, PublishedRevisionViewer };
@@ -0,0 +1,96 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useCallback, useEffect, useState } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Loading from '../components/loading';
5
+ import DocInfo from '../components/doc-info';
6
+ import DocOperations from '../components/doc-operations';
7
+ import Layout, { Header, Content } from '../layout';
8
+ import context from '../context';
9
+ import ErrorBoundary from './error-boundary';
10
+ import { PublishedRevisionDiffViewer } from '../basic-sdk';
11
+ import { resetWebTitleAndURL } from '../utils';
12
+ import '../assets/css/simple-editor.css';
13
+ var PublishedRevisionViewer = function PublishedRevisionViewer(_ref) {
14
+ var isStarred = _ref.isStarred,
15
+ isDraft = _ref.isDraft;
16
+ context.initApi();
17
+ var _useTranslation = useTranslation(),
18
+ t = _useTranslation.t;
19
+ var _useState = useState(true),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ isFirstLoading = _useState2[0],
22
+ setIsFirstLoading = _useState2[1];
23
+ var _useState3 = useState(''),
24
+ _useState4 = _slicedToArray(_useState3, 2),
25
+ errorMessage = _useState4[0],
26
+ setErrorMessage = _useState4[1];
27
+ var _useState5 = useState(false),
28
+ _useState6 = _slicedToArray(_useState5, 2),
29
+ isShowChanges = _useState6[0],
30
+ setShowChanges = _useState6[1];
31
+ var _useState7 = useState([]),
32
+ _useState8 = _slicedToArray(_useState7, 2),
33
+ changes = _useState8[0],
34
+ setChanges = _useState8[1];
35
+ var _useState9 = useState({}),
36
+ _useState10 = _slicedToArray(_useState9, 2),
37
+ document = _useState10[0],
38
+ setDocument = _useState10[1];
39
+
40
+ // useMount: reset title
41
+ useEffect(function () {
42
+ resetWebTitleAndURL(t);
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, []);
45
+ useEffect(function () {
46
+ context.getPublishedRevisionContent().then(function (res) {
47
+ var revisionContentString = res.data.content;
48
+ var document = JSON.parse(revisionContentString);
49
+ setDocument(document);
50
+ setIsFirstLoading(false);
51
+ }).catch(function (error) {
52
+ // eslint-disable-next-line
53
+ console.log(error);
54
+ var errorMessage = 'Load_doc_content_error';
55
+ if (error && error.response) {
56
+ var _ref2 = error.response.data || {},
57
+ error_type = _ref2.error_type;
58
+ if (error_type === 'content_invalid') {
59
+ errorMessage = 'Sdoc_format_invalid';
60
+ }
61
+ }
62
+ setErrorMessage(errorMessage);
63
+ setIsFirstLoading(false);
64
+ });
65
+ }, []);
66
+ var setDiffChanges = useCallback(function (diff) {
67
+ setChanges((diff === null || diff === void 0 ? void 0 : diff.changes) || []);
68
+ }, []);
69
+ var handleViewChangesToggle = useCallback(function (isShowChanges) {
70
+ setShowChanges(isShowChanges);
71
+ }, []);
72
+ if (isFirstLoading) {
73
+ return /*#__PURE__*/React.createElement(Loading, null);
74
+ }
75
+ if (errorMessage) {
76
+ return /*#__PURE__*/React.createElement("div", {
77
+ className: "error-page"
78
+ }, /*#__PURE__*/React.createElement("div", {
79
+ className: "error-tip"
80
+ }, t(errorMessage)));
81
+ }
82
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, {
83
+ isStarred: isStarred,
84
+ isDraft: isDraft,
85
+ isEditMode: false
86
+ }), /*#__PURE__*/React.createElement(DocOperations, {
87
+ isShowChanges: isShowChanges,
88
+ changes: changes,
89
+ handleViewChangesToggle: handleViewChangesToggle
90
+ })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(PublishedRevisionDiffViewer, {
91
+ isShowChanges: isShowChanges,
92
+ revisionContent: document,
93
+ didMountCallback: setDiffChanges
94
+ }))));
95
+ };
96
+ export default PublishedRevisionViewer;
@@ -1,4 +1,3 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
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';
@@ -8,11 +7,10 @@ import DocOperations from '../components/doc-operations';
8
7
  import Layout, { Header, Content } from '../layout';
9
8
  import context from '../context';
10
9
  import ErrorBoundary from './error-boundary';
11
- import { REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
12
- import toaster from '../components/toast';
13
10
  import { SDocEditor } from '../basic-sdk';
14
11
  import { RevisionDiffViewer } from '../basic-sdk/views';
15
12
  import { useDocument } from '../hooks/use-document';
13
+ import { resetWebTitleAndURL } from '../utils';
16
14
  import '../assets/css/simple-editor.css';
17
15
  var SimpleEditor = function SimpleEditor(_ref) {
18
16
  var isStarred = _ref.isStarred,
@@ -41,40 +39,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
41
39
 
42
40
  // useMount: reset title
43
41
  useEffect(function () {
44
- var isSdocRevision = context.getSetting('isSdocRevision');
45
- var originFilename = context.getSetting('originFilename');
46
- if (isSdocRevision) {
47
- window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
48
-
49
- // show revision created success info
50
- var url = new URL(window.location.href);
51
- var searchParams = new URLSearchParams(url.search);
52
- if (!searchParams.has(REVISION_FIRST_LOAD_KEY)) return;
53
- var firstLoadValue = searchParams.get(REVISION_FIRST_LOAD_KEY);
54
- if (firstLoadValue === REVISION_FIRST_LOAD_VALUE) {
55
- var revisionId = context.getSetting('revisionId');
56
- toaster.success(t('Revision_created', {
57
- id: revisionId
58
- }));
59
- searchParams.delete(REVISION_FIRST_LOAD_KEY);
60
- }
61
- var newParamsString = '';
62
- var _iterator = _createForOfIteratorHelper(searchParams.entries()),
63
- _step;
64
- try {
65
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
- var item = _step.value;
67
- newParamsString = newParamsString + "&".concat(item[0], "=").concat(item[1]);
68
- }
69
- } catch (err) {
70
- _iterator.e(err);
71
- } finally {
72
- _iterator.f();
73
- }
74
- var newURL = "".concat(url.origin).concat(url.pathname).concat(newParamsString ? '/?' + newParamsString : '');
75
- window.history.replaceState(null, null, newURL);
76
- }
77
-
42
+ resetWebTitleAndURL(t);
78
43
  // eslint-disable-next-line react-hooks/exhaustive-deps
79
44
  }, []);
80
45
  var setDiffChanges = useCallback(function (diff) {
@@ -1,5 +1,9 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
1
2
  import DateUtils from './date-utils';
2
3
  import LocalStorage from './local-storage-utils';
4
+ import context from '../context';
5
+ import { REVISION_FIRST_LOAD_KEY, REVISION_FIRST_LOAD_VALUE } from '../constants';
6
+ import toaster from '../components/toast';
3
7
  export var getDirPath = function getDirPath(path) {
4
8
  var dir = path.slice(0, path.lastIndexOf('/'));
5
9
  if (dir === '') {
@@ -45,4 +49,38 @@ export var isMac = function isMac() {
45
49
  return platform === 'Mac68K' || platform === 'MacPPC' || platform === 'Macintosh' || platform === 'MacIntel';
46
50
  };
47
51
  export var isMobile = typeof window !== 'undefined' && (window.innerWidth < 768 || navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null);
52
+ export var resetWebTitleAndURL = function resetWebTitleAndURL(t) {
53
+ var isSdocRevision = context.getSetting('isSdocRevision');
54
+ var originFilename = context.getSetting('originFilename');
55
+ if (!isSdocRevision) return;
56
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
57
+
58
+ // show revision created success info
59
+ var url = new URL(window.location.href);
60
+ var searchParams = new URLSearchParams(url.search);
61
+ if (!searchParams.has(REVISION_FIRST_LOAD_KEY)) return;
62
+ var firstLoadValue = searchParams.get(REVISION_FIRST_LOAD_KEY);
63
+ if (firstLoadValue === REVISION_FIRST_LOAD_VALUE) {
64
+ var revisionId = context.getSetting('revisionId');
65
+ toaster.success(t('Revision_created', {
66
+ id: revisionId
67
+ }));
68
+ searchParams.delete(REVISION_FIRST_LOAD_KEY);
69
+ }
70
+ var newParamsString = '';
71
+ var _iterator = _createForOfIteratorHelper(searchParams.entries()),
72
+ _step;
73
+ try {
74
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
75
+ var item = _step.value;
76
+ newParamsString = newParamsString + "&".concat(item[0], "=").concat(item[1]);
77
+ }
78
+ } catch (err) {
79
+ _iterator.e(err);
80
+ } finally {
81
+ _iterator.f();
82
+ }
83
+ var newURL = "".concat(url.origin).concat(url.pathname).concat(newParamsString ? '/?' + newParamsString : '');
84
+ window.history.replaceState(null, null, newURL);
85
+ };
48
86
  export { DateUtils, LocalStorage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.2.11",
3
+ "version": "0.2.13beta",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Smazání se nezdařilo"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Löschen fehlgeschlagen"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Delete failed"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Eliminar falló"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Échec de la suppression"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "Image border",
386
386
  "Delete_revision": "Delete revision",
387
387
  "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Rimozione fallita"
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -383,8 +383,7 @@
383
383
  "Block": "Блок",
384
384
  "Full_screen_mode": "Полноэкранный режим",
385
385
  "Image_border": "Граница изображения",
386
- "Delete_revision": "Delete revision",
387
- "Delete_tip": "Are you sure you want to delete {{content}} ?",
388
- "Delete_Successfully": "Delete Successfully",
389
- "Delete_failed": "Не удалось удалить"
386
+ "Delete_revision": "Удалить редакцию",
387
+ "Delete_tip": "Вы уверены, что хотите удалить {{content}} ?",
388
+ "Revision_deleted": "Revision deleted"
390
389
  }
@@ -385,6 +385,5 @@
385
385
  "Image_border": "图片边框",
386
386
  "Delete_revision": "删除修订稿",
387
387
  "Delete_tip": "确定要删除 {{content}} 吗?",
388
- "Delete_Successfully": "删除成功",
389
- "Delete_failed": "删除失败"
388
+ "Revision_deleted": "修订稿已删除"
390
389
  }