@cboxdk/cbox-ui 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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,349 @@ 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
+ function reducedMotion() {
1675
+ return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1676
+ }
1677
+ function visibleHeight() {
1678
+ return Math.round(window.visualViewport?.height ?? window.innerHeight);
1679
+ }
1680
+ function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
1681
+ const close = useRef(onClose);
1682
+ close.current = onClose;
1683
+ useEffect(() => {
1684
+ const sheet = panel.current;
1685
+ if (!enabled || sheet === null || typeof window === "undefined") return;
1686
+ let gesture = null;
1687
+ let natural = null;
1688
+ let closing = false;
1689
+ let timer;
1690
+ const scrollerOf = (target) => {
1691
+ for (let node = target; node !== null && node !== sheet; node = node.parentElement) {
1692
+ const overflow = getComputedStyle(node).overflowY;
1693
+ if ((overflow === "auto" || overflow === "scroll") && node instanceof HTMLElement) return node;
1694
+ }
1695
+ return null;
1696
+ };
1697
+ const contentHeight = () => {
1698
+ const body = sheet.querySelector("[data-cbx-sheet-scroll]");
1699
+ if (body === null) return sheet.offsetHeight;
1700
+ return sheet.offsetHeight - body.clientHeight + body.scrollHeight;
1701
+ };
1702
+ const setScrim = (fraction) => {
1703
+ if (scrim?.current) {
1704
+ if (fraction >= 1) scrim.current.style.removeProperty("--cbx-scrim");
1705
+ else scrim.current.style.setProperty("--cbx-scrim", String(Math.max(0, Math.min(1, fraction))));
1706
+ }
1707
+ };
1708
+ const animate = (on) => {
1709
+ const smooth = on && !reducedMotion();
1710
+ sheet.style.transition = smooth ? `height ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : "none";
1711
+ if (scrim?.current) scrim.current.style.transition = smooth ? `--cbx-scrim ${DURATION}ms ${EASE}` : "none";
1712
+ };
1713
+ const place2 = (height, detents) => {
1714
+ const smallest = detents[0];
1715
+ const largest = detents[detents.length - 1];
1716
+ let shown = height;
1717
+ let drop = 0;
1718
+ if (height > largest) shown = largest + rubberBand(height - largest);
1719
+ else if (height < smallest) {
1720
+ shown = smallest;
1721
+ drop = smallest - height;
1722
+ }
1723
+ sheet.style.maxHeight = "none";
1724
+ sheet.style.height = `${Math.round(shown)}px`;
1725
+ sheet.style.transform = drop > 0 ? `translateY(${Math.round(drop)}px)` : "";
1726
+ setScrim(drop > 0 ? 1 - drop / smallest : 1);
1727
+ sheet.dataset.cbxDragging = "true";
1728
+ };
1729
+ const begin = (event) => {
1730
+ if (gesture !== null) finish(gesture.last, event.timeStamp);
1731
+ if (closing) return;
1732
+ if (event.pointerType === "mouse" && event.button !== 0) return;
1733
+ const target = event.target instanceof Element ? event.target : null;
1734
+ if (target === null || target.closest(NO_DRAG) !== null) return;
1735
+ const zone = target.closest(".cbx-sheet-grab") !== null ? "grab" : "content";
1736
+ gesture = { id: event.pointerId, x: event.clientX, y: event.clientY, zone, scroller: scrollerOf(target), mode: void 0, last: event.clientY, start: 0, detents: [], tracker: new VelocityTracker() };
1737
+ gesture.tracker.add(event.timeStamp, event.clientY);
1738
+ window.addEventListener("pointermove", move);
1739
+ window.addEventListener("pointerup", end);
1740
+ window.addEventListener("pointercancel", end);
1741
+ };
1742
+ const canGrow = () => {
1743
+ const current = sheet.getBoundingClientRect().height;
1744
+ const detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1745
+ return current < detents[detents.length - 1] - 1;
1746
+ };
1747
+ const decide = (dx, dy) => {
1748
+ if (gesture === null) return void 0;
1749
+ if (gesture.mode !== void 0) return gesture.mode;
1750
+ const mode = dragIntent({ zone: gesture.zone, dx, dy, scrollTop: gesture.scroller?.scrollTop ?? 0, canGrow: gesture.zone === "content" && dy < 0 ? canGrow() : false });
1751
+ if (mode === "drag") {
1752
+ clearTimeout(timer);
1753
+ const current = sheet.getBoundingClientRect().height;
1754
+ if (natural === null && sheet.style.height === "") natural = Math.round(current);
1755
+ gesture.start = current;
1756
+ gesture.detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
1757
+ animate(false);
1758
+ try {
1759
+ sheet.setPointerCapture(gesture.id);
1760
+ } catch {
1761
+ }
1762
+ }
1763
+ gesture.mode = mode;
1764
+ return mode;
1765
+ };
1766
+ const move = (event) => {
1767
+ if (gesture === null || event.pointerId !== gesture.id) return;
1768
+ const dx = event.clientX - gesture.x;
1769
+ const dy = event.clientY - gesture.y;
1770
+ if (decide(dx, dy) !== "drag") return;
1771
+ gesture.last = event.clientY;
1772
+ gesture.tracker.add(event.timeStamp, event.clientY);
1773
+ place2(gesture.start - dy, gesture.detents);
1774
+ };
1775
+ const end = (event) => {
1776
+ if (gesture === null || event.pointerId !== gesture.id) return;
1777
+ finish(event.type === "pointerup" ? event.clientY : gesture.last, event.timeStamp);
1778
+ };
1779
+ const finish = (y, at) => {
1780
+ const done = gesture;
1781
+ gesture = null;
1782
+ unfollow();
1783
+ if (done === null || done.mode !== "drag") return;
1784
+ done.tracker.add(at, y);
1785
+ delete sheet.dataset.cbxDragging;
1786
+ const height = done.start - (y - done.y);
1787
+ const result = settleSheet({ height, velocity: done.tracker.velocity(), detents: done.detents });
1788
+ const swallow = (click) => {
1789
+ click.preventDefault();
1790
+ click.stopPropagation();
1791
+ };
1792
+ sheet.addEventListener("click", swallow, { capture: true, once: true });
1793
+ setTimeout(() => sheet.removeEventListener("click", swallow, { capture: true }), 350);
1794
+ animate(true);
1795
+ if (result.close) {
1796
+ closing = true;
1797
+ sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
1798
+ setScrim(0);
1799
+ timer = setTimeout(() => close.current(), reducedMotion() ? 0 : DURATION - 40);
1800
+ return;
1801
+ }
1802
+ if (natural !== null && result.height === natural) {
1803
+ sheet.style.height = `${natural}px`;
1804
+ sheet.style.transform = "";
1805
+ setScrim(1);
1806
+ timer = setTimeout(() => {
1807
+ sheet.style.height = "";
1808
+ sheet.style.maxHeight = "";
1809
+ sheet.style.transition = "";
1810
+ natural = null;
1811
+ }, reducedMotion() ? 0 : DURATION);
1812
+ return;
1813
+ }
1814
+ sheet.style.height = `${result.height}px`;
1815
+ sheet.style.transform = "";
1816
+ setScrim(1);
1817
+ };
1818
+ const touchMove = (event) => {
1819
+ if (gesture === null || event.touches.length > 1) return;
1820
+ const touch = event.touches[0];
1821
+ const mode = decide(touch.clientX - gesture.x, touch.clientY - gesture.y);
1822
+ if (mode === "drag" && event.cancelable) event.preventDefault();
1823
+ };
1824
+ const unfollow = () => {
1825
+ window.removeEventListener("pointermove", move);
1826
+ window.removeEventListener("pointerup", end);
1827
+ window.removeEventListener("pointercancel", end);
1828
+ };
1829
+ sheet.addEventListener("pointerdown", begin);
1830
+ sheet.addEventListener("touchmove", touchMove, { passive: false });
1831
+ return () => {
1832
+ clearTimeout(timer);
1833
+ unfollow();
1834
+ sheet.removeEventListener("pointerdown", begin);
1835
+ sheet.removeEventListener("touchmove", touchMove);
1836
+ for (const property of ["height", "maxHeight", "transform", "transition"]) sheet.style[property] = "";
1837
+ delete sheet.dataset.cbxDragging;
1838
+ if (scrim?.current) {
1839
+ scrim.current.style.removeProperty("--cbx-scrim");
1840
+ scrim.current.style.transition = "";
1841
+ }
1842
+ };
1843
+ }, [panel, scrim, size, enabled]);
1844
+ }
1845
+ function scrimHandlers(onClose) {
1846
+ return {
1847
+ onPointerDown: (event) => {
1848
+ event.currentTarget.dataset.cbxPressed = event.target === event.currentTarget ? "true" : "false";
1849
+ },
1850
+ onClick: (event) => {
1851
+ const pressed = event.currentTarget.dataset.cbxPressed === "true";
1852
+ delete event.currentTarget.dataset.cbxPressed;
1853
+ if (pressed && event.target === event.currentTarget) onClose();
1854
+ }
1855
+ };
1856
+ }
1505
1857
  var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
1506
1858
  var SUPPORT_TAG = "cbox-support";
1507
1859
  function useHelpState(store, select) {
@@ -1572,7 +1924,11 @@ function HelpColumn({ docked, mobile = false }) {
1572
1924
  const chatHost = useRef(null);
1573
1925
  const searchField = useRef(null);
1574
1926
  const opener = useRef(null);
1927
+ const scrim = useRef(null);
1575
1928
  const { help } = shell;
1929
+ useScrollLock(mobile && open);
1930
+ const closeSheet = useCallback(() => toggleHelp(false), [toggleHelp]);
1931
+ useSheetDrag({ panel: column, scrim, size: "tall", onClose: closeSheet, enabled: mobile && open });
1576
1932
  const portal = help.portalUrl;
1577
1933
  const updatesKey = help.enabled && help.updatesUrl !== void 0 ? `${help.updatesUrl}|${shell.context.levels[0]?.current.id ?? ""}` : null;
1578
1934
  const loadUpdates = useCallback(() => {
@@ -1670,7 +2026,7 @@ function HelpColumn({ docked, mobile = false }) {
1670
2026
  const active = document.activeElement;
1671
2027
  if (active === null || active === document.body || column.current?.contains(active)) {
1672
2028
  const back = opener.current?.isConnected ? opener.current : document.querySelector('[aria-controls="cbx-help"]');
1673
- back?.focus();
2029
+ back?.focus({ preventScroll: true });
1674
2030
  }
1675
2031
  opener.current = null;
1676
2032
  return;
@@ -1709,9 +2065,7 @@ function HelpColumn({ docked, mobile = false }) {
1709
2065
  const where = shell.context.levels.map((level) => level.current.name).join(" \xB7 ");
1710
2066
  const chatReady = help.enabled && help.sessionUrl !== void 0;
1711
2067
  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(
2068
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", hidden: !open, ...scrimHandlers(close), children: /* @__PURE__ */ jsxs(
1715
2069
  "div",
1716
2070
  {
1717
2071
  ref: column,
@@ -1729,13 +2083,13 @@ function HelpColumn({ docked, mobile = false }) {
1729
2083
  trapTab(event, column.current);
1730
2084
  },
1731
2085
  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: [
2086
+ /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2087
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head cbx-sheet-grab ${article !== null ? "has-back" : ""}`, children: [
1734
2088
  article !== null && /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-sheet-back", onClick: () => store.set({ article: null }), "aria-label": t("Back to Help"), children: /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }) }),
1735
2089
  /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: article !== null ? t("Article") : t("Help with {page}", { page: topic }) }),
1736
2090
  /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: close, "aria-label": t("Close Help"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
1737
2091
  ] }),
1738
- /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
2092
+ /* @__PURE__ */ jsxs("div", { ref: body, className: "cbx-sheet-body", "data-cbx-sheet-scroll": "", onScroll: (event) => store.set({ scrollTop: event.currentTarget.scrollTop }), children: [
1739
2093
  article !== null ? /* @__PURE__ */ jsxs("article", { className: "cbx-help-article", children: [
1740
2094
  /* @__PURE__ */ jsx("h2", { className: "cbx-help-article-title", children: article.title }),
1741
2095
  (article.body ?? article.excerpt ?? "").split(/\n{2,}/).filter(Boolean).map((paragraph, index) => /* @__PURE__ */ jsx("p", { children: paragraph }, index)),
@@ -2096,14 +2450,17 @@ function CommandPalette({ onClose }) {
2096
2450
  const [activeKey, setActiveKey] = useState(null);
2097
2451
  const field = useRef(null);
2098
2452
  const dialog = useRef(null);
2453
+ const scrim = useRef(null);
2099
2454
  const id = useId();
2455
+ useScrollLock();
2456
+ useSheetDrag({ panel: dialog, scrim, size: "full", onClose, enabled: mobile });
2100
2457
  const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2101
2458
  useEffect(() => {
2102
2459
  if (canAutofocus()) field.current?.focus();
2103
2460
  else dialog.current?.focus();
2104
2461
  const back = opener.current;
2105
2462
  return () => {
2106
- if (back instanceof HTMLElement) back.focus();
2463
+ if (back instanceof HTMLElement) back.focus({ preventScroll: true });
2107
2464
  };
2108
2465
  }, []);
2109
2466
  useEffect(() => {
@@ -2415,11 +2772,9 @@ function CommandPalette({ onClose }) {
2415
2772
  { value: "pages", label: t("Pages") },
2416
2773
  { value: "help", label: t("Help") }
2417
2774
  ];
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: [
2775
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: `cbx-overlay cbx-palette-backdrop ${mobile ? "is-sheet" : ""}`, ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs("div", { ref: dialog, className: `cbx-palette ${mobile ? "is-sheet" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": t("Search"), tabIndex: -1, onKeyDown, children: [
2776
+ mobile && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2777
+ /* @__PURE__ */ jsxs("div", { className: `cbx-palette-search ${mobile ? "cbx-sheet-grab" : ""}`, children: [
2423
2778
  /* @__PURE__ */ jsxs("label", { className: "cbx-palette-field", children: [
2424
2779
  /* @__PURE__ */ jsx(Search, { size: 18, strokeWidth: 1.8, "aria-hidden": true }),
2425
2780
  /* @__PURE__ */ jsx(
@@ -2444,7 +2799,7 @@ function CommandPalette({ onClose }) {
2444
2799
  mobile ? /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-palette-cancel", onClick: onClose, children: t("Cancel") }) : /* @__PURE__ */ jsx("kbd", { className: "cbx-kbd", children: "Esc" })
2445
2800
  ] }),
2446
2801
  /* @__PURE__ */ jsx("div", { className: "cbx-scopes", role: "radiogroup", "aria-label": t("Scope"), children: scopes.map((item) => /* @__PURE__ */ jsx("button", { type: "button", role: "radio", "aria-checked": scope === item.value, className: `cbx-scope ${scope === item.value ? "is-on" : ""}`, onClick: () => setScope(item.value), children: item.label }, item.value)) }),
2447
- /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", children: [
2802
+ /* @__PURE__ */ jsxs("div", { id: `${id}-list`, role: "listbox", "aria-label": t("Results"), className: "cbx-palette-list", "data-cbx-sheet-scroll": "", children: [
2448
2803
  rendered.map((section) => {
2449
2804
  const loading = section.state.status === "loading" && section.state.items.length === 0;
2450
2805
  if (section.count === 0 && !loading) return null;
@@ -2518,17 +2873,18 @@ function Sheet({
2518
2873
  }) {
2519
2874
  const { t } = useShell();
2520
2875
  const panel = useRef(null);
2876
+ const scrim = useRef(null);
2877
+ useScrollLock();
2878
+ useSheetDrag({ panel, scrim, size: size ?? "fit", onClose, enabled: side === "bottom" });
2521
2879
  const opener = useRef(typeof document !== "undefined" ? document.activeElement : null);
2522
2880
  useEffect(() => {
2523
2881
  panel.current?.focus();
2524
2882
  const restore = opener.current;
2525
2883
  return () => {
2526
- if (restore instanceof HTMLElement && restore.isConnected) restore.focus();
2884
+ if (restore instanceof HTMLElement && restore.isConnected) restore.focus({ preventScroll: true });
2527
2885
  };
2528
2886
  }, []);
2529
- return /* @__PURE__ */ jsx("div", { className: "cbx-overlay cbx-sheet-backdrop", onPointerDown: (event) => {
2530
- if (event.target === event.currentTarget) onClose();
2531
- }, children: /* @__PURE__ */ jsxs(
2887
+ return /* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-overlay cbx-sheet-backdrop", ...scrimHandlers(onClose), children: /* @__PURE__ */ jsxs(
2532
2888
  "div",
2533
2889
  {
2534
2890
  ref: panel,
@@ -2545,8 +2901,8 @@ function Sheet({
2545
2901
  trapTab(event, panel.current);
2546
2902
  },
2547
2903
  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: [
2904
+ side === "bottom" && /* @__PURE__ */ jsx("div", { className: "cbx-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
2905
+ /* @__PURE__ */ jsxs("div", { className: `cbx-sheet-head ${side === "bottom" ? "cbx-sheet-grab" : ""} ${back !== void 0 ? "has-back" : ""}`, children: [
2550
2906
  back !== void 0 && /* @__PURE__ */ jsxs("button", { type: "button", className: "cbx-sheet-back", onClick: back.onBack, "aria-label": back.label, children: [
2551
2907
  /* @__PURE__ */ jsx(ChevronLeft, { size: 20, strokeWidth: 1.8, "aria-hidden": true }),
2552
2908
  back.text !== void 0 && /* @__PURE__ */ jsx("span", { children: back.text })
@@ -2554,7 +2910,7 @@ function Sheet({
2554
2910
  /* @__PURE__ */ jsx("strong", { className: "cbx-sheet-title cbx-truncate", children: title ?? label }),
2555
2911
  /* @__PURE__ */ jsx("button", { type: "button", className: "cbx-icon-button", onClick: onClose, "aria-label": t("Close"), children: /* @__PURE__ */ jsx(X, { size: 18, strokeWidth: 1.8, "aria-hidden": true }) })
2556
2912
  ] }),
2557
- /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, children })
2913
+ /* @__PURE__ */ jsx("div", { className: `cbx-sheet-body ${bodyClassName ?? ""}`, "data-cbx-sheet-scroll": "", children })
2558
2914
  ]
2559
2915
  }
2560
2916
  ) });
@@ -3180,6 +3536,76 @@ function AppsSheet({ onClose }) {
3180
3536
  const { t } = useShell();
3181
3537
  return /* @__PURE__ */ jsx(Sheet, { label: t("Switch app"), onClose, children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false }) });
3182
3538
  }
3539
+ function MobilePage({ hidden, children }) {
3540
+ const box = useRef(null);
3541
+ const title = useShellPageTitle();
3542
+ useEffect(() => {
3543
+ const page = box.current;
3544
+ if (page === null) return;
3545
+ const mark = () => {
3546
+ for (const heading of page.querySelectorAll("[data-cbx-page-title]")) {
3547
+ const same = title !== null && sameTitle(heading.textContent ?? "", title);
3548
+ if (same !== heading.hasAttribute("data-cbx-same-title")) heading.toggleAttribute("data-cbx-same-title", same);
3549
+ }
3550
+ };
3551
+ mark();
3552
+ if (typeof MutationObserver === "undefined") return;
3553
+ const observer = new MutationObserver(mark);
3554
+ observer.observe(page, { childList: true, subtree: true, characterData: true });
3555
+ return () => observer.disconnect();
3556
+ }, [title]);
3557
+ return /* @__PURE__ */ jsx("div", { ref: box, className: "cbx-m-page", hidden, children });
3558
+ }
3559
+ function keyboardInset({ innerHeight, viewportHeight, offsetTop }) {
3560
+ return Math.max(0, Math.round(innerHeight - viewportHeight - offsetTop));
3561
+ }
3562
+ var EDITABLE = 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="range"]), textarea, select, [contenteditable]';
3563
+ function useViewportInsets(enabled) {
3564
+ useEffect(() => {
3565
+ if (!enabled || typeof window === "undefined") return;
3566
+ const html = document.documentElement;
3567
+ const viewport = window.visualViewport;
3568
+ let tallest = window.innerHeight;
3569
+ let width = window.innerWidth;
3570
+ let frame = 0;
3571
+ const update = () => {
3572
+ frame = 0;
3573
+ if (window.innerWidth !== width) {
3574
+ width = window.innerWidth;
3575
+ tallest = window.innerHeight;
3576
+ }
3577
+ tallest = Math.max(tallest, window.innerHeight);
3578
+ const visible = viewport?.height ?? window.innerHeight;
3579
+ const inset = keyboardInset({ innerHeight: window.innerHeight, viewportHeight: visible, offsetTop: viewport?.offsetTop ?? 0 });
3580
+ html.style.setProperty("--cbx-keyboard", `${inset}px`);
3581
+ html.style.setProperty("--cbx-vvh", `${Math.round(visible)}px`);
3582
+ const typing = document.activeElement instanceof Element && document.activeElement.matches(EDITABLE);
3583
+ const shrunk = tallest - visible > 120;
3584
+ if (typing && (inset > 120 || shrunk)) html.setAttribute("data-cbx-keyboard", "");
3585
+ else html.removeAttribute("data-cbx-keyboard");
3586
+ };
3587
+ const schedule = () => {
3588
+ if (frame === 0) frame = requestAnimationFrame(update);
3589
+ };
3590
+ update();
3591
+ viewport?.addEventListener("resize", schedule);
3592
+ viewport?.addEventListener("scroll", schedule);
3593
+ window.addEventListener("resize", schedule);
3594
+ document.addEventListener("focusin", schedule);
3595
+ document.addEventListener("focusout", schedule);
3596
+ return () => {
3597
+ cancelAnimationFrame(frame);
3598
+ viewport?.removeEventListener("resize", schedule);
3599
+ viewport?.removeEventListener("scroll", schedule);
3600
+ window.removeEventListener("resize", schedule);
3601
+ document.removeEventListener("focusin", schedule);
3602
+ document.removeEventListener("focusout", schedule);
3603
+ html.style.removeProperty("--cbx-keyboard");
3604
+ html.style.removeProperty("--cbx-vvh");
3605
+ html.removeAttribute("data-cbx-keyboard");
3606
+ };
3607
+ }, [enabled]);
3608
+ }
3183
3609
  var PlainLink = ({ href, children, ...props }) => /* @__PURE__ */ jsx("a", { href, ...props, children });
3184
3610
  function writeCookie(key, value) {
3185
3611
  if (typeof document === "undefined") return;
@@ -3214,6 +3640,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
3214
3640
  const [contextStep, setContextStep] = useState({ step: "root", direct: false });
3215
3641
  const [createKey, setCreateKey] = useState(null);
3216
3642
  const mobile = useMedia(MOBILE, false);
3643
+ useViewportInsets(mobile);
3217
3644
  const [moreView, setMoreView] = useMoreView();
3218
3645
  if (!store.get().seeded) store.set({ open: shell.preferences.helpOpen, restored: shell.preferences.helpOpen, seeded: true });
3219
3646
  const serverPreferences = JSON.stringify(shell.preferences);
@@ -3357,7 +3784,7 @@ function CboxShell({ shell, children, navigate = defaultNavigate, LinkComponent
3357
3784
  ] }),
3358
3785
  /* @__PURE__ */ jsxs("main", { id: mainId, tabIndex: -1, className: "cbx-shell-main canvas-gradient", children: [
3359
3786
  moreOpen && /* @__PURE__ */ jsx(MoreScreen, { view: moreView, setView: setMoreView }),
3360
- /* @__PURE__ */ jsx("div", { className: "cbx-m-page", hidden: moreOpen, children })
3787
+ /* @__PURE__ */ jsx(MobilePage, { hidden: moreOpen, children })
3361
3788
  ] })
3362
3789
  ] }),
3363
3790
  /* @__PURE__ */ jsx(
@@ -4333,6 +4760,8 @@ function PageHeader({
4333
4760
  }) {
4334
4761
  const { t } = useCboxLocalization();
4335
4762
  const shellHelp = useShellHelp();
4763
+ const shellTitle = useShellPageTitle();
4764
+ const duplicate = shellTitle !== null && typeof title === "string" && sameTitle(title, shellTitle);
4336
4765
  return /* @__PURE__ */ jsxs(
4337
4766
  "header",
4338
4767
  {
@@ -4343,7 +4772,7 @@ function PageHeader({
4343
4772
  children: [
4344
4773
  /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
4345
4774
  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: [
4775
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-cbx-same-title": duplicate ? "" : void 0, children: [
4347
4776
  /* @__PURE__ */ jsx("h1", { className: "text-2xl leading-tight font-semibold tracking-tight text-foreground", children: title }),
4348
4777
  help && shellHelp !== null ? /* @__PURE__ */ jsx(
4349
4778
  "button",
@@ -5274,6 +5703,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
5274
5703
  ] });
5275
5704
  }
5276
5705
 
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 };
5706
+ export { APP_HUES, AppContent, AppShell, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, EmptyState, Heading, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RowLink, SHELL_ICONS, SectionHeader, Sparkline, StatTile, StatusPill, applyTheme, buildUrlSearch, contextTrail, createHelpStore, defineUrlSchema, environmentFor, groupItems, hueFor, initialsOf, interpolate, isLive, pageIntent, parseListPage, parseShellCatalog, parseUrlSearch, quickEnvironments, settingsHref, switchBody, switchPayload, themeBootScript, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useKnownAppCatalog, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
5278
5707
  //# sourceMappingURL=index.js.map
5279
5708
  //# sourceMappingURL=index.js.map