@cboxdk/cbox-ui 0.13.0 → 0.14.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/README.md +3 -3
- package/dist/index.d.ts +24 -13
- package/dist/index.js +284 -264
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/tokens/controls.css +43 -25
package/dist/index.js
CHANGED
|
@@ -1487,6 +1487,248 @@ function useScrollLock(active = true) {
|
|
|
1487
1487
|
return lockScroll();
|
|
1488
1488
|
}, [active]);
|
|
1489
1489
|
}
|
|
1490
|
+
var LARGE = 0.92;
|
|
1491
|
+
var MEDIUM = 0.5;
|
|
1492
|
+
function sheetDetents({ size, viewport, current, content }) {
|
|
1493
|
+
const large = Math.round(viewport * LARGE);
|
|
1494
|
+
const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
|
|
1495
|
+
const sorted = heights.map(Math.round).sort((a, b) => a - b);
|
|
1496
|
+
const detents = [];
|
|
1497
|
+
for (const height of sorted) {
|
|
1498
|
+
const last = detents[detents.length - 1];
|
|
1499
|
+
if (last === void 0 || height - last >= 48) detents.push(height);
|
|
1500
|
+
else if (height === Math.round(current)) detents[detents.length - 1] = height;
|
|
1501
|
+
}
|
|
1502
|
+
return detents;
|
|
1503
|
+
}
|
|
1504
|
+
function rubberBand(overshoot, limit = 120) {
|
|
1505
|
+
if (overshoot <= 0) return 0;
|
|
1506
|
+
return limit * (1 - 1 / (overshoot / limit + 1));
|
|
1507
|
+
}
|
|
1508
|
+
function settleSheet({ height, velocity, detents }) {
|
|
1509
|
+
const smallest = detents[0] ?? height;
|
|
1510
|
+
const below = smallest - height;
|
|
1511
|
+
if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
|
|
1512
|
+
const projected = height - velocity * 200;
|
|
1513
|
+
let best = smallest;
|
|
1514
|
+
for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
|
|
1515
|
+
return { close: false, height: best };
|
|
1516
|
+
}
|
|
1517
|
+
var VelocityTracker = class {
|
|
1518
|
+
samples = [];
|
|
1519
|
+
add(t, y) {
|
|
1520
|
+
this.samples.push({ t, y });
|
|
1521
|
+
while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
|
|
1522
|
+
}
|
|
1523
|
+
velocity() {
|
|
1524
|
+
const first = this.samples[0];
|
|
1525
|
+
const last = this.samples[this.samples.length - 1];
|
|
1526
|
+
if (first === void 0 || last === void 0 || last.t === first.t) return 0;
|
|
1527
|
+
return (last.y - first.y) / (last.t - first.t);
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
|
|
1531
|
+
if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
|
|
1532
|
+
if (Math.abs(dx) > Math.abs(dy)) return "scroll";
|
|
1533
|
+
if (zone === "grab") return "drag";
|
|
1534
|
+
if (dy > 0 && scrollTop <= 0) return "drag";
|
|
1535
|
+
if (dy < 0 && canGrow) return "drag";
|
|
1536
|
+
return "scroll";
|
|
1537
|
+
}
|
|
1538
|
+
var EASE = "cubic-bezier(.2, .9, .25, 1)";
|
|
1539
|
+
var DURATION = 280;
|
|
1540
|
+
var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
|
|
1541
|
+
var GRAB_FIELD = '.cbx-sheet-grab :is(input[type="search"], input[type="text"], input:not([type]))';
|
|
1542
|
+
function reducedMotion() {
|
|
1543
|
+
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1544
|
+
}
|
|
1545
|
+
function visibleHeight() {
|
|
1546
|
+
return Math.round(window.visualViewport?.height ?? window.innerHeight);
|
|
1547
|
+
}
|
|
1548
|
+
function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
|
|
1549
|
+
const close = useRef(onClose);
|
|
1550
|
+
close.current = onClose;
|
|
1551
|
+
useEffect(() => {
|
|
1552
|
+
const sheet = panel.current;
|
|
1553
|
+
if (!enabled || sheet === null || typeof window === "undefined") return;
|
|
1554
|
+
let gesture = null;
|
|
1555
|
+
let natural = null;
|
|
1556
|
+
let closing = false;
|
|
1557
|
+
let timer;
|
|
1558
|
+
const scrollerOf = (target) => {
|
|
1559
|
+
for (let node = target; node !== null && node !== sheet; node = node.parentElement) {
|
|
1560
|
+
const overflow = getComputedStyle(node).overflowY;
|
|
1561
|
+
if ((overflow === "auto" || overflow === "scroll") && node instanceof HTMLElement) return node;
|
|
1562
|
+
}
|
|
1563
|
+
return null;
|
|
1564
|
+
};
|
|
1565
|
+
const contentHeight = () => {
|
|
1566
|
+
const body = sheet.querySelector("[data-cbx-sheet-scroll]");
|
|
1567
|
+
if (body === null) return sheet.offsetHeight;
|
|
1568
|
+
return sheet.offsetHeight - body.clientHeight + body.scrollHeight;
|
|
1569
|
+
};
|
|
1570
|
+
const setScrim = (fraction) => {
|
|
1571
|
+
if (scrim?.current) {
|
|
1572
|
+
if (fraction >= 1) scrim.current.style.removeProperty("--cbx-scrim");
|
|
1573
|
+
else scrim.current.style.setProperty("--cbx-scrim", String(Math.max(0, Math.min(1, fraction))));
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
const animate = (on) => {
|
|
1577
|
+
const smooth = on && !reducedMotion();
|
|
1578
|
+
sheet.style.transition = smooth ? `height ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : "none";
|
|
1579
|
+
if (scrim?.current) scrim.current.style.transition = smooth ? `--cbx-scrim ${DURATION}ms ${EASE}` : "none";
|
|
1580
|
+
};
|
|
1581
|
+
const place2 = (height, detents) => {
|
|
1582
|
+
const smallest = detents[0];
|
|
1583
|
+
const largest = detents[detents.length - 1];
|
|
1584
|
+
let shown = height;
|
|
1585
|
+
let drop = 0;
|
|
1586
|
+
if (height > largest) shown = largest + rubberBand(height - largest);
|
|
1587
|
+
else if (height < smallest) {
|
|
1588
|
+
shown = smallest;
|
|
1589
|
+
drop = smallest - height;
|
|
1590
|
+
}
|
|
1591
|
+
sheet.style.maxHeight = "none";
|
|
1592
|
+
sheet.style.height = `${Math.round(shown)}px`;
|
|
1593
|
+
sheet.style.transform = drop > 0 ? `translateY(${Math.round(drop)}px)` : "";
|
|
1594
|
+
setScrim(drop > 0 ? 1 - drop / smallest : 1);
|
|
1595
|
+
sheet.dataset.cbxDragging = "true";
|
|
1596
|
+
};
|
|
1597
|
+
const begin = (event) => {
|
|
1598
|
+
if (gesture !== null) finish(gesture.last, event.timeStamp);
|
|
1599
|
+
if (closing) return;
|
|
1600
|
+
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
1601
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
1602
|
+
if (target === null || target.closest(NO_DRAG) !== null && !target.matches(GRAB_FIELD)) return;
|
|
1603
|
+
const zone = target.closest(".cbx-sheet-grab") !== null ? "grab" : "content";
|
|
1604
|
+
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() };
|
|
1605
|
+
gesture.tracker.add(event.timeStamp, event.clientY);
|
|
1606
|
+
window.addEventListener("pointermove", move);
|
|
1607
|
+
window.addEventListener("pointerup", end);
|
|
1608
|
+
window.addEventListener("pointercancel", end);
|
|
1609
|
+
};
|
|
1610
|
+
const canGrow = () => {
|
|
1611
|
+
const current = sheet.getBoundingClientRect().height;
|
|
1612
|
+
const detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
|
|
1613
|
+
return current < detents[detents.length - 1] - 1;
|
|
1614
|
+
};
|
|
1615
|
+
const decide = (dx, dy) => {
|
|
1616
|
+
if (gesture === null) return void 0;
|
|
1617
|
+
if (gesture.mode !== void 0) return gesture.mode;
|
|
1618
|
+
const mode = dragIntent({ zone: gesture.zone, dx, dy, scrollTop: gesture.scroller?.scrollTop ?? 0, canGrow: gesture.zone === "content" && dy < 0 ? canGrow() : false });
|
|
1619
|
+
if (mode === "drag") {
|
|
1620
|
+
clearTimeout(timer);
|
|
1621
|
+
const current = sheet.getBoundingClientRect().height;
|
|
1622
|
+
if (natural === null && sheet.style.height === "") natural = Math.round(current);
|
|
1623
|
+
gesture.start = current;
|
|
1624
|
+
gesture.detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
|
|
1625
|
+
animate(false);
|
|
1626
|
+
try {
|
|
1627
|
+
sheet.setPointerCapture(gesture.id);
|
|
1628
|
+
} catch {
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
gesture.mode = mode;
|
|
1632
|
+
return mode;
|
|
1633
|
+
};
|
|
1634
|
+
const move = (event) => {
|
|
1635
|
+
if (gesture === null || event.pointerId !== gesture.id) return;
|
|
1636
|
+
const dx = event.clientX - gesture.x;
|
|
1637
|
+
const dy = event.clientY - gesture.y;
|
|
1638
|
+
if (decide(dx, dy) !== "drag") return;
|
|
1639
|
+
gesture.last = event.clientY;
|
|
1640
|
+
gesture.tracker.add(event.timeStamp, event.clientY);
|
|
1641
|
+
place2(gesture.start - dy, gesture.detents);
|
|
1642
|
+
};
|
|
1643
|
+
const end = (event) => {
|
|
1644
|
+
if (gesture === null || event.pointerId !== gesture.id) return;
|
|
1645
|
+
finish(event.type === "pointerup" ? event.clientY : gesture.last, event.timeStamp);
|
|
1646
|
+
};
|
|
1647
|
+
const finish = (y, at) => {
|
|
1648
|
+
const done = gesture;
|
|
1649
|
+
gesture = null;
|
|
1650
|
+
unfollow();
|
|
1651
|
+
if (done === null || done.mode !== "drag") return;
|
|
1652
|
+
done.tracker.add(at, y);
|
|
1653
|
+
delete sheet.dataset.cbxDragging;
|
|
1654
|
+
const height = done.start - (y - done.y);
|
|
1655
|
+
const result = settleSheet({ height, velocity: done.tracker.velocity(), detents: done.detents });
|
|
1656
|
+
const swallow = (click) => {
|
|
1657
|
+
click.preventDefault();
|
|
1658
|
+
click.stopPropagation();
|
|
1659
|
+
};
|
|
1660
|
+
sheet.addEventListener("click", swallow, { capture: true, once: true });
|
|
1661
|
+
setTimeout(() => sheet.removeEventListener("click", swallow, { capture: true }), 350);
|
|
1662
|
+
animate(true);
|
|
1663
|
+
if (result.close) {
|
|
1664
|
+
closing = true;
|
|
1665
|
+
sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
|
|
1666
|
+
setScrim(0);
|
|
1667
|
+
timer = setTimeout(() => {
|
|
1668
|
+
if (close.current() === false) {
|
|
1669
|
+
closing = false;
|
|
1670
|
+
sheet.style.height = `${done.start}px`;
|
|
1671
|
+
sheet.style.transform = "";
|
|
1672
|
+
setScrim(1);
|
|
1673
|
+
}
|
|
1674
|
+
}, reducedMotion() ? 0 : DURATION - 40);
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
if (natural !== null && result.height === natural) {
|
|
1678
|
+
sheet.style.height = `${natural}px`;
|
|
1679
|
+
sheet.style.transform = "";
|
|
1680
|
+
setScrim(1);
|
|
1681
|
+
timer = setTimeout(() => {
|
|
1682
|
+
sheet.style.height = "";
|
|
1683
|
+
sheet.style.maxHeight = "";
|
|
1684
|
+
sheet.style.transition = "";
|
|
1685
|
+
natural = null;
|
|
1686
|
+
}, reducedMotion() ? 0 : DURATION);
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
sheet.style.height = `${result.height}px`;
|
|
1690
|
+
sheet.style.transform = "";
|
|
1691
|
+
setScrim(1);
|
|
1692
|
+
};
|
|
1693
|
+
const touchMove = (event) => {
|
|
1694
|
+
if (gesture === null || event.touches.length > 1) return;
|
|
1695
|
+
const touch = event.touches[0];
|
|
1696
|
+
const mode = decide(touch.clientX - gesture.x, touch.clientY - gesture.y);
|
|
1697
|
+
if (mode === "drag" && event.cancelable) event.preventDefault();
|
|
1698
|
+
};
|
|
1699
|
+
const unfollow = () => {
|
|
1700
|
+
window.removeEventListener("pointermove", move);
|
|
1701
|
+
window.removeEventListener("pointerup", end);
|
|
1702
|
+
window.removeEventListener("pointercancel", end);
|
|
1703
|
+
};
|
|
1704
|
+
sheet.addEventListener("pointerdown", begin);
|
|
1705
|
+
sheet.addEventListener("touchmove", touchMove, { passive: false });
|
|
1706
|
+
return () => {
|
|
1707
|
+
clearTimeout(timer);
|
|
1708
|
+
unfollow();
|
|
1709
|
+
sheet.removeEventListener("pointerdown", begin);
|
|
1710
|
+
sheet.removeEventListener("touchmove", touchMove);
|
|
1711
|
+
for (const property of ["height", "maxHeight", "transform", "transition"]) sheet.style[property] = "";
|
|
1712
|
+
delete sheet.dataset.cbxDragging;
|
|
1713
|
+
if (scrim?.current) {
|
|
1714
|
+
scrim.current.style.removeProperty("--cbx-scrim");
|
|
1715
|
+
scrim.current.style.transition = "";
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
}, [panel, scrim, size, enabled]);
|
|
1719
|
+
}
|
|
1720
|
+
function scrimHandlers(onClose) {
|
|
1721
|
+
return {
|
|
1722
|
+
onPointerDown: (event) => {
|
|
1723
|
+
event.currentTarget.dataset.cbxPressed = event.target === event.currentTarget ? "true" : "false";
|
|
1724
|
+
},
|
|
1725
|
+
onClick: (event) => {
|
|
1726
|
+
const pressed = event.currentTarget.dataset.cbxPressed === "true";
|
|
1727
|
+
delete event.currentTarget.dataset.cbxPressed;
|
|
1728
|
+
if (pressed && event.target === event.currentTarget) onClose();
|
|
1729
|
+
}
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1490
1732
|
function Spinner({ className, label }) {
|
|
1491
1733
|
return /* @__PURE__ */ jsx(
|
|
1492
1734
|
"span",
|
|
@@ -1571,13 +1813,13 @@ function tabbables(root) {
|
|
|
1571
1813
|
return true;
|
|
1572
1814
|
});
|
|
1573
1815
|
}
|
|
1574
|
-
var
|
|
1575
|
-
function
|
|
1576
|
-
const close = useContext(
|
|
1816
|
+
var SheetContext = createContext(null);
|
|
1817
|
+
function useSheetClose() {
|
|
1818
|
+
const close = useContext(SheetContext);
|
|
1577
1819
|
return close ?? (() => void 0);
|
|
1578
1820
|
}
|
|
1579
|
-
function
|
|
1580
|
-
const close =
|
|
1821
|
+
function SheetClose({ onClick, ...props }) {
|
|
1822
|
+
const close = useSheetClose();
|
|
1581
1823
|
return /* @__PURE__ */ jsx(
|
|
1582
1824
|
Button,
|
|
1583
1825
|
{
|
|
@@ -1590,12 +1832,26 @@ function DialogClose({ onClick, ...props }) {
|
|
|
1590
1832
|
);
|
|
1591
1833
|
}
|
|
1592
1834
|
var useIsoLayoutEffect2 = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
1593
|
-
|
|
1835
|
+
var NARROW = "(max-width: 767.98px)";
|
|
1836
|
+
function useNarrow() {
|
|
1837
|
+
const [narrow, setNarrow] = useState(() => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(NARROW).matches);
|
|
1838
|
+
useEffect(() => {
|
|
1839
|
+
if (typeof window.matchMedia !== "function") return;
|
|
1840
|
+
const query2 = window.matchMedia(NARROW);
|
|
1841
|
+
const update = () => setNarrow(query2.matches);
|
|
1842
|
+
update();
|
|
1843
|
+
query2.addEventListener("change", update);
|
|
1844
|
+
return () => query2.removeEventListener("change", update);
|
|
1845
|
+
}, []);
|
|
1846
|
+
return narrow;
|
|
1847
|
+
}
|
|
1848
|
+
function Sheet({ open, onOpenChange, title, description, footer, size = "md", dismissible = true, className, children }) {
|
|
1594
1849
|
const { t } = useCboxLocalization();
|
|
1595
1850
|
const id = useId();
|
|
1596
1851
|
const titleId = `${id}-title`;
|
|
1597
1852
|
const descriptionId = `${id}-description`;
|
|
1598
1853
|
const layer = useRef(null);
|
|
1854
|
+
const scrim = useRef(null);
|
|
1599
1855
|
const panel = useRef(null);
|
|
1600
1856
|
const closeButton = useRef(null);
|
|
1601
1857
|
const body = useRef(null);
|
|
@@ -1608,7 +1864,9 @@ function Dialog({ open, onOpenChange, title, description, footer, size = "md", d
|
|
|
1608
1864
|
}
|
|
1609
1865
|
wasOpen.current = open;
|
|
1610
1866
|
const close = useCallback(() => onOpenChange(false), [onOpenChange]);
|
|
1867
|
+
const narrow = useNarrow();
|
|
1611
1868
|
useScrollLock(open);
|
|
1869
|
+
useSheetDrag({ panel, scrim, size: "fit", onClose: dismissible ? close : () => false, enabled: open && narrow });
|
|
1612
1870
|
useIsoLayoutEffect2(() => {
|
|
1613
1871
|
if (!open || layer.current === null) return;
|
|
1614
1872
|
const own = layer.current;
|
|
@@ -1685,8 +1943,8 @@ function Dialog({ open, onOpenChange, title, description, footer, size = "md", d
|
|
|
1685
1943
|
pressedOnScrim.current = false;
|
|
1686
1944
|
};
|
|
1687
1945
|
return createPortal(
|
|
1688
|
-
/* @__PURE__ */ jsx(
|
|
1689
|
-
/* @__PURE__ */ jsx("div", { className: "cbx-ui-overlay", "aria-hidden": "true", onMouseDown: onScrimDown, onClick: onScrimClick }),
|
|
1946
|
+
/* @__PURE__ */ jsx(SheetContext.Provider, { value: close, children: /* @__PURE__ */ jsxs("div", { ref: layer, "data-cbx-scroll-layer": "", "data-cbx-dialog-layer": "", children: [
|
|
1947
|
+
/* @__PURE__ */ jsx("div", { ref: scrim, className: "cbx-ui-overlay", "aria-hidden": "true", onMouseDown: onScrimDown, onClick: onScrimClick }),
|
|
1690
1948
|
/* @__PURE__ */ jsxs(
|
|
1691
1949
|
"div",
|
|
1692
1950
|
{
|
|
@@ -1696,18 +1954,19 @@ function Dialog({ open, onOpenChange, title, description, footer, size = "md", d
|
|
|
1696
1954
|
"aria-labelledby": titleId,
|
|
1697
1955
|
"aria-describedby": description !== void 0 ? descriptionId : void 0,
|
|
1698
1956
|
tabIndex: -1,
|
|
1699
|
-
className: cn("cbx-ui-
|
|
1957
|
+
className: cn("cbx-ui-sheet", `cbx-ui-sheet--${size}`, className),
|
|
1700
1958
|
onKeyDown,
|
|
1701
1959
|
children: [
|
|
1702
|
-
/* @__PURE__ */
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1960
|
+
/* @__PURE__ */ jsx("div", { className: "cbx-ui-sheet-handle cbx-sheet-grab", "aria-hidden": "true" }),
|
|
1961
|
+
/* @__PURE__ */ jsxs("div", { className: "cbx-ui-sheet-head cbx-sheet-grab", children: [
|
|
1962
|
+
/* @__PURE__ */ jsxs("div", { className: "cbx-ui-sheet-heading", children: [
|
|
1963
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, className: "cbx-ui-sheet-title", children: title }),
|
|
1964
|
+
description !== void 0 && /* @__PURE__ */ jsx("p", { id: descriptionId, className: "cbx-ui-sheet-desc", children: description })
|
|
1706
1965
|
] }),
|
|
1707
1966
|
/* @__PURE__ */ jsx("button", { ref: closeButton, type: "button", className: "cbx-ui-iconbtn", "aria-label": t("Close"), onClick: close, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) }) })
|
|
1708
1967
|
] }),
|
|
1709
|
-
children !== void 0 && children !== null && /* @__PURE__ */ jsx("div", { ref: body, className: "cbx-ui-
|
|
1710
|
-
footer !== void 0 && footer !== null && /* @__PURE__ */ jsx("div", { className: "cbx-ui-
|
|
1968
|
+
children !== void 0 && children !== null && /* @__PURE__ */ jsx("div", { ref: body, className: "cbx-ui-sheet-body", "data-cbx-sheet-scroll": "", children }),
|
|
1969
|
+
footer !== void 0 && footer !== null && /* @__PURE__ */ jsx("div", { className: "cbx-ui-sheet-foot", children: footer })
|
|
1711
1970
|
]
|
|
1712
1971
|
}
|
|
1713
1972
|
)
|
|
@@ -1715,6 +1974,9 @@ function Dialog({ open, onOpenChange, title, description, footer, size = "md", d
|
|
|
1715
1974
|
document.body
|
|
1716
1975
|
);
|
|
1717
1976
|
}
|
|
1977
|
+
var Dialog = Sheet;
|
|
1978
|
+
var DialogClose = SheetClose;
|
|
1979
|
+
var useDialogClose = useSheetClose;
|
|
1718
1980
|
var SHELL_ICONS = {
|
|
1719
1981
|
activity: Activity,
|
|
1720
1982
|
"bar-chart": BarChart3,
|
|
@@ -1843,248 +2105,6 @@ function parseArticles(body) {
|
|
|
1843
2105
|
return [article];
|
|
1844
2106
|
});
|
|
1845
2107
|
}
|
|
1846
|
-
var LARGE = 0.92;
|
|
1847
|
-
var MEDIUM = 0.5;
|
|
1848
|
-
function sheetDetents({ size, viewport, current, content }) {
|
|
1849
|
-
const large = Math.round(viewport * LARGE);
|
|
1850
|
-
const heights = size === "fit" ? [current, Math.min(Math.max(content, current), Math.max(large, current))] : [Math.round(viewport * MEDIUM), current];
|
|
1851
|
-
const sorted = heights.map(Math.round).sort((a, b) => a - b);
|
|
1852
|
-
const detents = [];
|
|
1853
|
-
for (const height of sorted) {
|
|
1854
|
-
const last = detents[detents.length - 1];
|
|
1855
|
-
if (last === void 0 || height - last >= 48) detents.push(height);
|
|
1856
|
-
else if (height === Math.round(current)) detents[detents.length - 1] = height;
|
|
1857
|
-
}
|
|
1858
|
-
return detents;
|
|
1859
|
-
}
|
|
1860
|
-
function rubberBand(overshoot, limit = 120) {
|
|
1861
|
-
if (overshoot <= 0) return 0;
|
|
1862
|
-
return limit * (1 - 1 / (overshoot / limit + 1));
|
|
1863
|
-
}
|
|
1864
|
-
function settleSheet({ height, velocity, detents }) {
|
|
1865
|
-
const smallest = detents[0] ?? height;
|
|
1866
|
-
const below = smallest - height;
|
|
1867
|
-
if (below > Math.min(160, smallest * 0.35) || below > 12 && velocity > 0.5) return { close: true };
|
|
1868
|
-
const projected = height - velocity * 200;
|
|
1869
|
-
let best = smallest;
|
|
1870
|
-
for (const detent of detents) if (Math.abs(detent - projected) < Math.abs(best - projected)) best = detent;
|
|
1871
|
-
return { close: false, height: best };
|
|
1872
|
-
}
|
|
1873
|
-
var VelocityTracker = class {
|
|
1874
|
-
samples = [];
|
|
1875
|
-
add(t, y) {
|
|
1876
|
-
this.samples.push({ t, y });
|
|
1877
|
-
while (this.samples.length > 2 && t - this.samples[0].t > 100) this.samples.shift();
|
|
1878
|
-
}
|
|
1879
|
-
velocity() {
|
|
1880
|
-
const first = this.samples[0];
|
|
1881
|
-
const last = this.samples[this.samples.length - 1];
|
|
1882
|
-
if (first === void 0 || last === void 0 || last.t === first.t) return 0;
|
|
1883
|
-
return (last.y - first.y) / (last.t - first.t);
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1886
|
-
function dragIntent({ zone, dx, dy, scrollTop, canGrow }) {
|
|
1887
|
-
if (Math.abs(dx) < 3 && Math.abs(dy) < 3) return void 0;
|
|
1888
|
-
if (Math.abs(dx) > Math.abs(dy)) return "scroll";
|
|
1889
|
-
if (zone === "grab") return "drag";
|
|
1890
|
-
if (dy > 0 && scrollTop <= 0) return "drag";
|
|
1891
|
-
if (dy < 0 && canGrow) return "drag";
|
|
1892
|
-
return "scroll";
|
|
1893
|
-
}
|
|
1894
|
-
var EASE = "cubic-bezier(.2, .9, .25, 1)";
|
|
1895
|
-
var DURATION = 280;
|
|
1896
|
-
var NO_DRAG = "input, textarea, select, [contenteditable], [data-no-drag]";
|
|
1897
|
-
var GRAB_FIELD = '.cbx-sheet-grab :is(input[type="search"], input[type="text"], input:not([type]))';
|
|
1898
|
-
function reducedMotion() {
|
|
1899
|
-
return typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1900
|
-
}
|
|
1901
|
-
function visibleHeight() {
|
|
1902
|
-
return Math.round(window.visualViewport?.height ?? window.innerHeight);
|
|
1903
|
-
}
|
|
1904
|
-
function useSheetDrag({ panel, scrim, size, onClose, enabled = true }) {
|
|
1905
|
-
const close = useRef(onClose);
|
|
1906
|
-
close.current = onClose;
|
|
1907
|
-
useEffect(() => {
|
|
1908
|
-
const sheet = panel.current;
|
|
1909
|
-
if (!enabled || sheet === null || typeof window === "undefined") return;
|
|
1910
|
-
let gesture = null;
|
|
1911
|
-
let natural = null;
|
|
1912
|
-
let closing = false;
|
|
1913
|
-
let timer;
|
|
1914
|
-
const scrollerOf = (target) => {
|
|
1915
|
-
for (let node = target; node !== null && node !== sheet; node = node.parentElement) {
|
|
1916
|
-
const overflow = getComputedStyle(node).overflowY;
|
|
1917
|
-
if ((overflow === "auto" || overflow === "scroll") && node instanceof HTMLElement) return node;
|
|
1918
|
-
}
|
|
1919
|
-
return null;
|
|
1920
|
-
};
|
|
1921
|
-
const contentHeight = () => {
|
|
1922
|
-
const body = sheet.querySelector("[data-cbx-sheet-scroll]");
|
|
1923
|
-
if (body === null) return sheet.offsetHeight;
|
|
1924
|
-
return sheet.offsetHeight - body.clientHeight + body.scrollHeight;
|
|
1925
|
-
};
|
|
1926
|
-
const setScrim = (fraction) => {
|
|
1927
|
-
if (scrim?.current) {
|
|
1928
|
-
if (fraction >= 1) scrim.current.style.removeProperty("--cbx-scrim");
|
|
1929
|
-
else scrim.current.style.setProperty("--cbx-scrim", String(Math.max(0, Math.min(1, fraction))));
|
|
1930
|
-
}
|
|
1931
|
-
};
|
|
1932
|
-
const animate = (on) => {
|
|
1933
|
-
const smooth = on && !reducedMotion();
|
|
1934
|
-
sheet.style.transition = smooth ? `height ${DURATION}ms ${EASE}, transform ${DURATION}ms ${EASE}` : "none";
|
|
1935
|
-
if (scrim?.current) scrim.current.style.transition = smooth ? `--cbx-scrim ${DURATION}ms ${EASE}` : "none";
|
|
1936
|
-
};
|
|
1937
|
-
const place2 = (height, detents) => {
|
|
1938
|
-
const smallest = detents[0];
|
|
1939
|
-
const largest = detents[detents.length - 1];
|
|
1940
|
-
let shown = height;
|
|
1941
|
-
let drop = 0;
|
|
1942
|
-
if (height > largest) shown = largest + rubberBand(height - largest);
|
|
1943
|
-
else if (height < smallest) {
|
|
1944
|
-
shown = smallest;
|
|
1945
|
-
drop = smallest - height;
|
|
1946
|
-
}
|
|
1947
|
-
sheet.style.maxHeight = "none";
|
|
1948
|
-
sheet.style.height = `${Math.round(shown)}px`;
|
|
1949
|
-
sheet.style.transform = drop > 0 ? `translateY(${Math.round(drop)}px)` : "";
|
|
1950
|
-
setScrim(drop > 0 ? 1 - drop / smallest : 1);
|
|
1951
|
-
sheet.dataset.cbxDragging = "true";
|
|
1952
|
-
};
|
|
1953
|
-
const begin = (event) => {
|
|
1954
|
-
if (gesture !== null) finish(gesture.last, event.timeStamp);
|
|
1955
|
-
if (closing) return;
|
|
1956
|
-
if (event.pointerType === "mouse" && event.button !== 0) return;
|
|
1957
|
-
const target = event.target instanceof Element ? event.target : null;
|
|
1958
|
-
if (target === null || target.closest(NO_DRAG) !== null && !target.matches(GRAB_FIELD)) return;
|
|
1959
|
-
const zone = target.closest(".cbx-sheet-grab") !== null ? "grab" : "content";
|
|
1960
|
-
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() };
|
|
1961
|
-
gesture.tracker.add(event.timeStamp, event.clientY);
|
|
1962
|
-
window.addEventListener("pointermove", move);
|
|
1963
|
-
window.addEventListener("pointerup", end);
|
|
1964
|
-
window.addEventListener("pointercancel", end);
|
|
1965
|
-
};
|
|
1966
|
-
const canGrow = () => {
|
|
1967
|
-
const current = sheet.getBoundingClientRect().height;
|
|
1968
|
-
const detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
|
|
1969
|
-
return current < detents[detents.length - 1] - 1;
|
|
1970
|
-
};
|
|
1971
|
-
const decide = (dx, dy) => {
|
|
1972
|
-
if (gesture === null) return void 0;
|
|
1973
|
-
if (gesture.mode !== void 0) return gesture.mode;
|
|
1974
|
-
const mode = dragIntent({ zone: gesture.zone, dx, dy, scrollTop: gesture.scroller?.scrollTop ?? 0, canGrow: gesture.zone === "content" && dy < 0 ? canGrow() : false });
|
|
1975
|
-
if (mode === "drag") {
|
|
1976
|
-
clearTimeout(timer);
|
|
1977
|
-
const current = sheet.getBoundingClientRect().height;
|
|
1978
|
-
if (natural === null && sheet.style.height === "") natural = Math.round(current);
|
|
1979
|
-
gesture.start = current;
|
|
1980
|
-
gesture.detents = sheetDetents({ size, viewport: visibleHeight(), current: natural ?? current, content: contentHeight() });
|
|
1981
|
-
animate(false);
|
|
1982
|
-
try {
|
|
1983
|
-
sheet.setPointerCapture(gesture.id);
|
|
1984
|
-
} catch {
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
gesture.mode = mode;
|
|
1988
|
-
return mode;
|
|
1989
|
-
};
|
|
1990
|
-
const move = (event) => {
|
|
1991
|
-
if (gesture === null || event.pointerId !== gesture.id) return;
|
|
1992
|
-
const dx = event.clientX - gesture.x;
|
|
1993
|
-
const dy = event.clientY - gesture.y;
|
|
1994
|
-
if (decide(dx, dy) !== "drag") return;
|
|
1995
|
-
gesture.last = event.clientY;
|
|
1996
|
-
gesture.tracker.add(event.timeStamp, event.clientY);
|
|
1997
|
-
place2(gesture.start - dy, gesture.detents);
|
|
1998
|
-
};
|
|
1999
|
-
const end = (event) => {
|
|
2000
|
-
if (gesture === null || event.pointerId !== gesture.id) return;
|
|
2001
|
-
finish(event.type === "pointerup" ? event.clientY : gesture.last, event.timeStamp);
|
|
2002
|
-
};
|
|
2003
|
-
const finish = (y, at) => {
|
|
2004
|
-
const done = gesture;
|
|
2005
|
-
gesture = null;
|
|
2006
|
-
unfollow();
|
|
2007
|
-
if (done === null || done.mode !== "drag") return;
|
|
2008
|
-
done.tracker.add(at, y);
|
|
2009
|
-
delete sheet.dataset.cbxDragging;
|
|
2010
|
-
const height = done.start - (y - done.y);
|
|
2011
|
-
const result = settleSheet({ height, velocity: done.tracker.velocity(), detents: done.detents });
|
|
2012
|
-
const swallow = (click) => {
|
|
2013
|
-
click.preventDefault();
|
|
2014
|
-
click.stopPropagation();
|
|
2015
|
-
};
|
|
2016
|
-
sheet.addEventListener("click", swallow, { capture: true, once: true });
|
|
2017
|
-
setTimeout(() => sheet.removeEventListener("click", swallow, { capture: true }), 350);
|
|
2018
|
-
animate(true);
|
|
2019
|
-
if (result.close) {
|
|
2020
|
-
closing = true;
|
|
2021
|
-
sheet.style.transform = `translateY(${Math.round(sheet.getBoundingClientRect().height + 24)}px)`;
|
|
2022
|
-
setScrim(0);
|
|
2023
|
-
timer = setTimeout(() => {
|
|
2024
|
-
if (close.current() === false) {
|
|
2025
|
-
closing = false;
|
|
2026
|
-
sheet.style.height = `${done.start}px`;
|
|
2027
|
-
sheet.style.transform = "";
|
|
2028
|
-
setScrim(1);
|
|
2029
|
-
}
|
|
2030
|
-
}, reducedMotion() ? 0 : DURATION - 40);
|
|
2031
|
-
return;
|
|
2032
|
-
}
|
|
2033
|
-
if (natural !== null && result.height === natural) {
|
|
2034
|
-
sheet.style.height = `${natural}px`;
|
|
2035
|
-
sheet.style.transform = "";
|
|
2036
|
-
setScrim(1);
|
|
2037
|
-
timer = setTimeout(() => {
|
|
2038
|
-
sheet.style.height = "";
|
|
2039
|
-
sheet.style.maxHeight = "";
|
|
2040
|
-
sheet.style.transition = "";
|
|
2041
|
-
natural = null;
|
|
2042
|
-
}, reducedMotion() ? 0 : DURATION);
|
|
2043
|
-
return;
|
|
2044
|
-
}
|
|
2045
|
-
sheet.style.height = `${result.height}px`;
|
|
2046
|
-
sheet.style.transform = "";
|
|
2047
|
-
setScrim(1);
|
|
2048
|
-
};
|
|
2049
|
-
const touchMove = (event) => {
|
|
2050
|
-
if (gesture === null || event.touches.length > 1) return;
|
|
2051
|
-
const touch = event.touches[0];
|
|
2052
|
-
const mode = decide(touch.clientX - gesture.x, touch.clientY - gesture.y);
|
|
2053
|
-
if (mode === "drag" && event.cancelable) event.preventDefault();
|
|
2054
|
-
};
|
|
2055
|
-
const unfollow = () => {
|
|
2056
|
-
window.removeEventListener("pointermove", move);
|
|
2057
|
-
window.removeEventListener("pointerup", end);
|
|
2058
|
-
window.removeEventListener("pointercancel", end);
|
|
2059
|
-
};
|
|
2060
|
-
sheet.addEventListener("pointerdown", begin);
|
|
2061
|
-
sheet.addEventListener("touchmove", touchMove, { passive: false });
|
|
2062
|
-
return () => {
|
|
2063
|
-
clearTimeout(timer);
|
|
2064
|
-
unfollow();
|
|
2065
|
-
sheet.removeEventListener("pointerdown", begin);
|
|
2066
|
-
sheet.removeEventListener("touchmove", touchMove);
|
|
2067
|
-
for (const property of ["height", "maxHeight", "transform", "transition"]) sheet.style[property] = "";
|
|
2068
|
-
delete sheet.dataset.cbxDragging;
|
|
2069
|
-
if (scrim?.current) {
|
|
2070
|
-
scrim.current.style.removeProperty("--cbx-scrim");
|
|
2071
|
-
scrim.current.style.transition = "";
|
|
2072
|
-
}
|
|
2073
|
-
};
|
|
2074
|
-
}, [panel, scrim, size, enabled]);
|
|
2075
|
-
}
|
|
2076
|
-
function scrimHandlers(onClose) {
|
|
2077
|
-
return {
|
|
2078
|
-
onPointerDown: (event) => {
|
|
2079
|
-
event.currentTarget.dataset.cbxPressed = event.target === event.currentTarget ? "true" : "false";
|
|
2080
|
-
},
|
|
2081
|
-
onClick: (event) => {
|
|
2082
|
-
const pressed = event.currentTarget.dataset.cbxPressed === "true";
|
|
2083
|
-
delete event.currentTarget.dataset.cbxPressed;
|
|
2084
|
-
if (pressed && event.target === event.currentTarget) onClose();
|
|
2085
|
-
}
|
|
2086
|
-
};
|
|
2087
|
-
}
|
|
2088
2108
|
var DEFAULT_SUPPORT_SCRIPT = "/ai-assistant/support.js";
|
|
2089
2109
|
var SUPPORT_TAG = "cbox-support";
|
|
2090
2110
|
function useHelpState(store, select) {
|
|
@@ -3091,7 +3111,7 @@ function CommandPalette({ onClose }) {
|
|
|
3091
3111
|
] })
|
|
3092
3112
|
] }) });
|
|
3093
3113
|
}
|
|
3094
|
-
function
|
|
3114
|
+
function Sheet2({
|
|
3095
3115
|
label,
|
|
3096
3116
|
side = "bottom",
|
|
3097
3117
|
onClose,
|
|
@@ -3186,7 +3206,7 @@ function CreateSheet({ onClose }) {
|
|
|
3186
3206
|
};
|
|
3187
3207
|
const title = top.kind === "tree" ? t("Create") : t("New {thing}", { thing: name(top).toLowerCase() });
|
|
3188
3208
|
return /* @__PURE__ */ jsxs(
|
|
3189
|
-
|
|
3209
|
+
Sheet2,
|
|
3190
3210
|
{
|
|
3191
3211
|
label: title,
|
|
3192
3212
|
side: mobile ? "bottom" : "right",
|
|
@@ -3952,7 +3972,7 @@ function ContextSheet({ onClose }) {
|
|
|
3952
3972
|
if (environment !== void 0) {
|
|
3953
3973
|
const index = levels.indexOf(environment);
|
|
3954
3974
|
const parent = levels[index - 1];
|
|
3955
|
-
return /* @__PURE__ */ jsx(
|
|
3975
|
+
return /* @__PURE__ */ jsx(Sheet2, { label: parent !== void 0 && index > 0 ? t("{things} in {name}", { things: pluralOf(environment), name: parent.current.name }) : pluralOf(environment), size: "tall", onClose, back: { label: t("Back"), onBack: back }, children: /* @__PURE__ */ jsx(EnvironmentList, { level: environment, parent: index > 0 ? parent?.current.id : void 0, parentName: index > 0 ? parent?.current.name : void 0, onPick: (item) => switchTo(parent !== void 0 && index > 0 ? { [parent.key]: parent.current.id, [environment.key]: item.id } : { [environment.key]: item.id }) }) });
|
|
3956
3976
|
}
|
|
3957
3977
|
}
|
|
3958
3978
|
const level = levels.find((item) => item.key === step);
|
|
@@ -3960,7 +3980,7 @@ function ContextSheet({ onClose }) {
|
|
|
3960
3980
|
const index = levels.indexOf(level);
|
|
3961
3981
|
const parent = index > 0 ? levels[index - 1] : void 0;
|
|
3962
3982
|
const inner = levels[index + 1];
|
|
3963
|
-
return /* @__PURE__ */ jsx(
|
|
3983
|
+
return /* @__PURE__ */ jsx(Sheet2, { label: level.label, size: "tall", onClose, back: { label: t("Back"), onBack: back }, children: /* @__PURE__ */ jsx("div", { className: "cbx-sheet-level", children: /* @__PURE__ */ jsx(
|
|
3964
3984
|
LevelPane,
|
|
3965
3985
|
{
|
|
3966
3986
|
level,
|
|
@@ -3972,7 +3992,7 @@ function ContextSheet({ onClose }) {
|
|
|
3972
3992
|
}
|
|
3973
3993
|
) }) });
|
|
3974
3994
|
}
|
|
3975
|
-
return /* @__PURE__ */ jsx(
|
|
3995
|
+
return /* @__PURE__ */ jsx(Sheet2, { label: t("Where you work"), onClose, children: /* @__PURE__ */ jsx(ContextRoot, { onStep: setStep }) });
|
|
3976
3996
|
}
|
|
3977
3997
|
function ContextRoot({ onStep }) {
|
|
3978
3998
|
const { shell, t, switchTo } = useShell();
|
|
@@ -4056,7 +4076,7 @@ function EnvironmentList({ level, parent, parentName, onPick }) {
|
|
|
4056
4076
|
}
|
|
4057
4077
|
function AppsSheet({ onClose }) {
|
|
4058
4078
|
const { t } = useShell();
|
|
4059
|
-
return /* @__PURE__ */ jsx(
|
|
4079
|
+
return /* @__PURE__ */ jsx(Sheet2, { label: t("Switch app"), onClose, children: /* @__PURE__ */ jsx(AppGrid, { autoFocus: false }) });
|
|
4060
4080
|
}
|
|
4061
4081
|
function MobilePage({ hidden, children }) {
|
|
4062
4082
|
const box = useRef(null);
|
|
@@ -6122,6 +6142,6 @@ function Sparkline({ values, color = "var(--chart-1)", width = 90, height = 20 }
|
|
|
6122
6142
|
] });
|
|
6123
6143
|
}
|
|
6124
6144
|
|
|
6125
|
-
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sparkline, Spinner, StatTile, StatusPill, Switch, Textarea, applyTheme, buildUrlSearch, buttonClassName, 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, useDialogClose, useFieldControl, useKnownAppCatalog, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
6145
|
+
export { APP_HUES, AppContent, AppShell, Button, CHART_PALETTE, CboxAppCatalog, CboxAppIcon, CboxBrand, CboxIdProvider, CboxLocalizationProvider, CboxServiceMark, CboxShell, CboxSurfaces, Checkbox, Combobox, CreateField, CreateForm, CreateRefField, CreateSubmit, DataPanel, Dialog, DialogClose, EmptyState, Field, Heading, Input, KeyValue, KeyValueList, PageHeader, PageShell, PageTabs, PanelBody, RadioGroup, RowLink, SHELL_ICONS, SectionHeader, Sheet, SheetClose, Sparkline, Spinner, StatTile, StatusPill, Switch, Textarea, applyTheme, buildUrlSearch, buttonClassName, 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, useDialogClose, useFieldControl, useKnownAppCatalog, useSheetClose, useShellCreate, useShellHelp, useShellPageTitle, withQuery };
|
|
6126
6146
|
//# sourceMappingURL=index.js.map
|
|
6127
6147
|
//# sourceMappingURL=index.js.map
|