Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
cursor: ew-resize;
}

/* Must match VERTICAL_MODE_MAX_WIDTH in useResizableColumns.js */
@container devtools (width < 600px) {
.Components {
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,142 +8,30 @@
*/

import * as React from 'react';
import {Fragment, useEffect, useLayoutEffect, useReducer, useRef} from 'react';
import {Fragment} from 'react';
import Tree from './Tree';
import {OwnersListContextController} from './OwnersListContext';
import portaledContent from '../portaledContent';
import {SettingsModalContextController} from 'react-devtools-shared/src/devtools/views/Settings/SettingsModalContext';
import {
localStorageGetItem,
localStorageSetItem,
} from 'react-devtools-shared/src/storage';
import InspectedElementErrorBoundary from './InspectedElementErrorBoundary';
import InspectedElement from './InspectedElement';
import {ModalDialog} from '../ModalDialog';
import SettingsModal from 'react-devtools-shared/src/devtools/views/Settings/SettingsModal';
import {NativeStyleContextController} from './NativeStyleEditor/context';
import useResizableColumns from '../useResizableColumns';

import styles from './Components.css';
import typeof {SyntheticPointerEvent} from 'react-dom-bindings/src/events/SyntheticEvent';

type Orientation = 'horizontal' | 'vertical';

type ResizeActionType =
| 'ACTION_SET_DID_MOUNT'
| 'ACTION_SET_HORIZONTAL_PERCENTAGE'
| 'ACTION_SET_VERTICAL_PERCENTAGE';

type ResizeAction = {
type: ResizeActionType,
payload: any,
};

type ResizeState = {
horizontalPercentage: number,
verticalPercentage: number,
};
const LOCAL_STORAGE_KEY = 'React::DevTools::createResizeReducer';

function Components(_: {}) {
const wrapperElementRef = useRef<null | HTMLElement>(null);
const resizeElementRef = useRef<null | HTMLElement>(null);

const [state, dispatch] = useReducer<ResizeState, any, ResizeAction>(
resizeReducer,
null,
initResizeState,
);

const {horizontalPercentage, verticalPercentage} = state;

useLayoutEffect(() => {
const resizeElement = resizeElementRef.current;

setResizeCSSVariable(
resizeElement,
'horizontal',
horizontalPercentage * 100,
);
setResizeCSSVariable(resizeElement, 'vertical', verticalPercentage * 100);
}, []);

useEffect(() => {
const timeoutID = setTimeout(() => {
localStorageSetItem(
LOCAL_STORAGE_KEY,
JSON.stringify({
horizontalPercentage,
verticalPercentage,
}),
);
}, 500);

return () => clearTimeout(timeoutID);
}, [horizontalPercentage, verticalPercentage]);

const onResizeStart = (event: SyntheticPointerEvent) => {
const element = event.currentTarget;
element.setPointerCapture(event.pointerId);
};

const onResizeEnd = (event: SyntheticPointerEvent) => {
const element = event.currentTarget;
element.releasePointerCapture(event.pointerId);
};

const onResize = (event: SyntheticPointerEvent) => {
const element = event.currentTarget;
const isResizing = element.hasPointerCapture(event.pointerId);
if (!isResizing) {
return;
}

const resizeElement = resizeElementRef.current;
const wrapperElement = wrapperElementRef.current;

if (wrapperElement === null || resizeElement === null) {
return;
}

event.preventDefault();

const orientation = getOrientation(wrapperElement);

const {height, width, left, top} = wrapperElement.getBoundingClientRect();

const currentMousePosition =
orientation === 'horizontal' ? event.clientX - left : event.clientY - top;

const boundaryMin = MINIMUM_SIZE;
const boundaryMax =
orientation === 'horizontal'
? width - MINIMUM_SIZE
: height - MINIMUM_SIZE;

const isMousePositionInBounds =
currentMousePosition > boundaryMin && currentMousePosition < boundaryMax;

if (isMousePositionInBounds) {
const resizedElementDimension =
orientation === 'horizontal' ? width : height;
const actionType =
orientation === 'horizontal'
? 'ACTION_SET_HORIZONTAL_PERCENTAGE'
: 'ACTION_SET_VERTICAL_PERCENTAGE';
const percentage = (currentMousePosition / resizedElementDimension) * 100;

setResizeCSSVariable(resizeElement, orientation, percentage);

dispatch({
type: actionType,
payload: currentMousePosition / resizedElementDimension,
});
}
};
const {wrapperRef, resizeElementRef, onResizeStart, onResizeEnd, onResize} =
useResizableColumns(LOCAL_STORAGE_KEY);

return (
<SettingsModalContextController>
<OwnersListContextController>
<div ref={wrapperElementRef} className={styles.Components}>
<div ref={wrapperRef} className={styles.Components}>
<Fragment>
<div ref={resizeElementRef} className={styles.TreeWrapper}>
<Tree />
Expand Down Expand Up @@ -176,67 +64,4 @@ function Components(_: {}) {
);
}

const LOCAL_STORAGE_KEY = 'React::DevTools::createResizeReducer';
const VERTICAL_MODE_MAX_WIDTH = 600;
const MINIMUM_SIZE = 100;

function initResizeState(): ResizeState {
let horizontalPercentage = 0.65;
let verticalPercentage = 0.5;

try {
let data = localStorageGetItem(LOCAL_STORAGE_KEY);
if (data != null) {
data = JSON.parse(data);
horizontalPercentage = data.horizontalPercentage;
verticalPercentage = data.verticalPercentage;
}
} catch (error) {}

return {
horizontalPercentage,
verticalPercentage,
};
}

function resizeReducer(state: ResizeState, action: ResizeAction): ResizeState {
switch (action.type) {
case 'ACTION_SET_HORIZONTAL_PERCENTAGE':
return {
...state,
horizontalPercentage: action.payload,
};
case 'ACTION_SET_VERTICAL_PERCENTAGE':
return {
...state,
verticalPercentage: action.payload,
};
default:
return state;
}
}

function getOrientation(
wrapperElement: null | HTMLElement,
): null | Orientation {
if (wrapperElement != null) {
const {width} = wrapperElement.getBoundingClientRect();
return width > VERTICAL_MODE_MAX_WIDTH ? 'horizontal' : 'vertical';
}
return null;
}

function setResizeCSSVariable(
resizeElement: null | HTMLElement,
orientation: null | Orientation,
percentage: number,
): void {
if (resizeElement !== null && orientation !== null) {
resizeElement.style.setProperty(
`--${orientation}-resize-percentage`,
`${percentage}%`,
);
}
}

export default (portaledContent(Components): component());
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
display: flex;
align-items: center;
padding: 0 0.5rem;
overflow-x: auto;
background-color: var(--color-background);
border-top: 1px solid var(--color-border);
font-family: var(--font-family-sans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
width: 100%;
flex: 1;
padding: 0.5rem;
overflow: hidden;
}

.PatternPath {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
width: 100%;
flex: 1;
padding: 0.5rem;
overflow: hidden;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,34 @@
.LeftColumn {
display: flex;
flex-direction: column;
flex: 2 1 200px;
flex: 0 0 var(--horizontal-resize-percentage);
min-width: 0;
overflow: hidden;
border-top: 1px solid var(--color-border);
}

.RightColumn {
display: flex;
flex-direction: column;
flex: 1 1 100px;
max-width: 300px;
flex: 1 1 35%;
overflow-x: hidden;
border-left: 1px solid var(--color-border);
border-top: 1px solid var(--color-border);
}

.ResizeBarWrapper {
flex: 0 0 0px;
position: relative;
}

.ResizeBar {
position: absolute;
left: 1px;
width: 5px;
height: 100%;
cursor: ew-resize;
}

.Content {
position: relative;
flex: 1 1 auto;
Expand Down Expand Up @@ -81,6 +95,16 @@
border-bottom: 1px solid var(--color-border);
}

.SnapshotSelectorWrapper {
width: 100%;
height: 2.25rem;
padding: 0 0.25rem;
flex: 0 0 auto;
display: flex;
align-items: center;
border-bottom: 1px solid var(--color-border);
}

.VRule {
height: 20px;
width: 1px;
Expand Down Expand Up @@ -132,4 +156,29 @@
color: var(--color-link);
margin-left: 0.25rem;
margin-right: 0.25rem;
}
}

/* Must match VERTICAL_MODE_MAX_WIDTH in useResizableColumns.js */
@container devtools (width < 600px) {
.Profiler {
flex-direction: column;
}

.LeftColumn {
flex: 0 0 var(--vertical-resize-percentage);
}

.RightColumn {
flex: 1 1 50%;
border-left: none;
}

.ResizeBar {
top: 1px;
left: 0;
width: 100%;
height: 5px;
cursor: ns-resize;
}
}

Loading