|
| 1 | +<script setup lang="ts"> |
| 2 | +import Header from './Header.vue'; |
| 3 | +import { Repl } from '@vue/repl'; |
| 4 | +import CodeMirror from '@vue/repl/codemirror-editor'; |
| 5 | +import { watchEffect } from 'vue'; |
| 6 | +import { NutUIStore } from './store'; |
| 7 | +
|
| 8 | +const setVH = () => { |
| 9 | + document.documentElement.style.setProperty('--vh', window.innerHeight + `px`); |
| 10 | +}; |
| 11 | +window.addEventListener('resize', setVH); |
| 12 | +setVH(); |
| 13 | +
|
| 14 | +const hash = location.hash.slice(1); |
| 15 | +
|
| 16 | +const store = new NutUIStore( |
| 17 | + { |
| 18 | + defaultVueRuntimeURL: 'https://cdn.jsdelivr.net/npm/@vue/runtime-dom/dist/runtime-dom.esm-browser.js' |
| 19 | + }, |
| 20 | + hash |
| 21 | +); |
| 22 | +
|
| 23 | +store.setImportMap({ |
| 24 | + imports: { |
| 25 | + '@nutui/nutui': 'https://cdn.jsdelivr.net/npm/@nutui/nutui/dist/nutui.js', |
| 26 | + '@nutui/icons-vue': 'https://cdn.jsdelivr.net/npm/@nutui/icons-vue/dist/lib/index.mjs', |
| 27 | + '@nutui/touch-emulator': 'https://cdn.jsdelivr.net/npm/@nutui/touch-emulator', |
| 28 | + // compatible with Functional Component style import |
| 29 | + '@nutui/nutui/dist/packages/toast/style': './style.js', |
| 30 | + '@nutui/nutui/dist/packages/dialog/style': './style.js', |
| 31 | + '@nutui/nutui/dist/packages/imagepreview/style': './style.js', |
| 32 | + '@nutui/nutui/dist/packages/notify/style': './style.js' |
| 33 | + } |
| 34 | +}); |
| 35 | +
|
| 36 | +// persist state |
| 37 | +watchEffect(() => { |
| 38 | + const newHash = store.serialize(); |
| 39 | + history.replaceState({}, '', newHash); |
| 40 | +}); |
| 41 | +</script> |
| 42 | + |
| 43 | +<template> |
| 44 | + <Header :store="store" /> |
| 45 | + <Repl |
| 46 | + @keydown.ctrl.s.prevent |
| 47 | + @keydown.meta.s.prevent |
| 48 | + :editor="CodeMirror" |
| 49 | + :store="store" |
| 50 | + :showImportMap="false" |
| 51 | + :showTsConfig="false" |
| 52 | + /> |
| 53 | +</template> |
| 54 | + |
| 55 | +<style> |
| 56 | +.dark { |
| 57 | + color-scheme: dark; |
| 58 | +} |
| 59 | +
|
| 60 | +body { |
| 61 | + font-size: 13px; |
| 62 | + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', |
| 63 | + 'Helvetica Neue', sans-serif; |
| 64 | + margin: 0; |
| 65 | + --base: #444; |
| 66 | + --nav-height: 50px; |
| 67 | +} |
| 68 | +
|
| 69 | +.vue-repl { |
| 70 | + --color-branding: #ff2f2b !important; |
| 71 | + --color-branding-dark: #ff2f2b !important; |
| 72 | + height: calc(var(--vh) - var(--nav-height)); |
| 73 | +} |
| 74 | +
|
| 75 | +button { |
| 76 | + border: none; |
| 77 | + outline: none; |
| 78 | + cursor: pointer; |
| 79 | + margin: 0; |
| 80 | + background-color: transparent; |
| 81 | +} |
| 82 | +</style> |
0 commit comments