@ship-it-ui/ui 0.0.11 → 0.0.12
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/dist/index.cjs +14 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -13
- package/dist/index.d.ts +23 -13
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3257,7 +3257,8 @@ var Carousel = (0, import_react52.forwardRef)(function Carousel2({
|
|
|
3257
3257
|
...props
|
|
3258
3258
|
}, ref) {
|
|
3259
3259
|
const N = items.length;
|
|
3260
|
-
const
|
|
3260
|
+
const loopMode = !loop ? null : loop === true ? "circular" : loop;
|
|
3261
|
+
const isLooping = loopMode !== null && N > 1;
|
|
3261
3262
|
const [active, setActive] = useControllableState({
|
|
3262
3263
|
value: indexProp,
|
|
3263
3264
|
defaultValue: defaultIndex ?? 0,
|
|
@@ -3265,6 +3266,7 @@ var Carousel = (0, import_react52.forwardRef)(function Carousel2({
|
|
|
3265
3266
|
});
|
|
3266
3267
|
const viewportRef = (0, import_react52.useRef)(null);
|
|
3267
3268
|
const internalScrollRef = (0, import_react52.useRef)(false);
|
|
3269
|
+
const wrapInProgressRef = (0, import_react52.useRef)(false);
|
|
3268
3270
|
const activeIdx = active ?? 0;
|
|
3269
3271
|
const domIndexFor = (0, import_react52.useCallback)((real) => isLooping ? real + 1 : real, [isLooping]);
|
|
3270
3272
|
const goTo = (0, import_react52.useCallback)(
|
|
@@ -3273,14 +3275,18 @@ var Carousel = (0, import_react52.forwardRef)(function Carousel2({
|
|
|
3273
3275
|
setActive(next);
|
|
3274
3276
|
const node = viewportRef.current;
|
|
3275
3277
|
if (node) {
|
|
3276
|
-
const
|
|
3278
|
+
const isNextWrap = loopMode === "circular" && activeIdx === N - 1 && i === activeIdx + 1;
|
|
3279
|
+
const isPrevWrap = loopMode === "circular" && activeIdx === 0 && i === activeIdx - 1;
|
|
3280
|
+
const targetDom = isNextWrap ? N + 1 : isPrevWrap ? 0 : domIndexFor(next);
|
|
3281
|
+
const slide = node.children[targetDom];
|
|
3277
3282
|
if (slide) {
|
|
3278
3283
|
internalScrollRef.current = true;
|
|
3284
|
+
if (isNextWrap || isPrevWrap) wrapInProgressRef.current = true;
|
|
3279
3285
|
slide.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "start" });
|
|
3280
3286
|
}
|
|
3281
3287
|
}
|
|
3282
3288
|
},
|
|
3283
|
-
[N, isLooping, domIndexFor, setActive]
|
|
3289
|
+
[N, isLooping, loopMode, domIndexFor, setActive, activeIdx]
|
|
3284
3290
|
);
|
|
3285
3291
|
(0, import_react52.useEffect)(() => {
|
|
3286
3292
|
const node = viewportRef.current;
|
|
@@ -3294,23 +3300,28 @@ var Carousel = (0, import_react52.forwardRef)(function Carousel2({
|
|
|
3294
3300
|
return;
|
|
3295
3301
|
}
|
|
3296
3302
|
if (domIdx === 0) {
|
|
3303
|
+
if (wrapInProgressRef.current && node.scrollLeft > 1) return;
|
|
3297
3304
|
const realTwin = node.children[N];
|
|
3298
3305
|
if (realTwin) {
|
|
3299
3306
|
internalScrollRef.current = true;
|
|
3300
3307
|
realTwin.scrollIntoView({ behavior: "instant", block: "nearest", inline: "start" });
|
|
3301
3308
|
}
|
|
3302
3309
|
if (activeIdx !== N - 1) setActive(N - 1);
|
|
3310
|
+
wrapInProgressRef.current = false;
|
|
3303
3311
|
return;
|
|
3304
3312
|
}
|
|
3305
3313
|
if (domIdx === N + 1) {
|
|
3314
|
+
if (wrapInProgressRef.current && node.scrollLeft < (N + 1) * width - 1) return;
|
|
3306
3315
|
const realTwin = node.children[1];
|
|
3307
3316
|
if (realTwin) {
|
|
3308
3317
|
internalScrollRef.current = true;
|
|
3309
3318
|
realTwin.scrollIntoView({ behavior: "instant", block: "nearest", inline: "start" });
|
|
3310
3319
|
}
|
|
3311
3320
|
if (activeIdx !== 0) setActive(0);
|
|
3321
|
+
wrapInProgressRef.current = false;
|
|
3312
3322
|
return;
|
|
3313
3323
|
}
|
|
3324
|
+
if (wrapInProgressRef.current) return;
|
|
3314
3325
|
const realIdx = domIdx - 1;
|
|
3315
3326
|
if (realIdx !== activeIdx) setActive(realIdx);
|
|
3316
3327
|
};
|