Skip to content

Commit 4c858a2

Browse files
committed
fix: jsx-explorer default text value error
1 parent b2d0394 commit 4c858a2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/jsx-explorer/src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as m from 'monaco-editor';
44
import { watchEffect } from 'vue';
55
import { transform } from '@babel/core';
66
import babelPluginJsx from '../../babel-plugin-jsx/src';
7-
import { initOptions, compilerOptions } from './options';
7+
import { initOptions, compilerOptions, VueJSXPluginOptions } from './options';
88
import './index.css';
99

1010
declare global {
@@ -14,9 +14,22 @@ declare global {
1414
}
1515
}
1616

17+
interface PersistedState {
18+
src: string
19+
options: VueJSXPluginOptions
20+
}
21+
1722
window.init = () => {
1823
const { monaco } = window;
1924

25+
const persistedState: PersistedState = JSON.parse(
26+
decodeURIComponent(window.location.hash.slice(1))
27+
|| localStorage.getItem('state')
28+
|| '{}',
29+
);
30+
31+
Object.assign(compilerOptions, persistedState.options);
32+
2033
const sharedEditorOptions: m.editor.IStandaloneEditorConstructionOptions = {
2134
theme: 'vs-dark',
2235
fontSize: 14,
@@ -37,7 +50,7 @@ window.init = () => {
3750
});
3851

3952
const editor = monaco.editor.create(document.getElementById('source')!, {
40-
value: decodeURIComponent(window.location.hash.slice(1)) || localStorage.getItem('state') || 'const App = () => <div>Hello World</div>',
53+
value: decodeURIComponent(window.location.hash.slice(1)) || persistedState.src || 'const App = () => <div>Hello World</div>',
4154
language: 'typescript',
4255
tabSize: 2,
4356
...sharedEditorOptions,

packages/jsx-explorer/src/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
} from 'vue';
44
import { VueJSXPluginOptions } from '../../babel-plugin-jsx/src';
55

6+
export { VueJSXPluginOptions };
7+
68
export const compilerOptions: VueJSXPluginOptions = reactive({
79
mergeProps: true,
810
optimize: false,

0 commit comments

Comments
 (0)