@djangocfg/ui-tools 2.1.130 → 2.1.131
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/README.md +57 -1
- package/dist/CronScheduler.client-5UEBG4EY.mjs +67 -0
- package/dist/CronScheduler.client-5UEBG4EY.mjs.map +1 -0
- package/dist/CronScheduler.client-ZDNFXYWJ.cjs +72 -0
- package/dist/CronScheduler.client-ZDNFXYWJ.cjs.map +1 -0
- package/dist/chunk-JFGLA6DT.cjs +1013 -0
- package/dist/chunk-JFGLA6DT.cjs.map +1 -0
- package/dist/chunk-MQDWUBVX.mjs +993 -0
- package/dist/chunk-MQDWUBVX.mjs.map +1 -0
- package/dist/index.cjs +109 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +280 -1
- package/dist/index.d.ts +280 -1
- package/dist/index.mjs +32 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +5 -0
- package/src/tools/CronScheduler/CronScheduler.client.tsx +140 -0
- package/src/tools/CronScheduler/CronScheduler.story.tsx +220 -0
- package/src/tools/CronScheduler/components/CronCheatsheet.tsx +101 -0
- package/src/tools/CronScheduler/components/CustomInput.tsx +67 -0
- package/src/tools/CronScheduler/components/DayChips.tsx +130 -0
- package/src/tools/CronScheduler/components/MonthDayGrid.tsx +143 -0
- package/src/tools/CronScheduler/components/SchedulePreview.tsx +103 -0
- package/src/tools/CronScheduler/components/ScheduleTypeSelector.tsx +57 -0
- package/src/tools/CronScheduler/components/TimeSelector.tsx +132 -0
- package/src/tools/CronScheduler/components/index.ts +24 -0
- package/src/tools/CronScheduler/context/CronSchedulerContext.tsx +237 -0
- package/src/tools/CronScheduler/context/hooks.ts +86 -0
- package/src/tools/CronScheduler/context/index.ts +18 -0
- package/src/tools/CronScheduler/index.tsx +91 -0
- package/src/tools/CronScheduler/lazy.tsx +67 -0
- package/src/tools/CronScheduler/types/index.ts +112 -0
- package/src/tools/CronScheduler/utils/cron-builder.ts +100 -0
- package/src/tools/CronScheduler/utils/cron-humanize.ts +218 -0
- package/src/tools/CronScheduler/utils/cron-parser.ts +188 -0
- package/src/tools/CronScheduler/utils/index.ts +12 -0
- package/src/tools/index.ts +36 -0
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkWGEGR3DF_cjs = require('./chunk-WGEGR3DF.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var components = require('@djangocfg/ui-core/components');
|
|
7
|
+
var lib = require('@djangocfg/ui-core/lib');
|
|
8
|
+
var lucideReact = require('lucide-react');
|
|
9
|
+
|
|
10
|
+
// src/tools/CronScheduler/utils/cron-builder.ts
|
|
11
|
+
function buildCron(state) {
|
|
12
|
+
const { type, hour, minute, weekDays, monthDays, customCron } = state;
|
|
13
|
+
const h = Math.max(0, Math.min(23, hour));
|
|
14
|
+
const m = Math.max(0, Math.min(59, minute));
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "daily":
|
|
17
|
+
return `${m} ${h} * * *`;
|
|
18
|
+
case "weekly": {
|
|
19
|
+
const sortedDays = [...weekDays].sort((a, b) => a - b);
|
|
20
|
+
const daysStr = sortedDays.length > 0 ? formatNumberList(sortedDays) : "*";
|
|
21
|
+
return `${m} ${h} * * ${daysStr}`;
|
|
22
|
+
}
|
|
23
|
+
case "monthly": {
|
|
24
|
+
const sortedDays = [...monthDays].sort((a, b) => a - b);
|
|
25
|
+
const daysStr = sortedDays.length > 0 ? formatNumberList(sortedDays) : "1";
|
|
26
|
+
return `${m} ${h} ${daysStr} * *`;
|
|
27
|
+
}
|
|
28
|
+
case "custom":
|
|
29
|
+
return customCron.trim() || "* * * * *";
|
|
30
|
+
default:
|
|
31
|
+
return "0 0 * * *";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
chunkWGEGR3DF_cjs.__name(buildCron, "buildCron");
|
|
35
|
+
function formatNumberList(nums) {
|
|
36
|
+
if (nums.length === 0) return "";
|
|
37
|
+
if (nums.length === 1) return nums[0].toString();
|
|
38
|
+
const sorted = [...nums].sort((a, b) => a - b);
|
|
39
|
+
const ranges = [];
|
|
40
|
+
let start = sorted[0];
|
|
41
|
+
let end = sorted[0];
|
|
42
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
43
|
+
if (sorted[i] === end + 1) {
|
|
44
|
+
end = sorted[i];
|
|
45
|
+
} else {
|
|
46
|
+
ranges.push(start === end ? `${start}` : `${start}-${end}`);
|
|
47
|
+
start = sorted[i];
|
|
48
|
+
end = sorted[i];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
ranges.push(start === end ? `${start}` : `${start}-${end}`);
|
|
52
|
+
return ranges.join(",");
|
|
53
|
+
}
|
|
54
|
+
chunkWGEGR3DF_cjs.__name(formatNumberList, "formatNumberList");
|
|
55
|
+
|
|
56
|
+
// src/tools/CronScheduler/utils/cron-parser.ts
|
|
57
|
+
function parseCron(cron) {
|
|
58
|
+
if (!cron || typeof cron !== "string") return null;
|
|
59
|
+
const parts = cron.trim().split(/\s+/);
|
|
60
|
+
if (parts.length !== 5) return null;
|
|
61
|
+
const [minutePart, hourPart, dayOfMonthPart, monthPart, dayOfWeekPart] = parts;
|
|
62
|
+
const minute = parseField(minutePart, 0, 59);
|
|
63
|
+
if (minute === null && minutePart !== "*") return null;
|
|
64
|
+
const hour = parseField(hourPart, 0, 23);
|
|
65
|
+
if (hour === null && hourPart !== "*") return null;
|
|
66
|
+
const result = detectScheduleType(
|
|
67
|
+
minutePart,
|
|
68
|
+
hourPart,
|
|
69
|
+
dayOfMonthPart,
|
|
70
|
+
monthPart,
|
|
71
|
+
dayOfWeekPart
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
type: result.type,
|
|
75
|
+
hour: hour ?? 0,
|
|
76
|
+
minute: minute ?? 0,
|
|
77
|
+
weekDays: result.weekDays,
|
|
78
|
+
monthDays: result.monthDays,
|
|
79
|
+
customCron: cron,
|
|
80
|
+
isValid: true
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
chunkWGEGR3DF_cjs.__name(parseCron, "parseCron");
|
|
84
|
+
function detectScheduleType(_minutePart, _hourPart, dayOfMonthPart, monthPart, dayOfWeekPart) {
|
|
85
|
+
let type = "custom";
|
|
86
|
+
let weekDays = [1, 2, 3, 4, 5];
|
|
87
|
+
let monthDays = [1];
|
|
88
|
+
if (dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
89
|
+
type = "daily";
|
|
90
|
+
} else if (dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart !== "*") {
|
|
91
|
+
type = "weekly";
|
|
92
|
+
weekDays = parseWeekDays(dayOfWeekPart);
|
|
93
|
+
} else if (dayOfMonthPart !== "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
94
|
+
type = "monthly";
|
|
95
|
+
monthDays = parseMonthDays(dayOfMonthPart);
|
|
96
|
+
}
|
|
97
|
+
return { type, weekDays, monthDays };
|
|
98
|
+
}
|
|
99
|
+
chunkWGEGR3DF_cjs.__name(detectScheduleType, "detectScheduleType");
|
|
100
|
+
function parseField(part, min, max) {
|
|
101
|
+
if (/^\d+$/.test(part)) {
|
|
102
|
+
const num = parseInt(part, 10);
|
|
103
|
+
if (num >= min && num <= max) return num;
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
chunkWGEGR3DF_cjs.__name(parseField, "parseField");
|
|
108
|
+
function parseWeekDays(part) {
|
|
109
|
+
const result = [];
|
|
110
|
+
if (part.includes("-")) {
|
|
111
|
+
const [start, end] = part.split("-").map((s) => parseInt(s, 10));
|
|
112
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
113
|
+
for (let i = start; i <= end && i <= 6; i++) {
|
|
114
|
+
if (i >= 0) result.push(i);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result.length > 0 ? result : [1, 2, 3, 4, 5];
|
|
118
|
+
}
|
|
119
|
+
for (const segment of part.split(",")) {
|
|
120
|
+
const num = parseInt(segment.trim(), 10);
|
|
121
|
+
if (!isNaN(num) && num >= 0 && num <= 6) {
|
|
122
|
+
result.push(num);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result.length > 0 ? result : [1, 2, 3, 4, 5];
|
|
126
|
+
}
|
|
127
|
+
chunkWGEGR3DF_cjs.__name(parseWeekDays, "parseWeekDays");
|
|
128
|
+
function parseMonthDays(part) {
|
|
129
|
+
const result = [];
|
|
130
|
+
if (part.includes("-")) {
|
|
131
|
+
const [start, end] = part.split("-").map((s) => parseInt(s, 10));
|
|
132
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
133
|
+
for (let i = start; i <= end && i <= 31; i++) {
|
|
134
|
+
if (i >= 1) result.push(i);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result.length > 0 ? result : [1];
|
|
138
|
+
}
|
|
139
|
+
for (const segment of part.split(",")) {
|
|
140
|
+
const num = parseInt(segment.trim(), 10);
|
|
141
|
+
if (!isNaN(num) && num >= 1 && num <= 31) {
|
|
142
|
+
result.push(num);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return result.length > 0 ? result : [1];
|
|
146
|
+
}
|
|
147
|
+
chunkWGEGR3DF_cjs.__name(parseMonthDays, "parseMonthDays");
|
|
148
|
+
function isValidCron(cron) {
|
|
149
|
+
if (!cron || typeof cron !== "string") return false;
|
|
150
|
+
const parts = cron.trim().split(/\s+/);
|
|
151
|
+
if (parts.length !== 5) return false;
|
|
152
|
+
const patterns = [
|
|
153
|
+
/^(\*|\d{1,2}|\d{1,2}-\d{1,2}|\d{1,2}(,\d{1,2})*|\*\/\d{1,2})$/,
|
|
154
|
+
// minute
|
|
155
|
+
/^(\*|\d{1,2}|\d{1,2}-\d{1,2}|\d{1,2}(,\d{1,2})*|\*\/\d{1,2})$/,
|
|
156
|
+
// hour
|
|
157
|
+
/^(\*|\d{1,2}|\d{1,2}-\d{1,2}|\d{1,2}(,\d{1,2})*|\*\/\d{1,2})$/,
|
|
158
|
+
// day of month
|
|
159
|
+
/^(\*|\d{1,2}|\d{1,2}-\d{1,2}|\d{1,2}(,\d{1,2})*|\*\/\d{1,2})$/,
|
|
160
|
+
// month
|
|
161
|
+
/^(\*|\d{1}|\d{1}-\d{1}|\d{1}(,\d{1})*|\*\/\d{1,2})$/
|
|
162
|
+
// day of week
|
|
163
|
+
];
|
|
164
|
+
return parts.every((part, i) => patterns[i].test(part));
|
|
165
|
+
}
|
|
166
|
+
chunkWGEGR3DF_cjs.__name(isValidCron, "isValidCron");
|
|
167
|
+
|
|
168
|
+
// src/tools/CronScheduler/utils/cron-humanize.ts
|
|
169
|
+
var WEEKDAY_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
170
|
+
function humanizeCron(cron) {
|
|
171
|
+
if (!cron || typeof cron !== "string") return "Invalid schedule";
|
|
172
|
+
const parts = cron.trim().split(/\s+/);
|
|
173
|
+
if (parts.length !== 5) return "Invalid schedule";
|
|
174
|
+
const [minutePart, hourPart, dayOfMonthPart, monthPart, dayOfWeekPart] = parts;
|
|
175
|
+
const minute = parseInt(minutePart, 10);
|
|
176
|
+
const hour = parseInt(hourPart, 10);
|
|
177
|
+
const timeStr = formatTime(hour, minute);
|
|
178
|
+
if (minutePart === "*" && hourPart === "*" && dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
179
|
+
return "Every minute";
|
|
180
|
+
}
|
|
181
|
+
if (minutePart.startsWith("*/")) {
|
|
182
|
+
const interval = parseInt(minutePart.slice(2), 10);
|
|
183
|
+
if (hourPart === "*") {
|
|
184
|
+
return `Every ${interval} minute${interval > 1 ? "s" : ""}`;
|
|
185
|
+
}
|
|
186
|
+
return `Every ${interval} minute${interval > 1 ? "s" : ""} at hour ${hour}`;
|
|
187
|
+
}
|
|
188
|
+
if (!isNaN(minute) && hourPart === "*" && dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
189
|
+
return `Every hour at minute ${minute}`;
|
|
190
|
+
}
|
|
191
|
+
if (dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
192
|
+
return `Every day at ${timeStr}`;
|
|
193
|
+
}
|
|
194
|
+
if (dayOfMonthPart === "*" && monthPart === "*" && dayOfWeekPart !== "*") {
|
|
195
|
+
const days = parseWeekDays2(dayOfWeekPart);
|
|
196
|
+
if (days.length === 7) {
|
|
197
|
+
return `Every day at ${timeStr}`;
|
|
198
|
+
}
|
|
199
|
+
if (days.length === 5 && isWeekdays(days)) {
|
|
200
|
+
return `Weekdays at ${timeStr}`;
|
|
201
|
+
}
|
|
202
|
+
if (days.length === 2 && isWeekend(days)) {
|
|
203
|
+
return `Weekends at ${timeStr}`;
|
|
204
|
+
}
|
|
205
|
+
const dayNames = days.map((d) => WEEKDAY_SHORT[d]).join(", ");
|
|
206
|
+
return `${dayNames} at ${timeStr}`;
|
|
207
|
+
}
|
|
208
|
+
if (dayOfMonthPart !== "*" && monthPart === "*" && dayOfWeekPart === "*") {
|
|
209
|
+
const days = parseMonthDays2(dayOfMonthPart);
|
|
210
|
+
if (days.length === 1) {
|
|
211
|
+
return `${ordinal(days[0])} of every month at ${timeStr}`;
|
|
212
|
+
}
|
|
213
|
+
if (days.length <= 3) {
|
|
214
|
+
const dayStr = days.map((d) => ordinal(d)).join(", ");
|
|
215
|
+
return `${dayStr} of every month at ${timeStr}`;
|
|
216
|
+
}
|
|
217
|
+
return `${days.length} days per month at ${timeStr}`;
|
|
218
|
+
}
|
|
219
|
+
return `Custom schedule`;
|
|
220
|
+
}
|
|
221
|
+
chunkWGEGR3DF_cjs.__name(humanizeCron, "humanizeCron");
|
|
222
|
+
function formatTime(hour, minute) {
|
|
223
|
+
const h = isNaN(hour) ? 0 : Math.max(0, Math.min(23, hour));
|
|
224
|
+
const m = isNaN(minute) ? 0 : Math.max(0, Math.min(59, minute));
|
|
225
|
+
return `${h.toString().padStart(2, "0")}:${m.toString().padStart(2, "0")}`;
|
|
226
|
+
}
|
|
227
|
+
chunkWGEGR3DF_cjs.__name(formatTime, "formatTime");
|
|
228
|
+
function parseWeekDays2(part) {
|
|
229
|
+
const result = [];
|
|
230
|
+
if (part.includes("-") && !part.includes(",")) {
|
|
231
|
+
const [start, end] = part.split("-").map((s) => parseInt(s, 10));
|
|
232
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
233
|
+
for (let i = start; i <= end && i <= 6; i++) {
|
|
234
|
+
if (i >= 0) result.push(i);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
for (const segment of part.split(",")) {
|
|
240
|
+
if (segment.includes("-")) {
|
|
241
|
+
const [start, end] = segment.split("-").map((s) => parseInt(s, 10));
|
|
242
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
243
|
+
for (let i = start; i <= end && i <= 6; i++) {
|
|
244
|
+
if (i >= 0) result.push(i);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
const num = parseInt(segment.trim(), 10);
|
|
249
|
+
if (!isNaN(num) && num >= 0 && num <= 6) {
|
|
250
|
+
result.push(num);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return result.sort((a, b) => a - b);
|
|
255
|
+
}
|
|
256
|
+
chunkWGEGR3DF_cjs.__name(parseWeekDays2, "parseWeekDays");
|
|
257
|
+
function parseMonthDays2(part) {
|
|
258
|
+
const result = [];
|
|
259
|
+
if (part.includes("-") && !part.includes(",")) {
|
|
260
|
+
const [start, end] = part.split("-").map((s) => parseInt(s, 10));
|
|
261
|
+
if (!isNaN(start) && !isNaN(end)) {
|
|
262
|
+
for (let i = start; i <= end && i <= 31; i++) {
|
|
263
|
+
if (i >= 1) result.push(i);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
for (const segment of part.split(",")) {
|
|
269
|
+
const num = parseInt(segment.trim(), 10);
|
|
270
|
+
if (!isNaN(num) && num >= 1 && num <= 31) {
|
|
271
|
+
result.push(num);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result.sort((a, b) => a - b);
|
|
275
|
+
}
|
|
276
|
+
chunkWGEGR3DF_cjs.__name(parseMonthDays2, "parseMonthDays");
|
|
277
|
+
function isWeekdays(days) {
|
|
278
|
+
const sorted = [...days].sort((a, b) => a - b);
|
|
279
|
+
return sorted.join(",") === "1,2,3,4,5";
|
|
280
|
+
}
|
|
281
|
+
chunkWGEGR3DF_cjs.__name(isWeekdays, "isWeekdays");
|
|
282
|
+
function isWeekend(days) {
|
|
283
|
+
const sorted = [...days].sort((a, b) => a - b);
|
|
284
|
+
return sorted.join(",") === "0,6";
|
|
285
|
+
}
|
|
286
|
+
chunkWGEGR3DF_cjs.__name(isWeekend, "isWeekend");
|
|
287
|
+
function ordinal(n) {
|
|
288
|
+
const s = ["th", "st", "nd", "rd"];
|
|
289
|
+
const v = n % 100;
|
|
290
|
+
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
291
|
+
}
|
|
292
|
+
chunkWGEGR3DF_cjs.__name(ordinal, "ordinal");
|
|
293
|
+
var CronSchedulerContext = react.createContext(null);
|
|
294
|
+
var DEFAULT_STATE = {
|
|
295
|
+
type: "daily",
|
|
296
|
+
hour: 9,
|
|
297
|
+
minute: 0,
|
|
298
|
+
weekDays: [1, 2, 3, 4, 5],
|
|
299
|
+
// Mon-Fri
|
|
300
|
+
monthDays: [1],
|
|
301
|
+
customCron: "* * * * *",
|
|
302
|
+
isValid: true
|
|
303
|
+
};
|
|
304
|
+
function CronSchedulerProvider({
|
|
305
|
+
children,
|
|
306
|
+
value,
|
|
307
|
+
onChange,
|
|
308
|
+
defaultType = "daily"
|
|
309
|
+
}) {
|
|
310
|
+
const isInitialMount = react.useRef(true);
|
|
311
|
+
const [state, setState] = react.useState(() => {
|
|
312
|
+
if (value) {
|
|
313
|
+
const parsed = parseCron(value);
|
|
314
|
+
if (parsed) return parsed;
|
|
315
|
+
}
|
|
316
|
+
return { ...DEFAULT_STATE, type: defaultType };
|
|
317
|
+
});
|
|
318
|
+
react.useEffect(() => {
|
|
319
|
+
if (value) {
|
|
320
|
+
const parsed = parseCron(value);
|
|
321
|
+
if (parsed) {
|
|
322
|
+
const currentCron = buildCron(state);
|
|
323
|
+
if (value !== currentCron) {
|
|
324
|
+
setState(parsed);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}, [value]);
|
|
329
|
+
const cronExpression = react.useMemo(() => buildCron(state), [state]);
|
|
330
|
+
const humanDescription = react.useMemo(() => humanizeCron(cronExpression), [cronExpression]);
|
|
331
|
+
react.useEffect(() => {
|
|
332
|
+
if (isInitialMount.current) {
|
|
333
|
+
isInitialMount.current = false;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
onChange?.(cronExpression);
|
|
337
|
+
}, [cronExpression, onChange]);
|
|
338
|
+
const setType = react.useCallback((type) => {
|
|
339
|
+
setState((s) => ({ ...s, type }));
|
|
340
|
+
}, []);
|
|
341
|
+
const setTime = react.useCallback((hour, minute) => {
|
|
342
|
+
setState((s) => ({
|
|
343
|
+
...s,
|
|
344
|
+
hour: Math.max(0, Math.min(23, hour)),
|
|
345
|
+
minute: Math.max(0, Math.min(59, minute))
|
|
346
|
+
}));
|
|
347
|
+
}, []);
|
|
348
|
+
const toggleWeekDay = react.useCallback((day) => {
|
|
349
|
+
setState((s) => {
|
|
350
|
+
const hasDay = s.weekDays.includes(day);
|
|
351
|
+
if (hasDay && s.weekDays.length === 1) return s;
|
|
352
|
+
const newDays = hasDay ? s.weekDays.filter((d) => d !== day) : [...s.weekDays, day];
|
|
353
|
+
return {
|
|
354
|
+
...s,
|
|
355
|
+
weekDays: newDays.sort((a, b) => a - b)
|
|
356
|
+
};
|
|
357
|
+
});
|
|
358
|
+
}, []);
|
|
359
|
+
const setWeekDays = react.useCallback((days) => {
|
|
360
|
+
setState((s) => ({
|
|
361
|
+
...s,
|
|
362
|
+
weekDays: days.length > 0 ? [...days].sort((a, b) => a - b) : [1]
|
|
363
|
+
// Default to Monday if empty
|
|
364
|
+
}));
|
|
365
|
+
}, []);
|
|
366
|
+
const toggleMonthDay = react.useCallback((day) => {
|
|
367
|
+
setState((s) => {
|
|
368
|
+
const hasDay = s.monthDays.includes(day);
|
|
369
|
+
if (hasDay && s.monthDays.length === 1) return s;
|
|
370
|
+
const newDays = hasDay ? s.monthDays.filter((d) => d !== day) : [...s.monthDays, day];
|
|
371
|
+
return {
|
|
372
|
+
...s,
|
|
373
|
+
monthDays: newDays.sort((a, b) => a - b)
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
}, []);
|
|
377
|
+
const setMonthDays = react.useCallback((days) => {
|
|
378
|
+
setState((s) => ({
|
|
379
|
+
...s,
|
|
380
|
+
monthDays: days.length > 0 ? [...days].sort((a, b) => a - b) : [1]
|
|
381
|
+
// Default to 1st if empty
|
|
382
|
+
}));
|
|
383
|
+
}, []);
|
|
384
|
+
const setCustomCron = react.useCallback((customCron) => {
|
|
385
|
+
const parsed = parseCron(customCron);
|
|
386
|
+
setState((s) => ({
|
|
387
|
+
...s,
|
|
388
|
+
customCron,
|
|
389
|
+
isValid: parsed !== null
|
|
390
|
+
}));
|
|
391
|
+
}, []);
|
|
392
|
+
const reset = react.useCallback(() => {
|
|
393
|
+
setState({ ...DEFAULT_STATE, type: defaultType });
|
|
394
|
+
}, [defaultType]);
|
|
395
|
+
const contextValue = react.useMemo(
|
|
396
|
+
() => ({
|
|
397
|
+
// State
|
|
398
|
+
...state,
|
|
399
|
+
// Computed
|
|
400
|
+
cronExpression,
|
|
401
|
+
humanDescription,
|
|
402
|
+
// Actions
|
|
403
|
+
setType,
|
|
404
|
+
setTime,
|
|
405
|
+
toggleWeekDay,
|
|
406
|
+
setWeekDays,
|
|
407
|
+
toggleMonthDay,
|
|
408
|
+
setMonthDays,
|
|
409
|
+
setCustomCron,
|
|
410
|
+
reset
|
|
411
|
+
}),
|
|
412
|
+
[
|
|
413
|
+
state,
|
|
414
|
+
cronExpression,
|
|
415
|
+
humanDescription,
|
|
416
|
+
setType,
|
|
417
|
+
setTime,
|
|
418
|
+
toggleWeekDay,
|
|
419
|
+
setWeekDays,
|
|
420
|
+
toggleMonthDay,
|
|
421
|
+
setMonthDays,
|
|
422
|
+
setCustomCron,
|
|
423
|
+
reset
|
|
424
|
+
]
|
|
425
|
+
);
|
|
426
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CronSchedulerContext.Provider, { value: contextValue, children });
|
|
427
|
+
}
|
|
428
|
+
chunkWGEGR3DF_cjs.__name(CronSchedulerProvider, "CronSchedulerProvider");
|
|
429
|
+
function useCronSchedulerContext() {
|
|
430
|
+
const context = react.useContext(CronSchedulerContext);
|
|
431
|
+
if (!context) {
|
|
432
|
+
throw new Error(
|
|
433
|
+
"useCronSchedulerContext must be used within CronSchedulerProvider"
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
return context;
|
|
437
|
+
}
|
|
438
|
+
chunkWGEGR3DF_cjs.__name(useCronSchedulerContext, "useCronSchedulerContext");
|
|
439
|
+
function useCronType() {
|
|
440
|
+
const { type, setType } = useCronSchedulerContext();
|
|
441
|
+
return react.useMemo(() => ({ type, setType }), [type, setType]);
|
|
442
|
+
}
|
|
443
|
+
chunkWGEGR3DF_cjs.__name(useCronType, "useCronType");
|
|
444
|
+
function useCronTime() {
|
|
445
|
+
const { hour, minute, setTime } = useCronSchedulerContext();
|
|
446
|
+
return react.useMemo(() => ({ hour, minute, setTime }), [hour, minute, setTime]);
|
|
447
|
+
}
|
|
448
|
+
chunkWGEGR3DF_cjs.__name(useCronTime, "useCronTime");
|
|
449
|
+
function useCronWeekDays() {
|
|
450
|
+
const { weekDays, toggleWeekDay, setWeekDays } = useCronSchedulerContext();
|
|
451
|
+
return react.useMemo(
|
|
452
|
+
() => ({ weekDays, toggleWeekDay, setWeekDays }),
|
|
453
|
+
[weekDays, toggleWeekDay, setWeekDays]
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
chunkWGEGR3DF_cjs.__name(useCronWeekDays, "useCronWeekDays");
|
|
457
|
+
function useCronMonthDays() {
|
|
458
|
+
const { monthDays, toggleMonthDay, setMonthDays } = useCronSchedulerContext();
|
|
459
|
+
return react.useMemo(
|
|
460
|
+
() => ({ monthDays, toggleMonthDay, setMonthDays }),
|
|
461
|
+
[monthDays, toggleMonthDay, setMonthDays]
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
chunkWGEGR3DF_cjs.__name(useCronMonthDays, "useCronMonthDays");
|
|
465
|
+
function useCronCustom() {
|
|
466
|
+
const { customCron, isValid, setCustomCron } = useCronSchedulerContext();
|
|
467
|
+
return react.useMemo(
|
|
468
|
+
() => ({ customCron, isValid, setCustomCron }),
|
|
469
|
+
[customCron, isValid, setCustomCron]
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
chunkWGEGR3DF_cjs.__name(useCronCustom, "useCronCustom");
|
|
473
|
+
function useCronPreview() {
|
|
474
|
+
const { cronExpression, humanDescription, isValid } = useCronSchedulerContext();
|
|
475
|
+
return react.useMemo(
|
|
476
|
+
() => ({ cronExpression, humanDescription, isValid }),
|
|
477
|
+
[cronExpression, humanDescription, isValid]
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
chunkWGEGR3DF_cjs.__name(useCronPreview, "useCronPreview");
|
|
481
|
+
function useCronScheduler() {
|
|
482
|
+
return useCronSchedulerContext();
|
|
483
|
+
}
|
|
484
|
+
chunkWGEGR3DF_cjs.__name(useCronScheduler, "useCronScheduler");
|
|
485
|
+
var SCHEDULE_TYPES = [
|
|
486
|
+
{ value: "daily", label: "Daily" },
|
|
487
|
+
{ value: "weekly", label: "Weekly" },
|
|
488
|
+
{ value: "monthly", label: "Monthly" },
|
|
489
|
+
{ value: "custom", label: "Custom" }
|
|
490
|
+
];
|
|
491
|
+
function ScheduleTypeSelector({
|
|
492
|
+
disabled,
|
|
493
|
+
className
|
|
494
|
+
}) {
|
|
495
|
+
const { type, setType } = useCronType();
|
|
496
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
497
|
+
components.Tabs,
|
|
498
|
+
{
|
|
499
|
+
value: type,
|
|
500
|
+
onValueChange: (v) => setType(v),
|
|
501
|
+
className: lib.cn("w-full", className),
|
|
502
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(components.TabsList, { className: "grid w-full grid-cols-4 h-9 p-0.5", children: SCHEDULE_TYPES.map(({ value, label }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
503
|
+
components.TabsTrigger,
|
|
504
|
+
{
|
|
505
|
+
value,
|
|
506
|
+
disabled,
|
|
507
|
+
className: lib.cn(
|
|
508
|
+
"text-xs font-medium px-2 py-1.5",
|
|
509
|
+
"data-[state=active]:shadow-sm",
|
|
510
|
+
"transition-all duration-150"
|
|
511
|
+
),
|
|
512
|
+
children: label
|
|
513
|
+
},
|
|
514
|
+
value
|
|
515
|
+
)) })
|
|
516
|
+
}
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
chunkWGEGR3DF_cjs.__name(ScheduleTypeSelector, "ScheduleTypeSelector");
|
|
520
|
+
var HOURS = Array.from({ length: 24 }, (_, i) => i);
|
|
521
|
+
var MINUTES = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55];
|
|
522
|
+
function TimeSelector({
|
|
523
|
+
format = "24h",
|
|
524
|
+
disabled,
|
|
525
|
+
className
|
|
526
|
+
}) {
|
|
527
|
+
const { hour, minute, setTime } = useCronTime();
|
|
528
|
+
const is24h = format === "24h";
|
|
529
|
+
const displayHour = is24h ? hour : hour % 12 || 12;
|
|
530
|
+
const isPM = hour >= 12;
|
|
531
|
+
const handleHourChange = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((value) => {
|
|
532
|
+
let newHour = parseInt(value, 10);
|
|
533
|
+
if (!is24h) {
|
|
534
|
+
if (isPM && newHour !== 12) newHour += 12;
|
|
535
|
+
else if (!isPM && newHour === 12) newHour = 0;
|
|
536
|
+
}
|
|
537
|
+
setTime(newHour, minute);
|
|
538
|
+
}, "handleHourChange");
|
|
539
|
+
const handleMinuteChange = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((value) => {
|
|
540
|
+
setTime(hour, parseInt(value, 10));
|
|
541
|
+
}, "handleMinuteChange");
|
|
542
|
+
const handlePeriodChange = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((value) => {
|
|
543
|
+
const newIsPM = value === "PM";
|
|
544
|
+
let newHour = hour;
|
|
545
|
+
if (newIsPM && hour < 12) newHour = hour + 12;
|
|
546
|
+
else if (!newIsPM && hour >= 12) newHour = hour - 12;
|
|
547
|
+
setTime(newHour, minute);
|
|
548
|
+
}, "handlePeriodChange");
|
|
549
|
+
const hours = is24h ? HOURS : Array.from({ length: 12 }, (_, i) => i + 1);
|
|
550
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("flex items-center gap-3", className), children: [
|
|
551
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-muted-foreground", children: [
|
|
552
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { className: "h-4 w-4" }),
|
|
553
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm", children: "Run at" })
|
|
554
|
+
] }),
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 flex-1", children: [
|
|
556
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
557
|
+
components.Select,
|
|
558
|
+
{
|
|
559
|
+
value: displayHour.toString(),
|
|
560
|
+
onValueChange: handleHourChange,
|
|
561
|
+
disabled,
|
|
562
|
+
children: [
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectTrigger, { className: "w-[70px] h-9", children: /* @__PURE__ */ jsxRuntime.jsx(components.SelectValue, { children: displayHour.toString().padStart(2, "0") }) }),
|
|
564
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectContent, { className: "max-h-48", children: hours.map((h) => /* @__PURE__ */ jsxRuntime.jsx(components.SelectItem, { value: h.toString(), children: h.toString().padStart(2, "0") }, h)) })
|
|
565
|
+
]
|
|
566
|
+
}
|
|
567
|
+
),
|
|
568
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground font-medium", children: ":" }),
|
|
569
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
570
|
+
components.Select,
|
|
571
|
+
{
|
|
572
|
+
value: minute.toString(),
|
|
573
|
+
onValueChange: handleMinuteChange,
|
|
574
|
+
disabled,
|
|
575
|
+
children: [
|
|
576
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectTrigger, { className: "w-[70px] h-9", children: /* @__PURE__ */ jsxRuntime.jsx(components.SelectValue, { children: minute.toString().padStart(2, "0") }) }),
|
|
577
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectContent, { className: "max-h-48", children: MINUTES.map((m) => /* @__PURE__ */ jsxRuntime.jsx(components.SelectItem, { value: m.toString(), children: m.toString().padStart(2, "0") }, m)) })
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
),
|
|
581
|
+
!is24h && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
582
|
+
components.Select,
|
|
583
|
+
{
|
|
584
|
+
value: isPM ? "PM" : "AM",
|
|
585
|
+
onValueChange: handlePeriodChange,
|
|
586
|
+
disabled,
|
|
587
|
+
children: [
|
|
588
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectTrigger, { className: "w-[70px] h-9", children: /* @__PURE__ */ jsxRuntime.jsx(components.SelectValue, {}) }),
|
|
589
|
+
/* @__PURE__ */ jsxRuntime.jsxs(components.SelectContent, { children: [
|
|
590
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectItem, { value: "AM", children: "AM" }),
|
|
591
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.SelectItem, { value: "PM", children: "PM" })
|
|
592
|
+
] })
|
|
593
|
+
]
|
|
594
|
+
}
|
|
595
|
+
)
|
|
596
|
+
] })
|
|
597
|
+
] });
|
|
598
|
+
}
|
|
599
|
+
chunkWGEGR3DF_cjs.__name(TimeSelector, "TimeSelector");
|
|
600
|
+
var DAYS = [
|
|
601
|
+
{ value: 1, label: "Mon" },
|
|
602
|
+
{ value: 2, label: "Tue" },
|
|
603
|
+
{ value: 3, label: "Wed" },
|
|
604
|
+
{ value: 4, label: "Thu" },
|
|
605
|
+
{ value: 5, label: "Fri" },
|
|
606
|
+
{ value: 6, label: "Sat" },
|
|
607
|
+
{ value: 0, label: "Sun" }
|
|
608
|
+
];
|
|
609
|
+
function DayChips({
|
|
610
|
+
disabled,
|
|
611
|
+
showPresets = true,
|
|
612
|
+
className
|
|
613
|
+
}) {
|
|
614
|
+
const { weekDays, toggleWeekDay, setWeekDays } = useCronWeekDays();
|
|
615
|
+
const isWeekdays2 = weekDays.length === 5 && [1, 2, 3, 4, 5].every((d) => weekDays.includes(d));
|
|
616
|
+
const isWeekend2 = weekDays.length === 2 && [0, 6].every((d) => weekDays.includes(d));
|
|
617
|
+
const isEveryday = weekDays.length === 7;
|
|
618
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("space-y-3", className), children: [
|
|
619
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1", children: DAYS.map(({ value, label }) => {
|
|
620
|
+
const isSelected = weekDays.includes(value);
|
|
621
|
+
const isWeekend3 = value === 0 || value === 6;
|
|
622
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
623
|
+
"button",
|
|
624
|
+
{
|
|
625
|
+
type: "button",
|
|
626
|
+
disabled,
|
|
627
|
+
onClick: () => toggleWeekDay(value),
|
|
628
|
+
"aria-pressed": isSelected,
|
|
629
|
+
className: lib.cn(
|
|
630
|
+
"flex flex-col items-center justify-center",
|
|
631
|
+
"py-2.5 rounded-lg text-xs font-medium",
|
|
632
|
+
"transition-all duration-150",
|
|
633
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",
|
|
634
|
+
"active:scale-[0.97]",
|
|
635
|
+
isSelected ? "bg-primary text-primary-foreground shadow-sm" : lib.cn(
|
|
636
|
+
"bg-muted/50 hover:bg-muted",
|
|
637
|
+
isWeekend3 ? "text-muted-foreground/70" : "text-muted-foreground"
|
|
638
|
+
),
|
|
639
|
+
disabled && "opacity-50 cursor-not-allowed pointer-events-none"
|
|
640
|
+
),
|
|
641
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: label })
|
|
642
|
+
},
|
|
643
|
+
value
|
|
644
|
+
);
|
|
645
|
+
}) }),
|
|
646
|
+
showPresets && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
647
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
648
|
+
PresetButton,
|
|
649
|
+
{
|
|
650
|
+
label: "Weekdays",
|
|
651
|
+
isActive: isWeekdays2,
|
|
652
|
+
onClick: () => setWeekDays([1, 2, 3, 4, 5]),
|
|
653
|
+
disabled
|
|
654
|
+
}
|
|
655
|
+
),
|
|
656
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
657
|
+
PresetButton,
|
|
658
|
+
{
|
|
659
|
+
label: "Weekends",
|
|
660
|
+
isActive: isWeekend2,
|
|
661
|
+
onClick: () => setWeekDays([0, 6]),
|
|
662
|
+
disabled
|
|
663
|
+
}
|
|
664
|
+
),
|
|
665
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
666
|
+
PresetButton,
|
|
667
|
+
{
|
|
668
|
+
label: "Every day",
|
|
669
|
+
isActive: isEveryday,
|
|
670
|
+
onClick: () => setWeekDays([0, 1, 2, 3, 4, 5, 6]),
|
|
671
|
+
disabled
|
|
672
|
+
}
|
|
673
|
+
)
|
|
674
|
+
] })
|
|
675
|
+
] });
|
|
676
|
+
}
|
|
677
|
+
chunkWGEGR3DF_cjs.__name(DayChips, "DayChips");
|
|
678
|
+
function PresetButton({ label, isActive, onClick, disabled }) {
|
|
679
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
680
|
+
"button",
|
|
681
|
+
{
|
|
682
|
+
type: "button",
|
|
683
|
+
disabled,
|
|
684
|
+
onClick,
|
|
685
|
+
className: lib.cn(
|
|
686
|
+
"flex-1 px-3 py-1.5 rounded-md text-xs font-medium",
|
|
687
|
+
"transition-colors duration-150",
|
|
688
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",
|
|
689
|
+
isActive ? "bg-primary/15 text-primary border border-primary/30" : "bg-muted/30 text-muted-foreground hover:bg-muted/50 border border-transparent",
|
|
690
|
+
disabled && "opacity-50 cursor-not-allowed"
|
|
691
|
+
),
|
|
692
|
+
children: label
|
|
693
|
+
}
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
chunkWGEGR3DF_cjs.__name(PresetButton, "PresetButton");
|
|
697
|
+
Array.from({ length: 31 }, (_, i) => i + 1);
|
|
698
|
+
var GRID_SIZE = 35;
|
|
699
|
+
function MonthDayGrid({
|
|
700
|
+
disabled,
|
|
701
|
+
showPresets = true,
|
|
702
|
+
className
|
|
703
|
+
}) {
|
|
704
|
+
const { monthDays, toggleMonthDay, setMonthDays } = useCronMonthDays();
|
|
705
|
+
const is1st = monthDays.length === 1 && monthDays[0] === 1;
|
|
706
|
+
const is15th = monthDays.length === 1 && monthDays[0] === 15;
|
|
707
|
+
const is1stAnd15th = monthDays.length === 2 && monthDays.includes(1) && monthDays.includes(15);
|
|
708
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("space-y-3", className), children: [
|
|
709
|
+
showPresets && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
710
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
711
|
+
PresetButton2,
|
|
712
|
+
{
|
|
713
|
+
label: "1st",
|
|
714
|
+
isActive: is1st,
|
|
715
|
+
onClick: () => setMonthDays([1]),
|
|
716
|
+
disabled
|
|
717
|
+
}
|
|
718
|
+
),
|
|
719
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
720
|
+
PresetButton2,
|
|
721
|
+
{
|
|
722
|
+
label: "15th",
|
|
723
|
+
isActive: is15th,
|
|
724
|
+
onClick: () => setMonthDays([15]),
|
|
725
|
+
disabled
|
|
726
|
+
}
|
|
727
|
+
),
|
|
728
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
729
|
+
PresetButton2,
|
|
730
|
+
{
|
|
731
|
+
label: "1st & 15th",
|
|
732
|
+
isActive: is1stAnd15th,
|
|
733
|
+
onClick: () => setMonthDays([1, 15]),
|
|
734
|
+
disabled
|
|
735
|
+
}
|
|
736
|
+
)
|
|
737
|
+
] }),
|
|
738
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-7 gap-1", children: Array.from({ length: GRID_SIZE }, (_, i) => {
|
|
739
|
+
const day = i + 1;
|
|
740
|
+
const isValidDay = day <= 31;
|
|
741
|
+
const isSelected = isValidDay && monthDays.includes(day);
|
|
742
|
+
const isPartialMonth = day > 28;
|
|
743
|
+
if (!isValidDay) {
|
|
744
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aspect-square" }, i);
|
|
745
|
+
}
|
|
746
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
747
|
+
"button",
|
|
748
|
+
{
|
|
749
|
+
type: "button",
|
|
750
|
+
disabled,
|
|
751
|
+
onClick: () => toggleMonthDay(day),
|
|
752
|
+
"aria-pressed": isSelected,
|
|
753
|
+
"aria-label": `Day ${day}`,
|
|
754
|
+
className: lib.cn(
|
|
755
|
+
"aspect-square flex items-center justify-center",
|
|
756
|
+
"rounded-lg text-sm font-medium",
|
|
757
|
+
"transition-all duration-150",
|
|
758
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",
|
|
759
|
+
"active:scale-[0.95]",
|
|
760
|
+
isSelected ? "bg-primary text-primary-foreground shadow-sm" : lib.cn(
|
|
761
|
+
"bg-muted/30 hover:bg-muted/60",
|
|
762
|
+
isPartialMonth ? "text-muted-foreground/50" : "text-muted-foreground"
|
|
763
|
+
),
|
|
764
|
+
disabled && "opacity-50 cursor-not-allowed pointer-events-none"
|
|
765
|
+
),
|
|
766
|
+
children: day
|
|
767
|
+
},
|
|
768
|
+
day
|
|
769
|
+
);
|
|
770
|
+
}) }),
|
|
771
|
+
monthDays.length > 1 && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground text-center", children: [
|
|
772
|
+
monthDays.length,
|
|
773
|
+
" days selected"
|
|
774
|
+
] })
|
|
775
|
+
] });
|
|
776
|
+
}
|
|
777
|
+
chunkWGEGR3DF_cjs.__name(MonthDayGrid, "MonthDayGrid");
|
|
778
|
+
function PresetButton2({ label, isActive, onClick, disabled }) {
|
|
779
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
780
|
+
"button",
|
|
781
|
+
{
|
|
782
|
+
type: "button",
|
|
783
|
+
disabled,
|
|
784
|
+
onClick,
|
|
785
|
+
className: lib.cn(
|
|
786
|
+
"flex-1 px-3 py-1.5 rounded-md text-xs font-medium",
|
|
787
|
+
"transition-colors duration-150",
|
|
788
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",
|
|
789
|
+
isActive ? "bg-primary/15 text-primary border border-primary/30" : "bg-muted/30 text-muted-foreground hover:bg-muted/50 border border-transparent",
|
|
790
|
+
disabled && "opacity-50 cursor-not-allowed"
|
|
791
|
+
),
|
|
792
|
+
children: label
|
|
793
|
+
}
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
chunkWGEGR3DF_cjs.__name(PresetButton2, "PresetButton");
|
|
797
|
+
function CustomInput({ disabled, className }) {
|
|
798
|
+
const { customCron, isValid, setCustomCron } = useCronCustom();
|
|
799
|
+
const [localValue, setLocalValue] = react.useState(customCron);
|
|
800
|
+
const [localValid, setLocalValid] = react.useState(isValid);
|
|
801
|
+
react.useEffect(() => {
|
|
802
|
+
setLocalValue(customCron);
|
|
803
|
+
setLocalValid(isValid);
|
|
804
|
+
}, [customCron, isValid]);
|
|
805
|
+
const handleChange = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((e) => {
|
|
806
|
+
const value = e.target.value;
|
|
807
|
+
setLocalValue(value);
|
|
808
|
+
const valid = isValidCron(value);
|
|
809
|
+
setLocalValid(valid);
|
|
810
|
+
setCustomCron(value);
|
|
811
|
+
}, "handleChange");
|
|
812
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: lib.cn("space-y-2", className), children: [
|
|
813
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-muted-foreground", children: "Cron expression" }),
|
|
814
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
815
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
816
|
+
components.Input,
|
|
817
|
+
{
|
|
818
|
+
type: "text",
|
|
819
|
+
value: localValue,
|
|
820
|
+
onChange: handleChange,
|
|
821
|
+
disabled,
|
|
822
|
+
placeholder: "* * * * *",
|
|
823
|
+
className: lib.cn(
|
|
824
|
+
"font-mono text-base pr-10 h-11",
|
|
825
|
+
!localValid && localValue.trim() && "border-destructive focus-visible:ring-destructive/50"
|
|
826
|
+
)
|
|
827
|
+
}
|
|
828
|
+
),
|
|
829
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: localValue.trim() && (localValid ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCircle2, { className: "h-5 w-5 text-green-500" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircle, { className: "h-5 w-5 text-destructive" })) })
|
|
830
|
+
] })
|
|
831
|
+
] });
|
|
832
|
+
}
|
|
833
|
+
chunkWGEGR3DF_cjs.__name(CustomInput, "CustomInput");
|
|
834
|
+
function CronCheatsheet({ className }) {
|
|
835
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Popover, { children: [
|
|
836
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
837
|
+
"button",
|
|
838
|
+
{
|
|
839
|
+
type: "button",
|
|
840
|
+
className: lib.cn(
|
|
841
|
+
"p-1 rounded hover:bg-muted/50 transition-colors",
|
|
842
|
+
className
|
|
843
|
+
),
|
|
844
|
+
"aria-label": "Cron syntax help",
|
|
845
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.HelpCircle, { className: "h-4 w-4 text-muted-foreground" })
|
|
846
|
+
}
|
|
847
|
+
) }),
|
|
848
|
+
/* @__PURE__ */ jsxRuntime.jsx(components.PopoverContent, { className: "w-72 p-3", align: "end", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
849
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-medium text-sm", children: "Cron Format" }),
|
|
850
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "block text-xs bg-muted px-2 py-1.5 rounded font-mono text-center", children: "min hour day month weekday" }),
|
|
851
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-4 gap-y-1 text-xs", children: [
|
|
852
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between", children: [
|
|
853
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "minute" }),
|
|
854
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "0-59" })
|
|
855
|
+
] }),
|
|
856
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between", children: [
|
|
857
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "hour" }),
|
|
858
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "0-23" })
|
|
859
|
+
] }),
|
|
860
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between", children: [
|
|
861
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "day" }),
|
|
862
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "1-31" })
|
|
863
|
+
] }),
|
|
864
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between", children: [
|
|
865
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "month" }),
|
|
866
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "1-12" })
|
|
867
|
+
] }),
|
|
868
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between col-span-2", children: [
|
|
869
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "weekday" }),
|
|
870
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "0-6 (Sun-Sat)" })
|
|
871
|
+
] })
|
|
872
|
+
] }),
|
|
873
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-2 border-t border-border space-y-1.5", children: [
|
|
874
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium", children: "Special characters" }),
|
|
875
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-1.5 text-xs", children: [
|
|
876
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
877
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "bg-muted px-1 rounded", children: "*" }),
|
|
878
|
+
" any value"
|
|
879
|
+
] }),
|
|
880
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
881
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "bg-muted px-1 rounded", children: "," }),
|
|
882
|
+
" list (1,3,5)"
|
|
883
|
+
] }),
|
|
884
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
885
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "bg-muted px-1 rounded", children: "-" }),
|
|
886
|
+
" range (1-5)"
|
|
887
|
+
] }),
|
|
888
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
889
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "bg-muted px-1 rounded", children: "/" }),
|
|
890
|
+
" step (*/15)"
|
|
891
|
+
] })
|
|
892
|
+
] })
|
|
893
|
+
] }),
|
|
894
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-2 border-t border-border space-y-1.5", children: [
|
|
895
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium", children: "Examples" }),
|
|
896
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 text-xs", children: [
|
|
897
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between font-mono", children: [
|
|
898
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "0 9 * * *" }),
|
|
899
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "daily at 9am" })
|
|
900
|
+
] }),
|
|
901
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between font-mono", children: [
|
|
902
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "0 9 * * 1-5" }),
|
|
903
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "weekdays 9am" })
|
|
904
|
+
] }),
|
|
905
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between font-mono", children: [
|
|
906
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "*/15 * * * *" }),
|
|
907
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "every 15 min" })
|
|
908
|
+
] }),
|
|
909
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between font-mono", children: [
|
|
910
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "0 0 1 * *" }),
|
|
911
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "1st of month" })
|
|
912
|
+
] })
|
|
913
|
+
] })
|
|
914
|
+
] })
|
|
915
|
+
] }) })
|
|
916
|
+
] });
|
|
917
|
+
}
|
|
918
|
+
chunkWGEGR3DF_cjs.__name(CronCheatsheet, "CronCheatsheet");
|
|
919
|
+
function SchedulePreview({
|
|
920
|
+
showCronExpression = true,
|
|
921
|
+
allowCopy = false,
|
|
922
|
+
className
|
|
923
|
+
}) {
|
|
924
|
+
const { cronExpression, humanDescription, isValid } = useCronPreview();
|
|
925
|
+
const [copied, setCopied] = react.useState(false);
|
|
926
|
+
const handleCopy = react.useCallback(async () => {
|
|
927
|
+
try {
|
|
928
|
+
await navigator.clipboard.writeText(cronExpression);
|
|
929
|
+
setCopied(true);
|
|
930
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
931
|
+
} catch (err) {
|
|
932
|
+
console.error("Failed to copy:", err);
|
|
933
|
+
}
|
|
934
|
+
}, [cronExpression]);
|
|
935
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
936
|
+
"div",
|
|
937
|
+
{
|
|
938
|
+
className: lib.cn(
|
|
939
|
+
"px-3 py-2.5 rounded-lg border",
|
|
940
|
+
"bg-muted/30 border-border/50",
|
|
941
|
+
!isValid && "border-destructive/30 bg-destructive/5",
|
|
942
|
+
className
|
|
943
|
+
),
|
|
944
|
+
children: [
|
|
945
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
946
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 min-w-0", children: [
|
|
947
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
948
|
+
lucideReact.Calendar,
|
|
949
|
+
{
|
|
950
|
+
className: lib.cn(
|
|
951
|
+
"h-4 w-4 shrink-0",
|
|
952
|
+
isValid ? "text-primary" : "text-destructive"
|
|
953
|
+
)
|
|
954
|
+
}
|
|
955
|
+
),
|
|
956
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
957
|
+
"span",
|
|
958
|
+
{
|
|
959
|
+
className: lib.cn(
|
|
960
|
+
"text-sm",
|
|
961
|
+
isValid ? "text-foreground" : "text-destructive"
|
|
962
|
+
),
|
|
963
|
+
children: humanDescription
|
|
964
|
+
}
|
|
965
|
+
)
|
|
966
|
+
] }),
|
|
967
|
+
allowCopy && /* @__PURE__ */ jsxRuntime.jsx(
|
|
968
|
+
"button",
|
|
969
|
+
{
|
|
970
|
+
type: "button",
|
|
971
|
+
onClick: handleCopy,
|
|
972
|
+
disabled: !isValid,
|
|
973
|
+
className: lib.cn(
|
|
974
|
+
"p-1 rounded transition-colors duration-150",
|
|
975
|
+
"hover:bg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",
|
|
976
|
+
"disabled:opacity-50 disabled:cursor-not-allowed"
|
|
977
|
+
),
|
|
978
|
+
title: copied ? "Copied!" : "Copy cron expression",
|
|
979
|
+
children: copied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-3.5 w-3.5 text-green-500" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-3.5 w-3.5 text-muted-foreground" })
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
] }),
|
|
983
|
+
showCronExpression && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-1.5 pt-1.5 border-t border-border/30 flex items-center justify-between", children: [
|
|
984
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "text-xs font-mono text-muted-foreground", children: cronExpression }),
|
|
985
|
+
/* @__PURE__ */ jsxRuntime.jsx(CronCheatsheet, {})
|
|
986
|
+
] })
|
|
987
|
+
]
|
|
988
|
+
}
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
chunkWGEGR3DF_cjs.__name(SchedulePreview, "SchedulePreview");
|
|
992
|
+
|
|
993
|
+
exports.CronSchedulerProvider = CronSchedulerProvider;
|
|
994
|
+
exports.CustomInput = CustomInput;
|
|
995
|
+
exports.DayChips = DayChips;
|
|
996
|
+
exports.MonthDayGrid = MonthDayGrid;
|
|
997
|
+
exports.SchedulePreview = SchedulePreview;
|
|
998
|
+
exports.ScheduleTypeSelector = ScheduleTypeSelector;
|
|
999
|
+
exports.TimeSelector = TimeSelector;
|
|
1000
|
+
exports.buildCron = buildCron;
|
|
1001
|
+
exports.humanizeCron = humanizeCron;
|
|
1002
|
+
exports.isValidCron = isValidCron;
|
|
1003
|
+
exports.parseCron = parseCron;
|
|
1004
|
+
exports.useCronCustom = useCronCustom;
|
|
1005
|
+
exports.useCronMonthDays = useCronMonthDays;
|
|
1006
|
+
exports.useCronPreview = useCronPreview;
|
|
1007
|
+
exports.useCronScheduler = useCronScheduler;
|
|
1008
|
+
exports.useCronSchedulerContext = useCronSchedulerContext;
|
|
1009
|
+
exports.useCronTime = useCronTime;
|
|
1010
|
+
exports.useCronType = useCronType;
|
|
1011
|
+
exports.useCronWeekDays = useCronWeekDays;
|
|
1012
|
+
//# sourceMappingURL=chunk-JFGLA6DT.cjs.map
|
|
1013
|
+
//# sourceMappingURL=chunk-JFGLA6DT.cjs.map
|