@cboxdk/cbox-ui 0.10.4 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,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,6 +76,10 @@ 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 };
@@ -340,8 +344,8 @@ var DEFAULT_FORMATS = [
340
344
  var FALLBACK_ZONES = ["UTC", "Europe/Copenhagen", "Europe/London", "Europe/Berlin", "Europe/Stockholm", "Europe/Oslo", "America/New_York", "America/Los_Angeles", "Asia/Tokyo"];
341
345
  function timeZones() {
342
346
  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, " ") }));
347
+ const zones2 = typeof supported === "function" ? supported("timeZone") : FALLBACK_ZONES;
348
+ return zones2.map((zone) => ({ code: zone, label: zone.replace(/_/g, " ") }));
345
349
  }
346
350
  function Avatar({ size = 30 }) {
347
351
  const { shell } = useShell();
@@ -357,7 +361,7 @@ function AccountMenu({ inline = false, onDone }) {
357
361
  const tab = inline ? 0 : -1;
358
362
  const languages = account.languages ?? DEFAULT_LANGUAGES;
359
363
  const formats = account.formats ?? DEFAULT_FORMATS;
360
- const zones = useMemo(() => view === "timeZone" ? timeZones() : [], [view]);
364
+ const zones2 = useMemo(() => view === "timeZone" ? timeZones() : [], [view]);
361
365
  useEffect(() => {
362
366
  if (view !== "main" || inline) return;
363
367
  menu.current?.querySelector('[role="menuitem"]')?.focus();
@@ -381,7 +385,7 @@ function AccountMenu({ inline = false, onDone }) {
381
385
  ] });
382
386
  if (view === "timeZone") return /* @__PURE__ */ jsxs("div", { className: "cbx-menu cbx-menu-account", children: [
383
387
  back,
384
- /* @__PURE__ */ jsx(OptionList, { label: t("Time zone"), options: zones, current: preferences.timeZone, onPick: pick("timeZone") })
388
+ /* @__PURE__ */ jsx(OptionList, { label: t("Time zone"), options: zones2, current: preferences.timeZone, onPick: pick("timeZone") })
385
389
  ] });
386
390
  const themes = [
387
391
  { value: "system", label: t("System"), icon: Monitor },
@@ -631,7 +635,7 @@ function forgetShellCatalog() {
631
635
  }
632
636
 
633
637
  // src/shell/data.ts
634
- var TONES = ["production", "sandbox", "neutral"];
638
+ var TONES = ["production", "sandbox", "neutral", "staging", "preview", "development"];
635
639
  function initialsOf(name) {
636
640
  const words = name.trim().split(/\s+/).filter(Boolean);
637
641
  const letters = words.length > 1 ? (words[0][0] ?? "") + (words[1][0] ?? "") : name.trim().slice(0, 2);
@@ -648,6 +652,9 @@ function toItem(value) {
648
652
  if (typeof row.label === "string" && row.label !== "") item.label = row.label;
649
653
  const test = row.testData ?? row.test_data;
650
654
  if (typeof test === "boolean") item.testData = test;
655
+ if (typeof row.live === "boolean") item.live = row.live;
656
+ if (typeof row.group === "string" && row.group !== "") item.group = row.group;
657
+ if (typeof row.description === "string" && row.description !== "") item.description = row.description;
651
658
  return item;
652
659
  }
653
660
  function parseListPage(body) {
@@ -810,6 +817,33 @@ function currentLocation() {
810
817
  if (typeof window === "undefined") return "/";
811
818
  return window.location.pathname + window.location.search + window.location.hash;
812
819
  }
820
+ function isLive(item) {
821
+ if (item.live !== void 0) return item.live;
822
+ if (item.testData === true) return false;
823
+ if (item.tone !== void 0) return item.tone === "production";
824
+ return void 0;
825
+ }
826
+ function environmentLevel(levels) {
827
+ return levels.find((level) => level.key === "environment");
828
+ }
829
+ function quickEnvironments(items, current) {
830
+ const picks = [current];
831
+ const live = items.find((item) => item.id !== current.id && isLive(item) === true);
832
+ if (live !== void 0) picks.push(live);
833
+ const test = items.find((item) => item.id !== current.id && item.id !== live?.id && isLive(item) !== true);
834
+ if (test !== void 0) picks.push(test);
835
+ return picks.slice(0, 3);
836
+ }
837
+ function groupItems(items) {
838
+ const runs = /* @__PURE__ */ new Map();
839
+ for (const item of items) {
840
+ const key = item.group ?? "";
841
+ const run = runs.get(key) ?? { group: item.group, items: [] };
842
+ run.items.push(item);
843
+ runs.set(key, run);
844
+ }
845
+ return Array.from(runs.values());
846
+ }
813
847
  var DEBOUNCE_MS = 120;
814
848
  var PAGE_SIZE = 25;
815
849
  function pageSize(url) {
@@ -915,7 +949,7 @@ function ToneSquare({ tone }) {
915
949
  function isEnvironmentLevel(level) {
916
950
  return level.key === "environment";
917
951
  }
918
- function LevelPane({ level, parent, currentId, heading, viewAll = true, searchable = true, autoFocus = false, chevron = false, createLabel, onPick, onPreview, onArrowRight, onArrowLeft, handle, className }) {
952
+ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchable = true, autoFocus = false, chevron = false, createLabel: createLabel2, onPick, onPreview, onArrowRight, onArrowLeft, handle, className }) {
919
953
  const { t, Link, navigate } = useShell();
920
954
  const [q, setQ] = useState("");
921
955
  const [active, setActiveRow] = useState(-1);
@@ -955,7 +989,7 @@ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchab
955
989
  useImperativeHandle(handle, () => ({ focus: focusSelf }), [focusSelf]);
956
990
  const optionId = (index) => `${id}-option-${index}`;
957
991
  const allId = `${id}-all`;
958
- const canCreate = level.createUrl !== void 0 && createLabel !== void 0;
992
+ const canCreate = level.createUrl !== void 0 && createLabel2 !== void 0;
959
993
  const viewAllLink = () => viewAll ? document.getElementById(allId) : null;
960
994
  const createAction = () => canCreate && !creating ? createButton.current : null;
961
995
  useEffect(() => {
@@ -1149,12 +1183,12 @@ function LevelPane({ level, parent, currentId, heading, viewAll = true, searchab
1149
1183
  ]
1150
1184
  }
1151
1185
  ),
1152
- canCreate && /* @__PURE__ */ jsx("div", { className: "cbx-pane-foot", children: creating ? /* @__PURE__ */ jsx(InlineCreate, { level, parent, label: createLabel, onCancel: () => {
1186
+ canCreate && /* @__PURE__ */ jsx("div", { className: "cbx-pane-foot", children: creating ? /* @__PURE__ */ jsx(InlineCreate, { level, parent, label: createLabel2, onCancel: () => {
1153
1187
  setCreating(false);
1154
1188
  focusSelf();
1155
1189
  } }) : /* @__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
1190
  /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1157
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: createLabel })
1191
+ /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: createLabel2 })
1158
1192
  ] }) })
1159
1193
  ] });
1160
1194
  }
@@ -1340,6 +1374,60 @@ function CascadeLabel({ levels }) {
1340
1374
  ] })
1341
1375
  ] });
1342
1376
  }
1377
+ var SHELL_ICONS = {
1378
+ activity: Activity,
1379
+ "bar-chart": BarChart3,
1380
+ bell: Bell,
1381
+ "book-open": BookOpen,
1382
+ boxes: Boxes,
1383
+ briefcase: Briefcase,
1384
+ building: Building2,
1385
+ calendar: Calendar,
1386
+ clock: Clock,
1387
+ cloud: Cloud,
1388
+ code: Code,
1389
+ "credit-card": CreditCard,
1390
+ database: Database,
1391
+ "file-text": FileText,
1392
+ folder: Folder,
1393
+ "git-branch": GitBranch,
1394
+ globe: Globe,
1395
+ "hard-drive": HardDrive,
1396
+ home: Home,
1397
+ inbox: Inbox,
1398
+ key: Key,
1399
+ "layout-dashboard": LayoutDashboard,
1400
+ "layout-grid": LayoutGrid,
1401
+ layers: Layers,
1402
+ "life-buoy": LifeBuoy,
1403
+ list: List,
1404
+ lock: Lock,
1405
+ mail: Mail,
1406
+ "message-square": MessageSquare,
1407
+ network: Network,
1408
+ package: Package,
1409
+ percent: Percent,
1410
+ plug: Plug,
1411
+ receipt: Receipt,
1412
+ rocket: Rocket,
1413
+ search: Search,
1414
+ send: Send,
1415
+ server: Server,
1416
+ settings: Settings,
1417
+ shield: Shield,
1418
+ "shield-check": ShieldCheck,
1419
+ sparkles: Sparkles,
1420
+ tag: Tag,
1421
+ timer: Timer,
1422
+ users: Users,
1423
+ wallet: Wallet,
1424
+ webhook: Webhook,
1425
+ zap: Zap
1426
+ };
1427
+ function resolveIcon(name, extra = {}) {
1428
+ if (name === void 0) return Circle;
1429
+ return extra[name] ?? SHELL_ICONS[name] ?? Circle;
1430
+ }
1343
1431
 
1344
1432
  // src/shell/help-store.ts
1345
1433
  var INITIAL_HELP_STATE = {
@@ -1419,6 +1507,14 @@ var SUPPORT_TAG = "cbox-support";
1419
1507
  function useHelpState(store, select) {
1420
1508
  return useSyncExternalStore(store.subscribe, () => select(store.get()), () => select(store.get()));
1421
1509
  }
1510
+ function useUnreadCount(store, sent) {
1511
+ const loaded = useHelpState(store, (state) => state.updatesStatus === "ready" ? state.updates.filter((update) => update.unread).length : null);
1512
+ return loaded ?? sent ?? 0;
1513
+ }
1514
+ function helpTopicName(shell) {
1515
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
1516
+ return shell.page?.title ?? area?.label ?? shell.app.name;
1517
+ }
1422
1518
  function contextTrail(shell) {
1423
1519
  return shell.context.levels.map((level) => level.current.name).join(" / ");
1424
1520
  }
@@ -1455,7 +1551,7 @@ function whenSupportReady(host, timeoutMs = 6e3) {
1455
1551
  attempt();
1456
1552
  });
1457
1553
  }
1458
- function HelpColumn({ docked }) {
1554
+ function HelpColumn({ docked, mobile = false }) {
1459
1555
  const { shell, t, help: store, toggleHelp, navigate, preferences } = useShell();
1460
1556
  const formatDate = useShortDate(preferences.regionalFormat ?? preferences.locale, preferences.timeZone);
1461
1557
  const open = useHelpState(store, (state) => helpVisible(state, docked));
@@ -1469,6 +1565,8 @@ function HelpColumn({ docked }) {
1469
1565
  const [results, setResults] = useState(null);
1470
1566
  const [question, setQuestion] = useState("");
1471
1567
  const [chatProblem, setChatProblem] = useState(false);
1568
+ const [asked, setAsked] = useState(false);
1569
+ const [followUp, setFollowUp] = useState("");
1472
1570
  const column = useRef(null);
1473
1571
  const body = useRef(null);
1474
1572
  const chatHost = useRef(null);
@@ -1502,7 +1600,7 @@ function HelpColumn({ docked }) {
1502
1600
  if (articles.topic === help.topic && articles.status === "ready") return;
1503
1601
  const controller = new AbortController();
1504
1602
  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) => {
1603
+ 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
1604
  if (error?.name !== "AbortError") setArticles({ topic: help.topic, items: [], status: "unavailable" });
1507
1605
  });
1508
1606
  return () => controller.abort();
@@ -1571,7 +1669,7 @@ function HelpColumn({ docked }) {
1571
1669
  if (closed) {
1572
1670
  const active = document.activeElement;
1573
1671
  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"]');
1672
+ const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
1575
1673
  back?.focus();
1576
1674
  }
1577
1675
  opener.current = null;
@@ -1602,7 +1700,123 @@ function HelpColumn({ docked }) {
1602
1700
  const submit = (event) => {
1603
1701
  event.preventDefault();
1604
1702
  void openChat(question.trim());
1703
+ if (question.trim() !== "") setAsked(true);
1605
1704
  };
1705
+ const pageArticles = help.articlesUrl !== void 0 ? articles.items : (help.articles ?? []).slice(0, 4);
1706
+ if (mobile) {
1707
+ const topic = helpTopicName(shell);
1708
+ const environment = environmentLevel(shell.context.levels)?.current;
1709
+ const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
1710
+ const chatReady = help.enabled && help.sessionUrl !== void 0;
1711
+ const close = () => toggleHelp(false);
1712
+ return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, onPointerDown: (event) => {
1713
+ if (event.target === event.currentTarget) close();
1714
+ }, children: /* @__PURE__ */ jsxs(
1715
+ "div",
1716
+ {
1717
+ ref: column,
1718
+ id: "cbx-help",
1719
+ className: "cbx-sheet cbx-sheet-bottom is-tall cbx-help-sheet",
1720
+ role: "dialog",
1721
+ "aria-modal": "true",
1722
+ "aria-label": t("Help with {page}", { page: topic }),
1723
+ tabIndex: -1,
1724
+ onKeyDown: (event) => {
1725
+ if (event.key === "Escape" && !event.defaultPrevented) {
1726
+ event.preventDefault();
1727
+ close();
1728
+ }
1729
+ trapTab(event, column.current);
1730
+ },
1731
+ children: [
1732
+ /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle", "aria-hidden": "true" }),
1733
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head ${article !== null ? "has-back" : ""}`, children: [
1734
+ 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 }) }),
1735
+ /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
1736
+ /* @__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 }) })
1737
+ ] }),
1738
+ /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
1739
+ article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
1740
+ /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
1741
+ (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
1742
+ article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
1743
+ t("Open the full article"),
1744
+ " ",
1745
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
1746
+ ] }),
1747
+ /* @__PURE__ */ jsx("p", { className: "cbx-eyebrow", children: t("Still stuck?") }),
1748
+ /* @__PURE__ */ jsxs(
1749
+ "form",
1750
+ {
1751
+ className: "cbx-askbar",
1752
+ onSubmit: (event) => {
1753
+ event.preventDefault();
1754
+ const text = followUp.trim();
1755
+ if (text === "") return;
1756
+ store.set({ article: null });
1757
+ setQuestion(text);
1758
+ setAsked(true);
1759
+ void openChat(text);
1760
+ },
1761
+ children: [
1762
+ /* @__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 }),
1763
+ /* @__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 }) })
1764
+ ]
1765
+ }
1766
+ )
1767
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1768
+ unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
1769
+ /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1770
+ /* @__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.") })
1771
+ ] }),
1772
+ /* @__PURE__ */ jsxs("form", { className: "cbx-askbar", onSubmit: submit, children: [
1773
+ /* @__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 }),
1774
+ /* @__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 }) })
1775
+ ] }),
1776
+ /* @__PURE__ */ jsxs("p", { className: "cbx-ctxnote", children: [
1777
+ environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
1778
+ t("Cbox sees this page: {page} in {where}", { page: topic, where })
1779
+ ] }),
1780
+ 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.") }),
1781
+ asked && chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
1782
+ /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1783
+ " ",
1784
+ t("Talk to a person")
1785
+ ] }),
1786
+ updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-threads", children: [
1787
+ /* @__PURE__ */ jsx("h2", { id: "cbx-help-threads", className: "cbx-eyebrow", children: t("Your conversations") }),
1788
+ /* @__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: [
1789
+ /* @__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 }) }),
1790
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
1791
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", children: update.title }),
1792
+ update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
1793
+ ] }),
1794
+ update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: 1 }) })
1795
+ ] }, update.id)) })
1796
+ ] }),
1797
+ pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-for", children: [
1798
+ /* @__PURE__ */ jsx("h2", { id: "cbx-help-for", className: "cbx-eyebrow", children: t("For {page}", { page: topic }) }),
1799
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => store.set({ article: item }), children: [
1800
+ /* @__PURE__ */ jsx(FileText, { className: "cbx-grow-icon", size: 18, strokeWidth: 1.7, "aria-hidden": true }),
1801
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.title }),
1802
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
1803
+ ] }, item.id)) })
1804
+ ] }),
1805
+ /* @__PURE__ */ jsxs("div", { className: "cbx-pbtns", children: [
1806
+ /* @__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") }),
1807
+ portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-pbtn", href: portal, target: "_blank", rel: "noopener", children: [
1808
+ t("Help center"),
1809
+ " ",
1810
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
1811
+ ] })
1812
+ ] })
1813
+ ] }),
1814
+ 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 }) })
1815
+ ] })
1816
+ ]
1817
+ }
1818
+ ) });
1819
+ }
1606
1820
  return /* @__PURE__ */ jsxs(
1607
1821
  "div",
1608
1822
  {
@@ -1694,9 +1908,9 @@ function HelpColumn({ docked }) {
1694
1908
  results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Searching\u2026") })
1695
1909
  ] })
1696
1910
  ] }),
1697
- help.topic !== void 0 && articles.items.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
1911
+ help.topic !== void 0 && pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
1698
1912
  /* @__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)) })
1913
+ /* @__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
1914
  ] }),
1701
1915
  /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-ask", children: [
1702
1916
  /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-ask", children: t("Ask Cbox") }) }),
@@ -1766,59 +1980,28 @@ function ArticleRow({ article }) {
1766
1980
  ] })
1767
1981
  ] });
1768
1982
  }
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;
1983
+
1984
+ // src/shell/recent.ts
1985
+ var LIMIT = 6;
1986
+ function storageKey(app) {
1987
+ return `cbox_shell_recent_${app}`;
1988
+ }
1989
+ function recentPages(app) {
1990
+ try {
1991
+ const raw = window.localStorage.getItem(storageKey(app));
1992
+ const parsed = raw === null ? [] : JSON.parse(raw);
1993
+ return Array.isArray(parsed) ? parsed.filter((row) => typeof row === "object" && row !== null && typeof row.title === "string" && typeof row.url === "string" && row.url.startsWith("/")) : [];
1994
+ } catch {
1995
+ return [];
1996
+ }
1997
+ }
1998
+ function rememberPage(app, page) {
1999
+ if (typeof window === "undefined" || !page.url.startsWith("/")) return;
2000
+ try {
2001
+ const next = [page, ...recentPages(app).filter((row) => row.url !== page.url)].slice(0, LIMIT);
2002
+ window.localStorage.setItem(storageKey(app), JSON.stringify(next));
2003
+ } catch {
2004
+ }
1822
2005
  }
1823
2006
  function navUrl(entry) {
1824
2007
  return entry.url ?? entry.href ?? "#";
@@ -1862,144 +2045,8 @@ function NavPageList({ pages, renderPage }) {
1862
2045
  ] }, `run-${index}`)
1863
2046
  ) });
1864
2047
  }
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
2048
  var GROUP_LIMIT = 5;
2049
+ var GROUP_KIND = { page: "actions", switch: "actions", actions: "actions", goto: "actions", records: "records", pages: "pages", docs: "help" };
2003
2050
  function matchScore(text, query2) {
2004
2051
  const haystack = text.toLowerCase();
2005
2052
  const terms = query2.toLowerCase().trim().split(/\s+/).filter(Boolean);
@@ -2026,7 +2073,7 @@ function localPages(shell, query2, open, lockedLabel) {
2026
2073
  }
2027
2074
  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
2075
  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) };
2076
+ 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
2077
  });
2031
2078
  }
2032
2079
  function rows(body, group) {
@@ -2039,7 +2086,8 @@ function rows(body, group) {
2039
2086
  return Array.isArray(data) ? data.filter((row) => typeof row === "object" && row !== null) : [];
2040
2087
  }
2041
2088
  function CommandPalette({ onClose }) {
2042
- const { shell, t, navigate, switchTo, openArticle, ask } = useShell();
2089
+ const { shell, t, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2090
+ const [scope, setScope] = useState("all");
2043
2091
  const [input, setInput] = useState("");
2044
2092
  const [query2, setQuery] = useState("");
2045
2093
  const [groups, setGroups] = useState({});
@@ -2083,17 +2131,26 @@ function CommandPalette({ onClose }) {
2083
2131
  setGroups({});
2084
2132
  return () => controller.abort();
2085
2133
  }
2086
- if (shell.palette.searchUrl !== void 0) {
2134
+ if (searchRecords !== void 0) {
2135
+ run(
2136
+ "records",
2137
+ async () => (await searchRecords(q2, signal)).flatMap((row) => {
2138
+ const url = safeUrl(row.url);
2139
+ if (url === void 0) return [];
2140
+ 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) }];
2141
+ })
2142
+ );
2143
+ } else if (shell.palette.searchUrl !== void 0) {
2087
2144
  run(
2088
2145
  "records",
2089
2146
  async () => rows(await requestJson(withQuery(shell.palette.searchUrl, { q: q2, group: "records" }), { signal }), "records").flatMap((row) => {
2090
2147
  const url = safeUrl(row.url);
2091
2148
  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) }];
2149
+ 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
2150
  })
2094
2151
  );
2095
2152
  }
2096
- const organization = shell.context.levels[0];
2153
+ const organization2 = shell.context.levels[0];
2097
2154
  run("goto", async () => {
2098
2155
  const loads = [];
2099
2156
  const kitGoto = shell.palette.gotoUrl === void 0 && shell.palette.searchUrl !== void 0;
@@ -2108,15 +2165,15 @@ function CommandPalette({ onClose }) {
2108
2165
  )
2109
2166
  );
2110
2167
  }
2111
- if (organization !== void 0 && !kitGoto) {
2168
+ if (organization2 !== void 0 && !kitGoto) {
2112
2169
  loads.push(
2113
- requestJson(withQuery(organization.listUrl, { q: q2, limit: "5" }), { signal }).then(
2170
+ requestJson(withQuery(organization2.listUrl, { q: q2, limit: "5" }), { signal }).then(
2114
2171
  (body) => rows(body).flatMap((row) => {
2115
2172
  if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.name !== "string") return [];
2116
2173
  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: () => {
2174
+ 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
2175
  onClose();
2119
- switchTo({ [organization.key]: orgId });
2176
+ switchTo({ [organization2.key]: orgId });
2120
2177
  } }];
2121
2178
  })
2122
2179
  )
@@ -2152,6 +2209,7 @@ function CommandPalette({ onClose }) {
2152
2209
  title: article.title,
2153
2210
  subtitle: article.excerpt,
2154
2211
  href: article.url,
2212
+ kind: "help",
2155
2213
  icon: /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2156
2214
  run: (newTab) => {
2157
2215
  if (newTab && article.url !== void 0) {
@@ -2165,42 +2223,126 @@ function CommandPalette({ onClose }) {
2165
2223
  );
2166
2224
  }
2167
2225
  return () => controller.abort();
2168
- }, [query2, shell]);
2226
+ }, [query2, shell, searchRecords]);
2169
2227
  const q = input.trim();
2228
+ const topic = helpTopicName(shell);
2229
+ const organization = shell.context.levels[0];
2230
+ const environment = environmentLevel(shell.context.levels);
2231
+ const envIndex = environment !== void 0 ? shell.context.levels.indexOf(environment) : -1;
2232
+ const envParent = envIndex > 0 ? shell.context.levels[envIndex - 1] : void 0;
2233
+ const environments = useContextList(environment?.listUrl, { parent: envParent?.current.id, enabled: environment !== void 0 });
2170
2234
  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" });
2235
+ const toItem2 = (action, prefix) => {
2236
+ const Icon = action.icon !== void 0 ? resolveIcon(action.icon) : Zap;
2237
+ return {
2238
+ id: `${prefix}:${action.id}`,
2239
+ title: action.label,
2240
+ subtitle: action.hint,
2241
+ href: action.method === "post" ? void 0 : action.url,
2242
+ kind: "actions",
2243
+ icon: /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2244
+ run: (newTab) => {
2245
+ if (!newTab) onClose();
2246
+ if (!newTab && action.create !== void 0 && canCreate && findCreatable(shell, action.create) !== void 0) {
2247
+ openCreate(action.create);
2248
+ return;
2182
2249
  }
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 } },
2191
- { 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: [] } }
2193
- ];
2194
- if (q !== "") {
2195
- sections.push({
2196
- key: "ask",
2197
- label: t("Ask Cbox"),
2198
- state: {
2199
- 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: () => {
2250
+ navigate(action.url, { method: action.method ?? "get", newTab: newTab && action.method !== "post" });
2251
+ }
2252
+ };
2253
+ };
2254
+ const matches2 = (item, words = []) => matchScore(`${item.title} ${item.subtitle ?? ""} ${words.join(" ")}`, q) > 0;
2255
+ const createItem2 = (key) => {
2256
+ const creatable = findCreatable(shell, key);
2257
+ if (creatable === void 0 || !canCreate) return null;
2258
+ 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: () => {
2259
+ onClose();
2260
+ openCreate(key);
2261
+ } };
2262
+ };
2263
+ const pageCreate = shell.page?.create !== void 0 ? createItem2(shell.page.create) : null;
2264
+ const pageActions = [...pageCreate !== null ? [pageCreate] : [], ...(shell.page?.actions ?? []).map((action) => toItem2(action, "page"))];
2265
+ const globalActions = shell.palette.actions.map((action) => toItem2(action, "action"));
2266
+ const switchItems = [];
2267
+ if (environment !== void 0) {
2268
+ environments.items.filter((item) => item.id !== environment.current.id).slice(0, 3).forEach(
2269
+ (item) => switchItems.push({
2270
+ id: `switch:${item.id}`,
2271
+ title: t("Switch to {name}", { name: item.name }),
2272
+ subtitle: environment.label,
2273
+ kind: "actions",
2274
+ icon: /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
2275
+ run: () => {
2201
2276
  onClose();
2202
- ask(q);
2203
- } }]
2277
+ switchTo(envParent !== void 0 ? { [envParent.key]: envParent.current.id, [environment.key]: item.id } : { [environment.key]: item.id });
2278
+ }
2279
+ })
2280
+ );
2281
+ }
2282
+ if (organization !== void 0) {
2283
+ switchItems.push({
2284
+ id: "switch:organization",
2285
+ title: t("Switch {thing}", { thing: organization.label.toLowerCase() }),
2286
+ subtitle: t("Now {name}", { name: organization.current.name }),
2287
+ kind: "actions",
2288
+ icon: /* @__PURE__ */ jsx(ArrowLeftRight, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2289
+ run: () => {
2290
+ onClose();
2291
+ openContext(organization.key, true);
2292
+ }
2293
+ });
2294
+ }
2295
+ const recent = useMemo(() => {
2296
+ if (shell.palette.recent !== void 0) {
2297
+ return shell.palette.recent.flatMap((row) => {
2298
+ const url = safeUrl(row.url);
2299
+ 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) }];
2300
+ });
2301
+ }
2302
+ const here = typeof window !== "undefined" ? window.location.pathname + window.location.search + window.location.hash : "";
2303
+ 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) }));
2304
+ }, [shell]);
2305
+ const ready = (items) => ({ status: "ready", items });
2306
+ const sections = q === "" ? [
2307
+ pageActions.length > 0 ? { key: "page", label: t("On {page}", { page: topic }), state: ready(pageActions) } : { key: "actions", label: t("Actions"), state: ready(globalActions) },
2308
+ { key: "recent", label: t("Recent"), state: ready(recent) },
2309
+ { key: "switch", label: t("Switch"), state: ready(switchItems) }
2310
+ ] : [
2311
+ {
2312
+ key: "actions",
2313
+ label: t("Actions"),
2314
+ state: ready(
2315
+ [
2316
+ ...pageActions.filter((item) => matches2(item, (shell.page?.actions ?? []).find((action) => `page:${action.id}` === item.id)?.keywords)),
2317
+ ...globalActions.filter((item) => matches2(item, shell.palette.actions.find((action) => `action:${action.id}` === item.id)?.keywords)),
2318
+ ...(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)),
2319
+ ...switchItems.filter((item) => matches2(item))
2320
+ ]
2321
+ )
2322
+ },
2323
+ { key: "goto", label: t("Go to"), state: groups.goto ?? { status: "idle", items: [] } },
2324
+ { key: "records", label: t("Records"), state: groups.records ?? { status: "idle", items: [] } },
2325
+ { key: "pages", label: t("Pages"), state: ready(pages) },
2326
+ { key: "docs", label: t("Help"), state: groups.docs ?? { status: "idle", items: [] } }
2327
+ ];
2328
+ const scoped = sections.map((section) => {
2329
+ if (scope === "all") return section;
2330
+ const kind = section.key === "recent" || section.key === "ask" ? null : GROUP_KIND[section.key];
2331
+ if (kind !== null && kind !== scope) return null;
2332
+ return { ...section, state: { ...section.state, items: section.state.items.filter((item) => item.kind === void 0 || item.kind === scope) } };
2333
+ }).filter((section) => section !== null);
2334
+ sections.length = 0;
2335
+ sections.push(...scoped);
2336
+ if (q !== "") {
2337
+ sections.push({
2338
+ key: "ask",
2339
+ label: t("Ask Cbox"),
2340
+ state: {
2341
+ status: "ready",
2342
+ 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: () => {
2343
+ onClose();
2344
+ ask(q);
2345
+ } }]
2204
2346
  }
2205
2347
  });
2206
2348
  }
@@ -2216,7 +2358,7 @@ function CommandPalette({ onClose }) {
2216
2358
  });
2217
2359
  const keyOf = (option) => option.kind === "item" ? `${option.group}:${option.item.id}` : `all:${option.group}`;
2218
2360
  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";
2361
+ const current = (group) => group === "pages" || group === "actions" || group === "page" || group === "recent" || group === "switch" || debounced && sections.find((section) => section.key === group)?.state.status === "ready";
2220
2362
  const busy = !debounced || sections.some((section) => section.state.status === "loading");
2221
2363
  const firstResult = options.find((option) => option.group !== "ask" && current(option.group));
2222
2364
  const autoKey = firstResult !== void 0 ? keyOf(firstResult) : !busy && options[0] !== void 0 ? keyOf(options[0]) : null;
@@ -2266,31 +2408,42 @@ function CommandPalette({ onClose }) {
2266
2408
  }
2267
2409
  };
2268
2410
  const activeOption = options[active];
2269
- return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-palette-backdrop", onPointerDown: (event) => {
2411
+ const scopes = [
2412
+ { value: "all", label: t("All") },
2413
+ { value: "actions", label: t("Actions") },
2414
+ { value: "records", label: t("Records") },
2415
+ { value: "pages", label: t("Pages") },
2416
+ { value: "help", label: t("Help") }
2417
+ ];
2418
+ return /* @__PURE__ */ jsx("div", { className: `cbx-overlay cbx-palette-backdrop ${mobile ? "is-sheet" : ""}`, onPointerDown: (event) => {
2270
2419
  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: [
2420
+ }, 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: [
2421
+ mobile && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle", "aria-hidden": "true" }),
2272
2422
  /* @__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" })
2423
+ /* @__PURE__ */ jsxs("label", { className: "cbx-palette-field", children: [
2424
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2425
+ /* @__PURE__ */ jsx(
2426
+ "input",
2427
+ {
2428
+ ref: field,
2429
+ type: "search",
2430
+ role: "combobox",
2431
+ "aria-expanded": "true",
2432
+ "aria-controls": `${id}-list`,
2433
+ "aria-activedescendant": activeOption !== void 0 ? `${id}-${active}` : void 0,
2434
+ "aria-autocomplete": "list",
2435
+ "aria-label": shell.palette.placeholder ?? t("Search or ask\u2026"),
2436
+ placeholder: shell.palette.placeholder ?? (mobile ? t("Search, act or ask\u2026") : t("Search or ask\u2026")),
2437
+ value: input,
2438
+ onChange: (event) => setInput(event.target.value),
2439
+ autoComplete: "off",
2440
+ spellCheck: false
2441
+ }
2442
+ )
2443
+ ] }),
2444
+ mobile ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-palette-cancel", onClick: onClose, children: t("Cancel") }) : /* @__PURE__ */ jsx("kbd", { className: "cbx-kbd", children: "Esc" })
2293
2445
  ] }),
2446
+ /* @__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)) }),
2294
2447
  /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", children: [
2295
2448
  rendered.map((section) => {
2296
2449
  const loading = section.state.status === "loading" && section.state.items.length === 0;
@@ -2301,7 +2454,7 @@ function CommandPalette({ onClose }) {
2301
2454
  section.state.status === "loading" && /* @__PURE__ */ jsx("span", { className: "cbx-palette-busy", "aria-hidden": "true" })
2302
2455
  ] }),
2303
2456
  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) => {
2457
+ 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
2458
  const index = section.start + offset;
2306
2459
  const on = index === active;
2307
2460
  return /* @__PURE__ */ jsx(
@@ -2315,8 +2468,10 @@ function CommandPalette({ onClose }) {
2315
2468
  onClick: (event) => choose(option, event.metaKey || event.ctrlKey),
2316
2469
  children: option.kind === "item" ? /* @__PURE__ */ jsxs(Fragment, { children: [
2317
2470
  /* @__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 }),
2471
+ /* @__PURE__ */ jsxs("span", { className: "cbx-row-text", children: [
2472
+ /* @__PURE__ */ jsx("span", { className: "cbx-row-name", title: option.item.title, children: option.item.title }),
2473
+ option.item.subtitle !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-row-label cbx-truncate", children: option.item.subtitle })
2474
+ ] }),
2320
2475
  on && /* @__PURE__ */ jsx(CornerDownLeft, { className: "cbx-row-trail", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2321
2476
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2322
2477
  /* @__PURE__ */ jsx("span", { className: "cbx-row-icon", children: /* @__PURE__ */ jsx(ArrowRight, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) }),
@@ -2325,7 +2480,7 @@ function CommandPalette({ onClose }) {
2325
2480
  },
2326
2481
  option.kind === "item" ? option.item.id : `all:${option.group}`
2327
2482
  );
2328
- })
2483
+ }) })
2329
2484
  ] }, section.key);
2330
2485
  }),
2331
2486
  options.length === 0 && q !== "" && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: q }) })
@@ -2350,6 +2505,681 @@ function CommandPalette({ onClose }) {
2350
2505
  ] })
2351
2506
  ] }) });
2352
2507
  }
2508
+ function Sheet({
2509
+ label,
2510
+ side = "bottom",
2511
+ onClose,
2512
+ children,
2513
+ title,
2514
+ back,
2515
+ size,
2516
+ className,
2517
+ bodyClassName
2518
+ }) {
2519
+ const { t } = useShell();
2520
+ const panel = useRef(null);
2521
+ const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2522
+ useEffect(() => {
2523
+ panel.current?.focus();
2524
+ const restore = opener.current;
2525
+ return () => {
2526
+ if (restore instanceof HTMLElement && restore.isConnected) restore.focus();
2527
+ };
2528
+ }, []);
2529
+ return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-sheet-backdrop", onPointerDown: (event) => {
2530
+ if (event.target === event.currentTarget) onClose();
2531
+ }, children: /* @__PURE__ */ jsxs(
2532
+ "div",
2533
+ {
2534
+ ref: panel,
2535
+ className: `cbx-sheet cbx-sheet-${side} ${size !== void 0 ? `is-${size}` : ""} ${className ?? ""}`,
2536
+ role: "dialog",
2537
+ "aria-modal": "true",
2538
+ "aria-label": label,
2539
+ tabIndex: -1,
2540
+ onKeyDown: (event) => {
2541
+ if (event.key === "Escape" && !event.defaultPrevented) {
2542
+ event.preventDefault();
2543
+ onClose();
2544
+ }
2545
+ trapTab(event, panel.current);
2546
+ },
2547
+ children: [
2548
+ side === "bottom" && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle", "aria-hidden": "true" }),
2549
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head ${back !== void 0 ? "has-back" : ""}`, children: [
2550
+ back !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-sheet-back", onClick: back.onBack, "aria-label": back.label, children: [
2551
+ /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }),
2552
+ back.text !== void 0 && /* @__PURE__ */ jsx("span", { children: back.text })
2553
+ ] }),
2554
+ /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: title ?? label }),
2555
+ /* @__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 }) })
2556
+ ] }),
2557
+ /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, children })
2558
+ ]
2559
+ }
2560
+ ) });
2561
+ }
2562
+ function findCreatable(shell, key) {
2563
+ if (key === void 0 || key === null) return void 0;
2564
+ return shell.create?.items.find((item) => item.key === key);
2565
+ }
2566
+ function pageCreateKey(shell) {
2567
+ return findCreatable(shell, shell.page?.create)?.key ?? findCreatable(shell, shell.create?.default)?.key ?? null;
2568
+ }
2569
+ function createLabel(shell, t) {
2570
+ const own = findCreatable(shell, shell.page?.create);
2571
+ return own !== void 0 ? t("New {thing}", { thing: own.label.toLowerCase() }) : t("Create");
2572
+ }
2573
+ function CreateSheet({ onClose }) {
2574
+ const { shell, t, mobile, createKey, renderCreate } = useShell();
2575
+ const [stack, setStack] = useState(() => findCreatable(shell, createKey) !== void 0 ? [{ kind: "tree" }, { kind: "form", key: createKey }] : [{ kind: "tree" }]);
2576
+ const top = stack[stack.length - 1];
2577
+ const below = stack.length > 1 ? stack[stack.length - 2] : null;
2578
+ const environmentLevelItem = environmentLevel(shell.context.levels)?.current ?? null;
2579
+ const notLive = environmentLevelItem !== null && isLive(environmentLevelItem) === false;
2580
+ const name = (entry) => entry === null ? "" : entry.kind === "tree" ? t("Create") : findCreatable(shell, entry.key)?.label ?? entry.key;
2581
+ const pop = () => setStack((current) => current.length > 1 ? current.slice(0, -1) : current);
2582
+ const title = top.kind === "tree" ? t("Create") : t("New {thing}", { thing: name(top).toLowerCase() });
2583
+ return /* @__PURE__ */ jsxs(
2584
+ Sheet,
2585
+ {
2586
+ label: title,
2587
+ side: mobile ? "bottom" : "right",
2588
+ size: "tall",
2589
+ onClose,
2590
+ className: "cbx-create-sheet",
2591
+ back: below !== null ? { label: t("Back to {thing}", { thing: name(below) }), text: name(below), onBack: pop } : void 0,
2592
+ children: [
2593
+ top.kind === "tree" && /* @__PURE__ */ jsx(CreateTree, { onPick: (key) => setStack([{ kind: "tree" }, { kind: "form", key }]) }),
2594
+ notLive && top.kind === "form" && /* @__PURE__ */ jsxs("p", { className: "cbx-create-env", role: "note", children: [
2595
+ /* @__PURE__ */ jsx(ToneSquare, { tone: environmentLevelItem.tone }),
2596
+ t("Creating in {environment}, not production", { environment: environmentLevelItem.name })
2597
+ ] }),
2598
+ stack.map((entry, index) => {
2599
+ if (entry.kind !== "form") return null;
2600
+ const creatable = findCreatable(shell, entry.key);
2601
+ if (creatable === void 0) return null;
2602
+ const under = stack[index - 1];
2603
+ const parent = under?.kind === "form" ? findCreatable(shell, under.key) ?? null : null;
2604
+ const form = {
2605
+ creatable,
2606
+ parent,
2607
+ submitLabel: parent !== null ? t("Create and use in {thing}", { thing: parent.label.toLowerCase() }) : creatable.submitLabel ?? t("Create {thing}", { thing: creatable.label.toLowerCase() }),
2608
+ createRef: (key, onCreated) => {
2609
+ if (findCreatable(shell, key) === void 0) return;
2610
+ setStack((current) => [...current.slice(0, index + 1), { kind: "form", key, onCreated }]);
2611
+ },
2612
+ done: (created) => {
2613
+ if (parent === null) {
2614
+ onClose();
2615
+ return;
2616
+ }
2617
+ setStack((current) => current.slice(0, index));
2618
+ if (created !== void 0) entry.onCreated?.(created);
2619
+ },
2620
+ close: onClose,
2621
+ environment: environmentLevelItem
2622
+ };
2623
+ const body = renderCreate?.(form) ?? null;
2624
+ 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}`);
2625
+ })
2626
+ ]
2627
+ }
2628
+ );
2629
+ }
2630
+ function CreateTree({ onPick }) {
2631
+ const { shell, t, icons } = useShell();
2632
+ const [q, setQ] = useState("");
2633
+ const groups = useMemo(() => {
2634
+ const items = (shell.create?.items ?? []).filter((item) => matchScore(`${item.label} ${(item.keywords ?? []).join(" ")}`, q) > 0);
2635
+ const order = [shell.nav.activeArea, ...shell.nav.areas.map((area) => area.key).filter((key) => key !== shell.nav.activeArea)];
2636
+ const keys = Array.from(new Set(items.map((item) => item.area))).sort((a, b) => {
2637
+ const ia = order.indexOf(a);
2638
+ const ib = order.indexOf(b);
2639
+ return (ia < 0 ? order.length : ia) - (ib < 0 ? order.length : ib);
2640
+ });
2641
+ return keys.map((key) => ({ area: shell.nav.areas.find((area) => area.key === key), key, items: items.filter((item) => item.area === key) }));
2642
+ }, [shell, q]);
2643
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-create-tree", children: [
2644
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
2645
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2646
+ /* @__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" })
2647
+ ] }),
2648
+ groups.map((group) => {
2649
+ const Icon = resolveIcon(group.area?.icon, icons);
2650
+ return /* @__PURE__ */ jsxs("section", { "aria-label": group.area?.label ?? group.key, children: [
2651
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: group.area?.label ?? group.key }),
2652
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: group.items.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => onPick(item.key), children: [
2653
+ /* @__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 }) }),
2654
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.label }),
2655
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2656
+ ] }, item.key)) })
2657
+ ] }, group.key);
2658
+ }),
2659
+ groups.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: q.trim() }) })
2660
+ ] });
2661
+ }
2662
+ function CreateField({ label, children, htmlFor }) {
2663
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-cfield", children: [
2664
+ htmlFor !== void 0 ? /* @__PURE__ */ jsx("label", { className: "cbx-cfield-label", htmlFor, children: label }) : /* @__PURE__ */ jsx("span", { className: "cbx-cfield-label", children: label }),
2665
+ children
2666
+ ] });
2667
+ }
2668
+ function CreateRefField({ label, value, placeholder, thing, onChoose, onCreate }) {
2669
+ const { t } = useShell();
2670
+ const id = useId();
2671
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-cfield", role: "group", "aria-labelledby": id, children: [
2672
+ /* @__PURE__ */ jsx("span", { id, className: "cbx-cfield-label", children: label }),
2673
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
2674
+ /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow ${value ? "" : "is-empty"}`, onClick: onChoose, "aria-haspopup": onChoose !== void 0 ? "dialog" : void 0, children: [
2675
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: value || placeholder }),
2676
+ /* @__PURE__ */ jsx(ChevronDown, { className: "cbx-grow-trail", size: 14, strokeWidth: 2, "aria-hidden": true })
2677
+ ] }),
2678
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-accent", onClick: onCreate, children: [
2679
+ /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2680
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("New {thing}", { thing: thing.toLowerCase() }) })
2681
+ ] })
2682
+ ] })
2683
+ ] });
2684
+ }
2685
+ function CreateSubmit({ form, busy = false, disabled = false }) {
2686
+ const { t } = useShell();
2687
+ 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 });
2688
+ }
2689
+ function CreateForm({ onSubmit, children }) {
2690
+ return /* @__PURE__ */ jsx("form", { className: "cbx-cform", onSubmit: (event) => {
2691
+ event.preventDefault();
2692
+ onSubmit(event);
2693
+ }, children });
2694
+ }
2695
+ var MAX_TABS = 4;
2696
+ function tabAreas(areas, tabs) {
2697
+ const chosen = tabs === void 0 ? areas.slice(0, MAX_TABS) : tabs.map((key) => areas.find((area) => area.key === key)).filter((area) => area !== void 0);
2698
+ return chosen.slice(0, MAX_TABS);
2699
+ }
2700
+ function pillLines(levels) {
2701
+ const main = levels[levels.length - 1];
2702
+ if (levels.length <= 1) return { top: main?.label ?? "", main };
2703
+ return { top: levels.slice(0, -1).map((level) => level.current.name).join(" \xB7 "), main };
2704
+ }
2705
+ function notLiveEnvironment(levels) {
2706
+ const environment = environmentLevel(levels)?.current;
2707
+ return environment !== void 0 && isLive(environment) === false ? environment : null;
2708
+ }
2709
+ function useUnread() {
2710
+ const { shell, help } = useShell();
2711
+ return useUnreadCount(help, shell.help.unread);
2712
+ }
2713
+ function MobileTopBar() {
2714
+ const { shell, t, openContext, toggleHelp, setOverlay, openCreate, canCreate } = useShell();
2715
+ const levels = shell.context.levels;
2716
+ const organization = levels[0];
2717
+ const { top, main } = pillLines(levels);
2718
+ const unread = useUnread();
2719
+ const topic = helpTopicName(shell);
2720
+ const trail = levels.map((level) => level.current.name).join(", ");
2721
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-m-bar", children: [
2722
+ 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: [
2723
+ /* @__PURE__ */ jsx(Chip, { item: organization.current, tone: "solid" }),
2724
+ /* @__PURE__ */ jsxs("span", { className: "cbx-m-pill-text", children: [
2725
+ /* @__PURE__ */ jsx("span", { className: "cbx-m-pill-top", children: top }),
2726
+ /* @__PURE__ */ jsxs("span", { className: "cbx-m-pill-main", children: [
2727
+ main?.key === "environment" && /* @__PURE__ */ jsx(ToneSquare, { tone: main.current.tone }),
2728
+ /* @__PURE__ */ jsx("span", { className: "cbx-truncate", children: main?.current.name })
2729
+ ] })
2730
+ ] }),
2731
+ /* @__PURE__ */ jsx(ChevronDown, { className: "cbx-m-pill-chevron", size: 14, strokeWidth: 2, "aria-hidden": true })
2732
+ ] }),
2733
+ /* @__PURE__ */ jsx("span", { className: "cbx-m-spacer" }),
2734
+ /* @__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: [
2735
+ /* @__PURE__ */ jsx(CircleHelp, { size: 21, strokeWidth: 1.8, "aria-hidden": true }),
2736
+ unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-m-dot", "aria-hidden": "true" })
2737
+ ] }),
2738
+ /* @__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 }) }),
2739
+ 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 }) })
2740
+ ] });
2741
+ }
2742
+ function MobileAreaHead() {
2743
+ const { shell, t, Link } = useShell();
2744
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
2745
+ const pages = area?.pages ?? [];
2746
+ const environment = notLiveEnvironment(shell.context.levels);
2747
+ const strip = useRef(null);
2748
+ useEffect(() => {
2749
+ const list = strip.current;
2750
+ const current = list?.querySelector('[aria-current="page"]');
2751
+ if (list === null || list === void 0 || current === null || current === void 0) return;
2752
+ const overflow = current.offsetLeft + current.offsetWidth - list.clientWidth;
2753
+ if (overflow > 0) list.scrollLeft = overflow + 32;
2754
+ }, [shell.nav.activePage, shell.nav.activeArea]);
2755
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-m-head", children: [
2756
+ area !== void 0 && /* @__PURE__ */ jsx("p", { className: "cbx-m-title", children: area.label }),
2757
+ environment !== null && /* @__PURE__ */ jsxs("div", { className: `cbx-m-env cbx-env-${environment.tone ?? "neutral"}`, role: "status", children: [
2758
+ /* @__PURE__ */ jsx(ToneSquare, { tone: environment.tone }),
2759
+ /* @__PURE__ */ jsx("span", { children: t("{environment}. Not production, nothing here touches live customers.", { environment: environment.name }) })
2760
+ ] }),
2761
+ 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) => {
2762
+ const on = page.key === shell.nav.activePage;
2763
+ return /* @__PURE__ */ jsxs(Link, { href: navUrl(page), className: `cbx-m-chip ${on ? "is-on" : ""}`, "aria-current": on ? "page" : void 0, children: [
2764
+ page.label,
2765
+ page.locked === true && /* @__PURE__ */ jsx(NavPageMarks, { page })
2766
+ ] }, page.key);
2767
+ }) }) : /* @__PURE__ */ jsx("div", { className: "cbx-m-chips-gap" })
2768
+ ] });
2769
+ }
2770
+ function TabBar({ onMore }) {
2771
+ const { shell, t, Link, icons, overlay, setOverlay } = useShell();
2772
+ const tabs = tabAreas(shell.nav.areas, shell.nav.tabs);
2773
+ const moreOpen = overlay === "more";
2774
+ const inTabs = tabs.some((area) => area.key === shell.nav.activeArea);
2775
+ return /* @__PURE__ */ jsxs("nav", { className: "cbx-tabbar", "aria-label": t("Main"), children: [
2776
+ tabs.map((area) => {
2777
+ const Icon = resolveIcon(area.icon, icons);
2778
+ const on = !moreOpen && area.key === shell.nav.activeArea;
2779
+ return /* @__PURE__ */ jsxs(Link, { href: navUrl(area), className: `cbx-tab ${on ? "is-on" : ""}`, "aria-current": on ? "page" : void 0, onClick: () => {
2780
+ if (moreOpen) setOverlay(null);
2781
+ }, children: [
2782
+ /* @__PURE__ */ jsx(Icon, { size: 23, strokeWidth: 1.7, "aria-hidden": true }),
2783
+ /* @__PURE__ */ jsx("span", { children: area.label })
2784
+ ] }, area.key);
2785
+ }),
2786
+ /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-tab ${moreOpen || !inTabs ? "is-on" : ""}`, "aria-expanded": moreOpen, "aria-controls": "cbx-more", onClick: onMore, children: [
2787
+ /* @__PURE__ */ jsx(MoreHorizontal, { size: 23, strokeWidth: 1.7, "aria-hidden": true }),
2788
+ /* @__PURE__ */ jsx("span", { children: t("More") })
2789
+ ] })
2790
+ ] });
2791
+ }
2792
+ function BackBar({ label, onBack }) {
2793
+ return /* @__PURE__ */ jsx("div", { className: "cbx-m-bar", children: /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-m-back", onClick: onBack, children: [
2794
+ /* @__PURE__ */ jsx(ChevronLeft, { size: 22, strokeWidth: 2, "aria-hidden": true }),
2795
+ label
2796
+ ] }) });
2797
+ }
2798
+ function Row({ children, onClick, href, className, ...rest }) {
2799
+ const { Link } = useShell();
2800
+ if (href !== void 0) {
2801
+ if (rest.target !== void 0) return /* @__PURE__ */ jsx("a", { href, className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
2802
+ return /* @__PURE__ */ jsx(Link, { href, className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
2803
+ }
2804
+ return /* @__PURE__ */ jsx("button", { type: "button", className: `cbx-grow ${className ?? ""}`, onClick, ...rest, children });
2805
+ }
2806
+ var Trail = () => /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true });
2807
+ function MoreScreen({ view, setView }) {
2808
+ const { t } = useShell();
2809
+ const top = useRef(null);
2810
+ useEffect(() => {
2811
+ if (typeof window !== "undefined" && typeof window.scrollTo === "function") {
2812
+ try {
2813
+ window.scrollTo(0, 0);
2814
+ } catch {
2815
+ }
2816
+ }
2817
+ top.current?.focus({ preventScroll: true });
2818
+ }, [view]);
2819
+ let body;
2820
+ if (view.kind === "area") body = /* @__PURE__ */ jsx(MoreArea, { areaKey: view.key, onBack: () => setView({ kind: "root" }) });
2821
+ else if (view.kind === "account") body = /* @__PURE__ */ jsx(MoreAccount, { onBack: () => setView({ kind: "root" }), onOption: (which) => setView({ kind: "option", which }) });
2822
+ else if (view.kind === "option") body = /* @__PURE__ */ jsx(MoreOption, { which: view.which, onBack: () => setView({ kind: "account" }) });
2823
+ else body = /* @__PURE__ */ jsx(MoreRoot, { onArea: (key) => setView({ kind: "area", key }), onAccount: () => setView({ kind: "account" }) });
2824
+ return /* @__PURE__ */ jsx("section", { id: "cbx-more", className: "cbx-more", "aria-label": t("More"), ref: top, tabIndex: -1, children: body });
2825
+ }
2826
+ function MoreRoot({ onArea, onAccount }) {
2827
+ const { shell, t, icons, Link, setOverlay, openContext, toggleHelp } = useShell();
2828
+ const [q, setQ] = useState("");
2829
+ const unread = useUnread();
2830
+ const topic = helpTopicName(shell);
2831
+ const hits = useMemo(() => {
2832
+ const query2 = q.trim();
2833
+ if (query2 === "") return [];
2834
+ const found = [];
2835
+ for (const area of shell.nav.areas) {
2836
+ const pages = area.pages ?? [];
2837
+ if (pages.length === 0) {
2838
+ const score = matchScore(area.label, query2);
2839
+ if (score > 0) found.push({ key: area.key, label: area.label, area: area.label, url: navUrl(area), score });
2840
+ }
2841
+ for (const page of pages) {
2842
+ const score = Math.max(matchScore(page.label, query2), matchScore(`${area.label} ${page.group ?? ""}`, query2) > 0 ? 1 : 0);
2843
+ if (score > 0) found.push({ key: `${area.key}:${page.key}`, label: page.label, area: area.label, url: navUrl(page), score });
2844
+ }
2845
+ }
2846
+ return found.sort((a, b) => b.score - a.score);
2847
+ }, [q, shell]);
2848
+ const appName = shell.app.name.replace(/^Cbox\s*·?\s*/i, "");
2849
+ const account = shell.account ?? {};
2850
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
2851
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-bar" }),
2852
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: t("More") }),
2853
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
2854
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2855
+ /* @__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" })
2856
+ ] }),
2857
+ q.trim() !== "" ? /* @__PURE__ */ jsxs("div", { className: "cbx-group", role: "group", "aria-label": t("Pages"), children: [
2858
+ hits.map((hit) => /* @__PURE__ */ jsxs(Link, { href: hit.url, className: "cbx-grow", onClick: () => setOverlay(null), children: [
2859
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: hit.label }),
2860
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: hit.area })
2861
+ ] }, hit.key)),
2862
+ hits.length === 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-muted", onClick: () => setOverlay("palette"), children: [
2863
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("No page matches. Search finds records too.") }),
2864
+ /* @__PURE__ */ jsx(Trail, {})
2865
+ ] })
2866
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2867
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: appName }),
2868
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: shell.nav.areas.map((area) => {
2869
+ const Icon = resolveIcon(area.icon, icons);
2870
+ const pages = area.pages ?? [];
2871
+ 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 }) });
2872
+ const lock = areaLocked(area) ? /* @__PURE__ */ jsxs("span", { className: "cbx-nav-lock", title: t("Not in your plan"), children: [
2873
+ /* @__PURE__ */ jsx(Lock, { size: 13, strokeWidth: 1.9, "aria-hidden": true }),
2874
+ /* @__PURE__ */ jsx("span", { className: "cbx-sr-only", children: t("(locked)") })
2875
+ ] }) : null;
2876
+ if (pages.length <= 1) {
2877
+ return /* @__PURE__ */ jsxs(Row, { href: navUrl(area), onClick: () => setOverlay(null), "aria-current": area.key === shell.nav.activeArea ? "page" : void 0, children: [
2878
+ tile,
2879
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: area.label }),
2880
+ lock,
2881
+ /* @__PURE__ */ jsx(Trail, {})
2882
+ ] }, area.key);
2883
+ }
2884
+ return /* @__PURE__ */ jsxs(Row, { onClick: () => onArea(area.key), children: [
2885
+ tile,
2886
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: area.label }),
2887
+ lock,
2888
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: pages.length }),
2889
+ /* @__PURE__ */ jsx(Trail, {})
2890
+ ] }, area.key);
2891
+ }) }),
2892
+ /* @__PURE__ */ jsx(WhereYouWork, { onStep: (step) => openContext(step, true) }),
2893
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: t("Help") }),
2894
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: /* @__PURE__ */ jsxs(Row, { className: "is-tall", onClick: () => toggleHelp(true), "aria-haspopup": "dialog", children: [
2895
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-accent", "aria-hidden": "true", children: /* @__PURE__ */ jsx(CircleHelp, { size: 17, strokeWidth: 1.8 }) }),
2896
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2897
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: t("Help with {page}", { page: topic }) }),
2898
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: t("Articles, Ask Cbox, chat with support") })
2899
+ ] }),
2900
+ unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: unread }) }),
2901
+ /* @__PURE__ */ jsx(Trail, {})
2902
+ ] }) }),
2903
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
2904
+ shell.notifications.enabled && /* @__PURE__ */ jsxs(Row, { href: shell.notifications.url, onClick: () => setOverlay(null), children: [
2905
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Bell, { size: 16, strokeWidth: 1.8 }) }),
2906
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Notifications") }),
2907
+ shell.notifications.unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: shell.notifications.unread }),
2908
+ /* @__PURE__ */ jsx(Trail, {})
2909
+ ] }),
2910
+ /* @__PURE__ */ jsxs(Row, { onClick: () => setOverlay("apps-sheet"), "aria-haspopup": "dialog", children: [
2911
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-primary", "aria-hidden": "true", children: /* @__PURE__ */ jsx(LayoutGrid, { size: 16, strokeWidth: 2 }) }),
2912
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Switch app") }),
2913
+ /* @__PURE__ */ jsx(Trail, {})
2914
+ ] })
2915
+ ] }),
2916
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: /* @__PURE__ */ jsxs(Row, { className: "is-tall", onClick: onAccount, children: [
2917
+ /* @__PURE__ */ jsx(Avatar, { size: 40 }),
2918
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2919
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: shell.person.name }),
2920
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: account.signedInWith !== void 0 ? account.signedInWith : t("Profile, language, theme") })
2921
+ ] }),
2922
+ /* @__PURE__ */ jsx(Trail, {})
2923
+ ] }) })
2924
+ ] })
2925
+ ] });
2926
+ }
2927
+ function WhereYouWork({ onStep }) {
2928
+ const { shell, t } = useShell();
2929
+ const levels = shell.context.levels;
2930
+ const environment = environmentLevel(levels);
2931
+ const parentOfEnvironment = environment !== void 0 ? levels[levels.indexOf(environment) - 1]?.current.id : void 0;
2932
+ const list = useContextList(environment?.listUrl, { parent: parentOfEnvironment, enabled: environment !== void 0 });
2933
+ if (levels.length === 0) return null;
2934
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2935
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: t("Where you work") }),
2936
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: levels.map((level, index) => {
2937
+ const env = level.key === "environment";
2938
+ return /* @__PURE__ */ jsxs(Row, { onClick: () => onStep(env ? "environments" : level.key), "aria-haspopup": "dialog", children: [
2939
+ 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) }),
2940
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2941
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: level.label }),
2942
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: level.current.name })
2943
+ ] }),
2944
+ env && list.status === "ready" && !list.hasMore && /* @__PURE__ */ jsx("span", { className: "cbx-grow-count", children: list.items.length }),
2945
+ /* @__PURE__ */ jsx(Trail, {})
2946
+ ] }, level.key);
2947
+ }) })
2948
+ ] });
2949
+ }
2950
+ function MoreArea({ areaKey, onBack }) {
2951
+ const { shell, t, setOverlay } = useShell();
2952
+ const area = shell.nav.areas.find((item) => item.key === areaKey);
2953
+ if (area === void 0) return null;
2954
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
2955
+ /* @__PURE__ */ jsx(BackBar, { label: t("More"), onBack }),
2956
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: area.label }),
2957
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
2958
+ groupPages(area.pages ?? []).map((run, index) => /* @__PURE__ */ jsxs("section", { role: "group", "aria-label": run.group ?? area.label, children: [
2959
+ run.group !== void 0 && /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", "aria-hidden": "true", children: run.group }),
2960
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: run.pages.map((page) => {
2961
+ const on = area.key === shell.nav.activeArea && page.key === shell.nav.activePage;
2962
+ return /* @__PURE__ */ jsxs(Row, { href: navUrl(page), onClick: () => setOverlay(null), "aria-current": on ? "page" : void 0, className: page.locked === true ? "is-locked" : "", children: [
2963
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: page.label }),
2964
+ /* @__PURE__ */ jsx(NavPageMarks, { page }),
2965
+ /* @__PURE__ */ jsx(Trail, {})
2966
+ ] }, page.key);
2967
+ }) })
2968
+ ] }, index))
2969
+ ] });
2970
+ }
2971
+ var DEFAULT_LANGUAGES2 = [
2972
+ { code: "en", label: "English" },
2973
+ { code: "da", label: "Dansk" }
2974
+ ];
2975
+ var DEFAULT_FORMATS2 = [
2976
+ { code: "en-GB", label: "English (United Kingdom)" },
2977
+ { code: "en-US", label: "English (United States)" },
2978
+ { code: "da-DK", label: "Dansk (Danmark)" },
2979
+ { code: "de-DE", label: "Deutsch (Deutschland)" },
2980
+ { code: "sv-SE", label: "Svenska (Sverige)" },
2981
+ { code: "nb-NO", label: "Norsk bokm\xE5l (Norge)" }
2982
+ ];
2983
+ function zones() {
2984
+ const supported = Intl.supportedValuesOf;
2985
+ const list = typeof supported === "function" ? supported("timeZone") : ["UTC", "Europe/Copenhagen", "Europe/London", "Europe/Berlin", "America/New_York"];
2986
+ return list.map((zone) => ({ code: zone, label: zone.replace(/_/g, " ") }));
2987
+ }
2988
+ function MoreAccount({ onBack, onOption }) {
2989
+ const { shell, t, preferences, setPreference, navigate } = useShell();
2990
+ const account = shell.account ?? {};
2991
+ const languages = account.languages ?? DEFAULT_LANGUAGES2;
2992
+ const formats = account.formats ?? DEFAULT_FORMATS2;
2993
+ const label = (options, code, fallback) => options.find((option) => option.code === code)?.label ?? code ?? fallback;
2994
+ const themes = [
2995
+ { value: "system", label: t("System") },
2996
+ { value: "light", label: t("Light") },
2997
+ { value: "dark", label: t("Dark") }
2998
+ ];
2999
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3000
+ /* @__PURE__ */ jsx(BackBar, { label: t("More"), onBack }),
3001
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: t("Account") }),
3002
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
3003
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3004
+ /* @__PURE__ */ jsxs("div", { className: "cbx-grow is-tall is-static", children: [
3005
+ /* @__PURE__ */ jsx(Avatar, { size: 40 }),
3006
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3007
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: shell.person.name }),
3008
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: account.signedInWith ?? t("Signed in with Cbox ID") })
3009
+ ] })
3010
+ ] }),
3011
+ account.profileUrl !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-grow", href: account.profileUrl, children: [
3012
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Profile and security") }),
3013
+ /* @__PURE__ */ jsx(ArrowUpRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
3014
+ ] })
3015
+ ] }),
3016
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3017
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("locale"), children: [
3018
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Language") }),
3019
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: label(languages, preferences.locale, "English") })
3020
+ ] }),
3021
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("regionalFormat"), children: [
3022
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Regional format") }),
3023
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: label(formats, preferences.regionalFormat, t("Automatic")) })
3024
+ ] }),
3025
+ /* @__PURE__ */ jsxs(Row, { onClick: () => onOption("timeZone"), children: [
3026
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("Time zone") }),
3027
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-value", children: (preferences.timeZone ?? t("Automatic")).replace(/_/g, " ") })
3028
+ ] })
3029
+ ] }),
3030
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", id: "cbx-theme-label", children: t("Theme") }),
3031
+ /* @__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)) }),
3032
+ (account.switchAccountUrl !== void 0 || account.signOutUrl !== void 0) && /* @__PURE__ */ jsxs("div", { className: "cbx-group", children: [
3033
+ 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") }) }),
3034
+ 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") }) })
3035
+ ] })
3036
+ ] });
3037
+ }
3038
+ function MoreOption({ which, onBack }) {
3039
+ const { shell, t, preferences, setPreference } = useShell();
3040
+ const account = shell.account ?? {};
3041
+ const options = which === "locale" ? account.languages ?? DEFAULT_LANGUAGES2 : which === "regionalFormat" ? account.formats ?? DEFAULT_FORMATS2 : zones();
3042
+ const title = which === "locale" ? t("Language") : which === "regionalFormat" ? t("Regional format") : t("Time zone");
3043
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-more-page", children: [
3044
+ /* @__PURE__ */ jsx(BackBar, { label: t("Account"), onBack }),
3045
+ /* @__PURE__ */ jsx("h1", { className: "cbx-m-big", children: title }),
3046
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-gap" }),
3047
+ /* @__PURE__ */ jsx(
3048
+ OptionList,
3049
+ {
3050
+ label: title,
3051
+ options,
3052
+ current: preferences[which],
3053
+ autoFocus: false,
3054
+ onPick: (code) => {
3055
+ setPreference(which, code);
3056
+ onBack();
3057
+ }
3058
+ }
3059
+ )
3060
+ ] });
3061
+ }
3062
+ function useMoreView() {
3063
+ const [view, setView] = useState({ kind: "root" });
3064
+ return [view, setView];
3065
+ }
3066
+ function ContextSheet({ onClose }) {
3067
+ const { shell, t, switchTo, contextStep } = useShell();
3068
+ const [step, setStep] = useState(contextStep.step);
3069
+ const direct = contextStep.direct;
3070
+ const levels = shell.context.levels;
3071
+ const back = () => direct ? onClose() : setStep("root");
3072
+ if (step === "environments") {
3073
+ const environment = environmentLevel(levels);
3074
+ if (environment !== void 0) {
3075
+ const index = levels.indexOf(environment);
3076
+ const parent = levels[index - 1];
3077
+ 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 }) }) });
3078
+ }
3079
+ }
3080
+ const level = levels.find((item) => item.key === step);
3081
+ if (step !== "root" && level !== void 0) {
3082
+ const index = levels.indexOf(level);
3083
+ const parent = index > 0 ? levels[index - 1] : void 0;
3084
+ const inner = levels[index + 1];
3085
+ 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(
3086
+ LevelPane,
3087
+ {
3088
+ level,
3089
+ parent: parent?.current.id,
3090
+ currentId: level.current.id,
3091
+ heading: pluralOf(level),
3092
+ createLabel: t("New {thing}", { thing: level.label.toLowerCase() }),
3093
+ onPick: (item) => index === 0 ? switchTo({ [level.key]: item.id }) : void pickKeepingEnvironment(level, inner, item, switchTo)
3094
+ }
3095
+ ) }) });
3096
+ }
3097
+ return /* @__PURE__ */ jsx(Sheet, { label: t("Where you work"), onClose, children: /* @__PURE__ */ jsx(ContextRoot, { onStep: setStep }) });
3098
+ }
3099
+ function ContextRoot({ onStep }) {
3100
+ const { shell, t, switchTo } = useShell();
3101
+ const levels = shell.context.levels;
3102
+ const environment = environmentLevel(levels);
3103
+ const above = levels.filter((level) => level !== environment);
3104
+ const envIndex = environment !== void 0 ? levels.indexOf(environment) : -1;
3105
+ const parent = envIndex > 0 ? levels[envIndex - 1] : void 0;
3106
+ const list = useContextList(environment?.listUrl, { parent: parent?.current.id, enabled: environment !== void 0 });
3107
+ const picks = environment !== void 0 ? quickEnvironments(list.items, environment.current) : [];
3108
+ const pick = (item) => {
3109
+ if (environment === void 0) return;
3110
+ switchTo(parent !== void 0 ? { [parent.key]: parent.current.id, [environment.key]: item.id } : { [environment.key]: item.id });
3111
+ };
3112
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3113
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: above.map((level, index) => /* @__PURE__ */ jsxs(Row, { onClick: () => onStep(level.key), children: [
3114
+ index === 0 && /* @__PURE__ */ jsx(Chip, { item: level.current, tone: "soft" }),
3115
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3116
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: level.label }),
3117
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: level.current.name })
3118
+ ] }),
3119
+ /* @__PURE__ */ jsx(Trail, {})
3120
+ ] }, level.key)) }),
3121
+ environment !== void 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
3122
+ /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: environment.label }),
3123
+ /* @__PURE__ */ jsxs("div", { className: "cbx-group", role: "group", "aria-label": environment.label, children: [
3124
+ picks.map((item) => {
3125
+ const current = item.id === environment.current.id;
3126
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", "aria-current": current ? "true" : void 0, onClick: () => current ? void 0 : pick(item), children: [
3127
+ /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
3128
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label cbx-grow-strong", children: item.name }),
3129
+ current && /* @__PURE__ */ jsx(Check, { className: "cbx-grow-check", size: 18, strokeWidth: 2, "aria-label": t("Current") })
3130
+ ] }, item.id);
3131
+ }),
3132
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow is-accent", onClick: () => onStep("environments"), children: [
3133
+ /* @__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() }) }),
3134
+ /* @__PURE__ */ jsx(Trail, {})
3135
+ ] })
3136
+ ] })
3137
+ ] })
3138
+ ] });
3139
+ }
3140
+ function EnvironmentList({ level, parent, parentName, onPick }) {
3141
+ const { t } = useShell();
3142
+ const [q, setQ] = useState("");
3143
+ const [creating, setCreating] = useState(false);
3144
+ const list = useContextList(level.listUrl, { q, parent });
3145
+ const plural = pluralOf(level);
3146
+ return /* @__PURE__ */ jsxs("div", { className: "cbx-env-list", children: [
3147
+ /* @__PURE__ */ jsxs("label", { className: "cbx-field-search", children: [
3148
+ /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
3149
+ /* @__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" })
3150
+ ] }),
3151
+ groupItems(list.items).map((run, index) => /* @__PURE__ */ jsxs("section", { "aria-label": run.group ?? plural, children: [
3152
+ run.group !== void 0 && /* @__PURE__ */ jsx("h2", { className: "cbx-eyebrow", children: run.group }),
3153
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: run.items.map((item) => {
3154
+ const current = item.id === level.current.id;
3155
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", "aria-current": current ? "true" : void 0, onClick: () => current ? void 0 : onPick(item), children: [
3156
+ /* @__PURE__ */ jsx(ToneSquare, { tone: item.tone }),
3157
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
3158
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong", children: item.name }),
3159
+ (item.description ?? item.label) !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub", children: item.description ?? item.label })
3160
+ ] }),
3161
+ current && /* @__PURE__ */ jsx(Check, { className: "cbx-grow-check", size: 18, strokeWidth: 2, "aria-label": t("Current") })
3162
+ ] }, item.id);
3163
+ }) })
3164
+ ] }, run.group ?? `run-${index}`)),
3165
+ 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") }) }) }),
3166
+ list.status === "loading" && list.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", "aria-live": "polite", children: t("Loading\u2026") }),
3167
+ list.status === "error" && /* @__PURE__ */ jsxs("p", { className: "cbx-list-note", role: "alert", children: [
3168
+ t("{things} could not be loaded.", { things: plural }),
3169
+ " ",
3170
+ /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: list.retry, children: t("Try again") })
3171
+ ] }),
3172
+ 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() }) }),
3173
+ 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: [
3174
+ /* @__PURE__ */ jsx(Plus, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
3175
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: t("New {thing}", { thing: level.label.toLowerCase() }) })
3176
+ ] }) })
3177
+ ] });
3178
+ }
3179
+ function AppsSheet({ onClose }) {
3180
+ const { t } = useShell();
3181
+ return /* @__PURE__ */ jsx(Sheet, { label: t("Switch app"), onClose, children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false }) });
3182
+ }
2353
3183
  var PlainLink = ({ href, children, ...props }) => /* @__PURE__ */ jsx("a", { href, ...props, children });
2354
3184
  function writeCookie(key, value) {
2355
3185
  if (typeof document === "undefined") return;
@@ -2376,11 +3206,15 @@ function useIsMac() {
2376
3206
  }, []);
2377
3207
  return mac;
2378
3208
  }
2379
- function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent = PlainLink, icons = {}, onPreferenceChange, helpStore, brandAssetBase = "/brand", mainId = "main-content" }) {
3209
+ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent = PlainLink, icons = {}, onPreferenceChange, helpStore, brandAssetBase = "/brand", mainId = "main-content", renderCreate, searchRecords }) {
2380
3210
  const { t } = useCboxLocalization();
2381
3211
  const [store] = useState(() => helpStore ?? sharedHelpStore());
2382
3212
  const [preferences, setPreferences] = useState(shell.preferences);
2383
3213
  const [overlay, setOverlay] = useState(null);
3214
+ const [contextStep, setContextStep] = useState({ step: "root", direct: false });
3215
+ const [createKey, setCreateKey] = useState(null);
3216
+ const mobile = useMedia(MOBILE, false);
3217
+ const [moreView, setMoreView] = useMoreView();
2384
3218
  if (!store.get().seeded) store.set({ open: shell.preferences.helpOpen, restored: shell.preferences.helpOpen, seeded: true });
2385
3219
  const serverPreferences = JSON.stringify(shell.preferences);
2386
3220
  useEffect(() => {
@@ -2407,6 +3241,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2407
3241
  const switchUrl = shell.context.switchUrl;
2408
3242
  const scope = levels.map((level) => `${level.key}:${level.current.id}`).join("|");
2409
3243
  if (scopeLists(scope)) forgetShellCatalog();
3244
+ const canCreate = renderCreate !== void 0 && (shell.create?.items.length ?? 0) > 0;
2410
3245
  const api = useMemo(
2411
3246
  () => ({
2412
3247
  shell,
@@ -2431,9 +3266,28 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2431
3266
  switchTo: (chosen) => {
2432
3267
  setOverlay(null);
2433
3268
  navigate(switchUrl, { method: "post", data: switchBody(levels, chosen, currentLocation()) });
2434
- }
3269
+ },
3270
+ mobile,
3271
+ contextStep,
3272
+ openContext: (step = "root", direct = false) => {
3273
+ if (mobile) {
3274
+ setContextStep({ step, direct, underMore: overlay === "more" });
3275
+ setOverlay("context-sheet");
3276
+ return;
3277
+ }
3278
+ setOverlay(step === "root" || step === levels[0]?.key || levels.length < 2 ? "org" : "context");
3279
+ },
3280
+ createKey,
3281
+ canCreate,
3282
+ openCreate: (key) => {
3283
+ if (!canCreate) return;
3284
+ setCreateKey(key ?? pageCreateKey(shell));
3285
+ setOverlay("create");
3286
+ },
3287
+ renderCreate,
3288
+ searchRecords
2435
3289
  }),
2436
- [shell, t, navigate, LinkComponent, icons, preferences, setPreference, overlay, store, toggleHelp, levels, switchUrl]
3290
+ [shell, t, navigate, LinkComponent, icons, preferences, setPreference, overlay, store, toggleHelp, levels, switchUrl, mobile, contextStep, createKey, canCreate, renderCreate, searchRecords]
2437
3291
  );
2438
3292
  const preferencesRef = useRef(preferences);
2439
3293
  preferencesRef.current = preferences;
@@ -2454,44 +3308,88 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2454
3308
  const page = `${shell.nav.activeArea}|${shell.nav.activePage ?? ""}|${shell.page?.title ?? ""}`;
2455
3309
  useEffect(() => {
2456
3310
  setOverlay((current) => current === "palette" ? current : null);
3311
+ setMoreView({ kind: "root" });
3312
+ if (shell.page?.title !== void 0) {
3313
+ const area = shell.nav.areas.find((item) => item.key === shell.nav.activeArea);
3314
+ rememberPage(shell.app.key, { title: shell.page.title, area: area?.label, url: currentLocation() });
3315
+ }
2457
3316
  }, [page]);
2458
3317
  const docked = useMedia(HELP_DOCKED, true);
2459
- const mobile = useMedia(MOBILE, false);
2460
3318
  const testData = levels.some((level) => level.current.testData === true);
2461
3319
  const helpOpen = useHelpState(store, (state) => helpVisible(state, docked));
2462
- const banners = shellBanners(shell, testData);
3320
+ const notLive = notLiveEnvironment(levels);
3321
+ const banners = shellBanners(shell, testData).filter((banner) => !(mobile && notLive !== null && banner.kind === "sandbox"));
3322
+ const envBanner = !mobile && notLive !== null && !banners.some((banner) => banner.kind === "sandbox") ? notLive : null;
3323
+ const strips = banners.map((banner, index) => /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-${banner.kind}`, role: "status", children: [
3324
+ /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: banner.text }),
3325
+ banner.action !== void 0 && /* @__PURE__ */ jsx(LinkComponent, { href: navUrl(banner.action), className: "cbx-banner-action", children: banner.action.label })
3326
+ ] }, `${banner.kind}-${index}`));
3327
+ const skip = /* @__PURE__ */ jsx(
3328
+ "a",
3329
+ {
3330
+ className: "cbx-skip-link",
3331
+ href: `#${mainId}`,
3332
+ onClick: (event) => {
3333
+ const main = document.getElementById(mainId);
3334
+ if (main === null) return;
3335
+ event.preventDefault();
3336
+ main.focus();
3337
+ main.scrollIntoView?.({ block: "start" });
3338
+ },
3339
+ children: t("Skip to content")
3340
+ }
3341
+ );
3342
+ const overlays = /* @__PURE__ */ jsxs(Fragment, { children: [
3343
+ overlay === "palette" && /* @__PURE__ */ jsx(CommandPalette, { onClose: () => setOverlay(null) }),
3344
+ overlay === "context-sheet" && /* @__PURE__ */ jsx(ContextSheet, { onClose: () => setOverlay(contextStep.underMore === true ? "more" : null) }, `${contextStep.step}:${String(contextStep.direct)}`),
3345
+ overlay === "apps-sheet" && /* @__PURE__ */ jsx(AppsSheet, { onClose: () => setOverlay("more") }),
3346
+ overlay === "create" && /* @__PURE__ */ jsx(CreateSheet, { onClose: () => setOverlay(null) }, createKey ?? "tree")
3347
+ ] });
3348
+ if (mobile) {
3349
+ const moreOpen = overlay === "more" || overlay === "apps-sheet" || overlay === "context-sheet" && contextStep.underMore === true;
3350
+ return /* @__PURE__ */ jsx(ShellContext.Provider, { value: api, children: /* @__PURE__ */ jsxs("div", { className: "cbx-shell is-mobile", "data-help-open": helpOpen, children: [
3351
+ skip,
3352
+ /* @__PURE__ */ jsxs("div", { className: "cbx-shell-column", children: [
3353
+ /* @__PURE__ */ jsxs("header", { className: "cbx-m-chrome", hidden: moreOpen, children: [
3354
+ /* @__PURE__ */ jsx(MobileTopBar, {}),
3355
+ /* @__PURE__ */ jsx(MobileAreaHead, {}),
3356
+ strips
3357
+ ] }),
3358
+ /* @__PURE__ */ jsxs("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children: [
3359
+ moreOpen && /* @__PURE__ */ jsx(MoreScreen, { view: moreView, setView: setMoreView }),
3360
+ /* @__PURE__ */ jsx("div", { className: "cbx-m-page", hidden: moreOpen, children })
3361
+ ] })
3362
+ ] }),
3363
+ /* @__PURE__ */ jsx(
3364
+ TabBar,
3365
+ {
3366
+ onMore: () => {
3367
+ setMoreView({ kind: "root" });
3368
+ setOverlay("more");
3369
+ }
3370
+ }
3371
+ ),
3372
+ /* @__PURE__ */ jsx(HelpColumn, { docked: false, mobile: true }),
3373
+ overlays
3374
+ ] }) });
3375
+ }
2463
3376
  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
- ),
3377
+ skip,
2479
3378
  /* @__PURE__ */ jsx(Rail, { brandAssetBase }),
2480
3379
  /* @__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}`)),
3380
+ /* @__PURE__ */ jsx(Header, {}),
3381
+ envBanner !== null && /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-env cbx-env-${envBanner.tone ?? "neutral"}`, role: "status", children: [
3382
+ /* @__PURE__ */ jsx(ToneSquare, { tone: envBanner.tone }),
3383
+ /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: t("{environment}. Not production, nothing here touches live customers.", { environment: envBanner.name }) })
3384
+ ] }),
3385
+ strips,
2486
3386
  /* @__PURE__ */ jsxs("div", { className: "cbx-shell-body", children: [
2487
3387
  /* @__PURE__ */ jsx(Subnav, {}),
2488
3388
  /* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children })
2489
3389
  ] })
2490
3390
  ] }),
2491
3391
  /* @__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) })
3392
+ overlays
2495
3393
  ] }) });
2496
3394
  }
2497
3395
  function AppMark() {
@@ -2610,7 +3508,7 @@ function Subnav() {
2610
3508
  ) })
2611
3509
  ] });
2612
3510
  }
2613
- function Header({ mobile }) {
3511
+ function Header() {
2614
3512
  const { shell, t, overlay, setOverlay, help, toggleHelp, Link } = useShell();
2615
3513
  const mac = useIsMac();
2616
3514
  const org = useRef(null);
@@ -2618,9 +3516,8 @@ function Header({ mobile }) {
2618
3516
  const apps = useRef(null);
2619
3517
  const docked = useMedia(HELP_DOCKED, true);
2620
3518
  const helpOpen = useHelpState(help, (state) => helpVisible(state, docked));
2621
- const unread = useHelpState(help, (state) => state.updates.filter((update) => update.unread).length);
3519
+ const unread = useUnreadCount(help, shell.help.unread);
2622
3520
  const [organization, ...rest] = shell.context.levels;
2623
- const trail = shell.context.levels.map((level) => level.current.name).join(" / ");
2624
3521
  const close = useCallback(() => setOverlay(null), [setOverlay]);
2625
3522
  const triggerKeyDown = (event, menu) => {
2626
3523
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
@@ -2633,28 +3530,22 @@ function Header({ mobile }) {
2633
3530
  }
2634
3531
  };
2635
3532
  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
3533
  organization !== void 0 && /* @__PURE__ */ jsxs("div", { className: "cbx-context cbx-only-desktop", children: [
2638
3534
  /* @__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
3535
  /* @__PURE__ */ jsx(Chip, { item: organization.current, tone: "solid" }),
2640
3536
  /* @__PURE__ */ jsx("span", { className: "cbx-trigger-text", title: organization.current.name, children: organization.current.name }),
2641
3537
  /* @__PURE__ */ jsx(ChevronsUpDown, { className: "cbx-trigger-chevron", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2642
3538
  ] }),
2643
- !mobile && /* @__PURE__ */ jsx(Popover, { open: overlay === "org", anchor: org, label: organization.label, onClose: close, children: /* @__PURE__ */ jsx(OrganizationMenu, { level: organization }) }),
3539
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "org", anchor: org, label: organization.label, onClose: close, children: /* @__PURE__ */ jsx(OrganizationMenu, { level: organization }) }),
2644
3540
  rest.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
2645
3541
  /* @__PURE__ */ jsx("span", { className: "cbx-separator", "aria-hidden": "true", children: "/" }),
2646
3542
  /* @__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
3543
  /* @__PURE__ */ jsx(CascadeLabel, { levels: rest }),
2648
3544
  /* @__PURE__ */ jsx(ChevronsUpDown, { className: "cbx-trigger-chevron", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2649
3545
  ] }),
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 }) })
3546
+ /* @__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
3547
  ] })
2652
3548
  ] }),
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
3549
  /* @__PURE__ */ jsxs("div", { className: "cbx-tools", children: [
2659
3550
  /* @__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
3551
  /* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
@@ -2671,7 +3562,7 @@ function Header({ mobile }) {
2671
3562
  shell.notifications.unread > 0 && /* @__PURE__ */ jsx("span", { className: "cbx-count", "aria-hidden": "true", children: shell.notifications.unread })
2672
3563
  ] }),
2673
3564
  /* @__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, {}) })
3565
+ /* @__PURE__ */ jsx(Popover, { open: overlay === "apps", anchor: apps, placement: "bottom-end", label: t("Switch app"), onClose: close, children: /* @__PURE__ */ jsx(AppGrid, {}) })
2675
3566
  ] })
2676
3567
  ] });
2677
3568
  }
@@ -3070,7 +3961,7 @@ function ComboboxGroupRows({
3070
3961
  /* @__PURE__ */ jsx("span", { className: "truncate text-[13px] font-medium text-foreground", children: opt.label }),
3071
3962
  opt.secondary !== void 0 ? /* @__PURE__ */ jsx("span", { className: "text-mono truncate text-[10px] text-muted-foreground", children: opt.secondary }) : null
3072
3963
  ] }),
3073
- isActive ? /* @__PURE__ */ jsx(Check3, {}) : null
3964
+ isActive ? /* @__PURE__ */ jsx(Check4, {}) : null
3074
3965
  ] });
3075
3966
  const className = cn(
3076
3967
  "group block w-full rounded-sm transition-colors text-left",
@@ -3139,7 +4030,7 @@ function FooterLink({
3139
4030
  prefetch: true,
3140
4031
  className,
3141
4032
  children: [
3142
- /* @__PURE__ */ jsx(Plus2, {}),
4033
+ /* @__PURE__ */ jsx(Plus5, {}),
3143
4034
  /* @__PURE__ */ jsx("span", { children: label })
3144
4035
  ]
3145
4036
  }
@@ -3152,7 +4043,7 @@ function FooterLink({
3152
4043
  className,
3153
4044
  onClick: onAfterClick,
3154
4045
  children: [
3155
- /* @__PURE__ */ jsx(Plus2, {}),
4046
+ /* @__PURE__ */ jsx(Plus5, {}),
3156
4047
  /* @__PURE__ */ jsx("span", { children: label })
3157
4048
  ]
3158
4049
  }
@@ -3252,7 +4143,7 @@ function Chevron({ open }) {
3252
4143
  }
3253
4144
  );
3254
4145
  }
3255
- function Check3() {
4146
+ function Check4() {
3256
4147
  return /* @__PURE__ */ jsx(
3257
4148
  "svg",
3258
4149
  {
@@ -3270,7 +4161,7 @@ function Check3() {
3270
4161
  }
3271
4162
  );
3272
4163
  }
3273
- function Plus2() {
4164
+ function Plus5() {
3274
4165
  return /* @__PURE__ */ jsx(
3275
4166
  "svg",
3276
4167
  {
@@ -4383,6 +5274,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
4383
5274
  ] });
4384
5275
  }
4385
5276
 
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 };
5277
+ 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, withQuery };
4387
5278
  //# sourceMappingURL=index.js.map
4388
5279
  //# sourceMappingURL=index.js.map