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