@cboxdk/cbox-ui 0.10.4 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ 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, useContext, useMemo, useSyncExternalStore, useState, useEffect, useCallback, useRef, createElement, useId, useLayoutEffect, useImperativeHandle } from 'react';
5
+ import { createContext, useContext, useMemo, useSyncExternalStore, useState, useId, useEffect, useCallback, useRef, createElement, useLayoutEffect, useImperativeHandle } from 'react';
6
6
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
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, PinOff, Pin, PanelLeftOpen, PanelLeftClose, Menu, ChevronsUpDown, CircleHelp, ArrowLeft, ArrowUpRight, X, CircleAlert, Ticket, UserRound, CornerDownLeft, ArrowRight, Circle, Monitor, Sun, Moon, ChevronRight, LogOut, Check, Plus } from 'lucide-react';
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
 
9
9
  var CboxIdContext = createContext(null);
10
10
  function CboxIdProvider({
@@ -76,10 +76,23 @@ function useShell() {
76
76
  if (api === null) throw new Error("[cbox-ui] Shell parts must be rendered inside <CboxShell>.");
77
77
  return api;
78
78
  }
79
+ function useShellCreate() {
80
+ const api = useContext(ShellContext);
81
+ return api === null || api.renderCreate === void 0 ? null : { openCreate: api.openCreate };
82
+ }
79
83
  function useShellHelp() {
80
84
  const api = useContext(ShellContext);
81
85
  return api === null ? null : { toggleHelp: api.toggleHelp, openArticle: api.openArticle, ask: api.ask };
82
86
  }
87
+ function sameTitle(a, b) {
88
+ const norm = (text) => text.replace(/\s+/g, " ").trim().replace(/:$/, "").toLocaleLowerCase();
89
+ return norm(a) !== "" && norm(a) === norm(b);
90
+ }
91
+ function useShellPageTitle() {
92
+ const api = useContext(ShellContext);
93
+ if (api === null || !api.mobile) return null;
94
+ return api.shell.nav.areas.find((area) => area.key === api.shell.nav.activeArea)?.label ?? null;
95
+ }
83
96
  var DESKTOP_POINTER = "(hover: hover) and (pointer: fine)";
84
97
  var HELP_DOCKED = "(min-width: 1280px)";
85
98
  var MOBILE = "(max-width: 767px)";
@@ -340,8 +353,8 @@ var DEFAULT_FORMATS = [
340
353
  var FALLBACK_ZONES = ["UTC", "Europe/Copenhagen", "Europe/London", "Europe/Berlin", "Europe/Stockholm", "Europe/Oslo", "America/New_York", "America/Los_Angeles", "Asia/Tokyo"];
341
354
  function timeZones() {
342
355
  const supported = Intl.supportedValuesOf;
343
- const zones = typeof supported === "function" ? supported("timeZone") : FALLBACK_ZONES;
344
- return zones.map((zone) => ({ code: zone, label: zone.replace(/_/g, " ") }));
356
+ const zones2 = typeof supported === "function" ? supported("timeZone") : FALLBACK_ZONES;
357
+ return zones2.map((zone) => ({ code: zone, label: zone.replace(/_/g, " ") }));
345
358
  }
346
359
  function Avatar({ size = 30 }) {
347
360
  const { shell } = useShell();
@@ -357,7 +370,7 @@ function AccountMenu({ inline = false, onDone }) {
357
370
  const tab = inline ? 0 : -1;
358
371
  const languages = account.languages ?? DEFAULT_LANGUAGES;
359
372
  const formats = account.formats ?? DEFAULT_FORMATS;
360
- const zones = useMemo(() => view === "timeZone" ? timeZones() : [], [view]);
373
+ const zones2 = useMemo(() => view === "timeZone" ? timeZones() : [], [view]);
361
374
  useEffect(() => {
362
375
  if (view !== "main" || inline) return;
363
376
  menu.current?.querySelector('[role="menuitem"]')?.focus();
@@ -381,7 +394,7 @@ function AccountMenu({ inline = false, onDone }) {
381
394
  ] });
382
395
  if (view === "timeZone") return /* @__PURE__ */ jsxs("div", { className: "cbx-menu cbx-menu-account", children: [
383
396
  back,
384
- /* @__PURE__ */ jsx(OptionList, { label: t("Time zone"), options: zones, current: preferences.timeZone, onPick: pick("timeZone") })
397
+ /* @__PURE__ */ jsx(OptionList, { label: t("Time zone"), options: zones2, current: preferences.timeZone, onPick: pick("timeZone") })
385
398
  ] });
386
399
  const themes = [
387
400
  { value: "system", label: t("System"), icon: Monitor },
@@ -631,7 +644,7 @@ function forgetShellCatalog() {
631
644
  }
632
645
 
633
646
  // src/shell/data.ts
634
- var TONES = ["production", "sandbox", "neutral"];
647
+ var TONES = ["production", "sandbox", "neutral", "staging", "preview", "development"];
635
648
  function initialsOf(name) {
636
649
  const words = name.trim().split(/\s+/).filter(Boolean);
637
650
  const letters = words.length > 1 ? (words[0][0] ?? "") + (words[1][0] ?? "") : name.trim().slice(0, 2);
@@ -648,6 +661,9 @@ function toItem(value) {
648
661
  if (typeof row.label === "string" && row.label !== "") item.label = row.label;
649
662
  const test = row.testData ?? row.test_data;
650
663
  if (typeof test === "boolean") item.testData = test;
664
+ if (typeof row.live === "boolean") item.live = row.live;
665
+ if (typeof row.group === "string" && row.group !== "") item.group = row.group;
666
+ if (typeof row.description === "string" && row.description !== "") item.description = row.description;
651
667
  return item;
652
668
  }
653
669
  function parseListPage(body) {
@@ -810,6 +826,33 @@ function currentLocation() {
810
826
  if (typeof window === "undefined") return "/";
811
827
  return window.location.pathname + window.location.search + window.location.hash;
812
828
  }
829
+ function isLive(item) {
830
+ if (item.live !== void 0) return item.live;
831
+ if (item.testData === true) return false;
832
+ if (item.tone !== void 0) return item.tone === "production";
833
+ return void 0;
834
+ }
835
+ function environmentLevel(levels) {
836
+ return levels.find((level) => level.key === "environment");
837
+ }
838
+ function quickEnvironments(items, current) {
839
+ const picks = [current];
840
+ const live = items.find((item) => item.id !== current.id && isLive(item) === true);
841
+ if (live !== void 0) picks.push(live);
842
+ const test = items.find((item) => item.id !== current.id && item.id !== live?.id && isLive(item) !== true);
843
+ if (test !== void 0) picks.push(test);
844
+ return picks.slice(0, 3);
845
+ }
846
+ function groupItems(items) {
847
+ const runs = /* @__PURE__ */ new Map();
848
+ for (const item of items) {
849
+ const key = item.group ?? "";
850
+ const run = runs.get(key) ?? { group: item.group, items: [] };
851
+ run.items.push(item);
852
+ runs.set(key, run);
853
+ }
854
+ return Array.from(runs.values());
855
+ }
813
856
  var DEBOUNCE_MS = 120;
814
857
  var PAGE_SIZE = 25;
815
858
  function pageSize(url) {
@@ -915,7 +958,7 @@ function ToneSquare({ tone }) {
915
958
  function isEnvironmentLevel(level) {
916
959
  return level.key === "environment";
917
960
  }
918
- function LevelPane({ level, parent, currentId, heading, viewAll = true, searchable = true, autoFocus = false, chevron = false, createLabel, onPick, onPreview, onArrowRight, onArrowLeft, handle, className }) {
961
+ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchable = true, autoFocus = false, chevron = false, createLabel: createLabel2, onPick, onPreview, onArrowRight, onArrowLeft, handle, className }) {
919
962
  const { t, Link, navigate } = useShell();
920
963
  const [q, setQ] = useState("");
921
964
  const [active, setActiveRow] = useState(-1);
@@ -955,7 +998,7 @@ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchab
955
998
  useImperativeHandle(handle, () => ({ focus: focusSelf }), [focusSelf]);
956
999
  const optionId = (index) => `${id}-option-${index}`;
957
1000
  const allId = `${id}-all`;
958
- const canCreate = level.createUrl !== void 0 && createLabel !== void 0;
1001
+ const canCreate = level.createUrl !== void 0 && createLabel2 !== void 0;
959
1002
  const viewAllLink = () => viewAll ? document.getElementById(allId) : null;
960
1003
  const createAction = () => canCreate && !creating ? createButton.current : null;
961
1004
  useEffect(() => {
@@ -1149,12 +1192,12 @@ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchab
1149
1192
  ]
1150
1193
  }
1151
1194
  ),
1152
- canCreate && /* @__PURE__ */ jsx("div", { className: "cbx-pane-foot", children: creating ? /* @__PURE__ */ jsx(InlineCreate, { level, parent, label: createLabel, onCancel: () => {
1195
+ canCreate && /* @__PURE__ */ jsx("div", { className: "cbx-pane-foot", children: creating ? /* @__PURE__ */ jsx(InlineCreate, { level, parent, label: createLabel2, onCancel: () => {
1153
1196
  setCreating(false);
1154
1197
  focusSelf();
1155
1198
  } }) : /* @__PURE__ */ jsxs("button", { ref: createButton, type: "button", className: "cbx-row cbx-row-action", "data-pane-action": "create", onClick: () => setCreating(true), onKeyDown: (event) => onActionKeyDown(event, "create"), children: [
1156
1199
  /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1157
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: createLabel })
1200
+ /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: createLabel2 })
1158
1201
  ] }) })
1159
1202
  ] });
1160
1203
  }
@@ -1340,6 +1383,60 @@ function CascadeLabel({ levels }) {
1340
1383
  ] })
1341
1384
  ] });
1342
1385
  }
1386
+ var SHELL_ICONS = {
1387
+ activity: Activity,
1388
+ "bar-chart": BarChart3,
1389
+ bell: Bell,
1390
+ "book-open": BookOpen,
1391
+ boxes: Boxes,
1392
+ briefcase: Briefcase,
1393
+ building: Building2,
1394
+ calendar: Calendar,
1395
+ clock: Clock,
1396
+ cloud: Cloud,
1397
+ code: Code,
1398
+ "credit-card": CreditCard,
1399
+ database: Database,
1400
+ "file-text": FileText,
1401
+ folder: Folder,
1402
+ "git-branch": GitBranch,
1403
+ globe: Globe,
1404
+ "hard-drive": HardDrive,
1405
+ home: Home,
1406
+ inbox: Inbox,
1407
+ key: Key,
1408
+ "layout-dashboard": LayoutDashboard,
1409
+ "layout-grid": LayoutGrid,
1410
+ layers: Layers,
1411
+ "life-buoy": LifeBuoy,
1412
+ list: List,
1413
+ lock: Lock,
1414
+ mail: Mail,
1415
+ "message-square": MessageSquare,
1416
+ network: Network,
1417
+ package: Package,
1418
+ percent: Percent,
1419
+ plug: Plug,
1420
+ receipt: Receipt,
1421
+ rocket: Rocket,
1422
+ search: Search,
1423
+ send: Send,
1424
+ server: Server,
1425
+ settings: Settings,
1426
+ shield: Shield,
1427
+ "shield-check": ShieldCheck,
1428
+ sparkles: Sparkles,
1429
+ tag: Tag,
1430
+ timer: Timer,
1431
+ users: Users,
1432
+ wallet: Wallet,
1433
+ webhook: Webhook,
1434
+ zap: Zap
1435
+ };
1436
+ function resolveIcon(name, extra = {}) {
1437
+ if (name === void 0) return Circle;
1438
+ return extra[name] ?? SHELL_ICONS[name] ?? Circle;
1439
+ }
1343
1440
 
1344
1441
  // src/shell/help-store.ts
1345
1442
  var INITIAL_HELP_STATE = {
@@ -1414,11 +1511,362 @@ function parseArticles(body) {
1414
1511
  return [article];
1415
1512
  });
1416
1513
  }
1514
+ var count = 0;
1515
+ var saved = null;
1516
+ var startY = 0;
1517
+ var startX = 0;
1518
+ var LAYER = ".cbx-overlay, [data-cbx-scroll-layer]";
1519
+ function scrollable(element, axis) {
1520
+ const style = getComputedStyle(element);
1521
+ const overflow = axis === "y" ? style.overflowY : style.overflowX;
1522
+ if (overflow !== "auto" && overflow !== "scroll") return false;
1523
+ return axis === "y" ? element.scrollHeight > element.clientHeight + 1 : element.scrollWidth > element.clientWidth + 1;
1524
+ }
1525
+ function canScrollWithin(target, dx, dy) {
1526
+ if (!(target instanceof Element)) return false;
1527
+ const layer = target.closest(LAYER);
1528
+ if (layer === null) return false;
1529
+ const axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";
1530
+ const delta = axis === "y" ? dy : dx;
1531
+ if (delta === 0) return true;
1532
+ if (target.closest('textarea, input[type="range"]') !== null) return true;
1533
+ for (let node = target; node !== null && node !== layer.parentElement; node = node.parentElement) {
1534
+ if (!scrollable(node, axis)) continue;
1535
+ const position = axis === "y" ? node.scrollTop : node.scrollLeft;
1536
+ const max = axis === "y" ? node.scrollHeight - node.clientHeight : node.scrollWidth - node.clientWidth;
1537
+ if (delta > 0 && position > 0) return true;
1538
+ if (delta < 0 && position < max - 1) return true;
1539
+ }
1540
+ return false;
1541
+ }
1542
+ function onTouchStart(event) {
1543
+ const touch = event.touches[0];
1544
+ if (touch === void 0) return;
1545
+ startX = touch.clientX;
1546
+ startY = touch.clientY;
1547
+ }
1548
+ function onTouchMove(event) {
1549
+ if (event.touches.length > 1 || !event.cancelable) return;
1550
+ const touch = event.touches[0];
1551
+ if (touch === void 0) return;
1552
+ const dx = touch.clientX - startX;
1553
+ const dy = touch.clientY - startY;
1554
+ startX = touch.clientX;
1555
+ startY = touch.clientY;
1556
+ if (!canScrollWithin(event.target, dx, dy)) event.preventDefault();
1557
+ }
1558
+ function scrollRegions() {
1559
+ return Array.from(document.querySelectorAll(".cbx-shell-main, [scroll-region]")).filter((element) => {
1560
+ const overflow = getComputedStyle(element).overflowY;
1561
+ return overflow === "auto" || overflow === "scroll";
1562
+ });
1563
+ }
1564
+ function lockScroll() {
1565
+ if (typeof document === "undefined") return () => void 0;
1566
+ count += 1;
1567
+ if (count === 1) {
1568
+ const html = document.documentElement;
1569
+ const body = document.body;
1570
+ const gutter = Math.max(0, window.innerWidth - html.clientWidth);
1571
+ saved = {
1572
+ x: window.scrollX,
1573
+ y: window.scrollY,
1574
+ html: { overflow: html.style.overflow, scrollBehavior: html.style.scrollBehavior },
1575
+ body: { overflow: body.style.overflow, paddingRight: body.style.paddingRight },
1576
+ regions: scrollRegions().map((element) => ({ element, overflow: element.style.overflow, top: element.scrollTop }))
1577
+ };
1578
+ html.style.overflow = "hidden";
1579
+ body.style.overflow = "hidden";
1580
+ if (gutter > 0) body.style.paddingRight = `calc(${getComputedStyle(body).paddingRight} + ${gutter}px)`;
1581
+ for (const region of saved.regions) region.element.style.overflow = "hidden";
1582
+ html.setAttribute("data-cbx-scroll-locked", "");
1583
+ document.addEventListener("touchstart", onTouchStart, { passive: true, capture: true });
1584
+ document.addEventListener("touchmove", onTouchMove, { passive: false, capture: true });
1585
+ }
1586
+ let released = false;
1587
+ return () => {
1588
+ if (released) return;
1589
+ released = true;
1590
+ count -= 1;
1591
+ if (count > 0 || saved === null) return;
1592
+ const html = document.documentElement;
1593
+ const body = document.body;
1594
+ const { x, y, regions } = saved;
1595
+ html.style.overflow = saved.html.overflow;
1596
+ body.style.overflow = saved.body.overflow;
1597
+ body.style.paddingRight = saved.body.paddingRight;
1598
+ html.removeAttribute("data-cbx-scroll-locked");
1599
+ document.removeEventListener("touchstart", onTouchStart, { capture: true });
1600
+ document.removeEventListener("touchmove", onTouchMove, { capture: true });
1601
+ html.style.scrollBehavior = "auto";
1602
+ for (const region of regions) {
1603
+ region.element.style.overflow = region.overflow;
1604
+ region.element.scrollTop = region.top;
1605
+ }
1606
+ if (window.scrollX !== x || window.scrollY !== y) {
1607
+ try {
1608
+ window.scrollTo(x, y);
1609
+ } catch {
1610
+ }
1611
+ }
1612
+ html.style.scrollBehavior = saved.html.scrollBehavior;
1613
+ saved = null;
1614
+ };
1615
+ }
1616
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
1617
+ function useScrollLock(active = true) {
1618
+ useIsoLayoutEffect(() => {
1619
+ if (!active) return;
1620
+ return lockScroll();
1621
+ }, [active]);
1622
+ }
1623
+ var LARGE = 0.92;
1624
+ var MEDIUM = 0.5;
1625
+ function sheetDetents({ size, viewport, current, content }) {
1626
+ const large = Math.round(viewport * LARGE);
1627
+ const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
1628
+ const sorted = heights.map(Math.round).sort((a, b) => a - b);
1629
+ const detents = [];
1630
+ for (const height of sorted) {
1631
+ const last = detents[detents.length - 1];
1632
+ if (last === void 0 || height - last >= 48) detents.push(height);
1633
+ else if (height === Math.round(current)) detents[detents.length - 1] = height;
1634
+ }
1635
+ return detents;
1636
+ }
1637
+ function rubberBand(overshoot, limit = 120) {
1638
+ if (overshoot <= 0) return 0;
1639
+ return limit * (1 - 1 / (overshoot / limit + 1));
1640
+ }
1641
+ function settleSheet({ height, velocity, detents }) {
1642
+ const smallest = detents[0] ?? height;
1643
+ const below = smallest - height;
1644
+ if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
1645
+ const projected = height - velocity * 200;
1646
+ let best = smallest;
1647
+ for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
1648
+ return { close: false, height: best };
1649
+ }
1650
+ var VelocityTracker = class {
1651
+ samples = [];
1652
+ add(t, y) {
1653
+ this.samples.push({ t, y });
1654
+ while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
1655
+ }
1656
+ velocity() {
1657
+ const first = this.samples[0];
1658
+ const last = this.samples[this.samples.length - 1];
1659
+ if (first === void 0 || last === void 0 || last.t === first.t) return 0;
1660
+ return (last.y - first.y) / (last.t - first.t);
1661
+ }
1662
+ };
1663
+ function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
1664
+ if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
1665
+ if (Math.abs(dx) > Math.abs(dy)) return "scroll";
1666
+ if (zone === "grab") return "drag";
1667
+ if (dy > 0 && scrollTop <= 0) return "drag";
1668
+ if (dy < 0 && canGrow) return "drag";
1669
+ return "scroll";
1670
+ }
1671
+ var EASE = "cubic-bezier(.2, .9, .25, 1)";
1672
+ var DURATION = 280;
1673
+ var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
1674
+ function reducedMotion() {
1675
+ return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1676
+ }
1677
+ function visibleHeight() {
1678
+ return Math.round(window.visualViewport?.height ?? window.innerHeight);
1679
+ }
1680
+ function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
1681
+ const close = useRef(onClose);
1682
+ close.current = onClose;
1683
+ useEffect(() => {
1684
+ const sheet = panel.current;
1685
+ if (!enabled || sheet === null || typeof window === "undefined") return;
1686
+ let gesture = null;
1687
+ let natural = null;
1688
+ let closing = false;
1689
+ let timer;
1690
+ const scrollerOf = (target) => {
1691
+ for (let node = target; node !== null && node !== sheet; node = node.parentElement) {
1692
+ const overflow = getComputedStyle(node).overflowY;
1693
+ if ((overflow === "auto" || overflow === "scroll") && node instanceof HTMLElement) return node;
1694
+ }
1695
+ return null;
1696
+ };
1697
+ const contentHeight = () => {
1698
+ const body = sheet.querySelector("[data-cbx-sheet-scroll]");
1699
+ if (body === null) return sheet.offsetHeight;
1700
+ return sheet.offsetHeight - body.clientHeight + body.scrollHeight;
1701
+ };
1702
+ const setScrim = (fraction) => {
1703
+ if (scrim?.current) {
1704
+ if (fraction >= 1) scrim.current.style.removeProperty("--cbx-scrim");
1705
+ else scrim.current.style.setProperty("--cbx-scrim", String(Math.max(0, Math.min(1, fraction))));
1706
+ }
1707
+ };
1708
+ const animate = (on) => {
1709
+ const smooth = on && !reducedMotion();
1710
+ sheet.style.transition = smooth ? `height ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : "none";
1711
+ if (scrim?.current) scrim.current.style.transition = smooth ? `--cbx-scrim ${DURATION}ms ${EASE}` : "none";
1712
+ };
1713
+ const place2 = (height, detents) => {
1714
+ const smallest = detents[0];
1715
+ const largest = detents[detents.length - 1];
1716
+ let shown = height;
1717
+ let drop = 0;
1718
+ if (height > largest) shown = largest + rubberBand(height - largest);
1719
+ else if (height < smallest) {
1720
+ shown = smallest;
1721
+ drop = smallest - height;
1722
+ }
1723
+ sheet.style.maxHeight = "none";
1724
+ sheet.style.height = `${Math.round(shown)}px`;
1725
+ sheet.style.transform = drop > 0 ? `translateY(${Math.round(drop)}px)` : "";
1726
+ setScrim(drop > 0 ? 1 - drop / smallest : 1);
1727
+ sheet.dataset.cbxDragging = "true";
1728
+ };
1729
+ const begin = (event) => {
1730
+ if (gesture !== null) finish(gesture.last, event.timeStamp);
1731
+ if (closing) return;
1732
+ if (event.pointerType === "mouse" && event.button !== 0) return;
1733
+ const target = event.target instanceof Element ? event.target : null;
1734
+ if (target === null || target.closest(NO_DRAG) !== null) return;
1735
+ const zone = target.closest(".cbx-sheet-grab") !== null ? "grab" : "content";
1736
+ gesture = { id: event.pointerId, x: event.clientX, y: event.clientY, zone, scroller: scrollerOf(target), mode: void 0, last: event.clientY, start: 0, detents: [], tracker: new VelocityTracker() };
1737
+ gesture.tracker.add(event.timeStamp, event.clientY);
1738
+ window.addEventListener("pointermove", move);
1739
+ window.addEventListener("pointerup", end);
1740
+ window.addEventListener("pointercancel", end);
1741
+ };
1742
+ const canGrow = () => {
1743
+ const current = sheet.getBoundingClientRect().height;
1744
+ const detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1745
+ return current < detents[detents.length - 1] - 1;
1746
+ };
1747
+ const decide = (dx, dy) => {
1748
+ if (gesture === null) return void 0;
1749
+ if (gesture.mode !== void 0) return gesture.mode;
1750
+ const mode = dragIntent({ zone: gesture.zone, dx, dy, scrollTop: gesture.scroller?.scrollTop ?? 0, canGrow: gesture.zone === "content" && dy < 0 ? canGrow() : false });
1751
+ if (mode === "drag") {
1752
+ clearTimeout(timer);
1753
+ const current = sheet.getBoundingClientRect().height;
1754
+ if (natural === null && sheet.style.height === "") natural = Math.round(current);
1755
+ gesture.start = current;
1756
+ gesture.detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1757
+ animate(false);
1758
+ try {
1759
+ sheet.setPointerCapture(gesture.id);
1760
+ } catch {
1761
+ }
1762
+ }
1763
+ gesture.mode = mode;
1764
+ return mode;
1765
+ };
1766
+ const move = (event) => {
1767
+ if (gesture === null || event.pointerId !== gesture.id) return;
1768
+ const dx = event.clientX - gesture.x;
1769
+ const dy = event.clientY - gesture.y;
1770
+ if (decide(dx, dy) !== "drag") return;
1771
+ gesture.last = event.clientY;
1772
+ gesture.tracker.add(event.timeStamp, event.clientY);
1773
+ place2(gesture.start - dy, gesture.detents);
1774
+ };
1775
+ const end = (event) => {
1776
+ if (gesture === null || event.pointerId !== gesture.id) return;
1777
+ finish(event.type === "pointerup" ? event.clientY : gesture.last, event.timeStamp);
1778
+ };
1779
+ const finish = (y, at) => {
1780
+ const done = gesture;
1781
+ gesture = null;
1782
+ unfollow();
1783
+ if (done === null || done.mode !== "drag") return;
1784
+ done.tracker.add(at, y);
1785
+ delete sheet.dataset.cbxDragging;
1786
+ const height = done.start - (y - done.y);
1787
+ const result = settleSheet({ height, velocity: done.tracker.velocity(), detents: done.detents });
1788
+ const swallow = (click) => {
1789
+ click.preventDefault();
1790
+ click.stopPropagation();
1791
+ };
1792
+ sheet.addEventListener("click", swallow, { capture: true, once: true });
1793
+ setTimeout(() => sheet.removeEventListener("click", swallow, { capture: true }), 350);
1794
+ animate(true);
1795
+ if (result.close) {
1796
+ closing = true;
1797
+ sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
1798
+ setScrim(0);
1799
+ timer = setTimeout(() => close.current(), reducedMotion() ? 0 : DURATION - 40);
1800
+ return;
1801
+ }
1802
+ if (natural !== null && result.height === natural) {
1803
+ sheet.style.height = `${natural}px`;
1804
+ sheet.style.transform = "";
1805
+ setScrim(1);
1806
+ timer = setTimeout(() => {
1807
+ sheet.style.height = "";
1808
+ sheet.style.maxHeight = "";
1809
+ sheet.style.transition = "";
1810
+ natural = null;
1811
+ }, reducedMotion() ? 0 : DURATION);
1812
+ return;
1813
+ }
1814
+ sheet.style.height = `${result.height}px`;
1815
+ sheet.style.transform = "";
1816
+ setScrim(1);
1817
+ };
1818
+ const touchMove = (event) => {
1819
+ if (gesture === null || event.touches.length > 1) return;
1820
+ const touch = event.touches[0];
1821
+ const mode = decide(touch.clientX - gesture.x, touch.clientY - gesture.y);
1822
+ if (mode === "drag" && event.cancelable) event.preventDefault();
1823
+ };
1824
+ const unfollow = () => {
1825
+ window.removeEventListener("pointermove", move);
1826
+ window.removeEventListener("pointerup", end);
1827
+ window.removeEventListener("pointercancel", end);
1828
+ };
1829
+ sheet.addEventListener("pointerdown", begin);
1830
+ sheet.addEventListener("touchmove", touchMove, { passive: false });
1831
+ return () => {
1832
+ clearTimeout(timer);
1833
+ unfollow();
1834
+ sheet.removeEventListener("pointerdown", begin);
1835
+ sheet.removeEventListener("touchmove", touchMove);
1836
+ for (const property of ["height", "maxHeight", "transform", "transition"]) sheet.style[property] = "";
1837
+ delete sheet.dataset.cbxDragging;
1838
+ if (scrim?.current) {
1839
+ scrim.current.style.removeProperty("--cbx-scrim");
1840
+ scrim.current.style.transition = "";
1841
+ }
1842
+ };
1843
+ }, [panel, scrim, size, enabled]);
1844
+ }
1845
+ function scrimHandlers(onClose) {
1846
+ return {
1847
+ onPointerDown: (event) => {
1848
+ event.currentTarget.dataset.cbxPressed = event.target === event.currentTarget ? "true" : "false";
1849
+ },
1850
+ onClick: (event) => {
1851
+ const pressed = event.currentTarget.dataset.cbxPressed === "true";
1852
+ delete event.currentTarget.dataset.cbxPressed;
1853
+ if (pressed && event.target === event.currentTarget) onClose();
1854
+ }
1855
+ };
1856
+ }
1417
1857
  var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
1418
1858
  var SUPPORT_TAG = "cbox-support";
1419
1859
  function useHelpState(store, select) {
1420
1860
  return useSyncExternalStore(store.subscribe, () => select(store.get()), () => select(store.get()));
1421
1861
  }
1862
+ function useUnreadCount(store, sent) {
1863
+ const loaded = useHelpState(store, (state) => state.updatesStatus === "ready" ? state.updates.filter((update) => update.unread).length : null);
1864
+ return loaded ?? sent ?? 0;
1865
+ }
1866
+ function helpTopicName(shell) {
1867
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
1868
+ return shell.page?.title ?? area?.label ?? shell.app.name;
1869
+ }
1422
1870
  function contextTrail(shell) {
1423
1871
  return shell.context.levels.map((level) => level.current.name).join(" / ");
1424
1872
  }
@@ -1455,7 +1903,7 @@ function whenSupportReady(host, timeoutMs = 6e3) {
1455
1903
  attempt();
1456
1904
  });
1457
1905
  }
1458
- function HelpColumn({ docked }) {
1906
+ function HelpColumn({ docked, mobile = false }) {
1459
1907
  const { shell, t, help: store, toggleHelp, navigate, preferences } = useShell();
1460
1908
  const formatDate = useShortDate(preferences.regionalFormat ?? preferences.locale, preferences.timeZone);
1461
1909
  const open = useHelpState(store, (state) => helpVisible(state, docked));
@@ -1469,12 +1917,18 @@ function HelpColumn({ docked }) {
1469
1917
  const [results, setResults] = useState(null);
1470
1918
  const [question, setQuestion] = useState("");
1471
1919
  const [chatProblem, setChatProblem] = useState(false);
1920
+ const [asked, setAsked] = useState(false);
1921
+ const [followUp, setFollowUp] = useState("");
1472
1922
  const column = useRef(null);
1473
1923
  const body = useRef(null);
1474
1924
  const chatHost = useRef(null);
1475
1925
  const searchField = useRef(null);
1476
1926
  const opener = useRef(null);
1927
+ const scrim = useRef(null);
1477
1928
  const { help } = shell;
1929
+ useScrollLock(mobile && open);
1930
+ const closeSheet = useCallback(() => toggleHelp(false), [toggleHelp]);
1931
+ useSheetDrag({ panel: column, scrim, size: "tall", onClose: closeSheet, enabled: mobile && open });
1478
1932
  const portal = help.portalUrl;
1479
1933
  const updatesKey = help.enabled && help.updatesUrl !== void 0 ? `${help.updatesUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
1480
1934
  const loadUpdates = useCallback(() => {
@@ -1502,7 +1956,7 @@ function HelpColumn({ docked }) {
1502
1956
  if (articles.topic === help.topic && articles.status === "ready") return;
1503
1957
  const controller = new AbortController();
1504
1958
  setArticles({ topic: help.topic, items: [], status: "loading" });
1505
- requestJson(help.articlesUrl.split("{topic}").join(encodeURIComponent(help.topic)), { signal: controller.signal }).then((answer) => setArticles({ topic: help.topic, items: parseArticles(answer).slice(0, 3), status: "ready" })).catch((error) => {
1959
+ requestJson(help.articlesUrl.split("{topic}").join(encodeURIComponent(help.topic)), { signal: controller.signal }).then((answer) => setArticles({ topic: help.topic, items: parseArticles(answer).slice(0, 4), status: "ready" })).catch((error) => {
1506
1960
  if (error?.name !== "AbortError") setArticles({ topic: help.topic, items: [], status: "unavailable" });
1507
1961
  });
1508
1962
  return () => controller.abort();
@@ -1571,8 +2025,8 @@ function HelpColumn({ docked }) {
1571
2025
  if (closed) {
1572
2026
  const active = document.activeElement;
1573
2027
  if (active === null || active === document.body || column.current?.contains(active)) {
1574
- const back = opener.current?.isConnected ? opener.current : document.querySelector('.cbx-tools [aria-controls="cbx-help"]');
1575
- back?.focus();
2028
+ const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
2029
+ back?.focus({ preventScroll: true });
1576
2030
  }
1577
2031
  opener.current = null;
1578
2032
  return;
@@ -1602,7 +2056,121 @@ function HelpColumn({ docked }) {
1602
2056
  const submit = (event) => {
1603
2057
  event.preventDefault();
1604
2058
  void openChat(question.trim());
2059
+ if (question.trim() !== "") setAsked(true);
1605
2060
  };
2061
+ const pageArticles = help.articlesUrl !== void 0 ? articles.items : (help.articles ?? []).slice(0, 4);
2062
+ if (mobile) {
2063
+ const topic = helpTopicName(shell);
2064
+ const environment = environmentLevel(shell.context.levels)?.current;
2065
+ const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
2066
+ const chatReady = help.enabled && help.sessionUrl !== void 0;
2067
+ const close = () => toggleHelp(false);
2068
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, ...scrimHandlers(close), children: /* @__PURE__ */ jsxs(
2069
+ "div",
2070
+ {
2071
+ ref: column,
2072
+ id: "cbx-help",
2073
+ className: "cbx-sheet cbx-sheet-bottom is-tall cbx-help-sheet",
2074
+ role: "dialog",
2075
+ "aria-modal": "true",
2076
+ "aria-label": t("Help with {page}", { page: topic }),
2077
+ tabIndex: -1,
2078
+ onKeyDown: (event) => {
2079
+ if (event.key === "Escape" && !event.defaultPrevented) {
2080
+ event.preventDefault();
2081
+ close();
2082
+ }
2083
+ trapTab(event, column.current);
2084
+ },
2085
+ children: [
2086
+ /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2087
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${article !== null ? "has-back" : ""}`, children: [
2088
+ article !== null && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-sheet-back", onClick: () => store.set({ article: null }), "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
2089
+ /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
2090
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: close, "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2091
+ ] }),
2092
+ /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", "data-cbx-sheet-scroll": "", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2093
+ article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2094
+ /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
2095
+ (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2096
+ article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2097
+ t("Open the full article"),
2098
+ " ",
2099
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2100
+ ] }),
2101
+ /* @__PURE__ */ jsx("p", { className: "cbx-eyebrow", children: t("Still stuck?") }),
2102
+ /* @__PURE__ */ jsxs(
2103
+ "form",
2104
+ {
2105
+ className: "cbx-askbar",
2106
+ onSubmit: (event) => {
2107
+ event.preventDefault();
2108
+ const text = followUp.trim();
2109
+ if (text === "") return;
2110
+ store.set({ article: null });
2111
+ setQuestion(text);
2112
+ setAsked(true);
2113
+ void openChat(text);
2114
+ },
2115
+ children: [
2116
+ /* @__PURE__ */ jsx("input", { type: "text", value: followUp, onChange: (event) => setFollowUp(event.target.value), placeholder: t("Ask a follow-up\u2026"), "aria-label": t("Ask a follow-up"), disabled: !chatReady }),
2117
+ /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askbar-send", "aria-label": t("Ask"), disabled: !chatReady, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2118
+ ]
2119
+ }
2120
+ )
2121
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2122
+ unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2123
+ /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2124
+ /* @__PURE__ */ jsx("span", { children: help.enabled ? t("Help is not available right now. The rest of the app works as usual.") : t("Help is not available here yet.") })
2125
+ ] }),
2126
+ /* @__PURE__ */ jsxs("form", { className: "cbx-askbar", onSubmit: submit, children: [
2127
+ /* @__PURE__ */ jsx("input", { ref: searchField, type: "text", value: question, onChange: (event) => setQuestion(event.target.value), placeholder: t("Ask about {page}\u2026", { page: topic }), "aria-label": t("Ask Cbox"), disabled: !chatReady }),
2128
+ /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askbar-send", "aria-label": t("Ask"), disabled: !chatReady, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2129
+ ] }),
2130
+ /* @__PURE__ */ jsxs("p", { className: "cbx-ctxnote", children: [
2131
+ environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
2132
+ t("Cbox sees this page: {page} in {where}", { page: topic, where })
2133
+ ] }),
2134
+ chatProblem && /* @__PURE__ */ jsx("p", { className: "cbx-create-error", role: "alert", children: t("The chat could not be opened. Try again, or use the support portal.") }),
2135
+ asked && chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
2136
+ /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2137
+ " ",
2138
+ t("Talk to a person")
2139
+ ] }),
2140
+ updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-threads", children: [
2141
+ /* @__PURE__ */ jsx("h2", { id: "cbx-help-threads", className: "cbx-eyebrow", children: t("Your conversations") }),
2142
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: updates.map((update) => /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow is-tall ${update.unread ? "is-unread" : ""}`, onClick: () => openUpdate(update), children: [
2143
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: update.kind === "chat" ? /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8 }) : /* @__PURE__ */ jsx(Ticket, { size: 16, strokeWidth: 1.8 }) }),
2144
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2145
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", children: update.title }),
2146
+ update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
2147
+ ] }),
2148
+ update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: 1 }) })
2149
+ ] }, update.id)) })
2150
+ ] }),
2151
+ pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-for", children: [
2152
+ /* @__PURE__ */ jsx("h2", { id: "cbx-help-for", className: "cbx-eyebrow", children: t("For {page}", { page: topic }) }),
2153
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => store.set({ article: item }), children: [
2154
+ /* @__PURE__ */ jsx(FileText, { className: "cbx-grow-icon", size: 18, strokeWidth: 1.7, "aria-hidden": true }),
2155
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.title }),
2156
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2157
+ ] }, item.id)) })
2158
+ ] }),
2159
+ /* @__PURE__ */ jsxs("div", { className: "cbx-pbtns", children: [
2160
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), disabled: !chatReady, children: t("Chat with support") }),
2161
+ portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-pbtn", href: portal, target: "_blank", rel: "noopener", children: [
2162
+ t("Help center"),
2163
+ " ",
2164
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2165
+ ] })
2166
+ ] })
2167
+ ] }),
2168
+ help.enabled && help.sessionUrl !== void 0 && /* @__PURE__ */ jsx("div", { ref: chatHost, className: "cbx-chat-host", "data-view": article !== null ? "article" : "home", children: createElement(SUPPORT_TAG, { "session-url": help.sessionUrl, intent: intentJson }) })
2169
+ ] })
2170
+ ]
2171
+ }
2172
+ ) });
2173
+ }
1606
2174
  return /* @__PURE__ */ jsxs(
1607
2175
  "div",
1608
2176
  {
@@ -1694,9 +2262,9 @@ function HelpColumn({ docked }) {
1694
2262
  results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Searching\u2026") })
1695
2263
  ] })
1696
2264
  ] }),
1697
- help.topic !== void 0 && articles.items.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
2265
+ help.topic !== void 0 && pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
1698
2266
  /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-topic", children: t("For this page") }) }),
1699
- /* @__PURE__ */ jsx("ul", { className: "cbx-list", role: "list", children: articles.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(ArticleRow, { article: item }) }, item.id)) })
2267
+ /* @__PURE__ */ jsx("ul", { className: "cbx-list", role: "list", children: pageArticles.slice(0, 3).map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(ArticleRow, { article: item }) }, item.id)) })
1700
2268
  ] }),
1701
2269
  /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-ask", children: [
1702
2270
  /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-ask", children: t("Ask Cbox") }) }),
@@ -1766,59 +2334,28 @@ function ArticleRow({ article }) {
1766
2334
  ] })
1767
2335
  ] });
1768
2336
  }
1769
- var SHELL_ICONS = {
1770
- activity: Activity,
1771
- "bar-chart": BarChart3,
1772
- bell: Bell,
1773
- "book-open": BookOpen,
1774
- boxes: Boxes,
1775
- briefcase: Briefcase,
1776
- building: Building2,
1777
- calendar: Calendar,
1778
- clock: Clock,
1779
- cloud: Cloud,
1780
- code: Code,
1781
- "credit-card": CreditCard,
1782
- database: Database,
1783
- "file-text": FileText,
1784
- folder: Folder,
1785
- "git-branch": GitBranch,
1786
- globe: Globe,
1787
- "hard-drive": HardDrive,
1788
- home: Home,
1789
- inbox: Inbox,
1790
- key: Key,
1791
- "layout-dashboard": LayoutDashboard,
1792
- "layout-grid": LayoutGrid,
1793
- layers: Layers,
1794
- "life-buoy": LifeBuoy,
1795
- list: List,
1796
- lock: Lock,
1797
- mail: Mail,
1798
- "message-square": MessageSquare,
1799
- network: Network,
1800
- package: Package,
1801
- percent: Percent,
1802
- plug: Plug,
1803
- receipt: Receipt,
1804
- rocket: Rocket,
1805
- search: Search,
1806
- send: Send,
1807
- server: Server,
1808
- settings: Settings,
1809
- shield: Shield,
1810
- "shield-check": ShieldCheck,
1811
- sparkles: Sparkles,
1812
- tag: Tag,
1813
- timer: Timer,
1814
- users: Users,
1815
- wallet: Wallet,
1816
- webhook: Webhook,
1817
- zap: Zap
1818
- };
1819
- function resolveIcon(name, extra = {}) {
1820
- if (name === void 0) return Circle;
1821
- return extra[name] ?? SHELL_ICONS[name] ?? Circle;
2337
+
2338
+ // src/shell/recent.ts
2339
+ var LIMIT = 6;
2340
+ function storageKey(app) {
2341
+ return `cbox_shell_recent_${app}`;
2342
+ }
2343
+ function recentPages(app) {
2344
+ try {
2345
+ const raw = window.localStorage.getItem(storageKey(app));
2346
+ const parsed = raw === null ? [] : JSON.parse(raw);
2347
+ return Array.isArray(parsed) ? parsed.filter((row) => typeof row === "object" && row !== null && typeof row.title === "string" && typeof row.url === "string" && row.url.startsWith("/")) : [];
2348
+ } catch {
2349
+ return [];
2350
+ }
2351
+ }
2352
+ function rememberPage(app, page) {
2353
+ if (typeof window === "undefined" || !page.url.startsWith("/")) return;
2354
+ try {
2355
+ const next = [page, ...recentPages(app).filter((row) => row.url !== page.url)].slice(0, LIMIT);
2356
+ window.localStorage.setItem(storageKey(app), JSON.stringify(next));
2357
+ } catch {
2358
+ }
1822
2359
  }
1823
2360
  function navUrl(entry) {
1824
2361
  return entry.url ?? entry.href ?? "#";
@@ -1862,153 +2399,17 @@ function NavPageList({ pages, renderPage }) {
1862
2399
  ] }, `run-${index}`)
1863
2400
  ) });
1864
2401
  }
1865
- function Sheet({ label, side, onClose, children, head }) {
1866
- const { t } = useShell();
1867
- const panel = useRef(null);
1868
- const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
1869
- useEffect(() => {
1870
- panel.current?.focus();
1871
- const back = opener.current;
1872
- return () => {
1873
- if (back instanceof HTMLElement) back.focus();
1874
- };
1875
- }, []);
1876
- return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-sheet-backdrop", onPointerDown: (event) => {
1877
- if (event.target === event.currentTarget) onClose();
1878
- }, children: /* @__PURE__ */ jsxs(
1879
- "div",
1880
- {
1881
- ref: panel,
1882
- className: `cbx-sheet cbx-sheet-${side}`,
1883
- role: "dialog",
1884
- "aria-modal": "true",
1885
- "aria-label": label,
1886
- tabIndex: -1,
1887
- onKeyDown: (event) => {
1888
- if (event.key === "Escape" && !event.defaultPrevented) {
1889
- event.preventDefault();
1890
- onClose();
1891
- }
1892
- trapTab(event, panel.current);
1893
- },
1894
- children: [
1895
- /* @__PURE__ */ jsxs("div", { className: "cbx-sheet-head", children: [
1896
- head ?? /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title", children: label }),
1897
- /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: onClose, "aria-label": t("Close"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
1898
- ] }),
1899
- /* @__PURE__ */ jsx("div", { className: "cbx-sheet-body", children })
1900
- ]
1901
- }
1902
- ) });
1903
- }
1904
- function NavSheet({ onClose }) {
1905
- const { shell, t, Link, icons } = useShell();
1906
- const [view, setView] = useState("nav");
1907
- if (view === "apps") {
1908
- return /* @__PURE__ */ jsx(
1909
- Sheet,
1910
- {
1911
- label: t("Switch app"),
1912
- side: "left",
1913
- onClose,
1914
- head: /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-row cbx-row-action cbx-back", onClick: () => setView("nav"), children: [
1915
- /* @__PURE__ */ jsx(ArrowLeft, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1916
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Switch app") })
1917
- ] }),
1918
- children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false })
1919
- }
1920
- );
1921
- }
1922
- return /* @__PURE__ */ jsxs(Sheet, { label: shell.app.name, side: "left", onClose, children: [
1923
- /* @__PURE__ */ jsx("nav", { "aria-label": t("Navigation"), className: "cbx-list", children: shell.nav.areas.map((area) => {
1924
- const Icon = resolveIcon(area.icon, icons);
1925
- const activeArea = area.key === shell.nav.activeArea;
1926
- return /* @__PURE__ */ jsxs("div", { className: "cbx-sheet-area", children: [
1927
- /* @__PURE__ */ jsxs(Link, { href: navUrl(area), className: `cbx-row cbx-row-action ${activeArea ? (area.pages ?? []).length > 1 ? "is-open" : "is-current" : ""}`, "aria-current": activeArea && (area.pages ?? []).length <= 1 ? "page" : void 0, onClick: onClose, children: [
1928
- /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1929
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: area.label }),
1930
- areaLocked(area) && /* @__PURE__ */ jsxs("span", { className: "cbx-nav-lock", title: t("Not in your plan"), children: [
1931
- /* @__PURE__ */ jsx(Lock, { size: 13, strokeWidth: 1.9, "aria-hidden": true }),
1932
- /* @__PURE__ */ jsx("span", { className: "cbx-sr-only", children: t("(locked)") })
1933
- ] })
1934
- ] }),
1935
- (area.pages ?? []).length > 1 && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-pages", children: /* @__PURE__ */ jsx(
1936
- NavPageList,
1937
- {
1938
- pages: area.pages ?? [],
1939
- renderPage: (page) => {
1940
- const on = activeArea && page.key === shell.nav.activePage;
1941
- return /* @__PURE__ */ jsxs(Link, { href: navUrl(page), className: `cbx-row cbx-row-action ${on ? "is-current" : ""} ${page.locked === true ? "is-locked" : ""}`, "aria-current": on ? "page" : void 0, "data-locked": page.locked === true ? "true" : void 0, onClick: onClose, children: [
1942
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: page.label }),
1943
- /* @__PURE__ */ jsx(NavPageMarks, { page })
1944
- ] }, page.key);
1945
- }
1946
- }
1947
- ) })
1948
- ] }, area.key);
1949
- }) }),
1950
- /* @__PURE__ */ jsxs("div", { className: "cbx-list cbx-list-foot", children: [
1951
- /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-row cbx-row-action", onClick: () => setView("apps"), children: [
1952
- /* @__PURE__ */ jsx(LayoutGrid, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1953
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Switch app") })
1954
- ] }),
1955
- shell.notifications.enabled && /* @__PURE__ */ jsxs(Link, { href: shell.notifications.url, className: "cbx-row cbx-row-action", onClick: onClose, children: [
1956
- /* @__PURE__ */ jsx(Bell, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1957
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Notifications") }),
1958
- shell.notifications.unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-count is-inline", children: shell.notifications.unread })
1959
- ] })
1960
- ] }),
1961
- /* @__PURE__ */ jsx(AccountMenu, { inline: true, onDone: onClose })
1962
- ] });
1963
- }
1964
- function ContextSheet({ onClose }) {
1965
- const { shell, t, switchTo } = useShell();
1966
- const [organization, outer, inner] = shell.context.levels;
1967
- return /* @__PURE__ */ jsxs(Sheet, { label: t("Where you are"), side: "bottom", onClose, children: [
1968
- organization !== void 0 && /* @__PURE__ */ jsx("section", { className: "cbx-sheet-level", "aria-label": organization.label, children: /* @__PURE__ */ jsx(
1969
- LevelPane,
1970
- {
1971
- level: organization,
1972
- currentId: organization.current.id,
1973
- heading: pluralOf(organization),
1974
- createLabel: t("New {thing}", { thing: organization.label.toLowerCase() }),
1975
- onPick: (item) => switchTo({ [organization.key]: item.id })
1976
- }
1977
- ) }),
1978
- outer !== void 0 && /* @__PURE__ */ jsx("section", { className: "cbx-sheet-level", "aria-label": outer.label, children: /* @__PURE__ */ jsx(
1979
- LevelPane,
1980
- {
1981
- level: outer,
1982
- parent: organization?.current.id,
1983
- currentId: outer.current.id,
1984
- heading: pluralOf(outer),
1985
- createLabel: t("New {thing}", { thing: outer.label.toLowerCase() }),
1986
- onPick: (item) => void pickKeepingEnvironment(outer, inner, item, switchTo)
1987
- }
1988
- ) }),
1989
- outer !== void 0 && inner !== void 0 && /* @__PURE__ */ jsx("section", { className: "cbx-sheet-level", "aria-label": inner.label, children: /* @__PURE__ */ jsx(
1990
- LevelPane,
1991
- {
1992
- level: inner,
1993
- parent: outer.current.id,
1994
- currentId: inner.current.id,
1995
- heading: t("{things} in {name}", { things: pluralOf(inner), name: outer.current.name }),
1996
- createLabel: t("New {thing} in {name}", { thing: inner.label.toLowerCase(), name: outer.current.name }),
1997
- onPick: (item) => switchTo({ [outer.key]: outer.current.id, [inner.key]: item.id })
1998
- }
1999
- ) })
2000
- ] });
2001
- }
2002
- var GROUP_LIMIT = 5;
2003
- function matchScore(text, query2) {
2004
- const haystack = text.toLowerCase();
2005
- const terms = query2.toLowerCase().trim().split(/\s+/).filter(Boolean);
2006
- if (terms.length === 0) return 1;
2007
- let score = 0;
2008
- for (const term of terms) {
2009
- const at = haystack.indexOf(term);
2010
- if (at < 0) return 0;
2011
- score += at === 0 ? 3 : haystack[at - 1] === " " ? 2 : 1;
2402
+ var GROUP_LIMIT = 5;
2403
+ var GROUP_KIND = { page: "actions", switch: "actions", actions: "actions", goto: "actions", records: "records", pages: "pages", docs: "help" };
2404
+ function matchScore(text, query2) {
2405
+ const haystack = text.toLowerCase();
2406
+ const terms = query2.toLowerCase().trim().split(/\s+/).filter(Boolean);
2407
+ if (terms.length === 0) return 1;
2408
+ let score = 0;
2409
+ for (const term of terms) {
2410
+ const at = haystack.indexOf(term);
2411
+ if (at < 0) return 0;
2412
+ score += at === 0 ? 3 : haystack[at - 1] === " " ? 2 : 1;
2012
2413
  }
2013
2414
  return score;
2014
2415
  }
@@ -2026,7 +2427,7 @@ function localPages(shell, query2, open, lockedLabel) {
2026
2427
  }
2027
2428
  return entries.map((entry) => ({ entry, score: matchScore(`${entry.title} ${entry.subtitle ?? ""}`, query2) })).filter(({ score }) => score > 0).sort((a, b) => b.score - a.score).map(({ entry }) => {
2028
2429
  const Icon = resolveIcon(entry.icon);
2029
- return { id: entry.id, title: entry.title, subtitle: entry.subtitle, href: entry.url, icon: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(entry.url, newTab) };
2430
+ return { id: entry.id, title: entry.title, subtitle: entry.subtitle, href: entry.url, kind: "pages", icon: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(entry.url, newTab) };
2030
2431
  });
2031
2432
  }
2032
2433
  function rows(body, group) {
@@ -2039,7 +2440,8 @@ function rows(body, group) {
2039
2440
  return Array.isArray(data) ? data.filter((row) => typeof row === "object" && row !== null) : [];
2040
2441
  }
2041
2442
  function CommandPalette({ onClose }) {
2042
- const { shell, t, navigate, switchTo, openArticle, ask } = useShell();
2443
+ const { shell, t, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2444
+ const [scope, setScope] = useState("all");
2043
2445
  const [input, setInput] = useState("");
2044
2446
  const [query2, setQuery] = useState("");
2045
2447
  const [groups, setGroups] = useState({});
@@ -2048,14 +2450,17 @@ function CommandPalette({ onClose }) {
2048
2450
  const [activeKey, setActiveKey] = useState(null);
2049
2451
  const field = useRef(null);
2050
2452
  const dialog = useRef(null);
2453
+ const scrim = useRef(null);
2051
2454
  const id = useId();
2455
+ useScrollLock();
2456
+ useSheetDrag({ panel: dialog, scrim, size: "full", onClose, enabled: mobile });
2052
2457
  const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2053
2458
  useEffect(() => {
2054
2459
  if (canAutofocus()) field.current?.focus();
2055
2460
  else dialog.current?.focus();
2056
2461
  const back = opener.current;
2057
2462
  return () => {
2058
- if (back instanceof HTMLElement) back.focus();
2463
+ if (back instanceof HTMLElement) back.focus({ preventScroll: true });
2059
2464
  };
2060
2465
  }, []);
2061
2466
  useEffect(() => {
@@ -2083,17 +2488,26 @@ function CommandPalette({ onClose }) {
2083
2488
  setGroups({});
2084
2489
  return () => controller.abort();
2085
2490
  }
2086
- if (shell.palette.searchUrl !== void 0) {
2491
+ if (searchRecords !== void 0) {
2492
+ run(
2493
+ "records",
2494
+ async () => (await searchRecords(q2, signal)).flatMap((row) => {
2495
+ const url = safeUrl(row.url);
2496
+ if (url === void 0) return [];
2497
+ return [{ id: `record:${row.id}`, title: row.title, subtitle: row.subtitle, href: url, kind: "records", icon: /* @__PURE__ */ jsx(FileText, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(url, newTab) }];
2498
+ })
2499
+ );
2500
+ } else if (shell.palette.searchUrl !== void 0) {
2087
2501
  run(
2088
2502
  "records",
2089
2503
  async () => rows(await requestJson(withQuery(shell.palette.searchUrl, { q: q2, group: "records" }), { signal }), "records").flatMap((row) => {
2090
2504
  const url = safeUrl(row.url);
2091
2505
  if (typeof row.title !== "string" || url === void 0) return [];
2092
- return [{ id: `record:${String(row.id ?? url)}`, title: row.title, subtitle: typeof row.subtitle === "string" ? row.subtitle : void 0, href: url, icon: /* @__PURE__ */ jsx(FileText, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(url, newTab) }];
2506
+ return [{ id: `record:${String(row.id ?? url)}`, title: row.title, subtitle: typeof row.subtitle === "string" ? row.subtitle : void 0, href: url, kind: "records", icon: /* @__PURE__ */ jsx(FileText, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(url, newTab) }];
2093
2507
  })
2094
2508
  );
2095
2509
  }
2096
- const organization = shell.context.levels[0];
2510
+ const organization2 = shell.context.levels[0];
2097
2511
  run("goto", async () => {
2098
2512
  const loads = [];
2099
2513
  const kitGoto = shell.palette.gotoUrl === void 0 && shell.palette.searchUrl !== void 0;
@@ -2108,15 +2522,15 @@ function CommandPalette({ onClose }) {
2108
2522
  )
2109
2523
  );
2110
2524
  }
2111
- if (organization !== void 0 && !kitGoto) {
2525
+ if (organization2 !== void 0 && !kitGoto) {
2112
2526
  loads.push(
2113
- requestJson(withQuery(organization.listUrl, { q: q2, limit: "5" }), { signal }).then(
2527
+ requestJson(withQuery(organization2.listUrl, { q: q2, limit: "5" }), { signal }).then(
2114
2528
  (body) => rows(body).flatMap((row) => {
2115
2529
  if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.name !== "string") return [];
2116
2530
  const orgId = String(row.id);
2117
- return [{ id: `org:${orgId}`, title: row.name, subtitle: organization.label, icon: /* @__PURE__ */ jsx("span", { className: "cbx-chip cbx-chip-soft", "aria-hidden": "true", children: typeof row.initials === "string" ? row.initials : initialsOf(row.name) }), run: () => {
2531
+ return [{ id: `org:${orgId}`, title: row.name, subtitle: organization2.label, icon: /* @__PURE__ */ jsx("span", { className: "cbx-chip cbx-chip-soft", "aria-hidden": "true", children: typeof row.initials === "string" ? row.initials : initialsOf(row.name) }), run: () => {
2118
2532
  onClose();
2119
- switchTo({ [organization.key]: orgId });
2533
+ switchTo({ [organization2.key]: orgId });
2120
2534
  } }];
2121
2535
  })
2122
2536
  )
@@ -2152,6 +2566,7 @@ function CommandPalette({ onClose }) {
2152
2566
  title: article.title,
2153
2567
  subtitle: article.excerpt,
2154
2568
  href: article.url,
2569
+ kind: "help",
2155
2570
  icon: /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2156
2571
  run: (newTab) => {
2157
2572
  if (newTab && article.url !== void 0) {
@@ -2165,39 +2580,123 @@ function CommandPalette({ onClose }) {
2165
2580
  );
2166
2581
  }
2167
2582
  return () => controller.abort();
2168
- }, [query2, shell]);
2583
+ }, [query2, shell, searchRecords]);
2169
2584
  const q = input.trim();
2585
+ const topic = helpTopicName(shell);
2586
+ const organization = shell.context.levels[0];
2587
+ const environment = environmentLevel(shell.context.levels);
2588
+ const envIndex = environment !== void 0 ? shell.context.levels.indexOf(environment) : -1;
2589
+ const envParent = envIndex > 0 ? shell.context.levels[envIndex - 1] : void 0;
2590
+ const environments = useContextList(environment?.listUrl, { parent: envParent?.current.id, enabled: environment !== void 0 });
2170
2591
  const pages = useMemo(() => localPages(shell, q, open, t("Locked")), [shell, q, t]);
2171
- const actions = useMemo(
2172
- () => shell.palette.actions.filter((action) => matchScore(`${action.label} ${(action.keywords ?? []).join(" ")}`, q) > 0).map((action) => {
2173
- const Icon = action.icon !== void 0 ? resolveIcon(action.icon) : Zap;
2174
- return {
2175
- id: `action:${action.id}`,
2176
- title: action.label,
2177
- href: action.method === "post" ? void 0 : action.url,
2178
- icon: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2179
- run: (newTab) => {
2180
- if (!newTab) onClose();
2181
- navigate(action.url, { method: action.method ?? "get", newTab: newTab && action.method !== "post" });
2592
+ const toItem2 = (action, prefix) => {
2593
+ const Icon = action.icon !== void 0 ? resolveIcon(action.icon) : Zap;
2594
+ return {
2595
+ id: `${prefix}:${action.id}`,
2596
+ title: action.label,
2597
+ subtitle: action.hint,
2598
+ href: action.method === "post" ? void 0 : action.url,
2599
+ kind: "actions",
2600
+ icon: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2601
+ run: (newTab) => {
2602
+ if (!newTab) onClose();
2603
+ if (!newTab && action.create !== void 0 && canCreate && findCreatable(shell, action.create) !== void 0) {
2604
+ openCreate(action.create);
2605
+ return;
2182
2606
  }
2183
- };
2184
- }),
2185
- [shell, q]
2186
- );
2187
- const sections = [
2188
- { key: "pages", label: t("Pages"), state: { status: "ready", items: pages } },
2189
- { key: "records", label: t("Records"), state: groups.records ?? { status: "idle", items: [] } },
2190
- { key: "actions", label: t("Actions"), state: { status: "ready", items: actions } },
2607
+ navigate(action.url, { method: action.method ?? "get", newTab: newTab && action.method !== "post" });
2608
+ }
2609
+ };
2610
+ };
2611
+ const matches2 = (item, words = []) => matchScore(`${item.title} ${item.subtitle ?? ""} ${words.join(" ")}`, q) > 0;
2612
+ const createItem2 = (key) => {
2613
+ const creatable = findCreatable(shell, key);
2614
+ if (creatable === void 0 || !canCreate) return null;
2615
+ return { id: `create:${key}`, title: t("New {thing}", { thing: creatable.label.toLowerCase() }), kind: "actions", icon: /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: () => {
2616
+ onClose();
2617
+ openCreate(key);
2618
+ } };
2619
+ };
2620
+ const pageCreate = shell.page?.create !== void 0 ? createItem2(shell.page.create) : null;
2621
+ const pageActions = [...pageCreate !== null ? [pageCreate] : [], ...(shell.page?.actions ?? []).map((action) => toItem2(action, "page"))];
2622
+ const globalActions = shell.palette.actions.map((action) => toItem2(action, "action"));
2623
+ const switchItems = [];
2624
+ if (environment !== void 0) {
2625
+ environments.items.filter((item) => item.id !== environment.current.id).slice(0, 3).forEach(
2626
+ (item) => switchItems.push({
2627
+ id: `switch:${item.id}`,
2628
+ title: t("Switch to {name}", { name: item.name }),
2629
+ subtitle: environment.label,
2630
+ kind: "actions",
2631
+ icon: /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
2632
+ run: () => {
2633
+ onClose();
2634
+ switchTo(envParent !== void 0 ? { [envParent.key]: envParent.current.id, [environment.key]: item.id } : { [environment.key]: item.id });
2635
+ }
2636
+ })
2637
+ );
2638
+ }
2639
+ if (organization !== void 0) {
2640
+ switchItems.push({
2641
+ id: "switch:organization",
2642
+ title: t("Switch {thing}", { thing: organization.label.toLowerCase() }),
2643
+ subtitle: t("Now {name}", { name: organization.current.name }),
2644
+ kind: "actions",
2645
+ icon: /* @__PURE__ */ jsx(ArrowLeftRight, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2646
+ run: () => {
2647
+ onClose();
2648
+ openContext(organization.key, true);
2649
+ }
2650
+ });
2651
+ }
2652
+ const recent = useMemo(() => {
2653
+ if (shell.palette.recent !== void 0) {
2654
+ return shell.palette.recent.flatMap((row) => {
2655
+ const url = safeUrl(row.url);
2656
+ return url === void 0 ? [] : [{ id: `recent:${row.id}`, title: row.title, subtitle: row.subtitle, href: url, kind: "records", icon: /* @__PURE__ */ jsx(Clock, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(url, newTab) }];
2657
+ });
2658
+ }
2659
+ const here = typeof window !== "undefined" ? window.location.pathname + window.location.search + window.location.hash : "";
2660
+ return recentPages(shell.app.key).filter((row) => row.url !== here).slice(0, 4).map((row) => ({ id: `recent:${row.url}`, title: row.title, subtitle: row.area, href: row.url, kind: "pages", icon: /* @__PURE__ */ jsx(Clock, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: (newTab) => open(row.url, newTab) }));
2661
+ }, [shell]);
2662
+ const ready = (items) => ({ status: "ready", items });
2663
+ const sections = q === "" ? [
2664
+ pageActions.length > 0 ? { key: "page", label: t("On {page}", { page: topic }), state: ready(pageActions) } : { key: "actions", label: t("Actions"), state: ready(globalActions) },
2665
+ { key: "recent", label: t("Recent"), state: ready(recent) },
2666
+ { key: "switch", label: t("Switch"), state: ready(switchItems) }
2667
+ ] : [
2668
+ {
2669
+ key: "actions",
2670
+ label: t("Actions"),
2671
+ state: ready(
2672
+ [
2673
+ ...pageActions.filter((item) => matches2(item, (shell.page?.actions ?? []).find((action) => `page:${action.id}` === item.id)?.keywords)),
2674
+ ...globalActions.filter((item) => matches2(item, shell.palette.actions.find((action) => `action:${action.id}` === item.id)?.keywords)),
2675
+ ...(shell.create?.items ?? []).filter((creatable) => creatable.key !== shell.page?.create).map((creatable) => createItem2(creatable.key)).filter((item) => item !== null && matches2(item, findCreatable(shell, item.id.slice("create:".length))?.keywords)),
2676
+ ...switchItems.filter((item) => matches2(item))
2677
+ ]
2678
+ )
2679
+ },
2191
2680
  { key: "goto", label: t("Go to"), state: groups.goto ?? { status: "idle", items: [] } },
2192
- { key: "docs", label: t("Docs and help"), state: groups.docs ?? { status: "idle", items: [] } }
2681
+ { key: "records", label: t("Records"), state: groups.records ?? { status: "idle", items: [] } },
2682
+ { key: "pages", label: t("Pages"), state: ready(pages) },
2683
+ { key: "docs", label: t("Help"), state: groups.docs ?? { status: "idle", items: [] } }
2193
2684
  ];
2685
+ const scoped = sections.map((section) => {
2686
+ if (scope === "all") return section;
2687
+ const kind = section.key === "recent" || section.key === "ask" ? null : GROUP_KIND[section.key];
2688
+ if (kind !== null && kind !== scope) return null;
2689
+ return { ...section, state: { ...section.state, items: section.state.items.filter((item) => item.kind === void 0 || item.kind === scope) } };
2690
+ }).filter((section) => section !== null);
2691
+ sections.length = 0;
2692
+ sections.push(...scoped);
2194
2693
  if (q !== "") {
2195
2694
  sections.push({
2196
2695
  key: "ask",
2197
2696
  label: t("Ask Cbox"),
2198
2697
  state: {
2199
2698
  status: "ready",
2200
- items: [{ id: "ask", title: t("Ask Cbox: \u201C{query}\u201D", { query: q }), subtitle: t("About this page"), icon: /* @__PURE__ */ jsx(Sparkles, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: () => {
2699
+ items: [{ id: "ask", title: t("Ask Cbox: \u201C{query}\u201D", { query: q }), subtitle: t("Answers with what you see on {page}", { page: topic }), icon: /* @__PURE__ */ jsx(Sparkles, { size: 16, strokeWidth: 1.8, "aria-hidden": true }), run: () => {
2201
2700
  onClose();
2202
2701
  ask(q);
2203
2702
  } }]
@@ -2216,7 +2715,7 @@ function CommandPalette({ onClose }) {
2216
2715
  });
2217
2716
  const keyOf = (option) => option.kind === "item" ? `${option.group}:${option.item.id}` : `all:${option.group}`;
2218
2717
  const debounced = q === query2.trim() && groupsFor === q;
2219
- const current = (group) => group === "pages" || group === "actions" || debounced && sections.find((section) => section.key === group)?.state.status === "ready";
2718
+ const current = (group) => group === "pages" || group === "actions" || group === "page" || group === "recent" || group === "switch" || debounced && sections.find((section) => section.key === group)?.state.status === "ready";
2220
2719
  const busy = !debounced || sections.some((section) => section.state.status === "loading");
2221
2720
  const firstResult = options.find((option) => option.group !== "ask" && current(option.group));
2222
2721
  const autoKey = firstResult !== void 0 ? keyOf(firstResult) : !busy && options[0] !== void 0 ? keyOf(options[0]) : null;
@@ -2266,32 +2765,41 @@ function CommandPalette({ onClose }) {
2266
2765
  }
2267
2766
  };
2268
2767
  const activeOption = options[active];
2269
- return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-palette-backdrop", onPointerDown: (event) => {
2270
- if (event.target === event.currentTarget) onClose();
2271
- }, children: /* @__PURE__ */ jsxs("div", { ref: dialog, className: "cbx-palette", role: "dialog", "aria-modal": "true", "aria-label": t("Search"), tabIndex: -1, onKeyDown, children: [
2272
- /* @__PURE__ */ jsxs("div", { className: "cbx-palette-search", children: [
2273
- /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2274
- /* @__PURE__ */ jsx(
2275
- "input",
2276
- {
2277
- ref: field,
2278
- type: "search",
2279
- role: "combobox",
2280
- "aria-expanded": "true",
2281
- "aria-controls": `${id}-list`,
2282
- "aria-activedescendant": activeOption !== void 0 ? `${id}-${active}` : void 0,
2283
- "aria-autocomplete": "list",
2284
- "aria-label": shell.palette.placeholder ?? t("Search or ask\u2026"),
2285
- placeholder: shell.palette.placeholder ?? t("Search or ask\u2026"),
2286
- value: input,
2287
- onChange: (event) => setInput(event.target.value),
2288
- autoComplete: "off",
2289
- spellCheck: false
2290
- }
2291
- ),
2292
- /* @__PURE__ */ jsx("kbd", { className: "cbx-kbd", children: "Esc" })
2768
+ const scopes = [
2769
+ { value: "all", label: t("All") },
2770
+ { value: "actions", label: t("Actions") },
2771
+ { value: "records", label: t("Records") },
2772
+ { value: "pages", label: t("Pages") },
2773
+ { value: "help", label: t("Help") }
2774
+ ];
2775
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: `cbx-overlay cbx-palette-backdrop ${mobile ? "is-sheet" : ""}`, ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs("div", { ref: dialog, className: `cbx-palette ${mobile ? "is-sheet" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": t("Search"), tabIndex: -1, onKeyDown, children: [
2776
+ mobile && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2777
+ /* @__PURE__ */ jsxs("div", { className: `cbx-palette-search ${mobile ? "cbx-sheet-grab" : ""}`, children: [
2778
+ /* @__PURE__ */ jsxs("label", { className: "cbx-palette-field", children: [
2779
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2780
+ /* @__PURE__ */ jsx(
2781
+ "input",
2782
+ {
2783
+ ref: field,
2784
+ type: "search",
2785
+ role: "combobox",
2786
+ "aria-expanded": "true",
2787
+ "aria-controls": `${id}-list`,
2788
+ "aria-activedescendant": activeOption !== void 0 ? `${id}-${active}` : void 0,
2789
+ "aria-autocomplete": "list",
2790
+ "aria-label": shell.palette.placeholder ?? t("Search or ask\u2026"),
2791
+ placeholder: shell.palette.placeholder ?? (mobile ? t("Search, act or ask\u2026") : t("Search or ask\u2026")),
2792
+ value: input,
2793
+ onChange: (event) => setInput(event.target.value),
2794
+ autoComplete: "off",
2795
+ spellCheck: false
2796
+ }
2797
+ )
2798
+ ] }),
2799
+ mobile ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-palette-cancel", onClick: onClose, children: t("Cancel") }) : /* @__PURE__ */ jsx("kbd", { className: "cbx-kbd", children: "Esc" })
2293
2800
  ] }),
2294
- /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", children: [
2801
+ /* @__PURE__ */ jsx("div", { className: "cbx-scopes", role: "radiogroup", "aria-label": t("Scope"), children: scopes.map((item) => /* @__PURE__ */ jsx("button", { type: "button", role: "radio", "aria-checked": scope === item.value, className: `cbx-scope ${scope === item.value ? "is-on" : ""}`, onClick: () => setScope(item.value), children: item.label }, item.value)) }),
2802
+ /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", "data-cbx-sheet-scroll": "", children: [
2295
2803
  rendered.map((section) => {
2296
2804
  const loading = section.state.status === "loading" && section.state.items.length === 0;
2297
2805
  if (section.count === 0 && !loading) return null;
@@ -2301,7 +2809,7 @@ function CommandPalette({ onClose }) {
2301
2809
  section.state.status === "loading" && /* @__PURE__ */ jsx("span", { className: "cbx-palette-busy", "aria-hidden": "true" })
2302
2810
  ] }),
2303
2811
  loading && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", "aria-live": "polite", children: t("Searching\u2026") }),
2304
- options.slice(section.start, section.start + section.count).map((option, offset) => {
2812
+ section.count > 0 && /* @__PURE__ */ jsx("div", { className: "cbx-palette-rows", role: "presentation", children: options.slice(section.start, section.start + section.count).map((option, offset) => {
2305
2813
  const index = section.start + offset;
2306
2814
  const on = index === active;
2307
2815
  return /* @__PURE__ */ jsx(
@@ -2315,8 +2823,10 @@ function CommandPalette({ onClose }) {
2315
2823
  onClick: (event) => choose(option, event.metaKey || event.ctrlKey),
2316
2824
  children: option.kind === "item" ? /* @__PURE__ */ jsxs(Fragment, { children: [
2317
2825
  /* @__PURE__ */ jsx("span", { className: "cbx-row-icon", children: option.item.icon }),
2318
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", title: option.item.title, children: option.item.title }),
2319
- option.item.subtitle !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-row-label cbx-truncate", children: option.item.subtitle }),
2826
+ /* @__PURE__ */ jsxs("span", { className: "cbx-row-text", children: [
2827
+ /* @__PURE__ */ jsx("span", { className: "cbx-row-name", title: option.item.title, children: option.item.title }),
2828
+ option.item.subtitle !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-row-label cbx-truncate", children: option.item.subtitle })
2829
+ ] }),
2320
2830
  on && /* @__PURE__ */ jsx(CornerDownLeft, { className: "cbx-row-trail", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2321
2831
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2322
2832
  /* @__PURE__ */ jsx("span", { className: "cbx-row-icon", children: /* @__PURE__ */ jsx(ArrowRight, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) }),
@@ -2325,7 +2835,7 @@ function CommandPalette({ onClose }) {
2325
2835
  },
2326
2836
  option.kind === "item" ? option.item.id : `all:${option.group}`
2327
2837
  );
2328
- })
2838
+ }) })
2329
2839
  ] }, section.key);
2330
2840
  }),
2331
2841
  options.length === 0 && q !== "" && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: q }) })
@@ -2350,6 +2860,752 @@ function CommandPalette({ onClose }) {
2350
2860
  ] })
2351
2861
  ] }) });
2352
2862
  }
2863
+ function Sheet({
2864
+ label,
2865
+ side = "bottom",
2866
+ onClose,
2867
+ children,
2868
+ title,
2869
+ back,
2870
+ size,
2871
+ className,
2872
+ bodyClassName
2873
+ }) {
2874
+ const { t } = useShell();
2875
+ const panel = useRef(null);
2876
+ const scrim = useRef(null);
2877
+ useScrollLock();
2878
+ useSheetDrag({ panel, scrim, size: size ?? "fit", onClose, enabled: side === "bottom" });
2879
+ const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2880
+ useEffect(() => {
2881
+ panel.current?.focus();
2882
+ const restore = opener.current;
2883
+ return () => {
2884
+ if (restore instanceof HTMLElement && restore.isConnected) restore.focus({ preventScroll: true });
2885
+ };
2886
+ }, []);
2887
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs(
2888
+ "div",
2889
+ {
2890
+ ref: panel,
2891
+ className: `cbx-sheet cbx-sheet-${side} ${size !== void 0 ? `is-${size}` : ""} ${className ?? ""}`,
2892
+ role: "dialog",
2893
+ "aria-modal": "true",
2894
+ "aria-label": label,
2895
+ tabIndex: -1,
2896
+ onKeyDown: (event) => {
2897
+ if (event.key === "Escape" && !event.defaultPrevented) {
2898
+ event.preventDefault();
2899
+ onClose();
2900
+ }
2901
+ trapTab(event, panel.current);
2902
+ },
2903
+ children: [
2904
+ side === "bottom" && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2905
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head ${side === "bottom" ? "cbx-sheet-grab" : ""} ${back !== void 0 ? "has-back" : ""}`, children: [
2906
+ back !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-sheet-back", onClick: back.onBack, "aria-label": back.label, children: [
2907
+ /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }),
2908
+ back.text !== void 0 && /* @__PURE__ */ jsx("span", { children: back.text })
2909
+ ] }),
2910
+ /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: title ?? label }),
2911
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: onClose, "aria-label": t("Close"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2912
+ ] }),
2913
+ /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, "data-cbx-sheet-scroll": "", children })
2914
+ ]
2915
+ }
2916
+ ) });
2917
+ }
2918
+ function findCreatable(shell, key) {
2919
+ if (key === void 0 || key === null) return void 0;
2920
+ return shell.create?.items.find((item) => item.key === key);
2921
+ }
2922
+ function pageCreateKey(shell) {
2923
+ return findCreatable(shell, shell.page?.create)?.key ?? findCreatable(shell, shell.create?.default)?.key ?? null;
2924
+ }
2925
+ function createLabel(shell, t) {
2926
+ const own = findCreatable(shell, shell.page?.create);
2927
+ return own !== void 0 ? t("New {thing}", { thing: own.label.toLowerCase() }) : t("Create");
2928
+ }
2929
+ function CreateSheet({ onClose }) {
2930
+ const { shell, t, mobile, createKey, renderCreate } = useShell();
2931
+ const [stack, setStack] = useState(() => findCreatable(shell, createKey) !== void 0 ? [{ kind: "tree" }, { kind: "form", key: createKey }] : [{ kind: "tree" }]);
2932
+ const top = stack[stack.length - 1];
2933
+ const below = stack.length > 1 ? stack[stack.length - 2] : null;
2934
+ const environmentLevelItem = environmentLevel(shell.context.levels)?.current ?? null;
2935
+ const notLive = environmentLevelItem !== null && isLive(environmentLevelItem) === false;
2936
+ const name = (entry) => entry === null ? "" : entry.kind === "tree" ? t("Create") : findCreatable(shell, entry.key)?.label ?? entry.key;
2937
+ const pop = () => setStack((current) => current.length > 1 ? current.slice(0, -1) : current);
2938
+ const title = top.kind === "tree" ? t("Create") : t("New {thing}", { thing: name(top).toLowerCase() });
2939
+ return /* @__PURE__ */ jsxs(
2940
+ Sheet,
2941
+ {
2942
+ label: title,
2943
+ side: mobile ? "bottom" : "right",
2944
+ size: "tall",
2945
+ onClose,
2946
+ className: "cbx-create-sheet",
2947
+ back: below !== null ? { label: t("Back to {thing}", { thing: name(below) }), text: name(below), onBack: pop } : void 0,
2948
+ children: [
2949
+ top.kind === "tree" && /* @__PURE__ */ jsx(CreateTree, { onPick: (key) => setStack([{ kind: "tree" }, { kind: "form", key }]) }),
2950
+ notLive && top.kind === "form" && /* @__PURE__ */ jsxs("p", { className: "cbx-create-env", role: "note", children: [
2951
+ /* @__PURE__ */ jsx(ToneSquare, { tone: environmentLevelItem.tone }),
2952
+ t("Creating in {environment}, not production", { environment: environmentLevelItem.name })
2953
+ ] }),
2954
+ stack.map((entry, index) => {
2955
+ if (entry.kind !== "form") return null;
2956
+ const creatable = findCreatable(shell, entry.key);
2957
+ if (creatable === void 0) return null;
2958
+ const under = stack[index - 1];
2959
+ const parent = under?.kind === "form" ? findCreatable(shell, under.key) ?? null : null;
2960
+ const form = {
2961
+ creatable,
2962
+ parent,
2963
+ submitLabel: parent !== null ? t("Create and use in {thing}", { thing: parent.label.toLowerCase() }) : creatable.submitLabel ?? t("Create {thing}", { thing: creatable.label.toLowerCase() }),
2964
+ createRef: (key, onCreated) => {
2965
+ if (findCreatable(shell, key) === void 0) return;
2966
+ setStack((current) => [...current.slice(0, index + 1), { kind: "form", key, onCreated }]);
2967
+ },
2968
+ done: (created) => {
2969
+ if (parent === null) {
2970
+ onClose();
2971
+ return;
2972
+ }
2973
+ setStack((current) => current.slice(0, index));
2974
+ if (created !== void 0) entry.onCreated?.(created);
2975
+ },
2976
+ close: onClose,
2977
+ environment: environmentLevelItem
2978
+ };
2979
+ const body = renderCreate?.(form) ?? null;
2980
+ 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}`);
2981
+ })
2982
+ ]
2983
+ }
2984
+ );
2985
+ }
2986
+ function CreateTree({ onPick }) {
2987
+ const { shell, t, icons } = useShell();
2988
+ const [q, setQ] = useState("");
2989
+ const groups = useMemo(() => {
2990
+ const items = (shell.create?.items ?? []).filter((item) => matchScore(`${item.label} ${(item.keywords ?? []).join(" ")}`, q) > 0);
2991
+ const order = [shell.nav.activeArea, ...shell.nav.areas.map((area) => area.key).filter((key) => key !== shell.nav.activeArea)];
2992
+ const keys = Array.from(new Set(items.map((item) => item.area))).sort((a, b) => {
2993
+ const ia = order.indexOf(a);
2994
+ const ib = order.indexOf(b);
2995
+ return (ia < 0 ? order.length : ia) - (ib < 0 ? order.length : ib);
2996
+ });
2997
+ return keys.map((key) => ({ area: shell.nav.areas.find((area) => area.key === key), key, items: items.filter((item) => item.area === key) }));
2998
+ }, [shell, q]);
2999
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-create-tree", children: [
3000
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
3001
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
3002
+ /* @__PURE__ */ jsx("input", { type: "search", value: q, onChange: (event) => setQ(event.target.value), placeholder: t("What do you want to create?"), "aria-label": t("Search what to create"), autoComplete: "off" })
3003
+ ] }),
3004
+ groups.map((group) => {
3005
+ const Icon = resolveIcon(group.area?.icon, icons);
3006
+ return /* @__PURE__ */ jsxs("section", { "aria-label": group.area?.label ?? group.key, children: [
3007
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: group.area?.label ?? group.key }),
3008
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: group.items.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => onPick(item.key), children: [
3009
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile", style: { "--cbx-hue": String(hueFor(group.key)) }, "aria-hidden": "true", children: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) }),
3010
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.label }),
3011
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
3012
+ ] }, item.key)) })
3013
+ ] }, group.key);
3014
+ }),
3015
+ groups.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: q.trim() }) })
3016
+ ] });
3017
+ }
3018
+ function CreateField({ label, children, htmlFor }) {
3019
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-cfield", children: [
3020
+ htmlFor !== void 0 ? /* @__PURE__ */ jsx("label", { className: "cbx-cfield-label", htmlFor, children: label }) : /* @__PURE__ */ jsx("span", { className: "cbx-cfield-label", children: label }),
3021
+ children
3022
+ ] });
3023
+ }
3024
+ function CreateRefField({ label, value, placeholder, thing, onChoose, onCreate }) {
3025
+ const { t } = useShell();
3026
+ const id = useId();
3027
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-cfield", role: "group", "aria-labelledby": id, children: [
3028
+ /* @__PURE__ */ jsx("span", { id, className: "cbx-cfield-label", children: label }),
3029
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3030
+ /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow ${value ? "" : "is-empty"}`, onClick: onChoose, "aria-haspopup": onChoose !== void 0 ? "dialog" : void 0, children: [
3031
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: value || placeholder }),
3032
+ /* @__PURE__ */ jsx(ChevronDown, { className: "cbx-grow-trail", size: 14, strokeWidth: 2, "aria-hidden": true })
3033
+ ] }),
3034
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-accent", onClick: onCreate, children: [
3035
+ /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
3036
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("New {thing}", { thing: thing.toLowerCase() }) })
3037
+ ] })
3038
+ ] })
3039
+ ] });
3040
+ }
3041
+ function CreateSubmit({ form, busy = false, disabled = false }) {
3042
+ const { t } = useShell();
3043
+ 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 });
3044
+ }
3045
+ function CreateForm({ onSubmit, children }) {
3046
+ return /* @__PURE__ */ jsx("form", { className: "cbx-cform", onSubmit: (event) => {
3047
+ event.preventDefault();
3048
+ onSubmit(event);
3049
+ }, children });
3050
+ }
3051
+ var MAX_TABS = 4;
3052
+ function tabAreas(areas, tabs) {
3053
+ const chosen = tabs === void 0 ? areas.slice(0, MAX_TABS) : tabs.map((key) => areas.find((area) => area.key === key)).filter((area) => area !== void 0);
3054
+ return chosen.slice(0, MAX_TABS);
3055
+ }
3056
+ function pillLines(levels) {
3057
+ const main = levels[levels.length - 1];
3058
+ if (levels.length <= 1) return { top: main?.label ?? "", main };
3059
+ return { top: levels.slice(0, -1).map((level) => level.current.name).join(" \xB7 "), main };
3060
+ }
3061
+ function notLiveEnvironment(levels) {
3062
+ const environment = environmentLevel(levels)?.current;
3063
+ return environment !== void 0 && isLive(environment) === false ? environment : null;
3064
+ }
3065
+ function useUnread() {
3066
+ const { shell, help } = useShell();
3067
+ return useUnreadCount(help, shell.help.unread);
3068
+ }
3069
+ function MobileTopBar() {
3070
+ const { shell, t, openContext, toggleHelp, setOverlay, openCreate, canCreate } = useShell();
3071
+ const levels = shell.context.levels;
3072
+ const organization = levels[0];
3073
+ const { top, main } = pillLines(levels);
3074
+ const unread = useUnread();
3075
+ const topic = helpTopicName(shell);
3076
+ const trail = levels.map((level) => level.current.name).join(", ");
3077
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-m-bar", children: [
3078
+ organization !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-m-pill", onClick: () => openContext("root"), "aria-haspopup": "dialog", "aria-label": t("Where you work: {trail}", { trail }), children: [
3079
+ /* @__PURE__ */ jsx(Chip, { item: organization.current, tone: "solid" }),
3080
+ /* @__PURE__ */ jsxs("span", { className: "cbx-m-pill-text", children: [
3081
+ /* @__PURE__ */ jsx("span", { className: "cbx-m-pill-top", children: top }),
3082
+ /* @__PURE__ */ jsxs("span", { className: "cbx-m-pill-main", children: [
3083
+ main?.key === "environment" && /* @__PURE__ */ jsx(ToneSquare, { tone: main.current.tone }),
3084
+ /* @__PURE__ */ jsx("span", { className: "cbx-truncate", children: main?.current.name })
3085
+ ] })
3086
+ ] }),
3087
+ /* @__PURE__ */ jsx(ChevronDown, { className: "cbx-m-pill-chevron", size: 14, strokeWidth: 2, "aria-hidden": true })
3088
+ ] }),
3089
+ /* @__PURE__ */ jsx("span", { className: "cbx-m-spacer" }),
3090
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-m-icon", onClick: () => toggleHelp(true), "aria-controls": "cbx-help", "aria-label": unread > 0 ? t("Help with {page}, {count} unread", { page: topic, count: unread }) : t("Help with {page}", { page: topic }), children: [
3091
+ /* @__PURE__ */ jsx(CircleHelp, { size: 21, strokeWidth: 1.8, "aria-hidden": true }),
3092
+ unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-m-dot", "aria-hidden": "true" })
3093
+ ] }),
3094
+ /* @__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 }) }),
3095
+ 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 }) })
3096
+ ] });
3097
+ }
3098
+ function MobileAreaHead() {
3099
+ const { shell, t, Link } = useShell();
3100
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
3101
+ const pages = area?.pages ?? [];
3102
+ const environment = notLiveEnvironment(shell.context.levels);
3103
+ const strip = useRef(null);
3104
+ useEffect(() => {
3105
+ const list = strip.current;
3106
+ const current = list?.querySelector('[aria-current="page"]');
3107
+ if (list === null || list === void 0 || current === null || current === void 0) return;
3108
+ const overflow = current.offsetLeft + current.offsetWidth - list.clientWidth;
3109
+ if (overflow > 0) list.scrollLeft = overflow + 32;
3110
+ }, [shell.nav.activePage, shell.nav.activeArea]);
3111
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-m-head", children: [
3112
+ area !== void 0 && /* @__PURE__ */ jsx("p", { className: "cbx-m-title", children: area.label }),
3113
+ environment !== null && /* @__PURE__ */ jsxs("div", { className: `cbx-m-env cbx-env-${environment.tone ?? "neutral"}`, role: "status", children: [
3114
+ /* @__PURE__ */ jsx(ToneSquare, { tone: environment.tone }),
3115
+ /* @__PURE__ */ jsx("span", { children: t("{environment}. Not production, nothing here touches live customers.", { environment: environment.name }) })
3116
+ ] }),
3117
+ 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) => {
3118
+ const on = page.key === shell.nav.activePage;
3119
+ return /* @__PURE__ */ jsxs(Link, { href: navUrl(page), className: `cbx-m-chip ${on ? "is-on" : ""}`, "aria-current": on ? "page" : void 0, children: [
3120
+ page.label,
3121
+ page.locked === true && /* @__PURE__ */ jsx(NavPageMarks, { page })
3122
+ ] }, page.key);
3123
+ }) }) : /* @__PURE__ */ jsx("div", { className: "cbx-m-chips-gap" })
3124
+ ] });
3125
+ }
3126
+ function TabBar({ onMore }) {
3127
+ const { shell, t, Link, icons, overlay, setOverlay } = useShell();
3128
+ const tabs = tabAreas(shell.nav.areas, shell.nav.tabs);
3129
+ const moreOpen = overlay === "more";
3130
+ const inTabs = tabs.some((area) => area.key === shell.nav.activeArea);
3131
+ return /* @__PURE__ */ jsxs("nav", { className: "cbx-tabbar", "aria-label": t("Main"), children: [
3132
+ tabs.map((area) => {
3133
+ const Icon = resolveIcon(area.icon, icons);
3134
+ const on = !moreOpen && area.key === shell.nav.activeArea;
3135
+ return /* @__PURE__ */ jsxs(Link, { href: navUrl(area), className: `cbx-tab ${on ? "is-on" : ""}`, "aria-current": on ? "page" : void 0, onClick: () => {
3136
+ if (moreOpen) setOverlay(null);
3137
+ }, children: [
3138
+ /* @__PURE__ */ jsx(Icon, { size: 23, strokeWidth: 1.7, "aria-hidden": true }),
3139
+ /* @__PURE__ */ jsx("span", { children: area.label })
3140
+ ] }, area.key);
3141
+ }),
3142
+ /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-tab ${moreOpen || !inTabs ? "is-on" : ""}`, "aria-expanded": moreOpen, "aria-controls": "cbx-more", onClick: onMore, children: [
3143
+ /* @__PURE__ */ jsx(MoreHorizontal, { size: 23, strokeWidth: 1.7, "aria-hidden": true }),
3144
+ /* @__PURE__ */ jsx("span", { children: t("More") })
3145
+ ] })
3146
+ ] });
3147
+ }
3148
+ function BackBar({ label, onBack }) {
3149
+ return /* @__PURE__ */ jsx("div", { className: "cbx-m-bar", children: /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-m-back", onClick: onBack, children: [
3150
+ /* @__PURE__ */ jsx(ChevronLeft, { size: 22, strokeWidth: 2, "aria-hidden": true }),
3151
+ label
3152
+ ] }) });
3153
+ }
3154
+ function Row({ children, onClick, href, className, ...rest }) {
3155
+ const { Link } = useShell();
3156
+ if (href !== void 0) {
3157
+ if (rest.target !== void 0) return /* @__PURE__ */ jsx("a", { href, className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
3158
+ return /* @__PURE__ */ jsx(Link, { href, className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
3159
+ }
3160
+ return /* @__PURE__ */ jsx("button", { type: "button", className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
3161
+ }
3162
+ var Trail = () => /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true });
3163
+ function MoreScreen({ view, setView }) {
3164
+ const { t } = useShell();
3165
+ const top = useRef(null);
3166
+ useEffect(() => {
3167
+ if (typeof window !== "undefined" && typeof window.scrollTo === "function") {
3168
+ try {
3169
+ window.scrollTo(0, 0);
3170
+ } catch {
3171
+ }
3172
+ }
3173
+ top.current?.focus({ preventScroll: true });
3174
+ }, [view]);
3175
+ let body;
3176
+ if (view.kind === "area") body = /* @__PURE__ */ jsx(MoreArea, { areaKey: view.key, onBack: () => setView({ kind: "root" }) });
3177
+ else if (view.kind === "account") body = /* @__PURE__ */ jsx(MoreAccount, { onBack: () => setView({ kind: "root" }), onOption: (which) => setView({ kind: "option", which }) });
3178
+ else if (view.kind === "option") body = /* @__PURE__ */ jsx(MoreOption, { which: view.which, onBack: () => setView({ kind: "account" }) });
3179
+ else body = /* @__PURE__ */ jsx(MoreRoot, { onArea: (key) => setView({ kind: "area", key }), onAccount: () => setView({ kind: "account" }) });
3180
+ return /* @__PURE__ */ jsx("section", { id: "cbx-more", className: "cbx-more", "aria-label": t("More"), ref: top, tabIndex: -1, children: body });
3181
+ }
3182
+ function MoreRoot({ onArea, onAccount }) {
3183
+ const { shell, t, icons, Link, setOverlay, openContext, toggleHelp } = useShell();
3184
+ const [q, setQ] = useState("");
3185
+ const unread = useUnread();
3186
+ const topic = helpTopicName(shell);
3187
+ const hits = useMemo(() => {
3188
+ const query2 = q.trim();
3189
+ if (query2 === "") return [];
3190
+ const found = [];
3191
+ for (const area of shell.nav.areas) {
3192
+ const pages = area.pages ?? [];
3193
+ if (pages.length === 0) {
3194
+ const score = matchScore(area.label, query2);
3195
+ if (score > 0) found.push({ key: area.key, label: area.label, area: area.label, url: navUrl(area), score });
3196
+ }
3197
+ for (const page of pages) {
3198
+ const score = Math.max(matchScore(page.label, query2), matchScore(`${area.label} ${page.group ?? ""}`, query2) > 0 ? 1 : 0);
3199
+ if (score > 0) found.push({ key: `${area.key}:${page.key}`, label: page.label, area: area.label, url: navUrl(page), score });
3200
+ }
3201
+ }
3202
+ return found.sort((a, b) => b.score - a.score);
3203
+ }, [q, shell]);
3204
+ const appName = shell.app.name.replace(/^Cbox\s*·?\s*/i, "");
3205
+ const account = shell.account ?? {};
3206
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3207
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-bar" }),
3208
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: t("More") }),
3209
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
3210
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
3211
+ /* @__PURE__ */ jsx("input", { type: "search", value: q, onChange: (event) => setQ(event.target.value), placeholder: t("Search all pages"), "aria-label": t("Search all pages"), autoComplete: "off" })
3212
+ ] }),
3213
+ q.trim() !== "" ? /* @__PURE__ */ jsxs("div", { className: "cbx-group", role: "group", "aria-label": t("Pages"), children: [
3214
+ hits.map((hit) => /* @__PURE__ */ jsxs(Link, { href: hit.url, className: "cbx-grow", onClick: () => setOverlay(null), children: [
3215
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: hit.label }),
3216
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: hit.area })
3217
+ ] }, hit.key)),
3218
+ hits.length === 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-muted", onClick: () => setOverlay("palette"), children: [
3219
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("No page matches. Search finds records too.") }),
3220
+ /* @__PURE__ */ jsx(Trail, {})
3221
+ ] })
3222
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3223
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: appName }),
3224
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: shell.nav.areas.map((area) => {
3225
+ const Icon = resolveIcon(area.icon, icons);
3226
+ const pages = area.pages ?? [];
3227
+ const tile = /* @__PURE__ */ jsx("span", { className: "cbx-tile", style: { "--cbx-hue": String(hueFor(area.key)) }, "aria-hidden": "true", children: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) });
3228
+ const lock = areaLocked(area) ? /* @__PURE__ */ jsxs("span", { className: "cbx-nav-lock", title: t("Not in your plan"), children: [
3229
+ /* @__PURE__ */ jsx(Lock, { size: 13, strokeWidth: 1.9, "aria-hidden": true }),
3230
+ /* @__PURE__ */ jsx("span", { className: "cbx-sr-only", children: t("(locked)") })
3231
+ ] }) : null;
3232
+ if (pages.length <= 1) {
3233
+ return /* @__PURE__ */ jsxs(Row, { href: navUrl(area), onClick: () => setOverlay(null), "aria-current": area.key === shell.nav.activeArea ? "page" : void 0, children: [
3234
+ tile,
3235
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: area.label }),
3236
+ lock,
3237
+ /* @__PURE__ */ jsx(Trail, {})
3238
+ ] }, area.key);
3239
+ }
3240
+ return /* @__PURE__ */ jsxs(Row, { onClick: () => onArea(area.key), children: [
3241
+ tile,
3242
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: area.label }),
3243
+ lock,
3244
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: pages.length }),
3245
+ /* @__PURE__ */ jsx(Trail, {})
3246
+ ] }, area.key);
3247
+ }) }),
3248
+ /* @__PURE__ */ jsx(WhereYouWork, { onStep: (step) => openContext(step, true) }),
3249
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: t("Help") }),
3250
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: /* @__PURE__ */ jsxs(Row, { className: "is-tall", onClick: () => toggleHelp(true), "aria-haspopup": "dialog", children: [
3251
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-accent", "aria-hidden": "true", children: /* @__PURE__ */ jsx(CircleHelp, { size: 17, strokeWidth: 1.8 }) }),
3252
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3253
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: t("Help with {page}", { page: topic }) }),
3254
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: t("Articles, Ask Cbox, chat with support") })
3255
+ ] }),
3256
+ unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: unread }) }),
3257
+ /* @__PURE__ */ jsx(Trail, {})
3258
+ ] }) }),
3259
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3260
+ shell.notifications.enabled && /* @__PURE__ */ jsxs(Row, { href: shell.notifications.url, onClick: () => setOverlay(null), children: [
3261
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Bell, { size: 16, strokeWidth: 1.8 }) }),
3262
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Notifications") }),
3263
+ shell.notifications.unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: shell.notifications.unread }),
3264
+ /* @__PURE__ */ jsx(Trail, {})
3265
+ ] }),
3266
+ /* @__PURE__ */ jsxs(Row, { onClick: () => setOverlay("apps-sheet"), "aria-haspopup": "dialog", children: [
3267
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-primary", "aria-hidden": "true", children: /* @__PURE__ */ jsx(LayoutGrid, { size: 16, strokeWidth: 2 }) }),
3268
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Switch app") }),
3269
+ /* @__PURE__ */ jsx(Trail, {})
3270
+ ] })
3271
+ ] }),
3272
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: /* @__PURE__ */ jsxs(Row, { className: "is-tall", onClick: onAccount, children: [
3273
+ /* @__PURE__ */ jsx(Avatar, { size: 40 }),
3274
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3275
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: shell.person.name }),
3276
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: account.signedInWith !== void 0 ? account.signedInWith : t("Profile, language, theme") })
3277
+ ] }),
3278
+ /* @__PURE__ */ jsx(Trail, {})
3279
+ ] }) })
3280
+ ] })
3281
+ ] });
3282
+ }
3283
+ function WhereYouWork({ onStep }) {
3284
+ const { shell, t } = useShell();
3285
+ const levels = shell.context.levels;
3286
+ const environment = environmentLevel(levels);
3287
+ const parentOfEnvironment = environment !== void 0 ? levels[levels.indexOf(environment) - 1]?.current.id : void 0;
3288
+ const list = useContextList(environment?.listUrl, { parent: parentOfEnvironment, enabled: environment !== void 0 });
3289
+ if (levels.length === 0) return null;
3290
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3291
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: t("Where you work") }),
3292
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: levels.map((level, index) => {
3293
+ const env = level.key === "environment";
3294
+ return /* @__PURE__ */ jsxs(Row, { onClick: () => onStep(env ? "environments" : level.key), "aria-haspopup": "dialog", children: [
3295
+ index === 0 ? /* @__PURE__ */ jsx(Chip, { item: level.current, tone: "soft" }) : env ? /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: /* @__PURE__ */ jsx(ToneSquare, { tone: level.current.tone }) }) : /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: level.current.initials ?? level.current.name.slice(0, 2) }),
3296
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3297
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: level.label }),
3298
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: level.current.name })
3299
+ ] }),
3300
+ env && list.status === "ready" && !list.hasMore && /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: list.items.length }),
3301
+ /* @__PURE__ */ jsx(Trail, {})
3302
+ ] }, level.key);
3303
+ }) })
3304
+ ] });
3305
+ }
3306
+ function MoreArea({ areaKey, onBack }) {
3307
+ const { shell, t, setOverlay } = useShell();
3308
+ const area = shell.nav.areas.find((item) => item.key === areaKey);
3309
+ if (area === void 0) return null;
3310
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3311
+ /* @__PURE__ */ jsx(BackBar, { label: t("More"), onBack }),
3312
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: area.label }),
3313
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
3314
+ groupPages(area.pages ?? []).map((run, index) => /* @__PURE__ */ jsxs("section", { role: "group", "aria-label": run.group ?? area.label, children: [
3315
+ run.group !== void 0 && /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", "aria-hidden": "true", children: run.group }),
3316
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: run.pages.map((page) => {
3317
+ const on = area.key === shell.nav.activeArea && page.key === shell.nav.activePage;
3318
+ return /* @__PURE__ */ jsxs(Row, { href: navUrl(page), onClick: () => setOverlay(null), "aria-current": on ? "page" : void 0, className: page.locked === true ? "is-locked" : "", children: [
3319
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: page.label }),
3320
+ /* @__PURE__ */ jsx(NavPageMarks, { page }),
3321
+ /* @__PURE__ */ jsx(Trail, {})
3322
+ ] }, page.key);
3323
+ }) })
3324
+ ] }, index))
3325
+ ] });
3326
+ }
3327
+ var DEFAULT_LANGUAGES2 = [
3328
+ { code: "en", label: "English" },
3329
+ { code: "da", label: "Dansk" }
3330
+ ];
3331
+ var DEFAULT_FORMATS2 = [
3332
+ { code: "en-GB", label: "English (United Kingdom)" },
3333
+ { code: "en-US", label: "English (United States)" },
3334
+ { code: "da-DK", label: "Dansk (Danmark)" },
3335
+ { code: "de-DE", label: "Deutsch (Deutschland)" },
3336
+ { code: "sv-SE", label: "Svenska (Sverige)" },
3337
+ { code: "nb-NO", label: "Norsk bokm\xE5l (Norge)" }
3338
+ ];
3339
+ function zones() {
3340
+ const supported = Intl.supportedValuesOf;
3341
+ const list = typeof supported === "function" ? supported("timeZone") : ["UTC", "Europe/Copenhagen", "Europe/London", "Europe/Berlin", "America/New_York"];
3342
+ return list.map((zone) => ({ code: zone, label: zone.replace(/_/g, " ") }));
3343
+ }
3344
+ function MoreAccount({ onBack, onOption }) {
3345
+ const { shell, t, preferences, setPreference, navigate } = useShell();
3346
+ const account = shell.account ?? {};
3347
+ const languages = account.languages ?? DEFAULT_LANGUAGES2;
3348
+ const formats = account.formats ?? DEFAULT_FORMATS2;
3349
+ const label = (options, code, fallback) => options.find((option) => option.code === code)?.label ?? code ?? fallback;
3350
+ const themes = [
3351
+ { value: "system", label: t("System") },
3352
+ { value: "light", label: t("Light") },
3353
+ { value: "dark", label: t("Dark") }
3354
+ ];
3355
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3356
+ /* @__PURE__ */ jsx(BackBar, { label: t("More"), onBack }),
3357
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: t("Account") }),
3358
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
3359
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3360
+ /* @__PURE__ */ jsxs("div", { className: "cbx-grow is-tall is-static", children: [
3361
+ /* @__PURE__ */ jsx(Avatar, { size: 40 }),
3362
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3363
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: shell.person.name }),
3364
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: account.signedInWith ?? t("Signed in with Cbox ID") })
3365
+ ] })
3366
+ ] }),
3367
+ account.profileUrl !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-grow", href: account.profileUrl, children: [
3368
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Profile and security") }),
3369
+ /* @__PURE__ */ jsx(ArrowUpRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
3370
+ ] })
3371
+ ] }),
3372
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3373
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("locale"), children: [
3374
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Language") }),
3375
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: label(languages, preferences.locale, "English") })
3376
+ ] }),
3377
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("regionalFormat"), children: [
3378
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Regional format") }),
3379
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: label(formats, preferences.regionalFormat, t("Automatic")) })
3380
+ ] }),
3381
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("timeZone"), children: [
3382
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Time zone") }),
3383
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: (preferences.timeZone ?? t("Automatic")).replace(/_/g, " ") })
3384
+ ] })
3385
+ ] }),
3386
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", id: "cbx-theme-label", children: t("Theme") }),
3387
+ /* @__PURE__ */ jsx("div", { className: "cbx-seg", role: "radiogroup", "aria-labelledby": "cbx-theme-label", children: themes.map((theme) => /* @__PURE__ */ jsx("button", { type: "button", role: "radio", "aria-checked": preferences.theme === theme.value, className: preferences.theme === theme.value ? "is-on" : "", onClick: () => setPreference("theme", theme.value), children: theme.label }, theme.value)) }),
3388
+ (account.switchAccountUrl !== void 0 || account.signOutUrl !== void 0) && /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3389
+ account.switchAccountUrl !== void 0 && /* @__PURE__ */ jsx("a", { className: "cbx-grow", href: account.switchAccountUrl, children: /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Switch account") }) }),
3390
+ account.signOutUrl !== void 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-grow is-danger", onClick: () => navigate(account.signOutUrl, { method: account.signOutMethod ?? "post" }), children: /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Sign out") }) })
3391
+ ] })
3392
+ ] });
3393
+ }
3394
+ function MoreOption({ which, onBack }) {
3395
+ const { shell, t, preferences, setPreference } = useShell();
3396
+ const account = shell.account ?? {};
3397
+ const options = which === "locale" ? account.languages ?? DEFAULT_LANGUAGES2 : which === "regionalFormat" ? account.formats ?? DEFAULT_FORMATS2 : zones();
3398
+ const title = which === "locale" ? t("Language") : which === "regionalFormat" ? t("Regional format") : t("Time zone");
3399
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3400
+ /* @__PURE__ */ jsx(BackBar, { label: t("Account"), onBack }),
3401
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: title }),
3402
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
3403
+ /* @__PURE__ */ jsx(
3404
+ OptionList,
3405
+ {
3406
+ label: title,
3407
+ options,
3408
+ current: preferences[which],
3409
+ autoFocus: false,
3410
+ onPick: (code) => {
3411
+ setPreference(which, code);
3412
+ onBack();
3413
+ }
3414
+ }
3415
+ )
3416
+ ] });
3417
+ }
3418
+ function useMoreView() {
3419
+ const [view, setView] = useState({ kind: "root" });
3420
+ return [view, setView];
3421
+ }
3422
+ function ContextSheet({ onClose }) {
3423
+ const { shell, t, switchTo, contextStep } = useShell();
3424
+ const [step, setStep] = useState(contextStep.step);
3425
+ const direct = contextStep.direct;
3426
+ const levels = shell.context.levels;
3427
+ const back = () => direct ? onClose() : setStep("root");
3428
+ if (step === "environments") {
3429
+ const environment = environmentLevel(levels);
3430
+ if (environment !== void 0) {
3431
+ const index = levels.indexOf(environment);
3432
+ const parent = levels[index - 1];
3433
+ return /* @__PURE__ */ jsx(Sheet, { label: parent !== void 0 && index > 0 ? t("{things} in {name}", { things: pluralOf(environment), name: parent.current.name }) : pluralOf(environment), size: "tall", onClose, back: { label: t("Back"), onBack: back }, children: /* @__PURE__ */ jsx(EnvironmentList, { level: environment, parent: index > 0 ? parent?.current.id : void 0, parentName: index > 0 ? parent?.current.name : void 0, onPick: (item) => switchTo(parent !== void 0 && index > 0 ? { [parent.key]: parent.current.id, [environment.key]: item.id } : { [environment.key]: item.id }) }) });
3434
+ }
3435
+ }
3436
+ const level = levels.find((item) => item.key === step);
3437
+ if (step !== "root" && level !== void 0) {
3438
+ const index = levels.indexOf(level);
3439
+ const parent = index > 0 ? levels[index - 1] : void 0;
3440
+ const inner = levels[index + 1];
3441
+ return /* @__PURE__ */ jsx(Sheet, { label: level.label, size: "tall", onClose, back: { label: t("Back"), onBack: back }, children: /* @__PURE__ */ jsx("div", { className: "cbx-sheet-level", children: /* @__PURE__ */ jsx(
3442
+ LevelPane,
3443
+ {
3444
+ level,
3445
+ parent: parent?.current.id,
3446
+ currentId: level.current.id,
3447
+ heading: pluralOf(level),
3448
+ createLabel: t("New {thing}", { thing: level.label.toLowerCase() }),
3449
+ onPick: (item) => index === 0 ? switchTo({ [level.key]: item.id }) : void pickKeepingEnvironment(level, inner, item, switchTo)
3450
+ }
3451
+ ) }) });
3452
+ }
3453
+ return /* @__PURE__ */ jsx(Sheet, { label: t("Where you work"), onClose, children: /* @__PURE__ */ jsx(ContextRoot, { onStep: setStep }) });
3454
+ }
3455
+ function ContextRoot({ onStep }) {
3456
+ const { shell, t, switchTo } = useShell();
3457
+ const levels = shell.context.levels;
3458
+ const environment = environmentLevel(levels);
3459
+ const above = levels.filter((level) => level !== environment);
3460
+ const envIndex = environment !== void 0 ? levels.indexOf(environment) : -1;
3461
+ const parent = envIndex > 0 ? levels[envIndex - 1] : void 0;
3462
+ const list = useContextList(environment?.listUrl, { parent: parent?.current.id, enabled: environment !== void 0 });
3463
+ const picks = environment !== void 0 ? quickEnvironments(list.items, environment.current) : [];
3464
+ const pick = (item) => {
3465
+ if (environment === void 0) return;
3466
+ switchTo(parent !== void 0 ? { [parent.key]: parent.current.id, [environment.key]: item.id } : { [environment.key]: item.id });
3467
+ };
3468
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3469
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: above.map((level, index) => /* @__PURE__ */ jsxs(Row, { onClick: () => onStep(level.key), children: [
3470
+ index === 0 && /* @__PURE__ */ jsx(Chip, { item: level.current, tone: "soft" }),
3471
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3472
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: level.label }),
3473
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: level.current.name })
3474
+ ] }),
3475
+ /* @__PURE__ */ jsx(Trail, {})
3476
+ ] }, level.key)) }),
3477
+ environment !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
3478
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: environment.label }),
3479
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", role: "group", "aria-label": environment.label, children: [
3480
+ picks.map((item) => {
3481
+ const current = item.id === environment.current.id;
3482
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", "aria-current": current ? "true" : void 0, onClick: () => current ? void 0 : pick(item), children: [
3483
+ /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
3484
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label cbx-grow-strong", children: item.name }),
3485
+ current && /* @__PURE__ */ jsx(Check, { className: "cbx-grow-check", size: 18, strokeWidth: 2, "aria-label": t("Current") })
3486
+ ] }, item.id);
3487
+ }),
3488
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-accent", onClick: () => onStep("environments"), children: [
3489
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: list.status === "ready" && !list.hasMore ? t("All {count} {things}", { count: list.items.length, things: pluralOf(environment).toLowerCase() }) : t("All {things}", { things: pluralOf(environment).toLowerCase() }) }),
3490
+ /* @__PURE__ */ jsx(Trail, {})
3491
+ ] })
3492
+ ] })
3493
+ ] })
3494
+ ] });
3495
+ }
3496
+ function EnvironmentList({ level, parent, parentName, onPick }) {
3497
+ const { t } = useShell();
3498
+ const [q, setQ] = useState("");
3499
+ const [creating, setCreating] = useState(false);
3500
+ const list = useContextList(level.listUrl, { q, parent });
3501
+ const plural = pluralOf(level);
3502
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-env-list", children: [
3503
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
3504
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
3505
+ /* @__PURE__ */ jsx("input", { type: "search", value: q, onChange: (event) => setQ(event.target.value), placeholder: t("Search {things}", { things: plural.toLowerCase() }), "aria-label": t("Search {things}", { things: plural.toLowerCase() }), autoComplete: "off" })
3506
+ ] }),
3507
+ groupItems(list.items).map((run, index) => /* @__PURE__ */ jsxs("section", { "aria-label": run.group ?? plural, children: [
3508
+ run.group !== void 0 && /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: run.group }),
3509
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: run.items.map((item) => {
3510
+ const current = item.id === level.current.id;
3511
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", "aria-current": current ? "true" : void 0, onClick: () => current ? void 0 : onPick(item), children: [
3512
+ /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
3513
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3514
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: item.name }),
3515
+ (item.description ?? item.label) !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: item.description ?? item.label })
3516
+ ] }),
3517
+ current && /* @__PURE__ */ jsx(Check, { className: "cbx-grow-check", size: 18, strokeWidth: 2, "aria-label": t("Current") })
3518
+ ] }, item.id);
3519
+ }) })
3520
+ ] }, run.group ?? `run-${index}`)),
3521
+ list.hasMore && /* @__PURE__ */ jsx("div", { className: "cbx-group", children: /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-grow is-accent", onClick: list.loadMore, children: /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: list.loadingMore ? t("Loading\u2026") : t("Show more") }) }) }),
3522
+ list.status === "loading" && list.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", "aria-live": "polite", children: t("Loading\u2026") }),
3523
+ list.status === "error" && /* @__PURE__ */ jsxs("p", { className: "cbx-list-note", role: "alert", children: [
3524
+ t("{things} could not be loaded.", { things: plural }),
3525
+ " ",
3526
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: list.retry, children: t("Try again") })
3527
+ ] }),
3528
+ list.status === "ready" && list.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", "aria-live": "polite", children: q.trim() === "" ? t("No {things} yet.", { things: plural.toLowerCase() }) : t("Nothing matches \u201C{query}\u201D.", { query: q.trim() }) }),
3529
+ level.createUrl !== void 0 && /* @__PURE__ */ jsx("div", { className: "cbx-group", children: creating ? /* @__PURE__ */ jsx("div", { className: "cbx-grow is-static", children: /* @__PURE__ */ jsx(InlineCreate, { level, parent, label: parentName !== void 0 ? t("New {thing} in {name}", { thing: level.label.toLowerCase(), name: parentName }) : t("New {thing}", { thing: level.label.toLowerCase() }), onCancel: () => setCreating(false) }) }) : /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-accent", onClick: () => setCreating(true), children: [
3530
+ /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
3531
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("New {thing}", { thing: level.label.toLowerCase() }) })
3532
+ ] }) })
3533
+ ] });
3534
+ }
3535
+ function AppsSheet({ onClose }) {
3536
+ const { t } = useShell();
3537
+ return /* @__PURE__ */ jsx(Sheet, { label: t("Switch app"), onClose, children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false }) });
3538
+ }
3539
+ function MobilePage({ hidden, children }) {
3540
+ const box = useRef(null);
3541
+ const title = useShellPageTitle();
3542
+ useEffect(() => {
3543
+ const page = box.current;
3544
+ if (page === null) return;
3545
+ const mark = () => {
3546
+ for (const heading of page.querySelectorAll("[data-cbx-page-title]")) {
3547
+ const same = title !== null && sameTitle(heading.textContent ?? "", title);
3548
+ if (same !== heading.hasAttribute("data-cbx-same-title")) heading.toggleAttribute("data-cbx-same-title", same);
3549
+ }
3550
+ };
3551
+ mark();
3552
+ if (typeof MutationObserver === "undefined") return;
3553
+ const observer = new MutationObserver(mark);
3554
+ observer.observe(page, { childList: true, subtree: true, characterData: true });
3555
+ return () => observer.disconnect();
3556
+ }, [title]);
3557
+ return /* @__PURE__ */ jsx("div", { ref: box, className: "cbx-m-page", hidden, children });
3558
+ }
3559
+ function keyboardInset({ innerHeight, viewportHeight, offsetTop }) {
3560
+ return Math.max(0, Math.round(innerHeight - viewportHeight - offsetTop));
3561
+ }
3562
+ var EDITABLE = 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="range"]), textarea, select, [contenteditable]';
3563
+ function useViewportInsets(enabled) {
3564
+ useEffect(() => {
3565
+ if (!enabled || typeof window === "undefined") return;
3566
+ const html = document.documentElement;
3567
+ const viewport = window.visualViewport;
3568
+ let tallest = window.innerHeight;
3569
+ let width = window.innerWidth;
3570
+ let frame = 0;
3571
+ const update = () => {
3572
+ frame = 0;
3573
+ if (window.innerWidth !== width) {
3574
+ width = window.innerWidth;
3575
+ tallest = window.innerHeight;
3576
+ }
3577
+ tallest = Math.max(tallest, window.innerHeight);
3578
+ const visible = viewport?.height ?? window.innerHeight;
3579
+ const inset = keyboardInset({ innerHeight: window.innerHeight, viewportHeight: visible, offsetTop: viewport?.offsetTop ?? 0 });
3580
+ html.style.setProperty("--cbx-keyboard", `${inset}px`);
3581
+ html.style.setProperty("--cbx-vvh", `${Math.round(visible)}px`);
3582
+ const typing = document.activeElement instanceof Element && document.activeElement.matches(EDITABLE);
3583
+ const shrunk = tallest - visible > 120;
3584
+ if (typing && (inset > 120 || shrunk)) html.setAttribute("data-cbx-keyboard", "");
3585
+ else html.removeAttribute("data-cbx-keyboard");
3586
+ };
3587
+ const schedule = () => {
3588
+ if (frame === 0) frame = requestAnimationFrame(update);
3589
+ };
3590
+ update();
3591
+ viewport?.addEventListener("resize", schedule);
3592
+ viewport?.addEventListener("scroll", schedule);
3593
+ window.addEventListener("resize", schedule);
3594
+ document.addEventListener("focusin", schedule);
3595
+ document.addEventListener("focusout", schedule);
3596
+ return () => {
3597
+ cancelAnimationFrame(frame);
3598
+ viewport?.removeEventListener("resize", schedule);
3599
+ viewport?.removeEventListener("scroll", schedule);
3600
+ window.removeEventListener("resize", schedule);
3601
+ document.removeEventListener("focusin", schedule);
3602
+ document.removeEventListener("focusout", schedule);
3603
+ html.style.removeProperty("--cbx-keyboard");
3604
+ html.style.removeProperty("--cbx-vvh");
3605
+ html.removeAttribute("data-cbx-keyboard");
3606
+ };
3607
+ }, [enabled]);
3608
+ }
2353
3609
  var PlainLink = ({ href, children, ...props }) => /* @__PURE__ */ jsx("a", { href, ...props, children });
2354
3610
  function writeCookie(key, value) {
2355
3611
  if (typeof document === "undefined") return;
@@ -2376,11 +3632,16 @@ function useIsMac() {
2376
3632
  }, []);
2377
3633
  return mac;
2378
3634
  }
2379
- function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent = PlainLink, icons = {}, onPreferenceChange, helpStore, brandAssetBase = "/brand", mainId = "main-content" }) {
3635
+ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent = PlainLink, icons = {}, onPreferenceChange, helpStore, brandAssetBase = "/brand", mainId = "main-content", renderCreate, searchRecords }) {
2380
3636
  const { t } = useCboxLocalization();
2381
3637
  const [store] = useState(() => helpStore ?? sharedHelpStore());
2382
3638
  const [preferences, setPreferences] = useState(shell.preferences);
2383
3639
  const [overlay, setOverlay] = useState(null);
3640
+ const [contextStep, setContextStep] = useState({ step: "root", direct: false });
3641
+ const [createKey, setCreateKey] = useState(null);
3642
+ const mobile = useMedia(MOBILE, false);
3643
+ useViewportInsets(mobile);
3644
+ const [moreView, setMoreView] = useMoreView();
2384
3645
  if (!store.get().seeded) store.set({ open: shell.preferences.helpOpen, restored: shell.preferences.helpOpen, seeded: true });
2385
3646
  const serverPreferences = JSON.stringify(shell.preferences);
2386
3647
  useEffect(() => {
@@ -2407,6 +3668,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2407
3668
  const switchUrl = shell.context.switchUrl;
2408
3669
  const scope = levels.map((level) => `${level.key}:${level.current.id}`).join("|");
2409
3670
  if (scopeLists(scope)) forgetShellCatalog();
3671
+ const canCreate = renderCreate !== void 0 && (shell.create?.items.length ?? 0) > 0;
2410
3672
  const api = useMemo(
2411
3673
  () => ({
2412
3674
  shell,
@@ -2431,9 +3693,28 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2431
3693
  switchTo: (chosen) => {
2432
3694
  setOverlay(null);
2433
3695
  navigate(switchUrl, { method: "post", data: switchBody(levels, chosen, currentLocation()) });
2434
- }
3696
+ },
3697
+ mobile,
3698
+ contextStep,
3699
+ openContext: (step = "root", direct = false) => {
3700
+ if (mobile) {
3701
+ setContextStep({ step, direct, underMore: overlay === "more" });
3702
+ setOverlay("context-sheet");
3703
+ return;
3704
+ }
3705
+ setOverlay(step === "root" || step === levels[0]?.key || levels.length < 2 ? "org" : "context");
3706
+ },
3707
+ createKey,
3708
+ canCreate,
3709
+ openCreate: (key) => {
3710
+ if (!canCreate) return;
3711
+ setCreateKey(key ?? pageCreateKey(shell));
3712
+ setOverlay("create");
3713
+ },
3714
+ renderCreate,
3715
+ searchRecords
2435
3716
  }),
2436
- [shell, t, navigate, LinkComponent, icons, preferences, setPreference, overlay, store, toggleHelp, levels, switchUrl]
3717
+ [shell, t, navigate, LinkComponent, icons, preferences, setPreference, overlay, store, toggleHelp, levels, switchUrl, mobile, contextStep, createKey, canCreate, renderCreate, searchRecords]
2437
3718
  );
2438
3719
  const preferencesRef = useRef(preferences);
2439
3720
  preferencesRef.current = preferences;
@@ -2454,44 +3735,88 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2454
3735
  const page = `${shell.nav.activeArea}|${shell.nav.activePage ?? ""}|${shell.page?.title ?? ""}`;
2455
3736
  useEffect(() => {
2456
3737
  setOverlay((current) => current === "palette" ? current : null);
3738
+ setMoreView({ kind: "root" });
3739
+ if (shell.page?.title !== void 0) {
3740
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
3741
+ rememberPage(shell.app.key, { title: shell.page.title, area: area?.label, url: currentLocation() });
3742
+ }
2457
3743
  }, [page]);
2458
3744
  const docked = useMedia(HELP_DOCKED, true);
2459
- const mobile = useMedia(MOBILE, false);
2460
3745
  const testData = levels.some((level) => level.current.testData === true);
2461
3746
  const helpOpen = useHelpState(store, (state) => helpVisible(state, docked));
2462
- const banners = shellBanners(shell, testData);
3747
+ const notLive = notLiveEnvironment(levels);
3748
+ const banners = shellBanners(shell, testData).filter((banner) => !(mobile && notLive !== null && banner.kind === "sandbox"));
3749
+ const envBanner = !mobile && notLive !== null && !banners.some((banner) => banner.kind === "sandbox") ? notLive : null;
3750
+ const strips = banners.map((banner, index) => /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-${banner.kind}`, role: "status", children: [
3751
+ /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: banner.text }),
3752
+ banner.action !== void 0 && /* @__PURE__ */ jsx(LinkComponent, { href: navUrl(banner.action), className: "cbx-banner-action", children: banner.action.label })
3753
+ ] }, `${banner.kind}-${index}`));
3754
+ const skip = /* @__PURE__ */ jsx(
3755
+ "a",
3756
+ {
3757
+ className: "cbx-skip-link",
3758
+ href: `#${mainId}`,
3759
+ onClick: (event) => {
3760
+ const main = document.getElementById(mainId);
3761
+ if (main === null) return;
3762
+ event.preventDefault();
3763
+ main.focus();
3764
+ main.scrollIntoView?.({ block: "start" });
3765
+ },
3766
+ children: t("Skip to content")
3767
+ }
3768
+ );
3769
+ const overlays = /* @__PURE__ */ jsxs(Fragment, { children: [
3770
+ overlay === "palette" && /* @__PURE__ */ jsx(CommandPalette, { onClose: () => setOverlay(null) }),
3771
+ overlay === "context-sheet" && /* @__PURE__ */ jsx(ContextSheet, { onClose: () => setOverlay(contextStep.underMore === true ? "more" : null) }, `${contextStep.step}:${String(contextStep.direct)}`),
3772
+ overlay === "apps-sheet" && /* @__PURE__ */ jsx(AppsSheet, { onClose: () => setOverlay("more") }),
3773
+ overlay === "create" && /* @__PURE__ */ jsx(CreateSheet, { onClose: () => setOverlay(null) }, createKey ?? "tree")
3774
+ ] });
3775
+ if (mobile) {
3776
+ const moreOpen = overlay === "more" || overlay === "apps-sheet" || overlay === "context-sheet" && contextStep.underMore === true;
3777
+ return /* @__PURE__ */ jsx(ShellContext.Provider, { value: api, children: /* @__PURE__ */ jsxs("div", { className: "cbx-shell is-mobile", "data-help-open": helpOpen, children: [
3778
+ skip,
3779
+ /* @__PURE__ */ jsxs("div", { className: "cbx-shell-column", children: [
3780
+ /* @__PURE__ */ jsxs("header", { className: "cbx-m-chrome", hidden: moreOpen, children: [
3781
+ /* @__PURE__ */ jsx(MobileTopBar, {}),
3782
+ /* @__PURE__ */ jsx(MobileAreaHead, {}),
3783
+ strips
3784
+ ] }),
3785
+ /* @__PURE__ */ jsxs("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children: [
3786
+ moreOpen && /* @__PURE__ */ jsx(MoreScreen, { view: moreView, setView: setMoreView }),
3787
+ /* @__PURE__ */ jsx(MobilePage, { hidden: moreOpen, children })
3788
+ ] })
3789
+ ] }),
3790
+ /* @__PURE__ */ jsx(
3791
+ TabBar,
3792
+ {
3793
+ onMore: () => {
3794
+ setMoreView({ kind: "root" });
3795
+ setOverlay("more");
3796
+ }
3797
+ }
3798
+ ),
3799
+ /* @__PURE__ */ jsx(HelpColumn, { docked: false, mobile: true }),
3800
+ overlays
3801
+ ] }) });
3802
+ }
2463
3803
  return /* @__PURE__ */ jsx(ShellContext.Provider, { value: api, children: /* @__PURE__ */ jsxs("div", { className: "cbx-shell", "data-help-open": helpOpen, children: [
2464
- /* @__PURE__ */ jsx(
2465
- "a",
2466
- {
2467
- className: "cbx-skip-link",
2468
- href: `#${mainId}`,
2469
- onClick: (event) => {
2470
- const main = document.getElementById(mainId);
2471
- if (main === null) return;
2472
- event.preventDefault();
2473
- main.focus();
2474
- main.scrollIntoView?.({ block: "start" });
2475
- },
2476
- children: t("Skip to content")
2477
- }
2478
- ),
3804
+ skip,
2479
3805
  /* @__PURE__ */ jsx(Rail, { brandAssetBase }),
2480
3806
  /* @__PURE__ */ jsxs("div", { className: "cbx-shell-column", children: [
2481
- /* @__PURE__ */ jsx(Header, { mobile }),
2482
- banners.map((banner, index) => /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-${banner.kind}`, role: "status", children: [
2483
- /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: banner.text }),
2484
- banner.action !== void 0 && /* @__PURE__ */ jsx(LinkComponent, { href: navUrl(banner.action), className: "cbx-banner-action", children: banner.action.label })
2485
- ] }, `${banner.kind}-${index}`)),
3807
+ /* @__PURE__ */ jsx(Header, {}),
3808
+ envBanner !== null && /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-env cbx-env-${envBanner.tone ?? "neutral"}`, role: "status", children: [
3809
+ /* @__PURE__ */ jsx(ToneSquare, { tone: envBanner.tone }),
3810
+ /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: t("{environment}. Not production, nothing here touches live customers.", { environment: envBanner.name }) })
3811
+ ] }),
3812
+ strips,
2486
3813
  /* @__PURE__ */ jsxs("div", { className: "cbx-shell-body", children: [
2487
3814
  /* @__PURE__ */ jsx(Subnav, {}),
2488
3815
  /* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children })
2489
3816
  ] })
2490
3817
  ] }),
2491
3818
  /* @__PURE__ */ jsx(HelpColumn, { docked }),
2492
- overlay === "palette" && /* @__PURE__ */ jsx(CommandPalette, { onClose: () => setOverlay(null) }),
2493
- overlay === "nav-sheet" && /* @__PURE__ */ jsx(NavSheet, { onClose: () => setOverlay(null) }),
2494
- overlay === "context-sheet" && /* @__PURE__ */ jsx(ContextSheet, { onClose: () => setOverlay(null) })
3819
+ overlays
2495
3820
  ] }) });
2496
3821
  }
2497
3822
  function AppMark() {
@@ -2610,7 +3935,7 @@ function Subnav() {
2610
3935
  ) })
2611
3936
  ] });
2612
3937
  }
2613
- function Header({ mobile }) {
3938
+ function Header() {
2614
3939
  const { shell, t, overlay, setOverlay, help, toggleHelp, Link } = useShell();
2615
3940
  const mac = useIsMac();
2616
3941
  const org = useRef(null);
@@ -2618,9 +3943,8 @@ function Header({ mobile }) {
2618
3943
  const apps = useRef(null);
2619
3944
  const docked = useMedia(HELP_DOCKED, true);
2620
3945
  const helpOpen = useHelpState(help, (state) => helpVisible(state, docked));
2621
- const unread = useHelpState(help, (state) => state.updates.filter((update) => update.unread).length);
3946
+ const unread = useUnreadCount(help, shell.help.unread);
2622
3947
  const [organization, ...rest] = shell.context.levels;
2623
- const trail = shell.context.levels.map((level) => level.current.name).join(" / ");
2624
3948
  const close = useCallback(() => setOverlay(null), [setOverlay]);
2625
3949
  const triggerKeyDown = (event, menu) => {
2626
3950
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
@@ -2633,28 +3957,22 @@ function Header({ mobile }) {
2633
3957
  }
2634
3958
  };
2635
3959
  return /* @__PURE__ */ jsxs("header", { className: "cbx-header", children: [
2636
- /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button cbx-only-mobile", onClick: () => setOverlay("nav-sheet"), "aria-label": t("Open navigation"), "aria-haspopup": "dialog", children: /* @__PURE__ */ jsx(Menu, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
2637
3960
  organization !== void 0 && /* @__PURE__ */ jsxs("div", { className: "cbx-context cbx-only-desktop", children: [
2638
3961
  /* @__PURE__ */ jsxs("button", { ref: org, type: "button", className: `cbx-trigger ${overlay === "org" ? "is-open" : ""}`, "aria-haspopup": "dialog", "aria-expanded": overlay === "org", "aria-label": t("{level}: {name}", { level: organization.label, name: organization.current.name }), onClick: () => setOverlay(overlay === "org" ? null : "org"), onKeyDown: (event) => triggerKeyDown(event, "org"), children: [
2639
3962
  /* @__PURE__ */ jsx(Chip, { item: organization.current, tone: "solid" }),
2640
3963
  /* @__PURE__ */ jsx("span", { className: "cbx-trigger-text", title: organization.current.name, children: organization.current.name }),
2641
3964
  /* @__PURE__ */ jsx(ChevronsUpDown, { className: "cbx-trigger-chevron", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2642
3965
  ] }),
2643
- !mobile && /* @__PURE__ */ jsx(Popover, { open: overlay === "org", anchor: org, label: organization.label, onClose: close, children: /* @__PURE__ */ jsx(OrganizationMenu, { level: organization }) }),
3966
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "org", anchor: org, label: organization.label, onClose: close, children: /* @__PURE__ */ jsx(OrganizationMenu, { level: organization }) }),
2644
3967
  rest.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
2645
3968
  /* @__PURE__ */ jsx("span", { className: "cbx-separator", "aria-hidden": "true", children: "/" }),
2646
3969
  /* @__PURE__ */ jsxs("button", { ref: second, type: "button", className: `cbx-trigger ${overlay === "context" ? "is-open" : ""}`, "aria-haspopup": "dialog", "aria-expanded": overlay === "context", "aria-label": rest.map((level) => t("{level}: {name}", { level: level.label, name: level.current.name })).join(", "), onClick: () => setOverlay(overlay === "context" ? null : "context"), onKeyDown: (event) => triggerKeyDown(event, "context"), children: [
2647
3970
  /* @__PURE__ */ jsx(CascadeLabel, { levels: rest }),
2648
3971
  /* @__PURE__ */ jsx(ChevronsUpDown, { className: "cbx-trigger-chevron", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2649
3972
  ] }),
2650
- !mobile && /* @__PURE__ */ jsx(Popover, { open: overlay === "context", anchor: second, label: rest.map((level) => level.label).join(" / "), onClose: close, children: /* @__PURE__ */ jsx(CascadeMenu, { levels: rest, parent: organization.current.id }) })
3973
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "context", anchor: second, label: rest.map((level) => level.label).join(" / "), onClose: close, children: /* @__PURE__ */ jsx(CascadeMenu, { levels: rest, parent: organization.current.id }) })
2651
3974
  ] })
2652
3975
  ] }),
2653
- organization !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-trigger cbx-context-mobile cbx-only-mobile", onClick: () => setOverlay("context-sheet"), "aria-haspopup": "dialog", "aria-label": t("Where you are: {trail}", { trail }), children: [
2654
- /* @__PURE__ */ jsx(Chip, { item: organization.current, tone: "solid" }),
2655
- /* @__PURE__ */ jsx("span", { className: "cbx-trigger-text", children: trail }),
2656
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "cbx-trigger-chevron", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2657
- ] }),
2658
3976
  /* @__PURE__ */ jsxs("div", { className: "cbx-tools", children: [
2659
3977
  /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-search-button", onClick: () => setOverlay("palette"), "aria-label": t("Search or ask\u2026"), "aria-keyshortcuts": mac ? "Meta+K" : "Control+K", children: [
2660
3978
  /* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
@@ -2671,7 +3989,7 @@ function Header({ mobile }) {
2671
3989
  shell.notifications.unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-count", "aria-hidden": "true", children: shell.notifications.unread })
2672
3990
  ] }),
2673
3991
  /* @__PURE__ */ jsx("button", { ref: apps, type: "button", className: `cbx-tool cbx-tool-icon cbx-only-desktop ${overlay === "apps" ? "is-on" : ""}`, onClick: () => setOverlay(overlay === "apps" ? null : "apps"), "aria-haspopup": "dialog", "aria-expanded": overlay === "apps", "aria-label": t("Switch app"), title: t("Switch app"), children: /* @__PURE__ */ jsx(LayoutGrid, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) }),
2674
- !mobile && /* @__PURE__ */ jsx(Popover, { open: overlay === "apps", anchor: apps, placement: "bottom-end", label: t("Switch app"), onClose: close, children: /* @__PURE__ */ jsx(AppGrid, {}) })
3992
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "apps", anchor: apps, placement: "bottom-end", label: t("Switch app"), onClose: close, children: /* @__PURE__ */ jsx(AppGrid, {}) })
2675
3993
  ] })
2676
3994
  ] });
2677
3995
  }
@@ -3070,7 +4388,7 @@ function ComboboxGroupRows({
3070
4388
  /* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-foreground", children: opt.label }),
3071
4389
  opt.secondary !== void 0 ? /* @__PURE__ */ jsx("span", { className: "text-mono truncate text-[10px] text-muted-foreground", children: opt.secondary }) : null
3072
4390
  ] }),
3073
- isActive ? /* @__PURE__ */ jsx(Check3, {}) : null
4391
+ isActive ? /* @__PURE__ */ jsx(Check4, {}) : null
3074
4392
  ] });
3075
4393
  const className = cn(
3076
4394
  "group block w-full rounded-sm transition-colors text-left",
@@ -3139,7 +4457,7 @@ function FooterLink({
3139
4457
  prefetch: true,
3140
4458
  className,
3141
4459
  children: [
3142
- /* @__PURE__ */ jsx(Plus2, {}),
4460
+ /* @__PURE__ */ jsx(Plus5, {}),
3143
4461
  /* @__PURE__ */ jsx("span", { children: label })
3144
4462
  ]
3145
4463
  }
@@ -3152,7 +4470,7 @@ function FooterLink({
3152
4470
  className,
3153
4471
  onClick: onAfterClick,
3154
4472
  children: [
3155
- /* @__PURE__ */ jsx(Plus2, {}),
4473
+ /* @__PURE__ */ jsx(Plus5, {}),
3156
4474
  /* @__PURE__ */ jsx("span", { children: label })
3157
4475
  ]
3158
4476
  }
@@ -3252,7 +4570,7 @@ function Chevron({ open }) {
3252
4570
  }
3253
4571
  );
3254
4572
  }
3255
- function Check3() {
4573
+ function Check4() {
3256
4574
  return /* @__PURE__ */ jsx(
3257
4575
  "svg",
3258
4576
  {
@@ -3270,7 +4588,7 @@ function Check3() {
3270
4588
  }
3271
4589
  );
3272
4590
  }
3273
- function Plus2() {
4591
+ function Plus5() {
3274
4592
  return /* @__PURE__ */ jsx(
3275
4593
  "svg",
3276
4594
  {
@@ -3442,6 +4760,8 @@ function PageHeader({
3442
4760
  }) {
3443
4761
  const { t } = useCboxLocalization();
3444
4762
  const shellHelp = useShellHelp();
4763
+ const shellTitle = useShellPageTitle();
4764
+ const duplicate = shellTitle !== null && typeof title === "string" && sameTitle(title, shellTitle);
3445
4765
  return /* @__PURE__ */ jsxs(
3446
4766
  "header",
3447
4767
  {
@@ -3452,7 +4772,7 @@ function PageHeader({
3452
4772
  children: [
3453
4773
  /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
3454
4774
  eyebrow !== void 0 ? /* @__PURE__ */ jsx("p", { className: "text-mono text-[10px] font-semibold tracking-[0.18em] text-muted-foreground uppercase", children: eyebrow }) : null,
3455
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
4775
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-cbx-same-title": duplicate ? "" : void 0, children: [
3456
4776
  /* @__PURE__ */ jsx("h1", { className: "text-2xl leading-tight font-semibold tracking-tight text-foreground", children: title }),
3457
4777
  help && shellHelp !== null ? /* @__PURE__ */ jsx(
3458
4778
  "button",
@@ -4383,6 +5703,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
4383
5703
  ] });
4384
5704
  }
4385
5705
 
4386
- export { APP_HUES, AppContent, AppShell, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Combobox, DataPanel, EmptyState, Heading, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RowLink, SHELL_ICONS, SectionHeader, Sparkline, StatTile, StatusPill, applyTheme, buildUrlSearch, contextTrail, createHelpStore, defineUrlSchema, environmentFor, hueFor, initialsOf, interpolate, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useKnownAppCatalog, useShellHelp, withQuery };
5706
+ export { APP_HUES, AppContent, AppShell, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, EmptyState, Heading, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RowLink, SHELL_ICONS, SectionHeader, Sparkline, StatTile, StatusPill, applyTheme, buildUrlSearch, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useKnownAppCatalog, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
4387
5707
  //# sourceMappingURL=index.js.map
4388
5708
  //# sourceMappingURL=index.js.map