@seafile/seafile-editor 0.3.76

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