vue3-yuanma/packages/template-explorer/src/options.ts

117 lines
3.5 KiB
TypeScript
Raw Normal View History

2019-10-05 05:43:20 +08:00
import { h, reactive, createApp } from '@vue/runtime-dom'
import { CompilerOptions } from '@vue/compiler-dom'
export const compilerOptions: CompilerOptions = reactive({
mode: 'module',
prefixIdentifiers: false,
2019-10-19 09:51:34 +08:00
hoistStatic: false,
cacheHandlers: false,
scopeId: null
2019-10-05 05:43:20 +08:00
})
const App = {
setup() {
return () => {
const usePrefix =
compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
return [
h('h1', `Vue 3 Template Explorer`),
h(
'a',
{
href: `https://github.com/vuejs/vue-next/tree/${__COMMIT__}`,
target: `_blank`
},
`@${__COMMIT__}`
),
h('div', { id: 'options' }, [
// mode selection
h('span', { class: 'options-group' }, [
h('span', { class: 'label' }, 'Mode:'),
h('input', {
type: 'radio',
id: 'mode-module',
name: 'mode',
checked: compilerOptions.mode === 'module',
onChange() {
compilerOptions.mode = 'module'
}
}),
h('label', { for: 'mode-module' }, 'module'),
h('input', {
type: 'radio',
id: 'mode-function',
name: 'mode',
checked: compilerOptions.mode === 'function',
onChange() {
compilerOptions.mode = 'function'
}
}),
h('label', { for: 'mode-function' }, 'function')
]),
// toggle prefixIdentifiers
2019-10-05 05:43:20 +08:00
h('input', {
type: 'checkbox',
id: 'prefix',
disabled: compilerOptions.mode === 'module',
checked: usePrefix,
onChange(e: Event) {
compilerOptions.prefixIdentifiers =
(<HTMLInputElement>e.target).checked ||
compilerOptions.mode === 'module'
2019-10-05 05:43:20 +08:00
}
}),
h('label', { for: 'prefix' }, 'prefixIdentifiers'),
// toggle hoistStatic
2019-10-05 05:43:20 +08:00
h('input', {
type: 'checkbox',
id: 'hoist',
checked: compilerOptions.hoistStatic,
onChange(e: Event) {
compilerOptions.hoistStatic = (<HTMLInputElement>e.target).checked
2019-10-05 05:43:20 +08:00
}
}),
h('label', { for: 'hoist' }, 'hoistStatic'),
2019-10-19 09:51:34 +08:00
// toggle cacheHandlers
h('input', {
type: 'checkbox',
id: 'cache',
checked: usePrefix && compilerOptions.cacheHandlers,
disabled: !usePrefix,
onChange(e: Event) {
compilerOptions.cacheHandlers = (<HTMLInputElement>(
e.target
)).checked
}
}),
h('label', { for: 'cache' }, 'cacheHandlers'),
// toggle scopeId
h('input', {
type: 'checkbox',
id: 'scope-id',
disabled: compilerOptions.mode !== 'module',
checked:
compilerOptions.mode === 'module' && compilerOptions.scopeId,
onChange(e: Event) {
compilerOptions.scopeId =
compilerOptions.mode === 'module' &&
(<HTMLInputElement>e.target).checked
? 'scope-id'
: null
}
}),
h('label', { for: 'scope-id' }, 'scopeId')
])
]
}
2019-10-05 05:43:20 +08:00
}
}
export function initOptions() {
createApp().mount(App, document.getElementById('header')!)
2019-10-05 05:43:20 +08:00
}