2020-02-05 04:59:37 +08:00
|
|
|
import { h, reactive, createApp, ref } from 'vue'
|
2019-10-05 05:43:20 +08:00
|
|
|
import { CompilerOptions } from '@vue/compiler-dom'
|
|
|
|
|
2020-02-05 04:59:37 +08:00
|
|
|
export const ssrMode = ref(false)
|
|
|
|
|
2019-10-05 05:43:20 +08:00
|
|
|
export const compilerOptions: CompilerOptions = reactive({
|
|
|
|
mode: 'module',
|
|
|
|
prefixIdentifiers: false,
|
2019-10-19 09:51:34 +08:00
|
|
|
hoistStatic: false,
|
2019-12-17 01:11:51 +08:00
|
|
|
cacheHandlers: false,
|
|
|
|
scopeId: null
|
2019-10-05 05:43:20 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
setup() {
|
2019-12-11 01:46:38 +08:00
|
|
|
return () => {
|
2020-02-05 04:59:37 +08:00
|
|
|
const isSSR = ssrMode.value
|
|
|
|
const isModule = compilerOptions.mode === 'module'
|
2019-12-11 01:46:38 +08:00
|
|
|
const usePrefix =
|
|
|
|
compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
|
2020-02-05 04:59:37 +08:00
|
|
|
|
2019-12-11 01:46:38 +08:00
|
|
|
return [
|
|
|
|
h('h1', `Vue 3 Template Explorer`),
|
|
|
|
h(
|
|
|
|
'a',
|
|
|
|
{
|
|
|
|
href: `https://github.com/vuejs/vue-next/tree/${__COMMIT__}`,
|
|
|
|
target: `_blank`
|
|
|
|
},
|
|
|
|
`@${__COMMIT__}`
|
|
|
|
),
|
2020-02-05 04:59:37 +08:00
|
|
|
|
2019-12-11 01:46:38 +08:00
|
|
|
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',
|
2020-02-05 04:59:37 +08:00
|
|
|
checked: isModule,
|
2019-12-11 01:46:38 +08:00
|
|
|
onChange() {
|
|
|
|
compilerOptions.mode = 'module'
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
h('label', { for: 'mode-module' }, 'module'),
|
|
|
|
h('input', {
|
|
|
|
type: 'radio',
|
|
|
|
id: 'mode-function',
|
|
|
|
name: 'mode',
|
2020-02-05 04:59:37 +08:00
|
|
|
checked: !isModule,
|
2019-12-11 01:46:38 +08:00
|
|
|
onChange() {
|
|
|
|
compilerOptions.mode = 'function'
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
h('label', { for: 'mode-function' }, 'function')
|
|
|
|
]),
|
|
|
|
|
2020-02-05 04:59:37 +08:00
|
|
|
// SSR
|
|
|
|
h('input', {
|
|
|
|
type: 'checkbox',
|
|
|
|
id: 'ssr',
|
|
|
|
name: 'ssr',
|
|
|
|
checked: ssrMode.value,
|
|
|
|
onChange(e: Event) {
|
|
|
|
ssrMode.value = (e.target as HTMLInputElement).checked
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
h('label', { for: 'ssr' }, 'SSR'),
|
|
|
|
|
2019-12-11 01:46:38 +08:00
|
|
|
// toggle prefixIdentifiers
|
2019-10-05 05:43:20 +08:00
|
|
|
h('input', {
|
2019-12-11 01:46:38 +08:00
|
|
|
type: 'checkbox',
|
|
|
|
id: 'prefix',
|
2020-02-05 04:59:37 +08:00
|
|
|
disabled: isModule || isSSR,
|
|
|
|
checked: usePrefix || isSSR,
|
2019-12-11 01:46:38 +08:00
|
|
|
onChange(e: Event) {
|
|
|
|
compilerOptions.prefixIdentifiers =
|
2020-02-05 04:59:37 +08:00
|
|
|
(e.target as HTMLInputElement).checked || isModule
|
2019-10-05 05:43:20 +08:00
|
|
|
}
|
|
|
|
}),
|
2019-12-11 01:46:38 +08:00
|
|
|
h('label', { for: 'prefix' }, 'prefixIdentifiers'),
|
|
|
|
|
|
|
|
// toggle hoistStatic
|
2019-10-05 05:43:20 +08:00
|
|
|
h('input', {
|
2019-12-11 01:46:38 +08:00
|
|
|
type: 'checkbox',
|
|
|
|
id: 'hoist',
|
2020-02-05 04:59:37 +08:00
|
|
|
checked: compilerOptions.hoistStatic && !isSSR,
|
|
|
|
disabled: isSSR,
|
2019-12-11 01:46:38 +08:00
|
|
|
onChange(e: Event) {
|
2020-02-05 04:59:37 +08:00
|
|
|
compilerOptions.hoistStatic = (e.target as HTMLInputElement).checked
|
2019-10-05 05:43:20 +08:00
|
|
|
}
|
|
|
|
}),
|
2019-12-11 01:46:38 +08:00
|
|
|
h('label', { for: 'hoist' }, 'hoistStatic'),
|
2019-10-19 09:51:34 +08:00
|
|
|
|
2019-12-11 01:46:38 +08:00
|
|
|
// toggle cacheHandlers
|
|
|
|
h('input', {
|
|
|
|
type: 'checkbox',
|
|
|
|
id: 'cache',
|
2020-02-05 04:59:37 +08:00
|
|
|
checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
|
|
|
|
disabled: !usePrefix || isSSR,
|
2019-12-11 01:46:38 +08:00
|
|
|
onChange(e: Event) {
|
2020-02-05 04:59:37 +08:00
|
|
|
compilerOptions.cacheHandlers = (e.target as HTMLInputElement).checked
|
2019-12-11 01:46:38 +08:00
|
|
|
}
|
|
|
|
}),
|
2019-12-17 01:11:51 +08:00
|
|
|
h('label', { for: 'cache' }, 'cacheHandlers'),
|
|
|
|
|
|
|
|
// toggle scopeId
|
|
|
|
h('input', {
|
|
|
|
type: 'checkbox',
|
|
|
|
id: 'scope-id',
|
2020-02-05 04:59:37 +08:00
|
|
|
disabled: !isModule,
|
|
|
|
checked: isModule && compilerOptions.scopeId,
|
2019-12-17 01:11:51 +08:00
|
|
|
onChange(e: Event) {
|
|
|
|
compilerOptions.scopeId =
|
2020-02-05 04:59:37 +08:00
|
|
|
isModule && (e.target as HTMLInputElement).checked
|
2019-12-17 01:11:51 +08:00
|
|
|
? 'scope-id'
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
h('label', { for: 'scope-id' }, 'scopeId')
|
2019-12-11 01:46:38 +08:00
|
|
|
])
|
|
|
|
]
|
|
|
|
}
|
2019-10-05 05:43:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function initOptions() {
|
2020-01-30 00:28:18 +08:00
|
|
|
createApp(App).mount(document.getElementById('header')!)
|
2019-10-05 05:43:20 +08:00
|
|
|
}
|