@sprinklrjs/spaceweb 11.0.0 → 12.14.4
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/allComponentsAndUtilities.d.ts +1 -0
- package/allComponentsAndUtilities.js +2 -1
- package/asyncSelect/asyncSelect.d.ts +4 -2
- package/asyncSelect/asyncSelect.js +43 -108
- package/asyncSelect/groupedAsyncSelect.d.ts +5 -0
- package/asyncSelect/groupedAsyncSelect.js +41 -0
- package/asyncSelect/helpers.d.ts +8 -2
- package/asyncSelect/helpers.js +35 -4
- package/asyncSelect/hooks/useAsyncOptionHandlers.d.ts +16 -11
- package/asyncSelect/hooks/useAsyncOptionHandlers.js +73 -26
- package/asyncSelect/hooks/useAsyncSelect.d.ts +10 -0
- package/asyncSelect/hooks/useAsyncSelect.js +182 -0
- package/asyncSelect/hooks/useResolveSelectedOptions.d.ts +10 -7
- package/asyncSelect/hooks/useResolveSelectedOptions.js +59 -47
- package/asyncSelect/index.d.ts +4 -1
- package/asyncSelect/index.js +8 -0
- package/asyncSelect/types.d.ts +61 -9
- package/avatar/avatar.js +12 -2
- package/avatar/styled-component.js +7 -22
- package/badge/styled-component.js +10 -8
- package/banner/banner.js +1 -1
- package/breadcrumb/breadcrumb-item.d.ts +7 -0
- package/breadcrumb/breadcrumb-item.js +41 -0
- package/breadcrumb/breadcrumb.d.ts +7 -0
- package/breadcrumb/breadcrumb.js +29 -0
- package/breadcrumb/index.d.ts +4 -0
- package/breadcrumb/index.js +17 -0
- package/breadcrumb/package.json +4 -0
- package/breadcrumb/styled-components.d.ts +7 -0
- package/breadcrumb/styled-components.js +19 -0
- package/breadcrumb/types.d.ts +38 -0
- package/breadcrumb/types.js +2 -0
- package/button/Button.d.ts +2 -0
- package/button/Button.js +13 -1
- package/button/IconButton/IconButton.d.ts +2 -4
- package/button/IconButton/IconButton.js +5 -2
- package/button/IconButton/types.d.ts +10 -1
- package/button/basewebAdapter.d.ts +3 -1
- package/button/styled-components.js +30 -25
- package/button/types.d.ts +3 -0
- package/button-group/ButtonGroup.d.ts +1 -0
- package/button-group/ButtonGroup.js +9 -5
- package/button-group/StatefulButtonGroup.d.ts +1 -0
- package/button-group/styled-components.d.ts +34 -0
- package/button-group/styled-components.js +57 -9
- package/button-group/types.d.ts +2 -0
- package/checkbox/basewebAdapters.js +6 -1
- package/color-picker/ColorPalette.d.ts +9 -0
- package/color-picker/ColorPalette.js +26 -0
- package/color-picker/ColorPicker.d.ts +3 -0
- package/color-picker/ColorPicker.js +35 -0
- package/color-picker/Swatch.d.ts +12 -0
- package/color-picker/Swatch.js +40 -0
- package/color-picker/colors.d.ts +1 -0
- package/color-picker/colors.js +109 -0
- package/color-picker/getContrastRatio.d.ts +1 -0
- package/color-picker/getContrastRatio.js +23 -0
- package/color-picker/index.d.ts +3 -0
- package/color-picker/index.js +7 -0
- package/color-picker/locale.d.ts +3 -0
- package/color-picker/locale.js +2 -0
- package/color-picker/package.json +4 -0
- package/color-picker/styled-component.d.ts +1 -0
- package/color-picker/styled-component.js +5 -0
- package/color-picker/types.d.ts +15 -0
- package/color-picker/types.js +2 -0
- package/currency/Currency.d.ts +3 -0
- package/currency/Currency.js +14 -0
- package/currency/constants.d.ts +3 -0
- package/currency/constants.js +8 -0
- package/currency/index.d.ts +5 -0
- package/currency/index.js +12 -0
- package/currency/package.json +4 -0
- package/currency/types.d.ts +7 -0
- package/currency/types.js +2 -0
- package/currency/useCurrency.d.ts +2 -0
- package/currency/useCurrency.js +12 -0
- package/currency/utils.d.ts +8 -0
- package/currency/utils.js +11 -0
- package/date-input/Before.d.ts +4 -2
- package/date-input/Before.js +4 -4
- package/date-input/CalendarIconButton.js +7 -1
- package/date-input/DateInput.d.ts +1 -1
- package/date-input/DateInput.js +46 -25
- package/date-input/styled-components.d.ts +2 -2
- package/date-input/styled-components.js +10 -8
- package/date-input/types.d.ts +4 -2
- package/date-picker/Calendar.js +5 -3
- package/date-picker/DateInput.js +16 -14
- package/date-picker/DatePickerContent.d.ts +9 -3
- package/date-picker/DatePickerContent.js +59 -8
- package/date-picker/DatePickerInput.js +9 -6
- package/date-picker/StatelessDatePicker.js +35 -16
- package/date-picker/locale.d.ts +2 -0
- package/date-picker/stateful-container.js +11 -8
- package/date-picker/styled-components.js +53 -3
- package/date-picker/types.d.ts +10 -1
- package/date-picker/utils.d.ts +3 -1
- package/date-picker/utils.js +8 -3
- package/date-time/DateTime.d.ts +3 -0
- package/date-time/DateTime.js +12 -0
- package/date-time/index.d.ts +3 -0
- package/date-time/index.js +9 -0
- package/date-time/package.json +4 -0
- package/date-time/types.d.ts +21 -0
- package/date-time/types.js +18 -0
- package/date-time/useDateTime.d.ts +2 -0
- package/date-time/useDateTime.js +13 -0
- package/date-time/variants.d.ts +4 -0
- package/date-time/variants.js +87 -0
- package/esm/allComponentsAndUtilities.d.ts +1 -0
- package/esm/allComponentsAndUtilities.js +2 -0
- package/esm/asyncSelect/asyncSelect.d.ts +4 -2
- package/esm/asyncSelect/asyncSelect.js +46 -111
- package/esm/asyncSelect/groupedAsyncSelect.d.ts +5 -0
- package/esm/asyncSelect/groupedAsyncSelect.js +37 -0
- package/esm/asyncSelect/helpers.d.ts +8 -2
- package/esm/asyncSelect/helpers.js +31 -3
- package/esm/asyncSelect/hooks/useAsyncOptionHandlers.d.ts +16 -11
- package/esm/asyncSelect/hooks/useAsyncOptionHandlers.js +76 -29
- package/esm/asyncSelect/hooks/useAsyncSelect.d.ts +10 -0
- package/esm/asyncSelect/hooks/useAsyncSelect.js +178 -0
- package/esm/asyncSelect/hooks/useResolveSelectedOptions.d.ts +10 -7
- package/esm/asyncSelect/hooks/useResolveSelectedOptions.js +62 -50
- package/esm/asyncSelect/index.d.ts +4 -1
- package/esm/asyncSelect/index.js +3 -0
- package/esm/asyncSelect/types.d.ts +61 -9
- package/esm/avatar/avatar.js +12 -2
- package/esm/avatar/styled-component.js +7 -22
- package/esm/badge/styled-component.js +10 -8
- package/esm/banner/banner.js +1 -1
- package/esm/breadcrumb/breadcrumb-item.d.ts +7 -0
- package/esm/breadcrumb/breadcrumb-item.js +39 -0
- package/esm/breadcrumb/breadcrumb.d.ts +7 -0
- package/esm/breadcrumb/breadcrumb.js +27 -0
- package/esm/breadcrumb/index.d.ts +4 -0
- package/esm/breadcrumb/index.js +3 -0
- package/esm/breadcrumb/styled-components.d.ts +7 -0
- package/esm/breadcrumb/styled-components.js +15 -0
- package/esm/breadcrumb/types.d.ts +38 -0
- package/esm/breadcrumb/types.js +1 -0
- package/esm/button/Button.d.ts +2 -0
- package/esm/button/Button.js +13 -1
- package/esm/button/IconButton/IconButton.d.ts +2 -4
- package/esm/button/IconButton/IconButton.js +5 -2
- package/esm/button/IconButton/types.d.ts +10 -1
- package/esm/button/basewebAdapter.d.ts +3 -1
- package/esm/button/styled-components.js +30 -25
- package/esm/button/types.d.ts +3 -0
- package/esm/button-group/ButtonGroup.d.ts +1 -0
- package/esm/button-group/ButtonGroup.js +9 -5
- package/esm/button-group/StatefulButtonGroup.d.ts +1 -0
- package/esm/button-group/styled-components.d.ts +34 -0
- package/esm/button-group/styled-components.js +55 -8
- package/esm/button-group/types.d.ts +2 -0
- package/esm/checkbox/basewebAdapters.js +6 -1
- package/esm/color-picker/ColorPalette.d.ts +9 -0
- package/esm/color-picker/ColorPalette.js +22 -0
- package/esm/color-picker/ColorPicker.d.ts +3 -0
- package/esm/color-picker/ColorPicker.js +31 -0
- package/esm/color-picker/Swatch.d.ts +12 -0
- package/esm/color-picker/Swatch.js +37 -0
- package/esm/color-picker/colors.d.ts +1 -0
- package/esm/color-picker/colors.js +106 -0
- package/esm/color-picker/getContrastRatio.d.ts +1 -0
- package/esm/color-picker/getContrastRatio.js +19 -0
- package/esm/color-picker/index.d.ts +3 -0
- package/esm/color-picker/index.js +2 -0
- package/esm/color-picker/locale.d.ts +3 -0
- package/esm/color-picker/locale.js +1 -0
- package/esm/color-picker/styled-component.d.ts +1 -0
- package/esm/color-picker/styled-component.js +2 -0
- package/esm/color-picker/types.d.ts +15 -0
- package/esm/color-picker/types.js +1 -0
- package/esm/currency/Currency.d.ts +3 -0
- package/esm/currency/Currency.js +10 -0
- package/esm/currency/constants.d.ts +3 -0
- package/esm/currency/constants.js +5 -0
- package/esm/currency/index.d.ts +5 -0
- package/esm/currency/index.js +5 -0
- package/esm/currency/types.d.ts +7 -0
- package/esm/currency/types.js +1 -0
- package/esm/currency/useCurrency.d.ts +2 -0
- package/esm/currency/useCurrency.js +8 -0
- package/esm/currency/utils.d.ts +8 -0
- package/esm/currency/utils.js +7 -0
- package/esm/date-input/Before.d.ts +4 -2
- package/esm/date-input/Before.js +4 -4
- package/esm/date-input/CalendarIconButton.js +7 -1
- package/esm/date-input/DateInput.d.ts +1 -1
- package/esm/date-input/DateInput.js +47 -26
- package/esm/date-input/styled-components.d.ts +2 -2
- package/esm/date-input/styled-components.js +10 -7
- package/esm/date-input/types.d.ts +4 -2
- package/esm/date-picker/Calendar.js +5 -3
- package/esm/date-picker/DateInput.js +17 -15
- package/esm/date-picker/DatePickerContent.d.ts +9 -3
- package/esm/date-picker/DatePickerContent.js +60 -9
- package/esm/date-picker/DatePickerInput.js +9 -6
- package/esm/date-picker/StatelessDatePicker.js +35 -16
- package/esm/date-picker/locale.d.ts +2 -0
- package/esm/date-picker/stateful-container.js +11 -8
- package/esm/date-picker/styled-components.js +53 -3
- package/esm/date-picker/types.d.ts +10 -1
- package/esm/date-picker/utils.d.ts +3 -1
- package/esm/date-picker/utils.js +9 -4
- package/esm/date-time/DateTime.d.ts +3 -0
- package/esm/date-time/DateTime.js +8 -0
- package/esm/date-time/index.d.ts +3 -0
- package/esm/date-time/index.js +3 -0
- package/esm/date-time/types.d.ts +21 -0
- package/esm/date-time/types.js +15 -0
- package/esm/date-time/useDateTime.d.ts +2 -0
- package/esm/date-time/useDateTime.js +9 -0
- package/esm/date-time/variants.d.ts +4 -0
- package/esm/date-time/variants.js +84 -0
- package/esm/form-control/form-control.d.ts +1 -1
- package/esm/form-control/form-control.js +17 -12
- package/esm/form-control/styled-component.js +17 -6
- package/esm/helpers/ClearIconButton.js +3 -1
- package/esm/helpers/StyledTombstone.d.ts +1 -0
- package/esm/helpers/StyledTombstone.js +17 -0
- package/esm/helpers/baseui/useConvertOverrides.js +6 -1
- package/esm/helpers/commonStyles.js +3 -6
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +8 -0
- package/esm/helpers/themeHelpers.d.ts +1 -0
- package/esm/helpers/themeHelpers.js +13 -0
- package/esm/hooks/useAutoFocus.js +6 -0
- package/esm/hooks/useMatchMedia.js +13 -2
- package/esm/icon/components/alert-solid.js +2 -0
- package/esm/icon/components/alert.js +2 -0
- package/esm/icon/components/calendar-solid.js +2 -0
- package/esm/icon/components/chevron-down.js +2 -0
- package/esm/icon/components/chevron-left.d.ts +3 -0
- package/esm/icon/components/chevron-left.js +8 -0
- package/esm/icon/components/chevron-right.d.ts +3 -0
- package/esm/icon/components/chevron-right.js +8 -0
- package/esm/icon/components/close.js +2 -0
- package/esm/icon/components/error-clr.js +2 -0
- package/esm/icon/components/error-solid.js +2 -0
- package/esm/icon/components/error.js +2 -0
- package/esm/icon/components/imagePreview.js +2 -0
- package/esm/icon/components/info.js +2 -0
- package/esm/icon/components/play-video.js +2 -0
- package/esm/icon/components/reset-color.d.ts +3 -0
- package/esm/icon/components/reset-color.js +8 -0
- package/esm/icon/components/search.js +2 -0
- package/esm/icon/components/tick.js +2 -0
- package/esm/icon/components/tickCircle-solid.js +2 -0
- package/esm/icon/components/user.js +2 -0
- package/esm/icon/components/video-non-playable.js +2 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/input/basewebAdapters.js +18 -3
- package/esm/input/styled-components.js +8 -6
- package/esm/input/types.d.ts +4 -1
- package/esm/layer/useLayersContextValue.js +3 -2
- package/esm/list/avatar-list-item.d.ts +12 -22
- package/esm/list/avatar-list-item.js +6 -4
- package/esm/list/index.d.ts +1 -1
- package/esm/list/index.js +1 -1
- package/esm/list/list-item.d.ts +3 -1
- package/esm/list/list-item.js +9 -6
- package/esm/list/styled-component.d.ts +1 -0
- package/esm/list/styled-component.js +23 -15
- package/esm/list/types.d.ts +3 -0
- package/esm/locale/en_US.js +26 -0
- package/esm/locale/types.d.ts +19 -0
- package/esm/menu/MenuContext.d.ts +2 -1
- package/esm/menu/MenuContext.js +1 -0
- package/esm/menu/menu-item.d.ts +4 -1
- package/esm/menu/menu-item.js +11 -11
- package/esm/menu/menu.d.ts +1 -0
- package/esm/menu/menu.js +11 -11
- package/esm/menu/types.d.ts +1 -0
- package/esm/menu/useKeyboardNavigation.d.ts +6 -3
- package/esm/menu/useKeyboardNavigation.js +21 -14
- package/esm/menu/useStatefulMenu.d.ts +5 -2
- package/esm/menu/useStatefulMenu.js +14 -8
- package/esm/modal/modal.js +3 -1
- package/esm/modal/overrides.d.ts +2 -2
- package/esm/modal/overrides.js +6 -7
- package/esm/modal/styled-components.js +7 -7
- package/esm/number/Number.d.ts +3 -0
- package/esm/number/Number.js +10 -0
- package/esm/number/constants.d.ts +2 -0
- package/esm/number/constants.js +4 -0
- package/esm/number/index.d.ts +5 -0
- package/esm/number/index.js +5 -0
- package/esm/number/types.d.ts +6 -0
- package/esm/number/types.js +1 -0
- package/esm/number/useNumber.d.ts +2 -0
- package/esm/number/useNumber.js +8 -0
- package/esm/overrides/index.d.ts +1 -1
- package/esm/overrides/index.js +1 -1
- package/esm/overrides/mergeOverrides.d.ts +3 -2
- package/esm/overrides/mergeOverrides.js +1 -1
- package/esm/payment-card/basewebAdapters.d.ts +2 -0
- package/esm/payment-card/basewebAdapters.js +23 -1
- package/esm/payment-card/styled-components.js +25 -6
- package/esm/phone-input/country-select-container.js +1 -1
- package/esm/phone-input/country-select.js +3 -3
- package/esm/phone-input/default-props.d.ts +5 -5
- package/esm/phone-input/default-props.js +7 -7
- package/esm/phone-input/flag-container.js +1 -1
- package/esm/phone-input/phone-input.d.ts +0 -4
- package/esm/phone-input/phone-input.js +20 -12
- package/esm/phone-input/stateful-phone-input-container.js +4 -3
- package/esm/phone-input/stateful-phone-input.d.ts +0 -4
- package/esm/phone-input/styled-components.d.ts +9 -1
- package/esm/phone-input/styled-components.js +21 -7
- package/esm/phone-input/types.d.ts +2 -1
- package/esm/phone-input/utils.d.ts +5 -1
- package/esm/phone-input/utils.js +6 -1
- package/esm/popover/adapter.d.ts +1 -0
- package/esm/popover/adapter.js +15 -0
- package/esm/popover/overrides.js +8 -19
- package/esm/popover/popover.d.ts +1 -0
- package/esm/popover/popover.js +9 -4
- package/esm/popover/stateful-popover.js +2 -2
- package/esm/popover/types.d.ts +3 -0
- package/esm/popover/utils.d.ts +12 -0
- package/esm/popover/utils.js +9 -0
- package/esm/progress/linear/styled-component.d.ts +1 -1
- package/esm/progress/linear/styled-component.js +5 -5
- package/esm/radio/styled-components.js +5 -5
- package/esm/search/index.d.ts +1 -0
- package/esm/search/index.js +1 -0
- package/esm/search/search.d.ts +1 -1
- package/esm/search/search.js +15 -6
- package/esm/search/stateful-search.d.ts +3 -0
- package/esm/search/stateful-search.js +15 -0
- package/esm/search/styled-components.d.ts +1 -10
- package/esm/search/styled-components.js +54 -24
- package/esm/search/types.d.ts +8 -2
- package/esm/select/base-select.d.ts +22 -5
- package/esm/select/base-select.js +174 -82
- package/esm/select/constants.d.ts +3 -0
- package/esm/select/constants.js +3 -1
- package/esm/select/default-props.d.ts +1 -0
- package/esm/select/default-props.js +3 -0
- package/esm/select/index.d.ts +2 -2
- package/esm/select/index.js +2 -2
- package/esm/select/locale.d.ts +4 -0
- package/esm/select/mobileSelect/MobileSheet.js +3 -1
- package/esm/select/multi-value.js +22 -12
- package/esm/select/overlaySelect/OverlaySelect.js +1 -0
- package/esm/select/overlaySelect/hooks/useOverlaySelectOverrides.d.ts +2 -1
- package/esm/select/overlaySelect/hooks/useOverlaySelectOverrides.js +13 -16
- package/esm/select/overrides.d.ts +3 -0
- package/esm/select/overrides.js +19 -6
- package/esm/select/select.d.ts +1 -0
- package/esm/select/select.js +9 -3
- package/esm/select/selectMenuAdapter/CollapsibleSelectMenu.d.ts +118 -0
- package/esm/select/selectMenuAdapter/CollapsibleSelectMenu.js +70 -0
- package/esm/select/selectMenuAdapter/SelectMenuAdapter.d.ts +2 -34
- package/esm/select/selectMenuAdapter/SelectMenuAdapter.js +3 -3
- package/esm/select/selectMenuAdapter/SelectMenuItem.d.ts +4 -1
- package/esm/select/selectMenuAdapter/hooks/useGetExpandedGroup.d.ts +6 -0
- package/esm/select/selectMenuAdapter/hooks/useGetExpandedGroup.js +16 -0
- package/esm/select/selectMenuAdapter/types.d.ts +42 -0
- package/esm/select/selectMenuAdapter/types.js +1 -0
- package/esm/select/stateful-select.d.ts +1 -0
- package/esm/select/styled-component.d.ts +10 -1
- package/esm/select/styled-component.js +39 -15
- package/esm/select/types.d.ts +23 -1
- package/esm/select/types.js +1 -0
- package/esm/select/utils/default-filter-options.d.ts +2 -1
- package/esm/select/utils/default-filter-options.js +5 -1
- package/esm/select/utils/hidden-element.d.ts +6 -0
- package/esm/select/utils/hidden-element.js +16 -0
- package/esm/select/utils/merge-options.d.ts +2 -0
- package/esm/select/utils/merge-options.js +18 -0
- package/esm/select/utils/test-utils.d.ts +1 -0
- package/esm/select/utils/test-utils.js +7 -0
- package/esm/slider/styled-components.js +4 -4
- package/esm/snackbar/Snackbar.js +12 -12
- package/esm/snackbar/styled-component.js +9 -6
- package/esm/spacewebProvider/SpacewebProvider.d.ts +2 -0
- package/esm/spacewebProvider/SpacewebProvider.js +9 -9
- package/esm/stack/stack.js +6 -13
- package/esm/style/_buildUtils.d.ts +1 -1
- package/esm/style/_buildUtils.js +3 -1
- package/esm/style/_parseStyle.js +7 -2
- package/esm/style/useMemoizedStyletron.js +6 -1
- package/esm/switch/styled-components.js +3 -3
- package/esm/tag/avatar-tag.js +23 -16
- package/esm/tag/styled-components.js +32 -27
- package/esm/tag/tag.js +20 -12
- package/esm/tag/types.d.ts +2 -2
- package/esm/tag/utils.d.ts +50 -0
- package/esm/tag/utils.js +64 -0
- package/esm/textarea/basewebAdapters.js +3 -3
- package/esm/textarea/textarea.js +3 -3
- package/esm/textarea/types.d.ts +2 -2
- package/esm/theme/Provider.d.ts +10 -0
- package/esm/theme/Provider.js +61 -0
- package/esm/theme/context.d.ts +1 -10
- package/esm/theme/context.js +1 -61
- package/esm/theme/index.d.ts +1 -0
- package/esm/theme/index.js +1 -0
- package/esm/time-picker/TimePicker.js +4 -1
- package/esm/time-range-picker/RangeSelectorContainer.js +1 -1
- package/esm/time-range-picker/TimeRangePicker.js +20 -12
- package/esm/time-range-picker/index.d.ts +1 -1
- package/esm/time-range-picker/index.js +1 -1
- package/esm/time-range-picker/types.d.ts +1 -2
- package/esm/time-range-picker/utils.d.ts +33 -4
- package/esm/time-range-picker/utils.js +49 -15
- package/esm/time-zone-picker/types.d.ts +2 -0
- package/esm/tooltip/overrides.js +0 -1
- package/esm/tooltip/stateful-tooltip.js +2 -2
- package/esm/tooltip/tooltip.d.ts +1 -1
- package/esm/tooltip/tooltip.js +5 -2
- package/esm/tooltip/types.d.ts +2 -0
- package/esm/types.d.ts +2 -1
- package/esm/typography/Typography.js +14 -1
- package/esm/typography/constants.d.ts +56 -0
- package/esm/typography/constants.js +56 -0
- package/esm/typography/index.d.ts +1 -0
- package/esm/typography/index.js +1 -0
- package/esm/typography/styled-components.js +12 -4
- package/esm/typography/types.d.ts +1 -1
- package/esm/utils/intlNumberFormatUtils/index.d.ts +7 -0
- package/esm/utils/intlNumberFormatUtils/index.js +36 -0
- package/esm/utils/intlNumberFormatUtils/types.d.ts +21 -0
- package/esm/utils/intlNumberFormatUtils/types.js +6 -0
- package/form-control/form-control.d.ts +1 -1
- package/form-control/form-control.js +16 -11
- package/form-control/styled-component.js +17 -6
- package/helpers/ClearIconButton.js +3 -1
- package/helpers/StyledTombstone.d.ts +1 -0
- package/helpers/StyledTombstone.js +21 -0
- package/helpers/baseui/useConvertOverrides.js +6 -1
- package/helpers/commonStyles.js +3 -6
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +10 -1
- package/helpers/themeHelpers.d.ts +1 -0
- package/helpers/themeHelpers.js +15 -1
- package/hooks/useAutoFocus.js +6 -0
- package/hooks/useMatchMedia.js +13 -2
- package/icon/components/alert-solid.js +2 -0
- package/icon/components/alert.js +2 -0
- package/icon/components/calendar-solid.js +2 -0
- package/icon/components/chevron-down.js +2 -0
- package/icon/components/chevron-left.d.ts +3 -0
- package/icon/components/chevron-left.js +11 -0
- package/icon/components/chevron-right.d.ts +3 -0
- package/icon/components/chevron-right.js +11 -0
- package/icon/components/close.js +2 -0
- package/icon/components/error-clr.js +2 -0
- package/icon/components/error-solid.js +2 -0
- package/icon/components/error.js +2 -0
- package/icon/components/imagePreview.js +2 -0
- package/icon/components/info.js +2 -0
- package/icon/components/play-video.js +2 -0
- package/icon/components/reset-color.d.ts +3 -0
- package/icon/components/reset-color.js +11 -0
- package/icon/components/search.js +2 -0
- package/icon/components/tick.js +2 -0
- package/icon/components/tickCircle-solid.js +2 -0
- package/icon/components/user.js +2 -0
- package/icon/components/video-non-playable.js +2 -0
- package/index.d.ts +2 -0
- package/index.js +3 -0
- package/input/basewebAdapters.js +18 -3
- package/input/styled-components.js +7 -5
- package/input/types.d.ts +4 -1
- package/layer/useLayersContextValue.js +2 -1
- package/list/avatar-list-item.d.ts +12 -22
- package/list/avatar-list-item.js +5 -3
- package/list/index.d.ts +1 -1
- package/list/index.js +2 -1
- package/list/list-item.d.ts +3 -1
- package/list/list-item.js +9 -6
- package/list/styled-component.d.ts +1 -0
- package/list/styled-component.js +24 -16
- package/list/types.d.ts +3 -0
- package/locale/en_US.js +26 -0
- package/locale/types.d.ts +19 -0
- package/menu/MenuContext.d.ts +2 -1
- package/menu/MenuContext.js +1 -0
- package/menu/menu-item.d.ts +4 -1
- package/menu/menu-item.js +11 -11
- package/menu/menu.d.ts +1 -0
- package/menu/menu.js +11 -11
- package/menu/types.d.ts +1 -0
- package/menu/useKeyboardNavigation.d.ts +6 -3
- package/menu/useKeyboardNavigation.js +21 -14
- package/menu/useStatefulMenu.d.ts +5 -2
- package/menu/useStatefulMenu.js +14 -8
- package/modal/modal.js +3 -1
- package/modal/overrides.d.ts +2 -2
- package/modal/overrides.js +6 -7
- package/modal/styled-components.js +7 -7
- package/number/Number.d.ts +3 -0
- package/number/Number.js +14 -0
- package/number/constants.d.ts +2 -0
- package/number/constants.js +7 -0
- package/number/index.d.ts +5 -0
- package/number/index.js +12 -0
- package/number/package.json +4 -0
- package/number/types.d.ts +6 -0
- package/number/types.js +2 -0
- package/number/useNumber.d.ts +2 -0
- package/number/useNumber.js +12 -0
- package/overrides/index.d.ts +1 -1
- package/overrides/index.js +2 -1
- package/overrides/mergeOverrides.d.ts +3 -2
- package/overrides/mergeOverrides.js +2 -1
- package/package.json +8 -5
- package/payment-card/basewebAdapters.d.ts +2 -0
- package/payment-card/basewebAdapters.js +23 -1
- package/payment-card/styled-components.js +24 -5
- package/phone-input/country-select-container.js +1 -1
- package/phone-input/country-select.js +3 -3
- package/phone-input/default-props.d.ts +5 -5
- package/phone-input/default-props.js +8 -7
- package/phone-input/flag-container.js +1 -1
- package/phone-input/phone-input.d.ts +0 -4
- package/phone-input/phone-input.js +19 -11
- package/phone-input/stateful-phone-input-container.js +4 -3
- package/phone-input/stateful-phone-input.d.ts +0 -4
- package/phone-input/styled-components.d.ts +9 -1
- package/phone-input/styled-components.js +22 -7
- package/phone-input/types.d.ts +2 -1
- package/phone-input/utils.d.ts +5 -1
- package/phone-input/utils.js +7 -1
- package/popover/adapter.d.ts +1 -0
- package/popover/adapter.js +16 -1
- package/popover/overrides.js +8 -19
- package/popover/popover.d.ts +1 -0
- package/popover/popover.js +8 -3
- package/popover/stateful-popover.js +2 -2
- package/popover/types.d.ts +3 -0
- package/popover/utils.d.ts +12 -0
- package/popover/utils.js +11 -1
- package/progress/linear/styled-component.d.ts +1 -1
- package/progress/linear/styled-component.js +5 -5
- package/radio/styled-components.js +5 -5
- package/search/index.d.ts +1 -0
- package/search/index.js +3 -1
- package/search/search.d.ts +1 -1
- package/search/search.js +14 -5
- package/search/stateful-search.d.ts +3 -0
- package/search/stateful-search.js +19 -0
- package/search/styled-components.d.ts +1 -10
- package/search/styled-components.js +56 -25
- package/search/types.d.ts +8 -2
- package/select/base-select.d.ts +22 -5
- package/select/base-select.js +172 -80
- package/select/constants.d.ts +3 -0
- package/select/constants.js +4 -2
- package/select/default-props.d.ts +1 -0
- package/select/default-props.js +3 -0
- package/select/index.d.ts +2 -2
- package/select/index.js +4 -1
- package/select/locale.d.ts +4 -0
- package/select/mobileSelect/MobileSheet.js +3 -1
- package/select/multi-value.js +21 -11
- package/select/overlaySelect/OverlaySelect.js +1 -0
- package/select/overlaySelect/hooks/useOverlaySelectOverrides.d.ts +2 -1
- package/select/overlaySelect/hooks/useOverlaySelectOverrides.js +13 -16
- package/select/overrides.d.ts +3 -0
- package/select/overrides.js +20 -6
- package/select/select.d.ts +1 -0
- package/select/select.js +9 -3
- package/select/selectMenuAdapter/CollapsibleSelectMenu.d.ts +118 -0
- package/select/selectMenuAdapter/CollapsibleSelectMenu.js +74 -0
- package/select/selectMenuAdapter/SelectMenuAdapter.d.ts +2 -34
- package/select/selectMenuAdapter/SelectMenuAdapter.js +3 -3
- package/select/selectMenuAdapter/SelectMenuItem.d.ts +4 -1
- package/select/selectMenuAdapter/hooks/useGetExpandedGroup.d.ts +6 -0
- package/select/selectMenuAdapter/hooks/useGetExpandedGroup.js +20 -0
- package/select/selectMenuAdapter/types.d.ts +42 -0
- package/select/selectMenuAdapter/types.js +2 -0
- package/select/stateful-select.d.ts +1 -0
- package/select/styled-component.d.ts +10 -1
- package/select/styled-component.js +38 -14
- package/select/types.d.ts +23 -1
- package/select/types.js +2 -1
- package/select/utils/default-filter-options.d.ts +2 -1
- package/select/utils/default-filter-options.js +6 -5
- package/select/utils/hidden-element.d.ts +6 -0
- package/select/utils/hidden-element.js +19 -0
- package/select/utils/merge-options.d.ts +2 -0
- package/select/utils/merge-options.js +22 -0
- package/select/utils/test-utils.d.ts +1 -0
- package/select/utils/test-utils.js +11 -0
- package/slider/styled-components.js +4 -4
- package/snackbar/Snackbar.js +12 -12
- package/snackbar/styled-component.js +9 -6
- package/spacewebProvider/SpacewebProvider.d.ts +2 -0
- package/spacewebProvider/SpacewebProvider.js +8 -8
- package/stack/stack.js +6 -13
- package/style/_buildUtils.d.ts +1 -1
- package/style/_buildUtils.js +3 -1
- package/style/_parseStyle.js +7 -2
- package/style/useMemoizedStyletron.js +6 -1
- package/switch/styled-components.js +3 -3
- package/tag/avatar-tag.js +23 -16
- package/tag/styled-components.js +32 -27
- package/tag/tag.js +19 -11
- package/tag/types.d.ts +2 -2
- package/tag/utils.d.ts +50 -0
- package/tag/utils.js +67 -1
- package/textarea/basewebAdapters.js +2 -2
- package/textarea/textarea.js +2 -2
- package/textarea/types.d.ts +2 -2
- package/theme/Provider.d.ts +10 -0
- package/theme/Provider.js +65 -0
- package/theme/context.d.ts +1 -10
- package/theme/context.js +1 -61
- package/theme/index.d.ts +1 -0
- package/theme/index.js +1 -0
- package/time-picker/TimePicker.js +4 -1
- package/time-range-picker/RangeSelectorContainer.js +1 -1
- package/time-range-picker/TimeRangePicker.js +19 -11
- package/time-range-picker/index.d.ts +1 -1
- package/time-range-picker/index.js +4 -1
- package/time-range-picker/types.d.ts +1 -2
- package/time-range-picker/utils.d.ts +33 -4
- package/time-range-picker/utils.js +53 -17
- package/time-zone-picker/types.d.ts +2 -0
- package/tooltip/overrides.js +0 -1
- package/tooltip/stateful-tooltip.js +2 -2
- package/tooltip/tooltip.d.ts +1 -1
- package/tooltip/tooltip.js +5 -2
- package/tooltip/types.d.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types.d.ts +2 -1
- package/typography/Typography.js +14 -1
- package/typography/constants.d.ts +56 -0
- package/typography/constants.js +57 -1
- package/typography/index.d.ts +1 -0
- package/typography/index.js +3 -1
- package/typography/styled-components.js +11 -3
- package/typography/types.d.ts +1 -1
- package/utils/intlNumberFormatUtils/index.d.ts +7 -0
- package/utils/intlNumberFormatUtils/index.js +40 -0
- package/utils/intlNumberFormatUtils/types.d.ts +21 -0
- package/utils/intlNumberFormatUtils/types.js +9 -0
- package/utils/package.json +4 -0
- package/esm/icon/components/chevron-right-solid.d.ts +0 -3
- package/esm/icon/components/chevron-right-solid.js +0 -6
- package/icon/components/chevron-right-solid.d.ts +0 -3
- package/icon/components/chevron-right-solid.js +0 -9
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
1
|
+
import { __assign, __read, __spreadArray } from "tslib";
|
|
2
|
+
import { normalizeOptions } from 'baseui/select/utils';
|
|
3
|
+
import { UNGROUPED_ID } from '../select/constants';
|
|
2
4
|
export var getNoResultsMsg = function (_a) {
|
|
3
5
|
var isLoading = _a.isLoading, minimumInput = _a.minimumInput, inputText = _a.inputText, noResultsMsg = _a.noResultsMsg, searchingText = _a.searchingText, emptyInputMsg = _a.emptyInputMsg;
|
|
4
6
|
if (isLoading) {
|
|
@@ -15,8 +17,34 @@ export var shouldPaginate = function (element, paginationBuffer) {
|
|
|
15
17
|
return element.scrollHeight > element.clientHeight &&
|
|
16
18
|
element.scrollTop >= element.scrollHeight - element.clientHeight - paginationBuffer;
|
|
17
19
|
};
|
|
20
|
+
export var getInputValue = function (inputRef) { var _a; return ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) || ''; };
|
|
21
|
+
export var arrayToGroupedOptions = function (options) {
|
|
22
|
+
if (!Array.isArray(options)) {
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
return options.reduce(function (acc, option) {
|
|
26
|
+
acc[option.__optgroup || UNGROUPED_ID] = acc[option.__optgroup || UNGROUPED_ID] || [];
|
|
27
|
+
acc[option.__optgroup || UNGROUPED_ID].push(option);
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
};
|
|
31
|
+
export var mergeOptions = function (a, b) {
|
|
32
|
+
var groupedA = arrayToGroupedOptions(a), groupedB = arrayToGroupedOptions(b);
|
|
33
|
+
var allKeys = Object.keys(__assign(__assign({}, groupedA), groupedB));
|
|
34
|
+
return allKeys.reduce(function (acc, key) {
|
|
35
|
+
acc[key] = __spreadArray(__spreadArray([], __read((groupedA[key] || [])), false), __read((groupedB[key] || [])), false);
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
};
|
|
39
|
+
export var initGroupOptions = function (groupConfig) {
|
|
40
|
+
return groupConfig.reduce(function (acc, _a) {
|
|
41
|
+
var id = _a.id;
|
|
42
|
+
acc[id] = [];
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
};
|
|
18
46
|
export var addOptionsInMap = function (optionsMap, options, valueKey) {
|
|
19
|
-
var newOptions = options.filter(function (option) { return !optionsMap[option[valueKey]]; });
|
|
47
|
+
var newOptions = normalizeOptions(options).filter(function (option) { return !optionsMap[option[valueKey]]; });
|
|
20
48
|
//Not creating a new map (reference) if there are no new options to be added
|
|
21
49
|
if (newOptions.length) {
|
|
22
50
|
var newOptionsMap_1 = __assign({}, optionsMap);
|
|
@@ -28,4 +56,4 @@ export var addOptionsInMap = function (optionsMap, options, valueKey) {
|
|
|
28
56
|
}
|
|
29
57
|
return optionsMap;
|
|
30
58
|
};
|
|
31
|
-
export
|
|
59
|
+
export { normalizeOptions };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Aneree on 15/01/21.
|
|
3
3
|
*/
|
|
4
|
-
import { MutableRefObject } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import { SetStateFunc, AllOptionsMap, AsyncSelectProps } from '../types';
|
|
4
|
+
import { MutableRefObject, UIEvent } from 'react';
|
|
5
|
+
import { Options } from '../../select';
|
|
6
|
+
import { SetStateFunc, AllOptionsMap, AsyncSelectProps, LoadOptions, GroupedOptions, GroupConfig } from '../types';
|
|
7
|
+
import { Value } from 'baseui/select/types';
|
|
7
8
|
interface UseAsyncOptionHandlersArgs {
|
|
8
9
|
valueKey: string;
|
|
9
10
|
isLoading: boolean;
|
|
@@ -11,18 +12,22 @@ interface UseAsyncOptionHandlersArgs {
|
|
|
11
12
|
paginationBuffer?: number;
|
|
12
13
|
inputRef: MutableRefObject<HTMLInputElement | null>;
|
|
13
14
|
setIsLoading: SetStateFunc<boolean>;
|
|
14
|
-
setOptions: SetStateFunc<
|
|
15
|
+
setOptions: SetStateFunc<GroupedOptions>;
|
|
15
16
|
setAllOptionsMap: SetStateFunc<AllOptionsMap>;
|
|
16
|
-
loadOptions:
|
|
17
|
-
options: Array<Option>;
|
|
18
|
-
complete: boolean;
|
|
19
|
-
}>;
|
|
17
|
+
loadOptions: LoadOptions;
|
|
20
18
|
createOption: AsyncSelectProps['createOption'];
|
|
19
|
+
groupConfig: GroupConfig;
|
|
20
|
+
selectedOptions?: Value;
|
|
21
|
+
moveSelectedOptionsToTop: boolean;
|
|
21
22
|
}
|
|
22
|
-
declare const useAsyncOptionHandlers: ({ inputRef, valueKey, isLoading, setOptions, loadOptions, minimumInput, setIsLoading, paginationBuffer, setAllOptionsMap, createOption: propsCreateOption, }: UseAsyncOptionHandlersArgs) => {
|
|
23
|
-
onPaginate: (event:
|
|
23
|
+
declare const useAsyncOptionHandlers: ({ inputRef, valueKey, isLoading, setOptions, loadOptions, minimumInput, setIsLoading, paginationBuffer, setAllOptionsMap, createOption: propsCreateOption, groupConfig, selectedOptions, moveSelectedOptionsToTop, }: UseAsyncOptionHandlersArgs) => {
|
|
24
|
+
onPaginate: (event: UIEvent<HTMLElement>, itemGroup?: string) => void;
|
|
24
25
|
onInputChange: () => void;
|
|
25
|
-
fetchOptions: (
|
|
26
|
+
fetchOptions: (itemGroups: {
|
|
27
|
+
group: string;
|
|
28
|
+
pageNumber: number;
|
|
29
|
+
}[]) => Promise<void>;
|
|
26
30
|
createOption: ((label: string) => Promise<Options>) | undefined;
|
|
31
|
+
resultCountMap: Record<string, number | undefined>;
|
|
27
32
|
};
|
|
28
33
|
export { useAsyncOptionHandlers };
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Created by Aneree on 15/01/21.
|
|
4
4
|
*/
|
|
5
|
-
import { useRef, useCallback } from 'react';
|
|
5
|
+
import { useRef, useCallback, useState } from 'react';
|
|
6
6
|
//hooks
|
|
7
7
|
import { useLatest } from '../../hooks/useLatest';
|
|
8
|
-
|
|
9
|
-
import {
|
|
8
|
+
import { shouldPaginate, addOptionsInMap, getInputValue, initGroupOptions, arrayToGroupedOptions, } from '../helpers';
|
|
9
|
+
import { UNGROUPED_ID } from '../../select/constants';
|
|
10
10
|
var useAsyncOptionHandlers = function (_a) {
|
|
11
|
-
var inputRef = _a.inputRef, valueKey = _a.valueKey, isLoading = _a.isLoading, setOptions = _a.setOptions, loadOptions = _a.loadOptions, minimumInput = _a.minimumInput, setIsLoading = _a.setIsLoading, paginationBuffer = _a.paginationBuffer, setAllOptionsMap = _a.setAllOptionsMap, propsCreateOption = _a.createOption;
|
|
12
|
-
var pageRef = useRef(
|
|
13
|
-
var completeRef = useRef(
|
|
14
|
-
var isPaginatingRef = useRef(
|
|
11
|
+
var inputRef = _a.inputRef, valueKey = _a.valueKey, isLoading = _a.isLoading, setOptions = _a.setOptions, loadOptions = _a.loadOptions, minimumInput = _a.minimumInput, setIsLoading = _a.setIsLoading, paginationBuffer = _a.paginationBuffer, setAllOptionsMap = _a.setAllOptionsMap, propsCreateOption = _a.createOption, groupConfig = _a.groupConfig, selectedOptions = _a.selectedOptions, moveSelectedOptionsToTop = _a.moveSelectedOptionsToTop;
|
|
12
|
+
var pageRef = useRef({});
|
|
13
|
+
var completeRef = useRef({});
|
|
14
|
+
var isPaginatingRef = useRef({});
|
|
15
|
+
var _b = __read(useState({}), 2), resultCountMap = _b[0], setResultCountMap = _b[1];
|
|
16
|
+
var updateResultCount = useCallback(function (groupId, count) { return setResultCountMap(function (prev) {
|
|
17
|
+
var _a;
|
|
18
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[groupId] = count, _a)));
|
|
19
|
+
}); }, []);
|
|
15
20
|
var valueKeyRef = useLatest(valueKey);
|
|
16
21
|
var loadOptionsRef = useLatest(loadOptions);
|
|
17
22
|
var minimumInputRef = useLatest(minimumInput);
|
|
18
23
|
var paginationBufferRef = useLatest(paginationBuffer);
|
|
19
|
-
var
|
|
20
|
-
|
|
24
|
+
var selectedOptionsRef = useLatest(selectedOptions);
|
|
25
|
+
var fetchOptions = useCallback(function (itemGroups) { return __awaiter(void 0, void 0, void 0, function () {
|
|
26
|
+
var timeoutId, loadedOptions, groupedOptions_1, selectedOptionsByGroup_1;
|
|
27
|
+
var _a;
|
|
21
28
|
return __generator(this, function (_b) {
|
|
22
29
|
switch (_b.label) {
|
|
23
30
|
case 0:
|
|
@@ -25,15 +32,39 @@ var useAsyncOptionHandlers = function (_a) {
|
|
|
25
32
|
_b.label = 1;
|
|
26
33
|
case 1:
|
|
27
34
|
_b.trys.push([1, , 3, 4]);
|
|
28
|
-
return [4 /*yield*/, loadOptionsRef.current(getInputValue(inputRef),
|
|
35
|
+
return [4 /*yield*/, loadOptionsRef.current(getInputValue(inputRef), itemGroups)];
|
|
29
36
|
case 2:
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
loadedOptions = _b.sent();
|
|
38
|
+
groupedOptions_1 = {};
|
|
39
|
+
selectedOptionsByGroup_1 = arrayToGroupedOptions((_a = selectedOptionsRef.current) !== null && _a !== void 0 ? _a : []);
|
|
40
|
+
loadedOptions.groups.forEach(function (_a) {
|
|
41
|
+
var options = _a.options, complete = _a.complete, group = _a.group, count = _a.count;
|
|
42
|
+
groupedOptions_1[group] = options;
|
|
43
|
+
completeRef.current[group] = complete;
|
|
44
|
+
updateResultCount(group, count);
|
|
45
|
+
});
|
|
46
|
+
setAllOptionsMap(function (prevOptions) { return addOptionsInMap(prevOptions, groupedOptions_1, valueKeyRef.current); });
|
|
32
47
|
//Merge options when it's not the first page
|
|
33
|
-
setOptions(function (prevOptions) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
setOptions(function (prevOptions) {
|
|
49
|
+
var updatedOptions = __assign({}, prevOptions);
|
|
50
|
+
itemGroups.forEach(function (_a) {
|
|
51
|
+
var group = _a.group, pageNumber = _a.pageNumber;
|
|
52
|
+
if (pageNumber) {
|
|
53
|
+
updatedOptions[group] = __spreadArray(__spreadArray([], __read(prevOptions[group]), false), __read(groupedOptions_1[group]), false);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
updatedOptions[group] =
|
|
57
|
+
moveSelectedOptionsToTop && selectedOptionsByGroup_1[group]
|
|
58
|
+
? __spreadArray(__spreadArray([], __read(selectedOptionsByGroup_1[group]), false), __read(groupedOptions_1[group]), false) : groupedOptions_1[group];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return updatedOptions;
|
|
62
|
+
});
|
|
63
|
+
itemGroups.forEach(function (_a) {
|
|
64
|
+
var group = _a.group, pageNumber = _a.pageNumber;
|
|
65
|
+
pageRef.current[group] = pageNumber;
|
|
66
|
+
isPaginatingRef.current[group] = false;
|
|
67
|
+
});
|
|
37
68
|
return [3 /*break*/, 4];
|
|
38
69
|
case 3:
|
|
39
70
|
clearTimeout(timeoutId);
|
|
@@ -42,34 +73,49 @@ var useAsyncOptionHandlers = function (_a) {
|
|
|
42
73
|
case 4: return [2 /*return*/];
|
|
43
74
|
}
|
|
44
75
|
});
|
|
45
|
-
}); }, [
|
|
46
|
-
|
|
76
|
+
}); }, [
|
|
77
|
+
inputRef,
|
|
78
|
+
loadOptionsRef,
|
|
79
|
+
setAllOptionsMap,
|
|
80
|
+
setIsLoading,
|
|
81
|
+
setOptions,
|
|
82
|
+
updateResultCount,
|
|
83
|
+
valueKeyRef,
|
|
84
|
+
selectedOptionsRef,
|
|
85
|
+
]);
|
|
86
|
+
var onPaginate = useCallback(function (event, itemGroup) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (itemGroup === void 0) { itemGroup = UNGROUPED_ID; }
|
|
47
89
|
if (!isLoading &&
|
|
48
|
-
!isPaginatingRef.current &&
|
|
49
|
-
!completeRef.current &&
|
|
90
|
+
!isPaginatingRef.current[itemGroup] &&
|
|
91
|
+
!completeRef.current[itemGroup] &&
|
|
50
92
|
shouldPaginate(event.target, paginationBufferRef.current)) {
|
|
51
|
-
isPaginatingRef.current = true;
|
|
52
|
-
fetchOptions(pageRef.current + 1);
|
|
93
|
+
isPaginatingRef.current[itemGroup] = true;
|
|
94
|
+
fetchOptions([{ group: itemGroup, pageNumber: ((_a = pageRef.current[itemGroup]) !== null && _a !== void 0 ? _a : 0) + 1 }]);
|
|
53
95
|
}
|
|
54
96
|
}, [fetchOptions, isLoading]);
|
|
55
97
|
var onInputChange = useCallback(function () {
|
|
56
98
|
if (getInputValue(inputRef).length < minimumInputRef.current) {
|
|
57
99
|
//reset state
|
|
58
100
|
setIsLoading(false);
|
|
59
|
-
setOptions(
|
|
60
|
-
pageRef.current =
|
|
61
|
-
completeRef.current =
|
|
101
|
+
setOptions(initGroupOptions(groupConfig));
|
|
102
|
+
pageRef.current = {};
|
|
103
|
+
completeRef.current = {};
|
|
104
|
+
setResultCountMap({});
|
|
62
105
|
return;
|
|
63
106
|
}
|
|
64
|
-
fetchOptions(
|
|
65
|
-
|
|
107
|
+
fetchOptions(groupConfig.map(function (_a) {
|
|
108
|
+
var id = _a.id;
|
|
109
|
+
return ({ group: id, pageNumber: 0 });
|
|
110
|
+
}));
|
|
111
|
+
}, [fetchOptions, groupConfig]);
|
|
66
112
|
var createOption = useCallback(function (label) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
113
|
var createdOptions, err_1;
|
|
68
114
|
return __generator(this, function (_a) {
|
|
69
115
|
switch (_a.label) {
|
|
70
116
|
case 0:
|
|
71
117
|
if (!propsCreateOption) {
|
|
72
|
-
throw 'Spaceweb: [AsyncSelect] `createOption` is not defined';
|
|
118
|
+
throw new Error('Spaceweb: [AsyncSelect] `createOption` is not defined');
|
|
73
119
|
}
|
|
74
120
|
_a.label = 1;
|
|
75
121
|
case 1:
|
|
@@ -94,6 +140,7 @@ var useAsyncOptionHandlers = function (_a) {
|
|
|
94
140
|
onInputChange: onInputChange,
|
|
95
141
|
fetchOptions: fetchOptions,
|
|
96
142
|
createOption: propsCreateOption ? createOption : undefined,
|
|
143
|
+
resultCountMap: resultCountMap,
|
|
97
144
|
};
|
|
98
145
|
};
|
|
99
146
|
export { useAsyncOptionHandlers };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OnChangeParams, SelectProps } from '../../select';
|
|
2
|
+
import { GroupedAsyncSelectProps, Id } from '../types';
|
|
3
|
+
export declare type UseAsyncSelectParams = Omit<GroupedAsyncSelectProps, 'onChange'> & {
|
|
4
|
+
onChange?: (params: OnChangeParams & {
|
|
5
|
+
valueKeys: Id[];
|
|
6
|
+
}) => unknown;
|
|
7
|
+
};
|
|
8
|
+
export declare const useAsyncSelect: (params: UseAsyncSelectParams) => SelectProps & {
|
|
9
|
+
resultCountMap: Record<string, number | undefined>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { __assign, __read, __rest, __spreadArray } from "tslib";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import _keyBy from 'lodash/keyBy';
|
|
4
|
+
import _reduce from 'lodash/reduce';
|
|
5
|
+
import _isObject from 'lodash/isObject';
|
|
6
|
+
//hooks
|
|
7
|
+
import { useLocale } from '../../locale';
|
|
8
|
+
import { useLatest } from '../../hooks/useLatest';
|
|
9
|
+
import useCombinedRefs from '../../hooks/useCombinedRef';
|
|
10
|
+
import { useInputChangeHandler } from './useInputChangeHandler';
|
|
11
|
+
import { useAsyncOptionHandlers } from './useAsyncOptionHandlers';
|
|
12
|
+
import { useResolveSelectedOptions } from './useResolveSelectedOptions';
|
|
13
|
+
//helpers
|
|
14
|
+
import { getInputValue, getNoResultsMsg, initGroupOptions, mergeOptions } from '../helpers';
|
|
15
|
+
import { normalizeOptions } from 'baseui/select/utils';
|
|
16
|
+
import { add$props } from '../../helpers';
|
|
17
|
+
//utils
|
|
18
|
+
import { mergeOverrides } from '../../overrides';
|
|
19
|
+
import defaultProps from '../../select/default-props';
|
|
20
|
+
import { LOADING_KEY } from '../../select/constants';
|
|
21
|
+
var EMPTY_OBJ = {};
|
|
22
|
+
export var useAsyncSelect = function (params) {
|
|
23
|
+
var loadOptions = params.loadOptions, searchingText = params.searchingText, paginationBuffer = params.paginationBuffer, debounceInterval = params.debounceInterval, resolveSelectedOptions = params.resolveSelectedOptions, _a = params.minimumInput, minimumInput = _a === void 0 ? 0 : _a, _b = params.loadOnMount, loadOnMount = _b === void 0 ? false : _b, _c = params.loadOnFocus, loadOnFocus = _c === void 0 ? false : _c, _d = params.initialOptions, initialOptions = _d === void 0 ? EMPTY_OBJ : _d, _e = params.listenAllInputChanges, listenAllInputChanges = _e === void 0 ? true : _e, groupConfig = params.groupConfig, resolveValuesOnUpdate = params.resolveValuesOnUpdate, hideUnresolvedValues = params.hideUnresolvedValues, _f = params.moveSelectedOptionsToTop, moveSelectedOptionsToTop = _f === void 0 ? false : _f,
|
|
24
|
+
//selectProps
|
|
25
|
+
onInputChange = params.onInputChange, noResultsMsg = params.noResultsMsg, overrides = params.overrides, groupedValue = params.value, controlRef = params.controlRef, propsInputRef = params.inputRef, propsCreateOption = params.createOption, _g = params.valueKey, valueKey = _g === void 0 ? defaultProps.valueKey : _g, _h = params.labelKey, labelKey = _h === void 0 ? defaultProps.labelKey : _h, propsOnChange = params.onChange, restSelectProps = __rest(params, ["loadOptions", "searchingText", "paginationBuffer", "debounceInterval", "resolveSelectedOptions", "minimumInput", "loadOnMount", "loadOnFocus", "initialOptions", "listenAllInputChanges", "groupConfig", "resolveValuesOnUpdate", "hideUnresolvedValues", "moveSelectedOptionsToTop", "onInputChange", "noResultsMsg", "overrides", "value", "controlRef", "inputRef", "createOption", "valueKey", "labelKey", "onChange"]);
|
|
26
|
+
var locale = useLocale();
|
|
27
|
+
var loadOnMountRef = useLatest(loadOnMount);
|
|
28
|
+
var _j = __read(useState(function () {
|
|
29
|
+
return mergeOptions(initialOptions, initGroupOptions(groupConfig));
|
|
30
|
+
}), 2), options = _j[0], setOptions = _j[1];
|
|
31
|
+
var _k = __read(useState(function () {
|
|
32
|
+
return _keyBy(normalizeOptions(initialOptions), valueKey);
|
|
33
|
+
}), 2), allOptionsMap = _k[0], setAllOptionsMap = _k[1];
|
|
34
|
+
var _l = __read(useState(null), 2), inputElement = _l[0], setInputElement = _l[1];
|
|
35
|
+
var inputRef = useLatest(inputElement);
|
|
36
|
+
var combinedRef = useCombinedRefs(setInputElement, propsInputRef);
|
|
37
|
+
var _m = __read(useState(null), 2), rootRef = _m[0], setRootRef = _m[1];
|
|
38
|
+
var _o = __read(useState(null), 2), popoverRef = _o[0], setPopoverRef = _o[1];
|
|
39
|
+
var _p = useResolveSelectedOptions({
|
|
40
|
+
groupedValue: groupedValue,
|
|
41
|
+
valueKey: valueKey,
|
|
42
|
+
inputRef: inputRef,
|
|
43
|
+
allOptionsMap: allOptionsMap,
|
|
44
|
+
setOptions: setOptions,
|
|
45
|
+
setAllOptionsMap: setAllOptionsMap,
|
|
46
|
+
resolveValuesOnUpdate: resolveValuesOnUpdate,
|
|
47
|
+
resolveSelectedOptions: resolveSelectedOptions,
|
|
48
|
+
}), unresolvedGroupedValueKeys = _p.unresolvedGroupedValueKeys, isResolvingValues = _p.isResolvingValues;
|
|
49
|
+
var _q = __read(useState(loadOnMount), 2), _isLoading = _q[0], setIsLoading = _q[1];
|
|
50
|
+
var isLoading = isResolvingValues || _isLoading;
|
|
51
|
+
var unresolvedValueKeysRef = useRef([]);
|
|
52
|
+
var selectedOptions = useMemo(function () {
|
|
53
|
+
if (!groupedValue) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
unresolvedValueKeysRef.current = [];
|
|
57
|
+
var groupedValueObject = _reduce(groupedValue, function (acc, values, groupId) {
|
|
58
|
+
acc[groupId] = (values || []).flatMap(function (valueObjOrId) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
var valueId = _isObject(valueObjOrId) ? valueObjOrId[valueKey] : valueObjOrId;
|
|
61
|
+
var isResolving = isResolvingValues && unresolvedGroupedValueKeys[groupId].includes(valueId);
|
|
62
|
+
var valueObject = _isObject(valueObjOrId)
|
|
63
|
+
? valueObjOrId
|
|
64
|
+
: (_a = {},
|
|
65
|
+
_a[valueKey] = valueId,
|
|
66
|
+
_a[labelKey] = valueId,
|
|
67
|
+
_a);
|
|
68
|
+
var isUnresolved = !allOptionsMap[valueId];
|
|
69
|
+
var resolvedObject = isUnresolved ? valueObject : __assign(__assign({}, valueObject), allOptionsMap[valueId]);
|
|
70
|
+
if (isResolving) {
|
|
71
|
+
return [__assign(__assign({}, resolvedObject), (_b = {}, _b[LOADING_KEY] = true, _b))];
|
|
72
|
+
}
|
|
73
|
+
if (isUnresolved && hideUnresolvedValues) {
|
|
74
|
+
unresolvedValueKeysRef.current.push({ id: valueId, groupId: groupId });
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
return [resolvedObject];
|
|
78
|
+
});
|
|
79
|
+
return acc;
|
|
80
|
+
}, {});
|
|
81
|
+
return normalizeOptions(groupedValueObject);
|
|
82
|
+
},
|
|
83
|
+
// All options map needs to be present in the dependency list so that the values get recomputed when
|
|
84
|
+
// the resolved options have been fetched
|
|
85
|
+
[
|
|
86
|
+
groupedValue,
|
|
87
|
+
valueKey,
|
|
88
|
+
isResolvingValues,
|
|
89
|
+
unresolvedGroupedValueKeys,
|
|
90
|
+
labelKey,
|
|
91
|
+
allOptionsMap,
|
|
92
|
+
hideUnresolvedValues,
|
|
93
|
+
]);
|
|
94
|
+
var _r = useAsyncOptionHandlers({
|
|
95
|
+
valueKey: valueKey,
|
|
96
|
+
isLoading: isLoading,
|
|
97
|
+
minimumInput: minimumInput,
|
|
98
|
+
paginationBuffer: paginationBuffer,
|
|
99
|
+
inputRef: inputRef,
|
|
100
|
+
setAllOptionsMap: setAllOptionsMap,
|
|
101
|
+
setIsLoading: setIsLoading,
|
|
102
|
+
setOptions: setOptions,
|
|
103
|
+
loadOptions: loadOptions,
|
|
104
|
+
createOption: propsCreateOption,
|
|
105
|
+
groupConfig: groupConfig,
|
|
106
|
+
selectedOptions: selectedOptions,
|
|
107
|
+
moveSelectedOptionsToTop: moveSelectedOptionsToTop,
|
|
108
|
+
}), fetchOptions = _r.fetchOptions, onPaginate = _r.onPaginate, inputChangeHandlerToDebounce = _r.onInputChange, createOption = _r.createOption, resultCountMap = _r.resultCountMap;
|
|
109
|
+
var _onInputChange = useInputChangeHandler({
|
|
110
|
+
inputElement: inputElement,
|
|
111
|
+
listenAllInputChanges: listenAllInputChanges,
|
|
112
|
+
onInputChange: onInputChange,
|
|
113
|
+
inputChangeHandlerToDebounce: inputChangeHandlerToDebounce,
|
|
114
|
+
debounceInterval: debounceInterval,
|
|
115
|
+
});
|
|
116
|
+
/************************************************ HANDLING FOCUS ****************************************************/
|
|
117
|
+
var handleFocus = useCallback(function (event) {
|
|
118
|
+
/**
|
|
119
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/relatedTarget
|
|
120
|
+
* event.relatedTarget points to last focused element
|
|
121
|
+
*/
|
|
122
|
+
var lastFocusedNode = event.relatedTarget;
|
|
123
|
+
if (loadOnFocus && !(rootRef === null || rootRef === void 0 ? void 0 : rootRef.contains(lastFocusedNode)) && !(popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.contains(lastFocusedNode))) {
|
|
124
|
+
inputChangeHandlerToDebounce();
|
|
125
|
+
}
|
|
126
|
+
}, [loadOnFocus, inputChangeHandlerToDebounce, rootRef, popoverRef]);
|
|
127
|
+
/******************************************* HANDLING FETCH ON MOUNT ************************************************/
|
|
128
|
+
useEffect(function () {
|
|
129
|
+
if (loadOnMountRef.current) {
|
|
130
|
+
fetchOptions(groupConfig.map(function (_a) {
|
|
131
|
+
var id = _a.id;
|
|
132
|
+
return ({ group: id, pageNumber: 0 });
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only want to load the options on first mount
|
|
136
|
+
}, []);
|
|
137
|
+
/********************************************************************************************************************/
|
|
138
|
+
var inputText = getInputValue(inputRef), adaptedNoResultsMsg = getNoResultsMsg({
|
|
139
|
+
isLoading: isLoading,
|
|
140
|
+
noResultsMsg: noResultsMsg,
|
|
141
|
+
inputText: inputText,
|
|
142
|
+
minimumInput: minimumInput,
|
|
143
|
+
searchingText: searchingText !== null && searchingText !== void 0 ? searchingText : locale.asyncSelect.searchingText,
|
|
144
|
+
emptyInputMsg: locale.asyncSelect.emptyInputMsg,
|
|
145
|
+
});
|
|
146
|
+
var mergedOverrides = useMemo(function () {
|
|
147
|
+
return mergeOverrides(__assign({ Root: { props: { ref: setRootRef, onFocus: handleFocus } }, Popover: { props: { overrides: { Inner: { props: { ref: setPopoverRef } } } } }, StatefulMenu: { props: { $onPaginate: onPaginate } }, NoResults: { props: add$props({ isLoading: isLoading, inputText: inputText, adaptedNoResultsMsg: adaptedNoResultsMsg }) } }, (params.type === 'overlay'
|
|
148
|
+
? {
|
|
149
|
+
// In overlaySelect, overflow property is on OverlayContentContainer
|
|
150
|
+
OverlayContentContainer: { props: { onScroll: onPaginate } },
|
|
151
|
+
Menu: { props: { $onPaginate: onPaginate } },
|
|
152
|
+
}
|
|
153
|
+
: {
|
|
154
|
+
//Overriding DropdownContainer and not StatefulMenu so that async select remains functional even when
|
|
155
|
+
//user overrides StatefulMenu in favour of rendering virtualized menu
|
|
156
|
+
Menu: { props: { onScroll: onPaginate } },
|
|
157
|
+
})), overrides);
|
|
158
|
+
}, [handleFocus, onPaginate, isLoading, inputText, adaptedNoResultsMsg, params.type, overrides]);
|
|
159
|
+
var onChange = useCallback(function (onChangeParams) {
|
|
160
|
+
propsOnChange === null || propsOnChange === void 0 ? void 0 : propsOnChange(__assign(__assign({}, onChangeParams), { valueKeys: __spreadArray(__spreadArray([], __read(unresolvedValueKeysRef.current.map(function (_a) {
|
|
161
|
+
var id = _a.id;
|
|
162
|
+
return id;
|
|
163
|
+
})), false), __read(onChangeParams.value.map(function (opt) { return opt[valueKey]; })), false), value: unresolvedValueKeysRef.current.length
|
|
164
|
+
? __spreadArray(__spreadArray([], __read(unresolvedValueKeysRef.current.map(function (_a) {
|
|
165
|
+
var _b;
|
|
166
|
+
var id = _a.id, groupId = _a.groupId;
|
|
167
|
+
return (_b = {},
|
|
168
|
+
_b[valueKey] = id,
|
|
169
|
+
_b[labelKey] = id,
|
|
170
|
+
_b.__optgroup = groupId,
|
|
171
|
+
_b);
|
|
172
|
+
})), false), __read(onChangeParams.value), false) : onChangeParams.value }));
|
|
173
|
+
}, [propsOnChange, valueKey, labelKey]);
|
|
174
|
+
return __assign(__assign({ children: undefined }, restSelectProps), { options: options, isLoading: isLoading, value: selectedOptions, controlRef: controlRef, inputRef: combinedRef, overrides: mergedOverrides, noResultsMsg: adaptedNoResultsMsg, createOption: createOption, onInputChange: _onInputChange, valueKey: valueKey, labelKey: labelKey, type: restSelectProps.type, resultCountMap: resultCountMap, onChange: onChange, onOpen: function () {
|
|
175
|
+
moveSelectedOptionsToTop && setOptions(function (prev) { return mergeOptions((selectedOptions || []), prev); });
|
|
176
|
+
restSelectProps.onOpen && restSelectProps.onOpen();
|
|
177
|
+
} });
|
|
178
|
+
};
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
* Created by Aneree on 15/01/21.
|
|
3
3
|
*/
|
|
4
4
|
import { MutableRefObject } from 'react';
|
|
5
|
-
import { Option
|
|
6
|
-
import {
|
|
5
|
+
import { Option } from '../../select';
|
|
6
|
+
import { AllOptionsMap, GroupedOptions, GroupedValue, Id, SetStateFunc } from '../types';
|
|
7
7
|
interface UseResolveSelectedOptionsArgs {
|
|
8
|
-
|
|
8
|
+
groupedValue?: GroupedValue;
|
|
9
9
|
valueKey: string;
|
|
10
10
|
allOptionsMap: AllOptionsMap;
|
|
11
|
-
|
|
11
|
+
resolveValuesOnUpdate?: boolean;
|
|
12
|
+
resolveSelectedOptions?: (groupVsUnresolvedValueKeys: Record<string, Array<Id>>) => Promise<Record<string, Array<Option>>>;
|
|
12
13
|
inputRef: MutableRefObject<HTMLInputElement | null>;
|
|
13
|
-
|
|
14
|
-
setOptions: SetStateFunc<Array<Option>>;
|
|
14
|
+
setOptions: SetStateFunc<GroupedOptions>;
|
|
15
15
|
setAllOptionsMap: SetStateFunc<AllOptionsMap>;
|
|
16
16
|
}
|
|
17
|
-
declare const useResolveSelectedOptions: ({
|
|
17
|
+
declare const useResolveSelectedOptions: ({ groupedValue, valueKey, allOptionsMap, resolveValuesOnUpdate, resolveSelectedOptions, inputRef, setOptions, setAllOptionsMap, }: UseResolveSelectedOptionsArgs) => {
|
|
18
|
+
isResolvingValues: boolean;
|
|
19
|
+
unresolvedGroupedValueKeys: Record<string, Id[]>;
|
|
20
|
+
};
|
|
18
21
|
export { useResolveSelectedOptions };
|
|
@@ -1,61 +1,73 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read
|
|
1
|
+
import { __awaiter, __generator, __read } from "tslib";
|
|
2
2
|
/**
|
|
3
3
|
* Created by Aneree on 15/01/21.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import _forEach from 'lodash/forEach';
|
|
7
|
+
import _isEmpty from 'lodash/isEmpty';
|
|
8
|
+
import _isObject from 'lodash/isObject';
|
|
7
9
|
//hooks
|
|
8
|
-
import {
|
|
10
|
+
import { useFirstMountState } from '../../hooks/useFirstMountState';
|
|
9
11
|
//helpers
|
|
10
|
-
import { addOptionsInMap, getInputValue } from '../helpers';
|
|
12
|
+
import { addOptionsInMap, getInputValue, mergeOptions } from '../helpers';
|
|
11
13
|
var useResolveSelectedOptions = function (_a) {
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
setAllOptionsMap(function (prevOptions) { return addOptionsInMap(prevOptions, options_1, valueKeyRef.current); });
|
|
30
|
-
//Inject the resolved selected options into the options state
|
|
31
|
-
// 1. Only if currently shown options are not filtered i.e. user input text is empty (All options need to be shown)
|
|
32
|
-
if (!getInputValue(inputRef)) {
|
|
33
|
-
setOptions(function (prevOptions) {
|
|
34
|
-
// 2. Only if they are not already present in the state
|
|
35
|
-
var combinedOptions = __spreadArray(__spreadArray([], __read(prevOptions), false), __read(options_1), false), uniqueOptions = _uniqBy(combinedOptions, valueKeyRef.current);
|
|
36
|
-
return prevOptions.length === uniqueOptions.length ? prevOptions : uniqueOptions;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
setIsLoading(false);
|
|
40
|
-
return [3 /*break*/, 4];
|
|
41
|
-
case 3:
|
|
42
|
-
e_1 = _a.sent();
|
|
43
|
-
setIsLoading(false);
|
|
44
|
-
throw e_1;
|
|
45
|
-
case 4: return [2 /*return*/];
|
|
46
|
-
}
|
|
14
|
+
var groupedValue = _a.groupedValue, valueKey = _a.valueKey, allOptionsMap = _a.allOptionsMap, resolveValuesOnUpdate = _a.resolveValuesOnUpdate, resolveSelectedOptions = _a.resolveSelectedOptions, inputRef = _a.inputRef, setOptions = _a.setOptions, setAllOptionsMap = _a.setAllOptionsMap;
|
|
15
|
+
var isFirstMount = useFirstMountState();
|
|
16
|
+
var unresolvedValuesResults = useRef({
|
|
17
|
+
unresolvedGroupedValueKeys: {},
|
|
18
|
+
hasUnresolvedValues: false,
|
|
19
|
+
});
|
|
20
|
+
useMemo(function () {
|
|
21
|
+
var shouldCalculateUnresolvedValues = (resolveValuesOnUpdate || isFirstMount) && resolveSelectedOptions && !_isEmpty(groupedValue);
|
|
22
|
+
if (!shouldCalculateUnresolvedValues) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
var unresolvedGroupedValueKeys = {}, hasUnresolvedValues = false;
|
|
26
|
+
_forEach(groupedValue, function (values, groupId) {
|
|
27
|
+
unresolvedGroupedValueKeys[groupId] = (values !== null && values !== void 0 ? values : [])
|
|
28
|
+
.map(function (valueObjOrId) { return (_isObject(valueObjOrId) ? valueObjOrId[valueKey] : valueObjOrId); })
|
|
29
|
+
.filter(function (valueId) { return !allOptionsMap[valueId]; });
|
|
30
|
+
hasUnresolvedValues = hasUnresolvedValues || unresolvedGroupedValueKeys[groupId].length > 0;
|
|
47
31
|
});
|
|
48
|
-
|
|
32
|
+
unresolvedValuesResults.current = { unresolvedGroupedValueKeys: unresolvedGroupedValueKeys, hasUnresolvedValues: hasUnresolvedValues };
|
|
33
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- calculate this on mount or when value changes
|
|
34
|
+
}, [groupedValue]);
|
|
35
|
+
var _b = unresolvedValuesResults.current, hasUnresolvedValues = _b.hasUnresolvedValues, unresolvedGroupedValueKeys = _b.unresolvedGroupedValueKeys;
|
|
36
|
+
var _c = __read(useState(hasUnresolvedValues), 2), isResolvingValues = _c[0], setIsResolving = _c[1];
|
|
49
37
|
useEffect(function () {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var _valueKey_1 = valueKeyRef.current;
|
|
54
|
-
var unresolvedValueKeys = (_b = valueRef.current) === null || _b === void 0 ? void 0 : _b.filter(function (valueOption) { return !allOptionsMapRef.current[valueOption[_valueKey_1]]; }).map(function (valueOption) { return valueOption[_valueKey_1]; });
|
|
55
|
-
if (unresolvedValueKeys.length) {
|
|
56
|
-
fetchUnresolvedValueKeys(unresolvedValueKeys);
|
|
57
|
-
}
|
|
38
|
+
if (!hasUnresolvedValues || !resolveSelectedOptions) {
|
|
39
|
+
setIsResolving(false);
|
|
40
|
+
return;
|
|
58
41
|
}
|
|
59
|
-
|
|
42
|
+
var fetchUnresolvedValueKeys = function (_unresolvedGroupedValueKeys) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
+
var options_1;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
setIsResolving(true);
|
|
48
|
+
_a.label = 1;
|
|
49
|
+
case 1:
|
|
50
|
+
_a.trys.push([1, , 3, 4]);
|
|
51
|
+
return [4 /*yield*/, resolveSelectedOptions(_unresolvedGroupedValueKeys)];
|
|
52
|
+
case 2:
|
|
53
|
+
options_1 = _a.sent();
|
|
54
|
+
setAllOptionsMap(function (prevOptions) { return addOptionsInMap(prevOptions, options_1, valueKey); });
|
|
55
|
+
//Inject the resolved selected options into the options state
|
|
56
|
+
// 1. Only if currently shown options are not filtered i.e. user input text is empty (All options need to be shown)
|
|
57
|
+
if (!getInputValue(inputRef)) {
|
|
58
|
+
setOptions(function (prevOptions) { return mergeOptions(prevOptions, options_1); });
|
|
59
|
+
}
|
|
60
|
+
return [3 /*break*/, 4];
|
|
61
|
+
case 3:
|
|
62
|
+
setIsResolving(false);
|
|
63
|
+
return [7 /*endfinally*/];
|
|
64
|
+
case 4: return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
fetchUnresolvedValueKeys(unresolvedGroupedValueKeys);
|
|
69
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- this effect should run only when unresolvedValues is changed
|
|
70
|
+
}, [unresolvedGroupedValueKeys]);
|
|
71
|
+
return { isResolvingValues: isResolvingValues, unresolvedGroupedValueKeys: unresolvedGroupedValueKeys };
|
|
60
72
|
};
|
|
61
73
|
export { useResolveSelectedOptions };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export type { Value, Option, AsyncSelectProps } from './types';
|
|
1
|
+
export type { Value, AsyncSelectValue, GroupedValue, Option, GroupedOptions, AsyncSelectProps, GroupedAsyncSelectProps, } from './types';
|
|
2
2
|
export * from './locale';
|
|
3
3
|
export * from './asyncSelect';
|
|
4
|
+
export { GroupedAsyncSelect } from './groupedAsyncSelect';
|
|
5
|
+
export { arrayToGroupedOptions, normalizeOptions } from './helpers';
|
|
6
|
+
export { STATE_CHANGE_TYPE } from '../select';
|
package/esm/asyncSelect/index.js
CHANGED