@dnb/eufemia 10.12.0 → 10.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/cjs/components/accordion/Accordion.js +1 -0
- package/cjs/components/accordion/Accordion.js.map +1 -1
- package/cjs/components/accordion/AccordionGroup.js +1 -0
- package/cjs/components/accordion/AccordionGroup.js.map +1 -1
- package/cjs/components/accordion/AccordionHeader.js +5 -15
- package/cjs/components/accordion/AccordionHeader.js.map +1 -1
- package/cjs/components/accordion/style/dnb-accordion.css +2 -2
- package/cjs/components/accordion/style/dnb-accordion.min.css +1 -1
- package/cjs/components/accordion/style/dnb-accordion.scss +3 -8
- package/cjs/components/accordion/style/themes/dnb-accordion-theme-sbanken.css +1 -1
- package/cjs/components/accordion/style/themes/dnb-accordion-theme-sbanken.min.css +1 -1
- package/cjs/components/accordion/style/themes/dnb-accordion-theme-sbanken.scss +1 -1
- package/cjs/components/anchor/Anchor.js.map +1 -1
- package/cjs/components/anchor/style/themes/dnb-anchor-theme-sbanken.css +2 -2
- package/cjs/components/anchor/style/themes/dnb-anchor-theme-sbanken.min.css +1 -1
- package/cjs/components/anchor/style/themes/dnb-anchor-theme-sbanken.scss +1 -2
- package/cjs/components/autocomplete/Autocomplete.d.ts +2 -2
- package/cjs/components/autocomplete/Autocomplete.js +41 -16
- package/cjs/components/autocomplete/Autocomplete.js.map +1 -1
- package/cjs/components/breadcrumb/Breadcrumb.js +1 -0
- package/cjs/components/breadcrumb/Breadcrumb.js.map +1 -1
- package/cjs/components/button/style/themes/dnb-button-theme-eiendom.scss +1 -1
- package/cjs/components/button/style/themes/dnb-button-theme-sbanken.css +2 -2
- package/cjs/components/button/style/themes/dnb-button-theme-sbanken.min.css +1 -1
- package/cjs/components/button/style/themes/dnb-button-theme-sbanken.scss +2 -2
- package/cjs/components/card/Card.js +2 -2
- package/cjs/components/card/Card.js.map +1 -1
- package/cjs/components/dialog/Dialog.js +1 -0
- package/cjs/components/dialog/Dialog.js.map +1 -1
- package/cjs/components/dialog/DialogContent.js +1 -0
- package/cjs/components/dialog/DialogContent.js.map +1 -1
- package/cjs/components/dialog/parts/DialogAction.js +1 -0
- package/cjs/components/dialog/parts/DialogAction.js.map +1 -1
- package/cjs/components/drawer/Drawer.js +1 -0
- package/cjs/components/drawer/Drawer.js.map +1 -1
- package/cjs/components/drawer/DrawerContent.js +1 -0
- package/cjs/components/drawer/DrawerContent.js.map +1 -1
- package/cjs/components/drawer/parts/DrawerContentContext.js +1 -0
- package/cjs/components/drawer/parts/DrawerContentContext.js.map +1 -1
- package/cjs/components/flex/Container.js +6 -4
- package/cjs/components/flex/Container.js.map +1 -1
- package/cjs/components/flex/utils.js +2 -2
- package/cjs/components/flex/utils.js.map +1 -1
- package/cjs/components/form-row/style/dnb-form-row.scss +1 -1
- package/cjs/components/icon/style/dnb-icon.scss +1 -1
- package/cjs/components/input-masked/InputMasked.d.ts +1 -1
- package/cjs/components/input-masked/MultiInputMask.d.ts +3 -3
- package/cjs/components/input-masked/MultiInputMask.js +2 -1
- package/cjs/components/input-masked/MultiInputMask.js.map +1 -1
- package/cjs/components/input-masked/hooks/useHandleCursorPosition.js +1 -0
- package/cjs/components/input-masked/hooks/useHandleCursorPosition.js.map +1 -1
- package/cjs/components/input-masked/hooks/useMultiInputValues.js +1 -0
- package/cjs/components/input-masked/hooks/useMultiInputValues.js.map +1 -1
- package/cjs/components/number-format/NumberUtils.js.map +1 -1
- package/cjs/components/number-format/useNumberFormat.js +1 -0
- package/cjs/components/number-format/useNumberFormat.js.map +1 -1
- package/cjs/components/pagination/PaginationBar.js +1 -0
- package/cjs/components/pagination/PaginationBar.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorContext.js +1 -0
- package/cjs/components/step-indicator/StepIndicatorContext.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorItem.js +3 -2
- package/cjs/components/step-indicator/StepIndicatorItem.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorList.js +1 -0
- package/cjs/components/step-indicator/StepIndicatorList.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorModal.js +1 -0
- package/cjs/components/step-indicator/StepIndicatorModal.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorSidebar.js +1 -0
- package/cjs/components/step-indicator/StepIndicatorSidebar.js.map +1 -1
- package/cjs/components/step-indicator/StepIndicatorTriggerButton.js +1 -0
- package/cjs/components/step-indicator/StepIndicatorTriggerButton.js.map +1 -1
- package/cjs/components/table/style/themes/dnb-table-theme-sbanken.css +1 -0
- package/cjs/components/table/style/themes/dnb-table-theme-sbanken.min.css +1 -1
- package/cjs/components/table/style/themes/dnb-table-theme-sbanken.scss +1 -0
- package/cjs/components/toggle-button/style/themes/dnb-toggle-button-theme-ui.scss +1 -1
- package/cjs/components/tooltip/TooltipWithEvents.js.map +1 -1
- package/cjs/components/upload/UploadContext.js +1 -0
- package/cjs/components/upload/UploadContext.js.map +1 -1
- package/cjs/components/upload/UploadFileInput.js +1 -0
- package/cjs/components/upload/UploadFileInput.js.map +1 -1
- package/cjs/components/upload/UploadFileListCell.js +1 -0
- package/cjs/components/upload/UploadFileListCell.js.map +1 -1
- package/cjs/elements/lists/Dl.d.ts +1 -1
- package/cjs/elements/lists/Dl.js.map +1 -1
- package/cjs/elements/typography/style/dnb-typography.scss +1 -1
- package/cjs/elements/typography/style/typography-mixins.scss +2 -2
- package/cjs/extensions/forms/DataContext/At/At.js +1 -0
- package/cjs/extensions/forms/DataContext/At/At.js.map +1 -1
- package/cjs/extensions/forms/DataContext/Provider/Provider.js +5 -3
- package/cjs/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/cjs/extensions/forms/Field/ArraySelection/ArraySelection.js +12 -9
- package/cjs/extensions/forms/Field/ArraySelection/ArraySelection.js.map +1 -1
- package/cjs/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js +5 -3
- package/cjs/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/cjs/extensions/forms/Field/Boolean/Boolean.js +3 -2
- package/cjs/extensions/forms/Field/Boolean/Boolean.js.map +1 -1
- package/cjs/extensions/forms/Field/Currency/Currency.js +3 -2
- package/cjs/extensions/forms/Field/Currency/Currency.js.map +1 -1
- package/cjs/extensions/forms/Field/Date/Date.js +2 -1
- package/cjs/extensions/forms/Field/Date/Date.js.map +1 -1
- package/cjs/extensions/forms/Field/Email/Email.js +5 -3
- package/cjs/extensions/forms/Field/Email/Email.js.map +1 -1
- package/cjs/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js +5 -3
- package/cjs/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/cjs/extensions/forms/Field/Number/Number.js +3 -2
- package/cjs/extensions/forms/Field/Number/Number.js.map +1 -1
- package/cjs/extensions/forms/Field/Option/Option.js +1 -1
- package/cjs/extensions/forms/Field/Option/Option.js.map +1 -1
- package/cjs/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js +5 -3
- package/cjs/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js.map +1 -1
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +5 -0
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.js +58 -18
- package/cjs/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/cjs/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js +6 -4
- package/cjs/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js.map +1 -1
- package/cjs/extensions/forms/Field/SelectCountry/SelectCountry.js +12 -8
- package/cjs/extensions/forms/Field/SelectCountry/SelectCountry.js.map +1 -1
- package/cjs/extensions/forms/Field/Selection/Selection.js +29 -20
- package/cjs/extensions/forms/Field/Selection/Selection.js.map +1 -1
- package/cjs/extensions/forms/Field/String/String.js +10 -9
- package/cjs/extensions/forms/Field/String/String.js.map +1 -1
- package/cjs/extensions/forms/Field/Toggle/Toggle.js +5 -4
- package/cjs/extensions/forms/Field/Toggle/Toggle.js.map +1 -1
- package/cjs/extensions/forms/FieldBlock/FieldBlock.js +1 -0
- package/cjs/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/cjs/extensions/forms/Form/SubmitButton/SubmitButton.js +1 -0
- package/cjs/extensions/forms/Form/SubmitButton/SubmitButton.js.map +1 -1
- package/cjs/extensions/forms/Iterate/Array/Array.js +2 -2
- package/cjs/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/cjs/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js +3 -2
- package/cjs/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js.map +1 -1
- package/cjs/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js +2 -1
- package/cjs/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js.map +1 -1
- package/cjs/extensions/forms/StepsLayout/NextButton/NextButton.js +1 -0
- package/cjs/extensions/forms/StepsLayout/NextButton/NextButton.js.map +1 -1
- package/cjs/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js +1 -0
- package/cjs/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js.map +1 -1
- package/cjs/extensions/forms/StepsLayout/Step/Step.js +1 -0
- package/cjs/extensions/forms/StepsLayout/Step/Step.js.map +1 -1
- package/cjs/extensions/forms/StepsLayout/StepsLayout.js +3 -1
- package/cjs/extensions/forms/StepsLayout/StepsLayout.js.map +1 -1
- package/cjs/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js +3 -1
- package/cjs/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/cjs/extensions/forms/Value/Boolean/Boolean.js +1 -0
- package/cjs/extensions/forms/Value/Boolean/Boolean.js.map +1 -1
- package/cjs/extensions/forms/Value/Currency/Currency.js +3 -2
- package/cjs/extensions/forms/Value/Currency/Currency.js.map +1 -1
- package/cjs/extensions/forms/Value/Date/Date.js +3 -1
- package/cjs/extensions/forms/Value/Date/Date.js.map +1 -1
- package/cjs/extensions/forms/Value/Email/Email.js +3 -1
- package/cjs/extensions/forms/Value/Email/Email.js.map +1 -1
- package/cjs/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js +3 -1
- package/cjs/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/cjs/extensions/forms/Value/PhoneNumber/PhoneNumber.js +3 -1
- package/cjs/extensions/forms/Value/PhoneNumber/PhoneNumber.js.map +1 -1
- package/cjs/extensions/forms/ValueBlock/ValueBlock.js +1 -1
- package/cjs/extensions/forms/ValueBlock/ValueBlock.js.map +1 -1
- package/cjs/extensions/forms/Visibility/Visibility.js +1 -0
- package/cjs/extensions/forms/Visibility/Visibility.js.map +1 -1
- package/cjs/extensions/forms/hooks/useDataValue.js +21 -17
- package/cjs/extensions/forms/hooks/useDataValue.js.map +1 -1
- package/cjs/extensions/forms/types.js +6 -6
- package/cjs/extensions/forms/types.js.map +1 -1
- package/cjs/extensions/forms/utils/ajv.js +3 -2
- package/cjs/extensions/forms/utils/ajv.js.map +1 -1
- package/cjs/extensions/forms/utils/numbers.js +2 -2
- package/cjs/extensions/forms/utils/numbers.js.map +1 -1
- package/cjs/extensions/forms/utils/useWasChanged.js +8 -6
- package/cjs/extensions/forms/utils/useWasChanged.js.map +1 -1
- package/cjs/fragments/drawer-list/DrawerListHelpers.js +1 -1
- package/cjs/fragments/drawer-list/DrawerListHelpers.js.map +1 -1
- package/cjs/fragments/drawer-list/DrawerListProvider.js.map +1 -1
- package/cjs/fragments/drawer-list/style/themes/dnb-drawer-list-theme-sbanken.scss +1 -1
- package/cjs/fragments/drawer-list/style/themes/dnb-drawer-list-theme-ui.scss +2 -2
- package/cjs/shared/Eufemia.d.ts +1 -1
- package/cjs/shared/Eufemia.js +2 -2
- package/cjs/shared/Eufemia.js.map +1 -1
- package/cjs/style/dnb-ui-components.css +2 -2
- package/cjs/style/dnb-ui-components.min.css +1 -1
- package/cjs/style/themes/theme-eiendom/eiendom-theme-components.css +2 -2
- package/cjs/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/cjs/style/themes/theme-sbanken/fonts.scss +5 -4
- package/cjs/style/themes/theme-sbanken/properties.js +2 -2
- package/cjs/style/themes/theme-sbanken/properties.js.map +1 -1
- package/cjs/style/themes/theme-sbanken/sbanken-theme-basis.css +3 -2
- package/cjs/style/themes/theme-sbanken/sbanken-theme-basis.min.css +1 -1
- package/cjs/style/themes/theme-sbanken/sbanken-theme-components.css +8 -7
- package/cjs/style/themes/theme-sbanken/sbanken-theme-components.min.css +4 -4
- package/cjs/style/themes/theme-sbanken/theme-mapping.scss +2 -1
- package/cjs/style/themes/theme-ui/ui-theme-components.css +2 -2
- package/cjs/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/components/accordion/Accordion.js +2 -0
- package/components/accordion/Accordion.js.map +1 -1
- package/components/accordion/AccordionGroup.js +2 -0
- package/components/accordion/AccordionGroup.js.map +1 -1
- package/components/accordion/AccordionHeader.js +6 -15
- package/components/accordion/AccordionHeader.js.map +1 -1
- package/components/accordion/style/dnb-accordion.css +2 -2
- package/components/accordion/style/dnb-accordion.min.css +1 -1
- package/components/accordion/style/dnb-accordion.scss +3 -8
- package/components/accordion/style/themes/dnb-accordion-theme-sbanken.css +1 -1
- package/components/accordion/style/themes/dnb-accordion-theme-sbanken.min.css +1 -1
- package/components/accordion/style/themes/dnb-accordion-theme-sbanken.scss +1 -1
- package/components/anchor/Anchor.js.map +1 -1
- package/components/anchor/style/themes/dnb-anchor-theme-sbanken.css +2 -2
- package/components/anchor/style/themes/dnb-anchor-theme-sbanken.min.css +1 -1
- package/components/anchor/style/themes/dnb-anchor-theme-sbanken.scss +1 -2
- package/components/autocomplete/Autocomplete.d.ts +2 -2
- package/components/autocomplete/Autocomplete.js +42 -17
- package/components/autocomplete/Autocomplete.js.map +1 -1
- package/components/breadcrumb/Breadcrumb.js +2 -0
- package/components/breadcrumb/Breadcrumb.js.map +1 -1
- package/components/button/style/themes/dnb-button-theme-eiendom.scss +1 -1
- package/components/button/style/themes/dnb-button-theme-sbanken.css +2 -2
- package/components/button/style/themes/dnb-button-theme-sbanken.min.css +1 -1
- package/components/button/style/themes/dnb-button-theme-sbanken.scss +2 -2
- package/components/card/Card.js +2 -2
- package/components/card/Card.js.map +1 -1
- package/components/dialog/Dialog.js +2 -0
- package/components/dialog/Dialog.js.map +1 -1
- package/components/dialog/DialogContent.js +2 -0
- package/components/dialog/DialogContent.js.map +1 -1
- package/components/dialog/parts/DialogAction.js +2 -0
- package/components/dialog/parts/DialogAction.js.map +1 -1
- package/components/drawer/Drawer.js +2 -0
- package/components/drawer/Drawer.js.map +1 -1
- package/components/drawer/DrawerContent.js +2 -0
- package/components/drawer/DrawerContent.js.map +1 -1
- package/components/drawer/parts/DrawerContentContext.js +2 -0
- package/components/drawer/parts/DrawerContentContext.js.map +1 -1
- package/components/flex/Container.js +6 -4
- package/components/flex/Container.js.map +1 -1
- package/components/flex/utils.js +2 -2
- package/components/flex/utils.js.map +1 -1
- package/components/form-row/style/dnb-form-row.scss +1 -1
- package/components/icon/style/dnb-icon.scss +1 -1
- package/components/input-masked/InputMasked.d.ts +1 -1
- package/components/input-masked/MultiInputMask.d.ts +3 -3
- package/components/input-masked/MultiInputMask.js +3 -1
- package/components/input-masked/MultiInputMask.js.map +1 -1
- package/components/input-masked/hooks/useHandleCursorPosition.js +2 -0
- package/components/input-masked/hooks/useHandleCursorPosition.js.map +1 -1
- package/components/input-masked/hooks/useMultiInputValues.js +2 -0
- package/components/input-masked/hooks/useMultiInputValues.js.map +1 -1
- package/components/number-format/NumberUtils.js.map +1 -1
- package/components/number-format/useNumberFormat.js +2 -0
- package/components/number-format/useNumberFormat.js.map +1 -1
- package/components/pagination/PaginationBar.js +2 -0
- package/components/pagination/PaginationBar.js.map +1 -1
- package/components/step-indicator/StepIndicatorContext.js +2 -0
- package/components/step-indicator/StepIndicatorContext.js.map +1 -1
- package/components/step-indicator/StepIndicatorItem.js +4 -2
- package/components/step-indicator/StepIndicatorItem.js.map +1 -1
- package/components/step-indicator/StepIndicatorList.js +2 -0
- package/components/step-indicator/StepIndicatorList.js.map +1 -1
- package/components/step-indicator/StepIndicatorModal.js +2 -0
- package/components/step-indicator/StepIndicatorModal.js.map +1 -1
- package/components/step-indicator/StepIndicatorSidebar.js +2 -0
- package/components/step-indicator/StepIndicatorSidebar.js.map +1 -1
- package/components/step-indicator/StepIndicatorTriggerButton.js +2 -0
- package/components/step-indicator/StepIndicatorTriggerButton.js.map +1 -1
- package/components/table/style/themes/dnb-table-theme-sbanken.css +1 -0
- package/components/table/style/themes/dnb-table-theme-sbanken.min.css +1 -1
- package/components/table/style/themes/dnb-table-theme-sbanken.scss +1 -0
- package/components/toggle-button/style/themes/dnb-toggle-button-theme-ui.scss +1 -1
- package/components/tooltip/TooltipWithEvents.js.map +1 -1
- package/components/upload/UploadContext.js +2 -0
- package/components/upload/UploadContext.js.map +1 -1
- package/components/upload/UploadFileInput.js +2 -0
- package/components/upload/UploadFileInput.js.map +1 -1
- package/components/upload/UploadFileListCell.js +2 -0
- package/components/upload/UploadFileListCell.js.map +1 -1
- package/elements/lists/Dl.d.ts +1 -1
- package/elements/lists/Dl.js.map +1 -1
- package/elements/typography/style/dnb-typography.scss +1 -1
- package/elements/typography/style/typography-mixins.scss +2 -2
- package/es/components/accordion/Accordion.js +2 -0
- package/es/components/accordion/Accordion.js.map +1 -1
- package/es/components/accordion/AccordionGroup.js +2 -0
- package/es/components/accordion/AccordionGroup.js.map +1 -1
- package/es/components/accordion/AccordionHeader.js +6 -15
- package/es/components/accordion/AccordionHeader.js.map +1 -1
- package/es/components/accordion/style/dnb-accordion.css +2 -2
- package/es/components/accordion/style/dnb-accordion.min.css +1 -1
- package/es/components/accordion/style/dnb-accordion.scss +3 -8
- package/es/components/accordion/style/themes/dnb-accordion-theme-sbanken.css +1 -1
- package/es/components/accordion/style/themes/dnb-accordion-theme-sbanken.min.css +1 -1
- package/es/components/accordion/style/themes/dnb-accordion-theme-sbanken.scss +1 -1
- package/es/components/anchor/Anchor.js.map +1 -1
- package/es/components/anchor/style/themes/dnb-anchor-theme-sbanken.css +2 -2
- package/es/components/anchor/style/themes/dnb-anchor-theme-sbanken.min.css +1 -1
- package/es/components/anchor/style/themes/dnb-anchor-theme-sbanken.scss +1 -2
- package/es/components/autocomplete/Autocomplete.d.ts +2 -2
- package/es/components/autocomplete/Autocomplete.js +42 -17
- package/es/components/autocomplete/Autocomplete.js.map +1 -1
- package/es/components/breadcrumb/Breadcrumb.js +2 -0
- package/es/components/breadcrumb/Breadcrumb.js.map +1 -1
- package/es/components/button/style/themes/dnb-button-theme-eiendom.scss +1 -1
- package/es/components/button/style/themes/dnb-button-theme-sbanken.css +2 -2
- package/es/components/button/style/themes/dnb-button-theme-sbanken.min.css +1 -1
- package/es/components/button/style/themes/dnb-button-theme-sbanken.scss +2 -2
- package/es/components/card/Card.js +2 -2
- package/es/components/card/Card.js.map +1 -1
- package/es/components/dialog/Dialog.js +2 -0
- package/es/components/dialog/Dialog.js.map +1 -1
- package/es/components/dialog/DialogContent.js +2 -0
- package/es/components/dialog/DialogContent.js.map +1 -1
- package/es/components/dialog/parts/DialogAction.js +2 -0
- package/es/components/dialog/parts/DialogAction.js.map +1 -1
- package/es/components/drawer/Drawer.js +2 -0
- package/es/components/drawer/Drawer.js.map +1 -1
- package/es/components/drawer/DrawerContent.js +2 -0
- package/es/components/drawer/DrawerContent.js.map +1 -1
- package/es/components/drawer/parts/DrawerContentContext.js +2 -0
- package/es/components/drawer/parts/DrawerContentContext.js.map +1 -1
- package/es/components/flex/Container.js +6 -4
- package/es/components/flex/Container.js.map +1 -1
- package/es/components/flex/utils.js +2 -2
- package/es/components/flex/utils.js.map +1 -1
- package/es/components/form-row/style/dnb-form-row.scss +1 -1
- package/es/components/icon/style/dnb-icon.scss +1 -1
- package/es/components/input-masked/InputMasked.d.ts +1 -1
- package/es/components/input-masked/MultiInputMask.d.ts +3 -3
- package/es/components/input-masked/MultiInputMask.js +3 -1
- package/es/components/input-masked/MultiInputMask.js.map +1 -1
- package/es/components/input-masked/hooks/useHandleCursorPosition.js +2 -0
- package/es/components/input-masked/hooks/useHandleCursorPosition.js.map +1 -1
- package/es/components/input-masked/hooks/useMultiInputValues.js +2 -0
- package/es/components/input-masked/hooks/useMultiInputValues.js.map +1 -1
- package/es/components/number-format/NumberUtils.js.map +1 -1
- package/es/components/number-format/useNumberFormat.js +2 -0
- package/es/components/number-format/useNumberFormat.js.map +1 -1
- package/es/components/pagination/PaginationBar.js +2 -0
- package/es/components/pagination/PaginationBar.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorContext.js +2 -0
- package/es/components/step-indicator/StepIndicatorContext.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorItem.js +4 -2
- package/es/components/step-indicator/StepIndicatorItem.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorList.js +2 -0
- package/es/components/step-indicator/StepIndicatorList.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorModal.js +2 -0
- package/es/components/step-indicator/StepIndicatorModal.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorSidebar.js +2 -0
- package/es/components/step-indicator/StepIndicatorSidebar.js.map +1 -1
- package/es/components/step-indicator/StepIndicatorTriggerButton.js +2 -0
- package/es/components/step-indicator/StepIndicatorTriggerButton.js.map +1 -1
- package/es/components/table/style/themes/dnb-table-theme-sbanken.css +1 -0
- package/es/components/table/style/themes/dnb-table-theme-sbanken.min.css +1 -1
- package/es/components/table/style/themes/dnb-table-theme-sbanken.scss +1 -0
- package/es/components/toggle-button/style/themes/dnb-toggle-button-theme-ui.scss +1 -1
- package/es/components/tooltip/TooltipWithEvents.js.map +1 -1
- package/es/components/upload/UploadContext.js +2 -0
- package/es/components/upload/UploadContext.js.map +1 -1
- package/es/components/upload/UploadFileInput.js +2 -0
- package/es/components/upload/UploadFileInput.js.map +1 -1
- package/es/components/upload/UploadFileListCell.js +2 -0
- package/es/components/upload/UploadFileListCell.js.map +1 -1
- package/es/elements/lists/Dl.d.ts +1 -1
- package/es/elements/lists/Dl.js.map +1 -1
- package/es/elements/typography/style/dnb-typography.scss +1 -1
- package/es/elements/typography/style/typography-mixins.scss +2 -2
- package/es/extensions/forms/DataContext/At/At.js +2 -0
- package/es/extensions/forms/DataContext/At/At.js.map +1 -1
- package/es/extensions/forms/DataContext/Provider/Provider.js +6 -3
- package/es/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/es/extensions/forms/Field/ArraySelection/ArraySelection.js +12 -9
- package/es/extensions/forms/Field/ArraySelection/ArraySelection.js.map +1 -1
- package/es/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js +6 -3
- package/es/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/es/extensions/forms/Field/Boolean/Boolean.js +4 -2
- package/es/extensions/forms/Field/Boolean/Boolean.js.map +1 -1
- package/es/extensions/forms/Field/Currency/Currency.js +3 -2
- package/es/extensions/forms/Field/Currency/Currency.js.map +1 -1
- package/es/extensions/forms/Field/Date/Date.js +3 -1
- package/es/extensions/forms/Field/Date/Date.js.map +1 -1
- package/es/extensions/forms/Field/Email/Email.js +6 -3
- package/es/extensions/forms/Field/Email/Email.js.map +1 -1
- package/es/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js +6 -3
- package/es/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/es/extensions/forms/Field/Number/Number.js +3 -2
- package/es/extensions/forms/Field/Number/Number.js.map +1 -1
- package/es/extensions/forms/Field/Option/Option.js +1 -1
- package/es/extensions/forms/Field/Option/Option.js.map +1 -1
- package/es/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js +6 -3
- package/es/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js.map +1 -1
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +5 -0
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.js +48 -16
- package/es/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/es/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js +7 -4
- package/es/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js.map +1 -1
- package/es/extensions/forms/Field/SelectCountry/SelectCountry.js +13 -8
- package/es/extensions/forms/Field/SelectCountry/SelectCountry.js.map +1 -1
- package/es/extensions/forms/Field/Selection/Selection.js +30 -20
- package/es/extensions/forms/Field/Selection/Selection.js.map +1 -1
- package/es/extensions/forms/Field/String/String.js +11 -9
- package/es/extensions/forms/Field/String/String.js.map +1 -1
- package/es/extensions/forms/Field/Toggle/Toggle.js +6 -4
- package/es/extensions/forms/Field/Toggle/Toggle.js.map +1 -1
- package/es/extensions/forms/FieldBlock/FieldBlock.js +2 -0
- package/es/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/es/extensions/forms/Form/SubmitButton/SubmitButton.js +2 -0
- package/es/extensions/forms/Form/SubmitButton/SubmitButton.js.map +1 -1
- package/es/extensions/forms/Iterate/Array/Array.js +2 -2
- package/es/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/es/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js +4 -2
- package/es/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js.map +1 -1
- package/es/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js +3 -1
- package/es/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js.map +1 -1
- package/es/extensions/forms/StepsLayout/NextButton/NextButton.js +2 -0
- package/es/extensions/forms/StepsLayout/NextButton/NextButton.js.map +1 -1
- package/es/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js +2 -0
- package/es/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js.map +1 -1
- package/es/extensions/forms/StepsLayout/Step/Step.js +2 -0
- package/es/extensions/forms/StepsLayout/Step/Step.js.map +1 -1
- package/es/extensions/forms/StepsLayout/StepsLayout.js +4 -1
- package/es/extensions/forms/StepsLayout/StepsLayout.js.map +1 -1
- package/es/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js +4 -1
- package/es/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/es/extensions/forms/Value/Boolean/Boolean.js +2 -0
- package/es/extensions/forms/Value/Boolean/Boolean.js.map +1 -1
- package/es/extensions/forms/Value/Currency/Currency.js +3 -2
- package/es/extensions/forms/Value/Currency/Currency.js.map +1 -1
- package/es/extensions/forms/Value/Date/Date.js +4 -1
- package/es/extensions/forms/Value/Date/Date.js.map +1 -1
- package/es/extensions/forms/Value/Email/Email.js +4 -1
- package/es/extensions/forms/Value/Email/Email.js.map +1 -1
- package/es/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js +4 -1
- package/es/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/es/extensions/forms/Value/PhoneNumber/PhoneNumber.js +4 -1
- package/es/extensions/forms/Value/PhoneNumber/PhoneNumber.js.map +1 -1
- package/es/extensions/forms/ValueBlock/ValueBlock.js +1 -1
- package/es/extensions/forms/ValueBlock/ValueBlock.js.map +1 -1
- package/es/extensions/forms/Visibility/Visibility.js +2 -0
- package/es/extensions/forms/Visibility/Visibility.js.map +1 -1
- package/es/extensions/forms/hooks/useDataValue.js +22 -17
- package/es/extensions/forms/hooks/useDataValue.js.map +1 -1
- package/es/extensions/forms/types.js +6 -6
- package/es/extensions/forms/types.js.map +1 -1
- package/es/extensions/forms/utils/ajv.js +3 -2
- package/es/extensions/forms/utils/ajv.js.map +1 -1
- package/es/extensions/forms/utils/numbers.js +2 -2
- package/es/extensions/forms/utils/numbers.js.map +1 -1
- package/es/extensions/forms/utils/useWasChanged.js +9 -6
- package/es/extensions/forms/utils/useWasChanged.js.map +1 -1
- package/es/fragments/drawer-list/DrawerListHelpers.js +1 -1
- package/es/fragments/drawer-list/DrawerListHelpers.js.map +1 -1
- package/es/fragments/drawer-list/DrawerListProvider.js.map +1 -1
- package/es/fragments/drawer-list/style/themes/dnb-drawer-list-theme-sbanken.scss +1 -1
- package/es/fragments/drawer-list/style/themes/dnb-drawer-list-theme-ui.scss +2 -2
- package/es/shared/Eufemia.d.ts +1 -1
- package/es/shared/Eufemia.js +2 -2
- package/es/shared/Eufemia.js.map +1 -1
- package/es/style/dnb-ui-components.css +2 -2
- package/es/style/dnb-ui-components.min.css +1 -1
- package/es/style/themes/theme-eiendom/eiendom-theme-components.css +2 -2
- package/es/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/es/style/themes/theme-sbanken/fonts.scss +5 -4
- package/es/style/themes/theme-sbanken/properties.js +2 -2
- package/es/style/themes/theme-sbanken/properties.js.map +1 -1
- package/es/style/themes/theme-sbanken/sbanken-theme-basis.css +3 -2
- package/es/style/themes/theme-sbanken/sbanken-theme-basis.min.css +1 -1
- package/es/style/themes/theme-sbanken/sbanken-theme-components.css +8 -7
- package/es/style/themes/theme-sbanken/sbanken-theme-components.min.css +4 -4
- package/es/style/themes/theme-sbanken/theme-mapping.scss +2 -1
- package/es/style/themes/theme-ui/ui-theme-components.css +2 -2
- package/es/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +1 -1
- package/esm/dnb-ui-extensions.min.mjs +2 -2
- package/esm/dnb-ui-lib.min.mjs +1 -1
- package/extensions/forms/DataContext/At/At.js +2 -0
- package/extensions/forms/DataContext/At/At.js.map +1 -1
- package/extensions/forms/DataContext/Provider/Provider.js +6 -3
- package/extensions/forms/DataContext/Provider/Provider.js.map +1 -1
- package/extensions/forms/Field/ArraySelection/ArraySelection.js +12 -9
- package/extensions/forms/Field/ArraySelection/ArraySelection.js.map +1 -1
- package/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js +6 -3
- package/extensions/forms/Field/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/extensions/forms/Field/Boolean/Boolean.js +4 -2
- package/extensions/forms/Field/Boolean/Boolean.js.map +1 -1
- package/extensions/forms/Field/Currency/Currency.js +3 -2
- package/extensions/forms/Field/Currency/Currency.js.map +1 -1
- package/extensions/forms/Field/Date/Date.js +3 -1
- package/extensions/forms/Field/Date/Date.js.map +1 -1
- package/extensions/forms/Field/Email/Email.js +6 -3
- package/extensions/forms/Field/Email/Email.js.map +1 -1
- package/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js +6 -3
- package/extensions/forms/Field/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/extensions/forms/Field/Number/Number.js +3 -2
- package/extensions/forms/Field/Number/Number.js.map +1 -1
- package/extensions/forms/Field/Option/Option.js +1 -1
- package/extensions/forms/Field/Option/Option.js.map +1 -1
- package/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js +6 -3
- package/extensions/forms/Field/OrganizationNumber/OrganizationNumber.js.map +1 -1
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.d.ts +5 -0
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.js +59 -18
- package/extensions/forms/Field/PhoneNumber/PhoneNumber.js.map +1 -1
- package/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js +7 -4
- package/extensions/forms/Field/PostalCodeAndCity/PostalCodeAndCity.js.map +1 -1
- package/extensions/forms/Field/SelectCountry/SelectCountry.js +13 -8
- package/extensions/forms/Field/SelectCountry/SelectCountry.js.map +1 -1
- package/extensions/forms/Field/Selection/Selection.js +30 -20
- package/extensions/forms/Field/Selection/Selection.js.map +1 -1
- package/extensions/forms/Field/String/String.js +11 -9
- package/extensions/forms/Field/String/String.js.map +1 -1
- package/extensions/forms/Field/Toggle/Toggle.js +6 -4
- package/extensions/forms/Field/Toggle/Toggle.js.map +1 -1
- package/extensions/forms/FieldBlock/FieldBlock.js +2 -0
- package/extensions/forms/FieldBlock/FieldBlock.js.map +1 -1
- package/extensions/forms/Form/SubmitButton/SubmitButton.js +2 -0
- package/extensions/forms/Form/SubmitButton/SubmitButton.js.map +1 -1
- package/extensions/forms/Iterate/Array/Array.js +2 -2
- package/extensions/forms/Iterate/Array/Array.js.map +1 -1
- package/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js +4 -2
- package/extensions/forms/Iterate/ArrayPushButton/ArrayPushButton.js.map +1 -1
- package/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js +3 -1
- package/extensions/forms/Iterate/ArrayRemoveElementButton/ArrayRemoveElementButton.js.map +1 -1
- package/extensions/forms/StepsLayout/NextButton/NextButton.js +2 -0
- package/extensions/forms/StepsLayout/NextButton/NextButton.js.map +1 -1
- package/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js +2 -0
- package/extensions/forms/StepsLayout/PreviousButton/PreviousButton.js.map +1 -1
- package/extensions/forms/StepsLayout/Step/Step.js +2 -0
- package/extensions/forms/StepsLayout/Step/Step.js.map +1 -1
- package/extensions/forms/StepsLayout/StepsLayout.js +4 -1
- package/extensions/forms/StepsLayout/StepsLayout.js.map +1 -1
- package/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js +4 -1
- package/extensions/forms/Value/BankAccountNumber/BankAccountNumber.js.map +1 -1
- package/extensions/forms/Value/Boolean/Boolean.js +2 -0
- package/extensions/forms/Value/Boolean/Boolean.js.map +1 -1
- package/extensions/forms/Value/Currency/Currency.js +3 -2
- package/extensions/forms/Value/Currency/Currency.js.map +1 -1
- package/extensions/forms/Value/Date/Date.js +4 -1
- package/extensions/forms/Value/Date/Date.js.map +1 -1
- package/extensions/forms/Value/Email/Email.js +4 -1
- package/extensions/forms/Value/Email/Email.js.map +1 -1
- package/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js +4 -1
- package/extensions/forms/Value/NationalIdentityNumber/NationalIdentityNumber.js.map +1 -1
- package/extensions/forms/Value/PhoneNumber/PhoneNumber.js +4 -1
- package/extensions/forms/Value/PhoneNumber/PhoneNumber.js.map +1 -1
- package/extensions/forms/ValueBlock/ValueBlock.js +1 -1
- package/extensions/forms/ValueBlock/ValueBlock.js.map +1 -1
- package/extensions/forms/Visibility/Visibility.js +2 -0
- package/extensions/forms/Visibility/Visibility.js.map +1 -1
- package/extensions/forms/hooks/useDataValue.js +22 -17
- package/extensions/forms/hooks/useDataValue.js.map +1 -1
- package/extensions/forms/types.js +6 -6
- package/extensions/forms/types.js.map +1 -1
- package/extensions/forms/utils/ajv.js +3 -2
- package/extensions/forms/utils/ajv.js.map +1 -1
- package/extensions/forms/utils/numbers.js +2 -2
- package/extensions/forms/utils/numbers.js.map +1 -1
- package/extensions/forms/utils/useWasChanged.js +9 -6
- package/extensions/forms/utils/useWasChanged.js.map +1 -1
- package/fragments/drawer-list/DrawerListHelpers.js +1 -1
- package/fragments/drawer-list/DrawerListHelpers.js.map +1 -1
- package/fragments/drawer-list/DrawerListProvider.js.map +1 -1
- package/fragments/drawer-list/style/themes/dnb-drawer-list-theme-sbanken.scss +1 -1
- package/fragments/drawer-list/style/themes/dnb-drawer-list-theme-ui.scss +2 -2
- package/package.json +11 -1
- package/shared/Eufemia.d.ts +1 -1
- package/shared/Eufemia.js +2 -2
- package/shared/Eufemia.js.map +1 -1
- package/style/dnb-ui-components.css +2 -2
- package/style/dnb-ui-components.min.css +1 -1
- package/style/themes/theme-eiendom/eiendom-theme-components.css +2 -2
- package/style/themes/theme-eiendom/eiendom-theme-components.min.css +1 -1
- package/style/themes/theme-sbanken/fonts.scss +5 -4
- package/style/themes/theme-sbanken/properties.js +2 -2
- package/style/themes/theme-sbanken/properties.js.map +1 -1
- package/style/themes/theme-sbanken/sbanken-theme-basis.css +3 -2
- package/style/themes/theme-sbanken/sbanken-theme-basis.min.css +1 -1
- package/style/themes/theme-sbanken/sbanken-theme-components.css +8 -7
- package/style/themes/theme-sbanken/sbanken-theme-components.min.css +4 -4
- package/style/themes/theme-sbanken/theme-mapping.scss +2 -1
- package/style/themes/theme-ui/ui-theme-components.css +2 -2
- package/style/themes/theme-ui/ui-theme-components.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +1 -1
- package/umd/dnb-ui-extensions.min.js +2 -2
- package/umd/dnb-ui-lib.min.js +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -10,7 +12,7 @@ import FieldBlockContext from '../FieldBlock/FieldBlockContext';
|
|
|
10
12
|
import IterateElementContext from '../Iterate/IterateElementContext';
|
|
11
13
|
import { makeUniqueId } from '../../../shared/component-helper';
|
|
12
14
|
export default function useDataValue(props) {
|
|
13
|
-
var _props$path;
|
|
15
|
+
var _props$path, _props$autoComplete;
|
|
14
16
|
const {
|
|
15
17
|
path,
|
|
16
18
|
elementPath,
|
|
@@ -30,7 +32,10 @@ export default function useDataValue(props) {
|
|
|
30
32
|
toInput = value => value,
|
|
31
33
|
fromInput = value => value
|
|
32
34
|
} = props;
|
|
33
|
-
const id = useMemo(() =>
|
|
35
|
+
const id = useMemo(() => {
|
|
36
|
+
var _props$id;
|
|
37
|
+
return (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : makeUniqueId();
|
|
38
|
+
}, [props.id]);
|
|
34
39
|
const dataContext = useContext(Context);
|
|
35
40
|
const fieldBlockContext = useContext(FieldBlockContext);
|
|
36
41
|
const iterateElementContext = useContext(IterateElementContext);
|
|
@@ -38,18 +43,18 @@ export default function useDataValue(props) {
|
|
|
38
43
|
handlePathChange: dataContextHandlePathChange,
|
|
39
44
|
setPathWithError: dataContextSetPathWithError,
|
|
40
45
|
errors: dataContextErrors
|
|
41
|
-
} = dataContext
|
|
46
|
+
} = dataContext !== null && dataContext !== void 0 ? dataContext : {};
|
|
42
47
|
const inFieldBlock = Boolean(fieldBlockContext);
|
|
43
48
|
const {
|
|
44
49
|
setError: setFieldBlockError,
|
|
45
50
|
setShowError: setShowFieldBlockError
|
|
46
|
-
} = fieldBlockContext
|
|
51
|
+
} = fieldBlockContext !== null && fieldBlockContext !== void 0 ? fieldBlockContext : {};
|
|
47
52
|
const inIterate = Boolean(iterateElementContext);
|
|
48
53
|
const {
|
|
49
54
|
index: iterateElementIndex,
|
|
50
55
|
value: iterateElementValue,
|
|
51
56
|
handleChange: handleIterateElementChange
|
|
52
|
-
} = iterateElementContext
|
|
57
|
+
} = iterateElementContext !== null && iterateElementContext !== void 0 ? iterateElementContext : {};
|
|
53
58
|
if (path && path.substring(0, 1) !== '/') {
|
|
54
59
|
throw new Error('Invalid path. Data value path JSON Pointers must be from root (starting with a /).');
|
|
55
60
|
}
|
|
@@ -92,7 +97,7 @@ export default function useDataValue(props) {
|
|
|
92
97
|
if (path) {
|
|
93
98
|
dataContextSetPathWithError === null || dataContextSetPathWithError === void 0 ? void 0 : dataContextSetPathWithError(path, Boolean(error));
|
|
94
99
|
}
|
|
95
|
-
setFieldBlockError === null || setFieldBlockError === void 0 ? void 0 : setFieldBlockError(path
|
|
100
|
+
setFieldBlockError === null || setFieldBlockError === void 0 ? void 0 : setFieldBlockError(path !== null && path !== void 0 ? path : id, errorWithCorrectMessage);
|
|
96
101
|
}, [path, id, errorMessages, dataContextSetPathWithError, setFieldBlockError]);
|
|
97
102
|
const validateValue = useCallback(valueToValidate => {
|
|
98
103
|
if (typeof validator === 'function') {
|
|
@@ -126,24 +131,24 @@ export default function useDataValue(props) {
|
|
|
126
131
|
useEffect(() => {
|
|
127
132
|
if (dataContext.showAllErrors) {
|
|
128
133
|
setShowError(true);
|
|
129
|
-
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path
|
|
134
|
+
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path !== null && path !== void 0 ? path : id, true);
|
|
130
135
|
}
|
|
131
136
|
}, [id, path, dataContext.showAllErrors, setShowFieldBlockError]);
|
|
132
137
|
const setHasFocus = useCallback((hasFocus, valueOverride) => {
|
|
133
138
|
if (hasFocus) {
|
|
134
139
|
hasFocusRef.current = true;
|
|
135
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus(valueOverride
|
|
140
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(valueOverride !== null && valueOverride !== void 0 ? valueOverride : value);
|
|
136
141
|
} else {
|
|
137
142
|
hasFocusRef.current = false;
|
|
138
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur(valueOverride
|
|
143
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(valueOverride !== null && valueOverride !== void 0 ? valueOverride : value);
|
|
139
144
|
if (!changedRef.current && !validateUnchanged) {
|
|
140
145
|
return;
|
|
141
146
|
}
|
|
142
147
|
if (typeof onBlurValidator === 'function') {
|
|
143
|
-
Promise.resolve(onBlurValidator(valueOverride
|
|
148
|
+
Promise.resolve(onBlurValidator(valueOverride !== null && valueOverride !== void 0 ? valueOverride : value)).then(setErrorAndUpdateDataContext);
|
|
144
149
|
}
|
|
145
150
|
setShowError(true);
|
|
146
|
-
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path
|
|
151
|
+
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path !== null && path !== void 0 ? path : id, true);
|
|
147
152
|
}
|
|
148
153
|
}, [id, path, value, validateUnchanged, onFocus, onBlur, onBlurValidator, setErrorAndUpdateDataContext, setShowFieldBlockError]);
|
|
149
154
|
const handleFocus = useCallback(() => setHasFocus(true), [setHasFocus]);
|
|
@@ -157,10 +162,10 @@ export default function useDataValue(props) {
|
|
|
157
162
|
changedRef.current = true;
|
|
158
163
|
if (continuousValidation || continuousValidation !== false && !hasFocusRef.current) {
|
|
159
164
|
setShowError(true);
|
|
160
|
-
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path
|
|
165
|
+
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path !== null && path !== void 0 ? path : id, true);
|
|
161
166
|
} else {
|
|
162
167
|
setShowError(false);
|
|
163
|
-
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path
|
|
168
|
+
setShowFieldBlockError === null || setShowFieldBlockError === void 0 ? void 0 : setShowFieldBlockError(path !== null && path !== void 0 ? path : id, false);
|
|
164
169
|
}
|
|
165
170
|
validateValue(newValue);
|
|
166
171
|
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
@@ -168,11 +173,11 @@ export default function useDataValue(props) {
|
|
|
168
173
|
dataContextHandlePathChange === null || dataContextHandlePathChange === void 0 ? void 0 : dataContextHandlePathChange(path, newValue);
|
|
169
174
|
}
|
|
170
175
|
if (elementPath) {
|
|
171
|
-
const
|
|
172
|
-
handleIterateElementChange === null || handleIterateElementChange === void 0 ? void 0 : handleIterateElementChange(
|
|
176
|
+
const iterateValuePath = `/${iterateElementIndex}${elementPath && elementPath !== '/' ? elementPath : ''}`;
|
|
177
|
+
handleIterateElementChange === null || handleIterateElementChange === void 0 ? void 0 : handleIterateElementChange(iterateValuePath, newValue);
|
|
173
178
|
}
|
|
174
179
|
}, [id, path, elementPath, iterateElementIndex, value, continuousValidation, onChange, validateValue, dataContextHandlePathChange, setShowFieldBlockError, handleIterateElementChange, fromInput]);
|
|
175
|
-
const exportError = useMemo(() => errorProp
|
|
180
|
+
const exportError = useMemo(() => errorProp !== null && errorProp !== void 0 ? errorProp : error, [errorProp, error]);
|
|
176
181
|
useEffect(() => {
|
|
177
182
|
if (path) {
|
|
178
183
|
dataContext === null || dataContext === void 0 ? void 0 : dataContext.handleMountField(path);
|
|
@@ -189,7 +194,7 @@ export default function useDataValue(props) {
|
|
|
189
194
|
name: props.name || ((_props$path = props.path) === null || _props$path === void 0 ? void 0 : _props$path.replace('/', '')) || id,
|
|
190
195
|
value: toInput(value),
|
|
191
196
|
error: inFieldBlock ? undefined : showError ? exportError : undefined,
|
|
192
|
-
autoComplete: props.autoComplete
|
|
197
|
+
autoComplete: (_props$autoComplete = props.autoComplete) !== null && _props$autoComplete !== void 0 ? _props$autoComplete : dataContext.autoComplete === true ? 'on' : 'off',
|
|
193
198
|
setHasFocus,
|
|
194
199
|
handleFocus,
|
|
195
200
|
handleBlur,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDataValue.js","names":["useRef","useEffect","useContext","useCallback","useMemo","useState","pointer","FormError","ajv","ajvErrorsToOneFormError","Context","FieldBlockContext","IterateElementContext","makeUniqueId","useDataValue","props","_props$path","path","elementPath","emptyValue","required","error","errorProp","onFocus","onBlur","onChange","validator","onBlurValidator","schema","errorMessages","validateInitially","validateUnchanged","continuousValidation","toInput","value","fromInput","id","dataContext","fieldBlockContext","iterateElementContext","handlePathChange","dataContextHandlePathChange","setPathWithError","dataContextSetPathWithError","errors","dataContextErrors","inFieldBlock","Boolean","setError","setFieldBlockError","setShowError","setShowFieldBlockError","inIterate","index","iterateElementIndex","iterateElementValue","handleChange","handleIterateElementChange","substring","Error","externalValue","undefined","has","get","data","setValue","changedRef","hasFocusRef","showError","schemaValidator","Object","keys","length","compile","setErrorAndUpdateDataContext","errorWithCorrectMessage","validationRule","validateValue","valueToValidate","Promise","resolve","then","showAllErrors","setHasFocus","hasFocus","valueOverride","current","handleFocus","handleBlur","argFromInput","newValue","iteratValuePath","exportError","handleMountField","handleUnMountField","_objectSpread","name","replace","autoComplete"],"sources":["../../../../../src/extensions/forms/hooks/useDataValue.ts"],"sourcesContent":["import {\n useRef,\n useEffect,\n useContext,\n useCallback,\n useMemo,\n useState,\n} from 'react'\nimport pointer from 'json-pointer'\nimport { FormError, FieldProps } from '../types'\nimport ajv, { ajvErrorsToOneFormError } from '../utils/ajv'\nimport { Context } from '../DataContext'\nimport FieldBlockContext from '../FieldBlock/FieldBlockContext'\nimport IterateElementContext from '../Iterate/IterateElementContext'\nimport { makeUniqueId } from '../../../shared/component-helper'\n\ninterface ReturnAdditional<Value> {\n id: string\n value: Value\n error: Error | FormError | undefined\n setHasFocus: (hasFocus: boolean, valueOverride?: unknown) => void\n handleFocus: () => void\n handleBlur: () => void\n handleChange: FieldProps<unknown>['onChange']\n}\n\nexport default function useDataValue<\n Value = unknown,\n Props extends FieldProps<Value> = FieldProps<Value>,\n>(props: Props): Props & ReturnAdditional<Value> {\n const {\n path,\n elementPath,\n emptyValue,\n required,\n error: errorProp,\n onFocus,\n onBlur,\n onChange,\n validator,\n onBlurValidator,\n schema,\n errorMessages,\n validateInitially,\n validateUnchanged,\n continuousValidation,\n toInput = (value) => value,\n fromInput = (value) => value,\n } = props\n const id = useMemo(() => props.id ?? makeUniqueId(), [props.id])\n const dataContext = useContext(Context)\n const fieldBlockContext = useContext(FieldBlockContext)\n const iterateElementContext = useContext(IterateElementContext)\n\n const {\n handlePathChange: dataContextHandlePathChange,\n setPathWithError: dataContextSetPathWithError,\n errors: dataContextErrors,\n } = dataContext ?? {}\n const inFieldBlock = Boolean(fieldBlockContext)\n const {\n setError: setFieldBlockError,\n setShowError: setShowFieldBlockError,\n } = fieldBlockContext ?? {}\n const inIterate = Boolean(iterateElementContext)\n const {\n index: iterateElementIndex,\n value: iterateElementValue,\n handleChange: handleIterateElementChange,\n } = iterateElementContext ?? {}\n\n if (path && path.substring(0, 1) !== '/') {\n throw new Error(\n 'Invalid path. Data value path JSON Pointers must be from root (starting with a /).'\n )\n }\n if (elementPath && elementPath.substring(0, 1) !== '/') {\n throw new Error(\n 'Invalid elementPath. Element pathJSON Pointers must be from root of iterate element (starting with a /).'\n )\n }\n if (elementPath && !iterateElementContext) {\n throw new Error(\n 'elementPath cannot be used when not inside an iterate element context. Wrap the component in an Iterate.Loop.'\n )\n }\n\n const externalValue = useMemo(() => {\n if (props.value !== undefined) {\n // Value-prop sent directly to the field has highest priority, overriding any surrounding source\n return props.value\n }\n\n if (inIterate && elementPath) {\n // This field is inside an iterate, and has a pointer from the base of the element being iterated\n if (elementPath === '/') {\n return iterateElementValue\n }\n\n return pointer.has(iterateElementValue, elementPath)\n ? pointer.get(iterateElementValue, elementPath)\n : undefined\n }\n\n if (dataContext.data && path) {\n // There is a surrounding data context and a path for where in the source to find the data\n if (path === '/') {\n return dataContext.data\n }\n\n return pointer.has(dataContext.data, path)\n ? pointer.get(dataContext.data, path)\n : undefined\n }\n return undefined\n }, [\n path,\n elementPath,\n inIterate,\n iterateElementValue,\n props.value,\n dataContext.data,\n ])\n\n // Hold an internal copy of the input value in case the input component is used uncontrolled,\n // and to handle errors in Eufemia on components that does not take updated callback functions into account.\n const [value, setValue] = useState(externalValue)\n const changedRef = useRef(false)\n const hasFocusRef = useRef(false)\n\n useEffect(() => {\n // When receiving the initial value, or receiving an updated value by props, update the internal value\n // so the component can be used \"controlled\".\n setValue(externalValue)\n }, [externalValue])\n\n // Error handling\n const [error, setError] = useState<Error | FormError | undefined>()\n const [showError, setShowError] = useState<boolean>(\n Boolean(validateInitially || errorProp)\n )\n const schemaValidator = useMemo(\n () =>\n schema && Object.keys(schema).length > 0\n ? ajv.compile(schema)\n : undefined,\n [schema]\n )\n\n const setErrorAndUpdateDataContext = useCallback(\n (error: FormError | undefined) => {\n const errorWithCorrectMessage =\n error instanceof FormError &&\n typeof error.validationRule === 'string' &&\n errorMessages?.[error.validationRule] !== undefined\n ? new FormError(errorMessages[error.validationRule])\n : error\n\n setError(errorWithCorrectMessage)\n\n if (path) {\n // Tell the data context about the error, so it can stop the user from submitting the form until the error has been fixed\n dataContextSetPathWithError?.(path, Boolean(error))\n }\n\n setFieldBlockError?.(path ?? id, errorWithCorrectMessage)\n },\n [\n path,\n id,\n errorMessages,\n dataContextSetPathWithError,\n setFieldBlockError,\n ]\n )\n\n const validateValue = useCallback(\n (valueToValidate): FormError | undefined => {\n // Prioritize received validator functions first\n // Possible future change: Merge errors if multiple, like one message with each message concatinated.\n if (typeof validator === 'function') {\n // Since the validator can return either a synchronous result or an asynchronous\n Promise.resolve(validator(valueToValidate))\n // This is a validator, so it is expected to resolve with an error when the value is invalid. If it\n // throws an error, it is not caught here as that will cause programmatic errors to show inside the form\n // as if they were operational errors.\n .then(setErrorAndUpdateDataContext)\n }\n\n if (valueToValidate === emptyValue && required) {\n const error = new FormError('The value is required', {\n validationRule: 'required',\n })\n setErrorAndUpdateDataContext(error)\n return error\n } else if (schemaValidator) {\n // This input has a direct schema (through props)\n if (valueToValidate === undefined && emptyValue === undefined) {\n // Avoid validating undefined-values if they are expected (set with emptyValue) as they will\n // usually fail against json-schema type\n setErrorAndUpdateDataContext(undefined)\n return undefined\n }\n schemaValidator(valueToValidate)\n const error = ajvErrorsToOneFormError(schemaValidator.errors)\n setErrorAndUpdateDataContext(error)\n return error\n } else {\n // Removing any previous error from required\n setErrorAndUpdateDataContext(undefined)\n return undefined\n }\n },\n [\n schemaValidator,\n emptyValue,\n required,\n setErrorAndUpdateDataContext,\n validator,\n ]\n )\n\n useEffect(() => {\n // If a surrounding data context has an error for this field (by path) and no error has been set by local component validation, use the data context error\n if (!error && path && dataContextErrors?.[path]) {\n setErrorAndUpdateDataContext(dataContextErrors[path])\n }\n }, [path, dataContextErrors, error, setErrorAndUpdateDataContext])\n\n useEffect(() => {\n if (dataContext.showAllErrors) {\n // If showError on a surrounding data context was changed and set to true, it is because the user clicked next, submit or\n // something else that should lead to showing the user all errors.\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n }\n }, [id, path, dataContext.showAllErrors, setShowFieldBlockError])\n\n const setHasFocus = useCallback(\n (hasFocus: boolean, valueOverride?: unknown) => {\n if (hasFocus) {\n // Field was put in focus (like when clicking in a text field or opening a dropdown menu)\n hasFocusRef.current = true\n onFocus?.(valueOverride ?? value)\n } else {\n // Field was removed from focus (like when tabbing out of a text field or closing a dropdown menu)\n hasFocusRef.current = false\n onBlur?.(valueOverride ?? value)\n\n if (!changedRef.current && !validateUnchanged) {\n // Avoid showing errors when blurring without havinc hanged the value, so tabbing through several\n // fields does not make errors pop up all over the place\n return\n }\n\n // External blur validators makes it possible to validate values but not on every character change in case of\n // expensive validation calling external services etc.\n if (typeof onBlurValidator === 'function') {\n // Since the validator can return either a synchronous result or an asynchronous\n Promise.resolve(onBlurValidator(valueOverride ?? value))\n // This is a validator, so it is expected to resolve with an error when the value is invalid. If it\n // throws an error, it is not caught here as that will cause programmatic errors to show inside the form\n // as if they were operational errors.\n .then(setErrorAndUpdateDataContext)\n }\n\n // Since the user left the field, show error (if any)\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n }\n },\n [\n id,\n path,\n value,\n validateUnchanged,\n onFocus,\n onBlur,\n onBlurValidator,\n setErrorAndUpdateDataContext,\n setShowFieldBlockError,\n ]\n )\n\n const handleFocus = useCallback(() => setHasFocus(true), [setHasFocus])\n const handleBlur = useCallback(() => setHasFocus(false), [setHasFocus])\n\n const handleChange = useCallback(\n (argFromInput) => {\n const newValue = fromInput(argFromInput)\n\n if (newValue === value) {\n // Avoid triggering a change if the value was not actually changed. This may be caused by rendering components\n // calling onChange even if the actual value did not change.\n return\n }\n setValue(newValue)\n changedRef.current = true\n\n if (\n continuousValidation ||\n (continuousValidation !== false && !hasFocusRef.current)\n ) {\n // When there is a change to the value without there having been any focus callback beforehand, it is likely\n // to believe that the blur callback will not be called either, which would trigger the display of the error.\n // The error is therefore displayed immediately (unless instructed not to with continuousValidation set to false).\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n } else {\n // When changing the value, hide errors to avoid annoying the user before they are finished filling in that value\n setShowError(false)\n setShowFieldBlockError?.(path ?? id, false)\n }\n // Always validate the value immediately when it is changed\n validateValue(newValue)\n\n onChange?.(newValue)\n if (path) {\n dataContextHandlePathChange?.(path, newValue)\n }\n if (elementPath) {\n const iteratValuePath = `/${iterateElementIndex}${\n elementPath && elementPath !== '/' ? elementPath : ''\n }`\n handleIterateElementChange?.(iteratValuePath, newValue)\n }\n },\n [\n id,\n path,\n elementPath,\n iterateElementIndex,\n value,\n continuousValidation,\n onChange,\n validateValue,\n dataContextHandlePathChange,\n setShowFieldBlockError,\n handleIterateElementChange,\n fromInput,\n ]\n )\n\n const exportError = useMemo(() => errorProp ?? error, [errorProp, error])\n\n useEffect(() => {\n // Mount procedure\n if (path) {\n dataContext?.handleMountField(path)\n }\n validateValue(externalValue)\n\n return () => {\n // Unmount procedure\n if (path) {\n dataContext?.handleUnMountField(path)\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- Only run for mount and unmount\n }, [])\n\n return {\n ...props,\n id,\n name: props.name || props.path?.replace('/', '') || id,\n value: toInput(value),\n error: inFieldBlock ? undefined : showError ? exportError : undefined,\n autoComplete:\n props.autoComplete ??\n (dataContext.autoComplete === true ? 'on' : 'off'),\n setHasFocus,\n handleFocus,\n handleBlur,\n handleChange,\n }\n}\n"],"mappings":";;;AAAA,SACEA,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,OAAO,EACPC,QAAQ,QACH,OAAO;AACd,OAAOC,OAAO,MAAM,cAAc;AAClC,SAASC,SAAS,QAAoB,UAAU;AAChD,OAAOC,GAAG,IAAIC,uBAAuB,QAAQ,cAAc;AAC3D,SAASC,OAAO,QAAQ,gBAAgB;AACxC,OAAOC,iBAAiB,MAAM,iCAAiC;AAC/D,OAAOC,qBAAqB,MAAM,kCAAkC;AAC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Y,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IACpDf,WAAW;IACXI,WAAW;IACXC,UAAU;IACVhC;EAAY;AAEhB"}
|
|
1
|
+
{"version":3,"file":"useDataValue.js","names":["useRef","useEffect","useContext","useCallback","useMemo","useState","pointer","FormError","ajv","ajvErrorsToOneFormError","Context","FieldBlockContext","IterateElementContext","makeUniqueId","useDataValue","props","_props$path","_props$autoComplete","path","elementPath","emptyValue","required","error","errorProp","onFocus","onBlur","onChange","validator","onBlurValidator","schema","errorMessages","validateInitially","validateUnchanged","continuousValidation","toInput","value","fromInput","id","_props$id","dataContext","fieldBlockContext","iterateElementContext","handlePathChange","dataContextHandlePathChange","setPathWithError","dataContextSetPathWithError","errors","dataContextErrors","inFieldBlock","Boolean","setError","setFieldBlockError","setShowError","setShowFieldBlockError","inIterate","index","iterateElementIndex","iterateElementValue","handleChange","handleIterateElementChange","substring","Error","externalValue","undefined","has","get","data","setValue","changedRef","hasFocusRef","showError","schemaValidator","Object","keys","length","compile","setErrorAndUpdateDataContext","errorWithCorrectMessage","validationRule","validateValue","valueToValidate","Promise","resolve","then","showAllErrors","setHasFocus","hasFocus","valueOverride","current","handleFocus","handleBlur","argFromInput","newValue","iterateValuePath","exportError","handleMountField","handleUnMountField","_objectSpread","name","replace","autoComplete"],"sources":["../../../../../src/extensions/forms/hooks/useDataValue.ts"],"sourcesContent":["import {\n useRef,\n useEffect,\n useContext,\n useCallback,\n useMemo,\n useState,\n} from 'react'\nimport pointer from 'json-pointer'\nimport { FormError, FieldProps } from '../types'\nimport ajv, { ajvErrorsToOneFormError } from '../utils/ajv'\nimport { Context } from '../DataContext'\nimport FieldBlockContext from '../FieldBlock/FieldBlockContext'\nimport IterateElementContext from '../Iterate/IterateElementContext'\nimport { makeUniqueId } from '../../../shared/component-helper'\n\ninterface ReturnAdditional<Value> {\n id: string\n value: Value\n error: Error | FormError | undefined\n setHasFocus: (hasFocus: boolean, valueOverride?: unknown) => void\n handleFocus: () => void\n handleBlur: () => void\n handleChange: FieldProps<unknown>['onChange']\n}\n\nexport default function useDataValue<\n Value = unknown,\n Props extends FieldProps<Value> = FieldProps<Value>,\n>(props: Props): Props & ReturnAdditional<Value> {\n const {\n path,\n elementPath,\n emptyValue,\n required,\n error: errorProp,\n onFocus,\n onBlur,\n onChange,\n validator,\n onBlurValidator,\n schema,\n errorMessages,\n validateInitially,\n validateUnchanged,\n continuousValidation,\n toInput = (value) => value,\n fromInput = (value) => value,\n } = props\n const id = useMemo(() => props.id ?? makeUniqueId(), [props.id])\n const dataContext = useContext(Context)\n const fieldBlockContext = useContext(FieldBlockContext)\n const iterateElementContext = useContext(IterateElementContext)\n\n const {\n handlePathChange: dataContextHandlePathChange,\n setPathWithError: dataContextSetPathWithError,\n errors: dataContextErrors,\n } = dataContext ?? {}\n const inFieldBlock = Boolean(fieldBlockContext)\n const {\n setError: setFieldBlockError,\n setShowError: setShowFieldBlockError,\n } = fieldBlockContext ?? {}\n const inIterate = Boolean(iterateElementContext)\n const {\n index: iterateElementIndex,\n value: iterateElementValue,\n handleChange: handleIterateElementChange,\n } = iterateElementContext ?? {}\n\n if (path && path.substring(0, 1) !== '/') {\n throw new Error(\n 'Invalid path. Data value path JSON Pointers must be from root (starting with a /).'\n )\n }\n if (elementPath && elementPath.substring(0, 1) !== '/') {\n throw new Error(\n 'Invalid elementPath. Element pathJSON Pointers must be from root of iterate element (starting with a /).'\n )\n }\n if (elementPath && !iterateElementContext) {\n throw new Error(\n 'elementPath cannot be used when not inside an iterate element context. Wrap the component in an Iterate.Loop.'\n )\n }\n\n const externalValue = useMemo(() => {\n if (props.value !== undefined) {\n // Value-prop sent directly to the field has highest priority, overriding any surrounding source\n return props.value\n }\n\n if (inIterate && elementPath) {\n // This field is inside an iterate, and has a pointer from the base of the element being iterated\n if (elementPath === '/') {\n return iterateElementValue\n }\n\n return pointer.has(iterateElementValue, elementPath)\n ? pointer.get(iterateElementValue, elementPath)\n : undefined\n }\n\n if (dataContext.data && path) {\n // There is a surrounding data context and a path for where in the source to find the data\n if (path === '/') {\n return dataContext.data\n }\n\n return pointer.has(dataContext.data, path)\n ? pointer.get(dataContext.data, path)\n : undefined\n }\n return undefined\n }, [\n path,\n elementPath,\n inIterate,\n iterateElementValue,\n props.value,\n dataContext.data,\n ])\n\n // Hold an internal copy of the input value in case the input component is used uncontrolled,\n // and to handle errors in Eufemia on components that does not take updated callback functions into account.\n const [value, setValue] = useState(externalValue)\n const changedRef = useRef(false)\n const hasFocusRef = useRef(false)\n\n useEffect(() => {\n // When receiving the initial value, or receiving an updated value by props, update the internal value\n // so the component can be used \"controlled\".\n setValue(externalValue)\n }, [externalValue])\n\n // Error handling\n const [error, setError] = useState<Error | FormError | undefined>()\n const [showError, setShowError] = useState<boolean>(\n Boolean(validateInitially || errorProp)\n )\n const schemaValidator = useMemo(\n () =>\n schema && Object.keys(schema).length > 0\n ? ajv.compile(schema)\n : undefined,\n [schema]\n )\n\n const setErrorAndUpdateDataContext = useCallback(\n (error: FormError | undefined) => {\n const errorWithCorrectMessage =\n error instanceof FormError &&\n typeof error.validationRule === 'string' &&\n errorMessages?.[error.validationRule] !== undefined\n ? new FormError(errorMessages[error.validationRule])\n : error\n\n setError(errorWithCorrectMessage)\n\n if (path) {\n // Tell the data context about the error, so it can stop the user from submitting the form until the error has been fixed\n dataContextSetPathWithError?.(path, Boolean(error))\n }\n\n setFieldBlockError?.(path ?? id, errorWithCorrectMessage)\n },\n [\n path,\n id,\n errorMessages,\n dataContextSetPathWithError,\n setFieldBlockError,\n ]\n )\n\n const validateValue = useCallback(\n (valueToValidate): FormError | undefined => {\n // Prioritize received validator functions first\n // Possible future change: Merge errors if multiple, like one message with each message concatenated.\n if (typeof validator === 'function') {\n // Since the validator can return either a synchronous result or an asynchronous\n Promise.resolve(validator(valueToValidate))\n // This is a validator, so it is expected to resolve with an error when the value is invalid. If it\n // throws an error, it is not caught here as that will cause programmatic errors to show inside the form\n // as if they were operational errors.\n .then(setErrorAndUpdateDataContext)\n }\n\n if (valueToValidate === emptyValue && required) {\n const error = new FormError('The value is required', {\n validationRule: 'required',\n })\n setErrorAndUpdateDataContext(error)\n return error\n } else if (schemaValidator) {\n // This input has a direct schema (through props)\n if (valueToValidate === undefined && emptyValue === undefined) {\n // Avoid validating undefined-values if they are expected (set with emptyValue) as they will\n // usually fail against json-schema type\n setErrorAndUpdateDataContext(undefined)\n return undefined\n }\n schemaValidator(valueToValidate)\n const error = ajvErrorsToOneFormError(schemaValidator.errors)\n setErrorAndUpdateDataContext(error)\n return error\n } else {\n // Removing any previous error from required\n setErrorAndUpdateDataContext(undefined)\n return undefined\n }\n },\n [\n schemaValidator,\n emptyValue,\n required,\n setErrorAndUpdateDataContext,\n validator,\n ]\n )\n\n useEffect(() => {\n // If a surrounding data context has an error for this field (by path) and no error has been set by local component validation, use the data context error\n if (!error && path && dataContextErrors?.[path]) {\n setErrorAndUpdateDataContext(dataContextErrors[path])\n }\n }, [path, dataContextErrors, error, setErrorAndUpdateDataContext])\n\n useEffect(() => {\n if (dataContext.showAllErrors) {\n // If showError on a surrounding data context was changed and set to true, it is because the user clicked next, submit or\n // something else that should lead to showing the user all errors.\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n }\n }, [id, path, dataContext.showAllErrors, setShowFieldBlockError])\n\n const setHasFocus = useCallback(\n (hasFocus: boolean, valueOverride?: unknown) => {\n if (hasFocus) {\n // Field was put in focus (like when clicking in a text field or opening a dropdown menu)\n hasFocusRef.current = true\n onFocus?.(valueOverride ?? value)\n } else {\n // Field was removed from focus (like when tabbing out of a text field or closing a dropdown menu)\n hasFocusRef.current = false\n onBlur?.(valueOverride ?? value)\n\n if (!changedRef.current && !validateUnchanged) {\n // Avoid showing errors when blurring without having changed the value, so tabbing through several\n // fields does not make errors pop up all over the place\n return\n }\n\n // External blur validators makes it possible to validate values but not on every character change in case of\n // expensive validation calling external services etc.\n if (typeof onBlurValidator === 'function') {\n // Since the validator can return either a synchronous result or an asynchronous\n Promise.resolve(onBlurValidator(valueOverride ?? value))\n // This is a validator, so it is expected to resolve with an error when the value is invalid. If it\n // throws an error, it is not caught here as that will cause programmatic errors to show inside the form\n // as if they were operational errors.\n .then(setErrorAndUpdateDataContext)\n }\n\n // Since the user left the field, show error (if any)\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n }\n },\n [\n id,\n path,\n value,\n validateUnchanged,\n onFocus,\n onBlur,\n onBlurValidator,\n setErrorAndUpdateDataContext,\n setShowFieldBlockError,\n ]\n )\n\n const handleFocus = useCallback(() => setHasFocus(true), [setHasFocus])\n const handleBlur = useCallback(() => setHasFocus(false), [setHasFocus])\n\n const handleChange = useCallback(\n (argFromInput) => {\n const newValue = fromInput(argFromInput)\n\n if (newValue === value) {\n // Avoid triggering a change if the value was not actually changed. This may be caused by rendering components\n // calling onChange even if the actual value did not change.\n return\n }\n setValue(newValue)\n changedRef.current = true\n\n if (\n continuousValidation ||\n (continuousValidation !== false && !hasFocusRef.current)\n ) {\n // When there is a change to the value without there having been any focus callback beforehand, it is likely\n // to believe that the blur callback will not be called either, which would trigger the display of the error.\n // The error is therefore displayed immediately (unless instructed not to with continuousValidation set to false).\n setShowError(true)\n setShowFieldBlockError?.(path ?? id, true)\n } else {\n // When changing the value, hide errors to avoid annoying the user before they are finished filling in that value\n setShowError(false)\n setShowFieldBlockError?.(path ?? id, false)\n }\n // Always validate the value immediately when it is changed\n validateValue(newValue)\n\n onChange?.(newValue)\n if (path) {\n dataContextHandlePathChange?.(path, newValue)\n }\n if (elementPath) {\n const iterateValuePath = `/${iterateElementIndex}${\n elementPath && elementPath !== '/' ? elementPath : ''\n }`\n handleIterateElementChange?.(iterateValuePath, newValue)\n }\n },\n [\n id,\n path,\n elementPath,\n iterateElementIndex,\n value,\n continuousValidation,\n onChange,\n validateValue,\n dataContextHandlePathChange,\n setShowFieldBlockError,\n handleIterateElementChange,\n fromInput,\n ]\n )\n\n const exportError = useMemo(() => errorProp ?? error, [errorProp, error])\n\n useEffect(() => {\n // Mount procedure\n if (path) {\n dataContext?.handleMountField(path)\n }\n validateValue(externalValue)\n\n return () => {\n // Unmount procedure\n if (path) {\n dataContext?.handleUnMountField(path)\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- Only run for mount and unmount\n }, [])\n\n return {\n ...props,\n id,\n name: props.name || props.path?.replace('/', '') || id,\n value: toInput(value),\n error: inFieldBlock ? undefined : showError ? exportError : undefined,\n autoComplete:\n props.autoComplete ??\n (dataContext.autoComplete === true ? 'on' : 'off'),\n setHasFocus,\n handleFocus,\n handleBlur,\n handleChange,\n }\n}\n"],"mappings":";;;;;AAAA,SACEA,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,OAAO,EACPC,QAAQ,QACH,OAAO;AACd,OAAOC,OAAO,MAAM,cAAc;AAClC,SAASC,SAAS,QAAoB,UAAU;AAChD,OAAOC,GAAG,IAAIC,uBAAuB,QAAQ,cAAc;AAC3D,SAASC,OAAO,QAAQ,gBAAgB;AACxC,OAAOC,iBAAiB,MAAM,iCAAiC;AAC/D,OAAOC,qBAAqB,MAAM,kCAAkC;AACpE,SAASC,YAAY,QAAQ,kCAAkC;AAY/D,eAAe,SAASC,YAAYA,CAGlCC,KAAY,EAAmC;EAAA,IAAAC,WAAA,EAAAC,mBAAA;EAC/C,MAAM;IACJC,IAAI;IACJC,WAAW;IACXC,UAAU;IACVC,QAAQ;IACRC,KAAK,EAAEC,SAAS;IAChBC,OAAO;IACPC,MAAM;IACNC,QAAQ;IACRC,SAAS;IACTC,eAAe;IACfC,MAAM;IACNC,aAAa;IACbC,iBAAiB;IACjBC,iBAAiB;IACjBC,oBAAoB;IACpBC,OAAO,GAAIC,KAAK,IAAKA,KAAK;IAC1BC,SAAS,GAAID,KAAK,IAAKA;EACzB,CAAC,GAAGpB,KAAK;EACT,MAAMsB,EAAE,GAAGjC,OAAO,CAAC;IAAA,IAAAkC,SAAA;IAAA,QAAAA,SAAA,GAAMvB,KAAK,CAACsB,EAAE,cAA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,UAAU;IACVhC;EAAY;AAEhB"}
|
|
@@ -10,22 +10,22 @@ export class FormError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
const dataValueReadProps = ['path', 'elementPath', 'value'];
|
|
12
12
|
export function pickDataValueReadProps(props) {
|
|
13
|
-
return Object.fromEntries(Object.entries(props
|
|
13
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => dataValueReadProps.includes(key)));
|
|
14
14
|
}
|
|
15
15
|
export function omitDataValueReadProps(props) {
|
|
16
|
-
return Object.fromEntries(Object.entries(props
|
|
16
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => !dataValueReadProps.includes(key)));
|
|
17
17
|
}
|
|
18
18
|
const dataValueWriteProps = ['emptyValue', 'onFocus', 'onBlur', 'onChange'];
|
|
19
19
|
export function pickDataValueWriteProps(props) {
|
|
20
|
-
return Object.fromEntries(Object.entries(props
|
|
20
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => dataValueWriteProps.includes(key)));
|
|
21
21
|
}
|
|
22
22
|
export function omitDataValueWriteProps(props) {
|
|
23
|
-
return Object.fromEntries(Object.entries(props
|
|
23
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => !dataValueWriteProps.includes(key)));
|
|
24
24
|
}
|
|
25
25
|
export function pickDataValueReadWriteProps(props) {
|
|
26
|
-
return Object.fromEntries(Object.entries(props
|
|
26
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => dataValueReadProps.includes(key) || dataValueWriteProps.includes(key)));
|
|
27
27
|
}
|
|
28
28
|
export function omitDataValueReadWriteProps(props) {
|
|
29
|
-
return Object.fromEntries(Object.entries(props
|
|
29
|
+
return Object.fromEntries(Object.entries(props !== null && props !== void 0 ? props : {}).filter(([key]) => !dataValueReadProps.includes(key) && !dataValueWriteProps.includes(key)));
|
|
30
30
|
}
|
|
31
31
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["FormError","Error","constructor","message","options","_defineProperty","validationRule","dataValueReadProps","pickDataValueReadProps","props","Object","fromEntries","entries","filter","key","includes","omitDataValueReadProps","dataValueWriteProps","pickDataValueWriteProps","omitDataValueWriteProps","pickDataValueReadWriteProps","omitDataValueReadWriteProps"],"sources":["../../../../src/extensions/forms/types.ts"],"sourcesContent":["import { JSONSchema7 } from 'json-schema'\nimport { SpacingProps } from '../../components/space/types'\n\ninterface IFormErrorOptions {\n validationRule?: string | string[]\n}\n\n/**\n * Standard error object for Eufemia Forms, extending the built-in error with additional information for data handling\n */\nexport class FormError extends Error {\n /**\n * What validation rule did the error occur based on? (i.e: minLength, required or maximum)\n */\n validationRule?: string | string[]\n\n constructor(message: string, options?: IFormErrorOptions) {\n super(message)\n\n if (options) {\n this.validationRule = options.validationRule\n }\n }\n}\n\n// Data value\n\ninterface DefaultErrorMessages {\n required?: string\n}\n\nexport interface DataValueReadProps<Value = unknown> {\n /** JSON Pointer for where the data for this field is located in the source dataset */\n path?: string\n /** JSON Pointer for where the data for this field is located in the source iterate loop element */\n elementPath?: string\n value?: Value\n}\n\nconst dataValueReadProps = ['path', 'elementPath', 'value']\n\nexport function pickDataValueReadProps<Props extends DataValueReadProps>(\n props: Props\n): DataValueReadProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(([key]) =>\n dataValueReadProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueReadProps<Props extends DataValueReadProps>(\n props: Props\n): Omit<DataValueReadProps, keyof DataValueReadProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) => !dataValueReadProps.includes(key)\n )\n )\n}\n\nexport interface DataValueWriteProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> {\n emptyValue?: EmptyValue\n onFocus?: (value: Value | EmptyValue) => void\n onBlur?: (value: Value | EmptyValue) => void\n onChange?: (value: Value | EmptyValue) => void\n}\n\nconst dataValueWriteProps = ['emptyValue', 'onFocus', 'onBlur', 'onChange']\n\nexport function pickDataValueWriteProps<Props extends DataValueWriteProps>(\n props: Props\n): DataValueWriteProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(([key]) =>\n dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueWriteProps<Props extends DataValueWriteProps>(\n props: Props\n): Omit<DataValueWriteProps, keyof DataValueWriteProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) => !dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport type DataValueReadWriteProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> = DataValueReadProps<Value> & DataValueWriteProps<Value, EmptyValue>\n\nexport function pickDataValueReadWriteProps<\n Props extends DataValueReadWriteProps,\n>(props: Props): DataValueReadWriteProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) =>\n dataValueReadProps.includes(key) ||\n dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueReadWriteProps<\n Props extends DataValueReadWriteProps,\n>(\n props: Props\n): Omit<DataValueReadWriteProps, keyof DataValueReadWriteProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) =>\n !dataValueReadProps.includes(key) &&\n !dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport type ComponentProps = SpacingProps & {\n className?: string\n}\n\nexport type DataValueReadComponentProps<Value = unknown> = ComponentProps &\n DataValueReadProps<Value>\n\nexport type DataValueReadWriteComponentProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> = ComponentProps &\n DataValueReadProps<Value> &\n DataValueWriteProps<Value, EmptyValue>\n\nexport interface FieldProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n ErrorMessages extends { required?: string } = DefaultErrorMessages,\n> extends DataValueReadWriteComponentProps<Value, EmptyValue> {\n /** ID added to the actual field component, and linked to the label via for-attribute */\n id?: string\n name?: string\n layout?: 'horizontal' | 'vertical'\n /** Main label text */\n label?: React.ReactNode\n /** A more discreet text displayed beside the label (i.e for \"(optional)\") */\n labelDescription?: React.ReactNode\n /** Secondary information displayed at the end of the label line (i.e character counter) */\n labelSecondary?: React.ReactNode\n /** Text showing in place of the value if no value is given */\n placeholder?: string\n autoComplete?:\n | HTMLInputElement['autocomplete']\n | HTMLTextAreaElement['autocomplete']\n info?: Error | FormError | string\n warning?: Error | FormError | string\n error?: Error | FormError\n disabled?: boolean\n // Validation\n required?: boolean\n schema?: JSONSchema7\n validator?: (\n value: Value | EmptyValue\n ) => Error | undefined | Promise<Error | undefined>\n onBlurValidator?: (\n value: Value | EmptyValue\n ) => Error | undefined | Promise<Error | undefined>\n /**\n * Should error messages based on validation be shown initially (from given value-prop or source data)\n * before the user interacts with the field?\n * @default false\n * */\n validateInitially?: boolean\n /**\n * Should error messages be shown when touching (like focusing a field and blurring) without having changed\n * the value? So the user did not introduce a new error, but it was invalid based on validation initially.\n */\n validateUnchanged?: boolean\n /** Should validation be done while writing, not just when blurring the field? */\n continuousValidation?: boolean\n errorMessages?: ErrorMessages\n // Derivatives\n toInput?: (external: Value | undefined) => any\n fromInput?: (...args: any[]) => Value | undefined\n}\n\nexport interface FieldHelpProps {\n help?: {\n title?: string\n contents?: string\n }\n}\n\nexport interface ValueProps<Value>\n extends DataValueReadComponentProps<Value> {\n label?: string\n /** Should the component render if the value is empty? */\n showEmpty?: boolean\n /** Text showing in place of the value if no value is given. */\n placeholder?: string\n /** JSON Pointer for where the data for this field is located in the source iterate loop element */\n elementPath?: string\n /** For showing the value inline (not as a block element) */\n inline?: boolean\n // Derivatives\n /** Prepare value for display (regardless of source like props or data context) */\n prepare?: (external: Value | undefined) => string\n}\n"],"mappings":";AAUA,OAAO,MAAMA,SAAS,SAASC,KAAK,CAAC;EAMnCC,WAAWA,CAACC,OAAe,EAAEC,OAA2B,EAAE;IACxD,KAAK,CAACD,OAAO,CAAC;IAAAE,eAAA;IAEd,IAAID,OAAO,EAAE;MACX,IAAI,CAACE,cAAc,GAAGF,OAAO,CAACE,cAAc;IAC9C;EACF;AACF;AAgBA,MAAMC,kBAAkB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC;AAE3D,OAAO,SAASC,sBAAsBA,CACpCC,KAAY,EACQ;EACpB,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,
|
|
1
|
+
{"version":3,"file":"types.js","names":["FormError","Error","constructor","message","options","_defineProperty","validationRule","dataValueReadProps","pickDataValueReadProps","props","Object","fromEntries","entries","filter","key","includes","omitDataValueReadProps","dataValueWriteProps","pickDataValueWriteProps","omitDataValueWriteProps","pickDataValueReadWriteProps","omitDataValueReadWriteProps"],"sources":["../../../../src/extensions/forms/types.ts"],"sourcesContent":["import { JSONSchema7 } from 'json-schema'\nimport { SpacingProps } from '../../components/space/types'\n\ninterface IFormErrorOptions {\n validationRule?: string | string[]\n}\n\n/**\n * Standard error object for Eufemia Forms, extending the built-in error with additional information for data handling\n */\nexport class FormError extends Error {\n /**\n * What validation rule did the error occur based on? (i.e: minLength, required or maximum)\n */\n validationRule?: string | string[]\n\n constructor(message: string, options?: IFormErrorOptions) {\n super(message)\n\n if (options) {\n this.validationRule = options.validationRule\n }\n }\n}\n\n// Data value\n\ninterface DefaultErrorMessages {\n required?: string\n}\n\nexport interface DataValueReadProps<Value = unknown> {\n /** JSON Pointer for where the data for this field is located in the source dataset */\n path?: string\n /** JSON Pointer for where the data for this field is located in the source iterate loop element */\n elementPath?: string\n value?: Value\n}\n\nconst dataValueReadProps = ['path', 'elementPath', 'value']\n\nexport function pickDataValueReadProps<Props extends DataValueReadProps>(\n props: Props\n): DataValueReadProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(([key]) =>\n dataValueReadProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueReadProps<Props extends DataValueReadProps>(\n props: Props\n): Omit<DataValueReadProps, keyof DataValueReadProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) => !dataValueReadProps.includes(key)\n )\n )\n}\n\nexport interface DataValueWriteProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> {\n emptyValue?: EmptyValue\n onFocus?: (value: Value | EmptyValue) => void\n onBlur?: (value: Value | EmptyValue) => void\n onChange?: (value: Value | EmptyValue) => void\n}\n\nconst dataValueWriteProps = ['emptyValue', 'onFocus', 'onBlur', 'onChange']\n\nexport function pickDataValueWriteProps<Props extends DataValueWriteProps>(\n props: Props\n): DataValueWriteProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(([key]) =>\n dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueWriteProps<Props extends DataValueWriteProps>(\n props: Props\n): Omit<DataValueWriteProps, keyof DataValueWriteProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) => !dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport type DataValueReadWriteProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> = DataValueReadProps<Value> & DataValueWriteProps<Value, EmptyValue>\n\nexport function pickDataValueReadWriteProps<\n Props extends DataValueReadWriteProps,\n>(props: Props): DataValueReadWriteProps {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) =>\n dataValueReadProps.includes(key) ||\n dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport function omitDataValueReadWriteProps<\n Props extends DataValueReadWriteProps,\n>(\n props: Props\n): Omit<DataValueReadWriteProps, keyof DataValueReadWriteProps> {\n return Object.fromEntries(\n Object.entries(props ?? {}).filter(\n ([key]) =>\n !dataValueReadProps.includes(key) &&\n !dataValueWriteProps.includes(key)\n )\n )\n}\n\nexport type ComponentProps = SpacingProps & {\n className?: string\n}\n\nexport type DataValueReadComponentProps<Value = unknown> = ComponentProps &\n DataValueReadProps<Value>\n\nexport type DataValueReadWriteComponentProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n> = ComponentProps &\n DataValueReadProps<Value> &\n DataValueWriteProps<Value, EmptyValue>\n\nexport interface FieldProps<\n Value = unknown,\n EmptyValue = undefined | string | number,\n ErrorMessages extends { required?: string } = DefaultErrorMessages,\n> extends DataValueReadWriteComponentProps<Value, EmptyValue> {\n /** ID added to the actual field component, and linked to the label via for-attribute */\n id?: string\n name?: string\n layout?: 'horizontal' | 'vertical'\n /** Main label text */\n label?: React.ReactNode\n /** A more discreet text displayed beside the label (i.e for \"(optional)\") */\n labelDescription?: React.ReactNode\n /** Secondary information displayed at the end of the label line (i.e character counter) */\n labelSecondary?: React.ReactNode\n /** Text showing in place of the value if no value is given */\n placeholder?: string\n autoComplete?:\n | HTMLInputElement['autocomplete']\n | HTMLTextAreaElement['autocomplete']\n info?: Error | FormError | string\n warning?: Error | FormError | string\n error?: Error | FormError\n disabled?: boolean\n // Validation\n required?: boolean\n schema?: JSONSchema7\n validator?: (\n value: Value | EmptyValue\n ) => Error | undefined | Promise<Error | undefined>\n onBlurValidator?: (\n value: Value | EmptyValue\n ) => Error | undefined | Promise<Error | undefined>\n /**\n * Should error messages based on validation be shown initially (from given value-prop or source data)\n * before the user interacts with the field?\n * @default false\n * */\n validateInitially?: boolean\n /**\n * Should error messages be shown when touching (like focusing a field and blurring) without having changed\n * the value? So the user did not introduce a new error, but it was invalid based on validation initially.\n */\n validateUnchanged?: boolean\n /** Should validation be done while writing, not just when blurring the field? */\n continuousValidation?: boolean\n errorMessages?: ErrorMessages\n // Derivatives\n toInput?: (external: Value | undefined) => any\n fromInput?: (...args: any[]) => Value | undefined\n}\n\nexport interface FieldHelpProps {\n help?: {\n title?: string\n contents?: string\n }\n}\n\nexport interface ValueProps<Value>\n extends DataValueReadComponentProps<Value> {\n label?: string\n /** Should the component render if the value is empty? */\n showEmpty?: boolean\n /** Text showing in place of the value if no value is given. */\n placeholder?: string\n /** JSON Pointer for where the data for this field is located in the source iterate loop element */\n elementPath?: string\n /** For showing the value inline (not as a block element) */\n inline?: boolean\n // Derivatives\n /** Prepare value for display (regardless of source like props or data context) */\n prepare?: (external: Value | undefined) => string\n}\n"],"mappings":";AAUA,OAAO,MAAMA,SAAS,SAASC,KAAK,CAAC;EAMnCC,WAAWA,CAACC,OAAe,EAAEC,OAA2B,EAAE;IACxD,KAAK,CAACD,OAAO,CAAC;IAAAE,eAAA;IAEd,IAAID,OAAO,EAAE;MACX,IAAI,CAACE,cAAc,GAAGF,OAAO,CAACE,cAAc;IAC9C;EACF;AACF;AAgBA,MAAMC,kBAAkB,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC;AAE3D,OAAO,SAASC,sBAAsBA,CACpCC,KAAY,EACQ;EACpB,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,KACvCP,kBAAkB,CAACQ,QAAQ,CAACD,GAAG,CACjC,CACF,CAAC;AACH;AAEA,OAAO,SAASE,sBAAsBA,CACpCP,KAAY,EACwC;EACpD,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAChC,CAAC,CAACC,GAAG,CAAC,KAAK,CAACP,kBAAkB,CAACQ,QAAQ,CAACD,GAAG,CAC7C,CACF,CAAC;AACH;AAYA,MAAMG,mBAAmB,GAAG,CAAC,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC;AAE3E,OAAO,SAASC,uBAAuBA,CACrCT,KAAY,EACS;EACrB,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,KACvCG,mBAAmB,CAACF,QAAQ,CAACD,GAAG,CAClC,CACF,CAAC;AACH;AAEA,OAAO,SAASK,uBAAuBA,CACrCV,KAAY,EAC0C;EACtD,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAChC,CAAC,CAACC,GAAG,CAAC,KAAK,CAACG,mBAAmB,CAACF,QAAQ,CAACD,GAAG,CAC9C,CACF,CAAC;AACH;AAOA,OAAO,SAASM,2BAA2BA,CAEzCX,KAAY,EAA2B;EACvC,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAChC,CAAC,CAACC,GAAG,CAAC,KACJP,kBAAkB,CAACQ,QAAQ,CAACD,GAAG,CAAC,IAChCG,mBAAmB,CAACF,QAAQ,CAACD,GAAG,CACpC,CACF,CAAC;AACH;AAEA,OAAO,SAASO,2BAA2BA,CAGzCZ,KAAY,EACkD;EAC9D,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACH,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CAAC,CAAC,CAAC,CAACI,MAAM,CAChC,CAAC,CAACC,GAAG,CAAC,KACJ,CAACP,kBAAkB,CAACQ,QAAQ,CAACD,GAAG,CAAC,IACjC,CAACG,mBAAmB,CAACF,QAAQ,CAACD,GAAG,CACrC,CACF,CAAC;AACH"}
|
|
@@ -30,7 +30,8 @@ function getValidationRule(ajvError) {
|
|
|
30
30
|
return ajvError.keyword;
|
|
31
31
|
}
|
|
32
32
|
function ajvErrorToFormError(ajvError) {
|
|
33
|
-
|
|
33
|
+
var _ajvError$message;
|
|
34
|
+
const error = new FormError((_ajvError$message = ajvError.message) !== null && _ajvError$message !== void 0 ? _ajvError$message : 'Unknown error', {
|
|
34
35
|
validationRule: getValidationRule(ajvError)
|
|
35
36
|
});
|
|
36
37
|
return error;
|
|
@@ -47,7 +48,7 @@ export function ajvErrorsToOneFormError(errors) {
|
|
|
47
48
|
validationRule: errors.map(getValidationRule)
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
export const ajvErrorsToFormErrors = errors => (errors
|
|
51
|
+
export const ajvErrorsToFormErrors = errors => (errors !== null && errors !== void 0 ? errors : []).reduce((errors, ajvError) => {
|
|
51
52
|
return _objectSpread(_objectSpread({}, errors), {}, {
|
|
52
53
|
[getInstancePath(ajvError)]: ajvErrorToFormError(ajvError)
|
|
53
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ajv.js","names":["Ajv","ajvErrors","FormError","ajv","allErrors","getInstancePath","ajvError","keyword","instancePath","params","missingProperty","errors","getValidationRule","ajvErrorToFormError","error","message","validationRule","ajvErrorsToOneFormError","length","errorMessages","map","join","ajvErrorsToFormErrors","reduce","_objectSpread"],"sources":["../../../../../src/extensions/forms/utils/ajv.ts"],"sourcesContent":["import Ajv, { ErrorObject } from 'ajv'\nimport ajvErrors from 'ajv-errors'\nimport { FormError } from '../types'\n\nconst ajv = new Ajv({\n // If allErrors is off, ajv only give you the first error it finds\n allErrors: true,\n})\n\najvErrors(ajv)\n\nfunction getInstancePath(ajvError: ErrorObject): string {\n switch (ajvError.keyword) {\n case 'required': {\n // Required-errors are considered object errors by ajv, so they don't have instancePaths. We want to\n // show them under the relevant field\n return `${ajvError.instancePath}/${ajvError.params.missingProperty}`\n }\n case 'errorMessage': {\n // errorMessage structures (from ajv-errors) wrap the original error. Find instance path from original\n // to avoid issues like required-errors pointing at parent object.\n if (ajvError.params.errors[0]) {\n return getInstancePath(ajvError.params.errors[0])\n }\n }\n }\n return ajvError.instancePath\n}\n\nfunction getValidationRule(ajvError: ErrorObject): string {\n if (ajvError.keyword === 'errorMessage' && ajvError.params.errors[0]) {\n // errorMessage structures (from ajv-errors) wrap the original error. Find keyword from original\n // to avoid issues like required-errors pointing at parent object.\n return getValidationRule(ajvError.params.errors[0])\n }\n return ajvError.keyword\n}\n\nfunction ajvErrorToFormError(ajvError: ErrorObject): FormError {\n const error = new FormError(ajvError.message ?? 'Unknown error', {\n validationRule: getValidationRule(ajvError),\n })\n return error\n}\n\n/**\n * Transform errors from ajv-validation into one error object (i.e for validating a flat value)\n */\nexport function ajvErrorsToOneFormError(\n errors?: ErrorObject[] | null\n): FormError | undefined {\n if (!errors || errors.length === 0) {\n return\n }\n if (errors.length === 1) {\n return ajvErrorToFormError(errors[0])\n }\n\n const errorMessages = errors?.map((error) => error.message)\n return new FormError(errorMessages.join(' | '), {\n validationRule: errors.map(getValidationRule),\n })\n}\n\n/**\n *\n * @param errors Transform errors from ajv-validation into a record of errors (path as key, error as value)\n * @returns\n */\nexport const ajvErrorsToFormErrors = (\n errors?: ErrorObject[] | null\n): Record<string, FormError> =>\n (errors ?? []).reduce((errors, ajvError) => {\n return {\n ...errors,\n [getInstancePath(ajvError)]: ajvErrorToFormError(ajvError),\n }\n }, {})\n\nexport default ajv\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAuB,KAAK;AACtC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,SAAS,QAAQ,UAAU;AAEpC,MAAMC,GAAG,GAAG,IAAIH,GAAG,CAAC;EAElBI,SAAS,EAAE;AACb,CAAC,CAAC;AAEFH,SAAS,CAACE,GAAG,CAAC;AAEd,SAASE,eAAeA,CAACC,QAAqB,EAAU;EACtD,QAAQA,QAAQ,CAACC,OAAO;IACtB,KAAK,UAAU;MAAE;QAGf,OAAQ,GAAED,QAAQ,CAACE,YAAa,IAAGF,QAAQ,CAACG,MAAM,CAACC,eAAgB,EAAC;MACtE;IACA,KAAK,cAAc;MAAE;QAGnB,IAAIJ,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,EAAE;UAC7B,OAAON,eAAe,CAACC,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,CAAC;QACnD;MACF;EACF;EACA,OAAOL,QAAQ,CAACE,YAAY;AAC9B;AAEA,SAASI,iBAAiBA,CAACN,QAAqB,EAAU;EACxD,IAAIA,QAAQ,CAACC,OAAO,KAAK,cAAc,IAAID,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,EAAE;IAGpE,OAAOC,iBAAiB,CAACN,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,CAAC;EACrD;EACA,OAAOL,QAAQ,CAACC,OAAO;AACzB;AAEA,SAASM,mBAAmBA,CAACP,QAAqB,EAAa;EAC7D,
|
|
1
|
+
{"version":3,"file":"ajv.js","names":["Ajv","ajvErrors","FormError","ajv","allErrors","getInstancePath","ajvError","keyword","instancePath","params","missingProperty","errors","getValidationRule","ajvErrorToFormError","_ajvError$message","error","message","validationRule","ajvErrorsToOneFormError","length","errorMessages","map","join","ajvErrorsToFormErrors","reduce","_objectSpread"],"sources":["../../../../../src/extensions/forms/utils/ajv.ts"],"sourcesContent":["import Ajv, { ErrorObject } from 'ajv'\nimport ajvErrors from 'ajv-errors'\nimport { FormError } from '../types'\n\nconst ajv = new Ajv({\n // If allErrors is off, ajv only give you the first error it finds\n allErrors: true,\n})\n\najvErrors(ajv)\n\nfunction getInstancePath(ajvError: ErrorObject): string {\n switch (ajvError.keyword) {\n case 'required': {\n // Required-errors are considered object errors by ajv, so they don't have instancePaths. We want to\n // show them under the relevant field\n return `${ajvError.instancePath}/${ajvError.params.missingProperty}`\n }\n case 'errorMessage': {\n // errorMessage structures (from ajv-errors) wrap the original error. Find instance path from original\n // to avoid issues like required-errors pointing at parent object.\n if (ajvError.params.errors[0]) {\n return getInstancePath(ajvError.params.errors[0])\n }\n }\n }\n return ajvError.instancePath\n}\n\nfunction getValidationRule(ajvError: ErrorObject): string {\n if (ajvError.keyword === 'errorMessage' && ajvError.params.errors[0]) {\n // errorMessage structures (from ajv-errors) wrap the original error. Find keyword from original\n // to avoid issues like required-errors pointing at parent object.\n return getValidationRule(ajvError.params.errors[0])\n }\n return ajvError.keyword\n}\n\nfunction ajvErrorToFormError(ajvError: ErrorObject): FormError {\n const error = new FormError(ajvError.message ?? 'Unknown error', {\n validationRule: getValidationRule(ajvError),\n })\n return error\n}\n\n/**\n * Transform errors from ajv-validation into one error object (i.e for validating a flat value)\n */\nexport function ajvErrorsToOneFormError(\n errors?: ErrorObject[] | null\n): FormError | undefined {\n if (!errors || errors.length === 0) {\n return\n }\n if (errors.length === 1) {\n return ajvErrorToFormError(errors[0])\n }\n\n const errorMessages = errors?.map((error) => error.message)\n return new FormError(errorMessages.join(' | '), {\n validationRule: errors.map(getValidationRule),\n })\n}\n\n/**\n *\n * @param errors Transform errors from ajv-validation into a record of errors (path as key, error as value)\n * @returns\n */\nexport const ajvErrorsToFormErrors = (\n errors?: ErrorObject[] | null\n): Record<string, FormError> =>\n (errors ?? []).reduce((errors, ajvError) => {\n return {\n ...errors,\n [getInstancePath(ajvError)]: ajvErrorToFormError(ajvError),\n }\n }, {})\n\nexport default ajv\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAuB,KAAK;AACtC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,SAAS,QAAQ,UAAU;AAEpC,MAAMC,GAAG,GAAG,IAAIH,GAAG,CAAC;EAElBI,SAAS,EAAE;AACb,CAAC,CAAC;AAEFH,SAAS,CAACE,GAAG,CAAC;AAEd,SAASE,eAAeA,CAACC,QAAqB,EAAU;EACtD,QAAQA,QAAQ,CAACC,OAAO;IACtB,KAAK,UAAU;MAAE;QAGf,OAAQ,GAAED,QAAQ,CAACE,YAAa,IAAGF,QAAQ,CAACG,MAAM,CAACC,eAAgB,EAAC;MACtE;IACA,KAAK,cAAc;MAAE;QAGnB,IAAIJ,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,EAAE;UAC7B,OAAON,eAAe,CAACC,QAAQ,CAACG,MAAM,CAACE,MAAM,CAAC,CAAC,CAAC,CAAC;QACnD;MACF;EACF;EACA,OAAOL,QAAQ,CAAC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AAmB,aAAA,CAAAA,aAAA,KACKd,MAAM;IACT,CAACN,eAAe,CAACC,QAAQ,CAAC,GAAGO,mBAAmB,CAACP,QAAQ;EAAC;AAE9D,CAAC,EAAE,CAAC,CAAC,CAAC;AAER,eAAeH,GAAG"}
|
|
@@ -7,7 +7,7 @@ export function formatNumber(value, options) {
|
|
|
7
7
|
magnitude,
|
|
8
8
|
prefix,
|
|
9
9
|
suffix
|
|
10
|
-
} = options
|
|
10
|
+
} = options !== null && options !== void 0 ? options : {};
|
|
11
11
|
const withMagnitude = magnitude !== undefined ? value / Math.pow(10, magnitude) : value;
|
|
12
12
|
const withDecimals = fixedDecimals !== undefined ? withMagnitude.toFixed(fixedDecimals) : decimalLimit ? (Math.round(withMagnitude * Math.pow(10, decimalLimit)) / Math.pow(10, decimalLimit)).toString() : withMagnitude.toString();
|
|
13
13
|
const withDecimalSymbol = decimalSymbol !== undefined ? withDecimals.replace('.', decimalSymbol) : withDecimals;
|
|
@@ -23,7 +23,7 @@ export function parseFormattedNumber(formattedValue, options) {
|
|
|
23
23
|
magnitude,
|
|
24
24
|
prefix,
|
|
25
25
|
suffix
|
|
26
|
-
} = options
|
|
26
|
+
} = options !== null && options !== void 0 ? options : {};
|
|
27
27
|
const parsedDecimalSymbol = decimalSymbol !== undefined ? formattedValue.replace(decimalSymbol, '.') : formattedValue;
|
|
28
28
|
const parsedThousandSeparator = thousandSeparator !== undefined ? parsedDecimalSymbol.split(thousandSeparator).join('') : parsedDecimalSymbol;
|
|
29
29
|
const parsedPrefix = prefix !== undefined && parsedThousandSeparator.substring(0, prefix.length) === prefix ? parsedThousandSeparator.substring(prefix.length) : parsedThousandSeparator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.js","names":["formatNumber","value","options","thousandSeparator","decimalLimit","fixedDecimals","decimalSymbol","magnitude","prefix","suffix","withMagnitude","undefined","Math","pow","withDecimals","toFixed","round","toString","withDecimalSymbol","replace","withThousandSeparator","withPrefix","withSuffix","parseFormattedNumber","formattedValue","parsedDecimalSymbol","parsedThousandSeparator","split","join","parsedPrefix","substring","length","parsedSuffix","slice","parsedNumber","Number","parsedMagnitude"],"sources":["../../../../../src/extensions/forms/utils/numbers.ts"],"sourcesContent":["interface FormatNumberOptions {\n prefix?: string\n suffix?: string\n /** Character to use for separating groups of number. Like '12 345' for 12345. */\n thousandSeparator?: string\n /** Max number of decimals. For source numbers with higher number of decimals, the number will be rounded. Will not add leading zeros. */\n decimalLimit?: number\n /** Set a fixed number of decimals (rounding when more decimals, adding leading zeros when less). */\n fixedDecimals?: number\n /** Symbol to separate between digits and decimals. */\n decimalSymbol?: string\n /** For showing magnitude of original number. For instance, 23500000 with magnitude 6 displays as 23,5 */\n magnitude?: number\n}\n\nexport function formatNumber(\n value: number,\n options?: FormatNumberOptions\n): string {\n const {\n thousandSeparator,\n decimalLimit,\n fixedDecimals,\n decimalSymbol = ',', // Norwegian default format\n magnitude,\n prefix,\n suffix,\n } = options ?? {}\n\n const withMagnitude =\n magnitude !== undefined ? value / Math.pow(10, magnitude) : value\n\n const withDecimals =\n fixedDecimals !== undefined\n ? withMagnitude.toFixed(fixedDecimals)\n : decimalLimit\n ? (\n Math.round(withMagnitude * Math.pow(10, decimalLimit)) /\n Math.pow(10, decimalLimit)\n ).toString()\n : withMagnitude.toString()\n\n const withDecimalSymbol =\n decimalSymbol !== undefined\n ? withDecimals.replace('.', decimalSymbol)\n : withDecimals\n\n const withThousandSeparator =\n thousandSeparator !== undefined\n ? withDecimalSymbol.replace(\n /\\B(?=(\\d{3})+(?!\\d))/g,\n thousandSeparator\n )\n : withDecimalSymbol\n\n const withPrefix =\n prefix !== undefined\n ? prefix + withThousandSeparator\n : withThousandSeparator\n\n const withSuffix =\n suffix !== undefined ? withPrefix + suffix : withPrefix\n\n return withSuffix\n}\n\nexport function parseFormattedNumber(\n formattedValue: string,\n options?: FormatNumberOptions\n): number {\n const {\n thousandSeparator,\n decimalSymbol = ',', // Norwegian default format\n magnitude,\n prefix,\n suffix,\n } = options ?? {}\n\n const parsedDecimalSymbol =\n decimalSymbol !== undefined\n ? formattedValue.replace(decimalSymbol, '.')\n : formattedValue\n\n const parsedThousandSeparator =\n thousandSeparator !== undefined\n ? parsedDecimalSymbol.split(thousandSeparator).join('')\n : parsedDecimalSymbol\n\n const parsedPrefix =\n prefix !== undefined &&\n parsedThousandSeparator.substring(0, prefix.length) === prefix\n ? parsedThousandSeparator.substring(prefix.length)\n : parsedThousandSeparator\n\n const parsedSuffix =\n suffix !== undefined &&\n parsedPrefix.slice(suffix.length * -1) === suffix\n ? parsedPrefix.substring(0, parsedPrefix.length - suffix.length)\n : parsedPrefix\n\n const parsedNumber = Number(parsedSuffix)\n\n const parsedMagnitude =\n magnitude !== undefined\n ? // toFixed to avoid inaccuracies (like 10/5 = 1.999999999999998)\n Number((parsedNumber * Math.pow(10, magnitude)).toFixed(6))\n : parsedNumber\n\n return parsedMagnitude\n}\n"],"mappings":"AAeA,OAAO,SAASA,YAAYA,CAC1BC,KAAa,EACbC,OAA6B,EACrB;EACR,MAAM;IACJC,iBAAiB;IACjBC,YAAY;IACZC,aAAa;IACbC,aAAa,GAAG,GAAG;IACnBC,SAAS;IACTC,MAAM;IACNC;EACF,CAAC,GAAGP,OAAO,
|
|
1
|
+
{"version":3,"file":"numbers.js","names":["formatNumber","value","options","thousandSeparator","decimalLimit","fixedDecimals","decimalSymbol","magnitude","prefix","suffix","withMagnitude","undefined","Math","pow","withDecimals","toFixed","round","toString","withDecimalSymbol","replace","withThousandSeparator","withPrefix","withSuffix","parseFormattedNumber","formattedValue","parsedDecimalSymbol","parsedThousandSeparator","split","join","parsedPrefix","substring","length","parsedSuffix","slice","parsedNumber","Number","parsedMagnitude"],"sources":["../../../../../src/extensions/forms/utils/numbers.ts"],"sourcesContent":["interface FormatNumberOptions {\n prefix?: string\n suffix?: string\n /** Character to use for separating groups of number. Like '12 345' for 12345. */\n thousandSeparator?: string\n /** Max number of decimals. For source numbers with higher number of decimals, the number will be rounded. Will not add leading zeros. */\n decimalLimit?: number\n /** Set a fixed number of decimals (rounding when more decimals, adding leading zeros when less). */\n fixedDecimals?: number\n /** Symbol to separate between digits and decimals. */\n decimalSymbol?: string\n /** For showing magnitude of original number. For instance, 23500000 with magnitude 6 displays as 23,5 */\n magnitude?: number\n}\n\nexport function formatNumber(\n value: number,\n options?: FormatNumberOptions\n): string {\n const {\n thousandSeparator,\n decimalLimit,\n fixedDecimals,\n decimalSymbol = ',', // Norwegian default format\n magnitude,\n prefix,\n suffix,\n } = options ?? {}\n\n const withMagnitude =\n magnitude !== undefined ? value / Math.pow(10, magnitude) : value\n\n const withDecimals =\n fixedDecimals !== undefined\n ? withMagnitude.toFixed(fixedDecimals)\n : decimalLimit\n ? (\n Math.round(withMagnitude * Math.pow(10, decimalLimit)) /\n Math.pow(10, decimalLimit)\n ).toString()\n : withMagnitude.toString()\n\n const withDecimalSymbol =\n decimalSymbol !== undefined\n ? withDecimals.replace('.', decimalSymbol)\n : withDecimals\n\n const withThousandSeparator =\n thousandSeparator !== undefined\n ? withDecimalSymbol.replace(\n /\\B(?=(\\d{3})+(?!\\d))/g,\n thousandSeparator\n )\n : withDecimalSymbol\n\n const withPrefix =\n prefix !== undefined\n ? prefix + withThousandSeparator\n : withThousandSeparator\n\n const withSuffix =\n suffix !== undefined ? withPrefix + suffix : withPrefix\n\n return withSuffix\n}\n\nexport function parseFormattedNumber(\n formattedValue: string,\n options?: FormatNumberOptions\n): number {\n const {\n thousandSeparator,\n decimalSymbol = ',', // Norwegian default format\n magnitude,\n prefix,\n suffix,\n } = options ?? {}\n\n const parsedDecimalSymbol =\n decimalSymbol !== undefined\n ? formattedValue.replace(decimalSymbol, '.')\n : formattedValue\n\n const parsedThousandSeparator =\n thousandSeparator !== undefined\n ? parsedDecimalSymbol.split(thousandSeparator).join('')\n : parsedDecimalSymbol\n\n const parsedPrefix =\n prefix !== undefined &&\n parsedThousandSeparator.substring(0, prefix.length) === prefix\n ? parsedThousandSeparator.substring(prefix.length)\n : parsedThousandSeparator\n\n const parsedSuffix =\n suffix !== undefined &&\n parsedPrefix.slice(suffix.length * -1) === suffix\n ? parsedPrefix.substring(0, parsedPrefix.length - suffix.length)\n : parsedPrefix\n\n const parsedNumber = Number(parsedSuffix)\n\n const parsedMagnitude =\n magnitude !== undefined\n ? // toFixed to avoid inaccuracies (like 10/5 = 1.999999999999998)\n Number((parsedNumber * Math.pow(10, magnitude)).toFixed(6))\n : parsedNumber\n\n return parsedMagnitude\n}\n"],"mappings":"AAeA,OAAO,SAASA,YAAYA,CAC1BC,KAAa,EACbC,OAA6B,EACrB;EACR,MAAM;IACJC,iBAAiB;IACjBC,YAAY;IACZC,aAAa;IACbC,aAAa,GAAG,GAAG;IACnBC,SAAS;IACTC,MAAM;IACNC;EACF,CAAC,GAAGP,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,CAAC,CAAC;EAEjB,MAAMQ,aAAa,GACjBH,SAAS,KAAKI,SAAS,GAAGV,KAAK,GAAGW,IAAI,CAACC,GAAG,CAAC,EAAE,EAAEN,SAAS,CAAC,GAAGN,KAAK;EAEnE,MAAMa,YAAY,GAChBT,aAAa,KAAKM,SAAS,GACvBD,aAAa,CAACK,OAAO,CAACV,aAAa,CAAC,GACpCD,YAAY,GACZ,CACEQ,IAAI,CAACI,KAAK,CAACN,aAAa,GAAGE,IAAI,CAACC,GAAG,CAAC,EAAE,EAAET,YAAY,CAAC,CAAC,GACtDQ,IAAI,CAACC,GAAG,CAAC,EAAE,EAAET,YAAY,CAAC,EAC1Ba,QAAQ,CAAC,CAAC,GACZP,aAAa,CAACO,QAAQ,CAAC,CAAC;EAE9B,MAAMC,iBAAiB,GACrBZ,aAAa,KAAKK,SAAS,GACvBG,YAAY,CAACK,OAAO,CAAC,GAAG,EAAEb,aAAa,CAAC,GACxCQ,YAAY;EAElB,MAAMM,qBAAqB,GACzBjB,iBAAiB,KAAKQ,SAAS,GAC3BO,iBAAiB,CAACC,OAAO,CACvB,uBAA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ACH,YAAY,CAAC;EAEzC,MAAMI,eAAe,GACnB7B,SAAS,KAAKI,SAAS,GAEnBwB,MAAM,CAAC,CAACD,YAAY,GAAGtB,IAAI,CAACC,GAAG,CAAC,EAAE,EAAEN,SAAS,CAAC,EAAEQ,OAAO,CAAC,CAAC,CAAC,CAAC,GAC3DmB,YAAY;EAElB,OAAOE,eAAe;AACxB"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import { useRef } from 'react';
|
|
2
4
|
export default function useWasChanged(subject, title, debug) {
|
|
5
|
+
var _previous$current;
|
|
3
6
|
const previous = useRef(subject);
|
|
4
7
|
if (!previous.current && !subject) {
|
|
5
8
|
console.log('useWasChanged() - No subject was provided, while previous render had a subject. Was the whole object deleted?');
|
|
@@ -7,12 +10,12 @@ export default function useWasChanged(subject, title, debug) {
|
|
|
7
10
|
const {
|
|
8
11
|
changed,
|
|
9
12
|
unchanged
|
|
10
|
-
} = [...Object.entries(subject), ...Object.entries(previous.current
|
|
13
|
+
} = [...Object.entries(subject), ...Object.entries((_previous$current = previous.current) !== null && _previous$current !== void 0 ? _previous$current : {}).filter(([key]) => subject[key] === undefined)].reduce(({
|
|
11
14
|
changed,
|
|
12
15
|
unchanged
|
|
13
16
|
}, [key, value]) => {
|
|
14
|
-
var _previous$
|
|
15
|
-
if (((_previous$
|
|
17
|
+
var _previous$current2;
|
|
18
|
+
if (((_previous$current2 = previous.current) === null || _previous$current2 === void 0 ? void 0 : _previous$current2[key]) !== (subject === null || subject === void 0 ? void 0 : subject[key])) {
|
|
16
19
|
return {
|
|
17
20
|
changed: changed.concat(key),
|
|
18
21
|
unchanged
|
|
@@ -30,12 +33,12 @@ export default function useWasChanged(subject, title, debug) {
|
|
|
30
33
|
if (changed.length === 0 && !debug) {
|
|
31
34
|
return;
|
|
32
35
|
}
|
|
33
|
-
console.groupCollapsed(`${title
|
|
36
|
+
console.groupCollapsed(`${title !== null && title !== void 0 ? title : 'object'} -- ${changed.length} members was changed`);
|
|
34
37
|
Object.values(changed).map(key => {
|
|
35
38
|
if (debug) {
|
|
36
|
-
var _previous$
|
|
39
|
+
var _previous$current3;
|
|
37
40
|
console.groupCollapsed(`CHANGED: ${key}`);
|
|
38
|
-
console.log('PREVIOUS: ', (_previous$
|
|
41
|
+
console.log('PREVIOUS: ', (_previous$current3 = previous.current) === null || _previous$current3 === void 0 ? void 0 : _previous$current3[key]);
|
|
39
42
|
console.log('CURRENT: ', subject === null || subject === void 0 ? void 0 : subject[key]);
|
|
40
43
|
console.groupEnd();
|
|
41
44
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWasChanged.js","names":["useRef","useWasChanged","subject","title","debug","previous","current","console","log","changed","unchanged","Object","entries","filter","key","undefined","reduce","value","_previous$
|
|
1
|
+
{"version":3,"file":"useWasChanged.js","names":["useRef","useWasChanged","subject","title","debug","_previous$current","previous","current","console","log","changed","unchanged","Object","entries","filter","key","undefined","reduce","value","_previous$current2","concat","length","groupCollapsed","values","map","_previous$current3","groupEnd"],"sources":["../../../../../src/extensions/forms/utils/useWasChanged.ts"],"sourcesContent":["import { useRef } from 'react'\n\n/**\n *\n * Shallow object comparison to easily find out what props of an object was changed since the last render\n */\nexport default function useWasChanged<Subject extends object>(\n subject: Subject,\n title?: string,\n debug?: boolean\n): void {\n const previous = useRef<Subject>(subject)\n if (!previous.current && !subject) {\n console.log(\n 'useWasChanged() - No subject was provided, while previous render had a subject. Was the whole object deleted?'\n )\n }\n\n const { changed, unchanged } = [\n ...Object.entries(subject),\n ...Object.entries(previous.current ?? {}).filter(\n ([key]) => subject[key] === undefined\n ),\n ].reduce(\n ({ changed, unchanged }, [key, value]) => {\n if (previous.current?.[key] !== subject?.[key]) {\n return {\n changed: changed.concat(key),\n unchanged,\n }\n } else {\n return {\n changed,\n unchanged: unchanged.concat(key),\n }\n }\n },\n { changed: [], unchanged: [] }\n )\n\n if (changed.length === 0 && !debug) {\n return\n }\n\n console.groupCollapsed(\n `${title ?? 'object'} -- ${changed.length} members was changed`\n )\n\n Object.values(changed).map((key) => {\n if (debug) {\n console.groupCollapsed(`CHANGED: ${key}`)\n console.log('PREVIOUS: ', previous.current?.[key])\n console.log('CURRENT: ', subject?.[key])\n console.groupEnd()\n } else {\n console.log(`CHANGED: ${key}`)\n }\n })\n Object.values(unchanged).map((key) => {\n console.log(`UNCHANGED: ${key}`)\n })\n\n previous.current = subject\n\n console.groupEnd()\n}\n"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,OAAO;AAM9B,eAAe,SAASC,aAAaA,CACnCC,OAAgB,EAChBC,KAAc,EACdC,KAAe,EACT;EAAA,IAAAC,iBAAA;EACN,MAAMC,QAAQ,GAAGN,MAAM,CAAUE,OAAO,CAAC;EACzC,IAAI,CAACI,QAAQ,CAACC,OAAO,IAAI,CAACL,OAAO,EAAE;IACjCM,OAAO,CAACC,GAAG,CACT,+GACF,CAAC;EACH;EAEA,MAAM;IAAEC,OAAO;IAAEC;EAAU,CAAC,GAAG,CAC7B,GAAGC,MAAM,CAACC,OAAO,CAACX,OAAO,CAAC,EAC1B,GAAGU,MAAM,CAACC,OAAO,EAAAR,iBAAA,GAACC,QAAQ,CAACC,OAAO,cAAAF,iBAAA,cAAAA,iBAAA,GAAI,CAAC,CAAC,CAAC,CAACS,MAAM,CAC9C,CAAC,CAACC,GAAG,CAAC,KAAKb,OAAO,CAACa,GAAG,CAAC,KAAKC,SAC9B,CAAC,CACF,CAACC,MAAM,CACN,CAAC;IAAEP,OAAO;IAAEC;EAAU,CAAC,EAAE,CAACI,GAAG,EAAEG,KAAK,CAAC,KAAK;IAAA,IAAAC,kBAAA;IACxC,IAAI,EAAAA,kBAAA,GAAAb,QAAQ,CAACC,OAAO,cAAAY,kBAAA,uBAAhBA,kBAAA,CAAmBJ,GAAG,CAAC,OAAKb,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAGa,GAAG,CAAC,GAAE;MAC9C,OAAO;QACLL,OAA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AC;AACpB"}
|
|
@@ -318,7 +318,7 @@ export const prepareDerivedState = (props, state) => {
|
|
|
318
318
|
if (props.value === 'initval') {
|
|
319
319
|
state.selected_item = null;
|
|
320
320
|
} else {
|
|
321
|
-
state.selected_item = getCurrentIndex(props.value, state.
|
|
321
|
+
state.selected_item = getCurrentIndex(props.value, state.original_data);
|
|
322
322
|
}
|
|
323
323
|
if (typeof props.on_state_update === 'function') {
|
|
324
324
|
dispatchCustomElementEvent({
|