@workos-inc/widgets 1.20.2-next.1792700156145 → 1.20.2
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/CHANGELOG.md +4 -10
- package/dist/cjs/admin-portal-audit-log-streaming.client.cjs +2 -1
- package/dist/cjs/admin-portal-audit-log-streaming.client.cjs.map +1 -1
- package/dist/cjs/admin-portal-domain-verification.client.cjs +3 -2
- package/dist/cjs/admin-portal-domain-verification.client.cjs.map +1 -1
- package/dist/cjs/admin-portal-sso-connection.client.cjs +2 -1
- package/dist/cjs/admin-portal-sso-connection.client.cjs.map +1 -1
- package/dist/cjs/api/api-provider.cjs +23 -1
- package/dist/cjs/api/api-provider.cjs.map +1 -1
- package/dist/cjs/api/api-provider.d.cts.map +1 -1
- package/dist/cjs/api/claims.cjs.map +1 -1
- package/dist/cjs/api/claims.d.cts +2 -1
- package/dist/cjs/api/claims.d.cts.map +1 -1
- package/dist/cjs/api/client-graphql/client.cjs +3 -2
- package/dist/cjs/api/client-graphql/client.cjs.map +1 -1
- package/dist/cjs/api/client-graphql/hooks.cjs +3 -20
- package/dist/cjs/api/client-graphql/hooks.cjs.map +1 -1
- package/dist/cjs/api/client-graphql/hooks.d.cts +3 -12
- package/dist/cjs/api/client-graphql/hooks.d.cts.map +1 -1
- package/dist/cjs/api/client-graphql/query-keys.cjs +25 -0
- package/dist/cjs/api/client-graphql/query-keys.cjs.map +1 -0
- package/dist/cjs/api/client-graphql/query-keys.d.cts +16 -0
- package/dist/cjs/api/client-graphql/query-keys.d.cts.map +1 -0
- package/dist/cjs/components/copy-text.cjs +1 -1
- package/dist/cjs/components/copy-text.cjs.map +1 -1
- package/dist/cjs/components/form.cjs +9 -13
- package/dist/cjs/components/form.cjs.map +1 -1
- package/dist/cjs/components/form.d.cts.map +1 -1
- package/dist/cjs/components/otp-input.cjs +1 -0
- package/dist/cjs/components/otp-input.cjs.map +1 -1
- package/dist/cjs/directory-sync.client.cjs +2 -1
- package/dist/cjs/directory-sync.client.cjs.map +1 -1
- package/dist/cjs/lib/api/api-key.cjs +4 -3
- package/dist/cjs/lib/api/api-key.cjs.map +1 -1
- package/dist/cjs/lib/api/me.cjs +2 -1
- package/dist/cjs/lib/api/me.cjs.map +1 -1
- package/dist/cjs/lib/api/pipes.cjs +7 -6
- package/dist/cjs/lib/api/pipes.cjs.map +1 -1
- package/dist/cjs/lib/api/user-api-key.cjs +3 -2
- package/dist/cjs/lib/api/user-api-key.cjs.map +1 -1
- package/dist/cjs/lib/i18n/intl-context.cjs.map +1 -1
- package/dist/cjs/lib/i18n/intl-context.d.cts +1 -0
- package/dist/cjs/lib/i18n/intl-context.d.cts.map +1 -1
- package/dist/cjs/lib/i18n/use-translation.cjs +2 -2
- package/dist/cjs/lib/i18n/use-translation.cjs.map +1 -1
- package/dist/cjs/lib/use-composed-event-handlers.cjs +15 -0
- package/dist/cjs/lib/use-composed-event-handlers.cjs.map +1 -0
- package/dist/cjs/lib/use-composed-event-handlers.d.cts +6 -0
- package/dist/cjs/lib/use-composed-event-handlers.d.cts.map +1 -0
- package/dist/cjs/lib/use-debounce.cjs +124 -116
- package/dist/cjs/lib/use-debounce.cjs.map +1 -1
- package/dist/cjs/lib/use-debounce.d.cts +53 -48
- package/dist/cjs/lib/use-debounce.d.cts.map +1 -1
- package/dist/cjs/lib/use-widgets-invalidator.cjs +3 -3
- package/dist/cjs/lib/use-widgets-invalidator.cjs.map +1 -1
- package/dist/cjs/lib/use-widgets-invalidator.d.cts.map +1 -1
- package/dist/cjs/lib/utils.cjs +0 -7
- package/dist/cjs/lib/utils.cjs.map +1 -1
- package/dist/cjs/lib/utils.d.cts +0 -3
- package/dist/cjs/lib/utils.d.cts.map +1 -1
- package/dist/cjs/organization-switcher.client.cjs +2 -1
- package/dist/cjs/organization-switcher.client.cjs.map +1 -1
- package/dist/cjs/pipes-admin.client.cjs +2 -1
- package/dist/cjs/pipes-admin.client.cjs.map +1 -1
- package/dist/cjs/pipes.client.cjs +2 -1
- package/dist/cjs/pipes.client.cjs.map +1 -1
- package/dist/cjs/user-security.client.cjs +2 -1
- package/dist/cjs/user-security.client.cjs.map +1 -1
- package/dist/cjs/user-sessions.client.cjs +2 -1
- package/dist/cjs/user-sessions.client.cjs.map +1 -1
- package/dist/cjs/widgets/api-keys/api-keys-search.cjs +1 -1
- package/dist/cjs/widgets/api-keys/api-keys-search.cjs.map +1 -1
- package/dist/cjs/widgets/api-keys/user-api-keys-search.cjs +1 -1
- package/dist/cjs/widgets/api-keys/user-api-keys-search.cjs.map +1 -1
- package/dist/cjs/widgets/organization-switcher/organization-switcher.cjs +19 -5
- package/dist/cjs/widgets/organization-switcher/organization-switcher.cjs.map +1 -1
- package/dist/cjs/widgets/organization-switcher/organization-switcher.d.cts +2 -1
- package/dist/cjs/widgets/organization-switcher/organization-switcher.d.cts.map +1 -1
- package/dist/cjs/widgets/pipes/pipes.cjs +3 -2
- package/dist/cjs/widgets/pipes/pipes.cjs.map +1 -1
- package/dist/cjs/widgets/user-sessions/logout-all-sessions-dialog.cjs +2 -1
- package/dist/cjs/widgets/user-sessions/logout-all-sessions-dialog.cjs.map +1 -1
- package/dist/cjs/widgets/user-sessions/logout-dialog.cjs +2 -1
- package/dist/cjs/widgets/user-sessions/logout-dialog.cjs.map +1 -1
- package/dist/cjs/widgets/users-management/invite-user-dialog.cjs +5 -6
- package/dist/cjs/widgets/users-management/invite-user-dialog.cjs.map +1 -1
- package/dist/cjs/widgets/users-management/users-management-utils.cjs +4 -3
- package/dist/cjs/widgets/users-management/users-management-utils.cjs.map +1 -1
- package/dist/cjs/widgets/users-management/users-management.cjs.map +1 -1
- package/dist/cjs/widgets/users-management/users-search.cjs +1 -1
- package/dist/cjs/widgets/users-management/users-search.cjs.map +1 -1
- package/dist/esm/admin-portal-audit-log-streaming.client.js +2 -1
- package/dist/esm/admin-portal-audit-log-streaming.client.js.map +1 -1
- package/dist/esm/admin-portal-domain-verification.client.js +2 -1
- package/dist/esm/admin-portal-domain-verification.client.js.map +1 -1
- package/dist/esm/admin-portal-sso-connection.client.js +2 -1
- package/dist/esm/admin-portal-sso-connection.client.js.map +1 -1
- package/dist/esm/api/api-provider.d.ts.map +1 -1
- package/dist/esm/api/api-provider.js +23 -1
- package/dist/esm/api/api-provider.js.map +1 -1
- package/dist/esm/api/claims.d.ts +2 -1
- package/dist/esm/api/claims.d.ts.map +1 -1
- package/dist/esm/api/claims.js.map +1 -1
- package/dist/esm/api/client-graphql/client.js +3 -2
- package/dist/esm/api/client-graphql/client.js.map +1 -1
- package/dist/esm/api/client-graphql/hooks.d.ts +3 -12
- package/dist/esm/api/client-graphql/hooks.d.ts.map +1 -1
- package/dist/esm/api/client-graphql/hooks.js +1 -18
- package/dist/esm/api/client-graphql/hooks.js.map +1 -1
- package/dist/esm/api/client-graphql/query-keys.d.ts +16 -0
- package/dist/esm/api/client-graphql/query-keys.d.ts.map +1 -0
- package/dist/esm/api/client-graphql/query-keys.js +23 -0
- package/dist/esm/api/client-graphql/query-keys.js.map +1 -0
- package/dist/esm/components/copy-text.js +1 -1
- package/dist/esm/components/copy-text.js.map +1 -1
- package/dist/esm/components/form.d.ts.map +1 -1
- package/dist/esm/components/form.js +9 -13
- package/dist/esm/components/form.js.map +1 -1
- package/dist/esm/components/otp-input.js +1 -0
- package/dist/esm/components/otp-input.js.map +1 -1
- package/dist/esm/directory-sync.client.js +2 -1
- package/dist/esm/directory-sync.client.js.map +1 -1
- package/dist/esm/lib/api/api-key.js +2 -1
- package/dist/esm/lib/api/api-key.js.map +1 -1
- package/dist/esm/lib/api/me.js +2 -1
- package/dist/esm/lib/api/me.js.map +1 -1
- package/dist/esm/lib/api/pipes.js +2 -1
- package/dist/esm/lib/api/pipes.js.map +1 -1
- package/dist/esm/lib/api/user-api-key.js +2 -1
- package/dist/esm/lib/api/user-api-key.js.map +1 -1
- package/dist/esm/lib/i18n/intl-context.d.ts +1 -0
- package/dist/esm/lib/i18n/intl-context.d.ts.map +1 -1
- package/dist/esm/lib/i18n/intl-context.js.map +1 -1
- package/dist/esm/lib/i18n/use-translation.js +2 -2
- package/dist/esm/lib/i18n/use-translation.js.map +1 -1
- package/dist/esm/lib/use-composed-event-handlers.d.ts +6 -0
- package/dist/esm/lib/use-composed-event-handlers.d.ts.map +1 -0
- package/dist/esm/lib/use-composed-event-handlers.js +12 -0
- package/dist/esm/lib/use-composed-event-handlers.js.map +1 -0
- package/dist/esm/lib/use-debounce.d.ts +53 -48
- package/dist/esm/lib/use-debounce.d.ts.map +1 -1
- package/dist/esm/lib/use-debounce.js +124 -116
- package/dist/esm/lib/use-debounce.js.map +1 -1
- package/dist/esm/lib/use-widgets-invalidator.d.ts.map +1 -1
- package/dist/esm/lib/use-widgets-invalidator.js +2 -2
- package/dist/esm/lib/use-widgets-invalidator.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +0 -3
- package/dist/esm/lib/utils.d.ts.map +1 -1
- package/dist/esm/lib/utils.js +1 -7
- package/dist/esm/lib/utils.js.map +1 -1
- package/dist/esm/organization-switcher.client.js +2 -1
- package/dist/esm/organization-switcher.client.js.map +1 -1
- package/dist/esm/pipes-admin.client.js +2 -1
- package/dist/esm/pipes-admin.client.js.map +1 -1
- package/dist/esm/pipes.client.js +2 -1
- package/dist/esm/pipes.client.js.map +1 -1
- package/dist/esm/user-security.client.js +2 -1
- package/dist/esm/user-security.client.js.map +1 -1
- package/dist/esm/user-sessions.client.js +2 -1
- package/dist/esm/user-sessions.client.js.map +1 -1
- package/dist/esm/widgets/api-keys/api-keys-search.js +1 -1
- package/dist/esm/widgets/api-keys/api-keys-search.js.map +1 -1
- package/dist/esm/widgets/api-keys/user-api-keys-search.js +1 -1
- package/dist/esm/widgets/api-keys/user-api-keys-search.js.map +1 -1
- package/dist/esm/widgets/organization-switcher/organization-switcher.d.ts +2 -1
- package/dist/esm/widgets/organization-switcher/organization-switcher.d.ts.map +1 -1
- package/dist/esm/widgets/organization-switcher/organization-switcher.js +19 -5
- package/dist/esm/widgets/organization-switcher/organization-switcher.js.map +1 -1
- package/dist/esm/widgets/pipes/pipes.js +2 -1
- package/dist/esm/widgets/pipes/pipes.js.map +1 -1
- package/dist/esm/widgets/user-sessions/logout-all-sessions-dialog.js +2 -1
- package/dist/esm/widgets/user-sessions/logout-all-sessions-dialog.js.map +1 -1
- package/dist/esm/widgets/user-sessions/logout-dialog.js +2 -1
- package/dist/esm/widgets/user-sessions/logout-dialog.js.map +1 -1
- package/dist/esm/widgets/users-management/invite-user-dialog.js +5 -6
- package/dist/esm/widgets/users-management/invite-user-dialog.js.map +1 -1
- package/dist/esm/widgets/users-management/users-management-utils.js +2 -1
- package/dist/esm/widgets/users-management/users-management-utils.js.map +1 -1
- package/dist/esm/widgets/users-management/users-management.js.map +1 -1
- package/dist/esm/widgets/users-management/users-search.js +1 -1
- package/dist/esm/widgets/users-management/users-search.js.map +1 -1
- package/package.json +1 -1
- package/src/api/api-provider.tsx +39 -1
- package/src/api/claims.ts +2 -1
- package/src/api/client-graphql/client.ts +8 -2
- package/src/api/client-graphql/hooks.ts +8 -27
- package/src/api/client-graphql/query-keys.ts +29 -0
- package/src/components/copy-text.tsx +1 -1
- package/src/components/form.tsx +33 -29
- package/src/components/otp-input.tsx +2 -0
- package/src/lib/i18n/intl-context.tsx +4 -0
- package/src/lib/i18n/use-translation.ts +1 -4
- package/src/lib/use-composed-event-handlers.ts +25 -0
- package/src/lib/use-debounce.ts +289 -237
- package/src/lib/use-widgets-invalidator.ts +0 -4
- package/src/lib/utils.ts +0 -12
- package/src/widgets/api-keys/api-keys-search.tsx +6 -3
- package/src/widgets/api-keys/user-api-keys-search.tsx +6 -3
- package/src/widgets/organization-switcher/organization-switcher.tsx +32 -8
- package/src/widgets/users-management/invite-user-dialog.tsx +9 -11
- package/src/widgets/users-management/users-management.tsx +1 -1
- package/src/widgets/users-management/users-search.tsx +6 -3
|
@@ -120,9 +120,15 @@ function createClientSdk(
|
|
|
120
120
|
async (action, _operationName, operationType, _variables) => {
|
|
121
121
|
const queryType: QueryType =
|
|
122
122
|
operationType === "mutation" ? "mutation" : "query";
|
|
123
|
+
const queryData = queryClient.getQueryData<AuthTokenQueryData>(
|
|
124
|
+
authTokenQueryKey(widgetType),
|
|
125
|
+
);
|
|
126
|
+
// Read the cached token at request time: the rendered `authToken` may lag
|
|
127
|
+
// behind the cache until React re-renders after a token refetch.
|
|
128
|
+
const token = queryData?.authToken ?? authToken;
|
|
123
129
|
|
|
124
130
|
try {
|
|
125
|
-
return await action(buildHeaders(
|
|
131
|
+
return await action(buildHeaders(token, widgetType));
|
|
126
132
|
} catch (error) {
|
|
127
133
|
let finalError: unknown = error;
|
|
128
134
|
if (error instanceof ClientError && isAuthError(error)) {
|
|
@@ -135,7 +141,7 @@ function createClientSdk(
|
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
|
|
138
|
-
if (freshToken && freshToken !==
|
|
144
|
+
if (freshToken && freshToken !== token) {
|
|
139
145
|
try {
|
|
140
146
|
return await action(buildHeaders(freshToken, widgetType));
|
|
141
147
|
} catch (retryError) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import type {
|
|
3
|
-
QueryKey,
|
|
4
3
|
UseMutationOptions,
|
|
5
4
|
UseQueryOptions,
|
|
6
5
|
} from "@tanstack/react-query";
|
|
@@ -8,32 +7,14 @@ import { useApiReady } from "../api-provider.js";
|
|
|
8
7
|
import { useClientGraphql } from "./client.js";
|
|
9
8
|
import type { Sdk } from "./generated.js";
|
|
10
9
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return queryKey[0] === CLIENT_GRAPHQL_KEY_PREFIX;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* React Query key for a Client GraphQL operation. Omit `variables` to address
|
|
24
|
-
* every cached page/variant of an operation, e.g. when invalidating after a
|
|
25
|
-
* mutation:
|
|
26
|
-
*
|
|
27
|
-
* queryClient.invalidateQueries({ queryKey: clientGraphqlQueryKey("Sessions") });
|
|
28
|
-
*/
|
|
29
|
-
export function clientGraphqlQueryKey<K extends ClientGraphqlOperation>(
|
|
30
|
-
operation: K,
|
|
31
|
-
variables?: ClientGraphqlVariables<K>,
|
|
32
|
-
): QueryKey {
|
|
33
|
-
return variables === undefined
|
|
34
|
-
? [CLIENT_GRAPHQL_KEY_PREFIX, operation]
|
|
35
|
-
: [CLIENT_GRAPHQL_KEY_PREFIX, operation, variables];
|
|
36
|
-
}
|
|
10
|
+
export {
|
|
11
|
+
clientGraphqlQueryKey,
|
|
12
|
+
isClientGraphqlQueryKey,
|
|
13
|
+
} from "./query-keys.js";
|
|
14
|
+
export type {
|
|
15
|
+
ClientGraphqlOperation,
|
|
16
|
+
ClientGraphqlVariables,
|
|
17
|
+
} from "./query-keys.js";
|
|
37
18
|
|
|
38
19
|
type ClientGraphqlQueryOptions<TResult, TData> = Omit<
|
|
39
20
|
UseQueryOptions<TResult, Error, TData>,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { QueryKey } from "@tanstack/react-query";
|
|
2
|
+
import type { Sdk } from "./generated.js";
|
|
3
|
+
|
|
4
|
+
export type ClientGraphqlOperation = keyof Sdk;
|
|
5
|
+
|
|
6
|
+
export type ClientGraphqlVariables<K extends ClientGraphqlOperation> =
|
|
7
|
+
Parameters<Sdk[K]>[0];
|
|
8
|
+
|
|
9
|
+
const CLIENT_GRAPHQL_KEY_PREFIX = "client-graphql";
|
|
10
|
+
|
|
11
|
+
export function isClientGraphqlQueryKey(queryKey: QueryKey): boolean {
|
|
12
|
+
return queryKey[0] === CLIENT_GRAPHQL_KEY_PREFIX;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React Query key for a Client GraphQL operation. Omit `variables` to address
|
|
17
|
+
* every cached page/variant of an operation, e.g. when invalidating after a
|
|
18
|
+
* mutation:
|
|
19
|
+
*
|
|
20
|
+
* queryClient.invalidateQueries({ queryKey: clientGraphqlQueryKey("Sessions") });
|
|
21
|
+
*/
|
|
22
|
+
export function clientGraphqlQueryKey<K extends ClientGraphqlOperation>(
|
|
23
|
+
operation: K,
|
|
24
|
+
variables?: ClientGraphqlVariables<K>,
|
|
25
|
+
): QueryKey {
|
|
26
|
+
return variables === undefined
|
|
27
|
+
? [CLIENT_GRAPHQL_KEY_PREFIX, operation]
|
|
28
|
+
: [CLIENT_GRAPHQL_KEY_PREFIX, operation, variables];
|
|
29
|
+
}
|
|
@@ -56,7 +56,7 @@ const CopyText: React.FC<CopyTextProps> = ({ value, label }) => {
|
|
|
56
56
|
title={copyLabel}
|
|
57
57
|
variant="ghost"
|
|
58
58
|
size="1"
|
|
59
|
-
aria-
|
|
59
|
+
aria-label={copyLabel}
|
|
60
60
|
className={namespaceClassName("copy-text__copy")}
|
|
61
61
|
onClick={async (event) => {
|
|
62
62
|
const button = event.currentTarget;
|
package/src/components/form.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Slot } from "@radix-ui/themes";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { useComposedRefs } from "../lib/compose-refs.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useComposedEventHandlers } from "../lib/use-composed-event-handlers.js";
|
|
6
6
|
|
|
7
7
|
/* -------------------------------------------------------------------------------------------------
|
|
8
8
|
* Form
|
|
@@ -195,12 +195,12 @@ const Form = /* @__PURE__ */ React.forwardRef<FormElement, FormProps>(
|
|
|
195
195
|
<ValidationContext.Provider
|
|
196
196
|
value={React.useMemo(
|
|
197
197
|
() => ({
|
|
198
|
-
getFieldValidity
|
|
198
|
+
getFieldValidity,
|
|
199
199
|
onFieldValidityChange: handleFieldValidityChange,
|
|
200
|
-
getFieldCustomMatcherEntries
|
|
200
|
+
getFieldCustomMatcherEntries,
|
|
201
201
|
onFieldCustomMatcherEntryAdd: handleFieldCustomMatcherAdd,
|
|
202
202
|
onFieldCustomMatcherEntryRemove: handleFieldCustomMatcherRemove,
|
|
203
|
-
getFieldCustomErrors
|
|
203
|
+
getFieldCustomErrors,
|
|
204
204
|
onFieldCustomErrorsChange: handleFieldCustomErrorsChange,
|
|
205
205
|
onFieldValiditionClear: handleFieldValiditionClear,
|
|
206
206
|
}),
|
|
@@ -234,23 +234,29 @@ const Form = /* @__PURE__ */ React.forwardRef<FormElement, FormProps>(
|
|
|
234
234
|
{...rootProps}
|
|
235
235
|
ref={composedFormRef}
|
|
236
236
|
// focus first invalid control when the form is submitted
|
|
237
|
-
onInvalid={
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
237
|
+
onInvalid={useComposedEventHandlers(
|
|
238
|
+
props.onInvalid,
|
|
239
|
+
React.useCallback((event) => {
|
|
240
|
+
const firstInvalidControl = getFirstInvalidControl(
|
|
241
|
+
event.currentTarget,
|
|
242
|
+
);
|
|
243
|
+
if (firstInvalidControl === event.target)
|
|
244
|
+
firstInvalidControl.focus();
|
|
245
|
+
|
|
246
|
+
// prevent default browser UI for form validation
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
}, []),
|
|
249
|
+
)}
|
|
247
250
|
// clear server errors when the form is re-submitted
|
|
248
251
|
onSubmit={(event) => {
|
|
249
252
|
props.onSubmit?.(event);
|
|
250
253
|
onClearServerErrors();
|
|
251
254
|
}}
|
|
252
255
|
// clear server errors when the form is reset
|
|
253
|
-
onReset={
|
|
256
|
+
onReset={useComposedEventHandlers(
|
|
257
|
+
props.onReset,
|
|
258
|
+
onClearServerErrors,
|
|
259
|
+
)}
|
|
254
260
|
/>
|
|
255
261
|
</AriaDescriptionContext.Provider>
|
|
256
262
|
</ValidationContext.Provider>
|
|
@@ -436,7 +442,8 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
|
|
|
436
442
|
onFieldValiditionClear,
|
|
437
443
|
} = validationContext;
|
|
438
444
|
const updateControlValidity = React.useCallback(
|
|
439
|
-
async (
|
|
445
|
+
async (event: { currentTarget: FormControlElement }) => {
|
|
446
|
+
const { currentTarget: control } = event;
|
|
440
447
|
//------------------------------------------------------------------------------------------
|
|
441
448
|
// 1. first, if we have built-in errors we stop here
|
|
442
449
|
|
|
@@ -515,9 +522,11 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
|
|
|
515
522
|
React.useEffect(() => {
|
|
516
523
|
const control = ref.current;
|
|
517
524
|
if (control) {
|
|
518
|
-
// We only want validate on change (native `change` event, not React's
|
|
519
|
-
// a UX decision, we don't want to validate
|
|
520
|
-
|
|
525
|
+
// We only want validate on change (native `change` event, not React's
|
|
526
|
+
// `onChange`). This is primarily a UX decision, we don't want to validate
|
|
527
|
+
// on every keystroke and React's `onChange` is the `input` event.
|
|
528
|
+
const handleChange = () =>
|
|
529
|
+
updateControlValidity({ currentTarget: control });
|
|
521
530
|
control.addEventListener("change", handleChange);
|
|
522
531
|
return () => control.removeEventListener("change", handleChange);
|
|
523
532
|
}
|
|
@@ -577,16 +586,11 @@ const FormControl = /* @__PURE__ */ React.forwardRef<
|
|
|
577
586
|
ref={composedRef}
|
|
578
587
|
id={id}
|
|
579
588
|
name={name}
|
|
580
|
-
onInvalid={
|
|
581
|
-
|
|
582
|
-
updateControlValidity
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
// oxlint-disable-next-line react/refs
|
|
586
|
-
onChange={composeEventHandlers(props.onChange, () => {
|
|
587
|
-
// reset validity when user changes value
|
|
588
|
-
resetControlValidity();
|
|
589
|
-
})}
|
|
589
|
+
onInvalid={useComposedEventHandlers(
|
|
590
|
+
props.onInvalid,
|
|
591
|
+
updateControlValidity,
|
|
592
|
+
)}
|
|
593
|
+
onChange={useComposedEventHandlers(props.onChange, resetControlValidity)}
|
|
590
594
|
/>
|
|
591
595
|
);
|
|
592
596
|
});
|
|
@@ -16,6 +16,10 @@ type MessageValues = Record<string, string | React.ReactNode>;
|
|
|
16
16
|
*/
|
|
17
17
|
interface IntlContextValue {
|
|
18
18
|
locale: string;
|
|
19
|
+
formatMessage(
|
|
20
|
+
descriptor: MessageDescriptor,
|
|
21
|
+
values?: Record<string, string>,
|
|
22
|
+
): string;
|
|
19
23
|
formatMessage(
|
|
20
24
|
descriptor: MessageDescriptor,
|
|
21
25
|
values?: MessageValues,
|
|
@@ -24,10 +24,7 @@ export function useTranslation() {
|
|
|
24
24
|
|
|
25
25
|
// If I18nProvider is present, use react-intl's formatMessage
|
|
26
26
|
if (formatMessage) {
|
|
27
|
-
|
|
28
|
-
return String(
|
|
29
|
-
formatMessage({ id, defaultMessage, description }, values),
|
|
30
|
-
);
|
|
27
|
+
return formatMessage({ id, defaultMessage, description }, values);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
// If no I18nProvider is present, return defaultMessage with simple interpolation
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export function useComposedEventHandlers<
|
|
4
|
+
E extends { defaultPrevented: boolean },
|
|
5
|
+
>(
|
|
6
|
+
originalEventHandler?: (event: E) => void,
|
|
7
|
+
ourEventHandler?: (event: E) => void,
|
|
8
|
+
): (event: E) => void;
|
|
9
|
+
|
|
10
|
+
export function useComposedEventHandlers<
|
|
11
|
+
E extends { defaultPrevented: boolean },
|
|
12
|
+
>(
|
|
13
|
+
originalEventHandler?: (event: E) => void,
|
|
14
|
+
ourEventHandler?: (event: E) => void,
|
|
15
|
+
): (event: E) => void {
|
|
16
|
+
return React.useCallback(
|
|
17
|
+
(event: E) => {
|
|
18
|
+
originalEventHandler?.(event);
|
|
19
|
+
if (!event?.defaultPrevented) {
|
|
20
|
+
ourEventHandler?.(event);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[originalEventHandler, ourEventHandler],
|
|
24
|
+
);
|
|
25
|
+
}
|