Skip to content

Commit f0e071c

Browse files
authored
feat(applet): add actions for pinia inspector (#488)
1 parent 37f2de6 commit f0e071c

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

packages/applet/src/modules/pinia/components/store/Index.vue

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { computed, onUnmounted, ref, watch } from 'vue'
33
import { Pane, Splitpanes } from 'splitpanes'
44
import { DevToolsMessagingEvents, rpc } from '@vue/devtools-core'
55
import { parse } from '@vue/devtools-kit'
6-
import type { CustomInspectorNode, CustomInspectorState } from '@vue/devtools-kit'
6+
import type { CustomInspectorNode, CustomInspectorOptions, CustomInspectorState } from '@vue/devtools-kit'
7+
import { vTooltip } from '@vue/devtools-ui'
78
import Navbar from '~/components/basic/Navbar.vue'
89
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
910
import Empty from '~/components/basic/Empty.vue'
@@ -16,6 +17,8 @@ const { expanded: expandedTreeNodes } = createExpandedContext()
1617
const { expanded: expandedStateNodes } = createExpandedContext('pinia-store-state')
1718
1819
const inspectorId = 'pinia'
20+
const nodeActions = ref<CustomInspectorOptions['nodeActions']>([])
21+
const actions = ref<CustomInspectorOptions['nodeActions']>([])
1922
2023
const selected = ref('')
2124
const tree = ref<CustomInspectorNode[]>([])
@@ -63,6 +66,30 @@ function flattenTreeNodes(tree: CustomInspectorNode[]) {
6366
return res
6467
}
6568
69+
function getNodeActions() {
70+
rpc.value.getInspectorNodeActions(inspectorId).then((actions) => {
71+
nodeActions.value = actions
72+
})
73+
}
74+
75+
function getActions() {
76+
rpc.value.getInspectorActions(inspectorId).then((_actions) => {
77+
actions.value = _actions
78+
})
79+
}
80+
81+
getNodeActions()
82+
83+
getActions()
84+
85+
function callNodeAction(index: number) {
86+
rpc.value.callInspectorNodeAction(inspectorId, index, selected.value)
87+
}
88+
89+
function callAction(index: number) {
90+
rpc.value.callInspectorAction(inspectorId, index)
91+
}
92+
6693
function filterEmptyState(data: Record<string, unknown[] | undefined>) {
6794
for (const key in data) {
6895
if (!data[key]?.length)
@@ -156,12 +183,28 @@ onUnmounted(() => {
156183
</DevToolsHeader>
157184
<Splitpanes class="flex-1 overflow-auto">
158185
<Pane border="r base" size="40" h-full>
159-
<div h-full select-none overflow-scroll p2 class="no-scrollbar">
160-
<ComponentTree v-model="selected" :data="tree" />
186+
<div class="h-full flex flex-col p2">
187+
<div v-if="actions?.length" class="mb-1 flex justify-end pb-1" border="b dashed base">
188+
<div class="flex items-center gap-2 px-1">
189+
<div v-for="(action, index) in actions" :key="index" v-tooltip.bottom-end="{ content: action.tooltip }" class="flex items-center gap1" @click="callAction(index)">
190+
<i :class="`i-ic-baseline-${action.icon.replace(/\_/g, '-')}`" cursor-pointer op70 text-base hover:op100 />
191+
</div>
192+
</div>
193+
</div>
194+
<div class="no-scrollbar flex-1 select-none overflow-scroll">
195+
<ComponentTree v-model="selected" :data="tree" />
196+
</div>
161197
</div>
162198
</Pane>
163199
<Pane size="60">
164-
<div h-full select-none overflow-scroll class="no-scrollbar">
200+
<div class="h-full flex flex-col p2">
201+
<div v-if="nodeActions?.length" class="mb-1 flex justify-end pb-1" border="b dashed base">
202+
<div class="flex items-center gap-2 px-1">
203+
<div v-for="(action, index) in nodeActions" :key="index" v-tooltip.bottom-end="{ content: action.tooltip }" class="flex items-center gap1" @click="callNodeAction(index)">
204+
<i :class="`i-ic-baseline-${action.icon.replace(/\_/g, '-')}`" cursor-pointer op70 text-base hover:op100 />
205+
</div>
206+
</div>
207+
</div>
165208
<RootStateViewer v-if="selected && !emptyState" class="p3" :data="state" :node-id="selected" :inspector-id="inspectorId" expanded-state-id="pinia-store-state" />
166209
<Empty v-else>
167210
No Data

packages/applet/uno.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ export default defineConfig(mergeConfigs([unoConfig, {
6868
'i-ic-baseline-error-outline',
6969
'i-ic-baseline-done-outline',
7070
'i-ic-baseline-delete-sweep',
71+
'i-ic-baseline-restore',
72+
'i-ic-baseline-content-copy',
73+
'i-ic-baseline-content-paste',
74+
'i-ic-baseline-save',
75+
'i-ic-baseline-folder-open',
7176
],
7277
}])) as any

0 commit comments

Comments
 (0)