@f-ewald/components 1.29.0 → 1.30.1

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.
@@ -0,0 +1,768 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LitElement, css, html, nothing } from "lit";
8
+ import { customElement, property, state } from "lit/decorators.js";
9
+ import { iconChevronRight, iconClock, iconPlus, iconTrash } from "./icons.js";
10
+ import { tokens } from "./tokens.js";
11
+ import { activateLayer, claimEscape, deactivateLayer, isTopLayer, } from "./utils/layer-stack.js";
12
+ import { CRON_FIELD_BOUNDS, CRON_FIELD_LABELS, CRON_FIELD_NAMES, MONTH_ABBREVIATIONS, WEEKDAY_ABBREVIATIONS, describeCron, detectFrequency, expandField, fieldFromValues, formatCron, isEveryValue, parseCron, } from "./utils/cron.js";
13
+ import "./button-group.js";
14
+ import "./form-select.js";
15
+ import "./icon-button.js";
16
+ import "./ui-button.js";
17
+ import "./ui-checkbox.js";
18
+ let instanceCount = 0;
19
+ /** The frequency presets offered above the advanced per-field editor. */
20
+ const FREQUENCY_OPTIONS = [
21
+ { value: "minute", label: "Every N minutes" },
22
+ { value: "hourly", label: "Hourly" },
23
+ { value: "daily", label: "Daily" },
24
+ { value: "weekly", label: "Weekly" },
25
+ { value: "monthly", label: "Monthly" },
26
+ { value: "yearly", label: "Yearly" },
27
+ { value: "advanced", label: "Advanced" },
28
+ ];
29
+ const TERM_KIND_OPTIONS = [
30
+ { value: "all", label: "Any" },
31
+ { value: "value", label: "One" },
32
+ { value: "range", label: "Range" },
33
+ { value: "step", label: "Step" },
34
+ ];
35
+ const DEFAULT_EXPRESSION = "0 * * * *";
36
+ function numberOptions(from, to, pad = false) {
37
+ const options = [];
38
+ for (let value = from; value <= to; value += 1) {
39
+ options.push({ value: String(value), label: pad ? String(value).padStart(2, "0") : String(value) });
40
+ }
41
+ return options;
42
+ }
43
+ function fieldOptions(name) {
44
+ const [min, max] = CRON_FIELD_BOUNDS[name];
45
+ if (name === "month") {
46
+ return MONTH_ABBREVIATIONS.map((label, index) => ({ value: String(index + 1), label }));
47
+ }
48
+ if (name === "dayOfWeek") {
49
+ return WEEKDAY_ABBREVIATIONS.map((label, index) => ({ value: String(index), label }));
50
+ }
51
+ return numberOptions(min, max);
52
+ }
53
+ /**
54
+ * Repeat-schedule picker that reads and writes a standard 5-field cron
55
+ * expression. The collapsed trigger shows a compact English description of
56
+ * the current schedule ("Every hour", "10:17 every Monday"); clicking it
57
+ * opens an anchored panel with the schedule form.
58
+ *
59
+ * The panel offers frequency presets (every N minutes, hourly, daily, weekly,
60
+ * monthly, yearly) plus an `Advanced` mode that edits each cron field as a
61
+ * list of terms, so any valid expression — including compound fields that mix
62
+ * ranges, steps, and single values — is reachable. Edits apply immediately:
63
+ * each change updates `value` and fires `change`; closing the panel only
64
+ * dismisses it.
65
+ *
66
+ * An unparseable `value` (e.g. `@reboot`, which has no five-field form) is
67
+ * preserved verbatim and shown as-is on the trigger; the panel then starts
68
+ * from the default hourly schedule.
69
+ *
70
+ * The host is `display: block` with a full-width trigger, matching the other
71
+ * value-entry fields. To shrink an instance to its content, constrain the
72
+ * host: `cron-schedule { display: inline-block; }`.
73
+ *
74
+ * @element cron-schedule
75
+ * @fires change - Fired with `{ value: string }` whenever the expression changes.
76
+ */
77
+ let CronSchedule = class CronSchedule extends LitElement {
78
+ constructor() {
79
+ super(...arguments);
80
+ /** The cron expression, e.g. `"0 * * * *"`. */
81
+ this.value = DEFAULT_EXPRESSION;
82
+ /** Accessible label for the trigger. */
83
+ this.label = "";
84
+ /** Whether the picker is disabled. */
85
+ this.disabled = false;
86
+ /** Whether the schedule panel is open. */
87
+ this.open = false;
88
+ this._mode = "hourly";
89
+ this.#panelId = `cron-schedule-panel-${++instanceCount}`;
90
+ this.#valueIsInternal = false;
91
+ this.#onWindowMousedown = (e) => {
92
+ if (!isTopLayer(this))
93
+ return;
94
+ // An outside click is already moving focus somewhere else, so closing
95
+ // must not pull it back to the trigger.
96
+ if (!e.composedPath().includes(this))
97
+ this.#close(false);
98
+ };
99
+ this.#onWindowKeydown = (e) => {
100
+ if (!isTopLayer(this))
101
+ return;
102
+ if (claimEscape(this, e))
103
+ this.#close();
104
+ };
105
+ }
106
+ static { this.styles = [
107
+ tokens,
108
+ css `
109
+ :host {
110
+ display: block;
111
+ position: relative;
112
+ font-family: var(
113
+ --ui-font,
114
+ ui-sans-serif,
115
+ system-ui,
116
+ sans-serif,
117
+ "Apple Color Emoji",
118
+ "Segoe UI Emoji",
119
+ "Segoe UI Symbol",
120
+ "Noto Color Emoji"
121
+ );
122
+ font-size: var(--ui-font-size-sm, 0.75rem);
123
+ }
124
+ button.trigger {
125
+ display: flex;
126
+ align-items: center;
127
+ gap: 0.5rem;
128
+ width: 100%;
129
+ height: 2rem;
130
+ box-sizing: border-box;
131
+ font-size: var(--ui-font-size-sm, 0.75rem);
132
+ line-height: var(--ui-line-height-tight, 1.25);
133
+ color: var(--ui-text, #0f172a);
134
+ background: var(--ui-surface, #ffffff);
135
+ border: 1px solid var(--ui-border, #e2e8f0);
136
+ border-radius: var(--ui-radius-sm, 0.25rem);
137
+ padding: 0.5rem 0.75rem;
138
+ cursor: pointer;
139
+ text-align: left;
140
+ font-family: var(
141
+ --ui-font,
142
+ ui-sans-serif,
143
+ system-ui,
144
+ sans-serif,
145
+ "Apple Color Emoji",
146
+ "Segoe UI Emoji",
147
+ "Segoe UI Symbol",
148
+ "Noto Color Emoji"
149
+ );
150
+ }
151
+ button.trigger:hover:not(:disabled) {
152
+ background: var(--ui-surface-muted, #f8fafc);
153
+ }
154
+ button.trigger:disabled {
155
+ cursor: not-allowed;
156
+ opacity: 0.6;
157
+ }
158
+ button.trigger:focus-visible {
159
+ outline: none;
160
+ border-color: var(--ui-primary, #4f46e5);
161
+ box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
162
+ }
163
+ .trigger-icon {
164
+ display: flex;
165
+ flex: 0 0 auto;
166
+ color: var(--ui-text-muted, #64748b);
167
+ }
168
+ .trigger-label {
169
+ flex: 1 1 auto;
170
+ min-width: 0;
171
+ overflow: hidden;
172
+ white-space: nowrap;
173
+ text-overflow: ellipsis;
174
+ }
175
+ .chevron {
176
+ display: flex;
177
+ flex: 0 0 auto;
178
+ color: var(--ui-text-muted, #64748b);
179
+ transform: rotate(90deg);
180
+ transition: transform 150ms ease;
181
+ }
182
+ :host([open]) .chevron {
183
+ transform: rotate(-90deg);
184
+ }
185
+ .panel {
186
+ /* Deliberately not a scroll container: an overflow ancestor clips the
187
+ nested form-select listboxes, which are absolutely positioned and
188
+ routinely taller than the panel itself. */
189
+ position: absolute;
190
+ top: calc(100% + 0.5rem);
191
+ left: 0;
192
+ z-index: var(--component-layer-z, 20);
193
+ box-sizing: border-box;
194
+ width: 25rem;
195
+ max-width: calc(100vw - 2rem);
196
+ display: flex;
197
+ flex-direction: column;
198
+ gap: 0.75rem;
199
+ padding: 0.75rem;
200
+ color: var(--ui-text, #0f172a);
201
+ background: var(--ui-surface, #ffffff);
202
+ border: 1px solid var(--ui-border, #e2e8f0);
203
+ border-radius: var(--ui-radius, 0.5rem);
204
+ box-shadow: var(--ui-shadow-lg, 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1));
205
+ }
206
+ .panel:focus-visible {
207
+ outline: none;
208
+ }
209
+ .row {
210
+ display: flex;
211
+ align-items: center;
212
+ gap: 0.5rem;
213
+ }
214
+ .row.wrap {
215
+ flex-wrap: wrap;
216
+ }
217
+ .row form-select {
218
+ flex: 1 1 auto;
219
+ min-width: 0;
220
+ }
221
+ .row form-select.narrow {
222
+ flex: 0 0 5rem;
223
+ }
224
+ .group-label {
225
+ display: block;
226
+ margin-bottom: 0.25rem;
227
+ color: var(--ui-text-muted, #64748b);
228
+ font-size: var(--ui-font-size-xs, 0.6875rem);
229
+ font-weight: var(--ui-font-weight-medium, 500);
230
+ letter-spacing: var(--ui-tracking-wide, 0.04em);
231
+ text-transform: uppercase;
232
+ }
233
+ .inline-label {
234
+ flex: 0 0 auto;
235
+ color: var(--ui-text-muted, #64748b);
236
+ }
237
+ .grid {
238
+ display: grid;
239
+ gap: 0.25rem;
240
+ }
241
+ .grid.weekdays {
242
+ grid-template-columns: repeat(4, minmax(0, 1fr));
243
+ }
244
+ .grid.months {
245
+ grid-template-columns: repeat(4, minmax(0, 1fr));
246
+ }
247
+ .grid.days {
248
+ grid-template-columns: repeat(7, minmax(0, 1fr));
249
+ }
250
+ fieldset {
251
+ margin: 0;
252
+ padding: 0;
253
+ border: 0;
254
+ min-width: 0;
255
+ }
256
+ legend {
257
+ padding: 0;
258
+ }
259
+ .field-editor {
260
+ display: flex;
261
+ flex-direction: column;
262
+ gap: 0.25rem;
263
+ padding: 0.5rem;
264
+ border: 1px solid var(--ui-border, #e2e8f0);
265
+ border-radius: var(--ui-radius-sm, 0.25rem);
266
+ }
267
+ .field-editor + .field-editor {
268
+ margin-top: 0.5rem;
269
+ }
270
+ .field-header {
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: space-between;
274
+ gap: 0.5rem;
275
+ }
276
+ .term-row {
277
+ display: flex;
278
+ flex-direction: column;
279
+ gap: 0.25rem;
280
+ padding: 0.25rem 0;
281
+ }
282
+ .term-row + .term-row {
283
+ border-top: 1px solid var(--ui-border, #e2e8f0);
284
+ }
285
+ .term-row button-group {
286
+ flex: 1 1 auto;
287
+ min-width: 0;
288
+ }
289
+ .readout {
290
+ display: flex;
291
+ align-items: center;
292
+ gap: 0.5rem;
293
+ padding-top: 0.5rem;
294
+ border-top: 1px solid var(--ui-border, #e2e8f0);
295
+ }
296
+ .readout code {
297
+ flex: 1 1 auto;
298
+ min-width: 0;
299
+ overflow-x: auto;
300
+ font-family: var(--ui-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace);
301
+ font-size: var(--ui-font-size-sm, 0.75rem);
302
+ color: var(--ui-text, #0f172a);
303
+ background: var(--ui-surface-muted, #f8fafc);
304
+ border-radius: var(--ui-radius-sm, 0.25rem);
305
+ padding: 0.25rem 0.5rem;
306
+ white-space: nowrap;
307
+ }
308
+ .description {
309
+ color: var(--ui-text-muted, #64748b);
310
+ }
311
+ @media (max-width: 48rem) {
312
+ .panel {
313
+ width: calc(100vw - 2rem);
314
+ }
315
+ .grid.days {
316
+ grid-template-columns: repeat(5, minmax(0, 1fr));
317
+ }
318
+ }
319
+ @media (prefers-reduced-motion: reduce) {
320
+ .chevron {
321
+ transition: none;
322
+ }
323
+ }
324
+ @media (forced-colors: active) {
325
+ button.trigger:focus-visible {
326
+ outline: 2px solid CanvasText;
327
+ outline-offset: 1px;
328
+ }
329
+ .panel {
330
+ border: 1px solid CanvasText;
331
+ }
332
+ }
333
+ `,
334
+ ]; }
335
+ #panelId;
336
+ #valueIsInternal;
337
+ /** The compact English description of the current expression. */
338
+ get description() {
339
+ return describeCron(this.value);
340
+ }
341
+ disconnectedCallback() {
342
+ super.disconnectedCallback();
343
+ this.#teardownPanel();
344
+ this.open = false;
345
+ }
346
+ willUpdate(changed) {
347
+ if (changed.has("value") && !this.#valueIsInternal) {
348
+ this._mode = detectFrequency(this.#expression());
349
+ }
350
+ this.#valueIsInternal = false;
351
+ }
352
+ updated(changed) {
353
+ if (changed.has("disabled") && this.disabled && this.open) {
354
+ this.open = false;
355
+ return;
356
+ }
357
+ if (!changed.has("open"))
358
+ return;
359
+ if (this.open) {
360
+ activateLayer(this);
361
+ window.addEventListener("mousedown", this.#onWindowMousedown, true);
362
+ window.addEventListener("keydown", this.#onWindowKeydown);
363
+ this.renderRoot.querySelector(".panel")?.focus({ preventScroll: true });
364
+ }
365
+ else {
366
+ this.#teardownPanel();
367
+ }
368
+ }
369
+ #teardownPanel() {
370
+ deactivateLayer(this);
371
+ window.removeEventListener("mousedown", this.#onWindowMousedown, true);
372
+ window.removeEventListener("keydown", this.#onWindowKeydown);
373
+ }
374
+ #onWindowMousedown;
375
+ #onWindowKeydown;
376
+ #toggle() {
377
+ if (this.disabled)
378
+ return;
379
+ if (this.open)
380
+ this.#close();
381
+ else
382
+ this.open = true;
383
+ }
384
+ #close(restoreFocus = true) {
385
+ if (!this.open)
386
+ return;
387
+ this.open = false;
388
+ if (!restoreFocus)
389
+ return;
390
+ this.renderRoot.querySelector("button.trigger")?.focus({ preventScroll: true });
391
+ }
392
+ /** The current expression, falling back to the default when unparseable. */
393
+ #expression() {
394
+ return parseCron(this.value) ?? parseCron(DEFAULT_EXPRESSION);
395
+ }
396
+ #commit(expression) {
397
+ const next = formatCron(expression);
398
+ if (next === this.value)
399
+ return;
400
+ this.#valueIsInternal = true;
401
+ this.value = next;
402
+ this.dispatchEvent(new CustomEvent("change", { detail: { value: next } }));
403
+ }
404
+ #patch(patch) {
405
+ this.#commit({ ...this.#expression(), ...patch });
406
+ }
407
+ /** Single value a field selects, or `fallback` when it selects none or many. */
408
+ #single(name, fallback) {
409
+ const field = this.#expression()[name];
410
+ if (isEveryValue(field))
411
+ return fallback;
412
+ return expandField(field, name)[0] ?? fallback;
413
+ }
414
+ #selected(name) {
415
+ const field = this.#expression()[name];
416
+ return isEveryValue(field) ? [] : expandField(field, name);
417
+ }
418
+ #onFrequencyChange(mode) {
419
+ this._mode = mode;
420
+ if (mode === "advanced")
421
+ return;
422
+ const minute = this.#single("minute", 0);
423
+ const hour = this.#single("hour", 9);
424
+ const every = [{ kind: "all" }];
425
+ const at = (value) => [{ kind: "value", value }];
426
+ if (mode === "minute") {
427
+ const current = this.#expression().minute[0];
428
+ const step = current?.kind === "step" ? current.step : 5;
429
+ this.#commit({
430
+ minute: [{ kind: "step", from: 0, to: null, step }],
431
+ hour: every,
432
+ dayOfMonth: every,
433
+ month: every,
434
+ dayOfWeek: every,
435
+ });
436
+ return;
437
+ }
438
+ if (mode === "hourly") {
439
+ this.#commit({
440
+ minute: at(minute),
441
+ hour: every,
442
+ dayOfMonth: every,
443
+ month: every,
444
+ dayOfWeek: every,
445
+ });
446
+ return;
447
+ }
448
+ const base = { minute: at(minute), hour: at(hour) };
449
+ if (mode === "daily") {
450
+ this.#commit({ ...base, dayOfMonth: every, month: every, dayOfWeek: every });
451
+ return;
452
+ }
453
+ if (mode === "weekly") {
454
+ const days = this.#selected("dayOfWeek");
455
+ this.#commit({
456
+ ...base,
457
+ dayOfMonth: every,
458
+ month: every,
459
+ dayOfWeek: fieldFromValues(days.length > 0 ? days : [1]),
460
+ });
461
+ return;
462
+ }
463
+ const days = this.#selected("dayOfMonth");
464
+ const dayOfMonth = fieldFromValues(days.length > 0 ? days : [1]);
465
+ if (mode === "monthly") {
466
+ this.#commit({ ...base, dayOfMonth, month: every, dayOfWeek: every });
467
+ return;
468
+ }
469
+ const months = this.#selected("month");
470
+ this.#commit({
471
+ ...base,
472
+ dayOfMonth,
473
+ month: fieldFromValues(months.length > 0 ? months : [1]),
474
+ dayOfWeek: every,
475
+ });
476
+ }
477
+ #onTimeChange(name, raw) {
478
+ this.#patch({ [name]: [{ kind: "value", value: Number(raw) }] });
479
+ }
480
+ /** Toggles one value in a checkbox-backed field. */
481
+ #onToggleValue(name, value, checked) {
482
+ const current = this.#selected(name);
483
+ const next = checked ? [...current, value] : current.filter((entry) => entry !== value);
484
+ if (next.length === 0)
485
+ return;
486
+ this.#patch({ [name]: fieldFromValues(next) });
487
+ }
488
+ #onTermChange(name, index, term) {
489
+ const field = [...this.#expression()[name]];
490
+ field[index] = term;
491
+ this.#patch({ [name]: field });
492
+ }
493
+ #onAddTerm(name) {
494
+ const [min] = CRON_FIELD_BOUNDS[name];
495
+ this.#patch({ [name]: [...this.#expression()[name], { kind: "value", value: min }] });
496
+ }
497
+ #onRemoveTerm(name, index) {
498
+ const field = this.#expression()[name].filter((_, entry) => entry !== index);
499
+ this.#patch({ [name]: field.length > 0 ? field : [{ kind: "all" }] });
500
+ }
501
+ #renderSelect(label, options, value, onChange, narrow = false) {
502
+ return html `
503
+ <form-select
504
+ class=${narrow ? "narrow" : ""}
505
+ label=${label}
506
+ .options=${options}
507
+ .value=${String(value)}
508
+ @change=${(e) => onChange(e.detail.value)}
509
+ ></form-select>
510
+ `;
511
+ }
512
+ #renderTime() {
513
+ return html `
514
+ <div class="row">
515
+ <span class="inline-label">At</span>
516
+ ${this.#renderSelect("Hour", numberOptions(0, 23, true), this.#single("hour", 9), (raw) => this.#onTimeChange("hour", raw))}
517
+ <span class="inline-label">:</span>
518
+ ${this.#renderSelect("Minute", numberOptions(0, 59, true), this.#single("minute", 0), (raw) => this.#onTimeChange("minute", raw))}
519
+ </div>
520
+ `;
521
+ }
522
+ #renderCheckboxGrid(name, legend, gridClass, entries) {
523
+ const selected = this.#selected(name);
524
+ // A cron field must match at least one value, so the last remaining box
525
+ // is disabled rather than silently rejecting the click.
526
+ const onlySelected = selected.length === 1 ? selected[0] : null;
527
+ return html `
528
+ <fieldset>
529
+ <legend class="group-label">${legend}</legend>
530
+ <div class="grid ${gridClass}">
531
+ ${entries.map((entry) => html `
532
+ <ui-checkbox
533
+ label=${entry.label}
534
+ data-value=${entry.value}
535
+ .checked=${selected.includes(entry.value)}
536
+ ?disabled=${onlySelected === entry.value}
537
+ @change=${(e) => {
538
+ e.stopPropagation();
539
+ this.#onToggleValue(name, entry.value, e.detail.checked);
540
+ }}
541
+ ></ui-checkbox>
542
+ `)}
543
+ </div>
544
+ </fieldset>
545
+ `;
546
+ }
547
+ #renderMinuteMode() {
548
+ const term = this.#expression().minute[0];
549
+ const step = term?.kind === "step" ? term.step : 1;
550
+ return html `
551
+ <div class="row">
552
+ <span class="inline-label">Every</span>
553
+ ${this.#renderSelect("Minutes", numberOptions(1, 59), step, (raw) => {
554
+ const value = Number(raw);
555
+ this.#patch({
556
+ minute: value === 1 ? [{ kind: "all" }] : [{ kind: "step", from: 0, to: null, step: value }],
557
+ });
558
+ })}
559
+ <span class="inline-label">minutes</span>
560
+ </div>
561
+ `;
562
+ }
563
+ #renderHourlyMode() {
564
+ const hourField = this.#expression().hour[0];
565
+ const step = hourField?.kind === "step" ? hourField.step : 1;
566
+ return html `
567
+ <div class="row">
568
+ <span class="inline-label">Every</span>
569
+ ${this.#renderSelect("Hours", numberOptions(1, 23), step, (raw) => {
570
+ const value = Number(raw);
571
+ this.#patch({
572
+ hour: value === 1 ? [{ kind: "all" }] : [{ kind: "step", from: 0, to: null, step: value }],
573
+ });
574
+ })}
575
+ <span class="inline-label">hours at minute</span>
576
+ ${this.#renderSelect("Minute", numberOptions(0, 59, true), this.#single("minute", 0), (raw) => this.#onTimeChange("minute", raw), true)}
577
+ </div>
578
+ `;
579
+ }
580
+ #renderWeeklyMode() {
581
+ return html `
582
+ ${this.#renderTime()}
583
+ ${this.#renderCheckboxGrid("dayOfWeek", "On days", "weekdays", WEEKDAY_ABBREVIATIONS.map((label, value) => ({ value, label })))}
584
+ `;
585
+ }
586
+ #renderMonthDays() {
587
+ return this.#renderCheckboxGrid("dayOfMonth", "On days of month", "days", Array.from({ length: 31 }, (_, index) => ({ value: index + 1, label: String(index + 1) })));
588
+ }
589
+ #renderMonths() {
590
+ return this.#renderCheckboxGrid("month", "In months", "months", MONTH_ABBREVIATIONS.map((label, index) => ({ value: index + 1, label })));
591
+ }
592
+ #renderTermInputs(name, index, term) {
593
+ const [min, max] = CRON_FIELD_BOUNDS[name];
594
+ const options = fieldOptions(name);
595
+ const change = (next) => this.#onTermChange(name, index, next);
596
+ if (term.kind === "all")
597
+ return nothing;
598
+ if (term.kind === "value") {
599
+ return html `
600
+ <div class="row">
601
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} value`, options, term.value, (raw) => change({ kind: "value", value: Number(raw) }))}
602
+ </div>
603
+ `;
604
+ }
605
+ if (term.kind === "range") {
606
+ return html `
607
+ <div class="row">
608
+ <span class="inline-label">From</span>
609
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} range start`, options, term.from, (raw) => {
610
+ const from = Number(raw);
611
+ change({ kind: "range", from, to: Math.max(from, term.to) });
612
+ })}
613
+ <span class="inline-label">to</span>
614
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} range end`, options, term.to, (raw) => {
615
+ const to = Number(raw);
616
+ change({ kind: "range", from: Math.min(term.from, to), to });
617
+ })}
618
+ </div>
619
+ `;
620
+ }
621
+ const to = term.to ?? max;
622
+ return html `
623
+ <div class="row wrap">
624
+ <span class="inline-label">Every</span>
625
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} step`, numberOptions(1, max - min || 1), term.step, (raw) => change({ ...term, step: Number(raw) }), true)}
626
+ <span class="inline-label">from</span>
627
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} step start`, options, term.from, (raw) => {
628
+ const from = Number(raw);
629
+ change({ ...term, from, to: term.to === null ? null : Math.max(from, term.to) });
630
+ })}
631
+ <span class="inline-label">to</span>
632
+ ${this.#renderSelect(`${CRON_FIELD_LABELS[name]} step end`, options, to, (raw) => {
633
+ const end = Number(raw);
634
+ change({ ...term, from: Math.min(term.from, end), to: end });
635
+ })}
636
+ </div>
637
+ `;
638
+ }
639
+ #renderFieldEditor(name) {
640
+ const field = this.#expression()[name];
641
+ return html `
642
+ <div class="field-editor" role="group" aria-label=${CRON_FIELD_LABELS[name]}>
643
+ <div class="field-header">
644
+ <span class="group-label">${CRON_FIELD_LABELS[name]}</span>
645
+ <ui-button
646
+ size="sm"
647
+ variant="secondary"
648
+ @click=${() => this.#onAddTerm(name)}
649
+ >
650
+ ${iconPlus(14)} Add rule
651
+ </ui-button>
652
+ </div>
653
+ ${field.map((term, index) => html `
654
+ <div class="term-row">
655
+ <div class="row">
656
+ <button-group
657
+ size="sm"
658
+ .options=${TERM_KIND_OPTIONS}
659
+ .value=${term.kind}
660
+ @change=${(e) => {
661
+ e.stopPropagation();
662
+ this.#onTermChange(name, index, this.#defaultTerm(name, e.detail.value));
663
+ }}
664
+ ></button-group>
665
+ <icon-button
666
+ label=${`Remove ${CRON_FIELD_LABELS[name].toLowerCase()} rule ${index + 1}`}
667
+ .icon=${iconTrash(18)}
668
+ @click=${() => this.#onRemoveTerm(name, index)}
669
+ ></icon-button>
670
+ </div>
671
+ ${this.#renderTermInputs(name, index, term)}
672
+ </div>
673
+ `)}
674
+ </div>
675
+ `;
676
+ }
677
+ #defaultTerm(name, kind) {
678
+ const [min, max] = CRON_FIELD_BOUNDS[name];
679
+ if (kind === "value")
680
+ return { kind: "value", value: min };
681
+ if (kind === "range")
682
+ return { kind: "range", from: min, to: max };
683
+ if (kind === "step")
684
+ return { kind: "step", from: min, to: null, step: 2 };
685
+ return { kind: "all" };
686
+ }
687
+ #renderModeBody() {
688
+ if (this._mode === "minute")
689
+ return this.#renderMinuteMode();
690
+ if (this._mode === "hourly")
691
+ return this.#renderHourlyMode();
692
+ if (this._mode === "daily")
693
+ return this.#renderTime();
694
+ if (this._mode === "weekly")
695
+ return this.#renderWeeklyMode();
696
+ if (this._mode === "monthly")
697
+ return html `${this.#renderTime()}${this.#renderMonthDays()}`;
698
+ if (this._mode === "yearly") {
699
+ return html `${this.#renderTime()}${this.#renderMonthDays()}${this.#renderMonths()}`;
700
+ }
701
+ return html `${CRON_FIELD_NAMES.map((name) => this.#renderFieldEditor(name))}`;
702
+ }
703
+ #renderPanel() {
704
+ return html `
705
+ <div
706
+ id=${this.#panelId}
707
+ class="panel"
708
+ role="dialog"
709
+ aria-label=${this.label ? `${this.label} schedule` : "Repeat schedule"}
710
+ tabindex="-1"
711
+ >
712
+ <div class="row">
713
+ <span class="inline-label">Repeat</span>
714
+ <form-select
715
+ label="Repeat"
716
+ .options=${FREQUENCY_OPTIONS}
717
+ .value=${this._mode}
718
+ @change=${(e) => this.#onFrequencyChange(e.detail.value)}
719
+ ></form-select>
720
+ </div>
721
+ ${this.#renderModeBody()}
722
+ <div class="readout">
723
+ <code>${this.value}</code>
724
+ <span class="description">${this.description}</span>
725
+ </div>
726
+ </div>
727
+ `;
728
+ }
729
+ render() {
730
+ return html `
731
+ <button
732
+ type="button"
733
+ class="trigger"
734
+ aria-haspopup="dialog"
735
+ aria-expanded=${this.open}
736
+ aria-controls=${this.#panelId}
737
+ aria-label=${this.label || nothing}
738
+ ?disabled=${this.disabled}
739
+ @click=${() => this.#toggle()}
740
+ >
741
+ <span class="trigger-icon" aria-hidden="true">${iconClock(14)}</span>
742
+ <span class="trigger-label">${this.description}</span>
743
+ <span class="chevron" aria-hidden="true">${iconChevronRight(14)}</span>
744
+ </button>
745
+ ${this.open ? this.#renderPanel() : nothing}
746
+ `;
747
+ }
748
+ };
749
+ __decorate([
750
+ property()
751
+ ], CronSchedule.prototype, "value", void 0);
752
+ __decorate([
753
+ property()
754
+ ], CronSchedule.prototype, "label", void 0);
755
+ __decorate([
756
+ property({ type: Boolean })
757
+ ], CronSchedule.prototype, "disabled", void 0);
758
+ __decorate([
759
+ property({ type: Boolean, reflect: true })
760
+ ], CronSchedule.prototype, "open", void 0);
761
+ __decorate([
762
+ state()
763
+ ], CronSchedule.prototype, "_mode", void 0);
764
+ CronSchedule = __decorate([
765
+ customElement("cron-schedule")
766
+ ], CronSchedule);
767
+ export { CronSchedule };
768
+ //# sourceMappingURL=cron-schedule.js.map