vp-example.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script setup lang="ts">
  2. import { computed, unref } from 'vue'
  3. import { File, Repl, ReplStore } from '@vue/repl'
  4. import mainCode from './main.vue?raw'
  5. import deptCode from './dept.js?raw'
  6. import type { SFCOptions } from '@vue/repl'
  7. const sfcOptions: SFCOptions = {
  8. script: {
  9. reactivityTransform: true,
  10. },
  11. }
  12. const props = defineProps({
  13. file: {
  14. type: String,
  15. required: true,
  16. },
  17. raw: {
  18. type: String,
  19. required: true,
  20. },
  21. demo: {
  22. type: Object,
  23. required: true,
  24. },
  25. })
  26. const loadSingleData = computed(() => {
  27. const store = {
  28. 'App.vue': decodeURIComponent(props.raw),
  29. // files: {
  30. // 'con'
  31. // },
  32. }
  33. return window.btoa(JSON.stringify(store))
  34. })
  35. const store = new ReplStore({
  36. // initialize repl with previously serialized state
  37. serializedState: unref(loadSingleData),
  38. // starts on the output pane (mobile only) if the URL has a showOutput query
  39. showOutput: true,
  40. // starts on a different tab on the output pane if the URL has a outputMode query
  41. // and default to the "preview" tab
  42. outputMode: 'preview',
  43. // specify the default URL to import Vue runtime from in the sandbox
  44. // default is the CDN link from unpkg.com with version matching Vue's version
  45. // from peerDependency
  46. defaultVueRuntimeURL: 'https://cdn.jsdelivr.net/npm/@vue/runtime-dom@latest/dist/runtime-dom.esm-browser.js',
  47. })
  48. store.init()
  49. store.setImportMap({
  50. imports: {
  51. vue: 'https://cdn.jsdelivr.net/npm/@vue/runtime-dom@latest/dist/runtime-dom.esm-browser.js',
  52. '@vue/shared': 'https://cdn.jsdelivr.net/npm/@vue/shared@latest/dist/shared.esm-bundler.js',
  53. 'kankan-components': 'https://4dkk.4dage.com/npm_test/kankan-components/dist/index.full.min.mjs',
  54. },
  55. })
  56. const PlaygroundMain = new File('PlaygroundMain.vue', mainCode)
  57. const deptFile = new File('dept.js', deptCode)
  58. store.addFile(PlaygroundMain)
  59. store.addFile(deptFile)
  60. store.state.mainFile = 'PlaygroundMain.vue'
  61. </script>
  62. <template>
  63. <div class="example-showcase" antialiased>
  64. <ClientOnly>
  65. <!-- <component :is="demo" v-if="demo" v-bind="$attrs" /> -->
  66. <Repl :store="store" :sfc-options="sfcOptions" :clear-console="false" :show-compile-output="false" auto-resize />
  67. </ClientOnly>
  68. </div>
  69. </template>
  70. <style lang="scss" scoped>
  71. .example-showcase {
  72. padding: 1.5rem;
  73. margin: 0.5px;
  74. background-color: var(--bg-color);
  75. }
  76. </style>
  77. <style lang="scss">
  78. .vue-repl {
  79. height: 600px;
  80. .left {
  81. display: none;
  82. }
  83. .right {
  84. width: 100% !important;
  85. }
  86. .tab-buttons {
  87. display: none;
  88. }
  89. }
  90. </style>