@@ -5,6 +5,7 @@ import { UICompCategory, UICompManifest, uiCompCategoryNames, uiCompRegistry } f
5
5
import { MenuProps } from "antd/es/menu" ;
6
6
import React from "react" ;
7
7
import { EditorState } from "@lowcoder-ee/comps/editorState" ;
8
+ import { getAllCompItems } from "comps/comps/containerBase/utils" ;
8
9
9
10
export function runScript ( code : string , inHost ?: boolean ) {
10
11
if ( inHost ) {
@@ -60,6 +61,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
60
61
simpleContainer : any ;
61
62
componentType ?: string | null ;
62
63
items : any ;
64
+ allAppComponents : any [ ] ;
63
65
} | null {
64
66
try {
65
67
// Get the UI component container
@@ -83,7 +85,9 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
83
85
84
86
// Get current layout and items
85
87
const currentLayout = simpleContainer . children . layout . getView ( ) ;
88
+
86
89
const items = getCombinedItems ( uiCompTree ) ;
90
+ const allAppComponents = getAllLayoutComponentsFromTree ( uiCompTree ) ;
87
91
88
92
// If no componentName is provided, return all items
89
93
if ( ! componentName ) {
@@ -92,6 +96,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
92
96
currentLayout,
93
97
simpleContainer,
94
98
items,
99
+ allAppComponents,
95
100
} ;
96
101
}
97
102
@@ -113,38 +118,35 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
113
118
simpleContainer,
114
119
componentType,
115
120
items,
121
+ allAppComponents,
116
122
} ;
117
123
} catch ( error ) {
118
124
console . error ( 'Error getting editor component key:' , error ) ;
119
125
return null ;
120
126
}
121
127
}
122
128
123
- interface Container {
124
- items ?: Record < string , any > ;
125
- }
126
-
127
- function getCombinedItems ( uiCompTree : any ) {
129
+ function getCombinedItems ( uiCompTree : any , parentPath : string [ ] = [ ] ) : Record < string , any > {
128
130
const combined : Record < string , any > = { } ;
129
131
130
- if ( uiCompTree . items ) {
131
- Object . entries ( uiCompTree . items ) . forEach ( ( [ itemKey , itemValue ] ) => {
132
- combined [ itemKey ] = itemValue ;
133
- } ) ;
134
- }
132
+ function processContainer ( container : any , currentPath : string [ ] ) {
133
+ if ( container . items ) {
134
+ Object . entries ( container . items ) . forEach ( ( [ itemKey , itemValue ] ) => {
135
+ ( itemValue as any ) . parentPath = [ ...currentPath ] ;
136
+ combined [ itemKey ] = itemValue ;
137
+ } ) ;
138
+ }
135
139
136
- if ( uiCompTree . children ) {
137
- Object . entries ( uiCompTree . children ) . forEach ( ( [ parentKey , container ] ) => {
138
- const typedContainer = container as Container ;
139
- if ( typedContainer . items ) {
140
- Object . entries ( typedContainer . items ) . forEach ( ( [ itemKey , itemValue ] ) => {
141
- itemValue . parentContainer = parentKey ;
142
- combined [ itemKey ] = itemValue ;
143
- } ) ;
144
- }
145
- } ) ;
140
+ if ( container . children ) {
141
+ Object . entries ( container . children ) . forEach ( ( [ childKey , childContainer ] ) => {
142
+ const newPath = [ ...currentPath , childKey ] ;
143
+ processContainer ( childContainer , newPath ) ;
144
+ } ) ;
145
+ }
146
146
}
147
147
148
+ processContainer ( uiCompTree , parentPath ) ;
149
+
148
150
return combined ;
149
151
}
150
152
@@ -156,3 +158,78 @@ export function getLayoutItemsOrder(layoutItems: any[]){
156
158
value : index . toString ( )
157
159
} ) ) ;
158
160
}
161
+
162
+ function getAllLayoutComponentsFromTree ( compTree : any ) : any [ ] {
163
+ try {
164
+ const allCompItems = getAllCompItems ( compTree ) ;
165
+
166
+ return Object . entries ( allCompItems ) . map ( ( [ itemKey , item ] ) => {
167
+ const compItem = item as any ;
168
+ if ( compItem && compItem . children ) {
169
+ return {
170
+ id : itemKey ,
171
+ compType : compItem . children . compType ?. getView ( ) ,
172
+ name : compItem . children . name ?. getView ( ) ,
173
+ key : itemKey ,
174
+ comp : compItem . children . comp ,
175
+ autoHeight : compItem . autoHeight ?.( ) ,
176
+ hidden : compItem . children . comp ?. children ?. hidden ?. getView ( ) ,
177
+ parentPath : compItem . parentPath || [ ]
178
+ } ;
179
+ }
180
+ } ) ;
181
+ } catch ( error ) {
182
+ console . error ( 'Error getting all app components from tree:' , error ) ;
183
+ return [ ] ;
184
+ }
185
+ }
186
+
187
+ export function getAllContainers ( editorState : any ) {
188
+ const containers : Array < { container : any , path : string [ ] } > = [ ] ;
189
+
190
+ function findContainers ( comp : any , path : string [ ] = [ ] ) {
191
+ if ( ! comp ) return ;
192
+
193
+ if ( comp . realSimpleContainer && typeof comp . realSimpleContainer === 'function' ) {
194
+ const simpleContainer = comp . realSimpleContainer ( ) ;
195
+ if ( simpleContainer ) {
196
+ containers . push ( { container : simpleContainer , path } ) ;
197
+ }
198
+ }
199
+
200
+ if ( comp . children ) {
201
+ Object . entries ( comp . children ) . forEach ( ( [ key , child ] ) => {
202
+ findContainers ( child , [ ...path , key ] ) ;
203
+ } ) ;
204
+ }
205
+ }
206
+
207
+ const uiComp = editorState . getUIComp ( ) ;
208
+ const container = uiComp . getComp ( ) ;
209
+ if ( container ) {
210
+ findContainers ( container ) ;
211
+ }
212
+
213
+ return containers ;
214
+ }
215
+
216
+ export function findTargetComponent ( editorState : any , selectedEditorComponent : string ) {
217
+ const allContainers = getAllContainers ( editorState ) ;
218
+
219
+ for ( const containerInfo of allContainers ) {
220
+ const containerLayout = containerInfo . container . children . layout . getView ( ) ;
221
+ const containerItems = containerInfo . container . children . items . children ;
222
+
223
+ for ( const [ key , item ] of Object . entries ( containerItems ) ) {
224
+ if ( ( item as any ) . children . name . getView ( ) === selectedEditorComponent ) {
225
+ return {
226
+ container : containerInfo . container ,
227
+ layout : containerLayout ,
228
+ componentKey : key
229
+ } ;
230
+ }
231
+ }
232
+ }
233
+
234
+ return null ;
235
+ }
0 commit comments