@seafile/sdoc-editor 0.1.67 → 0.1.68-beta1

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 (28) hide show
  1. package/dist/api/seafile-api.js +6 -0
  2. package/dist/assets/css/diff-viewer.css +0 -14
  3. package/dist/assets/css/simple-editor.css +5 -0
  4. package/dist/basic-sdk/assets/css/code-block.css +8 -5
  5. package/dist/basic-sdk/comment/style.css +1 -0
  6. package/dist/basic-sdk/editor.js +4 -2
  7. package/dist/basic-sdk/extension/plugins/code-block/plugin.js +72 -4
  8. package/dist/basic-sdk/extension/plugins/table/render/render-row.js +4 -4
  9. package/dist/basic-sdk/extension/plugins/table/render/table-root.js +1 -1
  10. package/dist/basic-sdk/extension/render/render-element.js +1 -0
  11. package/dist/basic-sdk/hooks/use-scroll-context.js +1 -1
  12. package/dist/basic-sdk/index.js +2 -2
  13. package/dist/{pages/diff-viewer → basic-sdk/views}/diff-viewer.js +6 -6
  14. package/dist/basic-sdk/views/index.js +3 -0
  15. package/dist/basic-sdk/{viewer.js → views/viewer.js} +6 -6
  16. package/dist/components/code-block-hover-menu/index.css +2 -2
  17. package/dist/components/doc-info/index.js +50 -54
  18. package/dist/components/doc-operations/history-operation.js +23 -0
  19. package/dist/components/doc-operations/index.js +14 -78
  20. package/dist/components/doc-operations/more-operations.js +44 -0
  21. package/dist/components/doc-operations/revision-operations.js +42 -0
  22. package/dist/context.js +10 -0
  23. package/dist/pages/diff-viewer/index.js +1 -1
  24. package/dist/utils/date-utils.js +86 -0
  25. package/dist/utils/index.js +18 -1
  26. package/package.json +1 -1
  27. package/public/locales/en/sdoc-editor.json +4 -1
  28. package/public/locales/zh-CN/sdoc-editor.json +4 -1
@@ -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
+ }
@@ -3,7 +3,8 @@
3
3
  }
4
4
 
5
5
  .sdoc-code-block-pre {
6
- border: 1px solid #ccc;
6
+ background: #FAFAFA;
7
+ border: 1px solid #f0f0f0;
7
8
  }
8
9
 
9
10
  .sdoc-code-block-pre .sdoc-code-no-wrap {
@@ -16,19 +17,21 @@
16
17
 
17
18
  .sdoc-code-block-code .sdoc-code-line {
18
19
  position: relative;
19
- padding-left: 5px;
20
+ padding-left: 24px;
20
21
  }
21
22
 
22
23
  .sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index {
23
24
  position: absolute;
24
- left: -10px;
25
+ left: -8px;
25
26
  color: #ccc;
26
- width: 10px;
27
- height: 10px;
28
27
  caret-color: transparent;
29
28
  pointer-events: none;
30
29
  }
31
30
 
31
+ .sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index::selection {
32
+ background: transparent;
33
+ }
34
+
32
35
  .sdoc-code-line
33
36
  .token.comment,
34
37
  .token.prolog,
@@ -64,6 +64,7 @@
64
64
  .sdoc-comment-container .comment-item .comment-header {
65
65
  display: flex;
66
66
  justify-content: space-between;
67
+ align-items: center;
67
68
  }
68
69
 
69
70
  .sdoc-comment-container .comment-item .comment-content {
@@ -47,6 +47,7 @@ var SDocEditor = function SDocEditor(_ref) {
47
47
  var _useCursors = useCursors(editor),
48
48
  cursors = _useCursors.cursors;
49
49
  var scrollRef = useRef(null);
50
+ var articleRef = useRef(null);
50
51
  var decorate = usePipDecorate(editor);
51
52
 
52
53
  // init eventHandler
@@ -59,7 +60,7 @@ var SDocEditor = function SDocEditor(_ref) {
59
60
  // useMount: init socket connection
60
61
  useEffect(function () {
61
62
  editor.openConnection();
62
- editor.width = scrollRef.current.children[0].clientWidth;
63
+ editor.width = articleRef.current.children[0].clientWidth;
63
64
  return function () {
64
65
  editor.closeConnection();
65
66
  };
@@ -121,7 +122,8 @@ var SDocEditor = function SDocEditor(_ref) {
121
122
  value: slateValue,
122
123
  onChange: onChange
123
124
  }, /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement("div", {
124
- className: "article"
125
+ className: "article",
126
+ ref: articleRef
125
127
  }, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
126
128
  renderElement: renderElement,
127
129
  renderLeaf: renderLeaf,
@@ -1,10 +1,78 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { Transforms } from '@seafile/slate';
3
- import { getNodeType, isLastNode, genEmptyParagraph } from '../../core';
4
- import { CODE_BLOCK } from '../../constants';
2
+ import _toArray from "@babel/runtime/helpers/esm/toArray";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import slugid from 'slugid';
5
+ import { Transforms, Node, Range, Editor } from '@seafile/slate';
6
+ import { getNodeType, isLastNode, genEmptyParagraph, getSelectedNodeByType, generateEmptyElement } from '../../core';
7
+ import { CODE_BLOCK, PARAGRAPH, CODE_LINE } from '../../constants';
5
8
  var withCodeBlock = function withCodeBlock(editor) {
6
- var normalizeNode = editor.normalizeNode;
9
+ var normalizeNode = editor.normalizeNode,
10
+ insertFragment = editor.insertFragment,
11
+ insertText = editor.insertText,
12
+ insertBreak = editor.insertBreak;
7
13
  var newEditor = editor;
14
+ newEditor.insertFragment = function (data) {
15
+ // only selected code block content
16
+ if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
17
+ data.forEach(function (node, index) {
18
+ if (node.type === CODE_BLOCK) {
19
+ var newBlock = node.children.map(function (line) {
20
+ var text = Node.string(line);
21
+ var p = generateEmptyElement(PARAGRAPH);
22
+ p.children[0].text = text;
23
+ return p;
24
+ });
25
+ data.splice.apply(data, [index, 1].concat(_toConsumableArray(newBlock)));
26
+ }
27
+ });
28
+ return insertFragment(data);
29
+ } else {
30
+ if (getSelectedNodeByType(editor, CODE_BLOCK)) {
31
+ // Paste into code block
32
+
33
+ // Pasted data is code block split with code-line
34
+ data.forEach(function (node, index) {
35
+ if (node.type === CODE_BLOCK) {
36
+ var codeLineArr = node.children.map(function (line) {
37
+ return line;
38
+ });
39
+ data.splice.apply(data, [index, 1].concat(_toConsumableArray(codeLineArr)));
40
+ }
41
+ });
42
+ var newData = data.map(function (node) {
43
+ var text = Node.string(node);
44
+ var codeLine = {
45
+ id: slugid.nice(),
46
+ type: CODE_LINE,
47
+ children: [{
48
+ text: text,
49
+ id: slugid.nice()
50
+ }]
51
+ };
52
+ return codeLine;
53
+ });
54
+
55
+ // current focus code-line string not empty
56
+ var string = Editor.string(newEditor, newEditor.selection.focus.path);
57
+ if (string.length !== 0 && Range.isCollapsed(newEditor.selection)) {
58
+ var _newData = _toArray(newData),
59
+ node = _newData[0],
60
+ restNode = _newData.slice(1);
61
+ var text = Node.string(node);
62
+ insertText(text);
63
+ if (restNode.length !== 0) {
64
+ insertBreak();
65
+ insertFragment(restNode);
66
+ }
67
+ return;
68
+ }
69
+ return insertFragment(newData);
70
+ } else {
71
+ // Paste into not a code block
72
+ return insertFragment(data);
73
+ }
74
+ }
75
+ };
8
76
 
9
77
  // Rewrite normalizeNode
10
78
  newEditor.normalizeNode = function (_ref) {
@@ -10,6 +10,7 @@ import { TABLE_ROW_MIN_HEIGHT } from '../constants';
10
10
  import { updateTableRowHeight } from '../helpers';
11
11
  import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
12
12
  import { useSettingSelectRangeContext, useResizeHandlersContext } from './hooks';
13
+ import { useScrollContext } from '../../../../hooks/use-scroll-context';
13
14
  var TableRow = function TableRow(_ref) {
14
15
  var _element$style;
15
16
  var element = _ref.element,
@@ -36,11 +37,11 @@ var TableRow = function TableRow(_ref) {
36
37
  _useState6 = _slicedToArray(_useState5, 2),
37
38
  height = _useState6[0],
38
39
  setHeight = _useState6[1];
40
+ var scrollContent = useScrollContext();
39
41
  var onMouseDown = useCallback(function (event) {
40
42
  eventStopPropagation(event);
41
43
  Transforms.deselect(editor);
42
- var pageElement = document.getElementsByClassName('sdoc-editor-article-container')[0];
43
- var mouseDownInfo = getMouseDownInfo(event, pageElement);
44
+ var mouseDownInfo = getMouseDownInfo(event, scrollContent.current);
44
45
  setMouseDownInfo(mouseDownInfo);
45
46
  setIsResizing(true);
46
47
 
@@ -50,8 +51,7 @@ var TableRow = function TableRow(_ref) {
50
51
  if (!isResizing) return;
51
52
  var onMouseMove = function onMouseMove(event) {
52
53
  eventStopPropagation(event);
53
- var pageElement = document.getElementsByClassName('sdoc-editor-article-container')[0];
54
- var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, pageElement);
54
+ var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, scrollContent.current);
55
55
  var newHeight = tableRow.current + mouseMoveInfo.displacementY;
56
56
  var validHeight = Math.max(TABLE_ROW_MIN_HEIGHT, newHeight);
57
57
  setHeight(validHeight);
@@ -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', {
@@ -99,6 +99,7 @@ var CustomElement = function CustomElement(props) {
99
99
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
100
100
  className: 'sdoc-code-line'
101
101
  }), lineNumber && /*#__PURE__*/React.createElement("span", {
102
+ spellCheck: false,
102
103
  className: "sdoc-code-line-index"
103
104
  }, lineNumber), children);
104
105
  }
@@ -1,4 +1,4 @@
1
- import React, { useContext } from "react";
1
+ import React, { useContext } from 'react';
2
2
  export var ScrollContext = React.createContext(null);
3
3
  export var useScrollContext = function useScrollContext() {
4
4
  var context = useContext(ScrollContext);
@@ -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,
@@ -26,7 +26,7 @@
26
26
  .sdoc-code-block-hover-menu-container .hover-menu-container .op-item {
27
27
  font-size: 12px;
28
28
  color: #212529;
29
- padding: 0 5px;
29
+ padding: 0 3px;
30
30
  border-radius: 2px;
31
31
  }
32
32
 
@@ -37,7 +37,7 @@
37
37
  }
38
38
 
39
39
  .sdoc-code-block-hover-menu-container .hover-menu-container .icon-font {
40
- font-size: 12px;
40
+ font-size: 14px;
41
41
  color: #999999;
42
42
  }
43
43
 
@@ -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.67",
3
+ "version": "0.1.68beta1",
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
  }