@frontile/forms 0.17.0-beta.9 → 0.17.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.
- package/declarations/components/checkbox-group.d.ts +9 -8
- package/declarations/components/checkbox.d.ts +7 -6
- 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 -1
- package/declarations/components/form-description.d.ts +0 -1
- package/declarations/components/form-feedback.d.ts +0 -1
- package/declarations/components/form.d.ts +245 -10
- package/declarations/components/icons.d.ts +0 -1
- package/declarations/components/input.d.ts +17 -12
- package/declarations/components/label.d.ts +4 -5
- package/declarations/components/native-select.d.ts +26 -12
- package/declarations/components/radio-group.d.ts +7 -8
- package/declarations/components/radio.d.ts +7 -6
- package/declarations/components/select.d.ts +281 -25
- package/declarations/components/switch.d.ts +37 -33
- package/declarations/components/textarea.d.ts +8 -7
- package/declarations/index.d.ts +3 -1
- package/declarations/template-registry.d.ts +0 -1
- package/declarations/test-support.d.ts +0 -1
- package/declarations/utils/index.d.ts +1 -1
- 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-description.js.map +1 -1
- package/dist/components/form-feedback.js.map +1 -1
- package/dist/components/form.js +12 -42
- package/dist/components/form.js.map +1 -1
- package/dist/components/icons.js.map +1 -1
- package/dist/components/input.js +11 -5
- package/dist/components/input.js.map +1 -1
- package/dist/components/label.js.map +1 -1
- package/dist/components/native-select.js +42 -7
- package/dist/components/native-select.js.map +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 +229 -13
- 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/index-CeaQc-U7.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/{runtime-BPCpkOf1-BKOwiRJp.js → runtime-BPCpkOf1-B5Lbloj7.js} +2 -2
- package/dist/{runtime-BPCpkOf1-BKOwiRJp.js.map → runtime-BPCpkOf1-B5Lbloj7.js.map} +1 -1
- package/dist/test-support.js +2 -2
- package/dist/test-support.js.map +1 -1
- package/package.json +12 -8
- package/declarations/components/checkbox-group.d.ts.map +0 -1
- package/declarations/components/checkbox.d.ts.map +0 -1
- package/declarations/components/form-control.d.ts.map +0 -1
- package/declarations/components/form-description.d.ts.map +0 -1
- package/declarations/components/form-feedback.d.ts.map +0 -1
- package/declarations/components/form.d.ts.map +0 -1
- package/declarations/components/icons.d.ts.map +0 -1
- package/declarations/components/input.d.ts.map +0 -1
- package/declarations/components/label.d.ts.map +0 -1
- package/declarations/components/native-select.d.ts.map +0 -1
- package/declarations/components/radio-group.d.ts.map +0 -1
- package/declarations/components/radio.d.ts.map +0 -1
- package/declarations/components/select.d.ts.map +0 -1
- package/declarations/components/switch.d.ts.map +0 -1
- package/declarations/components/textarea.d.ts.map +0 -1
- package/declarations/index.d.ts.map +0 -1
- package/declarations/template-registry.d.ts.map +0 -1
- package/declarations/test-support.d.ts.map +0 -1
- package/declarations/utils/index.d.ts.map +0 -1
|
@@ -13,7 +13,9 @@ interface Args extends FormControlSharedArgs {
|
|
|
13
13
|
interface CheckboxGroupSignature {
|
|
14
14
|
Args: Args;
|
|
15
15
|
Blocks: {
|
|
16
|
-
default: [
|
|
16
|
+
default: [
|
|
17
|
+
Checkbox: WithBoundArgs<typeof Checkbox, 'name' | 'onChange' | 'isDisabled'>
|
|
18
|
+
];
|
|
17
19
|
};
|
|
18
20
|
Element: HTMLDivElement;
|
|
19
21
|
}
|
|
@@ -21,21 +23,20 @@ declare class CheckboxGroup extends Component<CheckboxGroupSignature> {
|
|
|
21
23
|
get classes(): {
|
|
22
24
|
base: (slotProps?: ({
|
|
23
25
|
size?: "sm" | "md" | "lg" | undefined;
|
|
24
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
26
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | ({
|
|
25
27
|
size?: "sm" | "md" | "lg" | undefined;
|
|
26
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
28
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
27
29
|
optionsContainer: (slotProps?: ({
|
|
28
30
|
size?: "sm" | "md" | "lg" | undefined;
|
|
29
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
31
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | ({
|
|
30
32
|
size?: "sm" | "md" | "lg" | undefined;
|
|
31
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
33
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
32
34
|
label: (slotProps?: ({
|
|
33
35
|
size?: "sm" | "md" | "lg" | undefined;
|
|
34
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
36
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | ({
|
|
35
37
|
size?: "sm" | "md" | "lg" | undefined;
|
|
36
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
38
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
37
39
|
} & {} & {};
|
|
38
40
|
}
|
|
39
41
|
export { CheckboxGroup, type CheckboxGroupSignature };
|
|
40
42
|
export default CheckboxGroup;
|
|
41
|
-
//# sourceMappingURL=checkbox-group.d.ts.map
|
|
@@ -7,6 +7,7 @@ interface Args extends FormControlSharedArgs {
|
|
|
7
7
|
size?: CheckboxVariants['size'];
|
|
8
8
|
classes?: SlotsToClasses<CheckboxSlots>;
|
|
9
9
|
onChange?: (value: boolean, event: Event) => void;
|
|
10
|
+
onBlur?: () => void;
|
|
10
11
|
}
|
|
11
12
|
interface CheckboxSignature {
|
|
12
13
|
Args: Args;
|
|
@@ -15,25 +16,25 @@ interface CheckboxSignature {
|
|
|
15
16
|
declare class Checkbox extends Component<CheckboxSignature> {
|
|
16
17
|
get isChecked(): boolean;
|
|
17
18
|
handleChange(event: Event): void;
|
|
19
|
+
handleBlur(): void;
|
|
18
20
|
get classes(): {
|
|
19
21
|
base: (slotProps?: ({
|
|
20
22
|
size?: "sm" | "md" | "lg" | undefined;
|
|
21
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
23
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
22
24
|
input: (slotProps?: ({
|
|
23
25
|
size?: "sm" | "md" | "lg" | undefined;
|
|
24
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
26
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
25
27
|
labelContainer: (slotProps?: ({
|
|
26
28
|
size?: "sm" | "md" | "lg" | undefined;
|
|
27
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
29
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
28
30
|
label: (slotProps?: ({
|
|
29
31
|
size?: "sm" | "md" | "lg" | undefined;
|
|
30
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
32
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
31
33
|
} & {
|
|
32
34
|
input: (slotProps?: ({
|
|
33
35
|
size?: "sm" | "md" | "lg" | undefined;
|
|
34
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
36
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
35
37
|
} & {};
|
|
36
38
|
}
|
|
37
39
|
export { Checkbox, type CheckboxSignature };
|
|
38
40
|
export default Checkbox;
|
|
39
|
-
//# sourceMappingURL=checkbox.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MaybeNamed } from '@glint/template/-private/signature';
|
|
2
|
+
import type { Invokable, NamedArgs, ComponentReturn } from '@glint/template/-private/integration';
|
|
3
|
+
export type WithBoundArgsForSignature<Sig extends {
|
|
4
|
+
Args: unknown;
|
|
5
|
+
Blocks?: unknown;
|
|
6
|
+
Element?: unknown;
|
|
7
|
+
}, BoundKeys extends keyof Sig['Args']> = Invokable<(...args: [
|
|
8
|
+
...positional: [],
|
|
9
|
+
...named: MaybeNamed<NamedArgs<Omit<Sig['Args'], BoundKeys> & Partial<Pick<Sig['Args'], BoundKeys>>>>
|
|
10
|
+
]) => ComponentReturn<Sig extends {
|
|
11
|
+
Blocks: infer B;
|
|
12
|
+
} ? B : {}, Sig extends {
|
|
13
|
+
Element: infer E;
|
|
14
|
+
} ? E : unknown>>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import Checkbox from './checkbox';
|
|
3
|
+
import CheckboxGroup from './checkbox-group';
|
|
4
|
+
import Input from './input';
|
|
5
|
+
import Radio from './radio';
|
|
6
|
+
import RadioGroup from './radio-group';
|
|
7
|
+
import Switch from './switch';
|
|
8
|
+
import Textarea from './textarea';
|
|
9
|
+
import type { WithBoundArgs } from '@glint/template';
|
|
10
|
+
import type { FormDataCompiled, FormErrors } from './form';
|
|
11
|
+
import type { SelectSignature } from './select';
|
|
12
|
+
import type { WithBoundArgsForSignature } from './field-types';
|
|
13
|
+
type BoundSingleSelect<S = unknown> = WithBoundArgsForSignature<SelectSignature<S>, 'name' | 'errors' | 'selectedKey' | 'onBlur' | 'isDisabled'>;
|
|
14
|
+
type BoundMultiSelect<S = unknown> = WithBoundArgsForSignature<SelectSignature<S>, 'selectionMode' | 'name' | 'errors' | 'selectedKeys' | 'onBlur' | 'isDisabled'>;
|
|
15
|
+
interface FieldSignature<T extends Record<string, unknown> = FormDataCompiled> {
|
|
16
|
+
Element: HTMLElement;
|
|
17
|
+
Args: {
|
|
18
|
+
/** The name of the form field. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The validation errors for the form, keyed by field name. */
|
|
21
|
+
errors?: FormErrors;
|
|
22
|
+
/** The form data as key/value pairs. */
|
|
23
|
+
formData?: T;
|
|
24
|
+
/** Whether the field should be disabled. */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** When to run validation. */
|
|
27
|
+
validateOn?: ('change' | 'input' | 'blur')[];
|
|
28
|
+
/** Function to validate a single field by name. */
|
|
29
|
+
validateField?: (data: T, name: string) => Promise<FormErrors | undefined>;
|
|
30
|
+
};
|
|
31
|
+
Blocks: {
|
|
32
|
+
default: [
|
|
33
|
+
{
|
|
34
|
+
Checkbox: WithBoundArgs<typeof Checkbox, 'name' | 'errors' | 'checked' | 'onChange' | 'onBlur' | 'isDisabled'>;
|
|
35
|
+
CheckboxGroup: WithBoundArgs<typeof CheckboxGroup, 'name' | 'errors' | 'isDisabled'>;
|
|
36
|
+
Input: WithBoundArgs<typeof Input, 'name' | 'errors' | 'value' | 'onChange' | 'onInput' | 'onBlur' | 'isDisabled'>;
|
|
37
|
+
Radio: WithBoundArgs<typeof Radio, 'name' | 'errors' | 'checkedValue' | 'onChange' | 'onBlur' | 'isDisabled'>;
|
|
38
|
+
RadioGroup: WithBoundArgs<typeof RadioGroup, 'name' | 'errors' | 'value' | 'onChange' | 'isDisabled'>;
|
|
39
|
+
SingleSelect: BoundSingleSelect;
|
|
40
|
+
MultiSelect: BoundMultiSelect;
|
|
41
|
+
Switch: WithBoundArgs<typeof Switch, 'name' | 'errors' | 'isSelected' | 'onChange' | 'onBlur' | 'isDisabled'>;
|
|
42
|
+
Textarea: WithBoundArgs<typeof Textarea, 'name' | 'errors' | 'value' | 'onChange' | 'onInput' | 'onBlur' | 'isDisabled'>;
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Field is a component wrapper that provides conveniences for form fields.
|
|
49
|
+
* It automatically binds the appropriate form errors by name to yielded
|
|
50
|
+
* components.
|
|
51
|
+
*/
|
|
52
|
+
declare class Field<T extends Record<string, unknown> = FormDataCompiled> extends Component<FieldSignature<T>> {
|
|
53
|
+
/**
|
|
54
|
+
* Returns the validation errors for the field.
|
|
55
|
+
* Supports dotted field names (e.g., 'profile.email').
|
|
56
|
+
*/
|
|
57
|
+
get fieldErrors(): string | string[] | undefined;
|
|
58
|
+
/** The events on which validation should run. Defaults to ['change']. */
|
|
59
|
+
get validateOn(): ('change' | 'input' | 'blur')[];
|
|
60
|
+
/**
|
|
61
|
+
* Returns the current value for the field from formData.
|
|
62
|
+
* Supports both flat and dotted field names (e.g., 'email' or 'profile.email').
|
|
63
|
+
* Uses Ember's get() which handles both flat keys and dotted paths.
|
|
64
|
+
*/
|
|
65
|
+
get fieldValue(): T[string] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Validates the field by calling the validateField function passed in args.
|
|
68
|
+
*/
|
|
69
|
+
validateField(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Validates the field on change if change validation is enabled.
|
|
72
|
+
*/
|
|
73
|
+
handleChange(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Validates the field on input if input validation is enabled.
|
|
76
|
+
* Debounces validation to avoid excessive validation calls on every keystroke.
|
|
77
|
+
*/
|
|
78
|
+
handleInput(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Validates the field on blur if blur validation is enabled.
|
|
81
|
+
*/
|
|
82
|
+
handleBlur(): void;
|
|
83
|
+
}
|
|
84
|
+
export { Field, type FieldSignature };
|
|
85
|
+
export default Field;
|
|
@@ -9,6 +9,7 @@ interface FormControlSharedArgs {
|
|
|
9
9
|
description?: string;
|
|
10
10
|
errors?: string[] | string;
|
|
11
11
|
isInvalid?: boolean;
|
|
12
|
+
isDisabled?: boolean;
|
|
12
13
|
}
|
|
13
14
|
interface Args extends FormControlSharedArgs {
|
|
14
15
|
id?: string;
|
|
@@ -44,4 +45,3 @@ declare class FormControl extends Component<FormControlSignature> {
|
|
|
44
45
|
}
|
|
45
46
|
export { FormControl, type FormControlSignature, type FormControlSharedArgs };
|
|
46
47
|
export default FormControl;
|
|
47
|
-
//# sourceMappingURL=form-control.d.ts.map
|
|
@@ -1,19 +1,254 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { dataFrom } from 'form-data-utils';
|
|
3
|
+
import { Field } from './field';
|
|
4
|
+
import type { WithBoundArgs } from '@glint/template';
|
|
5
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import type { CustomValidatorFn } from '../utils/standard-validator';
|
|
7
|
+
import type Owner from '@ember/owner';
|
|
8
|
+
/** The form data as key/value pairs. */
|
|
9
|
+
type FormDataCompiled = ReturnType<typeof dataFrom>;
|
|
10
|
+
/** The validation errors for the form, keyed by field name. */
|
|
11
|
+
type FormErrors = Record<string, string | string[] | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* The data passed to `onChange` and `onSubmit` callbacks, which is similar
|
|
14
|
+
* to `FormContext` but also includes the form data.
|
|
15
|
+
*/
|
|
16
|
+
type FormResultData<T = FormDataCompiled> = {
|
|
17
|
+
/** The form data as key/value pairs. */
|
|
18
|
+
data: T;
|
|
19
|
+
/** Whether the form is valid (i.e. has no validation errors). */
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
/** Whether the form is invalid (i.e. has validation errors). */
|
|
22
|
+
isInvalid: boolean;
|
|
23
|
+
/** The current form validation errors. */
|
|
24
|
+
errors: FormErrors;
|
|
25
|
+
/**
|
|
26
|
+
* The set of fields that have changed from their initial values.
|
|
27
|
+
* For flat data structures: contains top-level keys (e.g., "firstName", "email")
|
|
28
|
+
* For nested data structures: contains dotted paths (e.g., "user.name.first", "profile.email")
|
|
29
|
+
*/
|
|
30
|
+
dirty: Set<string>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The context yielded to the default block of the `Form` component.
|
|
34
|
+
*/
|
|
35
|
+
interface FormContext<T = FormDataCompiled> {
|
|
36
|
+
/** The form data as key/value pairs. */
|
|
37
|
+
data?: T;
|
|
38
|
+
/** Whether the form is currently submitting. */
|
|
39
|
+
isLoading: boolean;
|
|
40
|
+
/** Whether the form is valid (i.e. has no validation errors). */
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
/** Whether the form is invalid (i.e. has validation errors). */
|
|
43
|
+
isInvalid: boolean;
|
|
44
|
+
/** The current form validation errors. */
|
|
45
|
+
errors: FormErrors;
|
|
46
|
+
/**
|
|
47
|
+
* The set of fields that have changed from their initial values.
|
|
48
|
+
* For flat data structures: contains top-level keys (e.g., "firstName", "email")
|
|
49
|
+
* For nested data structures: contains dotted paths (e.g., "user.name.first", "profile.email")
|
|
50
|
+
*/
|
|
51
|
+
dirty: Set<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Resets the form to its initial state.
|
|
54
|
+
* Clears all form fields, validation errors, and dirty tracking.
|
|
55
|
+
*/
|
|
56
|
+
reset: () => void;
|
|
57
|
+
/** The `Field` component, with args bound. */
|
|
58
|
+
Field: WithBoundArgs<typeof Field, 'errors' | 'formData' | 'disabled' | 'validateOn' | 'validateField'>;
|
|
59
|
+
}
|
|
60
|
+
interface FormSignature<T = FormDataCompiled> {
|
|
5
61
|
Element: HTMLFormElement;
|
|
6
62
|
Args: {
|
|
7
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The standard schema to validate form data against.
|
|
65
|
+
*/
|
|
66
|
+
schema?: StandardSchemaV1<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Optional custom validation function. A custom validator should return
|
|
69
|
+
* an array of Standard Schema issues, or `undefined` if there are none.
|
|
70
|
+
* This function may be async or sync.
|
|
71
|
+
*/
|
|
72
|
+
validate?: CustomValidatorFn<T>;
|
|
73
|
+
/**
|
|
74
|
+
* When to run validation.
|
|
75
|
+
*/
|
|
76
|
+
validateOn?: ('change' | 'input' | 'blur' | 'submit')[];
|
|
77
|
+
/**
|
|
78
|
+
* The initial form data as key/value pairs.
|
|
79
|
+
* This is primarily useful for setting default values in the form.
|
|
80
|
+
* This object receives changes as the user interacts with the form.
|
|
81
|
+
*/
|
|
82
|
+
data?: T;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the entire form and all its fields should be disabled. This only
|
|
85
|
+
* applies when using the yielded `Field` component.
|
|
86
|
+
*/
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Optional callback invoked on input changes within the form.
|
|
90
|
+
* @param result - The current form result data.
|
|
91
|
+
* @param event - The input event that triggered the change.
|
|
92
|
+
* @returns A promise or void.
|
|
93
|
+
*/
|
|
94
|
+
onChange?: (result: FormResultData<T>, event: Event) => Promise<void> | void;
|
|
95
|
+
/**
|
|
96
|
+
* Callback invoked on form submission. If `onSubmit` returns a promise,
|
|
97
|
+
* the form will be marked as `isLoading` until the promise resolves.
|
|
98
|
+
* @param result - The current form result data.
|
|
99
|
+
* @param event - The submit event that triggered the submission.
|
|
100
|
+
* @returns A promise or void.
|
|
101
|
+
*/
|
|
102
|
+
onSubmit: (result: FormResultData<T>, event: SubmitEvent) => Promise<void> | void;
|
|
103
|
+
/**
|
|
104
|
+
* Optional callback invoked when validation errors occur on form submission.
|
|
105
|
+
* @param errors - The validation errors found.
|
|
106
|
+
* @param data - The form data that was validated.
|
|
107
|
+
* @param event - The submit event that triggered the validation.
|
|
108
|
+
* @returns A promise or void.
|
|
109
|
+
*/
|
|
110
|
+
onError?: (errors: FormErrors, data: T, event: SubmitEvent) => Promise<void> | void;
|
|
8
111
|
};
|
|
9
112
|
Blocks: {
|
|
10
|
-
default: [];
|
|
113
|
+
default: [FormContext<T>];
|
|
11
114
|
};
|
|
12
115
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
116
|
+
/**
|
|
117
|
+
* A form component that handles form submissions and input changes.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```hbs
|
|
121
|
+
* <Form
|
|
122
|
+
* @data={{this.formData}}
|
|
123
|
+
* @schema={{this.schema}}
|
|
124
|
+
* @validate={{this.customValidator}}
|
|
125
|
+
* @onSubmit={{this.onSubmit}}
|
|
126
|
+
* @onChange={{this.onChange}}
|
|
127
|
+
* as |form|
|
|
128
|
+
* >
|
|
129
|
+
* <form.Field name="firstName" as |field|>
|
|
130
|
+
* <field.Input />
|
|
131
|
+
* </form.Field>
|
|
132
|
+
* <form.Field name="lastName" as |field|>
|
|
133
|
+
* <field.Input />
|
|
134
|
+
* </form.Field>
|
|
135
|
+
* <button type="submit" disabled={{form.isLoading}}>
|
|
136
|
+
* {{#if form.isLoading}}Submitting...{{else}}Submit{{/if}}
|
|
137
|
+
* </button>
|
|
138
|
+
* </Form>
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare class Form<T = FormDataCompiled> extends Component<FormSignature<T>> {
|
|
142
|
+
/** Whether the form is currently submitting. */
|
|
143
|
+
isLoading: boolean;
|
|
144
|
+
/** The current form validation errors. */
|
|
145
|
+
errors: FormErrors;
|
|
146
|
+
/** The current uncontrolled form data. */
|
|
147
|
+
uncontrolledData?: T;
|
|
148
|
+
/**
|
|
149
|
+
* Flattened snapshot of initial data for dirty field comparison.
|
|
150
|
+
* Stored in flattened form regardless of whether source data is nested or flat.
|
|
151
|
+
*/
|
|
152
|
+
initialDataSnapshot?: Record<string, unknown>;
|
|
153
|
+
/**
|
|
154
|
+
* The set of fields that have changed from their initial values.
|
|
155
|
+
* For flat data structures: contains top-level keys (e.g., "firstName", "email")
|
|
156
|
+
* For nested data structures: contains dotted paths (e.g., "user.name.first", "profile.email")
|
|
157
|
+
*/
|
|
158
|
+
dirty: Set<string>;
|
|
159
|
+
/** Reference to the form element. */
|
|
160
|
+
element: {
|
|
161
|
+
"__#1@#private": any;
|
|
162
|
+
current: HTMLFormElement | undefined;
|
|
163
|
+
setup: import("ember-modifier").FunctionBasedModifier<{
|
|
164
|
+
Args: {
|
|
165
|
+
Positional: unknown[];
|
|
166
|
+
Named: import("ember-modifier/-private/signature").EmptyObject;
|
|
167
|
+
};
|
|
168
|
+
Element: HTMLFormElement;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Creates a new instance of the Form component.
|
|
173
|
+
* Initializes internal state based on provided args.
|
|
174
|
+
* @param owner - The owner of the component.
|
|
175
|
+
* @param args - The arguments passed to the component.
|
|
176
|
+
*/
|
|
177
|
+
constructor(owner: Owner, args: FormSignature<T>['Args']);
|
|
178
|
+
/** Whether the form is valid (i.e. has no validation errors). */
|
|
179
|
+
get isValid(): boolean;
|
|
180
|
+
/** Whether the form is invalid (i.e. has validation errors). */
|
|
181
|
+
get isInvalid(): boolean;
|
|
182
|
+
/** Whether the form is controlled (`onChange` is provided). */
|
|
183
|
+
get isControlled(): boolean;
|
|
184
|
+
/** The events on which validation should run. */
|
|
185
|
+
get validateOn(): ('change' | 'input' | 'blur' | 'submit')[];
|
|
186
|
+
/** The events on which field-level validation should run. */
|
|
187
|
+
get fieldValidateOn(): ('change' | 'input' | 'blur')[];
|
|
188
|
+
/** The current form data, from args if controlled, or internal state if uncontrolled. */
|
|
189
|
+
get currentData(): T | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Validates data against the provided schema using StandardValidator.
|
|
192
|
+
* Updates the `errors` property with any validation errors found.
|
|
193
|
+
*
|
|
194
|
+
* @param data - The form data to validate.
|
|
195
|
+
* @returns A promise that resolves to the validation errors, if any.
|
|
196
|
+
*/
|
|
197
|
+
validate(data: T): Promise<FormErrors | undefined>;
|
|
198
|
+
/**
|
|
199
|
+
* Validates a single field against the provided schema using
|
|
200
|
+
* StandardValidator. Updates the `errors` property with any validation
|
|
201
|
+
* errors found for the field. If the field had previous errors but
|
|
202
|
+
* is now valid, those errors are cleared.
|
|
203
|
+
*
|
|
204
|
+
* @param data - The form data to validate against.
|
|
205
|
+
* @param name - The name of the field to validate.
|
|
206
|
+
* @returns A promise that resolves to errors for the field, if any.
|
|
207
|
+
*/
|
|
208
|
+
validateField(data: T, name: string): Promise<FormErrors | undefined>;
|
|
209
|
+
/**
|
|
210
|
+
* Computes which fields have changed from their initial values.
|
|
211
|
+
* Uses deep comparison for consistency across flat and nested structures.
|
|
212
|
+
* This is a pure function with no side effects.
|
|
213
|
+
*
|
|
214
|
+
* @param data - The current form data.
|
|
215
|
+
* @returns A set of field names that have changed.
|
|
216
|
+
*/
|
|
217
|
+
computeDirtyFields(data: T): Set<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Builds the form result data object to pass to callbacks.
|
|
220
|
+
* Also updates the dirty state as a side effect.
|
|
221
|
+
*
|
|
222
|
+
* @param data - The current form data.
|
|
223
|
+
* @returns The form result data object.
|
|
224
|
+
*/
|
|
225
|
+
buildFormResultData(data: T): FormResultData<T>;
|
|
226
|
+
/**
|
|
227
|
+
* Handles the `input` event on the form element.
|
|
228
|
+
* Calls the `onChange` callback with the current form data if provided.
|
|
229
|
+
* Automatically unflattens dotted field names to nested structure.
|
|
230
|
+
*/
|
|
231
|
+
handleInput(event: Event): void;
|
|
232
|
+
/**
|
|
233
|
+
* Handles the `submit` event on the form element.
|
|
234
|
+
* Prevents the default form submission and calls the `onSubmit` callback
|
|
235
|
+
* with the current form data. Manages the `isLoading` state during the
|
|
236
|
+
* submission process. Automatically unflattens dotted field names to nested structure.
|
|
237
|
+
*/
|
|
238
|
+
handleSubmit(event: SubmitEvent): Promise<void>;
|
|
239
|
+
/**
|
|
240
|
+
* Handles the `reset` event on the form element.
|
|
241
|
+
* Clears validation errors and dirty tracking.
|
|
242
|
+
* Restores the form data to its initial state.
|
|
243
|
+
* Calls `onChange` if the form is controlled to let parent update state.
|
|
244
|
+
*/
|
|
245
|
+
handleReset(event: Event): void;
|
|
246
|
+
/**
|
|
247
|
+
* Resets the form to its initial state.
|
|
248
|
+
* This method calls the native form reset() to clear all form controls,
|
|
249
|
+
* triggering a `reset` event that is handled in `handleReset`.
|
|
250
|
+
*/
|
|
251
|
+
reset(): void;
|
|
16
252
|
}
|
|
17
|
-
export { Form, type FormSignature, type FormResultData };
|
|
253
|
+
export { Form, type FormContext, type FormSignature, type FormDataCompiled, type FormResultData, type FormErrors };
|
|
18
254
|
export default Form;
|
|
19
|
-
//# sourceMappingURL=form.d.ts.map
|
|
@@ -5,4 +5,3 @@ declare const IconChevronUpDown: TOC<{
|
|
|
5
5
|
export { IconChevronUpDown };
|
|
6
6
|
declare const _default: import("@ember/component/template-only").TemplateOnlyComponent<never> & (abstract new () => import("@glint/template/-private/integration").InvokableInstance<() => import("@glint/template/-private/integration").ComponentReturn<{}>> & import("@glint/template/-private/integration").HasContext<import("@glint/template/-private/integration").TemplateContext<void, {}, {}, void>>);
|
|
7
7
|
export default _default;
|
|
8
|
-
//# sourceMappingURL=icons.d.ts.map
|
|
@@ -33,6 +33,10 @@ interface Args extends FormControlSharedArgs {
|
|
|
33
33
|
* Callback when onchange is triggered
|
|
34
34
|
*/
|
|
35
35
|
onChange?: (value: string, event?: InputEvent) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Callback when onblur is triggered
|
|
38
|
+
*/
|
|
39
|
+
onBlur?: () => void;
|
|
36
40
|
}
|
|
37
41
|
interface InputSignature {
|
|
38
42
|
Args: Args;
|
|
@@ -45,7 +49,8 @@ interface InputSignature {
|
|
|
45
49
|
declare class Input extends Component<InputSignature> {
|
|
46
50
|
uncontrolledValue: string;
|
|
47
51
|
inputRef: {
|
|
48
|
-
|
|
52
|
+
"__#1@#private": any;
|
|
53
|
+
current: HTMLInputElement | undefined;
|
|
49
54
|
setup: import("ember-modifier").FunctionBasedModifier<{
|
|
50
55
|
Args: {
|
|
51
56
|
Positional: unknown[];
|
|
@@ -59,6 +64,7 @@ declare class Input extends Component<InputSignature> {
|
|
|
59
64
|
get type(): string;
|
|
60
65
|
handleOnInput(event: Event): void;
|
|
61
66
|
handleOnChange(event: Event): void;
|
|
67
|
+
handleOnBlur(): void;
|
|
62
68
|
clearValue(): void;
|
|
63
69
|
get isClearable(): boolean;
|
|
64
70
|
get classes(): {
|
|
@@ -68,35 +74,35 @@ declare class Input extends Component<InputSignature> {
|
|
|
68
74
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
69
75
|
hasStartContent?: boolean | undefined;
|
|
70
76
|
hasEndContent?: boolean | undefined;
|
|
71
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
77
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
72
78
|
innerContainer: (slotProps?: ({
|
|
73
79
|
size?: "sm" | "md" | "lg" | undefined;
|
|
74
80
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
75
81
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
76
82
|
hasStartContent?: boolean | undefined;
|
|
77
83
|
hasEndContent?: boolean | undefined;
|
|
78
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
84
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
79
85
|
startContent: (slotProps?: ({
|
|
80
86
|
size?: "sm" | "md" | "lg" | undefined;
|
|
81
87
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
82
88
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
83
89
|
hasStartContent?: boolean | undefined;
|
|
84
90
|
hasEndContent?: boolean | undefined;
|
|
85
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
91
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
86
92
|
endContent: (slotProps?: ({
|
|
87
93
|
size?: "sm" | "md" | "lg" | undefined;
|
|
88
94
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
89
95
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
90
96
|
hasStartContent?: boolean | undefined;
|
|
91
97
|
hasEndContent?: boolean | undefined;
|
|
92
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
98
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
93
99
|
input: (slotProps?: ({
|
|
94
100
|
size?: "sm" | "md" | "lg" | undefined;
|
|
95
101
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
96
102
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
97
103
|
hasStartContent?: boolean | undefined;
|
|
98
104
|
hasEndContent?: boolean | undefined;
|
|
99
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
105
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
100
106
|
} & {
|
|
101
107
|
base: (slotProps?: ({
|
|
102
108
|
size?: "sm" | "md" | "lg" | undefined;
|
|
@@ -104,37 +110,36 @@ declare class Input extends Component<InputSignature> {
|
|
|
104
110
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
105
111
|
hasStartContent?: boolean | undefined;
|
|
106
112
|
hasEndContent?: boolean | undefined;
|
|
107
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
113
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
108
114
|
innerContainer: (slotProps?: ({
|
|
109
115
|
size?: "sm" | "md" | "lg" | undefined;
|
|
110
116
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
111
117
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
112
118
|
hasStartContent?: boolean | undefined;
|
|
113
119
|
hasEndContent?: boolean | undefined;
|
|
114
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
120
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
115
121
|
startContent: (slotProps?: ({
|
|
116
122
|
size?: "sm" | "md" | "lg" | undefined;
|
|
117
123
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
118
124
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
119
125
|
hasStartContent?: boolean | undefined;
|
|
120
126
|
hasEndContent?: boolean | undefined;
|
|
121
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
127
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
122
128
|
endContent: (slotProps?: ({
|
|
123
129
|
size?: "sm" | "md" | "lg" | undefined;
|
|
124
130
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
125
131
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
126
132
|
hasStartContent?: boolean | undefined;
|
|
127
133
|
hasEndContent?: boolean | undefined;
|
|
128
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
134
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
129
135
|
input: (slotProps?: ({
|
|
130
136
|
size?: "sm" | "md" | "lg" | undefined;
|
|
131
137
|
startContentPointerEvents?: "none" | "auto" | undefined;
|
|
132
138
|
endContentPointerEvents?: "none" | "auto" | undefined;
|
|
133
139
|
hasStartContent?: boolean | undefined;
|
|
134
140
|
hasEndContent?: boolean | undefined;
|
|
135
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
141
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
136
142
|
} & {};
|
|
137
143
|
}
|
|
138
144
|
export { Input, type InputSignature };
|
|
139
145
|
export default Input;
|
|
140
|
-
//# sourceMappingURL=input.d.ts.map
|
|
@@ -23,19 +23,18 @@ declare class Label extends Component<LabelSignature> {
|
|
|
23
23
|
get classes(): {
|
|
24
24
|
base: (slotProps?: ({
|
|
25
25
|
size?: "sm" | "md" | "lg" | undefined;
|
|
26
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
26
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
27
27
|
asterisk: (slotProps?: ({
|
|
28
28
|
size?: "sm" | "md" | "lg" | undefined;
|
|
29
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
29
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
30
30
|
} & {
|
|
31
31
|
base: (slotProps?: ({
|
|
32
32
|
size?: "sm" | "md" | "lg" | undefined;
|
|
33
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
33
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
34
34
|
asterisk: (slotProps?: ({
|
|
35
35
|
size?: "sm" | "md" | "lg" | undefined;
|
|
36
|
-
} & import("tailwind-variants").ClassProp<import("tailwind-
|
|
36
|
+
} & import("tailwind-variants").ClassProp<import("tailwind-variants").ClassValue>) | undefined) => string;
|
|
37
37
|
} & {};
|
|
38
38
|
}
|
|
39
39
|
export { Label, type LabelSignature };
|
|
40
40
|
export default Label;
|
|
41
|
-
//# sourceMappingURL=label.d.ts.map
|