@cboxdk/cbox-ui 0.12.0 → 0.13.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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { cn } from './chunk-QJ4T7RR2.js';
2
2
  export { cn, niceTicks, timeTicks } from './chunk-QJ4T7RR2.js';
3
3
  import { defineCboxAppSwitcher, subscribeKnownAppCatalog, readKnownAppCatalog, secureIconUrl, initials, parseAppCatalog, signInTarget, rememberAppCatalog } from './chunk-AJCYF7SS.js';
4
4
  export { authorizeHref, parseAppCatalog, readKnownAppCatalog, rememberAppCatalog, secureIconUrl, signInTarget } from './chunk-AJCYF7SS.js';
5
- import { createContext, forwardRef, Children, isValidElement, cloneElement, useContext, useMemo, useSyncExternalStore, useState, useId, useEffect, useCallback, useRef, createElement, useLayoutEffect, useImperativeHandle } from 'react';
5
+ import { createContext, forwardRef, Children, isValidElement, cloneElement, useContext, useMemo, useSyncExternalStore, useState, useId, useRef, useCallback, useEffect, createElement, useLayoutEffect, useImperativeHandle } from 'react';
6
6
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
7
7
  import { Zap, Webhook, Wallet, Users, Timer, Tag, Sparkles, ShieldCheck, Shield, Settings, Server, Send, Search, Rocket, Receipt, Plug, Percent, Package, Network, MessageSquare, Mail, Lock, List, LifeBuoy, Layers, LayoutGrid, LayoutDashboard, Key, Inbox, Home, HardDrive, Globe, GitBranch, Folder, FileText, Database, CreditCard, Code, Cloud, Clock, Calendar, Building2, Briefcase, Boxes, BookOpen, Bell, BarChart3, Activity, ChevronDown, Plus, PinOff, Pin, PanelLeftOpen, PanelLeftClose, ChevronsUpDown, CircleHelp, ArrowLeftRight, CornerDownLeft, ArrowRight, MoreHorizontal, ChevronLeft, X, ArrowUpRight, ArrowUp, CircleAlert, UserRound, Ticket, ChevronRight, ArrowLeft, Circle, Monitor, Sun, Moon, LogOut, Check } from 'lucide-react';
8
8
  import { createPortal } from 'react-dom';
@@ -85,14 +85,8 @@ function useShellHelp() {
85
85
  const api = useContext(ShellContext);
86
86
  return api === null ? null : { toggleHelp: api.toggleHelp, openArticle: api.openArticle, ask: api.ask };
87
87
  }
88
- function sameTitle(a, b) {
89
- const norm = (text) => text.replace(/\s+/g, " ").trim().replace(/:$/, "").toLocaleLowerCase();
90
- return norm(a) !== "" && norm(a) === norm(b);
91
- }
92
88
  function useShellPageTitle() {
93
- const api = useContext(ShellContext);
94
- if (api === null || !api.mobile) return null;
95
- return api.shell.nav.areas.find((area) => area.key === api.shell.nav.activeArea)?.label ?? null;
89
+ return null;
96
90
  }
97
91
  var DESKTOP_POINTER = "(hover: hover) and (pointer: fine)";
98
92
  var HELP_DOCKED = "(min-width: 1280px)";
@@ -1384,134 +1378,6 @@ function CascadeLabel({ levels }) {
1384
1378
  ] })
1385
1379
  ] });
1386
1380
  }
1387
- var SHELL_ICONS = {
1388
- activity: Activity,
1389
- "bar-chart": BarChart3,
1390
- bell: Bell,
1391
- "book-open": BookOpen,
1392
- boxes: Boxes,
1393
- briefcase: Briefcase,
1394
- building: Building2,
1395
- calendar: Calendar,
1396
- clock: Clock,
1397
- cloud: Cloud,
1398
- code: Code,
1399
- "credit-card": CreditCard,
1400
- database: Database,
1401
- "file-text": FileText,
1402
- folder: Folder,
1403
- "git-branch": GitBranch,
1404
- globe: Globe,
1405
- "hard-drive": HardDrive,
1406
- home: Home,
1407
- inbox: Inbox,
1408
- key: Key,
1409
- "layout-dashboard": LayoutDashboard,
1410
- "layout-grid": LayoutGrid,
1411
- layers: Layers,
1412
- "life-buoy": LifeBuoy,
1413
- list: List,
1414
- lock: Lock,
1415
- mail: Mail,
1416
- "message-square": MessageSquare,
1417
- network: Network,
1418
- package: Package,
1419
- percent: Percent,
1420
- plug: Plug,
1421
- receipt: Receipt,
1422
- rocket: Rocket,
1423
- search: Search,
1424
- send: Send,
1425
- server: Server,
1426
- settings: Settings,
1427
- shield: Shield,
1428
- "shield-check": ShieldCheck,
1429
- sparkles: Sparkles,
1430
- tag: Tag,
1431
- timer: Timer,
1432
- users: Users,
1433
- wallet: Wallet,
1434
- webhook: Webhook,
1435
- zap: Zap
1436
- };
1437
- function resolveIcon(name, extra = {}) {
1438
- if (name === void 0) return Circle;
1439
- return extra[name] ?? SHELL_ICONS[name] ?? Circle;
1440
- }
1441
-
1442
- // src/shell/help-store.ts
1443
- var INITIAL_HELP_STATE = {
1444
- open: false,
1445
- article: null,
1446
- query: "",
1447
- scrollTop: 0,
1448
- updates: [],
1449
- updatesStatus: "idle",
1450
- pendingQuestion: null,
1451
- seeded: false,
1452
- restored: false,
1453
- updatesKey: null
1454
- };
1455
- function helpVisible(state, docked) {
1456
- return state.open && (docked || !state.restored);
1457
- }
1458
- function createHelpStore(initial = {}) {
1459
- let state = { ...INITIAL_HELP_STATE, ...initial };
1460
- const listeners = /* @__PURE__ */ new Set();
1461
- return {
1462
- get: () => state,
1463
- set(patch) {
1464
- const next = typeof patch === "function" ? patch(state) : patch;
1465
- state = { ...state, ...next };
1466
- listeners.forEach((listener) => listener());
1467
- },
1468
- subscribe(listener) {
1469
- listeners.add(listener);
1470
- return () => listeners.delete(listener);
1471
- }
1472
- };
1473
- }
1474
- var browserStore = null;
1475
- function sharedHelpStore() {
1476
- if (typeof window === "undefined") return createHelpStore();
1477
- browserStore ??= createHelpStore();
1478
- return browserStore;
1479
- }
1480
- function parseUpdates(body) {
1481
- const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
1482
- return rows2.flatMap((value) => {
1483
- if (typeof value !== "object" || value === null) return [];
1484
- const row = value;
1485
- if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
1486
- const update = {
1487
- id: String(row.id),
1488
- kind: row.kind === "chat" ? "chat" : "ticket",
1489
- title: row.title,
1490
- unread: row.unread === true || row.read === false || row.read_at === null && row.unread !== false
1491
- };
1492
- if (typeof row.excerpt === "string") update.excerpt = row.excerpt;
1493
- const at = row.at ?? row.updated_at ?? row.created_at;
1494
- if (typeof at === "string") update.at = at;
1495
- const url = safeUrl(row.url);
1496
- if (url !== void 0) update.url = url;
1497
- return [update];
1498
- });
1499
- }
1500
- function parseArticles(body) {
1501
- const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
1502
- return rows2.flatMap((value) => {
1503
- if (typeof value !== "object" || value === null) return [];
1504
- const row = value;
1505
- if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
1506
- const article = { id: String(row.id), title: row.title };
1507
- if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
1508
- if (typeof row.body === "string") article.body = row.body;
1509
- const url = safeUrl(row.url);
1510
- if (url !== void 0) article.url = url;
1511
- if (typeof row.source === "string") article.source = row.source;
1512
- return [article];
1513
- });
1514
- }
1515
1381
  var count = 0;
1516
1382
  var saved = null;
1517
1383
  var startY = 0;
@@ -1621,55 +1487,411 @@ function useScrollLock(active = true) {
1621
1487
  return lockScroll();
1622
1488
  }, [active]);
1623
1489
  }
1624
- var LARGE = 0.92;
1625
- var MEDIUM = 0.5;
1626
- function sheetDetents({ size, viewport, current, content }) {
1627
- const large = Math.round(viewport * LARGE);
1628
- const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
1629
- const sorted = heights.map(Math.round).sort((a, b) => a - b);
1630
- const detents = [];
1631
- for (const height of sorted) {
1632
- const last = detents[detents.length - 1];
1633
- if (last === void 0 || height - last >= 48) detents.push(height);
1634
- else if (height === Math.round(current)) detents[detents.length - 1] = height;
1635
- }
1636
- return detents;
1637
- }
1638
- function rubberBand(overshoot, limit = 120) {
1639
- if (overshoot <= 0) return 0;
1640
- return limit * (1 - 1 / (overshoot / limit + 1));
1490
+ function Spinner({ className, label }) {
1491
+ return /* @__PURE__ */ jsx(
1492
+ "span",
1493
+ {
1494
+ className: cn("cbx-ui-spinner", className),
1495
+ role: label === void 0 ? void 0 : "status",
1496
+ "aria-hidden": label === void 0 ? true : void 0,
1497
+ "aria-label": label
1498
+ }
1499
+ );
1641
1500
  }
1642
- function settleSheet({ height, velocity, detents }) {
1643
- const smallest = detents[0] ?? height;
1644
- const below = smallest - height;
1645
- if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
1646
- const projected = height - velocity * 200;
1647
- let best = smallest;
1648
- for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
1649
- return { close: false, height: best };
1501
+ function buttonClassName({ variant = "ghost", size = "md" } = {}) {
1502
+ return cn("cbx-ui-btn", `cbx-ui-btn--${variant}`, size !== "md" && `cbx-ui-btn--${size}`);
1650
1503
  }
1651
- var VelocityTracker = class {
1652
- samples = [];
1653
- add(t, y) {
1654
- this.samples.push({ t, y });
1655
- while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
1656
- }
1657
- velocity() {
1658
- const first = this.samples[0];
1659
- const last = this.samples[this.samples.length - 1];
1660
- if (first === void 0 || last === void 0 || last.t === first.t) return 0;
1661
- return (last.y - first.y) / (last.t - first.t);
1504
+ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading = false, asChild = false, disabled, className, children, type, ...props }, ref) {
1505
+ const classes = cn(buttonClassName({ variant, size }), className);
1506
+ const glyph = loading ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
1507
+ const inactive = (disabled ?? false) || loading;
1508
+ if (asChild) {
1509
+ const child = Children.only(children);
1510
+ if (!isValidElement(child)) return null;
1511
+ const own = child.props;
1512
+ return cloneElement(child, {
1513
+ ...props,
1514
+ ref,
1515
+ className: cn(classes, own.className),
1516
+ "aria-busy": loading || void 0,
1517
+ "aria-disabled": inactive || void 0,
1518
+ // A disabled link keeps its focus (so it can be reached and explained) but goes nowhere.
1519
+ onClick: (event) => {
1520
+ if (inactive) {
1521
+ event.preventDefault();
1522
+ return;
1523
+ }
1524
+ own.onClick?.(event);
1525
+ props.onClick?.(event);
1526
+ },
1527
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [
1528
+ glyph,
1529
+ own.children
1530
+ ] })
1531
+ });
1662
1532
  }
1663
- };
1664
- function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
1665
- if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
1666
- if (Math.abs(dx) > Math.abs(dy)) return "scroll";
1667
- if (zone === "grab") return "drag";
1668
- if (dy > 0 && scrollTop <= 0) return "drag";
1669
- if (dy < 0 && canGrow) return "drag";
1670
- return "scroll";
1533
+ return /* @__PURE__ */ jsxs(
1534
+ "button",
1535
+ {
1536
+ ref,
1537
+ type: type ?? "button",
1538
+ className: classes,
1539
+ disabled: inactive,
1540
+ "aria-busy": loading || void 0,
1541
+ ...props,
1542
+ children: [
1543
+ glyph,
1544
+ children
1545
+ ]
1546
+ }
1547
+ );
1548
+ });
1549
+ var TABBABLE = [
1550
+ "a[href]",
1551
+ "area[href]",
1552
+ "button:not([disabled])",
1553
+ 'input:not([disabled]):not([type="hidden"])',
1554
+ "select:not([disabled])",
1555
+ "textarea:not([disabled])",
1556
+ "iframe",
1557
+ "audio[controls]",
1558
+ "video[controls]",
1559
+ '[contenteditable]:not([contenteditable="false"])',
1560
+ '[tabindex]:not([tabindex="-1"])'
1561
+ ].join(",");
1562
+ function tabbables(root) {
1563
+ const all = Array.from(root.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 && element.closest("[hidden], [inert]") === null);
1564
+ const checkedGroups = new Set(all.filter((element) => element instanceof HTMLInputElement && element.type === "radio" && element.checked).map((element) => element.name));
1565
+ const seen = /* @__PURE__ */ new Set();
1566
+ return all.filter((element) => {
1567
+ if (!(element instanceof HTMLInputElement) || element.type !== "radio" || element.name === "") return true;
1568
+ if (checkedGroups.has(element.name)) return element.checked;
1569
+ if (seen.has(element.name)) return false;
1570
+ seen.add(element.name);
1571
+ return true;
1572
+ });
1671
1573
  }
1672
- var EASE = "cubic-bezier(.2, .9, .25, 1)";
1574
+ var DialogContext = createContext(null);
1575
+ function useDialogClose() {
1576
+ const close = useContext(DialogContext);
1577
+ return close ?? (() => void 0);
1578
+ }
1579
+ function DialogClose({ onClick, ...props }) {
1580
+ const close = useDialogClose();
1581
+ return /* @__PURE__ */ jsx(
1582
+ Button,
1583
+ {
1584
+ ...props,
1585
+ onClick: (event) => {
1586
+ onClick?.(event);
1587
+ if (!event.defaultPrevented) close();
1588
+ }
1589
+ }
1590
+ );
1591
+ }
1592
+ var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect : useLayoutEffect;
1593
+ function Dialog({ open, onOpenChange, title, description, footer, size = "md", dismissible = true, className, children }) {
1594
+ const { t } = useCboxLocalization();
1595
+ const id = useId();
1596
+ const titleId = `${id}-title`;
1597
+ const descriptionId = `${id}-description`;
1598
+ const layer = useRef(null);
1599
+ const panel = useRef(null);
1600
+ const closeButton = useRef(null);
1601
+ const body = useRef(null);
1602
+ const returnTo = useRef(null);
1603
+ const wasOpen = useRef(false);
1604
+ const pressedOnScrim = useRef(false);
1605
+ if (open && !wasOpen.current && typeof document !== "undefined") {
1606
+ const active = document.activeElement;
1607
+ returnTo.current = active instanceof HTMLElement && active !== document.body ? active : null;
1608
+ }
1609
+ wasOpen.current = open;
1610
+ const close = useCallback(() => onOpenChange(false), [onOpenChange]);
1611
+ useScrollLock(open);
1612
+ useIsoLayoutEffect2(() => {
1613
+ if (!open || layer.current === null) return;
1614
+ const own = layer.current;
1615
+ const made = [];
1616
+ for (const sibling of Array.from(document.body.children)) {
1617
+ if (sibling === own || !(sibling instanceof HTMLElement) || sibling.hasAttribute("inert")) continue;
1618
+ if (sibling.tagName === "SCRIPT" || sibling.tagName === "STYLE") continue;
1619
+ sibling.setAttribute("inert", "");
1620
+ made.push(sibling);
1621
+ }
1622
+ return () => {
1623
+ for (const element of made) element.removeAttribute("inert");
1624
+ };
1625
+ }, [open]);
1626
+ useIsoLayoutEffect2(() => {
1627
+ if (!open || panel.current === null) return;
1628
+ const root = panel.current;
1629
+ if (root.contains(document.activeElement)) return;
1630
+ const marked = root.querySelector("[data-autofocus]");
1631
+ const field = body.current?.querySelector('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled]), [role="combobox"]');
1632
+ (marked ?? field ?? closeButton.current ?? root).focus({ preventScroll: true });
1633
+ }, [open]);
1634
+ useEffect(() => {
1635
+ if (!open) return;
1636
+ const onFocusIn = (event) => {
1637
+ const root = panel.current;
1638
+ const target = event.target;
1639
+ if (root === null || !(target instanceof Node) || root.contains(target)) return;
1640
+ if (target instanceof Element && target.closest("[data-cbx-dialog-layer]") !== null) return;
1641
+ (tabbables(root)[0] ?? root).focus({ preventScroll: true });
1642
+ };
1643
+ document.addEventListener("focusin", onFocusIn);
1644
+ return () => document.removeEventListener("focusin", onFocusIn);
1645
+ }, [open]);
1646
+ useEffect(() => {
1647
+ if (!open) return;
1648
+ return () => {
1649
+ const target = returnTo.current;
1650
+ if (target !== null && target.isConnected) target.focus({ preventScroll: true });
1651
+ };
1652
+ }, [open]);
1653
+ const onKeyDown = (event) => {
1654
+ if (event.defaultPrevented) return;
1655
+ if (event.key === "Escape") {
1656
+ event.preventDefault();
1657
+ event.stopPropagation();
1658
+ close();
1659
+ return;
1660
+ }
1661
+ if (event.key !== "Tab" || panel.current === null) return;
1662
+ const items = tabbables(panel.current);
1663
+ const first = items[0];
1664
+ const last = items[items.length - 1];
1665
+ if (first === void 0 || last === void 0) {
1666
+ event.preventDefault();
1667
+ panel.current.focus({ preventScroll: true });
1668
+ return;
1669
+ }
1670
+ const active = document.activeElement;
1671
+ if (event.shiftKey && (active === first || active === panel.current)) {
1672
+ event.preventDefault();
1673
+ last.focus();
1674
+ } else if (!event.shiftKey && active === last) {
1675
+ event.preventDefault();
1676
+ first.focus();
1677
+ }
1678
+ };
1679
+ if (!open || typeof document === "undefined") return null;
1680
+ const onScrimDown = (event) => {
1681
+ pressedOnScrim.current = event.target === event.currentTarget;
1682
+ };
1683
+ const onScrimClick = (event) => {
1684
+ if (dismissible && pressedOnScrim.current && event.target === event.currentTarget) close();
1685
+ pressedOnScrim.current = false;
1686
+ };
1687
+ return createPortal(
1688
+ /* @__PURE__ */ jsx(DialogContext.Provider, { value: close, children: /* @__PURE__ */ jsxs("div", { ref: layer, "data-cbx-scroll-layer": "", "data-cbx-dialog-layer": "", children: [
1689
+ /* @__PURE__ */ jsx("div", { className: "cbx-ui-overlay", "aria-hidden": "true", onMouseDown: onScrimDown, onClick: onScrimClick }),
1690
+ /* @__PURE__ */ jsxs(
1691
+ "div",
1692
+ {
1693
+ ref: panel,
1694
+ role: "dialog",
1695
+ "aria-modal": "true",
1696
+ "aria-labelledby": titleId,
1697
+ "aria-describedby": description !== void 0 ? descriptionId : void 0,
1698
+ tabIndex: -1,
1699
+ className: cn("cbx-ui-dialog", `cbx-ui-dialog--${size}`, className),
1700
+ onKeyDown,
1701
+ children: [
1702
+ /* @__PURE__ */ jsxs("div", { className: "cbx-ui-dialog-head", children: [
1703
+ /* @__PURE__ */ jsxs("div", { className: "cbx-ui-dialog-heading", children: [
1704
+ /* @__PURE__ */ jsx("h2", { id: titleId, className: "cbx-ui-dialog-title", children: title }),
1705
+ description !== void 0 && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "cbx-ui-dialog-desc", children: description })
1706
+ ] }),
1707
+ /* @__PURE__ */ jsx("button", { ref: closeButton, type: "button", className: "cbx-ui-iconbtn", "aria-label": t("Close"), onClick: close, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) }) })
1708
+ ] }),
1709
+ children !== void 0 && children !== null && /* @__PURE__ */ jsx("div", { ref: body, className: "cbx-ui-dialog-body", children }),
1710
+ footer !== void 0 && footer !== null && /* @__PURE__ */ jsx("div", { className: "cbx-ui-dialog-foot", children: footer })
1711
+ ]
1712
+ }
1713
+ )
1714
+ ] }) }),
1715
+ document.body
1716
+ );
1717
+ }
1718
+ var SHELL_ICONS = {
1719
+ activity: Activity,
1720
+ "bar-chart": BarChart3,
1721
+ bell: Bell,
1722
+ "book-open": BookOpen,
1723
+ boxes: Boxes,
1724
+ briefcase: Briefcase,
1725
+ building: Building2,
1726
+ calendar: Calendar,
1727
+ clock: Clock,
1728
+ cloud: Cloud,
1729
+ code: Code,
1730
+ "credit-card": CreditCard,
1731
+ database: Database,
1732
+ "file-text": FileText,
1733
+ folder: Folder,
1734
+ "git-branch": GitBranch,
1735
+ globe: Globe,
1736
+ "hard-drive": HardDrive,
1737
+ home: Home,
1738
+ inbox: Inbox,
1739
+ key: Key,
1740
+ "layout-dashboard": LayoutDashboard,
1741
+ "layout-grid": LayoutGrid,
1742
+ layers: Layers,
1743
+ "life-buoy": LifeBuoy,
1744
+ list: List,
1745
+ lock: Lock,
1746
+ mail: Mail,
1747
+ "message-square": MessageSquare,
1748
+ network: Network,
1749
+ package: Package,
1750
+ percent: Percent,
1751
+ plug: Plug,
1752
+ receipt: Receipt,
1753
+ rocket: Rocket,
1754
+ search: Search,
1755
+ send: Send,
1756
+ server: Server,
1757
+ settings: Settings,
1758
+ shield: Shield,
1759
+ "shield-check": ShieldCheck,
1760
+ sparkles: Sparkles,
1761
+ tag: Tag,
1762
+ timer: Timer,
1763
+ users: Users,
1764
+ wallet: Wallet,
1765
+ webhook: Webhook,
1766
+ zap: Zap
1767
+ };
1768
+ function resolveIcon(name, extra = {}) {
1769
+ if (name === void 0) return Circle;
1770
+ return extra[name] ?? SHELL_ICONS[name] ?? Circle;
1771
+ }
1772
+
1773
+ // src/shell/help-store.ts
1774
+ var INITIAL_HELP_STATE = {
1775
+ open: false,
1776
+ article: null,
1777
+ query: "",
1778
+ scrollTop: 0,
1779
+ updates: [],
1780
+ updatesStatus: "idle",
1781
+ pendingQuestion: null,
1782
+ seeded: false,
1783
+ restored: false,
1784
+ updatesKey: null
1785
+ };
1786
+ function helpVisible(state, docked) {
1787
+ return state.open && (docked || !state.restored);
1788
+ }
1789
+ function createHelpStore(initial = {}) {
1790
+ let state = { ...INITIAL_HELP_STATE, ...initial };
1791
+ const listeners = /* @__PURE__ */ new Set();
1792
+ return {
1793
+ get: () => state,
1794
+ set(patch) {
1795
+ const next = typeof patch === "function" ? patch(state) : patch;
1796
+ state = { ...state, ...next };
1797
+ listeners.forEach((listener) => listener());
1798
+ },
1799
+ subscribe(listener) {
1800
+ listeners.add(listener);
1801
+ return () => listeners.delete(listener);
1802
+ }
1803
+ };
1804
+ }
1805
+ var browserStore = null;
1806
+ function sharedHelpStore() {
1807
+ if (typeof window === "undefined") return createHelpStore();
1808
+ browserStore ??= createHelpStore();
1809
+ return browserStore;
1810
+ }
1811
+ function parseUpdates(body) {
1812
+ const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
1813
+ return rows2.flatMap((value) => {
1814
+ if (typeof value !== "object" || value === null) return [];
1815
+ const row = value;
1816
+ if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
1817
+ const update = {
1818
+ id: String(row.id),
1819
+ kind: row.kind === "chat" ? "chat" : "ticket",
1820
+ title: row.title,
1821
+ unread: row.unread === true || row.read === false || row.read_at === null && row.unread !== false
1822
+ };
1823
+ if (typeof row.excerpt === "string") update.excerpt = row.excerpt;
1824
+ const at = row.at ?? row.updated_at ?? row.created_at;
1825
+ if (typeof at === "string") update.at = at;
1826
+ const url = safeUrl(row.url);
1827
+ if (url !== void 0) update.url = url;
1828
+ return [update];
1829
+ });
1830
+ }
1831
+ function parseArticles(body) {
1832
+ const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
1833
+ return rows2.flatMap((value) => {
1834
+ if (typeof value !== "object" || value === null) return [];
1835
+ const row = value;
1836
+ if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
1837
+ const article = { id: String(row.id), title: row.title };
1838
+ if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
1839
+ if (typeof row.body === "string") article.body = row.body;
1840
+ const url = safeUrl(row.url);
1841
+ if (url !== void 0) article.url = url;
1842
+ if (typeof row.source === "string") article.source = row.source;
1843
+ return [article];
1844
+ });
1845
+ }
1846
+ var LARGE = 0.92;
1847
+ var MEDIUM = 0.5;
1848
+ function sheetDetents({ size, viewport, current, content }) {
1849
+ const large = Math.round(viewport * LARGE);
1850
+ const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
1851
+ const sorted = heights.map(Math.round).sort((a, b) => a - b);
1852
+ const detents = [];
1853
+ for (const height of sorted) {
1854
+ const last = detents[detents.length - 1];
1855
+ if (last === void 0 || height - last >= 48) detents.push(height);
1856
+ else if (height === Math.round(current)) detents[detents.length - 1] = height;
1857
+ }
1858
+ return detents;
1859
+ }
1860
+ function rubberBand(overshoot, limit = 120) {
1861
+ if (overshoot <= 0) return 0;
1862
+ return limit * (1 - 1 / (overshoot / limit + 1));
1863
+ }
1864
+ function settleSheet({ height, velocity, detents }) {
1865
+ const smallest = detents[0] ?? height;
1866
+ const below = smallest - height;
1867
+ if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
1868
+ const projected = height - velocity * 200;
1869
+ let best = smallest;
1870
+ for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
1871
+ return { close: false, height: best };
1872
+ }
1873
+ var VelocityTracker = class {
1874
+ samples = [];
1875
+ add(t, y) {
1876
+ this.samples.push({ t, y });
1877
+ while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
1878
+ }
1879
+ velocity() {
1880
+ const first = this.samples[0];
1881
+ const last = this.samples[this.samples.length - 1];
1882
+ if (first === void 0 || last === void 0 || last.t === first.t) return 0;
1883
+ return (last.y - first.y) / (last.t - first.t);
1884
+ }
1885
+ };
1886
+ function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
1887
+ if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
1888
+ if (Math.abs(dx) > Math.abs(dy)) return "scroll";
1889
+ if (zone === "grab") return "drag";
1890
+ if (dy > 0 && scrollTop <= 0) return "drag";
1891
+ if (dy < 0 && canGrow) return "drag";
1892
+ return "scroll";
1893
+ }
1894
+ var EASE = "cubic-bezier(.2, .9, .25, 1)";
1673
1895
  var DURATION = 280;
1674
1896
  var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
1675
1897
  var GRAB_FIELD = '.cbx-sheet-grab :is(input[type="search"], input[type="text"], input:not([type]))';
@@ -1798,7 +2020,14 @@ function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
1798
2020
  closing = true;
1799
2021
  sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
1800
2022
  setScrim(0);
1801
- timer = setTimeout(() => close.current(), reducedMotion() ? 0 : DURATION - 40);
2023
+ timer = setTimeout(() => {
2024
+ if (close.current() === false) {
2025
+ closing = false;
2026
+ sheet.style.height = `${done.start}px`;
2027
+ sheet.style.transform = "";
2028
+ setScrim(1);
2029
+ }
2030
+ }, reducedMotion() ? 0 : DURATION - 40);
1802
2031
  return;
1803
2032
  }
1804
2033
  if (natural !== null && result.height === natural) {
@@ -2866,6 +3095,7 @@ function Sheet({
2866
3095
  label,
2867
3096
  side = "bottom",
2868
3097
  onClose,
3098
+ onEscape,
2869
3099
  children,
2870
3100
  title,
2871
3101
  back,
@@ -2898,7 +3128,7 @@ function Sheet({
2898
3128
  onKeyDown: (event) => {
2899
3129
  if (event.key === "Escape" && !event.defaultPrevented) {
2900
3130
  event.preventDefault();
2901
- onClose();
3131
+ (onEscape ?? onClose)();
2902
3132
  }
2903
3133
  trapTab(event, panel.current);
2904
3134
  },
@@ -2931,12 +3161,29 @@ function createLabel(shell, t) {
2931
3161
  function CreateSheet({ onClose }) {
2932
3162
  const { shell, t, mobile, createKey, renderCreate } = useShell();
2933
3163
  const [stack, setStack] = useState(() => findCreatable(shell, createKey) !== void 0 ? [{ kind: "tree" }, { kind: "form", key: createKey }] : [{ kind: "tree" }]);
3164
+ const guards = useRef(/* @__PURE__ */ new Map());
3165
+ const [leaving, setLeaving] = useState(null);
2934
3166
  const top = stack[stack.length - 1];
2935
3167
  const below = stack.length > 1 ? stack[stack.length - 2] : null;
2936
3168
  const environmentLevelItem = environmentLevel(shell.context.levels)?.current ?? null;
2937
3169
  const notLive = environmentLevelItem !== null && isLive(environmentLevelItem) === false;
2938
3170
  const name = (entry) => entry === null ? "" : entry.kind === "tree" ? t("Create") : findCreatable(shell, entry.key)?.label ?? entry.key;
2939
- const pop = () => setStack((current) => current.length > 1 ? current.slice(0, -1) : current);
3171
+ const pop = () => {
3172
+ guards.current.delete(top);
3173
+ setStack((current) => current.length > 1 ? current.slice(0, -1) : current);
3174
+ if (top.kind === "form") requestAnimationFrame(() => top.returnFocus?.focus());
3175
+ };
3176
+ const leave = (scope) => {
3177
+ const entries = scope === "all" ? stack : [top];
3178
+ if (entries.some((entry) => guards.current.get(entry)?.busy)) return false;
3179
+ if (entries.some((entry) => guards.current.get(entry)?.dirty)) {
3180
+ setLeaving(scope);
3181
+ return false;
3182
+ }
3183
+ if (scope === "all" || below === null) onClose();
3184
+ else pop();
3185
+ return true;
3186
+ };
2940
3187
  const title = top.kind === "tree" ? t("Create") : t("New {thing}", { thing: name(top).toLowerCase() });
2941
3188
  return /* @__PURE__ */ jsxs(
2942
3189
  Sheet,
@@ -2944,9 +3191,10 @@ function CreateSheet({ onClose }) {
2944
3191
  label: title,
2945
3192
  side: mobile ? "bottom" : "right",
2946
3193
  size: "tall",
2947
- onClose,
3194
+ onClose: () => leave("all"),
3195
+ onEscape: () => leave("top"),
2948
3196
  className: "cbx-create-sheet",
2949
- back: below !== null ? { label: t("Back to {thing}", { thing: name(below) }), text: name(below), onBack: pop } : void 0,
3197
+ back: below !== null ? { label: t("Back to {thing}", { thing: name(below) }), text: name(below), onBack: () => leave("top") } : void 0,
2950
3198
  children: [
2951
3199
  top.kind === "tree" && /* @__PURE__ */ jsx(CreateTree, { onPick: (key) => setStack([{ kind: "tree" }, { kind: "form", key }]) }),
2952
3200
  notLive && top.kind === "form" && /* @__PURE__ */ jsxs("p", { className: "cbx-create-env", role: "note", children: [
@@ -2965,7 +3213,8 @@ function CreateSheet({ onClose }) {
2965
3213
  submitLabel: parent !== null ? t("Create and use in {thing}", { thing: parent.label.toLowerCase() }) : creatable.submitLabel ?? t("Create {thing}", { thing: creatable.label.toLowerCase() }),
2966
3214
  createRef: (key, onCreated) => {
2967
3215
  if (findCreatable(shell, key) === void 0) return;
2968
- setStack((current) => [...current.slice(0, index + 1), { kind: "form", key, onCreated }]);
3216
+ const returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : void 0;
3217
+ setStack((current) => [...current.slice(0, index + 1), { kind: "form", key, onCreated, returnFocus }]);
2969
3218
  },
2970
3219
  done: (created) => {
2971
3220
  if (parent === null) {
@@ -2975,12 +3224,33 @@ function CreateSheet({ onClose }) {
2975
3224
  setStack((current) => current.slice(0, index));
2976
3225
  if (created !== void 0) entry.onCreated?.(created);
2977
3226
  },
2978
- close: onClose,
3227
+ close: () => leave("all"),
3228
+ setDirty: (dirty) => guards.current.set(entry, { dirty, busy: guards.current.get(entry)?.busy ?? false }),
3229
+ setBusy: (busy) => guards.current.set(entry, { busy, dirty: guards.current.get(entry)?.dirty ?? false }),
2979
3230
  environment: environmentLevelItem
2980
3231
  };
2981
3232
  const body = renderCreate?.(form) ?? null;
2982
3233
  return /* @__PURE__ */ jsx("div", { className: "cbx-create-form", hidden: entry !== top, children: body ?? /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: t("{thing} cannot be created here yet.", { thing: creatable.label }) }) }, `${index}:${entry.key}`);
2983
- })
3234
+ }),
3235
+ /* @__PURE__ */ jsx(
3236
+ Dialog,
3237
+ {
3238
+ open: leaving !== null,
3239
+ onOpenChange: (open) => {
3240
+ if (!open) setLeaving(null);
3241
+ },
3242
+ title: leaving === "all" ? t("Discard this creation flow?") : t("Discard {thing}?", { thing: name(top).toLowerCase() }),
3243
+ description: leaving === "all" ? t("Unsaved entries in every task will be lost.") : t("Only this task is discarded. The task underneath keeps its values."),
3244
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
3245
+ /* @__PURE__ */ jsx(Button, { onClick: () => setLeaving(null), children: t("Keep editing") }),
3246
+ /* @__PURE__ */ jsx(Button, { variant: "danger", onClick: () => {
3247
+ if (leaving === "all" || below === null) onClose();
3248
+ else pop();
3249
+ setLeaving(null);
3250
+ }, children: t("Discard") })
3251
+ ] })
3252
+ }
3253
+ )
2984
3254
  ]
2985
3255
  }
2986
3256
  );
@@ -3040,15 +3310,277 @@ function CreateRefField({ label, value, placeholder, thing, onChoose, onCreate }
3040
3310
  ] })
3041
3311
  ] });
3042
3312
  }
3043
- function CreateSubmit({ form, busy = false, disabled = false }) {
3044
- const { t } = useShell();
3045
- return /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-button cbx-button-primary cbx-create-submit", disabled: busy || disabled, children: busy ? t("Creating\u2026") : form.submitLabel });
3313
+ function CreateSubmit({ form, busy = false, disabled = false }) {
3314
+ const { t } = useShell();
3315
+ return /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-button cbx-button-primary cbx-create-submit", disabled: busy || disabled, children: busy ? t("Creating\u2026") : form.submitLabel });
3316
+ }
3317
+ function CreateForm({ onSubmit, children }) {
3318
+ return /* @__PURE__ */ jsx("form", { className: "cbx-cform", onSubmit: (event) => {
3319
+ event.preventDefault();
3320
+ onSubmit(event);
3321
+ }, children });
3322
+ }
3323
+ var DefaultLink = ({ href, className, children, "aria-current": ariaCurrent }) => /* @__PURE__ */ jsx("a", { href, className, "aria-current": ariaCurrent, children });
3324
+ function PageTabs({
3325
+ items,
3326
+ currentPath,
3327
+ LinkComponent = DefaultLink,
3328
+ actions,
3329
+ className
3330
+ }) {
3331
+ const activeHref = resolveActiveHref(items, currentPath);
3332
+ return /* @__PURE__ */ jsxs(
3333
+ "div",
3334
+ {
3335
+ "data-component": "page-tabs",
3336
+ className: cn(
3337
+ // Card-style chrome — same border, radius, bg as DataPanel
3338
+ // so the tab strip reads as a peer of the content panels
3339
+ // beneath it instead of floating on the page background.
3340
+ // Width matches PageShell content; no sticky positioning.
3341
+ "cbx-page-tabs @container/tabs min-w-0 rounded-lg border border-border bg-card",
3342
+ className
3343
+ ),
3344
+ children: [
3345
+ /* @__PURE__ */ jsxs("div", { className: "cbx-page-tabs-desktop hidden items-end gap-3 px-3 @min-[56rem]/tabs:flex", children: [
3346
+ /* @__PURE__ */ jsx(
3347
+ DesktopStrip,
3348
+ {
3349
+ items,
3350
+ activeHref,
3351
+ LinkComponent
3352
+ }
3353
+ ),
3354
+ /* @__PURE__ */ jsx("div", { className: "flex min-h-12 shrink-0 items-center gap-2", children: actions })
3355
+ ] }),
3356
+ /* @__PURE__ */ jsxs("div", { className: "cbx-page-tabs-mobile flex flex-col gap-2 p-2 @min-[56rem]/tabs:hidden", children: [
3357
+ /* @__PURE__ */ jsx(
3358
+ MobileDropdown,
3359
+ {
3360
+ items,
3361
+ activeHref,
3362
+ LinkComponent
3363
+ }
3364
+ ),
3365
+ actions !== void 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions }) : null
3366
+ ] })
3367
+ ]
3368
+ }
3369
+ );
3370
+ }
3371
+ function DesktopStrip({ items, activeHref, LinkComponent }) {
3372
+ const { t } = useCboxLocalization();
3373
+ return /* @__PURE__ */ jsx(
3374
+ "nav",
3375
+ {
3376
+ className: "flex min-h-12 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden py-1.5",
3377
+ "aria-label": t("Section navigation"),
3378
+ children: items.map((item) => {
3379
+ const Icon = item.icon;
3380
+ const active = item.href === activeHref;
3381
+ return /* @__PURE__ */ jsxs(
3382
+ LinkComponent,
3383
+ {
3384
+ href: item.href,
3385
+ prefetch: true,
3386
+ "aria-current": active ? "page" : void 0,
3387
+ className: cn(
3388
+ "inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 text-[13px] whitespace-nowrap transition-colors",
3389
+ active ? "bg-secondary font-semibold text-foreground shadow-sm ring-1 ring-border-strong/60" : "text-muted-foreground hover:bg-secondary/60 hover:text-foreground"
3390
+ ),
3391
+ children: [
3392
+ Icon !== void 0 ? /* @__PURE__ */ jsx(
3393
+ Icon,
3394
+ {
3395
+ className: cn(
3396
+ "h-3.5 w-3.5 shrink-0",
3397
+ active ? "text-foreground" : "text-muted-foreground"
3398
+ ),
3399
+ strokeWidth: 1.7
3400
+ }
3401
+ ) : null,
3402
+ /* @__PURE__ */ jsx("span", { children: item.label }),
3403
+ /* @__PURE__ */ jsx(ItemTrailing, { item, active })
3404
+ ]
3405
+ },
3406
+ item.href
3407
+ );
3408
+ })
3409
+ }
3410
+ );
3411
+ }
3412
+ function MobileDropdown({ items, activeHref, LinkComponent }) {
3413
+ const { t } = useCboxLocalization();
3414
+ const [open, setOpen] = useState(false);
3415
+ const ref = useRef(null);
3416
+ const trigger = useRef(null);
3417
+ const listId = useId();
3418
+ const active = items.find((item) => item.href === activeHref) ?? items[0];
3419
+ useEffect(() => setOpen(false), [activeHref]);
3420
+ useEffect(() => {
3421
+ if (!open) return;
3422
+ function onPointerDown(event) {
3423
+ if (ref.current !== null && !ref.current.contains(event.target)) {
3424
+ setOpen(false);
3425
+ }
3426
+ }
3427
+ function onKey(event) {
3428
+ if (event.key === "Escape") {
3429
+ event.preventDefault();
3430
+ setOpen(false);
3431
+ trigger.current?.focus();
3432
+ }
3433
+ }
3434
+ window.addEventListener("pointerdown", onPointerDown);
3435
+ window.addEventListener("keydown", onKey);
3436
+ return () => {
3437
+ window.removeEventListener("pointerdown", onPointerDown);
3438
+ window.removeEventListener("keydown", onKey);
3439
+ };
3440
+ }, [open]);
3441
+ if (active === void 0) {
3442
+ return null;
3443
+ }
3444
+ const ActiveIcon = active.icon;
3445
+ return /* @__PURE__ */ jsxs("div", { ref, className: "cbx-page-tabs-dropdown relative", children: [
3446
+ /* @__PURE__ */ jsxs(
3447
+ "button",
3448
+ {
3449
+ ref: trigger,
3450
+ type: "button",
3451
+ onClick: () => setOpen((v) => !v),
3452
+ "aria-expanded": open,
3453
+ "aria-controls": listId,
3454
+ className: cn(
3455
+ "cbx-ui-page-tab-trigger flex w-full min-h-11 items-center justify-between gap-2 rounded-md border border-border bg-card px-3 text-left text-[13px] font-medium text-foreground transition-colors hover:border-border-strong",
3456
+ open && "border-border-strong ring-2 ring-ring/30"
3457
+ ),
3458
+ children: [
3459
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
3460
+ ActiveIcon !== void 0 ? /* @__PURE__ */ jsx(
3461
+ ActiveIcon,
3462
+ {
3463
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground",
3464
+ strokeWidth: 1.7
3465
+ }
3466
+ ) : null,
3467
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: active.label }),
3468
+ /* @__PURE__ */ jsx(ItemTrailing, { item: active, active: true })
3469
+ ] }),
3470
+ /* @__PURE__ */ jsx(Chevron, { open })
3471
+ ]
3472
+ }
3473
+ ),
3474
+ open ? /* @__PURE__ */ jsx(
3475
+ "ul",
3476
+ {
3477
+ id: listId,
3478
+ "aria-label": t("Section navigation"),
3479
+ onClick: (event) => {
3480
+ if (event.target.closest("a")) setOpen(false);
3481
+ },
3482
+ className: "absolute left-0 right-0 top-full z-30 mt-1 max-h-[60dvh] overflow-y-auto rounded-md border border-border bg-popover shadow-lg",
3483
+ children: items.map((item) => {
3484
+ const Icon = item.icon;
3485
+ const isActive = item.href === activeHref;
3486
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
3487
+ LinkComponent,
3488
+ {
3489
+ href: item.href,
3490
+ prefetch: true,
3491
+ "aria-current": isActive ? "page" : void 0,
3492
+ className: cn(
3493
+ "flex w-full items-center gap-2 px-3 py-2.5 text-[13px] transition-colors",
3494
+ isActive ? "bg-accent-soft font-semibold text-foreground" : "text-muted-foreground hover:bg-secondary hover:text-foreground"
3495
+ ),
3496
+ children: [
3497
+ Icon !== void 0 ? /* @__PURE__ */ jsx(
3498
+ Icon,
3499
+ {
3500
+ className: cn(
3501
+ "h-3.5 w-3.5 shrink-0",
3502
+ isActive ? "text-foreground" : "text-muted-foreground"
3503
+ ),
3504
+ strokeWidth: 1.7
3505
+ }
3506
+ ) : null,
3507
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 break-words", children: item.label }),
3508
+ /* @__PURE__ */ jsx(
3509
+ ItemTrailing,
3510
+ {
3511
+ item,
3512
+ active: isActive
3513
+ }
3514
+ )
3515
+ ]
3516
+ }
3517
+ ) }, item.href);
3518
+ })
3519
+ }
3520
+ ) : null
3521
+ ] });
3522
+ }
3523
+ function ItemTrailing({
3524
+ item,
3525
+ active
3526
+ }) {
3527
+ if (item.badge !== void 0) {
3528
+ return /* @__PURE__ */ jsx("span", { className: "ml-1 shrink-0", children: item.badge });
3529
+ }
3530
+ if (item.count !== void 0) {
3531
+ return /* @__PURE__ */ jsx(
3532
+ "span",
3533
+ {
3534
+ className: cn(
3535
+ "ml-1 shrink-0 rounded-sm border px-1 text-[10px] font-semibold tracking-tight tabular-nums",
3536
+ active ? "border-border-strong bg-secondary text-foreground" : "border-border bg-secondary/60 text-muted-foreground"
3537
+ ),
3538
+ children: item.count
3539
+ }
3540
+ );
3541
+ }
3542
+ return null;
3543
+ }
3544
+ function Chevron({ open }) {
3545
+ return /* @__PURE__ */ jsx(
3546
+ "svg",
3547
+ {
3548
+ width: "14",
3549
+ height: "14",
3550
+ viewBox: "0 0 14 14",
3551
+ fill: "none",
3552
+ stroke: "currentColor",
3553
+ strokeWidth: "1.6",
3554
+ strokeLinecap: "round",
3555
+ strokeLinejoin: "round",
3556
+ className: cn(
3557
+ "shrink-0 text-muted-foreground transition-transform duration-150",
3558
+ open && "rotate-180"
3559
+ ),
3560
+ "aria-hidden": true,
3561
+ children: /* @__PURE__ */ jsx("path", { d: "m3.5 5.5 3.5 3.5 3.5-3.5" })
3562
+ }
3563
+ );
3564
+ }
3565
+ function pathOnly(href) {
3566
+ const queryIndex = href.indexOf("?");
3567
+ const hashIndex = href.indexOf("#");
3568
+ let end = href.length;
3569
+ if (queryIndex !== -1) end = Math.min(end, queryIndex);
3570
+ if (hashIndex !== -1) end = Math.min(end, hashIndex);
3571
+ return href.slice(0, end);
3046
3572
  }
3047
- function CreateForm({ onSubmit, children }) {
3048
- return /* @__PURE__ */ jsx("form", { className: "cbx-cform", onSubmit: (event) => {
3049
- event.preventDefault();
3050
- onSubmit(event);
3051
- }, children });
3573
+ function resolveActiveHref(items, currentPath) {
3574
+ const current = pathOnly(currentPath);
3575
+ const candidates = items.map((item) => {
3576
+ const itemPath = pathOnly(item.href);
3577
+ const matched = item.matchPrefix === true ? current === itemPath || current.startsWith(itemPath + "/") : current === itemPath;
3578
+ return matched ? item.href : null;
3579
+ }).filter((href) => href !== null);
3580
+ if (candidates.length === 0) return null;
3581
+ return candidates.reduce(
3582
+ (longest, href) => href.length > longest.length ? href : longest
3583
+ );
3052
3584
  }
3053
3585
  var MAX_TABS = 4;
3054
3586
  function tabAreas(areas, tabs) {
@@ -3069,7 +3601,8 @@ function useUnread() {
3069
3601
  return useUnreadCount(help, shell.help.unread);
3070
3602
  }
3071
3603
  function MobileTopBar() {
3072
- const { shell, t, openContext, toggleHelp, setOverlay, openCreate, canCreate } = useShell();
3604
+ const { shell, t, openContext, toggleHelp, setOverlay, openCreate, canCreate, overlay } = useShell();
3605
+ const apps = useRef(null);
3073
3606
  const levels = shell.context.levels;
3074
3607
  const organization = levels[0];
3075
3608
  const { top, main } = pillLines(levels);
@@ -3094,6 +3627,8 @@ function MobileTopBar() {
3094
3627
  unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-m-dot", "aria-hidden": "true" })
3095
3628
  ] }),
3096
3629
  /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-m-icon", onClick: () => setOverlay("palette"), "aria-label": t("Search and commands"), "aria-haspopup": "dialog", children: /* @__PURE__ */ jsx(Search, { size: 21, strokeWidth: 1.8, "aria-hidden": true }) }),
3630
+ /* @__PURE__ */ jsx("button", { ref: apps, type: "button", className: "cbx-m-icon", onClick: () => setOverlay(overlay === "apps" ? null : "apps"), "aria-label": t("Switch app"), "aria-haspopup": "dialog", "aria-expanded": overlay === "apps", children: /* @__PURE__ */ jsx(LayoutGrid, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
3631
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "apps", anchor: apps, placement: "bottom-end", label: t("Switch app"), onClose: () => setOverlay(null), children: /* @__PURE__ */ jsx(AppGrid, {}) }),
3097
3632
  canCreate && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-m-icon is-primary", onClick: () => openCreate(), "aria-haspopup": "dialog", "aria-label": createLabel(shell, t), children: /* @__PURE__ */ jsx(Plus, { size: 22, strokeWidth: 2, "aria-hidden": true }) })
3098
3633
  ] });
3099
3634
  }
@@ -3102,27 +3637,12 @@ function MobileAreaHead() {
3102
3637
  const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
3103
3638
  const pages = area?.pages ?? [];
3104
3639
  const environment = notLiveEnvironment(shell.context.levels);
3105
- const strip = useRef(null);
3106
- useEffect(() => {
3107
- const list = strip.current;
3108
- const current = list?.querySelector('[aria-current="page"]');
3109
- if (list === null || list === void 0 || current === null || current === void 0) return;
3110
- const overflow = current.offsetLeft + current.offsetWidth - list.clientWidth;
3111
- if (overflow > 0) list.scrollLeft = overflow + 32;
3112
- }, [shell.nav.activePage, shell.nav.activeArea]);
3113
3640
  return /* @__PURE__ */ jsxs("div", { className: "cbx-m-head", children: [
3114
- area !== void 0 && /* @__PURE__ */ jsx("p", { className: "cbx-m-title", children: area.label }),
3115
3641
  environment !== null && /* @__PURE__ */ jsxs("div", { className: `cbx-m-env cbx-env-${environment.tone ?? "neutral"}`, role: "status", children: [
3116
3642
  /* @__PURE__ */ jsx(ToneSquare, { tone: environment.tone }),
3117
3643
  /* @__PURE__ */ jsx("span", { children: t("{environment}. Not production, nothing here touches live customers.", { environment: environment.name }) })
3118
3644
  ] }),
3119
- area !== void 0 && pages.length > 1 ? /* @__PURE__ */ jsx("nav", { ref: strip, className: "cbx-m-chips", "aria-label": t("{area} pages", { area: area.label }), children: pages.map((page) => {
3120
- const on = page.key === shell.nav.activePage;
3121
- return /* @__PURE__ */ jsxs(Link, { href: navUrl(page), className: `cbx-m-chip ${on ? "is-on" : ""}`, "aria-current": on ? "page" : void 0, children: [
3122
- page.label,
3123
- page.locked === true && /* @__PURE__ */ jsx(NavPageMarks, { page })
3124
- ] }, page.key);
3125
- }) }) : /* @__PURE__ */ jsx("div", { className: "cbx-m-chips-gap" })
3645
+ area !== void 0 && pages.length > 1 ? /* @__PURE__ */ jsx("div", { className: "cbx-m-section-nav", children: /* @__PURE__ */ jsx(PageTabs, { items: pages.map((page) => ({ href: navUrl(page), label: `${area.label} \xB7 ${page.label}`, badge: page.locked ? /* @__PURE__ */ jsx(NavPageMarks, { page }) : void 0 })), currentPath: navUrl(pages.find((page) => page.key === shell.nav.activePage) ?? pages[0]), LinkComponent: (props) => /* @__PURE__ */ jsx(Link, { href: props.href, className: props.className, "aria-current": props["aria-current"], children: props.children }) }) }) : /* @__PURE__ */ jsx("div", { className: "cbx-m-chips-gap" })
3126
3646
  ] });
3127
3647
  }
3128
3648
  function TabBar({ onMore }) {
@@ -3546,7 +4066,7 @@ function MobilePage({ hidden, children }) {
3546
4066
  if (page === null) return;
3547
4067
  const mark = () => {
3548
4068
  for (const heading of page.querySelectorAll("[data-cbx-page-title]")) {
3549
- const same = title !== null && sameTitle(heading.textContent ?? "", title);
4069
+ const same = title !== null;
3550
4070
  if (same !== heading.hasAttribute("data-cbx-same-title")) heading.toggleAttribute("data-cbx-same-title", same);
3551
4071
  }
3552
4072
  };
@@ -3646,8 +4166,16 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
3646
4166
  const [moreView, setMoreView] = useMoreView();
3647
4167
  if (!store.get().seeded) store.set({ open: shell.preferences.helpOpen, restored: shell.preferences.helpOpen, seeded: true });
3648
4168
  const serverPreferences = JSON.stringify(shell.preferences);
4169
+ const lastServer = useRef(serverPreferences);
3649
4170
  useEffect(() => {
3650
- setPreferences(JSON.parse(serverPreferences));
4171
+ if (lastServer.current === serverPreferences) return;
4172
+ const before = JSON.parse(lastServer.current);
4173
+ const after = JSON.parse(serverPreferences);
4174
+ lastServer.current = serverPreferences;
4175
+ const changed = Object.keys({ ...before, ...after }).filter((key) => JSON.stringify(before[key]) !== JSON.stringify(after[key]));
4176
+ if (changed.length === 0) return;
4177
+ setPreferences((current) => ({ ...current, ...Object.fromEntries(changed.map((key) => [key, after[key]])) }));
4178
+ if (changed.includes("theme")) applyTheme(after.theme);
3651
4179
  }, [serverPreferences]);
3652
4180
  const setPreference = useCallback(
3653
4181
  (key, value) => {
@@ -4279,7 +4807,7 @@ function Combobox(props) {
4279
4807
  children: activeOption !== null && activeOption !== void 0 ? activeOption.label : placeholder
4280
4808
  }
4281
4809
  ),
4282
- /* @__PURE__ */ jsx(Chevron, { open })
4810
+ /* @__PURE__ */ jsx(Chevron2, { open })
4283
4811
  ]
4284
4812
  }
4285
4813
  ),
@@ -4551,7 +5079,7 @@ function nextEnabledIndex(options, current, direction) {
4551
5079
  }
4552
5080
  return -1;
4553
5081
  }
4554
- function Chevron({ open }) {
5082
+ function Chevron2({ open }) {
4555
5083
  return /* @__PURE__ */ jsx(
4556
5084
  "svg",
4557
5085
  {
@@ -4762,8 +5290,6 @@ function PageHeader({
4762
5290
  }) {
4763
5291
  const { t } = useCboxLocalization();
4764
5292
  const shellHelp = useShellHelp();
4765
- const shellTitle = useShellPageTitle();
4766
- const duplicate = shellTitle !== null && typeof title === "string" && sameTitle(title, shellTitle);
4767
5293
  return /* @__PURE__ */ jsxs(
4768
5294
  "header",
4769
5295
  {
@@ -4774,7 +5300,7 @@ function PageHeader({
4774
5300
  children: [
4775
5301
  /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
4776
5302
  eyebrow !== void 0 ? /* @__PURE__ */ jsx("p", { className: "text-mono text-[10px] font-semibold tracking-[0.18em] text-muted-foreground uppercase", children: eyebrow }) : null,
4777
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-cbx-same-title": duplicate ? "" : void 0, children: [
5303
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-cbx-same-title": void 0, children: [
4778
5304
  /* @__PURE__ */ jsx("h1", { className: "text-2xl leading-tight font-semibold tracking-tight text-foreground", children: title }),
4779
5305
  help && shellHelp !== null ? /* @__PURE__ */ jsx(
4780
5306
  "button",
@@ -4817,269 +5343,14 @@ function PageShell({
4817
5343
  "div",
4818
5344
  {
4819
5345
  className: cn(
4820
- "mx-auto w-full space-y-6",
4821
- widthClass[width],
4822
- className
4823
- ),
4824
- children
4825
- }
4826
- );
4827
- }
4828
- var DefaultLink = ({ href, className, children, "aria-current": ariaCurrent }) => /* @__PURE__ */ jsx("a", { href, className, "aria-current": ariaCurrent, children });
4829
- function PageTabs({
4830
- items,
4831
- currentPath,
4832
- LinkComponent = DefaultLink,
4833
- actions,
4834
- className
4835
- }) {
4836
- const activeHref = resolveActiveHref(items, currentPath);
4837
- return /* @__PURE__ */ jsxs(
4838
- "div",
4839
- {
4840
- "data-component": "page-tabs",
4841
- className: cn(
4842
- // Card-style chrome — same border, radius, bg as DataPanel
4843
- // so the tab strip reads as a peer of the content panels
4844
- // beneath it instead of floating on the page background.
4845
- // Width matches PageShell content; no sticky positioning.
4846
- "rounded-lg border border-border bg-card",
4847
- className
4848
- ),
4849
- children: [
4850
- /* @__PURE__ */ jsxs("div", { className: "hidden items-end gap-3 px-3 sm:flex", children: [
4851
- /* @__PURE__ */ jsx(
4852
- DesktopStrip,
4853
- {
4854
- items,
4855
- activeHref,
4856
- LinkComponent
4857
- }
4858
- ),
4859
- /* @__PURE__ */ jsx("div", { className: "flex min-h-12 shrink-0 items-center gap-2", children: actions })
4860
- ] }),
4861
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 p-3 sm:hidden", children: [
4862
- /* @__PURE__ */ jsx(
4863
- MobileDropdown,
4864
- {
4865
- items,
4866
- activeHref,
4867
- LinkComponent
4868
- }
4869
- ),
4870
- actions !== void 0 ? /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions }) : null
4871
- ] })
4872
- ]
4873
- }
4874
- );
4875
- }
4876
- function DesktopStrip({ items, activeHref, LinkComponent }) {
4877
- const { t } = useCboxLocalization();
4878
- return /* @__PURE__ */ jsx(
4879
- "nav",
4880
- {
4881
- className: "flex min-h-12 flex-1 items-center gap-1 overflow-x-auto overflow-y-hidden py-1.5",
4882
- role: "tablist",
4883
- "aria-label": t("Section navigation"),
4884
- children: items.map((item) => {
4885
- const Icon = item.icon;
4886
- const active = item.href === activeHref;
4887
- return /* @__PURE__ */ jsxs(
4888
- LinkComponent,
4889
- {
4890
- href: item.href,
4891
- prefetch: true,
4892
- "aria-current": active ? "page" : void 0,
4893
- className: cn(
4894
- "inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 text-[13px] whitespace-nowrap transition-colors",
4895
- active ? "bg-secondary font-semibold text-foreground shadow-sm ring-1 ring-border-strong/60" : "text-muted-foreground hover:bg-secondary/60 hover:text-foreground"
4896
- ),
4897
- children: [
4898
- Icon !== void 0 ? /* @__PURE__ */ jsx(
4899
- Icon,
4900
- {
4901
- className: cn(
4902
- "h-3.5 w-3.5 shrink-0",
4903
- active ? "text-foreground" : "text-muted-foreground"
4904
- ),
4905
- strokeWidth: 1.7
4906
- }
4907
- ) : null,
4908
- /* @__PURE__ */ jsx("span", { children: item.label }),
4909
- /* @__PURE__ */ jsx(ItemTrailing, { item, active })
4910
- ]
4911
- },
4912
- item.href
4913
- );
4914
- })
4915
- }
4916
- );
4917
- }
4918
- function MobileDropdown({ items, activeHref, LinkComponent }) {
4919
- const { t } = useCboxLocalization();
4920
- const [open, setOpen] = useState(false);
4921
- const ref = useRef(null);
4922
- const listId = useId();
4923
- const active = items.find((item) => item.href === activeHref) ?? items[0];
4924
- useEffect(() => {
4925
- if (!open) return;
4926
- function onPointerDown(event) {
4927
- if (ref.current !== null && !ref.current.contains(event.target)) {
4928
- setOpen(false);
4929
- }
4930
- }
4931
- function onKey(event) {
4932
- if (event.key === "Escape") setOpen(false);
4933
- }
4934
- window.addEventListener("pointerdown", onPointerDown);
4935
- window.addEventListener("keydown", onKey);
4936
- return () => {
4937
- window.removeEventListener("pointerdown", onPointerDown);
4938
- window.removeEventListener("keydown", onKey);
4939
- };
4940
- }, [open]);
4941
- if (active === void 0) {
4942
- return null;
4943
- }
4944
- const ActiveIcon = active.icon;
4945
- return /* @__PURE__ */ jsxs("div", { ref, className: "relative", children: [
4946
- /* @__PURE__ */ jsxs(
4947
- "button",
4948
- {
4949
- type: "button",
4950
- onClick: () => setOpen((v) => !v),
4951
- "aria-expanded": open,
4952
- "aria-haspopup": "listbox",
4953
- "aria-controls": listId,
4954
- className: cn(
4955
- "flex w-full min-h-11 items-center justify-between gap-2 rounded-md border border-border bg-card px-3 text-left text-[13px] font-medium text-foreground transition-colors hover:border-border-strong",
4956
- open && "border-border-strong ring-2 ring-ring/30"
4957
- ),
4958
- children: [
4959
- /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
4960
- ActiveIcon !== void 0 ? /* @__PURE__ */ jsx(
4961
- ActiveIcon,
4962
- {
4963
- className: "h-3.5 w-3.5 shrink-0 text-muted-foreground",
4964
- strokeWidth: 1.7
4965
- }
4966
- ) : null,
4967
- /* @__PURE__ */ jsx("span", { className: "truncate", children: active.label }),
4968
- /* @__PURE__ */ jsx(ItemTrailing, { item: active, active: true })
4969
- ] }),
4970
- /* @__PURE__ */ jsx(Chevron2, { open })
4971
- ]
4972
- }
4973
- ),
4974
- open ? /* @__PURE__ */ jsx(
4975
- "ul",
4976
- {
4977
- id: listId,
4978
- role: "listbox",
4979
- "aria-label": t("Section navigation"),
4980
- className: "absolute left-0 right-0 top-full z-30 mt-1 overflow-hidden rounded-md border border-border bg-popover shadow-lg",
4981
- children: items.map((item) => {
4982
- const Icon = item.icon;
4983
- const isActive = item.href === activeHref;
4984
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
4985
- LinkComponent,
4986
- {
4987
- href: item.href,
4988
- prefetch: true,
4989
- "aria-current": isActive ? "page" : void 0,
4990
- className: cn(
4991
- "flex w-full items-center gap-2 px-3 py-2.5 text-[13px] transition-colors",
4992
- isActive ? "bg-accent-soft font-semibold text-foreground" : "text-muted-foreground hover:bg-secondary hover:text-foreground"
4993
- ),
4994
- children: [
4995
- Icon !== void 0 ? /* @__PURE__ */ jsx(
4996
- Icon,
4997
- {
4998
- className: cn(
4999
- "h-3.5 w-3.5 shrink-0",
5000
- isActive ? "text-foreground" : "text-muted-foreground"
5001
- ),
5002
- strokeWidth: 1.7
5003
- }
5004
- ) : null,
5005
- /* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: item.label }),
5006
- /* @__PURE__ */ jsx(
5007
- ItemTrailing,
5008
- {
5009
- item,
5010
- active: isActive
5011
- }
5012
- )
5013
- ]
5014
- }
5015
- ) }, item.href);
5016
- })
5017
- }
5018
- ) : null
5019
- ] });
5020
- }
5021
- function ItemTrailing({
5022
- item,
5023
- active
5024
- }) {
5025
- if (item.badge !== void 0) {
5026
- return /* @__PURE__ */ jsx("span", { className: "ml-1 shrink-0", children: item.badge });
5027
- }
5028
- if (item.count !== void 0) {
5029
- return /* @__PURE__ */ jsx(
5030
- "span",
5031
- {
5032
- className: cn(
5033
- "ml-1 shrink-0 rounded-sm border px-1 text-[10px] font-semibold tracking-tight tabular-nums",
5034
- active ? "border-border-strong bg-secondary text-foreground" : "border-border bg-secondary/60 text-muted-foreground"
5035
- ),
5036
- children: item.count
5037
- }
5038
- );
5039
- }
5040
- return null;
5041
- }
5042
- function Chevron2({ open }) {
5043
- return /* @__PURE__ */ jsx(
5044
- "svg",
5045
- {
5046
- width: "14",
5047
- height: "14",
5048
- viewBox: "0 0 14 14",
5049
- fill: "none",
5050
- stroke: "currentColor",
5051
- strokeWidth: "1.6",
5052
- strokeLinecap: "round",
5053
- strokeLinejoin: "round",
5054
- className: cn(
5055
- "shrink-0 text-muted-foreground transition-transform duration-150",
5056
- open && "rotate-180"
5346
+ "mx-auto w-full space-y-6",
5347
+ widthClass[width],
5348
+ className
5057
5349
  ),
5058
- "aria-hidden": true,
5059
- children: /* @__PURE__ */ jsx("path", { d: "m3.5 5.5 3.5 3.5 3.5-3.5" })
5350
+ children
5060
5351
  }
5061
5352
  );
5062
5353
  }
5063
- function pathOnly(href) {
5064
- const queryIndex = href.indexOf("?");
5065
- const hashIndex = href.indexOf("#");
5066
- let end = href.length;
5067
- if (queryIndex !== -1) end = Math.min(end, queryIndex);
5068
- if (hashIndex !== -1) end = Math.min(end, hashIndex);
5069
- return href.slice(0, end);
5070
- }
5071
- function resolveActiveHref(items, currentPath) {
5072
- const current = pathOnly(currentPath);
5073
- const candidates = items.map((item) => {
5074
- const itemPath = pathOnly(item.href);
5075
- const matched = item.matchPrefix === true ? current === itemPath || current.startsWith(itemPath + "/") : current === itemPath;
5076
- return matched ? item.href : null;
5077
- }).filter((href) => href !== null);
5078
- if (candidates.length === 0) return null;
5079
- return candidates.reduce(
5080
- (longest, href) => href.length > longest.length ? href : longest
5081
- );
5082
- }
5083
5354
  var DefaultLink2 = ({ href, className, children }) => /* @__PURE__ */ jsx("a", { href, className, children });
5084
5355
  function RowLink({
5085
5356
  href,
@@ -5214,65 +5485,6 @@ function StatusPill({
5214
5485
  }
5215
5486
  );
5216
5487
  }
5217
- function Spinner({ className, label }) {
5218
- return /* @__PURE__ */ jsx(
5219
- "span",
5220
- {
5221
- className: cn("cbx-ui-spinner", className),
5222
- role: label === void 0 ? void 0 : "status",
5223
- "aria-hidden": label === void 0 ? true : void 0,
5224
- "aria-label": label
5225
- }
5226
- );
5227
- }
5228
- function buttonClassName({ variant = "ghost", size = "md" } = {}) {
5229
- return cn("cbx-ui-btn", `cbx-ui-btn--${variant}`, size !== "md" && `cbx-ui-btn--${size}`);
5230
- }
5231
- var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading = false, asChild = false, disabled, className, children, type, ...props }, ref) {
5232
- const classes = cn(buttonClassName({ variant, size }), className);
5233
- const glyph = loading ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
5234
- const inactive = (disabled ?? false) || loading;
5235
- if (asChild) {
5236
- const child = Children.only(children);
5237
- if (!isValidElement(child)) return null;
5238
- const own = child.props;
5239
- return cloneElement(child, {
5240
- ...props,
5241
- ref,
5242
- className: cn(classes, own.className),
5243
- "aria-busy": loading || void 0,
5244
- "aria-disabled": inactive || void 0,
5245
- // A disabled link keeps its focus (so it can be reached and explained) but goes nowhere.
5246
- onClick: (event) => {
5247
- if (inactive) {
5248
- event.preventDefault();
5249
- return;
5250
- }
5251
- own.onClick?.(event);
5252
- props.onClick?.(event);
5253
- },
5254
- children: /* @__PURE__ */ jsxs(Fragment, { children: [
5255
- glyph,
5256
- own.children
5257
- ] })
5258
- });
5259
- }
5260
- return /* @__PURE__ */ jsxs(
5261
- "button",
5262
- {
5263
- ref,
5264
- type: type ?? "button",
5265
- className: classes,
5266
- disabled: inactive,
5267
- "aria-busy": loading || void 0,
5268
- ...props,
5269
- children: [
5270
- glyph,
5271
- children
5272
- ]
5273
- }
5274
- );
5275
- });
5276
5488
  function Checkbox({ checked, onCheckedChange, label, hint, disabled = false, required, name, value, id: statedId, className }) {
5277
5489
  const generated = useId();
5278
5490
  const id = statedId ?? generated;
@@ -5310,175 +5522,6 @@ function Checkbox({ checked, onCheckedChange, label, hint, disabled = false, req
5310
5522
  ] })
5311
5523
  ] });
5312
5524
  }
5313
- var TABBABLE = [
5314
- "a[href]",
5315
- "area[href]",
5316
- "button:not([disabled])",
5317
- 'input:not([disabled]):not([type="hidden"])',
5318
- "select:not([disabled])",
5319
- "textarea:not([disabled])",
5320
- "iframe",
5321
- "audio[controls]",
5322
- "video[controls]",
5323
- '[contenteditable]:not([contenteditable="false"])',
5324
- '[tabindex]:not([tabindex="-1"])'
5325
- ].join(",");
5326
- function tabbables(root) {
5327
- const all = Array.from(root.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 && element.closest("[hidden], [inert]") === null);
5328
- const checkedGroups = new Set(all.filter((element) => element instanceof HTMLInputElement && element.type === "radio" && element.checked).map((element) => element.name));
5329
- const seen = /* @__PURE__ */ new Set();
5330
- return all.filter((element) => {
5331
- if (!(element instanceof HTMLInputElement) || element.type !== "radio" || element.name === "") return true;
5332
- if (checkedGroups.has(element.name)) return element.checked;
5333
- if (seen.has(element.name)) return false;
5334
- seen.add(element.name);
5335
- return true;
5336
- });
5337
- }
5338
- var DialogContext = createContext(null);
5339
- function useDialogClose() {
5340
- const close = useContext(DialogContext);
5341
- return close ?? (() => void 0);
5342
- }
5343
- function DialogClose({ onClick, ...props }) {
5344
- const close = useDialogClose();
5345
- return /* @__PURE__ */ jsx(
5346
- Button,
5347
- {
5348
- ...props,
5349
- onClick: (event) => {
5350
- onClick?.(event);
5351
- if (!event.defaultPrevented) close();
5352
- }
5353
- }
5354
- );
5355
- }
5356
- var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5357
- function Dialog({ open, onOpenChange, title, description, footer, size = "md", dismissible = true, className, children }) {
5358
- const { t } = useCboxLocalization();
5359
- const id = useId();
5360
- const titleId = `${id}-title`;
5361
- const descriptionId = `${id}-description`;
5362
- const layer = useRef(null);
5363
- const panel = useRef(null);
5364
- const closeButton = useRef(null);
5365
- const body = useRef(null);
5366
- const returnTo = useRef(null);
5367
- const wasOpen = useRef(false);
5368
- const pressedOnScrim = useRef(false);
5369
- if (open && !wasOpen.current && typeof document !== "undefined") {
5370
- const active = document.activeElement;
5371
- returnTo.current = active instanceof HTMLElement && active !== document.body ? active : null;
5372
- }
5373
- wasOpen.current = open;
5374
- const close = useCallback(() => onOpenChange(false), [onOpenChange]);
5375
- useScrollLock(open);
5376
- useIsoLayoutEffect2(() => {
5377
- if (!open || layer.current === null) return;
5378
- const own = layer.current;
5379
- const made = [];
5380
- for (const sibling of Array.from(document.body.children)) {
5381
- if (sibling === own || !(sibling instanceof HTMLElement) || sibling.hasAttribute("inert")) continue;
5382
- if (sibling.tagName === "SCRIPT" || sibling.tagName === "STYLE") continue;
5383
- sibling.setAttribute("inert", "");
5384
- made.push(sibling);
5385
- }
5386
- return () => {
5387
- for (const element of made) element.removeAttribute("inert");
5388
- };
5389
- }, [open]);
5390
- useIsoLayoutEffect2(() => {
5391
- if (!open || panel.current === null) return;
5392
- const root = panel.current;
5393
- if (root.contains(document.activeElement)) return;
5394
- const marked = root.querySelector("[data-autofocus]");
5395
- const field = body.current?.querySelector('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled]), [role="combobox"]');
5396
- (marked ?? field ?? closeButton.current ?? root).focus({ preventScroll: true });
5397
- }, [open]);
5398
- useEffect(() => {
5399
- if (!open) return;
5400
- const onFocusIn = (event) => {
5401
- const root = panel.current;
5402
- const target = event.target;
5403
- if (root === null || !(target instanceof Node) || root.contains(target)) return;
5404
- if (target instanceof Element && target.closest("[data-cbx-dialog-layer]") !== null) return;
5405
- (tabbables(root)[0] ?? root).focus({ preventScroll: true });
5406
- };
5407
- document.addEventListener("focusin", onFocusIn);
5408
- return () => document.removeEventListener("focusin", onFocusIn);
5409
- }, [open]);
5410
- useEffect(() => {
5411
- if (!open) return;
5412
- return () => {
5413
- const target = returnTo.current;
5414
- if (target !== null && target.isConnected) target.focus({ preventScroll: true });
5415
- };
5416
- }, [open]);
5417
- const onKeyDown = (event) => {
5418
- if (event.defaultPrevented) return;
5419
- if (event.key === "Escape") {
5420
- event.preventDefault();
5421
- event.stopPropagation();
5422
- close();
5423
- return;
5424
- }
5425
- if (event.key !== "Tab" || panel.current === null) return;
5426
- const items = tabbables(panel.current);
5427
- const first = items[0];
5428
- const last = items[items.length - 1];
5429
- if (first === void 0 || last === void 0) {
5430
- event.preventDefault();
5431
- panel.current.focus({ preventScroll: true });
5432
- return;
5433
- }
5434
- const active = document.activeElement;
5435
- if (event.shiftKey && (active === first || active === panel.current)) {
5436
- event.preventDefault();
5437
- last.focus();
5438
- } else if (!event.shiftKey && active === last) {
5439
- event.preventDefault();
5440
- first.focus();
5441
- }
5442
- };
5443
- if (!open || typeof document === "undefined") return null;
5444
- const onScrimDown = (event) => {
5445
- pressedOnScrim.current = event.target === event.currentTarget;
5446
- };
5447
- const onScrimClick = (event) => {
5448
- if (dismissible && pressedOnScrim.current && event.target === event.currentTarget) close();
5449
- pressedOnScrim.current = false;
5450
- };
5451
- return createPortal(
5452
- /* @__PURE__ */ jsx(DialogContext.Provider, { value: close, children: /* @__PURE__ */ jsxs("div", { ref: layer, "data-cbx-scroll-layer": "", "data-cbx-dialog-layer": "", children: [
5453
- /* @__PURE__ */ jsx("div", { className: "cbx-ui-overlay", "aria-hidden": "true", onMouseDown: onScrimDown, onClick: onScrimClick }),
5454
- /* @__PURE__ */ jsxs(
5455
- "div",
5456
- {
5457
- ref: panel,
5458
- role: "dialog",
5459
- "aria-modal": "true",
5460
- "aria-labelledby": titleId,
5461
- "aria-describedby": description !== void 0 ? descriptionId : void 0,
5462
- tabIndex: -1,
5463
- className: cn("cbx-ui-dialog", `cbx-ui-dialog--${size}`, className),
5464
- onKeyDown,
5465
- children: [
5466
- /* @__PURE__ */ jsxs("div", { className: "cbx-ui-dialog-head", children: [
5467
- /* @__PURE__ */ jsxs("div", { className: "cbx-ui-dialog-heading", children: [
5468
- /* @__PURE__ */ jsx("h2", { id: titleId, className: "cbx-ui-dialog-title", children: title }),
5469
- description !== void 0 && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "cbx-ui-dialog-desc", children: description })
5470
- ] }),
5471
- /* @__PURE__ */ jsx("button", { ref: closeButton, type: "button", className: "cbx-ui-iconbtn", "aria-label": t("Close"), onClick: close, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) }) })
5472
- ] }),
5473
- children !== void 0 && children !== null && /* @__PURE__ */ jsx("div", { ref: body, className: "cbx-ui-dialog-body", children }),
5474
- footer !== void 0 && footer !== null && /* @__PURE__ */ jsx("div", { className: "cbx-ui-dialog-foot", children: footer })
5475
- ]
5476
- }
5477
- )
5478
- ] }) }),
5479
- document.body
5480
- );
5481
- }
5482
5525
  var FieldContext = createContext(null);
5483
5526
  function useFieldControl() {
5484
5527
  const field = useContext(FieldContext);