@bricks-toolkit/toolkit 0.1.19 → 0.1.20
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/dist/chunk-4PRNRENN.mjs +104 -0
- package/dist/chunk-E6KUCC56.mjs +804 -0
- package/dist/chunk-FK5HAWIU.cjs +531 -0
- package/dist/chunk-HG4BPC2T.cjs +806 -0
- package/dist/chunk-J53N2LAE.cjs +115 -0
- package/dist/chunk-LKNQH36V.mjs +529 -0
- package/dist/chunk-M5V2IWA6.mjs +565 -0
- package/dist/chunk-WVRXSANT.cjs +567 -0
- package/dist/date-picker/index.cjs +3 -2
- package/dist/date-picker/index.d.mts +23 -3
- package/dist/date-picker/index.d.ts +23 -3
- package/dist/date-picker/index.mjs +2 -1
- package/dist/date-time-picker/index.cjs +12 -0
- package/dist/date-time-picker/index.d.mts +52 -0
- package/dist/date-time-picker/index.d.ts +52 -0
- package/dist/date-time-picker/index.mjs +3 -0
- package/dist/index.cjs +27 -21
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +7 -5
- package/dist/time-picker/index.cjs +2 -2
- package/dist/time-picker/index.d.mts +22 -3
- package/dist/time-picker/index.d.ts +22 -3
- package/dist/time-picker/index.mjs +1 -1
- package/package.json +11 -1
- package/dist/chunk-7WNJ7L4Z.mjs +0 -335
- package/dist/chunk-DHC5LI2P.cjs +0 -338
- package/dist/chunk-VKQDW7C2.mjs +0 -336
- package/dist/chunk-W2ZAPLQH.cjs +0 -337
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/components/DatePicker/calendar.utils.ts
|
|
2
|
+
var MONTH_NAMES = [
|
|
3
|
+
"January",
|
|
4
|
+
"February",
|
|
5
|
+
"March",
|
|
6
|
+
"April",
|
|
7
|
+
"May",
|
|
8
|
+
"June",
|
|
9
|
+
"July",
|
|
10
|
+
"August",
|
|
11
|
+
"September",
|
|
12
|
+
"October",
|
|
13
|
+
"November",
|
|
14
|
+
"December"
|
|
15
|
+
];
|
|
16
|
+
var MONTH_NAMES_SHORT = [
|
|
17
|
+
"Jan",
|
|
18
|
+
"Feb",
|
|
19
|
+
"Mar",
|
|
20
|
+
"Apr",
|
|
21
|
+
"May",
|
|
22
|
+
"Jun",
|
|
23
|
+
"Jul",
|
|
24
|
+
"Aug",
|
|
25
|
+
"Sep",
|
|
26
|
+
"Oct",
|
|
27
|
+
"Nov",
|
|
28
|
+
"Dec"
|
|
29
|
+
];
|
|
30
|
+
var DAY_NAMES_SHORT = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
31
|
+
function getDaysInMonth(year, month) {
|
|
32
|
+
return new Date(year, month + 1, 0).getDate();
|
|
33
|
+
}
|
|
34
|
+
function getFirstDayOfMonth(year, month) {
|
|
35
|
+
return new Date(year, month, 1).getDay();
|
|
36
|
+
}
|
|
37
|
+
function buildCalendarGrid(year, month) {
|
|
38
|
+
const firstDay = getFirstDayOfMonth(year, month);
|
|
39
|
+
const daysInMonth = getDaysInMonth(year, month);
|
|
40
|
+
const grid = [];
|
|
41
|
+
let day = 1;
|
|
42
|
+
for (let row = 0; row < 6; row++) {
|
|
43
|
+
const week = [];
|
|
44
|
+
for (let col = 0; col < 7; col++) {
|
|
45
|
+
const idx = row * 7 + col;
|
|
46
|
+
if (idx < firstDay || day > daysInMonth) {
|
|
47
|
+
week.push(null);
|
|
48
|
+
} else {
|
|
49
|
+
week.push(new Date(year, month, day++));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
grid.push(week);
|
|
53
|
+
if (day > daysInMonth) break;
|
|
54
|
+
}
|
|
55
|
+
return grid;
|
|
56
|
+
}
|
|
57
|
+
function isSameDay(a, b) {
|
|
58
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
59
|
+
}
|
|
60
|
+
function isBeforeDay(date, min) {
|
|
61
|
+
const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
62
|
+
const m = new Date(min.getFullYear(), min.getMonth(), min.getDate());
|
|
63
|
+
return d < m;
|
|
64
|
+
}
|
|
65
|
+
function isAfterDay(date, max) {
|
|
66
|
+
const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
67
|
+
const m = new Date(max.getFullYear(), max.getMonth(), max.getDate());
|
|
68
|
+
return d > m;
|
|
69
|
+
}
|
|
70
|
+
function isDisabledDate(date, minDate, maxDate, disabledDates) {
|
|
71
|
+
if (minDate && isBeforeDay(date, minDate)) return true;
|
|
72
|
+
if (maxDate && isAfterDay(date, maxDate)) return true;
|
|
73
|
+
if (disabledDates?.some((d) => isSameDay(d, date))) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function formatDate(date, locale = "en-US") {
|
|
77
|
+
return new Intl.DateTimeFormat(locale, {
|
|
78
|
+
month: "short",
|
|
79
|
+
day: "numeric",
|
|
80
|
+
year: "numeric"
|
|
81
|
+
}).format(date);
|
|
82
|
+
}
|
|
83
|
+
function parseISODate(iso) {
|
|
84
|
+
if (!iso) return null;
|
|
85
|
+
const parts = iso.split("-");
|
|
86
|
+
if (parts.length < 3) return null;
|
|
87
|
+
const year = parseInt(parts[0] ?? "0", 10);
|
|
88
|
+
const month = parseInt(parts[1] ?? "0", 10);
|
|
89
|
+
const day = parseInt(parts[2] ?? "0", 10);
|
|
90
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) return null;
|
|
91
|
+
return new Date(year, month - 1, day);
|
|
92
|
+
}
|
|
93
|
+
function toISODateString(date) {
|
|
94
|
+
const y = date.getFullYear();
|
|
95
|
+
const m = String(date.getMonth() + 1).padStart(2, "0");
|
|
96
|
+
const d = String(date.getDate()).padStart(2, "0");
|
|
97
|
+
return `${String(y)}-${m}-${d}`;
|
|
98
|
+
}
|
|
99
|
+
function getYearRange(centerYear, span = 12) {
|
|
100
|
+
const start = Math.floor(centerYear / span) * span;
|
|
101
|
+
return Array.from({ length: span }, (_, i) => start + i);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { DAY_NAMES_SHORT, MONTH_NAMES, MONTH_NAMES_SHORT, buildCalendarGrid, formatDate, getYearRange, isDisabledDate, isSameDay, parseISODate, toISODateString };
|