Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 7ba3e44

Browse files
authored
feat: transition to target slide when clicking slide item and text editor (#11)
1 parent fb1dbe3 commit 7ba3e44

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/editor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function configEditor() {
6464

6565
commands.registerCommand('slidev.goto', async(idx: number) => {
6666
revealSlide(idx)
67+
previewProvider.updateSlide(idx)
6768
})
6869

6970
commands.registerCommand('slidev.next', async() => {

src/view/PreviewProvider.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,27 @@ code {
116116
http-equiv="Content-Security-Policy"
117117
content="default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';"
118118
/>
119+
<style>
120+
body {
121+
padding: 0;
122+
width: 100vw;
123+
height: 100vh;
124+
}
125+
iframe {
126+
border: none;
127+
width: 100%;
128+
height: 100%;
129+
}
130+
</style>
119131
<head>
120132
<body>
133+
<iframe id="iframe" src="${url}"></iframe>
121134
<script>
122-
window.addEventListener('load', () => {
123-
location.replace(${JSON.stringify(url)})
135+
var iframe = document.getElementById('iframe')
136+
window.addEventListener('message', ({ data }) => {
137+
if (data && data.target === 'slidev') {
138+
iframe.contentWindow.postMessage(data, '${serverAddr}')
139+
}
124140
})
125141
</script>
126142
</body>

0 commit comments

Comments
 (0)