@seafile/sdoc-editor 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/{new-editors/editor.js → editor.js} +38 -17
  2. package/dist/index.js +2 -36
  3. package/dist/slate-extension/core/transforms/move-children.js +1 -1
  4. package/dist/slate-extension/plugins/blockquote/helpers.js +3 -3
  5. package/dist/slate-extension/plugins/index.js +3 -2
  6. package/dist/slate-extension/plugins/list/transforms/normalize-list-item.js +2 -2
  7. package/dist/slate-extension/plugins/list/transforms/toggle-list.js +6 -8
  8. package/dist/slate-extension/plugins/socket/index.js +6 -0
  9. package/dist/slate-extension/plugins/socket/plugin.js +23 -0
  10. package/dist/slate-extension/socket/socket-client.js +94 -0
  11. package/dist/slate-extension/socket/socket-manager.js +63 -0
  12. package/dist/slate-extension/toolbar/index.js +1 -1
  13. package/dist/utils/event-bus.js +39 -0
  14. package/package.json +5 -25
  15. package/dist/assets/css/comment-dialog.css +0 -50
  16. package/dist/assets/css/diff-viewer.css +0 -105
  17. package/dist/assets/css/formula.css +0 -19
  18. package/dist/assets/css/history-viewer.css +0 -104
  19. package/dist/assets/css/image.css +0 -134
  20. package/dist/assets/css/issue-card.css +0 -43
  21. package/dist/assets/css/keyboard-shortcuts.css +0 -58
  22. package/dist/assets/css/link.css +0 -7
  23. package/dist/assets/css/markdown-editor.css +0 -12
  24. package/dist/assets/css/markdown-viewer.css +0 -69
  25. package/dist/assets/css/navbar-imgbutton.css +0 -83
  26. package/dist/assets/css/outline.css +0 -29
  27. package/dist/assets/css/table.css +0 -57
  28. package/dist/assets/css/textlink-hovermenu.css +0 -47
  29. package/dist/assets/css/topbar.css +0 -350
  30. package/dist/assets/css/tree-view.css +0 -67
  31. package/dist/assets/css/user-help.css +0 -84
  32. package/dist/assets/editor/plain-editor.css +0 -30
  33. package/dist/assets/editor/seatable-editor.css +0 -77
  34. package/dist/assets/editor/simple-editor.css +0 -77
  35. package/dist/components/click-outside.js +0 -46
  36. package/dist/components/context-menu.js +0 -97
  37. package/dist/components/dialogs/add-formula-dialog.js +0 -116
  38. package/dist/components/dialogs/add-image-dialog.js +0 -69
  39. package/dist/components/dialogs/add-link-dialog.js +0 -133
  40. package/dist/components/dialogs/comment-dialog.js +0 -97
  41. package/dist/components/dialogs/shortcut-dialog.js +0 -131
  42. package/dist/components/error-boundary.js +0 -28
  43. package/dist/components/load-script/index.js +0 -69
  44. package/dist/components/loading.js +0 -25
  45. package/dist/components/markdown-lint.js +0 -72
  46. package/dist/components/menu/index.js +0 -4
  47. package/dist/components/menu/item.js +0 -49
  48. package/dist/components/menu/menu.js +0 -38
  49. package/dist/components/menu/style.css +0 -42
  50. package/dist/components/modal-portal.js +0 -38
  51. package/dist/components/outline/index.js +0 -92
  52. package/dist/components/outline/outline-item.js +0 -58
  53. package/dist/components/select/_option.js +0 -44
  54. package/dist/components/select/field-setting.js +0 -106
  55. package/dist/components/select/index.js +0 -149
  56. package/dist/components/select/style.css +0 -144
  57. package/dist/components/svg-icons/check-mark-icon.js +0 -14
  58. package/dist/components/svg-icons/column-icon.js +0 -17
  59. package/dist/components/svg-icons/text-icon.js +0 -34
  60. package/dist/components/text-link-hover-menu/index.js +0 -123
  61. package/dist/components/toast/alert.js +0 -138
  62. package/dist/components/toast/index.js +0 -3
  63. package/dist/components/toast/toast.js +0 -159
  64. package/dist/components/toast/toastManager.js +0 -139
  65. package/dist/components/toast/toaster.js +0 -65
  66. package/dist/components/toolbar/header-list.js +0 -114
  67. package/dist/components/toolbar/help-group.js +0 -33
  68. package/dist/components/toolbar/index.js +0 -4
  69. package/dist/components/toolbar/insert-image.js +0 -106
  70. package/dist/components/toolbar/insert-table.js +0 -136
  71. package/dist/components/toolbar/table-group.js +0 -74
  72. package/dist/components/toolbar/toolbar.js +0 -317
  73. package/dist/components/toolbar/widgets/button-group.js +0 -24
  74. package/dist/components/toolbar/widgets/button-item.js +0 -129
  75. package/dist/components/toolbar/widgets/drop-list.js +0 -88
  76. package/dist/components/user-help/index.js +0 -179
  77. package/dist/config-0.js +0 -15
  78. package/dist/config.js +0 -16
  79. package/dist/constants/cell-types.js +0 -29
  80. package/dist/constants/column.js +0 -4
  81. package/dist/containers/code-highlight-package.js +0 -14
  82. package/dist/containers/controller/block-element-controller.js +0 -375
  83. package/dist/containers/controller/index.js +0 -5
  84. package/dist/containers/controller/inline-element-controller.js +0 -134
  85. package/dist/containers/controller/normalize-controller.js +0 -95
  86. package/dist/containers/controller/shortcut-controller.js +0 -385
  87. package/dist/containers/controller/void-element-controller.js +0 -9
  88. package/dist/containers/custom/custom.js +0 -18
  89. package/dist/containers/custom/get-event-transfer.js +0 -33
  90. package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
  91. package/dist/containers/custom/insertNodes.js +0 -120
  92. package/dist/containers/custom/is-empty-paragraph.js +0 -9
  93. package/dist/containers/custom/set-event-transfer.js +0 -30
  94. package/dist/containers/custom/split-nodes-at-point.js +0 -136
  95. package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
  96. package/dist/containers/editor-context.js +0 -85
  97. package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
  98. package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
  99. package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
  100. package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
  101. package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
  102. package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
  103. package/dist/containers/editor-utils/clear-format-utils.js +0 -84
  104. package/dist/containers/editor-utils/common-editor-utils.js +0 -492
  105. package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
  106. package/dist/containers/editor-utils/mark-utils.js +0 -20
  107. package/dist/containers/editor-utils/range-utils.js +0 -7
  108. package/dist/containers/editor-utils/selection-utils.js +0 -30
  109. package/dist/containers/editor-utils/text-utils.js +0 -117
  110. package/dist/containers/editor-widgets/check-list-item.js +0 -53
  111. package/dist/containers/editor-widgets/code-block.js +0 -128
  112. package/dist/containers/editor-widgets/column.js +0 -100
  113. package/dist/containers/editor-widgets/formula.js +0 -67
  114. package/dist/containers/editor-widgets/image.js +0 -237
  115. package/dist/containers/editor-widgets/link.js +0 -9
  116. package/dist/containers/editor-widgets/table.js +0 -144
  117. package/dist/containers/element-model/blockquote.js +0 -13
  118. package/dist/containers/element-model/column.js +0 -19
  119. package/dist/containers/element-model/image.js +0 -16
  120. package/dist/containers/element-model/link.js +0 -16
  121. package/dist/containers/element-model/table.js +0 -57
  122. package/dist/containers/element-model/text.js +0 -10
  123. package/dist/containers/render-utils/common-utils.js +0 -80
  124. package/dist/containers/render-utils/editor-utils.js +0 -133
  125. package/dist/containers/render-utils/viewer-utils.js +0 -198
  126. package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
  127. package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
  128. package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
  129. package/dist/editors/index.js +0 -78
  130. package/dist/editors/markdown-editor.js +0 -280
  131. package/dist/editors/plain-markdown-editor.js +0 -285
  132. package/dist/editors/seatable-editor.js +0 -210
  133. package/dist/editors/simple-editor.js +0 -200
  134. package/dist/utils/deserialize-html.js +0 -260
  135. package/dist/utils/diff/compare-strings.js +0 -35
  136. package/dist/utils/diff/diff.js +0 -769
  137. package/dist/utils/diff/index.js +0 -2
  138. package/dist/utils/seafile-markdown2html.js +0 -52
  139. package/dist/utils/slate2markdown/deserialize.js +0 -588
  140. package/dist/utils/slate2markdown/index.js +0 -3
  141. package/dist/utils/slate2markdown/serialize.js +0 -366
  142. package/dist/utils/utils.js +0 -69
  143. package/dist/viewer/diff-viewer.js +0 -85
  144. package/dist/viewer/index.js +0 -4
  145. package/dist/viewer/markdown-viewer.js +0 -121
  146. package/dist/viewer/seatable-viewer.js +0 -63
  147. package/dist/viewer/slate-viewer.js +0 -71
  148. /package/dist/assets/css/{new-editor-toolbar.css → sdoc-editor-toolbar.css} +0 -0
  149. /package/dist/assets/css/{new-editor.css → sdoc-editor.css} +0 -0
@@ -1,769 +0,0 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/esm/createClass";
6
- import lodash from 'lodash';
7
- import { Node, Text } from 'slate';
8
- import { compareTwoStrings } from './compare-strings';
9
- import { deserialize } from '../slate2markdown';
10
- function equalityFunctionForSlate(a, b) {
11
- if (a.type !== b.type) {
12
- return false;
13
- }
14
- if (lodash.isEqual(a, b)) {
15
- return true;
16
- }
17
- if (Text.isText(a) && Text.isText(b)) {
18
- if (compareTwoStrings(a.text, b.text) >= 0.5) {
19
- return 'changed';
20
- } else {
21
- return false;
22
- }
23
- }
24
- if (a.type === b.type && (a.type.includes('ordered_list') || a.type.includes('unordered_list'))) {
25
- if (compareTwoStrings(Node.text(a), Node.text(b)) >= 0.5) {
26
- return 'changed';
27
- }
28
- }
29
- if (a.type === b.type && (a.children.length > 1 || b.children.length > 1) && a.type === 'list_item') {
30
- if (compareTwoStrings(Node.text(a), Node.text(b)) >= 0.5) {
31
- return 'changed';
32
- }
33
- }
34
- if (a.type === b.type && a.type === 'paragraph') {
35
- if (compareTwoStrings(Node.text(a), Node.text(b)) >= 0.5) {
36
- return 'changed';
37
- }
38
- }
39
- if (a.type === b.type && a.type === 'table') {
40
- if (compareTwoStrings(Node.text(a), Node.text(b)) >= 0.5) {
41
- return 'changed';
42
- }
43
- }
44
-
45
- /*
46
- * the table diff is not the same as list diff,
47
- * in the table, if the old table_line and the new table_line or the old table_cell and new table_cell are not equal
48
- * the table_line or table_cells is set as changed, then the diff is expressed in the text of table_cell
49
- * */
50
-
51
- if (a.type === b.type && a.type === 'table_row') {
52
- return 'changed';
53
- }
54
- if (a.type === b.type && a.type === 'table_cell') {
55
- return 'changed';
56
- }
57
- return false;
58
- }
59
- function defaultEqualityFunction(a, b) {
60
- return a === b;
61
- }
62
- var SlateDiff = /*#__PURE__*/function () {
63
- function SlateDiff() {
64
- var _this = this;
65
- _classCallCheck(this, SlateDiff);
66
- this.deepDiff = function (newNodes, oldNodes, equalFunc) {
67
- var depth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
68
- var slateDiffNodes = [];
69
- // remeber current nodes depth
70
- var nodeDepth = depth + 1;
71
- var diff = new Diff({
72
- equalFunc: equalFunc
73
- });
74
- diff.ArrayDiff(newNodes, oldNodes);
75
- for (var i = 0; i < diff.diff.length; i++) {
76
- var diffElement = diff.diff[i];
77
- var changeType = diffElement.changeType;
78
- if (changeType === 'common') {
79
- var newItemData = {
80
- diff_state: 'diff-common',
81
- new_index: diffElement.newIndex,
82
- old_index: -1,
83
- node_depth: nodeDepth
84
- };
85
- diffElement.item.data = Object.assign(diffElement.item.data ? diffElement.item.data : {}, newItemData);
86
- } else if (changeType === 'added') {
87
- if (Text.isText(diffElement.item)) {
88
- diffElement.item.ADD = true;
89
- } else {
90
- var _newItemData = {
91
- diff_state: 'diff-added',
92
- new_index: diffElement.newIndex,
93
- old_index: -1,
94
- node_depth: nodeDepth
95
- };
96
- diffElement.item.data = Object.assign(diffElement.item.data ? diffElement.item.data : {}, _newItemData);
97
- }
98
- } else if (changeType === 'removed') {
99
- if (Text.isText(diffElement.item)) {
100
- diffElement.item.DELETE = true;
101
- } else {
102
- var _newItemData2 = {
103
- diff_state: 'diff-removed',
104
- new_index: -1,
105
- old_index: diffElement.oldIndex,
106
- node_depth: nodeDepth
107
- };
108
- diffElement.item.data = Object.assign(diffElement.item.data ? diffElement.item.data : {}, _newItemData2);
109
- }
110
- } else if (changeType === 'replaced') {
111
- var diffNodes = void 0,
112
- elementType = diffElement.item.type || 'text';
113
- if (elementType === 'text') {
114
- // compare text diff leaves use getTextDiff function
115
- diffNodes = _this.getTextDiff(diffElement.newItem, diffElement.oldItem);
116
- } else if (elementType.includes('ordered_list') || elementType.includes('unordered_list') || elementType.includes('list_item')) {
117
- diffNodes = _this.deepDiff(diffElement.newItem.children, diffElement.oldItem.children, equalFunc, nodeDepth);
118
- } else if (elementType === 'table' || elementType === 'table_row' || elementType === 'table_cell') {
119
- diffNodes = _this.deepDiff(diffElement.newItem.children, diffElement.oldItem.children, equalFunc, nodeDepth);
120
- } else if (elementType === 'paragraph') {
121
- // compare text or inline
122
- diffNodes = _this.deepDiff(diffElement.newItem.children, diffElement.oldItem.children, equalFunc, nodeDepth);
123
- }
124
- if (Text.isText(diffElement.item)) {
125
- diffElement.item = diffNodes;
126
- } else {
127
- var _newItemData3 = {
128
- diff_state: 'diff-replaced',
129
- new_index: -1,
130
- old_index: diffElement.oldIndex,
131
- node_depth: nodeDepth
132
- };
133
- diffElement.item.data = Object.assign(diffElement.item.data ? diffElement.item.data : {}, _newItemData3);
134
- diffElement.item.children = diffNodes;
135
- }
136
- }
137
-
138
- // add diff nodes to document
139
- if (Array.isArray(diffElement.item)) {
140
- slateDiffNodes = slateDiffNodes.concat(diffElement.item);
141
- } else {
142
- slateDiffNodes.push(diffElement.item);
143
- }
144
- }
145
- return slateDiffNodes;
146
- };
147
- this.getDiffDocument = function (newMarkdownContent, oldMarkdownContent) {
148
- var newNodes = deserialize(newMarkdownContent);
149
- var oldNodes = deserialize(oldMarkdownContent);
150
- var topSlateDiffNodes = _this.deepDiff(newNodes, oldNodes, equalityFunctionForSlate);
151
- //handle replaced paragraph
152
- topSlateDiffNodes = _this.splitTopDiffNodes(topSlateDiffNodes);
153
- return topSlateDiffNodes;
154
- };
155
- }
156
- _createClass(SlateDiff, [{
157
- key: "getTextDiff",
158
- value: function getTextDiff(newTextItem, oldTextItem) {
159
- var textNodes = [];
160
- var nodes = this.textDiff(newTextItem.text, oldTextItem.text);
161
- textNodes = textNodes.concat(nodes);
162
- return textNodes;
163
- }
164
- }, {
165
- key: "textDiff",
166
- value: function textDiff(newText, oldText) {
167
- var marks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
168
- var texts = [];
169
- var diff = new Diff({
170
- equalFunc: defaultEqualityFunction
171
- });
172
- diff.StringDiff(newText, oldText);
173
- var textDiffArray = diff.diff;
174
- var stringFragment = '';
175
- var lastDiffState = textDiffArray[0].changeType;
176
- textDiffArray.forEach(function (textCharacter, index, textDiffArray) {
177
- var markType = '';
178
- if (lastDiffState === 'removed') {
179
- markType = 'DELETE';
180
- } else if (lastDiffState === 'added') {
181
- markType = 'ADD';
182
- }
183
- if (lastDiffState === textCharacter.changeType) {
184
- stringFragment += textCharacter.item;
185
- if (index === textDiffArray.length - 1) {
186
- texts.push(_objectSpread(_defineProperty({
187
- text: stringFragment
188
- }, markType, true), marks));
189
- }
190
- } else if (textCharacter.changeType !== lastDiffState) {
191
- texts.push(_objectSpread(_objectSpread({
192
- text: stringFragment
193
- }, marks), {}, _defineProperty({}, markType, true)));
194
- lastDiffState = textCharacter.changeType;
195
- stringFragment = textCharacter.item;
196
- if (index === textDiffArray.length - 1) {
197
- if (lastDiffState === 'removed') {
198
- markType = 'DELETE';
199
- } else if (lastDiffState === 'added') {
200
- markType = 'ADD';
201
- }
202
- texts.push(_objectSpread(_defineProperty({
203
- text: stringFragment
204
- }, markType, true), marks));
205
- }
206
- }
207
- });
208
- return texts;
209
- }
210
- }, {
211
- key: "splitDiffParagraph",
212
- value: function splitDiffParagraph(diffParagraph) {
213
- // clone the replace paragraph to wrap the deleted and added nodes
214
- var newParagraph = lodash.cloneDeep(diffParagraph),
215
- oldParagraph = lodash.cloneDeep(diffParagraph),
216
- // wrap new paragraph nodes and old paragraph nodes
217
- newParagraphNodes = [],
218
- oldParagraphNodes = [];
219
- // traverse paragraph nodes
220
- diffParagraph.children.forEach(function (node, index1, nodes) {
221
- if (node.type === 'link' || node.type === 'image') {
222
- // if the node is inline node, like link
223
- // if the inline is added
224
- if (node.data.diff_state === 'diff-added') {
225
- // push the inline node to new paragraph nodes
226
- newParagraphNodes.push(node);
227
- } else if (node.data.diff_state === 'diff-removed') {
228
- // if the inline is added push the inline node to new paragraph nodes
229
- oldParagraphNodes.push(node);
230
- } else {
231
- // if the inline node is common new paragraph node and old paragraph all push the inline node
232
- newParagraphNodes.push(node);
233
- oldParagraphNodes.push(node);
234
- }
235
- } else {
236
- if (node.ADD) {
237
- newParagraphNodes.push(node);
238
- } else if (node.DELETE) {
239
- oldParagraphNodes.push(node);
240
- } else {
241
- // push common text
242
- newParagraphNodes.push(node);
243
- oldParagraphNodes.push(node);
244
- }
245
- }
246
- });
247
-
248
- // set new paragraph and old paragraph nodes
249
- newParagraph.children = newParagraphNodes;
250
- oldParagraph.data.paragraph_state = 'old-paragraph';
251
- newParagraph.data.paragraph_state = 'new-paragraph';
252
- oldParagraph.children = oldParagraphNodes;
253
- return [oldParagraph, newParagraph];
254
- }
255
- }, {
256
- key: "splitTopDiffNodes",
257
- value: function splitTopDiffNodes(slateDiffNodes) {
258
- var _this2 = this;
259
- // newSlateDiffNodes used to wrap the new slate nodes
260
- var newSlateDiffNodes = [];
261
- // traverse slate top Nodes and find the paragraph handle it
262
- slateDiffNodes.forEach(function (node) {
263
- if (node.data.diff_state === 'diff-replaced' && node.type === 'paragraph') {
264
- var splicedParagraph = _this2.splitDiffParagraph(node);
265
- // push the old and new paragraph node to newSlateDiffNodes
266
- newSlateDiffNodes.push(splicedParagraph[0], splicedParagraph[1]);
267
- } else if (node.data.diff_state === 'diff-replaced' && node.type === 'table') {
268
- _this2.splitTableDiffParagraph(node);
269
- newSlateDiffNodes.push(node);
270
- } else {
271
- newSlateDiffNodes.push(node);
272
- }
273
- });
274
- return newSlateDiffNodes;
275
- }
276
- }, {
277
- key: "splitTableDiffParagraph",
278
- value: function splitTableDiffParagraph(node) {
279
- var _this3 = this;
280
- node.children.forEach(function (tableRow, rowIndex, tablerows) {
281
- if (tableRow.data.diff_state === 'diff-replaced') {
282
- tableRow.children.forEach(function (tableCell) {
283
- if (tableCell.data.diff_state === 'diff-replaced') {
284
- if (tableCell.children[0].data.diff_state === 'diff-replaced') {
285
- var splicedParagraphNodes = _this3.splitDiffParagraph(tableCell.children[0]);
286
- tableCell.children = splicedParagraphNodes;
287
- }
288
- }
289
- });
290
- }
291
- });
292
- return node;
293
- }
294
- }]);
295
- return SlateDiff;
296
- }();
297
- var ArrayDiffElement = /*#__PURE__*/function () {
298
- function ArrayDiffElement(item, newIndex, oldIndex) {
299
- _classCallCheck(this, ArrayDiffElement);
300
- this.item = item;
301
- this.newIndex = newIndex;
302
- this.oldIndex = oldIndex;
303
- }
304
- _createClass(ArrayDiffElement, [{
305
- key: "added",
306
- value: function added() {
307
- return this.oldIndex === undefined;
308
- }
309
- }, {
310
- key: "removed",
311
- value: function removed() {
312
- return this.newIndex === undefined;
313
- }
314
- }, {
315
- key: "common",
316
- value: function common() {
317
- return this.oldIndex !== undefined && this.newIndex !== undefined;
318
- }
319
- }]);
320
- return ArrayDiffElement;
321
- }();
322
- var Diff = /*#__PURE__*/function () {
323
- function Diff(opts) {
324
- _classCallCheck(this, Diff);
325
- this.equalFunc = opts.equalFunc ? opts.equalFunc : defaultEqualityFunction;
326
- if (opts.shouldDetectChange != undefined) this.shouldDetectChange = opts.shouldDetectChange;else this.shouldDetectChange = false;
327
- this.similarityFunc = opts.similarityFunc;
328
- }
329
-
330
- /**
331
- Appends an array item to the subsequence of items that were added in the new array.
332
- @method added
333
- @param item The array item that was added.
334
- **/
335
- _createClass(Diff, [{
336
- key: "addAdded",
337
- value: function addAdded(item, newIndex) {
338
- var element = new ArrayDiffElement(item, newIndex, undefined);
339
- element.changeType = 'added';
340
- this.added.push(element);
341
- this.diff.push(element);
342
- }
343
-
344
- /**
345
- Appends an array item to the subsequence of items that were removed from the old array.
346
- @method removed
347
- @param item The array item that was added.
348
- **/
349
- }, {
350
- key: "addRemoved",
351
- value: function addRemoved(item, oldIndex) {
352
- var element = new ArrayDiffElement(item, undefined, oldIndex);
353
- this.removed.push(element);
354
- element.changeType = 'removed';
355
- this.diff.push(element);
356
- }
357
- }, {
358
- key: "addReplaced",
359
- value: function addReplaced(oldItem, newItem, oldIndex, newIndex) {
360
- var element = new ArrayDiffElement(oldItem, newIndex, oldIndex);
361
- element.newItem = newItem;
362
- element.oldItem = oldItem;
363
- element.changeType = 'replaced';
364
- this.replaced.push(element);
365
- this.diff.push(element);
366
- }
367
-
368
- /**
369
- Appends an array item to the longest common subsequence between the new and old arrays.
370
- @method common
371
- @param item The array item that was added.
372
- **/
373
- }, {
374
- key: "addCommon",
375
- value: function addCommon(oldItem, newItem, oldIndex, newIndex) {
376
- var element = new ArrayDiffElement(oldItem, newIndex, oldIndex);
377
- element.newItem = newItem;
378
- element.changeType = 'common';
379
- element.oldItem = oldItem;
380
- this.common.push(element);
381
- this.diff.push(element);
382
- }
383
- }, {
384
- key: "StringDiff",
385
- value: function StringDiff(newString, oldString) {
386
- var newLength = newString.length;
387
- var oldLength = oldString.length;
388
- var n = 0;
389
- var o = 0;
390
- var table = [];
391
- table[newLength] = [];
392
- for (o = oldLength; o >= 0; table[newLength][o--] = 0);
393
- for (n = newLength - 1; n >= 0; n--) {
394
- table[n] = [];
395
- table[n][oldLength] = 0;
396
- for (o = oldLength - 1; o >= 0; o--) {
397
- if (this.equalFunc(newString[n], oldString[o])) {
398
- table[n][o] = table[n + 1][o + 1] + 1;
399
- } else {
400
- table[n][o] = Math.max(table[n + 1][o], table[n][o + 1]);
401
- }
402
- }
403
- }
404
-
405
- // Fill in the subsequence arrays
406
- this.common = [];
407
- this.added = [];
408
- this.removed = [];
409
- this.replaced = [];
410
- this.diff = [];
411
- n = o = 0;
412
- while (n < newLength && o < oldLength) {
413
- var diffState = this.equalFunc(newString[n], oldString[o]);
414
- if (diffState) {
415
- var newItem = newString[n];
416
- var oldItem = oldString[o];
417
- this.addCommon(oldItem, newItem, o, n);
418
- n++;
419
- o++;
420
- } else if (table[n + 1][o] >= table[n][o + 1]) {
421
- this.addAdded(newString[n], n);
422
- n++;
423
- } else {
424
- this.addRemoved(oldString[o], o);
425
- o++;
426
- }
427
- }
428
- for (; n < newLength; n++) {
429
- this.addAdded(newString[n], n);
430
- }
431
- for (; o < oldLength; o++) {
432
- this.addRemoved(oldString[o], o);
433
- }
434
- }
435
- }, {
436
- key: "ArrayDiff",
437
- value: function ArrayDiff(newArray, oldArray, callback) {
438
- //newArray = newArray.toArray();
439
- //oldArray = oldArray.toArray();
440
- var newLength = newArray.length;
441
- var oldLength = oldArray.length;
442
- var n = 0;
443
- var o = 0;
444
- var table = [];
445
-
446
- // Build out the table
447
- table[newLength] = [];
448
- for (o = oldLength; o >= 0; table[newLength][o--] = 0);
449
- for (n = newLength - 1; n >= 0; n--) {
450
- table[n] = [];
451
- table[n][oldLength] = 0;
452
- for (o = oldLength - 1; o >= 0; o--) {
453
- if (this.equalFunc(newArray[n], oldArray[o])) {
454
- table[n][o] = table[n + 1][o + 1] + 1;
455
- } else {
456
- table[n][o] = Math.max(table[n + 1][o], table[n][o + 1]);
457
- }
458
- }
459
- }
460
-
461
- // Fill in the subsequence arrays
462
- this.common = [];
463
- this.added = [];
464
- this.removed = [];
465
- this.replaced = [];
466
- this.diff = [];
467
- n = o = 0;
468
- while (n < newLength && o < oldLength) {
469
- var diffState = this.equalFunc(newArray[n], oldArray[o]);
470
- if (diffState) {
471
- var newItem = newArray[n];
472
- var oldItem = oldArray[o];
473
- if (diffState === 'changed') {
474
- this.addReplaced(oldItem, newItem, o, n);
475
- } else {
476
- //if (newItem.isVoid) {
477
- this.addCommon(oldItem, newItem, o, n);
478
- }
479
- if (callback) {
480
- callback('C', o, n);
481
- }
482
- n++;
483
- o++;
484
- } else if (table[n + 1][o] >= table[n][o + 1]) {
485
- this.addAdded(newArray[n], n);
486
- if (callback) {
487
- callback('A', 0, n);
488
- }
489
- n++;
490
- } else {
491
- this.addRemoved(oldArray[o], o);
492
- if (callback) {
493
- callback('D', o, 0);
494
- }
495
- o++;
496
- }
497
- }
498
- for (; n < newLength; n++) {
499
- this.addAdded(newArray[n], n);
500
- if (callback) {
501
- callback('A', 0, n);
502
- }
503
- }
504
- for (; o < oldLength; o++) {
505
- this.addRemoved(oldArray[o], o);
506
- if (callback) {
507
- callback('D', o, 0);
508
- }
509
- }
510
- }
511
- }]);
512
- return Diff;
513
- }();
514
- var Diff3 = /*#__PURE__*/function () {
515
- function Diff3(opts) {
516
- _classCallCheck(this, Diff3);
517
- opts = opts || {};
518
- this.equalFunc = opts.equalFunc ? opts.equalFunc : defaultEqualityFunction;
519
- if (opts.shouldDetectChange != undefined) this.shouldDetectChange = opts.shouldDetectChange;else this.shouldDetectChange = false;
520
- this.similarityFunc = opts.similarityFunc;
521
- this.chunks = [];
522
- this.common = [];
523
- this.added = [];
524
- this.removed = [];
525
- this.mergedArray = [];
526
- }
527
- _createClass(Diff3, [{
528
- key: "diff3",
529
- value: function diff3(oArray, aArray, bArray) {
530
- this.oArray = oArray;
531
- this.aArray = aArray;
532
- this.bArray = bArray;
533
- var oaDiff = new Diff({
534
- equalFunc: this.equalFunc,
535
- shouldDetectChange: this.shouldDetectChange,
536
- similarityFunc: this.similarityFunc
537
- });
538
- oaDiff.ArrayDiff(aArray, oArray);
539
- var obDiff = new Diff({
540
- equalFunc: this.equalFunc,
541
- shouldDetectChange: this.shouldDetectChange,
542
- similarityFunc: this.similarityFunc
543
- });
544
- obDiff.ArrayDiff(bArray, oArray);
545
- var M_oa = [];
546
- for (var i = 0; i < oArray.length; i++) {
547
- M_oa[i] = [];
548
- for (var j = 0; j < aArray.length; j++) {
549
- M_oa[i][j] = 0;
550
- }
551
- }
552
- var _iterator = _createForOfIteratorHelper(oaDiff.common),
553
- _step;
554
- try {
555
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
556
- var item = _step.value;
557
- M_oa[item.oldIndex][item.newIndex] = 1;
558
- }
559
- } catch (err) {
560
- _iterator.e(err);
561
- } finally {
562
- _iterator.f();
563
- }
564
- this.M_oa = M_oa;
565
- var M_ob = [];
566
- for (var _i = 0; _i < oArray.length; _i++) {
567
- M_ob[_i] = [];
568
- for (var _j = 0; _j < bArray.length; _j++) {
569
- M_ob[_i][_j] = 0;
570
- }
571
- }
572
- var _iterator2 = _createForOfIteratorHelper(obDiff.common),
573
- _step2;
574
- try {
575
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
576
- var _item = _step2.value;
577
- M_ob[_item.oldIndex][_item.newIndex] = 1;
578
- }
579
- } catch (err) {
580
- _iterator2.e(err);
581
- } finally {
582
- _iterator2.f();
583
- }
584
- this.M_ob = M_ob;
585
- /*
586
- console.log("M_oa");
587
- console.log(M_oa);
588
- console.log("M_ob");
589
- console.log(M_ob);
590
- */
591
-
592
- var lo = 0;
593
- var la = 0;
594
- var lb = 0;
595
- var finalStable = undefined;
596
- // while (true) {
597
- // // find i that the cursor at the three array not match
598
- // let i = 0;
599
- // var iFound = false;
600
- // while (true) {
601
- // if (M_oa[lo+i][la+i] == 0 || M_ob[lo+i][lb+i] == 0) {
602
- // iFound = true;
603
- // break;
604
- // }
605
- // i++;
606
- // if (lo+i == oArray.length || la+i == aArray.length ||
607
- // lb+i == bArray.length)
608
- // break;
609
- // }
610
- // if (iFound == false) {
611
- // // go out and output a final stable chunk
612
- // //console.log("iFound == false");
613
- // finalStable = true;
614
- // break;
615
- // }
616
- //
617
- // if (i > 0) {
618
- // //console.log("stable chunk ");
619
- // var chunk = {};
620
- // chunk.startO = lo;
621
- // chunk.startA = la;
622
- // chunk.startB = lb;
623
- // chunk.endO = lo+i-1;
624
- // chunk.endA = la+i-1;
625
- // chunk.endB = lb+i-1;
626
- // chunk.isStable = true;
627
- // this.chunks.push(chunk);
628
- // //printChunk(oArray, aArray, bArray, chunk);
629
- // lo = lo + i;
630
- // la = la + i;
631
- // lb = lb + i;
632
- // continue;
633
- // }
634
- //
635
- // //console.log("unstable chunk ");
636
- // let o;
637
- // let a;
638
- // let b;
639
- // let found = false;
640
- // for (o = lo; o < oArray.length; o++) {
641
- // for (a = la; a < aArray.length; a++) {
642
- // if (M_oa[o][a] != true) {
643
- // continue;
644
- // }
645
- //
646
- // for (b = lb; b < bArray.length; b++) {
647
- // if (M_ob[o][b] == true) {
648
- // found = true;
649
- // break;
650
- // }
651
- // }
652
- // if (found == true) {
653
- // break;
654
- // }
655
- // }
656
- // if (found == true) {
657
- // break;
658
- // }
659
- // }
660
- //
661
- // if (found == true) {
662
- // let chunk = {}
663
- // chunk.startO = lo;
664
- // chunk.startA = la;
665
- // chunk.startB = lb;
666
- // chunk.endO = o-1;
667
- // chunk.endA = a-1;
668
- // chunk.endB = b-1;
669
- // chunk.isStable = false;
670
- // this.chunks.push(chunk);
671
- // //printChunk(oArray, aArray, bArray, chunk);
672
- // lo = o;
673
- // la = a;
674
- // lb = b;
675
- // continue;
676
- // } else {
677
- // // output a final unstable chunk
678
- // finalStable = false;
679
- // break;
680
- // }
681
- // }
682
-
683
- // output the final chunk
684
- if (lo < oArray.length || la < aArray.length || lb < bArray.length) {
685
- //console.log("final chunk ");
686
- var chunk = {};
687
- chunk.startO = lo;
688
- chunk.endO = oArray.length - 1;
689
- chunk.startA = la;
690
- chunk.endA = aArray.length - 1;
691
- chunk.startB = lb;
692
- chunk.endB = bArray.length - 1;
693
- chunk.isStable = finalStable;
694
- this.chunks.push(chunk);
695
- //printChunk(oArray, aArray, bArray, chunk);
696
- }
697
- }
698
- }, {
699
- key: "calPatchChunk",
700
- value: function calPatchChunk(chunk) {
701
- for (var i = chunk.startA; i <= chunk.endA; ++i) {
702
- // find if item also in O
703
- var found = false;
704
- for (var j = chunk.startO; j <= chunk.endO; ++j) {
705
- if (this.M_oa[j][i] === 1) {
706
- // The item in both A and O
707
- // The item is removed by B
708
- found = true;
709
- break;
710
- }
711
- }
712
- if (found === false) {
713
- // the item not found in O
714
- // the item is added or modifed in A
715
- // keep
716
- this.mergedArray.push(this.aArray[i]);
717
- }
718
- }
719
- for (var _i2 = chunk.startB; _i2 <= chunk.endB; ++_i2) {
720
- // find if item also in O
721
- var found = false;
722
- for (var _j2 = chunk.startO; _j2 <= chunk.endO; ++_j2) {
723
- if (this.M_ob[_j2][_i2] === 1) {
724
- // The item in both B and O
725
- // the item is removed by A (or moved by A)
726
- // do nothing
727
- found = true;
728
- break;
729
- }
730
- }
731
- if (found) continue;
732
-
733
- // the matched item not found in O
734
- // the item is added or modifed in B
735
- this.mergedArray.push(this.bArray[_i2]);
736
- }
737
- }
738
- }, {
739
- key: "calPatch",
740
- value: function calPatch() {
741
- var _iterator3 = _createForOfIteratorHelper(this.chunks),
742
- _step3;
743
- try {
744
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
745
- var chunk = _step3.value;
746
- if (chunk.isStable) {
747
- for (var i = 0; i + chunk.startA <= chunk.endA; ++i) {
748
- var c = {};
749
- c.indexA = i + chunk.startA;
750
- c.indexO = i + chunk.startO;
751
- c.indexB = i + chunk.startB;
752
- //this.common.push(c);
753
- this.mergedArray.push(this.aArray[c.indexA]);
754
- }
755
- }
756
- if (!chunk.isStable) {
757
- this.calPatchChunk(chunk);
758
- }
759
- }
760
- } catch (err) {
761
- _iterator3.e(err);
762
- } finally {
763
- _iterator3.f();
764
- }
765
- }
766
- }]);
767
- return Diff3;
768
- }();
769
- export { Diff, Diff3, equalityFunctionForSlate, SlateDiff };