1
1
( function ( global , factory ) {
2
2
if ( typeof define === "function" && define . amd ) {
3
- define ( [ ' module' , ' exports' , ' ../utils' ] , factory ) ;
3
+ define ( [ " module" , " exports" , "lodash" , " ../utils" ] , factory ) ;
4
4
} else if ( typeof exports !== "undefined" ) {
5
- factory ( module , exports , require ( ' ../utils' ) ) ;
5
+ factory ( module , exports , require ( "lodash" ) , require ( " ../utils" ) ) ;
6
6
} else {
7
7
var mod = {
8
8
exports : { }
9
9
} ;
10
- factory ( mod , mod . exports , global . utils ) ;
10
+ factory ( mod , mod . exports , global . lodash , global . utils ) ;
11
11
global . index = mod . exports ;
12
12
}
13
- } ) ( this , function ( module , exports , _utils ) {
14
- ' use strict' ;
13
+ } ) ( this , function ( module , exports , _lodash , _utils ) {
14
+ " use strict" ;
15
15
16
16
Object . defineProperty ( exports , "__esModule" , {
17
17
value : true
18
18
} ) ;
19
19
20
+ var _lodash2 = _interopRequireDefault ( _lodash ) ;
21
+
22
+ function _interopRequireDefault ( obj ) {
23
+ return obj && obj . __esModule ? obj : {
24
+ default : obj
25
+ } ;
26
+ }
27
+
28
+ var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) {
29
+ return typeof obj ;
30
+ } : function ( obj ) {
31
+ return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ;
32
+ } ;
33
+
20
34
function _defineProperty ( obj , key , value ) {
21
35
if ( key in obj ) {
22
36
Object . defineProperty ( obj , key , {
55
69
56
70
return Object . keys ( r ) . reduce ( function ( acc , key ) {
57
71
if ( l . hasOwnProperty ( key ) ) {
72
+ if ( Array . isArray ( l [ key ] ) && Array . isArray ( r [ key ] ) ) {
73
+ //const allKeys = _.merge(l[key], r[key]) ?? []
74
+ var newFields = _lodash2 . default . uniq ( _lodash2 . default . difference ( r [ key ] , l [ key ] ) ) ;
75
+ if ( newFields . length === 0 ) {
76
+ return acc ;
77
+ }
78
+ var newFieldsIndex = _lodash2 . default . map ( newFields , function ( o ) {
79
+ return {
80
+ content : o ,
81
+ index : [ ]
82
+ } ;
83
+ } ) ;
84
+
85
+ var _loop = function _loop ( i ) {
86
+ var index = _lodash2 . default . findIndex ( newFields , function ( o ) {
87
+ return _lodash2 . default . isEqual ( o , r [ key ] [ i ] ) ;
88
+ } ) ;
89
+ if ( index !== - 1 ) {
90
+ newFieldsIndex [ index ] . index . push ( i ) ;
91
+ }
92
+ } ;
93
+
94
+ for ( var i = 0 ; i < r [ key ] . length ; i ++ ) {
95
+ _loop ( i ) ;
96
+ }
97
+ return _extends ( { } , acc , _defineProperty ( { } , key , { after : newFieldsIndex } ) ) ;
98
+ }
58
99
var difference = addedDiff ( l [ key ] , r [ key ] ) ;
59
100
60
101
if ( ( 0 , _utils . isObject ) ( difference ) && ( 0 , _utils . isEmpty ) ( difference ) ) return acc ;
61
102
62
103
return _extends ( { } , acc , _defineProperty ( { } , key , difference ) ) ;
63
104
}
105
+ if ( _typeof ( r [ key ] ) === "object" && l [ key ] === undefined ) {
106
+ if ( Array . isArray ( r [ key ] ) ) {
107
+ return _extends ( { } , acc , _defineProperty ( { } , key , { after : r [ key ] } ) ) ;
108
+ }
109
+ var _difference = addedDiff ( { } , r [ key ] ) ;
110
+ if ( ( 0 , _utils . isObject ) ( _difference ) && ( 0 , _utils . isEmpty ) ( _difference ) ) return acc ;
111
+
112
+ return _extends ( { } , acc , _defineProperty ( { } , key , _difference ) ) ;
113
+ }
64
114
65
115
return _extends ( { } , acc , _defineProperty ( { } , key , { after : r [ key ] } ) ) ;
66
116
} , { } ) ;
67
117
} ;
68
118
69
119
exports . default = addedDiff ;
70
- module . exports = exports [ ' default' ] ;
120
+ module . exports = exports [ " default" ] ;
71
121
} ) ;
0 commit comments