@octanejs/aria 0.0.40 → 0.0.42
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/LICENSE-APACHE-2.0 +201 -0
- package/README.md +20 -7
- package/UPSTREAM.md +108 -0
- package/package.json +10 -6
- package/src/calendar/useCalendar.tsx +36 -0
- package/src/calendar/useCalendarBase.tsx +142 -0
- package/src/calendar/useCalendarCell.tsx +416 -0
- package/src/calendar/useCalendarGrid.tsx +202 -0
- package/src/calendar/useCalendarHeading.tsx +85 -0
- package/src/calendar/useCalendarMonthPicker.tsx +92 -0
- package/src/calendar/useCalendarYearPicker.tsx +127 -0
- package/src/calendar/useRangeCalendar.tsx +121 -0
- package/src/calendar/utils.tsx +183 -0
- package/src/color/useColorArea.tsx +599 -0
- package/src/color/useColorAreaGradient.tsx +157 -0
- package/src/color/useColorChannelField.tsx +53 -0
- package/src/color/useColorField.tsx +170 -0
- package/src/color/useColorSlider.tsx +177 -0
- package/src/color/useColorSwatch.tsx +83 -0
- package/src/color/useColorWheel.tsx +401 -0
- package/src/compat/react.ts +111 -0
- package/src/components/Calendar.tsx +842 -0
- package/src/components/ColorArea.tsx +120 -0
- package/src/components/ColorField.tsx +304 -0
- package/src/components/ColorPicker.tsx +86 -0
- package/src/components/ColorSlider.tsx +144 -0
- package/src/components/ColorSwatch.tsx +72 -0
- package/src/components/ColorSwatchPicker.tsx +176 -0
- package/src/components/ColorThumb.tsx +140 -0
- package/src/components/ColorWheel.tsx +163 -0
- package/src/components/DateField.tsx +580 -0
- package/src/components/DatePicker.tsx +386 -0
- package/src/components/DropZone.tsx +181 -0
- package/src/components/FileTrigger.tsx +96 -0
- package/src/components/GridLayout.tsx +33 -0
- package/src/components/HiddenDateInput.tsx +169 -0
- package/src/components/TableLayout.tsx +39 -0
- package/src/components/Toast.tsx +336 -0
- package/src/components/Virtualizer.tsx +219 -0
- package/src/components/index.ts +257 -7
- package/src/components/useDragAndDrop.tsx +221 -0
- package/src/components/utils.ts +12 -89
- package/src/datepicker/useDateField.tsx +272 -0
- package/src/datepicker/useDatePicker.tsx +229 -0
- package/src/datepicker/useDatePickerGroup.tsx +147 -0
- package/src/datepicker/useDateRangePicker.tsx +288 -0
- package/src/datepicker/useDateSegment.tsx +439 -0
- package/src/datepicker/useDisplayNames.tsx +53 -0
- package/src/dnd/DragManager.tsx +718 -0
- package/src/dnd/DragPreview.tsx +100 -0
- package/src/dnd/DropTargetKeyboardNavigation.tsx +317 -0
- package/src/dnd/ListDropTargetDelegate.tsx +215 -0
- package/src/dnd/constants.tsx +93 -0
- package/src/dnd/useAutoScroll.tsx +116 -0
- package/src/dnd/useClipboard.tsx +160 -0
- package/src/dnd/useDrag.tsx +437 -0
- package/src/dnd/useDraggableCollection.tsx +35 -0
- package/src/dnd/useDraggableItem.tsx +168 -0
- package/src/dnd/useDrop.tsx +518 -0
- package/src/dnd/useDropIndicator.tsx +129 -0
- package/src/dnd/useDroppableCollection.tsx +808 -0
- package/src/dnd/useDroppableItem.tsx +99 -0
- package/src/dnd/useVirtualDrop.tsx +52 -0
- package/src/dnd/utils.tsx +430 -0
- package/src/intl/calendar/ar-AE.json +14 -0
- package/src/intl/calendar/bg-BG.json +14 -0
- package/src/intl/calendar/cs-CZ.json +14 -0
- package/src/intl/calendar/da-DK.json +14 -0
- package/src/intl/calendar/de-DE.json +14 -0
- package/src/intl/calendar/el-GR.json +14 -0
- package/src/intl/calendar/en-US.json +14 -0
- package/src/intl/calendar/es-ES.json +14 -0
- package/src/intl/calendar/et-EE.json +14 -0
- package/src/intl/calendar/fi-FI.json +14 -0
- package/src/intl/calendar/fr-FR.json +14 -0
- package/src/intl/calendar/he-IL.json +14 -0
- package/src/intl/calendar/hr-HR.json +14 -0
- package/src/intl/calendar/hu-HU.json +14 -0
- package/src/intl/calendar/index.ts +73 -0
- package/src/intl/calendar/it-IT.json +14 -0
- package/src/intl/calendar/ja-JP.json +14 -0
- package/src/intl/calendar/ko-KR.json +14 -0
- package/src/intl/calendar/lt-LT.json +14 -0
- package/src/intl/calendar/lv-LV.json +14 -0
- package/src/intl/calendar/nb-NO.json +14 -0
- package/src/intl/calendar/nl-NL.json +14 -0
- package/src/intl/calendar/pl-PL.json +14 -0
- package/src/intl/calendar/pt-BR.json +14 -0
- package/src/intl/calendar/pt-PT.json +14 -0
- package/src/intl/calendar/ro-RO.json +14 -0
- package/src/intl/calendar/ru-RU.json +14 -0
- package/src/intl/calendar/sk-SK.json +14 -0
- package/src/intl/calendar/sl-SI.json +14 -0
- package/src/intl/calendar/sr-SP.json +14 -0
- package/src/intl/calendar/sv-SE.json +14 -0
- package/src/intl/calendar/tr-TR.json +14 -0
- package/src/intl/calendar/uk-UA.json +14 -0
- package/src/intl/calendar/zh-CN.json +14 -0
- package/src/intl/calendar/zh-TW.json +14 -0
- package/src/intl/color/ar-AE.json +8 -0
- package/src/intl/color/bg-BG.json +8 -0
- package/src/intl/color/cs-CZ.json +8 -0
- package/src/intl/color/da-DK.json +8 -0
- package/src/intl/color/de-DE.json +8 -0
- package/src/intl/color/el-GR.json +8 -0
- package/src/intl/color/en-US.json +8 -0
- package/src/intl/color/es-ES.json +8 -0
- package/src/intl/color/et-EE.json +8 -0
- package/src/intl/color/fi-FI.json +8 -0
- package/src/intl/color/fr-FR.json +8 -0
- package/src/intl/color/he-IL.json +8 -0
- package/src/intl/color/hr-HR.json +8 -0
- package/src/intl/color/hu-HU.json +8 -0
- package/src/intl/color/index.ts +73 -0
- package/src/intl/color/it-IT.json +8 -0
- package/src/intl/color/ja-JP.json +8 -0
- package/src/intl/color/ko-KR.json +8 -0
- package/src/intl/color/lt-LT.json +8 -0
- package/src/intl/color/lv-LV.json +8 -0
- package/src/intl/color/nb-NO.json +8 -0
- package/src/intl/color/nl-NL.json +8 -0
- package/src/intl/color/pl-PL.json +8 -0
- package/src/intl/color/pt-BR.json +8 -0
- package/src/intl/color/pt-PT.json +8 -0
- package/src/intl/color/ro-RO.json +8 -0
- package/src/intl/color/ru-RU.json +8 -0
- package/src/intl/color/sk-SK.json +8 -0
- package/src/intl/color/sl-SI.json +8 -0
- package/src/intl/color/sr-SP.json +8 -0
- package/src/intl/color/sv-SE.json +8 -0
- package/src/intl/color/tr-TR.json +8 -0
- package/src/intl/color/uk-UA.json +8 -0
- package/src/intl/color/zh-CN.json +8 -0
- package/src/intl/color/zh-TW.json +8 -0
- package/src/intl/datepicker/ar-AE.json +18 -0
- package/src/intl/datepicker/bg-BG.json +18 -0
- package/src/intl/datepicker/cs-CZ.json +18 -0
- package/src/intl/datepicker/da-DK.json +18 -0
- package/src/intl/datepicker/de-DE.json +18 -0
- package/src/intl/datepicker/el-GR.json +18 -0
- package/src/intl/datepicker/en-US.json +18 -0
- package/src/intl/datepicker/es-ES.json +18 -0
- package/src/intl/datepicker/et-EE.json +18 -0
- package/src/intl/datepicker/fi-FI.json +18 -0
- package/src/intl/datepicker/fr-FR.json +18 -0
- package/src/intl/datepicker/he-IL.json +18 -0
- package/src/intl/datepicker/hr-HR.json +18 -0
- package/src/intl/datepicker/hu-HU.json +18 -0
- package/src/intl/datepicker/index.ts +73 -0
- package/src/intl/datepicker/it-IT.json +18 -0
- package/src/intl/datepicker/ja-JP.json +18 -0
- package/src/intl/datepicker/ko-KR.json +18 -0
- package/src/intl/datepicker/lt-LT.json +18 -0
- package/src/intl/datepicker/lv-LV.json +18 -0
- package/src/intl/datepicker/nb-NO.json +18 -0
- package/src/intl/datepicker/nl-NL.json +18 -0
- package/src/intl/datepicker/pl-PL.json +18 -0
- package/src/intl/datepicker/pt-BR.json +18 -0
- package/src/intl/datepicker/pt-PT.json +18 -0
- package/src/intl/datepicker/ro-RO.json +18 -0
- package/src/intl/datepicker/ru-RU.json +18 -0
- package/src/intl/datepicker/sk-SK.json +18 -0
- package/src/intl/datepicker/sl-SI.json +18 -0
- package/src/intl/datepicker/sr-SP.json +18 -0
- package/src/intl/datepicker/sv-SE.json +18 -0
- package/src/intl/datepicker/tr-TR.json +18 -0
- package/src/intl/datepicker/uk-UA.json +18 -0
- package/src/intl/datepicker/zh-CN.json +18 -0
- package/src/intl/datepicker/zh-TW.json +18 -0
- package/src/intl/dnd/ar-AE.json +29 -0
- package/src/intl/dnd/bg-BG.json +29 -0
- package/src/intl/dnd/cs-CZ.json +29 -0
- package/src/intl/dnd/da-DK.json +29 -0
- package/src/intl/dnd/de-DE.json +29 -0
- package/src/intl/dnd/el-GR.json +29 -0
- package/src/intl/dnd/en-US.json +29 -0
- package/src/intl/dnd/es-ES.json +29 -0
- package/src/intl/dnd/et-EE.json +29 -0
- package/src/intl/dnd/fi-FI.json +29 -0
- package/src/intl/dnd/fr-FR.json +29 -0
- package/src/intl/dnd/he-IL.json +29 -0
- package/src/intl/dnd/hr-HR.json +29 -0
- package/src/intl/dnd/hu-HU.json +29 -0
- package/src/intl/dnd/index.ts +73 -0
- package/src/intl/dnd/it-IT.json +29 -0
- package/src/intl/dnd/ja-JP.json +29 -0
- package/src/intl/dnd/ko-KR.json +29 -0
- package/src/intl/dnd/lt-LT.json +29 -0
- package/src/intl/dnd/lv-LV.json +29 -0
- package/src/intl/dnd/nb-NO.json +29 -0
- package/src/intl/dnd/nl-NL.json +29 -0
- package/src/intl/dnd/pl-PL.json +29 -0
- package/src/intl/dnd/pt-BR.json +29 -0
- package/src/intl/dnd/pt-PT.json +29 -0
- package/src/intl/dnd/ro-RO.json +29 -0
- package/src/intl/dnd/ru-RU.json +29 -0
- package/src/intl/dnd/sk-SK.json +29 -0
- package/src/intl/dnd/sl-SI.json +29 -0
- package/src/intl/dnd/sr-SP.json +29 -0
- package/src/intl/dnd/sv-SE.json +29 -0
- package/src/intl/dnd/tr-TR.json +29 -0
- package/src/intl/dnd/uk-UA.json +29 -0
- package/src/intl/dnd/zh-CN.json +29 -0
- package/src/intl/dnd/zh-TW.json +29 -0
- package/src/intl/react-aria-components/ar-AE.json +6 -0
- package/src/intl/react-aria-components/bg-BG.json +6 -0
- package/src/intl/react-aria-components/cs-CZ.json +6 -0
- package/src/intl/react-aria-components/da-DK.json +6 -0
- package/src/intl/react-aria-components/de-DE.json +6 -0
- package/src/intl/react-aria-components/el-GR.json +6 -0
- package/src/intl/react-aria-components/en-US.json +6 -0
- package/src/intl/react-aria-components/es-ES.json +6 -0
- package/src/intl/react-aria-components/et-EE.json +6 -0
- package/src/intl/react-aria-components/fi-FI.json +6 -0
- package/src/intl/react-aria-components/fr-FR.json +6 -0
- package/src/intl/react-aria-components/he-IL.json +6 -0
- package/src/intl/react-aria-components/hr-HR.json +6 -0
- package/src/intl/react-aria-components/hu-HU.json +6 -0
- package/src/intl/react-aria-components/index.ts +73 -0
- package/src/intl/react-aria-components/it-IT.json +6 -0
- package/src/intl/react-aria-components/ja-JP.json +6 -0
- package/src/intl/react-aria-components/ko-KR.json +6 -0
- package/src/intl/react-aria-components/lt-LT.json +6 -0
- package/src/intl/react-aria-components/lv-LV.json +6 -0
- package/src/intl/react-aria-components/nb-NO.json +6 -0
- package/src/intl/react-aria-components/nl-NL.json +6 -0
- package/src/intl/react-aria-components/pl-PL.json +6 -0
- package/src/intl/react-aria-components/pt-BR.json +6 -0
- package/src/intl/react-aria-components/pt-PT.json +6 -0
- package/src/intl/react-aria-components/ro-RO.json +6 -0
- package/src/intl/react-aria-components/ru-RU.json +6 -0
- package/src/intl/react-aria-components/sk-SK.json +6 -0
- package/src/intl/react-aria-components/sl-SI.json +6 -0
- package/src/intl/react-aria-components/sr-SP.json +6 -0
- package/src/intl/react-aria-components/sv-SE.json +6 -0
- package/src/intl/react-aria-components/tr-TR.json +6 -0
- package/src/intl/react-aria-components/uk-UA.json +6 -0
- package/src/intl/react-aria-components/zh-CN.json +6 -0
- package/src/intl/react-aria-components/zh-TW.json +6 -0
- package/src/intl/stately-color/ar-AE.json +39 -0
- package/src/intl/stately-color/bg-BG.json +39 -0
- package/src/intl/stately-color/cs-CZ.json +39 -0
- package/src/intl/stately-color/da-DK.json +39 -0
- package/src/intl/stately-color/de-DE.json +39 -0
- package/src/intl/stately-color/el-GR.json +39 -0
- package/src/intl/stately-color/en-US.json +39 -0
- package/src/intl/stately-color/es-ES.json +39 -0
- package/src/intl/stately-color/et-EE.json +39 -0
- package/src/intl/stately-color/fi-FI.json +39 -0
- package/src/intl/stately-color/fr-FR.json +39 -0
- package/src/intl/stately-color/he-IL.json +39 -0
- package/src/intl/stately-color/hr-HR.json +39 -0
- package/src/intl/stately-color/hu-HU.json +39 -0
- package/src/intl/stately-color/index.ts +73 -0
- package/src/intl/stately-color/it-IT.json +39 -0
- package/src/intl/stately-color/ja-JP.json +39 -0
- package/src/intl/stately-color/ko-KR.json +39 -0
- package/src/intl/stately-color/lt-LT.json +39 -0
- package/src/intl/stately-color/lv-LV.json +39 -0
- package/src/intl/stately-color/nb-NO.json +39 -0
- package/src/intl/stately-color/nl-NL.json +39 -0
- package/src/intl/stately-color/pl-PL.json +39 -0
- package/src/intl/stately-color/pt-BR.json +39 -0
- package/src/intl/stately-color/pt-PT.json +39 -0
- package/src/intl/stately-color/ro-RO.json +39 -0
- package/src/intl/stately-color/ru-RU.json +39 -0
- package/src/intl/stately-color/sk-SK.json +39 -0
- package/src/intl/stately-color/sl-SI.json +39 -0
- package/src/intl/stately-color/sr-SP.json +39 -0
- package/src/intl/stately-color/sv-SE.json +39 -0
- package/src/intl/stately-color/tr-TR.json +39 -0
- package/src/intl/stately-color/uk-UA.json +39 -0
- package/src/intl/stately-color/zh-CN.json +39 -0
- package/src/intl/stately-color/zh-TW.json +39 -0
- package/src/intl/toast/ar-AE.json +4 -0
- package/src/intl/toast/bg-BG.json +4 -0
- package/src/intl/toast/cs-CZ.json +4 -0
- package/src/intl/toast/da-DK.json +4 -0
- package/src/intl/toast/de-DE.json +4 -0
- package/src/intl/toast/el-GR.json +4 -0
- package/src/intl/toast/en-US.json +4 -0
- package/src/intl/toast/es-ES.json +4 -0
- package/src/intl/toast/et-EE.json +4 -0
- package/src/intl/toast/fi-FI.json +4 -0
- package/src/intl/toast/fr-FR.json +4 -0
- package/src/intl/toast/he-IL.json +4 -0
- package/src/intl/toast/hr-HR.json +4 -0
- package/src/intl/toast/hu-HU.json +4 -0
- package/src/intl/toast/index.ts +73 -0
- package/src/intl/toast/it-IT.json +4 -0
- package/src/intl/toast/ja-JP.json +4 -0
- package/src/intl/toast/ko-KR.json +4 -0
- package/src/intl/toast/lt-LT.json +4 -0
- package/src/intl/toast/lv-LV.json +4 -0
- package/src/intl/toast/nb-NO.json +4 -0
- package/src/intl/toast/nl-NL.json +4 -0
- package/src/intl/toast/pl-PL.json +4 -0
- package/src/intl/toast/pt-BR.json +4 -0
- package/src/intl/toast/pt-PT.json +4 -0
- package/src/intl/toast/ro-RO.json +4 -0
- package/src/intl/toast/ru-RU.json +4 -0
- package/src/intl/toast/sk-SK.json +4 -0
- package/src/intl/toast/sl-SI.json +4 -0
- package/src/intl/toast/sr-SP.json +4 -0
- package/src/intl/toast/sv-SE.json +4 -0
- package/src/intl/toast/tr-TR.json +4 -0
- package/src/intl/toast/uk-UA.json +4 -0
- package/src/intl/toast/zh-CN.json +4 -0
- package/src/intl/toast/zh-TW.json +4 -0
- package/src/landmark/useLandmark.tsx +569 -0
- package/src/stately/calendar/types.tsx +239 -0
- package/src/stately/calendar/useCalendarState.tsx +527 -0
- package/src/stately/calendar/useRangeCalendarState.tsx +323 -0
- package/src/stately/calendar/utils.tsx +175 -0
- package/src/stately/color/Color.tsx +889 -0
- package/src/stately/color/types.tsx +82 -0
- package/src/stately/color/useColor.tsx +30 -0
- package/src/stately/color/useColorAreaState.tsx +255 -0
- package/src/stately/color/useColorChannelFieldState.tsx +86 -0
- package/src/stately/color/useColorFieldState.tsx +220 -0
- package/src/stately/color/useColorPickerState.tsx +31 -0
- package/src/stately/color/useColorSliderState.tsx +143 -0
- package/src/stately/color/useColorWheelState.tsx +225 -0
- package/src/stately/data/useAsyncList.tsx +382 -0
- package/src/stately/data/useListData.tsx +447 -0
- package/src/stately/data/useTreeData.tsx +603 -0
- package/src/stately/datepicker/IncompleteDate.tsx +427 -0
- package/src/stately/datepicker/placeholders.tsx +116 -0
- package/src/stately/datepicker/types.tsx +169 -0
- package/src/stately/datepicker/useDateFieldState.tsx +564 -0
- package/src/stately/datepicker/useDatePickerState.tsx +244 -0
- package/src/stately/datepicker/useDateRangePickerState.tsx +397 -0
- package/src/stately/datepicker/useTimeFieldState.tsx +123 -0
- package/src/stately/datepicker/utils.tsx +316 -0
- package/src/stately/dnd/useDraggableCollectionState.tsx +191 -0
- package/src/stately/dnd/useDroppableCollectionState.tsx +288 -0
- package/src/stately/layout/GridLayout.tsx +449 -0
- package/src/stately/layout/ListLayout.tsx +872 -0
- package/src/stately/layout/TableLayout.tsx +793 -0
- package/src/stately/layout/WaterfallLayout.tsx +399 -0
- package/src/stately/toast/useToastState.tsx +219 -0
- package/src/stately/virtualizer/Layout.tsx +105 -0
- package/src/stately/virtualizer/LayoutInfo.tsx +127 -0
- package/src/stately/virtualizer/OverscanManager.tsx +56 -0
- package/src/stately/virtualizer/Point.tsx +47 -0
- package/src/stately/virtualizer/Rect.tsx +194 -0
- package/src/stately/virtualizer/ReusableView.tsx +101 -0
- package/src/stately/virtualizer/Size.tsx +48 -0
- package/src/stately/virtualizer/Virtualizer.tsx +408 -0
- package/src/stately/virtualizer/types.tsx +48 -0
- package/src/stately/virtualizer/useVirtualizerState.tsx +138 -0
- package/src/stately/virtualizer/utils.tsx +32 -0
- package/src/textfield/useTextField.ts +3 -0
- package/src/toast/useToast.tsx +105 -0
- package/src/toast/useToastRegion.tsx +223 -0
- package/src/upstream-exports/react-aria/I18nProvider.tsx +17 -0
- package/src/upstream-exports/react-aria/ListDropTargetDelegate.tsx +15 -0
- package/src/upstream-exports/react-aria/PortalProvider.tsx +19 -0
- package/src/upstream-exports/react-aria/SSRProvider.tsx +15 -0
- package/src/upstream-exports/react-aria/VisuallyHidden.tsx +15 -0
- package/src/upstream-exports/react-aria/filterDOMProps.tsx +3 -0
- package/src/upstream-exports/react-aria/mergeProps.tsx +14 -0
- package/src/upstream-exports/react-aria/private/dnd/DragManager.tsx +3 -0
- package/src/upstream-exports/react-aria/private/interactions/PressResponder.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/isFocusable.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/shadowdom/DOMFunctions.tsx +8 -0
- package/src/upstream-exports/react-aria/private/utils/useId.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/useLabels.tsx +3 -0
- package/src/upstream-exports/react-aria/private/virtualizer/ScrollView.tsx +3 -0
- package/src/upstream-exports/react-aria/private/virtualizer/VirtualizerItem.tsx +3 -0
- package/src/upstream-exports/react-aria/useButton.tsx +22 -0
- package/src/upstream-exports/react-aria/useCalendar.tsx +37 -0
- package/src/upstream-exports/react-aria/useClipboard.tsx +23 -0
- package/src/upstream-exports/react-aria/useColorArea.tsx +19 -0
- package/src/upstream-exports/react-aria/useColorField.tsx +20 -0
- package/src/upstream-exports/react-aria/useColorSlider.tsx +19 -0
- package/src/upstream-exports/react-aria/useColorSwatch.tsx +15 -0
- package/src/upstream-exports/react-aria/useColorWheel.tsx +19 -0
- package/src/upstream-exports/react-aria/useDateField.tsx +23 -0
- package/src/upstream-exports/react-aria/useDatePicker.tsx +17 -0
- package/src/upstream-exports/react-aria/useDateRangePicker.tsx +24 -0
- package/src/upstream-exports/react-aria/useDraggableCollection.tsx +31 -0
- package/src/upstream-exports/react-aria/useDrop.tsx +33 -0
- package/src/upstream-exports/react-aria/useDroppableCollection.tsx +47 -0
- package/src/upstream-exports/react-aria/useFocusRing.tsx +16 -0
- package/src/upstream-exports/react-aria/useHover.tsx +17 -0
- package/src/upstream-exports/react-aria/useLocalizedStringFormatter.tsx +19 -0
- package/src/upstream-exports/react-aria/useObjectRef.tsx +14 -0
- package/src/upstream-exports/react-aria/useRangeCalendar.tsx +38 -0
- package/src/upstream-exports/react-aria/useTimeField.tsx +23 -0
- package/src/upstream-exports/react-aria/useToast.tsx +18 -0
- package/src/upstream-exports/react-stately/Color.tsx +23 -0
- package/src/upstream-exports/react-stately/private/form/useFormValidationState.tsx +11 -0
- package/src/upstream-exports/react-stately/useCalendarState.tsx +24 -0
- package/src/upstream-exports/react-stately/useColorAreaState.tsx +24 -0
- package/src/upstream-exports/react-stately/useColorFieldState.tsx +22 -0
- package/src/upstream-exports/react-stately/useColorPickerState.tsx +25 -0
- package/src/upstream-exports/react-stately/useColorSliderState.tsx +25 -0
- package/src/upstream-exports/react-stately/useColorWheelState.tsx +24 -0
- package/src/upstream-exports/react-stately/useDateFieldState.tsx +29 -0
- package/src/upstream-exports/react-stately/useDatePickerState.tsx +25 -0
- package/src/upstream-exports/react-stately/useDateRangePickerState.tsx +26 -0
- package/src/upstream-exports/react-stately/useDraggableCollectionState.tsx +19 -0
- package/src/upstream-exports/react-stately/useDroppableCollectionState.tsx +19 -0
- package/src/upstream-exports/react-stately/useRangeCalendarState.tsx +27 -0
- package/src/upstream-exports/react-stately/useTimeFieldState.tsx +26 -0
- package/src/upstream-exports/react-stately/useToastState.tsx +21 -0
- package/src/upstream-exports/react-stately/useVirtualizerState.tsx +22 -0
- package/src/utils/useLoadMore.tsx +89 -0
- package/src/virtualizer/ScrollView.tsx +401 -0
- package/src/virtualizer/Virtualizer.tsx +147 -0
- package/src/virtualizer/VirtualizerItem.tsx +108 -0
- package/src/virtualizer/useVirtualizerItem.tsx +57 -0
- package/src/virtualizer/utils.tsx +105 -0
- package/LICENSE +0 -21
- package/src/components/useDragAndDrop.ts +0 -164
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
/** @jsxImportSource octane */
|
|
2
|
+
// Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/dnd/DragManager.ts).
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { announce } from '../live-announcer/LiveAnnouncer';
|
|
16
|
+
|
|
17
|
+
import { ariaHideOutside } from '../overlays/ariaHideOutside';
|
|
18
|
+
import {
|
|
19
|
+
DragEndEvent,
|
|
20
|
+
DragItem,
|
|
21
|
+
DropActivateEvent,
|
|
22
|
+
DropEnterEvent,
|
|
23
|
+
DropEvent,
|
|
24
|
+
DropExitEvent,
|
|
25
|
+
DropItem,
|
|
26
|
+
DropOperation,
|
|
27
|
+
DropTarget as DroppableCollectionTarget,
|
|
28
|
+
FocusableElement,
|
|
29
|
+
} from '@react-types/shared';
|
|
30
|
+
import { getActiveElement, getEventTarget, nodeContains } from '../utils/shadowdom/DOMFunctions';
|
|
31
|
+
import { getDragModality, getTypes } from './utils';
|
|
32
|
+
import { isVirtualClick, isVirtualPointerEvent } from '../utils/isVirtualEvent';
|
|
33
|
+
import type { LocalizedStringFormatter } from '@internationalized/string';
|
|
34
|
+
import { RefObject, useEffect, useState } from '../compat/react';
|
|
35
|
+
|
|
36
|
+
let dropTargets = new Map<Element, DropTarget>();
|
|
37
|
+
let dropItems = new Map<Element, DroppableItem>();
|
|
38
|
+
let dragSession: DragSession | null = null;
|
|
39
|
+
let subscriptions = new Set<() => void>();
|
|
40
|
+
|
|
41
|
+
interface DropTarget {
|
|
42
|
+
element: FocusableElement;
|
|
43
|
+
preventFocusOnDrop?: boolean;
|
|
44
|
+
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;
|
|
45
|
+
onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void;
|
|
46
|
+
onDropExit?: (e: DropExitEvent) => void;
|
|
47
|
+
onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void;
|
|
48
|
+
onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void;
|
|
49
|
+
onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void;
|
|
50
|
+
onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void;
|
|
51
|
+
activateButtonRef?: RefObject<FocusableElement | null>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function registerDropTarget(target: DropTarget) {
|
|
55
|
+
dropTargets.set(target.element, target);
|
|
56
|
+
dragSession?.updateValidDropTargets();
|
|
57
|
+
return (): void => {
|
|
58
|
+
dropTargets.delete(target.element);
|
|
59
|
+
dragSession?.updateValidDropTargets();
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface DroppableItem {
|
|
64
|
+
element: FocusableElement;
|
|
65
|
+
target: DroppableCollectionTarget;
|
|
66
|
+
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation;
|
|
67
|
+
activateButtonRef?: RefObject<FocusableElement | null>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function registerDropItem(item: DroppableItem) {
|
|
71
|
+
dropItems.set(item.element, item);
|
|
72
|
+
return (): void => {
|
|
73
|
+
dropItems.delete(item.element);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface DragTarget {
|
|
78
|
+
element: FocusableElement;
|
|
79
|
+
items: DragItem[];
|
|
80
|
+
allowedDropOperations: DropOperation[];
|
|
81
|
+
onDragEnd?: (e: DragEndEvent) => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {
|
|
85
|
+
if (dragSession) {
|
|
86
|
+
throw new Error('Cannot begin dragging while already dragging');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
dragSession = new DragSession(target, stringFormatter);
|
|
90
|
+
requestAnimationFrame(() => {
|
|
91
|
+
if (dragSession) {
|
|
92
|
+
dragSession.setup();
|
|
93
|
+
if (getDragModality() === 'keyboard') {
|
|
94
|
+
dragSession.next();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
for (let cb of subscriptions) {
|
|
100
|
+
cb();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function useDragSession(): DragSession | null {
|
|
105
|
+
let [session, setSession] = useState(dragSession);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
let cb = () => setSession(dragSession);
|
|
109
|
+
subscriptions.add(cb);
|
|
110
|
+
return () => {
|
|
111
|
+
subscriptions.delete(cb);
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
return session;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** @private */
|
|
119
|
+
export function isVirtualDragging(): boolean {
|
|
120
|
+
return !!dragSession;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function endDragging() {
|
|
124
|
+
dragSession = null;
|
|
125
|
+
for (let cb of subscriptions) {
|
|
126
|
+
cb();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function isValidDropTarget(element: Element): boolean {
|
|
131
|
+
for (let target of dropTargets.keys()) {
|
|
132
|
+
if (nodeContains(target, element)) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const CANCELED_EVENTS = [
|
|
141
|
+
'pointerdown',
|
|
142
|
+
'pointermove',
|
|
143
|
+
'pointerenter',
|
|
144
|
+
'pointerleave',
|
|
145
|
+
'pointerover',
|
|
146
|
+
'pointerout',
|
|
147
|
+
'pointerup',
|
|
148
|
+
'mousedown',
|
|
149
|
+
'mousemove',
|
|
150
|
+
'mouseenter',
|
|
151
|
+
'mouseleave',
|
|
152
|
+
'mouseover',
|
|
153
|
+
'mouseout',
|
|
154
|
+
'mouseup',
|
|
155
|
+
'touchstart',
|
|
156
|
+
'touchmove',
|
|
157
|
+
'touchend',
|
|
158
|
+
'focusin',
|
|
159
|
+
'focusout',
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const CLICK_EVENTS = ['pointerup', 'mouseup', 'touchend'];
|
|
163
|
+
|
|
164
|
+
const MESSAGES = {
|
|
165
|
+
keyboard: 'dragStartedKeyboard',
|
|
166
|
+
touch: 'dragStartedTouch',
|
|
167
|
+
virtual: 'dragStartedVirtual',
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
class DragSession {
|
|
171
|
+
dragTarget: DragTarget;
|
|
172
|
+
validDropTargets: DropTarget[] = [];
|
|
173
|
+
currentDropTarget: DropTarget | null = null;
|
|
174
|
+
currentDropItem: DroppableItem | null = null;
|
|
175
|
+
dropOperation: DropOperation | null = null;
|
|
176
|
+
private mutationObserver: MutationObserver | null = null;
|
|
177
|
+
private restoreAriaHidden: (() => void) | null = null;
|
|
178
|
+
private stringFormatter: LocalizedStringFormatter;
|
|
179
|
+
private isVirtualClick: boolean = false;
|
|
180
|
+
private initialFocused: boolean;
|
|
181
|
+
|
|
182
|
+
constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {
|
|
183
|
+
this.dragTarget = target;
|
|
184
|
+
this.stringFormatter = stringFormatter;
|
|
185
|
+
|
|
186
|
+
this.onKeyDown = this.onKeyDown.bind(this);
|
|
187
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
188
|
+
this.onFocus = this.onFocus.bind(this);
|
|
189
|
+
this.onBlur = this.onBlur.bind(this);
|
|
190
|
+
this.onClick = this.onClick.bind(this);
|
|
191
|
+
this.onPointerDown = this.onPointerDown.bind(this);
|
|
192
|
+
this.cancelEvent = this.cancelEvent.bind(this);
|
|
193
|
+
this.initialFocused = false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
setup(): void {
|
|
197
|
+
document.addEventListener('keydown', this.onKeyDown, true);
|
|
198
|
+
document.addEventListener('keyup', this.onKeyUp, true);
|
|
199
|
+
window.addEventListener('focus', this.onFocus, true);
|
|
200
|
+
window.addEventListener('blur', this.onBlur, true);
|
|
201
|
+
document.addEventListener('click', this.onClick, true);
|
|
202
|
+
document.addEventListener('pointerdown', this.onPointerDown, true);
|
|
203
|
+
|
|
204
|
+
for (let event of CANCELED_EVENTS) {
|
|
205
|
+
document.addEventListener(event, this.cancelEvent, true);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.mutationObserver = new MutationObserver(() => this.updateValidDropTargets());
|
|
209
|
+
this.updateValidDropTargets();
|
|
210
|
+
|
|
211
|
+
announce(this.stringFormatter.format(MESSAGES[getDragModality() as keyof typeof MESSAGES]));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
teardown(): void {
|
|
215
|
+
document.removeEventListener('keydown', this.onKeyDown, true);
|
|
216
|
+
document.removeEventListener('keyup', this.onKeyUp, true);
|
|
217
|
+
window.removeEventListener('focus', this.onFocus, true);
|
|
218
|
+
window.removeEventListener('blur', this.onBlur, true);
|
|
219
|
+
document.removeEventListener('click', this.onClick, true);
|
|
220
|
+
document.removeEventListener('pointerdown', this.onPointerDown, true);
|
|
221
|
+
|
|
222
|
+
for (let event of CANCELED_EVENTS) {
|
|
223
|
+
document.removeEventListener(event, this.cancelEvent, true);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.mutationObserver?.disconnect();
|
|
227
|
+
this.restoreAriaHidden?.();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
onKeyDown(e: KeyboardEvent): void {
|
|
231
|
+
this.cancelEvent(e);
|
|
232
|
+
|
|
233
|
+
if (e.key === 'Escape') {
|
|
234
|
+
this.cancel();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (e.key === 'Tab' && !(e.metaKey || e.altKey || e.ctrlKey)) {
|
|
239
|
+
if (e.shiftKey) {
|
|
240
|
+
this.previous();
|
|
241
|
+
} else {
|
|
242
|
+
this.next();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (typeof this.currentDropTarget?.onKeyDown === 'function') {
|
|
247
|
+
this.currentDropTarget.onKeyDown(e, this.dragTarget);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
onKeyUp(e: KeyboardEvent): void {
|
|
252
|
+
this.cancelEvent(e);
|
|
253
|
+
|
|
254
|
+
if (e.key === 'Enter') {
|
|
255
|
+
if (e.altKey || nodeContains(this.getCurrentActivateButton(), getEventTarget(e) as Node)) {
|
|
256
|
+
this.activate(this.currentDropTarget, this.currentDropItem);
|
|
257
|
+
} else {
|
|
258
|
+
this.drop();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
getCurrentActivateButton(): FocusableElement | null {
|
|
264
|
+
return (
|
|
265
|
+
this.currentDropItem?.activateButtonRef?.current ??
|
|
266
|
+
this.currentDropTarget?.activateButtonRef?.current ??
|
|
267
|
+
null
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
onFocus(e: FocusEvent): void {
|
|
272
|
+
let activateButton = this.getCurrentActivateButton();
|
|
273
|
+
let eventTarget = getEventTarget(e);
|
|
274
|
+
if (eventTarget === activateButton) {
|
|
275
|
+
// TODO: canceling this breaks the focus ring. Revisit when we support tabbing.
|
|
276
|
+
this.cancelEvent(e);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Prevent focus events, except to the original drag target.
|
|
281
|
+
if (eventTarget !== this.dragTarget.element) {
|
|
282
|
+
this.cancelEvent(e);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.
|
|
286
|
+
if (!(eventTarget instanceof HTMLElement) || eventTarget === this.dragTarget.element) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let dropTarget =
|
|
291
|
+
this.validDropTargets.find((target) => target.element === eventTarget) ||
|
|
292
|
+
this.validDropTargets.find((target) => nodeContains(target.element, eventTarget));
|
|
293
|
+
|
|
294
|
+
if (!dropTarget) {
|
|
295
|
+
// if (e.target === activateButton) {
|
|
296
|
+
// activateButton.focus();
|
|
297
|
+
// }
|
|
298
|
+
if (this.currentDropTarget) {
|
|
299
|
+
this.currentDropTarget.element.focus();
|
|
300
|
+
} else {
|
|
301
|
+
this.dragTarget.element.focus();
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
let item = dropItems.get(eventTarget);
|
|
307
|
+
if (dropTarget) {
|
|
308
|
+
this.setCurrentDropTarget(dropTarget, item);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
onBlur(e: FocusEvent): void {
|
|
313
|
+
let activateButton = this.getCurrentActivateButton();
|
|
314
|
+
// Guard activateButton non-null so this doesn't trip on the case where
|
|
315
|
+
// there's no activate button and the focused element loses focus to nothing
|
|
316
|
+
// (browsers and jsdom 26+ both set relatedTarget to null in that case).
|
|
317
|
+
if (activateButton && e.relatedTarget === activateButton) {
|
|
318
|
+
this.cancelEvent(e);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (getEventTarget(e) !== this.dragTarget.element) {
|
|
323
|
+
this.cancelEvent(e);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),
|
|
327
|
+
// restore focus back to the current drop target if any, or the original drag target.
|
|
328
|
+
if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {
|
|
329
|
+
if (this.currentDropTarget) {
|
|
330
|
+
this.currentDropTarget.element.focus();
|
|
331
|
+
} else {
|
|
332
|
+
this.dragTarget.element.focus();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
onClick(e: MouseEvent): void {
|
|
338
|
+
this.cancelEvent(e);
|
|
339
|
+
if (isVirtualClick(e) || this.isVirtualClick) {
|
|
340
|
+
let dropElements = dropItems.values();
|
|
341
|
+
let eventTarget = getEventTarget(e) as HTMLElement;
|
|
342
|
+
let item = [...dropElements].find(
|
|
343
|
+
(item) =>
|
|
344
|
+
item.element === eventTarget ||
|
|
345
|
+
nodeContains(item.activateButtonRef?.current, eventTarget),
|
|
346
|
+
);
|
|
347
|
+
let dropTarget = this.validDropTargets.find((target) =>
|
|
348
|
+
nodeContains(target.element, eventTarget),
|
|
349
|
+
);
|
|
350
|
+
let activateButton =
|
|
351
|
+
item?.activateButtonRef?.current ?? dropTarget?.activateButtonRef?.current;
|
|
352
|
+
if (nodeContains(activateButton, eventTarget) && dropTarget) {
|
|
353
|
+
this.activate(dropTarget, item);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (getEventTarget(e) === this.dragTarget.element) {
|
|
358
|
+
this.cancel();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (dropTarget) {
|
|
363
|
+
this.setCurrentDropTarget(dropTarget, item);
|
|
364
|
+
this.drop(item);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
onPointerDown(e: PointerEvent): void {
|
|
370
|
+
// Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires
|
|
371
|
+
// so we can properly perform cancel and drop operations.
|
|
372
|
+
this.cancelEvent(e);
|
|
373
|
+
this.isVirtualClick = isVirtualPointerEvent(e);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
cancelEvent(e: Event): void {
|
|
377
|
+
// Allow focusin and focusout on the drag target so focus ring works properly.
|
|
378
|
+
let eventTarget = getEventTarget(e);
|
|
379
|
+
if (
|
|
380
|
+
(e.type === 'focusin' || e.type === 'focusout') &&
|
|
381
|
+
(eventTarget === this.dragTarget?.element || eventTarget === this.getCurrentActivateButton())
|
|
382
|
+
) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Allow default for events that might cancel a click event
|
|
387
|
+
if (!CLICK_EVENTS.includes(e.type)) {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
e.stopPropagation();
|
|
392
|
+
e.stopImmediatePropagation();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
updateValidDropTargets(): void {
|
|
396
|
+
if (!this.mutationObserver) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this.mutationObserver.disconnect();
|
|
401
|
+
if (this.restoreAriaHidden) {
|
|
402
|
+
this.restoreAriaHidden();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.validDropTargets = findValidDropTargets(this.dragTarget);
|
|
406
|
+
|
|
407
|
+
// Shuffle drop target order based on starting drag target.
|
|
408
|
+
if (this.validDropTargets.length > 0) {
|
|
409
|
+
let nearestIndex = this.findNearestDropTarget();
|
|
410
|
+
this.validDropTargets = [
|
|
411
|
+
...this.validDropTargets.slice(nearestIndex),
|
|
412
|
+
...this.validDropTargets.slice(0, nearestIndex),
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {
|
|
417
|
+
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Find valid drop items within collections
|
|
421
|
+
let types = getTypes(this.dragTarget.items);
|
|
422
|
+
let validDropItems = [...dropItems.values()].filter((item) => {
|
|
423
|
+
if (typeof item.getDropOperation === 'function') {
|
|
424
|
+
return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== 'cancel';
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return true;
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Filter out drop targets that contain valid items. We don't want to stop hiding elements
|
|
431
|
+
// other than the drop items that exist inside the collection.
|
|
432
|
+
let visibleDropTargets = this.validDropTargets.filter(
|
|
433
|
+
(target) => !validDropItems.some((item) => nodeContains(target.element, item.element)),
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
this.restoreAriaHidden = ariaHideOutside(
|
|
437
|
+
[
|
|
438
|
+
this.dragTarget.element,
|
|
439
|
+
...validDropItems.flatMap((item) =>
|
|
440
|
+
item.activateButtonRef?.current
|
|
441
|
+
? [item.element, item.activateButtonRef?.current]
|
|
442
|
+
: [item.element],
|
|
443
|
+
),
|
|
444
|
+
...visibleDropTargets.flatMap((target) =>
|
|
445
|
+
target.activateButtonRef?.current
|
|
446
|
+
? [target.element, target.activateButtonRef?.current]
|
|
447
|
+
: [target.element],
|
|
448
|
+
),
|
|
449
|
+
],
|
|
450
|
+
{ shouldUseInert: true },
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
this.mutationObserver.observe(document.body, {
|
|
454
|
+
subtree: true,
|
|
455
|
+
attributes: true,
|
|
456
|
+
attributeFilter: ['aria-hidden', 'inert'],
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
next(): void {
|
|
461
|
+
// TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.
|
|
462
|
+
// For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight
|
|
463
|
+
// is usable specifically by Tree. Will need tabbing for other components.
|
|
464
|
+
// let activateButton = this.getCurrentActivateButton();
|
|
465
|
+
// if (activateButton && document.activeElement !== activateButton) {
|
|
466
|
+
// activateButton.focus();
|
|
467
|
+
// return;
|
|
468
|
+
// }
|
|
469
|
+
|
|
470
|
+
if (!this.currentDropTarget) {
|
|
471
|
+
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let index = this.validDropTargets.indexOf(this.currentDropTarget);
|
|
476
|
+
if (index < 0) {
|
|
477
|
+
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// If we've reached the end of the valid drop targets, cycle back to the original drag target.
|
|
482
|
+
// This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).
|
|
483
|
+
if (index === this.validDropTargets.length - 1) {
|
|
484
|
+
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
485
|
+
this.setCurrentDropTarget(null);
|
|
486
|
+
this.dragTarget.element.focus();
|
|
487
|
+
} else {
|
|
488
|
+
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
this.setCurrentDropTarget(this.validDropTargets[index + 1]);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
previous(): void {
|
|
496
|
+
// let activateButton = this.getCurrentActivateButton();
|
|
497
|
+
// if (activateButton && document.activeElement === activateButton) {
|
|
498
|
+
// let target = this.currentDropItem ?? this.currentDropTarget;
|
|
499
|
+
// if (target) {
|
|
500
|
+
// target.element.focus();
|
|
501
|
+
// return;
|
|
502
|
+
// }
|
|
503
|
+
// }
|
|
504
|
+
|
|
505
|
+
if (!this.currentDropTarget) {
|
|
506
|
+
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
let index = this.validDropTargets.indexOf(this.currentDropTarget);
|
|
511
|
+
if (index < 0) {
|
|
512
|
+
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// If we've reached the start of the valid drop targets, cycle back to the original drag target.
|
|
517
|
+
// This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).
|
|
518
|
+
if (index === 0) {
|
|
519
|
+
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
520
|
+
this.setCurrentDropTarget(null);
|
|
521
|
+
this.dragTarget.element.focus();
|
|
522
|
+
} else {
|
|
523
|
+
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
this.setCurrentDropTarget(this.validDropTargets[index - 1]);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
findNearestDropTarget(): number {
|
|
531
|
+
let dragTargetRect = this.dragTarget.element.getBoundingClientRect();
|
|
532
|
+
|
|
533
|
+
let minDistance = Infinity;
|
|
534
|
+
let nearest = -1;
|
|
535
|
+
for (let i = 0; i < this.validDropTargets.length; i++) {
|
|
536
|
+
let dropTarget = this.validDropTargets[i];
|
|
537
|
+
let rect = dropTarget.element.getBoundingClientRect();
|
|
538
|
+
let dx = rect.left - dragTargetRect.left;
|
|
539
|
+
let dy = rect.top - dragTargetRect.top;
|
|
540
|
+
let dist = dx * dx + dy * dy;
|
|
541
|
+
if (dist < minDistance) {
|
|
542
|
+
minDistance = dist;
|
|
543
|
+
nearest = i;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return nearest;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {
|
|
551
|
+
if (dropTarget !== this.currentDropTarget) {
|
|
552
|
+
if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === 'function') {
|
|
553
|
+
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
554
|
+
this.currentDropTarget.onDropExit({
|
|
555
|
+
type: 'dropexit',
|
|
556
|
+
x: rect.left + rect.width / 2,
|
|
557
|
+
y: rect.top + rect.height / 2,
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
this.currentDropTarget = dropTarget;
|
|
562
|
+
|
|
563
|
+
if (dropTarget) {
|
|
564
|
+
if (typeof dropTarget.onDropEnter === 'function') {
|
|
565
|
+
let rect = dropTarget.element.getBoundingClientRect();
|
|
566
|
+
dropTarget.onDropEnter(
|
|
567
|
+
{
|
|
568
|
+
type: 'dropenter',
|
|
569
|
+
x: rect.left + rect.width / 2,
|
|
570
|
+
y: rect.top + rect.height / 2,
|
|
571
|
+
},
|
|
572
|
+
this.dragTarget,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (!item) {
|
|
577
|
+
dropTarget?.element.focus();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (item != null && item !== this.currentDropItem) {
|
|
583
|
+
if (
|
|
584
|
+
this.currentDropTarget &&
|
|
585
|
+
typeof this.currentDropTarget.onDropTargetEnter === 'function'
|
|
586
|
+
) {
|
|
587
|
+
this.currentDropTarget.onDropTargetEnter(item.target);
|
|
588
|
+
}
|
|
589
|
+
item.element.focus();
|
|
590
|
+
this.currentDropItem = item;
|
|
591
|
+
|
|
592
|
+
// Announce first drop target after drag start announcement finishes.
|
|
593
|
+
// Otherwise, it will never get announced because drag start announcement is assertive.
|
|
594
|
+
if (!this.initialFocused) {
|
|
595
|
+
let label = item?.element.getAttribute('aria-label');
|
|
596
|
+
if (label) {
|
|
597
|
+
announce(label, 'polite');
|
|
598
|
+
}
|
|
599
|
+
this.initialFocused = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
end(): void {
|
|
605
|
+
this.teardown();
|
|
606
|
+
endDragging();
|
|
607
|
+
|
|
608
|
+
if (typeof this.dragTarget.onDragEnd === 'function') {
|
|
609
|
+
let target =
|
|
610
|
+
this.currentDropTarget && this.dropOperation !== 'cancel'
|
|
611
|
+
? this.currentDropTarget
|
|
612
|
+
: this.dragTarget;
|
|
613
|
+
let rect = target.element.getBoundingClientRect();
|
|
614
|
+
this.dragTarget.onDragEnd({
|
|
615
|
+
type: 'dragend',
|
|
616
|
+
x: rect.x + rect.width / 2,
|
|
617
|
+
y: rect.y + rect.height / 2,
|
|
618
|
+
dropOperation: this.dropOperation || 'cancel',
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {
|
|
623
|
+
// Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).
|
|
624
|
+
// This corrects state such as whether focus ring should appear.
|
|
625
|
+
// useDroppableCollection handles this itself, so this is only for standalone drop zones.
|
|
626
|
+
getActiveElement()?.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
this.setCurrentDropTarget(null);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
cancel(): void {
|
|
633
|
+
this.setCurrentDropTarget(null);
|
|
634
|
+
this.end();
|
|
635
|
+
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
636
|
+
this.dragTarget.element.focus();
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).
|
|
640
|
+
getActiveElement()?.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
|
|
641
|
+
|
|
642
|
+
announce(this.stringFormatter.format('dropCanceled'));
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
drop(item?: DroppableItem): void {
|
|
646
|
+
if (!this.currentDropTarget) {
|
|
647
|
+
this.cancel();
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (typeof item?.getDropOperation === 'function') {
|
|
652
|
+
let types = getTypes(this.dragTarget.items);
|
|
653
|
+
this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);
|
|
654
|
+
} else if (typeof this.currentDropTarget.getDropOperation === 'function') {
|
|
655
|
+
let types = getTypes(this.dragTarget.items);
|
|
656
|
+
this.dropOperation = this.currentDropTarget.getDropOperation(
|
|
657
|
+
types,
|
|
658
|
+
this.dragTarget.allowedDropOperations,
|
|
659
|
+
);
|
|
660
|
+
} else {
|
|
661
|
+
// TODO: show menu ??
|
|
662
|
+
this.dropOperation = this.dragTarget.allowedDropOperations[0];
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (typeof this.currentDropTarget.onDrop === 'function') {
|
|
666
|
+
let items: DropItem[] = this.dragTarget.items.map((item) => ({
|
|
667
|
+
kind: 'text',
|
|
668
|
+
types: new Set(Object.keys(item)),
|
|
669
|
+
getText: (type: string) => Promise.resolve(item[type]),
|
|
670
|
+
}));
|
|
671
|
+
|
|
672
|
+
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
673
|
+
this.currentDropTarget.onDrop(
|
|
674
|
+
{
|
|
675
|
+
type: 'drop',
|
|
676
|
+
x: rect.left + rect.width / 2,
|
|
677
|
+
y: rect.top + rect.height / 2,
|
|
678
|
+
items,
|
|
679
|
+
dropOperation: this.dropOperation,
|
|
680
|
+
},
|
|
681
|
+
item?.target ?? null,
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
this.end();
|
|
686
|
+
announce(this.stringFormatter.format('dropComplete'));
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {
|
|
690
|
+
if (dropTarget && typeof dropTarget.onDropActivate === 'function') {
|
|
691
|
+
let target = dropItem?.target ?? null;
|
|
692
|
+
let rect = dropTarget.element.getBoundingClientRect();
|
|
693
|
+
dropTarget.onDropActivate(
|
|
694
|
+
{
|
|
695
|
+
type: 'dropactivate',
|
|
696
|
+
x: rect.left + rect.width / 2,
|
|
697
|
+
y: rect.top + rect.height / 2,
|
|
698
|
+
},
|
|
699
|
+
target,
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function findValidDropTargets(options: DragTarget) {
|
|
706
|
+
let types = getTypes(options.items);
|
|
707
|
+
return [...dropTargets.values()].filter((target) => {
|
|
708
|
+
if (target.element.closest('[aria-hidden="true"], [inert]')) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
if (typeof target.getDropOperation === 'function') {
|
|
713
|
+
return target.getDropOperation(types, options.allowedDropOperations) !== 'cancel';
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
return true;
|
|
717
|
+
});
|
|
718
|
+
}
|