3535</template >
3636
3737<script lang="ts">
38- import { inject , onMounted , reactive , ref , watchEffect } from ' vue'
38+ import { inject , onMounted , reactive , ref , watch , watchEffect } from ' vue'
3939import { Collapse , CollapseItem , Search } from ' @opentiny/vue'
4040import { SearchEmpty , CanvasDragItem } from ' @opentiny/tiny-engine-common'
4141import i18n from ' @opentiny/tiny-engine-common/js/i18n'
@@ -57,7 +57,6 @@ export default {
5757 const { generateNode, materialState, getComponentsByGroup } = useMaterial ()
5858 const gridTemplateColumns = ref (COMPONENT_PANEL_COLUMNS )
5959 const panelState = inject (' panelState' , {})
60- const { components } = materialState
6160 const { locale } = i18n .global
6261
6362 const fetchComponents = (components , name ) => {
@@ -91,10 +90,10 @@ export default {
9190 const initComponents = () => {
9291 const groupName = panelState .materialGroup
9392 if (groupName ) {
94- return getComponentsByGroup (components , groupName )
93+ return getComponentsByGroup (materialState . components , groupName )
9594 }
9695
97- return components
96+ return materialState . components
9897 }
9998
10099 const state = reactive ({
@@ -104,13 +103,23 @@ export default {
104103 })
105104
106105 watchEffect (() => {
107- state .activeName = [... Array (components .length ).keys ()]
106+ state .activeName = [... Array (materialState . components .length ).keys ()]
108107 })
109108
110109 const change = (value ) => {
111- state .components = fetchComponents (components , value )
110+ state .components = fetchComponents (materialState . components , value )
112111 }
113112
113+ watch (
114+ () => materialState .components ,
115+ (value ) => {
116+ state .components = fetchComponents (value , state .searchValue )
117+ },
118+ {
119+ deep: true
120+ }
121+ )
122+
114123 const componentClick = (data ) => {
115124 const { isShortcutPanel, emitEvent } = panelState
116125 const { addComponent } = useCanvas ().canvasApi .value
0 commit comments