nish-ui 2.1.2 → 2.2.0
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 +1 -1
- package/dist/base-tailwind.css +3 -1
- package/dist/base.css +3 -1
- package/dist/chart.js +1 -1
- package/dist/elements-all.js +1 -1
- package/dist/elements-charts.js +1 -1
- package/dist/elements-data.js +1 -1
- package/dist/elements-forms.js +1 -1
- package/dist/elements.js +3 -3
- package/dist/esm/components/calendar-base.js +291 -0
- package/dist/esm/components/calendar-classes.js +78 -0
- package/dist/esm/components/calendar.js +22 -254
- package/dist/esm/components/date-range-picker.js +213 -0
- package/dist/esm/components/forms.js +1 -0
- package/dist/esm/components/layout.js +8 -1
- package/dist/esm/components/range-calendar.js +122 -0
- package/dist/esm/components/strings.js +9 -0
- package/dist/esm/components/time-field-classes.js +110 -0
- package/dist/esm/components/time-field.js +308 -0
- package/dist/esm/components/tree-view.js +40 -46
- package/dist/esm/index.js +6 -0
- package/dist/esm/runtime.js +1 -1
- package/dist/format.js +1 -1
- package/dist/index.d.ts +161 -10
- package/dist/nish.css +3 -1
- package/dist/theme.d.ts +18 -0
- package/dist/theme.global.js +10 -1
- package/dist/theme.js +10 -1
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/range-calendar.tsx
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { getDefaultLocale } from "../format.js";
|
|
6
|
+
import {
|
|
7
|
+
firstDisabledIn,
|
|
8
|
+
fullDate,
|
|
9
|
+
inRange,
|
|
10
|
+
monthOf,
|
|
11
|
+
orderRange,
|
|
12
|
+
parseIso,
|
|
13
|
+
resolveLocale,
|
|
14
|
+
toRange
|
|
15
|
+
} from "./calendar-classes.js";
|
|
16
|
+
import { CalendarBase } from "./calendar-base.js";
|
|
17
|
+
import { useNishConfig, useNishStrings } from "./provider.js";
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
|
+
var warned = /* @__PURE__ */ new Set();
|
|
20
|
+
var OUTSIDE = { filled: false, band: null, ariaSelected: false };
|
|
21
|
+
function warnOnce(key, message) {
|
|
22
|
+
if (process.env.NODE_ENV === "production" || warned.has(key)) return;
|
|
23
|
+
warned.add(key);
|
|
24
|
+
console.warn(message);
|
|
25
|
+
}
|
|
26
|
+
function checkRange(prop, v) {
|
|
27
|
+
if (v == null) return null;
|
|
28
|
+
const r = toRange(v);
|
|
29
|
+
if (!r) {
|
|
30
|
+
warnOnce(`${prop}:shape`, `RangeCalendar: "${prop}" must be { from, to } with YYYY-MM-DD days`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (v.from > v.to) warnOnce(`${prop}:order`, `RangeCalendar: "${prop}" has from after to; the days were swapped`);
|
|
34
|
+
return r;
|
|
35
|
+
}
|
|
36
|
+
function RangeCalendar({
|
|
37
|
+
value,
|
|
38
|
+
defaultValue,
|
|
39
|
+
onValueChange,
|
|
40
|
+
allowDisabledInRange = false,
|
|
41
|
+
...shared
|
|
42
|
+
}) {
|
|
43
|
+
const strings = useNishStrings();
|
|
44
|
+
const config = useNishConfig();
|
|
45
|
+
const loc = resolveLocale(shared.locale ?? config.locale ?? getDefaultLocale());
|
|
46
|
+
const { min: minProp, max: maxProp, isDateDisabled } = shared;
|
|
47
|
+
const min = minProp != null && parseIso(minProp) ? minProp : null;
|
|
48
|
+
const max = maxProp != null && parseIso(maxProp) ? maxProp : null;
|
|
49
|
+
const controlled = value !== void 0;
|
|
50
|
+
const [own, setOwn] = useState(() => checkRange("defaultValue", defaultValue));
|
|
51
|
+
const [anchor, setAnchor] = useState(null);
|
|
52
|
+
const [hover, setHover] = useState(null);
|
|
53
|
+
const [focusDay, setFocusDay] = useState(null);
|
|
54
|
+
const [status, setStatus] = useState("");
|
|
55
|
+
const range = controlled ? checkRange("value", value) : own;
|
|
56
|
+
const off = (iso) => !inRange(iso, min, max) || isDateDisabled?.(iso) === true;
|
|
57
|
+
const blocks = (r) => !allowDisabledInRange && !!isDateDisabled && firstDisabledIn(r.from, r.to, isDateDisabled) !== null;
|
|
58
|
+
let band = range;
|
|
59
|
+
if (anchor) {
|
|
60
|
+
const target = hover ?? focusDay ?? anchor;
|
|
61
|
+
const r = orderRange(anchor, target);
|
|
62
|
+
band = off(target) || blocks(r) ? { from: anchor, to: anchor } : r;
|
|
63
|
+
}
|
|
64
|
+
const dayLook = (iso) => {
|
|
65
|
+
if (!band || iso < band.from || iso > band.to) return OUTSIDE;
|
|
66
|
+
const single = band.from === band.to;
|
|
67
|
+
return {
|
|
68
|
+
filled: anchor ? iso === anchor : iso === band.from || iso === band.to,
|
|
69
|
+
band: single ? null : iso === band.from ? "start" : iso === band.to ? "end" : "middle",
|
|
70
|
+
ariaSelected: anchor ? iso === anchor : true,
|
|
71
|
+
preview: !!anchor && iso !== anchor
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const start = (iso) => {
|
|
75
|
+
setAnchor(iso);
|
|
76
|
+
setStatus(strings.rangeStarted(fullDate(iso, loc)));
|
|
77
|
+
};
|
|
78
|
+
const onPick = (iso) => {
|
|
79
|
+
if (!anchor) {
|
|
80
|
+
start(iso);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const r = orderRange(anchor, iso);
|
|
84
|
+
if (blocks(r)) {
|
|
85
|
+
start(iso);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
setAnchor(null);
|
|
89
|
+
setHover(null);
|
|
90
|
+
if (!controlled) setOwn(r);
|
|
91
|
+
setStatus(strings.dateRange(fullDate(r.from, loc), fullDate(r.to, loc)));
|
|
92
|
+
onValueChange?.(r);
|
|
93
|
+
};
|
|
94
|
+
const onGridKeyDown = (e) => {
|
|
95
|
+
if (e.key === "Escape" && anchor !== null) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
setAnchor(null);
|
|
99
|
+
setHover(null);
|
|
100
|
+
setStatus("");
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return /* @__PURE__ */ jsx(
|
|
104
|
+
CalendarBase,
|
|
105
|
+
{
|
|
106
|
+
...shared,
|
|
107
|
+
componentName: "RangeCalendar",
|
|
108
|
+
initialMonth: range ? monthOf(range.from) : null,
|
|
109
|
+
focusPreference: anchor ?? range?.from ?? null,
|
|
110
|
+
dayLook,
|
|
111
|
+
onPick,
|
|
112
|
+
onDayFocus: setFocusDay,
|
|
113
|
+
onDayHover: setHover,
|
|
114
|
+
onGridKeyDown,
|
|
115
|
+
multiselectable: true,
|
|
116
|
+
children: /* @__PURE__ */ jsx("p", { "aria-live": "polite", className: "sr-only", children: status })
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
RangeCalendar
|
|
122
|
+
};
|
|
@@ -33,6 +33,15 @@ var DEFAULT_STRINGS = {
|
|
|
33
33
|
dayToken: "DD",
|
|
34
34
|
monthToken: "MM",
|
|
35
35
|
yearToken: "YYYY",
|
|
36
|
+
chooseDates: "Choose dates",
|
|
37
|
+
changeDates: (range) => `Change dates, ${range}`,
|
|
38
|
+
dateRange: (from, to) => `${from} to ${to}`,
|
|
39
|
+
rangeStarted: (start) => `Start date ${start}. Pick the end date.`,
|
|
40
|
+
invalidDateRange: "Enter a valid date range.",
|
|
41
|
+
hour: "Hour",
|
|
42
|
+
minute: "Minute",
|
|
43
|
+
dayPeriod: "AM/PM",
|
|
44
|
+
invalidTime: "Enter a valid time.",
|
|
36
45
|
optionAdded: (l) => `Added ${l}`,
|
|
37
46
|
optionRemoved: (l) => `Removed ${l}`,
|
|
38
47
|
clearAll: "Clear all",
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// src/components/time-field-classes.ts
|
|
2
|
+
var TIME_RE = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
3
|
+
var DIGITS_RE = /^\d{1,2}$/;
|
|
4
|
+
var pad2 = (n) => String(n).padStart(2, "0");
|
|
5
|
+
function parseTime(s) {
|
|
6
|
+
if (typeof s !== "string") return null;
|
|
7
|
+
const x = TIME_RE.exec(s);
|
|
8
|
+
return x ? { h: Number(x[1]), m: Number(x[2]) } : null;
|
|
9
|
+
}
|
|
10
|
+
function toTime(h, m) {
|
|
11
|
+
return `${pad2(h)}:${pad2(m)}`;
|
|
12
|
+
}
|
|
13
|
+
function inTimeRange(t, min, max) {
|
|
14
|
+
if (parseTime(min) && t < min) return false;
|
|
15
|
+
if (parseTime(max) && t > max) return false;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
var cycles = /* @__PURE__ */ new Map();
|
|
19
|
+
function hourCycleFor(locale) {
|
|
20
|
+
const hit = cycles.get(locale);
|
|
21
|
+
if (hit) return hit;
|
|
22
|
+
let c = 24;
|
|
23
|
+
try {
|
|
24
|
+
const o = new Intl.DateTimeFormat(locale, { hour: "numeric", timeZone: "UTC" }).resolvedOptions();
|
|
25
|
+
const twelve = o.hourCycle ? o.hourCycle === "h11" || o.hourCycle === "h12" : o.hour12 === true;
|
|
26
|
+
c = twelve ? 12 : 24;
|
|
27
|
+
} catch {
|
|
28
|
+
c = 24;
|
|
29
|
+
}
|
|
30
|
+
cycles.set(locale, c);
|
|
31
|
+
return c;
|
|
32
|
+
}
|
|
33
|
+
var periods = /* @__PURE__ */ new Map();
|
|
34
|
+
function dayPeriodNames(locale) {
|
|
35
|
+
const hit = periods.get(locale);
|
|
36
|
+
if (hit) return hit;
|
|
37
|
+
let r = ["AM", "PM"];
|
|
38
|
+
try {
|
|
39
|
+
const f = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true, timeZone: "UTC" });
|
|
40
|
+
const word = (h) => f.formatToParts(new Date(Date.UTC(2026, 0, 1, h))).find((p) => p.type === "dayPeriod")?.value;
|
|
41
|
+
r = [word(1) || "AM", word(13) || "PM"];
|
|
42
|
+
} catch {
|
|
43
|
+
r = ["AM", "PM"];
|
|
44
|
+
}
|
|
45
|
+
periods.set(locale, r);
|
|
46
|
+
return r;
|
|
47
|
+
}
|
|
48
|
+
function to12(h) {
|
|
49
|
+
return { hour: h % 12 === 0 ? 12 : h % 12, pm: h >= 12 };
|
|
50
|
+
}
|
|
51
|
+
function from12(hour, pm) {
|
|
52
|
+
return hour % 12 + (pm ? 12 : 0);
|
|
53
|
+
}
|
|
54
|
+
function normalizeStep(step) {
|
|
55
|
+
return Number.isFinite(step) ? Math.min(60, Math.max(1, Math.floor(step))) : 1;
|
|
56
|
+
}
|
|
57
|
+
function lastMinute(step) {
|
|
58
|
+
return Math.floor(59 / step) * step;
|
|
59
|
+
}
|
|
60
|
+
function stepHour(h, dir) {
|
|
61
|
+
return h === null ? dir > 0 ? 0 : 23 : (h + dir + 24) % 24;
|
|
62
|
+
}
|
|
63
|
+
function stepMinute(m, dir, step) {
|
|
64
|
+
if (m === null) return dir > 0 ? 0 : lastMinute(step);
|
|
65
|
+
if (dir > 0) {
|
|
66
|
+
const n2 = (Math.floor(m / step) + 1) * step;
|
|
67
|
+
return n2 > 59 ? 0 : n2;
|
|
68
|
+
}
|
|
69
|
+
const n = Math.ceil(m / step) * step - step;
|
|
70
|
+
return n < 0 ? lastMinute(step) : n;
|
|
71
|
+
}
|
|
72
|
+
function hourText(h, cycle) {
|
|
73
|
+
return cycle === 24 ? pad2(h) : String(to12(h).hour);
|
|
74
|
+
}
|
|
75
|
+
function draftFromTime(t, cycle) {
|
|
76
|
+
const p = parseTime(t);
|
|
77
|
+
if (!p) return { h: "", m: "", pm: false };
|
|
78
|
+
return { h: hourText(p.h, cycle), m: pad2(p.m), pm: p.h >= 12 };
|
|
79
|
+
}
|
|
80
|
+
function draftTime(d, cycle) {
|
|
81
|
+
if (d.h === "" && d.m === "") return null;
|
|
82
|
+
if (d.h === "" || d.m === "") return void 0;
|
|
83
|
+
if (!DIGITS_RE.test(d.h) || !DIGITS_RE.test(d.m)) return void 0;
|
|
84
|
+
const hn = Number(d.h);
|
|
85
|
+
const mn = Number(d.m);
|
|
86
|
+
if (cycle === 24 ? hn > 23 : hn < 1 || hn > 12) return void 0;
|
|
87
|
+
if (mn > 59) return void 0;
|
|
88
|
+
return toTime(cycle === 12 ? from12(hn, d.pm) : hn, mn);
|
|
89
|
+
}
|
|
90
|
+
function hourAdvances(text, cycle) {
|
|
91
|
+
const max = cycle === 24 ? 23 : 12;
|
|
92
|
+
return text.length >= 2 || text.length === 1 && Number(text) * 10 > max;
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
dayPeriodNames,
|
|
96
|
+
draftFromTime,
|
|
97
|
+
draftTime,
|
|
98
|
+
from12,
|
|
99
|
+
hourAdvances,
|
|
100
|
+
hourCycleFor,
|
|
101
|
+
hourText,
|
|
102
|
+
inTimeRange,
|
|
103
|
+
lastMinute,
|
|
104
|
+
normalizeStep,
|
|
105
|
+
parseTime,
|
|
106
|
+
stepHour,
|
|
107
|
+
stepMinute,
|
|
108
|
+
to12,
|
|
109
|
+
toTime
|
|
110
|
+
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/time-field.tsx
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { getDefaultLocale } from "../format.js";
|
|
7
|
+
import { resolveLocale } from "./calendar-classes.js";
|
|
8
|
+
import { useIsoLayoutEffect } from "./client.js";
|
|
9
|
+
import { setRef } from "./forms-classes.js";
|
|
10
|
+
import { fieldClass } from "./primitives-classes.js";
|
|
11
|
+
import { Select } from "./primitives.js";
|
|
12
|
+
import { useNishConfig, useNishStrings } from "./provider.js";
|
|
13
|
+
import {
|
|
14
|
+
dayPeriodNames,
|
|
15
|
+
draftFromTime,
|
|
16
|
+
draftTime,
|
|
17
|
+
from12,
|
|
18
|
+
hourAdvances,
|
|
19
|
+
hourCycleFor,
|
|
20
|
+
hourText,
|
|
21
|
+
inTimeRange,
|
|
22
|
+
lastMinute,
|
|
23
|
+
normalizeStep,
|
|
24
|
+
parseTime,
|
|
25
|
+
stepHour,
|
|
26
|
+
stepMinute
|
|
27
|
+
} from "./time-field-classes.js";
|
|
28
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
var pad2 = (n) => String(n).padStart(2, "0");
|
|
30
|
+
var warned = /* @__PURE__ */ new Set();
|
|
31
|
+
function warnOnce(message) {
|
|
32
|
+
if (process.env.NODE_ENV === "production" || warned.has(message)) return;
|
|
33
|
+
warned.add(message);
|
|
34
|
+
console.warn(message);
|
|
35
|
+
}
|
|
36
|
+
function boxNumber(text, lo, hi) {
|
|
37
|
+
if (!/^\d{1,2}$/.test(text)) return null;
|
|
38
|
+
const n = Number(text);
|
|
39
|
+
return n >= lo && n <= hi ? n : null;
|
|
40
|
+
}
|
|
41
|
+
function TimeField({
|
|
42
|
+
ref,
|
|
43
|
+
value: valueProp,
|
|
44
|
+
defaultValue = null,
|
|
45
|
+
onValueChange,
|
|
46
|
+
min,
|
|
47
|
+
max,
|
|
48
|
+
step,
|
|
49
|
+
hourCycle,
|
|
50
|
+
locale,
|
|
51
|
+
"aria-label": ariaLabel,
|
|
52
|
+
"aria-labelledby": ariaLabelledBy,
|
|
53
|
+
"aria-describedby": ariaDescribedBy,
|
|
54
|
+
"aria-invalid": ariaInvalid,
|
|
55
|
+
invalid,
|
|
56
|
+
id,
|
|
57
|
+
name,
|
|
58
|
+
form,
|
|
59
|
+
required,
|
|
60
|
+
disabled = false,
|
|
61
|
+
size = "md",
|
|
62
|
+
className,
|
|
63
|
+
...rest
|
|
64
|
+
}) {
|
|
65
|
+
const strings = useNishStrings();
|
|
66
|
+
const config = useNishConfig();
|
|
67
|
+
const loc = resolveLocale(locale ?? config.locale ?? getDefaultLocale());
|
|
68
|
+
const cycle = hourCycle ?? hourCycleFor(loc);
|
|
69
|
+
const st = normalizeStep(step);
|
|
70
|
+
const [am, pm] = dayPeriodNames(loc);
|
|
71
|
+
const minT = parseTime(min) ? min : null;
|
|
72
|
+
const maxT = parseTime(max) ? max : null;
|
|
73
|
+
const auto = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
74
|
+
const inputId = id ?? `nish-tf-${auto}`;
|
|
75
|
+
const nameId = `nish-tf-${auto}-name`;
|
|
76
|
+
const hId = `nish-tf-${auto}-h`;
|
|
77
|
+
const mId = `nish-tf-${auto}-m`;
|
|
78
|
+
const pId = `nish-tf-${auto}-p`;
|
|
79
|
+
const derived = ariaLabelledBy == null && ariaLabel == null && id != null;
|
|
80
|
+
const [labelId, setLabelId] = useState(id != null ? `${id}-label` : null);
|
|
81
|
+
useIsoLayoutEffect(() => {
|
|
82
|
+
if (!derived) return;
|
|
83
|
+
if (document.getElementById(`${id}-label`)) {
|
|
84
|
+
setLabelId(`${id}-label`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const nativeLabel = document.getElementById(id)?.labels?.[0];
|
|
88
|
+
const native = nativeLabel?.id || null;
|
|
89
|
+
setLabelId(native);
|
|
90
|
+
if (!native) {
|
|
91
|
+
warnOnce(
|
|
92
|
+
nativeLabel ? "TimeField: give its <label> an id, or use a Field, an aria-label or aria-labelledby." : "TimeField: give it a Field, an aria-label or aria-labelledby."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}, [derived, id]);
|
|
96
|
+
const src = ariaLabelledBy ?? (ariaLabel != null ? nameId : derived ? labelId ?? void 0 : void 0);
|
|
97
|
+
const names = (own2) => [src, own2].filter(Boolean).join(" ");
|
|
98
|
+
if (ariaLabel == null && ariaLabelledBy == null && id == null) {
|
|
99
|
+
warnOnce("TimeField: give it a Field, an aria-label or aria-labelledby.");
|
|
100
|
+
}
|
|
101
|
+
const controlled = valueProp !== void 0;
|
|
102
|
+
const okProp = (prop, v) => {
|
|
103
|
+
if (v == null) return null;
|
|
104
|
+
if (parseTime(v)) return v;
|
|
105
|
+
warnOnce(`TimeField: "${prop}" must be HH:mm`);
|
|
106
|
+
return null;
|
|
107
|
+
};
|
|
108
|
+
const [own, setOwn] = useState(() => okProp("defaultValue", defaultValue));
|
|
109
|
+
const value = controlled ? okProp("value", valueProp) : own;
|
|
110
|
+
const [draftState, setDraft] = useState(null);
|
|
111
|
+
const [bad, setBad] = useState(false);
|
|
112
|
+
if (draftState !== null && draftState.base !== value) {
|
|
113
|
+
setDraft(null);
|
|
114
|
+
setBad(false);
|
|
115
|
+
}
|
|
116
|
+
const draft = draftState !== null && draftState.base === value ? draftState.d : null;
|
|
117
|
+
const hourRef = useRef(null);
|
|
118
|
+
const minuteRef = useRef(null);
|
|
119
|
+
const shown = draft ?? draftFromTime(value, cycle);
|
|
120
|
+
const draftBad = () => {
|
|
121
|
+
if (draft === null) return false;
|
|
122
|
+
const t = draftTime(draft, cycle);
|
|
123
|
+
return t === void 0 || t !== null && !inTimeRange(t, minT, maxT);
|
|
124
|
+
};
|
|
125
|
+
const outside = value !== null && !inTimeRange(value, minT, maxT);
|
|
126
|
+
const isInvalid = invalid === true || ariaInvalid === true || ariaInvalid === "true" || bad || outside;
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
hourRef.current?.setCustomValidity(bad || outside ? strings.invalidTime : "");
|
|
129
|
+
}, [bad, outside, strings.invalidTime]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const f = hourRef.current?.form;
|
|
132
|
+
if (!f || controlled) return;
|
|
133
|
+
const onReset = () => {
|
|
134
|
+
setOwn(okProp("defaultValue", defaultValue));
|
|
135
|
+
setDraft(null);
|
|
136
|
+
setBad(false);
|
|
137
|
+
};
|
|
138
|
+
f.addEventListener("reset", onReset);
|
|
139
|
+
return () => f.removeEventListener("reset", onReset);
|
|
140
|
+
}, [name, form, controlled, defaultValue]);
|
|
141
|
+
const commit = (v) => {
|
|
142
|
+
if (!controlled) setOwn(v);
|
|
143
|
+
onValueChange?.(v);
|
|
144
|
+
};
|
|
145
|
+
const update = (next) => {
|
|
146
|
+
const t = draftTime(next, cycle);
|
|
147
|
+
if (t === null) {
|
|
148
|
+
if (value !== null) commit(null);
|
|
149
|
+
setDraft({ d: next, base: null });
|
|
150
|
+
setBad(false);
|
|
151
|
+
} else if (typeof t === "string" && inTimeRange(t, minT, maxT)) {
|
|
152
|
+
if (t !== value) commit(t);
|
|
153
|
+
setDraft({ d: next, base: t });
|
|
154
|
+
setBad(false);
|
|
155
|
+
} else {
|
|
156
|
+
setDraft({ d: next, base: value });
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const focusMinute = () => {
|
|
160
|
+
minuteRef.current?.focus();
|
|
161
|
+
minuteRef.current?.select();
|
|
162
|
+
};
|
|
163
|
+
const onKey = (which) => (e) => {
|
|
164
|
+
if (disabled) return;
|
|
165
|
+
const key = e.key;
|
|
166
|
+
if (key === "Enter") {
|
|
167
|
+
if (draftBad()) {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
setBad(true);
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (key === "ArrowUp" || key === "ArrowDown") {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
const dir = key === "ArrowUp" ? 1 : -1;
|
|
176
|
+
if (which === "h") {
|
|
177
|
+
const hn = boxNumber(shown.h, cycle === 12 ? 1 : 0, cycle === 12 ? 12 : 23);
|
|
178
|
+
const cur = hn === null ? null : cycle === 12 ? from12(hn, shown.pm) : hn;
|
|
179
|
+
const next = stepHour(cur, dir);
|
|
180
|
+
update({ ...shown, h: hourText(next, cycle), pm: next >= 12 });
|
|
181
|
+
} else {
|
|
182
|
+
const cur = boxNumber(shown.m, 0, 59);
|
|
183
|
+
update({ ...shown, m: pad2(stepMinute(cur, dir, st)) });
|
|
184
|
+
}
|
|
185
|
+
} else if (key === "Home") {
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
update(which === "h" ? { ...shown, h: hourText(0, cycle), pm: false } : { ...shown, m: "00" });
|
|
188
|
+
} else if (key === "End") {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
update(which === "h" ? { ...shown, h: hourText(23, cycle), pm: true } : { ...shown, m: pad2(lastMinute(st)) });
|
|
191
|
+
} else if (cycle === 12 && (key === "a" || key === "A" || key === "p" || key === "P")) {
|
|
192
|
+
e.preventDefault();
|
|
193
|
+
update({ ...shown, pm: key === "p" || key === "P" });
|
|
194
|
+
} else if (which === "h" && (key === ":" || key === ".")) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
focusMinute();
|
|
197
|
+
} else if (which === "m" && key === "Backspace" && shown.m === "") {
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
hourRef.current?.focus();
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const hourNow = boxNumber(shown.h, cycle === 12 ? 1 : 0, cycle === 12 ? 12 : 23);
|
|
203
|
+
const minuteNow = boxNumber(shown.m, 0, 59);
|
|
204
|
+
const boxClass = fieldClass({
|
|
205
|
+
size,
|
|
206
|
+
invalid: isInvalid,
|
|
207
|
+
className: "w-12 ps-0 pe-0 text-center tabular-nums pointer-coarse:w-14"
|
|
208
|
+
});
|
|
209
|
+
const common = {
|
|
210
|
+
type: "text",
|
|
211
|
+
inputMode: "numeric",
|
|
212
|
+
autoComplete: "off",
|
|
213
|
+
spellCheck: false,
|
|
214
|
+
maxLength: 2,
|
|
215
|
+
role: "spinbutton",
|
|
216
|
+
placeholder: "--",
|
|
217
|
+
disabled,
|
|
218
|
+
required,
|
|
219
|
+
// The boxes have no name, so nothing extra posts; this puts them (and their validity) in the same form.
|
|
220
|
+
form,
|
|
221
|
+
"aria-required": required || void 0,
|
|
222
|
+
"aria-describedby": ariaDescribedBy,
|
|
223
|
+
"aria-invalid": isInvalid || void 0,
|
|
224
|
+
className: boxClass,
|
|
225
|
+
onFocus: (e) => e.currentTarget.select()
|
|
226
|
+
};
|
|
227
|
+
return /* @__PURE__ */ jsxs(
|
|
228
|
+
"div",
|
|
229
|
+
{
|
|
230
|
+
...rest,
|
|
231
|
+
role: "group",
|
|
232
|
+
"aria-labelledby": src,
|
|
233
|
+
"data-disabled": disabled ? "" : void 0,
|
|
234
|
+
className: cn("inline-flex items-center gap-2", className),
|
|
235
|
+
onBlur: (e) => {
|
|
236
|
+
rest.onBlur?.(e);
|
|
237
|
+
if (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)) return;
|
|
238
|
+
const isBad = draftBad();
|
|
239
|
+
setBad(isBad);
|
|
240
|
+
if (!isBad) setDraft(null);
|
|
241
|
+
},
|
|
242
|
+
children: [
|
|
243
|
+
ariaLabel != null ? /* @__PURE__ */ jsx("span", { id: nameId, hidden: true, children: ariaLabel }) : null,
|
|
244
|
+
/* @__PURE__ */ jsx("span", { id: hId, hidden: true, children: strings.hour }),
|
|
245
|
+
/* @__PURE__ */ jsx("span", { id: mId, hidden: true, children: strings.minute }),
|
|
246
|
+
cycle === 12 ? /* @__PURE__ */ jsx("span", { id: pId, hidden: true, children: strings.dayPeriod }) : null,
|
|
247
|
+
/* @__PURE__ */ jsxs("span", { dir: "ltr", className: "inline-flex items-center gap-1", children: [
|
|
248
|
+
/* @__PURE__ */ jsx(
|
|
249
|
+
"input",
|
|
250
|
+
{
|
|
251
|
+
...common,
|
|
252
|
+
ref: (node) => {
|
|
253
|
+
hourRef.current = node;
|
|
254
|
+
setRef(ref, node);
|
|
255
|
+
},
|
|
256
|
+
id: inputId,
|
|
257
|
+
value: shown.h,
|
|
258
|
+
"aria-labelledby": names(hId),
|
|
259
|
+
"aria-valuemin": cycle === 12 ? 1 : 0,
|
|
260
|
+
"aria-valuemax": cycle === 12 ? 12 : 23,
|
|
261
|
+
"aria-valuenow": hourNow ?? void 0,
|
|
262
|
+
onChange: (e) => {
|
|
263
|
+
const d = e.target.value.replace(/\D/g, "").slice(0, 2);
|
|
264
|
+
update({ ...shown, h: d });
|
|
265
|
+
if (hourAdvances(d, cycle)) focusMinute();
|
|
266
|
+
},
|
|
267
|
+
onKeyDown: (e) => onKey("h")(e)
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-th-hi3", children: ":" }),
|
|
271
|
+
/* @__PURE__ */ jsx(
|
|
272
|
+
"input",
|
|
273
|
+
{
|
|
274
|
+
...common,
|
|
275
|
+
ref: minuteRef,
|
|
276
|
+
value: shown.m,
|
|
277
|
+
"aria-labelledby": names(mId),
|
|
278
|
+
"aria-valuemin": 0,
|
|
279
|
+
"aria-valuemax": 59,
|
|
280
|
+
"aria-valuenow": minuteNow ?? void 0,
|
|
281
|
+
onChange: (e) => update({ ...shown, m: e.target.value.replace(/\D/g, "").slice(0, 2) }),
|
|
282
|
+
onKeyDown: (e) => onKey("m")(e)
|
|
283
|
+
}
|
|
284
|
+
)
|
|
285
|
+
] }),
|
|
286
|
+
cycle === 12 ? /* @__PURE__ */ jsxs(
|
|
287
|
+
Select,
|
|
288
|
+
{
|
|
289
|
+
value: shown.pm ? "pm" : "am",
|
|
290
|
+
onChange: (e) => update({ ...shown, pm: e.target.value === "pm" }),
|
|
291
|
+
size,
|
|
292
|
+
disabled,
|
|
293
|
+
"aria-labelledby": names(pId),
|
|
294
|
+
className: "w-auto shrink-0",
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ jsx("option", { value: "am", children: am }),
|
|
297
|
+
/* @__PURE__ */ jsx("option", { value: "pm", children: pm })
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
) : null,
|
|
301
|
+
name != null ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value ?? "", form, disabled }) : null
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
export {
|
|
307
|
+
TimeField
|
|
308
|
+
};
|
|
@@ -46,11 +46,10 @@ var TreeItem = memo(function TreeItem2({
|
|
|
46
46
|
labelId,
|
|
47
47
|
itemRef,
|
|
48
48
|
onRowClick,
|
|
49
|
-
onToggle
|
|
50
|
-
children
|
|
49
|
+
onToggle
|
|
51
50
|
}) {
|
|
52
51
|
const parent = hasChildren(node);
|
|
53
|
-
return /* @__PURE__ */
|
|
52
|
+
return /* @__PURE__ */ jsx(
|
|
54
53
|
"li",
|
|
55
54
|
{
|
|
56
55
|
ref: itemRef,
|
|
@@ -67,35 +66,32 @@ var TreeItem = memo(function TreeItem2({
|
|
|
67
66
|
"data-disabled": node.disabled ? "" : void 0,
|
|
68
67
|
tabIndex: isTarget ? 0 : -1,
|
|
69
68
|
className: "outline-none [&:focus-visible>div]:outline-2 [&:focus-visible>div]:-outline-offset-2 [&:focus-visible>div]:outline-th-accent",
|
|
70
|
-
children:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
),
|
|
97
|
-
open ? /* @__PURE__ */ jsx("ul", { role: "group", className: "grid gap-px", children }) : null
|
|
98
|
-
]
|
|
69
|
+
children: /* @__PURE__ */ jsxs(
|
|
70
|
+
"div",
|
|
71
|
+
{
|
|
72
|
+
className: treeRowClass({ selected: selectable && selected, disabled: node.disabled }),
|
|
73
|
+
style: { paddingInlineStart: `calc(${level - 1} * 1.25rem + 0.25rem)` },
|
|
74
|
+
onClick: () => onRowClick(node),
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsx(
|
|
77
|
+
"span",
|
|
78
|
+
{
|
|
79
|
+
"aria-hidden": "true",
|
|
80
|
+
"data-tree-toggle": "",
|
|
81
|
+
onClick: parent ? (e) => {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
onToggle(node);
|
|
84
|
+
} : void 0,
|
|
85
|
+
className: "inline-flex w-6 shrink-0 self-stretch items-center justify-center text-th-hi3 pointer-coarse:w-11",
|
|
86
|
+
children: parent ? /* @__PURE__ */ jsx(Chevron, { open }) : null
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
node.icon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0 text-th-hi3", children: node.icon }) : null,
|
|
90
|
+
/* @__PURE__ */ jsx("span", { id: labelId, className: "min-w-0 flex-1 truncate", children: node.label }),
|
|
91
|
+
node.trailing != null ? /* @__PURE__ */ jsx("span", { className: "ms-auto shrink-0 text-xs text-th-hi3", children: node.trailing }) : null
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
)
|
|
99
95
|
}
|
|
100
96
|
);
|
|
101
97
|
});
|
|
@@ -290,29 +286,27 @@ function TreeView(props) {
|
|
|
290
286
|
},
|
|
291
287
|
[latest]
|
|
292
288
|
);
|
|
293
|
-
|
|
294
|
-
const open = hasChildren(node) && expandedSet.has(node.id);
|
|
289
|
+
return /* @__PURE__ */ jsx("ul", { ...rest, ref, role: "tree", className: cn("grid gap-px text-sm", className), onKeyDown, onFocus, onBlur, children: flat.map((f) => {
|
|
290
|
+
const open = hasChildren(f.node) && expandedSet.has(f.node.id);
|
|
295
291
|
return /* @__PURE__ */ jsx(
|
|
296
292
|
TreeItem,
|
|
297
293
|
{
|
|
298
|
-
node,
|
|
299
|
-
level,
|
|
300
|
-
posinset:
|
|
301
|
-
setsize:
|
|
294
|
+
node: f.node,
|
|
295
|
+
level: f.level,
|
|
296
|
+
posinset: f.posInSet,
|
|
297
|
+
setsize: f.setSize,
|
|
302
298
|
open,
|
|
303
299
|
selectable,
|
|
304
|
-
selected: selectedId === node.id,
|
|
305
|
-
isTarget: node.id === targetId,
|
|
306
|
-
labelId: `${uid}-${encodeURIComponent(node.id)}`,
|
|
300
|
+
selected: selectedId === f.node.id,
|
|
301
|
+
isTarget: f.node.id === targetId,
|
|
302
|
+
labelId: `${uid}-${encodeURIComponent(f.node.id)}`,
|
|
307
303
|
itemRef,
|
|
308
304
|
onRowClick,
|
|
309
|
-
onToggle
|
|
310
|
-
children: open ? renderNodes(node.children, level + 1) : null
|
|
305
|
+
onToggle
|
|
311
306
|
},
|
|
312
|
-
node.id
|
|
307
|
+
f.node.id
|
|
313
308
|
);
|
|
314
|
-
});
|
|
315
|
-
return /* @__PURE__ */ jsx("ul", { ...rest, ref, role: "tree", className: cn("grid gap-px text-sm", className), onKeyDown, onFocus, onBlur, children: renderNodes(items, 1) });
|
|
309
|
+
}) });
|
|
316
310
|
}
|
|
317
311
|
export {
|
|
318
312
|
TreeView
|