@commercetools/sync-actions 6.0.0 → 6.1.1
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/CHANGELOG.md +14 -0
- package/dist/sync-actions.cjs.js +111 -2490
- package/dist/sync-actions.es.js +110 -2487
- package/dist/sync-actions.umd.js +113 -2491
- package/dist/sync-actions.umd.min.js +1 -1
- package/package.json +1 -1
package/dist/sync-actions.es.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import flatten from 'lodash.flatten';
|
|
2
2
|
import isEqual from 'lodash.isequal';
|
|
3
3
|
import isNil from 'lodash.isnil';
|
|
4
|
-
import
|
|
5
|
-
import chalk from 'chalk';
|
|
4
|
+
import { DiffPatcher } from 'jsondiffpatch/dist/jsondiffpatch.cjs';
|
|
6
5
|
import forEach from 'lodash.foreach';
|
|
7
6
|
import uniqWith from 'lodash.uniqwith';
|
|
8
7
|
import intersection from 'lodash.intersection';
|
|
9
8
|
import without from 'lodash.without';
|
|
10
|
-
import sortBy
|
|
9
|
+
import sortBy from 'lodash.sortby';
|
|
11
10
|
|
|
12
11
|
function _arrayLikeToArray(r, a) {
|
|
13
12
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -125,14 +124,14 @@ function _toPropertyKey(t) {
|
|
|
125
124
|
var i = _toPrimitive(t, "string");
|
|
126
125
|
return "symbol" == typeof i ? i : i + "";
|
|
127
126
|
}
|
|
128
|
-
function _typeof
|
|
127
|
+
function _typeof(o) {
|
|
129
128
|
"@babel/helpers - typeof";
|
|
130
129
|
|
|
131
|
-
return _typeof
|
|
130
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
132
131
|
return typeof o;
|
|
133
132
|
} : function (o) {
|
|
134
133
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
135
|
-
}, _typeof
|
|
134
|
+
}, _typeof(o);
|
|
136
135
|
}
|
|
137
136
|
function _unsupportedIterableToArray(r, a) {
|
|
138
137
|
if (r) {
|
|
@@ -233,2451 +232,9 @@ function createMapActionGroup() {
|
|
|
233
232
|
};
|
|
234
233
|
}
|
|
235
234
|
|
|
236
|
-
var _typeof = typeof Symbol === "function" && _typeof$1(Symbol.iterator) === "symbol" ? function (obj) {
|
|
237
|
-
return _typeof$1(obj);
|
|
238
|
-
} : function (obj) {
|
|
239
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof$1(obj);
|
|
240
|
-
};
|
|
241
|
-
var classCallCheck = function classCallCheck(instance, Constructor) {
|
|
242
|
-
if (!(instance instanceof Constructor)) {
|
|
243
|
-
throw new TypeError("Cannot call a class as a function");
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
var createClass = function () {
|
|
247
|
-
function defineProperties(target, props) {
|
|
248
|
-
for (var i = 0; i < props.length; i++) {
|
|
249
|
-
var descriptor = props[i];
|
|
250
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
251
|
-
descriptor.configurable = true;
|
|
252
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
253
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return function (Constructor, protoProps, staticProps) {
|
|
257
|
-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
258
|
-
if (staticProps) defineProperties(Constructor, staticProps);
|
|
259
|
-
return Constructor;
|
|
260
|
-
};
|
|
261
|
-
}();
|
|
262
|
-
var get = function get(object, property, receiver) {
|
|
263
|
-
if (object === null) object = Function.prototype;
|
|
264
|
-
var desc = Object.getOwnPropertyDescriptor(object, property);
|
|
265
|
-
if (desc === undefined) {
|
|
266
|
-
var parent = Object.getPrototypeOf(object);
|
|
267
|
-
if (parent === null) {
|
|
268
|
-
return undefined;
|
|
269
|
-
} else {
|
|
270
|
-
return get(parent, property, receiver);
|
|
271
|
-
}
|
|
272
|
-
} else if ("value" in desc) {
|
|
273
|
-
return desc.value;
|
|
274
|
-
} else {
|
|
275
|
-
var getter = desc.get;
|
|
276
|
-
if (getter === undefined) {
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
return getter.call(receiver);
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
var inherits = function inherits(subClass, superClass) {
|
|
283
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
284
|
-
throw new TypeError("Super expression must either be null or a function, not " + _typeof$1(superClass));
|
|
285
|
-
}
|
|
286
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
287
|
-
constructor: {
|
|
288
|
-
value: subClass,
|
|
289
|
-
enumerable: false,
|
|
290
|
-
writable: true,
|
|
291
|
-
configurable: true
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
|
295
|
-
};
|
|
296
|
-
var possibleConstructorReturn = function possibleConstructorReturn(self, call) {
|
|
297
|
-
if (!self) {
|
|
298
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
299
|
-
}
|
|
300
|
-
return call && (_typeof$1(call) === "object" || typeof call === "function") ? call : self;
|
|
301
|
-
};
|
|
302
|
-
var slicedToArray = function () {
|
|
303
|
-
function sliceIterator(arr, i) {
|
|
304
|
-
var _arr = [];
|
|
305
|
-
var _n = true;
|
|
306
|
-
var _d = false;
|
|
307
|
-
var _e = undefined;
|
|
308
|
-
try {
|
|
309
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
310
|
-
_arr.push(_s.value);
|
|
311
|
-
if (i && _arr.length === i) break;
|
|
312
|
-
}
|
|
313
|
-
} catch (err) {
|
|
314
|
-
_d = true;
|
|
315
|
-
_e = err;
|
|
316
|
-
} finally {
|
|
317
|
-
try {
|
|
318
|
-
if (!_n && _i["return"]) _i["return"]();
|
|
319
|
-
} finally {
|
|
320
|
-
if (_d) throw _e;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return _arr;
|
|
324
|
-
}
|
|
325
|
-
return function (arr, i) {
|
|
326
|
-
if (Array.isArray(arr)) {
|
|
327
|
-
return arr;
|
|
328
|
-
} else if (Symbol.iterator in Object(arr)) {
|
|
329
|
-
return sliceIterator(arr, i);
|
|
330
|
-
} else {
|
|
331
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
}();
|
|
335
|
-
var toConsumableArray = function toConsumableArray(arr) {
|
|
336
|
-
if (Array.isArray(arr)) {
|
|
337
|
-
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
338
|
-
return arr2;
|
|
339
|
-
} else {
|
|
340
|
-
return Array.from(arr);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var Processor = function () {
|
|
344
|
-
function Processor(options) {
|
|
345
|
-
classCallCheck(this, Processor);
|
|
346
|
-
this.selfOptions = options || {};
|
|
347
|
-
this.pipes = {};
|
|
348
|
-
}
|
|
349
|
-
createClass(Processor, [{
|
|
350
|
-
key: 'options',
|
|
351
|
-
value: function options(_options) {
|
|
352
|
-
if (_options) {
|
|
353
|
-
this.selfOptions = _options;
|
|
354
|
-
}
|
|
355
|
-
return this.selfOptions;
|
|
356
|
-
}
|
|
357
|
-
}, {
|
|
358
|
-
key: 'pipe',
|
|
359
|
-
value: function pipe(name, pipeArg) {
|
|
360
|
-
var pipe = pipeArg;
|
|
361
|
-
if (typeof name === 'string') {
|
|
362
|
-
if (typeof pipe === 'undefined') {
|
|
363
|
-
return this.pipes[name];
|
|
364
|
-
} else {
|
|
365
|
-
this.pipes[name] = pipe;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (name && name.name) {
|
|
369
|
-
pipe = name;
|
|
370
|
-
if (pipe.processor === this) {
|
|
371
|
-
return pipe;
|
|
372
|
-
}
|
|
373
|
-
this.pipes[pipe.name] = pipe;
|
|
374
|
-
}
|
|
375
|
-
pipe.processor = this;
|
|
376
|
-
return pipe;
|
|
377
|
-
}
|
|
378
|
-
}, {
|
|
379
|
-
key: 'process',
|
|
380
|
-
value: function process(input, pipe) {
|
|
381
|
-
var context = input;
|
|
382
|
-
context.options = this.options();
|
|
383
|
-
var nextPipe = pipe || input.pipe || 'default';
|
|
384
|
-
var lastPipe = void 0;
|
|
385
|
-
var lastContext = void 0;
|
|
386
|
-
while (nextPipe) {
|
|
387
|
-
if (typeof context.nextAfterChildren !== 'undefined') {
|
|
388
|
-
// children processed and coming back to parent
|
|
389
|
-
context.next = context.nextAfterChildren;
|
|
390
|
-
context.nextAfterChildren = null;
|
|
391
|
-
}
|
|
392
|
-
if (typeof nextPipe === 'string') {
|
|
393
|
-
nextPipe = this.pipe(nextPipe);
|
|
394
|
-
}
|
|
395
|
-
nextPipe.process(context);
|
|
396
|
-
lastContext = context;
|
|
397
|
-
lastPipe = nextPipe;
|
|
398
|
-
nextPipe = null;
|
|
399
|
-
if (context) {
|
|
400
|
-
if (context.next) {
|
|
401
|
-
context = context.next;
|
|
402
|
-
nextPipe = lastContext.nextPipe || context.pipe || lastPipe;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return context.hasResult ? context.result : undefined;
|
|
407
|
-
}
|
|
408
|
-
}]);
|
|
409
|
-
return Processor;
|
|
410
|
-
}();
|
|
411
|
-
var Pipe = function () {
|
|
412
|
-
function Pipe(name) {
|
|
413
|
-
classCallCheck(this, Pipe);
|
|
414
|
-
this.name = name;
|
|
415
|
-
this.filters = [];
|
|
416
|
-
}
|
|
417
|
-
createClass(Pipe, [{
|
|
418
|
-
key: 'process',
|
|
419
|
-
value: function process(input) {
|
|
420
|
-
if (!this.processor) {
|
|
421
|
-
throw new Error('add this pipe to a processor before using it');
|
|
422
|
-
}
|
|
423
|
-
var debug = this.debug;
|
|
424
|
-
var length = this.filters.length;
|
|
425
|
-
var context = input;
|
|
426
|
-
for (var index = 0; index < length; index++) {
|
|
427
|
-
var filter = this.filters[index];
|
|
428
|
-
if (debug) {
|
|
429
|
-
this.log('filter: ' + filter.filterName);
|
|
430
|
-
}
|
|
431
|
-
filter(context);
|
|
432
|
-
if ((typeof context === 'undefined' ? 'undefined' : _typeof(context)) === 'object' && context.exiting) {
|
|
433
|
-
context.exiting = false;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if (!context.next && this.resultCheck) {
|
|
438
|
-
this.resultCheck(context);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}, {
|
|
442
|
-
key: 'log',
|
|
443
|
-
value: function log(msg) {
|
|
444
|
-
console.log('[jsondiffpatch] ' + this.name + ' pipe, ' + msg);
|
|
445
|
-
}
|
|
446
|
-
}, {
|
|
447
|
-
key: 'append',
|
|
448
|
-
value: function append() {
|
|
449
|
-
var _filters;
|
|
450
|
-
(_filters = this.filters).push.apply(_filters, arguments);
|
|
451
|
-
return this;
|
|
452
|
-
}
|
|
453
|
-
}, {
|
|
454
|
-
key: 'prepend',
|
|
455
|
-
value: function prepend() {
|
|
456
|
-
var _filters2;
|
|
457
|
-
(_filters2 = this.filters).unshift.apply(_filters2, arguments);
|
|
458
|
-
return this;
|
|
459
|
-
}
|
|
460
|
-
}, {
|
|
461
|
-
key: 'indexOf',
|
|
462
|
-
value: function indexOf(filterName) {
|
|
463
|
-
if (!filterName) {
|
|
464
|
-
throw new Error('a filter name is required');
|
|
465
|
-
}
|
|
466
|
-
for (var index = 0; index < this.filters.length; index++) {
|
|
467
|
-
var filter = this.filters[index];
|
|
468
|
-
if (filter.filterName === filterName) {
|
|
469
|
-
return index;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
throw new Error('filter not found: ' + filterName);
|
|
473
|
-
}
|
|
474
|
-
}, {
|
|
475
|
-
key: 'list',
|
|
476
|
-
value: function list() {
|
|
477
|
-
return this.filters.map(function (f) {
|
|
478
|
-
return f.filterName;
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}, {
|
|
482
|
-
key: 'after',
|
|
483
|
-
value: function after(filterName) {
|
|
484
|
-
var index = this.indexOf(filterName);
|
|
485
|
-
var params = Array.prototype.slice.call(arguments, 1);
|
|
486
|
-
if (!params.length) {
|
|
487
|
-
throw new Error('a filter is required');
|
|
488
|
-
}
|
|
489
|
-
params.unshift(index + 1, 0);
|
|
490
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
491
|
-
return this;
|
|
492
|
-
}
|
|
493
|
-
}, {
|
|
494
|
-
key: 'before',
|
|
495
|
-
value: function before(filterName) {
|
|
496
|
-
var index = this.indexOf(filterName);
|
|
497
|
-
var params = Array.prototype.slice.call(arguments, 1);
|
|
498
|
-
if (!params.length) {
|
|
499
|
-
throw new Error('a filter is required');
|
|
500
|
-
}
|
|
501
|
-
params.unshift(index, 0);
|
|
502
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
503
|
-
return this;
|
|
504
|
-
}
|
|
505
|
-
}, {
|
|
506
|
-
key: 'replace',
|
|
507
|
-
value: function replace(filterName) {
|
|
508
|
-
var index = this.indexOf(filterName);
|
|
509
|
-
var params = Array.prototype.slice.call(arguments, 1);
|
|
510
|
-
if (!params.length) {
|
|
511
|
-
throw new Error('a filter is required');
|
|
512
|
-
}
|
|
513
|
-
params.unshift(index, 1);
|
|
514
|
-
Array.prototype.splice.apply(this.filters, params);
|
|
515
|
-
return this;
|
|
516
|
-
}
|
|
517
|
-
}, {
|
|
518
|
-
key: 'remove',
|
|
519
|
-
value: function remove(filterName) {
|
|
520
|
-
var index = this.indexOf(filterName);
|
|
521
|
-
this.filters.splice(index, 1);
|
|
522
|
-
return this;
|
|
523
|
-
}
|
|
524
|
-
}, {
|
|
525
|
-
key: 'clear',
|
|
526
|
-
value: function clear() {
|
|
527
|
-
this.filters.length = 0;
|
|
528
|
-
return this;
|
|
529
|
-
}
|
|
530
|
-
}, {
|
|
531
|
-
key: 'shouldHaveResult',
|
|
532
|
-
value: function shouldHaveResult(should) {
|
|
533
|
-
if (should === false) {
|
|
534
|
-
this.resultCheck = null;
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
if (this.resultCheck) {
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
var pipe = this;
|
|
541
|
-
this.resultCheck = function (context) {
|
|
542
|
-
if (!context.hasResult) {
|
|
543
|
-
console.log(context);
|
|
544
|
-
var error = new Error(pipe.name + ' failed');
|
|
545
|
-
error.noResult = true;
|
|
546
|
-
throw error;
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
return this;
|
|
550
|
-
}
|
|
551
|
-
}]);
|
|
552
|
-
return Pipe;
|
|
553
|
-
}();
|
|
554
|
-
var Context = function () {
|
|
555
|
-
function Context() {
|
|
556
|
-
classCallCheck(this, Context);
|
|
557
|
-
}
|
|
558
|
-
createClass(Context, [{
|
|
559
|
-
key: 'setResult',
|
|
560
|
-
value: function setResult(result) {
|
|
561
|
-
this.result = result;
|
|
562
|
-
this.hasResult = true;
|
|
563
|
-
return this;
|
|
564
|
-
}
|
|
565
|
-
}, {
|
|
566
|
-
key: 'exit',
|
|
567
|
-
value: function exit() {
|
|
568
|
-
this.exiting = true;
|
|
569
|
-
return this;
|
|
570
|
-
}
|
|
571
|
-
}, {
|
|
572
|
-
key: 'switchTo',
|
|
573
|
-
value: function switchTo(next, pipe) {
|
|
574
|
-
if (typeof next === 'string' || next instanceof Pipe) {
|
|
575
|
-
this.nextPipe = next;
|
|
576
|
-
} else {
|
|
577
|
-
this.next = next;
|
|
578
|
-
if (pipe) {
|
|
579
|
-
this.nextPipe = pipe;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
return this;
|
|
583
|
-
}
|
|
584
|
-
}, {
|
|
585
|
-
key: 'push',
|
|
586
|
-
value: function push(child, name) {
|
|
587
|
-
child.parent = this;
|
|
588
|
-
if (typeof name !== 'undefined') {
|
|
589
|
-
child.childName = name;
|
|
590
|
-
}
|
|
591
|
-
child.root = this.root || this;
|
|
592
|
-
child.options = child.options || this.options;
|
|
593
|
-
if (!this.children) {
|
|
594
|
-
this.children = [child];
|
|
595
|
-
this.nextAfterChildren = this.next || null;
|
|
596
|
-
this.next = child;
|
|
597
|
-
} else {
|
|
598
|
-
this.children[this.children.length - 1].next = child;
|
|
599
|
-
this.children.push(child);
|
|
600
|
-
}
|
|
601
|
-
child.next = this;
|
|
602
|
-
return this;
|
|
603
|
-
}
|
|
604
|
-
}]);
|
|
605
|
-
return Context;
|
|
606
|
-
}();
|
|
607
|
-
var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
608
|
-
return a instanceof Array;
|
|
609
|
-
};
|
|
610
|
-
function cloneRegExp(re) {
|
|
611
|
-
var regexMatch = /^\/(.*)\/([gimyu]*)$/.exec(re.toString());
|
|
612
|
-
return new RegExp(regexMatch[1], regexMatch[2]);
|
|
613
|
-
}
|
|
614
|
-
function clone$1(arg) {
|
|
615
|
-
if ((typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) !== 'object') {
|
|
616
|
-
return arg;
|
|
617
|
-
}
|
|
618
|
-
if (arg === null) {
|
|
619
|
-
return null;
|
|
620
|
-
}
|
|
621
|
-
if (isArray(arg)) {
|
|
622
|
-
return arg.map(clone$1);
|
|
623
|
-
}
|
|
624
|
-
if (arg instanceof Date) {
|
|
625
|
-
return new Date(arg.getTime());
|
|
626
|
-
}
|
|
627
|
-
if (arg instanceof RegExp) {
|
|
628
|
-
return cloneRegExp(arg);
|
|
629
|
-
}
|
|
630
|
-
var cloned = {};
|
|
631
|
-
for (var name in arg) {
|
|
632
|
-
if (Object.prototype.hasOwnProperty.call(arg, name)) {
|
|
633
|
-
cloned[name] = clone$1(arg[name]);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
return cloned;
|
|
637
|
-
}
|
|
638
|
-
var DiffContext = function (_Context) {
|
|
639
|
-
inherits(DiffContext, _Context);
|
|
640
|
-
function DiffContext(left, right) {
|
|
641
|
-
classCallCheck(this, DiffContext);
|
|
642
|
-
var _this = possibleConstructorReturn(this, (DiffContext.__proto__ || Object.getPrototypeOf(DiffContext)).call(this));
|
|
643
|
-
_this.left = left;
|
|
644
|
-
_this.right = right;
|
|
645
|
-
_this.pipe = 'diff';
|
|
646
|
-
return _this;
|
|
647
|
-
}
|
|
648
|
-
createClass(DiffContext, [{
|
|
649
|
-
key: 'setResult',
|
|
650
|
-
value: function setResult(result) {
|
|
651
|
-
if (this.options.cloneDiffValues && (typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object') {
|
|
652
|
-
var clone$$1 = typeof this.options.cloneDiffValues === 'function' ? this.options.cloneDiffValues : clone$1;
|
|
653
|
-
if (_typeof(result[0]) === 'object') {
|
|
654
|
-
result[0] = clone$$1(result[0]);
|
|
655
|
-
}
|
|
656
|
-
if (_typeof(result[1]) === 'object') {
|
|
657
|
-
result[1] = clone$$1(result[1]);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
return Context.prototype.setResult.apply(this, arguments);
|
|
661
|
-
}
|
|
662
|
-
}]);
|
|
663
|
-
return DiffContext;
|
|
664
|
-
}(Context);
|
|
665
|
-
var PatchContext = function (_Context) {
|
|
666
|
-
inherits(PatchContext, _Context);
|
|
667
|
-
function PatchContext(left, delta) {
|
|
668
|
-
classCallCheck(this, PatchContext);
|
|
669
|
-
var _this = possibleConstructorReturn(this, (PatchContext.__proto__ || Object.getPrototypeOf(PatchContext)).call(this));
|
|
670
|
-
_this.left = left;
|
|
671
|
-
_this.delta = delta;
|
|
672
|
-
_this.pipe = 'patch';
|
|
673
|
-
return _this;
|
|
674
|
-
}
|
|
675
|
-
return PatchContext;
|
|
676
|
-
}(Context);
|
|
677
|
-
var ReverseContext = function (_Context) {
|
|
678
|
-
inherits(ReverseContext, _Context);
|
|
679
|
-
function ReverseContext(delta) {
|
|
680
|
-
classCallCheck(this, ReverseContext);
|
|
681
|
-
var _this = possibleConstructorReturn(this, (ReverseContext.__proto__ || Object.getPrototypeOf(ReverseContext)).call(this));
|
|
682
|
-
_this.delta = delta;
|
|
683
|
-
_this.pipe = 'reverse';
|
|
684
|
-
return _this;
|
|
685
|
-
}
|
|
686
|
-
return ReverseContext;
|
|
687
|
-
}(Context);
|
|
688
|
-
var isArray$1 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
689
|
-
return a instanceof Array;
|
|
690
|
-
};
|
|
691
|
-
var diffFilter = function trivialMatchesDiffFilter(context) {
|
|
692
|
-
if (context.left === context.right) {
|
|
693
|
-
context.setResult(undefined).exit();
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
if (typeof context.left === 'undefined') {
|
|
697
|
-
if (typeof context.right === 'function') {
|
|
698
|
-
throw new Error('functions are not supported');
|
|
699
|
-
}
|
|
700
|
-
context.setResult([context.right]).exit();
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
if (typeof context.right === 'undefined') {
|
|
704
|
-
context.setResult([context.left, 0, 0]).exit();
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
if (typeof context.left === 'function' || typeof context.right === 'function') {
|
|
708
|
-
throw new Error('functions are not supported');
|
|
709
|
-
}
|
|
710
|
-
context.leftType = context.left === null ? 'null' : _typeof(context.left);
|
|
711
|
-
context.rightType = context.right === null ? 'null' : _typeof(context.right);
|
|
712
|
-
if (context.leftType !== context.rightType) {
|
|
713
|
-
context.setResult([context.left, context.right]).exit();
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
if (context.leftType === 'boolean' || context.leftType === 'number') {
|
|
717
|
-
context.setResult([context.left, context.right]).exit();
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (context.leftType === 'object') {
|
|
721
|
-
context.leftIsArray = isArray$1(context.left);
|
|
722
|
-
}
|
|
723
|
-
if (context.rightType === 'object') {
|
|
724
|
-
context.rightIsArray = isArray$1(context.right);
|
|
725
|
-
}
|
|
726
|
-
if (context.leftIsArray !== context.rightIsArray) {
|
|
727
|
-
context.setResult([context.left, context.right]).exit();
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
if (context.left instanceof RegExp) {
|
|
731
|
-
if (context.right instanceof RegExp) {
|
|
732
|
-
context.setResult([context.left.toString(), context.right.toString()]).exit();
|
|
733
|
-
} else {
|
|
734
|
-
context.setResult([context.left, context.right]).exit();
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
diffFilter.filterName = 'trivial';
|
|
739
|
-
var patchFilter = function trivialMatchesPatchFilter(context) {
|
|
740
|
-
if (typeof context.delta === 'undefined') {
|
|
741
|
-
context.setResult(context.left).exit();
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
context.nested = !isArray$1(context.delta);
|
|
745
|
-
if (context.nested) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
if (context.delta.length === 1) {
|
|
749
|
-
context.setResult(context.delta[0]).exit();
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
if (context.delta.length === 2) {
|
|
753
|
-
if (context.left instanceof RegExp) {
|
|
754
|
-
var regexArgs = /^\/(.*)\/([gimyu]+)$/.exec(context.delta[1]);
|
|
755
|
-
if (regexArgs) {
|
|
756
|
-
context.setResult(new RegExp(regexArgs[1], regexArgs[2])).exit();
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
context.setResult(context.delta[1]).exit();
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
if (context.delta.length === 3 && context.delta[2] === 0) {
|
|
764
|
-
context.setResult(undefined).exit();
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
patchFilter.filterName = 'trivial';
|
|
768
|
-
var reverseFilter = function trivialReferseFilter(context) {
|
|
769
|
-
if (typeof context.delta === 'undefined') {
|
|
770
|
-
context.setResult(context.delta).exit();
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
context.nested = !isArray$1(context.delta);
|
|
774
|
-
if (context.nested) {
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
if (context.delta.length === 1) {
|
|
778
|
-
context.setResult([context.delta[0], 0, 0]).exit();
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
if (context.delta.length === 2) {
|
|
782
|
-
context.setResult([context.delta[1], context.delta[0]]).exit();
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
if (context.delta.length === 3 && context.delta[2] === 0) {
|
|
786
|
-
context.setResult([context.delta[0]]).exit();
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
reverseFilter.filterName = 'trivial';
|
|
790
|
-
function collectChildrenDiffFilter(context) {
|
|
791
|
-
if (!context || !context.children) {
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
var length = context.children.length;
|
|
795
|
-
var child = void 0;
|
|
796
|
-
var result = context.result;
|
|
797
|
-
for (var index = 0; index < length; index++) {
|
|
798
|
-
child = context.children[index];
|
|
799
|
-
if (typeof child.result === 'undefined') {
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
result = result || {};
|
|
803
|
-
result[child.childName] = child.result;
|
|
804
|
-
}
|
|
805
|
-
if (result && context.leftIsArray) {
|
|
806
|
-
result._t = 'a';
|
|
807
|
-
}
|
|
808
|
-
context.setResult(result).exit();
|
|
809
|
-
}
|
|
810
|
-
collectChildrenDiffFilter.filterName = 'collectChildren';
|
|
811
|
-
function objectsDiffFilter(context) {
|
|
812
|
-
if (context.leftIsArray || context.leftType !== 'object') {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
var name = void 0;
|
|
816
|
-
var child = void 0;
|
|
817
|
-
var propertyFilter = context.options.propertyFilter;
|
|
818
|
-
for (name in context.left) {
|
|
819
|
-
if (!Object.prototype.hasOwnProperty.call(context.left, name)) {
|
|
820
|
-
continue;
|
|
821
|
-
}
|
|
822
|
-
if (propertyFilter && !propertyFilter(name, context)) {
|
|
823
|
-
continue;
|
|
824
|
-
}
|
|
825
|
-
child = new DiffContext(context.left[name], context.right[name]);
|
|
826
|
-
context.push(child, name);
|
|
827
|
-
}
|
|
828
|
-
for (name in context.right) {
|
|
829
|
-
if (!Object.prototype.hasOwnProperty.call(context.right, name)) {
|
|
830
|
-
continue;
|
|
831
|
-
}
|
|
832
|
-
if (propertyFilter && !propertyFilter(name, context)) {
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
if (typeof context.left[name] === 'undefined') {
|
|
836
|
-
child = new DiffContext(undefined, context.right[name]);
|
|
837
|
-
context.push(child, name);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
if (!context.children || context.children.length === 0) {
|
|
841
|
-
context.setResult(undefined).exit();
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
context.exit();
|
|
845
|
-
}
|
|
846
|
-
objectsDiffFilter.filterName = 'objects';
|
|
847
|
-
var patchFilter$1 = function nestedPatchFilter(context) {
|
|
848
|
-
if (!context.nested) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
if (context.delta._t) {
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
var name = void 0;
|
|
855
|
-
var child = void 0;
|
|
856
|
-
for (name in context.delta) {
|
|
857
|
-
child = new PatchContext(context.left[name], context.delta[name]);
|
|
858
|
-
context.push(child, name);
|
|
859
|
-
}
|
|
860
|
-
context.exit();
|
|
861
|
-
};
|
|
862
|
-
patchFilter$1.filterName = 'objects';
|
|
863
|
-
var collectChildrenPatchFilter = function collectChildrenPatchFilter(context) {
|
|
864
|
-
if (!context || !context.children) {
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
if (context.delta._t) {
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
var length = context.children.length;
|
|
871
|
-
var child = void 0;
|
|
872
|
-
for (var index = 0; index < length; index++) {
|
|
873
|
-
child = context.children[index];
|
|
874
|
-
if (Object.prototype.hasOwnProperty.call(context.left, child.childName) && child.result === undefined) {
|
|
875
|
-
delete context.left[child.childName];
|
|
876
|
-
} else if (context.left[child.childName] !== child.result) {
|
|
877
|
-
context.left[child.childName] = child.result;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
context.setResult(context.left).exit();
|
|
881
|
-
};
|
|
882
|
-
collectChildrenPatchFilter.filterName = 'collectChildren';
|
|
883
|
-
var reverseFilter$1 = function nestedReverseFilter(context) {
|
|
884
|
-
if (!context.nested) {
|
|
885
|
-
return;
|
|
886
|
-
}
|
|
887
|
-
if (context.delta._t) {
|
|
888
|
-
return;
|
|
889
|
-
}
|
|
890
|
-
var name = void 0;
|
|
891
|
-
var child = void 0;
|
|
892
|
-
for (name in context.delta) {
|
|
893
|
-
child = new ReverseContext(context.delta[name]);
|
|
894
|
-
context.push(child, name);
|
|
895
|
-
}
|
|
896
|
-
context.exit();
|
|
897
|
-
};
|
|
898
|
-
reverseFilter$1.filterName = 'objects';
|
|
899
|
-
function collectChildrenReverseFilter(context) {
|
|
900
|
-
if (!context || !context.children) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
if (context.delta._t) {
|
|
904
|
-
return;
|
|
905
|
-
}
|
|
906
|
-
var length = context.children.length;
|
|
907
|
-
var child = void 0;
|
|
908
|
-
var delta = {};
|
|
909
|
-
for (var index = 0; index < length; index++) {
|
|
910
|
-
child = context.children[index];
|
|
911
|
-
if (delta[child.childName] !== child.result) {
|
|
912
|
-
delta[child.childName] = child.result;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
context.setResult(delta).exit();
|
|
916
|
-
}
|
|
917
|
-
collectChildrenReverseFilter.filterName = 'collectChildren';
|
|
918
|
-
|
|
919
|
-
/*
|
|
920
|
-
|
|
921
|
-
LCS implementation that supports arrays or strings
|
|
922
|
-
|
|
923
|
-
reference: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
|
|
924
|
-
|
|
925
|
-
*/
|
|
926
|
-
|
|
927
|
-
var defaultMatch = function defaultMatch(array1, array2, index1, index2) {
|
|
928
|
-
return array1[index1] === array2[index2];
|
|
929
|
-
};
|
|
930
|
-
var lengthMatrix = function lengthMatrix(array1, array2, match, context) {
|
|
931
|
-
var len1 = array1.length;
|
|
932
|
-
var len2 = array2.length;
|
|
933
|
-
var x = void 0,
|
|
934
|
-
y = void 0;
|
|
935
|
-
|
|
936
|
-
// initialize empty matrix of len1+1 x len2+1
|
|
937
|
-
var matrix = [len1 + 1];
|
|
938
|
-
for (x = 0; x < len1 + 1; x++) {
|
|
939
|
-
matrix[x] = [len2 + 1];
|
|
940
|
-
for (y = 0; y < len2 + 1; y++) {
|
|
941
|
-
matrix[x][y] = 0;
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
matrix.match = match;
|
|
945
|
-
// save sequence lengths for each coordinate
|
|
946
|
-
for (x = 1; x < len1 + 1; x++) {
|
|
947
|
-
for (y = 1; y < len2 + 1; y++) {
|
|
948
|
-
if (match(array1, array2, x - 1, y - 1, context)) {
|
|
949
|
-
matrix[x][y] = matrix[x - 1][y - 1] + 1;
|
|
950
|
-
} else {
|
|
951
|
-
matrix[x][y] = Math.max(matrix[x - 1][y], matrix[x][y - 1]);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
return matrix;
|
|
956
|
-
};
|
|
957
|
-
var backtrack = function backtrack(matrix, array1, array2, context) {
|
|
958
|
-
var index1 = array1.length;
|
|
959
|
-
var index2 = array2.length;
|
|
960
|
-
var subsequence = {
|
|
961
|
-
sequence: [],
|
|
962
|
-
indices1: [],
|
|
963
|
-
indices2: []
|
|
964
|
-
};
|
|
965
|
-
while (index1 !== 0 && index2 !== 0) {
|
|
966
|
-
var sameLetter = matrix.match(array1, array2, index1 - 1, index2 - 1, context);
|
|
967
|
-
if (sameLetter) {
|
|
968
|
-
subsequence.sequence.unshift(array1[index1 - 1]);
|
|
969
|
-
subsequence.indices1.unshift(index1 - 1);
|
|
970
|
-
subsequence.indices2.unshift(index2 - 1);
|
|
971
|
-
--index1;
|
|
972
|
-
--index2;
|
|
973
|
-
} else {
|
|
974
|
-
var valueAtMatrixAbove = matrix[index1][index2 - 1];
|
|
975
|
-
var valueAtMatrixLeft = matrix[index1 - 1][index2];
|
|
976
|
-
if (valueAtMatrixAbove > valueAtMatrixLeft) {
|
|
977
|
-
--index2;
|
|
978
|
-
} else {
|
|
979
|
-
--index1;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
return subsequence;
|
|
984
|
-
};
|
|
985
|
-
var get$1 = function get(array1, array2, match, context) {
|
|
986
|
-
var innerContext = context || {};
|
|
987
|
-
var matrix = lengthMatrix(array1, array2, match || defaultMatch, innerContext);
|
|
988
|
-
var result = backtrack(matrix, array1, array2, innerContext);
|
|
989
|
-
if (typeof array1 === 'string' && typeof array2 === 'string') {
|
|
990
|
-
result.sequence = result.sequence.join('');
|
|
991
|
-
}
|
|
992
|
-
return result;
|
|
993
|
-
};
|
|
994
|
-
var lcs = {
|
|
995
|
-
get: get$1
|
|
996
|
-
};
|
|
997
|
-
var ARRAY_MOVE = 3;
|
|
998
|
-
var isArray$2 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
999
|
-
return a instanceof Array;
|
|
1000
|
-
};
|
|
1001
|
-
var arrayIndexOf = typeof Array.prototype.indexOf === 'function' ? function (array, item) {
|
|
1002
|
-
return array.indexOf(item);
|
|
1003
|
-
} : function (array, item) {
|
|
1004
|
-
var length = array.length;
|
|
1005
|
-
for (var i = 0; i < length; i++) {
|
|
1006
|
-
if (array[i] === item) {
|
|
1007
|
-
return i;
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
return -1;
|
|
1011
|
-
};
|
|
1012
|
-
function arraysHaveMatchByRef(array1, array2, len1, len2) {
|
|
1013
|
-
for (var index1 = 0; index1 < len1; index1++) {
|
|
1014
|
-
var val1 = array1[index1];
|
|
1015
|
-
for (var index2 = 0; index2 < len2; index2++) {
|
|
1016
|
-
var val2 = array2[index2];
|
|
1017
|
-
if (index1 !== index2 && val1 === val2) {
|
|
1018
|
-
return true;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
function matchItems(array1, array2, index1, index2, context) {
|
|
1024
|
-
var value1 = array1[index1];
|
|
1025
|
-
var value2 = array2[index2];
|
|
1026
|
-
if (value1 === value2) {
|
|
1027
|
-
return true;
|
|
1028
|
-
}
|
|
1029
|
-
if ((typeof value1 === 'undefined' ? 'undefined' : _typeof(value1)) !== 'object' || (typeof value2 === 'undefined' ? 'undefined' : _typeof(value2)) !== 'object') {
|
|
1030
|
-
return false;
|
|
1031
|
-
}
|
|
1032
|
-
var objectHash = context.objectHash;
|
|
1033
|
-
if (!objectHash) {
|
|
1034
|
-
// no way to match objects was provided, try match by position
|
|
1035
|
-
return context.matchByPosition && index1 === index2;
|
|
1036
|
-
}
|
|
1037
|
-
var hash1 = void 0;
|
|
1038
|
-
var hash2 = void 0;
|
|
1039
|
-
if (typeof index1 === 'number') {
|
|
1040
|
-
context.hashCache1 = context.hashCache1 || [];
|
|
1041
|
-
hash1 = context.hashCache1[index1];
|
|
1042
|
-
if (typeof hash1 === 'undefined') {
|
|
1043
|
-
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
|
|
1044
|
-
}
|
|
1045
|
-
} else {
|
|
1046
|
-
hash1 = objectHash(value1);
|
|
1047
|
-
}
|
|
1048
|
-
if (typeof hash1 === 'undefined') {
|
|
1049
|
-
return false;
|
|
1050
|
-
}
|
|
1051
|
-
if (typeof index2 === 'number') {
|
|
1052
|
-
context.hashCache2 = context.hashCache2 || [];
|
|
1053
|
-
hash2 = context.hashCache2[index2];
|
|
1054
|
-
if (typeof hash2 === 'undefined') {
|
|
1055
|
-
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
|
|
1056
|
-
}
|
|
1057
|
-
} else {
|
|
1058
|
-
hash2 = objectHash(value2);
|
|
1059
|
-
}
|
|
1060
|
-
if (typeof hash2 === 'undefined') {
|
|
1061
|
-
return false;
|
|
1062
|
-
}
|
|
1063
|
-
return hash1 === hash2;
|
|
1064
|
-
}
|
|
1065
|
-
var diffFilter$1 = function arraysDiffFilter(context) {
|
|
1066
|
-
if (!context.leftIsArray) {
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
var matchContext = {
|
|
1070
|
-
objectHash: context.options && context.options.objectHash,
|
|
1071
|
-
matchByPosition: context.options && context.options.matchByPosition
|
|
1072
|
-
};
|
|
1073
|
-
var commonHead = 0;
|
|
1074
|
-
var commonTail = 0;
|
|
1075
|
-
var index = void 0;
|
|
1076
|
-
var index1 = void 0;
|
|
1077
|
-
var index2 = void 0;
|
|
1078
|
-
var array1 = context.left;
|
|
1079
|
-
var array2 = context.right;
|
|
1080
|
-
var len1 = array1.length;
|
|
1081
|
-
var len2 = array2.length;
|
|
1082
|
-
var child = void 0;
|
|
1083
|
-
if (len1 > 0 && len2 > 0 && !matchContext.objectHash && typeof matchContext.matchByPosition !== 'boolean') {
|
|
1084
|
-
matchContext.matchByPosition = !arraysHaveMatchByRef(array1, array2, len1, len2);
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
// separate common head
|
|
1088
|
-
while (commonHead < len1 && commonHead < len2 && matchItems(array1, array2, commonHead, commonHead, matchContext)) {
|
|
1089
|
-
index = commonHead;
|
|
1090
|
-
child = new DiffContext(context.left[index], context.right[index]);
|
|
1091
|
-
context.push(child, index);
|
|
1092
|
-
commonHead++;
|
|
1093
|
-
}
|
|
1094
|
-
// separate common tail
|
|
1095
|
-
while (commonTail + commonHead < len1 && commonTail + commonHead < len2 && matchItems(array1, array2, len1 - 1 - commonTail, len2 - 1 - commonTail, matchContext)) {
|
|
1096
|
-
index1 = len1 - 1 - commonTail;
|
|
1097
|
-
index2 = len2 - 1 - commonTail;
|
|
1098
|
-
child = new DiffContext(context.left[index1], context.right[index2]);
|
|
1099
|
-
context.push(child, index2);
|
|
1100
|
-
commonTail++;
|
|
1101
|
-
}
|
|
1102
|
-
var result = void 0;
|
|
1103
|
-
if (commonHead + commonTail === len1) {
|
|
1104
|
-
if (len1 === len2) {
|
|
1105
|
-
// arrays are identical
|
|
1106
|
-
context.setResult(undefined).exit();
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
// trivial case, a block (1 or more consecutive items) was added
|
|
1110
|
-
result = result || {
|
|
1111
|
-
_t: 'a'
|
|
1112
|
-
};
|
|
1113
|
-
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
1114
|
-
result[index] = [array2[index]];
|
|
1115
|
-
}
|
|
1116
|
-
context.setResult(result).exit();
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
if (commonHead + commonTail === len2) {
|
|
1120
|
-
// trivial case, a block (1 or more consecutive items) was removed
|
|
1121
|
-
result = result || {
|
|
1122
|
-
_t: 'a'
|
|
1123
|
-
};
|
|
1124
|
-
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1125
|
-
result['_' + index] = [array1[index], 0, 0];
|
|
1126
|
-
}
|
|
1127
|
-
context.setResult(result).exit();
|
|
1128
|
-
return;
|
|
1129
|
-
}
|
|
1130
|
-
// reset hash cache
|
|
1131
|
-
delete matchContext.hashCache1;
|
|
1132
|
-
delete matchContext.hashCache2;
|
|
1133
|
-
|
|
1134
|
-
// diff is not trivial, find the LCS (Longest Common Subsequence)
|
|
1135
|
-
var trimmed1 = array1.slice(commonHead, len1 - commonTail);
|
|
1136
|
-
var trimmed2 = array2.slice(commonHead, len2 - commonTail);
|
|
1137
|
-
var seq = lcs.get(trimmed1, trimmed2, matchItems, matchContext);
|
|
1138
|
-
var removedItems = [];
|
|
1139
|
-
result = result || {
|
|
1140
|
-
_t: 'a'
|
|
1141
|
-
};
|
|
1142
|
-
for (index = commonHead; index < len1 - commonTail; index++) {
|
|
1143
|
-
if (arrayIndexOf(seq.indices1, index - commonHead) < 0) {
|
|
1144
|
-
// removed
|
|
1145
|
-
result['_' + index] = [array1[index], 0, 0];
|
|
1146
|
-
removedItems.push(index);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
var detectMove = true;
|
|
1150
|
-
if (context.options && context.options.arrays && context.options.arrays.detectMove === false) {
|
|
1151
|
-
detectMove = false;
|
|
1152
|
-
}
|
|
1153
|
-
var includeValueOnMove = false;
|
|
1154
|
-
if (context.options && context.options.arrays && context.options.arrays.includeValueOnMove) {
|
|
1155
|
-
includeValueOnMove = true;
|
|
1156
|
-
}
|
|
1157
|
-
var removedItemsLength = removedItems.length;
|
|
1158
|
-
for (index = commonHead; index < len2 - commonTail; index++) {
|
|
1159
|
-
var indexOnArray2 = arrayIndexOf(seq.indices2, index - commonHead);
|
|
1160
|
-
if (indexOnArray2 < 0) {
|
|
1161
|
-
// added, try to match with a removed item and register as position move
|
|
1162
|
-
var isMove = false;
|
|
1163
|
-
if (detectMove && removedItemsLength > 0) {
|
|
1164
|
-
for (var removeItemIndex1 = 0; removeItemIndex1 < removedItemsLength; removeItemIndex1++) {
|
|
1165
|
-
index1 = removedItems[removeItemIndex1];
|
|
1166
|
-
if (matchItems(trimmed1, trimmed2, index1 - commonHead, index - commonHead, matchContext)) {
|
|
1167
|
-
// store position move as: [originalValue, newPosition, ARRAY_MOVE]
|
|
1168
|
-
result['_' + index1].splice(1, 2, index, ARRAY_MOVE);
|
|
1169
|
-
if (!includeValueOnMove) {
|
|
1170
|
-
// don't include moved value on diff, to save bytes
|
|
1171
|
-
result['_' + index1][0] = '';
|
|
1172
|
-
}
|
|
1173
|
-
index2 = index;
|
|
1174
|
-
child = new DiffContext(context.left[index1], context.right[index2]);
|
|
1175
|
-
context.push(child, index2);
|
|
1176
|
-
removedItems.splice(removeItemIndex1, 1);
|
|
1177
|
-
isMove = true;
|
|
1178
|
-
break;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
if (!isMove) {
|
|
1183
|
-
// added
|
|
1184
|
-
result[index] = [array2[index]];
|
|
1185
|
-
}
|
|
1186
|
-
} else {
|
|
1187
|
-
// match, do inner diff
|
|
1188
|
-
index1 = seq.indices1[indexOnArray2] + commonHead;
|
|
1189
|
-
index2 = seq.indices2[indexOnArray2] + commonHead;
|
|
1190
|
-
child = new DiffContext(context.left[index1], context.right[index2]);
|
|
1191
|
-
context.push(child, index2);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
context.setResult(result).exit();
|
|
1195
|
-
};
|
|
1196
|
-
diffFilter$1.filterName = 'arrays';
|
|
1197
|
-
var compare = {
|
|
1198
|
-
numerically: function numerically(a, b) {
|
|
1199
|
-
return a - b;
|
|
1200
|
-
},
|
|
1201
|
-
numericallyBy: function numericallyBy(name) {
|
|
1202
|
-
return function (a, b) {
|
|
1203
|
-
return a[name] - b[name];
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
var patchFilter$2 = function nestedPatchFilter(context) {
|
|
1208
|
-
if (!context.nested) {
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
if (context.delta._t !== 'a') {
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
var index = void 0;
|
|
1215
|
-
var index1 = void 0;
|
|
1216
|
-
var delta = context.delta;
|
|
1217
|
-
var array = context.left;
|
|
1218
|
-
|
|
1219
|
-
// first, separate removals, insertions and modifications
|
|
1220
|
-
var toRemove = [];
|
|
1221
|
-
var toInsert = [];
|
|
1222
|
-
var toModify = [];
|
|
1223
|
-
for (index in delta) {
|
|
1224
|
-
if (index !== '_t') {
|
|
1225
|
-
if (index[0] === '_') {
|
|
1226
|
-
// removed item from original array
|
|
1227
|
-
if (delta[index][2] === 0 || delta[index][2] === ARRAY_MOVE) {
|
|
1228
|
-
toRemove.push(parseInt(index.slice(1), 10));
|
|
1229
|
-
} else {
|
|
1230
|
-
throw new Error('only removal or move can be applied at original array indices,' + (' invalid diff type: ' + delta[index][2]));
|
|
1231
|
-
}
|
|
1232
|
-
} else {
|
|
1233
|
-
if (delta[index].length === 1) {
|
|
1234
|
-
// added item at new array
|
|
1235
|
-
toInsert.push({
|
|
1236
|
-
index: parseInt(index, 10),
|
|
1237
|
-
value: delta[index][0]
|
|
1238
|
-
});
|
|
1239
|
-
} else {
|
|
1240
|
-
// modified item at new array
|
|
1241
|
-
toModify.push({
|
|
1242
|
-
index: parseInt(index, 10),
|
|
1243
|
-
delta: delta[index]
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
// remove items, in reverse order to avoid sawing our own floor
|
|
1251
|
-
toRemove = toRemove.sort(compare.numerically);
|
|
1252
|
-
for (index = toRemove.length - 1; index >= 0; index--) {
|
|
1253
|
-
index1 = toRemove[index];
|
|
1254
|
-
var indexDiff = delta['_' + index1];
|
|
1255
|
-
var removedValue = array.splice(index1, 1)[0];
|
|
1256
|
-
if (indexDiff[2] === ARRAY_MOVE) {
|
|
1257
|
-
// reinsert later
|
|
1258
|
-
toInsert.push({
|
|
1259
|
-
index: indexDiff[1],
|
|
1260
|
-
value: removedValue
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
// insert items, in reverse order to avoid moving our own floor
|
|
1266
|
-
toInsert = toInsert.sort(compare.numericallyBy('index'));
|
|
1267
|
-
var toInsertLength = toInsert.length;
|
|
1268
|
-
for (index = 0; index < toInsertLength; index++) {
|
|
1269
|
-
var insertion = toInsert[index];
|
|
1270
|
-
array.splice(insertion.index, 0, insertion.value);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
// apply modifications
|
|
1274
|
-
var toModifyLength = toModify.length;
|
|
1275
|
-
var child = void 0;
|
|
1276
|
-
if (toModifyLength > 0) {
|
|
1277
|
-
for (index = 0; index < toModifyLength; index++) {
|
|
1278
|
-
var modification = toModify[index];
|
|
1279
|
-
child = new PatchContext(context.left[modification.index], modification.delta);
|
|
1280
|
-
context.push(child, modification.index);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
if (!context.children) {
|
|
1284
|
-
context.setResult(context.left).exit();
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
context.exit();
|
|
1288
|
-
};
|
|
1289
|
-
patchFilter$2.filterName = 'arrays';
|
|
1290
|
-
var collectChildrenPatchFilter$1 = function collectChildrenPatchFilter(context) {
|
|
1291
|
-
if (!context || !context.children) {
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
if (context.delta._t !== 'a') {
|
|
1295
|
-
return;
|
|
1296
|
-
}
|
|
1297
|
-
var length = context.children.length;
|
|
1298
|
-
var child = void 0;
|
|
1299
|
-
for (var index = 0; index < length; index++) {
|
|
1300
|
-
child = context.children[index];
|
|
1301
|
-
context.left[child.childName] = child.result;
|
|
1302
|
-
}
|
|
1303
|
-
context.setResult(context.left).exit();
|
|
1304
|
-
};
|
|
1305
|
-
collectChildrenPatchFilter$1.filterName = 'arraysCollectChildren';
|
|
1306
|
-
var reverseFilter$2 = function arraysReverseFilter(context) {
|
|
1307
|
-
if (!context.nested) {
|
|
1308
|
-
if (context.delta[2] === ARRAY_MOVE) {
|
|
1309
|
-
context.newName = '_' + context.delta[1];
|
|
1310
|
-
context.setResult([context.delta[0], parseInt(context.childName.substr(1), 10), ARRAY_MOVE]).exit();
|
|
1311
|
-
}
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
if (context.delta._t !== 'a') {
|
|
1315
|
-
return;
|
|
1316
|
-
}
|
|
1317
|
-
var name = void 0;
|
|
1318
|
-
var child = void 0;
|
|
1319
|
-
for (name in context.delta) {
|
|
1320
|
-
if (name === '_t') {
|
|
1321
|
-
continue;
|
|
1322
|
-
}
|
|
1323
|
-
child = new ReverseContext(context.delta[name]);
|
|
1324
|
-
context.push(child, name);
|
|
1325
|
-
}
|
|
1326
|
-
context.exit();
|
|
1327
|
-
};
|
|
1328
|
-
reverseFilter$2.filterName = 'arrays';
|
|
1329
|
-
var reverseArrayDeltaIndex = function reverseArrayDeltaIndex(delta, index, itemDelta) {
|
|
1330
|
-
if (typeof index === 'string' && index[0] === '_') {
|
|
1331
|
-
return parseInt(index.substr(1), 10);
|
|
1332
|
-
} else if (isArray$2(itemDelta) && itemDelta[2] === 0) {
|
|
1333
|
-
return '_' + index;
|
|
1334
|
-
}
|
|
1335
|
-
var reverseIndex = +index;
|
|
1336
|
-
for (var deltaIndex in delta) {
|
|
1337
|
-
var deltaItem = delta[deltaIndex];
|
|
1338
|
-
if (isArray$2(deltaItem)) {
|
|
1339
|
-
if (deltaItem[2] === ARRAY_MOVE) {
|
|
1340
|
-
var moveFromIndex = parseInt(deltaIndex.substr(1), 10);
|
|
1341
|
-
var moveToIndex = deltaItem[1];
|
|
1342
|
-
if (moveToIndex === +index) {
|
|
1343
|
-
return moveFromIndex;
|
|
1344
|
-
}
|
|
1345
|
-
if (moveFromIndex <= reverseIndex && moveToIndex > reverseIndex) {
|
|
1346
|
-
reverseIndex++;
|
|
1347
|
-
} else if (moveFromIndex >= reverseIndex && moveToIndex < reverseIndex) {
|
|
1348
|
-
reverseIndex--;
|
|
1349
|
-
}
|
|
1350
|
-
} else if (deltaItem[2] === 0) {
|
|
1351
|
-
var deleteIndex = parseInt(deltaIndex.substr(1), 10);
|
|
1352
|
-
if (deleteIndex <= reverseIndex) {
|
|
1353
|
-
reverseIndex++;
|
|
1354
|
-
}
|
|
1355
|
-
} else if (deltaItem.length === 1 && deltaIndex <= reverseIndex) {
|
|
1356
|
-
reverseIndex--;
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
return reverseIndex;
|
|
1361
|
-
};
|
|
1362
|
-
function collectChildrenReverseFilter$1(context) {
|
|
1363
|
-
if (!context || !context.children) {
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
if (context.delta._t !== 'a') {
|
|
1367
|
-
return;
|
|
1368
|
-
}
|
|
1369
|
-
var length = context.children.length;
|
|
1370
|
-
var child = void 0;
|
|
1371
|
-
var delta = {
|
|
1372
|
-
_t: 'a'
|
|
1373
|
-
};
|
|
1374
|
-
for (var index = 0; index < length; index++) {
|
|
1375
|
-
child = context.children[index];
|
|
1376
|
-
var name = child.newName;
|
|
1377
|
-
if (typeof name === 'undefined') {
|
|
1378
|
-
name = reverseArrayDeltaIndex(context.delta, child.childName, child.result);
|
|
1379
|
-
}
|
|
1380
|
-
if (delta[name] !== child.result) {
|
|
1381
|
-
delta[name] = child.result;
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
context.setResult(delta).exit();
|
|
1385
|
-
}
|
|
1386
|
-
collectChildrenReverseFilter$1.filterName = 'arraysCollectChildren';
|
|
1387
|
-
var diffFilter$2 = function datesDiffFilter(context) {
|
|
1388
|
-
if (context.left instanceof Date) {
|
|
1389
|
-
if (context.right instanceof Date) {
|
|
1390
|
-
if (context.left.getTime() !== context.right.getTime()) {
|
|
1391
|
-
context.setResult([context.left, context.right]);
|
|
1392
|
-
} else {
|
|
1393
|
-
context.setResult(undefined);
|
|
1394
|
-
}
|
|
1395
|
-
} else {
|
|
1396
|
-
context.setResult([context.left, context.right]);
|
|
1397
|
-
}
|
|
1398
|
-
context.exit();
|
|
1399
|
-
} else if (context.right instanceof Date) {
|
|
1400
|
-
context.setResult([context.left, context.right]).exit();
|
|
1401
|
-
}
|
|
1402
|
-
};
|
|
1403
|
-
diffFilter$2.filterName = 'dates';
|
|
1404
|
-
|
|
1405
|
-
/* global diff_match_patch */
|
|
1406
|
-
var TEXT_DIFF = 2;
|
|
1407
|
-
var DEFAULT_MIN_LENGTH = 60;
|
|
1408
|
-
var cachedDiffPatch = null;
|
|
1409
|
-
var getDiffMatchPatch = function getDiffMatchPatch(required) {
|
|
1410
|
-
/* jshint camelcase: false */
|
|
1411
|
-
|
|
1412
|
-
if (!cachedDiffPatch) {
|
|
1413
|
-
var instance = void 0;
|
|
1414
|
-
/* eslint-disable camelcase, new-cap */
|
|
1415
|
-
if (typeof diff_match_patch !== 'undefined') {
|
|
1416
|
-
// already loaded, probably a browser
|
|
1417
|
-
instance = typeof diff_match_patch === 'function' ? new diff_match_patch() : new diff_match_patch.diff_match_patch();
|
|
1418
|
-
} else if (dmp) {
|
|
1419
|
-
try {
|
|
1420
|
-
instance = dmp && new dmp();
|
|
1421
|
-
} catch (err) {
|
|
1422
|
-
instance = null;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
/* eslint-enable camelcase, new-cap */
|
|
1426
|
-
if (!instance) {
|
|
1427
|
-
if (!required) {
|
|
1428
|
-
return null;
|
|
1429
|
-
}
|
|
1430
|
-
var error = new Error('text diff_match_patch library not found');
|
|
1431
|
-
// eslint-disable-next-line camelcase
|
|
1432
|
-
error.diff_match_patch_not_found = true;
|
|
1433
|
-
throw error;
|
|
1434
|
-
}
|
|
1435
|
-
cachedDiffPatch = {
|
|
1436
|
-
diff: function diff(txt1, txt2) {
|
|
1437
|
-
return instance.patch_toText(instance.patch_make(txt1, txt2));
|
|
1438
|
-
},
|
|
1439
|
-
patch: function patch(txt1, _patch) {
|
|
1440
|
-
var results = instance.patch_apply(instance.patch_fromText(_patch), txt1);
|
|
1441
|
-
for (var i = 0; i < results[1].length; i++) {
|
|
1442
|
-
if (!results[1][i]) {
|
|
1443
|
-
var _error = new Error('text patch failed');
|
|
1444
|
-
_error.textPatchFailed = true;
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
return results[0];
|
|
1448
|
-
}
|
|
1449
|
-
};
|
|
1450
|
-
}
|
|
1451
|
-
return cachedDiffPatch;
|
|
1452
|
-
};
|
|
1453
|
-
var diffFilter$3 = function textsDiffFilter(context) {
|
|
1454
|
-
if (context.leftType !== 'string') {
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
var minLength = context.options && context.options.textDiff && context.options.textDiff.minLength || DEFAULT_MIN_LENGTH;
|
|
1458
|
-
if (context.left.length < minLength || context.right.length < minLength) {
|
|
1459
|
-
context.setResult([context.left, context.right]).exit();
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
// large text, try to use a text-diff algorithm
|
|
1463
|
-
var diffMatchPatch = getDiffMatchPatch();
|
|
1464
|
-
if (!diffMatchPatch) {
|
|
1465
|
-
// diff-match-patch library not available,
|
|
1466
|
-
// fallback to regular string replace
|
|
1467
|
-
context.setResult([context.left, context.right]).exit();
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
var diff = diffMatchPatch.diff;
|
|
1471
|
-
context.setResult([diff(context.left, context.right), 0, TEXT_DIFF]).exit();
|
|
1472
|
-
};
|
|
1473
|
-
diffFilter$3.filterName = 'texts';
|
|
1474
|
-
var patchFilter$3 = function textsPatchFilter(context) {
|
|
1475
|
-
if (context.nested) {
|
|
1476
|
-
return;
|
|
1477
|
-
}
|
|
1478
|
-
if (context.delta[2] !== TEXT_DIFF) {
|
|
1479
|
-
return;
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
// text-diff, use a text-patch algorithm
|
|
1483
|
-
var patch = getDiffMatchPatch(true).patch;
|
|
1484
|
-
context.setResult(patch(context.left, context.delta[0])).exit();
|
|
1485
|
-
};
|
|
1486
|
-
patchFilter$3.filterName = 'texts';
|
|
1487
|
-
var textDeltaReverse = function textDeltaReverse(delta) {
|
|
1488
|
-
var i = void 0;
|
|
1489
|
-
var l = void 0;
|
|
1490
|
-
var lines = void 0;
|
|
1491
|
-
var line = void 0;
|
|
1492
|
-
var lineTmp = void 0;
|
|
1493
|
-
var header = null;
|
|
1494
|
-
var headerRegex = /^@@ +-(\d+),(\d+) +\+(\d+),(\d+) +@@$/;
|
|
1495
|
-
var lineHeader = void 0;
|
|
1496
|
-
lines = delta.split('\n');
|
|
1497
|
-
for (i = 0, l = lines.length; i < l; i++) {
|
|
1498
|
-
line = lines[i];
|
|
1499
|
-
var lineStart = line.slice(0, 1);
|
|
1500
|
-
if (lineStart === '@') {
|
|
1501
|
-
header = headerRegex.exec(line);
|
|
1502
|
-
lineHeader = i;
|
|
1503
|
-
|
|
1504
|
-
// fix header
|
|
1505
|
-
lines[lineHeader] = '@@ -' + header[3] + ',' + header[4] + ' +' + header[1] + ',' + header[2] + ' @@';
|
|
1506
|
-
} else if (lineStart === '+') {
|
|
1507
|
-
lines[i] = '-' + lines[i].slice(1);
|
|
1508
|
-
if (lines[i - 1].slice(0, 1) === '+') {
|
|
1509
|
-
// swap lines to keep default order (-+)
|
|
1510
|
-
lineTmp = lines[i];
|
|
1511
|
-
lines[i] = lines[i - 1];
|
|
1512
|
-
lines[i - 1] = lineTmp;
|
|
1513
|
-
}
|
|
1514
|
-
} else if (lineStart === '-') {
|
|
1515
|
-
lines[i] = '+' + lines[i].slice(1);
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
return lines.join('\n');
|
|
1519
|
-
};
|
|
1520
|
-
var reverseFilter$3 = function textsReverseFilter(context) {
|
|
1521
|
-
if (context.nested) {
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
if (context.delta[2] !== TEXT_DIFF) {
|
|
1525
|
-
return;
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
// text-diff, use a text-diff algorithm
|
|
1529
|
-
context.setResult([textDeltaReverse(context.delta[0]), 0, TEXT_DIFF]).exit();
|
|
1530
|
-
};
|
|
1531
|
-
reverseFilter$3.filterName = 'texts';
|
|
1532
|
-
var DiffPatcher = function () {
|
|
1533
|
-
function DiffPatcher(options) {
|
|
1534
|
-
classCallCheck(this, DiffPatcher);
|
|
1535
|
-
this.processor = new Processor(options);
|
|
1536
|
-
this.processor.pipe(new Pipe('diff').append(collectChildrenDiffFilter, diffFilter, diffFilter$2, diffFilter$3, objectsDiffFilter, diffFilter$1).shouldHaveResult());
|
|
1537
|
-
this.processor.pipe(new Pipe('patch').append(collectChildrenPatchFilter, collectChildrenPatchFilter$1, patchFilter, patchFilter$3, patchFilter$1, patchFilter$2).shouldHaveResult());
|
|
1538
|
-
this.processor.pipe(new Pipe('reverse').append(collectChildrenReverseFilter, collectChildrenReverseFilter$1, reverseFilter, reverseFilter$3, reverseFilter$1, reverseFilter$2).shouldHaveResult());
|
|
1539
|
-
}
|
|
1540
|
-
createClass(DiffPatcher, [{
|
|
1541
|
-
key: 'options',
|
|
1542
|
-
value: function options() {
|
|
1543
|
-
var _processor;
|
|
1544
|
-
return (_processor = this.processor).options.apply(_processor, arguments);
|
|
1545
|
-
}
|
|
1546
|
-
}, {
|
|
1547
|
-
key: 'diff',
|
|
1548
|
-
value: function diff(left, right) {
|
|
1549
|
-
return this.processor.process(new DiffContext(left, right));
|
|
1550
|
-
}
|
|
1551
|
-
}, {
|
|
1552
|
-
key: 'patch',
|
|
1553
|
-
value: function patch(left, delta) {
|
|
1554
|
-
return this.processor.process(new PatchContext(left, delta));
|
|
1555
|
-
}
|
|
1556
|
-
}, {
|
|
1557
|
-
key: 'reverse',
|
|
1558
|
-
value: function reverse(delta) {
|
|
1559
|
-
return this.processor.process(new ReverseContext(delta));
|
|
1560
|
-
}
|
|
1561
|
-
}, {
|
|
1562
|
-
key: 'unpatch',
|
|
1563
|
-
value: function unpatch(right, delta) {
|
|
1564
|
-
return this.patch(right, this.reverse(delta));
|
|
1565
|
-
}
|
|
1566
|
-
}, {
|
|
1567
|
-
key: 'clone',
|
|
1568
|
-
value: function clone$$1(value) {
|
|
1569
|
-
return clone$1(value);
|
|
1570
|
-
}
|
|
1571
|
-
}]);
|
|
1572
|
-
return DiffPatcher;
|
|
1573
|
-
}();
|
|
1574
|
-
var isArray$3 = typeof Array.isArray === 'function' ? Array.isArray : function (a) {
|
|
1575
|
-
return a instanceof Array;
|
|
1576
|
-
};
|
|
1577
|
-
var getObjectKeys = typeof Object.keys === 'function' ? function (obj) {
|
|
1578
|
-
return Object.keys(obj);
|
|
1579
|
-
} : function (obj) {
|
|
1580
|
-
var names = [];
|
|
1581
|
-
for (var property in obj) {
|
|
1582
|
-
if (Object.prototype.hasOwnProperty.call(obj, property)) {
|
|
1583
|
-
names.push(property);
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
return names;
|
|
1587
|
-
};
|
|
1588
|
-
var trimUnderscore = function trimUnderscore(str) {
|
|
1589
|
-
if (str.substr(0, 1) === '_') {
|
|
1590
|
-
return str.slice(1);
|
|
1591
|
-
}
|
|
1592
|
-
return str;
|
|
1593
|
-
};
|
|
1594
|
-
var arrayKeyToSortNumber = function arrayKeyToSortNumber(key) {
|
|
1595
|
-
if (key === '_t') {
|
|
1596
|
-
return -1;
|
|
1597
|
-
} else {
|
|
1598
|
-
if (key.substr(0, 1) === '_') {
|
|
1599
|
-
return parseInt(key.slice(1), 10);
|
|
1600
|
-
} else {
|
|
1601
|
-
return parseInt(key, 10) + 0.1;
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
};
|
|
1605
|
-
var arrayKeyComparer = function arrayKeyComparer(key1, key2) {
|
|
1606
|
-
return arrayKeyToSortNumber(key1) - arrayKeyToSortNumber(key2);
|
|
1607
|
-
};
|
|
1608
|
-
var BaseFormatter = function () {
|
|
1609
|
-
function BaseFormatter() {
|
|
1610
|
-
classCallCheck(this, BaseFormatter);
|
|
1611
|
-
}
|
|
1612
|
-
createClass(BaseFormatter, [{
|
|
1613
|
-
key: 'format',
|
|
1614
|
-
value: function format(delta, left) {
|
|
1615
|
-
var context = {};
|
|
1616
|
-
this.prepareContext(context);
|
|
1617
|
-
this.recurse(context, delta, left);
|
|
1618
|
-
return this.finalize(context);
|
|
1619
|
-
}
|
|
1620
|
-
}, {
|
|
1621
|
-
key: 'prepareContext',
|
|
1622
|
-
value: function prepareContext(context) {
|
|
1623
|
-
context.buffer = [];
|
|
1624
|
-
context.out = function () {
|
|
1625
|
-
var _buffer;
|
|
1626
|
-
(_buffer = this.buffer).push.apply(_buffer, arguments);
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
}, {
|
|
1630
|
-
key: 'typeFormattterNotFound',
|
|
1631
|
-
value: function typeFormattterNotFound(context, deltaType) {
|
|
1632
|
-
throw new Error('cannot format delta type: ' + deltaType);
|
|
1633
|
-
}
|
|
1634
|
-
}, {
|
|
1635
|
-
key: 'typeFormattterErrorFormatter',
|
|
1636
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
1637
|
-
return err.toString();
|
|
1638
|
-
}
|
|
1639
|
-
}, {
|
|
1640
|
-
key: 'finalize',
|
|
1641
|
-
value: function finalize(_ref) {
|
|
1642
|
-
var buffer = _ref.buffer;
|
|
1643
|
-
if (isArray$3(buffer)) {
|
|
1644
|
-
return buffer.join('');
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
}, {
|
|
1648
|
-
key: 'recurse',
|
|
1649
|
-
value: function recurse(context, delta, left, key, leftKey, movedFrom, isLast) {
|
|
1650
|
-
var useMoveOriginHere = delta && movedFrom;
|
|
1651
|
-
var leftValue = useMoveOriginHere ? movedFrom.value : left;
|
|
1652
|
-
if (typeof delta === 'undefined' && typeof key === 'undefined') {
|
|
1653
|
-
return undefined;
|
|
1654
|
-
}
|
|
1655
|
-
var type = this.getDeltaType(delta, movedFrom);
|
|
1656
|
-
var nodeType = type === 'node' ? delta._t === 'a' ? 'array' : 'object' : '';
|
|
1657
|
-
if (typeof key !== 'undefined') {
|
|
1658
|
-
this.nodeBegin(context, key, leftKey, type, nodeType, isLast);
|
|
1659
|
-
} else {
|
|
1660
|
-
this.rootBegin(context, type, nodeType);
|
|
1661
|
-
}
|
|
1662
|
-
var typeFormattter = void 0;
|
|
1663
|
-
try {
|
|
1664
|
-
typeFormattter = this['format_' + type] || this.typeFormattterNotFound(context, type);
|
|
1665
|
-
typeFormattter.call(this, context, delta, leftValue, key, leftKey, movedFrom);
|
|
1666
|
-
} catch (err) {
|
|
1667
|
-
this.typeFormattterErrorFormatter(context, err, delta, leftValue, key, leftKey, movedFrom);
|
|
1668
|
-
if (typeof console !== 'undefined' && console.error) {
|
|
1669
|
-
console.error(err.stack);
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
if (typeof key !== 'undefined') {
|
|
1673
|
-
this.nodeEnd(context, key, leftKey, type, nodeType, isLast);
|
|
1674
|
-
} else {
|
|
1675
|
-
this.rootEnd(context, type, nodeType);
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
}, {
|
|
1679
|
-
key: 'formatDeltaChildren',
|
|
1680
|
-
value: function formatDeltaChildren(context, delta, left) {
|
|
1681
|
-
var self = this;
|
|
1682
|
-
this.forEachDeltaKey(delta, left, function (key, leftKey, movedFrom, isLast) {
|
|
1683
|
-
self.recurse(context, delta[key], left ? left[leftKey] : undefined, key, leftKey, movedFrom, isLast);
|
|
1684
|
-
});
|
|
1685
|
-
}
|
|
1686
|
-
}, {
|
|
1687
|
-
key: 'forEachDeltaKey',
|
|
1688
|
-
value: function forEachDeltaKey(delta, left, fn) {
|
|
1689
|
-
var keys = getObjectKeys(delta);
|
|
1690
|
-
var arrayKeys = delta._t === 'a';
|
|
1691
|
-
var moveDestinations = {};
|
|
1692
|
-
var name = void 0;
|
|
1693
|
-
if (typeof left !== 'undefined') {
|
|
1694
|
-
for (name in left) {
|
|
1695
|
-
if (Object.prototype.hasOwnProperty.call(left, name)) {
|
|
1696
|
-
if (typeof delta[name] === 'undefined' && (!arrayKeys || typeof delta['_' + name] === 'undefined')) {
|
|
1697
|
-
keys.push(name);
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
// look for move destinations
|
|
1703
|
-
for (name in delta) {
|
|
1704
|
-
if (Object.prototype.hasOwnProperty.call(delta, name)) {
|
|
1705
|
-
var value = delta[name];
|
|
1706
|
-
if (isArray$3(value) && value[2] === 3) {
|
|
1707
|
-
moveDestinations[value[1].toString()] = {
|
|
1708
|
-
key: name,
|
|
1709
|
-
value: left && left[parseInt(name.substr(1))]
|
|
1710
|
-
};
|
|
1711
|
-
if (this.includeMoveDestinations !== false) {
|
|
1712
|
-
if (typeof left === 'undefined' && typeof delta[value[1]] === 'undefined') {
|
|
1713
|
-
keys.push(value[1].toString());
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
if (arrayKeys) {
|
|
1720
|
-
keys.sort(arrayKeyComparer);
|
|
1721
|
-
} else {
|
|
1722
|
-
keys.sort();
|
|
1723
|
-
}
|
|
1724
|
-
for (var index = 0, length = keys.length; index < length; index++) {
|
|
1725
|
-
var key = keys[index];
|
|
1726
|
-
if (arrayKeys && key === '_t') {
|
|
1727
|
-
continue;
|
|
1728
|
-
}
|
|
1729
|
-
var leftKey = arrayKeys ? typeof key === 'number' ? key : parseInt(trimUnderscore(key), 10) : key;
|
|
1730
|
-
var isLast = index === length - 1;
|
|
1731
|
-
fn(key, leftKey, moveDestinations[leftKey], isLast);
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
}, {
|
|
1735
|
-
key: 'getDeltaType',
|
|
1736
|
-
value: function getDeltaType(delta, movedFrom) {
|
|
1737
|
-
if (typeof delta === 'undefined') {
|
|
1738
|
-
if (typeof movedFrom !== 'undefined') {
|
|
1739
|
-
return 'movedestination';
|
|
1740
|
-
}
|
|
1741
|
-
return 'unchanged';
|
|
1742
|
-
}
|
|
1743
|
-
if (isArray$3(delta)) {
|
|
1744
|
-
if (delta.length === 1) {
|
|
1745
|
-
return 'added';
|
|
1746
|
-
}
|
|
1747
|
-
if (delta.length === 2) {
|
|
1748
|
-
return 'modified';
|
|
1749
|
-
}
|
|
1750
|
-
if (delta.length === 3 && delta[2] === 0) {
|
|
1751
|
-
return 'deleted';
|
|
1752
|
-
}
|
|
1753
|
-
if (delta.length === 3 && delta[2] === 2) {
|
|
1754
|
-
return 'textdiff';
|
|
1755
|
-
}
|
|
1756
|
-
if (delta.length === 3 && delta[2] === 3) {
|
|
1757
|
-
return 'moved';
|
|
1758
|
-
}
|
|
1759
|
-
} else if ((typeof delta === 'undefined' ? 'undefined' : _typeof(delta)) === 'object') {
|
|
1760
|
-
return 'node';
|
|
1761
|
-
}
|
|
1762
|
-
return 'unknown';
|
|
1763
|
-
}
|
|
1764
|
-
}, {
|
|
1765
|
-
key: 'parseTextDiff',
|
|
1766
|
-
value: function parseTextDiff(value) {
|
|
1767
|
-
var output = [];
|
|
1768
|
-
var lines = value.split('\n@@ ');
|
|
1769
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
1770
|
-
var line = lines[i];
|
|
1771
|
-
var lineOutput = {
|
|
1772
|
-
pieces: []
|
|
1773
|
-
};
|
|
1774
|
-
var location = /^(?:@@ )?[-+]?(\d+),(\d+)/.exec(line).slice(1);
|
|
1775
|
-
lineOutput.location = {
|
|
1776
|
-
line: location[0],
|
|
1777
|
-
chr: location[1]
|
|
1778
|
-
};
|
|
1779
|
-
var pieces = line.split('\n').slice(1);
|
|
1780
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
1781
|
-
var piece = pieces[pieceIndex];
|
|
1782
|
-
if (!piece.length) {
|
|
1783
|
-
continue;
|
|
1784
|
-
}
|
|
1785
|
-
var pieceOutput = {
|
|
1786
|
-
type: 'context'
|
|
1787
|
-
};
|
|
1788
|
-
if (piece.substr(0, 1) === '+') {
|
|
1789
|
-
pieceOutput.type = 'added';
|
|
1790
|
-
} else if (piece.substr(0, 1) === '-') {
|
|
1791
|
-
pieceOutput.type = 'deleted';
|
|
1792
|
-
}
|
|
1793
|
-
pieceOutput.text = piece.slice(1);
|
|
1794
|
-
lineOutput.pieces.push(pieceOutput);
|
|
1795
|
-
}
|
|
1796
|
-
output.push(lineOutput);
|
|
1797
|
-
}
|
|
1798
|
-
return output;
|
|
1799
|
-
}
|
|
1800
|
-
}]);
|
|
1801
|
-
return BaseFormatter;
|
|
1802
|
-
}();
|
|
1803
|
-
var base = Object.freeze({
|
|
1804
|
-
default: BaseFormatter
|
|
1805
|
-
});
|
|
1806
|
-
var HtmlFormatter = function (_BaseFormatter) {
|
|
1807
|
-
inherits(HtmlFormatter, _BaseFormatter);
|
|
1808
|
-
function HtmlFormatter() {
|
|
1809
|
-
classCallCheck(this, HtmlFormatter);
|
|
1810
|
-
return possibleConstructorReturn(this, (HtmlFormatter.__proto__ || Object.getPrototypeOf(HtmlFormatter)).apply(this, arguments));
|
|
1811
|
-
}
|
|
1812
|
-
createClass(HtmlFormatter, [{
|
|
1813
|
-
key: 'typeFormattterErrorFormatter',
|
|
1814
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
1815
|
-
context.out('<pre class="jsondiffpatch-error">' + err + '</pre>');
|
|
1816
|
-
}
|
|
1817
|
-
}, {
|
|
1818
|
-
key: 'formatValue',
|
|
1819
|
-
value: function formatValue(context, value) {
|
|
1820
|
-
context.out('<pre>' + htmlEscape(JSON.stringify(value, null, 2)) + '</pre>');
|
|
1821
|
-
}
|
|
1822
|
-
}, {
|
|
1823
|
-
key: 'formatTextDiffString',
|
|
1824
|
-
value: function formatTextDiffString(context, value) {
|
|
1825
|
-
var lines = this.parseTextDiff(value);
|
|
1826
|
-
context.out('<ul class="jsondiffpatch-textdiff">');
|
|
1827
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
1828
|
-
var line = lines[i];
|
|
1829
|
-
context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
|
|
1830
|
-
var pieces = line.pieces;
|
|
1831
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
1832
|
-
/* global decodeURI */
|
|
1833
|
-
var piece = pieces[pieceIndex];
|
|
1834
|
-
context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + htmlEscape(decodeURI(piece.text)) + '</span>');
|
|
1835
|
-
}
|
|
1836
|
-
context.out('</div></li>');
|
|
1837
|
-
}
|
|
1838
|
-
context.out('</ul>');
|
|
1839
|
-
}
|
|
1840
|
-
}, {
|
|
1841
|
-
key: 'rootBegin',
|
|
1842
|
-
value: function rootBegin(context, type, nodeType) {
|
|
1843
|
-
var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
|
|
1844
|
-
context.out('<div class="jsondiffpatch-delta ' + nodeClass + '">');
|
|
1845
|
-
}
|
|
1846
|
-
}, {
|
|
1847
|
-
key: 'rootEnd',
|
|
1848
|
-
value: function rootEnd(context) {
|
|
1849
|
-
context.out('</div>' + (context.hasArrows ? '<script type="text/javascript">setTimeout(' + (adjustArrows.toString() + ',10);</script>') : ''));
|
|
1850
|
-
}
|
|
1851
|
-
}, {
|
|
1852
|
-
key: 'nodeBegin',
|
|
1853
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
1854
|
-
var nodeClass = 'jsondiffpatch-' + type + (nodeType ? ' jsondiffpatch-child-node-type-' + nodeType : '');
|
|
1855
|
-
context.out('<li class="' + nodeClass + '" data-key="' + leftKey + '">' + ('<div class="jsondiffpatch-property-name">' + leftKey + '</div>'));
|
|
1856
|
-
}
|
|
1857
|
-
}, {
|
|
1858
|
-
key: 'nodeEnd',
|
|
1859
|
-
value: function nodeEnd(context) {
|
|
1860
|
-
context.out('</li>');
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
/* jshint camelcase: false */
|
|
1864
|
-
/* eslint-disable camelcase */
|
|
1865
|
-
}, {
|
|
1866
|
-
key: 'format_unchanged',
|
|
1867
|
-
value: function format_unchanged(context, delta, left) {
|
|
1868
|
-
if (typeof left === 'undefined') {
|
|
1869
|
-
return;
|
|
1870
|
-
}
|
|
1871
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1872
|
-
this.formatValue(context, left);
|
|
1873
|
-
context.out('</div>');
|
|
1874
|
-
}
|
|
1875
|
-
}, {
|
|
1876
|
-
key: 'format_movedestination',
|
|
1877
|
-
value: function format_movedestination(context, delta, left) {
|
|
1878
|
-
if (typeof left === 'undefined') {
|
|
1879
|
-
return;
|
|
1880
|
-
}
|
|
1881
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1882
|
-
this.formatValue(context, left);
|
|
1883
|
-
context.out('</div>');
|
|
1884
|
-
}
|
|
1885
|
-
}, {
|
|
1886
|
-
key: 'format_node',
|
|
1887
|
-
value: function format_node(context, delta, left) {
|
|
1888
|
-
// recurse
|
|
1889
|
-
var nodeType = delta._t === 'a' ? 'array' : 'object';
|
|
1890
|
-
context.out('<ul class="jsondiffpatch-node jsondiffpatch-node-type-' + nodeType + '">');
|
|
1891
|
-
this.formatDeltaChildren(context, delta, left);
|
|
1892
|
-
context.out('</ul>');
|
|
1893
|
-
}
|
|
1894
|
-
}, {
|
|
1895
|
-
key: 'format_added',
|
|
1896
|
-
value: function format_added(context, delta) {
|
|
1897
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1898
|
-
this.formatValue(context, delta[0]);
|
|
1899
|
-
context.out('</div>');
|
|
1900
|
-
}
|
|
1901
|
-
}, {
|
|
1902
|
-
key: 'format_modified',
|
|
1903
|
-
value: function format_modified(context, delta) {
|
|
1904
|
-
context.out('<div class="jsondiffpatch-value jsondiffpatch-left-value">');
|
|
1905
|
-
this.formatValue(context, delta[0]);
|
|
1906
|
-
context.out('</div>' + '<div class="jsondiffpatch-value jsondiffpatch-right-value">');
|
|
1907
|
-
this.formatValue(context, delta[1]);
|
|
1908
|
-
context.out('</div>');
|
|
1909
|
-
}
|
|
1910
|
-
}, {
|
|
1911
|
-
key: 'format_deleted',
|
|
1912
|
-
value: function format_deleted(context, delta) {
|
|
1913
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1914
|
-
this.formatValue(context, delta[0]);
|
|
1915
|
-
context.out('</div>');
|
|
1916
|
-
}
|
|
1917
|
-
}, {
|
|
1918
|
-
key: 'format_moved',
|
|
1919
|
-
value: function format_moved(context, delta) {
|
|
1920
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1921
|
-
this.formatValue(context, delta[0]);
|
|
1922
|
-
context.out('</div><div class="jsondiffpatch-moved-destination">' + delta[1] + '</div>');
|
|
1923
|
-
|
|
1924
|
-
// draw an SVG arrow from here to move destination
|
|
1925
|
-
context.out( /* jshint multistr: true */
|
|
1926
|
-
'<div class="jsondiffpatch-arrow" ' + 'style="position: relative; left: -34px;">\n <svg width="30" height="60" ' + 'style="position: absolute; display: none;">\n <defs>\n <marker id="markerArrow" markerWidth="8" markerHeight="8"\n refx="2" refy="4"\n orient="auto" markerUnits="userSpaceOnUse">\n <path d="M1,1 L1,7 L7,4 L1,1" style="fill: #339;" />\n </marker>\n </defs>\n <path d="M30,0 Q-10,25 26,50"\n style="stroke: #88f; stroke-width: 2px; fill: none; ' + 'stroke-opacity: 0.5; marker-end: url(#markerArrow);"\n ></path>\n </svg>\n </div>');
|
|
1927
|
-
context.hasArrows = true;
|
|
1928
|
-
}
|
|
1929
|
-
}, {
|
|
1930
|
-
key: 'format_textdiff',
|
|
1931
|
-
value: function format_textdiff(context, delta) {
|
|
1932
|
-
context.out('<div class="jsondiffpatch-value">');
|
|
1933
|
-
this.formatTextDiffString(context, delta[0]);
|
|
1934
|
-
context.out('</div>');
|
|
1935
|
-
}
|
|
1936
|
-
}]);
|
|
1937
|
-
return HtmlFormatter;
|
|
1938
|
-
}(BaseFormatter);
|
|
1939
|
-
function htmlEscape(text) {
|
|
1940
|
-
var html = text;
|
|
1941
|
-
var replacements = [[/&/g, '&'], [/</g, '<'], [/>/g, '>'], [/'/g, '''], [/"/g, '"']];
|
|
1942
|
-
for (var i = 0; i < replacements.length; i++) {
|
|
1943
|
-
html = html.replace(replacements[i][0], replacements[i][1]);
|
|
1944
|
-
}
|
|
1945
|
-
return html;
|
|
1946
|
-
}
|
|
1947
|
-
var adjustArrows = function jsondiffpatchHtmlFormatterAdjustArrows(nodeArg) {
|
|
1948
|
-
var node = nodeArg || document;
|
|
1949
|
-
var getElementText = function getElementText(_ref) {
|
|
1950
|
-
var textContent = _ref.textContent,
|
|
1951
|
-
innerText = _ref.innerText;
|
|
1952
|
-
return textContent || innerText;
|
|
1953
|
-
};
|
|
1954
|
-
var eachByQuery = function eachByQuery(el, query, fn) {
|
|
1955
|
-
var elems = el.querySelectorAll(query);
|
|
1956
|
-
for (var i = 0, l = elems.length; i < l; i++) {
|
|
1957
|
-
fn(elems[i]);
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
var eachChildren = function eachChildren(_ref2, fn) {
|
|
1961
|
-
var children = _ref2.children;
|
|
1962
|
-
for (var i = 0, l = children.length; i < l; i++) {
|
|
1963
|
-
fn(children[i], i);
|
|
1964
|
-
}
|
|
1965
|
-
};
|
|
1966
|
-
eachByQuery(node, '.jsondiffpatch-arrow', function (_ref3) {
|
|
1967
|
-
var parentNode = _ref3.parentNode,
|
|
1968
|
-
children = _ref3.children,
|
|
1969
|
-
style = _ref3.style;
|
|
1970
|
-
var arrowParent = parentNode;
|
|
1971
|
-
var svg = children[0];
|
|
1972
|
-
var path = svg.children[1];
|
|
1973
|
-
svg.style.display = 'none';
|
|
1974
|
-
var destination = getElementText(arrowParent.querySelector('.jsondiffpatch-moved-destination'));
|
|
1975
|
-
var container = arrowParent.parentNode;
|
|
1976
|
-
var destinationElem = void 0;
|
|
1977
|
-
eachChildren(container, function (child) {
|
|
1978
|
-
if (child.getAttribute('data-key') === destination) {
|
|
1979
|
-
destinationElem = child;
|
|
1980
|
-
}
|
|
1981
|
-
});
|
|
1982
|
-
if (!destinationElem) {
|
|
1983
|
-
return;
|
|
1984
|
-
}
|
|
1985
|
-
try {
|
|
1986
|
-
var distance = destinationElem.offsetTop - arrowParent.offsetTop;
|
|
1987
|
-
svg.setAttribute('height', Math.abs(distance) + 6);
|
|
1988
|
-
style.top = -8 + (distance > 0 ? 0 : distance) + 'px';
|
|
1989
|
-
var curve = distance > 0 ? 'M30,0 Q-10,' + Math.round(distance / 2) + ' 26,' + (distance - 4) : 'M30,' + -distance + ' Q-10,' + Math.round(-distance / 2) + ' 26,4';
|
|
1990
|
-
path.setAttribute('d', curve);
|
|
1991
|
-
svg.style.display = '';
|
|
1992
|
-
} catch (err) {}
|
|
1993
|
-
});
|
|
1994
|
-
};
|
|
1995
|
-
|
|
1996
|
-
/* jshint camelcase: true */
|
|
1997
|
-
/* eslint-enable camelcase */
|
|
1998
|
-
|
|
1999
|
-
var showUnchanged = function showUnchanged(show, node, delay) {
|
|
2000
|
-
var el = node || document.body;
|
|
2001
|
-
var prefix = 'jsondiffpatch-unchanged-';
|
|
2002
|
-
var classes = {
|
|
2003
|
-
showing: prefix + 'showing',
|
|
2004
|
-
hiding: prefix + 'hiding',
|
|
2005
|
-
visible: prefix + 'visible',
|
|
2006
|
-
hidden: prefix + 'hidden'
|
|
2007
|
-
};
|
|
2008
|
-
var list = el.classList;
|
|
2009
|
-
if (!list) {
|
|
2010
|
-
return;
|
|
2011
|
-
}
|
|
2012
|
-
if (!delay) {
|
|
2013
|
-
list.remove(classes.showing);
|
|
2014
|
-
list.remove(classes.hiding);
|
|
2015
|
-
list.remove(classes.visible);
|
|
2016
|
-
list.remove(classes.hidden);
|
|
2017
|
-
if (show === false) {
|
|
2018
|
-
list.add(classes.hidden);
|
|
2019
|
-
}
|
|
2020
|
-
return;
|
|
2021
|
-
}
|
|
2022
|
-
if (show === false) {
|
|
2023
|
-
list.remove(classes.showing);
|
|
2024
|
-
list.add(classes.visible);
|
|
2025
|
-
setTimeout(function () {
|
|
2026
|
-
list.add(classes.hiding);
|
|
2027
|
-
}, 10);
|
|
2028
|
-
} else {
|
|
2029
|
-
list.remove(classes.hiding);
|
|
2030
|
-
list.add(classes.showing);
|
|
2031
|
-
list.remove(classes.hidden);
|
|
2032
|
-
}
|
|
2033
|
-
var intervalId = setInterval(function () {
|
|
2034
|
-
adjustArrows(el);
|
|
2035
|
-
}, 100);
|
|
2036
|
-
setTimeout(function () {
|
|
2037
|
-
list.remove(classes.showing);
|
|
2038
|
-
list.remove(classes.hiding);
|
|
2039
|
-
if (show === false) {
|
|
2040
|
-
list.add(classes.hidden);
|
|
2041
|
-
list.remove(classes.visible);
|
|
2042
|
-
} else {
|
|
2043
|
-
list.add(classes.visible);
|
|
2044
|
-
list.remove(classes.hidden);
|
|
2045
|
-
}
|
|
2046
|
-
setTimeout(function () {
|
|
2047
|
-
list.remove(classes.visible);
|
|
2048
|
-
clearInterval(intervalId);
|
|
2049
|
-
}, delay + 400);
|
|
2050
|
-
}, delay);
|
|
2051
|
-
};
|
|
2052
|
-
var hideUnchanged = function hideUnchanged(node, delay) {
|
|
2053
|
-
return showUnchanged(false, node, delay);
|
|
2054
|
-
};
|
|
2055
|
-
var defaultInstance = void 0;
|
|
2056
|
-
function format(delta, left) {
|
|
2057
|
-
if (!defaultInstance) {
|
|
2058
|
-
defaultInstance = new HtmlFormatter();
|
|
2059
|
-
}
|
|
2060
|
-
return defaultInstance.format(delta, left);
|
|
2061
|
-
}
|
|
2062
|
-
var html = Object.freeze({
|
|
2063
|
-
showUnchanged: showUnchanged,
|
|
2064
|
-
hideUnchanged: hideUnchanged,
|
|
2065
|
-
default: HtmlFormatter,
|
|
2066
|
-
format: format
|
|
2067
|
-
});
|
|
2068
|
-
var AnnotatedFormatter = function (_BaseFormatter) {
|
|
2069
|
-
inherits(AnnotatedFormatter, _BaseFormatter);
|
|
2070
|
-
function AnnotatedFormatter() {
|
|
2071
|
-
classCallCheck(this, AnnotatedFormatter);
|
|
2072
|
-
var _this = possibleConstructorReturn(this, (AnnotatedFormatter.__proto__ || Object.getPrototypeOf(AnnotatedFormatter)).call(this));
|
|
2073
|
-
_this.includeMoveDestinations = false;
|
|
2074
|
-
return _this;
|
|
2075
|
-
}
|
|
2076
|
-
createClass(AnnotatedFormatter, [{
|
|
2077
|
-
key: 'prepareContext',
|
|
2078
|
-
value: function prepareContext(context) {
|
|
2079
|
-
get(AnnotatedFormatter.prototype.__proto__ || Object.getPrototypeOf(AnnotatedFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2080
|
-
context.indent = function (levels) {
|
|
2081
|
-
this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
|
|
2082
|
-
this.indentPad = new Array(this.indentLevel + 1).join(' ');
|
|
2083
|
-
};
|
|
2084
|
-
context.row = function (json, htmlNote) {
|
|
2085
|
-
context.out('<tr><td style="white-space: nowrap;">' + '<pre class="jsondiffpatch-annotated-indent"' + ' style="display: inline-block">');
|
|
2086
|
-
context.out(context.indentPad);
|
|
2087
|
-
context.out('</pre><pre style="display: inline-block">');
|
|
2088
|
-
context.out(json);
|
|
2089
|
-
context.out('</pre></td><td class="jsondiffpatch-delta-note"><div>');
|
|
2090
|
-
context.out(htmlNote);
|
|
2091
|
-
context.out('</div></td></tr>');
|
|
2092
|
-
};
|
|
2093
|
-
}
|
|
2094
|
-
}, {
|
|
2095
|
-
key: 'typeFormattterErrorFormatter',
|
|
2096
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2097
|
-
context.row('', '<pre class="jsondiffpatch-error">' + err + '</pre>');
|
|
2098
|
-
}
|
|
2099
|
-
}, {
|
|
2100
|
-
key: 'formatTextDiffString',
|
|
2101
|
-
value: function formatTextDiffString(context, value) {
|
|
2102
|
-
var lines = this.parseTextDiff(value);
|
|
2103
|
-
context.out('<ul class="jsondiffpatch-textdiff">');
|
|
2104
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
2105
|
-
var line = lines[i];
|
|
2106
|
-
context.out('<li><div class="jsondiffpatch-textdiff-location">' + ('<span class="jsondiffpatch-textdiff-line-number">' + line.location.line + '</span><span class="jsondiffpatch-textdiff-char">' + line.location.chr + '</span></div><div class="jsondiffpatch-textdiff-line">'));
|
|
2107
|
-
var pieces = line.pieces;
|
|
2108
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
2109
|
-
var piece = pieces[pieceIndex];
|
|
2110
|
-
context.out('<span class="jsondiffpatch-textdiff-' + piece.type + '">' + piece.text + '</span>');
|
|
2111
|
-
}
|
|
2112
|
-
context.out('</div></li>');
|
|
2113
|
-
}
|
|
2114
|
-
context.out('</ul>');
|
|
2115
|
-
}
|
|
2116
|
-
}, {
|
|
2117
|
-
key: 'rootBegin',
|
|
2118
|
-
value: function rootBegin(context, type, nodeType) {
|
|
2119
|
-
context.out('<table class="jsondiffpatch-annotated-delta">');
|
|
2120
|
-
if (type === 'node') {
|
|
2121
|
-
context.row('{');
|
|
2122
|
-
context.indent();
|
|
2123
|
-
}
|
|
2124
|
-
if (nodeType === 'array') {
|
|
2125
|
-
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
}, {
|
|
2129
|
-
key: 'rootEnd',
|
|
2130
|
-
value: function rootEnd(context, type) {
|
|
2131
|
-
if (type === 'node') {
|
|
2132
|
-
context.indent(-1);
|
|
2133
|
-
context.row('}');
|
|
2134
|
-
}
|
|
2135
|
-
context.out('</table>');
|
|
2136
|
-
}
|
|
2137
|
-
}, {
|
|
2138
|
-
key: 'nodeBegin',
|
|
2139
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
2140
|
-
context.row('"' + key + '": {');
|
|
2141
|
-
if (type === 'node') {
|
|
2142
|
-
context.indent();
|
|
2143
|
-
}
|
|
2144
|
-
if (nodeType === 'array') {
|
|
2145
|
-
context.row('"_t": "a",', 'Array delta (member names indicate array indices)');
|
|
2146
|
-
}
|
|
2147
|
-
}
|
|
2148
|
-
}, {
|
|
2149
|
-
key: 'nodeEnd',
|
|
2150
|
-
value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
|
|
2151
|
-
if (type === 'node') {
|
|
2152
|
-
context.indent(-1);
|
|
2153
|
-
}
|
|
2154
|
-
context.row('}' + (isLast ? '' : ','));
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
/* jshint camelcase: false */
|
|
2158
|
-
|
|
2159
|
-
/* eslint-disable camelcase */
|
|
2160
|
-
}, {
|
|
2161
|
-
key: 'format_unchanged',
|
|
2162
|
-
value: function format_unchanged() {}
|
|
2163
|
-
}, {
|
|
2164
|
-
key: 'format_movedestination',
|
|
2165
|
-
value: function format_movedestination() {}
|
|
2166
|
-
}, {
|
|
2167
|
-
key: 'format_node',
|
|
2168
|
-
value: function format_node(context, delta, left) {
|
|
2169
|
-
// recurse
|
|
2170
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2171
|
-
}
|
|
2172
|
-
}]);
|
|
2173
|
-
return AnnotatedFormatter;
|
|
2174
|
-
}(BaseFormatter);
|
|
2175
|
-
|
|
2176
|
-
/* eslint-enable camelcase */
|
|
2177
|
-
|
|
2178
|
-
var wrapPropertyName = function wrapPropertyName(name) {
|
|
2179
|
-
return '<pre style="display:inline-block">"' + name + '"</pre>';
|
|
2180
|
-
};
|
|
2181
|
-
var deltaAnnotations = {
|
|
2182
|
-
added: function added(delta, left, key, leftKey) {
|
|
2183
|
-
var formatLegend = ' <pre>([newValue])</pre>';
|
|
2184
|
-
if (typeof leftKey === 'undefined') {
|
|
2185
|
-
return 'new value' + formatLegend;
|
|
2186
|
-
}
|
|
2187
|
-
if (typeof leftKey === 'number') {
|
|
2188
|
-
return 'insert at index ' + leftKey + formatLegend;
|
|
2189
|
-
}
|
|
2190
|
-
return 'add property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2191
|
-
},
|
|
2192
|
-
modified: function modified(delta, left, key, leftKey) {
|
|
2193
|
-
var formatLegend = ' <pre>([previousValue, newValue])</pre>';
|
|
2194
|
-
if (typeof leftKey === 'undefined') {
|
|
2195
|
-
return 'modify value' + formatLegend;
|
|
2196
|
-
}
|
|
2197
|
-
if (typeof leftKey === 'number') {
|
|
2198
|
-
return 'modify at index ' + leftKey + formatLegend;
|
|
2199
|
-
}
|
|
2200
|
-
return 'modify property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2201
|
-
},
|
|
2202
|
-
deleted: function deleted(delta, left, key, leftKey) {
|
|
2203
|
-
var formatLegend = ' <pre>([previousValue, 0, 0])</pre>';
|
|
2204
|
-
if (typeof leftKey === 'undefined') {
|
|
2205
|
-
return 'delete value' + formatLegend;
|
|
2206
|
-
}
|
|
2207
|
-
if (typeof leftKey === 'number') {
|
|
2208
|
-
return 'remove index ' + leftKey + formatLegend;
|
|
2209
|
-
}
|
|
2210
|
-
return 'delete property ' + wrapPropertyName(leftKey) + formatLegend;
|
|
2211
|
-
},
|
|
2212
|
-
moved: function moved(delta, left, key, leftKey) {
|
|
2213
|
-
return 'move from <span title="(position to remove at original state)">' + ('index ' + leftKey + '</span> to <span title="(position to insert at final') + (' state)">index ' + delta[1] + '</span>');
|
|
2214
|
-
},
|
|
2215
|
-
textdiff: function textdiff(delta, left, key, leftKey) {
|
|
2216
|
-
var location = typeof leftKey === 'undefined' ? '' : typeof leftKey === 'number' ? ' at index ' + leftKey : ' at property ' + wrapPropertyName(leftKey);
|
|
2217
|
-
return 'text diff' + location + ', format is <a href="https://code.google.com/' + 'p/google-diff-match-patch/wiki/Unidiff">a variation of Unidiff</a>';
|
|
2218
|
-
}
|
|
2219
|
-
};
|
|
2220
|
-
var formatAnyChange = function formatAnyChange(context, delta) {
|
|
2221
|
-
var deltaType = this.getDeltaType(delta);
|
|
2222
|
-
var annotator = deltaAnnotations[deltaType];
|
|
2223
|
-
var htmlNote = annotator && annotator.apply(annotator, Array.prototype.slice.call(arguments, 1));
|
|
2224
|
-
var json = JSON.stringify(delta, null, 2);
|
|
2225
|
-
if (deltaType === 'textdiff') {
|
|
2226
|
-
// split text diffs lines
|
|
2227
|
-
json = json.split('\\n').join('\\n"+\n "');
|
|
2228
|
-
}
|
|
2229
|
-
context.indent();
|
|
2230
|
-
context.row(json, htmlNote);
|
|
2231
|
-
context.indent(-1);
|
|
2232
|
-
};
|
|
2233
|
-
|
|
2234
|
-
/* eslint-disable camelcase */
|
|
2235
|
-
AnnotatedFormatter.prototype.format_added = formatAnyChange;
|
|
2236
|
-
AnnotatedFormatter.prototype.format_modified = formatAnyChange;
|
|
2237
|
-
AnnotatedFormatter.prototype.format_deleted = formatAnyChange;
|
|
2238
|
-
AnnotatedFormatter.prototype.format_moved = formatAnyChange;
|
|
2239
|
-
AnnotatedFormatter.prototype.format_textdiff = formatAnyChange;
|
|
2240
|
-
var defaultInstance$1 = void 0;
|
|
2241
|
-
function format$1(delta, left) {
|
|
2242
|
-
if (!defaultInstance$1) {
|
|
2243
|
-
defaultInstance$1 = new AnnotatedFormatter();
|
|
2244
|
-
}
|
|
2245
|
-
return defaultInstance$1.format(delta, left);
|
|
2246
|
-
}
|
|
2247
|
-
var annotated = Object.freeze({
|
|
2248
|
-
default: AnnotatedFormatter,
|
|
2249
|
-
format: format$1
|
|
2250
|
-
});
|
|
2251
|
-
var OPERATIONS = {
|
|
2252
|
-
add: 'add',
|
|
2253
|
-
remove: 'remove',
|
|
2254
|
-
replace: 'replace',
|
|
2255
|
-
move: 'move'
|
|
2256
|
-
};
|
|
2257
|
-
var JSONFormatter = function (_BaseFormatter) {
|
|
2258
|
-
inherits(JSONFormatter, _BaseFormatter);
|
|
2259
|
-
function JSONFormatter() {
|
|
2260
|
-
classCallCheck(this, JSONFormatter);
|
|
2261
|
-
var _this = possibleConstructorReturn(this, (JSONFormatter.__proto__ || Object.getPrototypeOf(JSONFormatter)).call(this));
|
|
2262
|
-
_this.includeMoveDestinations = true;
|
|
2263
|
-
return _this;
|
|
2264
|
-
}
|
|
2265
|
-
createClass(JSONFormatter, [{
|
|
2266
|
-
key: 'prepareContext',
|
|
2267
|
-
value: function prepareContext(context) {
|
|
2268
|
-
get(JSONFormatter.prototype.__proto__ || Object.getPrototypeOf(JSONFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2269
|
-
context.result = [];
|
|
2270
|
-
context.path = [];
|
|
2271
|
-
context.pushCurrentOp = function (obj) {
|
|
2272
|
-
var op = obj.op,
|
|
2273
|
-
value = obj.value;
|
|
2274
|
-
var val = {
|
|
2275
|
-
op: op,
|
|
2276
|
-
path: this.currentPath()
|
|
2277
|
-
};
|
|
2278
|
-
if (typeof value !== 'undefined') {
|
|
2279
|
-
val.value = value;
|
|
2280
|
-
}
|
|
2281
|
-
this.result.push(val);
|
|
2282
|
-
};
|
|
2283
|
-
context.pushMoveOp = function (to) {
|
|
2284
|
-
var from = this.currentPath();
|
|
2285
|
-
this.result.push({
|
|
2286
|
-
op: OPERATIONS.move,
|
|
2287
|
-
from: from,
|
|
2288
|
-
path: this.toPath(to)
|
|
2289
|
-
});
|
|
2290
|
-
};
|
|
2291
|
-
context.currentPath = function () {
|
|
2292
|
-
return '/' + this.path.join('/');
|
|
2293
|
-
};
|
|
2294
|
-
context.toPath = function (toPath) {
|
|
2295
|
-
var to = this.path.slice();
|
|
2296
|
-
to[to.length - 1] = toPath;
|
|
2297
|
-
return '/' + to.join('/');
|
|
2298
|
-
};
|
|
2299
|
-
}
|
|
2300
|
-
}, {
|
|
2301
|
-
key: 'typeFormattterErrorFormatter',
|
|
2302
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2303
|
-
context.out('[ERROR] ' + err);
|
|
2304
|
-
}
|
|
2305
|
-
}, {
|
|
2306
|
-
key: 'rootBegin',
|
|
2307
|
-
value: function rootBegin() {}
|
|
2308
|
-
}, {
|
|
2309
|
-
key: 'rootEnd',
|
|
2310
|
-
value: function rootEnd() {}
|
|
2311
|
-
}, {
|
|
2312
|
-
key: 'nodeBegin',
|
|
2313
|
-
value: function nodeBegin(_ref, key, leftKey) {
|
|
2314
|
-
var path = _ref.path;
|
|
2315
|
-
path.push(leftKey);
|
|
2316
|
-
}
|
|
2317
|
-
}, {
|
|
2318
|
-
key: 'nodeEnd',
|
|
2319
|
-
value: function nodeEnd(_ref2) {
|
|
2320
|
-
var path = _ref2.path;
|
|
2321
|
-
path.pop();
|
|
2322
|
-
}
|
|
2323
|
-
|
|
2324
|
-
/* jshint camelcase: false */
|
|
2325
|
-
/* eslint-disable camelcase */
|
|
2326
|
-
}, {
|
|
2327
|
-
key: 'format_unchanged',
|
|
2328
|
-
value: function format_unchanged() {}
|
|
2329
|
-
}, {
|
|
2330
|
-
key: 'format_movedestination',
|
|
2331
|
-
value: function format_movedestination() {}
|
|
2332
|
-
}, {
|
|
2333
|
-
key: 'format_node',
|
|
2334
|
-
value: function format_node(context, delta, left) {
|
|
2335
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2336
|
-
}
|
|
2337
|
-
}, {
|
|
2338
|
-
key: 'format_added',
|
|
2339
|
-
value: function format_added(context, delta) {
|
|
2340
|
-
context.pushCurrentOp({
|
|
2341
|
-
op: OPERATIONS.add,
|
|
2342
|
-
value: delta[0]
|
|
2343
|
-
});
|
|
2344
|
-
}
|
|
2345
|
-
}, {
|
|
2346
|
-
key: 'format_modified',
|
|
2347
|
-
value: function format_modified(context, delta) {
|
|
2348
|
-
context.pushCurrentOp({
|
|
2349
|
-
op: OPERATIONS.replace,
|
|
2350
|
-
value: delta[1]
|
|
2351
|
-
});
|
|
2352
|
-
}
|
|
2353
|
-
}, {
|
|
2354
|
-
key: 'format_deleted',
|
|
2355
|
-
value: function format_deleted(context) {
|
|
2356
|
-
context.pushCurrentOp({
|
|
2357
|
-
op: OPERATIONS.remove
|
|
2358
|
-
});
|
|
2359
|
-
}
|
|
2360
|
-
}, {
|
|
2361
|
-
key: 'format_moved',
|
|
2362
|
-
value: function format_moved(context, delta) {
|
|
2363
|
-
var to = delta[1];
|
|
2364
|
-
context.pushMoveOp(to);
|
|
2365
|
-
}
|
|
2366
|
-
}, {
|
|
2367
|
-
key: 'format_textdiff',
|
|
2368
|
-
value: function format_textdiff() {
|
|
2369
|
-
throw new Error('Not implemented');
|
|
2370
|
-
}
|
|
2371
|
-
}, {
|
|
2372
|
-
key: 'format',
|
|
2373
|
-
value: function format(delta, left) {
|
|
2374
|
-
var context = {};
|
|
2375
|
-
this.prepareContext(context);
|
|
2376
|
-
this.recurse(context, delta, left);
|
|
2377
|
-
return context.result;
|
|
2378
|
-
}
|
|
2379
|
-
}]);
|
|
2380
|
-
return JSONFormatter;
|
|
2381
|
-
}(BaseFormatter);
|
|
2382
|
-
var last = function last(arr) {
|
|
2383
|
-
return arr[arr.length - 1];
|
|
2384
|
-
};
|
|
2385
|
-
var sortBy = function sortBy(arr, pred) {
|
|
2386
|
-
arr.sort(pred);
|
|
2387
|
-
return arr;
|
|
2388
|
-
};
|
|
2389
|
-
var compareByIndexDesc = function compareByIndexDesc(indexA, indexB) {
|
|
2390
|
-
var lastA = parseInt(indexA, 10);
|
|
2391
|
-
var lastB = parseInt(indexB, 10);
|
|
2392
|
-
if (!(isNaN(lastA) || isNaN(lastB))) {
|
|
2393
|
-
return lastB - lastA;
|
|
2394
|
-
} else {
|
|
2395
|
-
return 0;
|
|
2396
|
-
}
|
|
2397
|
-
};
|
|
2398
|
-
var opsByDescendingOrder = function opsByDescendingOrder(removeOps) {
|
|
2399
|
-
return sortBy(removeOps, function (a, b) {
|
|
2400
|
-
var splitA = a.path.split('/');
|
|
2401
|
-
var splitB = b.path.split('/');
|
|
2402
|
-
if (splitA.length !== splitB.length) {
|
|
2403
|
-
return splitA.length - splitB.length;
|
|
2404
|
-
} else {
|
|
2405
|
-
return compareByIndexDesc(last(splitA), last(splitB));
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2408
|
-
};
|
|
2409
|
-
var partitionOps = function partitionOps(arr, fns) {
|
|
2410
|
-
var initArr = Array(fns.length + 1).fill().map(function () {
|
|
2411
|
-
return [];
|
|
2412
|
-
});
|
|
2413
|
-
return arr.map(function (item) {
|
|
2414
|
-
var position = fns.map(function (fn) {
|
|
2415
|
-
return fn(item);
|
|
2416
|
-
}).indexOf(true);
|
|
2417
|
-
if (position < 0) {
|
|
2418
|
-
position = fns.length;
|
|
2419
|
-
}
|
|
2420
|
-
return {
|
|
2421
|
-
item: item,
|
|
2422
|
-
position: position
|
|
2423
|
-
};
|
|
2424
|
-
}).reduce(function (acc, item) {
|
|
2425
|
-
acc[item.position].push(item.item);
|
|
2426
|
-
return acc;
|
|
2427
|
-
}, initArr);
|
|
2428
|
-
};
|
|
2429
|
-
var isMoveOp = function isMoveOp(_ref3) {
|
|
2430
|
-
var op = _ref3.op;
|
|
2431
|
-
return op === 'move';
|
|
2432
|
-
};
|
|
2433
|
-
var isRemoveOp = function isRemoveOp(_ref4) {
|
|
2434
|
-
var op = _ref4.op;
|
|
2435
|
-
return op === 'remove';
|
|
2436
|
-
};
|
|
2437
|
-
var reorderOps = function reorderOps(diff) {
|
|
2438
|
-
var _partitionOps = partitionOps(diff, [isMoveOp, isRemoveOp]),
|
|
2439
|
-
_partitionOps2 = slicedToArray(_partitionOps, 3),
|
|
2440
|
-
moveOps = _partitionOps2[0],
|
|
2441
|
-
removedOps = _partitionOps2[1],
|
|
2442
|
-
restOps = _partitionOps2[2];
|
|
2443
|
-
var removeOpsReverse = opsByDescendingOrder(removedOps);
|
|
2444
|
-
return [].concat(toConsumableArray(removeOpsReverse), toConsumableArray(moveOps), toConsumableArray(restOps));
|
|
2445
|
-
};
|
|
2446
|
-
var defaultInstance$2 = void 0;
|
|
2447
|
-
var format$2 = function format(delta, left) {
|
|
2448
|
-
if (!defaultInstance$2) {
|
|
2449
|
-
defaultInstance$2 = new JSONFormatter();
|
|
2450
|
-
}
|
|
2451
|
-
return reorderOps(defaultInstance$2.format(delta, left));
|
|
2452
|
-
};
|
|
2453
|
-
var log = function log(delta, left) {
|
|
2454
|
-
console.log(format$2(delta, left));
|
|
2455
|
-
};
|
|
2456
|
-
var jsonpatch = Object.freeze({
|
|
2457
|
-
default: JSONFormatter,
|
|
2458
|
-
partitionOps: partitionOps,
|
|
2459
|
-
format: format$2,
|
|
2460
|
-
log: log
|
|
2461
|
-
});
|
|
2462
|
-
function chalkColor(name) {
|
|
2463
|
-
return chalk && chalk[name] || function () {
|
|
2464
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
2465
|
-
args[_key] = arguments[_key];
|
|
2466
|
-
}
|
|
2467
|
-
return args;
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
var colors = {
|
|
2471
|
-
added: chalkColor('green'),
|
|
2472
|
-
deleted: chalkColor('red'),
|
|
2473
|
-
movedestination: chalkColor('gray'),
|
|
2474
|
-
moved: chalkColor('yellow'),
|
|
2475
|
-
unchanged: chalkColor('gray'),
|
|
2476
|
-
error: chalkColor('white.bgRed'),
|
|
2477
|
-
textDiffLine: chalkColor('gray')
|
|
2478
|
-
};
|
|
2479
|
-
var ConsoleFormatter = function (_BaseFormatter) {
|
|
2480
|
-
inherits(ConsoleFormatter, _BaseFormatter);
|
|
2481
|
-
function ConsoleFormatter() {
|
|
2482
|
-
classCallCheck(this, ConsoleFormatter);
|
|
2483
|
-
var _this = possibleConstructorReturn(this, (ConsoleFormatter.__proto__ || Object.getPrototypeOf(ConsoleFormatter)).call(this));
|
|
2484
|
-
_this.includeMoveDestinations = false;
|
|
2485
|
-
return _this;
|
|
2486
|
-
}
|
|
2487
|
-
createClass(ConsoleFormatter, [{
|
|
2488
|
-
key: 'prepareContext',
|
|
2489
|
-
value: function prepareContext(context) {
|
|
2490
|
-
get(ConsoleFormatter.prototype.__proto__ || Object.getPrototypeOf(ConsoleFormatter.prototype), 'prepareContext', this).call(this, context);
|
|
2491
|
-
context.indent = function (levels) {
|
|
2492
|
-
this.indentLevel = (this.indentLevel || 0) + (typeof levels === 'undefined' ? 1 : levels);
|
|
2493
|
-
this.indentPad = new Array(this.indentLevel + 1).join(' ');
|
|
2494
|
-
this.outLine();
|
|
2495
|
-
};
|
|
2496
|
-
context.outLine = function () {
|
|
2497
|
-
this.buffer.push('\n' + (this.indentPad || ''));
|
|
2498
|
-
};
|
|
2499
|
-
context.out = function () {
|
|
2500
|
-
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2501
|
-
args[_key2] = arguments[_key2];
|
|
2502
|
-
}
|
|
2503
|
-
for (var i = 0, l = args.length; i < l; i++) {
|
|
2504
|
-
var lines = args[i].split('\n');
|
|
2505
|
-
var text = lines.join('\n' + (this.indentPad || ''));
|
|
2506
|
-
if (this.color && this.color[0]) {
|
|
2507
|
-
text = this.color[0](text);
|
|
2508
|
-
}
|
|
2509
|
-
this.buffer.push(text);
|
|
2510
|
-
}
|
|
2511
|
-
};
|
|
2512
|
-
context.pushColor = function (color) {
|
|
2513
|
-
this.color = this.color || [];
|
|
2514
|
-
this.color.unshift(color);
|
|
2515
|
-
};
|
|
2516
|
-
context.popColor = function () {
|
|
2517
|
-
this.color = this.color || [];
|
|
2518
|
-
this.color.shift();
|
|
2519
|
-
};
|
|
2520
|
-
}
|
|
2521
|
-
}, {
|
|
2522
|
-
key: 'typeFormattterErrorFormatter',
|
|
2523
|
-
value: function typeFormattterErrorFormatter(context, err) {
|
|
2524
|
-
context.pushColor(colors.error);
|
|
2525
|
-
context.out('[ERROR]' + err);
|
|
2526
|
-
context.popColor();
|
|
2527
|
-
}
|
|
2528
|
-
}, {
|
|
2529
|
-
key: 'formatValue',
|
|
2530
|
-
value: function formatValue(context, value) {
|
|
2531
|
-
context.out(JSON.stringify(value, null, 2));
|
|
2532
|
-
}
|
|
2533
|
-
}, {
|
|
2534
|
-
key: 'formatTextDiffString',
|
|
2535
|
-
value: function formatTextDiffString(context, value) {
|
|
2536
|
-
var lines = this.parseTextDiff(value);
|
|
2537
|
-
context.indent();
|
|
2538
|
-
for (var i = 0, l = lines.length; i < l; i++) {
|
|
2539
|
-
var line = lines[i];
|
|
2540
|
-
context.pushColor(colors.textDiffLine);
|
|
2541
|
-
context.out(line.location.line + ',' + line.location.chr + ' ');
|
|
2542
|
-
context.popColor();
|
|
2543
|
-
var pieces = line.pieces;
|
|
2544
|
-
for (var pieceIndex = 0, piecesLength = pieces.length; pieceIndex < piecesLength; pieceIndex++) {
|
|
2545
|
-
var piece = pieces[pieceIndex];
|
|
2546
|
-
context.pushColor(colors[piece.type]);
|
|
2547
|
-
context.out(piece.text);
|
|
2548
|
-
context.popColor();
|
|
2549
|
-
}
|
|
2550
|
-
if (i < l - 1) {
|
|
2551
|
-
context.outLine();
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
context.indent(-1);
|
|
2555
|
-
}
|
|
2556
|
-
}, {
|
|
2557
|
-
key: 'rootBegin',
|
|
2558
|
-
value: function rootBegin(context, type, nodeType) {
|
|
2559
|
-
context.pushColor(colors[type]);
|
|
2560
|
-
if (type === 'node') {
|
|
2561
|
-
context.out(nodeType === 'array' ? '[' : '{');
|
|
2562
|
-
context.indent();
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
}, {
|
|
2566
|
-
key: 'rootEnd',
|
|
2567
|
-
value: function rootEnd(context, type, nodeType) {
|
|
2568
|
-
if (type === 'node') {
|
|
2569
|
-
context.indent(-1);
|
|
2570
|
-
context.out(nodeType === 'array' ? ']' : '}');
|
|
2571
|
-
}
|
|
2572
|
-
context.popColor();
|
|
2573
|
-
}
|
|
2574
|
-
}, {
|
|
2575
|
-
key: 'nodeBegin',
|
|
2576
|
-
value: function nodeBegin(context, key, leftKey, type, nodeType) {
|
|
2577
|
-
context.pushColor(colors[type]);
|
|
2578
|
-
context.out(leftKey + ': ');
|
|
2579
|
-
if (type === 'node') {
|
|
2580
|
-
context.out(nodeType === 'array' ? '[' : '{');
|
|
2581
|
-
context.indent();
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
}, {
|
|
2585
|
-
key: 'nodeEnd',
|
|
2586
|
-
value: function nodeEnd(context, key, leftKey, type, nodeType, isLast) {
|
|
2587
|
-
if (type === 'node') {
|
|
2588
|
-
context.indent(-1);
|
|
2589
|
-
context.out(nodeType === 'array' ? ']' : '}' + (isLast ? '' : ','));
|
|
2590
|
-
}
|
|
2591
|
-
if (!isLast) {
|
|
2592
|
-
context.outLine();
|
|
2593
|
-
}
|
|
2594
|
-
context.popColor();
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
/* jshint camelcase: false */
|
|
2598
|
-
/* eslint-disable camelcase */
|
|
2599
|
-
}, {
|
|
2600
|
-
key: 'format_unchanged',
|
|
2601
|
-
value: function format_unchanged(context, delta, left) {
|
|
2602
|
-
if (typeof left === 'undefined') {
|
|
2603
|
-
return;
|
|
2604
|
-
}
|
|
2605
|
-
this.formatValue(context, left);
|
|
2606
|
-
}
|
|
2607
|
-
}, {
|
|
2608
|
-
key: 'format_movedestination',
|
|
2609
|
-
value: function format_movedestination(context, delta, left) {
|
|
2610
|
-
if (typeof left === 'undefined') {
|
|
2611
|
-
return;
|
|
2612
|
-
}
|
|
2613
|
-
this.formatValue(context, left);
|
|
2614
|
-
}
|
|
2615
|
-
}, {
|
|
2616
|
-
key: 'format_node',
|
|
2617
|
-
value: function format_node(context, delta, left) {
|
|
2618
|
-
// recurse
|
|
2619
|
-
this.formatDeltaChildren(context, delta, left);
|
|
2620
|
-
}
|
|
2621
|
-
}, {
|
|
2622
|
-
key: 'format_added',
|
|
2623
|
-
value: function format_added(context, delta) {
|
|
2624
|
-
this.formatValue(context, delta[0]);
|
|
2625
|
-
}
|
|
2626
|
-
}, {
|
|
2627
|
-
key: 'format_modified',
|
|
2628
|
-
value: function format_modified(context, delta) {
|
|
2629
|
-
context.pushColor(colors.deleted);
|
|
2630
|
-
this.formatValue(context, delta[0]);
|
|
2631
|
-
context.popColor();
|
|
2632
|
-
context.out(' => ');
|
|
2633
|
-
context.pushColor(colors.added);
|
|
2634
|
-
this.formatValue(context, delta[1]);
|
|
2635
|
-
context.popColor();
|
|
2636
|
-
}
|
|
2637
|
-
}, {
|
|
2638
|
-
key: 'format_deleted',
|
|
2639
|
-
value: function format_deleted(context, delta) {
|
|
2640
|
-
this.formatValue(context, delta[0]);
|
|
2641
|
-
}
|
|
2642
|
-
}, {
|
|
2643
|
-
key: 'format_moved',
|
|
2644
|
-
value: function format_moved(context, delta) {
|
|
2645
|
-
context.out('==> ' + delta[1]);
|
|
2646
|
-
}
|
|
2647
|
-
}, {
|
|
2648
|
-
key: 'format_textdiff',
|
|
2649
|
-
value: function format_textdiff(context, delta) {
|
|
2650
|
-
this.formatTextDiffString(context, delta[0]);
|
|
2651
|
-
}
|
|
2652
|
-
}]);
|
|
2653
|
-
return ConsoleFormatter;
|
|
2654
|
-
}(BaseFormatter);
|
|
2655
|
-
var defaultInstance$3 = void 0;
|
|
2656
|
-
var format$3 = function format(delta, left) {
|
|
2657
|
-
if (!defaultInstance$3) {
|
|
2658
|
-
defaultInstance$3 = new ConsoleFormatter();
|
|
2659
|
-
}
|
|
2660
|
-
return defaultInstance$3.format(delta, left);
|
|
2661
|
-
};
|
|
2662
|
-
function log$1(delta, left) {
|
|
2663
|
-
console.log(format$3(delta, left));
|
|
2664
|
-
}
|
|
2665
|
-
var console$1 = Object.freeze({
|
|
2666
|
-
default: ConsoleFormatter,
|
|
2667
|
-
format: format$3,
|
|
2668
|
-
log: log$1
|
|
2669
|
-
});
|
|
2670
|
-
Object.freeze({
|
|
2671
|
-
base: base,
|
|
2672
|
-
html: html,
|
|
2673
|
-
annotated: annotated,
|
|
2674
|
-
jsonpatch: jsonpatch,
|
|
2675
|
-
console: console$1
|
|
2676
|
-
});
|
|
2677
|
-
|
|
2678
235
|
function objectHash(obj, index) {
|
|
2679
236
|
var objIndex = "$$index:".concat(index);
|
|
2680
|
-
return _typeof
|
|
237
|
+
return _typeof(obj) === 'object' && obj !== null ? obj.id || obj.name || obj.url || objIndex : objIndex;
|
|
2681
238
|
}
|
|
2682
239
|
var diffpatcher = new DiffPatcher({
|
|
2683
240
|
objectHash: objectHash,
|
|
@@ -2841,7 +398,7 @@ function isCreateAction(obj, key) {
|
|
|
2841
398
|
* false otherwise
|
|
2842
399
|
*/
|
|
2843
400
|
function isChangeAction(obj, key) {
|
|
2844
|
-
return REGEX_NUMBER$4.test(key) && (_typeof
|
|
401
|
+
return REGEX_NUMBER$4.test(key) && (_typeof(obj[key]) === 'object' || typeof obj[key] === 'string');
|
|
2845
402
|
}
|
|
2846
403
|
|
|
2847
404
|
/**
|
|
@@ -2857,7 +414,7 @@ function isChangeAction(obj, key) {
|
|
|
2857
414
|
* false otherwise
|
|
2858
415
|
*/
|
|
2859
416
|
function isRemoveAction$1(obj, key) {
|
|
2860
|
-
return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof
|
|
417
|
+
return REGEX_UNDERSCORE_NUMBER$4.test(key) && Array.isArray(obj[key]) && obj[key].length === 3 && (_typeof(obj[key][0]) === 'object' || typeof obj[key][0] === 'string') && obj[key][1] === 0 && obj[key][2] === 0;
|
|
2861
418
|
}
|
|
2862
419
|
|
|
2863
420
|
/**
|
|
@@ -2950,6 +507,11 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
|
|
|
2950
507
|
};
|
|
2951
508
|
};
|
|
2952
509
|
|
|
510
|
+
/* actions that start with 'set' can generate undefined valued */
|
|
511
|
+
var isOptionalField = function isOptionalField(action) {
|
|
512
|
+
return action.startsWith('set');
|
|
513
|
+
};
|
|
514
|
+
|
|
2953
515
|
/**
|
|
2954
516
|
* Builds actions for simple object properties, given a list of actions
|
|
2955
517
|
* E.g. [{ action: `changeName`, key: 'name' }]
|
|
@@ -2960,13 +522,17 @@ var createIsEmptyValue = function createIsEmptyValue(emptyValues) {
|
|
|
2960
522
|
* @param {Object} options.oldObj - the object that needs to be updated
|
|
2961
523
|
* @param {Object} options.newObj - the new representation of the object
|
|
2962
524
|
* @param {Boolean} options.shouldOmitEmptyString - a flag to determine if we should treat an empty string a NON-value
|
|
525
|
+
* @param {Boolean} options.shouldUnsetOmittedProperties - a flag to determine if we should unset fields which are omitted in the newObj
|
|
526
|
+
* @param {Boolean} options.shouldPreventUnsettingRequiredFields - a flag to determine if required fields should be unset
|
|
2963
527
|
*/
|
|
2964
528
|
function buildBaseAttributesActions(_ref) {
|
|
2965
529
|
var actions = _ref.actions,
|
|
2966
530
|
diff = _ref.diff,
|
|
2967
531
|
oldObj = _ref.oldObj,
|
|
2968
532
|
newObj = _ref.newObj,
|
|
2969
|
-
shouldOmitEmptyString = _ref.shouldOmitEmptyString
|
|
533
|
+
shouldOmitEmptyString = _ref.shouldOmitEmptyString,
|
|
534
|
+
shouldUnsetOmittedProperties = _ref.shouldUnsetOmittedProperties,
|
|
535
|
+
shouldPreventUnsettingRequiredFields = _ref.shouldPreventUnsettingRequiredFields;
|
|
2970
536
|
var isEmptyValue = createIsEmptyValue(shouldOmitEmptyString ? [undefined, null, ''] : [undefined, null]);
|
|
2971
537
|
return actions.map(function (item) {
|
|
2972
538
|
var key = item.key; // e.g.: name, description, ...
|
|
@@ -2976,7 +542,9 @@ function buildBaseAttributesActions(_ref) {
|
|
|
2976
542
|
var now = newObj[key];
|
|
2977
543
|
var isNotDefinedBefore = isEmptyValue(oldObj[key]);
|
|
2978
544
|
var isNotDefinedNow = isEmptyValue(newObj[key]);
|
|
545
|
+
var isOmitted = !Object.keys(newObj).includes(key);
|
|
2979
546
|
if (!delta) return undefined;
|
|
547
|
+
if (isNotDefinedNow && !isOptionalField(item.action) && shouldPreventUnsettingRequiredFields) return undefined;
|
|
2980
548
|
if (isNotDefinedNow && isNotDefinedBefore) return undefined;
|
|
2981
549
|
if (!isNotDefinedNow && isNotDefinedBefore)
|
|
2982
550
|
// no value previously set
|
|
@@ -2985,8 +553,8 @@ function buildBaseAttributesActions(_ref) {
|
|
|
2985
553
|
}, actionKey, now);
|
|
2986
554
|
|
|
2987
555
|
/* no new value */
|
|
2988
|
-
if (isNotDefinedNow && !
|
|
2989
|
-
if (isNotDefinedNow
|
|
556
|
+
if (isNotDefinedNow && isOmitted && !shouldUnsetOmittedProperties) return undefined;
|
|
557
|
+
if (isNotDefinedNow)
|
|
2990
558
|
// value unset
|
|
2991
559
|
return {
|
|
2992
560
|
action: item.action
|
|
@@ -3096,7 +664,9 @@ function actionsMapBase$k(diff, oldObj, newObj) {
|
|
|
3096
664
|
diff: diff,
|
|
3097
665
|
oldObj: oldObj,
|
|
3098
666
|
newObj: newObj,
|
|
3099
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
667
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
668
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
669
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
3100
670
|
});
|
|
3101
671
|
}
|
|
3102
672
|
function actionsMapReferences$3(diff, oldObj, newObj) {
|
|
@@ -3144,7 +714,7 @@ function copyEmptyArrayProps() {
|
|
|
3144
714
|
return acc;
|
|
3145
715
|
}, {});
|
|
3146
716
|
for (var i = 0; i < newObj[key].length; i++) {
|
|
3147
|
-
if (!isNil(newObj[key][i]) && _typeof
|
|
717
|
+
if (!isNil(newObj[key][i]) && _typeof(newObj[key][i]) === 'object' && !isNil(newObj[key][i].id)) {
|
|
3148
718
|
// Since its unordered array elements then check if the element on `oldObj` exists by id
|
|
3149
719
|
var foundObject = hashMapValue[newObj[key][i].id];
|
|
3150
720
|
if (!isNil(foundObject)) {
|
|
@@ -3166,7 +736,7 @@ function copyEmptyArrayProps() {
|
|
|
3166
736
|
merged[key] = isNil(newObj[key]) ? [] : newObj[key];
|
|
3167
737
|
return merged;
|
|
3168
738
|
}
|
|
3169
|
-
if (!isNil(newObj[key]) && _typeof
|
|
739
|
+
if (!isNil(newObj[key]) && _typeof(value) === 'object' &&
|
|
3170
740
|
// Ignore Date as this will create invalid object since typeof date === 'object' return true
|
|
3171
741
|
// ex: {date: new Date()} will result {date: {}}
|
|
3172
742
|
!(value instanceof Date)) {
|
|
@@ -3298,7 +868,9 @@ function actionsMapBase$j(diff, oldObj, newObj) {
|
|
|
3298
868
|
diff: diff,
|
|
3299
869
|
oldObj: oldObj,
|
|
3300
870
|
newObj: newObj,
|
|
3301
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
871
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
872
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
873
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
3302
874
|
});
|
|
3303
875
|
}
|
|
3304
876
|
function actionsMapSetDefaultBase(diff, oldObj, newObj) {
|
|
@@ -3308,7 +880,9 @@ function actionsMapSetDefaultBase(diff, oldObj, newObj) {
|
|
|
3308
880
|
diff: diff,
|
|
3309
881
|
oldObj: oldObj,
|
|
3310
882
|
newObj: newObj,
|
|
3311
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
883
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
884
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
885
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
3312
886
|
});
|
|
3313
887
|
}
|
|
3314
888
|
function actionsMapReferences$2(diff, oldObj, newObj) {
|
|
@@ -3504,7 +1078,9 @@ function actionsMapBase$i(diff, oldObj, newObj) {
|
|
|
3504
1078
|
diff: diff,
|
|
3505
1079
|
oldObj: oldObj,
|
|
3506
1080
|
newObj: newObj,
|
|
3507
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
1081
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
1082
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
1083
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
3508
1084
|
});
|
|
3509
1085
|
}
|
|
3510
1086
|
function actionsMapReferences$1(diff, oldObj, newObj) {
|
|
@@ -3754,7 +1330,7 @@ function _buildSetAttributeAction(diffedValue, oldVariant, attribute, sameForAll
|
|
|
3754
1330
|
currencyCode: diffedValue.currencyCode ? getDeltaValue(diffedValue.currencyCode) : attribute.value.currencyCode
|
|
3755
1331
|
};else if (diffedValue.key)
|
|
3756
1332
|
// Enum / LEnum (use only the key)
|
|
3757
|
-
action.value = getDeltaValue(diffedValue.key);else if (_typeof
|
|
1333
|
+
action.value = getDeltaValue(diffedValue.key);else if (_typeof(diffedValue) === 'object') if ({}.hasOwnProperty.call(diffedValue, '_t') && diffedValue._t === 'a') {
|
|
3758
1334
|
// set-typed attribute
|
|
3759
1335
|
action = _objectSpread2(_objectSpread2({}, action), {}, {
|
|
3760
1336
|
value: attribute.value
|
|
@@ -3786,7 +1362,7 @@ function _buildVariantImagesAction(diffedImages) {
|
|
|
3786
1362
|
action: 'addExternalImage',
|
|
3787
1363
|
variantId: oldVariant.id,
|
|
3788
1364
|
image: getDeltaValue(image)
|
|
3789
|
-
});else if (_typeof
|
|
1365
|
+
});else if (_typeof(image) === 'object') if ({}.hasOwnProperty.call(image, 'url') && image.url.length === 2) {
|
|
3790
1366
|
// There is a new image, remove the old one first.
|
|
3791
1367
|
actions.push({
|
|
3792
1368
|
action: 'removeImage',
|
|
@@ -4021,15 +1597,19 @@ function actionsMapBase$h(diff, oldObj, newObj) {
|
|
|
4021
1597
|
diff: diff,
|
|
4022
1598
|
oldObj: oldObj,
|
|
4023
1599
|
newObj: newObj,
|
|
4024
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
1600
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
1601
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
|
|
4025
1602
|
});
|
|
4026
1603
|
}
|
|
4027
1604
|
function actionsMapMeta(diff, oldObj, newObj) {
|
|
1605
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
4028
1606
|
return buildBaseAttributesActions({
|
|
4029
1607
|
actions: metaActionsList,
|
|
4030
1608
|
diff: diff,
|
|
4031
1609
|
oldObj: oldObj,
|
|
4032
|
-
newObj: newObj
|
|
1610
|
+
newObj: newObj,
|
|
1611
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
1612
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
|
|
4033
1613
|
});
|
|
4034
1614
|
}
|
|
4035
1615
|
function actionsMapAddVariants(diff, oldObj, newObj) {
|
|
@@ -4339,7 +1919,9 @@ function actionsMapBase$g(diff, oldObj, newObj) {
|
|
|
4339
1919
|
diff: diff,
|
|
4340
1920
|
oldObj: oldObj,
|
|
4341
1921
|
newObj: newObj,
|
|
4342
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
1922
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
1923
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
1924
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
4343
1925
|
});
|
|
4344
1926
|
}
|
|
4345
1927
|
function actionsMapDeliveries(diff, oldObj, newObj) {
|
|
@@ -4558,7 +2140,9 @@ function actionsMapBase$f(diff, oldObj, newObj) {
|
|
|
4558
2140
|
diff: diff,
|
|
4559
2141
|
oldObj: oldObj,
|
|
4560
2142
|
newObj: newObj,
|
|
4561
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2143
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2144
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2145
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
4562
2146
|
});
|
|
4563
2147
|
}
|
|
4564
2148
|
|
|
@@ -4646,7 +2230,9 @@ function actionsMapBase$e(diff, oldObj, newObj) {
|
|
|
4646
2230
|
diff: diff,
|
|
4647
2231
|
oldObj: oldObj,
|
|
4648
2232
|
newObj: newObj,
|
|
4649
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2233
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2234
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2235
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
4650
2236
|
});
|
|
4651
2237
|
}
|
|
4652
2238
|
|
|
@@ -4697,7 +2283,9 @@ function actionsMapBase$d(diff, oldObj, newObj) {
|
|
|
4697
2283
|
diff: diff,
|
|
4698
2284
|
oldObj: oldObj,
|
|
4699
2285
|
newObj: newObj,
|
|
4700
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2286
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2287
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2288
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
4701
2289
|
});
|
|
4702
2290
|
}
|
|
4703
2291
|
|
|
@@ -4767,7 +2355,9 @@ function actionsMapBase$c(diff, oldObj, newObj) {
|
|
|
4767
2355
|
diff: diff,
|
|
4768
2356
|
oldObj: oldObj,
|
|
4769
2357
|
newObj: newObj,
|
|
4770
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2358
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2359
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2360
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
4771
2361
|
});
|
|
4772
2362
|
}
|
|
4773
2363
|
|
|
@@ -4875,8 +2465,8 @@ function createCircularEqualCreator(isEqual) {
|
|
|
4875
2465
|
if (cache === void 0) {
|
|
4876
2466
|
cache = getNewCache();
|
|
4877
2467
|
}
|
|
4878
|
-
var isCacheableA = !!a && _typeof
|
|
4879
|
-
var isCacheableB = !!b && _typeof
|
|
2468
|
+
var isCacheableA = !!a && _typeof(a) === 'object';
|
|
2469
|
+
var isCacheableB = !!b && _typeof(b) === 'object';
|
|
4880
2470
|
if (isCacheableA || isCacheableB) {
|
|
4881
2471
|
var hasA = isCacheableA && cache.has(a);
|
|
4882
2472
|
var hasB = isCacheableB && cache.has(b);
|
|
@@ -5042,7 +2632,7 @@ function createComparator(createIsEqual) {
|
|
|
5042
2632
|
if (a === b) {
|
|
5043
2633
|
return true;
|
|
5044
2634
|
}
|
|
5045
|
-
if (a && b && _typeof
|
|
2635
|
+
if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
5046
2636
|
if (isPlainObject(a) && isPlainObject(b)) {
|
|
5047
2637
|
return areObjectsEqual(a, b, isEqual, meta);
|
|
5048
2638
|
}
|
|
@@ -5115,7 +2705,9 @@ function actionsMapBase$b(diff, oldObj, newObj) {
|
|
|
5115
2705
|
diff: diff,
|
|
5116
2706
|
oldObj: oldObj,
|
|
5117
2707
|
newObj: newObj,
|
|
5118
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2708
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2709
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2710
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5119
2711
|
});
|
|
5120
2712
|
}
|
|
5121
2713
|
function actionsMapRates(diff, oldObj, newObj) {
|
|
@@ -5203,7 +2795,9 @@ function actionsMapBase$a(diff, oldObj, newObj) {
|
|
|
5203
2795
|
diff: diff,
|
|
5204
2796
|
oldObj: oldObj,
|
|
5205
2797
|
newObj: newObj,
|
|
5206
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2798
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2799
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2800
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5207
2801
|
});
|
|
5208
2802
|
}
|
|
5209
2803
|
function actionsMapLocations(diff, oldObj, newObj) {
|
|
@@ -5308,7 +2902,9 @@ function actionsMapBase$9(diff, oldObj, newObj) {
|
|
|
5308
2902
|
diff: diff,
|
|
5309
2903
|
oldObj: oldObj,
|
|
5310
2904
|
newObj: newObj,
|
|
5311
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
2905
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
2906
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
2907
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5312
2908
|
});
|
|
5313
2909
|
}
|
|
5314
2910
|
var addShippingRates = function addShippingRates(newZoneRate) {
|
|
@@ -5431,7 +3027,8 @@ function actionsMapBase$8(diff, previous, next) {
|
|
|
5431
3027
|
actions: baseActionsList$8,
|
|
5432
3028
|
oldObj: previous,
|
|
5433
3029
|
newObj: next,
|
|
5434
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3030
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3031
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
|
|
5435
3032
|
});
|
|
5436
3033
|
}
|
|
5437
3034
|
|
|
@@ -5688,7 +3285,9 @@ function actionsMapBase$7(diff, oldObj, newObj) {
|
|
|
5688
3285
|
diff: diff,
|
|
5689
3286
|
oldObj: oldObj,
|
|
5690
3287
|
newObj: newObj,
|
|
5691
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3288
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3289
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3290
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5692
3291
|
});
|
|
5693
3292
|
}
|
|
5694
3293
|
function actionsMapRoles(diff, oldObj, newObj) {
|
|
@@ -5774,7 +3373,9 @@ function actionsMapBase$6(diff, oldObj, newObj) {
|
|
|
5774
3373
|
diff: diff,
|
|
5775
3374
|
oldObj: oldObj,
|
|
5776
3375
|
newObj: newObj,
|
|
5777
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3376
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3377
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3378
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5778
3379
|
});
|
|
5779
3380
|
}
|
|
5780
3381
|
|
|
@@ -5825,7 +3426,9 @@ function actionsMapBase$5(diff, oldObj, newObj) {
|
|
|
5825
3426
|
diff: diff,
|
|
5826
3427
|
oldObj: oldObj,
|
|
5827
3428
|
newObj: newObj,
|
|
5828
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3429
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3430
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3431
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
5829
3432
|
});
|
|
5830
3433
|
}
|
|
5831
3434
|
function actionsMapEnums(fieldName, attributeType, attributeDiff, previous, next) {
|
|
@@ -5951,7 +3554,7 @@ function actionsMapFieldDefinitions(fieldDefinitionsDiff, previous, next, diffPa
|
|
|
5951
3554
|
// in order to prevent any eventual removal of `addAction`.
|
|
5952
3555
|
// List of `removeActions` can be found here
|
|
5953
3556
|
// https://docs.commercetools.com/http-api-projects-types.html#change-key
|
|
5954
|
-
var sortedActions = sortBy
|
|
3557
|
+
var sortedActions = sortBy(actions, function (action) {
|
|
5955
3558
|
return action.action !== 'removeFieldDefinition';
|
|
5956
3559
|
});
|
|
5957
3560
|
return sortedActions;
|
|
@@ -6020,6 +3623,7 @@ function actionsMapBase$4(diff, oldObj, newObj) {
|
|
|
6020
3623
|
});
|
|
6021
3624
|
}
|
|
6022
3625
|
var actionsMapBusinessUnit = function actionsMapBusinessUnit(diff, oldObj, newObj) {
|
|
3626
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
6023
3627
|
var businessUnits = diff.businessUnits;
|
|
6024
3628
|
if (!businessUnits) {
|
|
6025
3629
|
return [];
|
|
@@ -6028,10 +3632,13 @@ var actionsMapBusinessUnit = function actionsMapBusinessUnit(diff, oldObj, newOb
|
|
|
6028
3632
|
actions: myBusinessUnitActionsList,
|
|
6029
3633
|
diff: businessUnits,
|
|
6030
3634
|
oldObj: oldObj.businessUnits,
|
|
6031
|
-
newObj: newObj.businessUnits
|
|
3635
|
+
newObj: newObj.businessUnits,
|
|
3636
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3637
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties
|
|
6032
3638
|
});
|
|
6033
3639
|
};
|
|
6034
3640
|
function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) {
|
|
3641
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
6035
3642
|
var searchIndexing = diff.searchIndexing;
|
|
6036
3643
|
if (!searchIndexing) {
|
|
6037
3644
|
return [];
|
|
@@ -6044,7 +3651,10 @@ function actionsMapSearchIndexingConfiguration(diff, oldObj, newObj) {
|
|
|
6044
3651
|
actions: customerSearchActionsList,
|
|
6045
3652
|
diff: diff.searchIndexing.customers,
|
|
6046
3653
|
oldObj: oldObj.searchIndexing.customers,
|
|
6047
|
-
newObj: newObj.searchIndexing.customers
|
|
3654
|
+
newObj: newObj.searchIndexing.customers,
|
|
3655
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3656
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3657
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
6048
3658
|
});
|
|
6049
3659
|
}
|
|
6050
3660
|
|
|
@@ -6087,11 +3697,15 @@ var baseActionsList$3 = [{
|
|
|
6087
3697
|
key: 'supplyChannels'
|
|
6088
3698
|
}];
|
|
6089
3699
|
function actionsMapBase$3(diff, oldObj, newObj) {
|
|
3700
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
6090
3701
|
return buildBaseAttributesActions({
|
|
6091
3702
|
actions: baseActionsList$3,
|
|
6092
3703
|
diff: diff,
|
|
6093
3704
|
oldObj: oldObj,
|
|
6094
|
-
newObj: newObj
|
|
3705
|
+
newObj: newObj,
|
|
3706
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3707
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3708
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
6095
3709
|
});
|
|
6096
3710
|
}
|
|
6097
3711
|
|
|
@@ -6108,10 +3722,11 @@ function createStoresMapActions(mapActionGroup) {
|
|
|
6108
3722
|
};
|
|
6109
3723
|
}
|
|
6110
3724
|
var stores = (function (actionGroupList) {
|
|
3725
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
6111
3726
|
var mapActionGroup = createMapActionGroup(actionGroupList);
|
|
6112
3727
|
var doMapActions = createStoresMapActions(mapActionGroup);
|
|
6113
3728
|
var onBeforeApplyingDiff = null;
|
|
6114
|
-
var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff);
|
|
3729
|
+
var buildActions = createBuildActions(diff, doMapActions, onBeforeApplyingDiff, options);
|
|
6115
3730
|
return {
|
|
6116
3731
|
buildActions: buildActions
|
|
6117
3732
|
};
|
|
@@ -6125,11 +3740,15 @@ var baseActionsList$2 = [{
|
|
|
6125
3740
|
key: 'key'
|
|
6126
3741
|
}];
|
|
6127
3742
|
function actionsMapBase$2(diff, oldObj, newObj) {
|
|
3743
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
6128
3744
|
return buildBaseAttributesActions({
|
|
6129
3745
|
actions: baseActionsList$2,
|
|
6130
3746
|
diff: diff,
|
|
6131
3747
|
oldObj: oldObj,
|
|
6132
|
-
newObj: newObj
|
|
3748
|
+
newObj: newObj,
|
|
3749
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3750
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3751
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
6133
3752
|
});
|
|
6134
3753
|
}
|
|
6135
3754
|
|
|
@@ -6186,7 +3805,9 @@ function actionsMapBase$1(diff, oldObj, newObj) {
|
|
|
6186
3805
|
diff: diff,
|
|
6187
3806
|
oldObj: oldObj,
|
|
6188
3807
|
newObj: newObj,
|
|
6189
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3808
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3809
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3810
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
6190
3811
|
});
|
|
6191
3812
|
}
|
|
6192
3813
|
|
|
@@ -6232,7 +3853,9 @@ function actionsMapBase(diff, oldObj, newObj) {
|
|
|
6232
3853
|
diff: diff,
|
|
6233
3854
|
oldObj: oldObj,
|
|
6234
3855
|
newObj: newObj,
|
|
6235
|
-
shouldOmitEmptyString: config.shouldOmitEmptyString
|
|
3856
|
+
shouldOmitEmptyString: config.shouldOmitEmptyString,
|
|
3857
|
+
shouldUnsetOmittedProperties: config.shouldUnsetOmittedProperties,
|
|
3858
|
+
shouldPreventUnsettingRequiredFields: config.shouldPreventUnsettingRequiredFields
|
|
6236
3859
|
});
|
|
6237
3860
|
}
|
|
6238
3861
|
function actionsMapAttributes(diff, oldObj, newObj) {
|