react-stately 3.46.0 → 3.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/Color.cjs.map +1 -1
- package/dist/exports/Color.js.map +1 -1
- package/dist/exports/Color.mjs.map +1 -1
- package/dist/exports/index.cjs.map +1 -1
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.cjs.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.js.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.mjs.map +1 -1
- package/dist/exports/private/collections/getChildNodes.cjs.map +1 -1
- package/dist/exports/private/collections/getChildNodes.js.map +1 -1
- package/dist/exports/private/collections/getChildNodes.mjs.map +1 -1
- package/dist/exports/private/flags/flags.cjs.map +1 -1
- package/dist/exports/private/flags/flags.js.map +1 -1
- package/dist/exports/private/flags/flags.mjs.map +1 -1
- package/dist/exports/private/form/useFormValidationState.cjs.map +1 -1
- package/dist/exports/private/form/useFormValidationState.js.map +1 -1
- package/dist/exports/private/form/useFormValidationState.mjs.map +1 -1
- package/dist/exports/private/grid/GridCollection.cjs.map +1 -1
- package/dist/exports/private/grid/GridCollection.js.map +1 -1
- package/dist/exports/private/grid/GridCollection.mjs.map +1 -1
- package/dist/exports/private/steplist/useStepListState.cjs.map +1 -1
- package/dist/exports/private/steplist/useStepListState.js.map +1 -1
- package/dist/exports/private/steplist/useStepListState.mjs.map +1 -1
- package/dist/exports/private/table/TableCollection.cjs.map +1 -1
- package/dist/exports/private/table/TableCollection.js.map +1 -1
- package/dist/exports/private/table/TableCollection.mjs.map +1 -1
- package/dist/exports/private/table/useTreeGridState.cjs.map +1 -1
- package/dist/exports/private/table/useTreeGridState.js.map +1 -1
- package/dist/exports/private/table/useTreeGridState.mjs.map +1 -1
- package/dist/exports/useAsyncList.cjs.map +1 -1
- package/dist/exports/useAsyncList.js.map +1 -1
- package/dist/exports/useAsyncList.mjs.map +1 -1
- package/dist/exports/useCalendarState.cjs.map +1 -1
- package/dist/exports/useCalendarState.js.map +1 -1
- package/dist/exports/useCalendarState.mjs.map +1 -1
- package/dist/exports/useColorAreaState.cjs.map +1 -1
- package/dist/exports/useColorAreaState.js.map +1 -1
- package/dist/exports/useColorAreaState.mjs.map +1 -1
- package/dist/exports/useColorFieldState.cjs.map +1 -1
- package/dist/exports/useColorFieldState.js.map +1 -1
- package/dist/exports/useColorFieldState.mjs.map +1 -1
- package/dist/exports/useColorPickerState.cjs.map +1 -1
- package/dist/exports/useColorPickerState.js.map +1 -1
- package/dist/exports/useColorPickerState.mjs.map +1 -1
- package/dist/exports/useColorSliderState.cjs.map +1 -1
- package/dist/exports/useColorSliderState.js.map +1 -1
- package/dist/exports/useColorSliderState.mjs.map +1 -1
- package/dist/exports/useColorWheelState.cjs.map +1 -1
- package/dist/exports/useColorWheelState.js.map +1 -1
- package/dist/exports/useColorWheelState.mjs.map +1 -1
- package/dist/exports/useComboBoxState.cjs +1 -1
- package/dist/exports/useComboBoxState.cjs.map +1 -1
- package/dist/exports/useComboBoxState.js +1 -1
- package/dist/exports/useComboBoxState.js.map +1 -1
- package/dist/exports/useComboBoxState.mjs +1 -1
- package/dist/exports/useComboBoxState.mjs.map +1 -1
- package/dist/exports/useDateFieldState.cjs.map +1 -1
- package/dist/exports/useDateFieldState.js.map +1 -1
- package/dist/exports/useDateFieldState.mjs.map +1 -1
- package/dist/exports/useDatePickerState.cjs.map +1 -1
- package/dist/exports/useDatePickerState.js.map +1 -1
- package/dist/exports/useDatePickerState.mjs.map +1 -1
- package/dist/exports/useDateRangePickerState.cjs.map +1 -1
- package/dist/exports/useDateRangePickerState.js.map +1 -1
- package/dist/exports/useDateRangePickerState.mjs.map +1 -1
- package/dist/exports/useDisclosureGroupState.cjs.map +1 -1
- package/dist/exports/useDisclosureGroupState.js.map +1 -1
- package/dist/exports/useDisclosureGroupState.mjs.map +1 -1
- package/dist/exports/useDraggableCollectionState.cjs.map +1 -1
- package/dist/exports/useDraggableCollectionState.js.map +1 -1
- package/dist/exports/useDraggableCollectionState.mjs.map +1 -1
- package/dist/exports/useDroppableCollectionState.cjs.map +1 -1
- package/dist/exports/useDroppableCollectionState.js.map +1 -1
- package/dist/exports/useDroppableCollectionState.mjs.map +1 -1
- package/dist/exports/useMenuTriggerState.cjs.map +1 -1
- package/dist/exports/useMenuTriggerState.js.map +1 -1
- package/dist/exports/useMenuTriggerState.mjs.map +1 -1
- package/dist/exports/useMultipleSelectionState.cjs.map +1 -1
- package/dist/exports/useMultipleSelectionState.js.map +1 -1
- package/dist/exports/useMultipleSelectionState.mjs.map +1 -1
- package/dist/exports/useOverlayTriggerState.cjs.map +1 -1
- package/dist/exports/useOverlayTriggerState.js.map +1 -1
- package/dist/exports/useOverlayTriggerState.mjs.map +1 -1
- package/dist/exports/useRangeCalendarState.cjs.map +1 -1
- package/dist/exports/useRangeCalendarState.js.map +1 -1
- package/dist/exports/useRangeCalendarState.mjs.map +1 -1
- package/dist/exports/useSelectState.cjs.map +1 -1
- package/dist/exports/useSelectState.js.map +1 -1
- package/dist/exports/useSelectState.mjs.map +1 -1
- package/dist/exports/useSingleSelectListState.cjs.map +1 -1
- package/dist/exports/useSingleSelectListState.js.map +1 -1
- package/dist/exports/useSingleSelectListState.mjs.map +1 -1
- package/dist/exports/useTableState.cjs.map +1 -1
- package/dist/exports/useTableState.js.map +1 -1
- package/dist/exports/useTableState.mjs.map +1 -1
- package/dist/exports/useTimeFieldState.cjs.map +1 -1
- package/dist/exports/useTimeFieldState.js.map +1 -1
- package/dist/exports/useTimeFieldState.mjs.map +1 -1
- package/dist/exports/useToastState.cjs.map +1 -1
- package/dist/exports/useToastState.js.map +1 -1
- package/dist/exports/useToastState.mjs.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.cjs.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.js.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.mjs.map +1 -1
- package/dist/private/calendar/useCalendarState.cjs +82 -30
- package/dist/private/calendar/useCalendarState.cjs.map +1 -1
- package/dist/private/calendar/useCalendarState.js +85 -32
- package/dist/private/calendar/useCalendarState.js.map +1 -1
- package/dist/private/calendar/useCalendarState.mjs +84 -32
- package/dist/private/calendar/useCalendarState.mjs.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.cjs +53 -40
- package/dist/private/calendar/useRangeCalendarState.cjs.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.js +55 -43
- package/dist/private/calendar/useRangeCalendarState.js.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.mjs +55 -42
- package/dist/private/calendar/useRangeCalendarState.mjs.map +1 -1
- package/dist/private/calendar/utils.cjs +6 -1
- package/dist/private/calendar/utils.cjs.map +1 -1
- package/dist/private/calendar/utils.js +6 -2
- package/dist/private/calendar/utils.js.map +1 -1
- package/dist/private/calendar/utils.mjs +6 -2
- package/dist/private/calendar/utils.mjs.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.cjs.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.js.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.mjs.map +1 -1
- package/dist/private/collections/CollectionBuilder.cjs.map +1 -1
- package/dist/private/collections/CollectionBuilder.js.map +1 -1
- package/dist/private/collections/CollectionBuilder.mjs.map +1 -1
- package/dist/private/collections/Item.cjs +1 -0
- package/dist/private/collections/Item.cjs.map +1 -1
- package/dist/private/collections/Item.js +1 -0
- package/dist/private/collections/Item.js.map +1 -1
- package/dist/private/collections/Item.mjs +1 -0
- package/dist/private/collections/Item.mjs.map +1 -1
- package/dist/private/collections/Section.cjs +1 -0
- package/dist/private/collections/Section.cjs.map +1 -1
- package/dist/private/collections/Section.js +1 -0
- package/dist/private/collections/Section.js.map +1 -1
- package/dist/private/collections/Section.mjs +1 -0
- package/dist/private/collections/Section.mjs.map +1 -1
- package/dist/private/collections/getChildNodes.cjs.map +1 -1
- package/dist/private/collections/getChildNodes.js.map +1 -1
- package/dist/private/collections/getChildNodes.mjs.map +1 -1
- package/dist/private/collections/useCollection.cjs.map +1 -1
- package/dist/private/collections/useCollection.js.map +1 -1
- package/dist/private/collections/useCollection.mjs.map +1 -1
- package/dist/private/color/Color.cjs +15 -9
- package/dist/private/color/Color.cjs.map +1 -1
- package/dist/private/color/Color.js +15 -9
- package/dist/private/color/Color.js.map +1 -1
- package/dist/private/color/Color.mjs +15 -9
- package/dist/private/color/Color.mjs.map +1 -1
- package/dist/private/color/useColorAreaState.cjs.map +1 -1
- package/dist/private/color/useColorAreaState.js.map +1 -1
- package/dist/private/color/useColorAreaState.mjs.map +1 -1
- package/dist/private/color/useColorChannelFieldState.cjs.map +1 -1
- package/dist/private/color/useColorChannelFieldState.js.map +1 -1
- package/dist/private/color/useColorChannelFieldState.mjs.map +1 -1
- package/dist/private/color/useColorFieldState.cjs.map +1 -1
- package/dist/private/color/useColorFieldState.js.map +1 -1
- package/dist/private/color/useColorFieldState.mjs.map +1 -1
- package/dist/private/color/useColorPickerState.cjs.map +1 -1
- package/dist/private/color/useColorPickerState.js.map +1 -1
- package/dist/private/color/useColorPickerState.mjs.map +1 -1
- package/dist/private/color/useColorSliderState.cjs +5 -3
- package/dist/private/color/useColorSliderState.cjs.map +1 -1
- package/dist/private/color/useColorSliderState.js +5 -3
- package/dist/private/color/useColorSliderState.js.map +1 -1
- package/dist/private/color/useColorSliderState.mjs +5 -3
- package/dist/private/color/useColorSliderState.mjs.map +1 -1
- package/dist/private/color/useColorWheelState.cjs.map +1 -1
- package/dist/private/color/useColorWheelState.js.map +1 -1
- package/dist/private/color/useColorWheelState.mjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.cjs +8 -2
- package/dist/private/combobox/useComboBoxState.cjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.js +8 -2
- package/dist/private/combobox/useComboBoxState.js.map +1 -1
- package/dist/private/combobox/useComboBoxState.mjs +8 -2
- package/dist/private/combobox/useComboBoxState.mjs.map +1 -1
- package/dist/private/data/useAsyncList.cjs.map +1 -1
- package/dist/private/data/useAsyncList.js.map +1 -1
- package/dist/private/data/useAsyncList.mjs.map +1 -1
- package/dist/private/data/useListData.cjs.map +1 -1
- package/dist/private/data/useListData.js.map +1 -1
- package/dist/private/data/useListData.mjs.map +1 -1
- package/dist/private/data/useTreeData.cjs.map +1 -1
- package/dist/private/data/useTreeData.js.map +1 -1
- package/dist/private/data/useTreeData.mjs.map +1 -1
- package/dist/private/datepicker/IncompleteDate.cjs +8 -2
- package/dist/private/datepicker/IncompleteDate.cjs.map +1 -1
- package/dist/private/datepicker/IncompleteDate.js +8 -2
- package/dist/private/datepicker/IncompleteDate.js.map +1 -1
- package/dist/private/datepicker/IncompleteDate.mjs +8 -2
- package/dist/private/datepicker/IncompleteDate.mjs.map +1 -1
- package/dist/private/datepicker/placeholders.cjs +5 -0
- package/dist/private/datepicker/placeholders.cjs.map +1 -1
- package/dist/private/datepicker/placeholders.js +5 -0
- package/dist/private/datepicker/placeholders.js.map +1 -1
- package/dist/private/datepicker/placeholders.mjs +5 -0
- package/dist/private/datepicker/placeholders.mjs.map +1 -1
- package/dist/private/datepicker/useDateFieldState.cjs.map +1 -1
- package/dist/private/datepicker/useDateFieldState.js.map +1 -1
- package/dist/private/datepicker/useDateFieldState.mjs.map +1 -1
- package/dist/private/datepicker/useDatePickerState.cjs.map +1 -1
- package/dist/private/datepicker/useDatePickerState.js.map +1 -1
- package/dist/private/datepicker/useDatePickerState.mjs.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.cjs +1 -1
- package/dist/private/datepicker/useDateRangePickerState.cjs.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.js +1 -1
- package/dist/private/datepicker/useDateRangePickerState.js.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.mjs +1 -1
- package/dist/private/datepicker/useDateRangePickerState.mjs.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.cjs.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.js.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.mjs.map +1 -1
- package/dist/private/datepicker/utils.cjs +2 -2
- package/dist/private/datepicker/utils.cjs.map +1 -1
- package/dist/private/datepicker/utils.js +2 -2
- package/dist/private/datepicker/utils.js.map +1 -1
- package/dist/private/datepicker/utils.mjs +2 -2
- package/dist/private/datepicker/utils.mjs.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.cjs.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.js.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.mjs.map +1 -1
- package/dist/private/disclosure/useDisclosureState.cjs.map +1 -1
- package/dist/private/disclosure/useDisclosureState.js.map +1 -1
- package/dist/private/disclosure/useDisclosureState.mjs.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.cjs.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.js.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.mjs.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.cjs.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.js.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.mjs.map +1 -1
- package/dist/private/form/useFormValidationState.cjs.map +1 -1
- package/dist/private/form/useFormValidationState.js.map +1 -1
- package/dist/private/form/useFormValidationState.mjs.map +1 -1
- package/dist/private/grid/GridCollection.cjs.map +1 -1
- package/dist/private/grid/GridCollection.js.map +1 -1
- package/dist/private/grid/GridCollection.mjs.map +1 -1
- package/dist/private/grid/useGridState.cjs.map +1 -1
- package/dist/private/grid/useGridState.js.map +1 -1
- package/dist/private/grid/useGridState.mjs.map +1 -1
- package/dist/private/layout/GridLayout.cjs +8 -3
- package/dist/private/layout/GridLayout.cjs.map +1 -1
- package/dist/private/layout/GridLayout.js +8 -3
- package/dist/private/layout/GridLayout.js.map +1 -1
- package/dist/private/layout/GridLayout.mjs +8 -3
- package/dist/private/layout/GridLayout.mjs.map +1 -1
- package/dist/private/layout/ListLayout.cjs +1 -1
- package/dist/private/layout/ListLayout.cjs.map +1 -1
- package/dist/private/layout/ListLayout.js +2 -1
- package/dist/private/layout/ListLayout.js.map +1 -1
- package/dist/private/layout/ListLayout.mjs +1 -1
- package/dist/private/layout/ListLayout.mjs.map +1 -1
- package/dist/private/layout/TableLayout.cjs +60 -35
- package/dist/private/layout/TableLayout.cjs.map +1 -1
- package/dist/private/layout/TableLayout.js +65 -38
- package/dist/private/layout/TableLayout.js.map +1 -1
- package/dist/private/layout/TableLayout.mjs +61 -36
- package/dist/private/layout/TableLayout.mjs.map +1 -1
- package/dist/private/layout/WaterfallLayout.cjs.map +1 -1
- package/dist/private/layout/WaterfallLayout.js.map +1 -1
- package/dist/private/layout/WaterfallLayout.mjs.map +1 -1
- package/dist/private/list/ListCollection.cjs.map +1 -1
- package/dist/private/list/ListCollection.js.map +1 -1
- package/dist/private/list/ListCollection.mjs.map +1 -1
- package/dist/private/list/useListState.cjs.map +1 -1
- package/dist/private/list/useListState.js.map +1 -1
- package/dist/private/list/useListState.mjs.map +1 -1
- package/dist/private/list/useSingleSelectListState.cjs.map +1 -1
- package/dist/private/list/useSingleSelectListState.js.map +1 -1
- package/dist/private/list/useSingleSelectListState.mjs.map +1 -1
- package/dist/private/menu/useMenuTriggerState.cjs.map +1 -1
- package/dist/private/menu/useMenuTriggerState.js.map +1 -1
- package/dist/private/menu/useMenuTriggerState.mjs.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.cjs.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.js.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.mjs.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.cjs +13 -1
- package/dist/private/numberfield/useNumberFieldState.cjs.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.js +13 -1
- package/dist/private/numberfield/useNumberFieldState.js.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.mjs +13 -1
- package/dist/private/numberfield/useNumberFieldState.mjs.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.cjs.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.js.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.mjs.map +1 -1
- package/dist/private/radio/useRadioGroupState.cjs.map +1 -1
- package/dist/private/radio/useRadioGroupState.js.map +1 -1
- package/dist/private/radio/useRadioGroupState.mjs.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.cjs.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.js.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.mjs.map +1 -1
- package/dist/private/select/useSelectState.cjs.map +1 -1
- package/dist/private/select/useSelectState.js.map +1 -1
- package/dist/private/select/useSelectState.mjs.map +1 -1
- package/dist/private/selection/SelectionManager.cjs +2 -1
- package/dist/private/selection/SelectionManager.cjs.map +1 -1
- package/dist/private/selection/SelectionManager.js +3 -2
- package/dist/private/selection/SelectionManager.js.map +1 -1
- package/dist/private/selection/SelectionManager.mjs +2 -1
- package/dist/private/selection/SelectionManager.mjs.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.cjs.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.js.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.mjs.map +1 -1
- package/dist/private/slider/useSliderState.cjs +22 -2
- package/dist/private/slider/useSliderState.cjs.map +1 -1
- package/dist/private/slider/useSliderState.js +22 -2
- package/dist/private/slider/useSliderState.js.map +1 -1
- package/dist/private/slider/useSliderState.mjs +22 -2
- package/dist/private/slider/useSliderState.mjs.map +1 -1
- package/dist/private/steplist/useStepListState.cjs.map +1 -1
- package/dist/private/steplist/useStepListState.js.map +1 -1
- package/dist/private/steplist/useStepListState.mjs.map +1 -1
- package/dist/private/table/Cell.cjs +2 -1
- package/dist/private/table/Cell.cjs.map +1 -1
- package/dist/private/table/Cell.js +2 -1
- package/dist/private/table/Cell.js.map +1 -1
- package/dist/private/table/Cell.mjs +2 -1
- package/dist/private/table/Cell.mjs.map +1 -1
- package/dist/private/table/Column.cjs +1 -0
- package/dist/private/table/Column.cjs.map +1 -1
- package/dist/private/table/Column.js +1 -0
- package/dist/private/table/Column.js.map +1 -1
- package/dist/private/table/Column.mjs +1 -0
- package/dist/private/table/Column.mjs.map +1 -1
- package/dist/private/table/Row.cjs +2 -1
- package/dist/private/table/Row.cjs.map +1 -1
- package/dist/private/table/Row.js +2 -1
- package/dist/private/table/Row.js.map +1 -1
- package/dist/private/table/Row.mjs +2 -1
- package/dist/private/table/Row.mjs.map +1 -1
- package/dist/private/table/TableBody.cjs +4 -2
- package/dist/private/table/TableBody.cjs.map +1 -1
- package/dist/private/table/TableBody.js +4 -2
- package/dist/private/table/TableBody.js.map +1 -1
- package/dist/private/table/TableBody.mjs +4 -2
- package/dist/private/table/TableBody.mjs.map +1 -1
- package/dist/private/table/TableCollection.cjs +1 -1
- package/dist/private/table/TableCollection.cjs.map +1 -1
- package/dist/private/table/TableCollection.js +1 -1
- package/dist/private/table/TableCollection.js.map +1 -1
- package/dist/private/table/TableCollection.mjs +1 -1
- package/dist/private/table/TableCollection.mjs.map +1 -1
- package/dist/private/table/TableColumnLayout.cjs +4 -1
- package/dist/private/table/TableColumnLayout.cjs.map +1 -1
- package/dist/private/table/TableColumnLayout.js +4 -1
- package/dist/private/table/TableColumnLayout.js.map +1 -1
- package/dist/private/table/TableColumnLayout.mjs +4 -1
- package/dist/private/table/TableColumnLayout.mjs.map +1 -1
- package/dist/private/table/TableHeader.cjs +4 -2
- package/dist/private/table/TableHeader.cjs.map +1 -1
- package/dist/private/table/TableHeader.js +4 -2
- package/dist/private/table/TableHeader.js.map +1 -1
- package/dist/private/table/TableHeader.mjs +4 -2
- package/dist/private/table/TableHeader.mjs.map +1 -1
- package/dist/private/table/TableUtils.cjs +1 -1
- package/dist/private/table/TableUtils.cjs.map +1 -1
- package/dist/private/table/TableUtils.js +1 -1
- package/dist/private/table/TableUtils.js.map +1 -1
- package/dist/private/table/TableUtils.mjs +1 -1
- package/dist/private/table/TableUtils.mjs.map +1 -1
- package/dist/private/table/useTableColumnResizeState.cjs.map +1 -1
- package/dist/private/table/useTableColumnResizeState.js.map +1 -1
- package/dist/private/table/useTableColumnResizeState.mjs.map +1 -1
- package/dist/private/table/useTableState.cjs +2 -1
- package/dist/private/table/useTableState.cjs.map +1 -1
- package/dist/private/table/useTableState.js +2 -1
- package/dist/private/table/useTableState.js.map +1 -1
- package/dist/private/table/useTableState.mjs +2 -1
- package/dist/private/table/useTableState.mjs.map +1 -1
- package/dist/private/table/useTreeGridState.cjs +2 -1
- package/dist/private/table/useTreeGridState.cjs.map +1 -1
- package/dist/private/table/useTreeGridState.js +2 -1
- package/dist/private/table/useTreeGridState.js.map +1 -1
- package/dist/private/table/useTreeGridState.mjs +2 -1
- package/dist/private/table/useTreeGridState.mjs.map +1 -1
- package/dist/private/tabs/useTabListState.cjs.map +1 -1
- package/dist/private/tabs/useTabListState.js.map +1 -1
- package/dist/private/tabs/useTabListState.mjs.map +1 -1
- package/dist/private/toast/useToastState.cjs.map +1 -1
- package/dist/private/toast/useToastState.js.map +1 -1
- package/dist/private/toast/useToastState.mjs.map +1 -1
- package/dist/private/toggle/useToggleGroupState.cjs.map +1 -1
- package/dist/private/toggle/useToggleGroupState.js.map +1 -1
- package/dist/private/toggle/useToggleGroupState.mjs.map +1 -1
- package/dist/private/toggle/useToggleState.cjs.map +1 -1
- package/dist/private/toggle/useToggleState.js.map +1 -1
- package/dist/private/toggle/useToggleState.mjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.cjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.js.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.mjs.map +1 -1
- package/dist/private/tree/TreeCollection.cjs.map +1 -1
- package/dist/private/tree/TreeCollection.js.map +1 -1
- package/dist/private/tree/TreeCollection.mjs.map +1 -1
- package/dist/private/tree/useTreeState.cjs.map +1 -1
- package/dist/private/tree/useTreeState.js.map +1 -1
- package/dist/private/tree/useTreeState.mjs.map +1 -1
- package/dist/private/utils/number.cjs +2 -1
- package/dist/private/utils/number.cjs.map +1 -1
- package/dist/private/utils/number.js +2 -1
- package/dist/private/utils/number.js.map +1 -1
- package/dist/private/utils/number.mjs +2 -1
- package/dist/private/utils/number.mjs.map +1 -1
- package/dist/private/utils/useControlledState.cjs.map +1 -1
- package/dist/private/utils/useControlledState.js.map +1 -1
- package/dist/private/utils/useControlledState.mjs.map +1 -1
- package/dist/private/virtualizer/Layout.cjs.map +1 -1
- package/dist/private/virtualizer/Layout.js.map +1 -1
- package/dist/private/virtualizer/Layout.mjs.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.cjs +4 -2
- package/dist/private/virtualizer/LayoutInfo.cjs.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.js +4 -2
- package/dist/private/virtualizer/LayoutInfo.js.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.mjs +4 -2
- package/dist/private/virtualizer/LayoutInfo.mjs.map +1 -1
- package/dist/private/virtualizer/Rect.cjs +4 -0
- package/dist/private/virtualizer/Rect.cjs.map +1 -1
- package/dist/private/virtualizer/Rect.js +4 -0
- package/dist/private/virtualizer/Rect.js.map +1 -1
- package/dist/private/virtualizer/Rect.mjs +4 -0
- package/dist/private/virtualizer/Rect.mjs.map +1 -1
- package/dist/private/virtualizer/ReusableView.cjs.map +1 -1
- package/dist/private/virtualizer/ReusableView.js.map +1 -1
- package/dist/private/virtualizer/ReusableView.mjs.map +1 -1
- package/dist/private/virtualizer/Size.cjs.map +1 -1
- package/dist/private/virtualizer/Size.js.map +1 -1
- package/dist/private/virtualizer/Size.mjs.map +1 -1
- package/dist/private/virtualizer/Virtualizer.cjs +4 -4
- package/dist/private/virtualizer/Virtualizer.cjs.map +1 -1
- package/dist/private/virtualizer/Virtualizer.js +4 -4
- package/dist/private/virtualizer/Virtualizer.js.map +1 -1
- package/dist/private/virtualizer/Virtualizer.mjs +4 -4
- package/dist/private/virtualizer/Virtualizer.mjs.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.cjs.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.js.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.mjs.map +1 -1
- package/dist/types/exports/useCalendarState.d.ts +1 -1
- package/dist/types/src/autocomplete/useAutocompleteState.d.ts +4 -1
- package/dist/types/src/calendar/types.d.ts +50 -14
- package/dist/types/src/calendar/useCalendarState.d.ts +20 -6
- package/dist/types/src/calendar/useRangeCalendarState.d.ts +14 -5
- package/dist/types/src/calendar/utils.d.ts +1 -0
- package/dist/types/src/checkbox/useCheckboxGroupState.d.ts +1 -0
- package/dist/types/src/collections/useCollection.d.ts +1 -1
- package/dist/types/src/color/useColorAreaState.d.ts +21 -8
- package/dist/types/src/color/useColorFieldState.d.ts +2 -3
- package/dist/types/src/color/useColorSliderState.d.ts +4 -1
- package/dist/types/src/color/useColorWheelState.d.ts +5 -1
- package/dist/types/src/combobox/useComboBoxState.d.ts +19 -6
- package/dist/types/src/data/useAsyncList.d.ts +2 -2
- package/dist/types/src/data/useListData.d.ts +13 -1
- package/dist/types/src/data/useTreeData.d.ts +11 -0
- package/dist/types/src/datepicker/IncompleteDate.d.ts +11 -5
- package/dist/types/src/datepicker/types.d.ts +37 -11
- package/dist/types/src/datepicker/useDateFieldState.d.ts +13 -4
- package/dist/types/src/datepicker/useDatePickerState.d.ts +10 -4
- package/dist/types/src/datepicker/useDateRangePickerState.d.ts +12 -3
- package/dist/types/src/dnd/useDraggableCollectionState.d.ts +4 -1
- package/dist/types/src/form/useFormValidationState.d.ts +4 -1
- package/dist/types/src/grid/GridCollection.d.ts +2 -1
- package/dist/types/src/grid/useGridState.d.ts +7 -3
- package/dist/types/src/layout/GridLayout.d.ts +18 -2
- package/dist/types/src/layout/ListLayout.d.ts +34 -12
- package/dist/types/src/layout/TableLayout.d.ts +11 -4
- package/dist/types/src/layout/WaterfallLayout.d.ts +9 -2
- package/dist/types/src/list/useListState.d.ts +2 -2
- package/dist/types/src/menu/useMenuTriggerState.d.ts +3 -1
- package/dist/types/src/menu/useSubmenuTriggerState.d.ts +2 -2
- package/dist/types/src/numberfield/useNumberFieldState.d.ts +15 -11
- package/dist/types/src/radio/useRadioGroupState.d.ts +4 -1
- package/dist/types/src/select/useSelectState.d.ts +13 -2
- package/dist/types/src/selection/types.d.ts +4 -1
- package/dist/types/src/selection/useMultipleSelectionState.d.ts +2 -0
- package/dist/types/src/slider/useSliderState.d.ts +22 -2
- package/dist/types/src/table/Column.d.ts +4 -1
- package/dist/types/src/table/Row.d.ts +5 -3
- package/dist/types/src/table/TableBody.d.ts +3 -2
- package/dist/types/src/table/TableCollection.d.ts +4 -1
- package/dist/types/src/table/TableColumnLayout.d.ts +4 -1
- package/dist/types/src/table/TableHeader.d.ts +7 -3
- package/dist/types/src/table/TableUtils.d.ts +19 -16
- package/dist/types/src/table/useTableColumnResizeState.d.ts +5 -3
- package/dist/types/src/table/useTableState.d.ts +15 -6
- package/dist/types/src/table/useTreeGridState.d.ts +3 -2
- package/dist/types/src/toggle/useToggleGroupState.d.ts +1 -0
- package/dist/types/src/toggle/useToggleState.d.ts +2 -1
- package/dist/types/src/tooltip/useTooltipTriggerState.d.ts +8 -2
- package/dist/types/src/tree/useTreeState.d.ts +1 -1
- package/dist/types/src/utils/number.d.ts +2 -1
- package/dist/types/src/virtualizer/Layout.d.ts +5 -2
- package/dist/types/src/virtualizer/LayoutInfo.d.ts +10 -3
- package/dist/types/src/virtualizer/Rect.d.ts +4 -0
- package/dist/types/src/virtualizer/Virtualizer.d.ts +5 -4
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2GM,SAAS,0CAAqE,KAA+B;IAClH,IAAI,iBACF,gBAAgB,+BAChB,sBAAsB,kBAAkB,UACzC,GAAG;IACJ,IAAI,eAAe,CAAA,GAAA,yCAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IACvE,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE;QAC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AqC;IACzD,IAAI,UAAU,WACZ,OAAO;IAET,IAAI,UAAU,MACZ,OAAO,EAAE;IAEX,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C","sources":["packages/react-stately/src/select/useSelectState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {CollectionBase, CollectionStateBase, FocusableProps, FocusStrategy, HelpTextProps, InputBase, Key, LabelableProps, Node, Selection, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, Omit<InputBase, 'isReadOnly'>, ValueBase<ValueType<M>, ChangeValueType<M>>, Validation<ValidationType<M>>, HelpTextProps, LabelableProps, TextInputBase, FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n * @default 'single'\n */\n selectionMode?: M,\n /**\n * The currently selected key in the collection (controlled).\n * @deprecated\n */\n selectedKey?: Key | null,\n /**\n * The initial selected key in the collection (uncontrolled).\n * @deprecated\n */\n defaultSelectedKey?: Key | null,\n /**\n * Handler that is called when the selection changes.\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void,\n /** Sets the open state of the menu. */\n isOpen?: boolean,\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean,\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void,\n /** Whether the Select should close when an item is selected. Defaults to true if selectionMode is single, false otherwise. */\n shouldCloseOnSelect?: boolean,\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'> extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'> extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n * @deprecated\n */\n readonly selectedKey: Key | null,\n\n /**\n * The default selected key.\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null,\n\n /**\n * Sets the selected key.\n * @deprecated\n */\n setSelectedKey(key: Key | null): void,\n\n /** The current select value. */\n readonly value: ValueType<M>,\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>,\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void,\n\n /**\n * The value of the first selected item.\n * @deprecated\n */\n readonly selectedItem: Node<T> | null,\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[],\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean,\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void,\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null,\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void,\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T extends object, M extends SelectionMode = 'single'>(props: SelectStateOptions<T, M>): SelectState<T, M> {\n let {\n selectionMode = 'single' as M,\n shouldCloseOnSelect = selectionMode === 'single'\n } = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined ? props.defaultValue : (selectionMode === 'single' ? props.defaultSelectedKey ?? null : []) as ValueType<M>;\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined ? props.value : (selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>;\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(value, defaultValue, props.onChange as any);\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue = selectionMode === 'single' && Array.isArray(controlledValue) ? controlledValue[0] : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? value[0] ?? null : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys].map(key => listState.collection.getItem(key)).filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : displayValue as any\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? initialValue as ValueType<M>,\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey: props.defaultSelectedKey ?? (props.selectionMode === 'single' ? initialValue as Key : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.mjs.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+IM,SAAS,0CACd,KAA+B;IAE/B,IAAI,iBAAC,gBAAgB,+BAAe,sBAAsB,kBAAkB,UAAS,GAAG;IACxF,IAAI,eAAe,CAAA,GAAA,yCAAqB,EAAE;IAC1C,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAwB;IACvE,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE;QACzB,OAAO,MAAM,YAAY,KAAK,YAC1B,MAAM,YAAY,GAChB,kBAAkB,WAAY,MAAM,kBAAkB,IAAI,OAAQ,EAAE;IAC5E,GAAG;QAAC,MAAM,YAAY;QAAE,MAAM,kBAAkB;QAAE;KAAc;IAChE,IAAI,Q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copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n CollectionBase,\n CollectionStateBase,\n FocusableProps,\n FocusStrategy,\n HelpTextProps,\n InputBase,\n Key,\n LabelableProps,\n Node,\n Selection,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {ListState, useListState} from '../list/useListState';\nimport {OverlayTriggerState, useOverlayTriggerState} from '../overlays/useOverlayTriggerState';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport type SelectionMode = 'single' | 'multiple';\nexport type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];\nexport type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];\ntype ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];\n\nexport interface SelectProps<T, M extends SelectionMode = 'single'>\n extends\n CollectionBase<T>,\n Omit<InputBase, 'isReadOnly'>,\n ValueBase<ValueType<M>, ChangeValueType<M>>,\n Validation<ValidationType<M>>,\n HelpTextProps,\n LabelableProps,\n TextInputBase,\n FocusableProps {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * The currently selected key in the collection (controlled).\n *\n * @deprecated\n */\n selectedKey?: Key | null;\n /**\n * The initial selected key in the collection (uncontrolled).\n *\n * @deprecated\n */\n defaultSelectedKey?: Key | null;\n /**\n * Handler that is called when the selection changes.\n *\n * @deprecated\n */\n onSelectionChange?: (key: Key | null) => void;\n /** Sets the open state of the menu. */\n isOpen?: boolean;\n /** Sets the default open state of the menu. */\n defaultOpen?: boolean;\n /** Method that is called when the open state of the menu changes. */\n onOpenChange?: (isOpen: boolean) => void;\n /**\n * Whether the Select should close when an item is selected. Defaults to true if selectionMode is\n * single, false otherwise.\n */\n shouldCloseOnSelect?: boolean;\n /** Whether the select should be allowed to be open when the collection is empty. */\n allowsEmptyCollection?: boolean;\n}\n\nexport interface SelectStateOptions<T, M extends SelectionMode = 'single'>\n extends Omit<SelectProps<T, M>, 'children'>, CollectionStateBase<T> {}\n\nexport interface SelectState<T, M extends SelectionMode = 'single'>\n extends ListState<T>, OverlayTriggerState, FormValidationState {\n /**\n * The key for the first selected item.\n *\n * @deprecated\n */\n readonly selectedKey: Key | null;\n\n /**\n * The default selected key.\n *\n * @deprecated\n */\n readonly defaultSelectedKey: Key | null;\n\n /**\n * Sets the selected key.\n *\n * @deprecated\n */\n setSelectedKey(key: Key | null): void;\n\n /** The current select value. */\n readonly value: ValueType<M>;\n\n /** The default select value. */\n readonly defaultValue: ValueType<M>;\n\n /** Sets the select value. */\n setValue(value: Key | readonly Key[] | null): void;\n\n /**\n * The value of the first selected item.\n *\n * @deprecated\n */\n readonly selectedItem: Node<T> | null;\n\n /** The value of the selected items. */\n readonly selectedItems: Node<T>[];\n\n /** Whether the select is currently focused. */\n readonly isFocused: boolean;\n\n /** Sets whether the select is focused. */\n setFocused(isFocused: boolean): void;\n\n /** Controls which item will be auto focused when the menu opens. */\n readonly focusStrategy: FocusStrategy | null;\n\n /** Opens the menu. */\n open(focusStrategy?: FocusStrategy | null): void;\n\n /** Toggles the menu. */\n toggle(focusStrategy?: FocusStrategy | null): void;\n}\n\n/**\n * Provides state management for a select component. Handles building a collection\n * of items from props, handles the open state for the popup menu, and manages\n * multiple selection state.\n */\nexport function useSelectState<T, M extends SelectionMode = 'single'>(\n props: SelectStateOptions<T, M>\n): SelectState<T, M> {\n let {selectionMode = 'single' as M, shouldCloseOnSelect = selectionMode === 'single'} = props;\n let triggerState = useOverlayTriggerState(props);\n let [focusStrategy, setFocusStrategy] = useState<FocusStrategy | null>(null);\n let defaultValue = useMemo(() => {\n return props.defaultValue !== undefined\n ? props.defaultValue\n : ((selectionMode === 'single' ? (props.defaultSelectedKey ?? null) : []) as ValueType<M>);\n }, [props.defaultValue, props.defaultSelectedKey, selectionMode]);\n let value = useMemo(() => {\n return props.value !== undefined\n ? props.value\n : ((selectionMode === 'single' ? props.selectedKey : undefined) as ValueType<M>);\n }, [props.value, props.selectedKey, selectionMode]);\n let [controlledValue, setControlledValue] = useControlledState<Key | readonly Key[] | null>(\n value,\n defaultValue,\n props.onChange as any\n );\n // Only display the first selected item if in single selection mode but the value is an array.\n let displayValue =\n selectionMode === 'single' && Array.isArray(controlledValue)\n ? controlledValue[0]\n : controlledValue;\n let setValue = (value: Key | Key[] | null) => {\n if (selectionMode === 'single') {\n let key = Array.isArray(value) ? (value[0] ?? null) : value;\n setControlledValue(key);\n if (key !== displayValue) {\n props.onSelectionChange?.(key);\n }\n } else {\n let keys: Key[] = [];\n if (Array.isArray(value)) {\n keys = value;\n } else if (value != null) {\n keys = [value];\n }\n\n setControlledValue(keys);\n }\n };\n\n let listState = useListState({\n ...props,\n selectionMode,\n disallowEmptySelection: selectionMode === 'single',\n allowDuplicateSelectionEvents: true,\n selectedKeys: useMemo(() => convertValue(displayValue), [displayValue]),\n onSelectionChange: (keys: Selection) => {\n // impossible, but TS doesn't know that\n if (keys === 'all') {\n return;\n }\n\n if (selectionMode === 'single') {\n let key = keys.values().next().value ?? null;\n setValue(key);\n } else {\n setValue([...keys]);\n }\n if (shouldCloseOnSelect) {\n triggerState.close();\n }\n\n validationState.commitValidation();\n }\n });\n\n let selectedKey = listState.selectionManager.firstSelectedKey;\n let selectedItems = useMemo(() => {\n return [...listState.selectionManager.selectedKeys]\n .map(key => listState.collection.getItem(key))\n .filter(item => item != null);\n }, [listState.selectionManager.selectedKeys, listState.collection]);\n\n let validationState = useFormValidationState({\n ...props,\n value: Array.isArray(displayValue) && displayValue.length === 0 ? null : (displayValue as any)\n });\n\n let [isFocused, setFocused] = useState(false);\n let [initialValue] = useState(displayValue);\n\n return {\n ...validationState,\n ...listState,\n ...triggerState,\n value: displayValue as ValueType<M>,\n defaultValue: defaultValue ?? (initialValue as ValueType<M>),\n setValue,\n selectedKey,\n setSelectedKey: setValue,\n selectedItem: selectedItems[0] ?? null,\n selectedItems,\n defaultSelectedKey:\n props.defaultSelectedKey ?? (props.selectionMode === 'single' ? (initialValue as Key) : null),\n focusStrategy,\n open(focusStrategy: FocusStrategy | null = null) {\n // Don't open if the collection is empty.\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.open();\n }\n },\n toggle(focusStrategy: FocusStrategy | null = null) {\n if (listState.collection.size !== 0 || props.allowsEmptyCollection) {\n setFocusStrategy(focusStrategy);\n triggerState.toggle();\n }\n },\n isFocused,\n setFocused\n };\n}\n\nfunction convertValue(value: Key | Key[] | null | undefined) {\n if (value === undefined) {\n return undefined;\n }\n if (value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n"],"names":[],"version":3,"file":"useSelectState.mjs.map"}
|
|
@@ -298,7 +298,8 @@ class $b9a23b9997e48a30$export$6c8a5aaad13c9852 {
|
|
|
298
298
|
return true;
|
|
299
299
|
}
|
|
300
300
|
isDisabled(key) {
|
|
301
|
-
|
|
301
|
+
let item = this.collection.getItem(key);
|
|
302
|
+
return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!item?.props?.isDisabled) && item?.props?.disabledBehavior !== 'selection';
|
|
302
303
|
}
|
|
303
304
|
isLink(key) {
|
|
304
305
|
return !!this.collection.getItem(key)?.props?.href;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA2BM,MAAM;IAQX,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,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AAU,CAAC,IAAI,CAAC,mBAAmB,EACxF,OAAO;QAGT,OAAO;IACT;IAEA,WAAW,GAAQ,EAAW;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAU,CAAA,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO,UAAS;IACvI;IAEA,OAAO,GAAQ,EAAW;QACxB,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO;IAChD;IAEA,aAAa,GAAQ,EAAO;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM;IACvC;IAEA,eAAe,UAAqC,EAAoB;QACtE,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;YACvC,gBAAgB,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU;QACxD;IACF;AACF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate,\n fullCollection?: Collection<Node<unknown>>\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA4BM,MAAM;IAQX,YACE,UAAqC,EACrC,KAA6B,EAC7B,OAAiC,CACjC;QACA,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;QACb,IAAI,CAAC,mBAAmB,GAAG,SAAS,uBAAuB;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,SAAS,kBAAkB;QACjD,IAAI,CAAC,cAAc,GAAG,SAAS,kBAAkB;IACnD;IAEA;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAQ;QAC/D,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;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,EAAoB;QACtE,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;YACvC,gBAAgB,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU;QACxD;IACF;AACF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection,\n DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean;\n layoutDelegate?: LayoutDelegate;\n fullCollection?: Collection<Node<unknown>>;\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(\n collection: Collection<Node<unknown>>,\n state: MultipleSelectionState,\n options?: SelectionManagerOptions\n ) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(\n this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys\n );\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (\n !this.disallowEmptySelection &&\n (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)\n ) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (\n this.selectionBehavior === 'toggle' ||\n (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))\n ) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n let item = this.collection.getItem(key);\n return (\n this.state.disabledBehavior === 'all' &&\n (this.state.disabledKeys.has(key) || !!item?.props?.isDisabled) &&\n item?.props?.disabledBehavior !== 'selection'\n );\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.cjs.map"}
|
|
@@ -293,8 +293,9 @@ class $60fcbaf037242b1f$export$6c8a5aaad13c9852 {
|
|
|
293
293
|
return true;
|
|
294
294
|
}
|
|
295
295
|
isDisabled(key) {
|
|
296
|
-
var
|
|
297
|
-
|
|
296
|
+
var _item_props, _item_props1;
|
|
297
|
+
let item = this.collection.getItem(key);
|
|
298
|
+
return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!(item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled)) && (item === null || item === void 0 ? void 0 : (_item_props1 = item.props) === null || _item_props1 === void 0 ? void 0 : _item_props1.disabledBehavior) !== 'selection';
|
|
298
299
|
}
|
|
299
300
|
isLink(key) {
|
|
300
301
|
var _this_collection_getItem_props, _this_collection_getItem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA2BM,MAAM;IAiBX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAQ;QAC/D,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;IAEA;;GAEC,GACD,IAAI,YAAqB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;IAC7B;IAEA;;GAEC,GACD,WAAW,SAAkB,EAAQ;QACnC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IACxB;IA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AAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,UAAU,CAAD;IACvI;IAEA,OAAO,GAAQ,EAAW;YACf,gCAAA;QAAT,OAAO,CAAC,GAAC,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,IAAI;IACpD;IAEA,aAAa,GAAQ,EAAO;YACnB;QAAP,QAAO,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,+CAAA,yBAA8B,KAAK;IAC5C;IAEA,eAAe,UAAqC,EAAoB;YAIpD;QAHlB,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;YACvC,gBAAgB,CAAA,uBAAA,IAAI,CAAC,cAAc,cAAnB,kCAAA,uBAAuB,IAAI,CAAC,UAAU;QACxD;IACF;IAteA,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;YACc;QAA3B,IAAI,CAAC,mBAAmB,GAAG,CAAA,+BAAA,oBAAA,8BAAA,QAAS,mBAAmB,cAA5B,0CAAA,+BAAgC;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;QACjD,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;IACnD;AAgeF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate,\n fullCollection?: Collection<Node<unknown>>\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA4BM,MAAM;IAqBX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EA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AA,oBAAA,8BAAA,QAAS,cAAc,KAAI;QACjD,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;IACnD;AA6eF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection,\n DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean;\n layoutDelegate?: LayoutDelegate;\n fullCollection?: Collection<Node<unknown>>;\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(\n collection: Collection<Node<unknown>>,\n state: MultipleSelectionState,\n options?: SelectionManagerOptions\n ) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(\n this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys\n );\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (\n !this.disallowEmptySelection &&\n (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)\n ) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (\n this.selectionBehavior === 'toggle' ||\n (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))\n ) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n let item = this.collection.getItem(key);\n return (\n this.state.disabledBehavior === 'all' &&\n (this.state.disabledKeys.has(key) || !!item?.props?.isDisabled) &&\n item?.props?.disabledBehavior !== 'selection'\n );\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.js.map"}
|
|
@@ -292,7 +292,8 @@ class $4a07ac835f260f78$export$6c8a5aaad13c9852 {
|
|
|
292
292
|
return true;
|
|
293
293
|
}
|
|
294
294
|
isDisabled(key) {
|
|
295
|
-
|
|
295
|
+
let item = this.collection.getItem(key);
|
|
296
|
+
return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!item?.props?.isDisabled) && item?.props?.disabledBehavior !== 'selection';
|
|
296
297
|
}
|
|
297
298
|
isLink(key) {
|
|
298
299
|
return !!this.collection.getItem(key)?.props?.href;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA2BM,MAAM;IAQX,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;QACb,IAAI,CAAC,mBAAmB,GAAG,SAAS,uBAAuB;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,SAAS,kBAAkB;QACjD,IAAI,CAAC,cAAc,GAAG,SAAS,kBAAkB;IACnD;IAEA;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAQ;QAC/D,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;IAEA;;GAEC,GACD,IAAI,YAAqB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;IAC7B;IAEA;;GAEC,GACD,WAAW,SAAkB,EAAQ;QACnC,IAAI,CAAC,KAAK,CAAC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;QACxD;IACF;AACF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate,\n fullCollection?: Collection<Node<unknown>>\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.mjs.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA4BM,MAAM;IAQX,YACE,UAAqC,EACrC,KAA6B,EAC7B,OAAiC,CACjC;QACA,IAAI,CAAC,UAAU,GAAG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IAAI,KAAK,UAAU,CAAC,IAAI,CAAC,mBAAmB,EACxF,OAAO;QAGT,OAAO;IACT;IAEA,WAAW,GAAQ,EAAW;QAC5B,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QACnC,OACE,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAC/B,CAAA,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,OAAO,UAAS,KAC7D,MAAM,OAAO,qBAAqB;IAEtC;IAEA,OAAO,GAAQ,EAAW;QACxB,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO;IAChD;IAEA,aAAa,GAAQ,EAAO;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM;IACvC;IAEA,eAAe,UAAqC,EAAoB;QACtE,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;YACvC,gBAAgB,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,UAAU;QACxD;IACF;AACF","sources":["packages/react-stately/src/selection/SelectionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n Collection,\n DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '../collections/getChildNodes';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean;\n layoutDelegate?: LayoutDelegate;\n fullCollection?: Collection<Node<unknown>>;\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\n private fullCollection: Collection<Node<unknown>> | null;\n\n constructor(\n collection: Collection<Node<unknown>>,\n state: MultipleSelectionState,\n options?: SelectionManagerOptions\n ) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n this.layoutDelegate = options?.layoutDelegate || null;\n this.fullCollection = options?.fullCollection || null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || (item && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || (item && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item && item.type !== 'item' && item.parentKey != null) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(\n this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys\n );\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n // Use the full (unfiltered) collection when available so that materializing\n // the 'all' selection includes items that are currently filtered out (e.g. by Autocomplete).\n let collection = this.fullCollection ?? this.collection;\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItemIn(key, collection)) {\n let item = collection.getItem(key);\n if (item?.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys(getFirstItem(getChildNodes(item, collection))?.key ?? null);\n }\n }\n\n key = collection.getKeyAfter(key);\n }\n };\n\n addKeys(collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (\n !this.disallowEmptySelection &&\n (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)\n ) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (\n this.selectionBehavior === 'toggle' ||\n (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))\n ) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n return this.canSelectItemIn(key, this.collection);\n }\n\n private canSelectItemIn(key: Key, collection: Collection<Node<unknown>>): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n let item = this.collection.getItem(key);\n return (\n this.state.disabledBehavior === 'all' &&\n (this.state.disabledKeys.has(key) || !!item?.props?.isDisabled) &&\n item?.props?.disabledBehavior !== 'selection'\n );\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined,\n fullCollection: this.fullCollection ?? this.collection\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.mjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAeD,SAAS,gCAAU,IAAI,EAAE,IAAI;IAC3B,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EACzB,OAAO;IAGT,KAAK,IAAI,QAAQ,KAAM;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,OACZ,OAAO;IAEX;IAEA,OAAO;AACT;AAsBO,SAAS,0CACd,KAAkC;IAElC,IAAI,iBACF,gBAAgB,gCAChB,yBAAyB,sCACzB,6BAA6B,EAC7B,mBAAmB,wBAAwB,QAAQ,oBACnD,mBAAmB,OACpB,GAAG;IAEJ,8FAA8F;IAC9F,kGAAkG;IAClG,IAAI,eAAe,CAAA,GAAA,mBAAK,EAA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IAAI,cAAa;YACf,OAAO,cAAc,OAAO;QAC9B;QACA,IAAI,sBAAqB;YACvB,OAAO,sBAAsB,OAAO;QACtC;QACA,eAAc,CAAC,EAAE,qBAAqB,OAAO;YAC3C,cAAc,OAAO,GAAG;YACxB,sBAAsB,OAAO,GAAG;YAChC,cAAc;QAChB;sBACA;QACA,iBAAgB,IAAI;YAClB,IAAI,iCAAiC,CAAC,gCAAU,MAAM,eACpD,gBAAgB;QAEpB;QACA,cAAc;0BACd;IACF;AACF;AAEA,SAAS,uCACP,SAAmD,EACnD,YAAwB;IAExB,IAAI,CAAC,WACH,OAAO;IAGT,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAA,GAAA,mCAAQ,EAAE;AACrD","sources":["packages/react-stately/src/selection/useMultipleSelectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n DisabledBehavior,\n FocusStrategy,\n Key,\n MultipleSelection,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /**\n * How multiple selection should behave in the collection.\n *\n * @default 'toggle'\n */\n selectionBehavior?: SelectionBehavior;\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean;\n /**\n * Whether `disabledKeys` applies to all interactions, or only selection.\n *\n * @default 'all'\n */\n disabledBehavior?: DisabledBehavior;\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(\n props: MultipleSelectionStateProps\n): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection = false,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef<Key | null>(null);\n let childFocusStrategyRef = useRef<FocusStrategy | null>(null);\n let [, setFocusedKey] = useState<Key | null>(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(\n () => convertSelection(props.defaultSelectedKeys, new Selection()),\n [props.defaultSelectedKeys]\n );\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys!,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (\n selectionBehaviorProp === 'replace' &&\n selectionBehavior === 'toggle' &&\n typeof selectedKeys === 'object' &&\n selectedKeys.size === 0\n ) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(\n selection: 'all' | Iterable<Key> | null | undefined,\n defaultValue?: Selection\n): 'all' | Set<Key> | undefined {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all' ? 'all' : new Selection(selection);\n}\n"],"names":[],"version":3,"file":"useMultipleSelectionState.cjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAeD,SAAS,gCAAU,IAAI,EAAE,IAAI;IAC3B,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EACzB,OAAO;IAGT,KAAK,IAAI,QAAQ,KAAM;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,OACZ,OAAO;IAEX;IAEA,OAAO;AACT;AAsBO,SAAS,0CACd,KAAkC;IAElC,IAAI,iBACF,gBAAgB,gCAChB,yBAAyB,sCACzB,6BAA6B,EAC7B,mBAAmB,wBAAwB,QAAQ,oBACnD,mBAAmB,OACpB,GAAG;IAEJ,8FAA8F;IAC9F,kGAAkG;IAClG,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,IAAI,GAAG,WAAW,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9B;QACA,IAAI,sBAAqB;YACvB,OAAO,sBAAsB,OAAO;QACtC;QACA,eAAc,CAAC,EAAE,qBAAqB,OAAO;YAC3C,cAAc,OAAO,GAAG;YACxB,sBAAsB,OAAO,GAAG;YAChC,cAAc;QAChB;sBACA;QACA,iBAAgB,IAAI;YAClB,IAAI,iCAAiC,CAAC,gCAAU,MAAM,eACpD,gBAAgB;QAEpB;QACA,cAAc;0BACd;IACF;AACF;AAEA,SAAS,uCACP,SAAmD,EACnD,YAAwB;IAExB,IAAI,CAAC,WACH,OAAO;IAGT,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAA,GAAA,yCAAQ,EAAE;AACrD","sources":["packages/react-stately/src/selection/useMultipleSelectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n DisabledBehavior,\n FocusStrategy,\n Key,\n MultipleSelection,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /**\n * How multiple selection should behave in the collection.\n *\n * @default 'toggle'\n */\n selectionBehavior?: SelectionBehavior;\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean;\n /**\n * Whether `disabledKeys` applies to all interactions, or only selection.\n *\n * @default 'all'\n */\n disabledBehavior?: DisabledBehavior;\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(\n props: MultipleSelectionStateProps\n): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection = false,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef<Key | null>(null);\n let childFocusStrategyRef = useRef<FocusStrategy | null>(null);\n let [, setFocusedKey] = useState<Key | null>(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(\n () => convertSelection(props.defaultSelectedKeys, new Selection()),\n [props.defaultSelectedKeys]\n );\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys!,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (\n selectionBehaviorProp === 'replace' &&\n selectionBehavior === 'toggle' &&\n typeof selectedKeys === 'object' &&\n selectedKeys.size === 0\n ) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(\n selection: 'all' | Iterable<Key> | null | undefined,\n defaultValue?: Selection\n): 'all' | Set<Key> | undefined {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all' ? 'all' : new Selection(selection);\n}\n"],"names":[],"version":3,"file":"useMultipleSelectionState.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAeD,SAAS,gCAAU,IAAI,EAAE,IAAI;IAC3B,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,EACzB,OAAO;IAGT,KAAK,IAAI,QAAQ,KAAM;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,OACZ,OAAO;IAEX;IAEA,OAAO;AACT;AAsBO,SAAS,0CACd,KAAkC;IAElC,IAAI,iBACF,gBAAgB,gCAChB,yBAAyB,sCACzB,6BAA6B,EAC7B,mBAAmB,wBAAwB,QAAQ,oBACnD,mBAAmB,OACpB,GAAG;IAEJ,8FAA8F;IAC9F,kGAAkG;IAClG,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,IAAI,GAAG,WAAW,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAA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B,OAAO;QACtC;QACA,eAAc,CAAC,EAAE,qBAAqB,OAAO;YAC3C,cAAc,OAAO,GAAG;YACxB,sBAAsB,OAAO,GAAG;YAChC,cAAc;QAChB;sBACA;QACA,iBAAgB,IAAI;YAClB,IAAI,iCAAiC,CAAC,gCAAU,MAAM,eACpD,gBAAgB;QAEpB;QACA,cAAc;0BACd;IACF;AACF;AAEA,SAAS,uCACP,SAAmD,EACnD,YAAwB;IAExB,IAAI,CAAC,WACH,OAAO;IAGT,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAA,GAAA,yCAAQ,EAAE;AACrD","sources":["packages/react-stately/src/selection/useMultipleSelectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n DisabledBehavior,\n FocusStrategy,\n Key,\n MultipleSelection,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nfunction equalSets(setA, setB) {\n if (setA.size !== setB.size) {\n return false;\n }\n\n for (let item of setA) {\n if (!setB.has(item)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport interface MultipleSelectionStateProps extends MultipleSelection {\n /**\n * How multiple selection should behave in the collection.\n *\n * @default 'toggle'\n */\n selectionBehavior?: SelectionBehavior;\n /** Whether onSelectionChange should fire even if the new set of keys is the same as the last. */\n allowDuplicateSelectionEvents?: boolean;\n /**\n * Whether `disabledKeys` applies to all interactions, or only selection.\n *\n * @default 'all'\n */\n disabledBehavior?: DisabledBehavior;\n}\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(\n props: MultipleSelectionStateProps\n): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection = false,\n allowDuplicateSelectionEvents,\n selectionBehavior: selectionBehaviorProp = 'toggle',\n disabledBehavior = 'all'\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef<Key | null>(null);\n let childFocusStrategyRef = useRef<FocusStrategy | null>(null);\n let [, setFocusedKey] = useState<Key | null>(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(\n () => convertSelection(props.defaultSelectedKeys, new Selection()),\n [props.defaultSelectedKeys]\n );\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys!,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n let [selectionBehavior, setSelectionBehavior] = useState(selectionBehaviorProp);\n\n // If the selectionBehavior prop is set to replace, but the current state is toggle (e.g. due to long press\n // to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.\n if (\n selectionBehaviorProp === 'replace' &&\n selectionBehavior === 'toggle' &&\n typeof selectedKeys === 'object' &&\n selectedKeys.size === 0\n ) {\n setSelectionBehavior('replace');\n }\n\n // If the selectionBehavior prop changes, update the state as well.\n let lastSelectionBehavior = useRef(selectionBehaviorProp);\n useEffect(() => {\n if (selectionBehaviorProp !== lastSelectionBehavior.current) {\n setSelectionBehavior(selectionBehaviorProp);\n lastSelectionBehavior.current = selectionBehaviorProp;\n }\n }, [selectionBehaviorProp]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n selectionBehavior,\n setSelectionBehavior,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys(keys) {\n if (allowDuplicateSelectionEvents || !equalSets(keys, selectedKeys)) {\n setSelectedKeys(keys);\n }\n },\n disabledKeys: disabledKeysProp,\n disabledBehavior\n };\n}\n\nfunction convertSelection(\n selection: 'all' | Iterable<Key> | null | undefined,\n defaultValue?: Selection\n): 'all' | Set<Key> | undefined {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all' ? 'all' : new Selection(selection);\n}\n"],"names":[],"version":3,"file":"useMultipleSelectionState.mjs.map"}
|