From 3feec4653979d15e273432b3011c92b229f0df36 Mon Sep 17 00:00:00 2001 From: Arlo Date: Wed, 5 Jun 2024 23:01:53 +0800 Subject: [PATCH] feat: compatible with v6 plugin API, refactor messaging system (#421) Co-authored-by: Alex Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .vscode/settings.json | 5 +- .../src/components/basic/AppConnecting.vue | 41 ++ .../src/components/basic/DevToolsHeader.vue | 4 +- .../src/components/basic/SelectiveList.vue | 4 +- .../src/components/state/ChildStateViewer.vue | 4 +- .../src/components/state/RootStateViewer.vue | 4 +- .../src/components/state/StateFieldEditor.vue | 14 +- .../src/components/state/StateFieldViewer.vue | 22 +- .../src/components/timeline/EventList.vue | 6 +- .../applet/src/components/timeline/index.vue | 28 +- .../applet/src/composables/connect-state.ts | 47 --- .../src/composables/custom-inspector-state.ts | 28 ++ .../src/composables/custom-inspector.ts | 51 +++ .../applet/src/composables/devtools-state.ts | 44 -- .../applet/src/composables/virtual-router.ts | 22 +- packages/applet/src/index.ts | 5 +- .../applet/src/modules/components/index.vue | 76 ++-- .../components/DevToolsLogo.vue | 5 + .../components/Home.vue | 32 +- .../components/state/Index.vue | 102 +++-- .../components/timeline/Index.vue | 10 + .../src/modules/custom-inspector/index.ts | 5 + .../src/modules/custom-inspector/index.vue | 81 ++++ .../modules/pinia/components/store/Index.vue | 62 ++- packages/applet/src/modules/pinia/index.vue | 3 - .../router/components/routes/Index.vue | 69 ++-- .../router/components/timeline/Index.vue | 5 +- packages/applet/src/modules/router/index.vue | 42 +- .../vee-validate/components/DevToolsLogo.vue | 8 - .../modules/vee-validate/components/Home.vue | 52 --- .../vee-validate/components/state/Index.vue | 154 ------- .../components/timeline/Index.vue | 9 - .../applet/src/modules/vee-validate/index.ts | 5 - .../applet/src/modules/vee-validate/index.vue | 35 -- .../vue-query/components/DevToolsLogo.vue | 8 - .../vue-query/components/timeline/Index.vue | 9 - .../applet/src/modules/vue-query/index.ts | 5 - .../applet/src/modules/vue-query/index.vue | 36 -- .../modules/vuex/components/DevToolsLogo.vue | 6 - .../src/modules/vuex/components/Home.vue | 52 --- .../modules/vuex/components/store/Index.vue | 104 ----- .../vuex/components/timeline/Index.vue | 9 - packages/applet/src/modules/vuex/index.ts | 5 - packages/applet/src/modules/vuex/index.vue | 36 -- packages/browser-extension/manifest.json | 4 +- packages/browser-extension/package.json | 1 + packages/browser-extension/src/background.ts | 24 +- packages/browser-extension/src/detector.ts | 18 +- .../src/devtools-background.ts | 43 +- .../browser-extension/src/devtools-overlay.ts | 137 +++---- .../browser-extension/src/devtools-panel.ts | 241 ++++++----- packages/browser-extension/src/proxy.ts | 52 +-- packages/browser-extension/src/user-app.ts | 57 +-- packages/client/src/App.vue | 107 ++--- .../client/src/components/AppConnecting.vue | 2 +- .../src/components/CustomTabComponent.vue | 2 +- .../src/components/assets/AssetDetails.vue | 20 +- .../src/components/common/DockingPanel.vue | 26 +- .../inspector/InspectorDataField/Actions.vue | 163 -------- .../InspectorDataField/EditInput.vue | 90 ----- .../components/inspector/InspectorNodeTag.vue | 24 -- .../components/inspector/InspectorState.vue | 35 -- .../inspector/InspectorStateField.vue | 267 ------------- .../inspector/InspectorStateType.vue | 20 - .../components/inspector/InspectorTree.vue | 39 -- packages/client/src/composables/app.ts | 4 +- packages/client/src/composables/client.ts | 32 -- .../src/composables/custom-inspector-tabs.ts | 24 ++ packages/client/src/composables/host.ts | 18 + .../client/src/composables/open-in-editor.ts | 4 +- .../client/src/composables/state-commands.ts | 10 +- packages/client/src/composables/state-tab.ts | 25 +- packages/client/src/composables/view-mode.ts | 40 +- packages/client/src/constants/tab.ts | 70 +--- packages/client/src/index.ts | 19 +- packages/client/src/main.ts | 156 +++----- packages/client/src/pages/assets.vue | 20 +- packages/client/src/pages/components.vue | 7 +- .../src/pages/custom-inspector-tab-view.vue | 31 ++ packages/client/src/pages/custom-tab-view.vue | 6 +- packages/client/src/pages/graph.vue | 24 +- packages/client/src/pages/i18n.vue | 97 ----- packages/client/src/pages/overview.vue | 110 ++--- packages/client/src/pages/pages.vue | 22 +- packages/client/src/pages/router.vue | 10 +- packages/client/src/pages/settings.vue | 12 +- packages/client/src/pages/vee-validate.vue | 8 - packages/client/src/pages/vue-query.vue | 8 - packages/client/src/pages/vuex.vue | 8 - .../src/bridge-events/devtools-actions.ts | 128 ------ .../src/bridge-events/devtools-listeners.ts | 89 ----- packages/core/src/bridge-events/index.ts | 11 - packages/core/src/bridge/api.ts | 57 --- packages/core/src/bridge/app.ts | 29 -- packages/core/src/bridge/core.ts | 66 --- packages/core/src/bridge/devtools.ts | 7 - packages/core/src/bridge/index.ts | 4 - packages/core/src/bridge/shared.ts | 30 -- packages/core/src/handshake.ts | 58 --- packages/core/src/index.ts | 10 +- packages/core/src/injection.ts | 17 - packages/core/src/rpc/global.ts | 245 ++++++++++++ packages/core/src/rpc/index.ts | 3 + .../module-types.ts => rpc/types.ts} | 0 packages/core/src/rpc/vite.ts | 79 ++++ packages/core/src/separate-window/index.ts | 91 ----- packages/core/src/vite-bridge/client.ts | 55 --- packages/core/src/vite-bridge/server.ts | 26 -- packages/core/src/vite-bridge/shared.ts | 22 - packages/core/src/vue-plugin.ts | 120 ------ .../core/src/vue-plugin/devtools-state.ts | 118 ++++++ .../devtools-kit/__tests__/api/api.test.ts | 154 ------- .../devtools-kit/__tests__/api/plugin.test.ts | 46 --- packages/devtools-kit/__tests__/hook.test.ts | 40 -- packages/devtools-kit/__tests__/state.test.ts | 27 -- packages/devtools-kit/global.d.ts | 9 +- packages/devtools-kit/package.json | 4 +- packages/devtools-kit/src/api/api.ts | 278 ------------- packages/devtools-kit/src/api/hook.ts | 78 ---- packages/devtools-kit/src/api/index.ts | 6 +- packages/devtools-kit/src/api/off.ts | 5 - packages/devtools-kit/src/api/on.ts | 60 --- packages/devtools-kit/src/api/plugin.ts | 78 ---- packages/devtools-kit/src/api/v6/index.ts | 142 +++++++ packages/devtools-kit/src/api/v7/index.ts | 6 + .../src/core/{app-record => app}/index.ts | 38 +- .../src/core/component-highlighter/index.ts | 8 +- .../src/core/component/state/editor.ts | 8 +- .../src/core/component/state/index.ts | 4 +- .../src/core/component/state/process.ts | 4 +- .../src/core/component/state/reviver.ts | 4 +- .../src/core/component/tree/index.ts | 4 +- .../src/core/component/tree/walker.ts | 22 +- .../src/core/component/types/tree.ts | 23 +- .../src/core/component/utils/index.ts | 10 +- .../devtools-kit/src/core/custom-tab/index.ts | 11 - .../src/core/high-perf-mode/index.ts | 2 +- packages/devtools-kit/src/core/index.ts | 111 +++--- .../devtools-kit/src/core/inspector/index.ts | 48 --- .../src/core/open-in-editor/index.ts | 2 +- .../plugin/components.ts} | 79 ++-- .../devtools-kit/src/core/plugin/index.ts | 39 ++ .../devtools-kit/src/core/router/index.ts | 14 +- .../devtools-kit/src/core/timeline/index.ts | 27 -- packages/devtools-kit/src/ctx/api.ts | 105 +++++ .../devtools-kit/src/{state => ctx}/env.ts | 3 +- packages/devtools-kit/src/ctx/hook.ts | 376 ++++++++++++++++++ packages/devtools-kit/src/ctx/index.ts | 43 ++ packages/devtools-kit/src/ctx/inspector.ts | 91 +++++ packages/devtools-kit/src/ctx/plugin.ts | 14 + .../devtools-kit/src/{state => ctx}/router.ts | 14 +- packages/devtools-kit/src/ctx/state.ts | 199 +++++++++ packages/devtools-kit/src/ctx/timeline.ts | 24 ++ packages/devtools-kit/src/index.ts | 43 +- packages/devtools-kit/src/messaging/index.ts | 163 ++++++++ .../presets/broadcast-channel/context.ts | 1 + .../presets/broadcast-channel/index.ts | 26 ++ .../src/messaging/presets/electron/client.ts | 17 + .../src/messaging/presets/electron/context.ts | 51 +++ .../src/messaging/presets/electron/index.ts | 4 + .../src/messaging/presets/electron/proxy.ts | 21 + .../src/messaging/presets/electron/server.ts | 17 + .../src/messaging/presets/extension/client.ts | 54 +++ .../messaging/presets/extension/context.ts | 52 +++ .../src/messaging/presets/extension/index.ts | 4 + .../src/messaging/presets/extension/proxy.ts | 48 +++ .../src/messaging/presets/extension/server.ts | 25 ++ .../src/messaging/presets/iframe/client.ts | 31 ++ .../src/messaging/presets/iframe/context.ts | 12 + .../src/messaging/presets/iframe}/index.ts | 2 +- .../src/messaging/presets/iframe/server.ts | 60 +++ .../src/messaging/presets/index.ts | 6 + .../src/messaging/presets/vite/client.ts | 17 + .../src/messaging/presets/vite/context.ts | 33 ++ .../src/messaging/presets/vite/index.ts | 3 + .../src/messaging/presets/vite/server.ts | 16 + .../src/messaging/presets/ws/client.ts | 25 ++ .../src/messaging/presets/ws/context.ts | 28 ++ .../src/messaging/presets/ws/index.ts | 3 + .../src/messaging/presets/ws/server.ts | 14 + .../src/messaging/types/channel.ts | 0 .../devtools-kit/src/messaging/types/index.ts | 7 + packages/devtools-kit/src/plugins/index.ts | 1 - packages/devtools-kit/src/state/app-record.ts | 58 --- packages/devtools-kit/src/state/context.ts | 40 -- packages/devtools-kit/src/state/index.ts | 5 - packages/devtools-kit/src/state/state.ts | 83 ---- packages/devtools-kit/src/types/app.ts | 57 +-- .../index.ts => types/command.ts} | 17 - packages/devtools-kit/src/types/component.ts | 91 +++++ packages/devtools-kit/src/types/context.ts | 17 - packages/devtools-kit/src/types/env.ts | 3 - packages/devtools-kit/src/types/hook.ts | 5 +- packages/devtools-kit/src/types/index.ts | 9 +- packages/devtools-kit/src/types/inspector.ts | 50 +++ packages/devtools-kit/src/types/plugin.ts | 46 +++ packages/devtools-kit/src/types/state.ts | 17 - .../custom-tab/types.ts => types/tab.ts} | 0 packages/devtools-kit/src/types/timeline.ts | 41 ++ packages/devtools-kit/tsup.config.ts | 2 +- packages/electron/package.json | 1 + packages/electron/src/cli.ts | 2 +- packages/electron/src/devtools.ts | 30 +- packages/electron/src/server.ts | 10 +- packages/electron/src/user-app.core.ts | 30 +- packages/overlay/src/App.vue | 40 +- packages/overlay/src/components/FrameBox.vue | 22 +- packages/overlay/src/composables/bridge.ts | 21 - packages/overlay/src/composables/index.ts | 1 - packages/playground/applet/src/App.vue | 32 +- packages/playground/basic/src/main.ts | 41 +- packages/playground/basic/vite.config.ts | 2 +- packages/shared/src/env.ts | 1 + packages/vite/src/modules/get-config.ts | 8 - packages/vite/src/modules/graph.ts | 26 -- packages/vite/src/modules/index.ts | 3 - packages/vite/src/overlay.js | 12 +- packages/vite/src/{modules => rpc}/assets.ts | 82 ++-- packages/vite/src/rpc/get-config.ts | 9 + packages/vite/src/rpc/graph.ts | 24 ++ packages/vite/src/rpc/index.ts | 15 + packages/vite/src/rpc/types.ts | 8 + packages/vite/src/vite.ts | 18 +- pnpm-lock.yaml | 39 ++ scripts/extension-zip.ts | 5 +- 225 files changed, 4129 insertions(+), 4694 deletions(-) create mode 100644 packages/applet/src/components/basic/AppConnecting.vue delete mode 100644 packages/applet/src/composables/connect-state.ts create mode 100644 packages/applet/src/composables/custom-inspector-state.ts create mode 100644 packages/applet/src/composables/custom-inspector.ts delete mode 100644 packages/applet/src/composables/devtools-state.ts create mode 100644 packages/applet/src/modules/custom-inspector/components/DevToolsLogo.vue rename packages/applet/src/modules/{vue-query => custom-inspector}/components/Home.vue (50%) rename packages/applet/src/modules/{vue-query => custom-inspector}/components/state/Index.vue (52%) create mode 100644 packages/applet/src/modules/custom-inspector/components/timeline/Index.vue create mode 100644 packages/applet/src/modules/custom-inspector/index.ts create mode 100644 packages/applet/src/modules/custom-inspector/index.vue delete mode 100644 packages/applet/src/modules/vee-validate/components/DevToolsLogo.vue delete mode 100644 packages/applet/src/modules/vee-validate/components/Home.vue delete mode 100644 packages/applet/src/modules/vee-validate/components/state/Index.vue delete mode 100644 packages/applet/src/modules/vee-validate/components/timeline/Index.vue delete mode 100644 packages/applet/src/modules/vee-validate/index.ts delete mode 100644 packages/applet/src/modules/vee-validate/index.vue delete mode 100644 packages/applet/src/modules/vue-query/components/DevToolsLogo.vue delete mode 100644 packages/applet/src/modules/vue-query/components/timeline/Index.vue delete mode 100644 packages/applet/src/modules/vue-query/index.ts delete mode 100644 packages/applet/src/modules/vue-query/index.vue delete mode 100644 packages/applet/src/modules/vuex/components/DevToolsLogo.vue delete mode 100644 packages/applet/src/modules/vuex/components/Home.vue delete mode 100644 packages/applet/src/modules/vuex/components/store/Index.vue delete mode 100644 packages/applet/src/modules/vuex/components/timeline/Index.vue delete mode 100644 packages/applet/src/modules/vuex/index.ts delete mode 100644 packages/applet/src/modules/vuex/index.vue delete mode 100644 packages/client/src/components/inspector/InspectorDataField/Actions.vue delete mode 100644 packages/client/src/components/inspector/InspectorDataField/EditInput.vue delete mode 100644 packages/client/src/components/inspector/InspectorNodeTag.vue delete mode 100644 packages/client/src/components/inspector/InspectorState.vue delete mode 100644 packages/client/src/components/inspector/InspectorStateField.vue delete mode 100644 packages/client/src/components/inspector/InspectorStateType.vue delete mode 100644 packages/client/src/components/inspector/InspectorTree.vue delete mode 100644 packages/client/src/composables/client.ts create mode 100644 packages/client/src/composables/custom-inspector-tabs.ts create mode 100644 packages/client/src/composables/host.ts create mode 100644 packages/client/src/pages/custom-inspector-tab-view.vue delete mode 100644 packages/client/src/pages/i18n.vue delete mode 100644 packages/client/src/pages/vee-validate.vue delete mode 100644 packages/client/src/pages/vue-query.vue delete mode 100644 packages/client/src/pages/vuex.vue delete mode 100644 packages/core/src/bridge-events/devtools-actions.ts delete mode 100644 packages/core/src/bridge-events/devtools-listeners.ts delete mode 100644 packages/core/src/bridge-events/index.ts delete mode 100644 packages/core/src/bridge/api.ts delete mode 100644 packages/core/src/bridge/app.ts delete mode 100644 packages/core/src/bridge/core.ts delete mode 100644 packages/core/src/bridge/devtools.ts delete mode 100644 packages/core/src/bridge/index.ts delete mode 100644 packages/core/src/bridge/shared.ts delete mode 100644 packages/core/src/handshake.ts delete mode 100644 packages/core/src/injection.ts create mode 100644 packages/core/src/rpc/global.ts create mode 100644 packages/core/src/rpc/index.ts rename packages/core/src/{vite-bridge/module-types.ts => rpc/types.ts} (100%) create mode 100644 packages/core/src/rpc/vite.ts delete mode 100644 packages/core/src/separate-window/index.ts delete mode 100644 packages/core/src/vite-bridge/client.ts delete mode 100644 packages/core/src/vite-bridge/server.ts delete mode 100644 packages/core/src/vite-bridge/shared.ts delete mode 100644 packages/core/src/vue-plugin.ts create mode 100644 packages/core/src/vue-plugin/devtools-state.ts delete mode 100644 packages/devtools-kit/__tests__/api/api.test.ts delete mode 100644 packages/devtools-kit/__tests__/api/plugin.test.ts delete mode 100644 packages/devtools-kit/__tests__/hook.test.ts delete mode 100644 packages/devtools-kit/__tests__/state.test.ts delete mode 100644 packages/devtools-kit/src/api/api.ts delete mode 100644 packages/devtools-kit/src/api/hook.ts delete mode 100644 packages/devtools-kit/src/api/off.ts delete mode 100644 packages/devtools-kit/src/api/on.ts delete mode 100644 packages/devtools-kit/src/api/plugin.ts create mode 100644 packages/devtools-kit/src/api/v6/index.ts create mode 100644 packages/devtools-kit/src/api/v7/index.ts rename packages/devtools-kit/src/core/{app-record => app}/index.ts (61%) delete mode 100644 packages/devtools-kit/src/core/custom-tab/index.ts delete mode 100644 packages/devtools-kit/src/core/inspector/index.ts rename packages/devtools-kit/src/{plugins/component.ts => core/plugin/components.ts} (66%) create mode 100644 packages/devtools-kit/src/core/plugin/index.ts delete mode 100644 packages/devtools-kit/src/core/timeline/index.ts create mode 100644 packages/devtools-kit/src/ctx/api.ts rename packages/devtools-kit/src/{state => ctx}/env.ts (73%) create mode 100644 packages/devtools-kit/src/ctx/hook.ts create mode 100644 packages/devtools-kit/src/ctx/index.ts create mode 100644 packages/devtools-kit/src/ctx/inspector.ts create mode 100644 packages/devtools-kit/src/ctx/plugin.ts rename packages/devtools-kit/src/{state => ctx}/router.ts (51%) create mode 100644 packages/devtools-kit/src/ctx/state.ts create mode 100644 packages/devtools-kit/src/ctx/timeline.ts create mode 100644 packages/devtools-kit/src/messaging/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/broadcast-channel/context.ts create mode 100644 packages/devtools-kit/src/messaging/presets/broadcast-channel/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/electron/client.ts create mode 100644 packages/devtools-kit/src/messaging/presets/electron/context.ts create mode 100644 packages/devtools-kit/src/messaging/presets/electron/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/electron/proxy.ts create mode 100644 packages/devtools-kit/src/messaging/presets/electron/server.ts create mode 100644 packages/devtools-kit/src/messaging/presets/extension/client.ts create mode 100644 packages/devtools-kit/src/messaging/presets/extension/context.ts create mode 100644 packages/devtools-kit/src/messaging/presets/extension/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/extension/proxy.ts create mode 100644 packages/devtools-kit/src/messaging/presets/extension/server.ts create mode 100644 packages/devtools-kit/src/messaging/presets/iframe/client.ts create mode 100644 packages/devtools-kit/src/messaging/presets/iframe/context.ts rename packages/{core/src/vite-bridge => devtools-kit/src/messaging/presets/iframe}/index.ts (61%) create mode 100644 packages/devtools-kit/src/messaging/presets/iframe/server.ts create mode 100644 packages/devtools-kit/src/messaging/presets/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/vite/client.ts create mode 100644 packages/devtools-kit/src/messaging/presets/vite/context.ts create mode 100644 packages/devtools-kit/src/messaging/presets/vite/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/vite/server.ts create mode 100644 packages/devtools-kit/src/messaging/presets/ws/client.ts create mode 100644 packages/devtools-kit/src/messaging/presets/ws/context.ts create mode 100644 packages/devtools-kit/src/messaging/presets/ws/index.ts create mode 100644 packages/devtools-kit/src/messaging/presets/ws/server.ts create mode 100644 packages/devtools-kit/src/messaging/types/channel.ts create mode 100644 packages/devtools-kit/src/messaging/types/index.ts delete mode 100644 packages/devtools-kit/src/plugins/index.ts delete mode 100644 packages/devtools-kit/src/state/app-record.ts delete mode 100644 packages/devtools-kit/src/state/context.ts delete mode 100644 packages/devtools-kit/src/state/index.ts delete mode 100644 packages/devtools-kit/src/state/state.ts rename packages/devtools-kit/src/{core/custom-command/index.ts => types/command.ts} (64%) create mode 100644 packages/devtools-kit/src/types/component.ts delete mode 100644 packages/devtools-kit/src/types/context.ts delete mode 100644 packages/devtools-kit/src/types/env.ts create mode 100644 packages/devtools-kit/src/types/inspector.ts create mode 100644 packages/devtools-kit/src/types/plugin.ts delete mode 100644 packages/devtools-kit/src/types/state.ts rename packages/devtools-kit/src/{core/custom-tab/types.ts => types/tab.ts} (100%) create mode 100644 packages/devtools-kit/src/types/timeline.ts delete mode 100644 packages/overlay/src/composables/bridge.ts delete mode 100644 packages/vite/src/modules/get-config.ts delete mode 100644 packages/vite/src/modules/graph.ts delete mode 100644 packages/vite/src/modules/index.ts rename packages/vite/src/{modules => rpc}/assets.ts (68%) create mode 100644 packages/vite/src/rpc/get-config.ts create mode 100644 packages/vite/src/rpc/graph.ts create mode 100644 packages/vite/src/rpc/index.ts create mode 100644 packages/vite/src/rpc/types.ts 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 @@