Skip to content

Commit 573ef7b

Browse files
committed
dev-tools
1 parent 318aaf6 commit 573ef7b

File tree

6 files changed

+62
-1
lines changed

6 files changed

+62
-1
lines changed

packages/dev-tools/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @julianjark/dev-tools
22

3+
## 0.13.0
4+
5+
### Minor Changes
6+
7+
- don't trigger shortcuts on input fields
8+
39
## 0.12.0
410

511
### Minor Changes

packages/dev-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@julianjark/dev-tools",
3-
"version": "0.12.0",
3+
"version": "0.13.0",
44
"description": "Helper tools for development",
55
"author": "Julian Jark",
66
"license": "ISC",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useRef } from "react";
2+
3+
interface DevToolsTriggerProps {
4+
onTrigger: () => void;
5+
}
6+
7+
/**
8+
* Trigger dev tools by clicking 5 times on the bottom right corner of the screen
9+
* Allows devtools to be opened on mobile
10+
*/
11+
export function DevToolsTrigger({ onTrigger }: DevToolsTriggerProps) {
12+
const clickRef = useRef({ clicks: 0, lastClicked: 0 });
13+
const onClick = () => {
14+
const now = Date.now();
15+
const { clicks, lastClicked } = clickRef.current;
16+
if (now - lastClicked > 500) {
17+
clickRef.current = { clicks: 1, lastClicked: now };
18+
} else {
19+
clickRef.current = { clicks: clicks + 1, lastClicked: now };
20+
}
21+
22+
if (clickRef.current.clicks > 5) {
23+
clickRef.current = { clicks: 0, lastClicked: 0 };
24+
onTrigger();
25+
}
26+
};
27+
return (
28+
<div style={{ position: "relative" }}>
29+
<button
30+
onClick={onClick}
31+
style={{
32+
height: 160,
33+
width: 160,
34+
position: "absolute",
35+
bottom: 0,
36+
right: 0,
37+
opacity: 0,
38+
}}
39+
/>
40+
</div>
41+
);
42+
}

packages/dev-tools/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./preview-mode.ui";
22
export * from "./use-shortcut";
3+
export * from "./dev-tools-trigger";

packages/dev-tools/src/use-shortcut.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { useCallback, useEffect, useRef } from "react";
33
export const useShortcut = (keys: string, onTrigger: () => unknown) => {
44
const pressedKeysRef = useRef("");
55
const handleKeyPress = useCallback((event: KeyboardEvent) => {
6+
const target = (event.target || {}) as HTMLElement;
7+
if (
8+
target.isContentEditable ||
9+
target.nodeName === "INPUT" ||
10+
target.nodeName === "TEXTAREA"
11+
) {
12+
return;
13+
}
14+
615
pressedKeysRef.current += event.key;
716
if (pressedKeysRef.current === keys) {
817
pressedKeysRef.current = "";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
22
extends: ["turbo", "prettier"],
3+
rules: {
4+
"@next/next/no-img-element": "off",
5+
},
36
};

0 commit comments

Comments
 (0)