@carbon-labs/wc-date-picker 0.2.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 +201 -0
- package/es/__stories__/date-picker.stories.d.ts +949 -0
- package/es/components/date-picker/calendar-renderer.d.ts +147 -0
- package/es/components/date-picker/calendar-renderer.js +406 -0
- package/es/components/date-picker/calendar-renderer.js.map +1 -0
- package/es/components/date-picker/date-picker-input-skeleton.d.ts +34 -0
- package/es/components/date-picker/date-picker-input-skeleton.js +77 -0
- package/es/components/date-picker/date-picker-input-skeleton.js.map +1 -0
- package/es/components/date-picker/date-picker-input.d.ts +539 -0
- package/es/components/date-picker/date-picker-input.js +413 -0
- package/es/components/date-picker/date-picker-input.js.map +1 -0
- package/es/components/date-picker/date-picker.d.ts +977 -0
- package/es/components/date-picker/date-picker.js +1047 -0
- package/es/components/date-picker/date-picker.js.map +1 -0
- package/es/components/date-picker/date-picker.scss.js +6 -0
- package/es/components/date-picker/date-picker.scss.js.map +1 -0
- package/es/components/date-picker/defs.d.ts +45 -0
- package/es/components/date-picker/defs.js +51 -0
- package/es/components/date-picker/defs.js.map +1 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +5 -0
- package/es/index.js.map +1 -0
- package/es/state-machine/actions.d.ts +35 -0
- package/es/state-machine/actions.js +860 -0
- package/es/state-machine/actions.js.map +1 -0
- package/es/state-machine/adapters/web-component-adapter.d.ts +142 -0
- package/es/state-machine/adapters/web-component-adapter.js +269 -0
- package/es/state-machine/adapters/web-component-adapter.js.map +1 -0
- package/es/state-machine/effects.d.ts +35 -0
- package/es/state-machine/effects.js +92 -0
- package/es/state-machine/effects.js.map +1 -0
- package/es/state-machine/guards.d.ts +41 -0
- package/es/state-machine/guards.js +143 -0
- package/es/state-machine/guards.js.map +1 -0
- package/es/state-machine/index.d.ts +12 -0
- package/es/state-machine/machine.d.ts +92 -0
- package/es/state-machine/machine.js +272 -0
- package/es/state-machine/machine.js.map +1 -0
- package/es/state-machine/states.d.ts +89 -0
- package/es/state-machine/states.js +105 -0
- package/es/state-machine/states.js.map +1 -0
- package/es/state-machine/temporal-utils.d.ts +203 -0
- package/es/state-machine/temporal-utils.js +128 -0
- package/es/state-machine/temporal-utils.js.map +1 -0
- package/es/state-machine/types.d.ts +163 -0
- package/es/temp-imports/.storybook/templates/with-layer.d.ts +26 -0
- package/es/temp-imports/globals/decorators/carbon-element.d.ts +45 -0
- package/es/temp-imports/globals/decorators/carbon-element.js +63 -0
- package/es/temp-imports/globals/decorators/carbon-element.js.map +1 -0
- package/es/temp-imports/globals/decorators/host-listener.d.ts +17 -0
- package/es/temp-imports/globals/decorators/host-listener.js +62 -0
- package/es/temp-imports/globals/decorators/host-listener.js.map +1 -0
- package/es/temp-imports/globals/internal/collection-helpers.d.ts +41 -0
- package/es/temp-imports/globals/internal/handle.d.ts +16 -0
- package/es/temp-imports/globals/internal/icon-loader-utils.d.ts +31 -0
- package/es/temp-imports/globals/internal/icon-loader-utils.js +69 -0
- package/es/temp-imports/globals/internal/icon-loader-utils.js.map +1 -0
- package/es/temp-imports/globals/internal/icon-loader.d.ts +28 -0
- package/es/temp-imports/globals/internal/icon-loader.js +43 -0
- package/es/temp-imports/globals/internal/icon-loader.js.map +1 -0
- package/es/temp-imports/globals/mixins/focus.d.ts +369 -0
- package/es/temp-imports/globals/mixins/focus.js +38 -0
- package/es/temp-imports/globals/mixins/focus.js.map +1 -0
- package/es/temp-imports/globals/mixins/form.d.ts +379 -0
- package/es/temp-imports/globals/mixins/form.js +49 -0
- package/es/temp-imports/globals/mixins/form.js.map +1 -0
- package/es/temp-imports/globals/mixins/host-listener.d.ts +387 -0
- package/es/temp-imports/globals/mixins/host-listener.js +76 -0
- package/es/temp-imports/globals/mixins/host-listener.js.map +1 -0
- package/es/temp-imports/globals/mixins/on.d.ts +9 -0
- package/es/temp-imports/globals/mixins/on.js +19 -0
- package/es/temp-imports/globals/mixins/on.js.map +1 -0
- package/es/temp-imports/globals/settings.d.ts +13 -0
- package/es/temp-imports/globals/settings.js +76 -0
- package/es/temp-imports/globals/settings.js.map +1 -0
- package/es/temp-imports/globals/shared-enums.d.ts +19 -0
- package/es/temp-imports/globals/shared-enums.js +23 -0
- package/es/temp-imports/globals/shared-enums.js.map +1 -0
- package/lib/__stories__/date-picker.stories.d.ts +949 -0
- package/lib/components/date-picker/calendar-renderer.d.ts +147 -0
- package/lib/components/date-picker/calendar-renderer.js +408 -0
- package/lib/components/date-picker/calendar-renderer.js.map +1 -0
- package/lib/components/date-picker/date-picker-input-skeleton.d.ts +34 -0
- package/lib/components/date-picker/date-picker-input-skeleton.js +79 -0
- package/lib/components/date-picker/date-picker-input-skeleton.js.map +1 -0
- package/lib/components/date-picker/date-picker-input.d.ts +539 -0
- package/lib/components/date-picker/date-picker-input.js +422 -0
- package/lib/components/date-picker/date-picker-input.js.map +1 -0
- package/lib/components/date-picker/date-picker.d.ts +977 -0
- package/lib/components/date-picker/date-picker.js +1049 -0
- package/lib/components/date-picker/date-picker.js.map +1 -0
- package/lib/components/date-picker/date-picker.scss.js +10 -0
- package/lib/components/date-picker/date-picker.scss.js.map +1 -0
- package/lib/components/date-picker/defs.d.ts +45 -0
- package/lib/components/date-picker/defs.js +56 -0
- package/lib/components/date-picker/defs.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/state-machine/actions.d.ts +35 -0
- package/lib/state-machine/actions.js +864 -0
- package/lib/state-machine/actions.js.map +1 -0
- package/lib/state-machine/adapters/web-component-adapter.d.ts +142 -0
- package/lib/state-machine/adapters/web-component-adapter.js +271 -0
- package/lib/state-machine/adapters/web-component-adapter.js.map +1 -0
- package/lib/state-machine/effects.d.ts +35 -0
- package/lib/state-machine/effects.js +96 -0
- package/lib/state-machine/effects.js.map +1 -0
- package/lib/state-machine/guards.d.ts +41 -0
- package/lib/state-machine/guards.js +147 -0
- package/lib/state-machine/guards.js.map +1 -0
- package/lib/state-machine/index.d.ts +12 -0
- package/lib/state-machine/machine.d.ts +92 -0
- package/lib/state-machine/machine.js +274 -0
- package/lib/state-machine/machine.js.map +1 -0
- package/lib/state-machine/states.d.ts +89 -0
- package/lib/state-machine/states.js +105 -0
- package/lib/state-machine/states.js.map +1 -0
- package/lib/state-machine/temporal-utils.d.ts +203 -0
- package/lib/state-machine/temporal-utils.js +136 -0
- package/lib/state-machine/temporal-utils.js.map +1 -0
- package/lib/state-machine/types.d.ts +163 -0
- package/lib/temp-imports/.storybook/templates/with-layer.d.ts +26 -0
- package/lib/temp-imports/globals/decorators/carbon-element.d.ts +45 -0
- package/lib/temp-imports/globals/decorators/carbon-element.js +65 -0
- package/lib/temp-imports/globals/decorators/carbon-element.js.map +1 -0
- package/lib/temp-imports/globals/decorators/host-listener.d.ts +17 -0
- package/lib/temp-imports/globals/decorators/host-listener.js +66 -0
- package/lib/temp-imports/globals/decorators/host-listener.js.map +1 -0
- package/lib/temp-imports/globals/internal/collection-helpers.d.ts +41 -0
- package/lib/temp-imports/globals/internal/handle.d.ts +16 -0
- package/lib/temp-imports/globals/internal/icon-loader-utils.d.ts +31 -0
- package/lib/temp-imports/globals/internal/icon-loader-utils.js +72 -0
- package/lib/temp-imports/globals/internal/icon-loader-utils.js.map +1 -0
- package/lib/temp-imports/globals/internal/icon-loader.d.ts +28 -0
- package/lib/temp-imports/globals/internal/icon-loader.js +45 -0
- package/lib/temp-imports/globals/internal/icon-loader.js.map +1 -0
- package/lib/temp-imports/globals/mixins/focus.d.ts +369 -0
- package/lib/temp-imports/globals/mixins/focus.js +42 -0
- package/lib/temp-imports/globals/mixins/focus.js.map +1 -0
- package/lib/temp-imports/globals/mixins/form.d.ts +379 -0
- package/lib/temp-imports/globals/mixins/form.js +53 -0
- package/lib/temp-imports/globals/mixins/form.js.map +1 -0
- package/lib/temp-imports/globals/mixins/host-listener.d.ts +387 -0
- package/lib/temp-imports/globals/mixins/host-listener.js +80 -0
- package/lib/temp-imports/globals/mixins/host-listener.js.map +1 -0
- package/lib/temp-imports/globals/mixins/on.d.ts +9 -0
- package/lib/temp-imports/globals/mixins/on.js +23 -0
- package/lib/temp-imports/globals/mixins/on.js.map +1 -0
- package/lib/temp-imports/globals/settings.d.ts +13 -0
- package/lib/temp-imports/globals/settings.js +79 -0
- package/lib/temp-imports/globals/settings.js.map +1 -0
- package/lib/temp-imports/globals/shared-enums.d.ts +19 -0
- package/lib/temp-imports/globals/shared-enums.js +23 -0
- package/lib/temp-imports/globals/shared-enums.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var states = require('./states.js');
|
|
4
|
+
var temporalUtils = require('./temporal-utils.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Copyright IBM Corp. 2026
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Actions for state transitions
|
|
14
|
+
*/
|
|
15
|
+
const actions = {
|
|
16
|
+
[states.DatePickerState.IDLE]: {
|
|
17
|
+
/**
|
|
18
|
+
* Action for CALENDAR_ICON_CLICK event
|
|
19
|
+
*
|
|
20
|
+
* @param {DatePickerContext} context - Current context
|
|
21
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
22
|
+
*/
|
|
23
|
+
CALENDAR_ICON_CLICK: (context) => {
|
|
24
|
+
// Initialize viewDate to today if not set
|
|
25
|
+
const viewDate = context.viewDate || context.startDate || Temporal.Now.plainDateISO();
|
|
26
|
+
// Initialize focusedDate to selected date or today if no date is selected
|
|
27
|
+
const focusedDate = context.startDate || Temporal.Now.plainDateISO();
|
|
28
|
+
return {
|
|
29
|
+
isOpen: true,
|
|
30
|
+
viewDate,
|
|
31
|
+
focusedDate,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
/** Action for INPUT_BLUR event */
|
|
35
|
+
INPUT_BLUR: () => ({
|
|
36
|
+
isFocused: false,
|
|
37
|
+
}),
|
|
38
|
+
/** Action for OUTSIDE_CLICK event */
|
|
39
|
+
OUTSIDE_CLICK: () => ({
|
|
40
|
+
isOpen: false,
|
|
41
|
+
isFocused: false,
|
|
42
|
+
}),
|
|
43
|
+
/** Action for CALENDAR_CLOSE event */
|
|
44
|
+
CALENDAR_CLOSE: () => ({
|
|
45
|
+
isOpen: false,
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
[states.DatePickerState.FOCUSED]: {
|
|
49
|
+
/**
|
|
50
|
+
* Action for INPUT_FOCUS event
|
|
51
|
+
*
|
|
52
|
+
* @param {DatePickerContext} _context - The current context (unused)
|
|
53
|
+
* @param {DatePickerEvent} event - The event
|
|
54
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
55
|
+
*/
|
|
56
|
+
INPUT_FOCUS: (_context, event) => {
|
|
57
|
+
const payload = event.payload;
|
|
58
|
+
return {
|
|
59
|
+
isFocused: true,
|
|
60
|
+
lastFocusedInput: (payload === null || payload === void 0 ? void 0 : payload.inputType) || 'from',
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Action for CALENDAR_OPEN event from FOCUSED state
|
|
65
|
+
*
|
|
66
|
+
* @param {DatePickerContext} context - Current context
|
|
67
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
68
|
+
*/
|
|
69
|
+
CALENDAR_OPEN: (context) => {
|
|
70
|
+
// Initialize viewDate to today if not set
|
|
71
|
+
const viewDate = context.viewDate || context.startDate || Temporal.Now.plainDateISO();
|
|
72
|
+
// Initialize focusedDate to selected date or today if no date is selected
|
|
73
|
+
const focusedDate = context.startDate || Temporal.Now.plainDateISO();
|
|
74
|
+
return {
|
|
75
|
+
isOpen: true,
|
|
76
|
+
viewDate,
|
|
77
|
+
focusedDate,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
[states.DatePickerState.CALENDAR_OPEN]: {
|
|
82
|
+
/**
|
|
83
|
+
* Action for CALENDAR_OPEN event
|
|
84
|
+
*
|
|
85
|
+
* @param {DatePickerContext} context - Current context
|
|
86
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
87
|
+
*/
|
|
88
|
+
CALENDAR_OPEN: (context) => {
|
|
89
|
+
// Initialize viewDate to today if not set
|
|
90
|
+
const viewDate = context.viewDate || context.startDate || Temporal.Now.plainDateISO();
|
|
91
|
+
// Initialize focusedDate for keyboard navigation
|
|
92
|
+
const focusedDate = context.startDate || viewDate;
|
|
93
|
+
return {
|
|
94
|
+
isOpen: true,
|
|
95
|
+
viewDate,
|
|
96
|
+
focusedDate,
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Action for CALENDAR_ICON_CLICK event
|
|
101
|
+
*
|
|
102
|
+
* @param {DatePickerContext} context - Current context
|
|
103
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
104
|
+
*/
|
|
105
|
+
CALENDAR_ICON_CLICK: (context) => {
|
|
106
|
+
// Initialize viewDate to today if not set
|
|
107
|
+
const viewDate = context.viewDate || context.startDate || Temporal.Now.plainDateISO();
|
|
108
|
+
// Initialize focusedDate for keyboard navigation
|
|
109
|
+
const focusedDate = context.startDate || viewDate;
|
|
110
|
+
return {
|
|
111
|
+
isOpen: true,
|
|
112
|
+
viewDate,
|
|
113
|
+
focusedDate,
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* Action for RANGE_START_SELECT event
|
|
118
|
+
*
|
|
119
|
+
* @param {DatePickerContext} _context - Current context
|
|
120
|
+
* @param {DatePickerEvent} event - The event
|
|
121
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
122
|
+
*/
|
|
123
|
+
RANGE_START_SELECT: (_context, event) => {
|
|
124
|
+
const payload = event.payload;
|
|
125
|
+
const startDate = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
126
|
+
if (!startDate) {
|
|
127
|
+
return {};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
startDate,
|
|
131
|
+
endDate: null, // Reset end date when selecting a new start
|
|
132
|
+
value: temporalUtils.plainDateToISOString(startDate),
|
|
133
|
+
viewDate: startDate, // Set view date to show the selected month
|
|
134
|
+
focusedDate: startDate, // Set focused date to the selected start date
|
|
135
|
+
isOpen: true, // Keep calendar open for selecting end date
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Action for DATE_SELECT event (single mode)
|
|
140
|
+
*
|
|
141
|
+
* @param {DatePickerContext} _context - Current context
|
|
142
|
+
* @param {DatePickerEvent} event - The event
|
|
143
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
144
|
+
*/
|
|
145
|
+
DATE_SELECT: (_context, event) => {
|
|
146
|
+
const payload = event.payload;
|
|
147
|
+
const startDate = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
148
|
+
if (!startDate) {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
startDate,
|
|
153
|
+
value: temporalUtils.plainDateToISOString(startDate),
|
|
154
|
+
isOpen: false, // Close calendar after selecting date in single mode
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Action for PREV_MONTH event
|
|
159
|
+
*
|
|
160
|
+
* @param {DatePickerContext} context - Current context
|
|
161
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
162
|
+
*/
|
|
163
|
+
PREV_MONTH: (context) => {
|
|
164
|
+
if (!context.viewDate) {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
viewDate: context.viewDate.add({ months: -1 }),
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
/**
|
|
172
|
+
* Action for NEXT_MONTH event
|
|
173
|
+
*
|
|
174
|
+
* @param {DatePickerContext} context - Current context
|
|
175
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
176
|
+
*/
|
|
177
|
+
NEXT_MONTH: (context) => {
|
|
178
|
+
if (!context.viewDate) {
|
|
179
|
+
return {};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
viewDate: context.viewDate.add({ months: 1 }),
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Action for PREV_YEAR event
|
|
187
|
+
*
|
|
188
|
+
* @param {DatePickerContext} context - Current context
|
|
189
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
190
|
+
*/
|
|
191
|
+
PREV_YEAR: (context) => {
|
|
192
|
+
if (!context.viewDate) {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
viewDate: context.viewDate.add({ years: -1 }),
|
|
197
|
+
};
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* Action for NEXT_YEAR event
|
|
201
|
+
*
|
|
202
|
+
* @param {DatePickerContext} context - Current context
|
|
203
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
204
|
+
*/
|
|
205
|
+
NEXT_YEAR: (context) => {
|
|
206
|
+
if (!context.viewDate) {
|
|
207
|
+
return {};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
viewDate: context.viewDate.add({ years: 1 }),
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
/** Action for GO_TO_TODAY event */
|
|
214
|
+
GO_TO_TODAY: () => ({
|
|
215
|
+
viewDate: Temporal.Now.plainDateISO(),
|
|
216
|
+
}),
|
|
217
|
+
/**
|
|
218
|
+
* Action for ESCAPE_KEY event - close calendar
|
|
219
|
+
*
|
|
220
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
221
|
+
*/
|
|
222
|
+
ESCAPE_KEY: () => ({
|
|
223
|
+
isOpen: false,
|
|
224
|
+
}),
|
|
225
|
+
/**
|
|
226
|
+
* Action for TAB_KEY event - close calendar
|
|
227
|
+
*
|
|
228
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
229
|
+
*/
|
|
230
|
+
TAB_KEY: () => ({
|
|
231
|
+
isOpen: false,
|
|
232
|
+
}),
|
|
233
|
+
/**
|
|
234
|
+
* Action for ENTER_KEY event - select focused date
|
|
235
|
+
*
|
|
236
|
+
* @param {DatePickerContext} context - Current context
|
|
237
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
238
|
+
*/
|
|
239
|
+
ENTER_KEY: (context) => {
|
|
240
|
+
if (!context.focusedDate) {
|
|
241
|
+
return {};
|
|
242
|
+
}
|
|
243
|
+
// Select the focused date (same logic as DATE_SELECT)
|
|
244
|
+
return {
|
|
245
|
+
startDate: context.focusedDate,
|
|
246
|
+
value: temporalUtils.plainDateToISOString(context.focusedDate),
|
|
247
|
+
isOpen: context.closeOnSelect ? false : context.isOpen,
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Action for ARROW_UP event - move focus up one week
|
|
252
|
+
*
|
|
253
|
+
* @param {DatePickerContext} context - Current context
|
|
254
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
255
|
+
*/
|
|
256
|
+
ARROW_UP: (context) => {
|
|
257
|
+
const focusedDate = context.focusedDate ||
|
|
258
|
+
context.startDate ||
|
|
259
|
+
context.viewDate ||
|
|
260
|
+
Temporal.Now.plainDateISO();
|
|
261
|
+
const newFocusedDate = focusedDate.add({ days: -7 });
|
|
262
|
+
// If we moved to a different month, update viewDate
|
|
263
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
264
|
+
? newFocusedDate
|
|
265
|
+
: context.viewDate;
|
|
266
|
+
return {
|
|
267
|
+
focusedDate: newFocusedDate,
|
|
268
|
+
viewDate,
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Action for ARROW_DOWN event - move focus down one week
|
|
273
|
+
*
|
|
274
|
+
* @param {DatePickerContext} context - Current context
|
|
275
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
276
|
+
*/
|
|
277
|
+
ARROW_DOWN: (context) => {
|
|
278
|
+
const focusedDate = context.focusedDate ||
|
|
279
|
+
context.startDate ||
|
|
280
|
+
context.viewDate ||
|
|
281
|
+
Temporal.Now.plainDateISO();
|
|
282
|
+
const newFocusedDate = focusedDate.add({ days: 7 });
|
|
283
|
+
// If we moved to a different month, update viewDate
|
|
284
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
285
|
+
? newFocusedDate
|
|
286
|
+
: context.viewDate;
|
|
287
|
+
return {
|
|
288
|
+
focusedDate: newFocusedDate,
|
|
289
|
+
viewDate,
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
/**
|
|
293
|
+
* Action for ARROW_LEFT event - move focus left one day
|
|
294
|
+
*
|
|
295
|
+
* @param {DatePickerContext} context - Current context
|
|
296
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
297
|
+
*/
|
|
298
|
+
ARROW_LEFT: (context) => {
|
|
299
|
+
const focusedDate = context.focusedDate ||
|
|
300
|
+
context.startDate ||
|
|
301
|
+
context.viewDate ||
|
|
302
|
+
Temporal.Now.plainDateISO();
|
|
303
|
+
const newFocusedDate = focusedDate.add({ days: -1 });
|
|
304
|
+
// If we moved to a different month, update viewDate
|
|
305
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
306
|
+
? newFocusedDate
|
|
307
|
+
: context.viewDate;
|
|
308
|
+
return {
|
|
309
|
+
focusedDate: newFocusedDate,
|
|
310
|
+
viewDate,
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
/**
|
|
314
|
+
* Action for ARROW_RIGHT event - move focus right one day
|
|
315
|
+
*
|
|
316
|
+
* @param {DatePickerContext} context - Current context
|
|
317
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
318
|
+
*/
|
|
319
|
+
ARROW_RIGHT: (context) => {
|
|
320
|
+
const focusedDate = context.focusedDate ||
|
|
321
|
+
context.startDate ||
|
|
322
|
+
context.viewDate ||
|
|
323
|
+
Temporal.Now.plainDateISO();
|
|
324
|
+
const newFocusedDate = focusedDate.add({ days: 1 });
|
|
325
|
+
// If we moved to a different month, update viewDate
|
|
326
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
327
|
+
? newFocusedDate
|
|
328
|
+
: context.viewDate;
|
|
329
|
+
return {
|
|
330
|
+
focusedDate: newFocusedDate,
|
|
331
|
+
viewDate,
|
|
332
|
+
};
|
|
333
|
+
},
|
|
334
|
+
/**
|
|
335
|
+
* Action for PAGE_UP event - move to previous month
|
|
336
|
+
*
|
|
337
|
+
* @param {DatePickerContext} context - Current context
|
|
338
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
339
|
+
*/
|
|
340
|
+
PAGE_UP: (context) => {
|
|
341
|
+
if (!context.viewDate) {
|
|
342
|
+
return {};
|
|
343
|
+
}
|
|
344
|
+
const newViewDate = context.viewDate.add({ months: -1 });
|
|
345
|
+
const focusedDate = context.focusedDate
|
|
346
|
+
? context.focusedDate.add({ months: -1 })
|
|
347
|
+
: null;
|
|
348
|
+
return {
|
|
349
|
+
viewDate: newViewDate,
|
|
350
|
+
focusedDate,
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
/**
|
|
354
|
+
* Action for PAGE_DOWN event - move to next month
|
|
355
|
+
*
|
|
356
|
+
* @param {DatePickerContext} context - Current context
|
|
357
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
358
|
+
*/
|
|
359
|
+
PAGE_DOWN: (context) => {
|
|
360
|
+
if (!context.viewDate) {
|
|
361
|
+
return {};
|
|
362
|
+
}
|
|
363
|
+
const newViewDate = context.viewDate.add({ months: 1 });
|
|
364
|
+
const focusedDate = context.focusedDate
|
|
365
|
+
? context.focusedDate.add({ months: 1 })
|
|
366
|
+
: null;
|
|
367
|
+
return {
|
|
368
|
+
viewDate: newViewDate,
|
|
369
|
+
focusedDate,
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
/**
|
|
373
|
+
* Action for HOME_KEY event - move to start of week
|
|
374
|
+
*
|
|
375
|
+
* @param {DatePickerContext} context - Current context
|
|
376
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
377
|
+
*/
|
|
378
|
+
HOME_KEY: (context) => {
|
|
379
|
+
const focusedDate = context.focusedDate ||
|
|
380
|
+
context.startDate ||
|
|
381
|
+
context.viewDate ||
|
|
382
|
+
Temporal.Now.plainDateISO();
|
|
383
|
+
// Convert to JS Date to get day of week (0 = Sunday, 6 = Saturday)
|
|
384
|
+
const jsDate = new Date(focusedDate.year, focusedDate.month - 1, focusedDate.day);
|
|
385
|
+
const dayOfWeek = jsDate.getDay();
|
|
386
|
+
// Move to Sunday (start of week in US calendar)
|
|
387
|
+
const daysToSubtract = dayOfWeek;
|
|
388
|
+
const newFocusedDate = focusedDate.add({ days: -daysToSubtract });
|
|
389
|
+
// If we moved to a different month, update viewDate
|
|
390
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
391
|
+
? newFocusedDate
|
|
392
|
+
: context.viewDate;
|
|
393
|
+
return {
|
|
394
|
+
focusedDate: newFocusedDate,
|
|
395
|
+
viewDate,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
/**
|
|
399
|
+
* Action for END_KEY event - move to end of week
|
|
400
|
+
*
|
|
401
|
+
* @param {DatePickerContext} context - Current context
|
|
402
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
403
|
+
*/
|
|
404
|
+
END_KEY: (context) => {
|
|
405
|
+
const focusedDate = context.focusedDate ||
|
|
406
|
+
context.startDate ||
|
|
407
|
+
context.viewDate ||
|
|
408
|
+
Temporal.Now.plainDateISO();
|
|
409
|
+
// Convert to JS Date to get day of week (0 = Sunday, 6 = Saturday)
|
|
410
|
+
const jsDate = new Date(focusedDate.year, focusedDate.month - 1, focusedDate.day);
|
|
411
|
+
const dayOfWeek = jsDate.getDay();
|
|
412
|
+
// Move to Saturday (end of week in US calendar)
|
|
413
|
+
const daysToAdd = 6 - dayOfWeek;
|
|
414
|
+
const newFocusedDate = focusedDate.add({ days: daysToAdd });
|
|
415
|
+
// If we moved to a different month, update viewDate
|
|
416
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
417
|
+
? newFocusedDate
|
|
418
|
+
: context.viewDate;
|
|
419
|
+
return {
|
|
420
|
+
focusedDate: newFocusedDate,
|
|
421
|
+
viewDate,
|
|
422
|
+
};
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
[states.DatePickerState.SELECTING_START]: {
|
|
426
|
+
/**
|
|
427
|
+
* Action for CALENDAR_OPEN event
|
|
428
|
+
*
|
|
429
|
+
* @param {DatePickerContext} context - Current context
|
|
430
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
431
|
+
*/
|
|
432
|
+
CALENDAR_OPEN: (context) => {
|
|
433
|
+
if (context.mode === 'range') {
|
|
434
|
+
return {
|
|
435
|
+
isOpen: true,
|
|
436
|
+
startDate: null,
|
|
437
|
+
endDate: null,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return { isOpen: true };
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
[states.DatePickerState.SELECTING_END]: {
|
|
444
|
+
/**
|
|
445
|
+
* Action for RANGE_START_SELECT event
|
|
446
|
+
*
|
|
447
|
+
* @param {DatePickerContext} _context - Current context
|
|
448
|
+
* @param {DatePickerEvent} event - The event
|
|
449
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
450
|
+
*/
|
|
451
|
+
RANGE_START_SELECT: (_context, event) => {
|
|
452
|
+
const payload = event.payload;
|
|
453
|
+
const startDate = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
454
|
+
if (!startDate) {
|
|
455
|
+
return {};
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
startDate,
|
|
459
|
+
endDate: null, // Reset end date when selecting a new start
|
|
460
|
+
value: temporalUtils.plainDateToISOString(startDate),
|
|
461
|
+
};
|
|
462
|
+
},
|
|
463
|
+
/**
|
|
464
|
+
* Action for RANGE_END_SELECT event
|
|
465
|
+
*
|
|
466
|
+
* @param {DatePickerContext} context - Current context
|
|
467
|
+
* @param {DatePickerEvent} event - The event
|
|
468
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
469
|
+
*/
|
|
470
|
+
RANGE_END_SELECT: (context, event) => {
|
|
471
|
+
const payload = event.payload;
|
|
472
|
+
const endDate = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
473
|
+
const { startDate } = context;
|
|
474
|
+
if (!endDate || !startDate) {
|
|
475
|
+
return {};
|
|
476
|
+
}
|
|
477
|
+
// Ensure end date is after start date, swap if needed
|
|
478
|
+
let finalStartDate = startDate;
|
|
479
|
+
let finalEndDate = endDate;
|
|
480
|
+
if (temporalUtils.comparePlainDates(endDate, startDate) < 0) {
|
|
481
|
+
finalStartDate = endDate;
|
|
482
|
+
finalEndDate = startDate;
|
|
483
|
+
}
|
|
484
|
+
return {
|
|
485
|
+
startDate: finalStartDate,
|
|
486
|
+
endDate: finalEndDate,
|
|
487
|
+
value: `${temporalUtils.plainDateToISOString(finalStartDate)}/${temporalUtils.plainDateToISOString(finalEndDate)}`,
|
|
488
|
+
isOpen: false, // Always close after selecting end date in range mode
|
|
489
|
+
lastFocusedInput: 'to', // Set to 'to' so the end date input gets updated
|
|
490
|
+
};
|
|
491
|
+
},
|
|
492
|
+
/**
|
|
493
|
+
* Action for ESCAPE_KEY event - close calendar
|
|
494
|
+
*
|
|
495
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
496
|
+
*/
|
|
497
|
+
ESCAPE_KEY: () => ({
|
|
498
|
+
isOpen: false,
|
|
499
|
+
}),
|
|
500
|
+
/**
|
|
501
|
+
* Action for TAB_KEY event - close calendar
|
|
502
|
+
*
|
|
503
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
504
|
+
*/
|
|
505
|
+
TAB_KEY: () => ({
|
|
506
|
+
isOpen: false,
|
|
507
|
+
}),
|
|
508
|
+
/**
|
|
509
|
+
* Action for ARROW_UP event - move focus up one week
|
|
510
|
+
*
|
|
511
|
+
* @param {DatePickerContext} context - Current context
|
|
512
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
513
|
+
*/
|
|
514
|
+
ARROW_UP: (context) => {
|
|
515
|
+
const focusedDate = context.focusedDate ||
|
|
516
|
+
context.startDate ||
|
|
517
|
+
context.viewDate ||
|
|
518
|
+
Temporal.Now.plainDateISO();
|
|
519
|
+
const newFocusedDate = focusedDate.add({ days: -7 });
|
|
520
|
+
// If we moved to a different month, update viewDate
|
|
521
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
522
|
+
? newFocusedDate
|
|
523
|
+
: context.viewDate;
|
|
524
|
+
return {
|
|
525
|
+
focusedDate: newFocusedDate,
|
|
526
|
+
viewDate,
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
/**
|
|
530
|
+
* Action for ARROW_DOWN event - move focus down one week
|
|
531
|
+
*
|
|
532
|
+
* @param {DatePickerContext} context - Current context
|
|
533
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
534
|
+
*/
|
|
535
|
+
ARROW_DOWN: (context) => {
|
|
536
|
+
const focusedDate = context.focusedDate ||
|
|
537
|
+
context.startDate ||
|
|
538
|
+
context.viewDate ||
|
|
539
|
+
Temporal.Now.plainDateISO();
|
|
540
|
+
const newFocusedDate = focusedDate.add({ days: 7 });
|
|
541
|
+
// If we moved to a different month, update viewDate
|
|
542
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
543
|
+
? newFocusedDate
|
|
544
|
+
: context.viewDate;
|
|
545
|
+
return {
|
|
546
|
+
focusedDate: newFocusedDate,
|
|
547
|
+
viewDate,
|
|
548
|
+
};
|
|
549
|
+
},
|
|
550
|
+
/**
|
|
551
|
+
* Action for ARROW_LEFT event - move focus left one day
|
|
552
|
+
*
|
|
553
|
+
* @param {DatePickerContext} context - Current context
|
|
554
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
555
|
+
*/
|
|
556
|
+
ARROW_LEFT: (context) => {
|
|
557
|
+
const focusedDate = context.focusedDate ||
|
|
558
|
+
context.startDate ||
|
|
559
|
+
context.viewDate ||
|
|
560
|
+
Temporal.Now.plainDateISO();
|
|
561
|
+
const newFocusedDate = focusedDate.add({ days: -1 });
|
|
562
|
+
// If we moved to a different month, update viewDate
|
|
563
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
564
|
+
? newFocusedDate
|
|
565
|
+
: context.viewDate;
|
|
566
|
+
return {
|
|
567
|
+
focusedDate: newFocusedDate,
|
|
568
|
+
viewDate,
|
|
569
|
+
};
|
|
570
|
+
},
|
|
571
|
+
/**
|
|
572
|
+
* Action for ARROW_RIGHT event - move focus right one day
|
|
573
|
+
*
|
|
574
|
+
* @param {DatePickerContext} context - Current context
|
|
575
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
576
|
+
*/
|
|
577
|
+
ARROW_RIGHT: (context) => {
|
|
578
|
+
const focusedDate = context.focusedDate ||
|
|
579
|
+
context.startDate ||
|
|
580
|
+
context.viewDate ||
|
|
581
|
+
Temporal.Now.plainDateISO();
|
|
582
|
+
const newFocusedDate = focusedDate.add({ days: 1 });
|
|
583
|
+
// If we moved to a different month, update viewDate
|
|
584
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
585
|
+
? newFocusedDate
|
|
586
|
+
: context.viewDate;
|
|
587
|
+
return {
|
|
588
|
+
focusedDate: newFocusedDate,
|
|
589
|
+
viewDate,
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
/**
|
|
593
|
+
* Action for PAGE_UP event - move to previous month
|
|
594
|
+
*
|
|
595
|
+
* @param {DatePickerContext} context - Current context
|
|
596
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
597
|
+
*/
|
|
598
|
+
PAGE_UP: (context) => {
|
|
599
|
+
const focusedDate = context.focusedDate ||
|
|
600
|
+
context.startDate ||
|
|
601
|
+
context.viewDate ||
|
|
602
|
+
Temporal.Now.plainDateISO();
|
|
603
|
+
const newFocusedDate = focusedDate.add({ months: -1 });
|
|
604
|
+
return {
|
|
605
|
+
focusedDate: newFocusedDate,
|
|
606
|
+
viewDate: newFocusedDate,
|
|
607
|
+
};
|
|
608
|
+
},
|
|
609
|
+
/**
|
|
610
|
+
* Action for PAGE_DOWN event - move to next month
|
|
611
|
+
*
|
|
612
|
+
* @param {DatePickerContext} context - Current context
|
|
613
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
614
|
+
*/
|
|
615
|
+
PAGE_DOWN: (context) => {
|
|
616
|
+
const focusedDate = context.focusedDate ||
|
|
617
|
+
context.startDate ||
|
|
618
|
+
context.viewDate ||
|
|
619
|
+
Temporal.Now.plainDateISO();
|
|
620
|
+
const newFocusedDate = focusedDate.add({ months: 1 });
|
|
621
|
+
return {
|
|
622
|
+
focusedDate: newFocusedDate,
|
|
623
|
+
viewDate: newFocusedDate,
|
|
624
|
+
};
|
|
625
|
+
},
|
|
626
|
+
/**
|
|
627
|
+
* Action for HOME_KEY event - move to start of week
|
|
628
|
+
*
|
|
629
|
+
* @param {DatePickerContext} context - Current context
|
|
630
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
631
|
+
*/
|
|
632
|
+
HOME_KEY: (context) => {
|
|
633
|
+
const focusedDate = context.focusedDate ||
|
|
634
|
+
context.startDate ||
|
|
635
|
+
context.viewDate ||
|
|
636
|
+
Temporal.Now.plainDateISO();
|
|
637
|
+
const dayOfWeek = focusedDate.dayOfWeek(); // 1 = Monday, 7 = Sunday
|
|
638
|
+
const daysToSubtract = dayOfWeek === 7 ? 0 : dayOfWeek; // Move to Sunday
|
|
639
|
+
const newFocusedDate = focusedDate.add({ days: -daysToSubtract });
|
|
640
|
+
// If we moved to a different month, update viewDate
|
|
641
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
642
|
+
? newFocusedDate
|
|
643
|
+
: context.viewDate;
|
|
644
|
+
return {
|
|
645
|
+
focusedDate: newFocusedDate,
|
|
646
|
+
viewDate,
|
|
647
|
+
};
|
|
648
|
+
},
|
|
649
|
+
/**
|
|
650
|
+
* Action for END_KEY event - move to end of week
|
|
651
|
+
*
|
|
652
|
+
* @param {DatePickerContext} context - Current context
|
|
653
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
654
|
+
*/
|
|
655
|
+
END_KEY: (context) => {
|
|
656
|
+
const focusedDate = context.focusedDate ||
|
|
657
|
+
context.startDate ||
|
|
658
|
+
context.viewDate ||
|
|
659
|
+
Temporal.Now.plainDateISO();
|
|
660
|
+
const dayOfWeek = focusedDate.dayOfWeek(); // 1 = Monday, 7 = Sunday
|
|
661
|
+
const daysToAdd = dayOfWeek === 7 ? 0 : 7 - dayOfWeek; // Move to Saturday
|
|
662
|
+
const newFocusedDate = focusedDate.add({ days: daysToAdd });
|
|
663
|
+
// If we moved to a different month, update viewDate
|
|
664
|
+
const viewDate = newFocusedDate.month !== focusedDate.month
|
|
665
|
+
? newFocusedDate
|
|
666
|
+
: context.viewDate;
|
|
667
|
+
return {
|
|
668
|
+
focusedDate: newFocusedDate,
|
|
669
|
+
viewDate,
|
|
670
|
+
};
|
|
671
|
+
},
|
|
672
|
+
/**
|
|
673
|
+
* Action for ENTER_KEY event - select focused date as end date
|
|
674
|
+
*
|
|
675
|
+
* @param {DatePickerContext} context - Current context
|
|
676
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
677
|
+
*/
|
|
678
|
+
ENTER_KEY: (context) => {
|
|
679
|
+
if (!context.focusedDate || !context.startDate) {
|
|
680
|
+
return {};
|
|
681
|
+
}
|
|
682
|
+
const endDate = context.focusedDate;
|
|
683
|
+
const { startDate } = context;
|
|
684
|
+
// Ensure end date is after start date, swap if needed
|
|
685
|
+
let finalStartDate = startDate;
|
|
686
|
+
let finalEndDate = endDate;
|
|
687
|
+
if (temporalUtils.comparePlainDates(endDate, startDate) < 0) {
|
|
688
|
+
finalStartDate = endDate;
|
|
689
|
+
finalEndDate = startDate;
|
|
690
|
+
}
|
|
691
|
+
return {
|
|
692
|
+
startDate: finalStartDate,
|
|
693
|
+
endDate: finalEndDate,
|
|
694
|
+
value: `${temporalUtils.plainDateToISOString(finalStartDate)}/${temporalUtils.plainDateToISOString(finalEndDate)}`,
|
|
695
|
+
isOpen: false, // Always close after selecting end date in range mode
|
|
696
|
+
};
|
|
697
|
+
},
|
|
698
|
+
/**
|
|
699
|
+
* Action for PREV_MONTH event
|
|
700
|
+
*
|
|
701
|
+
* @param {DatePickerContext} context - Current context
|
|
702
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
703
|
+
*/
|
|
704
|
+
PREV_MONTH: (context) => {
|
|
705
|
+
if (!context.viewDate) {
|
|
706
|
+
return {};
|
|
707
|
+
}
|
|
708
|
+
return {
|
|
709
|
+
viewDate: context.viewDate.add({ months: -1 }),
|
|
710
|
+
};
|
|
711
|
+
},
|
|
712
|
+
/**
|
|
713
|
+
* Action for NEXT_MONTH event
|
|
714
|
+
*
|
|
715
|
+
* @param {DatePickerContext} context - Current context
|
|
716
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
717
|
+
*/
|
|
718
|
+
NEXT_MONTH: (context) => {
|
|
719
|
+
if (!context.viewDate) {
|
|
720
|
+
return {};
|
|
721
|
+
}
|
|
722
|
+
return {
|
|
723
|
+
viewDate: context.viewDate.add({ months: 1 }),
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
},
|
|
727
|
+
[states.DatePickerState.DATE_SELECTED]: {
|
|
728
|
+
/**
|
|
729
|
+
* Action for DATE_SELECT event
|
|
730
|
+
*
|
|
731
|
+
* @param {DatePickerContext} context - Current context
|
|
732
|
+
* @param {DatePickerEvent} event - The event
|
|
733
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
734
|
+
*/
|
|
735
|
+
DATE_SELECT: (context, event) => {
|
|
736
|
+
const payload = event.payload;
|
|
737
|
+
const date = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
738
|
+
if (!date) {
|
|
739
|
+
return {};
|
|
740
|
+
}
|
|
741
|
+
if (context.mode === 'single') {
|
|
742
|
+
return {
|
|
743
|
+
startDate: date,
|
|
744
|
+
value: temporalUtils.plainDateToISOString(date),
|
|
745
|
+
isOpen: context.closeOnSelect ? false : context.isOpen,
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
return {};
|
|
749
|
+
},
|
|
750
|
+
/**
|
|
751
|
+
* Action for RANGE_END_SELECT event
|
|
752
|
+
*
|
|
753
|
+
* @param {DatePickerContext} context - Current context
|
|
754
|
+
* @param {DatePickerEvent} event - The event
|
|
755
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
756
|
+
*/
|
|
757
|
+
RANGE_END_SELECT: (context, event) => {
|
|
758
|
+
const payload = event.payload;
|
|
759
|
+
const endDate = payload === null || payload === void 0 ? void 0 : payload.date;
|
|
760
|
+
const { startDate } = context;
|
|
761
|
+
if (!endDate || !startDate) {
|
|
762
|
+
return {};
|
|
763
|
+
}
|
|
764
|
+
// Ensure end date is after start date, swap if needed
|
|
765
|
+
let finalStartDate = startDate;
|
|
766
|
+
let finalEndDate = endDate;
|
|
767
|
+
if (temporalUtils.comparePlainDates(endDate, startDate) < 0) {
|
|
768
|
+
finalStartDate = endDate;
|
|
769
|
+
finalEndDate = startDate;
|
|
770
|
+
}
|
|
771
|
+
return {
|
|
772
|
+
startDate: finalStartDate,
|
|
773
|
+
endDate: finalEndDate,
|
|
774
|
+
value: `${temporalUtils.plainDateToISOString(finalStartDate)}/${temporalUtils.plainDateToISOString(finalEndDate)}`,
|
|
775
|
+
isOpen: context.closeOnSelect ? false : context.isOpen,
|
|
776
|
+
};
|
|
777
|
+
},
|
|
778
|
+
/** Action for CALENDAR_CLOSE event */
|
|
779
|
+
CALENDAR_CLOSE: () => ({
|
|
780
|
+
isOpen: false,
|
|
781
|
+
}),
|
|
782
|
+
},
|
|
783
|
+
[states.DatePickerState.DISABLED]: {
|
|
784
|
+
/** Action for a DISABLE event */
|
|
785
|
+
DISABLE: () => ({
|
|
786
|
+
isDisabled: true,
|
|
787
|
+
isOpen: false,
|
|
788
|
+
}),
|
|
789
|
+
/** Action for ENABLE event */
|
|
790
|
+
ENABLE: () => ({
|
|
791
|
+
isDisabled: false,
|
|
792
|
+
}),
|
|
793
|
+
},
|
|
794
|
+
[states.DatePickerState.READONLY]: {
|
|
795
|
+
/** Action for SET_READONLY event */
|
|
796
|
+
SET_READONLY: () => ({
|
|
797
|
+
isReadonly: true,
|
|
798
|
+
isOpen: false,
|
|
799
|
+
}),
|
|
800
|
+
/** Action for UNSET_READONLY event */
|
|
801
|
+
UNSET_READONLY: () => ({
|
|
802
|
+
isReadonly: false,
|
|
803
|
+
}),
|
|
804
|
+
},
|
|
805
|
+
[states.DatePickerState.ERROR]: {
|
|
806
|
+
/**
|
|
807
|
+
* Action for VALIDATION_ERROR event
|
|
808
|
+
*
|
|
809
|
+
* @param {DatePickerContext} _context - Current context (unused)
|
|
810
|
+
* @param {DatePickerEvent} event - The event
|
|
811
|
+
* @returns {Partial<DatePickerContext>} Updated context
|
|
812
|
+
*/
|
|
813
|
+
VALIDATION_ERROR: (_context, event) => {
|
|
814
|
+
const payload = event.payload;
|
|
815
|
+
return {
|
|
816
|
+
isInvalid: true,
|
|
817
|
+
errorMessage: (payload === null || payload === void 0 ? void 0 : payload.message) || 'Invalid date',
|
|
818
|
+
};
|
|
819
|
+
},
|
|
820
|
+
/** Action for CLEAR_ERROR event */
|
|
821
|
+
CLEAR_ERROR: () => ({
|
|
822
|
+
isInvalid: false,
|
|
823
|
+
errorMessage: undefined,
|
|
824
|
+
}),
|
|
825
|
+
/** Action for VALUE_CHANGE event */
|
|
826
|
+
VALUE_CHANGE: () => ({
|
|
827
|
+
isInvalid: false,
|
|
828
|
+
errorMessage: undefined,
|
|
829
|
+
}),
|
|
830
|
+
},
|
|
831
|
+
};
|
|
832
|
+
/**
|
|
833
|
+
* Get action for a specific state and event
|
|
834
|
+
*
|
|
835
|
+
* @param {DatePickerState} state - The current state
|
|
836
|
+
* @param {string} eventType - The event type
|
|
837
|
+
* @returns {StateAction | undefined} The action function or undefined
|
|
838
|
+
*/
|
|
839
|
+
function getAction(state, eventType) {
|
|
840
|
+
var _a;
|
|
841
|
+
return (_a = actions[state]) === null || _a === void 0 ? void 0 : _a[eventType];
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Execute an action and return context updates
|
|
845
|
+
*
|
|
846
|
+
* @param {DatePickerState} state - The current state
|
|
847
|
+
* @param {string} eventType - The event type
|
|
848
|
+
* @param {DatePickerContext} context - The current context
|
|
849
|
+
* @param {DatePickerEvent} event - The event
|
|
850
|
+
* @returns {Partial<DatePickerContext>} Partial context updates
|
|
851
|
+
*/
|
|
852
|
+
function executeAction(state, eventType, context, event) {
|
|
853
|
+
const action = getAction(state, eventType);
|
|
854
|
+
if (!action) {
|
|
855
|
+
return {};
|
|
856
|
+
}
|
|
857
|
+
return action(context, event);
|
|
858
|
+
}
|
|
859
|
+
// Made with Bob
|
|
860
|
+
|
|
861
|
+
exports.actions = actions;
|
|
862
|
+
exports.executeAction = executeAction;
|
|
863
|
+
exports.getAction = getAction;
|
|
864
|
+
//# sourceMappingURL=actions.js.map
|