Skip to content

Commit 29f8029

Browse files
committed
feat: emit event on bim-grid when elements are created based on templates
1 parent 97e1fcb commit 29f8029

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/core/src/components/Grid/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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),

packages/core/src/components/Grid/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

packages/core/src/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Checkbox } from "./Checkbox";
33
import { ColorInput } from "./ColorInput";
44
import { ContextMenu } from "./ContextMenu";
55
import { Dropdown } from "./Dropdown";
6-
import { Grid } from "./Grid";
6+
import { ElementCreatedEventDetail, Grid } from "./Grid";
77
import { Icon } from "./Icon";
88
import { Input } from "./Input";
99
import { 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

0 commit comments

Comments
 (0)