|
| 1 | +<script setup lang="ts"> |
| 2 | +import { useDevToolsBridgeRpc } from '@vue/devtools-core' |
| 3 | +
|
| 4 | +// eslint-disable-next-line ts/no-import-type-side-effects |
| 5 | +import { type InspectorNodeTag, type InspectorState } from '@vue/devtools-kit' |
| 6 | +import { Pane, Splitpanes } from 'splitpanes' |
| 7 | +
|
| 8 | +const bridgeRpc = useDevToolsBridgeRpc() |
| 9 | +const INSPECTOR_ID = 'vue-i18n-resource-inspector' |
| 10 | +
|
| 11 | +const selected = ref('') |
| 12 | +const tree = ref<{ id: string, label: string, tags: InspectorNodeTag[] }[]>([]) |
| 13 | +const state = ref<{ |
| 14 | + inspectorId?: string |
| 15 | + state?: InspectorState[] |
| 16 | + getters?: InspectorState[] |
| 17 | +}>({}) |
| 18 | +
|
| 19 | +function getI18nState(nodeId: string) { |
| 20 | + bridgeRpc.getInspectorState({ inspectorId: INSPECTOR_ID, nodeId }).then(({ data }) => { |
| 21 | + state.value = data |
| 22 | + }) |
| 23 | +} |
| 24 | +
|
| 25 | +function clearI18nState() { |
| 26 | + state.value = {} |
| 27 | +} |
| 28 | +
|
| 29 | +watch(selected, () => { |
| 30 | + clearI18nState() |
| 31 | + getI18nState(selected.value) |
| 32 | +}) |
| 33 | +
|
| 34 | +createCollapseContext('inspector-state') |
| 35 | +
|
| 36 | +onDevToolsClientConnected(() => { |
| 37 | + bridgeRpc.getInspectorTree({ inspectorId: INSPECTOR_ID, filter: '' }).then(({ data }) => { |
| 38 | + tree.value = data |
| 39 | + if (!selected.value && data.length) { |
| 40 | + selected.value = data[0].id |
| 41 | + getI18nState(data[0].id) |
| 42 | + } |
| 43 | + }) |
| 44 | +
|
| 45 | + bridgeRpc.on.inspectorTreeUpdated((data) => { |
| 46 | + if (!data?.data.length) |
| 47 | + return |
| 48 | + tree.value = data.data |
| 49 | + if (!selected.value && data.data.length) { |
| 50 | + selected.value = data.data[0].id |
| 51 | + getI18nState(data.data[0].id) |
| 52 | + } |
| 53 | + }, { |
| 54 | + inspectorId: INSPECTOR_ID, |
| 55 | + }) |
| 56 | +
|
| 57 | + bridgeRpc.on.inspectorStateUpdated((data) => { |
| 58 | + if (!data || !data.state.length) |
| 59 | + return |
| 60 | +
|
| 61 | + state.value = data |
| 62 | + }, { |
| 63 | + inspectorId: INSPECTOR_ID, |
| 64 | + }) |
| 65 | +}) |
| 66 | +
|
| 67 | +onUnmounted(() => { |
| 68 | + bridgeRpc.unhighlightElement() |
| 69 | +}) |
| 70 | +</script> |
| 71 | + |
| 72 | +<template> |
| 73 | + <PanelGrids h-screen> |
| 74 | + <Splitpanes> |
| 75 | + <Pane flex flex-col border="r base"> |
| 76 | + <div h-screen select-none overflow-scroll p-2 class="no-scrollbar"> |
| 77 | + <InspectorTree v-model="selected" :data="tree" /> |
| 78 | + </div> |
| 79 | + </Pane> |
| 80 | + <Pane flex flex-col> |
| 81 | + <div :key="selected" h-0 grow overflow-auto p-2 class="no-scrollbar"> |
| 82 | + <InspectorState |
| 83 | + v-for="(item, key) in state" :id="key" |
| 84 | + :key="key" |
| 85 | + :inspector-id="INSPECTOR_ID" |
| 86 | + :node-id="selected" :data="item" :name="`${key}`" |
| 87 | + /> |
| 88 | + </div> |
| 89 | + </Pane> |
| 90 | + </Splitpanes> |
| 91 | + </PanelGrids> |
| 92 | +</template> |
0 commit comments