@tearleads/windowing 0.2.16 → 0.2.18
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/package.json +1 -1
- package/routed/RoutedPane.css +8 -6
- package/routed/RoutedPaneSidebar.js +9 -1
- package/routed/RoutedPaneSidebar.js.map +1 -1
- package/sidebar/SidebarResize.d.ts +6 -2
- package/sidebar/SidebarResize.js +21 -19
- package/sidebar/SidebarResize.js.map +1 -1
- package/sidebar/useSidebarWidthBounds.d.ts +9 -0
- package/sidebar/useSidebarWidthBounds.js +33 -0
- package/sidebar/useSidebarWidthBounds.js.map +1 -0
- package/window/WindowSidebar.js +1 -1
- package/window/WindowSidebar.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tearleads/windowing",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "App-agnostic window management for React: window state, window chrome, and the menu and sidebar primitives it renders with.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
package/routed/RoutedPane.css
CHANGED
|
@@ -205,16 +205,19 @@
|
|
|
205
205
|
cursor: pointer;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
.routed-pane-iconbutton:hover:not(:disabled),
|
|
209
208
|
.routed-pane-iconbutton:focus-visible:not(:disabled) {
|
|
210
|
-
background: var(--app-hover-surface);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
.routed-pane-iconbutton[aria-expanded="true"] {
|
|
214
209
|
background: var(--emphasis-surface);
|
|
215
210
|
color: var(--emphasis-text);
|
|
216
211
|
}
|
|
217
212
|
|
|
213
|
+
@media (hover: hover) {
|
|
214
|
+
.routed-pane-iconbutton:hover:not(:disabled),
|
|
215
|
+
.routed-pane-taskbar-menu-button:hover {
|
|
216
|
+
background: var(--emphasis-surface);
|
|
217
|
+
color: var(--emphasis-text);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
218
221
|
.routed-pane-iconbutton:disabled {
|
|
219
222
|
opacity: var(--opacity-disabled);
|
|
220
223
|
cursor: default;
|
|
@@ -352,7 +355,6 @@
|
|
|
352
355
|
cursor: pointer;
|
|
353
356
|
}
|
|
354
357
|
|
|
355
|
-
.routed-pane-taskbar-menu-button:hover,
|
|
356
358
|
.routed-pane-taskbar-menu-button:focus-visible,
|
|
357
359
|
.routed-pane-taskbar-menu-button[aria-expanded="true"] {
|
|
358
360
|
background: var(--emphasis-surface);
|
|
@@ -2,6 +2,13 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { SidebarResizeHandle, useSidebarResize, } from "../sidebar/SidebarResize.js";
|
|
3
3
|
import "./RoutedPaneSidebar.css";
|
|
4
4
|
const DEFAULT_WIDTH = 224;
|
|
5
|
+
function getResizeContainer(sidebar) {
|
|
6
|
+
// The app bar spans sidebar + content in both launcher placements. Its width
|
|
7
|
+
// also changes when the side launcher expands, even if the viewport does not.
|
|
8
|
+
return (sidebar
|
|
9
|
+
.closest(".routed-pane")
|
|
10
|
+
?.querySelector(".routed-pane-appbar") ?? null);
|
|
11
|
+
}
|
|
5
12
|
function RoutedPaneMobileSidebar({ children, onClose, }) {
|
|
6
13
|
return (_jsxs(_Fragment, { children: [_jsx("button", { "aria-label": "Close sidebar", className: "routed-pane-scrim", type: "button", onClick: onClose }), _jsx("div", { className: "routed-pane-sidebar", id: "routed-pane-sidebar", role: "dialog", children: children })] }));
|
|
7
14
|
}
|
|
@@ -9,8 +16,9 @@ function RoutedPaneTabletSidebar({ children }) {
|
|
|
9
16
|
const resize = useSidebarResize({
|
|
10
17
|
defaultWidth: DEFAULT_WIDTH,
|
|
11
18
|
initialWidth: null,
|
|
19
|
+
getResizeContainer,
|
|
12
20
|
});
|
|
13
|
-
return (_jsxs("div", { className: "routed-pane-sidebar-frame", children: [_jsx("div", { className: "routed-pane-sidebar", id: "routed-pane-sidebar", ref: resize.sidebarRef, style: resize.width === null ? undefined : { width: resize.width }, children: children }), _jsx(SidebarResizeHandle, { className: "routed-pane-sidebar-resize-handle", controls: "routed-pane-sidebar", currentWidth: resize.resolvedWidth, onKeyDown: resize.handleKeyDown, onPointerDown: resize.handlePointerDown })] }));
|
|
21
|
+
return (_jsxs("div", { className: "routed-pane-sidebar-frame", children: [_jsx("div", { className: "routed-pane-sidebar", id: "routed-pane-sidebar", ref: resize.sidebarRef, style: resize.width === null ? undefined : { width: resize.width }, children: children }), _jsx(SidebarResizeHandle, { className: "routed-pane-sidebar-resize-handle", controls: "routed-pane-sidebar", currentWidth: resize.resolvedWidth, maxWidth: resize.maxWidth, onKeyDown: resize.handleKeyDown, onPointerDown: resize.handlePointerDown })] }));
|
|
14
22
|
}
|
|
15
23
|
export function RoutedPaneSidebar({ children, onClose, tier, }) {
|
|
16
24
|
return tier === "mobile" ? (_jsx(RoutedPaneMobileSidebar, { onClose: onClose, children: children })) : (_jsx(RoutedPaneTabletSidebar, { children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoutedPaneSidebar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/routed/RoutedPaneSidebar.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,yBAAyB,CAAC;AAEjC,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,SAAS,uBAAuB,CAAC,EAC/B,QAAQ,EACR,OAAO,GAIR;IACC,OAAO,CACL,8BACE,+BACa,eAAe,EAC1B,SAAS,EAAC,mBAAmB,EAC7B,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,OAAO,GAChB,EACF,cACE,SAAS,EAAC,qBAAqB,EAC/B,EAAE,EAAC,qBAAqB,EACxB,IAAI,EAAC,QAAQ,YAEZ,QAAQ,GACL,IACL,CACJ,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,EAAE,QAAQ,EAA2B;IACpE,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC9B,YAAY,EAAE,aAAa;QAC3B,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,OAAO,CACL,eAAK,SAAS,EAAC,2BAA2B,aACxC,cACE,SAAS,EAAC,qBAAqB,EAC/B,EAAE,EAAC,qBAAqB,EACxB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,YAEjE,QAAQ,GACL,EACN,KAAC,mBAAmB,IAClB,SAAS,EAAC,mCAAmC,EAC7C,QAAQ,EAAC,qBAAqB,EAC9B,YAAY,EAAE,MAAM,CAAC,aAAa,EAClC,SAAS,EAAE,MAAM,CAAC,aAAa,EAC/B,aAAa,EAAE,MAAM,CAAC,iBAAiB,GACvC,IACE,CACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,EAChC,QAAQ,EACR,OAAO,EACP,IAAI,GAKL;IACC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CACzB,KAAC,uBAAuB,IAAC,OAAO,EAAE,OAAO,YACtC,QAAQ,GACe,CAC3B,CAAC,CAAC,CAAC,CACF,KAAC,uBAAuB,cAAE,QAAQ,GAA2B,CAC9D,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport type { RoutedLayoutTier } from \"../launcher/useRoutedLayoutTier\";\nimport {\n SidebarResizeHandle,\n useSidebarResize,\n} from \"../sidebar/SidebarResize\";\nimport \"./RoutedPaneSidebar.css\";\n\nconst DEFAULT_WIDTH = 224;\n\nfunction RoutedPaneMobileSidebar({\n children,\n onClose,\n}: {\n children: ReactNode;\n onClose: () => void;\n}) {\n return (\n <>\n <button\n aria-label=\"Close sidebar\"\n className=\"routed-pane-scrim\"\n type=\"button\"\n onClick={onClose}\n />\n <div\n className=\"routed-pane-sidebar\"\n id=\"routed-pane-sidebar\"\n role=\"dialog\"\n >\n {children}\n </div>\n </>\n );\n}\n\nfunction RoutedPaneTabletSidebar({ children }: { children: ReactNode }) {\n const resize = useSidebarResize({\n defaultWidth: DEFAULT_WIDTH,\n initialWidth: null,\n });\n\n return (\n <div className=\"routed-pane-sidebar-frame\">\n <div\n className=\"routed-pane-sidebar\"\n id=\"routed-pane-sidebar\"\n ref={resize.sidebarRef}\n style={resize.width === null ? undefined : { width: resize.width }}\n >\n {children}\n </div>\n <SidebarResizeHandle\n className=\"routed-pane-sidebar-resize-handle\"\n controls=\"routed-pane-sidebar\"\n currentWidth={resize.resolvedWidth}\n onKeyDown={resize.handleKeyDown}\n onPointerDown={resize.handlePointerDown}\n />\n </div>\n );\n}\n\nexport function RoutedPaneSidebar({\n children,\n onClose,\n tier,\n}: {\n children: ReactNode;\n onClose: () => void;\n tier: RoutedLayoutTier;\n}) {\n return tier === \"mobile\" ? (\n <RoutedPaneMobileSidebar onClose={onClose}>\n {children}\n </RoutedPaneMobileSidebar>\n ) : (\n <RoutedPaneTabletSidebar>{children}</RoutedPaneTabletSidebar>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RoutedPaneSidebar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/routed/RoutedPaneSidebar.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,yBAAyB,CAAC;AAEjC,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,SAAS,kBAAkB,CAAC,OAAoB;IAC9C,6EAA6E;IAC7E,8EAA8E;IAC9E,OAAO,CACL,OAAO;SACJ,OAAO,CAAC,cAAc,CAAC;QACxB,EAAE,aAAa,CAAc,qBAAqB,CAAC,IAAI,IAAI,CAC9D,CAAC;AAC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,CAAC,CACF,KAAC,uBAAuB,cAAE,QAAQ,GAA2B,CAC9D,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport type { RoutedLayoutTier } from \"../launcher/useRoutedLayoutTier\";\nimport {\n SidebarResizeHandle,\n useSidebarResize,\n} from \"../sidebar/SidebarResize\";\nimport \"./RoutedPaneSidebar.css\";\n\nconst DEFAULT_WIDTH = 224;\n\nfunction getResizeContainer(sidebar: HTMLElement) {\n // The app bar spans sidebar + content in both launcher placements. Its width\n // also changes when the side launcher expands, even if the viewport does not.\n return (\n sidebar\n .closest(\".routed-pane\")\n ?.querySelector<HTMLElement>(\".routed-pane-appbar\") ?? null\n );\n}\n\nfunction RoutedPaneMobileSidebar({\n children,\n onClose,\n}: {\n children: ReactNode;\n onClose: () => void;\n}) {\n return (\n <>\n <button\n aria-label=\"Close sidebar\"\n className=\"routed-pane-scrim\"\n type=\"button\"\n onClick={onClose}\n />\n <div\n className=\"routed-pane-sidebar\"\n id=\"routed-pane-sidebar\"\n role=\"dialog\"\n >\n {children}\n </div>\n </>\n );\n}\n\nfunction RoutedPaneTabletSidebar({ children }: { children: ReactNode }) {\n const resize = useSidebarResize({\n defaultWidth: DEFAULT_WIDTH,\n initialWidth: null,\n getResizeContainer,\n });\n\n return (\n <div className=\"routed-pane-sidebar-frame\">\n <div\n className=\"routed-pane-sidebar\"\n id=\"routed-pane-sidebar\"\n ref={resize.sidebarRef}\n style={resize.width === null ? undefined : { width: resize.width }}\n >\n {children}\n </div>\n <SidebarResizeHandle\n className=\"routed-pane-sidebar-resize-handle\"\n controls=\"routed-pane-sidebar\"\n currentWidth={resize.resolvedWidth}\n maxWidth={resize.maxWidth}\n onKeyDown={resize.handleKeyDown}\n onPointerDown={resize.handlePointerDown}\n />\n </div>\n );\n}\n\nexport function RoutedPaneSidebar({\n children,\n onClose,\n tier,\n}: {\n children: ReactNode;\n onClose: () => void;\n tier: RoutedLayoutTier;\n}) {\n return tier === \"mobile\" ? (\n <RoutedPaneMobileSidebar onClose={onClose}>\n {children}\n </RoutedPaneMobileSidebar>\n ) : (\n <RoutedPaneTabletSidebar>{children}</RoutedPaneTabletSidebar>\n );\n}\n"]}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type RefObject } from "react";
|
|
2
|
-
export declare function useSidebarResize({ defaultWidth, initialWidth, }: {
|
|
2
|
+
export declare function useSidebarResize({ defaultWidth, initialWidth, getResizeContainer, }: {
|
|
3
3
|
defaultWidth: number;
|
|
4
4
|
initialWidth?: number | null;
|
|
5
|
+
/** Stable resolver for the element spanning sidebar + content, excluding the launcher rail. */
|
|
6
|
+
getResizeContainer?: (sidebar: HTMLElement) => HTMLElement | null;
|
|
5
7
|
}): {
|
|
6
8
|
handleKeyDown: (event: ReactKeyboardEvent<HTMLHRElement>) => void;
|
|
7
9
|
handlePointerDown: (event: ReactPointerEvent<HTMLHRElement>) => void;
|
|
10
|
+
maxWidth: number;
|
|
8
11
|
resolvedWidth: number;
|
|
9
12
|
sidebarRef: RefObject<HTMLDivElement | null>;
|
|
10
13
|
width: number | null;
|
|
11
14
|
};
|
|
12
|
-
export declare function SidebarResizeHandle({ className, controls, currentWidth, onKeyDown, onPointerDown, }: {
|
|
15
|
+
export declare function SidebarResizeHandle({ className, controls, currentWidth, maxWidth, onKeyDown, onPointerDown, }: {
|
|
13
16
|
className: string;
|
|
14
17
|
controls?: string | undefined;
|
|
15
18
|
currentWidth: number;
|
|
19
|
+
maxWidth?: number;
|
|
16
20
|
onKeyDown: (event: ReactKeyboardEvent<HTMLHRElement>) => void;
|
|
17
21
|
onPointerDown: (event: ReactPointerEvent<HTMLHRElement>) => void;
|
|
18
22
|
}): import("react").JSX.Element;
|
package/sidebar/SidebarResize.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
3
3
|
import "./SidebarResize.css";
|
|
4
|
-
|
|
5
|
-
const MAX_WIDTH = 400;
|
|
4
|
+
import { MIN_SIDEBAR_WIDTH as MIN_WIDTH, UNMEASURED_MAX_SIDEBAR_WIDTH, useSidebarWidthBounds, } from "./useSidebarWidthBounds.js";
|
|
6
5
|
const KEYBOARD_RESIZE_STEP = 10;
|
|
7
|
-
function clampSidebarWidth(width) {
|
|
8
|
-
return Math.min(
|
|
6
|
+
function clampSidebarWidth(width, maxWidth) {
|
|
7
|
+
return Math.min(maxWidth, Math.max(MIN_WIDTH, width));
|
|
9
8
|
}
|
|
10
|
-
function useSidebarDragEffect({ active, draggingRef, endDrag, setWidth, }) {
|
|
9
|
+
function useSidebarDragEffect({ active, draggingRef, endDrag, maxWidthRef, setWidth, }) {
|
|
11
10
|
useEffect(() => {
|
|
12
11
|
if (!active) {
|
|
13
12
|
return;
|
|
@@ -18,7 +17,7 @@ function useSidebarDragEffect({ active, draggingRef, endDrag, setWidth, }) {
|
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
19
|
const dx = event.clientX - dragState.startX;
|
|
21
|
-
setWidth(clampSidebarWidth(dragState.startWidth + dx));
|
|
20
|
+
setWidth(clampSidebarWidth(dragState.startWidth + dx, maxWidthRef.current));
|
|
22
21
|
}
|
|
23
22
|
function handlePointerEnd(event) {
|
|
24
23
|
if (event.pointerId === draggingRef.current?.pointerId) {
|
|
@@ -34,22 +33,23 @@ function useSidebarDragEffect({ active, draggingRef, endDrag, setWidth, }) {
|
|
|
34
33
|
document.removeEventListener("pointercancel", handlePointerEnd);
|
|
35
34
|
endDrag();
|
|
36
35
|
};
|
|
37
|
-
}, [active, draggingRef, endDrag, setWidth]);
|
|
36
|
+
}, [active, draggingRef, endDrag, maxWidthRef, setWidth]);
|
|
38
37
|
}
|
|
39
|
-
export function useSidebarResize({ defaultWidth, initialWidth = defaultWidth, }) {
|
|
38
|
+
export function useSidebarResize({ defaultWidth, initialWidth = defaultWidth, getResizeContainer, }) {
|
|
40
39
|
const [width, setWidth] = useState(initialWidth);
|
|
41
40
|
const [isDragging, setIsDragging] = useState(false);
|
|
42
41
|
const sidebarRef = useRef(null);
|
|
43
42
|
const draggingRef = useRef(null);
|
|
43
|
+
const { maxWidth, maxWidthRef } = useSidebarWidthBounds(sidebarRef, getResizeContainer);
|
|
44
44
|
const readCurrentWidth = useCallback(() => {
|
|
45
45
|
if (width !== null) {
|
|
46
|
-
return width;
|
|
46
|
+
return clampSidebarWidth(width, maxWidth);
|
|
47
47
|
}
|
|
48
48
|
const measuredWidth = sidebarRef.current?.getBoundingClientRect().width;
|
|
49
49
|
return measuredWidth && measuredWidth > 0
|
|
50
|
-
? clampSidebarWidth(measuredWidth)
|
|
51
|
-
: defaultWidth;
|
|
52
|
-
}, [defaultWidth, width]);
|
|
50
|
+
? clampSidebarWidth(measuredWidth, maxWidth)
|
|
51
|
+
: clampSidebarWidth(defaultWidth, maxWidth);
|
|
52
|
+
}, [defaultWidth, maxWidth, width]);
|
|
53
53
|
const endDrag = useCallback(() => {
|
|
54
54
|
if (!draggingRef.current) {
|
|
55
55
|
return;
|
|
@@ -63,6 +63,7 @@ export function useSidebarResize({ defaultWidth, initialWidth = defaultWidth, })
|
|
|
63
63
|
active: isDragging,
|
|
64
64
|
draggingRef,
|
|
65
65
|
endDrag,
|
|
66
|
+
maxWidthRef,
|
|
66
67
|
setWidth,
|
|
67
68
|
});
|
|
68
69
|
const handlePointerDown = useCallback((event) => {
|
|
@@ -89,7 +90,7 @@ export function useSidebarResize({ defaultWidth, initialWidth = defaultWidth, })
|
|
|
89
90
|
}
|
|
90
91
|
if (event.key === "End") {
|
|
91
92
|
event.preventDefault();
|
|
92
|
-
setWidth(
|
|
93
|
+
setWidth(maxWidth);
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
96
|
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") {
|
|
@@ -98,18 +99,19 @@ export function useSidebarResize({ defaultWidth, initialWidth = defaultWidth, })
|
|
|
98
99
|
event.preventDefault();
|
|
99
100
|
const direction = event.key === "ArrowLeft" ? -1 : 1;
|
|
100
101
|
const multiplier = event.shiftKey ? 5 : 1;
|
|
101
|
-
setWidth((
|
|
102
|
-
|
|
103
|
-
}, [readCurrentWidth]);
|
|
102
|
+
setWidth(clampSidebarWidth(readCurrentWidth() + direction * KEYBOARD_RESIZE_STEP * multiplier, maxWidth));
|
|
103
|
+
}, [maxWidth, readCurrentWidth]);
|
|
104
104
|
return {
|
|
105
105
|
handleKeyDown,
|
|
106
106
|
handlePointerDown,
|
|
107
|
+
maxWidth,
|
|
107
108
|
resolvedWidth: readCurrentWidth(),
|
|
108
109
|
sidebarRef,
|
|
109
|
-
width,
|
|
110
|
+
// Keep the chosen width when space returns, unless the user resizes again.
|
|
111
|
+
width: width === null ? null : clampSidebarWidth(width, maxWidth),
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
|
-
export function SidebarResizeHandle({ className, controls, currentWidth, onKeyDown, onPointerDown, }) {
|
|
113
|
-
return (_jsx("hr", { "aria-controls": controls, "aria-label": "Resize sidebar", "aria-orientation": "vertical", "aria-valuemax":
|
|
114
|
+
export function SidebarResizeHandle({ className, controls, currentWidth, maxWidth, onKeyDown, onPointerDown, }) {
|
|
115
|
+
return (_jsx("hr", { "aria-controls": controls, "aria-label": "Resize sidebar", "aria-orientation": "vertical", "aria-valuemax": maxWidth ?? Math.max(UNMEASURED_MAX_SIDEBAR_WIDTH, currentWidth), "aria-valuemin": MIN_WIDTH, "aria-valuenow": currentWidth, className: `sidebar-resize-handle ${className}`, onKeyDown: onKeyDown, onPointerDown: onPointerDown, tabIndex: 0 }));
|
|
114
116
|
}
|
|
115
117
|
//# sourceMappingURL=SidebarResize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SidebarResize.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/sidebar/SidebarResize.tsx"],"names":[],"mappings":";AAAA,O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AAK,EAAE,CAAC;YACxB,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,QAAQ,CAAC,SAAS,CAAC,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,GAAG,KAAK,WAAW,IAAI,KAAK,CAAC,GAAG,KAAK,YAAY,EAAE,CAAC;YAC5D,OAAO;QACT,CAAC;QAED,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,QAAQ,CAAC,CAAC,YAAY,EAAE,EAAE,CACxB,iBAAiB,CACf,CAAC,YAAY,IAAI,gBAAgB,EAAE,CAAC;YAClC,SAAS,GAAG,oBAAoB,GAAG,UAAU,CAChD,CACF,CAAC;IACJ,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,aAAa,EAAE,gBAAgB,EAAE;QACjC,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,aAAa,GAOd;IACC,OAAO,CACL,8BACiB,QAAQ,gBACZ,gBAAgB,sBACV,UAAU,mBACZ,SAAS,mBACT,SAAS,mBACT,YAAY,EAC3B,SAAS,EAAE,yBAAyB,SAAS,EAAE,EAC/C,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,GACX,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Dispatch,\n type KeyboardEvent as ReactKeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport \"./SidebarResize.css\";\n\nconst MIN_WIDTH = 80;\nconst MAX_WIDTH = 400;\nconst KEYBOARD_RESIZE_STEP = 10;\n\ninterface DragState {\n pointerId: number;\n startWidth: number;\n startX: number;\n}\n\nfunction clampSidebarWidth(width: number) {\n return Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, width));\n}\n\nfunction useSidebarDragEffect({\n active,\n draggingRef,\n endDrag,\n setWidth,\n}: {\n active: boolean;\n draggingRef: RefObject<DragState | null>;\n endDrag: () => void;\n setWidth: Dispatch<SetStateAction<number | null>>;\n}) {\n useEffect(() => {\n if (!active) {\n return;\n }\n\n function handlePointerMove(event: PointerEvent) {\n const dragState = draggingRef.current;\n if (!dragState || event.pointerId !== dragState.pointerId) {\n return;\n }\n\n const dx = event.clientX - dragState.startX;\n setWidth(clampSidebarWidth(dragState.startWidth + dx));\n }\n\n function handlePointerEnd(event: PointerEvent) {\n if (event.pointerId === draggingRef.current?.pointerId) {\n endDrag();\n }\n }\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerEnd);\n document.addEventListener(\"pointercancel\", handlePointerEnd);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerEnd);\n document.removeEventListener(\"pointercancel\", handlePointerEnd);\n endDrag();\n };\n }, [active, draggingRef, endDrag, setWidth]);\n}\n\nexport function useSidebarResize({\n defaultWidth,\n initialWidth = defaultWidth,\n}: {\n defaultWidth: number;\n initialWidth?: number | null;\n}) {\n const [width, setWidth] = useState<number | null>(initialWidth);\n const [isDragging, setIsDragging] = useState(false);\n const sidebarRef = useRef<HTMLDivElement>(null);\n const draggingRef = useRef<DragState | null>(null);\n\n const readCurrentWidth = useCallback(() => {\n if (width !== null) {\n return width;\n }\n\n const measuredWidth = sidebarRef.current?.getBoundingClientRect().width;\n return measuredWidth && measuredWidth > 0\n ? clampSidebarWidth(measuredWidth)\n : defaultWidth;\n }, [defaultWidth, width]);\n\n const endDrag = useCallback(() => {\n if (!draggingRef.current) {\n return;\n }\n\n draggingRef.current = null;\n setIsDragging(false);\n document.body.style.cursor = \"\";\n document.body.style.userSelect = \"\";\n }, []);\n\n useSidebarDragEffect({\n active: isDragging,\n draggingRef,\n endDrag,\n setWidth,\n });\n\n const handlePointerDown = useCallback(\n (event: ReactPointerEvent<HTMLHRElement>) => {\n if (event.button !== 0 || !event.isPrimary) {\n return;\n }\n\n event.preventDefault();\n const startWidth = readCurrentWidth();\n draggingRef.current = {\n pointerId: event.pointerId,\n startWidth,\n startX: event.clientX,\n };\n setWidth(startWidth);\n setIsDragging(true);\n document.body.style.cursor = \"col-resize\";\n document.body.style.userSelect = \"none\";\n },\n [readCurrentWidth],\n );\n\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLHRElement>) => {\n if (event.key === \"Home\") {\n event.preventDefault();\n setWidth(MIN_WIDTH);\n return;\n }\n\n if (event.key === \"End\") {\n event.preventDefault();\n setWidth(MAX_WIDTH);\n return;\n }\n\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") {\n return;\n }\n\n event.preventDefault();\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n const multiplier = event.shiftKey ? 5 : 1;\n setWidth((currentWidth) =>\n clampSidebarWidth(\n (currentWidth ?? readCurrentWidth()) +\n direction * KEYBOARD_RESIZE_STEP * multiplier,\n ),\n );\n },\n [readCurrentWidth],\n );\n\n return {\n handleKeyDown,\n handlePointerDown,\n resolvedWidth: readCurrentWidth(),\n sidebarRef,\n width,\n };\n}\n\nexport function SidebarResizeHandle({\n className,\n controls,\n currentWidth,\n onKeyDown,\n onPointerDown,\n}: {\n className: string;\n controls?: string | undefined;\n currentWidth: number;\n onKeyDown: (event: ReactKeyboardEvent<HTMLHRElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLHRElement>) => void;\n}) {\n return (\n <hr\n aria-controls={controls}\n aria-label=\"Resize sidebar\"\n aria-orientation=\"vertical\"\n aria-valuemax={MAX_WIDTH}\n aria-valuemin={MIN_WIDTH}\n aria-valuenow={currentWidth}\n className={`sidebar-resize-handle ${className}`}\n onKeyDown={onKeyDown}\n onPointerDown={onPointerDown}\n tabIndex={0}\n />\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SidebarResize.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/sidebar/SidebarResize.tsx"],"names":[],"mappings":";AAAA,OAAO,EAML,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EACL,iBAAiB,IAAI,SAAS,EAC9B,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAQhC,SAAS,iBAAiB,CAAC,KAAa,EAAE,QAAgB;IACxD,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,oBAAoB,CAAC,EAC5B,MAAM,EACN,WAAW,EACX,OAAO,EACP,WAAW,EACX,QAAQ,GAOT;IACC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO;QACT,CAAC;QAED,SAAS,iBAAiB,CAAC,KAAmB;YAC5C,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC;YACtC,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,EAAE,CAAC;gBAC1D,OAAO;YACT,CAAC;YAED,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;YAC5C,QAAQ,CACN,iBAAiB,CAAC,SAAS,CAAC,UAAU,GAAG,EAAE,EAAE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AAC,QAAQ,EAAE,gBAAgB,CAAC,CAC7B,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,QAAQ;QACR,aAAa,EAAE,gBAAgB,EAAE;QACjC,UAAU;QACV,2EAA2E;QAC3E,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC;KAClE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,GAQd;IACC,OAAO,CACL,8BACiB,QAAQ,gBACZ,gBAAgB,sBACV,UAAU,mBAEzB,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,4BAA4B,EAAE,YAAY,CAAC,mBAEnD,SAAS,mBACT,YAAY,EAC3B,SAAS,EAAE,yBAAyB,SAAS,EAAE,EAC/C,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,CAAC,GACX,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Dispatch,\n type KeyboardEvent as ReactKeyboardEvent,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n type SetStateAction,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport \"./SidebarResize.css\";\nimport {\n MIN_SIDEBAR_WIDTH as MIN_WIDTH,\n UNMEASURED_MAX_SIDEBAR_WIDTH,\n useSidebarWidthBounds,\n} from \"./useSidebarWidthBounds\";\n\nconst KEYBOARD_RESIZE_STEP = 10;\n\ninterface DragState {\n pointerId: number;\n startWidth: number;\n startX: number;\n}\n\nfunction clampSidebarWidth(width: number, maxWidth: number) {\n return Math.min(maxWidth, Math.max(MIN_WIDTH, width));\n}\n\nfunction useSidebarDragEffect({\n active,\n draggingRef,\n endDrag,\n maxWidthRef,\n setWidth,\n}: {\n active: boolean;\n draggingRef: RefObject<DragState | null>;\n endDrag: () => void;\n maxWidthRef: RefObject<number>;\n setWidth: Dispatch<SetStateAction<number | null>>;\n}) {\n useEffect(() => {\n if (!active) {\n return;\n }\n\n function handlePointerMove(event: PointerEvent) {\n const dragState = draggingRef.current;\n if (!dragState || event.pointerId !== dragState.pointerId) {\n return;\n }\n\n const dx = event.clientX - dragState.startX;\n setWidth(\n clampSidebarWidth(dragState.startWidth + dx, maxWidthRef.current),\n );\n }\n\n function handlePointerEnd(event: PointerEvent) {\n if (event.pointerId === draggingRef.current?.pointerId) {\n endDrag();\n }\n }\n\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handlePointerEnd);\n document.addEventListener(\"pointercancel\", handlePointerEnd);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handlePointerEnd);\n document.removeEventListener(\"pointercancel\", handlePointerEnd);\n endDrag();\n };\n }, [active, draggingRef, endDrag, maxWidthRef, setWidth]);\n}\n\nexport function useSidebarResize({\n defaultWidth,\n initialWidth = defaultWidth,\n getResizeContainer,\n}: {\n defaultWidth: number;\n initialWidth?: number | null;\n /** Stable resolver for the element spanning sidebar + content, excluding the launcher rail. */\n getResizeContainer?: (sidebar: HTMLElement) => HTMLElement | null;\n}) {\n const [width, setWidth] = useState<number | null>(initialWidth);\n const [isDragging, setIsDragging] = useState(false);\n const sidebarRef = useRef<HTMLDivElement>(null);\n const draggingRef = useRef<DragState | null>(null);\n const { maxWidth, maxWidthRef } = useSidebarWidthBounds(\n sidebarRef,\n getResizeContainer,\n );\n\n const readCurrentWidth = useCallback(() => {\n if (width !== null) {\n return clampSidebarWidth(width, maxWidth);\n }\n\n const measuredWidth = sidebarRef.current?.getBoundingClientRect().width;\n return measuredWidth && measuredWidth > 0\n ? clampSidebarWidth(measuredWidth, maxWidth)\n : clampSidebarWidth(defaultWidth, maxWidth);\n }, [defaultWidth, maxWidth, width]);\n\n const endDrag = useCallback(() => {\n if (!draggingRef.current) {\n return;\n }\n\n draggingRef.current = null;\n setIsDragging(false);\n document.body.style.cursor = \"\";\n document.body.style.userSelect = \"\";\n }, []);\n\n useSidebarDragEffect({\n active: isDragging,\n draggingRef,\n endDrag,\n maxWidthRef,\n setWidth,\n });\n\n const handlePointerDown = useCallback(\n (event: ReactPointerEvent<HTMLHRElement>) => {\n if (event.button !== 0 || !event.isPrimary) {\n return;\n }\n\n event.preventDefault();\n const startWidth = readCurrentWidth();\n draggingRef.current = {\n pointerId: event.pointerId,\n startWidth,\n startX: event.clientX,\n };\n setWidth(startWidth);\n setIsDragging(true);\n document.body.style.cursor = \"col-resize\";\n document.body.style.userSelect = \"none\";\n },\n [readCurrentWidth],\n );\n\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLHRElement>) => {\n if (event.key === \"Home\") {\n event.preventDefault();\n setWidth(MIN_WIDTH);\n return;\n }\n\n if (event.key === \"End\") {\n event.preventDefault();\n setWidth(maxWidth);\n return;\n }\n\n if (event.key !== \"ArrowLeft\" && event.key !== \"ArrowRight\") {\n return;\n }\n\n event.preventDefault();\n const direction = event.key === \"ArrowLeft\" ? -1 : 1;\n const multiplier = event.shiftKey ? 5 : 1;\n setWidth(\n clampSidebarWidth(\n readCurrentWidth() + direction * KEYBOARD_RESIZE_STEP * multiplier,\n maxWidth,\n ),\n );\n },\n [maxWidth, readCurrentWidth],\n );\n\n return {\n handleKeyDown,\n handlePointerDown,\n maxWidth,\n resolvedWidth: readCurrentWidth(),\n sidebarRef,\n // Keep the chosen width when space returns, unless the user resizes again.\n width: width === null ? null : clampSidebarWidth(width, maxWidth),\n };\n}\n\nexport function SidebarResizeHandle({\n className,\n controls,\n currentWidth,\n maxWidth,\n onKeyDown,\n onPointerDown,\n}: {\n className: string;\n controls?: string | undefined;\n currentWidth: number;\n maxWidth?: number;\n onKeyDown: (event: ReactKeyboardEvent<HTMLHRElement>) => void;\n onPointerDown: (event: ReactPointerEvent<HTMLHRElement>) => void;\n}) {\n return (\n <hr\n aria-controls={controls}\n aria-label=\"Resize sidebar\"\n aria-orientation=\"vertical\"\n aria-valuemax={\n maxWidth ?? Math.max(UNMEASURED_MAX_SIDEBAR_WIDTH, currentWidth)\n }\n aria-valuemin={MIN_WIDTH}\n aria-valuenow={currentWidth}\n className={`sidebar-resize-handle ${className}`}\n onKeyDown={onKeyDown}\n onPointerDown={onPointerDown}\n tabIndex={0}\n />\n );\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export declare const MIN_SIDEBAR_WIDTH = 80;
|
|
3
|
+
export declare const UNMEASURED_MAX_SIDEBAR_WIDTH = 400;
|
|
4
|
+
declare function parentContainer(sidebar: HTMLElement): HTMLElement | null;
|
|
5
|
+
export declare function useSidebarWidthBounds(sidebarRef: RefObject<HTMLDivElement | null>, getResizeContainer?: typeof parentContainer): {
|
|
6
|
+
maxWidth: number;
|
|
7
|
+
maxWidthRef: RefObject<number>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
export const MIN_SIDEBAR_WIDTH = 80;
|
|
3
|
+
export const UNMEASURED_MAX_SIDEBAR_WIDTH = 400;
|
|
4
|
+
function parentContainer(sidebar) {
|
|
5
|
+
return sidebar.parentElement;
|
|
6
|
+
}
|
|
7
|
+
export function useSidebarWidthBounds(sidebarRef, getResizeContainer = parentContainer) {
|
|
8
|
+
const [maxWidth, setMaxWidth] = useState(UNMEASURED_MAX_SIDEBAR_WIDTH);
|
|
9
|
+
const maxWidthRef = useRef(maxWidth);
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
const sidebar = sidebarRef.current;
|
|
12
|
+
const container = sidebar && getResizeContainer(sidebar);
|
|
13
|
+
if (!container)
|
|
14
|
+
return;
|
|
15
|
+
function measure() {
|
|
16
|
+
const availableWidth = container?.getBoundingClientRect().width ?? 0;
|
|
17
|
+
// Hidden layouts have no useful bounds until they become visible again.
|
|
18
|
+
if (availableWidth <= 0)
|
|
19
|
+
return;
|
|
20
|
+
const nextMax = Math.max(MIN_SIDEBAR_WIDTH, Math.floor(availableWidth * 0.9));
|
|
21
|
+
maxWidthRef.current = nextMax;
|
|
22
|
+
setMaxWidth(nextMax);
|
|
23
|
+
}
|
|
24
|
+
measure();
|
|
25
|
+
if (typeof ResizeObserver === "undefined")
|
|
26
|
+
return;
|
|
27
|
+
const observer = new ResizeObserver(measure);
|
|
28
|
+
observer.observe(container);
|
|
29
|
+
return () => observer.disconnect();
|
|
30
|
+
}, [getResizeContainer, sidebarRef]);
|
|
31
|
+
return { maxWidth, maxWidthRef };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=useSidebarWidthBounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSidebarWidthBounds.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/sidebar/useSidebarWidthBounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE1E,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEhD,SAAS,eAAe,CAAC,OAAoB;IAC3C,OAAO,OAAO,CAAC,aAAa,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,UAA4C,EAC5C,kBAAkB,GAAG,eAAe;IAEpC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,4BAA4B,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAErC,eAAe,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,MAAM,SAAS,GAAG,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS;YAAE,OAAO;QAEvB,SAAS,OAAO;YACd,MAAM,cAAc,GAAG,SAAS,EAAE,qBAAqB,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC;YACrE,wEAAwE;YACxE,IAAI,cAAc,IAAI,CAAC;gBAAE,OAAO;YAChC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CACtB,iBAAiB,EACjB,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,GAAG,CAAC,CACjC,CAAC;YACF,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC;YAC9B,WAAW,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,EAAE,CAAC;QACV,IAAI,OAAO,cAAc,KAAK,WAAW;YAAE,OAAO;QAClD,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;IAErC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { type RefObject, useLayoutEffect, useRef, useState } from \"react\";\n\nexport const MIN_SIDEBAR_WIDTH = 80;\nexport const UNMEASURED_MAX_SIDEBAR_WIDTH = 400;\n\nfunction parentContainer(sidebar: HTMLElement) {\n return sidebar.parentElement;\n}\n\nexport function useSidebarWidthBounds(\n sidebarRef: RefObject<HTMLDivElement | null>,\n getResizeContainer = parentContainer,\n) {\n const [maxWidth, setMaxWidth] = useState(UNMEASURED_MAX_SIDEBAR_WIDTH);\n const maxWidthRef = useRef(maxWidth);\n\n useLayoutEffect(() => {\n const sidebar = sidebarRef.current;\n const container = sidebar && getResizeContainer(sidebar);\n if (!container) return;\n\n function measure() {\n const availableWidth = container?.getBoundingClientRect().width ?? 0;\n // Hidden layouts have no useful bounds until they become visible again.\n if (availableWidth <= 0) return;\n const nextMax = Math.max(\n MIN_SIDEBAR_WIDTH,\n Math.floor(availableWidth * 0.9),\n );\n maxWidthRef.current = nextMax;\n setMaxWidth(nextMax);\n }\n\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(container);\n return () => observer.disconnect();\n }, [getResizeContainer, sidebarRef]);\n\n return { maxWidth, maxWidthRef };\n}\n"]}
|
package/window/WindowSidebar.js
CHANGED
|
@@ -4,6 +4,6 @@ import "./WindowSidebar.css";
|
|
|
4
4
|
const DEFAULT_WIDTH = 160;
|
|
5
5
|
export function WindowSidebar({ contentRef, defaultWidth = DEFAULT_WIDTH, sidebar, children, }) {
|
|
6
6
|
const resize = useSidebarResize({ defaultWidth });
|
|
7
|
-
return (_jsxs("div", { className: "window-sidebar-layout", children: [_jsx("div", { className: "window-sidebar", ref: resize.sidebarRef, style: { width: resize.width ?? defaultWidth }, children: sidebar }), _jsx(SidebarResizeHandle, { className: "window-sidebar-handle", currentWidth: resize.resolvedWidth, onKeyDown: resize.handleKeyDown, onPointerDown: resize.handlePointerDown }), _jsx("div", { className: "window-sidebar-content", ref: contentRef, tabIndex: -1, children: _jsx("div", { className: "window-sidebar-content-scroll", children: children }) })] }));
|
|
7
|
+
return (_jsxs("div", { className: "window-sidebar-layout", children: [_jsx("div", { className: "window-sidebar", ref: resize.sidebarRef, style: { width: resize.width ?? defaultWidth }, children: sidebar }), _jsx(SidebarResizeHandle, { className: "window-sidebar-handle", currentWidth: resize.resolvedWidth, maxWidth: resize.maxWidth, onKeyDown: resize.handleKeyDown, onPointerDown: resize.handlePointerDown }), _jsx("div", { className: "window-sidebar-content", ref: contentRef, tabIndex: -1, children: _jsx("div", { className: "window-sidebar-content-scroll", children: children }) })] }));
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=WindowSidebar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WindowSidebar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowSidebar.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,qBAAqB,CAAC;AAE7B,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,MAAM,UAAU,aAAa,CAAC,EAC5B,UAAU,EACV,YAAY,GAAG,aAAa,EAC5B,OAAO,EACP,QAAQ,GAKR;IACA,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAElD,OAAO,CACL,eAAK,SAAS,EAAC,uBAAuB,aACpC,cACE,SAAS,EAAC,gBAAgB,EAC1B,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,YAAY,EAAE,YAE7C,OAAO,GACJ,EACN,KAAC,mBAAmB,IAClB,SAAS,EAAC,uBAAuB,EACjC,YAAY,EAAE,MAAM,CAAC,aAAa,EAClC,SAAS,EAAE,MAAM,CAAC,aAAa,EAC/B,aAAa,EAAE,MAAM,CAAC,iBAAiB,GACvC,EAGF,cAAK,SAAS,EAAC,wBAAwB,EAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,YACnE,cAAK,SAAS,EAAC,+BAA+B,YAAE,QAAQ,GAAO,GAC3D,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { PropsWithChildren, Ref } from \"react\";\nimport {\n SidebarResizeHandle,\n useSidebarResize,\n} from \"../sidebar/SidebarResize\";\nimport \"./WindowSidebar.css\";\n\nconst DEFAULT_WIDTH = 160;\n\nexport function WindowSidebar({\n contentRef,\n defaultWidth = DEFAULT_WIDTH,\n sidebar,\n children,\n}: PropsWithChildren<{\n contentRef?: Ref<HTMLDivElement> | undefined;\n defaultWidth?: number;\n sidebar?: React.ReactNode;\n}>) {\n const resize = useSidebarResize({ defaultWidth });\n\n return (\n <div className=\"window-sidebar-layout\">\n <div\n className=\"window-sidebar\"\n ref={resize.sidebarRef}\n style={{ width: resize.width ?? defaultWidth }}\n >\n {sidebar}\n </div>\n <SidebarResizeHandle\n className=\"window-sidebar-handle\"\n currentWidth={resize.resolvedWidth}\n onKeyDown={resize.handleKeyDown}\n onPointerDown={resize.handlePointerDown}\n />\n {/* Focusable only to script, like `.window-body-content`: the overlay host\n is where focus lands when an overlay outlives the control that opened it. */}\n <div className=\"window-sidebar-content\" ref={contentRef} tabIndex={-1}>\n <div className=\"window-sidebar-content-scroll\">{children}</div>\n </div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WindowSidebar.js","sourceRoot":"","sources":["../../../home/runner/work/tearleads/tearleads/packages/windowing/src/window/WindowSidebar.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,qBAAqB,CAAC;AAE7B,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,MAAM,UAAU,aAAa,CAAC,EAC5B,UAAU,EACV,YAAY,GAAG,aAAa,EAC5B,OAAO,EACP,QAAQ,GAKR;IACA,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;IAElD,OAAO,CACL,eAAK,SAAS,EAAC,uBAAuB,aACpC,cACE,SAAS,EAAC,gBAAgB,EAC1B,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,YAAY,EAAE,YAE7C,OAAO,GACJ,EACN,KAAC,mBAAmB,IAClB,SAAS,EAAC,uBAAuB,EACjC,YAAY,EAAE,MAAM,CAAC,aAAa,EAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,SAAS,EAAE,MAAM,CAAC,aAAa,EAC/B,aAAa,EAAE,MAAM,CAAC,iBAAiB,GACvC,EAGF,cAAK,SAAS,EAAC,wBAAwB,EAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,YACnE,cAAK,SAAS,EAAC,+BAA+B,YAAE,QAAQ,GAAO,GAC3D,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { PropsWithChildren, Ref } from \"react\";\nimport {\n SidebarResizeHandle,\n useSidebarResize,\n} from \"../sidebar/SidebarResize\";\nimport \"./WindowSidebar.css\";\n\nconst DEFAULT_WIDTH = 160;\n\nexport function WindowSidebar({\n contentRef,\n defaultWidth = DEFAULT_WIDTH,\n sidebar,\n children,\n}: PropsWithChildren<{\n contentRef?: Ref<HTMLDivElement> | undefined;\n defaultWidth?: number;\n sidebar?: React.ReactNode;\n}>) {\n const resize = useSidebarResize({ defaultWidth });\n\n return (\n <div className=\"window-sidebar-layout\">\n <div\n className=\"window-sidebar\"\n ref={resize.sidebarRef}\n style={{ width: resize.width ?? defaultWidth }}\n >\n {sidebar}\n </div>\n <SidebarResizeHandle\n className=\"window-sidebar-handle\"\n currentWidth={resize.resolvedWidth}\n maxWidth={resize.maxWidth}\n onKeyDown={resize.handleKeyDown}\n onPointerDown={resize.handlePointerDown}\n />\n {/* Focusable only to script, like `.window-body-content`: the overlay host\n is where focus lands when an overlay outlives the control that opened it. */}\n <div className=\"window-sidebar-content\" ref={contentRef} tabIndex={-1}>\n <div className=\"window-sidebar-content-scroll\">{children}</div>\n </div>\n </div>\n );\n}\n"]}
|