@sybilion/uilib 1.4.13 → 1.4.15
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/agent-glossary/content-prompt.generated.ts +28 -23
- package/dist/agent-glossary/content.generated.ts +28 -23
- package/dist/agent-glossary/content.index.md +1 -1
- package/dist/agent-glossary/content.md +28 -23
- package/dist/agent-glossary/content.prompt.md +28 -23
- package/dist/agent-glossary/workspace.generated.ts +1 -1
- package/dist/agent-glossary/workspace.index.md +1 -1
- package/dist/agent-glossary/workspace.md +1 -1
- package/dist/esm/components/ui/Chat/ChatChrome/ChatChrome.js +28 -3
- package/dist/esm/components/ui/Chat/ChatSheet/useChatPanelChromeModel.js +31 -1
- package/dist/esm/components/ui/DropdownMenu/DropdownMenu.styl.js +2 -2
- package/dist/esm/components/ui/Page/Breadcrumbs/Breadcrumbs.js +28 -1
- package/dist/esm/components/ui/PanelResizeHandle/PanelResizeHandle.js +50 -0
- package/dist/esm/components/ui/Sidebar/Sidebar.styl.js +3 -3
- package/dist/esm/components/ui/Sidebar/SidebarAside.js +36 -0
- package/dist/esm/components/ui/Sidebar/SidebarContent/SidebarContent.js +13 -0
- package/dist/esm/components/ui/Sidebar/SidebarContent/SidebarContent.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarFooter/SidebarFooter.js +9 -0
- package/dist/esm/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarGroup/SidebarGroup.js +9 -0
- package/dist/esm/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.js +11 -0
- package/dist/esm/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenu/SidebarMenu.js +15 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.js +11 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.js +16 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.js +12 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.js +32 -0
- package/dist/esm/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarProvider/SidebarProvider.js +314 -0
- package/dist/esm/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarRail/SidebarRail.js +11 -0
- package/dist/esm/components/ui/Sidebar/SidebarRail/SidebarRail.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.js +26 -0
- package/dist/esm/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.js +10 -0
- package/dist/esm/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.js +16 -0
- package/dist/esm/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl.js +7 -0
- package/dist/esm/components/ui/Sidebar/sidebarConstants.js +7 -0
- package/dist/esm/components/ui/Sidebar/sidebarContext.js +28 -0
- package/dist/esm/components/ui/Sidebar/sidebarUtils.js +41 -0
- package/dist/esm/components/widgets/DriversComparisonChart/DriversComparisonChart.js +26 -5
- package/dist/esm/components/widgets/PerformanceChart/PerformanceTable.js +26 -4
- package/dist/esm/components/widgets/SidebarDatasetsItemsGrouped/SidebarDatasetsItemsGrouped.js +28 -1
- package/dist/esm/index.js +18 -1
- package/dist/esm/types/src/components/ui/PanelResizeHandle/PanelResizeHandle.d.ts +9 -0
- package/dist/esm/types/src/components/ui/Sidebar/Sidebar.d.ts +19 -106
- package/dist/esm/types/src/components/ui/Sidebar/Sidebar.types.d.ts +41 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarAside.d.ts +2 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarContent/SidebarContent.d.ts +3 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.d.ts +2 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.d.ts +2 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.d.ts +4 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.d.ts +4 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.d.ts +5 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.d.ts +10 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.d.ts +3 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.d.ts +9 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.d.ts +11 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarRail/SidebarRail.d.ts +2 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.d.ts +4 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.d.ts +3 -0
- package/dist/esm/types/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.d.ts +3 -0
- package/dist/esm/types/src/components/ui/Sidebar/sidebarConstants.d.ts +5 -0
- package/dist/esm/types/src/components/ui/Sidebar/sidebarContext.d.ts +7 -0
- package/dist/esm/types/src/components/ui/Sidebar/sidebarUtils.d.ts +3 -0
- package/package.json +1 -1
- package/src/components/ui/ChartAreaInteractive/AGENT.md +0 -4
- package/src/components/ui/Chat/ChatChrome/ChatChrome.tsx +5 -2
- package/src/components/ui/DropdownMenu/DropdownMenu.styl +4 -1
- package/src/components/ui/PanelResizeHandle/PanelResizeHandle.tsx +89 -0
- package/src/components/ui/Sidebar/Sidebar.styl +23 -621
- package/src/components/ui/Sidebar/Sidebar.styl.d.ts +0 -33
- package/src/components/ui/Sidebar/Sidebar.tsx +25 -1145
- package/src/components/ui/Sidebar/Sidebar.types.ts +46 -0
- package/src/components/ui/Sidebar/SidebarAside.tsx +92 -0
- package/src/components/ui/Sidebar/SidebarContent/SidebarContent.styl +27 -0
- package/src/components/ui/Sidebar/SidebarContent/SidebarContent.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarContent/SidebarContent.tsx +29 -0
- package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl +7 -0
- package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarFooter/SidebarFooter.tsx +15 -0
- package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl +10 -0
- package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarGroup/SidebarGroup.tsx +15 -0
- package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl +34 -0
- package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarGroupAction/SidebarGroupAction.tsx +23 -0
- package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl +60 -0
- package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.styl.d.ts +12 -0
- package/src/components/ui/Sidebar/SidebarMenu/SidebarMenu.tsx +40 -0
- package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl +73 -0
- package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.styl.d.ts +8 -0
- package/src/components/ui/Sidebar/SidebarMenuAction/SidebarMenuAction.tsx +31 -0
- package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl +107 -0
- package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.styl.d.ts +15 -0
- package/src/components/ui/Sidebar/SidebarMenuButton/SidebarMenuButton.tsx +82 -0
- package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl +39 -0
- package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.styl.d.ts +8 -0
- package/src/components/ui/Sidebar/SidebarMenuSub/SidebarMenuSub.tsx +29 -0
- package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl +71 -0
- package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.styl.d.ts +8 -0
- package/src/components/ui/Sidebar/SidebarMenuSubButton/SidebarMenuSubButton.tsx +80 -0
- package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl +45 -0
- package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.styl.d.ts +9 -0
- package/src/components/ui/Sidebar/SidebarProvider/SidebarProvider.tsx +447 -0
- package/src/components/ui/Sidebar/SidebarRail/SidebarRail.styl +42 -0
- package/src/components/ui/Sidebar/SidebarRail/SidebarRail.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarRail/SidebarRail.tsx +22 -0
- package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl +37 -0
- package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarResizeHandle/SidebarResizeHandle.tsx +54 -0
- package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl +7 -0
- package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarSeparator/SidebarSeparator.tsx +20 -0
- package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl +11 -0
- package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.styl.d.ts +7 -0
- package/src/components/ui/Sidebar/SidebarTrigger/SidebarTrigger.tsx +34 -0
- package/src/components/ui/Sidebar/sidebarConstants.ts +6 -0
- package/src/components/ui/Sidebar/sidebarContext.tsx +46 -0
- package/src/components/ui/Sidebar/sidebarUtils.ts +47 -0
- package/src/components/widgets/DriverMap/AGENT.md +0 -4
- package/src/components/widgets/DriversComparisonChart/AGENT.md +0 -4
- package/src/components/widgets/PerformanceChart/AGENT.md +0 -4
- package/src/components/widgets/SidebarDatasetsItemsGrouped/AGENT.md +28 -11
- package/src/docs/components/DocsGuidance/DocsGuidance.styl +1 -0
- package/src/docs/components/DocsSidebar/DocsSidebar.tsx +14 -8
- package/src/docs/pages/SmartTextTruncatePage.styl +2 -14
- package/src/docs/pages/SmartTextTruncatePage.styl.d.ts +0 -1
- package/src/docs/pages/SmartTextTruncatePage.tsx +0 -6
- package/dist/esm/components/ui/Sidebar/Sidebar.js +0 -541
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import {
|
|
3
|
+
CSSProperties,
|
|
4
|
+
ComponentProps,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
|
|
13
|
+
import { TooltipProvider } from '#uilib/components/ui/Tooltip';
|
|
14
|
+
import {
|
|
15
|
+
CHAT_WIDTH_STORAGE_KEY,
|
|
16
|
+
SIDEBAR_WIDTH_STORAGE_KEY_PX,
|
|
17
|
+
clampChatWidthPx,
|
|
18
|
+
clampSidebarWidthPx,
|
|
19
|
+
shellFitsSidebarsLayout,
|
|
20
|
+
} from '#uilib/hooks/panelWidth';
|
|
21
|
+
import useEvent from '#uilib/hooks/useEvent';
|
|
22
|
+
import { useIsSidebarSheetLayout } from '#uilib/hooks/useIsSidebarSheetLayout';
|
|
23
|
+
import { useShellWidthObserver } from '#uilib/hooks/useShellWidthObserver';
|
|
24
|
+
import { getCookie, setCookie } from '#uilib/lib/cookie';
|
|
25
|
+
import { getCookiePreferences } from '#uilib/lib/cookie-consent/cookie-consent';
|
|
26
|
+
import { LS } from '@homecode/ui';
|
|
27
|
+
|
|
28
|
+
import type { SetSidebarOpenOptions } from '../Sidebar.types';
|
|
29
|
+
import S from './SidebarProvider.styl';
|
|
30
|
+
import {
|
|
31
|
+
DISMISS_CHAT_FOR_LAYOUT_EVENT,
|
|
32
|
+
SIDEBAR_KEYBOARD_SHORTCUT,
|
|
33
|
+
SIDEBAR_WIDTH_ICON,
|
|
34
|
+
} from '../sidebarConstants';
|
|
35
|
+
import { SidebarActionsContext, SidebarStateContext } from '../sidebarContext';
|
|
36
|
+
import {
|
|
37
|
+
isEditableKeyboardTarget,
|
|
38
|
+
readInitialChatWidthPx,
|
|
39
|
+
readInitialSidebarWidthPx,
|
|
40
|
+
} from '../sidebarUtils';
|
|
41
|
+
|
|
42
|
+
export function SidebarProvider({
|
|
43
|
+
defaultOpen = (getCookie('isSidebarOpen') as unknown as boolean) ?? true,
|
|
44
|
+
className,
|
|
45
|
+
style,
|
|
46
|
+
children,
|
|
47
|
+
userId,
|
|
48
|
+
sidebarWidthStorageKey,
|
|
49
|
+
persistSidebarWidthWithoutConsent = false,
|
|
50
|
+
...props
|
|
51
|
+
}: ComponentProps<'div'> & {
|
|
52
|
+
defaultOpen?: boolean;
|
|
53
|
+
open?: boolean;
|
|
54
|
+
onOpenChange?: (open: boolean) => void;
|
|
55
|
+
userId?: string | number | null;
|
|
56
|
+
/** LocalStorage key for sidebar width (pixels). Defaults to `sidebarWidthPx`. */
|
|
57
|
+
sidebarWidthStorageKey?: string;
|
|
58
|
+
/** When true, sidebar width is saved without functional cookie consent (e.g. internal docs). */
|
|
59
|
+
persistSidebarWidthWithoutConsent?: boolean;
|
|
60
|
+
}) {
|
|
61
|
+
const sidebarLsKey = sidebarWidthStorageKey ?? SIDEBAR_WIDTH_STORAGE_KEY_PX;
|
|
62
|
+
const allowPersistSidebarWidth =
|
|
63
|
+
persistSidebarWidthWithoutConsent ||
|
|
64
|
+
Boolean(getCookiePreferences(userId)?.functional);
|
|
65
|
+
|
|
66
|
+
const isSidebarSheetLayout = useIsSidebarSheetLayout();
|
|
67
|
+
const [isOpen, setIsOpen] = useState(
|
|
68
|
+
isSidebarSheetLayout ? false : defaultOpen,
|
|
69
|
+
);
|
|
70
|
+
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
71
|
+
const shellWidthRef = useRef(0);
|
|
72
|
+
const prevShellWidthRef = useRef(0);
|
|
73
|
+
const [shellEl, setShellEl] = useState<HTMLDivElement | null>(null);
|
|
74
|
+
const [chatPanelContainer, setChatPanelContainer] =
|
|
75
|
+
useState<HTMLDivElement | null>(null);
|
|
76
|
+
const onChatPanelMount = useCallback((node: HTMLDivElement | null) => {
|
|
77
|
+
setChatPanelContainer(node);
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
const [sidebarWidthPx, _setSidebarWidthPx] = useState(() =>
|
|
81
|
+
readInitialSidebarWidthPx(sidebarLsKey),
|
|
82
|
+
);
|
|
83
|
+
const [chatWidthPx, _setChatWidthPx] = useState(readInitialChatWidthPx);
|
|
84
|
+
const [chatPanelOpen, _setChatPanelOpen] = useState(false);
|
|
85
|
+
const sidebarWidthRef = useRef(sidebarWidthPx);
|
|
86
|
+
const chatWidthRef = useRef(chatWidthPx);
|
|
87
|
+
const isOpenRef = useRef(isOpen);
|
|
88
|
+
const chatPanelOpenRef = useRef(chatPanelOpen);
|
|
89
|
+
/** Left nav was auto-closed because chat opened on a narrow shell; reopen when chat closes. */
|
|
90
|
+
const sidebarAutoClosedForChatRef = useRef(false);
|
|
91
|
+
sidebarWidthRef.current = sidebarWidthPx;
|
|
92
|
+
chatWidthRef.current = chatWidthPx;
|
|
93
|
+
isOpenRef.current = isOpen;
|
|
94
|
+
chatPanelOpenRef.current = chatPanelOpen;
|
|
95
|
+
|
|
96
|
+
const mergeWrapperRef = useCallback((el: HTMLDivElement | null) => {
|
|
97
|
+
wrapperRef.current = el;
|
|
98
|
+
setShellEl(el);
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
const getShellWidth = useCallback((): number => {
|
|
102
|
+
const w = shellWidthRef.current;
|
|
103
|
+
if (w > 0) return w;
|
|
104
|
+
if (wrapperRef.current) {
|
|
105
|
+
const cw = wrapperRef.current.getBoundingClientRect().width;
|
|
106
|
+
if (cw > 0) return cw;
|
|
107
|
+
}
|
|
108
|
+
return typeof window !== 'undefined' ? window.innerWidth : 1200;
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
const getChatPanelOpen = useCallback(
|
|
112
|
+
(): boolean => chatPanelOpenRef.current,
|
|
113
|
+
[],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const setSidebarWidthPx = useCallback(
|
|
117
|
+
(px: number, options?: { persist?: boolean }) => {
|
|
118
|
+
const persist = options?.persist !== false;
|
|
119
|
+
const shellW = getShellWidth();
|
|
120
|
+
const next = clampSidebarWidthPx(px, shellW, {
|
|
121
|
+
chatPanelOpen: chatPanelOpenRef.current,
|
|
122
|
+
chatWidthPx: chatWidthRef.current,
|
|
123
|
+
});
|
|
124
|
+
sidebarWidthRef.current = next;
|
|
125
|
+
|
|
126
|
+
// Live drag: update CSS var only — avoid re-rendering the whole nav tree each frame.
|
|
127
|
+
if (wrapperRef.current) {
|
|
128
|
+
wrapperRef.current.style.setProperty('--sidebar-width', `${next}px`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!persist) return;
|
|
132
|
+
|
|
133
|
+
_setSidebarWidthPx(next);
|
|
134
|
+
if (allowPersistSidebarWidth) {
|
|
135
|
+
LS.set(sidebarLsKey, next);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[getShellWidth, sidebarLsKey, allowPersistSidebarWidth],
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const setChatWidthPx = useCallback(
|
|
142
|
+
(px: number, options?: { persist?: boolean }) => {
|
|
143
|
+
const persist = options?.persist !== false;
|
|
144
|
+
const shellW = getShellWidth();
|
|
145
|
+
const effectiveSidebarW = isOpenRef.current ? sidebarWidthRef.current : 0;
|
|
146
|
+
const next = clampChatWidthPx(px, shellW, effectiveSidebarW);
|
|
147
|
+
_setChatWidthPx(next);
|
|
148
|
+
if (persist && getCookiePreferences(userId)?.functional) {
|
|
149
|
+
LS.set(CHAT_WIDTH_STORAGE_KEY, next);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
[getShellWidth, userId],
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const handleShellResize = useCallback(
|
|
156
|
+
(shellW: number) => {
|
|
157
|
+
shellWidthRef.current = shellW;
|
|
158
|
+
const prev = prevShellWidthRef.current;
|
|
159
|
+
if (prev > 0 && shellW > 0) {
|
|
160
|
+
const s = sidebarWidthRef.current;
|
|
161
|
+
const c = chatWidthRef.current;
|
|
162
|
+
const sScaled = Math.round((s * shellW) / prev);
|
|
163
|
+
const cScaled = Math.round((c * shellW) / prev);
|
|
164
|
+
const effS = (navOpen: boolean, sidebarPx: number) =>
|
|
165
|
+
navOpen ? sidebarPx : 0;
|
|
166
|
+
let cNext = clampChatWidthPx(
|
|
167
|
+
cScaled,
|
|
168
|
+
shellW,
|
|
169
|
+
effS(isOpenRef.current, sScaled),
|
|
170
|
+
);
|
|
171
|
+
let sNext = clampSidebarWidthPx(sScaled, shellW, {
|
|
172
|
+
chatPanelOpen: chatPanelOpenRef.current,
|
|
173
|
+
chatWidthPx: cNext,
|
|
174
|
+
});
|
|
175
|
+
cNext = clampChatWidthPx(
|
|
176
|
+
cScaled,
|
|
177
|
+
shellW,
|
|
178
|
+
effS(isOpenRef.current, sNext),
|
|
179
|
+
);
|
|
180
|
+
sNext = clampSidebarWidthPx(sScaled, shellW, {
|
|
181
|
+
chatPanelOpen: chatPanelOpenRef.current,
|
|
182
|
+
chatWidthPx: cNext,
|
|
183
|
+
});
|
|
184
|
+
_setSidebarWidthPx(sNext);
|
|
185
|
+
_setChatWidthPx(cNext);
|
|
186
|
+
if (allowPersistSidebarWidth) {
|
|
187
|
+
LS.set(sidebarLsKey, sNext);
|
|
188
|
+
}
|
|
189
|
+
if (getCookiePreferences(userId)?.functional) {
|
|
190
|
+
LS.set(CHAT_WIDTH_STORAGE_KEY, cNext);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
prevShellWidthRef.current = shellW;
|
|
194
|
+
},
|
|
195
|
+
[userId, sidebarLsKey, allowPersistSidebarWidth],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const fitPanelWidthsToShell = useCallback(() => {
|
|
199
|
+
const shellW = getShellWidth();
|
|
200
|
+
if (shellW <= 0) return;
|
|
201
|
+
const s = sidebarWidthRef.current;
|
|
202
|
+
const c = chatWidthRef.current;
|
|
203
|
+
const effS = isOpenRef.current ? s : 0;
|
|
204
|
+
let cNext = clampChatWidthPx(c, shellW, effS);
|
|
205
|
+
let sNext = clampSidebarWidthPx(s, shellW, {
|
|
206
|
+
chatPanelOpen: chatPanelOpenRef.current,
|
|
207
|
+
chatWidthPx: cNext,
|
|
208
|
+
});
|
|
209
|
+
cNext = clampChatWidthPx(c, shellW, isOpenRef.current ? sNext : 0);
|
|
210
|
+
sNext = clampSidebarWidthPx(s, shellW, {
|
|
211
|
+
chatPanelOpen: chatPanelOpenRef.current,
|
|
212
|
+
chatWidthPx: cNext,
|
|
213
|
+
});
|
|
214
|
+
if (sNext !== s || cNext !== c) {
|
|
215
|
+
_setSidebarWidthPx(sNext);
|
|
216
|
+
_setChatWidthPx(cNext);
|
|
217
|
+
if (allowPersistSidebarWidth) {
|
|
218
|
+
LS.set(sidebarLsKey, sNext);
|
|
219
|
+
}
|
|
220
|
+
if (getCookiePreferences(userId)?.functional) {
|
|
221
|
+
LS.set(CHAT_WIDTH_STORAGE_KEY, cNext);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, [getShellWidth, userId, sidebarLsKey, allowPersistSidebarWidth]);
|
|
225
|
+
|
|
226
|
+
useLayoutEffect(() => {
|
|
227
|
+
if (!shellEl || isSidebarSheetLayout) return;
|
|
228
|
+
fitPanelWidthsToShell();
|
|
229
|
+
}, [
|
|
230
|
+
shellEl,
|
|
231
|
+
chatPanelOpen,
|
|
232
|
+
isSidebarSheetLayout,
|
|
233
|
+
isOpen,
|
|
234
|
+
fitPanelWidthsToShell,
|
|
235
|
+
]);
|
|
236
|
+
|
|
237
|
+
useShellWidthObserver(shellEl, handleShellResize);
|
|
238
|
+
|
|
239
|
+
const closeOppositeSidebarIfNoSpace = useCallback(
|
|
240
|
+
(openingMain: boolean, openingChat: boolean) => {
|
|
241
|
+
if (isSidebarSheetLayout) return;
|
|
242
|
+
const shellW = getShellWidth();
|
|
243
|
+
const layoutAfterOpen = {
|
|
244
|
+
mainSidebarOpen: openingMain || isOpenRef.current,
|
|
245
|
+
chatPanelOpen: openingChat || chatPanelOpenRef.current,
|
|
246
|
+
sidebarWidthPx: sidebarWidthRef.current,
|
|
247
|
+
chatWidthPx: chatWidthRef.current,
|
|
248
|
+
};
|
|
249
|
+
if (shellFitsSidebarsLayout(shellW, layoutAfterOpen)) return;
|
|
250
|
+
if (openingMain && chatPanelOpenRef.current) {
|
|
251
|
+
_setChatPanelOpen(false);
|
|
252
|
+
if (typeof window !== 'undefined') {
|
|
253
|
+
window.dispatchEvent(new CustomEvent(DISMISS_CHAT_FOR_LAYOUT_EVENT));
|
|
254
|
+
}
|
|
255
|
+
} else if (openingChat && isOpenRef.current) {
|
|
256
|
+
sidebarAutoClosedForChatRef.current = true;
|
|
257
|
+
setIsOpen(false);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
[isSidebarSheetLayout, getShellWidth],
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const setChatPanelOpen = useCallback(
|
|
264
|
+
(open: boolean) => {
|
|
265
|
+
if (open) {
|
|
266
|
+
closeOppositeSidebarIfNoSpace(false, true);
|
|
267
|
+
const shellW = getShellWidth();
|
|
268
|
+
if (shellW > 0 && !isSidebarSheetLayout) {
|
|
269
|
+
const navOpenAfter =
|
|
270
|
+
isOpenRef.current && !sidebarAutoClosedForChatRef.current;
|
|
271
|
+
const effNav = navOpenAfter ? sidebarWidthRef.current : 0;
|
|
272
|
+
const cNext = clampChatWidthPx(chatWidthRef.current, shellW, effNav);
|
|
273
|
+
if (cNext !== chatWidthRef.current) {
|
|
274
|
+
_setChatWidthPx(cNext);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
_setChatPanelOpen(true);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
_setChatPanelOpen(false);
|
|
281
|
+
if (sidebarAutoClosedForChatRef.current) {
|
|
282
|
+
sidebarAutoClosedForChatRef.current = false;
|
|
283
|
+
setIsOpen(true);
|
|
284
|
+
if (getCookiePreferences(userId)?.functional) {
|
|
285
|
+
setCookie('isSidebarOpen', 'true', 60 * 60 * 24 * 7);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
[
|
|
290
|
+
closeOppositeSidebarIfNoSpace,
|
|
291
|
+
getShellWidth,
|
|
292
|
+
isSidebarSheetLayout,
|
|
293
|
+
userId,
|
|
294
|
+
],
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const setOpen = useCallback(
|
|
298
|
+
(value: boolean, options?: SetSidebarOpenOptions) => {
|
|
299
|
+
const layoutAutoClose = options?.layoutAutoClose === true;
|
|
300
|
+
|
|
301
|
+
if (value) {
|
|
302
|
+
sidebarAutoClosedForChatRef.current = false;
|
|
303
|
+
closeOppositeSidebarIfNoSpace(true, false);
|
|
304
|
+
} else if (layoutAutoClose) {
|
|
305
|
+
sidebarAutoClosedForChatRef.current = true;
|
|
306
|
+
} else {
|
|
307
|
+
sidebarAutoClosedForChatRef.current = false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const useViewTransition =
|
|
311
|
+
options?.viewTransition !== false &&
|
|
312
|
+
!isSidebarSheetLayout &&
|
|
313
|
+
'startViewTransition' in document &&
|
|
314
|
+
document.startViewTransition;
|
|
315
|
+
|
|
316
|
+
if (useViewTransition) {
|
|
317
|
+
document.startViewTransition(() => {
|
|
318
|
+
setIsOpen(value);
|
|
319
|
+
});
|
|
320
|
+
} else {
|
|
321
|
+
setIsOpen(value);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (!layoutAutoClose && getCookiePreferences(userId)?.functional) {
|
|
325
|
+
setCookie('isSidebarOpen', value.toString(), 60 * 60 * 24 * 7);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
[isSidebarSheetLayout, userId, closeOppositeSidebarIfNoSpace],
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
const toggleSidebar = useCallback(
|
|
332
|
+
() => setOpen(!isOpenRef.current),
|
|
333
|
+
[setOpen],
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
useEffect(() => {
|
|
337
|
+
const shell = wrapperRef.current;
|
|
338
|
+
if (!shell) return;
|
|
339
|
+
if (chatPanelOpen) {
|
|
340
|
+
shell.setAttribute('data-chat-open', '');
|
|
341
|
+
if (isSidebarSheetLayout) {
|
|
342
|
+
shell.style.setProperty('--chat-panel-width', '100%');
|
|
343
|
+
shell.style.setProperty('--chat-panel-height', '100dvh');
|
|
344
|
+
} else {
|
|
345
|
+
shell.style.setProperty('--chat-panel-width', `${chatWidthPx}px`);
|
|
346
|
+
shell.style.removeProperty('--chat-panel-height');
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
shell.removeAttribute('data-chat-open');
|
|
350
|
+
shell.style.setProperty('--chat-panel-width', '0px');
|
|
351
|
+
shell.style.removeProperty('--chat-panel-height');
|
|
352
|
+
}
|
|
353
|
+
}, [chatPanelOpen, isSidebarSheetLayout, chatWidthPx]);
|
|
354
|
+
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
return () => {
|
|
357
|
+
const shell = wrapperRef.current;
|
|
358
|
+
if (!shell) return;
|
|
359
|
+
shell.removeAttribute('data-chat-open');
|
|
360
|
+
shell.style.setProperty('--chat-panel-width', '0px');
|
|
361
|
+
shell.style.removeProperty('--chat-panel-height');
|
|
362
|
+
};
|
|
363
|
+
}, []);
|
|
364
|
+
|
|
365
|
+
useEvent({
|
|
366
|
+
event: 'keydown',
|
|
367
|
+
callback: (e: KeyboardEvent) => {
|
|
368
|
+
const isToggleShortcut =
|
|
369
|
+
(e.key === SIDEBAR_KEYBOARD_SHORTCUT && (e.metaKey || e.ctrlKey)) ||
|
|
370
|
+
(e.key === '/' && !isEditableKeyboardTarget(document.activeElement));
|
|
371
|
+
|
|
372
|
+
if (isToggleShortcut) {
|
|
373
|
+
e.preventDefault();
|
|
374
|
+
toggleSidebar();
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const sidebarActionsValue = useMemo(
|
|
380
|
+
() => ({
|
|
381
|
+
setOpen,
|
|
382
|
+
toggleSidebar,
|
|
383
|
+
setSidebarWidthPx,
|
|
384
|
+
setChatWidthPx,
|
|
385
|
+
setChatPanelOpen,
|
|
386
|
+
getShellWidth,
|
|
387
|
+
getChatPanelOpen,
|
|
388
|
+
}),
|
|
389
|
+
[
|
|
390
|
+
setOpen,
|
|
391
|
+
toggleSidebar,
|
|
392
|
+
setSidebarWidthPx,
|
|
393
|
+
setChatWidthPx,
|
|
394
|
+
setChatPanelOpen,
|
|
395
|
+
getShellWidth,
|
|
396
|
+
getChatPanelOpen,
|
|
397
|
+
],
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
const sidebarStateValue = useMemo(
|
|
401
|
+
() => ({
|
|
402
|
+
isOpen,
|
|
403
|
+
sidebarWidthPx,
|
|
404
|
+
chatWidthPx,
|
|
405
|
+
chatPanelOpen,
|
|
406
|
+
chatPanelContainer,
|
|
407
|
+
sidebarWrapperRef: wrapperRef,
|
|
408
|
+
}),
|
|
409
|
+
[isOpen, sidebarWidthPx, chatWidthPx, chatPanelOpen, chatPanelContainer],
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
<SidebarActionsContext.Provider value={sidebarActionsValue}>
|
|
414
|
+
<SidebarStateContext.Provider value={sidebarStateValue}>
|
|
415
|
+
<TooltipProvider delayDuration={0}>
|
|
416
|
+
<div
|
|
417
|
+
ref={mergeWrapperRef}
|
|
418
|
+
data-slot="sidebar-wrapper"
|
|
419
|
+
data-state={isOpen ? 'expanded' : 'collapsed'}
|
|
420
|
+
style={
|
|
421
|
+
{
|
|
422
|
+
'--sidebar-width': `${sidebarWidthPx}px`,
|
|
423
|
+
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
|
424
|
+
...style,
|
|
425
|
+
} as CSSProperties
|
|
426
|
+
}
|
|
427
|
+
className={cn(S.sidebarWrapper, className)}
|
|
428
|
+
{...props}
|
|
429
|
+
>
|
|
430
|
+
<div
|
|
431
|
+
className={S.sidebarMainShell}
|
|
432
|
+
// style={{ viewTransitionName: 'sidebar-gap' }}
|
|
433
|
+
>
|
|
434
|
+
{children}
|
|
435
|
+
</div>
|
|
436
|
+
<div
|
|
437
|
+
ref={onChatPanelMount}
|
|
438
|
+
className={S.chatPanelMount}
|
|
439
|
+
data-slot="chat-panel-mount"
|
|
440
|
+
// style={{ viewTransitionName: 'sidebar-container' }}
|
|
441
|
+
/>
|
|
442
|
+
</div>
|
|
443
|
+
</TooltipProvider>
|
|
444
|
+
</SidebarStateContext.Provider>
|
|
445
|
+
</SidebarActionsContext.Provider>
|
|
446
|
+
);
|
|
447
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
@import '../../../../lib/theme.styl';
|
|
2
|
+
|
|
3
|
+
.sidebarRail
|
|
4
|
+
position absolute
|
|
5
|
+
inset-y 0
|
|
6
|
+
z-index 20
|
|
7
|
+
display hidden
|
|
8
|
+
width 1rem
|
|
9
|
+
// transform translateX(-50%)
|
|
10
|
+
transition all ease-out
|
|
11
|
+
&:hover::after
|
|
12
|
+
background-color var(--sidebar-border)
|
|
13
|
+
&[data-side="left"]
|
|
14
|
+
right -1rem
|
|
15
|
+
&[data-side="right"]
|
|
16
|
+
left 0
|
|
17
|
+
&::after
|
|
18
|
+
content ""
|
|
19
|
+
position absolute
|
|
20
|
+
inset-y 0
|
|
21
|
+
left 50%
|
|
22
|
+
width 2px
|
|
23
|
+
@media (min-width 640px)
|
|
24
|
+
display flex
|
|
25
|
+
&[data-side="left"]
|
|
26
|
+
cursor w-resize
|
|
27
|
+
&[data-side="right"]
|
|
28
|
+
cursor e-resize
|
|
29
|
+
&[data-side="left"][data-state="collapsed"]
|
|
30
|
+
cursor e-resize
|
|
31
|
+
&[data-side="right"][data-state="collapsed"]
|
|
32
|
+
cursor w-resize
|
|
33
|
+
&[data-collapsible="offcanvas"]
|
|
34
|
+
transform translateX(0)
|
|
35
|
+
&:hover
|
|
36
|
+
background-color var(--sidebar)
|
|
37
|
+
&::after
|
|
38
|
+
left 100%
|
|
39
|
+
&[data-side="left"][data-collapsible="offcanvas"]
|
|
40
|
+
right -0.5rem
|
|
41
|
+
&[data-side="right"][data-collapsible="offcanvas"]
|
|
42
|
+
left -0.5rem
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
import S from './SidebarRail.styl';
|
|
5
|
+
import { useSidebarActions } from '../sidebarContext';
|
|
6
|
+
|
|
7
|
+
export function SidebarRail({ className, ...props }: ComponentProps<'button'>) {
|
|
8
|
+
const { toggleSidebar } = useSidebarActions();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<button
|
|
12
|
+
data-sidebar="rail"
|
|
13
|
+
data-slot="sidebar-rail"
|
|
14
|
+
aria-label="Toggle Sidebar"
|
|
15
|
+
tabIndex={-1}
|
|
16
|
+
onClick={toggleSidebar}
|
|
17
|
+
title="Toggle Sidebar"
|
|
18
|
+
className={cn(S.sidebarRail, className)}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@import '../../../../lib/theme.styl';
|
|
2
|
+
|
|
3
|
+
.sidebarResizeHandle
|
|
4
|
+
position absolute
|
|
5
|
+
top -200px
|
|
6
|
+
// bottom 40px
|
|
7
|
+
height calc(100vh + 200px - var(--app-banner-height, 0px))
|
|
8
|
+
z-index 30
|
|
9
|
+
width 5px
|
|
10
|
+
border-radius 2.5px
|
|
11
|
+
user-select none
|
|
12
|
+
touch-action none
|
|
13
|
+
background-color transparent
|
|
14
|
+
transition opacity 150ms ease-out
|
|
15
|
+
background-color var(--page-color)
|
|
16
|
+
opacity 0
|
|
17
|
+
|
|
18
|
+
&::before
|
|
19
|
+
content ""
|
|
20
|
+
position absolute
|
|
21
|
+
right 0
|
|
22
|
+
height 100%
|
|
23
|
+
width 30px
|
|
24
|
+
cursor col-resize
|
|
25
|
+
|
|
26
|
+
&[data-side="left"]
|
|
27
|
+
right 2px
|
|
28
|
+
&[data-side="right"]
|
|
29
|
+
left 0
|
|
30
|
+
&:hover
|
|
31
|
+
opacity 1
|
|
32
|
+
&:active
|
|
33
|
+
opacity 0
|
|
34
|
+
|
|
35
|
+
[data-full-height-resizer] &
|
|
36
|
+
top -80px
|
|
37
|
+
height calc(100vh - var(--gap-top) * -1 - var(--app-banner-height, 0px))
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { ComponentProps, useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
import { PanelResizeHandle } from '#uilib/components/ui/PanelResizeHandle/PanelResizeHandle';
|
|
5
|
+
import { useIsSidebarSheetLayout } from '#uilib/hooks/useIsSidebarSheetLayout';
|
|
6
|
+
|
|
7
|
+
import { useSidebarActions, useSidebarState } from '../sidebarContext';
|
|
8
|
+
import S from './SidebarResizeHandle.styl';
|
|
9
|
+
|
|
10
|
+
export function SidebarResizeHandle({
|
|
11
|
+
className,
|
|
12
|
+
side = 'left',
|
|
13
|
+
...props
|
|
14
|
+
}: ComponentProps<'div'> & { side?: 'left' | 'right' }) {
|
|
15
|
+
const { isOpen, sidebarWidthPx } = useSidebarState();
|
|
16
|
+
const { setSidebarWidthPx, getShellWidth } = useSidebarActions();
|
|
17
|
+
const isSidebarSheetLayout = useIsSidebarSheetLayout();
|
|
18
|
+
|
|
19
|
+
const edge: 'leading' | 'trailing' = side === 'left' ? 'trailing' : 'leading';
|
|
20
|
+
|
|
21
|
+
const onDragWidth = useCallback(
|
|
22
|
+
(rawPx: number) => {
|
|
23
|
+
setSidebarWidthPx(rawPx, { persist: false });
|
|
24
|
+
},
|
|
25
|
+
[setSidebarWidthPx],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const onDragComplete = useCallback(
|
|
29
|
+
(finalRawPx: number) => {
|
|
30
|
+
setSidebarWidthPx(finalRawPx, { persist: true });
|
|
31
|
+
},
|
|
32
|
+
[setSidebarWidthPx],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (isSidebarSheetLayout || !isOpen) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<PanelResizeHandle
|
|
41
|
+
edge={edge}
|
|
42
|
+
isActive={isOpen && !isSidebarSheetLayout}
|
|
43
|
+
startWidthPx={sidebarWidthPx}
|
|
44
|
+
getShellWidth={getShellWidth}
|
|
45
|
+
onDragWidth={onDragWidth}
|
|
46
|
+
onDragComplete={onDragComplete}
|
|
47
|
+
data-sidebar="resize-handle"
|
|
48
|
+
data-slot="sidebar-resize-handle"
|
|
49
|
+
data-side={side}
|
|
50
|
+
className={cn(S.sidebarResizeHandle, className)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
import { Separator } from '#uilib/components/ui/Separator';
|
|
5
|
+
|
|
6
|
+
import S from './SidebarSeparator.styl';
|
|
7
|
+
|
|
8
|
+
export function SidebarSeparator({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}: ComponentProps<typeof Separator>) {
|
|
12
|
+
return (
|
|
13
|
+
<Separator
|
|
14
|
+
data-slot="sidebar-separator"
|
|
15
|
+
data-sidebar="separator"
|
|
16
|
+
className={cn(S.sidebarSeparator, className)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|