workflow(template-explorer): persist compilerOptions
This commit is contained in:
parent
a8c82909fa
commit
31345b5af9
@ -8,9 +8,11 @@ const self = window as any
|
|||||||
|
|
||||||
self.init = () => {
|
self.init = () => {
|
||||||
const monaco = (window as any).monaco as typeof m
|
const monaco = (window as any).monaco as typeof m
|
||||||
const persistedContent =
|
const persistedState = JSON.parse(
|
||||||
decodeURIComponent(window.location.hash.slice(1)) ||
|
decodeURIComponent(window.location.hash.slice(1)) || `{}`
|
||||||
`<div>{{ foo + bar }}</div>`
|
)
|
||||||
|
|
||||||
|
Object.assign(compilerOptions, persistedState.options)
|
||||||
|
|
||||||
let lastSuccessfulCode: string = `/* See console for error */`
|
let lastSuccessfulCode: string = `/* See console for error */`
|
||||||
let lastSuccessfulMap: SourceMapConsumer | undefined = undefined
|
let lastSuccessfulMap: SourceMapConsumer | undefined = undefined
|
||||||
@ -56,7 +58,13 @@ self.init = () => {
|
|||||||
|
|
||||||
function reCompile() {
|
function reCompile() {
|
||||||
const src = editor.getValue()
|
const src = editor.getValue()
|
||||||
window.location.hash = encodeURIComponent(src)
|
// every time we re-compile, persist current state to URL
|
||||||
|
window.location.hash = encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
src,
|
||||||
|
options: compilerOptions
|
||||||
|
})
|
||||||
|
)
|
||||||
const res = compileCode(src)
|
const res = compileCode(src)
|
||||||
if (res) {
|
if (res) {
|
||||||
output.setValue(res)
|
output.setValue(res)
|
||||||
@ -78,7 +86,7 @@ self.init = () => {
|
|||||||
const editor = monaco.editor.create(
|
const editor = monaco.editor.create(
|
||||||
document.getElementById('source') as HTMLElement,
|
document.getElementById('source') as HTMLElement,
|
||||||
{
|
{
|
||||||
value: persistedContent,
|
value: persistedState.src || `<div>Hello World!</div>`,
|
||||||
language: 'html',
|
language: 'html',
|
||||||
...sharedEditorOptions
|
...sharedEditorOptions
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user