mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
remove some timer
This commit is contained in:
@@ -16,26 +16,28 @@ export const root = style({
|
|||||||
width: panelWidthVar,
|
width: panelWidthVar,
|
||||||
minWidth: panelWidthVar,
|
minWidth: panelWidthVar,
|
||||||
height: '100%',
|
height: '100%',
|
||||||
|
zIndex: 4,
|
||||||
|
transform: 'translateX(0)',
|
||||||
|
maxWidth: '50%',
|
||||||
selectors: {
|
selectors: {
|
||||||
'&[data-is-floating="true"]': {
|
'&[data-open="false"][data-handle-position="right"],&[data-is-floating="true"][data-handle-position="right"]':
|
||||||
position: 'absolute',
|
{
|
||||||
width: `calc(${panelWidthVar})`,
|
marginLeft: `calc(${panelWidthVar} * -1)`,
|
||||||
zIndex: 4,
|
},
|
||||||
},
|
'&[data-open="false"][data-handle-position="left"],&[data-is-floating="true"][data-handle-position="left"]':
|
||||||
'&[data-open="true"]': {
|
{
|
||||||
maxWidth: '50%',
|
marginRight: `calc(${panelWidthVar} * -1)`,
|
||||||
},
|
},
|
||||||
'&[data-open="false"][data-handle-position="right"]': {
|
'&[data-open="true"][data-handle-position="right"][data-is-floating="true"]':
|
||||||
marginLeft: `calc(${panelWidthVar} * -1)`,
|
{
|
||||||
},
|
transform: `translateX(${panelWidthVar})`,
|
||||||
'&[data-open="false"][data-handle-position="left"]': {
|
},
|
||||||
marginRight: `calc(${panelWidthVar} * -1)`,
|
'&[data-open="true"][data-handle-position="left"][data-is-floating="true"]':
|
||||||
},
|
{
|
||||||
'&[data-enable-animation="true"][data-is-floating="false"]': {
|
transform: `translateX(-${panelWidthVar})`,
|
||||||
transition: `margin-left ${animationTimeout} .05s, margin-right ${animationTimeout} .05s, width ${animationTimeout} .05s,background ${animationTimeout} .05s,scale ${animationTimeout} .05s`,
|
},
|
||||||
},
|
'&[data-enable-animation="true"]': {
|
||||||
'&[data-enable-animation="true"][data-is-floating="true"]': {
|
transition: `margin-left ${animationTimeout}, margin-right ${animationTimeout}, transform ${animationTimeout}, background ${animationTimeout}`,
|
||||||
transition: 'margin-left 0.5s cubic-bezier(0.22,1,0.36,1)',
|
|
||||||
},
|
},
|
||||||
'&[data-transition-state="exited"]': {
|
'&[data-transition-state="exited"]': {
|
||||||
// avoid focus on hidden panel
|
// avoid focus on hidden panel
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import {
|
import { forwardRef, useCallback, useLayoutEffect, useRef } from 'react';
|
||||||
forwardRef,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useLayoutEffect,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import { useTransition } from 'react-transition-state';
|
import { useTransition } from 'react-transition-state';
|
||||||
|
|
||||||
import * as styles from './resize-panel.css';
|
import * as styles from './resize-panel.css';
|
||||||
@@ -129,17 +122,6 @@ const ResizeHandle = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// delay initial animation to avoid flickering
|
|
||||||
function useEnableAnimation() {
|
|
||||||
const [enable, setEnable] = useState(false);
|
|
||||||
useEffect(() => {
|
|
||||||
window.setTimeout(() => {
|
|
||||||
setEnable(true);
|
|
||||||
}, 500);
|
|
||||||
}, []);
|
|
||||||
return enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
const animationTimeout = 300;
|
const animationTimeout = 300;
|
||||||
|
|
||||||
export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
|
export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
|
||||||
@@ -152,7 +134,7 @@ export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
|
|||||||
maxWidth,
|
maxWidth,
|
||||||
width,
|
width,
|
||||||
floating,
|
floating,
|
||||||
enableAnimation: _enableAnimation = true,
|
enableAnimation = true,
|
||||||
open,
|
open,
|
||||||
unmountOnExit,
|
unmountOnExit,
|
||||||
onOpen,
|
onOpen,
|
||||||
@@ -165,7 +147,6 @@ export const ResizePanel = forwardRef<HTMLDivElement, ResizePanelProps>(
|
|||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
const enableAnimation = useEnableAnimation() && _enableAnimation;
|
|
||||||
const safeWidth = Math.min(maxWidth, Math.max(minWidth, width));
|
const safeWidth = Math.min(maxWidth, Math.max(minWidth, width));
|
||||||
const [{ status }, toggle] = useTransition({
|
const [{ status }, toggle] = useTransition({
|
||||||
timeout: animationTimeout,
|
timeout: animationTimeout,
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ const DesktopLayout = ({ children }: PropsWithChildren) => {
|
|||||||
<AppTabsHeader
|
<AppTabsHeader
|
||||||
left={
|
left={
|
||||||
<>
|
<>
|
||||||
<SidebarSwitch show enableOpenHoverSidebar />
|
<SidebarSwitch show />
|
||||||
<NavigationButtons />
|
<NavigationButtons />
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,8 @@ interface HeaderPros {
|
|||||||
export const Header = ({ left, center, right }: HeaderPros) => {
|
export const Header = ({ left, center, right }: HeaderPros) => {
|
||||||
const appSidebarService = useService(AppSidebarService).sidebar;
|
const appSidebarService = useService(AppSidebarService).sidebar;
|
||||||
const open = useLiveData(appSidebarService.open$);
|
const open = useLiveData(appSidebarService.open$);
|
||||||
const appSidebarFloating = useLiveData(appSidebarService.responsiveFloating$);
|
|
||||||
const hoverFloating = useLiveData(appSidebarService.hoverFloating$);
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={clsx(style.header)} data-open={open} data-testid="header">
|
||||||
className={clsx(style.header)}
|
|
||||||
data-open={open}
|
|
||||||
data-sidebar-floating={appSidebarFloating || hoverFloating}
|
|
||||||
data-testid="header"
|
|
||||||
>
|
|
||||||
<div className={clsx(style.headerSideContainer)}>
|
<div className={clsx(style.headerSideContainer)}>
|
||||||
<div className={clsx(style.headerItem, 'left')}>
|
<div className={clsx(style.headerItem, 'left')}>
|
||||||
<div>{left}</div>
|
<div>{left}</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { cssVar, lightCssVariables } from '@toeverything/theme';
|
import { cssVar, lightCssVariables } from '@toeverything/theme';
|
||||||
import { createVar, globalStyle, keyframes, style } from '@vanilla-extract/css';
|
import { createVar, globalStyle, style } from '@vanilla-extract/css';
|
||||||
|
|
||||||
export const panelWidthVar = createVar('panel-width');
|
export const panelWidthVar = createVar('panel-width');
|
||||||
|
|
||||||
@@ -42,19 +42,7 @@ globalStyle(`html[data-theme="dark"] ${appStyle}`, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const anime = keyframes({
|
|
||||||
'0%': {
|
|
||||||
marginLeft: '8px',
|
|
||||||
},
|
|
||||||
'100%': {
|
|
||||||
marginLeft: '0',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const mainContainerStyle = style({
|
export const mainContainerStyle = style({
|
||||||
vars: {
|
|
||||||
[panelWidthVar]: '256px',
|
|
||||||
},
|
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
zIndex: 0,
|
zIndex: 0,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -76,14 +64,6 @@ export const mainContainerStyle = style({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'&[data-side-bar-open="true"][data-show-pin-sidebar-animation="true"]': {
|
|
||||||
marginLeft: panelWidthVar,
|
|
||||||
transition: 'margin-left 0.5s ease-in-out',
|
|
||||||
},
|
|
||||||
'&[data-client-border="true"][data-side-bar-open="true"][data-side-bar-floating="false"]':
|
|
||||||
{
|
|
||||||
animation: `${anime} 0.5s ease-in-out forwards`,
|
|
||||||
},
|
|
||||||
'&[data-client-border="true"][data-is-desktop="true"]': {
|
'&[data-client-border="true"][data-is-desktop="true"]': {
|
||||||
marginTop: 0,
|
marginTop: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,22 +1,15 @@
|
|||||||
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
|
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
|
||||||
import { AppSidebarService } from '@affine/core/modules/app-sidebar';
|
|
||||||
import {
|
import {
|
||||||
DocsService,
|
DocsService,
|
||||||
GlobalContextService,
|
GlobalContextService,
|
||||||
useLiveData,
|
useLiveData,
|
||||||
useService,
|
useService,
|
||||||
} from '@toeverything/infra';
|
} from '@toeverything/infra';
|
||||||
import { assignInlineVars } from '@vanilla-extract/dynamic';
|
|
||||||
import { clsx } from 'clsx';
|
import { clsx } from 'clsx';
|
||||||
import type { HTMLAttributes, PropsWithChildren, ReactElement } from 'react';
|
import type { HTMLAttributes, PropsWithChildren, ReactElement } from 'react';
|
||||||
import { forwardRef, useMemo } from 'react';
|
import { forwardRef } from 'react';
|
||||||
|
|
||||||
import {
|
import { appStyle, mainContainerStyle, toolStyle } from './index.css';
|
||||||
appStyle,
|
|
||||||
mainContainerStyle,
|
|
||||||
panelWidthVar,
|
|
||||||
toolStyle,
|
|
||||||
} from './index.css';
|
|
||||||
|
|
||||||
export type WorkspaceRootProps = PropsWithChildren<{
|
export type WorkspaceRootProps = PropsWithChildren<{
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -54,41 +47,16 @@ export interface MainContainerProps extends HTMLAttributes<HTMLDivElement> {}
|
|||||||
export const MainContainer = forwardRef<
|
export const MainContainer = forwardRef<
|
||||||
HTMLDivElement,
|
HTMLDivElement,
|
||||||
PropsWithChildren<MainContainerProps>
|
PropsWithChildren<MainContainerProps>
|
||||||
>(function MainContainer(
|
>(function MainContainer({ className, children, ...props }, ref): ReactElement {
|
||||||
{ className, children, style, ...props },
|
|
||||||
ref
|
|
||||||
): ReactElement {
|
|
||||||
const appSidebarService = useService(AppSidebarService).sidebar;
|
|
||||||
const appSideBarOpen = useLiveData(appSidebarService.open$);
|
|
||||||
const appSidebarHoverFloating = useLiveData(appSidebarService.hoverFloating$);
|
|
||||||
const appSideBarWidth = useLiveData(appSidebarService.width$);
|
|
||||||
|
|
||||||
const showAppSideBarPinAnimation = useLiveData(
|
|
||||||
appSidebarService.showFloatToPinAnimation$
|
|
||||||
);
|
|
||||||
const { appSettings } = useAppSettingHelper();
|
const { appSettings } = useAppSettingHelper();
|
||||||
|
|
||||||
const combinedStyle = useMemo(() => {
|
|
||||||
const dynamicStyle = assignInlineVars({
|
|
||||||
[panelWidthVar]: `${appSideBarWidth}px`,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
...style,
|
|
||||||
...dynamicStyle,
|
|
||||||
};
|
|
||||||
}, [appSideBarWidth, style]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
{...props}
|
{...props}
|
||||||
style={combinedStyle}
|
|
||||||
className={clsx(mainContainerStyle, className)}
|
className={clsx(mainContainerStyle, className)}
|
||||||
data-is-desktop={BUILD_CONFIG.isElectron}
|
data-is-desktop={BUILD_CONFIG.isElectron}
|
||||||
data-transparent={false}
|
data-transparent={false}
|
||||||
data-client-border={appSettings.clientBorder}
|
data-client-border={appSettings.clientBorder}
|
||||||
data-side-bar-open={appSideBarOpen}
|
|
||||||
data-side-bar-floating={appSidebarHoverFloating}
|
|
||||||
data-show-pin-sidebar-animation={showAppSideBarPinAnimation}
|
|
||||||
data-testid="main-container"
|
data-testid="main-container"
|
||||||
ref={ref}
|
ref={ref}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import { map } from 'rxjs';
|
|||||||
|
|
||||||
import type { AppSidebarState } from '../providers/storage';
|
import type { AppSidebarState } from '../providers/storage';
|
||||||
|
|
||||||
const isMobile = !BUILD_CONFIG.isElectron && window.innerWidth < 768;
|
|
||||||
|
|
||||||
enum APP_SIDEBAR_STATE {
|
enum APP_SIDEBAR_STATE {
|
||||||
OPEN = 'open',
|
OPEN = 'open',
|
||||||
WIDTH = 'width',
|
WIDTH = 'width',
|
||||||
@@ -15,11 +13,15 @@ export class AppSidebar extends Entity {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* whether the sidebar is open,
|
||||||
|
* even if the sidebar is not open, hovering can show the floating sidebar
|
||||||
|
*/
|
||||||
open$ = LiveData.from(
|
open$ = LiveData.from(
|
||||||
this.appSidebarState
|
this.appSidebarState
|
||||||
.watch<boolean>(APP_SIDEBAR_STATE.OPEN)
|
.watch<boolean>(APP_SIDEBAR_STATE.OPEN)
|
||||||
.pipe(map(value => value ?? !isMobile)),
|
.pipe(map(value => value ?? true)),
|
||||||
!isMobile
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
width$ = LiveData.from(
|
width$ = LiveData.from(
|
||||||
@@ -28,11 +30,17 @@ export class AppSidebar extends Entity {
|
|||||||
.pipe(map(value => value ?? 248)),
|
.pipe(map(value => value ?? 248)),
|
||||||
248
|
248
|
||||||
);
|
);
|
||||||
responsiveFloating$ = new LiveData<boolean>(isMobile);
|
|
||||||
hoverFloating$ = new LiveData<boolean>(false);
|
|
||||||
resizing$ = new LiveData<boolean>(false);
|
|
||||||
|
|
||||||
showFloatToPinAnimation$ = new LiveData<boolean>(false);
|
/**
|
||||||
|
* hovering can show the floating sidebar, without open it
|
||||||
|
*/
|
||||||
|
hovering$ = new LiveData<boolean>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* small screen mode, will disable hover effect
|
||||||
|
*/
|
||||||
|
smallScreenMode$ = new LiveData<boolean>(false);
|
||||||
|
resizing$ = new LiveData<boolean>(false);
|
||||||
|
|
||||||
getCachedAppSidebarOpenState = () => {
|
getCachedAppSidebarOpenState = () => {
|
||||||
return this.appSidebarState.get<boolean>(APP_SIDEBAR_STATE.OPEN);
|
return this.appSidebarState.get<boolean>(APP_SIDEBAR_STATE.OPEN);
|
||||||
@@ -44,26 +52,15 @@ export class AppSidebar extends Entity {
|
|||||||
|
|
||||||
setOpen = (open: boolean) => {
|
setOpen = (open: boolean) => {
|
||||||
this.appSidebarState.set(APP_SIDEBAR_STATE.OPEN, open);
|
this.appSidebarState.set(APP_SIDEBAR_STATE.OPEN, open);
|
||||||
if (!open && this.hoverFloating$.value) {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
this.setHoverFloating(false);
|
|
||||||
}, 500);
|
|
||||||
return () => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
setResponsiveFloating = (floating: boolean) => {
|
setSmallScreenMode = (smallScreenMode: boolean) => {
|
||||||
this.responsiveFloating$.next(floating);
|
this.smallScreenMode$.next(smallScreenMode);
|
||||||
};
|
};
|
||||||
|
|
||||||
setHoverFloating = (hoverFloating: boolean) => {
|
setHovering = (hoverFloating: boolean) => {
|
||||||
if (hoverFloating) {
|
this.hovering$.next(hoverFloating);
|
||||||
this.showFloatToPinAnimation$.next(false);
|
|
||||||
}
|
|
||||||
this.hoverFloating$.next(hoverFloating);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
setResizing = (resizing: boolean) => {
|
setResizing = (resizing: boolean) => {
|
||||||
@@ -73,8 +70,4 @@ export class AppSidebar extends Entity {
|
|||||||
setWidth = (width: number) => {
|
setWidth = (width: number) => {
|
||||||
this.appSidebarState.set(APP_SIDEBAR_STATE.WIDTH, width);
|
this.appSidebarState.set(APP_SIDEBAR_STATE.WIDTH, width);
|
||||||
};
|
};
|
||||||
|
|
||||||
setShowFloatToPinAnimation = (show: boolean) => {
|
|
||||||
this.showFloatToPinAnimation$.next(show);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ export const hoverNavWrapperStyle = style({
|
|||||||
boxShadow: cssVar('--affine-popover-shadow'),
|
boxShadow: cssVar('--affine-popover-shadow'),
|
||||||
borderRadius: '6px',
|
borderRadius: '6px',
|
||||||
},
|
},
|
||||||
'&[data-is-floating="true"][data-show-pin-animation="true"]': {
|
|
||||||
marginLeft: '0',
|
|
||||||
},
|
|
||||||
'&[data-is-floating="true"][data-is-electron="true"]': {
|
'&[data-is-floating="true"][data-is-electron="true"]': {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
marginTop: '-4px',
|
marginTop: '-4px',
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { debounce } from 'lodash-es';
|
import { debounce } from 'lodash-es';
|
||||||
import type { PropsWithChildren, ReactElement } from 'react';
|
import type { PropsWithChildren, ReactElement } from 'react';
|
||||||
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { AppSidebarService } from '../services/app-sidebar';
|
import { AppSidebarService } from '../services/app-sidebar';
|
||||||
import * as styles from './fallback.css';
|
import * as styles from './fallback.css';
|
||||||
@@ -45,21 +45,45 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
|||||||
|
|
||||||
const open = useLiveData(appSidebarService.open$);
|
const open = useLiveData(appSidebarService.open$);
|
||||||
const width = useLiveData(appSidebarService.width$);
|
const width = useLiveData(appSidebarService.width$);
|
||||||
const responsiveFloating = useLiveData(appSidebarService.responsiveFloating$);
|
const smallScreenMode = useLiveData(appSidebarService.smallScreenMode$);
|
||||||
const hoverFloating = useLiveData(appSidebarService.hoverFloating$);
|
const hovering = useLiveData(appSidebarService.hovering$) && open !== true;
|
||||||
const resizing = useLiveData(appSidebarService.resizing$);
|
const resizing = useLiveData(appSidebarService.resizing$);
|
||||||
const showFloatToPinAnimation = useLiveData(
|
const [deferredHovering, setDeferredHovering] = useState(false);
|
||||||
appSidebarService.showFloatToPinAnimation$
|
useEffect(() => {
|
||||||
);
|
if (open) {
|
||||||
|
// if open, we don't need to show the floating sidebar
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
setDeferredHovering(false);
|
||||||
|
return;
|
||||||
const clearExistingTimeout = useCallback(() => {
|
|
||||||
if (timeoutRef.current) {
|
|
||||||
clearTimeout(timeoutRef.current);
|
|
||||||
timeoutRef.current = null;
|
|
||||||
}
|
}
|
||||||
}, []);
|
if (hovering) {
|
||||||
|
// if hovering is true, we make a little delay here.
|
||||||
|
// this allow the sidebar close animation to complete.
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setDeferredHovering(hovering);
|
||||||
|
}, 150);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// if hovering is false, we set the deferred value after 1000ms
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setDeferredHovering(hovering);
|
||||||
|
}, 1000);
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [hovering, open]);
|
||||||
|
|
||||||
|
const sidebarState = smallScreenMode
|
||||||
|
? open
|
||||||
|
? 'floating-with-mask'
|
||||||
|
: 'close'
|
||||||
|
: open
|
||||||
|
? 'open'
|
||||||
|
: deferredHovering
|
||||||
|
? 'floating'
|
||||||
|
: 'close';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// do not float app sidebar on desktop
|
// do not float app sidebar on desktop
|
||||||
@@ -71,19 +95,8 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
|||||||
const isFloatingMaxWidth = window.matchMedia(
|
const isFloatingMaxWidth = window.matchMedia(
|
||||||
`(max-width: ${floatingMaxWidth}px)`
|
`(max-width: ${floatingMaxWidth}px)`
|
||||||
).matches;
|
).matches;
|
||||||
const isOverflowWidth = window.matchMedia(
|
const isFloating = isFloatingMaxWidth;
|
||||||
`(max-width: ${width / 0.4}px)`
|
appSidebarService.setSmallScreenMode(isFloating);
|
||||||
).matches;
|
|
||||||
const isFloating = isFloatingMaxWidth || isOverflowWidth;
|
|
||||||
if (
|
|
||||||
open === undefined &&
|
|
||||||
appSidebarService.getCachedAppSidebarOpenState() === undefined
|
|
||||||
) {
|
|
||||||
// give the initial value,
|
|
||||||
// so that the sidebar can be closed on mobile by default
|
|
||||||
appSidebarService.setOpen(!isFloating);
|
|
||||||
}
|
|
||||||
appSidebarService.setResponsiveFloating(isFloating);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dOnResize = debounce(onResize, 50);
|
const dOnResize = debounce(onResize, 50);
|
||||||
@@ -91,7 +104,7 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
|||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('resize', dOnResize);
|
window.removeEventListener('resize', dOnResize);
|
||||||
};
|
};
|
||||||
}, [appSidebarService, open, width]);
|
}, [appSidebarService]);
|
||||||
|
|
||||||
const hasRightBorder = !BUILD_CONFIG.isElectron && !clientBorder;
|
const hasRightBorder = !BUILD_CONFIG.isElectron && !clientBorder;
|
||||||
|
|
||||||
@@ -121,34 +134,20 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
|||||||
}, [appSidebarService]);
|
}, [appSidebarService]);
|
||||||
|
|
||||||
const onMouseEnter = useCallback(() => {
|
const onMouseEnter = useCallback(() => {
|
||||||
if (!timeoutRef.current) {
|
appSidebarService.setHovering(true);
|
||||||
return;
|
}, [appSidebarService]);
|
||||||
}
|
|
||||||
clearExistingTimeout();
|
|
||||||
}, [clearExistingTimeout]);
|
|
||||||
|
|
||||||
const onMouseLeave = useCallback(() => {
|
const onMouseLeave = useCallback(() => {
|
||||||
if (!hoverFloating) {
|
appSidebarService.setHovering(false);
|
||||||
clearExistingTimeout();
|
}, [appSidebarService]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearExistingTimeout();
|
|
||||||
timeoutRef.current = setTimeout(() => {
|
|
||||||
appSidebarService.setOpen(false);
|
|
||||||
}, 1500);
|
|
||||||
}, [hoverFloating, clearExistingTimeout, appSidebarService]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
clearExistingTimeout();
|
|
||||||
};
|
|
||||||
}, [clearExistingTimeout]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ResizePanel
|
<ResizePanel
|
||||||
floating={responsiveFloating || hoverFloating}
|
floating={
|
||||||
open={open}
|
sidebarState === 'floating' || sidebarState === 'floating-with-mask'
|
||||||
|
}
|
||||||
|
open={sidebarState !== 'close'}
|
||||||
resizing={resizing}
|
resizing={resizing}
|
||||||
maxWidth={MAX_WIDTH}
|
maxWidth={MAX_WIDTH}
|
||||||
minWidth={MIN_WIDTH}
|
minWidth={MIN_WIDTH}
|
||||||
@@ -158,37 +157,36 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
|||||||
onResizing={handleResizing}
|
onResizing={handleResizing}
|
||||||
onWidthChange={handleWidthChange}
|
onWidthChange={handleWidthChange}
|
||||||
className={clsx(navWrapperStyle, {
|
className={clsx(navWrapperStyle, {
|
||||||
[hoverNavWrapperStyle]: hoverFloating,
|
[hoverNavWrapperStyle]: sidebarState === 'floating',
|
||||||
})}
|
})}
|
||||||
resizeHandleOffset={0}
|
resizeHandleOffset={0}
|
||||||
resizeHandleVerticalPadding={clientBorder ? 16 : 0}
|
resizeHandleVerticalPadding={clientBorder ? 16 : 0}
|
||||||
onMouseEnter={onMouseEnter}
|
onMouseEnter={onMouseEnter}
|
||||||
onMouseLeave={onMouseLeave}
|
onMouseLeave={onMouseLeave}
|
||||||
data-transparent
|
data-transparent
|
||||||
data-open={open}
|
data-open={sidebarState !== 'close'}
|
||||||
data-has-border={hasRightBorder}
|
data-has-border={hasRightBorder}
|
||||||
data-testid="app-sidebar-wrapper"
|
data-testid="app-sidebar-wrapper"
|
||||||
data-is-macos-electron={isMacosDesktop}
|
data-is-macos-electron={isMacosDesktop}
|
||||||
data-client-border={clientBorder}
|
data-client-border={clientBorder}
|
||||||
data-is-electron={BUILD_CONFIG.isElectron}
|
data-is-electron={BUILD_CONFIG.isElectron}
|
||||||
data-show-pin-animation={showFloatToPinAnimation}
|
|
||||||
>
|
>
|
||||||
<nav className={navStyle} data-testid="app-sidebar">
|
<nav className={navStyle} data-testid="app-sidebar">
|
||||||
{!BUILD_CONFIG.isElectron && !hoverFloating && <SidebarHeader />}
|
{!BUILD_CONFIG.isElectron && sidebarState !== 'floating' && (
|
||||||
|
<SidebarHeader />
|
||||||
|
)}
|
||||||
<div className={navBodyStyle} data-testid="sliderBar-inner">
|
<div className={navBodyStyle} data-testid="sliderBar-inner">
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</ResizePanel>
|
</ResizePanel>
|
||||||
{!hoverFloating && (
|
<div
|
||||||
<div
|
data-testid="app-sidebar-float-mask"
|
||||||
data-testid="app-sidebar-float-mask"
|
data-open={open}
|
||||||
data-open={open}
|
data-is-floating={sidebarState === 'floating-with-mask'}
|
||||||
data-is-floating={responsiveFloating}
|
className={sidebarFloatMaskStyle}
|
||||||
className={sidebarFloatMaskStyle}
|
onClick={handleClose}
|
||||||
onClick={handleClose}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,39 +9,26 @@ import * as styles from './sidebar-switch.css';
|
|||||||
|
|
||||||
export const SidebarSwitch = ({
|
export const SidebarSwitch = ({
|
||||||
show,
|
show,
|
||||||
enableOpenHoverSidebar,
|
|
||||||
className,
|
className,
|
||||||
}: {
|
}: {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
enableOpenHoverSidebar?: boolean;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const appSidebarService = useService(AppSidebarService).sidebar;
|
const appSidebarService = useService(AppSidebarService).sidebar;
|
||||||
const open = useLiveData(appSidebarService.open$);
|
const open = useLiveData(appSidebarService.open$);
|
||||||
const hoverFloating = useLiveData(appSidebarService.hoverFloating$);
|
|
||||||
const switchRef = useRef<HTMLDivElement>(null);
|
const switchRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const handleMouseEnter = useCallback(() => {
|
const handleMouseEnter = useCallback(() => {
|
||||||
if (!enableOpenHoverSidebar || open) {
|
appSidebarService.setHovering(true);
|
||||||
return;
|
}, [appSidebarService]);
|
||||||
}
|
|
||||||
appSidebarService.setHoverFloating(true);
|
|
||||||
appSidebarService.setOpen(true);
|
|
||||||
}, [appSidebarService, enableOpenHoverSidebar, open]);
|
|
||||||
|
|
||||||
const handleClickSwitch = useCallback(() => {
|
const handleClickSwitch = useCallback(() => {
|
||||||
if (open && hoverFloating) {
|
appSidebarService.toggleSidebar();
|
||||||
appSidebarService.setShowFloatToPinAnimation(true);
|
}, [appSidebarService]);
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
appSidebarService.setShowFloatToPinAnimation(false);
|
const handleMouseLeave = useCallback(() => {
|
||||||
appSidebarService.setHoverFloating(false);
|
appSidebarService.setHovering(false);
|
||||||
}, 500);
|
}, [appSidebarService]);
|
||||||
return () => {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return appSidebarService.toggleSidebar();
|
|
||||||
}, [appSidebarService, hoverFloating, open]);
|
|
||||||
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const tooltipContent = open
|
const tooltipContent = open
|
||||||
@@ -54,13 +41,13 @@ export const SidebarSwitch = ({
|
|||||||
data-show={show}
|
data-show={show}
|
||||||
className={styles.sidebarSwitchClip}
|
className={styles.sidebarSwitchClip}
|
||||||
data-testid={`app-sidebar-arrow-button-${open ? 'collapse' : 'expand'}`}
|
data-testid={`app-sidebar-arrow-button-${open ? 'collapse' : 'expand'}`}
|
||||||
data-enable-open-hover-sidebar={enableOpenHoverSidebar}
|
|
||||||
onMouseEnter={handleMouseEnter}
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onMouseLeave={handleMouseLeave}
|
||||||
>
|
>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={tooltipContent}
|
tooltip={tooltipContent}
|
||||||
tooltipShortcut={['$mod', '/']}
|
tooltipShortcut={['$mod', '/']}
|
||||||
tooltipOptions={{ side: open && !hoverFloating ? 'bottom' : 'right' }}
|
tooltipOptions={{ side: open ? 'bottom' : 'right' }}
|
||||||
className={className}
|
className={className}
|
||||||
size="24"
|
size="24"
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const SidebarContainer = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={clsx(styles.sidebarContainerInner, className)} {...props}>
|
<div className={clsx(styles.sidebarContainerInner, className)} {...props}>
|
||||||
<Header floating={false} onToggle={handleToggleOpen}>
|
<Header onToggle={handleToggleOpen}>
|
||||||
<SidebarHeaderSwitcher />
|
<SidebarHeaderSwitcher />
|
||||||
</Header>
|
</Header>
|
||||||
{sidebarTabs.length > 0 ? (
|
{sidebarTabs.length > 0 ? (
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { RightSidebarIcon } from '@blocksuite/icons/rc';
|
|||||||
import * as styles from './sidebar-header.css';
|
import * as styles from './sidebar-header.css';
|
||||||
|
|
||||||
export type HeaderProps = {
|
export type HeaderProps = {
|
||||||
floating: boolean;
|
|
||||||
onToggle?: () => void;
|
onToggle?: () => void;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
};
|
};
|
||||||
@@ -13,20 +12,13 @@ function Container({
|
|||||||
children,
|
children,
|
||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
floating,
|
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
floating?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div data-testid="header" style={style} className={className}>
|
||||||
data-testid="header"
|
|
||||||
style={style}
|
|
||||||
className={className}
|
|
||||||
data-sidebar-floating={floating}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -40,9 +32,9 @@ const ToggleButton = ({ onToggle }: { onToggle?: () => void }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Header = ({ floating, children, onToggle }: HeaderProps) => {
|
export const Header = ({ children, onToggle }: HeaderProps) => {
|
||||||
return (
|
return (
|
||||||
<Container className={styles.header} floating={floating}>
|
<Container className={styles.header}>
|
||||||
{children}
|
{children}
|
||||||
{!BUILD_CONFIG.isElectron && (
|
{!BUILD_CONFIG.isElectron && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user