@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,527 @@
|
|
|
1
|
+
/** @jsxImportSource octane */
|
|
2
|
+
// Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-stately/src/calendar/useCalendarState.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 {
|
|
16
|
+
alignCenter,
|
|
17
|
+
alignEnd,
|
|
18
|
+
alignStart,
|
|
19
|
+
constrainStart,
|
|
20
|
+
constrainValue,
|
|
21
|
+
isEqualDuration,
|
|
22
|
+
isInvalid,
|
|
23
|
+
previousAvailableDate,
|
|
24
|
+
} from './utils';
|
|
25
|
+
import {
|
|
26
|
+
Calendar,
|
|
27
|
+
CalendarDate,
|
|
28
|
+
CalendarIdentifier,
|
|
29
|
+
DateDuration,
|
|
30
|
+
DateFormatter,
|
|
31
|
+
endOfMonth,
|
|
32
|
+
endOfWeek,
|
|
33
|
+
getDayOfWeek,
|
|
34
|
+
getWeeksInMonth,
|
|
35
|
+
GregorianCalendar,
|
|
36
|
+
isEqualCalendar,
|
|
37
|
+
isSameDay,
|
|
38
|
+
startOfMonth,
|
|
39
|
+
startOfWeek,
|
|
40
|
+
toCalendar,
|
|
41
|
+
toCalendarDate,
|
|
42
|
+
today,
|
|
43
|
+
} from '@internationalized/date';
|
|
44
|
+
import {
|
|
45
|
+
CalendarPropsBase,
|
|
46
|
+
CalendarSelectionMode,
|
|
47
|
+
CalendarState,
|
|
48
|
+
CalendarValueType,
|
|
49
|
+
DateValue,
|
|
50
|
+
MappedDateValue,
|
|
51
|
+
} from './types';
|
|
52
|
+
import { useControlledState } from '../utils/useControlledState';
|
|
53
|
+
import { useMemo, useState } from '../../compat/react';
|
|
54
|
+
import { ValidationState, ValueBase } from '@react-types/shared';
|
|
55
|
+
|
|
56
|
+
export interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>
|
|
57
|
+
extends
|
|
58
|
+
CalendarPropsBase,
|
|
59
|
+
ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {
|
|
60
|
+
/**
|
|
61
|
+
* Whether single or multiple selection is enabled.
|
|
62
|
+
*
|
|
63
|
+
* @default 'single'
|
|
64
|
+
*/
|
|
65
|
+
selectionMode?: M;
|
|
66
|
+
/**
|
|
67
|
+
* Callback that is called for each date of the calendar. If it returns true, then the date is
|
|
68
|
+
* unavailable.
|
|
69
|
+
*/
|
|
70
|
+
isDateUnavailable?: (date: DateValue) => boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface CalendarStateOptions<
|
|
74
|
+
T extends DateValue = DateValue,
|
|
75
|
+
M extends CalendarSelectionMode = 'single',
|
|
76
|
+
> extends CalendarProps<T, M> {
|
|
77
|
+
/** The locale to display and edit the value according to. */
|
|
78
|
+
locale: string;
|
|
79
|
+
/**
|
|
80
|
+
* A function that creates a [Calendar](../internationalized/date/Calendar.html)
|
|
81
|
+
* object for a given calendar identifier. Such a function may be imported from the
|
|
82
|
+
* `@internationalized/date` package, or manually implemented to include support for
|
|
83
|
+
* only certain calendars.
|
|
84
|
+
*/
|
|
85
|
+
createCalendar: (name: CalendarIdentifier) => Calendar;
|
|
86
|
+
/**
|
|
87
|
+
* The amount of days that will be displayed at once. This affects how pagination works.
|
|
88
|
+
*
|
|
89
|
+
* @default { months: 1 }
|
|
90
|
+
*/
|
|
91
|
+
visibleDuration?: DateDuration;
|
|
92
|
+
/**
|
|
93
|
+
* Determines the alignment of the visible months on initial render based on the current selection
|
|
94
|
+
* or current date if there is no selection.
|
|
95
|
+
*
|
|
96
|
+
* @default 'center'
|
|
97
|
+
*/
|
|
98
|
+
selectionAlignment?: 'start' | 'center' | 'end';
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Provides state management for a calendar component.
|
|
102
|
+
* A calendar displays one or more date grids and allows users to select a single date.
|
|
103
|
+
*/
|
|
104
|
+
export function useCalendarState<
|
|
105
|
+
T extends DateValue = DateValue,
|
|
106
|
+
M extends CalendarSelectionMode = 'single',
|
|
107
|
+
>(props: CalendarStateOptions<T, M>): CalendarState<M> {
|
|
108
|
+
let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);
|
|
109
|
+
let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);
|
|
110
|
+
let {
|
|
111
|
+
locale,
|
|
112
|
+
createCalendar,
|
|
113
|
+
visibleDuration = { months: 1 },
|
|
114
|
+
minValue,
|
|
115
|
+
maxValue,
|
|
116
|
+
selectionAlignment,
|
|
117
|
+
isDateUnavailable,
|
|
118
|
+
pageBehavior = 'visible',
|
|
119
|
+
selectionMode = 'single' as M,
|
|
120
|
+
firstDayOfWeek,
|
|
121
|
+
weeksInMonth,
|
|
122
|
+
} = props;
|
|
123
|
+
let calendar = useMemo(
|
|
124
|
+
() => createCalendar(resolvedOptions.calendar as CalendarIdentifier),
|
|
125
|
+
[createCalendar, resolvedOptions.calendar],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
let [value, setControlledValue] = useControlledState<
|
|
129
|
+
T | T[] | null,
|
|
130
|
+
MappedDateValue<T> | MappedDateValue<T>[] | null
|
|
131
|
+
>(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);
|
|
132
|
+
let calendarDateValue = useMemo(() => {
|
|
133
|
+
if (Array.isArray(value)) {
|
|
134
|
+
return value.map((value) => toCalendar(toCalendarDate(value), calendar));
|
|
135
|
+
} else {
|
|
136
|
+
return value ? toCalendar(toCalendarDate(value), calendar) : null;
|
|
137
|
+
}
|
|
138
|
+
}, [value, calendar]);
|
|
139
|
+
let timeZone = useMemo(() => {
|
|
140
|
+
let val = Array.isArray(value) ? value[0] : value;
|
|
141
|
+
return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;
|
|
142
|
+
}, [value, resolvedOptions.timeZone]);
|
|
143
|
+
let focusedCalendarDate = useMemo(
|
|
144
|
+
() =>
|
|
145
|
+
props.focusedValue
|
|
146
|
+
? constrainValue(
|
|
147
|
+
toCalendar(toCalendarDate(props.focusedValue), calendar),
|
|
148
|
+
minValue,
|
|
149
|
+
maxValue,
|
|
150
|
+
)
|
|
151
|
+
: undefined,
|
|
152
|
+
[props.focusedValue, calendar, minValue, maxValue],
|
|
153
|
+
);
|
|
154
|
+
let defaultFocusedCalendarDate = useMemo(() => {
|
|
155
|
+
if (props.defaultFocusedValue) {
|
|
156
|
+
return constrainValue(
|
|
157
|
+
toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),
|
|
158
|
+
minValue,
|
|
159
|
+
maxValue,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (calendarDateValue) {
|
|
164
|
+
return constrainValue(
|
|
165
|
+
Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,
|
|
166
|
+
minValue,
|
|
167
|
+
maxValue,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);
|
|
172
|
+
}, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);
|
|
173
|
+
let [focusedDate, setFocusedDate] = useControlledState(
|
|
174
|
+
focusedCalendarDate,
|
|
175
|
+
defaultFocusedCalendarDate,
|
|
176
|
+
props.onFocusChange,
|
|
177
|
+
);
|
|
178
|
+
let getStartDate = () => {
|
|
179
|
+
switch (selectionAlignment) {
|
|
180
|
+
case 'start':
|
|
181
|
+
return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);
|
|
182
|
+
case 'end':
|
|
183
|
+
return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);
|
|
184
|
+
case 'center':
|
|
185
|
+
default:
|
|
186
|
+
return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
let [startDate, setStartDate] = useState(getStartDate);
|
|
191
|
+
let [isFocused, setFocused] = useState(props.autoFocus || false);
|
|
192
|
+
|
|
193
|
+
let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);
|
|
194
|
+
if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {
|
|
195
|
+
setLastVisibleDuration(visibleDuration);
|
|
196
|
+
setStartDate(getStartDate());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let endDate = useMemo(() => {
|
|
200
|
+
let duration = { ...visibleDuration };
|
|
201
|
+
if (duration.days) {
|
|
202
|
+
duration.days--;
|
|
203
|
+
} else {
|
|
204
|
+
duration.days = -1;
|
|
205
|
+
}
|
|
206
|
+
return startDate.add(duration);
|
|
207
|
+
}, [startDate, visibleDuration]);
|
|
208
|
+
|
|
209
|
+
// Reset focused date and visible range when calendar changes.
|
|
210
|
+
let [lastCalendar, setLastCalendar] = useState(calendar);
|
|
211
|
+
if (!isEqualCalendar(calendar, lastCalendar)) {
|
|
212
|
+
let newFocusedDate = toCalendar(focusedDate, calendar);
|
|
213
|
+
setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));
|
|
214
|
+
setFocusedDate(newFocusedDate);
|
|
215
|
+
setLastCalendar(calendar);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (isInvalid(focusedDate, minValue, maxValue)) {
|
|
219
|
+
// If the focused date was moved to an invalid value, it can't be focused, so constrain it.
|
|
220
|
+
setFocusedDate(constrainValue(focusedDate, minValue, maxValue));
|
|
221
|
+
} else if (focusedDate.compare(startDate) < 0) {
|
|
222
|
+
setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));
|
|
223
|
+
} else if (focusedDate.compare(endDate) > 0) {
|
|
224
|
+
setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Sets focus to a specific cell date
|
|
228
|
+
function focusCell(date: CalendarDate) {
|
|
229
|
+
date = constrainValue(date, minValue, maxValue);
|
|
230
|
+
setFocusedDate(date);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function normalizeValue(newValue: CalendarDate) {
|
|
234
|
+
let constrained = constrainValue(newValue, minValue, maxValue);
|
|
235
|
+
let prev = previousAvailableDate(constrained, startDate, isDateUnavailable);
|
|
236
|
+
if (!prev) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// The display calendar should not have any effect on the emitted value.
|
|
241
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
242
|
+
let baseValue = Array.isArray(value) ? value[0] : value;
|
|
243
|
+
let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());
|
|
244
|
+
|
|
245
|
+
// Preserve time if the input value had one.
|
|
246
|
+
if (baseValue && 'hour' in baseValue) {
|
|
247
|
+
return baseValue.set(calendarValue) as T;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return calendarValue as T;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function setValue(newValue: CalendarDate | CalendarDate[] | null) {
|
|
254
|
+
if (!props.isDisabled && !props.isReadOnly) {
|
|
255
|
+
if (newValue === null) {
|
|
256
|
+
setControlledValue(selectionMode === 'multiple' ? [] : null);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (Array.isArray(newValue)) {
|
|
261
|
+
setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);
|
|
262
|
+
} else {
|
|
263
|
+
let localValue = normalizeValue(newValue);
|
|
264
|
+
if (localValue) {
|
|
265
|
+
setControlledValue(localValue as any);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
let isUnavailable = useMemo(() => {
|
|
272
|
+
if (!calendarDateValue) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (Array.isArray(calendarDateValue)) {
|
|
277
|
+
return calendarDateValue.some(
|
|
278
|
+
(date) => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)
|
|
284
|
+
);
|
|
285
|
+
}, [calendarDateValue, isDateUnavailable, minValue, maxValue]);
|
|
286
|
+
let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;
|
|
287
|
+
let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;
|
|
288
|
+
|
|
289
|
+
let pageDuration = useMemo(() => {
|
|
290
|
+
if (pageBehavior === 'visible') {
|
|
291
|
+
return visibleDuration;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return unitDuration(visibleDuration);
|
|
295
|
+
}, [pageBehavior, visibleDuration]);
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
isDisabled: props.isDisabled ?? false,
|
|
299
|
+
isReadOnly: props.isReadOnly ?? false,
|
|
300
|
+
value: calendarDateValue as any,
|
|
301
|
+
setValue: setValue as any,
|
|
302
|
+
selectionMode,
|
|
303
|
+
visibleDuration,
|
|
304
|
+
visibleRange: {
|
|
305
|
+
start: startDate,
|
|
306
|
+
end: endDate,
|
|
307
|
+
},
|
|
308
|
+
minValue,
|
|
309
|
+
maxValue,
|
|
310
|
+
focusedDate,
|
|
311
|
+
timeZone,
|
|
312
|
+
validationState,
|
|
313
|
+
isValueInvalid,
|
|
314
|
+
setFocusedDate(date) {
|
|
315
|
+
focusCell(date);
|
|
316
|
+
},
|
|
317
|
+
focusNextDay() {
|
|
318
|
+
focusCell(focusedDate.add({ days: 1 }));
|
|
319
|
+
},
|
|
320
|
+
focusPreviousDay() {
|
|
321
|
+
focusCell(focusedDate.subtract({ days: 1 }));
|
|
322
|
+
},
|
|
323
|
+
focusNextRow() {
|
|
324
|
+
if (visibleDuration.days) {
|
|
325
|
+
this.focusNextPage();
|
|
326
|
+
} else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
327
|
+
focusCell(focusedDate.add({ weeks: 1 }));
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
focusPreviousRow() {
|
|
331
|
+
if (visibleDuration.days) {
|
|
332
|
+
this.focusPreviousPage();
|
|
333
|
+
} else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {
|
|
334
|
+
focusCell(focusedDate.subtract({ weeks: 1 }));
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
focusNextPage() {
|
|
338
|
+
let start = startDate.add(pageDuration);
|
|
339
|
+
setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));
|
|
340
|
+
setStartDate(
|
|
341
|
+
alignStart(
|
|
342
|
+
constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),
|
|
343
|
+
pageDuration,
|
|
344
|
+
locale,
|
|
345
|
+
),
|
|
346
|
+
);
|
|
347
|
+
},
|
|
348
|
+
focusPreviousPage() {
|
|
349
|
+
let start = startDate.subtract(pageDuration);
|
|
350
|
+
setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));
|
|
351
|
+
setStartDate(
|
|
352
|
+
alignStart(
|
|
353
|
+
constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),
|
|
354
|
+
pageDuration,
|
|
355
|
+
locale,
|
|
356
|
+
),
|
|
357
|
+
);
|
|
358
|
+
},
|
|
359
|
+
focusSectionStart() {
|
|
360
|
+
if (visibleDuration.days) {
|
|
361
|
+
focusCell(startDate);
|
|
362
|
+
} else if (visibleDuration.weeks) {
|
|
363
|
+
focusCell(startOfWeek(focusedDate, locale));
|
|
364
|
+
} else if (visibleDuration.months || visibleDuration.years) {
|
|
365
|
+
focusCell(startOfMonth(focusedDate));
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
focusSectionEnd() {
|
|
369
|
+
if (visibleDuration.days) {
|
|
370
|
+
focusCell(endDate);
|
|
371
|
+
} else if (visibleDuration.weeks) {
|
|
372
|
+
focusCell(endOfWeek(focusedDate, locale));
|
|
373
|
+
} else if (visibleDuration.months || visibleDuration.years) {
|
|
374
|
+
focusCell(endOfMonth(focusedDate));
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
focusNextSection(larger) {
|
|
378
|
+
if (!larger && !visibleDuration.days) {
|
|
379
|
+
focusCell(focusedDate.add(unitDuration(visibleDuration)));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (visibleDuration.days) {
|
|
384
|
+
this.focusNextPage();
|
|
385
|
+
} else if (visibleDuration.weeks) {
|
|
386
|
+
focusCell(focusedDate.add({ months: 1 }));
|
|
387
|
+
} else if (visibleDuration.months || visibleDuration.years) {
|
|
388
|
+
focusCell(focusedDate.add({ years: 1 }));
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
focusPreviousSection(larger) {
|
|
392
|
+
if (!larger && !visibleDuration.days) {
|
|
393
|
+
focusCell(focusedDate.subtract(unitDuration(visibleDuration)));
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (visibleDuration.days) {
|
|
398
|
+
this.focusPreviousPage();
|
|
399
|
+
} else if (visibleDuration.weeks) {
|
|
400
|
+
focusCell(focusedDate.subtract({ months: 1 }));
|
|
401
|
+
} else if (visibleDuration.months || visibleDuration.years) {
|
|
402
|
+
focusCell(focusedDate.subtract({ years: 1 }));
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
selectFocusedDate() {
|
|
406
|
+
if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {
|
|
407
|
+
this.selectDate(focusedDate);
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
selectDate(date) {
|
|
411
|
+
if (props.isDisabled || props.isReadOnly) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (selectionMode === 'multiple' && date != null) {
|
|
416
|
+
let newDate = normalizeValue(date);
|
|
417
|
+
if (!newDate) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let baseValue: T[] = [];
|
|
422
|
+
if (Array.isArray(value)) {
|
|
423
|
+
baseValue = value;
|
|
424
|
+
} else if (value != null) {
|
|
425
|
+
baseValue = [value];
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
let index = baseValue.findIndex((value) => isSameDay(value, newDate));
|
|
429
|
+
let newValue =
|
|
430
|
+
index >= 0
|
|
431
|
+
? baseValue.slice(0, index).concat(baseValue.slice(index + 1))
|
|
432
|
+
: [...baseValue, newDate];
|
|
433
|
+
setControlledValue(newValue);
|
|
434
|
+
} else {
|
|
435
|
+
setValue(date);
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
isFocused,
|
|
439
|
+
setFocused,
|
|
440
|
+
isInvalid(date) {
|
|
441
|
+
return isInvalid(date, minValue, maxValue);
|
|
442
|
+
},
|
|
443
|
+
isSelected(date) {
|
|
444
|
+
if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
return Array.isArray(calendarDateValue)
|
|
448
|
+
? calendarDateValue.some((value) => isSameDay(value, date))
|
|
449
|
+
: isSameDay(date, calendarDateValue);
|
|
450
|
+
},
|
|
451
|
+
isCellFocused(date) {
|
|
452
|
+
return isFocused && focusedDate && isSameDay(date, focusedDate);
|
|
453
|
+
},
|
|
454
|
+
isCellDisabled(date) {
|
|
455
|
+
return (
|
|
456
|
+
props.isDisabled ||
|
|
457
|
+
date.compare(startDate) < 0 ||
|
|
458
|
+
date.compare(endDate) > 0 ||
|
|
459
|
+
this.isInvalid(date)
|
|
460
|
+
);
|
|
461
|
+
},
|
|
462
|
+
isCellUnavailable(date) {
|
|
463
|
+
return props.isDateUnavailable ? props.isDateUnavailable(date) : false;
|
|
464
|
+
},
|
|
465
|
+
isPreviousVisibleRangeInvalid() {
|
|
466
|
+
let prev = startDate.subtract({ days: 1 });
|
|
467
|
+
return isSameDay(prev, startDate) || this.isInvalid(prev);
|
|
468
|
+
},
|
|
469
|
+
isNextVisibleRangeInvalid() {
|
|
470
|
+
// Adding may return the same date if we reached the end of time
|
|
471
|
+
// according to the calendar system (e.g. 9999-12-31).
|
|
472
|
+
let next = endDate.add({ days: 1 });
|
|
473
|
+
return isSameDay(next, endDate) || this.isInvalid(next);
|
|
474
|
+
},
|
|
475
|
+
getDatesInWeek(weekIndex, from = startDate) {
|
|
476
|
+
let date = from.add({ weeks: weekIndex });
|
|
477
|
+
let dates: (CalendarDate | null)[] = [];
|
|
478
|
+
|
|
479
|
+
let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;
|
|
480
|
+
if (days === 7) {
|
|
481
|
+
date = startOfWeek(date, locale, firstDayOfWeek);
|
|
482
|
+
|
|
483
|
+
// startOfWeek will clamp dates within the calendar system's valid range, which may
|
|
484
|
+
// start in the middle of a week. In this case, add null placeholders.
|
|
485
|
+
let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);
|
|
486
|
+
for (let i = 0; i < dayOfWeek; i++) {
|
|
487
|
+
dates.push(null);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
while (dates.length < days) {
|
|
492
|
+
dates.push(date);
|
|
493
|
+
let nextDate = date.add({ days: 1 });
|
|
494
|
+
if (isSameDay(date, nextDate)) {
|
|
495
|
+
// If the next day is the same, we have hit the end of the calendar system.
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
date = nextDate;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Add null placeholders if at the end of the calendar system.
|
|
502
|
+
while (dates.length < days) {
|
|
503
|
+
dates.push(null);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return dates;
|
|
507
|
+
},
|
|
508
|
+
getWeeksInMonth(date = startDate) {
|
|
509
|
+
let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);
|
|
510
|
+
if (visibleDuration.weeks || visibleDuration.days) {
|
|
511
|
+
weeks = visibleDuration.weeks ?? 0;
|
|
512
|
+
if (visibleDuration.days) {
|
|
513
|
+
weeks += Math.ceil(visibleDuration.days / 7);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return weeks;
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function unitDuration(duration: DateDuration) {
|
|
522
|
+
let unit = { ...duration };
|
|
523
|
+
for (let key in duration) {
|
|
524
|
+
(unit as Record<string, number | undefined>)[key] = 1;
|
|
525
|
+
}
|
|
526
|
+
return unit;
|
|
527
|
+
}
|