@destyler/carousel 0.2.6 → 0.2.7

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 CHANGED
@@ -1,10 +1,9 @@
1
- import * as _destyler_anatomy0 from "@destyler/anatomy";
2
1
  import * as _destyler_xstate0 from "@destyler/xstate";
3
2
  import { AnyEventObject, ContextRef, Machine, XSend, XState } from "@destyler/xstate";
4
3
  import { CommonProperties, DirectionProperty, NormalizeProps, Orientation, OrientationProperty, PropTypes, RequiredBy } from "@destyler/types";
5
4
 
6
5
  //#region src/anatomy.d.ts
7
- declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "itemGroup" | "item" | "control" | "nextTrigger" | "prevTrigger" | "indicatorGroup" | "indicator" | "autoplayTrigger">;
6
+ declare const anatomy: any;
8
7
  //#endregion
9
8
  //#region src/types.d.ts
10
9
  interface PageChangeDetails {
@@ -79,9 +78,14 @@ interface PublicContext extends DirectionProperty, CommonProperties, Orientation
79
78
  */
80
79
  loop: boolean;
81
80
  /**
82
- * The index of the active page.
81
+ * The controlled index of the active page.
83
82
  */
84
- page: number;
83
+ page?: number | undefined;
84
+ /**
85
+ * The initial active page when it is not controlled.
86
+ * Prefer this over seeding with `page` for uncontrolled usage.
87
+ */
88
+ defaultPage?: number | undefined;
85
89
  /**
86
90
  * The amount of space between items.
87
91
  * @default "0px"
@@ -242,8 +246,8 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
242
246
  declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
243
247
  //#endregion
244
248
  //#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">];
249
+ declare const props: ("autoplay" | "id" | "ids" | "translations" | "slidesPerPage" | "slidesPerMove" | "allowMouseDrag" | "loop" | "page" | "defaultPage" | "spacing" | "padding" | "onPageChange" | "inViewThreshold" | "snapType" | "slideCount" | "onDragStatusChange" | "onAutoplayStatusChange" | "dir" | "getRootNode" | "orientation")[];
250
+ 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
251
  declare const indicatorProps: (keyof IndicatorProps)[];
248
252
  declare const splitIndicatorProps: <Props extends IndicatorProps>(props: Props) => [IndicatorProps, Omit<Props, keyof IndicatorProps>];
249
253
  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",
@@ -719,6 +733,7 @@ function machine(userContext) {
719
733
  //#endregion
720
734
  //#region src/props.ts
721
735
  const props = createProps()([
736
+ "defaultPage",
722
737
  "dir",
723
738
  "getRootNode",
724
739
  "id",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@destyler/carousel",
3
3
  "type": "module",
4
- "version": "0.2.6",
4
+ "version": "0.2.7",
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.6",
26
- "@destyler/dom": "0.2.6",
27
- "@destyler/types": "0.2.6",
28
- "@destyler/utils": "0.2.6",
29
- "@destyler/scroll-snap": "0.2.6",
30
- "@destyler/xstate": "0.2.6"
25
+ "@destyler/anatomy": "0.2.7",
26
+ "@destyler/scroll-snap": "0.2.7",
27
+ "@destyler/dom": "0.2.7",
28
+ "@destyler/types": "0.2.7",
29
+ "@destyler/xstate": "0.2.7",
30
+ "@destyler/utils": "0.2.7"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"