Skip to content

Commit e51dc41

Browse files
committed
feat: queries
1 parent 349a34b commit e51dc41

File tree

9 files changed

+295
-306
lines changed

9 files changed

+295
-306
lines changed

packages/demo/src/app/dropzone-wrapper/examples/sandbox/sandbox.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, ViewEncapsulation } from '@angular/core'
1+
import { Component, ViewEncapsulation, viewChild } from '@angular/core'
22
import { FormsModule } from '@angular/forms'
33
// eslint-disable-next-line @import/no-extraneous-dependencies
44
import Dropzone from 'dropzone'
@@ -27,8 +27,8 @@ export class SandboxComponent {
2727
maxFiles: 1
2828
}
2929

30-
@ViewChild(DropzoneComponent) componentRef?: DropzoneComponent
31-
@ViewChild(DropzoneDirective) directiveRef?: DropzoneDirective
30+
readonly componentRef = viewChild(DropzoneComponent)
31+
readonly directiveRef = viewChild(DropzoneDirective)
3232

3333
onUploadInit(dz: Dropzone) {
3434
console.log('onUploadInit:', dz)
@@ -51,10 +51,12 @@ export class SandboxComponent {
5151
}
5252

5353
resetDropzone(): void {
54-
if (this.type === 'directive' && this.directiveRef) {
55-
this.directiveRef.reset()
56-
} else if (this.type === 'component' && this.componentRef && this.componentRef.directiveRef) {
57-
this.componentRef.directiveRef.reset()
54+
const directiveRef = this.directiveRef()
55+
const componentRef = this.componentRef()
56+
if (this.type === 'directive' && directiveRef) {
57+
directiveRef.reset()
58+
} else if (this.type === 'component' && componentRef && componentRef.directiveRef) {
59+
componentRef.directiveRef.reset()
5860
}
5961
}
6062

packages/dropzone-wrapper/src/lib/dropzone.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @angular-eslint/no-output-rename */
2-
import { Component, EventEmitter, OnInit, Output, ViewChild, ViewEncapsulation, input } from '@angular/core'
2+
import { Component, EventEmitter, OnInit, Output, ViewEncapsulation, input, viewChild } from '@angular/core'
33
import { DropzoneDirective } from './dropzone.directive'
44
import { DropzoneConfig, DropzoneListeners, NXT_DROPZONE_LISTENERS } from './dropzone.interfaces'
55

@@ -79,7 +79,7 @@ export class DropzoneComponent implements OnInit, DropzoneListeners {
7979

8080
@Output('queueComplete') readonly DZ_QUEUECOMPLETE = new EventEmitter<void>()
8181

82-
@ViewChild(DropzoneDirective) directiveRef?: DropzoneDirective
82+
readonly directiveRef = viewChild(DropzoneDirective)
8383

8484
constructor() { }
8585

packages/pick-datetime/src/lib/date-time/calendar-month-view/calendar-month-view.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Inject, Input, OnDestroy, OnInit, Output, ViewChild, input } from '@angular/core'
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Inject, Input, OnDestroy, OnInit, Output, input, viewChild } from '@angular/core'
22
import { Subscription } from 'rxjs'
33
import { DateTimeAdapter } from '../../class/date-time-adapter.class'
44
import { DateTimeFormats, NXT_DATE_TIME_FORMATS } from '../../class/date-time-format.class'
@@ -243,8 +243,7 @@ export class MonthViewComponent<T> implements OnInit, AfterContentInit, OnDestro
243243
readonly pickerMomentChange = new EventEmitter<T>()
244244

245245
/** The body of calendar table */
246-
@ViewChild(CalendarBodyComponent, { static: true })
247-
private calendarBodyElm?: CalendarBodyComponent
246+
private readonly calendarBodyElm = viewChild(CalendarBodyComponent)
248247

249248
/** @internal */
250249
@HostBinding('class.nxt-dt-calendar-view')
@@ -595,6 +594,6 @@ export class MonthViewComponent<T> implements OnInit, AfterContentInit, OnDestro
595594
}
596595

597596
private focusActiveCell() {
598-
this.calendarBodyElm?.focusActiveCell()
597+
this.calendarBodyElm()?.focusActiveCell()
599598
}
600599
}

packages/pick-datetime/src/lib/date-time/calendar-multi-year-view/calendar-multi-year-view.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Input, OnInit, Output, ViewChild } from '@angular/core'
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Input, OnInit, Output, viewChild } from '@angular/core'
22
import { DateTimeAdapter } from '../../class/date-time-adapter.class'
33
import { DateFilter, SelectMode } from '../../class/date-time.class'
4-
import { CalendarCell, CalendarBodyComponent } from '../calendar-body/calendar-body.component'
4+
import { CalendarBodyComponent, CalendarCell } from '../calendar-body/calendar-body.component'
55
import { DateTimeIntl } from '../date-time-picker-intl.service'
66

77
/** @internal */
@@ -206,8 +206,7 @@ export class MultiYearViewComponent<T> implements OnInit, AfterContentInit {
206206
readonly keyboardEnter = new EventEmitter<void>()
207207

208208
/** The body of calendar table */
209-
@ViewChild(CalendarBodyComponent, { static: true })
210-
private calendarBodyElm?: CalendarBodyComponent
209+
private readonly calendarBodyElm = viewChild(CalendarBodyComponent)
211210

212211
/** @internal */
213212
@HostBinding('class.nxt-dt-calendar-view')
@@ -446,6 +445,6 @@ export class MultiYearViewComponent<T> implements OnInit, AfterContentInit {
446445
}
447446

448447
private focusActiveCell() {
449-
this.calendarBodyElm?.focusActiveCell()
448+
this.calendarBodyElm()?.focusActiveCell()
450449
}
451450
}

packages/pick-datetime/src/lib/date-time/calendar-year-view/calendar-year-view.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Inject, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
1+
import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, HostBinding, Inject, Input, OnDestroy, OnInit, Output, viewChild } from '@angular/core'
22
import { Subscription } from 'rxjs'
33
import { DateTimeAdapter } from '../../class/date-time-adapter.class'
44
import { DateTimeFormats, NXT_DATE_TIME_FORMATS } from '../../class/date-time-format.class'
55
import { DateFilter, SelectMode } from '../../class/date-time.class'
6-
import { CalendarCell, CalendarBodyComponent } from '../calendar-body/calendar-body.component'
6+
import { CalendarBodyComponent, CalendarCell } from '../calendar-body/calendar-body.component'
77

88
/** @internal */
99
const MONTHS_PER_YEAR = 12
@@ -196,8 +196,7 @@ export class YearViewComponent<T> implements OnInit, AfterContentInit, OnDestroy
196196
readonly keyboardEnter = new EventEmitter<void>()
197197

198198
/** The body of calendar table */
199-
@ViewChild(CalendarBodyComponent, { static: true })
200-
private calendarBodyElm?: CalendarBodyComponent
199+
private readonly calendarBodyElm = viewChild(CalendarBodyComponent)
201200

202201
/** @internal */
203202
@HostBinding('class.nxt-dt-calendar-view')
@@ -515,6 +514,6 @@ export class YearViewComponent<T> implements OnInit, AfterContentInit, OnDestroy
515514
}
516515

517516
private focusActiveCell() {
518-
this.calendarBodyElm?.focusActiveCell()
517+
this.calendarBodyElm()?.focusActiveCell()
519518
}
520519
}

packages/pick-datetime/src/lib/date-time/date-time-inline/date-time-inline.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, HostBinding, Inject, Input, OnInit, Output, Provider, ViewChild } from '@angular/core'
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, HostBinding, Inject, Input, OnInit, Output, Provider, viewChild } from '@angular/core'
22
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
33
import { DateTimeAdapter } from '../../class/date-time-adapter.class'
44
import { DateTimeFormats, NXT_DATE_TIME_FORMATS } from '../../class/date-time-format.class'
@@ -25,8 +25,7 @@ export const NXT_DATETIME_VALUE_ACCESSOR: Provider = {
2525
})
2626
export class DateTimeInlineComponent<T> extends DateTimeDirective<T> implements OnInit, ControlValueAccessor {
2727

28-
@ViewChild(DateTimeContainerComponent, { static: true })
29-
private container?: DateTimeContainerComponent<T>
28+
private readonly container = viewChild(DateTimeContainerComponent)
3029

3130
private _pickerType: PickerType = 'both'
3231
/**
@@ -261,21 +260,24 @@ export class DateTimeInlineComponent<T> extends DateTimeDirective<T> implements
261260
}
262261

263262
ngOnInit() {
264-
if (this.container)
265-
this.container.picker = this
263+
const container = this.container()
264+
if (container)
265+
container.picker = this
266266
}
267267

268268
writeValue(value: any): void {
269269
value = value ?? undefined
270270
if (this.isInSingleMode) {
271271
this.value = value
272-
if (this.container)
273-
this.container.pickerMoment = value
272+
const container = this.container()
273+
if (container)
274+
container.pickerMoment = value
274275
} else {
275276
this.values = value
276-
if (this.container)
277-
this.container.pickerMoment = this._values?.[
278-
this.container.activeSelectedIndex
277+
const container = this.container()
278+
if (container)
279+
container.pickerMoment = this._values?.[
280+
container.activeSelectedIndex
279281
]
280282
}
281283
}

packages/pick-datetime/src/lib/date-time/date-time-picker-container/date-time-picker-container.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AnimationEvent } from '@angular/animations'
2-
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, HostBinding, HostListener, OnInit, ViewChild } from '@angular/core'
2+
import { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, HostBinding, HostListener, OnInit, viewChild } from '@angular/core'
33
import { Subject } from 'rxjs'
44
import { CdkTrapFocus } from '@angular/cdk/a11y'
55
import { NgClass } from '@angular/common'
@@ -30,11 +30,9 @@ import { dateTimePickerAnimations } from './date-time-picker-container.animation
3030
})
3131
export class DateTimeContainerComponent<T> implements OnInit, AfterContentInit, AfterViewInit {
3232

33-
@ViewChild(CalendarComponent)
34-
calendar?: CalendarComponent<T>
33+
readonly calendar = viewChild(CalendarComponent)
3534

36-
@ViewChild(TimerComponent)
37-
timer?: TimerComponent<T>
35+
readonly timer = viewChild(TimerComponent)
3836

3937
picker?: DateTimeDirective<T>
4038
activeSelectedIndex = 0 // The current active SelectedIndex in range select mode (0: 'from', 1: 'to')
@@ -464,10 +462,12 @@ export class DateTimeContainerComponent<T> implements OnInit, AfterContentInit,
464462
return
465463
}
466464

467-
if (this.calendar) {
468-
this.calendar.focusActiveCell()
469-
} else if (this.timer) {
470-
this.timer.focus()
465+
const calendar = this.calendar()
466+
const timer = this.timer()
467+
if (calendar) {
468+
calendar.focusActiveCell()
469+
} else if (timer) {
470+
timer.focus()
471471
}
472472
}
473473
}

0 commit comments

Comments
 (0)