Skip to content

Commit c74c0dd

Browse files
committed
Version 1.0.7 - Resizing
1 parent c281c35 commit c74c0dd

15 files changed

Lines changed: 170 additions & 50 deletions

File tree

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run lint && npm run tsc

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm test

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
"name": "remix-development-tools",
33
"description": "Remix development tools.",
44
"author": "Alem Tuzlak",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"license": "MIT",
77
"keywords": [
88
"remix",
99
"remix-dev-tools"
1010
],
1111
"private": false,
1212
"type": "module",
13-
"main": "./dist/index.cjs",
13+
"main": "./dist/index.umd.cjs",
1414
"module": "./dist/index.js",
1515
"exports": {
1616
"./stylesheet.css": "./dist/stylesheet.css",
1717
".": {
1818
"import": "./dist/index.js",
19-
"require": "./dist/index.cjs"
19+
"require": "./dist/index.umd.cjs",
20+
"types": "./dist/index.d.ts"
2021
}
2122
},
2223
"typings": "./dist/index.d.ts",
@@ -42,7 +43,12 @@
4243
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
4344
"prettier": "prettier --check .",
4445
"preview": "vite preview",
45-
"test": "vitest run --coverage"
46+
"profile": "vite build --profile",
47+
"test": "vitest run --coverage",
48+
"setup": "npm install && cd ./src/remix-app-for-testing && npm install && cd ../..",
49+
"prepare": "husky install",
50+
"tsc": "tsc --noEmit",
51+
"validate": "npm run lint && npm run tsc && npm run test"
4652
},
4753
"workspaces": [
4854
".",
@@ -69,6 +75,7 @@
6975
"eslint-plugin-react-hooks": "^4.6.0",
7076
"eslint-plugin-react-refresh": "^0.3.4",
7177
"happy-dom": "^9.9.2",
78+
"husky": "^8.0.3",
7279
"nodemon": "^3.0.1",
7380
"npm-run-all": "^4.1.5",
7481
"postcss": "^8.4.24",
@@ -92,4 +99,4 @@
9299
"react-use-websocket": "^4.3.1",
93100
"tailwind-merge": "^1.13.2"
94101
}
95-
}
102+
}

src/RemixDevTools/RemixDevTools.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import { useRDTContext } from "./context/useRDTContext";
88
import { isDev } from "./utils/isDev";
99
import { useGetSocket } from "./hooks/useGetSocket";
1010
import { Radio } from "lucide-react";
11+
import { useResize } from "./hooks/useResize";
1112

1213
interface Props {
1314
defaultOpen: boolean;
1415
}
1516

1617
const RemixDevTools = ({ defaultOpen }: Props) => {
1718
const [isOpen, setIsOpen] = useState(defaultOpen);
18-
const { activeTab, setActiveTab, setShouldConnectWithForge } =
19+
const { activeTab, setActiveTab, setShouldConnectWithForge, height } =
1920
useRDTContext();
20-
21+
const { enableResize, disableResize, isResizing } = useResize();
2122
useTimelineHandler();
2223
const { isConnected, isConnecting } = useGetSocket();
2324
const Component = tabs.find((tab) => tab.id === activeTab)?.component;
@@ -38,16 +39,23 @@ const RemixDevTools = ({ defaultOpen }: Props) => {
3839
)}
3940
/>
4041
</div>
41-
4242
<div
43-
style={{ zIndex: 9998 }}
43+
style={{ zIndex: 9998, height }}
4444
className={clsx(
4545
"rdt-duration-600 rdt-fixed rdt-bottom-0 rdt-left-0 rdt-box-border rdt-flex rdt-w-screen rdt-resize-y rdt-flex-col rdt-overflow-auto rdt-bg-[#212121] rdt-text-white rdt-opacity-0 rdt-transition-all",
46-
isOpen
47-
? "rdt-h-[40vh] rdt-opacity-100 rdt-drop-shadow-2xl"
48-
: "rdt-h-0"
46+
isOpen ? "rdt-opacity-100 rdt-drop-shadow-2xl" : "rdt-h-0",
47+
isResizing ? "rdt-pointer-events-none" : "",
48+
isResizing && "rdt-cursor-grabbing "
4949
)}
5050
>
51+
<div
52+
onMouseDown={enableResize}
53+
onMouseUp={disableResize}
54+
className={clsx(
55+
"rdt-absolute rdt-h-1 rdt-w-full rdt-cursor-n-resize",
56+
isResizing && "rdt-cursor-grabbing "
57+
)}
58+
/>
5159
<div className="rdt-flex rdt-h-8 rdt-w-full rdt-bg-gray-800">
5260
{tabs
5361
.filter(

src/RemixDevTools/context/rdtReducer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type RemixDevToolsState = {
1010
activeTab: Tabs;
1111
shouldConnectWithForge: boolean;
1212
port: number;
13+
height: number;
1314
};
1415
};
1516

@@ -20,6 +21,7 @@ export const initialState: RemixDevToolsState = {
2021
activeTab: "timeline",
2122
shouldConnectWithForge: false,
2223
port: 3003,
24+
height: 400,
2325
},
2426
};
2527

@@ -36,6 +38,11 @@ type SetActiveTab = {
3638
payload: Tabs;
3739
};
3840

41+
type SetDevToolsHeight = {
42+
type: "SET_HEIGHT";
43+
payload: number;
44+
};
45+
3946
type SetRouteWildcards = {
4047
type: "SET_ROUTE_WILDCARDS";
4148
payload: RouteWildcards;
@@ -62,6 +69,7 @@ export type RemixDevToolsActions =
6269
| SetActiveTab
6370
| PurgeTimeline
6471
| SetRouteWildcards
72+
| SetDevToolsHeight
6573
| SetShouldConnectToForgeAction
6674
| SetIsSubmittedAction;
6775

@@ -102,6 +110,15 @@ export const rdtReducer = (
102110
routeWildcards: payload,
103111
},
104112
};
113+
case "SET_HEIGHT":
114+
return {
115+
...state,
116+
settings: {
117+
...state.settings,
118+
height: payload,
119+
},
120+
};
121+
105122
case "SET_SHOULD_CONNECT_TO_FORGE":
106123
return {
107124
...state,

src/RemixDevTools/context/useRDTContext.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const useRDTContext = () => {
1111
}
1212
const { state, dispatch } = context;
1313
const { timeline, settings } = state;
14-
const { activeTab, shouldConnectWithForge, routeWildcards, port } = settings;
14+
const { activeTab, shouldConnectWithForge, routeWildcards, port, height } =
15+
settings;
1516

1617
useEffect(() => {
1718
const reducedState = { ...state };
@@ -53,6 +54,17 @@ const useRDTContext = () => {
5354
},
5455
[dispatch]
5556
);
57+
58+
const setHeight = useCallback(
59+
(height: number) => {
60+
dispatch({
61+
type: "SET_HEIGHT",
62+
payload: height,
63+
});
64+
},
65+
[dispatch]
66+
);
67+
5668
return {
5769
setTimelineEvent,
5870
setActiveTab,
@@ -63,6 +75,8 @@ const useRDTContext = () => {
6375
shouldConnectWithForge,
6476
routeWildcards,
6577
port,
78+
height,
79+
setHeight,
6680
setRouteWildcards,
6781
};
6882
};
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { useCallback, useEffect, useState } from "react";
2+
import { useRDTContext } from "../context/useRDTContext";
23

3-
type UseResizeProps = {
4-
minHeight: number;
5-
};
6-
7-
const useResize = (
8-
{ minHeight = 384 }: UseResizeProps = { minHeight: 384 }
9-
) => {
4+
const useResize = () => {
5+
const { height, setHeight } = useRDTContext();
106
const [isResizing, setIsResizing] = useState(false);
11-
const [height, setHeight] = useState(minHeight);
127

138
const enableResize = useCallback(() => {
149
setIsResizing(true);
@@ -24,12 +19,11 @@ const useResize = (
2419
const newHeight = window.innerHeight - e.clientY; // Calculate the new height based on the mouse position
2520

2621
//const newHeight = e.clientY; // You may want to add some offset here from props
27-
if (newHeight >= minHeight) {
28-
setHeight(newHeight);
29-
}
22+
23+
setHeight(newHeight);
3024
}
3125
},
32-
[minHeight, isResizing, setHeight]
26+
[isResizing, setHeight]
3327
);
3428

3529
useEffect(() => {
@@ -42,7 +36,7 @@ const useResize = (
4236
};
4337
}, [disableResize, resize]);
4438

45-
return { height, enableResize };
39+
return { height, enableResize, disableResize, isResizing };
4640
};
4741

4842
export { useResize };

src/RemixDevTools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./RemixDevTools";
2+
export { RemixDevTools as default } from "./RemixDevTools";

src/RemixDevTools/tabs/PageTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ const PageTab = () => {
4343
const reversed = routes.reverse();
4444
const { revalidate, state } = useRevalidator();
4545
const { isConnected, sendJsonMessage } = useGetSocket();
46+
4647
return (
47-
<div className="rdt-relative rdt-flex rdt-h-[40vh] rdt-flex-col rdt-overflow-y-auto rdt-p-6 rdt-px-6">
48+
<div className="rdt-relative rdt-flex rdt-h-full rdt-flex-col rdt-overflow-y-auto rdt-p-6 rdt-px-6">
4849
<button
4950
onClick={() => revalidate()}
5051
className={clsx(

0 commit comments

Comments
 (0)