@surfaces-ui/components 0.4.0 → 0.6.0
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/chart/Chart.js +9 -1
- package/dist/chart/Chart.js.map +1 -1
- package/dist/chart/labels.d.ts +23 -0
- package/dist/chart/labels.js +82 -0
- package/dist/chart/labels.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/source/SourceList.js +6 -0
- package/dist/source/SourceList.js.map +1 -1
- package/dist/styles.css +117 -2
- package/dist/styles.layer.css +117 -2
- package/dist/text/Image.d.ts +50 -0
- package/dist/text/Image.js +65 -0
- package/dist/text/Image.js.map +1 -0
- package/dist/text/Markdown.d.ts +5 -1
- package/dist/text/Markdown.js +4 -2
- package/dist/text/Markdown.js.map +1 -1
- package/dist/workspace/SideNav.d.ts +14 -0
- package/dist/workspace/SideNav.js +31 -3
- package/dist/workspace/SideNav.js.map +1 -1
- package/package.json +6 -6
|
@@ -23,6 +23,31 @@ export function drawerBox(holder, viewport, least = SIDENAV_LEAST) {
|
|
|
23
23
|
return undefined;
|
|
24
24
|
return { top, left, width, height };
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Where the drawer's stage is put, in the px its `top` and `left` are counted in. A fixed box is placed from the window
|
|
28
|
+
* unless something around it is its containing block: a `.sf-container` in a browser where a container query brings
|
|
29
|
+
* layout containment (Chrome 156 does not), or anything a host has contained, transformed or filtered. `origin` is where that block starts on screen, measured
|
|
30
|
+
* from the stage itself, and the box is counted from there. With the window as the block nothing changes, and no box
|
|
31
|
+
* stays no box (the stylesheet's own window). Inside another block "the whole window" has to be worked out too.
|
|
32
|
+
*/
|
|
33
|
+
export function stageBox(box, origin, viewport) {
|
|
34
|
+
if (!origin.top && !origin.left)
|
|
35
|
+
return box;
|
|
36
|
+
const target = box ?? { top: 0, left: 0, width: viewport.width, height: viewport.height };
|
|
37
|
+
return { top: target.top - origin.top, left: target.left - origin.left, width: target.width, height: target.height };
|
|
38
|
+
}
|
|
39
|
+
/** Where on screen a fixed element's containing block starts: where the element is, less the offsets it was given. */
|
|
40
|
+
function fixedOrigin(element) {
|
|
41
|
+
if (!element)
|
|
42
|
+
return { top: 0, left: 0 };
|
|
43
|
+
const rect = element.getBoundingClientRect();
|
|
44
|
+
const style = getComputedStyle(element);
|
|
45
|
+
// A fixed box's computed `top` and `left` are the used px. Anything else (not laid out, no stylesheet) says nothing.
|
|
46
|
+
const top = rect.top - Number.parseFloat(style.top);
|
|
47
|
+
const left = rect.left - Number.parseFloat(style.left);
|
|
48
|
+
// Under half a px is rounding, not a containing block.
|
|
49
|
+
return { top: Math.abs(top) >= 0.5 ? top : 0, left: Math.abs(left) >= 0.5 ? left : 0 };
|
|
50
|
+
}
|
|
26
51
|
/** What holds the navigation when it is drawn inside a region that answers to its own size (a surface, a result). */
|
|
27
52
|
const holderOf = (element) => element?.closest(".sf-container") ?? undefined;
|
|
28
53
|
/** True when the window, or the region the navigation is drawn in, is too narrow to dock it. */
|
|
@@ -76,6 +101,7 @@ export function SideNav({ label, groups, current, onSelect, pinned: given, defau
|
|
|
76
101
|
const pinned = (given ?? kept) && !narrow;
|
|
77
102
|
const [open, setOpen] = useState(false);
|
|
78
103
|
const panel = useRef(null);
|
|
104
|
+
const stage = useRef(null);
|
|
79
105
|
const opener = () => document.getElementById(`${id}-open`);
|
|
80
106
|
const close = () => {
|
|
81
107
|
setOpen(false);
|
|
@@ -90,14 +116,16 @@ export function SideNav({ label, groups, current, onSelect, pinned: given, defau
|
|
|
90
116
|
requestAnimationFrame(() => opener()?.focus());
|
|
91
117
|
};
|
|
92
118
|
const taking = !pinned && open;
|
|
93
|
-
// Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves
|
|
119
|
+
// Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves, and counted
|
|
120
|
+
// from whatever the stage is really placed against (the window, or a holder that contains fixed boxes).
|
|
94
121
|
const [box, setBox] = useState(undefined);
|
|
95
122
|
useLayoutEffect(() => {
|
|
96
123
|
if (!taking)
|
|
97
124
|
return;
|
|
98
125
|
const place = () => {
|
|
99
126
|
const rect = holderOf(root.current)?.getBoundingClientRect();
|
|
100
|
-
const
|
|
127
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
128
|
+
const next = stageBox(drawerBox(rect ? { top: rect.top, left: rect.left, width: rect.width, height: rect.height } : undefined, viewport), fixedOrigin(stage.current), viewport);
|
|
101
129
|
setBox((before) => (before && next && before.top === next.top && before.left === next.left && before.width === next.width && before.height === next.height ? before : next));
|
|
102
130
|
};
|
|
103
131
|
place();
|
|
@@ -144,6 +172,6 @@ export function SideNav({ label, groups, current, onSelect, pinned: given, defau
|
|
|
144
172
|
if (taking)
|
|
145
173
|
close();
|
|
146
174
|
};
|
|
147
|
-
return (_jsxs("div", { ref: root, className: `sf-sidenav${className ? ` ${className}` : ""}`, "data-pinned": pinned, "data-open": open || undefined, "data-narrow": narrow || undefined, style: placed, onKeyDown: onKey, children: [!pinned && (_jsx("button", { id: `${id}-open`, type: "button", className: "sf-sidenav-open", "aria-expanded": open, "aria-controls": `${id}-panel`, "aria-label": `Show ${navigationName(label)}`, onClick: () => setOpen(true), children: _jsx(ControlIcon, { icon: "menu" }) })), _jsxs("div", { className: "sf-sidenav-stage", children: [taking && _jsx("div", { className: "sf-sidenav-backdrop", "aria-hidden": "true", onClick: close }), _jsxs("div", { id: `${id}-panel`, ref: panel, className: "sf-sidenav-panel", role: pinned ? undefined : "dialog", "aria-modal": taking || undefined, "aria-label": pinned ? undefined : navigationName(label), children: [_jsxs("div", { className: "sf-sidenav-top", children: [_jsx("div", { className: "sf-sidenav-header", children: header }), !narrow && (_jsxs("button", { type: "button", className: "sf-sidenav-pin", "aria-pressed": pinned, title: pinned ? "Let the navigation fold away" : "Keep the navigation open", onClick: () => setPinned(!pinned), children: [_jsx(ControlIcon, { icon: pinned ? "fold" : "unfold" }), _jsx("span", { className: "sf-sidenav-pin-label", children: pinned ? "Fold away" : "Keep open" })] })), !pinned && (_jsx("button", { type: "button", className: "sf-sidenav-close", "aria-label": `Close ${navigationName(label)}`, onClick: close, children: _jsx(ControlIcon, { icon: "close" }) }))] }), _jsx("nav", { className: "sf-sidenav-nav", "aria-label": label, children: groups.map((group, g) => (_jsxs("section", { className: "sf-sidenav-group", "aria-labelledby": group.label ? `${id}-group-${g}` : undefined, children: [group.label && (_jsx("h2", { id: `${id}-group-${g}`, className: "sf-sidenav-group-label", children: group.label })), _jsx("ul", { children: group.items.map((item) => (_jsx("li", { children: item.href ? (_jsx("a", { href: item.href, "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) : (_jsx("button", { type: "button", "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) }, item.id))) })] }, group.label ?? g))) }), footer && _jsx("div", { className: "sf-sidenav-footer", children: footer })] })] })] }));
|
|
175
|
+
return (_jsxs("div", { ref: root, className: `sf-sidenav${className ? ` ${className}` : ""}`, "data-pinned": pinned, "data-open": open || undefined, "data-narrow": narrow || undefined, style: placed, onKeyDown: onKey, children: [!pinned && (_jsx("button", { id: `${id}-open`, type: "button", className: "sf-sidenav-open", "aria-expanded": open, "aria-controls": `${id}-panel`, "aria-label": `Show ${navigationName(label)}`, onClick: () => setOpen(true), children: _jsx(ControlIcon, { icon: "menu" }) })), _jsxs("div", { ref: stage, className: "sf-sidenav-stage", children: [taking && _jsx("div", { className: "sf-sidenav-backdrop", "aria-hidden": "true", onClick: close }), _jsxs("div", { id: `${id}-panel`, ref: panel, className: "sf-sidenav-panel", role: pinned ? undefined : "dialog", "aria-modal": taking || undefined, "aria-label": pinned ? undefined : navigationName(label), children: [_jsxs("div", { className: "sf-sidenav-top", children: [_jsx("div", { className: "sf-sidenav-header", children: header }), !narrow && (_jsxs("button", { type: "button", className: "sf-sidenav-pin", "aria-pressed": pinned, title: pinned ? "Let the navigation fold away" : "Keep the navigation open", onClick: () => setPinned(!pinned), children: [_jsx(ControlIcon, { icon: pinned ? "fold" : "unfold" }), _jsx("span", { className: "sf-sidenav-pin-label", children: pinned ? "Fold away" : "Keep open" })] })), !pinned && (_jsx("button", { type: "button", className: "sf-sidenav-close", "aria-label": `Close ${navigationName(label)}`, onClick: close, children: _jsx(ControlIcon, { icon: "close" }) }))] }), _jsx("nav", { className: "sf-sidenav-nav", "aria-label": label, children: groups.map((group, g) => (_jsxs("section", { className: "sf-sidenav-group", "aria-labelledby": group.label ? `${id}-group-${g}` : undefined, children: [group.label && (_jsx("h2", { id: `${id}-group-${g}`, className: "sf-sidenav-group-label", children: group.label })), _jsx("ul", { children: group.items.map((item) => (_jsx("li", { children: item.href ? (_jsx("a", { href: item.href, "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) : (_jsx("button", { type: "button", "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) }, item.id))) })] }, group.label ?? g))) }), footer && _jsx("div", { className: "sf-sidenav-footer", children: footer })] })] })] }));
|
|
148
176
|
}
|
|
149
177
|
//# sourceMappingURL=SideNav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SideNav.js","sourceRoot":"","sources":["../../src/workspace/SideNav.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA0E,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpJ,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAkC1D,2HAA2H;AAC3H,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAEnD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAErJ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ACE,EACL,MAAM,IAAI,cAAK,SAAS,EAAC,mBAAmB,YAAE,MAAM,GAAO,IACxD,IACA,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, type RefObject, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { ControlIcon } from \"../controls/ItemControls.js\";\n\nexport interface SideNavItem {\n id: string;\n label: string;\n /** Where the item goes. Without one the item is a button and only `onSelect` is called. */\n href?: string;\n}\n\nexport interface SideNavGroup {\n /** A heading over the group's items. */\n label?: string;\n items: SideNavItem[];\n}\n\nexport interface SideNavProps {\n /** What the navigation is for, for assistive technology: \"Playground\". */\n label: string;\n groups: SideNavGroup[];\n /** The id of the item for the page being shown. */\n current?: string;\n onSelect?(id: string): void;\n /** Whether the navigation stays open beside the page. Give it with `onPinnedChange` to hold it yourself. */\n pinned?: boolean;\n /** Whether it starts pinned when it holds the state itself. Defaults to true. */\n defaultPinned?: boolean;\n onPinnedChange?(pinned: boolean): void;\n /** Shown above the items: a name, a status, a picker. */\n header?: ReactNode;\n /** Shown below the items. */\n footer?: ReactNode;\n className?: string;\n}\n\n/** Below this width the navigation is always folded away: docked beside a phone's page it would leave the page no room. */\nexport const SIDENAV_NARROW = \"(max-width: 40rem)\";\n\nconst narrowQuery = () => (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(SIDENAV_NARROW) : undefined);\n\n/** The width, in rem, under which whatever holds the navigation is too narrow to dock it beside the page. */\nconst NARROW_REM = 40;\n/** The least room, in px each way, a drawer needs: in a smaller box it takes the window instead. */\nexport const SIDENAV_LEAST = 240;\n\n/** A box on screen, in px from the window's top left. */\nexport interface NavBox {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\n/**\n * Where a folded navigation's drawer goes: the part of its holder that is on screen. Nothing (the whole window) when\n * the holder is not laid out, is off screen, or shows less than `least` px either way.\n */\nexport function drawerBox(holder: NavBox | undefined, viewport: { width: number; height: number }, least = SIDENAV_LEAST): NavBox | undefined {\n if (!holder) return undefined;\n const top = Math.max(holder.top, 0);\n const left = Math.max(holder.left, 0);\n const width = Math.min(holder.left + holder.width, viewport.width) - left;\n const height = Math.min(holder.top + holder.height, viewport.height) - top;\n if (!(width >= least) || !(height >= least)) return undefined;\n return { top, left, width, height };\n}\n\n/** What holds the navigation when it is drawn inside a region that answers to its own size (a surface, a result). */\nconst holderOf = (element: Element | null) => element?.closest(\".sf-container\") ?? undefined;\n\n/** True when the window, or the region the navigation is drawn in, is too narrow to dock it. */\nfunction useNarrow(root: RefObject<HTMLElement | null>): boolean {\n const [narrow, setNarrow] = useState(() => narrowQuery()?.matches ?? false);\n const [tight, setTight] = useState(false);\n useEffect(() => {\n const query = narrowQuery();\n if (!query) return;\n const change = () => setNarrow(query.matches);\n change();\n query.addEventListener(\"change\", change);\n return () => query.removeEventListener(\"change\", change);\n }, []);\n useEffect(() => {\n const holder = holderOf(root.current);\n if (!holder || typeof ResizeObserver === \"undefined\") return;\n const measure = () => {\n const width = holder.getBoundingClientRect().width;\n const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n // A holder that is not laid out says nothing.\n setTight(width > 0 && width < NARROW_REM * rem);\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(holder);\n return () => observer.disconnect();\n }, [root]);\n return narrow || tight;\n}\n\n/** \"Site navigation\" for \"Site\", and \"Main navigation\" left as it is: a label that already says so is not said twice. */\nexport const navigationName = (label: string) => (/\\bnavigation\\s*$/i.test(label) ? label.trim() : `${label.trim()} navigation`);\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Side navigation that can get out of the way. Pinned, it sits beside the page. Unpinned, it keeps only the room its\n * menu button takes: a slim strip where the navigation was, so the button never sits over the page or a host's own\n * toolbar. Pressing it slides the navigation in from the left as a dialog: over the window, or, drawn inside a region\n * that answers to its own size (a surface in a host's canvas, a chat reply), over that region only. Focus moves into\n * it and stays there until it closes, on Escape, on its close button, or when an item is chosen; focus then goes back\n * to the menu button. Where the window or that region is under 40rem wide (`SIDENAV_NARROW`) it is always folded and\n * offers no pin.\n */\nexport function SideNav({ label, groups, current, onSelect, pinned: given, defaultPinned = true, onPinnedChange, header, footer, className }: SideNavProps) {\n const id = useId();\n const [kept, setKept] = useState(defaultPinned);\n const root = useRef<HTMLDivElement>(null);\n const narrow = useNarrow(root);\n // On a narrow screen it is folded whatever was chosen; the choice comes back on a wider one.\n const pinned = (given ?? kept) && !narrow;\n const [open, setOpen] = useState(false);\n const panel = useRef<HTMLDivElement>(null);\n const opener = () => document.getElementById(`${id}-open`);\n const close = () => {\n setOpen(false);\n requestAnimationFrame(() => opener()?.focus());\n };\n const setPinned = (next: boolean) => {\n setKept(next);\n setOpen(false);\n onPinnedChange?.(next);\n // Folding away from the button inside the panel: focus goes to the menu button that opens it again.\n if (!next) requestAnimationFrame(() => opener()?.focus());\n };\n const taking = !pinned && open;\n // Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves.\n const [box, setBox] = useState<NavBox | undefined>(undefined);\n useLayoutEffect(() => {\n if (!taking) return;\n const place = () => {\n const rect = holderOf(root.current)?.getBoundingClientRect();\n const next = drawerBox(rect ? { top: rect.top, left: rect.left, width: rect.width, height: rect.height } : undefined, { width: window.innerWidth, height: window.innerHeight });\n setBox((before) => (before && next && before.top === next.top && before.left === next.left && before.width === next.width && before.height === next.height ? before : next));\n };\n place();\n window.addEventListener(\"resize\", place);\n window.addEventListener(\"scroll\", place, true);\n return () => {\n window.removeEventListener(\"resize\", place);\n window.removeEventListener(\"scroll\", place, true);\n };\n }, [taking]);\n const placed = !pinned && box ? ({ \"--sf-sidenav-top\": `${box.top}px`, \"--sf-sidenav-left\": `${box.left}px`, \"--sf-sidenav-width\": `${box.width}px`, \"--sf-sidenav-height\": `${box.height}px` } as CSSProperties) : undefined;\n // Opened over the page: focus goes in, to the close button first.\n useEffect(() => {\n if (taking) panel.current?.querySelector<HTMLElement>(\".sf-sidenav-close\")?.focus();\n }, [taking]);\n\n const onKey = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!taking) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n return;\n }\n // Focus stays inside while it covers the page.\n if (event.key === \"Tab\" && panel.current) {\n const all = [...panel.current.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const first = all[0];\n const last = all[all.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n }\n };\n const choose = (item: string) => {\n onSelect?.(item);\n if (taking) close();\n };\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: Escape and Tab are handled here for everything inside; the controls themselves are buttons and links.\n <div ref={root} className={`sf-sidenav${className ? ` ${className}` : \"\"}`} data-pinned={pinned} data-open={open || undefined} data-narrow={narrow || undefined} style={placed} onKeyDown={onKey}>\n {!pinned && (\n <button id={`${id}-open`} type=\"button\" className=\"sf-sidenav-open\" aria-expanded={open} aria-controls={`${id}-panel`} aria-label={`Show ${navigationName(label)}`} onClick={() => setOpen(true)}>\n <ControlIcon icon=\"menu\" />\n </button>\n )}\n {/* Folded, the drawer and the dimmed page behind it live in a stage laid over the holder, which clips the drawer as it slides. */}\n <div className=\"sf-sidenav-stage\">\n {/* The page behind a drawer is dimmed, and a press on it closes the drawer; Escape and the close button do the same. */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents lint/a11y/noStaticElementInteractions: a pointer's shortcut; the keyboard closes it with Escape or the close button. */}\n {taking && <div className=\"sf-sidenav-backdrop\" aria-hidden=\"true\" onClick={close} />}\n <div\n id={`${id}-panel`}\n ref={panel}\n className=\"sf-sidenav-panel\"\n role={pinned ? undefined : \"dialog\"}\n aria-modal={taking || undefined}\n aria-label={pinned ? undefined : navigationName(label)}\n >\n <div className=\"sf-sidenav-top\">\n <div className=\"sf-sidenav-header\">{header}</div>\n {!narrow && (\n <button type=\"button\" className=\"sf-sidenav-pin\" aria-pressed={pinned} title={pinned ? \"Let the navigation fold away\" : \"Keep the navigation open\"} onClick={() => setPinned(!pinned)}>\n <ControlIcon icon={pinned ? \"fold\" : \"unfold\"} />\n <span className=\"sf-sidenav-pin-label\">{pinned ? \"Fold away\" : \"Keep open\"}</span>\n </button>\n )}\n {!pinned && (\n <button type=\"button\" className=\"sf-sidenav-close\" aria-label={`Close ${navigationName(label)}`} onClick={close}>\n <ControlIcon icon=\"close\" />\n </button>\n )}\n </div>\n <nav className=\"sf-sidenav-nav\" aria-label={label}>\n {groups.map((group, g) => (\n <section key={group.label ?? g} className=\"sf-sidenav-group\" aria-labelledby={group.label ? `${id}-group-${g}` : undefined}>\n {group.label && (\n <h2 id={`${id}-group-${g}`} className=\"sf-sidenav-group-label\">\n {group.label}\n </h2>\n )}\n <ul>\n {group.items.map((item) => (\n <li key={item.id}>\n {item.href ? (\n <a href={item.href} aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </a>\n ) : (\n <button type=\"button\" aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </button>\n )}\n </li>\n ))}\n </ul>\n </section>\n ))}\n </nav>\n {footer && <div className=\"sf-sidenav-footer\">{footer}</div>}\n </div>\n </div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SideNav.js","sourceRoot":"","sources":["../../src/workspace/SideNav.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA0E,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpJ,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAkC1D,2HAA2H;AAC3H,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAEnD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,M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C,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,YACvG,IAAI,CAAC,KAAK,GACT,CACL,CAAC,CAAC,CAAC,CACF,iBAAQ,IAAI,EAAC,QAAQ,kBAAe,IAAI,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,YACzG,IAAI,CAAC,KAAK,GACJ,CACV,IATM,IAAI,CAAC,EAAE,CAUX,CACN,CAAC,GACC,KApBO,KAAK,CAAC,KAAK,IAAI,CAAC,CAqBpB,CACX,CAAC,GACE,EACL,MAAM,IAAI,cAAK,SAAS,EAAC,mBAAmB,YAAE,MAAM,GAAO,IACxD,IACA,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, type RefObject, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { ControlIcon } from \"../controls/ItemControls.js\";\n\nexport interface SideNavItem {\n id: string;\n label: string;\n /** Where the item goes. Without one the item is a button and only `onSelect` is called. */\n href?: string;\n}\n\nexport interface SideNavGroup {\n /** A heading over the group's items. */\n label?: string;\n items: SideNavItem[];\n}\n\nexport interface SideNavProps {\n /** What the navigation is for, for assistive technology: \"Playground\". */\n label: string;\n groups: SideNavGroup[];\n /** The id of the item for the page being shown. */\n current?: string;\n onSelect?(id: string): void;\n /** Whether the navigation stays open beside the page. Give it with `onPinnedChange` to hold it yourself. */\n pinned?: boolean;\n /** Whether it starts pinned when it holds the state itself. Defaults to true. */\n defaultPinned?: boolean;\n onPinnedChange?(pinned: boolean): void;\n /** Shown above the items: a name, a status, a picker. */\n header?: ReactNode;\n /** Shown below the items. */\n footer?: ReactNode;\n className?: string;\n}\n\n/** Below this width the navigation is always folded away: docked beside a phone's page it would leave the page no room. */\nexport const SIDENAV_NARROW = \"(max-width: 40rem)\";\n\nconst narrowQuery = () => (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(SIDENAV_NARROW) : undefined);\n\n/** The width, in rem, under which whatever holds the navigation is too narrow to dock it beside the page. */\nconst NARROW_REM = 40;\n/** The least room, in px each way, a drawer needs: in a smaller box it takes the window instead. */\nexport const SIDENAV_LEAST = 240;\n\n/** A box on screen, in px from the window's top left. */\nexport interface NavBox {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\n/**\n * Where a folded navigation's drawer goes: the part of its holder that is on screen. Nothing (the whole window) when\n * the holder is not laid out, is off screen, or shows less than `least` px either way.\n */\nexport function drawerBox(holder: NavBox | undefined, viewport: { width: number; height: number }, least = SIDENAV_LEAST): NavBox | undefined {\n if (!holder) return undefined;\n const top = Math.max(holder.top, 0);\n const left = Math.max(holder.left, 0);\n const width = Math.min(holder.left + holder.width, viewport.width) - left;\n const height = Math.min(holder.top + holder.height, viewport.height) - top;\n if (!(width >= least) || !(height >= least)) return undefined;\n return { top, left, width, height };\n}\n\n/**\n * Where the drawer's stage is put, in the px its `top` and `left` are counted in. A fixed box is placed from the window\n * unless something around it is its containing block: a `.sf-container` in a browser where a container query brings\n * layout containment (Chrome 156 does not), or anything a host has contained, transformed or filtered. `origin` is where that block starts on screen, measured\n * from the stage itself, and the box is counted from there. With the window as the block nothing changes, and no box\n * stays no box (the stylesheet's own window). Inside another block \"the whole window\" has to be worked out too.\n */\nexport function stageBox(box: NavBox | undefined, origin: { top: number; left: number }, viewport: { width: number; height: number }): NavBox | undefined {\n if (!origin.top && !origin.left) return box;\n const target = box ?? { top: 0, left: 0, width: viewport.width, height: viewport.height };\n return { top: target.top - origin.top, left: target.left - origin.left, width: target.width, height: target.height };\n}\n\n/** Where on screen a fixed element's containing block starts: where the element is, less the offsets it was given. */\nfunction fixedOrigin(element: HTMLElement | null): { top: number; left: number } {\n if (!element) return { top: 0, left: 0 };\n const rect = element.getBoundingClientRect();\n const style = getComputedStyle(element);\n // A fixed box's computed `top` and `left` are the used px. Anything else (not laid out, no stylesheet) says nothing.\n const top = rect.top - Number.parseFloat(style.top);\n const left = rect.left - Number.parseFloat(style.left);\n // Under half a px is rounding, not a containing block.\n return { top: Math.abs(top) >= 0.5 ? top : 0, left: Math.abs(left) >= 0.5 ? left : 0 };\n}\n\n/** What holds the navigation when it is drawn inside a region that answers to its own size (a surface, a result). */\nconst holderOf = (element: Element | null) => element?.closest(\".sf-container\") ?? undefined;\n\n/** True when the window, or the region the navigation is drawn in, is too narrow to dock it. */\nfunction useNarrow(root: RefObject<HTMLElement | null>): boolean {\n const [narrow, setNarrow] = useState(() => narrowQuery()?.matches ?? false);\n const [tight, setTight] = useState(false);\n useEffect(() => {\n const query = narrowQuery();\n if (!query) return;\n const change = () => setNarrow(query.matches);\n change();\n query.addEventListener(\"change\", change);\n return () => query.removeEventListener(\"change\", change);\n }, []);\n useEffect(() => {\n const holder = holderOf(root.current);\n if (!holder || typeof ResizeObserver === \"undefined\") return;\n const measure = () => {\n const width = holder.getBoundingClientRect().width;\n const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n // A holder that is not laid out says nothing.\n setTight(width > 0 && width < NARROW_REM * rem);\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(holder);\n return () => observer.disconnect();\n }, [root]);\n return narrow || tight;\n}\n\n/** \"Site navigation\" for \"Site\", and \"Main navigation\" left as it is: a label that already says so is not said twice. */\nexport const navigationName = (label: string) => (/\\bnavigation\\s*$/i.test(label) ? label.trim() : `${label.trim()} navigation`);\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Side navigation that can get out of the way. Pinned, it sits beside the page. Unpinned, it keeps only the room its\n * menu button takes: a slim strip where the navigation was, so the button never sits over the page or a host's own\n * toolbar. Pressing it slides the navigation in from the left as a dialog: over the window, or, drawn inside a region\n * that answers to its own size (a surface in a host's canvas, a chat reply), over that region only. Focus moves into\n * it and stays there until it closes, on Escape, on its close button, or when an item is chosen; focus then goes back\n * to the menu button. Where the window or that region is under 40rem wide (`SIDENAV_NARROW`) it is always folded and\n * offers no pin.\n */\nexport function SideNav({ label, groups, current, onSelect, pinned: given, defaultPinned = true, onPinnedChange, header, footer, className }: SideNavProps) {\n const id = useId();\n const [kept, setKept] = useState(defaultPinned);\n const root = useRef<HTMLDivElement>(null);\n const narrow = useNarrow(root);\n // On a narrow screen it is folded whatever was chosen; the choice comes back on a wider one.\n const pinned = (given ?? kept) && !narrow;\n const [open, setOpen] = useState(false);\n const panel = useRef<HTMLDivElement>(null);\n const stage = useRef<HTMLDivElement>(null);\n const opener = () => document.getElementById(`${id}-open`);\n const close = () => {\n setOpen(false);\n requestAnimationFrame(() => opener()?.focus());\n };\n const setPinned = (next: boolean) => {\n setKept(next);\n setOpen(false);\n onPinnedChange?.(next);\n // Folding away from the button inside the panel: focus goes to the menu button that opens it again.\n if (!next) requestAnimationFrame(() => opener()?.focus());\n };\n const taking = !pinned && open;\n // Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves, and counted\n // from whatever the stage is really placed against (the window, or a holder that contains fixed boxes).\n const [box, setBox] = useState<NavBox | undefined>(undefined);\n useLayoutEffect(() => {\n if (!taking) return;\n const place = () => {\n const rect = holderOf(root.current)?.getBoundingClientRect();\n const viewport = { width: window.innerWidth, height: window.innerHeight };\n const next = stageBox(drawerBox(rect ? { top: rect.top, left: rect.left, width: rect.width, height: rect.height } : undefined, viewport), fixedOrigin(stage.current), viewport);\n setBox((before) => (before && next && before.top === next.top && before.left === next.left && before.width === next.width && before.height === next.height ? before : next));\n };\n place();\n window.addEventListener(\"resize\", place);\n window.addEventListener(\"scroll\", place, true);\n return () => {\n window.removeEventListener(\"resize\", place);\n window.removeEventListener(\"scroll\", place, true);\n };\n }, [taking]);\n const placed = !pinned && box ? ({ \"--sf-sidenav-top\": `${box.top}px`, \"--sf-sidenav-left\": `${box.left}px`, \"--sf-sidenav-width\": `${box.width}px`, \"--sf-sidenav-height\": `${box.height}px` } as CSSProperties) : undefined;\n // Opened over the page: focus goes in, to the close button first.\n useEffect(() => {\n if (taking) panel.current?.querySelector<HTMLElement>(\".sf-sidenav-close\")?.focus();\n }, [taking]);\n\n const onKey = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!taking) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n return;\n }\n // Focus stays inside while it covers the page.\n if (event.key === \"Tab\" && panel.current) {\n const all = [...panel.current.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const first = all[0];\n const last = all[all.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n }\n };\n const choose = (item: string) => {\n onSelect?.(item);\n if (taking) close();\n };\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: Escape and Tab are handled here for everything inside; the controls themselves are buttons and links.\n <div ref={root} className={`sf-sidenav${className ? ` ${className}` : \"\"}`} data-pinned={pinned} data-open={open || undefined} data-narrow={narrow || undefined} style={placed} onKeyDown={onKey}>\n {!pinned && (\n <button id={`${id}-open`} type=\"button\" className=\"sf-sidenav-open\" aria-expanded={open} aria-controls={`${id}-panel`} aria-label={`Show ${navigationName(label)}`} onClick={() => setOpen(true)}>\n <ControlIcon icon=\"menu\" />\n </button>\n )}\n {/* Folded, the drawer and the dimmed page behind it live in a stage laid over the holder, which clips the drawer as it slides. */}\n <div ref={stage} className=\"sf-sidenav-stage\">\n {/* The page behind a drawer is dimmed, and a press on it closes the drawer; Escape and the close button do the same. */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents lint/a11y/noStaticElementInteractions: a pointer's shortcut; the keyboard closes it with Escape or the close button. */}\n {taking && <div className=\"sf-sidenav-backdrop\" aria-hidden=\"true\" onClick={close} />}\n <div\n id={`${id}-panel`}\n ref={panel}\n className=\"sf-sidenav-panel\"\n role={pinned ? undefined : \"dialog\"}\n aria-modal={taking || undefined}\n aria-label={pinned ? undefined : navigationName(label)}\n >\n <div className=\"sf-sidenav-top\">\n <div className=\"sf-sidenav-header\">{header}</div>\n {!narrow && (\n <button type=\"button\" className=\"sf-sidenav-pin\" aria-pressed={pinned} title={pinned ? \"Let the navigation fold away\" : \"Keep the navigation open\"} onClick={() => setPinned(!pinned)}>\n <ControlIcon icon={pinned ? \"fold\" : \"unfold\"} />\n <span className=\"sf-sidenav-pin-label\">{pinned ? \"Fold away\" : \"Keep open\"}</span>\n </button>\n )}\n {!pinned && (\n <button type=\"button\" className=\"sf-sidenav-close\" aria-label={`Close ${navigationName(label)}`} onClick={close}>\n <ControlIcon icon=\"close\" />\n </button>\n )}\n </div>\n <nav className=\"sf-sidenav-nav\" aria-label={label}>\n {groups.map((group, g) => (\n <section key={group.label ?? g} className=\"sf-sidenav-group\" aria-labelledby={group.label ? `${id}-group-${g}` : undefined}>\n {group.label && (\n <h2 id={`${id}-group-${g}`} className=\"sf-sidenav-group-label\">\n {group.label}\n </h2>\n )}\n <ul>\n {group.items.map((item) => (\n <li key={item.id}>\n {item.href ? (\n <a href={item.href} aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </a>\n ) : (\n <button type=\"button\" aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </button>\n )}\n </li>\n ))}\n </ul>\n </section>\n ))}\n </nav>\n {footer && <div className=\"sf-sidenav-footer\">{footer}</div>}\n </div>\n </div>\n </div>\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfaces-ui/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "React components for Surfaces UI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"surfaces-ui",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"jsdom": "^31.0.0",
|
|
54
54
|
"react": "^19.3.1",
|
|
55
55
|
"react-dom": "^19.3.1",
|
|
56
|
-
"@surfaces-ui/discovery": "0.
|
|
56
|
+
"@surfaces-ui/discovery": "0.6.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@bufbuild/protobuf": "^2.17.0",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"@lezer/highlight": "^1.2.5",
|
|
68
68
|
"apache-arrow": "^21.2.0",
|
|
69
69
|
"echarts": "^6.1.0",
|
|
70
|
-
"@surfaces-ui/data": "0.
|
|
71
|
-
"@surfaces-ui/proto": "0.
|
|
72
|
-
"@surfaces-ui/tokens": "0.
|
|
73
|
-
"@surfaces-ui/trace": "0.
|
|
70
|
+
"@surfaces-ui/data": "0.6.0",
|
|
71
|
+
"@surfaces-ui/proto": "0.6.0",
|
|
72
|
+
"@surfaces-ui/tokens": "0.6.0",
|
|
73
|
+
"@surfaces-ui/trace": "0.6.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"react": ">=18",
|