Skip to content

Commit 8cffded

Browse files
committed
feat(soba): apply objectEvents as host directive to RoundedBox
This allows `ngts-rounded-box` consumer to listen to events using () output syntax
1 parent b11efc0 commit 8cffded

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: libs/soba/abstractions/src/lib/rounded-box.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import {
55
CUSTOM_ELEMENTS_SCHEMA,
66
effect,
77
ElementRef,
8+
inject,
89
input,
910
untracked,
1011
viewChild,
1112
} from '@angular/core';
12-
import { extend, NgtArgs, NgtMesh, omit, pick } from 'angular-three';
13+
import { extend, NgtArgs, NgtMesh, NgtObjectEvents, NgtObjectEventsOutputs, omit, pick } from 'angular-three';
1314
import { mergeInputs } from 'ngxtension/inject-inputs';
1415
import { ExtrudeGeometry, Mesh, Shape } from 'three';
1516
import { toCreasedNormals } from 'three-stdlib';
@@ -60,6 +61,7 @@ const defaultOptions: NgtsRoundedBoxOptions = {
6061
schemas: [CUSTOM_ELEMENTS_SCHEMA],
6162
changeDetection: ChangeDetectionStrategy.OnPush,
6263
imports: [NgtArgs],
64+
hostDirectives: [{ directive: NgtObjectEvents, outputs: NgtObjectEventsOutputs }],
6365
})
6466
export class NgtsRoundedBox {
6567
options = input(defaultOptions, { transform: mergeInputs(defaultOptions) });
@@ -113,6 +115,16 @@ export class NgtsRoundedBox {
113115
constructor() {
114116
extend({ ExtrudeGeometry, Mesh });
115117

118+
const objectEvents = inject(NgtObjectEvents, { host: true });
119+
120+
effect(
121+
() => {
122+
const mesh = this.meshRef().nativeElement;
123+
objectEvents.ngtObjectEvents.set(mesh);
124+
},
125+
{ allowSignalWrites: true },
126+
);
127+
116128
effect(() => {
117129
const geometry = this.geometryRef()?.nativeElement;
118130
if (!geometry) return;

0 commit comments

Comments
 (0)