Skip to content

Commit

Permalink
feat(cdk): tuiNativeElement add util (#7393)
Browse files Browse the repository at this point in the history
Signed-off-by: waterplea <[email protected]>
  • Loading branch information
waterplea authored May 9, 2024
1 parent 4635ba9 commit 68d4514
Show file tree
Hide file tree
Showing 116 changed files with 359 additions and 439 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Directive, ElementRef, inject, Input, NgZone} from '@angular/core';
import {Directive, inject, Input, NgZone} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {ANIMATION_FRAME, PERFORMANCE} from '@ng-web-apis/common';
import {tuiDescribeSector} from '@taiga-ui/addon-charts/utils';
import {tuiClamp, tuiEaseInOutQuad, tuiZonefree} from '@taiga-ui/cdk';
import {tuiClamp, tuiEaseInOutQuad, tuiInjectElement, tuiZonefree} from '@taiga-ui/cdk';
import {TUI_ANIMATIONS_SPEED, tuiGetDuration} from '@taiga-ui/core';
import {BehaviorSubject, map, pairwise, switchMap, takeWhile} from 'rxjs';

Expand All @@ -13,7 +13,7 @@ export class TuiPieChartDirective {
private readonly sector$ = new BehaviorSubject<readonly [number, number]>([0, 0]);

constructor() {
const el: SVGPathElement = inject(ElementRef).nativeElement;
const el = tuiInjectElement<SVGPathElement>();
const performance = inject(PERFORMANCE);
const animationFrame$ = inject(ANIMATION_FRAME);
const speed = inject(TUI_ANIMATIONS_SPEED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {ElementRef} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
ContentChild,
ElementRef,
EventEmitter,
HostListener,
inject,
Expand All @@ -22,6 +22,7 @@ import {
tuiAsControl,
tuiAsFocusableItemAccessor,
TuiAutoFocusDirective,
tuiInjectElement,
tuiIsElement,
tuiIsInput,
tuiIsNativeFocused,
Expand Down Expand Up @@ -85,7 +86,7 @@ export class TuiInputCardGroupedComponent
@ViewChild('inputCVC', {read: TuiAutoFocusDirective})
private readonly cvcCardAutofocusRef?: TuiAutoFocusDirective;

private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private expireInert = false;

@Input()
Expand Down
6 changes: 3 additions & 3 deletions projects/addon-doc/components/demo/demo.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {Location} from '@angular/common';
import type {OnInit} from '@angular/core';
import type {ElementRef, OnInit} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
ContentChild,
ElementRef,
HostBinding,
HostListener,
inject,
Expand All @@ -23,6 +22,7 @@ import {tuiCoerceValueIsTrue} from '@taiga-ui/addon-doc/utils';
import {
tuiClamp,
tuiCleanObject,
tuiInjectElement,
tuiPure,
tuiPx,
TuiResizeableDirective,
Expand All @@ -47,7 +47,7 @@ export class TuiDocDemoComponent implements OnInit {
@ViewChild('resizer', {static: true})
private readonly resizer?: ElementRef<HTMLElement>;

private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly locationRef = inject(Location);
private readonly urlSerializer = inject(UrlSerializer);
private readonly urlStateHandler = inject(TUI_DOC_URL_STATE_HANDLER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Directive, ElementRef, inject, Input} from '@angular/core';
import {Directive, inject, Input} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {TUI_DOC_PAGE_LOADED} from '@taiga-ui/addon-doc/tokens';
import {tuiGetElementObscures} from '@taiga-ui/cdk';
import {tuiGetElementObscures, tuiInjectElement} from '@taiga-ui/cdk';
import {debounceTime, filter, ReplaySubject, switchMap} from 'rxjs';

@Directive({
Expand All @@ -11,7 +11,7 @@ export class TuiScrollIntoViewLinkDirective {
private readonly scroll$ = new ReplaySubject<boolean>(1);

constructor() {
const el: HTMLElement = inject(ElementRef).nativeElement;
const el = tuiInjectElement();

inject(TUI_DOC_PAGE_LOADED)
.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ElementRef, inject, Injectable} from '@angular/core';
import {tuiScrollFrom, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {inject, Injectable} from '@angular/core';
import {tuiInjectElement, tuiScrollFrom, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {
distinctUntilChanged,
Expand Down Expand Up @@ -27,7 +27,7 @@ export const MICRO_OFFSET = 10 ** -6;

@Injectable()
export class TuiPullToRefreshService extends Observable<number> {
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly scrollRef: HTMLElement = inject(TUI_SCROLL_REF).nativeElement;
private readonly loaded$ = inject(TUI_PULL_TO_REFRESH_LOADED);
private readonly threshold = inject(TUI_PULL_TO_REFRESH_THRESHOLD);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type {AfterViewInit, QueryList} from '@angular/core';
import type {AfterViewInit, ElementRef, QueryList} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
HostBinding,
HostListener,
inject,
ViewChild,
ViewChildren,
} from '@angular/core';
import type {TuiPopover} from '@taiga-ui/cdk';
import {EMPTY_QUERY, tuiPure} from '@taiga-ui/cdk';
import {EMPTY_QUERY, tuiInjectElement, tuiPure} from '@taiga-ui/cdk';
import {
TUI_ANIMATIONS_SPEED,
TUI_CLOSE_WORD,
Expand Down Expand Up @@ -47,7 +46,7 @@ export class TuiSheetDialogComponent<I> implements AfterViewInit {
@ViewChildren('stops')
private readonly stopsRefs: QueryList<ElementRef<HTMLElement>> = EMPTY_QUERY;

private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly speed = inject(TUI_ANIMATIONS_SPEED);

private pointers = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {AfterViewInit} from '@angular/core';
import {ChangeDetectionStrategy, Component, ElementRef, inject} from '@angular/core';
import {TuiIdService} from '@taiga-ui/cdk';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {TuiIdService, tuiInjectElement} from '@taiga-ui/cdk';
import {TUI_CLOSE_WORD, TUI_COMMON_ICONS} from '@taiga-ui/core';

export const TUI_SHEET_CLOSE = 'tui-sheet-close';
Expand All @@ -13,7 +13,7 @@ export const TUI_SHEET_ID = 'tui-sheet-id';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiSheetHeadingComponent implements AfterViewInit {
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
protected readonly closeWord$ = inject(TUI_CLOSE_WORD);
protected readonly icons = inject(TUI_COMMON_ICONS);
protected readonly id = inject(TuiIdService).generate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type {AfterViewInit, QueryList} from '@angular/core';
import type {AfterViewInit, ElementRef, QueryList} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
ElementRef,
HostListener,
inject,
Input,
Expand All @@ -12,7 +11,13 @@ import {
ViewChildren,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {EMPTY_QUERY, TUI_IS_IOS, tuiPure, tuiZonefull} from '@taiga-ui/cdk';
import {
EMPTY_QUERY,
TUI_IS_IOS,
tuiInjectElement,
tuiPure,
tuiZonefull,
} from '@taiga-ui/cdk';
import {tuiSlideInTop} from '@taiga-ui/core';
import {TUI_MORE_WORD} from '@taiga-ui/kit';
import {map, timer} from 'rxjs';
Expand Down Expand Up @@ -50,7 +55,7 @@ export class TuiSheetComponent<T> implements TuiSheetRequiredProps<T>, AfterView

private readonly destroyRef = inject(DestroyRef);
private readonly scroll$ = inject(TUI_SHEET_SCROLL);
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly zone = inject(NgZone);

@Input()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {Directive, ElementRef, inject, NgZone, Output} from '@angular/core';
import {Directive, inject, NgZone, Output} from '@angular/core';
import {WINDOW} from '@ng-web-apis/common';
import {tuiIfMap, tuiIsFalsy, tuiTypedFromEvent, tuiZonefull} from '@taiga-ui/cdk';
import {
tuiIfMap,
tuiInjectElement,
tuiIsFalsy,
tuiTypedFromEvent,
tuiZonefull,
} from '@taiga-ui/cdk';
import type {Observable} from 'rxjs';
import {distinctUntilChanged, filter, merge, startWith} from 'rxjs';

Expand All @@ -16,7 +22,7 @@ export class TuiSheetCloseDirective {
private readonly dragged$ = inject(TUI_SHEET_DRAGGED);
private readonly scroll$ = inject(TUI_SHEET_SCROLL);
private readonly win = inject(WINDOW);
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly sheet = inject(TuiSheetComponent);

@Output()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {DestroyRef, Directive, ElementRef, inject} from '@angular/core';
import {DestroyRef, Directive, inject} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {tuiInjectElement} from '@taiga-ui/cdk';
import {TUI_SCROLL_REF} from '@taiga-ui/core';
import {
distinctUntilChanged,
Expand All @@ -19,7 +20,7 @@ export class TuiSheetStopDirective {
constructor() {
const scrollRef = inject(TUI_SCROLL_REF).nativeElement;
const destroyRef = inject(DestroyRef);
const el: HTMLElement = inject(ElementRef).nativeElement;
const el = tuiInjectElement();

inject(TUI_SHEET_SCROLL)
.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Directive, ElementRef, inject, Input} from '@angular/core';
import {tuiGetActualTarget} from '@taiga-ui/cdk';
import {Directive, Input} from '@angular/core';
import {tuiGetActualTarget, tuiInjectElement} from '@taiga-ui/cdk';

@Directive({
standalone: true,
Expand All @@ -10,7 +10,7 @@ import {tuiGetActualTarget} from '@taiga-ui/cdk';
},
})
export class TuiSwipeActionsAutoCloseDirective {
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();

@Input()
public autoClose: boolean | string = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ChangeDetectorRef, Directive, ElementRef, inject} from '@angular/core';
import {ChangeDetectorRef, Directive, inject} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {RouterLinkActive} from '@angular/router';
import {tuiWatch} from '@taiga-ui/cdk';
import {tuiInjectElement, tuiWatch} from '@taiga-ui/cdk';
import type {Observable} from 'rxjs';
import {EMPTY, filter} from 'rxjs';

Expand All @@ -13,7 +13,7 @@ import {TuiTabBarComponent} from './tab-bar.component';
export class TuiTabBarItemDirective {
constructor() {
const tabs = inject(TuiTabBarComponent);
const el: HTMLElement = inject(ElementRef).nativeElement;
const el = tuiInjectElement();
const link: Observable<boolean> =
inject(RouterLinkActive, {optional: true})?.isActiveChange || EMPTY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ import {
afterNextRender,
ChangeDetectorRef,
DestroyRef,
ElementRef,
inject,
Injectable,
INJECTOR,
NgZone,
} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {tuiGetElementOffset, tuiScrollFrom, tuiZonefree} from '@taiga-ui/cdk';
import {
tuiGetElementOffset,
tuiInjectElement,
tuiScrollFrom,
tuiZonefree,
} from '@taiga-ui/cdk';
import {SCROLL_REF_SELECTOR, TUI_SCROLL_REF} from '@taiga-ui/core';
import {map, Observable, Subscription, tap} from 'rxjs';

@Injectable()
export class TuiElasticStickyService extends Observable<number> {
private readonly injector = inject(INJECTOR);
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly scrollRef: HTMLElement = inject(TUI_SCROLL_REF).nativeElement;
private readonly el = tuiInjectElement();
private readonly scrollRef = inject(TUI_SCROLL_REF).nativeElement;
private readonly zone = inject(NgZone);
private readonly cd = inject(ChangeDetectorRef);
private readonly destroyRef = inject(DestroyRef);
Expand Down
5 changes: 3 additions & 2 deletions projects/addon-mobile/directives/ripple/ripple.directive.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Directive, ElementRef, inject, Input, Renderer2} from '@angular/core';
import {Directive, inject, Input, Renderer2} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {
TUI_FALSE_HANDLER,
TUI_TRUE_HANDLER,
tuiInjectElement,
tuiTypedFromEvent,
tuiWithStyles,
} from '@taiga-ui/cdk';
Expand All @@ -23,7 +24,7 @@ const TOUCH_MOVE_DELAY = 100;
providers: TUI_RIPPLE_PROVIDERS,
})
export class TuiRippleDirective {
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly renderer = inject(Renderer2);
private readonly start$ = inject(TUI_RIPPLE_START);
private readonly end$ = inject(TUI_RIPPLE_END);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Directive, ElementRef, inject, Input, Renderer2} from '@angular/core';
import {Directive, inject, Input, Renderer2} from '@angular/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import type {TuiTouchMode} from '@taiga-ui/addon-mobile/types';
import {tuiFindTouchIndex} from '@taiga-ui/addon-mobile/utils';
import {TUI_IS_IOS, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {TUI_IS_IOS, tuiInjectElement, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {TUI_ELEMENT_REF} from '@taiga-ui/core';
import {filter, map, race, switchMap, take, tap} from 'rxjs';

Expand All @@ -18,7 +18,7 @@ const STYLE = {
export class TuiTouchableDirective {
private readonly isIOS = inject(TUI_IS_IOS);
private readonly renderer = inject(Renderer2);
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly elementRef?: HTMLElement = inject(TUI_ELEMENT_REF, {optional: true})
?.nativeElement;

Expand Down
11 changes: 3 additions & 8 deletions projects/addon-preview/components/preview/preview.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
inject,
Input,
} from '@angular/core';
import {ChangeDetectionStrategy, Component, inject, Input} from '@angular/core';
import {TUI_PREVIEW_ICONS, TUI_PREVIEW_TEXTS} from '@taiga-ui/addon-preview/tokens';
import type {TuiZoom} from '@taiga-ui/cdk';
import {
TUI_FALSE_HANDLER,
tuiClamp,
tuiDragAndDropFrom,
tuiInjectElement,
tuiPx,
tuiRound,
tuiTypedFromEvent,
Expand All @@ -30,7 +25,7 @@ const ROTATION_ANGLE = 90;
animations: [tuiSlideInTop],
})
export class TuiPreviewComponent {
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();

@Input()
public zoomable = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DOCUMENT} from '@angular/common';
import {Directive, ElementRef, inject, Output} from '@angular/core';
import {tuiPreventDefault, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {Directive, inject, Output} from '@angular/core';
import {tuiInjectElement, tuiPreventDefault, tuiTypedFromEvent} from '@taiga-ui/cdk';
import {TUI_ELEMENT_REF} from '@taiga-ui/core';
import {distinctUntilChanged, map, switchMap, takeUntil} from 'rxjs';

Expand All @@ -9,7 +9,7 @@ import {distinctUntilChanged, map, switchMap, takeUntil} from 'rxjs';
})
export class TuiResizedDirective {
private readonly doc = inject(DOCUMENT);
private readonly el: HTMLElement = inject(ElementRef).nativeElement;
private readonly el = tuiInjectElement();
private readonly parentRef: HTMLTableCellElement =
inject(TUI_ELEMENT_REF).nativeElement;

Expand Down
Loading

0 comments on commit 68d4514

Please sign in to comment.