Skip to content

Commit 7412679

Browse files
committed
feat(lil-gui): expose standalone components
1 parent 4a051f6 commit 7412679

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

packages/ngx-lil-gui/.release-it.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
}
2929
},
3030
"@release-it/bumper": {
31-
"in": "packages/ngx-lil-gui/package.json",
32-
"out": ["packages/ngx-lil-gui/package.json", "dist/packages/ngx-lil-gui/package.json"]
31+
"in": "packages/ngx-lil-gui/version.json",
32+
"out": ["dist/packages/ngx-lil-gui/package.json"]
3333
}
3434
},
3535
"git": {

packages/ngx-lil-gui/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"license": "MIT",
2222
"description": "Lil-GUI wrapper for Angular",
2323
"peerDependencies": {
24-
"@angular/common": "^13.0.0",
25-
"@angular/core": "^13.0.0"
24+
"@angular/common": "^14.0.0",
25+
"@angular/core": "^14.0.0"
2626
},
2727
"dependencies": {
2828
"tslib": "^2.3.0",
29-
"lil-gui": "~0.16.0"
29+
"lil-gui": "~0.16.0 || ~0.17.0"
3030
}
3131
}

packages/ngx-lil-gui/src/lib/ngx-lil-gui-color.component.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {
22
ChangeDetectionStrategy,
33
Component,
44
EventEmitter,
5+
inject,
6+
InjectFlags,
57
Input,
68
OnDestroy,
79
OnInit,
8-
Optional,
910
Output,
10-
SkipSelf,
1111
} from '@angular/core';
1212
import { ColorController } from 'lil-gui';
1313
import { NgxLilGui } from './ngx-lil-gui.component';
@@ -21,6 +21,7 @@ import type {
2121
selector: 'ngx-lil-gui-color[property]',
2222
template: ``,
2323
changeDetection: ChangeDetectionStrategy.OnPush,
24+
standalone: true,
2425
})
2526
export class NgxLilGuiColor implements OnInit, OnDestroy {
2627
@Input() property!: string;
@@ -37,20 +38,20 @@ export class NgxLilGuiColor implements OnInit, OnDestroy {
3738
return this.#colorController;
3839
}
3940

40-
constructor(@Optional() @SkipSelf() private parentGui: NgxLilGui) {
41-
if (!parentGui) {
41+
#parentGui = inject(NgxLilGui, InjectFlags.Optional | InjectFlags.SkipSelf);
42+
43+
ngOnInit() {
44+
if (!this.#parentGui) {
4245
throw new Error('ngx-lil-gui-color must be used within a ngx-lil-gui');
4346
}
44-
}
4547

46-
ngOnInit() {
4748
this.preAdd.emit();
4849

49-
this.#colorController = this.parentGui.addColor(
50+
this.#colorController = this.#parentGui.addColor(
5051
this.property,
5152
this.colorConfig
5253
);
53-
this.parentGui.run(() => {
54+
this.#parentGui.run(() => {
5455
if (this.colorController) {
5556
this.colorController.updateDisplay();
5657

packages/ngx-lil-gui/src/lib/ngx-lil-gui-controller.component.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {
22
ChangeDetectionStrategy,
33
Component,
44
EventEmitter,
5+
inject,
6+
InjectFlags,
57
Input,
68
OnDestroy,
79
OnInit,
8-
Optional,
910
Output,
10-
SkipSelf,
1111
} from '@angular/core';
1212
import { Controller } from 'lil-gui';
1313
import { NgxLilGui } from './ngx-lil-gui.component';
@@ -21,6 +21,7 @@ import type {
2121
selector: 'ngx-lil-gui-controller[property]',
2222
template: ``,
2323
changeDetection: ChangeDetectionStrategy.OnPush,
24+
standalone: true,
2425
})
2526
export class NgxLilGuiController implements OnInit, OnDestroy {
2627
@Input() property!: string;
@@ -33,22 +34,22 @@ export class NgxLilGuiController implements OnInit, OnDestroy {
3334

3435
#controller?: Controller;
3536

36-
constructor(@Optional() @SkipSelf() private parentGui: NgxLilGui) {
37-
if (!parentGui) {
37+
#parentGui = inject(NgxLilGui, InjectFlags.Optional | InjectFlags.SkipSelf);
38+
39+
ngOnInit() {
40+
if (!this.#parentGui) {
3841
throw new Error(
39-
'ngx-lil-gui-controller must be used within a ngx-lil-gui.'
42+
'ngx-lil-gui-controller must be used within a ngx-lil-gui'
4043
);
4144
}
42-
}
4345

44-
ngOnInit() {
4546
this.preAdd.emit();
4647

47-
this.#controller = this.parentGui.addController(
48+
this.#controller = this.#parentGui.addController(
4849
this.property,
4950
this.controllerConfig
5051
);
51-
this.parentGui.run(() => {
52+
this.#parentGui.run(() => {
5253
if (this.controller) {
5354
this.controller.updateDisplay();
5455

packages/ngx-lil-gui/src/lib/ngx-lil-gui.component.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import {
33
Component,
44
ElementRef,
55
EventEmitter,
6-
Inject,
6+
inject,
7+
InjectFlags,
78
Input,
89
NgZone,
910
OnDestroy,
1011
OnInit,
11-
Optional,
1212
Output,
13-
SkipSelf,
1413
} from '@angular/core';
1514
import GUI, { ColorController, Controller } from 'lil-gui';
1615
import type {
@@ -33,6 +32,7 @@ import type {
3332
`,
3433
template: ` <ng-content></ng-content> `,
3534
changeDetection: ChangeDetectionStrategy.OnPush,
35+
standalone: true,
3636
})
3737
export class NgxLilGui implements OnInit, OnDestroy {
3838
@Input() zoneless = false;
@@ -54,19 +54,20 @@ export class NgxLilGui implements OnInit, OnDestroy {
5454

5555
#gui!: GUI;
5656

57-
constructor(
58-
@SkipSelf() private hostElement: ElementRef<HTMLElement>,
59-
@Optional() @SkipSelf() @Inject(NgxLilGui) private parentGUI: NgxLilGui,
60-
private ngZone: NgZone
61-
) {}
57+
#hostElement = inject(
58+
ElementRef,
59+
InjectFlags.SkipSelf
60+
) as ElementRef<HTMLElement>;
61+
#parentGUI = inject(NgxLilGui, InjectFlags.Optional | InjectFlags.SkipSelf);
62+
#ngZone = inject(NgZone);
6263

6364
ngOnInit() {
65+
this.zoneless = this.#parentGUI?.zoneless ?? this.zoneless;
6466
this.run(() => {
65-
this.zoneless = this.parentGUI?.zoneless ?? this.zoneless;
6667
let container: HTMLElement | undefined =
6768
this.container instanceof HTMLElement
6869
? this.container
69-
: this.hostElement.nativeElement;
70+
: this.#hostElement.nativeElement;
7071

7172
if (typeof this.container === 'boolean') {
7273
container = undefined;
@@ -79,7 +80,7 @@ export class NgxLilGui implements OnInit, OnDestroy {
7980
injectStyles: this.injectStyles,
8081
width: this.width,
8182
title: this.title,
82-
parent: this.self ? undefined : this.parentGUI?.gui || undefined,
83+
parent: this.self ? undefined : this.#parentGUI?.gui || undefined,
8384
});
8485

8586
this.#setupEvents();
@@ -128,7 +129,7 @@ export class NgxLilGui implements OnInit, OnDestroy {
128129

129130
run<TReturn = void>(fn: () => TReturn): TReturn {
130131
if (this.zoneless) {
131-
return this.ngZone.runOutsideAngular(() => {
132+
return this.#ngZone.runOutsideAngular(() => {
132133
return fn();
133134
});
134135
}

packages/ngx-lil-gui/src/lib/ngx-lil-gui.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { NgxLilGuiColor } from './ngx-lil-gui-color.component';
33
import { NgxLilGuiController } from './ngx-lil-gui-controller.component';
44
import { NgxLilGui } from './ngx-lil-gui.component';
55

6+
/**
7+
* @description Using standalone components is recommended
8+
*/
69
@NgModule({
7-
declarations: [NgxLilGui, NgxLilGuiController, NgxLilGuiColor],
10+
imports: [NgxLilGui, NgxLilGuiController, NgxLilGuiColor],
811
exports: [NgxLilGui, NgxLilGuiController, NgxLilGuiColor],
912
})
1013
export class NgxLilGuiModule {}

packages/ngx-lil-gui/version.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2.1.0"
3+
}

0 commit comments

Comments
 (0)