nish-ui 2.0.2 → 2.1.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 +18 -8
- package/dist/chart.js +1 -1
- package/dist/elements-all.js +13 -13
- 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/app-shell.js +145 -45
- package/dist/esm/components/breadcrumbs.js +1 -1
- package/dist/esm/components/calendar-classes.js +325 -0
- package/dist/esm/components/calendar.js +263 -0
- package/dist/esm/components/canvas/route.js +56 -20
- package/dist/esm/components/carousel-classes.js +27 -0
- package/dist/esm/components/carousel.js +317 -0
- package/dist/esm/components/command.js +2 -27
- package/dist/esm/components/context-menu.js +199 -0
- package/dist/esm/components/date-picker.js +208 -0
- package/dist/esm/components/display-classes.js +10 -13
- package/dist/esm/components/display.js +22 -19
- package/dist/esm/components/drawer.js +139 -0
- package/dist/esm/components/filters.js +1 -1
- package/dist/esm/components/flow.js +1 -1
- package/dist/esm/components/hover-card.js +221 -0
- package/dist/esm/components/icons.js +17 -0
- package/dist/esm/components/inbox.js +2 -1
- package/dist/esm/components/lazy-module.js +53 -0
- package/dist/esm/components/menu.js +344 -0
- package/dist/esm/components/modal.js +173 -0
- package/dist/esm/components/more-sheet.js +52 -0
- package/dist/esm/components/multi-select.js +420 -0
- package/dist/esm/components/nav-items.js +138 -0
- package/dist/esm/components/nav.js +13 -174
- package/dist/esm/components/navigate.js +33 -0
- package/dist/esm/components/overlay-core.js +221 -0
- package/dist/esm/components/overlay-dialog.js +255 -0
- package/dist/esm/components/overlay-position.js +163 -0
- package/dist/esm/components/overlay.js +7 -1441
- package/dist/esm/components/popover.js +92 -0
- package/dist/esm/components/segmented.js +2 -1
- package/dist/esm/components/split.js +1 -1
- package/dist/esm/components/strings.js +25 -0
- package/dist/esm/components/tooltip.js +177 -0
- package/dist/esm/components/tree-view-classes.js +57 -0
- package/dist/esm/components/tree-view.js +319 -0
- package/dist/esm/components/virtual-table.js +245 -0
- package/dist/esm/components/virtual.js +291 -0
- package/dist/esm/inbox.js +12 -0
- package/dist/esm/index.js +61 -2
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/service-tokens.js +6 -0
- package/dist/esm/theme.js +2 -2
- package/dist/esm/virtual-range.js +73 -0
- package/dist/format.js +1 -1
- package/dist/inbox.d.ts +238 -0
- package/dist/index.d.ts +1030 -777
- package/dist/nish-components.css +2 -0
- package/dist/nish-components.min.css +1 -1
- package/dist/service-tokens.d.ts +60 -0
- package/dist/theme.d.ts +50 -0
- package/dist/theme.global.js +28 -3
- package/dist/theme.js +28 -3
- package/package.json +17 -1
|
@@ -9,9 +9,14 @@ import { safeUrl } from "../url.js";
|
|
|
9
9
|
import { ConnectionBanner, LoadingBar, PageContainer } from "./layout.js";
|
|
10
10
|
import { AppErrorBoundary } from "./error-boundary.js";
|
|
11
11
|
import { AppHeader } from "./display.js";
|
|
12
|
+
import { warnDev } from "./display-classes.js";
|
|
13
|
+
import { Skeleton } from "./feedback.js";
|
|
12
14
|
import { MoreIcon } from "./icons.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
+
import { lazyModule, preloadWhenIdle, useLazyModule } from "./lazy-module.js";
|
|
16
|
+
import { BottomNav, NavRail, NavSidebar } from "./nav.js";
|
|
17
|
+
import { visibleNavItems } from "./nav-items.js";
|
|
18
|
+
import { NavBadge } from "./nav-items.js";
|
|
19
|
+
import { DropdownMenu, MenuItem } from "./menu.js";
|
|
15
20
|
import { IconButton } from "./primitives.js";
|
|
16
21
|
import { useNishStrings } from "./provider.js";
|
|
17
22
|
import { tabClass } from "./tabs-classes.js";
|
|
@@ -19,6 +24,7 @@ import { ThemeToggle } from "./theme-toggle.js";
|
|
|
19
24
|
import { Toaster } from "./toast.js";
|
|
20
25
|
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
21
26
|
var MAIN_ID = "nish-main";
|
|
27
|
+
var sheetModule = /* @__PURE__ */ lazyModule(() => import("./more-sheet.js"));
|
|
22
28
|
function AppShell({
|
|
23
29
|
name,
|
|
24
30
|
icon,
|
|
@@ -42,6 +48,15 @@ function AppShell({
|
|
|
42
48
|
toaster = {},
|
|
43
49
|
errorBoundary = true,
|
|
44
50
|
resetKey,
|
|
51
|
+
navMode = "adaptive",
|
|
52
|
+
tabs = "underline",
|
|
53
|
+
bottomNav,
|
|
54
|
+
moreMenu: moreMenuProp = true,
|
|
55
|
+
headerInnerClassName,
|
|
56
|
+
containerClassName,
|
|
57
|
+
footer,
|
|
58
|
+
fullHeight = false,
|
|
59
|
+
navPending = 0,
|
|
45
60
|
children
|
|
46
61
|
}) {
|
|
47
62
|
const strings = useNishStrings();
|
|
@@ -57,7 +72,9 @@ function AppShell({
|
|
|
57
72
|
}
|
|
58
73
|
setSheet(false);
|
|
59
74
|
}, [resetKey]);
|
|
60
|
-
const
|
|
75
|
+
const headerMode = navMode === "header";
|
|
76
|
+
if (headerMode && sidebar !== false) warnDev('nish-ui: AppShell navMode="header" ignores sidebar.');
|
|
77
|
+
const side = headerMode || sidebar === false ? null : sidebar === true ? {} : sidebar;
|
|
61
78
|
const storageKey = side?.storageKey === false ? null : side?.storageKey ?? "nish-sidebar-collapsed";
|
|
62
79
|
const [storedCollapsed, setStoredCollapsed] = useLocalStorage(storageKey ?? "nish-sidebar-collapsed", side?.defaultCollapsed ?? false);
|
|
63
80
|
const [memoryCollapsed, setMemoryCollapsed] = useState(side?.defaultCollapsed ?? false);
|
|
@@ -69,48 +86,88 @@ function AppShell({
|
|
|
69
86
|
const bannersRef = useRef(null);
|
|
70
87
|
useHeightVar(bannersRef, "--nish-banners-h");
|
|
71
88
|
const hasNav = nav.length > 0;
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
const brandMode = hasNav && side?.brand != null;
|
|
90
|
+
const brandNode = (isCollapsed) => typeof side?.brand === "function" ? side.brand({ collapsed: isCollapsed }) : side?.brand;
|
|
91
|
+
let bottomItems;
|
|
92
|
+
let overflow;
|
|
93
|
+
if (headerMode) {
|
|
94
|
+
bottomItems = [];
|
|
95
|
+
overflow = [];
|
|
96
|
+
} else if (bottomNav) {
|
|
97
|
+
bottomItems = [];
|
|
98
|
+
for (const key of bottomNav) {
|
|
99
|
+
const found = nav.find((i) => i.key === key);
|
|
100
|
+
if (found) bottomItems.push(found);
|
|
101
|
+
else warnDev(`nish-ui: AppShell bottomNav key "${key}" is not in nav.`);
|
|
102
|
+
}
|
|
103
|
+
if (bottomNav.length > 5) warnDev("nish-ui: AppShell bottomNav has more than 5 items; they do not fit a 360px screen.");
|
|
104
|
+
overflow = nav.filter((i) => !bottomItems.includes(i));
|
|
105
|
+
} else {
|
|
106
|
+
const n = nav.length <= 5 ? nav.length : Math.max(0, primary);
|
|
107
|
+
bottomItems = nav.slice(0, n);
|
|
108
|
+
overflow = nav.slice(n);
|
|
109
|
+
}
|
|
110
|
+
const sheetItems = hasNav && !headerMode ? [...overflow, ...moreItems] : [];
|
|
76
111
|
const hasSheet = sheetItems.length > 0;
|
|
77
112
|
const moreActive = sheetItems.some((i) => i.active);
|
|
113
|
+
const sheetMod = useLazyModule(sheetModule, sheet, () => setSheet(false));
|
|
114
|
+
useEffect(() => hasSheet ? preloadWhenIdle(sheetModule) : void 0, [hasSheet]);
|
|
115
|
+
const showMoreMenu = moreItems.length > 0 && moreMenuProp !== false;
|
|
116
|
+
if (headerMode && moreMenuProp === false && moreItems.length > 0) warnDev('nish-ui: AppShell moreMenu={false} with navMode="header" hides moreItems.');
|
|
117
|
+
if (fullHeight && footer != null) warnDev("nish-ui: AppShell fullHeight does not render footer.");
|
|
78
118
|
const stickTop = "sticky top-[calc(var(--nish-header-h,0px)+var(--nish-banners-h,0px))] h-[calc(100dvh-var(--nish-header-h,0px)-var(--nish-banners-h,0px))] self-start";
|
|
79
119
|
const toggle = themeToggle === false ? false : hasSheet ? /* @__PURE__ */ jsx("span", { className: "max-md:hidden", children: themeToggle ?? /* @__PURE__ */ jsx(ThemeToggle, {}) }) : themeToggle;
|
|
80
|
-
const
|
|
81
|
-
const className = cn(tabClass({ active: !!item.active }), "inline-flex");
|
|
120
|
+
const tabNodes = (variant) => /* @__PURE__ */ jsx(Fragment2, { children: nav.map((item) => {
|
|
121
|
+
const className = cn(tabClass({ active: !!item.active, variant }), "inline-flex", variant === "pill" && "items-center");
|
|
82
122
|
const current = item.active ? "page" : void 0;
|
|
123
|
+
const children2 = /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
124
|
+
item.label,
|
|
125
|
+
/* @__PURE__ */ jsx(NavBadge, { value: item.badge })
|
|
126
|
+
] });
|
|
83
127
|
if (renderLink && item.href != null) {
|
|
84
|
-
return /* @__PURE__ */ jsx(Fragment, { children: renderLink(item, { className, children:
|
|
128
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderLink(item, { className, children: children2, "aria-current": current, onClick: item.onSelect }) }, item.key);
|
|
85
129
|
}
|
|
86
|
-
return item.href != null ? /* @__PURE__ */ jsx("a", { href: item.href, className, "aria-current": current, onClick: item.onSelect, children:
|
|
130
|
+
return item.href != null ? /* @__PURE__ */ jsx("a", { href: item.href, className, "aria-current": current, onClick: item.onSelect, children: children2 }, item.key) : /* @__PURE__ */ jsx("button", { type: "button", className, "aria-current": current, onClick: item.onSelect, children: children2 }, item.key);
|
|
87
131
|
}) });
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
132
|
+
const showHeaderTabs = hasNav && !side && (headerMode || tabs !== "pill");
|
|
133
|
+
const showPills = hasNav && !side && !headerMode && tabs === "pill";
|
|
134
|
+
const headerNav = !hasNav && navPending > 0 ? [
|
|
135
|
+
// Skeleton is already aria-hidden; this keeps the placeholder landmark from being empty.
|
|
136
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: strings.loading }, "loading"),
|
|
137
|
+
...Array.from({ length: navPending }, (_, i) => /* @__PURE__ */ jsx(Skeleton, { className: cn("w-24 rounded-lg pointer-coarse:h-11", tabs === "pill" ? "h-8" : "h-10") }, i))
|
|
138
|
+
] : showHeaderTabs ? tabNodes(tabs === "pill" ? "pill" : "underline") : void 0;
|
|
139
|
+
const moreMenuNode = (menuSide) => /* @__PURE__ */ jsx(
|
|
140
|
+
DropdownMenu,
|
|
141
|
+
{
|
|
142
|
+
align: "end",
|
|
143
|
+
side: menuSide,
|
|
144
|
+
trigger: /* @__PURE__ */ jsx(IconButton, { label: strings.more, children: /* @__PURE__ */ jsx(MoreIcon, { size: 20 }) }),
|
|
145
|
+
children: moreItems.map((item) => /* @__PURE__ */ jsx(
|
|
146
|
+
MenuItem,
|
|
147
|
+
{
|
|
148
|
+
icon: item.icon,
|
|
149
|
+
active: item.active,
|
|
150
|
+
onSelect: () => {
|
|
151
|
+
if (item.onSelect) item.onSelect();
|
|
152
|
+
else if (item.href != null) {
|
|
153
|
+
const href = safeUrl(item.href);
|
|
154
|
+
if (href !== null) window.location.assign(href);
|
|
155
|
+
}
|
|
108
156
|
},
|
|
109
|
-
item.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
157
|
+
children: item.label
|
|
158
|
+
},
|
|
159
|
+
item.key
|
|
160
|
+
))
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
const moreMenu = showMoreMenu ? /* @__PURE__ */ jsx("div", { className: hasNav && !headerMode ? "hidden md:inline-flex" : "inline-flex", children: moreMenuNode() }) : null;
|
|
164
|
+
const hubHref = hub ? safeUrl(hub.href) : null;
|
|
165
|
+
const hubPill = hub && hubHref != null ? /* @__PURE__ */ jsxs("a", { className: "nish-pill-link", href: hubHref, title: hub.title ?? strings.hubTitle, children: [
|
|
166
|
+
/* @__PURE__ */ jsx("span", { className: "inline-block rtl:-scale-x-100", children: "\u2190" }),
|
|
167
|
+
" ",
|
|
168
|
+
/* @__PURE__ */ jsx("span", { className: "nish-pill-link-label", children: hub.label })
|
|
169
|
+
] }) : null;
|
|
170
|
+
const sidebarToggle = themeToggle === false ? null : themeToggle ?? /* @__PURE__ */ jsx(ThemeToggle, { compact: collapsed });
|
|
114
171
|
const page = errorBoundary ? /* @__PURE__ */ jsx(AppErrorBoundary, { resetKeys: [resetKey], children }) : children;
|
|
115
172
|
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
116
173
|
/* @__PURE__ */ jsx(
|
|
@@ -139,13 +196,15 @@ function AppShell({
|
|
|
139
196
|
hideNameBelow: icon != null ? "sm" : void 0,
|
|
140
197
|
compactPill: true,
|
|
141
198
|
actions: /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
199
|
+
showPills ? /* @__PURE__ */ jsx("nav", { "aria-label": navLabel, className: "hidden items-center gap-1 lg:flex", children: tabNodes("pill") }) : null,
|
|
142
200
|
hasNav && side?.tools != null ? /* @__PURE__ */ jsx("span", { className: "flex items-center gap-2 lg:hidden", children: side.tools }) : null,
|
|
143
201
|
actions,
|
|
144
202
|
moreMenu
|
|
145
203
|
] }),
|
|
146
204
|
themeToggle: toggle,
|
|
147
|
-
className: "max-lg:[&>nav]:hidden",
|
|
148
|
-
|
|
205
|
+
className: cn(!headerMode && "max-lg:[&>nav]:hidden", brandMode && "lg:hidden"),
|
|
206
|
+
innerClassName: headerInnerClassName,
|
|
207
|
+
nav: headerNav,
|
|
149
208
|
navLabel
|
|
150
209
|
}
|
|
151
210
|
),
|
|
@@ -163,32 +222,73 @@ function AppShell({
|
|
|
163
222
|
}
|
|
164
223
|
),
|
|
165
224
|
/* @__PURE__ */ jsxs("div", { className: "md:flex", children: [
|
|
166
|
-
hasNav ? /* @__PURE__ */ jsx("div", { className: cn(stickTop, "hidden md:block lg:hidden"), children: /* @__PURE__ */ jsx(NavRail, { items: nav, showFrom: "md", hideFrom: "lg", footer: railFooter, renderLink, label: navLabel, className: "h-full" }) }) : null,
|
|
225
|
+
hasNav && !headerMode ? /* @__PURE__ */ jsx("div", { className: cn(stickTop, "hidden md:block lg:hidden"), children: /* @__PURE__ */ jsx(NavRail, { items: nav, showFrom: "md", hideFrom: "lg", footer: railFooter, renderLink, label: navLabel, className: "h-full" }) }) : null,
|
|
167
226
|
hasNav && side ? /* @__PURE__ */ jsx("div", { className: cn(stickTop, "hidden lg:block"), children: /* @__PURE__ */ jsx(
|
|
168
227
|
NavSidebar,
|
|
169
228
|
{
|
|
170
229
|
items: nav,
|
|
171
230
|
collapsed,
|
|
172
231
|
onCollapsedChange: setCollapsed,
|
|
173
|
-
|
|
174
|
-
|
|
232
|
+
header: brandMode && !collapsed ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
233
|
+
hubPill,
|
|
234
|
+
brandNode(false)
|
|
235
|
+
] }) : void 0,
|
|
236
|
+
tools: brandMode ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
237
|
+
side.tools,
|
|
238
|
+
actions
|
|
239
|
+
] }) : side.tools,
|
|
240
|
+
footer: brandMode ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
241
|
+
sidebarToggle,
|
|
242
|
+
side.footer,
|
|
243
|
+
showMoreMenu ? moreMenuNode("top") : null
|
|
244
|
+
] }) : side.footer,
|
|
175
245
|
renderLink,
|
|
176
246
|
label: navLabel
|
|
177
247
|
}
|
|
178
248
|
) }) : null,
|
|
179
|
-
/* @__PURE__ */
|
|
249
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
250
|
+
brandMode && collapsed ? /* @__PURE__ */ jsxs("div", { className: "hidden h-14 items-center gap-3 border-b border-th-line px-[var(--nish-page-gutter,1rem)] py-[5px] lg:flex", children: [
|
|
251
|
+
hubPill,
|
|
252
|
+
brandNode(true)
|
|
253
|
+
] }) : null,
|
|
254
|
+
fullHeight ? /* @__PURE__ */ jsx(
|
|
255
|
+
"main",
|
|
256
|
+
{
|
|
257
|
+
id: mainId,
|
|
258
|
+
tabIndex: -1,
|
|
259
|
+
className: cn(
|
|
260
|
+
"flex min-h-0 flex-col overflow-hidden focus:outline-none h-[calc(100dvh-var(--nish-header-h,0px)-var(--nish-banners-h,0px))] pb-[var(--nish-bottom-inset,0px)]",
|
|
261
|
+
brandMode && collapsed && "lg:h-[calc(100dvh-var(--nish-banners-h,0px)-3.5rem)]"
|
|
262
|
+
),
|
|
263
|
+
children: page
|
|
264
|
+
}
|
|
265
|
+
) : container === false ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
266
|
+
/* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "focus:outline-none", children: page }),
|
|
267
|
+
footer
|
|
268
|
+
] }) : /* @__PURE__ */ jsxs(PageContainer, { as: "div", size: container, className: containerClassName, children: [
|
|
269
|
+
/* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "focus:outline-none", children: page }),
|
|
270
|
+
footer
|
|
271
|
+
] })
|
|
272
|
+
] })
|
|
180
273
|
] }),
|
|
181
|
-
hasNav ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
274
|
+
hasNav && !headerMode ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
182
275
|
/* @__PURE__ */ jsx(
|
|
183
276
|
BottomNav,
|
|
184
277
|
{
|
|
185
278
|
items: bottomItems,
|
|
186
|
-
more: hasSheet ? {
|
|
279
|
+
more: hasSheet ? {
|
|
280
|
+
active: moreActive,
|
|
281
|
+
expanded: sheet,
|
|
282
|
+
onToggle: () => {
|
|
283
|
+
void sheetModule.load().catch(() => void 0);
|
|
284
|
+
setSheet((s) => !s);
|
|
285
|
+
}
|
|
286
|
+
} : void 0,
|
|
187
287
|
renderLink,
|
|
188
288
|
label: navLabel
|
|
189
289
|
}
|
|
190
290
|
),
|
|
191
|
-
/* @__PURE__ */ jsx(MoreSheet, { open: sheet, onClose: () => setSheet(false), items: sheetItems, renderLink })
|
|
291
|
+
sheetMod ? /* @__PURE__ */ jsx(sheetMod.MoreSheet, { open: sheet, onClose: () => setSheet(false), items: sheetItems, renderLink }) : null
|
|
192
292
|
] }) : null,
|
|
193
293
|
toaster !== false ? /* @__PURE__ */ jsx(Toaster, { ...toaster }) : null
|
|
194
294
|
] });
|
|
@@ -5,7 +5,7 @@ import { Children, Fragment, cloneElement, isValidElement, useCallback, useRef,
|
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { safeUrl } from "../url.js";
|
|
7
7
|
import { useIsoLayoutEffect } from "./client.js";
|
|
8
|
-
import { DropdownMenu, MenuItem } from "./
|
|
8
|
+
import { DropdownMenu, MenuItem } from "./menu.js";
|
|
9
9
|
import { useNishStrings } from "./provider.js";
|
|
10
10
|
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
var LINK = cn(
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// src/components/calendar-classes.ts
|
|
2
|
+
var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
var MONTH_RE = /^(\d{4})-(\d{2})$/;
|
|
4
|
+
function pad(n, width) {
|
|
5
|
+
let s = String(n);
|
|
6
|
+
while (s.length < width) s = "0" + s;
|
|
7
|
+
return s;
|
|
8
|
+
}
|
|
9
|
+
function utcDate(y, m, d) {
|
|
10
|
+
const t = /* @__PURE__ */ new Date(0);
|
|
11
|
+
t.setUTCFullYear(y, m - 1, d);
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function fromDate(t) {
|
|
15
|
+
return { y: t.getUTCFullYear(), m: t.getUTCMonth() + 1, d: t.getUTCDate() };
|
|
16
|
+
}
|
|
17
|
+
function daysInMonth(y, m) {
|
|
18
|
+
return utcDate(y, m + 1, 0).getUTCDate();
|
|
19
|
+
}
|
|
20
|
+
function parseIso(s) {
|
|
21
|
+
if (typeof s !== "string") return null;
|
|
22
|
+
const match = ISO_RE.exec(s);
|
|
23
|
+
if (!match) return null;
|
|
24
|
+
const y = Number(match[1]);
|
|
25
|
+
const m = Number(match[2]);
|
|
26
|
+
const d = Number(match[3]);
|
|
27
|
+
if (y < 1 || m < 1 || m > 12 || d < 1 || d > daysInMonth(y, m)) return null;
|
|
28
|
+
return { y, m, d };
|
|
29
|
+
}
|
|
30
|
+
function toIso(p) {
|
|
31
|
+
return `${pad(p.y, 4)}-${pad(p.m, 2)}-${pad(p.d, 2)}`;
|
|
32
|
+
}
|
|
33
|
+
function parseMonth(s) {
|
|
34
|
+
if (typeof s !== "string") return null;
|
|
35
|
+
const match = MONTH_RE.exec(s);
|
|
36
|
+
if (!match) return null;
|
|
37
|
+
const y = Number(match[1]);
|
|
38
|
+
const m = Number(match[2]);
|
|
39
|
+
if (y < 1 || m < 1 || m > 12) return null;
|
|
40
|
+
return { y, m };
|
|
41
|
+
}
|
|
42
|
+
function monthOf(iso) {
|
|
43
|
+
return iso.slice(0, 7);
|
|
44
|
+
}
|
|
45
|
+
function firstOfMonth(month) {
|
|
46
|
+
return `${month}-01`;
|
|
47
|
+
}
|
|
48
|
+
function dateOf(iso) {
|
|
49
|
+
const p = parseIso(iso);
|
|
50
|
+
return p ? utcDate(p.y, p.m, p.d) : /* @__PURE__ */ new Date(NaN);
|
|
51
|
+
}
|
|
52
|
+
function addDays(iso, n) {
|
|
53
|
+
const p = parseIso(iso);
|
|
54
|
+
if (!p) return iso;
|
|
55
|
+
const t = utcDate(p.y, p.m, p.d);
|
|
56
|
+
t.setUTCDate(t.getUTCDate() + n);
|
|
57
|
+
const q = fromDate(t);
|
|
58
|
+
if (q.y > 9999) return "9999-12-31";
|
|
59
|
+
if (q.y < 1) return "0001-01-01";
|
|
60
|
+
return toIso(q);
|
|
61
|
+
}
|
|
62
|
+
function addMonthsYmd(p, n) {
|
|
63
|
+
const total = p.y * 12 + (p.m - 1) + n;
|
|
64
|
+
const y = Math.floor(total / 12);
|
|
65
|
+
const m = total - y * 12 + 1;
|
|
66
|
+
if (y > 9999) return { y: 9999, m: 12, d: p.d };
|
|
67
|
+
if (y < 1) return { y: 1, m: 1, d: p.d };
|
|
68
|
+
return { y, m, d: Math.min(p.d, daysInMonth(y, m)) };
|
|
69
|
+
}
|
|
70
|
+
function addMonths(iso, n) {
|
|
71
|
+
const p = parseIso(iso);
|
|
72
|
+
return p ? toIso(addMonthsYmd(p, n)) : iso;
|
|
73
|
+
}
|
|
74
|
+
function addYears(iso, n) {
|
|
75
|
+
return addMonths(iso, n * 12);
|
|
76
|
+
}
|
|
77
|
+
function shiftMonth(month, n) {
|
|
78
|
+
const p = parseMonth(month);
|
|
79
|
+
if (!p) return month;
|
|
80
|
+
const q = addMonthsYmd({ y: p.y, m: p.m, d: 1 }, n);
|
|
81
|
+
return `${pad(q.y, 4)}-${pad(q.m, 2)}`;
|
|
82
|
+
}
|
|
83
|
+
function weekday(iso) {
|
|
84
|
+
return dateOf(iso).getUTCDay();
|
|
85
|
+
}
|
|
86
|
+
function startOfWeek(iso, weekStartsOn) {
|
|
87
|
+
return addDays(iso, -((weekday(iso) - weekStartsOn + 7) % 7));
|
|
88
|
+
}
|
|
89
|
+
function endOfWeek(iso, weekStartsOn) {
|
|
90
|
+
return addDays(startOfWeek(iso, weekStartsOn), 6);
|
|
91
|
+
}
|
|
92
|
+
function clampIso(iso, min, max) {
|
|
93
|
+
if (min && iso < min) return min;
|
|
94
|
+
if (max && iso > max) return max;
|
|
95
|
+
return iso;
|
|
96
|
+
}
|
|
97
|
+
function inRange(iso, min, max) {
|
|
98
|
+
if (min && iso < min) return false;
|
|
99
|
+
if (max && iso > max) return false;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function monthGrid(month, weekStartsOn) {
|
|
103
|
+
const p = parseMonth(month);
|
|
104
|
+
const rows = [];
|
|
105
|
+
const count = p ? daysInMonth(p.y, p.m) : 0;
|
|
106
|
+
const lead = p ? (weekday(firstOfMonth(month)) - weekStartsOn + 7) % 7 : 0;
|
|
107
|
+
let day = 1 - lead;
|
|
108
|
+
for (let r = 0; r < 6; r++) {
|
|
109
|
+
const row = [];
|
|
110
|
+
for (let c = 0; c < 7; c++) {
|
|
111
|
+
row.push(p && day >= 1 && day <= count ? `${month}-${pad(day, 2)}` : null);
|
|
112
|
+
day++;
|
|
113
|
+
}
|
|
114
|
+
rows.push(row);
|
|
115
|
+
}
|
|
116
|
+
return rows;
|
|
117
|
+
}
|
|
118
|
+
function calendarKeyTarget(key, shiftKey, from, weekStartsOn, rtl) {
|
|
119
|
+
switch (key) {
|
|
120
|
+
case "ArrowRight":
|
|
121
|
+
return addDays(from, rtl ? -1 : 1);
|
|
122
|
+
case "ArrowLeft":
|
|
123
|
+
return addDays(from, rtl ? 1 : -1);
|
|
124
|
+
case "ArrowDown":
|
|
125
|
+
return addDays(from, 7);
|
|
126
|
+
case "ArrowUp":
|
|
127
|
+
return addDays(from, -7);
|
|
128
|
+
case "Home":
|
|
129
|
+
return startOfWeek(from, weekStartsOn);
|
|
130
|
+
case "End":
|
|
131
|
+
return endOfWeek(from, weekStartsOn);
|
|
132
|
+
case "PageUp":
|
|
133
|
+
return shiftKey ? addYears(from, -1) : addMonths(from, -1);
|
|
134
|
+
case "PageDown":
|
|
135
|
+
return shiftKey ? addYears(from, 1) : addMonths(from, 1);
|
|
136
|
+
default:
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function isoToday(now = /* @__PURE__ */ new Date()) {
|
|
141
|
+
return toIso({ y: now.getFullYear(), m: now.getMonth() + 1, d: now.getDate() });
|
|
142
|
+
}
|
|
143
|
+
var resolved = /* @__PURE__ */ new Map();
|
|
144
|
+
function resolveLocale(locale) {
|
|
145
|
+
if (!locale) return "en-US";
|
|
146
|
+
const hit = resolved.get(locale);
|
|
147
|
+
if (hit) return hit;
|
|
148
|
+
let out = "en-US";
|
|
149
|
+
try {
|
|
150
|
+
out = Intl.getCanonicalLocales(locale)[0] ?? "en-US";
|
|
151
|
+
} catch {
|
|
152
|
+
out = "en-US";
|
|
153
|
+
}
|
|
154
|
+
resolved.set(locale, out);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
var SUNDAY_FIRST = new Set(
|
|
158
|
+
"AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW".split(
|
|
159
|
+
" "
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
var SATURDAY_FIRST = new Set("AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));
|
|
163
|
+
var weekStarts = /* @__PURE__ */ new Map();
|
|
164
|
+
function weekStartFor(locale) {
|
|
165
|
+
const hit = weekStarts.get(locale);
|
|
166
|
+
if (hit !== void 0) return hit;
|
|
167
|
+
const v = computeWeekStart(locale);
|
|
168
|
+
weekStarts.set(locale, v);
|
|
169
|
+
return v;
|
|
170
|
+
}
|
|
171
|
+
function computeWeekStart(locale) {
|
|
172
|
+
let region = "US";
|
|
173
|
+
try {
|
|
174
|
+
region = new Intl.Locale(resolveLocale(locale)).maximize().region ?? "US";
|
|
175
|
+
} catch {
|
|
176
|
+
region = "US";
|
|
177
|
+
}
|
|
178
|
+
if (SUNDAY_FIRST.has(region)) return 0;
|
|
179
|
+
if (SATURDAY_FIRST.has(region)) return 6;
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
183
|
+
function formatter(locale, options) {
|
|
184
|
+
const opts = { ...options, timeZone: "UTC", calendar: "gregory" };
|
|
185
|
+
const key = `${locale}|${JSON.stringify(opts)}`;
|
|
186
|
+
let f = formatters.get(key);
|
|
187
|
+
if (!f) {
|
|
188
|
+
f = new Intl.DateTimeFormat(locale, opts);
|
|
189
|
+
formatters.set(key, f);
|
|
190
|
+
}
|
|
191
|
+
return f;
|
|
192
|
+
}
|
|
193
|
+
var BIDI_MARKS_RE = /[]/g;
|
|
194
|
+
var fieldParts = /* @__PURE__ */ new Map();
|
|
195
|
+
function dateFieldParts(locale) {
|
|
196
|
+
const cached = fieldParts.get(locale);
|
|
197
|
+
if (cached) return cached;
|
|
198
|
+
const parts = formatter(locale, { year: "numeric", month: "2-digit", day: "2-digit", numberingSystem: "latn" }).formatToParts(utcDate(2026, 12, 31)).map((p) => {
|
|
199
|
+
if (p.type === "day" || p.type === "month" || p.type === "year") return { type: p.type, value: p.value };
|
|
200
|
+
return { type: "literal", value: p.value.replace(BIDI_MARKS_RE, "") };
|
|
201
|
+
});
|
|
202
|
+
fieldParts.set(locale, parts);
|
|
203
|
+
return parts;
|
|
204
|
+
}
|
|
205
|
+
function formatDateField(iso, locale) {
|
|
206
|
+
const p = parseIso(iso);
|
|
207
|
+
if (!p) return "";
|
|
208
|
+
return dateFieldParts(locale).map((part) => {
|
|
209
|
+
if (part.type === "year") return String(p.y).padStart(4, "0");
|
|
210
|
+
if (part.type === "month") return String(p.m).padStart(2, "0");
|
|
211
|
+
if (part.type === "day") return String(p.d).padStart(2, "0");
|
|
212
|
+
return part.value;
|
|
213
|
+
}).join("");
|
|
214
|
+
}
|
|
215
|
+
var FIELD_JUNK_RE = /[^\d\s/.,-]/;
|
|
216
|
+
var ISO_FIELD_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
217
|
+
var DIGITS_RE = /\d+/g;
|
|
218
|
+
function parseDateField(text, locale) {
|
|
219
|
+
const t = text.replace(BIDI_MARKS_RE, "").trim();
|
|
220
|
+
if (t === "") return null;
|
|
221
|
+
if (FIELD_JUNK_RE.test(t)) return null;
|
|
222
|
+
if (ISO_FIELD_RE.test(t)) {
|
|
223
|
+
const p = parseIso(t);
|
|
224
|
+
return p ? toIso(p) : null;
|
|
225
|
+
}
|
|
226
|
+
const order = dateFieldParts(locale).map((p) => p.type).filter((type) => type !== "literal");
|
|
227
|
+
const groups = t.match(DIGITS_RE);
|
|
228
|
+
if (!groups) return null;
|
|
229
|
+
let raw;
|
|
230
|
+
if (groups.length === 3) {
|
|
231
|
+
raw = groups;
|
|
232
|
+
} else if (groups.length === 1 && groups[0].length === 8) {
|
|
233
|
+
const digits = groups[0];
|
|
234
|
+
raw = [];
|
|
235
|
+
let at = 0;
|
|
236
|
+
for (const type of order) {
|
|
237
|
+
const width = type === "year" ? 4 : 2;
|
|
238
|
+
raw.push(digits.slice(at, at + width));
|
|
239
|
+
at += width;
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
if (order.length !== 3) return null;
|
|
245
|
+
const found = { day: "", month: "", year: "" };
|
|
246
|
+
order.forEach((type, i) => {
|
|
247
|
+
found[type] = raw[i];
|
|
248
|
+
});
|
|
249
|
+
let y = Number(found.year);
|
|
250
|
+
if (found.year.length === 3 || found.year.length > 4) return null;
|
|
251
|
+
if (found.year.length <= 2) y = 2e3 + y;
|
|
252
|
+
const m = Number(found.month);
|
|
253
|
+
const d = Number(found.day);
|
|
254
|
+
if (y < 1 || m < 1 || m > 12 || d < 1 || d > daysInMonth(y, m)) return null;
|
|
255
|
+
return toIso({ y, m, d });
|
|
256
|
+
}
|
|
257
|
+
function datePlaceholder(locale, tokens) {
|
|
258
|
+
return dateFieldParts(locale).map((p) => p.type === "literal" ? p.value : tokens[p.type]).join("");
|
|
259
|
+
}
|
|
260
|
+
function monthTitle(month, locale) {
|
|
261
|
+
const p = parseMonth(month);
|
|
262
|
+
if (!p) return "";
|
|
263
|
+
return formatter(locale, { month: "long", year: "numeric" }).format(utcDate(p.y, p.m, 1));
|
|
264
|
+
}
|
|
265
|
+
function monthNames(locale) {
|
|
266
|
+
const f = formatter(locale, { month: "long" });
|
|
267
|
+
const names = [];
|
|
268
|
+
for (let m = 1; m <= 12; m++) names.push(f.format(utcDate(2026, m, 1)));
|
|
269
|
+
return names;
|
|
270
|
+
}
|
|
271
|
+
function weekdayNames(locale, weekStartsOn) {
|
|
272
|
+
const short = formatter(locale, { weekday: "short" });
|
|
273
|
+
const long = formatter(locale, { weekday: "long" });
|
|
274
|
+
const narrow = formatter(locale, { weekday: "narrow" });
|
|
275
|
+
const days = [];
|
|
276
|
+
for (let i = 0; i < 7; i++) days.push(utcDate(2026, 11, 1 + (weekStartsOn + i) % 7));
|
|
277
|
+
const shorts = days.map((t) => short.format(t));
|
|
278
|
+
const useNarrow = shorts.some((n) => n.length > 4);
|
|
279
|
+
return days.map((t, i) => ({
|
|
280
|
+
short: useNarrow ? narrow.format(t) : shorts[i],
|
|
281
|
+
long: long.format(t)
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
function dayNumber(iso, locale) {
|
|
285
|
+
const p = parseIso(iso);
|
|
286
|
+
return p ? formatter(locale, { day: "numeric" }).format(utcDate(p.y, p.m, p.d)) : "";
|
|
287
|
+
}
|
|
288
|
+
function fullDate(iso, locale) {
|
|
289
|
+
const p = parseIso(iso);
|
|
290
|
+
if (!p) return "";
|
|
291
|
+
return formatter(locale, { weekday: "long", year: "numeric", month: "long", day: "numeric" }).format(
|
|
292
|
+
utcDate(p.y, p.m, p.d)
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
export {
|
|
296
|
+
addDays,
|
|
297
|
+
addMonths,
|
|
298
|
+
addYears,
|
|
299
|
+
calendarKeyTarget,
|
|
300
|
+
clampIso,
|
|
301
|
+
dateFieldParts,
|
|
302
|
+
datePlaceholder,
|
|
303
|
+
dayNumber,
|
|
304
|
+
daysInMonth,
|
|
305
|
+
endOfWeek,
|
|
306
|
+
firstOfMonth,
|
|
307
|
+
formatDateField,
|
|
308
|
+
fullDate,
|
|
309
|
+
inRange,
|
|
310
|
+
isoToday,
|
|
311
|
+
monthGrid,
|
|
312
|
+
monthNames,
|
|
313
|
+
monthOf,
|
|
314
|
+
monthTitle,
|
|
315
|
+
parseDateField,
|
|
316
|
+
parseIso,
|
|
317
|
+
parseMonth,
|
|
318
|
+
resolveLocale,
|
|
319
|
+
shiftMonth,
|
|
320
|
+
startOfWeek,
|
|
321
|
+
toIso,
|
|
322
|
+
weekStartFor,
|
|
323
|
+
weekday,
|
|
324
|
+
weekdayNames
|
|
325
|
+
};
|