@radix-ui/react-form 0.1.0-rc.2 → 0.1.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,465 +1,483 @@
1
1
  "use strict";
2
2
  "use client";
3
- (() => {
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
- }) : x)(function(x) {
13
- if (typeof require !== "undefined") return require.apply(this, arguments);
14
- throw Error('Dynamic require of "' + x + '" is not supported');
15
- });
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
30
 
33
- // packages/react/form/src/Form.tsx
34
- var React = __toESM(__require("react"));
35
- var import_primitive = __require("@radix-ui/primitive");
36
- var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
37
- var import_react_context = __require("@radix-ui/react-context");
38
- var import_react_id = __require("@radix-ui/react-id");
39
- var import_react_label = __require("@radix-ui/react-label");
40
- var import_react_primitive = __require("@radix-ui/react-primitive");
41
- var import_jsx_runtime = __require("react/jsx-runtime");
42
- var [createFormContext, createFormScope] = (0, import_react_context.createContextScope)("Form");
43
- var FORM_NAME = "Form";
44
- var [ValidationProvider, useValidationContext] = createFormContext(FORM_NAME);
45
- var [AriaDescriptionProvider, useAriaDescriptionContext] = createFormContext(FORM_NAME);
46
- var Form = React.forwardRef(
47
- (props, forwardedRef) => {
48
- const { __scopeForm, onClearServerErrors = () => {
49
- }, ...rootProps } = props;
50
- const formRef = React.useRef(null);
51
- const composedFormRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, formRef);
52
- const [validityMap, setValidityMap] = React.useState({});
53
- const getFieldValidity = React.useCallback(
54
- (fieldName) => validityMap[fieldName],
55
- [validityMap]
56
- );
57
- const handleFieldValidityChange = React.useCallback(
58
- (fieldName, validity) => setValidityMap((prevValidityMap) => ({
59
- ...prevValidityMap,
60
- [fieldName]: { ...prevValidityMap[fieldName] ?? {}, ...validity }
61
- })),
62
- []
63
- );
64
- const handleFieldValiditionClear = React.useCallback((fieldName) => {
65
- setValidityMap((prevValidityMap) => ({ ...prevValidityMap, [fieldName]: void 0 }));
66
- setCustomErrorsMap((prevCustomErrorsMap) => ({ ...prevCustomErrorsMap, [fieldName]: {} }));
67
- }, []);
68
- const [customMatcherEntriesMap, setCustomMatcherEntriesMap] = React.useState({});
69
- const getFieldCustomMatcherEntries = React.useCallback(
70
- (fieldName) => customMatcherEntriesMap[fieldName] ?? [],
71
- [customMatcherEntriesMap]
72
- );
73
- const handleFieldCustomMatcherAdd = React.useCallback((fieldName, matcherEntry) => {
74
- setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap) => ({
75
- ...prevCustomMatcherEntriesMap,
76
- [fieldName]: [...prevCustomMatcherEntriesMap[fieldName] ?? [], matcherEntry]
77
- }));
78
- }, []);
79
- const handleFieldCustomMatcherRemove = React.useCallback((fieldName, matcherEntryId) => {
80
- setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap) => ({
81
- ...prevCustomMatcherEntriesMap,
82
- [fieldName]: (prevCustomMatcherEntriesMap[fieldName] ?? []).filter(
83
- (matcherEntry) => matcherEntry.id !== matcherEntryId
84
- )
85
- }));
86
- }, []);
87
- const [customErrorsMap, setCustomErrorsMap] = React.useState({});
88
- const getFieldCustomErrors = React.useCallback(
89
- (fieldName) => customErrorsMap[fieldName] ?? {},
90
- [customErrorsMap]
91
- );
92
- const handleFieldCustomErrorsChange = React.useCallback((fieldName, customErrors) => {
93
- setCustomErrorsMap((prevCustomErrorsMap) => ({
94
- ...prevCustomErrorsMap,
95
- [fieldName]: { ...prevCustomErrorsMap[fieldName] ?? {}, ...customErrors }
96
- }));
97
- }, []);
98
- const [messageIdsMap, setMessageIdsMap] = React.useState({});
99
- const handleFieldMessageIdAdd = React.useCallback((fieldName, id) => {
100
- setMessageIdsMap((prevMessageIdsMap) => {
101
- const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]).add(id);
102
- return { ...prevMessageIdsMap, [fieldName]: fieldDescriptionIds };
103
- });
104
- }, []);
105
- const handleFieldMessageIdRemove = React.useCallback((fieldName, id) => {
106
- setMessageIdsMap((prevMessageIdsMap) => {
107
- const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]);
108
- fieldDescriptionIds.delete(id);
109
- return { ...prevMessageIdsMap, [fieldName]: fieldDescriptionIds };
110
- });
111
- }, []);
112
- const getFieldDescription = React.useCallback(
113
- (fieldName) => Array.from(messageIdsMap[fieldName] ?? []).join(" ") || void 0,
114
- [messageIdsMap]
115
- );
116
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
- ValidationProvider,
118
- {
119
- scope: __scopeForm,
120
- getFieldValidity,
121
- onFieldValidityChange: handleFieldValidityChange,
122
- getFieldCustomMatcherEntries,
123
- onFieldCustomMatcherEntryAdd: handleFieldCustomMatcherAdd,
124
- onFieldCustomMatcherEntryRemove: handleFieldCustomMatcherRemove,
125
- getFieldCustomErrors,
126
- onFieldCustomErrorsChange: handleFieldCustomErrorsChange,
127
- onFieldValiditionClear: handleFieldValiditionClear,
128
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
- AriaDescriptionProvider,
130
- {
131
- scope: __scopeForm,
132
- onFieldMessageIdAdd: handleFieldMessageIdAdd,
133
- onFieldMessageIdRemove: handleFieldMessageIdRemove,
134
- getFieldDescription,
135
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
136
- import_react_primitive.Primitive.form,
137
- {
138
- ...rootProps,
139
- ref: composedFormRef,
140
- onInvalid: (0, import_primitive.composeEventHandlers)(props.onInvalid, (event) => {
141
- const firstInvalidControl = getFirstInvalidControl(event.currentTarget);
142
- if (firstInvalidControl === event.target) firstInvalidControl.focus();
143
- event.preventDefault();
144
- }),
145
- onSubmit: (0, import_primitive.composeEventHandlers)(props.onSubmit, onClearServerErrors, {
146
- checkForDefaultPrevented: false
147
- }),
148
- onReset: (0, import_primitive.composeEventHandlers)(props.onReset, onClearServerErrors)
149
- }
150
- )
151
- }
152
- )
153
- }
154
- );
155
- }
156
- );
157
- Form.displayName = FORM_NAME;
158
- var FIELD_NAME = "FormField";
159
- var [FormFieldProvider, useFormFieldContext] = createFormContext(FIELD_NAME);
160
- var FormField = React.forwardRef(
161
- (props, forwardedRef) => {
162
- const { __scopeForm, name, serverInvalid = false, ...fieldProps } = props;
163
- const validationContext = useValidationContext(FIELD_NAME, __scopeForm);
164
- const validity = validationContext.getFieldValidity(name);
165
- const id = (0, import_react_id.useId)();
166
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormFieldProvider, { scope: __scopeForm, id, name, serverInvalid, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
- import_react_primitive.Primitive.div,
168
- {
169
- "data-valid": getValidAttribute(validity, serverInvalid),
170
- "data-invalid": getInvalidAttribute(validity, serverInvalid),
171
- ...fieldProps,
172
- ref: forwardedRef
173
- }
174
- ) });
175
- }
176
- );
177
- FormField.displayName = FIELD_NAME;
178
- var LABEL_NAME = "FormLabel";
179
- var FormLabel = React.forwardRef(
180
- (props, forwardedRef) => {
181
- const { __scopeForm, ...labelProps } = props;
182
- const validationContext = useValidationContext(LABEL_NAME, __scopeForm);
183
- const fieldContext = useFormFieldContext(LABEL_NAME, __scopeForm);
184
- const htmlFor = labelProps.htmlFor || fieldContext.id;
185
- const validity = validationContext.getFieldValidity(fieldContext.name);
186
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
187
- import_react_label.Label,
188
- {
189
- "data-valid": getValidAttribute(validity, fieldContext.serverInvalid),
190
- "data-invalid": getInvalidAttribute(validity, fieldContext.serverInvalid),
191
- ...labelProps,
192
- ref: forwardedRef,
193
- htmlFor
194
- }
195
- );
196
- }
197
- );
198
- FormLabel.displayName = LABEL_NAME;
199
- var CONTROL_NAME = "FormControl";
200
- var FormControl = React.forwardRef(
201
- (props, forwardedRef) => {
202
- const { __scopeForm, ...controlProps } = props;
203
- const validationContext = useValidationContext(CONTROL_NAME, __scopeForm);
204
- const fieldContext = useFormFieldContext(CONTROL_NAME, __scopeForm);
205
- const ariaDescriptionContext = useAriaDescriptionContext(CONTROL_NAME, __scopeForm);
206
- const ref = React.useRef(null);
207
- const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
208
- const name = controlProps.name || fieldContext.name;
209
- const id = controlProps.id || fieldContext.id;
210
- const customMatcherEntries = validationContext.getFieldCustomMatcherEntries(name);
211
- const { onFieldValidityChange, onFieldCustomErrorsChange, onFieldValiditionClear } = validationContext;
212
- const updateControlValidity = React.useCallback(
213
- async (control) => {
214
- if (hasBuiltInError(control.validity)) {
215
- const controlValidity2 = validityStateToObject(control.validity);
216
- onFieldValidityChange(name, controlValidity2);
217
- return;
218
- }
219
- const formData = control.form ? new FormData(control.form) : new FormData();
220
- const matcherArgs = [control.value, formData];
221
- const syncCustomMatcherEntries = [];
222
- const ayncCustomMatcherEntries = [];
223
- customMatcherEntries.forEach((customMatcherEntry) => {
224
- if (isAsyncCustomMatcherEntry(customMatcherEntry, matcherArgs)) {
225
- ayncCustomMatcherEntries.push(customMatcherEntry);
226
- } else if (isSyncCustomMatcherEntry(customMatcherEntry)) {
227
- syncCustomMatcherEntries.push(customMatcherEntry);
228
- }
229
- });
230
- const syncCustomErrors = syncCustomMatcherEntries.map(({ id: id2, match }) => {
231
- return [id2, match(...matcherArgs)];
232
- });
233
- const syncCustomErrorsById = Object.fromEntries(syncCustomErrors);
234
- const hasSyncCustomErrors = Object.values(syncCustomErrorsById).some(Boolean);
235
- const hasCustomError = hasSyncCustomErrors;
236
- control.setCustomValidity(hasCustomError ? DEFAULT_INVALID_MESSAGE : "");
237
- const controlValidity = validityStateToObject(control.validity);
238
- onFieldValidityChange(name, controlValidity);
239
- onFieldCustomErrorsChange(name, syncCustomErrorsById);
240
- if (!hasSyncCustomErrors && ayncCustomMatcherEntries.length > 0) {
241
- const promisedCustomErrors = ayncCustomMatcherEntries.map(
242
- ({ id: id2, match }) => match(...matcherArgs).then((matches) => [id2, matches])
243
- );
244
- const asyncCustomErrors = await Promise.all(promisedCustomErrors);
245
- const asyncCustomErrorsById = Object.fromEntries(asyncCustomErrors);
246
- const hasAsyncCustomErrors = Object.values(asyncCustomErrorsById).some(Boolean);
247
- const hasCustomError2 = hasAsyncCustomErrors;
248
- control.setCustomValidity(hasCustomError2 ? DEFAULT_INVALID_MESSAGE : "");
249
- const controlValidity2 = validityStateToObject(control.validity);
250
- onFieldValidityChange(name, controlValidity2);
251
- onFieldCustomErrorsChange(name, asyncCustomErrorsById);
31
+ // packages/react/form/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ Control: () => Control,
35
+ Field: () => Field,
36
+ Form: () => Form,
37
+ FormControl: () => FormControl,
38
+ FormField: () => FormField,
39
+ FormLabel: () => FormLabel,
40
+ FormMessage: () => FormMessage,
41
+ FormSubmit: () => FormSubmit,
42
+ FormValidityState: () => FormValidityState,
43
+ Label: () => Label,
44
+ Message: () => Message,
45
+ Root: () => Root,
46
+ Submit: () => Submit,
47
+ ValidityState: () => ValidityState,
48
+ createFormScope: () => createFormScope
49
+ });
50
+ module.exports = __toCommonJS(src_exports);
51
+
52
+ // packages/react/form/src/Form.tsx
53
+ var React = __toESM(require("react"));
54
+ var import_primitive = require("@radix-ui/primitive");
55
+ var import_react_compose_refs = require("@radix-ui/react-compose-refs");
56
+ var import_react_context = require("@radix-ui/react-context");
57
+ var import_react_id = require("@radix-ui/react-id");
58
+ var import_react_label = require("@radix-ui/react-label");
59
+ var import_react_primitive = require("@radix-ui/react-primitive");
60
+ var import_jsx_runtime = require("react/jsx-runtime");
61
+ var [createFormContext, createFormScope] = (0, import_react_context.createContextScope)("Form");
62
+ var FORM_NAME = "Form";
63
+ var [ValidationProvider, useValidationContext] = createFormContext(FORM_NAME);
64
+ var [AriaDescriptionProvider, useAriaDescriptionContext] = createFormContext(FORM_NAME);
65
+ var Form = React.forwardRef(
66
+ (props, forwardedRef) => {
67
+ const { __scopeForm, onClearServerErrors = () => {
68
+ }, ...rootProps } = props;
69
+ const formRef = React.useRef(null);
70
+ const composedFormRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, formRef);
71
+ const [validityMap, setValidityMap] = React.useState({});
72
+ const getFieldValidity = React.useCallback(
73
+ (fieldName) => validityMap[fieldName],
74
+ [validityMap]
75
+ );
76
+ const handleFieldValidityChange = React.useCallback(
77
+ (fieldName, validity) => setValidityMap((prevValidityMap) => ({
78
+ ...prevValidityMap,
79
+ [fieldName]: { ...prevValidityMap[fieldName] ?? {}, ...validity }
80
+ })),
81
+ []
82
+ );
83
+ const handleFieldValiditionClear = React.useCallback((fieldName) => {
84
+ setValidityMap((prevValidityMap) => ({ ...prevValidityMap, [fieldName]: void 0 }));
85
+ setCustomErrorsMap((prevCustomErrorsMap) => ({ ...prevCustomErrorsMap, [fieldName]: {} }));
86
+ }, []);
87
+ const [customMatcherEntriesMap, setCustomMatcherEntriesMap] = React.useState({});
88
+ const getFieldCustomMatcherEntries = React.useCallback(
89
+ (fieldName) => customMatcherEntriesMap[fieldName] ?? [],
90
+ [customMatcherEntriesMap]
91
+ );
92
+ const handleFieldCustomMatcherAdd = React.useCallback((fieldName, matcherEntry) => {
93
+ setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap) => ({
94
+ ...prevCustomMatcherEntriesMap,
95
+ [fieldName]: [...prevCustomMatcherEntriesMap[fieldName] ?? [], matcherEntry]
96
+ }));
97
+ }, []);
98
+ const handleFieldCustomMatcherRemove = React.useCallback((fieldName, matcherEntryId) => {
99
+ setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap) => ({
100
+ ...prevCustomMatcherEntriesMap,
101
+ [fieldName]: (prevCustomMatcherEntriesMap[fieldName] ?? []).filter(
102
+ (matcherEntry) => matcherEntry.id !== matcherEntryId
103
+ )
104
+ }));
105
+ }, []);
106
+ const [customErrorsMap, setCustomErrorsMap] = React.useState({});
107
+ const getFieldCustomErrors = React.useCallback(
108
+ (fieldName) => customErrorsMap[fieldName] ?? {},
109
+ [customErrorsMap]
110
+ );
111
+ const handleFieldCustomErrorsChange = React.useCallback((fieldName, customErrors) => {
112
+ setCustomErrorsMap((prevCustomErrorsMap) => ({
113
+ ...prevCustomErrorsMap,
114
+ [fieldName]: { ...prevCustomErrorsMap[fieldName] ?? {}, ...customErrors }
115
+ }));
116
+ }, []);
117
+ const [messageIdsMap, setMessageIdsMap] = React.useState({});
118
+ const handleFieldMessageIdAdd = React.useCallback((fieldName, id) => {
119
+ setMessageIdsMap((prevMessageIdsMap) => {
120
+ const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]).add(id);
121
+ return { ...prevMessageIdsMap, [fieldName]: fieldDescriptionIds };
122
+ });
123
+ }, []);
124
+ const handleFieldMessageIdRemove = React.useCallback((fieldName, id) => {
125
+ setMessageIdsMap((prevMessageIdsMap) => {
126
+ const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]);
127
+ fieldDescriptionIds.delete(id);
128
+ return { ...prevMessageIdsMap, [fieldName]: fieldDescriptionIds };
129
+ });
130
+ }, []);
131
+ const getFieldDescription = React.useCallback(
132
+ (fieldName) => Array.from(messageIdsMap[fieldName] ?? []).join(" ") || void 0,
133
+ [messageIdsMap]
134
+ );
135
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
136
+ ValidationProvider,
137
+ {
138
+ scope: __scopeForm,
139
+ getFieldValidity,
140
+ onFieldValidityChange: handleFieldValidityChange,
141
+ getFieldCustomMatcherEntries,
142
+ onFieldCustomMatcherEntryAdd: handleFieldCustomMatcherAdd,
143
+ onFieldCustomMatcherEntryRemove: handleFieldCustomMatcherRemove,
144
+ getFieldCustomErrors,
145
+ onFieldCustomErrorsChange: handleFieldCustomErrorsChange,
146
+ onFieldValiditionClear: handleFieldValiditionClear,
147
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
+ AriaDescriptionProvider,
149
+ {
150
+ scope: __scopeForm,
151
+ onFieldMessageIdAdd: handleFieldMessageIdAdd,
152
+ onFieldMessageIdRemove: handleFieldMessageIdRemove,
153
+ getFieldDescription,
154
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
+ import_react_primitive.Primitive.form,
156
+ {
157
+ ...rootProps,
158
+ ref: composedFormRef,
159
+ onInvalid: (0, import_primitive.composeEventHandlers)(props.onInvalid, (event) => {
160
+ const firstInvalidControl = getFirstInvalidControl(event.currentTarget);
161
+ if (firstInvalidControl === event.target) firstInvalidControl.focus();
162
+ event.preventDefault();
163
+ }),
164
+ onSubmit: (0, import_primitive.composeEventHandlers)(props.onSubmit, onClearServerErrors, {
165
+ checkForDefaultPrevented: false
166
+ }),
167
+ onReset: (0, import_primitive.composeEventHandlers)(props.onReset, onClearServerErrors)
168
+ }
169
+ )
252
170
  }
253
- },
254
- [customMatcherEntries, name, onFieldCustomErrorsChange, onFieldValidityChange]
255
- );
256
- React.useEffect(() => {
257
- const control = ref.current;
258
- if (control) {
259
- const handleChange = () => updateControlValidity(control);
260
- control.addEventListener("change", handleChange);
261
- return () => control.removeEventListener("change", handleChange);
262
- }
263
- }, [updateControlValidity]);
264
- const resetControlValidity = React.useCallback(() => {
265
- const control = ref.current;
266
- if (control) {
267
- control.setCustomValidity("");
268
- onFieldValiditionClear(name);
269
- }
270
- }, [name, onFieldValiditionClear]);
271
- React.useEffect(() => {
272
- const form = ref.current?.form;
273
- if (form) {
274
- form.addEventListener("reset", resetControlValidity);
275
- return () => form.removeEventListener("reset", resetControlValidity);
276
- }
277
- }, [resetControlValidity]);
278
- React.useEffect(() => {
279
- const control = ref.current;
280
- const form = control?.closest("form");
281
- if (form && fieldContext.serverInvalid) {
282
- const firstInvalidControl = getFirstInvalidControl(form);
283
- if (firstInvalidControl === control) firstInvalidControl.focus();
171
+ )
172
+ }
173
+ );
174
+ }
175
+ );
176
+ Form.displayName = FORM_NAME;
177
+ var FIELD_NAME = "FormField";
178
+ var [FormFieldProvider, useFormFieldContext] = createFormContext(FIELD_NAME);
179
+ var FormField = React.forwardRef(
180
+ (props, forwardedRef) => {
181
+ const { __scopeForm, name, serverInvalid = false, ...fieldProps } = props;
182
+ const validationContext = useValidationContext(FIELD_NAME, __scopeForm);
183
+ const validity = validationContext.getFieldValidity(name);
184
+ const id = (0, import_react_id.useId)();
185
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormFieldProvider, { scope: __scopeForm, id, name, serverInvalid, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_react_primitive.Primitive.div,
187
+ {
188
+ "data-valid": getValidAttribute(validity, serverInvalid),
189
+ "data-invalid": getInvalidAttribute(validity, serverInvalid),
190
+ ...fieldProps,
191
+ ref: forwardedRef
192
+ }
193
+ ) });
194
+ }
195
+ );
196
+ FormField.displayName = FIELD_NAME;
197
+ var LABEL_NAME = "FormLabel";
198
+ var FormLabel = React.forwardRef(
199
+ (props, forwardedRef) => {
200
+ const { __scopeForm, ...labelProps } = props;
201
+ const validationContext = useValidationContext(LABEL_NAME, __scopeForm);
202
+ const fieldContext = useFormFieldContext(LABEL_NAME, __scopeForm);
203
+ const htmlFor = labelProps.htmlFor || fieldContext.id;
204
+ const validity = validationContext.getFieldValidity(fieldContext.name);
205
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
206
+ import_react_label.Label,
207
+ {
208
+ "data-valid": getValidAttribute(validity, fieldContext.serverInvalid),
209
+ "data-invalid": getInvalidAttribute(validity, fieldContext.serverInvalid),
210
+ ...labelProps,
211
+ ref: forwardedRef,
212
+ htmlFor
213
+ }
214
+ );
215
+ }
216
+ );
217
+ FormLabel.displayName = LABEL_NAME;
218
+ var CONTROL_NAME = "FormControl";
219
+ var FormControl = React.forwardRef(
220
+ (props, forwardedRef) => {
221
+ const { __scopeForm, ...controlProps } = props;
222
+ const validationContext = useValidationContext(CONTROL_NAME, __scopeForm);
223
+ const fieldContext = useFormFieldContext(CONTROL_NAME, __scopeForm);
224
+ const ariaDescriptionContext = useAriaDescriptionContext(CONTROL_NAME, __scopeForm);
225
+ const ref = React.useRef(null);
226
+ const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
227
+ const name = controlProps.name || fieldContext.name;
228
+ const id = controlProps.id || fieldContext.id;
229
+ const customMatcherEntries = validationContext.getFieldCustomMatcherEntries(name);
230
+ const { onFieldValidityChange, onFieldCustomErrorsChange, onFieldValiditionClear } = validationContext;
231
+ const updateControlValidity = React.useCallback(
232
+ async (control) => {
233
+ if (hasBuiltInError(control.validity)) {
234
+ const controlValidity2 = validityStateToObject(control.validity);
235
+ onFieldValidityChange(name, controlValidity2);
236
+ return;
284
237
  }
285
- }, [fieldContext.serverInvalid]);
286
- const validity = validationContext.getFieldValidity(name);
287
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
288
- import_react_primitive.Primitive.input,
289
- {
290
- "data-valid": getValidAttribute(validity, fieldContext.serverInvalid),
291
- "data-invalid": getInvalidAttribute(validity, fieldContext.serverInvalid),
292
- "aria-invalid": fieldContext.serverInvalid ? true : void 0,
293
- "aria-describedby": ariaDescriptionContext.getFieldDescription(name),
294
- title: "",
295
- ...controlProps,
296
- ref: composedRef,
297
- id,
298
- name,
299
- onInvalid: (0, import_primitive.composeEventHandlers)(props.onInvalid, (event) => {
300
- const control = event.currentTarget;
301
- updateControlValidity(control);
302
- }),
303
- onChange: (0, import_primitive.composeEventHandlers)(props.onChange, (event) => {
304
- resetControlValidity();
305
- })
238
+ const formData = control.form ? new FormData(control.form) : new FormData();
239
+ const matcherArgs = [control.value, formData];
240
+ const syncCustomMatcherEntries = [];
241
+ const ayncCustomMatcherEntries = [];
242
+ customMatcherEntries.forEach((customMatcherEntry) => {
243
+ if (isAsyncCustomMatcherEntry(customMatcherEntry, matcherArgs)) {
244
+ ayncCustomMatcherEntries.push(customMatcherEntry);
245
+ } else if (isSyncCustomMatcherEntry(customMatcherEntry)) {
246
+ syncCustomMatcherEntries.push(customMatcherEntry);
247
+ }
248
+ });
249
+ const syncCustomErrors = syncCustomMatcherEntries.map(({ id: id2, match }) => {
250
+ return [id2, match(...matcherArgs)];
251
+ });
252
+ const syncCustomErrorsById = Object.fromEntries(syncCustomErrors);
253
+ const hasSyncCustomErrors = Object.values(syncCustomErrorsById).some(Boolean);
254
+ const hasCustomError = hasSyncCustomErrors;
255
+ control.setCustomValidity(hasCustomError ? DEFAULT_INVALID_MESSAGE : "");
256
+ const controlValidity = validityStateToObject(control.validity);
257
+ onFieldValidityChange(name, controlValidity);
258
+ onFieldCustomErrorsChange(name, syncCustomErrorsById);
259
+ if (!hasSyncCustomErrors && ayncCustomMatcherEntries.length > 0) {
260
+ const promisedCustomErrors = ayncCustomMatcherEntries.map(
261
+ ({ id: id2, match }) => match(...matcherArgs).then((matches) => [id2, matches])
262
+ );
263
+ const asyncCustomErrors = await Promise.all(promisedCustomErrors);
264
+ const asyncCustomErrorsById = Object.fromEntries(asyncCustomErrors);
265
+ const hasAsyncCustomErrors = Object.values(asyncCustomErrorsById).some(Boolean);
266
+ const hasCustomError2 = hasAsyncCustomErrors;
267
+ control.setCustomValidity(hasCustomError2 ? DEFAULT_INVALID_MESSAGE : "");
268
+ const controlValidity2 = validityStateToObject(control.validity);
269
+ onFieldValidityChange(name, controlValidity2);
270
+ onFieldCustomErrorsChange(name, asyncCustomErrorsById);
306
271
  }
307
- );
308
- }
309
- );
310
- FormControl.displayName = CONTROL_NAME;
311
- var DEFAULT_INVALID_MESSAGE = "This value is not valid";
312
- var DEFAULT_BUILT_IN_MESSAGES = {
313
- badInput: DEFAULT_INVALID_MESSAGE,
314
- patternMismatch: "This value does not match the required pattern",
315
- rangeOverflow: "This value is too large",
316
- rangeUnderflow: "This value is too small",
317
- stepMismatch: "This value does not match the required step",
318
- tooLong: "This value is too long",
319
- tooShort: "This value is too short",
320
- typeMismatch: "This value does not match the required type",
321
- valid: void 0,
322
- valueMissing: "This value is missing"
323
- };
324
- var MESSAGE_NAME = "FormMessage";
325
- var FormMessage = React.forwardRef(
326
- (props, forwardedRef) => {
327
- const { match, name: nameProp, ...messageProps } = props;
328
- const fieldContext = useFormFieldContext(MESSAGE_NAME, props.__scopeForm);
329
- const name = nameProp ?? fieldContext.name;
330
- if (match === void 0) {
331
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { ...messageProps, ref: forwardedRef, name, children: props.children || DEFAULT_INVALID_MESSAGE });
332
- } else if (typeof match === "function") {
333
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormCustomMessage, { match, ...messageProps, ref: forwardedRef, name });
334
- } else {
335
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormBuiltInMessage, { match, ...messageProps, ref: forwardedRef, name });
272
+ },
273
+ [customMatcherEntries, name, onFieldCustomErrorsChange, onFieldValidityChange]
274
+ );
275
+ React.useEffect(() => {
276
+ const control = ref.current;
277
+ if (control) {
278
+ const handleChange = () => updateControlValidity(control);
279
+ control.addEventListener("change", handleChange);
280
+ return () => control.removeEventListener("change", handleChange);
336
281
  }
337
- }
338
- );
339
- FormMessage.displayName = MESSAGE_NAME;
340
- var FormBuiltInMessage = React.forwardRef(
341
- (props, forwardedRef) => {
342
- const { match, forceMatch = false, name, children, ...messageProps } = props;
343
- const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
344
- const validity = validationContext.getFieldValidity(name);
345
- const matches = forceMatch || validity?.[match];
346
- if (matches) {
347
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { ref: forwardedRef, ...messageProps, name, children: children ?? DEFAULT_BUILT_IN_MESSAGES[match] });
282
+ }, [updateControlValidity]);
283
+ const resetControlValidity = React.useCallback(() => {
284
+ const control = ref.current;
285
+ if (control) {
286
+ control.setCustomValidity("");
287
+ onFieldValiditionClear(name);
348
288
  }
349
- return null;
350
- }
351
- );
352
- var FormCustomMessage = React.forwardRef(
353
- (props, forwardedRef) => {
354
- const { match, forceMatch = false, name, id: idProp, children, ...messageProps } = props;
355
- const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
356
- const ref = React.useRef(null);
357
- const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
358
- const _id = (0, import_react_id.useId)();
359
- const id = idProp ?? _id;
360
- const customMatcherEntry = React.useMemo(() => ({ id, match }), [id, match]);
361
- const { onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove } = validationContext;
362
- React.useEffect(() => {
363
- onFieldCustomMatcherEntryAdd(name, customMatcherEntry);
364
- return () => onFieldCustomMatcherEntryRemove(name, customMatcherEntry.id);
365
- }, [customMatcherEntry, name, onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove]);
366
- const validity = validationContext.getFieldValidity(name);
367
- const customErrors = validationContext.getFieldCustomErrors(name);
368
- const hasMatchingCustomError = customErrors[id];
369
- const matches = forceMatch || validity && !hasBuiltInError(validity) && hasMatchingCustomError;
370
- if (matches) {
371
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { id, ref: composedRef, ...messageProps, name, children: children ?? DEFAULT_INVALID_MESSAGE });
289
+ }, [name, onFieldValiditionClear]);
290
+ React.useEffect(() => {
291
+ const form = ref.current?.form;
292
+ if (form) {
293
+ form.addEventListener("reset", resetControlValidity);
294
+ return () => form.removeEventListener("reset", resetControlValidity);
372
295
  }
373
- return null;
374
- }
375
- );
376
- var FormMessageImpl = React.forwardRef(
377
- (props, forwardedRef) => {
378
- const { __scopeForm, id: idProp, name, ...messageProps } = props;
379
- const ariaDescriptionContext = useAriaDescriptionContext(MESSAGE_NAME, __scopeForm);
380
- const _id = (0, import_react_id.useId)();
381
- const id = idProp ?? _id;
382
- const { onFieldMessageIdAdd, onFieldMessageIdRemove } = ariaDescriptionContext;
383
- React.useEffect(() => {
384
- onFieldMessageIdAdd(name, id);
385
- return () => onFieldMessageIdRemove(name, id);
386
- }, [name, id, onFieldMessageIdAdd, onFieldMessageIdRemove]);
387
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { id, ...messageProps, ref: forwardedRef });
388
- }
389
- );
390
- var VALIDITY_STATE_NAME = "FormValidityState";
391
- var FormValidityState = (props) => {
392
- const { __scopeForm, name: nameProp, children } = props;
393
- const validationContext = useValidationContext(VALIDITY_STATE_NAME, __scopeForm);
394
- const fieldContext = useFormFieldContext(VALIDITY_STATE_NAME, __scopeForm);
395
- const name = nameProp ?? fieldContext.name;
296
+ }, [resetControlValidity]);
297
+ React.useEffect(() => {
298
+ const control = ref.current;
299
+ const form = control?.closest("form");
300
+ if (form && fieldContext.serverInvalid) {
301
+ const firstInvalidControl = getFirstInvalidControl(form);
302
+ if (firstInvalidControl === control) firstInvalidControl.focus();
303
+ }
304
+ }, [fieldContext.serverInvalid]);
396
305
  const validity = validationContext.getFieldValidity(name);
397
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: children(validity) });
398
- };
399
- FormValidityState.displayName = VALIDITY_STATE_NAME;
400
- var SUBMIT_NAME = "FormSubmit";
401
- var FormSubmit = React.forwardRef(
402
- (props, forwardedRef) => {
403
- const { __scopeForm, ...submitProps } = props;
404
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.button, { type: "submit", ...submitProps, ref: forwardedRef });
405
- }
406
- );
407
- FormSubmit.displayName = SUBMIT_NAME;
408
- function validityStateToObject(validity) {
409
- const object = {};
410
- for (const key in validity) {
411
- object[key] = validity[key];
412
- }
413
- return object;
414
- }
415
- function isHTMLElement(element) {
416
- return element instanceof HTMLElement;
306
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
307
+ import_react_primitive.Primitive.input,
308
+ {
309
+ "data-valid": getValidAttribute(validity, fieldContext.serverInvalid),
310
+ "data-invalid": getInvalidAttribute(validity, fieldContext.serverInvalid),
311
+ "aria-invalid": fieldContext.serverInvalid ? true : void 0,
312
+ "aria-describedby": ariaDescriptionContext.getFieldDescription(name),
313
+ title: "",
314
+ ...controlProps,
315
+ ref: composedRef,
316
+ id,
317
+ name,
318
+ onInvalid: (0, import_primitive.composeEventHandlers)(props.onInvalid, (event) => {
319
+ const control = event.currentTarget;
320
+ updateControlValidity(control);
321
+ }),
322
+ onChange: (0, import_primitive.composeEventHandlers)(props.onChange, (event) => {
323
+ resetControlValidity();
324
+ })
325
+ }
326
+ );
417
327
  }
418
- function isFormControl(element) {
419
- return "validity" in element;
328
+ );
329
+ FormControl.displayName = CONTROL_NAME;
330
+ var DEFAULT_INVALID_MESSAGE = "This value is not valid";
331
+ var DEFAULT_BUILT_IN_MESSAGES = {
332
+ badInput: DEFAULT_INVALID_MESSAGE,
333
+ patternMismatch: "This value does not match the required pattern",
334
+ rangeOverflow: "This value is too large",
335
+ rangeUnderflow: "This value is too small",
336
+ stepMismatch: "This value does not match the required step",
337
+ tooLong: "This value is too long",
338
+ tooShort: "This value is too short",
339
+ typeMismatch: "This value does not match the required type",
340
+ valid: void 0,
341
+ valueMissing: "This value is missing"
342
+ };
343
+ var MESSAGE_NAME = "FormMessage";
344
+ var FormMessage = React.forwardRef(
345
+ (props, forwardedRef) => {
346
+ const { match, name: nameProp, ...messageProps } = props;
347
+ const fieldContext = useFormFieldContext(MESSAGE_NAME, props.__scopeForm);
348
+ const name = nameProp ?? fieldContext.name;
349
+ if (match === void 0) {
350
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { ...messageProps, ref: forwardedRef, name, children: props.children || DEFAULT_INVALID_MESSAGE });
351
+ } else if (typeof match === "function") {
352
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormCustomMessage, { match, ...messageProps, ref: forwardedRef, name });
353
+ } else {
354
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormBuiltInMessage, { match, ...messageProps, ref: forwardedRef, name });
355
+ }
420
356
  }
421
- function isInvalid(control) {
422
- return isFormControl(control) && (control.validity.valid === false || control.getAttribute("aria-invalid") === "true");
357
+ );
358
+ FormMessage.displayName = MESSAGE_NAME;
359
+ var FormBuiltInMessage = React.forwardRef(
360
+ (props, forwardedRef) => {
361
+ const { match, forceMatch = false, name, children, ...messageProps } = props;
362
+ const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
363
+ const validity = validationContext.getFieldValidity(name);
364
+ const matches = forceMatch || validity?.[match];
365
+ if (matches) {
366
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { ref: forwardedRef, ...messageProps, name, children: children ?? DEFAULT_BUILT_IN_MESSAGES[match] });
367
+ }
368
+ return null;
423
369
  }
424
- function getFirstInvalidControl(form) {
425
- const elements = form.elements;
426
- const [firstInvalidControl] = Array.from(elements).filter(isHTMLElement).filter(isInvalid);
427
- return firstInvalidControl;
370
+ );
371
+ var FormCustomMessage = React.forwardRef(
372
+ (props, forwardedRef) => {
373
+ const { match, forceMatch = false, name, id: idProp, children, ...messageProps } = props;
374
+ const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
375
+ const ref = React.useRef(null);
376
+ const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
377
+ const _id = (0, import_react_id.useId)();
378
+ const id = idProp ?? _id;
379
+ const customMatcherEntry = React.useMemo(() => ({ id, match }), [id, match]);
380
+ const { onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove } = validationContext;
381
+ React.useEffect(() => {
382
+ onFieldCustomMatcherEntryAdd(name, customMatcherEntry);
383
+ return () => onFieldCustomMatcherEntryRemove(name, customMatcherEntry.id);
384
+ }, [customMatcherEntry, name, onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove]);
385
+ const validity = validationContext.getFieldValidity(name);
386
+ const customErrors = validationContext.getFieldCustomErrors(name);
387
+ const hasMatchingCustomError = customErrors[id];
388
+ const matches = forceMatch || validity && !hasBuiltInError(validity) && hasMatchingCustomError;
389
+ if (matches) {
390
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { id, ref: composedRef, ...messageProps, name, children: children ?? DEFAULT_INVALID_MESSAGE });
391
+ }
392
+ return null;
428
393
  }
429
- function isAsyncCustomMatcherEntry(entry, args) {
430
- return entry.match.constructor.name === "AsyncFunction" || returnsPromise(entry.match, args);
394
+ );
395
+ var FormMessageImpl = React.forwardRef(
396
+ (props, forwardedRef) => {
397
+ const { __scopeForm, id: idProp, name, ...messageProps } = props;
398
+ const ariaDescriptionContext = useAriaDescriptionContext(MESSAGE_NAME, __scopeForm);
399
+ const _id = (0, import_react_id.useId)();
400
+ const id = idProp ?? _id;
401
+ const { onFieldMessageIdAdd, onFieldMessageIdRemove } = ariaDescriptionContext;
402
+ React.useEffect(() => {
403
+ onFieldMessageIdAdd(name, id);
404
+ return () => onFieldMessageIdRemove(name, id);
405
+ }, [name, id, onFieldMessageIdAdd, onFieldMessageIdRemove]);
406
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { id, ...messageProps, ref: forwardedRef });
431
407
  }
432
- function isSyncCustomMatcherEntry(entry) {
433
- return entry.match.constructor.name === "Function";
408
+ );
409
+ var VALIDITY_STATE_NAME = "FormValidityState";
410
+ var FormValidityState = (props) => {
411
+ const { __scopeForm, name: nameProp, children } = props;
412
+ const validationContext = useValidationContext(VALIDITY_STATE_NAME, __scopeForm);
413
+ const fieldContext = useFormFieldContext(VALIDITY_STATE_NAME, __scopeForm);
414
+ const name = nameProp ?? fieldContext.name;
415
+ const validity = validationContext.getFieldValidity(name);
416
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: children(validity) });
417
+ };
418
+ FormValidityState.displayName = VALIDITY_STATE_NAME;
419
+ var SUBMIT_NAME = "FormSubmit";
420
+ var FormSubmit = React.forwardRef(
421
+ (props, forwardedRef) => {
422
+ const { __scopeForm, ...submitProps } = props;
423
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.button, { type: "submit", ...submitProps, ref: forwardedRef });
434
424
  }
435
- function returnsPromise(func, args) {
436
- return func(...args) instanceof Promise;
425
+ );
426
+ FormSubmit.displayName = SUBMIT_NAME;
427
+ function validityStateToObject(validity) {
428
+ const object = {};
429
+ for (const key in validity) {
430
+ object[key] = validity[key];
437
431
  }
438
- function hasBuiltInError(validity) {
439
- let error = false;
440
- for (const validityKey in validity) {
441
- const key = validityKey;
442
- if (key !== "valid" && key !== "customError" && validity[key]) {
443
- error = true;
444
- break;
445
- }
432
+ return object;
433
+ }
434
+ function isHTMLElement(element) {
435
+ return element instanceof HTMLElement;
436
+ }
437
+ function isFormControl(element) {
438
+ return "validity" in element;
439
+ }
440
+ function isInvalid(control) {
441
+ return isFormControl(control) && (control.validity.valid === false || control.getAttribute("aria-invalid") === "true");
442
+ }
443
+ function getFirstInvalidControl(form) {
444
+ const elements = form.elements;
445
+ const [firstInvalidControl] = Array.from(elements).filter(isHTMLElement).filter(isInvalid);
446
+ return firstInvalidControl;
447
+ }
448
+ function isAsyncCustomMatcherEntry(entry, args) {
449
+ return entry.match.constructor.name === "AsyncFunction" || returnsPromise(entry.match, args);
450
+ }
451
+ function isSyncCustomMatcherEntry(entry) {
452
+ return entry.match.constructor.name === "Function";
453
+ }
454
+ function returnsPromise(func, args) {
455
+ return func(...args) instanceof Promise;
456
+ }
457
+ function hasBuiltInError(validity) {
458
+ let error = false;
459
+ for (const validityKey in validity) {
460
+ const key = validityKey;
461
+ if (key !== "valid" && key !== "customError" && validity[key]) {
462
+ error = true;
463
+ break;
446
464
  }
447
- return error;
448
- }
449
- function getValidAttribute(validity, serverInvalid) {
450
- if (validity?.valid === true && !serverInvalid) return true;
451
- return void 0;
452
- }
453
- function getInvalidAttribute(validity, serverInvalid) {
454
- if (validity?.valid === false || serverInvalid) return true;
455
- return void 0;
456
465
  }
457
- var Root = Form;
458
- var Field = FormField;
459
- var Label = FormLabel;
460
- var Control = FormControl;
461
- var Message = FormMessage;
462
- var ValidityState = FormValidityState;
463
- var Submit = FormSubmit;
464
- })();
466
+ return error;
467
+ }
468
+ function getValidAttribute(validity, serverInvalid) {
469
+ if (validity?.valid === true && !serverInvalid) return true;
470
+ return void 0;
471
+ }
472
+ function getInvalidAttribute(validity, serverInvalid) {
473
+ if (validity?.valid === false || serverInvalid) return true;
474
+ return void 0;
475
+ }
476
+ var Root = Form;
477
+ var Field = FormField;
478
+ var Label = FormLabel;
479
+ var Control = FormControl;
480
+ var Message = FormMessage;
481
+ var ValidityState = FormValidityState;
482
+ var Submit = FormSubmit;
465
483
  //# sourceMappingURL=index.js.map