Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface InspectProps {
disabled?: boolean;
}

let isCloke = false;

export default function Inspect({
children,
margin = true,
Expand All @@ -38,14 +40,29 @@ export default function Inspect({
}
}

function onInspxSwitch() {
if (isCloke) {
uninspect();
} else {
if (margin) inspectMargin(nodesAtPointerRef.current);
if (size) inspectSize(nodesAtPointerRef.current);
if (padding) inspectPadding(nodesAtPointerRef.current);
}
isCloke = !isCloke;
}

if (!disabled) {
window.addEventListener('keyup', onKeyUp);
window.addEventListener('keydown', onKeyDown);
// @ts-ignore
window.addEventListener('inspxswitch', onInspxSwitch);
}

return () => {
window.removeEventListener('keyup', onKeyUp);
window.removeEventListener('keydown', onKeyDown);
// @ts-ignore
window.removeEventListener('inspxswitch', onInspxSwitch);
};
}, [margin, size, padding, disabled]);

Expand All @@ -64,7 +81,7 @@ export default function Inspect({

nodesAtPointerRef.current = nodes as HTMLElement[];

if (e.altKey) {
if (e.altKey || isCloke) {
if (margin) inspectMargin(nodes);
if (size) inspectSize(nodes);
if (padding) inspectPadding(nodes);
Expand Down