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;AAkIM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC,OAAc,KAAK,EAAE,IAAI,KAAK,GAAG,eAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,qBA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M,GAAG,KAC3B,AAAC,CAAA,UAAU,WAAW,SAAS,QAAQ,CAAC,OAAO,CAAC,SAAS,MAAM,OAAO,CAAC,MAAK,IAAK,iBACpF;IAEJ;IAEA,UAAU;QAAC,UAAU;IAAK,GAAG;iBAAC;mBAAS;IAAS;IAEhD,IAAI,eAAe,aAAa,IAAI,CAAC,CAAC,GAAG,IAAM,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,IAAI;IACvG,8CAA8C;IAC9C,IAAI,CAAC,YAAY,SAAS,GAAG,IAAI,MAAM;QACrC,aAAa,OAAO,CAAC,CAAA;YACnB,QAAQ,WAAW;QACrB;QACA,OAAO;YAAC,OAAO;mBACV,SAAS,KAAK,CAAC,GAAG;mBAClB;mBACA,SAAS,KAAK,CAAC;aACnB;YAAE,SAAS;QAAM;IACpB;IAEA,uDAAuD;IACvD,OAAO,WAAW,UAAU,SAAS,GAAG,EAAE,CAAA,aAAe,CAAA;YACvD,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GAAI;AACN","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[],\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>,\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key,\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[]\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key,\n /** The key of the parent node. */\n parentKey?: Key | null,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[] | null\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[],\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>,\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void,\n\n /**\n * Gets a node from the tree by key.\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined,\n\n /**\n * Inserts an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void,\n\n /**\n * Inserts items into the list before the item at the given key.\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void,\n\n /**\n * Inserts items into the list after the item at the given key.\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void,\n\n /**\n * Appends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void,\n\n /**\n * Prepends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void,\n\n /**\n * Removes an item from the tree by its key.\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void,\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void,\n\n /**\n * Moves an item within the tree.\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void,\n\n /**\n * Moves one or more items before a given key.\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Moves one or more items after a given key.\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Updates an item in the tree.\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[],\n nodeMap: Map<Key, TreeNode<T>>\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(items: TreeNode<T>[], key: Key | null, update: (node: TreeNode<T>) => TreeNode<T> | null, originalMap: Map<Key, TreeNode<T>>) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n }, originalMap));\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(newItems, child.key, () => null, newMap);\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if ((child.parentKey === toParent\n || child.parentKey === toParent?.key)\n && keyArray.includes(child.key)\n && (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) < originalToIndex) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) => inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1);\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap); \n });\n return {items: [\n ...newItems.slice(0, toIndex),\n ...inOrderItems,\n ...newItems.slice(toIndex)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParent.key, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }), newMap);\n}\n"],"names":[],"version":3,"file":"useTreeData.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC,OAAc,KAAK,EAAE,IAAI,KAAK,GAAG,eAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,qBAAO,EAAoB,IAAM,UAAU,cAAc,IAAI;IACpF,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,SAAS,UACP,eAA2B,EAAE,EAC7B,GAA0B,EAC1B,SAAsB;QAEtB,IAAI,gBAAgB,MAClB,eAAe,EAAE;QAEnB,OAAO;YACL,OAAO,aAAa,GAAG,CAAC,CAAA;gBACtB,IAAI,OAAoB;oBACtB,KAAK,OAAO;oBACZ,WAAW,aAAa;oBACxB,OAAO;oBACP,UAAU;gBACZ;gBAEA,KAAK,QAAQ,GAAG,UAAU,YAAY,OAAO,KAAK,KAAK,GAAG,EAAE,KAAK;gBACjE,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE;gBAClB,OAAO;YACT;YACA,SAAS;QACX;IACF;IAEA,SAAS,WACP,KAAoB,EACpB,GAAe,EACf,MAAiD,EACjD,WAAkC;QAEl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W,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.cjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAkIM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;oBA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K,CAAC;aACnB;YAAE,SAAS;QAAM;IACpB;IAEA,uDAAuD;IACvD,OAAO,WAAW,UAAU,SAAS,GAAG,EAAE,CAAA,aAAe,CAAA;YACvD,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GAAI;AACN","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[],\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>,\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key,\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[]\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key,\n /** The key of the parent node. */\n parentKey?: Key | null,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[] | null\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[],\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>,\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void,\n\n /**\n * Gets a node from the tree by key.\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined,\n\n /**\n * Inserts an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void,\n\n /**\n * Inserts items into the list before the item at the given key.\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void,\n\n /**\n * Inserts items into the list after the item at the given key.\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void,\n\n /**\n * Appends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void,\n\n /**\n * Prepends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void,\n\n /**\n * Removes an item from the tree by its key.\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void,\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void,\n\n /**\n * Moves an item within the tree.\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void,\n\n /**\n * Moves one or more items before a given key.\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Moves one or more items after a given key.\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Updates an item in the tree.\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[],\n nodeMap: Map<Key, TreeNode<T>>\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(items: TreeNode<T>[], key: Key | null, update: (node: TreeNode<T>) => TreeNode<T> | null, originalMap: Map<Key, TreeNode<T>>) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n }, originalMap));\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(newItems, child.key, () => null, newMap);\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if ((child.parentKey === toParent\n || child.parentKey === toParent?.key)\n && keyArray.includes(child.key)\n && (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) < originalToIndex) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) => inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1);\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap); \n });\n return {items: [\n ...newItems.slice(0, toIndex),\n ...inOrderItems,\n ...newItems.slice(toIndex)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParent.key, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }), newMap);\n}\n"],"names":[],"version":3,"file":"useTreeData.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;oBAC3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SAAS;QACX;IACF;IAEA,uDAAuD;IACvD,OAAO,WACL,UACA,SAAS,GAAG,EACZ,CAAA,aAAe,CAAA;YACb,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAkIM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF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UAAU,MAAM,GAAG,EAAE,IAAM,MAAM;YACvF,WAAW;YACX,SAAS;QACX;QACA,qGAAqG;QACrG,4GAA4G;QAC5G,IAAI,AAAC,CAAA,MAAM,SAAS,KAAK,YACpB,MAAM,SAAS,KAAK,UAAU,GAAE,KAChC,SAAS,QAAQ,CAAC,MAAM,GAAG,KAC3B,AAAC,CAAA,UAAU,WAAW,SAAS,QAAQ,CAAC,OAAO,CAAC,SAAS,MAAM,OAAO,CAAC,MAAK,IAAK,iBACpF;IAEJ;IAEA,UAAU;QAAC,UAAU;IAAK,GAAG;iBAAC;mBAAS;IAAS;IAEhD,IAAI,eAAe,aAAa,IAAI,CAAC,CAAC,GAAG,IAAM,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,IAAI;IACvG,8CAA8C;IAC9C,IAAI,CAAC,YAAY,SAAS,GAAG,IAAI,MAAM;QACrC,aAAa,OAAO,CAAC,CAAA;YACnB,QAAQ,WAAW;QACrB;QACA,OAAO;YAAC,OAAO;mBACV,SAAS,KAAK,CAAC,GAAG;mBAClB;mBACA,SAAS,KAAK,CAAC;aACnB;YAAE,SAAS;QAAM;IACpB;IAEA,uDAAuD;IACvD,OAAO,WAAW,UAAU,SAAS,GAAG,EAAE,CAAA,aAAe,CAAA;YACvD,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GAAI;AACN","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[],\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>,\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key,\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[]\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key,\n /** The key of the parent node. */\n parentKey?: Key | null,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[] | null\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[],\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>,\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void,\n\n /**\n * Gets a node from the tree by key.\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined,\n\n /**\n * Inserts an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void,\n\n /**\n * Inserts items into the list before the item at the given key.\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void,\n\n /**\n * Inserts items into the list after the item at the given key.\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void,\n\n /**\n * Appends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void,\n\n /**\n * Prepends an item into a parent node as a child.\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void,\n\n /**\n * Removes an item from the tree by its key.\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void,\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void,\n\n /**\n * Moves an item within the tree.\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void,\n\n /**\n * Moves one or more items before a given key.\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Moves one or more items after a given key.\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void,\n\n /**\n * Updates an item in the tree.\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[],\n nodeMap: Map<Key, TreeNode<T>>\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(items: TreeNode<T>[], key: Key | null, update: (node: TreeNode<T>) => TreeNode<T> | null, originalMap: Map<Key, TreeNode<T>>) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }), newMap);\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems((prevState) => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n }, originalMap));\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(newItems, child.key, () => null, newMap);\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if ((child.parentKey === toParent\n || child.parentKey === toParent?.key)\n && keyArray.includes(child.key)\n && (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) < originalToIndex) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) => inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1);\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap); \n });\n return {items: [\n ...newItems.slice(0, toIndex),\n ...inOrderItems,\n ...newItems.slice(toIndex)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParent.key, parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }), newMap);\n}\n"],"names":[],"version":3,"file":"useTreeData.mjs.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC,OAAc,KAAK,EAAE,IAAI,KAAK,GAAG,eAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,eAAO,EAAoB,IAAM,UAAU,cAAc,IAAI;IACpF,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,SAAS,UACP,eAA2B,EAAE,EAC7B,GAA0B,EAC1B,SAAsB;QAEtB,IAAI,gBAAgB,MAClB,eAAe,EAAE;QAEnB,OAAO;YACL,OAAO,aAAa,GAAG,CAAC,CAAA;gBACtB,IAAI,OAAoB;oBACtB,KAAK,OAAO;oBACZ,WAAW,aAAa;oBACxB,OAAO;oBACP,UAAU;gBACZ;gBAEA,KAAK,QAAQ,GAAG,UAAU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SAAS,KAAK,CAAC,GAAG;mBAAa;mBAAiB,SAAS,KAAK,CAAC;aAAS;YACnF,SAAS;QACX;IACF;IAEA,uDAAuD;IACvD,OAAO,WACL,UACA,SAAS,GAAG,EACZ,CAAA,aAAe,CAAA;YACb,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.mjs.map"}
|
|
@@ -85,7 +85,10 @@ class $644c5fdef7cba18c$export$ae165b50d181e1ef {
|
|
|
85
85
|
result.offset = null;
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
88
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Increments or decrements the given field. If it is null, then it is set to the placeholder
|
|
90
|
+
* value.
|
|
91
|
+
*/ cycle(field, amount, placeholder, displaySegments) {
|
|
89
92
|
let res = this.copy();
|
|
90
93
|
// If field is null, default to placeholder.
|
|
91
94
|
if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {
|
|
@@ -163,7 +166,10 @@ class $644c5fdef7cba18c$export$ae165b50d181e1ef {
|
|
|
163
166
|
}
|
|
164
167
|
return res;
|
|
165
168
|
}
|
|
166
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Converts the incomplete date to a full date value, using the provided value for any unset
|
|
171
|
+
* fields.
|
|
172
|
+
*/ toValue(value) {
|
|
167
173
|
if ('hour' in value) {
|
|
168
174
|
let hour = this.hour;
|
|
169
175
|
if (hour != null) hour = $644c5fdef7cba18c$var$fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAcM,MAAM;IAcX,YAAY,QAAkB,EAAE,SAAoB,EAAE,SAAqD,CAAE;QAC3G,IAAI,CAAC,GAAG,GAAG,WAAW,OAAO;QAC7B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,IAAI,GAAG,WAAW,QAAQ;QAC/B,IAAI,CAAC,KAAK,GAAG,WAAW,SAAS;QACjC,IAAI,CAAC,GAAG,GAAG,WAAW,OAAO;QAC7B,IAAI,CAAC,IAAI,GAAG,WAAW,QAAQ;QAC/B,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,CAAC,MAAM,GAAG,WAAW,UAAU;QACnC,IAAI,CAAC,MAAM,GAAG,WAAW,UAAU;QACnC,IAAI,CAAC,WAAW,GAAG,W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,IAAI,QAAQ,KACV,QAAQ;IAEZ,OAAO;QACL,SAAS;QACT,IAAI,QAAQ,KACV,QAAQ,MAAO,CAAA,MAAM,QAAQ,CAAA;aACxB,IAAI,QAAQ,KACjB,QAAQ,MAAO,CAAA,QAAQ,MAAM,CAAA;IAEjC;IAEA,OAAO;AACT;AAEA,SAAS,kCAAY,IAAY,EAAE,SAAoB;IACrD,IAAI,YAA2B,QAAQ,KAAK,IAAI;IAChD,OAAQ;QACN,KAAK;YACH,kDAAkD;YAClD,IAAI,QAAQ,IACV,QAAQ;YAEV;QACF,KAAK;YACH,qDAAqD;YACrD,IAAI,SAAS,GACX,OAAO;iBACF,IAAI,OAAO,IAChB,QAAQ;YAEV;QACF,KAAK;YACH,kCAAkC;YAClC,YAAY;YACZ;QACF,KAAK;YACH,+EAA+E;YAC/E,QAAQ;YACR,YAAY;IAChB;IAEA,OAAO;QAAC;QAAW;KAAK;AAC1B;AAEA,SAAS,oCAAc,IAAY,EAAE,SAAiB,EAAE,SAAoB;IAC1E,OAAQ;QACN,KAAK;YACH,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,IAAI,SAAS,IACX,OAAO;YAET,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,QAAQ;YACR;IACJ;IAEA,OAAO;AACT","sources":["packages/react-stately/src/datepicker/IncompleteDate.ts"],"sourcesContent":["/*\n * Copyright 2026 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 {AnyDateTime, Calendar, CalendarDate, ZonedDateTime} from '@internationalized/date';\nimport {DateSegmentType} from './useDateFieldState';\nimport {DateValue} from './types';\n\ntype HourCycle = 'h12' | 'h11' | 'h23' | 'h24';\n\n/**\n * This class represents a date that is incomplete or otherwise invalid as a result of user editing.\n * For example, it can represent temporary dates such as February 31st if the user edits the day before the month.\n * Times are represented according to an hour cycle rather than always in 24 hour time. This enables the user to adjust\n * the day period (e.g. am/pm) independently from the hour.\n */\nexport class IncompleteDate {\n calendar: Calendar;\n era: string | null;\n year: number | null;\n month: number | null;\n day: number | null;\n hour: number | null;\n hourCycle: HourCycle;\n dayPeriod: number | null;\n minute: number | null;\n second: number | null;\n millisecond: number | null;\n offset: number | null;\n\n constructor(calendar: Calendar, hourCycle: HourCycle, dateValue?: Partial<Omit<AnyDateTime, 'copy'>> | null) {\n this.era = dateValue?.era ?? null;\n this.calendar = calendar;\n this.year = dateValue?.year ?? null;\n this.month = dateValue?.month ?? null;\n this.day = dateValue?.day ?? null;\n this.hour = dateValue?.hour ?? null;\n this.hourCycle = hourCycle;\n this.dayPeriod = null;\n this.minute = dateValue?.minute ?? null;\n this.second = dateValue?.second ?? null;\n this.millisecond = dateValue?.millisecond ?? null;\n this.offset = 'offset' in (dateValue ?? {}) ? (dateValue as any).offset : null;\n\n // Convert the hour from 24 hour time to the given hour cycle.\n if (this.hour != null) {\n let [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);\n this.dayPeriod = dayPeriod;\n this.hour = hour;\n }\n }\n\n copy(): IncompleteDate {\n let res = new IncompleteDate(this.calendar, this.hourCycle);\n res.era = this.era;\n res.year = this.year;\n res.month = this.month;\n res.day = this.day;\n res.hour = this.hour;\n res.dayPeriod = this.dayPeriod;\n res.minute = this.minute;\n res.second = this.second;\n res.millisecond = this.millisecond;\n res.offset = this.offset;\n return res;\n }\n\n /** Checks whether all the specified segments have a value. */\n isComplete(segments: DateSegmentType[]) {\n return segments.every(segment => this[segment] != null);\n }\n\n /** Checks whether the given date value matches this value for the specified segments. */\n validate(dt: DateValue, segments: DateSegmentType[]) {\n return segments.every(segment => {\n if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {\n let [dayPeriod, hour] = toHourCycle(dt.hour, this.hourCycle);\n return this.dayPeriod === dayPeriod && this.hour === hour;\n }\n return this[segment] === dt[segment];\n });\n }\n\n /** Checks if the date is empty (i.e. all specified segments are null). */\n isCleared(segments: DateSegmentType[]): boolean {\n return segments.every(segment => this[segment] === null);\n }\n\n /** Sets the given field. */\n set(field: DateSegmentType, value: number | string, placeholder: DateValue): IncompleteDate {\n let result = this.copy();\n result[field] = value;\n if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) {\n result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n if (field === 'year' && result.era == null) {\n result.era = placeholder.era;\n }\n\n // clear offset when a date/time field changes since it may no longer be valid\n if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') {\n result.offset = null;\n }\n return result;\n }\n\n /** Sets the given field to null. */\n clear(field: DateSegmentType): IncompleteDate {\n let result = this.copy();\n // @ts-ignore\n result[field] = null;\n if (field === 'year') {\n result.era = null;\n }\n\n // clear offset when a field is cleared since it may no longer be valid\n result.offset = null;\n return result;\n }\n\n /** Increments or decrements the given field. If it is null, then it is set to the placeholder value. */\n cycle(field: DateSegmentType, amount: number, placeholder: DateValue, displaySegments: DateSegmentType[]): IncompleteDate {\n let res = this.copy();\n\n // If field is null, default to placeholder.\n if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {\n if (field === 'hour' && 'hour' in placeholder) {\n let [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);\n res.dayPeriod = dayPeriod;\n res.hour = hour;\n } else {\n res[field] = placeholder[field];\n }\n if (field === 'year' && res.era == null) {\n res.era = placeholder.era;\n }\n\n return res;\n }\n\n switch (field) {\n case 'era': {\n let eras = this.calendar.getEras();\n let index = eras.indexOf(res.era!);\n index = cycleValue(index, amount, 0, eras.length - 1);\n res.era = eras[index];\n break;\n }\n case 'year': {\n // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.\n let date = new CalendarDate(this.calendar, this.era ?? placeholder.era, this.year ?? placeholder.year, this.month ?? 1, this.day ?? 1);\n date = date.cycle(field, amount, {round: field === 'year'});\n res.era = date.era;\n res.year = date.year;\n break;\n }\n case 'month':\n res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());\n break;\n case 'day':\n // Allow incrementing up to the maximum number of days in any month.\n res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());\n break;\n case 'hour': {\n // if date is fully defined or it is just a time field, and we have a time zone, use toValue to get a ZonedDateTime to cycle\n // so DST fallback is properly handled\n let hasDateSegements = displaySegments.some(s => ['year', 'month', 'day'].includes(s));\n if ('timeZone' in placeholder && (!hasDateSegements || (res.year != null && res.month != null && res.day != null))) {\n let date = this.toValue(placeholder) as ZonedDateTime;\n date = date.cycle('hour', amount, {hourCycle: this.hourCycle === 'h12' ? 12 : 24, round: false});\n let [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);\n res.hour = adjustedHour;\n res.dayPeriod = dayPeriod;\n res.offset = date.offset;\n } else {\n let hours = res.hour ?? 0;\n let limits = this.getSegmentLimits('hour')!;\n res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);\n if (res.dayPeriod == null && 'hour' in placeholder) {\n res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n }\n break;\n }\n case 'dayPeriod':\n res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);\n break;\n case 'minute':\n res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);\n break;\n case 'second':\n res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);\n break;\n }\n\n return res;\n }\n\n /** Converts the incomplete date to a full date value, using the provided value for any unset fields. */\n toValue(value: DateValue): DateValue {\n if ('hour' in value) {\n let hour = this.hour;\n if (hour != null) {\n hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);\n } else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') {\n hour = this.dayPeriod === 1 ? 12 : 0;\n }\n\n let res = value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day,\n hour: hour ?? value.hour,\n minute: this.minute ?? value.minute,\n second: this.second ?? value.second,\n millisecond: this.millisecond ?? value.millisecond\n });\n\n if ('offset' in res && this.offset != null && res.offset !== this.offset) {\n res = res.add({milliseconds: res.offset - this.offset});\n }\n\n return res;\n } else {\n return value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day\n });\n }\n }\n\n getSegmentLimits(type: string): {value: number | null, minValue: number, maxValue: number} | undefined {\n switch (type) {\n case 'era': {\n let eras = this.calendar.getEras();\n return {\n value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,\n minValue: 0,\n maxValue: eras.length - 1\n };\n }\n case 'year':\n return {\n value: this.year,\n minValue: 1,\n maxValue: 9999\n };\n case 'month':\n return {\n value: this.month,\n minValue: 1,\n maxValue: this.calendar.getMaximumMonthsInYear()\n };\n case 'day':\n return {\n value: this.day,\n minValue: 1,\n maxValue: this.calendar.getMaximumDaysInMonth()\n };\n case 'dayPeriod': {\n return {\n value: this.dayPeriod,\n minValue: 0,\n maxValue: 1\n };\n }\n case 'hour': {\n let minValue = 0;\n let maxValue = 23;\n if (this.hourCycle === 'h12') {\n minValue = 1;\n maxValue = 12;\n } else if (this.hourCycle === 'h11') {\n minValue = 0;\n maxValue = 11;\n }\n\n return {\n value: this.hour,\n minValue,\n maxValue\n };\n }\n case 'minute':\n return {\n value: this.minute,\n minValue: 0,\n maxValue: 59\n };\n case 'second':\n return {\n value: this.second,\n minValue: 0,\n maxValue: 59\n };\n }\n }\n}\n\nfunction cycleValue(value: number, amount: number, min: number, max: number, round = false) {\n if (round) {\n value += Math.sign(amount);\n\n if (value < min) {\n value = max;\n }\n\n let div = Math.abs(amount);\n if (amount > 0) {\n value = Math.ceil(value / div) * div;\n } else {\n value = Math.floor(value / div) * div;\n }\n\n if (value > max) {\n value = min;\n }\n } else {\n value += amount;\n if (value < min) {\n value = max - (min - value - 1);\n } else if (value > max) {\n value = min + (value - max - 1);\n }\n }\n\n return value;\n}\n\nfunction toHourCycle(hour: number, hourCycle: HourCycle): [number | null, number] {\n let dayPeriod: number | null = hour >= 12 ? 1 : 0;\n switch (hourCycle) {\n case 'h11':\n // Hours are numbered from 0 to 11. Used in Japan.\n if (hour >= 12) {\n hour -= 12;\n }\n break;\n case 'h12':\n // Hours are numbered from 12 (representing 0) to 11.\n if (hour === 0) {\n hour = 12;\n } else if (hour > 12) {\n hour -= 12;\n }\n break;\n case 'h23':\n // 24 hour time, numbered 0 to 23.\n dayPeriod = null;\n break;\n case 'h24':\n // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.\n hour += 1;\n dayPeriod = null;\n }\n\n return [dayPeriod, hour];\n}\n\nfunction fromHourCycle(hour: number, dayPeriod: number, hourCycle: HourCycle): number {\n switch (hourCycle) {\n case 'h11':\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h12':\n if (hour === 12) {\n hour = 0;\n }\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h24':\n hour -= 1;\n break;\n }\n\n return hour;\n}\n"],"names":[],"version":3,"file":"IncompleteDate.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAcM,MAAM;IAcX,YACE,QAAkB,EAClB,SAAoB,EACpB,SAAqD,CACrD;QACA,IAAI,CAAC,GAAG,GAAG,WAAW,OAAO;QAC7B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,IAAI,GAAG,WAAW,QAAQ;QAC/B,IAAI,CAAC,KAAK,GAAG,WAAW,SAAS;QACjC,IAAI,CAAC,GAAG,GAAG,WAAW,OAAO;QAC7B,IAAI,CAAC,IAAI,GAAG,WAAW,QAAQ;QAC/B,IAAI,CAAC,SAAS,GAAG;QACjB,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GAAG,CAAC;QACnB,IAAI,SAAS,GACX,QAAQ,KAAK,IAAI,CAAC,QAAQ,OAAO;aAEjC,QAAQ,KAAK,KAAK,CAAC,QAAQ,OAAO;QAGpC,IAAI,QAAQ,KACV,QAAQ;IAEZ,OAAO;QACL,SAAS;QACT,IAAI,QAAQ,KACV,QAAQ,MAAO,CAAA,MAAM,QAAQ,CAAA;aACxB,IAAI,QAAQ,KACjB,QAAQ,MAAO,CAAA,QAAQ,MAAM,CAAA;IAEjC;IAEA,OAAO;AACT;AAEA,SAAS,kCAAY,IAAY,EAAE,SAAoB;IACrD,IAAI,YAA2B,QAAQ,KAAK,IAAI;IAChD,OAAQ;QACN,KAAK;YACH,kDAAkD;YAClD,IAAI,QAAQ,IACV,QAAQ;YAEV;QACF,KAAK;YACH,qDAAqD;YACrD,IAAI,SAAS,GACX,OAAO;iBACF,IAAI,OAAO,IAChB,QAAQ;YAEV;QACF,KAAK;YACH,kCAAkC;YAClC,YAAY;YACZ;QACF,KAAK;YACH,+EAA+E;YAC/E,QAAQ;YACR,YAAY;IAChB;IAEA,OAAO;QAAC;QAAW;KAAK;AAC1B;AAEA,SAAS,oCAAc,IAAY,EAAE,SAAiB,EAAE,SAAoB;IAC1E,OAAQ;QACN,KAAK;YACH,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,IAAI,SAAS,IACX,OAAO;YAET,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,QAAQ;YACR;IACJ;IAEA,OAAO;AACT","sources":["packages/react-stately/src/datepicker/IncompleteDate.ts"],"sourcesContent":["/*\n * Copyright 2026 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 {AnyDateTime, Calendar, CalendarDate, ZonedDateTime} from '@internationalized/date';\nimport {DateSegmentType} from './useDateFieldState';\nimport {DateValue} from './types';\n\ntype HourCycle = 'h12' | 'h11' | 'h23' | 'h24';\n\n/**\n * This class represents a date that is incomplete or otherwise invalid as a result of user editing.\n * For example, it can represent temporary dates such as February 31st if the user edits the day\n * before the month. Times are represented according to an hour cycle rather than always in 24 hour\n * time. This enables the user to adjust the day period (e.g. am/pm) independently from the hour.\n */\nexport class IncompleteDate {\n calendar: Calendar;\n era: string | null;\n year: number | null;\n month: number | null;\n day: number | null;\n hour: number | null;\n hourCycle: HourCycle;\n dayPeriod: number | null;\n minute: number | null;\n second: number | null;\n millisecond: number | null;\n offset: number | null;\n\n constructor(\n calendar: Calendar,\n hourCycle: HourCycle,\n dateValue?: Partial<Omit<AnyDateTime, 'copy'>> | null\n ) {\n this.era = dateValue?.era ?? null;\n this.calendar = calendar;\n this.year = dateValue?.year ?? null;\n this.month = dateValue?.month ?? null;\n this.day = dateValue?.day ?? null;\n this.hour = dateValue?.hour ?? null;\n this.hourCycle = hourCycle;\n this.dayPeriod = null;\n this.minute = dateValue?.minute ?? null;\n this.second = dateValue?.second ?? null;\n this.millisecond = dateValue?.millisecond ?? null;\n this.offset = 'offset' in (dateValue ?? {}) ? (dateValue as any).offset : null;\n\n // Convert the hour from 24 hour time to the given hour cycle.\n if (this.hour != null) {\n let [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);\n this.dayPeriod = dayPeriod;\n this.hour = hour;\n }\n }\n\n copy(): IncompleteDate {\n let res = new IncompleteDate(this.calendar, this.hourCycle);\n res.era = this.era;\n res.year = this.year;\n res.month = this.month;\n res.day = this.day;\n res.hour = this.hour;\n res.dayPeriod = this.dayPeriod;\n res.minute = this.minute;\n res.second = this.second;\n res.millisecond = this.millisecond;\n res.offset = this.offset;\n return res;\n }\n\n /** Checks whether all the specified segments have a value. */\n isComplete(segments: DateSegmentType[]) {\n return segments.every(segment => this[segment] != null);\n }\n\n /** Checks whether the given date value matches this value for the specified segments. */\n validate(dt: DateValue, segments: DateSegmentType[]) {\n return segments.every(segment => {\n if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {\n let [dayPeriod, hour] = toHourCycle(dt.hour, this.hourCycle);\n return this.dayPeriod === dayPeriod && this.hour === hour;\n }\n return this[segment] === dt[segment];\n });\n }\n\n /** Checks if the date is empty (i.e. all specified segments are null). */\n isCleared(segments: DateSegmentType[]): boolean {\n return segments.every(segment => this[segment] === null);\n }\n\n /** Sets the given field. */\n set(field: DateSegmentType, value: number | string, placeholder: DateValue): IncompleteDate {\n let result = this.copy();\n result[field] = value;\n if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) {\n result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n if (field === 'year' && result.era == null) {\n result.era = placeholder.era;\n }\n\n // clear offset when a date/time field changes since it may no longer be valid\n if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') {\n result.offset = null;\n }\n return result;\n }\n\n /** Sets the given field to null. */\n clear(field: DateSegmentType): IncompleteDate {\n let result = this.copy();\n // @ts-ignore\n result[field] = null;\n if (field === 'year') {\n result.era = null;\n }\n\n // clear offset when a field is cleared since it may no longer be valid\n result.offset = null;\n return result;\n }\n\n /**\n * Increments or decrements the given field. If it is null, then it is set to the placeholder\n * value.\n */\n cycle(\n field: DateSegmentType,\n amount: number,\n placeholder: DateValue,\n displaySegments: DateSegmentType[]\n ): IncompleteDate {\n let res = this.copy();\n\n // If field is null, default to placeholder.\n if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {\n if (field === 'hour' && 'hour' in placeholder) {\n let [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);\n res.dayPeriod = dayPeriod;\n res.hour = hour;\n } else {\n res[field] = placeholder[field];\n }\n if (field === 'year' && res.era == null) {\n res.era = placeholder.era;\n }\n\n return res;\n }\n\n switch (field) {\n case 'era': {\n let eras = this.calendar.getEras();\n let index = eras.indexOf(res.era!);\n index = cycleValue(index, amount, 0, eras.length - 1);\n res.era = eras[index];\n break;\n }\n case 'year': {\n // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.\n let date = new CalendarDate(\n this.calendar,\n this.era ?? placeholder.era,\n this.year ?? placeholder.year,\n this.month ?? 1,\n this.day ?? 1\n );\n date = date.cycle(field, amount, {round: field === 'year'});\n res.era = date.era;\n res.year = date.year;\n break;\n }\n case 'month':\n res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());\n break;\n case 'day':\n // Allow incrementing up to the maximum number of days in any month.\n res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());\n break;\n case 'hour': {\n // if date is fully defined or it is just a time field, and we have a time zone, use toValue to get a ZonedDateTime to cycle\n // so DST fallback is properly handled\n let hasDateSegements = displaySegments.some(s => ['year', 'month', 'day'].includes(s));\n if (\n 'timeZone' in placeholder &&\n (!hasDateSegements || (res.year != null && res.month != null && res.day != null))\n ) {\n let date = this.toValue(placeholder) as ZonedDateTime;\n date = date.cycle('hour', amount, {\n hourCycle: this.hourCycle === 'h12' ? 12 : 24,\n round: false\n });\n let [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);\n res.hour = adjustedHour;\n res.dayPeriod = dayPeriod;\n res.offset = date.offset;\n } else {\n let hours = res.hour ?? 0;\n let limits = this.getSegmentLimits('hour')!;\n res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);\n if (res.dayPeriod == null && 'hour' in placeholder) {\n res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n }\n break;\n }\n case 'dayPeriod':\n res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);\n break;\n case 'minute':\n res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);\n break;\n case 'second':\n res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);\n break;\n }\n\n return res;\n }\n\n /**\n * Converts the incomplete date to a full date value, using the provided value for any unset\n * fields.\n */\n toValue(value: DateValue): DateValue {\n if ('hour' in value) {\n let hour = this.hour;\n if (hour != null) {\n hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);\n } else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') {\n hour = this.dayPeriod === 1 ? 12 : 0;\n }\n\n let res = value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day,\n hour: hour ?? value.hour,\n minute: this.minute ?? value.minute,\n second: this.second ?? value.second,\n millisecond: this.millisecond ?? value.millisecond\n });\n\n if ('offset' in res && this.offset != null && res.offset !== this.offset) {\n res = res.add({milliseconds: res.offset - this.offset});\n }\n\n return res;\n } else {\n return value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day\n });\n }\n }\n\n getSegmentLimits(\n type: string\n ): {value: number | null; minValue: number; maxValue: number} | undefined {\n switch (type) {\n case 'era': {\n let eras = this.calendar.getEras();\n return {\n value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,\n minValue: 0,\n maxValue: eras.length - 1\n };\n }\n case 'year':\n return {\n value: this.year,\n minValue: 1,\n maxValue: 9999\n };\n case 'month':\n return {\n value: this.month,\n minValue: 1,\n maxValue: this.calendar.getMaximumMonthsInYear()\n };\n case 'day':\n return {\n value: this.day,\n minValue: 1,\n maxValue: this.calendar.getMaximumDaysInMonth()\n };\n case 'dayPeriod': {\n return {\n value: this.dayPeriod,\n minValue: 0,\n maxValue: 1\n };\n }\n case 'hour': {\n let minValue = 0;\n let maxValue = 23;\n if (this.hourCycle === 'h12') {\n minValue = 1;\n maxValue = 12;\n } else if (this.hourCycle === 'h11') {\n minValue = 0;\n maxValue = 11;\n }\n\n return {\n value: this.hour,\n minValue,\n maxValue\n };\n }\n case 'minute':\n return {\n value: this.minute,\n minValue: 0,\n maxValue: 59\n };\n case 'second':\n return {\n value: this.second,\n minValue: 0,\n maxValue: 59\n };\n }\n }\n}\n\nfunction cycleValue(value: number, amount: number, min: number, max: number, round = false) {\n if (round) {\n value += Math.sign(amount);\n\n if (value < min) {\n value = max;\n }\n\n let div = Math.abs(amount);\n if (amount > 0) {\n value = Math.ceil(value / div) * div;\n } else {\n value = Math.floor(value / div) * div;\n }\n\n if (value > max) {\n value = min;\n }\n } else {\n value += amount;\n if (value < min) {\n value = max - (min - value - 1);\n } else if (value > max) {\n value = min + (value - max - 1);\n }\n }\n\n return value;\n}\n\nfunction toHourCycle(hour: number, hourCycle: HourCycle): [number | null, number] {\n let dayPeriod: number | null = hour >= 12 ? 1 : 0;\n switch (hourCycle) {\n case 'h11':\n // Hours are numbered from 0 to 11. Used in Japan.\n if (hour >= 12) {\n hour -= 12;\n }\n break;\n case 'h12':\n // Hours are numbered from 12 (representing 0) to 11.\n if (hour === 0) {\n hour = 12;\n } else if (hour > 12) {\n hour -= 12;\n }\n break;\n case 'h23':\n // 24 hour time, numbered 0 to 23.\n dayPeriod = null;\n break;\n case 'h24':\n // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.\n hour += 1;\n dayPeriod = null;\n }\n\n return [dayPeriod, hour];\n}\n\nfunction fromHourCycle(hour: number, dayPeriod: number, hourCycle: HourCycle): number {\n switch (hourCycle) {\n case 'h11':\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h12':\n if (hour === 12) {\n hour = 0;\n }\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h24':\n hour -= 1;\n break;\n }\n\n return hour;\n}\n"],"names":[],"version":3,"file":"IncompleteDate.cjs.map"}
|
|
@@ -59,7 +59,10 @@ class $79f9316e7c43839c$export$ae165b50d181e1ef {
|
|
|
59
59
|
result.offset = null;
|
|
60
60
|
return result;
|
|
61
61
|
}
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Increments or decrements the given field. If it is null, then it is set to the placeholder
|
|
64
|
+
* value.
|
|
65
|
+
*/ cycle(field, amount, placeholder, displaySegments) {
|
|
63
66
|
let res = this.copy();
|
|
64
67
|
// If field is null, default to placeholder.
|
|
65
68
|
if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {
|
|
@@ -144,7 +147,10 @@ class $79f9316e7c43839c$export$ae165b50d181e1ef {
|
|
|
144
147
|
}
|
|
145
148
|
return res;
|
|
146
149
|
}
|
|
147
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Converts the incomplete date to a full date value, using the provided value for any unset
|
|
152
|
+
* fields.
|
|
153
|
+
*/ toValue(value) {
|
|
148
154
|
var _this_era, _this_year, _this_month, _this_day;
|
|
149
155
|
if ('hour' in value) {
|
|
150
156
|
let hour = this.hour;
|