@seafile/sdoc-editor 0.1.60 → 0.1.62
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.
- package/dist/api/sdoc-server-api.js +52 -0
- package/dist/basic-sdk/assets/css/layout.css +32 -0
- package/dist/basic-sdk/comment/comment-context-provider.js +27 -0
- package/dist/basic-sdk/comment/comment-decorate.js +29 -0
- package/dist/basic-sdk/comment/comment-editor.js +73 -0
- package/dist/basic-sdk/comment/comment-item.js +93 -0
- package/dist/basic-sdk/comment/comment-list.js +128 -0
- package/dist/basic-sdk/comment/comment.js +64 -0
- package/dist/basic-sdk/comment/helper.js +44 -0
- package/dist/basic-sdk/comment/hooks/use-comment-context.js +11 -0
- package/dist/basic-sdk/comment/hooks/use-comment-mount.js +55 -0
- package/dist/basic-sdk/comment/index.js +12 -0
- package/dist/basic-sdk/comment/reducer/comment-reducer.js +82 -0
- package/dist/basic-sdk/comment/style.css +137 -0
- package/dist/basic-sdk/decorates/index.js +21 -0
- package/dist/basic-sdk/editor.js +23 -12
- package/dist/basic-sdk/extension/constants/index.js +8 -0
- package/dist/basic-sdk/extension/core/utils/index.js +7 -4
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +6 -3
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -2
- package/dist/basic-sdk/extension/plugins/table/constants/index.js +0 -2
- package/dist/basic-sdk/extension/plugins/table/helpers.js +13 -11
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +1 -0
- package/dist/basic-sdk/extension/plugins/table/render/table-root.js +15 -10
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +15 -7
- package/dist/basic-sdk/extension/render/render-element.js +17 -2
- package/dist/basic-sdk/extension/toolbar/index.js +3 -16
- package/dist/basic-sdk/highlight-decorate/index.js +5 -11
- package/dist/basic-sdk/hooks/use-scroll-context.js +10 -0
- package/dist/basic-sdk/hooks/use-selection-element.js +20 -0
- package/dist/basic-sdk/hooks/use-selection-position.js +34 -0
- package/dist/basic-sdk/hooks/use-selection-update.js +18 -0
- package/dist/basic-sdk/utils/diff-text.js +255 -0
- package/dist/basic-sdk/utils/diff.js +229 -142
- package/dist/basic-sdk/utils/document-utils.js +18 -0
- package/dist/basic-sdk/viewer.js +48 -66
- package/dist/constants/index.js +2 -1
- package/dist/context.js +20 -0
- package/dist/pages/diff-viewer/diff-viewer.js +43 -114
- package/dist/pages/diff-viewer/history-version-viewer.js +6 -1
- package/package.json +2 -2
|
@@ -1,122 +1,206 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import
|
|
4
|
+
import slugid from 'slugid';
|
|
5
|
+
import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../../basic-sdk/extension/constants';
|
|
4
6
|
import ObjectUtils from './object-utils';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import DiffText from './diff-text';
|
|
8
|
+
import { normalizeChildren } from './document-utils';
|
|
9
|
+
|
|
10
|
+
// ignore
|
|
11
|
+
var IGNORE_KEYS = ['BOLD', 'ITALIC', 'columns', 'minHeight', 'language', 'white_space'];
|
|
12
|
+
var generatorDiffTextElement = function generatorDiffTextElement(textElement, diffType) {
|
|
13
|
+
var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
14
|
+
if (!textElement) return null;
|
|
15
|
+
if (!diffType) return textElement;
|
|
16
|
+
var id = textElement.id;
|
|
17
|
+
return _objectSpread(_objectSpread({}, textElement), {}, _defineProperty({
|
|
18
|
+
id: id || slugid.nice()
|
|
19
|
+
}, diffType, true), style);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Depth facilitates each child node, adding diffType to each end node
|
|
23
|
+
var generatorDiffElement = function generatorDiffElement(element, diffType) {
|
|
24
|
+
var _objectSpread3;
|
|
25
|
+
var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
26
|
+
if (!element) return null;
|
|
27
|
+
if (!Array.isArray(element.children) || element.children.length === 0) {
|
|
28
|
+
return generatorDiffTextElement(element, diffType, style);
|
|
29
|
+
}
|
|
30
|
+
return _objectSpread(_objectSpread({}, element), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, diffType, true), _defineProperty(_objectSpread3, "children", element.children.map(function (item) {
|
|
31
|
+
return generatorDiffElement(item, diffType, style);
|
|
32
|
+
})), _objectSpread3));
|
|
10
33
|
};
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
var generateIdMapAndIds = function generateIdMapAndIds(elements) {
|
|
35
|
+
var map = {};
|
|
36
|
+
var ids = [];
|
|
37
|
+
if (!Array.isArray(elements) || elements.length === 0) return {
|
|
38
|
+
map: map,
|
|
39
|
+
ids: ids
|
|
40
|
+
};
|
|
41
|
+
elements.forEach(function (element) {
|
|
42
|
+
ids.push(element.id);
|
|
43
|
+
map[element.id] = element;
|
|
18
44
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
return {
|
|
46
|
+
map: map,
|
|
47
|
+
ids: ids
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var hasChildren = function hasChildren(element) {
|
|
51
|
+
if (!element) return false;
|
|
52
|
+
if (!Array.isArray(element.children) || element.children.length === 0) return false;
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// id diffs
|
|
57
|
+
var getIdDiffs = function getIdDiffs(oldIds, newIds) {
|
|
58
|
+
var diff = new DiffText(oldIds, newIds);
|
|
59
|
+
return diff.getDiffs();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// text diffs
|
|
63
|
+
var getTextDiff = function getTextDiff(element, oldElement, diff) {
|
|
64
|
+
var newText = element.text;
|
|
65
|
+
var oldText = oldElement.text;
|
|
66
|
+
var textDiff = new DiffText(oldText || '', newText || '');
|
|
67
|
+
var textDiffs = textDiff.getDiffs();
|
|
68
|
+
var newChildren = [];
|
|
69
|
+
textDiffs.forEach(function (item, index) {
|
|
70
|
+
var id = "".concat(element.id || slugid.nice(), "-").concat(index);
|
|
71
|
+
var elementItem = {
|
|
72
|
+
id: id,
|
|
73
|
+
text: item.value
|
|
74
|
+
};
|
|
75
|
+
if (item.added) {
|
|
76
|
+
diff.changes.push(id);
|
|
77
|
+
var commonChild = generatorDiffTextElement(elementItem, 'ADD', ADDED_STYLE);
|
|
78
|
+
newChildren.push(commonChild);
|
|
79
|
+
} else if (item.removed) {
|
|
80
|
+
diff.changes.push(id);
|
|
81
|
+
var _commonChild = generatorDiffTextElement(elementItem, 'DELETE', DELETED_STYLE);
|
|
82
|
+
newChildren.push(_commonChild);
|
|
83
|
+
} else {
|
|
84
|
+
var _commonChild2 = generatorDiffTextElement(elementItem);
|
|
85
|
+
newChildren.push(_commonChild2);
|
|
45
86
|
}
|
|
87
|
+
});
|
|
88
|
+
return newChildren;
|
|
89
|
+
};
|
|
90
|
+
var getCommonDiff = function getCommonDiff(element, oldElement, diff) {
|
|
91
|
+
if (!hasChildren(element) && !hasChildren(oldElement)) {
|
|
92
|
+
var _newChildren = getTextDiff(element, oldElement, diff);
|
|
93
|
+
return [_objectSpread(_objectSpread({}, element), {}, {
|
|
94
|
+
children: _newChildren
|
|
95
|
+
})];
|
|
46
96
|
}
|
|
47
|
-
|
|
97
|
+
if (!hasChildren(element) || !hasChildren(oldElement)) {
|
|
98
|
+
var elementId = element.id || slugid.nice();
|
|
99
|
+
diff.changes.push("".concat(elementId, "_delete"));
|
|
100
|
+
return [generatorDiffElement(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
101
|
+
id: "".concat(elementId, "_delete")
|
|
102
|
+
}), 'DELETE', DELETED_STYLE), generatorDiffElement(_objectSpread(_objectSpread({}, element), {}, {
|
|
103
|
+
id: "".concat(elementId, "_add")
|
|
104
|
+
}), 'ADD', ADDED_STYLE)];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Content does not change
|
|
108
|
+
if (ObjectUtils.isSameObject(element, oldElement, [].concat(IGNORE_KEYS, ['type']))) {
|
|
109
|
+
return [element];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Compare content
|
|
113
|
+
var currentChildren = element.children;
|
|
114
|
+
var oldChildren = oldElement.children;
|
|
115
|
+
var _generateIdMapAndIds = generateIdMapAndIds(currentChildren),
|
|
116
|
+
currentMap = _generateIdMapAndIds.map,
|
|
117
|
+
currentIds = _generateIdMapAndIds.ids;
|
|
118
|
+
var _generateIdMapAndIds2 = generateIdMapAndIds(oldChildren),
|
|
119
|
+
oldMap = _generateIdMapAndIds2.map,
|
|
120
|
+
oldIds = _generateIdMapAndIds2.ids;
|
|
121
|
+
var idDiffs = getIdDiffs(oldIds, currentIds);
|
|
122
|
+
var newChildren = [];
|
|
123
|
+
idDiffs.forEach(function (idDiff) {
|
|
124
|
+
var ids = idDiff.value;
|
|
125
|
+
var isAdded = idDiff.added;
|
|
126
|
+
var isDelete = idDiff.removed;
|
|
127
|
+
ids.forEach(function (id) {
|
|
128
|
+
var newChildrenElement = currentMap[id];
|
|
129
|
+
var oldChildrenElement = oldMap[id];
|
|
130
|
+
if (isAdded) {
|
|
131
|
+
diff.changes.push(id);
|
|
132
|
+
newChildren.push(generatorDiffElement(newChildrenElement, 'ADD', ADDED_STYLE));
|
|
133
|
+
} else if (isDelete) {
|
|
134
|
+
diff.changes.push(id);
|
|
135
|
+
newChildren.push(generatorDiffElement(oldChildrenElement, 'DELETE', DELETED_STYLE));
|
|
136
|
+
} else {
|
|
137
|
+
if (ObjectUtils.isSameObject(newChildrenElement, oldChildrenElement, IGNORE_KEYS)) {
|
|
138
|
+
newChildren.push(newChildrenElement);
|
|
139
|
+
} else {
|
|
140
|
+
if (newChildrenElement.type === oldChildrenElement.type) {
|
|
141
|
+
if (!newChildrenElement.type) {
|
|
142
|
+
var textDiffs = getTextDiff(newChildrenElement, oldChildrenElement, diff);
|
|
143
|
+
newChildren.push.apply(newChildren, _toConsumableArray(textDiffs));
|
|
144
|
+
} else if (newChildrenElement.type === ELEMENT_TYPE.IMAGE) {
|
|
145
|
+
if (newChildrenElement.data.src === oldChildrenElement.data.src) {
|
|
146
|
+
newChildren.push(newChildrenElement);
|
|
147
|
+
} else {
|
|
148
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, element), {}, {
|
|
149
|
+
id: element.id + '_add'
|
|
150
|
+
}), 'ADD', ADDED_STYLE));
|
|
151
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, oldChildrenElement), {}, {
|
|
152
|
+
id: element.id + '_delete'
|
|
153
|
+
}), 'DELETE', DELETED_STYLE));
|
|
154
|
+
}
|
|
155
|
+
} else if (newChildrenElement.type === ELEMENT_TYPE.LINK) {
|
|
156
|
+
if (newChildrenElement.title !== oldChildrenElement.title) {
|
|
157
|
+
var diffElements = getCommonDiff(newChildrenElement, oldChildrenElement, diff);
|
|
158
|
+
newChildren.push.apply(newChildren, _toConsumableArray(diffElements));
|
|
159
|
+
} else if (newChildrenElement.href !== oldChildrenElement.href) {
|
|
160
|
+
diff.changes.push(oldChildrenElement.id + '_delete');
|
|
161
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, oldChildrenElement), {}, {
|
|
162
|
+
id: oldChildrenElement.id + '_delete'
|
|
163
|
+
}), 'DELETE', DELETED_STYLE));
|
|
164
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, newChildrenElement), {}, {
|
|
165
|
+
id: newChildrenElement.id + '_add'
|
|
166
|
+
}), 'ADD', ADDED_STYLE));
|
|
167
|
+
} else {
|
|
168
|
+
newChildren.push(newChildrenElement);
|
|
169
|
+
}
|
|
170
|
+
} else if (newChildrenElement.type === ELEMENT_TYPE.TABLE_ROW || newChildrenElement.type === ELEMENT_TYPE.TABLE_CELL) {
|
|
171
|
+
var newRows = getCommonDiff(newChildrenElement, oldChildrenElement, diff);
|
|
172
|
+
newChildren.push.apply(newChildren, _toConsumableArray(newRows));
|
|
173
|
+
} else {
|
|
174
|
+
var commonDiffs = getCommonDiff(newChildrenElement, oldChildrenElement, diff);
|
|
175
|
+
newChildren.push.apply(newChildren, _toConsumableArray(commonDiffs));
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
diff.changes.push(oldChildrenElement.id + '_delete');
|
|
179
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, oldChildrenElement), {}, {
|
|
180
|
+
id: oldChildrenElement.id + '_delete'
|
|
181
|
+
}), 'DELETE', DELETED_STYLE));
|
|
182
|
+
newChildren.push(generatorDiffTextElement(_objectSpread(_objectSpread({}, newChildrenElement), {}, {
|
|
183
|
+
id: newChildrenElement.id + '_add'
|
|
184
|
+
}), 'ADD', ADDED_STYLE));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
return [_objectSpread(_objectSpread({}, element), {}, {
|
|
191
|
+
children: newChildren
|
|
192
|
+
})];
|
|
48
193
|
};
|
|
49
194
|
var updateDiffValue = function updateDiffValue(diff, element, oldElement) {
|
|
50
195
|
if (!diff || !element || !oldElement) return;
|
|
51
|
-
if (ObjectUtils.isSameObject(element, oldElement)) {
|
|
52
|
-
diff.value.push(
|
|
53
|
-
diff_type: DIFF_TYPE.COMMON
|
|
54
|
-
}));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
var currentElementType = element.type;
|
|
58
|
-
var oldElementType = oldElement.type;
|
|
59
|
-
if (currentElementType !== oldElementType) {
|
|
60
|
-
diff.changes.push(oldElement.id);
|
|
61
|
-
diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
62
|
-
diff_type: DIFF_TYPE.DELETE
|
|
63
|
-
}));
|
|
64
|
-
diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
65
|
-
diff_type: DIFF_TYPE.ADD
|
|
66
|
-
}));
|
|
196
|
+
if (ObjectUtils.isSameObject(element, oldElement, IGNORE_KEYS)) {
|
|
197
|
+
diff.value.push(element);
|
|
67
198
|
return;
|
|
68
199
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
case ELEMENT_TYPE.HEADER3:
|
|
74
|
-
case ELEMENT_TYPE.HEADER4:
|
|
75
|
-
case ELEMENT_TYPE.HEADER5:
|
|
76
|
-
case ELEMENT_TYPE.HEADER6:
|
|
77
|
-
case ELEMENT_TYPE.BLOCKQUOTE:
|
|
78
|
-
case ELEMENT_TYPE.LINK:
|
|
79
|
-
case ELEMENT_TYPE.CHECK_LIST_ITEM:
|
|
80
|
-
case ELEMENT_TYPE.CODE_BLOCK:
|
|
81
|
-
case ELEMENT_TYPE.IMAGE:
|
|
82
|
-
{
|
|
83
|
-
diff.changes.push(oldElement.id);
|
|
84
|
-
diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
85
|
-
diff_type: DIFF_TYPE.DELETE
|
|
86
|
-
}));
|
|
87
|
-
diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
88
|
-
diff_type: DIFF_TYPE.ADD
|
|
89
|
-
}));
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
case ELEMENT_TYPE.ORDERED_LIST:
|
|
93
|
-
case ELEMENT_TYPE.UNORDERED_LIST:
|
|
94
|
-
case ELEMENT_TYPE.LIST_ITEM:
|
|
95
|
-
case ELEMENT_TYPE.LIST_LIC:
|
|
96
|
-
{
|
|
97
|
-
var _diff$changes;
|
|
98
|
-
var _getElementDiffValue = getElementDiffValue(element.children, oldElement.children),
|
|
99
|
-
diffValue = _getElementDiffValue.value,
|
|
100
|
-
diffChanges = _getElementDiffValue.changes;
|
|
101
|
-
(_diff$changes = diff.changes).push.apply(_diff$changes, _toConsumableArray(diffChanges));
|
|
102
|
-
diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
103
|
-
children: diffValue,
|
|
104
|
-
diff_type: DIFF_TYPE.MODIFY
|
|
105
|
-
}));
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
default:
|
|
109
|
-
{
|
|
110
|
-
diff.changes.push(oldElement.id);
|
|
111
|
-
diff.value.push(_objectSpread(_objectSpread({}, oldElement), {}, {
|
|
112
|
-
diff_type: DIFF_TYPE.DELETE
|
|
113
|
-
}));
|
|
114
|
-
diff.value.push(_objectSpread(_objectSpread({}, element), {}, {
|
|
115
|
-
diff_type: DIFF_TYPE.ADD
|
|
116
|
-
}));
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
200
|
+
var elements = getCommonDiff(element, oldElement, diff);
|
|
201
|
+
elements.forEach(function (item) {
|
|
202
|
+
diff.value.push(item);
|
|
203
|
+
});
|
|
120
204
|
};
|
|
121
205
|
|
|
122
206
|
/**
|
|
@@ -131,37 +215,34 @@ var getElementDiffValue = function getElementDiffValue(currentContent, oldConten
|
|
|
131
215
|
value: [],
|
|
132
216
|
changes: []
|
|
133
217
|
};
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
diff.value.splice(elementIndex, 0, _objectSpread(_objectSpread({}, oldElement), {}, {
|
|
163
|
-
diff_type: DIFF_TYPE.DELETE
|
|
164
|
-
}));
|
|
218
|
+
var _generateIdMapAndIds3 = generateIdMapAndIds(currentContent),
|
|
219
|
+
currentContentMap = _generateIdMapAndIds3.map,
|
|
220
|
+
currentIds = _generateIdMapAndIds3.ids;
|
|
221
|
+
var _generateIdMapAndIds4 = generateIdMapAndIds(oldContent),
|
|
222
|
+
oldContentMap = _generateIdMapAndIds4.map,
|
|
223
|
+
oldIds = _generateIdMapAndIds4.ids;
|
|
224
|
+
var diffs = getIdDiffs(oldIds, currentIds);
|
|
225
|
+
diffs.forEach(function (diffItem) {
|
|
226
|
+
var elementIds = diffItem.value;
|
|
227
|
+
if (diffItem.removed) {
|
|
228
|
+
elementIds.forEach(function (elementId) {
|
|
229
|
+
diff.changes.push(elementId);
|
|
230
|
+
var element = oldContentMap[elementId];
|
|
231
|
+
var diffElement = generatorDiffElement(element, 'DELETE', DELETED_STYLE);
|
|
232
|
+
diff.value.push(diffElement);
|
|
233
|
+
});
|
|
234
|
+
} else if (diffItem.added) {
|
|
235
|
+
elementIds.forEach(function (elementId) {
|
|
236
|
+
diff.changes.push(elementId);
|
|
237
|
+
var element = currentContentMap[elementId];
|
|
238
|
+
var diffElement = generatorDiffElement(element, 'ADD', ADDED_STYLE);
|
|
239
|
+
diff.value.push(diffElement);
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
elementIds.forEach(function (elementId) {
|
|
243
|
+
var element = currentContentMap[elementId];
|
|
244
|
+
updateDiffValue(diff, element, oldContentMap[element.id]);
|
|
245
|
+
});
|
|
165
246
|
}
|
|
166
247
|
});
|
|
167
248
|
return diff;
|
|
@@ -180,10 +261,16 @@ export var getDiff = function getDiff() {
|
|
|
180
261
|
var oldValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
181
262
|
children: []
|
|
182
263
|
};
|
|
183
|
-
var
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
264
|
+
var _currentValue$childre = _objectSpread(_objectSpread({}, currentValue), {}, {
|
|
265
|
+
children: normalizeChildren(currentValue.children)
|
|
266
|
+
}),
|
|
267
|
+
currentVersion = _currentValue$childre.version,
|
|
268
|
+
currentContent = _currentValue$childre.children;
|
|
269
|
+
var _oldValue$children = _objectSpread(_objectSpread({}, oldValue), {}, {
|
|
270
|
+
children: normalizeChildren(oldValue.children)
|
|
271
|
+
}),
|
|
272
|
+
oldVersion = _oldValue$children.version,
|
|
273
|
+
oldContent = _oldValue$children.children;
|
|
187
274
|
if (currentVersion === oldVersion) return {
|
|
188
275
|
value: currentContent,
|
|
189
276
|
changes: []
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import ObjectUtils from './object-utils';
|
|
2
|
+
import { generateDefaultText } from '../../basic-sdk/extension/core/utils/index';
|
|
3
|
+
export var normalizeChildren = function normalizeChildren(children) {
|
|
4
|
+
// text
|
|
5
|
+
if (!Array.isArray(children)) return children;
|
|
6
|
+
|
|
7
|
+
// element
|
|
8
|
+
if (Array.isArray(children) && children.length === 0) return [generateDefaultText()];
|
|
9
|
+
return children.map(function (child) {
|
|
10
|
+
// child is text
|
|
11
|
+
if (ObjectUtils.hasProperty(child, 'text') && !ObjectUtils.hasProperty(child, 'children')) {
|
|
12
|
+
return child;
|
|
13
|
+
}
|
|
14
|
+
// child is element
|
|
15
|
+
child.children = normalizeChildren(child.children);
|
|
16
|
+
return child;
|
|
17
|
+
});
|
|
18
|
+
};
|
package/dist/basic-sdk/viewer.js
CHANGED
|
@@ -1,74 +1,56 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
-
import React from 'react';
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
6
3
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
7
|
-
import
|
|
4
|
+
import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from './extension';
|
|
8
5
|
import { withSocketIO } from './socket';
|
|
9
6
|
import withNodeId from './node-id';
|
|
10
7
|
import './assets/css/layout.css';
|
|
11
8
|
import './assets/css/sdoc-editor-plugins.css';
|
|
12
9
|
import { generateDefaultDocContent } from '../utils';
|
|
13
|
-
var SDocViewer =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
placeholder: "",
|
|
59
|
-
renderElement: function renderElement(props) {
|
|
60
|
-
return _renderElement(props, _this2.editor);
|
|
61
|
-
},
|
|
62
|
-
renderLeaf: function renderLeaf(props) {
|
|
63
|
-
return _renderLeaf(props, _this2.editor);
|
|
64
|
-
},
|
|
65
|
-
onDOMBeforeInput: function onDOMBeforeInput(event) {}
|
|
66
|
-
}))))));
|
|
67
|
-
}
|
|
68
|
-
}]);
|
|
69
|
-
return SDocViewer;
|
|
70
|
-
}(React.Component);
|
|
71
|
-
SDocViewer.defaultProps = {
|
|
72
|
-
isOpenSocket: false
|
|
10
|
+
var SDocViewer = function SDocViewer(_ref) {
|
|
11
|
+
var isOpenSocket = _ref.isOpenSocket,
|
|
12
|
+
document = _ref.document,
|
|
13
|
+
config = _ref.config,
|
|
14
|
+
customRenderLeaf = _ref.renderLeaf,
|
|
15
|
+
customRenderElement = _ref.renderElement;
|
|
16
|
+
var editor = !isOpenSocket ? withNodeId(defaultEditor) : withSocketIO(withNodeId(defaultEditor, {
|
|
17
|
+
document: document,
|
|
18
|
+
config: config
|
|
19
|
+
}));
|
|
20
|
+
var slateValue = (document || generateDefaultDocContent()).children;
|
|
21
|
+
var articleRef = useRef(null);
|
|
22
|
+
var _useState = useState(false),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
setUpdate = _useState2[1];
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
editor.width = articleRef.current.children[0].clientWidth;
|
|
27
|
+
setUpdate(true);
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, []);
|
|
30
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
className: "sdoc-editor-container"
|
|
32
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
33
|
+
className: "sdoc-editor-content"
|
|
34
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
35
|
+
className: "flex-fill o-auto sdoc-editor-article-container",
|
|
36
|
+
id: "sdoc-editor-article-container"
|
|
37
|
+
}, /*#__PURE__*/React.createElement(Slate, {
|
|
38
|
+
editor: editor,
|
|
39
|
+
value: slateValue,
|
|
40
|
+
onChange: function onChange() {}
|
|
41
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
className: "article mx-auto",
|
|
43
|
+
ref: articleRef
|
|
44
|
+
}, /*#__PURE__*/React.createElement(Editable, {
|
|
45
|
+
readOnly: true,
|
|
46
|
+
placeholder: "",
|
|
47
|
+
renderElement: function renderElement(props) {
|
|
48
|
+
return (customRenderElement || _renderElement)(props, editor);
|
|
49
|
+
},
|
|
50
|
+
renderLeaf: function renderLeaf(props) {
|
|
51
|
+
return (customRenderLeaf || _renderLeaf)(props, editor);
|
|
52
|
+
},
|
|
53
|
+
onDOMBeforeInput: function onDOMBeforeInput(event) {}
|
|
54
|
+
}))))));
|
|
73
55
|
};
|
|
74
56
|
export default SDocViewer;
|
package/dist/constants/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export var EXTERNAL_EVENT = {
|
|
|
2
2
|
INTERNAL_LINK_CLICK: 'internal_link_click',
|
|
3
3
|
TOGGLE_STAR: 'toggle_star',
|
|
4
4
|
CANCEL_TABLE_SELECT_RANGE: 'cancel_table_select_range'
|
|
5
|
-
};
|
|
5
|
+
};
|
|
6
|
+
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
package/dist/context.js
CHANGED
|
@@ -101,6 +101,26 @@ var Context = /*#__PURE__*/function () {
|
|
|
101
101
|
avatar_url: avatarURL
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "listComments",
|
|
106
|
+
value: function listComments() {
|
|
107
|
+
return this.sdocServerApi.listComments();
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "insertComment",
|
|
111
|
+
value: function insertComment(comment) {
|
|
112
|
+
return this.sdocServerApi.insertComment(comment);
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
key: "deleteComment",
|
|
116
|
+
value: function deleteComment(commentId) {
|
|
117
|
+
return this.sdocServerApi.deleteComment(commentId);
|
|
118
|
+
}
|
|
119
|
+
}, {
|
|
120
|
+
key: "updateComment",
|
|
121
|
+
value: function updateComment(commentId, newComment) {
|
|
122
|
+
return this.sdocServerApi.updateComment(commentId, newComment);
|
|
123
|
+
}
|
|
104
124
|
}]);
|
|
105
125
|
return Context;
|
|
106
126
|
}();
|