@jfdevelops/react-multi-step-form 1.0.0-alpha.32 → 1.0.0-alpha.34

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.
Files changed (53) hide show
  1. package/dist/create-context.cjs +6 -8
  2. package/dist/create-context.cjs.map +1 -1
  3. package/dist/create-context.d.cts +19 -21
  4. package/dist/create-context.d.mts +19 -21
  5. package/dist/create-context.mjs +12 -14
  6. package/dist/create-context.mjs.map +1 -1
  7. package/dist/field.cjs.map +1 -1
  8. package/dist/field.d.cts +15 -15
  9. package/dist/field.d.mts +15 -15
  10. package/dist/field.mjs.map +1 -1
  11. package/dist/form-config.cjs +38 -6
  12. package/dist/form-config.cjs.map +1 -1
  13. package/dist/form-config.d.cts +52 -18
  14. package/dist/form-config.d.mts +52 -18
  15. package/dist/form-config.mjs +38 -6
  16. package/dist/form-config.mjs.map +1 -1
  17. package/dist/hooks/use-multi-step-form-data.cjs +4 -22
  18. package/dist/hooks/use-multi-step-form-data.cjs.map +1 -1
  19. package/dist/hooks/use-multi-step-form-data.d.cts +12 -10
  20. package/dist/hooks/use-multi-step-form-data.d.mts +12 -10
  21. package/dist/hooks/use-multi-step-form-data.mjs +5 -22
  22. package/dist/hooks/use-multi-step-form-data.mjs.map +1 -1
  23. package/dist/hooks/use-selector.cjs.map +1 -1
  24. package/dist/hooks/use-selector.d.cts +18 -4
  25. package/dist/hooks/use-selector.d.mts +18 -4
  26. package/dist/hooks/use-selector.mjs.map +1 -1
  27. package/dist/index.cjs +2 -3
  28. package/dist/index.d.cts +3 -3
  29. package/dist/index.d.mts +3 -3
  30. package/dist/index.mjs +3 -3
  31. package/dist/schema.cjs +87 -10
  32. package/dist/schema.cjs.map +1 -1
  33. package/dist/schema.d.cts +66 -25
  34. package/dist/schema.d.mts +66 -25
  35. package/dist/schema.mjs +88 -11
  36. package/dist/schema.mjs.map +1 -1
  37. package/dist/selector.cjs.map +1 -1
  38. package/dist/selector.d.cts +8 -8
  39. package/dist/selector.d.mts +8 -8
  40. package/dist/selector.mjs.map +1 -1
  41. package/dist/step-schema.cjs +54 -56
  42. package/dist/step-schema.cjs.map +1 -1
  43. package/dist/step-schema.d.cts +62 -61
  44. package/dist/step-schema.d.mts +62 -61
  45. package/dist/step-schema.mjs +57 -58
  46. package/dist/step-schema.mjs.map +1 -1
  47. package/dist/utils.cjs +12 -0
  48. package/dist/utils.cjs.map +1 -1
  49. package/dist/utils.d.cts +12 -0
  50. package/dist/utils.d.mts +12 -0
  51. package/dist/utils.mjs +13 -2
  52. package/dist/utils.mjs.map +1 -1
  53. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"schema.cjs","names":["MultiStepFormSchemaCore","#internal","DEFAULT_CASING","MultiStepFormStepSchema","MultiStepFormStepSchemaInternal"],"sources":["../src/schema.ts"],"sourcesContent":["import {\n type CasingType,\n type Constrain,\n createCtx,\n type CreateHelperFunctionOptionsBase,\n DEFAULT_CASING,\n type DefaultCasing,\n type DefaultStorageKey,\n type HelperFnChosenSteps,\n type MultiStepFormSchemaOptions as MultiStepFormSchemaBaseOptions,\n MultiStepFormSchema as MultiStepFormSchemaCore,\n type ResolvedStep as ResolvedStepCore,\n type Step,\n type StepNumbers,\n} from '@jfdevelops/multi-step-form-core';\nimport type { ComponentPropsWithRef } from 'react';\nimport { MultiStepFormSchemaConfig } from './form-config';\nimport {\n type CreateComponentCallback,\n type CreatedMultiStepFormComponent,\n type HelperFunctions,\n MultiStepFormStepSchema,\n type ResolvedStep,\n} from './step-schema';\nimport { MultiStepFormStepSchemaInternal } from '@jfdevelops/multi-step-form-core/_internals';\n\n// export type AnyMultiStepFormSchema = MultiStepFormSchema<any, any, any>;\nexport type AnyMultiStepFormSchema = { [x: string]: any };\n\n// Helper inference types for `AnyMultiStepFormSchema`\nexport namespace MultiStepFormSchema {\n /**\n * Infer the resolved step from a {@linkcode MultiStepFormSchema}.\n */\n export type resolvedStep<T extends AnyMultiStepFormSchema> =\n T['stepSchema']['value'];\n /**\n * Infer the {@linkcode MultiStepFormSchema}'s step numbers.\n */\n export type stepNumbers<T extends AnyMultiStepFormSchema> = StepNumbers<\n resolvedStep<T>\n >;\n /**\n * Get the data for a specific step from a {@linkcode MultiStepFormSchema}.\n */\n export type getData<\n T extends AnyMultiStepFormSchema,\n TTarget extends keyof resolvedStep<T>\n > = resolvedStep<T>[TTarget];\n}\n\nexport interface MultiStepFormSchemaOptions<\n TStep extends Step<TCasing>,\n TCasing extends CasingType,\n TStorageKey extends string,\n TFormAlias extends string,\n TFormEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<TResolvedStep>,\n TFormProps extends object,\n TResolvedStep extends ResolvedStep<TStep, TCasing> = ResolvedStep<\n TStep,\n TCasing\n >\n> extends MultiStepFormSchemaBaseOptions<TStep, TCasing, TStorageKey>,\n MultiStepFormSchemaConfig.Form<\n TResolvedStep,\n TFormAlias,\n TFormEnabledFor,\n TFormProps\n > {}\n\nexport class MultiStepFormSchema<\n step extends Step<casing>,\n casing extends CasingType = DefaultCasing,\n storageKey extends string = DefaultStorageKey,\n formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias,\n formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep> = MultiStepFormSchemaConfig.defaultEnabledFor,\n formProps extends object = ComponentPropsWithRef<'form'>,\n resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<\n step,\n casing\n >,\n stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n >\n extends MultiStepFormSchemaCore<\n step,\n casing,\n ResolvedStepCore<step, casing>,\n StepNumbers<ResolvedStepCore<step, casing>>,\n storageKey\n >\n implements HelperFunctions<resolvedStep, stepNumbers>\n{\n // @ts-ignore\n stepSchema: MultiStepFormStepSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >;\n readonly #internal: MultiStepFormStepSchemaInternal<\n step,\n casing,\n resolvedStep,\n stepNumbers\n >;\n\n constructor(\n config: MultiStepFormSchemaOptions<\n step,\n Constrain<casing, CasingType>,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >\n ) {\n const { nameTransformCasing = DEFAULT_CASING, storage, ...rest } = config;\n const options = { nameTransformCasing, storage, ...rest };\n\n super(options);\n\n this.stepSchema = new MultiStepFormStepSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >(options);\n this.#internal = new MultiStepFormStepSchemaInternal<\n step,\n casing,\n resolvedStep,\n stepNumbers\n >({\n originalValue: this.stepSchema.original,\n getValue: () => this.stepSchema.value as never,\n setValue: (value) => {\n this.stepSchema.value = { ...value } as never;\n this.storage.add(value);\n this.notify();\n },\n });\n }\n\n createComponent<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>,\n props = undefined\n >(\n options: CreateHelperFunctionOptionsBase<\n resolvedStep,\n stepNumbers,\n chosenSteps\n >,\n fn: CreateComponentCallback<resolvedStep, stepNumbers, chosenSteps, props>\n ): CreatedMultiStepFormComponent<props> {\n const { stepData } = options;\n const ctx = createCtx<resolvedStep, stepNumbers, chosenSteps>(\n this.stepSchema.value as never,\n stepData\n ) as never;\n\n return ((props?: props) =>\n fn(\n {\n ctx,\n update: this.#internal.createHelperFnInputUpdate(stepData),\n reset: this.#internal.createHelperFnInputReset(stepData),\n },\n props as any\n )) as any;\n }\n}\n\nexport function createMultiStepFormSchema<\n step extends Step<casing>,\n casing extends CasingType = DefaultCasing,\n storageKey extends string = DefaultStorageKey,\n formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias,\n formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep> = MultiStepFormSchemaConfig.defaultEnabledFor,\n formProps extends object = ComponentPropsWithRef<'form'>,\n resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n>(\n options: MultiStepFormSchemaOptions<\n step,\n Constrain<casing, CasingType>,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >\n) {\n return new MultiStepFormSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps,\n resolvedStep,\n stepNumbers\n >(options);\n}\n"],"mappings":";;;;;AAsEA,IAAa,sBAAb,cAaUA,sDAQV;CAEE;CAQA,CAASC;CAOT,YACE,QAQA;EACA,MAAM,EAAE,sBAAsBC,kDAAgB,SAAS,GAAG,SAAS;EACnE,MAAM,UAAU;GAAE;GAAqB;GAAS,GAAG;GAAM;AAEzD,QAAM,QAAQ;AAEd,OAAK,aAAa,IAAIC,4CAOpB,QAAQ;AACV,QAAKF,WAAY,IAAIG,6EAKnB;GACA,eAAe,KAAK,WAAW;GAC/B,gBAAgB,KAAK,WAAW;GAChC,WAAW,UAAU;AACnB,SAAK,WAAW,QAAQ,EAAE,GAAG,OAAO;AACpC,SAAK,QAAQ,IAAI,MAAM;AACvB,SAAK,QAAQ;;GAEhB,CAAC;;CAGJ,gBAIE,SAKA,IACsC;EACtC,MAAM,EAAE,aAAa;EACrB,MAAM,uDACJ,KAAK,WAAW,OAChB,SACD;AAED,WAAS,UACP,GACE;GACE;GACA,QAAQ,MAAKH,SAAU,0BAA0B,SAAS;GAC1D,OAAO,MAAKA,SAAU,yBAAyB,SAAS;GACzD,EACD,MACD;;;AAIP,SAAgB,0BAUd,SAQA;AACA,QAAO,IAAI,oBAST,QAAQ"}
1
+ {"version":3,"file":"schema.cjs","names":["MultiStepFormSchemaCore","#internal","DEFAULT_CASING","MultiStepFormStepSchema","MultiStepFormStepSchemaInternal","DEFAULT_STORAGE_KEY","MultiStepFormStorage","createMultiStepFormContext","createComponent"],"sources":["../src/schema.ts"],"sourcesContent":["import {\n type BaseStorageConfig,\n DEFAULT_CASING,\n DEFAULT_STORAGE_KEY,\n type Expand,\n type HelperFn,\n type HelperFnChosenSteps,\n MultiStepFormSchema as MultiStepFormSchemaCore,\n MultiStepFormStorage,\n type steps,\n} from '@jfdevelops/multi-step-form-core';\nimport {\n MultiStepFormStepSchemaInternal,\n type StepSchema,\n} from '@jfdevelops/multi-step-form-core/_internals';\nimport {\n createMultiStepFormContext,\n type MultiStepFormContextResult,\n} from './create-context';\nimport { MultiStepFormSchemaConfig } from './form-config';\nimport { type HelperFunctions, MultiStepFormStepSchema } from './step-schema';\nimport { createComponent, type CreateComponentCallback } from './utils';\n\n// Helper inference types for `AnyMultiStepFormSchema`\nexport namespace MultiStepFormSchema {\n export type config<\n def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n > = MultiStepFormStepSchema.config<def, value> & {\n /**\n * The React context for the multi step form.\n *\n * This is a private property and is not meant to be used directly.\n * @private\n * @internal\n */\n context?: MultiStepFormContextResult<def, value>;\n };\n}\n\nexport class MultiStepFormSchema<\n const def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n>\n extends MultiStepFormSchemaCore<def, value>\n implements HelperFunctions<def, value>\n{\n stepSchema: MultiStepFormStepSchema<def, value>;\n readonly #internal: MultiStepFormStepSchemaInternal<def, value>;\n override readonly storage: MultiStepFormStorage<\n value,\n StepSchema.inferStorageKey<def>\n >;\n override readonly storageConfig: BaseStorageConfig<\n StepSchema.inferStorageKey<def>\n >;\n\n readonly context: MultiStepFormContextResult<def, value> = undefined as never;\n readonly formConfig: MultiStepFormSchemaConfig.FormConfig<def, value> =\n undefined as never;\n\n constructor(config: MultiStepFormSchema.config<def, value>) {\n const {\n nameTransformCasing = DEFAULT_CASING,\n steps,\n form,\n storage,\n context,\n } = config;\n const options = {\n steps,\n nameTransformCasing,\n storage,\n form,\n } as MultiStepFormStepSchema.config<def, value>;\n\n super(options);\n\n this.stepSchema = new MultiStepFormStepSchema(options);\n this.#internal = new MultiStepFormStepSchemaInternal({\n originalValue: this.stepSchema.original,\n getValue: () => this.stepSchema.value,\n setValue: (value) => {\n this.stepSchema.value = { ...value };\n this.storage.add(value);\n this.notify();\n },\n });\n this.storageConfig = {\n key: (storage?.key ??\n DEFAULT_STORAGE_KEY) as StepSchema.inferStorageKey<def>,\n store: storage?.store,\n throwWhenUndefined: storage?.throwWhenUndefined,\n };\n this.storage = new MultiStepFormStorage({\n data: this.stepSchema.value,\n ...this.storageConfig,\n });\n if (context) {\n this.context = context;\n }\n\n if (form) {\n this.formConfig = form;\n }\n }\n\n /**\n * A helper function to add a form configuration to the {@linkcode MultiStepFormSchema}.\n *\n * By calling this function, you will have access to the create form component in all step\n * utility functions.\n *\n * @example\n * ```tsx\n * const schema = createMultiStepFormSchema({\n * steps: {\n * step1: {\n * title: 'Step 1',\n * fields: {\n * firstName: {\n * defaultValue: '',\n * },\n * },\n * },\n * },\n * }).withForm({\n * render(data) {\n * return (props: MyCustomProps) => {\n * return <form {...props}>{props.children}</form>;\n * };\n * },\n * });\n * ```\n * @param config The form configuration.\n * @returns A new {@linkcode MultiStepFormSchema} with the form configuration.\n */\n withForm<\n const formConfig extends MultiStepFormSchemaConfig.FormConfig<def, value>,\n >(config: formConfig) {\n const { key, store, throwWhenUndefined } = this.storageConfig;\n\n return new MultiStepFormSchema<\n Expand<def & Readonly<{ form: formConfig }>>\n >({\n steps: this.stepSchema.original,\n form: config,\n nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,\n storage: {\n key,\n store,\n throwWhenUndefined: throwWhenUndefined,\n },\n } as never);\n }\n\n withContext() {\n const context = createMultiStepFormContext(this);\n\n return new MultiStepFormSchema<def, value>({\n steps: this.stepSchema.original,\n form: this.formConfig,\n nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,\n storage: {\n key: this.storageConfig.key,\n store: this.storageConfig.store,\n throwWhenUndefined: this.storageConfig.throwWhenUndefined,\n },\n context,\n } as never);\n }\n\n createComponent<\n chosenSteps extends HelperFnChosenSteps.main<\n value,\n steps.StepNumbers<value>\n >,\n props = undefined,\n >(\n options: HelperFn.BaseOptions<value, chosenSteps>,\n fn: CreateComponentCallback<value, chosenSteps, props>\n ) {\n return createComponent({\n fn,\n input: ({ stepData }) => ({\n reset: this.#internal.createHelperFnInputReset(stepData),\n update: this.#internal.createHelperFnInputUpdate(stepData),\n }),\n options,\n value: this.stepSchema.value,\n });\n }\n}\n\nexport function createMultiStepFormSchema<\n const def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n>(options: def) {\n return new MultiStepFormSchema<def, value>(options);\n}\n"],"mappings":";;;;;;;AAwCA,IAAa,sBAAb,MAAa,4BAIHA,sDAEV;CACE;CACA,CAASC;CACT,AAAkB;CAIlB,AAAkB;CAIlB,AAAS,UAAkD;CAC3D,AAAS,aACP;CAEF,YAAY,QAAgD;EAC1D,MAAM,EACJ,sBAAsBC,kDACtB,OACA,MACA,SACA,YACE;EACJ,MAAM,UAAU;GACd;GACA;GACA;GACA;GACD;AAED,QAAM,QAAQ;AAEd,OAAK,aAAa,IAAIC,4CAAwB,QAAQ;AACtD,QAAKF,WAAY,IAAIG,6EAAgC;GACnD,eAAe,KAAK,WAAW;GAC/B,gBAAgB,KAAK,WAAW;GAChC,WAAW,UAAU;AACnB,SAAK,WAAW,QAAQ,EAAE,GAAG,OAAO;AACpC,SAAK,QAAQ,IAAI,MAAM;AACvB,SAAK,QAAQ;;GAEhB,CAAC;AACF,OAAK,gBAAgB;GACnB,KAAM,SAAS,OACbC;GACF,OAAO,SAAS;GAChB,oBAAoB,SAAS;GAC9B;AACD,OAAK,UAAU,IAAIC,uDAAqB;GACtC,MAAM,KAAK,WAAW;GACtB,GAAG,KAAK;GACT,CAAC;AACF,MAAI,QACF,MAAK,UAAU;AAGjB,MAAI,KACF,MAAK,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCtB,SAEE,QAAoB;EACpB,MAAM,EAAE,KAAK,OAAO,uBAAuB,KAAK;AAEhD,SAAO,IAAI,oBAET;GACA,OAAO,KAAK,WAAW;GACvB,MAAM;GACN,qBAAqB,KAAK,WAAW;GACrC,SAAS;IACP;IACA;IACoB;IACrB;GACF,CAAU;;CAGb,cAAc;EACZ,MAAM,UAAUC,kDAA2B,KAAK;AAEhD,SAAO,IAAI,oBAAgC;GACzC,OAAO,KAAK,WAAW;GACvB,MAAM,KAAK;GACX,qBAAqB,KAAK,WAAW;GACrC,SAAS;IACP,KAAK,KAAK,cAAc;IACxB,OAAO,KAAK,cAAc;IAC1B,oBAAoB,KAAK,cAAc;IACxC;GACD;GACD,CAAU;;CAGb,gBAOE,SACA,IACA;AACA,SAAOC,8BAAgB;GACrB;GACA,QAAQ,EAAE,gBAAgB;IACxB,OAAO,MAAKP,SAAU,yBAAyB,SAAS;IACxD,QAAQ,MAAKA,SAAU,0BAA0B,SAAS;IAC3D;GACD;GACA,OAAO,KAAK,WAAW;GACxB,CAAC;;;AAIN,SAAgB,0BAGd,SAAc;AACd,QAAO,IAAI,oBAAgC,QAAQ"}
package/dist/schema.d.cts CHANGED
@@ -1,34 +1,75 @@
1
- import { CreateComponentCallback, CreatedMultiStepFormComponent, HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1, ResolvedStep as ResolvedStep$1 } from "./step-schema.cjs";
1
+ import { CreateComponentCallback, CreatedMultiStepFormComponent } from "./utils.cjs";
2
+ import { MultiStepFormContextResult } from "./create-context.cjs";
2
3
  import { MultiStepFormSchemaConfig } from "./form-config.cjs";
3
- import { CasingType, Constrain, CreateHelperFunctionOptionsBase, DefaultCasing, DefaultStorageKey, HelperFnChosenSteps, MultiStepFormSchema, MultiStepFormSchemaOptions, ResolvedStep, Step, StepNumbers } from "@jfdevelops/multi-step-form-core";
4
- import { ComponentPropsWithRef } from "react";
4
+ import { HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1 } from "./step-schema.cjs";
5
+ import * as _jfdevelops_multi_step_form_core0 from "@jfdevelops/multi-step-form-core";
6
+ import { BaseStorageConfig, Expand, HelperFn, HelperFnChosenSteps, MultiStepFormSchema, MultiStepFormStorage, steps } from "@jfdevelops/multi-step-form-core";
7
+ import { StepSchema } from "@jfdevelops/multi-step-form-core/_internals";
5
8
 
6
9
  //#region src/schema.d.ts
7
- type AnyMultiStepFormSchema = {
8
- [x: string]: any;
9
- };
10
10
  declare namespace MultiStepFormSchema$1 {
11
- /**
12
- * Infer the resolved step from a {@linkcode MultiStepFormSchema}.
13
- */
14
- type resolvedStep<T extends AnyMultiStepFormSchema> = T['stepSchema']['value'];
15
- /**
16
- * Infer the {@linkcode MultiStepFormSchema}'s step numbers.
17
- */
18
- type stepNumbers<T extends AnyMultiStepFormSchema> = StepNumbers<resolvedStep<T>>;
19
- /**
20
- * Get the data for a specific step from a {@linkcode MultiStepFormSchema}.
21
- */
22
- type getData<T extends AnyMultiStepFormSchema, TTarget extends keyof resolvedStep<T>> = resolvedStep<T>[TTarget];
11
+ type config<def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>> = MultiStepFormStepSchema$1.config<def, value> & {
12
+ /**
13
+ * The React context for the multi step form.
14
+ *
15
+ * This is a private property and is not meant to be used directly.
16
+ * @private
17
+ * @internal
18
+ */
19
+ context?: MultiStepFormContextResult<def, value>;
20
+ };
23
21
  }
24
- interface MultiStepFormSchemaOptions$1<TStep extends Step<TCasing>, TCasing extends CasingType, TStorageKey extends string, TFormAlias extends string, TFormEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<TResolvedStep>, TFormProps extends object, TResolvedStep extends ResolvedStep$1<TStep, TCasing> = ResolvedStep$1<TStep, TCasing>> extends MultiStepFormSchemaOptions<TStep, TCasing, TStorageKey>, MultiStepFormSchemaConfig.Form<TResolvedStep, TFormAlias, TFormEnabledFor, TFormProps> {}
25
- declare class MultiStepFormSchema$1<step extends Step<casing>, casing extends CasingType = DefaultCasing, storageKey extends string = DefaultStorageKey, formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias, formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep$1> = MultiStepFormSchemaConfig.defaultEnabledFor, formProps extends object = ComponentPropsWithRef<'form'>, resolvedStep$1 extends ResolvedStep$1<step, casing> = ResolvedStep$1<step, casing>, stepNumbers extends StepNumbers<resolvedStep$1> = StepNumbers<resolvedStep$1>> extends MultiStepFormSchema<step, casing, ResolvedStep<step, casing>, StepNumbers<ResolvedStep<step, casing>>, storageKey> implements HelperFunctions<resolvedStep$1, stepNumbers> {
22
+ declare class MultiStepFormSchema$1<const def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>> extends MultiStepFormSchema<def, value> implements HelperFunctions<def, value> {
26
23
  #private;
27
- stepSchema: MultiStepFormStepSchema$1<step, casing, storageKey, formAlias, formEnabledFor, formProps>;
28
- constructor(config: MultiStepFormSchemaOptions$1<step, Constrain<casing, CasingType>, storageKey, formAlias, formEnabledFor, formProps>);
29
- createComponent<chosenSteps extends HelperFnChosenSteps<resolvedStep$1, stepNumbers>, props = undefined>(options: CreateHelperFunctionOptionsBase<resolvedStep$1, stepNumbers, chosenSteps>, fn: CreateComponentCallback<resolvedStep$1, stepNumbers, chosenSteps, props>): CreatedMultiStepFormComponent<props>;
24
+ stepSchema: MultiStepFormStepSchema$1<def, value>;
25
+ readonly storage: MultiStepFormStorage<value, StepSchema.inferStorageKey<def>>;
26
+ readonly storageConfig: BaseStorageConfig<StepSchema.inferStorageKey<def>>;
27
+ readonly context: MultiStepFormContextResult<def, value>;
28
+ readonly formConfig: MultiStepFormSchemaConfig.FormConfig<def, value>;
29
+ constructor(config: MultiStepFormSchema$1.config<def, value>);
30
+ /**
31
+ * A helper function to add a form configuration to the {@linkcode MultiStepFormSchema}.
32
+ *
33
+ * By calling this function, you will have access to the create form component in all step
34
+ * utility functions.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * const schema = createMultiStepFormSchema({
39
+ * steps: {
40
+ * step1: {
41
+ * title: 'Step 1',
42
+ * fields: {
43
+ * firstName: {
44
+ * defaultValue: '',
45
+ * },
46
+ * },
47
+ * },
48
+ * },
49
+ * }).withForm({
50
+ * render(data) {
51
+ * return (props: MyCustomProps) => {
52
+ * return <form {...props}>{props.children}</form>;
53
+ * };
54
+ * },
55
+ * });
56
+ * ```
57
+ * @param config The form configuration.
58
+ * @returns A new {@linkcode MultiStepFormSchema} with the form configuration.
59
+ */
60
+ withForm<const formConfig extends MultiStepFormSchemaConfig.FormConfig<def, value>>(config: formConfig): MultiStepFormSchema$1<Expand<def & Readonly<{
61
+ form: formConfig;
62
+ }>>, Expand<steps._instantiateSteps<Expand<def & Readonly<{
63
+ form: formConfig;
64
+ }>>> extends infer T ? { [key in keyof T]: Expand<T[key] & (T extends {} ? key extends steps.StepNumbers<T> ? {
65
+ update: _jfdevelops_multi_step_form_core0.UpdateFn.stepSpecific<T, key, steps.StepNumbers<T>>;
66
+ reset: _jfdevelops_multi_step_form_core0.ResetFn.stepSpecific<T, key>;
67
+ createHelperFn: _jfdevelops_multi_step_form_core0.StepSpecificHelperFn<T, key>;
68
+ } & steps.ExtendedStepSpecificFunctions<t, T, key> : {} : {}) extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never> } : never>>;
69
+ withContext(): MultiStepFormSchema$1<def, value>;
70
+ createComponent<chosenSteps extends HelperFnChosenSteps.main<value, steps.StepNumbers<value>>, props = undefined>(options: HelperFn.BaseOptions<value, chosenSteps>, fn: CreateComponentCallback<value, chosenSteps, props>): CreatedMultiStepFormComponent<props>;
30
71
  }
31
- declare function createMultiStepFormSchema<step extends Step<casing>, casing extends CasingType = DefaultCasing, storageKey extends string = DefaultStorageKey, formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias, formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep$1> = MultiStepFormSchemaConfig.defaultEnabledFor, formProps extends object = ComponentPropsWithRef<'form'>, resolvedStep$1 extends ResolvedStep$1<step, casing> = ResolvedStep$1<step, casing>, stepNumbers extends StepNumbers<resolvedStep$1> = StepNumbers<resolvedStep$1>>(options: MultiStepFormSchemaOptions$1<step, Constrain<casing, CasingType>, storageKey, formAlias, formEnabledFor, formProps>): MultiStepFormSchema$1<step, casing, storageKey, formAlias, formEnabledFor, formProps, resolvedStep$1, stepNumbers>;
72
+ declare function createMultiStepFormSchema<const def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>>(options: def): MultiStepFormSchema$1<def, value>;
32
73
  //#endregion
33
- export { AnyMultiStepFormSchema, MultiStepFormSchema$1 as MultiStepFormSchema, MultiStepFormSchemaOptions$1 as MultiStepFormSchemaOptions, createMultiStepFormSchema };
74
+ export { MultiStepFormSchema$1 as MultiStepFormSchema, createMultiStepFormSchema };
34
75
  //# sourceMappingURL=schema.d.cts.map
package/dist/schema.d.mts CHANGED
@@ -1,34 +1,75 @@
1
- import { CreateComponentCallback, CreatedMultiStepFormComponent, HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1, ResolvedStep as ResolvedStep$1 } from "./step-schema.mjs";
1
+ import { CreateComponentCallback, CreatedMultiStepFormComponent } from "./utils.mjs";
2
+ import { MultiStepFormContextResult } from "./create-context.mjs";
2
3
  import { MultiStepFormSchemaConfig } from "./form-config.mjs";
3
- import { CasingType, Constrain, CreateHelperFunctionOptionsBase, DefaultCasing, DefaultStorageKey, HelperFnChosenSteps, MultiStepFormSchema, MultiStepFormSchemaOptions, ResolvedStep, Step, StepNumbers } from "@jfdevelops/multi-step-form-core";
4
- import { ComponentPropsWithRef } from "react";
4
+ import { HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1 } from "./step-schema.mjs";
5
+ import * as _jfdevelops_multi_step_form_core0 from "@jfdevelops/multi-step-form-core";
6
+ import { BaseStorageConfig, Expand, HelperFn, HelperFnChosenSteps, MultiStepFormSchema, MultiStepFormStorage, steps } from "@jfdevelops/multi-step-form-core";
7
+ import { StepSchema } from "@jfdevelops/multi-step-form-core/_internals";
5
8
 
6
9
  //#region src/schema.d.ts
7
- type AnyMultiStepFormSchema = {
8
- [x: string]: any;
9
- };
10
10
  declare namespace MultiStepFormSchema$1 {
11
- /**
12
- * Infer the resolved step from a {@linkcode MultiStepFormSchema}.
13
- */
14
- type resolvedStep<T extends AnyMultiStepFormSchema> = T['stepSchema']['value'];
15
- /**
16
- * Infer the {@linkcode MultiStepFormSchema}'s step numbers.
17
- */
18
- type stepNumbers<T extends AnyMultiStepFormSchema> = StepNumbers<resolvedStep<T>>;
19
- /**
20
- * Get the data for a specific step from a {@linkcode MultiStepFormSchema}.
21
- */
22
- type getData<T extends AnyMultiStepFormSchema, TTarget extends keyof resolvedStep<T>> = resolvedStep<T>[TTarget];
11
+ type config<def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>> = MultiStepFormStepSchema$1.config<def, value> & {
12
+ /**
13
+ * The React context for the multi step form.
14
+ *
15
+ * This is a private property and is not meant to be used directly.
16
+ * @private
17
+ * @internal
18
+ */
19
+ context?: MultiStepFormContextResult<def, value>;
20
+ };
23
21
  }
24
- interface MultiStepFormSchemaOptions$1<TStep extends Step<TCasing>, TCasing extends CasingType, TStorageKey extends string, TFormAlias extends string, TFormEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<TResolvedStep>, TFormProps extends object, TResolvedStep extends ResolvedStep$1<TStep, TCasing> = ResolvedStep$1<TStep, TCasing>> extends MultiStepFormSchemaOptions<TStep, TCasing, TStorageKey>, MultiStepFormSchemaConfig.Form<TResolvedStep, TFormAlias, TFormEnabledFor, TFormProps> {}
25
- declare class MultiStepFormSchema$1<step extends Step<casing>, casing extends CasingType = DefaultCasing, storageKey extends string = DefaultStorageKey, formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias, formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep$1> = MultiStepFormSchemaConfig.defaultEnabledFor, formProps extends object = ComponentPropsWithRef<'form'>, resolvedStep$1 extends ResolvedStep$1<step, casing> = ResolvedStep$1<step, casing>, stepNumbers extends StepNumbers<resolvedStep$1> = StepNumbers<resolvedStep$1>> extends MultiStepFormSchema<step, casing, ResolvedStep<step, casing>, StepNumbers<ResolvedStep<step, casing>>, storageKey> implements HelperFunctions<resolvedStep$1, stepNumbers> {
22
+ declare class MultiStepFormSchema$1<const def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>> extends MultiStepFormSchema<def, value> implements HelperFunctions<def, value> {
26
23
  #private;
27
- stepSchema: MultiStepFormStepSchema$1<step, casing, storageKey, formAlias, formEnabledFor, formProps>;
28
- constructor(config: MultiStepFormSchemaOptions$1<step, Constrain<casing, CasingType>, storageKey, formAlias, formEnabledFor, formProps>);
29
- createComponent<chosenSteps extends HelperFnChosenSteps<resolvedStep$1, stepNumbers>, props = undefined>(options: CreateHelperFunctionOptionsBase<resolvedStep$1, stepNumbers, chosenSteps>, fn: CreateComponentCallback<resolvedStep$1, stepNumbers, chosenSteps, props>): CreatedMultiStepFormComponent<props>;
24
+ stepSchema: MultiStepFormStepSchema$1<def, value>;
25
+ readonly storage: MultiStepFormStorage<value, StepSchema.inferStorageKey<def>>;
26
+ readonly storageConfig: BaseStorageConfig<StepSchema.inferStorageKey<def>>;
27
+ readonly context: MultiStepFormContextResult<def, value>;
28
+ readonly formConfig: MultiStepFormSchemaConfig.FormConfig<def, value>;
29
+ constructor(config: MultiStepFormSchema$1.config<def, value>);
30
+ /**
31
+ * A helper function to add a form configuration to the {@linkcode MultiStepFormSchema}.
32
+ *
33
+ * By calling this function, you will have access to the create form component in all step
34
+ * utility functions.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * const schema = createMultiStepFormSchema({
39
+ * steps: {
40
+ * step1: {
41
+ * title: 'Step 1',
42
+ * fields: {
43
+ * firstName: {
44
+ * defaultValue: '',
45
+ * },
46
+ * },
47
+ * },
48
+ * },
49
+ * }).withForm({
50
+ * render(data) {
51
+ * return (props: MyCustomProps) => {
52
+ * return <form {...props}>{props.children}</form>;
53
+ * };
54
+ * },
55
+ * });
56
+ * ```
57
+ * @param config The form configuration.
58
+ * @returns A new {@linkcode MultiStepFormSchema} with the form configuration.
59
+ */
60
+ withForm<const formConfig extends MultiStepFormSchemaConfig.FormConfig<def, value>>(config: formConfig): MultiStepFormSchema$1<Expand<def & Readonly<{
61
+ form: formConfig;
62
+ }>>, Expand<steps._instantiateSteps<Expand<def & Readonly<{
63
+ form: formConfig;
64
+ }>>> extends infer T ? { [key in keyof T]: Expand<T[key] & (T extends {} ? key extends steps.StepNumbers<T> ? {
65
+ update: _jfdevelops_multi_step_form_core0.UpdateFn.stepSpecific<T, key, steps.StepNumbers<T>>;
66
+ reset: _jfdevelops_multi_step_form_core0.ResetFn.stepSpecific<T, key>;
67
+ createHelperFn: _jfdevelops_multi_step_form_core0.StepSpecificHelperFn<T, key>;
68
+ } & steps.ExtendedStepSpecificFunctions<t, T, key> : {} : {}) extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never> } : never>>;
69
+ withContext(): MultiStepFormSchema$1<def, value>;
70
+ createComponent<chosenSteps extends HelperFnChosenSteps.main<value, steps.StepNumbers<value>>, props = undefined>(options: HelperFn.BaseOptions<value, chosenSteps>, fn: CreateComponentCallback<value, chosenSteps, props>): CreatedMultiStepFormComponent<props>;
30
71
  }
31
- declare function createMultiStepFormSchema<step extends Step<casing>, casing extends CasingType = DefaultCasing, storageKey extends string = DefaultStorageKey, formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias, formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep$1> = MultiStepFormSchemaConfig.defaultEnabledFor, formProps extends object = ComponentPropsWithRef<'form'>, resolvedStep$1 extends ResolvedStep$1<step, casing> = ResolvedStep$1<step, casing>, stepNumbers extends StepNumbers<resolvedStep$1> = StepNumbers<resolvedStep$1>>(options: MultiStepFormSchemaOptions$1<step, Constrain<casing, CasingType>, storageKey, formAlias, formEnabledFor, formProps>): MultiStepFormSchema$1<step, casing, storageKey, formAlias, formEnabledFor, formProps, resolvedStep$1, stepNumbers>;
72
+ declare function createMultiStepFormSchema<const def extends StepSchema.Config, value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>>(options: def): MultiStepFormSchema$1<def, value>;
32
73
  //#endregion
33
- export { AnyMultiStepFormSchema, MultiStepFormSchema$1 as MultiStepFormSchema, MultiStepFormSchemaOptions$1 as MultiStepFormSchemaOptions, createMultiStepFormSchema };
74
+ export { MultiStepFormSchema$1 as MultiStepFormSchema, createMultiStepFormSchema };
34
75
  //# sourceMappingURL=schema.d.mts.map
package/dist/schema.mjs CHANGED
@@ -1,17 +1,24 @@
1
+ import { createMultiStepFormContext } from "./create-context.mjs";
2
+ import { createComponent } from "./utils.mjs";
1
3
  import { MultiStepFormStepSchema as MultiStepFormStepSchema$1 } from "./step-schema.mjs";
2
- import { DEFAULT_CASING, MultiStepFormSchema, createCtx } from "@jfdevelops/multi-step-form-core";
4
+ import { DEFAULT_CASING, DEFAULT_STORAGE_KEY, MultiStepFormSchema, MultiStepFormStorage } from "@jfdevelops/multi-step-form-core";
3
5
  import { MultiStepFormStepSchemaInternal } from "@jfdevelops/multi-step-form-core/_internals";
4
6
 
5
7
  //#region src/schema.ts
6
- var MultiStepFormSchema$1 = class extends MultiStepFormSchema {
8
+ var MultiStepFormSchema$1 = class MultiStepFormSchema$1 extends MultiStepFormSchema {
7
9
  stepSchema;
8
10
  #internal;
11
+ storage;
12
+ storageConfig;
13
+ context = void 0;
14
+ formConfig = void 0;
9
15
  constructor(config) {
10
- const { nameTransformCasing = DEFAULT_CASING, storage, ...rest } = config;
16
+ const { nameTransformCasing = DEFAULT_CASING, steps: steps$1, form, storage, context } = config;
11
17
  const options = {
18
+ steps: steps$1,
12
19
  nameTransformCasing,
13
20
  storage,
14
- ...rest
21
+ form
15
22
  };
16
23
  super(options);
17
24
  this.stepSchema = new MultiStepFormStepSchema$1(options);
@@ -24,15 +31,85 @@ var MultiStepFormSchema$1 = class extends MultiStepFormSchema {
24
31
  this.notify();
25
32
  }
26
33
  });
34
+ this.storageConfig = {
35
+ key: storage?.key ?? DEFAULT_STORAGE_KEY,
36
+ store: storage?.store,
37
+ throwWhenUndefined: storage?.throwWhenUndefined
38
+ };
39
+ this.storage = new MultiStepFormStorage({
40
+ data: this.stepSchema.value,
41
+ ...this.storageConfig
42
+ });
43
+ if (context) this.context = context;
44
+ if (form) this.formConfig = form;
45
+ }
46
+ /**
47
+ * A helper function to add a form configuration to the {@linkcode MultiStepFormSchema}.
48
+ *
49
+ * By calling this function, you will have access to the create form component in all step
50
+ * utility functions.
51
+ *
52
+ * @example
53
+ * ```tsx
54
+ * const schema = createMultiStepFormSchema({
55
+ * steps: {
56
+ * step1: {
57
+ * title: 'Step 1',
58
+ * fields: {
59
+ * firstName: {
60
+ * defaultValue: '',
61
+ * },
62
+ * },
63
+ * },
64
+ * },
65
+ * }).withForm({
66
+ * render(data) {
67
+ * return (props: MyCustomProps) => {
68
+ * return <form {...props}>{props.children}</form>;
69
+ * };
70
+ * },
71
+ * });
72
+ * ```
73
+ * @param config The form configuration.
74
+ * @returns A new {@linkcode MultiStepFormSchema} with the form configuration.
75
+ */
76
+ withForm(config) {
77
+ const { key, store, throwWhenUndefined } = this.storageConfig;
78
+ return new MultiStepFormSchema$1({
79
+ steps: this.stepSchema.original,
80
+ form: config,
81
+ nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,
82
+ storage: {
83
+ key,
84
+ store,
85
+ throwWhenUndefined
86
+ }
87
+ });
88
+ }
89
+ withContext() {
90
+ const context = createMultiStepFormContext(this);
91
+ return new MultiStepFormSchema$1({
92
+ steps: this.stepSchema.original,
93
+ form: this.formConfig,
94
+ nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,
95
+ storage: {
96
+ key: this.storageConfig.key,
97
+ store: this.storageConfig.store,
98
+ throwWhenUndefined: this.storageConfig.throwWhenUndefined
99
+ },
100
+ context
101
+ });
27
102
  }
28
103
  createComponent(options, fn) {
29
- const { stepData } = options;
30
- const ctx = createCtx(this.stepSchema.value, stepData);
31
- return ((props) => fn({
32
- ctx,
33
- update: this.#internal.createHelperFnInputUpdate(stepData),
34
- reset: this.#internal.createHelperFnInputReset(stepData)
35
- }, props));
104
+ return createComponent({
105
+ fn,
106
+ input: ({ stepData }) => ({
107
+ reset: this.#internal.createHelperFnInputReset(stepData),
108
+ update: this.#internal.createHelperFnInputUpdate(stepData)
109
+ }),
110
+ options,
111
+ value: this.stepSchema.value
112
+ });
36
113
  }
37
114
  };
38
115
  function createMultiStepFormSchema(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.mjs","names":["MultiStepFormSchema","MultiStepFormSchemaCore","#internal","MultiStepFormStepSchema"],"sources":["../src/schema.ts"],"sourcesContent":["import {\n type CasingType,\n type Constrain,\n createCtx,\n type CreateHelperFunctionOptionsBase,\n DEFAULT_CASING,\n type DefaultCasing,\n type DefaultStorageKey,\n type HelperFnChosenSteps,\n type MultiStepFormSchemaOptions as MultiStepFormSchemaBaseOptions,\n MultiStepFormSchema as MultiStepFormSchemaCore,\n type ResolvedStep as ResolvedStepCore,\n type Step,\n type StepNumbers,\n} from '@jfdevelops/multi-step-form-core';\nimport type { ComponentPropsWithRef } from 'react';\nimport { MultiStepFormSchemaConfig } from './form-config';\nimport {\n type CreateComponentCallback,\n type CreatedMultiStepFormComponent,\n type HelperFunctions,\n MultiStepFormStepSchema,\n type ResolvedStep,\n} from './step-schema';\nimport { MultiStepFormStepSchemaInternal } from '@jfdevelops/multi-step-form-core/_internals';\n\n// export type AnyMultiStepFormSchema = MultiStepFormSchema<any, any, any>;\nexport type AnyMultiStepFormSchema = { [x: string]: any };\n\n// Helper inference types for `AnyMultiStepFormSchema`\nexport namespace MultiStepFormSchema {\n /**\n * Infer the resolved step from a {@linkcode MultiStepFormSchema}.\n */\n export type resolvedStep<T extends AnyMultiStepFormSchema> =\n T['stepSchema']['value'];\n /**\n * Infer the {@linkcode MultiStepFormSchema}'s step numbers.\n */\n export type stepNumbers<T extends AnyMultiStepFormSchema> = StepNumbers<\n resolvedStep<T>\n >;\n /**\n * Get the data for a specific step from a {@linkcode MultiStepFormSchema}.\n */\n export type getData<\n T extends AnyMultiStepFormSchema,\n TTarget extends keyof resolvedStep<T>\n > = resolvedStep<T>[TTarget];\n}\n\nexport interface MultiStepFormSchemaOptions<\n TStep extends Step<TCasing>,\n TCasing extends CasingType,\n TStorageKey extends string,\n TFormAlias extends string,\n TFormEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<TResolvedStep>,\n TFormProps extends object,\n TResolvedStep extends ResolvedStep<TStep, TCasing> = ResolvedStep<\n TStep,\n TCasing\n >\n> extends MultiStepFormSchemaBaseOptions<TStep, TCasing, TStorageKey>,\n MultiStepFormSchemaConfig.Form<\n TResolvedStep,\n TFormAlias,\n TFormEnabledFor,\n TFormProps\n > {}\n\nexport class MultiStepFormSchema<\n step extends Step<casing>,\n casing extends CasingType = DefaultCasing,\n storageKey extends string = DefaultStorageKey,\n formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias,\n formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep> = MultiStepFormSchemaConfig.defaultEnabledFor,\n formProps extends object = ComponentPropsWithRef<'form'>,\n resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<\n step,\n casing\n >,\n stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n >\n extends MultiStepFormSchemaCore<\n step,\n casing,\n ResolvedStepCore<step, casing>,\n StepNumbers<ResolvedStepCore<step, casing>>,\n storageKey\n >\n implements HelperFunctions<resolvedStep, stepNumbers>\n{\n // @ts-ignore\n stepSchema: MultiStepFormStepSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >;\n readonly #internal: MultiStepFormStepSchemaInternal<\n step,\n casing,\n resolvedStep,\n stepNumbers\n >;\n\n constructor(\n config: MultiStepFormSchemaOptions<\n step,\n Constrain<casing, CasingType>,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >\n ) {\n const { nameTransformCasing = DEFAULT_CASING, storage, ...rest } = config;\n const options = { nameTransformCasing, storage, ...rest };\n\n super(options);\n\n this.stepSchema = new MultiStepFormStepSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >(options);\n this.#internal = new MultiStepFormStepSchemaInternal<\n step,\n casing,\n resolvedStep,\n stepNumbers\n >({\n originalValue: this.stepSchema.original,\n getValue: () => this.stepSchema.value as never,\n setValue: (value) => {\n this.stepSchema.value = { ...value } as never;\n this.storage.add(value);\n this.notify();\n },\n });\n }\n\n createComponent<\n chosenSteps extends HelperFnChosenSteps<resolvedStep, stepNumbers>,\n props = undefined\n >(\n options: CreateHelperFunctionOptionsBase<\n resolvedStep,\n stepNumbers,\n chosenSteps\n >,\n fn: CreateComponentCallback<resolvedStep, stepNumbers, chosenSteps, props>\n ): CreatedMultiStepFormComponent<props> {\n const { stepData } = options;\n const ctx = createCtx<resolvedStep, stepNumbers, chosenSteps>(\n this.stepSchema.value as never,\n stepData\n ) as never;\n\n return ((props?: props) =>\n fn(\n {\n ctx,\n update: this.#internal.createHelperFnInputUpdate(stepData),\n reset: this.#internal.createHelperFnInputReset(stepData),\n },\n props as any\n )) as any;\n }\n}\n\nexport function createMultiStepFormSchema<\n step extends Step<casing>,\n casing extends CasingType = DefaultCasing,\n storageKey extends string = DefaultStorageKey,\n formAlias extends string = MultiStepFormSchemaConfig.defaultFormAlias,\n formEnabledFor extends MultiStepFormSchemaConfig.formEnabledFor<resolvedStep> = MultiStepFormSchemaConfig.defaultEnabledFor,\n formProps extends object = ComponentPropsWithRef<'form'>,\n resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n>(\n options: MultiStepFormSchemaOptions<\n step,\n Constrain<casing, CasingType>,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps\n >\n) {\n return new MultiStepFormSchema<\n step,\n casing,\n storageKey,\n formAlias,\n formEnabledFor,\n formProps,\n resolvedStep,\n stepNumbers\n >(options);\n}\n"],"mappings":";;;;;AAsEA,IAAaA,wBAAb,cAaUC,oBAQV;CAEE;CAQA,CAASC;CAOT,YACE,QAQA;EACA,MAAM,EAAE,sBAAsB,gBAAgB,SAAS,GAAG,SAAS;EACnE,MAAM,UAAU;GAAE;GAAqB;GAAS,GAAG;GAAM;AAEzD,QAAM,QAAQ;AAEd,OAAK,aAAa,IAAIC,0BAOpB,QAAQ;AACV,QAAKD,WAAY,IAAI,gCAKnB;GACA,eAAe,KAAK,WAAW;GAC/B,gBAAgB,KAAK,WAAW;GAChC,WAAW,UAAU;AACnB,SAAK,WAAW,QAAQ,EAAE,GAAG,OAAO;AACpC,SAAK,QAAQ,IAAI,MAAM;AACvB,SAAK,QAAQ;;GAEhB,CAAC;;CAGJ,gBAIE,SAKA,IACsC;EACtC,MAAM,EAAE,aAAa;EACrB,MAAM,MAAM,UACV,KAAK,WAAW,OAChB,SACD;AAED,WAAS,UACP,GACE;GACE;GACA,QAAQ,MAAKA,SAAU,0BAA0B,SAAS;GAC1D,OAAO,MAAKA,SAAU,yBAAyB,SAAS;GACzD,EACD,MACD;;;AAIP,SAAgB,0BAUd,SAQA;AACA,QAAO,IAAIF,sBAST,QAAQ"}
1
+ {"version":3,"file":"schema.mjs","names":["MultiStepFormSchema","MultiStepFormSchemaCore","#internal","MultiStepFormStepSchema"],"sources":["../src/schema.ts"],"sourcesContent":["import {\n type BaseStorageConfig,\n DEFAULT_CASING,\n DEFAULT_STORAGE_KEY,\n type Expand,\n type HelperFn,\n type HelperFnChosenSteps,\n MultiStepFormSchema as MultiStepFormSchemaCore,\n MultiStepFormStorage,\n type steps,\n} from '@jfdevelops/multi-step-form-core';\nimport {\n MultiStepFormStepSchemaInternal,\n type StepSchema,\n} from '@jfdevelops/multi-step-form-core/_internals';\nimport {\n createMultiStepFormContext,\n type MultiStepFormContextResult,\n} from './create-context';\nimport { MultiStepFormSchemaConfig } from './form-config';\nimport { type HelperFunctions, MultiStepFormStepSchema } from './step-schema';\nimport { createComponent, type CreateComponentCallback } from './utils';\n\n// Helper inference types for `AnyMultiStepFormSchema`\nexport namespace MultiStepFormSchema {\n export type config<\n def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n > = MultiStepFormStepSchema.config<def, value> & {\n /**\n * The React context for the multi step form.\n *\n * This is a private property and is not meant to be used directly.\n * @private\n * @internal\n */\n context?: MultiStepFormContextResult<def, value>;\n };\n}\n\nexport class MultiStepFormSchema<\n const def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n>\n extends MultiStepFormSchemaCore<def, value>\n implements HelperFunctions<def, value>\n{\n stepSchema: MultiStepFormStepSchema<def, value>;\n readonly #internal: MultiStepFormStepSchemaInternal<def, value>;\n override readonly storage: MultiStepFormStorage<\n value,\n StepSchema.inferStorageKey<def>\n >;\n override readonly storageConfig: BaseStorageConfig<\n StepSchema.inferStorageKey<def>\n >;\n\n readonly context: MultiStepFormContextResult<def, value> = undefined as never;\n readonly formConfig: MultiStepFormSchemaConfig.FormConfig<def, value> =\n undefined as never;\n\n constructor(config: MultiStepFormSchema.config<def, value>) {\n const {\n nameTransformCasing = DEFAULT_CASING,\n steps,\n form,\n storage,\n context,\n } = config;\n const options = {\n steps,\n nameTransformCasing,\n storage,\n form,\n } as MultiStepFormStepSchema.config<def, value>;\n\n super(options);\n\n this.stepSchema = new MultiStepFormStepSchema(options);\n this.#internal = new MultiStepFormStepSchemaInternal({\n originalValue: this.stepSchema.original,\n getValue: () => this.stepSchema.value,\n setValue: (value) => {\n this.stepSchema.value = { ...value };\n this.storage.add(value);\n this.notify();\n },\n });\n this.storageConfig = {\n key: (storage?.key ??\n DEFAULT_STORAGE_KEY) as StepSchema.inferStorageKey<def>,\n store: storage?.store,\n throwWhenUndefined: storage?.throwWhenUndefined,\n };\n this.storage = new MultiStepFormStorage({\n data: this.stepSchema.value,\n ...this.storageConfig,\n });\n if (context) {\n this.context = context;\n }\n\n if (form) {\n this.formConfig = form;\n }\n }\n\n /**\n * A helper function to add a form configuration to the {@linkcode MultiStepFormSchema}.\n *\n * By calling this function, you will have access to the create form component in all step\n * utility functions.\n *\n * @example\n * ```tsx\n * const schema = createMultiStepFormSchema({\n * steps: {\n * step1: {\n * title: 'Step 1',\n * fields: {\n * firstName: {\n * defaultValue: '',\n * },\n * },\n * },\n * },\n * }).withForm({\n * render(data) {\n * return (props: MyCustomProps) => {\n * return <form {...props}>{props.children}</form>;\n * };\n * },\n * });\n * ```\n * @param config The form configuration.\n * @returns A new {@linkcode MultiStepFormSchema} with the form configuration.\n */\n withForm<\n const formConfig extends MultiStepFormSchemaConfig.FormConfig<def, value>,\n >(config: formConfig) {\n const { key, store, throwWhenUndefined } = this.storageConfig;\n\n return new MultiStepFormSchema<\n Expand<def & Readonly<{ form: formConfig }>>\n >({\n steps: this.stepSchema.original,\n form: config,\n nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,\n storage: {\n key,\n store,\n throwWhenUndefined: throwWhenUndefined,\n },\n } as never);\n }\n\n withContext() {\n const context = createMultiStepFormContext(this);\n\n return new MultiStepFormSchema<def, value>({\n steps: this.stepSchema.original,\n form: this.formConfig,\n nameTransformCasing: this.stepSchema.defaultNameTransformationCasing,\n storage: {\n key: this.storageConfig.key,\n store: this.storageConfig.store,\n throwWhenUndefined: this.storageConfig.throwWhenUndefined,\n },\n context,\n } as never);\n }\n\n createComponent<\n chosenSteps extends HelperFnChosenSteps.main<\n value,\n steps.StepNumbers<value>\n >,\n props = undefined,\n >(\n options: HelperFn.BaseOptions<value, chosenSteps>,\n fn: CreateComponentCallback<value, chosenSteps, props>\n ) {\n return createComponent({\n fn,\n input: ({ stepData }) => ({\n reset: this.#internal.createHelperFnInputReset(stepData),\n update: this.#internal.createHelperFnInputUpdate(stepData),\n }),\n options,\n value: this.stepSchema.value,\n });\n }\n}\n\nexport function createMultiStepFormSchema<\n const def extends StepSchema.Config,\n value extends steps.instantiateSteps<def> = steps.instantiateSteps<def>,\n>(options: def) {\n return new MultiStepFormSchema<def, value>(options);\n}\n"],"mappings":";;;;;;;AAwCA,IAAaA,wBAAb,MAAaA,8BAIHC,oBAEV;CACE;CACA,CAASC;CACT,AAAkB;CAIlB,AAAkB;CAIlB,AAAS,UAAkD;CAC3D,AAAS,aACP;CAEF,YAAY,QAAgD;EAC1D,MAAM,EACJ,sBAAsB,gBACtB,gBACA,MACA,SACA,YACE;EACJ,MAAM,UAAU;GACd;GACA;GACA;GACA;GACD;AAED,QAAM,QAAQ;AAEd,OAAK,aAAa,IAAIC,0BAAwB,QAAQ;AACtD,QAAKD,WAAY,IAAI,gCAAgC;GACnD,eAAe,KAAK,WAAW;GAC/B,gBAAgB,KAAK,WAAW;GAChC,WAAW,UAAU;AACnB,SAAK,WAAW,QAAQ,EAAE,GAAG,OAAO;AACpC,SAAK,QAAQ,IAAI,MAAM;AACvB,SAAK,QAAQ;;GAEhB,CAAC;AACF,OAAK,gBAAgB;GACnB,KAAM,SAAS,OACb;GACF,OAAO,SAAS;GAChB,oBAAoB,SAAS;GAC9B;AACD,OAAK,UAAU,IAAI,qBAAqB;GACtC,MAAM,KAAK,WAAW;GACtB,GAAG,KAAK;GACT,CAAC;AACF,MAAI,QACF,MAAK,UAAU;AAGjB,MAAI,KACF,MAAK,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCtB,SAEE,QAAoB;EACpB,MAAM,EAAE,KAAK,OAAO,uBAAuB,KAAK;AAEhD,SAAO,IAAIF,sBAET;GACA,OAAO,KAAK,WAAW;GACvB,MAAM;GACN,qBAAqB,KAAK,WAAW;GACrC,SAAS;IACP;IACA;IACoB;IACrB;GACF,CAAU;;CAGb,cAAc;EACZ,MAAM,UAAU,2BAA2B,KAAK;AAEhD,SAAO,IAAIA,sBAAgC;GACzC,OAAO,KAAK,WAAW;GACvB,MAAM,KAAK;GACX,qBAAqB,KAAK,WAAW;GACrC,SAAS;IACP,KAAK,KAAK,cAAc;IACxB,OAAO,KAAK,cAAc;IAC1B,oBAAoB,KAAK,cAAc;IACxC;GACD;GACD,CAAU;;CAGb,gBAOE,SACA,IACA;AACA,SAAO,gBAAgB;GACrB;GACA,QAAQ,EAAE,gBAAgB;IACxB,OAAO,MAAKE,SAAU,yBAAyB,SAAS;IACxD,QAAQ,MAAKA,SAAU,0BAA0B,SAAS;IAC3D;GACD;GACA,OAAO,KAAK,WAAW;GACxB,CAAC;;;AAIN,SAAgB,0BAGd,SAAc;AACd,QAAO,IAAIF,sBAAgC,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"selector.cjs","names":["createUseSelector","Selector: component<TCurrentStep>","MultiStepFormLogger","selector","Fragment"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n Expand,\n MultiStepFormLogger,\n type CurrentStepHelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { createElement, useMemo } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport {\n createUseSelector,\n SelectorFn,\n type DebugOptions,\n} from './hooks/use-selector';\n\nexport namespace selector {\n export type props<TCurrentStep extends AnyResolvedStep, TSelected> = {\n selector: SelectorFn<TCurrentStep, TSelected>;\n children?: (selected: TSelected) => React.ReactNode;\n /**\n * Optional debug options to customize logging behavior.\n */\n debug?: boolean | DebugOptions<TSelected>;\n };\n export type component<TCurrentStep extends AnyResolvedStep> =\n /**\n * A component for reactively displaying a value from the form context.\n * Unlike `useSelector`, this component only re-renders itself, not the parent component.\n * Use this when you want to display a reactive value without causing parent re-renders.\n *\n * @param props - The props for the Selector component.\n *\n * @example\n * ```tsx\n * // With no debug options (default behavior)\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n\n * @example\n * ```tsx\n * // With debug enabled\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n *\n * @example\n * ```tsx\n * // With custom debug options\n * <Selector\n * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}\n * debug={{\n * onRender: (value) => console.log('Rendered with:', value),\n * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)\n * }}\n * >\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n */\n <TSelected>(props: props<TCurrentStep, TSelected>) => React.ReactNode;\n\n export function create<TCurrentStep extends AnyResolvedStep>(\n createCtx: () => Expand<CurrentStepHelperFnCtx<TCurrentStep>>,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<TCurrentStep> = ({\n selector,\n children,\n debug,\n }) => {\n const isDebugEnabled =\n typeof debug === 'boolean' ? debug : debug !== undefined;\n const debugOptions = typeof debug === 'object' ? debug : undefined;\n const prefix = debugOptions?.prefix;\n\n const logger = useMemo(() => {\n if (!isDebugEnabled) {\n return undefined;\n }\n\n return new MultiStepFormLogger({\n debug: true,\n prefix: (defaultValue) => {\n const defaultPrefix = `${defaultValue}-Selector`;\n console.log(prefix);\n\n // If no prefix is provided, use default\n if (!prefix) {\n return defaultPrefix;\n }\n\n // If prefix is a string, use it directly\n if (typeof prefix === 'string') {\n return prefix;\n }\n\n // If prefix is a function, call it with the default prefix\n if (typeof prefix === 'function') {\n return prefix(defaultValue);\n }\n\n // If prefix is an object with action/value, handle prepend/append\n if (typeof prefix === 'object') {\n const { action = 'prepend', value, delimiter = '-' } = prefix;\n const resolvedValue =\n typeof value === 'function' ? value(defaultValue) : value;\n\n if (action === 'prepend') {\n return `${resolvedValue}${delimiter}${defaultPrefix}`;\n }\n\n if (action === 'append') {\n return `${defaultPrefix}${delimiter}${resolvedValue}`;\n }\n\n return defaultPrefix;\n }\n\n return defaultPrefix;\n },\n });\n }, [isDebugEnabled, prefix]);\n\n const selected = useSelector(selector, logger, debugOptions);\n\n logger?.info(\n debugOptions?.onRender?.(selected) ??\n `Rendering with selected: ${JSON.stringify(selected)}`\n );\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n // Remove memo to test if it's causing the issue\n // The memo was meant to prevent re-renders when parent re-renders,\n // but useSyncExternalStore should handle reactivity\n return Selector;\n }\n}\n"],"mappings":";;;;;;;;CA+DS,SAAS,OACd,WACA,WACA;EACA,MAAM,cAAcA,uCAAkB,WAAW,UAAU;EAC3D,MAAMC,YAAqC,EACzC,sBACA,UACA,YACI;GACJ,MAAM,iBACJ,OAAO,UAAU,YAAY,QAAQ,UAAU;GACjD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ;GACzD,MAAM,SAAS,cAAc;GAE7B,MAAM,kCAAuB;AAC3B,QAAI,CAAC,eACH;AAGF,WAAO,IAAIC,sDAAoB;KAC7B,OAAO;KACP,SAAS,iBAAiB;MACxB,MAAM,gBAAgB,GAAG,aAAa;AACtC,cAAQ,IAAI,OAAO;AAGnB,UAAI,CAAC,OACH,QAAO;AAIT,UAAI,OAAO,WAAW,SACpB,QAAO;AAIT,UAAI,OAAO,WAAW,WACpB,QAAO,OAAO,aAAa;AAI7B,UAAI,OAAO,WAAW,UAAU;OAC9B,MAAM,EAAE,SAAS,WAAW,OAAO,YAAY,QAAQ;OACvD,MAAM,gBACJ,OAAO,UAAU,aAAa,MAAM,aAAa,GAAG;AAEtD,WAAI,WAAW,UACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,WAAI,WAAW,SACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,cAAO;;AAGT,aAAO;;KAEV,CAAC;MACD,CAAC,gBAAgB,OAAO,CAAC;GAE5B,MAAM,WAAW,YAAYC,YAAU,QAAQ,aAAa;AAE5D,WAAQ,KACN,cAAc,WAAW,SAAS,IAChC,4BAA4B,KAAK,UAAU,SAAS,GACvD;AAED,OAAI,SACF,iCAAqBC,4BAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,mCAAqBA,4BAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAM9D,SAAO"}
1
+ {"version":3,"file":"selector.cjs","names":["createUseSelector","Selector: component<steps>","MultiStepFormLogger","selector","Fragment"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n type Expand,\n type HelperFn,\n MultiStepFormLogger,\n type steps,\n} from '@jfdevelops/multi-step-form-core';\nimport { createElement, useMemo } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport {\n createUseSelector,\n type DebugOptions,\n type SelectorFn,\n} from './hooks/use-selector';\n\nexport namespace selector {\n export type props<steps extends steps.instantiateSteps, selected> = {\n selector: SelectorFn<steps, selected>;\n children?: (selected: selected) => React.ReactNode;\n /**\n * Optional debug options to customize logging behavior.\n */\n debug?: boolean | DebugOptions<selected>;\n };\n export type component<steps extends steps.instantiateSteps> =\n /**\n * A component for reactively displaying a value from the form context.\n * Unlike `useSelector`, this component only re-renders itself, not the parent component.\n * Use this when you want to display a reactive value without causing parent re-renders.\n *\n * @param props - The props for the Selector component.\n *\n * @example\n * ```tsx\n * // With no debug options (default behavior)\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n\n * @example\n * ```tsx\n * // With debug enabled\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n *\n * @example\n * ```tsx\n * // With custom debug options\n * <Selector\n * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}\n * debug={{\n * onRender: (value) => console.log('Rendered with:', value),\n * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)\n * }}\n * >\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n */\n <selected>(props: props<steps, selected>) => React.ReactNode;\n\n export function create<steps extends steps.instantiateSteps>(\n createCtx: () => Expand<\n HelperFn.buildCtx<steps, [steps.StepNumbers<steps>]>\n >,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<steps> = ({ selector, children, debug }) => {\n const isDebugEnabled =\n typeof debug === 'boolean' ? debug : debug !== undefined;\n const debugOptions = typeof debug === 'object' ? debug : undefined;\n const prefix = debugOptions?.prefix;\n\n const logger = useMemo(() => {\n if (!isDebugEnabled) {\n return undefined;\n }\n\n return new MultiStepFormLogger({\n debug: true,\n prefix: (defaultValue) => {\n const defaultPrefix = `${defaultValue}-Selector`;\n console.log(prefix);\n\n // If no prefix is provided, use default\n if (!prefix) {\n return defaultPrefix;\n }\n\n // If prefix is a string, use it directly\n if (typeof prefix === 'string') {\n return prefix;\n }\n\n // If prefix is a function, call it with the default prefix\n if (typeof prefix === 'function') {\n return prefix(defaultValue);\n }\n\n // If prefix is an object with action/value, handle prepend/append\n if (typeof prefix === 'object') {\n const { action = 'prepend', value, delimiter = '-' } = prefix;\n const resolvedValue =\n typeof value === 'function' ? value(defaultValue) : value;\n\n if (action === 'prepend') {\n return `${resolvedValue}${delimiter}${defaultPrefix}`;\n }\n\n if (action === 'append') {\n return `${defaultPrefix}${delimiter}${resolvedValue}`;\n }\n\n return defaultPrefix;\n }\n\n return defaultPrefix;\n },\n });\n }, [isDebugEnabled, prefix]);\n\n const selected = useSelector(selector, logger, debugOptions);\n\n logger?.info(\n debugOptions?.onRender?.(selected) ??\n `Rendering with selected: ${JSON.stringify(selected)}`\n );\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n // Remove memo to test if it's causing the issue\n // The memo was meant to prevent re-renders when parent re-renders,\n // but useSyncExternalStore should handle reactivity\n return Selector;\n }\n}\n"],"mappings":";;;;;;;;CA+DS,SAAS,OACd,WAGA,WACA;EACA,MAAM,cAAcA,uCAAkB,WAAW,UAAU;EAC3D,MAAMC,YAA8B,EAAE,sBAAU,UAAU,YAAY;GACpE,MAAM,iBACJ,OAAO,UAAU,YAAY,QAAQ,UAAU;GACjD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ;GACzD,MAAM,SAAS,cAAc;GAE7B,MAAM,kCAAuB;AAC3B,QAAI,CAAC,eACH;AAGF,WAAO,IAAIC,sDAAoB;KAC7B,OAAO;KACP,SAAS,iBAAiB;MACxB,MAAM,gBAAgB,GAAG,aAAa;AACtC,cAAQ,IAAI,OAAO;AAGnB,UAAI,CAAC,OACH,QAAO;AAIT,UAAI,OAAO,WAAW,SACpB,QAAO;AAIT,UAAI,OAAO,WAAW,WACpB,QAAO,OAAO,aAAa;AAI7B,UAAI,OAAO,WAAW,UAAU;OAC9B,MAAM,EAAE,SAAS,WAAW,OAAO,YAAY,QAAQ;OACvD,MAAM,gBACJ,OAAO,UAAU,aAAa,MAAM,aAAa,GAAG;AAEtD,WAAI,WAAW,UACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,WAAI,WAAW,SACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,cAAO;;AAGT,aAAO;;KAEV,CAAC;MACD,CAAC,gBAAgB,OAAO,CAAC;GAE5B,MAAM,WAAW,YAAYC,YAAU,QAAQ,aAAa;AAE5D,WAAQ,KACN,cAAc,WAAW,SAAS,IAChC,4BAA4B,KAAK,UAAU,SAAS,GACvD;AAED,OAAI,SACF,iCAAqBC,4BAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,mCAAqBA,4BAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAM9D,SAAO"}
@@ -1,17 +1,17 @@
1
1
  import { DebugOptions, SelectorFn } from "./hooks/use-selector.cjs";
2
- import { AnyResolvedStep, CurrentStepHelperFnCtx, Expand } from "@jfdevelops/multi-step-form-core";
2
+ import { Expand, HelperFn } from "@jfdevelops/multi-step-form-core";
3
3
 
4
4
  //#region src/selector.d.ts
5
5
  declare namespace selector {
6
- type props<TCurrentStep extends AnyResolvedStep, TSelected> = {
7
- selector: SelectorFn<TCurrentStep, TSelected>;
8
- children?: (selected: TSelected) => React.ReactNode;
6
+ type props<steps$1 extends steps$1.instantiateSteps, selected> = {
7
+ selector: SelectorFn<steps$1, selected>;
8
+ children?: (selected: selected) => React.ReactNode;
9
9
  /**
10
10
  * Optional debug options to customize logging behavior.
11
11
  */
12
- debug?: boolean | DebugOptions<TSelected>;
12
+ debug?: boolean | DebugOptions<selected>;
13
13
  };
14
- type component<TCurrentStep extends AnyResolvedStep> =
14
+ type component<steps$1 extends steps$1.instantiateSteps> =
15
15
  /**
16
16
  * A component for reactively displaying a value from the form context.
17
17
  * Unlike `useSelector`, this component only re-renders itself, not the parent component.
@@ -48,8 +48,8 @@ declare namespace selector {
48
48
  * </Selector>
49
49
  * ```
50
50
  */
51
- <TSelected>(props: props<TCurrentStep, TSelected>) => React.ReactNode;
52
- function create<TCurrentStep extends AnyResolvedStep>(createCtx: () => Expand<CurrentStepHelperFnCtx<TCurrentStep>>, subscribe: (listener: () => void) => () => void): component<TCurrentStep>;
51
+ <selected>(props: props<steps$1, selected>) => React.ReactNode;
52
+ function create<steps$1 extends steps$1.instantiateSteps>(createCtx: () => Expand<HelperFn.buildCtx<steps$1, [steps$1.StepNumbers<steps$1>]>>, subscribe: (listener: () => void) => () => void): component<steps$1>;
53
53
  }
54
54
  //#endregion
55
55
  export { selector };
@@ -1,17 +1,17 @@
1
1
  import { DebugOptions, SelectorFn } from "./hooks/use-selector.mjs";
2
- import { AnyResolvedStep, CurrentStepHelperFnCtx, Expand } from "@jfdevelops/multi-step-form-core";
2
+ import { Expand, HelperFn } from "@jfdevelops/multi-step-form-core";
3
3
 
4
4
  //#region src/selector.d.ts
5
5
  declare namespace selector {
6
- type props<TCurrentStep extends AnyResolvedStep, TSelected> = {
7
- selector: SelectorFn<TCurrentStep, TSelected>;
8
- children?: (selected: TSelected) => React.ReactNode;
6
+ type props<steps$1 extends steps$1.instantiateSteps, selected> = {
7
+ selector: SelectorFn<steps$1, selected>;
8
+ children?: (selected: selected) => React.ReactNode;
9
9
  /**
10
10
  * Optional debug options to customize logging behavior.
11
11
  */
12
- debug?: boolean | DebugOptions<TSelected>;
12
+ debug?: boolean | DebugOptions<selected>;
13
13
  };
14
- type component<TCurrentStep extends AnyResolvedStep> =
14
+ type component<steps$1 extends steps$1.instantiateSteps> =
15
15
  /**
16
16
  * A component for reactively displaying a value from the form context.
17
17
  * Unlike `useSelector`, this component only re-renders itself, not the parent component.
@@ -48,8 +48,8 @@ declare namespace selector {
48
48
  * </Selector>
49
49
  * ```
50
50
  */
51
- <TSelected>(props: props<TCurrentStep, TSelected>) => React.ReactNode;
52
- function create<TCurrentStep extends AnyResolvedStep>(createCtx: () => Expand<CurrentStepHelperFnCtx<TCurrentStep>>, subscribe: (listener: () => void) => () => void): component<TCurrentStep>;
51
+ <selected>(props: props<steps$1, selected>) => React.ReactNode;
52
+ function create<steps$1 extends steps$1.instantiateSteps>(createCtx: () => Expand<HelperFn.buildCtx<steps$1, [steps$1.StepNumbers<steps$1>]>>, subscribe: (listener: () => void) => () => void): component<steps$1>;
53
53
  }
54
54
  //#endregion
55
55
  export { selector };
@@ -1 +1 @@
1
- {"version":3,"file":"selector.mjs","names":["createCtx","Selector: component<TCurrentStep>","selector"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n Expand,\n MultiStepFormLogger,\n type CurrentStepHelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { createElement, useMemo } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport {\n createUseSelector,\n SelectorFn,\n type DebugOptions,\n} from './hooks/use-selector';\n\nexport namespace selector {\n export type props<TCurrentStep extends AnyResolvedStep, TSelected> = {\n selector: SelectorFn<TCurrentStep, TSelected>;\n children?: (selected: TSelected) => React.ReactNode;\n /**\n * Optional debug options to customize logging behavior.\n */\n debug?: boolean | DebugOptions<TSelected>;\n };\n export type component<TCurrentStep extends AnyResolvedStep> =\n /**\n * A component for reactively displaying a value from the form context.\n * Unlike `useSelector`, this component only re-renders itself, not the parent component.\n * Use this when you want to display a reactive value without causing parent re-renders.\n *\n * @param props - The props for the Selector component.\n *\n * @example\n * ```tsx\n * // With no debug options (default behavior)\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n\n * @example\n * ```tsx\n * // With debug enabled\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n *\n * @example\n * ```tsx\n * // With custom debug options\n * <Selector\n * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}\n * debug={{\n * onRender: (value) => console.log('Rendered with:', value),\n * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)\n * }}\n * >\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n */\n <TSelected>(props: props<TCurrentStep, TSelected>) => React.ReactNode;\n\n export function create<TCurrentStep extends AnyResolvedStep>(\n createCtx: () => Expand<CurrentStepHelperFnCtx<TCurrentStep>>,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<TCurrentStep> = ({\n selector,\n children,\n debug,\n }) => {\n const isDebugEnabled =\n typeof debug === 'boolean' ? debug : debug !== undefined;\n const debugOptions = typeof debug === 'object' ? debug : undefined;\n const prefix = debugOptions?.prefix;\n\n const logger = useMemo(() => {\n if (!isDebugEnabled) {\n return undefined;\n }\n\n return new MultiStepFormLogger({\n debug: true,\n prefix: (defaultValue) => {\n const defaultPrefix = `${defaultValue}-Selector`;\n console.log(prefix);\n\n // If no prefix is provided, use default\n if (!prefix) {\n return defaultPrefix;\n }\n\n // If prefix is a string, use it directly\n if (typeof prefix === 'string') {\n return prefix;\n }\n\n // If prefix is a function, call it with the default prefix\n if (typeof prefix === 'function') {\n return prefix(defaultValue);\n }\n\n // If prefix is an object with action/value, handle prepend/append\n if (typeof prefix === 'object') {\n const { action = 'prepend', value, delimiter = '-' } = prefix;\n const resolvedValue =\n typeof value === 'function' ? value(defaultValue) : value;\n\n if (action === 'prepend') {\n return `${resolvedValue}${delimiter}${defaultPrefix}`;\n }\n\n if (action === 'append') {\n return `${defaultPrefix}${delimiter}${resolvedValue}`;\n }\n\n return defaultPrefix;\n }\n\n return defaultPrefix;\n },\n });\n }, [isDebugEnabled, prefix]);\n\n const selected = useSelector(selector, logger, debugOptions);\n\n logger?.info(\n debugOptions?.onRender?.(selected) ??\n `Rendering with selected: ${JSON.stringify(selected)}`\n );\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n // Remove memo to test if it's causing the issue\n // The memo was meant to prevent re-renders when parent re-renders,\n // but useSyncExternalStore should handle reactivity\n return Selector;\n }\n}\n"],"mappings":";;;;;;;;CA+DS,SAAS,OACd,aACA,WACA;EACA,MAAM,cAAc,kBAAkBA,aAAW,UAAU;EAC3D,MAAMC,YAAqC,EACzC,sBACA,UACA,YACI;GACJ,MAAM,iBACJ,OAAO,UAAU,YAAY,QAAQ,UAAU;GACjD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ;GACzD,MAAM,SAAS,cAAc;GAE7B,MAAM,SAAS,cAAc;AAC3B,QAAI,CAAC,eACH;AAGF,WAAO,IAAI,oBAAoB;KAC7B,OAAO;KACP,SAAS,iBAAiB;MACxB,MAAM,gBAAgB,GAAG,aAAa;AACtC,cAAQ,IAAI,OAAO;AAGnB,UAAI,CAAC,OACH,QAAO;AAIT,UAAI,OAAO,WAAW,SACpB,QAAO;AAIT,UAAI,OAAO,WAAW,WACpB,QAAO,OAAO,aAAa;AAI7B,UAAI,OAAO,WAAW,UAAU;OAC9B,MAAM,EAAE,SAAS,WAAW,OAAO,YAAY,QAAQ;OACvD,MAAM,gBACJ,OAAO,UAAU,aAAa,MAAM,aAAa,GAAG;AAEtD,WAAI,WAAW,UACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,WAAI,WAAW,SACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,cAAO;;AAGT,aAAO;;KAEV,CAAC;MACD,CAAC,gBAAgB,OAAO,CAAC;GAE5B,MAAM,WAAW,YAAYC,YAAU,QAAQ,aAAa;AAE5D,WAAQ,KACN,cAAc,WAAW,SAAS,IAChC,4BAA4B,KAAK,UAAU,SAAS,GACvD;AAED,OAAI,SACF,QAAO,cAAc,UAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,UAAO,cAAc,UAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAM9D,SAAO"}
1
+ {"version":3,"file":"selector.mjs","names":["createCtx","Selector: component<steps>","selector"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n type Expand,\n type HelperFn,\n MultiStepFormLogger,\n type steps,\n} from '@jfdevelops/multi-step-form-core';\nimport { createElement, useMemo } from 'react';\nimport { Fragment } from 'react/jsx-runtime';\nimport {\n createUseSelector,\n type DebugOptions,\n type SelectorFn,\n} from './hooks/use-selector';\n\nexport namespace selector {\n export type props<steps extends steps.instantiateSteps, selected> = {\n selector: SelectorFn<steps, selected>;\n children?: (selected: selected) => React.ReactNode;\n /**\n * Optional debug options to customize logging behavior.\n */\n debug?: boolean | DebugOptions<selected>;\n };\n export type component<steps extends steps.instantiateSteps> =\n /**\n * A component for reactively displaying a value from the form context.\n * Unlike `useSelector`, this component only re-renders itself, not the parent component.\n * Use this when you want to display a reactive value without causing parent re-renders.\n *\n * @param props - The props for the Selector component.\n *\n * @example\n * ```tsx\n * // With no debug options (default behavior)\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n\n * @example\n * ```tsx\n * // With debug enabled\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n *\n * @example\n * ```tsx\n * // With custom debug options\n * <Selector\n * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}\n * debug={{\n * onRender: (value) => console.log('Rendered with:', value),\n * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)\n * }}\n * >\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\n * ```\n */\n <selected>(props: props<steps, selected>) => React.ReactNode;\n\n export function create<steps extends steps.instantiateSteps>(\n createCtx: () => Expand<\n HelperFn.buildCtx<steps, [steps.StepNumbers<steps>]>\n >,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<steps> = ({ selector, children, debug }) => {\n const isDebugEnabled =\n typeof debug === 'boolean' ? debug : debug !== undefined;\n const debugOptions = typeof debug === 'object' ? debug : undefined;\n const prefix = debugOptions?.prefix;\n\n const logger = useMemo(() => {\n if (!isDebugEnabled) {\n return undefined;\n }\n\n return new MultiStepFormLogger({\n debug: true,\n prefix: (defaultValue) => {\n const defaultPrefix = `${defaultValue}-Selector`;\n console.log(prefix);\n\n // If no prefix is provided, use default\n if (!prefix) {\n return defaultPrefix;\n }\n\n // If prefix is a string, use it directly\n if (typeof prefix === 'string') {\n return prefix;\n }\n\n // If prefix is a function, call it with the default prefix\n if (typeof prefix === 'function') {\n return prefix(defaultValue);\n }\n\n // If prefix is an object with action/value, handle prepend/append\n if (typeof prefix === 'object') {\n const { action = 'prepend', value, delimiter = '-' } = prefix;\n const resolvedValue =\n typeof value === 'function' ? value(defaultValue) : value;\n\n if (action === 'prepend') {\n return `${resolvedValue}${delimiter}${defaultPrefix}`;\n }\n\n if (action === 'append') {\n return `${defaultPrefix}${delimiter}${resolvedValue}`;\n }\n\n return defaultPrefix;\n }\n\n return defaultPrefix;\n },\n });\n }, [isDebugEnabled, prefix]);\n\n const selected = useSelector(selector, logger, debugOptions);\n\n logger?.info(\n debugOptions?.onRender?.(selected) ??\n `Rendering with selected: ${JSON.stringify(selected)}`\n );\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n // Remove memo to test if it's causing the issue\n // The memo was meant to prevent re-renders when parent re-renders,\n // but useSyncExternalStore should handle reactivity\n return Selector;\n }\n}\n"],"mappings":";;;;;;;;CA+DS,SAAS,OACd,aAGA,WACA;EACA,MAAM,cAAc,kBAAkBA,aAAW,UAAU;EAC3D,MAAMC,YAA8B,EAAE,sBAAU,UAAU,YAAY;GACpE,MAAM,iBACJ,OAAO,UAAU,YAAY,QAAQ,UAAU;GACjD,MAAM,eAAe,OAAO,UAAU,WAAW,QAAQ;GACzD,MAAM,SAAS,cAAc;GAE7B,MAAM,SAAS,cAAc;AAC3B,QAAI,CAAC,eACH;AAGF,WAAO,IAAI,oBAAoB;KAC7B,OAAO;KACP,SAAS,iBAAiB;MACxB,MAAM,gBAAgB,GAAG,aAAa;AACtC,cAAQ,IAAI,OAAO;AAGnB,UAAI,CAAC,OACH,QAAO;AAIT,UAAI,OAAO,WAAW,SACpB,QAAO;AAIT,UAAI,OAAO,WAAW,WACpB,QAAO,OAAO,aAAa;AAI7B,UAAI,OAAO,WAAW,UAAU;OAC9B,MAAM,EAAE,SAAS,WAAW,OAAO,YAAY,QAAQ;OACvD,MAAM,gBACJ,OAAO,UAAU,aAAa,MAAM,aAAa,GAAG;AAEtD,WAAI,WAAW,UACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,WAAI,WAAW,SACb,QAAO,GAAG,gBAAgB,YAAY;AAGxC,cAAO;;AAGT,aAAO;;KAEV,CAAC;MACD,CAAC,gBAAgB,OAAO,CAAC;GAE5B,MAAM,WAAW,YAAYC,YAAU,QAAQ,aAAa;AAE5D,WAAQ,KACN,cAAc,WAAW,SAAS,IAChC,4BAA4B,KAAK,UAAU,SAAS,GACvD;AAED,OAAI,SACF,QAAO,cAAc,UAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,UAAO,cAAc,UAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAM9D,SAAO"}