| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- import { createApp, h, reactive, ref } from 'vue'
- import type { CompilerOptions } from '@vue/compiler-vapor'
- import { BindingTypes } from '@vue/compiler-core'
- export const ssrMode = ref(false)
- export const vaporMode = ref(true)
- export const defaultOptions: CompilerOptions = {
- mode: 'module',
- filename: 'Foo.vue',
- prefixIdentifiers: false,
- hoistStatic: false,
- cacheHandlers: false,
- scopeId: null,
- inline: false,
- ssrCssVars: `{ color }`,
- compatConfig: { MODE: 3 },
- whitespace: 'condense',
- bindingMetadata: {
- TestComponent: BindingTypes.SETUP_CONST,
- setupRef: BindingTypes.SETUP_REF,
- setupConst: BindingTypes.SETUP_CONST,
- setupLet: BindingTypes.SETUP_LET,
- setupMaybeRef: BindingTypes.SETUP_MAYBE_REF,
- setupProp: BindingTypes.PROPS,
- vMySetupDir: BindingTypes.SETUP_CONST,
- },
- }
- export const compilerOptions: CompilerOptions = reactive(
- Object.assign({}, defaultOptions),
- )
- const App = {
- setup() {
- return () => {
- const isSSR = ssrMode.value
- const isModule = compilerOptions.mode === 'module'
- const usePrefix =
- compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
- return [
- h('h1', `Vue Template Explorer`),
- h(
- 'a',
- {
- href: `https://github.com/vuejs/core/tree/${__COMMIT__}`,
- target: `_blank`,
- },
- `@${__COMMIT__}`,
- ),
- ' | ',
- h(
- 'a',
- {
- href: 'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
- target: `_blank`,
- },
- 'History',
- ),
- h('div', { id: 'options-wrapper' }, [
- h('div', { id: 'options-label' }, 'Options ↘'),
- h('ul', { id: 'options' }, [
- // mode selection
- h('li', { id: 'mode' }, [
- h('span', { class: 'label' }, 'Mode: '),
- h('input', {
- type: 'radio',
- id: 'mode-module',
- name: 'mode',
- checked: isModule,
- onChange() {
- compilerOptions.mode = 'module'
- },
- }),
- h('label', { for: 'mode-module' }, 'module'),
- ' ',
- h('input', {
- type: 'radio',
- id: 'mode-function',
- name: 'mode',
- checked: !isModule,
- onChange() {
- compilerOptions.mode = 'function'
- },
- }),
- h('label', { for: 'mode-function' }, 'function'),
- ]),
- // whitespace handling
- h('li', { id: 'whitespace' }, [
- h('span', { class: 'label' }, 'whitespace: '),
- h('input', {
- type: 'radio',
- id: 'whitespace-condense',
- name: 'whitespace',
- checked: compilerOptions.whitespace === 'condense',
- onChange() {
- compilerOptions.whitespace = 'condense'
- },
- }),
- h('label', { for: 'whitespace-condense' }, 'condense'),
- ' ',
- h('input', {
- type: 'radio',
- id: 'whitespace-preserve',
- name: 'whitespace',
- checked: compilerOptions.whitespace === 'preserve',
- onChange() {
- compilerOptions.whitespace = 'preserve'
- },
- }),
- h('label', { for: 'whitespace-preserve' }, 'preserve'),
- ]),
- // SSR
- h('li', [
- 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'),
- ]),
- // toggle prefixIdentifiers
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'prefix',
- disabled: isModule || isSSR,
- checked: usePrefix || isSSR,
- onChange(e: Event) {
- compilerOptions.prefixIdentifiers =
- (e.target as HTMLInputElement).checked || isModule
- },
- }),
- h('label', { for: 'prefix' }, 'prefixIdentifiers'),
- ]),
- // toggle hoistStatic
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'hoist',
- checked: compilerOptions.hoistStatic && !isSSR,
- disabled: isSSR,
- onChange(e: Event) {
- compilerOptions.hoistStatic = (
- e.target as HTMLInputElement
- ).checked
- },
- }),
- h('label', { for: 'hoist' }, 'hoistStatic'),
- ]),
- // toggle cacheHandlers
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'cache',
- checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
- disabled: !usePrefix || isSSR,
- onChange(e: Event) {
- compilerOptions.cacheHandlers = (
- e.target as HTMLInputElement
- ).checked
- },
- }),
- h('label', { for: 'cache' }, 'cacheHandlers'),
- ]),
- // toggle scopeId
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'scope-id',
- disabled: !isModule,
- checked: isModule && compilerOptions.scopeId,
- onChange(e: Event) {
- compilerOptions.scopeId =
- isModule && (e.target as HTMLInputElement).checked
- ? 'scope-id'
- : null
- },
- }),
- h('label', { for: 'scope-id' }, 'scopeId'),
- ]),
- // inline mode
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'inline',
- checked: compilerOptions.inline,
- onChange(e: Event) {
- compilerOptions.inline = (
- e.target as HTMLInputElement
- ).checked
- },
- }),
- h('label', { for: 'inline' }, 'inline'),
- ]),
- // compat mode
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'compat',
- checked: compilerOptions.compatConfig!.MODE === 2,
- onChange(e: Event) {
- compilerOptions.compatConfig!.MODE = (
- e.target as HTMLInputElement
- ).checked
- ? 2
- : 3
- },
- }),
- h('label', { for: 'compat' }, 'v2 compat mode'),
- ]),
- h('li', [
- h('input', {
- type: 'checkbox',
- id: 'vapor',
- checked: vaporMode.value,
- onChange(e: Event) {
- vaporMode.value = (e.target as HTMLInputElement).checked
- },
- }),
- h('label', { for: 'vapor' }, 'vapor'),
- ]),
- ]),
- ]),
- ]
- }
- },
- }
- export function initOptions() {
- createApp(App).mount(document.getElementById('header')!)
- }
|