@seafile/sdoc-editor 0.1.68 → 0.1.69

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.
@@ -35,6 +35,12 @@ var SeafileAPI = /*#__PURE__*/function () {
35
35
  var url = '/api/v2.1/seadoc/download-image/' + docUuid + '/' + encodeURIComponent(imageName);
36
36
  return this.req.get(url);
37
37
  }
38
+ }, {
39
+ key: "sdocPublishRevision",
40
+ value: function sdocPublishRevision(docUuid) {
41
+ var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
42
+ return this.req.post(url);
43
+ }
38
44
  }]);
39
45
  return SeafileAPI;
40
46
  }();
@@ -3,17 +3,3 @@
3
3
  margin: 0 -5px;
4
4
  overflow: hidden;
5
5
  }
6
-
7
- .sdoc-diff-added {
8
- background-color: #e6ffed;
9
- }
10
-
11
- .sdoc-diff-removed {
12
- background-color: #ffeef0;
13
- }
14
-
15
- .sdoc-diff-modify {
16
- padding-left: 2px;
17
- margin-left: -5px;
18
- border-left: 3px solid #f9c513;
19
- }
@@ -5,6 +5,7 @@
5
5
 
6
6
  .sdoc-editor-page-header .doc-info .doc-name {
7
7
  font-size: 18px;
8
+ font-weight: 700;
8
9
  color: #212529;
9
10
  }
10
11
 
@@ -24,3 +25,7 @@
24
25
  .sdoc-editor-page-header .doc-info .sdoc-link {
25
26
  font-size: 14px;
26
27
  }
28
+
29
+ .sdoc-editor-page-header .doc-state {
30
+ font-size: 0.8125rem;
31
+ }
@@ -58,7 +58,7 @@ var CommentItem = function CommentItem(_ref) {
58
58
  onMouseLeave: onMouseLeave
59
59
  }, /*#__PURE__*/React.createElement("div", {
60
60
  className: "comment-header"
61
- }, /*#__PURE__*/React.createElement("span", {
61
+ }, /*#__PURE__*/React.createElement("div", {
62
62
  className: "comment-author"
63
63
  }, /*#__PURE__*/React.createElement("span", {
64
64
  className: "comment-author__avatar"
@@ -67,7 +67,7 @@ var CommentItem = function CommentItem(_ref) {
67
67
  src: comment.avatar_url
68
68
  })), /*#__PURE__*/React.createElement("span", {
69
69
  className: "comment-author__name"
70
- }, comment.user_name)), isActive && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
70
+ }, comment.user_name)), isActive && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
71
71
  id: menuId,
72
72
  className: "comment-operation"
73
73
  }, /*#__PURE__*/React.createElement("i", {
@@ -61,7 +61,8 @@
61
61
  background: #fafafa;
62
62
  }
63
63
 
64
- .sdoc-comment-container .comment-item .comment-header {
64
+ .sdoc-comment-container .comment-item .comment-header,
65
+ .sdoc-comment-container .comment-item .comment-author {
65
66
  display: flex;
66
67
  justify-content: space-between;
67
68
  align-items: center;
@@ -75,6 +76,8 @@
75
76
 
76
77
  .sdoc-comment-container .comment-header .comment-author__avatar {
77
78
  margin-right: 10px;
79
+ display: flex;
80
+ align-items: center;
78
81
  }
79
82
 
80
83
  .sdoc-comment-container .comment-header .comment-author__avatar img {
@@ -89,6 +92,7 @@
89
92
  }
90
93
 
91
94
  .sdoc-comment-container .comment-header .comment-operation {
95
+ line-height: 20px;
92
96
  font-size: 20px;
93
97
  color: rgb(70, 77, 90);
94
98
  width: 20px;
@@ -28,7 +28,7 @@ var TableRoot = function TableRoot(_ref) {
28
28
  'scroll position-relative': allWidth > editor.width
29
29
  }),
30
30
  style: _objectSpread(_objectSpread({}, attributes.style), {}, {
31
- maxWidth: editor.width
31
+ maxWidth: editor.width ? editor.width : '100%'
32
32
  })
33
33
  }), /*#__PURE__*/React.createElement("div", {
34
34
  className: classnames('sdoc-table-scroll-wrapper', {
@@ -1,5 +1,5 @@
1
1
  import SDocEditor from './editor';
2
- import SDocViewer from './viewer';
2
+ import { DiffViewer, SDocViewer } from './views';
3
3
  import SDocOutline from './outline';
4
4
  import EventBus from './utils/event-bus';
5
- export { SDocEditor, SDocViewer, SDocOutline, EventBus };
5
+ export { SDocEditor, SDocViewer, SDocOutline, EventBus, DiffViewer };
@@ -1,9 +1,9 @@
1
1
  import React, { useCallback, useEffect } from 'react';
2
- import { renderLeaf, renderElement } from '../../basic-sdk/extension';
3
- import { getDiff } from '../../basic-sdk/utils/diff';
2
+ import { renderLeaf, renderElement } from '../extension';
3
+ import { getDiff } from '../utils/diff';
4
4
  import context from '../../context';
5
- import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../../basic-sdk/extension/constants';
6
- import { SDocViewer } from '../../basic-sdk';
5
+ import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants';
6
+ import SDocViewer from './viewer';
7
7
  import '../../assets/css/diff-viewer.css';
8
8
  var DiffViewer = function DiffViewer(_ref) {
9
9
  var currentContent = _ref.currentContent,
@@ -27,8 +27,8 @@ var DiffViewer = function DiffViewer(_ref) {
27
27
  var type = element.type;
28
28
  if (type === ELEMENT_TYPE.IMAGE && (element.ADD || element.DELETE)) {
29
29
  var style = element.ADD ? ADDED_STYLE : DELETED_STYLE;
30
- return /*#__PURE__*/React.createElement("div", {
31
- className: "p-1",
30
+ return /*#__PURE__*/React.createElement("span", {
31
+ className: "d-inline-block p-1",
32
32
  style: {
33
33
  backgroundColor: style.background_color,
34
34
  width: 'fit-content',
@@ -0,0 +1,3 @@
1
+ import DiffViewer from './diff-viewer';
2
+ import SDocViewer from './viewer';
3
+ export { DiffViewer, SDocViewer };
@@ -1,12 +1,12 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useRef, useEffect, useState } from 'react';
3
3
  import { Editable, Slate } from '@seafile/slate-react';
4
- import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from './extension';
5
- import { withSocketIO } from './socket';
6
- import withNodeId from './node-id';
7
- import './assets/css/layout.css';
8
- import './assets/css/sdoc-editor-plugins.css';
9
- import { generateDefaultDocContent } from '../utils';
4
+ import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from '../extension';
5
+ import { withSocketIO } from '../socket';
6
+ import withNodeId from '../node-id';
7
+ import '../assets/css/layout.css';
8
+ import '../assets/css/sdoc-editor-plugins.css';
9
+ import { generateDefaultDocContent } from '../../utils';
10
10
  var SDocViewer = function SDocViewer(_ref) {
11
11
  var isOpenSocket = _ref.isOpenSocket,
12
12
  document = _ref.document,
@@ -1,61 +1,57 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React from 'react';
1
+ import React, { useCallback } from 'react';
6
2
  import TipMessage from '../tip-message';
7
3
  import { withTranslation } from 'react-i18next';
8
4
  import context from '../../context';
9
5
  import { EventBus } from '../../basic-sdk';
10
6
  import { EXTERNAL_EVENT } from '../../constants';
11
- var DocInfo = /*#__PURE__*/function (_React$Component) {
12
- _inherits(DocInfo, _React$Component);
13
- var _super = _createSuper(DocInfo);
14
- function DocInfo() {
15
- var _this;
16
- _classCallCheck(this, DocInfo);
17
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
- args[_key] = arguments[_key];
19
- }
20
- _this = _super.call.apply(_super, [this].concat(args));
21
- _this.onInternalLinkClick = function () {
22
- var eventBus = EventBus.getInstance();
23
- eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK);
24
- };
25
- _this.toggleStar = function () {
26
- var eventBus = EventBus.getInstance();
27
- eventBus.dispatch(EXTERNAL_EVENT.TOGGLE_STAR);
28
- };
29
- return _this;
7
+ import { DateUtils } from '../../utils';
8
+ var DocInfo = function DocInfo(_ref) {
9
+ var t = _ref.t,
10
+ isStarred = _ref.isStarred;
11
+ var onInternalLinkClick = useCallback(function () {
12
+ var eventBus = EventBus.getInstance();
13
+ eventBus.dispatch(EXTERNAL_EVENT.INTERNAL_LINK_CLICK);
14
+ }, []);
15
+ var toggleStar = useCallback(function () {
16
+ var eventBus = EventBus.getInstance();
17
+ eventBus.dispatch(EXTERNAL_EVENT.TOGGLE_STAR);
18
+ }, []);
19
+ var isSdocRevision = context.getSetting('isSdocRevision');
20
+ var docName = context.getSetting('docName');
21
+ var _context$getSettings = context.getSettings(),
22
+ isShowInternalLink = _context$getSettings.isShowInternalLink,
23
+ isStarIconShown = _context$getSettings.isStarIconShown;
24
+ var docInfo = /*#__PURE__*/React.createElement(React.Fragment, null, isStarIconShown && /*#__PURE__*/React.createElement("button", {
25
+ className: "doc-icon sdocfont ".concat(isStarred ? 'sdoc-starred' : 'sdoc-unstarred', " border-0 p-0 bg-transparent"),
26
+ title: isStarred ? t('Starred') : t('Unstarred'),
27
+ "aria-label": isStarred ? t('Unstar') : t('Star'),
28
+ onClick: toggleStar
29
+ }), isShowInternalLink && /*#__PURE__*/React.createElement("span", {
30
+ className: "doc-icon"
31
+ }, /*#__PURE__*/React.createElement("span", {
32
+ className: "internal-link sdocfont sdoc-link",
33
+ title: t('Internal_link'),
34
+ onClick: onInternalLinkClick
35
+ })), /*#__PURE__*/React.createElement(TipMessage, null));
36
+ if (!isSdocRevision) {
37
+ return /*#__PURE__*/React.createElement("div", {
38
+ className: "doc-info"
39
+ }, /*#__PURE__*/React.createElement("div", {
40
+ className: "doc-name"
41
+ }, docName), docInfo);
30
42
  }
31
- _createClass(DocInfo, [{
32
- key: "render",
33
- value: function render() {
34
- var _this$props = this.props,
35
- t = _this$props.t,
36
- isStarred = _this$props.isStarred;
37
- var docName = context.getSetting('docName');
38
- var _context$getSettings = context.getSettings(),
39
- isShowInternalLink = _context$getSettings.isShowInternalLink,
40
- isStarIconShown = _context$getSettings.isStarIconShown;
41
- return /*#__PURE__*/React.createElement("div", {
42
- className: "doc-info"
43
- }, /*#__PURE__*/React.createElement("div", {
44
- className: "doc-name"
45
- }, docName), isStarIconShown && /*#__PURE__*/React.createElement("button", {
46
- className: "doc-icon sdocfont ".concat(isStarred ? 'sdoc-starred' : 'sdoc-unstarred', " border-0 p-0 bg-transparent"),
47
- title: isStarred ? t('Starred') : t('Unstarred'),
48
- "aria-label": isStarred ? t('Unstar') : t('Star'),
49
- onClick: this.toggleStar
50
- }), isShowInternalLink && /*#__PURE__*/React.createElement("span", {
51
- className: "doc-icon"
52
- }, /*#__PURE__*/React.createElement("span", {
53
- className: "internal-link sdocfont sdoc-link",
54
- title: t('Internal_link'),
55
- onClick: this.onInternalLinkClick
56
- })), /*#__PURE__*/React.createElement(TipMessage, null));
57
- }
58
- }]);
59
- return DocInfo;
60
- }(React.Component);
43
+ var revisionCreatedAt = context.getSetting('revisionCreatedAt');
44
+ var oldDocName = context.getSetting('originFilename');
45
+ return /*#__PURE__*/React.createElement("div", {
46
+ className: "doc-info d-flex flex-column"
47
+ }, /*#__PURE__*/React.createElement("div", {
48
+ className: "doc-name-container d-flex align-items-center justify-content-start w-100"
49
+ }, /*#__PURE__*/React.createElement("div", {
50
+ className: "doc-name"
51
+ }, oldDocName), docInfo), /*#__PURE__*/React.createElement("div", {
52
+ className: "doc-state"
53
+ }, /*#__PURE__*/React.createElement("span", {
54
+ className: "mr-2"
55
+ }, t('Revision')), /*#__PURE__*/React.createElement("span", null, DateUtils.format(revisionCreatedAt, 'YYYY-MM-DD HH:MM'))));
56
+ };
61
57
  export default withTranslation('sdoc-editor')(DocInfo);
@@ -0,0 +1,23 @@
1
+ import React, { useCallback } from 'react';
2
+ import context from '../../context';
3
+ var HistoryOperation = function HistoryOperation() {
4
+ var docPerm = context.getSetting('docPerm');
5
+ var historyURL = context.getSetting('historyURL');
6
+ var isSdocRevision = context.getSetting('isSdocRevision');
7
+ var toggleHistory = useCallback(function (event) {
8
+ event.stopPropagation();
9
+ event.nativeEvent.stopImmediatePropagation();
10
+ window.location.href = historyURL;
11
+
12
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13
+ }, []);
14
+ if (docPerm !== 'rw' || !historyURL) return null;
15
+ if (isSdocRevision) return null;
16
+ return /*#__PURE__*/React.createElement("span", {
17
+ className: "op-item",
18
+ onClick: toggleHistory
19
+ }, /*#__PURE__*/React.createElement("i", {
20
+ className: "sdocfont sdoc-history"
21
+ }));
22
+ };
23
+ export default HistoryOperation;
@@ -1,81 +1,17 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Fragment } from 'react';
6
- import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
7
- import CollaboratorsOperation from './collaborators-operation';
8
- import context from '../../context';
1
+ import React from 'react';
9
2
  import { withTranslation } from 'react-i18next';
3
+ import RevisionOperations from './revision-operations';
4
+ import HistoryOperation from './history-operation';
5
+ import CollaboratorsOperation from './collaborators-operation';
6
+ import MoreOperations from './more-operations';
10
7
  import './style.css';
11
- var DocOperations = /*#__PURE__*/function (_React$Component) {
12
- _inherits(DocOperations, _React$Component);
13
- var _super = _createSuper(DocOperations);
14
- function DocOperations(props) {
15
- var _this;
16
- _classCallCheck(this, DocOperations);
17
- _this = _super.call(this, props);
18
- _this.toggleDropdown = function () {
19
- _this.setState({
20
- isDropdownOpen: !_this.state.isDropdownOpen
21
- });
22
- };
23
- _this.toggleHistory = function (event) {
24
- event.stopPropagation();
25
- event.nativeEvent.stopImmediatePropagation();
26
- var historyURL = context.getSetting('historyURL');
27
- window.location.href = historyURL;
28
- };
29
- _this.state = {
30
- isDropdownOpen: false
31
- };
32
- return _this;
33
- }
34
- _createClass(DocOperations, [{
35
- key: "render",
36
- value: function render() {
37
- var t = this.props.t;
38
- var isDropdownOpen = this.state.isDropdownOpen;
39
- var docPerm = context.getSetting('docPerm');
40
- var historyURL = context.getSetting('historyURL');
41
- var parentFolderURL = context.getSetting('parentFolderURL');
42
- var dropdownItems = [];
43
- if (parentFolderURL) {
44
- dropdownItems.push({
45
- text: t('Open_parent_folder'),
46
- URL: parentFolderURL
47
- });
48
- }
49
- return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
50
- className: "doc-ops"
51
- }, /*#__PURE__*/React.createElement("span", {
52
- className: "op-item"
53
- }, /*#__PURE__*/React.createElement("i", {
54
- className: "sdocfont sdoc-share"
55
- })), docPerm === 'rw' && historyURL && /*#__PURE__*/React.createElement("span", {
56
- className: "op-item",
57
- onClick: this.toggleHistory
58
- }, /*#__PURE__*/React.createElement("i", {
59
- className: "sdocfont sdoc-history"
60
- })), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), dropdownItems.length > 0 && /*#__PURE__*/React.createElement(Dropdown, {
61
- isOpen: isDropdownOpen,
62
- toggle: this.toggleDropdown
63
- }, /*#__PURE__*/React.createElement(DropdownToggle, {
64
- className: "op-item",
65
- tag: "span"
66
- }, /*#__PURE__*/React.createElement("i", {
67
- className: "sdocfont sdoc-menu"
68
- })), /*#__PURE__*/React.createElement(DropdownMenu, {
69
- right: true
70
- }, dropdownItems.map(function (item, index) {
71
- return /*#__PURE__*/React.createElement(DropdownItem, {
72
- tag: "a",
73
- href: item.URL,
74
- key: index
75
- }, item.text);
76
- })))));
77
- }
78
- }]);
79
- return DocOperations;
80
- }(React.Component);
8
+ var DocOperations = function DocOperations() {
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ className: "doc-ops"
11
+ }, /*#__PURE__*/React.createElement(RevisionOperations, null), /*#__PURE__*/React.createElement("span", {
12
+ className: "op-item"
13
+ }, /*#__PURE__*/React.createElement("i", {
14
+ className: "sdocfont sdoc-share"
15
+ })), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), /*#__PURE__*/React.createElement(MoreOperations, null));
16
+ };
81
17
  export default withTranslation('sdoc-editor')(DocOperations);
@@ -0,0 +1,44 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useCallback, useState } from 'react';
3
+ import { withTranslation } from 'react-i18next';
4
+ import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
5
+ import context from '../../context';
6
+ var MoreOperations = function MoreOperations(_ref) {
7
+ var t = _ref.t;
8
+ var _useState = useState(false),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ isDropdownOpen = _useState2[0],
11
+ setIsDropdownOpen = _useState2[1];
12
+ var toggleDropdown = useCallback(function (isDropdownOpen) {
13
+ setIsDropdownOpen(!isDropdownOpen);
14
+ }, []);
15
+ var parentFolderURL = context.getSetting('parentFolderURL');
16
+ var dropdownItems = [];
17
+ if (parentFolderURL) {
18
+ dropdownItems.push({
19
+ text: t('Open_parent_folder'),
20
+ URL: parentFolderURL
21
+ });
22
+ }
23
+ if (dropdownItems.length === 0) return null;
24
+ return /*#__PURE__*/React.createElement(Dropdown, {
25
+ isOpen: isDropdownOpen,
26
+ toggle: function toggle() {
27
+ return toggleDropdown(isDropdownOpen);
28
+ }
29
+ }, /*#__PURE__*/React.createElement(DropdownToggle, {
30
+ className: "op-item",
31
+ tag: "span"
32
+ }, /*#__PURE__*/React.createElement("i", {
33
+ className: "sdocfont sdoc-menu"
34
+ })), /*#__PURE__*/React.createElement(DropdownMenu, {
35
+ right: true
36
+ }, dropdownItems.map(function (item, index) {
37
+ return /*#__PURE__*/React.createElement(DropdownItem, {
38
+ tag: "a",
39
+ href: item.URL,
40
+ key: index
41
+ }, item.text);
42
+ })));
43
+ };
44
+ export default withTranslation('sdoc-editor')(MoreOperations);
@@ -0,0 +1,42 @@
1
+ import React, { useCallback } from 'react';
2
+ import { Button } from 'reactstrap';
3
+ import { withTranslation } from 'react-i18next';
4
+ import context from '../../context';
5
+ import toaster from '../../components/toast';
6
+ var RevisionOperations = function RevisionOperations(_ref) {
7
+ var t = _ref.t;
8
+ var isSdocRevision = context.getSetting('isSdocRevision');
9
+ var revisionURL = context.getSetting('revisionURL');
10
+ var isPublished = context.getSetting('isPublished');
11
+ var repoID = context.getSetting('repoID');
12
+ var siteRoot = context.getSetting('siteRoot');
13
+ var viewChanges = useCallback(function (event) {
14
+ event.stopPropagation();
15
+ event.nativeEvent.stopImmediatePropagation();
16
+ window.location.href = revisionURL;
17
+
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ }, []);
20
+ var publishRevision = useCallback(function (event) {
21
+ event.stopPropagation();
22
+ event.nativeEvent.stopImmediatePropagation();
23
+ context.publishSdocRevision().then(function (res) {
24
+ var origin_file_path = res.data.origin_file_path;
25
+ window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
26
+ }).catch(function (error) {
27
+ toaster.danger(t('Error'));
28
+ });
29
+
30
+ // eslint-disable-next-line react-hooks/exhaustive-deps
31
+ }, []);
32
+ if (!isSdocRevision) return null;
33
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isPublished && revisionURL && /*#__PURE__*/React.createElement(Button, {
34
+ color: "success",
35
+ className: "mr-4",
36
+ onClick: viewChanges
37
+ }, t('View_changes')), !isPublished && /*#__PURE__*/React.createElement(Button, {
38
+ color: "success",
39
+ onClick: publishRevision
40
+ }, t('Publish')));
41
+ };
42
+ export default withTranslation('sdoc-editor')(RevisionOperations);
package/dist/context.js CHANGED
@@ -101,6 +101,8 @@ var Context = /*#__PURE__*/function () {
101
101
  avatar_url: avatarURL
102
102
  };
103
103
  }
104
+
105
+ // comments
104
106
  }, {
105
107
  key: "listComments",
106
108
  value: function listComments() {
@@ -121,6 +123,14 @@ var Context = /*#__PURE__*/function () {
121
123
  value: function updateComment(commentId, newComment) {
122
124
  return this.sdocServerApi.updateComment(commentId, newComment);
123
125
  }
126
+
127
+ // revision
128
+ }, {
129
+ key: "publishSdocRevision",
130
+ value: function publishSdocRevision() {
131
+ var docUuid = this.getSetting('docUuid');
132
+ return this.api.sdocPublishRevision(docUuid);
133
+ }
124
134
  }]);
125
135
  return Context;
126
136
  }();
@@ -4,7 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React, { Component } from 'react';
6
6
  import HistoryVersionViewer from './history-version-viewer';
7
- import DiffViewer from './diff-viewer';
7
+ import { DiffViewer } from '../../basic-sdk';
8
8
  import context from '../../context';
9
9
  var Index = /*#__PURE__*/function (_Component) {
10
10
  _inherits(Index, _Component);
@@ -0,0 +1,86 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ var DateUtils = /*#__PURE__*/function () {
4
+ function DateUtils() {
5
+ _classCallCheck(this, DateUtils);
6
+ }
7
+ _createClass(DateUtils, null, [{
8
+ key: "format",
9
+ value:
10
+ /**
11
+ * return the formatted date with target format.
12
+ * @param {string|date object} date
13
+ * @param {string} format
14
+ * @returns formatted date
15
+ */
16
+ function format(date, _format) {
17
+ var dateObject = this.getValidDate(date);
18
+ if (!dateObject) {
19
+ return '';
20
+ }
21
+ var upperCaseFormat = _format && _format.toUpperCase();
22
+ var year = dateObject.getFullYear();
23
+ var month = dateObject.getMonth() + 1;
24
+ var day = dateObject.getDate();
25
+ var displayMonth = month < 10 ? "0".concat(month) : month;
26
+ var displayDay = day < 10 ? "0".concat(day) : day;
27
+ switch (upperCaseFormat) {
28
+ case 'YYYY-MM-DD HH:MM:SS':
29
+ {
30
+ var hours = dateObject.getHours();
31
+ var minutes = dateObject.getMinutes();
32
+ var seconds = dateObject.getSeconds();
33
+ var disPlayHours = hours < 10 ? "0".concat(hours) : hours;
34
+ var disPlayMinutes = minutes < 10 ? "0".concat(minutes) : minutes;
35
+ var disPlaySeconds = seconds < 10 ? "0".concat(seconds) : seconds;
36
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay, " ").concat(disPlayHours, ":").concat(disPlayMinutes, ":").concat(disPlaySeconds);
37
+ }
38
+ case 'YYYY-MM-DD HH:MM':
39
+ {
40
+ var _hours = dateObject.getHours();
41
+ var _minutes = dateObject.getMinutes();
42
+ var _disPlayHours = _hours < 10 ? "0".concat(_hours) : _hours;
43
+ var _disPlayMinutes = _minutes < 10 ? "0".concat(_minutes) : _minutes;
44
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay, " ").concat(_disPlayHours, ":").concat(_disPlayMinutes);
45
+ }
46
+ default:
47
+ {
48
+ return "".concat(year, "-").concat(displayMonth, "-").concat(displayDay);
49
+ }
50
+ }
51
+ }
52
+ }, {
53
+ key: "isValidDateObject",
54
+ value: function isValidDateObject(dateObject) {
55
+ return dateObject instanceof Date && !isNaN(dateObject.getTime());
56
+ }
57
+ }, {
58
+ key: "getValidDate",
59
+ value: function getValidDate(date) {
60
+ if (!date) {
61
+ return null;
62
+ }
63
+ var isDateTypeString = typeof date === 'string';
64
+ var dateString = date;
65
+ var dateObject = date;
66
+ if (isDateTypeString) {
67
+ if (dateString.split(' ').length > 1 || dateString.includes('T')) {
68
+ dateObject = new Date(date);
69
+ } else {
70
+ // given date is without time precision
71
+ dateString = "".concat(date, " 00:00:00");
72
+ dateObject = new Date(dateString);
73
+ }
74
+ }
75
+ if (this.isValidDateObject(dateObject)) return dateObject;
76
+ if (!isDateTypeString) return null;
77
+
78
+ //ios phone and safari browser not support use '2021-09-10 12:30', support '2021/09/10 12:30'
79
+ dateObject = new Date(dateString.replace(/-/g, '/'));
80
+ if (this.isValidDateObject(dateObject)) return dateObject;
81
+ return null;
82
+ }
83
+ }]);
84
+ return DateUtils;
85
+ }();
86
+ export default DateUtils;
@@ -1,3 +1,4 @@
1
+ import DateUtils from './date-utils';
1
2
  export var getDirPath = function getDirPath(path) {
2
3
  var dir = path.slice(0, path.lastIndexOf('/'));
3
4
  if (dir === '') {
@@ -22,4 +23,20 @@ export var generateDefaultDocContent = function generateDefaultDocContent() {
22
23
  export var getImageFileNameWithTimestamp = function getImageFileNameWithTimestamp() {
23
24
  var d = Date.now();
24
25
  return 'image-' + d.toString() + '.png';
25
- };
26
+ };
27
+ export var getErrorMsg = function getErrorMsg(error) {
28
+ var errorMsg = '';
29
+ if (error.response) {
30
+ if (error.response.status === 403) {
31
+ errorMsg = 'Permission_denied';
32
+ } else if (error.response.data && error.response.data['error_msg']) {
33
+ errorMsg = error.response.data['error_msg'];
34
+ } else {
35
+ errorMsg = 'Error';
36
+ }
37
+ } else {
38
+ errorMsg = 'Please_check_the_network';
39
+ }
40
+ return errorMsg;
41
+ };
42
+ export { DateUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.68",
3
+ "version": "0.1.69",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -251,5 +251,8 @@
251
251
  "Add_comment": "Add comment",
252
252
  "Delete_comment": "Delete comment",
253
253
  "Are_you_sure_to_delete_this_comment": "Are you sure to delete this comment?",
254
- "Confirm": "Confirm"
254
+ "Confirm": "Confirm",
255
+ "View_changes": "View changes",
256
+ "Revision": "Revision",
257
+ "Error": "Error"
255
258
  }
@@ -251,5 +251,8 @@
251
251
  "Add_comment": "添加评论",
252
252
  "Delete_comment": "删除评论",
253
253
  "Are_you_sure_to_delete_this_comment": "你确定要删除这个评论吗?",
254
- "Confirm": "确定"
254
+ "Confirm": "确定",
255
+ "View_changes": "查看改动",
256
+ "Revision": "修订",
257
+ "Error": "错误"
255
258
  }