@jfdevelops/react-multi-step-form 1.0.0-alpha.22 → 1.0.0-alpha.24
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 +92 -0
- package/dist/create-context.cjs.map +1 -0
- package/dist/create-context.d.cts +154 -0
- package/dist/create-context.d.mts +154 -0
- package/dist/create-context.mjs +92 -0
- package/dist/create-context.mjs.map +1 -0
- package/dist/field.cjs +30 -0
- package/dist/field.cjs.map +1 -0
- package/dist/field.d.cts +40 -0
- package/dist/field.d.mts +40 -0
- package/dist/field.mjs +25 -0
- package/dist/field.mjs.map +1 -0
- package/dist/form-config.cjs +32 -0
- package/dist/form-config.cjs.map +1 -0
- package/dist/form-config.d.cts +160 -0
- package/dist/form-config.d.mts +160 -0
- package/dist/form-config.mjs +27 -0
- package/dist/form-config.mjs.map +1 -0
- package/dist/hooks/use-multi-step-form-data.cjs +41 -0
- package/dist/hooks/use-multi-step-form-data.cjs.map +1 -0
- package/dist/hooks/use-multi-step-form-data.d.cts +28 -0
- package/dist/hooks/use-multi-step-form-data.d.mts +28 -0
- package/dist/hooks/use-multi-step-form-data.mjs +39 -0
- package/dist/hooks/use-multi-step-form-data.mjs.map +1 -0
- package/dist/hooks/use-selector.cjs +16 -0
- package/dist/hooks/use-selector.cjs.map +1 -0
- package/dist/hooks/use-selector.d.cts +9 -0
- package/dist/hooks/use-selector.d.mts +9 -0
- package/dist/hooks/use-selector.mjs +16 -0
- package/dist/hooks/use-selector.mjs.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +6 -0
- package/dist/schema.cjs +45 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +34 -0
- package/dist/schema.d.mts +34 -0
- package/dist/schema.mjs +44 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/selector.cjs +27 -0
- package/dist/selector.cjs.map +1 -0
- package/dist/selector.d.cts +30 -0
- package/dist/selector.d.mts +30 -0
- package/dist/selector.mjs +22 -0
- package/dist/selector.mjs.map +1 -0
- package/dist/step-schema.cjs +229 -0
- package/dist/step-schema.cjs.map +1 -0
- package/dist/step-schema.d.cts +164 -0
- package/dist/step-schema.d.mts +164 -0
- package/dist/step-schema.mjs +222 -0
- package/dist/step-schema.mjs.map +1 -0
- package/dist/utils.cjs +34 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.mjs +33 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnyMultiStepFormSchema, MultiStepFormSchema } from "../schema.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-multi-step-form-data.d.ts
|
|
4
|
+
type UseMultiStepFormDataOptions<TSchema extends AnyMultiStepFormSchema, TTarget extends keyof MultiStepFormSchema.resolvedStep<TSchema> = keyof MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
5
|
+
targetStep: TTarget;
|
|
6
|
+
};
|
|
7
|
+
type UseMultiStepFormData<TSchema extends AnyMultiStepFormSchema, TResolvedStep extends MultiStepFormSchema.resolvedStep<TSchema> = MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
8
|
+
/**
|
|
9
|
+
* Returns the entire {@linkcode MultiStepFormSchema instance}.
|
|
10
|
+
*/
|
|
11
|
+
(): TSchema;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the data for the target step.
|
|
14
|
+
* @param stepNumber The step number to return.
|
|
15
|
+
* @throws {TypeError} If `options.stepNumber` is invalid.
|
|
16
|
+
*/
|
|
17
|
+
<targetStep extends keyof TResolvedStep>(options: UseMultiStepFormDataOptions<TSchema, targetStep>): MultiStepFormSchema.getData<TSchema, targetStep>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the specified data from the {@linkcode MultiStepFormSchema} instance via the callback's return.
|
|
20
|
+
*/
|
|
21
|
+
<data>(selector: (schema: TSchema) => data): data;
|
|
22
|
+
};
|
|
23
|
+
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema>(schema: schema): schema;
|
|
24
|
+
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema, targetStep extends keyof MultiStepFormSchema.resolvedStep<schema>>(schema: schema, options: UseMultiStepFormDataOptions<schema, targetStep>): MultiStepFormSchema.getData<schema, targetStep>;
|
|
25
|
+
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema, data>(schema: schema, selector: (schema: schema) => data): data;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { UseMultiStepFormData, useMultiStepFormData };
|
|
28
|
+
//# sourceMappingURL=use-multi-step-form-data.d.mts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { VALIDATED_STEP_REGEX, invariant } from "@jfdevelops/multi-step-form-core";
|
|
2
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/use-multi-step-form-data.ts
|
|
5
|
+
function throwIfInvalidStepNumber(schema, targetStep) {
|
|
6
|
+
invariant(typeof targetStep === "string", `The target step must be a string, was ${typeof targetStep}`);
|
|
7
|
+
const { as, isValidStepNumber } = schema.stepSchema.steps;
|
|
8
|
+
const formattedStepNumbersList = new Intl.ListFormat("en", {
|
|
9
|
+
type: "disjunction",
|
|
10
|
+
style: "long"
|
|
11
|
+
}).format(as("array.string.untyped"));
|
|
12
|
+
invariant(VALIDATED_STEP_REGEX.test(targetStep), `The target step must match the following format: "step{number}". Available steps are ${formattedStepNumbersList}`);
|
|
13
|
+
const stepNumber = Number.parseInt(targetStep.replace("step", ""));
|
|
14
|
+
invariant(isValidStepNumber(stepNumber), `The step number "${stepNumber}" is not a valid step number. Valid step numbers include ${formattedStepNumbersList}`, TypeError);
|
|
15
|
+
return stepNumber;
|
|
16
|
+
}
|
|
17
|
+
function createMultiStepFormDataHook(schema) {
|
|
18
|
+
function useMultiStepFormData$1(optionsOrSelector) {
|
|
19
|
+
return useSyncExternalStoreWithSelector(schema.subscribe, () => schema.getSnapshot(), () => schema.getSnapshot(), (snapshot) => {
|
|
20
|
+
if (typeof optionsOrSelector === "object") {
|
|
21
|
+
const stepNumber = throwIfInvalidStepNumber(snapshot, optionsOrSelector.targetStep);
|
|
22
|
+
return snapshot.stepSchema.get({ step: stepNumber }).data;
|
|
23
|
+
}
|
|
24
|
+
if (typeof optionsOrSelector === "function") return optionsOrSelector(snapshot);
|
|
25
|
+
return snapshot;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return useMultiStepFormData$1;
|
|
29
|
+
}
|
|
30
|
+
function useMultiStepFormData(schema, optionsOrSelector) {
|
|
31
|
+
const hook = createMultiStepFormDataHook(schema);
|
|
32
|
+
if (typeof optionsOrSelector === "object") return hook(optionsOrSelector);
|
|
33
|
+
if (typeof optionsOrSelector === "function") return hook(optionsOrSelector);
|
|
34
|
+
return hook();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { createMultiStepFormDataHook, throwIfInvalidStepNumber, useMultiStepFormData };
|
|
39
|
+
//# sourceMappingURL=use-multi-step-form-data.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-step-form-data.mjs","names":["useMultiStepFormData"],"sources":["../../src/hooks/use-multi-step-form-data.ts"],"sourcesContent":["import type { AnyMultiStepFormSchema, MultiStepFormSchema } from '@/schema';\nimport {\n invariant,\n VALIDATED_STEP_REGEX,\n} from '@jfdevelops/multi-step-form-core';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';\n\nexport type UseMultiStepFormDataOptions<\n TSchema extends AnyMultiStepFormSchema,\n TTarget extends keyof MultiStepFormSchema.resolvedStep<TSchema> = keyof MultiStepFormSchema.resolvedStep<TSchema>\n> = {\n targetStep: TTarget;\n};\nexport type UseMultiStepFormData<\n // step extends Step<casing>,\n // casing extends CasingType,\n // storageKey extends string,\n // resolvedStep extends ResolvedStep<step, casing>,\n // schema extends MultiStepFormSchema<\n // step,\n // casing,\n // storageKey\n // > = MultiStepFormSchema<step, casing, storageKey>,\n TSchema extends AnyMultiStepFormSchema,\n TResolvedStep extends MultiStepFormSchema.resolvedStep<TSchema> = MultiStepFormSchema.resolvedStep<TSchema>\n> = {\n /**\n * Returns the entire {@linkcode MultiStepFormSchema instance}.\n */\n (): TSchema;\n /**\n * Returns the data for the target step.\n * @param stepNumber The step number to return.\n * @throws {TypeError} If `options.stepNumber` is invalid.\n */\n <targetStep extends keyof TResolvedStep>(\n options: UseMultiStepFormDataOptions<TSchema, targetStep>\n ): MultiStepFormSchema.getData<TSchema, targetStep>;\n /**\n * Returns the specified data from the {@linkcode MultiStepFormSchema} instance via the callback's return.\n */\n <data>(selector: (schema: TSchema) => data): data;\n};\n\nexport function throwIfInvalidStepNumber<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(schema: schema, targetStep: unknown) {\n invariant(\n typeof targetStep === 'string',\n `The target step must be a string, was ${typeof targetStep}`\n );\n\n const { as, isValidStepNumber } = schema.stepSchema.steps;\n const formatter = new Intl.ListFormat('en', {\n type: 'disjunction',\n style: 'long',\n });\n const formattedStepNumbersList = formatter.format(as('array.string.untyped'));\n\n invariant(\n VALIDATED_STEP_REGEX.test(targetStep),\n `The target step must match the following format: \"step{number}\". Available steps are ${formattedStepNumbersList}`\n );\n\n const stepNumber = Number.parseInt(targetStep.replace('step', ''));\n\n invariant(\n isValidStepNumber(stepNumber),\n `The step number \"${stepNumber}\" is not a valid step number. Valid step numbers include ${formattedStepNumbersList}`,\n TypeError\n );\n\n return stepNumber as MultiStepFormSchema.stepNumbers<schema>;\n}\n\nexport function createMultiStepFormDataHook<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(schema: schema): UseMultiStepFormData<schema> {\n function useMultiStepFormData(\n optionsOrSelector?:\n | UseMultiStepFormDataOptions<schema>\n | ((data: schema) => unknown)\n ) {\n return useSyncExternalStoreWithSelector(\n schema.subscribe,\n () => schema.getSnapshot(),\n () => schema.getSnapshot(),\n (snapshot) => {\n if (typeof optionsOrSelector === 'object') {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const stepNumber = throwIfInvalidStepNumber(\n snapshot,\n optionsOrSelector.targetStep\n );\n\n return snapshot.stepSchema.get({ step: stepNumber as never }).data;\n }\n\n if (typeof optionsOrSelector === 'function') {\n return optionsOrSelector(snapshot);\n }\n\n return snapshot;\n }\n );\n }\n\n return useMultiStepFormData as any;\n}\n\nfunction useMultiStepFormData<schema extends AnyMultiStepFormSchema>(\n schema: schema\n): schema;\nfunction useMultiStepFormData<\n schema extends AnyMultiStepFormSchema,\n targetStep extends keyof MultiStepFormSchema.resolvedStep<schema>\n>(\n schema: schema,\n options: UseMultiStepFormDataOptions<schema, targetStep>\n): MultiStepFormSchema.getData<schema, targetStep>;\nfunction useMultiStepFormData<schema extends AnyMultiStepFormSchema, data>(\n schema: schema,\n selector: (schema: schema) => data\n): data;\nfunction useMultiStepFormData<\n // step extends Step<casing>,\n // casing extends CasingType = DefaultCasing,\n // storageKey extends string = DefaultStorageKey,\n // resolvedStep extends ResolvedStep<step, casing> = ResolvedStep<step, casing>,\n // stepNumbers extends StepNumbers<resolvedStep> = StepNumbers<resolvedStep>\n schema extends AnyMultiStepFormSchema\n>(\n schema: schema,\n optionsOrSelector?:\n | UseMultiStepFormDataOptions<schema>\n | ((data: schema) => unknown)\n) {\n const hook = createMultiStepFormDataHook(schema);\n\n if (typeof optionsOrSelector === 'object') {\n return hook(optionsOrSelector);\n }\n\n if (typeof optionsOrSelector === 'function') {\n return hook(optionsOrSelector);\n }\n\n return hook();\n}\n\nexport { useMultiStepFormData };\n"],"mappings":";;;;AA4CA,SAAgB,yBAOd,QAAgB,YAAqB;AACrC,WACE,OAAO,eAAe,UACtB,yCAAyC,OAAO,aACjD;CAED,MAAM,EAAE,IAAI,sBAAsB,OAAO,WAAW;CAKpD,MAAM,2BAJY,IAAI,KAAK,WAAW,MAAM;EAC1C,MAAM;EACN,OAAO;EACR,CAAC,CACyC,OAAO,GAAG,uBAAuB,CAAC;AAE7E,WACE,qBAAqB,KAAK,WAAW,EACrC,wFAAwF,2BACzF;CAED,MAAM,aAAa,OAAO,SAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC;AAElE,WACE,kBAAkB,WAAW,EAC7B,oBAAoB,WAAW,2DAA2D,4BAC1F,UACD;AAED,QAAO;;AAGT,SAAgB,4BAOd,QAA8C;CAC9C,SAASA,uBACP,mBAGA;AACA,SAAO,iCACL,OAAO,iBACD,OAAO,aAAa,QACpB,OAAO,aAAa,GACzB,aAAa;AACZ,OAAI,OAAO,sBAAsB,UAAU;IAEzC,MAAM,aAAa,yBACjB,UACA,kBAAkB,WACnB;AAED,WAAO,SAAS,WAAW,IAAI,EAAE,MAAM,YAAqB,CAAC,CAAC;;AAGhE,OAAI,OAAO,sBAAsB,WAC/B,QAAO,kBAAkB,SAAS;AAGpC,UAAO;IAEV;;AAGH,QAAOA;;AAiBT,SAAS,qBAQP,QACA,mBAGA;CACA,MAAM,OAAO,4BAA4B,OAAO;AAEhD,KAAI,OAAO,sBAAsB,SAC/B,QAAO,KAAK,kBAAkB;AAGhC,KAAI,OAAO,sBAAsB,WAC/B,QAAO,KAAK,kBAAkB;AAGhC,QAAO,MAAM"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-selector.ts
|
|
4
|
+
function createUseSelector(createCtx, subscribe) {
|
|
5
|
+
return (selector) => {
|
|
6
|
+
return (0, react.useSyncExternalStore)(subscribe, () => {
|
|
7
|
+
return selector(createCtx());
|
|
8
|
+
}, () => {
|
|
9
|
+
return selector(createCtx());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.createUseSelector = createUseSelector;
|
|
16
|
+
//# sourceMappingURL=use-selector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selector.cjs","names":[],"sources":["../../src/hooks/use-selector.ts"],"sourcesContent":["import type {\n AnyResolvedStep,\n StepNumbers,\n HelperFnChosenSteps,\n Expand,\n HelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { useSyncExternalStore } from 'react';\n\nexport type UseSelector<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n> = ReturnType<typeof createUseSelector<TResolvedStep, TSteps, TChosenSteps>>;\nexport type SelectorFn<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>,\n TSelected\n> = (\n ctx: Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>\n) => TSelected;\n\nexport function createUseSelector<\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 return <selected>(\n selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, selected>\n ) => {\n return useSyncExternalStore(\n subscribe,\n () => {\n const currentCtx = createCtx();\n return selector(currentCtx);\n },\n () => {\n const currentCtx = createCtx();\n return selector(currentCtx);\n }\n );\n };\n}\n"],"mappings":";;;AAuBA,SAAgB,kBAKd,WACA,WACA;AACA,SACE,aACG;AACH,yCACE,iBACM;AAEJ,UAAO,SADY,WAAW,CACH;WAEvB;AAEJ,UAAO,SADY,WAAW,CACH;IAE9B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-selector.d.ts
|
|
4
|
+
type UseSelector<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> = ReturnType<typeof createUseSelector<TResolvedStep, TSteps, TChosenSteps>>;
|
|
5
|
+
type SelectorFn<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = (ctx: Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>) => TSelected;
|
|
6
|
+
declare function createUseSelector<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): <selected>(selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, selected>) => selected;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SelectorFn, UseSelector };
|
|
9
|
+
//# sourceMappingURL=use-selector.d.cts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-selector.d.ts
|
|
4
|
+
type UseSelector<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> = ReturnType<typeof createUseSelector<TResolvedStep, TSteps, TChosenSteps>>;
|
|
5
|
+
type SelectorFn<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = (ctx: Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>) => TSelected;
|
|
6
|
+
declare function createUseSelector<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): <selected>(selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, selected>) => selected;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { SelectorFn, UseSelector };
|
|
9
|
+
//# sourceMappingURL=use-selector.d.mts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/use-selector.ts
|
|
4
|
+
function createUseSelector(createCtx, subscribe) {
|
|
5
|
+
return (selector) => {
|
|
6
|
+
return useSyncExternalStore(subscribe, () => {
|
|
7
|
+
return selector(createCtx());
|
|
8
|
+
}, () => {
|
|
9
|
+
return selector(createCtx());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createUseSelector };
|
|
16
|
+
//# sourceMappingURL=use-selector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-selector.mjs","names":[],"sources":["../../src/hooks/use-selector.ts"],"sourcesContent":["import type {\n AnyResolvedStep,\n StepNumbers,\n HelperFnChosenSteps,\n Expand,\n HelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { useSyncExternalStore } from 'react';\n\nexport type UseSelector<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>\n> = ReturnType<typeof createUseSelector<TResolvedStep, TSteps, TChosenSteps>>;\nexport type SelectorFn<\n TResolvedStep extends AnyResolvedStep,\n TSteps extends StepNumbers<TResolvedStep>,\n TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>,\n TSelected\n> = (\n ctx: Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>\n) => TSelected;\n\nexport function createUseSelector<\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 return <selected>(\n selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, selected>\n ) => {\n return useSyncExternalStore(\n subscribe,\n () => {\n const currentCtx = createCtx();\n return selector(currentCtx);\n },\n () => {\n const currentCtx = createCtx();\n return selector(currentCtx);\n }\n );\n };\n}\n"],"mappings":";;;AAuBA,SAAgB,kBAKd,WACA,WACA;AACA,SACE,aACG;AACH,SAAO,qBACL,iBACM;AAEJ,UAAO,SADY,WAAW,CACH;WAEvB;AAEJ,UAAO,SADY,WAAW,CACH;IAE9B"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const require_step_schema = require('./step-schema.cjs');
|
|
2
|
+
const require_schema = require('./schema.cjs');
|
|
3
|
+
const require_use_multi_step_form_data = require('./hooks/use-multi-step-form-data.cjs');
|
|
4
|
+
const require_create_context = require('./create-context.cjs');
|
|
5
|
+
|
|
6
|
+
exports.MultiStepFormSchema = require_schema.MultiStepFormSchema;
|
|
7
|
+
exports.MultiStepFormStepSchema = require_step_schema.MultiStepFormStepSchema;
|
|
8
|
+
Object.defineProperty(exports, 'StepSpecificComponent', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return require_step_schema.StepSpecificComponent;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
exports.createDefaultValues = require_step_schema.createDefaultValues;
|
|
15
|
+
exports.createMultiStepFormContext = require_create_context.createMultiStepFormContext;
|
|
16
|
+
exports.createMultiStepFormSchema = require_schema.createMultiStepFormSchema;
|
|
17
|
+
exports.useMultiStepFormData = require_use_multi_step_form_data.useMultiStepFormData;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, createDefaultValues } from "./step-schema.cjs";
|
|
2
|
+
import { AnyMultiStepFormSchema, MultiStepFormSchema, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.cjs";
|
|
3
|
+
import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.cjs";
|
|
4
|
+
import { CreateHOC, MultiStepFormContextResult, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createMultiStepFormContext } from "./create-context.cjs";
|
|
5
|
+
export { AnyMultiStepFormSchema, AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateHOC, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormContextResult, MultiStepFormSchema, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, createDefaultValues } from "./step-schema.mjs";
|
|
2
|
+
import { AnyMultiStepFormSchema, MultiStepFormSchema, MultiStepFormSchemaOptions, createMultiStepFormSchema } from "./schema.mjs";
|
|
3
|
+
import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.mjs";
|
|
4
|
+
import { CreateHOC, MultiStepFormContextResult, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createMultiStepFormContext } from "./create-context.mjs";
|
|
5
|
+
export { AnyMultiStepFormSchema, AnyResolvedStep, CreateComponent, CreateComponentCallback, CreateComponentFn, CreateFunction, CreateHOC, CreateStepSpecificComponentCallback, CreatedMultiStepFormComponent, ExtractedDefaultValues, HelperFunctions, MultiStepFormContextResult, MultiStepFormSchema, MultiStepFormSchemaOptions, MultiStepFormSchemaStepConfig, MultiStepFormStepSchema, ResolvedStep, StepSpecificComponent, StepSpecificCreateComponentFn, UseCurrentStepBaseResult, UseCurrentStepErrorResult, UseCurrentStepOptions, UseCurrentStepResult, UseCurrentStepSuccessResult, UseProgressBaseOptions, UseProgressOptions, UseProgressResult, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues } from "./step-schema.mjs";
|
|
2
|
+
import { MultiStepFormSchema, createMultiStepFormSchema } from "./schema.mjs";
|
|
3
|
+
import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.mjs";
|
|
4
|
+
import { createMultiStepFormContext } from "./create-context.mjs";
|
|
5
|
+
|
|
6
|
+
export { MultiStepFormSchema, MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };
|
package/dist/schema.cjs
ADDED
|
@@ -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
|
package/dist/schema.mjs
ADDED
|
@@ -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,27 @@
|
|
|
1
|
+
const require_use_selector = require('./hooks/use-selector.cjs');
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
|
|
5
|
+
//#region src/selector.tsx
|
|
6
|
+
let selector;
|
|
7
|
+
(function(_selector) {
|
|
8
|
+
function create(createCtx, subscribe) {
|
|
9
|
+
const useSelector = require_use_selector.createUseSelector(createCtx, subscribe);
|
|
10
|
+
const Selector = ({ selector: selector$1, children }) => {
|
|
11
|
+
const selected = useSelector(selector$1);
|
|
12
|
+
if (children) return (0, react.createElement)(react_jsx_runtime.Fragment, null, children(selected));
|
|
13
|
+
return (0, react.createElement)(react_jsx_runtime.Fragment, null, String(selected ?? ""));
|
|
14
|
+
};
|
|
15
|
+
return (0, react.memo)(Selector, () => false);
|
|
16
|
+
}
|
|
17
|
+
_selector.create = create;
|
|
18
|
+
})(selector || (selector = {}));
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
Object.defineProperty(exports, 'selector', {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return selector;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=selector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.cjs","names":["createUseSelector","Selector: component<TResolvedStep, TSteps, TChosenSteps>","selector","Fragment"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n StepNumbers,\n HelperFnChosenSteps,\n Expand,\n HelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { createUseSelector, SelectorFn } from './hooks/use-selector';\nimport { Fragment } from 'react/jsx-runtime';\nimport { createElement, memo } from 'react';\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 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 selector - A function that receives the current step's context and returns the selected value\n * @param children - Optional render prop that receives the selected value\n *\n * @example\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\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 }) => {\n const selected = useSelector(selector);\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n return memo(\n Selector,\n // Always return false to allow re-renders when the selected value changes\n // The memoization is just to prevent re-renders when parent re-renders\n () => false\n );\n }\n}\n"],"mappings":";;;;;;;CA2CS,SAAS,OAKd,WACA,WACA;EACA,MAAM,cAAcA,uCAAkB,WAAW,UAAU;EAC3D,MAAMC,YAA4D,EAChE,sBACA,eACI;GACJ,MAAM,WAAW,YAAYC,WAAS;AAEtC,OAAI,SACF,iCAAqBC,4BAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,mCAAqBA,4BAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAG9D,yBACE,gBAGM,MACP"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SelectorFn } from "./hooks/use-selector.cjs";
|
|
2
|
+
import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
|
|
3
|
+
import * as react0 from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/selector.d.ts
|
|
6
|
+
declare namespace selector {
|
|
7
|
+
type props<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = {
|
|
8
|
+
selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, TSelected>;
|
|
9
|
+
children?: (selected: TSelected) => React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
type component<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> =
|
|
12
|
+
/**
|
|
13
|
+
* A component for reactively displaying a value from the form context.
|
|
14
|
+
* Unlike `useSelector`, this component only re-renders itself, not the parent component.
|
|
15
|
+
* Use this when you want to display a reactive value without causing parent re-renders.
|
|
16
|
+
*
|
|
17
|
+
* @param selector - A function that receives the current step's context and returns the selected value
|
|
18
|
+
* @param children - Optional render prop that receives the selected value
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>
|
|
22
|
+
* {(value) => <p>First name: {value}</p>}
|
|
23
|
+
* </Selector>
|
|
24
|
+
*/
|
|
25
|
+
<TSelected>(props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>) => React.ReactNode;
|
|
26
|
+
function create<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): react0.MemoExoticComponent<component<TResolvedStep, TSteps, TChosenSteps>>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { selector };
|
|
30
|
+
//# sourceMappingURL=selector.d.cts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SelectorFn } from "./hooks/use-selector.mjs";
|
|
2
|
+
import { AnyResolvedStep, Expand, HelperFnChosenSteps, HelperFnCtx, StepNumbers } from "@jfdevelops/multi-step-form-core";
|
|
3
|
+
import * as react0 from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/selector.d.ts
|
|
6
|
+
declare namespace selector {
|
|
7
|
+
type props<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>, TSelected> = {
|
|
8
|
+
selector: SelectorFn<TResolvedStep, TSteps, TChosenSteps, TSelected>;
|
|
9
|
+
children?: (selected: TSelected) => React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
type component<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>> =
|
|
12
|
+
/**
|
|
13
|
+
* A component for reactively displaying a value from the form context.
|
|
14
|
+
* Unlike `useSelector`, this component only re-renders itself, not the parent component.
|
|
15
|
+
* Use this when you want to display a reactive value without causing parent re-renders.
|
|
16
|
+
*
|
|
17
|
+
* @param selector - A function that receives the current step's context and returns the selected value
|
|
18
|
+
* @param children - Optional render prop that receives the selected value
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>
|
|
22
|
+
* {(value) => <p>First name: {value}</p>}
|
|
23
|
+
* </Selector>
|
|
24
|
+
*/
|
|
25
|
+
<TSelected>(props: props<TResolvedStep, TSteps, TChosenSteps, TSelected>) => React.ReactNode;
|
|
26
|
+
function create<TResolvedStep extends AnyResolvedStep, TSteps extends StepNumbers<TResolvedStep>, TChosenSteps extends HelperFnChosenSteps<TResolvedStep, TSteps>>(createCtx: () => Expand<HelperFnCtx<TResolvedStep, TSteps, TChosenSteps>>, subscribe: (listener: () => void) => () => void): react0.MemoExoticComponent<component<TResolvedStep, TSteps, TChosenSteps>>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { selector };
|
|
30
|
+
//# sourceMappingURL=selector.d.mts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createUseSelector } from "./hooks/use-selector.mjs";
|
|
2
|
+
import { createElement, memo } from "react";
|
|
3
|
+
import { Fragment } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/selector.tsx
|
|
6
|
+
let selector;
|
|
7
|
+
(function(_selector) {
|
|
8
|
+
function create(createCtx, subscribe) {
|
|
9
|
+
const useSelector = createUseSelector(createCtx, subscribe);
|
|
10
|
+
const Selector = ({ selector: selector$1, children }) => {
|
|
11
|
+
const selected = useSelector(selector$1);
|
|
12
|
+
if (children) return createElement(Fragment, null, children(selected));
|
|
13
|
+
return createElement(Fragment, null, String(selected ?? ""));
|
|
14
|
+
};
|
|
15
|
+
return memo(Selector, () => false);
|
|
16
|
+
}
|
|
17
|
+
_selector.create = create;
|
|
18
|
+
})(selector || (selector = {}));
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { selector };
|
|
22
|
+
//# sourceMappingURL=selector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.mjs","names":["Selector: component<TResolvedStep, TSteps, TChosenSteps>","selector"],"sources":["../src/selector.tsx"],"sourcesContent":["import {\n AnyResolvedStep,\n StepNumbers,\n HelperFnChosenSteps,\n Expand,\n HelperFnCtx,\n} from '@jfdevelops/multi-step-form-core';\nimport { createUseSelector, SelectorFn } from './hooks/use-selector';\nimport { Fragment } from 'react/jsx-runtime';\nimport { createElement, memo } from 'react';\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 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 selector - A function that receives the current step's context and returns the selected value\n * @param children - Optional render prop that receives the selected value\n *\n * @example\n * <Selector selector={(ctx) => ctx.step1.fields.firstName.defaultValue}>\n * {(value) => <p>First name: {value}</p>}\n * </Selector>\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 }) => {\n const selected = useSelector(selector);\n\n if (children) {\n return createElement(Fragment, null, children(selected));\n }\n return createElement(Fragment, null, String(selected ?? ''));\n };\n\n return memo(\n Selector,\n // Always return false to allow re-renders when the selected value changes\n // The memoization is just to prevent re-renders when parent re-renders\n () => false\n );\n }\n}\n"],"mappings":";;;;;;;CA2CS,SAAS,OAKd,WACA,WACA;EACA,MAAM,cAAc,kBAAkB,WAAW,UAAU;EAC3D,MAAMA,YAA4D,EAChE,sBACA,eACI;GACJ,MAAM,WAAW,YAAYC,WAAS;AAEtC,OAAI,SACF,QAAO,cAAc,UAAU,MAAM,SAAS,SAAS,CAAC;AAE1D,UAAO,cAAc,UAAU,MAAM,OAAO,YAAY,GAAG,CAAC;;AAG9D,SAAO,KACL,gBAGM,MACP"}
|