@cboxdk/cbox-ui 0.11.0 → 0.11.2

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
@@ -84,6 +84,15 @@ function useShellHelp() {
84
84
  const api = useContext(ShellContext);
85
85
  return api === null ? null : { toggleHelp: api.toggleHelp, openArticle: api.openArticle, ask: api.ask };
86
86
  }
87
+ function sameTitle(a, b) {
88
+ const norm = (text) => text.replace(/\s+/g, " ").trim().replace(/:$/, "").toLocaleLowerCase();
89
+ return norm(a) !== "" && norm(a) === norm(b);
90
+ }
91
+ function useShellPageTitle() {
92
+ const api = useContext(ShellContext);
93
+ if (api === null || !api.mobile) return null;
94
+ return api.shell.nav.areas.find((area) => area.key === api.shell.nav.activeArea)?.label ?? null;
95
+ }
87
96
  var DESKTOP_POINTER = "(hover: hover) and (pointer: fine)";
88
97
  var HELP_DOCKED = "(min-width: 1280px)";
89
98
  var MOBILE = "(max-width: 767px)";
@@ -1502,6 +1511,350 @@ function parseArticles(body) {
1502
1511
  return [article];
1503
1512
  });
1504
1513
  }
1514
+ var count = 0;
1515
+ var saved = null;
1516
+ var startY = 0;
1517
+ var startX = 0;
1518
+ var LAYER = ".cbx-overlay, [data-cbx-scroll-layer]";
1519
+ function scrollable(element, axis) {
1520
+ const style = getComputedStyle(element);
1521
+ const overflow = axis === "y" ? style.overflowY : style.overflowX;
1522
+ if (overflow !== "auto" && overflow !== "scroll") return false;
1523
+ return axis === "y" ? element.scrollHeight > element.clientHeight + 1 : element.scrollWidth > element.clientWidth + 1;
1524
+ }
1525
+ function canScrollWithin(target, dx, dy) {
1526
+ if (!(target instanceof Element)) return false;
1527
+ const layer = target.closest(LAYER);
1528
+ if (layer === null) return false;
1529
+ const axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";
1530
+ const delta = axis === "y" ? dy : dx;
1531
+ if (delta === 0) return true;
1532
+ if (target.closest('textarea, input[type="range"]') !== null) return true;
1533
+ for (let node = target; node !== null && node !== layer.parentElement; node = node.parentElement) {
1534
+ if (!scrollable(node, axis)) continue;
1535
+ const position = axis === "y" ? node.scrollTop : node.scrollLeft;
1536
+ const max = axis === "y" ? node.scrollHeight - node.clientHeight : node.scrollWidth - node.clientWidth;
1537
+ if (delta > 0 && position > 0) return true;
1538
+ if (delta < 0 && position < max - 1) return true;
1539
+ }
1540
+ return false;
1541
+ }
1542
+ function onTouchStart(event) {
1543
+ const touch = event.touches[0];
1544
+ if (touch === void 0) return;
1545
+ startX = touch.clientX;
1546
+ startY = touch.clientY;
1547
+ }
1548
+ function onTouchMove(event) {
1549
+ if (event.touches.length > 1 || !event.cancelable) return;
1550
+ const touch = event.touches[0];
1551
+ if (touch === void 0) return;
1552
+ const dx = touch.clientX - startX;
1553
+ const dy = touch.clientY - startY;
1554
+ startX = touch.clientX;
1555
+ startY = touch.clientY;
1556
+ if (!canScrollWithin(event.target, dx, dy)) event.preventDefault();
1557
+ }
1558
+ function scrollRegions() {
1559
+ return Array.from(document.querySelectorAll(".cbx-shell-main, [scroll-region]")).filter((element) => {
1560
+ const overflow = getComputedStyle(element).overflowY;
1561
+ return overflow === "auto" || overflow === "scroll";
1562
+ });
1563
+ }
1564
+ function lockScroll() {
1565
+ if (typeof document === "undefined") return () => void 0;
1566
+ count += 1;
1567
+ if (count === 1) {
1568
+ const html = document.documentElement;
1569
+ const body = document.body;
1570
+ const gutter = Math.max(0, window.innerWidth - html.clientWidth);
1571
+ saved = {
1572
+ x: window.scrollX,
1573
+ y: window.scrollY,
1574
+ html: { overflow: html.style.overflow, scrollBehavior: html.style.scrollBehavior },
1575
+ body: { overflow: body.style.overflow, paddingRight: body.style.paddingRight },
1576
+ regions: scrollRegions().map((element) => ({ element, overflow: element.style.overflow, top: element.scrollTop }))
1577
+ };
1578
+ html.style.overflow = "hidden";
1579
+ body.style.overflow = "hidden";
1580
+ if (gutter > 0) body.style.paddingRight = `calc(${getComputedStyle(body).paddingRight} + ${gutter}px)`;
1581
+ for (const region of saved.regions) region.element.style.overflow = "hidden";
1582
+ html.setAttribute("data-cbx-scroll-locked", "");
1583
+ document.addEventListener("touchstart", onTouchStart, { passive: true, capture: true });
1584
+ document.addEventListener("touchmove", onTouchMove, { passive: false, capture: true });
1585
+ }
1586
+ let released = false;
1587
+ return () => {
1588
+ if (released) return;
1589
+ released = true;
1590
+ count -= 1;
1591
+ if (count > 0 || saved === null) return;
1592
+ const html = document.documentElement;
1593
+ const body = document.body;
1594
+ const { x, y, regions } = saved;
1595
+ html.style.overflow = saved.html.overflow;
1596
+ body.style.overflow = saved.body.overflow;
1597
+ body.style.paddingRight = saved.body.paddingRight;
1598
+ html.removeAttribute("data-cbx-scroll-locked");
1599
+ document.removeEventListener("touchstart", onTouchStart, { capture: true });
1600
+ document.removeEventListener("touchmove", onTouchMove, { capture: true });
1601
+ html.style.scrollBehavior = "auto";
1602
+ for (const region of regions) {
1603
+ region.element.style.overflow = region.overflow;
1604
+ region.element.scrollTop = region.top;
1605
+ }
1606
+ if (window.scrollX !== x || window.scrollY !== y) {
1607
+ try {
1608
+ window.scrollTo(x, y);
1609
+ } catch {
1610
+ }
1611
+ }
1612
+ html.style.scrollBehavior = saved.html.scrollBehavior;
1613
+ saved = null;
1614
+ };
1615
+ }
1616
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
1617
+ function useScrollLock(active = true) {
1618
+ useIsoLayoutEffect(() => {
1619
+ if (!active) return;
1620
+ return lockScroll();
1621
+ }, [active]);
1622
+ }
1623
+ var LARGE = 0.92;
1624
+ var MEDIUM = 0.5;
1625
+ function sheetDetents({ size, viewport, current, content }) {
1626
+ const large = Math.round(viewport * LARGE);
1627
+ const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
1628
+ const sorted = heights.map(Math.round).sort((a, b) => a - b);
1629
+ const detents = [];
1630
+ for (const height of sorted) {
1631
+ const last = detents[detents.length - 1];
1632
+ if (last === void 0 || height - last >= 48) detents.push(height);
1633
+ else if (height === Math.round(current)) detents[detents.length - 1] = height;
1634
+ }
1635
+ return detents;
1636
+ }
1637
+ function rubberBand(overshoot, limit = 120) {
1638
+ if (overshoot <= 0) return 0;
1639
+ return limit * (1 - 1 / (overshoot / limit + 1));
1640
+ }
1641
+ function settleSheet({ height, velocity, detents }) {
1642
+ const smallest = detents[0] ?? height;
1643
+ const below = smallest - height;
1644
+ if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
1645
+ const projected = height - velocity * 200;
1646
+ let best = smallest;
1647
+ for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
1648
+ return { close: false, height: best };
1649
+ }
1650
+ var VelocityTracker = class {
1651
+ samples = [];
1652
+ add(t, y) {
1653
+ this.samples.push({ t, y });
1654
+ while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
1655
+ }
1656
+ velocity() {
1657
+ const first = this.samples[0];
1658
+ const last = this.samples[this.samples.length - 1];
1659
+ if (first === void 0 || last === void 0 || last.t === first.t) return 0;
1660
+ return (last.y - first.y) / (last.t - first.t);
1661
+ }
1662
+ };
1663
+ function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
1664
+ if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
1665
+ if (Math.abs(dx) > Math.abs(dy)) return "scroll";
1666
+ if (zone === "grab") return "drag";
1667
+ if (dy > 0 && scrollTop <= 0) return "drag";
1668
+ if (dy < 0 && canGrow) return "drag";
1669
+ return "scroll";
1670
+ }
1671
+ var EASE = "cubic-bezier(.2, .9, .25, 1)";
1672
+ var DURATION = 280;
1673
+ var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
1674
+ var GRAB_FIELD = '.cbx-sheet-grab :is(input[type="search"], input[type="text"], input:not([type]))';
1675
+ function reducedMotion() {
1676
+ return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1677
+ }
1678
+ function visibleHeight() {
1679
+ return Math.round(window.visualViewport?.height ?? window.innerHeight);
1680
+ }
1681
+ function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
1682
+ const close = useRef(onClose);
1683
+ close.current = onClose;
1684
+ useEffect(() => {
1685
+ const sheet = panel.current;
1686
+ if (!enabled || sheet === null || typeof window === "undefined") return;
1687
+ let gesture = null;
1688
+ let natural = null;
1689
+ let closing = false;
1690
+ let timer;
1691
+ const scrollerOf = (target) => {
1692
+ for (let node = target; node !== null && node !== sheet; node = node.parentElement) {
1693
+ const overflow = getComputedStyle(node).overflowY;
1694
+ if ((overflow === "auto" || overflow === "scroll") && node instanceof HTMLElement) return node;
1695
+ }
1696
+ return null;
1697
+ };
1698
+ const contentHeight = () => {
1699
+ const body = sheet.querySelector("[data-cbx-sheet-scroll]");
1700
+ if (body === null) return sheet.offsetHeight;
1701
+ return sheet.offsetHeight - body.clientHeight + body.scrollHeight;
1702
+ };
1703
+ const setScrim = (fraction) => {
1704
+ if (scrim?.current) {
1705
+ if (fraction >= 1) scrim.current.style.removeProperty("--cbx-scrim");
1706
+ else scrim.current.style.setProperty("--cbx-scrim", String(Math.max(0, Math.min(1, fraction))));
1707
+ }
1708
+ };
1709
+ const animate = (on) => {
1710
+ const smooth = on && !reducedMotion();
1711
+ sheet.style.transition = smooth ? `height ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : "none";
1712
+ if (scrim?.current) scrim.current.style.transition = smooth ? `--cbx-scrim ${DURATION}ms ${EASE}` : "none";
1713
+ };
1714
+ const place2 = (height, detents) => {
1715
+ const smallest = detents[0];
1716
+ const largest = detents[detents.length - 1];
1717
+ let shown = height;
1718
+ let drop = 0;
1719
+ if (height > largest) shown = largest + rubberBand(height - largest);
1720
+ else if (height < smallest) {
1721
+ shown = smallest;
1722
+ drop = smallest - height;
1723
+ }
1724
+ sheet.style.maxHeight = "none";
1725
+ sheet.style.height = `${Math.round(shown)}px`;
1726
+ sheet.style.transform = drop > 0 ? `translateY(${Math.round(drop)}px)` : "";
1727
+ setScrim(drop > 0 ? 1 - drop / smallest : 1);
1728
+ sheet.dataset.cbxDragging = "true";
1729
+ };
1730
+ const begin = (event) => {
1731
+ if (gesture !== null) finish(gesture.last, event.timeStamp);
1732
+ if (closing) return;
1733
+ if (event.pointerType === "mouse" && event.button !== 0) return;
1734
+ const target = event.target instanceof Element ? event.target : null;
1735
+ if (target === null || target.closest(NO_DRAG) !== null && !target.matches(GRAB_FIELD)) return;
1736
+ const zone = target.closest(".cbx-sheet-grab") !== null ? "grab" : "content";
1737
+ gesture = { id: event.pointerId, x: event.clientX, y: event.clientY, zone, scroller: scrollerOf(target), mode: void 0, last: event.clientY, start: 0, detents: [], tracker: new VelocityTracker() };
1738
+ gesture.tracker.add(event.timeStamp, event.clientY);
1739
+ window.addEventListener("pointermove", move);
1740
+ window.addEventListener("pointerup", end);
1741
+ window.addEventListener("pointercancel", end);
1742
+ };
1743
+ const canGrow = () => {
1744
+ const current = sheet.getBoundingClientRect().height;
1745
+ const detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1746
+ return current < detents[detents.length - 1] - 1;
1747
+ };
1748
+ const decide = (dx, dy) => {
1749
+ if (gesture === null) return void 0;
1750
+ if (gesture.mode !== void 0) return gesture.mode;
1751
+ const mode = dragIntent({ zone: gesture.zone, dx, dy, scrollTop: gesture.scroller?.scrollTop ?? 0, canGrow: gesture.zone === "content" && dy < 0 ? canGrow() : false });
1752
+ if (mode === "drag") {
1753
+ clearTimeout(timer);
1754
+ const current = sheet.getBoundingClientRect().height;
1755
+ if (natural === null && sheet.style.height === "") natural = Math.round(current);
1756
+ gesture.start = current;
1757
+ gesture.detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1758
+ animate(false);
1759
+ try {
1760
+ sheet.setPointerCapture(gesture.id);
1761
+ } catch {
1762
+ }
1763
+ }
1764
+ gesture.mode = mode;
1765
+ return mode;
1766
+ };
1767
+ const move = (event) => {
1768
+ if (gesture === null || event.pointerId !== gesture.id) return;
1769
+ const dx = event.clientX - gesture.x;
1770
+ const dy = event.clientY - gesture.y;
1771
+ if (decide(dx, dy) !== "drag") return;
1772
+ gesture.last = event.clientY;
1773
+ gesture.tracker.add(event.timeStamp, event.clientY);
1774
+ place2(gesture.start - dy, gesture.detents);
1775
+ };
1776
+ const end = (event) => {
1777
+ if (gesture === null || event.pointerId !== gesture.id) return;
1778
+ finish(event.type === "pointerup" ? event.clientY : gesture.last, event.timeStamp);
1779
+ };
1780
+ const finish = (y, at) => {
1781
+ const done = gesture;
1782
+ gesture = null;
1783
+ unfollow();
1784
+ if (done === null || done.mode !== "drag") return;
1785
+ done.tracker.add(at, y);
1786
+ delete sheet.dataset.cbxDragging;
1787
+ const height = done.start - (y - done.y);
1788
+ const result = settleSheet({ height, velocity: done.tracker.velocity(), detents: done.detents });
1789
+ const swallow = (click) => {
1790
+ click.preventDefault();
1791
+ click.stopPropagation();
1792
+ };
1793
+ sheet.addEventListener("click", swallow, { capture: true, once: true });
1794
+ setTimeout(() => sheet.removeEventListener("click", swallow, { capture: true }), 350);
1795
+ animate(true);
1796
+ if (result.close) {
1797
+ closing = true;
1798
+ sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
1799
+ setScrim(0);
1800
+ timer = setTimeout(() => close.current(), reducedMotion() ? 0 : DURATION - 40);
1801
+ return;
1802
+ }
1803
+ if (natural !== null && result.height === natural) {
1804
+ sheet.style.height = `${natural}px`;
1805
+ sheet.style.transform = "";
1806
+ setScrim(1);
1807
+ timer = setTimeout(() => {
1808
+ sheet.style.height = "";
1809
+ sheet.style.maxHeight = "";
1810
+ sheet.style.transition = "";
1811
+ natural = null;
1812
+ }, reducedMotion() ? 0 : DURATION);
1813
+ return;
1814
+ }
1815
+ sheet.style.height = `${result.height}px`;
1816
+ sheet.style.transform = "";
1817
+ setScrim(1);
1818
+ };
1819
+ const touchMove = (event) => {
1820
+ if (gesture === null || event.touches.length > 1) return;
1821
+ const touch = event.touches[0];
1822
+ const mode = decide(touch.clientX - gesture.x, touch.clientY - gesture.y);
1823
+ if (mode === "drag" && event.cancelable) event.preventDefault();
1824
+ };
1825
+ const unfollow = () => {
1826
+ window.removeEventListener("pointermove", move);
1827
+ window.removeEventListener("pointerup", end);
1828
+ window.removeEventListener("pointercancel", end);
1829
+ };
1830
+ sheet.addEventListener("pointerdown", begin);
1831
+ sheet.addEventListener("touchmove", touchMove, { passive: false });
1832
+ return () => {
1833
+ clearTimeout(timer);
1834
+ unfollow();
1835
+ sheet.removeEventListener("pointerdown", begin);
1836
+ sheet.removeEventListener("touchmove", touchMove);
1837
+ for (const property of ["height", "maxHeight", "transform", "transition"]) sheet.style[property] = "";
1838
+ delete sheet.dataset.cbxDragging;
1839
+ if (scrim?.current) {
1840
+ scrim.current.style.removeProperty("--cbx-scrim");
1841
+ scrim.current.style.transition = "";
1842
+ }
1843
+ };
1844
+ }, [panel, scrim, size, enabled]);
1845
+ }
1846
+ function scrimHandlers(onClose) {
1847
+ return {
1848
+ onPointerDown: (event) => {
1849
+ event.currentTarget.dataset.cbxPressed = event.target === event.currentTarget ? "true" : "false";
1850
+ },
1851
+ onClick: (event) => {
1852
+ const pressed = event.currentTarget.dataset.cbxPressed === "true";
1853
+ delete event.currentTarget.dataset.cbxPressed;
1854
+ if (pressed && event.target === event.currentTarget) onClose();
1855
+ }
1856
+ };
1857
+ }
1505
1858
  var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
1506
1859
  var SUPPORT_TAG = "cbox-support";
1507
1860
  function useHelpState(store, select) {
@@ -1572,7 +1925,11 @@ function HelpColumn({ docked, mobile = false }) {
1572
1925
  const chatHost = useRef(null);
1573
1926
  const searchField = useRef(null);
1574
1927
  const opener = useRef(null);
1928
+ const scrim = useRef(null);
1575
1929
  const { help } = shell;
1930
+ useScrollLock(mobile && open);
1931
+ const closeSheet = useCallback(() => toggleHelp(false), [toggleHelp]);
1932
+ useSheetDrag({ panel: column, scrim, size: "tall", onClose: closeSheet, enabled: mobile && open });
1576
1933
  const portal = help.portalUrl;
1577
1934
  const updatesKey = help.enabled && help.updatesUrl !== void 0 ? `${help.updatesUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
1578
1935
  const loadUpdates = useCallback(() => {
@@ -1670,7 +2027,7 @@ function HelpColumn({ docked, mobile = false }) {
1670
2027
  const active = document.activeElement;
1671
2028
  if (active === null || active === document.body || column.current?.contains(active)) {
1672
2029
  const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
1673
- back?.focus();
2030
+ back?.focus({ preventScroll: true });
1674
2031
  }
1675
2032
  opener.current = null;
1676
2033
  return;
@@ -1709,9 +2066,7 @@ function HelpColumn({ docked, mobile = false }) {
1709
2066
  const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
1710
2067
  const chatReady = help.enabled && help.sessionUrl !== void 0;
1711
2068
  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(
2069
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, ...scrimHandlers(close), children: /* @__PURE__ */ jsxs(
1715
2070
  "div",
1716
2071
  {
1717
2072
  ref: column,
@@ -1729,13 +2084,13 @@ function HelpColumn({ docked, mobile = false }) {
1729
2084
  trapTab(event, column.current);
1730
2085
  },
1731
2086
  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: [
2087
+ /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2088
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${article !== null ? "has-back" : ""}`, children: [
1734
2089
  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
2090
  /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
1736
2091
  /* @__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
2092
  ] }),
1738
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2093
+ /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", "data-cbx-sheet-scroll": "", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
1739
2094
  article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
1740
2095
  /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
1741
2096
  (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
@@ -2096,14 +2451,17 @@ function CommandPalette({ onClose }) {
2096
2451
  const [activeKey, setActiveKey] = useState(null);
2097
2452
  const field = useRef(null);
2098
2453
  const dialog = useRef(null);
2454
+ const scrim = useRef(null);
2099
2455
  const id = useId();
2456
+ useScrollLock();
2457
+ useSheetDrag({ panel: dialog, scrim, size: "full", onClose, enabled: mobile });
2100
2458
  const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2101
2459
  useEffect(() => {
2102
2460
  if (canAutofocus()) field.current?.focus();
2103
2461
  else dialog.current?.focus();
2104
2462
  const back = opener.current;
2105
2463
  return () => {
2106
- if (back instanceof HTMLElement) back.focus();
2464
+ if (back instanceof HTMLElement) back.focus({ preventScroll: true });
2107
2465
  };
2108
2466
  }, []);
2109
2467
  useEffect(() => {
@@ -2415,11 +2773,9 @@ function CommandPalette({ onClose }) {
2415
2773
  { value: "pages", label: t("Pages") },
2416
2774
  { value: "help", label: t("Help") }
2417
2775
  ];
2418
- return /* @__PURE__ */ jsx("div", { className: `cbx-overlay cbx-palette-backdrop ${mobile ? "is-sheet" : ""}`, onPointerDown: (event) => {
2419
- if (event.target === event.currentTarget) onClose();
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" }),
2422
- /* @__PURE__ */ jsxs("div", { className: "cbx-palette-search", children: [
2776
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: `cbx-overlay cbx-palette-backdrop ${mobile ? "is-sheet" : ""}`, ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs("div", { ref: dialog, className: `cbx-palette ${mobile ? "is-sheet" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": t("Search"), tabIndex: -1, onKeyDown, children: [
2777
+ mobile && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2778
+ /* @__PURE__ */ jsxs("div", { className: `cbx-palette-search ${mobile ? "cbx-sheet-grab" : ""}`, children: [
2423
2779
  /* @__PURE__ */ jsxs("label", { className: "cbx-palette-field", children: [
2424
2780
  /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2425
2781
  /* @__PURE__ */ jsx(
@@ -2444,7 +2800,7 @@ function CommandPalette({ onClose }) {
2444
2800
  mobile ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-palette-cancel", onClick: onClose, children: t("Cancel") }) : /* @__PURE__ */ jsx("kbd", { className: "cbx-kbd", children: "Esc" })
2445
2801
  ] }),
2446
2802
  /* @__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)) }),
2447
- /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", children: [
2803
+ /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", "data-cbx-sheet-scroll": "", children: [
2448
2804
  rendered.map((section) => {
2449
2805
  const loading = section.state.status === "loading" && section.state.items.length === 0;
2450
2806
  if (section.count === 0 && !loading) return null;
@@ -2518,17 +2874,18 @@ function Sheet({
2518
2874
  }) {
2519
2875
  const { t } = useShell();
2520
2876
  const panel = useRef(null);
2877
+ const scrim = useRef(null);
2878
+ useScrollLock();
2879
+ useSheetDrag({ panel, scrim, size: size ?? "fit", onClose, enabled: side === "bottom" });
2521
2880
  const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2522
2881
  useEffect(() => {
2523
2882
  panel.current?.focus();
2524
2883
  const restore = opener.current;
2525
2884
  return () => {
2526
- if (restore instanceof HTMLElement && restore.isConnected) restore.focus();
2885
+ if (restore instanceof HTMLElement && restore.isConnected) restore.focus({ preventScroll: true });
2527
2886
  };
2528
2887
  }, []);
2529
- return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-sheet-backdrop", onPointerDown: (event) => {
2530
- if (event.target === event.currentTarget) onClose();
2531
- }, children: /* @__PURE__ */ jsxs(
2888
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs(
2532
2889
  "div",
2533
2890
  {
2534
2891
  ref: panel,
@@ -2545,8 +2902,8 @@ function Sheet({
2545
2902
  trapTab(event, panel.current);
2546
2903
  },
2547
2904
  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: [
2905
+ side === "bottom" && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2906
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head ${side === "bottom" ? "cbx-sheet-grab" : ""} ${back !== void 0 ? "has-back" : ""}`, children: [
2550
2907
  back !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-sheet-back", onClick: back.onBack, "aria-label": back.label, children: [
2551
2908
  /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }),
2552
2909
  back.text !== void 0 && /* @__PURE__ */ jsx("span", { children: back.text })
@@ -2554,7 +2911,7 @@ function Sheet({
2554
2911
  /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: title ?? label }),
2555
2912
  /* @__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
2913
  ] }),
2557
- /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, children })
2914
+ /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, "data-cbx-sheet-scroll": "", children })
2558
2915
  ]
2559
2916
  }
2560
2917
  ) });
@@ -3180,6 +3537,76 @@ function AppsSheet({ onClose }) {
3180
3537
  const { t } = useShell();
3181
3538
  return /* @__PURE__ */ jsx(Sheet, { label: t("Switch app"), onClose, children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false }) });
3182
3539
  }
3540
+ function MobilePage({ hidden, children }) {
3541
+ const box = useRef(null);
3542
+ const title = useShellPageTitle();
3543
+ useEffect(() => {
3544
+ const page = box.current;
3545
+ if (page === null) return;
3546
+ const mark = () => {
3547
+ for (const heading of page.querySelectorAll("[data-cbx-page-title]")) {
3548
+ const same = title !== null && sameTitle(heading.textContent ?? "", title);
3549
+ if (same !== heading.hasAttribute("data-cbx-same-title")) heading.toggleAttribute("data-cbx-same-title", same);
3550
+ }
3551
+ };
3552
+ mark();
3553
+ if (typeof MutationObserver === "undefined") return;
3554
+ const observer = new MutationObserver(mark);
3555
+ observer.observe(page, { childList: true, subtree: true, characterData: true });
3556
+ return () => observer.disconnect();
3557
+ }, [title]);
3558
+ return /* @__PURE__ */ jsx("div", { ref: box, className: "cbx-m-page", hidden, children });
3559
+ }
3560
+ function keyboardInset({ innerHeight, viewportHeight, offsetTop }) {
3561
+ return Math.max(0, Math.round(innerHeight - viewportHeight - offsetTop));
3562
+ }
3563
+ var EDITABLE = 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="range"]), textarea, select, [contenteditable]';
3564
+ function useViewportInsets(enabled) {
3565
+ useEffect(() => {
3566
+ if (!enabled || typeof window === "undefined") return;
3567
+ const html = document.documentElement;
3568
+ const viewport = window.visualViewport;
3569
+ let tallest = window.innerHeight;
3570
+ let width = window.innerWidth;
3571
+ let frame = 0;
3572
+ const update = () => {
3573
+ frame = 0;
3574
+ if (window.innerWidth !== width) {
3575
+ width = window.innerWidth;
3576
+ tallest = window.innerHeight;
3577
+ }
3578
+ tallest = Math.max(tallest, window.innerHeight);
3579
+ const visible = viewport?.height ?? window.innerHeight;
3580
+ const inset = keyboardInset({ innerHeight: window.innerHeight, viewportHeight: visible, offsetTop: viewport?.offsetTop ?? 0 });
3581
+ html.style.setProperty("--cbx-keyboard", `${inset}px`);
3582
+ html.style.setProperty("--cbx-vvh", `${Math.round(visible)}px`);
3583
+ const typing = document.activeElement instanceof Element && document.activeElement.matches(EDITABLE);
3584
+ const shrunk = tallest - visible > 120;
3585
+ if (typing && (inset > 120 || shrunk)) html.setAttribute("data-cbx-keyboard", "");
3586
+ else html.removeAttribute("data-cbx-keyboard");
3587
+ };
3588
+ const schedule = () => {
3589
+ if (frame === 0) frame = requestAnimationFrame(update);
3590
+ };
3591
+ update();
3592
+ viewport?.addEventListener("resize", schedule);
3593
+ viewport?.addEventListener("scroll", schedule);
3594
+ window.addEventListener("resize", schedule);
3595
+ document.addEventListener("focusin", schedule);
3596
+ document.addEventListener("focusout", schedule);
3597
+ return () => {
3598
+ cancelAnimationFrame(frame);
3599
+ viewport?.removeEventListener("resize", schedule);
3600
+ viewport?.removeEventListener("scroll", schedule);
3601
+ window.removeEventListener("resize", schedule);
3602
+ document.removeEventListener("focusin", schedule);
3603
+ document.removeEventListener("focusout", schedule);
3604
+ html.style.removeProperty("--cbx-keyboard");
3605
+ html.style.removeProperty("--cbx-vvh");
3606
+ html.removeAttribute("data-cbx-keyboard");
3607
+ };
3608
+ }, [enabled]);
3609
+ }
3183
3610
  var PlainLink = ({ href, children, ...props }) => /* @__PURE__ */ jsx("a", { href, ...props, children });
3184
3611
  function writeCookie(key, value) {
3185
3612
  if (typeof document === "undefined") return;
@@ -3214,6 +3641,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
3214
3641
  const [contextStep, setContextStep] = useState({ step: "root", direct: false });
3215
3642
  const [createKey, setCreateKey] = useState(null);
3216
3643
  const mobile = useMedia(MOBILE, false);
3644
+ useViewportInsets(mobile);
3217
3645
  const [moreView, setMoreView] = useMoreView();
3218
3646
  if (!store.get().seeded) store.set({ open: shell.preferences.helpOpen, restored: shell.preferences.helpOpen, seeded: true });
3219
3647
  const serverPreferences = JSON.stringify(shell.preferences);
@@ -3357,7 +3785,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
3357
3785
  ] }),
3358
3786
  /* @__PURE__ */ jsxs("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children: [
3359
3787
  moreOpen && /* @__PURE__ */ jsx(MoreScreen, { view: moreView, setView: setMoreView }),
3360
- /* @__PURE__ */ jsx("div", { className: "cbx-m-page", hidden: moreOpen, children })
3788
+ /* @__PURE__ */ jsx(MobilePage, { hidden: moreOpen, children })
3361
3789
  ] })
3362
3790
  ] }),
3363
3791
  /* @__PURE__ */ jsx(
@@ -3873,7 +4301,7 @@ function Combobox(props) {
3873
4301
  onChange: (e) => setQuery(e.target.value),
3874
4302
  onKeyDown,
3875
4303
  placeholder: searchPlaceholder,
3876
- className: "h-8 w-full rounded-sm border-0 bg-transparent pl-7 pr-2 text-[13px] outline-none placeholder:text-muted-foreground/70",
4304
+ className: "h-8 w-full rounded-sm border-0 bg-transparent pl-7 pr-2 text-base outline-none placeholder:text-muted-foreground/70 md:text-[13px]",
3877
4305
  "aria-controls": listId,
3878
4306
  "aria-autocomplete": "list",
3879
4307
  "aria-activedescendant": highlightIndex >= 0 ? `${listId}-${highlightIndex}` : void 0
@@ -4333,6 +4761,8 @@ function PageHeader({
4333
4761
  }) {
4334
4762
  const { t } = useCboxLocalization();
4335
4763
  const shellHelp = useShellHelp();
4764
+ const shellTitle = useShellPageTitle();
4765
+ const duplicate = shellTitle !== null && typeof title === "string" && sameTitle(title, shellTitle);
4336
4766
  return /* @__PURE__ */ jsxs(
4337
4767
  "header",
4338
4768
  {
@@ -4343,7 +4773,7 @@ function PageHeader({
4343
4773
  children: [
4344
4774
  /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
4345
4775
  eyebrow !== void 0 ? /* @__PURE__ */ jsx("p", { className: "text-mono text-[10px] font-semibold tracking-[0.18em] text-muted-foreground uppercase", children: eyebrow }) : null,
4346
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
4776
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-cbx-same-title": duplicate ? "" : void 0, children: [
4347
4777
  /* @__PURE__ */ jsx("h1", { className: "text-2xl leading-tight font-semibold tracking-tight text-foreground", children: title }),
4348
4778
  help && shellHelp !== null ? /* @__PURE__ */ jsx(
4349
4779
  "button",
@@ -5274,6 +5704,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
5274
5704
  ] });
5275
5705
  }
5276
5706
 
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 };
5707
+ export { APP_HUES, AppContent, AppShell, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, EmptyState, Heading, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RowLink, SHELL_ICONS, SectionHeader, Sparkline, StatTile, StatusPill, applyTheme, buildUrlSearch, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useKnownAppCatalog, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
5278
5708
  //# sourceMappingURL=index.js.map
5279
5709
  //# sourceMappingURL=index.js.map