-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
162 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,60 @@ | ||
<script setup lang="ts"> | ||
<script setup> | ||
import '@vue/repl/style.css'; | ||
import { File, Repl, ReplStore } from '@vue/repl'; | ||
import Monaco from '@vue/repl/monaco-editor'; | ||
import { shallowRef, watch } from 'vue'; | ||
const props = defineProps({ | ||
code: { | ||
type: String, | ||
default: '<template>\n</template>', | ||
}, | ||
import { watchEffect } from 'vue'; | ||
import { Repl, ReplStore } from '@vue/repl'; | ||
import CodeMirror from '@vue/repl/codemirror-editor'; | ||
// import Monaco from '@vue/repl/monaco-editor'; | ||
function setVH() { | ||
document.documentElement.style.setProperty('--vh', `${window.innerHeight}px`); | ||
}; | ||
window.addEventListener('resize', setVH); | ||
setVH(); | ||
const query = new URLSearchParams(location.search); | ||
const defaultSerializedState = 'eNp9kc1uwyAQhF8l4pyYQ26RFfUvh/bQVm2PXFy8cYjxgmBxLUV+92LcuG4V5YZmhuHb5cRurc3aAGzDcoLG6oJgK3CxyNvVZyAyuH2AfRE05XxSBOZ8FmZLphprHK2awmZHbzC2nYYS8WN4wTaLpAzajaxtIevYF9RgCHYgsn7DuSwx3i9Bq9ZlCMTRNnwe56XylE4xJ9jQ2AvsIwF5aXCvqn/vS9NYpcG9WFIG/3IUWpuvp6SRC7A86/IAsr6gH3034r468OBaEGzyqHAV0Gjv3p+hi+fJbEwZdExfMd/AGx0GxjF2F7CM2LNcon1M61RYffhdR4D+PNQAmraR8oLFL72/Mvov7jpbT1vsvwGBTq3o'; | ||
const store = new ReplStore({ | ||
// initialize repl with previously serialized state | ||
serializedState: location.hash.slice(1) || defaultSerializedState, | ||
// starts on the output pane (mobile only) if the URL has a showOutput query | ||
showOutput: query.has('showOutput'), | ||
// starts on a different tab on the output pane if the URL has a outputMode query | ||
// and default to the "preview" tab | ||
outputMode: query.get('outputMode') || 'preview', | ||
// specify the default URL to import Vue runtime from in the sandbox | ||
// default is the CDN link from jsdelivr.com with version matching Vue's version | ||
// from peerDependency | ||
// defaultVueRuntimeURL: 'cdn link to vue.runtime.esm-browser.js', | ||
}); | ||
const store = shallowRef(new ReplStore()); | ||
// persist state to URL hash | ||
watchEffect(() => history.replaceState({}, '', store.serialize())); | ||
store.value.setImportMap({ | ||
// pre-set import map | ||
store.setImportMap({ | ||
imports: { | ||
'@ckpack/v-ui': 'https://cdn.jsdelivr.net/npm/@ckpack/v-ui/dist/v-ui.js', | ||
}, | ||
}); | ||
watch(() => props.code, (v) => { | ||
setAppFile(v); | ||
}, { | ||
immediate: true, | ||
}); | ||
const previewOptions = { | ||
customCode: { | ||
importCode: 'import VUI from \'@ckpack/v-ui\';', | ||
useCode: 'app.use(VUI);', | ||
}, | ||
}; | ||
function setAppFile(code: string) { | ||
if (store.value) { | ||
store.value.addFile(new File('src/App.vue', code)); | ||
} | ||
} | ||
defineExpose({ setAppFile }); | ||
</script> | ||
|
||
<template> | ||
<Repl | ||
:auto-resize="true" | ||
:editor="Monaco" :store="store" :preview-options="previewOptions" | ||
layout="vertical" | ||
:show-import-map="false" | ||
:show-compile-output="false" | ||
:show-ts-config="false" | ||
/> | ||
<Repl :store="store" :editor="CodeMirror" :show-compile-output="true" :preview-options="previewOptions" /> | ||
</template> | ||
|
||
<style> | ||
.editor-container { | ||
.editor { | ||
min-height: 300px !important; | ||
} | ||
.vue-repl { | ||
height: calc(var(--vh) - var(--vp-nav-height)) !important; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.vp-doc div[class*='language-'] { | ||
/* .vp-doc div[class*='language-'] { | ||
margin: 0; | ||
} | ||
} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
import DefaultTheme from 'vitepress/theme'; | ||
import './index.css'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
import VUI from '@/index'; | ||
|
||
export default { | ||
...DefaultTheme, | ||
async enhanceApp({ app }) { | ||
app.use(VUI); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
if (!import.meta.env.SSR) { | ||
const ReplWrapper = (await import('../plugins/repl-wrapper.vue')).default; | ||
app.component('ReplWrapper', ReplWrapper); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
layout: home | ||
--- | ||
<repl-wrapper /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.