2020 ></div >
2121 <div
2222 v-if =" childNodes.status === 'loaded' && childNodes.data.length > 0"
23- class =" flex flex-col flex-1 truncate"
23+ class =" flex flex-1 flex-col truncate"
2424 :class =" {
2525 'bg-divider': highlightNode,
2626 }"
3030 :key =" `${childNode.id}-${childNode.data.type}`"
3131 :node-item =" childNode"
3232 :adapter =" adapter"
33+ :expand-all =" expandAll"
3334 >
3435 <!-- The child slot is given a dynamic name in order to not break Volar -->
3536 <template
5859
5960 <div
6061 v-if =" childNodes.status === 'loading'"
61- class =" flex flex-col items-center justify-center flex-1 p-4"
62+ class =" flex flex-1 flex- col items-center justify-center p-4"
6263 >
6364 <SmartSpinner class =" my-4" />
6465 <span class =" text-secondaryLight" >{{ t?.("state.loading") }}</span >
6566 </div >
6667 <div
6768 v-if =" childNodes.status === 'loaded' && childNodes.data.length === 0"
68- class =" flex flex-col flex-1 "
69+ class =" flex flex-1 flex-col "
6970 >
7071 <slot name =" emptyNode" :node =" nodeItem" ></slot >
7172 </div >
7273 </div >
7374</template >
7475
7576<script setup lang="ts" generic =" T extends any " >
76- import { computed , inject , ref } from " vue"
77+ import { computed , inject , onMounted , ref } from " vue"
7778import SmartTreeBranch from " ./TreeBranch.vue"
7879import SmartSpinner from " ./Spinner.vue"
7980import { SmartTreeAdapter , TreeNode } from " ~/helpers/treeAdapter"
8081import { HOPP_UI_OPTIONS , HoppUIPluginOptions } from " ./../../plugin"
8182const { t } = inject <HoppUIPluginOptions >(HOPP_UI_OPTIONS ) ?? {}
8283
83- const props = defineProps <{
84- /**
85- * The node item that will be used to render the tree branch
86- * @template T The type of the data passed to the tree branch
87- */
88- adapter: SmartTreeAdapter <T >
89- /**
90- * The node item that will be used to render the tree branch content
91- */
92- nodeItem: TreeNode <T >
93- /**
94- * Total number of rootNode
95- */
96- rootNodesLength? : number
97- }>()
84+ const props = withDefaults (
85+ defineProps <{
86+ /**
87+ * The node item that will be used to render the tree branch
88+ * @template T The type of the data passed to the tree branch
89+ */
90+ adapter: SmartTreeAdapter <T >
91+ /**
92+ * The node item that will be used to render the tree branch content
93+ */
94+ nodeItem: TreeNode <T >
95+ /**
96+ * Total number of rootNode
97+ */
98+ rootNodesLength? : number
99+ /**
100+ * open by default
101+ */
102+ expandAll? : boolean
103+ }>(),
104+ {
105+ rootNodesLength: 0 ,
106+ expandAll: false ,
107+ },
108+ )
98109
99110const CHILD_SLOT_NAME = " default"
100111
@@ -114,15 +125,27 @@ const highlightNode = ref(false)
114125/**
115126 * Fetch the child nodes from the adapter by passing the node id of the current node
116127 */
117- const childNodes = props .adapter .getChildren (props .nodeItem .id , props .nodeItem .data .type )
128+ const childNodes = props .adapter .getChildren (
129+ props .nodeItem .id ,
130+ props .nodeItem .data .type ,
131+ )
118132
119133const toggleNodeChildren = () => {
134+ if (props .expandAll ) return
120135 if (! childrenRendered .value ) childrenRendered .value = true
121136
122137 showChildren .value = ! showChildren .value
123138 isNodeOpen .value = ! isNodeOpen .value
124139}
125140
141+ onMounted (() => {
142+ if (props .expandAll ) {
143+ childrenRendered .value = true
144+ showChildren .value = true
145+ isNodeOpen .value = true
146+ }
147+ })
148+
126149const highlightNodeChildren = (id : string | null ) => {
127150 if (id ) {
128151 highlightNode .value = true
0 commit comments