@loykin/cron-input 0.0.1-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/index.cjs +556 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +548 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +476 -0
- package/dist/styles.d.ts +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LeeSuk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @loykin/cron-input
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@loykin/cron-input)
|
|
4
|
+
|
|
5
|
+
Cron expression builder with a visual schedule editor and raw expression fallback.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @loykin/cron-input
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { CronInput } from '@loykin/cron-input'
|
|
17
|
+
import '@loykin/cron-input/styles'
|
|
18
|
+
|
|
19
|
+
function App() {
|
|
20
|
+
const [value, setValue] = useState({ type: 'daily', hour: 9, minute: 0 })
|
|
21
|
+
|
|
22
|
+
return <CronInput value={value} onChange={setValue} />
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Modes
|
|
27
|
+
|
|
28
|
+
| Tab | Example expression |
|
|
29
|
+
|---|---|
|
|
30
|
+
| Interval | `*/5 * * * *` |
|
|
31
|
+
| Daily | `0 9 * * *` |
|
|
32
|
+
| Weekly | `30 9 * * 1,3,5` |
|
|
33
|
+
| Monthly | `0 9 1 * *` |
|
|
34
|
+
| Custom | supported 5-field cron subset (numbers, `*`, `*/n`, `a-b`, comma lists) |
|
|
35
|
+
|
|
36
|
+
## Utilities
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { toCronExpression, fromCronExpression, toDisplayString, validateCronExpression } from '@loykin/cron-input'
|
|
40
|
+
|
|
41
|
+
toCronExpression({ type: 'weekly', days: [1, 3, 5], hour: 9, minute: 0 })
|
|
42
|
+
// → "0 9 * * 1,3,5"
|
|
43
|
+
|
|
44
|
+
toDisplayString({ type: 'weekly', days: [1, 3, 5], hour: 9, minute: 0 })
|
|
45
|
+
// → "Mon, Wed, Fri at 09:00"
|
|
46
|
+
|
|
47
|
+
fromCronExpression('0 9 * * *')
|
|
48
|
+
// → { type: 'daily', hour: 9, minute: 0 }
|
|
49
|
+
|
|
50
|
+
validateCronExpression('99 99 * * *')
|
|
51
|
+
// → false
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Headless
|
|
55
|
+
|
|
56
|
+
Use `useCronInput` if you want full control over the UI:
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { useCronInput } from '@loykin/cron-input'
|
|
60
|
+
|
|
61
|
+
const { isOpen, setIsOpen, draft, setDraft, onApply, onCancel } = useCronInput({ value, onChange })
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Theming
|
|
65
|
+
|
|
66
|
+
Uses the shared `--basekit-*` CSS custom properties. See the [root README](../../README.md#theming) for the full token list.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
[GitHub](https://github.com/loykin/basekit) · [npm](https://www.npmjs.com/package/@loykin/cron-input)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var lucideReact = require('lucide-react');
|
|
5
|
+
var clsx = require('clsx');
|
|
6
|
+
var button = require('@base-ui/react/button');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var popover = require('@base-ui/react/popover');
|
|
9
|
+
var tabs = require('@base-ui/react/tabs');
|
|
10
|
+
|
|
11
|
+
// src/CronInput.tsx
|
|
12
|
+
function cn(...inputs) {
|
|
13
|
+
return clsx.clsx(inputs);
|
|
14
|
+
}
|
|
15
|
+
function Button({
|
|
16
|
+
className,
|
|
17
|
+
variant = "default",
|
|
18
|
+
size = "default",
|
|
19
|
+
...props
|
|
20
|
+
}) {
|
|
21
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
22
|
+
button.Button,
|
|
23
|
+
{
|
|
24
|
+
"data-variant": variant,
|
|
25
|
+
"data-size": size,
|
|
26
|
+
className: cn("ci-btn", className),
|
|
27
|
+
...props
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
function Popover({ ...props }) {
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Root, { ...props });
|
|
33
|
+
}
|
|
34
|
+
function PopoverTrigger({ ...props }) {
|
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Trigger, { ...props });
|
|
36
|
+
}
|
|
37
|
+
function PopoverContent({
|
|
38
|
+
className,
|
|
39
|
+
align = "start",
|
|
40
|
+
side = "bottom",
|
|
41
|
+
sideOffset = 4,
|
|
42
|
+
container,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
return /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Portal, { container, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
46
|
+
popover.Popover.Positioner,
|
|
47
|
+
{
|
|
48
|
+
align,
|
|
49
|
+
side,
|
|
50
|
+
sideOffset,
|
|
51
|
+
className: "ci-positioner",
|
|
52
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(popover.Popover.Popup, { className: cn("ci-popover-content", className), ...props })
|
|
53
|
+
}
|
|
54
|
+
) });
|
|
55
|
+
}
|
|
56
|
+
function Tabs({ className, ...props }) {
|
|
57
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
58
|
+
tabs.Tabs.Root,
|
|
59
|
+
{
|
|
60
|
+
"data-orientation": "horizontal",
|
|
61
|
+
className: cn("ci-tabs", className),
|
|
62
|
+
...props
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
function TabsList({ className, ...props }) {
|
|
67
|
+
return /* @__PURE__ */ jsxRuntime.jsx(tabs.Tabs.List, { className: cn("ci-tabs-list", className), ...props });
|
|
68
|
+
}
|
|
69
|
+
function TabsTrigger({ className, ...props }) {
|
|
70
|
+
return /* @__PURE__ */ jsxRuntime.jsx(tabs.Tabs.Tab, { className: cn("ci-tabs-trigger", className), ...props });
|
|
71
|
+
}
|
|
72
|
+
function TabsContent({ className, ...props }) {
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsx(tabs.Tabs.Panel, { className: cn("ci-tabs-content", className), ...props });
|
|
74
|
+
}
|
|
75
|
+
function useCronInput({ value, onChange }) {
|
|
76
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
77
|
+
const [draft, setDraft] = react.useState(value);
|
|
78
|
+
const wasOpen = react.useRef(false);
|
|
79
|
+
react.useEffect(() => {
|
|
80
|
+
const justOpened = isOpen && !wasOpen.current;
|
|
81
|
+
wasOpen.current = isOpen;
|
|
82
|
+
if (justOpened) setDraft(value);
|
|
83
|
+
}, [isOpen, value]);
|
|
84
|
+
const onApply = react.useCallback(() => {
|
|
85
|
+
onChange(draft);
|
|
86
|
+
setIsOpen(false);
|
|
87
|
+
}, [draft, onChange]);
|
|
88
|
+
const onCancel = react.useCallback(() => {
|
|
89
|
+
setDraft(value);
|
|
90
|
+
setIsOpen(false);
|
|
91
|
+
}, [value]);
|
|
92
|
+
return { isOpen, setIsOpen, draft, setDraft, onApply, onCancel };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/cron-utils.ts
|
|
96
|
+
var DAY_LABELS = {
|
|
97
|
+
0: "Sun",
|
|
98
|
+
1: "Mon",
|
|
99
|
+
2: "Tue",
|
|
100
|
+
3: "Wed",
|
|
101
|
+
4: "Thu",
|
|
102
|
+
5: "Fri",
|
|
103
|
+
6: "Sat"
|
|
104
|
+
};
|
|
105
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
106
|
+
function toCronExpression(value) {
|
|
107
|
+
switch (value.type) {
|
|
108
|
+
case "interval": {
|
|
109
|
+
const { every, unit } = value;
|
|
110
|
+
if (unit === "minute") return `*/${every} * * * *`;
|
|
111
|
+
if (unit === "hour") return `0 */${every} * * *`;
|
|
112
|
+
return `0 0 */${every} * *`;
|
|
113
|
+
}
|
|
114
|
+
case "daily":
|
|
115
|
+
return `${value.minute} ${value.hour} * * *`;
|
|
116
|
+
case "weekly": {
|
|
117
|
+
const days = value.days.length === 0 ? "*" : [...value.days].sort((a, b) => a - b).join(",");
|
|
118
|
+
return `${value.minute} ${value.hour} * * ${days}`;
|
|
119
|
+
}
|
|
120
|
+
case "monthly":
|
|
121
|
+
return `${value.minute} ${value.hour} ${value.day} * *`;
|
|
122
|
+
case "custom":
|
|
123
|
+
return value.expression;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function toDisplayString(value) {
|
|
127
|
+
switch (value.type) {
|
|
128
|
+
case "interval": {
|
|
129
|
+
const { every, unit } = value;
|
|
130
|
+
const label = unit === "minute" ? every === 1 ? "minute" : "minutes" : unit === "hour" ? every === 1 ? "hour" : "hours" : every === 1 ? "day" : "days";
|
|
131
|
+
return every === 1 ? `Every ${label}` : `Every ${every} ${label}`;
|
|
132
|
+
}
|
|
133
|
+
case "daily":
|
|
134
|
+
return `Daily at ${pad(value.hour)}:${pad(value.minute)}`;
|
|
135
|
+
case "weekly": {
|
|
136
|
+
if (value.days.length === 0) return `Weekly at ${pad(value.hour)}:${pad(value.minute)}`;
|
|
137
|
+
const dayStr = [...value.days].sort((a, b) => a - b).map((d) => DAY_LABELS[d]).join(", ");
|
|
138
|
+
return `${dayStr} at ${pad(value.hour)}:${pad(value.minute)}`;
|
|
139
|
+
}
|
|
140
|
+
case "monthly":
|
|
141
|
+
return `Monthly, day ${value.day} at ${pad(value.hour)}:${pad(value.minute)}`;
|
|
142
|
+
case "custom":
|
|
143
|
+
return value.expression || "Custom schedule";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function fromCronExpression(expr) {
|
|
147
|
+
if (!validateCronExpression(expr)) return { type: "custom", expression: expr };
|
|
148
|
+
const parts = expr.trim().split(/\s+/);
|
|
149
|
+
const [min, hour, dom, month, dow] = parts;
|
|
150
|
+
const m = parseInt(min, 10);
|
|
151
|
+
const h = parseInt(hour, 10);
|
|
152
|
+
if (/^\*\/\d+$/.test(min) && hour === "*" && dom === "*" && month === "*" && dow === "*")
|
|
153
|
+
return { type: "interval", every: parseInt(min.slice(2), 10), unit: "minute" };
|
|
154
|
+
if (min === "0" && /^\*\/\d+$/.test(hour) && dom === "*" && month === "*" && dow === "*")
|
|
155
|
+
return { type: "interval", every: parseInt(hour.slice(2), 10), unit: "hour" };
|
|
156
|
+
if (min === "0" && hour === "0" && /^\*\/\d+$/.test(dom) && month === "*" && dow === "*")
|
|
157
|
+
return { type: "interval", every: parseInt(dom.slice(2), 10), unit: "day" };
|
|
158
|
+
if (/^\d+$/.test(min) && /^\d+$/.test(hour) && dom === "*" && month === "*" && dow === "*")
|
|
159
|
+
return { type: "daily", hour: h, minute: m };
|
|
160
|
+
if (/^\d+$/.test(min) && /^\d+$/.test(hour) && dom === "*" && month === "*" && /^[\d,]+$/.test(dow)) {
|
|
161
|
+
const normalized = [...new Set(dow.split(",").map(Number).map((d) => d === 7 ? 0 : d))].filter((d) => d >= 0 && d <= 6).sort((a, b) => a - b);
|
|
162
|
+
return { type: "weekly", days: normalized, hour: h, minute: m };
|
|
163
|
+
}
|
|
164
|
+
if (/^\d+$/.test(min) && /^\d+$/.test(hour) && /^\d+$/.test(dom) && month === "*" && dow === "*") {
|
|
165
|
+
const day = parseInt(dom, 10);
|
|
166
|
+
return { type: "monthly", day, hour: h, minute: m };
|
|
167
|
+
}
|
|
168
|
+
return { type: "custom", expression: expr };
|
|
169
|
+
}
|
|
170
|
+
function isValidNumber(s, min, max) {
|
|
171
|
+
if (!/^\d+$/.test(s)) return false;
|
|
172
|
+
const n = parseInt(s, 10);
|
|
173
|
+
return n >= min && n <= max;
|
|
174
|
+
}
|
|
175
|
+
function isValidField(field, min, max) {
|
|
176
|
+
if (field === "*") return true;
|
|
177
|
+
if (field.startsWith("*/")) {
|
|
178
|
+
const step = parseInt(field.slice(2), 10);
|
|
179
|
+
return !isNaN(step) && step >= 1 && step <= max;
|
|
180
|
+
}
|
|
181
|
+
if (field.includes(",")) {
|
|
182
|
+
return field.split(",").every((part) => isValidField(part, min, max));
|
|
183
|
+
}
|
|
184
|
+
if (field.includes("-")) {
|
|
185
|
+
const parts = field.split("-");
|
|
186
|
+
if (parts.length !== 2) return false;
|
|
187
|
+
const [a, b] = parts.map(Number);
|
|
188
|
+
return !isNaN(a) && !isNaN(b) && a >= min && a <= max && b >= min && b <= max && a <= b;
|
|
189
|
+
}
|
|
190
|
+
return isValidNumber(field, min, max);
|
|
191
|
+
}
|
|
192
|
+
function validateCronExpression(expr) {
|
|
193
|
+
const parts = expr.trim().split(/\s+/);
|
|
194
|
+
if (parts.length !== 5) return false;
|
|
195
|
+
const [min, hour, dom, month, dow] = parts;
|
|
196
|
+
return isValidField(min, 0, 59) && isValidField(hour, 0, 23) && isValidField(dom, 1, 31) && isValidField(month, 1, 12) && isValidField(dow, 0, 7);
|
|
197
|
+
}
|
|
198
|
+
function switchTab(current, next) {
|
|
199
|
+
const hour = "hour" in current ? current.hour : 9;
|
|
200
|
+
const minute = "minute" in current ? current.minute : 0;
|
|
201
|
+
switch (next) {
|
|
202
|
+
case "interval":
|
|
203
|
+
return { type: "interval", every: 5, unit: "minute" };
|
|
204
|
+
case "daily":
|
|
205
|
+
return { type: "daily", hour, minute };
|
|
206
|
+
case "weekly":
|
|
207
|
+
return {
|
|
208
|
+
type: "weekly",
|
|
209
|
+
days: current.type === "weekly" ? current.days : [1, 3, 5],
|
|
210
|
+
hour,
|
|
211
|
+
minute
|
|
212
|
+
};
|
|
213
|
+
case "monthly":
|
|
214
|
+
return {
|
|
215
|
+
type: "monthly",
|
|
216
|
+
day: current.type === "monthly" ? current.day : 1,
|
|
217
|
+
hour,
|
|
218
|
+
minute
|
|
219
|
+
};
|
|
220
|
+
case "custom":
|
|
221
|
+
return { type: "custom", expression: toCronExpression(current) };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/types.ts
|
|
226
|
+
var DEFAULT_LABELS = {
|
|
227
|
+
interval: "Interval",
|
|
228
|
+
daily: "Daily",
|
|
229
|
+
weekly: "Weekly",
|
|
230
|
+
monthly: "Monthly",
|
|
231
|
+
custom: "Custom",
|
|
232
|
+
apply: "Apply",
|
|
233
|
+
cancel: "Cancel"
|
|
234
|
+
};
|
|
235
|
+
var DEFAULT_VALUE = { type: "daily", hour: 9, minute: 0 };
|
|
236
|
+
function NumberStepper({ value, min, max, padded = true, onChange }) {
|
|
237
|
+
const clamp = (n) => Math.min(max, Math.max(min, n));
|
|
238
|
+
const display = padded ? String(value).padStart(2, "0") : String(value);
|
|
239
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-stepper", children: [
|
|
240
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
241
|
+
"button",
|
|
242
|
+
{
|
|
243
|
+
type: "button",
|
|
244
|
+
className: "ci-stepper-btn",
|
|
245
|
+
onClick: () => onChange(clamp(value - 1)),
|
|
246
|
+
tabIndex: -1,
|
|
247
|
+
"aria-label": "Decrease",
|
|
248
|
+
children: "\u2212"
|
|
249
|
+
}
|
|
250
|
+
),
|
|
251
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
252
|
+
"input",
|
|
253
|
+
{
|
|
254
|
+
type: "text",
|
|
255
|
+
inputMode: "numeric",
|
|
256
|
+
className: "ci-stepper-input",
|
|
257
|
+
value: display,
|
|
258
|
+
onChange: (e) => {
|
|
259
|
+
const raw = e.target.value.replace(/\D/g, "");
|
|
260
|
+
if (raw === "") return;
|
|
261
|
+
const n = parseInt(raw, 10);
|
|
262
|
+
if (!isNaN(n)) onChange(clamp(n));
|
|
263
|
+
},
|
|
264
|
+
onKeyDown: (e) => {
|
|
265
|
+
if (e.key === "ArrowUp") {
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
onChange(clamp(value + 1));
|
|
268
|
+
}
|
|
269
|
+
if (e.key === "ArrowDown") {
|
|
270
|
+
e.preventDefault();
|
|
271
|
+
onChange(clamp(value - 1));
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
onFocus: (e) => e.currentTarget.select()
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
278
|
+
"button",
|
|
279
|
+
{
|
|
280
|
+
type: "button",
|
|
281
|
+
className: "ci-stepper-btn",
|
|
282
|
+
onClick: () => onChange(clamp(value + 1)),
|
|
283
|
+
tabIndex: -1,
|
|
284
|
+
"aria-label": "Increase",
|
|
285
|
+
children: "+"
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
] });
|
|
289
|
+
}
|
|
290
|
+
function TimePicker({ hour, minute, onChange }) {
|
|
291
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-time", children: [
|
|
292
|
+
/* @__PURE__ */ jsxRuntime.jsx(NumberStepper, { value: hour, min: 0, max: 23, onChange: (h) => onChange(h, minute) }),
|
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-time-sep", children: ":" }),
|
|
294
|
+
/* @__PURE__ */ jsxRuntime.jsx(NumberStepper, { value: minute, min: 0, max: 59, onChange: (m) => onChange(hour, m) })
|
|
295
|
+
] });
|
|
296
|
+
}
|
|
297
|
+
var DAYS = [
|
|
298
|
+
{ index: 1, label: "Mo" },
|
|
299
|
+
{ index: 2, label: "Tu" },
|
|
300
|
+
{ index: 3, label: "We" },
|
|
301
|
+
{ index: 4, label: "Th" },
|
|
302
|
+
{ index: 5, label: "Fr" },
|
|
303
|
+
{ index: 6, label: "Sa" },
|
|
304
|
+
{ index: 0, label: "Su" }
|
|
305
|
+
];
|
|
306
|
+
function DayChips({ days, onChange }) {
|
|
307
|
+
const toggle = (day) => {
|
|
308
|
+
const next = days.includes(day) ? days.filter((d) => d !== day) : [...days, day].sort((a, b) => a - b);
|
|
309
|
+
onChange(next);
|
|
310
|
+
};
|
|
311
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ci-day-chips", children: DAYS.map((d) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
312
|
+
"button",
|
|
313
|
+
{
|
|
314
|
+
type: "button",
|
|
315
|
+
className: cn("ci-day-chip", days.includes(d.index) && "ci-day-chip--active"),
|
|
316
|
+
onClick: () => toggle(d.index),
|
|
317
|
+
children: d.label
|
|
318
|
+
},
|
|
319
|
+
d.index
|
|
320
|
+
)) });
|
|
321
|
+
}
|
|
322
|
+
function IntervalTab({ every, unit, onChange }) {
|
|
323
|
+
const maxMap = { minute: 59, hour: 23, day: 30 };
|
|
324
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ci-tab-body", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-interval-row", children: [
|
|
325
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "Every" }),
|
|
326
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
327
|
+
NumberStepper,
|
|
328
|
+
{
|
|
329
|
+
value: every,
|
|
330
|
+
min: 1,
|
|
331
|
+
max: maxMap[unit],
|
|
332
|
+
padded: false,
|
|
333
|
+
onChange: (n) => onChange(n, unit)
|
|
334
|
+
}
|
|
335
|
+
),
|
|
336
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ci-unit-seg", children: ["minute", "hour", "day"].map((u) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
337
|
+
"button",
|
|
338
|
+
{
|
|
339
|
+
type: "button",
|
|
340
|
+
className: cn("ci-unit-btn", unit === u && "ci-unit-btn--active"),
|
|
341
|
+
onClick: () => onChange(Math.min(every, maxMap[u]), u),
|
|
342
|
+
children: u === "minute" ? "min" : u === "hour" ? "hr" : "day"
|
|
343
|
+
},
|
|
344
|
+
u
|
|
345
|
+
)) })
|
|
346
|
+
] }) });
|
|
347
|
+
}
|
|
348
|
+
function DailyTab({ hour, minute, onChange }) {
|
|
349
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ci-tab-body", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-field-row", children: [
|
|
350
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "Every day at" }),
|
|
351
|
+
/* @__PURE__ */ jsxRuntime.jsx(TimePicker, { hour, minute, onChange })
|
|
352
|
+
] }) });
|
|
353
|
+
}
|
|
354
|
+
function WeeklyTab({ days, hour, minute, onChange }) {
|
|
355
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-tab-body", children: [
|
|
356
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-field-row ci-field-row--col", children: [
|
|
357
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "Repeat on" }),
|
|
358
|
+
/* @__PURE__ */ jsxRuntime.jsx(DayChips, { days, onChange: (d) => onChange(d, hour, minute) })
|
|
359
|
+
] }),
|
|
360
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-field-row ci-field-row--mt", children: [
|
|
361
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "At" }),
|
|
362
|
+
/* @__PURE__ */ jsxRuntime.jsx(TimePicker, { hour, minute, onChange: (h, m) => onChange(days, h, m) })
|
|
363
|
+
] })
|
|
364
|
+
] });
|
|
365
|
+
}
|
|
366
|
+
function MonthlyTab({ day, hour, minute, onChange }) {
|
|
367
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-tab-body", children: [
|
|
368
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-field-row", children: [
|
|
369
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "On day" }),
|
|
370
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
371
|
+
NumberStepper,
|
|
372
|
+
{
|
|
373
|
+
value: day,
|
|
374
|
+
min: 1,
|
|
375
|
+
max: 28,
|
|
376
|
+
padded: false,
|
|
377
|
+
onChange: (d) => onChange(d, hour, minute)
|
|
378
|
+
}
|
|
379
|
+
),
|
|
380
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "of every month" })
|
|
381
|
+
] }),
|
|
382
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-field-row ci-field-row--mt", children: [
|
|
383
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-label", children: "At" }),
|
|
384
|
+
/* @__PURE__ */ jsxRuntime.jsx(TimePicker, { hour, minute, onChange: (h, m) => onChange(day, h, m) })
|
|
385
|
+
] })
|
|
386
|
+
] });
|
|
387
|
+
}
|
|
388
|
+
function CustomTab({ expression, onChange }) {
|
|
389
|
+
const [input, setInput] = react.useState(expression);
|
|
390
|
+
react.useEffect(() => {
|
|
391
|
+
setInput(expression);
|
|
392
|
+
}, [expression]);
|
|
393
|
+
const parts = input.trim().split(/\s+/);
|
|
394
|
+
const isValid = validateCronExpression(input);
|
|
395
|
+
const parsed = isValid && parts.length === 5 ? fromCronExpression(input) : null;
|
|
396
|
+
const FIELD_LABELS = ["min", "hour", "dom", "mon", "dow"];
|
|
397
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-tab-body ci-custom", children: [
|
|
398
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("ci-custom-wrap", input && !isValid && "ci-custom-wrap--error"), children: [
|
|
399
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
400
|
+
"input",
|
|
401
|
+
{
|
|
402
|
+
type: "text",
|
|
403
|
+
className: "ci-custom-input",
|
|
404
|
+
value: input,
|
|
405
|
+
placeholder: "* * * * *",
|
|
406
|
+
spellCheck: false,
|
|
407
|
+
onChange: (e) => {
|
|
408
|
+
setInput(e.target.value);
|
|
409
|
+
onChange(e.target.value);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
input && /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("ci-custom-badge", isValid ? "ci-custom-badge--ok" : "ci-custom-badge--err"), children: isValid ? "\u2713" : "\u2717" })
|
|
414
|
+
] }),
|
|
415
|
+
isValid && parsed && parsed.type !== "custom" && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "ci-custom-desc", children: toDisplayString(parsed) }),
|
|
416
|
+
parts.length === 5 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ci-custom-fields", children: FIELD_LABELS.map((label, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-custom-field", children: [
|
|
417
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-custom-field-val", children: parts[i] }),
|
|
418
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-custom-field-lbl", children: label })
|
|
419
|
+
] }, label)) })
|
|
420
|
+
] });
|
|
421
|
+
}
|
|
422
|
+
function CronInput({
|
|
423
|
+
value: valueProp,
|
|
424
|
+
defaultValue = DEFAULT_VALUE,
|
|
425
|
+
onChange,
|
|
426
|
+
disabled = false,
|
|
427
|
+
labels: labelsProp,
|
|
428
|
+
popoverAlign = "start",
|
|
429
|
+
popoverSide = "bottom",
|
|
430
|
+
renderTrigger,
|
|
431
|
+
portalContainer,
|
|
432
|
+
className
|
|
433
|
+
}) {
|
|
434
|
+
const labels = { ...DEFAULT_LABELS, ...labelsProp };
|
|
435
|
+
const [uncontrolled, setUncontrolled] = react.useState(defaultValue);
|
|
436
|
+
const isControlled = valueProp !== void 0;
|
|
437
|
+
const value = isControlled ? valueProp : uncontrolled;
|
|
438
|
+
const handleChange = (next) => {
|
|
439
|
+
if (!isControlled) setUncontrolled(next);
|
|
440
|
+
onChange?.(next);
|
|
441
|
+
};
|
|
442
|
+
const { isOpen, setIsOpen, draft, setDraft, onApply, onCancel } = useCronInput({
|
|
443
|
+
value,
|
|
444
|
+
onChange: handleChange
|
|
445
|
+
});
|
|
446
|
+
const handleTabChange = (tab) => {
|
|
447
|
+
setDraft(switchTab(draft, tab));
|
|
448
|
+
};
|
|
449
|
+
const handleDraft = (next) => setDraft(next);
|
|
450
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: isOpen, onOpenChange: disabled ? void 0 : setIsOpen, children: [
|
|
451
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
452
|
+
PopoverTrigger,
|
|
453
|
+
{
|
|
454
|
+
disabled,
|
|
455
|
+
render: (triggerProps) => renderTrigger ? renderTrigger(triggerProps, { open: isOpen, value }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
456
|
+
"button",
|
|
457
|
+
{
|
|
458
|
+
...triggerProps,
|
|
459
|
+
disabled,
|
|
460
|
+
className: cn("ci-trigger", isOpen && "ci-trigger--open", className),
|
|
461
|
+
children: [
|
|
462
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock, { size: 13, className: "ci-trigger-icon" }),
|
|
463
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-trigger-label", children: toDisplayString(value) })
|
|
464
|
+
]
|
|
465
|
+
}
|
|
466
|
+
)
|
|
467
|
+
}
|
|
468
|
+
),
|
|
469
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
470
|
+
PopoverContent,
|
|
471
|
+
{
|
|
472
|
+
align: popoverAlign,
|
|
473
|
+
side: popoverSide,
|
|
474
|
+
sideOffset: 4,
|
|
475
|
+
container: portalContainer,
|
|
476
|
+
children: [
|
|
477
|
+
/* @__PURE__ */ jsxRuntime.jsxs(Tabs, { value: draft.type, onValueChange: handleTabChange, children: [
|
|
478
|
+
/* @__PURE__ */ jsxRuntime.jsxs(TabsList, { children: [
|
|
479
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "interval", children: labels.interval }),
|
|
480
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "daily", children: labels.daily }),
|
|
481
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "weekly", children: labels.weekly }),
|
|
482
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "monthly", children: labels.monthly }),
|
|
483
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: "custom", children: labels.custom })
|
|
484
|
+
] }),
|
|
485
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "interval", children: draft.type === "interval" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
486
|
+
IntervalTab,
|
|
487
|
+
{
|
|
488
|
+
every: draft.every,
|
|
489
|
+
unit: draft.unit,
|
|
490
|
+
onChange: (every, unit) => handleDraft({ type: "interval", every, unit })
|
|
491
|
+
}
|
|
492
|
+
) }),
|
|
493
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "daily", children: draft.type === "daily" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
494
|
+
DailyTab,
|
|
495
|
+
{
|
|
496
|
+
hour: draft.hour,
|
|
497
|
+
minute: draft.minute,
|
|
498
|
+
onChange: (hour, minute) => handleDraft({ type: "daily", hour, minute })
|
|
499
|
+
}
|
|
500
|
+
) }),
|
|
501
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "weekly", children: draft.type === "weekly" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
502
|
+
WeeklyTab,
|
|
503
|
+
{
|
|
504
|
+
days: draft.days,
|
|
505
|
+
hour: draft.hour,
|
|
506
|
+
minute: draft.minute,
|
|
507
|
+
onChange: (days, hour, minute) => handleDraft({ type: "weekly", days, hour, minute })
|
|
508
|
+
}
|
|
509
|
+
) }),
|
|
510
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "monthly", children: draft.type === "monthly" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
511
|
+
MonthlyTab,
|
|
512
|
+
{
|
|
513
|
+
day: draft.day,
|
|
514
|
+
hour: draft.hour,
|
|
515
|
+
minute: draft.minute,
|
|
516
|
+
onChange: (day, hour, minute) => handleDraft({ type: "monthly", day, hour, minute })
|
|
517
|
+
}
|
|
518
|
+
) }),
|
|
519
|
+
/* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: "custom", children: draft.type === "custom" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
520
|
+
CustomTab,
|
|
521
|
+
{
|
|
522
|
+
expression: draft.expression,
|
|
523
|
+
onChange: (expression) => handleDraft({ type: "custom", expression })
|
|
524
|
+
}
|
|
525
|
+
) })
|
|
526
|
+
] }),
|
|
527
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-footer", children: [
|
|
528
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ci-preview", children: toDisplayString(draft) }),
|
|
529
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ci-footer-actions", children: [
|
|
530
|
+
/* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "outline", size: "sm", onClick: onCancel, children: labels.cancel }),
|
|
531
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
532
|
+
Button,
|
|
533
|
+
{
|
|
534
|
+
size: "sm",
|
|
535
|
+
onClick: onApply,
|
|
536
|
+
disabled: draft.type === "custom" && !validateCronExpression(draft.expression),
|
|
537
|
+
children: labels.apply
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
] })
|
|
541
|
+
] })
|
|
542
|
+
]
|
|
543
|
+
}
|
|
544
|
+
)
|
|
545
|
+
] });
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
exports.CronInput = CronInput;
|
|
549
|
+
exports.DEFAULT_VALUE = DEFAULT_VALUE;
|
|
550
|
+
exports.fromCronExpression = fromCronExpression;
|
|
551
|
+
exports.toCronExpression = toCronExpression;
|
|
552
|
+
exports.toDisplayString = toDisplayString;
|
|
553
|
+
exports.useCronInput = useCronInput;
|
|
554
|
+
exports.validateCronExpression = validateCronExpression;
|
|
555
|
+
//# sourceMappingURL=index.cjs.map
|
|
556
|
+
//# sourceMappingURL=index.cjs.map
|