@seafile/sdoc-editor 0.1.77 → 0.1.78-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.
@@ -62,6 +62,12 @@ var SeafileAPI = /*#__PURE__*/function () {
62
62
  form.append('file_uuid', fileUuid);
63
63
  return this._sendPostRequest(url, form);
64
64
  }
65
+ }, {
66
+ key: "getSeadocRevisionDownloadLinks",
67
+ value: function getSeadocRevisionDownloadLinks(docUuid) {
68
+ var url = '/api/v2.1/seadoc/revision/download-links/' + docUuid + '/';
69
+ return this.req.get(url);
70
+ }
65
71
  }]);
66
72
  return SeafileAPI;
67
73
  }();
@@ -61,9 +61,8 @@ var SDocEditor = function SDocEditor(_ref) {
61
61
  // useMount: init socket connection
62
62
  useEffect(function () {
63
63
  editor.openConnection();
64
- editor.width = articleRef.current.children[0].clientWidth;
65
64
  return function () {
66
- editor.closeConnection();
65
+ editor.closeConnection && editor.closeConnection();
67
66
  };
68
67
  // eslint-disable-next-line react-hooks/exhaustive-deps
69
68
  }, []);
@@ -71,6 +70,7 @@ var SDocEditor = function SDocEditor(_ref) {
71
70
  // useMount: focus editor
72
71
  useEffect(function () {
73
72
  var timer = setTimeout(function () {
73
+ editor.width = articleRef.current.children[0].clientWidth;
74
74
  focusEditor(editor);
75
75
  }, 300);
76
76
  return function () {
@@ -9,21 +9,45 @@ var codeBlockRule = function codeBlockRule(element, parseChild) {
9
9
  return item.nodeName === 'CODE';
10
10
  });
11
11
  var codeChild = children[0];
12
- var lang = codeChild.getAttribute('lang');
13
- lang = genCodeLangs().find(function (item) {
14
- return item.value === lang;
15
- }) || 'plaintext';
16
- return {
17
- level: 'level1',
18
- id: slugid.nice(),
19
- language: lang,
20
- type: CODE_BLOCK,
21
- children: parseChild(children)
22
- };
12
+ if (codeChild) {
13
+ var lang = codeChild.getAttribute('lang');
14
+ lang = genCodeLangs().find(function (item) {
15
+ return item.value === lang;
16
+ }) || 'plaintext';
17
+ return {
18
+ level: 'level1',
19
+ id: slugid.nice(),
20
+ language: lang,
21
+ type: CODE_BLOCK,
22
+ children: parseChild(children)
23
+ };
24
+ } else {
25
+ var _lang = 'plaintext';
26
+ var content = childNodes[0].textContent;
27
+ var _children = content.split('\n').map(function (text) {
28
+ return {
29
+ level: 'level2',
30
+ id: slugid.nice(),
31
+ type: CODE_LINE,
32
+ children: [{
33
+ level: 'level3',
34
+ id: slugid.nice(),
35
+ text: text
36
+ }]
37
+ };
38
+ });
39
+ return {
40
+ level: 'level1',
41
+ id: slugid.nice(),
42
+ language: _lang,
43
+ type: CODE_BLOCK,
44
+ children: _children
45
+ };
46
+ }
23
47
  }
24
48
  if (nodeName === 'CODE' && element.parentElement.nodeName === 'PRE') {
25
- var content = element.textContent;
26
- var hasNewLine = content.indexOf('\n') > -1;
49
+ var _content = element.textContent;
50
+ var hasNewLine = _content.indexOf('\n') > -1;
27
51
  if (!hasNewLine) {
28
52
  return {
29
53
  level: 'level2',
@@ -36,7 +60,7 @@ var codeBlockRule = function codeBlockRule(element, parseChild) {
36
60
  }]
37
61
  };
38
62
  }
39
- var codes = content.split('\n');
63
+ var codes = _content.split('\n');
40
64
  return codes.map(function (item) {
41
65
  return {
42
66
  level: 'level2',
@@ -21,9 +21,6 @@ var CommonMenu = /*#__PURE__*/function (_Component) {
21
21
  itemClass = "rich-icon-btn d-flex ".concat(disabled ? 'rich-icon-btn-disabled' : 'rich-icon-btn-hover');
22
22
  return itemClass + ' ' + className;
23
23
  };
24
- _this.hidePopover = function () {
25
- _this.ref && _this.ref.toggle && _this.ref.toggle();
26
- };
27
24
  _this.setRef = function (ref) {
28
25
  _this.ref = ref;
29
26
  if (!_this.ref) return;
@@ -1,4 +1,3 @@
1
- var _this = this;
2
1
  import { generateCursorData } from '../cursor/helper';
3
2
  import EventBus from '../utils/event-bus';
4
3
  import SocketManager from './socket-manager';
@@ -16,7 +15,7 @@ var withSocketIO = function withSocketIO(editor, options) {
16
15
  socketManager = SocketManager.getInstance(newEditor, document, config);
17
16
  };
18
17
  newEditor.closeConnection = function () {
19
- socketManager && _this.socketManager.closeConnection();
18
+ socketManager && socketManager.closeSocketConnect();
20
19
  };
21
20
  newEditor.onChange = function () {
22
21
  var operations = newEditor.operations;
@@ -43,12 +43,12 @@ var DocInfo = function DocInfo(_ref) {
43
43
  var revisionCreatedAt = context.getSetting('revisionCreatedAt');
44
44
  var oldDocName = context.getSetting('originFilename');
45
45
  return /*#__PURE__*/React.createElement("div", {
46
- className: "doc-info d-flex flex-column"
46
+ className: "doc-info d-flex flex-column align-items-start"
47
47
  }, /*#__PURE__*/React.createElement("div", {
48
48
  className: "doc-name-container d-flex align-items-center justify-content-start w-100"
49
49
  }, /*#__PURE__*/React.createElement("div", {
50
50
  className: "doc-name"
51
- }, oldDocName), docInfo), /*#__PURE__*/React.createElement("div", {
51
+ }, oldDocName), /*#__PURE__*/React.createElement(TipMessage, null)), /*#__PURE__*/React.createElement("div", {
52
52
  className: "doc-state"
53
53
  }, /*#__PURE__*/React.createElement("span", {
54
54
  className: "mr-2"
@@ -4,14 +4,21 @@ import RevisionOperations from './revision-operations';
4
4
  import HistoryOperation from './history-operation';
5
5
  import CollaboratorsOperation from './collaborators-operation';
6
6
  import MoreOperations from './more-operations';
7
+ import context from '../../context';
7
8
  import './style.css';
8
- var DocOperations = function DocOperations() {
9
+ var DocOperations = function DocOperations(_ref) {
10
+ var isShowChanges = _ref.isShowChanges,
11
+ toggleViewChanges = _ref.toggleViewChanges;
12
+ var isSdocRevision = context.getSetting('isSdocRevision');
9
13
  return /*#__PURE__*/React.createElement("div", {
10
14
  className: "doc-ops"
11
- }, /*#__PURE__*/React.createElement(RevisionOperations, null), /*#__PURE__*/React.createElement("span", {
15
+ }, /*#__PURE__*/React.createElement(RevisionOperations, {
16
+ isShowChanges: isShowChanges,
17
+ toggleViewChanges: toggleViewChanges
18
+ }), !isSdocRevision && /*#__PURE__*/React.createElement("span", {
12
19
  className: "op-item"
13
20
  }, /*#__PURE__*/React.createElement("i", {
14
21
  className: "sdocfont sdoc-share"
15
- })), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), /*#__PURE__*/React.createElement(MoreOperations, null));
22
+ })), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
16
23
  };
17
24
  export default withTranslation('sdoc-editor')(DocOperations);
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import PublishRevision from './publish-button';
3
+ import ViewChanges from './view-changes';
4
+ import MoreRevisionOperations from './more-revision-operations';
5
+ var RevisionOperations = function RevisionOperations(_ref) {
6
+ var isShowChanges = _ref.isShowChanges,
7
+ toggleViewChanges = _ref.toggleViewChanges;
8
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(ViewChanges, {
9
+ isShowChanges: isShowChanges,
10
+ toggleViewChanges: toggleViewChanges
11
+ }), /*#__PURE__*/React.createElement(PublishRevision, null));
12
+ };
13
+ export default RevisionOperations;
@@ -0,0 +1,60 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import React, { Component, useCallback, useState } from 'react';
7
+ import { withTranslation } from 'react-i18next';
8
+ import { UncontrolledPopover } from 'reactstrap';
9
+ var MoreRevisionOperations = /*#__PURE__*/function (_Component) {
10
+ _inherits(MoreRevisionOperations, _Component);
11
+ var _super = _createSuper(MoreRevisionOperations);
12
+ function MoreRevisionOperations(props) {
13
+ var _this;
14
+ _classCallCheck(this, MoreRevisionOperations);
15
+ _this = _super.call(this, props);
16
+ _this.setRef = function (ref) {
17
+ console.log('click');
18
+ var that = _assertThisInitialized(_this);
19
+ if (!ref) return;
20
+ var toggle = ref.toggle;
21
+ ref.toggle = function (c) {
22
+ console.log(c);
23
+ toggle && toggle();
24
+ that.setState({
25
+ isShowMenu: !that.state.isShowMenu
26
+ });
27
+ };
28
+ };
29
+ _this.state = {
30
+ isShowMenu: false
31
+ };
32
+ _this.id = 'sdoc-revision-more-operations';
33
+ return _this;
34
+ }
35
+ _createClass(MoreRevisionOperations, [{
36
+ key: "render",
37
+ value: function render() {
38
+ var isShowMenu = this.state.isShowMenu;
39
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
40
+ id: this.id,
41
+ className: ""
42
+ }, /*#__PURE__*/React.createElement("i", {
43
+ className: "mr-2 sdocfont sdoc-revise"
44
+ }), /*#__PURE__*/React.createElement("span", {
45
+ className: "sdocfont sdoc-".concat(isShowMenu ? 'caret-up' : 'drop-down')
46
+ })), /*#__PURE__*/React.createElement(UncontrolledPopover, {
47
+ target: this.id,
48
+ className: "sdoc-common-menu-popover",
49
+ trigger: "legacy",
50
+ placement: "bottom-start",
51
+ hideArrow: true,
52
+ ref: this.setRef
53
+ }, /*#__PURE__*/React.createElement("div", {
54
+ className: "sdoc-common-menu-popover-container"
55
+ }, "123")));
56
+ }
57
+ }]);
58
+ return MoreRevisionOperations;
59
+ }(Component);
60
+ export default withTranslation('sdoc-editor')(MoreRevisionOperations);
@@ -0,0 +1,32 @@
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 PublishRevision = function PublishRevision(_ref) {
7
+ var t = _ref.t;
8
+ var isSdocRevision = context.getSetting('isSdocRevision');
9
+ var isPublished = context.getSetting('isPublished');
10
+ var repoID = context.getSetting('repoID');
11
+ var siteRoot = context.getSetting('siteRoot');
12
+ var publish = useCallback(function (event) {
13
+ event.stopPropagation();
14
+ event.nativeEvent.stopImmediatePropagation();
15
+ context.publishSdocRevision().then(function (res) {
16
+ var origin_file_path = res.data.origin_file_path;
17
+ window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
18
+ }).catch(function (error) {
19
+ toaster.danger(t('Error'));
20
+ });
21
+
22
+ // eslint-disable-next-line react-hooks/exhaustive-deps
23
+ }, []);
24
+ if (!isSdocRevision) return null;
25
+ if (isPublished) return null;
26
+ return /*#__PURE__*/React.createElement(Button, {
27
+ color: "success",
28
+ onClick: publish,
29
+ className: "ml-4"
30
+ }, t('Publish'));
31
+ };
32
+ export default withTranslation('sdoc-editor')(PublishRevision);
@@ -1,8 +1,8 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { Button } from 'reactstrap';
3
3
  import { withTranslation } from 'react-i18next';
4
- import context from '../../context';
5
- import toaster from '../../components/toast';
4
+ import context from '../../../context';
5
+ import toaster from '../../toast';
6
6
  var RevisionOperations = function RevisionOperations(_ref) {
7
7
  var t = _ref.t;
8
8
  var isSdocRevision = context.getSetting('isSdocRevision');
@@ -48,7 +48,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
48
48
  // eslint-disable-next-line react-hooks/exhaustive-deps
49
49
  }, []);
50
50
  if (!isSdocRevision) return startReviseBtn();
51
- return /*#__PURE__*/React.createElement(React.Fragment, null, startReviseBtn('mr-4'), !isPublished && revisionURL && /*#__PURE__*/React.createElement(Button, {
51
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isPublished && revisionURL && /*#__PURE__*/React.createElement(Button, {
52
52
  color: "success",
53
53
  className: "mr-4",
54
54
  onClick: viewChanges
@@ -0,0 +1,3 @@
1
+ .sdoc-toggle-revision-changes .custom-switch {
2
+ padding-left: 0;
3
+ }
@@ -0,0 +1,26 @@
1
+ import React, { useCallback } from 'react';
2
+ import { withTranslation } from 'react-i18next';
3
+ import { UncontrolledTooltip } from 'reactstrap';
4
+ import Switch from '../../../switch';
5
+ import './index.css';
6
+ var ViewChanges = function ViewChanges(_ref) {
7
+ var isShowChanges = _ref.isShowChanges,
8
+ t = _ref.t,
9
+ toggleViewChanges = _ref.toggleViewChanges;
10
+ var onToggleViewCHanges = useCallback(function () {
11
+ toggleViewChanges(!isShowChanges);
12
+
13
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14
+ }, [isShowChanges]);
15
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
16
+ id: "sdoc-toggle-revision-changes-container",
17
+ className: "h-100 ml-4 d-flex align-items-center "
18
+ }, /*#__PURE__*/React.createElement(Switch, {
19
+ checked: isShowChanges,
20
+ onChange: onToggleViewCHanges,
21
+ className: "sdoc-toggle-revision-changes d-flex align-items-center"
22
+ })), /*#__PURE__*/React.createElement(UncontrolledTooltip, {
23
+ target: "sdoc-toggle-revision-changes-container"
24
+ }, t('View_changes')));
25
+ };
26
+ export default withTranslation('sdoc-editor')(ViewChanges);
@@ -0,0 +1,14 @@
1
+ .seadoc-switch.small .custom-switch-indicator {
2
+ width: 22px;
3
+ height: 12px;
4
+ border-radius: 6px;
5
+ }
6
+
7
+ .seadoc-switch.small .custom-switch-indicator:before {
8
+ height: 8px;
9
+ width: 8px;
10
+ }
11
+
12
+ .seadoc-switch.small .custom-switch-input:checked~.custom-switch-indicator:before {
13
+ left: 12px;
14
+ }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+ import './index.css';
4
+ function Switch(props) {
5
+ var onChange = props.onChange,
6
+ checked = props.checked,
7
+ placeholder = props.placeholder,
8
+ disabled = props.disabled,
9
+ className = props.className,
10
+ size = props.size;
11
+ return /*#__PURE__*/React.createElement("div", {
12
+ className: classnames('seadoc-switch position-relative', className, size)
13
+ }, /*#__PURE__*/React.createElement("label", {
14
+ className: "custom-switch"
15
+ }, /*#__PURE__*/React.createElement("input", {
16
+ className: "custom-switch-input",
17
+ type: "checkbox",
18
+ checked: checked,
19
+ onChange: onChange,
20
+ name: "custom-switch-checkbox",
21
+ disabled: disabled
22
+ }), placeholder && /*#__PURE__*/React.createElement("span", {
23
+ className: "custom-switch-description text-truncate"
24
+ }, placeholder), /*#__PURE__*/React.createElement("span", {
25
+ className: "custom-switch-indicator"
26
+ })));
27
+ }
28
+ export default Switch;
package/dist/context.js CHANGED
@@ -139,6 +139,12 @@ var Context = /*#__PURE__*/function () {
139
139
  var docUuid = this.getSetting('docUuid');
140
140
  return this.api.sdocPublishRevision(docUuid);
141
141
  }
142
+ }, {
143
+ key: "getSeadocRevisionDownloadLinks",
144
+ value: function getSeadocRevisionDownloadLinks() {
145
+ var docUuid = this.getSetting('docUuid');
146
+ return this.api.getSeadocRevisionDownloadLinks(docUuid);
147
+ }
142
148
  }]);
143
149
  return Context;
144
150
  }();
@@ -1,10 +1,5 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _inherits from "@babel/runtime/helpers/esm/inherits";
5
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- 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; }
7
- import React from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useCallback, useEffect, useState } from 'react';
8
3
  import { SDocEditor } from '../basic-sdk';
9
4
  import Loading from '../components/loading';
10
5
  import DocInfo from '../components/doc-info';
@@ -12,116 +7,131 @@ import DocOperations from '../components/doc-operations';
12
7
  import Layout, { Header, Content } from '../layout';
13
8
  import { generateDefaultDocContent } from '../utils';
14
9
  import context from '../context';
10
+ import DiffViewer from './diff-viewer';
15
11
  import '../assets/css/simple-editor.css';
16
- var SimpleEditor = /*#__PURE__*/function (_React$Component) {
17
- _inherits(SimpleEditor, _React$Component);
18
- var _super = _createSuper(SimpleEditor);
19
- function SimpleEditor(props) {
20
- var _this;
21
- _classCallCheck(this, SimpleEditor);
22
- _this = _super.call(this, props);
23
- _this.onValueChanged = function (value) {
24
- _this.isValueChanged = true;
25
- _this.value = value;
26
- };
27
- _this.onSave = function () {
28
- if (_this.isValueChanged) {
29
- _this.isValueChanged = false;
30
- var content = {
31
- version: _this.state.document.version,
32
- children: _this.value
12
+ var SimpleEditor = function SimpleEditor(_ref) {
13
+ var isStarred = _ref.isStarred;
14
+ var _useState = useState(false),
15
+ _useState2 = _slicedToArray(_useState, 2),
16
+ isContextInit = _useState2[0],
17
+ setContextInit = _useState2[1];
18
+ var _useState3 = useState(false),
19
+ _useState4 = _slicedToArray(_useState3, 2),
20
+ isShowChanges = _useState4[0],
21
+ setShowChanges = _useState4[1];
22
+ var _useState5 = useState(''),
23
+ _useState6 = _slicedToArray(_useState5, 2),
24
+ errorMessage = _useState6[0],
25
+ setErrorMessage = _useState6[1];
26
+ var _useState7 = useState(null),
27
+ _useState8 = _slicedToArray(_useState7, 2),
28
+ document = _useState8[0],
29
+ setDocument = _useState8[1];
30
+ var _useState9 = useState(null),
31
+ _useState10 = _slicedToArray(_useState9, 2),
32
+ currentContent = _useState10[0],
33
+ setCurrentContent = _useState10[1];
34
+ var _useState11 = useState(null),
35
+ _useState12 = _slicedToArray(_useState11, 2),
36
+ lastContent = _useState12[0],
37
+ setLastContent = _useState12[1];
38
+ useEffect(function () {
39
+ context.initApi();
40
+ context.getFileContent().then(function (res) {
41
+ var result = res.data || generateDefaultDocContent();
42
+ if (result && !result.children) {
43
+ result = {
44
+ version: 0,
45
+ children: result.content,
46
+ cursors: result.cursors || {}
33
47
  };
34
- context.saveContent(JSON.stringify(content)).then(function (res) {
35
- // eslint-disable-next-line
36
- console.log('saved success');
37
- });
38
- }
39
- };
40
- _this.state = {
41
- isContextInit: false,
42
- errorMessage: null,
43
- document: null,
44
- isSaved: false,
45
- isSaving: false
46
- };
47
- _this.saveTimer = null;
48
- return _this;
49
- }
50
- _createClass(SimpleEditor, [{
51
- key: "componentDidMount",
52
- value: function () {
53
- var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
54
- var contentRes, result;
55
- return _regeneratorRuntime().wrap(function _callee$(_context) {
56
- while (1) switch (_context.prev = _context.next) {
57
- case 0:
58
- context.initApi();
59
- _context.prev = 1;
60
- _context.next = 4;
61
- return context.getFileContent();
62
- case 4:
63
- contentRes = _context.sent;
64
- result = contentRes.data || generateDefaultDocContent();
65
- if (result && !result.children) {
66
- result = {
67
- version: 0,
68
- children: result.content,
69
- cursors: result.cursors || {}
70
- };
71
- }
72
- this.setState({
73
- isContextInit: true,
74
- document: result
75
- });
76
- _context.next = 14;
77
- break;
78
- case 10:
79
- _context.prev = 10;
80
- _context.t0 = _context["catch"](1);
81
- // eslint-disable-next-line
82
- console.log(_context.t0);
83
- this.setState({
84
- isContextInit: true,
85
- errorMessage: 'load doc content error',
86
- document: null
87
- });
88
- case 14:
89
- case "end":
90
- return _context.stop();
91
- }
92
- }, _callee, this, [[1, 10]]);
93
- }));
94
- function componentDidMount() {
95
- return _componentDidMount.apply(this, arguments);
96
- }
97
- return componentDidMount;
98
- }()
99
- }, {
100
- key: "render",
101
- value: function render() {
102
- var _this$state = this.state,
103
- isContextInit = _this$state.isContextInit,
104
- errorMessage = _this$state.errorMessage,
105
- document = _this$state.document;
106
- if (!isContextInit) {
107
- return /*#__PURE__*/React.createElement(Loading, null);
108
48
  }
109
- if (errorMessage) {
110
- return /*#__PURE__*/React.createElement("div", {
111
- className: "d-flex justify-content-center"
112
- }, errorMessage);
113
- }
114
- var isOpenSocket = context.getSetting('isOpenSocket');
115
- return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, {
116
- isStarred: this.props.isStarred
117
- }), /*#__PURE__*/React.createElement(DocOperations, null)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
118
- config: context.getEditorConfig(),
119
- document: document,
120
- isOpenSocket: isOpenSocket,
121
- onValueChanged: this.onValueChanged
122
- })));
49
+ setDocument(result);
50
+ setContextInit(true);
51
+ }).catch(function (error) {
52
+ // eslint-disable-next-line
53
+ console.log(error);
54
+ setErrorMessage('load doc content error');
55
+ setDocument(null);
56
+ setContextInit(true);
57
+ });
58
+ }, []);
59
+ var toggleViewChanges = useCallback(function (isShowChanges) {
60
+ setContextInit(false);
61
+ if (isShowChanges) {
62
+ context.getSeadocRevisionDownloadLinks().then(function (res) {
63
+ var _res$data = res.data,
64
+ fileDownloadLink = _res$data.file_download_link,
65
+ originFileDownloadLink = _res$data.origin_file_download_link;
66
+ fetch(fileDownloadLink).then(function (res) {
67
+ return res.json();
68
+ }).then(function (revisionContent) {
69
+ fetch(originFileDownloadLink).then(function (res) {
70
+ return res.json();
71
+ }).then(function (originContent) {
72
+ setCurrentContent(revisionContent);
73
+ setLastContent(originContent);
74
+ setErrorMessage(null);
75
+ setContextInit(true);
76
+ setShowChanges(true);
77
+ }).catch(function (error) {
78
+ setErrorMessage('load doc content error');
79
+ setContextInit(true);
80
+ setShowChanges(true);
81
+ });
82
+ }).catch(function (error) {
83
+ setErrorMessage('load doc content error');
84
+ setContextInit(true);
85
+ setShowChanges(true);
86
+ });
87
+ }).catch(function (error) {
88
+ setErrorMessage('load doc content error');
89
+ setContextInit(true);
90
+ setShowChanges(true);
91
+ });
92
+ } else {
93
+ context.getFileContent().then(function (res) {
94
+ var result = res.data || generateDefaultDocContent();
95
+ if (result && !result.children) {
96
+ result = {
97
+ version: 0,
98
+ children: result.content,
99
+ cursors: result.cursors || {}
100
+ };
101
+ }
102
+ setDocument(result);
103
+ setShowChanges(false);
104
+ setContextInit(true);
105
+ }).catch(function (error) {
106
+ // eslint-disable-next-line
107
+ console.log(error);
108
+ setErrorMessage('load doc content error');
109
+ setDocument(null);
110
+ setShowChanges(false);
111
+ setContextInit(true);
112
+ });
123
113
  }
124
- }]);
125
- return SimpleEditor;
126
- }(React.Component);
114
+ }, []);
115
+ if (!isContextInit) {
116
+ return /*#__PURE__*/React.createElement(Loading, null);
117
+ }
118
+ if (errorMessage) {
119
+ return /*#__PURE__*/React.createElement("div", {
120
+ className: "d-flex justify-content-center"
121
+ }, errorMessage);
122
+ }
123
+ return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement(DocInfo, {
124
+ isStarred: isStarred
125
+ }), /*#__PURE__*/React.createElement(DocOperations, {
126
+ isShowChanges: isShowChanges,
127
+ toggleViewChanges: toggleViewChanges
128
+ })), /*#__PURE__*/React.createElement(Content, null, isShowChanges ? /*#__PURE__*/React.createElement(DiffViewer, {
129
+ currentContent: currentContent,
130
+ lastContent: lastContent
131
+ }) : /*#__PURE__*/React.createElement(SDocEditor, {
132
+ config: context.getEditorConfig(),
133
+ document: document,
134
+ isOpenSocket: context.getSetting('isOpenSocket')
135
+ })));
136
+ };
127
137
  export default SimpleEditor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.77",
3
+ "version": "0.1.78beta1",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -3,6 +3,8 @@
3
3
  "Italic": "斜体",
4
4
  "Underline": "下划线",
5
5
  "Strikethrough": "中划线",
6
+ "Superscript": "上标",
7
+ "Subscript": "下标",
6
8
  "Inline_code": "代码",
7
9
  "Header_one": "一级标题",
8
10
  "Header_two": "二级标题",
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: "sdocfont"; /* Project id 4097705 */
3
- src: url('./sdoc-editor-font/iconfont.eot?t=1689301494065'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1689301494065#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1689301494065') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1689301494065') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1689301494065') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1689301494065#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1689461796012'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1689461796012#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1689461796012') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1689461796012') format('woff'),
7
+ url('iconfont.ttf?t=1689461796012') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1689461796012#sdocfont') format('svg');
9
9
  }
10
10
 
11
11
  .sdocfont {