diff --git a/packages/jsx-explorer/src/index.ts b/packages/jsx-explorer/src/index.ts index 2e952e1..ad3cbe4 100644 --- a/packages/jsx-explorer/src/index.ts +++ b/packages/jsx-explorer/src/index.ts @@ -4,7 +4,7 @@ import * as m from 'monaco-editor'; import { watchEffect } from 'vue'; import { transform } from '@babel/core'; import babelPluginJsx from '../../babel-plugin-jsx/src'; -import { initOptions, compilerOptions } from './options'; +import { initOptions, compilerOptions, VueJSXPluginOptions } from './options'; import './index.css'; declare global { @@ -14,9 +14,22 @@ declare global { } } +interface PersistedState { + src: string + options: VueJSXPluginOptions +} + window.init = () => { 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 = { theme: 'vs-dark', fontSize: 14, @@ -37,7 +50,7 @@ window.init = () => { }); const editor = monaco.editor.create(document.getElementById('source')!, { - value: decodeURIComponent(window.location.hash.slice(1)) || localStorage.getItem('state') || 'const App = () =>