From c79531a1584a09542ba9e3d08065a40b1c314cf2 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 10 Aug 2023 12:08:23 +0200 Subject: [PATCH] refactor!: orangize internal host client interface (#381) --- .../devtools-kit/src/_types/client-api.ts | 68 ++++++----- packages/devtools/client/app.vue | 4 +- .../client/components/RestartDialogs.vue | 2 +- .../client/components/TimelineView.vue | 2 +- .../devtools/client/pages/modules/hooks.vue | 2 +- .../client/pages/modules/overview.vue | 15 +-- .../devtools/client/pages/modules/plugins.vue | 4 +- .../client/pages/modules/runtime-configs.vue | 2 +- packages/devtools/client/pages/settings.vue | 4 +- packages/devtools/client/plugins/global.ts | 2 + .../src/runtime/plugins/view/FrameBox.vue | 2 +- .../src/runtime/plugins/view/Main.vue | 6 +- .../src/runtime/plugins/view/client.ts | 114 +++++++++++------- 13 files changed, 133 insertions(+), 94 deletions(-) diff --git a/packages/devtools-kit/src/_types/client-api.ts b/packages/devtools-kit/src/_types/client-api.ts index 9eba1e8f31..8fce4ecd92 100644 --- a/packages/devtools-kit/src/_types/client-api.ts +++ b/packages/devtools-kit/src/_types/client-api.ts @@ -42,6 +42,14 @@ export interface NuxtDevtoolsClientHooks { * Triggers reactivity manually, since Vue won't be reactive across frames) */ 'host:update:reactivity': () => void + /** + * Host action to control the DevTools navigation + */ + 'host:action:navigate': (path: string) => void + /** + * Host action to reload the DevTools + */ + 'host:action:reload': () => void } /** @@ -49,10 +57,9 @@ export interface NuxtDevtoolsClientHooks { */ export interface NuxtDevtoolsHostClient { nuxt: NuxtApp - appConfig: AppConfig hooks: Hookable - colorMode: Ref<'dark' | 'light'> + getIframe(): HTMLIFrameElement | undefined inspector?: { instance?: VueInspectorClient @@ -62,38 +69,45 @@ export interface NuxtDevtoolsHostClient { isEnabled: Ref } - loadingTimeMetrics: LoadingTimeMetric - getClientHooksMetrics(): HookInfo[] - - clientPluginMetrics: PluginMetric[] | undefined - clientTimelineMetrics: TimelineMetrics | undefined - - reloadPage(): void + devtools: { + close(): void + open(): void + toggle(): void + reload(): void + navigate(path: string): void + + /** + * Popup the DevTools frame into Picture-in-Picture mode + * + * Requires Chrome 111 with experimental flag enabled. + * + * Function is undefined when not supported. + * + * @see https://developer.chrome.com/docs/web-platform/document-picture-in-picture/ + */ + popup?(): any + } - close(): void - open(): void - toggle(): void + app: { + reload(): void + navigate(path: string, hard?: boolean): void + appConfig: AppConfig + colorMode: Ref<'dark' | 'light'> + frameState: Ref + } - /** - * Popup the DevTools frame into Picture-in-Picture mode - * - * Requires Chrome 111 with experimental flag enabled. - * - * Function is undefined when not supported. - * - * @see https://developer.chrome.com/docs/web-platform/document-picture-in-picture/ - */ - popup?(): any + metrics: { + clientHooks(): HookInfo[] + clientPlugins(): PluginMetric[] | undefined + clientTimeline(): TimelineMetrics | undefined + loading(): LoadingTimeMetric + } /** * Update client * @internal */ - updateClient(): NuxtDevtoolsHostClient - - getIframe(): HTMLIFrameElement | undefined - - frameState: Ref + syncClient(): NuxtDevtoolsHostClient } export interface NuxtDevtoolsClient { diff --git a/packages/devtools/client/app.vue b/packages/devtools/client/app.vue index ef40a01e43..5f7c764dcc 100644 --- a/packages/devtools/client/app.vue +++ b/packages/devtools/client/app.vue @@ -36,7 +36,7 @@ const isUtilityView = computed(() => route.path.startsWith('/__')) const waiting = computed(() => !client.value && !showConnectionWarning.value) watch( - () => client.value?.colorMode.value, + () => client.value?.app.colorMode.value, (mode) => { if (mode) colorMode.value = mode @@ -46,7 +46,7 @@ watch( addEventListener('keydown', (e) => { if (e.code === 'KeyD' && e.altKey) { - client.value?.close() + client.value?.devtools.close() e.preventDefault() } }) diff --git a/packages/devtools/client/components/RestartDialogs.vue b/packages/devtools/client/components/RestartDialogs.vue index 00b8efded3..b23e45ea6e 100644 --- a/packages/devtools/client/components/RestartDialogs.vue +++ b/packages/devtools/client/components/RestartDialogs.vue @@ -17,7 +17,7 @@ nuxt.hook('devtools:terminal:exit', ({ id, code }) => { if (result) { rpc.restartNuxt() setTimeout(() => { - client.value?.reloadPage() + client.value?.app.reload() }, 500) } }) diff --git a/packages/devtools/client/components/TimelineView.vue b/packages/devtools/client/components/TimelineView.vue index 2e29eb95e5..1b787ab71f 100644 --- a/packages/devtools/client/components/TimelineView.vue +++ b/packages/devtools/client/components/TimelineView.vue @@ -6,7 +6,7 @@ const client = useClient() const view = ref<'table' | 'list'>('table') const selected = ref() -const metrics = computed(() => client.value?.clientTimelineMetrics) +const metrics = computed(() => client.value?.metrics.clientTimeline()) function clear() { if (metrics.value) diff --git a/packages/devtools/client/pages/modules/hooks.vue b/packages/devtools/client/pages/modules/hooks.vue index f4adfef317..2f597ba80c 100644 --- a/packages/devtools/client/pages/modules/hooks.vue +++ b/packages/devtools/client/pages/modules/hooks.vue @@ -7,7 +7,7 @@ definePageMeta({ const serverHooks = useServerHooks() const client = useClient() -const clientHooks = computed(() => client.value?.getClientHooksMetrics()) +const clientHooks = computed(() => client.value?.metrics.clientHooks())