@proyecto-viviana/solid-stately 0.0.5 → 0.1.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/README.md +312 -0
- package/dist/index.d.ts +3363 -6
- package/dist/index.js +6194 -19
- package/dist/index.js.map +1 -1
- package/package.json +52 -48
- package/src/autocomplete/createAutocompleteState.d.ts +46 -0
- package/src/autocomplete/createAutocompleteState.d.ts.map +1 -0
- package/src/autocomplete/createAutocompleteState.ts +90 -0
- package/src/autocomplete/index.d.ts +2 -0
- package/src/autocomplete/index.d.ts.map +1 -0
- package/src/autocomplete/index.ts +5 -0
- package/src/calendar/createCalendarState.d.ts +130 -0
- package/src/calendar/createCalendarState.d.ts.map +1 -0
- package/src/calendar/createCalendarState.ts +461 -0
- package/src/calendar/createDateFieldState.d.ts +110 -0
- package/src/calendar/createDateFieldState.d.ts.map +1 -0
- package/src/calendar/createDateFieldState.ts +562 -0
- package/src/calendar/createRangeCalendarState.d.ts +146 -0
- package/src/calendar/createRangeCalendarState.d.ts.map +1 -0
- package/src/calendar/createRangeCalendarState.ts +535 -0
- package/src/calendar/createTimeFieldState.d.ts +95 -0
- package/src/calendar/createTimeFieldState.d.ts.map +1 -0
- package/src/calendar/createTimeFieldState.ts +483 -0
- package/src/calendar/index.d.ts +7 -0
- package/src/calendar/index.d.ts.map +1 -0
- package/src/calendar/index.ts +81 -0
- package/{dist → src}/checkbox/createCheckboxGroupState.d.ts +1 -0
- package/src/checkbox/createCheckboxGroupState.d.ts.map +1 -0
- package/{dist → src}/checkbox/index.d.ts +1 -0
- package/src/checkbox/index.d.ts.map +1 -0
- package/src/collections/ListCollection.d.ts +37 -0
- package/src/collections/ListCollection.d.ts.map +1 -0
- package/src/collections/ListCollection.ts +146 -0
- package/src/collections/createListState.d.ts +79 -0
- package/src/collections/createListState.d.ts.map +1 -0
- package/src/collections/createListState.ts +264 -0
- package/src/collections/createMenuState.d.ts +50 -0
- package/src/collections/createMenuState.d.ts.map +1 -0
- package/src/collections/createMenuState.ts +106 -0
- package/src/collections/createSelectionState.d.ts +76 -0
- package/src/collections/createSelectionState.d.ts.map +1 -0
- package/src/collections/createSelectionState.ts +336 -0
- package/src/collections/index.d.ts +6 -0
- package/src/collections/index.d.ts.map +1 -0
- package/src/collections/index.ts +46 -0
- package/src/collections/types.d.ts +147 -0
- package/src/collections/types.d.ts.map +1 -0
- package/src/collections/types.ts +169 -0
- package/src/color/Color.d.ts +28 -0
- package/src/color/Color.d.ts.map +1 -0
- package/src/color/Color.ts +951 -0
- package/src/color/createColorAreaState.d.ts +76 -0
- package/src/color/createColorAreaState.d.ts.map +1 -0
- package/src/color/createColorAreaState.ts +293 -0
- package/src/color/createColorFieldState.d.ts +55 -0
- package/src/color/createColorFieldState.d.ts.map +1 -0
- package/src/color/createColorFieldState.ts +292 -0
- package/src/color/createColorSliderState.d.ts +67 -0
- package/src/color/createColorSliderState.d.ts.map +1 -0
- package/src/color/createColorSliderState.ts +241 -0
- package/src/color/createColorWheelState.d.ts +51 -0
- package/src/color/createColorWheelState.d.ts.map +1 -0
- package/src/color/createColorWheelState.ts +211 -0
- package/src/color/index.d.ts +10 -0
- package/src/color/index.d.ts.map +1 -0
- package/src/color/index.ts +47 -0
- package/src/color/types.d.ts +106 -0
- package/src/color/types.d.ts.map +1 -0
- package/src/color/types.ts +127 -0
- package/src/combobox/createComboBoxState.d.ts +125 -0
- package/src/combobox/createComboBoxState.d.ts.map +1 -0
- package/src/combobox/createComboBoxState.ts +703 -0
- package/src/combobox/index.d.ts +5 -0
- package/src/combobox/index.d.ts.map +1 -0
- package/src/combobox/index.ts +13 -0
- package/src/disclosure/createDisclosureState.d.ts +64 -0
- package/src/disclosure/createDisclosureState.d.ts.map +1 -0
- package/src/disclosure/createDisclosureState.ts +193 -0
- package/src/disclosure/index.d.ts +2 -0
- package/src/disclosure/index.d.ts.map +1 -0
- package/src/disclosure/index.ts +9 -0
- package/src/dnd/createDragState.d.ts +59 -0
- package/src/dnd/createDragState.d.ts.map +1 -0
- package/src/dnd/createDragState.ts +153 -0
- package/src/dnd/createDraggableCollectionState.d.ts +57 -0
- package/src/dnd/createDraggableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDraggableCollectionState.ts +165 -0
- package/src/dnd/createDropState.d.ts +61 -0
- package/src/dnd/createDropState.d.ts.map +1 -0
- package/src/dnd/createDropState.ts +212 -0
- package/src/dnd/createDroppableCollectionState.d.ts +78 -0
- package/src/dnd/createDroppableCollectionState.d.ts.map +1 -0
- package/src/dnd/createDroppableCollectionState.ts +357 -0
- package/src/dnd/index.d.ts +11 -0
- package/src/dnd/index.d.ts.map +1 -0
- package/src/dnd/index.ts +76 -0
- package/src/dnd/types.d.ts +264 -0
- package/src/dnd/types.d.ts.map +1 -0
- package/src/dnd/types.ts +317 -0
- package/src/form/createFormValidationState.d.ts +100 -0
- package/src/form/createFormValidationState.d.ts.map +1 -0
- package/src/form/createFormValidationState.ts +389 -0
- package/src/form/index.d.ts +2 -0
- package/src/form/index.d.ts.map +1 -0
- package/src/form/index.ts +15 -0
- package/src/grid/createGridState.d.ts +12 -0
- package/src/grid/createGridState.d.ts.map +1 -0
- package/src/grid/createGridState.ts +327 -0
- package/src/grid/index.d.ts +7 -0
- package/src/grid/index.d.ts.map +1 -0
- package/src/grid/index.ts +13 -0
- package/src/grid/types.d.ts +156 -0
- package/src/grid/types.d.ts.map +1 -0
- package/src/grid/types.ts +179 -0
- package/src/index.d.ts +26 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.ts +350 -1
- package/src/numberfield/createNumberFieldState.d.ts +65 -0
- package/src/numberfield/createNumberFieldState.d.ts.map +1 -0
- package/src/numberfield/createNumberFieldState.ts +383 -0
- package/src/numberfield/index.d.ts +2 -0
- package/src/numberfield/index.d.ts.map +1 -0
- package/src/numberfield/index.ts +5 -0
- package/src/overlays/createOverlayTriggerState.d.ts +32 -0
- package/src/overlays/createOverlayTriggerState.d.ts.map +1 -0
- package/src/overlays/createOverlayTriggerState.ts +67 -0
- package/src/overlays/index.d.ts +2 -0
- package/src/overlays/index.d.ts.map +1 -0
- package/src/overlays/index.ts +5 -0
- package/{dist → src}/radio/createRadioGroupState.d.ts +1 -0
- package/src/radio/createRadioGroupState.d.ts.map +1 -0
- package/{dist → src}/radio/index.d.ts +1 -0
- package/src/radio/index.d.ts.map +1 -0
- package/src/searchfield/createSearchFieldState.d.ts +25 -0
- package/src/searchfield/createSearchFieldState.d.ts.map +1 -0
- package/src/searchfield/createSearchFieldState.ts +62 -0
- package/src/searchfield/index.d.ts +3 -0
- package/src/searchfield/index.d.ts.map +1 -0
- package/src/searchfield/index.ts +5 -0
- package/src/select/createSelectState.d.ts +73 -0
- package/src/select/createSelectState.d.ts.map +1 -0
- package/src/select/createSelectState.ts +181 -0
- package/src/select/index.d.ts +2 -0
- package/src/select/index.d.ts.map +1 -0
- package/src/select/index.ts +5 -0
- package/src/slider/createSliderState.d.ts +72 -0
- package/src/slider/createSliderState.d.ts.map +1 -0
- package/src/slider/createSliderState.ts +211 -0
- package/src/slider/index.d.ts +3 -0
- package/src/slider/index.d.ts.map +1 -0
- package/src/slider/index.ts +6 -0
- package/{dist → src}/ssr/index.d.ts +5 -0
- package/src/ssr/index.d.ts.map +1 -0
- package/src/ssr/index.ts +6 -1
- package/src/table/TableCollection.d.ts +52 -0
- package/src/table/TableCollection.d.ts.map +1 -0
- package/src/table/TableCollection.ts +388 -0
- package/src/table/createTableState.d.ts +12 -0
- package/src/table/createTableState.d.ts.map +1 -0
- package/src/table/createTableState.ts +127 -0
- package/src/table/index.d.ts +8 -0
- package/src/table/index.d.ts.map +1 -0
- package/src/table/index.ts +18 -0
- package/src/table/types.d.ts +139 -0
- package/src/table/types.d.ts.map +1 -0
- package/src/table/types.ts +150 -0
- package/src/tabs/createTabListState.d.ts +68 -0
- package/src/tabs/createTabListState.d.ts.map +1 -0
- package/src/tabs/createTabListState.ts +240 -0
- package/src/tabs/index.d.ts +2 -0
- package/src/tabs/index.d.ts.map +1 -0
- package/src/tabs/index.ts +7 -0
- package/{dist → src}/textfield/createTextFieldState.d.ts +1 -0
- package/src/textfield/createTextFieldState.d.ts.map +1 -0
- package/{dist → src}/textfield/index.d.ts +1 -0
- package/src/textfield/index.d.ts.map +1 -0
- package/src/toast/createToastState.d.ts +118 -0
- package/src/toast/createToastState.d.ts.map +1 -0
- package/src/toast/createToastState.ts +316 -0
- package/src/toast/index.d.ts +2 -0
- package/src/toast/index.d.ts.map +1 -0
- package/src/toast/index.ts +11 -0
- package/{dist → src}/toggle/createToggleState.d.ts +1 -0
- package/src/toggle/createToggleState.d.ts.map +1 -0
- package/{dist → src}/toggle/index.d.ts +1 -0
- package/src/toggle/index.d.ts.map +1 -0
- package/src/tooltip/createTooltipTriggerState.d.ts +39 -0
- package/src/tooltip/createTooltipTriggerState.d.ts.map +1 -0
- package/src/tooltip/createTooltipTriggerState.ts +183 -0
- package/src/tooltip/index.d.ts +2 -0
- package/src/tooltip/index.d.ts.map +1 -0
- package/src/tooltip/index.ts +6 -0
- package/src/tree/TreeCollection.d.ts +40 -0
- package/src/tree/TreeCollection.d.ts.map +1 -0
- package/src/tree/TreeCollection.ts +175 -0
- package/src/tree/createTreeState.d.ts +14 -0
- package/src/tree/createTreeState.d.ts.map +1 -0
- package/src/tree/createTreeState.ts +392 -0
- package/src/tree/index.d.ts +7 -0
- package/src/tree/index.d.ts.map +1 -0
- package/src/tree/index.ts +13 -0
- package/src/tree/types.d.ts +157 -0
- package/src/tree/types.d.ts.map +1 -0
- package/src/tree/types.ts +174 -0
- package/{dist → src}/utils/index.d.ts +1 -0
- package/src/utils/index.d.ts.map +1 -0
- package/{dist → src}/utils/reactivity.d.ts +1 -0
- package/src/utils/reactivity.d.ts.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRangeCalendarState.d.ts","sourceRoot":"","sources":["createRangeCalendarState.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA4B,KAAK,Q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kB,CAAC,CAAC,CAAC,CAgWvB"}
|
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RangeCalendarState for Solid-Stately
|
|
3
|
+
*
|
|
4
|
+
* Provides state management for range calendar components.
|
|
5
|
+
* Based on @react-stately/calendar useRangeCalendarState
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createSignal, createMemo, type Accessor } from 'solid-js';
|
|
9
|
+
import {
|
|
10
|
+
type CalendarDate,
|
|
11
|
+
type DateValue,
|
|
12
|
+
today,
|
|
13
|
+
getLocalTimeZone,
|
|
14
|
+
isSameDay,
|
|
15
|
+
isSameMonth,
|
|
16
|
+
startOfMonth,
|
|
17
|
+
endOfMonth,
|
|
18
|
+
startOfWeek,
|
|
19
|
+
getWeeksInMonth,
|
|
20
|
+
getDayOfWeek,
|
|
21
|
+
DateFormatter,
|
|
22
|
+
toCalendarDate as intlToCalendarDate,
|
|
23
|
+
} from '@internationalized/date';
|
|
24
|
+
import { access, type MaybeAccessor } from '../utils';
|
|
25
|
+
import type { ValidationState } from './createCalendarState';
|
|
26
|
+
|
|
27
|
+
// ============================================
|
|
28
|
+
// TYPES
|
|
29
|
+
// ============================================
|
|
30
|
+
|
|
31
|
+
export interface DateRange {
|
|
32
|
+
start: CalendarDate;
|
|
33
|
+
end: CalendarDate;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RangeValue<T> {
|
|
37
|
+
start: T;
|
|
38
|
+
end: T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface RangeCalendarStateProps<T extends DateValue = DateValue> {
|
|
42
|
+
/** The current value (controlled). */
|
|
43
|
+
value?: MaybeAccessor<RangeValue<T> | null>;
|
|
44
|
+
/** The default value (uncontrolled). */
|
|
45
|
+
defaultValue?: RangeValue<T> | null;
|
|
46
|
+
/** Handler called when the value changes. */
|
|
47
|
+
onChange?: (value: RangeValue<T>) => void;
|
|
48
|
+
/** The minimum allowed date. */
|
|
49
|
+
minValue?: MaybeAccessor<DateValue | undefined>;
|
|
50
|
+
/** The maximum allowed date. */
|
|
51
|
+
maxValue?: MaybeAccessor<DateValue | undefined>;
|
|
52
|
+
/** Whether the calendar is disabled. */
|
|
53
|
+
isDisabled?: MaybeAccessor<boolean>;
|
|
54
|
+
/** Whether the calendar is read-only. */
|
|
55
|
+
isReadOnly?: MaybeAccessor<boolean>;
|
|
56
|
+
/** The date that is focused when the calendar first mounts. */
|
|
57
|
+
focusedValue?: MaybeAccessor<DateValue | undefined>;
|
|
58
|
+
/** The default focused date (uncontrolled). */
|
|
59
|
+
defaultFocusedValue?: DateValue;
|
|
60
|
+
/** Handler called when the focused date changes. */
|
|
61
|
+
onFocusChange?: (date: CalendarDate) => void;
|
|
62
|
+
/** The locale to use for formatting. */
|
|
63
|
+
locale?: string;
|
|
64
|
+
/** Callback to determine if a date is unavailable. */
|
|
65
|
+
isDateUnavailable?: (date: DateValue) => boolean;
|
|
66
|
+
/** The number of months to display at once. */
|
|
67
|
+
visibleMonths?: number;
|
|
68
|
+
/** Controls which days are disabled. */
|
|
69
|
+
isDateDisabled?: (date: DateValue) => boolean;
|
|
70
|
+
/** Validation state. */
|
|
71
|
+
validationState?: MaybeAccessor<ValidationState | undefined>;
|
|
72
|
+
/** Whether to allow selecting the same date for start and end. */
|
|
73
|
+
allowsNonContiguousRanges?: boolean;
|
|
74
|
+
/** The first day of the week (0 = Sunday, 1 = Monday, etc.). */
|
|
75
|
+
firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface RangeCalendarState<T extends DateValue = DateValue> {
|
|
79
|
+
/** The currently selected date range. */
|
|
80
|
+
value: Accessor<RangeValue<T> | null>;
|
|
81
|
+
/** Sets the selected date range. */
|
|
82
|
+
setValue: (value: RangeValue<T> | null) => void;
|
|
83
|
+
/** The currently focused date. */
|
|
84
|
+
focusedDate: Accessor<CalendarDate>;
|
|
85
|
+
/** Sets the focused date. */
|
|
86
|
+
setFocusedDate: (date: CalendarDate) => void;
|
|
87
|
+
/** The anchor date when selecting a range (first click). */
|
|
88
|
+
anchorDate: Accessor<CalendarDate | null>;
|
|
89
|
+
/** Sets the anchor date. */
|
|
90
|
+
setAnchorDate: (date: CalendarDate | null) => void;
|
|
91
|
+
/** The highlighted range during selection. */
|
|
92
|
+
highlightedRange: Accessor<RangeValue<CalendarDate> | null>;
|
|
93
|
+
/** Whether the calendar is disabled. */
|
|
94
|
+
isDisabled: Accessor<boolean>;
|
|
95
|
+
/** Whether the calendar is read-only. */
|
|
96
|
+
isReadOnly: Accessor<boolean>;
|
|
97
|
+
/** The visible date range (first and last day of visible month(s)). */
|
|
98
|
+
visibleRange: Accessor<{ start: CalendarDate; end: CalendarDate }>;
|
|
99
|
+
/** The timezone used for date calculations. */
|
|
100
|
+
timeZone: string;
|
|
101
|
+
/** The validation state. */
|
|
102
|
+
validationState: Accessor<ValidationState | undefined>;
|
|
103
|
+
/** Whether a date is within the selected range. */
|
|
104
|
+
isSelected: (date: DateValue) => boolean;
|
|
105
|
+
/** Whether a date is the start of the selection. */
|
|
106
|
+
isSelectionStart: (date: DateValue) => boolean;
|
|
107
|
+
/** Whether a date is the end of the selection. */
|
|
108
|
+
isSelectionEnd: (date: DateValue) => boolean;
|
|
109
|
+
/** Whether a date is focused. */
|
|
110
|
+
isCellFocused: (date: DateValue) => boolean;
|
|
111
|
+
/** Whether a date is unavailable. */
|
|
112
|
+
isCellUnavailable: (date: DateValue) => boolean;
|
|
113
|
+
/** Whether a date is disabled. */
|
|
114
|
+
isCellDisabled: (date: DateValue) => boolean;
|
|
115
|
+
/** Whether a date is outside the visible range. */
|
|
116
|
+
isOutsideVisibleRange: (date: DateValue) => boolean;
|
|
117
|
+
/** Whether a date is invalid. */
|
|
118
|
+
isInvalid: (date: DateValue) => boolean;
|
|
119
|
+
/** Moves focus to the previous page (month). */
|
|
120
|
+
focusPreviousPage: () => void;
|
|
121
|
+
/** Moves focus to the next page (month). */
|
|
122
|
+
focusNextPage: () => void;
|
|
123
|
+
/** Moves focus to the previous section (year). */
|
|
124
|
+
focusPreviousSection: () => void;
|
|
125
|
+
/** Moves focus to the next section (year). */
|
|
126
|
+
focusNextSection: () => void;
|
|
127
|
+
/** Moves focus to the previous day. */
|
|
128
|
+
focusPreviousDay: () => void;
|
|
129
|
+
/** Moves focus to the next day. */
|
|
130
|
+
focusNextDay: () => void;
|
|
131
|
+
/** Moves focus to the previous week. */
|
|
132
|
+
focusPreviousWeek: () => void;
|
|
133
|
+
/** Moves focus to the next week. */
|
|
134
|
+
focusNextWeek: () => void;
|
|
135
|
+
/** Moves focus to the start of the month. */
|
|
136
|
+
focusPageStart: () => void;
|
|
137
|
+
/** Moves focus to the end of the month. */
|
|
138
|
+
focusPageEnd: () => void;
|
|
139
|
+
/** Selects the focused date. */
|
|
140
|
+
selectFocusedDate: () => void;
|
|
141
|
+
/** Selects a specific date. */
|
|
142
|
+
selectDate: (date: CalendarDate) => void;
|
|
143
|
+
/** Whether focus is currently within the calendar. */
|
|
144
|
+
isFocused: Accessor<boolean>;
|
|
145
|
+
/** Sets whether focus is within the calendar. */
|
|
146
|
+
setFocused: (focused: boolean) => void;
|
|
147
|
+
/** Gets the dates for a week in the visible range. */
|
|
148
|
+
getDatesInWeek: (weekIndex: number, monthStartDate?: CalendarDate) => (CalendarDate | null)[];
|
|
149
|
+
/** Gets the number of weeks in a month. */
|
|
150
|
+
getWeeksInMonth: (date?: CalendarDate) => number;
|
|
151
|
+
/** The week day headers. */
|
|
152
|
+
weekDays: Accessor<string[]>;
|
|
153
|
+
/** The title for the calendar (formatted month and year). */
|
|
154
|
+
title: Accessor<string>;
|
|
155
|
+
/** The number of visible months. */
|
|
156
|
+
visibleMonths: number;
|
|
157
|
+
/** Whether the user is currently selecting a range. */
|
|
158
|
+
isDragging: Accessor<boolean>;
|
|
159
|
+
/** Sets whether the user is dragging to select. */
|
|
160
|
+
setDragging: (dragging: boolean) => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ============================================
|
|
164
|
+
// IMPLEMENTATION
|
|
165
|
+
// ============================================
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Provides state management for a range calendar component.
|
|
169
|
+
*/
|
|
170
|
+
export function createRangeCalendarState<T extends DateValue = CalendarDate>(
|
|
171
|
+
props: RangeCalendarStateProps<T> = {}
|
|
172
|
+
): RangeCalendarState<T> {
|
|
173
|
+
const timeZone = getLocalTimeZone();
|
|
174
|
+
const locale = props.locale ?? 'en-US';
|
|
175
|
+
const visibleMonths = props.visibleMonths ?? 1;
|
|
176
|
+
|
|
177
|
+
// Determine the initially focused date
|
|
178
|
+
const getInitialFocusedDate = (): CalendarDate => {
|
|
179
|
+
const controlledFocused = access(props.focusedValue);
|
|
180
|
+
if (controlledFocused) {
|
|
181
|
+
return toCalendarDate(controlledFocused);
|
|
182
|
+
}
|
|
183
|
+
if (props.defaultFocusedValue) {
|
|
184
|
+
return toCalendarDate(props.defaultFocusedValue);
|
|
185
|
+
}
|
|
186
|
+
const controlledValue = access(props.value);
|
|
187
|
+
if (controlledValue?.start) {
|
|
188
|
+
return toCalendarDate(controlledValue.start);
|
|
189
|
+
}
|
|
190
|
+
if (props.defaultValue?.start) {
|
|
191
|
+
return toCalendarDate(props.defaultValue.start);
|
|
192
|
+
}
|
|
193
|
+
return today(timeZone);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// State signals
|
|
197
|
+
const [internalValue, setInternalValue] = createSignal<RangeValue<T> | null>(
|
|
198
|
+
props.defaultValue ?? null
|
|
199
|
+
);
|
|
200
|
+
const [focusedDate, setFocusedDateInternal] = createSignal<CalendarDate>(
|
|
201
|
+
getInitialFocusedDate()
|
|
202
|
+
);
|
|
203
|
+
const [anchorDate, setAnchorDate] = createSignal<CalendarDate | null>(null);
|
|
204
|
+
const [isFocused, setFocused] = createSignal(false);
|
|
205
|
+
const [isDragging, setDragging] = createSignal(false);
|
|
206
|
+
|
|
207
|
+
// Controlled vs uncontrolled value
|
|
208
|
+
const value = createMemo<RangeValue<T> | null>(() => {
|
|
209
|
+
const controlled = access(props.value);
|
|
210
|
+
return controlled !== undefined ? controlled : internalValue();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Derived states
|
|
214
|
+
const isDisabled = createMemo(() => access(props.isDisabled) ?? false);
|
|
215
|
+
const isReadOnly = createMemo(() => access(props.isReadOnly) ?? false);
|
|
216
|
+
const validationState = createMemo(() => access(props.validationState));
|
|
217
|
+
|
|
218
|
+
// Highlighted range during selection
|
|
219
|
+
const highlightedRange = createMemo<RangeValue<CalendarDate> | null>(() => {
|
|
220
|
+
const anchor = anchorDate();
|
|
221
|
+
if (!anchor) {
|
|
222
|
+
const v = value();
|
|
223
|
+
if (v) {
|
|
224
|
+
return {
|
|
225
|
+
start: toCalendarDate(v.start),
|
|
226
|
+
end: toCalendarDate(v.end),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const focused = focusedDate();
|
|
233
|
+
if (anchor.compare(focused) <= 0) {
|
|
234
|
+
return { start: anchor, end: focused };
|
|
235
|
+
}
|
|
236
|
+
return { start: focused, end: anchor };
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Visible range based on focused date
|
|
240
|
+
const visibleRange = createMemo(() => {
|
|
241
|
+
const focused = focusedDate();
|
|
242
|
+
const start = startOfMonth(focused);
|
|
243
|
+
let end = endOfMonth(focused);
|
|
244
|
+
|
|
245
|
+
for (let i = 1; i < visibleMonths; i++) {
|
|
246
|
+
end = endOfMonth(end.add({ months: 1 }));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return { start, end };
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// Format week days for headers
|
|
253
|
+
const weekDays = createMemo(() => {
|
|
254
|
+
const formatter = new DateFormatter(locale, { weekday: 'short' });
|
|
255
|
+
const startDay = props.firstDayOfWeek ?? 0;
|
|
256
|
+
const days: string[] = [];
|
|
257
|
+
const base = today(timeZone);
|
|
258
|
+
|
|
259
|
+
const dayOfWeek = getDayOfWeek(base, locale);
|
|
260
|
+
const weekStart = base.subtract({ days: (dayOfWeek - startDay + 7) % 7 });
|
|
261
|
+
|
|
262
|
+
for (let i = 0; i < 7; i++) {
|
|
263
|
+
const day = weekStart.add({ days: i });
|
|
264
|
+
days.push(formatter.format(day.toDate(timeZone)));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return days;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Title (formatted month/year)
|
|
271
|
+
const title = createMemo(() => {
|
|
272
|
+
const formatter = new DateFormatter(locale, {
|
|
273
|
+
month: 'long',
|
|
274
|
+
year: 'numeric',
|
|
275
|
+
});
|
|
276
|
+
return formatter.format(focusedDate().toDate(timeZone));
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Set value with onChange callback
|
|
280
|
+
const setValue = (newValue: RangeValue<T> | null) => {
|
|
281
|
+
if (isDisabled() || isReadOnly()) return;
|
|
282
|
+
|
|
283
|
+
const controlled = access(props.value);
|
|
284
|
+
if (controlled === undefined) {
|
|
285
|
+
setInternalValue(() => newValue);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (newValue && props.onChange) {
|
|
289
|
+
props.onChange(newValue);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Set focused date with constraints
|
|
294
|
+
const setFocusedDate = (date: CalendarDate) => {
|
|
295
|
+
const minValue = access(props.minValue);
|
|
296
|
+
const maxValue = access(props.maxValue);
|
|
297
|
+
|
|
298
|
+
let constrained = date;
|
|
299
|
+
|
|
300
|
+
if (minValue && date.compare(toCalendarDate(minValue)) < 0) {
|
|
301
|
+
constrained = toCalendarDate(minValue);
|
|
302
|
+
}
|
|
303
|
+
if (maxValue && date.compare(toCalendarDate(maxValue)) > 0) {
|
|
304
|
+
constrained = toCalendarDate(maxValue);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
setFocusedDateInternal(constrained);
|
|
308
|
+
props.onFocusChange?.(constrained);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// Check if a date is within the selected range
|
|
312
|
+
const isSelected = (date: DateValue): boolean => {
|
|
313
|
+
const range = highlightedRange();
|
|
314
|
+
if (!range) return false;
|
|
315
|
+
|
|
316
|
+
const calDate = toCalendarDate(date);
|
|
317
|
+
return (
|
|
318
|
+
calDate.compare(range.start) >= 0 && calDate.compare(range.end) <= 0
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// Check if a date is the start of the selection
|
|
323
|
+
const isSelectionStart = (date: DateValue): boolean => {
|
|
324
|
+
const range = highlightedRange();
|
|
325
|
+
if (!range) return false;
|
|
326
|
+
return isSameDay(toCalendarDate(date), range.start);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// Check if a date is the end of the selection
|
|
330
|
+
const isSelectionEnd = (date: DateValue): boolean => {
|
|
331
|
+
const range = highlightedRange();
|
|
332
|
+
if (!range) return false;
|
|
333
|
+
return isSameDay(toCalendarDate(date), range.end);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// Check if a date is focused
|
|
337
|
+
const isCellFocused = (date: DateValue): boolean => {
|
|
338
|
+
return isSameDay(toCalendarDate(date), focusedDate());
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// Check if a date is unavailable
|
|
342
|
+
const isCellUnavailable = (date: DateValue): boolean => {
|
|
343
|
+
return props.isDateUnavailable?.(date) ?? false;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// Check if a date is disabled
|
|
347
|
+
const isCellDisabled = (date: DateValue): boolean => {
|
|
348
|
+
if (isDisabled()) return true;
|
|
349
|
+
if (props.isDateDisabled?.(date)) return true;
|
|
350
|
+
|
|
351
|
+
const minValue = access(props.minValue);
|
|
352
|
+
const maxValue = access(props.maxValue);
|
|
353
|
+
const calDate = toCalendarDate(date);
|
|
354
|
+
|
|
355
|
+
if (minValue && calDate.compare(toCalendarDate(minValue)) < 0) return true;
|
|
356
|
+
if (maxValue && calDate.compare(toCalendarDate(maxValue)) > 0) return true;
|
|
357
|
+
|
|
358
|
+
return false;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// Check if a date is outside the visible range
|
|
362
|
+
const isOutsideVisibleRange = (date: DateValue): boolean => {
|
|
363
|
+
const range = visibleRange();
|
|
364
|
+
const calDate = toCalendarDate(date);
|
|
365
|
+
return !isSameMonth(calDate, range.start) && !isSameMonth(calDate, range.end);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
// Check if a date is invalid
|
|
369
|
+
const isInvalid = (date: DateValue): boolean => {
|
|
370
|
+
return isCellDisabled(date) || isCellUnavailable(date);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// Navigation methods
|
|
374
|
+
const focusPreviousPage = () => {
|
|
375
|
+
setFocusedDate(focusedDate().subtract({ months: 1 }));
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const focusNextPage = () => {
|
|
379
|
+
setFocusedDate(focusedDate().add({ months: 1 }));
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
const focusPreviousSection = () => {
|
|
383
|
+
setFocusedDate(focusedDate().subtract({ years: 1 }));
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const focusNextSection = () => {
|
|
387
|
+
setFocusedDate(focusedDate().add({ years: 1 }));
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const focusPreviousDay = () => {
|
|
391
|
+
setFocusedDate(focusedDate().subtract({ days: 1 }));
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const focusNextDay = () => {
|
|
395
|
+
setFocusedDate(focusedDate().add({ days: 1 }));
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const focusPreviousWeek = () => {
|
|
399
|
+
setFocusedDate(focusedDate().subtract({ weeks: 1 }));
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const focusNextWeek = () => {
|
|
403
|
+
setFocusedDate(focusedDate().add({ weeks: 1 }));
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const focusPageStart = () => {
|
|
407
|
+
setFocusedDate(startOfMonth(focusedDate()));
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const focusPageEnd = () => {
|
|
411
|
+
setFocusedDate(endOfMonth(focusedDate()));
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// Selection methods
|
|
415
|
+
const selectFocusedDate = () => {
|
|
416
|
+
if (isReadOnly() || isDisabled()) return;
|
|
417
|
+
selectDate(focusedDate());
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
const selectDate = (date: CalendarDate) => {
|
|
421
|
+
if (isReadOnly() || isDisabled()) return;
|
|
422
|
+
if (isCellDisabled(date) || isCellUnavailable(date)) return;
|
|
423
|
+
|
|
424
|
+
const anchor = anchorDate();
|
|
425
|
+
|
|
426
|
+
if (!anchor) {
|
|
427
|
+
// First click - set anchor
|
|
428
|
+
setAnchorDate(date);
|
|
429
|
+
setDragging(true);
|
|
430
|
+
} else {
|
|
431
|
+
// Second click - complete selection
|
|
432
|
+
let start: CalendarDate;
|
|
433
|
+
let end: CalendarDate;
|
|
434
|
+
|
|
435
|
+
if (date.compare(anchor) < 0) {
|
|
436
|
+
start = date;
|
|
437
|
+
end = anchor;
|
|
438
|
+
} else {
|
|
439
|
+
start = anchor;
|
|
440
|
+
end = date;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
setValue({
|
|
444
|
+
start: start as unknown as T,
|
|
445
|
+
end: end as unknown as T,
|
|
446
|
+
});
|
|
447
|
+
setAnchorDate(null);
|
|
448
|
+
setDragging(false);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
setFocusedDate(date);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// Get dates in a specific week
|
|
455
|
+
const getDatesInWeek = (
|
|
456
|
+
weekIndex: number,
|
|
457
|
+
monthStartDate?: CalendarDate
|
|
458
|
+
): (CalendarDate | null)[] => {
|
|
459
|
+
const startDate = monthStartDate ?? visibleRange().start;
|
|
460
|
+
|
|
461
|
+
const monthStart = startOfMonth(startDate);
|
|
462
|
+
const weekStart = startOfWeek(monthStart, locale);
|
|
463
|
+
|
|
464
|
+
const week: (CalendarDate | null)[] = [];
|
|
465
|
+
const firstDayOfWeek = weekStart.add({ weeks: weekIndex });
|
|
466
|
+
|
|
467
|
+
for (let i = 0; i < 7; i++) {
|
|
468
|
+
const date = firstDayOfWeek.add({ days: i });
|
|
469
|
+
week.push(date);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return week;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// Get number of weeks in a month
|
|
476
|
+
const getWeeksInMonthFn = (date?: CalendarDate): number => {
|
|
477
|
+
const monthDate = date ?? focusedDate();
|
|
478
|
+
return getWeeksInMonth(monthDate, locale);
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
value,
|
|
483
|
+
setValue,
|
|
484
|
+
focusedDate,
|
|
485
|
+
setFocusedDate,
|
|
486
|
+
anchorDate,
|
|
487
|
+
setAnchorDate,
|
|
488
|
+
highlightedRange,
|
|
489
|
+
isDisabled,
|
|
490
|
+
isReadOnly,
|
|
491
|
+
visibleRange,
|
|
492
|
+
timeZone,
|
|
493
|
+
validationState,
|
|
494
|
+
isSelected,
|
|
495
|
+
isSelectionStart,
|
|
496
|
+
isSelectionEnd,
|
|
497
|
+
isCellFocused,
|
|
498
|
+
isCellUnavailable,
|
|
499
|
+
isCellDisabled,
|
|
500
|
+
isOutsideVisibleRange,
|
|
501
|
+
isInvalid,
|
|
502
|
+
focusPreviousPage,
|
|
503
|
+
focusNextPage,
|
|
504
|
+
focusPreviousSection,
|
|
505
|
+
focusNextSection,
|
|
506
|
+
focusPreviousDay,
|
|
507
|
+
focusNextDay,
|
|
508
|
+
focusPreviousWeek,
|
|
509
|
+
focusNextWeek,
|
|
510
|
+
focusPageStart,
|
|
511
|
+
focusPageEnd,
|
|
512
|
+
selectFocusedDate,
|
|
513
|
+
selectDate,
|
|
514
|
+
isFocused,
|
|
515
|
+
setFocused,
|
|
516
|
+
getDatesInWeek,
|
|
517
|
+
getWeeksInMonth: getWeeksInMonthFn,
|
|
518
|
+
weekDays,
|
|
519
|
+
title,
|
|
520
|
+
visibleMonths,
|
|
521
|
+
isDragging,
|
|
522
|
+
setDragging,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ============================================
|
|
527
|
+
// HELPER FUNCTIONS
|
|
528
|
+
// ============================================
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Converts a DateValue to a CalendarDate.
|
|
532
|
+
*/
|
|
533
|
+
function toCalendarDate(date: DateValue): CalendarDate {
|
|
534
|
+
return intlToCalendarDate(date);
|
|
535
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeFieldState for Solid-Stately
|
|
3
|
+
*
|
|
4
|
+
* Provides state management for time field components with segment-based editing.
|
|
5
|
+
* Based on @react-stately/datepicker useTimeFieldState
|
|
6
|
+
*/
|
|
7
|
+
import { type Accessor } from 'solid-js';
|
|
8
|
+
import { type Time, type CalendarDateTime, type ZonedDateTime } from '@internationalized/date';
|
|
9
|
+
import { type MaybeAccessor } from '../utils';
|
|
10
|
+
import type { ValidationState } from './createCalendarState';
|
|
11
|
+
export type TimeValue = Time | CalendarDateTime | ZonedDateTime;
|
|
12
|
+
export type TimeSegmentType = 'hour' | 'minute' | 'second' | 'dayPeriod' | 'literal';
|
|
13
|
+
export interface TimeSegment {
|
|
14
|
+
/** The type of segment. */
|
|
15
|
+
type: TimeSegmentType;
|
|
16
|
+
/** The text content of the segment. */
|
|
17
|
+
text: string;
|
|
18
|
+
/** The numeric value of the segment (if applicable). */
|
|
19
|
+
value?: number;
|
|
20
|
+
/** The minimum value for the segment. */
|
|
21
|
+
minValue?: number;
|
|
22
|
+
/** The maximum value for the segment. */
|
|
23
|
+
maxValue?: number;
|
|
24
|
+
/** Whether this segment is editable. */
|
|
25
|
+
isEditable: boolean;
|
|
26
|
+
/** Whether this segment is a placeholder. */
|
|
27
|
+
isPlaceholder: boolean;
|
|
28
|
+
/** A placeholder string for the segment. */
|
|
29
|
+
placeholder: string;
|
|
30
|
+
}
|
|
31
|
+
export interface TimeFieldStateProps<T extends TimeValue = Time> {
|
|
32
|
+
/** The current value (controlled). */
|
|
33
|
+
value?: MaybeAccessor<T | null>;
|
|
34
|
+
/** The default value (uncontrolled). */
|
|
35
|
+
defaultValue?: T | null;
|
|
36
|
+
/** Handler called when the value changes. */
|
|
37
|
+
onChange?: (value: T | null) => void;
|
|
38
|
+
/** The minimum allowed time. */
|
|
39
|
+
minValue?: MaybeAccessor<TimeValue | undefined>;
|
|
40
|
+
/** The maximum allowed time. */
|
|
41
|
+
maxValue?: MaybeAccessor<TimeValue | undefined>;
|
|
42
|
+
/** Whether the field is disabled. */
|
|
43
|
+
isDisabled?: MaybeAccessor<boolean>;
|
|
44
|
+
/** Whether the field is read-only. */
|
|
45
|
+
isReadOnly?: MaybeAccessor<boolean>;
|
|
46
|
+
/** Whether the field is required. */
|
|
47
|
+
isRequired?: MaybeAccessor<boolean>;
|
|
48
|
+
/** The locale to use for formatting. */
|
|
49
|
+
locale?: string;
|
|
50
|
+
/** The granularity (hour, minute, second). */
|
|
51
|
+
granularity?: 'hour' | 'minute' | 'second';
|
|
52
|
+
/** Whether to show 12 or 24 hour format. */
|
|
53
|
+
hourCycle?: 12 | 24;
|
|
54
|
+
/** Validation state. */
|
|
55
|
+
validationState?: MaybeAccessor<ValidationState | undefined>;
|
|
56
|
+
/** The placeholder value. */
|
|
57
|
+
placeholderValue?: T;
|
|
58
|
+
}
|
|
59
|
+
export interface TimeFieldState<T extends TimeValue = Time> {
|
|
60
|
+
/** The current value. */
|
|
61
|
+
value: Accessor<T | null>;
|
|
62
|
+
/** Sets the value. */
|
|
63
|
+
setValue: (value: T | null) => void;
|
|
64
|
+
/** The segments that make up the time. */
|
|
65
|
+
segments: Accessor<TimeSegment[]>;
|
|
66
|
+
/** Sets a segment value. */
|
|
67
|
+
setSegment: (type: TimeSegmentType, value: number) => void;
|
|
68
|
+
/** Increments a segment. */
|
|
69
|
+
incrementSegment: (type: TimeSegmentType) => void;
|
|
70
|
+
/** Decrements a segment. */
|
|
71
|
+
decrementSegment: (type: TimeSegmentType) => void;
|
|
72
|
+
/** Clears a segment. */
|
|
73
|
+
clearSegment: (type: TimeSegmentType) => void;
|
|
74
|
+
/** Whether the field is disabled. */
|
|
75
|
+
isDisabled: Accessor<boolean>;
|
|
76
|
+
/** Whether the field is read-only. */
|
|
77
|
+
isReadOnly: Accessor<boolean>;
|
|
78
|
+
/** Whether the field is required. */
|
|
79
|
+
isRequired: Accessor<boolean>;
|
|
80
|
+
/** The validation state. */
|
|
81
|
+
validationState: Accessor<ValidationState | undefined>;
|
|
82
|
+
/** The granularity. */
|
|
83
|
+
granularity: 'hour' | 'minute' | 'second';
|
|
84
|
+
/** Whether the value is invalid. */
|
|
85
|
+
isInvalid: Accessor<boolean>;
|
|
86
|
+
/** The locale. */
|
|
87
|
+
locale: string;
|
|
88
|
+
/** The hour cycle. */
|
|
89
|
+
hourCycle: 12 | 24;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Provides state management for a time field component.
|
|
93
|
+
*/
|
|
94
|
+
export declare function createTimeFieldState<T extends TimeValue = Time>(props?: TimeFieldStateProps<T>): TimeFieldState<T>;
|
|
95
|
+
//# sourceMappingURL=createTimeFieldState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTimeFieldState.d.ts","sourceRoot":"","sources":["createTimeFieldState.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA4B,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EACL,KAAK,IAAI,EACT,KAAK,gBAAg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