@seafile/sdoc-editor 0.1.30 → 0.1.32

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.
@@ -0,0 +1,19 @@
1
+ .sdoc-diff {
2
+ padding: 0 5px;
3
+ margin: 0 -5px;
4
+ overflow: hidden;
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
+ }
@@ -0,0 +1,29 @@
1
+ export var BLOCKQUOTE = 'blockquote';
2
+ export var BOLD = 'bold';
3
+ export var ITALIC = 'italic';
4
+ export var HEADER = 'header';
5
+ export var HEADER1 = 'header1';
6
+ export var HEADER2 = 'header2';
7
+ export var HEADER3 = 'header3';
8
+ export var HEADER4 = 'header4';
9
+ export var HEADER5 = 'header5';
10
+ export var HEADER6 = 'header6';
11
+ export var ORDERED_LIST = 'ordered_list';
12
+ export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
13
+ export var LIST_ITEM = 'list-item';
14
+ export var LIST_LIC = 'list-lic'; // placeholder
15
+ export var CHECK_LIST = 'check-list';
16
+ export var CHECK_LIST_ITEM = 'check-list-item';
17
+ export var PARAGRAPH = 'paragraph';
18
+ export var LINK = 'link';
19
+ export var HTML = 'html';
20
+ export var CODE_BLOCK = 'code-block';
21
+ export var CODE_LINE = 'code-line';
22
+ export var IMAGE = 'image';
23
+ export var TABLE = 'table';
24
+ export var TABLE_CELL = 'table-cell';
25
+ export var TABLE_ROW = 'table-row';
26
+ export var FORMULA = 'formula';
27
+ export var COLUMN = 'column';
28
+ export var TEXT_STYLE = 'text-style';
29
+ export var BOLD_ITALIC = 'bold-italic';
@@ -1,35 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  var _MENUS_CONFIG_MAP, _HEADER_TITLE_MAP;
3
3
  // extension plugin
4
- export var BLOCKQUOTE = 'blockquote';
5
- export var BOLD = 'bold';
6
- export var ITALIC = 'italic';
7
- export var HEADER = 'header';
8
- export var HEADER1 = 'header1';
9
- export var HEADER2 = 'header2';
10
- export var HEADER3 = 'header3';
11
- export var HEADER4 = 'header4';
12
- export var HEADER5 = 'header5';
13
- export var HEADER6 = 'header6';
14
- export var ORDERED_LIST = 'ordered_list';
15
- export var UNORDERED_LIST = 'unordered_list'; // unordered_list can not work
16
- export var LIST_ITEM = 'list-item';
17
- export var LIST_LIC = 'list-lic'; // placeholder
18
- export var CHECK_LIST = 'check-list';
19
- export var CHECK_LIST_ITEM = 'check-list-item';
20
- export var PARAGRAPH = 'paragraph';
21
- export var LINK = 'link';
22
- export var HTML = 'html';
23
- export var CODE_BLOCK = 'code-block';
24
- export var CODE_LINE = 'code-line';
25
- export var IMAGE = 'image';
26
- export var TABLE = 'table';
27
- export var TABLE_CELL = 'table-cell';
28
- export var TABLE_ROW = 'table-row';
29
- export var FORMULA = 'formula';
30
- export var COLUMN = 'column';
31
- export var TEXTSTYLE = 'text-style';
32
- export var BOLD_ITALIC = 'bold-italic';
4
+ import * as ELEMENT_TYPE from './element-type';
5
+ import { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC } from './element-type';
33
6
 
34
7
  // history
35
8
  export var UNDO = 'undo';
@@ -64,7 +37,7 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
64
37
  id: "sdoc_".concat(IMAGE),
65
38
  iconClass: 'iconfont icon-image',
66
39
  text: 'insert_image'
67
- }), _defineProperty(_MENUS_CONFIG_MAP, TEXTSTYLE, [{
40
+ }), _defineProperty(_MENUS_CONFIG_MAP, TEXT_STYLE, [{
68
41
  id: ITALIC,
69
42
  iconClass: 'iconfont icon-italic',
70
43
  text: 'italic',
@@ -85,4 +58,11 @@ export var MENUS_CONFIG_MAP = (_MENUS_CONFIG_MAP = {}, _defineProperty(_MENUS_CO
85
58
  text: 'redo',
86
59
  type: 'redo'
87
60
  }), _MENUS_CONFIG_MAP);
88
- export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
61
+ export var HEADER_TITLE_MAP = (_HEADER_TITLE_MAP = {}, _defineProperty(_HEADER_TITLE_MAP, HEADER1, 'header_one'), _defineProperty(_HEADER_TITLE_MAP, HEADER2, 'header_two'), _defineProperty(_HEADER_TITLE_MAP, HEADER3, 'header_three'), _defineProperty(_HEADER_TITLE_MAP, HEADER4, 'header_four'), _defineProperty(_HEADER_TITLE_MAP, HEADER5, 'header_five'), _defineProperty(_HEADER_TITLE_MAP, HEADER6, 'header_six'), _defineProperty(_HEADER_TITLE_MAP, PARAGRAPH, 'paragraph'), _HEADER_TITLE_MAP);
62
+ export var DIFF_TYPE = {
63
+ ADD: 'add',
64
+ DELETE: 'delete',
65
+ MODIFY: 'modify',
66
+ COMMON: 'common'
67
+ };
68
+ export { BLOCKQUOTE, BOLD, ITALIC, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, PARAGRAPH, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, BOLD_ITALIC, ELEMENT_TYPE };
@@ -5,6 +5,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
7
  import Lightbox from '@seafile/react-image-lightbox';
8
+ import { getImageURL } from '../helpers';
8
9
  import '@seafile/react-image-lightbox/style.css';
9
10
  var ImagePreviewer = /*#__PURE__*/function (_React$Component) {
10
11
  _inherits(ImagePreviewer, _React$Component);
@@ -19,7 +20,8 @@ var ImagePreviewer = /*#__PURE__*/function (_React$Component) {
19
20
  while (nodes && nodeIndex <= nodes.length - 1) {
20
21
  var currentNode = nodes[nodeIndex];
21
22
  if (currentNode.type === 'image') {
22
- currentNode.data.src && list.push(currentNode.data.src);
23
+ var url = getImageURL(currentNode.data.src);
24
+ url && list.push(url);
23
25
  } else {
24
26
  list.push.apply(list, _toConsumableArray(_this.getImageNodes(currentNode.children)));
25
27
  }
@@ -1,8 +1,10 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import urlJoin from 'url-join';
3
4
  import { Editor, Range, Transforms } from '@seafile/slate';
4
5
  import { BLOCKQUOTE, CODE_BLOCK, IMAGE, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
5
6
  import { generateEmptyElement, getNodeType } from '../../core';
7
+ import context from '../../../../context';
6
8
  export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
7
9
  var selection = editor.selection;
8
10
  if (selection === null) return true;
@@ -51,4 +53,10 @@ export var updateImage = function updateImage(editor, data) {
51
53
  at: editor.selection,
52
54
  voids: true
53
55
  });
56
+ };
57
+ export var getImageURL = function getImageURL(url) {
58
+ if (url && url.startsWith('http')) return url;
59
+ var serviceUrl = context.getSetting('serviceUrl');
60
+ var assetsUrl = context.getSetting('assetsUrl');
61
+ return urlJoin(serviceUrl, assetsUrl, url);
54
62
  };
@@ -7,10 +7,8 @@ import { useSelected } from '@seafile/slate-react';
7
7
  import React from 'react';
8
8
  import classNames from 'classnames';
9
9
  import { withTranslation } from 'react-i18next';
10
- import urlJoin from 'url-join';
11
- import { updateImage } from './helpers';
10
+ import { getImageURL, updateImage } from './helpers';
12
11
  import ImagePreviewer from './dialogs/image-previewer';
13
- import context from '../../../../context';
14
12
  var Image = /*#__PURE__*/function (_React$Component) {
15
13
  _inherits(Image, _React$Component);
16
14
  var _super = _createSuper(Image);
@@ -89,13 +87,6 @@ var Image = /*#__PURE__*/function (_React$Component) {
89
87
  return _this;
90
88
  }
91
89
  _createClass(Image, [{
92
- key: "getImageURL",
93
- value: function getImageURL(url) {
94
- var serviceUrl = context.getSetting('serviceUrl');
95
- var assetsUrl = context.getSetting('assetsUrl');
96
- return urlJoin(serviceUrl, assetsUrl, url);
97
- }
98
- }, {
99
90
  key: "render",
100
91
  value: function render() {
101
92
  var _this$props2 = this.props,
@@ -116,7 +107,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
116
107
  }, attributes), /*#__PURE__*/React.createElement("img", {
117
108
  className: imageClassName,
118
109
  ref: this.setImageRef,
119
- src: this.getImageURL(data.src),
110
+ src: getImageURL(data.src),
120
111
  style: imageStyle,
121
112
  draggable: false,
122
113
  alt: ""
@@ -135,7 +126,7 @@ var Image = /*#__PURE__*/function (_React$Component) {
135
126
  className: "image-size",
136
127
  contentEditable: false
137
128
  }, /*#__PURE__*/React.createElement("span", null, t('width'), ':', parseInt(this.state.width || this.image.clientWidth)), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('height'), ':', this.image.clientHeight)), children), isShowImagePreview && /*#__PURE__*/React.createElement(ImagePreviewer, {
138
- imageUrl: data.src,
129
+ imageUrl: getImageURL(data.src),
139
130
  editor: this.props.editor,
140
131
  toggleImagePreviewer: this.setFullScreen
141
132
  }));
@@ -4,7 +4,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
- import { TEXTSTYLE, MENUS_CONFIG_MAP } from '../../../constants';
7
+ import { TEXT_STYLE, MENUS_CONFIG_MAP } from '../../../constants';
8
8
  import { focusEditor } from '../../../core';
9
9
  import { MenuItem } from '../../../menu';
10
10
  import { getValue, isMenuDisabled, addMark, removeMark } from '../helpers';
@@ -68,7 +68,7 @@ var TextStyleMenuList = /*#__PURE__*/function (_React$Component) {
68
68
  value: function render() {
69
69
  var textStyleMenuList = this.getTextStyleMenuList();
70
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, textStyleMenuList.map(function (menuItem, index) {
71
- var menuItemConfig = MENUS_CONFIG_MAP[TEXTSTYLE][index];
71
+ var menuItemConfig = MENUS_CONFIG_MAP[TEXT_STYLE][index];
72
72
  var menuItemProps = _objectSpread(_objectSpread({}, menuItem), menuItemConfig);
73
73
  return /*#__PURE__*/React.createElement(MenuItem, Object.assign({
74
74
  key: index
@@ -0,0 +1,191 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
4
+ import ObjectUtils from './object-utils';
5
+ var getElementIndexInDiffDocument = function getElementIndexInDiffDocument(diffValue, element) {
6
+ return diffValue.findIndex(function (item) {
7
+ return item.id === element.id;
8
+ });
9
+ };
10
+ var getNearestElementIndex = function getNearestElementIndex(diff, oldDocument, elementId) {
11
+ var diffValue = diff.value;
12
+ var elementInDiffDocumentIdx = getElementIndexInDiffDocument(diffValue, elementId);
13
+ if (elementInDiffDocumentIdx > -1) return elementInDiffDocumentIdx + 1;
14
+ var oldElementCount = oldDocument.length;
15
+ var elementInOldDocumentIndex = oldDocument.findIndex(function (item) {
16
+ return item.id === elementId;
17
+ });
18
+ var leftIndex = elementInOldDocumentIndex - 1;
19
+ leftIndex = leftIndex === -1 ? 0 : leftIndex;
20
+ var rightIndex = elementInOldDocumentIndex + 1;
21
+ rightIndex = rightIndex === oldElementCount - 1 ? oldElementCount - 1 : rightIndex;
22
+ while (elementInDiffDocumentIdx === -1 && leftIndex > -2 && rightIndex < oldElementCount + 1) {
23
+ if (leftIndex > -1) {
24
+ var oldLeftElement = oldDocument[leftIndex];
25
+ elementInDiffDocumentIdx = getElementIndexInDiffDocument(diffValue, oldLeftElement);
26
+ if (elementInDiffDocumentIdx > -1) {
27
+ return elementInDiffDocumentIdx + 1;
28
+ }
29
+ }
30
+ if (rightIndex < oldElementCount) {
31
+ var oldLastElement = oldDocument[rightIndex];
32
+ elementInDiffDocumentIdx = getElementIndexInDiffDocument(diffValue, oldLastElement);
33
+ if (elementInDiffDocumentIdx > -1) {
34
+ return elementInDiffDocumentIdx;
35
+ }
36
+ }
37
+ leftIndex--;
38
+ rightIndex++;
39
+ if (leftIndex === -2 && rightIndex < oldElementCount) {
40
+ leftIndex = -1;
41
+ }
42
+ if (rightIndex === oldElementCount && leftIndex > -1) {
43
+ rightIndex = oldElementCount;
44
+ }
45
+ }
46
+ return diffValue.length - 1;
47
+ };
48
+ var updateDiffValue = function updateDiffValue(diff, element, oldElement) {
49
+ if (!diff || !element || !oldElement) return;
50
+ if (ObjectUtils.isSameObject(element, oldElement)) {
51
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
52
+ diff_type: DIFF_TYPE.COMMON
53
+ }));
54
+ return;
55
+ }
56
+ var currentElementType = element.type;
57
+ var oldElementType = oldElement.type;
58
+ if (currentElementType !== oldElementType) {
59
+ diff.changes.push(oldElement.id);
60
+ diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
61
+ diff_type: DIFF_TYPE.DELETE
62
+ }));
63
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
64
+ diff_type: DIFF_TYPE.ADD
65
+ }));
66
+ return;
67
+ }
68
+ switch (currentElementType) {
69
+ case ELEMENT_TYPE.PARAGRAPH:
70
+ case ELEMENT_TYPE.HEADER1:
71
+ case ELEMENT_TYPE.HEADER2:
72
+ case ELEMENT_TYPE.HEADER3:
73
+ case ELEMENT_TYPE.HEADER4:
74
+ case ELEMENT_TYPE.HEADER5:
75
+ case ELEMENT_TYPE.HEADER6:
76
+ case ELEMENT_TYPE.BLOCKQUOTE:
77
+ case ELEMENT_TYPE.LINK:
78
+ case ELEMENT_TYPE.CHECK_LIST_ITEM:
79
+ case ELEMENT_TYPE.CODE_BLOCK:
80
+ case ELEMENT_TYPE.IMAGE:
81
+ {
82
+ diff.changes.push(oldElement.id);
83
+ diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
84
+ diff_type: DIFF_TYPE.DELETE
85
+ }));
86
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
87
+ diff_type: DIFF_TYPE.ADD
88
+ }));
89
+ break;
90
+ }
91
+ case ELEMENT_TYPE.ORDERED_LIST:
92
+ case ELEMENT_TYPE.UNORDERED_LIST:
93
+ case ELEMENT_TYPE.LIST_ITEM:
94
+ case ELEMENT_TYPE.LIST_LIC:
95
+ {
96
+ var _diff$changes;
97
+ var _getElementDiffValue = getElementDiffValue(element.children, oldElement.children),
98
+ diffValue = _getElementDiffValue.value,
99
+ diffChanges = _getElementDiffValue.changes;
100
+ (_diff$changes = diff.changes).push.apply(_diff$changes, _toConsumableArray(diffChanges));
101
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
102
+ children: diffValue,
103
+ diff_type: DIFF_TYPE.MODIFY
104
+ }));
105
+ break;
106
+ }
107
+ default:
108
+ {
109
+ diff.changes.push(oldElement.id);
110
+ diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
111
+ diff_type: DIFF_TYPE.DELETE
112
+ }));
113
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
114
+ diff_type: DIFF_TYPE.ADD
115
+ }));
116
+ break;
117
+ }
118
+ }
119
+ };
120
+
121
+ /**
122
+ * params:
123
+ * currentValue: current version document content
124
+ * oldValue: last version document content
125
+ * return { value: [], change: [] }
126
+ */
127
+ var getElementDiffValue = function getElementDiffValue(currentContent, oldContent) {
128
+ // init
129
+ var diff = {
130
+ value: [],
131
+ changes: []
132
+ };
133
+ var currentContentMap = {};
134
+ var oldContentMap = {};
135
+ currentContent.forEach(function (element) {
136
+ currentContentMap[element.id] = element;
137
+ });
138
+ oldContent.forEach(function (element) {
139
+ oldContentMap[element.id] = element;
140
+ });
141
+
142
+ // generator diff elements
143
+ for (var i = 0; i < currentContent.length; i++) {
144
+ var element = currentContent[i];
145
+ var isAdded = !oldContentMap[element.id]; // added
146
+ if (isAdded) {
147
+ diff.changes.push(element.id);
148
+ diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
149
+ diff_type: DIFF_TYPE.ADD
150
+ }));
151
+ continue;
152
+ }
153
+ updateDiffValue(diff, element, oldContentMap[element.id]);
154
+ }
155
+ oldContent.forEach(function (oldElement) {
156
+ var oldElementId = oldElement.id;
157
+ if (!currentContentMap[oldElementId]) {
158
+ // deleted
159
+ diff.changes.push(oldElementId);
160
+ var elementIndex = getNearestElementIndex(diff, oldContent, oldElementId);
161
+ diff.value.splice(elementIndex, 0, _objectSpread(_objectSpread({}, oldElement), {}, {
162
+ diff_type: DIFF_TYPE.DELETE
163
+ }));
164
+ }
165
+ });
166
+ return diff;
167
+ };
168
+
169
+ /**
170
+ * params:
171
+ * currentValue: current version document
172
+ * oldValue: last version document
173
+ * return { value: [], change: [] }
174
+ */
175
+ export var getDiff = function getDiff() {
176
+ var currentValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
177
+ children: []
178
+ };
179
+ var oldValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
180
+ children: []
181
+ };
182
+ var currentVersion = currentValue.version,
183
+ currentContent = currentValue.children;
184
+ var oldVersion = oldValue.version,
185
+ oldContent = oldValue.children;
186
+ if (currentVersion === oldVersion) return {
187
+ value: currentContent,
188
+ changes: []
189
+ };
190
+ return getElementDiffValue(currentContent, oldContent);
191
+ };
@@ -0,0 +1,57 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ var ObjectUtils = /*#__PURE__*/function () {
5
+ function ObjectUtils() {
6
+ _classCallCheck(this, ObjectUtils);
7
+ }
8
+ _createClass(ObjectUtils, null, [{
9
+ key: "getDataType",
10
+ value: function getDataType(data) {
11
+ var type = typeof data;
12
+ if (type !== 'object') {
13
+ return type;
14
+ }
15
+ return Object.prototype.toString.call(data).replace(/^\[object (\S+)\]$/, '$1');
16
+ }
17
+ }, {
18
+ key: "iterable",
19
+ value: function iterable(data) {
20
+ return ['Object', 'Array'].includes(this.getDataType(data));
21
+ }
22
+ }, {
23
+ key: "isObjectChanged",
24
+ value: function isObjectChanged(source, comparison, notIncludeKeys) {
25
+ var _this = this;
26
+ if (!this.iterable(source)) {
27
+ throw new Error("source should be a Object or Array , but got ".concat(this.getDataType(source)));
28
+ }
29
+ if (this.getDataType(source) !== this.getDataType(comparison)) {
30
+ return true;
31
+ }
32
+ var sourceKeys = Object.keys(source);
33
+ var comparisonKeys = Object.keys(_objectSpread(_objectSpread({}, source), comparison)).filter(function (key) {
34
+ return !notIncludeKeys.includes(key);
35
+ });
36
+ if (sourceKeys.length !== comparisonKeys.length) {
37
+ return true;
38
+ }
39
+ return comparisonKeys.some(function (key) {
40
+ if (_this.iterable(source[key])) {
41
+ return _this.isObjectChanged(source[key], comparison[key], notIncludeKeys);
42
+ } else {
43
+ return source[key] !== comparison[key];
44
+ }
45
+ });
46
+ }
47
+ }, {
48
+ key: "isSameObject",
49
+ value: function isSameObject(source, comparison) {
50
+ var notIncludeKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
51
+ if (!source || !comparison) return false;
52
+ return !this.isObjectChanged(source, comparison, notIncludeKeys);
53
+ }
54
+ }]);
55
+ return ObjectUtils;
56
+ }();
57
+ export default ObjectUtils;
@@ -0,0 +1,118 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
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
+ import React, { Component } from 'react';
7
+ import { Editable, Slate } from '@seafile/slate-react';
8
+ import editor, { renderLeaf, renderElement } from '../../basic-sdk/extension';
9
+ import withNodeId from '../../basic-sdk/node-id';
10
+ import { getDiff } from '../../basic-sdk/utils/diff';
11
+ import { DIFF_TYPE, ELEMENT_TYPE } from '../../basic-sdk/extension/constants';
12
+ import '../../assets/css/diff-viewer.css';
13
+ var DiffViewer = /*#__PURE__*/function (_Component) {
14
+ _inherits(DiffViewer, _Component);
15
+ var _super = _createSuper(DiffViewer);
16
+ function DiffViewer(_props) {
17
+ var _this;
18
+ _classCallCheck(this, DiffViewer);
19
+ _this = _super.call(this, _props);
20
+ _this.renderLeaf = function (props) {
21
+ return renderLeaf(props, _this.editor);
22
+ };
23
+ _this.renderElement = function (props) {
24
+ var element = props.element;
25
+ var diff_type = element.diff_type,
26
+ type = element.type;
27
+ if (diff_type === DIFF_TYPE.ADD) {
28
+ if (type === ELEMENT_TYPE.LIST_ITEM) {
29
+ return renderElement(_objectSpread(_objectSpread({}, props), {}, {
30
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
31
+ className: 'sdoc-diff-added'
32
+ })
33
+ }), _this.editor);
34
+ }
35
+ return /*#__PURE__*/React.createElement("div", {
36
+ className: "sdoc-diff sdoc-diff-added"
37
+ }, renderElement(_objectSpread(_objectSpread({}, props), {}, {
38
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
39
+ className: 'sdoc-diff-added'
40
+ })
41
+ }), _this.editor));
42
+ }
43
+ if (diff_type === DIFF_TYPE.DELETE) {
44
+ if (type === ELEMENT_TYPE.LIST_ITEM) {
45
+ return renderElement(_objectSpread(_objectSpread({}, props), {}, {
46
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
47
+ className: 'sdoc-diff-removed'
48
+ })
49
+ }), _this.editor);
50
+ }
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ className: "sdoc-diff sdoc-diff-removed"
53
+ }, renderElement(_objectSpread(_objectSpread({}, props), {}, {
54
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
55
+ className: 'sdoc-diff-removed'
56
+ })
57
+ }), _this.editor));
58
+ }
59
+ if (diff_type === DIFF_TYPE.MODIFY) {
60
+ if (type === ELEMENT_TYPE.ORDERED_LIST || type === ELEMENT_TYPE.UNORDERED_LIST) {
61
+ return renderElement(_objectSpread(_objectSpread({}, props), {}, {
62
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
63
+ className: 'sdoc-diff-modify'
64
+ })
65
+ }), _this.editor);
66
+ }
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ className: "sdoc-diff-modify"
69
+ }, renderElement(_objectSpread(_objectSpread({}, props), {}, {
70
+ attributes: _objectSpread(_objectSpread({}, props.attributes), {}, {
71
+ className: 'sdoc-diff-modify'
72
+ })
73
+ }), _this.editor));
74
+ }
75
+ return renderElement(props, _this.editor);
76
+ };
77
+ var currentContent = _props.currentContent,
78
+ lastContent = _props.lastContent;
79
+ _this.diff = currentContent ? getDiff(currentContent, lastContent) : {
80
+ value: [],
81
+ changes: []
82
+ };
83
+ _this.editor = withNodeId(editor);
84
+ return _this;
85
+ }
86
+ _createClass(DiffViewer, [{
87
+ key: "componentDidMount",
88
+ value: function componentDidMount() {
89
+ this.props.didMountCallback && this.props.didMountCallback(this.diff);
90
+ }
91
+ }, {
92
+ key: "render",
93
+ value: function render() {
94
+ return /*#__PURE__*/React.createElement("div", {
95
+ className: "sdoc-editor-container"
96
+ }, /*#__PURE__*/React.createElement("div", {
97
+ className: "sdoc-editor-content"
98
+ }, /*#__PURE__*/React.createElement("div", {
99
+ className: "flex-fill o-auto"
100
+ }, /*#__PURE__*/React.createElement(Slate, {
101
+ editor: this.editor,
102
+ value: this.diff.value,
103
+ onChange: function onChange() {}
104
+ }, /*#__PURE__*/React.createElement("div", {
105
+ className: "article mx-auto"
106
+ }, /*#__PURE__*/React.createElement(Editable, {
107
+ readOnly: true,
108
+ placeholder: "",
109
+ renderElement: this.renderElement,
110
+ renderLeaf: this.renderLeaf,
111
+ onDOMBeforeInput: function onDOMBeforeInput() {},
112
+ onKeyDown: function onKeyDown() {}
113
+ }))))));
114
+ }
115
+ }]);
116
+ return DiffViewer;
117
+ }(Component);
118
+ export default DiffViewer;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { SDocViewer } from '../../basic-sdk';
3
+ import { generateDefaultDocContent } from '../../utils';
4
+ function HistoryVersionViewer(props) {
5
+ var document = props.document;
6
+ return /*#__PURE__*/React.createElement(SDocViewer, {
7
+ document: document || generateDefaultDocContent()
8
+ });
9
+ }
10
+ export default HistoryVersionViewer;
@@ -0,0 +1,31 @@
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, { Component } from 'react';
6
+ import HistoryVersionViewer from './history-version-viewer';
7
+ import DiffViewer from './diff-viewer';
8
+ var Index = /*#__PURE__*/function (_Component) {
9
+ _inherits(Index, _Component);
10
+ var _super = _createSuper(Index);
11
+ function Index() {
12
+ _classCallCheck(this, Index);
13
+ return _super.apply(this, arguments);
14
+ }
15
+ _createClass(Index, [{
16
+ key: "render",
17
+ value: function render() {
18
+ var _this$props = this.props,
19
+ currentContent = _this$props.currentContent,
20
+ lastContent = _this$props.lastContent;
21
+ if (!lastContent) {
22
+ return /*#__PURE__*/React.createElement(HistoryVersionViewer, {
23
+ document: currentContent
24
+ });
25
+ }
26
+ return /*#__PURE__*/React.createElement(DiffViewer, this.props);
27
+ }
28
+ }]);
29
+ return Index;
30
+ }(Component);
31
+ export default Index;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "reactstrap": "8.9.0",
19
19
  "slugid": "3.2.0",
20
20
  "socket.io-client": "4.6.1",
21
- "url-join": "5.0.0",
21
+ "url-join": "4.0.1",
22
22
  "url-parse": "1.5.10",
23
23
  "uuid": "9.0.0"
24
24
  },