fix: jsx-explorer default text value error

This commit is contained in:
Amour1688 2021-03-04 16:55:43 +08:00
parent b2d0394281
commit 4c858a26e4
2 changed files with 17 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import * as m from 'monaco-editor';
import { watchEffect } from 'vue'; import { watchEffect } from 'vue';
import { transform } from '@babel/core'; import { transform } from '@babel/core';
import babelPluginJsx from '../../babel-plugin-jsx/src'; import babelPluginJsx from '../../babel-plugin-jsx/src';
import { initOptions, compilerOptions } from './options'; import { initOptions, compilerOptions, VueJSXPluginOptions } from './options';
import './index.css'; import './index.css';
declare global { declare global {
@ -14,9 +14,22 @@ declare global {
} }
} }
interface PersistedState {
src: string
options: VueJSXPluginOptions
}
window.init = () => { window.init = () => {
const { monaco } = window; const { monaco } = window;
const persistedState: PersistedState = JSON.parse(
decodeURIComponent(window.location.hash.slice(1))
|| localStorage.getItem('state')
|| '{}',
);
Object.assign(compilerOptions, persistedState.options);
const sharedEditorOptions: m.editor.IStandaloneEditorConstructionOptions = { const sharedEditorOptions: m.editor.IStandaloneEditorConstructionOptions = {
theme: 'vs-dark', theme: 'vs-dark',
fontSize: 14, fontSize: 14,
@ -37,7 +50,7 @@ window.init = () => {
}); });
const editor = monaco.editor.create(document.getElementById('source')!, { const editor = monaco.editor.create(document.getElementById('source')!, {
value: decodeURIComponent(window.location.hash.slice(1)) || localStorage.getItem('state') || 'const App = () => <div>Hello World</div>', value: decodeURIComponent(window.location.hash.slice(1)) || persistedState.src || 'const App = () => <div>Hello World</div>',
language: 'typescript', language: 'typescript',
tabSize: 2, tabSize: 2,
...sharedEditorOptions, ...sharedEditorOptions,

View File

@ -3,6 +3,8 @@ import {
} from 'vue'; } from 'vue';
import { VueJSXPluginOptions } from '../../babel-plugin-jsx/src'; import { VueJSXPluginOptions } from '../../babel-plugin-jsx/src';
export { VueJSXPluginOptions };
export const compilerOptions: VueJSXPluginOptions = reactive({ export const compilerOptions: VueJSXPluginOptions = reactive({
mergeProps: true, mergeProps: true,
optimize: false, optimize: false,