@radix-ui/react-form 0.1.0-rc.1 → 0.1.0-rc.3
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 +464 -445
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,464 +1,483 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
));
|
|
2
|
+
"use client";
|
|
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);
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
ref: forwardedRef
|
|
172
|
-
}
|
|
173
|
-
) });
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
FormField.displayName = FIELD_NAME;
|
|
177
|
-
var LABEL_NAME = "FormLabel";
|
|
178
|
-
var FormLabel = React.forwardRef(
|
|
179
|
-
(props, forwardedRef) => {
|
|
180
|
-
const { __scopeForm, ...labelProps } = props;
|
|
181
|
-
const validationContext = useValidationContext(LABEL_NAME, __scopeForm);
|
|
182
|
-
const fieldContext = useFormFieldContext(LABEL_NAME, __scopeForm);
|
|
183
|
-
const htmlFor = labelProps.htmlFor || fieldContext.id;
|
|
184
|
-
const validity = validationContext.getFieldValidity(fieldContext.name);
|
|
185
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
186
|
-
import_react_label.Label,
|
|
187
|
-
{
|
|
188
|
-
"data-valid": getValidAttribute(validity, fieldContext.serverInvalid),
|
|
189
|
-
"data-invalid": getInvalidAttribute(validity, fieldContext.serverInvalid),
|
|
190
|
-
...labelProps,
|
|
191
|
-
ref: forwardedRef,
|
|
192
|
-
htmlFor
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
FormLabel.displayName = LABEL_NAME;
|
|
198
|
-
var CONTROL_NAME = "FormControl";
|
|
199
|
-
var FormControl = React.forwardRef(
|
|
200
|
-
(props, forwardedRef) => {
|
|
201
|
-
const { __scopeForm, ...controlProps } = props;
|
|
202
|
-
const validationContext = useValidationContext(CONTROL_NAME, __scopeForm);
|
|
203
|
-
const fieldContext = useFormFieldContext(CONTROL_NAME, __scopeForm);
|
|
204
|
-
const ariaDescriptionContext = useAriaDescriptionContext(CONTROL_NAME, __scopeForm);
|
|
205
|
-
const ref = React.useRef(null);
|
|
206
|
-
const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
207
|
-
const name = controlProps.name || fieldContext.name;
|
|
208
|
-
const id = controlProps.id || fieldContext.id;
|
|
209
|
-
const customMatcherEntries = validationContext.getFieldCustomMatcherEntries(name);
|
|
210
|
-
const { onFieldValidityChange, onFieldCustomErrorsChange, onFieldValiditionClear } = validationContext;
|
|
211
|
-
const updateControlValidity = React.useCallback(
|
|
212
|
-
async (control) => {
|
|
213
|
-
if (hasBuiltInError(control.validity)) {
|
|
214
|
-
const controlValidity2 = validityStateToObject(control.validity);
|
|
215
|
-
onFieldValidityChange(name, controlValidity2);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const formData = control.form ? new FormData(control.form) : new FormData();
|
|
219
|
-
const matcherArgs = [control.value, formData];
|
|
220
|
-
const syncCustomMatcherEntries = [];
|
|
221
|
-
const ayncCustomMatcherEntries = [];
|
|
222
|
-
customMatcherEntries.forEach((customMatcherEntry) => {
|
|
223
|
-
if (isAsyncCustomMatcherEntry(customMatcherEntry, matcherArgs)) {
|
|
224
|
-
ayncCustomMatcherEntries.push(customMatcherEntry);
|
|
225
|
-
} else if (isSyncCustomMatcherEntry(customMatcherEntry)) {
|
|
226
|
-
syncCustomMatcherEntries.push(customMatcherEntry);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
const syncCustomErrors = syncCustomMatcherEntries.map(({ id: id2, match }) => {
|
|
230
|
-
return [id2, match(...matcherArgs)];
|
|
231
|
-
});
|
|
232
|
-
const syncCustomErrorsById = Object.fromEntries(syncCustomErrors);
|
|
233
|
-
const hasSyncCustomErrors = Object.values(syncCustomErrorsById).some(Boolean);
|
|
234
|
-
const hasCustomError = hasSyncCustomErrors;
|
|
235
|
-
control.setCustomValidity(hasCustomError ? DEFAULT_INVALID_MESSAGE : "");
|
|
236
|
-
const controlValidity = validityStateToObject(control.validity);
|
|
237
|
-
onFieldValidityChange(name, controlValidity);
|
|
238
|
-
onFieldCustomErrorsChange(name, syncCustomErrorsById);
|
|
239
|
-
if (!hasSyncCustomErrors && ayncCustomMatcherEntries.length > 0) {
|
|
240
|
-
const promisedCustomErrors = ayncCustomMatcherEntries.map(
|
|
241
|
-
({ id: id2, match }) => match(...matcherArgs).then((matches) => [id2, matches])
|
|
242
|
-
);
|
|
243
|
-
const asyncCustomErrors = await Promise.all(promisedCustomErrors);
|
|
244
|
-
const asyncCustomErrorsById = Object.fromEntries(asyncCustomErrors);
|
|
245
|
-
const hasAsyncCustomErrors = Object.values(asyncCustomErrorsById).some(Boolean);
|
|
246
|
-
const hasCustomError2 = hasAsyncCustomErrors;
|
|
247
|
-
control.setCustomValidity(hasCustomError2 ? DEFAULT_INVALID_MESSAGE : "");
|
|
248
|
-
const controlValidity2 = validityStateToObject(control.validity);
|
|
249
|
-
onFieldValidityChange(name, controlValidity2);
|
|
250
|
-
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
|
+
)
|
|
251
170
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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;
|
|
283
237
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
{
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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);
|
|
305
271
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
rangeUnderflow: "This value is too small",
|
|
316
|
-
stepMismatch: "This value does not match the required step",
|
|
317
|
-
tooLong: "This value is too long",
|
|
318
|
-
tooShort: "This value is too short",
|
|
319
|
-
typeMismatch: "This value does not match the required type",
|
|
320
|
-
valid: void 0,
|
|
321
|
-
valueMissing: "This value is missing"
|
|
322
|
-
};
|
|
323
|
-
var MESSAGE_NAME = "FormMessage";
|
|
324
|
-
var FormMessage = React.forwardRef(
|
|
325
|
-
(props, forwardedRef) => {
|
|
326
|
-
const { match, name: nameProp, ...messageProps } = props;
|
|
327
|
-
const fieldContext = useFormFieldContext(MESSAGE_NAME, props.__scopeForm);
|
|
328
|
-
const name = nameProp ?? fieldContext.name;
|
|
329
|
-
if (match === void 0) {
|
|
330
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormMessageImpl, { ...messageProps, ref: forwardedRef, name, children: props.children || DEFAULT_INVALID_MESSAGE });
|
|
331
|
-
} else if (typeof match === "function") {
|
|
332
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FormCustomMessage, { match, ...messageProps, ref: forwardedRef, name });
|
|
333
|
-
} else {
|
|
334
|
-
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);
|
|
335
281
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
|
|
343
|
-
const validity = validationContext.getFieldValidity(name);
|
|
344
|
-
const matches = forceMatch || validity?.[match];
|
|
345
|
-
if (matches) {
|
|
346
|
-
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);
|
|
347
288
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const validationContext = useValidationContext(MESSAGE_NAME, messageProps.__scopeForm);
|
|
355
|
-
const ref = React.useRef(null);
|
|
356
|
-
const composedRef = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
357
|
-
const _id = (0, import_react_id.useId)();
|
|
358
|
-
const id = idProp ?? _id;
|
|
359
|
-
const customMatcherEntry = React.useMemo(() => ({ id, match }), [id, match]);
|
|
360
|
-
const { onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove } = validationContext;
|
|
361
|
-
React.useEffect(() => {
|
|
362
|
-
onFieldCustomMatcherEntryAdd(name, customMatcherEntry);
|
|
363
|
-
return () => onFieldCustomMatcherEntryRemove(name, customMatcherEntry.id);
|
|
364
|
-
}, [customMatcherEntry, name, onFieldCustomMatcherEntryAdd, onFieldCustomMatcherEntryRemove]);
|
|
365
|
-
const validity = validationContext.getFieldValidity(name);
|
|
366
|
-
const customErrors = validationContext.getFieldCustomErrors(name);
|
|
367
|
-
const hasMatchingCustomError = customErrors[id];
|
|
368
|
-
const matches = forceMatch || validity && !hasBuiltInError(validity) && hasMatchingCustomError;
|
|
369
|
-
if (matches) {
|
|
370
|
-
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);
|
|
371
295
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const { onFieldMessageIdAdd, onFieldMessageIdRemove } = ariaDescriptionContext;
|
|
382
|
-
React.useEffect(() => {
|
|
383
|
-
onFieldMessageIdAdd(name, id);
|
|
384
|
-
return () => onFieldMessageIdRemove(name, id);
|
|
385
|
-
}, [name, id, onFieldMessageIdAdd, onFieldMessageIdRemove]);
|
|
386
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { id, ...messageProps, ref: forwardedRef });
|
|
387
|
-
}
|
|
388
|
-
);
|
|
389
|
-
var VALIDITY_STATE_NAME = "FormValidityState";
|
|
390
|
-
var FormValidityState = (props) => {
|
|
391
|
-
const { __scopeForm, name: nameProp, children } = props;
|
|
392
|
-
const validationContext = useValidationContext(VALIDITY_STATE_NAME, __scopeForm);
|
|
393
|
-
const fieldContext = useFormFieldContext(VALIDITY_STATE_NAME, __scopeForm);
|
|
394
|
-
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]);
|
|
395
305
|
const validity = validationContext.getFieldValidity(name);
|
|
396
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
);
|
|
416
327
|
}
|
|
417
|
-
|
|
418
|
-
|
|
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
|
+
}
|
|
419
356
|
}
|
|
420
|
-
|
|
421
|
-
|
|
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;
|
|
422
369
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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;
|
|
427
393
|
}
|
|
428
|
-
|
|
429
|
-
|
|
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 });
|
|
430
407
|
}
|
|
431
|
-
|
|
432
|
-
|
|
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 });
|
|
433
424
|
}
|
|
434
|
-
|
|
435
|
-
|
|
425
|
+
);
|
|
426
|
+
FormSubmit.displayName = SUBMIT_NAME;
|
|
427
|
+
function validityStateToObject(validity) {
|
|
428
|
+
const object = {};
|
|
429
|
+
for (const key in validity) {
|
|
430
|
+
object[key] = validity[key];
|
|
436
431
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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;
|
|
445
464
|
}
|
|
446
|
-
return error;
|
|
447
|
-
}
|
|
448
|
-
function getValidAttribute(validity, serverInvalid) {
|
|
449
|
-
if (validity?.valid === true && !serverInvalid) return true;
|
|
450
|
-
return void 0;
|
|
451
|
-
}
|
|
452
|
-
function getInvalidAttribute(validity, serverInvalid) {
|
|
453
|
-
if (validity?.valid === false || serverInvalid) return true;
|
|
454
|
-
return void 0;
|
|
455
465
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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;
|
|
464
483
|
//# sourceMappingURL=index.js.map
|