diff --git a/client/app.vue b/client/app.vue index 541e1fdb..1660aa02 100644 --- a/client/app.vue +++ b/client/app.vue @@ -3,26 +3,52 @@ import 'floating-vue/dist/style.css' import { useLocalStorage } from '@vueuse/core' import { envTab, - globalDebug, path, refreshSources, } from './util/logic' import { + appFetch, colorMode, computed, - fetchGlobalDebug, highlight, + useAsyncData, useHead, } from '#imports' -import { fetchPageDebug } from '~/composables/fetch' useHead({ - title: 'Nuxt Simple Robots', + title: 'Nuxt Robots', }) -globalDebug.value = await fetchGlobalDebug() +const globalDebugFetch = useAsyncData<{ indexable: boolean, hints: string[], runtimeConfig: { version: string } }>(() => { + if (!appFetch.value || typeof appFetch.value !== 'function') { + return null + } + const query: Record = {} + if (envTab.value === 'Production') + query.mockProductionEnv = true + return appFetch.value('/__robots__/debug.json', { + query, + }) +}, { + watch: [envTab, appFetch], +}) +const { data: globalDebug } = globalDebugFetch -const pathDebug = await fetchPageDebug() +const pathDebug = useAsyncData(() => { + if (!appFetch.value || typeof appFetch.value !== 'function') { + return null + } + const query: Record = { + path: path.value, + } + if (envTab.value === 'Production') + query.mockProductionEnv = true + return appFetch.value('/__robots__/debug-path.json', { + query, + }) +}, { + watch: [envTab, path, appFetch], +}) const pathDebugData = computed(() => pathDebug.data?.value) @@ -33,7 +59,7 @@ useHead({ }, }) -const globalDebugData = computed(() => globalDebug.value?.data) +const globalDebugData = computed(() => globalDebug.value || {}) const version = computed(() => { return globalDebugData.value?.runtimeConfig?.version || '' @@ -142,11 +168,11 @@ const tab = useLocalStorage('nuxt-robots:tab', 'overview')
-
+
-
- {{ globalDebug!.error }} +
+ {{ globalDebugFetch.error.value }}
-import { useVModel } from '@vueuse/core' +import { ref } from '#imports' const props = withDefaults( defineProps<{ @@ -20,9 +20,14 @@ const props = withDefaults( }, ) -const open = useVModel(props, 'open') +const emits = defineEmits<{ + 'update:modelValue': [value: boolean] +}>() + +const open = ref(props.open) function onToggle(e: any) { open.value = e.target.open + emits('update:modelValue', e.target.open) } diff --git a/client/composables/fetch.ts b/client/composables/fetch.ts deleted file mode 100644 index 5535419b..00000000 --- a/client/composables/fetch.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { envTab, path } from '../util/logic' -import { appFetch } from './rpc' -import { useAsyncData } from '#imports' - -export function fetchPageDebug() { - return useAsyncData(() => { - const query: Record = { - path: path.value, - } - if (envTab.value === 'Production') - query.mockProductionEnv = true - return appFetch.value('/__robots__/debug-path.json', { - query, - }) - }, { - watch: [envTab, path], - }) -} - -export function fetchGlobalDebug() { - return useAsyncData(() => { - const query: Record = {} - if (envTab.value === 'Production') - query.mockProductionEnv = true - return appFetch.value('/__robots__/debug.json', { - query, - }) - }, { - watch: [envTab], - }) -} diff --git a/client/composables/rpc.ts b/client/composables/rpc.ts index 02984038..a7f5200a 100644 --- a/client/composables/rpc.ts +++ b/client/composables/rpc.ts @@ -2,7 +2,7 @@ import { onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client' import type { $Fetch } from 'nitropack' import { ref, watchEffect } from 'vue' import type { NuxtDevtoolsClient, NuxtDevtoolsIframeClient } from '@nuxt/devtools-kit/types' -import type { ClientFunctions, ServerFunctions } from '../../src/rpc-types' +import type { ClientFunctions, ServerFunctions } from '../../src/devtools' import { globalRefreshTime, path, query, refreshSources } from '~/util/logic' export const appFetch = ref<$Fetch>() diff --git a/client/composables/shiki.ts b/client/composables/shiki.ts index 7f0aa64e..fadc66e5 100644 --- a/client/composables/shiki.ts +++ b/client/composables/shiki.ts @@ -4,6 +4,7 @@ import { ref } from 'vue' import { useColorMode } from '#imports' export const shiki = ref() +const mode = useColorMode() // TODO: Only loading when needed getHighlighter({ @@ -18,7 +19,6 @@ getHighlighter({ }).then((i) => { shiki.value = i }) export function highlight(code: string, lang: BundledLanguage) { - const mode = useColorMode() if (!shiki.value) return code return shiki.value.codeToHtml(code, { diff --git a/client/util/logic.ts b/client/util/logic.ts index 41ee61a3..29ec7ccd 100644 --- a/client/util/logic.ts +++ b/client/util/logic.ts @@ -1,11 +1,9 @@ import { computed, ref } from 'vue' import { useDebounceFn, useLocalStorage } from '@vueuse/core' import { withBase } from 'ufo' -import type { _AsyncData } from '#app/composables/asyncData' export const envTab = useLocalStorage('nuxt-robots:env-tab', 'Production') -export const globalDebug = ref<_AsyncData<{ indexable: boolean, hints: string[], runtimeConfig: { version: string } }, any>>() export const refreshTime = ref(Date.now()) export const globalRefreshTime = ref(Date.now())