@commercetools/sync-actions 5.19.2 → 6.0.0

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