1
- import { ResizeObserver } from 'vue-resize' ;
1
+ import { ResizeObserver as ResizeObserver$1 } from 'vue-resize' ;
2
2
import { ObserveVisibility } from 'vue-observe-visibility' ;
3
3
import ScrollParent from 'scrollparent' ;
4
4
@@ -71,6 +71,78 @@ function _objectSpread2(target) {
71
71
return target ;
72
72
}
73
73
74
+ function _unsupportedIterableToArray ( o , minLen ) {
75
+ if ( ! o ) return ;
76
+ if ( typeof o === "string" ) return _arrayLikeToArray ( o , minLen ) ;
77
+ var n = Object . prototype . toString . call ( o ) . slice ( 8 , - 1 ) ;
78
+ if ( n === "Object" && o . constructor ) n = o . constructor . name ;
79
+ if ( n === "Map" || n === "Set" ) return Array . from ( n ) ;
80
+ if ( n === "Arguments" || / ^ (?: U i | I ) n t (?: 8 | 1 6 | 3 2 ) (?: C l a m p e d ) ? A r r a y $ / . test ( n ) ) return _arrayLikeToArray ( o , minLen ) ;
81
+ }
82
+
83
+ function _arrayLikeToArray ( arr , len ) {
84
+ if ( len == null || len > arr . length ) len = arr . length ;
85
+
86
+ for ( var i = 0 , arr2 = new Array ( len ) ; i < len ; i ++ ) arr2 [ i ] = arr [ i ] ;
87
+
88
+ return arr2 ;
89
+ }
90
+
91
+ function _createForOfIteratorHelper ( o ) {
92
+ if ( typeof Symbol === "undefined" || o [ Symbol . iterator ] == null ) {
93
+ if ( Array . isArray ( o ) || ( o = _unsupportedIterableToArray ( o ) ) ) {
94
+ var i = 0 ;
95
+
96
+ var F = function ( ) { } ;
97
+
98
+ return {
99
+ s : F ,
100
+ n : function ( ) {
101
+ if ( i >= o . length ) return {
102
+ done : true
103
+ } ;
104
+ return {
105
+ done : false ,
106
+ value : o [ i ++ ]
107
+ } ;
108
+ } ,
109
+ e : function ( e ) {
110
+ throw e ;
111
+ } ,
112
+ f : F
113
+ } ;
114
+ }
115
+
116
+ throw new TypeError ( "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." ) ;
117
+ }
118
+
119
+ var it ,
120
+ normalCompletion = true ,
121
+ didErr = false ,
122
+ err ;
123
+ return {
124
+ s : function ( ) {
125
+ it = o [ Symbol . iterator ] ( ) ;
126
+ } ,
127
+ n : function ( ) {
128
+ var step = it . next ( ) ;
129
+ normalCompletion = step . done ;
130
+ return step ;
131
+ } ,
132
+ e : function ( e ) {
133
+ didErr = true ;
134
+ err = e ;
135
+ } ,
136
+ f : function ( ) {
137
+ try {
138
+ if ( ! normalCompletion && it . return != null ) it . return ( ) ;
139
+ } finally {
140
+ if ( didErr ) throw err ;
141
+ }
142
+ }
143
+ } ;
144
+ }
145
+
74
146
var props = {
75
147
items : {
76
148
type : Array ,
@@ -111,7 +183,7 @@ var uid = 0;
111
183
var script = {
112
184
name : 'RecycleScroller' ,
113
185
components : {
114
- ResizeObserver : ResizeObserver
186
+ ResizeObserver : ResizeObserver$1
115
187
} ,
116
188
directives : {
117
189
ObserveVisibility : ObserveVisibility
@@ -876,9 +948,36 @@ var script$1 = {
876
948
} ,
877
949
inheritAttrs : false ,
878
950
provide : function provide ( ) {
951
+ if ( typeof ResizeObserver !== 'undefined' ) {
952
+ this . $_resizeObserver = new ResizeObserver ( function ( entries ) {
953
+ var _iterator = _createForOfIteratorHelper ( entries ) ,
954
+ _step ;
955
+
956
+ try {
957
+ for ( _iterator . s ( ) ; ! ( _step = _iterator . n ( ) ) . done ; ) {
958
+ var entry = _step . value ;
959
+
960
+ if ( entry . target ) {
961
+ var event = new CustomEvent ( 'resize' , {
962
+ detail : {
963
+ contentRect : entry . contentRect
964
+ }
965
+ } ) ;
966
+ entry . target . dispatchEvent ( event ) ;
967
+ }
968
+ }
969
+ } catch ( err ) {
970
+ _iterator . e ( err ) ;
971
+ } finally {
972
+ _iterator . f ( ) ;
973
+ }
974
+ } ) ;
975
+ }
976
+
879
977
return {
880
978
vscrollData : this . vscrollData ,
881
- vscrollParent : this
979
+ vscrollParent : this ,
980
+ vscrollResizeObserver : this . $_resizeObserver
882
981
} ;
883
982
} ,
884
983
props : _objectSpread2 ( { } , props , {
@@ -913,10 +1012,6 @@ var script$1 = {
913
1012
var size = sizes [ id ] ;
914
1013
915
1014
if ( typeof size === 'undefined' && ! this . $_undefinedMap [ id ] ) {
916
- // eslint-disable-next-line vue/no-side-effects-in-computed-properties
917
- this . $_undefinedSizes ++ ; // eslint-disable-next-line vue/no-side-effects-in-computed-properties
918
-
919
- this . $_undefinedMap [ id ] = true ;
920
1015
size = 0 ;
921
1016
}
922
1017
@@ -1010,15 +1105,19 @@ var script$1 = {
1010
1105
var el = this . $el ; // Item is inserted to the DOM
1011
1106
1012
1107
this . $nextTick ( function ( ) {
1013
- // Item sizes are computed
1108
+ el . scrollTop = Number . MAX_SAFE_INTEGER ; // Item sizes are computed
1109
+
1014
1110
var cb = function cb ( ) {
1015
- el . scrollTop = el . scrollHeight ;
1111
+ el . scrollTop = Number . MAX_SAFE_INTEGER ;
1112
+ requestAnimationFrame ( function ( ) {
1113
+ el . scrollTop = Number . MAX_SAFE_INTEGER ;
1016
1114
1017
- if ( _this . $_undefinedSizes === 0 ) {
1018
- _this . $_scrollingToBottom = false ;
1019
- } else {
1020
- requestAnimationFrame ( cb ) ;
1021
- }
1115
+ if ( _this . $_undefinedSizes === 0 ) {
1116
+ _this . $_scrollingToBottom = false ;
1117
+ } else {
1118
+ requestAnimationFrame ( cb ) ;
1119
+ }
1120
+ } ) ;
1022
1121
} ;
1023
1122
1024
1123
requestAnimationFrame ( cb ) ;
@@ -1120,7 +1219,7 @@ __vue_render__$1._withStripped = true;
1120
1219
1121
1220
var script$2 = {
1122
1221
name : 'DynamicScrollerItem' ,
1123
- inject : [ 'vscrollData' , 'vscrollParent' ] ,
1222
+ inject : [ 'vscrollData' , 'vscrollParent' , 'vscrollResizeObserver' ] ,
1124
1223
props : {
1125
1224
item : {
1126
1225
required : true
@@ -1166,7 +1265,27 @@ var script$2 = {
1166
1265
}
1167
1266
} ,
1168
1267
active : function active ( value ) {
1169
- if ( value && this . $_pendingVScrollUpdate === this . id ) {
1268
+ if ( ! this . size ) {
1269
+ if ( value ) {
1270
+ if ( ! this . vscrollParent . $_undefinedMap [ this . id ] ) {
1271
+ this . vscrollParent . $_undefinedSizes ++ ;
1272
+ this . vscrollParent . $_undefinedMap [ this . id ] = true ;
1273
+ }
1274
+ } else {
1275
+ if ( this . vscrollParent . $_undefinedMap [ this . id ] ) {
1276
+ this . vscrollParent . $_undefinedSizes -- ;
1277
+ this . vscrollParent . $_undefinedMap [ this . id ] = false ;
1278
+ }
1279
+ }
1280
+ }
1281
+
1282
+ if ( this . vscrollResizeObserver ) {
1283
+ if ( value ) {
1284
+ this . observeSize ( ) ;
1285
+ } else {
1286
+ this . unobserveSize ( ) ;
1287
+ }
1288
+ } else if ( value && this . $_pendingVScrollUpdate === this . id ) {
1170
1289
this . updateSize ( ) ;
1171
1290
}
1172
1291
}
@@ -1178,27 +1297,31 @@ var script$2 = {
1178
1297
this . $_forceNextVScrollUpdate = null ;
1179
1298
this . updateWatchData ( ) ;
1180
1299
1181
- var _loop = function _loop ( k ) {
1182
- _this . $watch ( function ( ) {
1183
- return _this . sizeDependencies [ k ] ;
1184
- } , _this . onDataUpdate ) ;
1185
- } ;
1300
+ if ( ! this . vscrollResizeObserver ) {
1301
+ var _loop = function _loop ( k ) {
1302
+ _this . $watch ( function ( ) {
1303
+ return _this . sizeDependencies [ k ] ;
1304
+ } , _this . onDataUpdate ) ;
1305
+ } ;
1186
1306
1187
- for ( var k in this . sizeDependencies ) {
1188
- _loop ( k ) ;
1189
- }
1307
+ for ( var k in this . sizeDependencies ) {
1308
+ _loop ( k ) ;
1309
+ }
1190
1310
1191
- this . vscrollParent . $on ( 'vscroll:update' , this . onVscrollUpdate ) ;
1192
- this . vscrollParent . $on ( 'vscroll:update-size' , this . onVscrollUpdateSize ) ;
1311
+ this . vscrollParent . $on ( 'vscroll:update' , this . onVscrollUpdate ) ;
1312
+ this . vscrollParent . $on ( 'vscroll:update-size' , this . onVscrollUpdateSize ) ;
1313
+ }
1193
1314
} ,
1194
1315
mounted : function mounted ( ) {
1195
1316
if ( this . vscrollData . active ) {
1196
1317
this . updateSize ( ) ;
1318
+ this . observeSize ( ) ;
1197
1319
}
1198
1320
} ,
1199
1321
beforeDestroy : function beforeDestroy ( ) {
1200
1322
this . vscrollParent . $off ( 'vscroll:update' , this . onVscrollUpdate ) ;
1201
1323
this . vscrollParent . $off ( 'vscroll:update-size' , this . onVscrollUpdateSize ) ;
1324
+ this . unobserveSize ( ) ;
1202
1325
} ,
1203
1326
methods : {
1204
1327
updateSize : function updateSize ( ) {
@@ -1216,9 +1339,6 @@ var script$2 = {
1216
1339
this . $_forceNextVScrollUpdate = this . id ;
1217
1340
}
1218
1341
} ,
1219
- getBounds : function getBounds ( ) {
1220
- return this . $el . getBoundingClientRect ( ) ;
1221
- } ,
1222
1342
updateWatchData : function updateWatchData ( ) {
1223
1343
var _this2 = this ;
1224
1344
@@ -1252,26 +1372,42 @@ var script$2 = {
1252
1372
1253
1373
this . $nextTick ( function ( ) {
1254
1374
if ( _this3 . id === id ) {
1255
- var bounds = _this3 . getBounds ( ) ;
1256
-
1257
- var size = Math . round ( _this3 . vscrollParent . direction === 'vertical' ? bounds . height : bounds . width ) ;
1258
-
1259
- if ( size && _this3 . size !== size ) {
1260
- if ( _this3 . vscrollParent . $_undefinedMap [ id ] ) {
1261
- _this3 . vscrollParent . $_undefinedSizes -- ;
1262
- _this3 . vscrollParent . $_undefinedMap [ id ] = undefined ;
1263
- }
1264
-
1265
- _this3 . $set ( _this3 . vscrollData . sizes , _this3 . id , size ) ;
1266
-
1267
- _this3 . $set ( _this3 . vscrollData . validSizes , _this3 . id , true ) ;
1375
+ var width = _this3 . $el . offsetWidth ;
1376
+ var height = _this3 . $el . offsetHeight ;
1268
1377
1269
- if ( _this3 . emitResize ) _this3 . $emit ( 'resize' , _this3 . id ) ;
1270
- }
1378
+ _this3 . applySize ( width , height ) ;
1271
1379
}
1272
1380
1273
1381
_this3 . $_pendingSizeUpdate = null ;
1274
1382
} ) ;
1383
+ } ,
1384
+ applySize : function applySize ( width , height ) {
1385
+ var size = Math . round ( this . vscrollParent . direction === 'vertical' ? height : width ) ;
1386
+
1387
+ if ( size && this . size !== size ) {
1388
+ if ( this . vscrollParent . $_undefinedMap [ this . id ] ) {
1389
+ this . vscrollParent . $_undefinedSizes -- ;
1390
+ this . vscrollParent . $_undefinedMap [ this . id ] = undefined ;
1391
+ }
1392
+
1393
+ this . $set ( this . vscrollData . sizes , this . id , size ) ;
1394
+ this . $set ( this . vscrollData . validSizes , this . id , true ) ;
1395
+ if ( this . emitResize ) this . $emit ( 'resize' , this . id ) ;
1396
+ }
1397
+ } ,
1398
+ observeSize : function observeSize ( ) {
1399
+ this . vscrollResizeObserver . observe ( this . $el . parentNode ) ;
1400
+ this . $el . parentNode . addEventListener ( 'resize' , this . onResize ) ;
1401
+ } ,
1402
+ unobserveSize : function unobserveSize ( ) {
1403
+ this . vscrollResizeObserver . unobserve ( this . $el . parentNode ) ;
1404
+ this . $el . parentNode . removeEventListener ( 'resize' , this . onResize ) ;
1405
+ } ,
1406
+ onResize : function onResize ( event ) {
1407
+ var _event$detail$content = event . detail . contentRect ,
1408
+ width = _event$detail$content . width ,
1409
+ height = _event$detail$content . height ;
1410
+ this . applySize ( width , height ) ;
1275
1411
}
1276
1412
} ,
1277
1413
render : function render ( h ) {
@@ -9864,7 +10000,7 @@ function registerComponents(Vue, prefix) {
9864
10000
9865
10001
var plugin = {
9866
10002
// eslint-disable-next-line no-undef
9867
- version : "1.0.0-rc.2 " ,
10003
+ version : "1.0.0" ,
9868
10004
install : function install ( Vue , options ) {
9869
10005
var finalOptions = Object . assign ( { } , {
9870
10006
installComponents : true ,
0 commit comments