@cboxdk/cbox-ui 0.14.1 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { defineCboxAppSwitcher, subscribeKnownAppCatalog, readKnownAppCatalog, s
4
4
  export { authorizeHref, parseAppCatalog, readKnownAppCatalog, rememberAppCatalog, secureIconUrl, signInTarget } from './chunk-AJCYF7SS.js';
5
5
  import { createContext, forwardRef, Children, isValidElement, cloneElement, useContext, useMemo, useSyncExternalStore, useState, useId, useRef, useCallback, useEffect, createElement, useLayoutEffect, useImperativeHandle } from 'react';
6
6
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
7
- 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';
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, CircleAlert, ChevronRight, Ticket, ArrowUpRight, UserRound, ChevronLeft, X, ArrowLeft, Circle, Monitor, Sun, Moon, LogOut, Check, ArrowUp } from 'lucide-react';
8
8
  import { createPortal } from 'react-dom';
9
9
 
10
10
  var CboxIdContext = createContext(null);
@@ -1442,8 +1442,9 @@ function lockScroll() {
1442
1442
  body: { overflow: body.style.overflow, paddingRight: body.style.paddingRight },
1443
1443
  regions: scrollRegions().map((element) => ({ element, overflow: element.style.overflow, top: element.scrollTop }))
1444
1444
  };
1445
+ const bodyScrolls = getComputedStyle(html).overflowY !== "visible" && ["auto", "scroll"].includes(getComputedStyle(body).overflowY);
1445
1446
  html.style.overflow = "hidden";
1446
- body.style.overflow = "hidden";
1447
+ if (bodyScrolls) body.style.overflow = "hidden";
1447
1448
  if (gutter > 0) body.style.paddingRight = `calc(${getComputedStyle(body).paddingRight} + ${gutter}px)`;
1448
1449
  for (const region of saved.regions) region.element.style.overflow = "hidden";
1449
1450
  html.setAttribute("data-cbx-scroll-locked", "");
@@ -1743,10 +1744,10 @@ function Spinner({ className, label }) {
1743
1744
  function buttonClassName({ variant = "ghost", size = "md" } = {}) {
1744
1745
  return cn("cbx-ui-btn", `cbx-ui-btn--${variant}`, size !== "md" && `cbx-ui-btn--${size}`);
1745
1746
  }
1746
- var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading = false, asChild = false, disabled, className, children, type, ...props }, ref) {
1747
+ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon, loading: loading2 = false, asChild = false, disabled, className, children, type, ...props }, ref) {
1747
1748
  const classes = cn(buttonClassName({ variant, size }), className);
1748
- const glyph = loading ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
1749
- const inactive = (disabled ?? false) || loading;
1749
+ const glyph = loading2 ? /* @__PURE__ */ jsx(Spinner, {}) : icon !== void 0 && icon !== null ? /* @__PURE__ */ jsx("span", { className: "cbx-ui-btn-glyph", "aria-hidden": "true", children: icon }) : null;
1750
+ const inactive = (disabled ?? false) || loading2;
1750
1751
  if (asChild) {
1751
1752
  const child = Children.only(children);
1752
1753
  if (!isValidElement(child)) return null;
@@ -1755,7 +1756,7 @@ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon,
1755
1756
  ...props,
1756
1757
  ref,
1757
1758
  className: cn(classes, own.className),
1758
- "aria-busy": loading || void 0,
1759
+ "aria-busy": loading2 || void 0,
1759
1760
  "aria-disabled": inactive || void 0,
1760
1761
  // A disabled link keeps its focus (so it can be reached and explained) but goes nowhere.
1761
1762
  onClick: (event) => {
@@ -1779,7 +1780,7 @@ var Button = forwardRef(function Button2({ variant = "ghost", size = "md", icon,
1779
1780
  type: type ?? "button",
1780
1781
  className: classes,
1781
1782
  disabled: inactive,
1782
- "aria-busy": loading || void 0,
1783
+ "aria-busy": loading2 || void 0,
1783
1784
  ...props,
1784
1785
  children: [
1785
1786
  glyph,
@@ -2032,6 +2033,157 @@ function resolveIcon(name, extra = {}) {
2032
2033
  return extra[name] ?? SHELL_ICONS[name] ?? Circle;
2033
2034
  }
2034
2035
 
2036
+ // src/shell/help-api.ts
2037
+ var SESSION_FIELD = { search: "searchUrl", articles: "articlesUrl", article: "articleUrl", updates: "updatesUrl" };
2038
+ var EXPIRY_MARGIN_MS = 15e3;
2039
+ function ownUrl(help, endpoint) {
2040
+ if (endpoint === "search") return help.searchUrl;
2041
+ if (endpoint === "articles") return help.articlesUrl;
2042
+ if (endpoint === "updates") return help.updatesUrl;
2043
+ return void 0;
2044
+ }
2045
+ function helpSessionKey(shell) {
2046
+ const { help } = shell;
2047
+ if (!help.enabled || help.sessionUrl === void 0) return null;
2048
+ return `${help.sessionUrl}|${shell.context.levels[0]?.current.id ?? ""}`;
2049
+ }
2050
+ function endpointUrl(value) {
2051
+ if (typeof value !== "string" || value === "") return void 0;
2052
+ try {
2053
+ const url = new URL(value, typeof window === "undefined" ? "https://localhost" : window.location.href);
2054
+ const local = url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
2055
+ return url.protocol === "https:" || local ? value : void 0;
2056
+ } catch {
2057
+ return void 0;
2058
+ }
2059
+ }
2060
+ function parseSession(key, body) {
2061
+ const row = typeof body === "object" && body !== null ? body : {};
2062
+ const session = { key, status: "ready" };
2063
+ if (typeof row.identity !== "string" || row.identity === "") return session;
2064
+ session.identity = row.identity;
2065
+ session.expiresAt = typeof row.expires_at === "number" ? row.expires_at * 1e3 : Date.now() + 12e4;
2066
+ const fields = { searchUrl: row.search_url, articlesUrl: row.topics_url, articleUrl: row.article_url, updatesUrl: row.updates_url };
2067
+ for (const [field, value] of Object.entries(fields)) {
2068
+ const url = endpointUrl(value);
2069
+ if (url !== void 0) session[field] = url;
2070
+ }
2071
+ return session;
2072
+ }
2073
+ var loading = /* @__PURE__ */ new WeakMap();
2074
+ function fresh(session, key) {
2075
+ return session !== null && session.key === key && session.status === "ready" && (session.expiresAt === void 0 || session.expiresAt - EXPIRY_MARGIN_MS > Date.now());
2076
+ }
2077
+ function loadHelpSession(store, help, key, force = false) {
2078
+ const current = store.get().session;
2079
+ if (!force && fresh(current, key)) return Promise.resolve(current);
2080
+ const pending = loading.get(store);
2081
+ if (pending !== void 0 && pending.key === key) return pending.promise;
2082
+ if (current === null || current.key !== key) store.set({ session: { key, status: "loading" } });
2083
+ const promise = requestJson(help.sessionUrl).then((body) => parseSession(key, body)).catch(() => ({ key, status: "ready" })).then((session) => {
2084
+ if (loading.get(store)?.promise === promise) loading.delete(store);
2085
+ const latest = store.get().session;
2086
+ if (latest === null || latest.key === key) store.set({ session });
2087
+ return session;
2088
+ });
2089
+ loading.set(store, { key, promise });
2090
+ return promise;
2091
+ }
2092
+ function helpEndpointState(help, session, key, endpoint) {
2093
+ if (!help.enabled) return "none";
2094
+ if (ownUrl(help, endpoint) !== void 0) return "ready";
2095
+ if (key === null) return "none";
2096
+ if (session === null || session.key !== key || session.status === "loading") return "pending";
2097
+ return session[SESSION_FIELD[endpoint]] !== void 0 ? "ready" : "none";
2098
+ }
2099
+ var HelpUnavailableError = class extends Error {
2100
+ constructor(endpoint) {
2101
+ super(`Help has no ${endpoint} endpoint here`);
2102
+ }
2103
+ };
2104
+ async function bearerJson(url, identity, init) {
2105
+ const response = await fetch(url, { method: init.method ?? "GET", credentials: "omit", headers: { Accept: "application/json", Authorization: `Bearer ${identity}` }, signal: init.signal });
2106
+ const text = await response.text();
2107
+ let body = null;
2108
+ try {
2109
+ body = text === "" ? null : JSON.parse(text);
2110
+ } catch {
2111
+ body = null;
2112
+ }
2113
+ if (!response.ok) throw new ShellRequestError(response.status, body);
2114
+ return body;
2115
+ }
2116
+ async function helpRequest(store, shell, endpoint, build, init = {}) {
2117
+ const { help } = shell;
2118
+ const own = help.enabled ? ownUrl(help, endpoint) : void 0;
2119
+ if (own !== void 0) return requestJson(build(own), init);
2120
+ const key = helpSessionKey(shell);
2121
+ if (key === null) throw new HelpUnavailableError(endpoint);
2122
+ const call = async (force) => {
2123
+ const session = await loadHelpSession(store, help, key, force);
2124
+ const url = session[SESSION_FIELD[endpoint]];
2125
+ if (url === void 0 || session.identity === void 0) throw new HelpUnavailableError(endpoint);
2126
+ return bearerJson(build(url), session.identity, init);
2127
+ };
2128
+ try {
2129
+ return await call(false);
2130
+ } catch (error) {
2131
+ if (error instanceof ShellRequestError && error.status === 401) return call(true);
2132
+ throw error;
2133
+ }
2134
+ }
2135
+ var BLOCKS = { h1: "h4", h2: "h4", h3: "h4", h4: "h5", h5: "h6", h6: "h6" };
2136
+ var KEPT = /* @__PURE__ */ new Set(["p", "br", "hr", "ul", "ol", "li", "strong", "b", "em", "i", "code", "pre", "blockquote", "kbd", "table", "thead", "tbody", "tr", "th", "td", "a", "img", "h4", "h5", "h6"]);
2137
+ var DROPPED = /* @__PURE__ */ new Set(["script", "style", "iframe", "object", "embed", "template", "noscript", "svg", "math", "form", "link", "meta", "base", "head", "title"]);
2138
+ function cleanArticleHtml(html) {
2139
+ if (typeof DOMParser === "undefined") return "";
2140
+ const source = new DOMParser().parseFromString(html, "text/html");
2141
+ const out = source.implementation.createHTMLDocument("");
2142
+ const copy = (from, into) => {
2143
+ for (const node of Array.from(from.childNodes)) {
2144
+ if (node.nodeType === 3) {
2145
+ into.appendChild(out.createTextNode(node.textContent ?? ""));
2146
+ continue;
2147
+ }
2148
+ if (node.nodeType !== 1) continue;
2149
+ const element = node;
2150
+ const name = element.tagName.toLowerCase();
2151
+ if (DROPPED.has(name)) continue;
2152
+ const tag = BLOCKS[name] ?? name;
2153
+ if (!KEPT.has(tag)) {
2154
+ copy(element, into);
2155
+ continue;
2156
+ }
2157
+ const made = out.createElement(tag);
2158
+ if (tag === "a") {
2159
+ const href = element.getAttribute("href")?.trim() ?? "";
2160
+ if (!/^(https?:\/\/|\/(?!\/)|#)/i.test(href)) {
2161
+ copy(element, into);
2162
+ continue;
2163
+ }
2164
+ made.setAttribute("href", href);
2165
+ if (/^https?:/i.test(href)) {
2166
+ made.setAttribute("target", "_blank");
2167
+ made.setAttribute("rel", "noopener noreferrer");
2168
+ }
2169
+ }
2170
+ if (tag === "img") {
2171
+ const src = element.getAttribute("src")?.trim() ?? "";
2172
+ if (!/^https:\/\//i.test(src)) continue;
2173
+ made.setAttribute("src", src);
2174
+ made.setAttribute("alt", element.getAttribute("alt") ?? "");
2175
+ made.setAttribute("loading", "lazy");
2176
+ made.setAttribute("referrerpolicy", "no-referrer");
2177
+ }
2178
+ if ((tag === "td" || tag === "th") && /^[1-9]\d?$/.test(element.getAttribute("colspan") ?? "")) made.setAttribute("colspan", element.getAttribute("colspan"));
2179
+ copy(element, made);
2180
+ into.appendChild(made);
2181
+ }
2182
+ };
2183
+ copy(source.body, out.body);
2184
+ return out.body.innerHTML;
2185
+ }
2186
+
2035
2187
  // src/shell/help-store.ts
2036
2188
  var INITIAL_HELP_STATE = {
2037
2189
  open: false,
@@ -2041,6 +2193,8 @@ var INITIAL_HELP_STATE = {
2041
2193
  updates: [],
2042
2194
  updatesStatus: "idle",
2043
2195
  pendingQuestion: null,
2196
+ chat: false,
2197
+ session: null,
2044
2198
  seeded: false,
2045
2199
  restored: false,
2046
2200
  updatesKey: null
@@ -2090,20 +2244,35 @@ function parseUpdates(body) {
2090
2244
  return [update];
2091
2245
  });
2092
2246
  }
2247
+ function parseArticle(value, source) {
2248
+ if (typeof value !== "object" || value === null) return null;
2249
+ const row = value;
2250
+ if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return null;
2251
+ const article = { id: String(row.id), title: row.title };
2252
+ if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
2253
+ if (typeof row.body === "string") article.body = row.body;
2254
+ if (typeof row.body_html === "string") article.bodyHtml = row.body_html;
2255
+ const url = safeUrl(row.url);
2256
+ if (url !== void 0) article.url = url;
2257
+ if (typeof row.source === "string") article.source = row.source;
2258
+ else if (source !== void 0) article.source = source;
2259
+ return article;
2260
+ }
2093
2261
  function parseArticles(body) {
2094
- const rows2 = Array.isArray(body) ? body : typeof body === "object" && body !== null && Array.isArray(body.data) ? body.data : [];
2095
- return rows2.flatMap((value) => {
2096
- if (typeof value !== "object" || value === null) return [];
2097
- const row = value;
2098
- if (typeof row.id !== "string" && typeof row.id !== "number" || typeof row.title !== "string") return [];
2099
- const article = { id: String(row.id), title: row.title };
2100
- if (typeof row.excerpt === "string") article.excerpt = row.excerpt;
2101
- if (typeof row.body === "string") article.body = row.body;
2102
- const url = safeUrl(row.url);
2103
- if (url !== void 0) article.url = url;
2104
- if (typeof row.source === "string") article.source = row.source;
2105
- return [article];
2106
- });
2262
+ const answer = typeof body === "object" && body !== null ? body : {};
2263
+ if (!Array.isArray(body) && !Array.isArray(answer.data) && Array.isArray(answer.groups)) {
2264
+ return answer.groups.flatMap((group) => {
2265
+ const rows3 = typeof group === "object" && group !== null ? group : {};
2266
+ const source = typeof rows3.source === "string" ? rows3.source : void 0;
2267
+ return (Array.isArray(rows3.data) ? rows3.data : []).flatMap((row) => parseArticle(row, source) ?? []);
2268
+ });
2269
+ }
2270
+ const rows2 = Array.isArray(body) ? body : Array.isArray(answer.data) ? answer.data : [];
2271
+ return rows2.flatMap((row) => parseArticle(row) ?? []);
2272
+ }
2273
+ function parseArticleBody(body) {
2274
+ const answer = typeof body === "object" && body !== null ? body : null;
2275
+ return parseArticle(answer !== null && typeof answer.data === "object" && answer.data !== null && !Array.isArray(answer.data) ? answer.data : body);
2107
2276
  }
2108
2277
  var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
2109
2278
  var SUPPORT_TAG = "cbox-support";
@@ -2128,6 +2297,15 @@ function pageIntent(shell) {
2128
2297
  if (typeof window !== "undefined") intent.url = window.location.pathname;
2129
2298
  return intent;
2130
2299
  }
2300
+ function ownPath(url) {
2301
+ if (typeof url !== "string" || typeof window === "undefined") return null;
2302
+ try {
2303
+ const target = new URL(url, window.location.href);
2304
+ return target.origin === window.location.origin ? target.pathname + target.search + target.hash : null;
2305
+ } catch {
2306
+ return null;
2307
+ }
2308
+ }
2131
2309
  function ensureScript(src) {
2132
2310
  if (typeof document === "undefined" || customElements.get(SUPPORT_TAG) !== void 0) return;
2133
2311
  if (Array.from(document.scripts).some((script2) => script2.getAttribute("src") === src)) return;
@@ -2164,34 +2342,45 @@ function HelpColumn({ docked, mobile = false }) {
2164
2342
  const updates = useHelpState(store, (state) => state.updates);
2165
2343
  const updatesStatus = useHelpState(store, (state) => state.updatesStatus);
2166
2344
  const pendingQuestion = useHelpState(store, (state) => state.pendingQuestion);
2345
+ const chat = useHelpState(store, (state) => state.chat);
2346
+ const session = useHelpState(store, (state) => state.session);
2347
+ const [loadedArticle, setLoadedArticle] = useState(null);
2167
2348
  const [articles, setArticles] = useState({ topic: void 0, items: [], status: "loading" });
2168
2349
  const [results, setResults] = useState(null);
2169
- const [question, setQuestion] = useState("");
2170
2350
  const [chatProblem, setChatProblem] = useState(false);
2171
- const [asked, setAsked] = useState(false);
2172
2351
  const [followUp, setFollowUp] = useState("");
2173
2352
  const column = useRef(null);
2174
2353
  const body = useRef(null);
2175
2354
  const chatHost = useRef(null);
2176
- const searchField = useRef(null);
2355
+ const askField = useRef(null);
2177
2356
  const opener = useRef(null);
2178
2357
  const scrim = useRef(null);
2179
2358
  const { help } = shell;
2359
+ const latest = useRef({ shell, navigate, toggleHelp, docked });
2360
+ latest.current = { shell, navigate, toggleHelp, docked };
2361
+ const sessionKey = helpSessionKey(shell);
2362
+ const canSearch = helpEndpointState(help, session, sessionKey, "search") !== "none";
2363
+ const canLoadArticles = helpEndpointState(help, session, sessionKey, "articles") !== "none";
2364
+ const hasUpdates = helpEndpointState(help, session, sessionKey, "updates") !== "none";
2365
+ const sentArticles = (help.articles ?? []).slice(0, 4);
2366
+ const view = article !== null ? "article" : chat ? "chat" : "home";
2367
+ const [chatKnown, setChatKnown] = useState(false);
2368
+ useEffect(() => setChatKnown(knowsChat(sessionKey)), [sessionKey]);
2180
2369
  useScrollLock(mobile && open);
2181
2370
  const closeSheet = useCallback(() => toggleHelp(false), [toggleHelp]);
2182
2371
  useSheetDrag({ panel: column, scrim, size: "tall", onClose: closeSheet, enabled: mobile && open });
2183
2372
  const portal = help.portalUrl;
2184
- const updatesKey = help.enabled && help.updatesUrl !== void 0 ? `${help.updatesUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
2373
+ const updatesKey = hasUpdates ? `${help.updatesUrl ?? help.sessionUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
2185
2374
  const loadUpdates = useCallback(() => {
2186
- if (updatesKey === null || help.updatesUrl === void 0) return;
2375
+ if (updatesKey === null) return;
2187
2376
  const current = () => store.get().updatesKey === updatesKey;
2188
2377
  store.set({ updatesStatus: "loading", updatesKey });
2189
- requestJson(help.updatesUrl).then((answer) => {
2378
+ helpRequest(store, latest.current.shell, "updates", (url) => url).then((answer) => {
2190
2379
  if (current()) store.set({ updates: parseUpdates(answer), updatesStatus: "ready" });
2191
- }).catch(() => {
2192
- if (current()) store.set({ updatesStatus: "unavailable" });
2380
+ }).catch((error) => {
2381
+ if (current()) store.set(error instanceof HelpUnavailableError ? { updates: [], updatesStatus: "ready" } : { updatesStatus: "unavailable" });
2193
2382
  });
2194
- }, [updatesKey, help.updatesUrl, store]);
2383
+ }, [updatesKey, store]);
2195
2384
  useEffect(() => {
2196
2385
  const state = store.get();
2197
2386
  if (state.updatesKey !== updatesKey) {
@@ -2203,33 +2392,53 @@ function HelpColumn({ docked, mobile = false }) {
2203
2392
  if (open && store.get().updatesStatus !== "loading") loadUpdates();
2204
2393
  }, [open]);
2205
2394
  useEffect(() => {
2206
- if (!open || !help.enabled || help.articlesUrl === void 0 || help.topic === void 0) return;
2207
- if (articles.topic === help.topic && articles.status === "ready") return;
2395
+ const topic2 = help.topic;
2396
+ if (!open || !canLoadArticles || topic2 === void 0 || help.articlesUrl === void 0 && sentArticles.length > 0) return;
2397
+ if (articles.topic === topic2 && articles.status === "ready") return;
2208
2398
  const controller = new AbortController();
2209
- setArticles({ topic: help.topic, items: [], status: "loading" });
2210
- 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) => {
2211
- if (error?.name !== "AbortError") setArticles({ topic: help.topic, items: [], status: "unavailable" });
2399
+ setArticles({ topic: topic2, items: [], status: "loading" });
2400
+ helpRequest(store, latest.current.shell, "articles", (url) => url.split("{topic}").join(encodeURIComponent(topic2)), { signal: controller.signal }).then((answer) => setArticles({ topic: topic2, items: parseArticles(answer).slice(0, 4), status: "ready" })).catch((error) => {
2401
+ if (error?.name === "AbortError") return;
2402
+ setArticles({ topic: topic2, items: [], status: error instanceof HelpUnavailableError ? "ready" : "unavailable" });
2212
2403
  });
2213
2404
  return () => controller.abort();
2214
- }, [open, help.enabled, help.articlesUrl, help.topic]);
2405
+ }, [open, canLoadArticles, help.articlesUrl, help.topic, sessionKey]);
2215
2406
  useEffect(() => {
2216
2407
  const q = query2.trim();
2217
- if (!help.enabled || help.searchUrl === void 0 || q === "") {
2408
+ if (!canSearch || q === "") {
2218
2409
  setResults(null);
2219
2410
  return;
2220
2411
  }
2221
2412
  const controller = new AbortController();
2222
2413
  const timer = setTimeout(() => {
2223
2414
  setResults((current) => ({ q, items: current?.items ?? [], status: "loading" }));
2224
- requestJson(withQuery(help.searchUrl, { q, topic: help.topic }), { signal: controller.signal }).then((answer) => setResults({ q, items: parseArticles(answer), status: "ready" })).catch((error) => {
2225
- if (error?.name !== "AbortError") setResults({ q, items: [], status: "unavailable" });
2415
+ helpRequest(store, latest.current.shell, "search", (url) => withQuery(url, { q, topic: help.topic }), { signal: controller.signal }).then((answer) => setResults({ q, items: parseArticles(answer), status: "ready" })).catch((error) => {
2416
+ if (error?.name === "AbortError") return;
2417
+ setResults(error instanceof HelpUnavailableError ? null : { q, items: [], status: "unavailable" });
2226
2418
  });
2227
2419
  }, DEBOUNCE_MS);
2228
2420
  return () => {
2229
2421
  clearTimeout(timer);
2230
2422
  controller.abort();
2231
2423
  };
2232
- }, [query2, help.enabled, help.searchUrl, help.topic]);
2424
+ }, [query2, canSearch, help.searchUrl, help.topic, sessionKey, store]);
2425
+ const needsSession = help.enabled && sessionKey !== null && (help.searchUrl === void 0 || help.updatesUrl === void 0 || help.articlesUrl === void 0 && sentArticles.length === 0);
2426
+ useEffect(() => {
2427
+ if (open && needsSession && sessionKey !== null) void loadHelpSession(store, latest.current.shell.help, sessionKey);
2428
+ }, [open, needsSession, sessionKey, store]);
2429
+ const articleId = article?.id;
2430
+ const articleHasBody = article !== null && (article.body !== void 0 || article.bodyHtml !== void 0);
2431
+ useEffect(() => {
2432
+ if (articleId === void 0 || articleHasBody) return;
2433
+ const page = latest.current.shell;
2434
+ if (helpEndpointState(page.help, store.get().session, helpSessionKey(page), "article") === "none") return;
2435
+ const controller = new AbortController();
2436
+ setLoadedArticle({ id: articleId, html: null, status: "loading" });
2437
+ helpRequest(store, page, "article", (url) => url.split("{id}").join(encodeURIComponent(articleId)), { signal: controller.signal }).then((answer) => setLoadedArticle({ id: articleId, html: parseArticleBody(answer)?.bodyHtml ?? null, status: "ready" })).catch((error) => {
2438
+ if (error?.name !== "AbortError") setLoadedArticle({ id: articleId, html: null, status: "ready" });
2439
+ });
2440
+ return () => controller.abort();
2441
+ }, [articleId, articleHasBody, sessionKey, store]);
2233
2442
  useEffect(() => {
2234
2443
  if (open && help.enabled && help.sessionUrl !== void 0) ensureScript(help.scriptUrl ?? DEFAULT_SUPPORT_SCRIPT);
2235
2444
  }, [open, help.enabled, help.sessionUrl, help.scriptUrl]);
@@ -2244,30 +2453,82 @@ function HelpColumn({ docked, mobile = false }) {
2244
2453
  setChatProblem(false);
2245
2454
  if (help.sessionUrl === void 0) {
2246
2455
  setChatProblem(true);
2247
- return;
2456
+ return false;
2248
2457
  }
2249
2458
  ensureScript(help.scriptUrl ?? DEFAULT_SUPPORT_SCRIPT);
2250
2459
  const element = await whenSupportReady(chatHost.current);
2251
2460
  if (element === null) {
2252
2461
  setChatProblem(true);
2253
- return;
2462
+ return false;
2463
+ }
2464
+ const intent2 = JSON.parse(intentJson);
2465
+ element.intent = intent2;
2466
+ let opened;
2467
+ let handed = false;
2468
+ if (handover && typeof element.handover === "function") {
2469
+ opened = element.handover();
2470
+ handed = true;
2471
+ } else if (ask !== void 0 && ask !== "" && typeof element.ask === "function") {
2472
+ opened = element.ask(ask, intent2);
2473
+ handed = true;
2474
+ } else opened = element.open?.();
2475
+ if (await opened === false) {
2476
+ setChatProblem(true);
2477
+ return false;
2254
2478
  }
2255
- element.intent = JSON.parse(intentJson);
2256
- if (handover && typeof element.handover === "function") void element.handover();
2257
- else if (ask !== void 0 && ask !== "" && typeof element.ask === "function") void element.ask(ask, element.intent);
2258
- else void element.open?.();
2479
+ rememberChat(sessionKey);
2480
+ setChatKnown(true);
2481
+ return handed;
2482
+ },
2483
+ [help.sessionUrl, help.scriptUrl, intentJson, sessionKey]
2484
+ );
2485
+ const askCbox = useCallback(
2486
+ (text) => {
2487
+ void openChat(text).then((sent) => {
2488
+ if (sent) store.set((state) => state.query.trim() === text ? { query: "" } : {});
2489
+ });
2259
2490
  },
2260
- [help.sessionUrl, help.scriptUrl, intentJson]
2491
+ [openChat, store]
2261
2492
  );
2493
+ const closeChat = useCallback(() => {
2494
+ const element = chatHost.current?.querySelector(SUPPORT_TAG);
2495
+ if (typeof element?.close === "function") void element.close();
2496
+ store.set({ chat: false });
2497
+ }, [store]);
2262
2498
  useEffect(() => {
2263
2499
  if (pendingQuestion === null || !open) return;
2264
- store.set({ pendingQuestion: null });
2265
- setQuestion(pendingQuestion);
2266
- void openChat(pendingQuestion);
2267
- }, [pendingQuestion, open, openChat, store]);
2500
+ store.set({ pendingQuestion: null, query: pendingQuestion });
2501
+ askCbox(pendingQuestion);
2502
+ }, [pendingQuestion, open, askCbox, store]);
2503
+ useEffect(() => {
2504
+ const node = column.current;
2505
+ if (node === null) return;
2506
+ const onOpen = (event) => {
2507
+ if (event.detail?.inline === true) store.set({ chat: true });
2508
+ };
2509
+ const onClose = (event) => {
2510
+ store.set({ chat: false });
2511
+ if (event.detail?.reason === "unavailable") setChatProblem(true);
2512
+ };
2513
+ const onNavigate = (event) => {
2514
+ const path = ownPath(event.detail?.url);
2515
+ if (path === null) return;
2516
+ event.preventDefault();
2517
+ if (!latest.current.docked) latest.current.toggleHelp(false);
2518
+ latest.current.navigate(path);
2519
+ };
2520
+ node.addEventListener("cbox-support:open", onOpen);
2521
+ node.addEventListener("cbox-support:close", onClose);
2522
+ node.addEventListener("cbox-support:navigate", onNavigate);
2523
+ return () => {
2524
+ node.removeEventListener("cbox-support:open", onOpen);
2525
+ node.removeEventListener("cbox-support:close", onClose);
2526
+ node.removeEventListener("cbox-support:navigate", onNavigate);
2527
+ };
2528
+ }, [store]);
2268
2529
  useLayoutEffect(() => {
2269
2530
  if (open && body.current !== null) body.current.scrollTop = store.get().scrollTop;
2270
- }, [open, article, store]);
2531
+ }, [open, view, store]);
2271
2532
  const wasOpen = useRef(open);
2272
2533
  useEffect(() => {
2273
2534
  const opened = open && !wasOpen.current;
@@ -2276,8 +2537,8 @@ function HelpColumn({ docked, mobile = false }) {
2276
2537
  if (closed) {
2277
2538
  const active = document.activeElement;
2278
2539
  if (active === null || active === document.body || column.current?.contains(active)) {
2279
- const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
2280
- back?.focus({ preventScroll: true });
2540
+ const back2 = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
2541
+ back2?.focus({ preventScroll: true });
2281
2542
  }
2282
2543
  opener.current = null;
2283
2544
  return;
@@ -2287,13 +2548,13 @@ function HelpColumn({ docked, mobile = false }) {
2287
2548
  const active = document.activeElement;
2288
2549
  opener.current = active instanceof HTMLElement && active !== document.body && !column.current?.contains(active) ? active : null;
2289
2550
  }
2290
- if (opened && canAutofocus() && store.get().article === null) searchField.current?.focus();
2551
+ if (opened && canAutofocus() && store.get().article === null && !store.get().chat) askField.current?.focus();
2291
2552
  else if (!docked && !column.current?.contains(document.activeElement)) column.current?.focus();
2292
2553
  }, [open, docked, store]);
2293
2554
  const markRead = (update) => {
2294
2555
  if (!update.unread) return;
2295
2556
  store.set((state) => ({ updates: state.updates.map((item) => item.id === update.id ? { ...item, unread: false } : item) }));
2296
- if (help.updatesUrl !== void 0) requestJson(`${help.updatesUrl.replace(/\/$/, "")}/${encodeURIComponent(update.id)}/read`, { method: "POST" }).catch(() => void 0);
2557
+ helpRequest(store, latest.current.shell, "updates", (url) => `${url.replace(/\/$/, "")}/${encodeURIComponent(update.id)}/read`, { method: "POST" }).catch(() => void 0);
2297
2558
  };
2298
2559
  const openUpdate = (update) => {
2299
2560
  markRead(update);
@@ -2303,19 +2564,124 @@ function HelpColumn({ docked, mobile = false }) {
2303
2564
  };
2304
2565
  const unread = updates.filter((update) => update.unread);
2305
2566
  const unavailable = !help.enabled || updatesStatus === "unavailable" || articles.status === "unavailable" || results?.status === "unavailable";
2306
- const trail = contextTrail(shell);
2307
- const submit = (event) => {
2308
- event.preventDefault();
2309
- void openChat(question.trim());
2310
- if (question.trim() !== "") setAsked(true);
2567
+ const topic = helpTopicName(shell);
2568
+ const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
2569
+ const environment = environmentLevel(shell.context.levels)?.current;
2570
+ const chatReady = help.enabled && help.sessionUrl !== void 0;
2571
+ const close = () => toggleHelp(false);
2572
+ const back = () => view === "article" ? store.set({ article: null }) : closeChat();
2573
+ const pageArticles = help.articlesUrl === void 0 && sentArticles.length > 0 ? sentArticles : articles.items;
2574
+ const context = (strip) => /* @__PURE__ */ jsxs("p", { className: `cbx-ctxnote ${strip ? "is-strip" : ""}`, children: [
2575
+ environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
2576
+ /* @__PURE__ */ jsx("span", { className: "cbx-truncate", title: t("Cbox sees this page: {page} in {where}", { page: topic, where }), children: t("Cbox sees this page: {page} in {where}", { page: topic, where }) })
2577
+ ] });
2578
+ const home = /* @__PURE__ */ jsxs(Fragment, { children: [
2579
+ unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2580
+ /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2581
+ /* @__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.") }),
2582
+ help.enabled && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: () => {
2583
+ loadUpdates();
2584
+ setArticles((current) => ({ ...current, status: "loading", topic: void 0 }));
2585
+ }, children: t("Try again") })
2586
+ ] }),
2587
+ (chatReady || canSearch) && /* @__PURE__ */ jsxs(Fragment, { children: [
2588
+ /* @__PURE__ */ jsx(
2589
+ AskField,
2590
+ {
2591
+ field: askField,
2592
+ value: query2,
2593
+ onChange: (value) => store.set({ query: value }),
2594
+ onSubmit: chatReady ? () => askCbox(query2.trim()) : void 0,
2595
+ placeholder: !chatReady ? t("Search docs and knowledge base") : canSearch ? t("Search or ask\u2026") : t("Ask about {page}\u2026", { page: topic }),
2596
+ label: !chatReady ? t("Search docs and knowledge base") : canSearch ? t("Search or ask\u2026") : t("Ask Cbox")
2597
+ }
2598
+ ),
2599
+ chatReady && context(false)
2600
+ ] }),
2601
+ 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.") }),
2602
+ results !== null ? /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-results", "aria-live": "polite", children: [
2603
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-results", className: "cbx-help-heading", children: t("Results") }),
2604
+ results.items.length > 0 && /* @__PURE__ */ jsx("div", { className: "cbx-group", children: results.items.map((item) => /* @__PURE__ */ jsx(ArticleRow, { article: item }, item.id)) }),
2605
+ results.status === "ready" && results.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: chatReady ? t("No articles match. Send it to ask Cbox.") : t("Nothing matches \u201C{query}\u201D.", { query: results.q }) }),
2606
+ results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", children: t("Searching\u2026") })
2607
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2608
+ chatKnown && chatReady && /* @__PURE__ */ jsx("div", { className: "cbx-group cbx-help-resume", children: /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => void openChat(), children: [
2609
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-accent", "aria-hidden": "true", children: /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8 }) }),
2610
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-label cbx-grow-strong", children: t("Continue the conversation") }),
2611
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2612
+ ] }) }),
2613
+ updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-updates", children: [
2614
+ /* @__PURE__ */ jsxs("div", { className: "cbx-help-heading", children: [
2615
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-updates", children: t("Support updates") }),
2616
+ unread.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pane-all", onClick: () => unread.forEach(markRead), children: t("Mark all read") })
2617
+ ] }),
2618
+ /* @__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: [
2619
+ /* @__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 }) }),
2620
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2621
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", title: update.title, children: update.title }),
2622
+ update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
2623
+ ] }),
2624
+ /* @__PURE__ */ jsxs("span", { className: "cbx-help-meta", children: [
2625
+ update.at !== void 0 && /* @__PURE__ */ jsx("time", { dateTime: update.at, children: formatDate(update.at) }),
2626
+ update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-unread-dot", role: "img", "aria-label": t("Unread") })
2627
+ ] })
2628
+ ] }, update.id)) })
2629
+ ] }),
2630
+ pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-topic", children: [
2631
+ /* @__PURE__ */ jsx("h3", { id: "cbx-help-topic", className: "cbx-help-heading", children: t("For {page}", { page: topic }) }),
2632
+ /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsx(ArticleRow, { article: item }, item.id)) })
2633
+ ] })
2634
+ ] })
2635
+ ] });
2636
+ const reading = article !== null && /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2637
+ /* @__PURE__ */ jsx("h3", { className: "cbx-help-article-title", children: article.title }),
2638
+ /* @__PURE__ */ jsx(ArticleBody, { article, loaded: loadedArticle !== null && loadedArticle.id === article.id ? loadedArticle : null }),
2639
+ article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2640
+ t("Open the full article"),
2641
+ " ",
2642
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2643
+ ] }),
2644
+ chatReady && /* @__PURE__ */ jsxs(Fragment, { children: [
2645
+ /* @__PURE__ */ jsx("h4", { className: "cbx-help-heading", children: t("Still stuck?") }),
2646
+ /* @__PURE__ */ jsx(
2647
+ AskField,
2648
+ {
2649
+ value: followUp,
2650
+ onChange: setFollowUp,
2651
+ onSubmit: () => {
2652
+ const text = followUp.trim();
2653
+ store.set({ article: null, query: text });
2654
+ setFollowUp("");
2655
+ askCbox(text);
2656
+ },
2657
+ placeholder: t("Ask a follow-up\u2026"),
2658
+ label: t("Ask a follow-up")
2659
+ }
2660
+ )
2661
+ ] })
2662
+ ] });
2663
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
2664
+ view === "article" ? reading : view === "home" ? home : null,
2665
+ chatReady && /* @__PURE__ */ jsx("div", { ref: chatHost, className: `cbx-chat-host ${view === "chat" ? "is-open" : ""}`, "data-view": view, children: createElement(SUPPORT_TAG, { "session-url": help.sessionUrl, intent: intentJson, inline: mobile ? "sheet" : "column" }) })
2666
+ ] });
2667
+ const foot = view !== "chat" && (chatReady || portal !== void 0) && /* @__PURE__ */ jsxs("div", { className: "cbx-help-foot", children: [
2668
+ chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-help-action", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
2669
+ /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2670
+ " ",
2671
+ t("Talk to a person")
2672
+ ] }),
2673
+ portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-help-action", href: portal, target: "_blank", rel: "noopener", "aria-label": t("Support portal (opens in a new tab)"), children: [
2674
+ /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2675
+ " ",
2676
+ t("Support portal"),
2677
+ " ",
2678
+ /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2679
+ ] })
2680
+ ] });
2681
+ const onScroll = (top) => {
2682
+ if (view !== "chat") store.set({ scrollTop: top });
2311
2683
  };
2312
- const pageArticles = help.articlesUrl !== void 0 ? articles.items : (help.articles ?? []).slice(0, 4);
2313
2684
  if (mobile) {
2314
- const topic = helpTopicName(shell);
2315
- const environment = environmentLevel(shell.context.levels)?.current;
2316
- const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
2317
- const chatReady = help.enabled && help.sessionUrl !== void 0;
2318
- const close = () => toggleHelp(false);
2319
2685
  return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, ...scrimHandlers(close), children: /* @__PURE__ */ jsxs(
2320
2686
  "div",
2321
2687
  {
@@ -2335,89 +2701,14 @@ function HelpColumn({ docked, mobile = false }) {
2335
2701
  },
2336
2702
  children: [
2337
2703
  /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2338
- /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${article !== null ? "has-back" : ""}`, children: [
2339
- 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 }) }),
2340
- /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
2704
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${view !== "home" ? "has-back" : ""}`, children: [
2705
+ view !== "home" && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-sheet-back", onClick: back, "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
2706
+ /* @__PURE__ */ jsx("h2", { className: "cbx-sheet-title cbx-truncate", children: view === "article" ? t("Article") : view === "chat" ? t("Ask Cbox") : t("Help with {page}", { page: topic }) }),
2341
2707
  /* @__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 }) })
2342
2708
  ] }),
2343
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", "data-cbx-sheet-scroll": "", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2344
- article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2345
- /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
2346
- (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2347
- article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2348
- t("Open the full article"),
2349
- " ",
2350
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2351
- ] }),
2352
- /* @__PURE__ */ jsx("p", { className: "cbx-eyebrow", children: t("Still stuck?") }),
2353
- /* @__PURE__ */ jsxs(
2354
- "form",
2355
- {
2356
- className: "cbx-askbar",
2357
- onSubmit: (event) => {
2358
- event.preventDefault();
2359
- const text = followUp.trim();
2360
- if (text === "") return;
2361
- store.set({ article: null });
2362
- setQuestion(text);
2363
- setAsked(true);
2364
- void openChat(text);
2365
- },
2366
- children: [
2367
- /* @__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 }),
2368
- /* @__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 }) })
2369
- ]
2370
- }
2371
- )
2372
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2373
- unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2374
- /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2375
- /* @__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.") })
2376
- ] }),
2377
- /* @__PURE__ */ jsxs("form", { className: "cbx-askbar", onSubmit: submit, children: [
2378
- /* @__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 }),
2379
- /* @__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 }) })
2380
- ] }),
2381
- /* @__PURE__ */ jsxs("p", { className: "cbx-ctxnote", children: [
2382
- environment !== void 0 && /* @__PURE__ */ jsx("span", { className: `cbx-tone cbx-tone-${environment.tone ?? "neutral"}`, "aria-hidden": "true" }),
2383
- t("Cbox sees this page: {page} in {where}", { page: topic, where })
2384
- ] }),
2385
- 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.") }),
2386
- asked && chatReady && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-pbtn", onClick: () => void openChat(t("I would like to talk to a person."), true), children: [
2387
- /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2388
- " ",
2389
- t("Talk to a person")
2390
- ] }),
2391
- updates.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-threads", children: [
2392
- /* @__PURE__ */ jsx("h2", { id: "cbx-help-threads", className: "cbx-eyebrow", children: t("Your conversations") }),
2393
- /* @__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: [
2394
- /* @__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 }) }),
2395
- /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2396
- /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", children: update.title }),
2397
- update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: update.excerpt })
2398
- ] }),
2399
- update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-badge", children: t("{count} new", { count: 1 }) })
2400
- ] }, update.id)) })
2401
- ] }),
2402
- pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { "aria-labelledby": "cbx-help-for", children: [
2403
- /* @__PURE__ */ jsx("h2", { id: "cbx-help-for", className: "cbx-eyebrow", children: t("For {page}", { page: topic }) }),
2404
- /* @__PURE__ */ jsx("div", { className: "cbx-group", children: pageArticles.map((item) => /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-grow", onClick: () => store.set({ article: item }), children: [
2405
- /* @__PURE__ */ jsx(FileText, { className: "cbx-grow-icon", size: 18, strokeWidth: 1.7, "aria-hidden": true }),
2406
- /* @__PURE__ */ jsx("span", { className: "cbx-grow-label", children: item.title }),
2407
- /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2408
- ] }, item.id)) })
2409
- ] }),
2410
- /* @__PURE__ */ jsxs("div", { className: "cbx-pbtns", children: [
2411
- /* @__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") }),
2412
- portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-pbtn", href: portal, target: "_blank", rel: "noopener", children: [
2413
- t("Help center"),
2414
- " ",
2415
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2416
- ] })
2417
- ] })
2418
- ] }),
2419
- 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 }) })
2420
- ] })
2709
+ view === "chat" && context(true),
2710
+ /* @__PURE__ */ jsx("div", { ref: body, className: `cbx-sheet-body ${view === "chat" ? "is-chat" : ""}`, "data-cbx-sheet-scroll": "", onScroll: (event) => onScroll(event.currentTarget.scrollTop), children: content }),
2711
+ foot
2421
2712
  ]
2422
2713
  }
2423
2714
  ) });
@@ -2437,126 +2728,82 @@ function HelpColumn({ docked, mobile = false }) {
2437
2728
  onKeyDown: (event) => {
2438
2729
  if (event.key === "Escape" && !event.defaultPrevented) {
2439
2730
  event.preventDefault();
2440
- toggleHelp(false);
2731
+ close();
2441
2732
  }
2442
2733
  if (!docked) trapTab(event, column.current);
2443
2734
  },
2444
2735
  children: [
2445
2736
  /* @__PURE__ */ jsxs("div", { className: "cbx-help-head", children: [
2446
- article !== null ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: () => store.set({ article: null }), "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ArrowLeft, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }) : /* @__PURE__ */ jsx(LifeBuoy, { className: "cbx-help-mark", size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2447
- /* @__PURE__ */ jsx("h2", { className: "cbx-help-title", children: t("Help") }),
2448
- portal !== void 0 && /* @__PURE__ */ jsx("a", { className: "cbx-icon-button", href: portal, target: "_blank", rel: "noopener", "aria-label": t("Support portal (opens in a new tab)"), title: t("Support portal"), children: /* @__PURE__ */ jsx(ArrowUpRight, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }),
2449
- /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: () => toggleHelp(false), "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2737
+ view !== "home" ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: back, "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ArrowLeft, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) }) : /* @__PURE__ */ jsx(LifeBuoy, { className: "cbx-help-mark", size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2738
+ /* @__PURE__ */ jsx("h2", { className: "cbx-help-title", children: view === "article" ? t("Article") : view === "chat" ? t("Ask Cbox") : t("Help") }),
2739
+ /* @__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 }) })
2450
2740
  ] }),
2451
- /* @__PURE__ */ jsxs("p", { className: "cbx-help-page", children: [
2452
- /* @__PURE__ */ jsx("span", { className: "cbx-help-page-label", children: t("On this page") }),
2453
- /* @__PURE__ */ jsxs("span", { className: "cbx-truncate", title: [shell.page?.title, trail].filter(Boolean).join(" \xB7 "), children: [
2454
- shell.page?.title !== void 0 && /* @__PURE__ */ jsx("strong", { children: shell.page.title }),
2455
- shell.page?.title !== void 0 && trail !== "" && " \xB7 ",
2456
- trail
2457
- ] })
2458
- ] }),
2459
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-help-body", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2460
- article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
2461
- /* @__PURE__ */ jsx("h3", { children: article.title }),
2462
- (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2463
- article.url !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-link", href: article.url, target: "_blank", rel: "noopener", children: [
2464
- t("Open the full article"),
2465
- " ",
2466
- /* @__PURE__ */ jsx(ArrowUpRight, { size: 14, strokeWidth: 1.8, "aria-hidden": true })
2467
- ] })
2468
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2469
- unavailable && /* @__PURE__ */ jsxs("div", { className: "cbx-help-notice", role: "status", children: [
2470
- /* @__PURE__ */ jsx(CircleAlert, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2471
- /* @__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.") }),
2472
- help.enabled && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-link", onClick: () => {
2473
- loadUpdates();
2474
- setArticles((current) => ({ ...current, status: "loading", topic: void 0 }));
2475
- }, children: t("Try again") })
2476
- ] }),
2477
- unread.length > 0 || updates.length > 0 ? /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-updates", children: [
2478
- /* @__PURE__ */ jsxs("div", { className: "cbx-pane-heading", children: [
2479
- /* @__PURE__ */ jsx("span", { id: "cbx-help-updates", children: t("Support updates") }),
2480
- unread.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-pane-all", onClick: () => unread.forEach(markRead), children: t("Mark all read") })
2481
- ] }),
2482
- /* @__PURE__ */ jsx("ul", { className: "cbx-list", role: "list", children: updates.map((update) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-update ${update.unread ? "is-unread" : ""}`, onClick: () => openUpdate(update), children: [
2483
- update.kind === "chat" ? /* @__PURE__ */ jsx(MessageSquare, { size: 16, strokeWidth: 1.8, "aria-hidden": true }) : /* @__PURE__ */ jsx(Ticket, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2484
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-text", children: [
2485
- /* @__PURE__ */ jsx("span", { className: "cbx-update-title cbx-truncate", title: update.title, children: update.title }),
2486
- update.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-update-excerpt", children: update.excerpt })
2487
- ] }),
2488
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-meta", children: [
2489
- update.at !== void 0 && /* @__PURE__ */ jsx("time", { dateTime: update.at, children: formatDate(update.at) }),
2490
- update.unread && /* @__PURE__ */ jsx("span", { className: "cbx-unread-dot", "aria-label": t("Unread") })
2491
- ] })
2492
- ] }) }, update.id)) })
2493
- ] }) : null,
2494
- /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-label": t("Search docs and knowledge base"), children: [
2495
- /* @__PURE__ */ jsxs("div", { className: "cbx-help-search", children: [
2496
- /* @__PURE__ */ jsx(Search, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2497
- /* @__PURE__ */ jsx(
2498
- "input",
2499
- {
2500
- ref: searchField,
2501
- type: "search",
2502
- value: query2,
2503
- onChange: (event) => store.set({ query: event.target.value }),
2504
- placeholder: t("Search docs and knowledge base"),
2505
- "aria-label": t("Search docs and knowledge base"),
2506
- disabled: !help.enabled || help.searchUrl === void 0
2507
- }
2508
- )
2509
- ] }),
2510
- results !== null && /* @__PURE__ */ jsxs("ul", { className: "cbx-list", role: "list", "aria-live": "polite", children: [
2511
- results.items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(ArticleRow, { article: item }) }, item.id)),
2512
- results.status === "ready" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Nothing matches \u201C{query}\u201D.", { query: results.q }) }),
2513
- results.status === "loading" && results.items.length === 0 && /* @__PURE__ */ jsx("li", { className: "cbx-list-note", children: t("Searching\u2026") })
2514
- ] })
2515
- ] }),
2516
- help.topic !== void 0 && pageArticles.length > 0 && /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-topic", children: [
2517
- /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-topic", children: t("For this page") }) }),
2518
- /* @__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)) })
2519
- ] }),
2520
- /* @__PURE__ */ jsxs("section", { className: "cbx-help-section", "aria-labelledby": "cbx-help-ask", children: [
2521
- /* @__PURE__ */ jsx("div", { className: "cbx-pane-heading", children: /* @__PURE__ */ jsx("span", { id: "cbx-help-ask", children: t("Ask Cbox") }) }),
2522
- /* @__PURE__ */ jsxs("form", { className: "cbx-ask", onSubmit: submit, children: [
2523
- /* @__PURE__ */ jsx(
2524
- "textarea",
2525
- {
2526
- className: "cbx-input",
2527
- rows: 3,
2528
- value: question,
2529
- onChange: (event) => setQuestion(event.target.value),
2530
- placeholder: t("Ask about this page\u2026"),
2531
- "aria-label": t("Ask Cbox"),
2532
- disabled: !help.enabled || help.sessionUrl === void 0,
2533
- onKeyDown: (event) => {
2534
- if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) submit(event);
2535
- }
2536
- }
2537
- ),
2538
- /* @__PURE__ */ jsxs("button", { type: "submit", className: "cbx-button cbx-button-primary", disabled: !help.enabled || help.sessionUrl === void 0, children: [
2539
- /* @__PURE__ */ jsx(Sparkles, { size: 15, strokeWidth: 1.8, "aria-hidden": true }),
2540
- " ",
2541
- t("Ask")
2542
- ] })
2543
- ] }),
2544
- 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.") })
2545
- ] })
2546
- ] }),
2547
- 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 }) })
2548
- ] }),
2549
- /* @__PURE__ */ jsxs("div", { className: "cbx-help-foot", children: [
2550
- /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-row cbx-row-action", onClick: () => void openChat(t("I would like to talk to a person."), true), disabled: !help.enabled || help.sessionUrl === void 0, children: [
2551
- /* @__PURE__ */ jsx(UserRound, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2552
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Talk to a person") })
2553
- ] }),
2554
- portal !== void 0 && /* @__PURE__ */ jsxs("a", { className: "cbx-row cbx-row-action", href: portal, target: "_blank", rel: "noopener", children: [
2555
- /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2556
- /* @__PURE__ */ jsx("span", { className: "cbx-row-name", children: t("Support portal") }),
2557
- /* @__PURE__ */ jsx(ArrowUpRight, { className: "cbx-row-trail", size: 14, strokeWidth: 1.8, "aria-hidden": true })
2558
- ] })
2559
- ] })
2741
+ view === "chat" && context(true),
2742
+ /* @__PURE__ */ jsx("div", { ref: body, className: `cbx-help-body ${view === "chat" ? "is-chat" : ""}`, onScroll: (event) => onScroll(event.currentTarget.scrollTop), children: content }),
2743
+ foot
2744
+ ]
2745
+ }
2746
+ );
2747
+ }
2748
+ var CHAT_FLAG = "cbx-help-chat:";
2749
+ function knowsChat(key) {
2750
+ try {
2751
+ return key !== null && localStorage.getItem(CHAT_FLAG + key) === "1";
2752
+ } catch {
2753
+ return false;
2754
+ }
2755
+ }
2756
+ function rememberChat(key) {
2757
+ try {
2758
+ if (key !== null) localStorage.setItem(CHAT_FLAG + key, "1");
2759
+ } catch {
2760
+ }
2761
+ }
2762
+ function AskField({ value, onChange, onSubmit, placeholder, label, field }) {
2763
+ const { t } = useShell();
2764
+ const own = useRef(null);
2765
+ const fit = useCallback(() => {
2766
+ const element = own.current;
2767
+ if (element === null) return;
2768
+ element.style.height = "auto";
2769
+ element.style.height = element.scrollHeight > 0 ? `${Math.min(element.scrollHeight, 120)}px` : "";
2770
+ }, []);
2771
+ useLayoutEffect(fit, [value, fit]);
2772
+ const empty = value.trim() === "";
2773
+ const send = () => {
2774
+ if (!empty) onSubmit?.();
2775
+ };
2776
+ return /* @__PURE__ */ jsxs(
2777
+ "form",
2778
+ {
2779
+ className: "cbx-askfield",
2780
+ onSubmit: (event) => {
2781
+ event.preventDefault();
2782
+ send();
2783
+ },
2784
+ children: [
2785
+ /* @__PURE__ */ jsx(
2786
+ "textarea",
2787
+ {
2788
+ ref: (element) => {
2789
+ own.current = element;
2790
+ if (typeof field === "function") field(element);
2791
+ else if (field != null) field.current = element;
2792
+ },
2793
+ rows: 1,
2794
+ value,
2795
+ onChange: (event) => onChange(event.target.value),
2796
+ placeholder,
2797
+ "aria-label": label,
2798
+ onFocus: fit,
2799
+ onKeyDown: (event) => {
2800
+ if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing || event.keyCode === 229) return;
2801
+ event.preventDefault();
2802
+ send();
2803
+ }
2804
+ }
2805
+ ),
2806
+ onSubmit !== void 0 && /* @__PURE__ */ jsx("button", { type: "submit", className: "cbx-askfield-send", "aria-label": t("Ask"), disabled: empty, children: /* @__PURE__ */ jsx(ArrowUp, { size: 16, strokeWidth: 2.2, "aria-hidden": true }) })
2560
2807
  ]
2561
2808
  }
2562
2809
  );
@@ -2575,14 +2822,25 @@ function useShortDate(locale, timeZone) {
2575
2822
  return Number.isNaN(date.getTime()) ? iso : format.format(date);
2576
2823
  }, [format]);
2577
2824
  }
2825
+ function ArticleBody({ article, loaded }) {
2826
+ const { t } = useShell();
2827
+ const html = article.bodyHtml ?? loaded?.html ?? null;
2828
+ const clean = useMemo(() => html === null ? "" : cleanArticleHtml(html), [html]);
2829
+ if (clean !== "") return /* @__PURE__ */ jsx("div", { className: "cbx-help-prose", dangerouslySetInnerHTML: { __html: clean } });
2830
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2831
+ (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
2832
+ loaded?.status === "loading" && /* @__PURE__ */ jsx("p", { className: "cbx-list-note", role: "status", children: t("Loading\u2026") })
2833
+ ] });
2834
+ }
2578
2835
  function ArticleRow({ article }) {
2579
2836
  const { openArticle } = useShell();
2580
- return /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-update", onClick: () => openArticle(article), children: [
2581
- /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8, "aria-hidden": true }),
2582
- /* @__PURE__ */ jsxs("span", { className: "cbx-update-text", children: [
2583
- /* @__PURE__ */ jsx("span", { className: "cbx-update-title cbx-truncate", title: article.title, children: article.title }),
2584
- article.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-update-excerpt", children: article.excerpt })
2585
- ] })
2837
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: `cbx-grow ${article.excerpt !== void 0 ? "is-tall" : ""}`, onClick: () => openArticle(article), children: [
2838
+ /* @__PURE__ */ jsx("span", { className: "cbx-tile is-plain", "aria-hidden": "true", children: /* @__PURE__ */ jsx(BookOpen, { size: 16, strokeWidth: 1.8 }) }),
2839
+ /* @__PURE__ */ jsxs("span", { className: "cbx-grow-text", children: [
2840
+ /* @__PURE__ */ jsx("span", { className: "cbx-grow-strong cbx-truncate", title: article.title, children: article.title }),
2841
+ article.excerpt !== void 0 && /* @__PURE__ */ jsx("span", { className: "cbx-grow-sub cbx-truncate", children: article.excerpt })
2842
+ ] }),
2843
+ /* @__PURE__ */ jsx(ChevronRight, { className: "cbx-grow-trail", size: 16, strokeWidth: 1.8, "aria-hidden": true })
2586
2844
  ] });
2587
2845
  }
2588
2846
 
@@ -2691,7 +2949,7 @@ function rows(body, group) {
2691
2949
  return Array.isArray(data) ? data.filter((row) => typeof row === "object" && row !== null) : [];
2692
2950
  }
2693
2951
  function CommandPalette({ onClose }) {
2694
- const { shell, t, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2952
+ const { shell, t, help: helpStore, navigate, switchTo, openArticle, ask, mobile, openContext, openCreate, canCreate, searchRecords } = useShell();
2695
2953
  const [scope, setScope] = useState("all");
2696
2954
  const [input, setInput] = useState("");
2697
2955
  const [query2, setQuery] = useState("");
@@ -2809,10 +3067,15 @@ function CommandPalette({ onClose }) {
2809
3067
  if (settled.every((result) => result.status === "rejected") && settled.length > 0) throw new Error("unavailable");
2810
3068
  return settled.flatMap((result) => result.status === "fulfilled" ? result.value : []);
2811
3069
  });
2812
- if (shell.help.enabled && shell.help.searchUrl !== void 0) {
3070
+ if (helpEndpointState(shell.help, helpStore.get().session, helpSessionKey(shell), "search") !== "none") {
2813
3071
  run(
2814
3072
  "docs",
2815
- async () => parseArticles(await requestJson(withQuery(shell.help.searchUrl, { q: q2, topic: shell.help.topic }), { signal })).map((article) => ({
3073
+ async () => parseArticles(
3074
+ await helpRequest(helpStore, shell, "search", (url) => withQuery(url, { q: q2, topic: shell.help.topic }), { signal }).catch((error) => {
3075
+ if (error instanceof HelpUnavailableError) return [];
3076
+ throw error;
3077
+ })
3078
+ ).map((article) => ({
2816
3079
  id: `doc:${article.id}`,
2817
3080
  title: article.title,
2818
3081
  subtitle: article.excerpt,
@@ -3052,14 +3315,14 @@ function CommandPalette({ onClose }) {
3052
3315
  /* @__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)) }),
3053
3316
  /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", "data-cbx-sheet-scroll": "", children: [
3054
3317
  rendered.map((section) => {
3055
- const loading = section.state.status === "loading" && section.state.items.length === 0;
3056
- if (section.count === 0 && !loading) return null;
3318
+ const loading2 = section.state.status === "loading" && section.state.items.length === 0;
3319
+ if (section.count === 0 && !loading2) return null;
3057
3320
  return /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": `${id}-${section.key}`, className: "cbx-palette-group", children: [
3058
3321
  /* @__PURE__ */ jsxs("div", { id: `${id}-${section.key}`, className: "cbx-pane-heading", role: "presentation", children: [
3059
3322
  /* @__PURE__ */ jsx("span", { children: section.label }),
3060
3323
  section.state.status === "loading" && /* @__PURE__ */ jsx("span", { className: "cbx-palette-busy", "aria-hidden": "true" })
3061
3324
  ] }),
3062
- loading && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", "aria-live": "polite", children: t("Searching\u2026") }),
3325
+ loading2 && /* @__PURE__ */ jsx("div", { className: "cbx-list-note", "aria-live": "polite", children: t("Searching\u2026") }),
3063
3326
  section.count > 0 && /* @__PURE__ */ jsx("div", { className: "cbx-palette-rows", role: "presentation", children: options.slice(section.start, section.start + section.count).map((option, offset) => {
3064
3327
  const index = section.start + offset;
3065
3328
  const on = index === active;
@@ -5456,8 +5719,8 @@ function StatTile({
5456
5719
  ),
5457
5720
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-0.5", children: [
5458
5721
  /* @__PURE__ */ jsx("p", { className: "tabular text-2xl leading-none font-semibold tracking-tight text-foreground", children: value }),
5459
- /* @__PURE__ */ jsx("p", { className: "truncate text-xs text-muted-foreground", children: label }),
5460
- suffix ? /* @__PURE__ */ jsx("p", { className: "text-mono truncate text-[10px] text-muted-foreground", children: suffix }) : null
5722
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-pretty break-words text-muted-foreground", children: label }),
5723
+ suffix ? /* @__PURE__ */ jsx("p", { className: "text-mono text-[10px] text-pretty break-words text-muted-foreground", children: suffix }) : null
5461
5724
  ] })
5462
5725
  ]
5463
5726
  }
@@ -5781,7 +6044,7 @@ function InboxSurface({ open, onClose }) {
5781
6044
  const transport = useTransport();
5782
6045
  const cboxId = useCboxIdOptional();
5783
6046
  const [inbox, setInbox] = useState(null);
5784
- const [loading, setLoading] = useState(false);
6047
+ const [loading2, setLoading] = useState(false);
5785
6048
  const [error, setError] = useState(null);
5786
6049
  const [filter, setFilter] = useState("all");
5787
6050
  const userId = cboxId?.user.id ?? null;
@@ -5892,7 +6155,7 @@ function InboxSurface({ open, onClose }) {
5892
6155
  children: error !== null ? /* @__PURE__ */ jsxs("div", { className: "px-5 py-8 text-center", children: [
5893
6156
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-destructive-text", children: t("Couldn't load inbox") }),
5894
6157
  /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: error })
5895
- ] }) : loading && inbox === null ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12 text-center text-sm text-muted-foreground", children: t("Loading\u2026") }) : filtered.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12", children: /* @__PURE__ */ jsx(
6158
+ ] }) : loading2 && inbox === null ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12 text-center text-sm text-muted-foreground", children: t("Loading\u2026") }) : filtered.length === 0 ? /* @__PURE__ */ jsx("div", { className: "px-5 py-12", children: /* @__PURE__ */ jsx(
5896
6159
  EmptyState,
5897
6160
  {
5898
6161
  title: filter === "unread" ? t("No unread notifications") : t("No notifications yet"),