@jfdevelops/react-multi-step-form 1.0.0-alpha.20 → 1.0.0-alpha.22

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 (41) hide show
  1. package/package.json +2 -2
  2. package/dist/create-context.cjs +0 -92
  3. package/dist/create-context.cjs.map +0 -1
  4. package/dist/create-context.d.cts +0 -154
  5. package/dist/create-context.d.mts +0 -154
  6. package/dist/create-context.mjs +0 -92
  7. package/dist/create-context.mjs.map +0 -1
  8. package/dist/field.cjs +0 -22
  9. package/dist/field.cjs.map +0 -1
  10. package/dist/field.d.cts +0 -38
  11. package/dist/field.d.mts +0 -38
  12. package/dist/field.mjs +0 -16
  13. package/dist/field.mjs.map +0 -1
  14. package/dist/form-config.cjs +0 -32
  15. package/dist/form-config.cjs.map +0 -1
  16. package/dist/form-config.d.cts +0 -160
  17. package/dist/form-config.d.mts +0 -160
  18. package/dist/form-config.mjs +0 -27
  19. package/dist/form-config.mjs.map +0 -1
  20. package/dist/hooks/use-multi-step-form-data.cjs +0 -41
  21. package/dist/hooks/use-multi-step-form-data.cjs.map +0 -1
  22. package/dist/hooks/use-multi-step-form-data.d.cts +0 -28
  23. package/dist/hooks/use-multi-step-form-data.d.mts +0 -28
  24. package/dist/hooks/use-multi-step-form-data.mjs +0 -39
  25. package/dist/hooks/use-multi-step-form-data.mjs.map +0 -1
  26. package/dist/index.cjs +0 -17
  27. package/dist/index.d.cts +0 -5
  28. package/dist/index.d.mts +0 -5
  29. package/dist/index.mjs +0 -6
  30. package/dist/schema.cjs +0 -45
  31. package/dist/schema.cjs.map +0 -1
  32. package/dist/schema.d.cts +0 -34
  33. package/dist/schema.d.mts +0 -34
  34. package/dist/schema.mjs +0 -44
  35. package/dist/schema.mjs.map +0 -1
  36. package/dist/step-schema.cjs +0 -237
  37. package/dist/step-schema.cjs.map +0 -1
  38. package/dist/step-schema.d.cts +0 -136
  39. package/dist/step-schema.d.mts +0 -136
  40. package/dist/step-schema.mjs +0 -230
  41. package/dist/step-schema.mjs.map +0 -1
@@ -1,39 +0,0 @@
1
- import { VALIDATED_STEP_REGEX, invariant } from "@jfdevelops/multi-step-form-core";
2
- import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
3
-
4
- //#region src/hooks/use-multi-step-form-data.ts
5
- function throwIfInvalidStepNumber(schema, targetStep) {
6
- invariant(typeof targetStep === "string", `The target step must be a string, was ${typeof targetStep}`);
7
- const { as, isValidStepNumber } = schema.stepSchema.steps;
8
- const formattedStepNumbersList = new Intl.ListFormat("en", {
9
- type: "disjunction",
10
- style: "long"
11
- }).format(as("array.string.untyped"));
12
- invariant(VALIDATED_STEP_REGEX.test(targetStep), `The target step must match the following format: "step{number}". Available steps are ${formattedStepNumbersList}`);
13
- const stepNumber = Number.parseInt(targetStep.replace("step", ""));
14
- invariant(isValidStepNumber(stepNumber), `The step number "${stepNumber}" is not a valid step number. Valid step numbers include ${formattedStepNumbersList}`, TypeError);
15
- return stepNumber;
16
- }
17
- function createMultiStepFormDataHook(schema) {
18
- function useMultiStepFormData$1(optionsOrSelector) {
19
- return useSyncExternalStoreWithSelector(schema.subscribe, () => schema.getSnapshot(), () => schema.getSnapshot(), (snapshot) => {
20
- if (typeof optionsOrSelector === "object") {
21
- const stepNumber = throwIfInvalidStepNumber(snapshot, optionsOrSelector.targetStep);
22
- return snapshot.stepSchema.get({ step: stepNumber }).data;
23
- }
24
- if (typeof optionsOrSelector === "function") return optionsOrSelector(snapshot);
25
- return snapshot;
26
- });
27
- }
28
- return useMultiStepFormData$1;
29
- }
30
- function useMultiStepFormData(schema, optionsOrSelector) {
31
- const hook = createMultiStepFormDataHook(schema);
32
- if (typeof optionsOrSelector === "object") return hook(optionsOrSelector);
33
- if (typeof optionsOrSelector === "function") return hook(optionsOrSelector);
34
- return hook();
35
- }
36
-
37
- //#endregion
38
- export { createMultiStepFormDataHook, throwIfInvalidStepNumber, useMultiStepFormData };
39
- //# sourceMappingURL=use-multi-step-form-data.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-multi-step-form-data.mjs","names":["useMultiStepFormData"],"sources":["../../src/hooks/use-multi-step-form-data.ts"],"sourcesContent":["import type { AnyMultiStepFormSchema, MultiStepFormSchema } from '@/schema';\nimport {\n invariant,\n VALIDATED_STEP_REGEX,\n} from '@jfdevelops/multi-step-form-core';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\n\nexport type UseMultiStepFormDataOptions<\n TSchema extends AnyMultiStepFormSchema,\n TTarget extends keyof MultiStepFormSchema.resolvedStep<TSchema> = keyof MultiStepFormSchema.resolvedStep<TSchema>\n> = {\n targetStep: TTarget;\n};\nexport type UseMultiStepFormData<\n // step extends Step<casing>,\n // casing extends CasingType,\n // storageKey extends string,\n // resolvedStep extends ResolvedStep<step, casing>,\n // schema extends MultiStepFormSchema<\n // step,\n // casing,\n // storageKey\n // > = MultiStepFormSchema<step, casing, storageKey>,\n TSchema extends AnyMultiStepFormSchema,\n TResolvedStep extends MultiStepFormSchema.resolvedStep<TSchema> = MultiStepFormSchema.resolvedStep<TSchema>\n> = {\n /**\n * Returns the entire {@linkcode MultiStepFormSchema instance}.\n */\n (): TSchema;\n /**\n * Returns the data for the target step.\n * @param stepNumber The step number to return.\n * @throws {TypeError} If `options.stepNumber` is invalid.\n */\n <targetStep extends keyof TResolvedStep>(\n options: UseMultiStepFormDataOptions<TSchema, targetStep>\n ): MultiStepFormSchema.getData<TSchema, targetStep>;\n /**\n * Returns the specified data from the {@linkcode MultiStepFormSchema} instance via the callback's return.\n */\n <data>(selector: (schema: TSchema) => data): data;\n};\n\nexport function throwIfInvalidStepNumber<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(schema: schema, targetStep: unknown) {\n invariant(\n typeof targetStep === 'string',\n `The target step must be a string, was ${typeof targetStep}`\n );\n\n const { as, isValidStepNumber } = schema.stepSchema.steps;\n const formatter = new Intl.ListFormat('en', {\n type: 'disjunction',\n style: 'long',\n });\n const formattedStepNumbersList = formatter.format(as('array.string.untyped'));\n\n invariant(\n VALIDATED_STEP_REGEX.test(targetStep),\n `The target step must match the following format: \"step{number}\". Available steps are ${formattedStepNumbersList}`\n );\n\n const stepNumber = Number.parseInt(targetStep.replace('step', ''));\n\n invariant(\n isValidStepNumber(stepNumber),\n `The step number \"${stepNumber}\" is not a valid step number. Valid step numbers include ${formattedStepNumbersList}`,\n TypeError\n );\n\n return stepNumber as MultiStepFormSchema.stepNumbers<schema>;\n}\n\nexport function createMultiStepFormDataHook<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(schema: schema): UseMultiStepFormData<schema> {\n function useMultiStepFormData(\n optionsOrSelector?:\n | UseMultiStepFormDataOptions<schema>\n | ((data: schema) => unknown)\n ) {\n return useSyncExternalStoreWithSelector(\n schema.subscribe,\n () => schema.getSnapshot(),\n () => schema.getSnapshot(),\n (snapshot) => {\n if (typeof optionsOrSelector === 'object') {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const stepNumber = throwIfInvalidStepNumber(\n snapshot,\n optionsOrSelector.targetStep\n );\n\n return snapshot.stepSchema.get({ step: stepNumber as never }).data;\n }\n\n if (typeof optionsOrSelector === 'function') {\n return optionsOrSelector(snapshot);\n }\n\n return snapshot;\n }\n );\n }\n\n return useMultiStepFormData as any;\n}\n\nfunction useMultiStepFormData<schema extends AnyMultiStepFormSchema>(\n schema: schema\n): schema;\nfunction useMultiStepFormData<\n schema extends AnyMultiStepFormSchema,\n targetStep extends keyof MultiStepFormSchema.resolvedStep<schema>\n>(\n schema: schema,\n options: UseMultiStepFormDataOptions<schema, targetStep>\n): MultiStepFormSchema.getData<schema, targetStep>;\nfunction useMultiStepFormData<schema extends AnyMultiStepFormSchema, data>(\n schema: schema,\n selector: (schema: schema) => data\n): data;\nfunction useMultiStepFormData<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(\n schema: schema,\n optionsOrSelector?:\n | UseMultiStepFormDataOptions<schema>\n | ((data: schema) => unknown)\n) {\n const hook = createMultiStepFormDataHook(schema);\n\n if (typeof optionsOrSelector === 'object') {\n return hook(optionsOrSelector);\n }\n\n if (typeof optionsOrSelector === 'function') {\n return hook(optionsOrSelector);\n }\n\n return hook();\n}\n\nexport { useMultiStepFormData };\n"],"mappings":";;;;AA4CA,SAAgB,yBAOd,QAAgB,YAAqB;AACrC,WACE,OAAO,eAAe,UACtB,yCAAyC,OAAO,aACjD;CAED,MAAM,EAAE,IAAI,sBAAsB,OAAO,WAAW;CAKpD,MAAM,2BAJY,IAAI,KAAK,WAAW,MAAM;EAC1C,MAAM;EACN,OAAO;EACR,CAAC,CACyC,OAAO,GAAG,uBAAuB,CAAC;AAE7E,WACE,qBAAqB,KAAK,WAAW,EACrC,wFAAwF,2BACzF;CAED,MAAM,aAAa,OAAO,SAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC;AAElE,WACE,kBAAkB,WAAW,EAC7B,oBAAoB,WAAW,2DAA2D,4BAC1F,UACD;AAED,QAAO;;AAGT,SAAgB,4BAOd,QAA8C;CAC9C,SAASA,uBACP,mBAGA;AACA,SAAO,iCACL,OAAO,iBACD,OAAO,aAAa,QACpB,OAAO,aAAa,GACzB,aAAa;AACZ,OAAI,OAAO,sBAAsB,UAAU;IAEzC,MAAM,aAAa,yBACjB,UACA,kBAAkB,WACnB;AAED,WAAO,SAAS,WAAW,IAAI,EAAE,MAAM,YAAqB,CAAC,CAAC;;AAGhE,OAAI,OAAO,sBAAsB,WAC/B,QAAO,kBAAkB,SAAS;AAGpC,UAAO;IAEV;;AAGH,QAAOA;;AAiBT,SAAS,qBAQP,QACA,mBAGA;CACA,MAAM,OAAO,4BAA4B,OAAO;AAEhD,KAAI,OAAO,sBAAsB,SAC/B,QAAO,KAAK,kBAAkB;AAGhC,KAAI,OAAO,sBAAsB,WAC/B,QAAO,KAAK,kBAAkB;AAGhC,QAAO,MAAM"}
package/dist/index.cjs DELETED
@@ -1,17 +0,0 @@
1
- const require_step_schema = require('./step-schema.cjs');
2
- const require_schema = require('./schema.cjs');
3
- const require_use_multi_step_form_data = require('./hooks/use-multi-step-form-data.cjs');
4
- const require_create_context = require('./create-context.cjs');
5
-
6
- exports.MultiStepFormSchema = require_schema.MultiStepFormSchema;
7
- exports.MultiStepFormStepSchema = require_step_schema.MultiStepFormStepSchema;
8
- Object.defineProperty(exports, 'StepSpecificComponent', {
9
- enumerable: true,
10
- get: function () {
11
- return require_step_schema.StepSpecificComponent;
12
- }
13
- });
14
- exports.createDefaultValues = require_step_schema.createDefaultValues;
15
- exports.createMultiStepFormContext = require_create_context.createMultiStepFormContext;
16
- exports.createMultiStepFormSchema = require_schema.createMultiStepFormSchema;
17
- exports.useMultiStepFormData = require_use_multi_step_form_data.useMultiStepFormData;
package/dist/index.d.cts DELETED
@@ -1,5 +0,0 @@
1
- import { AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, createDefaultValues } from "./step-schema.cjs";
2
- import { AnyMultiStepFormSchema, MultiStepFormSchema, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.cjs";
3
- import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.cjs";
4
- import { CreateHOC, MultiStepFormContextResult, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createMultiStepFormContext } from "./create-context.cjs";
5
- export { AnyMultiStepFormSchema, AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateHOC, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormContextResult, MultiStepFormSchema, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
package/dist/index.d.mts DELETED
@@ -1,5 +0,0 @@
1
- import { AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, createDefaultValues } from "./step-schema.mjs";
2
- import { AnyMultiStepFormSchema, MultiStepFormSchema, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.mjs";
3
- import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.mjs";
4
- import { CreateHOC, MultiStepFormContextResult, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createMultiStepFormContext } from "./create-context.mjs";
5
- export { AnyMultiStepFormSchema, AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateHOC, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormContextResult, MultiStepFormSchema, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
package/dist/index.mjs DELETED
@@ -1,6 +0,0 @@
1
- import { MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues } from "./step-schema.mjs";
2
- import { MultiStepFormSchema, createMultiStepFormSchema } from "./schema.mjs";
3
- import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.mjs";
4
- import { createMultiStepFormContext } from "./create-context.mjs";
5
-
6
- export { MultiStepFormSchema, MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
package/dist/schema.cjs DELETED
@@ -1,45 +0,0 @@
1
- const require_step_schema = require('./step-schema.cjs');
2
- let __jfdevelops_multi_step_form_core = require("@jfdevelops/multi-step-form-core");
3
- let __jfdevelops_multi_step_form_core__internals = require("@jfdevelops/multi-step-form-core/_internals");
4
-
5
- //#region src/schema.ts
6
- var MultiStepFormSchema = class extends __jfdevelops_multi_step_form_core.MultiStepFormSchema {
7
- stepSchema;
8
- #internal;
9
- constructor(config) {
10
- const { nameTransformCasing = __jfdevelops_multi_step_form_core.DEFAULT_CASING, storage, ...rest } = config;
11
- const options = {
12
- nameTransformCasing,
13
- storage,
14
- ...rest
15
- };
16
- super(options);
17
- this.stepSchema = new require_step_schema.MultiStepFormStepSchema(options);
18
- this.#internal = new __jfdevelops_multi_step_form_core__internals.MultiStepFormStepSchemaInternal({
19
- originalValue: this.stepSchema.original,
20
- getValue: () => this.stepSchema.value,
21
- setValue: (value) => {
22
- this.stepSchema.value = { ...value };
23
- this.storage.add(value);
24
- this.notify();
25
- }
26
- });
27
- }
28
- createComponent(options, fn) {
29
- const { stepData } = options;
30
- const ctx = (0, __jfdevelops_multi_step_form_core.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));
36
- }
37
- };
38
- function createMultiStepFormSchema(options) {
39
- return new MultiStepFormSchema(options);
40
- }
41
-
42
- //#endregion
43
- exports.MultiStepFormSchema = MultiStepFormSchema;
44
- exports.createMultiStepFormSchema = createMultiStepFormSchema;
45
- //# sourceMappingURL=schema.cjs.map
@@ -1 +0,0 @@
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"}
package/dist/schema.d.cts DELETED
@@ -1,34 +0,0 @@
1
- import { CreateComponentCallback, CreatedMultiStepFormComponent, HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1, ResolvedStep as ResolvedStep$1 } from "./step-schema.cjs";
2
- 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";
5
-
6
- //#region src/schema.d.ts
7
- type AnyMultiStepFormSchema = {
8
- [x: string]: any;
9
- };
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];
23
- }
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> {
26
- #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>;
30
- }
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>;
32
- //#endregion
33
- export { AnyMultiStepFormSchema, MultiStepFormSchema$1 as MultiStepFormSchema, MultiStepFormSchemaOptions$1 as MultiStepFormSchemaOptions, createMultiStepFormSchema };
34
- //# sourceMappingURL=schema.d.cts.map
package/dist/schema.d.mts DELETED
@@ -1,34 +0,0 @@
1
- import { CreateComponentCallback, CreatedMultiStepFormComponent, HelperFunctions, MultiStepFormStepSchema as MultiStepFormStepSchema$1, ResolvedStep as ResolvedStep$1 } from "./step-schema.mjs";
2
- 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";
5
-
6
- //#region src/schema.d.ts
7
- type AnyMultiStepFormSchema = {
8
- [x: string]: any;
9
- };
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];
23
- }
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> {
26
- #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>;
30
- }
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>;
32
- //#endregion
33
- export { AnyMultiStepFormSchema, MultiStepFormSchema$1 as MultiStepFormSchema, MultiStepFormSchemaOptions$1 as MultiStepFormSchemaOptions, createMultiStepFormSchema };
34
- //# sourceMappingURL=schema.d.mts.map
package/dist/schema.mjs DELETED
@@ -1,44 +0,0 @@
1
- import { MultiStepFormStepSchema as MultiStepFormStepSchema$1 } from "./step-schema.mjs";
2
- import { DEFAULT_CASING, MultiStepFormSchema, createCtx } from "@jfdevelops/multi-step-form-core";
3
- import { MultiStepFormStepSchemaInternal } from "@jfdevelops/multi-step-form-core/_internals";
4
-
5
- //#region src/schema.ts
6
- var MultiStepFormSchema$1 = class extends MultiStepFormSchema {
7
- stepSchema;
8
- #internal;
9
- constructor(config) {
10
- const { nameTransformCasing = DEFAULT_CASING, storage, ...rest } = config;
11
- const options = {
12
- nameTransformCasing,
13
- storage,
14
- ...rest
15
- };
16
- super(options);
17
- this.stepSchema = new MultiStepFormStepSchema$1(options);
18
- this.#internal = new MultiStepFormStepSchemaInternal({
19
- originalValue: this.stepSchema.original,
20
- getValue: () => this.stepSchema.value,
21
- setValue: (value) => {
22
- this.stepSchema.value = { ...value };
23
- this.storage.add(value);
24
- this.notify();
25
- }
26
- });
27
- }
28
- 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));
36
- }
37
- };
38
- function createMultiStepFormSchema(options) {
39
- return new MultiStepFormSchema$1(options);
40
- }
41
-
42
- //#endregion
43
- export { MultiStepFormSchema$1 as MultiStepFormSchema, createMultiStepFormSchema };
44
- //# sourceMappingURL=schema.mjs.map
@@ -1 +0,0 @@
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,237 +0,0 @@
1
- const require_field = require('./field.cjs');
2
- const require_form_config = require('./form-config.cjs');
3
- let __jfdevelops_multi_step_form_core = require("@jfdevelops/multi-step-form-core");
4
- let __jfdevelops_multi_step_form_core__internals = require("@jfdevelops/multi-step-form-core/_internals");
5
-
6
- //#region src/step-schema.ts
7
- let StepSpecificComponent;
8
- (function(_StepSpecificComponent) {
9
- _StepSpecificComponent.DEFAULT_FORM_INSTANCE_ALIAS = "form";
10
- })(StepSpecificComponent || (StepSpecificComponent = {}));
11
- /**
12
- * Creates a default values object for the target step.
13
- * @param steps The steps schema.
14
- * @param targetStep The step to create the default values for.
15
- * @returns An object containing the field names and their default values.
16
- */
17
- function createDefaultValues(steps, targetStep) {
18
- (0, __jfdevelops_multi_step_form_core.invariant)(targetStep in steps, `The target step ${targetStep} is not a valid step key`);
19
- const current = steps[targetStep];
20
- (0, __jfdevelops_multi_step_form_core.invariant)("fields" in current, `No "fields" were found for ${targetStep}`);
21
- let defaultValues = {};
22
- for (const [fieldName, fieldValues] of Object.entries(current.fields)) defaultValues = {
23
- ...defaultValues,
24
- [fieldName]: fieldValues.defaultValue
25
- };
26
- return defaultValues;
27
- }
28
- var MultiStepFormStepSchema = class extends __jfdevelops_multi_step_form_core.MultiStepFormStepSchema {
29
- value;
30
- #internal;
31
- constructor(config) {
32
- const { form, ...rest } = config;
33
- super(rest);
34
- this.value = (0, __jfdevelops_multi_step_form_core.createStep)(this.original);
35
- this.#internal = new __jfdevelops_multi_step_form_core__internals.MultiStepFormStepSchemaInternal({
36
- originalValue: this.original,
37
- getValue: () => this.value,
38
- setValue: (next) => this.handlePostUpdate(next)
39
- });
40
- this.sync();
41
- this.value = this.#internal.enrichValues(this.value, (step) => {
42
- const key = `step${step}`;
43
- const stepData = [key];
44
- const id = form?.id ?? key;
45
- const ctx = (0, __jfdevelops_multi_step_form_core.createCtx)(this.value, stepData);
46
- return { createComponent: this.createStepSpecificComponentFactory(stepData, {
47
- isStepSpecific: true,
48
- defaultId: id,
49
- form
50
- }, ctx) };
51
- });
52
- }
53
- createFormComponent(form, defaultId) {
54
- const { render, enabledForSteps = "all", id = defaultId } = form;
55
- const ctx = {
56
- id,
57
- steps: (0, __jfdevelops_multi_step_form_core.createCtx)(this.value, enabledForSteps)
58
- };
59
- return (props) => render(ctx, props);
60
- }
61
- createStepSpecificComponentImpl(stepData, config, input, extraInput = {}) {
62
- return (fn) => ((props) => {
63
- const hookResults = {};
64
- for (const [key, value] of Object.entries(extraInput)) if (typeof value === "function") try {
65
- hookResults[key] = value();
66
- } catch (error) {
67
- const errorMessage = error instanceof Error ? error.message : String(error);
68
- throw new Error(`[multi-step-form] Error calling hook "${key}" in useFormInstance.render: ${errorMessage}\n\nThis usually means:\n1. The hook is being called outside of a React component\n2. The hook has invalid dependencies or configuration\n3. There's an error in your hook implementation\n\nOriginal error: ${errorMessage}`, { cause: error });
69
- }
70
- else hookResults[key] = value;
71
- const { defaultId, form } = config;
72
- const { ctx } = input;
73
- const [step] = stepData;
74
- (0, __jfdevelops_multi_step_form_core.invariant)(this.steps.isValidStepKey(step), `[createComponent]: the target step ${step} is invalid. Note, this error shouldn't appear as the target step should always be valid. If you see this error, please open an issue.`);
75
- const stepNumber = Number.parseInt(step.replace("step", ""));
76
- (0, __jfdevelops_multi_step_form_core.invariant)(!Number.isNaN(stepNumber), `[${step}:"createComponent"]: an error occurred while extracting the number`);
77
- const current = this.value[step];
78
- (0, __jfdevelops_multi_step_form_core.invariant)("fields" in current, `[${step}:createComponent]: unable to find the "fields" for the current step`);
79
- (0, __jfdevelops_multi_step_form_core.invariant)(typeof current.fields === "object", `[${step}:createComponent]: the "fields" property must be an object, was ${typeof current.fields}`);
80
- const stepUpdater = this.#internal.createStepUpdaterFn(step);
81
- const Field = require_field.field.create((name) => {
82
- const currentFields = Object.keys(current.fields);
83
- (0, __jfdevelops_multi_step_form_core.invariant)(typeof name === "string", (formatter) => `[${step}:Field]: the "name" prop must be a string and a valid field for ${step}. Available fields include: "${formatter.format(currentFields)}"`);
84
- (0, __jfdevelops_multi_step_form_core.invariant)(name in current.fields, (formatter) => `[${step}:Field]: the field "${name}" doesn't exist for the current step. Available fields include: "${formatter.format(currentFields)}".`);
85
- (0, __jfdevelops_multi_step_form_core.invariant)("update" in current, `[${step}:Field]: No "update" function was found`);
86
- const defaultValue = this.getValue(step, name);
87
- const { label, nameTransformCasing, type } = current.fields[name];
88
- const targetFields = `fields.${name}.defaultValue`;
89
- return {
90
- defaultValue,
91
- label,
92
- nameTransformCasing,
93
- type,
94
- name,
95
- onInputChange: (value) => {
96
- let resolvedValue;
97
- if (typeof value === "function") resolvedValue = value(this.getValue(step, name));
98
- else resolvedValue = value;
99
- this.update({
100
- targetStep: step,
101
- updater: resolvedValue,
102
- fields: [targetFields]
103
- });
104
- },
105
- reset: () => this.reset({
106
- fields: [targetFields],
107
- targetStep: step
108
- })
109
- };
110
- });
111
- let fnInput = {
112
- ctx,
113
- onInputChange: stepUpdater,
114
- reset: this.#internal.createStepResetterFn(step),
115
- Field,
116
- ...hookResults
117
- };
118
- if (form) {
119
- const { alias = require_form_config.MultiStepFormSchemaConfig.DEFAULT_FORM_ALIAS, ...rest } = form;
120
- const enabledFor = rest.enabledForSteps ?? "all";
121
- if (require_form_config.MultiStepFormSchemaConfig.isFormAvailable(stepData, enabledFor)) fnInput = {
122
- ...fnInput,
123
- [alias]: this.createFormComponent(rest, defaultId)
124
- };
125
- return fn(fnInput, props);
126
- }
127
- return fn({
128
- ...fnInput,
129
- [require_form_config.MultiStepFormSchemaConfig.DEFAULT_FORM_ALIAS]: require_form_config.MultiStepFormSchemaConfig.createDefaultForm(defaultId)
130
- }, props);
131
- });
132
- }
133
- createCtx(logger, values) {
134
- return function(options) {
135
- const { ctx, ctxData } = options;
136
- logger.info("Option \"ctxData\" is defined");
137
- (0, __jfdevelops_multi_step_form_core.invariant)(typeof ctxData === "function", "Option \"ctxData\" must be a function");
138
- const additionalCtx = ctxData({ ctx: values });
139
- logger.info(`Addition context is: ${JSON.stringify(additionalCtx, null, 2)}`);
140
- const resolvedCtx = {
141
- ...ctx,
142
- ...additionalCtx
143
- };
144
- logger.info(`Resolved context is: ${JSON.stringify(resolvedCtx, null, 2)}`);
145
- return resolvedCtx;
146
- };
147
- }
148
- createStepSpecificComponentFactory(stepData, config, ctx) {
149
- const createStepSpecificComponentImpl = this.createStepSpecificComponentImpl.bind(this);
150
- const createDefaultValues$1 = this.createDefaultValues.bind(this);
151
- const resolvedValues = this.value;
152
- const [targetStep] = stepData;
153
- const update = this.#internal.createStepUpdaterFn(targetStep).bind(this.#internal);
154
- const reset = this.#internal.createStepResetterFn(targetStep).bind(this.#internal);
155
- const createCtx$1 = this.createCtx.bind(this);
156
- function impl(optionsOrFn, fn) {
157
- function createResolvedCtx(additionalCtx) {
158
- return additionalCtx ? { ctx: {
159
- ...ctx,
160
- ...additionalCtx
161
- } } : { ctx };
162
- }
163
- function createStepSpecificComponent() {
164
- (0, __jfdevelops_multi_step_form_core.invariant)(typeof optionsOrFn === "function", "The first argument must be a function");
165
- return createStepSpecificComponentImpl(stepData, config, createResolvedCtx(void 0))(optionsOrFn);
166
- }
167
- if (typeof optionsOrFn === "object") {
168
- const { useFormInstance, ctxData, debug } = optionsOrFn;
169
- const logger = new __jfdevelops_multi_step_form_core.MultiStepFormLogger({
170
- debug,
171
- prefix(prefix) {
172
- return `${prefix}-${targetStep}-createComponent`;
173
- }
174
- });
175
- logger.info("First argument is an object");
176
- const { [targetStep]: _, ...values } = resolvedValues;
177
- (0, __jfdevelops_multi_step_form_core.invariant)(typeof fn === "function", "The second argument must be a function");
178
- const createdCtx = createCtx$1(logger, values);
179
- if (useFormInstance) {
180
- const { render, alias = StepSpecificComponent.DEFAULT_FORM_INSTANCE_ALIAS } = useFormInstance;
181
- const [step] = stepData;
182
- const defaultValues = createDefaultValues$1(step);
183
- const resolvedCtx = ctxData ? createdCtx({
184
- ctx,
185
- ctxData
186
- }) : { ctx };
187
- const renderInput = {
188
- ctx: resolvedCtx,
189
- defaultValues
190
- };
191
- return createStepSpecificComponentImpl(stepData, config, {
192
- ctx: resolvedCtx,
193
- update,
194
- reset
195
- }, { [alias]: () => render(renderInput) })(fn);
196
- }
197
- if (ctxData) return createStepSpecificComponentImpl(stepData, config, {
198
- ctx: createdCtx({
199
- ctx,
200
- ctxData
201
- }),
202
- update,
203
- reset
204
- })(fn);
205
- return createStepSpecificComponent();
206
- }
207
- return createStepSpecificComponent();
208
- }
209
- return impl;
210
- }
211
- /**
212
- * A helper function to create a component for a specific step.
213
- * @param options The options for creating the step specific component.
214
- * @param fn A callback that is used for accessing the target step's data and defining
215
- * any props that the component should have. This function must return a valid `JSX` element.
216
- * @returns The created component for the step.
217
- */
218
- createComponent(options, fn) {
219
- const { stepData } = options;
220
- const ctx = (0, __jfdevelops_multi_step_form_core.createCtx)(this.value, stepData);
221
- return ((props) => fn(ctx, props));
222
- }
223
- createDefaultValues(targetStep) {
224
- return createDefaultValues(this.value, targetStep);
225
- }
226
- };
227
-
228
- //#endregion
229
- exports.MultiStepFormStepSchema = MultiStepFormStepSchema;
230
- Object.defineProperty(exports, 'StepSpecificComponent', {
231
- enumerable: true,
232
- get: function () {
233
- return StepSpecificComponent;
234
- }
235
- });
236
- exports.createDefaultValues = createDefaultValues;
237
- //# sourceMappingURL=step-schema.cjs.map