@onewelcome/react-lib-components 14.0.0-experiment.1 → 14.0.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/dist/components/Breadcrumbs/Breadcrumbs.module.scss.cjs.js +2 -2
- package/dist/components/Breadcrumbs/Breadcrumbs.module.scss.es.js +5 -5
- package/dist/components/Button/BaseButton.module.scss.cjs.js +2 -2
- package/dist/components/Button/BaseButton.module.scss.es.js +4 -4
- package/dist/components/Button/Button.cjs.js +1 -1
- package/dist/components/Button/Button.cjs.js.map +1 -1
- package/dist/components/Button/Button.es.js +11 -2
- package/dist/components/Button/Button.es.js.map +1 -1
- package/dist/components/Button/Button.module.scss.cjs.js +2 -2
- package/dist/components/Button/Button.module.scss.es.js +17 -17
- package/dist/components/Button/IconButton.module.scss.cjs.js +2 -2
- package/dist/components/Button/IconButton.module.scss.es.js +18 -18
- package/dist/components/ContextMenu/ContextMenu.cjs.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.es.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenu.module.scss.cjs.js +2 -2
- package/dist/components/ContextMenu/ContextMenu.module.scss.es.js +6 -6
- package/dist/components/ContextMenu/ContextMenuDivider.module.scss.cjs.js +2 -2
- package/dist/components/ContextMenu/ContextMenuDivider.module.scss.es.js +2 -2
- package/dist/components/ContextMenu/ContextMenuItem.cjs.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenuItem.es.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenuItem.module.scss.cjs.js +2 -2
- package/dist/components/ContextMenu/ContextMenuItem.module.scss.es.js +3 -3
- package/dist/components/ContextMenu/ContextMenuService.cjs.js +1 -1
- package/dist/components/ContextMenu/ContextMenuService.cjs.js.map +1 -1
- package/dist/components/ContextMenu/ContextMenuService.es.js +20 -17
- package/dist/components/ContextMenu/ContextMenuService.es.js.map +1 -1
- package/dist/components/DataGrid/DataGrid.cjs.js +1 -1
- package/dist/components/DataGrid/DataGrid.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGrid.es.js +102 -59
- package/dist/components/DataGrid/DataGrid.es.js.map +1 -1
- package/dist/components/DataGrid/DataGrid.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGrid.module.scss.es.js +8 -6
- package/dist/components/DataGrid/DataGrid.module.scss.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridActions/DataGridActions.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridActions/DataGridActions.module.scss.es.js +6 -6
- package/dist/components/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss.es.js +7 -7
- package/dist/components/DataGrid/DataGridBody/DataGridBody.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridBody.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridBody.es.js +4 -2
- package/dist/components/DataGrid/DataGridBody/DataGridBody.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridBody.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridBody.module.scss.es.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridCell/DataGridCell.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridCell/DataGridCell.module.scss.es.js +5 -5
- package/dist/components/DataGrid/DataGridBody/DataGridDrawer/DataGridDrawer.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridDrawer/DataGridDrawer.module.scss.es.js +4 -4
- package/dist/components/DataGrid/DataGridBody/DataGridDrawer/DataGridDrawerItem.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridDrawer/DataGridDrawerItem.module.scss.es.js +5 -5
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.es.js +2 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.module.scss.es.js +24 -24
- package/dist/components/DataGrid/DataGridBody/DataGridRow/useNestedRow.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/useNestedRow.es.js +1 -1
- package/dist/components/DataGrid/DataGridBody/DataGridRow/useNestedRow.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.es.js +4 -4
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridFilters/DataGridFilter.module.scss.es.js +9 -9
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterPopover.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterPopover.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterService.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterService.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterService.es.js +17 -21
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterService.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterTag.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterTag.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterTag.es.js +15 -4
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterTag.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterValueSelect.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterValueSelect.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterValueSelect.es.js +54 -6
- package/dist/components/DataGrid/DataGridFilters/DataGridFilterValueSelect.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilters.interfaces.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridFilters.interfaces.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.es.js +4 -4
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridFilters/DataGridToolbar.module.scss.es.js +10 -10
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.es.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePicker.module.scss.es.js +17 -17
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePickerCalendarSection.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePickerCalendarSection.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePickerCalendarSection.es.js +45 -24
- package/dist/components/DataGrid/DataGridFilters/DateTimePicker/DateTimePickerCalendarSection.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/useFiltersReducer.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridFilters/useFiltersReducer.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridFilters/useFiltersReducer.es.js +7 -9
- package/dist/components/DataGrid/DataGridFilters/useFiltersReducer.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.es.js +6 -2
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.module.scss.es.js +7 -4
- package/dist/components/DataGrid/DataGridHeader/DataGridHeader.module.scss.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.cjs.js +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.cjs.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.es.js +14 -12
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.es.js.map +1 -1
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss.cjs.js +2 -2
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss.es.js +11 -10
- package/dist/components/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss.es.js.map +1 -1
- package/dist/components/DatePicker/DatePicker.module.scss.cjs.js +2 -2
- package/dist/components/DatePicker/DatePicker.module.scss.es.js +31 -31
- package/dist/components/Form/Checkbox/Checkbox.cjs.js.map +1 -1
- package/dist/components/Form/Checkbox/Checkbox.es.js.map +1 -1
- package/dist/components/Form/Checkbox/Checkbox.module.scss.cjs.js +2 -2
- package/dist/components/Form/Checkbox/Checkbox.module.scss.es.js +13 -13
- package/dist/components/Form/Fieldset/Fieldset.cjs.js +1 -1
- package/dist/components/Form/Fieldset/Fieldset.cjs.js.map +1 -1
- package/dist/components/Form/Fieldset/Fieldset.es.js +3 -2
- package/dist/components/Form/Fieldset/Fieldset.es.js.map +1 -1
- package/dist/components/Form/Fieldset/Fieldset.module.scss.cjs.js +2 -2
- package/dist/components/Form/Fieldset/Fieldset.module.scss.es.js +8 -5
- package/dist/components/Form/Fieldset/Fieldset.module.scss.es.js.map +1 -1
- package/dist/components/Form/FileUpload/FileItem/FileItem.cjs.js +1 -1
- package/dist/components/Form/FileUpload/FileItem/FileItem.cjs.js.map +1 -1
- package/dist/components/Form/FileUpload/FileItem/FileItem.es.js +1 -1
- package/dist/components/Form/FileUpload/FileItem/FileItem.es.js.map +1 -1
- package/dist/components/Form/FileUpload/FileItem/FileItem.module.scss.cjs.js +2 -2
- package/dist/components/Form/FileUpload/FileItem/FileItem.module.scss.es.js +18 -18
- package/dist/components/Form/FileUpload/FileUpload.cjs.js +1 -1
- package/dist/components/Form/FileUpload/FileUpload.cjs.js.map +1 -1
- package/dist/components/Form/FileUpload/FileUpload.es.js +6 -6
- package/dist/components/Form/FileUpload/FileUpload.es.js.map +1 -1
- package/dist/components/Form/FileUpload/FileUpload.module.scss.cjs.js +2 -2
- package/dist/components/Form/FileUpload/FileUpload.module.scss.es.js +16 -16
- package/dist/components/Form/Form.module.scss.cjs.js +2 -2
- package/dist/components/Form/Form.module.scss.es.js +2 -2
- package/dist/components/Form/FormControl/FormControl.cjs.js +1 -1
- package/dist/components/Form/FormControl/FormControl.cjs.js.map +1 -1
- package/dist/components/Form/FormControl/FormControl.es.js +3 -3
- package/dist/components/Form/FormControl/FormControl.es.js.map +1 -1
- package/dist/components/Form/FormControl/FormControl.module.scss.cjs.js +2 -2
- package/dist/components/Form/FormControl/FormControl.module.scss.es.js +13 -13
- package/dist/components/Form/FormErrorText/FormErrorText.module.scss.cjs.js +2 -2
- package/dist/components/Form/FormErrorText/FormErrorText.module.scss.es.js +9 -6
- package/dist/components/Form/FormErrorText/FormErrorText.module.scss.es.js.map +1 -1
- package/dist/components/Form/FormGroup/FormGroup.cjs.js.map +1 -1
- package/dist/components/Form/FormGroup/FormGroup.es.js.map +1 -1
- package/dist/components/Form/FormGroup/FormGroup.module.scss.cjs.js +2 -2
- package/dist/components/Form/FormGroup/FormGroup.module.scss.es.js +3 -3
- package/dist/components/Form/FormHelperText/FormHelperText.module.scss.cjs.js +2 -2
- package/dist/components/Form/FormHelperText/FormHelperText.module.scss.es.js +4 -4
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.cjs.js +1 -1
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.cjs.js.map +1 -1
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.es.js +4 -1
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.es.js.map +1 -1
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/FormSelectorWrapper/FormSelectorWrapper.module.scss.es.js +6 -6
- package/dist/components/Form/Input/Input.cjs.js +1 -1
- package/dist/components/Form/Input/Input.cjs.js.map +1 -1
- package/dist/components/Form/Input/Input.es.js +48 -5
- package/dist/components/Form/Input/Input.es.js.map +1 -1
- package/dist/components/Form/Input/Input.module.scss.cjs.js +2 -2
- package/dist/components/Form/Input/Input.module.scss.es.js +8 -8
- package/dist/components/Form/Label/Label.module.scss.cjs.js +2 -2
- package/dist/components/Form/Label/Label.module.scss.es.js +2 -2
- package/dist/components/Form/Radio/Radio.cjs.js.map +1 -1
- package/dist/components/Form/Radio/Radio.es.js +1 -1
- package/dist/components/Form/Radio/Radio.es.js.map +1 -1
- package/dist/components/Form/Radio/Radio.module.scss.cjs.js +2 -2
- package/dist/components/Form/Radio/Radio.module.scss.es.js +11 -11
- package/dist/components/Form/Select/MultiSelect/MultiOption.cjs.js +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiOption.cjs.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiOption.es.js +11 -10
- package/dist/components/Form/Select/MultiSelect/MultiOption.es.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiSelect.cjs.js +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiSelect.cjs.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiSelect.es.js +236 -57
- package/dist/components/Form/Select/MultiSelect/MultiSelect.es.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/MultiSelect.module.scss.cjs.js +2 -2
- package/dist/components/Form/Select/MultiSelect/MultiSelect.module.scss.es.js +20 -15
- package/dist/components/Form/Select/MultiSelect/MultiSelect.module.scss.es.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/SelectButton.module.scss.cjs.js +2 -2
- package/dist/components/Form/Select/MultiSelect/SelectButton.module.scss.es.js +2 -2
- package/dist/components/Form/Select/MultiSelect/SelectedOptions.cjs.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/SelectedOptions.es.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/SelectedOptions.module.scss.cjs.js +2 -2
- package/dist/components/Form/Select/MultiSelect/SelectedOptions.module.scss.es.js +4 -4
- package/dist/components/Form/Select/MultiSelect/useArrowNavigation.cjs.js +1 -1
- package/dist/components/Form/Select/MultiSelect/useArrowNavigation.cjs.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/useArrowNavigation.es.js +134 -32
- package/dist/components/Form/Select/MultiSelect/useArrowNavigation.es.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/useSearch.cjs.js +1 -1
- package/dist/components/Form/Select/MultiSelect/useSearch.cjs.js.map +1 -1
- package/dist/components/Form/Select/MultiSelect/useSearch.es.js +73 -55
- package/dist/components/Form/Select/MultiSelect/useSearch.es.js.map +1 -1
- package/dist/components/Form/Select/Select.interfaces.cjs.js.map +1 -1
- package/dist/components/Form/Select/Select.interfaces.es.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/Option.cjs.js +1 -1
- package/dist/components/Form/Select/SingleSelect/Option.cjs.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/Option.es.js +16 -9
- package/dist/components/Form/Select/SingleSelect/Option.es.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/Select.cjs.js +1 -1
- package/dist/components/Form/Select/SingleSelect/Select.cjs.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/Select.es.js +202 -46
- package/dist/components/Form/Select/SingleSelect/Select.es.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/Select.module.scss.cjs.js +2 -2
- package/dist/components/Form/Select/SingleSelect/Select.module.scss.es.js +21 -17
- package/dist/components/Form/Select/SingleSelect/Select.module.scss.es.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/useArrowNavigation.cjs.js +1 -1
- package/dist/components/Form/Select/SingleSelect/useArrowNavigation.cjs.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/useArrowNavigation.es.js +176 -89
- package/dist/components/Form/Select/SingleSelect/useArrowNavigation.es.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/useSearch.cjs.js +1 -1
- package/dist/components/Form/Select/SingleSelect/useSearch.cjs.js.map +1 -1
- package/dist/components/Form/Select/SingleSelect/useSearch.es.js +48 -36
- package/dist/components/Form/Select/SingleSelect/useSearch.es.js.map +1 -1
- package/dist/components/Form/Select/useAddNewBtn.cjs.js +1 -1
- package/dist/components/Form/Select/useAddNewBtn.cjs.js.map +1 -1
- package/dist/components/Form/Select/useAddNewBtn.es.js +8 -6
- package/dist/components/Form/Select/useAddNewBtn.es.js.map +1 -1
- package/dist/components/Form/Select/useAddNewBtn.module.scss.cjs.js +2 -2
- package/dist/components/Form/Select/useAddNewBtn.module.scss.es.js +4 -4
- package/dist/components/Form/Select/useBaseSearch.cjs.js +2 -0
- package/dist/components/Form/Select/useBaseSearch.cjs.js.map +1 -0
- package/dist/components/Form/Select/useBaseSearch.es.js +85 -0
- package/dist/components/Form/Select/useBaseSearch.es.js.map +1 -0
- package/dist/components/Form/Select/useSelectPositionList.cjs.js +1 -1
- package/dist/components/Form/Select/useSelectPositionList.cjs.js.map +1 -1
- package/dist/components/Form/Select/useSelectPositionList.es.js +18 -5
- package/dist/components/Form/Select/useSelectPositionList.es.js.map +1 -1
- package/dist/components/Form/Textarea/Textarea.cjs.js +1 -1
- package/dist/components/Form/Textarea/Textarea.cjs.js.map +1 -1
- package/dist/components/Form/Textarea/Textarea.es.js +4 -0
- package/dist/components/Form/Textarea/Textarea.es.js.map +1 -1
- package/dist/components/Form/Textarea/Textarea.module.scss.cjs.js +2 -2
- package/dist/components/Form/Textarea/Textarea.module.scss.es.js +6 -6
- package/dist/components/Form/Toggle/Toggle.cjs.js +1 -1
- package/dist/components/Form/Toggle/Toggle.cjs.js.map +1 -1
- package/dist/components/Form/Toggle/Toggle.es.js +5 -3
- package/dist/components/Form/Toggle/Toggle.es.js.map +1 -1
- package/dist/components/Form/Toggle/Toggle.module.scss.cjs.js +2 -2
- package/dist/components/Form/Toggle/Toggle.module.scss.es.js +18 -18
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.cjs.js +1 -1
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.es.js +25 -17
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.module.scss.es.js +8 -4
- package/dist/components/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.module.scss.es.js.map +1 -1
- package/dist/components/Form/Wrapper/InputWrapper/InputWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/InputWrapper/InputWrapper.module.scss.es.js +5 -5
- package/dist/components/Form/Wrapper/MultiSelectWrapper/MultiSelectWrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/MultiSelectWrapper/MultiSelectWrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/MultiSelectWrapper/MultiSelectWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/MultiSelectWrapper/MultiSelectWrapper.module.scss.es.js +3 -3
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.cjs.js +1 -1
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.es.js +41 -22
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.module.scss.es.js +8 -4
- package/dist/components/Form/Wrapper/RadioWrapper/RadioWrapper.module.scss.es.js.map +1 -1
- package/dist/components/Form/Wrapper/SelectWrapper/SelectWrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/SelectWrapper/SelectWrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/SelectWrapper/SelectWrapper.module.scss.es.js +3 -3
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.cjs.js +1 -1
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.es.js +2 -0
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss.es.js +8 -8
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.cjs.js +1 -1
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.cjs.js.map +1 -1
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.es.js +1 -1
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.es.js.map +1 -1
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.module.scss.cjs.js +2 -2
- package/dist/components/Form/Wrapper/Wrapper/Wrapper.module.scss.es.js +6 -6
- package/dist/components/Icon/Icon.cjs.js +1 -1
- package/dist/components/Icon/Icon.cjs.js.map +1 -1
- package/dist/components/Icon/Icon.es.js +2 -1
- package/dist/components/Icon/Icon.es.js.map +1 -1
- package/dist/components/Icon/Icon.module.scss.cjs.js +2 -2
- package/dist/components/Icon/Icon.module.scss.es.js +108 -107
- package/dist/components/Icon/Icon.module.scss.es.js.map +1 -1
- package/dist/components/Layout/ActionBar/ActionBar.cjs.js +2 -0
- package/dist/components/Layout/ActionBar/ActionBar.cjs.js.map +1 -0
- package/dist/components/Layout/ActionBar/ActionBar.es.js +122 -0
- package/dist/components/Layout/ActionBar/ActionBar.es.js.map +1 -0
- package/dist/components/Layout/ActionBar/ActionBar.module.scss.cjs.js +3 -0
- package/dist/components/Layout/ActionBar/ActionBar.module.scss.cjs.js.map +1 -0
- package/dist/components/Layout/ActionBar/ActionBar.module.scss.es.js +24 -0
- package/dist/components/Layout/ActionBar/ActionBar.module.scss.es.js.map +1 -0
- package/dist/components/Layout/Card/Card.module.scss.cjs.js +2 -2
- package/dist/components/Layout/Card/Card.module.scss.es.js +12 -12
- package/dist/components/Layout/ContentHeader/ContentHeader.cjs.js +1 -1
- package/dist/components/Layout/ContentHeader/ContentHeader.cjs.js.map +1 -1
- package/dist/components/Layout/ContentHeader/ContentHeader.es.js +66 -41
- package/dist/components/Layout/ContentHeader/ContentHeader.es.js.map +1 -1
- package/dist/components/Layout/ContentHeader/ContentHeader.module.scss.cjs.js +2 -2
- package/dist/components/Layout/ContentHeader/ContentHeader.module.scss.es.js +28 -13
- package/dist/components/Layout/ContentHeader/ContentHeader.module.scss.es.js.map +1 -1
- package/dist/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.scss.cjs.js +2 -2
- package/dist/components/Layout/FormPage/FormWithStepper/FormSection/FormSection.module.scss.es.js +4 -4
- package/dist/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.scss.cjs.js +2 -2
- package/dist/components/Layout/FormPage/FormWithStepper/FormStepper/FormStepper.module.scss.es.js +2 -2
- package/dist/components/Layout/FormPage/FormWithStepper/FormWithStepper.module.scss.cjs.js +2 -2
- package/dist/components/Layout/FormPage/FormWithStepper/FormWithStepper.module.scss.es.js +3 -3
- package/dist/components/Link/Link.cjs.js.map +1 -1
- package/dist/components/Link/Link.es.js +1 -1
- package/dist/components/Link/Link.es.js.map +1 -1
- package/dist/components/Link/Link.module.scss.cjs.js +2 -2
- package/dist/components/Link/Link.module.scss.es.js +17 -17
- package/dist/components/Notifications/Alert/AlertContainer/AlertContainer.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Alert/AlertContainer/AlertContainer.module.scss.es.js +11 -11
- package/dist/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.cjs.js +1 -1
- package/dist/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.cjs.js.map +1 -1
- package/dist/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.es.js +7 -1
- package/dist/components/Notifications/Alert/AlertContainer/useAlertContainerHeightAnimation.es.js.map +1 -1
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.cjs.js +1 -1
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.cjs.js.map +1 -1
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.es.js +1 -1
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.es.js.map +1 -1
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Alert/AlertItem/AlertItem.module.scss.es.js +22 -22
- package/dist/components/Notifications/Banner/Banner.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Banner/Banner.module.scss.es.js +9 -9
- package/dist/components/Notifications/BaseModal/BaseModal.cjs.js +1 -1
- package/dist/components/Notifications/BaseModal/BaseModal.cjs.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModal.es.js +1 -1
- package/dist/components/Notifications/BaseModal/BaseModal.es.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModal.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/BaseModal/BaseModal.module.scss.es.js +5 -5
- package/dist/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.cjs.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.es.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/BaseModal/BaseModalActions/BaseModalActions.module.scss.es.js +4 -4
- package/dist/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.cjs.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.es.js.map +1 -1
- package/dist/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/BaseModal/BaseModalContent/BaseModalContent.module.scss.es.js +2 -2
- package/dist/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.module.scss.es.js +6 -6
- package/dist/components/Notifications/Dialog/Dialog.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Dialog/Dialog.module.scss.es.js +4 -4
- package/dist/components/Notifications/Dialog/DialogActions/DialogActions.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Dialog/DialogActions/DialogActions.module.scss.es.js +3 -3
- package/dist/components/Notifications/Dialog/DialogTitle/DialogTitle.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/Dialog/DialogTitle/DialogTitle.module.scss.es.js +10 -10
- package/dist/components/Notifications/DiscardChangesModal/DiscardChangesModal.cjs.js.map +1 -1
- package/dist/components/Notifications/DiscardChangesModal/DiscardChangesModal.es.js.map +1 -1
- package/dist/components/Notifications/SideSheet/SideSheet.cjs.js.map +1 -1
- package/dist/components/Notifications/SideSheet/SideSheet.es.js +1 -1
- package/dist/components/Notifications/SideSheet/SideSheet.es.js.map +1 -1
- package/dist/components/Notifications/SideSheet/SideSheet.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/SideSheet/SideSheet.module.scss.es.js +13 -13
- package/dist/components/Notifications/SideSheet/SideSheetContent/SideSheetContent.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/SideSheet/SideSheetContent/SideSheetContent.module.scss.es.js +2 -2
- package/dist/components/Notifications/SideSheet/SideSheetHeader/SideSheetHeader.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/SideSheet/SideSheetHeader/SideSheetHeader.module.scss.es.js +2 -2
- package/dist/components/Notifications/SlideInModal/SlideInModal.cjs.js.map +1 -1
- package/dist/components/Notifications/SlideInModal/SlideInModal.es.js +1 -1
- package/dist/components/Notifications/SlideInModal/SlideInModal.es.js.map +1 -1
- package/dist/components/Notifications/SlideInModal/SlideInModal.module.scss.cjs.js +2 -2
- package/dist/components/Notifications/SlideInModal/SlideInModal.module.scss.es.js +10 -10
- package/dist/components/Pagination/Pagination.cjs.js +1 -1
- package/dist/components/Pagination/Pagination.cjs.js.map +1 -1
- package/dist/components/Pagination/Pagination.es.js +118 -90
- package/dist/components/Pagination/Pagination.es.js.map +1 -1
- package/dist/components/Pagination/Pagination.module.scss.cjs.js +2 -2
- package/dist/components/Pagination/Pagination.module.scss.es.js +15 -14
- package/dist/components/Pagination/Pagination.module.scss.es.js.map +1 -1
- package/dist/components/Popover/Popover.cjs.js.map +1 -1
- package/dist/components/Popover/Popover.es.js.map +1 -1
- package/dist/components/Popover/Popover.module.scss.cjs.js +2 -2
- package/dist/components/Popover/Popover.module.scss.es.js +3 -3
- package/dist/components/ProgressBar/ProgressBar.cjs.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.es.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.module.scss.cjs.js +2 -2
- package/dist/components/ProgressBar/ProgressBar.module.scss.es.js +9 -9
- package/dist/components/Skeleton/Skeleton.module.scss.cjs.js +2 -2
- package/dist/components/Skeleton/Skeleton.module.scss.es.js +5 -5
- package/dist/components/Spinner/Spinner.module.scss.cjs.js +2 -2
- package/dist/components/Spinner/Spinner.module.scss.es.js +3 -3
- package/dist/components/Stepper/Step.module.scss.cjs.js +2 -2
- package/dist/components/Stepper/Step.module.scss.es.js +22 -22
- package/dist/components/Stepper/Stepper.module.scss.cjs.js +2 -2
- package/dist/components/Stepper/Stepper.module.scss.es.js +4 -4
- package/dist/components/Tabs/Tab.module.scss.cjs.js +2 -2
- package/dist/components/Tabs/Tab.module.scss.es.js +3 -3
- package/dist/components/Tabs/TabButton.cjs.js.map +1 -1
- package/dist/components/Tabs/TabButton.es.js.map +1 -1
- package/dist/components/Tabs/TabButton.module.scss.cjs.js +2 -2
- package/dist/components/Tabs/TabButton.module.scss.es.js +12 -12
- package/dist/components/Tabs/Tabs.cjs.js +1 -1
- package/dist/components/Tabs/Tabs.cjs.js.map +1 -1
- package/dist/components/Tabs/Tabs.es.js +1 -1
- package/dist/components/Tabs/Tabs.es.js.map +1 -1
- package/dist/components/Tabs/Tabs.module.scss.cjs.js +2 -2
- package/dist/components/Tabs/Tabs.module.scss.es.js +10 -10
- package/dist/components/Tag/RemoveButton.module.scss.cjs.js +2 -2
- package/dist/components/Tag/RemoveButton.module.scss.es.js +3 -3
- package/dist/components/Tag/Tag.cjs.js +1 -1
- package/dist/components/Tag/Tag.cjs.js.map +1 -1
- package/dist/components/Tag/Tag.es.js +7 -1
- package/dist/components/Tag/Tag.es.js.map +1 -1
- package/dist/components/Tag/Tag.module.scss.cjs.js +2 -2
- package/dist/components/Tag/Tag.module.scss.es.js +6 -6
- package/dist/components/TextEllipsis/TextEllipsis.cjs.js.map +1 -1
- package/dist/components/TextEllipsis/TextEllipsis.es.js.map +1 -1
- package/dist/components/TextEllipsis/TextEllipsis.module.scss.cjs.js +2 -2
- package/dist/components/TextEllipsis/TextEllipsis.module.scss.es.js +3 -3
- package/dist/components/Tiles/Tile.cjs.js.map +1 -1
- package/dist/components/Tiles/Tile.es.js.map +1 -1
- package/dist/components/Tiles/Tile.module.scss.cjs.js +2 -2
- package/dist/components/Tiles/Tile.module.scss.es.js +8 -8
- package/dist/components/Tiles/Tiles.module.scss.cjs.js +2 -2
- package/dist/components/Tiles/Tiles.module.scss.es.js +2 -2
- package/dist/components/Tooltip/Tooltip.cjs.js +1 -1
- package/dist/components/Tooltip/Tooltip.cjs.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.es.js +47 -39
- package/dist/components/Tooltip/Tooltip.es.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.module.scss.cjs.js +2 -2
- package/dist/components/Tooltip/Tooltip.module.scss.es.js +28 -27
- package/dist/components/Tooltip/Tooltip.module.scss.es.js.map +1 -1
- package/dist/components/Typography/Typography.module.scss.cjs.js +2 -2
- package/dist/components/Typography/Typography.module.scss.es.js +13 -13
- package/dist/components/_BaseStyling_/BaseStyling.cjs.js +2 -1
- package/dist/components/_BaseStyling_/BaseStyling.cjs.js.map +1 -1
- package/dist/components/_BaseStyling_/BaseStyling.es.js +3 -3
- package/dist/components/_BaseStyling_/BaseStyling.es.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNav.cjs.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNav.es.js +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNav.es.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNav.module.scss.cjs.js +2 -2
- package/dist/components/admin/layout/LeftNav/LeftNav.module.scss.es.js +5 -5
- package/dist/components/admin/layout/LeftNav/LeftNavItem/ButtonLeftNavItem.cjs.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNavItem/ButtonLeftNavItem.es.js +3 -1
- package/dist/components/admin/layout/LeftNav/LeftNavItem/ButtonLeftNavItem.es.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNavItem/LeftNavItem.module.scss.cjs.js +2 -2
- package/dist/components/admin/layout/LeftNav/LeftNavItem/LeftNavItem.module.scss.es.js +14 -14
- package/dist/components/admin/layout/LeftNav/LeftNavItem/LinkLeftNavItem.cjs.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/LeftNavItem/LinkLeftNavItem.es.js +6 -2
- package/dist/components/admin/layout/LeftNav/LeftNavItem/LinkLeftNavItem.es.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/useRefItems.cjs.js +1 -1
- package/dist/components/admin/layout/LeftNav/useRefItems.cjs.js.map +1 -1
- package/dist/components/admin/layout/LeftNav/useRefItems.es.js +7 -6
- package/dist/components/admin/layout/LeftNav/useRefItems.es.js.map +1 -1
- package/dist/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.module.scss.cjs.js +2 -2
- package/dist/components/admin/layout/MicrofrontendContainer/MicrofrontendContainer.module.scss.es.js +3 -3
- package/dist/components/admin/layout/ProfileMenu/ProfileMenu.module.scss.cjs.js +2 -2
- package/dist/components/admin/layout/ProfileMenu/ProfileMenu.module.scss.es.js +7 -7
- package/dist/components/admin/layout/TopNavBar/TopNavBar.module.scss.cjs.js +2 -2
- package/dist/components/admin/layout/TopNavBar/TopNavBar.module.scss.es.js +13 -13
- package/dist/components/miscellaneous/IdentityProviderButton.cjs.js.map +1 -1
- package/dist/components/miscellaneous/IdentityProviderButton.es.js.map +1 -1
- package/dist/components/miscellaneous/IdentityProviderButton.module.scss.cjs.js +2 -2
- package/dist/components/miscellaneous/IdentityProviderButton.module.scss.es.js +3 -3
- package/dist/components/withReadOnly.cjs.js +1 -1
- package/dist/components/withReadOnly.cjs.js.map +1 -1
- package/dist/components/withReadOnly.es.js +2 -4
- package/dist/components/withReadOnly.es.js.map +1 -1
- package/dist/hooks/useClickOutside.cjs.js +1 -1
- package/dist/hooks/useClickOutside.cjs.js.map +1 -1
- package/dist/hooks/useClickOutside.es.js +1 -1
- package/dist/hooks/useClickOutside.es.js.map +1 -1
- package/dist/hooks/useDebouncedCallback.cjs.js +1 -1
- package/dist/hooks/useDebouncedCallback.cjs.js.map +1 -1
- package/dist/hooks/useDebouncedCallback.es.js +9 -2
- package/dist/hooks/useDebouncedCallback.es.js.map +1 -1
- package/dist/hooks/useGetDomRoot.cjs.js.map +1 -1
- package/dist/hooks/useGetDomRoot.es.js.map +1 -1
- package/dist/hooks/usePosition.cjs.js +1 -1
- package/dist/hooks/usePosition.cjs.js.map +1 -1
- package/dist/hooks/usePosition.es.js +105 -4
- package/dist/hooks/usePosition.es.js.map +1 -1
- package/dist/hooks/useRepeatFocus.cjs.js.map +1 -1
- package/dist/hooks/useRepeatFocus.es.js.map +1 -1
- package/dist/hooks/useScreenSize.cjs.js +1 -1
- package/dist/hooks/useScreenSize.cjs.js.map +1 -1
- package/dist/hooks/useScreenSize.es.js +1 -1
- package/dist/hooks/useScreenSize.es.js.map +1 -1
- package/dist/hooks/useStickyStacking.cjs.js +2 -0
- package/dist/hooks/useStickyStacking.cjs.js.map +1 -0
- package/dist/hooks/useStickyStacking.es.js +208 -0
- package/dist/hooks/useStickyStacking.es.js.map +1 -0
- package/dist/hooks/useUploadFile.cjs.js +1 -1
- package/dist/hooks/useUploadFile.cjs.js.map +1 -1
- package/dist/hooks/useUploadFile.es.js +1 -1
- package/dist/hooks/useUploadFile.es.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +140 -29
- package/dist/index.es.js +4 -0
- package/dist/index.es.js.map +1 -1
- package/dist/node_modules/tabbable/dist/index.esm.cjs.js +1 -1
- package/dist/node_modules/tabbable/dist/index.esm.cjs.js.map +1 -1
- package/dist/node_modules/tabbable/dist/index.esm.es.js +4 -3
- package/dist/node_modules/tabbable/dist/index.esm.es.js.map +1 -1
- package/dist/readyclasses.module.scss.cjs.js +2 -2
- package/dist/readyclasses.module.scss.es.js +5 -5
- package/dist/util/helper.cjs.js +1 -1
- package/dist/util/helper.cjs.js.map +1 -1
- package/dist/util/helper.es.js +33 -16
- package/dist/util/helper.es.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
const componentsWithKeyEventsToPrevent = ["CheckboxWrapper"];
|
|
2
|
+
const componentsWithKeyEventsToPrevent = /* @__PURE__ */ new Set(["CheckboxWrapper"]);
|
|
3
3
|
const getDisplayName = (WrappedComponent) => {
|
|
4
4
|
return WrappedComponent.displayName ?? WrappedComponent.name ?? "Component";
|
|
5
5
|
};
|
|
@@ -28,9 +28,7 @@ const withReadOnly = (WrappedComponent, options) => {
|
|
|
28
28
|
e.preventDefault();
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
if (readOnlyView && componentsWithKeyEventsToPrevent.
|
|
32
|
-
WrappedComponent.displayName || WrappedComponent.name
|
|
33
|
-
)) {
|
|
31
|
+
if (readOnlyView && componentsWithKeyEventsToPrevent.has(WrappedComponent.displayName || WrappedComponent.name)) {
|
|
34
32
|
const props = {};
|
|
35
33
|
props.onKeyUp = (e) => {
|
|
36
34
|
preventSubmissionKeys(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withReadOnly.es.js","sources":["../../src/components/withReadOnly.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, ForwardedRef, PropsWithChildren, PropsWithoutRef } from \"react\";\n\nexport interface WithReadOnlyProps {\n readOnlyView?: boolean;\n required?: boolean;\n helperText?: string;\n type?: string;\n}\n\nconst componentsWithKeyEventsToPrevent
|
|
1
|
+
{"version":3,"file":"withReadOnly.es.js","sources":["../../src/components/withReadOnly.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, ForwardedRef, PropsWithChildren, PropsWithoutRef } from \"react\";\n\nexport interface WithReadOnlyProps {\n readOnlyView?: boolean;\n required?: boolean;\n helperText?: string;\n type?: string;\n}\n\nconst componentsWithKeyEventsToPrevent = new Set<string>([\"CheckboxWrapper\"]);\n\nconst getDisplayName = <P,>(WrappedComponent: ComponentType<P>) => {\n return WrappedComponent.displayName ?? WrappedComponent.name ?? \"Component\";\n};\n\nconst getConditionalProps = (readOnlyView: boolean, type: string, helperText?: string) => {\n const props: Record<string, unknown> = {};\n\n if (readOnlyView) {\n props.style = { pointerEvents: \"none\", userSelect: \"text\" };\n if (helperText) {\n props.helperText = \"\";\n }\n } else if (helperText) {\n props.helperText = helperText;\n }\n\n if (type) {\n props.type = type;\n }\n\n return props;\n};\n\ntype WithReadOnlyOptions = {\n isWrapperComponent: boolean;\n};\n\nexport const withReadOnly = <P extends object>(\n WrappedComponent: ComponentType<P>,\n options?: WithReadOnlyOptions\n) => {\n const { isWrapperComponent } = options || {};\n\n const preventKeyUpAndKeyDownHandlerForSpecificComponents = (readOnlyView: boolean) => {\n const preventSubmissionKeys = (e: KeyboardEvent) => {\n const isEnterOrSpace = (e: KeyboardEvent) => e.key === \"Enter\" || e.key === \" \";\n if (isEnterOrSpace(e)) {\n e.stopPropagation();\n e.preventDefault();\n }\n };\n\n if (\n readOnlyView &&\n componentsWithKeyEventsToPrevent.has(WrappedComponent.displayName || WrappedComponent.name)\n ) {\n const props: Record<string, unknown> = {};\n\n props.onKeyUp = (e: KeyboardEvent) => {\n preventSubmissionKeys(e);\n };\n\n props.onKeyDown = (e: KeyboardEvent) => {\n preventSubmissionKeys(e);\n };\n\n return props;\n }\n\n return {};\n };\n\n const WithReadOnlyComponent = React.forwardRef(\n (\n props: PropsWithoutRef<PropsWithChildren<P & WithReadOnlyProps>>,\n ref: ForwardedRef<unknown>\n ) => {\n const {\n readOnlyView = false,\n required,\n children,\n helperText,\n type = \"\",\n ...restProps\n } = props;\n\n return (\n <WrappedComponent\n ref={ref}\n {...(restProps as P)}\n data-readonlyview={readOnlyView}\n aria-readonly={isWrapperComponent ? undefined : readOnlyView}\n required={readOnlyView ? false : required}\n {...getConditionalProps(readOnlyView, type, helperText)}\n {...preventKeyUpAndKeyDownHandlerForSpecificComponents(readOnlyView)}\n >\n {children}\n </WrappedComponent>\n );\n }\n );\n\n WithReadOnlyComponent.displayName = `withReadOnly_${getDisplayName(WrappedComponent)}`;\n return WithReadOnlyComponent;\n};\n"],"names":["e"],"mappings":";AAyBA,MAAM,mCAAmC,oBAAI,IAAY,CAAC,iBAAiB,CAAC;AAE5E,MAAM,iBAAiB,CAAK,qBAAuC;AACjE,SAAO,iBAAiB,eAAe,iBAAiB,QAAQ;AAClE;AAEA,MAAM,sBAAsB,CAAC,cAAuB,MAAc,eAAwB;AACxF,QAAM,QAAiC,CAAA;AAEvC,MAAI,cAAc;AAChB,UAAM,QAAQ,EAAE,eAAe,QAAQ,YAAY,OAAA;AACnD,QAAI,YAAY;AACd,YAAM,aAAa;AAAA,IACrB;AAAA,EACF,WAAW,YAAY;AACrB,UAAM,aAAa;AAAA,EACrB;AAEA,MAAI,MAAM;AACR,UAAM,OAAO;AAAA,EACf;AAEA,SAAO;AACT;AAMO,MAAM,eAAe,CAC1B,kBACA,YACG;AACH,QAAM,EAAE,uBAAuB,WAAW,CAAA;AAE1C,QAAM,qDAAqD,CAAC,iBAA0B;AACpF,UAAM,wBAAwB,CAAC,MAAqB;AAClD,YAAM,iBAAiB,CAACA,OAAqBA,GAAE,QAAQ,WAAWA,GAAE,QAAQ;AAC5E,UAAI,eAAe,CAAC,GAAG;AACrB,UAAE,gBAAA;AACF,UAAE,eAAA;AAAA,MACJ;AAAA,IACF;AAEA,QACE,gBACA,iCAAiC,IAAI,iBAAiB,eAAe,iBAAiB,IAAI,GAC1F;AACA,YAAM,QAAiC,CAAA;AAEvC,YAAM,UAAU,CAAC,MAAqB;AACpC,8BAAsB,CAAC;AAAA,MACzB;AAEA,YAAM,YAAY,CAAC,MAAqB;AACtC,8BAAsB,CAAC;AAAA,MACzB;AAEA,aAAO;AAAA,IACT;AAEA,WAAO,CAAA;AAAA,EACT;AAEA,QAAM,wBAAwB,MAAM;AAAA,IAClC,CACE,OACA,QACG;AACH,YAAM;AAAA,QACJ,eAAe;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP,GAAG;AAAA,MAAA,IACD;AAEJ,aACE,sBAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACC,GAAI;AAAA,UACL,qBAAmB;AAAA,UACnB,iBAAe,qBAAqB,SAAY;AAAA,UAChD,UAAU,eAAe,QAAQ;AAAA,UAChC,GAAG,oBAAoB,cAAc,MAAM,UAAU;AAAA,UACrD,GAAG,mDAAmD,YAAY;AAAA,QAAA;AAAA,QAElE;AAAA,MAAA;AAAA,IAGP;AAAA,EAAA;AAGF,wBAAsB,cAAc,gBAAgB,eAAe,gBAAgB,CAAC;AACpF,SAAO;AACT;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useClickOutside=(t,i,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useClickOutside=(t,i,o)=>{function c(e){const o=null==t?void 0:t.current;o&&(e.composedPath().includes(o)||i(e))}e.useEffect(()=>(setTimeout(()=>window.addEventListener("click",c)),()=>{setTimeout(()=>window.removeEventListener("click",c))}),o)};
|
|
2
2
|
//# sourceMappingURL=useClickOutside.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.cjs.js","sources":["../../src/hooks/useClickOutside.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DependencyList, useEffect } from \"react\";\n\nexport const useClickOutside = (\n myElementRef: React.RefObject<HTMLElement>,\n onClickOutside: (event: MouseEvent) => void,\n dependencies?: DependencyList\n) => {\n function eventListener(event: MouseEvent) {\n const myElement = myElementRef?.current;\n if (!myElement) {\n return;\n }\n const clickedInsideMyElement =
|
|
1
|
+
{"version":3,"file":"useClickOutside.cjs.js","sources":["../../src/hooks/useClickOutside.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DependencyList, useEffect } from \"react\";\n\nexport const useClickOutside = (\n myElementRef: React.RefObject<HTMLElement | null>,\n onClickOutside: (event: MouseEvent) => void,\n dependencies?: DependencyList\n) => {\n function eventListener(event: MouseEvent) {\n const myElement = myElementRef?.current;\n if (!myElement) {\n return;\n }\n const clickedInsideMyElement = event.composedPath().includes(myElement);\n\n if (!clickedInsideMyElement) {\n onClickOutside(event);\n }\n }\n useEffect(() => {\n setTimeout(() => window.addEventListener(\"click\", eventListener));\n\n return () => {\n setTimeout(() => window.removeEventListener(\"click\", eventListener));\n };\n }, dependencies);\n};\n"],"names":["myElementRef","onClickOutside","dependencies","eventListener","event","myElement","current","composedPath","includes","useEffect","setTimeout","window","addEventListener","removeEventListener"],"mappings":"iIAkB+B,CAC7BA,EACAC,EACAC,KAEA,SAASC,EAAcC,GACrB,MAAMC,EAAY,MAAAL,OAAA,EAAAA,EAAcM,QAC3BD,IAG0BD,EAAMG,eAAeC,SAASH,IAG3DJ,EAAeG,GAEnB,CACAK,EAAAA,UAAU,KACRC,WAAW,IAAMC,OAAOC,iBAAiB,QAAST,IAE3C,KACLO,WAAW,IAAMC,OAAOE,oBAAoB,QAASV,MAEtDD"}
|
|
@@ -5,7 +5,7 @@ const useClickOutside = (myElementRef, onClickOutside, dependencies) => {
|
|
|
5
5
|
if (!myElement) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
const clickedInsideMyElement =
|
|
8
|
+
const clickedInsideMyElement = event.composedPath().includes(myElement);
|
|
9
9
|
if (!clickedInsideMyElement) {
|
|
10
10
|
onClickOutside(event);
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.es.js","sources":["../../src/hooks/useClickOutside.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DependencyList, useEffect } from \"react\";\n\nexport const useClickOutside = (\n myElementRef: React.RefObject<HTMLElement>,\n onClickOutside: (event: MouseEvent) => void,\n dependencies?: DependencyList\n) => {\n function eventListener(event: MouseEvent) {\n const myElement = myElementRef?.current;\n if (!myElement) {\n return;\n }\n const clickedInsideMyElement =
|
|
1
|
+
{"version":3,"file":"useClickOutside.es.js","sources":["../../src/hooks/useClickOutside.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DependencyList, useEffect } from \"react\";\n\nexport const useClickOutside = (\n myElementRef: React.RefObject<HTMLElement | null>,\n onClickOutside: (event: MouseEvent) => void,\n dependencies?: DependencyList\n) => {\n function eventListener(event: MouseEvent) {\n const myElement = myElementRef?.current;\n if (!myElement) {\n return;\n }\n const clickedInsideMyElement = event.composedPath().includes(myElement);\n\n if (!clickedInsideMyElement) {\n onClickOutside(event);\n }\n }\n useEffect(() => {\n setTimeout(() => window.addEventListener(\"click\", eventListener));\n\n return () => {\n setTimeout(() => window.removeEventListener(\"click\", eventListener));\n };\n }, dependencies);\n};\n"],"names":[],"mappings":";AAkBO,MAAM,kBAAkB,CAC7B,cACA,gBACA,iBACG;AACH,WAAS,cAAc,OAAmB;AACxC,UAAM,YAAY,6CAAc;AAChC,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AACA,UAAM,yBAAyB,MAAM,aAAA,EAAe,SAAS,SAAS;AAEtE,QAAI,CAAC,wBAAwB;AAC3B,qBAAe,KAAK;AAAA,IACtB;AAAA,EACF;AACA,YAAU,MAAM;AACd,eAAW,MAAM,OAAO,iBAAiB,SAAS,aAAa,CAAC;AAEhE,WAAO,MAAM;AACX,iBAAW,MAAM,OAAO,oBAAoB,SAAS,aAAa,CAAC;AAAA,IACrE;AAAA,EACF,GAAG,YAAY;AACjB;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useDebouncedCallback=(r,t,u)=>{const c=e.useRef(),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useDebouncedCallback=(r,t,u)=>{const c=e.useRef(void 0),l=u?[r,t,...u]:[r,t],n=e.useCallback((...e)=>{null!=c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{r(...e)},t)},l),o=e.useCallback(()=>{null!=c.current&&(clearTimeout(c.current),c.current=void 0)},[]);return Object.assign(n,{cancel:o})};
|
|
2
2
|
//# sourceMappingURL=useDebouncedCallback.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebouncedCallback.cjs.js","sources":["../../src/hooks/useDebouncedCallback.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\n\nexport const useDebouncedCallback = <T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n dependencies?: React.DependencyList\n) => {\n const timeout = React.useRef<ReturnType<typeof setTimeout
|
|
1
|
+
{"version":3,"file":"useDebouncedCallback.cjs.js","sources":["../../src/hooks/useDebouncedCallback.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\n\nexport const useDebouncedCallback = <T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n dependencies?: React.DependencyList\n) => {\n const timeout = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const comboDeps = dependencies ? [callback, delay, ...dependencies] : [callback, delay];\n\n const debounced = React.useCallback((...args: T) => {\n if (timeout.current != null) {\n clearTimeout(timeout.current);\n }\n\n timeout.current = setTimeout(() => {\n callback(...args);\n }, delay);\n }, comboDeps);\n\n const cancel = React.useCallback(() => {\n if (timeout.current != null) {\n clearTimeout(timeout.current);\n timeout.current = undefined;\n }\n }, []);\n\n return Object.assign(debounced, { cancel });\n};\n"],"names":["callback","delay","dependencies","timeout","React","useRef","comboDeps","debounced","useCallback","args","current","clearTimeout","setTimeout","cancel","Object","assign"],"mappings":"sIAkBoC,CAClCA,EACAC,EACAC,KAEA,MAAMC,EAAUC,EAAMC,YAAkD,GAClEC,EAAYJ,EAAe,CAACF,EAAUC,KAAUC,GAAgB,CAACF,EAAUC,GAE3EM,EAAYH,EAAMI,YAAY,IAAIC,KACf,MAAnBN,EAAQO,SACVC,aAAaR,EAAQO,SAGvBP,EAAQO,QAAUE,WAAW,KAC3BZ,KAAYS,IACXR,IACFK,GAEGO,EAAST,EAAMI,YAAY,KACR,MAAnBL,EAAQO,UACVC,aAAaR,EAAQO,SACrBP,EAAQO,aAAU,IAEnB,IAEH,OAAOI,OAAOC,OAAOR,EAAW,CAAEM"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
const useDebouncedCallback = (callback, delay, dependencies) => {
|
|
3
|
-
const timeout = React.useRef();
|
|
3
|
+
const timeout = React.useRef(void 0);
|
|
4
4
|
const comboDeps = dependencies ? [callback, delay, ...dependencies] : [callback, delay];
|
|
5
|
-
|
|
5
|
+
const debounced = React.useCallback((...args) => {
|
|
6
6
|
if (timeout.current != null) {
|
|
7
7
|
clearTimeout(timeout.current);
|
|
8
8
|
}
|
|
@@ -10,6 +10,13 @@ const useDebouncedCallback = (callback, delay, dependencies) => {
|
|
|
10
10
|
callback(...args);
|
|
11
11
|
}, delay);
|
|
12
12
|
}, comboDeps);
|
|
13
|
+
const cancel = React.useCallback(() => {
|
|
14
|
+
if (timeout.current != null) {
|
|
15
|
+
clearTimeout(timeout.current);
|
|
16
|
+
timeout.current = void 0;
|
|
17
|
+
}
|
|
18
|
+
}, []);
|
|
19
|
+
return Object.assign(debounced, { cancel });
|
|
13
20
|
};
|
|
14
21
|
export {
|
|
15
22
|
useDebouncedCallback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebouncedCallback.es.js","sources":["../../src/hooks/useDebouncedCallback.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\n\nexport const useDebouncedCallback = <T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n dependencies?: React.DependencyList\n) => {\n const timeout = React.useRef<ReturnType<typeof setTimeout
|
|
1
|
+
{"version":3,"file":"useDebouncedCallback.es.js","sources":["../../src/hooks/useDebouncedCallback.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from \"react\";\n\nexport const useDebouncedCallback = <T extends unknown[]>(\n callback: (...args: T) => void,\n delay: number,\n dependencies?: React.DependencyList\n) => {\n const timeout = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n const comboDeps = dependencies ? [callback, delay, ...dependencies] : [callback, delay];\n\n const debounced = React.useCallback((...args: T) => {\n if (timeout.current != null) {\n clearTimeout(timeout.current);\n }\n\n timeout.current = setTimeout(() => {\n callback(...args);\n }, delay);\n }, comboDeps);\n\n const cancel = React.useCallback(() => {\n if (timeout.current != null) {\n clearTimeout(timeout.current);\n timeout.current = undefined;\n }\n }, []);\n\n return Object.assign(debounced, { cancel });\n};\n"],"names":[],"mappings":";AAkBO,MAAM,uBAAuB,CAClC,UACA,OACA,iBACG;AACH,QAAM,UAAU,MAAM,OAAkD,MAAS;AACjF,QAAM,YAAY,eAAe,CAAC,UAAU,OAAO,GAAG,YAAY,IAAI,CAAC,UAAU,KAAK;AAEtF,QAAM,YAAY,MAAM,YAAY,IAAI,SAAY;AAClD,QAAI,QAAQ,WAAW,MAAM;AAC3B,mBAAa,QAAQ,OAAO;AAAA,IAC9B;AAEA,YAAQ,UAAU,WAAW,MAAM;AACjC,eAAS,GAAG,IAAI;AAAA,IAClB,GAAG,KAAK;AAAA,EACV,GAAG,SAAS;AAEZ,QAAM,SAAS,MAAM,YAAY,MAAM;AACrC,QAAI,QAAQ,WAAW,MAAM;AAC3B,mBAAa,QAAQ,OAAO;AAC5B,cAAQ,UAAU;AAAA,IACpB;AAAA,EACF,GAAG,CAAA,CAAE;AAEL,SAAO,OAAO,OAAO,WAAW,EAAE,QAAQ;AAC5C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetDomRoot.cjs.js","sources":["../../src/hooks/useGetDomRoot.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from \"react\";\n\nexport const useGetDomRoot = (\n passedDomRoot: HTMLElement | undefined,\n relativeElement: React.RefObject<HTMLDivElement> | null\n) => {\n const [root, setRoot] = useState<HTMLElement>(document.body);\n\n useEffect(() => {\n if (relativeElement?.current && !passedDomRoot) {\n const closestBaseStylingWrapper = relativeElement.current.closest(\".basestyling-wrapper\");\n\n if (closestBaseStylingWrapper) {\n setRoot(closestBaseStylingWrapper as HTMLElement);\n return;\n }\n } else if (passedDomRoot) {\n setRoot(passedDomRoot);\n return;\n }\n }, [relativeElement]);\n\n return { root };\n};\n"],"names":["passedDomRoot","relativeElement","root","setRoot","useState","document","body","useEffect","current","closestBaseStylingWrapper","closest"],"mappings":"+HAkB6B,CAC3BA,EACAC,KAEA,MAAOC,EAAMC,GAAWC,EAAAA,SAAsBC,SAASC,MAgBvD,OAdAC,EAAAA,UAAU,KACR,IAAI,MAAAN,OAAA,EAAAA,EAAiBO,WAAYR,EAAe,CAC9C,MAAMS,EAA4BR,EAAgBO,QAAQE,QAAQ,wBAElE,GAAID,EAEF,YADAN,EAAQM,EAGZ,SAAWT,EAET,YADAG,EAAQH,IAGT,CAACC,IAEG,CAAEC"}
|
|
1
|
+
{"version":3,"file":"useGetDomRoot.cjs.js","sources":["../../src/hooks/useGetDomRoot.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from \"react\";\n\nexport const useGetDomRoot = (\n passedDomRoot: HTMLElement | undefined,\n relativeElement: React.RefObject<HTMLDivElement | null> | null\n) => {\n const [root, setRoot] = useState<HTMLElement>(document.body);\n\n useEffect(() => {\n if (relativeElement?.current && !passedDomRoot) {\n const closestBaseStylingWrapper = relativeElement.current.closest(\".basestyling-wrapper\");\n\n if (closestBaseStylingWrapper) {\n setRoot(closestBaseStylingWrapper as HTMLElement);\n return;\n }\n } else if (passedDomRoot) {\n setRoot(passedDomRoot);\n return;\n }\n }, [relativeElement]);\n\n return { root };\n};\n"],"names":["passedDomRoot","relativeElement","root","setRoot","useState","document","body","useEffect","current","closestBaseStylingWrapper","closest"],"mappings":"+HAkB6B,CAC3BA,EACAC,KAEA,MAAOC,EAAMC,GAAWC,EAAAA,SAAsBC,SAASC,MAgBvD,OAdAC,EAAAA,UAAU,KACR,IAAI,MAAAN,OAAA,EAAAA,EAAiBO,WAAYR,EAAe,CAC9C,MAAMS,EAA4BR,EAAgBO,QAAQE,QAAQ,wBAElE,GAAID,EAEF,YADAN,EAAQM,EAGZ,SAAWT,EAET,YADAG,EAAQH,IAGT,CAACC,IAEG,CAAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetDomRoot.es.js","sources":["../../src/hooks/useGetDomRoot.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from \"react\";\n\nexport const useGetDomRoot = (\n passedDomRoot: HTMLElement | undefined,\n relativeElement: React.RefObject<HTMLDivElement> | null\n) => {\n const [root, setRoot] = useState<HTMLElement>(document.body);\n\n useEffect(() => {\n if (relativeElement?.current && !passedDomRoot) {\n const closestBaseStylingWrapper = relativeElement.current.closest(\".basestyling-wrapper\");\n\n if (closestBaseStylingWrapper) {\n setRoot(closestBaseStylingWrapper as HTMLElement);\n return;\n }\n } else if (passedDomRoot) {\n setRoot(passedDomRoot);\n return;\n }\n }, [relativeElement]);\n\n return { root };\n};\n"],"names":[],"mappings":";AAkBO,MAAM,gBAAgB,CAC3B,eACA,oBACG;AACH,QAAM,CAAC,MAAM,OAAO,IAAI,SAAsB,SAAS,IAAI;AAE3D,YAAU,MAAM;AACd,SAAI,mDAAiB,YAAW,CAAC,eAAe;AAC9C,YAAM,4BAA4B,gBAAgB,QAAQ,QAAQ,sBAAsB;AAExF,UAAI,2BAA2B;AAC7B,gBAAQ,yBAAwC;AAChD;AAAA,MACF;AAAA,IACF,WAAW,eAAe;AACxB,cAAQ,aAAa;AACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,SAAO,EAAE,KAAA;AACX;"}
|
|
1
|
+
{"version":3,"file":"useGetDomRoot.es.js","sources":["../../src/hooks/useGetDomRoot.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useState } from \"react\";\n\nexport const useGetDomRoot = (\n passedDomRoot: HTMLElement | undefined,\n relativeElement: React.RefObject<HTMLDivElement | null> | null\n) => {\n const [root, setRoot] = useState<HTMLElement>(document.body);\n\n useEffect(() => {\n if (relativeElement?.current && !passedDomRoot) {\n const closestBaseStylingWrapper = relativeElement.current.closest(\".basestyling-wrapper\");\n\n if (closestBaseStylingWrapper) {\n setRoot(closestBaseStylingWrapper as HTMLElement);\n return;\n }\n } else if (passedDomRoot) {\n setRoot(passedDomRoot);\n return;\n }\n }, [relativeElement]);\n\n return { root };\n};\n"],"names":[],"mappings":";AAkBO,MAAM,gBAAgB,CAC3B,eACA,oBACG;AACH,QAAM,CAAC,MAAM,OAAO,IAAI,SAAsB,SAAS,IAAI;AAE3D,YAAU,MAAM;AACd,SAAI,mDAAiB,YAAW,CAAC,eAAe;AAC9C,YAAM,4BAA4B,gBAAgB,QAAQ,QAAQ,sBAAsB;AAExF,UAAI,2BAA2B;AAC7B,gBAAQ,yBAAwC;AAChD;AAAA,MACF;AAAA,IACF,WAAW,eAAe;AACxB,cAAQ,aAAa;AACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,SAAO,EAAE,KAAA;AACX;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=require("./useDebouncedCallback.cjs.js");var o=(t=>(t.LEFT="left",t.CENTER="center",t.CENTER_H="centerh",t.RIGHT="right",t))(o||{}),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=require("./useDebouncedCallback.cjs.js");var o=(t=>(t.LEFT="left",t.CENTER="center",t.CENTER_H="centerh",t.RIGHT="right",t))(o||{}),n=(t=>(t.TOP="top",t.CENTER="center",t.CENTER_V="centerv",t.BOTTOM="bottom",t))(n||{});const i={relativeElement:void 0,elementToBePositioned:void 0,transformOrigin:{horizontal:"left",vertical:"top"},placement:{horizontal:"left",vertical:"top"},offset:{top:0,right:0,bottom:0,left:0},debounceAmount:20};exports.horizontal=o,exports.usePosition=(o=i)=>{const n={...i,...o},[r,l]=t.useState(!1);void 0===n.transformOrigin&&(n.transformOrigin=i.transformOrigin),void 0===n.placement&&(n.placement=i.placement),void 0===n.offset&&(n.offset=i.offset);const[s,a]=t.useState({left:0,top:0,right:"initial",bottom:"initial"}),c=(t,e,o)=>{var i,r;const l=((t,e,o,i,r)=>{const l="center"===e?(t=>{if("horizontal"===t)return"centerh";if("vertical"===t)return"centerv";throw new Error(`the requested return value isn't "vertical" or "horizontal" ${t} was given.`)})(o):e,s=((t,e,o,n,i)=>{let r=0;return"left"===t[e]||"top"===t[e]?r=o[n]:"center"===t[e]?r=o[n]-i["horizontal"===e?"width":"height"]/2:"right"!==t[e]&&"bottom"!==t[e]||(r=window["horizontal"===e?"innerWidth":"innerHeight"]-o[n]),r})(t,o,i,l,r),a=((t,e,o)=>{var i,r,l,s,a,c,d,u,h,f,v,w;let m=t;return("horizontal"===e&&0!==(null==(i=n.offset)?void 0:i.left)||"horizontal"===e&&0!==(null==(r=n.offset)?void 0:r.right))&&("left"!==o[e]&&"center"!==o[e]||(m+=null==(l=n.offset)?void 0:l.left,m-=null==(s=n.offset)?void 0:s.right),"right"===o[e]&&(m-=null==(a=n.offset)?void 0:a.left,m+=null==(c=n.offset)?void 0:c.right)),("vertical"===e&&0!==(null==(d=n.offset)?void 0:d.top)||"vertical"===e&&0!==(null==(u=n.offset)?void 0:u.bottom))&&("top"!==o[e]&&"center"!==o[e]||(m+=null==(h=n.offset)?void 0:h.top,m-=null==(f=n.offset)?void 0:f.bottom),"bottom"===o[e]&&(m-=null==(v=n.offset)?void 0:v.top,m+=null==(w=n.offset)?void 0:w.bottom)),m})(s,o,t);return((t,e,o,n)=>{let i=t;return i<0&&(i=0),("left"===e[o]&&i>window.innerWidth-n.width||"center"===e[o]&&"horizontal"===o&&i>window.innerWidth-n.width)&&(i=window.innerWidth-n.width),("top"===e[o]&&i>window.innerHeight-n.height||"center"===e[o]&&"vertical"===o&&i>window.innerHeight-n.height)&&(i=window.innerHeight-n.height),"right"===e[o]&&i>window.innerWidth-n.width&&(i=window.innerWidth-n.width),"bottom"===e[o]&&i>window.innerHeight-n.height&&(i=window.innerHeight-n.height),i})(a,t,o,r)})(n.transformOrigin,n.placement[o],o,t,e);let s="left",c="right";"horizontal"===o&&"right"===(null==(i=n.transformOrigin)?void 0:i.horizontal)?(s="right",c="left"):"horizontal"===o&&(s="left",c="right"),"vertical"===o&&"bottom"===(null==(r=n.transformOrigin)?void 0:r.vertical)?(s="bottom",c="top"):"vertical"===o&&(s="top",c="bottom"),a(t=>({...t,[s]:l,[c]:"initial"}))},d=()=>{var t,e;if(!(null==(t=n.relativeElement)?void 0:t.current)||!(null==(e=n.elementToBePositioned)?void 0:e.current))return;const o=n.relativeElement.current.getBoundingClientRect(),i={height:n.elementToBePositioned.current.offsetHeight,width:n.elementToBePositioned.current.offsetWidth},s={top:o.top,right:o.right,bottom:o.bottom,center:0,centerv:o.top+o.height/2,centerh:o.left+o.width/2,left:o.left,width:o.width,height:o.height,x:o.x,y:o.y};c(s,i,"horizontal"),c(s,i,"vertical"),r||l(!0)},u=t.useRef(d);u.current=d;const h=e.useDebouncedCallback(()=>{u.current()},n.debounceAmount??20);return t.useEffect(()=>{var t,e;if(!r)return;let o=null;const i=()=>{null!==o&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=null,u.current()})};window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),window.visualViewport&&(window.visualViewport.addEventListener("resize",i),window.visualViewport.addEventListener("scroll",i));const l=[];if(null==(t=n.relativeElement)?void 0:t.current){const t=n.relativeElement.current;l.push(...(t=>{const e=[];let o=t.parentElement;for(;o&&o!==document.documentElement;){const t=window.getComputedStyle(o),n=t.overflowX,i=t.overflowY;"auto"!==n&&"scroll"!==n&&"auto"!==i&&"scroll"!==i||e.push(o),o=o.parentElement}return e})(t));for(const e of l)e.addEventListener("scroll",i)}let s,a=0,c=0;if("undefined"!=typeof ResizeObserver&&(null==(e=n.elementToBePositioned)?void 0:e.current)){const t=n.elementToBePositioned.current;a=t.offsetWidth,c=t.offsetHeight,s=new ResizeObserver(t=>{const e=t[0];if(!e)return;const{width:n,height:i}=e.contentRect;(Math.abs(n-a)>1||Math.abs(i-c)>1)&&(a=n,c=i,null!==o&&cancelAnimationFrame(o),o=requestAnimationFrame(()=>{o=null,u.current()}))}),s.observe(t)}return()=>{null!==o&&cancelAnimationFrame(o),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),window.visualViewport&&(window.visualViewport.removeEventListener("resize",i),window.visualViewport.removeEventListener("scroll",i));for(const t of l)t.removeEventListener("scroll",i);s&&s.disconnect()}},[r]),{top:s.top,bottom:s.bottom,left:s.left,right:s.right,calculatePosition:h,calculatePositionImmediate:()=>{u.current()},initialCalculationDone:r,resetCalculationState:()=>{l(!1)}}},exports.vertical=n;
|
|
2
2
|
//# sourceMappingURL=usePosition.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePosition.cjs.js","sources":["../../src/hooks/usePosition.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useState } from \"react\";\nimport { useDebouncedCallback } from \"./useDebouncedCallback\";\n\nexport interface ConfigObject {\n relativeElement: RefElement;\n elementToBePositioned: RefElement;\n transformOrigin?: Placement;\n placement?: Placement;\n offset?: Offset;\n debounceAmount?: number;\n}\n\nexport enum horizontal {\n LEFT = \"left\",\n CENTER = \"center\",\n CENTER_H = \"centerh\",\n RIGHT = \"right\"\n}\n\nexport enum vertical {\n TOP = \"top\",\n CENTER = \"center\",\n CENTER_V = \"centerv\",\n BOTTOM = \"bottom\"\n}\n\nexport type HorizontalPlacement = `${horizontal}`;\nexport type VerticalPlacement = `${vertical}`;\n\ntype Axis = \"vertical\" | \"horizontal\";\ntype RefElement = React.RefObject<HTMLOrSVGElement> | undefined;\n\ninterface DomRectObject {\n top: number;\n right: number;\n bottom: number;\n left: number;\n center: number;\n centerh: number;\n centerv: number;\n width: number;\n height: number;\n x: number;\n y: number;\n}\n\nexport interface Placement {\n horizontal: HorizontalPlacement;\n vertical: VerticalPlacement;\n}\n\nexport interface Offset {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport interface Position {\n top: PositionType;\n right: PositionType;\n bottom: PositionType;\n left: PositionType;\n}\n\ninterface Dimensions {\n height: number;\n width: number;\n}\n\nexport type PositionType = number | \"initial\";\n\nconst defaultConfigObject: ConfigObject = {\n relativeElement: undefined,\n elementToBePositioned: undefined,\n transformOrigin: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n placement: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n offset: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n debounceAmount: 20\n};\n\nexport const usePosition = (providedConfigObject: ConfigObject = defaultConfigObject) => {\n const configObject = { ...defaultConfigObject, ...providedConfigObject };\n const [initialCalculationDone, setInitialCalculationDone] = useState(false);\n\n if (configObject.transformOrigin === undefined) {\n configObject.transformOrigin = defaultConfigObject.transformOrigin;\n }\n\n if (configObject.placement === undefined) {\n configObject.placement = defaultConfigObject.placement;\n }\n\n if (configObject.offset === undefined) {\n configObject.offset = defaultConfigObject.offset;\n }\n\n const [position, setPosition] = useState<Position>({\n left: 0,\n top: 0,\n right: \"initial\",\n bottom: \"initial\"\n });\n\n const _fixPossibleViewportOverflow = (\n value: number,\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n elDimensions: Dimensions\n ) => {\n let returnValue = value;\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"top\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"center\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"bottom\" && returnValue < 0)\n ) {\n returnValue = 0;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" &&\n returnValue > window.innerWidth - elDimensions.width) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"horizontal\" &&\n returnValue > window.innerWidth - elDimensions.width)\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"top\" &&\n returnValue > window.innerHeight - elDimensions.height) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"vertical\" &&\n returnValue > window.innerHeight - elDimensions.height)\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"right\" &&\n returnValue > window.innerWidth - elDimensions.width\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"bottom\" &&\n returnValue > window.innerHeight - elDimensions.height\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n return returnValue;\n };\n\n const _applyOffsetToPlacementValue = (\n value: number,\n requestedReturnValue: Axis,\n transformOrigin: Placement\n ) => {\n let returnValue = value;\n if (\n (requestedReturnValue === \"horizontal\" && configObject.offset?.left !== 0) ||\n (requestedReturnValue === \"horizontal\" && configObject.offset?.right !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.left!;\n returnValue -= configObject.offset?.right!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"right\") {\n returnValue -= configObject.offset?.left!;\n returnValue += configObject.offset?.right!;\n }\n }\n\n if (\n (requestedReturnValue === \"vertical\" && configObject.offset?.top !== 0) ||\n (requestedReturnValue === \"vertical\" && configObject.offset?.bottom !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"top\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.top!;\n returnValue -= configObject.offset?.bottom!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"bottom\") {\n returnValue -= configObject.offset?.top!;\n returnValue += configObject.offset?.bottom!;\n }\n }\n\n return returnValue;\n };\n\n const _calculateInitialPlacementValue = (\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n placementOriginDefinition: HorizontalPlacement | VerticalPlacement,\n elDimensions: Dimensions\n ) => {\n let value = 0;\n\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"top\"\n ) {\n value = relEl[placementOriginDefinition];\n } else if (transformOrigin[requestedReturnValue] === \"center\") {\n value =\n relEl[placementOriginDefinition] -\n elDimensions[requestedReturnValue === \"horizontal\" ? \"width\" : \"height\"] / 2;\n } else if (\n transformOrigin[requestedReturnValue] === \"right\" ||\n transformOrigin[requestedReturnValue] === \"bottom\"\n ) {\n value =\n window[requestedReturnValue === \"horizontal\" ? \"innerWidth\" : \"innerHeight\"] -\n relEl[placementOriginDefinition];\n }\n\n return value;\n };\n\n /**\n *\n * @param requestedReturnValue whether the requested return value is for the horizontal or vertical axis\n * @returns either the horizontally centered placement definition (centerh) or the vertically centered one (centerv)\n */\n const _determineCenteredPlacementOrigin = (requestedReturnValue: Axis) => {\n if (requestedReturnValue === \"horizontal\") {\n return \"centerh\";\n } else if (requestedReturnValue === \"vertical\") {\n return \"centerv\";\n }\n throw new Error(\n `the requested return value isn't \"vertical\" or \"horizontal\" ${requestedReturnValue} was given.`\n );\n };\n\n const _calculatePlacementValue = (\n transformOrigin: Placement,\n placement: HorizontalPlacement | VerticalPlacement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n elDimensions: Dimensions\n ): number => {\n const placementOriginDefinition =\n placement === \"center\" ? _determineCenteredPlacementOrigin(requestedReturnValue) : placement;\n\n const value = _calculateInitialPlacementValue(\n transformOrigin,\n requestedReturnValue,\n relEl,\n placementOriginDefinition,\n elDimensions\n );\n\n const valueWithOffset = _applyOffsetToPlacementValue(\n value,\n requestedReturnValue,\n transformOrigin\n );\n\n return _fixPossibleViewportOverflow(\n valueWithOffset,\n transformOrigin,\n requestedReturnValue,\n elDimensions\n );\n };\n\n const _calculatePlacement = (relEl: DomRectObject, elDimensions: Dimensions, axis: Axis) => {\n const placementValue = _calculatePlacementValue(\n configObject.transformOrigin!,\n configObject.placement![axis]!,\n axis,\n relEl,\n elDimensions\n );\n\n let direction = \"left\";\n let oppositeDirection = \"right\";\n\n if (axis === \"horizontal\" && configObject.transformOrigin?.horizontal === \"right\") {\n direction = \"right\";\n oppositeDirection = \"left\";\n } else if (axis === \"horizontal\") {\n direction = \"left\";\n oppositeDirection = \"right\";\n }\n\n if (axis === \"vertical\" && configObject.transformOrigin?.vertical === \"bottom\") {\n direction = \"bottom\";\n oppositeDirection = \"top\";\n } else if (axis === \"vertical\") {\n direction = \"top\";\n oppositeDirection = \"bottom\";\n }\n\n setPosition(prevState => ({\n ...prevState,\n [direction]: placementValue,\n [oppositeDirection]: \"initial\"\n }));\n };\n\n const calculatePosition = useDebouncedCallback(() => {\n if (!configObject.relativeElement?.current || !configObject.elementToBePositioned?.current) {\n return;\n }\n const relativeElRect = (configObject.relativeElement!\n .current as HTMLElement)!.getBoundingClientRect();\n const elementToBePositionedDimensions: Dimensions = {\n height: (configObject.elementToBePositioned!.current as HTMLElement).offsetHeight,\n width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth\n };\n\n /** We want to add a center (horizontal and vertical) property to the DOMRect object. Since it's a special object we can't modify so we clone it and add it. */\n const clonedRelEl = {\n top: relativeElRect.top,\n right: relativeElRect.right,\n bottom: relativeElRect.bottom,\n center: 0,\n centerv: relativeElRect.top + relativeElRect.height / 2,\n centerh: relativeElRect.left + relativeElRect.width / 2,\n left: relativeElRect.left,\n width: relativeElRect.width,\n height: relativeElRect.height,\n x: relativeElRect.x,\n y: relativeElRect.y\n };\n\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"horizontal\");\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"vertical\");\n\n if (!initialCalculationDone) {\n setInitialCalculationDone(true);\n }\n }, configObject.debounceAmount ?? 20);\n\n return {\n top: position.top,\n bottom: position.bottom,\n left: position.left,\n right: position.right,\n calculatePosition,\n initialCalculationDone\n };\n};\n"],"names":["horizontal","vertical","defaultConfigObject","relativeElement","elementToBePositioned","transformOrigin","placement","offset","top","right","bottom","left","debounceAmount","providedConfigObject","configObject","initialCalculationDone","setInitialCalculationDone","useState","position","setPosition","_calculatePlacement","relEl","elDimensions","axis","placementValue","requestedReturnValue","placementOriginDefinition","Error","_determineCenteredPlacementOrigin","value","window","_calculateInitialPlacementValue","valueWithOffset","returnValue","_a","_b","_c","_d","_e","_f","_g","_h","_i","_j","_k","_l","_applyOffsetToPlacementValue","innerWidth","width","innerHeight","height","_fixPossibleViewportOverflow","_calculatePlacementValue","direction","oppositeDirection","prevState","calculatePosition","useDebouncedCallback","current","relativeElRect","getBoundingClientRect","elementToBePositionedDimensions","offsetHeight","offsetWidth","clonedRelEl","center","centerv","centerh","x","y"],"mappings":"oJA4BO,IAAKA,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,SAAW,UACXA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA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,IAAA,IACPA,EACHF,CAACA,GAAY7B,EACb8B,CAACA,GAAoB,cAInBE,EAAoBC,EAAAA,qBAAqB,aAC7C,KAAK,OAAAvB,IAAa/B,sBAAb,EAAA+B,EAA8BwB,YAAY,OAAAvB,EAAArB,EAAaV,4BAAb,EAAA+B,EAAoCuB,SACjF,OAEF,MAAMC,EAAkB7C,EAAaX,gBAClCuD,QAAyBE,wBACtBC,EAA8C,CAClDX,OAASpC,EAAaV,sBAAuBsD,QAAwBI,aACrEd,MAAQlC,EAAaV,sBAAuBsD,QAAwBK,aAIhEC,EAAc,CAClBxD,IAAKmD,EAAenD,IACpBC,MAAOkD,EAAelD,MACtBC,OAAQiD,EAAejD,OACvBuD,OAAQ,EACRC,QAASP,EAAenD,IAAMmD,EAAeT,OAAS,EACtDiB,QAASR,EAAehD,KAAOgD,EAAeX,MAAQ,EACtDrC,KAAMgD,EAAehD,KACrBqC,MAAOW,EAAeX,MACtBE,OAAQS,EAAeT,OACvBkB,EAAGT,EAAeS,EAClBC,EAAGV,EAAeU,GAGpBjD,EAAoB4C,EAAaH,EAAiC,cAClEzC,EAAoB4C,EAAaH,EAAiC,YAE7D9C,GACHC,GAA0B,IAE3BF,EAAaF,gBAAkB,IAElC,MAAO,CACLJ,IAAKU,EAASV,IACdE,OAAQQ,EAASR,OACjBC,KAAMO,EAASP,KACfF,MAAOS,EAAST,MAChB+C,oBACAzC"}
|
|
1
|
+
{"version":3,"file":"usePosition.cjs.js","sources":["../../src/hooks/usePosition.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useState, useEffect, useRef } from \"react\";\nimport { useDebouncedCallback } from \"./useDebouncedCallback\";\n\nexport interface ConfigObject {\n relativeElement: RefElement;\n elementToBePositioned: RefElement;\n transformOrigin?: Placement;\n placement?: Placement;\n offset?: Offset;\n debounceAmount?: number;\n}\n\nexport enum horizontal {\n LEFT = \"left\",\n CENTER = \"center\",\n CENTER_H = \"centerh\",\n RIGHT = \"right\"\n}\n\nexport enum vertical {\n TOP = \"top\",\n CENTER = \"center\",\n CENTER_V = \"centerv\",\n BOTTOM = \"bottom\"\n}\n\nexport type HorizontalPlacement = `${horizontal}`;\nexport type VerticalPlacement = `${vertical}`;\n\ntype Axis = \"vertical\" | \"horizontal\";\ntype RefElement = React.RefObject<HTMLOrSVGElement | null> | undefined;\n\ninterface DomRectObject {\n top: number;\n right: number;\n bottom: number;\n left: number;\n center: number;\n centerh: number;\n centerv: number;\n width: number;\n height: number;\n x: number;\n y: number;\n}\n\nexport interface Placement {\n horizontal: HorizontalPlacement;\n vertical: VerticalPlacement;\n}\n\nexport interface Offset {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport interface Position {\n top: PositionType;\n right: PositionType;\n bottom: PositionType;\n left: PositionType;\n}\n\ninterface Dimensions {\n height: number;\n width: number;\n}\n\nexport type PositionType = number | \"initial\";\n\nconst defaultConfigObject: ConfigObject = {\n relativeElement: undefined,\n elementToBePositioned: undefined,\n transformOrigin: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n placement: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n offset: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n debounceAmount: 20\n};\n\nexport const usePosition = (providedConfigObject: ConfigObject = defaultConfigObject) => {\n const configObject = { ...defaultConfigObject, ...providedConfigObject };\n const [initialCalculationDone, setInitialCalculationDone] = useState(false);\n\n if (configObject.transformOrigin === undefined) {\n configObject.transformOrigin = defaultConfigObject.transformOrigin;\n }\n\n if (configObject.placement === undefined) {\n configObject.placement = defaultConfigObject.placement;\n }\n\n if (configObject.offset === undefined) {\n configObject.offset = defaultConfigObject.offset;\n }\n\n const [position, setPosition] = useState<Position>({\n left: 0,\n top: 0,\n right: \"initial\",\n bottom: \"initial\"\n });\n\n const resetCalculationState = () => {\n setInitialCalculationDone(false);\n };\n\n const _fixPossibleViewportOverflow = (\n value: number,\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n elDimensions: Dimensions\n ) => {\n let returnValue = value;\n\n if (returnValue < 0) {\n returnValue = 0;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" &&\n returnValue > window.innerWidth - elDimensions.width) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"horizontal\" &&\n returnValue > window.innerWidth - elDimensions.width)\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"top\" &&\n returnValue > window.innerHeight - elDimensions.height) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"vertical\" &&\n returnValue > window.innerHeight - elDimensions.height)\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"right\" &&\n returnValue > window.innerWidth - elDimensions.width\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"bottom\" &&\n returnValue > window.innerHeight - elDimensions.height\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n return returnValue;\n };\n\n const _applyOffsetToPlacementValue = (\n value: number,\n requestedReturnValue: Axis,\n transformOrigin: Placement\n ) => {\n let returnValue = value;\n if (\n (requestedReturnValue === \"horizontal\" && configObject.offset?.left !== 0) ||\n (requestedReturnValue === \"horizontal\" && configObject.offset?.right !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.left!;\n returnValue -= configObject.offset?.right!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"right\") {\n returnValue -= configObject.offset?.left!;\n returnValue += configObject.offset?.right!;\n }\n }\n\n if (\n (requestedReturnValue === \"vertical\" && configObject.offset?.top !== 0) ||\n (requestedReturnValue === \"vertical\" && configObject.offset?.bottom !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"top\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.top!;\n returnValue -= configObject.offset?.bottom!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"bottom\") {\n returnValue -= configObject.offset?.top!;\n returnValue += configObject.offset?.bottom!;\n }\n }\n\n return returnValue;\n };\n\n const _calculateInitialPlacementValue = (\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n placementOriginDefinition: HorizontalPlacement | VerticalPlacement,\n elDimensions: Dimensions\n ) => {\n let value = 0;\n\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"top\"\n ) {\n value = relEl[placementOriginDefinition];\n } else if (transformOrigin[requestedReturnValue] === \"center\") {\n value =\n relEl[placementOriginDefinition] -\n elDimensions[requestedReturnValue === \"horizontal\" ? \"width\" : \"height\"] / 2;\n } else if (\n transformOrigin[requestedReturnValue] === \"right\" ||\n transformOrigin[requestedReturnValue] === \"bottom\"\n ) {\n value =\n window[requestedReturnValue === \"horizontal\" ? \"innerWidth\" : \"innerHeight\"] -\n relEl[placementOriginDefinition];\n }\n\n return value;\n };\n\n /**\n *\n * @param requestedReturnValue whether the requested return value is for the horizontal or vertical axis\n * @returns either the horizontally centered placement definition (centerh) or the vertically centered one (centerv)\n */\n const _determineCenteredPlacementOrigin = (requestedReturnValue: Axis) => {\n if (requestedReturnValue === \"horizontal\") {\n return \"centerh\";\n } else if (requestedReturnValue === \"vertical\") {\n return \"centerv\";\n }\n throw new Error(\n `the requested return value isn't \"vertical\" or \"horizontal\" ${requestedReturnValue} was given.`\n );\n };\n\n const _calculatePlacementValue = (\n transformOrigin: Placement,\n placement: HorizontalPlacement | VerticalPlacement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n elDimensions: Dimensions\n ): number => {\n const placementOriginDefinition =\n placement === \"center\" ? _determineCenteredPlacementOrigin(requestedReturnValue) : placement;\n\n const value = _calculateInitialPlacementValue(\n transformOrigin,\n requestedReturnValue,\n relEl,\n placementOriginDefinition,\n elDimensions\n );\n\n const valueWithOffset = _applyOffsetToPlacementValue(\n value,\n requestedReturnValue,\n transformOrigin\n );\n\n return _fixPossibleViewportOverflow(\n valueWithOffset,\n transformOrigin,\n requestedReturnValue,\n elDimensions\n );\n };\n\n const _calculatePlacement = (relEl: DomRectObject, elDimensions: Dimensions, axis: Axis) => {\n const placementValue = _calculatePlacementValue(\n configObject.transformOrigin!,\n configObject.placement![axis]!,\n axis,\n relEl,\n elDimensions\n );\n\n let direction = \"left\";\n let oppositeDirection = \"right\";\n\n if (axis === \"horizontal\" && configObject.transformOrigin?.horizontal === \"right\") {\n direction = \"right\";\n oppositeDirection = \"left\";\n } else if (axis === \"horizontal\") {\n direction = \"left\";\n oppositeDirection = \"right\";\n }\n\n if (axis === \"vertical\" && configObject.transformOrigin?.vertical === \"bottom\") {\n direction = \"bottom\";\n oppositeDirection = \"top\";\n } else if (axis === \"vertical\") {\n direction = \"top\";\n oppositeDirection = \"bottom\";\n }\n\n setPosition(prevState => ({\n ...prevState,\n [direction]: placementValue,\n [oppositeDirection]: \"initial\"\n }));\n };\n\n const _performCalculation = () => {\n if (!configObject.relativeElement?.current || !configObject.elementToBePositioned?.current) {\n return;\n }\n const relativeElRect = (configObject.relativeElement!\n .current as HTMLElement)!.getBoundingClientRect();\n const elementToBePositionedDimensions: Dimensions = {\n height: (configObject.elementToBePositioned!.current as HTMLElement).offsetHeight,\n width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth\n };\n\n /** We want to add a center (horizontal and vertical) property to the DOMRect object. Since it's a special object we can't modify so we clone it and add it. */\n const clonedRelEl = {\n top: relativeElRect.top,\n right: relativeElRect.right,\n bottom: relativeElRect.bottom,\n center: 0,\n centerv: relativeElRect.top + relativeElRect.height / 2,\n centerh: relativeElRect.left + relativeElRect.width / 2,\n left: relativeElRect.left,\n width: relativeElRect.width,\n height: relativeElRect.height,\n x: relativeElRect.x,\n y: relativeElRect.y\n };\n\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"horizontal\");\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"vertical\");\n\n if (!initialCalculationDone) {\n setInitialCalculationDone(true);\n }\n };\n\n const performCalculationRef = useRef(_performCalculation);\n performCalculationRef.current = _performCalculation;\n\n const calculatePosition = useDebouncedCallback(() => {\n performCalculationRef.current();\n }, configObject.debounceAmount ?? 20);\n\n const calculatePositionImmediate = () => {\n performCalculationRef.current();\n };\n\n const _getScrollableAncestors = (element: HTMLElement): HTMLElement[] => {\n const ancestors: HTMLElement[] = [];\n let parent = element.parentElement;\n while (parent && parent !== document.documentElement) {\n const style = window.getComputedStyle(parent);\n const overflowX = style.overflowX;\n const overflowY = style.overflowY;\n if (\n overflowX === \"auto\" ||\n overflowX === \"scroll\" ||\n overflowY === \"auto\" ||\n overflowY === \"scroll\"\n ) {\n ancestors.push(parent);\n }\n parent = parent.parentElement;\n }\n return ancestors;\n };\n\n useEffect(() => {\n if (!initialCalculationDone) {\n return;\n }\n\n let rafId: number | null = null;\n\n const handleResize = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(() => {\n rafId = null;\n performCalculationRef.current();\n });\n };\n\n window.addEventListener(\"resize\", handleResize);\n window.addEventListener(\"scroll\", handleResize, true);\n\n if (window.visualViewport) {\n window.visualViewport.addEventListener(\"resize\", handleResize);\n window.visualViewport.addEventListener(\"scroll\", handleResize);\n }\n\n const scrollableAncestors: HTMLElement[] = [];\n if (configObject.relativeElement?.current) {\n const relEl = configObject.relativeElement.current as HTMLElement;\n scrollableAncestors.push(..._getScrollableAncestors(relEl));\n for (const ancestor of scrollableAncestors) {\n ancestor.addEventListener(\"scroll\", handleResize);\n }\n }\n\n let resizeObserver: ResizeObserver | undefined;\n let lastObservedWidth = 0;\n let lastObservedHeight = 0;\n if (typeof ResizeObserver !== \"undefined\" && configObject.elementToBePositioned?.current) {\n const el = configObject.elementToBePositioned.current as HTMLElement;\n lastObservedWidth = el.offsetWidth;\n lastObservedHeight = el.offsetHeight;\n resizeObserver = new ResizeObserver(entries => {\n const entry = entries[0];\n if (!entry) {\n return;\n }\n const { width, height } = entry.contentRect;\n if (Math.abs(width - lastObservedWidth) > 1 || Math.abs(height - lastObservedHeight) > 1) {\n lastObservedWidth = width;\n lastObservedHeight = height;\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(() => {\n rafId = null;\n performCalculationRef.current();\n });\n }\n });\n resizeObserver.observe(el);\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n\n window.removeEventListener(\"resize\", handleResize);\n window.removeEventListener(\"scroll\", handleResize, true);\n\n if (window.visualViewport) {\n window.visualViewport.removeEventListener(\"resize\", handleResize);\n window.visualViewport.removeEventListener(\"scroll\", handleResize);\n }\n\n for (const ancestor of scrollableAncestors) {\n ancestor.removeEventListener(\"scroll\", handleResize);\n }\n\n if (resizeObserver) {\n resizeObserver.disconnect();\n }\n };\n }, [initialCalculationDone]);\n\n return {\n top: position.top,\n bottom: position.bottom,\n left: position.left,\n right: position.right,\n calculatePosition,\n calculatePositionImmediate,\n initialCalculationDone,\n resetCalculationState\n };\n};\n"],"names":["horizontal","vertical","defaultConfigObject","relativeElement","elementToBePositioned","transformOrigin","placement","offset","top","right","bottom","left","debounceAmount","providedConfigObject","configObject","initialCalculationDone","setInitialCalculationDone","useState","position","setPosition","_calculatePlacement","relEl","elDimensions","axis","placementValue","requestedReturnValue","placementOriginDefinition","Error","_determineCenteredPlacementOrigin","value","window","_calculateInitialPlacementValue","valueWithOffset","returnValue","_a","_b","_c","_d","_e","_f","_g","_h","_i","_j","_k","_l","_applyOffsetToPlacementValue","innerWidth","width","innerHeight","height","_fixPossibleViewportOverflow","_calculatePlacementValue","direction","oppositeDirection","prevState","_performCalculation","current","relativeElRect","getBoundingClientRect","elementToBePositionedDimensions","offsetHeight","offsetWidth","clonedRelEl","center","centerv","centerh","x","y","performCalculationRef","useRef","calculatePosition","useDebouncedCallback","useEffect","rafId","handleResize","cancelAnimationFrame","requestAnimationFrame","addEventListener","visualViewport","scrollableAncestors","push","element","ancestors","parent","parentElement","document","documentElement","style","getComputedStyle","overflowX","overflowY","_getScrollableAncestors","ancestor","resizeObserver","lastObservedWidth","lastObservedHeight","ResizeObserver","el","entries","entry","contentRect","Math","abs","observe","removeEventListener","disconnect","calculatePositionImmediate","resetCalculationState"],"mappings":"oJA4BO,IAAKA,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,SAAW,UACXA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA,GAOAC,GAAAA,IACVA,EAAA,IAAM,MACNA,EAAA,OAAS,SACTA,EAAA,SAAW,UACXA,EAAA,OAAS,SAJCA,IAAAA,GAAA,CAAA,GAqDZ,MAAMC,EAAoC,CACxCC,qBAAiB,EACjBC,2BAAuB,EACvBC,gBAAiB,CACfL,WAAY,OACZC,SAAU,OAEZK,UAAW,CACTN,WAAY,OACZC,SAAU,OAEZM,OAAQ,CACNC,IAAK,EACLC,MAAO,EACPC,OAAQ,EACRC,KAAM,GAERC,eAAgB,6CAGS,CAACC,EAAqCX,KAC/D,MAAMY,EAAe,IAAKZ,KAAwBW,IAC3CE,EAAwBC,GAA6BC,EAAAA,UAAS,QAEhC,IAAjCH,EAAaT,kBACfS,EAAaT,gBAAkBH,EAAoBG,sBAGtB,IAA3BS,EAAaR,YACfQ,EAAaR,UAAYJ,EAAoBI,gBAGnB,IAAxBQ,EAAaP,SACfO,EAAaP,OAASL,EAAoBK,QAG5C,MAAOW,EAAUC,GAAeF,WAAm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,OAEF,MAAMpD,MAAEA,EAAAE,OAAOA,GAAWkD,EAAMC,aAC5BC,KAAKC,IAAIvD,EAAQ+C,GAAqB,GAAKO,KAAKC,IAAIrD,EAAS8C,GAAsB,KACrFD,EAAoB/C,EACpBgD,EAAqB9C,EACP,OAAVwB,GACFE,qBAAqBF,GAEvBA,EAAQG,sBAAsB,KAC5BH,EAAQ,KACRL,EAAsBZ,eAI5BqC,EAAeU,QAAQN,EACzB,CAEA,MAAO,KACS,OAAVxB,GACFE,qBAAqBF,GAGvB5C,OAAO2E,oBAAoB,SAAU9B,GACrC7C,OAAO2E,oBAAoB,SAAU9B,GAAc,GAE/C7C,OAAOiD,iBACTjD,OAAOiD,eAAe0B,oBAAoB,SAAU9B,GACpD7C,OAAOiD,eAAe0B,oBAAoB,SAAU9B,IAGtD,IAAA,MAAWkB,KAAYb,EACrBa,EAASY,oBAAoB,SAAU9B,GAGrCmB,GACFA,EAAeY,eAGlB,CAAC3F,IAEG,CACLP,IAAKU,EAASV,IACdE,OAAQQ,EAASR,OACjBC,KAAMO,EAASP,KACfF,MAAOS,EAAST,MAChB8D,oBACAoC,2BAnHiC,KACjCtC,EAAsBZ,WAmHtB1C,yBACA6F,sBAjX4B,KAC5B5F,GAA0B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useState, useRef, useEffect } from "react";
|
|
2
2
|
import { useDebouncedCallback } from "./useDebouncedCallback.es.js";
|
|
3
3
|
var horizontal = /* @__PURE__ */ ((horizontal2) => {
|
|
4
4
|
horizontal2["LEFT"] = "left";
|
|
@@ -51,9 +51,12 @@ const usePosition = (providedConfigObject = defaultConfigObject) => {
|
|
|
51
51
|
right: "initial",
|
|
52
52
|
bottom: "initial"
|
|
53
53
|
});
|
|
54
|
+
const resetCalculationState = () => {
|
|
55
|
+
setInitialCalculationDone(false);
|
|
56
|
+
};
|
|
54
57
|
const _fixPossibleViewportOverflow = (value, transformOrigin, requestedReturnValue, elDimensions) => {
|
|
55
58
|
let returnValue = value;
|
|
56
|
-
if (
|
|
59
|
+
if (returnValue < 0) {
|
|
57
60
|
returnValue = 0;
|
|
58
61
|
}
|
|
59
62
|
if (transformOrigin[requestedReturnValue] === "left" && returnValue > window.innerWidth - elDimensions.width || transformOrigin[requestedReturnValue] === "center" && requestedReturnValue === "horizontal" && returnValue > window.innerWidth - elDimensions.width) {
|
|
@@ -168,7 +171,7 @@ const usePosition = (providedConfigObject = defaultConfigObject) => {
|
|
|
168
171
|
[oppositeDirection]: "initial"
|
|
169
172
|
}));
|
|
170
173
|
};
|
|
171
|
-
const
|
|
174
|
+
const _performCalculation = () => {
|
|
172
175
|
var _a, _b;
|
|
173
176
|
if (!((_a = configObject.relativeElement) == null ? void 0 : _a.current) || !((_b = configObject.elementToBePositioned) == null ? void 0 : _b.current)) {
|
|
174
177
|
return;
|
|
@@ -196,14 +199,112 @@ const usePosition = (providedConfigObject = defaultConfigObject) => {
|
|
|
196
199
|
if (!initialCalculationDone) {
|
|
197
200
|
setInitialCalculationDone(true);
|
|
198
201
|
}
|
|
202
|
+
};
|
|
203
|
+
const performCalculationRef = useRef(_performCalculation);
|
|
204
|
+
performCalculationRef.current = _performCalculation;
|
|
205
|
+
const calculatePosition = useDebouncedCallback(() => {
|
|
206
|
+
performCalculationRef.current();
|
|
199
207
|
}, configObject.debounceAmount ?? 20);
|
|
208
|
+
const calculatePositionImmediate = () => {
|
|
209
|
+
performCalculationRef.current();
|
|
210
|
+
};
|
|
211
|
+
const _getScrollableAncestors = (element) => {
|
|
212
|
+
const ancestors = [];
|
|
213
|
+
let parent = element.parentElement;
|
|
214
|
+
while (parent && parent !== document.documentElement) {
|
|
215
|
+
const style = window.getComputedStyle(parent);
|
|
216
|
+
const overflowX = style.overflowX;
|
|
217
|
+
const overflowY = style.overflowY;
|
|
218
|
+
if (overflowX === "auto" || overflowX === "scroll" || overflowY === "auto" || overflowY === "scroll") {
|
|
219
|
+
ancestors.push(parent);
|
|
220
|
+
}
|
|
221
|
+
parent = parent.parentElement;
|
|
222
|
+
}
|
|
223
|
+
return ancestors;
|
|
224
|
+
};
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
if (!initialCalculationDone) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
let rafId = null;
|
|
231
|
+
const handleResize = () => {
|
|
232
|
+
if (rafId !== null) {
|
|
233
|
+
cancelAnimationFrame(rafId);
|
|
234
|
+
}
|
|
235
|
+
rafId = requestAnimationFrame(() => {
|
|
236
|
+
rafId = null;
|
|
237
|
+
performCalculationRef.current();
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
window.addEventListener("resize", handleResize);
|
|
241
|
+
window.addEventListener("scroll", handleResize, true);
|
|
242
|
+
if (window.visualViewport) {
|
|
243
|
+
window.visualViewport.addEventListener("resize", handleResize);
|
|
244
|
+
window.visualViewport.addEventListener("scroll", handleResize);
|
|
245
|
+
}
|
|
246
|
+
const scrollableAncestors = [];
|
|
247
|
+
if ((_a = configObject.relativeElement) == null ? void 0 : _a.current) {
|
|
248
|
+
const relEl = configObject.relativeElement.current;
|
|
249
|
+
scrollableAncestors.push(..._getScrollableAncestors(relEl));
|
|
250
|
+
for (const ancestor of scrollableAncestors) {
|
|
251
|
+
ancestor.addEventListener("scroll", handleResize);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let resizeObserver;
|
|
255
|
+
let lastObservedWidth = 0;
|
|
256
|
+
let lastObservedHeight = 0;
|
|
257
|
+
if (typeof ResizeObserver !== "undefined" && ((_b = configObject.elementToBePositioned) == null ? void 0 : _b.current)) {
|
|
258
|
+
const el = configObject.elementToBePositioned.current;
|
|
259
|
+
lastObservedWidth = el.offsetWidth;
|
|
260
|
+
lastObservedHeight = el.offsetHeight;
|
|
261
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
262
|
+
const entry = entries[0];
|
|
263
|
+
if (!entry) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const { width, height } = entry.contentRect;
|
|
267
|
+
if (Math.abs(width - lastObservedWidth) > 1 || Math.abs(height - lastObservedHeight) > 1) {
|
|
268
|
+
lastObservedWidth = width;
|
|
269
|
+
lastObservedHeight = height;
|
|
270
|
+
if (rafId !== null) {
|
|
271
|
+
cancelAnimationFrame(rafId);
|
|
272
|
+
}
|
|
273
|
+
rafId = requestAnimationFrame(() => {
|
|
274
|
+
rafId = null;
|
|
275
|
+
performCalculationRef.current();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
resizeObserver.observe(el);
|
|
280
|
+
}
|
|
281
|
+
return () => {
|
|
282
|
+
if (rafId !== null) {
|
|
283
|
+
cancelAnimationFrame(rafId);
|
|
284
|
+
}
|
|
285
|
+
window.removeEventListener("resize", handleResize);
|
|
286
|
+
window.removeEventListener("scroll", handleResize, true);
|
|
287
|
+
if (window.visualViewport) {
|
|
288
|
+
window.visualViewport.removeEventListener("resize", handleResize);
|
|
289
|
+
window.visualViewport.removeEventListener("scroll", handleResize);
|
|
290
|
+
}
|
|
291
|
+
for (const ancestor of scrollableAncestors) {
|
|
292
|
+
ancestor.removeEventListener("scroll", handleResize);
|
|
293
|
+
}
|
|
294
|
+
if (resizeObserver) {
|
|
295
|
+
resizeObserver.disconnect();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}, [initialCalculationDone]);
|
|
200
299
|
return {
|
|
201
300
|
top: position.top,
|
|
202
301
|
bottom: position.bottom,
|
|
203
302
|
left: position.left,
|
|
204
303
|
right: position.right,
|
|
205
304
|
calculatePosition,
|
|
206
|
-
|
|
305
|
+
calculatePositionImmediate,
|
|
306
|
+
initialCalculationDone,
|
|
307
|
+
resetCalculationState
|
|
207
308
|
};
|
|
208
309
|
};
|
|
209
310
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePosition.es.js","sources":["../../src/hooks/usePosition.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useState } from \"react\";\nimport { useDebouncedCallback } from \"./useDebouncedCallback\";\n\nexport interface ConfigObject {\n relativeElement: RefElement;\n elementToBePositioned: RefElement;\n transformOrigin?: Placement;\n placement?: Placement;\n offset?: Offset;\n debounceAmount?: number;\n}\n\nexport enum horizontal {\n LEFT = \"left\",\n CENTER = \"center\",\n CENTER_H = \"centerh\",\n RIGHT = \"right\"\n}\n\nexport enum vertical {\n TOP = \"top\",\n CENTER = \"center\",\n CENTER_V = \"centerv\",\n BOTTOM = \"bottom\"\n}\n\nexport type HorizontalPlacement = `${horizontal}`;\nexport type VerticalPlacement = `${vertical}`;\n\ntype Axis = \"vertical\" | \"horizontal\";\ntype RefElement = React.RefObject<HTMLOrSVGElement> | undefined;\n\ninterface DomRectObject {\n top: number;\n right: number;\n bottom: number;\n left: number;\n center: number;\n centerh: number;\n centerv: number;\n width: number;\n height: number;\n x: number;\n y: number;\n}\n\nexport interface Placement {\n horizontal: HorizontalPlacement;\n vertical: VerticalPlacement;\n}\n\nexport interface Offset {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport interface Position {\n top: PositionType;\n right: PositionType;\n bottom: PositionType;\n left: PositionType;\n}\n\ninterface Dimensions {\n height: number;\n width: number;\n}\n\nexport type PositionType = number | \"initial\";\n\nconst defaultConfigObject: ConfigObject = {\n relativeElement: undefined,\n elementToBePositioned: undefined,\n transformOrigin: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n placement: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n offset: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n debounceAmount: 20\n};\n\nexport const usePosition = (providedConfigObject: ConfigObject = defaultConfigObject) => {\n const configObject = { ...defaultConfigObject, ...providedConfigObject };\n const [initialCalculationDone, setInitialCalculationDone] = useState(false);\n\n if (configObject.transformOrigin === undefined) {\n configObject.transformOrigin = defaultConfigObject.transformOrigin;\n }\n\n if (configObject.placement === undefined) {\n configObject.placement = defaultConfigObject.placement;\n }\n\n if (configObject.offset === undefined) {\n configObject.offset = defaultConfigObject.offset;\n }\n\n const [position, setPosition] = useState<Position>({\n left: 0,\n top: 0,\n right: \"initial\",\n bottom: \"initial\"\n });\n\n const _fixPossibleViewportOverflow = (\n value: number,\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n elDimensions: Dimensions\n ) => {\n let returnValue = value;\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"top\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"center\" && returnValue < 0) ||\n (transformOrigin[requestedReturnValue] === \"bottom\" && returnValue < 0)\n ) {\n returnValue = 0;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" &&\n returnValue > window.innerWidth - elDimensions.width) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"horizontal\" &&\n returnValue > window.innerWidth - elDimensions.width)\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"top\" &&\n returnValue > window.innerHeight - elDimensions.height) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"vertical\" &&\n returnValue > window.innerHeight - elDimensions.height)\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"right\" &&\n returnValue > window.innerWidth - elDimensions.width\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"bottom\" &&\n returnValue > window.innerHeight - elDimensions.height\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n return returnValue;\n };\n\n const _applyOffsetToPlacementValue = (\n value: number,\n requestedReturnValue: Axis,\n transformOrigin: Placement\n ) => {\n let returnValue = value;\n if (\n (requestedReturnValue === \"horizontal\" && configObject.offset?.left !== 0) ||\n (requestedReturnValue === \"horizontal\" && configObject.offset?.right !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.left!;\n returnValue -= configObject.offset?.right!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"right\") {\n returnValue -= configObject.offset?.left!;\n returnValue += configObject.offset?.right!;\n }\n }\n\n if (\n (requestedReturnValue === \"vertical\" && configObject.offset?.top !== 0) ||\n (requestedReturnValue === \"vertical\" && configObject.offset?.bottom !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"top\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.top!;\n returnValue -= configObject.offset?.bottom!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"bottom\") {\n returnValue -= configObject.offset?.top!;\n returnValue += configObject.offset?.bottom!;\n }\n }\n\n return returnValue;\n };\n\n const _calculateInitialPlacementValue = (\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n placementOriginDefinition: HorizontalPlacement | VerticalPlacement,\n elDimensions: Dimensions\n ) => {\n let value = 0;\n\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"top\"\n ) {\n value = relEl[placementOriginDefinition];\n } else if (transformOrigin[requestedReturnValue] === \"center\") {\n value =\n relEl[placementOriginDefinition] -\n elDimensions[requestedReturnValue === \"horizontal\" ? \"width\" : \"height\"] / 2;\n } else if (\n transformOrigin[requestedReturnValue] === \"right\" ||\n transformOrigin[requestedReturnValue] === \"bottom\"\n ) {\n value =\n window[requestedReturnValue === \"horizontal\" ? \"innerWidth\" : \"innerHeight\"] -\n relEl[placementOriginDefinition];\n }\n\n return value;\n };\n\n /**\n *\n * @param requestedReturnValue whether the requested return value is for the horizontal or vertical axis\n * @returns either the horizontally centered placement definition (centerh) or the vertically centered one (centerv)\n */\n const _determineCenteredPlacementOrigin = (requestedReturnValue: Axis) => {\n if (requestedReturnValue === \"horizontal\") {\n return \"centerh\";\n } else if (requestedReturnValue === \"vertical\") {\n return \"centerv\";\n }\n throw new Error(\n `the requested return value isn't \"vertical\" or \"horizontal\" ${requestedReturnValue} was given.`\n );\n };\n\n const _calculatePlacementValue = (\n transformOrigin: Placement,\n placement: HorizontalPlacement | VerticalPlacement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n elDimensions: Dimensions\n ): number => {\n const placementOriginDefinition =\n placement === \"center\" ? _determineCenteredPlacementOrigin(requestedReturnValue) : placement;\n\n const value = _calculateInitialPlacementValue(\n transformOrigin,\n requestedReturnValue,\n relEl,\n placementOriginDefinition,\n elDimensions\n );\n\n const valueWithOffset = _applyOffsetToPlacementValue(\n value,\n requestedReturnValue,\n transformOrigin\n );\n\n return _fixPossibleViewportOverflow(\n valueWithOffset,\n transformOrigin,\n requestedReturnValue,\n elDimensions\n );\n };\n\n const _calculatePlacement = (relEl: DomRectObject, elDimensions: Dimensions, axis: Axis) => {\n const placementValue = _calculatePlacementValue(\n configObject.transformOrigin!,\n configObject.placement![axis]!,\n axis,\n relEl,\n elDimensions\n );\n\n let direction = \"left\";\n let oppositeDirection = \"right\";\n\n if (axis === \"horizontal\" && configObject.transformOrigin?.horizontal === \"right\") {\n direction = \"right\";\n oppositeDirection = \"left\";\n } else if (axis === \"horizontal\") {\n direction = \"left\";\n oppositeDirection = \"right\";\n }\n\n if (axis === \"vertical\" && configObject.transformOrigin?.vertical === \"bottom\") {\n direction = \"bottom\";\n oppositeDirection = \"top\";\n } else if (axis === \"vertical\") {\n direction = \"top\";\n oppositeDirection = \"bottom\";\n }\n\n setPosition(prevState => ({\n ...prevState,\n [direction]: placementValue,\n [oppositeDirection]: \"initial\"\n }));\n };\n\n const calculatePosition = useDebouncedCallback(() => {\n if (!configObject.relativeElement?.current || !configObject.elementToBePositioned?.current) {\n return;\n }\n const relativeElRect = (configObject.relativeElement!\n .current as HTMLElement)!.getBoundingClientRect();\n const elementToBePositionedDimensions: Dimensions = {\n height: (configObject.elementToBePositioned!.current as HTMLElement).offsetHeight,\n width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth\n };\n\n /** We want to add a center (horizontal and vertical) property to the DOMRect object. Since it's a special object we can't modify so we clone it and add it. */\n const clonedRelEl = {\n top: relativeElRect.top,\n right: relativeElRect.right,\n bottom: relativeElRect.bottom,\n center: 0,\n centerv: relativeElRect.top + relativeElRect.height / 2,\n centerh: relativeElRect.left + relativeElRect.width / 2,\n left: relativeElRect.left,\n width: relativeElRect.width,\n height: relativeElRect.height,\n x: relativeElRect.x,\n y: relativeElRect.y\n };\n\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"horizontal\");\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"vertical\");\n\n if (!initialCalculationDone) {\n setInitialCalculationDone(true);\n }\n }, configObject.debounceAmount ?? 20);\n\n return {\n top: position.top,\n bottom: position.bottom,\n left: position.left,\n right: position.right,\n calculatePosition,\n initialCalculationDone\n };\n};\n"],"names":["horizontal","vertical"],"mappings":";;AA4BO,IAAK,+BAAAA,gBAAL;AACLA,cAAA,MAAA,IAAO;AACPA,cAAA,QAAA,IAAS;AACTA,cAAA,UAAA,IAAW;AACXA,cAAA,OAAA,IAAQ;AAJE,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,IAAK,6BAAAC,cAAL;AACLA,YAAA,KAAA,IAAM;AACNA,YAAA,QAAA,IAAS;AACTA,YAAA,UAAA,IAAW;AACXA,YAAA,QAAA,IAAS;AAJC,SAAAA;AAAA,GAAA,YAAA,CAAA,CAAA;AAqDZ,MAAM,sBAA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,QAAI,CAAC,wBAAwB;AAC3B,gCAA0B,IAAI;AAAA,IAChC;AAAA,EACF,GAAG,aAAa,kBAAkB,EAAE;AAEpC,SAAO;AAAA,IACL,KAAK,SAAS;AAAA,IACd,QAAQ,SAAS;AAAA,IACjB,MAAM,SAAS;AAAA,IACf,OAAO,SAAS;AAAA,IAChB;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"usePosition.es.js","sources":["../../src/hooks/usePosition.ts"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useState, useEffect, useRef } from \"react\";\nimport { useDebouncedCallback } from \"./useDebouncedCallback\";\n\nexport interface ConfigObject {\n relativeElement: RefElement;\n elementToBePositioned: RefElement;\n transformOrigin?: Placement;\n placement?: Placement;\n offset?: Offset;\n debounceAmount?: number;\n}\n\nexport enum horizontal {\n LEFT = \"left\",\n CENTER = \"center\",\n CENTER_H = \"centerh\",\n RIGHT = \"right\"\n}\n\nexport enum vertical {\n TOP = \"top\",\n CENTER = \"center\",\n CENTER_V = \"centerv\",\n BOTTOM = \"bottom\"\n}\n\nexport type HorizontalPlacement = `${horizontal}`;\nexport type VerticalPlacement = `${vertical}`;\n\ntype Axis = \"vertical\" | \"horizontal\";\ntype RefElement = React.RefObject<HTMLOrSVGElement | null> | undefined;\n\ninterface DomRectObject {\n top: number;\n right: number;\n bottom: number;\n left: number;\n center: number;\n centerh: number;\n centerv: number;\n width: number;\n height: number;\n x: number;\n y: number;\n}\n\nexport interface Placement {\n horizontal: HorizontalPlacement;\n vertical: VerticalPlacement;\n}\n\nexport interface Offset {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport interface Position {\n top: PositionType;\n right: PositionType;\n bottom: PositionType;\n left: PositionType;\n}\n\ninterface Dimensions {\n height: number;\n width: number;\n}\n\nexport type PositionType = number | \"initial\";\n\nconst defaultConfigObject: ConfigObject = {\n relativeElement: undefined,\n elementToBePositioned: undefined,\n transformOrigin: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n placement: {\n horizontal: \"left\",\n vertical: \"top\"\n },\n offset: {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n },\n debounceAmount: 20\n};\n\nexport const usePosition = (providedConfigObject: ConfigObject = defaultConfigObject) => {\n const configObject = { ...defaultConfigObject, ...providedConfigObject };\n const [initialCalculationDone, setInitialCalculationDone] = useState(false);\n\n if (configObject.transformOrigin === undefined) {\n configObject.transformOrigin = defaultConfigObject.transformOrigin;\n }\n\n if (configObject.placement === undefined) {\n configObject.placement = defaultConfigObject.placement;\n }\n\n if (configObject.offset === undefined) {\n configObject.offset = defaultConfigObject.offset;\n }\n\n const [position, setPosition] = useState<Position>({\n left: 0,\n top: 0,\n right: \"initial\",\n bottom: \"initial\"\n });\n\n const resetCalculationState = () => {\n setInitialCalculationDone(false);\n };\n\n const _fixPossibleViewportOverflow = (\n value: number,\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n elDimensions: Dimensions\n ) => {\n let returnValue = value;\n\n if (returnValue < 0) {\n returnValue = 0;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"left\" &&\n returnValue > window.innerWidth - elDimensions.width) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"horizontal\" &&\n returnValue > window.innerWidth - elDimensions.width)\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n (transformOrigin[requestedReturnValue] === \"top\" &&\n returnValue > window.innerHeight - elDimensions.height) ||\n (transformOrigin[requestedReturnValue] === \"center\" &&\n requestedReturnValue === \"vertical\" &&\n returnValue > window.innerHeight - elDimensions.height)\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"right\" &&\n returnValue > window.innerWidth - elDimensions.width\n ) {\n returnValue = window.innerWidth - elDimensions.width;\n }\n\n if (\n transformOrigin[requestedReturnValue] === \"bottom\" &&\n returnValue > window.innerHeight - elDimensions.height\n ) {\n returnValue = window.innerHeight - elDimensions.height;\n }\n\n return returnValue;\n };\n\n const _applyOffsetToPlacementValue = (\n value: number,\n requestedReturnValue: Axis,\n transformOrigin: Placement\n ) => {\n let returnValue = value;\n if (\n (requestedReturnValue === \"horizontal\" && configObject.offset?.left !== 0) ||\n (requestedReturnValue === \"horizontal\" && configObject.offset?.right !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.left!;\n returnValue -= configObject.offset?.right!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"right\") {\n returnValue -= configObject.offset?.left!;\n returnValue += configObject.offset?.right!;\n }\n }\n\n if (\n (requestedReturnValue === \"vertical\" && configObject.offset?.top !== 0) ||\n (requestedReturnValue === \"vertical\" && configObject.offset?.bottom !== 0)\n ) {\n if (\n transformOrigin[requestedReturnValue] === \"top\" ||\n transformOrigin[requestedReturnValue] === \"center\"\n ) {\n returnValue += configObject.offset?.top!;\n returnValue -= configObject.offset?.bottom!;\n }\n\n if (transformOrigin[requestedReturnValue] === \"bottom\") {\n returnValue -= configObject.offset?.top!;\n returnValue += configObject.offset?.bottom!;\n }\n }\n\n return returnValue;\n };\n\n const _calculateInitialPlacementValue = (\n transformOrigin: Placement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n placementOriginDefinition: HorizontalPlacement | VerticalPlacement,\n elDimensions: Dimensions\n ) => {\n let value = 0;\n\n if (\n transformOrigin[requestedReturnValue] === \"left\" ||\n transformOrigin[requestedReturnValue] === \"top\"\n ) {\n value = relEl[placementOriginDefinition];\n } else if (transformOrigin[requestedReturnValue] === \"center\") {\n value =\n relEl[placementOriginDefinition] -\n elDimensions[requestedReturnValue === \"horizontal\" ? \"width\" : \"height\"] / 2;\n } else if (\n transformOrigin[requestedReturnValue] === \"right\" ||\n transformOrigin[requestedReturnValue] === \"bottom\"\n ) {\n value =\n window[requestedReturnValue === \"horizontal\" ? \"innerWidth\" : \"innerHeight\"] -\n relEl[placementOriginDefinition];\n }\n\n return value;\n };\n\n /**\n *\n * @param requestedReturnValue whether the requested return value is for the horizontal or vertical axis\n * @returns either the horizontally centered placement definition (centerh) or the vertically centered one (centerv)\n */\n const _determineCenteredPlacementOrigin = (requestedReturnValue: Axis) => {\n if (requestedReturnValue === \"horizontal\") {\n return \"centerh\";\n } else if (requestedReturnValue === \"vertical\") {\n return \"centerv\";\n }\n throw new Error(\n `the requested return value isn't \"vertical\" or \"horizontal\" ${requestedReturnValue} was given.`\n );\n };\n\n const _calculatePlacementValue = (\n transformOrigin: Placement,\n placement: HorizontalPlacement | VerticalPlacement,\n requestedReturnValue: Axis,\n relEl: DomRectObject,\n elDimensions: Dimensions\n ): number => {\n const placementOriginDefinition =\n placement === \"center\" ? _determineCenteredPlacementOrigin(requestedReturnValue) : placement;\n\n const value = _calculateInitialPlacementValue(\n transformOrigin,\n requestedReturnValue,\n relEl,\n placementOriginDefinition,\n elDimensions\n );\n\n const valueWithOffset = _applyOffsetToPlacementValue(\n value,\n requestedReturnValue,\n transformOrigin\n );\n\n return _fixPossibleViewportOverflow(\n valueWithOffset,\n transformOrigin,\n requestedReturnValue,\n elDimensions\n );\n };\n\n const _calculatePlacement = (relEl: DomRectObject, elDimensions: Dimensions, axis: Axis) => {\n const placementValue = _calculatePlacementValue(\n configObject.transformOrigin!,\n configObject.placement![axis]!,\n axis,\n relEl,\n elDimensions\n );\n\n let direction = \"left\";\n let oppositeDirection = \"right\";\n\n if (axis === \"horizontal\" && configObject.transformOrigin?.horizontal === \"right\") {\n direction = \"right\";\n oppositeDirection = \"left\";\n } else if (axis === \"horizontal\") {\n direction = \"left\";\n oppositeDirection = \"right\";\n }\n\n if (axis === \"vertical\" && configObject.transformOrigin?.vertical === \"bottom\") {\n direction = \"bottom\";\n oppositeDirection = \"top\";\n } else if (axis === \"vertical\") {\n direction = \"top\";\n oppositeDirection = \"bottom\";\n }\n\n setPosition(prevState => ({\n ...prevState,\n [direction]: placementValue,\n [oppositeDirection]: \"initial\"\n }));\n };\n\n const _performCalculation = () => {\n if (!configObject.relativeElement?.current || !configObject.elementToBePositioned?.current) {\n return;\n }\n const relativeElRect = (configObject.relativeElement!\n .current as HTMLElement)!.getBoundingClientRect();\n const elementToBePositionedDimensions: Dimensions = {\n height: (configObject.elementToBePositioned!.current as HTMLElement).offsetHeight,\n width: (configObject.elementToBePositioned!.current as HTMLElement).offsetWidth\n };\n\n /** We want to add a center (horizontal and vertical) property to the DOMRect object. Since it's a special object we can't modify so we clone it and add it. */\n const clonedRelEl = {\n top: relativeElRect.top,\n right: relativeElRect.right,\n bottom: relativeElRect.bottom,\n center: 0,\n centerv: relativeElRect.top + relativeElRect.height / 2,\n centerh: relativeElRect.left + relativeElRect.width / 2,\n left: relativeElRect.left,\n width: relativeElRect.width,\n height: relativeElRect.height,\n x: relativeElRect.x,\n y: relativeElRect.y\n };\n\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"horizontal\");\n _calculatePlacement(clonedRelEl, elementToBePositionedDimensions, \"vertical\");\n\n if (!initialCalculationDone) {\n setInitialCalculationDone(true);\n }\n };\n\n const performCalculationRef = useRef(_performCalculation);\n performCalculationRef.current = _performCalculation;\n\n const calculatePosition = useDebouncedCallback(() => {\n performCalculationRef.current();\n }, configObject.debounceAmount ?? 20);\n\n const calculatePositionImmediate = () => {\n performCalculationRef.current();\n };\n\n const _getScrollableAncestors = (element: HTMLElement): HTMLElement[] => {\n const ancestors: HTMLElement[] = [];\n let parent = element.parentElement;\n while (parent && parent !== document.documentElement) {\n const style = window.getComputedStyle(parent);\n const overflowX = style.overflowX;\n const overflowY = style.overflowY;\n if (\n overflowX === \"auto\" ||\n overflowX === \"scroll\" ||\n overflowY === \"auto\" ||\n overflowY === \"scroll\"\n ) {\n ancestors.push(parent);\n }\n parent = parent.parentElement;\n }\n return ancestors;\n };\n\n useEffect(() => {\n if (!initialCalculationDone) {\n return;\n }\n\n let rafId: number | null = null;\n\n const handleResize = () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(() => {\n rafId = null;\n performCalculationRef.current();\n });\n };\n\n window.addEventListener(\"resize\", handleResize);\n window.addEventListener(\"scroll\", handleResize, true);\n\n if (window.visualViewport) {\n window.visualViewport.addEventListener(\"resize\", handleResize);\n window.visualViewport.addEventListener(\"scroll\", handleResize);\n }\n\n const scrollableAncestors: HTMLElement[] = [];\n if (configObject.relativeElement?.current) {\n const relEl = configObject.relativeElement.current as HTMLElement;\n scrollableAncestors.push(..._getScrollableAncestors(relEl));\n for (const ancestor of scrollableAncestors) {\n ancestor.addEventListener(\"scroll\", handleResize);\n }\n }\n\n let resizeObserver: ResizeObserver | undefined;\n let lastObservedWidth = 0;\n let lastObservedHeight = 0;\n if (typeof ResizeObserver !== \"undefined\" && configObject.elementToBePositioned?.current) {\n const el = configObject.elementToBePositioned.current as HTMLElement;\n lastObservedWidth = el.offsetWidth;\n lastObservedHeight = el.offsetHeight;\n resizeObserver = new ResizeObserver(entries => {\n const entry = entries[0];\n if (!entry) {\n return;\n }\n const { width, height } = entry.contentRect;\n if (Math.abs(width - lastObservedWidth) > 1 || Math.abs(height - lastObservedHeight) > 1) {\n lastObservedWidth = width;\n lastObservedHeight = height;\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n rafId = requestAnimationFrame(() => {\n rafId = null;\n performCalculationRef.current();\n });\n }\n });\n resizeObserver.observe(el);\n }\n\n return () => {\n if (rafId !== null) {\n cancelAnimationFrame(rafId);\n }\n\n window.removeEventListener(\"resize\", handleResize);\n window.removeEventListener(\"scroll\", handleResize, true);\n\n if (window.visualViewport) {\n window.visualViewport.removeEventListener(\"resize\", handleResize);\n window.visualViewport.removeEventListener(\"scroll\", handleResize);\n }\n\n for (const ancestor of scrollableAncestors) {\n ancestor.removeEventListener(\"scroll\", handleResize);\n }\n\n if (resizeObserver) {\n resizeObserver.disconnect();\n }\n };\n }, [initialCalculationDone]);\n\n return {\n top: position.top,\n bottom: position.bottom,\n left: position.left,\n right: position.right,\n calculatePosition,\n calculatePositionImmediate,\n initialCalculationDone,\n resetCalculationState\n };\n};\n"],"names":["horizontal","vertical"],"mappings":";;AA4BO,IAAK,+BAAAA,gBAAL;AACLA,cAAA,MAAA,IAAO;AACPA,cAAA,QAAA,IAAS;AACTA,cAAA,UAAA,IAAW;AACXA,cAAA,OAAA,IAAQ;AAJE,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,IAAK,6BAAAC,cAAL;AACLA,YAAA,KAAA,IAAM;AACNA,YAAA,QAAA,IAAS;AACTA,YAAA,UAAA,IAAW;AACXA,YAAA,QAAA,IAAS;AAJC,SAAAA;AAAA,GAAA,YAAA,CAAA,CAAA;AAqDZ,MAAM,sBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,uBAAuB;AAAA,EACvB,iBAAiB;AAAA,IACf,YAAY;AAAA,IACZ,UAAU;AAAA,EAAA;AAAA,EAEZ,WAAW;AAAA,IACT,YAAY;AAAA,IACZ,UAAU;AAAA,EAAA;AAAA,EAEZ,QAAQ;AAAA,IACN,KAAK;AAAA,IACL,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,MAAM;AAAA,EAAA;AAAA,EAER,gBAAgB;AAClB;AAEO,MAAM,cAAc,CAAC,uBAAqC,wBAAwB;AACvF,QAAM,eAAe,EAAE,GAAG,qBAAqB,GAAG,qBAAA;AAClD,QAAM,CAAC,wBAAwB,yBAAyB,IAAI,SAAS,KAAK;AAE1E,MAAI,aAAa,oBAAoB,QAAW;AAC9C,iBAAa,kBAAkB,o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AAQ,sBAAsB,MAAM;AAClC,oBAAQ;AACR,kCAAsB,QAAA;AAAA,UACxB,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AACD,qBAAe,QAAQ,EAAE;AAAA,IAC3B;AAEA,WAAO,MAAM;AACX,UAAI,UAAU,MAAM;AAClB,6BAAqB,KAAK;AAAA,MAC5B;AAEA,aAAO,oBAAoB,UAAU,YAAY;AACjD,aAAO,oBAAoB,UAAU,cAAc,IAAI;AAEvD,UAAI,OAAO,gBAAgB;AACzB,eAAO,eAAe,oBAAoB,UAAU,YAAY;AAChE,eAAO,eAAe,oBAAoB,UAAU,YAAY;AAAA,MAClE;AAEA,iBAAW,YAAY,qBAAqB;AAC1C,iBAAS,oBAAoB,UAAU,YAAY;AAAA,MACrD;AAEA,UAAI,gBAAgB;AAClB,uBAAe,WAAA;AAAA,MACjB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,sBAAsB,CAAC;AAE3B,SAAO;AAAA,IACL,KAAK,SAAS;AAAA,IACd,QAAQ,SAAS;AAAA,IACjB,MAAM,SAAS;AAAA,IACf,OAAO,SAAS;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRepeatFocus.cjs.js","sources":["../../src/hooks/useRepeatFocus.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RefObject, useEffect } from \"react\";\nimport { getTabbableElements } from \"../utils/focusManagement\";\n\n/**\n * @description This is a hook that will make sure that when a modal is open and the user tabs through the it,\n * the focus will be repeated and the user will not lose their entire focusable element to an element in the background\n * that is being blocked by the modal.\n */\n\nexport const useRepeatFocus = (ref: RefObject<HTMLDivElement>, open?: boolean) => {\n useEffect(() => {\n if (!ref.current || !open) {\n return;\n }\n\n const tabbableElements = getTabbableElements(ref.current);\n const firstFocusableElement = tabbableElements[0];\n const lastFocusableElement = tabbableElements[tabbableElements.length - 1];\n\n if (!lastFocusableElement || !firstFocusableElement) {\n return;\n }\n\n const handleTabKeyPress = (event: Event) => {\n if (!(event instanceof KeyboardEvent) || event.key !== \"Tab\") {\n return;\n }\n\n if (event.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n event.preventDefault();\n lastFocusableElement?.focus();\n }\n } else if (document.activeElement === lastFocusableElement) {\n event.preventDefault();\n firstFocusableElement?.focus();\n }\n };\n\n lastFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n\n return () => {\n lastFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n };\n }, [ref, open]);\n};\n"],"names":["ref","open","useEffect","current","tabbableElements","getTabbableElements","firstFocusableElement","lastFocusableElement","length","handleTabKeyPress","event","KeyboardEvent","key","shiftKey","document","activeElement","preventDefault","focus","addEventListener","removeEventListener"],"mappings":"6KAyB8B,CAACA,
|
|
1
|
+
{"version":3,"file":"useRepeatFocus.cjs.js","sources":["../../src/hooks/useRepeatFocus.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RefObject, useEffect } from \"react\";\nimport { getTabbableElements } from \"../utils/focusManagement\";\n\n/**\n * @description This is a hook that will make sure that when a modal is open and the user tabs through the it,\n * the focus will be repeated and the user will not lose their entire focusable element to an element in the background\n * that is being blocked by the modal.\n */\n\nexport const useRepeatFocus = (ref: RefObject<HTMLDivElement | null>, open?: boolean) => {\n useEffect(() => {\n if (!ref.current || !open) {\n return;\n }\n\n const tabbableElements = getTabbableElements(ref.current);\n const firstFocusableElement = tabbableElements[0];\n const lastFocusableElement = tabbableElements[tabbableElements.length - 1];\n\n if (!lastFocusableElement || !firstFocusableElement) {\n return;\n }\n\n const handleTabKeyPress = (event: Event) => {\n if (!(event instanceof KeyboardEvent) || event.key !== \"Tab\") {\n return;\n }\n\n if (event.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n event.preventDefault();\n lastFocusableElement?.focus();\n }\n } else if (document.activeElement === lastFocusableElement) {\n event.preventDefault();\n firstFocusableElement?.focus();\n }\n };\n\n lastFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n\n return () => {\n lastFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n };\n }, [ref, open]);\n};\n"],"names":["ref","open","useEffect","current","tabbableElements","getTabbableElements","firstFocusableElement","lastFocusableElement","length","handleTabKeyPress","event","KeyboardEvent","key","shiftKey","document","activeElement","preventDefault","focus","addEventListener","removeEventListener"],"mappings":"6KAyB8B,CAACA,EAAuCC,KACpEC,EAAAA,UAAU,KACR,IAAKF,EAAIG,UAAYF,EACnB,OAGF,MAAMG,EAAmBC,EAAAA,oBAAoBL,EAAIG,SAC3CG,EAAwBF,EAAiB,GACzCG,EAAuBH,EAAiBA,EAAiBI,OAAS,GAExE,IAAKD,IAAyBD,EAC5B,OAGF,MAAMG,EAAqBC,IACnBA,aAAiBC,eAAgC,QAAdD,EAAME,MAI3CF,EAAMG,SACJC,SAASC,gBAAkBT,IAC7BI,EAAMM,iBACN,MAAAT,GAAAA,EAAsBU,SAEfH,SAASC,gBAAkBR,IACpCG,EAAMM,iBACN,MAAAV,GAAAA,EAAuBW,WAO3B,OAHAV,EAAqBW,iBAAiB,UAAWT,GACjDH,EAAsBY,iBAAiB,UAAWT,GAE3C,KACLF,EAAqBY,oBAAoB,UAAWV,GACpDH,EAAsBa,oBAAoB,UAAWV,KAEtD,CAACT,EAAKC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRepeatFocus.es.js","sources":["../../src/hooks/useRepeatFocus.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RefObject, useEffect } from \"react\";\nimport { getTabbableElements } from \"../utils/focusManagement\";\n\n/**\n * @description This is a hook that will make sure that when a modal is open and the user tabs through the it,\n * the focus will be repeated and the user will not lose their entire focusable element to an element in the background\n * that is being blocked by the modal.\n */\n\nexport const useRepeatFocus = (ref: RefObject<HTMLDivElement>, open?: boolean) => {\n useEffect(() => {\n if (!ref.current || !open) {\n return;\n }\n\n const tabbableElements = getTabbableElements(ref.current);\n const firstFocusableElement = tabbableElements[0];\n const lastFocusableElement = tabbableElements[tabbableElements.length - 1];\n\n if (!lastFocusableElement || !firstFocusableElement) {\n return;\n }\n\n const handleTabKeyPress = (event: Event) => {\n if (!(event instanceof KeyboardEvent) || event.key !== \"Tab\") {\n return;\n }\n\n if (event.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n event.preventDefault();\n lastFocusableElement?.focus();\n }\n } else if (document.activeElement === lastFocusableElement) {\n event.preventDefault();\n firstFocusableElement?.focus();\n }\n };\n\n lastFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n\n return () => {\n lastFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n };\n }, [ref, open]);\n};\n"],"names":[],"mappings":";;AAyBO,MAAM,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"useRepeatFocus.es.js","sources":["../../src/hooks/useRepeatFocus.tsx"],"sourcesContent":["/*\n * Copyright 2022 OneWelcome B.V.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RefObject, useEffect } from \"react\";\nimport { getTabbableElements } from \"../utils/focusManagement\";\n\n/**\n * @description This is a hook that will make sure that when a modal is open and the user tabs through the it,\n * the focus will be repeated and the user will not lose their entire focusable element to an element in the background\n * that is being blocked by the modal.\n */\n\nexport const useRepeatFocus = (ref: RefObject<HTMLDivElement | null>, open?: boolean) => {\n useEffect(() => {\n if (!ref.current || !open) {\n return;\n }\n\n const tabbableElements = getTabbableElements(ref.current);\n const firstFocusableElement = tabbableElements[0];\n const lastFocusableElement = tabbableElements[tabbableElements.length - 1];\n\n if (!lastFocusableElement || !firstFocusableElement) {\n return;\n }\n\n const handleTabKeyPress = (event: Event) => {\n if (!(event instanceof KeyboardEvent) || event.key !== \"Tab\") {\n return;\n }\n\n if (event.shiftKey) {\n if (document.activeElement === firstFocusableElement) {\n event.preventDefault();\n lastFocusableElement?.focus();\n }\n } else if (document.activeElement === lastFocusableElement) {\n event.preventDefault();\n firstFocusableElement?.focus();\n }\n };\n\n lastFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.addEventListener(\"keydown\", handleTabKeyPress);\n\n return () => {\n lastFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n firstFocusableElement.removeEventListener(\"keydown\", handleTabKeyPress);\n };\n }, [ref, open]);\n};\n"],"names":[],"mappings":";;AAyBO,MAAM,iBAAiB,CAAC,KAAuC,SAAmB;AACvF,YAAU,MAAM;AACd,QAAI,CAAC,IAAI,WAAW,CAAC,MAAM;AACzB;AAAA,IACF;AAEA,UAAM,mBAAmB,oBAAoB,IAAI,OAAO;AACxD,UAAM,wBAAwB,iBAAiB,CAAC;AAChD,UAAM,uBAAuB,iBAAiB,iBAAiB,SAAS,CAAC;AAEzE,QAAI,CAAC,wBAAwB,CAAC,uBAAuB;AACnD;AAAA,IACF;AAEA,UAAM,oBAAoB,CAAC,UAAiB;AAC1C,UAAI,EAAE,iBAAiB,kBAAkB,MAAM,QAAQ,OAAO;AAC5D;AAAA,MACF;AAEA,UAAI,MAAM,UAAU;AAClB,YAAI,SAAS,kBAAkB,uBAAuB;AACpD,gBAAM,eAAA;AACN,uEAAsB;AAAA,QACxB;AAAA,MACF,WAAW,SAAS,kBAAkB,sBAAsB;AAC1D,cAAM,eAAA;AACN,uEAAuB;AAAA,MACzB;AAAA,IACF;AAEA,yBAAqB,iBAAiB,WAAW,iBAAiB;AAClE,0BAAsB,iBAAiB,WAAW,iBAAiB;AAEnE,WAAO,MAAM;AACX,2BAAqB,oBAAoB,WAAW,iBAAiB;AACrE,4BAAsB,oBAAoB,WAAW,iBAAiB;AAAA,IACxE;AAAA,EACF,GAAG,CAAC,KAAK,IAAI,CAAC;AAChB;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),n=require("../variables.cjs.js"),r=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),t=e=>e<r(n.breakpoints[n.ScreenSize.SMALL])?n.ScreenSize.SMALL:e<r(n.breakpoints[n.ScreenSize.MEDIUM])?n.ScreenSize.MEDIUM:n.ScreenSize.LARGE;exports.useScreenSize=({onScreenSizeChange:r}={})=>{const[i,S]=e.useState(t(window.innerWidth));return e.useEffect(()=>{const e=()=>{const e=t(window.innerWidth);S(n=>e!==n?(null==r||r(e,n),e):n)};return window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)},[]),{screenSize:i,isDesktopScreenSize:()=>i===n.ScreenSize.LARGE}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),n=require("../variables.cjs.js"),r=e=>e*Number.parseFloat(getComputedStyle(document.documentElement).fontSize),t=e=>e<r(n.breakpoints[n.ScreenSize.SMALL])?n.ScreenSize.SMALL:e<r(n.breakpoints[n.ScreenSize.MEDIUM])?n.ScreenSize.MEDIUM:n.ScreenSize.LARGE;exports.useScreenSize=({onScreenSizeChange:r}={})=>{const[i,S]=e.useState(t(window.innerWidth));return e.useEffect(()=>{const e=()=>{const e=t(window.innerWidth);S(n=>e!==n?(null==r||r(e,n),e):n)};return window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)},[]),{screenSize:i,isDesktopScreenSize:()=>i===n.ScreenSize.LARGE}};
|
|
2
2
|
//# sourceMappingURL=useScreenSize.cjs.js.map
|