|
1 | 1 | <script setup lang="ts"> |
| 2 | +import type { ClientScriptEntry, DevToolsDockEntry } from '@vitejs/devtools-kit' |
2 | 3 | import type { DockProps } from './DockProps' |
3 | 4 | import { useEventListener, useScreenSafeArea } from '@vueuse/core' |
4 | 5 | import { computed, onMounted, reactive, ref, toRefs, useTemplateRef, watchEffect } from 'vue' |
@@ -213,6 +214,32 @@ const panelStyle = computed(() => { |
213 | 214 | return style |
214 | 215 | }) |
215 | 216 |
|
| 217 | +// TODO: use a visual module to host all the imports |
| 218 | +function importScript(entry: ClientScriptEntry) { |
| 219 | + return import(/* @vite-ignore */ entry.importFrom) |
| 220 | + .then((module) => { |
| 221 | + return module[entry.importName || 'default'] |
| 222 | + }) |
| 223 | + .catch((error) => { |
| 224 | + // TODO: maybe popup a error toast here? |
| 225 | + console.error('[VITE DEVTOOLS] Error importing action', error) |
| 226 | + return Promise.reject(error) |
| 227 | + }) |
| 228 | +} |
| 229 | +
|
| 230 | +function onSelected(entry: DevToolsDockEntry) { |
| 231 | + if (entry?.type === 'action') { |
| 232 | + return importScript(entry.import).then(fn => fn()) |
| 233 | + } |
| 234 | +
|
| 235 | + state.value.dockEntry = entry |
| 236 | +
|
| 237 | + // TODO: handle for each type of entry |
| 238 | + if ('import' in entry && entry.import) { |
| 239 | + importScript(entry.import) |
| 240 | + } |
| 241 | +} |
| 242 | +
|
216 | 243 | onMounted(() => { |
217 | 244 | bringUp() |
218 | 245 | recalculateCounter.value++ |
@@ -250,7 +277,7 @@ onMounted(() => { |
250 | 277 | :class="isMinimized ? 'opacity-0' : 'opacity-100'" |
251 | 278 | :is-vertical="isVertical" |
252 | 279 | :selected="state.dockEntry" |
253 | | - @select="s => state.dockEntry = s" |
| 280 | + @select="onSelected" |
254 | 281 | /> |
255 | 282 | </div> |
256 | 283 | </div> |
|
0 commit comments