@buildnbuzz/buzzform 0.1.0

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.
@@ -0,0 +1,273 @@
1
+ // src/utils/array.ts
2
+ import { nanoid } from "nanoid";
3
+ function createArrayHelpers(getArray, setArray) {
4
+ return {
5
+ fields: (path) => {
6
+ const arr = getArray(path);
7
+ if (!Array.isArray(arr)) return [];
8
+ return arr.map((item, index) => ({
9
+ id: item?.id || `${path}-${index}`,
10
+ ...item
11
+ }));
12
+ },
13
+ append: (path, value) => {
14
+ const current = getArray(path) || [];
15
+ const itemWithId = ensureId(value);
16
+ setArray(path, [...current, itemWithId]);
17
+ },
18
+ prepend: (path, value) => {
19
+ const current = getArray(path) || [];
20
+ const itemWithId = ensureId(value);
21
+ setArray(path, [itemWithId, ...current]);
22
+ },
23
+ insert: (path, index, value) => {
24
+ const current = [...getArray(path) || []];
25
+ const itemWithId = ensureId(value);
26
+ current.splice(index, 0, itemWithId);
27
+ setArray(path, current);
28
+ },
29
+ remove: (path, index) => {
30
+ const current = [...getArray(path) || []];
31
+ current.splice(index, 1);
32
+ setArray(path, current);
33
+ },
34
+ move: (path, from, to) => {
35
+ const current = [...getArray(path) || []];
36
+ const [item] = current.splice(from, 1);
37
+ current.splice(to, 0, item);
38
+ setArray(path, current);
39
+ },
40
+ swap: (path, indexA, indexB) => {
41
+ const current = [...getArray(path) || []];
42
+ const temp = current[indexA];
43
+ current[indexA] = current[indexB];
44
+ current[indexB] = temp;
45
+ setArray(path, current);
46
+ },
47
+ replace: (path, values) => {
48
+ const itemsWithIds = values.map(ensureId);
49
+ setArray(path, itemsWithIds);
50
+ },
51
+ update: (path, index, value) => {
52
+ const current = [...getArray(path) || []];
53
+ const existingId = current[index]?.id;
54
+ current[index] = {
55
+ ...typeof value === "object" && value !== null ? value : {},
56
+ id: existingId || nanoid()
57
+ };
58
+ setArray(path, current);
59
+ }
60
+ };
61
+ }
62
+ function ensureId(value) {
63
+ if (typeof value === "object" && value !== null) {
64
+ const obj = value;
65
+ if (!obj.id) {
66
+ return { ...obj, id: nanoid() };
67
+ }
68
+ return obj;
69
+ }
70
+ return { value, id: nanoid() };
71
+ }
72
+
73
+ // src/lib/utils.ts
74
+ function generateFieldId(path) {
75
+ return `field-${path.replace(/\./g, "-").replace(/\[/g, "-").replace(/\]/g, "")}`;
76
+ }
77
+ function getNestedValue(obj, path) {
78
+ if (!obj || !path) return void 0;
79
+ return path.split(".").reduce((acc, key) => {
80
+ if (acc && typeof acc === "object" && acc !== null) {
81
+ return acc[key];
82
+ }
83
+ return void 0;
84
+ }, obj);
85
+ }
86
+ function setNestedValue(obj, path, value) {
87
+ const keys = path.split(".");
88
+ const result = { ...obj };
89
+ let current = result;
90
+ for (let i = 0; i < keys.length - 1; i++) {
91
+ const key = keys[i];
92
+ if (!(key in current) || typeof current[key] !== "object") {
93
+ const nextKey = keys[i + 1];
94
+ current[key] = /^\d+$/.test(nextKey) ? [] : {};
95
+ } else {
96
+ current[key] = Array.isArray(current[key]) ? [...current[key]] : { ...current[key] };
97
+ }
98
+ current = current[key];
99
+ }
100
+ current[keys[keys.length - 1]] = value;
101
+ return result;
102
+ }
103
+ function formatBytes(bytes, decimals = 2) {
104
+ if (bytes === 0) return "0 Bytes";
105
+ const k = 1024;
106
+ const dm = decimals < 0 ? 0 : decimals;
107
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
108
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
109
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
110
+ }
111
+ function flattenNestedObject(obj, prefix = "") {
112
+ const result = {};
113
+ for (const key in obj) {
114
+ const path = prefix ? `${prefix}.${key}` : key;
115
+ const value = obj[key];
116
+ if (typeof value === "boolean") {
117
+ result[path] = value;
118
+ } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
119
+ Object.assign(result, flattenNestedObject(value, path));
120
+ }
121
+ }
122
+ return result;
123
+ }
124
+
125
+ // src/lib/field.ts
126
+ function getNestedFieldPaths(fields, basePath) {
127
+ const paths = [];
128
+ for (const field of fields) {
129
+ if ("name" in field && field.name) {
130
+ const fieldPath = basePath ? `${basePath}.${field.name}` : field.name;
131
+ paths.push(fieldPath);
132
+ if (field.type === "group" && "fields" in field) {
133
+ paths.push(...getNestedFieldPaths(field.fields, fieldPath));
134
+ }
135
+ if (field.type === "array" && "fields" in field) {
136
+ paths.push(...getNestedFieldPaths(field.fields, fieldPath));
137
+ }
138
+ }
139
+ if ("fields" in field && field.type !== "group" && field.type !== "array") {
140
+ const layoutField = field;
141
+ paths.push(...getNestedFieldPaths(layoutField.fields, basePath));
142
+ }
143
+ if (field.type === "tabs" && "tabs" in field) {
144
+ for (const tab of field.tabs) {
145
+ const tabPath = tab.name ? basePath ? `${basePath}.${tab.name}` : tab.name : basePath;
146
+ paths.push(...getNestedFieldPaths(tab.fields, tabPath));
147
+ }
148
+ }
149
+ }
150
+ return paths;
151
+ }
152
+ function countNestedErrors(errors, fields, basePath) {
153
+ const paths = getNestedFieldPaths(fields, basePath);
154
+ return paths.filter((path) => errors[path]).length;
155
+ }
156
+ function resolveFieldState(value, formData, siblingData = formData) {
157
+ if (typeof value === "function") {
158
+ return value(formData, siblingData);
159
+ }
160
+ return Boolean(value);
161
+ }
162
+ function getArrayRowLabel(rowData, fields, uiOptions, fallbackLabel) {
163
+ if (uiOptions?.rowLabelField && rowData?.[uiOptions.rowLabelField]) {
164
+ return String(rowData[uiOptions.rowLabelField]);
165
+ }
166
+ const firstNamedField = fields.find((f) => "name" in f && f.name);
167
+ if (firstNamedField && "name" in firstNamedField) {
168
+ const value = rowData?.[firstNamedField.name];
169
+ if (value) {
170
+ return String(value);
171
+ }
172
+ }
173
+ return fallbackLabel;
174
+ }
175
+ function getFieldWidthStyle(style) {
176
+ if (!style?.width) return void 0;
177
+ return {
178
+ width: typeof style.width === "number" ? `${style.width}px` : style.width
179
+ };
180
+ }
181
+ function normalizeSelectOption(option) {
182
+ if (typeof option === "string") {
183
+ return { value: option, label: option };
184
+ }
185
+ return {
186
+ value: option.value,
187
+ label: option.label ?? String(option.value),
188
+ description: option.description,
189
+ icon: option.icon,
190
+ disabled: option.disabled
191
+ };
192
+ }
193
+ function getSelectOptionValue(option) {
194
+ if (typeof option === "string") return option;
195
+ const val = option.value;
196
+ if (typeof val === "boolean") return val ? "true" : "false";
197
+ return String(val);
198
+ }
199
+ function getSelectOptionLabel(option) {
200
+ if (typeof option === "string") return option;
201
+ return option.label ?? String(option.value);
202
+ }
203
+ function getSelectOptionLabelString(option) {
204
+ if (typeof option === "string") return option;
205
+ if (typeof option.label === "string") return option.label;
206
+ return String(option.value);
207
+ }
208
+ function isSelectOptionDisabled(option) {
209
+ if (typeof option === "string") return false;
210
+ return option.disabled === true;
211
+ }
212
+ function clampNumber(value, min, max) {
213
+ let result = value;
214
+ if (min !== void 0 && result < min) result = min;
215
+ if (max !== void 0 && result > max) result = max;
216
+ return result;
217
+ }
218
+ function applyNumericPrecision(value, precision) {
219
+ if (value === void 0 || precision === void 0) return value;
220
+ return parseFloat(value.toFixed(precision));
221
+ }
222
+ function formatNumberWithSeparator(value, separator = ",") {
223
+ if (value === void 0 || value === null || isNaN(value)) return "";
224
+ const [intPart, decPart] = value.toString().split(".");
225
+ const formattedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
226
+ return decPart !== void 0 ? `${formattedInt}.${decPart}` : formattedInt;
227
+ }
228
+ function parseFormattedNumber(str, separator = ",") {
229
+ if (!str || str === "") return void 0;
230
+ const cleaned = str.split(separator).join("");
231
+ const num = parseFloat(cleaned);
232
+ return isNaN(num) ? void 0 : num;
233
+ }
234
+ function parseToDate(value) {
235
+ if (!value) return void 0;
236
+ if (value instanceof Date) {
237
+ return isNaN(value.getTime()) ? void 0 : value;
238
+ }
239
+ if (typeof value === "number") {
240
+ const date = new Date(value);
241
+ return isNaN(date.getTime()) ? void 0 : date;
242
+ }
243
+ if (typeof value === "string") {
244
+ const date = new Date(value);
245
+ return isNaN(date.getTime()) ? void 0 : date;
246
+ }
247
+ return void 0;
248
+ }
249
+
250
+ export {
251
+ createArrayHelpers,
252
+ generateFieldId,
253
+ getNestedValue,
254
+ setNestedValue,
255
+ formatBytes,
256
+ flattenNestedObject,
257
+ getNestedFieldPaths,
258
+ countNestedErrors,
259
+ resolveFieldState,
260
+ getArrayRowLabel,
261
+ getFieldWidthStyle,
262
+ normalizeSelectOption,
263
+ getSelectOptionValue,
264
+ getSelectOptionLabel,
265
+ getSelectOptionLabelString,
266
+ isSelectOptionDisabled,
267
+ clampNumber,
268
+ applyNumericPrecision,
269
+ formatNumberWithSeparator,
270
+ parseFormattedNumber,
271
+ parseToDate
272
+ };
273
+ //# sourceMappingURL=chunk-DDDGBPVU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/array.ts","../src/lib/utils.ts","../src/lib/field.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\r\nimport type { ArrayHelpers } from '../types';\r\n\r\n/**\r\n * Creates a standardized set of array field manipulation methods.\r\n * Abstracts the difference between getting/setting values in different form libraries.\r\n * \r\n * @param getArray - Function to get current array value at a path\r\n * @param setArray - Function to set array value at a path\r\n */\r\nexport function createArrayHelpers(\r\n getArray: (path: string) => unknown[],\r\n setArray: (path: string, value: unknown[]) => void\r\n): ArrayHelpers {\r\n return {\r\n fields: <T = unknown>(path: string): Array<T & { id: string }> => {\r\n const arr = getArray(path);\r\n if (!Array.isArray(arr)) return [];\r\n return arr.map((item, index) => ({\r\n id: (item as Record<string, unknown>)?.id as string || `${path}-${index}`,\r\n ...item as T,\r\n }));\r\n },\r\n\r\n append: (path: string, value: unknown) => {\r\n const current = getArray(path) || [];\r\n const itemWithId = ensureId(value);\r\n setArray(path, [...current, itemWithId]);\r\n },\r\n\r\n prepend: (path: string, value: unknown) => {\r\n const current = getArray(path) || [];\r\n const itemWithId = ensureId(value);\r\n setArray(path, [itemWithId, ...current]);\r\n },\r\n\r\n insert: (path: string, index: number, value: unknown) => {\r\n const current = [...(getArray(path) || [])];\r\n const itemWithId = ensureId(value);\r\n current.splice(index, 0, itemWithId);\r\n setArray(path, current);\r\n },\r\n\r\n remove: (path: string, index: number) => {\r\n const current = [...(getArray(path) || [])];\r\n current.splice(index, 1);\r\n setArray(path, current);\r\n },\r\n\r\n move: (path: string, from: number, to: number) => {\r\n const current = [...(getArray(path) || [])];\r\n const [item] = current.splice(from, 1);\r\n current.splice(to, 0, item);\r\n setArray(path, current);\r\n },\r\n\r\n swap: (path: string, indexA: number, indexB: number) => {\r\n const current = [...(getArray(path) || [])];\r\n const temp = current[indexA];\r\n current[indexA] = current[indexB];\r\n current[indexB] = temp;\r\n setArray(path, current);\r\n },\r\n\r\n replace: (path: string, values: unknown[]) => {\r\n const itemsWithIds = values.map(ensureId);\r\n setArray(path, itemsWithIds);\r\n },\r\n\r\n update: (path: string, index: number, value: unknown) => {\r\n const current = [...(getArray(path) || [])];\r\n // Preserve existing ID if present\r\n const existingId = (current[index] as Record<string, unknown>)?.id;\r\n current[index] = {\r\n ...(typeof value === 'object' && value !== null ? value : {}),\r\n id: existingId || nanoid(),\r\n };\r\n setArray(path, current);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Ensures an item has a unique ID for React keys.\r\n */\r\nfunction ensureId(value: unknown): unknown {\r\n if (typeof value === 'object' && value !== null) {\r\n const obj = value as Record<string, unknown>;\r\n if (!obj.id) {\r\n return { ...obj, id: nanoid() };\r\n }\r\n return obj;\r\n }\r\n return { value, id: nanoid() };\r\n}\r\n","// =============================================================================\r\n// COMMON UTILITIES\r\n// These are used by both the core package and registry field components.\r\n// =============================================================================\r\n\r\n/**\r\n * Generate a unique field ID from the field path.\r\n * Converts dot notation to dashes and prefixes with 'field-'.\r\n * Used for accessibility (htmlFor, id attributes).\r\n * \r\n * @example\r\n * generateFieldId('user.profile.email') => 'field-user-profile-email'\r\n * generateFieldId('items[0].name') => 'field-items-0-name'\r\n */\r\nexport function generateFieldId(path: string): string {\r\n return `field-${path.replace(/\\./g, \"-\").replace(/\\[/g, \"-\").replace(/\\]/g, \"\")}`;\r\n}\r\n\r\n/**\r\n * Safely retrieve a nested value from an object using a dot-notation path.\r\n * \r\n * @example\r\n * getNestedValue({ user: { name: 'John' } }, 'user.name') => 'John'\r\n * getNestedValue({ items: [{ id: 1 }] }, 'items.0.id') => 1\r\n */\r\nexport function getNestedValue(obj: unknown, path: string): unknown {\r\n if (!obj || !path) return undefined;\r\n return path.split(\".\").reduce<unknown>((acc: unknown, key: string) => {\r\n if (acc && typeof acc === \"object\" && acc !== null) {\r\n return (acc as Record<string, unknown>)[key];\r\n }\r\n return undefined;\r\n }, obj);\r\n}\r\n\r\n/**\r\n * Set a nested value in an object using a dot-notation path.\r\n * Creates intermediate objects/arrays as needed.\r\n * \r\n * @example\r\n * setNestedValue({}, 'user.name', 'John') => { user: { name: 'John' } }\r\n */\r\nexport function setNestedValue<T extends Record<string, unknown>>(\r\n obj: T,\r\n path: string,\r\n value: unknown\r\n): T {\r\n const keys = path.split(\".\");\r\n const result = { ...obj } as Record<string, unknown>;\r\n let current = result;\r\n\r\n for (let i = 0; i < keys.length - 1; i++) {\r\n const key = keys[i];\r\n if (!(key in current) || typeof current[key] !== \"object\") {\r\n // Check if next key is numeric (array index)\r\n const nextKey = keys[i + 1];\r\n current[key] = /^\\d+$/.test(nextKey) ? [] : {};\r\n } else {\r\n current[key] = Array.isArray(current[key])\r\n ? [...(current[key] as unknown[])]\r\n : { ...(current[key] as Record<string, unknown>) };\r\n }\r\n current = current[key] as Record<string, unknown>;\r\n }\r\n\r\n current[keys[keys.length - 1]] = value;\r\n return result as T;\r\n}\r\n\r\n/**\r\n * Format bytes into a human-readable string.\r\n * \r\n * @example\r\n * formatBytes(1024) => '1 KB'\r\n * formatBytes(1234567) => '1.18 MB'\r\n */\r\nexport function formatBytes(bytes: number, decimals = 2): string {\r\n if (bytes === 0) return '0 Bytes';\r\n\r\n const k = 1024;\r\n const dm = decimals < 0 ? 0 : decimals;\r\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\r\n\r\n const i = Math.floor(Math.log(bytes) / Math.log(k));\r\n\r\n return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;\r\n}\r\n\r\n/**\r\n * Flatten a nested object to dot-notation paths.\r\n * Useful for converting form library state (like dirtyFields, touchedFields)\r\n * to the flat format expected by FormState.\r\n * \r\n * @example\r\n * flattenNestedObject({ user: { name: true, email: true } })\r\n * // => { 'user.name': true, 'user.email': true }\r\n * \r\n * flattenNestedObject({ items: { 0: { title: true } } })\r\n * // => { 'items.0.title': true }\r\n */\r\nexport function flattenNestedObject(\r\n obj: Record<string, unknown>,\r\n prefix = ''\r\n): Record<string, boolean> {\r\n const result: Record<string, boolean> = {};\r\n\r\n for (const key in obj) {\r\n const path = prefix ? `${prefix}.${key}` : key;\r\n const value = obj[key];\r\n\r\n if (typeof value === 'boolean') {\r\n result[path] = value;\r\n } else if (value !== null && typeof value === 'object' && !Array.isArray(value)) {\r\n Object.assign(result, flattenNestedObject(value as Record<string, unknown>, path));\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\n","import type { ReactNode } from 'react';\r\nimport type { Field } from '../types';\r\n\r\n// =============================================================================\r\n// FIELD PATH UTILITIES\r\n// These utilities help work with nested field definitions and form data.\r\n// =============================================================================\r\n\r\n/**\r\n * Recursively extracts all field paths from a field definition tree.\r\n * Handles nested groups, arrays, and layout fields (rows, tabs, collapsibles).\r\n * \r\n * @param fields - Array of field definitions\r\n * @param basePath - Base path prefix (e.g., \"contacts.0\" for array items)\r\n * @returns Array of all field paths\r\n * \r\n * @example\r\n * const fields = [\r\n * { type: 'text', name: 'name' },\r\n * { type: 'group', name: 'address', fields: [\r\n * { type: 'text', name: 'city' },\r\n * { type: 'text', name: 'zip' }\r\n * ]}\r\n * ];\r\n * getNestedFieldPaths(fields, 'contact')\r\n * // => ['contact.name', 'contact.address', 'contact.address.city', 'contact.address.zip']\r\n */\r\nexport function getNestedFieldPaths(fields: Field[], basePath: string): string[] {\r\n const paths: string[] = [];\r\n\r\n for (const field of fields) {\r\n // Data fields with names\r\n if ('name' in field && field.name) {\r\n const fieldPath = basePath ? `${basePath}.${field.name}` : field.name;\r\n paths.push(fieldPath);\r\n\r\n // Recurse into group/array fields\r\n if (field.type === 'group' && 'fields' in field) {\r\n paths.push(...getNestedFieldPaths(field.fields, fieldPath));\r\n }\r\n if (field.type === 'array' && 'fields' in field) {\r\n paths.push(...getNestedFieldPaths(field.fields, fieldPath));\r\n }\r\n }\r\n\r\n // Layout fields (row, tabs, collapsible) - pass through without adding to path\r\n if ('fields' in field && field.type !== 'group' && field.type !== 'array') {\r\n const layoutField = field as Field & { fields: Field[] };\r\n paths.push(...getNestedFieldPaths(layoutField.fields, basePath));\r\n }\r\n\r\n // Tabs field - iterate through tabs\r\n if (field.type === 'tabs' && 'tabs' in field) {\r\n for (const tab of field.tabs) {\r\n const tabPath = tab.name ? (basePath ? `${basePath}.${tab.name}` : tab.name) : basePath;\r\n paths.push(...getNestedFieldPaths(tab.fields, tabPath));\r\n }\r\n }\r\n }\r\n\r\n return paths;\r\n}\r\n\r\n/**\r\n * Count validation errors in nested fields.\r\n * Useful for showing error badges on collapsible sections, array rows, tabs, etc.\r\n * \r\n * @param errors - Form errors object from FormAdapter.formState.errors\r\n * @param fields - Field definitions to check\r\n * @param basePath - Base path for the fields\r\n * @returns Number of fields with errors\r\n * \r\n * @example\r\n * const errorCount = countNestedErrors(form.formState.errors, arrayField.fields, `items.0`);\r\n */\r\nexport function countNestedErrors(\r\n errors: Record<string, unknown>,\r\n fields: Field[],\r\n basePath: string\r\n): number {\r\n const paths = getNestedFieldPaths(fields, basePath);\r\n return paths.filter((path) => errors[path]).length;\r\n}\r\n\r\n/**\r\n * Resolve a potentially dynamic field property (disabled, readOnly, hidden).\r\n * These properties can be boolean or a function that receives form data.\r\n * \r\n * @param value - The property value (boolean or function)\r\n * @param formData - Current form data\r\n * @param siblingData - Data at the same level (for arrays, this is the row data)\r\n * @returns Resolved boolean value\r\n * \r\n * @example\r\n * const isDisabled = resolveFieldState(field.disabled, formData, siblingData);\r\n */\r\nexport function resolveFieldState<TData = Record<string, unknown>>(\r\n value: boolean | ((data: TData, siblingData: Record<string, unknown>) => boolean) | undefined,\r\n formData: TData,\r\n siblingData: Record<string, unknown> = formData as Record<string, unknown>\r\n): boolean {\r\n if (typeof value === 'function') {\r\n return value(formData, siblingData);\r\n }\r\n return Boolean(value);\r\n}\r\n\r\n/**\r\n * Get the label value for an array row based on field configuration.\r\n * First checks for a specific rowLabelField in ui options, then falls back\r\n * to the first named field's value.\r\n * \r\n * @param rowData - Data for the row\r\n * @param fields - Field definitions for the array\r\n * @param uiOptions - UI options that may contain rowLabelField\r\n * @param fallbackLabel - Default label if no value found\r\n * @returns Label string for the row\r\n * \r\n * @example\r\n * const label = getArrayRowLabel(rowData, field.fields, field.ui, `Item ${index + 1}`);\r\n */\r\nexport function getArrayRowLabel(\r\n rowData: Record<string, unknown> | undefined,\r\n fields: Field[],\r\n uiOptions: { rowLabelField?: string } | undefined,\r\n fallbackLabel: string\r\n): string {\r\n // First try explicit rowLabelField\r\n if (uiOptions?.rowLabelField && rowData?.[uiOptions.rowLabelField]) {\r\n return String(rowData[uiOptions.rowLabelField]);\r\n }\r\n\r\n // Fall back to first named field\r\n const firstNamedField = fields.find((f) => 'name' in f && f.name);\r\n if (firstNamedField && 'name' in firstNamedField) {\r\n const value = rowData?.[firstNamedField.name];\r\n if (value) {\r\n return String(value);\r\n }\r\n }\r\n\r\n return fallbackLabel;\r\n}\r\n\r\n// =============================================================================\r\n// FIELD STYLE UTILITIES\r\n// Helpers for computing field styling props.\r\n// =============================================================================\r\n\r\n/**\r\n * Compute the inline style object for a field's width.\r\n * Handles both numeric (px) and string (CSS) width values.\r\n * \r\n * @param style - Field style configuration\r\n * @returns CSS properties object or undefined if no width specified\r\n * \r\n * @example\r\n * <Field style={getFieldWidthStyle(field.style)}>\r\n * ...\r\n * </Field>\r\n */\r\nexport function getFieldWidthStyle(\r\n style: { width?: number | string } | undefined\r\n): { width: string } | undefined {\r\n if (!style?.width) return undefined;\r\n return {\r\n width: typeof style.width === 'number'\r\n ? `${style.width}px`\r\n : style.width,\r\n };\r\n}\r\n\r\n// =============================================================================\r\n// SELECT OPTION UTILITIES\r\n// Helpers for normalizing and extracting data from SelectOption | string.\r\n// =============================================================================\r\n\r\ntype SelectOptionLike = { value: string | number | boolean; label?: ReactNode; description?: ReactNode; icon?: ReactNode; disabled?: boolean } | string;\r\n\r\n/**\r\n * Normalize a select option to always be an object.\r\n * Converts string options to { value, label } objects.\r\n * \r\n * @param option - String or SelectOption object\r\n * @returns Normalized SelectOption object\r\n * \r\n * @example\r\n * normalizeSelectOption('foo') // => { value: 'foo', label: 'foo' }\r\n * normalizeSelectOption({ value: 'bar', label: 'Bar' }) // => { value: 'bar', label: 'Bar' }\r\n */\r\nexport function normalizeSelectOption(option: SelectOptionLike): {\r\n value: string | number | boolean;\r\n label: ReactNode;\r\n description?: ReactNode;\r\n icon?: ReactNode;\r\n disabled?: boolean;\r\n} {\r\n if (typeof option === 'string') {\r\n return { value: option, label: option };\r\n }\r\n return {\r\n value: option.value,\r\n label: option.label ?? String(option.value),\r\n description: option.description,\r\n icon: option.icon,\r\n disabled: option.disabled,\r\n };\r\n}\r\n\r\n/**\r\n * Get the value from a select option (handles string or object).\r\n * \r\n * @param option - String or SelectOption object\r\n * @returns The option's value as a string\r\n * \r\n * @example\r\n * getSelectOptionValue('foo') // => 'foo'\r\n * getSelectOptionValue({ value: 123, label: 'One Two Three' }) // => '123'\r\n */\r\nexport function getSelectOptionValue(option: SelectOptionLike): string {\r\n if (typeof option === 'string') return option;\r\n const val = option.value;\r\n if (typeof val === 'boolean') return val ? 'true' : 'false';\r\n return String(val);\r\n}\r\n\r\n/**\r\n * Get the label from a select option (handles string or object).\r\n * Returns ReactNode to support JSX labels.\r\n * \r\n * @param option - String or SelectOption object\r\n * @returns The option's label for display\r\n * \r\n * @example\r\n * getSelectOptionLabel('foo') // => 'foo'\r\n * getSelectOptionLabel({ value: 'bar', label: <strong>Bar</strong> }) // => <strong>Bar</strong>\r\n */\r\nexport function getSelectOptionLabel(option: SelectOptionLike): ReactNode {\r\n if (typeof option === 'string') return option;\r\n return option.label ?? String(option.value);\r\n}\r\n\r\n/**\r\n * Get the string label from a select option (for filtering/comparison).\r\n * Always returns a string, not ReactNode.\r\n * \r\n * @param option - String or SelectOption object\r\n * @returns The option's label as a string\r\n */\r\nexport function getSelectOptionLabelString(option: SelectOptionLike): string {\r\n if (typeof option === 'string') return option;\r\n if (typeof option.label === 'string') return option.label;\r\n return String(option.value);\r\n}\r\n\r\n/**\r\n * Check if a select option is disabled.\r\n * \r\n * @param option - String or SelectOption object\r\n * @returns true if option is disabled\r\n */\r\nexport function isSelectOptionDisabled(option: SelectOptionLike): boolean {\r\n if (typeof option === 'string') return false;\r\n return option.disabled === true;\r\n}\r\n\r\n// =============================================================================\r\n// NUMBER UTILITIES\r\n// Helpers for number field operations.\r\n// =============================================================================\r\n\r\n/**\r\n * Clamp a number between min and max bounds.\r\n * \r\n * @param value - The number to clamp\r\n * @param min - Minimum bound (optional)\r\n * @param max - Maximum bound (optional)\r\n * @returns Clamped number\r\n * \r\n * @example\r\n * clampNumber(5, 0, 10) // => 5\r\n * clampNumber(-5, 0, 10) // => 0\r\n * clampNumber(15, 0, 10) // => 10\r\n */\r\nexport function clampNumber(value: number, min?: number, max?: number): number {\r\n let result = value;\r\n if (min !== undefined && result < min) result = min;\r\n if (max !== undefined && result > max) result = max;\r\n return result;\r\n}\r\n\r\n/**\r\n * Apply numeric precision (decimal places) to a number.\r\n * \r\n * @param value - The number to format\r\n * @param precision - Number of decimal places\r\n * @returns Formatted number or undefined if input is undefined\r\n * \r\n * @example\r\n * applyNumericPrecision(3.14159, 2) // => 3.14\r\n * applyNumericPrecision(10, 2) // => 10\r\n */\r\nexport function applyNumericPrecision(\r\n value: number | undefined,\r\n precision?: number\r\n): number | undefined {\r\n if (value === undefined || precision === undefined) return value;\r\n return parseFloat(value.toFixed(precision));\r\n}\r\n\r\n/**\r\n * Format a number with thousand separators.\r\n * \r\n * @param value - The number to format\r\n * @param separator - Separator character (default: ',')\r\n * @returns Formatted string or empty string if value is undefined/NaN\r\n * \r\n * @example\r\n * formatNumberWithSeparator(1234567.89) // => '1,234,567.89'\r\n * formatNumberWithSeparator(1234567, ' ') // => '1 234 567'\r\n */\r\nexport function formatNumberWithSeparator(\r\n value: number | undefined,\r\n separator: string = ','\r\n): string {\r\n if (value === undefined || value === null || isNaN(value)) return '';\r\n const [intPart, decPart] = value.toString().split('.');\r\n const formattedInt = intPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, separator);\r\n return decPart !== undefined ? `${formattedInt}.${decPart}` : formattedInt;\r\n}\r\n\r\n/**\r\n * Parse a formatted number string back to a number.\r\n * \r\n * @param str - Formatted string with separators\r\n * @param separator - Separator character to remove\r\n * @returns Parsed number or undefined if invalid\r\n * \r\n * @example\r\n * parseFormattedNumber('1,234,567.89') // => 1234567.89\r\n * parseFormattedNumber('1 234 567', ' ') // => 1234567\r\n */\r\nexport function parseFormattedNumber(\r\n str: string,\r\n separator: string = ','\r\n): number | undefined {\r\n if (!str || str === '') return undefined;\r\n const cleaned = str.split(separator).join('');\r\n const num = parseFloat(cleaned);\r\n return isNaN(num) ? undefined : num;\r\n}\r\n\r\n// =============================================================================\r\n// DATE UTILITIES\r\n// Helpers for date field operations.\r\n// =============================================================================\r\n\r\n/**\r\n * Safely parse a value to a Date object.\r\n * Handles Date objects, ISO strings, and timestamps.\r\n * \r\n * @param value - Value to parse (Date, string, number, or unknown)\r\n * @returns Date object or undefined if invalid\r\n * \r\n * @example\r\n * parseToDate(new Date()) // => Date\r\n * parseToDate('2024-01-15') // => Date\r\n * parseToDate(null) // => undefined\r\n */\r\nexport function parseToDate(value: unknown): Date | undefined {\r\n if (!value) return undefined;\r\n if (value instanceof Date) {\r\n return isNaN(value.getTime()) ? undefined : value;\r\n }\r\n if (typeof value === 'number') {\r\n const date = new Date(value);\r\n return isNaN(date.getTime()) ? undefined : date;\r\n }\r\n if (typeof value === 'string') {\r\n const date = new Date(value);\r\n return isNaN(date.getTime()) ? undefined : date;\r\n }\r\n return undefined;\r\n}\r\n"],"mappings":";AAAA,SAAS,cAAc;AAUhB,SAAS,mBACZ,UACA,UACY;AACZ,SAAO;AAAA,IACH,QAAQ,CAAc,SAA4C;AAC9D,YAAM,MAAM,SAAS,IAAI;AACzB,UAAI,CAAC,MAAM,QAAQ,GAAG,EAAG,QAAO,CAAC;AACjC,aAAO,IAAI,IAAI,CAAC,MAAM,WAAW;AAAA,QAC7B,IAAK,MAAkC,MAAgB,GAAG,IAAI,IAAI,KAAK;AAAA,QACvE,GAAG;AAAA,MACP,EAAE;AAAA,IACN;AAAA,IAEA,QAAQ,CAAC,MAAc,UAAmB;AACtC,YAAM,UAAU,SAAS,IAAI,KAAK,CAAC;AACnC,YAAM,aAAa,SAAS,KAAK;AACjC,eAAS,MAAM,CAAC,GAAG,SAAS,UAAU,CAAC;AAAA,IAC3C;AAAA,IAEA,SAAS,CAAC,MAAc,UAAmB;AACvC,YAAM,UAAU,SAAS,IAAI,KAAK,CAAC;AACnC,YAAM,aAAa,SAAS,KAAK;AACjC,eAAS,MAAM,CAAC,YAAY,GAAG,OAAO,CAAC;AAAA,IAC3C;AAAA,IAEA,QAAQ,CAAC,MAAc,OAAe,UAAmB;AACrD,YAAM,UAAU,CAAC,GAAI,SAAS,IAAI,KAAK,CAAC,CAAE;AAC1C,YAAM,aAAa,SAAS,KAAK;AACjC,cAAQ,OAAO,OAAO,GAAG,UAAU;AACnC,eAAS,MAAM,OAAO;AAAA,IAC1B;AAAA,IAEA,QAAQ,CAAC,MAAc,UAAkB;AACrC,YAAM,UAAU,CAAC,GAAI,SAAS,IAAI,KAAK,CAAC,CAAE;AAC1C,cAAQ,OAAO,OAAO,CAAC;AACvB,eAA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