@cboxdk/cbox-ui 0.10.1 → 0.10.3

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
@@ -1,5 +1,5 @@
1
- import { cn } from './chunk-OFTNLF7H.js';
2
- export { cn, niceTicks, timeTicks } from './chunk-OFTNLF7H.js';
1
+ import { cn } from './chunk-QJ4T7RR2.js';
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
5
  import { createContext, useContext, useMemo, useSyncExternalStore, useState, useEffect, useCallback, useRef, createElement, useId, useLayoutEffect, useImperativeHandle } from 'react';
@@ -1803,6 +1803,14 @@ function resolveIcon(name, extra = {}) {
1803
1803
  function navUrl(entry) {
1804
1804
  return entry.url ?? entry.href ?? "#";
1805
1805
  }
1806
+ function areaLocked(area) {
1807
+ const pages = area.pages ?? [];
1808
+ return pages.length > 0 && pages.every((page) => page.locked === true);
1809
+ }
1810
+ function shellBanners(shell, testData) {
1811
+ const all = shell.banners ?? (shell.banner !== void 0 ? [shell.banner] : []);
1812
+ return all.filter((banner) => banner.kind !== "sandbox" || testData);
1813
+ }
1806
1814
  function groupPages(pages) {
1807
1815
  const runs = /* @__PURE__ */ new Map();
1808
1816
  for (const page of pages) {
@@ -1898,7 +1906,11 @@ function NavSheet({ onClose }) {
1898
1906
  return /* @__PURE__ */ jsxs("div", { className: "cbx-sheet-area", children: [
1899
1907
  /* @__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: [
1900
1908
  /* @__PURE__ */ jsx(Icon, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
1901
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: area.label })
1909
+ /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: area.label }),
1910
+ areaLocked(area) && /* @__PURE__ */ jsxs("span", { className: "cbx-nav-lock", title: t("Not in your plan"), children: [
1911
+ /* @__PURE__ */ jsx(Lock, { size: 13, strokeWidth: 1.9, "aria-hidden": true }),
1912
+ /* @__PURE__ */ jsx("span", { className: "cbx-sr-only", children: t("(locked)") })
1913
+ ] })
1902
1914
  ] }),
1903
1915
  (area.pages ?? []).length > 1 && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-pages", children: /* @__PURE__ */ jsx(
1904
1916
  NavPageList,
@@ -2011,6 +2023,7 @@ function CommandPalette({ onClose }) {
2011
2023
  const [input, setInput] = useState("");
2012
2024
  const [query2, setQuery] = useState("");
2013
2025
  const [groups, setGroups] = useState({});
2026
+ const [groupsFor, setGroupsFor] = useState("");
2014
2027
  const [expanded, setExpanded] = useState(null);
2015
2028
  const [activeKey, setActiveKey] = useState(null);
2016
2029
  const field = useRef(null);
@@ -2037,14 +2050,15 @@ function CommandPalette({ onClose }) {
2037
2050
  const q2 = query2.trim();
2038
2051
  const controller = new AbortController();
2039
2052
  const run = (key, load) => {
2040
- setGroups((current) => ({ ...current, [key]: { status: "loading", items: current[key]?.items ?? [] } }));
2053
+ setGroups((current2) => ({ ...current2, [key]: { status: "loading", items: current2[key]?.items ?? [] } }));
2041
2054
  load().then((items) => {
2042
- if (!controller.signal.aborted) setGroups((current) => ({ ...current, [key]: { status: "ready", items } }));
2055
+ if (!controller.signal.aborted) setGroups((current2) => ({ ...current2, [key]: { status: "ready", items } }));
2043
2056
  }).catch(() => {
2044
- if (!controller.signal.aborted) setGroups((current) => ({ ...current, [key]: { status: "error", items: [] } }));
2057
+ if (!controller.signal.aborted) setGroups((current2) => ({ ...current2, [key]: { status: "error", items: [] } }));
2045
2058
  });
2046
2059
  };
2047
2060
  const signal = controller.signal;
2061
+ setGroupsFor(q2);
2048
2062
  if (q2 === "") {
2049
2063
  setGroups({});
2050
2064
  return () => controller.abort();
@@ -2181,8 +2195,14 @@ function CommandPalette({ onClose }) {
2181
2195
  return { ...section, start, count: items.length + (more ? 1 : 0) };
2182
2196
  });
2183
2197
  const keyOf = (option) => option.kind === "item" ? `${option.group}:${option.item.id}` : `all:${option.group}`;
2184
- const found = activeKey === null ? -1 : options.findIndex((option) => keyOf(option) === activeKey);
2185
- const active = found >= 0 ? found : 0;
2198
+ const debounced = q === query2.trim() && groupsFor === q;
2199
+ const current = (group) => group === "pages" || group === "actions" || debounced && sections.find((section) => section.key === group)?.state.status === "ready";
2200
+ const busy = !debounced || sections.some((section) => section.state.status === "loading");
2201
+ const firstResult = options.find((option) => option.group !== "ask" && current(option.group));
2202
+ const autoKey = firstResult !== void 0 ? keyOf(firstResult) : !busy && options[0] !== void 0 ? keyOf(options[0]) : null;
2203
+ const indexOf = (key) => key === null ? -1 : options.findIndex((option) => keyOf(option) === key);
2204
+ const found = indexOf(activeKey);
2205
+ const active = found >= 0 ? found : indexOf(autoKey);
2186
2206
  const setActive = (next) => {
2187
2207
  const index = typeof next === "function" ? next(active) : next;
2188
2208
  const option = options[index];
@@ -2191,10 +2211,9 @@ function CommandPalette({ onClose }) {
2191
2211
  useEffect(() => {
2192
2212
  setActiveKey(null);
2193
2213
  }, [q]);
2194
- const firstKey = options[0] === void 0 ? null : keyOf(options[0]);
2195
2214
  useEffect(() => {
2196
- if (activeKey === null && firstKey !== null) setActiveKey(firstKey);
2197
- }, [activeKey, firstKey]);
2215
+ if (activeKey === null && autoKey !== null) setActiveKey(autoKey);
2216
+ }, [activeKey, autoKey]);
2198
2217
  useEffect(() => {
2199
2218
  revealInList(`${id}-${active}`);
2200
2219
  }, [active, id]);
@@ -2420,7 +2439,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2420
2439
  const mobile = useMedia(MOBILE, false);
2421
2440
  const testData = levels.some((level) => level.current.testData === true);
2422
2441
  const helpOpen = useHelpState(store, (state) => helpVisible(state, docked));
2423
- const banner = shell.banner !== void 0 && (shell.banner.kind !== "sandbox" || testData) ? shell.banner : void 0;
2442
+ const banners = shellBanners(shell, testData);
2424
2443
  return /* @__PURE__ */ jsx(ShellContext.Provider, { value: api, children: /* @__PURE__ */ jsxs("div", { className: "cbx-shell", "data-help-open": helpOpen, children: [
2425
2444
  /* @__PURE__ */ jsx(
2426
2445
  "a",
@@ -2440,10 +2459,10 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
2440
2459
  /* @__PURE__ */ jsx(Rail, { brandAssetBase }),
2441
2460
  /* @__PURE__ */ jsxs("div", { className: "cbx-shell-column", children: [
2442
2461
  /* @__PURE__ */ jsx(Header, { mobile }),
2443
- banner !== void 0 && /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-${banner.kind}`, role: "status", children: [
2462
+ banners.map((banner, index) => /* @__PURE__ */ jsxs("div", { className: `cbx-banner cbx-banner-${banner.kind}`, role: "status", children: [
2444
2463
  /* @__PURE__ */ jsx("span", { className: "cbx-banner-text", children: banner.text }),
2445
2464
  banner.action !== void 0 && /* @__PURE__ */ jsx(LinkComponent, { href: navUrl(banner.action), className: "cbx-banner-action", children: banner.action.label })
2446
- ] }),
2465
+ ] }, `${banner.kind}-${index}`)),
2447
2466
  /* @__PURE__ */ jsxs("div", { className: "cbx-shell-body", children: [
2448
2467
  /* @__PURE__ */ jsx(Subnav, {}),
2449
2468
  /* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children })
@@ -2503,9 +2522,15 @@ function Rail({ brandAssetBase }) {
2503
2522
  /* @__PURE__ */ jsx("nav", { className: "cbx-rail-nav", "aria-label": name, children: shell.nav.areas.map((area) => {
2504
2523
  const Icon = resolveIcon(area.icon, icons);
2505
2524
  const active = area.key === shell.nav.activeArea;
2506
- return /* @__PURE__ */ jsxs(Link, { href: navUrl(area), className: `cbx-rail-link ${active ? "is-active" : ""}`, "aria-current": active ? "page" : void 0, title: open ? void 0 : area.label, "aria-label": area.label, children: [
2507
- /* @__PURE__ */ jsx(Icon, { size: 18, strokeWidth: 1.7, "aria-hidden": true }),
2508
- /* @__PURE__ */ jsx("span", { className: "cbx-rail-label", children: area.label })
2525
+ const locked = areaLocked(area);
2526
+ const label = locked ? t("{area} (locked)", { area: area.label }) : area.label;
2527
+ return /* @__PURE__ */ jsxs(Link, { href: navUrl(area), className: `cbx-rail-link ${active ? "is-active" : ""} ${locked ? "is-locked" : ""}`, "aria-current": active ? "page" : void 0, title: open ? void 0 : label, "aria-label": label, "data-locked": locked ? "true" : void 0, children: [
2528
+ /* @__PURE__ */ jsxs("span", { className: "cbx-rail-icon", children: [
2529
+ /* @__PURE__ */ jsx(Icon, { size: 18, strokeWidth: 1.7, "aria-hidden": true }),
2530
+ locked && /* @__PURE__ */ jsx("span", { className: "cbx-rail-lock", "aria-hidden": "true", children: /* @__PURE__ */ jsx(Lock, { size: 9, strokeWidth: 2.4 }) })
2531
+ ] }),
2532
+ /* @__PURE__ */ jsx("span", { className: "cbx-rail-label", children: area.label }),
2533
+ locked && /* @__PURE__ */ jsx(Lock, { className: "cbx-rail-lock-open", size: 13, strokeWidth: 1.9, "aria-hidden": true })
2509
2534
  ] }, area.key);
2510
2535
  }) }),
2511
2536
  /* @__PURE__ */ jsx("div", { className: "cbx-rail-foot", children: /* @__PURE__ */ jsxs(