Browse Source

Merge pull request #24766 from abpframework/issue-24673

feat(angular): Migrate to output functions
pull/24854/head
Fahri Gedik 6 months ago
committed by GitHub
parent
commit
94f7c3e080
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      npm/ng-packs/packages/components/chart.js/src/chart.component.ts
  2. 10
      npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts
  3. 12
      npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts
  4. 4
      npm/ng-packs/packages/core/src/lib/directives/caps-lock.directive.ts
  5. 4
      npm/ng-packs/packages/core/src/lib/directives/debounce.directive.ts
  6. 19
      npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts
  7. 4
      npm/ng-packs/packages/core/src/lib/directives/init.directive.ts
  8. 4
      npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts
  9. 8
      npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts
  10. 4
      npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts
  11. 4
      npm/ng-packs/packages/feature-management/src/lib/models/feature-management.ts
  12. 6
      npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts
  13. 4
      npm/ng-packs/packages/permission-management/src/lib/models/permission-management.ts
  14. 21
      npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts
  15. 10
      npm/ng-packs/packages/theme-shared/src/lib/components/checkbox/checkbox.component.ts
  16. 10
      npm/ng-packs/packages/theme-shared/src/lib/components/form-input/form-input.component.ts
  17. 4
      npm/ng-packs/packages/theme-shared/src/lib/components/toast/toast.component.ts

10
npm/ng-packs/packages/components/chart.js/src/chart.component.ts

@ -4,14 +4,13 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
ElementRef, ElementRef,
EventEmitter,
Input, Input,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
Output,
SimpleChanges, SimpleChanges,
ViewChild, ViewChild,
inject inject,
output,
} from '@angular/core'; } from '@angular/core';
let Chart: any; let Chart: any;
@ -53,9 +52,8 @@ export class ChartComponent implements AfterViewInit, OnDestroy, OnChanges {
@Input() responsive = true; @Input() responsive = true;
@Output() dataSelect = new EventEmitter(); readonly dataSelect = output<any>();
readonly initialized = output<boolean>();
@Output() initialized = new EventEmitter<boolean>();
@ViewChild('canvas') canvas!: ElementRef<HTMLCanvasElement>; @ViewChild('canvas') canvas!: ElementRef<HTMLCanvasElement>;

10
npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts

@ -11,12 +11,12 @@ import {
LOCALE_ID, LOCALE_ID,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
Output,
PLATFORM_ID, PLATFORM_ID,
signal, signal,
SimpleChanges, SimpleChanges,
TemplateRef, TemplateRef,
TrackByFunction, TrackByFunction,
output,
contentChild, contentChild,
viewChild viewChild
} from '@angular/core'; } from '@angular/core';
@ -118,7 +118,7 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn
@Input() actionsTemplate?: TemplateRef<any>; @Input() actionsTemplate?: TemplateRef<any>;
@Output() tableActivate = new EventEmitter(); readonly tableActivate = output();
@Input() selectable = false; @Input() selectable = false;
@ -128,18 +128,18 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn
_selectionType: SelectionType = SelectionType.multiClick; _selectionType: SelectionType = SelectionType.multiClick;
@Input() selected: any[] = []; @Input() selected: any[] = [];
@Output() selectionChange = new EventEmitter<any[]>(); readonly selectionChange = output<any[]>();
// Infinite scroll configuration // Infinite scroll configuration
@Input() infiniteScroll = false; @Input() infiniteScroll = false;
@Input() isLoading = false; @Input() isLoading = false;
@Input() scrollThreshold = 10; @Input() scrollThreshold = 10;
@Output() loadMore = new EventEmitter<void>(); readonly loadMore = output<void>();
@Input() tableHeight: number; @Input() tableHeight: number;
@Input() rowDetailTemplate?: TemplateRef<RowDetailContext<R>>; @Input() rowDetailTemplate?: TemplateRef<RowDetailContext<R>>;
@Input() rowDetailHeight: string | number = '100%'; @Input() rowDetailHeight: string | number = '100%';
@Output() rowDetailToggle = new EventEmitter<R>(); readonly rowDetailToggle = output<R>();
readonly rowDetailComponent = contentChild(ExtensibleTableRowDetailComponent); readonly rowDetailComponent = contentChild(ExtensibleTableRowDetailComponent);

12
npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts

@ -7,7 +7,7 @@ import {
inject, inject,
Input, Input,
OnInit, OnInit,
Output, output,
TemplateRef, TemplateRef,
ViewEncapsulation, ViewEncapsulation,
} from '@angular/core'; } from '@angular/core';
@ -63,11 +63,11 @@ export class TreeComponent implements OnInit {
readonly menu = contentChild<TemplateRef<any>>('menu'); readonly menu = contentChild<TemplateRef<any>>('menu');
readonly customNodeTemplate = contentChild(TreeNodeTemplateDirective); readonly customNodeTemplate = contentChild(TreeNodeTemplateDirective);
readonly expandedIconTemplate = contentChild(ExpandedIconTemplateDirective); readonly expandedIconTemplate = contentChild(ExpandedIconTemplateDirective);
@Output() readonly checkedKeysChange = new EventEmitter(); readonly checkedKeysChange = output<any>();
@Output() readonly expandedKeysChange = new EventEmitter<string[]>(); readonly expandedKeysChange = output<string[]>();
@Output() readonly selectedNodeChange = new EventEmitter(); readonly selectedNodeChange = output<any>();
@Output() readonly dropOver = new EventEmitter<DropEvent>(); readonly dropOver = output<DropEvent>();
@Output() readonly nzExpandChange = new EventEmitter<NzFormatEmitEvent>(); readonly nzExpandChange = output<NzFormatEmitEvent>();
@Input() noAnimation = true; @Input() noAnimation = true;
@Input() draggable: boolean; @Input() draggable: boolean;
@Input() checkable: boolean; @Input() checkable: boolean;

4
npm/ng-packs/packages/core/src/lib/directives/caps-lock.directive.ts

@ -1,10 +1,10 @@
import { Directive, EventEmitter, HostListener, Output } from '@angular/core'; import { Directive, HostListener, output } from '@angular/core';
@Directive({ @Directive({
selector: '[abpCapsLock]', selector: '[abpCapsLock]',
}) })
export class TrackCapsLockDirective { export class TrackCapsLockDirective {
@Output('abpCapsLock') capsLock = new EventEmitter<boolean>(); readonly capsLock = output<boolean>({ alias: 'abpCapsLock' });
@HostListener('window:keydown', ['$event']) @HostListener('window:keydown', ['$event'])
onKeyDown(event: KeyboardEvent): void { onKeyDown(event: KeyboardEvent): void {

4
npm/ng-packs/packages/core/src/lib/directives/debounce.directive.ts

@ -1,4 +1,4 @@
import { Directive, ElementRef, EventEmitter, Input, OnInit, Output, inject } from '@angular/core'; import { Directive, ElementRef, Input, OnInit, inject, output } from '@angular/core';
import { fromEvent } from 'rxjs'; import { fromEvent } from 'rxjs';
import { debounceTime } from 'rxjs/operators'; import { debounceTime } from 'rxjs/operators';
import { SubscriptionService } from '../services/subscription.service'; import { SubscriptionService } from '../services/subscription.service';
@ -13,7 +13,7 @@ export class InputEventDebounceDirective implements OnInit {
@Input() debounce = 300; @Input() debounce = 300;
@Output('input.debounce') readonly debounceEvent = new EventEmitter<Event>(); readonly debounceEvent = output<Event>({ alias: 'input.debounce' });
ngOnInit(): void { ngOnInit(): void {
const input$ = fromEvent<InputEvent>(this.el.nativeElement, 'input').pipe( const input$ = fromEvent<InputEvent>(this.el.nativeElement, 'input').pipe(

19
npm/ng-packs/packages/core/src/lib/directives/form-submit.directive.ts

@ -1,12 +1,11 @@
import { import {
ChangeDetectorRef, ChangeDetectorRef,
Directive, Directive,
ElementRef, ElementRef,
EventEmitter, Input,
Input, OnInit,
OnInit, inject,
Output, output
inject
} from '@angular/core'; } from '@angular/core';
import { FormGroupDirective, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { FormGroupDirective, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { fromEvent } from 'rxjs'; import { fromEvent } from 'rxjs';
@ -37,7 +36,7 @@ export class FormSubmitDirective implements OnInit {
@Input() @Input()
markAsDirtyWhenSubmit = true; markAsDirtyWhenSubmit = true;
@Output() readonly ngSubmit = new EventEmitter(); readonly ngSubmit = output();
executedNgSubmit = false; executedNgSubmit = false;

4
npm/ng-packs/packages/core/src/lib/directives/init.directive.ts

@ -1,4 +1,4 @@
import { Directive, Output, EventEmitter, ElementRef, AfterViewInit, inject } from '@angular/core'; import { Directive, ElementRef, AfterViewInit, inject, output } from '@angular/core';
@Directive({ @Directive({
selector: '[abpInit]', selector: '[abpInit]',
@ -6,7 +6,7 @@ import { Directive, Output, EventEmitter, ElementRef, AfterViewInit, inject } fr
export class InitDirective implements AfterViewInit { export class InitDirective implements AfterViewInit {
private elRef = inject(ElementRef); private elRef = inject(ElementRef);
@Output('abpInit') readonly init = new EventEmitter<ElementRef<any>>(); readonly init = output<ElementRef<any>>({ alias: 'abpInit' });
ngAfterViewInit() { ngAfterViewInit() {
this.init.emit(this.elRef); this.init.emit(this.elRef);

4
npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts

@ -1,4 +1,4 @@
import { Directive, ElementRef, EventEmitter, OnInit, Output, inject } from '@angular/core'; import { Directive, ElementRef, OnInit, inject, output } from '@angular/core';
import { fromEvent } from 'rxjs'; import { fromEvent } from 'rxjs';
import { SubscriptionService } from '../services/subscription.service'; import { SubscriptionService } from '../services/subscription.service';
@ -10,7 +10,7 @@ export class StopPropagationDirective implements OnInit {
private el = inject(ElementRef); private el = inject(ElementRef);
private subscription = inject(SubscriptionService); private subscription = inject(SubscriptionService);
@Output('click.stop') readonly stopPropEvent = new EventEmitter<MouseEvent>(); readonly stopPropEvent = output<MouseEvent>({ alias: 'click.stop' });
ngOnInit(): void { ngOnInit(): void {
this.subscription.addOne(fromEvent<MouseEvent>(this.el.nativeElement, 'click'), event => { this.subscription.addOne(fromEvent<MouseEvent>(this.el.nativeElement, 'click'), event => {

8
npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output, inject } from '@angular/core'; import { Component, Input, inject, output } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
@ -18,11 +18,9 @@ class DefaultComponent {
@Input() @Input()
twoWay: boolean; twoWay: boolean;
@Output() readonly twoWayChange = output<boolean>();
readonly twoWayChange = new EventEmitter<boolean>();
@Output() readonly someOutput = output<string>();
readonly someOutput = new EventEmitter<string>();
setTwoWay(value) { setTwoWay(value) {
this.twoWay = value; this.twoWay = value;

4
npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output, inject, DOCUMENT } from '@angular/core'; import { Component, Input, inject, DOCUMENT, output } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common'; import { NgTemplateOutlet } from '@angular/common';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { ConfigStateService, LocalizationPipe, TrackByService } from '@abp/ng.core'; import { ConfigStateService, LocalizationPipe, TrackByService } from '@abp/ng.core';
@ -103,7 +103,7 @@ export class FeatureManagementComponent
} }
} }
@Output() readonly visibleChange = new EventEmitter<boolean>(); readonly visibleChange = output<boolean>();
modalBusy = false; modalBusy = false;

4
npm/ng-packs/packages/feature-management/src/lib/models/feature-management.ts

@ -1,4 +1,4 @@
import { EventEmitter } from '@angular/core'; import { EventEmitter, OutputEmitterRef } from '@angular/core';
export namespace FeatureManagement { export namespace FeatureManagement {
export interface FeatureManagementComponentInputs { export interface FeatureManagementComponentInputs {
@ -8,6 +8,6 @@ export namespace FeatureManagement {
} }
export interface FeatureManagementComponentOutputs { export interface FeatureManagementComponentOutputs {
readonly visibleChange: EventEmitter<boolean>; readonly visibleChange: EventEmitter<boolean> | OutputEmitterRef<boolean>;
} }
} }

6
npm/ng-packs/packages/permission-management/src/lib/components/permission-management.component.ts

@ -20,13 +20,13 @@ import {
computed, computed,
DOCUMENT, DOCUMENT,
ElementRef, ElementRef,
EventEmitter,
inject, inject,
Injector, Injector,
Input, Input,
Output, QueryList,
signal, signal,
TrackByFunction, TrackByFunction,
output,
viewChildren viewChildren
} from '@angular/core'; } from '@angular/core';
import { of } from 'rxjs'; import { of } from 'rxjs';
@ -160,7 +160,7 @@ export class PermissionManagementComponent
} }
} }
@Output() readonly visibleChange = new EventEmitter<boolean>(); readonly visibleChange = output<boolean>();
selectAllInThisTabsRef = viewChildren<ElementRef<HTMLInputElement>>('selectAllInThisTabsRef'); selectAllInThisTabsRef = viewChildren<ElementRef<HTMLInputElement>>('selectAllInThisTabsRef');
selectAllInAllTabsRef = viewChildren<ElementRef<HTMLInputElement>>('selectAllInAllTabsRef'); selectAllInAllTabsRef = viewChildren<ElementRef<HTMLInputElement>>('selectAllInAllTabsRef');

4
npm/ng-packs/packages/permission-management/src/lib/models/permission-management.ts

@ -1,5 +1,5 @@
import { GetPermissionListResultDto } from '@abp/ng.permission-management/proxy'; import { GetPermissionListResultDto } from '@abp/ng.permission-management/proxy';
import { EventEmitter } from '@angular/core'; import { EventEmitter, OutputEmitterRef } from '@angular/core';
export namespace PermissionManagement { export namespace PermissionManagement {
export interface State { export interface State {
@ -14,6 +14,6 @@ export namespace PermissionManagement {
} }
export interface PermissionManagementComponentOutputs { export interface PermissionManagementComponentOutputs {
readonly visibleChange: EventEmitter<boolean>; readonly visibleChange: EventEmitter<boolean> | OutputEmitterRef<boolean>;
} }
} }

21
npm/ng-packs/packages/theme-shared/src/lib/components/button/button.component.ts

@ -2,12 +2,11 @@
import { import {
Component, Component,
ElementRef, ElementRef,
EventEmitter,
Input, Input,
OnInit, OnInit,
Output,
Renderer2, Renderer2,
inject, inject,
output,
viewChild viewChild
} from '@angular/core'; } from '@angular/core';
import { ABP, StopPropagationDirective } from '@abp/ng.core'; import { ABP, StopPropagationDirective } from '@abp/ng.core';
@ -22,9 +21,9 @@ import { ABP, StopPropagationDirective } from '@abp/ng.core';
[attr.form]="formName" [attr.form]="formName"
[class]="buttonClass" [class]="buttonClass"
[disabled]="loading || disabled" [disabled]="loading || disabled"
(click.stop)="click.next($event); abpClick.next($event)" (click.stop)="click.emit($event); abpClick.emit($event)"
(focus)="focus.next($event); abpFocus.next($event)" (focus)="focus.emit($event); abpFocus.emit($event)"
(blur)="blur.next($event); abpBlur.next($event)" (blur)="blur.emit($event); abpBlur.emit($event)"
> >
<i [class]="icon" class="me-1" aria-hidden="true"></i><ng-content></ng-content> <i [class]="icon" class="me-1" aria-hidden="true"></i><ng-content></ng-content>
</button> </button>
@ -58,17 +57,17 @@ export class ButtonComponent implements OnInit {
@Input() @Input()
attributes?: ABP.Dictionary<string>; attributes?: ABP.Dictionary<string>;
@Output() readonly click = new EventEmitter<MouseEvent>(); readonly click = output<MouseEvent>();
@Output() readonly focus = new EventEmitter<FocusEvent>(); readonly focus = output<FocusEvent>();
@Output() readonly blur = new EventEmitter<FocusEvent>(); readonly blur = output<FocusEvent>();
@Output() readonly abpClick = new EventEmitter<MouseEvent>(); readonly abpClick = output<MouseEvent>();
@Output() readonly abpFocus = new EventEmitter<FocusEvent>(); readonly abpFocus = output<FocusEvent>();
@Output() readonly abpBlur = new EventEmitter<FocusEvent>(); readonly abpBlur = output<FocusEvent>();
readonly buttonRef = viewChild.required<ElementRef<HTMLButtonElement>>('button'); readonly buttonRef = viewChild.required<ElementRef<HTMLButtonElement>>('button');

10
npm/ng-packs/packages/theme-shared/src/lib/components/checkbox/checkbox.component.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, forwardRef, Input, Output } from '@angular/core'; import { Component, forwardRef, Input, output } from '@angular/core';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core'; import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core';
@ -13,8 +13,8 @@ import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core';
[readonly]="checkboxReadonly" [readonly]="checkboxReadonly"
[class]="checkboxClass" [class]="checkboxClass"
[style]="checkboxStyle" [style]="checkboxStyle"
(blur)="checkboxBlur.next()" (blur)="checkboxBlur.emit()"
(focus)="checkboxFocus.next()" (focus)="checkboxFocus.emit()"
/> />
@if (label) { @if (label) {
<label [class]="labelClass" [for]="checkboxId"> <label [class]="labelClass" [for]="checkboxId">
@ -44,6 +44,6 @@ export class FormCheckboxComponent extends AbstractNgModelComponent {
| undefined; | undefined;
@Input() checkboxClass = 'form-check-input'; @Input() checkboxClass = 'form-check-input';
@Input() checkboxReadonly = false; @Input() checkboxReadonly = false;
@Output() checkboxBlur = new EventEmitter<void>(); readonly checkboxBlur = output<void>();
@Output() checkboxFocus = new EventEmitter<void>(); readonly checkboxFocus = output<void>();
} }

10
npm/ng-packs/packages/theme-shared/src/lib/components/form-input/form-input.component.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, forwardRef, Input, Output } from '@angular/core'; import { Component, forwardRef, Input, output } from '@angular/core';
import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'; import { FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core'; import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core';
@ -18,8 +18,8 @@ import { AbstractNgModelComponent, LocalizationPipe } from '@abp/ng.core';
[readonly]="inputReadonly" [readonly]="inputReadonly"
[class]="inputClass" [class]="inputClass"
[style]="inputStyle" [style]="inputStyle"
(blur)="formBlur.next()" (blur)="formBlur.emit()"
(focus)="formFocus.next()" (focus)="formFocus.emit()"
[(ngModel)]="value" [(ngModel)]="value"
/> />
</div> </div>
@ -46,6 +46,6 @@ export class FormInputComponent extends AbstractNgModelComponent {
| null | null
| undefined; | undefined;
@Input() inputClass = 'form-control'; @Input() inputClass = 'form-control';
@Output() formBlur = new EventEmitter<void>(); readonly formBlur = output<void>();
@Output() formFocus = new EventEmitter<void>(); readonly formFocus = output<void>();
} }

4
npm/ng-packs/packages/theme-shared/src/lib/components/toast/toast.component.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Component, Input, OnInit, output } from '@angular/core';
import { Toaster } from '../../models/toaster'; import { Toaster } from '../../models/toaster';
import { LocalizationPipe } from '@abp/ng.core'; import { LocalizationPipe } from '@abp/ng.core';
@ -12,7 +12,7 @@ export class ToastComponent implements OnInit {
@Input() @Input()
toast!: Toaster.Toast; toast!: Toaster.Toast;
@Output() remove = new EventEmitter<number>(); readonly remove = output<number>();
get severityClass(): string { get severityClass(): string {
if (!this.toast || !this.toast.severity) return ''; if (!this.toast || !this.toast.severity) return '';

Loading…
Cancel
Save