From 4b157a104596f9d81bf8e774718f4bcd98f4154f Mon Sep 17 00:00:00 2001 From: userquin Date: Wed, 21 Aug 2024 21:04:42 +0200 Subject: [PATCH 01/17] feat: add UI improvements --- playground/src/App.vue | 5 +++++ playground/src/router/index.ts | 5 +++++ playground/src/views/Error.vue | 15 +++++++++++++ playground/src/views/Other.vue | 12 +++++++++- playground/src/vite-env.d.ts | 4 ++++ playground/vite.config.ts | 23 ++++++++++++++++++- src/client/components/DurationDisplay.vue | 27 ++++++++++++++++++----- src/client/components/ErrorDisplay.vue | 8 +++---- src/client/components/FilepathItem.vue | 6 ++--- src/client/components/ModuleId.vue | 2 +- src/client/components/ModuleList.vue | 10 ++++----- src/client/components/PluginName.vue | 4 ++-- src/client/pages/index/module.vue | 12 +++++----- uno.config.ts | 11 +++++++++ 14 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 playground/src/views/Error.vue diff --git a/playground/src/App.vue b/playground/src/App.vue index 4abaf77..8fce66a 100644 --- a/playground/src/App.vue +++ b/playground/src/App.vue @@ -8,9 +8,14 @@ import { RouterLink, RouterView } from 'vue-router' Home + | Other + | + + Error + diff --git a/playground/src/router/index.ts b/playground/src/router/index.ts index 8292351..bf5207b 100644 --- a/playground/src/router/index.ts +++ b/playground/src/router/index.ts @@ -14,6 +14,11 @@ const router = createRouter({ path: '/other', component: () => import('../views/Other.vue'), }, + { + name: 'error', + path: '/error', + component: () => import('../views/Error.vue'), + }, ], }) diff --git a/playground/src/views/Error.vue b/playground/src/views/Error.vue new file mode 100644 index 0000000..5c4ea1d --- /dev/null +++ b/playground/src/views/Error.vue @@ -0,0 +1,15 @@ + + + diff --git a/playground/src/views/Other.vue b/playground/src/views/Other.vue index a1665a0..d832f41 100644 --- a/playground/src/views/Other.vue +++ b/playground/src/views/Other.vue @@ -1,7 +1,17 @@ diff --git a/playground/src/vite-env.d.ts b/playground/src/vite-env.d.ts index ed4f286..dc53bc8 100644 --- a/playground/src/vite-env.d.ts +++ b/playground/src/vite-env.d.ts @@ -2,3 +2,7 @@ declare module 'virtual:hi' { const value: string export default value } +declare module 'virtual:slow:*' { + const value: string + export default value +} diff --git a/playground/vite.config.ts b/playground/vite.config.ts index 18994e2..218b07e 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -10,7 +10,7 @@ export default defineConfig({ plugins: [ vue(), { - name: 'custom-loader', + name: 'virtual-loader', resolveId(id) { return id === 'virtual:hi' ? `\0${id}` : undefined }, @@ -19,6 +19,27 @@ export default defineConfig({ return 'export default \'Hi!\'' }, }, + { + name: 'slow-virtual-loader', + // for testing purpose, don't change it + enforce: 'post', + resolveId(id) { + return id.startsWith('virtual:slow:') ? `\0${id}` : undefined + }, + async load(id) { + if (!id.startsWith('\0virtual:slow:')) + return + + const matcher = /^\0virtual:slow:(\d)$/.exec(id) + if (matcher) { + const timeout = +matcher[1] + await new Promise(resolve => setTimeout(resolve, timeout * 1000)) + return `export default 'Hi after ${timeout} seconds!'` + } + + throw new Error('Invalid timeout!') + }, + }, Inspect({ build: true, open: true, diff --git a/src/client/components/DurationDisplay.vue b/src/client/components/DurationDisplay.vue index f9d3782..f73fa4a 100644 --- a/src/client/components/DurationDisplay.vue +++ b/src/client/components/DurationDisplay.vue @@ -15,16 +15,16 @@ function getDurationColor(duration: number | undefined) { if (!props.color) return '' if (duration == null) - return 'text-gray:75' + return 'status-gray' duration = duration * props.factor if (duration < 1) - return 'text-gray:75' + return 'status-gray' if (duration > 1000) - return 'text-red-400' + return 'status-red' if (duration > 500) - return 'text-orange-400' + return 'status-yellow' if (duration > 200) - return 'text-yellow-400' + return 'status-green' return '' } @@ -43,6 +43,21 @@ const units = computed(() => { + + diff --git a/src/client/components/ErrorDisplay.vue b/src/client/components/ErrorDisplay.vue index a250687..4aafa06 100644 --- a/src/client/components/ErrorDisplay.vue +++ b/src/client/components/ErrorDisplay.vue @@ -14,15 +14,15 @@ function normalizeFilename(filename?: string) {