|
2 | 2 | import SplitPane from './SplitPane.vue'
|
3 | 3 | import Output from './output/Output.vue'
|
4 | 4 | import { Store, ReplStore, SFCOptions } from './store'
|
5 |
| -import { provide, ref, toRef, computed } from 'vue' |
| 5 | +import { provide, ref, toRef, computed, watchEffect } from 'vue' |
6 | 6 | import type { EditorComponentType } from './editor/types'
|
7 | 7 | import EditorContainer from './editor/EditorContainer.vue'
|
8 | 8 |
|
@@ -56,29 +56,29 @@ if (!props.editor) {
|
56 | 56 | }
|
57 | 57 |
|
58 | 58 | const outputRef = ref<InstanceType<typeof Output>>()
|
59 |
| -const { store } = props |
60 |
| -const sfcOptions = (store.options = props.sfcOptions || {}) |
61 |
| -if (!sfcOptions.script) { |
62 |
| - sfcOptions.script = {} |
63 |
| -} |
64 |
| -// @ts-ignore only needed in 3.3 |
65 |
| -sfcOptions.script.fs = { |
66 |
| - fileExists(file: string) { |
67 |
| - if (file.startsWith('/')) file = file.slice(1) |
68 |
| - return !!store.state.files[file] |
69 |
| - }, |
70 |
| - readFile(file: string) { |
71 |
| - if (file.startsWith('/')) file = file.slice(1) |
72 |
| - return store.state.files[file].code |
73 |
| - }, |
74 |
| -} |
75 | 59 |
|
76 |
| -store.init() |
| 60 | +watchEffect(() => { |
| 61 | + const { store } = props |
| 62 | + const sfcOptions = (store.options = props.sfcOptions || {}) |
| 63 | + sfcOptions.script ||= {} |
| 64 | + sfcOptions.script.fs = { |
| 65 | + fileExists(file: string) { |
| 66 | + if (file.startsWith('/')) file = file.slice(1) |
| 67 | + return !!store.state.files[file] |
| 68 | + }, |
| 69 | + readFile(file: string) { |
| 70 | + if (file.startsWith('/')) file = file.slice(1) |
| 71 | + return store.state.files[file].code |
| 72 | + }, |
| 73 | + } |
| 74 | +}) |
| 75 | +
|
| 76 | +props.store.init() |
77 | 77 |
|
78 | 78 | const editorSlotName = computed(() => (props.layoutReverse ? 'right' : 'left'))
|
79 | 79 | const outputSlotName = computed(() => (props.layoutReverse ? 'left' : 'right'))
|
80 | 80 |
|
81 |
| -provide('store', store) |
| 81 | +provide('store', props.store) |
82 | 82 | provide('autoresize', props.autoResize)
|
83 | 83 | provide('import-map', toRef(props, 'showImportMap'))
|
84 | 84 | provide('tsconfig', toRef(props, 'showTsConfig'))
|
|
0 commit comments