@proyecto-viviana/solid-stately 0.5.0 → 0.6.0-rc.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/LICENSE-APACHE-2.0 +201 -0
- package/NOTICE +91 -0
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -1
- package/dist/autocomplete/createAutocompleteState.d.ts.map +1 -0
- package/dist/autocomplete/index.d.ts +1 -0
- package/dist/autocomplete/index.d.ts.map +1 -0
- package/dist/calendar/IncompleteDate.d.ts +2 -1
- package/dist/calendar/IncompleteDate.d.ts.map +1 -0
- package/dist/calendar/createCalendarState.d.ts +7 -8
- package/dist/calendar/createCalendarState.d.ts.map +1 -0
- package/dist/calendar/createDateFieldState.d.ts +4 -20
- package/dist/calendar/createDateFieldState.d.ts.map +1 -0
- package/dist/calendar/createDatePickerState.d.ts +2 -7
- package/dist/calendar/createDatePickerState.d.ts.map +1 -0
- package/dist/calendar/createRangeCalendarState.d.ts +7 -7
- package/dist/calendar/createRangeCalendarState.d.ts.map +1 -0
- package/dist/calendar/createTimeFieldState.d.ts +4 -23
- package/dist/calendar/createTimeFieldState.d.ts.map +1 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.d.ts.map +1 -0
- package/dist/calendar/intl/index.d.ts +1 -0
- package/dist/calendar/intl/index.d.ts.map +1 -0
- package/dist/checkbox/createCheckboxGroupState.d.ts +1 -0
- package/dist/checkbox/createCheckboxGroupState.d.ts.map +1 -0
- package/dist/checkbox/index.d.ts +1 -0
- package/dist/checkbox/index.d.ts.map +1 -0
- package/dist/collections/ListCollection.d.ts +5 -0
- package/dist/collections/ListCollection.d.ts.map +1 -0
- package/dist/collections/createListState.d.ts +2 -6
- package/dist/collections/createListState.d.ts.map +1 -0
- package/dist/collections/createMenuState.d.ts +30 -13
- package/dist/collections/createMenuState.d.ts.map +1 -0
- package/dist/collections/createSelectionState.d.ts +2 -5
- package/dist/collections/createSelectionState.d.ts.map +1 -0
- package/dist/collections/getChildNodes.d.ts +6 -3
- package/dist/collections/getChildNodes.d.ts.map +1 -0
- package/dist/collections/index.d.ts +2 -1
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/collections/types.d.ts +36 -2
- package/dist/collections/types.d.ts.map +1 -0
- package/dist/color/Color.d.ts +7 -1
- package/dist/color/Color.d.ts.map +1 -0
- package/dist/color/createColorAreaState.d.ts +2 -5
- package/dist/color/createColorAreaState.d.ts.map +1 -0
- package/dist/color/createColorFieldState.d.ts +2 -5
- package/dist/color/createColorFieldState.d.ts.map +1 -0
- package/dist/color/createColorSliderState.d.ts +2 -5
- package/dist/color/createColorSliderState.d.ts.map +1 -0
- package/dist/color/createColorWheelState.d.ts +2 -5
- package/dist/color/createColorWheelState.d.ts.map +1 -0
- package/dist/color/getColorChannels.d.ts +3 -0
- package/dist/color/getColorChannels.d.ts.map +1 -0
- package/dist/color/index.d.ts +2 -1
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/intl/index.d.ts +1 -0
- package/dist/color/intl/index.d.ts.map +1 -0
- package/dist/color/types.d.ts +2 -1
- package/dist/color/types.d.ts.map +1 -0
- package/dist/combobox/createComboBoxState.d.ts +4 -8
- package/dist/combobox/createComboBoxState.d.ts.map +1 -0
- package/dist/combobox/index.d.ts +1 -0
- package/dist/combobox/index.d.ts.map +1 -0
- package/dist/data/createAsyncList.d.ts +1 -7
- package/dist/data/createAsyncList.d.ts.map +1 -0
- package/dist/data/createListData.d.ts +1 -6
- package/dist/data/createListData.d.ts.map +1 -0
- package/dist/data/createTreeData.d.ts +1 -6
- package/dist/data/createTreeData.d.ts.map +1 -0
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/datepicker/index.d.ts +1 -0
- package/dist/datepicker/index.d.ts.map +1 -0
- package/dist/disclosure/createDisclosureState.d.ts +2 -5
- package/dist/disclosure/createDisclosureState.d.ts.map +1 -0
- package/dist/disclosure/index.d.ts +1 -0
- package/dist/disclosure/index.d.ts.map +1 -0
- package/dist/dnd/createDragState.d.ts +2 -6
- package/dist/dnd/createDragState.d.ts.map +1 -0
- package/dist/dnd/createDraggableCollectionState.d.ts +39 -10
- package/dist/dnd/createDraggableCollectionState.d.ts.map +1 -0
- package/dist/dnd/createDropState.d.ts +2 -6
- package/dist/dnd/createDropState.d.ts.map +1 -0
- package/dist/dnd/createDroppableCollectionState.d.ts +28 -11
- package/dist/dnd/createDroppableCollectionState.d.ts.map +1 -0
- package/dist/dnd/index.d.ts +3 -2
- package/dist/dnd/index.d.ts.map +1 -0
- package/dist/dnd/types.d.ts +17 -0
- package/dist/dnd/types.d.ts.map +1 -0
- package/dist/flags/flags.d.ts +5 -0
- package/dist/flags/flags.d.ts.map +1 -0
- package/dist/form/createFormValidationState.d.ts +2 -9
- package/{src → dist}/form/createFormValidationState.d.ts.map +1 -1
- package/dist/form/index.d.ts +1 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/grid/createGridState.d.ts +3 -2
- package/dist/grid/createGridState.d.ts.map +1 -0
- package/dist/grid/index.d.ts +1 -0
- package/dist/grid/index.d.ts.map +1 -0
- package/dist/grid/types.d.ts +23 -1
- package/dist/grid/types.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3016 -1579
- package/dist/index.js.map +1 -1
- package/dist/menu/index.d.ts +2 -1
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/numberfield/createNumberFieldState.d.ts +31 -6
- package/dist/numberfield/createNumberFieldState.d.ts.map +1 -0
- package/dist/numberfield/index.d.ts +1 -0
- package/dist/numberfield/index.d.ts.map +1 -0
- package/dist/overlays/createOverlayTriggerState.d.ts +12 -1
- package/dist/overlays/createOverlayTriggerState.d.ts.map +1 -0
- package/dist/overlays/index.d.ts +1 -0
- package/dist/overlays/index.d.ts.map +1 -0
- package/dist/private/flags/flags.js +26 -0
- package/dist/private/flags/flags.js.map +1 -0
- package/dist/radio/createRadioGroupState.d.ts +1 -0
- package/dist/radio/createRadioGroupState.d.ts.map +1 -0
- package/dist/radio/index.d.ts +1 -0
- package/dist/radio/index.d.ts.map +1 -0
- package/dist/searchfield/createSearchFieldState.d.ts +2 -5
- package/dist/searchfield/createSearchFieldState.d.ts.map +1 -0
- package/dist/searchfield/index.d.ts +1 -0
- package/dist/searchfield/index.d.ts.map +1 -0
- package/dist/select/createSelectState.d.ts +17 -6
- package/dist/select/createSelectState.d.ts.map +1 -0
- package/dist/select/index.d.ts +1 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/selection/Selection.d.ts +2 -1
- package/dist/selection/Selection.d.ts.map +1 -0
- package/dist/selection/SelectionManager.d.ts +1 -19
- package/dist/selection/SelectionManager.d.ts.map +1 -0
- package/dist/selection/createMultipleSelectionState.d.ts +2 -13
- package/dist/selection/createMultipleSelectionState.d.ts.map +1 -0
- package/dist/selection/index.d.ts +1 -0
- package/dist/selection/index.d.ts.map +1 -0
- package/dist/slider/createSliderState.d.ts +2 -5
- package/dist/slider/createSliderState.d.ts.map +1 -0
- package/dist/slider/index.d.ts +1 -0
- package/dist/slider/index.d.ts.map +1 -0
- package/dist/ssr/index.d.ts +2 -7
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/steplist/createStepListState.d.ts +2 -5
- package/dist/steplist/createStepListState.d.ts.map +1 -0
- package/dist/steplist/index.d.ts +1 -0
- package/dist/steplist/index.d.ts.map +1 -0
- package/dist/table/TableCollection.d.ts +1 -0
- package/dist/table/TableCollection.d.ts.map +1 -0
- package/dist/table/createTableColumnResizeState.d.ts +2 -9
- package/dist/table/createTableColumnResizeState.d.ts.map +1 -0
- package/dist/table/createTableState.d.ts +2 -5
- package/dist/table/createTableState.d.ts.map +1 -0
- package/dist/table/createTreeGridState.d.ts +2 -8
- package/dist/table/createTreeGridState.d.ts.map +1 -0
- package/dist/table/index.d.ts +1 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/types.d.ts +35 -1
- package/dist/table/types.d.ts.map +1 -0
- package/dist/tabs/createTabListState.d.ts +2 -5
- package/dist/tabs/createTabListState.d.ts.map +1 -0
- package/dist/tabs/index.d.ts +1 -0
- package/dist/tabs/index.d.ts.map +1 -0
- package/dist/textfield/createTextFieldState.d.ts +1 -0
- package/dist/textfield/createTextFieldState.d.ts.map +1 -0
- package/dist/textfield/index.d.ts +1 -0
- package/dist/textfield/index.d.ts.map +1 -0
- package/dist/toast/createToastState.d.ts +2 -5
- package/dist/toast/createToastState.d.ts.map +1 -0
- package/dist/toast/index.d.ts +1 -0
- package/dist/toast/index.d.ts.map +1 -0
- package/dist/toggle/createToggleGroupState.d.ts +1 -0
- package/dist/toggle/createToggleGroupState.d.ts.map +1 -0
- package/dist/toggle/createToggleState.d.ts +1 -0
- package/dist/toggle/createToggleState.d.ts.map +1 -0
- package/dist/toggle/index.d.ts +1 -0
- package/dist/toggle/index.d.ts.map +1 -0
- package/dist/tokenfield/TokenFieldValue.d.ts +72 -0
- package/dist/tokenfield/TokenFieldValue.d.ts.map +1 -0
- package/dist/tokenfield/createTokenFieldState.d.ts +33 -0
- package/dist/tokenfield/createTokenFieldState.d.ts.map +1 -0
- package/dist/tokenfield/index.d.ts +3 -0
- package/dist/tokenfield/index.d.ts.map +1 -0
- package/dist/tooltip/createTooltipTriggerState.d.ts +9 -8
- package/dist/tooltip/createTooltipTriggerState.d.ts.map +1 -0
- package/dist/tooltip/index.d.ts +1 -0
- package/dist/tooltip/index.d.ts.map +1 -0
- package/dist/tree/TreeCollection.d.ts +1 -0
- package/dist/tree/TreeCollection.d.ts.map +1 -0
- package/dist/tree/createTreeState.d.ts +2 -7
- package/{src → dist}/tree/createTreeState.d.ts.map +1 -1
- package/dist/tree/index.d.ts +1 -0
- package/dist/tree/index.d.ts.map +1 -0
- package/dist/tree/types.d.ts +19 -1
- package/dist/tree/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/owner.d.ts +9 -0
- package/dist/utils/owner.d.ts.map +1 -0
- package/dist/utils/reactivity.d.ts +19 -0
- package/dist/utils/reactivity.d.ts.map +1 -0
- package/package.json +23 -9
- package/src/autocomplete/createAutocompleteState.ts +18 -4
- package/src/calendar/IncompleteDate.ts +15 -1
- package/src/calendar/createCalendarState.ts +194 -79
- package/src/calendar/createDateFieldState.ts +60 -42
- package/src/calendar/createDatePickerState.ts +32 -14
- package/src/calendar/createRangeCalendarState.ts +136 -74
- package/src/calendar/createTimeFieldState.ts +25 -6
- package/src/calendar/intl/index.ts +205 -142
- package/src/checkbox/createCheckboxGroupState.ts +29 -13
- package/src/collections/ListCollection.ts +31 -0
- package/src/collections/createListState.ts +23 -6
- package/src/collections/createMenuState.ts +59 -14
- package/src/collections/createSelectionState.ts +32 -12
- package/src/collections/getChildNodes.ts +20 -3
- package/src/collections/index.ts +2 -0
- package/src/collections/types.ts +35 -2
- package/src/color/Color.ts +66 -29
- package/src/color/createColorAreaState.ts +29 -4
- package/src/color/createColorFieldState.ts +37 -11
- package/src/color/createColorSliderState.ts +36 -7
- package/src/color/createColorWheelState.ts +20 -4
- package/src/color/getColorChannels.ts +16 -0
- package/src/color/index.ts +1 -0
- package/src/color/intl/index.ts +890 -855
- package/src/color/types.ts +1 -1
- package/src/combobox/createComboBoxState.ts +178 -195
- package/src/data/createAsyncList.ts +22 -2
- package/src/data/createListData.ts +19 -2
- package/src/data/createTreeData.ts +19 -3
- package/src/disclosure/createDisclosureState.ts +40 -19
- package/src/dnd/createDragState.ts +22 -4
- package/src/dnd/createDraggableCollectionState.ts +137 -10
- package/src/dnd/createDropState.ts +21 -3
- package/src/dnd/createDroppableCollectionState.ts +117 -11
- package/src/dnd/index.ts +4 -0
- package/src/dnd/types.ts +16 -0
- package/src/flags/flags.ts +25 -0
- package/src/form/createFormValidationState.ts +54 -36
- package/src/grid/createGridState.ts +187 -109
- package/src/grid/types.ts +22 -1
- package/src/index.ts +15 -0
- package/src/menu/index.ts +2 -0
- package/src/numberfield/createNumberFieldState.ts +153 -66
- package/src/overlays/createOverlayTriggerState.ts +31 -4
- package/src/radio/createRadioGroupState.ts +19 -5
- package/src/searchfield/createSearchFieldState.ts +18 -3
- package/src/select/createSelectState.ts +73 -8
- package/src/selection/Selection.ts +15 -1
- package/src/selection/SelectionManager.ts +14 -0
- package/src/selection/createMultipleSelectionState.ts +44 -25
- package/src/slider/createSliderState.ts +20 -5
- package/src/ssr/index.ts +27 -4
- package/src/steplist/createStepListState.ts +38 -17
- package/src/table/TableCollection.ts +14 -0
- package/src/table/createTableColumnResizeState.ts +20 -3
- package/src/table/createTableState.ts +22 -1
- package/src/table/createTreeGridState.ts +21 -4
- package/src/table/types.ts +36 -3
- package/src/tabs/createTabListState.ts +77 -34
- package/src/textfield/createTextFieldState.ts +17 -3
- package/src/toast/createToastState.ts +28 -3
- package/src/toggle/createToggleGroupState.ts +20 -5
- package/src/toggle/createToggleState.ts +19 -4
- package/src/tokenfield/TokenFieldValue.ts +440 -0
- package/src/tokenfield/createTokenFieldState.ts +88 -0
- package/src/tokenfield/index.ts +14 -0
- package/src/tooltip/createTooltipTriggerState.ts +49 -13
- package/src/tree/TreeCollection.ts +14 -0
- package/src/tree/createTreeState.ts +62 -35
- package/src/tree/types.ts +18 -1
- package/src/utils/index.ts +9 -1
- package/src/utils/owner.ts +20 -0
- package/src/utils/reactivity.ts +45 -1
- package/src/autocomplete/createAutocompleteState.d.ts +0 -48
- package/src/autocomplete/createAutocompleteState.d.ts.map +0 -1
- package/src/autocomplete/index.d.ts +0 -6
- package/src/autocomplete/index.d.ts.map +0 -1
- package/src/calendar/createCalendarState.d.ts +0 -152
- package/src/calendar/createCalendarState.d.ts.map +0 -1
- package/src/calendar/createDateFieldState.d.ts +0 -145
- package/src/calendar/createDateFieldState.d.ts.map +0 -1
- package/src/calendar/createRangeCalendarState.d.ts +0 -171
- package/src/calendar/createRangeCalendarState.d.ts.map +0 -1
- package/src/calendar/createTimeFieldState.d.ts +0 -97
- package/src/calendar/createTimeFieldState.d.ts.map +0 -1
- package/src/calendar/index.d.ts +0 -80
- package/src/calendar/index.d.ts.map +0 -1
- package/src/checkbox/createCheckboxGroupState.d.ts +0 -73
- package/src/checkbox/createCheckboxGroupState.d.ts.map +0 -1
- package/src/checkbox/index.d.ts +0 -6
- package/src/checkbox/index.d.ts.map +0 -1
- package/src/collections/ListCollection.d.ts +0 -40
- package/src/collections/ListCollection.d.ts.map +0 -1
- package/src/collections/createListState.d.ts +0 -94
- package/src/collections/createListState.d.ts.map +0 -1
- package/src/collections/createMenuState.d.ts +0 -55
- package/src/collections/createMenuState.d.ts.map +0 -1
- package/src/collections/createSelectionState.d.ts +0 -89
- package/src/collections/createSelectionState.d.ts.map +0 -1
- package/src/collections/index.d.ts +0 -38
- package/src/collections/index.d.ts.map +0 -1
- package/src/collections/types.d.ts +0 -147
- package/src/collections/types.d.ts.map +0 -1
- package/src/color/Color.d.ts +0 -43
- package/src/color/Color.d.ts.map +0 -1
- package/src/color/createColorAreaState.d.ts +0 -78
- package/src/color/createColorAreaState.d.ts.map +0 -1
- package/src/color/createColorFieldState.d.ts +0 -57
- package/src/color/createColorFieldState.d.ts.map +0 -1
- package/src/color/createColorSliderState.d.ts +0 -69
- package/src/color/createColorSliderState.d.ts.map +0 -1
- package/src/color/createColorWheelState.d.ts +0 -53
- package/src/color/createColorWheelState.d.ts.map +0 -1
- package/src/color/index.d.ts +0 -39
- package/src/color/index.d.ts.map +0 -1
- package/src/color/types.d.ts +0 -111
- package/src/color/types.d.ts.map +0 -1
- package/src/combobox/createComboBoxState.d.ts +0 -127
- package/src/combobox/createComboBoxState.d.ts.map +0 -1
- package/src/combobox/index.d.ts +0 -13
- package/src/combobox/index.d.ts.map +0 -1
- package/src/disclosure/createDisclosureState.d.ts +0 -68
- package/src/disclosure/createDisclosureState.d.ts.map +0 -1
- package/src/disclosure/index.d.ts +0 -10
- package/src/disclosure/index.d.ts.map +0 -1
- package/src/dnd/createDragState.d.ts +0 -68
- package/src/dnd/createDragState.d.ts.map +0 -1
- package/src/dnd/createDraggableCollectionState.d.ts +0 -68
- package/src/dnd/createDraggableCollectionState.d.ts.map +0 -1
- package/src/dnd/createDropState.d.ts +0 -80
- package/src/dnd/createDropState.d.ts.map +0 -1
- package/src/dnd/createDroppableCollectionState.d.ts +0 -107
- package/src/dnd/createDroppableCollectionState.d.ts.map +0 -1
- package/src/dnd/index.d.ts +0 -60
- package/src/dnd/index.d.ts.map +0 -1
- package/src/dnd/types.d.ts +0 -277
- package/src/dnd/types.d.ts.map +0 -1
- package/src/form/createFormValidationState.d.ts +0 -102
- package/src/form/index.d.ts +0 -16
- package/src/form/index.d.ts.map +0 -1
- package/src/grid/createGridState.d.ts +0 -15
- package/src/grid/createGridState.d.ts.map +0 -1
- package/src/grid/index.d.ts +0 -7
- package/src/grid/index.d.ts.map +0 -1
- package/src/grid/types.d.ts +0 -163
- package/src/grid/types.d.ts.map +0 -1
- package/src/index.d.ts +0 -311
- package/src/index.d.ts.map +0 -1
- package/src/numberfield/createNumberFieldState.d.ts +0 -67
- package/src/numberfield/createNumberFieldState.d.ts.map +0 -1
- package/src/numberfield/index.d.ts +0 -6
- package/src/numberfield/index.d.ts.map +0 -1
- package/src/overlays/createOverlayTriggerState.d.ts +0 -34
- package/src/overlays/createOverlayTriggerState.d.ts.map +0 -1
- package/src/overlays/index.d.ts +0 -6
- package/src/overlays/index.d.ts.map +0 -1
- package/src/radio/createRadioGroupState.d.ts +0 -79
- package/src/radio/createRadioGroupState.d.ts.map +0 -1
- package/src/radio/index.d.ts +0 -7
- package/src/radio/index.d.ts.map +0 -1
- package/src/searchfield/createSearchFieldState.d.ts +0 -27
- package/src/searchfield/createSearchFieldState.d.ts.map +0 -1
- package/src/searchfield/index.d.ts +0 -3
- package/src/searchfield/index.d.ts.map +0 -1
- package/src/select/createSelectState.d.ts +0 -75
- package/src/select/createSelectState.d.ts.map +0 -1
- package/src/select/index.d.ts +0 -2
- package/src/select/index.d.ts.map +0 -1
- package/src/slider/createSliderState.d.ts +0 -72
- package/src/slider/createSliderState.d.ts.map +0 -1
- package/src/slider/index.d.ts +0 -3
- package/src/slider/index.d.ts.map +0 -1
- package/src/ssr/index.d.ts +0 -28
- package/src/ssr/index.d.ts.map +0 -1
- package/src/table/TableCollection.d.ts +0 -54
- package/src/table/TableCollection.d.ts.map +0 -1
- package/src/table/createTableState.d.ts +0 -15
- package/src/table/createTableState.d.ts.map +0 -1
- package/src/table/index.d.ts +0 -18
- package/src/table/index.d.ts.map +0 -1
- package/src/table/types.d.ts +0 -145
- package/src/table/types.d.ts.map +0 -1
- package/src/tabs/createTabListState.d.ts +0 -70
- package/src/tabs/createTabListState.d.ts.map +0 -1
- package/src/tabs/index.d.ts +0 -8
- package/src/tabs/index.d.ts.map +0 -1
- package/src/textfield/createTextFieldState.d.ts +0 -32
- package/src/textfield/createTextFieldState.d.ts.map +0 -1
- package/src/textfield/index.d.ts +0 -6
- package/src/textfield/index.d.ts.map +0 -1
- package/src/toast/createToastState.d.ts +0 -129
- package/src/toast/createToastState.d.ts.map +0 -1
- package/src/toast/index.d.ts +0 -12
- package/src/toast/index.d.ts.map +0 -1
- package/src/toggle/createToggleState.d.ts +0 -34
- package/src/toggle/createToggleState.d.ts.map +0 -1
- package/src/toggle/index.d.ts +0 -2
- package/src/toggle/index.d.ts.map +0 -1
- package/src/tooltip/createTooltipTriggerState.d.ts +0 -39
- package/src/tooltip/createTooltipTriggerState.d.ts.map +0 -1
- package/src/tooltip/index.d.ts +0 -7
- package/src/tooltip/index.d.ts.map +0 -1
- package/src/tree/TreeCollection.d.ts +0 -43
- package/src/tree/TreeCollection.d.ts.map +0 -1
- package/src/tree/createTreeState.d.ts +0 -17
- package/src/tree/index.d.ts +0 -13
- package/src/tree/index.d.ts.map +0 -1
- package/src/tree/types.d.ts +0 -162
- package/src/tree/types.d.ts.map +0 -1
- package/src/utils/index.d.ts +0 -2
- package/src/utils/index.d.ts.map +0 -1
- package/src/utils/reactivity.d.ts +0 -28
- package/src/utils/reactivity.d.ts.map +0 -1
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Ported to SolidJS for Proyecto Viviana; based on packages/react-stately/src/calendar/useCalendarState.ts
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* CalendarState for Solid-Stately
|
|
3
17
|
*
|
|
@@ -5,7 +19,8 @@
|
|
|
5
19
|
* Based on @react-stately/calendar useCalendarState
|
|
6
20
|
*/
|
|
7
21
|
|
|
8
|
-
import {
|
|
22
|
+
import { createMemo, createEffect } from "solid-js";
|
|
23
|
+
import type { Accessor } from "solid-js";
|
|
9
24
|
import {
|
|
10
25
|
type Calendar as InternationalizedCalendar,
|
|
11
26
|
type CalendarDate,
|
|
@@ -25,8 +40,9 @@ import {
|
|
|
25
40
|
createCalendar as intlCreateCalendar,
|
|
26
41
|
toCalendar as intlToCalendar,
|
|
27
42
|
toCalendarDate as intlToCalendarDate,
|
|
43
|
+
minDate,
|
|
28
44
|
} from "@internationalized/date";
|
|
29
|
-
import { access, type MaybeAccessor } from "../utils";
|
|
45
|
+
import { access, createInternalSignal, readNow, type MaybeAccessor } from "../utils";
|
|
30
46
|
|
|
31
47
|
export type ValidationState = "valid" | "invalid";
|
|
32
48
|
export type CalendarPageBehavior = "single" | "visible";
|
|
@@ -75,7 +91,7 @@ export interface CalendarStateProps<
|
|
|
75
91
|
/** Callback that is called for each date in the calendar to determine if it is unavailable. */
|
|
76
92
|
isDateUnavailable?: (date: DateValue) => boolean;
|
|
77
93
|
/** The number of months to display at once. */
|
|
78
|
-
visibleMonths?: number
|
|
94
|
+
visibleMonths?: MaybeAccessor<number | undefined>;
|
|
79
95
|
/** Controls whether paging advances by one month or by the visible month range. */
|
|
80
96
|
pageBehavior?: CalendarPageBehavior;
|
|
81
97
|
/** Determines how the visible months align around the initial focused date. */
|
|
@@ -138,6 +154,10 @@ export interface CalendarState<
|
|
|
138
154
|
isOutsideVisibleRange: (date: DateValue) => boolean;
|
|
139
155
|
/** Whether a date is invalid. */
|
|
140
156
|
isInvalid: (date: DateValue) => boolean;
|
|
157
|
+
/** Whether the previous page is entirely outside min/max. */
|
|
158
|
+
isPreviousVisibleRangeInvalid: () => boolean;
|
|
159
|
+
/** Whether the next page is entirely outside min/max. */
|
|
160
|
+
isNextVisibleRangeInvalid: () => boolean;
|
|
141
161
|
/** Moves focus to the previous page (month). */
|
|
142
162
|
focusPreviousPage: () => void;
|
|
143
163
|
/** Moves focus to the next page (month). */
|
|
@@ -198,7 +218,7 @@ export function createCalendarState<
|
|
|
198
218
|
const calendar = createMemo(() =>
|
|
199
219
|
(props.createCalendar ?? intlCreateCalendar)(resolvedOptions().calendar as CalendarIdentifier),
|
|
200
220
|
);
|
|
201
|
-
const visibleMonths = props.visibleMonths ?? 1;
|
|
221
|
+
const visibleMonths = createMemo(() => Math.max(1, Number(access(props.visibleMonths) ?? 1)));
|
|
202
222
|
const firstDayOfWeekName = (): CalendarDayOfWeek | undefined =>
|
|
203
223
|
props.firstDayOfWeek == null ? undefined : dayOfWeekNames[props.firstDayOfWeek];
|
|
204
224
|
|
|
@@ -212,11 +232,11 @@ export function createCalendarState<
|
|
|
212
232
|
case "start":
|
|
213
233
|
return 0;
|
|
214
234
|
case "end":
|
|
215
|
-
return Math.max(visibleMonths - 1, 0);
|
|
235
|
+
return Math.max(visibleMonths() - 1, 0);
|
|
216
236
|
case "center":
|
|
217
237
|
default: {
|
|
218
|
-
let halfDuration = Math.floor(visibleMonths / 2);
|
|
219
|
-
if (halfDuration > 0 && visibleMonths % 2 === 0) {
|
|
238
|
+
let halfDuration = Math.floor(visibleMonths() / 2);
|
|
239
|
+
if (halfDuration > 0 && visibleMonths() % 2 === 0) {
|
|
220
240
|
halfDuration--;
|
|
221
241
|
}
|
|
222
242
|
return halfDuration;
|
|
@@ -232,7 +252,7 @@ export function createCalendarState<
|
|
|
232
252
|
const visibleRangeEnd = (start: CalendarDate): CalendarDate => {
|
|
233
253
|
let end = endOfMonth(start);
|
|
234
254
|
|
|
235
|
-
for (let i = 1; i < visibleMonths; i++) {
|
|
255
|
+
for (let i = 1; i < visibleMonths(); i++) {
|
|
236
256
|
end = endOfMonth(end.add({ months: 1 }));
|
|
237
257
|
}
|
|
238
258
|
|
|
@@ -280,18 +300,19 @@ export function createCalendarState<
|
|
|
280
300
|
|
|
281
301
|
// State signals
|
|
282
302
|
const initialFocusedDate = constrainDate(getInitialFocusedDate());
|
|
283
|
-
const [internalValue, setInternalValue] =
|
|
303
|
+
const [internalValue, setInternalValue] = createInternalSignal<T | T[] | null>(
|
|
284
304
|
(props.defaultValue as T | T[] | null) ?? null,
|
|
285
305
|
);
|
|
286
|
-
const [focusedDate, setFocusedDateInternal] =
|
|
287
|
-
|
|
306
|
+
const [focusedDate, setFocusedDateInternal] =
|
|
307
|
+
createInternalSignal<CalendarDate>(initialFocusedDate);
|
|
308
|
+
const [visibleRangeStart, setVisibleRangeStart] = createInternalSignal<CalendarDate>(
|
|
288
309
|
alignVisibleRangeStart(initialFocusedDate),
|
|
289
310
|
);
|
|
290
311
|
// Init from autoFocus, mirroring @react-stately useCalendarState
|
|
291
312
|
// (`useState(props.autoFocus || false)`). Without autoFocus the calendar
|
|
292
313
|
// mounts unfocused and never steals DOM focus.
|
|
293
|
-
const [isFocused, setFocused] =
|
|
294
|
-
const [isPaginating, setIsPaginating] =
|
|
314
|
+
const [isFocused, setFocused] = createInternalSignal(props.autoFocus ?? false);
|
|
315
|
+
const [isPaginating, setIsPaginating] = createInternalSignal(false);
|
|
295
316
|
|
|
296
317
|
// Controlled vs uncontrolled value
|
|
297
318
|
const sourceValue = createMemo<T | T[] | null>(() => {
|
|
@@ -312,75 +333,96 @@ export function createCalendarState<
|
|
|
312
333
|
const validationState = createMemo(() => access(props.validationState));
|
|
313
334
|
const isValueInvalid = createMemo(() => validationState() === "invalid");
|
|
314
335
|
|
|
315
|
-
// Visible range based on the paged range start.
|
|
316
|
-
|
|
336
|
+
// Visible range based on the paged range start. Function (not memo) so
|
|
337
|
+
// onFocusChange snapshots see the live page after a same-turn write.
|
|
338
|
+
const visibleRange = () => {
|
|
317
339
|
const start = visibleRangeStart();
|
|
318
340
|
const end = visibleRangeEnd(start);
|
|
319
341
|
|
|
320
342
|
return { start, end };
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const syncVisibleRangeForFocusedDate = (nextFocusedDate: CalendarDate) => {
|
|
324
|
-
const range = visibleRange();
|
|
343
|
+
};
|
|
325
344
|
|
|
345
|
+
const syncVisibleRangeForFocusedDate = (
|
|
346
|
+
nextFocusedDate: CalendarDate,
|
|
347
|
+
range: { start: CalendarDate; end: CalendarDate },
|
|
348
|
+
months: number,
|
|
349
|
+
) => {
|
|
326
350
|
if (nextFocusedDate.compare(range.start) < 0) {
|
|
327
|
-
setVisibleRangeStart(startOfMonth(nextFocusedDate.subtract({ months:
|
|
351
|
+
setVisibleRangeStart(startOfMonth(nextFocusedDate.subtract({ months: months - 1 })));
|
|
328
352
|
} else if (nextFocusedDate.compare(range.end) > 0) {
|
|
329
353
|
setVisibleRangeStart(startOfMonth(nextFocusedDate));
|
|
330
354
|
}
|
|
331
355
|
};
|
|
332
356
|
|
|
333
|
-
createEffect(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
const currentFocusedDate = focusedDate();
|
|
359
|
-
const nextFocusedDate = constrainDate(currentFocusedDate);
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
nextFocusedDate.compare(currentFocusedDate) === 0 &&
|
|
363
|
-
isEqualCalendar(nextFocusedDate.calendar, currentFocusedDate.calendar)
|
|
364
|
-
) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
syncVisibleRangeForFocusedDate(nextFocusedDate);
|
|
369
|
-
setFocusedDateInternal(nextFocusedDate);
|
|
370
|
-
props.onFocusChange?.(nextFocusedDate);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
createEffect(() => {
|
|
374
|
-
const currentFocusedDate = focusedDate();
|
|
375
|
-
const nextFocusedDate = toDisplayCalendarDate(currentFocusedDate);
|
|
357
|
+
createEffect(
|
|
358
|
+
() => {
|
|
359
|
+
const controlledFocused = access(props.focusedValue);
|
|
360
|
+
if (!controlledFocused) return null;
|
|
361
|
+
return {
|
|
362
|
+
nextFocusedDate: constrainDate(toDisplayCalendarDate(controlledFocused)),
|
|
363
|
+
currentFocusedDate: focusedDate(),
|
|
364
|
+
range: visibleRange(),
|
|
365
|
+
months: visibleMonths(),
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
(data) => {
|
|
369
|
+
if (!data) return;
|
|
370
|
+
const { nextFocusedDate, currentFocusedDate, range, months } = data;
|
|
371
|
+
if (
|
|
372
|
+
nextFocusedDate.compare(currentFocusedDate) !== 0 ||
|
|
373
|
+
!isEqualCalendar(nextFocusedDate.calendar, currentFocusedDate.calendar)
|
|
374
|
+
) {
|
|
375
|
+
setFocusedDateInternal(nextFocusedDate);
|
|
376
|
+
}
|
|
377
|
+
syncVisibleRangeForFocusedDate(nextFocusedDate, range, months);
|
|
378
|
+
},
|
|
379
|
+
);
|
|
376
380
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
381
|
+
createEffect(
|
|
382
|
+
() => {
|
|
383
|
+
const controlledFocused = access(props.focusedValue);
|
|
384
|
+
if (controlledFocused) return null;
|
|
385
|
+
const currentFocusedDate = focusedDate();
|
|
386
|
+
const nextFocusedDate = constrainDate(currentFocusedDate);
|
|
387
|
+
if (
|
|
388
|
+
nextFocusedDate.compare(currentFocusedDate) === 0 &&
|
|
389
|
+
isEqualCalendar(nextFocusedDate.calendar, currentFocusedDate.calendar)
|
|
390
|
+
) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
currentFocusedDate,
|
|
395
|
+
nextFocusedDate,
|
|
396
|
+
range: visibleRange(),
|
|
397
|
+
months: visibleMonths(),
|
|
398
|
+
};
|
|
399
|
+
},
|
|
400
|
+
(data) => {
|
|
401
|
+
if (!data) return;
|
|
402
|
+
syncVisibleRangeForFocusedDate(data.nextFocusedDate, data.range, data.months);
|
|
403
|
+
setFocusedDateInternal(data.nextFocusedDate);
|
|
404
|
+
props.onFocusChange?.(data.nextFocusedDate);
|
|
405
|
+
},
|
|
406
|
+
);
|
|
380
407
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
408
|
+
createEffect(
|
|
409
|
+
() => {
|
|
410
|
+
const currentFocusedDate = focusedDate();
|
|
411
|
+
const nextFocusedDate = toDisplayCalendarDate(currentFocusedDate);
|
|
412
|
+
if (isEqualCalendar(currentFocusedDate.calendar, nextFocusedDate.calendar)) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
nextFocusedDate,
|
|
417
|
+
alignedStart: alignVisibleRangeStart(nextFocusedDate),
|
|
418
|
+
};
|
|
419
|
+
},
|
|
420
|
+
(data) => {
|
|
421
|
+
if (!data) return;
|
|
422
|
+
setFocusedDateInternal(data.nextFocusedDate);
|
|
423
|
+
setVisibleRangeStart(data.alignedStart);
|
|
424
|
+
},
|
|
425
|
+
);
|
|
384
426
|
|
|
385
427
|
// Format week days for headers
|
|
386
428
|
const weekDays = createMemo(() => {
|
|
@@ -408,22 +450,45 @@ export function createCalendarState<
|
|
|
408
450
|
return formatter.format(formattableMonth.toDate(timeZone));
|
|
409
451
|
});
|
|
410
452
|
|
|
453
|
+
// Walks previousAvailableDate from minValue ?? minDate(constrained, startDate)
|
|
454
|
+
// rather than from startDate alone, so a date before the visible month remains
|
|
455
|
+
// selectable when isDateUnavailable is set. Mirrors useCalendarState.normalizeValue.
|
|
456
|
+
const normalizeValue = (newValue: CalendarDate): T | null => {
|
|
457
|
+
const constrained = constrainDate(newValue);
|
|
458
|
+
const minBound = access(props.minValue);
|
|
459
|
+
const lowerBound =
|
|
460
|
+
minBound != null
|
|
461
|
+
? toDisplayCalendarDate(minBound)
|
|
462
|
+
: (minDate(constrained, visibleRange().start) ?? constrained);
|
|
463
|
+
const prev = previousAvailableDate(constrained, lowerBound, props.isDateUnavailable);
|
|
464
|
+
if (!prev) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const oldValue = sourceValue();
|
|
469
|
+
const referenceValue = Array.isArray(oldValue) ? (oldValue[0] ?? null) : oldValue;
|
|
470
|
+
return convertValue(prev, referenceValue) as T;
|
|
471
|
+
};
|
|
472
|
+
|
|
411
473
|
// Set value with onChange callback
|
|
412
474
|
const setValue = (newValue: T | T[] | null) => {
|
|
413
475
|
if (isDisabled() || isReadOnly()) return;
|
|
414
476
|
|
|
415
477
|
const oldValue = sourceValue();
|
|
416
|
-
const referenceValue = Array.isArray(oldValue) ? (oldValue[0] ?? null) : oldValue;
|
|
417
478
|
|
|
418
479
|
let nextValue: T | T[] | null;
|
|
419
480
|
if (newValue == null) {
|
|
420
481
|
nextValue = selectionMode() === "multiple" ? ([] as T[]) : null;
|
|
421
482
|
} else if (Array.isArray(newValue)) {
|
|
422
|
-
nextValue = newValue
|
|
423
|
-
(v) =>
|
|
424
|
-
|
|
483
|
+
nextValue = newValue
|
|
484
|
+
.map((v) => normalizeValue(toDisplayCalendarDate(v)))
|
|
485
|
+
.filter((v): v is T => v != null);
|
|
425
486
|
} else {
|
|
426
|
-
|
|
487
|
+
const localValue = normalizeValue(toDisplayCalendarDate(newValue));
|
|
488
|
+
if (!localValue) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
nextValue = localValue;
|
|
427
492
|
}
|
|
428
493
|
|
|
429
494
|
const controlled = access(props.value);
|
|
@@ -444,7 +509,7 @@ export function createCalendarState<
|
|
|
444
509
|
return;
|
|
445
510
|
}
|
|
446
511
|
|
|
447
|
-
syncVisibleRangeForFocusedDate(constrained);
|
|
512
|
+
syncVisibleRangeForFocusedDate(constrained, visibleRange(), visibleMonths());
|
|
448
513
|
setFocusedDateInternal(constrained);
|
|
449
514
|
props.onFocusChange?.(constrained);
|
|
450
515
|
};
|
|
@@ -510,10 +575,33 @@ export function createCalendarState<
|
|
|
510
575
|
return isCellDisabled(date) || isCellUnavailable(date);
|
|
511
576
|
};
|
|
512
577
|
|
|
578
|
+
// RAC `useCalendarState.ts` `isPreviousVisibleRangeInvalid` /
|
|
579
|
+
// `isNextVisibleRangeInvalid`: prev = startDate−1 invalid; next = endDate+1.
|
|
580
|
+
const isDateOutsideAllowedRange = (date: DateValue): boolean => {
|
|
581
|
+
const min = minValueState();
|
|
582
|
+
const max = maxValueState();
|
|
583
|
+
const calDate = toDisplayCalendarDate(date);
|
|
584
|
+
if (min && calDate.compare(toDisplayCalendarDate(min)) < 0) return true;
|
|
585
|
+
if (max && calDate.compare(toDisplayCalendarDate(max)) > 0) return true;
|
|
586
|
+
return false;
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
const isPreviousVisibleRangeInvalid = () => {
|
|
590
|
+
const start = visibleRange().start;
|
|
591
|
+
const previous = start.subtract({ days: 1 });
|
|
592
|
+
return isSameDay(previous, start) || isDateOutsideAllowedRange(previous);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
const isNextVisibleRangeInvalid = () => {
|
|
596
|
+
const end = visibleRange().end;
|
|
597
|
+
const next = end.add({ days: 1 });
|
|
598
|
+
return isSameDay(next, end) || isDateOutsideAllowedRange(next);
|
|
599
|
+
};
|
|
600
|
+
|
|
513
601
|
// Navigation methods
|
|
514
602
|
const focusPreviousPage = () => {
|
|
515
603
|
setIsPaginating(true);
|
|
516
|
-
const pageMonths = props.pageBehavior === "single" ? 1 : visibleMonths;
|
|
604
|
+
const pageMonths = props.pageBehavior === "single" ? 1 : visibleMonths();
|
|
517
605
|
const nextFocusedDate = constrainDate(focusedDate().subtract({ months: pageMonths }));
|
|
518
606
|
setFocusedDateInternal(nextFocusedDate);
|
|
519
607
|
setVisibleRangeStart(startOfMonth(visibleRangeStart().subtract({ months: pageMonths })));
|
|
@@ -523,7 +611,7 @@ export function createCalendarState<
|
|
|
523
611
|
|
|
524
612
|
const focusNextPage = () => {
|
|
525
613
|
setIsPaginating(true);
|
|
526
|
-
const pageMonths = props.pageBehavior === "single" ? 1 : visibleMonths;
|
|
614
|
+
const pageMonths = props.pageBehavior === "single" ? 1 : visibleMonths();
|
|
527
615
|
const nextFocusedDate = constrainDate(focusedDate().add({ months: pageMonths }));
|
|
528
616
|
setFocusedDateInternal(nextFocusedDate);
|
|
529
617
|
setVisibleRangeStart(startOfMonth(visibleRangeStart().add({ months: pageMonths })));
|
|
@@ -583,7 +671,7 @@ export function createCalendarState<
|
|
|
583
671
|
if (isReadOnly() || isDisabled()) return;
|
|
584
672
|
|
|
585
673
|
if (selectionMode() === "multiple") {
|
|
586
|
-
const current = value();
|
|
674
|
+
const current = access(props.value) !== undefined ? value() : readNow(internalValue);
|
|
587
675
|
const base: CalendarDate[] = Array.isArray(current)
|
|
588
676
|
? current.map((v) => toDisplayCalendarDate(v))
|
|
589
677
|
: current != null
|
|
@@ -655,6 +743,8 @@ export function createCalendarState<
|
|
|
655
743
|
isCellDisabled,
|
|
656
744
|
isOutsideVisibleRange,
|
|
657
745
|
isInvalid,
|
|
746
|
+
isPreviousVisibleRangeInvalid,
|
|
747
|
+
isNextVisibleRangeInvalid,
|
|
658
748
|
focusPreviousPage,
|
|
659
749
|
focusNextPage,
|
|
660
750
|
focusPreviousSection,
|
|
@@ -673,7 +763,9 @@ export function createCalendarState<
|
|
|
673
763
|
getWeeksInMonth: getWeeksInMonthFn,
|
|
674
764
|
weekDays,
|
|
675
765
|
title,
|
|
676
|
-
visibleMonths
|
|
766
|
+
get visibleMonths() {
|
|
767
|
+
return visibleMonths();
|
|
768
|
+
},
|
|
677
769
|
isPaginating,
|
|
678
770
|
};
|
|
679
771
|
}
|
|
@@ -695,3 +787,26 @@ function convertValue(newValue: CalendarDate, oldValue?: DateValue | null): Date
|
|
|
695
787
|
|
|
696
788
|
return localValue;
|
|
697
789
|
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Walks backward from `date` while it is unavailable and still at/after `minValue`.
|
|
793
|
+
* Mirrors @react-stately/calendar previousAvailableDate.
|
|
794
|
+
*/
|
|
795
|
+
function previousAvailableDate(
|
|
796
|
+
date: CalendarDate,
|
|
797
|
+
minValue: CalendarDate,
|
|
798
|
+
isDateUnavailable?: (date: DateValue) => boolean,
|
|
799
|
+
): CalendarDate | null {
|
|
800
|
+
if (!isDateUnavailable) {
|
|
801
|
+
return date;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
while (date.compare(minValue) >= 0 && isDateUnavailable(date)) {
|
|
805
|
+
date = date.subtract({ days: 1 });
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (date.compare(minValue) >= 0) {
|
|
809
|
+
return date;
|
|
810
|
+
}
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Ported to SolidJS for Proyecto Viviana; based on packages/react-stately/src/datepicker/useDateFieldState.ts
|
|
14
|
+
// Ported to SolidJS for Proyecto Viviana; based on packages/react-stately/src/datepicker/utils.ts
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
17
|
* DateFieldState for Solid-Stately
|
|
3
18
|
*
|
|
@@ -12,11 +27,14 @@
|
|
|
12
27
|
*
|
|
13
28
|
* The upstream "derived state during render" resync (which re-mints the display
|
|
14
29
|
* value when the committed value / calendar / hour cycle changes) is ported to a
|
|
15
|
-
*
|
|
16
|
-
*
|
|
30
|
+
* split `createEffect`. Compute tracks the committed value; apply writes the
|
|
31
|
+
* display override. Solid 2 has no `createComputed`.
|
|
17
32
|
*/
|
|
18
33
|
|
|
19
|
-
import {
|
|
34
|
+
import { createMemo, createEffect, untrack } from "solid-js";
|
|
35
|
+
import type { Accessor } from "solid-js";
|
|
36
|
+
import { access, createInternalSignal, type MaybeAccessor } from "../utils";
|
|
37
|
+
|
|
20
38
|
import {
|
|
21
39
|
type Calendar,
|
|
22
40
|
type CalendarDateTime,
|
|
@@ -33,7 +51,6 @@ import {
|
|
|
33
51
|
isEqualCalendar,
|
|
34
52
|
createCalendar as intlCreateCalendar,
|
|
35
53
|
} from "@internationalized/date";
|
|
36
|
-
import { access, type MaybeAccessor } from "../utils";
|
|
37
54
|
import type { ValidationState } from "./createCalendarState";
|
|
38
55
|
import { IncompleteDate } from "./IncompleteDate";
|
|
39
56
|
import { formatDateFieldError, getPlaceholder, type DateFieldErrorKey } from "./intl";
|
|
@@ -100,7 +117,7 @@ export interface DateFieldStateProps<T extends DateValue = DateValue> {
|
|
|
100
117
|
/** Whether the value is invalid (controlled). */
|
|
101
118
|
isInvalid?: boolean;
|
|
102
119
|
/** The locale to use for formatting. */
|
|
103
|
-
locale?: string
|
|
120
|
+
locale?: MaybeAccessor<string | undefined>;
|
|
104
121
|
/** The granularity of the date/time (day, hour, minute, second). */
|
|
105
122
|
granularity?: FieldGranularity;
|
|
106
123
|
/** The maximum granularity (largest editable unit). Defaults to `year`. */
|
|
@@ -235,7 +252,7 @@ const TYPE_MAPPING: Record<string, string> = {
|
|
|
235
252
|
export function createDateFieldState<T extends DateValue = DateValue>(
|
|
236
253
|
props: DateFieldStateProps<T> = {},
|
|
237
254
|
): DateFieldState<T> {
|
|
238
|
-
const locale = ()
|
|
255
|
+
const locale = createMemo(() => access(props.locale) ?? "en-US");
|
|
239
256
|
const createCalendarFn = (name: CalendarIdentifier): Calendar =>
|
|
240
257
|
(props.createCalendar ?? intlCreateCalendar)(name);
|
|
241
258
|
|
|
@@ -252,19 +269,15 @@ export function createDateFieldState<T extends DateValue = DateValue>(
|
|
|
252
269
|
timeZone: v && "timeZone" in v ? (v as { timeZone: string }).timeZone : undefined,
|
|
253
270
|
};
|
|
254
271
|
});
|
|
255
|
-
const
|
|
256
|
-
granularity: Granularity;
|
|
257
|
-
timeZone: string | undefined;
|
|
258
|
-
}>(initialDefaults);
|
|
259
|
-
createComputed(() => {
|
|
272
|
+
const lastDefaults = createMemo<typeof initialDefaults>((prev = initialDefaults) => {
|
|
260
273
|
const v = v0();
|
|
261
|
-
if (!v) return;
|
|
274
|
+
if (!v) return prev;
|
|
262
275
|
const defaultGranularity = ("minute" in v ? "minute" : "day") as Granularity;
|
|
263
276
|
const defaultTimeZone = "timeZone" in v ? (v as { timeZone: string }).timeZone : undefined;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
setLastDefaults({ granularity: defaultGranularity, timeZone: defaultTimeZone });
|
|
277
|
+
if (prev.granularity !== defaultGranularity || prev.timeZone !== defaultTimeZone) {
|
|
278
|
+
return { granularity: defaultGranularity, timeZone: defaultTimeZone };
|
|
267
279
|
}
|
|
280
|
+
return prev;
|
|
268
281
|
});
|
|
269
282
|
const granularity = (): FieldGranularity => {
|
|
270
283
|
if (props.granularity) return props.granularity;
|
|
@@ -296,7 +309,9 @@ export function createDateFieldState<T extends DateValue = DateValue>(
|
|
|
296
309
|
const hourCycle = (): HourCycle => calendarAndHourCycle()[1];
|
|
297
310
|
|
|
298
311
|
// Controlled vs uncontrolled committed value.
|
|
299
|
-
const [internalValue, setInternalValue] =
|
|
312
|
+
const [internalValue, setInternalValue] = createInternalSignal<T | null>(
|
|
313
|
+
props.defaultValue ?? null,
|
|
314
|
+
);
|
|
300
315
|
const rawValue = createMemo<T | null>(() => {
|
|
301
316
|
const controlled = access(props.value);
|
|
302
317
|
return controlled !== undefined ? controlled : internalValue();
|
|
@@ -307,32 +322,33 @@ export function createDateFieldState<T extends DateValue = DateValue>(
|
|
|
307
322
|
};
|
|
308
323
|
|
|
309
324
|
// The current value, converted to the display calendar.
|
|
310
|
-
const calendarValue = createMemo<DateValue | null>(
|
|
325
|
+
const calendarValue = createMemo<DateValue | null>(
|
|
326
|
+
() => convertValue(rawValue(), calendar()) ?? null,
|
|
327
|
+
);
|
|
311
328
|
|
|
312
329
|
const initialValue = untrack(calendarValue);
|
|
313
330
|
|
|
314
331
|
// The display override: holds the (possibly invalid/incomplete) value being edited.
|
|
315
|
-
const [displayValue, setDisplayValue] =
|
|
332
|
+
const [displayValue, setDisplayValue] = createInternalSignal<IncompleteDate>(
|
|
316
333
|
untrack(() => new IncompleteDate(calendar(), hourCycle(), untrack(calendarValue))),
|
|
317
334
|
);
|
|
318
335
|
|
|
319
|
-
//
|
|
320
|
-
// from the outside
|
|
321
|
-
// synchronously (like React's render-phase setState), never leaving a stale frame.
|
|
336
|
+
// Resync the display override when the committed value, calendar, or hour
|
|
337
|
+
// cycle changes from the outside. Compute tracks those sources; apply writes.
|
|
322
338
|
let lastValue = untrack(calendarValue);
|
|
323
339
|
let lastCalendar = untrack(calendar);
|
|
324
340
|
let lastHourCycle = untrack(hourCycle);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
341
|
+
createEffect(
|
|
342
|
+
() => ({ cv: calendarValue(), cal: calendar(), hc: hourCycle() }),
|
|
343
|
+
({ cv, cal, hc }) => {
|
|
344
|
+
if (cv !== lastValue || hc !== lastHourCycle || !isEqualCalendar(cal, lastCalendar)) {
|
|
345
|
+
lastValue = cv;
|
|
346
|
+
lastCalendar = cal;
|
|
347
|
+
lastHourCycle = hc;
|
|
348
|
+
setDisplayValue(new IncompleteDate(cal, hc, cv));
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
);
|
|
336
352
|
|
|
337
353
|
const showEra = (): boolean => calendar().identifier === "gregory" && displayValue().era === "BC";
|
|
338
354
|
const maxGranularity = (): "year" | "month" | "day" | "hour" | "minute" =>
|
|
@@ -352,7 +368,9 @@ export function createDateFieldState<T extends DateValue = DateValue>(
|
|
|
352
368
|
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
353
369
|
}));
|
|
354
370
|
|
|
355
|
-
const dateFormatter = createMemo(
|
|
371
|
+
const dateFormatter = createMemo(
|
|
372
|
+
() => new DateFormatter(locale(), getFormatOptions({}, formatOpts())),
|
|
373
|
+
);
|
|
356
374
|
const resolvedOptions = createMemo(() => dateFormatter().resolvedOptions());
|
|
357
375
|
|
|
358
376
|
const displaySegments = createMemo<DateSegmentType[]>(() => {
|
|
@@ -632,9 +650,7 @@ function processSegments(
|
|
|
632
650
|
const isPlaceholder =
|
|
633
651
|
EDITABLE_SEGMENTS[type] === true &&
|
|
634
652
|
displayValue[segment.type as keyof IncompleteDate] == null;
|
|
635
|
-
const placeholder = EDITABLE_SEGMENTS[type]
|
|
636
|
-
? getPlaceholder(type, segment.value, locale)
|
|
637
|
-
: "";
|
|
653
|
+
const placeholder = EDITABLE_SEGMENTS[type] ? getPlaceholder(type, segment.value, locale) : "";
|
|
638
654
|
const limits = displayValue.getSegmentLimits(type);
|
|
639
655
|
const dateSegment: DateSegment = {
|
|
640
656
|
type,
|
|
@@ -736,13 +752,12 @@ export function getFormatOptions(
|
|
|
736
752
|
let endIdx = keys.indexOf(granularity);
|
|
737
753
|
if (endIdx < 0) endIdx = 2;
|
|
738
754
|
if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
|
|
739
|
-
const opts: Record<string, unknown> = keys
|
|
740
|
-
(
|
|
755
|
+
const opts: Record<string, unknown> = keys
|
|
756
|
+
.slice(startIdx, endIdx + 1)
|
|
757
|
+
.reduce((acc: Record<string, unknown>, key) => {
|
|
741
758
|
acc[key] = merged[key];
|
|
742
759
|
return acc;
|
|
743
|
-
},
|
|
744
|
-
{},
|
|
745
|
-
);
|
|
760
|
+
}, {});
|
|
746
761
|
if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
|
|
747
762
|
opts.timeZone = options.timeZone || "UTC";
|
|
748
763
|
const hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
|
|
@@ -751,7 +766,10 @@ export function getFormatOptions(
|
|
|
751
766
|
return opts as Intl.DateTimeFormatOptions;
|
|
752
767
|
}
|
|
753
768
|
|
|
754
|
-
function convertValue(
|
|
769
|
+
function convertValue(
|
|
770
|
+
value: DateValue | null | undefined,
|
|
771
|
+
calendar: Calendar,
|
|
772
|
+
): DateValue | null | undefined {
|
|
755
773
|
if (value === null) return null;
|
|
756
774
|
if (!value) return undefined;
|
|
757
775
|
return toCalendar(value, calendar);
|