@quickbuilder.io/date-pickers 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +167 -2
- package/dist/DatePickersLocalization-DAGwd4hM.d.mts +200 -0
- package/dist/DatePickersLocalization-DAGwd4hM.d.ts +200 -0
- package/dist/chunk-SIFVGHXY.mjs +108 -0
- package/dist/chunk-SIFVGHXY.mjs.map +1 -0
- package/dist/chunk-XMJPY2BR.js +120 -0
- package/dist/chunk-XMJPY2BR.js.map +1 -0
- package/dist/index.d.mts +588 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +951 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +893 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react-native.d.mts +654 -0
- package/dist/react-native.d.ts +654 -0
- package/dist/react-native.js +1761 -0
- package/dist/react-native.js.map +1 -0
- package/dist/react-native.mjs +1721 -0
- package/dist/react-native.mjs.map +1 -0
- package/dist/react.d.mts +531 -0
- package/dist/react.d.ts +531 -0
- package/dist/react.js +1885 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +1794 -0
- package/dist/react.mjs.map +1 -0
- package/dist/runtime.d.mts +3 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.js +37 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +4 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +140 -4
package/dist/react.js
ADDED
|
@@ -0,0 +1,1885 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var chunkXMJPY2BR_js = require('./chunk-XMJPY2BR.js');
|
|
5
|
+
var calendar = require('@quickbuilder.io/design-system/calendar');
|
|
6
|
+
var React2 = require('react');
|
|
7
|
+
var react = require('@quickbuilder.io/design-system/react');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
13
|
+
|
|
14
|
+
// src/framework-adapter.ts
|
|
15
|
+
var datePickersFrameworkAdapterSupport = Object.freeze([
|
|
16
|
+
{ framework: "react", entrypoint: "@quickbuilder.io/date-pickers/react", status: "implemented" },
|
|
17
|
+
{ framework: "vue", status: "unsupported" },
|
|
18
|
+
{ framework: "preact", status: "unsupported" },
|
|
19
|
+
{ framework: "qwik", status: "unsupported" },
|
|
20
|
+
{ framework: "astro", status: "unsupported" },
|
|
21
|
+
{ framework: "svelte", status: "unsupported" },
|
|
22
|
+
{ framework: "solid", status: "unsupported" },
|
|
23
|
+
{ framework: "web-components", status: "unsupported" },
|
|
24
|
+
{ framework: "react-native", status: "implemented", entrypoint: "@quickbuilder.io/date-pickers/react-native" }
|
|
25
|
+
]);
|
|
26
|
+
var frameworkAdapterSupport = datePickersFrameworkAdapterSupport;
|
|
27
|
+
|
|
28
|
+
// src/DatePickers.capabilities.ts
|
|
29
|
+
var datePickerCapabilityFeatures = [
|
|
30
|
+
{ id: "date-picker", label: "Date picker", category: "field", packageTier: "community", status: "implemented" },
|
|
31
|
+
{ id: "time-picker", label: "Time picker", category: "field", packageTier: "community", status: "implemented" },
|
|
32
|
+
{ id: "date-time-picker", label: "Date time picker", category: "field", packageTier: "community", status: "implemented" },
|
|
33
|
+
{ id: "date-calendar", label: "Date calendar", category: "view", packageTier: "community", status: "implemented" },
|
|
34
|
+
{ id: "controlled-state", label: "Controlled and uncontrolled values", category: "field", packageTier: "community", status: "implemented" },
|
|
35
|
+
{ id: "validation", label: "Date and time validation", category: "validation", packageTier: "community", status: "implemented" },
|
|
36
|
+
{ id: "localization", label: "Locale-aware formatting", category: "localization", packageTier: "community", status: "implemented" },
|
|
37
|
+
{ id: "localization-provider", label: "Localization provider", category: "localization", packageTier: "community", status: "implemented" },
|
|
38
|
+
{ id: "date-adapters", label: "Date adapter contract", category: "localization", packageTier: "community", status: "implemented" },
|
|
39
|
+
{ id: "date-adapter-bridges", label: "Day.js, date-fns, Luxon, and Moment adapter bridges", category: "localization", packageTier: "community", status: "implemented" },
|
|
40
|
+
{ id: "calendar-system-adapter-bridges", label: "Jalali, Hijri, and Buddhist adapter bridges", category: "localization", packageTier: "community", status: "implemented" },
|
|
41
|
+
{ id: "calendar-system-display-labels", label: "Calendar-system display labels", category: "localization", packageTier: "community", status: "implemented" },
|
|
42
|
+
{ id: "calendar-system-field-values", label: "Calendar-system field parsing and formatting", category: "localization", packageTier: "community", status: "implemented" },
|
|
43
|
+
{ id: "slots", label: "Slots and slot props", category: "customization", packageTier: "community", status: "implemented" },
|
|
44
|
+
{ id: "date-range-picker", label: "Date range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
45
|
+
{ id: "time-range-picker", label: "Time range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
46
|
+
{ id: "date-time-range-picker", label: "Date time range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
47
|
+
{ id: "range-shortcuts", label: "Range shortcuts", category: "customization", packageTier: "pro", status: "implemented" },
|
|
48
|
+
{ id: "timezone-values", label: "Timezone-aware rendering and value conversion", category: "localization", packageTier: "community", status: "implemented" },
|
|
49
|
+
{ id: "non-gregorian-calendar-grid", label: "Native non-Gregorian calendar grid rendering", category: "localization", packageTier: "community", status: "implemented" }
|
|
50
|
+
];
|
|
51
|
+
var datePickerCapabilityFeatureIds = datePickerCapabilityFeatures.map((feature) => feature.id);
|
|
52
|
+
|
|
53
|
+
// src/DatePickersTimezone.ts
|
|
54
|
+
function resolvePickerTimezone(timezone, providerTimezone) {
|
|
55
|
+
const requestedTimezone = timezone ?? providerTimezone;
|
|
56
|
+
if (requestedTimezone === void 0) return void 0;
|
|
57
|
+
if (requestedTimezone === "default") {
|
|
58
|
+
if (providerTimezone === void 0 || providerTimezone === "default") return void 0;
|
|
59
|
+
return resolvePickerTimezone(providerTimezone);
|
|
60
|
+
}
|
|
61
|
+
if (requestedTimezone === "system") {
|
|
62
|
+
return getSystemTimezone();
|
|
63
|
+
}
|
|
64
|
+
if (requestedTimezone === "UTC") {
|
|
65
|
+
return "UTC";
|
|
66
|
+
}
|
|
67
|
+
assertSupportedTimezone(requestedTimezone);
|
|
68
|
+
return requestedTimezone;
|
|
69
|
+
}
|
|
70
|
+
function toTimezoneDisplayDate(value, timezone) {
|
|
71
|
+
if (value === null) return null;
|
|
72
|
+
if (timezone === void 0) return cloneDate(value);
|
|
73
|
+
const parts = getTimezoneParts(value, timezone);
|
|
74
|
+
const display = /* @__PURE__ */ new Date(0);
|
|
75
|
+
display.setFullYear(parts.year, parts.month - 1, parts.day);
|
|
76
|
+
display.setHours(parts.hour, parts.minute, parts.second, value.getMilliseconds());
|
|
77
|
+
return display;
|
|
78
|
+
}
|
|
79
|
+
function fromTimezoneDisplayDate(value, timezone) {
|
|
80
|
+
if (value === null) return null;
|
|
81
|
+
if (timezone === void 0) return cloneDate(value);
|
|
82
|
+
const utcGuess = civilStamp(value);
|
|
83
|
+
const firstOffset = getTimezoneOffsetMs(new Date(utcGuess), timezone);
|
|
84
|
+
const firstCandidate = new Date(utcGuess - firstOffset);
|
|
85
|
+
const secondOffset = getTimezoneOffsetMs(firstCandidate, timezone);
|
|
86
|
+
return new Date(utcGuess - secondOffset);
|
|
87
|
+
}
|
|
88
|
+
function getSystemTimezone() {
|
|
89
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
90
|
+
if (!zone) throw new Error("The system timezone is unavailable.");
|
|
91
|
+
return zone;
|
|
92
|
+
}
|
|
93
|
+
function assertSupportedTimezone(timezone) {
|
|
94
|
+
getTimezoneFormatter(timezone);
|
|
95
|
+
}
|
|
96
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
97
|
+
function getTimezoneFormatter(timezone) {
|
|
98
|
+
if (typeof timezone !== "string") throw new TypeError("Unsupported timezone. Supply an IANA timezone name.");
|
|
99
|
+
const cached = formatters.get(timezone);
|
|
100
|
+
if (cached) return cached;
|
|
101
|
+
try {
|
|
102
|
+
const formatter = new Intl.DateTimeFormat("en-US-u-ca-gregory", {
|
|
103
|
+
day: "2-digit",
|
|
104
|
+
hour: "2-digit",
|
|
105
|
+
hourCycle: "h23",
|
|
106
|
+
minute: "2-digit",
|
|
107
|
+
month: "2-digit",
|
|
108
|
+
second: "2-digit",
|
|
109
|
+
timeZone: timezone,
|
|
110
|
+
year: "numeric"
|
|
111
|
+
});
|
|
112
|
+
if (formatters.size >= 32) formatters.delete(formatters.keys().next().value);
|
|
113
|
+
formatters.set(timezone, formatter);
|
|
114
|
+
return formatter;
|
|
115
|
+
} catch {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Unsupported date picker timezone "${timezone}". Use "UTC", "system", "default", or a valid IANA timezone.`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function cloneDate(value) {
|
|
122
|
+
return new Date(value.getTime());
|
|
123
|
+
}
|
|
124
|
+
function getZonedCivilTimestamp(value, timezone) {
|
|
125
|
+
if (!Number.isFinite(value.getTime())) throw new RangeError("A valid instant is required.");
|
|
126
|
+
if (timezone === "UTC") return value.getTime();
|
|
127
|
+
const parts = getTimezoneParts(value, timezone);
|
|
128
|
+
const stamp = /* @__PURE__ */ new Date(0);
|
|
129
|
+
stamp.setUTCFullYear(parts.year, parts.month - 1, parts.day);
|
|
130
|
+
stamp.setUTCHours(parts.hour, parts.minute, parts.second, value.getMilliseconds());
|
|
131
|
+
return stamp.getTime();
|
|
132
|
+
}
|
|
133
|
+
function getTimezoneOffsetMs(value, timezone) {
|
|
134
|
+
return getZonedCivilTimestamp(value, timezone) - value.getTime();
|
|
135
|
+
}
|
|
136
|
+
function getTimezoneParts(value, timezone) {
|
|
137
|
+
const parts = getTimezoneFormatter(timezone).formatToParts(value);
|
|
138
|
+
const resolvedParts = Object.fromEntries(
|
|
139
|
+
parts.map((part) => [part.type, part.value])
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
day: Number(resolvedParts.day),
|
|
143
|
+
hour: Number(resolvedParts.hour),
|
|
144
|
+
minute: Number(resolvedParts.minute),
|
|
145
|
+
month: Number(resolvedParts.month),
|
|
146
|
+
second: Number(resolvedParts.second),
|
|
147
|
+
year: Number(resolvedParts.year)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function civilStamp(date) {
|
|
151
|
+
const stamp = /* @__PURE__ */ new Date(0);
|
|
152
|
+
stamp.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
|
|
153
|
+
stamp.setUTCHours(
|
|
154
|
+
date.getHours(),
|
|
155
|
+
date.getMinutes(),
|
|
156
|
+
date.getSeconds(),
|
|
157
|
+
date.getMilliseconds()
|
|
158
|
+
);
|
|
159
|
+
return stamp.getTime();
|
|
160
|
+
}
|
|
161
|
+
function resolveDateTimeInstant(value, timezone, disambiguation) {
|
|
162
|
+
if (!Number.isFinite(value.getTime()))
|
|
163
|
+
throw new RangeError("Date-time resolution requires a valid date.");
|
|
164
|
+
if (timezone === void 0) {
|
|
165
|
+
assertDisambiguation(disambiguation);
|
|
166
|
+
return { date: new Date(value), error: null };
|
|
167
|
+
}
|
|
168
|
+
return resolveZonedCivilTimestamp(civilStamp(value), timezone, disambiguation);
|
|
169
|
+
}
|
|
170
|
+
function addZonedCalendarDays(value, days, timezone) {
|
|
171
|
+
if (!Number.isFinite(value.getTime()) || !Number.isSafeInteger(days))
|
|
172
|
+
throw new RangeError("Calendar-day addition requires a valid instant and an integer day count.");
|
|
173
|
+
assertSupportedTimezone(timezone);
|
|
174
|
+
if (days === 0) return { date: new Date(value), error: null };
|
|
175
|
+
const target = getZonedCivilTimestamp(value, timezone) + days * 864e5;
|
|
176
|
+
return resolveZonedCivilTimestamp(target, timezone, "reject");
|
|
177
|
+
}
|
|
178
|
+
function assertDisambiguation(disambiguation) {
|
|
179
|
+
if (!["earlier", "later", "reject"].includes(disambiguation))
|
|
180
|
+
throw new TypeError("Unsupported date-time disambiguation.");
|
|
181
|
+
}
|
|
182
|
+
function resolveZonedCivilTimestamp(target, timezone, disambiguation) {
|
|
183
|
+
if (!Number.isSafeInteger(target) || !Number.isFinite(new Date(target).getTime()))
|
|
184
|
+
throw new RangeError("A valid civil timestamp is required.");
|
|
185
|
+
assertDisambiguation(disambiguation);
|
|
186
|
+
if (timezone === "UTC") return { date: new Date(target), error: null };
|
|
187
|
+
const offsets = /* @__PURE__ */ new Set();
|
|
188
|
+
for (const hours of [-36, -12, 0, 12, 36]) {
|
|
189
|
+
const probe = new Date(target + hours * 36e5);
|
|
190
|
+
offsets.add(getTimezoneOffsetMs(probe, timezone));
|
|
191
|
+
}
|
|
192
|
+
const matches = [...offsets].filter((offset) => getTimezoneOffsetMs(new Date(target - offset), timezone) === offset).map((offset) => target - offset).sort((a, b) => a - b);
|
|
193
|
+
if (!matches.length) return { date: null, error: "nonexistentTime" };
|
|
194
|
+
if (matches.length > 1 && disambiguation === "reject")
|
|
195
|
+
return { date: null, error: "ambiguousTime" };
|
|
196
|
+
return {
|
|
197
|
+
date: new Date(
|
|
198
|
+
disambiguation === "later" ? matches[matches.length - 1] : matches[0]
|
|
199
|
+
),
|
|
200
|
+
error: null
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function resolveDatePickerLocale(requested) {
|
|
204
|
+
const supported = calendar.normalizeLocale(requested);
|
|
205
|
+
if (requested === supported) return supported;
|
|
206
|
+
const [canonical] = Intl.getCanonicalLocales(requested);
|
|
207
|
+
const locale = calendar.normalizeLocale(canonical);
|
|
208
|
+
if (locale !== canonical) throw new RangeError(`Unsupported date picker locale: ${requested}`);
|
|
209
|
+
return locale;
|
|
210
|
+
}
|
|
211
|
+
function cloneDate2(value) {
|
|
212
|
+
return new Date(value.getTime());
|
|
213
|
+
}
|
|
214
|
+
function isValidDate(value) {
|
|
215
|
+
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
216
|
+
}
|
|
217
|
+
function startOfDay(value) {
|
|
218
|
+
const date = cloneDate2(value);
|
|
219
|
+
date.setHours(0, 0, 0, 0);
|
|
220
|
+
return date;
|
|
221
|
+
}
|
|
222
|
+
function mergeDateAndTime(dateValue, timeValue) {
|
|
223
|
+
if (!dateValue && !timeValue) return null;
|
|
224
|
+
const nextValue = cloneDate2(dateValue ?? timeValue ?? /* @__PURE__ */ new Date());
|
|
225
|
+
if (timeValue) {
|
|
226
|
+
nextValue.setHours(timeValue.getHours(), timeValue.getMinutes(), 0, 0);
|
|
227
|
+
}
|
|
228
|
+
return nextValue;
|
|
229
|
+
}
|
|
230
|
+
function resolveDateValidationError({
|
|
231
|
+
disableFuture = false,
|
|
232
|
+
disablePast = false,
|
|
233
|
+
maxDate,
|
|
234
|
+
minDate,
|
|
235
|
+
shouldDisableDate,
|
|
236
|
+
today = /* @__PURE__ */ new Date(),
|
|
237
|
+
value
|
|
238
|
+
}) {
|
|
239
|
+
if (value === null) return null;
|
|
240
|
+
if (!isValidDate(value)) return "invalidDate";
|
|
241
|
+
const comparableValue = startOfDay(value).getTime();
|
|
242
|
+
const todayStamp = startOfDay(today).getTime();
|
|
243
|
+
if (disablePast && comparableValue < todayStamp) return "disablePast";
|
|
244
|
+
if (disableFuture && comparableValue > todayStamp) return "disableFuture";
|
|
245
|
+
if (minDate && comparableValue < startOfDay(minDate).getTime()) return "minDate";
|
|
246
|
+
if (maxDate && comparableValue > startOfDay(maxDate).getTime()) return "maxDate";
|
|
247
|
+
if (shouldDisableDate?.(value)) return "shouldDisableDate";
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
function resolveTimeValidationError({
|
|
251
|
+
disableFuture = false,
|
|
252
|
+
disablePast = false,
|
|
253
|
+
maxTime,
|
|
254
|
+
minTime,
|
|
255
|
+
shouldDisableTime,
|
|
256
|
+
now = /* @__PURE__ */ new Date(),
|
|
257
|
+
value
|
|
258
|
+
}) {
|
|
259
|
+
if (value === null) return null;
|
|
260
|
+
if (!isValidDate(value)) return "invalidTime";
|
|
261
|
+
if (disablePast && minutesFromDate(value) < minutesFromDate(now)) return "disablePast";
|
|
262
|
+
if (disableFuture && minutesFromDate(value) > minutesFromDate(now)) return "disableFuture";
|
|
263
|
+
if (minTime && minutesFromDate(value) < minutesFromDate(minTime)) return "minTime";
|
|
264
|
+
if (maxTime && minutesFromDate(value) > minutesFromDate(maxTime)) return "maxTime";
|
|
265
|
+
if (shouldDisableTime?.(value)) return "shouldDisableTime";
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
function shouldAllowDate({
|
|
269
|
+
disableFuture,
|
|
270
|
+
disablePast,
|
|
271
|
+
maxDate,
|
|
272
|
+
minDate,
|
|
273
|
+
shouldDisableDate
|
|
274
|
+
}) {
|
|
275
|
+
return (date) => resolveDateValidationError({
|
|
276
|
+
disableFuture,
|
|
277
|
+
disablePast,
|
|
278
|
+
maxDate,
|
|
279
|
+
minDate,
|
|
280
|
+
shouldDisableDate,
|
|
281
|
+
value: date
|
|
282
|
+
}) === null;
|
|
283
|
+
}
|
|
284
|
+
function shouldAllowTime({
|
|
285
|
+
disableFuture,
|
|
286
|
+
disablePast,
|
|
287
|
+
maxTime,
|
|
288
|
+
minTime,
|
|
289
|
+
shouldDisableTime
|
|
290
|
+
}) {
|
|
291
|
+
return (time) => resolveTimeValidationError({
|
|
292
|
+
disableFuture,
|
|
293
|
+
disablePast,
|
|
294
|
+
maxTime,
|
|
295
|
+
minTime,
|
|
296
|
+
shouldDisableTime,
|
|
297
|
+
value: time
|
|
298
|
+
}) === null;
|
|
299
|
+
}
|
|
300
|
+
function minutesFromDate(value) {
|
|
301
|
+
return value.getHours() * 60 + value.getMinutes();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/DatePickersAdapters.ts
|
|
305
|
+
var AdapterDateFns = class {
|
|
306
|
+
constructor(options = {}) {
|
|
307
|
+
this.options = options;
|
|
308
|
+
this.adapterName = "date-fns";
|
|
309
|
+
this.runtime = isDateFnsRuntime(options.dateLibInstance) ? options.dateLibInstance : void 0;
|
|
310
|
+
}
|
|
311
|
+
format(value, formatKey = "short") {
|
|
312
|
+
if (!this.isValid(value)) return "";
|
|
313
|
+
const format = resolveUnicodeDateFormat(formatKey);
|
|
314
|
+
return this.runtime?.format ? this.runtime.format(value, format) : formatNativeDate(value, this.options.locale, resolvePickerTimezone(this.options.timezone), formatKey);
|
|
315
|
+
}
|
|
316
|
+
fromJsDate(value) {
|
|
317
|
+
return new Date(value.getTime());
|
|
318
|
+
}
|
|
319
|
+
isEqual(left, right) {
|
|
320
|
+
if (left === null || right === null) return left === right;
|
|
321
|
+
return left.getTime() === right.getTime();
|
|
322
|
+
}
|
|
323
|
+
isValid(value) {
|
|
324
|
+
if (!(value instanceof Date)) return false;
|
|
325
|
+
return this.runtime?.isValid ? this.runtime.isValid(value) : !Number.isNaN(value.getTime());
|
|
326
|
+
}
|
|
327
|
+
parse(value, formatKey = "short") {
|
|
328
|
+
const parsed = this.runtime?.parse ? this.runtime.parse(value, resolveUnicodeDateFormat(formatKey), /* @__PURE__ */ new Date()) : new Date(value);
|
|
329
|
+
return this.isValid(parsed) ? parsed : null;
|
|
330
|
+
}
|
|
331
|
+
toJsDate(value) {
|
|
332
|
+
return new Date(value.getTime());
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var AdapterDayjs = class {
|
|
336
|
+
constructor(options = {}) {
|
|
337
|
+
this.options = options;
|
|
338
|
+
this.adapterName = "dayjs";
|
|
339
|
+
this.dayjs = requireDateLibInstance(options.dateLibInstance, "AdapterDayjs", "dayjs");
|
|
340
|
+
}
|
|
341
|
+
format(value, formatKey = "short") {
|
|
342
|
+
return this.isValid(value) ? value.format(resolveDayjsMomentFormat(formatKey)) : "";
|
|
343
|
+
}
|
|
344
|
+
fromJsDate(value) {
|
|
345
|
+
return this.dayjs(value);
|
|
346
|
+
}
|
|
347
|
+
isEqual(left, right) {
|
|
348
|
+
if (left === null || right === null) return left === right;
|
|
349
|
+
return getDateValueTime(left) === getDateValueTime(right);
|
|
350
|
+
}
|
|
351
|
+
isValid(value) {
|
|
352
|
+
return isDayjsLike(value) && value.isValid();
|
|
353
|
+
}
|
|
354
|
+
parse(value, formatKey = "short") {
|
|
355
|
+
const parsed = this.dayjs(value, resolveDayjsMomentFormat(formatKey));
|
|
356
|
+
return this.isValid(parsed) ? parsed : null;
|
|
357
|
+
}
|
|
358
|
+
toJsDate(value) {
|
|
359
|
+
return value.toDate();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
var AdapterLuxon = class {
|
|
363
|
+
constructor(options = {}) {
|
|
364
|
+
this.options = options;
|
|
365
|
+
this.adapterName = "luxon";
|
|
366
|
+
this.dateTime = requireDateLibInstance(options.dateLibInstance, "AdapterLuxon", "luxon DateTime");
|
|
367
|
+
}
|
|
368
|
+
format(value, formatKey = "short") {
|
|
369
|
+
return this.isValid(value) ? withLuxonContext(value, this.options).toFormat(resolveLuxonFormat(formatKey)) : "";
|
|
370
|
+
}
|
|
371
|
+
fromJsDate(value) {
|
|
372
|
+
return this.dateTime.fromJSDate(value, getLuxonOptions(this.options));
|
|
373
|
+
}
|
|
374
|
+
isEqual(left, right) {
|
|
375
|
+
if (left === null || right === null) return left === right;
|
|
376
|
+
return getDateValueTime(left) === getDateValueTime(right);
|
|
377
|
+
}
|
|
378
|
+
isValid(value) {
|
|
379
|
+
return isLuxonLike(value) && value.isValid;
|
|
380
|
+
}
|
|
381
|
+
parse(value, formatKey = "short") {
|
|
382
|
+
const format = resolveLuxonFormat(formatKey);
|
|
383
|
+
const parsed = this.dateTime.fromFormat ? this.dateTime.fromFormat(value, format, getLuxonOptions(this.options)) : this.dateTime.fromISO(value, getLuxonOptions(this.options));
|
|
384
|
+
return this.isValid(parsed) ? parsed : null;
|
|
385
|
+
}
|
|
386
|
+
toJsDate(value) {
|
|
387
|
+
return value.toJSDate();
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var AdapterMoment = class {
|
|
391
|
+
constructor(options = {}) {
|
|
392
|
+
this.options = options;
|
|
393
|
+
this.adapterName = "moment";
|
|
394
|
+
this.moment = requireDateLibInstance(options.dateLibInstance, "AdapterMoment", "moment");
|
|
395
|
+
}
|
|
396
|
+
format(value, formatKey = "short") {
|
|
397
|
+
return this.isValid(value) ? value.format(resolveDayjsMomentFormat(formatKey)) : "";
|
|
398
|
+
}
|
|
399
|
+
fromJsDate(value) {
|
|
400
|
+
return this.moment(value);
|
|
401
|
+
}
|
|
402
|
+
isEqual(left, right) {
|
|
403
|
+
if (left === null || right === null) return left === right;
|
|
404
|
+
return getDateValueTime(left) === getDateValueTime(right);
|
|
405
|
+
}
|
|
406
|
+
isValid(value) {
|
|
407
|
+
return isMomentLike(value) && value.isValid();
|
|
408
|
+
}
|
|
409
|
+
parse(value, formatKey = "short") {
|
|
410
|
+
const parsed = this.moment(value, resolveDayjsMomentFormat(formatKey));
|
|
411
|
+
return this.isValid(parsed) ? parsed : null;
|
|
412
|
+
}
|
|
413
|
+
toJsDate(value) {
|
|
414
|
+
return value.toDate();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
function requireDateLibInstance(dateLibInstance, adapterName, libraryName) {
|
|
418
|
+
if (!dateLibInstance) {
|
|
419
|
+
throw new Error(`${adapterName} requires ${libraryName} to be passed through DatePickersLocalizationProvider dateLibInstance.`);
|
|
420
|
+
}
|
|
421
|
+
return dateLibInstance;
|
|
422
|
+
}
|
|
423
|
+
function isDateFnsRuntime(value) {
|
|
424
|
+
return typeof value === "object" && value !== null;
|
|
425
|
+
}
|
|
426
|
+
function isDayjsLike(value) {
|
|
427
|
+
return typeof value === "object" && value !== null && typeof value.format === "function" && typeof value.isValid === "function" && typeof value.toDate === "function";
|
|
428
|
+
}
|
|
429
|
+
function isMomentLike(value) {
|
|
430
|
+
return isDayjsLike(value);
|
|
431
|
+
}
|
|
432
|
+
function isLuxonLike(value) {
|
|
433
|
+
return typeof value === "object" && value !== null && typeof value.isValid === "boolean" && typeof value.toFormat === "function" && typeof value.toJSDate === "function";
|
|
434
|
+
}
|
|
435
|
+
function getDateValueTime(value) {
|
|
436
|
+
if (value.toMillis) return value.toMillis();
|
|
437
|
+
const primitiveValue = typeof value.valueOf === "function" ? value.valueOf() : void 0;
|
|
438
|
+
if (typeof primitiveValue === "number") return primitiveValue;
|
|
439
|
+
if (value.toDate) return value.toDate().getTime();
|
|
440
|
+
if (value.toJSDate) return value.toJSDate().getTime();
|
|
441
|
+
return Number.NaN;
|
|
442
|
+
}
|
|
443
|
+
function resolveDayjsMomentFormat(formatKey) {
|
|
444
|
+
if (formatKey === "short") return "L";
|
|
445
|
+
if (formatKey === "medium") return "ll";
|
|
446
|
+
if (formatKey === "long") return "LL";
|
|
447
|
+
return formatKey;
|
|
448
|
+
}
|
|
449
|
+
function resolveLuxonFormat(formatKey) {
|
|
450
|
+
if (formatKey === "short") return "D";
|
|
451
|
+
if (formatKey === "medium") return "DD";
|
|
452
|
+
if (formatKey === "long") return "DDD";
|
|
453
|
+
return formatKey;
|
|
454
|
+
}
|
|
455
|
+
function resolveUnicodeDateFormat(formatKey) {
|
|
456
|
+
if (formatKey === "short") return "P";
|
|
457
|
+
if (formatKey === "medium") return "PP";
|
|
458
|
+
if (formatKey === "long") return "PPP";
|
|
459
|
+
return formatKey;
|
|
460
|
+
}
|
|
461
|
+
function formatNativeDate(value, locale, timezone, formatKey) {
|
|
462
|
+
const dateStyle = formatKey === "long" ? "long" : formatKey === "medium" ? "medium" : "short";
|
|
463
|
+
return new Intl.DateTimeFormat(locale ?? "en", {
|
|
464
|
+
dateStyle,
|
|
465
|
+
timeZone: timezone
|
|
466
|
+
}).format(value);
|
|
467
|
+
}
|
|
468
|
+
function getLuxonOptions(options) {
|
|
469
|
+
return {
|
|
470
|
+
...options.locale ? { locale: options.locale } : {},
|
|
471
|
+
...resolvePickerTimezone(options.timezone) ? { zone: resolvePickerTimezone(options.timezone) } : {}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function withLuxonContext(value, options) {
|
|
475
|
+
let nextValue = value;
|
|
476
|
+
if (options.locale && nextValue.setLocale) {
|
|
477
|
+
nextValue = nextValue.setLocale(options.locale);
|
|
478
|
+
}
|
|
479
|
+
const resolvedTimezone = resolvePickerTimezone(options.timezone);
|
|
480
|
+
if (resolvedTimezone && nextValue.setZone) {
|
|
481
|
+
nextValue = nextValue.setZone(resolvedTimezone);
|
|
482
|
+
}
|
|
483
|
+
return nextValue;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/DatePickersCalendarSystems.ts
|
|
487
|
+
var datePickerCalendarSystemAdapters = [
|
|
488
|
+
{
|
|
489
|
+
adapterName: "date-fns-jalali",
|
|
490
|
+
calendarSystem: "jalali",
|
|
491
|
+
fieldEditing: "supported",
|
|
492
|
+
runtimePackage: "date-fns-jalali"
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
adapterName: "moment-jalaali",
|
|
496
|
+
calendarSystem: "jalali",
|
|
497
|
+
fieldEditing: "supported",
|
|
498
|
+
runtimePackage: "moment-jalaali"
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
adapterName: "moment-hijri",
|
|
502
|
+
calendarSystem: "hijri",
|
|
503
|
+
fieldEditing: "view-only-recommended",
|
|
504
|
+
runtimePackage: "moment-hijri"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
adapterName: "dayjs-buddhist",
|
|
508
|
+
calendarSystem: "buddhist",
|
|
509
|
+
fieldEditing: "supported",
|
|
510
|
+
runtimePackage: "dayjs"
|
|
511
|
+
}
|
|
512
|
+
];
|
|
513
|
+
var AdapterDateFnsJalali = class extends AdapterDateFns {
|
|
514
|
+
constructor(options = {}) {
|
|
515
|
+
requireCalendarRuntime(options.dateLibInstance, "AdapterDateFnsJalali", "date-fns-jalali");
|
|
516
|
+
super(options);
|
|
517
|
+
this.adapterName = "date-fns-jalali";
|
|
518
|
+
this.calendarSystem = "jalali";
|
|
519
|
+
this.fieldEditing = "supported";
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
var AdapterMomentJalaali = class extends AdapterMoment {
|
|
523
|
+
constructor(options = {}) {
|
|
524
|
+
super({
|
|
525
|
+
...options,
|
|
526
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterMomentJalaali", "moment-jalaali")
|
|
527
|
+
});
|
|
528
|
+
this.adapterName = "moment-jalaali";
|
|
529
|
+
this.calendarSystem = "jalali";
|
|
530
|
+
this.fieldEditing = "supported";
|
|
531
|
+
}
|
|
532
|
+
format(value, formatKey = "short") {
|
|
533
|
+
return this.isValid(value) ? value.format(resolveMomentJalaaliFormat(formatKey)) : "";
|
|
534
|
+
}
|
|
535
|
+
parse(value, formatKey = "short") {
|
|
536
|
+
const parsed = this.createMomentValue(value, resolveMomentJalaaliFormat(formatKey));
|
|
537
|
+
return this.isValid(parsed) ? parsed : null;
|
|
538
|
+
}
|
|
539
|
+
createMomentValue(value, format) {
|
|
540
|
+
const factory = requireCalendarRuntime(
|
|
541
|
+
this.moment,
|
|
542
|
+
"AdapterMomentJalaali",
|
|
543
|
+
"moment-jalaali"
|
|
544
|
+
);
|
|
545
|
+
return factory(value, format);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
var AdapterMomentHijri = class extends AdapterMoment {
|
|
549
|
+
constructor(options = {}) {
|
|
550
|
+
super({
|
|
551
|
+
...options,
|
|
552
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterMomentHijri", "moment-hijri")
|
|
553
|
+
});
|
|
554
|
+
this.adapterName = "moment-hijri";
|
|
555
|
+
this.calendarSystem = "hijri";
|
|
556
|
+
this.fieldEditing = "view-only-recommended";
|
|
557
|
+
}
|
|
558
|
+
format(value, formatKey = "short") {
|
|
559
|
+
return this.isValid(value) ? value.format(resolveMomentHijriFormat(formatKey)) : "";
|
|
560
|
+
}
|
|
561
|
+
parse(value, formatKey = "short") {
|
|
562
|
+
const parsed = this.createMomentValue(value, resolveMomentHijriFormat(formatKey));
|
|
563
|
+
return this.isValid(parsed) ? parsed : null;
|
|
564
|
+
}
|
|
565
|
+
createMomentValue(value, format) {
|
|
566
|
+
const factory = requireCalendarRuntime(
|
|
567
|
+
this.moment,
|
|
568
|
+
"AdapterMomentHijri",
|
|
569
|
+
"moment-hijri"
|
|
570
|
+
);
|
|
571
|
+
return factory(value, format);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
var AdapterDayjsBuddhist = class extends AdapterDayjs {
|
|
575
|
+
constructor(options = {}) {
|
|
576
|
+
super({
|
|
577
|
+
...options,
|
|
578
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterDayjsBuddhist", "dayjs with buddhistEra plugin")
|
|
579
|
+
});
|
|
580
|
+
this.adapterName = "dayjs-buddhist";
|
|
581
|
+
this.calendarSystem = "buddhist";
|
|
582
|
+
this.fieldEditing = "supported";
|
|
583
|
+
}
|
|
584
|
+
format(value, formatKey = "short") {
|
|
585
|
+
return this.isValid(value) ? value.format(resolveDayjsBuddhistFormat(formatKey)) : "";
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
function isCalendarSystemAdapter(adapter) {
|
|
589
|
+
return typeof adapter.calendarSystem === "string";
|
|
590
|
+
}
|
|
591
|
+
function getDatePickerCalendarSystem(adapter) {
|
|
592
|
+
return isCalendarSystemAdapter(adapter) ? adapter.calendarSystem : "gregory";
|
|
593
|
+
}
|
|
594
|
+
function supportsDatePickerCalendarSystem(calendarSystem) {
|
|
595
|
+
return datePickerCalendarSystemAdapters.some((adapter) => adapter.calendarSystem === calendarSystem) || calendarSystem === "gregory";
|
|
596
|
+
}
|
|
597
|
+
function requireCalendarRuntime(dateLibInstance, adapterName, packageName) {
|
|
598
|
+
if (!dateLibInstance) {
|
|
599
|
+
throw new Error(`${adapterName} requires ${packageName} to be passed through DatePickersLocalizationProvider dateLibInstance.`);
|
|
600
|
+
}
|
|
601
|
+
return dateLibInstance;
|
|
602
|
+
}
|
|
603
|
+
function resolveMomentJalaaliFormat(formatKey) {
|
|
604
|
+
if (formatKey === "short") return "jYYYY/jMM/jDD";
|
|
605
|
+
if (formatKey === "medium") return "jD jMMM jYYYY";
|
|
606
|
+
if (formatKey === "long") return "jD jMMMM jYYYY";
|
|
607
|
+
return formatKey;
|
|
608
|
+
}
|
|
609
|
+
function resolveMomentHijriFormat(formatKey) {
|
|
610
|
+
if (formatKey === "short") return "iYYYY/iMM/iDD";
|
|
611
|
+
if (formatKey === "medium") return "iD iMMM iYYYY";
|
|
612
|
+
if (formatKey === "long") return "iD iMMMM iYYYY";
|
|
613
|
+
return formatKey;
|
|
614
|
+
}
|
|
615
|
+
function resolveDayjsBuddhistFormat(formatKey) {
|
|
616
|
+
if (formatKey === "short") return "BBBB/MM/DD";
|
|
617
|
+
if (formatKey === "medium") return "D MMM BBBB";
|
|
618
|
+
if (formatKey === "long") return "D MMMM BBBB";
|
|
619
|
+
return formatKey;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/DatePickersFormatting.ts
|
|
623
|
+
var RELATIVE_THRESHOLDS = Object.freeze([
|
|
624
|
+
{ limit: 60, milliseconds: 1e3, unit: "second" },
|
|
625
|
+
{ limit: 60, milliseconds: 6e4, unit: "minute" },
|
|
626
|
+
{ limit: 24, milliseconds: 36e5, unit: "hour" },
|
|
627
|
+
{ limit: 7, milliseconds: 864e5, unit: "day" },
|
|
628
|
+
{ limit: 5, milliseconds: 6048e5, unit: "week" },
|
|
629
|
+
{ limit: 12, milliseconds: 2629746e3, unit: "month" },
|
|
630
|
+
{
|
|
631
|
+
limit: Number.POSITIVE_INFINITY,
|
|
632
|
+
milliseconds: 31556952e3,
|
|
633
|
+
unit: "year"
|
|
634
|
+
}
|
|
635
|
+
]);
|
|
636
|
+
function toDatePickerDate(value) {
|
|
637
|
+
const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);
|
|
638
|
+
if (Number.isNaN(date.getTime())) {
|
|
639
|
+
throw new RangeError(`Invalid date value "${String(value)}".`);
|
|
640
|
+
}
|
|
641
|
+
return date;
|
|
642
|
+
}
|
|
643
|
+
function formatDateTime(value, { locale = "en-US", ...options } = {}) {
|
|
644
|
+
return new Intl.DateTimeFormat(
|
|
645
|
+
locale,
|
|
646
|
+
Object.keys(options).length > 0 ? options : { dateStyle: "medium" }
|
|
647
|
+
).format(toDatePickerDate(value));
|
|
648
|
+
}
|
|
649
|
+
function formatDatePattern(value, pattern, locale = "en-US") {
|
|
650
|
+
const date = toDatePickerDate(value);
|
|
651
|
+
if (pattern === "yyyy-MM-dd") {
|
|
652
|
+
return [
|
|
653
|
+
String(date.getFullYear()).padStart(4, "0"),
|
|
654
|
+
String(date.getMonth() + 1).padStart(2, "0"),
|
|
655
|
+
String(date.getDate()).padStart(2, "0")
|
|
656
|
+
].join("-");
|
|
657
|
+
}
|
|
658
|
+
const optionsByPattern = {
|
|
659
|
+
PPpp: { dateStyle: "medium", timeStyle: "short" },
|
|
660
|
+
EEE: { weekday: "short" },
|
|
661
|
+
"EEEE, MMMM d, yyyy": {
|
|
662
|
+
day: "numeric",
|
|
663
|
+
month: "long",
|
|
664
|
+
weekday: "long",
|
|
665
|
+
year: "numeric"
|
|
666
|
+
},
|
|
667
|
+
"MMM d": { day: "numeric", month: "short" },
|
|
668
|
+
"MMM d, h:mm a": {
|
|
669
|
+
day: "numeric",
|
|
670
|
+
hour: "numeric",
|
|
671
|
+
hour12: true,
|
|
672
|
+
minute: "2-digit",
|
|
673
|
+
month: "short"
|
|
674
|
+
},
|
|
675
|
+
"MMM d, yyyy": { day: "numeric", month: "short", year: "numeric" },
|
|
676
|
+
"MMMM d, yyyy": { day: "numeric", month: "long", year: "numeric" },
|
|
677
|
+
"MMMM yyyy": { month: "long", year: "numeric" },
|
|
678
|
+
d: { day: "numeric" },
|
|
679
|
+
"h a": { hour: "numeric", hour12: true },
|
|
680
|
+
"h:mm a": { hour: "numeric", hour12: true, minute: "2-digit" }
|
|
681
|
+
};
|
|
682
|
+
const options = optionsByPattern[pattern];
|
|
683
|
+
if (!options) {
|
|
684
|
+
throw new RangeError(
|
|
685
|
+
`Unsupported Quick Builder date pattern "${pattern}".`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
689
|
+
}
|
|
690
|
+
function formatRelativeTime(value, {
|
|
691
|
+
addSuffix = true,
|
|
692
|
+
locale = "en-US",
|
|
693
|
+
now = Date.now(),
|
|
694
|
+
numeric = "always"
|
|
695
|
+
} = {}) {
|
|
696
|
+
const difference = toDatePickerDate(value).getTime() - toDatePickerDate(now).getTime();
|
|
697
|
+
const absoluteDifference = Math.abs(difference);
|
|
698
|
+
const selected = RELATIVE_THRESHOLDS.find(
|
|
699
|
+
({ limit, milliseconds }) => absoluteDifference < limit * milliseconds
|
|
700
|
+
) ?? RELATIVE_THRESHOLDS[RELATIVE_THRESHOLDS.length - 1];
|
|
701
|
+
const rawValue = difference / selected.milliseconds;
|
|
702
|
+
const roundedValue = rawValue < 0 ? Math.ceil(rawValue) : Math.floor(rawValue);
|
|
703
|
+
const displayValue = roundedValue === 0 && difference !== 0 ? difference < 0 ? -1 : 1 : roundedValue;
|
|
704
|
+
if (addSuffix) {
|
|
705
|
+
return new Intl.RelativeTimeFormat(locale, {
|
|
706
|
+
numeric,
|
|
707
|
+
style: "long"
|
|
708
|
+
}).format(displayValue, selected.unit);
|
|
709
|
+
}
|
|
710
|
+
return new Intl.NumberFormat(locale, {
|
|
711
|
+
style: "unit",
|
|
712
|
+
unit: selected.unit,
|
|
713
|
+
unitDisplay: "long"
|
|
714
|
+
}).format(Math.abs(displayValue));
|
|
715
|
+
}
|
|
716
|
+
function parseIsoDate(value) {
|
|
717
|
+
return toDatePickerDate(value);
|
|
718
|
+
}
|
|
719
|
+
function addCalendarDays(value, amount) {
|
|
720
|
+
const date = toDatePickerDate(value);
|
|
721
|
+
date.setDate(date.getDate() + amount);
|
|
722
|
+
return date;
|
|
723
|
+
}
|
|
724
|
+
function subtractCalendarDays(value, amount) {
|
|
725
|
+
return addCalendarDays(value, -amount);
|
|
726
|
+
}
|
|
727
|
+
function isSameCalendarDay(left, right) {
|
|
728
|
+
const leftDate = toDatePickerDate(left);
|
|
729
|
+
const rightDate = toDatePickerDate(right);
|
|
730
|
+
return leftDate.getFullYear() === rightDate.getFullYear() && leftDate.getMonth() === rightDate.getMonth() && leftDate.getDate() === rightDate.getDate();
|
|
731
|
+
}
|
|
732
|
+
function isDateToday(value, now = Date.now()) {
|
|
733
|
+
return isSameCalendarDay(value, now);
|
|
734
|
+
}
|
|
735
|
+
function isDateYesterday(value, now = Date.now()) {
|
|
736
|
+
return isSameCalendarDay(value, addCalendarDays(now, -1));
|
|
737
|
+
}
|
|
738
|
+
function isDateThisWeek(value, {
|
|
739
|
+
now = Date.now(),
|
|
740
|
+
weekStartsOn = 0
|
|
741
|
+
} = {}) {
|
|
742
|
+
if (!Number.isInteger(weekStartsOn) || weekStartsOn < 0 || weekStartsOn > 6) {
|
|
743
|
+
throw new RangeError("weekStartsOn must be an integer from 0 through 6.");
|
|
744
|
+
}
|
|
745
|
+
const reference = toDatePickerDate(now);
|
|
746
|
+
const start = new Date(
|
|
747
|
+
reference.getFullYear(),
|
|
748
|
+
reference.getMonth(),
|
|
749
|
+
reference.getDate()
|
|
750
|
+
);
|
|
751
|
+
start.setDate(start.getDate() - (start.getDay() - weekStartsOn + 7) % 7);
|
|
752
|
+
const end = addCalendarDays(start, 7);
|
|
753
|
+
const candidate = toDatePickerDate(value).getTime();
|
|
754
|
+
return candidate >= start.getTime() && candidate < end.getTime();
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/DatePickers.storage.ts
|
|
758
|
+
function assertDate(value, basis = "local") {
|
|
759
|
+
if (!(value instanceof Date) || !Number.isFinite(value.getTime()))
|
|
760
|
+
throw new TypeError("Invalid picker date");
|
|
761
|
+
const year = basis === "utc" ? value.getUTCFullYear() : value.getFullYear();
|
|
762
|
+
if (year < 1 || year > 9999) throw new TypeError("Invalid picker date");
|
|
763
|
+
}
|
|
764
|
+
var pad = (value, width = 2) => String(value).padStart(width, "0");
|
|
765
|
+
function serializePickerDate(value) {
|
|
766
|
+
assertDate(value);
|
|
767
|
+
return {
|
|
768
|
+
version: 1,
|
|
769
|
+
kind: "date",
|
|
770
|
+
date: `${pad(value.getFullYear(), 4)}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function serializePickerTime(value) {
|
|
774
|
+
assertDate(value);
|
|
775
|
+
if (value.getSeconds() || value.getMilliseconds())
|
|
776
|
+
throw new Error("Time picker storage requires minute precision");
|
|
777
|
+
return {
|
|
778
|
+
version: 1,
|
|
779
|
+
kind: "time",
|
|
780
|
+
time: `${pad(value.getHours())}:${pad(value.getMinutes())}`
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
function serializePickerDateTime(value, timezone) {
|
|
784
|
+
assertDate(value, "utc");
|
|
785
|
+
if (!timezone || timezone === "system" || timezone === "default")
|
|
786
|
+
throw new Error("Persist an explicit display timezone");
|
|
787
|
+
assertSupportedTimezone(timezone);
|
|
788
|
+
return {
|
|
789
|
+
version: 1,
|
|
790
|
+
kind: "dateTime",
|
|
791
|
+
instant: value.toISOString(),
|
|
792
|
+
timezone
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function parseStoredPickerValue(input) {
|
|
796
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
797
|
+
throw new TypeError("Expected picker storage schema version 1");
|
|
798
|
+
const value = Object.getOwnPropertyDescriptors(input);
|
|
799
|
+
if (Object.values(value).some((property) => !("value" in property)))
|
|
800
|
+
throw new TypeError("Picker storage must contain JSON values");
|
|
801
|
+
const record = Object.fromEntries(
|
|
802
|
+
Object.entries(value).map(([key, descriptor]) => [key, descriptor.value])
|
|
803
|
+
);
|
|
804
|
+
const fields = record.kind === "date" ? ["version", "kind", "date"] : record.kind === "time" ? ["version", "kind", "time"] : ["version", "kind", "instant", "timezone"];
|
|
805
|
+
if (record.version !== 1 || Object.keys(record).length !== fields.length || Object.keys(record).some((key) => !fields.includes(key)))
|
|
806
|
+
throw new TypeError("Invalid picker storage fields");
|
|
807
|
+
if (record.kind === "date" && typeof record.date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(record.date)) {
|
|
808
|
+
const [year, month, day] = record.date.split("-").map(Number);
|
|
809
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
810
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
811
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
812
|
+
if (year >= 1 && date.toISOString().slice(0, 10) === record.date)
|
|
813
|
+
return { version: 1, kind: "date", date: record.date };
|
|
814
|
+
}
|
|
815
|
+
if (record.kind === "time" && typeof record.time === "string" && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(record.time))
|
|
816
|
+
return { version: 1, kind: "time", time: record.time };
|
|
817
|
+
if (record.kind === "dateTime" && typeof record.instant === "string" && typeof record.timezone === "string") {
|
|
818
|
+
const date = new Date(record.instant);
|
|
819
|
+
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(record.instant) && Number.isFinite(date.getTime()) && date.toISOString() === record.instant)
|
|
820
|
+
return serializePickerDateTime(date, record.timezone);
|
|
821
|
+
}
|
|
822
|
+
throw new TypeError("Invalid stored picker value");
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/core.ts
|
|
826
|
+
var datePickersPackageManifest = {
|
|
827
|
+
packageName: "@quickbuilder.io/date-pickers",
|
|
828
|
+
displayName: "Quick Builder Date Pickers",
|
|
829
|
+
family: "date-pickers",
|
|
830
|
+
tier: "community",
|
|
831
|
+
designSystemDependency: "@quickbuilder.io/design-system",
|
|
832
|
+
status: "implemented"
|
|
833
|
+
};
|
|
834
|
+
var packageManifest = datePickersPackageManifest;
|
|
835
|
+
function usePickerField(value, defaultValue, props) {
|
|
836
|
+
const localization = chunkXMJPY2BR_js.useDatePickersLocalization();
|
|
837
|
+
const locale = resolveDatePickerLocale(props.locale ?? localization.adapterLocale);
|
|
838
|
+
const timezone = resolvePickerTimezone(props.timezone, localization.timezone);
|
|
839
|
+
const [internalValue, setInternalValue] = React2__default.default.useState(defaultValue ?? null);
|
|
840
|
+
const accepted = value === void 0 ? internalValue : value;
|
|
841
|
+
const display = (candidate, name) => candidate == null ? null : toTimezoneDisplayDate(chunkXMJPY2BR_js.toPickerDate(localization.adapter, candidate, name), timezone);
|
|
842
|
+
const ref = React2__default.default.useRef(null);
|
|
843
|
+
const inputRef = React2__default.default.useCallback(
|
|
844
|
+
(node) => {
|
|
845
|
+
ref.current = node;
|
|
846
|
+
if (typeof props.inputRef === "function") {
|
|
847
|
+
const cleanup = props.inputRef(node);
|
|
848
|
+
if (cleanup)
|
|
849
|
+
return () => {
|
|
850
|
+
ref.current = null;
|
|
851
|
+
cleanup();
|
|
852
|
+
};
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
if (props.inputRef) props.inputRef.current = node;
|
|
856
|
+
},
|
|
857
|
+
[props.inputRef]
|
|
858
|
+
);
|
|
859
|
+
React2__default.default.useEffect(() => {
|
|
860
|
+
const form = ref.current?.form;
|
|
861
|
+
if (!form || value !== void 0) return;
|
|
862
|
+
const reset = (event) => queueMicrotask(() => {
|
|
863
|
+
if (!event.defaultPrevented && ref.current?.form === form)
|
|
864
|
+
setInternalValue(defaultValue ?? null);
|
|
865
|
+
});
|
|
866
|
+
form.addEventListener("reset", reset);
|
|
867
|
+
return () => form.removeEventListener("reset", reset);
|
|
868
|
+
}, [defaultValue, props.form, value]);
|
|
869
|
+
return {
|
|
870
|
+
...localization,
|
|
871
|
+
locale,
|
|
872
|
+
timezone,
|
|
873
|
+
accepted,
|
|
874
|
+
display,
|
|
875
|
+
inputRef,
|
|
876
|
+
setAccepted: (next) => {
|
|
877
|
+
if (value === void 0) setInternalValue(next);
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
var escapePattern = (text) => text.replace(/[.*+?^$()|[\]{}\\]/g, "\\$&");
|
|
882
|
+
var stripDirection = (text) => text.normalize("NFKC").replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, "").trim();
|
|
883
|
+
function createDateTimeCodec(locale, calendarSystem, hour12) {
|
|
884
|
+
const dateFormat = new Intl.DateTimeFormat(
|
|
885
|
+
calendar.getCalendarSystemLocale(locale, calendarSystem),
|
|
886
|
+
{ year: "numeric", month: "2-digit", day: "2-digit" }
|
|
887
|
+
);
|
|
888
|
+
const timeFormat = new Intl.DateTimeFormat(locale, {
|
|
889
|
+
hour: "2-digit",
|
|
890
|
+
minute: "2-digit",
|
|
891
|
+
...hour12 === void 0 ? {} : hour12 ? { hour12: true } : { hourCycle: "h23" }
|
|
892
|
+
});
|
|
893
|
+
const digits = new Intl.NumberFormat(locale, { useGrouping: false });
|
|
894
|
+
const normalize = (text) => {
|
|
895
|
+
let value = stripDirection(text).toLocaleLowerCase(locale);
|
|
896
|
+
for (let digit = 0; digit < 10; digit++)
|
|
897
|
+
value = value.split(digits.format(digit)).join(String(digit));
|
|
898
|
+
return value;
|
|
899
|
+
};
|
|
900
|
+
const periods = [0, 13].map(
|
|
901
|
+
(hour) => timeFormat.formatToParts(new Date(2026, 0, 1, hour)).find((part) => part.type === "dayPeriod")?.value ?? ""
|
|
902
|
+
);
|
|
903
|
+
const fields = [];
|
|
904
|
+
const pattern = timeFormat.formatToParts(new Date(2026, 0, 1, 13, 45)).map((part) => {
|
|
905
|
+
if (part.type === "hour" || part.type === "minute") {
|
|
906
|
+
fields.push(part.type);
|
|
907
|
+
return "(\\d{1,2})";
|
|
908
|
+
}
|
|
909
|
+
if (part.type === "dayPeriod") {
|
|
910
|
+
fields.push(part.type);
|
|
911
|
+
return "(" + periods.map((value) => escapePattern(normalize(value))).join("|") + ")";
|
|
912
|
+
}
|
|
913
|
+
if (/^\s+$/.test(part.value)) return "\\s*";
|
|
914
|
+
return escapePattern(normalize(part.value)).replace(/\s+/g, "\\s*");
|
|
915
|
+
}).join("");
|
|
916
|
+
const expression = new RegExp("^(.+?)[,\u060C]?\\s+" + pattern + "$", "u");
|
|
917
|
+
return {
|
|
918
|
+
format: (date) => date ? dateFormat.format(date) + ", " + timeFormat.format(date) : "",
|
|
919
|
+
formatTime: (date) => timeFormat.format(date),
|
|
920
|
+
parse: (text) => {
|
|
921
|
+
const match = normalize(text).match(expression);
|
|
922
|
+
if (!match) return null;
|
|
923
|
+
const date = calendar.parseDateInputForCalendarSystem(
|
|
924
|
+
match[1].replace(/[,،]$/, ""),
|
|
925
|
+
locale,
|
|
926
|
+
calendarSystem,
|
|
927
|
+
true
|
|
928
|
+
);
|
|
929
|
+
if (!date) return null;
|
|
930
|
+
const values = Object.fromEntries(
|
|
931
|
+
fields.map((field, index) => [field, match[index + 2]])
|
|
932
|
+
);
|
|
933
|
+
let hour = Number(values.hour);
|
|
934
|
+
const minute = Number(values.minute);
|
|
935
|
+
if (minute > 59 || hour > 23) return null;
|
|
936
|
+
if (values.dayPeriod) {
|
|
937
|
+
if (hour < 1 || hour > 12) return null;
|
|
938
|
+
hour = hour % 12 + (values.dayPeriod === normalize(periods[1]) ? 12 : 0);
|
|
939
|
+
}
|
|
940
|
+
date.setHours(hour, minute, 0, 0);
|
|
941
|
+
return date.getHours() === hour && date.getMinutes() === minute ? date : null;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function assertOrderedPickerBounds(min, max, compareValue, name) {
|
|
946
|
+
if (min !== void 0 && !isValidDate(min) || max !== void 0 && !isValidDate(max))
|
|
947
|
+
throw new RangeError(`${name} must be valid dates.`);
|
|
948
|
+
if (min && max && compareValue(min) > compareValue(max))
|
|
949
|
+
throw new RangeError(`${name} must be ordered.`);
|
|
950
|
+
}
|
|
951
|
+
function assertDateBounds(minDate, maxDate) {
|
|
952
|
+
assertOrderedPickerBounds(
|
|
953
|
+
minDate,
|
|
954
|
+
maxDate,
|
|
955
|
+
(date) => startOfDay(date).getTime(),
|
|
956
|
+
"minDate/maxDate"
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
function assertDateTimeBounds(constraints) {
|
|
960
|
+
assertOrderedPickerBounds(
|
|
961
|
+
constraints.minDateTime,
|
|
962
|
+
constraints.maxDateTime,
|
|
963
|
+
(date) => date.getTime(),
|
|
964
|
+
"minDateTime/maxDateTime"
|
|
965
|
+
);
|
|
966
|
+
assertDateBounds(constraints.minDate, constraints.maxDate);
|
|
967
|
+
assertOrderedPickerBounds(
|
|
968
|
+
constraints.minTime,
|
|
969
|
+
constraints.maxTime,
|
|
970
|
+
minutesFromDate,
|
|
971
|
+
"minTime/maxTime"
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
function validateDateTime(display, instant, constraints) {
|
|
975
|
+
if (!display || !instant) return constraints.required ? "required" : null;
|
|
976
|
+
const dateError = resolveDateValidationError({
|
|
977
|
+
value: display,
|
|
978
|
+
minDate: constraints.minDate,
|
|
979
|
+
maxDate: constraints.maxDate,
|
|
980
|
+
shouldDisableDate: constraints.shouldDisableDate
|
|
981
|
+
});
|
|
982
|
+
if (dateError) return dateError;
|
|
983
|
+
if (constraints.minDateTime && instant < constraints.minDateTime)
|
|
984
|
+
return "minDateTime";
|
|
985
|
+
if (constraints.maxDateTime && instant > constraints.maxDateTime)
|
|
986
|
+
return "maxDateTime";
|
|
987
|
+
if (constraints.disablePast && instant.getTime() < Date.now())
|
|
988
|
+
return "disablePast";
|
|
989
|
+
if (constraints.disableFuture && instant.getTime() > Date.now())
|
|
990
|
+
return "disableFuture";
|
|
991
|
+
if (display.getMinutes() % constraints.minutesStep !== 0)
|
|
992
|
+
return "minutesStep";
|
|
993
|
+
return resolveTimeValidationError({
|
|
994
|
+
value: display,
|
|
995
|
+
minTime: constraints.minTime,
|
|
996
|
+
maxTime: constraints.maxTime,
|
|
997
|
+
shouldDisableTime: constraints.shouldDisableTime
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
var dateTimeValidationMessages = {
|
|
1001
|
+
required: "Choose a date and time.",
|
|
1002
|
+
invalidDate: "Enter a complete date and time in the displayed format.",
|
|
1003
|
+
invalidTime: "Enter a valid time.",
|
|
1004
|
+
minDate: "Choose a date on or after the earliest available date.",
|
|
1005
|
+
maxDate: "Choose a date on or before the latest available date.",
|
|
1006
|
+
minTime: "Choose a time at or after opening time.",
|
|
1007
|
+
maxTime: "Choose a time at or before closing time.",
|
|
1008
|
+
minDateTime: "Choose a date and time at or after the minimum.",
|
|
1009
|
+
maxDateTime: "Choose a date and time at or before the maximum.",
|
|
1010
|
+
disablePast: "Choose a future date and time.",
|
|
1011
|
+
disableFuture: "Choose a past date and time.",
|
|
1012
|
+
shouldDisableDate: "This date is unavailable. Choose another date.",
|
|
1013
|
+
shouldDisableTime: "This time is unavailable. Choose another time.",
|
|
1014
|
+
minutesStep: "Choose a time that matches the minute interval.",
|
|
1015
|
+
nonexistentTime: "This local time does not exist because the clocks move forward. Choose another time.",
|
|
1016
|
+
ambiguousTime: "This local time occurs twice because the clocks move back. Choose another time or set an explicit timezone policy."
|
|
1017
|
+
};
|
|
1018
|
+
function useDateTimePicker(props) {
|
|
1019
|
+
const {
|
|
1020
|
+
adapter,
|
|
1021
|
+
adapterLocale,
|
|
1022
|
+
localeText,
|
|
1023
|
+
timezone: providerTimezone
|
|
1024
|
+
} = chunkXMJPY2BR_js.useDatePickersLocalization();
|
|
1025
|
+
const locale = resolveDatePickerLocale(props.locale ?? adapterLocale);
|
|
1026
|
+
const timezone = resolvePickerTimezone(props.timezone, providerTimezone) ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1027
|
+
const calendarSystem = props.calendarSystem ?? getDatePickerCalendarSystem(adapter);
|
|
1028
|
+
const minutesStep = props.minutesStep ?? 1;
|
|
1029
|
+
const disambiguation = props.disambiguation ?? "reject";
|
|
1030
|
+
if (!Number.isInteger(minutesStep) || minutesStep < 1 || 60 % minutesStep !== 0)
|
|
1031
|
+
throw new RangeError(
|
|
1032
|
+
"DateTimePicker.minutesStep must be a positive divisor of 60."
|
|
1033
|
+
);
|
|
1034
|
+
if (!["earlier", "later", "reject"].includes(disambiguation))
|
|
1035
|
+
throw new TypeError("Unsupported DateTimePicker.disambiguation.");
|
|
1036
|
+
if (!["gregory", "buddhist", "jalali", "hijri"].includes(calendarSystem))
|
|
1037
|
+
throw new TypeError("Unsupported DateTimePicker.calendarSystem.");
|
|
1038
|
+
const codec = React2__default.default.useMemo(
|
|
1039
|
+
() => createDateTimeCodec(locale, calendarSystem, props.hour12),
|
|
1040
|
+
[locale, calendarSystem, props.hour12]
|
|
1041
|
+
);
|
|
1042
|
+
const labels = chunkXMJPY2BR_js.resolveDatePickerLocaleText({
|
|
1043
|
+
...localeText,
|
|
1044
|
+
...props.localeText
|
|
1045
|
+
});
|
|
1046
|
+
const controlled = props.value !== void 0;
|
|
1047
|
+
const [internalValue, setInternalValue] = React2__default.default.useState(
|
|
1048
|
+
props.defaultValue ?? null
|
|
1049
|
+
);
|
|
1050
|
+
const value = controlled ? props.value ?? null : internalValue;
|
|
1051
|
+
const toDate = (input, name) => {
|
|
1052
|
+
if (input === void 0) return void 0;
|
|
1053
|
+
return chunkXMJPY2BR_js.toPickerDate(adapter, input, "DateTimePicker." + name);
|
|
1054
|
+
};
|
|
1055
|
+
const validValue = value !== null && adapter.isValid(value) && Number.isFinite(adapter.toJsDate(value).getTime());
|
|
1056
|
+
const storage = validValue ? adapter.toJsDate(value) : null;
|
|
1057
|
+
const display = toTimezoneDisplayDate(storage, timezone);
|
|
1058
|
+
const constraints = {
|
|
1059
|
+
minutesStep,
|
|
1060
|
+
required: props.required,
|
|
1061
|
+
disablePast: props.disablePast,
|
|
1062
|
+
disableFuture: props.disableFuture,
|
|
1063
|
+
shouldDisableDate: props.shouldDisableDate,
|
|
1064
|
+
shouldDisableTime: props.shouldDisableTime,
|
|
1065
|
+
minDate: toTimezoneDisplayDate(
|
|
1066
|
+
toDate(props.minDate, "minDate") ?? null,
|
|
1067
|
+
timezone
|
|
1068
|
+
) ?? void 0,
|
|
1069
|
+
maxDate: toTimezoneDisplayDate(
|
|
1070
|
+
toDate(props.maxDate, "maxDate") ?? null,
|
|
1071
|
+
timezone
|
|
1072
|
+
) ?? void 0,
|
|
1073
|
+
minTime: toTimezoneDisplayDate(
|
|
1074
|
+
toDate(props.minTime, "minTime") ?? null,
|
|
1075
|
+
timezone
|
|
1076
|
+
) ?? void 0,
|
|
1077
|
+
maxTime: toTimezoneDisplayDate(
|
|
1078
|
+
toDate(props.maxTime, "maxTime") ?? null,
|
|
1079
|
+
timezone
|
|
1080
|
+
) ?? void 0,
|
|
1081
|
+
minDateTime: toDate(props.minDateTime, "minDateTime"),
|
|
1082
|
+
maxDateTime: toDate(props.maxDateTime, "maxDateTime")
|
|
1083
|
+
};
|
|
1084
|
+
assertDateTimeBounds(constraints);
|
|
1085
|
+
const reference = toDate(props.referenceDate, "referenceDate");
|
|
1086
|
+
const makeDraft = () => {
|
|
1087
|
+
const date = new Date(
|
|
1088
|
+
display ?? toTimezoneDisplayDate(reference ?? /* @__PURE__ */ new Date(), timezone)
|
|
1089
|
+
);
|
|
1090
|
+
date.setSeconds(0, 0);
|
|
1091
|
+
if (!display && !reference)
|
|
1092
|
+
date.setMinutes(
|
|
1093
|
+
Math.floor(date.getMinutes() / minutesStep) * minutesStep
|
|
1094
|
+
);
|
|
1095
|
+
return date;
|
|
1096
|
+
};
|
|
1097
|
+
const [draft, setDraft] = React2__default.default.useState(makeDraft);
|
|
1098
|
+
const [internalOpen, setInternalOpen] = React2__default.default.useState(
|
|
1099
|
+
props.defaultOpen ?? false
|
|
1100
|
+
);
|
|
1101
|
+
const [text, setText] = React2__default.default.useState(null);
|
|
1102
|
+
const [inputError, setInputError] = React2__default.default.useState(null);
|
|
1103
|
+
const [touched, setTouched] = React2__default.default.useState(false);
|
|
1104
|
+
const inputRef = React2__default.default.useRef(null);
|
|
1105
|
+
const surfaceRef = React2__default.default.useRef(null);
|
|
1106
|
+
const composing = React2__default.default.useRef(false);
|
|
1107
|
+
const interactive = !props.disabled && !props.readOnly && props.status !== "loading";
|
|
1108
|
+
const open = interactive && (props.open ?? internalOpen);
|
|
1109
|
+
const validate = (next) => {
|
|
1110
|
+
const resolution = next ? resolveDateTimeInstant(next, timezone, disambiguation) : { date: null, error: null };
|
|
1111
|
+
return {
|
|
1112
|
+
date: resolution.date,
|
|
1113
|
+
error: resolution.error ?? validateDateTime(next, resolution.date, constraints)
|
|
1114
|
+
};
|
|
1115
|
+
};
|
|
1116
|
+
const valueError = value !== null && !validValue ? "invalidDate" : validateDateTime(display, storage, {
|
|
1117
|
+
...constraints,
|
|
1118
|
+
required: touched && props.required
|
|
1119
|
+
});
|
|
1120
|
+
const error = inputError ?? valueError;
|
|
1121
|
+
const message = (code) => props.validationMessage?.(code) ?? dateTimeValidationMessages[code];
|
|
1122
|
+
const errorMessage = error ? message(error) : void 0;
|
|
1123
|
+
const lastError = React2__default.default.useRef(null);
|
|
1124
|
+
const reportError = (next, nextValue = value) => {
|
|
1125
|
+
if (lastError.current !== next) {
|
|
1126
|
+
lastError.current = next;
|
|
1127
|
+
props.onError?.(next, nextValue);
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
React2__default.default.useEffect(() => {
|
|
1131
|
+
reportError(error);
|
|
1132
|
+
const externalError = props.errorMessage || props.invalid || props.status === "error";
|
|
1133
|
+
inputRef.current?.setCustomValidity(errorMessage ?? (externalError ? typeof props.errorMessage === "string" ? props.errorMessage : "Review this date and time." : ""));
|
|
1134
|
+
});
|
|
1135
|
+
React2__default.default.useEffect(() => {
|
|
1136
|
+
setText(null);
|
|
1137
|
+
setInputError(null);
|
|
1138
|
+
}, [storage?.getTime(), codec]);
|
|
1139
|
+
React2__default.default.useEffect(() => {
|
|
1140
|
+
if (open) setDraft(makeDraft());
|
|
1141
|
+
}, [open, storage?.getTime(), timezone, calendarSystem]);
|
|
1142
|
+
React2__default.default.useEffect(() => {
|
|
1143
|
+
const form = inputRef.current?.form;
|
|
1144
|
+
const reset = (event) => queueMicrotask(() => {
|
|
1145
|
+
if (event.defaultPrevented || inputRef.current?.form !== form) return;
|
|
1146
|
+
if (!controlled) setInternalValue(props.defaultValue ?? null);
|
|
1147
|
+
setText(null);
|
|
1148
|
+
setInputError(null);
|
|
1149
|
+
setTouched(false);
|
|
1150
|
+
setInternalOpen(false);
|
|
1151
|
+
});
|
|
1152
|
+
form?.addEventListener("reset", reset);
|
|
1153
|
+
return () => form?.removeEventListener("reset", reset);
|
|
1154
|
+
}, [controlled, props.defaultValue, props.form]);
|
|
1155
|
+
const setOpen = (next, restoreFocus = false) => {
|
|
1156
|
+
if (next && !interactive) return;
|
|
1157
|
+
if (next !== open) {
|
|
1158
|
+
if (props.open === void 0) setInternalOpen(next);
|
|
1159
|
+
props.onOpenChange?.(next);
|
|
1160
|
+
if (next) props.onOpen?.();
|
|
1161
|
+
else props.onClose?.();
|
|
1162
|
+
}
|
|
1163
|
+
if (restoreFocus) inputRef.current?.focus({ preventScroll: true });
|
|
1164
|
+
};
|
|
1165
|
+
const commit = (next, accept = false) => {
|
|
1166
|
+
if (!interactive) return false;
|
|
1167
|
+
const result = validate(next);
|
|
1168
|
+
if (result.error && next !== null) {
|
|
1169
|
+
setInputError(result.error);
|
|
1170
|
+
setTouched(true);
|
|
1171
|
+
reportError(result.error);
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
const adapted = result.date ? adapter.fromJsDate(result.date) : null;
|
|
1175
|
+
if (!controlled) setInternalValue(adapted);
|
|
1176
|
+
setText(null);
|
|
1177
|
+
setInputError(null);
|
|
1178
|
+
setTouched(true);
|
|
1179
|
+
reportError(result.error, adapted);
|
|
1180
|
+
if (!adapter.isEqual(value, adapted))
|
|
1181
|
+
props.onChange?.(adapted, { validationError: result.error });
|
|
1182
|
+
if (accept) props.onAccept?.(adapted);
|
|
1183
|
+
return true;
|
|
1184
|
+
};
|
|
1185
|
+
const commitText = () => {
|
|
1186
|
+
if (text === null || composing.current || !interactive) return;
|
|
1187
|
+
const parsed = text.trim() ? codec.parse(text) : null;
|
|
1188
|
+
if (text.trim() && !parsed) {
|
|
1189
|
+
setInputError("invalidDate");
|
|
1190
|
+
setTouched(true);
|
|
1191
|
+
reportError("invalidDate");
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
commit(parsed);
|
|
1195
|
+
};
|
|
1196
|
+
return {
|
|
1197
|
+
locale,
|
|
1198
|
+
timezone,
|
|
1199
|
+
calendarSystem,
|
|
1200
|
+
codec,
|
|
1201
|
+
labels,
|
|
1202
|
+
minutesStep,
|
|
1203
|
+
constraints,
|
|
1204
|
+
markTouched: () => setTouched(true),
|
|
1205
|
+
inputRef,
|
|
1206
|
+
surfaceRef,
|
|
1207
|
+
composing,
|
|
1208
|
+
interactive,
|
|
1209
|
+
open,
|
|
1210
|
+
setOpen,
|
|
1211
|
+
draft,
|
|
1212
|
+
setDraft,
|
|
1213
|
+
validate,
|
|
1214
|
+
makeDraftForDate: (date) => toTimezoneDisplayDate(date, timezone),
|
|
1215
|
+
displayText: text ?? codec.format(display),
|
|
1216
|
+
text,
|
|
1217
|
+
setText,
|
|
1218
|
+
setInputError,
|
|
1219
|
+
errorMessage,
|
|
1220
|
+
commit,
|
|
1221
|
+
commitText,
|
|
1222
|
+
makeDraft,
|
|
1223
|
+
message
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
function DateTimePickerPanel({
|
|
1227
|
+
model,
|
|
1228
|
+
props
|
|
1229
|
+
}) {
|
|
1230
|
+
const { draft, setDraft, labels, constraints } = model;
|
|
1231
|
+
const result = model.validate(draft);
|
|
1232
|
+
const today = model.makeDraftForDate(/* @__PURE__ */ new Date());
|
|
1233
|
+
const earliest = constraints.minDateTime && model.makeDraftForDate(constraints.minDateTime);
|
|
1234
|
+
const latest = constraints.maxDateTime && model.makeDraftForDate(constraints.maxDateTime);
|
|
1235
|
+
const minDate = earliest && (!constraints.minDate || earliest > constraints.minDate) ? earliest : constraints.minDate;
|
|
1236
|
+
const maxDate = latest && (!constraints.maxDate || latest < constraints.maxDate) ? latest : constraints.maxDate;
|
|
1237
|
+
const uses12Hours = new Intl.DateTimeFormat(model.locale, {
|
|
1238
|
+
hour: "numeric",
|
|
1239
|
+
hour12: props.hour12
|
|
1240
|
+
}).resolvedOptions().hour12;
|
|
1241
|
+
const digits = new Intl.NumberFormat(model.locale, {
|
|
1242
|
+
minimumIntegerDigits: 2,
|
|
1243
|
+
useGrouping: false
|
|
1244
|
+
});
|
|
1245
|
+
const updateTime = (hour, minute) => {
|
|
1246
|
+
const next = new Date(draft);
|
|
1247
|
+
next.setHours(hour, minute, 0, 0);
|
|
1248
|
+
setDraft(next);
|
|
1249
|
+
};
|
|
1250
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1251
|
+
react.Box,
|
|
1252
|
+
{
|
|
1253
|
+
"data-component-type": "DateTimePicker.Panel",
|
|
1254
|
+
width: "full",
|
|
1255
|
+
dir: props.rtl ? "rtl" : void 0,
|
|
1256
|
+
children: [
|
|
1257
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1258
|
+
react.Calendar,
|
|
1259
|
+
{
|
|
1260
|
+
ariaLabel: labels.datePickerToolbarTitle,
|
|
1261
|
+
value: draft,
|
|
1262
|
+
defaultMonth: draft,
|
|
1263
|
+
onChange: (date) => {
|
|
1264
|
+
if (date instanceof Date) {
|
|
1265
|
+
const next = new Date(date);
|
|
1266
|
+
next.setHours(draft.getHours(), draft.getMinutes(), 0, 0);
|
|
1267
|
+
setDraft(next);
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
locale: model.locale,
|
|
1271
|
+
calendarSystem: model.calendarSystem,
|
|
1272
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
1273
|
+
showMonthDropdown: props.showMonthDropdown,
|
|
1274
|
+
showYearDropdown: props.showYearDropdown,
|
|
1275
|
+
minDate,
|
|
1276
|
+
maxDate,
|
|
1277
|
+
filterDate: (date) => resolveDateValidationError({ ...constraints, minDate, maxDate, value: date, today }) === null,
|
|
1278
|
+
today,
|
|
1279
|
+
rtl: props.rtl,
|
|
1280
|
+
shouldCloseOnSelect: false,
|
|
1281
|
+
containFocus: false,
|
|
1282
|
+
width: "100%"
|
|
1283
|
+
}
|
|
1284
|
+
),
|
|
1285
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1286
|
+
react.Box,
|
|
1287
|
+
{
|
|
1288
|
+
padding: "var(--qb-space-md)",
|
|
1289
|
+
paddingTop: 0,
|
|
1290
|
+
display: "grid",
|
|
1291
|
+
gap: "var(--qb-space-sm)",
|
|
1292
|
+
children: [
|
|
1293
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Text, { size: "small", weight: "semibold", children: labels.timeLabel }),
|
|
1294
|
+
/* @__PURE__ */ jsxRuntime.jsxs(react.Layout, { cols: uses12Hours ? 3 : 2, gap: "var(--qb-space-xs)", children: [
|
|
1295
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Layout.Cell, { span: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1296
|
+
react.Dropdown,
|
|
1297
|
+
{
|
|
1298
|
+
ariaLabel: labels.hoursLabel,
|
|
1299
|
+
selectedId: uses12Hours ? draft.getHours() % 12 || 12 : draft.getHours(),
|
|
1300
|
+
options: Array.from(
|
|
1301
|
+
{ length: uses12Hours ? 12 : 24 },
|
|
1302
|
+
(_, index) => ({
|
|
1303
|
+
id: uses12Hours ? index + 1 : index,
|
|
1304
|
+
value: digits.format(uses12Hours ? index + 1 : index)
|
|
1305
|
+
})
|
|
1306
|
+
),
|
|
1307
|
+
onSelect: (option) => updateTime(
|
|
1308
|
+
uses12Hours ? Number(option.id) % 12 + (draft.getHours() >= 12 ? 12 : 0) : Number(option.id),
|
|
1309
|
+
draft.getMinutes()
|
|
1310
|
+
)
|
|
1311
|
+
}
|
|
1312
|
+
) }),
|
|
1313
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Layout.Cell, { span: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1314
|
+
react.Dropdown,
|
|
1315
|
+
{
|
|
1316
|
+
ariaLabel: labels.minutesLabel,
|
|
1317
|
+
selectedId: draft.getMinutes(),
|
|
1318
|
+
options: [
|
|
1319
|
+
.../* @__PURE__ */ new Set([
|
|
1320
|
+
...Array.from(
|
|
1321
|
+
{ length: 60 / model.minutesStep },
|
|
1322
|
+
(_, index) => index * model.minutesStep
|
|
1323
|
+
),
|
|
1324
|
+
draft.getMinutes()
|
|
1325
|
+
])
|
|
1326
|
+
].sort((a, b) => a - b).map((minute) => ({
|
|
1327
|
+
id: minute,
|
|
1328
|
+
value: digits.format(minute),
|
|
1329
|
+
disabled: minute % model.minutesStep !== 0
|
|
1330
|
+
})),
|
|
1331
|
+
onSelect: (option) => updateTime(draft.getHours(), Number(option.id))
|
|
1332
|
+
}
|
|
1333
|
+
) }),
|
|
1334
|
+
uses12Hours && /* @__PURE__ */ jsxRuntime.jsx(react.Layout.Cell, { span: 1, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1335
|
+
react.Dropdown,
|
|
1336
|
+
{
|
|
1337
|
+
ariaLabel: labels.dayPeriodLabel,
|
|
1338
|
+
selectedId: draft.getHours() >= 12 ? 1 : 0,
|
|
1339
|
+
options: [0, 1].map((period) => {
|
|
1340
|
+
const date = new Date(draft);
|
|
1341
|
+
date.setHours(period * 12);
|
|
1342
|
+
return {
|
|
1343
|
+
id: period,
|
|
1344
|
+
value: new Intl.DateTimeFormat(model.locale, {
|
|
1345
|
+
hour: "numeric",
|
|
1346
|
+
hour12: true
|
|
1347
|
+
}).formatToParts(date).find((part) => part.type === "dayPeriod").value
|
|
1348
|
+
};
|
|
1349
|
+
}),
|
|
1350
|
+
onSelect: (option) => updateTime(
|
|
1351
|
+
draft.getHours() % 12 + Number(option.id) * 12,
|
|
1352
|
+
draft.getMinutes()
|
|
1353
|
+
)
|
|
1354
|
+
}
|
|
1355
|
+
) })
|
|
1356
|
+
] }),
|
|
1357
|
+
model.timezone && /* @__PURE__ */ jsxRuntime.jsx(react.Text, { size: "tiny", secondary: true, children: model.timezone }),
|
|
1358
|
+
result.error && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1359
|
+
react.Text,
|
|
1360
|
+
{
|
|
1361
|
+
role: "status",
|
|
1362
|
+
size: "small",
|
|
1363
|
+
color: "var(--qb-color-danger-foreground)",
|
|
1364
|
+
children: model.message(result.error)
|
|
1365
|
+
}
|
|
1366
|
+
)
|
|
1367
|
+
]
|
|
1368
|
+
}
|
|
1369
|
+
),
|
|
1370
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1371
|
+
react.Box,
|
|
1372
|
+
{
|
|
1373
|
+
display: "flex",
|
|
1374
|
+
justifyContent: "space-between",
|
|
1375
|
+
alignItems: "center",
|
|
1376
|
+
gap: "var(--qb-space-xs)",
|
|
1377
|
+
padding: "var(--qb-space-sm)",
|
|
1378
|
+
borderTop: "1px solid var(--qb-color-border)",
|
|
1379
|
+
children: [
|
|
1380
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1381
|
+
react.Button,
|
|
1382
|
+
{
|
|
1383
|
+
size: "small",
|
|
1384
|
+
priority: "tertiary",
|
|
1385
|
+
onClick: () => {
|
|
1386
|
+
const next = model.makeDraftForDate(/* @__PURE__ */ new Date());
|
|
1387
|
+
next.setSeconds(0, 0);
|
|
1388
|
+
next.setMinutes(
|
|
1389
|
+
Math.floor(next.getMinutes() / model.minutesStep) * model.minutesStep
|
|
1390
|
+
);
|
|
1391
|
+
setDraft(next);
|
|
1392
|
+
},
|
|
1393
|
+
children: labels.nowButtonLabel
|
|
1394
|
+
}
|
|
1395
|
+
),
|
|
1396
|
+
/* @__PURE__ */ jsxRuntime.jsxs(react.Box, { display: "flex", gap: "var(--qb-space-xs)", children: [
|
|
1397
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1398
|
+
react.Button,
|
|
1399
|
+
{
|
|
1400
|
+
size: "small",
|
|
1401
|
+
priority: "secondary",
|
|
1402
|
+
onClick: () => model.setOpen(false, true),
|
|
1403
|
+
children: labels.cancelButtonLabel
|
|
1404
|
+
}
|
|
1405
|
+
),
|
|
1406
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1407
|
+
react.Button,
|
|
1408
|
+
{
|
|
1409
|
+
size: "small",
|
|
1410
|
+
disabled: Boolean(result.error),
|
|
1411
|
+
onClick: () => {
|
|
1412
|
+
if (model.commit(draft, true)) model.setOpen(false, true);
|
|
1413
|
+
},
|
|
1414
|
+
children: labels.applyButtonLabel
|
|
1415
|
+
}
|
|
1416
|
+
)
|
|
1417
|
+
] })
|
|
1418
|
+
]
|
|
1419
|
+
}
|
|
1420
|
+
)
|
|
1421
|
+
]
|
|
1422
|
+
}
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
function DateTimePicker(props) {
|
|
1426
|
+
const model = useDateTimePicker(props);
|
|
1427
|
+
const panelId = React2__default.default.useId();
|
|
1428
|
+
const {
|
|
1429
|
+
value,
|
|
1430
|
+
defaultValue,
|
|
1431
|
+
referenceDate,
|
|
1432
|
+
onChange,
|
|
1433
|
+
onError,
|
|
1434
|
+
onAccept,
|
|
1435
|
+
minDate,
|
|
1436
|
+
maxDate,
|
|
1437
|
+
minTime,
|
|
1438
|
+
maxTime,
|
|
1439
|
+
minDateTime,
|
|
1440
|
+
maxDateTime,
|
|
1441
|
+
disablePast,
|
|
1442
|
+
disableFuture,
|
|
1443
|
+
shouldDisableDate,
|
|
1444
|
+
shouldDisableTime,
|
|
1445
|
+
minutesStep,
|
|
1446
|
+
hour12,
|
|
1447
|
+
timezone,
|
|
1448
|
+
disambiguation,
|
|
1449
|
+
locale,
|
|
1450
|
+
localeText,
|
|
1451
|
+
calendarSystem,
|
|
1452
|
+
firstDayOfWeek,
|
|
1453
|
+
showMonthDropdown,
|
|
1454
|
+
showYearDropdown,
|
|
1455
|
+
open,
|
|
1456
|
+
defaultOpen,
|
|
1457
|
+
onOpen,
|
|
1458
|
+
onClose,
|
|
1459
|
+
onOpenChange,
|
|
1460
|
+
validationMessage,
|
|
1461
|
+
popoverProps,
|
|
1462
|
+
inputRef,
|
|
1463
|
+
onBlur,
|
|
1464
|
+
onKeyDown,
|
|
1465
|
+
onInputClicked,
|
|
1466
|
+
onClear,
|
|
1467
|
+
onCompositionChange,
|
|
1468
|
+
onInvalid,
|
|
1469
|
+
...fieldProps
|
|
1470
|
+
} = props;
|
|
1471
|
+
const focusCalendar = () => model.surfaceRef.current?.querySelector(
|
|
1472
|
+
'[data-component-type="Calendar.Day"][tabindex="0"]'
|
|
1473
|
+
)?.focus();
|
|
1474
|
+
const assignInput = (element) => {
|
|
1475
|
+
model.inputRef.current = element;
|
|
1476
|
+
if (typeof inputRef === "function") inputRef(element);
|
|
1477
|
+
else if (inputRef) inputRef.current = element;
|
|
1478
|
+
};
|
|
1479
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1480
|
+
react.Popover,
|
|
1481
|
+
{
|
|
1482
|
+
...popoverProps,
|
|
1483
|
+
id: panelId,
|
|
1484
|
+
role: "dialog",
|
|
1485
|
+
"aria-label": model.labels.dateTimePickerToolbarTitle,
|
|
1486
|
+
shown: model.open,
|
|
1487
|
+
placement: popoverProps?.placement ?? "bottom-start",
|
|
1488
|
+
appendTo: popoverProps?.appendTo ?? "parent",
|
|
1489
|
+
width: 320,
|
|
1490
|
+
maxWidth: "calc(100vw - 24px)",
|
|
1491
|
+
fluid: true,
|
|
1492
|
+
showArrow: false,
|
|
1493
|
+
surfaceRef: model.surfaceRef,
|
|
1494
|
+
onShow: focusCalendar,
|
|
1495
|
+
onClickOutside: () => model.setOpen(false),
|
|
1496
|
+
onTabOut: () => model.setOpen(false),
|
|
1497
|
+
onEscPress: () => model.setOpen(false, true),
|
|
1498
|
+
children: [
|
|
1499
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Popover.Element, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1500
|
+
react.Input,
|
|
1501
|
+
{
|
|
1502
|
+
...fieldProps,
|
|
1503
|
+
componentType: "DateTimePicker",
|
|
1504
|
+
inputRef: assignInput,
|
|
1505
|
+
type: "text",
|
|
1506
|
+
role: "combobox",
|
|
1507
|
+
ariaHaspopup: "dialog",
|
|
1508
|
+
ariaExpanded: model.open,
|
|
1509
|
+
ariaControls: model.open ? panelId : void 0,
|
|
1510
|
+
ariaLabel: props.ariaLabel ?? (props.label || props.ariaLabelledby ? void 0 : model.labels.dateTimePickerToolbarTitle),
|
|
1511
|
+
value: model.displayText,
|
|
1512
|
+
placeholder: props.placeholder ?? model.codec.format(new Date(2026, 8, 28, 14, 30)),
|
|
1513
|
+
readOnly: props.readOnly || props.status === "loading",
|
|
1514
|
+
status: model.errorMessage ? "error" : props.status,
|
|
1515
|
+
errorMessage: model.errorMessage ?? props.errorMessage,
|
|
1516
|
+
hideStatusSuffix: props.hideStatusSuffix ?? true,
|
|
1517
|
+
autocomplete: props.autocomplete ?? "off",
|
|
1518
|
+
clearButton: props.clearButton ?? true,
|
|
1519
|
+
clearButtonAriaLabel: props.clearButtonAriaLabel ?? model.labels.clearButtonLabel,
|
|
1520
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1521
|
+
react.IconButton,
|
|
1522
|
+
{
|
|
1523
|
+
size: "tiny",
|
|
1524
|
+
priority: "tertiary",
|
|
1525
|
+
showTooltip: false,
|
|
1526
|
+
ariaLabel: model.labels.dateTimePickerToolbarTitle,
|
|
1527
|
+
disabled: !model.interactive,
|
|
1528
|
+
"aria-expanded": model.open,
|
|
1529
|
+
"aria-controls": model.open ? panelId : void 0,
|
|
1530
|
+
onClick: () => model.setOpen(!model.open),
|
|
1531
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(react.Icon, { iconName: "calendar", size: 18, color: "currentColor", decorative: true })
|
|
1532
|
+
}
|
|
1533
|
+
),
|
|
1534
|
+
onClear: (event) => {
|
|
1535
|
+
if (model.commit(null)) {
|
|
1536
|
+
model.setOpen(false);
|
|
1537
|
+
onClear?.(event);
|
|
1538
|
+
}
|
|
1539
|
+
},
|
|
1540
|
+
onChange: (event) => {
|
|
1541
|
+
if (model.interactive) {
|
|
1542
|
+
model.setText(event.target.value);
|
|
1543
|
+
model.setInputError(null);
|
|
1544
|
+
}
|
|
1545
|
+
},
|
|
1546
|
+
onInvalid: (event) => {
|
|
1547
|
+
model.markTouched();
|
|
1548
|
+
onInvalid?.(event);
|
|
1549
|
+
},
|
|
1550
|
+
onBlur: (event) => {
|
|
1551
|
+
model.commitText();
|
|
1552
|
+
onBlur?.(event);
|
|
1553
|
+
},
|
|
1554
|
+
onCompositionChange: (composing) => {
|
|
1555
|
+
model.composing.current = composing;
|
|
1556
|
+
onCompositionChange?.(composing);
|
|
1557
|
+
},
|
|
1558
|
+
onInputClicked,
|
|
1559
|
+
onKeyDown: (event) => {
|
|
1560
|
+
onKeyDown?.(event);
|
|
1561
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing || model.composing.current)
|
|
1562
|
+
return;
|
|
1563
|
+
if (event.key === "ArrowDown" && model.interactive) {
|
|
1564
|
+
event.preventDefault();
|
|
1565
|
+
model.commitText();
|
|
1566
|
+
if (model.open) focusCalendar();
|
|
1567
|
+
else model.setOpen(true);
|
|
1568
|
+
} else if (event.key === "Enter" && model.text !== null) {
|
|
1569
|
+
event.preventDefault();
|
|
1570
|
+
model.commitText();
|
|
1571
|
+
} else if (event.key === "Escape") {
|
|
1572
|
+
model.setText(null);
|
|
1573
|
+
model.setInputError(null);
|
|
1574
|
+
if (model.open) {
|
|
1575
|
+
event.preventDefault();
|
|
1576
|
+
model.setOpen(false, true);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
) }),
|
|
1582
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1583
|
+
react.Popover.Content,
|
|
1584
|
+
{
|
|
1585
|
+
contentPadding: 0,
|
|
1586
|
+
contentStyle: { maxHeight: "calc(100dvh - 32px)", overflowY: "auto" },
|
|
1587
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DateTimePickerPanel, { model, props })
|
|
1588
|
+
}
|
|
1589
|
+
)
|
|
1590
|
+
]
|
|
1591
|
+
}
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
function DatePicker({
|
|
1595
|
+
calendarAriaLabel,
|
|
1596
|
+
clearButtonAriaLabel,
|
|
1597
|
+
defaultValue,
|
|
1598
|
+
disableFuture,
|
|
1599
|
+
disablePast,
|
|
1600
|
+
localeText,
|
|
1601
|
+
maxDate,
|
|
1602
|
+
minDate,
|
|
1603
|
+
onChange,
|
|
1604
|
+
onClose,
|
|
1605
|
+
onError,
|
|
1606
|
+
onOpen,
|
|
1607
|
+
shouldDisableDate,
|
|
1608
|
+
slotProps,
|
|
1609
|
+
slots,
|
|
1610
|
+
timezone,
|
|
1611
|
+
value,
|
|
1612
|
+
...props
|
|
1613
|
+
}) {
|
|
1614
|
+
const field = usePickerField(value, defaultValue, {
|
|
1615
|
+
...props,
|
|
1616
|
+
timezone,
|
|
1617
|
+
inputRef: props.inputRef ?? slotProps?.field?.inputRef
|
|
1618
|
+
});
|
|
1619
|
+
const FieldComponent = slots?.field ?? react.DatePicker;
|
|
1620
|
+
const labels = chunkXMJPY2BR_js.resolveDatePickerLocaleText({ ...field.localeText, ...localeText });
|
|
1621
|
+
const calendarSystem = props.calendarSystem ?? getDatePickerCalendarSystem(field.adapter);
|
|
1622
|
+
const constraints = {
|
|
1623
|
+
disableFuture,
|
|
1624
|
+
disablePast,
|
|
1625
|
+
shouldDisableDate,
|
|
1626
|
+
today: props.today ?? toTimezoneDisplayDate(/* @__PURE__ */ new Date(), field.timezone),
|
|
1627
|
+
minDate: field.display(minDate, "minDate") ?? void 0,
|
|
1628
|
+
maxDate: field.display(maxDate, "maxDate") ?? void 0
|
|
1629
|
+
};
|
|
1630
|
+
const validate = (date) => resolveDateValidationError({ ...constraints, value: date });
|
|
1631
|
+
const pendingText = React2__default.default.useRef(null);
|
|
1632
|
+
const accept = (date) => {
|
|
1633
|
+
if (props.disabled || props.readOnly || props.status === "loading" || validate(date)) return;
|
|
1634
|
+
const storage = fromTimezoneDisplayDate(date, field.timezone);
|
|
1635
|
+
const next = storage ? field.adapter.fromJsDate(storage) : null;
|
|
1636
|
+
field.setAccepted(next);
|
|
1637
|
+
onChange?.(next, { validationError: null });
|
|
1638
|
+
onError?.(null, next);
|
|
1639
|
+
};
|
|
1640
|
+
const commitText = (input) => {
|
|
1641
|
+
const text = pendingText.current;
|
|
1642
|
+
pendingText.current = null;
|
|
1643
|
+
if (text === null || text !== input.value) return;
|
|
1644
|
+
const date = react.parseDateInputForCalendarSystem(text, field.locale, calendarSystem, true);
|
|
1645
|
+
if (date) accept(date);
|
|
1646
|
+
};
|
|
1647
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1648
|
+
FieldComponent,
|
|
1649
|
+
{
|
|
1650
|
+
...slotProps?.field,
|
|
1651
|
+
...props,
|
|
1652
|
+
inputRef: field.inputRef,
|
|
1653
|
+
calendarAriaLabel: calendarAriaLabel ?? labels.datePickerToolbarTitle,
|
|
1654
|
+
calendarSystem,
|
|
1655
|
+
clearButtonAriaLabel: clearButtonAriaLabel ?? labels.clearButtonLabel,
|
|
1656
|
+
excludePastDates: disablePast,
|
|
1657
|
+
locale: field.locale,
|
|
1658
|
+
today: constraints.today,
|
|
1659
|
+
filterDate: (date) => validate(date) === null,
|
|
1660
|
+
maxDate: constraints.maxDate,
|
|
1661
|
+
minDate: constraints.minDate,
|
|
1662
|
+
onChange: (text, date, event) => {
|
|
1663
|
+
pendingText.current = event && text !== "" ? text : null;
|
|
1664
|
+
if (pendingText.current === null && (date || text === "")) accept(date ?? null);
|
|
1665
|
+
},
|
|
1666
|
+
onBlur: (event) => {
|
|
1667
|
+
commitText(event.currentTarget);
|
|
1668
|
+
(props.onBlur ?? slotProps?.field?.onBlur)?.(event);
|
|
1669
|
+
},
|
|
1670
|
+
onEnterPressed: (event) => {
|
|
1671
|
+
(props.onEnterPressed ?? slotProps?.field?.onEnterPressed)?.(event);
|
|
1672
|
+
if (!event.defaultPrevented) commitText(event.currentTarget);
|
|
1673
|
+
},
|
|
1674
|
+
onClose,
|
|
1675
|
+
onInvalid: (text) => {
|
|
1676
|
+
const parsed = react.parseDateInputForCalendarSystem(text, field.locale, calendarSystem, true);
|
|
1677
|
+
onError?.(parsed ? validate(parsed) : "invalidDate", field.accepted);
|
|
1678
|
+
},
|
|
1679
|
+
onOpenChange: (open) => {
|
|
1680
|
+
if (open) onOpen?.();
|
|
1681
|
+
},
|
|
1682
|
+
slots: { calendar: slots?.calendar },
|
|
1683
|
+
slotProps: { calendar: slotProps?.calendar },
|
|
1684
|
+
value: field.display(field.accepted, "value")
|
|
1685
|
+
}
|
|
1686
|
+
);
|
|
1687
|
+
}
|
|
1688
|
+
function TimePicker({
|
|
1689
|
+
ariaLabel,
|
|
1690
|
+
defaultValue,
|
|
1691
|
+
disableFuture,
|
|
1692
|
+
disablePast,
|
|
1693
|
+
localeText,
|
|
1694
|
+
maxTime,
|
|
1695
|
+
minTime,
|
|
1696
|
+
onChange,
|
|
1697
|
+
onError,
|
|
1698
|
+
shouldDisableTime,
|
|
1699
|
+
slotProps,
|
|
1700
|
+
slots,
|
|
1701
|
+
timezone,
|
|
1702
|
+
value,
|
|
1703
|
+
...props
|
|
1704
|
+
}) {
|
|
1705
|
+
const field = usePickerField(value, defaultValue, {
|
|
1706
|
+
...props,
|
|
1707
|
+
timezone,
|
|
1708
|
+
inputRef: props.inputRef ?? slotProps?.field?.inputRef
|
|
1709
|
+
});
|
|
1710
|
+
const FieldComponent = slots?.field ?? react.TimeInput;
|
|
1711
|
+
const labels = chunkXMJPY2BR_js.resolveDatePickerLocaleText({ ...field.localeText, ...localeText });
|
|
1712
|
+
const constraints = {
|
|
1713
|
+
disableFuture,
|
|
1714
|
+
disablePast,
|
|
1715
|
+
shouldDisableTime,
|
|
1716
|
+
now: toTimezoneDisplayDate(/* @__PURE__ */ new Date(), field.timezone),
|
|
1717
|
+
minTime: field.display(minTime, "minTime") ?? void 0,
|
|
1718
|
+
maxTime: field.display(maxTime, "maxTime") ?? void 0
|
|
1719
|
+
};
|
|
1720
|
+
if (constraints.minTime && constraints.maxTime && minutesFromDate(constraints.minTime) > minutesFromDate(constraints.maxTime))
|
|
1721
|
+
throw new RangeError("TimePicker.minTime/maxTime must be ordered.");
|
|
1722
|
+
const validate = (date) => resolveTimeValidationError({ ...constraints, value: date });
|
|
1723
|
+
const selected = field.display(field.accepted, "value");
|
|
1724
|
+
const [draftError, setDraftError] = React2__default.default.useState(null);
|
|
1725
|
+
const valueError = validate(selected);
|
|
1726
|
+
const error = draftError ?? valueError;
|
|
1727
|
+
const lastError = React2__default.default.useRef(null);
|
|
1728
|
+
React2__default.default.useEffect(() => {
|
|
1729
|
+
if (lastError.current !== error) {
|
|
1730
|
+
lastError.current = error;
|
|
1731
|
+
onError?.(error, field.accepted);
|
|
1732
|
+
}
|
|
1733
|
+
}, [error, field.accepted, onError]);
|
|
1734
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1735
|
+
FieldComponent,
|
|
1736
|
+
{
|
|
1737
|
+
...slotProps?.field,
|
|
1738
|
+
...props,
|
|
1739
|
+
inputRef: field.inputRef,
|
|
1740
|
+
ariaLabel: ariaLabel ?? labels.timePickerToolbarTitle,
|
|
1741
|
+
locale: field.locale,
|
|
1742
|
+
filterTime: (date) => validate(date) === null,
|
|
1743
|
+
status: props.status === "loading" ? "loading" : error ? "error" : props.status ?? slotProps?.field?.status,
|
|
1744
|
+
statusMessage: error ? dateTimeValidationMessages[error] : props.statusMessage ?? slotProps?.field?.statusMessage,
|
|
1745
|
+
invalidMessage: props.invalidMessage ?? slotProps?.field?.invalidMessage ?? (draftError ? dateTimeValidationMessages[draftError] : void 0),
|
|
1746
|
+
onChange: ({ date }) => {
|
|
1747
|
+
if (props.disabled || props.readOnly || props.status === "loading") return;
|
|
1748
|
+
const candidateError = validate(date);
|
|
1749
|
+
if (candidateError) {
|
|
1750
|
+
setDraftError(candidateError);
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
const storage = fromTimezoneDisplayDate(date, field.timezone);
|
|
1754
|
+
const next = storage ? field.adapter.fromJsDate(storage) : null;
|
|
1755
|
+
field.setAccepted(next);
|
|
1756
|
+
setDraftError(null);
|
|
1757
|
+
lastError.current = null;
|
|
1758
|
+
onChange?.(next, { validationError: null });
|
|
1759
|
+
onError?.(null, next);
|
|
1760
|
+
},
|
|
1761
|
+
onValidationChange: (invalid) => setDraftError(invalid ? invalid.date ? validate(invalid.date) : "invalidTime" : null),
|
|
1762
|
+
onInvalid: ({ date }) => setDraftError(date ? validate(date) : "invalidTime"),
|
|
1763
|
+
value: selected
|
|
1764
|
+
}
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1767
|
+
function DateCalendar(props) {
|
|
1768
|
+
const { adapter, adapterLocale, timezone } = chunkXMJPY2BR_js.useDatePickersLocalization();
|
|
1769
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1770
|
+
react.Calendar,
|
|
1771
|
+
{
|
|
1772
|
+
...props,
|
|
1773
|
+
locale: resolveDatePickerLocale(props.locale ?? adapterLocale),
|
|
1774
|
+
calendarSystem: props.calendarSystem ?? getDatePickerCalendarSystem(adapter),
|
|
1775
|
+
today: props.today ?? toTimezoneDisplayDate(/* @__PURE__ */ new Date(), resolvePickerTimezone(timezone)),
|
|
1776
|
+
selectionMode: props.selectionMode ?? "day"
|
|
1777
|
+
}
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
function parsePickerDateValue(value, locale = "en", calendarSystem = "gregory") {
|
|
1781
|
+
if (value === null || value === void 0) return null;
|
|
1782
|
+
return react.parseDateInputForCalendarSystem(value, locale, calendarSystem) ?? null;
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
// src/frameworks/react/index.ts
|
|
1786
|
+
var datePickersReactFrameworkAdapter = Object.freeze({
|
|
1787
|
+
apiVersion: 1,
|
|
1788
|
+
id: "quickbuilder-react",
|
|
1789
|
+
framework: "react",
|
|
1790
|
+
packageName: "@quickbuilder.io/date-pickers",
|
|
1791
|
+
entrypoint: "@quickbuilder.io/date-pickers/react",
|
|
1792
|
+
status: "implemented",
|
|
1793
|
+
capabilities: Object.freeze(["picker-components", "localization", "date-adapters", "calendar-systems"])
|
|
1794
|
+
});
|
|
1795
|
+
var reactFrameworkAdapter = datePickersReactFrameworkAdapter;
|
|
1796
|
+
|
|
1797
|
+
Object.defineProperty(exports, "AdapterNativeDate", {
|
|
1798
|
+
enumerable: true,
|
|
1799
|
+
get: function () { return chunkXMJPY2BR_js.AdapterNativeDate; }
|
|
1800
|
+
});
|
|
1801
|
+
Object.defineProperty(exports, "DatePickersLocalizationProvider", {
|
|
1802
|
+
enumerable: true,
|
|
1803
|
+
get: function () { return chunkXMJPY2BR_js.DatePickersLocalizationProvider; }
|
|
1804
|
+
});
|
|
1805
|
+
Object.defineProperty(exports, "createDatePickerAdapter", {
|
|
1806
|
+
enumerable: true,
|
|
1807
|
+
get: function () { return chunkXMJPY2BR_js.createDatePickerAdapter; }
|
|
1808
|
+
});
|
|
1809
|
+
Object.defineProperty(exports, "defaultDatePickerLocaleText", {
|
|
1810
|
+
enumerable: true,
|
|
1811
|
+
get: function () { return chunkXMJPY2BR_js.defaultDatePickerLocaleText; }
|
|
1812
|
+
});
|
|
1813
|
+
Object.defineProperty(exports, "resolveDatePickerLocaleText", {
|
|
1814
|
+
enumerable: true,
|
|
1815
|
+
get: function () { return chunkXMJPY2BR_js.resolveDatePickerLocaleText; }
|
|
1816
|
+
});
|
|
1817
|
+
Object.defineProperty(exports, "toPickerDate", {
|
|
1818
|
+
enumerable: true,
|
|
1819
|
+
get: function () { return chunkXMJPY2BR_js.toPickerDate; }
|
|
1820
|
+
});
|
|
1821
|
+
Object.defineProperty(exports, "useDatePickersLocalization", {
|
|
1822
|
+
enumerable: true,
|
|
1823
|
+
get: function () { return chunkXMJPY2BR_js.useDatePickersLocalization; }
|
|
1824
|
+
});
|
|
1825
|
+
exports.AdapterDateFns = AdapterDateFns;
|
|
1826
|
+
exports.AdapterDateFnsJalali = AdapterDateFnsJalali;
|
|
1827
|
+
exports.AdapterDayjs = AdapterDayjs;
|
|
1828
|
+
exports.AdapterDayjsBuddhist = AdapterDayjsBuddhist;
|
|
1829
|
+
exports.AdapterLuxon = AdapterLuxon;
|
|
1830
|
+
exports.AdapterMoment = AdapterMoment;
|
|
1831
|
+
exports.AdapterMomentHijri = AdapterMomentHijri;
|
|
1832
|
+
exports.AdapterMomentJalaali = AdapterMomentJalaali;
|
|
1833
|
+
exports.DateCalendar = DateCalendar;
|
|
1834
|
+
exports.DatePicker = DatePicker;
|
|
1835
|
+
exports.DateTimePicker = DateTimePicker;
|
|
1836
|
+
exports.TimePicker = TimePicker;
|
|
1837
|
+
exports.addCalendarDays = addCalendarDays;
|
|
1838
|
+
exports.addZonedCalendarDays = addZonedCalendarDays;
|
|
1839
|
+
exports.assertSupportedTimezone = assertSupportedTimezone;
|
|
1840
|
+
exports.cloneDate = cloneDate2;
|
|
1841
|
+
exports.datePickerCalendarSystemAdapters = datePickerCalendarSystemAdapters;
|
|
1842
|
+
exports.datePickerCapabilityFeatureIds = datePickerCapabilityFeatureIds;
|
|
1843
|
+
exports.datePickerCapabilityFeatures = datePickerCapabilityFeatures;
|
|
1844
|
+
exports.datePickersFrameworkAdapterSupport = datePickersFrameworkAdapterSupport;
|
|
1845
|
+
exports.datePickersPackageManifest = datePickersPackageManifest;
|
|
1846
|
+
exports.datePickersReactFrameworkAdapter = datePickersReactFrameworkAdapter;
|
|
1847
|
+
exports.formatDatePattern = formatDatePattern;
|
|
1848
|
+
exports.formatDateTime = formatDateTime;
|
|
1849
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
1850
|
+
exports.frameworkAdapterSupport = frameworkAdapterSupport;
|
|
1851
|
+
exports.fromTimezoneDisplayDate = fromTimezoneDisplayDate;
|
|
1852
|
+
exports.getDatePickerCalendarSystem = getDatePickerCalendarSystem;
|
|
1853
|
+
exports.getSystemTimezone = getSystemTimezone;
|
|
1854
|
+
exports.getZonedCivilTimestamp = getZonedCivilTimestamp;
|
|
1855
|
+
exports.isCalendarSystemAdapter = isCalendarSystemAdapter;
|
|
1856
|
+
exports.isDateThisWeek = isDateThisWeek;
|
|
1857
|
+
exports.isDateToday = isDateToday;
|
|
1858
|
+
exports.isDateYesterday = isDateYesterday;
|
|
1859
|
+
exports.isSameCalendarDay = isSameCalendarDay;
|
|
1860
|
+
exports.isValidDate = isValidDate;
|
|
1861
|
+
exports.mergeDateAndTime = mergeDateAndTime;
|
|
1862
|
+
exports.minutesFromDate = minutesFromDate;
|
|
1863
|
+
exports.packageManifest = packageManifest;
|
|
1864
|
+
exports.parseIsoDate = parseIsoDate;
|
|
1865
|
+
exports.parsePickerDateValue = parsePickerDateValue;
|
|
1866
|
+
exports.parseStoredPickerValue = parseStoredPickerValue;
|
|
1867
|
+
exports.reactFrameworkAdapter = reactFrameworkAdapter;
|
|
1868
|
+
exports.resolveDatePickerLocale = resolveDatePickerLocale;
|
|
1869
|
+
exports.resolveDateTimeInstant = resolveDateTimeInstant;
|
|
1870
|
+
exports.resolveDateValidationError = resolveDateValidationError;
|
|
1871
|
+
exports.resolvePickerTimezone = resolvePickerTimezone;
|
|
1872
|
+
exports.resolveTimeValidationError = resolveTimeValidationError;
|
|
1873
|
+
exports.resolveZonedCivilTimestamp = resolveZonedCivilTimestamp;
|
|
1874
|
+
exports.serializePickerDate = serializePickerDate;
|
|
1875
|
+
exports.serializePickerDateTime = serializePickerDateTime;
|
|
1876
|
+
exports.serializePickerTime = serializePickerTime;
|
|
1877
|
+
exports.shouldAllowDate = shouldAllowDate;
|
|
1878
|
+
exports.shouldAllowTime = shouldAllowTime;
|
|
1879
|
+
exports.startOfDay = startOfDay;
|
|
1880
|
+
exports.subtractCalendarDays = subtractCalendarDays;
|
|
1881
|
+
exports.supportsDatePickerCalendarSystem = supportsDatePickerCalendarSystem;
|
|
1882
|
+
exports.toDatePickerDate = toDatePickerDate;
|
|
1883
|
+
exports.toTimezoneDisplayDate = toTimezoneDisplayDate;
|
|
1884
|
+
//# sourceMappingURL=react.js.map
|
|
1885
|
+
//# sourceMappingURL=react.js.map
|