@jfdevelops/react-multi-step-form 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (67) hide show
  1. package/dist/create-context.cjs +92 -0
  2. package/dist/create-context.cjs.map +1 -0
  3. package/dist/create-context.d.cts +154 -0
  4. package/dist/create-context.d.mts +154 -0
  5. package/dist/create-context.mjs +92 -0
  6. package/dist/create-context.mjs.map +1 -0
  7. package/dist/field.cjs +41 -0
  8. package/dist/field.cjs.map +1 -0
  9. package/dist/field.d.cts +68 -0
  10. package/dist/field.d.mts +68 -0
  11. package/dist/field.mjs +36 -0
  12. package/dist/field.mjs.map +1 -0
  13. package/dist/form-config.cjs +32 -0
  14. package/dist/form-config.cjs.map +1 -0
  15. package/dist/form-config.d.cts +160 -0
  16. package/dist/form-config.d.mts +160 -0
  17. package/dist/form-config.mjs +27 -0
  18. package/dist/form-config.mjs.map +1 -0
  19. package/dist/hooks/use-multi-step-form-data.cjs +41 -0
  20. package/dist/hooks/use-multi-step-form-data.cjs.map +1 -0
  21. package/dist/hooks/use-multi-step-form-data.d.cts +28 -0
  22. package/dist/hooks/use-multi-step-form-data.d.mts +28 -0
  23. package/dist/hooks/use-multi-step-form-data.mjs +39 -0
  24. package/dist/hooks/use-multi-step-form-data.mjs.map +1 -0
  25. package/dist/hooks/use-selector.cjs +64 -0
  26. package/dist/hooks/use-selector.cjs.map +1 -0
  27. package/dist/hooks/use-selector.d.cts +92 -0
  28. package/dist/hooks/use-selector.d.mts +92 -0
  29. package/dist/hooks/use-selector.mjs +64 -0
  30. package/dist/hooks/use-selector.mjs.map +1 -0
  31. package/dist/index.cjs +16 -43
  32. package/dist/index.d.cts +5 -0
  33. package/dist/index.d.mts +5 -0
  34. package/dist/index.mjs +5 -1415
  35. package/dist/schema.cjs +45 -0
  36. package/dist/schema.cjs.map +1 -0
  37. package/dist/schema.d.cts +34 -0
  38. package/dist/schema.d.mts +34 -0
  39. package/dist/schema.mjs +44 -0
  40. package/dist/schema.mjs.map +1 -0
  41. package/dist/selector.cjs +53 -0
  42. package/dist/selector.cjs.map +1 -0
  43. package/dist/selector.d.cts +56 -0
  44. package/dist/selector.d.mts +56 -0
  45. package/dist/selector.mjs +48 -0
  46. package/dist/selector.mjs.map +1 -0
  47. package/dist/step-schema.cjs +244 -0
  48. package/dist/step-schema.cjs.map +1 -0
  49. package/dist/step-schema.d.cts +164 -0
  50. package/dist/step-schema.d.mts +164 -0
  51. package/dist/step-schema.mjs +237 -0
  52. package/dist/step-schema.mjs.map +1 -0
  53. package/dist/utils.cjs +34 -0
  54. package/dist/utils.cjs.map +1 -0
  55. package/dist/utils.mjs +33 -0
  56. package/dist/utils.mjs.map +1 -0
  57. package/package.json +15 -11
  58. package/dist/index.cjs.map +0 -1
  59. package/dist/index.mjs.map +0 -1
  60. package/dist/types/create-context.d.ts +0 -156
  61. package/dist/types/field.d.ts +0 -22
  62. package/dist/types/form-config.d.ts +0 -161
  63. package/dist/types/hooks/use-multi-step-form-data.d.ts +0 -26
  64. package/dist/types/index.d.ts +0 -4
  65. package/dist/types/schema.d.ts +0 -29
  66. package/dist/types/step-schema.d.ts +0 -134
  67. package/dist/types/utils.d.ts +0 -0
@@ -0,0 +1,45 @@
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
@@ -0,0 +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"}
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,44 @@
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
@@ -0,0 +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"}
@@ -0,0 +1,53 @@
1
+ const require_use_selector = require('./hooks/use-selector.cjs');
2
+ let __jfdevelops_multi_step_form_core = require("@jfdevelops/multi-step-form-core");
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+
6
+ //#region src/selector.tsx
7
+ let selector;
8
+ (function(_selector) {
9
+ function create(createCtx, subscribe) {
10
+ const useSelector = require_use_selector.createUseSelector(createCtx, subscribe);
11
+ const Selector = ({ selector: selector$1, children, debug }) => {
12
+ const isDebugEnabled = typeof debug === "boolean" ? debug : debug !== void 0;
13
+ const debugOptions = typeof debug === "object" ? debug : void 0;
14
+ const prefix = debugOptions?.prefix;
15
+ const logger = (0, react.useMemo)(() => {
16
+ if (!isDebugEnabled) return;
17
+ return new __jfdevelops_multi_step_form_core.MultiStepFormLogger({
18
+ debug: true,
19
+ prefix: (defaultValue) => {
20
+ const defaultPrefix = `${defaultValue}-Selector`;
21
+ console.log(prefix);
22
+ if (!prefix) return defaultPrefix;
23
+ if (typeof prefix === "string") return prefix;
24
+ if (typeof prefix === "function") return prefix(defaultValue);
25
+ if (typeof prefix === "object") {
26
+ const { action = "prepend", value, delimiter = "-" } = prefix;
27
+ const resolvedValue = typeof value === "function" ? value(defaultValue) : value;
28
+ if (action === "prepend") return `${resolvedValue}${delimiter}${defaultPrefix}`;
29
+ if (action === "append") return `${defaultPrefix}${delimiter}${resolvedValue}`;
30
+ return defaultPrefix;
31
+ }
32
+ return defaultPrefix;
33
+ }
34
+ });
35
+ }, [isDebugEnabled, prefix]);
36
+ const selected = useSelector(selector$1, logger, debugOptions);
37
+ logger?.info(debugOptions?.onRender?.(selected) ?? `Rendering with selected: ${JSON.stringify(selected)}`);
38
+ if (children) return (0, react.createElement)(react_jsx_runtime.Fragment, null, children(selected));
39
+ return (0, react.createElement)(react_jsx_runtime.Fragment, null, String(selected ?? ""));
40
+ };
41
+ return Selector;
42
+ }
43
+ _selector.create = create;
44
+ })(selector || (selector = {}));
45
+
46
+ //#endregion
47
+ Object.defineProperty(exports, 'selector', {
48
+ enumerable: true,
49
+ get: function () {
50
+ return selector;
51
+ }
52
+ });
53
+ //# sourceMappingURL=selector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.cjs","names":["createUseSelector","Selector: component<TResolvedStep, TSteps, TChosenSteps>","MultiStepFormLogger","selector","Fragment"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n Expand,\n HelperFnChosenSteps,\n HelperFnCtx,\n MultiStepFormLogger,\n StepNumbers,\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<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>,\n TSelected\n > = {\n selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, 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<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n > =\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>(\n props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>\n ) => React.ReactNode;\n\n export function create<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n >(\n createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<TResolvedStep, TSteps, TChosenSteps> = ({\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":";;;;;;;;CA4ES,SAAS,OAKd,WACA,WACA;EACA,MAAM,cAAcA,uCAAkB,WAAW,UAAU;EAC3D,MAAMC,YAA4D,EAChE,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"}
@@ -0,0 +1,56 @@
1
+ import { DebugOptions, SelectorFn } from "./hooks/use-selector.cjs";
2
+ import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
3
+
4
+ //#region src/selector.d.ts
5
+ declare namespace selector {
6
+ type props<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = {
7
+ selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, TSelected>;
8
+ children?: (selected: TSelected) => React.ReactNode;
9
+ /**
10
+ * Optional debug options to customize logging behavior.
11
+ */
12
+ debug?: boolean | DebugOptions<TSelected>;
13
+ };
14
+ type component<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> =
15
+ /**
16
+ * A component for reactively displaying a value from the form context.
17
+ * Unlike `useSelector`, this component only re-renders itself, not the parent component.
18
+ * Use this when you want to display a reactive value without causing parent re-renders.
19
+ *
20
+ * @param props - The props for the Selector component.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * // With no debug options (default behavior)
25
+ * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>
26
+ * {(value) => <p>First name: {value}</p>}
27
+ * </Selector>
28
+ * ```
29
+ * @example
30
+ * ```tsx
31
+ * // With debug enabled
32
+ * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>
33
+ * {(value) => <p>First name: {value}</p>}
34
+ * </Selector>
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // With custom debug options
40
+ * <Selector
41
+ * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}
42
+ * debug={{
43
+ * onRender: (value) => console.log('Rendered with:', value),
44
+ * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)
45
+ * }}
46
+ * >
47
+ * {(value) => <p>First name: {value}</p>}
48
+ * </Selector>
49
+ * ```
50
+ */
51
+ <TSelected>(props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>) => React.ReactNode;
52
+ function create<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): component<TResolvedStep, TSteps, TChosenSteps>;
53
+ }
54
+ //#endregion
55
+ export { selector };
56
+ //# sourceMappingURL=selector.d.cts.map
@@ -0,0 +1,56 @@
1
+ import { DebugOptions, SelectorFn } from "./hooks/use-selector.mjs";
2
+ import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
3
+
4
+ //#region src/selector.d.ts
5
+ declare namespace selector {
6
+ type props<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = {
7
+ selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, TSelected>;
8
+ children?: (selected: TSelected) => React.ReactNode;
9
+ /**
10
+ * Optional debug options to customize logging behavior.
11
+ */
12
+ debug?: boolean | DebugOptions<TSelected>;
13
+ };
14
+ type component<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> =
15
+ /**
16
+ * A component for reactively displaying a value from the form context.
17
+ * Unlike `useSelector`, this component only re-renders itself, not the parent component.
18
+ * Use this when you want to display a reactive value without causing parent re-renders.
19
+ *
20
+ * @param props - The props for the Selector component.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * // With no debug options (default behavior)
25
+ * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>
26
+ * {(value) => <p>First name: {value}</p>}
27
+ * </Selector>
28
+ * ```
29
+ * @example
30
+ * ```tsx
31
+ * // With debug enabled
32
+ * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue} debug>
33
+ * {(value) => <p>First name: {value}</p>}
34
+ * </Selector>
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // With custom debug options
40
+ * <Selector
41
+ * selector={(ctx) => ctx.step1.fields.firstName.defaultValue}
42
+ * debug={{
43
+ * onRender: (value) => console.log('Rendered with:', value),
44
+ * onValueChanged: (oldVal, newVal) => console.log('Changed:', oldVal, '->', newVal)
45
+ * }}
46
+ * >
47
+ * {(value) => <p>First name: {value}</p>}
48
+ * </Selector>
49
+ * ```
50
+ */
51
+ <TSelected>(props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>) => React.ReactNode;
52
+ function create<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): component<TResolvedStep, TSteps, TChosenSteps>;
53
+ }
54
+ //#endregion
55
+ export { selector };
56
+ //# sourceMappingURL=selector.d.mts.map
@@ -0,0 +1,48 @@
1
+ import { createUseSelector } from "./hooks/use-selector.mjs";
2
+ import { MultiStepFormLogger } from "@jfdevelops/multi-step-form-core";
3
+ import { createElement, useMemo } from "react";
4
+ import { Fragment } from "react/jsx-runtime";
5
+
6
+ //#region src/selector.tsx
7
+ let selector;
8
+ (function(_selector) {
9
+ function create(createCtx$1, subscribe) {
10
+ const useSelector = createUseSelector(createCtx$1, subscribe);
11
+ const Selector = ({ selector: selector$1, children, debug }) => {
12
+ const isDebugEnabled = typeof debug === "boolean" ? debug : debug !== void 0;
13
+ const debugOptions = typeof debug === "object" ? debug : void 0;
14
+ const prefix = debugOptions?.prefix;
15
+ const logger = useMemo(() => {
16
+ if (!isDebugEnabled) return;
17
+ return new MultiStepFormLogger({
18
+ debug: true,
19
+ prefix: (defaultValue) => {
20
+ const defaultPrefix = `${defaultValue}-Selector`;
21
+ console.log(prefix);
22
+ if (!prefix) return defaultPrefix;
23
+ if (typeof prefix === "string") return prefix;
24
+ if (typeof prefix === "function") return prefix(defaultValue);
25
+ if (typeof prefix === "object") {
26
+ const { action = "prepend", value, delimiter = "-" } = prefix;
27
+ const resolvedValue = typeof value === "function" ? value(defaultValue) : value;
28
+ if (action === "prepend") return `${resolvedValue}${delimiter}${defaultPrefix}`;
29
+ if (action === "append") return `${defaultPrefix}${delimiter}${resolvedValue}`;
30
+ return defaultPrefix;
31
+ }
32
+ return defaultPrefix;
33
+ }
34
+ });
35
+ }, [isDebugEnabled, prefix]);
36
+ const selected = useSelector(selector$1, logger, debugOptions);
37
+ logger?.info(debugOptions?.onRender?.(selected) ?? `Rendering with selected: ${JSON.stringify(selected)}`);
38
+ if (children) return createElement(Fragment, null, children(selected));
39
+ return createElement(Fragment, null, String(selected ?? ""));
40
+ };
41
+ return Selector;
42
+ }
43
+ _selector.create = create;
44
+ })(selector || (selector = {}));
45
+
46
+ //#endregion
47
+ export { selector };
48
+ //# sourceMappingURL=selector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.mjs","names":["createCtx","Selector: component<TResolvedStep, TSteps, TChosenSteps>","selector"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n Expand,\n HelperFnChosenSteps,\n HelperFnCtx,\n MultiStepFormLogger,\n StepNumbers,\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<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>,\n TSelected\n > = {\n selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, 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<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n > =\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>(\n props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>\n ) => React.ReactNode;\n\n export function create<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n >(\n createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>,\n subscribe: (listener: () => void) => () => void\n ) {\n const useSelector = createUseSelector(createCtx, subscribe);\n const Selector: component<TResolvedStep, TSteps, TChosenSteps> = ({\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":";;;;;;;;CA4ES,SAAS,OAKd,aACA,WACA;EACA,MAAM,cAAc,kBAAkBA,aAAW,UAAU;EAC3D,MAAMC,YAA4D,EAChE,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"}