@frontile/forms 0.17.0-beta.25 → 0.17.0-beta.26
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/declarations/components/checkbox-group.d.ts +3 -1
- package/declarations/components/checkbox.d.ts +2 -0
- package/declarations/components/field-types.d.ts +14 -0
- package/declarations/components/field.d.ts +85 -0
- package/declarations/components/form-control.d.ts +1 -0
- package/declarations/components/form.d.ts +244 -8
- package/declarations/components/input.d.ts +5 -0
- package/declarations/components/radio-group.d.ts +1 -1
- package/declarations/components/radio.d.ts +2 -0
- package/declarations/components/select.d.ts +211 -5
- package/declarations/components/switch.d.ts +21 -16
- package/declarations/components/textarea.d.ts +2 -0
- package/declarations/index.d.ts +3 -0
- package/declarations/utils/index.d.ts +1 -0
- package/declarations/utils/nested-data.d.ts +44 -0
- package/declarations/utils/standard-validator.d.ts +151 -0
- package/dist/_app_/components/field-types.js +1 -0
- package/dist/_app_/components/field.js +1 -0
- package/dist/components/checkbox-group.js +1 -1
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/checkbox.js +8 -2
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/field-types.js +2 -0
- package/dist/components/field-types.js.map +1 -0
- package/dist/components/field.js +103 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/form-control.js.map +1 -1
- package/dist/components/form.js +12 -29
- package/dist/components/form.js.map +1 -1
- package/dist/components/input.js +8 -2
- package/dist/components/input.js.map +1 -1
- package/dist/components/native-select.js +1 -1
- package/dist/components/radio-group.js +1 -1
- package/dist/components/radio-group.js.map +1 -1
- package/dist/components/radio.js +8 -2
- package/dist/components/radio.js.map +1 -1
- package/dist/components/select.js +159 -18
- package/dist/components/select.js.map +1 -1
- package/dist/components/switch.js +5 -2
- package/dist/components/switch.js.map +1 -1
- package/dist/components/textarea.js +8 -2
- package/dist/components/textarea.js.map +1 -1
- package/dist/form-CVuJDJUq.js +726 -0
- package/dist/form-CVuJDJUq.js.map +1 -0
- package/dist/form-Dzyb1-8B.js +623 -0
- package/dist/form-Dzyb1-8B.js.map +1 -0
- package/dist/index-CeaQc-U7.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js +67 -0
- package/dist/runtime-BPCpkOf1-B5Lbloj7.js.map +1 -0
- package/dist/test-support.js +2 -2
- package/dist/test-support.js.map +1 -1
- package/package.json +10 -7
|
@@ -10,6 +10,32 @@ interface BaseSelectArgs<T> extends Pick<PopoverSignature['Args'], 'placement' |
|
|
|
10
10
|
interface BaseSingleSelectArgs<T> extends BaseSelectArgs<T> {
|
|
11
11
|
/**
|
|
12
12
|
* The currently selected key for single selection mode.
|
|
13
|
+
*
|
|
14
|
+
* **Data Flow:**
|
|
15
|
+
* - Pass this to set the initial selection
|
|
16
|
+
* - Update this in your `onSelectionChange` handler to maintain two-way binding
|
|
17
|
+
* - The component calls `onSelectionChange` whenever the user changes the selection
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```gts
|
|
21
|
+
* import { tracked } from '@glimmer/tracking';
|
|
22
|
+
*
|
|
23
|
+
* class MyComponent {
|
|
24
|
+
* @tracked selectedKey = 'option1';
|
|
25
|
+
*
|
|
26
|
+
* handleSelectionChange = (key: string | null) => {
|
|
27
|
+
* this.selectedKey = key; // Update parent state
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* <template>
|
|
31
|
+
* <Select
|
|
32
|
+
* @selectedKey={{this.selectedKey}}
|
|
33
|
+
* @onSelectionChange={{this.handleSelectionChange}}
|
|
34
|
+
* @items={{this.items}}
|
|
35
|
+
* />
|
|
36
|
+
* </template>
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
13
39
|
*/
|
|
14
40
|
selectedKey?: string | null;
|
|
15
41
|
/**
|
|
@@ -18,6 +44,10 @@ interface BaseSingleSelectArgs<T> extends BaseSelectArgs<T> {
|
|
|
18
44
|
selectedKeys?: never;
|
|
19
45
|
/**
|
|
20
46
|
* Callback fired when the selection changes in single mode.
|
|
47
|
+
*
|
|
48
|
+
* Update your `@selectedKey` state in this callback to maintain two-way binding.
|
|
49
|
+
*
|
|
50
|
+
* @param key - The newly selected key, or null if selection was cleared
|
|
21
51
|
*/
|
|
22
52
|
onSelectionChange?: (key: string | null) => void;
|
|
23
53
|
}
|
|
@@ -48,10 +78,41 @@ interface MultipleSelectArgs<T> extends BaseSelectArgs<T> {
|
|
|
48
78
|
selectedKey?: never;
|
|
49
79
|
/**
|
|
50
80
|
* The currently selected keys for multiple selection mode.
|
|
81
|
+
*
|
|
82
|
+
* **Data Flow:**
|
|
83
|
+
* - Pass this to set the initial selection (array of keys)
|
|
84
|
+
* - Update this in your `onSelectionChange` handler to maintain two-way binding
|
|
85
|
+
* - The component calls `onSelectionChange` whenever the user changes the selection
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```gts
|
|
89
|
+
* import { tracked } from '@glimmer/tracking';
|
|
90
|
+
*
|
|
91
|
+
* class MyComponent {
|
|
92
|
+
* @tracked selectedKeys = ['option1', 'option2'];
|
|
93
|
+
*
|
|
94
|
+
* handleSelectionChange = (keys: string[]) => {
|
|
95
|
+
* this.selectedKeys = keys; // Update parent state
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* <template>
|
|
99
|
+
* <Select
|
|
100
|
+
* @selectionMode="multiple"
|
|
101
|
+
* @selectedKeys={{this.selectedKeys}}
|
|
102
|
+
* @onSelectionChange={{this.handleSelectionChange}}
|
|
103
|
+
* @items={{this.items}}
|
|
104
|
+
* />
|
|
105
|
+
* </template>
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
51
108
|
*/
|
|
52
109
|
selectedKeys?: string[];
|
|
53
110
|
/**
|
|
54
111
|
* Callback fired when the selection changes in multiple mode.
|
|
112
|
+
*
|
|
113
|
+
* Update your `@selectedKeys` state in this callback to maintain two-way binding.
|
|
114
|
+
*
|
|
115
|
+
* @param keys - The newly selected keys (empty array if all selections cleared)
|
|
55
116
|
*/
|
|
56
117
|
onSelectionChange?: (keys: string[]) => void;
|
|
57
118
|
}
|
|
@@ -69,8 +130,9 @@ type SelectArgs<T> = (ExplicitSingleSelectArgs<T> | DefaultSingleSelectArgs<T> |
|
|
|
69
130
|
* - 'sm': Small
|
|
70
131
|
* - 'md': Medium
|
|
71
132
|
* - 'lg': Large
|
|
72
|
-
*
|
|
73
|
-
*
|
|
133
|
+
* - 'trigger': Same size as the trigger
|
|
134
|
+
*
|
|
135
|
+
* @defaultValue 'trigger'
|
|
74
136
|
*/
|
|
75
137
|
popoverSize?: 'sm' | 'md' | 'lg' | 'trigger';
|
|
76
138
|
/**
|
|
@@ -144,9 +206,8 @@ type SelectArgs<T> = (ExplicitSingleSelectArgs<T> | DefaultSingleSelectArgs<T> |
|
|
|
144
206
|
startContentPointerEvents?: 'none' | 'auto';
|
|
145
207
|
/**
|
|
146
208
|
* Controls pointer-events property of endContent.
|
|
147
|
-
*
|
|
148
|
-
* needs to capture events,
|
|
149
|
-
* element only.
|
|
209
|
+
* Defaults to `none` to pass click events to the input. If your content
|
|
210
|
+
* needs to capture events, add the `pointer-events-auto` class to that element.
|
|
150
211
|
*
|
|
151
212
|
* @defaultValue 'none'
|
|
152
213
|
*/
|
|
@@ -157,6 +218,10 @@ type SelectArgs<T> = (ExplicitSingleSelectArgs<T> | DefaultSingleSelectArgs<T> |
|
|
|
157
218
|
* @defaultValue false
|
|
158
219
|
*/
|
|
159
220
|
hideEmptyContent?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Callback fired when the select component loses focus.
|
|
223
|
+
*/
|
|
224
|
+
onBlur?: () => void;
|
|
160
225
|
};
|
|
161
226
|
interface SelectSignature<T> {
|
|
162
227
|
Args: SelectArgs<T>;
|
|
@@ -183,11 +248,69 @@ interface SelectSignature<T> {
|
|
|
183
248
|
emptyContent: [];
|
|
184
249
|
};
|
|
185
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Select Component - A feature-rich dropdown selection component
|
|
253
|
+
*
|
|
254
|
+
* ## Selection State Architecture
|
|
255
|
+
*
|
|
256
|
+
* This component uses a **two-way data binding pattern** for managing selection state:
|
|
257
|
+
*
|
|
258
|
+
* ### Data Flow
|
|
259
|
+
* 1. **External → Internal (Initialization & Updates)**
|
|
260
|
+
* - Parent passes `@selectedKey` or `@selectedKeys` as arguments
|
|
261
|
+
* - Constructor initializes internal tracked properties (`_selectedKey` or `_selectedKeys`)
|
|
262
|
+
* - Modifiers (`updateSingleSelectValue`, `updateMultipleSelectValue`) sync internal state
|
|
263
|
+
* when parent updates the arguments
|
|
264
|
+
*
|
|
265
|
+
* 2. **Internal State Management**
|
|
266
|
+
* - `_selectedKey` / `_selectedKeys`: Internal tracked state (prefixed with underscore)
|
|
267
|
+
* - These serve as the "source of truth" for rendering and reactivity
|
|
268
|
+
* - Getters (`getSelectedKey`, `selectedKeys`) expose this internal state to the template
|
|
269
|
+
*
|
|
270
|
+
* 3. **Internal → External (User Interactions)**
|
|
271
|
+
* - User interactions trigger selection change handlers
|
|
272
|
+
* - Handlers update internal `_selectedKey` / `_selectedKeys` for immediate UI update
|
|
273
|
+
* - Handlers call parent's `@onSelectionChange` callback to notify of state change
|
|
274
|
+
* - Parent updates its state, which flows back through step 1
|
|
275
|
+
*
|
|
276
|
+
* ### Why Both Internal State AND Callbacks?
|
|
277
|
+
* - **Internal state:** Enables immediate, responsive UI updates (`_selectedKey` / `_selectedKeys`)
|
|
278
|
+
* - **Parent callback:** Enables parent to take action when changes occur (`@onSelectionChange`)
|
|
279
|
+
* - This pattern provides both responsive UX and parent inclusion over state
|
|
280
|
+
*
|
|
281
|
+
* ### Example Flow
|
|
282
|
+
* ```
|
|
283
|
+
* User clicks item
|
|
284
|
+
* → onSelectionChange handler
|
|
285
|
+
* → Updates _selectedKey (immediate UI update)
|
|
286
|
+
* → Calls parent's @onSelectionChange callback
|
|
287
|
+
* → Parent updates its @selectedKey state
|
|
288
|
+
* → updateSingleSelectValue modifier syncs _selectedKey with new arg value
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
186
291
|
declare class Select<T = unknown> extends Component<SelectSignature<T>> {
|
|
187
292
|
nodes: ListItem[];
|
|
188
293
|
isOpen: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Internal tracked state for single selection mode.
|
|
296
|
+
* Source of truth for rendering. Synced with @selectedKey via the updateSingleSelectValue modifier.
|
|
297
|
+
*/
|
|
189
298
|
_selectedKey: string | null;
|
|
299
|
+
/**
|
|
300
|
+
* Internal tracked state for multiple selection mode.
|
|
301
|
+
* Source of truth for rendering. Synced with @selectedKeys via the updateMultipleSelectValue modifier.
|
|
302
|
+
*/
|
|
190
303
|
_selectedKeys: string[];
|
|
304
|
+
/**
|
|
305
|
+
* Initializes the component and sets up initial selection state.
|
|
306
|
+
*
|
|
307
|
+
* **Initialization:**
|
|
308
|
+
* 1. Determines selection mode (single vs multiple)
|
|
309
|
+
* 2. Copies external arg values (@selectedKey or @selectedKeys) to internal tracked state
|
|
310
|
+
* 3. Logs warnings if incorrect args are used for the selection mode
|
|
311
|
+
*
|
|
312
|
+
* Note: After instantiation, modifiers keep internal state synced with external arguments.
|
|
313
|
+
*/
|
|
191
314
|
constructor(owner: Owner, args: SelectArgs<T>);
|
|
192
315
|
validateArgs(): void;
|
|
193
316
|
filterValue?: string;
|
|
@@ -213,15 +336,66 @@ declare class Select<T = unknown> extends Component<SelectSignature<T>> {
|
|
|
213
336
|
Element: HTMLInputElement | HTMLButtonElement;
|
|
214
337
|
}>;
|
|
215
338
|
};
|
|
339
|
+
/**
|
|
340
|
+
* Handles selection changes from the Listbox component.
|
|
341
|
+
*
|
|
342
|
+
* **Flow:**
|
|
343
|
+
* 1. Updates internal state (`_selectedKey` or `_selectedKeys`) for immediate UI updates
|
|
344
|
+
* 2. Calls parent's `@onSelectionChange` callback to notify of the change
|
|
345
|
+
* 3. Parent updates its state, which flows back via modifier to complete the cycle
|
|
346
|
+
*
|
|
347
|
+
* **Side effects:**
|
|
348
|
+
* - Clears filter value (for searchable selects)
|
|
349
|
+
* - Triggers form input event for native form integration
|
|
350
|
+
*
|
|
351
|
+
* @param keys - Array of selected keys from Listbox (converted to single value in single mode)
|
|
352
|
+
*/
|
|
216
353
|
onSelectionChange: (keys: string[]) => void;
|
|
354
|
+
/**
|
|
355
|
+
* Handles selection changes from the native <select> element.
|
|
356
|
+
*
|
|
357
|
+
* This is similar to `onSelectionChange` but accepts a single key directly
|
|
358
|
+
* rather than an array, matching the native select's single-value API.
|
|
359
|
+
*
|
|
360
|
+
* **Flow:**
|
|
361
|
+
* 1. Updates internal `_selectedKey` for immediate UI update
|
|
362
|
+
* 2. Calls parent's `@onSelectionChange` callback
|
|
363
|
+
*
|
|
364
|
+
* @param key - The selected key, or null if cleared
|
|
365
|
+
*/
|
|
217
366
|
onSingleSelectionChange: (key: string | null) => void;
|
|
218
367
|
onOpenChange: (isOpen: boolean) => void;
|
|
219
368
|
onFilterChange: (event: Event) => void;
|
|
369
|
+
/**
|
|
370
|
+
* Returns current selection as an array for template rendering.
|
|
371
|
+
*
|
|
372
|
+
* Normalizes both single and multiple selection modes to a consistent array interface:
|
|
373
|
+
* - Multiple mode: Returns `_selectedKeys` directly
|
|
374
|
+
* - Single mode: Converts `_selectedKey` to array format (or empty array if null)
|
|
375
|
+
*
|
|
376
|
+
* Note: Always returns internal tracked state rather than arguments. External updates
|
|
377
|
+
* sync through modifiers to maintain consistency.
|
|
378
|
+
*
|
|
379
|
+
* @returns Array of selected keys (empty array if none selected)
|
|
380
|
+
*/
|
|
220
381
|
get selectedKeys(): string[];
|
|
382
|
+
/**
|
|
383
|
+
* Returns the selected key for single selection mode.
|
|
384
|
+
*
|
|
385
|
+
* **Returns:**
|
|
386
|
+
* - Single mode: Returns `_selectedKey` (string or null)
|
|
387
|
+
* - Multiple mode: Returns null (not applicable)
|
|
388
|
+
*
|
|
389
|
+
* Note: Always returns internal tracked state rather than arguments. External updates
|
|
390
|
+
* sync through modifiers to maintain consistency.
|
|
391
|
+
*
|
|
392
|
+
* @returns The selected key, or null if none selected or in multiple mode
|
|
393
|
+
*/
|
|
221
394
|
get getSelectedKey(): string | null;
|
|
222
395
|
get blockScroll(): boolean;
|
|
223
396
|
get disableFocusTrap(): boolean;
|
|
224
397
|
onAction: (key: string) => void;
|
|
398
|
+
handleBlur(): void;
|
|
225
399
|
clearSelectedKeys: () => void;
|
|
226
400
|
onItemsChange: (nodes: ListItem[], _: "add" | "remove") => void;
|
|
227
401
|
didClose: () => void;
|
|
@@ -320,6 +494,38 @@ declare class Select<T = unknown> extends Component<SelectSignature<T>> {
|
|
|
320
494
|
get filteredItems(): T[] | undefined;
|
|
321
495
|
get showEmptyContent(): boolean;
|
|
322
496
|
get autoActivateMode(): 'first' | 'selected';
|
|
497
|
+
/**
|
|
498
|
+
* Syncs internal `_selectedKeys` with external `@selectedKeys` argument.
|
|
499
|
+
*
|
|
500
|
+
* Runs whenever `@selectedKeys` changes:
|
|
501
|
+
* - Updates `_selectedKeys` to match the new external value
|
|
502
|
+
* - Normalizes undefined/null to empty array
|
|
503
|
+
*
|
|
504
|
+
* This enables UI updates when the external value changes.
|
|
505
|
+
*/
|
|
506
|
+
updateMultipleSelectValue: import("ember-modifier").FunctionBasedModifier<{
|
|
507
|
+
Args: {
|
|
508
|
+
Positional: [string[] | null | undefined];
|
|
509
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
510
|
+
};
|
|
511
|
+
Element: HTMLDivElement;
|
|
512
|
+
}>;
|
|
513
|
+
/**
|
|
514
|
+
* Syncs internal `_selectedKey` with external `@selectedKey` argument.
|
|
515
|
+
*
|
|
516
|
+
* Runs whenever `@selectedKey` changes:
|
|
517
|
+
* - Updates `_selectedKey` to match the new external value
|
|
518
|
+
* - Handles null values for cleared selections
|
|
519
|
+
*
|
|
520
|
+
* This enables UI updates when the external value changes.
|
|
521
|
+
*/
|
|
522
|
+
updateSingleSelectValue: import("ember-modifier").FunctionBasedModifier<{
|
|
523
|
+
Args: {
|
|
524
|
+
Positional: [string | null | undefined];
|
|
525
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
526
|
+
};
|
|
527
|
+
Element: HTMLDivElement;
|
|
528
|
+
}>;
|
|
323
529
|
}
|
|
324
530
|
export { Select, type SelectSignature };
|
|
325
531
|
export default Select;
|
|
@@ -41,6 +41,10 @@ interface Args extends FormControlSharedArgs {
|
|
|
41
41
|
* Receives the new boolean value and, optionally, the triggering Event.
|
|
42
42
|
*/
|
|
43
43
|
onChange?: ((value: boolean, event: Event) => void) | ((value: boolean) => void);
|
|
44
|
+
/**
|
|
45
|
+
* Callback triggered when the Switch loses focus (blur event).
|
|
46
|
+
*/
|
|
47
|
+
onBlur?: () => void;
|
|
44
48
|
}
|
|
45
49
|
interface SwitchSignature {
|
|
46
50
|
Args: Args;
|
|
@@ -59,85 +63,86 @@ declare class Switch extends Component<SwitchSignature> {
|
|
|
59
63
|
get isControlled(): boolean;
|
|
60
64
|
get isSelected(): boolean;
|
|
61
65
|
handleChange: (event: Event) => void;
|
|
66
|
+
handleBlur: () => void;
|
|
62
67
|
get classes(): {
|
|
63
68
|
base: (slotProps?: ({
|
|
64
|
-
intent?: "
|
|
69
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
65
70
|
size?: "sm" | "md" | "lg" | undefined;
|
|
66
71
|
isDisabled?: boolean | undefined;
|
|
67
72
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
68
73
|
labelContainer: (slotProps?: ({
|
|
69
|
-
intent?: "
|
|
74
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
70
75
|
size?: "sm" | "md" | "lg" | undefined;
|
|
71
76
|
isDisabled?: boolean | undefined;
|
|
72
77
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
73
78
|
label: (slotProps?: ({
|
|
74
|
-
intent?: "
|
|
79
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
75
80
|
size?: "sm" | "md" | "lg" | undefined;
|
|
76
81
|
isDisabled?: boolean | undefined;
|
|
77
82
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
78
83
|
wrapper: (slotProps?: ({
|
|
79
|
-
intent?: "
|
|
84
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
80
85
|
size?: "sm" | "md" | "lg" | undefined;
|
|
81
86
|
isDisabled?: boolean | undefined;
|
|
82
87
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
83
88
|
hiddenInput: (slotProps?: ({
|
|
84
|
-
intent?: "
|
|
89
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
85
90
|
size?: "sm" | "md" | "lg" | undefined;
|
|
86
91
|
isDisabled?: boolean | undefined;
|
|
87
92
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
88
93
|
thumb: (slotProps?: ({
|
|
89
|
-
intent?: "
|
|
94
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
90
95
|
size?: "sm" | "md" | "lg" | undefined;
|
|
91
96
|
isDisabled?: boolean | undefined;
|
|
92
97
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
93
98
|
startContent: (slotProps?: ({
|
|
94
|
-
intent?: "
|
|
99
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
95
100
|
size?: "sm" | "md" | "lg" | undefined;
|
|
96
101
|
isDisabled?: boolean | undefined;
|
|
97
102
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
98
103
|
endContent: (slotProps?: ({
|
|
99
|
-
intent?: "
|
|
104
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
100
105
|
size?: "sm" | "md" | "lg" | undefined;
|
|
101
106
|
isDisabled?: boolean | undefined;
|
|
102
107
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
103
108
|
} & {
|
|
104
109
|
base: (slotProps?: ({
|
|
105
|
-
intent?: "
|
|
110
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
106
111
|
size?: "sm" | "md" | "lg" | undefined;
|
|
107
112
|
isDisabled?: boolean | undefined;
|
|
108
113
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
109
114
|
labelContainer: (slotProps?: ({
|
|
110
|
-
intent?: "
|
|
115
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
111
116
|
size?: "sm" | "md" | "lg" | undefined;
|
|
112
117
|
isDisabled?: boolean | undefined;
|
|
113
118
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
114
119
|
label: (slotProps?: ({
|
|
115
|
-
intent?: "
|
|
120
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
116
121
|
size?: "sm" | "md" | "lg" | undefined;
|
|
117
122
|
isDisabled?: boolean | undefined;
|
|
118
123
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
119
124
|
wrapper: (slotProps?: ({
|
|
120
|
-
intent?: "
|
|
125
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
121
126
|
size?: "sm" | "md" | "lg" | undefined;
|
|
122
127
|
isDisabled?: boolean | undefined;
|
|
123
128
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
124
129
|
hiddenInput: (slotProps?: ({
|
|
125
|
-
intent?: "
|
|
130
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
126
131
|
size?: "sm" | "md" | "lg" | undefined;
|
|
127
132
|
isDisabled?: boolean | undefined;
|
|
128
133
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
129
134
|
thumb: (slotProps?: ({
|
|
130
|
-
intent?: "
|
|
135
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
131
136
|
size?: "sm" | "md" | "lg" | undefined;
|
|
132
137
|
isDisabled?: boolean | undefined;
|
|
133
138
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
134
139
|
startContent: (slotProps?: ({
|
|
135
|
-
intent?: "
|
|
140
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
136
141
|
size?: "sm" | "md" | "lg" | undefined;
|
|
137
142
|
isDisabled?: boolean | undefined;
|
|
138
143
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
139
144
|
endContent: (slotProps?: ({
|
|
140
|
-
intent?: "
|
|
145
|
+
intent?: "primary" | "success" | "danger" | "warning" | "default" | undefined;
|
|
141
146
|
size?: "sm" | "md" | "lg" | undefined;
|
|
142
147
|
isDisabled?: boolean | undefined;
|
|
143
148
|
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
@@ -9,6 +9,7 @@ interface Args extends FormControlSharedArgs {
|
|
|
9
9
|
classes?: SlotsToClasses<TextareaSlots>;
|
|
10
10
|
onInput?: (value: string, event: InputEvent) => void;
|
|
11
11
|
onChange?: (value: string, event: InputEvent) => void;
|
|
12
|
+
onBlur?: () => void;
|
|
12
13
|
}
|
|
13
14
|
interface TextareaSignature {
|
|
14
15
|
Args: Args;
|
|
@@ -17,6 +18,7 @@ interface TextareaSignature {
|
|
|
17
18
|
declare class Textarea extends Component<TextareaSignature> {
|
|
18
19
|
handleOnInput(event: Event): void;
|
|
19
20
|
handleOnChange(event: Event): void;
|
|
21
|
+
handleOnBlur(): void;
|
|
20
22
|
get classes(): {
|
|
21
23
|
base: (slotProps?: ({
|
|
22
24
|
size?: "sm" | "md" | "lg" | undefined;
|
package/declarations/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './components/form';
|
|
2
|
+
export * from './components/field';
|
|
2
3
|
export * from './components/checkbox';
|
|
3
4
|
export * from './components/checkbox-group';
|
|
4
5
|
export * from './components/form-description';
|
|
@@ -12,3 +13,5 @@ export * from './components/radio';
|
|
|
12
13
|
export * from './components/radio-group';
|
|
13
14
|
export * from './components/form-control';
|
|
14
15
|
export * from './components/switch';
|
|
16
|
+
export * from './utils/standard-validator';
|
|
17
|
+
export * from './utils/nested-data';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with nested data structures in forms.
|
|
3
|
+
* These functions convert between nested objects and flat dotted-path notation.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Flattens a nested object into a flat object with dotted-path keys.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* flattenData({name: {first: 'John', last: 'Doe'}, email: 'john@example.com'})
|
|
10
|
+
* // Returns: {'name.first': 'John', 'name.last': 'Doe', 'email': 'john@example.com'}
|
|
11
|
+
*
|
|
12
|
+
* @param data - The nested data object to flatten
|
|
13
|
+
* @param prefix - Internal parameter for recursion (parent path)
|
|
14
|
+
* @returns A flat object with dotted-path keys
|
|
15
|
+
*/
|
|
16
|
+
export declare function flattenData<T = unknown>(data: Record<string, unknown>, prefix?: string): Record<string, T>;
|
|
17
|
+
/**
|
|
18
|
+
* Unflattens a flat object with dotted-path keys into a nested object structure.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* unflattenData({'name.first': 'John', 'name.last': 'Doe', 'email': 'john@example.com'})
|
|
22
|
+
* // Returns: {name: {first: 'John', last: 'Doe'}, email: 'john@example.com'}
|
|
23
|
+
*
|
|
24
|
+
* @param data - The flat data object with dotted-path keys
|
|
25
|
+
* @returns A nested object structure
|
|
26
|
+
*/
|
|
27
|
+
export declare function unflattenData<T = unknown>(data: Record<string, unknown>): Record<string, T>;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the data structure contains any nested objects.
|
|
30
|
+
* If true, we need to handle it as nested data.
|
|
31
|
+
*
|
|
32
|
+
* @param data - The data object to check
|
|
33
|
+
* @returns True if the data contains nested plain objects
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasNestedData(data: Record<string, unknown>): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Deep equality comparison for nested objects.
|
|
38
|
+
* Handles primitives, arrays, and nested objects.
|
|
39
|
+
*
|
|
40
|
+
* @param a - First value to compare
|
|
41
|
+
* @param b - Second value to compare
|
|
42
|
+
* @returns True if values are deeply equal
|
|
43
|
+
*/
|
|
44
|
+
export declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/**
|
|
3
|
+
* The issues collection returned by a Standard Schema validation failure.
|
|
4
|
+
*/
|
|
5
|
+
export type Issues = readonly StandardSchemaV1.Issue[];
|
|
6
|
+
/**
|
|
7
|
+
* The return type of a validator function.
|
|
8
|
+
* Resolves to the issues (when validation fails) or undefined
|
|
9
|
+
* (when it succeeds).
|
|
10
|
+
*/
|
|
11
|
+
export type ValidatorReturn = Promise<Issues | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* StandardSchemaV1 issues as either a promise or synchronous. If there are
|
|
14
|
+
* no issues, `undefined` is returned.
|
|
15
|
+
*/
|
|
16
|
+
export type CustomValidatorReturn = ValidatorReturn | Issues | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A custom validator function.
|
|
19
|
+
* If there are errors, they are returned by the validator as
|
|
20
|
+
* StandardSchemaV1 issues. If there are no errors, nothing is returned.
|
|
21
|
+
*/
|
|
22
|
+
export type CustomValidatorFn<Input = unknown> = (input: Input) => CustomValidatorReturn;
|
|
23
|
+
/**
|
|
24
|
+
* Provides convenience methods for validating data using Standard Schema.
|
|
25
|
+
* Also supports custom validator functions that return issues in the
|
|
26
|
+
* Standard Schema format.
|
|
27
|
+
*
|
|
28
|
+
* Most of the time you should use `validateAll` or `validateFieldAll` to
|
|
29
|
+
* validate data. Schema and custom validation are optional arguments
|
|
30
|
+
* to these methods. This is useful because schema and custom validation
|
|
31
|
+
* must both be optional in the form component, which is the primary use
|
|
32
|
+
* case for this class.
|
|
33
|
+
*
|
|
34
|
+
* Note: all methods are static, so you do not need to instantiate
|
|
35
|
+
* this class.
|
|
36
|
+
*
|
|
37
|
+
* @see https://standardschema.dev/
|
|
38
|
+
*/
|
|
39
|
+
declare class StandardValidator {
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Validates data against the provided standard schema.
|
|
43
|
+
* If there are errors, they are returned. Otherwise, nothing is returned.
|
|
44
|
+
* This provides a boolean indication of outcome: if there is a return
|
|
45
|
+
* value, validation failed. Otherwise, validation succeeded.
|
|
46
|
+
* @see https://standardschema.dev/
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const input = …; // your data to validate
|
|
50
|
+
* const schema = …; // your standard schema
|
|
51
|
+
* const issues = await StandardValidator.validate(input, schema);
|
|
52
|
+
*
|
|
53
|
+
* @param input The input to validate.
|
|
54
|
+
* @param schema The standard schema to validate against.
|
|
55
|
+
* @return The issues if validation failed, otherwise undefined.
|
|
56
|
+
*/
|
|
57
|
+
static validate<I, O>(input: I, schema: StandardSchemaV1<I, O>): ValidatorReturn;
|
|
58
|
+
/**
|
|
59
|
+
* Validates a single field within the input data using the provided
|
|
60
|
+
* standard schema. If there are issues related to the specified field,
|
|
61
|
+
* they are returned. Otherwise, nothing is returned.
|
|
62
|
+
*
|
|
63
|
+
* Note: because standard schema does not provide a way to validate
|
|
64
|
+
* individual fields, this method filters the issues returned by the
|
|
65
|
+
* schema validation to find those related to the specified field.
|
|
66
|
+
* @see https://standardschema.dev/
|
|
67
|
+
*
|
|
68
|
+
* @param input The input data to validate.
|
|
69
|
+
* @param fieldName The name of the field to validate.
|
|
70
|
+
* @param schema The standard schema to validate against.
|
|
71
|
+
* @returns The issues related to the specified field if validation failed,
|
|
72
|
+
* otherwise undefined.
|
|
73
|
+
*/
|
|
74
|
+
static validateField<I, O>(input: I, fieldName: string, schema: StandardSchemaV1<I, O>): ValidatorReturn;
|
|
75
|
+
/**
|
|
76
|
+
* Validates input using a custom validator function.
|
|
77
|
+
* If there are errors, they are returned by the validator as
|
|
78
|
+
* StandardSchemaV1 issues. If there are no errors, nothing is returned.
|
|
79
|
+
* @see https://standardschema.dev/
|
|
80
|
+
*
|
|
81
|
+
* @param input The input data to validate.
|
|
82
|
+
* @param customValidator The custom validator function to use.
|
|
83
|
+
* @returns The issues if validation failed, otherwise undefined.
|
|
84
|
+
*/
|
|
85
|
+
static validateCustom<I>(input: I, customValidator: CustomValidatorFn<I>): ValidatorReturn;
|
|
86
|
+
/**
|
|
87
|
+
* Validates a single field within the input data using a custom validator
|
|
88
|
+
* function. If there are issues related to the specified field, they are
|
|
89
|
+
* returned. Otherwise, nothing is returned.
|
|
90
|
+
*
|
|
91
|
+
* Note: because custom validators may return issues for multiple fields,
|
|
92
|
+
* this method filters the issues returned by the custom validator to find
|
|
93
|
+
* those related to the specified field.
|
|
94
|
+
* @see https://standardschema.dev/
|
|
95
|
+
*
|
|
96
|
+
* @param input The input data to validate.
|
|
97
|
+
* @param fieldName The name of the field to validate.
|
|
98
|
+
* @param customValidator The custom validator function to use.
|
|
99
|
+
* @returns The issues related to the specified field if validation failed,
|
|
100
|
+
* otherwise undefined.
|
|
101
|
+
*/
|
|
102
|
+
static validateFieldCustom<I>(input: I, fieldName: string, customValidator: CustomValidatorFn<I>): ValidatorReturn;
|
|
103
|
+
/**
|
|
104
|
+
* Validates input data using both a standard schema and a custom validator
|
|
105
|
+
* function, merging any issues found by either method. If there are issues,
|
|
106
|
+
* they are returned. Otherwise, nothing is returned. This method runs both
|
|
107
|
+
* validations in parallel.
|
|
108
|
+
*
|
|
109
|
+
* Note: `schema` and `customValidator` are both optional. If either the
|
|
110
|
+
* schema or custom validator is not provided, that validation is skipped.
|
|
111
|
+
* @see https://standardschema.dev/
|
|
112
|
+
*
|
|
113
|
+
* @param input The input data to validate.
|
|
114
|
+
* @param schema Optional standard schema to validate against.
|
|
115
|
+
* @param customValidator Optional custom validator function to use.
|
|
116
|
+
* @returns issues if validation failed, otherwise undefined.
|
|
117
|
+
*/
|
|
118
|
+
static validateAll<I, O>(input: I, schema?: StandardSchemaV1<I, O>, customValidator?: CustomValidatorFn<I>): ValidatorReturn;
|
|
119
|
+
/**
|
|
120
|
+
* Validates a single field within the input data using both a standard
|
|
121
|
+
* schema and a custom validator function, merging any issues found by
|
|
122
|
+
* either method. If there are issues related to the specified field,
|
|
123
|
+
* they are returned. Otherwise, nothing is returned. This method runs
|
|
124
|
+
* both validations in parallel.
|
|
125
|
+
*
|
|
126
|
+
* Note: `schema` and `customValidator` are both optional. If either the
|
|
127
|
+
* schema or custom validator is not provided, that validation is skipped.
|
|
128
|
+
* @see https://standardschema.dev/
|
|
129
|
+
*
|
|
130
|
+
* @param input The input data to validate.
|
|
131
|
+
* @param fieldName The name of the field to validate.
|
|
132
|
+
* @param schema Optional standard schema to validate against.
|
|
133
|
+
* @param customValidator Optional custom validator function to use.
|
|
134
|
+
* @returns The issues related to the specified field if validation failed,
|
|
135
|
+
* otherwise undefined.
|
|
136
|
+
*/
|
|
137
|
+
static validateFieldAll<I, O>(input: I, fieldName: string, schema?: StandardSchemaV1<I, O>, customValidator?: CustomValidatorFn<I>): ValidatorReturn;
|
|
138
|
+
/**
|
|
139
|
+
* Filters issues to those related to the specified field name.
|
|
140
|
+
* Supports both simple field names and dotted notation for nested fields.
|
|
141
|
+
*
|
|
142
|
+
* @param issues The issues to filter.
|
|
143
|
+
* @param fieldName The name of the field to filter by (e.g., "email" or
|
|
144
|
+
* "profile.contact.email").
|
|
145
|
+
* @returns The issues related to the specified field, or undefined if
|
|
146
|
+
* there are none.
|
|
147
|
+
*/
|
|
148
|
+
static filterFieldIssues(issues: Issues, fieldName: string): Issues | undefined;
|
|
149
|
+
}
|
|
150
|
+
export { StandardValidator };
|
|
151
|
+
export default StandardValidator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@frontile/forms/components/field-types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@frontile/forms/components/field";
|
|
@@ -15,7 +15,7 @@ class CheckboxGroup extends Component {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
static {
|
|
18
|
-
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{yield (component Checkbox name=@name onChange=@onChange size=@size) to=\"default\"}}\n </div>\n </FormControl>\n ", {
|
|
18
|
+
setComponentTemplate(precompileTemplate("\n <FormControl @size={{@size}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} @class={{this.classes.base class=@classes.base}} ...attributes as |c|>\n <c.Label @class={{this.classes.label class=@classes.label}}>\n {{@label}}\n </c.Label>\n <div class={{this.classes.optionsContainer class=@classes.optionsContainer}} data-orientation={{if @orientation @orientation \"vertical\"}}>\n {{yield (component Checkbox name=@name onChange=@onChange size=@size isDisabled=@isDisabled) to=\"default\"}}\n </div>\n </FormControl>\n ", {
|
|
19
19
|
strictMode: true,
|
|
20
20
|
scope: () => ({
|
|
21
21
|
FormControl,
|