@destyler/carousel 0.2.6 → 0.2.9
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.d.mts +9 -4
- package/dist/index.mjs +23 -4
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -79,9 +79,14 @@ interface PublicContext extends DirectionProperty, CommonProperties, Orientation
|
|
|
79
79
|
*/
|
|
80
80
|
loop: boolean;
|
|
81
81
|
/**
|
|
82
|
-
* The index of the active page.
|
|
82
|
+
* The controlled index of the active page.
|
|
83
83
|
*/
|
|
84
|
-
page
|
|
84
|
+
page?: number | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The initial active page when it is not controlled.
|
|
87
|
+
* Prefer this over seeding with `page` for uncontrolled usage.
|
|
88
|
+
*/
|
|
89
|
+
defaultPage?: number | undefined;
|
|
85
90
|
/**
|
|
86
91
|
* The amount of space between items.
|
|
87
92
|
* @default "0px"
|
|
@@ -242,8 +247,8 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
|
|
|
242
247
|
declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
|
|
243
248
|
//#endregion
|
|
244
249
|
//#region src/props.d.ts
|
|
245
|
-
declare const props: ("autoplay" | "id" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "dir" | "getRootNode" | "orientation")[];
|
|
246
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "autoplay" | "id" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "dir" | "getRootNode" | "orientation">];
|
|
250
|
+
declare const props: ("autoplay" | "id" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "defaultPage" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "dir" | "getRootNode" | "orientation")[];
|
|
251
|
+
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "autoplay" | "id" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "defaultPage" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "dir" | "getRootNode" | "orientation">];
|
|
247
252
|
declare const indicatorProps: (keyof IndicatorProps)[];
|
|
248
253
|
declare const splitIndicatorProps: <Props extends IndicatorProps>(props: Props) => [IndicatorProps, Omit<Props, keyof IndicatorProps>];
|
|
249
254
|
declare const itemProps: (keyof ItemProps)[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createAnatomy } from "@destyler/anatomy";
|
|
2
2
|
import { addDomEvent, ariaAttr, createScope, dataAttr, getEventKey, getEventTarget, getTabbables, isFocusable, queryAll, raf, trackPointerMove } from "@destyler/dom";
|
|
3
3
|
import { findSnapPoint, getScrollSnapPositions } from "@destyler/scroll-snap";
|
|
4
|
-
import { add, compact, createSplitProps, isEqual, isObject, nextIndex, prevIndex, remove, uniq } from "@destyler/utils";
|
|
4
|
+
import { add, compact, createSplitProps, isControlled, isEqual, isObject, isPropUserProvided, nextIndex, prevIndex, remove, resolveControllableProp, uniq, withControllableProvided } from "@destyler/utils";
|
|
5
5
|
import { createMachine, ref } from "@destyler/xstate";
|
|
6
6
|
import { createProps } from "@destyler/types";
|
|
7
7
|
|
|
@@ -321,6 +321,13 @@ const invoke = { pageChange: (ctx) => {
|
|
|
321
321
|
const set = { page: (ctx, value) => {
|
|
322
322
|
const page = clamp(value, 0, ctx.pageSnapPoints.length - 1);
|
|
323
323
|
if (isEqual(ctx.page, page)) return;
|
|
324
|
+
if (isControlled(ctx, "page")) {
|
|
325
|
+
ctx.onPageChange?.({
|
|
326
|
+
page,
|
|
327
|
+
pageSnapPoint: ctx.pageSnapPoints[page]
|
|
328
|
+
});
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
324
331
|
ctx.page = page;
|
|
325
332
|
invoke.pageChange(ctx);
|
|
326
333
|
} };
|
|
@@ -353,7 +360,13 @@ function ensureItemGroupEl(ctx, fn) {
|
|
|
353
360
|
};
|
|
354
361
|
}
|
|
355
362
|
function machine(userContext) {
|
|
356
|
-
const ctx = compact(userContext);
|
|
363
|
+
const ctx = compact(withControllableProvided(userContext, ["page"]));
|
|
364
|
+
const { initial: initialPage } = resolveControllableProp({
|
|
365
|
+
value: ctx.page,
|
|
366
|
+
defaultValue: ctx.defaultPage,
|
|
367
|
+
valueProvided: isPropUserProvided(ctx, "page"),
|
|
368
|
+
fallback: 0
|
|
369
|
+
});
|
|
357
370
|
return createMachine({
|
|
358
371
|
id: "carousel",
|
|
359
372
|
initial: ctx.autoplay ? "autoplay" : "idle",
|
|
@@ -370,6 +383,7 @@ function machine(userContext) {
|
|
|
370
383
|
allowMouseDrag: false,
|
|
371
384
|
inViewThreshold: .6,
|
|
372
385
|
...ctx,
|
|
386
|
+
page: initialPage,
|
|
373
387
|
timeoutRef: ref({ current: void 0 }),
|
|
374
388
|
translations: {
|
|
375
389
|
nextTrigger: "Next slide",
|
|
@@ -393,7 +407,11 @@ function machine(userContext) {
|
|
|
393
407
|
watch: {
|
|
394
408
|
slidesPerPage: ["setSnapPoints"],
|
|
395
409
|
slidesPerMove: ["setSnapPoints"],
|
|
396
|
-
page: [
|
|
410
|
+
page: [
|
|
411
|
+
"clearScrollEndTimer",
|
|
412
|
+
"scrollToPage",
|
|
413
|
+
"focusIndicatorEl"
|
|
414
|
+
],
|
|
397
415
|
orientation: ["setSnapPoints", "scrollToPage"]
|
|
398
416
|
},
|
|
399
417
|
on: {
|
|
@@ -589,7 +607,7 @@ function machine(userContext) {
|
|
|
589
607
|
},
|
|
590
608
|
scrollToPage(ctx$1, evt) {
|
|
591
609
|
const behavior = evt.instant ? "instant" : "smooth";
|
|
592
|
-
const index = clamp(
|
|
610
|
+
const index = clamp(ctx$1.page ?? 0, 0, ctx$1.pageSnapPoints.length - 1);
|
|
593
611
|
const el = dom.getItemGroupEl(ctx$1);
|
|
594
612
|
const axis = ctx$1.isHorizontal ? "left" : "top";
|
|
595
613
|
el.scrollTo({
|
|
@@ -719,6 +737,7 @@ function machine(userContext) {
|
|
|
719
737
|
//#endregion
|
|
720
738
|
//#region src/props.ts
|
|
721
739
|
const props = createProps()([
|
|
740
|
+
"defaultPage",
|
|
722
741
|
"dir",
|
|
723
742
|
"getRootNode",
|
|
724
743
|
"id",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/carousel",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9",
|
|
5
5
|
"description": "an interactive slideshow component for cycling through elements.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/anatomy": "0.2.
|
|
26
|
-
"@destyler/dom": "0.2.
|
|
27
|
-
"@destyler/
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/
|
|
30
|
-
"@destyler/xstate": "0.2.
|
|
25
|
+
"@destyler/anatomy": "0.2.9",
|
|
26
|
+
"@destyler/dom": "0.2.9",
|
|
27
|
+
"@destyler/scroll-snap": "0.2.9",
|
|
28
|
+
"@destyler/types": "0.2.9",
|
|
29
|
+
"@destyler/utils": "0.2.9",
|
|
30
|
+
"@destyler/xstate": "0.2.9"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|