-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathRootStateViewer.vue
More file actions
64 lines (59 loc) · 1.7 KB
/
RootStateViewer.vue
File metadata and controls
64 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script setup lang="ts">
import type { CustomInspectorState } from '@vue/devtools-kit'
import { watchEffect } from 'vue'
import ToggleExpanded from '~/components/basic/ToggleExpanded.vue'
import { createStateEditorContext } from '~/composables/state-editor'
import { useToggleExpanded } from '~/composables/toggle-expanded'
import ChildStateViewer from './ChildStateViewer.vue'
const props = withDefaults(defineProps<{
data: Record<string, CustomInspectorState[]>
nodeId: string
inspectorId: string
disableEdit?: boolean
expandedStateId?: string
}>(), {
disableEdit: false,
expandedStateId: '',
})
function initEditorContext() {
return {
nodeId: props.nodeId,
inspectorId: props.inspectorId,
disableEdit: props.disableEdit,
}
}
const { context } = createStateEditorContext(initEditorContext())
watchEffect(() => {
context.value = initEditorContext()
})
const { expanded, toggleExpanded } = useToggleExpanded(props.expandedStateId)
</script>
<template>
<div>
<div
v-for="(item, key, index) in data"
:key="index"
>
<div
class="flex items-center"
:class="[item?.length && 'cursor-pointer hover:(bg-active)']"
@click="toggleExpanded(`${index}`)"
>
<ToggleExpanded
v-if="item?.length"
:value="expanded.includes(`${index}`)"
/>
<!-- placeholder -->
<span v-else pl5 />
<span text-3.5 text-hex-a3a3a3 font-state-field>
{{ key }}
</span>
</div>
<div
v-if="item?.length && expanded.includes(`${index}`)"
>
<ChildStateViewer :data="item" :index="`${index}`" :expanded-state-id="expandedStateId" />
</div>
</div>
</div>
</template>