Skip to content

Commit 08933b9

Browse files
aquaductapeMilo
authored andcommitted
dispatch preview/devtools iframe keyboard zoom event to parent window
1 parent df89e1c commit 08933b9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/solid-repl/src/components/preview.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ import { Component, Show, createEffect, createMemo, createSignal, onCleanup, unt
22
import { useZoom } from '../hooks/useZoom';
33
import { GridResizer } from './gridResizer';
44

5+
const dispatchKeyboardEventToParentZoomState = () => `
6+
document.addEventListener('keydown', (e) => {
7+
if (!(e.ctrlKey || e.metaKey)) return;
8+
if(!['=', '-'].includes(e.key)) return
9+
10+
const options = {
11+
key: e.key,
12+
ctrlKey: e.ctrlKey,
13+
metaKey: e.metaKey
14+
}
15+
const keyboardEvent = new KeyboardEvent('keydown', options)
16+
window.parent.document.dispatchEvent(keyboardEvent)
17+
18+
e.preventDefault()
19+
});
20+
`;
21+
522
const generateHTML = (isDark: boolean, importMap: string) => `
623
<!doctype html>
724
<html${isDark ? ' class="dark"' : ''}>
@@ -144,6 +161,8 @@ const generateHTML = (isDark: boolean, importMap: string) => `
144161
console.error(e);
145162
}
146163
});
164+
165+
${dispatchKeyboardEventToParentZoomState()}
147166
</script>
148167
</head>
149168
<body>
@@ -168,6 +187,9 @@ const useDevtoolsSrc = () => {
168187
}
169188
}
170189
</style>
190+
<script>
191+
${dispatchKeyboardEventToParentZoomState()}
192+
</script>
171193
<meta name="referrer" content="no-referrer">
172194
<script src="https://unpkg.com/@ungap/custom-elements/es.js"></script>
173195
<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/public/front_end/entrypoints/chii_app/chii_app.js"></script>

0 commit comments

Comments
 (0)