|
| 1 | +import Vue, { h, reactive } from 'vue' |
| 2 | + |
| 3 | +type VueJSXPresetOptions = { |
| 4 | + functional?: boolean |
| 5 | + injectH?: boolean |
| 6 | + vModel?: boolean |
| 7 | + vOn?: boolean |
| 8 | + compositionAPI?: true | 'auto' | 'native' | 'plugin' | 'vue-demi' | false | { importSource: string } |
| 9 | +} |
| 10 | + |
| 11 | +export { type VueJSXPresetOptions } |
| 12 | + |
| 13 | +export const compilerOptions: VueJSXPresetOptions = reactive({ |
| 14 | + functional: true, |
| 15 | + injectH: true, |
| 16 | + vModel: true, |
| 17 | + vOn: true, |
| 18 | + compositionAPI: false, |
| 19 | +}) |
| 20 | + |
| 21 | +const App = { |
| 22 | + setup() { |
| 23 | + return () => [ |
| 24 | + h('div', { attrs: { id: 'header' } }, [ |
| 25 | + h('h1', 'Vue 2 JSX Explorer'), |
| 26 | + h( |
| 27 | + 'a', |
| 28 | + { |
| 29 | + // FIXME: |
| 30 | + href: 'https://github.com/vuejs/jsx-vue2', |
| 31 | + // href: 'https://app.netlify.com/sites/vue-next-jsx-explorer/deploys', |
| 32 | + target: '_blank', |
| 33 | + }, |
| 34 | + 'History', |
| 35 | + ), |
| 36 | + |
| 37 | + h('div', { attrs: { id: 'options-wrapper' } }, [ |
| 38 | + h('div', { attrs: { id: 'options-label' } }, 'Options ↘'), |
| 39 | + h('ul', { attrs: { id: 'options' } }, [ |
| 40 | + h('li', [ |
| 41 | + h('input', { |
| 42 | + attrs: { |
| 43 | + type: 'checkbox', |
| 44 | + id: 'functional', |
| 45 | + name: 'functional', |
| 46 | + }, |
| 47 | + domProps: { |
| 48 | + checked: compilerOptions.functional, |
| 49 | + }, |
| 50 | + on: { |
| 51 | + change: (e: Event) => { |
| 52 | + compilerOptions.functional = (e.target as HTMLInputElement).checked |
| 53 | + }, |
| 54 | + }, |
| 55 | + }), |
| 56 | + h('label', { attrs: { for: 'functional' } }, ['functional']), |
| 57 | + ]), |
| 58 | + |
| 59 | + h('li', [ |
| 60 | + h('input', { |
| 61 | + attrs: { |
| 62 | + type: 'checkbox', |
| 63 | + id: 'injectH', |
| 64 | + name: 'injectH', |
| 65 | + }, |
| 66 | + domProps: { |
| 67 | + checked: compilerOptions.injectH, |
| 68 | + }, |
| 69 | + on: { |
| 70 | + change: (e: Event) => { |
| 71 | + compilerOptions.injectH = (e.target as HTMLInputElement).checked |
| 72 | + }, |
| 73 | + }, |
| 74 | + }), |
| 75 | + h('label', { attrs: { for: 'injectH' } }, ['injectH']), |
| 76 | + ]), |
| 77 | + |
| 78 | + h('li', [ |
| 79 | + h('input', { |
| 80 | + attrs: { |
| 81 | + type: 'checkbox', |
| 82 | + id: 'vModel', |
| 83 | + name: 'vModel', |
| 84 | + }, |
| 85 | + domProps: { |
| 86 | + checked: compilerOptions.vModel, |
| 87 | + }, |
| 88 | + on: { |
| 89 | + change: (e: Event) => { |
| 90 | + compilerOptions.vModel = (e.target as HTMLInputElement).checked |
| 91 | + }, |
| 92 | + }, |
| 93 | + }), |
| 94 | + h('label', { attrs: { for: 'vModel' } }, ['vModel']), |
| 95 | + ]), |
| 96 | + |
| 97 | + h('li', [ |
| 98 | + h('input', { |
| 99 | + attrs: { |
| 100 | + type: 'checkbox', |
| 101 | + id: 'vOn', |
| 102 | + name: 'vOn', |
| 103 | + }, |
| 104 | + domProps: { |
| 105 | + checked: compilerOptions.vOn, |
| 106 | + }, |
| 107 | + on: { |
| 108 | + change: (e: Event) => { |
| 109 | + compilerOptions.vOn = (e.target as HTMLInputElement).checked |
| 110 | + }, |
| 111 | + }, |
| 112 | + }), |
| 113 | + h('label', { attrs: { for: 'vOn' } }, ['vOn']), |
| 114 | + ]), |
| 115 | + |
| 116 | + h('li', [ |
| 117 | + h( |
| 118 | + 'span', |
| 119 | + { |
| 120 | + class: 'label', |
| 121 | + }, |
| 122 | + ['compositionAPI:'], |
| 123 | + ), |
| 124 | + h('input', { |
| 125 | + attrs: { |
| 126 | + type: 'radio', |
| 127 | + name: 'compositionAPI', |
| 128 | + id: 'compositionAPI-false', |
| 129 | + }, |
| 130 | + domProps: { |
| 131 | + checked: compilerOptions.compositionAPI === false, |
| 132 | + }, |
| 133 | + on: { |
| 134 | + change: () => (compilerOptions.compositionAPI = false), |
| 135 | + }, |
| 136 | + }), |
| 137 | + h( |
| 138 | + 'label', |
| 139 | + { |
| 140 | + attrs: { |
| 141 | + for: 'compositionAPI-false', |
| 142 | + }, |
| 143 | + }, |
| 144 | + ['false'], |
| 145 | + ), |
| 146 | + h('input', { |
| 147 | + attrs: { |
| 148 | + type: 'radio', |
| 149 | + name: 'compositionAPI', |
| 150 | + id: 'compositionAPI-auto', |
| 151 | + }, |
| 152 | + domProps: { |
| 153 | + checked: compilerOptions.compositionAPI === true || compilerOptions.compositionAPI === 'auto', |
| 154 | + }, |
| 155 | + on: { |
| 156 | + change: () => (compilerOptions.compositionAPI = 'auto'), |
| 157 | + }, |
| 158 | + }), |
| 159 | + h( |
| 160 | + 'label', |
| 161 | + { |
| 162 | + attrs: { |
| 163 | + for: 'compositionAPI-auto', |
| 164 | + }, |
| 165 | + }, |
| 166 | + ['auto'], |
| 167 | + ), |
| 168 | + h('input', { |
| 169 | + attrs: { |
| 170 | + type: 'radio', |
| 171 | + name: 'compositionAPI', |
| 172 | + id: 'compositionAPI-native', |
| 173 | + }, |
| 174 | + domProps: { |
| 175 | + checked: compilerOptions.compositionAPI === 'native', |
| 176 | + }, |
| 177 | + on: { |
| 178 | + change: () => (compilerOptions.compositionAPI = 'native'), |
| 179 | + }, |
| 180 | + }), |
| 181 | + h( |
| 182 | + 'label', |
| 183 | + { |
| 184 | + attrs: { |
| 185 | + for: 'compositionAPI-native', |
| 186 | + }, |
| 187 | + }, |
| 188 | + ['native'], |
| 189 | + ), |
| 190 | + h('input', { |
| 191 | + attrs: { |
| 192 | + type: 'radio', |
| 193 | + name: 'compositionAPI', |
| 194 | + id: 'compositionAPI-plugin', |
| 195 | + }, |
| 196 | + domProps: { |
| 197 | + checked: compilerOptions.compositionAPI === 'plugin', |
| 198 | + }, |
| 199 | + on: { |
| 200 | + change: () => (compilerOptions.compositionAPI = 'plugin'), |
| 201 | + }, |
| 202 | + }), |
| 203 | + h( |
| 204 | + 'label', |
| 205 | + { |
| 206 | + attrs: { |
| 207 | + for: 'compositionAPI-plugin', |
| 208 | + }, |
| 209 | + }, |
| 210 | + ['plugin'], |
| 211 | + ), |
| 212 | + h('input', { |
| 213 | + attrs: { |
| 214 | + type: 'radio', |
| 215 | + name: 'compositionAPI', |
| 216 | + id: 'compositionAPI-vue-demi', |
| 217 | + }, |
| 218 | + domProps: { |
| 219 | + checked: compilerOptions.compositionAPI === 'vue-demi', |
| 220 | + }, |
| 221 | + on: { |
| 222 | + change: () => (compilerOptions.compositionAPI = 'vue-demi'), |
| 223 | + }, |
| 224 | + }), |
| 225 | + h( |
| 226 | + 'label', |
| 227 | + { |
| 228 | + attrs: { |
| 229 | + for: 'compositionAPI-vue-demi', |
| 230 | + }, |
| 231 | + }, |
| 232 | + ['vue-demi'], |
| 233 | + ), |
| 234 | + ]), |
| 235 | + ]), |
| 236 | + ]), |
| 237 | + ]), |
| 238 | + ] |
| 239 | + }, |
| 240 | +} |
| 241 | + |
| 242 | +export function initOptions() { |
| 243 | + new Vue({ |
| 244 | + render: h => h(App), |
| 245 | + }).$mount(document.getElementById('header')!) |
| 246 | +} |
0 commit comments