@mittwald/flow-react-components 1.7.0-next.0 → 1.7.0-next.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/dist/assets/component-index.json +1 -1
- package/dist/assets/doc-properties.json +1 -1
- package/dist/js/_virtual/_30.locale.mjs +4 -0
- package/dist/js/_virtual/_36.locale.mjs +2 -0
- package/dist/js/packages/components/src/components/FieldError/FieldError.mjs +1 -1
- package/dist/js/packages/components/src/components/FieldError/FieldError.mjs.map +1 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/PasswordCreationField.mjs +6 -7
- package/dist/js/packages/components/src/components/PasswordCreationField/PasswordCreationField.mjs.map +1 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/components/ValidationResultEntry/ValidationResultEntry.mjs +3 -7
- package/dist/js/packages/components/src/components/PasswordCreationField/components/ValidationResultEntry/ValidationResultEntry.mjs.map +1 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/lib/generateValidationTranslation.mjs +16 -1
- package/dist/js/packages/components/src/components/PasswordCreationField/lib/generateValidationTranslation.mjs.map +1 -1
- package/dist/js/packages/components/src/integrations/react-hook-form/components/Field/Field.mjs +6 -1
- package/dist/js/packages/components/src/integrations/react-hook-form/components/Field/Field.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/hooks/useFieldComponent.mjs.map +1 -1
- package/dist/js/packages/components/src/lib/hooks/useFieldError.mjs +15 -5
- package/dist/js/packages/components/src/lib/hooks/useFieldError.mjs.map +1 -1
- package/dist/types/lib/hooks/useFieldComponent.d.ts +2 -1
- package/dist/types/lib/hooks/useFieldError.d.ts +5 -1
- package/package.json +10 -10
|
@@ -32,6 +32,8 @@ var __locale_default = {
|
|
|
32
32
|
"validation.charPool.special.min": "{min, plural, one {Bitte verwende mindestens ein Sonderzeichen.} other {Bitte verwende mindestens {min} Sonderzeichen.}}",
|
|
33
33
|
"validation.charPool.special.min.short": "{min, plural, one {Mindestens ein Sonderzeichen} other {Mindestens {min} Sonderzeichen}}",
|
|
34
34
|
"validation.general.failingComplexity": "Bitte erhöhe die Komplexität deines Passwortes.",
|
|
35
|
+
"validation.general.fallback": "{isValid, select, true {Das Passwort erfüllt die Anforderungen.} other {Das Passwort erfüllt die Anforderungen nicht.}}",
|
|
36
|
+
"validation.general.fallback.short": "Weitere Anforderung",
|
|
35
37
|
"validation.general.optimizeComplexity": "Dein Passwort erfüllt die Minimalanforderungen.",
|
|
36
38
|
"validation.general.securePassword": "Sehr gut! Dein Passwort ist sicher.",
|
|
37
39
|
"validation.general.short.unspecified": "Keine spezifischen Anforderungen",
|
|
@@ -78,6 +80,8 @@ var __locale_default = {
|
|
|
78
80
|
"validation.charPool.special.min": "{min, plural, one {Please use at least one special character.} other {Please use at least {min} special characters.}}",
|
|
79
81
|
"validation.charPool.special.min.short": "{min, plural, one {At least one special character} other {At least {min} special characters}}",
|
|
80
82
|
"validation.general.failingComplexity": "Please increase the complexity of your password.",
|
|
83
|
+
"validation.general.fallback": "{isValid, select, true {The password meets the requirements.} other {The password does not meet the requirements.}}",
|
|
84
|
+
"validation.general.fallback.short": "Additional requirement",
|
|
81
85
|
"validation.general.optimizeComplexity": "Your password meets the minimum requirements.",
|
|
82
86
|
"validation.general.securePassword": "Awesome! Your password is secure.",
|
|
83
87
|
"validation.general.short.unspecified": "No specific requirements",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// \0.locale.json@72ba2ce40f190df671686fec50c04ddf
|
|
4
4
|
var __locale_default = {
|
|
5
5
|
"de-DE": {
|
|
6
|
+
"validation.invalid": "Bitte überprüfe deine Eingabe",
|
|
6
7
|
"validation.max": "Maximale Anzahl von {number} erreicht",
|
|
7
8
|
"validation.maxLength": "Bitte gib höchstens {number} Zeichen ein",
|
|
8
9
|
"validation.min": "Minimale Anzahl von {number} noch nicht erreicht",
|
|
@@ -11,6 +12,7 @@ var __locale_default = {
|
|
|
11
12
|
"validation.required": "Dieses Feld ist erforderlich"
|
|
12
13
|
},
|
|
13
14
|
"en-US": {
|
|
15
|
+
"validation.invalid": "Please check your input",
|
|
14
16
|
"validation.max": "Maximum number of {number} reached",
|
|
15
17
|
"validation.maxLength": "Please enter at most {number} characters",
|
|
16
18
|
"validation.min": "Minimum number of {number} has not yet been reached",
|
|
@@ -16,7 +16,7 @@ import { FieldErrorContext, TextContext } from "react-aria-components";
|
|
|
16
16
|
// src/components/FieldError/FieldError.tsx
|
|
17
17
|
/** @flr-generate all */
|
|
18
18
|
var FieldError = flowComponent("FieldError", (props) => {
|
|
19
|
-
const { children, className, ref, renderAlert, ...rest } = props;
|
|
19
|
+
const { children, className, ref, isFallback: ignoredIsFallback, renderAlert, ...rest } = props;
|
|
20
20
|
const rootClassName = clsx(FieldError_module_default.fieldError, className);
|
|
21
21
|
const isSkeleton = useSkeletonMode();
|
|
22
22
|
const fieldValidation = useContext(FieldErrorContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldError.mjs","names":["styles"],"sources":["../../../../../../../src/components/FieldError/FieldError.tsx"],"sourcesContent":["import React, {\n type PropsWithChildren,\n useContext,\n useLayoutEffect,\n} from \"react\";\nimport styles from \"./FieldError.module.scss\";\nimport * as Aria from \"react-aria-components\";\nimport { FieldErrorContext, TextContext } from \"react-aria-components\";\nimport clsx from \"clsx\";\nimport type { FlowComponentProps } from \"@/lib/componentFactory/flowComponent\";\nimport { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport { AlertText } from \"@/components/AlertText\";\nimport { Alert } from \"@/components/Alert\";\nimport { Heading } from \"@/components/Heading\";\nimport { FieldErrorRenderedContext } from \"@/lib/hooks/fieldErrorRenderedContext\";\nimport { useObjectRef } from \"react-aria\";\nimport { useSkeletonMode } from \"@/components/SkeletonMode/skeletonModeContext\";\n\nexport interface FieldErrorProps\n extends\n PropsWithChildren<Omit<Aria.FieldErrorProps, \"children\">>,\n FlowComponentProps {\n /** @internal */\n renderAlert?: boolean;\n}\n\n/** @flr-generate all */\nexport const FieldError = flowComponent(\"FieldError\", (props) => {\n const {
|
|
1
|
+
{"version":3,"file":"FieldError.mjs","names":["styles"],"sources":["../../../../../../../src/components/FieldError/FieldError.tsx"],"sourcesContent":["import React, {\n type PropsWithChildren,\n useContext,\n useLayoutEffect,\n} from \"react\";\nimport styles from \"./FieldError.module.scss\";\nimport * as Aria from \"react-aria-components\";\nimport { FieldErrorContext, TextContext } from \"react-aria-components\";\nimport clsx from \"clsx\";\nimport type { FlowComponentProps } from \"@/lib/componentFactory/flowComponent\";\nimport { flowComponent } from \"@/lib/componentFactory/flowComponent\";\nimport { AlertText } from \"@/components/AlertText\";\nimport { Alert } from \"@/components/Alert\";\nimport { Heading } from \"@/components/Heading\";\nimport { FieldErrorRenderedContext } from \"@/lib/hooks/fieldErrorRenderedContext\";\nimport { useObjectRef } from \"react-aria\";\nimport { useSkeletonMode } from \"@/components/SkeletonMode/skeletonModeContext\";\n\nexport interface FieldErrorProps\n extends\n PropsWithChildren<Omit<Aria.FieldErrorProps, \"children\">>,\n FlowComponentProps {\n /** @internal */\n isFallback?: boolean;\n /** @internal */\n renderAlert?: boolean;\n}\n\n/** @flr-generate all */\nexport const FieldError = flowComponent(\"FieldError\", (props) => {\n const {\n children,\n className,\n ref,\n isFallback: ignoredIsFallback,\n renderAlert,\n ...rest\n } = props;\n\n const rootClassName = clsx(styles.fieldError, className);\n const isSkeleton = useSkeletonMode();\n const fieldValidation = useContext(FieldErrorContext);\n const reportRendered = useContext(FieldErrorRenderedContext);\n const hasChildren = React.Children.count(children) >= 1;\n\n // Inside a field the field decides whether there is an error – children only\n // provide its message. Without a field, children are the error.\n const isInvalid = fieldValidation ? fieldValidation.isInvalid : hasChildren;\n // A skeleton claims no state, and an error is one.\n const isShown = isInvalid && !isSkeleton;\n\n // Never mutate the context's errors: for a valid field react-aria hands out\n // one module-level array shared by every field of the page.\n const message = hasChildren\n ? children\n : fieldValidation?.validationErrors.at(-1);\n\n const errorState = {\n isInvalid,\n validationDetails: fieldValidation?.validationDetails ?? {\n badInput: false,\n customError: isInvalid,\n patternMismatch: false,\n rangeOverflow: false,\n rangeUnderflow: false,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valid: !isInvalid,\n valueMissing: false,\n },\n validationErrors: message ? [message] : [],\n };\n\n // Report what is actually in the document: inside a collection (`Select`,\n // `ComboBox`) react-aria renders the children a second time into a hidden\n // collection document, where no field context exists and no id resolves.\n const localRef = useObjectRef(ref);\n useLayoutEffect(() => {\n const element = localRef.current;\n if (!reportRendered || !isShown || !element?.isConnected || !element.id) {\n return;\n }\n reportRendered(element.id);\n return () => reportRendered(undefined);\n }, [reportRendered, isShown, rest.id, localRef]);\n\n if (!isShown) {\n return undefined;\n }\n\n return (\n <Aria.Provider values={[[TextContext, { slot: undefined }]]}>\n <FieldErrorContext value={errorState as never}>\n <Aria.FieldError ref={localRef} {...rest} className={rootClassName}>\n {({ validationErrors }) => {\n return renderAlert ? (\n <Alert status=\"danger\">\n <Heading>{validationErrors}</Heading>\n </Alert>\n ) : (\n <AlertText status=\"danger\">{validationErrors}</AlertText>\n );\n }}\n </Aria.FieldError>\n </FieldErrorContext>\n </Aria.Provider>\n );\n});\n\nexport default FieldError;\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,IAAa,aAAa,cAAc,eAAe,UAAU;CAC/D,MAAM,EACJ,UACA,WACA,KACA,YAAY,mBACZ,aACA,GAAG,SACD;CAEJ,MAAM,gBAAgB,KAAKA,0BAAO,YAAY,SAAS;CACvD,MAAM,aAAa,gBAAgB;CACnC,MAAM,kBAAkB,WAAW,iBAAiB;CACpD,MAAM,iBAAiB,WAAW,yBAAyB;CAC3D,MAAM,cAAc,MAAM,SAAS,MAAM,QAAQ,KAAK;CAItD,MAAM,YAAY,kBAAkB,gBAAgB,YAAY;CAEhE,MAAM,UAAU,aAAa,CAAC;CAI9B,MAAM,UAAU,cACZ,WACA,iBAAiB,iBAAiB,GAAG,EAAE;CAE3C,MAAM,aAAa;EACjB;EACA,mBAAmB,iBAAiB,qBAAqB;GACvD,UAAU;GACV,aAAa;GACb,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GAChB,cAAc;GACd,SAAS;GACT,UAAU;GACV,cAAc;GACd,OAAO,CAAC;GACR,cAAc;EAChB;EACA,kBAAkB,UAAU,CAAC,OAAO,IAAI,CAAC;CAC3C;CAKA,MAAM,WAAW,aAAa,GAAG;CACjC,sBAAsB;EACpB,MAAM,UAAU,SAAS;EACzB,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,SAAS,eAAe,CAAC,QAAQ,IACnE;EAEF,eAAe,QAAQ,EAAE;EACzB,aAAa,eAAe,KAAA,CAAS;CACvC,GAAG;EAAC;EAAgB;EAAS,KAAK;EAAI;CAAQ,CAAC;CAE/C,IAAI,CAAC,SACH;CAGF,OACE,oBAAC,KAAK,UAAN;EAAe,QAAQ,CAAC,CAAC,aAAa,EAAE,MAAM,KAAA,EAAU,CAAC,CAAC;EACxD,UAAA,oBAAC,mBAAD;GAAmB,OAAO;GACxB,UAAA,oBAAC,KAAK,YAAN;IAAiB,KAAK;IAAU,GAAI;IAAM,WAAW;IACjD,WAAA,EAAE,uBAAuB;KACzB,OAAO,cACL,oBAAC,OAAD;MAAO,QAAO;MACZ,UAAA,oBAAC,SAAD,EAAA,UAAU,iBAA0B,CAAA;KAC/B,CAAA,IAEP,oBAAC,WAAD;MAAW,QAAO;MAAU,UAAA;KAA4B,CAAA;IAE5D;GACe,CAAA;EACA,CAAA;CACN,CAAA;AAEnB,CAAC"}
|
package/dist/js/packages/components/src/components/PasswordCreationField/PasswordCreationField.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { defaultPasswordCreationPolicy } from "../../integrations/@mittwald/pass
|
|
|
14
14
|
import { Policy } from "../../../../../@mittwald/password-tools-js.mjs";
|
|
15
15
|
import getStateFromLatestPolicyValidationResult from "./lib/getStateFromLatestPolicyValidationResult.mjs";
|
|
16
16
|
import __locale_default from "../../../../../_virtual/_30.locale.mjs";
|
|
17
|
-
import
|
|
17
|
+
import { formatValidationResult } from "./lib/generateValidationTranslation.mjs";
|
|
18
18
|
import { ComplexityIndicator } from "./components/ComplexityIndicator/ComplexityIndicator.mjs";
|
|
19
19
|
import { generatePassword } from "./worker/generatePassword.mjs";
|
|
20
20
|
import { TogglePasswordVisibilityButton } from "./components/TogglePasswordVisibilityButton/TogglePasswordVisibilityButton.mjs";
|
|
@@ -49,6 +49,7 @@ var PasswordCreationField = flowComponent("PasswordCreationField", (props) => {
|
|
|
49
49
|
* error and the bar color after every typing pause.
|
|
50
50
|
*/
|
|
51
51
|
const [isValidationPending, setIsValidationPending] = useState(false);
|
|
52
|
+
const [validatedPassword, setValidatedPassword] = useState();
|
|
52
53
|
const loadingRef = useRef(null);
|
|
53
54
|
const { rememberValidationResult } = usePolicyValidationResult(validationPolicy, value ?? "", () => {
|
|
54
55
|
if (isEmptyValue) return;
|
|
@@ -59,6 +60,7 @@ var PasswordCreationField = flowComponent("PasswordCreationField", (props) => {
|
|
|
59
60
|
}, ({ password, isValid, results }) => {
|
|
60
61
|
if (loadingRef.current) clearTimeout(loadingRef.current);
|
|
61
62
|
setIsValidationPending(false);
|
|
63
|
+
setValidatedPassword(password);
|
|
62
64
|
if (isEmptyValue) {
|
|
63
65
|
setPolicyValidationResult(() => ({
|
|
64
66
|
...results,
|
|
@@ -74,12 +76,9 @@ var PasswordCreationField = flowComponent("PasswordCreationField", (props) => {
|
|
|
74
76
|
});
|
|
75
77
|
const isEmptyValue = !value;
|
|
76
78
|
const stateFromValidationResult = getStateFromLatestPolicyValidationResult(isEmptyValue, policyValidationResult);
|
|
77
|
-
|
|
78
|
-
if (stateFromValidationResult) {
|
|
79
|
-
const [translationKey, translationValues] = generateValidationTranslation(stateFromValidationResult);
|
|
80
|
-
latestValidationErrorText = translate.format(translationKey, translationValues);
|
|
81
|
-
}
|
|
79
|
+
const latestValidationErrorText = stateFromValidationResult ? formatValidationResult(translate, stateFromValidationResult) : void 0;
|
|
82
80
|
const isValidFromValidationResult = !isEmptyValue && stateFromValidationResult?.isValid;
|
|
81
|
+
const isPolicyResultPending = !isEmptyValue && validatedPassword !== value;
|
|
83
82
|
const isInvalidFromValidationResult = !isEmptyValue && stateFromValidationResult?.isValid === false;
|
|
84
83
|
const isInvalid = invalidFromProps || isInvalidFromValidationResult;
|
|
85
84
|
const { FieldErrorView, FieldErrorCaptureContext, wrapperProps, controlProps, fieldPropsContext, renderedFieldErrorId, skeletonProps } = useFieldComponent(props, "PasswordCreationField");
|
|
@@ -234,7 +233,7 @@ var PasswordCreationField = flowComponent("PasswordCreationField", (props) => {
|
|
|
234
233
|
})
|
|
235
234
|
})
|
|
236
235
|
]
|
|
237
|
-
}), latestValidationErrorText && /* @__PURE__ */ jsx(FieldError, { children: latestValidationErrorText })] }), /* @__PURE__ */ jsx(FieldErrorView, {})]
|
|
236
|
+
}), isInvalidFromValidationResult && latestValidationErrorText && /* @__PURE__ */ jsx(FieldError, { children: latestValidationErrorText })] }), /* @__PURE__ */ jsx(FieldErrorView, { withoutFallback: isPolicyResultPending })]
|
|
238
237
|
});
|
|
239
238
|
});
|
|
240
239
|
export { PasswordCreationField, PasswordCreationField as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordCreationField.mjs","names":["locales","styles","_Fragment"],"sources":["../../../../../../../src/components/PasswordCreationField/PasswordCreationField.tsx"],"sourcesContent":["import {\n type PropsWithChildren,\n useState,\n type ClipboardEvent,\n useCallback,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport {\n dynamic,\n type PropsContext,\n PropsContextProvider,\n} from \"@/lib/propsContext\";\nimport {\n flowComponent,\n type FlowComponentProps,\n} from \"@/lib/componentFactory/flowComponent\";\nimport styles from \"./PasswordCreationField.module.scss\";\nimport * as Aria from \"react-aria-components\";\nimport clsx from \"clsx\";\nimport { type ActionFn } from \"@/components/Action\";\nimport getStateFromLatestPolicyValidationResult from \"@/components/PasswordCreationField/lib/getStateFromLatestPolicyValidationResult\";\nimport locales from \"./locales/*.locale.json\";\nimport generateValidationTranslation from \"@/components/PasswordCreationField/lib/generateValidationTranslation\";\nimport FieldDescription from \"@/components/FieldDescription\";\nimport ComplexityIndicator from \"@/components/PasswordCreationField/components/ComplexityIndicator/ComplexityIndicator\";\nimport { generatePassword } from \"@/components/PasswordCreationField/worker/generatePassword\";\nimport TogglePasswordVisibilityButton from \"@/components/PasswordCreationField/components/TogglePasswordVisibilityButton/TogglePasswordVisibilityButton\";\nimport { ValidationResultButton } from \"@/components/PasswordCreationField/components/ValidationResultButton/ValidationResultButton\";\nimport { PasswordGenerateButton } from \"@/components/PasswordCreationField/components/PasswordGenerateButton/PasswordGenerateButton\";\nimport type {\n PolicyValidationResult,\n PolicyGenericDeclaration,\n RuleValidationResult,\n} from \"@/integrations/@mittwald/password-tools-js\";\nimport {\n defaultPasswordCreationPolicy,\n Policy,\n} from \"@/integrations/@mittwald/password-tools-js\";\nimport { usePolicyValidationResult } from \"@/components/PasswordCreationField/lib/usePolicyValidationResult\";\nimport { joinIds, useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { FieldError } from \"@/components/FieldError\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport {\n useAriaAnnouncePasswordVisibility,\n useAriaAnnounceValidationState,\n} from \"@/components/PasswordCreationField/lib/ariaAnnounce\";\n\nexport interface PasswordCreationFieldProps\n extends\n PropsWithChildren<\n Omit<Aria.TextFieldProps, \"children\" | \"value\" | \"defaultValue\"> &\n Partial<Pick<Aria.FieldErrorRenderProps, \"validationErrors\">>\n >,\n FlowComponentProps<HTMLInputElement> {\n /** The password of a controlled field. */\n value?: string;\n /** Called with the password and its validity whenever the password changes. */\n onValidationResult?: (result: { password: string; isValid: boolean }) => void;\n /** The initial password of an uncontrolled field. */\n defaultValue?: string;\n /** The placeholder shown while the field is empty. */\n placeholder?: string;\n /**\n * The policy the password is validated against.\n *\n * @default defaultPasswordCreationPolicy\n */\n validationPolicy?: PolicyGenericDeclaration;\n}\n\nexport interface ResolvedPolicyValidationResult extends Omit<\n PolicyValidationResult,\n \"isValid\"\n> {\n isValid: boolean | \"indeterminate\";\n ruleResults: RuleValidationResult[];\n}\n\n/** @flr-generate all */\nexport const PasswordCreationField = flowComponent(\n \"PasswordCreationField\",\n (props) => {\n const {\n children,\n className,\n ref,\n isDisabled,\n onValidationResult,\n isInvalid: invalidFromProps,\n validationPolicy:\n validationPolicyFromProps = defaultPasswordCreationPolicy,\n isRequired,\n value,\n onChange,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n const translate = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n\n const validationPolicy = useMemo(\n () => Policy.fromDeclaration(validationPolicyFromProps),\n [validationPolicyFromProps],\n );\n\n const [isPasswordRevealed, setIsPasswordRevealed] = useState(false);\n const initialPolicyValidationState: ResolvedPolicyValidationResult = {\n isValid: \"indeterminate\",\n complexity: {\n min: validationPolicy.minComplexity,\n actual: 4,\n warning: null,\n },\n ruleResults: [],\n };\n\n const [policyValidationResult, setPolicyValidationResult] = useState(\n initialPolicyValidationState,\n );\n\n /**\n * A validation that outlasts the delay shows the loading bar, but keeps the\n * previous result until the new one arrives – dropping it flickered the\n * error and the bar color after every typing pause.\n */\n const [isValidationPending, setIsValidationPending] = useState(false);\n const loadingRef = useRef<ReturnType<typeof setTimeout>>(null);\n const { rememberValidationResult } = usePolicyValidationResult(\n validationPolicy,\n value ?? \"\",\n () => {\n if (isEmptyValue) {\n return;\n }\n\n if (loadingRef.current) {\n clearTimeout(loadingRef.current);\n }\n loadingRef.current = setTimeout(() => {\n setIsValidationPending(true);\n }, 150);\n },\n ({ password, isValid, results }) => {\n if (loadingRef.current) {\n clearTimeout(loadingRef.current);\n }\n setIsValidationPending(false);\n\n if (isEmptyValue) {\n setPolicyValidationResult(() => ({\n ...results,\n isValid: true,\n }));\n return;\n }\n\n setPolicyValidationResult(() => results);\n onValidationResult?.({ password, isValid });\n },\n );\n\n const isEmptyValue = !value;\n const stateFromValidationResult = getStateFromLatestPolicyValidationResult(\n isEmptyValue,\n policyValidationResult,\n );\n let latestValidationErrorText = undefined;\n if (stateFromValidationResult) {\n const [translationKey, translationValues] = generateValidationTranslation(\n stateFromValidationResult,\n );\n latestValidationErrorText = translate.format(\n translationKey,\n translationValues,\n );\n }\n\n const isValidFromValidationResult =\n !isEmptyValue && stateFromValidationResult?.isValid;\n\n const isInvalidFromValidationResult =\n !isEmptyValue && stateFromValidationResult?.isValid === false;\n const isInvalid = invalidFromProps || isInvalidFromValidationResult;\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n wrapperProps,\n controlProps,\n fieldPropsContext,\n renderedFieldErrorId,\n skeletonProps,\n } = useFieldComponent(props, \"PasswordCreationField\");\n\n /**\n * The result for a valid password appears after the asynchronous policy\n * validation. react-aria resolves its description slot only when the\n * field's validity changes, so a result that appears while the field stays\n * valid (a generated password) was never linked. It gets its own id\n * instead, referenced only while it is rendered.\n *\n * A shown error replaces it: the FormField styles hide descriptions next to\n * an error, and a hidden description would still be announced.\n */\n const resultDescriptionId = useId();\n const [isResultDescriptionRendered, setIsResultDescriptionRendered] =\n useState(false);\n const resultDescriptionRef = useCallback((element: Element | null) => {\n setIsResultDescriptionRendered(!!element);\n }, []);\n const describedBy = joinIds(\n isResultDescriptionRendered && resultDescriptionId,\n controlProps[\"aria-describedby\"],\n );\n\n useAriaAnnounceValidationState(\n latestValidationErrorText,\n !isEmptyValue && policyValidationResult.isValid !== \"indeterminate\",\n );\n useAriaAnnouncePasswordVisibility(isPasswordRevealed);\n\n const setOptimisticPolicyValidationResult = (\n state: Partial<ResolvedPolicyValidationResult> = {},\n ) => {\n setPolicyValidationResult((currentState) => ({\n ...currentState,\n isValid: true,\n ...state,\n }));\n };\n\n const onPasswordGenerateHandler: ActionFn = async () => {\n const generatedPassword = await generatePassword(validationPolicy);\n /**\n * The generator returns only passwords the policy accepts, so the rating\n * is set with the password instead of after the typing debounce. It is\n * the policy's own result: a guessed one (full strength) was overturned\n * by the real rating, e.g. to \"meets the minimum requirements\". Cached,\n * so the debounced validation of this password does not rate it again.\n */\n const generatedPasswordResult =\n await validationPolicy.validate(generatedPassword);\n rememberValidationResult(generatedPassword, generatedPasswordResult);\n setPolicyValidationResult(generatedPasswordResult);\n setIsPasswordRevealed(true);\n onChange(generatedPassword);\n };\n\n const onPasswordPasteHandler = (event: ClipboardEvent) => {\n const pastedValue = event.clipboardData?.getData(\"text\");\n if (typeof pastedValue === \"string\" && pastedValue !== value) {\n setOptimisticPolicyValidationResult({\n isValid: \"indeterminate\",\n });\n }\n };\n\n const togglePasswordVisibilityHandler = () => {\n setIsPasswordRevealed((old) => !old);\n };\n\n const propsContext: PropsContext = {\n ...fieldPropsContext,\n Button: {\n tunnel: {\n id: \"button\",\n component: \"PasswordCreationField\",\n },\n size: \"m\",\n variant: \"plain\",\n color: \"secondary\",\n isDisabled: isDisabled,\n className: styles.button,\n },\n CopyButton: {\n tunnel: {\n id: \"button\",\n component: \"PasswordCreationField\",\n },\n size: \"m\",\n variant: \"plain\",\n color: \"secondary\",\n isDisabled: isDisabled,\n className: styles.button,\n text: value,\n },\n Label: {\n ...fieldPropsContext.Label,\n children: dynamic((localProps) => {\n return (\n <>\n {localProps.children}\n <PasswordGenerateButton\n isDisabled={isDisabled}\n onGeneratePasswordAction={onPasswordGenerateHandler}\n />\n <ValidationResultButton\n isEmptyValue={isEmptyValue}\n isDisabled={isDisabled}\n policyValidationResult={policyValidationResult}\n />\n </>\n );\n }),\n },\n };\n\n return (\n <Aria.TextField\n {...rest}\n {...skeletonProps}\n aria-describedby={describedBy}\n value={value}\n type={isPasswordRevealed ? \"text\" : \"password\"}\n onChange={onChange}\n onPaste={onPasswordPasteHandler}\n className={clsx(wrapperProps.className, className)}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isRequired={isRequired}\n >\n <FieldErrorCaptureContext>\n <PropsContextProvider\n props={propsContext}\n dependencies={[\n isDisabled,\n isRequired,\n value,\n policyValidationResult,\n isEmptyValue,\n ]}\n >\n {children}\n <Aria.Group\n isDisabled={isDisabled}\n className={clsx(styles.inputGroup)}\n >\n <Aria.Input ref={ref} className={styles.input} />\n <Aria.Group className={styles.buttonContainer}>\n <TogglePasswordVisibilityButton\n className={styles.button}\n isVisible={isPasswordRevealed}\n isDisabled={isDisabled}\n onPress={togglePasswordVisibilityHandler}\n />\n <UiComponentTunnelExit\n id=\"button\"\n component=\"PasswordCreationField\"\n />\n </Aria.Group>\n <ComplexityIndicator\n key={value}\n isEmptyValue={isEmptyValue}\n isLoading={\n isValidationPending ||\n policyValidationResult.isValid === \"indeterminate\"\n }\n policyValidationResult={policyValidationResult}\n validationResultState={stateFromValidationResult}\n isInvalid={invalidFromProps}\n />\n </Aria.Group>\n {isValidFromValidationResult && !renderedFieldErrorId && (\n // Out of react-aria's description slot, which would set its own\n // id – see `resultDescriptionId`.\n <Aria.TextContext.Provider value={null}>\n <FieldDescription\n id={resultDescriptionId}\n ref={resultDescriptionRef}\n >\n {latestValidationErrorText}\n </FieldDescription>\n </Aria.TextContext.Provider>\n )}\n </PropsContextProvider>\n {/* After `children`: the field shows the first error in the tree, and\n a consumer's error wins over the policy's. */}\n {latestValidationErrorText && (\n <FieldError>{latestValidationErrorText}</FieldError>\n )}\n </FieldErrorCaptureContext>\n <FieldErrorView />\n </Aria.TextField>\n );\n },\n);\n\nexport default PasswordCreationField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,IAAa,wBAAwB,cACnC,0BACC,UAAU;CACT,MAAM,EACJ,UACA,WACA,KACA,YACA,oBACA,WAAW,kBACX,kBACE,4BAA4B,+BAC9B,YACA,OACA,UACA,GAAG,SACD,4BAA4B,OAAO,EAAE;CAEzC,MAAM,YAAY,4BAChBA,kBACA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MACc;MACZ,0BAA0B;KAC3B,CAAA;KACD,oBAAC,wBAAD;MACgB;MACF;MACY;KACzB,CAAA;IACD,EAAA,CAAA;GAEN,CAAC;EACH;CACF;CAEA,OACE,qBAAC,KAAK,WAAN;EACE,GAAI;EACJ,GAAI;EACJ,oBAAkB;EACX;EACP,MAAM,qBAAqB,SAAS;EAC1B;EACV,SAAS;EACT,WAAW,KAAK,aAAa,WAAW,SAAS;EACrC;EACD;EACC;EAXd,UAAA,CAaE,qBAAC,0BAAD,EAAA,UAAA,CACE,qBAAC,sBAAD;GACE,OAAO;GACP,cAAc;IACZ;IACA;IACA;IACA;IACA;GACF;GARF,UAAA;IAUG;IACD,qBAAC,KAAK,OAAN;KACc;KACZ,WAAW,KAAKD,qCAAO,UAAU;KAFnC,UAAA;MAIE,oBAAC,KAAK,OAAN;OAAiB;OAAK,WAAWA,qCAAO;MAAQ,CAAA;MAChD,qBAAC,KAAK,OAAN;OAAY,WAAWA,qCAAO;OAA9B,UAAA,CACE,oBAAC,gCAAD;QACE,WAAWA,qCAAO;QAClB,WAAW;QACC;QACZ,SAAS;OACV,CAAA,GACD,oBAAC,uBAAD;QACE,IAAG;QACH,WAAU;OACX,CAAA,CACS;;MACZ,oBAAC,qBAAD;OAEgB;OACd,WACE,uBACA,uBAAuB,YAAY;OAEb;OACxB,uBAAuB;OACvB,WAAW;MACZ,GATM,KASN;KACS;;IACX,+BAA+B,CAAC,wBAG/B,oBAAC,KAAK,YAAY,UAAlB;KAA2B,OAAO;KAChC,UAAA,oBAAC,kBAAD;MACE,IAAI;MACJ,KAAK;MAEJ,UAAA;KACe,CAAA;IACO,CAAA;GAET;EAGrB,CAAA,GAAA,6BACC,oBAAC,YAAD,EAAA,UAAa,0BAAsC,CAAA,CAE7B,EAAA,CAAA,GAC1B,oBAAC,gBAAD,CAAiB,CAAA,CACH;;AAEpB,CACF"}
|
|
1
|
+
{"version":3,"file":"PasswordCreationField.mjs","names":["locales","styles","_Fragment"],"sources":["../../../../../../../src/components/PasswordCreationField/PasswordCreationField.tsx"],"sourcesContent":["import {\n type PropsWithChildren,\n useState,\n type ClipboardEvent,\n useCallback,\n useId,\n useMemo,\n useRef,\n} from \"react\";\nimport {\n dynamic,\n type PropsContext,\n PropsContextProvider,\n} from \"@/lib/propsContext\";\nimport {\n flowComponent,\n type FlowComponentProps,\n} from \"@/lib/componentFactory/flowComponent\";\nimport styles from \"./PasswordCreationField.module.scss\";\nimport * as Aria from \"react-aria-components\";\nimport clsx from \"clsx\";\nimport { type ActionFn } from \"@/components/Action\";\nimport getStateFromLatestPolicyValidationResult from \"@/components/PasswordCreationField/lib/getStateFromLatestPolicyValidationResult\";\nimport locales from \"./locales/*.locale.json\";\nimport { formatValidationResult } from \"@/components/PasswordCreationField/lib/generateValidationTranslation\";\nimport FieldDescription from \"@/components/FieldDescription\";\nimport ComplexityIndicator from \"@/components/PasswordCreationField/components/ComplexityIndicator/ComplexityIndicator\";\nimport { generatePassword } from \"@/components/PasswordCreationField/worker/generatePassword\";\nimport TogglePasswordVisibilityButton from \"@/components/PasswordCreationField/components/TogglePasswordVisibilityButton/TogglePasswordVisibilityButton\";\nimport { ValidationResultButton } from \"@/components/PasswordCreationField/components/ValidationResultButton/ValidationResultButton\";\nimport { PasswordGenerateButton } from \"@/components/PasswordCreationField/components/PasswordGenerateButton/PasswordGenerateButton\";\nimport type {\n PolicyValidationResult,\n PolicyGenericDeclaration,\n RuleValidationResult,\n} from \"@/integrations/@mittwald/password-tools-js\";\nimport {\n defaultPasswordCreationPolicy,\n Policy,\n} from \"@/integrations/@mittwald/password-tools-js\";\nimport { usePolicyValidationResult } from \"@/components/PasswordCreationField/lib/usePolicyValidationResult\";\nimport { joinIds, useFieldComponent } from \"@/lib/hooks/useFieldComponent\";\nimport { FieldError } from \"@/components/FieldError\";\nimport { useControlledHostValueProps } from \"@/lib/remote/useControlledHostValueProps\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport {\n useAriaAnnouncePasswordVisibility,\n useAriaAnnounceValidationState,\n} from \"@/components/PasswordCreationField/lib/ariaAnnounce\";\n\nexport interface PasswordCreationFieldProps\n extends\n PropsWithChildren<\n Omit<Aria.TextFieldProps, \"children\" | \"value\" | \"defaultValue\"> &\n Partial<Pick<Aria.FieldErrorRenderProps, \"validationErrors\">>\n >,\n FlowComponentProps<HTMLInputElement> {\n /** The password of a controlled field. */\n value?: string;\n /** Called with the password and its validity whenever the password changes. */\n onValidationResult?: (result: { password: string; isValid: boolean }) => void;\n /** The initial password of an uncontrolled field. */\n defaultValue?: string;\n /** The placeholder shown while the field is empty. */\n placeholder?: string;\n /**\n * The policy the password is validated against.\n *\n * @default defaultPasswordCreationPolicy\n */\n validationPolicy?: PolicyGenericDeclaration;\n}\n\nexport interface ResolvedPolicyValidationResult extends Omit<\n PolicyValidationResult,\n \"isValid\"\n> {\n isValid: boolean | \"indeterminate\";\n ruleResults: RuleValidationResult[];\n}\n\n/** @flr-generate all */\nexport const PasswordCreationField = flowComponent(\n \"PasswordCreationField\",\n (props) => {\n const {\n children,\n className,\n ref,\n isDisabled,\n onValidationResult,\n isInvalid: invalidFromProps,\n validationPolicy:\n validationPolicyFromProps = defaultPasswordCreationPolicy,\n isRequired,\n value,\n onChange,\n ...rest\n } = useControlledHostValueProps(props, \"\");\n\n const translate = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n\n const validationPolicy = useMemo(\n () => Policy.fromDeclaration(validationPolicyFromProps),\n [validationPolicyFromProps],\n );\n\n const [isPasswordRevealed, setIsPasswordRevealed] = useState(false);\n const initialPolicyValidationState: ResolvedPolicyValidationResult = {\n isValid: \"indeterminate\",\n complexity: {\n min: validationPolicy.minComplexity,\n actual: 4,\n warning: null,\n },\n ruleResults: [],\n };\n\n const [policyValidationResult, setPolicyValidationResult] = useState(\n initialPolicyValidationState,\n );\n\n /**\n * A validation that outlasts the delay shows the loading bar, but keeps the\n * previous result until the new one arrives – dropping it flickered the\n * error and the bar color after every typing pause.\n */\n const [isValidationPending, setIsValidationPending] = useState(false);\n const [validatedPassword, setValidatedPassword] = useState<string>();\n const loadingRef = useRef<ReturnType<typeof setTimeout>>(null);\n const { rememberValidationResult } = usePolicyValidationResult(\n validationPolicy,\n value ?? \"\",\n () => {\n if (isEmptyValue) {\n return;\n }\n\n if (loadingRef.current) {\n clearTimeout(loadingRef.current);\n }\n loadingRef.current = setTimeout(() => {\n setIsValidationPending(true);\n }, 150);\n },\n ({ password, isValid, results }) => {\n if (loadingRef.current) {\n clearTimeout(loadingRef.current);\n }\n setIsValidationPending(false);\n setValidatedPassword(password);\n\n if (isEmptyValue) {\n setPolicyValidationResult(() => ({\n ...results,\n isValid: true,\n }));\n return;\n }\n\n setPolicyValidationResult(() => results);\n onValidationResult?.({ password, isValid });\n },\n );\n\n const isEmptyValue = !value;\n const stateFromValidationResult = getStateFromLatestPolicyValidationResult(\n isEmptyValue,\n policyValidationResult,\n );\n const latestValidationErrorText = stateFromValidationResult\n ? formatValidationResult(translate, stateFromValidationResult)\n : undefined;\n\n const isValidFromValidationResult =\n !isEmptyValue && stateFromValidationResult?.isValid;\n\n // A form validating the same policy fails before the debounced check of\n // the field: its fallback error would flash until the policy message.\n const isPolicyResultPending = !isEmptyValue && validatedPassword !== value;\n\n const isInvalidFromValidationResult =\n !isEmptyValue && stateFromValidationResult?.isValid === false;\n const isInvalid = invalidFromProps || isInvalidFromValidationResult;\n\n const {\n FieldErrorView,\n FieldErrorCaptureContext,\n wrapperProps,\n controlProps,\n fieldPropsContext,\n renderedFieldErrorId,\n skeletonProps,\n } = useFieldComponent(props, \"PasswordCreationField\");\n\n /**\n * The result for a valid password appears after the asynchronous policy\n * validation. react-aria resolves its description slot only when the\n * field's validity changes, so a result that appears while the field stays\n * valid (a generated password) was never linked. It gets its own id\n * instead, referenced only while it is rendered.\n *\n * A shown error replaces it: the FormField styles hide descriptions next to\n * an error, and a hidden description would still be announced.\n */\n const resultDescriptionId = useId();\n const [isResultDescriptionRendered, setIsResultDescriptionRendered] =\n useState(false);\n const resultDescriptionRef = useCallback((element: Element | null) => {\n setIsResultDescriptionRendered(!!element);\n }, []);\n const describedBy = joinIds(\n isResultDescriptionRendered && resultDescriptionId,\n controlProps[\"aria-describedby\"],\n );\n\n useAriaAnnounceValidationState(\n latestValidationErrorText,\n !isEmptyValue && policyValidationResult.isValid !== \"indeterminate\",\n );\n useAriaAnnouncePasswordVisibility(isPasswordRevealed);\n\n const setOptimisticPolicyValidationResult = (\n state: Partial<ResolvedPolicyValidationResult> = {},\n ) => {\n setPolicyValidationResult((currentState) => ({\n ...currentState,\n isValid: true,\n ...state,\n }));\n };\n\n const onPasswordGenerateHandler: ActionFn = async () => {\n const generatedPassword = await generatePassword(validationPolicy);\n /**\n * The generator returns only passwords the policy accepts, so the rating\n * is set with the password instead of after the typing debounce. It is\n * the policy's own result: a guessed one (full strength) was overturned\n * by the real rating, e.g. to \"meets the minimum requirements\". Cached,\n * so the debounced validation of this password does not rate it again.\n */\n const generatedPasswordResult =\n await validationPolicy.validate(generatedPassword);\n rememberValidationResult(generatedPassword, generatedPasswordResult);\n setPolicyValidationResult(generatedPasswordResult);\n setIsPasswordRevealed(true);\n onChange(generatedPassword);\n };\n\n const onPasswordPasteHandler = (event: ClipboardEvent) => {\n const pastedValue = event.clipboardData?.getData(\"text\");\n if (typeof pastedValue === \"string\" && pastedValue !== value) {\n setOptimisticPolicyValidationResult({\n isValid: \"indeterminate\",\n });\n }\n };\n\n const togglePasswordVisibilityHandler = () => {\n setIsPasswordRevealed((old) => !old);\n };\n\n const propsContext: PropsContext = {\n ...fieldPropsContext,\n Button: {\n tunnel: {\n id: \"button\",\n component: \"PasswordCreationField\",\n },\n size: \"m\",\n variant: \"plain\",\n color: \"secondary\",\n isDisabled: isDisabled,\n className: styles.button,\n },\n CopyButton: {\n tunnel: {\n id: \"button\",\n component: \"PasswordCreationField\",\n },\n size: \"m\",\n variant: \"plain\",\n color: \"secondary\",\n isDisabled: isDisabled,\n className: styles.button,\n text: value,\n },\n Label: {\n ...fieldPropsContext.Label,\n children: dynamic((localProps) => {\n return (\n <>\n {localProps.children}\n <PasswordGenerateButton\n isDisabled={isDisabled}\n onGeneratePasswordAction={onPasswordGenerateHandler}\n />\n <ValidationResultButton\n isEmptyValue={isEmptyValue}\n isDisabled={isDisabled}\n policyValidationResult={policyValidationResult}\n />\n </>\n );\n }),\n },\n };\n\n return (\n <Aria.TextField\n {...rest}\n {...skeletonProps}\n aria-describedby={describedBy}\n value={value}\n type={isPasswordRevealed ? \"text\" : \"password\"}\n onChange={onChange}\n onPaste={onPasswordPasteHandler}\n className={clsx(wrapperProps.className, className)}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isRequired={isRequired}\n >\n <FieldErrorCaptureContext>\n <PropsContextProvider\n props={propsContext}\n dependencies={[\n isDisabled,\n isRequired,\n value,\n policyValidationResult,\n isEmptyValue,\n ]}\n >\n {children}\n <Aria.Group\n isDisabled={isDisabled}\n className={clsx(styles.inputGroup)}\n >\n <Aria.Input ref={ref} className={styles.input} />\n <Aria.Group className={styles.buttonContainer}>\n <TogglePasswordVisibilityButton\n className={styles.button}\n isVisible={isPasswordRevealed}\n isDisabled={isDisabled}\n onPress={togglePasswordVisibilityHandler}\n />\n <UiComponentTunnelExit\n id=\"button\"\n component=\"PasswordCreationField\"\n />\n </Aria.Group>\n <ComplexityIndicator\n key={value}\n isEmptyValue={isEmptyValue}\n isLoading={\n isValidationPending ||\n policyValidationResult.isValid === \"indeterminate\"\n }\n policyValidationResult={policyValidationResult}\n validationResultState={stateFromValidationResult}\n isInvalid={invalidFromProps}\n />\n </Aria.Group>\n {isValidFromValidationResult && !renderedFieldErrorId && (\n // Out of react-aria's description slot, which would set its own\n // id – see `resultDescriptionId`.\n <Aria.TextContext.Provider value={null}>\n <FieldDescription\n id={resultDescriptionId}\n ref={resultDescriptionRef}\n >\n {latestValidationErrorText}\n </FieldDescription>\n </Aria.TextContext.Provider>\n )}\n </PropsContextProvider>\n {/* After `children`: the field shows the first error in the tree, and\n a consumer's error wins over the policy's. */}\n {isInvalidFromValidationResult && latestValidationErrorText && (\n <FieldError>{latestValidationErrorText}</FieldError>\n )}\n </FieldErrorCaptureContext>\n <FieldErrorView withoutFallback={isPolicyResultPending} />\n </Aria.TextField>\n );\n },\n);\n\nexport default PasswordCreationField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,IAAa,wBAAwB,cACnC,0BACC,UAAU;CACT,MAAM,EACJ,UACA,WACA,KACA,YACA,oBACA,WAAW,kBACX,kBACE,4BAA4B,+BAC9B,YACA,OACA,UACA,GAAG,SACD,4BAA4B,OAAO,EAAE;CAEzC,MAAM,YAAY,4BAChBA,kBACA,uBACF;CAEA,MAAM,mBAAmB,cACjB,OAAO,gBAAgB,yBAAyB,GACtD,CAAC,yBAAyB,CAC5B;CAEA,MAAM,CAAC,oBAAoB,yBAAyB,SAAS,KAAK;CAClE,MAAM,+BAA+D;EACnE,SAAS;EACT,YAAY;GACV,KAAK,iBAAiB;GACtB,QAAQ;GACR,SAAS;EACX;EACA,aAAa,CAAC;CAChB;CAEA,MAAM,CAAC,wBAAwB,6BAA6B,SAC1D,4BACF;;;;;;CAOA,MAAM,CAAC,qBAAqB,0BAA0B,SAAS,KAAK;CACpE,MAAM,CAAC,mBAAmB,wBAAwB,SAAiB;CACnE,MAAM,aAAa,OAAsC,IAAI;CAC7D,MAAM,EAAE,6BAA6B,0BACnC,kBACA,SAAS,UACH;EACJ,IAAI,cACF;EAGF,IAAI,WAAW,SACb,aAAa,WAAW,OAAO;EAEjC,WAAW,UAAU,iBAAiB;GACpC,uBAAuB,IAAI;EAC7B,GAAG,GAAG;CACR,IACC,EAAE,UAAU,SAAS,cAAc;EAClC,IAAI,WAAW,SACb,aAAa,WAAW,OAAO;EAEjC,uBAAuB,KAAK;EAC5B,qBAAqB,QAAQ;EAE7B,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CAAA,GACD,oBAAC,uBAAD;QACE,IAAG;QACH,WAAU;OACX,CAAA,CACS;;MACZ,oBAAC,qBAAD;OAEgB;OACd,WACE,uBACA,uBAAuB,YAAY;OAEb;OACxB,uBAAuB;OACvB,WAAW;MACZ,GATM,KASN;KACS;;IACX,+BAA+B,CAAC,wBAG/B,oBAAC,KAAK,YAAY,UAAlB;KAA2B,OAAO;KAChC,UAAA,oBAAC,kBAAD;MACE,IAAI;MACJ,KAAK;MAEJ,UAAA;KACe,CAAA;IACO,CAAA;GAET;EAGrB,CAAA,GAAA,iCAAiC,6BAChC,oBAAC,YAAD,EAAA,UAAa,0BAAsC,CAAA,CAE7B,EAAA,CAAA,GAC1B,oBAAC,gBAAD,EAAgB,iBAAiB,sBAAwB,CAAA,CAC3C;;AAEpB,CACF"}
|
|
@@ -4,7 +4,7 @@ import { useLocalizedStringFormatter } from "../../../TranslationProvider/useLoc
|
|
|
4
4
|
import { AlertIcon } from "../../../AlertIcon/AlertIcon.mjs";
|
|
5
5
|
import { Text } from "../../../Text/Text.mjs";
|
|
6
6
|
import __locale_default from "../../../../../../../_virtual/_30.locale.mjs";
|
|
7
|
-
import generateValidationTranslation from "../../lib/generateValidationTranslation.mjs";
|
|
7
|
+
import generateValidationTranslation, { formatValidationResult } from "../../lib/generateValidationTranslation.mjs";
|
|
8
8
|
import ValidationResultEntry_module_default from "./ValidationResultEntry.module.mjs";
|
|
9
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
import * as Aria from "react-aria-components";
|
|
@@ -18,11 +18,7 @@ var ValidationResultEntry = (props) => {
|
|
|
18
18
|
"aria-label": void 0
|
|
19
19
|
});
|
|
20
20
|
const status = translate.format(result.isValid ? "password.requirements.rule.fulfilled" : "password.requirements.rule.unfulfilled");
|
|
21
|
-
|
|
22
|
-
if (unspecifiedRules) {
|
|
23
|
-
translationKey = `${translationKey}.unspecified`;
|
|
24
|
-
translationValues = {};
|
|
25
|
-
}
|
|
21
|
+
const text = unspecifiedRules ? translate.format(`${generateValidationTranslation(result, true)[0]}.unspecified`, {}) : formatValidationResult(translate, result, true);
|
|
26
22
|
return /* @__PURE__ */ jsxs("li", {
|
|
27
23
|
className: ValidationResultEntry_module_default.validationResultEntry,
|
|
28
24
|
"data-rule": result.ruleType,
|
|
@@ -30,7 +26,7 @@ var ValidationResultEntry = (props) => {
|
|
|
30
26
|
children: [icon, /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Aria.VisuallyHidden, {
|
|
31
27
|
elementType: "span",
|
|
32
28
|
children: `${status}: `
|
|
33
|
-
}),
|
|
29
|
+
}), text] })]
|
|
34
30
|
});
|
|
35
31
|
};
|
|
36
32
|
export { ValidationResultEntry, ValidationResultEntry as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationResultEntry.mjs","names":["locales","styles"],"sources":["../../../../../../../../../src/components/PasswordCreationField/components/ValidationResultEntry/ValidationResultEntry.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport * as Aria from \"react-aria-components\";\nimport { Text } from \"@/components/Text\";\nimport generateValidationTranslation from \"@/components/PasswordCreationField/lib/generateValidationTranslation\";\nimport locales from \"./../../locales/*.locale.json\";\nimport styles from \"./ValidationResultEntry.module.scss\";\nimport type { RuleValidationResult } from \"@/integrations/@mittwald/password-tools-js\";\nimport AlertIcon from \"@/components/AlertIcon\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\n\ninterface Props {\n result: Partial<RuleValidationResult>;\n unspecifiedRules?: boolean;\n}\n\n/** @internal */\nexport const ValidationResultEntry: FC<Props> = (props) => {\n const { result, unspecifiedRules = false } = props;\n const translate = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n\n const icon = (\n <AlertIcon\n status={result.isValid ? \"success\" : \"warning\"}\n // The status is spelled out as text right next to it, so the icon is\n // decorative. Overriding `AlertIcon`'s generic \"Status …\" label with\n // `undefined` is what makes `Icon` hide it from the accessibility tree.\n aria-label={undefined}\n />\n );\n\n const status = translate.format(\n result.isValid\n ? \"password.requirements.rule.fulfilled\"\n : \"password.requirements.rule.unfulfilled\",\n );\n\n
|
|
1
|
+
{"version":3,"file":"ValidationResultEntry.mjs","names":["locales","styles"],"sources":["../../../../../../../../../src/components/PasswordCreationField/components/ValidationResultEntry/ValidationResultEntry.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport * as Aria from \"react-aria-components\";\nimport { Text } from \"@/components/Text\";\nimport generateValidationTranslation, {\n formatValidationResult,\n} from \"@/components/PasswordCreationField/lib/generateValidationTranslation\";\nimport locales from \"./../../locales/*.locale.json\";\nimport styles from \"./ValidationResultEntry.module.scss\";\nimport type { RuleValidationResult } from \"@/integrations/@mittwald/password-tools-js\";\nimport AlertIcon from \"@/components/AlertIcon\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\n\ninterface Props {\n result: Partial<RuleValidationResult>;\n unspecifiedRules?: boolean;\n}\n\n/** @internal */\nexport const ValidationResultEntry: FC<Props> = (props) => {\n const { result, unspecifiedRules = false } = props;\n const translate = useLocalizedStringFormatter(\n locales,\n \"PasswordCreationField\",\n );\n\n const icon = (\n <AlertIcon\n status={result.isValid ? \"success\" : \"warning\"}\n // The status is spelled out as text right next to it, so the icon is\n // decorative. Overriding `AlertIcon`'s generic \"Status …\" label with\n // `undefined` is what makes `Icon` hide it from the accessibility tree.\n aria-label={undefined}\n />\n );\n\n const status = translate.format(\n result.isValid\n ? \"password.requirements.rule.fulfilled\"\n : \"password.requirements.rule.unfulfilled\",\n );\n\n const text = unspecifiedRules\n ? translate.format(\n `${generateValidationTranslation(result, true)[0]}.unspecified`,\n {},\n )\n : formatValidationResult(translate, result, true);\n\n return (\n <li\n className={styles.validationResultEntry}\n data-rule={result.ruleType}\n data-rule-valid={result.isValid}\n >\n {icon}\n <Text>\n <Aria.VisuallyHidden elementType=\"span\">{`${status}: `}</Aria.VisuallyHidden>\n {text}\n </Text>\n </li>\n );\n};\n\nexport default ValidationResultEntry;\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAa,yBAAoC,UAAU;CACzD,MAAM,EAAE,QAAQ,mBAAmB,UAAU;CAC7C,MAAM,YAAY,4BAChBA,kBACA,uBACF;CAEA,MAAM,OACJ,oBAAC,WAAD;EACE,QAAQ,OAAO,UAAU,YAAY;EAIrC,cAAY,KAAA;CACb,CAAA;CAGH,MAAM,SAAS,UAAU,OACvB,OAAO,UACH,yCACA,wCACN;CAEA,MAAM,OAAO,mBACT,UAAU,OACR,GAAG,8BAA8B,QAAQ,IAAI,CAAC,CAAC,GAAG,eAClD,CAAC,CACH,IACA,uBAAuB,WAAW,QAAQ,IAAI;CAElD,OACE,qBAAC,MAAD;EACE,WAAWC,qCAAO;EAClB,aAAW,OAAO;EAClB,mBAAiB,OAAO;EAH1B,UAAA,CAKG,MACD,qBAAC,MAAD,EAAA,UAAA,CACE,oBAAC,KAAK,gBAAN;GAAqB,aAAY;GAAQ,UAAA,GAAG,OAAO;EAAyB,CAAA,GAC3E,IACG,EAAA,CAAA,CACJ;;AAER"}
|
|
@@ -23,6 +23,21 @@ var generateValidationTranslation = (r, shotVersion = false) => {
|
|
|
23
23
|
}];
|
|
24
24
|
return [translationKey, r];
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Formats the message of a validation result. A rule without a translation
|
|
28
|
+
* (e.g. a custom rule or char pool) gets a generic message instead of throwing,
|
|
29
|
+
* so a rejected password always shows why it was rejected.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
var formatValidationResult = (formatter, result, shortVersion = false) => {
|
|
34
|
+
const [translationKey, translationValues] = generateValidationTranslation(result, shortVersion);
|
|
35
|
+
try {
|
|
36
|
+
return formatter.format(translationKey, translationValues);
|
|
37
|
+
} catch {
|
|
38
|
+
return formatter.format(shortVersion ? "validation.general.fallback.short" : "validation.general.fallback", { isValid: result.isValid === true });
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export { generateValidationTranslation as default, generateValidationTranslation, formatValidationResult };
|
|
27
42
|
|
|
28
43
|
//# sourceMappingURL=generateValidationTranslation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateValidationTranslation.mjs","names":[],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/generateValidationTranslation.ts"],"sourcesContent":["import {\n RuleType,\n type RuleValidationResult,\n} from \"@/integrations/@mittwald/password-tools-js\";\n\nconst generateTranslationString = (\n rule: Partial<RuleValidationResult> & { translationKey?: string },\n shortVersion = false,\n): string => {\n if (rule.translationKey) {\n return `validation.${rule.translationKey}`;\n }\n const translateString = `validation.${rule.ruleType ?? \"general\"}`;\n let finalTranslationString: string;\n\n if (\n (\"min\" in rule && rule.min !== undefined) ||\n (\"max\" in rule && rule.max !== undefined)\n ) {\n const breakingBoundaryProperty = rule.failingBoundary\n ? rule.failingBoundary\n : rule.min\n ? \"min\"\n : \"max\";\n\n if (rule.identifier) {\n finalTranslationString = `${translateString}.${rule.identifier}.${breakingBoundaryProperty}`;\n } else {\n finalTranslationString = `${translateString}.${breakingBoundaryProperty}`;\n }\n } else if (rule.identifier) {\n finalTranslationString = `${translateString}.${rule.identifier}`;\n } else {\n finalTranslationString = translateString;\n }\n\n return shortVersion\n ? `${finalTranslationString}.short`\n : finalTranslationString;\n};\n\n/** @internal */\nexport const generateValidationTranslation = (\n r: Partial<RuleValidationResult>,\n shotVersion = false,\n): [string, Record<string, string | number | boolean> | undefined] => {\n const translationKey = generateTranslationString(r, shotVersion);\n\n if (r.ruleType === RuleType.char && r.chars) {\n return [\n translationKey,\n { ...r, chars: r.chars.map((c) => c.char).join(\"\") },\n ];\n }\n\n return [\n translationKey,\n r as unknown as Record<string, string | number | boolean> | undefined,\n ];\n};\n\nexport default generateValidationTranslation;\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"generateValidationTranslation.mjs","names":[],"sources":["../../../../../../../../src/components/PasswordCreationField/lib/generateValidationTranslation.ts"],"sourcesContent":["import {\n RuleType,\n type RuleValidationResult,\n} from \"@/integrations/@mittwald/password-tools-js\";\nimport type { Variables } from \"@internationalized/string\";\n\nconst generateTranslationString = (\n rule: Partial<RuleValidationResult> & { translationKey?: string },\n shortVersion = false,\n): string => {\n if (rule.translationKey) {\n return `validation.${rule.translationKey}`;\n }\n const translateString = `validation.${rule.ruleType ?? \"general\"}`;\n let finalTranslationString: string;\n\n if (\n (\"min\" in rule && rule.min !== undefined) ||\n (\"max\" in rule && rule.max !== undefined)\n ) {\n const breakingBoundaryProperty = rule.failingBoundary\n ? rule.failingBoundary\n : rule.min\n ? \"min\"\n : \"max\";\n\n if (rule.identifier) {\n finalTranslationString = `${translateString}.${rule.identifier}.${breakingBoundaryProperty}`;\n } else {\n finalTranslationString = `${translateString}.${breakingBoundaryProperty}`;\n }\n } else if (rule.identifier) {\n finalTranslationString = `${translateString}.${rule.identifier}`;\n } else {\n finalTranslationString = translateString;\n }\n\n return shortVersion\n ? `${finalTranslationString}.short`\n : finalTranslationString;\n};\n\n/** @internal */\nexport const generateValidationTranslation = (\n r: Partial<RuleValidationResult>,\n shotVersion = false,\n): [string, Record<string, string | number | boolean> | undefined] => {\n const translationKey = generateTranslationString(r, shotVersion);\n\n if (r.ruleType === RuleType.char && r.chars) {\n return [\n translationKey,\n { ...r, chars: r.chars.map((c) => c.char).join(\"\") },\n ];\n }\n\n return [\n translationKey,\n r as unknown as Record<string, string | number | boolean> | undefined,\n ];\n};\n\ninterface ValidationResultFormatter {\n format: (key: string, variables?: Variables) => string;\n}\n\n/**\n * Formats the message of a validation result. A rule without a translation\n * (e.g. a custom rule or char pool) gets a generic message instead of throwing,\n * so a rejected password always shows why it was rejected.\n *\n * @internal\n */\nexport const formatValidationResult = (\n formatter: ValidationResultFormatter,\n result: Partial<RuleValidationResult>,\n shortVersion = false,\n): string => {\n const [translationKey, translationValues] = generateValidationTranslation(\n result,\n shortVersion,\n );\n\n try {\n return formatter.format(translationKey, translationValues);\n } catch {\n return formatter.format(\n shortVersion\n ? \"validation.general.fallback.short\"\n : \"validation.general.fallback\",\n { isValid: result.isValid === true },\n );\n }\n};\n\nexport default generateValidationTranslation;\n"],"mappings":";;;;AAMA,IAAM,6BACJ,MACA,eAAe,UACJ;CACX,IAAI,KAAK,gBACP,OAAO,cAAc,KAAK;CAE5B,MAAM,kBAAkB,cAAc,KAAK,YAAY;CACvD,IAAI;CAEJ,IACG,SAAS,QAAQ,KAAK,QAAQ,KAAA,KAC9B,SAAS,QAAQ,KAAK,QAAQ,KAAA,GAC/B;EACA,MAAM,2BAA2B,KAAK,kBAClC,KAAK,kBACL,KAAK,MACH,QACA;EAEN,IAAI,KAAK,YACP,yBAAyB,GAAG,gBAAgB,GAAG,KAAK,WAAW,GAAG;OAElE,yBAAyB,GAAG,gBAAgB,GAAG;CAEnD,OAAO,IAAI,KAAK,YACd,yBAAyB,GAAG,gBAAgB,GAAG,KAAK;MAEpD,yBAAyB;CAG3B,OAAO,eACH,GAAG,uBAAuB,UAC1B;AACN;;AAGA,IAAa,iCACX,GACA,cAAc,UACsD;CACpE,MAAM,iBAAiB,0BAA0B,GAAG,WAAW;CAE/D,IAAI,EAAE,aAAa,SAAS,QAAQ,EAAE,OACpC,OAAO,CACL,gBACA;EAAE,GAAG;EAAG,OAAO,EAAE,MAAM,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,EAAE;CAAE,CACrD;CAGF,OAAO,CACL,gBACA,CACF;AACF;;;;;;;;AAaA,IAAa,0BACX,WACA,QACA,eAAe,UACJ;CACX,MAAM,CAAC,gBAAgB,qBAAqB,8BAC1C,QACA,YACF;CAEA,IAAI;EACF,OAAO,UAAU,OAAO,gBAAgB,iBAAiB;CAC3D,QAAQ;EACN,OAAO,UAAU,OACf,eACI,sCACA,+BACJ,EAAE,SAAS,OAAO,YAAY,KAAK,CACrC;CACF;AACF"}
|
package/dist/js/packages/components/src/integrations/react-hook-form/components/Field/Field.mjs
CHANGED
|
@@ -59,6 +59,11 @@ function Field(props) {
|
|
|
59
59
|
name
|
|
60
60
|
}) ?? controller.field.value;
|
|
61
61
|
const isFieldInvalid = controller.fieldState.invalid;
|
|
62
|
+
const errorMessage = controller.fieldState.error?.message;
|
|
63
|
+
const fieldError = errorMessage ? /* @__PURE__ */ jsx(FieldErrorView, { children: errorMessage }) : isFieldInvalid ? /* @__PURE__ */ jsx(FieldErrorView, {
|
|
64
|
+
isFallback: true,
|
|
65
|
+
children: stringFormatter.format("validation.invalid")
|
|
66
|
+
}) : null;
|
|
62
67
|
const { disabled, ...controllerFieldProps } = controller.field;
|
|
63
68
|
const fieldProps = {
|
|
64
69
|
...controllerFieldProps,
|
|
@@ -72,7 +77,7 @@ function Field(props) {
|
|
|
72
77
|
defaultValue,
|
|
73
78
|
isInvalid: isFieldInvalid,
|
|
74
79
|
children: dynamic((p) => {
|
|
75
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [p.children,
|
|
80
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [p.children, fieldError] });
|
|
76
81
|
})
|
|
77
82
|
};
|
|
78
83
|
const propsContext = {
|
package/dist/js/packages/components/src/integrations/react-hook-form/components/Field/Field.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.mjs","names":["locales","_Fragment"],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/Field/Field.tsx"],"sourcesContent":["import { useFormContext } from \"@/integrations/react-hook-form/components/FormContextProvider/FormContextProvider\";\nimport {\n dynamic,\n type PropsContext,\n PropsContextProvider,\n} from \"@/lib/propsContext\";\nimport { type PropsWithChildren } from \"react\";\nimport {\n type ControllerProps,\n type FieldValues,\n useController,\n type UseFormReturn,\n useWatch,\n} from \"react-hook-form\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./locales/*.locale.json\";\nimport FieldErrorView from \"@/views/FieldErrorView\";\nimport { useUpdateFormDefaultValue } from \"@/integrations/react-hook-form/components/Field/hooks/useUpdateFormDefaultValue\";\nimport type {\n FlowComponentName,\n FlowComponentPropName,\n} from \"@/components/propTypes\";\n\ntype DisableableComponentName = {\n [C in FlowComponentName]: \"isDisabled\" extends FlowComponentPropName<C>\n ? C\n : never;\n}[FlowComponentName];\n\nexport interface FieldProps<T extends FieldValues>\n extends Omit<ControllerProps<T>, \"render\">, PropsWithChildren {}\n\nexport function Field<T extends FieldValues>(props: FieldProps<T>) {\n const { children, name, defaultValue, ...rest } = props;\n\n const stringFormatter = useLocalizedStringFormatter(\n locales,\n \"ReactHookForm.Field\",\n );\n\n const controller = useController({\n ...props,\n rules: {\n ...props.rules,\n min:\n typeof rest.rules?.min === \"number\"\n ? {\n value: rest.rules.min,\n message: stringFormatter.format(\"validation.min\", {\n number: rest.rules.min,\n }),\n }\n : rest.rules?.min,\n max:\n typeof rest.rules?.max === \"number\"\n ? {\n value: rest.rules.max,\n message: stringFormatter.format(\"validation.max\", {\n number: rest.rules.max,\n }),\n }\n : rest.rules?.max,\n required:\n typeof rest.rules?.required === \"boolean\"\n ? stringFormatter.format(\"validation.required\")\n : rest.rules?.required,\n pattern:\n rest.rules?.pattern instanceof RegExp\n ? {\n value: rest.rules.pattern,\n message: stringFormatter.format(\"validation.pattern\", {\n pattern: rest.rules.pattern.source,\n }),\n }\n : rest.rules?.pattern,\n minLength:\n typeof rest.rules?.minLength === \"number\"\n ? {\n value: rest.rules.minLength,\n message: stringFormatter.format(\"validation.minLength\", {\n number: rest.rules.minLength,\n }),\n }\n : rest.rules?.minLength,\n maxLength:\n typeof rest.rules?.maxLength === \"number\"\n ? {\n value: rest.rules.maxLength,\n message: stringFormatter.format(\"validation.maxLength\", {\n number: rest.rules.maxLength,\n }),\n }\n : rest.rules?.maxLength,\n },\n });\n const formContext = useFormContext<T>();\n\n useUpdateFormDefaultValue(props, formContext.form);\n\n /**\n * We don't use controller.field.value here, because it doesn't update when\n * the form value is updated outside of this field (e.g. when setting values\n * with form.setValue or resetting the form), and the Field unmounts in\n * between. This is generally a feature of React Hook Form, but this breaks\n * dynamic forms where fields are conditionally rendered.\n *\n * By using formContext.form.watch(name), we ensure that the field value is\n * always in sync with the form state. See:\n * https://react-hook-form.com/api/usecontroller/controller/\n */\n const value =\n useWatch({\n control: formContext.form.control,\n name,\n }) ?? controller.field.value;\n\n const isFieldInvalid = controller.fieldState.invalid;\n\n const { disabled, ...controllerFieldProps } = controller.field;\n\n const fieldProps = {\n ...controllerFieldProps,\n // Dynamic, so a local `isDisabled={false}` cannot enable a field whose\n // value React Hook Form drops on submit\n ...(disabled && {\n isDisabled: dynamic<DisableableComponentName, \"isDisabled\">(() => true),\n }),\n value,\n name,\n form: formContext.id,\n isRequired: !!rest.rules?.required,\n isReadOnly: formContext.isReadOnly,\n validationBehavior: \"aria\" as const,\n defaultValue,\n isInvalid: isFieldInvalid,\n children: dynamic((p) => {\n return (\n <>\n {p.children}\n
|
|
1
|
+
{"version":3,"file":"Field.mjs","names":["locales","_Fragment"],"sources":["../../../../../../../../../src/integrations/react-hook-form/components/Field/Field.tsx"],"sourcesContent":["import { useFormContext } from \"@/integrations/react-hook-form/components/FormContextProvider/FormContextProvider\";\nimport {\n dynamic,\n type PropsContext,\n PropsContextProvider,\n} from \"@/lib/propsContext\";\nimport { type PropsWithChildren } from \"react\";\nimport {\n type ControllerProps,\n type FieldValues,\n useController,\n type UseFormReturn,\n useWatch,\n} from \"react-hook-form\";\nimport { useLocalizedStringFormatter } from \"@/components/TranslationProvider/useLocalizedStringFormatter\";\nimport locales from \"./locales/*.locale.json\";\nimport FieldErrorView from \"@/views/FieldErrorView\";\nimport { useUpdateFormDefaultValue } from \"@/integrations/react-hook-form/components/Field/hooks/useUpdateFormDefaultValue\";\nimport type {\n FlowComponentName,\n FlowComponentPropName,\n} from \"@/components/propTypes\";\n\ntype DisableableComponentName = {\n [C in FlowComponentName]: \"isDisabled\" extends FlowComponentPropName<C>\n ? C\n : never;\n}[FlowComponentName];\n\nexport interface FieldProps<T extends FieldValues>\n extends Omit<ControllerProps<T>, \"render\">, PropsWithChildren {}\n\nexport function Field<T extends FieldValues>(props: FieldProps<T>) {\n const { children, name, defaultValue, ...rest } = props;\n\n const stringFormatter = useLocalizedStringFormatter(\n locales,\n \"ReactHookForm.Field\",\n );\n\n const controller = useController({\n ...props,\n rules: {\n ...props.rules,\n min:\n typeof rest.rules?.min === \"number\"\n ? {\n value: rest.rules.min,\n message: stringFormatter.format(\"validation.min\", {\n number: rest.rules.min,\n }),\n }\n : rest.rules?.min,\n max:\n typeof rest.rules?.max === \"number\"\n ? {\n value: rest.rules.max,\n message: stringFormatter.format(\"validation.max\", {\n number: rest.rules.max,\n }),\n }\n : rest.rules?.max,\n required:\n typeof rest.rules?.required === \"boolean\"\n ? stringFormatter.format(\"validation.required\")\n : rest.rules?.required,\n pattern:\n rest.rules?.pattern instanceof RegExp\n ? {\n value: rest.rules.pattern,\n message: stringFormatter.format(\"validation.pattern\", {\n pattern: rest.rules.pattern.source,\n }),\n }\n : rest.rules?.pattern,\n minLength:\n typeof rest.rules?.minLength === \"number\"\n ? {\n value: rest.rules.minLength,\n message: stringFormatter.format(\"validation.minLength\", {\n number: rest.rules.minLength,\n }),\n }\n : rest.rules?.minLength,\n maxLength:\n typeof rest.rules?.maxLength === \"number\"\n ? {\n value: rest.rules.maxLength,\n message: stringFormatter.format(\"validation.maxLength\", {\n number: rest.rules.maxLength,\n }),\n }\n : rest.rules?.maxLength,\n },\n });\n const formContext = useFormContext<T>();\n\n useUpdateFormDefaultValue(props, formContext.form);\n\n /**\n * We don't use controller.field.value here, because it doesn't update when\n * the form value is updated outside of this field (e.g. when setting values\n * with form.setValue or resetting the form), and the Field unmounts in\n * between. This is generally a feature of React Hook Form, but this breaks\n * dynamic forms where fields are conditionally rendered.\n *\n * By using formContext.form.watch(name), we ensure that the field value is\n * always in sync with the form state. See:\n * https://react-hook-form.com/api/usecontroller/controller/\n */\n const value =\n useWatch({\n control: formContext.form.control,\n name,\n }) ?? controller.field.value;\n\n const isFieldInvalid = controller.fieldState.invalid;\n const errorMessage = controller.fieldState.error?.message;\n const fieldError = errorMessage ? (\n <FieldErrorView>{errorMessage}</FieldErrorView>\n ) : isFieldInvalid ? (\n <FieldErrorView isFallback>\n {stringFormatter.format(\"validation.invalid\")}\n </FieldErrorView>\n ) : null;\n\n const { disabled, ...controllerFieldProps } = controller.field;\n\n const fieldProps = {\n ...controllerFieldProps,\n // Dynamic, so a local `isDisabled={false}` cannot enable a field whose\n // value React Hook Form drops on submit\n ...(disabled && {\n isDisabled: dynamic<DisableableComponentName, \"isDisabled\">(() => true),\n }),\n value,\n name,\n form: formContext.id,\n isRequired: !!rest.rules?.required,\n isReadOnly: formContext.isReadOnly,\n validationBehavior: \"aria\" as const,\n defaultValue,\n isInvalid: isFieldInvalid,\n children: dynamic((p) => {\n return (\n <>\n {p.children}\n {fieldError}\n </>\n );\n }),\n };\n\n const propsContext: PropsContext = {\n Autocomplete: {\n SearchField: fieldProps,\n TextField: fieldProps,\n },\n SearchField: fieldProps,\n TextField: fieldProps,\n TextArea: fieldProps,\n MarkdownEditor: fieldProps,\n CodeEditor: fieldProps,\n Checkbox: {\n ...fieldProps,\n isSelected: value,\n },\n CheckboxGroup: {\n ...fieldProps,\n },\n CheckboxButton: {\n ...fieldProps,\n isSelected: value,\n },\n FileField: fieldProps,\n FileDropZone: fieldProps,\n NumberField: fieldProps,\n RadioGroup: fieldProps,\n Switch: {\n ...fieldProps,\n isSelected: value,\n },\n Slider: fieldProps,\n PasswordCreationField: fieldProps,\n DatePicker: fieldProps,\n DateRangePicker: fieldProps,\n TimeField: fieldProps,\n SegmentedControl: fieldProps,\n Select: {\n ...fieldProps,\n selectedKey: value,\n },\n ComboBox: {\n ...fieldProps,\n selectedKey: value,\n },\n Rating: fieldProps,\n };\n\n return (\n <PropsContextProvider\n props={propsContext}\n dependencies={[\n controller.fieldState,\n controller.field,\n value,\n formContext.isReadOnly,\n ]}\n >\n {children}\n </PropsContextProvider>\n );\n}\n\nexport const typedField = <T extends FieldValues>(\n ignoredForm: UseFormReturn<T> | UseFormReturn<T>[\"control\"],\n): typeof Field<T> => Field;\n\nexport default Field;\n"],"mappings":";;;;;;;;;;;;;AAgCA,SAAgB,MAA6B,OAAsB;CACjE,MAAM,EAAE,UAAU,MAAM,cAAc,GAAG,SAAS;CAElD,MAAM,kBAAkB,4BACtBA,kBACA,qBACF;CAEA,MAAM,aAAa,cAAc;EAC/B,GAAG;EACH,OAAO;GACL,GAAG,MAAM;GACT,KACE,OAAO,KAAK,OAAO,QAAQ,WACvB;IACE,OAAO,KAAK,MAAM;IAClB,SAAS,gBAAgB,OAAO,kBAAkB,EAChD,QAAQ,KAAK,MAAM,IACrB,CAAC;GACH,IACA,KAAK,OAAO;GAClB,KACE,OAAO,KAAK,OAAO,QAAQ,WACvB;IACE,OAAO,KAAK,MAAM;IAClB,SAAS,gBAAgB,OAAO,kBAAkB,EAChD,QAAQ,KAAK,MAAM,IACrB,CAAC;GACH,IACA,KAAK,OAAO;GAClB,UACE,OAAO,KAAK,OAAO,aAAa,YAC5B,gBAAgB,OAAO,qBAAqB,IAC5C,KAAK,OAAO;GAClB,SACE,KAAK,OAAO,mBAAmB,SAC3B;IACE,OAAO,KAAK,MAAM;IAClB,SAAS,gBAAgB,OAAO,sBAAsB,EACpD,SAAS,KAAK,MAAM,QAAQ,OAC9B,CAAC;GACH,IACA,KAAK,OAAO;GAClB,WACE,OAAO,KAAK,OAAO,cAAc,WAC7B;IACE,OAAO,KAAK,MAAM;IAClB,SAAS,gBAAgB,OAAO,wBAAwB,EACtD,QAAQ,KAAK,MAAM,UACrB,CAAC;GACH,IACA,KAAK,OAAO;GAClB,WACE,OAAO,KAAK,OAAO,cAAc,WAC7B;IACE,OAAO,KAAK,MAAM;IAClB,SAAS,gBAAgB,OAAO,wBAAwB,EACtD,QAAQ,KAAK,MAAM,UACrB,CAAC;GACH,IACA,KAAK,OAAO;EACpB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AC,sBAAD;EACE,OAAO;EACP,cAAc;GACZ,WAAW;GACX,WAAW;GACX;GACA,YAAY;EACd;EAEC;CACmB,CAAA;AAE1B;AAEA,IAAa,cACX,gBACoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldComponent.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldComponent.tsx"],"sourcesContent":["import { type FC, type PropsWithChildren, useId } from \"react\";\nimport { type PropsContext } from \"@/lib/propsContext\";\nimport formFieldStyles from \"@/components/FormField/FormField.module.scss\";\nimport { useFieldError
|
|
1
|
+
{"version":3,"file":"useFieldComponent.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldComponent.tsx"],"sourcesContent":["import { type FC, type PropsWithChildren, useId } from \"react\";\nimport { type PropsContext } from \"@/lib/propsContext\";\nimport formFieldStyles from \"@/components/FormField/FormField.module.scss\";\nimport {\n type FieldErrorViewProps,\n useFieldError,\n} from \"@/lib/hooks/useFieldError\";\nimport { type ClassValue } from \"clsx\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\nimport { useSkeletonMode } from \"@/components/SkeletonMode/skeletonModeContext\";\n\ninterface FieldComponentProps {\n className?: ClassValue;\n isRequired?: boolean;\n isDisabled?: boolean;\n \"aria-describedby\"?: string;\n}\n\nexport interface UseFieldComponent {\n FieldErrorCaptureContext: FC<PropsWithChildren>;\n FieldErrorView: FC<FieldErrorViewProps>;\n fieldPropsContext: PropsContext;\n /** For the field's outer element. */\n wrapperProps: {\n className: string;\n };\n /**\n * For what assistive technology lands on — the input, or the group of a\n * grouped control. Where the react-aria root forwards `aria-describedby` to\n * its input itself, spread it on the root together with `wrapperProps`.\n * Spread it after `rest`: it already contains the consumer's\n * `aria-describedby`, which `rest` would otherwise put back alone.\n */\n controlProps: {\n \"aria-describedby\"?: string;\n };\n /** The id of the error while one is rendered, without the consumer's ids. */\n renderedFieldErrorId?: string;\n /**\n * Belongs on the field's root element. In an enabled `SkeletonMode` it makes\n * the field `inert`, and `data-skeleton` turns its control into a surface\n * (`formSkeleton` in `@/styles/mixins/formControl`).\n */\n skeletonProps: {\n inert?: true;\n \"data-skeleton\"?: true;\n };\n}\n\n/** Joins id references, dropping empty ones. @internal */\nexport const joinIds = (...ids: (string | false | null | undefined)[]) =>\n ids.filter(Boolean).join(\" \") || undefined;\n\nexport const useFieldComponent = (\n props: FieldComponentProps,\n component: FlowComponentName,\n): UseFieldComponent => {\n const fieldErrorId = useId();\n const { FieldErrorView, FieldErrorCaptureContext, renderedFieldErrorId } =\n useFieldError({\n fieldErrorId,\n component,\n });\n const isSkeleton = useSkeletonMode();\n\n // setting up the props context for all components that\n // are part of a form control\n const fieldPropsContext: PropsContext = {\n Label: {\n className: formFieldStyles.label,\n optional: !props.isRequired,\n isDisabled: !!props.isDisabled,\n },\n FieldDescription: {\n className: formFieldStyles.fieldDescription,\n },\n };\n\n return {\n FieldErrorView,\n FieldErrorCaptureContext,\n fieldPropsContext,\n wrapperProps: {\n className: formFieldStyles.formField,\n },\n controlProps: {\n // Reference the error only while it is rendered – an id that points to\n // nothing fails HTML validators and a11y checks.\n \"aria-describedby\": joinIds(\n renderedFieldErrorId,\n props[\"aria-describedby\"],\n ),\n },\n renderedFieldErrorId,\n skeletonProps: isSkeleton ? { inert: true, \"data-skeleton\": true } : {},\n } as const;\n};\n"],"mappings":";;;;;;;;;AAkDA,IAAa,WAAW,GAAG,QACzB,IAAI,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,KAAK,KAAA;AAEnC,IAAa,qBACX,OACA,cACsB;CACtB,MAAM,eAAe,MAAM;CAC3B,MAAM,EAAE,gBAAgB,0BAA0B,yBAChD,cAAc;EACZ;EACA;CACF,CAAC;CACH,MAAM,aAAa,gBAAgB;CAenC,OAAO;EACL;EACA;EACA,mBAAA;GAbA,OAAO;IACL,WAAWA,yBAAgB;IAC3B,UAAU,CAAC,MAAM;IACjB,YAAY,CAAC,CAAC,MAAM;GACtB;GACA,kBAAkB,EAChB,WAAWA,yBAAgB,iBAC7B;EAMA;EACA,cAAc,EACZ,WAAWA,yBAAgB,UAC7B;EACA,cAAc,EAGZ,oBAAoB,QAClB,sBACA,MAAM,mBACR,EACF;EACA;EACA,eAAe,aAAa;GAAE,OAAO;GAAM,iBAAiB;EAAK,IAAI,CAAC;CACxE;AACF"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import useProps from "./useProps.mjs";
|
|
4
4
|
import { PropsContextProvider } from "../propsContext/components/PropsContextProvider.mjs";
|
|
5
5
|
import { ClearPropsContext } from "../propsContext/components/ClearPropsContext.mjs";
|
|
6
|
+
import dynamic from "../propsContext/dynamicProps/dynamic.mjs";
|
|
6
7
|
import { UiComponentTunnelExit } from "../../components/UiComponentTunnel/UiComponentTunnelExit.mjs";
|
|
7
8
|
import FormField_module_default from "../../components/FormField/FormField.module.mjs";
|
|
8
9
|
import { FieldErrorRenderedContext } from "./fieldErrorRenderedContext.mjs";
|
|
@@ -12,12 +13,13 @@ import { jsx } from "react/jsx-runtime";
|
|
|
12
13
|
var useFieldError = (options) => {
|
|
13
14
|
const currentTunnelId = useProps("FieldError", {}).tunnel?.id;
|
|
14
15
|
const tunnelId = options.tunnelId ?? currentTunnelId ?? `${options.fieldErrorId}.fieldError`;
|
|
16
|
+
const fallbackTunnelId = `${tunnelId}.fallback`;
|
|
15
17
|
const fieldErrorCapturePropsContext = { FieldError: {
|
|
16
18
|
id: options.fieldErrorId,
|
|
17
|
-
tunnel: {
|
|
18
|
-
id: tunnelId,
|
|
19
|
+
tunnel: dynamic((props) => ({
|
|
20
|
+
id: props.isFallback ? fallbackTunnelId : tunnelId,
|
|
19
21
|
component: options.component
|
|
20
|
-
},
|
|
22
|
+
})),
|
|
21
23
|
className: FormField_module_default.fieldError
|
|
22
24
|
} };
|
|
23
25
|
const [renderedFieldErrorId, setRenderedFieldErrorId] = useState();
|
|
@@ -29,7 +31,7 @@ var useFieldError = (options) => {
|
|
|
29
31
|
children: props.children
|
|
30
32
|
});
|
|
31
33
|
}, [tunnelId]),
|
|
32
|
-
FieldErrorView: useMemo(() => () => {
|
|
34
|
+
FieldErrorView: useMemo(() => ({ withoutFallback }) => {
|
|
33
35
|
if (currentTunnelId) return null;
|
|
34
36
|
return /* @__PURE__ */ jsx(FieldErrorRenderedContext, {
|
|
35
37
|
value: setRenderedFieldErrorId,
|
|
@@ -38,12 +40,20 @@ var useFieldError = (options) => {
|
|
|
38
40
|
component: options.component,
|
|
39
41
|
children: (children) => {
|
|
40
42
|
const childrenArray = React.Children.toArray(children);
|
|
41
|
-
return /* @__PURE__ */ jsx(
|
|
43
|
+
return /* @__PURE__ */ jsx(UiComponentTunnelExit, {
|
|
44
|
+
id: fallbackTunnelId,
|
|
45
|
+
component: options.component,
|
|
46
|
+
children: (fallbackChildren) => {
|
|
47
|
+
const fallbackChildrenArray = React.Children.toArray(fallbackChildren);
|
|
48
|
+
return /* @__PURE__ */ jsx(ClearPropsContext, { children: childrenArray[0] ?? (withoutFallback ? null : fallbackChildrenArray[0]) });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
42
51
|
}
|
|
43
52
|
})
|
|
44
53
|
});
|
|
45
54
|
}, [
|
|
46
55
|
currentTunnelId,
|
|
56
|
+
fallbackTunnelId,
|
|
47
57
|
tunnelId,
|
|
48
58
|
options.component
|
|
49
59
|
]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldError.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldError.tsx"],"sourcesContent":["import React, {\n type FC,\n type PropsWithChildren,\n useMemo,\n useState,\n} from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"useFieldError.mjs","names":["formFieldStyles"],"sources":["../../../../../../../src/lib/hooks/useFieldError.tsx"],"sourcesContent":["import React, {\n type FC,\n type PropsWithChildren,\n useMemo,\n useState,\n} from \"react\";\nimport {\n dynamic,\n type PropsContext,\n PropsContextProvider,\n} from \"@/lib/propsContext\";\nimport formFieldStyles from \"@/components/FormField/FormField.module.scss\";\nimport ClearPropsContext from \"@/lib/propsContext/components/ClearPropsContext\";\nimport { useProps } from \"@/lib/hooks/useProps\";\nimport { UiComponentTunnelExit } from \"@/components/UiComponentTunnel/UiComponentTunnelExit\";\nimport type { FlowComponentName } from \"@/components/propTypes\";\nimport { FieldErrorRenderedContext } from \"@/lib/hooks/fieldErrorRenderedContext\";\n\nexport interface FieldErrorViewProps {\n /** Holds a fallback error back, e.g. while the field validates on its own. */\n withoutFallback?: boolean;\n}\n\nexport interface UseFieldErrorOptions {\n fieldErrorId: string;\n tunnelId?: string;\n component: FlowComponentName;\n}\n\nexport const useFieldError = (options: UseFieldErrorOptions) => {\n const fieldErrorProps = useProps(\"FieldError\", {});\n const currentTunnelId = fieldErrorProps.tunnel?.id;\n const tunnelId =\n options.tunnelId ?? currentTunnelId ?? `${options.fieldErrorId}.fieldError`;\n const fallbackTunnelId = `${tunnelId}.fallback`;\n\n const fieldErrorCapturePropsContext: PropsContext = {\n FieldError: {\n id: options.fieldErrorId,\n tunnel: dynamic((props) => ({\n id: props.isFallback ? fallbackTunnelId : tunnelId,\n component: options.component,\n })),\n className: formFieldStyles.fieldError,\n },\n };\n\n const [renderedFieldErrorId, setRenderedFieldErrorId] = useState<string>();\n\n const FieldErrorCaptureContext: FC<PropsWithChildren> = useMemo(\n () => (props) => {\n return (\n <PropsContextProvider\n props={fieldErrorCapturePropsContext}\n dependencies={[tunnelId]}\n >\n {props.children}\n </PropsContextProvider>\n );\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the props context is new each render and only changes with tunnelId\n [tunnelId],\n );\n\n // Keep the component identity stable: a new one per render makes React\n // remount the error on every render of the field (each keystroke).\n const FieldErrorView: FC<FieldErrorViewProps> = useMemo(\n () =>\n ({ withoutFallback }) => {\n if (currentTunnelId) {\n return null;\n }\n\n return (\n <FieldErrorRenderedContext value={setRenderedFieldErrorId}>\n <UiComponentTunnelExit id={tunnelId} component={options.component}>\n {(children) => {\n const childrenArray = React.Children.toArray(children);\n return (\n <UiComponentTunnelExit\n id={fallbackTunnelId}\n component={options.component}\n >\n {(fallbackChildren) => {\n const fallbackChildrenArray =\n React.Children.toArray(fallbackChildren);\n return (\n <ClearPropsContext>\n {childrenArray[0] ??\n (withoutFallback ? null : fallbackChildrenArray[0])}\n </ClearPropsContext>\n );\n }}\n </UiComponentTunnelExit>\n );\n }}\n </UiComponentTunnelExit>\n </FieldErrorRenderedContext>\n );\n },\n [currentTunnelId, fallbackTunnelId, tunnelId, options.component],\n );\n\n return {\n FieldErrorCaptureContext,\n FieldErrorView,\n /**\n * The id of the error while one is rendered for this field. A nested field\n * (a `Checkbox` inside a `CheckboxButton`) renders its error at the outer\n * one, so only the outer field ever gets an id here.\n */\n renderedFieldErrorId,\n } as const;\n};\n"],"mappings":";;;;;;;;;;;;AA6BA,IAAa,iBAAiB,YAAkC;CAE9D,MAAM,kBADkB,SAAS,cAAc,CAAC,CACxB,CAAA,CAAgB,QAAQ;CAChD,MAAM,WACJ,QAAQ,YAAY,mBAAmB,GAAG,QAAQ,aAAa;CACjE,MAAM,mBAAmB,GAAG,SAAS;CAErC,MAAM,gCAA8C,EAClD,YAAY;EACV,IAAI,QAAQ;EACZ,QAAQ,SAAS,WAAW;GAC1B,IAAI,MAAM,aAAa,mBAAmB;GAC1C,WAAW,QAAQ;EACrB,EAAE;EACF,WAAWA,yBAAgB;CAC7B,EACF;CAEA,MAAM,CAAC,sBAAsB,2BAA2B,SAAiB;CAwDzE,OAAO;EACL,0BAvDsD,eAC/C,UAAU;GACf,OACE,oBAAC,sBAAD;IACE,OAAO;IACP,cAAc,CAAC,QAAQ;IAEtB,UAAA,MAAM;GACa,CAAA;EAE1B,GAEA,CAAC,QAAQ,CA2CT;EACA,gBAvC8C,eAE3C,EAAE,sBAAsB;GACvB,IAAI,iBACF,OAAO;GAGT,OACE,oBAAC,2BAAD;IAA2B,OAAO;IAChC,UAAA,oBAAC,uBAAD;KAAuB,IAAI;KAAU,WAAW,QAAQ;KACpD,WAAA,aAAa;MACb,MAAM,gBAAgB,MAAM,SAAS,QAAQ,QAAQ;MACrD,OACE,oBAAC,uBAAD;OACE,IAAI;OACJ,WAAW,QAAQ;OAEjB,WAAA,qBAAqB;QACrB,MAAM,wBACJ,MAAM,SAAS,QAAQ,gBAAgB;QACzC,OACE,oBAAC,mBAAD,EAAA,UACG,cAAc,OACZ,kBAAkB,OAAO,sBAAsB,IACjC,CAAA;OAEvB;MACqB,CAAA;KAE3B;IACqB,CAAA;GACE,CAAA;EAE/B,GACF;GAAC;GAAiB;GAAkB;GAAU,QAAQ;EAAS,CAK/D;;;;;;EAMA;CACF;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FC, PropsWithChildren } from 'react';
|
|
2
2
|
import { PropsContext } from '../propsContext';
|
|
3
|
+
import { FieldErrorViewProps } from './useFieldError';
|
|
3
4
|
import { ClassValue } from 'clsx';
|
|
4
5
|
import { FlowComponentName } from '../../components/propTypes';
|
|
5
6
|
interface FieldComponentProps {
|
|
@@ -10,7 +11,7 @@ interface FieldComponentProps {
|
|
|
10
11
|
}
|
|
11
12
|
export interface UseFieldComponent {
|
|
12
13
|
FieldErrorCaptureContext: FC<PropsWithChildren>;
|
|
13
|
-
FieldErrorView: FC
|
|
14
|
+
FieldErrorView: FC<FieldErrorViewProps>;
|
|
14
15
|
fieldPropsContext: PropsContext;
|
|
15
16
|
/** For the field's outer element. */
|
|
16
17
|
wrapperProps: {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { FlowComponentName } from '../../components/propTypes';
|
|
3
|
+
export interface FieldErrorViewProps {
|
|
4
|
+
/** Holds a fallback error back, e.g. while the field validates on its own. */
|
|
5
|
+
withoutFallback?: boolean;
|
|
6
|
+
}
|
|
3
7
|
export interface UseFieldErrorOptions {
|
|
4
8
|
fieldErrorId: string;
|
|
5
9
|
tunnelId?: string;
|
|
@@ -9,7 +13,7 @@ export declare const useFieldError: (options: UseFieldErrorOptions) => {
|
|
|
9
13
|
readonly FieldErrorCaptureContext: React.FC<{
|
|
10
14
|
children?: React.ReactNode | undefined;
|
|
11
15
|
}>;
|
|
12
|
-
readonly FieldErrorView: React.FC
|
|
16
|
+
readonly FieldErrorView: React.FC<FieldErrorViewProps>;
|
|
13
17
|
/**
|
|
14
18
|
* The id of the error while one is rendered for this field. A nested field
|
|
15
19
|
* (a `Checkbox` inside a `CheckboxButton`) renders its error at the outer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-react-components",
|
|
3
|
-
"version": "1.7.0-next.
|
|
3
|
+
"version": "1.7.0-next.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A React implementation of Flow, mittwald’s design system",
|
|
6
6
|
"homepage": "https://flow.mittwald.de",
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"@internationalized/string-compiler": "^3.4.1",
|
|
85
85
|
"@lezer/common": "^1.5.2",
|
|
86
86
|
"@lezer/highlight": "^1.2.3",
|
|
87
|
-
"@mittwald/flow-icons": "^1.7.0-next.
|
|
87
|
+
"@mittwald/flow-icons": "^1.7.0-next.2",
|
|
88
88
|
"@mittwald/password-tools-js": "^3.0.0",
|
|
89
|
-
"@mittwald/react-tunnel": "^1.7.0-next.
|
|
89
|
+
"@mittwald/react-tunnel": "^1.7.0-next.2",
|
|
90
90
|
"@mittwald/react-use-promise": "^4.2.2",
|
|
91
91
|
"@react-aria/form": "^3.2.1",
|
|
92
92
|
"@react-aria/i18n": "^3.13.1",
|
|
@@ -139,13 +139,13 @@
|
|
|
139
139
|
"@internationalized/date": "^3.12.3",
|
|
140
140
|
"@lezer/generator": "^1.8.0",
|
|
141
141
|
"@lezer/lr": "^1.4.10",
|
|
142
|
-
"@mittwald/flow-components-base": "1.7.0-next.
|
|
143
|
-
"@mittwald/flow-core": "1.7.0-next.
|
|
144
|
-
"@mittwald/flow-design-tokens": "1.7.0-next.
|
|
145
|
-
"@mittwald/flow-icons-base": "1.7.0-next.
|
|
142
|
+
"@mittwald/flow-components-base": "1.7.0-next.2",
|
|
143
|
+
"@mittwald/flow-core": "1.7.0-next.2",
|
|
144
|
+
"@mittwald/flow-design-tokens": "1.7.0-next.2",
|
|
145
|
+
"@mittwald/flow-icons-base": "1.7.0-next.2",
|
|
146
146
|
"@mittwald/react-use-promise": "^4.2.2",
|
|
147
147
|
"@mittwald/remote-dom-react": "1.2.2-mittwald.10",
|
|
148
|
-
"@mittwald/typescript-config": "1.7.0-next.
|
|
148
|
+
"@mittwald/typescript-config": "1.7.0-next.2",
|
|
149
149
|
"@nx/storybook": "^22.7.6",
|
|
150
150
|
"@storybook/addon-a11y": "^10.5.10",
|
|
151
151
|
"@storybook/addon-actions": "^9.0.8",
|
|
@@ -199,7 +199,7 @@
|
|
|
199
199
|
},
|
|
200
200
|
"peerDependencies": {
|
|
201
201
|
"@internationalized/date": "^3.12.2",
|
|
202
|
-
"@mittwald/flow-icons-pro": "1.7.0-next.
|
|
202
|
+
"@mittwald/flow-icons-pro": "1.7.0-next.2",
|
|
203
203
|
"@mittwald/react-use-promise": "^4.2.2",
|
|
204
204
|
"next": "^16.2.3",
|
|
205
205
|
"react": "^19.2.0",
|
|
@@ -223,5 +223,5 @@
|
|
|
223
223
|
"browserslist": [
|
|
224
224
|
"baseline widely available"
|
|
225
225
|
],
|
|
226
|
-
"gitHead": "
|
|
226
|
+
"gitHead": "6cf22f094490b9fa8d4389141d3178b800e6701e"
|
|
227
227
|
}
|