File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
packages/core/src/components Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 GridLayoutsDefinition ,
1212 GridComponentDefinition ,
1313 UpdateGridComponents ,
14+ ElementCreatedEventDetail ,
1415} from "./src" ;
1516
1617/**
@@ -193,6 +194,12 @@ export class Grid<
193194 }
194195 }
195196
197+ private emitElementCreation ( detail : ElementCreatedEventDetail ) {
198+ this . dispatchEvent ( new CustomEvent < ElementCreatedEventDetail > ( "elementcreated" , {
199+ detail
200+ } ) )
201+ }
202+
196203 protected render ( ) {
197204 if ( this . layout ) {
198205 if ( this . layouts [ this . layout ] ) {
@@ -230,6 +237,8 @@ export class Grid<
230237 HTMLElement ,
231238 { }
232239 > ( template , initialState ) ;
240+
241+ this . emitElementCreation ( { name : area , element : component } )
233242
234243 component . setAttribute ( "data-grid-template-id" , templateId ) ;
235244
@@ -246,6 +255,9 @@ export class Grid<
246255 if ( existingComponent ) return existingComponent ;
247256
248257 const component = Component . create ( element ) ;
258+
259+ this . emitElementCreation ( { name : area , element : component } )
260+
249261 component . setAttribute (
250262 "data-grid-template-id" ,
251263 this . getTemplateId ( element ) ,
Original file line number Diff line number Diff line change @@ -57,3 +57,8 @@ export type UpdateGridComponents<T extends GridComponentDefinition> = {
5757 > ,
5858 ) => void ;
5959} ;
60+
61+ export interface ElementCreatedEventDetail < T extends HTMLElement = HTMLElement > {
62+ name : string ;
63+ element : T
64+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { Checkbox } from "./Checkbox";
33import { ColorInput } from "./ColorInput" ;
44import { ContextMenu } from "./ContextMenu" ;
55import { Dropdown } from "./Dropdown" ;
6- import { Grid } from "./Grid" ;
6+ import { ElementCreatedEventDetail , Grid } from "./Grid" ;
77import { Icon } from "./Icon" ;
88import { Input } from "./Input" ;
99import { Label } from "./Label" ;
@@ -77,6 +77,7 @@ declare global {
7777 rowcreated : CustomEvent < RowCreatedEventDetail > ;
7878 rowselected : CustomEvent < RowSelectedEventDetail > ;
7979 rowdeselected : CustomEvent < RowDeselectedEventDetail > ;
80+ elementcreated : CustomEvent < ElementCreatedEventDetail > ;
8081 }
8182}
8283
You can’t perform that action at this time.
0 commit comments