Skip to content

Commit

Permalink
refactor!: remove date-time related deprecations, EMPTY_VALIDATOR (#2164
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vladimirpotekhin authored and splincode committed Aug 10, 2022
1 parent ee62d5b commit 86e78c1
Show file tree
Hide file tree
Showing 48 changed files with 798 additions and 1,426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces';
import {draw} from '@taiga-ui/addon-charts/utils';
import {
inRange,
tuiDefaultProp,
TuiIdService,
tuiInRange,
tuiPure,
TuiStringHandler,
tuiZoneOptimized,
Expand All @@ -27,7 +27,7 @@ import {TuiLineChartHintDirective} from './line-chart-hint.directive';

// eslint-disable-next-line @typescript-eslint/naming-convention
export function smoothingAssertion(smoothingFactor: number): boolean {
return inRange(smoothingFactor, 0, 100);
return tuiInRange(smoothingFactor, 0, 100);
}

const SMOOTHING_MESSAGE = `smoothingFactor must be between 0 and 100`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Directive, ElementRef, HostListener, Inject} from '@angular/core';
import {
clamp,
getClosestFocusable,
isNativeMouseFocusable,
setNativeFocused,
tuiGetClosestFocusable,
tuiIsNativeFocusedIn,
tuiIsNativeMouseFocusable,
TuiNativeFocusableElement,
} from '@taiga-ui/cdk';

Expand Down Expand Up @@ -49,9 +49,9 @@ export class TuiToolbarNavigationManagerDirective {
: this.toolsContainers;

for (const el of tools) {
const focusableElement = isNativeMouseFocusable(el)
const focusableElement = tuiIsNativeMouseFocusable(el)
? el
: getClosestFocusable(el, false, el, false);
: tuiGetClosestFocusable(el, false, el, false);

if (focusableElement) {
return focusableElement;
Expand All @@ -62,21 +62,26 @@ export class TuiToolbarNavigationManagerDirective {
}

private findPreviousTool(wrapper: HTMLElement): HTMLElement | null {
if (isNativeMouseFocusable(wrapper)) {
if (tuiIsNativeMouseFocusable(wrapper)) {
return wrapper;
}

const lookedInside = getClosestFocusable(wrapper, false, wrapper, false);
const lookedInside = tuiGetClosestFocusable(wrapper, false, wrapper, false);

return (
lookedInside ||
getClosestFocusable(wrapper, true, this.elementRef.nativeElement, false)
tuiGetClosestFocusable(wrapper, true, this.elementRef.nativeElement, false)
);
}

private findNextTool(wrapper: HTMLElement): HTMLElement | null {
return isNativeMouseFocusable(wrapper)
return tuiIsNativeMouseFocusable(wrapper)
? wrapper
: getClosestFocusable(wrapper, false, this.elementRef.nativeElement, false);
: tuiGetClosestFocusable(
wrapper,
false,
this.elementRef.nativeElement,
false,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {tuiInsertHtml} from '@taiga-ui/addon-editor/utils';
import {
EMPTY_FUNCTION,
getClipboardDataText,
getClosestFocusable,
preventDefault,
setNativeFocused,
TUI_FOCUSABLE_ITEM_ACCESSOR,
TuiComputedDocumentException,
TuiDestroyService,
TuiEventWith,
TuiFocusableElementAccessor,
tuiGetClosestFocusable,
TuiHandler,
tuiIsNativeFocused,
tuiRequiredSetter,
Expand Down Expand Up @@ -219,7 +219,7 @@ export class TuiDesignModeDirective

event.preventDefault();

const element = getClosestFocusable(
const element = tuiGetClosestFocusable(
this.elementRef.nativeElement,
event.shiftKey,
this.elementRef.nativeElement.ownerDocument.body,
Expand Down
5 changes: 2 additions & 3 deletions projects/addon-mobile/components/sheet/sheet-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {inject, InjectionToken} from '@angular/core';
import {InjectionToken} from '@angular/core';
import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus';

import {TuiSheet} from './sheet';
import {TUI_SHEET_OFFSET} from './sheet-tokens';

export interface TuiSheetOptions<I = undefined, O = unknown> {
readonly image: PolymorpheusContent<TuiSheet<O, I>>;
Expand All @@ -28,6 +27,6 @@ export const TUI_SHEET_DEFAULT_OPTIONS: Omit<TuiSheetOptions, 'data'> = {
export const TUI_SHEET_OPTIONS = new InjectionToken<Omit<TuiSheetOptions, 'data'>>(
`Default parameters for sheet component`,
{
factory: () => ({...TUI_SHEET_DEFAULT_OPTIONS, offset: inject(TUI_SHEET_OFFSET)}),
factory: () => ({...TUI_SHEET_DEFAULT_OPTIONS}),
},
);
8 changes: 0 additions & 8 deletions projects/addon-mobile/components/sheet/sheet-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@ export const TUI_SHEET_SCROLL = new InjectionToken<number>(
export const TUI_SHEET_DRAGGED = new InjectionToken<boolean>(
'The sheet is being dragged',
);

/** @deprecated use option argument for each Sheet */
export const TUI_SHEET_OFFSET = new InjectionToken<number>(
'Offset from the top at which the sheet stops',
{
factory: () => 16,
},
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Directive, ElementRef, Inject, Input, Optional, Renderer2} from '@angular/core';
import {TuiTouchMode} from '@taiga-ui/addon-mobile/types';
import {findTouchIndex} from '@taiga-ui/addon-mobile/utils';
import {tuiFindTouchIndex} from '@taiga-ui/addon-mobile/utils';
import {
TUI_IS_IOS,
tuiDefaultProp,
Expand Down Expand Up @@ -74,7 +74,7 @@ export class TuiTouchableDirective {
identifier: number,
): boolean {
const {ownerDocument} = element;
const id = findTouchIndex(touches, identifier);
const id = tuiFindTouchIndex(touches, identifier);

if (!ownerDocument || id === -1) {
return true;
Expand Down
8 changes: 1 addition & 7 deletions projects/addon-mobile/utils/find-touch-index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* @deprecated: use {@link tuiFindTouchIndex} instead
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function findTouchIndex(touches: TouchList, id: number): number {
export function tuiFindTouchIndex(touches: TouchList, id: number): number {
for (let i = 0; i < touches.length; i++) {
const {identifier} = touches[i];

Expand All @@ -13,5 +9,3 @@ export function findTouchIndex(touches: TouchList, id: number): number {

return -1;
}

export const tuiFindTouchIndex = findTouchIndex;
3 changes: 0 additions & 3 deletions projects/cdk/constants/empty.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {QueryList} from '@angular/core';
import {ValidatorFn} from '@angular/forms';

/**
* For type safety when using @ContentChildren and @ViewChildren
Expand All @@ -9,8 +8,6 @@ import {ValidatorFn} from '@angular/forms';
export const EMPTY_QUERY = new QueryList<any>();
export const EMPTY_ARRAY: [] = [];
export const EMPTY_FUNCTION: (...args: any[]) => void = () => {};
/** @deprecated use Validators.nullValidator */
export const EMPTY_VALIDATOR: ValidatorFn = () => null;
export const EMPTY_CLIENT_RECT: ClientRect = {
bottom: 0,
height: 0,
Expand Down
13 changes: 3 additions & 10 deletions projects/cdk/constants/test/handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {AbstractControl} from '@angular/forms';

import {ALWAYS_FALSE_HANDLER} from '../always-false-handler';
import {ALWAYS_TRUE_HANDLER} from '../always-true-handler';
import {EMPTY_VALIDATOR} from '../empty';

describe(`Handler functions`, () => {
it(`Always false`, () => {
describe('Handler functions', () => {
it('Always false', () => {
expect(ALWAYS_FALSE_HANDLER()).toBe(false);
});

it(`Always true`, () => {
it('Always true', () => {
expect(ALWAYS_TRUE_HANDLER()).toBe(true);
});

it(`EMPTY_VALIDATOR`, () => {
expect(EMPTY_VALIDATOR({} as unknown as AbstractControl)).toBe(null);
});
});
23 changes: 0 additions & 23 deletions projects/cdk/date-time/date-fillers.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
import {inject, InjectionToken} from '@angular/core';

import {RANGE_SEPARATOR_CHAR} from './date-time';

/**
* @deprecated dont use it. See {@link TUI_DATE_FORMAT}
*/
export const TUI_DATE_FILLER = new InjectionToken<string>(`date filler for Taiga UI`, {
factory: () => `dd.mm.yyyy`,
});

/**
* @deprecated dont use it
*/
export const TUI_DATE_RANGE_FILLER = new InjectionToken<string>(
`date range filler for Taiga UI`,
{
factory: () => {
const dateFiller = inject(TUI_DATE_FILLER);

return `${dateFiller}${RANGE_SEPARATOR_CHAR}${dateFiller}`;
},
},
);

/**
* @internal 'dd.mm.yyyy'.length
* Used in:
Expand Down
33 changes: 5 additions & 28 deletions projects/cdk/date-time/day-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TuiMonthRange} from './month-range';
* @deprecated
*/
export const isDateMode = (dateMode: string): dateMode is TuiDateMode =>
[`DMY`, `YMD`, `MDY`].includes(dateMode);
['DMY', 'YMD', 'MDY'].includes(dateMode);

/**
* An immutable range of two {@link TuiDay} objects
Expand All @@ -36,16 +36,6 @@ export class TuiDayRange extends TuiMonthRange {
: new TuiDayRange(day2, day1);
}

/**
* @deprecated
*/
static normalizeParse(
rangeString: string,
dateFiller: string,
dateRangeFiller: string,
): TuiDayRange;
static normalizeParse(rangeString: string, dateMode?: TuiDateMode): TuiDayRange;

/**
* Parse and correct a day range in string format
*
Expand All @@ -55,13 +45,11 @@ export class TuiDayRange extends TuiMonthRange {
*/
static normalizeParse(
rangeString: string,
dateMode: string | TuiDateMode = `DMY`,
dateMode: TuiDateMode = 'DMY',
): TuiDayRange {
const dateFormat = isDateMode(dateMode) ? dateMode : `DMY`;

const leftDay = TuiDay.normalizeParse(
rangeString.slice(0, DATE_FILLER_LENGTH),
dateFormat,
dateMode,
);

if (rangeString.length < DATE_RANGE_FILLER_LENGTH) {
Expand All @@ -72,7 +60,7 @@ export class TuiDayRange extends TuiMonthRange {
leftDay,
TuiDay.normalizeParse(
rangeString.slice(DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length),
dateFormat,
dateMode,
),
);
}
Expand All @@ -81,17 +69,6 @@ export class TuiDayRange extends TuiMonthRange {
return this.from.daySame(this.to);
}

/**
* Human readable format.
* @deprecated use {@link getFormattedDayRange} instead
*/
get formattedDayRange(): string {
const from = this.from.getFormattedDay(`DMY`, `.`);
const to = this.to.getFormattedDay(`DMY`, `.`);

return `${from}${RANGE_SEPARATOR_CHAR}${to}`;
}

/**
* Tests ranges for identity
*
Expand Down Expand Up @@ -123,7 +100,7 @@ export class TuiDayRange extends TuiMonthRange {
return `${from}${RANGE_SEPARATOR_CHAR}${to}`;
}

toString(dateFormat: TuiDateMode = `DMY`, dateSeparator: string = `.`): string {
toString(dateFormat: TuiDateMode = 'DMY', dateSeparator: string = '.'): string {
const from = this.from.getFormattedDay(dateFormat, dateSeparator);
const to = this.to.getFormattedDay(dateFormat, dateSeparator);

Expand Down
Loading

0 comments on commit 86e78c1

Please sign in to comment.