@adyen/kyc-components 3.81.0 → 3.82.0-beta.1
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/{AcceptTermsOfServiceComponent-PDXa81vb.js → AcceptTermsOfServiceComponent-Do0w4uTc.js} +36 -10
- package/dist/{AccountSetupRejected-Du83gH0_.js → AccountSetupRejected-C7bZBsjo.js} +6 -4
- package/dist/Address-CX1FM8LF.js +1076 -0
- package/dist/Alert-DCYc9VpX.js +231 -0
- package/dist/{Avatar-Cd_8eqbA.js → Avatar-BaxjEBNy.js} +2 -2
- package/dist/BusinessDetailsDropin-yG7M7i9-.js +5088 -0
- package/dist/BusinessFinancingComponent-CZZcn51m.js +45 -0
- package/dist/{BusinessFinancingDropin-DioEfiqH.js → BusinessFinancingDropin-EfA32nOP.js} +43 -20
- package/dist/BusinessFinancingPage-Bb1dPIJF.js +40 -0
- package/dist/{BusinessTypeSelectionPage-uk6eDO5O.js → BusinessTypeSelectionPage-CjEomufR.js} +9 -5
- package/dist/Card-DsB6bxW-.js +145 -0
- package/dist/Confirm-X9nR52Md.js +64 -0
- package/dist/{ContractViewer-B2LwC3wV.js → ContractViewer-Byp71k2e.js} +33 -38
- package/dist/CountryField-DxBBjy81.js +864 -0
- package/dist/CreateIndividualComponent-Dyn173AJ.js +72 -0
- package/dist/CreateTransferInstrumentComponent-BT78AU6Z.js +67 -0
- package/dist/Currency-wsIZH1_j.js +238 -0
- package/dist/{CustomerSupport-C4n96PMt.js → CustomerSupport-B7VbKM8X.js} +10 -6
- package/dist/{DebugModal-CYO8HZDV.js → DebugModal-CZwhc_eY.js} +8 -5
- package/dist/{DecisionMakerDetailsPage-IT7x1ZRJ.js → DecisionMakerDetailsPage-Y7E2RfUW.js} +11 -4
- package/dist/{DecisionMakers-DkXmcSK4.js → DecisionMakers-DNepilyq.js} +224 -96
- package/dist/Dropzone-nt4AXJ-H.js +218 -0
- package/dist/{EmbeddedStatus-BS-fmZSm.js → EmbeddedStatus-D0gkDJMZ.js} +4 -4
- package/dist/{EndStateLayout-qrS2Eh-G.js → EndStateLayout-C2whNAgv.js} +2 -2
- package/dist/{FormFlow-BjHYz5-l.js → FormFlow-CRhuooj2.js} +8 -2
- package/dist/FormNavigation-BdFqTFAy.js +162 -0
- package/dist/{IndividualOnfidoDropin-B-y2VRFi.js → IndividualOnfidoDropin-BWM9aKLs.js} +2796 -64
- package/dist/InputDate-DydMc18N.js +43 -0
- package/dist/InputGroup-WBfGDV5F.js +32 -0
- package/dist/InputText-BCNFl9Ni.js +161 -0
- package/dist/{Introduction-CVSG_NSh.js → Introduction-1ZBVqCrd.js} +58 -4
- package/dist/LegalRepresentativeDetailsPage-B2yyvDKF.js +61 -0
- package/dist/Link-BGc9wGrL.js +35 -0
- package/dist/ManageIndividualComponent-CFvL5A-c.js +47 -0
- package/dist/ManageTermsOfServiceComponent-DTrzRxr1.js +47 -0
- package/dist/{ManageTransferInstrumentComponent-Byi222QQ.js → ManageTransferInstrumentComponent-B2cBS1y1.js} +25 -4
- package/dist/MaskedInput-DOTRZoSO.js +799 -0
- package/dist/MaybeModal-SjCkh5yq.js +25 -0
- package/dist/Modal-t5jbmZJu.js +136 -0
- package/dist/{OnboardingDropinComponent-CDK7PYx0.js → OnboardingDropinComponent-DegbZ_o6.js} +200 -41
- package/dist/PayoutDetailsDropin-58zkMbID.js +3694 -0
- package/dist/RadioGroup-Dkwl1v8z.js +143 -0
- package/dist/RegistrationAddress-DOqLUQEe.js +2334 -0
- package/dist/{Review-BCxsmMlz.js → Review-8WTYj81b.js} +8 -4
- package/dist/{RootBusinessDetailsPage-CIWtTZ1z.js → RootBusinessDetailsPage-FDWyaMpG.js} +65 -44
- package/dist/RootIndividualDetailsPage-SFgbb5Bk.js +77 -0
- package/dist/{SignPCIComponent-DzKFISwc.js → SignPCIComponent-bl7LzPjE.js} +17 -8
- package/dist/{SingpassSelection-ChRvdPZF.js → SingpassSelection-DukeaL-T.js} +6 -6
- package/dist/SoleProprietorshipPage-C-XJc7Iq.js +50 -0
- package/dist/{SourceOfFundsPage-DuUOdcam.js → SourceOfFundsPage-D-xLHf2C.js} +46 -24
- package/dist/Spacer-BK3jDget.js +18 -0
- package/dist/StepProgressIndicator-DHei86A6.js +78 -0
- package/dist/StoreProvider-B6-mwoeD.js +7072 -0
- package/dist/StructuredList-DaepaiVE.js +38 -0
- package/dist/{TaskItemStatus-DDwHsmh8.js → TaskItemStatus-BxzVEGbJ.js} +4 -3
- package/dist/{TaskStatusIndicator-Bmm2PsCZ.js → TaskStatusIndicator-Dfp2GcbN.js} +2 -2
- package/dist/TaxInformationField-r8gB7YBi.js +3062 -0
- package/dist/{TaxReportingDropin-kPcT1Kxt.js → TaxReportingDropin-5Lp9F8Ab.js} +25 -9
- package/dist/{TileGroup-BC8PSahf.js → TileGroup-jIldfSJ7.js} +4 -2
- package/dist/{TrustDetailsPage-lnVmcLSH.js → TrustDetailsPage-CjCSvds-.js} +506 -19
- package/dist/TrustMemberCompanyPage-Z6YT-R_a.js +60 -0
- package/dist/TrustMemberIndividualPage-qDN9m9Dv.js +66 -0
- package/dist/UnincorporatedPartnershipIndividualPage-iRZOCq2z.js +66 -0
- package/dist/UnincorporatedPartnershipMemberCompanyPage-9FlDLivA.js +64 -0
- package/dist/{ViewVerificationStatusComponent-D2V-RY2M.js → ViewVerificationStatusComponent-7D-3OVVA.js} +4 -3
- package/dist/adyen-business-financing.js +33 -22
- package/dist/adyen-individual.js +36 -27
- package/dist/adyen-kyc-components.js +28 -15
- package/dist/adyen-manage-individual.js +25 -26
- package/dist/adyen-manage-terms-of-service.js +26 -27
- package/dist/adyen-manage-transfer-instruments.js +40 -42
- package/dist/adyen-onboarding.js +3 -3
- package/dist/adyen-terms-of-service.js +41 -38
- package/dist/adyen-transfer-instrument.js +38 -29
- package/dist/adyen-verification-status.js +44 -36
- package/dist/analytics-CYiivYhI.js +61 -0
- package/dist/{bafinUtils-T6TnU7m4.js → bafinUtils-DSQnsLeT.js} +164 -10
- package/dist/basePatterns-BwdnMQxI.js +15 -0
- package/dist/bg-BG-CW9c658c.js +13 -0
- package/dist/bg-BG-CZ8v3rdy.js +30 -0
- package/dist/{bg-BG-Dlzl9Szn.js → bg-BG-D5192UVe.js} +1 -2
- package/dist/{bg-BG-NMIts2sa.js → bg-BG-QC5irNEG.js} +2 -4
- package/dist/commonValidators-CwkyFFVz.js +24 -0
- package/dist/{cs-CZ-BkyFDlAU.js → cs-CZ-DOqH0WeT.js} +1 -2
- package/dist/cs-CZ-Dx6momCa.js +30 -0
- package/dist/cs-CZ-dU9fnQ1g.js +13 -0
- package/dist/{cs-CZ-Csr_35T-.js → cs-CZ-t297LwYw.js} +2 -4
- package/dist/currency-BGwQyxBo.js +36 -0
- package/dist/{da-DK-B5KNtXL8.js → da-DK-B45X2VaJ.js} +1 -2
- package/dist/da-DK-BJ7aTPir.js +13 -0
- package/dist/{da-DK-Dm8o1giq.js → da-DK-BoQic3Gy.js} +2 -4
- package/dist/da-DK-D4H69PX3.js +30 -0
- package/dist/de-DE-C78RLE2G.js +13 -0
- package/dist/{de-DE-BA9tcpNQ.js → de-DE-CWvgMDqU.js} +1 -2
- package/dist/{de-DE-DMFaycio.js → de-DE-Dwagawx1.js} +2 -4
- package/dist/de-DE-wp5-H-ov.js +30 -0
- package/dist/dropinUtils-CkJv8r-0.js +192 -0
- package/dist/el-GR-BZRKurtr.js +13 -0
- package/dist/{el-GR-DIhHT2q_.js → el-GR-C3rkK_oc.js} +1 -2
- package/dist/el-GR-CK2heqPJ.js +30 -0
- package/dist/{el-GR-CGeBAkDN.js → el-GR-CxwhV-TX.js} +2 -4
- package/dist/emitEvent-CzZf80Am.js +28 -0
- package/dist/{en-US-DX4NHkX-.js → en-US-BbAzROHT.js} +2 -4
- package/dist/{en-US-TrwIHFh-.js → en-US-CAm3meB1.js} +1 -2
- package/dist/{en-US-SbE0c1gn.js → en-US-DIdQJky-.js} +1 -2
- package/dist/en-US.instructions-Ddr7AO05.js +22 -0
- package/dist/{es-ES-pXHx3ODy.js → es-ES-Bsoco8Fj.js} +2 -4
- package/dist/es-ES-BtUSEzkE.js +13 -0
- package/dist/{es-ES-RXwbiHjS.js → es-ES-DKCCgVF8.js} +1 -2
- package/dist/es-ES-Ds3-DtqZ.js +30 -0
- package/dist/et-EE-BCnK305R.js +13 -0
- package/dist/{et-EE-ZssIqWkO.js → et-EE-Bc6ioJRG.js} +1 -2
- package/dist/et-EE-Co-8akjV.js +30 -0
- package/dist/{et-EE-QLVnr6Vl.js → et-EE-DdGlUpaQ.js} +2 -4
- package/dist/{fi-FI-DT351N-G.js → fi-FI-ClnsYt3L.js} +2 -4
- package/dist/fi-FI-Cvar63RH.js +13 -0
- package/dist/fi-FI-DPNeTsJS.js +30 -0
- package/dist/{fi-FI-DmiggQEL.js → fi-FI-Hhku9Lmc.js} +1 -2
- package/dist/fieldConfigurations-CzZ2B1fa.js +458 -0
- package/dist/form-rules-DhbF2mY4.js +13 -0
- package/dist/fr-FR-B5543Fe-.js +13 -0
- package/dist/{fr-FR-N5wYE2BZ.js → fr-FR-BYuKsZIb.js} +1 -2
- package/dist/{fr-FR-BNXXNUX_.js → fr-FR-CJI0bIig.js} +2 -4
- package/dist/fr-FR-ChmNQciP.js +30 -0
- package/dist/getName-BkvLQ7My.js +41 -0
- package/dist/{hasDataChanged-e2EDb7Ni.js → hasDataChanged-B7dryhBQ.js} +2 -2
- package/dist/{hr-HR-B8AZ4eHJ.js → hr-HR-C0yWizOX.js} +2 -4
- package/dist/{hr-HR-5iwKtfgh.js → hr-HR-CPO5Yw2B.js} +1 -2
- package/dist/hr-HR-DqC8Cgs6.js +30 -0
- package/dist/hr-HR-ZreFlbK9.js +13 -0
- package/dist/hu-HU-B3BihdGh.js +13 -0
- package/dist/hu-HU-BOanVlKb.js +30 -0
- package/dist/{hu-HU-Aq1LsWah.js → hu-HU-mo_0ULJG.js} +1 -2
- package/dist/{hu-HU-DRi6Dz9U.js → hu-HU-wnSie9tz.js} +2 -4
- package/dist/iframeWidget-BfmN5KKM.js +234 -0
- package/dist/{payout-verification-instant-BIcnFP-p.js → instant-verification-Dvvkyfmp.js} +3 -3
- package/dist/isEmpty-CJ2g18ZH.js +23 -0
- package/dist/{it-IT-BeYbInCQ.js → it-IT-BeC2Y1F8.js} +2 -4
- package/dist/it-IT-Dd6xGSe-.js +13 -0
- package/dist/{it-IT-8DEagvb2.js → it-IT-Nl57jui-.js} +1 -2
- package/dist/it-IT-eCrTB65E.js +30 -0
- package/dist/ja-JP-BJljbFIZ.js +30 -0
- package/dist/{ja-JP-BhS-_dIx.js → ja-JP-CbgaW99b.js} +2 -2
- package/dist/{ja-JP-BGAJQs1g.js → ja-JP-D3oQAH7z.js} +1 -2
- package/dist/{ja-JP-C1OQ16fo.js → ja-JP-YoU7mNrK.js} +2 -4
- package/dist/ja-JP-iTbqSPNL.js +13 -0
- package/dist/keys-BpNgnAsD.js +23 -0
- package/dist/{localizeDateString-VqxvPF9j.js → localizeDateString-C4IzMd3y.js} +2 -2
- package/dist/{lt-LT-HZOWQKZT.js → lt-LT-CVasDmF3.js} +1 -2
- package/dist/lt-LT-DE-4IXNG.js +13 -0
- package/dist/{lt-LT-_MzAcXJo.js → lt-LT-DIe4cKlu.js} +2 -4
- package/dist/lt-LT-DckQGgoT.js +30 -0
- package/dist/lv-LV-CeivEZms.js +13 -0
- package/dist/lv-LV-DP9oRTFv.js +30 -0
- package/dist/{lv-LV-CRhXAjn6.js → lv-LV-DXgW5zWl.js} +2 -4
- package/dist/{lv-LV-F-Z4lDCV.js → lv-LV-Sbsv8-nD.js} +1 -2
- package/dist/{payout-verification-manual-DH9-DdlZ.js → manual-verification-BvZWqA00.js} +3 -3
- package/dist/mapExistingFile-D8NcT-or.js +231 -0
- package/dist/mapScriptLocalization-DBcq31SQ.js +72 -0
- package/dist/mapTransferInstrumentToPayoutAccount-CijqOJMZ.js +30 -0
- package/dist/{nl-NL-C-xUU2N3.js → nl-NL-BHkRnVrj.js} +1 -2
- package/dist/{nl-NL-Dbx0ZmI7.js → nl-NL-Cysslsh2.js} +2 -4
- package/dist/nl-NL-D2QKudfh.js +30 -0
- package/dist/nl-NL-DVENFpd5.js +13 -0
- package/dist/no-NO-C_snYWBc.js +30 -0
- package/dist/no-NO-Dn2UkdoI.js +13 -0
- package/dist/{no-NO-47ncaBZY.js → no-NO-kaAdT9B8.js} +1 -2
- package/dist/{no-NO-C0sfkp82.js → no-NO-zSnPtrDi.js} +2 -4
- package/dist/pl-PL-CQ6c2Qz_.js +30 -0
- package/dist/{pl-PL-CZLzkboH.js → pl-PL-DD8JN4Qf.js} +1 -2
- package/dist/pl-PL-DFAzuceF.js +13 -0
- package/dist/{pl-PL-DAPGaxWi.js → pl-PL-UB5J5JcB.js} +2 -4
- package/dist/pt-PT-C-hbNnsB.js +30 -0
- package/dist/{pt-PT-BY9rcwcF.js → pt-PT-CjsyP_OK.js} +2 -4
- package/dist/{pt-PT-CN4ws8N7.js → pt-PT-Xm-pm3mb.js} +1 -2
- package/dist/pt-PT-_o5xgnxS.js +13 -0
- package/dist/{resolveEnvironment-CDg6ksvB.js → resolveEnvironment-94mV6qts.js} +3 -3
- package/dist/ro-RO-BrTWk1Ui.js +30 -0
- package/dist/{ro-RO-RylOvc5g.js → ro-RO-C3m6aJVP.js} +1 -2
- package/dist/{ro-RO-DJLWmWZ4.js → ro-RO-C8yYXQc_.js} +2 -4
- package/dist/ro-RO-D7c_Rj8V.js +13 -0
- package/dist/{rules-BnJSV_NR.js → rules-D9wLpDnS.js} +5 -2
- package/dist/sk-SK-BBSuh2fA.js +13 -0
- package/dist/sk-SK-BTFtoPmI.js +30 -0
- package/dist/{sk-SK-BfJKbtGy.js → sk-SK-BVc-vNQm.js} +1 -2
- package/dist/{sk-SK-B7o3L57C.js → sk-SK-DbOE9C6n.js} +2 -4
- package/dist/sl-SI-BLTuWNf5.js +13 -0
- package/dist/sl-SI-BhVTSmhQ.js +30 -0
- package/dist/{sl-SI-C8CMAkD0.js → sl-SI-Br0UEUPL.js} +2 -4
- package/dist/{sl-SI-DklUFzaY.js → sl-SI-D_rqR0D7.js} +1 -2
- package/dist/style.css +3272 -3254
- package/dist/styles-CLV89_hH.js +3272 -3254
- package/dist/sv-SE-66rqYTxi.js +30 -0
- package/dist/{sv-SE-qduyDIzY.js → sv-SE-B3zoXMuH.js} +1 -2
- package/dist/sv-SE-BUfESAQK.js +13 -0
- package/dist/{sv-SE-Bwh0wKFk.js → sv-SE-BtXmvxx4.js} +2 -4
- package/dist/translation-BxcrjuWb.js +472 -0
- package/dist/types/api/industryCodes/industryCodes.types.d.ts +2 -0
- package/dist/types/api/industryCodes/useIndustryCodes.d.ts +6 -0
- package/dist/types/api/queryKeys.d.ts +2 -1
- package/dist/types/components/BankAccount/forms/PayoutDetails/PayoutDetails.d.ts +1 -0
- package/dist/types/components/BankAccount/forms/PayoutVerificationMethod/payoutVerificationMethodMetadata.d.ts +3 -3
- package/dist/types/components/BankAccount/tasks/PayoutDetailsDropin/payoutDetailsFormConfig.d.ts +0 -9
- package/dist/types/components/Business/forms/BasicInformation/BasicInformationMultiform.d.ts +0 -1
- package/dist/types/components/Business/forms/BusinessDetails/forms.d.ts +6 -0
- package/dist/types/components/Business/forms/rules.d.ts +1 -3
- package/dist/types/components/Business/tasks/BusinessDetailsDropin/utils.d.ts +1 -2
- package/dist/types/components/Business/tasks/BusinessDetailsMultiformDropin/BusinessDetailsMultiform.d.ts +1 -1
- package/dist/types/components/Contract/tasks/ServiceAgreementDropin/ServiceAgreementDropin.d.ts +1 -1
- package/dist/types/components/Contract/tasks/ServiceAgreementDropin/types.d.ts +1 -0
- package/dist/types/components/EFP/tasks/SourceOfFundsDropin/utils.d.ts +0 -1
- package/dist/types/components/EmbeddedDropins/AcceptTermsOfServiceComponent/AcceptTermsOfServiceComponent.d.ts +4 -3
- package/dist/types/components/Individual/forms/Individual/Individual.d.ts +4 -0
- package/dist/types/components/Individual/forms/Individual/ProofOfRelationship/types.d.ts +0 -5
- package/dist/types/components/Shared/fields/IdFieldTypeSelector/countryIdNumberTypes.d.ts +1 -1
- package/dist/types/components/Shared/forms/Address/utils.d.ts +1 -1
- package/dist/types/components/Trust/forms/Trust/Trust.d.ts +1 -0
- package/dist/types/components/Trust/forms/TrustRegistrationDetails/types.d.ts +1 -2
- package/dist/types/components/Trust/tasks/TrustMembers/TrustMembersOverview.d.ts +2 -1
- package/dist/types/components/UnincorporatedPartnership/pages/UnincorporatedPartnershipMemberCompanyPage.d.ts +2 -1
- package/dist/types/components/ui/atoms/ActionsMenu/ActionsMenu.d.ts +2 -1
- package/dist/types/components/ui/atoms/Button/Button.types.d.ts +3 -3
- package/dist/types/components/ui/atoms/ListItem/ListItem.d.ts +2 -1
- package/dist/types/components/ui/atoms/RadioGroupCard/RadioGroupCard.types.d.ts +0 -14
- package/dist/types/components/ui/atoms/RadioWithLabel/RadioWithLabel.d.ts +2 -1
- package/dist/types/components/ui/atoms/SelectList/SelectList.d.ts +1 -0
- package/dist/types/components/ui/atoms/StepProgressIndicator/StepProgressIndicator.d.ts +2 -1
- package/dist/types/components/ui/atoms/StructuredList/StructuredList.d.ts +2 -1
- package/dist/types/components/ui/atoms/Svg/svgs.d.ts +0 -12
- package/dist/types/components/ui/atoms/TaskStatusIndicator/TaskStatusIndicator.d.ts +3 -2
- package/dist/types/components/ui/layout/LandingLayout/LandingLayout.d.ts +1 -1
- package/dist/types/components/ui/layout/StackLayout/StackLayout.d.ts +2 -1
- package/dist/types/components/ui/molecules/InputCurrency/InputCurrency.d.ts +2 -1
- package/dist/types/components/ui/molecules/InputEmail/InputEmail.d.ts +2 -1
- package/dist/types/components/ui/molecules/InputGroup/InputGroup.d.ts +2 -1
- package/dist/types/components/ui/molecules/InputTelephone/InputTelephone.d.ts +2 -1
- package/dist/types/components/ui/molecules/InputText/InputText.d.ts +2 -0
- package/dist/types/components/ui/molecules/MaskedInput/MaskedInput.d.ts +0 -1
- package/dist/types/components/ui/molecules/Tabs/Tabs.d.ts +1 -1
- package/dist/types/context/StateContext/types.d.ts +1 -1
- package/dist/types/core/models/api/accountIdentification.d.ts +5 -4
- package/dist/types/core/models/api/contracts.d.ts +1 -1
- package/dist/types/core/process-field-configurations.d.ts +14 -3
- package/dist/types/embeds/business-financing/AdyenBusinessFinancing.d.ts +1 -1
- package/dist/types/embeds/business-financing/adyen-business-financing.types.d.ts +1 -5
- package/dist/types/embeds/emitEvent.d.ts +14 -0
- package/dist/types/embeds/individual/adyen-individual.types.d.ts +2 -2
- package/dist/types/embeds/manage-individual/AdyenManageIndividual.d.ts +1 -1
- package/dist/types/embeds/manage-individual/adyen-manage-individual.types.d.ts +1 -1
- package/dist/types/embeds/manage-terms-of-service/AdyenManageTermsOfService.d.ts +1 -1
- package/dist/types/embeds/manage-terms-of-service/adyen-manage-terms-of-service.types.d.ts +1 -1
- package/dist/types/embeds/manage-transfer-instruments/AdyenManageTransferInstrument.d.ts +3 -4
- package/dist/types/embeds/manage-transfer-instruments/adyen-manage-transfer-instruments.types.d.ts +3 -4
- package/dist/types/embeds/terms-of-service/adyen-terms-of-service.types.d.ts +4 -3
- package/dist/types/embeds/transfer-instrument/adyen-transfer-instrument.types.d.ts +2 -2
- package/dist/types/embeds/verification-status/adyen-verification-status.types.d.ts +3 -3
- package/dist/types/hooks/introduction/useIntroductionScreens.d.ts +2 -1
- package/dist/types/hooks/introduction/useShouldShowIntroduction.d.ts +2 -1
- package/dist/types/language/utils.d.ts +1 -1
- package/dist/types/utils/addLinkedFields.d.ts +7 -1
- package/dist/types/utils/entityStatusUtil.d.ts +1 -1
- package/dist/types/utils/formUtils.d.ts +1 -1
- package/dist/types/utils/getDisplayErrorMessage.d.ts +1 -1
- package/dist/types/utils/getName.d.ts +1 -1
- package/dist/types/utils/makeSelectItemForRole.d.ts +1 -1
- package/dist/types/utils/masking/masks/businessRegistrationNumberMasks.d.ts +5 -0
- package/dist/types/utils/translation.d.ts +6 -0
- package/dist/types-CAznNNSI.js +160 -0
- package/dist/types-DAyrP-xk.js +64 -0
- package/dist/types-Da02-5C7.js +74 -0
- package/dist/useAssociatedLegalEntity-Bw8j7jsT.js +33 -0
- package/dist/useDataset-BLJa9WLi.js +120 -0
- package/dist/useForm-CiqZ15MF.js +1694 -0
- package/dist/useFormContext-beqGS11A.js +23 -0
- package/dist/useGlobalData-DRn0XQ0c.js +205 -0
- package/dist/{useMultiForm-Cbf_MGdG.js → useMultiForm-B2RH71uE.js} +4 -2
- package/dist/{useOnboardingStatus-bmHIDRGr.js → useOnboardingStatus-D1idaeSA.js} +2 -2
- package/dist/useScenarios-MJLlpy2B.js +46 -0
- package/dist/{useTermsOfServiceStatus-CMtyaC84.js → useTermsOfServiceStatus-YnguYeSj.js} +2 -2
- package/dist/useToastContext-BBdhLX_K.js +51 -0
- package/dist/useUnincorporatedPartnershipMembers-TCYzsxr-.js +99 -0
- package/dist/utils-Bw6dVL0x.js +29 -0
- package/dist/{utils-B-s8erbM.js → utils-CMkU9dq6.js} +46 -4
- package/dist/utils-DNSfZiio.js +70 -0
- package/dist/utils-Drt88lUg.js +159 -0
- package/dist/validate-BacCnDiH.js +382 -0
- package/dist/{validate-CNlNB2Sq.js → validate-BlPEAs8d.js} +2 -2
- package/dist/validate-DQ_IsigQ.js +605 -0
- package/dist/validationError-eJqGwKE_.js +86 -0
- package/package.json +44 -45
- package/dist/BusinessDetailsDropin-DR8YA-wz.js +0 -2136
- package/dist/BusinessFinancingComponent-saZxipq7.js +0 -38
- package/dist/BusinessFinancingPage-D7NMT1SV.js +0 -35
- package/dist/CreateIndividualComponent-B_6j8j5H.js +0 -64
- package/dist/CreateTransferInstrumentComponent-DgZq6f2m.js +0 -55
- package/dist/LegalRepresentativeDetailsPage-R9h6n8e1.js +0 -55
- package/dist/ManageIndividualComponent-D3EZWpKz.js +0 -42
- package/dist/ManageTermsOfServiceComponent-C2BMpyzo.js +0 -40
- package/dist/RootIndividualDetailsPage-DGpYhDWo.js +0 -71
- package/dist/SoleProprietorshipPage-CF_TKUfD.js +0 -44
- package/dist/StoreProvider-pdSV8sgb.js +0 -31920
- package/dist/TrustMemberCompanyPage-6_h3PnmT.js +0 -54
- package/dist/TrustMemberIndividualPage-DPlQ6OnQ.js +0 -60
- package/dist/UnincorporatedPartnershipIndividualPage-Bgcip8u6.js +0 -60
- package/dist/UnincorporatedPartnershipMemberCompanyPage-k5Cc0TWw.js +0 -57
- package/dist/VerificationErrorAlert-BEgXW4gA.js +0 -77
- package/dist/bg-BG-BvSUDgGF.js +0 -13
- package/dist/cs-CZ-y4mvq4Lv.js +0 -13
- package/dist/da-DK-qgQOVjDp.js +0 -13
- package/dist/de-DE-pSdsxBpQ.js +0 -13
- package/dist/el-GR-Bvjk5Sw8.js +0 -13
- package/dist/en-US-Bq2Twy6x.js +0 -54
- package/dist/es-ES-Dy1uR2H_.js +0 -13
- package/dist/et-EE-d9V24rcf.js +0 -13
- package/dist/fi-FI-B0fnAFV2.js +0 -13
- package/dist/fr-FR-BoKzVp2q.js +0 -13
- package/dist/getFieldsWithExistingData-BPKk0HGd.js +0 -22
- package/dist/hr-HR-CF0AHQzi.js +0 -13
- package/dist/hu-HU-CSPhOvLC.js +0 -13
- package/dist/it-IT-BH-eqIKH.js +0 -13
- package/dist/ja-JP-B3yqM_FM.js +0 -13
- package/dist/lt-LT-Lzl_Cbw-.js +0 -13
- package/dist/lv-LV-y00wN1pj.js +0 -13
- package/dist/mapFinancialReportsToFinancialInformation-iVvcsDNu.js +0 -66
- package/dist/mapScriptLocalization-H2Re3k5X.js +0 -35
- package/dist/nl-NL-DmnFXAQC.js +0 -13
- package/dist/no-NO-DbvFfP96.js +0 -13
- package/dist/pl-PL--mmxopYA.js +0 -13
- package/dist/pt-PT-BVzXBFp7.js +0 -13
- package/dist/ro-RO-Cdmevo9A.js +0 -13
- package/dist/ru-RU-FZb2upqh.js +0 -13
- package/dist/sk-SK-nfeuTcY5.js +0 -13
- package/dist/sl-SI-DUTZDqkP.js +0 -13
- package/dist/sv-SE-BTx2XKAp.js +0 -13
- package/dist/useUpdateLegalEntity-D91nO-DU.js +0 -57
- package/dist/validate-DhvbSKV4.js +0 -40
- package/dist/zh-CN-wUb4MmTZ.js +0 -13
- package/dist/zh-TW-DNTXHLKa.js +0 -13
|
@@ -0,0 +1,1694 @@
|
|
|
1
|
+
;
|
|
2
|
+
{
|
|
3
|
+
try {
|
|
4
|
+
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
|
|
5
|
+
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "485ea493-c135-47be-a588-a19ed650ab45", e._sentryDebugIdIdentifier = "sentry-dbid-485ea493-c135-47be-a588-a19ed650ab45");
|
|
6
|
+
} catch (e) {
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
;
|
|
10
|
+
import { jsxs, Fragment, jsx } from "preact/jsx-runtime";
|
|
11
|
+
import cx from "classnames";
|
|
12
|
+
import { useState, useEffect, useRef, useMemo, useCallback, useReducer } from "preact/hooks";
|
|
13
|
+
import { U as useAnalyticsContext, a as useTranslation, V as Icon, w as translateStringOrObject, L as Loader, W as noop, x as Typography, N as createLogger, a9 as isEmpty, az as entriesOf, aG as doArraysMatch } from "./StoreProvider-B6-mwoeD.js";
|
|
14
|
+
import { computed, signal, useSignal, useSignalEffect } from "@preact/signals";
|
|
15
|
+
import { K as KEYBOARD_KEYS } from "./keys-BpNgnAsD.js";
|
|
16
|
+
import { d as debouncedInputEvent } from "./analytics-CYiivYhI.js";
|
|
17
|
+
function Checkbox({
|
|
18
|
+
id,
|
|
19
|
+
name,
|
|
20
|
+
value,
|
|
21
|
+
className,
|
|
22
|
+
label,
|
|
23
|
+
isInvalid,
|
|
24
|
+
onChange,
|
|
25
|
+
helper,
|
|
26
|
+
checked,
|
|
27
|
+
readonly,
|
|
28
|
+
disabled,
|
|
29
|
+
enableTracking = false,
|
|
30
|
+
"aria-required": ariaRequired,
|
|
31
|
+
"aria-invalid": ariaInvalid,
|
|
32
|
+
"aria-describedby": ariaDescribedBy
|
|
33
|
+
}) {
|
|
34
|
+
const userEvents = useAnalyticsContext();
|
|
35
|
+
const handleChange = (newValue) => {
|
|
36
|
+
if (enableTracking) {
|
|
37
|
+
userEvents.addFieldEvent("Interacted with form field", {
|
|
38
|
+
actionType: "input",
|
|
39
|
+
field: name,
|
|
40
|
+
returnValue: String(newValue)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
onChange(newValue);
|
|
44
|
+
};
|
|
45
|
+
const helperId = `${id}-helper`;
|
|
46
|
+
const ariaDescribedById = `${helper ? helperId : ""} ${ariaDescribedBy ?? ""}`.trim();
|
|
47
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
"input",
|
|
50
|
+
{
|
|
51
|
+
id,
|
|
52
|
+
name,
|
|
53
|
+
value,
|
|
54
|
+
"aria-describedby": ariaDescribedById,
|
|
55
|
+
"aria-invalid": ariaInvalid || isInvalid,
|
|
56
|
+
"aria-required": ariaRequired,
|
|
57
|
+
readOnly: readonly,
|
|
58
|
+
disabled,
|
|
59
|
+
checked,
|
|
60
|
+
className: cx([
|
|
61
|
+
"adyen-kyc-checkbox__input",
|
|
62
|
+
[className],
|
|
63
|
+
{ "adyen-kyc-checkbox__input--invalid": isInvalid }
|
|
64
|
+
]),
|
|
65
|
+
type: "checkbox",
|
|
66
|
+
onClick: (event) => {
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
handleChange(!checked);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsx("label", { htmlFor: id, className: "adyen-kyc-checkbox__label", children: label }),
|
|
73
|
+
helper && /* @__PURE__ */ jsx("span", { id: helperId, className: "adyen-kyc-checkbox__helper-text", children: helper })
|
|
74
|
+
] });
|
|
75
|
+
}
|
|
76
|
+
const ARIA_ERROR_SUFFIX = "-ariaError";
|
|
77
|
+
function uuidv4() {
|
|
78
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
79
|
+
let r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
80
|
+
return v.toString(16);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const useId = (prefix) => {
|
|
84
|
+
const [uuid] = useState(uuidv4());
|
|
85
|
+
return `${prefix}_${uuid}`;
|
|
86
|
+
};
|
|
87
|
+
const MaybeFieldset = ({
|
|
88
|
+
children,
|
|
89
|
+
className,
|
|
90
|
+
name,
|
|
91
|
+
disabled,
|
|
92
|
+
el,
|
|
93
|
+
dataTestId
|
|
94
|
+
}) => el === "fieldset" ? /* @__PURE__ */ jsx("fieldset", { name, disabled, className, "data-testid": dataTestId, children }) : /* @__PURE__ */ jsx("div", { className, "data-testid": dataTestId, children });
|
|
95
|
+
const Field = ({
|
|
96
|
+
className,
|
|
97
|
+
classNameModifiers = [],
|
|
98
|
+
children,
|
|
99
|
+
disabled,
|
|
100
|
+
optional,
|
|
101
|
+
errorMessage,
|
|
102
|
+
formatGuidance,
|
|
103
|
+
helper,
|
|
104
|
+
helperPosition = "above",
|
|
105
|
+
isValid,
|
|
106
|
+
label,
|
|
107
|
+
name,
|
|
108
|
+
showErrorIconBottom = false,
|
|
109
|
+
showErrorIcon = true,
|
|
110
|
+
el = "div",
|
|
111
|
+
dataTestId,
|
|
112
|
+
onBlur,
|
|
113
|
+
onFieldBlur,
|
|
114
|
+
onFocus
|
|
115
|
+
}) => {
|
|
116
|
+
const uniqueId = useId("field");
|
|
117
|
+
const { t } = useTranslation("common");
|
|
118
|
+
const userEvents = useAnalyticsContext();
|
|
119
|
+
const Label = el === "fieldset" ? "legend" : "label";
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!errorMessage) return;
|
|
122
|
+
const returnValue = typeof errorMessage === "string" && errorMessage || typeof errorMessage === "object" && errorMessage.key || "invalid";
|
|
123
|
+
userEvents.addFieldEvent("Encountered error", {
|
|
124
|
+
actionType: "input",
|
|
125
|
+
field: name,
|
|
126
|
+
returnType: "validation",
|
|
127
|
+
returnValue
|
|
128
|
+
});
|
|
129
|
+
}, [name, errorMessage, userEvents]);
|
|
130
|
+
const elementIds = {
|
|
131
|
+
label: `${uniqueId}-label`,
|
|
132
|
+
helper: `${uniqueId}-helper`,
|
|
133
|
+
error: `${uniqueId}${ARIA_ERROR_SUFFIX}`,
|
|
134
|
+
guidanceText: `${uniqueId}-guidanceText`
|
|
135
|
+
};
|
|
136
|
+
const inputDescribedBy = `${errorMessage ? elementIds.error : ""} ${helper ? elementIds.helper : ""} ${formatGuidance ? elementIds.guidanceText : ""}`.trim();
|
|
137
|
+
return /* @__PURE__ */ jsxs(
|
|
138
|
+
MaybeFieldset,
|
|
139
|
+
{
|
|
140
|
+
className: cx(
|
|
141
|
+
"adyen-kyc-field",
|
|
142
|
+
className,
|
|
143
|
+
classNameModifiers.map((m) => `adyen-kyc-field--${m}`),
|
|
144
|
+
{
|
|
145
|
+
"adyen-kyc-field--error": !!errorMessage,
|
|
146
|
+
"adyen-kyc-field--valid": isValid,
|
|
147
|
+
"adyen-kyc-field--disabled": disabled
|
|
148
|
+
}
|
|
149
|
+
),
|
|
150
|
+
name,
|
|
151
|
+
disabled,
|
|
152
|
+
el,
|
|
153
|
+
dataTestId,
|
|
154
|
+
children: [
|
|
155
|
+
label && /* @__PURE__ */ jsxs(
|
|
156
|
+
Label,
|
|
157
|
+
{
|
|
158
|
+
id: elementIds.label,
|
|
159
|
+
htmlFor: el === "fieldset" ? void 0 : uniqueId,
|
|
160
|
+
className: cx("adyen-kyc-label__text", {
|
|
161
|
+
"adyen-kyc-label__text--error": !!errorMessage
|
|
162
|
+
}),
|
|
163
|
+
children: [
|
|
164
|
+
label,
|
|
165
|
+
optional && /* @__PURE__ */ jsxs("span", { className: "adyen-kyc-optional-label", children: [
|
|
166
|
+
" ",
|
|
167
|
+
t(($) => $["optional"])
|
|
168
|
+
] })
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
helper && helperPosition === "above" && /* @__PURE__ */ jsx("span", { id: elementIds.helper, className: "adyen-kyc-helper-text adyen-kyc-helper-text__above", children: helper }),
|
|
173
|
+
/* @__PURE__ */ jsxs("div", { className: "adyen-kyc-input-wrapper", children: [
|
|
174
|
+
children({
|
|
175
|
+
id: uniqueId,
|
|
176
|
+
"aria-labelledby": elementIds.label,
|
|
177
|
+
"aria-describedby": inputDescribedBy,
|
|
178
|
+
isInvalid: !!errorMessage,
|
|
179
|
+
isValid: !!isValid,
|
|
180
|
+
onBlurHandler: (e) => {
|
|
181
|
+
if (typeof onBlur === "function") onBlur(e);
|
|
182
|
+
if (typeof onFieldBlur === "function") onFieldBlur(e);
|
|
183
|
+
},
|
|
184
|
+
onFocusHandler: (e) => {
|
|
185
|
+
if (typeof onFocus === "function") onFocus(e);
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
helper && helperPosition === "below" && /* @__PURE__ */ jsx(
|
|
189
|
+
"span",
|
|
190
|
+
{
|
|
191
|
+
id: elementIds.helper,
|
|
192
|
+
className: "adyen-kyc-helper-text adyen-kyc-helper-text__below",
|
|
193
|
+
children: helper
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
isValid && /* @__PURE__ */ jsx("span", { className: "adyen-kyc-input__inline-validation adyen-kyc-input__inline-validation--valid", children: /* @__PURE__ */ jsx(Icon, { name: "check" }) }),
|
|
197
|
+
!!errorMessage && !showErrorIconBottom && showErrorIcon && /* @__PURE__ */ jsx("span", { className: "adyen-kyc-input__inline-validation adyen-kyc-input__inline-validation--invalid", children: /* @__PURE__ */ jsx(Icon, { name: "field-error" }) })
|
|
198
|
+
] }),
|
|
199
|
+
/* @__PURE__ */ jsxs("div", { "aria-live": "polite", "aria-atomic": true, className: "adyen-kyc-error-text", children: [
|
|
200
|
+
/* @__PURE__ */ jsx("span", { className: "adyen-kyc-u-screen-reader-only", children: `${label}:` }),
|
|
201
|
+
!!errorMessage && typeof errorMessage !== "boolean" && /* @__PURE__ */ jsxs("span", { id: elementIds.error, children: [
|
|
202
|
+
translateStringOrObject(t, errorMessage),
|
|
203
|
+
showErrorIconBottom && /* @__PURE__ */ jsx("span", { className: "adyen-kyc-input__inline-validation adyen-kyc-input__inline-validation--invalid-bottom", children: /* @__PURE__ */ jsx(Icon, { name: "field-error" }) })
|
|
204
|
+
] })
|
|
205
|
+
] }),
|
|
206
|
+
!errorMessage && formatGuidance && /* @__PURE__ */ jsx("span", { id: elementIds.guidanceText, "aria-live": "polite", className: "adyen-kyc-guidance-text", children: formatGuidance })
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
};
|
|
211
|
+
const loaderWrapperLoader = "adyen-kyc-loader-wrapper-loader";
|
|
212
|
+
const loaderWrapperLoaderActive = "adyen-kyc-loader-wrapper-loader-active";
|
|
213
|
+
const styles$1 = {
|
|
214
|
+
loaderWrapperLoader,
|
|
215
|
+
loaderWrapperLoaderActive
|
|
216
|
+
};
|
|
217
|
+
const LoaderWrapper = ({
|
|
218
|
+
children,
|
|
219
|
+
status,
|
|
220
|
+
formOpacityWhenLoading = 0,
|
|
221
|
+
loaderSize = "medium",
|
|
222
|
+
showSpinner = true,
|
|
223
|
+
className
|
|
224
|
+
}) => {
|
|
225
|
+
const opacitySyle = status === "loading" ? {
|
|
226
|
+
opacity: formOpacityWhenLoading
|
|
227
|
+
} : { opacity: 1 };
|
|
228
|
+
const loaderWrapperClass = cx(styles$1.loaderWrapperLoader, {
|
|
229
|
+
[styles$1.loaderWrapperLoaderActive]: status === "loading" && showSpinner
|
|
230
|
+
});
|
|
231
|
+
const overlayClass = cx(styles$1.loaderWrapper, className);
|
|
232
|
+
return /* @__PURE__ */ jsxs("div", { className: overlayClass, style: { position: "relative" }, children: [
|
|
233
|
+
/* @__PURE__ */ jsx("div", { className: loaderWrapperClass, children: /* @__PURE__ */ jsx(Loader, { size: loaderSize }) }),
|
|
234
|
+
/* @__PURE__ */ jsx("div", { className: styles$1.loaderWrapperForm, style: opacitySyle, children })
|
|
235
|
+
] });
|
|
236
|
+
};
|
|
237
|
+
const createSelectFocus = ({
|
|
238
|
+
activeItems,
|
|
239
|
+
filteredItems: items
|
|
240
|
+
}) => {
|
|
241
|
+
const numberOfItems = computed(() => items.value.length - 1);
|
|
242
|
+
const focused = signal();
|
|
243
|
+
const getDefaultFocusedItem = () => {
|
|
244
|
+
const firstActiveOption = activeItems.value.find((option) => !option.disabled);
|
|
245
|
+
const firstEnabledOption = items.value.find((option) => !option.disabled);
|
|
246
|
+
return firstActiveOption ?? firstEnabledOption;
|
|
247
|
+
};
|
|
248
|
+
const focusedItemIndex = computed(() => {
|
|
249
|
+
const currFocus = focused.value;
|
|
250
|
+
const toFind = focusedIsItem(currFocus) ? currFocus : getDefaultFocusedItem();
|
|
251
|
+
if (!toFind) {
|
|
252
|
+
console.warn("[Select] No existing focused item, and none of the filtered items are enabled");
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
return items.value.findIndex((i) => i.id === toFind.id);
|
|
256
|
+
});
|
|
257
|
+
const findPotentialIndex = (currentIndex, direction) => {
|
|
258
|
+
const potentialIndex = direction === "down" ? currentIndex + 1 : currentIndex - 1;
|
|
259
|
+
const potentialItem = items.value[potentialIndex];
|
|
260
|
+
if (potentialIndex < 0 || potentialIndex > numberOfItems.value) {
|
|
261
|
+
return "exceedsBounds";
|
|
262
|
+
}
|
|
263
|
+
if (potentialItem.disabled) {
|
|
264
|
+
return findPotentialIndex(potentialIndex, direction);
|
|
265
|
+
}
|
|
266
|
+
return potentialIndex;
|
|
267
|
+
};
|
|
268
|
+
const moveFocusToNextItem = () => {
|
|
269
|
+
const nextIndex = findPotentialIndex(focusedItemIndex.value, "down");
|
|
270
|
+
if (nextIndex !== "exceedsBounds") focused.value = items.value[nextIndex];
|
|
271
|
+
};
|
|
272
|
+
const moveFocusToPreviousItem = () => {
|
|
273
|
+
const prevIndex = findPotentialIndex(focusedItemIndex.value, "up");
|
|
274
|
+
if (prevIndex !== "exceedsBounds") focused.value = items.value[prevIndex];
|
|
275
|
+
};
|
|
276
|
+
const moveFocusToFirstItem = () => {
|
|
277
|
+
let currIndex = focusedItemIndex.value;
|
|
278
|
+
while (true) {
|
|
279
|
+
const before = findPotentialIndex(currIndex, "up");
|
|
280
|
+
if (before === "exceedsBounds") break;
|
|
281
|
+
currIndex = before;
|
|
282
|
+
}
|
|
283
|
+
focused.value = items.value[currIndex];
|
|
284
|
+
};
|
|
285
|
+
const moveFocusToLastItem = () => {
|
|
286
|
+
let currIndex = focusedItemIndex.value;
|
|
287
|
+
while (true) {
|
|
288
|
+
const after = findPotentialIndex(currIndex, "down");
|
|
289
|
+
if (after === "exceedsBounds") break;
|
|
290
|
+
currIndex = after;
|
|
291
|
+
}
|
|
292
|
+
focused.value = items.value[currIndex];
|
|
293
|
+
};
|
|
294
|
+
const focusInput = () => {
|
|
295
|
+
focused.value = "input";
|
|
296
|
+
};
|
|
297
|
+
const focusItem = (item) => {
|
|
298
|
+
focused.value = item;
|
|
299
|
+
};
|
|
300
|
+
const focusDefaultItem = () => {
|
|
301
|
+
focused.value = getDefaultFocusedItem();
|
|
302
|
+
};
|
|
303
|
+
const focusNothing = () => {
|
|
304
|
+
focused.value = void 0;
|
|
305
|
+
};
|
|
306
|
+
return {
|
|
307
|
+
focused,
|
|
308
|
+
moveFocusToFirstItem,
|
|
309
|
+
moveFocusToLastItem,
|
|
310
|
+
moveFocusToNextItem,
|
|
311
|
+
moveFocusToPreviousItem,
|
|
312
|
+
focusInput,
|
|
313
|
+
focusItem,
|
|
314
|
+
focusDefaultItem,
|
|
315
|
+
focusNothing
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
const useSelectFocus = (options) => {
|
|
319
|
+
const [selectFocus] = useState(createSelectFocus(options));
|
|
320
|
+
return selectFocus;
|
|
321
|
+
};
|
|
322
|
+
const focusedIsItem = (focused) => Boolean(focused) && typeof focused === "object";
|
|
323
|
+
const useWatchingSignal = (value) => {
|
|
324
|
+
const signal2 = useSignal(value);
|
|
325
|
+
if (signal2.peek() !== value) signal2.value = value;
|
|
326
|
+
return signal2;
|
|
327
|
+
};
|
|
328
|
+
const simulateTextChangeFromKeyboardEvent = (keyDownEvent, value) => {
|
|
329
|
+
const { key } = keyDownEvent;
|
|
330
|
+
let newValue = value;
|
|
331
|
+
if (key === KEYBOARD_KEYS.backspace) {
|
|
332
|
+
newValue = newValue.slice(0, newValue.length - 1);
|
|
333
|
+
} else if (key.length === 1) {
|
|
334
|
+
newValue += key;
|
|
335
|
+
}
|
|
336
|
+
return newValue;
|
|
337
|
+
};
|
|
338
|
+
function useMirrorProp(prop, propOnChange, defaultVal) {
|
|
339
|
+
const [isMirroring] = useState(propOnChange !== void 0);
|
|
340
|
+
const [local, setLocal] = useState(defaultVal);
|
|
341
|
+
if (isMirroring) {
|
|
342
|
+
return [prop, propOnChange];
|
|
343
|
+
} else {
|
|
344
|
+
return [local, setLocal];
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const selectInputWrapper = "adyen-kyc-select-input-wrapper";
|
|
348
|
+
const selectInput = "adyen-kyc-select-input";
|
|
349
|
+
const selectInputActive = "adyen-kyc-select-input--active";
|
|
350
|
+
const selectInputReadonly = "adyen-kyc-select-input--readonly";
|
|
351
|
+
const selectInputInvalid = "adyen-kyc-select-input--invalid";
|
|
352
|
+
const selectInputMinimal = "adyen-kyc-select-input--minimal";
|
|
353
|
+
const selectInputSearch = "adyen-kyc-select-input-search";
|
|
354
|
+
const selectInputFilterable = "adyen-kyc-select-input--filterable";
|
|
355
|
+
const selectInputWrapperFilterable = "adyen-kyc-select-input-wrapper--filterable";
|
|
356
|
+
const selectInputWrapperNonFilterable = "adyen-kyc-select-input-wrapper--non-filterable";
|
|
357
|
+
const selectInputListOpen = "adyen-kyc-select-input--list-open";
|
|
358
|
+
const selectInputNonFilterable = "adyen-kyc-select-input--non-filterable";
|
|
359
|
+
const selectInputPlaceholder = "adyen-kyc-select-input--placeholder";
|
|
360
|
+
const ignorePointerEvents = "adyen-kyc-ignore-pointer-events";
|
|
361
|
+
const handlePointerEvents = "adyen-kyc-handle-pointer-events";
|
|
362
|
+
const styles = {
|
|
363
|
+
selectInputWrapper,
|
|
364
|
+
selectInput,
|
|
365
|
+
selectInputActive,
|
|
366
|
+
selectInputReadonly,
|
|
367
|
+
selectInputInvalid,
|
|
368
|
+
selectInputMinimal,
|
|
369
|
+
selectInputSearch,
|
|
370
|
+
selectInputFilterable,
|
|
371
|
+
selectInputWrapperFilterable,
|
|
372
|
+
selectInputWrapperNonFilterable,
|
|
373
|
+
selectInputListOpen,
|
|
374
|
+
selectInputNonFilterable,
|
|
375
|
+
selectInputPlaceholder,
|
|
376
|
+
ignorePointerEvents,
|
|
377
|
+
handlePointerEvents
|
|
378
|
+
};
|
|
379
|
+
const isAppleMobile = /iPhone|iPad/.test(navigator.platform);
|
|
380
|
+
function SelectButton({
|
|
381
|
+
id,
|
|
382
|
+
name,
|
|
383
|
+
active,
|
|
384
|
+
readonly,
|
|
385
|
+
showList,
|
|
386
|
+
isInvalid,
|
|
387
|
+
onClick,
|
|
388
|
+
onButtonKeyDown,
|
|
389
|
+
filterable,
|
|
390
|
+
isFiltering,
|
|
391
|
+
placeholder,
|
|
392
|
+
focusProps: { focused },
|
|
393
|
+
selectListId,
|
|
394
|
+
onInput,
|
|
395
|
+
behaviour,
|
|
396
|
+
loading,
|
|
397
|
+
text,
|
|
398
|
+
enableTracking = false,
|
|
399
|
+
onFocus,
|
|
400
|
+
inputRef,
|
|
401
|
+
minimal,
|
|
402
|
+
"aria-describedby": ariaDescribedBy,
|
|
403
|
+
"aria-labelledby": ariaLabelledBy,
|
|
404
|
+
"aria-label": ariaLabel
|
|
405
|
+
}) {
|
|
406
|
+
const userEvents = useAnalyticsContext();
|
|
407
|
+
const wrapperRef = useRef(null);
|
|
408
|
+
useSignalEffect(() => {
|
|
409
|
+
if (focused.value === "input") {
|
|
410
|
+
inputRef.current?.focus();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
const handleFocus = (e) => {
|
|
414
|
+
if (readonly) return;
|
|
415
|
+
if (enableTracking)
|
|
416
|
+
userEvents.addFieldEvent("Interacted with form field", {
|
|
417
|
+
actionType: "focus",
|
|
418
|
+
field: name
|
|
419
|
+
});
|
|
420
|
+
onFocus(e);
|
|
421
|
+
};
|
|
422
|
+
const handleClick = (e) => {
|
|
423
|
+
e.preventDefault();
|
|
424
|
+
e.stopPropagation();
|
|
425
|
+
if (readonly) return;
|
|
426
|
+
onClick();
|
|
427
|
+
};
|
|
428
|
+
const handleKeyDown = (e) => {
|
|
429
|
+
if (!readonly) onButtonKeyDown(e);
|
|
430
|
+
};
|
|
431
|
+
const handleInput = (e) => {
|
|
432
|
+
if (filterable && !readonly) onInput(e.target.value);
|
|
433
|
+
};
|
|
434
|
+
const truncatedDisplayValue = useMemo(() => {
|
|
435
|
+
if (active.length === 0) return void 0;
|
|
436
|
+
const activeText = active.map(({ selectedOptionName, name: name2 }) => selectedOptionName ?? name2).join(", ");
|
|
437
|
+
return activeText.length > 50 ? activeText.substring(0, 50) + "..." : activeText;
|
|
438
|
+
}, [active]);
|
|
439
|
+
const title = active?.length ? active.map(({ name: name2 }) => name2).join(",") : placeholder;
|
|
440
|
+
const isFocused = focused.value === "input";
|
|
441
|
+
const value = useMemo(() => {
|
|
442
|
+
if (behaviour === "textIsData" || focused.value !== void 0 && // can be focusing either the input or one of the options
|
|
443
|
+
filterable && isFiltering)
|
|
444
|
+
return text;
|
|
445
|
+
return truncatedDisplayValue;
|
|
446
|
+
}, [behaviour, text, focused.value, filterable, isFiltering, truncatedDisplayValue]);
|
|
447
|
+
return (
|
|
448
|
+
// In this case, the `<input>` within is fully accessible - this `onClick` is simply handling the situation
|
|
449
|
+
// where there is no `<label>` around the component. In that case, we should handle click events as if they
|
|
450
|
+
// occurred on the input.
|
|
451
|
+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
452
|
+
/* @__PURE__ */ jsxs(
|
|
453
|
+
"div",
|
|
454
|
+
{
|
|
455
|
+
className: cx({
|
|
456
|
+
[styles.selectInputWrapper]: true,
|
|
457
|
+
[styles.selectInputMinimal]: minimal,
|
|
458
|
+
[styles.selectInputReadonly]: readonly,
|
|
459
|
+
[styles.selectInputActive]: isFocused,
|
|
460
|
+
[styles.selectInputListOpen]: showList,
|
|
461
|
+
[styles.selectInputInvalid]: isInvalid,
|
|
462
|
+
[styles.selectInputSearch]: filterable === "prefiltered",
|
|
463
|
+
[styles.selectInputWrapperFilterable]: filterable,
|
|
464
|
+
[styles.selectInputWrapperNonFilterable]: !filterable,
|
|
465
|
+
// To resolve a bug where filterable select `<input>`s weren't focusable on iOS
|
|
466
|
+
[styles.ignorePointerEvents]: isAppleMobile
|
|
467
|
+
}),
|
|
468
|
+
ref: wrapperRef,
|
|
469
|
+
onClick: handleClick,
|
|
470
|
+
onFocusIn: handleFocus,
|
|
471
|
+
children: [
|
|
472
|
+
/* @__PURE__ */ jsx(
|
|
473
|
+
"input",
|
|
474
|
+
{
|
|
475
|
+
id,
|
|
476
|
+
name,
|
|
477
|
+
title,
|
|
478
|
+
ref: inputRef,
|
|
479
|
+
type: filterable ? "text" : "button",
|
|
480
|
+
role: "combobox",
|
|
481
|
+
"aria-haspopup": "listbox",
|
|
482
|
+
"aria-owns": selectListId,
|
|
483
|
+
"aria-controls": selectListId,
|
|
484
|
+
"aria-expanded": showList,
|
|
485
|
+
"aria-describedby": ariaDescribedBy,
|
|
486
|
+
"aria-disabled": readonly,
|
|
487
|
+
"aria-label": ariaLabel,
|
|
488
|
+
"aria-labelledby": ariaLabelledBy,
|
|
489
|
+
"aria-autocomplete": filterable ? "list" : void 0,
|
|
490
|
+
autoComplete: "off",
|
|
491
|
+
className: cx({
|
|
492
|
+
[styles.selectInput]: true,
|
|
493
|
+
[styles.selectInputFilterable]: filterable,
|
|
494
|
+
[styles.selectInputNonFilterable]: !filterable,
|
|
495
|
+
[styles.selectInputMinimal]: minimal,
|
|
496
|
+
[styles.selectInputReadonly]: readonly,
|
|
497
|
+
// To resolve a bug where filterable select `<input>`s weren't focusable on iOS
|
|
498
|
+
[styles.handlePointerEvents]: isAppleMobile
|
|
499
|
+
}),
|
|
500
|
+
placeholder,
|
|
501
|
+
value,
|
|
502
|
+
disabled: readonly,
|
|
503
|
+
onClick: handleClick,
|
|
504
|
+
onInput: handleInput,
|
|
505
|
+
onKeyDown: handleKeyDown
|
|
506
|
+
}
|
|
507
|
+
),
|
|
508
|
+
!filterable && !value ? /* @__PURE__ */ jsx("span", { className: styles.selectInputPlaceholder, children: placeholder }) : void 0,
|
|
509
|
+
loading && /* @__PURE__ */ jsx(Loader, { size: "small", dot: true })
|
|
510
|
+
]
|
|
511
|
+
}
|
|
512
|
+
)
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
const SelectListItem = ({
|
|
516
|
+
id,
|
|
517
|
+
item,
|
|
518
|
+
selected,
|
|
519
|
+
isMulti,
|
|
520
|
+
isSearch,
|
|
521
|
+
children,
|
|
522
|
+
onSelect,
|
|
523
|
+
onKeyDown,
|
|
524
|
+
onFocus,
|
|
525
|
+
className
|
|
526
|
+
}) => /* @__PURE__ */ jsx(
|
|
527
|
+
"li",
|
|
528
|
+
{
|
|
529
|
+
"aria-disabled": !!item.disabled,
|
|
530
|
+
"aria-selected": selected,
|
|
531
|
+
className: cx([
|
|
532
|
+
"adyen-kyc-dropdown-element",
|
|
533
|
+
{
|
|
534
|
+
"adyen-kyc-dropdown-element--active": selected,
|
|
535
|
+
"adyen-kyc-dropdown-element--disabled": !!item.disabled,
|
|
536
|
+
"adyen-kyc-dropdown-multi-element": isMulti,
|
|
537
|
+
"adyen-kyc-dropdown-element-description": !isMulti && !isSearch && item.description,
|
|
538
|
+
"adyen-kyc-dropdown-search-element": isSearch
|
|
539
|
+
},
|
|
540
|
+
className
|
|
541
|
+
]),
|
|
542
|
+
"data-disabled": !!item.disabled,
|
|
543
|
+
"data-value": item.id,
|
|
544
|
+
onFocus: (event) => {
|
|
545
|
+
if (item.disabled) return;
|
|
546
|
+
onFocus?.(event);
|
|
547
|
+
},
|
|
548
|
+
onClick: (e) => {
|
|
549
|
+
e.preventDefault();
|
|
550
|
+
if (item.disabled) return;
|
|
551
|
+
onSelect(!selected);
|
|
552
|
+
},
|
|
553
|
+
onKeyDown: (e) => {
|
|
554
|
+
if (item.disabled) return;
|
|
555
|
+
onKeyDown(e);
|
|
556
|
+
},
|
|
557
|
+
role: "option",
|
|
558
|
+
tabIndex: -1,
|
|
559
|
+
children: isMulti ? /* @__PURE__ */ jsx("span", { style: { pointerEvents: "none", width: "100%" }, children: /* @__PURE__ */ jsx(
|
|
560
|
+
Checkbox,
|
|
561
|
+
{
|
|
562
|
+
id,
|
|
563
|
+
onChange: noop,
|
|
564
|
+
label: item.name,
|
|
565
|
+
disabled: item.disabled,
|
|
566
|
+
helper: item.description,
|
|
567
|
+
checked: selected,
|
|
568
|
+
name: `adyen-kyc-dropdown-element__checkbox adyen-kyc-dropdown-element__checkbox--${item.id}`
|
|
569
|
+
}
|
|
570
|
+
) }) : children ? [children] : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
571
|
+
item.icon && /* @__PURE__ */ jsx("span", { className: "adyen-kyc-dropdown-element__icon", children: item.icon }),
|
|
572
|
+
item.description ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
573
|
+
/* @__PURE__ */ jsx(
|
|
574
|
+
Typography,
|
|
575
|
+
{
|
|
576
|
+
el: "span",
|
|
577
|
+
variant: "body-strongest",
|
|
578
|
+
className: "adyen-kyc-dropdown-element__label",
|
|
579
|
+
children: item.name
|
|
580
|
+
}
|
|
581
|
+
),
|
|
582
|
+
/* @__PURE__ */ jsx(
|
|
583
|
+
Typography,
|
|
584
|
+
{
|
|
585
|
+
el: "span",
|
|
586
|
+
color: "secondary",
|
|
587
|
+
className: "adyen-kyc-dropdown-element-description__text",
|
|
588
|
+
children: item.description
|
|
589
|
+
}
|
|
590
|
+
)
|
|
591
|
+
] }) : /* @__PURE__ */ jsx("span", { className: "adyen-kyc-dropdown-element__label", children: item.name })
|
|
592
|
+
] })
|
|
593
|
+
}
|
|
594
|
+
);
|
|
595
|
+
const logger$1 = createLogger();
|
|
596
|
+
const DEFAULT_ITEM_HEIGHT = 36;
|
|
597
|
+
function SelectList({
|
|
598
|
+
selectListId,
|
|
599
|
+
active,
|
|
600
|
+
filteredItems,
|
|
601
|
+
showList,
|
|
602
|
+
isMulti,
|
|
603
|
+
inputRef,
|
|
604
|
+
isSearch,
|
|
605
|
+
loading,
|
|
606
|
+
getSearchItem,
|
|
607
|
+
onKeyDown,
|
|
608
|
+
onSelect,
|
|
609
|
+
minimal,
|
|
610
|
+
maxVisibleItems = 5,
|
|
611
|
+
focusProps: {
|
|
612
|
+
focused,
|
|
613
|
+
focusItem,
|
|
614
|
+
focusDefaultItem,
|
|
615
|
+
moveFocusToNextItem,
|
|
616
|
+
moveFocusToPreviousItem,
|
|
617
|
+
moveFocusToFirstItem,
|
|
618
|
+
moveFocusToLastItem
|
|
619
|
+
}
|
|
620
|
+
}) {
|
|
621
|
+
const { t } = useTranslation("ui");
|
|
622
|
+
const [startIndex, setStartIndex] = useState(0);
|
|
623
|
+
const [endIndex, setEndIndex] = useState(maxVisibleItems);
|
|
624
|
+
const listRef = useRef(null);
|
|
625
|
+
const calculatedItemHeight = (() => {
|
|
626
|
+
if (listRef.current && showList) {
|
|
627
|
+
const height2 = listRef.current.firstElementChild?.firstElementChild?.clientHeight;
|
|
628
|
+
if (height2 !== void 0) return height2;
|
|
629
|
+
}
|
|
630
|
+
})();
|
|
631
|
+
const itemHeight = calculatedItemHeight || DEFAULT_ITEM_HEIGHT;
|
|
632
|
+
const totalItems = filteredItems.length;
|
|
633
|
+
const visibleItems = useMemo(
|
|
634
|
+
() => filteredItems.slice(startIndex, endIndex),
|
|
635
|
+
[endIndex, filteredItems, startIndex]
|
|
636
|
+
);
|
|
637
|
+
const findElementForItem = useCallback(
|
|
638
|
+
(item) => {
|
|
639
|
+
const listContainer = listRef.current;
|
|
640
|
+
if (!listContainer) return;
|
|
641
|
+
return listContainer.querySelector(
|
|
642
|
+
`[role="option"][data-value="${item.id}"]`
|
|
643
|
+
);
|
|
644
|
+
},
|
|
645
|
+
[listRef]
|
|
646
|
+
);
|
|
647
|
+
const recalculateScrollIndexes = useCallback(() => {
|
|
648
|
+
if (!listRef.current) return;
|
|
649
|
+
const { scrollTop } = listRef.current;
|
|
650
|
+
const maxStartIndex = totalItems < maxVisibleItems ? totalItems : totalItems - maxVisibleItems;
|
|
651
|
+
const newStartIndex = Math.min(Math.max(0, Math.floor(scrollTop / itemHeight)), maxStartIndex);
|
|
652
|
+
const newEndIndex = Math.min(newStartIndex + maxVisibleItems, totalItems);
|
|
653
|
+
setStartIndex(newStartIndex);
|
|
654
|
+
setEndIndex(newEndIndex);
|
|
655
|
+
}, [totalItems, maxVisibleItems, itemHeight, listRef]);
|
|
656
|
+
useEffect(() => {
|
|
657
|
+
recalculateScrollIndexes();
|
|
658
|
+
}, [recalculateScrollIndexes]);
|
|
659
|
+
const scrollItemIntoView = useCallback(
|
|
660
|
+
(item) => {
|
|
661
|
+
if (!listRef.current) return;
|
|
662
|
+
const itemIndex = filteredItems.indexOf(item);
|
|
663
|
+
if (itemIndex === -1) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
const maxScrollTop = totalItems * itemHeight;
|
|
667
|
+
listRef.current.scrollTop = Math.min(itemHeight * (itemIndex + 0.5), maxScrollTop);
|
|
668
|
+
},
|
|
669
|
+
[filteredItems, itemHeight, totalItems, listRef]
|
|
670
|
+
);
|
|
671
|
+
const acquireFocusForItem = useCallback(
|
|
672
|
+
(item) => {
|
|
673
|
+
let itemEl = findElementForItem(item);
|
|
674
|
+
if (!itemEl) {
|
|
675
|
+
scrollItemIntoView(item);
|
|
676
|
+
}
|
|
677
|
+
setTimeout(() => {
|
|
678
|
+
itemEl = itemEl ?? findElementForItem(item);
|
|
679
|
+
if (itemEl) {
|
|
680
|
+
itemEl.focus();
|
|
681
|
+
} else {
|
|
682
|
+
logger$1.warn("[SelectList] still cannot see the option", item.name);
|
|
683
|
+
}
|
|
684
|
+
}, 20);
|
|
685
|
+
},
|
|
686
|
+
[findElementForItem, scrollItemIntoView]
|
|
687
|
+
);
|
|
688
|
+
useSignalEffect(() => {
|
|
689
|
+
const currFocused = focused.value;
|
|
690
|
+
if (focusedIsItem(currFocused)) {
|
|
691
|
+
acquireFocusForItem(currFocused);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
const listListeners = {
|
|
695
|
+
[KEYBOARD_KEYS.arrowUp]: moveFocusToPreviousItem,
|
|
696
|
+
[KEYBOARD_KEYS.arrowDown]: moveFocusToNextItem,
|
|
697
|
+
[KEYBOARD_KEYS.home]: moveFocusToFirstItem,
|
|
698
|
+
[KEYBOARD_KEYS.end]: moveFocusToLastItem
|
|
699
|
+
};
|
|
700
|
+
const onListKeydown = (event) => {
|
|
701
|
+
const listener = listListeners[event.key];
|
|
702
|
+
if (listener) {
|
|
703
|
+
event.preventDefault();
|
|
704
|
+
listener();
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
const getItems = () => {
|
|
708
|
+
if (loading) {
|
|
709
|
+
return /* @__PURE__ */ jsx("div", { className: "adyen-kyc-dropdown-element adyen-kyc-dropdown-element--no-options", children: t(($) => $["loading"]) });
|
|
710
|
+
}
|
|
711
|
+
if (!filteredItems.length) {
|
|
712
|
+
if (startIndex !== 0 || endIndex !== maxVisibleItems) {
|
|
713
|
+
setStartIndex(0);
|
|
714
|
+
setEndIndex(maxVisibleItems);
|
|
715
|
+
}
|
|
716
|
+
return /* @__PURE__ */ jsx("div", { className: "adyen-kyc-dropdown-element adyen-kyc-dropdown-element--no-options", children: t(($) => $["noOptionsFound"]) });
|
|
717
|
+
}
|
|
718
|
+
if (visibleItems.length) {
|
|
719
|
+
return visibleItems.map((item) => /* @__PURE__ */ jsx(
|
|
720
|
+
SelectListItem,
|
|
721
|
+
{
|
|
722
|
+
item,
|
|
723
|
+
id: item.id,
|
|
724
|
+
onKeyDown: (event) => onKeyDown(event, item),
|
|
725
|
+
onFocus: (event) => {
|
|
726
|
+
focusItem(item);
|
|
727
|
+
event.stopPropagation();
|
|
728
|
+
},
|
|
729
|
+
onSelect: () => onSelect(item),
|
|
730
|
+
selected: !!active.find((activeItem) => activeItem.id === item.id),
|
|
731
|
+
isMulti,
|
|
732
|
+
isSearch,
|
|
733
|
+
children: getSearchItem && getSearchItem(item)
|
|
734
|
+
},
|
|
735
|
+
item.id
|
|
736
|
+
));
|
|
737
|
+
}
|
|
738
|
+
return null;
|
|
739
|
+
};
|
|
740
|
+
const height = useMemo(() => {
|
|
741
|
+
if (loading) return "auto";
|
|
742
|
+
return totalItems > maxVisibleItems && itemHeight ? `${itemHeight * maxVisibleItems}px` : "auto";
|
|
743
|
+
}, [itemHeight, totalItems, loading, maxVisibleItems]);
|
|
744
|
+
const allItemsVisible = totalItems <= maxVisibleItems;
|
|
745
|
+
const [showAbove, setShowAbove] = useState(false);
|
|
746
|
+
useEffect(() => {
|
|
747
|
+
const list = listRef.current;
|
|
748
|
+
const input = inputRef.current;
|
|
749
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
750
|
+
const dropdownHeight = list.offsetHeight;
|
|
751
|
+
const windowHeight = window.innerHeight;
|
|
752
|
+
const position = input.getBoundingClientRect().bottom;
|
|
753
|
+
const isSpaceBelow = windowHeight - position > dropdownHeight;
|
|
754
|
+
const isSpaceAbove = position > dropdownHeight;
|
|
755
|
+
setShowAbove(!isSpaceBelow && isSpaceAbove);
|
|
756
|
+
});
|
|
757
|
+
resizeObserver.observe(list);
|
|
758
|
+
return () => resizeObserver.disconnect();
|
|
759
|
+
}, [inputRef, listRef]);
|
|
760
|
+
return /* @__PURE__ */ jsx(
|
|
761
|
+
"div",
|
|
762
|
+
{
|
|
763
|
+
className: cx({
|
|
764
|
+
"adyen-kyc-dropdown-list": true,
|
|
765
|
+
"adyen-kyc-dropdown-list--minimal": minimal,
|
|
766
|
+
"adyen-kyc-dropdown-list--active": showList,
|
|
767
|
+
"adyen-kyc-dropdown-list--above": showAbove
|
|
768
|
+
}),
|
|
769
|
+
id: selectListId,
|
|
770
|
+
role: "listbox",
|
|
771
|
+
onScroll: recalculateScrollIndexes,
|
|
772
|
+
style: {
|
|
773
|
+
overflowY: allItemsVisible ? "hidden" : "auto",
|
|
774
|
+
position: "absolute",
|
|
775
|
+
height
|
|
776
|
+
},
|
|
777
|
+
onKeyDown: onListKeydown,
|
|
778
|
+
onFocus: focusDefaultItem,
|
|
779
|
+
tabIndex: -1,
|
|
780
|
+
ref: listRef,
|
|
781
|
+
children: /* @__PURE__ */ jsxs(
|
|
782
|
+
"ul",
|
|
783
|
+
{
|
|
784
|
+
className: "adyen-kyc-dropdown-list__transformer",
|
|
785
|
+
style: {
|
|
786
|
+
transform: `translateY(${startIndex * itemHeight}px)`
|
|
787
|
+
},
|
|
788
|
+
children: [
|
|
789
|
+
getItems(),
|
|
790
|
+
/* @__PURE__ */ jsx(
|
|
791
|
+
"div",
|
|
792
|
+
{
|
|
793
|
+
style: {
|
|
794
|
+
// fake the height of the remaining items in the list so scroll position is correct
|
|
795
|
+
height: `${(totalItems - endIndex) * itemHeight}px`
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
)
|
|
799
|
+
]
|
|
800
|
+
}
|
|
801
|
+
)
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
const Select = ({
|
|
806
|
+
id,
|
|
807
|
+
items,
|
|
808
|
+
filterable = true,
|
|
809
|
+
readonly = false,
|
|
810
|
+
onChange,
|
|
811
|
+
onSelect,
|
|
812
|
+
selected,
|
|
813
|
+
name,
|
|
814
|
+
isInvalid = false,
|
|
815
|
+
placeholder = "",
|
|
816
|
+
isMulti,
|
|
817
|
+
enableTracking = false,
|
|
818
|
+
maxVisibleItems,
|
|
819
|
+
getSearchItem,
|
|
820
|
+
onBlur = noop,
|
|
821
|
+
text: filterTextProp,
|
|
822
|
+
setText: setFilterTextProp,
|
|
823
|
+
showList: showListProp,
|
|
824
|
+
setShowList: setShowListProp,
|
|
825
|
+
behaviour = "textIsFilter",
|
|
826
|
+
loading = false,
|
|
827
|
+
minimal = false,
|
|
828
|
+
"aria-describedby": ariaDescribedBy,
|
|
829
|
+
"aria-label": ariaLabel,
|
|
830
|
+
"aria-labelledby": ariaLabelledBy,
|
|
831
|
+
excludedValues
|
|
832
|
+
}) => {
|
|
833
|
+
const userEvents = useAnalyticsContext();
|
|
834
|
+
const selectContainerRef = useRef(null);
|
|
835
|
+
const inputRef = useRef(null);
|
|
836
|
+
const selectListId = useId("select");
|
|
837
|
+
const [textFilter, setTextFilter] = useMirrorProp(filterTextProp, setFilterTextProp, "");
|
|
838
|
+
const [isShowList, setIsShowList] = useMirrorProp(showListProp, setShowListProp, false);
|
|
839
|
+
const [isFiltering, setIsFiltering] = useState(false);
|
|
840
|
+
const active = useMemo(() => {
|
|
841
|
+
if (selected === void 0) return [];
|
|
842
|
+
return (Array.isArray(selected) ? selected : [selected]).map((s) => {
|
|
843
|
+
if (typeof s === "object") return s;
|
|
844
|
+
return items.find((i) => i.id === s);
|
|
845
|
+
}).filter(Boolean);
|
|
846
|
+
}, [items, selected]);
|
|
847
|
+
const filtered = useMemo(() => {
|
|
848
|
+
const availableItems = items.filter((item) => !excludedValues?.includes(item));
|
|
849
|
+
return availableItems.filter((item) => {
|
|
850
|
+
if (filterable === "prefiltered" || !isFiltering) return true;
|
|
851
|
+
return item.name.toLowerCase().includes(textFilter.toLowerCase());
|
|
852
|
+
});
|
|
853
|
+
}, [filterable, isFiltering, items, textFilter, excludedValues]);
|
|
854
|
+
const activeSignal = useWatchingSignal(active);
|
|
855
|
+
const filteredSignal = useWatchingSignal(filtered);
|
|
856
|
+
const focusProps = useSelectFocus({
|
|
857
|
+
activeItems: activeSignal,
|
|
858
|
+
filteredItems: filteredSignal
|
|
859
|
+
});
|
|
860
|
+
const {
|
|
861
|
+
focusInput,
|
|
862
|
+
focusItem,
|
|
863
|
+
focusDefaultItem,
|
|
864
|
+
focusNothing,
|
|
865
|
+
moveFocusToNextItem,
|
|
866
|
+
moveFocusToPreviousItem
|
|
867
|
+
} = focusProps;
|
|
868
|
+
const closeList = useCallback(
|
|
869
|
+
(shiftFocusTo) => {
|
|
870
|
+
if (behaviour === "textIsFilter") setTextFilter("");
|
|
871
|
+
setIsShowList(false);
|
|
872
|
+
switch (shiftFocusTo) {
|
|
873
|
+
case "input":
|
|
874
|
+
focusInput();
|
|
875
|
+
break;
|
|
876
|
+
case "nothing":
|
|
877
|
+
focusNothing();
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
[behaviour, focusInput, focusNothing, setIsShowList, setTextFilter]
|
|
882
|
+
);
|
|
883
|
+
const showList = useCallback(() => {
|
|
884
|
+
if (!isShowList) setIsShowList(true);
|
|
885
|
+
}, [isShowList, setIsShowList]);
|
|
886
|
+
const handleSelect = useCallback(
|
|
887
|
+
(selectedItem) => {
|
|
888
|
+
setIsFiltering(false);
|
|
889
|
+
if (readonly) return;
|
|
890
|
+
if (isMulti) {
|
|
891
|
+
const isAlreadySelected = active.find((item) => item.id === selectedItem.id);
|
|
892
|
+
const newActiveItems = isAlreadySelected ? active.filter((i) => i.id !== selectedItem.id) : [...active, selectedItem];
|
|
893
|
+
onSelect?.(newActiveItems);
|
|
894
|
+
onChange?.({ target: { value: newActiveItems.map((i) => i.id), name: name ?? "" } });
|
|
895
|
+
focusItem(selectedItem);
|
|
896
|
+
} else {
|
|
897
|
+
const handleOnSelect = onSelect;
|
|
898
|
+
const handleOnChange = onChange;
|
|
899
|
+
handleOnSelect?.(selectedItem);
|
|
900
|
+
handleOnChange?.({ target: { value: selectedItem.id, name: name ?? "" } });
|
|
901
|
+
closeList("input");
|
|
902
|
+
}
|
|
903
|
+
if (enableTracking) {
|
|
904
|
+
userEvents.addFieldEvent("Interacted with form field", {
|
|
905
|
+
actionType: "select",
|
|
906
|
+
field: name,
|
|
907
|
+
returnValue: selectedItem.id
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
},
|
|
911
|
+
[
|
|
912
|
+
readonly,
|
|
913
|
+
isMulti,
|
|
914
|
+
enableTracking,
|
|
915
|
+
active,
|
|
916
|
+
onSelect,
|
|
917
|
+
onChange,
|
|
918
|
+
name,
|
|
919
|
+
focusItem,
|
|
920
|
+
closeList,
|
|
921
|
+
userEvents
|
|
922
|
+
]
|
|
923
|
+
);
|
|
924
|
+
const handleBlur = (e) => {
|
|
925
|
+
onBlur(e);
|
|
926
|
+
};
|
|
927
|
+
const handleInputKeyDown = async (e) => {
|
|
928
|
+
if (e.key === KEYBOARD_KEYS.enter && isShowList) {
|
|
929
|
+
if (filtered.length === 1) {
|
|
930
|
+
handleSelect(filtered[0]);
|
|
931
|
+
} else {
|
|
932
|
+
e.preventDefault();
|
|
933
|
+
}
|
|
934
|
+
} else if (e.key === KEYBOARD_KEYS.escape) {
|
|
935
|
+
closeList("nothing");
|
|
936
|
+
} else if (e.key === KEYBOARD_KEYS.enter || e.key === KEYBOARD_KEYS.space && (!filterable || !isShowList)) {
|
|
937
|
+
e.preventDefault();
|
|
938
|
+
e.stopPropagation();
|
|
939
|
+
showList();
|
|
940
|
+
focusDefaultItem();
|
|
941
|
+
} else if (e.key === KEYBOARD_KEYS.arrowUp || e.key === KEYBOARD_KEYS.arrowDown) {
|
|
942
|
+
e.preventDefault();
|
|
943
|
+
e.stopPropagation();
|
|
944
|
+
showList();
|
|
945
|
+
focusDefaultItem();
|
|
946
|
+
switch (e.key) {
|
|
947
|
+
case KEYBOARD_KEYS.arrowUp:
|
|
948
|
+
moveFocusToPreviousItem();
|
|
949
|
+
break;
|
|
950
|
+
case KEYBOARD_KEYS.arrowDown:
|
|
951
|
+
moveFocusToNextItem();
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
} else if (e.key === KEYBOARD_KEYS.tab) {
|
|
955
|
+
closeList("nothing");
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
const handleClickOutside = (e) => {
|
|
959
|
+
if (!selectContainerRef.current?.contains(e.target)) {
|
|
960
|
+
closeList("nothing");
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
const handleListItemKeyDown = (e, item) => {
|
|
964
|
+
switch (e.key) {
|
|
965
|
+
case KEYBOARD_KEYS.escape:
|
|
966
|
+
e.preventDefault();
|
|
967
|
+
closeList("input");
|
|
968
|
+
break;
|
|
969
|
+
case KEYBOARD_KEYS.space:
|
|
970
|
+
case KEYBOARD_KEYS.enter:
|
|
971
|
+
handleSelect(item);
|
|
972
|
+
break;
|
|
973
|
+
case KEYBOARD_KEYS.tab:
|
|
974
|
+
closeList("nothing");
|
|
975
|
+
break;
|
|
976
|
+
case KEYBOARD_KEYS.arrowUp:
|
|
977
|
+
case KEYBOARD_KEYS.arrowDown:
|
|
978
|
+
case KEYBOARD_KEYS.home:
|
|
979
|
+
case KEYBOARD_KEYS.end:
|
|
980
|
+
break;
|
|
981
|
+
default: {
|
|
982
|
+
e.preventDefault();
|
|
983
|
+
e.stopPropagation();
|
|
984
|
+
handleTextFilter(simulateTextChangeFromKeyboardEvent(e, textFilter));
|
|
985
|
+
focusInput();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
const handleTextFilter = useCallback(
|
|
990
|
+
(value) => {
|
|
991
|
+
showList();
|
|
992
|
+
setIsFiltering(true);
|
|
993
|
+
setTextFilter(value);
|
|
994
|
+
if (enableTracking) {
|
|
995
|
+
debouncedInputEvent({ actionType: "input", field: name });
|
|
996
|
+
}
|
|
997
|
+
},
|
|
998
|
+
[enableTracking, name, setTextFilter, showList]
|
|
999
|
+
);
|
|
1000
|
+
useEffect(() => {
|
|
1001
|
+
document.addEventListener("click", handleClickOutside, true);
|
|
1002
|
+
return () => {
|
|
1003
|
+
document.removeEventListener("click", handleClickOutside, true);
|
|
1004
|
+
};
|
|
1005
|
+
}, []);
|
|
1006
|
+
return /* @__PURE__ */ jsxs(
|
|
1007
|
+
"div",
|
|
1008
|
+
{
|
|
1009
|
+
className: cx({ "adyen-kyc-dropdown": true, "adyen-kyc-dropdown--minimal": minimal }),
|
|
1010
|
+
ref: selectContainerRef,
|
|
1011
|
+
onFocusOut: handleBlur,
|
|
1012
|
+
children: [
|
|
1013
|
+
/* @__PURE__ */ jsx(
|
|
1014
|
+
SelectButton,
|
|
1015
|
+
{
|
|
1016
|
+
id,
|
|
1017
|
+
name,
|
|
1018
|
+
active,
|
|
1019
|
+
filterable,
|
|
1020
|
+
isFiltering,
|
|
1021
|
+
isInvalid,
|
|
1022
|
+
onButtonKeyDown: handleInputKeyDown,
|
|
1023
|
+
onInput: handleTextFilter,
|
|
1024
|
+
placeholder,
|
|
1025
|
+
readonly,
|
|
1026
|
+
selectListId,
|
|
1027
|
+
showList: isShowList,
|
|
1028
|
+
focusProps,
|
|
1029
|
+
"aria-describedby": ariaDescribedBy || "",
|
|
1030
|
+
"aria-label": ariaLabel || "",
|
|
1031
|
+
"aria-labelledby": ariaLabelledBy || "",
|
|
1032
|
+
isMulti: Boolean(isMulti),
|
|
1033
|
+
loading,
|
|
1034
|
+
behaviour,
|
|
1035
|
+
text: textFilter,
|
|
1036
|
+
inputRef,
|
|
1037
|
+
enableTracking,
|
|
1038
|
+
minimal,
|
|
1039
|
+
onClick: () => {
|
|
1040
|
+
if (isShowList) {
|
|
1041
|
+
closeList("input");
|
|
1042
|
+
} else {
|
|
1043
|
+
showList();
|
|
1044
|
+
focusInput();
|
|
1045
|
+
}
|
|
1046
|
+
},
|
|
1047
|
+
onFocus: () => focusInput()
|
|
1048
|
+
}
|
|
1049
|
+
),
|
|
1050
|
+
/* @__PURE__ */ jsx(
|
|
1051
|
+
SelectList,
|
|
1052
|
+
{
|
|
1053
|
+
active,
|
|
1054
|
+
filteredItems: filtered,
|
|
1055
|
+
onKeyDown: handleListItemKeyDown,
|
|
1056
|
+
onSelect: handleSelect,
|
|
1057
|
+
selectListId,
|
|
1058
|
+
showList: isShowList,
|
|
1059
|
+
textFilter,
|
|
1060
|
+
isMulti: Boolean(isMulti),
|
|
1061
|
+
isSearch: filterable === "prefiltered",
|
|
1062
|
+
getSearchItem,
|
|
1063
|
+
loading,
|
|
1064
|
+
maxVisibleItems,
|
|
1065
|
+
focusProps,
|
|
1066
|
+
inputRef,
|
|
1067
|
+
minimal
|
|
1068
|
+
}
|
|
1069
|
+
)
|
|
1070
|
+
]
|
|
1071
|
+
}
|
|
1072
|
+
);
|
|
1073
|
+
};
|
|
1074
|
+
class ValidationResult {
|
|
1075
|
+
validationResults;
|
|
1076
|
+
constructor(results) {
|
|
1077
|
+
this.validationResults = results;
|
|
1078
|
+
}
|
|
1079
|
+
/** Checks if all validation rules have passed */
|
|
1080
|
+
get isValid() {
|
|
1081
|
+
return this.validationResults.reduce((acc, result) => acc && result.isValid, true);
|
|
1082
|
+
}
|
|
1083
|
+
/** Checks if any validation rule returned an error */
|
|
1084
|
+
hasError() {
|
|
1085
|
+
return Boolean(this.getError());
|
|
1086
|
+
}
|
|
1087
|
+
/** Returns the first validation result that returned an error */
|
|
1088
|
+
getError() {
|
|
1089
|
+
return this.validationResults.find((result) => result.hasError);
|
|
1090
|
+
}
|
|
1091
|
+
/** Used to add async validation results to the static validation result*/
|
|
1092
|
+
addError(result) {
|
|
1093
|
+
this.validationResults.push(result);
|
|
1094
|
+
return this.validationResults;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
const logger = createLogger();
|
|
1098
|
+
const useAsyncValidator = (asyncRules) => {
|
|
1099
|
+
const [asyncValidationResults, setAsyncValidationResults] = useState({});
|
|
1100
|
+
const clearAsyncValidationResults = useCallback(
|
|
1101
|
+
(field) => setAsyncValidationResults((existingResults) => ({
|
|
1102
|
+
...existingResults,
|
|
1103
|
+
[field]: void 0
|
|
1104
|
+
})),
|
|
1105
|
+
[]
|
|
1106
|
+
);
|
|
1107
|
+
const triggerAsyncValidation = useCallback(
|
|
1108
|
+
(field, formState, mode) => {
|
|
1109
|
+
const rule = asyncRules?.[field];
|
|
1110
|
+
if (!rule || !rule.modes.includes(mode)) {
|
|
1111
|
+
clearAsyncValidationResults(field);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
const value = formState.data[field];
|
|
1115
|
+
return rule.asyncValidate(formState.data[field], { state: formState }).then((isValid) => {
|
|
1116
|
+
setAsyncValidationResults((existingResults) => ({
|
|
1117
|
+
...existingResults,
|
|
1118
|
+
[field]: new ValidationResult([
|
|
1119
|
+
{
|
|
1120
|
+
isValid,
|
|
1121
|
+
errorMessage: typeof rule.errorMessage === "function" ? rule.errorMessage(value, { state: formState }) : rule.errorMessage,
|
|
1122
|
+
hasError: !isValid
|
|
1123
|
+
}
|
|
1124
|
+
])
|
|
1125
|
+
}));
|
|
1126
|
+
}).catch(logger.error);
|
|
1127
|
+
},
|
|
1128
|
+
[asyncRules, clearAsyncValidationResults]
|
|
1129
|
+
);
|
|
1130
|
+
return {
|
|
1131
|
+
asyncValidationResults,
|
|
1132
|
+
triggerAsyncValidation,
|
|
1133
|
+
clearAsyncValidationResults
|
|
1134
|
+
};
|
|
1135
|
+
};
|
|
1136
|
+
const useStaticValidator = (rules) => {
|
|
1137
|
+
const getRulesForField = useCallback(
|
|
1138
|
+
(field) => {
|
|
1139
|
+
const fallbackRule = {
|
|
1140
|
+
validate: () => true,
|
|
1141
|
+
modes: ["blur", "input"]
|
|
1142
|
+
};
|
|
1143
|
+
const fieldRules = rules?.[field] ?? [fallbackRule];
|
|
1144
|
+
return Array.isArray(fieldRules) ? fieldRules : [fieldRules];
|
|
1145
|
+
},
|
|
1146
|
+
[rules]
|
|
1147
|
+
);
|
|
1148
|
+
const triggerStaticValidation = useCallback(
|
|
1149
|
+
({ key, value, mode = "blur" }, context) => {
|
|
1150
|
+
const fieldRules = getRulesForField(key);
|
|
1151
|
+
const isFieldOptional = !!context?.state.optionalFields?.includes(key);
|
|
1152
|
+
const isFieldObscured = !!context?.state.obscuredFields?.includes(key);
|
|
1153
|
+
const validationRulesResult = fieldRules.map((rule) => {
|
|
1154
|
+
const shouldValidate = rule.modes.includes(mode) && !isFieldObscured;
|
|
1155
|
+
const isValid = isFieldOptional && isEmpty(value) ? true : rule.validate(value, context);
|
|
1156
|
+
return {
|
|
1157
|
+
isValid,
|
|
1158
|
+
errorMessage: typeof rule.errorMessage === "function" ? rule.errorMessage(value, context) : rule.errorMessage,
|
|
1159
|
+
hasError: shouldValidate && !isValid
|
|
1160
|
+
};
|
|
1161
|
+
});
|
|
1162
|
+
return new ValidationResult(validationRulesResult);
|
|
1163
|
+
},
|
|
1164
|
+
[getRulesForField]
|
|
1165
|
+
);
|
|
1166
|
+
return {
|
|
1167
|
+
triggerStaticValidation
|
|
1168
|
+
};
|
|
1169
|
+
};
|
|
1170
|
+
const omitKeys = (obj, omit) => Object.keys(obj).filter((k) => !omit.includes(k)).reduce((a, c) => {
|
|
1171
|
+
a[c] = obj[c];
|
|
1172
|
+
return a;
|
|
1173
|
+
}, {});
|
|
1174
|
+
const addKeys = (obj, add, initialValue, defaultData, pendingData) => add.reduce(
|
|
1175
|
+
(a, c) => ({
|
|
1176
|
+
...a,
|
|
1177
|
+
[c]: a[c] ?? pendingData?.[c] ?? defaultData?.[c] ?? initialValue
|
|
1178
|
+
}),
|
|
1179
|
+
obj
|
|
1180
|
+
);
|
|
1181
|
+
function getDataByFields(formData, fieldKeys) {
|
|
1182
|
+
return entriesOf(formData).reduce((acc, [key, val]) => {
|
|
1183
|
+
if (fieldKeys.includes(key)) {
|
|
1184
|
+
return { ...acc, [key]: val };
|
|
1185
|
+
}
|
|
1186
|
+
return acc;
|
|
1187
|
+
}, {});
|
|
1188
|
+
}
|
|
1189
|
+
const processField = ({
|
|
1190
|
+
key,
|
|
1191
|
+
value = null,
|
|
1192
|
+
mode,
|
|
1193
|
+
defaultData,
|
|
1194
|
+
fieldContext,
|
|
1195
|
+
formatters,
|
|
1196
|
+
staticValidate,
|
|
1197
|
+
asyncValidate
|
|
1198
|
+
}) => {
|
|
1199
|
+
const formatterFn = formatters?.[key]?.formatter ? formatters[key]?.formatter : formatters?.[key];
|
|
1200
|
+
const formattedValue = formatterFn && typeof formatterFn === "function" ? formatterFn(value, fieldContext) : value;
|
|
1201
|
+
const shouldValidateField = !(defaultData?.[key] === value && !!defaultData?.[key]);
|
|
1202
|
+
if (shouldValidateField && value) {
|
|
1203
|
+
asyncValidate(key, fieldContext.state, mode);
|
|
1204
|
+
}
|
|
1205
|
+
const validationResult = shouldValidateField ? staticValidate({ key, value: formattedValue, mode }, fieldContext) : new ValidationResult([
|
|
1206
|
+
{
|
|
1207
|
+
isValid: true,
|
|
1208
|
+
hasError: false
|
|
1209
|
+
}
|
|
1210
|
+
]);
|
|
1211
|
+
return [formattedValue, validationResult];
|
|
1212
|
+
};
|
|
1213
|
+
function init({
|
|
1214
|
+
schema,
|
|
1215
|
+
defaultData,
|
|
1216
|
+
fieldProblems,
|
|
1217
|
+
obscuredFields,
|
|
1218
|
+
optionalFields,
|
|
1219
|
+
trustedFields,
|
|
1220
|
+
formatters,
|
|
1221
|
+
staticValidate,
|
|
1222
|
+
asyncValidate
|
|
1223
|
+
}) {
|
|
1224
|
+
const getProcessedState = (fieldKey) => {
|
|
1225
|
+
const [formattedValue, validationResult] = processField({
|
|
1226
|
+
key: fieldKey,
|
|
1227
|
+
value: defaultData?.[fieldKey],
|
|
1228
|
+
mode: "blur",
|
|
1229
|
+
formatters,
|
|
1230
|
+
defaultData,
|
|
1231
|
+
fieldContext: {
|
|
1232
|
+
state: {
|
|
1233
|
+
data: defaultData,
|
|
1234
|
+
obscuredFields,
|
|
1235
|
+
optionalFields,
|
|
1236
|
+
trustedFields
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
staticValidate,
|
|
1240
|
+
asyncValidate
|
|
1241
|
+
});
|
|
1242
|
+
if (typeof defaultData?.[fieldKey] === "undefined") {
|
|
1243
|
+
return {
|
|
1244
|
+
valid: validationResult.isValid && !fieldProblems?.[fieldKey] || false,
|
|
1245
|
+
errors: null,
|
|
1246
|
+
data: null,
|
|
1247
|
+
fieldProblems: fieldProblems?.[fieldKey] ?? false
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
return {
|
|
1251
|
+
valid: validationResult.isValid && !fieldProblems?.[fieldKey] || false,
|
|
1252
|
+
errors: validationResult.getError() ?? null,
|
|
1253
|
+
data: formattedValue,
|
|
1254
|
+
fieldProblems: fieldProblems?.[fieldKey] ?? false
|
|
1255
|
+
};
|
|
1256
|
+
};
|
|
1257
|
+
const formFields = optionalFields ? [...schema, ...optionalFields] : schema;
|
|
1258
|
+
const formData = formFields.reduce(
|
|
1259
|
+
(acc, field) => {
|
|
1260
|
+
const {
|
|
1261
|
+
valid,
|
|
1262
|
+
errors,
|
|
1263
|
+
data,
|
|
1264
|
+
fieldProblems: processedFieldProblems
|
|
1265
|
+
} = getProcessedState(field);
|
|
1266
|
+
return {
|
|
1267
|
+
...acc,
|
|
1268
|
+
data: { ...acc.data, [field]: data },
|
|
1269
|
+
valid: { ...acc.valid, [field]: valid },
|
|
1270
|
+
errors: { ...acc.errors, [field]: errors },
|
|
1271
|
+
fieldProblems: { ...acc.fieldProblems, [field]: processedFieldProblems }
|
|
1272
|
+
};
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
schema,
|
|
1276
|
+
data: {},
|
|
1277
|
+
valid: {},
|
|
1278
|
+
errors: {},
|
|
1279
|
+
fieldProblems: {},
|
|
1280
|
+
obscuredFields,
|
|
1281
|
+
optionalFields,
|
|
1282
|
+
trustedFields
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1285
|
+
return formData;
|
|
1286
|
+
}
|
|
1287
|
+
function reducer({
|
|
1288
|
+
staticValidate,
|
|
1289
|
+
asyncValidate,
|
|
1290
|
+
obscuredFields,
|
|
1291
|
+
optionalFields,
|
|
1292
|
+
trustedFields,
|
|
1293
|
+
formatters
|
|
1294
|
+
}) {
|
|
1295
|
+
return (state, {
|
|
1296
|
+
type,
|
|
1297
|
+
key,
|
|
1298
|
+
mode,
|
|
1299
|
+
value,
|
|
1300
|
+
schema,
|
|
1301
|
+
selectedSchema,
|
|
1302
|
+
formValue,
|
|
1303
|
+
fieldProblems,
|
|
1304
|
+
defaultData
|
|
1305
|
+
}) => {
|
|
1306
|
+
const validationSchema = selectedSchema || state.schema;
|
|
1307
|
+
switch (type) {
|
|
1308
|
+
case "setData": {
|
|
1309
|
+
if (!key) return state;
|
|
1310
|
+
return { ...state, data: { ...state.data, [key]: value } };
|
|
1311
|
+
}
|
|
1312
|
+
case "setValid": {
|
|
1313
|
+
if (!key) return state;
|
|
1314
|
+
return { ...state, valid: { ...state.valid, [key]: value } };
|
|
1315
|
+
}
|
|
1316
|
+
case "setErrors": {
|
|
1317
|
+
if (!key) return state;
|
|
1318
|
+
return { ...state, errors: { ...state.errors, [key]: value } };
|
|
1319
|
+
}
|
|
1320
|
+
case "setFieldProblems": {
|
|
1321
|
+
return state?.schema?.reduce(
|
|
1322
|
+
(acc, field) => ({
|
|
1323
|
+
...acc,
|
|
1324
|
+
fieldProblems: {
|
|
1325
|
+
...state.fieldProblems,
|
|
1326
|
+
[field]: fieldProblems?.[field] ?? false
|
|
1327
|
+
},
|
|
1328
|
+
valid: { ...state.valid, [field]: state.valid?.[field] && !fieldProblems?.[field] }
|
|
1329
|
+
}),
|
|
1330
|
+
state
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
case "setSchema": {
|
|
1334
|
+
if (!schema) return state;
|
|
1335
|
+
const defaultState = init({
|
|
1336
|
+
schema,
|
|
1337
|
+
// requiredFields
|
|
1338
|
+
defaultData,
|
|
1339
|
+
fieldProblems,
|
|
1340
|
+
obscuredFields,
|
|
1341
|
+
optionalFields,
|
|
1342
|
+
trustedFields,
|
|
1343
|
+
staticValidate,
|
|
1344
|
+
asyncValidate
|
|
1345
|
+
});
|
|
1346
|
+
const removedFields = state.optionalFields?.length ? [
|
|
1347
|
+
...state.schema.filter((field) => !schema.includes(field)),
|
|
1348
|
+
...state.optionalFields.filter((field) => !optionalFields?.includes(field))
|
|
1349
|
+
] : state.schema.filter((field) => !schema.includes(field));
|
|
1350
|
+
const newFields = optionalFields?.length ? [
|
|
1351
|
+
...schema.filter((field) => !state.schema?.includes(field)),
|
|
1352
|
+
...optionalFields.filter((field) => !state.optionalFields?.includes(field))
|
|
1353
|
+
] : schema.filter((field) => !state.schema?.includes(field));
|
|
1354
|
+
const local = {
|
|
1355
|
+
data: omitKeys(state.data, newFields),
|
|
1356
|
+
errors: omitKeys(state.errors, newFields),
|
|
1357
|
+
valid: omitKeys(state.valid, newFields),
|
|
1358
|
+
fieldProblems: omitKeys(state.fieldProblems, newFields)
|
|
1359
|
+
};
|
|
1360
|
+
const updatedData = addKeys(
|
|
1361
|
+
omitKeys(state.data, removedFields),
|
|
1362
|
+
newFields,
|
|
1363
|
+
null,
|
|
1364
|
+
defaultState.data,
|
|
1365
|
+
state.local?.data
|
|
1366
|
+
);
|
|
1367
|
+
const updatedValid = addKeys(
|
|
1368
|
+
omitKeys(state.valid, removedFields),
|
|
1369
|
+
newFields,
|
|
1370
|
+
false,
|
|
1371
|
+
defaultState.valid,
|
|
1372
|
+
state.local?.valid
|
|
1373
|
+
);
|
|
1374
|
+
const updatedErrors = addKeys(
|
|
1375
|
+
omitKeys(state.errors, removedFields),
|
|
1376
|
+
newFields,
|
|
1377
|
+
null,
|
|
1378
|
+
defaultState.errors,
|
|
1379
|
+
state.local?.errors
|
|
1380
|
+
);
|
|
1381
|
+
const updatedFieldProblems = addKeys(
|
|
1382
|
+
omitKeys(state.fieldProblems, removedFields),
|
|
1383
|
+
newFields,
|
|
1384
|
+
false,
|
|
1385
|
+
defaultState.fieldProblems,
|
|
1386
|
+
state.local?.fieldProblems
|
|
1387
|
+
);
|
|
1388
|
+
return {
|
|
1389
|
+
...state,
|
|
1390
|
+
schema,
|
|
1391
|
+
data: updatedData,
|
|
1392
|
+
valid: updatedValid,
|
|
1393
|
+
errors: updatedErrors,
|
|
1394
|
+
fieldProblems: updatedFieldProblems,
|
|
1395
|
+
obscuredFields,
|
|
1396
|
+
optionalFields,
|
|
1397
|
+
trustedFields,
|
|
1398
|
+
local
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
case "updateField": {
|
|
1402
|
+
if (!key || !mode) return state;
|
|
1403
|
+
const [formattedValue, validation] = processField({
|
|
1404
|
+
key,
|
|
1405
|
+
value,
|
|
1406
|
+
mode,
|
|
1407
|
+
defaultData,
|
|
1408
|
+
formatters,
|
|
1409
|
+
fieldContext: { state },
|
|
1410
|
+
staticValidate,
|
|
1411
|
+
asyncValidate
|
|
1412
|
+
});
|
|
1413
|
+
const oldValue = state.data[key];
|
|
1414
|
+
const clearFieldProblems = oldValue !== formattedValue;
|
|
1415
|
+
return {
|
|
1416
|
+
...state,
|
|
1417
|
+
data: { ...state.data, [key]: formattedValue },
|
|
1418
|
+
errors: {
|
|
1419
|
+
...state.errors,
|
|
1420
|
+
[key]: validation.getError() ?? null
|
|
1421
|
+
},
|
|
1422
|
+
valid: {
|
|
1423
|
+
...state.valid,
|
|
1424
|
+
[key]: validation.isValid && !state.fieldProblems?.[key] || false
|
|
1425
|
+
},
|
|
1426
|
+
fieldProblems: {
|
|
1427
|
+
...state.fieldProblems,
|
|
1428
|
+
[key]: clearFieldProblems ? false : state.fieldProblems?.[key] ?? false
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
case "mergeForm": {
|
|
1433
|
+
const mergedState = {
|
|
1434
|
+
...state,
|
|
1435
|
+
data: { ...state.data, ...formValue?.data },
|
|
1436
|
+
errors: { ...state.errors, ...formValue?.errors },
|
|
1437
|
+
valid: { ...state.valid, ...formValue?.valid },
|
|
1438
|
+
fieldProblems: { ...state.fieldProblems, ...formValue?.fieldProblems }
|
|
1439
|
+
};
|
|
1440
|
+
if (mergedState.valid) {
|
|
1441
|
+
mergedState.isValid = Object.values(mergedState.valid).every((isValid) => isValid);
|
|
1442
|
+
}
|
|
1443
|
+
return mergedState;
|
|
1444
|
+
}
|
|
1445
|
+
case "validateForm": {
|
|
1446
|
+
const formValidation = validationSchema?.reduce(
|
|
1447
|
+
(acc, cur) => {
|
|
1448
|
+
const [formattedValue, validation] = processField({
|
|
1449
|
+
key: cur,
|
|
1450
|
+
value: state.data[cur],
|
|
1451
|
+
mode: "blur",
|
|
1452
|
+
defaultData,
|
|
1453
|
+
formatters,
|
|
1454
|
+
fieldContext: { state },
|
|
1455
|
+
staticValidate,
|
|
1456
|
+
asyncValidate
|
|
1457
|
+
});
|
|
1458
|
+
const oldValue = state.data[cur];
|
|
1459
|
+
const clearFieldProblems = oldValue !== formattedValue;
|
|
1460
|
+
return {
|
|
1461
|
+
valid: {
|
|
1462
|
+
...acc.valid,
|
|
1463
|
+
[cur]: validation.isValid && !state.fieldProblems?.[cur] || false
|
|
1464
|
+
},
|
|
1465
|
+
errors: {
|
|
1466
|
+
...acc.errors,
|
|
1467
|
+
[cur]: validation.getError() ?? null
|
|
1468
|
+
},
|
|
1469
|
+
fieldProblems: {
|
|
1470
|
+
...acc.fieldProblems,
|
|
1471
|
+
[cur]: clearFieldProblems ? false : state.fieldProblems?.[cur] ?? false
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
},
|
|
1475
|
+
{ valid: state.valid, errors: state.errors, fieldProblems: state.fieldProblems }
|
|
1476
|
+
);
|
|
1477
|
+
return {
|
|
1478
|
+
...state,
|
|
1479
|
+
valid: formValidation?.valid,
|
|
1480
|
+
errors: formValidation?.errors,
|
|
1481
|
+
fieldProblems: formValidation?.fieldProblems
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
default:
|
|
1485
|
+
throw new Error("Undefined useForm action");
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
const mergeStaticAndAsyncErrorsState = (staticValidationErrors, asyncValidationErrors, schema, setValid, optionalFields) => {
|
|
1490
|
+
const fields = optionalFields ? [...schema, ...optionalFields] : schema;
|
|
1491
|
+
if (!fields.length) return staticValidationErrors;
|
|
1492
|
+
const errors = fields.reduce(
|
|
1493
|
+
(acc, field) => {
|
|
1494
|
+
if (asyncValidationErrors[field]?.getError()) setValid(field, false);
|
|
1495
|
+
return {
|
|
1496
|
+
...acc,
|
|
1497
|
+
[field]: staticValidationErrors[field] ?? asyncValidationErrors[field]?.getError() ?? null
|
|
1498
|
+
};
|
|
1499
|
+
},
|
|
1500
|
+
{}
|
|
1501
|
+
);
|
|
1502
|
+
return errors;
|
|
1503
|
+
};
|
|
1504
|
+
function useForm({
|
|
1505
|
+
schema,
|
|
1506
|
+
defaultData,
|
|
1507
|
+
rules,
|
|
1508
|
+
asyncRules,
|
|
1509
|
+
fieldProblems,
|
|
1510
|
+
obscuredFields,
|
|
1511
|
+
optionalFields,
|
|
1512
|
+
trustedFields,
|
|
1513
|
+
formatters,
|
|
1514
|
+
shouldValidate = false
|
|
1515
|
+
}) {
|
|
1516
|
+
const { triggerStaticValidation } = useStaticValidator(rules);
|
|
1517
|
+
const { triggerAsyncValidation, asyncValidationResults } = useAsyncValidator(asyncRules);
|
|
1518
|
+
const getRequiredFields = useMemo(
|
|
1519
|
+
() => typeof schema === "function" ? schema : () => schema,
|
|
1520
|
+
[schema]
|
|
1521
|
+
);
|
|
1522
|
+
const getSchema = useMemo(
|
|
1523
|
+
() => defaultData ? getRequiredFields(defaultData) : [],
|
|
1524
|
+
[defaultData, getRequiredFields]
|
|
1525
|
+
);
|
|
1526
|
+
const getReducer = useCallback(
|
|
1527
|
+
() => reducer({
|
|
1528
|
+
staticValidate: triggerStaticValidation,
|
|
1529
|
+
asyncValidate: triggerAsyncValidation,
|
|
1530
|
+
obscuredFields,
|
|
1531
|
+
optionalFields,
|
|
1532
|
+
trustedFields,
|
|
1533
|
+
formatters
|
|
1534
|
+
}),
|
|
1535
|
+
[
|
|
1536
|
+
triggerStaticValidation,
|
|
1537
|
+
triggerAsyncValidation,
|
|
1538
|
+
obscuredFields,
|
|
1539
|
+
optionalFields,
|
|
1540
|
+
trustedFields,
|
|
1541
|
+
formatters
|
|
1542
|
+
]
|
|
1543
|
+
);
|
|
1544
|
+
const initialData = useMemo(
|
|
1545
|
+
() => ({
|
|
1546
|
+
schema: getSchema,
|
|
1547
|
+
defaultData,
|
|
1548
|
+
fieldProblems,
|
|
1549
|
+
obscuredFields,
|
|
1550
|
+
optionalFields,
|
|
1551
|
+
trustedFields,
|
|
1552
|
+
formatters,
|
|
1553
|
+
staticValidate: triggerStaticValidation,
|
|
1554
|
+
asyncValidate: triggerAsyncValidation
|
|
1555
|
+
}),
|
|
1556
|
+
[
|
|
1557
|
+
getSchema,
|
|
1558
|
+
defaultData,
|
|
1559
|
+
fieldProblems,
|
|
1560
|
+
obscuredFields,
|
|
1561
|
+
optionalFields,
|
|
1562
|
+
trustedFields,
|
|
1563
|
+
formatters,
|
|
1564
|
+
triggerStaticValidation,
|
|
1565
|
+
triggerAsyncValidation
|
|
1566
|
+
]
|
|
1567
|
+
);
|
|
1568
|
+
const [state, dispatch] = useReducer(getReducer(), initialData, init);
|
|
1569
|
+
const isValid = useMemo(
|
|
1570
|
+
() => state.schema?.every((key) => state.valid[key]),
|
|
1571
|
+
[state.schema, state.valid]
|
|
1572
|
+
);
|
|
1573
|
+
const getTargetValue = useCallback(
|
|
1574
|
+
(key, e) => {
|
|
1575
|
+
if (!e?.target) return e;
|
|
1576
|
+
if (e.target.type === "checkbox") {
|
|
1577
|
+
return !state.data[key];
|
|
1578
|
+
}
|
|
1579
|
+
return e.target.value;
|
|
1580
|
+
},
|
|
1581
|
+
[state.data]
|
|
1582
|
+
);
|
|
1583
|
+
const setErrors = useCallback(
|
|
1584
|
+
(key, value) => dispatch({ type: "setErrors", key, value }),
|
|
1585
|
+
[]
|
|
1586
|
+
);
|
|
1587
|
+
const setValid = useCallback(
|
|
1588
|
+
(key, value) => dispatch({ type: "setValid", key, value }),
|
|
1589
|
+
[]
|
|
1590
|
+
);
|
|
1591
|
+
const setData = useCallback(
|
|
1592
|
+
(key, value) => dispatch({ type: "setData", key, value }),
|
|
1593
|
+
[]
|
|
1594
|
+
);
|
|
1595
|
+
const setSchema = useCallback(
|
|
1596
|
+
(newSchema) => dispatch({ type: "setSchema", schema: newSchema, defaultData }),
|
|
1597
|
+
[defaultData]
|
|
1598
|
+
);
|
|
1599
|
+
const setFieldProblems = useCallback(
|
|
1600
|
+
(newFieldProblems) => dispatch({ type: "setFieldProblems", fieldProblems: newFieldProblems }),
|
|
1601
|
+
[]
|
|
1602
|
+
);
|
|
1603
|
+
const mergeForm = useCallback(
|
|
1604
|
+
(formValue) => dispatch({ type: "mergeForm", formValue }),
|
|
1605
|
+
[]
|
|
1606
|
+
);
|
|
1607
|
+
const handleChangeFor = useCallback(
|
|
1608
|
+
(key, mode = "blur") => (e) => {
|
|
1609
|
+
const value = getTargetValue(key, e);
|
|
1610
|
+
dispatch({
|
|
1611
|
+
type: "updateField",
|
|
1612
|
+
key,
|
|
1613
|
+
value,
|
|
1614
|
+
mode,
|
|
1615
|
+
defaultData
|
|
1616
|
+
});
|
|
1617
|
+
},
|
|
1618
|
+
[defaultData, getTargetValue]
|
|
1619
|
+
);
|
|
1620
|
+
const triggerValidation = useCallback(
|
|
1621
|
+
(selectedSchema) => {
|
|
1622
|
+
dispatch({
|
|
1623
|
+
type: "validateForm",
|
|
1624
|
+
selectedSchema,
|
|
1625
|
+
defaultData
|
|
1626
|
+
});
|
|
1627
|
+
},
|
|
1628
|
+
[defaultData]
|
|
1629
|
+
);
|
|
1630
|
+
const resetToDefaultData = useCallback(() => {
|
|
1631
|
+
getSchema.forEach((field) => {
|
|
1632
|
+
if (!defaultData || typeof defaultData[field] !== "undefined") {
|
|
1633
|
+
return handleChangeFor(field)(defaultData?.[field]);
|
|
1634
|
+
}
|
|
1635
|
+
setValid(field, false);
|
|
1636
|
+
setErrors(field, null);
|
|
1637
|
+
setData(field, defaultData[field]);
|
|
1638
|
+
});
|
|
1639
|
+
}, [defaultData, getSchema, handleChangeFor, setData, setErrors, setValid]);
|
|
1640
|
+
useEffect(() => {
|
|
1641
|
+
const newSchema = getRequiredFields(state.data);
|
|
1642
|
+
if (!doArraysMatch(state.schema, newSchema)) {
|
|
1643
|
+
setSchema(newSchema);
|
|
1644
|
+
}
|
|
1645
|
+
}, [state.schema, state.data, setSchema, getRequiredFields]);
|
|
1646
|
+
useEffect(() => {
|
|
1647
|
+
if (shouldValidate) {
|
|
1648
|
+
triggerValidation();
|
|
1649
|
+
}
|
|
1650
|
+
}, [shouldValidate, state.schema]);
|
|
1651
|
+
useEffect(() => {
|
|
1652
|
+
if (fieldProblems) {
|
|
1653
|
+
setFieldProblems(fieldProblems);
|
|
1654
|
+
}
|
|
1655
|
+
}, [JSON.stringify(fieldProblems), setFieldProblems]);
|
|
1656
|
+
const formErrors = useMemo(
|
|
1657
|
+
() => mergeStaticAndAsyncErrorsState(
|
|
1658
|
+
state.errors,
|
|
1659
|
+
asyncValidationResults,
|
|
1660
|
+
state.schema,
|
|
1661
|
+
setValid,
|
|
1662
|
+
state.optionalFields
|
|
1663
|
+
),
|
|
1664
|
+
[asyncValidationResults, state.errors, state.optionalFields, state.schema]
|
|
1665
|
+
);
|
|
1666
|
+
return {
|
|
1667
|
+
mergeForm,
|
|
1668
|
+
setData,
|
|
1669
|
+
setValid,
|
|
1670
|
+
setErrors,
|
|
1671
|
+
setFieldProblems,
|
|
1672
|
+
handleChangeFor,
|
|
1673
|
+
triggerValidation,
|
|
1674
|
+
resetToDefaultData,
|
|
1675
|
+
isValid,
|
|
1676
|
+
schema: state.schema,
|
|
1677
|
+
valid: state.valid,
|
|
1678
|
+
errors: formErrors,
|
|
1679
|
+
data: state.data,
|
|
1680
|
+
fieldProblems: state.fieldProblems
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
export {
|
|
1684
|
+
Checkbox as C,
|
|
1685
|
+
Field as F,
|
|
1686
|
+
LoaderWrapper as L,
|
|
1687
|
+
SelectListItem as S,
|
|
1688
|
+
ValidationResult as V,
|
|
1689
|
+
useForm as a,
|
|
1690
|
+
useId as b,
|
|
1691
|
+
Select as c,
|
|
1692
|
+
getDataByFields as g,
|
|
1693
|
+
uuidv4 as u
|
|
1694
|
+
};
|