mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-14 21:10:37 +02:00
refactor to use showCompactSidebar instead
This commit is contained in:
@@ -477,9 +477,9 @@ const deviceContextInitialValue = {
|
|||||||
editor: {
|
editor: {
|
||||||
isMobile: false,
|
isMobile: false,
|
||||||
canFitSidebar: false,
|
canFitSidebar: false,
|
||||||
|
showCompactSidebar: false,
|
||||||
},
|
},
|
||||||
isTouchScreen: false,
|
isTouchScreen: false,
|
||||||
isTouchMobile: false,
|
|
||||||
};
|
};
|
||||||
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
const DeviceContext = React.createContext<Device>(deviceContextInitialValue);
|
||||||
DeviceContext.displayName = "DeviceContext";
|
DeviceContext.displayName = "DeviceContext";
|
||||||
@@ -2423,12 +2423,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return isMobile || isTouchMobile;
|
return isMobile || isTouchMobile;
|
||||||
};
|
};
|
||||||
|
|
||||||
private isTablet = (): boolean => {
|
|
||||||
const { clientWidth: viewportWidth } = document.body;
|
|
||||||
|
|
||||||
return this.isMobileOrTablet() && viewportWidth > MQ_MAX_WIDTH_PORTRAIT;
|
|
||||||
};
|
|
||||||
|
|
||||||
private isMobileBreakpoint = (width: number, height: number) => {
|
private isMobileBreakpoint = (width: number, height: number) => {
|
||||||
return (
|
return (
|
||||||
width < MQ_MAX_WIDTH_PORTRAIT ||
|
width < MQ_MAX_WIDTH_PORTRAIT ||
|
||||||
@@ -2459,17 +2453,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
private refreshTouchScreen = () => {
|
|
||||||
const previousIsTouchMobile = this.device.isTouchMobile;
|
|
||||||
const currentIsTouchMobile = this.isMobileOrTablet();
|
|
||||||
|
|
||||||
if (previousIsTouchMobile !== currentIsTouchMobile) {
|
|
||||||
this.device = { ...this.device, isTouchMobile: currentIsTouchMobile };
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
private refreshEditorBreakpoints = () => {
|
private refreshEditorBreakpoints = () => {
|
||||||
const container = this.excalidrawContainerRef.current;
|
const container = this.excalidrawContainerRef.current;
|
||||||
if (!container) {
|
if (!container) {
|
||||||
@@ -2489,6 +2472,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
const nextEditorState = updateObject(prevEditorState, {
|
const nextEditorState = updateObject(prevEditorState, {
|
||||||
isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
|
isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
|
||||||
canFitSidebar: editorWidth > sidebarBreakpoint,
|
canFitSidebar: editorWidth > sidebarBreakpoint,
|
||||||
|
showCompactSidebar:
|
||||||
|
this.isMobileOrTablet() && editorWidth > MQ_MAX_WIDTH_PORTRAIT,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prevEditorState !== nextEditorState) {
|
if (prevEditorState !== nextEditorState) {
|
||||||
@@ -2575,7 +2560,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
) {
|
) {
|
||||||
this.refreshViewportBreakpoints();
|
this.refreshViewportBreakpoints();
|
||||||
this.refreshEditorBreakpoints();
|
this.refreshEditorBreakpoints();
|
||||||
this.refreshTouchScreen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportsResizeObserver && this.excalidrawContainerRef.current) {
|
if (supportsResizeObserver && this.excalidrawContainerRef.current) {
|
||||||
@@ -2635,7 +2619,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
.getElementsIncludingDeleted()
|
.getElementsIncludingDeleted()
|
||||||
.forEach((element) => ShapeCache.delete(element));
|
.forEach((element) => ShapeCache.delete(element));
|
||||||
this.refreshViewportBreakpoints();
|
this.refreshViewportBreakpoints();
|
||||||
this.refreshTouchScreen();
|
|
||||||
this.updateDOMRect();
|
this.updateDOMRect();
|
||||||
if (!supportsResizeObserver) {
|
if (!supportsResizeObserver) {
|
||||||
this.refreshEditorBreakpoints();
|
this.refreshEditorBreakpoints();
|
||||||
|
@@ -284,7 +284,7 @@ const LayerUI = ({
|
|||||||
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
||||||
{renderCanvasActions()}
|
{renderCanvasActions()}
|
||||||
{shouldRenderSelectedShapeActions &&
|
{shouldRenderSelectedShapeActions &&
|
||||||
renderSelectedShapeActions(device.isTouchMobile)}
|
renderSelectedShapeActions(device.editor.showCompactSidebar)}
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled &&
|
{!appState.viewModeEnabled &&
|
||||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||||
|
@@ -883,9 +883,9 @@ export type Device = Readonly<{
|
|||||||
editor: {
|
editor: {
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
canFitSidebar: boolean;
|
canFitSidebar: boolean;
|
||||||
|
showCompactSidebar: boolean;
|
||||||
};
|
};
|
||||||
isTouchScreen: boolean;
|
isTouchScreen: boolean;
|
||||||
isTouchMobile: boolean;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type FrameNameBounds = {
|
export type FrameNameBounds = {
|
||||||
|
Reference in New Issue
Block a user