virtua 0.43.4 → 0.43.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -20
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/solid/index.js +1 -1
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.jsx +48 -40
- package/lib/solid/index.jsx.map +1 -1
- package/lib/solid/index.mjs +1 -1
- package/lib/solid/index.mjs.map +1 -1
- package/lib/vue/index.js +1 -1
- package/lib/vue/index.js.map +1 -1
- package/lib/vue/index.mjs +1 -1
- package/lib/vue/index.mjs.map +1 -1
- package/package.json +4 -5
package/lib/solid/index.jsx
CHANGED
|
@@ -28,12 +28,10 @@ const microtask = typeof queueMicrotask === "function"
|
|
|
28
28
|
*/
|
|
29
29
|
const createPromise = () => {
|
|
30
30
|
let resolve;
|
|
31
|
-
|
|
32
|
-
const promise = new Promise((res, rej) => {
|
|
31
|
+
const promise = new Promise((res) => {
|
|
33
32
|
resolve = res;
|
|
34
|
-
reject = rej;
|
|
35
33
|
});
|
|
36
|
-
return [promise, resolve
|
|
34
|
+
return [promise, resolve];
|
|
37
35
|
};
|
|
38
36
|
/**
|
|
39
37
|
* @internal
|
|
@@ -704,7 +702,7 @@ const createScroller = (store, isHorizontal) => {
|
|
|
704
702
|
let viewportElement;
|
|
705
703
|
let scrollObserver;
|
|
706
704
|
let cancelScroll;
|
|
707
|
-
|
|
705
|
+
let initialized = createPromise();
|
|
708
706
|
const scrollOffsetKey = isHorizontal ? "scrollLeft" : "scrollTop";
|
|
709
707
|
const overflowKey = isHorizontal ? "overflowX" : "overflowY";
|
|
710
708
|
// The given offset will be clamped by browser
|
|
@@ -712,7 +710,10 @@ const createScroller = (store, isHorizontal) => {
|
|
|
712
710
|
const scheduleImperativeScroll = async (getTargetOffset, smooth) => {
|
|
713
711
|
// Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.
|
|
714
712
|
// https://github.com/inokawa/virtua/pull/733
|
|
715
|
-
|
|
713
|
+
// https://github.com/inokawa/virtua/pull/750
|
|
714
|
+
if (!(await initialized[0])) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
716
717
|
if (cancelScroll) {
|
|
717
718
|
// Cancel waiting scrollTo
|
|
718
719
|
cancelScroll();
|
|
@@ -720,19 +721,21 @@ const createScroller = (store, isHorizontal) => {
|
|
|
720
721
|
const waitForMeasurement = () => {
|
|
721
722
|
// Wait for the scroll destination items to be measured.
|
|
722
723
|
// The measurement will be done asynchronously and the timing is not predictable so we use promise.
|
|
723
|
-
const [promise, resolve
|
|
724
|
-
cancelScroll =
|
|
724
|
+
const [promise, resolve] = createPromise();
|
|
725
|
+
cancelScroll = () => {
|
|
726
|
+
resolve(false);
|
|
727
|
+
};
|
|
725
728
|
// Resize event may not happen when the window/tab is not visible, or during browser back in Safari.
|
|
726
729
|
// We have to wait for the initial measurement to avoid failing imperative scroll on mount.
|
|
727
730
|
// https://github.com/inokawa/virtua/issues/450
|
|
728
731
|
if (isInitialMeasurementDone(store)) {
|
|
729
|
-
//
|
|
730
|
-
timeout(
|
|
732
|
+
// Cancel when items around scroll destination completely measured
|
|
733
|
+
timeout(cancelScroll, 150);
|
|
731
734
|
}
|
|
732
735
|
return [
|
|
733
736
|
promise,
|
|
734
737
|
store.$subscribe(UPDATE_SIZE_EVENT, () => {
|
|
735
|
-
resolve();
|
|
738
|
+
resolve(true);
|
|
736
739
|
}),
|
|
737
740
|
];
|
|
738
741
|
};
|
|
@@ -744,11 +747,10 @@ const createScroller = (store, isHorizontal) => {
|
|
|
744
747
|
}
|
|
745
748
|
const [promise, unsubscribe] = waitForMeasurement();
|
|
746
749
|
try {
|
|
747
|
-
await promise
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
return;
|
|
750
|
+
if (!(await promise)) {
|
|
751
|
+
// canceled
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
752
754
|
}
|
|
753
755
|
finally {
|
|
754
756
|
unsubscribe();
|
|
@@ -765,11 +767,10 @@ const createScroller = (store, isHorizontal) => {
|
|
|
765
767
|
try {
|
|
766
768
|
viewportElement[scrollOffsetKey] = normalizeOffset(getTargetOffset(), isHorizontal);
|
|
767
769
|
store.$update(ACTION_MANUAL_SCROLL);
|
|
768
|
-
await promise
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return;
|
|
770
|
+
if (!(await promise)) {
|
|
771
|
+
// canceled or finished
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
773
774
|
}
|
|
774
775
|
finally {
|
|
775
776
|
unsubscribe();
|
|
@@ -802,11 +803,13 @@ const createScroller = (store, isHorizontal) => {
|
|
|
802
803
|
viewport[scrollOffsetKey] += jump;
|
|
803
804
|
}
|
|
804
805
|
});
|
|
805
|
-
|
|
806
|
+
initialized[1](true);
|
|
806
807
|
},
|
|
807
808
|
$dispose() {
|
|
808
809
|
scrollObserver && scrollObserver._dispose();
|
|
809
|
-
|
|
810
|
+
initialized[1](false);
|
|
811
|
+
// https://github.com/inokawa/virtua/pull/765
|
|
812
|
+
initialized = createPromise();
|
|
810
813
|
},
|
|
811
814
|
$scrollTo(offset) {
|
|
812
815
|
scheduleImperativeScroll(() => offset);
|
|
@@ -855,7 +858,7 @@ const createWindowScroller = (store, isHorizontal) => {
|
|
|
855
858
|
let containerElement;
|
|
856
859
|
let scrollObserver;
|
|
857
860
|
let cancelScroll;
|
|
858
|
-
|
|
861
|
+
let initialized = createPromise();
|
|
859
862
|
const calcOffsetToViewport = (node, viewport, window, isHorizontal, offset = 0) => {
|
|
860
863
|
// TODO calc offset only when it changes (maybe impossible)
|
|
861
864
|
const offsetKey = isHorizontal ? "offsetLeft" : "offsetTop";
|
|
@@ -872,26 +875,31 @@ const createWindowScroller = (store, isHorizontal) => {
|
|
|
872
875
|
const scheduleImperativeScroll = async (getTargetOffset, smooth) => {
|
|
873
876
|
// Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.
|
|
874
877
|
// https://github.com/inokawa/virtua/pull/733
|
|
875
|
-
|
|
878
|
+
// https://github.com/inokawa/virtua/pull/750
|
|
879
|
+
if (!(await initialized[0])) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
876
882
|
if (cancelScroll) {
|
|
877
883
|
cancelScroll();
|
|
878
884
|
}
|
|
879
885
|
const waitForMeasurement = () => {
|
|
880
886
|
// Wait for the scroll destination items to be measured.
|
|
881
887
|
// The measurement will be done asynchronously and the timing is not predictable so we use promise.
|
|
882
|
-
const [promise, resolve
|
|
883
|
-
cancelScroll =
|
|
888
|
+
const [promise, resolve] = createPromise();
|
|
889
|
+
cancelScroll = () => {
|
|
890
|
+
resolve(false);
|
|
891
|
+
};
|
|
884
892
|
// Resize event may not happen when the window/tab is not visible, or during browser back in Safari.
|
|
885
893
|
// We have to wait for the initial measurement to avoid failing imperative scroll on mount.
|
|
886
894
|
// https://github.com/inokawa/virtua/issues/450
|
|
887
895
|
if (isInitialMeasurementDone(store)) {
|
|
888
|
-
//
|
|
889
|
-
timeout(
|
|
896
|
+
// Cancel when items around scroll destination completely measured
|
|
897
|
+
timeout(cancelScroll, 150);
|
|
890
898
|
}
|
|
891
899
|
return [
|
|
892
900
|
promise,
|
|
893
901
|
store.$subscribe(UPDATE_SIZE_EVENT, () => {
|
|
894
|
-
resolve();
|
|
902
|
+
resolve(true);
|
|
895
903
|
}),
|
|
896
904
|
];
|
|
897
905
|
};
|
|
@@ -904,10 +912,9 @@ const createWindowScroller = (store, isHorizontal) => {
|
|
|
904
912
|
}
|
|
905
913
|
const [promise, unsubscribe] = waitForMeasurement();
|
|
906
914
|
try {
|
|
907
|
-
await promise
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
return;
|
|
915
|
+
if (!(await promise)) {
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
911
918
|
}
|
|
912
919
|
finally {
|
|
913
920
|
unsubscribe();
|
|
@@ -926,10 +933,9 @@ const createWindowScroller = (store, isHorizontal) => {
|
|
|
926
933
|
[isHorizontal ? "left" : "top"]: normalizeOffset(getTargetOffset(), isHorizontal),
|
|
927
934
|
});
|
|
928
935
|
store.$update(ACTION_MANUAL_SCROLL);
|
|
929
|
-
await promise
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
return;
|
|
936
|
+
if (!(await promise)) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
933
939
|
}
|
|
934
940
|
finally {
|
|
935
941
|
unsubscribe();
|
|
@@ -955,12 +961,14 @@ const createWindowScroller = (store, isHorizontal) => {
|
|
|
955
961
|
window.scrollBy(isHorizontal ? jump : 0, isHorizontal ? 0 : jump);
|
|
956
962
|
}
|
|
957
963
|
}, () => calcOffsetToViewport(container, documentBody, window, isHorizontal));
|
|
958
|
-
|
|
964
|
+
initialized[1](true);
|
|
959
965
|
},
|
|
960
966
|
$dispose() {
|
|
961
967
|
scrollObserver && scrollObserver._dispose();
|
|
962
968
|
containerElement = undefined;
|
|
963
|
-
|
|
969
|
+
initialized[1](false);
|
|
970
|
+
// https://github.com/inokawa/virtua/pull/765
|
|
971
|
+
initialized = createPromise();
|
|
964
972
|
},
|
|
965
973
|
$fixScrollJump: () => {
|
|
966
974
|
scrollObserver && scrollObserver._fixScrollJump();
|