diff --git a/.vscode/settings.json b/.vscode/settings.json index 02c83895..0823b7b2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -31,5 +31,8 @@ "yaml" ], "scss.lint.unknownAtRules": "ignore", - "typescript.tsdk": "node_modules/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib", + "cSpell.words": [ + "Mergeable" + ] } diff --git a/packages/applet/src/components/basic/AppConnecting.vue b/packages/applet/src/components/basic/AppConnecting.vue new file mode 100644 index 00000000..d26c06ea --- /dev/null +++ b/packages/applet/src/components/basic/AppConnecting.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/packages/applet/src/components/basic/DevToolsHeader.vue b/packages/applet/src/components/basic/DevToolsHeader.vue index 01a660c7..a734d3d1 100644 --- a/packages/applet/src/components/basic/DevToolsHeader.vue +++ b/packages/applet/src/components/basic/DevToolsHeader.vue @@ -3,7 +3,7 @@ import { defineProps } from 'vue' import { useVirtualRouter } from '~/composables/virtual-router' defineProps<{ - githubRepoLink: string + githubRepoLink?: string docLink: string }>() const router = useVirtualRouter() @@ -20,7 +20,7 @@ const router = useVirtualRouter() - + diff --git a/packages/applet/src/components/basic/SelectiveList.vue b/packages/applet/src/components/basic/SelectiveList.vue index 5709105a..06565be2 100644 --- a/packages/applet/src/components/basic/SelectiveList.vue +++ b/packages/applet/src/components/basic/SelectiveList.vue @@ -1,9 +1,9 @@ diff --git a/packages/applet/src/composables/connect-state.ts b/packages/applet/src/composables/connect-state.ts deleted file mode 100644 index 3d0a43c1..00000000 --- a/packages/applet/src/composables/connect-state.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { getDevToolsState, onDevToolsStateUpdated } from '@vue/devtools-core' -import type { ComputedRef, InjectionKey } from 'vue' -import { computed, inject, provide, ref, watch } from 'vue' - -const VueDevToolsConnectStateSymbol: InjectionKey> = Symbol('VueDevToolsConnectStateSymbol') - -export function createDevToolsConnectStateContext() { - const appConnected = ref(false) - const clientConnected = ref(false) - const connected = computed(() => appConnected.value && clientConnected.value) - - getDevToolsState().then((data) => { - appConnected.value = data!.connected - clientConnected.value = data!.clientConnected - }) - - onDevToolsStateUpdated((data) => { - appConnected.value = data.connected - clientConnected.value = data.clientConnected - }) - - provide(VueDevToolsConnectStateSymbol, connected) - - return { - connected, - } -} - -export function useDevToolsConnectState() { - return inject(VueDevToolsConnectStateSymbol, ref(false)) -} - -export function onDevToolsClientConnected(callback: () => void) { - const connected = useDevToolsConnectState() - - if (connected.value) { - callback() - } - else { - const stop = watch(connected, (value) => { - if (value) { - stop() - callback() - } - }) - } -} diff --git a/packages/applet/src/composables/custom-inspector-state.ts b/packages/applet/src/composables/custom-inspector-state.ts new file mode 100644 index 00000000..9226ce10 --- /dev/null +++ b/packages/applet/src/composables/custom-inspector-state.ts @@ -0,0 +1,28 @@ +import { inject, provide, ref } from 'vue' +import type { InjectionKey, Ref } from 'vue' + +type CustomInspectorState = Partial<{ + homepage: string + id: string + label: string + logo: string + timelineLayerIds: string[] +}> + +const VueDevToolsStateSymbol: InjectionKey> = Symbol('VueDevToolsCustomInspectorStateSymbol') + +export function useCustomInspectorState() { + return inject(VueDevToolsStateSymbol)! +} + +export function createCustomInspectorStateContext() { + const state = ref({ + homepage: '', + id: '', + label: '', + logo: '', + timelineLayerIds: [], + }) as Ref + provide(VueDevToolsStateSymbol, state) + return state +} diff --git a/packages/applet/src/composables/custom-inspector.ts b/packages/applet/src/composables/custom-inspector.ts new file mode 100644 index 00000000..a94e3ee7 --- /dev/null +++ b/packages/applet/src/composables/custom-inspector.ts @@ -0,0 +1,51 @@ +import { onUnmounted, ref } from 'vue' +import { DevToolsMessagingEvents, onRpcConnected, rpc } from '@vue/devtools-core' + +export interface CustomInspectorType { + id: string + label: string + logo: string + packageName: string | undefined + homepage: string | undefined +} + +export function useCustomInspector() { + const registeredInspector = ref([]) + const inspectors = ref([]) + + function onUpdate(inspector: CustomInspectorType[]) { + inspectors.value = inspector + if (inspector.length < registeredInspector.value.length) { + registeredInspector.value = [] + } + inspectors.value.forEach((inspector) => { + register(inspector) + }) + } + onRpcConnected(() => { + rpc.value.getCustomInspector().then((inspector) => { + inspectors.value = inspector + inspectors.value.forEach((inspector) => { + register(inspector) + }) + }) + rpc.functions.on(DevToolsMessagingEvents.INSPECTOR_UPDATED, onUpdate) + }) + + function register(inspector: CustomInspectorType) { + if (registeredInspector.value.some(i => i.id === inspector.id)) { + return + } + + registeredInspector.value.push(inspector) + } + + onUnmounted(() => { + rpc.functions.off(DevToolsMessagingEvents.INSPECTOR_UPDATED, onUpdate) + }) + + return { + registeredInspector, + register, + } +} diff --git a/packages/applet/src/composables/devtools-state.ts b/packages/applet/src/composables/devtools-state.ts deleted file mode 100644 index a0ec7a6f..00000000 --- a/packages/applet/src/composables/devtools-state.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { getDevToolsState, onDevToolsStateUpdated } from '@vue/devtools-core' -import type { InjectionKey, Ref } from 'vue' -import { inject, provide, ref } from 'vue' - -import type { AppRecord } from '@vue/devtools-kit' - -export type DevtoolsBridgeAppRecord = Pick - -const VueDevToolsStateSymbol: InjectionKey<{ - appRecords: Ref> - activeAppRecordId: Ref -}> = Symbol('VueDevToolsStateSymbol') - -export function createDevToolsStateContext() { - const appRecords = ref>([]) - const activeAppRecordId = ref('') - - getDevToolsState().then((data) => { - appRecords.value = data!.appRecords - activeAppRecordId.value = data!.activeAppRecordId! - }) - - onDevToolsStateUpdated((data) => { - appRecords.value = data.appRecords - activeAppRecordId.value = data.activeAppRecordId! - }) - - provide(VueDevToolsStateSymbol, { - appRecords, - activeAppRecordId, - }) - - return { - appRecords, - activeAppRecordId, - } -} - -export function useDevToolsState() { - return inject(VueDevToolsStateSymbol, { - appRecords: ref([]), - activeAppRecordId: ref(''), - }) -} diff --git a/packages/applet/src/composables/virtual-router.ts b/packages/applet/src/composables/virtual-router.ts index a82c398a..6103fc69 100644 --- a/packages/applet/src/composables/virtual-router.ts +++ b/packages/applet/src/composables/virtual-router.ts @@ -1,19 +1,23 @@ -import type { Component, InjectionKey, Ref } from 'vue' -import { computed, defineComponent, h, inject, provide, ref } from 'vue' +import type { Component, ComputedRef, InjectionKey, Ref } from 'vue' +import { computed, defineComponent, h, inject, provide, ref, toValue } from 'vue' +import type { MaybeRef } from '@vueuse/core' +export interface VirtualRoute { path: string, component: Component, icon?: string, name?: string } const VirtualRouteKey: InjectionKey> = Symbol('VirtualRouteKey') -const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string, name?: string }[]> = Symbol('VirtualRoutesKey') +const VirtualRoutesKey: InjectionKey> = Symbol('VirtualRoutesKey') -export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string, name?: string }[]) { +export function registerVirtualRouter(routes: MaybeRef) { const route = ref<{ path: string, icon?: string }>({ path: '/', }) + + const _routes = computed(() => toValue(routes)) const routePath = computed(() => route.value.path) const VirtualRouterView = defineComponent({ setup() { return () => { - const route = routes.find(route => route.path === routePath.value) + const route = _routes.value.find(route => route.path === routePath.value) if (route) return h(route.component) @@ -22,9 +26,13 @@ export function registerVirtualRouter(routes: { path: string, component: Compone }, }) + function restoreRouter() { + route.value.path = '/' + } + provide(VirtualRouteKey, route) - provide(VirtualRoutesKey, routes) - return { VirtualRouterView } + provide(VirtualRoutesKey, _routes) + return { VirtualRouterView, restoreRouter } } export function useVirtualRouter() { diff --git a/packages/applet/src/index.ts b/packages/applet/src/index.ts index fc7ccdfc..61cb2755 100644 --- a/packages/applet/src/index.ts +++ b/packages/applet/src/index.ts @@ -6,6 +6,5 @@ import 'floating-vue/dist/style.css' export * from './modules/pinia' export * from './modules/components' export * from './modules/router' -export * from './modules/vue-query' -export * from './modules/vuex' -export * from './modules/vee-validate' +export * from './modules/custom-inspector' +export * from './composables/custom-inspector' diff --git a/packages/applet/src/modules/components/index.vue b/packages/applet/src/modules/components/index.vue index cf5a1e25..0fe0cd31 100644 --- a/packages/applet/src/modules/components/index.vue +++ b/packages/applet/src/modules/components/index.vue @@ -1,16 +1,10 @@