@stepperize/core
Advanced tools
+32
-32
@@ -1,2 +0,2 @@ | ||
| type Step<Id extends string = string, Data extends object = {}> = { | ||
| type Step<Id extends string = string, Data extends object = object> = { | ||
| id: Id; | ||
@@ -43,19 +43,27 @@ } & Data; | ||
| }; | ||
| /** Optional payload for navigation (e.g. metadata to merge into transition context without waiting for setState). */ | ||
| type TransitionPayload<Steps extends Step[] = Step[]> = { | ||
| /** Metadata to merge into ctx.metadata for this transition and persist. */ | ||
| metadata?: Partial<Record<Get.Id<Steps>, Metadata>>; | ||
| }; | ||
| type StepperNavigation<Steps extends Step[] = Step[]> = { | ||
| /** | ||
| * Advances to the next step. | ||
| * @returns The next step. | ||
| * @param payload - Optional metadata to merge into transition context (avoids stale metadata in onBeforeTransition). | ||
| * @returns void or Promise when lifecycle hooks run. | ||
| */ | ||
| next: () => void | Promise<void>; | ||
| next: (payload?: TransitionPayload<Steps>) => void | Promise<void>; | ||
| /** | ||
| * Returns to the previous step. | ||
| * @returns The previous step. | ||
| * @param payload - Optional metadata to merge into transition context. | ||
| * @returns void or Promise when lifecycle hooks run. | ||
| */ | ||
| prev: () => void | Promise<void>; | ||
| prev: (payload?: TransitionPayload<Steps>) => void | Promise<void>; | ||
| /** | ||
| * Navigates to a specific step by its ID. | ||
| * @param id - The ID of the step to navigate to. | ||
| * @returns The step to navigate to. | ||
| * @param payload - Optional metadata to merge into transition context. | ||
| * @returns void or Promise when lifecycle hooks run. | ||
| */ | ||
| goTo: (id: Get.Id<Steps>) => void | Promise<void>; | ||
| goTo: (id: Get.Id<Steps>, payload?: TransitionPayload<Steps>) => void | Promise<void>; | ||
| /** | ||
@@ -186,12 +194,16 @@ * Resets the stepper to its initial state. | ||
| }; | ||
| type MaybePromise<T> = T | Promise<T>; | ||
| type StepperLifecycle<Steps extends Step[] = Step[]> = { | ||
| /** | ||
| * Called before a transition occurs. | ||
| * @param cb - The callback to call before the transition occurs. | ||
| * Registers a callback before each transition. Multiple callbacks are supported; returns unsubscribe. | ||
| * @param cb - The callback (return false or Promise<false> to cancel transition). | ||
| * @returns Unsubscribe function. | ||
| */ | ||
| onBeforeTransition: (cb: (ctx: TransitionContext<Steps>) => void | Promise<void | false>) => void; | ||
| onBeforeTransition: (cb: (ctx: TransitionContext<Steps>) => MaybePromise<void | false>) => () => void; | ||
| /** | ||
| * Called after a transition occurs. | ||
| * Registers a callback after each transition. Multiple callbacks are supported; returns unsubscribe. | ||
| * @param cb - The callback. | ||
| * @returns Unsubscribe function. | ||
| */ | ||
| onAfterTransition: (cb: (ctx: TransitionContext<Steps>) => void | Promise<void>) => void; | ||
| onAfterTransition: (cb: (ctx: TransitionContext<Steps>) => MaybePromise<void>) => () => void; | ||
| }; | ||
@@ -299,24 +311,12 @@ type TransitionContext<Steps extends Step[] = Step[]> = { | ||
| getAll(): Steps; | ||
| get: <Id extends Get.Id<Steps>>(id: Id) => Get.StepById<Steps, typeof id>; | ||
| get<Id extends Get.Id<Steps>>(id: Id): Get.StepById<Steps, typeof id>; | ||
| getIndex: <Id extends Get.Id<Steps>>(id: Id) => number; | ||
| getByIndex: <Index extends number>(index: Index) => Steps[Index]; | ||
| getFirst(): { | ||
| id: string; | ||
| }; | ||
| getLast(): { | ||
| id: string; | ||
| }; | ||
| getNext<Id extends Get.Id<Steps>>(id: Id): { | ||
| id: string; | ||
| }; | ||
| getPrev<Id extends Get.Id<Steps>>(id: Id): { | ||
| id: string; | ||
| }; | ||
| getFirst(): Steps[0]; | ||
| getLast(): Steps[number]; | ||
| getNext<Id extends Get.Id<Steps>>(id: Id): Steps[number]; | ||
| getPrev<Id extends Get.Id<Steps>>(id: Id): Steps[number]; | ||
| getNeighbors<Id extends Get.Id<Steps>>(id: Id): { | ||
| prev: { | ||
| id: string; | ||
| } | null; | ||
| next: { | ||
| id: string; | ||
| } | null; | ||
| prev: Steps[number] | null; | ||
| next: Steps[number] | null; | ||
| }; | ||
@@ -354,2 +354,2 @@ }; | ||
| export { Get, type Metadata, type Step, type StepStatus, type Stepper, type StepperFlow, type StepperLookup, type StepperMetadata, type StepperNavigation, type StepperState, type Utils, generateCommonStepperUseFns, generateStepperUtils, getInitialMetadata, getInitialStepIndex, updateStepIndex }; | ||
| export { Get, type Metadata, type Step, type StepStatus, type Stepper, type StepperFlow, type StepperLookup, type StepperMetadata, type StepperNavigation, type StepperState, type TransitionPayload, type Utils, generateCommonStepperUseFns, generateStepperUtils, getInitialMetadata, getInitialStepIndex, updateStepIndex }; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| function e(...e){return{getAll:()=>e,get:n=>e.find(e=>e.id===n),getIndex:n=>e.findIndex(e=>e.id===n),getByIndex:n=>e[n],getFirst:()=>e[0],getLast:()=>e[e.length-1],getNext:n=>e[e.findIndex(e=>e.id===n)+1],getPrev:n=>e[e.findIndex(e=>e.id===n)-1],getNeighbors(n){const t=e.findIndex(e=>e.id===n);return{prev:t>0?e[t-1]:null,next:t<e.length-1?e[t+1]:null}}}}function n(e,n){return Math.max(e.findIndex(e=>e.id===n),0)}function t(e,n){return e.reduce((e,t)=>(e[t.id]=n?.[t.id]??null,e),{})}function i(e,n,t){return{switch(e){const t=e[n.id];return t?.(n)},when(n,i,r){const d=e[t];return(Array.isArray(n)?d.id===n[0]&&n.slice(1).every(Boolean):d.id===n)?i?.(d):r?.(d)},match(n,t){const i=e.find(e=>e.id===n);if(!i)return null;const r=t[n];return r?.(i)??null},is:e=>n.id===e}}var r=(e,n,t)=>{n<0&&d({steps:e,newIndex:n,direction:"next",reason:"it is the first step"}),n>=e.length&&d({steps:e,newIndex:n,direction:"prev",reason:"it is the last step"}),t(n)},d=({steps:e,newIndex:n,direction:t,reason:i})=>{const r=e[n]?.id??`index ${n}`;throw new Error(`Cannot navigate ${t} from step "${r}": ${i}`)};export{i as generateCommonStepperUseFns,e as generateStepperUtils,t as getInitialMetadata,n as getInitialStepIndex,r as updateStepIndex}; | ||
| function n(...n){const t=t=>n.findIndex(n=>n.id===t),e=t=>n[t];return{getAll:()=>n,get:n=>e(t(n)),getIndex:n=>t(n),getByIndex:e,getFirst:()=>e(0),getLast:()=>e(n.length-1),getNext:n=>e(t(n)+1),getPrev:n=>e(t(n)-1),getNeighbors(r){const i=t(r);return{prev:i>0?e(i-1):null,next:i<n.length-1?e(i+1):null}}}}function t(n,t){const e=n.findIndex(n=>n.id===t);return-1===e?0:e}function e(n,t){const e={};for(const r of n){const n=r.id;e[n]=t?.[n]??null}return e}function r(n,t,e){return{switch(n){const e=n[t.id];return e?.(t)},when(t,r,i){const o=n[e];return(Array.isArray(t)?o.id===t[0]&&t.slice(1).every(Boolean):o.id===t)?r?.(o):i?.(o)},match(t,e){const r=n.find(n=>n.id===t);if(!r)return null;const i=e[t];return i?.(r)??null},is:n=>t.id===n}}var i=(n,t,e)=>{if(!(t>=0&&t<n.length))throw new Error(`Cannot navigate ${t<0?"prev":"next"}: ${t<0?"first step":"last step"}`);e(t)};export{r as generateCommonStepperUseFns,n as generateStepperUtils,e as getInitialMetadata,t as getInitialStepIndex,i as updateStepIndex}; |
+3
-3
| { | ||
| "name": "@stepperize/core", | ||
| "version": "2.0.0", | ||
| "version": "2.1.0", | ||
| "private": false, | ||
@@ -33,7 +33,7 @@ "publishConfig": { | ||
| "@testing-library/react": "^16.3.2", | ||
| "jsdom": "^27.4.0", | ||
| "jsdom": "^28.1.0", | ||
| "tsup": "^8.5.1", | ||
| "terser": "^5.46.0", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.0.17" | ||
| "vitest": "^4.0.18" | ||
| }, | ||
@@ -40,0 +40,0 @@ "scripts": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16754
4.76%0
-100%