@seafile/sdoc-editor 0.1.95 → 0.1.96

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.
@@ -30,6 +30,19 @@ var SDocServerApi = /*#__PURE__*/function () {
30
30
  }
31
31
  });
32
32
  }
33
+ }, {
34
+ key: "normalizeSdocContent",
35
+ value: function normalizeSdocContent() {
36
+ var server = this.server,
37
+ docUuid = this.docUuid,
38
+ accessToken = this.accessToken;
39
+ var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/normalize-sdoc");
40
+ return axios.get(url, {
41
+ headers: {
42
+ Authorization: "Token ".concat(accessToken)
43
+ }
44
+ });
45
+ }
33
46
  }, {
34
47
  key: "saveDocContent",
35
48
  value: function saveDocContent(content) {
@@ -0,0 +1,16 @@
1
+ .error-page {
2
+ flex: 1;
3
+ display: flex;
4
+ flex-direction: column;
5
+ justify-content: center;
6
+ align-items: center;
7
+ overflow: hidden;
8
+ }
9
+
10
+ .error-page .error-tip {
11
+ color: red;
12
+ }
13
+
14
+ .error-page .error-button {
15
+ margin-top: 20px;
16
+ }
@@ -17,19 +17,13 @@
17
17
 
18
18
  .sdoc-code-block-code .sdoc-code-line {
19
19
  position: relative;
20
- padding-left: 24px;
20
+ counter-increment: number;
21
21
  }
22
22
 
23
- .sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index {
24
- position: absolute;
25
- left: -8px;
23
+ .sdoc-code-block-code .sdoc-code-line::before {
24
+ content: counter(number);
26
25
  color: #ccc;
27
- caret-color: transparent;
28
- pointer-events: none;
29
- }
30
-
31
- .sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index::selection {
32
- background: transparent;
26
+ margin-right: 24px;
33
27
  }
34
28
 
35
29
  .sdoc-code-line
@@ -2,6 +2,7 @@
2
2
  position: absolute;
3
3
  height: 42px;
4
4
  z-index: 101;
5
+ width: 250px;
5
6
  }
6
7
 
7
8
  .sdoc-code-block-hover-menu-container .hover-menu-container {
@@ -9,9 +10,8 @@
9
10
  padding: 7px 8px;
10
11
  background-color: #fff;
11
12
  display: flex;
12
- justify-content: space-between;
13
+ justify-content: space-around;
13
14
  align-items: center;
14
- column-gap: 5px;
15
15
  border-radius: 3px;
16
16
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
17
17
  border: 1px solid #e8e8e8;
@@ -23,23 +23,43 @@
23
23
  background: #f1f1f1;
24
24
  }
25
25
 
26
+ .sdoc-code-block-hover-menu-container .hover-menu-container > span:not(:last-of-type) {
27
+ padding-right: 12px;
28
+ border-right: 1px solid #e5e5e5;
29
+ }
30
+
26
31
  .sdoc-code-block-hover-menu-container .hover-menu-container .op-item {
32
+ position: relative;
27
33
  font-size: 12px;
28
34
  color: #212529;
29
- padding: 0 5px;
35
+ padding: 5px;
30
36
  border-radius: 2px;
31
37
  }
32
38
 
33
- .sdoc-code-block-hover-menu-container .hover-menu-container .op-item:not(:last-child) {
34
- border-right: 1px solid #e5e5e5;
35
- }
36
-
37
39
  .sdoc-code-block-hover-menu-container .hover-menu-container .op-item:hover {
38
40
  color: #212529;
39
41
  text-decoration: none;
40
42
  background: #f1f1f1;
41
43
  }
42
44
 
45
+ .sdoc-code-block-hover-menu-container .hover-menu-container .op-tooltip:hover::after {
46
+ position: absolute;
47
+ color: #212529;
48
+ content: attr(op-item-tooltip);
49
+ top: -40px;
50
+ left: -20px;
51
+ width: 70px;
52
+ height: 30px;
53
+ display: flex;
54
+ justify-content: center;
55
+ align-items: center;
56
+ background-color: #fff;
57
+ border-radius: 3px;
58
+ border: 1px solid #e8e8e8;
59
+ font-size: 12px;
60
+ box-shadow: 0 0 5px #ccc;
61
+ }
62
+
43
63
  .sdoc-code-block-hover-menu-container .hover-menu-container .icon-font {
44
64
  font-size: 14px;
45
65
  color: #999999;
@@ -47,35 +67,51 @@
47
67
 
48
68
  .sdoc-langs-list-container {
49
69
  position: absolute;
50
- top: 36px;
51
- left: 8px;
52
- width: 90%;
53
- height: 400px;
54
- overflow-y: auto;
70
+ top: 38px;
71
+ left: 0px;
72
+ width: 200px;
73
+ overflow-y: hidden;
55
74
  background-color: #fff;
56
- border-radius: 3px;
57
- box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
58
- border: 1px solid #e8e8e8;
75
+ border-radius: 4px;
76
+ box-shadow: 0 0 5px #ccc;
77
+ border: 1px solid #dedede;
78
+ }
79
+
80
+ .sdoc-langs-list-container .sdoc-search-langs {
81
+ padding: 10px 10px 0;
82
+ }
83
+
84
+ .sdoc-langs-list-container .sdoc-search-langs input {
85
+ max-height: 30px;
86
+ font-size: 14px;
59
87
  }
60
88
 
61
89
  .sdoc-langs-list-container .langs-list-ul {
62
90
  list-style: none;
91
+ overflow-y: auto;
92
+ max-height: 280px;
93
+ min-height: 100px;
94
+ padding: 10px;
63
95
  }
64
96
 
65
97
  .sdoc-langs-list-container .langs-list-ul .langs-list-li {
66
- padding: 7px;
67
98
  position: relative;
68
- text-align: left;
69
99
  white-space: nowrap;
70
100
  cursor: pointer;
101
+ line-height: 30px;
102
+ height: 30px;
103
+ font-size: 13px;
104
+ padding-left: 12px;
105
+ display: flex;
106
+ justify-content: space-between;
71
107
  }
72
108
 
73
109
  .sdoc-langs-list-container .langs-list-ul .langs-list-li:hover {
74
- background: #f1f1f1;;
110
+ background-color: #f5f5f5;;
75
111
  }
76
112
 
77
113
  .sdoc-langs-list-container .langs-list-ul .langs-list-li .active {
78
- background: #f1f1f1;;
114
+ background-color: #f5f5f5;;
79
115
  }
80
116
 
81
117
  .sdoc-langs-list-container .langs-list-ul .langs-list-li .li-check-mark {
@@ -1,5 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import React, { useCallback, useEffect, useState } from 'react';
3
+ import { Input } from 'reactstrap';
3
4
  import { withTranslation } from 'react-i18next';
4
5
  import { ElementPopover } from '../../../commons/';
5
6
  import { genCodeLangs } from '../prismjs';
@@ -23,8 +24,14 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
23
24
  _useState4 = _slicedToArray(_useState3, 2),
24
25
  selectedLanguageText = _useState4[0],
25
26
  setSelectedLanguageText = _useState4[1];
26
- var onHiddenLangsList = useCallback(function () {
27
- setIsShowlangsList(false);
27
+ var _useState5 = useState(genCodeLangs()),
28
+ _useState6 = _slicedToArray(_useState5, 2),
29
+ langsData = _useState6[0],
30
+ setLangsData = _useState6[1];
31
+ var onHiddenLangsList = useCallback(function (e) {
32
+ if (!e.target.parentNode.className.includes('sdoc-search-langs')) {
33
+ setIsShowlangsList(false);
34
+ }
28
35
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
36
  }, []);
30
37
  useEffect(function () {
@@ -68,36 +75,69 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
68
75
  }).text;
69
76
  setSelectedLanguageText(selectedLanguageText);
70
77
  }, [language]);
78
+ var onChange = useCallback(function (e) {
79
+ var filterData = [];
80
+ var restData = [];
81
+ genCodeLangs().forEach(function (item) {
82
+ if (item.value.startsWith(e.currentTarget.value.toLowerCase())) {
83
+ filterData.push(item);
84
+ } else {
85
+ restData.push(item);
86
+ }
87
+ });
88
+ setLangsData([].concat(filterData, restData));
89
+ // eslint-disable-next-line react-hooks/exhaustive-deps
90
+ }, []);
71
91
  return /*#__PURE__*/React.createElement(ElementPopover, null, /*#__PURE__*/React.createElement("div", {
72
92
  className: "sdoc-code-block-hover-menu-container",
73
93
  style: menuPosition
74
94
  }, /*#__PURE__*/React.createElement("div", {
75
95
  className: "hover-menu-container"
96
+ }, /*#__PURE__*/React.createElement("span", {
97
+ className: "op-group-item"
76
98
  }, /*#__PURE__*/React.createElement("span", {
77
99
  role: "button",
78
100
  className: "op-item ".concat(isShowlangsList ? 'active' : ''),
79
101
  onClick: onShowLangs
80
102
  }, /*#__PURE__*/React.createElement("span", null, selectedLanguageText), /*#__PURE__*/React.createElement("i", {
81
103
  className: "sdocfont sdoc-drop-down ml-1 icon-font"
82
- })), /*#__PURE__*/React.createElement("span", {
104
+ }))), /*#__PURE__*/React.createElement("span", {
105
+ className: "op-group-item"
106
+ }, /*#__PURE__*/React.createElement("span", {
83
107
  role: "button",
84
- className: "op-item ".concat(white_space === 'normal' ? 'active' : ''),
108
+ className: "op-item ".concat(white_space === 'normal' ? 'active' : '', " op-tooltip"),
109
+ "op-item-tooltip": t('Auto_wrap'),
85
110
  onClick: onAutoLineWrap
86
- }, /*#__PURE__*/React.createElement("span", null, t('Auto_wrap'))), /*#__PURE__*/React.createElement("span", {
111
+ }, /*#__PURE__*/React.createElement("i", {
112
+ className: "sdocfont sdoc-auto-linefeed ml-r icon-font"
113
+ }))), /*#__PURE__*/React.createElement("span", {
114
+ className: "op-group-item"
115
+ }, /*#__PURE__*/React.createElement("span", {
87
116
  role: "button",
88
- className: "op-item",
117
+ className: "op-item op-tooltip",
118
+ "op-item-tooltip": t('Copy'),
89
119
  onClick: onCopyCodeBlock
90
- }, /*#__PURE__*/React.createElement("span", null, t('Copy'))), /*#__PURE__*/React.createElement("span", {
120
+ }, /*#__PURE__*/React.createElement("i", {
121
+ className: "sdocfont sdoc-copy ml-r icon-font"
122
+ }))), /*#__PURE__*/React.createElement("span", {
123
+ className: "op-group-item"
124
+ }, /*#__PURE__*/React.createElement("span", {
91
125
  role: "button",
92
- className: 'op-item',
126
+ className: 'op-item op-tooltip',
127
+ "op-item-tooltip": t('Delete'),
93
128
  onClick: onDelete
94
129
  }, /*#__PURE__*/React.createElement("i", {
95
130
  className: "sdocfont sdoc-delete icon-font"
96
- })), isShowlangsList && /*#__PURE__*/React.createElement("div", {
131
+ }))), isShowlangsList && /*#__PURE__*/React.createElement("div", {
97
132
  className: "sdoc-langs-list-container"
98
- }, /*#__PURE__*/React.createElement("ul", {
133
+ }, /*#__PURE__*/React.createElement("div", {
134
+ className: "sdoc-search-langs"
135
+ }, /*#__PURE__*/React.createElement(Input, {
136
+ placeholder: t('Search_language'),
137
+ onChange: onChange
138
+ })), /*#__PURE__*/React.createElement("ul", {
99
139
  className: "langs-list-ul"
100
- }, genCodeLangs().map(function (item) {
140
+ }, langsData.map(function (item) {
101
141
  return /*#__PURE__*/React.createElement("li", {
102
142
  className: "langs-list-li ".concat(selectedLanguageText === item.text ? 'active' : ''),
103
143
  id: item.value,
@@ -105,11 +145,11 @@ var CodeBlockHoverMenu = function CodeBlockHoverMenu(_ref) {
105
145
  onClick: function onClick() {
106
146
  onSelectLang(item);
107
147
  }
108
- }, /*#__PURE__*/React.createElement("span", {
148
+ }, item.text, /*#__PURE__*/React.createElement("span", {
109
149
  className: "li-check-mark ".concat(selectedLanguageText === item.text ? 'li-checked' : '')
110
150
  }, /*#__PURE__*/React.createElement("i", {
111
- className: "sdocfont sdoc-check-square icon-font"
112
- })), item.text);
151
+ className: "sdocfont sdoc-check-mark icon-font"
152
+ })));
113
153
  }))))));
114
154
  };
115
155
  export default withTranslation('sdoc-editor')(CodeBlockHoverMenu);
@@ -22,54 +22,54 @@ export var genCodeLangs = function genCodeLangs() {
22
22
  return [{
23
23
  text: 'Plain Text',
24
24
  value: 'plaintext'
25
+ }, {
26
+ text: 'Bash',
27
+ value: 'bash'
25
28
  }, {
26
29
  text: 'CSS',
27
30
  value: 'css'
31
+ }, {
32
+ text: 'C',
33
+ value: 'c'
34
+ }, {
35
+ text: 'C++',
36
+ value: 'cpp'
37
+ }, {
38
+ text: 'C#',
39
+ value: 'csharp'
40
+ }, {
41
+ text: 'Go',
42
+ value: 'go'
28
43
  }, {
29
44
  text: 'HTML',
30
45
  value: 'html'
31
- }, {
32
- text: 'XML',
33
- value: 'xml'
34
46
  }, {
35
47
  text: 'Javascript',
36
48
  value: 'javascript'
37
49
  }, {
38
- text: 'Typescript',
39
- value: 'typescript'
40
- }, {
41
- text: 'Go',
42
- value: 'go'
50
+ text: 'Java',
51
+ value: 'java'
43
52
  }, {
44
53
  text: 'PHP',
45
54
  value: 'php'
46
- }, {
47
- text: 'C',
48
- value: 'c'
49
55
  }, {
50
56
  text: 'Python',
51
57
  value: 'python'
52
58
  }, {
53
- text: 'Java',
54
- value: 'java'
55
- }, {
56
- text: 'C++',
57
- value: 'cpp'
58
- }, {
59
- text: 'C#',
60
- value: 'csharp'
59
+ text: 'Ruby',
60
+ value: 'ruby'
61
61
  }, {
62
62
  text: 'SQL',
63
63
  value: 'sql'
64
- }, {
65
- text: 'Ruby',
66
- value: 'ruby'
67
64
  }, {
68
65
  text: 'Swift',
69
66
  value: 'swift'
70
67
  }, {
71
- text: 'Bash',
72
- value: 'bash'
68
+ text: 'Typescript',
69
+ value: 'typescript'
70
+ }, {
71
+ text: 'XML',
72
+ value: 'xml'
73
73
  }];
74
74
  };
75
75
  export var normalizeTokensByLanguageType = {
@@ -65,7 +65,7 @@ var CodeBlock = function CodeBlock(_ref) {
65
65
  });
66
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
67
67
  }, []);
68
- var onMouseEnter = useCallback(function (e) {
68
+ var onFocusCodeBlock = useCallback(function (e) {
69
69
  if (readOnly) return;
70
70
  if (codeBlockRef.current) {
71
71
  var _codeBlockRef$current = codeBlockRef.current.getBoundingClientRect(),
@@ -112,16 +112,22 @@ var CodeBlock = function CodeBlock(_ref) {
112
112
  }
113
113
  // eslint-disable-next-line react-hooks/exhaustive-deps
114
114
  }, [showHoverMenu]);
115
+ var isEntering = useCallback(function (e) {
116
+ return !editor.operations.every(function (operation) {
117
+ return operation.type === 'set_selection';
118
+ });
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ }, []);
115
121
  return /*#__PURE__*/React.createElement("div", {
116
122
  ref: codeBlockRef,
117
123
  className: 'sdoc-code-block-container',
118
- onMouseEnter: onMouseEnter,
124
+ onClick: onFocusCodeBlock,
119
125
  onMouseLeave: onMouseLeave
120
126
  }, /*#__PURE__*/React.createElement("pre", Object.assign({
121
127
  className: 'sdoc-code-block-pre'
122
128
  }, attributes), /*#__PURE__*/React.createElement("code", {
123
129
  className: "sdoc-code-block-code ".concat(white_space === 'nowrap' ? 'sdoc-code-no-wrap' : '')
124
- }, children)), showHoverMenu && /*#__PURE__*/React.createElement(CodeBlockHoverMenu, {
130
+ }, children)), showHoverMenu && !isEntering() && /*#__PURE__*/React.createElement(CodeBlockHoverMenu, {
125
131
  menuPosition: menuPosition,
126
132
  onChangeLanguage: onChangeLanguage,
127
133
  language: element.language,
@@ -46,6 +46,23 @@ var codeBlockRule = function codeBlockRule(element, parseChild) {
46
46
  }
47
47
  }
48
48
  if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
49
+ var childIsP = Array.from(childNodes).every(function (n) {
50
+ return n.nodeName === 'P';
51
+ });
52
+ if (childIsP) {
53
+ return Array.from(childNodes).map(function (n) {
54
+ return {
55
+ level: 'level2',
56
+ id: slugid.nice(),
57
+ type: CODE_LINE,
58
+ children: [{
59
+ level: 'level3',
60
+ id: slugid.nice(),
61
+ text: n.textContent
62
+ }]
63
+ };
64
+ });
65
+ }
49
66
  var _content = element.textContent;
50
67
  var hasNewLine = _content.indexOf('\n') > -1;
51
68
  if (!hasNewLine) {
@@ -99,13 +99,9 @@ var CustomElement = function CustomElement(props) {
99
99
  at: path
100
100
  });
101
101
  if (parentNode[0].type === CODE_BLOCK) {
102
- var lineNumber = path.at(-1) + 1;
103
102
  return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
104
103
  className: 'sdoc-code-line'
105
- }), lineNumber && /*#__PURE__*/React.createElement("span", {
106
- spellCheck: false,
107
- className: "sdoc-code-line-index"
108
- }, lineNumber), children);
104
+ }), children);
109
105
  }
110
106
  return children;
111
107
  }
package/dist/context.js CHANGED
@@ -79,6 +79,11 @@ var Context = /*#__PURE__*/function () {
79
79
  value: function getFileContent() {
80
80
  return this.sdocServerApi.getDocContent();
81
81
  }
82
+ }, {
83
+ key: "normalizeSdocContent",
84
+ value: function normalizeSdocContent() {
85
+ return this.sdocServerApi.normalizeSdocContent();
86
+ }
82
87
  }, {
83
88
  key: "saveContent",
84
89
  value: function saveContent(content) {
@@ -0,0 +1,42 @@
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, { PureComponent } from 'react';
6
+ import ErrorPage from './error-page';
7
+ var ErrorBoundary = /*#__PURE__*/function (_PureComponent) {
8
+ _inherits(ErrorBoundary, _PureComponent);
9
+ var _super = _createSuper(ErrorBoundary);
10
+ function ErrorBoundary(props) {
11
+ var _this;
12
+ _classCallCheck(this, ErrorBoundary);
13
+ _this = _super.call(this, props);
14
+ _this.state = {
15
+ hasError: false
16
+ };
17
+ return _this;
18
+ }
19
+ _createClass(ErrorBoundary, [{
20
+ key: "componentDidCatch",
21
+ value: function componentDidCatch(error, errorInfo) {
22
+ console.log(error, errorInfo);
23
+ }
24
+ }, {
25
+ key: "render",
26
+ value: function render() {
27
+ if (this.state.hasError) {
28
+ return /*#__PURE__*/React.createElement(ErrorPage, null);
29
+ }
30
+ return this.props.children;
31
+ }
32
+ }], [{
33
+ key: "getDerivedStateFromError",
34
+ value: function getDerivedStateFromError(error) {
35
+ return {
36
+ hasError: true
37
+ };
38
+ }
39
+ }]);
40
+ return ErrorBoundary;
41
+ }(PureComponent);
42
+ export { ErrorBoundary as default };
@@ -0,0 +1,41 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
+ import React, { useCallback } from 'react';
4
+ import { Button } from 'reactstrap';
5
+ import { withTranslation } from 'react-i18next';
6
+ import context from '../context';
7
+ import '../assets/css/error-page.css';
8
+ function ErrorPage(_ref) {
9
+ var t = _ref.t;
10
+ var normalizeSdoc = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
11
+ var res, success;
12
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
13
+ while (1) switch (_context.prev = _context.next) {
14
+ case 0:
15
+ _context.next = 2;
16
+ return context.normalizeSdocContent();
17
+ case 2:
18
+ res = _context.sent;
19
+ success = res.data.success;
20
+ if (success) {
21
+ // eslint-disable-next-line no-restricted-globals
22
+ location.reload(true);
23
+ }
24
+ case 5:
25
+ case "end":
26
+ return _context.stop();
27
+ }
28
+ }, _callee);
29
+ })), []);
30
+ return /*#__PURE__*/React.createElement("div", {
31
+ className: "error-page"
32
+ }, /*#__PURE__*/React.createElement("span", {
33
+ className: "error-tip"
34
+ }, t('Sdoc_error_tip')), /*#__PURE__*/React.createElement(Button, {
35
+ className: "error-button",
36
+ onClick: function onClick() {
37
+ return normalizeSdoc();
38
+ }
39
+ }, t('Repair')));
40
+ }
41
+ export default withTranslation('sdoc-editor')(ErrorPage);
@@ -9,6 +9,7 @@ import Layout, { Header, Content } from '../layout';
9
9
  import { generateDefaultDocContent } from '../utils';
10
10
  import context from '../context';
11
11
  import DiffViewer from './diff-viewer';
12
+ import ErrorBoundary from './error-boundary';
12
13
  import '../assets/css/simple-editor.css';
13
14
  var SimpleEditor = function SimpleEditor(_ref) {
14
15
  var isStarred = _ref.isStarred,
@@ -122,7 +123,7 @@ var SimpleEditor = function SimpleEditor(_ref) {
122
123
  className: "d-flex justify-content-center"
123
124
  }, t(errorMessage));
124
125
  }
125
- return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, {
126
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, {
126
127
  isStarred: isStarred,
127
128
  isDraft: isDraft,
128
129
  isEditMode: !isShowChanges
@@ -140,6 +141,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
140
141
  config: context.getEditorConfig(),
141
142
  document: document,
142
143
  isOpenSocket: context.getSetting('isOpenSocket')
143
- }))));
144
+ })))));
144
145
  };
145
146
  export default withTranslation('sdoc-editor')(SimpleEditor);
@@ -11,6 +11,7 @@ import context from '../context';
11
11
  import Loading from '../components/loading';
12
12
  import Layout, { Header, Content } from '../layout';
13
13
  import { generateDefaultDocContent } from '../utils';
14
+ import ErrorBoundary from './error-boundary';
14
15
  var SimpleViewer = /*#__PURE__*/function (_React$Component) {
15
16
  _inherits(SimpleViewer, _React$Component);
16
17
  var _super = _createSuper(SimpleViewer);
@@ -95,10 +96,10 @@ var SimpleViewer = /*#__PURE__*/function (_React$Component) {
95
96
  }, t(errorMessage));
96
97
  }
97
98
  var docName = context.getSetting('docName');
98
- return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", null, docName)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
99
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", null, docName)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
99
100
  document: document,
100
101
  onValueChanged: this.onValueChanged
101
- })));
102
+ }))));
102
103
  }
103
104
  }]);
104
105
  return SimpleViewer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.95",
3
+ "version": "0.1.96",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -319,5 +319,8 @@
319
319
  "Creator": "Creator",
320
320
  "Created_time": "Created time",
321
321
  "Created_at": "Created at",
322
- "Resolved_tip": "Mark as resolved and hide discussion"
322
+ "Resolved_tip": "Mark as resolved and hide discussion",
323
+ "Search_language": "Search language",
324
+ "Sdoc_error_tip": "The document has errors and cannot be displayed. Please try to fix it automatically by clicking the button below.",
325
+ "Repair": "Repair"
323
326
  }
@@ -319,5 +319,8 @@
319
319
  "Creator": "创建者",
320
320
  "Created_time": "创建时间",
321
321
  "Created_at": "创建时间",
322
- "Resolved_tip": "标记为已解决并隐藏讨论内容"
322
+ "Resolved_tip": "标记为已解决并隐藏讨论内容",
323
+ "Search_language": "查找语言",
324
+ "Sdoc_error_tip": "文档有错误,无法显示。请尝试点击下方按钮自动修复。",
325
+ "Repair": "修复"
323
326
  }