Skip to content

Commit

Permalink
refactor: support noUncheckedIndexedAccess (#8714)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Aug 30, 2024
1 parent 53b7d00 commit e566fac
Show file tree
Hide file tree
Showing 149 changed files with 447 additions and 396 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"@taiga-ui/event-plugins": "4.0.1",
"@taiga-ui/prettier-config": "0.113.3",
"@taiga-ui/stylelint-config": "0.147.0",
"@taiga-ui/tsconfig": "0.113.3",
"@taiga-ui/tsconfig": "0.147.10",
"@types/glob": "8.1.0",
"@types/loader-utils": "2.0.6",
"@types/node": "22.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ export class TuiLineChart {
private readonly hover$ = new Subject<number>();
private readonly autoId = tuiInjectId();

protected readonly hintDirective = inject(TuiLineChartHint, {
optional: true,
});
protected readonly hintDirective = inject(TuiLineChartHint, {optional: true});

protected readonly hintOptions = inject(TuiHintOptionsDirective, {optional: true});

Expand Down Expand Up @@ -165,8 +163,10 @@ export class TuiLineChart {

protected getImplicit($implicit: TuiPoint): TuiPoint | readonly TuiPoint[] {
return (
this.hintDirective?.getContext(this.value.indexOf($implicit), this) ||
$implicit
(this.hintDirective?.getContext(
this.value.indexOf($implicit),
this,
) as readonly TuiPoint[]) ?? $implicit
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NgForOf} from '@angular/common';
import type {AfterViewInit, QueryList} from '@angular/core';
import {type AfterViewInit, type QueryList} from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
Expand Down Expand Up @@ -113,6 +113,12 @@ export class TuiLineDaysChart implements AfterViewInit {
});
}

public get hint():
| PolymorpheusContent<TuiContext<[TuiDay, number]>>
| PolymorpheusContent<TuiContext<readonly TuiPoint[]>> {
return this.hintDirective?.hint ?? this.hintContent;
}

public ngAfterViewInit(): void {
combineLatest([tuiLineChartDrivers(this.charts), this.hovered$])
.pipe(
Expand Down Expand Up @@ -146,6 +152,30 @@ export class TuiLineDaysChart implements AfterViewInit {
});
}

public raise(index: number, {value}: TuiLineChart): void {
const x = value[index]?.[0] || 0;
const month = this.getDay(x);

if (!month) {
return;
}

if (this.hintDirective) {
this.hintDirective.raise(month);
} else {
this.onHovered(month);
}
}

public getContext(index: number, {value}: TuiLineChart): unknown {
const x = value[index]?.[0] || 0;
const day = this.getDay(x);

return this.hintDirective && day
? this.hintDirective.getContext(day)
: this.getHintContext(x, this.value);
}

protected get months(): ReadonlyArray<readonly TuiPoint[]> {
return this.value.length ? this.breakMonths(this.value) : EMPTY_ARRAY;
}
Expand All @@ -154,18 +184,12 @@ export class TuiLineDaysChart implements AfterViewInit {
return this.months.length * (this.value[0]?.[0].daysCount || 0);
}

protected get hint():
| PolymorpheusContent<TuiContext<[TuiDay, number]>>
| PolymorpheusContent<TuiContext<readonly TuiPoint[]>> {
return this.hintDirective?.hint ?? this.hintContent;
}

@tuiPure
protected getHintContext(
x: number,
value: ReadonlyArray<[TuiDay, number]>,
): [TuiDay, number] {
return value[x - (value[0]?.[0]?.day || 0) + 1];
): [TuiDay, number] | null {
return value[x - (value[0]?.[0]?.day || 0) + 1] ?? null;
}

protected readonly daysStringify: TuiStringHandler<number> = (index) => {
Expand All @@ -183,34 +207,10 @@ export class TuiLineDaysChart implements AfterViewInit {
return index - offset;
}

protected raise(index: number, {value}: TuiLineChart): void {
const x = value[index]?.[0] || 0;
const month = this.getDay(x);

if (!month) {
return;
}

if (this.hintDirective) {
this.hintDirective.raise(month);
} else {
this.onHovered(month);
}
}

protected getWidth(index: number): number {
return (this.getDay(index)?.daysCount || 0) * this.months.length;
}

protected getContext(index: number, {value}: TuiLineChart): unknown {
const x = value[index]?.[0] || 0;
const day = this.getDay(x);

return this.hintDirective && day
? this.hintDirective.getContext(day)
: this.getHintContext(x, this.value);
}

@tuiPure
private breakMonths(
value: ReadonlyArray<[TuiDay, number]>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
[style.zIndex]="zIndex"
[tuiHintContent]="hintContent ? hint : ''"
[value]="month"
[width]="first ? firstWidth : getWidth(month[0][0])"
[x]="first ? 0 : getX(month[0][0])"
[width]="first ? firstWidth : getWidth(month[0]?.[0] ?? 0)"
[x]="first ? 0 : getX(month[0]?.[0] ?? 0)"
[xStringify]="xStringify ? daysStringify : null"
[y]="y"
[yStringify]="yStringify"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
[style.color]="'var(--tui-chart-categorical-0' + index + ')'"
[tuiHint]="hintContent"
[tuiHintContext]="{$implicit: index}"
[tuiPieChart]="segments[index]"
[tuiPieChart]="segments[index] || [0, 0]"
(tuiHoveredChange)="onHovered($event, index)"
/>
</g>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ describe('TuiRepeatTimes directive', () => {
});

it('passes index as implicit context', () => {
expect(debugElements[0].nativeElement.title).toBe('0');
expect(debugElements[1].nativeElement.title).toBe('1');
expect(debugElements[2].nativeElement.title).toBe('2');
expect(debugElements[0]?.nativeElement.title).toBe('0');
expect(debugElements[1]?.nativeElement.title).toBe('1');
expect(debugElements[2]?.nativeElement.title).toBe('2');
});
});
});
6 changes: 3 additions & 3 deletions projects/cdk/utils/dom/test/get-element-obscurers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ describe('tuiGetElementObscures', () => {
const mockElementFromPoint = jest.mocked(ownerDocument.elementFromPoint);

mockElementFromPoint
.mockReturnValueOnce(others[0])
.mockReturnValueOnce(others[1])
.mockReturnValueOnce(others[2])
.mockReturnValueOnce(others[0]!)
.mockReturnValueOnce(others[1]!)
.mockReturnValueOnce(others[2]!)
.mockReturnValueOnce(element);

expect(tuiGetElementObscures(element)).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ describe('CalendarSheet', () => {
it('blocked date under condition', () => {
expect(getDisabledCalendarItems().length).toBe(1);
expect(
getDisabledCalendarItems()[0].nativeElement.textContent.trim(),
getDisabledCalendarItems()[0]?.nativeElement.textContent.trim(),
).toBe('20');
});

it('click on blocked date does not change value', () => {
getDisabledCalendarItems()[0].nativeElement.click();
getDisabledCalendarItems()[0]?.nativeElement.click();
fixture.detectChanges();

expect(testComponent.value).toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion projects/demo-playwright/tests/deep/deep-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test.describe('Deep / Select', () => {
if (cleaner) {
await cleaner.click();
} else {
await options[0].focus();
await options[0]?.focus();
await page.keyboard.down('Enter');
}

Expand Down
8 changes: 4 additions & 4 deletions projects/demo-playwright/tests/kit/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test.describe('Slider', () => {
});

test('=> 0', async () => {
await tickLabels[0].click();
await tickLabels[0]?.click();

await expect(async () => {
expect(await slider.value).toBe(0);
Expand All @@ -173,7 +173,7 @@ test.describe('Slider', () => {
});

test('=> 500', async () => {
await tickLabels[2].click();
await tickLabels[2]?.click();

await expect(async () => {
expect(await slider.value).toBe(500);
Expand All @@ -184,7 +184,7 @@ test.describe('Slider', () => {
});

test('=> 750', async () => {
await tickLabels[3].click();
await tickLabels[3]?.click();

await expect(async () => {
expect(await slider.value).toBe(750);
Expand All @@ -195,7 +195,7 @@ test.describe('Slider', () => {
});

test('=> 1000', async () => {
await tickLabels.at(-1)!.click();
await tickLabels.at(-1)?.click();

await expect(async () => {
expect(await slider.value).toBe(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class TuiCalendarRangePO {
public async selectItem(index: number): Promise<void> {
const items = await this.getItems();

await items[index].click();
await items[index]?.click();
}

public async itemHasCheckmark(index: number): Promise<boolean> {
const items = await this.getItems();

const itemCheckmark = await items[index]
.locator('[automation-id="tui-calendar-range__checkmark"]')
?.locator('[automation-id="tui-calendar-range__checkmark"]')
.count();

return !!itemCheckmark;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export class TuiInputDateRangePO {
public async selectItem(index: number): Promise<void> {
const items = await this.getItems();

await items[index].click();
await items[index]?.click();
}

public async itemHasCheckmark(index: number): Promise<boolean> {
const items = await this.getItems();

const itemCheckmark = await items[index]
.locator('[automation-id="tui-calendar-range__checkmark"]')
?.locator('[automation-id="tui-calendar-range__checkmark"]')
.count();

return !!itemCheckmark;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class TuiTextfieldWithDataListPO {
const options = await this.getOptions();

for (const optionIndex of indexes) {
await options[optionIndex].click();
await options[optionIndex]?.click();
}
}

Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/modules/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const config: ApplicationConfig = {
}

return `${link}/${pkg.toLowerCase()}/${type.toLowerCase()}/${(
header[0].toLowerCase() + header.slice(1)
(header[0]?.toLowerCase() ?? '') + header.slice(1)
).replaceAll(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}`;
},
},
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/modules/app/landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div
class="container"
(waIntersectionObservee)="intersected = $event[0].isIntersecting || intersected"
(waIntersectionObservee)="intersected = $event[0]?.isIntersecting || intersected"
>
<iframe
*ngIf="intersected || current === 1"
Expand Down Expand Up @@ -160,7 +160,7 @@ <h2 class="opensource">It’s open source</h2>
waIntersectionObserver
waIntersectionThreshold="0.5"
class="screen"
(waIntersectionObservee)="onIntersection($event, index)"
(waIntersectionObservee)="$event[0] && onIntersection($event[0], index)"
></div>

<footer class="footer">
Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/modules/app/landing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Page implements OnInit {
}

protected onIntersection(
[{isIntersecting, target}]: IntersectionObserverEntry[],
{isIntersecting, target}: IntersectionObserverEntry,
index: number,
): void {
if (isIntersecting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export abstract class AbstractTuiStackblitzResourcesLoader {
].map(tuiRawLoad),
);

const [angularJson, tsconfig] = tuiTryParseMarkdownCodeBlock(configsContent);
const [mainTs] = tuiTryParseMarkdownCodeBlock(mainTsContent);
const [indexHtml] = tuiTryParseMarkdownCodeBlock(indexHtmlContent);
const [globalStyles] = tuiTryParseMarkdownCodeBlock(stylesContent);
const [angularJson = '', tsconfig = ''] =
tuiTryParseMarkdownCodeBlock(configsContent);
const [mainTs = ''] = tuiTryParseMarkdownCodeBlock(mainTsContent);
const [indexHtml = ''] = tuiTryParseMarkdownCodeBlock(indexHtmlContent);
const [globalStyles = ''] = tuiTryParseMarkdownCodeBlock(stylesContent);

return {angularJson, tsconfig, mainTs, indexHtml, globalStyles};
}
Expand Down
4 changes: 2 additions & 2 deletions projects/demo/src/modules/app/stackblitz/starter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default class Page implements OnInit {
description:
'A starter with Taiga UI library\nDocumentation: https://taiga-ui.dev',
files: {
[appPrefix`app.template.html`]: appTemplate,
[appPrefix`app.component.ts`]: appComponent,
[appPrefix`app.template.html`]: appTemplate ?? '',
[appPrefix`app.component.ts`]: appComponent ?? '',
[appPrefix`app.style.less`]:
"@import '@taiga-ui/core/styles/taiga-ui-local.less';",
},
Expand Down
Loading

0 comments on commit e566fac

Please sign in to comment.