@buildnbuzz/buzzform 0.1.6 → 0.1.7
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/{adapter-CpEUN0gt.d.mts → adapter-Bd0fYuAE.d.mts} +56 -5
- package/dist/{adapter-CpEUN0gt.d.ts → adapter-Bd0fYuAE.d.ts} +56 -5
- package/dist/{chunk-VXG7KGOZ.mjs → chunk-P5XPEIIF.mjs} +37 -2
- package/dist/chunk-P5XPEIIF.mjs.map +1 -0
- package/dist/index.d.mts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +62 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -7
- package/dist/index.mjs.map +1 -1
- package/dist/rhf.d.mts +1 -1
- package/dist/rhf.d.ts +1 -1
- package/dist/rhf.mjs +1 -1
- package/dist/schema.d.mts +3 -3
- package/dist/schema.d.ts +3 -3
- package/dist/schema.mjs +1 -1
- package/dist/{utils-DTtDPnVV.d.mts → utils-BsX0viz8.d.mts} +1 -1
- package/dist/{utils-YM0cIt68.d.ts → utils-DHF346op.d.ts} +1 -1
- package/dist/zod.d.mts +1 -1
- package/dist/zod.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-VXG7KGOZ.mjs.map +0 -1
|
@@ -692,6 +692,43 @@ interface FormSettings {
|
|
|
692
692
|
*/
|
|
693
693
|
autoFocus?: boolean;
|
|
694
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Output type for form submission data.
|
|
697
|
+
* - 'path': Flat keys with full path using a delimiter (e.g., "person.contactDetails.address.street")
|
|
698
|
+
*
|
|
699
|
+
* When no output config is set, the default behavior is preserved
|
|
700
|
+
* (hierarchical JSON matching the field tree structure).
|
|
701
|
+
*/
|
|
702
|
+
type OutputType = "path";
|
|
703
|
+
/**
|
|
704
|
+
* Delimiter character used for path output.
|
|
705
|
+
* @default '.'
|
|
706
|
+
*/
|
|
707
|
+
type PathDelimiter = "." | "-" | "_";
|
|
708
|
+
/**
|
|
709
|
+
* Configuration for form submission output shape.
|
|
710
|
+
* When omitted, the default hierarchical JSON output is used.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* // Path output with dot: { 'person.name': 'John', 'person.address.street': 'Main St' }
|
|
714
|
+
* output: { type: 'path' }
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* // Path output with underscore: { 'person_name': 'John', 'person_address_street': 'Main St' }
|
|
718
|
+
* output: { type: 'path', delimiter: '_' }
|
|
719
|
+
*/
|
|
720
|
+
interface OutputConfig {
|
|
721
|
+
/**
|
|
722
|
+
* Output mode.
|
|
723
|
+
* Set to 'path' to flatten nested data into delimited path keys.
|
|
724
|
+
*/
|
|
725
|
+
type: OutputType;
|
|
726
|
+
/**
|
|
727
|
+
* Delimiter for path keys.
|
|
728
|
+
* @default '.'
|
|
729
|
+
*/
|
|
730
|
+
delimiter?: PathDelimiter;
|
|
731
|
+
}
|
|
695
732
|
/**
|
|
696
733
|
* Global form configuration set at the provider level.
|
|
697
734
|
* These defaults apply to all forms unless overridden.
|
|
@@ -732,7 +769,7 @@ interface FormConfig {
|
|
|
732
769
|
* - 'onSubmit': Validate only on submit
|
|
733
770
|
* @default 'onChange'
|
|
734
771
|
*/
|
|
735
|
-
mode?:
|
|
772
|
+
mode?: "onChange" | "onBlur" | "onSubmit";
|
|
736
773
|
/**
|
|
737
774
|
* When to re-validate after initial validation error.
|
|
738
775
|
* - 'onChange': Re-validate on every change (default)
|
|
@@ -740,7 +777,14 @@ interface FormConfig {
|
|
|
740
777
|
* - 'onSubmit': Re-validate only on submit
|
|
741
778
|
* @default 'onChange'
|
|
742
779
|
*/
|
|
743
|
-
reValidateMode?:
|
|
780
|
+
reValidateMode?: "onChange" | "onBlur" | "onSubmit";
|
|
781
|
+
/**
|
|
782
|
+
* Default output configuration for all forms.
|
|
783
|
+
* Controls the shape of data passed to onSubmit.
|
|
784
|
+
* Can be overridden per-form via UseFormOptions.
|
|
785
|
+
* @default undefined (hierarchical JSON)
|
|
786
|
+
*/
|
|
787
|
+
output?: OutputConfig;
|
|
744
788
|
}
|
|
745
789
|
/**
|
|
746
790
|
* Options passed to useForm hook.
|
|
@@ -785,12 +829,19 @@ interface UseFormOptions<TData = Record<string, unknown>> {
|
|
|
785
829
|
* Override the validation mode for this form.
|
|
786
830
|
* Uses provider's mode if not specified.
|
|
787
831
|
*/
|
|
788
|
-
mode?:
|
|
832
|
+
mode?: "onChange" | "onBlur" | "onSubmit";
|
|
789
833
|
/**
|
|
790
834
|
* Override the re-validation mode for this form.
|
|
791
835
|
* Uses provider's reValidateMode if not specified.
|
|
792
836
|
*/
|
|
793
|
-
reValidateMode?:
|
|
837
|
+
reValidateMode?: "onChange" | "onBlur" | "onSubmit";
|
|
838
|
+
/**
|
|
839
|
+
* Output configuration for this form.
|
|
840
|
+
* Overrides the provider-level output config.
|
|
841
|
+
* Controls the shape of data passed to onSubmit.
|
|
842
|
+
* @default undefined (defaults to hierarchical JSON if not specified here or in Provider)
|
|
843
|
+
*/
|
|
844
|
+
output?: OutputConfig;
|
|
794
845
|
/**
|
|
795
846
|
* Form behavior settings.
|
|
796
847
|
*/
|
|
@@ -1173,4 +1224,4 @@ type AdapterFactory<TData = Record<string, unknown>> = (options: AdapterOptions<
|
|
|
1173
1224
|
*/
|
|
1174
1225
|
declare function validateAdapter(adapter: FormAdapter, adapterName?: string): void;
|
|
1175
1226
|
|
|
1176
|
-
export { type ArrayHelpers as A, type BaseField as B, type ConditionContext as C, type DateField as D, type EmailField as E, type Field as F, type GroupField as G, type RowField as H, type Tab as I, type TabsField as J, type CollapsibleField as K, type FieldType as L, type DataField as M, type NumberField as N, type
|
|
1227
|
+
export { type ArrayHelpers as A, type BaseField as B, type ConditionContext as C, type DateField as D, type EmailField as E, type Field as F, type GroupField as G, type RowField as H, type Tab as I, type TabsField as J, type CollapsibleField as K, type FieldType as L, type DataField as M, type NumberField as N, type OutputConfig as O, type PasswordField as P, type LayoutField as Q, type ResolverResult as R, type SetValueOptions as S, type TextField as T, type UseFormOptions as U, type ValidationContext as V, type BuzzFormSchema as W, type FormSettings as X, type OutputType as Y, type PathDelimiter as Z, type FormConfig as a, type FormAdapter as b, type FormState as c, type FieldError as d, type Resolver as e, type AdapterOptions as f, type AdapterFactory as g, type ValidationResult as h, type ValidationFn as i, type FieldCondition as j, type FieldComponentProps as k, type FieldInputProps as l, type FieldInputRenderFn as m, type FieldStyle as n, type TextareaField as o, type DatetimeField as p, type SelectOption as q, type SelectField as r, type CheckboxGroupField as s, type CheckboxField as t, type SwitchField as u, validateAdapter as v, type RadioField as w, type TagsField as x, type UploadField as y, type ArrayField as z };
|
|
@@ -692,6 +692,43 @@ interface FormSettings {
|
|
|
692
692
|
*/
|
|
693
693
|
autoFocus?: boolean;
|
|
694
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Output type for form submission data.
|
|
697
|
+
* - 'path': Flat keys with full path using a delimiter (e.g., "person.contactDetails.address.street")
|
|
698
|
+
*
|
|
699
|
+
* When no output config is set, the default behavior is preserved
|
|
700
|
+
* (hierarchical JSON matching the field tree structure).
|
|
701
|
+
*/
|
|
702
|
+
type OutputType = "path";
|
|
703
|
+
/**
|
|
704
|
+
* Delimiter character used for path output.
|
|
705
|
+
* @default '.'
|
|
706
|
+
*/
|
|
707
|
+
type PathDelimiter = "." | "-" | "_";
|
|
708
|
+
/**
|
|
709
|
+
* Configuration for form submission output shape.
|
|
710
|
+
* When omitted, the default hierarchical JSON output is used.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* // Path output with dot: { 'person.name': 'John', 'person.address.street': 'Main St' }
|
|
714
|
+
* output: { type: 'path' }
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* // Path output with underscore: { 'person_name': 'John', 'person_address_street': 'Main St' }
|
|
718
|
+
* output: { type: 'path', delimiter: '_' }
|
|
719
|
+
*/
|
|
720
|
+
interface OutputConfig {
|
|
721
|
+
/**
|
|
722
|
+
* Output mode.
|
|
723
|
+
* Set to 'path' to flatten nested data into delimited path keys.
|
|
724
|
+
*/
|
|
725
|
+
type: OutputType;
|
|
726
|
+
/**
|
|
727
|
+
* Delimiter for path keys.
|
|
728
|
+
* @default '.'
|
|
729
|
+
*/
|
|
730
|
+
delimiter?: PathDelimiter;
|
|
731
|
+
}
|
|
695
732
|
/**
|
|
696
733
|
* Global form configuration set at the provider level.
|
|
697
734
|
* These defaults apply to all forms unless overridden.
|
|
@@ -732,7 +769,7 @@ interface FormConfig {
|
|
|
732
769
|
* - 'onSubmit': Validate only on submit
|
|
733
770
|
* @default 'onChange'
|
|
734
771
|
*/
|
|
735
|
-
mode?:
|
|
772
|
+
mode?: "onChange" | "onBlur" | "onSubmit";
|
|
736
773
|
/**
|
|
737
774
|
* When to re-validate after initial validation error.
|
|
738
775
|
* - 'onChange': Re-validate on every change (default)
|
|
@@ -740,7 +777,14 @@ interface FormConfig {
|
|
|
740
777
|
* - 'onSubmit': Re-validate only on submit
|
|
741
778
|
* @default 'onChange'
|
|
742
779
|
*/
|
|
743
|
-
reValidateMode?:
|
|
780
|
+
reValidateMode?: "onChange" | "onBlur" | "onSubmit";
|
|
781
|
+
/**
|
|
782
|
+
* Default output configuration for all forms.
|
|
783
|
+
* Controls the shape of data passed to onSubmit.
|
|
784
|
+
* Can be overridden per-form via UseFormOptions.
|
|
785
|
+
* @default undefined (hierarchical JSON)
|
|
786
|
+
*/
|
|
787
|
+
output?: OutputConfig;
|
|
744
788
|
}
|
|
745
789
|
/**
|
|
746
790
|
* Options passed to useForm hook.
|
|
@@ -785,12 +829,19 @@ interface UseFormOptions<TData = Record<string, unknown>> {
|
|
|
785
829
|
* Override the validation mode for this form.
|
|
786
830
|
* Uses provider's mode if not specified.
|
|
787
831
|
*/
|
|
788
|
-
mode?:
|
|
832
|
+
mode?: "onChange" | "onBlur" | "onSubmit";
|
|
789
833
|
/**
|
|
790
834
|
* Override the re-validation mode for this form.
|
|
791
835
|
* Uses provider's reValidateMode if not specified.
|
|
792
836
|
*/
|
|
793
|
-
reValidateMode?:
|
|
837
|
+
reValidateMode?: "onChange" | "onBlur" | "onSubmit";
|
|
838
|
+
/**
|
|
839
|
+
* Output configuration for this form.
|
|
840
|
+
* Overrides the provider-level output config.
|
|
841
|
+
* Controls the shape of data passed to onSubmit.
|
|
842
|
+
* @default undefined (defaults to hierarchical JSON if not specified here or in Provider)
|
|
843
|
+
*/
|
|
844
|
+
output?: OutputConfig;
|
|
794
845
|
/**
|
|
795
846
|
* Form behavior settings.
|
|
796
847
|
*/
|
|
@@ -1173,4 +1224,4 @@ type AdapterFactory<TData = Record<string, unknown>> = (options: AdapterOptions<
|
|
|
1173
1224
|
*/
|
|
1174
1225
|
declare function validateAdapter(adapter: FormAdapter, adapterName?: string): void;
|
|
1175
1226
|
|
|
1176
|
-
export { type ArrayHelpers as A, type BaseField as B, type ConditionContext as C, type DateField as D, type EmailField as E, type Field as F, type GroupField as G, type RowField as H, type Tab as I, type TabsField as J, type CollapsibleField as K, type FieldType as L, type DataField as M, type NumberField as N, type
|
|
1227
|
+
export { type ArrayHelpers as A, type BaseField as B, type ConditionContext as C, type DateField as D, type EmailField as E, type Field as F, type GroupField as G, type RowField as H, type Tab as I, type TabsField as J, type CollapsibleField as K, type FieldType as L, type DataField as M, type NumberField as N, type OutputConfig as O, type PasswordField as P, type LayoutField as Q, type ResolverResult as R, type SetValueOptions as S, type TextField as T, type UseFormOptions as U, type ValidationContext as V, type BuzzFormSchema as W, type FormSettings as X, type OutputType as Y, type PathDelimiter as Z, type FormConfig as a, type FormAdapter as b, type FormState as c, type FieldError as d, type Resolver as e, type AdapterOptions as f, type AdapterFactory as g, type ValidationResult as h, type ValidationFn as i, type FieldCondition as j, type FieldComponentProps as k, type FieldInputProps as l, type FieldInputRenderFn as m, type FieldStyle as n, type TextareaField as o, type DatetimeField as p, type SelectOption as q, type SelectField as r, type CheckboxGroupField as s, type CheckboxField as t, type SwitchField as u, validateAdapter as v, type RadioField as w, type TagsField as x, type UploadField as y, type ArrayField as z };
|
|
@@ -253,6 +253,40 @@ function parseToDate(value) {
|
|
|
253
253
|
return void 0;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
// src/lib/output.ts
|
|
257
|
+
function transformFormOutput(data, config) {
|
|
258
|
+
if (!config || config.type !== "path") {
|
|
259
|
+
return data;
|
|
260
|
+
}
|
|
261
|
+
if (typeof data !== "object" || data === null) {
|
|
262
|
+
return data;
|
|
263
|
+
}
|
|
264
|
+
return flattenToPathKeys(
|
|
265
|
+
data,
|
|
266
|
+
config.delimiter ?? "."
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function flattenToPathKeys(data, delimiter, prefix = "") {
|
|
270
|
+
const result = {};
|
|
271
|
+
for (const [key, value] of Object.entries(data)) {
|
|
272
|
+
const path = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
273
|
+
if (isPlainObject(value)) {
|
|
274
|
+
Object.assign(
|
|
275
|
+
result,
|
|
276
|
+
flattenToPathKeys(value, delimiter, path)
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
result[path] = value;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
function isPlainObject(value) {
|
|
285
|
+
if (typeof value !== "object" || value === null) return false;
|
|
286
|
+
const proto = Object.getPrototypeOf(value);
|
|
287
|
+
return proto === Object.prototype || proto === null;
|
|
288
|
+
}
|
|
289
|
+
|
|
256
290
|
export {
|
|
257
291
|
createArrayHelpers,
|
|
258
292
|
generateFieldId,
|
|
@@ -274,6 +308,7 @@ export {
|
|
|
274
308
|
applyNumericPrecision,
|
|
275
309
|
formatNumberWithSeparator,
|
|
276
310
|
parseFormattedNumber,
|
|
277
|
-
parseToDate
|
|
311
|
+
parseToDate,
|
|
312
|
+
transformFormOutput
|
|
278
313
|
};
|
|
279
|
-
//# sourceMappingURL=chunk-
|
|
314
|
+
//# sourceMappingURL=chunk-P5XPEIIF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/array.ts","../src/lib/utils.ts","../src/lib/field.ts","../src/lib/output.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport type { ArrayHelpers } from '../types';\n\n/**\n * Creates a standardized set of array field manipulation methods.\n * Abstracts the difference between getting/setting values in different form libraries.\n * \n * @param getArray - Function to get current array value at a path\n * @param setArray - Function to set array value at a path\n */\nexport function createArrayHelpers(\n getArray: (path: string) => unknown,\n setArray: (path: string, value: unknown[]) => void\n): ArrayHelpers {\n const readArray = (path: string): unknown[] => {\n const value = getArray(path);\n return Array.isArray(value) ? value : [];\n };\n\n return {\n fields: <T = unknown>(path: string): Array<T & { id: string }> => {\n const arr = readArray(path);\n return arr.map((item, index) => {\n const itemObject =\n typeof item === 'object' && item !== null\n ? (item as Record<string, unknown>)\n : ({ value: item } as Record<string, unknown>);\n\n return {\n id: (itemObject.id as string) || `${path}-${index}`,\n ...(itemObject as T),\n };\n });\n },\n\n append: (path: string, value: unknown) => {\n const current = readArray(path);\n const itemWithId = ensureId(value);\n setArray(path, [...current, itemWithId]);\n },\n\n prepend: (path: string, value: unknown) => {\n const current = readArray(path);\n const itemWithId = ensureId(value);\n setArray(path, [itemWithId, ...current]);\n },\n\n insert: (path: string, index: number, value: unknown) => {\n const current = [...readArray(path)];\n const itemWithId = ensureId(value);\n current.splice(index, 0, itemWithId);\n setArray(path, current);\n },\n\n remove: (path: string, index: number) => {\n const current = [...readArray(path)];\n current.splice(index, 1);\n setArray(path, current);\n },\n\n move: (path: string, from: number, to: number) => {\n const current = [...readArray(path)];\n const [item] = current.splice(from, 1);\n current.splice(to, 0, item);\n setArray(path, current);\n },\n\n swap: (path: string, indexA: number, indexB: number) => {\n const current = [...readArray(path)];\n const temp = current[indexA];\n current[indexA] = current[indexB];\n current[indexB] = temp;\n setArray(path, current);\n },\n\n replace: (path: string, values: unknown[]) => {\n const itemsWithIds = values.map(ensureId);\n setArray(path, itemsWithIds);\n },\n\n update: (path: string, index: number, value: unknown) => {\n const current = [...readArray(path)];\n // Preserve existing ID if present\n const existingId = (current[index] as Record<string, unknown>)?.id;\n current[index] = {\n ...(typeof value === 'object' && value !== null ? value : {}),\n id: existingId || nanoid(),\n };\n setArray(path, current);\n },\n };\n}\n\n/**\n * Ensures an item has a unique ID for React keys.\n */\nfunction ensureId(value: unknown): unknown {\n if (typeof value === 'object' && value !== null) {\n const obj = value as Record<string, unknown>;\n if (!obj.id) {\n return { ...obj, id: nanoid() };\n }\n return obj;\n }\n return { value, id: nanoid() };\n}\n","// =============================================================================\n// COMMON UTILITIES\n// These are used by both the core package and registry field components.\n// =============================================================================\n\n/**\n * Generate a unique field ID from the field path.\n * Converts dot notation to dashes and prefixes with 'field-'.\n * Used for accessibility (htmlFor, id attributes).\n * \n * @example\n * generateFieldId('user.profile.email') => 'field-user-profile-email'\n * generateFieldId('items[0].name') => 'field-items-0-name'\n */\nexport function generateFieldId(path: string): string {\n return `field-${path.replace(/\\./g, \"-\").replace(/\\[/g, \"-\").replace(/\\]/g, \"\")}`;\n}\n\n/**\n * Safely retrieve a nested value from an object using a dot-notation path.\n * \n * @example\n * getNestedValue({ user: { name: 'John' } }, 'user.name') => 'John'\n * getNestedValue({ items: [{ id: 1 }] }, 'items.0.id') => 1\n */\nexport function getNestedValue(obj: unknown, path: string): unknown {\n if (!obj || !path) return undefined;\n return path.split(\".\").reduce<unknown>((acc: unknown, key: string) => {\n if (acc && typeof acc === \"object\" && acc !== null) {\n return (acc as Record<string, unknown>)[key];\n }\n return undefined;\n }, obj);\n}\n\n/**\n * Set a nested value in an object using a dot-notation path.\n * Creates intermediate objects/arrays as needed.\n * \n * @example\n * setNestedValue({}, 'user.name', 'John') => { user: { name: 'John' } }\n */\nexport function setNestedValue<T extends Record<string, unknown>>(\n obj: T,\n path: string,\n value: unknown\n): T {\n const keys = path.split(\".\");\n const result = { ...obj } as Record<string, unknown>;\n let current = result;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n if (!(key in current) || typeof current[key] !== \"object\") {\n // Check if next key is numeric (array index)\n const nextKey = keys[i + 1];\n current[key] = /^\\d+$/.test(nextKey) ? [] : {};\n } else {\n current[key] = Array.isArray(current[key])\n ? [...(current[key] as unknown[])]\n : { ...(current[key] as Record<string, unknown>) };\n }\n current = current[key] as Record<string, unknown>;\n }\n\n current[keys[keys.length - 1]] = value;\n return result as T;\n}\n\n/**\n * Format bytes into a human-readable string.\n * \n * @example\n * formatBytes(1024) => '1 KB'\n * formatBytes(1234567) => '1.18 MB'\n */\nexport function formatBytes(bytes: number, decimals = 2): string {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1024;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;\n}\n\n/**\n * Flatten a nested object to dot-notation paths.\n * Useful for converting form library state (like dirtyFields, touchedFields)\n * to the flat format expected by FormState.\n * \n * @example\n * flattenNestedObject({ user: { name: true, email: true } })\n * // => { 'user.name': true, 'user.email': true }\n * \n * flattenNestedObject({ items: { 0: { title: true } } })\n * // => { 'items.0.title': true }\n */\nexport function flattenNestedObject(\n obj: Record<string, unknown>,\n prefix = ''\n): Record<string, boolean> {\n const result: Record<string, boolean> = {};\n\n for (const key in obj) {\n const path = prefix ? `${prefix}.${key}` : key;\n const value = obj[key];\n\n if (typeof value === 'boolean') {\n result[path] = value;\n } else if (value !== null && typeof value === 'object' && !Array.isArray(value)) {\n Object.assign(result, flattenNestedObject(value as Record<string, unknown>, path));\n }\n }\n\n return result;\n}\n\n","import type { ReactNode } from 'react';\nimport type { Field } from '../types';\n\n// =============================================================================\n// FIELD PATH UTILITIES\n// These utilities help work with nested field definitions and form data.\n// =============================================================================\n\n/**\n * Recursively extracts all field paths from a field definition tree.\n * Handles nested groups, arrays, and layout fields (rows, tabs, collapsibles).\n * \n * @param fields - Array of field definitions\n * @param basePath - Base path prefix (e.g., \"contacts.0\" for array items)\n * @returns Array of all field paths\n * \n * @example\n * const fields = [\n * { type: 'text', name: 'name' },\n * { type: 'group', name: 'address', fields: [\n * { type: 'text', name: 'city' },\n * { type: 'text', name: 'zip' }\n * ]}\n * ];\n * getNestedFieldPaths(fields, 'contact')\n * // => ['contact.name', 'contact.address', 'contact.address.city', 'contact.address.zip']\n */\nexport function getNestedFieldPaths(fields: Field[], basePath: string): string[] {\n const paths: string[] = [];\n\n for (const field of fields) {\n // Data fields with names\n if ('name' in field && field.name) {\n const fieldPath = basePath ? `${basePath}.${field.name}` : field.name;\n paths.push(fieldPath);\n\n // Recurse into group/array fields\n if (field.type === 'group' && 'fields' in field) {\n paths.push(...getNestedFieldPaths(field.fields, fieldPath));\n }\n if (field.type === 'array' && 'fields' in field) {\n paths.push(...getNestedFieldPaths(field.fields, fieldPath));\n }\n }\n\n // Layout fields (row, tabs, collapsible) - pass through without adding to path\n if ('fields' in field && field.type !== 'group' && field.type !== 'array') {\n const layoutField = field as Field & { fields: Field[] };\n paths.push(...getNestedFieldPaths(layoutField.fields, basePath));\n }\n\n // Tabs field - iterate through tabs\n if (field.type === 'tabs' && 'tabs' in field) {\n for (const tab of field.tabs) {\n const tabPath = tab.name ? (basePath ? `${basePath}.${tab.name}` : tab.name) : basePath;\n paths.push(...getNestedFieldPaths(tab.fields, tabPath));\n }\n }\n }\n\n return paths;\n}\n\n/**\n * Count validation errors in nested fields.\n * Useful for showing error badges on collapsible sections, array rows, tabs, etc.\n * \n * @param errors - Form errors object from FormAdapter.formState.errors\n * @param fields - Field definitions to check\n * @param basePath - Base path for the fields\n * @returns Number of fields with errors\n * \n * @example\n * const errorCount = countNestedErrors(form.formState.errors, arrayField.fields, `items.0`);\n */\nexport function countNestedErrors(\n errors: Record<string, unknown>,\n fields: Field[],\n basePath: string\n): number {\n const paths = getNestedFieldPaths(fields, basePath);\n return paths.filter((path) => errors[path]).length;\n}\n\n/**\n * Resolve a potentially dynamic field property (disabled, readOnly, hidden).\n * These properties can be boolean or a function that receives form data.\n * \n * @param value - The property value (boolean or function)\n * @param formData - Current form data\n * @param siblingData - Data at the same level (for arrays, this is the row data)\n * @returns Resolved boolean value\n * \n * @example\n * const isDisabled = resolveFieldState(field.disabled, formData, siblingData);\n */\nexport function resolveFieldState<TData = Record<string, unknown>>(\n value: boolean | ((data: TData, siblingData: Record<string, unknown>) => boolean) | undefined,\n formData: TData,\n siblingData: Record<string, unknown> = formData as Record<string, unknown>\n): boolean {\n if (typeof value === 'function') {\n return value(formData, siblingData);\n }\n return Boolean(value);\n}\n\n/**\n * Get the label value for an array row based on field configuration.\n * First checks for a specific rowLabelField in ui options, then falls back\n * to the first named field's value.\n * \n * @param rowData - Data for the row\n * @param fields - Field definitions for the array\n * @param uiOptions - UI options that may contain rowLabelField\n * @param fallbackLabel - Default label if no value found\n * @returns Label string for the row\n * \n * @example\n * const label = getArrayRowLabel(rowData, field.fields, field.ui, `Item ${index + 1}`);\n */\nexport function getArrayRowLabel(\n rowData: Record<string, unknown> | undefined,\n fields: Field[],\n uiOptions: { rowLabelField?: string } | undefined,\n fallbackLabel: string\n): string {\n // First try explicit rowLabelField\n if (uiOptions?.rowLabelField && rowData?.[uiOptions.rowLabelField]) {\n return String(rowData[uiOptions.rowLabelField]);\n }\n\n // Fall back to first named field\n const firstNamedField = fields.find((f) => 'name' in f && f.name);\n if (firstNamedField && 'name' in firstNamedField) {\n const value = rowData?.[firstNamedField.name];\n if (value) {\n return String(value);\n }\n }\n\n return fallbackLabel;\n}\n\n// =============================================================================\n// FIELD STYLE UTILITIES\n// Helpers for computing field styling props.\n// =============================================================================\n\n/**\n * Compute the inline style object for a field's width.\n * Handles both numeric (px) and string (CSS) width values.\n * \n * @param style - Field style configuration\n * @returns CSS properties object or undefined if no width specified\n * \n * @example\n * <Field style={getFieldWidthStyle(field.style)}>\n * ...\n * </Field>\n */\nexport function getFieldWidthStyle(\n style: { width?: number | string } | undefined\n): { width: string } | undefined {\n if (!style?.width) return undefined;\n return {\n width: typeof style.width === 'number'\n ? `${style.width}px`\n : style.width,\n };\n}\n\n// =============================================================================\n// SELECT OPTION UTILITIES\n// Helpers for normalizing and extracting data from SelectOption | string.\n// =============================================================================\n\ntype SelectOptionLike = { value: string | number | boolean; label?: ReactNode; description?: ReactNode; icon?: ReactNode; disabled?: boolean } | string;\n\n/**\n * Normalize a select option to always be an object.\n * Converts string options to { value, label } objects.\n * \n * @param option - String or SelectOption object\n * @returns Normalized SelectOption object\n * \n * @example\n * normalizeSelectOption('foo') // => { value: 'foo', label: 'foo' }\n * normalizeSelectOption({ value: 'bar', label: 'Bar' }) // => { value: 'bar', label: 'Bar' }\n */\nexport function normalizeSelectOption(option: SelectOptionLike): {\n value: string | number | boolean;\n label: ReactNode;\n description?: ReactNode;\n icon?: ReactNode;\n disabled?: boolean;\n} {\n if (typeof option === 'string') {\n return { value: option, label: option };\n }\n return {\n value: option.value,\n label: option.label ?? String(option.value),\n description: option.description,\n icon: option.icon,\n disabled: option.disabled,\n };\n}\n\n/**\n * Get the value from a select option (handles string or object).\n * \n * @param option - String or SelectOption object\n * @returns The option's value as a string\n * \n * @example\n * getSelectOptionValue('foo') // => 'foo'\n * getSelectOptionValue({ value: 123, label: 'One Two Three' }) // => '123'\n */\nexport function getSelectOptionValue(option: SelectOptionLike): string {\n if (typeof option === 'string') return option;\n const val = option.value;\n if (typeof val === 'boolean') return val ? 'true' : 'false';\n return String(val);\n}\n\n/**\n * Get the label from a select option (handles string or object).\n * Returns ReactNode to support JSX labels.\n * \n * @param option - String or SelectOption object\n * @returns The option's label for display\n * \n * @example\n * getSelectOptionLabel('foo') // => 'foo'\n * getSelectOptionLabel({ value: 'bar', label: <strong>Bar</strong> }) // => <strong>Bar</strong>\n */\nexport function getSelectOptionLabel(option: SelectOptionLike): ReactNode {\n if (typeof option === 'string') return option;\n return option.label ?? String(option.value);\n}\n\n/**\n * Get the string label from a select option (for filtering/comparison).\n * Always returns a string, not ReactNode.\n * \n * @param option - String or SelectOption object\n * @returns The option's label as a string\n */\nexport function getSelectOptionLabelString(option: SelectOptionLike): string {\n if (typeof option === 'string') return option;\n if (typeof option.label === 'string') return option.label;\n return String(option.value);\n}\n\n/**\n * Check if a select option is disabled.\n * \n * @param option - String or SelectOption object\n * @returns true if option is disabled\n */\nexport function isSelectOptionDisabled(option: SelectOptionLike): boolean {\n if (typeof option === 'string') return false;\n return option.disabled === true;\n}\n\n// =============================================================================\n// NUMBER UTILITIES\n// Helpers for number field operations.\n// =============================================================================\n\n/**\n * Clamp a number between min and max bounds.\n * \n * @param value - The number to clamp\n * @param min - Minimum bound (optional)\n * @param max - Maximum bound (optional)\n * @returns Clamped number\n * \n * @example\n * clampNumber(5, 0, 10) // => 5\n * clampNumber(-5, 0, 10) // => 0\n * clampNumber(15, 0, 10) // => 10\n */\nexport function clampNumber(value: number, min?: number, max?: number): number {\n let result = value;\n if (min !== undefined && result < min) result = min;\n if (max !== undefined && result > max) result = max;\n return result;\n}\n\n/**\n * Apply numeric precision (decimal places) to a number.\n * \n * @param value - The number to format\n * @param precision - Number of decimal places\n * @returns Formatted number or undefined if input is undefined\n * \n * @example\n * applyNumericPrecision(3.14159, 2) // => 3.14\n * applyNumericPrecision(10, 2) // => 10\n */\nexport function applyNumericPrecision(\n value: number | undefined,\n precision?: number\n): number | undefined {\n if (value === undefined || precision === undefined) return value;\n return parseFloat(value.toFixed(precision));\n}\n\n/**\n * Format a number with thousand separators.\n * \n * @param value - The number to format\n * @param separator - Separator character (default: ',')\n * @returns Formatted string or empty string if value is undefined/NaN\n * \n * @example\n * formatNumberWithSeparator(1234567.89) // => '1,234,567.89'\n * formatNumberWithSeparator(1234567, ' ') // => '1 234 567'\n */\nexport function formatNumberWithSeparator(\n value: number | undefined,\n separator: string = ','\n): string {\n if (value === undefined || value === null || isNaN(value)) return '';\n const [intPart, decPart] = value.toString().split('.');\n const formattedInt = intPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\n return decPart !== undefined ? `${formattedInt}.${decPart}` : formattedInt;\n}\n\n/**\n * Parse a formatted number string back to a number.\n * \n * @param str - Formatted string with separators\n * @param separator - Separator character to remove\n * @returns Parsed number or undefined if invalid\n * \n * @example\n * parseFormattedNumber('1,234,567.89') // => 1234567.89\n * parseFormattedNumber('1 234 567', ' ') // => 1234567\n */\nexport function parseFormattedNumber(\n str: string,\n separator: string = ','\n): number | undefined {\n if (!str || str === '') return undefined;\n const cleaned = str.split(separator).join('');\n const num = parseFloat(cleaned);\n return isNaN(num) ? undefined : num;\n}\n\n// =============================================================================\n// DATE UTILITIES\n// Helpers for date field operations.\n// =============================================================================\n\n/**\n * Safely parse a value to a Date object.\n * Handles Date objects, ISO strings, and timestamps.\n * \n * @param value - Value to parse (Date, string, number, or unknown)\n * @returns Date object or undefined if invalid\n * \n * @example\n * parseToDate(new Date()) // => Date\n * parseToDate('2024-01-15') // => Date\n * parseToDate(null) // => undefined\n */\nexport function parseToDate(value: unknown): Date | undefined {\n if (!value) return undefined;\n if (value instanceof Date) {\n return isNaN(value.getTime()) ? undefined : value;\n }\n if (typeof value === 'number') {\n const date = new Date(value);\n return isNaN(date.getTime()) ? undefined : date;\n }\n if (typeof value === 'string') {\n const date = new Date(value);\n return isNaN(date.getTime()) ? undefined : date;\n }\n return undefined;\n}\n","import type { OutputConfig } from \"../types\";\n\n/**\n * Transform form data into the configured output shape.\n *\n * NOTE: The input data (typically from RHF with GroupField) is already nested.\n * - 'flat' / 'nested' → pass through as-is (already nested)\n * - 'path' → flatten nested object into path-delimited keys\n */\nexport function transformFormOutput<TData>(\n data: TData,\n config?: OutputConfig,\n): TData {\n if (!config || config.type !== \"path\") {\n return data;\n }\n\n if (typeof data !== \"object\" || data === null) {\n return data;\n }\n\n return flattenToPathKeys(\n data as Record<string, unknown>,\n config.delimiter ?? \".\",\n ) as TData;\n}\n\n/**\n * Flatten a nested object into single-level keys using a delimiter.\n * Leaf values (primitives, arrays, Date, File, etc.) are NOT traversed.\n */\nfunction flattenToPathKeys(\n data: Record<string, unknown>,\n delimiter: string,\n prefix = \"\",\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(data)) {\n const path = prefix ? `${prefix}${delimiter}${key}` : key;\n\n if (isPlainObject(value)) {\n Object.assign(\n result,\n flattenToPathKeys(value as Record<string, unknown>, delimiter, path),\n );\n } else {\n result[path] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Check if a value is a plain object.\n */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null) return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAUhB,SAAS,mBACZ,UACA,UACY;AACZ,QAAM,YAAY,CAAC,SAA4B;AAC3C,UAAM,QAAQ,SAAS,IAAI;AAC3B,WAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACH,QAAQ,CAAc,SAA4C;AAC9D,YAAM,MAAM,UAAU,IAAI;AAC1B,aAAO,IAAI,IAAI,CAAC,MAAM,UAAU;AAC5B,cAAM,aACF,OAAO,SAAS,YAAY,SAAS,OAC9B,OACA,EAAE,OAAO,KAAK;AAEzB,eAAO;AAAA,UACH,IAAK,WAAW,MAAiB,GAAG,IAAI,IAAI,KAAK;AAAA,UACjD,GAAI;AAAA,QACR;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IAEA,QAAQ,CAAC,MAAc,UAAmB;AACtC,YAAM,UAAU,UAAU,IAAI;AAC9B,YAAM,aAAa,SAAS,KAAK;AACjC,eAAS,MAAM,CAAC,GAAG,SAAS,UAAU,CAAC;AAAA,IAC3C;AAAA,IAEA,SAAS,CAAC,MAAc,UAAmB;AACvC,YAAM,UAAU,UAAU,IAAI;AAC9B,YAAM,aAAa,SAAS,KAAK;AACjC,eAAS,MAAM,CAAC,YAA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AAM,OAAO,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,GAAG,KAAK;AAEtD,QAAI,cAAc,KAAK,GAAG;AACxB,aAAO;AAAA,QACL;AAAA,QACA,kBAAkB,OAAkC,WAAW,IAAI;AAAA,MACrE;AAAA,IACF,OAAO;AACL,aAAO,IAAI,IAAI;AAAA,IACjB;AAAA,EACF;AAEA,SAAO;AACT;AAKA,SAAS,cAAc,OAAkD;AACvE,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as Field, a as FormConfig, U as UseFormOptions, b as FormAdapter } from './adapter-
|
|
2
|
-
export { g as AdapterFactory, f as AdapterOptions, z as ArrayField, A as ArrayHelpers, B as BaseField,
|
|
3
|
-
export { F as FieldToZod, a as FieldsToShape, c as InferSchema, I as InferType, S as SchemaBuilder, b as SchemaBuilderMap, h as coerceToDate, g as coerceToNumber, l as createArrayHelpers, d as createSchema, e as extractValidationConfig, f as fieldsToZodSchema, p as formatBytes, n as generateFieldId, o as getNestedValue, i as getPatternErrorMessage, j as isFileLike, k as isFileTypeAccepted, m as makeOptional, s as setNestedValue } from './utils-
|
|
1
|
+
import { F as Field, O as OutputConfig, a as FormConfig, U as UseFormOptions, b as FormAdapter } from './adapter-Bd0fYuAE.mjs';
|
|
2
|
+
export { g as AdapterFactory, f as AdapterOptions, z as ArrayField, A as ArrayHelpers, B as BaseField, W as BuzzFormSchema, t as CheckboxField, s as CheckboxGroupField, K as CollapsibleField, C as ConditionContext, M as DataField, D as DateField, p as DatetimeField, E as EmailField, k as FieldComponentProps, j as FieldCondition, d as FieldError, l as FieldInputProps, m as FieldInputRenderFn, n as FieldStyle, L as FieldType, X as FormSettings, c as FormState, G as GroupField, Q as LayoutField, N as NumberField, Y as OutputType, P as PasswordField, Z as PathDelimiter, w as RadioField, e as Resolver, R as ResolverResult, H as RowField, r as SelectField, q as SelectOption, S as SetValueOptions, u as SwitchField, I as Tab, J as TabsField, x as TagsField, T as TextField, o as TextareaField, y as UploadField, V as ValidationContext, i as ValidationFn, h as ValidationResult, v as validateAdapter } from './adapter-Bd0fYuAE.mjs';
|
|
3
|
+
export { F as FieldToZod, a as FieldsToShape, c as InferSchema, I as InferType, S as SchemaBuilder, b as SchemaBuilderMap, h as coerceToDate, g as coerceToNumber, l as createArrayHelpers, d as createSchema, e as extractValidationConfig, f as fieldsToZodSchema, p as formatBytes, n as generateFieldId, o as getNestedValue, i as getPatternErrorMessage, j as isFileLike, k as isFileTypeAccepted, m as makeOptional, s as setNestedValue } from './utils-BsX0viz8.mjs';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { ReactNode } from 'react';
|
|
6
6
|
import 'zod';
|
|
@@ -212,6 +212,15 @@ declare function parseFormattedNumber(str: string, separator?: string): number |
|
|
|
212
212
|
*/
|
|
213
213
|
declare function parseToDate(value: unknown): Date | undefined;
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Transform form data into the configured output shape.
|
|
217
|
+
*
|
|
218
|
+
* NOTE: The input data (typically from RHF with GroupField) is already nested.
|
|
219
|
+
* - 'flat' / 'nested' → pass through as-is (already nested)
|
|
220
|
+
* - 'path' → flatten nested object into path-delimited keys
|
|
221
|
+
*/
|
|
222
|
+
declare function transformFormOutput<TData>(data: TData, config?: OutputConfig): TData;
|
|
223
|
+
|
|
215
224
|
/**
|
|
216
225
|
* Provider for global form configuration.
|
|
217
226
|
* Set the adapter, resolver, and default mode for all forms in the app.
|
|
@@ -267,4 +276,4 @@ declare const FormConfigContext: React.Context<FormConfig | null>;
|
|
|
267
276
|
*/
|
|
268
277
|
declare function useForm<TData extends Record<string, unknown> = Record<string, unknown>>(options: UseFormOptions<TData>): FormAdapter<TData>;
|
|
269
278
|
|
|
270
|
-
export { Field, FormAdapter, FormConfig, FormConfigContext, FormProvider, UseFormOptions, applyNumericPrecision, clampNumber, countNestedErrors, formatNumberWithSeparator, getArrayRowLabel, getFieldWidthStyle, getNestedFieldPaths, getSelectOptionLabel, getSelectOptionLabelString, getSelectOptionValue, isSelectOptionDisabled, normalizeSelectOption, parseFormattedNumber, parseToDate, resolveFieldState, useForm };
|
|
279
|
+
export { Field, FormAdapter, FormConfig, FormConfigContext, FormProvider, OutputConfig, UseFormOptions, applyNumericPrecision, clampNumber, countNestedErrors, formatNumberWithSeparator, getArrayRowLabel, getFieldWidthStyle, getNestedFieldPaths, getSelectOptionLabel, getSelectOptionLabelString, getSelectOptionValue, isSelectOptionDisabled, normalizeSelectOption, parseFormattedNumber, parseToDate, resolveFieldState, transformFormOutput, useForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as Field, a as FormConfig, U as UseFormOptions, b as FormAdapter } from './adapter-
|
|
2
|
-
export { g as AdapterFactory, f as AdapterOptions, z as ArrayField, A as ArrayHelpers, B as BaseField,
|
|
3
|
-
export { F as FieldToZod, a as FieldsToShape, c as InferSchema, I as InferType, S as SchemaBuilder, b as SchemaBuilderMap, h as coerceToDate, g as coerceToNumber, l as createArrayHelpers, d as createSchema, e as extractValidationConfig, f as fieldsToZodSchema, p as formatBytes, n as generateFieldId, o as getNestedValue, i as getPatternErrorMessage, j as isFileLike, k as isFileTypeAccepted, m as makeOptional, s as setNestedValue } from './utils-
|
|
1
|
+
import { F as Field, O as OutputConfig, a as FormConfig, U as UseFormOptions, b as FormAdapter } from './adapter-Bd0fYuAE.js';
|
|
2
|
+
export { g as AdapterFactory, f as AdapterOptions, z as ArrayField, A as ArrayHelpers, B as BaseField, W as BuzzFormSchema, t as CheckboxField, s as CheckboxGroupField, K as CollapsibleField, C as ConditionContext, M as DataField, D as DateField, p as DatetimeField, E as EmailField, k as FieldComponentProps, j as FieldCondition, d as FieldError, l as FieldInputProps, m as FieldInputRenderFn, n as FieldStyle, L as FieldType, X as FormSettings, c as FormState, G as GroupField, Q as LayoutField, N as NumberField, Y as OutputType, P as PasswordField, Z as PathDelimiter, w as RadioField, e as Resolver, R as ResolverResult, H as RowField, r as SelectField, q as SelectOption, S as SetValueOptions, u as SwitchField, I as Tab, J as TabsField, x as TagsField, T as TextField, o as TextareaField, y as UploadField, V as ValidationContext, i as ValidationFn, h as ValidationResult, v as validateAdapter } from './adapter-Bd0fYuAE.js';
|
|
3
|
+
export { F as FieldToZod, a as FieldsToShape, c as InferSchema, I as InferType, S as SchemaBuilder, b as SchemaBuilderMap, h as coerceToDate, g as coerceToNumber, l as createArrayHelpers, d as createSchema, e as extractValidationConfig, f as fieldsToZodSchema, p as formatBytes, n as generateFieldId, o as getNestedValue, i as getPatternErrorMessage, j as isFileLike, k as isFileTypeAccepted, m as makeOptional, s as setNestedValue } from './utils-DHF346op.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { ReactNode } from 'react';
|
|
6
6
|
import 'zod';
|
|
@@ -212,6 +212,15 @@ declare function parseFormattedNumber(str: string, separator?: string): number |
|
|
|
212
212
|
*/
|
|
213
213
|
declare function parseToDate(value: unknown): Date | undefined;
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Transform form data into the configured output shape.
|
|
217
|
+
*
|
|
218
|
+
* NOTE: The input data (typically from RHF with GroupField) is already nested.
|
|
219
|
+
* - 'flat' / 'nested' → pass through as-is (already nested)
|
|
220
|
+
* - 'path' → flatten nested object into path-delimited keys
|
|
221
|
+
*/
|
|
222
|
+
declare function transformFormOutput<TData>(data: TData, config?: OutputConfig): TData;
|
|
223
|
+
|
|
215
224
|
/**
|
|
216
225
|
* Provider for global form configuration.
|
|
217
226
|
* Set the adapter, resolver, and default mode for all forms in the app.
|
|
@@ -267,4 +276,4 @@ declare const FormConfigContext: React.Context<FormConfig | null>;
|
|
|
267
276
|
*/
|
|
268
277
|
declare function useForm<TData extends Record<string, unknown> = Record<string, unknown>>(options: UseFormOptions<TData>): FormAdapter<TData>;
|
|
269
278
|
|
|
270
|
-
export { Field, FormAdapter, FormConfig, FormConfigContext, FormProvider, UseFormOptions, applyNumericPrecision, clampNumber, countNestedErrors, formatNumberWithSeparator, getArrayRowLabel, getFieldWidthStyle, getNestedFieldPaths, getSelectOptionLabel, getSelectOptionLabelString, getSelectOptionValue, isSelectOptionDisabled, normalizeSelectOption, parseFormattedNumber, parseToDate, resolveFieldState, useForm };
|
|
279
|
+
export { Field, FormAdapter, FormConfig, FormConfigContext, FormProvider, OutputConfig, UseFormOptions, applyNumericPrecision, clampNumber, countNestedErrors, formatNumberWithSeparator, getArrayRowLabel, getFieldWidthStyle, getNestedFieldPaths, getSelectOptionLabel, getSelectOptionLabelString, getSelectOptionValue, isSelectOptionDisabled, normalizeSelectOption, parseFormattedNumber, parseToDate, resolveFieldState, transformFormOutput, useForm };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
parseToDate: () => parseToDate,
|
|
52
52
|
resolveFieldState: () => resolveFieldState,
|
|
53
53
|
setNestedValue: () => setNestedValue,
|
|
54
|
+
transformFormOutput: () => transformFormOutput,
|
|
54
55
|
useForm: () => useForm,
|
|
55
56
|
validateAdapter: () => validateAdapter
|
|
56
57
|
});
|
|
@@ -884,6 +885,40 @@ function parseToDate(value) {
|
|
|
884
885
|
return void 0;
|
|
885
886
|
}
|
|
886
887
|
|
|
888
|
+
// src/lib/output.ts
|
|
889
|
+
function transformFormOutput(data, config) {
|
|
890
|
+
if (!config || config.type !== "path") {
|
|
891
|
+
return data;
|
|
892
|
+
}
|
|
893
|
+
if (typeof data !== "object" || data === null) {
|
|
894
|
+
return data;
|
|
895
|
+
}
|
|
896
|
+
return flattenToPathKeys(
|
|
897
|
+
data,
|
|
898
|
+
config.delimiter ?? "."
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
function flattenToPathKeys(data, delimiter, prefix = "") {
|
|
902
|
+
const result = {};
|
|
903
|
+
for (const [key, value] of Object.entries(data)) {
|
|
904
|
+
const path = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
905
|
+
if (isPlainObject(value)) {
|
|
906
|
+
Object.assign(
|
|
907
|
+
result,
|
|
908
|
+
flattenToPathKeys(value, delimiter, path)
|
|
909
|
+
);
|
|
910
|
+
} else {
|
|
911
|
+
result[path] = value;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return result;
|
|
915
|
+
}
|
|
916
|
+
function isPlainObject(value) {
|
|
917
|
+
if (typeof value !== "object" || value === null) return false;
|
|
918
|
+
const proto = Object.getPrototypeOf(value);
|
|
919
|
+
return proto === Object.prototype || proto === null;
|
|
920
|
+
}
|
|
921
|
+
|
|
887
922
|
// src/context/form-context.ts
|
|
888
923
|
var import_react = require("react");
|
|
889
924
|
var FormConfigContext = (0, import_react.createContext)(null);
|
|
@@ -915,9 +950,9 @@ function extractDefaultsFromFields(fields) {
|
|
|
915
950
|
}
|
|
916
951
|
return hasDefaults ? defaults : void 0;
|
|
917
952
|
}
|
|
918
|
-
function applySettings(form, settings) {
|
|
919
|
-
if (!settings) return form;
|
|
920
|
-
if (settings
|
|
953
|
+
function applySettings(form, settings, outputConfig) {
|
|
954
|
+
if (!settings && !outputConfig) return form;
|
|
955
|
+
if (settings?.submitOnlyWhenDirty) {
|
|
921
956
|
const originalHandleSubmit = form.handleSubmit;
|
|
922
957
|
form.handleSubmit = (e) => {
|
|
923
958
|
if (!form.formState.isDirty) {
|
|
@@ -930,6 +965,21 @@ function applySettings(form, settings) {
|
|
|
930
965
|
if (settings) {
|
|
931
966
|
form.settings = settings;
|
|
932
967
|
}
|
|
968
|
+
if (outputConfig?.type === "path") {
|
|
969
|
+
const originalGetValues = form.getValues;
|
|
970
|
+
form.getValues = () => {
|
|
971
|
+
const values = originalGetValues();
|
|
972
|
+
return transformFormOutput(values, outputConfig);
|
|
973
|
+
};
|
|
974
|
+
const originalWatch = form.watch;
|
|
975
|
+
form.watch = (name) => {
|
|
976
|
+
const values = originalWatch(name);
|
|
977
|
+
if (!name) {
|
|
978
|
+
return transformFormOutput(values, outputConfig);
|
|
979
|
+
}
|
|
980
|
+
return values;
|
|
981
|
+
};
|
|
982
|
+
}
|
|
933
983
|
return form;
|
|
934
984
|
}
|
|
935
985
|
function useForm(options) {
|
|
@@ -938,6 +988,7 @@ function useForm(options) {
|
|
|
938
988
|
const resolverFn = globalConfig?.resolver;
|
|
939
989
|
const mode = options.mode ?? globalConfig?.mode ?? "onChange";
|
|
940
990
|
const reValidateMode = options.reValidateMode ?? globalConfig?.reValidateMode ?? "onChange";
|
|
991
|
+
const outputConfig = options.output ?? globalConfig?.output;
|
|
941
992
|
const resolver = options.schema && resolverFn ? resolverFn(options.schema) : void 0;
|
|
942
993
|
const schemaWithFields = options.schema;
|
|
943
994
|
const fieldDefaults = (0, import_react2.useMemo)(
|
|
@@ -945,6 +996,11 @@ function useForm(options) {
|
|
|
945
996
|
[schemaWithFields?.fields]
|
|
946
997
|
);
|
|
947
998
|
const defaultValues = options.defaultValues ?? fieldDefaults;
|
|
999
|
+
const userOnSubmit = options.onSubmit;
|
|
1000
|
+
const wrappedOnSubmit = userOnSubmit && outputConfig?.type === "path" ? (data) => {
|
|
1001
|
+
const transformed = transformFormOutput(data, outputConfig);
|
|
1002
|
+
return userOnSubmit(transformed);
|
|
1003
|
+
} : userOnSubmit;
|
|
948
1004
|
const effectiveAdapter = adapter ?? ((_opts) => {
|
|
949
1005
|
throw new Error("useForm: No adapter configured.");
|
|
950
1006
|
});
|
|
@@ -953,7 +1009,7 @@ function useForm(options) {
|
|
|
953
1009
|
resolver,
|
|
954
1010
|
mode,
|
|
955
1011
|
reValidateMode,
|
|
956
|
-
onSubmit:
|
|
1012
|
+
onSubmit: wrappedOnSubmit
|
|
957
1013
|
});
|
|
958
1014
|
if (!options.schema) {
|
|
959
1015
|
throw new Error(
|
|
@@ -965,7 +1021,7 @@ function useForm(options) {
|
|
|
965
1021
|
"useForm: No adapter configured. Either wrap your app in <FormProvider adapter={...}> or pass adapter in options."
|
|
966
1022
|
);
|
|
967
1023
|
}
|
|
968
|
-
return applySettings(form, options.settings);
|
|
1024
|
+
return applySettings(form, options.settings, outputConfig);
|
|
969
1025
|
}
|
|
970
1026
|
// Annotate the CommonJS export names for ESM import in node:
|
|
971
1027
|
0 && (module.exports = {
|
|
@@ -1000,6 +1056,7 @@ function useForm(options) {
|
|
|
1000
1056
|
parseToDate,
|
|
1001
1057
|
resolveFieldState,
|
|
1002
1058
|
setNestedValue,
|
|
1059
|
+
transformFormOutput,
|
|
1003
1060
|
useForm,
|
|
1004
1061
|
validateAdapter
|
|
1005
1062
|
});
|