Skip to content

Commit f91fe0b

Browse files
committed
chore: v1.0.0
1 parent 5fb219e commit f91fe0b

File tree

4 files changed

+366
-94
lines changed

4 files changed

+366
-94
lines changed

dist/vue-virtual-scroller.esm.js

Lines changed: 181 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ResizeObserver } from 'vue-resize';
1+
import { ResizeObserver as ResizeObserver$1 } from 'vue-resize';
22
import { ObserveVisibility } from 'vue-observe-visibility';
33
import ScrollParent from 'scrollparent';
44

@@ -71,6 +71,78 @@ function _objectSpread2(target) {
7171
return target;
7272
}
7373

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" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.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+
74146
var props = {
75147
items: {
76148
type: Array,
@@ -111,7 +183,7 @@ var uid = 0;
111183
var script = {
112184
name: 'RecycleScroller',
113185
components: {
114-
ResizeObserver: ResizeObserver
186+
ResizeObserver: ResizeObserver$1
115187
},
116188
directives: {
117189
ObserveVisibility: ObserveVisibility
@@ -876,9 +948,36 @@ var script$1 = {
876948
},
877949
inheritAttrs: false,
878950
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+
879977
return {
880978
vscrollData: this.vscrollData,
881-
vscrollParent: this
979+
vscrollParent: this,
980+
vscrollResizeObserver: this.$_resizeObserver
882981
};
883982
},
884983
props: _objectSpread2({}, props, {
@@ -913,10 +1012,6 @@ var script$1 = {
9131012
var size = sizes[id];
9141013

9151014
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;
9201015
size = 0;
9211016
}
9221017

@@ -1010,15 +1105,19 @@ var script$1 = {
10101105
var el = this.$el; // Item is inserted to the DOM
10111106

10121107
this.$nextTick(function () {
1013-
// Item sizes are computed
1108+
el.scrollTop = Number.MAX_SAFE_INTEGER; // Item sizes are computed
1109+
10141110
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;
10161114

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+
});
10221121
};
10231122

10241123
requestAnimationFrame(cb);
@@ -1120,7 +1219,7 @@ __vue_render__$1._withStripped = true;
11201219

11211220
var script$2 = {
11221221
name: 'DynamicScrollerItem',
1123-
inject: ['vscrollData', 'vscrollParent'],
1222+
inject: ['vscrollData', 'vscrollParent', 'vscrollResizeObserver'],
11241223
props: {
11251224
item: {
11261225
required: true
@@ -1166,7 +1265,27 @@ var script$2 = {
11661265
}
11671266
},
11681267
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) {
11701289
this.updateSize();
11711290
}
11721291
}
@@ -1178,27 +1297,31 @@ var script$2 = {
11781297
this.$_forceNextVScrollUpdate = null;
11791298
this.updateWatchData();
11801299

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+
};
11861306

1187-
for (var k in this.sizeDependencies) {
1188-
_loop(k);
1189-
}
1307+
for (var k in this.sizeDependencies) {
1308+
_loop(k);
1309+
}
11901310

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+
}
11931314
},
11941315
mounted: function mounted() {
11951316
if (this.vscrollData.active) {
11961317
this.updateSize();
1318+
this.observeSize();
11971319
}
11981320
},
11991321
beforeDestroy: function beforeDestroy() {
12001322
this.vscrollParent.$off('vscroll:update', this.onVscrollUpdate);
12011323
this.vscrollParent.$off('vscroll:update-size', this.onVscrollUpdateSize);
1324+
this.unobserveSize();
12021325
},
12031326
methods: {
12041327
updateSize: function updateSize() {
@@ -1216,9 +1339,6 @@ var script$2 = {
12161339
this.$_forceNextVScrollUpdate = this.id;
12171340
}
12181341
},
1219-
getBounds: function getBounds() {
1220-
return this.$el.getBoundingClientRect();
1221-
},
12221342
updateWatchData: function updateWatchData() {
12231343
var _this2 = this;
12241344

@@ -1252,26 +1372,42 @@ var script$2 = {
12521372

12531373
this.$nextTick(function () {
12541374
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;
12681377

1269-
if (_this3.emitResize) _this3.$emit('resize', _this3.id);
1270-
}
1378+
_this3.applySize(width, height);
12711379
}
12721380

12731381
_this3.$_pendingSizeUpdate = null;
12741382
});
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);
12751411
}
12761412
},
12771413
render: function render(h) {
@@ -9864,7 +10000,7 @@ function registerComponents(Vue, prefix) {
986410000

986510001
var plugin = {
986610002
// eslint-disable-next-line no-undef
9867-
version: "1.0.0-rc.2",
10003+
version: "1.0.0",
986810004
install: function install(Vue, options) {
986910005
var finalOptions = Object.assign({}, {
987010006
installComponents: true,

dist/vue-virtual-scroller.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)