options.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import { h, reactive, createApp, ref } from 'vue'
  2. import { CompilerOptions } from '@vue/compiler-dom'
  3. import { BindingTypes } from '@vue/compiler-core'
  4. export const ssrMode = ref(false)
  5. export const defaultOptions: CompilerOptions = {
  6. mode: 'module',
  7. filename: 'Foo.vue',
  8. prefixIdentifiers: false,
  9. hoistStatic: false,
  10. cacheHandlers: false,
  11. scopeId: null,
  12. inline: false,
  13. ssrCssVars: `{ color }`,
  14. compatConfig: { MODE: 3 },
  15. whitespace: 'condense',
  16. bindingMetadata: {
  17. TestComponent: BindingTypes.SETUP_CONST,
  18. setupRef: BindingTypes.SETUP_REF,
  19. setupConst: BindingTypes.SETUP_CONST,
  20. setupLet: BindingTypes.SETUP_LET,
  21. setupMaybeRef: BindingTypes.SETUP_MAYBE_REF,
  22. setupProp: BindingTypes.PROPS,
  23. vMySetupDir: BindingTypes.SETUP_CONST
  24. }
  25. }
  26. export const compilerOptions: CompilerOptions = reactive(
  27. Object.assign({}, defaultOptions)
  28. )
  29. const App = {
  30. setup() {
  31. return () => {
  32. const isSSR = ssrMode.value
  33. const isModule = compilerOptions.mode === 'module'
  34. const usePrefix =
  35. compilerOptions.prefixIdentifiers || compilerOptions.mode === 'module'
  36. return [
  37. h('h1', `Vue 3 Template Explorer`),
  38. h(
  39. 'a',
  40. {
  41. href: `https://github.com/vuejs/core/tree/${__COMMIT__}`,
  42. target: `_blank`
  43. },
  44. `@${__COMMIT__}`
  45. ),
  46. ' | ',
  47. h(
  48. 'a',
  49. {
  50. href: 'https://app.netlify.com/sites/vue-next-template-explorer/deploys',
  51. target: `_blank`
  52. },
  53. 'History'
  54. ),
  55. h('div', { id: 'options-wrapper' }, [
  56. h('div', { id: 'options-label' }, 'Options ↘'),
  57. h('ul', { id: 'options' }, [
  58. // mode selection
  59. h('li', { id: 'mode' }, [
  60. h('span', { class: 'label' }, 'Mode: '),
  61. h('input', {
  62. type: 'radio',
  63. id: 'mode-module',
  64. name: 'mode',
  65. checked: isModule,
  66. onChange() {
  67. compilerOptions.mode = 'module'
  68. }
  69. }),
  70. h('label', { for: 'mode-module' }, 'module'),
  71. ' ',
  72. h('input', {
  73. type: 'radio',
  74. id: 'mode-function',
  75. name: 'mode',
  76. checked: !isModule,
  77. onChange() {
  78. compilerOptions.mode = 'function'
  79. }
  80. }),
  81. h('label', { for: 'mode-function' }, 'function')
  82. ]),
  83. // whitespace handling
  84. h('li', { id: 'whitespace' }, [
  85. h('span', { class: 'label' }, 'whitespace: '),
  86. h('input', {
  87. type: 'radio',
  88. id: 'whitespace-condense',
  89. name: 'whitespace',
  90. checked: compilerOptions.whitespace === 'condense',
  91. onChange() {
  92. compilerOptions.whitespace = 'condense'
  93. }
  94. }),
  95. h('label', { for: 'whitespace-condense' }, 'condense'),
  96. ' ',
  97. h('input', {
  98. type: 'radio',
  99. id: 'whitespace-preserve',
  100. name: 'whitespace',
  101. checked: compilerOptions.whitespace === 'preserve',
  102. onChange() {
  103. compilerOptions.whitespace = 'preserve'
  104. }
  105. }),
  106. h('label', { for: 'whitespace-preserve' }, 'preserve')
  107. ]),
  108. // SSR
  109. h('li', [
  110. h('input', {
  111. type: 'checkbox',
  112. id: 'ssr',
  113. name: 'ssr',
  114. checked: ssrMode.value,
  115. onChange(e: Event) {
  116. ssrMode.value = (e.target as HTMLInputElement).checked
  117. }
  118. }),
  119. h('label', { for: 'ssr' }, 'SSR')
  120. ]),
  121. // toggle prefixIdentifiers
  122. h('li', [
  123. h('input', {
  124. type: 'checkbox',
  125. id: 'prefix',
  126. disabled: isModule || isSSR,
  127. checked: usePrefix || isSSR,
  128. onChange(e: Event) {
  129. compilerOptions.prefixIdentifiers =
  130. (e.target as HTMLInputElement).checked || isModule
  131. }
  132. }),
  133. h('label', { for: 'prefix' }, 'prefixIdentifiers')
  134. ]),
  135. // toggle hoistStatic
  136. h('li', [
  137. h('input', {
  138. type: 'checkbox',
  139. id: 'hoist',
  140. checked: compilerOptions.hoistStatic && !isSSR,
  141. disabled: isSSR,
  142. onChange(e: Event) {
  143. compilerOptions.hoistStatic = (
  144. e.target as HTMLInputElement
  145. ).checked
  146. }
  147. }),
  148. h('label', { for: 'hoist' }, 'hoistStatic')
  149. ]),
  150. // toggle cacheHandlers
  151. h('li', [
  152. h('input', {
  153. type: 'checkbox',
  154. id: 'cache',
  155. checked: usePrefix && compilerOptions.cacheHandlers && !isSSR,
  156. disabled: !usePrefix || isSSR,
  157. onChange(e: Event) {
  158. compilerOptions.cacheHandlers = (
  159. e.target as HTMLInputElement
  160. ).checked
  161. }
  162. }),
  163. h('label', { for: 'cache' }, 'cacheHandlers')
  164. ]),
  165. // toggle scopeId
  166. h('li', [
  167. h('input', {
  168. type: 'checkbox',
  169. id: 'scope-id',
  170. disabled: !isModule,
  171. checked: isModule && compilerOptions.scopeId,
  172. onChange(e: Event) {
  173. compilerOptions.scopeId =
  174. isModule && (e.target as HTMLInputElement).checked
  175. ? 'scope-id'
  176. : null
  177. }
  178. }),
  179. h('label', { for: 'scope-id' }, 'scopeId')
  180. ]),
  181. // inline mode
  182. h('li', [
  183. h('input', {
  184. type: 'checkbox',
  185. id: 'inline',
  186. checked: compilerOptions.inline,
  187. onChange(e: Event) {
  188. compilerOptions.inline = (
  189. e.target as HTMLInputElement
  190. ).checked
  191. }
  192. }),
  193. h('label', { for: 'inline' }, 'inline')
  194. ]),
  195. // compat mode
  196. h('li', [
  197. h('input', {
  198. type: 'checkbox',
  199. id: 'compat',
  200. checked: compilerOptions.compatConfig!.MODE === 2,
  201. onChange(e: Event) {
  202. compilerOptions.compatConfig!.MODE = (
  203. e.target as HTMLInputElement
  204. ).checked
  205. ? 2
  206. : 3
  207. }
  208. }),
  209. h('label', { for: 'compat' }, 'v2 compat mode')
  210. ])
  211. ])
  212. ])
  213. ]
  214. }
  215. }
  216. }
  217. export function initOptions() {
  218. createApp(App).mount(document.getElementById('header')!)
  219. }