Line data Source code
1 : <template>
2 4 : <div ref="previewPanel">
3 : <div
4 : v-if="filteredSections.length === 0"
5 : class="flex min-h-0 flex-1 items-center justify-center px-6 py-8 text-center text-sm text-muted-foreground"
6 : >
7 : {{
8 : t('sideToolbar.nodeLibraryTab.noMatchingNodes', {
9 : query: searchQuery
10 : })
11 : }}
12 : </div>
13 16 : <div
14 : v-for="section in filteredSections"
15 : :id="`essentials-section-${section.key}`"
16 : :key="section.key"
17 : class="border-b last:border-b-0"
18 : >
19 : <div
20 : class="sticky top-0 z-10 flex h-14 w-full items-center justify-between bg-background px-4 text-sm font-bold tracking-wide text-muted-foreground"
21 : >
22 : <span class="uppercase">{{ $t(`essentials.${section.key}`) }}</span>
23 : </div>
24 : <div
25 : v-if="section.tiles?.length"
26 : class="grid grid-cols-[repeat(auto-fill,minmax(96px,1fr))] gap-2 p-4"
27 : >
28 44 : <EssentialNodeCard
29 : v-for="tile in section.tiles.filter(
30 : (tile) => !tile.media || mediaFilters[tile.media]
31 : )"
32 : :key="tile.nodeName"
33 : :preview-panel
34 : :tile
35 : />
36 : </div>
37 : <div v-else class="flex flex-col gap-10 px-4">
38 60 : <div
39 : v-for="subgroup in section.subgroups?.filter(
40 : (s) => mediaFilters[s.media]
41 : )"
42 : :id="`essentials-subgroup-${subgroup.key}`"
43 : :key="subgroup.key"
44 : class="scroll-mt-30 last:pb-4"
45 : >
46 : <div class="text-sm leading-[15px] font-normal">
47 : {{ $t(`essentials.${subgroup.key}`) }}
48 : </div>
49 : <div
50 : class="mt-4 grid grid-cols-[repeat(auto-fill,minmax(96px,1fr))] gap-2"
51 : >
52 276 : <EssentialNodeCard
53 : v-for="tile in subgroup.tiles"
54 : :key="tile.nodeName"
55 : :preview-panel
56 : :tile
57 : />
58 : </div>
59 : </div>
60 : </div>
61 : </div>
62 : </div>
63 : </template>
64 :
65 : <script setup lang="ts">
66 : import { computed, useTemplateRef } from 'vue'
67 : import { useI18n } from 'vue-i18n'
68 :
69 : import { resolveEssentialTileNodeDef } from '@/composables/useEssentialTileNodeDef'
70 : import type {
71 : EssentialsMediaType,
72 : EssentialSection,
73 : EssentialTile
74 : } from '@/constants/essentialsNodes'
75 : import { ESSENTIAL_SECTIONS } from '@/constants/essentialsNodes'
76 : import { useNodeDefStore } from '@/stores/nodeDefStore'
77 :
78 : import EssentialNodeCard from './EssentialNodeCard.vue'
79 :
80 2 : const { t } = useI18n()
81 : const { searchQuery = '' } = defineProps<{
82 : searchQuery?: string
83 : mediaFilters: Record<EssentialsMediaType, boolean>
84 : }>()
85 2 : const previewPanel = useTemplateRef('previewPanel')
86 2 : const nodeDefStore = useNodeDefStore()
87 :
88 2 : const filteredSections = computed<EssentialSection[]>(() => {
89 2 : const query = searchQuery.trim().toLowerCase()
90 2 : if (!query) return ESSENTIAL_SECTIONS
91 :
92 0 : const matchesQuery = (tile: EssentialTile) => {
93 : const name =
94 : resolveEssentialTileNodeDef(tile, nodeDefStore)?.display_name ??
95 : tile.nodeName
96 0 : return name.toLowerCase().includes(query)
97 : }
98 0 : return ESSENTIAL_SECTIONS.flatMap<EssentialSection>((section) => {
99 0 : if (section.tiles?.length) {
100 0 : const tiles = section.tiles.filter(matchesQuery)
101 0 : return tiles.length ? [{ ...section, tiles }] : []
102 : }
103 :
104 0 : const subgroups = section.subgroups
105 : ?.map((sg) => ({ ...sg, tiles: sg.tiles.filter(matchesQuery) }))
106 : .filter((sg) => sg.tiles.length)
107 0 : return subgroups?.length ? [{ ...section, subgroups }] : []
108 : })
109 : })
110 : </script>
|