@mantine-vue/dates 1.1.2
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/cjs/index.cjs +2337 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/index.mjs +2252 -0
- package/esm/index.mjs.map +1 -0
- package/lib/index.d.mts +2669 -0
- package/lib/index.d.ts +2669 -0
- package/package.json +48 -0
- package/styles.css +518 -0
- package/styles.layer.css +520 -0
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,2337 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let dayjs = require("dayjs");
|
|
25
|
+
dayjs = __toESM(dayjs);
|
|
26
|
+
let dayjs_plugin_customParseFormat = require("dayjs/plugin/customParseFormat");
|
|
27
|
+
dayjs_plugin_customParseFormat = __toESM(dayjs_plugin_customParseFormat);
|
|
28
|
+
let vue = require("vue");
|
|
29
|
+
let _mantine_vue_hooks = require("@mantine-vue/hooks");
|
|
30
|
+
let _mantine_vue_core = require("@mantine-vue/core");
|
|
31
|
+
var Dates_module_default = {
|
|
32
|
+
calendar: "_calendar_5kwje_1",
|
|
33
|
+
calendarLevel: "_calendarLevel_5kwje_15",
|
|
34
|
+
calendarHeader: "_calendarHeader_5kwje_19",
|
|
35
|
+
calendarHeaderLevel: "_calendarHeaderLevel_5kwje_32",
|
|
36
|
+
calendarHeaderControl: "_calendarHeaderControl_5kwje_33",
|
|
37
|
+
calendarHeaderControlIcon: "_calendarHeaderControlIcon_5kwje_74",
|
|
38
|
+
month: "_month_5kwje_87",
|
|
39
|
+
monthRow: "_monthRow_5kwje_97",
|
|
40
|
+
monthCell: "_monthCell_5kwje_101",
|
|
41
|
+
weekday: "_weekday_5kwje_110",
|
|
42
|
+
weekNumber: "_weekNumber_5kwje_122",
|
|
43
|
+
day: "_day_5kwje_128",
|
|
44
|
+
pickerControl: "_pickerControl_5kwje_189",
|
|
45
|
+
controlsGrid: "_controlsGrid_5kwje_195",
|
|
46
|
+
timePicker: "_timePicker_5kwje_255",
|
|
47
|
+
dateTimePicker: "_dateTimePicker_5kwje_256",
|
|
48
|
+
datePickerRoot: "_datePickerRoot_5kwje_260",
|
|
49
|
+
timeWrapper: "_timeWrapper_5kwje_270",
|
|
50
|
+
timeInput: "_timeInput_5kwje_276",
|
|
51
|
+
presetsList: "_presetsList_5kwje_281",
|
|
52
|
+
presetButton: "_presetButton_5kwje_289",
|
|
53
|
+
timePickerPresetsGroup: "_timePickerPresetsGroup_5kwje_300",
|
|
54
|
+
dropdown: "_dropdown_5kwje_304",
|
|
55
|
+
placeholder: "_placeholder_5kwje_308",
|
|
56
|
+
timeGridControl: "_timeGridControl_5kwje_312",
|
|
57
|
+
timePickerFieldsRoot: "_timePickerFieldsRoot_5kwje_343",
|
|
58
|
+
timePickerFieldsGroup: "_timePickerFieldsGroup_5kwje_350",
|
|
59
|
+
timePickerField: "_timePickerField_5kwje_343",
|
|
60
|
+
timePickerDropdown: "_timePickerDropdown_5kwje_400",
|
|
61
|
+
timePickerControlsListGroup: "_timePickerControlsListGroup_5kwje_404",
|
|
62
|
+
timePickerControlsList: "_timePickerControlsList_5kwje_404",
|
|
63
|
+
timePickerControl: "_timePickerControl_5kwje_404",
|
|
64
|
+
miniCalendarRoot: "_miniCalendarRoot_5kwje_433",
|
|
65
|
+
miniCalendarDays: "_miniCalendarDays_5kwje_440",
|
|
66
|
+
miniCalendarDay: "_miniCalendarDay_5kwje_440",
|
|
67
|
+
miniCalendarDayMonth: "_miniCalendarDayMonth_5kwje_475",
|
|
68
|
+
miniCalendarDayNumber: "_miniCalendarDayNumber_5kwje_481",
|
|
69
|
+
miniCalendarControl: "_miniCalendarControl_5kwje_486"
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/index.ts
|
|
73
|
+
dayjs.default.extend(dayjs_plugin_customParseFormat.default);
|
|
74
|
+
var DATES_PROVIDER_DEFAULT_SETTINGS = {
|
|
75
|
+
locale: "en",
|
|
76
|
+
firstDayOfWeek: 1,
|
|
77
|
+
weekendDays: [0, 6],
|
|
78
|
+
timezone: "UTC",
|
|
79
|
+
consistentWeeks: false
|
|
80
|
+
};
|
|
81
|
+
var DatesContextKey = Symbol("DatesContext");
|
|
82
|
+
var DatesProvider = (0, vue.defineComponent)({
|
|
83
|
+
name: "DatesProvider",
|
|
84
|
+
props: { settings: {
|
|
85
|
+
type: Object,
|
|
86
|
+
default: () => ({})
|
|
87
|
+
} },
|
|
88
|
+
setup(props, { slots }) {
|
|
89
|
+
const settings = (0, vue.computed)(() => ({
|
|
90
|
+
...DATES_PROVIDER_DEFAULT_SETTINGS,
|
|
91
|
+
...props.settings
|
|
92
|
+
}));
|
|
93
|
+
(0, vue.provide)(DatesContextKey, settings.value);
|
|
94
|
+
(0, vue.watch)(settings, (value) => (0, vue.provide)(DatesContextKey, value));
|
|
95
|
+
return () => slots.default?.();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
function useDatesContext() {
|
|
99
|
+
return (0, vue.inject)(DatesContextKey, DATES_PROVIDER_DEFAULT_SETTINGS);
|
|
100
|
+
}
|
|
101
|
+
function normalizeDate(value) {
|
|
102
|
+
if (value == null || value === "") return null;
|
|
103
|
+
const parsed = (0, dayjs.default)(value);
|
|
104
|
+
return parsed.isValid() ? parsed.format("YYYY-MM-DD") : null;
|
|
105
|
+
}
|
|
106
|
+
function toDateString(value) {
|
|
107
|
+
return normalizeDate(value);
|
|
108
|
+
}
|
|
109
|
+
function shiftTimezone(direction, date, timezone) {
|
|
110
|
+
return date;
|
|
111
|
+
}
|
|
112
|
+
function getTimezoneOffset(date, timezone) {
|
|
113
|
+
return new Date(date).getTimezoneOffset();
|
|
114
|
+
}
|
|
115
|
+
function clampDate(date, minDate, maxDate) {
|
|
116
|
+
const value = (0, dayjs.default)(date);
|
|
117
|
+
const min = normalizeDate(minDate);
|
|
118
|
+
const max = normalizeDate(maxDate);
|
|
119
|
+
if (min && value.isBefore(min, "day")) return min;
|
|
120
|
+
if (max && value.isAfter(max, "day")) return max;
|
|
121
|
+
return value.format("YYYY-MM-DD");
|
|
122
|
+
}
|
|
123
|
+
function getDefaultClampedDate({ minDate, maxDate, defaultDate } = {}) {
|
|
124
|
+
return clampDate(normalizeDate(defaultDate) || (0, dayjs.default)().format("YYYY-MM-DD"), minDate, maxDate);
|
|
125
|
+
}
|
|
126
|
+
function assignTime(date, time) {
|
|
127
|
+
const timeValue = (0, dayjs.default)(time);
|
|
128
|
+
return (0, dayjs.default)(date).hour(timeValue.hour()).minute(timeValue.minute()).second(timeValue.second()).millisecond(timeValue.millisecond()).toDate();
|
|
129
|
+
}
|
|
130
|
+
function getFormattedDate({ date, format = "MMMM D, YYYY", locale }) {
|
|
131
|
+
return (0, dayjs.default)(date).locale(locale || "en").format(format);
|
|
132
|
+
}
|
|
133
|
+
function isSameDate(a, b) {
|
|
134
|
+
if (!a || !b) return false;
|
|
135
|
+
return (0, dayjs.default)(a).isSame(b, "day");
|
|
136
|
+
}
|
|
137
|
+
function isSameMonth(a, b) {
|
|
138
|
+
return (0, dayjs.default)(a).isSame(b, "month");
|
|
139
|
+
}
|
|
140
|
+
function isSameYear(a, b) {
|
|
141
|
+
return (0, dayjs.default)(a).isSame(b, "year");
|
|
142
|
+
}
|
|
143
|
+
function getStartOfWeek(date, firstDayOfWeek = 1) {
|
|
144
|
+
const value = (0, dayjs.default)(date);
|
|
145
|
+
const diff = (value.day() - firstDayOfWeek + 7) % 7;
|
|
146
|
+
return value.subtract(diff, "day").format("YYYY-MM-DD");
|
|
147
|
+
}
|
|
148
|
+
function getEndOfWeek(date, firstDayOfWeek = 1) {
|
|
149
|
+
return (0, dayjs.default)(getStartOfWeek(date, firstDayOfWeek)).add(6, "day").format("YYYY-MM-DD");
|
|
150
|
+
}
|
|
151
|
+
function getWeekNumber(date) {
|
|
152
|
+
const current = (0, dayjs.default)(date);
|
|
153
|
+
const yearStart = (0, dayjs.default)(`${current.year()}-01-01`);
|
|
154
|
+
return Math.ceil((current.diff(yearStart, "day") + yearStart.day() + 1) / 7);
|
|
155
|
+
}
|
|
156
|
+
function handleControlKeyDown({ rowIndex, cellIndex, event, controlsRef }) {
|
|
157
|
+
const rows = controlsRef.length;
|
|
158
|
+
const cols = controlsRef[0]?.length || 0;
|
|
159
|
+
let nextRow = rowIndex;
|
|
160
|
+
let nextCell = cellIndex;
|
|
161
|
+
if (event.key === "ArrowRight") nextCell += 1;
|
|
162
|
+
if (event.key === "ArrowLeft") nextCell -= 1;
|
|
163
|
+
if (event.key === "ArrowDown") nextRow += 1;
|
|
164
|
+
if (event.key === "ArrowUp") nextRow -= 1;
|
|
165
|
+
if (event.key === "Home") nextCell = 0;
|
|
166
|
+
if (event.key === "End") nextCell = cols - 1;
|
|
167
|
+
if (nextCell < 0) {
|
|
168
|
+
nextCell = cols - 1;
|
|
169
|
+
nextRow -= 1;
|
|
170
|
+
}
|
|
171
|
+
if (nextCell >= cols) {
|
|
172
|
+
nextCell = 0;
|
|
173
|
+
nextRow += 1;
|
|
174
|
+
}
|
|
175
|
+
const next = controlsRef[(nextRow + rows) % rows]?.[(nextCell + cols) % cols];
|
|
176
|
+
if (next) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
next.focus();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function focusAdjacentControl(refs, rowIndex, cellIndex, direction) {
|
|
182
|
+
const isFocusable = (el) => !!el && !el.disabled && !el.hasAttribute("data-hidden") && !el.hasAttribute("data-outside");
|
|
183
|
+
let nextRow = rowIndex;
|
|
184
|
+
let nextCell = cellIndex;
|
|
185
|
+
for (let i = 0; i < 60; i += 1) {
|
|
186
|
+
if (direction === "up") nextRow -= 1;
|
|
187
|
+
if (direction === "down") nextRow += 1;
|
|
188
|
+
if (direction === "left") {
|
|
189
|
+
nextCell -= 1;
|
|
190
|
+
if (nextCell < 0) {
|
|
191
|
+
nextRow -= 1;
|
|
192
|
+
nextCell = (refs[nextRow]?.length || 1) - 1;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (direction === "right") {
|
|
196
|
+
nextCell += 1;
|
|
197
|
+
if (nextCell >= (refs[nextRow]?.length || 0)) {
|
|
198
|
+
nextRow += 1;
|
|
199
|
+
nextCell = 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const row = refs[nextRow];
|
|
203
|
+
if (!row) return;
|
|
204
|
+
const el = row[nextCell];
|
|
205
|
+
if (el === void 0) return;
|
|
206
|
+
if (isFocusable(el)) {
|
|
207
|
+
el.focus();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function keyToDirection(key) {
|
|
213
|
+
if (key === "ArrowUp") return "up";
|
|
214
|
+
if (key === "ArrowDown") return "down";
|
|
215
|
+
if (key === "ArrowLeft") return "left";
|
|
216
|
+
if (key === "ArrowRight") return "right";
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
function setGridRef(refs, rowIndex, cellIndex, node) {
|
|
220
|
+
if (!refs[rowIndex]) refs[rowIndex] = [];
|
|
221
|
+
refs[rowIndex][cellIndex] = node?.$el ?? node ?? void 0;
|
|
222
|
+
}
|
|
223
|
+
function getMonthDays(month, firstDayOfWeek, consistentWeeks = false) {
|
|
224
|
+
const startOfMonth = (0, dayjs.default)(month).startOf("month");
|
|
225
|
+
const start = (0, dayjs.default)(getStartOfWeek(startOfMonth.format("YYYY-MM-DD"), firstDayOfWeek));
|
|
226
|
+
const weeks = consistentWeeks ? 6 : Math.ceil((startOfMonth.daysInMonth() + startOfMonth.day()) / 7);
|
|
227
|
+
return Array.from({ length: weeks }, (_, week) => Array.from({ length: 7 }, (__, day) => start.add(week * 7 + day, "day").format("YYYY-MM-DD")));
|
|
228
|
+
}
|
|
229
|
+
function isBeforeMin(date, minDate) {
|
|
230
|
+
const min = normalizeDate(minDate);
|
|
231
|
+
return !!min && (0, dayjs.default)(date).isBefore(min, "day");
|
|
232
|
+
}
|
|
233
|
+
function isAfterMax(date, maxDate) {
|
|
234
|
+
const max = normalizeDate(maxDate);
|
|
235
|
+
return !!max && (0, dayjs.default)(date).isAfter(max, "day");
|
|
236
|
+
}
|
|
237
|
+
function formatValue(value, type, format, locale, labelSeparator = "–", valueFormatter) {
|
|
238
|
+
if (valueFormatter) return valueFormatter({
|
|
239
|
+
type,
|
|
240
|
+
date: value,
|
|
241
|
+
locale,
|
|
242
|
+
format,
|
|
243
|
+
labelSeparator
|
|
244
|
+
});
|
|
245
|
+
if (type === "multiple") return Array.isArray(value) ? value.map((item) => (0, dayjs.default)(item).locale(locale || "en").format(format)).join(", ") : "";
|
|
246
|
+
if (type === "range") {
|
|
247
|
+
const [start, end] = Array.isArray(value) ? value : [null, null];
|
|
248
|
+
if (!start && !end) return "";
|
|
249
|
+
if (start && !end) return `${(0, dayjs.default)(start).locale(locale || "en").format(format)} ${labelSeparator} `;
|
|
250
|
+
if (!start && end) return `${labelSeparator} ${(0, dayjs.default)(end).locale(locale || "en").format(format)}`;
|
|
251
|
+
return `${(0, dayjs.default)(start).locale(locale || "en").format(format)} ${labelSeparator} ${(0, dayjs.default)(end).locale(locale || "en").format(format)}`;
|
|
252
|
+
}
|
|
253
|
+
return value ? (0, dayjs.default)(value).locale(locale || "en").format(format) : "";
|
|
254
|
+
}
|
|
255
|
+
function getMonthLabel(date, format = "MMMM YYYY", locale) {
|
|
256
|
+
return (0, dayjs.default)(date).locale(locale || "en").format(format);
|
|
257
|
+
}
|
|
258
|
+
function getYearRange(date) {
|
|
259
|
+
const year = (0, dayjs.default)(date).year();
|
|
260
|
+
const start = year - year % 10;
|
|
261
|
+
return Array.from({ length: 10 }, (_, index) => (0, dayjs.default)(`${start + index}-01-01`).format("YYYY-MM-DD"));
|
|
262
|
+
}
|
|
263
|
+
function getDecadeLabel(date) {
|
|
264
|
+
const years = getYearRange(date);
|
|
265
|
+
return `${(0, dayjs.default)(years[0]).year()} – ${(0, dayjs.default)(years[years.length - 1]).year()}`;
|
|
266
|
+
}
|
|
267
|
+
var Day = (0, vue.defineComponent)({
|
|
268
|
+
name: "Day",
|
|
269
|
+
inheritAttrs: false,
|
|
270
|
+
props: {
|
|
271
|
+
date: {
|
|
272
|
+
type: String,
|
|
273
|
+
required: true
|
|
274
|
+
},
|
|
275
|
+
size: {
|
|
276
|
+
type: [String, Number],
|
|
277
|
+
default: "sm"
|
|
278
|
+
},
|
|
279
|
+
static: {
|
|
280
|
+
type: Boolean,
|
|
281
|
+
default: false
|
|
282
|
+
},
|
|
283
|
+
weekend: Boolean,
|
|
284
|
+
outside: Boolean,
|
|
285
|
+
selected: Boolean,
|
|
286
|
+
hidden: Boolean,
|
|
287
|
+
inRange: Boolean,
|
|
288
|
+
firstInRange: Boolean,
|
|
289
|
+
lastInRange: Boolean,
|
|
290
|
+
highlightToday: Boolean,
|
|
291
|
+
fullWidth: Boolean,
|
|
292
|
+
disabled: Boolean,
|
|
293
|
+
renderDay: Function,
|
|
294
|
+
classNames: {
|
|
295
|
+
type: [Object, Function],
|
|
296
|
+
default: void 0
|
|
297
|
+
},
|
|
298
|
+
styles: {
|
|
299
|
+
type: [Object, Function],
|
|
300
|
+
default: void 0
|
|
301
|
+
},
|
|
302
|
+
unstyled: Boolean
|
|
303
|
+
},
|
|
304
|
+
setup(props, { attrs }) {
|
|
305
|
+
return () => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
306
|
+
...attrs,
|
|
307
|
+
component: props.static ? "div" : "button",
|
|
308
|
+
class: [Dates_module_default.day, attrs.class],
|
|
309
|
+
disabled: props.disabled,
|
|
310
|
+
style: [{ display: props.hidden ? "none" : void 0 }, attrs.style],
|
|
311
|
+
"data-today": (0, dayjs.default)(props.date).isSame(/* @__PURE__ */ new Date(), "day") || void 0,
|
|
312
|
+
"data-hidden": props.hidden || void 0,
|
|
313
|
+
"data-highlight-today": props.highlightToday || void 0,
|
|
314
|
+
"data-disabled": props.disabled || void 0,
|
|
315
|
+
"data-weekend": !props.disabled && !props.outside && props.weekend || void 0,
|
|
316
|
+
"data-outside": !props.disabled && props.outside || void 0,
|
|
317
|
+
"data-selected": !props.disabled && props.selected || void 0,
|
|
318
|
+
"data-in-range": props.inRange && !props.disabled || void 0,
|
|
319
|
+
"data-first-in-range": props.firstInRange && !props.disabled || void 0,
|
|
320
|
+
"data-last-in-range": props.lastInRange && !props.disabled || void 0,
|
|
321
|
+
"data-static": props.static || void 0,
|
|
322
|
+
"data-full-width": props.fullWidth || void 0
|
|
323
|
+
}, () => props.renderDay?.(props.date) || (0, dayjs.default)(props.date).date());
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
var PickerControl = (0, vue.defineComponent)({
|
|
327
|
+
name: "PickerControl",
|
|
328
|
+
inheritAttrs: false,
|
|
329
|
+
props: {
|
|
330
|
+
selected: Boolean,
|
|
331
|
+
disabled: Boolean,
|
|
332
|
+
inRange: Boolean,
|
|
333
|
+
firstInRange: Boolean,
|
|
334
|
+
lastInRange: Boolean,
|
|
335
|
+
withCellSpacing: {
|
|
336
|
+
type: Boolean,
|
|
337
|
+
default: true
|
|
338
|
+
},
|
|
339
|
+
fullWidth: Boolean
|
|
340
|
+
},
|
|
341
|
+
setup(props, { attrs, slots }) {
|
|
342
|
+
return () => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
343
|
+
...attrs,
|
|
344
|
+
class: [Dates_module_default.pickerControl, attrs.class],
|
|
345
|
+
disabled: props.disabled,
|
|
346
|
+
"data-selected": props.selected && !props.disabled || void 0,
|
|
347
|
+
"data-disabled": props.disabled || void 0,
|
|
348
|
+
"data-in-range": props.inRange && !props.disabled && !props.selected || void 0,
|
|
349
|
+
"data-first-in-range": props.firstInRange && !props.disabled || void 0,
|
|
350
|
+
"data-last-in-range": props.lastInRange && !props.disabled || void 0,
|
|
351
|
+
"data-with-cell-spacing": props.withCellSpacing || void 0,
|
|
352
|
+
"data-full-width": props.fullWidth || void 0
|
|
353
|
+
}, () => slots.default?.());
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
var CalendarHeader = (0, vue.defineComponent)({
|
|
357
|
+
name: "CalendarHeader",
|
|
358
|
+
props: {
|
|
359
|
+
label: {
|
|
360
|
+
type: String,
|
|
361
|
+
required: true
|
|
362
|
+
},
|
|
363
|
+
hasNextLevel: {
|
|
364
|
+
type: Boolean,
|
|
365
|
+
default: true
|
|
366
|
+
},
|
|
367
|
+
withNext: {
|
|
368
|
+
type: Boolean,
|
|
369
|
+
default: true
|
|
370
|
+
},
|
|
371
|
+
withPrevious: {
|
|
372
|
+
type: Boolean,
|
|
373
|
+
default: true
|
|
374
|
+
},
|
|
375
|
+
nextDisabled: Boolean,
|
|
376
|
+
previousDisabled: Boolean,
|
|
377
|
+
nextLabel: {
|
|
378
|
+
type: String,
|
|
379
|
+
default: "Next"
|
|
380
|
+
},
|
|
381
|
+
previousLabel: {
|
|
382
|
+
type: String,
|
|
383
|
+
default: "Previous"
|
|
384
|
+
},
|
|
385
|
+
levelControlAriaLabel: String,
|
|
386
|
+
fullWidth: Boolean,
|
|
387
|
+
onNext: Function,
|
|
388
|
+
onPrevious: Function,
|
|
389
|
+
onLevelClick: Function
|
|
390
|
+
},
|
|
391
|
+
setup(props) {
|
|
392
|
+
return () => {
|
|
393
|
+
const previousControl = props.withPrevious ? (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
394
|
+
class: Dates_module_default.calendarHeaderControl,
|
|
395
|
+
"data-direction": "previous",
|
|
396
|
+
"aria-label": props.previousLabel,
|
|
397
|
+
onClick: props.onPrevious,
|
|
398
|
+
disabled: props.previousDisabled,
|
|
399
|
+
"data-disabled": props.previousDisabled || void 0
|
|
400
|
+
}, () => (0, vue.h)(_mantine_vue_core.AccordionChevron, {
|
|
401
|
+
class: Dates_module_default.calendarHeaderControlIcon,
|
|
402
|
+
"data-direction": "previous",
|
|
403
|
+
size: "45%"
|
|
404
|
+
})) : null;
|
|
405
|
+
const levelControl = (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
406
|
+
component: props.hasNextLevel ? "button" : "div",
|
|
407
|
+
class: Dates_module_default.calendarHeaderLevel,
|
|
408
|
+
onClick: props.hasNextLevel ? props.onLevelClick : void 0,
|
|
409
|
+
disabled: !props.hasNextLevel,
|
|
410
|
+
"data-static": !props.hasNextLevel || void 0,
|
|
411
|
+
"aria-label": props.levelControlAriaLabel
|
|
412
|
+
}, () => props.label);
|
|
413
|
+
const nextControl = props.withNext ? (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
414
|
+
class: Dates_module_default.calendarHeaderControl,
|
|
415
|
+
"data-direction": "next",
|
|
416
|
+
"aria-label": props.nextLabel,
|
|
417
|
+
onClick: props.onNext,
|
|
418
|
+
disabled: props.nextDisabled,
|
|
419
|
+
"data-disabled": props.nextDisabled || void 0
|
|
420
|
+
}, () => (0, vue.h)(_mantine_vue_core.AccordionChevron, {
|
|
421
|
+
class: Dates_module_default.calendarHeaderControlIcon,
|
|
422
|
+
"data-direction": "next",
|
|
423
|
+
size: "45%"
|
|
424
|
+
})) : null;
|
|
425
|
+
return (0, vue.h)("div", {
|
|
426
|
+
class: Dates_module_default.calendarHeader,
|
|
427
|
+
"data-full-width": props.fullWidth || void 0
|
|
428
|
+
}, [
|
|
429
|
+
previousControl,
|
|
430
|
+
levelControl,
|
|
431
|
+
nextControl
|
|
432
|
+
]);
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
var WeekdaysRow = (0, vue.defineComponent)({
|
|
437
|
+
name: "WeekdaysRow",
|
|
438
|
+
props: {
|
|
439
|
+
firstDayOfWeek: Number,
|
|
440
|
+
weekendDays: Array,
|
|
441
|
+
locale: String,
|
|
442
|
+
weekdayFormat: {
|
|
443
|
+
type: [String, Function],
|
|
444
|
+
default: "dd"
|
|
445
|
+
},
|
|
446
|
+
withWeekNumbers: Boolean
|
|
447
|
+
},
|
|
448
|
+
setup(props) {
|
|
449
|
+
const ctx = useDatesContext();
|
|
450
|
+
return () => {
|
|
451
|
+
const first = props.firstDayOfWeek ?? ctx.firstDayOfWeek;
|
|
452
|
+
const days = Array.from({ length: 7 }, (_, index) => (0, dayjs.default)("2024-01-07").add((first + index) % 7, "day"));
|
|
453
|
+
return (0, vue.h)("tr", { class: Dates_module_default.weekdaysRow }, [props.withWeekNumbers ? (0, vue.h)("th", { class: Dates_module_default.weekday }) : null, ...days.map((date) => (0, vue.h)("th", {
|
|
454
|
+
class: Dates_module_default.weekday,
|
|
455
|
+
"data-weekend": (props.weekendDays ?? ctx.weekendDays).includes(date.day()) || void 0
|
|
456
|
+
}, typeof props.weekdayFormat === "function" ? props.weekdayFormat(date.format("YYYY-MM-DD")) : date.locale(props.locale || ctx.locale).format(props.weekdayFormat)))]);
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
var Month = (0, vue.defineComponent)({
|
|
461
|
+
name: "Month",
|
|
462
|
+
props: {
|
|
463
|
+
month: {
|
|
464
|
+
type: String,
|
|
465
|
+
default: () => (0, dayjs.default)().format("YYYY-MM-DD")
|
|
466
|
+
},
|
|
467
|
+
value: {
|
|
468
|
+
type: [
|
|
469
|
+
String,
|
|
470
|
+
Array,
|
|
471
|
+
null
|
|
472
|
+
],
|
|
473
|
+
default: null
|
|
474
|
+
},
|
|
475
|
+
type: {
|
|
476
|
+
type: String,
|
|
477
|
+
default: "default"
|
|
478
|
+
},
|
|
479
|
+
firstDayOfWeek: Number,
|
|
480
|
+
weekendDays: Array,
|
|
481
|
+
minDate: [String, Date],
|
|
482
|
+
maxDate: [String, Date],
|
|
483
|
+
excludeDate: Function,
|
|
484
|
+
renderDay: Function,
|
|
485
|
+
hideOutsideDates: Boolean,
|
|
486
|
+
hideWeekdays: Boolean,
|
|
487
|
+
getDayProps: Function,
|
|
488
|
+
getDayAriaLabel: Function,
|
|
489
|
+
onDayClick: Function,
|
|
490
|
+
onDayMouseEnter: Function,
|
|
491
|
+
withCellSpacing: {
|
|
492
|
+
type: Boolean,
|
|
493
|
+
default: true
|
|
494
|
+
},
|
|
495
|
+
highlightToday: Boolean,
|
|
496
|
+
withWeekNumbers: Boolean,
|
|
497
|
+
static: Boolean,
|
|
498
|
+
fullWidth: Boolean
|
|
499
|
+
},
|
|
500
|
+
setup(props) {
|
|
501
|
+
const ctx = useDatesContext();
|
|
502
|
+
const hovered = (0, vue.ref)(null);
|
|
503
|
+
const dayRefs = [];
|
|
504
|
+
const isSelected = (date) => {
|
|
505
|
+
if (props.type === "multiple") return Array.isArray(props.value) && props.value.includes(date);
|
|
506
|
+
if (props.type === "range") {
|
|
507
|
+
const [start, end] = Array.isArray(props.value) ? props.value : [null, null];
|
|
508
|
+
return isSameDate(date, start) || isSameDate(date, end);
|
|
509
|
+
}
|
|
510
|
+
return isSameDate(date, props.value);
|
|
511
|
+
};
|
|
512
|
+
const isInRange = (date) => {
|
|
513
|
+
if (props.type !== "range" || !Array.isArray(props.value)) return false;
|
|
514
|
+
const [start, end] = props.value;
|
|
515
|
+
const rangeEnd = end || hovered.value;
|
|
516
|
+
if (!start || !rangeEnd) return false;
|
|
517
|
+
return (0, dayjs.default)(date).isAfter(start, "day") && (0, dayjs.default)(date).isBefore(rangeEnd, "day");
|
|
518
|
+
};
|
|
519
|
+
return () => {
|
|
520
|
+
const first = props.firstDayOfWeek ?? ctx.firstDayOfWeek;
|
|
521
|
+
const rows = getMonthDays(props.month, first, ctx.consistentWeeks);
|
|
522
|
+
const flatDates = rows.flat();
|
|
523
|
+
const isEnabled = (date) => {
|
|
524
|
+
const outside = !(0, dayjs.default)(date).isSame(props.month, "month");
|
|
525
|
+
return !(isBeforeMin(date, props.minDate) || isAfterMax(date, props.maxDate) || props.excludeDate?.(date) || props.getDayProps?.(date)?.disabled) && (!props.hideOutsideDates || !outside);
|
|
526
|
+
};
|
|
527
|
+
const enabledDates = flatDates.filter(isEnabled);
|
|
528
|
+
const dateInTabOrder = enabledDates.find((date) => isSelected(date)) ?? enabledDates.find((date) => (0, dayjs.default)().isSame(date, "date")) ?? enabledDates[0];
|
|
529
|
+
return (0, vue.h)("table", {
|
|
530
|
+
class: Dates_module_default.month,
|
|
531
|
+
"data-full-width": props.fullWidth || void 0
|
|
532
|
+
}, [props.hideWeekdays ? null : (0, vue.h)("thead", [(0, vue.h)(WeekdaysRow, {
|
|
533
|
+
firstDayOfWeek: first,
|
|
534
|
+
weekendDays: props.weekendDays,
|
|
535
|
+
withWeekNumbers: props.withWeekNumbers
|
|
536
|
+
})]), (0, vue.h)("tbody", rows.map((week, rowIndex) => (0, vue.h)("tr", { class: Dates_module_default.monthRow }, [props.withWeekNumbers ? (0, vue.h)("td", { class: Dates_module_default.weekNumber }, getWeekNumber(week[0])) : null, ...week.map((date, cellIndex) => {
|
|
537
|
+
const outside = !(0, dayjs.default)(date).isSame(props.month, "month");
|
|
538
|
+
const disabled = isBeforeMin(date, props.minDate) || isAfterMax(date, props.maxDate) || props.excludeDate?.(date);
|
|
539
|
+
const dayProps = props.getDayProps?.(date) || {};
|
|
540
|
+
const selected = isSelected(date);
|
|
541
|
+
const [start, end] = props.type === "range" && Array.isArray(props.value) ? props.value : [null, null];
|
|
542
|
+
return (0, vue.h)("td", {
|
|
543
|
+
class: Dates_module_default.monthCell,
|
|
544
|
+
"data-with-spacing": props.withCellSpacing || void 0
|
|
545
|
+
}, [(0, vue.h)(Day, {
|
|
546
|
+
...dayProps,
|
|
547
|
+
date,
|
|
548
|
+
static: props.static,
|
|
549
|
+
disabled: disabled || dayProps.disabled,
|
|
550
|
+
weekend: (props.weekendDays ?? ctx.weekendDays).includes((0, dayjs.default)(date).day()),
|
|
551
|
+
outside,
|
|
552
|
+
hidden: props.hideOutsideDates && outside,
|
|
553
|
+
selected,
|
|
554
|
+
inRange: isInRange(date),
|
|
555
|
+
firstInRange: isSameDate(date, start),
|
|
556
|
+
lastInRange: isSameDate(date, end),
|
|
557
|
+
highlightToday: props.highlightToday,
|
|
558
|
+
fullWidth: props.fullWidth,
|
|
559
|
+
renderDay: props.renderDay,
|
|
560
|
+
"aria-label": props.getDayAriaLabel?.(date),
|
|
561
|
+
tabindex: props.static ? void 0 : date === dateInTabOrder ? 0 : -1,
|
|
562
|
+
"data-autofocus": selected || void 0,
|
|
563
|
+
ref: (node) => setGridRef(dayRefs, rowIndex, cellIndex, node),
|
|
564
|
+
onClick: (event) => {
|
|
565
|
+
dayProps.onClick?.(event);
|
|
566
|
+
if (!disabled && !props.static) props.onDayClick?.(date);
|
|
567
|
+
},
|
|
568
|
+
onMouseenter: (event) => {
|
|
569
|
+
hovered.value = date;
|
|
570
|
+
dayProps.onMouseenter?.(event);
|
|
571
|
+
props.onDayMouseEnter?.(date);
|
|
572
|
+
},
|
|
573
|
+
onKeydown: (event) => {
|
|
574
|
+
dayProps.onKeydown?.(event);
|
|
575
|
+
const direction = keyToDirection(event.key);
|
|
576
|
+
if (direction) {
|
|
577
|
+
event.preventDefault();
|
|
578
|
+
focusAdjacentControl(dayRefs, rowIndex, cellIndex, direction);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
})]);
|
|
582
|
+
})])))]);
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
var MonthsList = (0, vue.defineComponent)({
|
|
587
|
+
name: "MonthsList",
|
|
588
|
+
props: {
|
|
589
|
+
year: {
|
|
590
|
+
type: String,
|
|
591
|
+
default: () => (0, dayjs.default)().format("YYYY-MM-DD")
|
|
592
|
+
},
|
|
593
|
+
value: [
|
|
594
|
+
String,
|
|
595
|
+
Array,
|
|
596
|
+
null
|
|
597
|
+
],
|
|
598
|
+
minDate: [String, Date],
|
|
599
|
+
maxDate: [String, Date],
|
|
600
|
+
locale: String,
|
|
601
|
+
monthsListFormat: {
|
|
602
|
+
type: [String, Function],
|
|
603
|
+
default: "MMM"
|
|
604
|
+
},
|
|
605
|
+
getMonthControlProps: Function,
|
|
606
|
+
onMonthSelect: Function,
|
|
607
|
+
onMonthMouseEnter: Function,
|
|
608
|
+
fullWidth: Boolean
|
|
609
|
+
},
|
|
610
|
+
setup(props) {
|
|
611
|
+
const controlRefs = [];
|
|
612
|
+
return () => {
|
|
613
|
+
const months = Array.from({ length: 12 }, (_, index) => (0, dayjs.default)(props.year).month(index).startOf("month").format("YYYY-MM-DD"));
|
|
614
|
+
const isEnabled = (date) => !(props.minDate && (0, dayjs.default)(date).endOf("month").isBefore(props.minDate, "day") || props.maxDate && (0, dayjs.default)(date).startOf("month").isAfter(props.maxDate, "day") || props.getMonthControlProps?.(date)?.disabled);
|
|
615
|
+
const isSelected = (date) => Array.isArray(props.value) ? props.value.some((item) => (0, dayjs.default)(item).isSame(date, "month")) : !!props.value && (0, dayjs.default)(props.value).isSame(date, "month");
|
|
616
|
+
const enabledMonths = months.filter(isEnabled);
|
|
617
|
+
const monthInTabOrder = enabledMonths.find(isSelected) ?? enabledMonths.find((date) => (0, dayjs.default)().isSame(date, "month")) ?? enabledMonths[0];
|
|
618
|
+
return (0, vue.h)(_mantine_vue_core.SimpleGrid, {
|
|
619
|
+
cols: 3,
|
|
620
|
+
spacing: 4,
|
|
621
|
+
class: Dates_module_default.controlsGrid,
|
|
622
|
+
"data-full-width": props.fullWidth || void 0
|
|
623
|
+
}, () => months.map((date, index) => {
|
|
624
|
+
const rowIndex = Math.floor(index / 3);
|
|
625
|
+
const cellIndex = index % 3;
|
|
626
|
+
const disabled = !isEnabled(date);
|
|
627
|
+
const controlProps = props.getMonthControlProps?.(date) || {};
|
|
628
|
+
return (0, vue.h)(PickerControl, {
|
|
629
|
+
fullWidth: props.fullWidth,
|
|
630
|
+
...controlProps,
|
|
631
|
+
disabled: disabled || controlProps.disabled,
|
|
632
|
+
selected: isSelected(date),
|
|
633
|
+
tabindex: date === monthInTabOrder ? 0 : -1,
|
|
634
|
+
"data-autofocus": isSelected(date) || void 0,
|
|
635
|
+
ref: (node) => setGridRef(controlRefs, rowIndex, cellIndex, node),
|
|
636
|
+
onClick: (event) => {
|
|
637
|
+
controlProps.onClick?.(event);
|
|
638
|
+
if (!disabled) props.onMonthSelect?.(date);
|
|
639
|
+
},
|
|
640
|
+
onMouseenter: (event) => {
|
|
641
|
+
controlProps.onMouseenter?.(event);
|
|
642
|
+
props.onMonthMouseEnter?.(date);
|
|
643
|
+
},
|
|
644
|
+
onKeydown: (event) => {
|
|
645
|
+
controlProps.onKeydown?.(event);
|
|
646
|
+
const direction = keyToDirection(event.key);
|
|
647
|
+
if (direction) {
|
|
648
|
+
event.preventDefault();
|
|
649
|
+
focusAdjacentControl(controlRefs, rowIndex, cellIndex, direction);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}, () => typeof props.monthsListFormat === "function" ? props.monthsListFormat(date) : (0, dayjs.default)(date).locale(props.locale || "en").format(props.monthsListFormat));
|
|
653
|
+
}));
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
var YearsList = (0, vue.defineComponent)({
|
|
658
|
+
name: "YearsList",
|
|
659
|
+
props: {
|
|
660
|
+
decade: {
|
|
661
|
+
type: String,
|
|
662
|
+
default: () => (0, dayjs.default)().format("YYYY-MM-DD")
|
|
663
|
+
},
|
|
664
|
+
value: [
|
|
665
|
+
String,
|
|
666
|
+
Array,
|
|
667
|
+
null
|
|
668
|
+
],
|
|
669
|
+
minDate: [String, Date],
|
|
670
|
+
maxDate: [String, Date],
|
|
671
|
+
yearsListFormat: {
|
|
672
|
+
type: [String, Function],
|
|
673
|
+
default: "YYYY"
|
|
674
|
+
},
|
|
675
|
+
getYearControlProps: Function,
|
|
676
|
+
onYearSelect: Function,
|
|
677
|
+
onYearMouseEnter: Function,
|
|
678
|
+
fullWidth: Boolean
|
|
679
|
+
},
|
|
680
|
+
setup(props) {
|
|
681
|
+
const controlRefs = [];
|
|
682
|
+
return () => {
|
|
683
|
+
const years = getYearRange(props.decade);
|
|
684
|
+
const isEnabled = (date) => !(props.minDate && (0, dayjs.default)(date).endOf("year").isBefore(props.minDate, "day") || props.maxDate && (0, dayjs.default)(date).startOf("year").isAfter(props.maxDate, "day") || props.getYearControlProps?.(date)?.disabled);
|
|
685
|
+
const isSelected = (date) => Array.isArray(props.value) ? props.value.some((item) => (0, dayjs.default)(item).isSame(date, "year")) : !!props.value && (0, dayjs.default)(props.value).isSame(date, "year");
|
|
686
|
+
const enabledYears = years.filter(isEnabled);
|
|
687
|
+
const yearInTabOrder = enabledYears.find(isSelected) ?? enabledYears.find((date) => (0, dayjs.default)().isSame(date, "year")) ?? enabledYears[0];
|
|
688
|
+
return (0, vue.h)(_mantine_vue_core.SimpleGrid, {
|
|
689
|
+
cols: 3,
|
|
690
|
+
spacing: 4,
|
|
691
|
+
class: Dates_module_default.controlsGrid,
|
|
692
|
+
"data-full-width": props.fullWidth || void 0
|
|
693
|
+
}, () => years.map((date, index) => {
|
|
694
|
+
const rowIndex = Math.floor(index / 3);
|
|
695
|
+
const cellIndex = index % 3;
|
|
696
|
+
const disabled = !isEnabled(date);
|
|
697
|
+
const controlProps = props.getYearControlProps?.(date) || {};
|
|
698
|
+
return (0, vue.h)(PickerControl, {
|
|
699
|
+
fullWidth: props.fullWidth,
|
|
700
|
+
...controlProps,
|
|
701
|
+
disabled: disabled || controlProps.disabled,
|
|
702
|
+
selected: isSelected(date),
|
|
703
|
+
tabindex: date === yearInTabOrder ? 0 : -1,
|
|
704
|
+
"data-autofocus": isSelected(date) || void 0,
|
|
705
|
+
ref: (node) => setGridRef(controlRefs, rowIndex, cellIndex, node),
|
|
706
|
+
onClick: (event) => {
|
|
707
|
+
controlProps.onClick?.(event);
|
|
708
|
+
if (!disabled) props.onYearSelect?.(date);
|
|
709
|
+
},
|
|
710
|
+
onMouseenter: (event) => {
|
|
711
|
+
controlProps.onMouseenter?.(event);
|
|
712
|
+
props.onYearMouseEnter?.(date);
|
|
713
|
+
},
|
|
714
|
+
onKeydown: (event) => {
|
|
715
|
+
controlProps.onKeydown?.(event);
|
|
716
|
+
const direction = keyToDirection(event.key);
|
|
717
|
+
if (direction) {
|
|
718
|
+
event.preventDefault();
|
|
719
|
+
focusAdjacentControl(controlRefs, rowIndex, cellIndex, direction);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}, () => typeof props.yearsListFormat === "function" ? props.yearsListFormat(date) : (0, dayjs.default)(date).format(props.yearsListFormat));
|
|
723
|
+
}));
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
function getNextLevel(level, direction) {
|
|
728
|
+
const order = [
|
|
729
|
+
"month",
|
|
730
|
+
"year",
|
|
731
|
+
"decade"
|
|
732
|
+
];
|
|
733
|
+
return order[Math.max(0, Math.min(order.length - 1, order.indexOf(level) + (direction === "up" ? 1 : -1)))];
|
|
734
|
+
}
|
|
735
|
+
function clampLevel(level, minLevel, maxLevel) {
|
|
736
|
+
const order = [
|
|
737
|
+
"month",
|
|
738
|
+
"year",
|
|
739
|
+
"decade"
|
|
740
|
+
];
|
|
741
|
+
const toNumber = (value, fallback) => value ? order.indexOf(value) : fallback;
|
|
742
|
+
return order[Math.max(toNumber(minLevel, 0), Math.min(toNumber(maxLevel, 2), toNumber(level, 0)))];
|
|
743
|
+
}
|
|
744
|
+
var Calendar = (0, vue.defineComponent)({
|
|
745
|
+
name: "Calendar",
|
|
746
|
+
props: {
|
|
747
|
+
defaultLevel: String,
|
|
748
|
+
level: String,
|
|
749
|
+
onLevelChange: Function,
|
|
750
|
+
maxLevel: {
|
|
751
|
+
type: String,
|
|
752
|
+
default: "decade"
|
|
753
|
+
},
|
|
754
|
+
minLevel: {
|
|
755
|
+
type: String,
|
|
756
|
+
default: "month"
|
|
757
|
+
},
|
|
758
|
+
defaultDate: [String, Date],
|
|
759
|
+
date: [String, Date],
|
|
760
|
+
onDateChange: Function,
|
|
761
|
+
numberOfColumns: {
|
|
762
|
+
type: Number,
|
|
763
|
+
default: 1
|
|
764
|
+
},
|
|
765
|
+
columnsToScroll: Number,
|
|
766
|
+
type: {
|
|
767
|
+
type: String,
|
|
768
|
+
default: "default"
|
|
769
|
+
},
|
|
770
|
+
value: [
|
|
771
|
+
String,
|
|
772
|
+
Array,
|
|
773
|
+
null
|
|
774
|
+
],
|
|
775
|
+
minDate: [String, Date],
|
|
776
|
+
maxDate: [String, Date],
|
|
777
|
+
locale: String,
|
|
778
|
+
firstDayOfWeek: Number,
|
|
779
|
+
weekendDays: Array,
|
|
780
|
+
renderDay: Function,
|
|
781
|
+
getDayProps: Function,
|
|
782
|
+
getDayAriaLabel: Function,
|
|
783
|
+
getMonthControlProps: Function,
|
|
784
|
+
getYearControlProps: Function,
|
|
785
|
+
excludeDate: Function,
|
|
786
|
+
hideOutsideDates: Boolean,
|
|
787
|
+
hideWeekdays: Boolean,
|
|
788
|
+
monthLabelFormat: {
|
|
789
|
+
type: [String, Function],
|
|
790
|
+
default: "MMMM YYYY"
|
|
791
|
+
},
|
|
792
|
+
yearLabelFormat: {
|
|
793
|
+
type: [String, Function],
|
|
794
|
+
default: "YYYY"
|
|
795
|
+
},
|
|
796
|
+
decadeLabelFormat: Function,
|
|
797
|
+
monthsListFormat: {
|
|
798
|
+
type: [String, Function],
|
|
799
|
+
default: "MMM"
|
|
800
|
+
},
|
|
801
|
+
yearsListFormat: {
|
|
802
|
+
type: [String, Function],
|
|
803
|
+
default: "YYYY"
|
|
804
|
+
},
|
|
805
|
+
onYearSelect: Function,
|
|
806
|
+
onMonthSelect: Function,
|
|
807
|
+
onMonthMouseEnter: Function,
|
|
808
|
+
onYearMouseEnter: Function,
|
|
809
|
+
onDayClick: Function,
|
|
810
|
+
withCellSpacing: {
|
|
811
|
+
type: Boolean,
|
|
812
|
+
default: true
|
|
813
|
+
},
|
|
814
|
+
highlightToday: Boolean,
|
|
815
|
+
withWeekNumbers: Boolean,
|
|
816
|
+
static: Boolean,
|
|
817
|
+
fullWidth: Boolean
|
|
818
|
+
},
|
|
819
|
+
setup(props, { attrs }) {
|
|
820
|
+
const [_level, setLevel] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
821
|
+
value: (0, vue.computed)(() => props.level === void 0 ? void 0 : clampLevel(props.level, props.minLevel, props.maxLevel)),
|
|
822
|
+
defaultValue: props.defaultLevel === void 0 ? void 0 : clampLevel(props.defaultLevel, props.minLevel, props.maxLevel),
|
|
823
|
+
finalValue: clampLevel(void 0, props.minLevel, props.maxLevel),
|
|
824
|
+
onChange: (value) => props.onLevelChange?.(value)
|
|
825
|
+
});
|
|
826
|
+
const [_date, setDate] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
827
|
+
value: (0, vue.computed)(() => normalizeDate(props.date) || void 0),
|
|
828
|
+
defaultValue: normalizeDate(props.defaultDate) || void 0,
|
|
829
|
+
finalValue: getDefaultClampedDate({
|
|
830
|
+
minDate: props.minDate,
|
|
831
|
+
maxDate: props.maxDate
|
|
832
|
+
}),
|
|
833
|
+
onChange: (value) => props.onDateChange?.(value)
|
|
834
|
+
});
|
|
835
|
+
const scroll = props.columnsToScroll || props.numberOfColumns || 1;
|
|
836
|
+
const updateDate = (amount, unit) => {
|
|
837
|
+
setDate((0, dayjs.default)(_date.value).add(amount, unit).format("YYYY-MM-DD"));
|
|
838
|
+
};
|
|
839
|
+
return () => (0, vue.h)(_mantine_vue_core.Box, {
|
|
840
|
+
...attrs,
|
|
841
|
+
class: [Dates_module_default.calendar, attrs.class],
|
|
842
|
+
"data-calendar": true,
|
|
843
|
+
"data-full-width": props.fullWidth || void 0
|
|
844
|
+
}, () => Array.from({ length: props.numberOfColumns || 1 }, (_, column) => {
|
|
845
|
+
const currentDate = (0, dayjs.default)(_date.value).add(column * scroll, _level.value === "month" ? "month" : _level.value === "year" ? "year" : "year").format("YYYY-MM-DD");
|
|
846
|
+
if (_level.value === "month") return (0, vue.h)("div", { class: Dates_module_default.calendarLevel }, [(0, vue.h)(CalendarHeader, {
|
|
847
|
+
label: typeof props.monthLabelFormat === "function" ? props.monthLabelFormat(currentDate) : getMonthLabel(currentDate, props.monthLabelFormat, props.locale),
|
|
848
|
+
hasNextLevel: props.maxLevel !== "month",
|
|
849
|
+
withPrevious: column === 0,
|
|
850
|
+
withNext: column === (props.numberOfColumns || 1) - 1,
|
|
851
|
+
fullWidth: props.fullWidth,
|
|
852
|
+
onPrevious: () => updateDate(-scroll, "month"),
|
|
853
|
+
onNext: () => updateDate(scroll, "month"),
|
|
854
|
+
onLevelClick: () => setLevel(getNextLevel(_level.value, "up"))
|
|
855
|
+
}), (0, vue.h)(Month, {
|
|
856
|
+
month: currentDate,
|
|
857
|
+
value: props.value,
|
|
858
|
+
type: props.type,
|
|
859
|
+
minDate: props.minDate,
|
|
860
|
+
maxDate: props.maxDate,
|
|
861
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
862
|
+
weekendDays: props.weekendDays,
|
|
863
|
+
renderDay: props.renderDay,
|
|
864
|
+
getDayProps: props.getDayProps,
|
|
865
|
+
getDayAriaLabel: props.getDayAriaLabel,
|
|
866
|
+
excludeDate: props.excludeDate,
|
|
867
|
+
hideOutsideDates: props.hideOutsideDates,
|
|
868
|
+
hideWeekdays: props.hideWeekdays,
|
|
869
|
+
withCellSpacing: props.withCellSpacing,
|
|
870
|
+
highlightToday: props.highlightToday,
|
|
871
|
+
withWeekNumbers: props.withWeekNumbers,
|
|
872
|
+
static: props.static,
|
|
873
|
+
fullWidth: props.fullWidth,
|
|
874
|
+
onDayClick: props.onDayClick
|
|
875
|
+
})]);
|
|
876
|
+
if (_level.value === "year") return (0, vue.h)("div", { class: Dates_module_default.calendarLevel }, [(0, vue.h)(CalendarHeader, {
|
|
877
|
+
label: typeof props.yearLabelFormat === "function" ? props.yearLabelFormat(currentDate) : (0, dayjs.default)(currentDate).format(props.yearLabelFormat),
|
|
878
|
+
hasNextLevel: props.maxLevel === "decade",
|
|
879
|
+
withPrevious: column === 0,
|
|
880
|
+
withNext: column === (props.numberOfColumns || 1) - 1,
|
|
881
|
+
fullWidth: props.fullWidth,
|
|
882
|
+
onPrevious: () => updateDate(-scroll, "year"),
|
|
883
|
+
onNext: () => updateDate(scroll, "year"),
|
|
884
|
+
onLevelClick: () => setLevel(getNextLevel(_level.value, "up"))
|
|
885
|
+
}), (0, vue.h)(MonthsList, {
|
|
886
|
+
year: currentDate,
|
|
887
|
+
value: props.value,
|
|
888
|
+
minDate: props.minDate,
|
|
889
|
+
maxDate: props.maxDate,
|
|
890
|
+
monthsListFormat: props.monthsListFormat,
|
|
891
|
+
getMonthControlProps: props.getMonthControlProps,
|
|
892
|
+
fullWidth: props.fullWidth,
|
|
893
|
+
onMonthMouseEnter: props.onMonthMouseEnter,
|
|
894
|
+
onMonthSelect: (date) => {
|
|
895
|
+
setDate(date);
|
|
896
|
+
props.onMonthSelect?.(date);
|
|
897
|
+
setLevel(clampLevel("month", props.minLevel, props.maxLevel));
|
|
898
|
+
}
|
|
899
|
+
})]);
|
|
900
|
+
const years = getYearRange(currentDate);
|
|
901
|
+
return (0, vue.h)("div", { class: Dates_module_default.calendarLevel }, [(0, vue.h)(CalendarHeader, {
|
|
902
|
+
label: props.decadeLabelFormat ? props.decadeLabelFormat(years[0], years[years.length - 1]) : getDecadeLabel(currentDate),
|
|
903
|
+
withPrevious: column === 0,
|
|
904
|
+
withNext: column === (props.numberOfColumns || 1) - 1,
|
|
905
|
+
hasNextLevel: false,
|
|
906
|
+
fullWidth: props.fullWidth,
|
|
907
|
+
onPrevious: () => updateDate(-10 * scroll, "year"),
|
|
908
|
+
onNext: () => updateDate(10 * scroll, "year")
|
|
909
|
+
}), (0, vue.h)(YearsList, {
|
|
910
|
+
decade: currentDate,
|
|
911
|
+
value: props.value,
|
|
912
|
+
minDate: props.minDate,
|
|
913
|
+
maxDate: props.maxDate,
|
|
914
|
+
yearsListFormat: props.yearsListFormat,
|
|
915
|
+
getYearControlProps: props.getYearControlProps,
|
|
916
|
+
fullWidth: props.fullWidth,
|
|
917
|
+
onYearMouseEnter: props.onYearMouseEnter,
|
|
918
|
+
onYearSelect: (date) => {
|
|
919
|
+
setDate(date);
|
|
920
|
+
props.onYearSelect?.(date);
|
|
921
|
+
setLevel(clampLevel("year", props.minLevel, props.maxLevel));
|
|
922
|
+
}
|
|
923
|
+
})]);
|
|
924
|
+
}));
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
var MonthLevel = Calendar;
|
|
928
|
+
var YearLevel = Calendar;
|
|
929
|
+
var DecadeLevel = Calendar;
|
|
930
|
+
var MonthLevelGroup = Calendar;
|
|
931
|
+
var YearLevelGroup = Calendar;
|
|
932
|
+
var DecadeLevelGroup = Calendar;
|
|
933
|
+
var LevelsGroup = Calendar;
|
|
934
|
+
function isInRangeGranular(date, range, unit) {
|
|
935
|
+
const sorted = [...range].sort((a, b) => (0, dayjs.default)(a).isAfter((0, dayjs.default)(b)) ? 1 : -1);
|
|
936
|
+
return !(0, dayjs.default)(date).isBefore(sorted[0], unit) && !(0, dayjs.default)(date).isAfter(sorted[1], unit);
|
|
937
|
+
}
|
|
938
|
+
function getNextPickerValue(value, date, type, sortDates = true) {
|
|
939
|
+
if (type === "multiple") {
|
|
940
|
+
const next = Array.isArray(value) ? [...value] : [];
|
|
941
|
+
const index = next.findIndex((item) => isSameDate(item, date));
|
|
942
|
+
if (index >= 0) next.splice(index, 1);
|
|
943
|
+
else next.push(date);
|
|
944
|
+
return sortDates ? next.sort((a, b) => (0, dayjs.default)(a).valueOf() - (0, dayjs.default)(b).valueOf()) : next;
|
|
945
|
+
}
|
|
946
|
+
if (type === "range") {
|
|
947
|
+
const [start, end] = Array.isArray(value) ? value : [null, null];
|
|
948
|
+
if (!start || start && end || (0, dayjs.default)(date).isBefore(start, "day")) return [date, null];
|
|
949
|
+
return [start, date];
|
|
950
|
+
}
|
|
951
|
+
return date;
|
|
952
|
+
}
|
|
953
|
+
var DatePicker = (0, vue.defineComponent)({
|
|
954
|
+
name: "DatePicker",
|
|
955
|
+
props: {
|
|
956
|
+
type: {
|
|
957
|
+
type: String,
|
|
958
|
+
default: "default"
|
|
959
|
+
},
|
|
960
|
+
value: [
|
|
961
|
+
String,
|
|
962
|
+
Array,
|
|
963
|
+
null
|
|
964
|
+
],
|
|
965
|
+
defaultValue: [
|
|
966
|
+
String,
|
|
967
|
+
Array,
|
|
968
|
+
null
|
|
969
|
+
],
|
|
970
|
+
onChange: Function,
|
|
971
|
+
allowDeselect: {
|
|
972
|
+
type: Boolean,
|
|
973
|
+
default: true
|
|
974
|
+
},
|
|
975
|
+
sortDates: {
|
|
976
|
+
type: Boolean,
|
|
977
|
+
default: true
|
|
978
|
+
},
|
|
979
|
+
presets: Array
|
|
980
|
+
},
|
|
981
|
+
setup(props, { attrs }) {
|
|
982
|
+
const finalValue = (0, vue.computed)(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
983
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
984
|
+
value: (0, vue.computed)(() => props.value),
|
|
985
|
+
defaultValue: props.defaultValue,
|
|
986
|
+
finalValue: finalValue.value,
|
|
987
|
+
onChange: (value) => props.onChange?.(value)
|
|
988
|
+
});
|
|
989
|
+
const selectDate = (date) => {
|
|
990
|
+
if (props.type === "default" && props.allowDeselect && isSameDate(_value.value, date)) setValue(null);
|
|
991
|
+
else setValue(getNextPickerValue(_value.value, date, props.type, props.sortDates));
|
|
992
|
+
};
|
|
993
|
+
const calendarDate = (0, vue.ref)(void 0);
|
|
994
|
+
const calendarLevel = (0, vue.ref)(void 0);
|
|
995
|
+
const selectPreset = (value) => {
|
|
996
|
+
const date = Array.isArray(value) ? value[0] : value;
|
|
997
|
+
if (date != null) {
|
|
998
|
+
calendarDate.value = date;
|
|
999
|
+
calendarLevel.value = "month";
|
|
1000
|
+
}
|
|
1001
|
+
setValue(value);
|
|
1002
|
+
};
|
|
1003
|
+
return () => {
|
|
1004
|
+
const calendar = (0, vue.h)(Calendar, {
|
|
1005
|
+
...attrs,
|
|
1006
|
+
type: props.type,
|
|
1007
|
+
value: _value.value,
|
|
1008
|
+
date: calendarDate.value,
|
|
1009
|
+
onDateChange: (date) => calendarDate.value = date,
|
|
1010
|
+
level: calendarLevel.value,
|
|
1011
|
+
onLevelChange: (level) => calendarLevel.value = level,
|
|
1012
|
+
onDayClick: selectDate
|
|
1013
|
+
});
|
|
1014
|
+
if (!props.presets?.length) return calendar;
|
|
1015
|
+
return (0, vue.h)("div", { class: Dates_module_default.datePickerRoot }, [(0, vue.h)("div", { class: Dates_module_default.presetsList }, props.presets.map((preset, index) => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
1016
|
+
key: index,
|
|
1017
|
+
class: Dates_module_default.presetButton,
|
|
1018
|
+
onClick: () => selectPreset(preset.value),
|
|
1019
|
+
onMousedown: (event) => event.preventDefault()
|
|
1020
|
+
}, () => preset.label))), calendar]);
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
var YearPicker = (0, vue.defineComponent)({
|
|
1025
|
+
name: "YearPicker",
|
|
1026
|
+
props: {
|
|
1027
|
+
type: {
|
|
1028
|
+
type: String,
|
|
1029
|
+
default: "default"
|
|
1030
|
+
},
|
|
1031
|
+
value: [
|
|
1032
|
+
String,
|
|
1033
|
+
Array,
|
|
1034
|
+
null
|
|
1035
|
+
],
|
|
1036
|
+
defaultValue: [
|
|
1037
|
+
String,
|
|
1038
|
+
Array,
|
|
1039
|
+
null
|
|
1040
|
+
],
|
|
1041
|
+
onChange: Function,
|
|
1042
|
+
allowDeselect: {
|
|
1043
|
+
type: Boolean,
|
|
1044
|
+
default: true
|
|
1045
|
+
},
|
|
1046
|
+
sortDates: {
|
|
1047
|
+
type: Boolean,
|
|
1048
|
+
default: true
|
|
1049
|
+
},
|
|
1050
|
+
presets: Array,
|
|
1051
|
+
onYearSelect: Function
|
|
1052
|
+
},
|
|
1053
|
+
setup(props, { attrs }) {
|
|
1054
|
+
const finalValue = (0, vue.computed)(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
1055
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1056
|
+
value: (0, vue.computed)(() => props.value),
|
|
1057
|
+
defaultValue: props.defaultValue,
|
|
1058
|
+
finalValue: finalValue.value,
|
|
1059
|
+
onChange: (value) => props.onChange?.(value)
|
|
1060
|
+
});
|
|
1061
|
+
const hoveredDate = (0, vue.ref)(null);
|
|
1062
|
+
const selectYear = (date) => {
|
|
1063
|
+
if (props.type === "default" && props.allowDeselect && isSameDate(_value.value, date)) setValue(null);
|
|
1064
|
+
else setValue(getNextPickerValue(_value.value, date, props.type, props.sortDates));
|
|
1065
|
+
hoveredDate.value = null;
|
|
1066
|
+
props.onYearSelect?.(date);
|
|
1067
|
+
};
|
|
1068
|
+
const yearControlProps = (date) => {
|
|
1069
|
+
const external = attrs.getYearControlProps?.(date) || {};
|
|
1070
|
+
if (props.type !== "range" || !Array.isArray(_value.value)) return external;
|
|
1071
|
+
const [start, end] = _value.value;
|
|
1072
|
+
const hovered = start && !end ? hoveredDate.value : null;
|
|
1073
|
+
return {
|
|
1074
|
+
inRange: start && hovered ? isInRangeGranular(date, [hovered, start], "year") : start && end ? isInRangeGranular(date, [start, end], "year") : false,
|
|
1075
|
+
firstInRange: start ? (0, dayjs.default)(date).isSame(start, "year") && !(hovered && (0, dayjs.default)(hovered).isBefore(start, "year")) : false,
|
|
1076
|
+
lastInRange: end ? (0, dayjs.default)(date).isSame(end, "year") : !!(start && hovered && (0, dayjs.default)(hovered).isBefore(start, "year") && (0, dayjs.default)(date).isSame(start, "year")),
|
|
1077
|
+
...external
|
|
1078
|
+
};
|
|
1079
|
+
};
|
|
1080
|
+
const calendarDate = (0, vue.ref)(void 0);
|
|
1081
|
+
const selectPreset = (value) => {
|
|
1082
|
+
const date = Array.isArray(value) ? value[0] : value;
|
|
1083
|
+
if (date != null) calendarDate.value = date;
|
|
1084
|
+
setValue(value);
|
|
1085
|
+
};
|
|
1086
|
+
return () => {
|
|
1087
|
+
const calendar = (0, vue.h)(Calendar, {
|
|
1088
|
+
...attrs,
|
|
1089
|
+
type: props.type,
|
|
1090
|
+
value: _value.value,
|
|
1091
|
+
date: calendarDate.value,
|
|
1092
|
+
onDateChange: (date) => calendarDate.value = date,
|
|
1093
|
+
defaultLevel: "decade",
|
|
1094
|
+
minLevel: "decade",
|
|
1095
|
+
onYearSelect: selectYear,
|
|
1096
|
+
getYearControlProps: yearControlProps,
|
|
1097
|
+
onYearMouseEnter: (date) => {
|
|
1098
|
+
const [start, end] = Array.isArray(_value.value) ? _value.value : [null, null];
|
|
1099
|
+
if (props.type === "range" && start && !end) hoveredDate.value = date;
|
|
1100
|
+
},
|
|
1101
|
+
onMouseleave: () => {
|
|
1102
|
+
hoveredDate.value = null;
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
if (!props.presets?.length) return calendar;
|
|
1106
|
+
return (0, vue.h)("div", { class: Dates_module_default.datePickerRoot }, [(0, vue.h)("div", { class: Dates_module_default.presetsList }, props.presets.map((preset, index) => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
1107
|
+
key: index,
|
|
1108
|
+
class: Dates_module_default.presetButton,
|
|
1109
|
+
onClick: () => selectPreset(preset.value),
|
|
1110
|
+
onMousedown: (event) => event.preventDefault()
|
|
1111
|
+
}, () => preset.label))), calendar]);
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
var MonthPicker = (0, vue.defineComponent)({
|
|
1116
|
+
name: "MonthPicker",
|
|
1117
|
+
props: {
|
|
1118
|
+
type: {
|
|
1119
|
+
type: String,
|
|
1120
|
+
default: "default"
|
|
1121
|
+
},
|
|
1122
|
+
value: [
|
|
1123
|
+
String,
|
|
1124
|
+
Array,
|
|
1125
|
+
null
|
|
1126
|
+
],
|
|
1127
|
+
defaultValue: [
|
|
1128
|
+
String,
|
|
1129
|
+
Array,
|
|
1130
|
+
null
|
|
1131
|
+
],
|
|
1132
|
+
onChange: Function,
|
|
1133
|
+
allowDeselect: {
|
|
1134
|
+
type: Boolean,
|
|
1135
|
+
default: true
|
|
1136
|
+
},
|
|
1137
|
+
sortDates: {
|
|
1138
|
+
type: Boolean,
|
|
1139
|
+
default: true
|
|
1140
|
+
},
|
|
1141
|
+
presets: Array,
|
|
1142
|
+
onMonthSelect: Function
|
|
1143
|
+
},
|
|
1144
|
+
setup(props, { attrs }) {
|
|
1145
|
+
const finalValue = (0, vue.computed)(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
1146
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1147
|
+
value: (0, vue.computed)(() => props.value),
|
|
1148
|
+
defaultValue: props.defaultValue,
|
|
1149
|
+
finalValue: finalValue.value,
|
|
1150
|
+
onChange: (value) => props.onChange?.(value)
|
|
1151
|
+
});
|
|
1152
|
+
const hoveredDate = (0, vue.ref)(null);
|
|
1153
|
+
const selectMonth = (date) => {
|
|
1154
|
+
if (props.type === "default" && props.allowDeselect && isSameDate(_value.value, date)) setValue(null);
|
|
1155
|
+
else setValue(getNextPickerValue(_value.value, date, props.type, props.sortDates));
|
|
1156
|
+
hoveredDate.value = null;
|
|
1157
|
+
props.onMonthSelect?.(date);
|
|
1158
|
+
};
|
|
1159
|
+
const monthControlProps = (date) => {
|
|
1160
|
+
const external = attrs.getMonthControlProps?.(date) || {};
|
|
1161
|
+
if (props.type !== "range" || !Array.isArray(_value.value)) return external;
|
|
1162
|
+
const [start, end] = _value.value;
|
|
1163
|
+
const hovered = start && !end ? hoveredDate.value : null;
|
|
1164
|
+
return {
|
|
1165
|
+
inRange: start && hovered ? isInRangeGranular(date, [hovered, start], "month") : start && end ? isInRangeGranular(date, [start, end], "month") : false,
|
|
1166
|
+
firstInRange: start ? (0, dayjs.default)(date).isSame(start, "month") && !(hovered && (0, dayjs.default)(hovered).isBefore(start, "month")) : false,
|
|
1167
|
+
lastInRange: end ? (0, dayjs.default)(date).isSame(end, "month") : !!(start && hovered && (0, dayjs.default)(hovered).isBefore(start, "month") && (0, dayjs.default)(date).isSame(start, "month")),
|
|
1168
|
+
...external
|
|
1169
|
+
};
|
|
1170
|
+
};
|
|
1171
|
+
const calendarDate = (0, vue.ref)(void 0);
|
|
1172
|
+
const selectPreset = (value) => {
|
|
1173
|
+
const date = Array.isArray(value) ? value[0] : value;
|
|
1174
|
+
if (date != null) calendarDate.value = date;
|
|
1175
|
+
setValue(value);
|
|
1176
|
+
};
|
|
1177
|
+
return () => {
|
|
1178
|
+
const calendar = (0, vue.h)(Calendar, {
|
|
1179
|
+
...attrs,
|
|
1180
|
+
type: props.type,
|
|
1181
|
+
value: _value.value,
|
|
1182
|
+
date: calendarDate.value,
|
|
1183
|
+
onDateChange: (date) => calendarDate.value = date,
|
|
1184
|
+
defaultLevel: "year",
|
|
1185
|
+
minLevel: "year",
|
|
1186
|
+
onMonthSelect: selectMonth,
|
|
1187
|
+
getMonthControlProps: monthControlProps,
|
|
1188
|
+
onMonthMouseEnter: (date) => {
|
|
1189
|
+
const [start, end] = Array.isArray(_value.value) ? _value.value : [null, null];
|
|
1190
|
+
if (props.type === "range" && start && !end) hoveredDate.value = date;
|
|
1191
|
+
},
|
|
1192
|
+
onMouseleave: () => {
|
|
1193
|
+
hoveredDate.value = null;
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
if (!props.presets?.length) return calendar;
|
|
1197
|
+
return (0, vue.h)("div", { class: Dates_module_default.datePickerRoot }, [(0, vue.h)("div", { class: Dates_module_default.presetsList }, props.presets.map((preset, index) => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
1198
|
+
key: index,
|
|
1199
|
+
class: Dates_module_default.presetButton,
|
|
1200
|
+
onClick: () => selectPreset(preset.value),
|
|
1201
|
+
onMousedown: (event) => event.preventDefault()
|
|
1202
|
+
}, () => preset.label))), calendar]);
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
var PickerInputBase = (0, vue.defineComponent)({
|
|
1207
|
+
name: "PickerInputBase",
|
|
1208
|
+
props: {
|
|
1209
|
+
formattedValue: {
|
|
1210
|
+
type: String,
|
|
1211
|
+
default: ""
|
|
1212
|
+
},
|
|
1213
|
+
dropdownOpened: Boolean,
|
|
1214
|
+
dropdownType: {
|
|
1215
|
+
type: String,
|
|
1216
|
+
default: "popover"
|
|
1217
|
+
},
|
|
1218
|
+
label: [
|
|
1219
|
+
String,
|
|
1220
|
+
Number,
|
|
1221
|
+
Object,
|
|
1222
|
+
Function
|
|
1223
|
+
],
|
|
1224
|
+
placeholder: String,
|
|
1225
|
+
clearable: Boolean,
|
|
1226
|
+
disabled: Boolean,
|
|
1227
|
+
required: Boolean,
|
|
1228
|
+
error: [String, Boolean],
|
|
1229
|
+
size: {
|
|
1230
|
+
type: [String, Number],
|
|
1231
|
+
default: "sm"
|
|
1232
|
+
},
|
|
1233
|
+
variant: String,
|
|
1234
|
+
onClear: Function,
|
|
1235
|
+
onDropdownClose: Function,
|
|
1236
|
+
onDropdownOpen: Function
|
|
1237
|
+
},
|
|
1238
|
+
emits: ["click"],
|
|
1239
|
+
inheritAttrs: false,
|
|
1240
|
+
setup(props, { slots, emit, attrs }) {
|
|
1241
|
+
const opened = (0, vue.ref)(props.dropdownOpened);
|
|
1242
|
+
(0, vue.watch)(() => props.dropdownOpened, (value) => {
|
|
1243
|
+
opened.value = value;
|
|
1244
|
+
});
|
|
1245
|
+
const close = () => {
|
|
1246
|
+
opened.value = false;
|
|
1247
|
+
props.onDropdownClose?.();
|
|
1248
|
+
};
|
|
1249
|
+
const open = () => {
|
|
1250
|
+
if (!props.disabled) {
|
|
1251
|
+
opened.value = true;
|
|
1252
|
+
props.onDropdownOpen?.();
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
const target = () => (0, vue.h)(_mantine_vue_core.InputBase, {
|
|
1256
|
+
...attrs,
|
|
1257
|
+
component: "button",
|
|
1258
|
+
type: "button",
|
|
1259
|
+
label: props.label,
|
|
1260
|
+
placeholder: props.placeholder,
|
|
1261
|
+
disabled: props.disabled,
|
|
1262
|
+
required: props.required,
|
|
1263
|
+
error: props.error,
|
|
1264
|
+
pointer: true,
|
|
1265
|
+
size: props.size,
|
|
1266
|
+
variant: props.variant,
|
|
1267
|
+
rightSection: props.clearable && props.formattedValue ? (0, vue.h)(_mantine_vue_core.CloseButton, {
|
|
1268
|
+
size: props.size,
|
|
1269
|
+
onMousedown: (event) => event.stopPropagation(),
|
|
1270
|
+
onClick: (event) => {
|
|
1271
|
+
event.stopPropagation();
|
|
1272
|
+
props.onClear?.();
|
|
1273
|
+
}
|
|
1274
|
+
}) : void 0,
|
|
1275
|
+
rightSectionPointerEvents: props.clearable && props.formattedValue ? "all" : void 0,
|
|
1276
|
+
onClick: (event) => {
|
|
1277
|
+
emit("click", event);
|
|
1278
|
+
open();
|
|
1279
|
+
}
|
|
1280
|
+
}, () => props.formattedValue ? (0, vue.h)("span", props.formattedValue) : (0, vue.h)("span", { class: Dates_module_default.placeholder }, props.placeholder));
|
|
1281
|
+
return () => props.dropdownType === "modal" ? (0, vue.h)(_mantine_vue_core.Box, null, () => [target(), (0, vue.h)(_mantine_vue_core.Modal, {
|
|
1282
|
+
opened: opened.value,
|
|
1283
|
+
onClose: close,
|
|
1284
|
+
title: props.label,
|
|
1285
|
+
size: "auto"
|
|
1286
|
+
}, () => slots.default?.({ close }))]) : (0, vue.h)(_mantine_vue_core.Popover, {
|
|
1287
|
+
opened: opened.value,
|
|
1288
|
+
onChange: (value) => value ? open() : close(),
|
|
1289
|
+
position: "bottom-start",
|
|
1290
|
+
trapFocus: true,
|
|
1291
|
+
returnFocus: false
|
|
1292
|
+
}, () => [(0, vue.h)(_mantine_vue_core.Popover.Target, null, target), (0, vue.h)(_mantine_vue_core.Popover.Dropdown, { class: Dates_module_default.dropdown }, () => slots.default?.({ close }))]);
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
function createPickerInput(name, Picker, defaultLevel, defaultValueFormat = "MMMM D, YYYY") {
|
|
1296
|
+
return (0, vue.defineComponent)({
|
|
1297
|
+
name,
|
|
1298
|
+
props: {
|
|
1299
|
+
type: {
|
|
1300
|
+
type: String,
|
|
1301
|
+
default: "default"
|
|
1302
|
+
},
|
|
1303
|
+
value: [
|
|
1304
|
+
String,
|
|
1305
|
+
Array,
|
|
1306
|
+
null
|
|
1307
|
+
],
|
|
1308
|
+
defaultValue: [
|
|
1309
|
+
String,
|
|
1310
|
+
Array,
|
|
1311
|
+
null
|
|
1312
|
+
],
|
|
1313
|
+
onChange: Function,
|
|
1314
|
+
valueFormat: {
|
|
1315
|
+
type: String,
|
|
1316
|
+
default: defaultValueFormat
|
|
1317
|
+
},
|
|
1318
|
+
labelSeparator: {
|
|
1319
|
+
type: String,
|
|
1320
|
+
default: "–"
|
|
1321
|
+
},
|
|
1322
|
+
locale: String,
|
|
1323
|
+
placeholder: String,
|
|
1324
|
+
label: [
|
|
1325
|
+
String,
|
|
1326
|
+
Number,
|
|
1327
|
+
Object,
|
|
1328
|
+
Function
|
|
1329
|
+
],
|
|
1330
|
+
clearable: Boolean,
|
|
1331
|
+
closeOnChange: {
|
|
1332
|
+
type: Boolean,
|
|
1333
|
+
default: true
|
|
1334
|
+
},
|
|
1335
|
+
sortDates: {
|
|
1336
|
+
type: Boolean,
|
|
1337
|
+
default: true
|
|
1338
|
+
},
|
|
1339
|
+
valueFormatter: Function
|
|
1340
|
+
},
|
|
1341
|
+
setup(props, { attrs }) {
|
|
1342
|
+
const finalValue = (0, vue.computed)(() => props.type === "multiple" ? [] : props.type === "range" ? [null, null] : null);
|
|
1343
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1344
|
+
value: (0, vue.computed)(() => props.value),
|
|
1345
|
+
defaultValue: props.defaultValue,
|
|
1346
|
+
finalValue: finalValue.value,
|
|
1347
|
+
onChange: (value) => props.onChange?.(value)
|
|
1348
|
+
});
|
|
1349
|
+
const opened = (0, vue.ref)(false);
|
|
1350
|
+
const formattedValue = (0, vue.computed)(() => formatValue(_value.value, props.type, props.valueFormat, props.locale, props.labelSeparator, props.valueFormatter));
|
|
1351
|
+
return () => (0, vue.h)(PickerInputBase, {
|
|
1352
|
+
...attrs,
|
|
1353
|
+
formattedValue: formattedValue.value,
|
|
1354
|
+
dropdownOpened: opened.value,
|
|
1355
|
+
label: props.label,
|
|
1356
|
+
placeholder: props.placeholder,
|
|
1357
|
+
clearable: props.clearable,
|
|
1358
|
+
onDropdownOpen: () => opened.value = true,
|
|
1359
|
+
onDropdownClose: () => opened.value = false,
|
|
1360
|
+
onClear: () => setValue(finalValue.value)
|
|
1361
|
+
}, { default: ({ close }) => (0, vue.h)(Picker, {
|
|
1362
|
+
...attrs,
|
|
1363
|
+
type: props.type,
|
|
1364
|
+
value: _value.value,
|
|
1365
|
+
sortDates: props.sortDates,
|
|
1366
|
+
defaultLevel,
|
|
1367
|
+
locale: props.locale,
|
|
1368
|
+
onChange: (value) => {
|
|
1369
|
+
setValue(value);
|
|
1370
|
+
if (props.closeOnChange && props.type === "default") close();
|
|
1371
|
+
}
|
|
1372
|
+
}) });
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
var DatePickerInput = createPickerInput("DatePickerInput", DatePicker);
|
|
1377
|
+
var MonthPickerInput = createPickerInput("MonthPickerInput", MonthPicker, "year", "MMMM YYYY");
|
|
1378
|
+
var YearPickerInput = createPickerInput("YearPickerInput", YearPicker, "decade", "YYYY");
|
|
1379
|
+
var HiddenDatesInput = (0, vue.defineComponent)({
|
|
1380
|
+
name: "HiddenDatesInput",
|
|
1381
|
+
props: {
|
|
1382
|
+
name: String,
|
|
1383
|
+
value: [
|
|
1384
|
+
String,
|
|
1385
|
+
Array,
|
|
1386
|
+
null
|
|
1387
|
+
]
|
|
1388
|
+
},
|
|
1389
|
+
setup(props) {
|
|
1390
|
+
return () => {
|
|
1391
|
+
const value = Array.isArray(props.value) ? props.value.filter(Boolean).join(",") : props.value || "";
|
|
1392
|
+
return (0, vue.h)("input", {
|
|
1393
|
+
type: "hidden",
|
|
1394
|
+
name: props.name,
|
|
1395
|
+
value
|
|
1396
|
+
});
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
function dateStringParser(value, format = "MMMM D, YYYY", locale) {
|
|
1401
|
+
return (0, dayjs.default)(value, format, locale || "en", true).format("YYYY-MM-DD");
|
|
1402
|
+
}
|
|
1403
|
+
function isDateValid({ date, minDate, maxDate }) {
|
|
1404
|
+
const parsed = (0, dayjs.default)(date);
|
|
1405
|
+
return parsed.isValid() && !isBeforeMin(parsed.format("YYYY-MM-DD"), minDate) && !isAfterMax(parsed.format("YYYY-MM-DD"), maxDate);
|
|
1406
|
+
}
|
|
1407
|
+
var DateInput = (0, vue.defineComponent)({
|
|
1408
|
+
name: "DateInput",
|
|
1409
|
+
inheritAttrs: false,
|
|
1410
|
+
props: {
|
|
1411
|
+
value: [
|
|
1412
|
+
String,
|
|
1413
|
+
Date,
|
|
1414
|
+
null
|
|
1415
|
+
],
|
|
1416
|
+
defaultValue: [
|
|
1417
|
+
String,
|
|
1418
|
+
Date,
|
|
1419
|
+
null
|
|
1420
|
+
],
|
|
1421
|
+
onChange: Function,
|
|
1422
|
+
valueFormat: {
|
|
1423
|
+
type: String,
|
|
1424
|
+
default: "MMMM D, YYYY"
|
|
1425
|
+
},
|
|
1426
|
+
dateParser: Function,
|
|
1427
|
+
locale: String,
|
|
1428
|
+
clearable: Boolean,
|
|
1429
|
+
minDate: [String, Date],
|
|
1430
|
+
maxDate: [String, Date],
|
|
1431
|
+
presets: Array
|
|
1432
|
+
},
|
|
1433
|
+
setup(props, { attrs }) {
|
|
1434
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1435
|
+
value: (0, vue.computed)(() => props.value === void 0 ? void 0 : normalizeDate(props.value)),
|
|
1436
|
+
defaultValue: normalizeDate(props.defaultValue),
|
|
1437
|
+
finalValue: null,
|
|
1438
|
+
onChange: (value) => props.onChange?.(value)
|
|
1439
|
+
});
|
|
1440
|
+
const formatValue = (value) => value ? (0, dayjs.default)(value).locale(props.locale || "en").format(props.valueFormat) : "";
|
|
1441
|
+
const inputValue = (0, vue.ref)(formatValue(_value.value));
|
|
1442
|
+
const opened = (0, vue.ref)(false);
|
|
1443
|
+
(0, vue.watch)(_value, (value) => {
|
|
1444
|
+
if (!opened.value) inputValue.value = formatValue(value);
|
|
1445
|
+
});
|
|
1446
|
+
const parseInput = (raw) => {
|
|
1447
|
+
const parsed = props.dateParser?.(raw) || dateStringParser(raw, props.valueFormat, props.locale);
|
|
1448
|
+
return (0, dayjs.default)(parsed).isValid() && isDateValid({
|
|
1449
|
+
date: parsed,
|
|
1450
|
+
minDate: props.minDate,
|
|
1451
|
+
maxDate: props.maxDate
|
|
1452
|
+
}) ? parsed : null;
|
|
1453
|
+
};
|
|
1454
|
+
const commit = () => {
|
|
1455
|
+
opened.value = false;
|
|
1456
|
+
if (!inputValue.value.trim()) {
|
|
1457
|
+
if (props.clearable) setValue(null);
|
|
1458
|
+
else inputValue.value = formatValue(_value.value);
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
const parsed = parseInput(inputValue.value);
|
|
1462
|
+
if (parsed) setValue(parsed);
|
|
1463
|
+
else inputValue.value = formatValue(_value.value);
|
|
1464
|
+
};
|
|
1465
|
+
const selectDay = (date) => {
|
|
1466
|
+
setValue(date);
|
|
1467
|
+
inputValue.value = formatValue(date);
|
|
1468
|
+
opened.value = false;
|
|
1469
|
+
};
|
|
1470
|
+
return () => (0, vue.h)(_mantine_vue_core.Box, null, () => (0, vue.h)(_mantine_vue_core.Popover, {
|
|
1471
|
+
opened: opened.value,
|
|
1472
|
+
onChange: (v) => opened.value = v,
|
|
1473
|
+
position: "bottom-start"
|
|
1474
|
+
}, () => [(0, vue.h)(_mantine_vue_core.Popover.Target, null, () => (0, vue.h)(_mantine_vue_core.InputBase, {
|
|
1475
|
+
...attrs,
|
|
1476
|
+
value: inputValue.value,
|
|
1477
|
+
onInput: (event) => inputValue.value = event.target.value,
|
|
1478
|
+
onFocus: () => opened.value = true,
|
|
1479
|
+
onClick: () => opened.value = true,
|
|
1480
|
+
onBlur: commit,
|
|
1481
|
+
onKeydown: (event) => {
|
|
1482
|
+
if (event.key === "Escape") opened.value = false;
|
|
1483
|
+
},
|
|
1484
|
+
rightSection: props.clearable && _value.value ? (0, vue.h)(_mantine_vue_core.CloseButton, {
|
|
1485
|
+
onMousedown: (event) => event.stopPropagation(),
|
|
1486
|
+
onClick: (event) => {
|
|
1487
|
+
event.stopPropagation();
|
|
1488
|
+
inputValue.value = "";
|
|
1489
|
+
setValue(null);
|
|
1490
|
+
}
|
|
1491
|
+
}) : void 0,
|
|
1492
|
+
rightSectionPointerEvents: props.clearable && _value.value ? "all" : void 0
|
|
1493
|
+
})), (0, vue.h)(_mantine_vue_core.Popover.Dropdown, { onMousedown: (event) => event.preventDefault() }, () => [props.presets?.length ? (0, vue.h)(_mantine_vue_core.Group, {
|
|
1494
|
+
gap: 4,
|
|
1495
|
+
mb: 4
|
|
1496
|
+
}, () => props.presets?.map((preset, index) => (0, vue.h)(_mantine_vue_core.Button, {
|
|
1497
|
+
key: index,
|
|
1498
|
+
size: "xs",
|
|
1499
|
+
variant: "light",
|
|
1500
|
+
onClick: () => selectDay(preset.value)
|
|
1501
|
+
}, () => preset.label))) : null, (0, vue.h)(Calendar, {
|
|
1502
|
+
defaultDate: _value.value || void 0,
|
|
1503
|
+
minDate: props.minDate,
|
|
1504
|
+
maxDate: props.maxDate,
|
|
1505
|
+
locale: props.locale,
|
|
1506
|
+
getDayProps: (date) => ({
|
|
1507
|
+
selected: isSameDate(date, _value.value),
|
|
1508
|
+
onClick: () => selectDay(date)
|
|
1509
|
+
})
|
|
1510
|
+
})])]));
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
function splitTimeString(value = "") {
|
|
1514
|
+
const [time = "", period] = value.split(" ");
|
|
1515
|
+
const [hours = "00", minutes = "00", seconds = "00"] = time.split(":");
|
|
1516
|
+
return {
|
|
1517
|
+
hours,
|
|
1518
|
+
minutes,
|
|
1519
|
+
seconds,
|
|
1520
|
+
period
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
function padTime(value) {
|
|
1524
|
+
return String(value).padStart(2, "0");
|
|
1525
|
+
}
|
|
1526
|
+
var defaultAmPmLabels = {
|
|
1527
|
+
am: "AM",
|
|
1528
|
+
pm: "PM"
|
|
1529
|
+
};
|
|
1530
|
+
function getParsedTime({ time, format, amPmLabels = defaultAmPmLabels }) {
|
|
1531
|
+
if (!time) return {
|
|
1532
|
+
hours: null,
|
|
1533
|
+
minutes: null,
|
|
1534
|
+
seconds: null,
|
|
1535
|
+
amPm: null
|
|
1536
|
+
};
|
|
1537
|
+
const { hours, minutes, seconds } = splitTimeString(time);
|
|
1538
|
+
const h24 = Number(hours);
|
|
1539
|
+
const m = Number(minutes);
|
|
1540
|
+
const s = Number(seconds);
|
|
1541
|
+
if (format === "12h") {
|
|
1542
|
+
const amPm = h24 >= 12 ? amPmLabels.pm : amPmLabels.am;
|
|
1543
|
+
return {
|
|
1544
|
+
hours: h24 % 12 === 0 ? 12 : h24 % 12,
|
|
1545
|
+
minutes: m,
|
|
1546
|
+
seconds: s,
|
|
1547
|
+
amPm
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
return {
|
|
1551
|
+
hours: h24,
|
|
1552
|
+
minutes: m,
|
|
1553
|
+
seconds: s,
|
|
1554
|
+
amPm: null
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
function getTimeString({ hours, minutes, seconds, format = "24h", withSeconds = false, amPm = null, amPmLabels = defaultAmPmLabels }) {
|
|
1558
|
+
if (hours === null || minutes === null) return {
|
|
1559
|
+
valid: false,
|
|
1560
|
+
value: ""
|
|
1561
|
+
};
|
|
1562
|
+
if (withSeconds && (seconds === null || seconds === void 0)) return {
|
|
1563
|
+
valid: false,
|
|
1564
|
+
value: ""
|
|
1565
|
+
};
|
|
1566
|
+
if (format === "24h") return {
|
|
1567
|
+
valid: true,
|
|
1568
|
+
value: `${padTime(hours)}:${padTime(minutes)}${withSeconds ? `:${padTime(seconds || 0)}` : ""}`
|
|
1569
|
+
};
|
|
1570
|
+
if (amPm === null) return {
|
|
1571
|
+
valid: false,
|
|
1572
|
+
value: ""
|
|
1573
|
+
};
|
|
1574
|
+
let h24 = hours;
|
|
1575
|
+
if (amPm === amPmLabels.pm && hours !== 12) h24 += 12;
|
|
1576
|
+
else if (amPm === amPmLabels.am && hours === 12) h24 = 0;
|
|
1577
|
+
return {
|
|
1578
|
+
valid: true,
|
|
1579
|
+
value: `${padTime(h24)}:${padTime(minutes)}${withSeconds ? `:${padTime(seconds || 0)}` : ""}`
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
function timeToSeconds(value) {
|
|
1583
|
+
const { hours, minutes, seconds } = splitTimeString(value);
|
|
1584
|
+
return Number(hours) * 3600 + Number(minutes) * 60 + Number(seconds || 0);
|
|
1585
|
+
}
|
|
1586
|
+
function isSameTime(a, b) {
|
|
1587
|
+
return !!a && !!b && timeToSeconds(a) === timeToSeconds(b);
|
|
1588
|
+
}
|
|
1589
|
+
function compareTime(a, b) {
|
|
1590
|
+
return timeToSeconds(a) - timeToSeconds(b);
|
|
1591
|
+
}
|
|
1592
|
+
function clampTime(value, min, max) {
|
|
1593
|
+
if (min && compareTime(value, min) < 0) return min;
|
|
1594
|
+
if (max && compareTime(value, max) > 0) return max;
|
|
1595
|
+
return value;
|
|
1596
|
+
}
|
|
1597
|
+
function getTimeRange(start, end, step = 60) {
|
|
1598
|
+
const result = [];
|
|
1599
|
+
for (let current = timeToSeconds(start); current <= timeToSeconds(end); current += step) {
|
|
1600
|
+
const hours = Math.floor(current / 3600);
|
|
1601
|
+
const minutes = Math.floor(current % 3600 / 60);
|
|
1602
|
+
result.push(`${padTime(hours)}:${padTime(minutes)}`);
|
|
1603
|
+
}
|
|
1604
|
+
return result;
|
|
1605
|
+
}
|
|
1606
|
+
var TimeInput = (0, vue.defineComponent)({
|
|
1607
|
+
name: "TimeInput",
|
|
1608
|
+
props: {
|
|
1609
|
+
withSeconds: Boolean,
|
|
1610
|
+
value: String,
|
|
1611
|
+
defaultValue: String,
|
|
1612
|
+
onChange: Function
|
|
1613
|
+
},
|
|
1614
|
+
setup(props, { attrs }) {
|
|
1615
|
+
return () => (0, vue.h)(_mantine_vue_core.InputBase, {
|
|
1616
|
+
...attrs,
|
|
1617
|
+
type: "time",
|
|
1618
|
+
step: props.withSeconds ? 1 : 60,
|
|
1619
|
+
value: props.value,
|
|
1620
|
+
defaultValue: props.defaultValue,
|
|
1621
|
+
onChange: props.onChange
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
var TimeGrid = (0, vue.defineComponent)({
|
|
1626
|
+
name: "TimeGrid",
|
|
1627
|
+
props: {
|
|
1628
|
+
data: {
|
|
1629
|
+
type: Array,
|
|
1630
|
+
default: () => []
|
|
1631
|
+
},
|
|
1632
|
+
value: String,
|
|
1633
|
+
defaultValue: String,
|
|
1634
|
+
minTime: String,
|
|
1635
|
+
maxTime: String,
|
|
1636
|
+
allowDeselect: Boolean,
|
|
1637
|
+
disabled: Boolean,
|
|
1638
|
+
onChange: Function,
|
|
1639
|
+
getControlProps: Function
|
|
1640
|
+
},
|
|
1641
|
+
setup(props, { attrs }) {
|
|
1642
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1643
|
+
value: (0, vue.computed)(() => props.value),
|
|
1644
|
+
defaultValue: props.defaultValue,
|
|
1645
|
+
finalValue: null,
|
|
1646
|
+
onChange: (value) => props.onChange?.(value)
|
|
1647
|
+
});
|
|
1648
|
+
return () => (0, vue.h)(_mantine_vue_core.Box, {
|
|
1649
|
+
...attrs,
|
|
1650
|
+
class: [Dates_module_default.timeGridRoot, attrs.class]
|
|
1651
|
+
}, () => (0, vue.h)(_mantine_vue_core.SimpleGrid, {
|
|
1652
|
+
cols: 3,
|
|
1653
|
+
spacing: "xs",
|
|
1654
|
+
class: Dates_module_default.timeGrid
|
|
1655
|
+
}, () => props.data.map((item) => {
|
|
1656
|
+
const isDisabled = props.disabled || props.minTime && compareTime(item, props.minTime) < 0 || props.maxTime && compareTime(item, props.maxTime) > 0;
|
|
1657
|
+
const controlProps = props.getControlProps?.(item) || {};
|
|
1658
|
+
const active = isSameTime(_value.value ?? void 0, item);
|
|
1659
|
+
return (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
1660
|
+
...controlProps,
|
|
1661
|
+
class: [Dates_module_default.timeGridControl, controlProps.class],
|
|
1662
|
+
disabled: isDisabled || controlProps.disabled,
|
|
1663
|
+
"data-active": active || void 0,
|
|
1664
|
+
"data-disabled": isDisabled || controlProps.disabled || void 0,
|
|
1665
|
+
onClick: (event) => {
|
|
1666
|
+
controlProps.onClick?.(event);
|
|
1667
|
+
if (isDisabled) return;
|
|
1668
|
+
const nextValue = props.allowDeselect && active ? null : item;
|
|
1669
|
+
if (nextValue !== _value.value) setValue(nextValue);
|
|
1670
|
+
}
|
|
1671
|
+
}, () => item);
|
|
1672
|
+
})));
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
var SpinInput = (0, vue.defineComponent)({
|
|
1676
|
+
name: "SpinInput",
|
|
1677
|
+
inheritAttrs: false,
|
|
1678
|
+
props: {
|
|
1679
|
+
value: {
|
|
1680
|
+
type: Number,
|
|
1681
|
+
default: null
|
|
1682
|
+
},
|
|
1683
|
+
min: {
|
|
1684
|
+
type: Number,
|
|
1685
|
+
required: true
|
|
1686
|
+
},
|
|
1687
|
+
max: {
|
|
1688
|
+
type: Number,
|
|
1689
|
+
required: true
|
|
1690
|
+
},
|
|
1691
|
+
onChange: Function,
|
|
1692
|
+
step: {
|
|
1693
|
+
type: Number,
|
|
1694
|
+
default: 1
|
|
1695
|
+
},
|
|
1696
|
+
onNextInput: Function,
|
|
1697
|
+
onPreviousInput: Function,
|
|
1698
|
+
allowTemporaryZero: Boolean,
|
|
1699
|
+
placeholder: {
|
|
1700
|
+
type: String,
|
|
1701
|
+
default: "--"
|
|
1702
|
+
},
|
|
1703
|
+
disableAutoAdvance: Boolean,
|
|
1704
|
+
disabled: Boolean,
|
|
1705
|
+
readOnly: Boolean
|
|
1706
|
+
},
|
|
1707
|
+
setup(props, { attrs }) {
|
|
1708
|
+
const maxDigit = () => Number(props.max.toFixed(0)[0]);
|
|
1709
|
+
const arrowsMax = () => props.max + 1 - props.step;
|
|
1710
|
+
const handleChange = (raw) => {
|
|
1711
|
+
if (props.readOnly) return;
|
|
1712
|
+
const clearValue = raw.replace(/\D/g, "");
|
|
1713
|
+
if (clearValue === "") return;
|
|
1714
|
+
let parsedValue = 0;
|
|
1715
|
+
for (let i = 0; i < clearValue.length; i += 1) {
|
|
1716
|
+
const digit = clearValue.charCodeAt(i) - 48;
|
|
1717
|
+
const next = parsedValue * 10 + digit;
|
|
1718
|
+
parsedValue = next > props.max ? digit : next;
|
|
1719
|
+
}
|
|
1720
|
+
const clampedValue = props.allowTemporaryZero && parsedValue === 0 && props.min > 0 ? 0 : Math.min(Math.max(parsedValue, props.min), props.max);
|
|
1721
|
+
props.onChange?.(clampedValue);
|
|
1722
|
+
if (!props.disableAutoAdvance && (clampedValue > maxDigit() || raw.startsWith("00"))) props.onNextInput?.();
|
|
1723
|
+
};
|
|
1724
|
+
const handleKeydown = (event) => {
|
|
1725
|
+
if (props.readOnly) return;
|
|
1726
|
+
if (event.key === "0" && props.value === 0) {
|
|
1727
|
+
event.preventDefault();
|
|
1728
|
+
props.onNextInput?.();
|
|
1729
|
+
}
|
|
1730
|
+
if (event.key === "Home") {
|
|
1731
|
+
event.preventDefault();
|
|
1732
|
+
props.onChange?.(props.min);
|
|
1733
|
+
}
|
|
1734
|
+
if (event.key === "End") {
|
|
1735
|
+
event.preventDefault();
|
|
1736
|
+
props.onChange?.(props.max);
|
|
1737
|
+
}
|
|
1738
|
+
if (event.key === "Backspace" || event.key === "Delete") {
|
|
1739
|
+
event.preventDefault();
|
|
1740
|
+
if (props.value !== null) props.onChange?.(null);
|
|
1741
|
+
else props.onPreviousInput?.();
|
|
1742
|
+
}
|
|
1743
|
+
if (event.key === "ArrowRight") {
|
|
1744
|
+
event.preventDefault();
|
|
1745
|
+
props.onNextInput?.();
|
|
1746
|
+
}
|
|
1747
|
+
if (event.key === "ArrowLeft") {
|
|
1748
|
+
event.preventDefault();
|
|
1749
|
+
props.onPreviousInput?.();
|
|
1750
|
+
}
|
|
1751
|
+
if (event.key === "ArrowUp") {
|
|
1752
|
+
event.preventDefault();
|
|
1753
|
+
const newValue = props.value === null ? props.min : Math.min(Math.max(props.value + props.step, props.min), arrowsMax());
|
|
1754
|
+
props.onChange?.(newValue);
|
|
1755
|
+
}
|
|
1756
|
+
if (event.key === "ArrowDown") {
|
|
1757
|
+
event.preventDefault();
|
|
1758
|
+
const newValue = props.value === null ? arrowsMax() : Math.min(Math.max(props.value - props.step, props.min), arrowsMax());
|
|
1759
|
+
props.onChange?.(newValue);
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
return () => (0, vue.h)("input", {
|
|
1763
|
+
...attrs,
|
|
1764
|
+
type: "text",
|
|
1765
|
+
role: "spinbutton",
|
|
1766
|
+
"aria-valuemin": props.min,
|
|
1767
|
+
"aria-valuemax": props.max,
|
|
1768
|
+
"aria-valuenow": props.value === null ? 0 : props.value,
|
|
1769
|
+
"data-empty": props.value === null || void 0,
|
|
1770
|
+
inputmode: "numeric",
|
|
1771
|
+
placeholder: props.placeholder,
|
|
1772
|
+
disabled: props.disabled,
|
|
1773
|
+
readonly: props.readOnly,
|
|
1774
|
+
value: props.value === null ? "" : padTime(props.value),
|
|
1775
|
+
onInput: (event) => handleChange(event.target.value),
|
|
1776
|
+
onKeydown: handleKeydown,
|
|
1777
|
+
onFocus: (event) => event.target.select(),
|
|
1778
|
+
onClick: (event) => {
|
|
1779
|
+
event.stopPropagation();
|
|
1780
|
+
event.target.select();
|
|
1781
|
+
},
|
|
1782
|
+
onMousedown: (event) => event.stopPropagation()
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
var AmPmInput = (0, vue.defineComponent)({
|
|
1787
|
+
name: "AmPmInput",
|
|
1788
|
+
props: {
|
|
1789
|
+
value: {
|
|
1790
|
+
type: String,
|
|
1791
|
+
default: null
|
|
1792
|
+
},
|
|
1793
|
+
labels: {
|
|
1794
|
+
type: Object,
|
|
1795
|
+
default: () => defaultAmPmLabels
|
|
1796
|
+
},
|
|
1797
|
+
onChange: Function,
|
|
1798
|
+
disabled: Boolean,
|
|
1799
|
+
readOnly: Boolean
|
|
1800
|
+
},
|
|
1801
|
+
setup(props, { attrs }) {
|
|
1802
|
+
return () => (0, vue.h)("select", {
|
|
1803
|
+
...attrs,
|
|
1804
|
+
class: Dates_module_default.timePickerField,
|
|
1805
|
+
"data-am-pm": true,
|
|
1806
|
+
disabled: props.disabled,
|
|
1807
|
+
value: props.value ?? props.labels.am,
|
|
1808
|
+
onChange: (event) => props.onChange?.(event.target.value)
|
|
1809
|
+
}, [(0, vue.h)("option", { value: props.labels.am }, props.labels.am), (0, vue.h)("option", { value: props.labels.pm }, props.labels.pm)]);
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
var TimeControlsList = (0, vue.defineComponent)({
|
|
1813
|
+
name: "TimeControlsList",
|
|
1814
|
+
props: {
|
|
1815
|
+
min: {
|
|
1816
|
+
type: Number,
|
|
1817
|
+
required: true
|
|
1818
|
+
},
|
|
1819
|
+
max: {
|
|
1820
|
+
type: Number,
|
|
1821
|
+
required: true
|
|
1822
|
+
},
|
|
1823
|
+
step: {
|
|
1824
|
+
type: Number,
|
|
1825
|
+
default: 1
|
|
1826
|
+
},
|
|
1827
|
+
value: {
|
|
1828
|
+
type: Number,
|
|
1829
|
+
default: null
|
|
1830
|
+
},
|
|
1831
|
+
onSelect: Function,
|
|
1832
|
+
formatValue: Function
|
|
1833
|
+
},
|
|
1834
|
+
setup(props) {
|
|
1835
|
+
return () => (0, vue.h)(_mantine_vue_core.ScrollArea, { h: 200 }, () => (0, vue.h)("div", { class: Dates_module_default.timePickerControlsList }, Array.from({ length: Math.floor((props.max - props.min) / props.step) + 1 }, (_, index) => props.min + index * props.step).map((item) => (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
1836
|
+
key: item,
|
|
1837
|
+
class: Dates_module_default.timePickerControl,
|
|
1838
|
+
"data-active": item === props.value || void 0,
|
|
1839
|
+
onClick: () => props.onSelect?.(item)
|
|
1840
|
+
}, () => props.formatValue ? props.formatValue(item) : padTime(item)))));
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
var TimePicker = (0, vue.defineComponent)({
|
|
1844
|
+
name: "TimePicker",
|
|
1845
|
+
props: {
|
|
1846
|
+
value: String,
|
|
1847
|
+
defaultValue: String,
|
|
1848
|
+
onChange: Function,
|
|
1849
|
+
withSeconds: Boolean,
|
|
1850
|
+
min: String,
|
|
1851
|
+
max: String,
|
|
1852
|
+
format: {
|
|
1853
|
+
type: String,
|
|
1854
|
+
default: "24h"
|
|
1855
|
+
},
|
|
1856
|
+
amPmLabels: {
|
|
1857
|
+
type: Object,
|
|
1858
|
+
default: () => defaultAmPmLabels
|
|
1859
|
+
},
|
|
1860
|
+
hoursStep: {
|
|
1861
|
+
type: Number,
|
|
1862
|
+
default: 1
|
|
1863
|
+
},
|
|
1864
|
+
minutesStep: {
|
|
1865
|
+
type: Number,
|
|
1866
|
+
default: 1
|
|
1867
|
+
},
|
|
1868
|
+
secondsStep: {
|
|
1869
|
+
type: Number,
|
|
1870
|
+
default: 1
|
|
1871
|
+
},
|
|
1872
|
+
clearable: Boolean,
|
|
1873
|
+
withDropdown: Boolean,
|
|
1874
|
+
disabled: Boolean,
|
|
1875
|
+
readOnly: Boolean,
|
|
1876
|
+
size: {
|
|
1877
|
+
type: [String, Number],
|
|
1878
|
+
default: "sm"
|
|
1879
|
+
},
|
|
1880
|
+
presets: Array,
|
|
1881
|
+
hoursRef: Object
|
|
1882
|
+
},
|
|
1883
|
+
setup(props, { attrs }) {
|
|
1884
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
1885
|
+
value: (0, vue.computed)(() => props.value),
|
|
1886
|
+
defaultValue: props.defaultValue,
|
|
1887
|
+
finalValue: "",
|
|
1888
|
+
onChange: (value) => props.onChange?.(value)
|
|
1889
|
+
});
|
|
1890
|
+
const parsed = (0, vue.computed)(() => getParsedTime({
|
|
1891
|
+
time: _value.value,
|
|
1892
|
+
format: props.format,
|
|
1893
|
+
amPmLabels: props.amPmLabels
|
|
1894
|
+
}));
|
|
1895
|
+
const hours = (0, vue.ref)(parsed.value.hours);
|
|
1896
|
+
const minutes = (0, vue.ref)(parsed.value.minutes);
|
|
1897
|
+
const seconds = (0, vue.ref)(parsed.value.seconds);
|
|
1898
|
+
const amPm = (0, vue.ref)(parsed.value.amPm);
|
|
1899
|
+
(0, vue.watch)(_value, (value) => {
|
|
1900
|
+
const next = getParsedTime({
|
|
1901
|
+
time: value,
|
|
1902
|
+
format: props.format,
|
|
1903
|
+
amPmLabels: props.amPmLabels
|
|
1904
|
+
});
|
|
1905
|
+
hours.value = next.hours;
|
|
1906
|
+
minutes.value = next.minutes;
|
|
1907
|
+
seconds.value = next.seconds;
|
|
1908
|
+
amPm.value = next.amPm;
|
|
1909
|
+
});
|
|
1910
|
+
const hoursRef = (0, vue.ref)();
|
|
1911
|
+
const minutesRef = (0, vue.ref)();
|
|
1912
|
+
const secondsRef = (0, vue.ref)();
|
|
1913
|
+
const amPmRef = (0, vue.ref)();
|
|
1914
|
+
const focusRef = (target) => {
|
|
1915
|
+
(target?.$el ?? target)?.focus?.();
|
|
1916
|
+
};
|
|
1917
|
+
const focus = (field) => {
|
|
1918
|
+
focusRef((field === "hours" ? hoursRef : field === "minutes" ? minutesRef : field === "seconds" ? secondsRef : amPmRef).value);
|
|
1919
|
+
};
|
|
1920
|
+
(0, vue.watch)(hoursRef, (val) => {
|
|
1921
|
+
if (props.hoursRef) props.hoursRef.value = val?.$el ?? val;
|
|
1922
|
+
}, { immediate: true });
|
|
1923
|
+
const commit = () => {
|
|
1924
|
+
const result = getTimeString({
|
|
1925
|
+
hours: hours.value,
|
|
1926
|
+
minutes: minutes.value,
|
|
1927
|
+
seconds: seconds.value,
|
|
1928
|
+
format: props.format,
|
|
1929
|
+
withSeconds: props.withSeconds,
|
|
1930
|
+
amPm: amPm.value,
|
|
1931
|
+
amPmLabels: props.amPmLabels
|
|
1932
|
+
});
|
|
1933
|
+
setValue(result.valid ? result.value : "");
|
|
1934
|
+
};
|
|
1935
|
+
const setHours = (value) => {
|
|
1936
|
+
let adjusted = value;
|
|
1937
|
+
if (props.format === "12h" && typeof value === "number" && value > 12) adjusted = (value - 1) % 12 + 1;
|
|
1938
|
+
hours.value = adjusted;
|
|
1939
|
+
commit();
|
|
1940
|
+
focus("hours");
|
|
1941
|
+
};
|
|
1942
|
+
const setMinutes = (value) => {
|
|
1943
|
+
minutes.value = value;
|
|
1944
|
+
commit();
|
|
1945
|
+
focus("minutes");
|
|
1946
|
+
};
|
|
1947
|
+
const setSeconds = (value) => {
|
|
1948
|
+
seconds.value = value;
|
|
1949
|
+
commit();
|
|
1950
|
+
focus("seconds");
|
|
1951
|
+
};
|
|
1952
|
+
const setAmPm = (value) => {
|
|
1953
|
+
amPm.value = value;
|
|
1954
|
+
commit();
|
|
1955
|
+
focus("amPm");
|
|
1956
|
+
};
|
|
1957
|
+
const clear = () => {
|
|
1958
|
+
hours.value = null;
|
|
1959
|
+
minutes.value = null;
|
|
1960
|
+
seconds.value = null;
|
|
1961
|
+
amPm.value = null;
|
|
1962
|
+
setValue("");
|
|
1963
|
+
focus("hours");
|
|
1964
|
+
};
|
|
1965
|
+
const isClearable = (0, vue.computed)(() => props.clearable && !props.readOnly && !props.disabled && (hours.value !== null || minutes.value !== null || seconds.value !== null || amPm.value !== null));
|
|
1966
|
+
const opened = (0, vue.ref)(false);
|
|
1967
|
+
return () => (0, vue.h)(_mantine_vue_core.Popover, {
|
|
1968
|
+
opened: props.withDropdown && opened.value,
|
|
1969
|
+
position: "bottom-start",
|
|
1970
|
+
transitionProps: { duration: 0 }
|
|
1971
|
+
}, () => [(0, vue.h)(_mantine_vue_core.Popover.Target, null, () => (0, vue.h)(_mantine_vue_core.InputBase, {
|
|
1972
|
+
...attrs,
|
|
1973
|
+
component: "div",
|
|
1974
|
+
size: props.size,
|
|
1975
|
+
disabled: props.disabled,
|
|
1976
|
+
onClick: () => {
|
|
1977
|
+
focus("hours");
|
|
1978
|
+
if (props.withDropdown) opened.value = true;
|
|
1979
|
+
},
|
|
1980
|
+
onMousedown: (event) => event.preventDefault(),
|
|
1981
|
+
onFocusin: () => {
|
|
1982
|
+
if (props.withDropdown) opened.value = true;
|
|
1983
|
+
},
|
|
1984
|
+
onFocusout: () => {
|
|
1985
|
+
if (props.withDropdown) opened.value = false;
|
|
1986
|
+
},
|
|
1987
|
+
rightSection: isClearable.value ? (0, vue.h)(_mantine_vue_core.CloseButton, {
|
|
1988
|
+
size: props.size,
|
|
1989
|
+
onMousedown: (event) => event.preventDefault(),
|
|
1990
|
+
onClick: clear
|
|
1991
|
+
}) : void 0,
|
|
1992
|
+
rightSectionPointerEvents: isClearable.value ? "all" : void 0
|
|
1993
|
+
}, () => [(0, vue.h)("div", {
|
|
1994
|
+
class: Dates_module_default.timePickerFieldsRoot,
|
|
1995
|
+
dir: "ltr"
|
|
1996
|
+
}, [(0, vue.h)("div", { class: Dates_module_default.timePickerFieldsGroup }, [
|
|
1997
|
+
(0, vue.h)(SpinInput, {
|
|
1998
|
+
ref: hoursRef,
|
|
1999
|
+
class: Dates_module_default.timePickerField,
|
|
2000
|
+
value: hours.value,
|
|
2001
|
+
min: props.format === "12h" ? 1 : 0,
|
|
2002
|
+
max: props.format === "12h" ? 12 : 23,
|
|
2003
|
+
step: props.hoursStep,
|
|
2004
|
+
onChange: setHours,
|
|
2005
|
+
onNextInput: () => focus("minutes"),
|
|
2006
|
+
allowTemporaryZero: props.format === "12h",
|
|
2007
|
+
readOnly: props.readOnly,
|
|
2008
|
+
disabled: props.disabled,
|
|
2009
|
+
placeholder: "--"
|
|
2010
|
+
}),
|
|
2011
|
+
(0, vue.h)("span", ":"),
|
|
2012
|
+
(0, vue.h)(SpinInput, {
|
|
2013
|
+
ref: minutesRef,
|
|
2014
|
+
class: Dates_module_default.timePickerField,
|
|
2015
|
+
value: minutes.value,
|
|
2016
|
+
min: 0,
|
|
2017
|
+
max: 59,
|
|
2018
|
+
step: props.minutesStep,
|
|
2019
|
+
onChange: setMinutes,
|
|
2020
|
+
onPreviousInput: () => focus("hours"),
|
|
2021
|
+
onNextInput: () => focus(props.withSeconds ? "seconds" : "amPm"),
|
|
2022
|
+
readOnly: props.readOnly,
|
|
2023
|
+
disabled: props.disabled,
|
|
2024
|
+
placeholder: "--"
|
|
2025
|
+
}),
|
|
2026
|
+
props.withSeconds ? (0, vue.h)("span", ":") : null,
|
|
2027
|
+
props.withSeconds ? (0, vue.h)(SpinInput, {
|
|
2028
|
+
ref: secondsRef,
|
|
2029
|
+
class: Dates_module_default.timePickerField,
|
|
2030
|
+
value: seconds.value,
|
|
2031
|
+
min: 0,
|
|
2032
|
+
max: 59,
|
|
2033
|
+
step: props.secondsStep,
|
|
2034
|
+
onChange: setSeconds,
|
|
2035
|
+
onPreviousInput: () => focus("minutes"),
|
|
2036
|
+
onNextInput: () => focus("amPm"),
|
|
2037
|
+
readOnly: props.readOnly,
|
|
2038
|
+
disabled: props.disabled,
|
|
2039
|
+
placeholder: "--"
|
|
2040
|
+
}) : null,
|
|
2041
|
+
props.format === "12h" ? (0, vue.h)(AmPmInput, {
|
|
2042
|
+
ref: amPmRef,
|
|
2043
|
+
value: amPm.value,
|
|
2044
|
+
labels: props.amPmLabels,
|
|
2045
|
+
onChange: setAmPm,
|
|
2046
|
+
readOnly: props.readOnly,
|
|
2047
|
+
disabled: props.disabled
|
|
2048
|
+
}) : null
|
|
2049
|
+
])])])), (0, vue.h)(_mantine_vue_core.Popover.Dropdown, {
|
|
2050
|
+
class: Dates_module_default.timePickerDropdown,
|
|
2051
|
+
onMousedown: (event) => event.preventDefault()
|
|
2052
|
+
}, () => [props.presets?.length ? (0, vue.h)(_mantine_vue_core.Group, {
|
|
2053
|
+
gap: 4,
|
|
2054
|
+
class: Dates_module_default.timePickerPresetsGroup
|
|
2055
|
+
}, () => props.presets?.map((preset) => (0, vue.h)(_mantine_vue_core.Button, {
|
|
2056
|
+
size: "xs",
|
|
2057
|
+
variant: "light",
|
|
2058
|
+
onClick: () => setValue(preset.value)
|
|
2059
|
+
}, () => preset.label))) : (0, vue.h)("div", { class: Dates_module_default.timePickerControlsListGroup }, [
|
|
2060
|
+
(0, vue.h)(TimeControlsList, {
|
|
2061
|
+
min: props.format === "12h" ? 1 : 0,
|
|
2062
|
+
max: props.format === "12h" ? 12 : 23,
|
|
2063
|
+
step: props.hoursStep,
|
|
2064
|
+
value: hours.value,
|
|
2065
|
+
onSelect: setHours
|
|
2066
|
+
}),
|
|
2067
|
+
(0, vue.h)(TimeControlsList, {
|
|
2068
|
+
min: 0,
|
|
2069
|
+
max: 59,
|
|
2070
|
+
step: props.minutesStep,
|
|
2071
|
+
value: minutes.value,
|
|
2072
|
+
onSelect: setMinutes
|
|
2073
|
+
}),
|
|
2074
|
+
props.withSeconds ? (0, vue.h)(TimeControlsList, {
|
|
2075
|
+
min: 0,
|
|
2076
|
+
max: 59,
|
|
2077
|
+
step: props.secondsStep,
|
|
2078
|
+
value: seconds.value,
|
|
2079
|
+
onSelect: setSeconds
|
|
2080
|
+
}) : null
|
|
2081
|
+
])])]);
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
var TimeValue = (0, vue.defineComponent)({
|
|
2085
|
+
name: "TimeValue",
|
|
2086
|
+
props: {
|
|
2087
|
+
value: {
|
|
2088
|
+
type: [String, Date],
|
|
2089
|
+
required: true
|
|
2090
|
+
},
|
|
2091
|
+
format: {
|
|
2092
|
+
type: String,
|
|
2093
|
+
default: "HH:mm"
|
|
2094
|
+
},
|
|
2095
|
+
locale: String
|
|
2096
|
+
},
|
|
2097
|
+
setup(props, { attrs }) {
|
|
2098
|
+
return () => (0, vue.h)(_mantine_vue_core.Text, attrs, () => (props.value instanceof Date ? (0, dayjs.default)(props.value) : (0, dayjs.default)(`2024-01-01 ${props.value}`)).locale(props.locale || "en").format(props.format));
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
var DateTimePicker = (0, vue.defineComponent)({
|
|
2102
|
+
name: "DateTimePicker",
|
|
2103
|
+
props: {
|
|
2104
|
+
value: [
|
|
2105
|
+
String,
|
|
2106
|
+
Date,
|
|
2107
|
+
null
|
|
2108
|
+
],
|
|
2109
|
+
defaultValue: [
|
|
2110
|
+
String,
|
|
2111
|
+
Date,
|
|
2112
|
+
null
|
|
2113
|
+
],
|
|
2114
|
+
onChange: Function,
|
|
2115
|
+
valueFormat: {
|
|
2116
|
+
type: String,
|
|
2117
|
+
default: "MMMM D, YYYY h:mm A"
|
|
2118
|
+
},
|
|
2119
|
+
clearable: Boolean,
|
|
2120
|
+
withSeconds: Boolean,
|
|
2121
|
+
size: {
|
|
2122
|
+
type: [String, Number],
|
|
2123
|
+
default: "sm"
|
|
2124
|
+
},
|
|
2125
|
+
submitButtonProps: Object
|
|
2126
|
+
},
|
|
2127
|
+
setup(props, { attrs }) {
|
|
2128
|
+
const hoursRef = (0, vue.ref)();
|
|
2129
|
+
const [_value, setValue] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
2130
|
+
value: (0, vue.computed)(() => props.value === void 0 ? void 0 : props.value === null ? null : new Date(props.value)),
|
|
2131
|
+
defaultValue: props.defaultValue ? new Date(props.defaultValue) : null,
|
|
2132
|
+
finalValue: null,
|
|
2133
|
+
onChange: (value) => props.onChange?.(value)
|
|
2134
|
+
});
|
|
2135
|
+
const date = (0, vue.computed)(() => _value.value ? (0, dayjs.default)(_value.value).format("YYYY-MM-DD") : null);
|
|
2136
|
+
const time = (0, vue.computed)(() => _value.value ? (0, dayjs.default)(_value.value).format(props.withSeconds ? "HH:mm:ss" : "HH:mm") : "");
|
|
2137
|
+
const updateDate = (nextDate) => {
|
|
2138
|
+
if (!nextDate || Array.isArray(nextDate)) return;
|
|
2139
|
+
setValue(assignTime(nextDate, `2024-01-01 ${time.value || "00:00"}`));
|
|
2140
|
+
hoursRef.value?.focus?.();
|
|
2141
|
+
};
|
|
2142
|
+
const updateTime = (nextTime) => {
|
|
2143
|
+
if (date.value) setValue(assignTime(date.value, `2024-01-01 ${nextTime}`));
|
|
2144
|
+
};
|
|
2145
|
+
return () => (0, vue.h)(PickerInputBase, {
|
|
2146
|
+
...attrs,
|
|
2147
|
+
formattedValue: _value.value ? (0, dayjs.default)(_value.value).format(props.valueFormat) : "",
|
|
2148
|
+
clearable: props.clearable,
|
|
2149
|
+
onClear: () => setValue(null)
|
|
2150
|
+
}, { default: ({ close }) => (0, vue.h)("div", { class: Dates_module_default.dateTimePicker }, [(0, vue.h)(DatePicker, {
|
|
2151
|
+
fullWidth: false,
|
|
2152
|
+
value: date.value,
|
|
2153
|
+
onChange: updateDate
|
|
2154
|
+
}), (0, vue.h)("div", { class: Dates_module_default.timeWrapper }, [(0, vue.h)("div", { class: Dates_module_default.timeInput }, [(0, vue.h)(TimePicker, {
|
|
2155
|
+
value: time.value,
|
|
2156
|
+
withSeconds: props.withSeconds,
|
|
2157
|
+
size: props.size,
|
|
2158
|
+
hoursRef,
|
|
2159
|
+
onChange: updateTime
|
|
2160
|
+
})]), (0, vue.h)(_mantine_vue_core.ActionIcon, {
|
|
2161
|
+
variant: "default",
|
|
2162
|
+
size: `input-${props.size || "sm"}`,
|
|
2163
|
+
"data-mantine-stop-propagation": true,
|
|
2164
|
+
...props.submitButtonProps,
|
|
2165
|
+
onClick: (event) => {
|
|
2166
|
+
props.submitButtonProps?.onClick?.(event);
|
|
2167
|
+
close();
|
|
2168
|
+
}
|
|
2169
|
+
}, () => (0, vue.h)(_mantine_vue_core.CheckIcon, { size: "30%" }))])]) });
|
|
2170
|
+
}
|
|
2171
|
+
});
|
|
2172
|
+
var InlineDateTimePicker = DateTimePicker;
|
|
2173
|
+
var MiniCalendar = (0, vue.defineComponent)({
|
|
2174
|
+
name: "MiniCalendar",
|
|
2175
|
+
props: {
|
|
2176
|
+
date: [String, Date],
|
|
2177
|
+
defaultDate: [String, Date],
|
|
2178
|
+
onDateChange: Function,
|
|
2179
|
+
value: [
|
|
2180
|
+
String,
|
|
2181
|
+
Date,
|
|
2182
|
+
null
|
|
2183
|
+
],
|
|
2184
|
+
onChange: Function,
|
|
2185
|
+
maxDate: [String, Date],
|
|
2186
|
+
minDate: [String, Date],
|
|
2187
|
+
numberOfDays: {
|
|
2188
|
+
type: Number,
|
|
2189
|
+
default: 7
|
|
2190
|
+
},
|
|
2191
|
+
monthLabelFormat: {
|
|
2192
|
+
type: String,
|
|
2193
|
+
default: "MMM"
|
|
2194
|
+
},
|
|
2195
|
+
onNext: Function,
|
|
2196
|
+
onPrevious: Function,
|
|
2197
|
+
getDayProps: Function,
|
|
2198
|
+
size: {
|
|
2199
|
+
type: String,
|
|
2200
|
+
default: "sm"
|
|
2201
|
+
},
|
|
2202
|
+
previousControlProps: Object,
|
|
2203
|
+
nextControlProps: Object,
|
|
2204
|
+
locale: String
|
|
2205
|
+
},
|
|
2206
|
+
setup(props, { attrs }) {
|
|
2207
|
+
const ctx = useDatesContext();
|
|
2208
|
+
const [_date, setDate] = (0, _mantine_vue_hooks.useUncontrolled)({
|
|
2209
|
+
value: (0, vue.computed)(() => toDateString(props.date ?? null) ?? void 0),
|
|
2210
|
+
defaultValue: toDateString(props.defaultDate ?? null) ?? void 0,
|
|
2211
|
+
finalValue: toDateString(props.value ?? null) || (0, dayjs.default)().format("YYYY-MM-DD"),
|
|
2212
|
+
onChange: (value) => props.onDateChange?.(value)
|
|
2213
|
+
});
|
|
2214
|
+
const handleNext = () => {
|
|
2215
|
+
props.onNext?.();
|
|
2216
|
+
setDate((0, dayjs.default)(_date.value).add(props.numberOfDays, "days").format("YYYY-MM-DD"));
|
|
2217
|
+
};
|
|
2218
|
+
const handlePrevious = () => {
|
|
2219
|
+
props.onPrevious?.();
|
|
2220
|
+
setDate((0, dayjs.default)(_date.value).subtract(props.numberOfDays, "days").format("YYYY-MM-DD"));
|
|
2221
|
+
};
|
|
2222
|
+
return () => {
|
|
2223
|
+
const previousDisabled = props.minDate ? (0, dayjs.default)(_date.value).subtract(1, "days").isBefore((0, dayjs.default)(props.minDate)) : false;
|
|
2224
|
+
const nextDisabled = props.maxDate ? (0, dayjs.default)(_date.value).add(props.numberOfDays, "days").isAfter((0, dayjs.default)(props.maxDate)) : false;
|
|
2225
|
+
const range = Array.from({ length: props.numberOfDays }, (_, index) => (0, dayjs.default)(_date.value).add(index, "days")).map((date) => {
|
|
2226
|
+
const disabled = props.minDate && date.isBefore((0, dayjs.default)(props.minDate), "day") || props.maxDate && date.isAfter((0, dayjs.default)(props.maxDate), "day") || false;
|
|
2227
|
+
const dayProps = props.getDayProps?.(toDateString(date.format("YYYY-MM-DD"))) || {};
|
|
2228
|
+
return (0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
2229
|
+
key: date.toString(),
|
|
2230
|
+
disabled,
|
|
2231
|
+
"aria-label": date.format("YYYY-MM-DD"),
|
|
2232
|
+
"data-disabled": disabled || void 0,
|
|
2233
|
+
"data-selected": props.value && (0, dayjs.default)(date).isSame(props.value, "day") || void 0,
|
|
2234
|
+
...dayProps,
|
|
2235
|
+
class: [Dates_module_default.miniCalendarDay, dayProps.class],
|
|
2236
|
+
onClick: (event) => {
|
|
2237
|
+
dayProps.onClick?.(event);
|
|
2238
|
+
props.onChange?.(toDateString(date.format("YYYY-MM-DD")));
|
|
2239
|
+
}
|
|
2240
|
+
}, () => [(0, vue.h)("span", { class: Dates_module_default.miniCalendarDayMonth }, date.locale(props.locale || ctx.locale).format(props.monthLabelFormat)), (0, vue.h)("span", { class: Dates_module_default.miniCalendarDayNumber }, String(date.date()))]);
|
|
2241
|
+
});
|
|
2242
|
+
return (0, vue.h)(_mantine_vue_core.Box, {
|
|
2243
|
+
...attrs,
|
|
2244
|
+
class: [Dates_module_default.miniCalendarRoot, attrs.class]
|
|
2245
|
+
}, () => [
|
|
2246
|
+
(0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
2247
|
+
onClick: handlePrevious,
|
|
2248
|
+
disabled: previousDisabled,
|
|
2249
|
+
"data-disabled": previousDisabled || void 0,
|
|
2250
|
+
"data-direction": "previous",
|
|
2251
|
+
...props.previousControlProps,
|
|
2252
|
+
class: [Dates_module_default.miniCalendarControl, props.previousControlProps?.class]
|
|
2253
|
+
}, () => props.previousControlProps?.children || (0, vue.h)(_mantine_vue_core.AccordionChevron, {
|
|
2254
|
+
"data-chevron": true,
|
|
2255
|
+
size: props.size
|
|
2256
|
+
})),
|
|
2257
|
+
(0, vue.h)("div", { class: Dates_module_default.miniCalendarDays }, range),
|
|
2258
|
+
(0, vue.h)(_mantine_vue_core.UnstyledButton, {
|
|
2259
|
+
onClick: handleNext,
|
|
2260
|
+
disabled: nextDisabled,
|
|
2261
|
+
"data-disabled": nextDisabled || void 0,
|
|
2262
|
+
"data-direction": "next",
|
|
2263
|
+
...props.nextControlProps,
|
|
2264
|
+
class: [Dates_module_default.miniCalendarControl, props.nextControlProps?.class]
|
|
2265
|
+
}, () => props.nextControlProps?.children || (0, vue.h)(_mantine_vue_core.AccordionChevron, {
|
|
2266
|
+
"data-chevron": true,
|
|
2267
|
+
size: props.size
|
|
2268
|
+
}))
|
|
2269
|
+
]);
|
|
2270
|
+
};
|
|
2271
|
+
}
|
|
2272
|
+
});
|
|
2273
|
+
var getFormattedTime = ({ value, format = "HH:mm" }) => (value instanceof Date ? (0, dayjs.default)(value) : (0, dayjs.default)(`2024-01-01 ${value}`)).format(format);
|
|
2274
|
+
//#endregion
|
|
2275
|
+
exports.AmPmInput = AmPmInput;
|
|
2276
|
+
exports.Calendar = Calendar;
|
|
2277
|
+
exports.CalendarHeader = CalendarHeader;
|
|
2278
|
+
exports.DateInput = DateInput;
|
|
2279
|
+
exports.DatePicker = DatePicker;
|
|
2280
|
+
exports.DatePickerInput = DatePickerInput;
|
|
2281
|
+
exports.DateTimePicker = DateTimePicker;
|
|
2282
|
+
exports.DatesProvider = DatesProvider;
|
|
2283
|
+
exports.Day = Day;
|
|
2284
|
+
exports.DecadeLevel = DecadeLevel;
|
|
2285
|
+
exports.DecadeLevelGroup = DecadeLevelGroup;
|
|
2286
|
+
exports.HiddenDatesInput = HiddenDatesInput;
|
|
2287
|
+
exports.InlineDateTimePicker = InlineDateTimePicker;
|
|
2288
|
+
exports.LevelsGroup = LevelsGroup;
|
|
2289
|
+
exports.MiniCalendar = MiniCalendar;
|
|
2290
|
+
exports.Month = Month;
|
|
2291
|
+
exports.MonthLevel = MonthLevel;
|
|
2292
|
+
exports.MonthLevelGroup = MonthLevelGroup;
|
|
2293
|
+
exports.MonthPicker = MonthPicker;
|
|
2294
|
+
exports.MonthPickerInput = MonthPickerInput;
|
|
2295
|
+
exports.MonthsList = MonthsList;
|
|
2296
|
+
exports.PickerControl = PickerControl;
|
|
2297
|
+
exports.PickerInputBase = PickerInputBase;
|
|
2298
|
+
exports.SpinInput = SpinInput;
|
|
2299
|
+
exports.TimeControlsList = TimeControlsList;
|
|
2300
|
+
exports.TimeGrid = TimeGrid;
|
|
2301
|
+
exports.TimeInput = TimeInput;
|
|
2302
|
+
exports.TimePicker = TimePicker;
|
|
2303
|
+
exports.TimeValue = TimeValue;
|
|
2304
|
+
exports.WeekdaysRow = WeekdaysRow;
|
|
2305
|
+
exports.YearLevel = YearLevel;
|
|
2306
|
+
exports.YearLevelGroup = YearLevelGroup;
|
|
2307
|
+
exports.YearPicker = YearPicker;
|
|
2308
|
+
exports.YearPickerInput = YearPickerInput;
|
|
2309
|
+
exports.YearsList = YearsList;
|
|
2310
|
+
exports.assignTime = assignTime;
|
|
2311
|
+
exports.clampDate = clampDate;
|
|
2312
|
+
exports.clampTime = clampTime;
|
|
2313
|
+
exports.compareTime = compareTime;
|
|
2314
|
+
exports.dateStringParser = dateStringParser;
|
|
2315
|
+
exports.getDefaultClampedDate = getDefaultClampedDate;
|
|
2316
|
+
exports.getEndOfWeek = getEndOfWeek;
|
|
2317
|
+
exports.getFormattedDate = getFormattedDate;
|
|
2318
|
+
exports.getFormattedTime = getFormattedTime;
|
|
2319
|
+
exports.getParsedTime = getParsedTime;
|
|
2320
|
+
exports.getStartOfWeek = getStartOfWeek;
|
|
2321
|
+
exports.getTimeRange = getTimeRange;
|
|
2322
|
+
exports.getTimeString = getTimeString;
|
|
2323
|
+
exports.getTimezoneOffset = getTimezoneOffset;
|
|
2324
|
+
exports.getWeekNumber = getWeekNumber;
|
|
2325
|
+
exports.handleControlKeyDown = handleControlKeyDown;
|
|
2326
|
+
exports.isDateValid = isDateValid;
|
|
2327
|
+
exports.isSameDate = isSameDate;
|
|
2328
|
+
exports.isSameMonth = isSameMonth;
|
|
2329
|
+
exports.isSameTime = isSameTime;
|
|
2330
|
+
exports.isSameYear = isSameYear;
|
|
2331
|
+
exports.padTime = padTime;
|
|
2332
|
+
exports.shiftTimezone = shiftTimezone;
|
|
2333
|
+
exports.timeToSeconds = timeToSeconds;
|
|
2334
|
+
exports.toDateString = toDateString;
|
|
2335
|
+
exports.useDatesContext = useDatesContext;
|
|
2336
|
+
|
|
2337
|
+
//# sourceMappingURL=index.cjs.map
|