@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/index.mjs
ADDED
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
import { normalizeLocale } from '@quickbuilder.io/design-system/calendar';
|
|
2
|
+
|
|
3
|
+
// src/framework-adapter.ts
|
|
4
|
+
var datePickersFrameworkAdapterSupport = Object.freeze([
|
|
5
|
+
{ framework: "react", entrypoint: "@quickbuilder.io/date-pickers/react", status: "implemented" },
|
|
6
|
+
{ framework: "vue", status: "unsupported" },
|
|
7
|
+
{ framework: "preact", status: "unsupported" },
|
|
8
|
+
{ framework: "qwik", status: "unsupported" },
|
|
9
|
+
{ framework: "astro", status: "unsupported" },
|
|
10
|
+
{ framework: "svelte", status: "unsupported" },
|
|
11
|
+
{ framework: "solid", status: "unsupported" },
|
|
12
|
+
{ framework: "web-components", status: "unsupported" },
|
|
13
|
+
{ framework: "react-native", status: "implemented", entrypoint: "@quickbuilder.io/date-pickers/react-native" }
|
|
14
|
+
]);
|
|
15
|
+
var frameworkAdapterSupport = datePickersFrameworkAdapterSupport;
|
|
16
|
+
|
|
17
|
+
// src/DatePickers.capabilities.ts
|
|
18
|
+
var datePickerCapabilityFeatures = [
|
|
19
|
+
{ id: "date-picker", label: "Date picker", category: "field", packageTier: "community", status: "implemented" },
|
|
20
|
+
{ id: "time-picker", label: "Time picker", category: "field", packageTier: "community", status: "implemented" },
|
|
21
|
+
{ id: "date-time-picker", label: "Date time picker", category: "field", packageTier: "community", status: "implemented" },
|
|
22
|
+
{ id: "date-calendar", label: "Date calendar", category: "view", packageTier: "community", status: "implemented" },
|
|
23
|
+
{ id: "controlled-state", label: "Controlled and uncontrolled values", category: "field", packageTier: "community", status: "implemented" },
|
|
24
|
+
{ id: "validation", label: "Date and time validation", category: "validation", packageTier: "community", status: "implemented" },
|
|
25
|
+
{ id: "localization", label: "Locale-aware formatting", category: "localization", packageTier: "community", status: "implemented" },
|
|
26
|
+
{ id: "localization-provider", label: "Localization provider", category: "localization", packageTier: "community", status: "implemented" },
|
|
27
|
+
{ id: "date-adapters", label: "Date adapter contract", category: "localization", packageTier: "community", status: "implemented" },
|
|
28
|
+
{ id: "date-adapter-bridges", label: "Day.js, date-fns, Luxon, and Moment adapter bridges", category: "localization", packageTier: "community", status: "implemented" },
|
|
29
|
+
{ id: "calendar-system-adapter-bridges", label: "Jalali, Hijri, and Buddhist adapter bridges", category: "localization", packageTier: "community", status: "implemented" },
|
|
30
|
+
{ id: "calendar-system-display-labels", label: "Calendar-system display labels", category: "localization", packageTier: "community", status: "implemented" },
|
|
31
|
+
{ id: "calendar-system-field-values", label: "Calendar-system field parsing and formatting", category: "localization", packageTier: "community", status: "implemented" },
|
|
32
|
+
{ id: "slots", label: "Slots and slot props", category: "customization", packageTier: "community", status: "implemented" },
|
|
33
|
+
{ id: "date-range-picker", label: "Date range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
34
|
+
{ id: "time-range-picker", label: "Time range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
35
|
+
{ id: "date-time-range-picker", label: "Date time range picker", category: "field", packageTier: "pro", status: "implemented" },
|
|
36
|
+
{ id: "range-shortcuts", label: "Range shortcuts", category: "customization", packageTier: "pro", status: "implemented" },
|
|
37
|
+
{ id: "timezone-values", label: "Timezone-aware rendering and value conversion", category: "localization", packageTier: "community", status: "implemented" },
|
|
38
|
+
{ id: "non-gregorian-calendar-grid", label: "Native non-Gregorian calendar grid rendering", category: "localization", packageTier: "community", status: "implemented" }
|
|
39
|
+
];
|
|
40
|
+
var datePickerCapabilityFeatureIds = datePickerCapabilityFeatures.map((feature) => feature.id);
|
|
41
|
+
|
|
42
|
+
// src/DatePickersTimezone.ts
|
|
43
|
+
function resolvePickerTimezone(timezone, providerTimezone) {
|
|
44
|
+
const requestedTimezone = timezone ?? providerTimezone;
|
|
45
|
+
if (requestedTimezone === void 0) return void 0;
|
|
46
|
+
if (requestedTimezone === "default") {
|
|
47
|
+
if (providerTimezone === void 0 || providerTimezone === "default") return void 0;
|
|
48
|
+
return resolvePickerTimezone(providerTimezone);
|
|
49
|
+
}
|
|
50
|
+
if (requestedTimezone === "system") {
|
|
51
|
+
return getSystemTimezone();
|
|
52
|
+
}
|
|
53
|
+
if (requestedTimezone === "UTC") {
|
|
54
|
+
return "UTC";
|
|
55
|
+
}
|
|
56
|
+
assertSupportedTimezone(requestedTimezone);
|
|
57
|
+
return requestedTimezone;
|
|
58
|
+
}
|
|
59
|
+
function toTimezoneDisplayDate(value, timezone) {
|
|
60
|
+
if (value === null) return null;
|
|
61
|
+
if (timezone === void 0) return cloneDate(value);
|
|
62
|
+
const parts = getTimezoneParts(value, timezone);
|
|
63
|
+
const display = /* @__PURE__ */ new Date(0);
|
|
64
|
+
display.setFullYear(parts.year, parts.month - 1, parts.day);
|
|
65
|
+
display.setHours(parts.hour, parts.minute, parts.second, value.getMilliseconds());
|
|
66
|
+
return display;
|
|
67
|
+
}
|
|
68
|
+
function fromTimezoneDisplayDate(value, timezone) {
|
|
69
|
+
if (value === null) return null;
|
|
70
|
+
if (timezone === void 0) return cloneDate(value);
|
|
71
|
+
const utcGuess = civilStamp(value);
|
|
72
|
+
const firstOffset = getTimezoneOffsetMs(new Date(utcGuess), timezone);
|
|
73
|
+
const firstCandidate = new Date(utcGuess - firstOffset);
|
|
74
|
+
const secondOffset = getTimezoneOffsetMs(firstCandidate, timezone);
|
|
75
|
+
return new Date(utcGuess - secondOffset);
|
|
76
|
+
}
|
|
77
|
+
function getSystemTimezone() {
|
|
78
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
79
|
+
if (!zone) throw new Error("The system timezone is unavailable.");
|
|
80
|
+
return zone;
|
|
81
|
+
}
|
|
82
|
+
function assertSupportedTimezone(timezone) {
|
|
83
|
+
getTimezoneFormatter(timezone);
|
|
84
|
+
}
|
|
85
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
86
|
+
function getTimezoneFormatter(timezone) {
|
|
87
|
+
if (typeof timezone !== "string") throw new TypeError("Unsupported timezone. Supply an IANA timezone name.");
|
|
88
|
+
const cached = formatters.get(timezone);
|
|
89
|
+
if (cached) return cached;
|
|
90
|
+
try {
|
|
91
|
+
const formatter = new Intl.DateTimeFormat("en-US-u-ca-gregory", {
|
|
92
|
+
day: "2-digit",
|
|
93
|
+
hour: "2-digit",
|
|
94
|
+
hourCycle: "h23",
|
|
95
|
+
minute: "2-digit",
|
|
96
|
+
month: "2-digit",
|
|
97
|
+
second: "2-digit",
|
|
98
|
+
timeZone: timezone,
|
|
99
|
+
year: "numeric"
|
|
100
|
+
});
|
|
101
|
+
if (formatters.size >= 32) formatters.delete(formatters.keys().next().value);
|
|
102
|
+
formatters.set(timezone, formatter);
|
|
103
|
+
return formatter;
|
|
104
|
+
} catch {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Unsupported date picker timezone "${timezone}". Use "UTC", "system", "default", or a valid IANA timezone.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function cloneDate(value) {
|
|
111
|
+
return new Date(value.getTime());
|
|
112
|
+
}
|
|
113
|
+
function getZonedCivilTimestamp(value, timezone) {
|
|
114
|
+
if (!Number.isFinite(value.getTime())) throw new RangeError("A valid instant is required.");
|
|
115
|
+
if (timezone === "UTC") return value.getTime();
|
|
116
|
+
const parts = getTimezoneParts(value, timezone);
|
|
117
|
+
const stamp = /* @__PURE__ */ new Date(0);
|
|
118
|
+
stamp.setUTCFullYear(parts.year, parts.month - 1, parts.day);
|
|
119
|
+
stamp.setUTCHours(parts.hour, parts.minute, parts.second, value.getMilliseconds());
|
|
120
|
+
return stamp.getTime();
|
|
121
|
+
}
|
|
122
|
+
function getTimezoneOffsetMs(value, timezone) {
|
|
123
|
+
return getZonedCivilTimestamp(value, timezone) - value.getTime();
|
|
124
|
+
}
|
|
125
|
+
function getTimezoneParts(value, timezone) {
|
|
126
|
+
const parts = getTimezoneFormatter(timezone).formatToParts(value);
|
|
127
|
+
const resolvedParts = Object.fromEntries(
|
|
128
|
+
parts.map((part) => [part.type, part.value])
|
|
129
|
+
);
|
|
130
|
+
return {
|
|
131
|
+
day: Number(resolvedParts.day),
|
|
132
|
+
hour: Number(resolvedParts.hour),
|
|
133
|
+
minute: Number(resolvedParts.minute),
|
|
134
|
+
month: Number(resolvedParts.month),
|
|
135
|
+
second: Number(resolvedParts.second),
|
|
136
|
+
year: Number(resolvedParts.year)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function civilStamp(date) {
|
|
140
|
+
const stamp = /* @__PURE__ */ new Date(0);
|
|
141
|
+
stamp.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());
|
|
142
|
+
stamp.setUTCHours(
|
|
143
|
+
date.getHours(),
|
|
144
|
+
date.getMinutes(),
|
|
145
|
+
date.getSeconds(),
|
|
146
|
+
date.getMilliseconds()
|
|
147
|
+
);
|
|
148
|
+
return stamp.getTime();
|
|
149
|
+
}
|
|
150
|
+
function resolveDateTimeInstant(value, timezone, disambiguation) {
|
|
151
|
+
if (!Number.isFinite(value.getTime()))
|
|
152
|
+
throw new RangeError("Date-time resolution requires a valid date.");
|
|
153
|
+
if (timezone === void 0) {
|
|
154
|
+
assertDisambiguation(disambiguation);
|
|
155
|
+
return { date: new Date(value), error: null };
|
|
156
|
+
}
|
|
157
|
+
return resolveZonedCivilTimestamp(civilStamp(value), timezone, disambiguation);
|
|
158
|
+
}
|
|
159
|
+
function addZonedCalendarDays(value, days, timezone) {
|
|
160
|
+
if (!Number.isFinite(value.getTime()) || !Number.isSafeInteger(days))
|
|
161
|
+
throw new RangeError("Calendar-day addition requires a valid instant and an integer day count.");
|
|
162
|
+
assertSupportedTimezone(timezone);
|
|
163
|
+
if (days === 0) return { date: new Date(value), error: null };
|
|
164
|
+
const target = getZonedCivilTimestamp(value, timezone) + days * 864e5;
|
|
165
|
+
return resolveZonedCivilTimestamp(target, timezone, "reject");
|
|
166
|
+
}
|
|
167
|
+
function assertDisambiguation(disambiguation) {
|
|
168
|
+
if (!["earlier", "later", "reject"].includes(disambiguation))
|
|
169
|
+
throw new TypeError("Unsupported date-time disambiguation.");
|
|
170
|
+
}
|
|
171
|
+
function resolveZonedCivilTimestamp(target, timezone, disambiguation) {
|
|
172
|
+
if (!Number.isSafeInteger(target) || !Number.isFinite(new Date(target).getTime()))
|
|
173
|
+
throw new RangeError("A valid civil timestamp is required.");
|
|
174
|
+
assertDisambiguation(disambiguation);
|
|
175
|
+
if (timezone === "UTC") return { date: new Date(target), error: null };
|
|
176
|
+
const offsets = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const hours of [-36, -12, 0, 12, 36]) {
|
|
178
|
+
const probe = new Date(target + hours * 36e5);
|
|
179
|
+
offsets.add(getTimezoneOffsetMs(probe, timezone));
|
|
180
|
+
}
|
|
181
|
+
const matches = [...offsets].filter((offset) => getTimezoneOffsetMs(new Date(target - offset), timezone) === offset).map((offset) => target - offset).sort((a, b) => a - b);
|
|
182
|
+
if (!matches.length) return { date: null, error: "nonexistentTime" };
|
|
183
|
+
if (matches.length > 1 && disambiguation === "reject")
|
|
184
|
+
return { date: null, error: "ambiguousTime" };
|
|
185
|
+
return {
|
|
186
|
+
date: new Date(
|
|
187
|
+
disambiguation === "later" ? matches[matches.length - 1] : matches[0]
|
|
188
|
+
),
|
|
189
|
+
error: null
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function resolveDatePickerLocale(requested) {
|
|
193
|
+
const supported = normalizeLocale(requested);
|
|
194
|
+
if (requested === supported) return supported;
|
|
195
|
+
const [canonical] = Intl.getCanonicalLocales(requested);
|
|
196
|
+
const locale = normalizeLocale(canonical);
|
|
197
|
+
if (locale !== canonical) throw new RangeError(`Unsupported date picker locale: ${requested}`);
|
|
198
|
+
return locale;
|
|
199
|
+
}
|
|
200
|
+
function cloneDate2(value) {
|
|
201
|
+
return new Date(value.getTime());
|
|
202
|
+
}
|
|
203
|
+
function isValidDate(value) {
|
|
204
|
+
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
205
|
+
}
|
|
206
|
+
function startOfDay(value) {
|
|
207
|
+
const date = cloneDate2(value);
|
|
208
|
+
date.setHours(0, 0, 0, 0);
|
|
209
|
+
return date;
|
|
210
|
+
}
|
|
211
|
+
function mergeDateAndTime(dateValue, timeValue) {
|
|
212
|
+
if (!dateValue && !timeValue) return null;
|
|
213
|
+
const nextValue = cloneDate2(dateValue ?? timeValue ?? /* @__PURE__ */ new Date());
|
|
214
|
+
if (timeValue) {
|
|
215
|
+
nextValue.setHours(timeValue.getHours(), timeValue.getMinutes(), 0, 0);
|
|
216
|
+
}
|
|
217
|
+
return nextValue;
|
|
218
|
+
}
|
|
219
|
+
function resolveDateValidationError({
|
|
220
|
+
disableFuture = false,
|
|
221
|
+
disablePast = false,
|
|
222
|
+
maxDate,
|
|
223
|
+
minDate,
|
|
224
|
+
shouldDisableDate,
|
|
225
|
+
today = /* @__PURE__ */ new Date(),
|
|
226
|
+
value
|
|
227
|
+
}) {
|
|
228
|
+
if (value === null) return null;
|
|
229
|
+
if (!isValidDate(value)) return "invalidDate";
|
|
230
|
+
const comparableValue = startOfDay(value).getTime();
|
|
231
|
+
const todayStamp = startOfDay(today).getTime();
|
|
232
|
+
if (disablePast && comparableValue < todayStamp) return "disablePast";
|
|
233
|
+
if (disableFuture && comparableValue > todayStamp) return "disableFuture";
|
|
234
|
+
if (minDate && comparableValue < startOfDay(minDate).getTime()) return "minDate";
|
|
235
|
+
if (maxDate && comparableValue > startOfDay(maxDate).getTime()) return "maxDate";
|
|
236
|
+
if (shouldDisableDate?.(value)) return "shouldDisableDate";
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
function resolveTimeValidationError({
|
|
240
|
+
disableFuture = false,
|
|
241
|
+
disablePast = false,
|
|
242
|
+
maxTime,
|
|
243
|
+
minTime,
|
|
244
|
+
shouldDisableTime,
|
|
245
|
+
now = /* @__PURE__ */ new Date(),
|
|
246
|
+
value
|
|
247
|
+
}) {
|
|
248
|
+
if (value === null) return null;
|
|
249
|
+
if (!isValidDate(value)) return "invalidTime";
|
|
250
|
+
if (disablePast && minutesFromDate(value) < minutesFromDate(now)) return "disablePast";
|
|
251
|
+
if (disableFuture && minutesFromDate(value) > minutesFromDate(now)) return "disableFuture";
|
|
252
|
+
if (minTime && minutesFromDate(value) < minutesFromDate(minTime)) return "minTime";
|
|
253
|
+
if (maxTime && minutesFromDate(value) > minutesFromDate(maxTime)) return "maxTime";
|
|
254
|
+
if (shouldDisableTime?.(value)) return "shouldDisableTime";
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
function shouldAllowDate({
|
|
258
|
+
disableFuture,
|
|
259
|
+
disablePast,
|
|
260
|
+
maxDate,
|
|
261
|
+
minDate,
|
|
262
|
+
shouldDisableDate
|
|
263
|
+
}) {
|
|
264
|
+
return (date) => resolveDateValidationError({
|
|
265
|
+
disableFuture,
|
|
266
|
+
disablePast,
|
|
267
|
+
maxDate,
|
|
268
|
+
minDate,
|
|
269
|
+
shouldDisableDate,
|
|
270
|
+
value: date
|
|
271
|
+
}) === null;
|
|
272
|
+
}
|
|
273
|
+
function shouldAllowTime({
|
|
274
|
+
disableFuture,
|
|
275
|
+
disablePast,
|
|
276
|
+
maxTime,
|
|
277
|
+
minTime,
|
|
278
|
+
shouldDisableTime
|
|
279
|
+
}) {
|
|
280
|
+
return (time) => resolveTimeValidationError({
|
|
281
|
+
disableFuture,
|
|
282
|
+
disablePast,
|
|
283
|
+
maxTime,
|
|
284
|
+
minTime,
|
|
285
|
+
shouldDisableTime,
|
|
286
|
+
value: time
|
|
287
|
+
}) === null;
|
|
288
|
+
}
|
|
289
|
+
function minutesFromDate(value) {
|
|
290
|
+
return value.getHours() * 60 + value.getMinutes();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/DatePickersLocalization.ts
|
|
294
|
+
function toPickerDate(adapter, value, name) {
|
|
295
|
+
if (adapter.isValid(value)) {
|
|
296
|
+
const date = adapter.toJsDate(value);
|
|
297
|
+
if (date instanceof Date && Number.isFinite(date.getTime())) return date;
|
|
298
|
+
}
|
|
299
|
+
throw new TypeError(`${name} must be a valid adapter value.`);
|
|
300
|
+
}
|
|
301
|
+
var defaultDatePickerLocaleText = {
|
|
302
|
+
cancelButtonLabel: "Cancel",
|
|
303
|
+
applyButtonLabel: "Apply",
|
|
304
|
+
timeLabel: "Time",
|
|
305
|
+
hoursLabel: "Hours",
|
|
306
|
+
minutesLabel: "Minutes",
|
|
307
|
+
dayPeriodLabel: "AM or PM",
|
|
308
|
+
nowButtonLabel: "Now",
|
|
309
|
+
clearButtonLabel: "Clear",
|
|
310
|
+
datePickerToolbarTitle: "Select date",
|
|
311
|
+
dateTimePickerToolbarTitle: "Select date and time",
|
|
312
|
+
end: "End",
|
|
313
|
+
okButtonLabel: "OK",
|
|
314
|
+
start: "Start",
|
|
315
|
+
timePickerToolbarTitle: "Select time"
|
|
316
|
+
};
|
|
317
|
+
function resolveDatePickerLocaleText(localeText) {
|
|
318
|
+
return {
|
|
319
|
+
...defaultDatePickerLocaleText,
|
|
320
|
+
...localeText
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
var AdapterNativeDate = class {
|
|
324
|
+
constructor(options = {}) {
|
|
325
|
+
this.options = options;
|
|
326
|
+
this.adapterName = "native";
|
|
327
|
+
}
|
|
328
|
+
format(value, formatKey = "short") {
|
|
329
|
+
if (!this.isValid(value)) return "";
|
|
330
|
+
const locale = this.options.locale ?? "en";
|
|
331
|
+
const dateStyle = formatKey === "long" ? "long" : formatKey === "medium" ? "medium" : "short";
|
|
332
|
+
return new Intl.DateTimeFormat(locale, {
|
|
333
|
+
dateStyle,
|
|
334
|
+
timeZone: this.options.timezone
|
|
335
|
+
}).format(value);
|
|
336
|
+
}
|
|
337
|
+
fromJsDate(value) {
|
|
338
|
+
return new Date(value.getTime());
|
|
339
|
+
}
|
|
340
|
+
isEqual(left, right) {
|
|
341
|
+
if (left === null || right === null) return left === right;
|
|
342
|
+
return left.getTime() === right.getTime();
|
|
343
|
+
}
|
|
344
|
+
isValid(value) {
|
|
345
|
+
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
346
|
+
}
|
|
347
|
+
parse(value) {
|
|
348
|
+
const parsed = new Date(value);
|
|
349
|
+
return this.isValid(parsed) ? parsed : null;
|
|
350
|
+
}
|
|
351
|
+
toJsDate(value) {
|
|
352
|
+
return new Date(value.getTime());
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
function createDatePickerAdapter(adapter) {
|
|
356
|
+
return adapter;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/DatePickersAdapters.ts
|
|
360
|
+
var AdapterDateFns = class {
|
|
361
|
+
constructor(options = {}) {
|
|
362
|
+
this.options = options;
|
|
363
|
+
this.adapterName = "date-fns";
|
|
364
|
+
this.runtime = isDateFnsRuntime(options.dateLibInstance) ? options.dateLibInstance : void 0;
|
|
365
|
+
}
|
|
366
|
+
format(value, formatKey = "short") {
|
|
367
|
+
if (!this.isValid(value)) return "";
|
|
368
|
+
const format = resolveUnicodeDateFormat(formatKey);
|
|
369
|
+
return this.runtime?.format ? this.runtime.format(value, format) : formatNativeDate(value, this.options.locale, resolvePickerTimezone(this.options.timezone), formatKey);
|
|
370
|
+
}
|
|
371
|
+
fromJsDate(value) {
|
|
372
|
+
return new Date(value.getTime());
|
|
373
|
+
}
|
|
374
|
+
isEqual(left, right) {
|
|
375
|
+
if (left === null || right === null) return left === right;
|
|
376
|
+
return left.getTime() === right.getTime();
|
|
377
|
+
}
|
|
378
|
+
isValid(value) {
|
|
379
|
+
if (!(value instanceof Date)) return false;
|
|
380
|
+
return this.runtime?.isValid ? this.runtime.isValid(value) : !Number.isNaN(value.getTime());
|
|
381
|
+
}
|
|
382
|
+
parse(value, formatKey = "short") {
|
|
383
|
+
const parsed = this.runtime?.parse ? this.runtime.parse(value, resolveUnicodeDateFormat(formatKey), /* @__PURE__ */ new Date()) : new Date(value);
|
|
384
|
+
return this.isValid(parsed) ? parsed : null;
|
|
385
|
+
}
|
|
386
|
+
toJsDate(value) {
|
|
387
|
+
return new Date(value.getTime());
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var AdapterDayjs = class {
|
|
391
|
+
constructor(options = {}) {
|
|
392
|
+
this.options = options;
|
|
393
|
+
this.adapterName = "dayjs";
|
|
394
|
+
this.dayjs = requireDateLibInstance(options.dateLibInstance, "AdapterDayjs", "dayjs");
|
|
395
|
+
}
|
|
396
|
+
format(value, formatKey = "short") {
|
|
397
|
+
return this.isValid(value) ? value.format(resolveDayjsMomentFormat(formatKey)) : "";
|
|
398
|
+
}
|
|
399
|
+
fromJsDate(value) {
|
|
400
|
+
return this.dayjs(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 isDayjsLike(value) && value.isValid();
|
|
408
|
+
}
|
|
409
|
+
parse(value, formatKey = "short") {
|
|
410
|
+
const parsed = this.dayjs(value, resolveDayjsMomentFormat(formatKey));
|
|
411
|
+
return this.isValid(parsed) ? parsed : null;
|
|
412
|
+
}
|
|
413
|
+
toJsDate(value) {
|
|
414
|
+
return value.toDate();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
var AdapterLuxon = class {
|
|
418
|
+
constructor(options = {}) {
|
|
419
|
+
this.options = options;
|
|
420
|
+
this.adapterName = "luxon";
|
|
421
|
+
this.dateTime = requireDateLibInstance(options.dateLibInstance, "AdapterLuxon", "luxon DateTime");
|
|
422
|
+
}
|
|
423
|
+
format(value, formatKey = "short") {
|
|
424
|
+
return this.isValid(value) ? withLuxonContext(value, this.options).toFormat(resolveLuxonFormat(formatKey)) : "";
|
|
425
|
+
}
|
|
426
|
+
fromJsDate(value) {
|
|
427
|
+
return this.dateTime.fromJSDate(value, getLuxonOptions(this.options));
|
|
428
|
+
}
|
|
429
|
+
isEqual(left, right) {
|
|
430
|
+
if (left === null || right === null) return left === right;
|
|
431
|
+
return getDateValueTime(left) === getDateValueTime(right);
|
|
432
|
+
}
|
|
433
|
+
isValid(value) {
|
|
434
|
+
return isLuxonLike(value) && value.isValid;
|
|
435
|
+
}
|
|
436
|
+
parse(value, formatKey = "short") {
|
|
437
|
+
const format = resolveLuxonFormat(formatKey);
|
|
438
|
+
const parsed = this.dateTime.fromFormat ? this.dateTime.fromFormat(value, format, getLuxonOptions(this.options)) : this.dateTime.fromISO(value, getLuxonOptions(this.options));
|
|
439
|
+
return this.isValid(parsed) ? parsed : null;
|
|
440
|
+
}
|
|
441
|
+
toJsDate(value) {
|
|
442
|
+
return value.toJSDate();
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
var AdapterMoment = class {
|
|
446
|
+
constructor(options = {}) {
|
|
447
|
+
this.options = options;
|
|
448
|
+
this.adapterName = "moment";
|
|
449
|
+
this.moment = requireDateLibInstance(options.dateLibInstance, "AdapterMoment", "moment");
|
|
450
|
+
}
|
|
451
|
+
format(value, formatKey = "short") {
|
|
452
|
+
return this.isValid(value) ? value.format(resolveDayjsMomentFormat(formatKey)) : "";
|
|
453
|
+
}
|
|
454
|
+
fromJsDate(value) {
|
|
455
|
+
return this.moment(value);
|
|
456
|
+
}
|
|
457
|
+
isEqual(left, right) {
|
|
458
|
+
if (left === null || right === null) return left === right;
|
|
459
|
+
return getDateValueTime(left) === getDateValueTime(right);
|
|
460
|
+
}
|
|
461
|
+
isValid(value) {
|
|
462
|
+
return isMomentLike(value) && value.isValid();
|
|
463
|
+
}
|
|
464
|
+
parse(value, formatKey = "short") {
|
|
465
|
+
const parsed = this.moment(value, resolveDayjsMomentFormat(formatKey));
|
|
466
|
+
return this.isValid(parsed) ? parsed : null;
|
|
467
|
+
}
|
|
468
|
+
toJsDate(value) {
|
|
469
|
+
return value.toDate();
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
function requireDateLibInstance(dateLibInstance, adapterName, libraryName) {
|
|
473
|
+
if (!dateLibInstance) {
|
|
474
|
+
throw new Error(`${adapterName} requires ${libraryName} to be passed through DatePickersLocalizationProvider dateLibInstance.`);
|
|
475
|
+
}
|
|
476
|
+
return dateLibInstance;
|
|
477
|
+
}
|
|
478
|
+
function isDateFnsRuntime(value) {
|
|
479
|
+
return typeof value === "object" && value !== null;
|
|
480
|
+
}
|
|
481
|
+
function isDayjsLike(value) {
|
|
482
|
+
return typeof value === "object" && value !== null && typeof value.format === "function" && typeof value.isValid === "function" && typeof value.toDate === "function";
|
|
483
|
+
}
|
|
484
|
+
function isMomentLike(value) {
|
|
485
|
+
return isDayjsLike(value);
|
|
486
|
+
}
|
|
487
|
+
function isLuxonLike(value) {
|
|
488
|
+
return typeof value === "object" && value !== null && typeof value.isValid === "boolean" && typeof value.toFormat === "function" && typeof value.toJSDate === "function";
|
|
489
|
+
}
|
|
490
|
+
function getDateValueTime(value) {
|
|
491
|
+
if (value.toMillis) return value.toMillis();
|
|
492
|
+
const primitiveValue = typeof value.valueOf === "function" ? value.valueOf() : void 0;
|
|
493
|
+
if (typeof primitiveValue === "number") return primitiveValue;
|
|
494
|
+
if (value.toDate) return value.toDate().getTime();
|
|
495
|
+
if (value.toJSDate) return value.toJSDate().getTime();
|
|
496
|
+
return Number.NaN;
|
|
497
|
+
}
|
|
498
|
+
function resolveDayjsMomentFormat(formatKey) {
|
|
499
|
+
if (formatKey === "short") return "L";
|
|
500
|
+
if (formatKey === "medium") return "ll";
|
|
501
|
+
if (formatKey === "long") return "LL";
|
|
502
|
+
return formatKey;
|
|
503
|
+
}
|
|
504
|
+
function resolveLuxonFormat(formatKey) {
|
|
505
|
+
if (formatKey === "short") return "D";
|
|
506
|
+
if (formatKey === "medium") return "DD";
|
|
507
|
+
if (formatKey === "long") return "DDD";
|
|
508
|
+
return formatKey;
|
|
509
|
+
}
|
|
510
|
+
function resolveUnicodeDateFormat(formatKey) {
|
|
511
|
+
if (formatKey === "short") return "P";
|
|
512
|
+
if (formatKey === "medium") return "PP";
|
|
513
|
+
if (formatKey === "long") return "PPP";
|
|
514
|
+
return formatKey;
|
|
515
|
+
}
|
|
516
|
+
function formatNativeDate(value, locale, timezone, formatKey) {
|
|
517
|
+
const dateStyle = formatKey === "long" ? "long" : formatKey === "medium" ? "medium" : "short";
|
|
518
|
+
return new Intl.DateTimeFormat(locale ?? "en", {
|
|
519
|
+
dateStyle,
|
|
520
|
+
timeZone: timezone
|
|
521
|
+
}).format(value);
|
|
522
|
+
}
|
|
523
|
+
function getLuxonOptions(options) {
|
|
524
|
+
return {
|
|
525
|
+
...options.locale ? { locale: options.locale } : {},
|
|
526
|
+
...resolvePickerTimezone(options.timezone) ? { zone: resolvePickerTimezone(options.timezone) } : {}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function withLuxonContext(value, options) {
|
|
530
|
+
let nextValue = value;
|
|
531
|
+
if (options.locale && nextValue.setLocale) {
|
|
532
|
+
nextValue = nextValue.setLocale(options.locale);
|
|
533
|
+
}
|
|
534
|
+
const resolvedTimezone = resolvePickerTimezone(options.timezone);
|
|
535
|
+
if (resolvedTimezone && nextValue.setZone) {
|
|
536
|
+
nextValue = nextValue.setZone(resolvedTimezone);
|
|
537
|
+
}
|
|
538
|
+
return nextValue;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/DatePickersCalendarSystems.ts
|
|
542
|
+
var datePickerCalendarSystemAdapters = [
|
|
543
|
+
{
|
|
544
|
+
adapterName: "date-fns-jalali",
|
|
545
|
+
calendarSystem: "jalali",
|
|
546
|
+
fieldEditing: "supported",
|
|
547
|
+
runtimePackage: "date-fns-jalali"
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
adapterName: "moment-jalaali",
|
|
551
|
+
calendarSystem: "jalali",
|
|
552
|
+
fieldEditing: "supported",
|
|
553
|
+
runtimePackage: "moment-jalaali"
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
adapterName: "moment-hijri",
|
|
557
|
+
calendarSystem: "hijri",
|
|
558
|
+
fieldEditing: "view-only-recommended",
|
|
559
|
+
runtimePackage: "moment-hijri"
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
adapterName: "dayjs-buddhist",
|
|
563
|
+
calendarSystem: "buddhist",
|
|
564
|
+
fieldEditing: "supported",
|
|
565
|
+
runtimePackage: "dayjs"
|
|
566
|
+
}
|
|
567
|
+
];
|
|
568
|
+
var AdapterDateFnsJalali = class extends AdapterDateFns {
|
|
569
|
+
constructor(options = {}) {
|
|
570
|
+
requireCalendarRuntime(options.dateLibInstance, "AdapterDateFnsJalali", "date-fns-jalali");
|
|
571
|
+
super(options);
|
|
572
|
+
this.adapterName = "date-fns-jalali";
|
|
573
|
+
this.calendarSystem = "jalali";
|
|
574
|
+
this.fieldEditing = "supported";
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
var AdapterMomentJalaali = class extends AdapterMoment {
|
|
578
|
+
constructor(options = {}) {
|
|
579
|
+
super({
|
|
580
|
+
...options,
|
|
581
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterMomentJalaali", "moment-jalaali")
|
|
582
|
+
});
|
|
583
|
+
this.adapterName = "moment-jalaali";
|
|
584
|
+
this.calendarSystem = "jalali";
|
|
585
|
+
this.fieldEditing = "supported";
|
|
586
|
+
}
|
|
587
|
+
format(value, formatKey = "short") {
|
|
588
|
+
return this.isValid(value) ? value.format(resolveMomentJalaaliFormat(formatKey)) : "";
|
|
589
|
+
}
|
|
590
|
+
parse(value, formatKey = "short") {
|
|
591
|
+
const parsed = this.createMomentValue(value, resolveMomentJalaaliFormat(formatKey));
|
|
592
|
+
return this.isValid(parsed) ? parsed : null;
|
|
593
|
+
}
|
|
594
|
+
createMomentValue(value, format) {
|
|
595
|
+
const factory = requireCalendarRuntime(
|
|
596
|
+
this.moment,
|
|
597
|
+
"AdapterMomentJalaali",
|
|
598
|
+
"moment-jalaali"
|
|
599
|
+
);
|
|
600
|
+
return factory(value, format);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
var AdapterMomentHijri = class extends AdapterMoment {
|
|
604
|
+
constructor(options = {}) {
|
|
605
|
+
super({
|
|
606
|
+
...options,
|
|
607
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterMomentHijri", "moment-hijri")
|
|
608
|
+
});
|
|
609
|
+
this.adapterName = "moment-hijri";
|
|
610
|
+
this.calendarSystem = "hijri";
|
|
611
|
+
this.fieldEditing = "view-only-recommended";
|
|
612
|
+
}
|
|
613
|
+
format(value, formatKey = "short") {
|
|
614
|
+
return this.isValid(value) ? value.format(resolveMomentHijriFormat(formatKey)) : "";
|
|
615
|
+
}
|
|
616
|
+
parse(value, formatKey = "short") {
|
|
617
|
+
const parsed = this.createMomentValue(value, resolveMomentHijriFormat(formatKey));
|
|
618
|
+
return this.isValid(parsed) ? parsed : null;
|
|
619
|
+
}
|
|
620
|
+
createMomentValue(value, format) {
|
|
621
|
+
const factory = requireCalendarRuntime(
|
|
622
|
+
this.moment,
|
|
623
|
+
"AdapterMomentHijri",
|
|
624
|
+
"moment-hijri"
|
|
625
|
+
);
|
|
626
|
+
return factory(value, format);
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
var AdapterDayjsBuddhist = class extends AdapterDayjs {
|
|
630
|
+
constructor(options = {}) {
|
|
631
|
+
super({
|
|
632
|
+
...options,
|
|
633
|
+
dateLibInstance: requireCalendarRuntime(options.dateLibInstance, "AdapterDayjsBuddhist", "dayjs with buddhistEra plugin")
|
|
634
|
+
});
|
|
635
|
+
this.adapterName = "dayjs-buddhist";
|
|
636
|
+
this.calendarSystem = "buddhist";
|
|
637
|
+
this.fieldEditing = "supported";
|
|
638
|
+
}
|
|
639
|
+
format(value, formatKey = "short") {
|
|
640
|
+
return this.isValid(value) ? value.format(resolveDayjsBuddhistFormat(formatKey)) : "";
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
function isCalendarSystemAdapter(adapter) {
|
|
644
|
+
return typeof adapter.calendarSystem === "string";
|
|
645
|
+
}
|
|
646
|
+
function getDatePickerCalendarSystem(adapter) {
|
|
647
|
+
return isCalendarSystemAdapter(adapter) ? adapter.calendarSystem : "gregory";
|
|
648
|
+
}
|
|
649
|
+
function supportsDatePickerCalendarSystem(calendarSystem) {
|
|
650
|
+
return datePickerCalendarSystemAdapters.some((adapter) => adapter.calendarSystem === calendarSystem) || calendarSystem === "gregory";
|
|
651
|
+
}
|
|
652
|
+
function requireCalendarRuntime(dateLibInstance, adapterName, packageName) {
|
|
653
|
+
if (!dateLibInstance) {
|
|
654
|
+
throw new Error(`${adapterName} requires ${packageName} to be passed through DatePickersLocalizationProvider dateLibInstance.`);
|
|
655
|
+
}
|
|
656
|
+
return dateLibInstance;
|
|
657
|
+
}
|
|
658
|
+
function resolveMomentJalaaliFormat(formatKey) {
|
|
659
|
+
if (formatKey === "short") return "jYYYY/jMM/jDD";
|
|
660
|
+
if (formatKey === "medium") return "jD jMMM jYYYY";
|
|
661
|
+
if (formatKey === "long") return "jD jMMMM jYYYY";
|
|
662
|
+
return formatKey;
|
|
663
|
+
}
|
|
664
|
+
function resolveMomentHijriFormat(formatKey) {
|
|
665
|
+
if (formatKey === "short") return "iYYYY/iMM/iDD";
|
|
666
|
+
if (formatKey === "medium") return "iD iMMM iYYYY";
|
|
667
|
+
if (formatKey === "long") return "iD iMMMM iYYYY";
|
|
668
|
+
return formatKey;
|
|
669
|
+
}
|
|
670
|
+
function resolveDayjsBuddhistFormat(formatKey) {
|
|
671
|
+
if (formatKey === "short") return "BBBB/MM/DD";
|
|
672
|
+
if (formatKey === "medium") return "D MMM BBBB";
|
|
673
|
+
if (formatKey === "long") return "D MMMM BBBB";
|
|
674
|
+
return formatKey;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/DatePickersFormatting.ts
|
|
678
|
+
var RELATIVE_THRESHOLDS = Object.freeze([
|
|
679
|
+
{ limit: 60, milliseconds: 1e3, unit: "second" },
|
|
680
|
+
{ limit: 60, milliseconds: 6e4, unit: "minute" },
|
|
681
|
+
{ limit: 24, milliseconds: 36e5, unit: "hour" },
|
|
682
|
+
{ limit: 7, milliseconds: 864e5, unit: "day" },
|
|
683
|
+
{ limit: 5, milliseconds: 6048e5, unit: "week" },
|
|
684
|
+
{ limit: 12, milliseconds: 2629746e3, unit: "month" },
|
|
685
|
+
{
|
|
686
|
+
limit: Number.POSITIVE_INFINITY,
|
|
687
|
+
milliseconds: 31556952e3,
|
|
688
|
+
unit: "year"
|
|
689
|
+
}
|
|
690
|
+
]);
|
|
691
|
+
function toDatePickerDate(value) {
|
|
692
|
+
const date = value instanceof Date ? new Date(value.getTime()) : new Date(value);
|
|
693
|
+
if (Number.isNaN(date.getTime())) {
|
|
694
|
+
throw new RangeError(`Invalid date value "${String(value)}".`);
|
|
695
|
+
}
|
|
696
|
+
return date;
|
|
697
|
+
}
|
|
698
|
+
function formatDateTime(value, { locale = "en-US", ...options } = {}) {
|
|
699
|
+
return new Intl.DateTimeFormat(
|
|
700
|
+
locale,
|
|
701
|
+
Object.keys(options).length > 0 ? options : { dateStyle: "medium" }
|
|
702
|
+
).format(toDatePickerDate(value));
|
|
703
|
+
}
|
|
704
|
+
function formatDatePattern(value, pattern, locale = "en-US") {
|
|
705
|
+
const date = toDatePickerDate(value);
|
|
706
|
+
if (pattern === "yyyy-MM-dd") {
|
|
707
|
+
return [
|
|
708
|
+
String(date.getFullYear()).padStart(4, "0"),
|
|
709
|
+
String(date.getMonth() + 1).padStart(2, "0"),
|
|
710
|
+
String(date.getDate()).padStart(2, "0")
|
|
711
|
+
].join("-");
|
|
712
|
+
}
|
|
713
|
+
const optionsByPattern = {
|
|
714
|
+
PPpp: { dateStyle: "medium", timeStyle: "short" },
|
|
715
|
+
EEE: { weekday: "short" },
|
|
716
|
+
"EEEE, MMMM d, yyyy": {
|
|
717
|
+
day: "numeric",
|
|
718
|
+
month: "long",
|
|
719
|
+
weekday: "long",
|
|
720
|
+
year: "numeric"
|
|
721
|
+
},
|
|
722
|
+
"MMM d": { day: "numeric", month: "short" },
|
|
723
|
+
"MMM d, h:mm a": {
|
|
724
|
+
day: "numeric",
|
|
725
|
+
hour: "numeric",
|
|
726
|
+
hour12: true,
|
|
727
|
+
minute: "2-digit",
|
|
728
|
+
month: "short"
|
|
729
|
+
},
|
|
730
|
+
"MMM d, yyyy": { day: "numeric", month: "short", year: "numeric" },
|
|
731
|
+
"MMMM d, yyyy": { day: "numeric", month: "long", year: "numeric" },
|
|
732
|
+
"MMMM yyyy": { month: "long", year: "numeric" },
|
|
733
|
+
d: { day: "numeric" },
|
|
734
|
+
"h a": { hour: "numeric", hour12: true },
|
|
735
|
+
"h:mm a": { hour: "numeric", hour12: true, minute: "2-digit" }
|
|
736
|
+
};
|
|
737
|
+
const options = optionsByPattern[pattern];
|
|
738
|
+
if (!options) {
|
|
739
|
+
throw new RangeError(
|
|
740
|
+
`Unsupported Quick Builder date pattern "${pattern}".`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
744
|
+
}
|
|
745
|
+
function formatRelativeTime(value, {
|
|
746
|
+
addSuffix = true,
|
|
747
|
+
locale = "en-US",
|
|
748
|
+
now = Date.now(),
|
|
749
|
+
numeric = "always"
|
|
750
|
+
} = {}) {
|
|
751
|
+
const difference = toDatePickerDate(value).getTime() - toDatePickerDate(now).getTime();
|
|
752
|
+
const absoluteDifference = Math.abs(difference);
|
|
753
|
+
const selected = RELATIVE_THRESHOLDS.find(
|
|
754
|
+
({ limit, milliseconds }) => absoluteDifference < limit * milliseconds
|
|
755
|
+
) ?? RELATIVE_THRESHOLDS[RELATIVE_THRESHOLDS.length - 1];
|
|
756
|
+
const rawValue = difference / selected.milliseconds;
|
|
757
|
+
const roundedValue = rawValue < 0 ? Math.ceil(rawValue) : Math.floor(rawValue);
|
|
758
|
+
const displayValue = roundedValue === 0 && difference !== 0 ? difference < 0 ? -1 : 1 : roundedValue;
|
|
759
|
+
if (addSuffix) {
|
|
760
|
+
return new Intl.RelativeTimeFormat(locale, {
|
|
761
|
+
numeric,
|
|
762
|
+
style: "long"
|
|
763
|
+
}).format(displayValue, selected.unit);
|
|
764
|
+
}
|
|
765
|
+
return new Intl.NumberFormat(locale, {
|
|
766
|
+
style: "unit",
|
|
767
|
+
unit: selected.unit,
|
|
768
|
+
unitDisplay: "long"
|
|
769
|
+
}).format(Math.abs(displayValue));
|
|
770
|
+
}
|
|
771
|
+
function parseIsoDate(value) {
|
|
772
|
+
return toDatePickerDate(value);
|
|
773
|
+
}
|
|
774
|
+
function addCalendarDays(value, amount) {
|
|
775
|
+
const date = toDatePickerDate(value);
|
|
776
|
+
date.setDate(date.getDate() + amount);
|
|
777
|
+
return date;
|
|
778
|
+
}
|
|
779
|
+
function subtractCalendarDays(value, amount) {
|
|
780
|
+
return addCalendarDays(value, -amount);
|
|
781
|
+
}
|
|
782
|
+
function isSameCalendarDay(left, right) {
|
|
783
|
+
const leftDate = toDatePickerDate(left);
|
|
784
|
+
const rightDate = toDatePickerDate(right);
|
|
785
|
+
return leftDate.getFullYear() === rightDate.getFullYear() && leftDate.getMonth() === rightDate.getMonth() && leftDate.getDate() === rightDate.getDate();
|
|
786
|
+
}
|
|
787
|
+
function isDateToday(value, now = Date.now()) {
|
|
788
|
+
return isSameCalendarDay(value, now);
|
|
789
|
+
}
|
|
790
|
+
function isDateYesterday(value, now = Date.now()) {
|
|
791
|
+
return isSameCalendarDay(value, addCalendarDays(now, -1));
|
|
792
|
+
}
|
|
793
|
+
function isDateThisWeek(value, {
|
|
794
|
+
now = Date.now(),
|
|
795
|
+
weekStartsOn = 0
|
|
796
|
+
} = {}) {
|
|
797
|
+
if (!Number.isInteger(weekStartsOn) || weekStartsOn < 0 || weekStartsOn > 6) {
|
|
798
|
+
throw new RangeError("weekStartsOn must be an integer from 0 through 6.");
|
|
799
|
+
}
|
|
800
|
+
const reference = toDatePickerDate(now);
|
|
801
|
+
const start = new Date(
|
|
802
|
+
reference.getFullYear(),
|
|
803
|
+
reference.getMonth(),
|
|
804
|
+
reference.getDate()
|
|
805
|
+
);
|
|
806
|
+
start.setDate(start.getDate() - (start.getDay() - weekStartsOn + 7) % 7);
|
|
807
|
+
const end = addCalendarDays(start, 7);
|
|
808
|
+
const candidate = toDatePickerDate(value).getTime();
|
|
809
|
+
return candidate >= start.getTime() && candidate < end.getTime();
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// src/DatePickers.storage.ts
|
|
813
|
+
function assertDate(value, basis = "local") {
|
|
814
|
+
if (!(value instanceof Date) || !Number.isFinite(value.getTime()))
|
|
815
|
+
throw new TypeError("Invalid picker date");
|
|
816
|
+
const year = basis === "utc" ? value.getUTCFullYear() : value.getFullYear();
|
|
817
|
+
if (year < 1 || year > 9999) throw new TypeError("Invalid picker date");
|
|
818
|
+
}
|
|
819
|
+
var pad = (value, width = 2) => String(value).padStart(width, "0");
|
|
820
|
+
function serializePickerDate(value) {
|
|
821
|
+
assertDate(value);
|
|
822
|
+
return {
|
|
823
|
+
version: 1,
|
|
824
|
+
kind: "date",
|
|
825
|
+
date: `${pad(value.getFullYear(), 4)}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function serializePickerTime(value) {
|
|
829
|
+
assertDate(value);
|
|
830
|
+
if (value.getSeconds() || value.getMilliseconds())
|
|
831
|
+
throw new Error("Time picker storage requires minute precision");
|
|
832
|
+
return {
|
|
833
|
+
version: 1,
|
|
834
|
+
kind: "time",
|
|
835
|
+
time: `${pad(value.getHours())}:${pad(value.getMinutes())}`
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
function serializePickerDateTime(value, timezone) {
|
|
839
|
+
assertDate(value, "utc");
|
|
840
|
+
if (!timezone || timezone === "system" || timezone === "default")
|
|
841
|
+
throw new Error("Persist an explicit display timezone");
|
|
842
|
+
assertSupportedTimezone(timezone);
|
|
843
|
+
return {
|
|
844
|
+
version: 1,
|
|
845
|
+
kind: "dateTime",
|
|
846
|
+
instant: value.toISOString(),
|
|
847
|
+
timezone
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
function parseStoredPickerValue(input) {
|
|
851
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
852
|
+
throw new TypeError("Expected picker storage schema version 1");
|
|
853
|
+
const value = Object.getOwnPropertyDescriptors(input);
|
|
854
|
+
if (Object.values(value).some((property) => !("value" in property)))
|
|
855
|
+
throw new TypeError("Picker storage must contain JSON values");
|
|
856
|
+
const record = Object.fromEntries(
|
|
857
|
+
Object.entries(value).map(([key, descriptor]) => [key, descriptor.value])
|
|
858
|
+
);
|
|
859
|
+
const fields = record.kind === "date" ? ["version", "kind", "date"] : record.kind === "time" ? ["version", "kind", "time"] : ["version", "kind", "instant", "timezone"];
|
|
860
|
+
if (record.version !== 1 || Object.keys(record).length !== fields.length || Object.keys(record).some((key) => !fields.includes(key)))
|
|
861
|
+
throw new TypeError("Invalid picker storage fields");
|
|
862
|
+
if (record.kind === "date" && typeof record.date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(record.date)) {
|
|
863
|
+
const [year, month, day] = record.date.split("-").map(Number);
|
|
864
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
865
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
866
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
867
|
+
if (year >= 1 && date.toISOString().slice(0, 10) === record.date)
|
|
868
|
+
return { version: 1, kind: "date", date: record.date };
|
|
869
|
+
}
|
|
870
|
+
if (record.kind === "time" && typeof record.time === "string" && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(record.time))
|
|
871
|
+
return { version: 1, kind: "time", time: record.time };
|
|
872
|
+
if (record.kind === "dateTime" && typeof record.instant === "string" && typeof record.timezone === "string") {
|
|
873
|
+
const date = new Date(record.instant);
|
|
874
|
+
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)
|
|
875
|
+
return serializePickerDateTime(date, record.timezone);
|
|
876
|
+
}
|
|
877
|
+
throw new TypeError("Invalid stored picker value");
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/core.ts
|
|
881
|
+
var datePickersPackageManifest = {
|
|
882
|
+
packageName: "@quickbuilder.io/date-pickers",
|
|
883
|
+
displayName: "Quick Builder Date Pickers",
|
|
884
|
+
family: "date-pickers",
|
|
885
|
+
tier: "community",
|
|
886
|
+
designSystemDependency: "@quickbuilder.io/design-system",
|
|
887
|
+
status: "implemented"
|
|
888
|
+
};
|
|
889
|
+
var packageManifest = datePickersPackageManifest;
|
|
890
|
+
|
|
891
|
+
export { AdapterDateFns, AdapterDateFnsJalali, AdapterDayjs, AdapterDayjsBuddhist, AdapterLuxon, AdapterMoment, AdapterMomentHijri, AdapterMomentJalaali, AdapterNativeDate, addCalendarDays, addZonedCalendarDays, assertSupportedTimezone, cloneDate2 as cloneDate, createDatePickerAdapter, datePickerCalendarSystemAdapters, datePickerCapabilityFeatureIds, datePickerCapabilityFeatures, datePickersFrameworkAdapterSupport, datePickersPackageManifest, defaultDatePickerLocaleText, formatDatePattern, formatDateTime, formatRelativeTime, frameworkAdapterSupport, fromTimezoneDisplayDate, getDatePickerCalendarSystem, getSystemTimezone, getZonedCivilTimestamp, isCalendarSystemAdapter, isDateThisWeek, isDateToday, isDateYesterday, isSameCalendarDay, isValidDate, mergeDateAndTime, minutesFromDate, packageManifest, parseIsoDate, parseStoredPickerValue, resolveDatePickerLocale, resolveDatePickerLocaleText, resolveDateTimeInstant, resolveDateValidationError, resolvePickerTimezone, resolveTimeValidationError, resolveZonedCivilTimestamp, serializePickerDate, serializePickerDateTime, serializePickerTime, shouldAllowDate, shouldAllowTime, startOfDay, subtractCalendarDays, supportsDatePickerCalendarSystem, toDatePickerDate, toPickerDate, toTimezoneDisplayDate };
|
|
892
|
+
//# sourceMappingURL=index.mjs.map
|
|
893
|
+
//# sourceMappingURL=index.mjs.map
|