@elementor/editor-elements 3.33.0-278 → 3.33.0-279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ export type ElementChildren = Record< string, ElementModel[] >;
11
11
 
12
12
  export function useElementChildren< T extends ElementChildren >(
13
13
  elementId: ElementID,
14
- childrenTypes: ( keyof T & string )[]
14
+ childrenTypes: Record< string, string >
15
15
  ): T {
16
16
  return useListenTo(
17
17
  [
@@ -24,19 +24,19 @@ export function useElementChildren< T extends ElementChildren >(
24
24
  () => {
25
25
  const container = getContainer( elementId );
26
26
 
27
- const elementChildren = childrenTypes.reduce( ( acc, type ) => {
28
- acc[ type ] = [];
27
+ const elementChildren = Object.entries( childrenTypes ).reduce( ( acc, [ parentType, childType ] ) => {
28
+ const parent = container?.children?.findRecursive?.(
29
+ ( { model } ) => model.get( 'elType' ) === parentType
30
+ );
29
31
 
30
- return acc;
31
- }, {} as ElementChildren );
32
+ const children = parent?.children ?? [];
32
33
 
33
- container?.children?.forEachRecursive?.( ( { model, id } ) => {
34
- const elType = model.get( 'elType' );
34
+ acc[ childType ] = children
35
+ .filter( ( { model } ) => model.get( 'elType' ) === childType )
36
+ .map( ( { id } ) => ( { id } ) );
35
37
 
36
- if ( elType && elType in elementChildren ) {
37
- elementChildren[ elType ].push( { id } );
38
- }
39
- } );
38
+ return acc;
39
+ }, {} as ElementChildren );
40
40
 
41
41
  return elementChildren;
42
42
  },