diff --git a/projects/addon-doc/components/navigation/navigation.providers.ts b/projects/addon-doc/components/navigation/navigation.providers.ts index d537f28d6945..d3a5d1c4ea46 100644 --- a/projects/addon-doc/components/navigation/navigation.providers.ts +++ b/projects/addon-doc/components/navigation/navigation.providers.ts @@ -1,12 +1,11 @@ import type {Provider} from '@angular/core'; -import {InjectionToken} from '@angular/core'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import type {Event} from '@angular/router'; import {ActivatedRoute, NavigationEnd, Router, Scroll} from '@angular/router'; import {TUI_DOC_PAGES, TUI_DOC_TITLE} from '@taiga-ui/addon-doc/tokens'; import type {TuiDocRoutePages} from '@taiga-ui/addon-doc/types'; import {tuiAutoFocusOptionsProvider} from '@taiga-ui/cdk/directives/auto-focus'; -import {tuiIsPresent} from '@taiga-ui/cdk/utils/miscellaneous'; +import {tuiCreateToken, tuiIsPresent} from '@taiga-ui/cdk/utils/miscellaneous'; import {tuiLinkOptionsProvider} from '@taiga-ui/core/components/link'; import {tuiScrollbarOptionsProvider} from '@taiga-ui/core/components/scrollbar'; import type {Observable} from 'rxjs'; @@ -22,22 +21,17 @@ function labelsProviderFactory(pages: TuiDocRoutePages): readonly string[] { /** * Page title */ -export const NAVIGATION_TITLE = new InjectionToken>( - '[NAVIGATION_TITLE]', -); +export const NAVIGATION_TITLE = tuiCreateToken>(); /** * Navigation sections labels for search */ -export const NAVIGATION_LABELS = new InjectionToken( - '[NAVIGATION_LABELS]', -); +export const NAVIGATION_LABELS = tuiCreateToken(); /** * Navigation pages */ -export const NAVIGATION_ITEMS: InjectionToken = - new InjectionToken('[NAVIGATION_ITEMS]'); +export const NAVIGATION_ITEMS = tuiCreateToken(); export const NAVIGATION_PROVIDERS: Provider[] = [ tuiAutoFocusOptionsProvider({preventScroll: true}), diff --git a/projects/addon-doc/components/page/page.providers.ts b/projects/addon-doc/components/page/page.providers.ts index 8a1bc95a393f..7bfcdbecc72a 100644 --- a/projects/addon-doc/components/page/page.providers.ts +++ b/projects/addon-doc/components/page/page.providers.ts @@ -1,11 +1,12 @@ import type {Provider} from '@angular/core'; -import {ElementRef, InjectionToken} from '@angular/core'; +import {ElementRef} from '@angular/core'; import {TUI_DOC_SEE_ALSO} from '@taiga-ui/addon-doc/tokens'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; /** * Array if related page titles */ -export const PAGE_SEE_ALSO = new InjectionToken('[PAGE_SEE_ALSO]'); +export const PAGE_SEE_ALSO = tuiCreateToken(); export const PAGE_PROVIDERS: Provider[] = [ { diff --git a/projects/addon-doc/tokens/code-editor.ts b/projects/addon-doc/tokens/code-editor.ts index e1235d654dda..7ad00b51d01e 100644 --- a/projects/addon-doc/tokens/code-editor.ts +++ b/projects/addon-doc/tokens/code-editor.ts @@ -1,9 +1,7 @@ -import {InjectionToken} from '@angular/core'; import type {TuiCodeEditor} from '@taiga-ui/addon-doc/types'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; /** * Service for opening online IDE e.g. Stackblitz */ -export const TUI_DOC_CODE_EDITOR = new InjectionToken( - '[TUI_DOC_CODE_EDITOR]', -); +export const TUI_DOC_CODE_EDITOR = tuiCreateToken(); diff --git a/projects/addon-mobile/components/mobile-calendar/mobile-calendar.providers.ts b/projects/addon-mobile/components/mobile-calendar/mobile-calendar.providers.ts index 523e953da93b..f6ddeff4b624 100644 --- a/projects/addon-mobile/components/mobile-calendar/mobile-calendar.providers.ts +++ b/projects/addon-mobile/components/mobile-calendar/mobile-calendar.providers.ts @@ -1,11 +1,12 @@ import {VIRTUAL_SCROLL_STRATEGY} from '@angular/cdk/scrolling'; import type {Provider} from '@angular/core'; -import {ChangeDetectorRef, InjectionToken, Optional} from '@angular/core'; +import {ChangeDetectorRef, Optional} from '@angular/core'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import type {TuiDayRange} from '@taiga-ui/cdk/date-time'; import {tuiWatch} from '@taiga-ui/cdk/observables'; import {TuiScrollService} from '@taiga-ui/cdk/services'; import {TUI_IS_IOS} from '@taiga-ui/cdk/tokens'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import {TUI_CALENDAR_DATE_STREAM} from '@taiga-ui/kit/tokens'; import type {Observable} from 'rxjs'; import {EMPTY} from 'rxjs'; @@ -15,9 +16,7 @@ import {TuiMobileCalendarStrategy} from './mobile-calendar.strategy'; /** * Stream for updating value */ -export const TUI_VALUE_STREAM = new InjectionToken>( - '[TUI_VALUE_STREAM]', -); +export const TUI_VALUE_STREAM = tuiCreateToken>(); export const TUI_MOBILE_CALENDAR_PROVIDERS: Provider[] = [ TuiScrollService, diff --git a/projects/cdk/tokens/window-size.ts b/projects/cdk/tokens/window-size.ts index 8d5e86e50fd0..14b10a853496 100644 --- a/projects/cdk/tokens/window-size.ts +++ b/projects/cdk/tokens/window-size.ts @@ -1,46 +1,42 @@ -import {inject, InjectionToken} from '@angular/core'; +import {inject} from '@angular/core'; import {WA_WINDOW} from '@ng-web-apis/common'; import {tuiTypedFromEvent} from '@taiga-ui/cdk/observables'; +import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils'; import type {Observable} from 'rxjs'; import {map, shareReplay, startWith} from 'rxjs'; -export const TUI_WINDOW_SIZE = new InjectionToken>( - '[TUI_WINDOW_SIZE]', - { - factory: () => { - const w = inject(WA_WINDOW); +export const TUI_WINDOW_SIZE = tuiCreateTokenFromFactory>(() => { + const w = inject(WA_WINDOW); - return tuiTypedFromEvent(w, 'resize').pipe( - startWith(null), - map(() => { - const width = Math.max( - w.document.documentElement.clientWidth || 0, - w.innerWidth || 0, - w.visualViewport?.width || 0, - ); - const height = Math.max( - w.document.documentElement.clientHeight || 0, - w.innerHeight || 0, - w.visualViewport?.height || 0, - ); - const rect = { - width, - height, - top: 0, - left: 0, - right: width, - bottom: height, - x: 0, - y: 0, - }; - - return { - ...rect, - toJSON: () => JSON.stringify(rect), - }; - }), - shareReplay({bufferSize: 1, refCount: true}), + return tuiTypedFromEvent(w, 'resize').pipe( + startWith(null), + map(() => { + const width = Math.max( + w.document.documentElement.clientWidth || 0, + w.innerWidth || 0, + w.visualViewport?.width || 0, + ); + const height = Math.max( + w.document.documentElement.clientHeight || 0, + w.innerHeight || 0, + w.visualViewport?.height || 0, ); - }, - }, -); + const rect = { + width, + height, + top: 0, + left: 0, + right: width, + bottom: height, + x: 0, + y: 0, + }; + + return { + ...rect, + toJSON: () => JSON.stringify(rect), + }; + }), + shareReplay({bufferSize: 1, refCount: true}), + ); +}); diff --git a/projects/core/components/data-list/data-list.tokens.ts b/projects/core/components/data-list/data-list.tokens.ts index 11ec53307155..6702d0ff7326 100644 --- a/projects/core/components/data-list/data-list.tokens.ts +++ b/projects/core/components/data-list/data-list.tokens.ts @@ -1,7 +1,6 @@ import type {Provider, TemplateRef, Type} from '@angular/core'; -import {InjectionToken} from '@angular/core'; import type {TuiContext, TuiIdentityMatcher, TuiStringHandler} from '@taiga-ui/cdk/types'; -import {tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; +import {tuiCreateToken, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types'; import type {PolymorpheusContent} from '@taiga-ui/polymorpheus'; @@ -21,9 +20,10 @@ export interface TuiDataListHost { /** * Content for tuiOption component */ -export const TUI_OPTION_CONTENT = new InjectionToken< - PolymorpheusContent>>> ->('[TUI_OPTION_CONTENT]'); +export const TUI_OPTION_CONTENT = + tuiCreateToken< + PolymorpheusContent>>> + >(); export function tuiAsOptionContent( useValue: PolymorpheusContent>>>, @@ -37,9 +37,7 @@ export function tuiAsOptionContent( /** * Accessor for data-list options */ -export const TUI_DATA_LIST_ACCESSOR = new InjectionToken( - '[TUI_DATA_LIST_ACCESSOR]', -); +export const TUI_DATA_LIST_ACCESSOR = tuiCreateToken(); export function tuiAsDataListAccessor(accessor: Type): Provider { return tuiProvide(TUI_DATA_LIST_ACCESSOR, accessor); @@ -48,9 +46,7 @@ export function tuiAsDataListAccessor(accessor: Type): Prov /** * DataList controller */ -export const TUI_DATA_LIST_HOST = new InjectionToken>( - '[TUI_DATA_LIST_HOST]', -); +export const TUI_DATA_LIST_HOST = tuiCreateToken>(); export function tuiAsDataListHost(host: Type>): Provider { return tuiProvide(TUI_DATA_LIST_HOST, host); diff --git a/projects/core/directives/dropdown/dropdown.providers.ts b/projects/core/directives/dropdown/dropdown.providers.ts index 8e3d6cc95847..e4310c157bdf 100644 --- a/projects/core/directives/dropdown/dropdown.providers.ts +++ b/projects/core/directives/dropdown/dropdown.providers.ts @@ -1,6 +1,8 @@ import type {Type} from '@angular/core'; -import {InjectionToken} from '@angular/core'; -import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils/miscellaneous'; +import { + tuiCreateToken, + tuiCreateTokenFromFactory, +} from '@taiga-ui/cdk/utils/miscellaneous'; import {TuiDropdownComponent} from './dropdown.component'; @@ -11,4 +13,4 @@ export const TUI_DROPDOWN_COMPONENT = tuiCreateTokenFromFactory>( () => TuiDropdownComponent, ); -export const TUI_DROPDOWN_CONTEXT = new InjectionToken>(''); +export const TUI_DROPDOWN_CONTEXT = tuiCreateToken>(); diff --git a/projects/core/tokens/dark-mode.ts b/projects/core/tokens/dark-mode.ts index 128884211b8e..bb48e8295f93 100644 --- a/projects/core/tokens/dark-mode.ts +++ b/projects/core/tokens/dark-mode.ts @@ -1,49 +1,50 @@ -import {effect, inject, InjectionToken, signal, type WritableSignal} from '@angular/core'; +import {effect, inject, signal, type WritableSignal} from '@angular/core'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import {WA_LOCAL_STORAGE, WA_WINDOW} from '@ng-web-apis/common'; -import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; +import { + tuiCreateToken, + tuiCreateTokenFromFactory, +} from '@taiga-ui/cdk/utils/miscellaneous'; import {filter, fromEvent} from 'rxjs'; export const TUI_DARK_MODE_DEFAULT_KEY = 'tuiDark'; export const TUI_DARK_MODE_KEY = tuiCreateToken(TUI_DARK_MODE_DEFAULT_KEY); -export const TUI_DARK_MODE = new InjectionToken< +export const TUI_DARK_MODE = tuiCreateTokenFromFactory< WritableSignal & {reset(): void} ->('', { - factory: () => { - let automatic = true; +>(() => { + let automatic = true; - const storage = inject(WA_LOCAL_STORAGE); - const key = inject(TUI_DARK_MODE_KEY); - const saved = storage.getItem(key); - const media = inject(WA_WINDOW).matchMedia('(prefers-color-scheme: dark)'); - const result = signal(Boolean((saved && JSON.parse(saved)) ?? media.matches)); + const storage = inject(WA_LOCAL_STORAGE); + const key = inject(TUI_DARK_MODE_KEY); + const saved = storage.getItem(key); + const media = inject(WA_WINDOW).matchMedia('(prefers-color-scheme: dark)'); + const result = signal(Boolean((saved && JSON.parse(saved)) ?? media.matches)); - fromEvent(media, 'change') - .pipe( - filter(() => !storage.getItem(key)), - takeUntilDestroyed(), - ) - .subscribe(() => { - automatic = true; - result.set(media.matches); - }); + fromEvent(media, 'change') + .pipe( + filter(() => !storage.getItem(key)), + takeUntilDestroyed(), + ) + .subscribe(() => { + automatic = true; + result.set(media.matches); + }); - effect(() => { - const value = String(result()); + effect(() => { + const value = String(result()); - if (automatic) { - automatic = false; - } else { - storage.setItem(key, value); - } - }); + if (automatic) { + automatic = false; + } else { + storage.setItem(key, value); + } + }); - return Object.assign(result, { - reset: () => { - storage.removeItem(key); - automatic = true; - result.set(media.matches); - }, - }); - }, + return Object.assign(result, { + reset: () => { + storage.removeItem(key); + automatic = true; + result.set(media.matches); + }, + }); }); diff --git a/projects/demo/src/modules/app/version-manager/version-manager.providers.ts b/projects/demo/src/modules/app/version-manager/version-manager.providers.ts index 807403999440..74bda23cfefa 100644 --- a/projects/demo/src/modules/app/version-manager/version-manager.providers.ts +++ b/projects/demo/src/modules/app/version-manager/version-manager.providers.ts @@ -1,14 +1,11 @@ import {DOCUMENT} from '@angular/common'; import type {Provider} from '@angular/core'; -import {InjectionToken} from '@angular/core'; -import {TUI_BASE_HREF} from '@taiga-ui/cdk'; +import {TUI_BASE_HREF, tuiCreateToken} from '@taiga-ui/cdk'; import type {TuiVersionMeta} from './versions.constants'; import {TUI_VERSIONS_META_MAP} from './versions.constants'; -export const TUI_SELECTED_VERSION_META = new InjectionToken( - '[TUI_SELECTED_VERSION_META]: Meta information about selected version of Taiga docs', -); +export const TUI_SELECTED_VERSION_META = tuiCreateToken(); export const TUI_VERSION_MANAGER_PROVIDERS: Provider[] = [ { diff --git a/projects/demo/src/modules/components/abstract/abstract-props-accessor.ts b/projects/demo/src/modules/components/abstract/abstract-props-accessor.ts index 44854fb3859f..5d2c591e158e 100644 --- a/projects/demo/src/modules/components/abstract/abstract-props-accessor.ts +++ b/projects/demo/src/modules/components/abstract/abstract-props-accessor.ts @@ -1,8 +1,6 @@ -import {InjectionToken} from '@angular/core'; +import {tuiCreateToken} from '@taiga-ui/cdk'; import type {TuiSupportingDocumentationComponent} from './supporting-documentation-component'; export const ABSTRACT_PROPS_ACCESSOR = - new InjectionToken( - '[ABSTRACT_PROPS_ACCESSOR]: Component extends AbstractExample class', - ); + tuiCreateToken(); diff --git a/projects/i18n/tokens/language-loader.ts b/projects/i18n/tokens/language-loader.ts index 735cc0346931..ddcf7cfde769 100644 --- a/projects/i18n/tokens/language-loader.ts +++ b/projects/i18n/tokens/language-loader.ts @@ -1,4 +1,4 @@ -import {InjectionToken} from '@angular/core'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import type {TuiLanguageLoader} from '@taiga-ui/i18n/types'; /** @@ -6,6 +6,4 @@ import type {TuiLanguageLoader} from '@taiga-ui/i18n/types'; * @note: cannot be transferred to a shared file * ReferenceError: Cannot access 'TUI_LANGUAGE_LOADER' before initialization */ -export const TUI_LANGUAGE_LOADER = new InjectionToken( - '[TUI_LANGUAGE_LOADER]', -); +export const TUI_LANGUAGE_LOADER = tuiCreateToken(); diff --git a/projects/i18n/tokens/language-storage-key.ts b/projects/i18n/tokens/language-storage-key.ts index 8fa121141629..668f9b6557a2 100644 --- a/projects/i18n/tokens/language-storage-key.ts +++ b/projects/i18n/tokens/language-storage-key.ts @@ -1,11 +1,6 @@ -import {InjectionToken} from '@angular/core'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; /** * Default key for search value in storage */ -export const TUI_LANGUAGE_STORAGE_KEY = new InjectionToken( - '[TUI_LANGUAGE_STORAGE_KEY]', - { - factory: () => 'tuiLanguage', - }, -); +export const TUI_LANGUAGE_STORAGE_KEY = tuiCreateToken('tuiLanguage'); diff --git a/projects/i18n/tokens/language.ts b/projects/i18n/tokens/language.ts index cdd5de24cbca..a1594cbe1feb 100644 --- a/projects/i18n/tokens/language.ts +++ b/projects/i18n/tokens/language.ts @@ -1,4 +1,5 @@ -import {inject, InjectionToken} from '@angular/core'; +import {inject} from '@angular/core'; +import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils/miscellaneous'; import {TUI_ENGLISH_LANGUAGE} from '@taiga-ui/i18n/languages/english'; import type {TuiLanguage} from '@taiga-ui/i18n/types'; import type {Observable} from 'rxjs'; @@ -7,19 +8,13 @@ import {of} from 'rxjs'; /** * Default Language for Taiga UI libraries i18n */ -export const TUI_DEFAULT_LANGUAGE = new InjectionToken( - '[TUI_DEFAULT_LANGUAGE]', - { - factory: () => TUI_ENGLISH_LANGUAGE, - }, +export const TUI_DEFAULT_LANGUAGE = tuiCreateTokenFromFactory( + () => TUI_ENGLISH_LANGUAGE, ); /** * Language for Taiga UI libraries i18n */ -export const TUI_LANGUAGE = new InjectionToken>( - '[TUI_LANGUAGE]', - { - factory: () => of(inject(TUI_DEFAULT_LANGUAGE)), - }, +export const TUI_LANGUAGE = tuiCreateTokenFromFactory>(() => + of(inject(TUI_DEFAULT_LANGUAGE)), ); diff --git a/projects/kit/components/tabs/tabs.providers.ts b/projects/kit/components/tabs/tabs.providers.ts index a3b02d1b1579..8a250d7f54c3 100644 --- a/projects/kit/components/tabs/tabs.providers.ts +++ b/projects/kit/components/tabs/tabs.providers.ts @@ -1,19 +1,19 @@ import {DOCUMENT} from '@angular/common'; import type {Provider} from '@angular/core'; -import {ChangeDetectorRef, ElementRef, InjectionToken} from '@angular/core'; +import {ChangeDetectorRef, ElementRef} from '@angular/core'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import { MutationObserverService, WA_MUTATION_OBSERVER_INIT, } from '@ng-web-apis/mutation-observer'; import {ResizeObserverService} from '@ng-web-apis/resize-observer'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import {tuiDropdownOptionsProvider} from '@taiga-ui/core/directives/dropdown'; import type {Observable} from 'rxjs'; import {debounceTime, filter, merge, startWith, tap} from 'rxjs'; -export const TUI_TABS_REFRESH = new InjectionToken>( - '[TUI_TABS_REFRESH]', -); +export const TUI_TABS_REFRESH = tuiCreateToken>(); + export const TUI_TABS_PROVIDERS: Provider[] = [ ResizeObserverService, MutationObserverService, diff --git a/projects/kit/components/tree/misc/tree.tokens.ts b/projects/kit/components/tree/misc/tree.tokens.ts index 2df247356916..309c62ff3f27 100644 --- a/projects/kit/components/tree/misc/tree.tokens.ts +++ b/projects/kit/components/tree/misc/tree.tokens.ts @@ -1,4 +1,3 @@ -import {InjectionToken} from '@angular/core'; import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import type {PolymorpheusContent} from '@taiga-ui/polymorpheus'; @@ -8,9 +7,7 @@ import type {TuiTreeAccessor, TuiTreeItemContext, TuiTreeLoader} from './tree.in /** * Controller for tracking value - TuiTreeItemComponent pairs */ -export const TUI_TREE_ACCESSOR = new InjectionToken>( - '[TUI_TREE_ACCESSOR]', -); +export const TUI_TREE_ACCESSOR = tuiCreateToken>(); /** * Controller for expanding the tree @@ -20,7 +17,7 @@ export const TUI_TREE_CONTROLLER = tuiCreateToken(TUI_DEFAULT_TREE_CONTROLLER); /** * A node of a tree view */ -export const TUI_TREE_NODE = new InjectionToken('[TUI_TREE_NODE]'); +export const TUI_TREE_NODE = tuiCreateToken(); /** * A tree node placeholder for loading @@ -30,14 +27,12 @@ export const TUI_TREE_LOADING = tuiCreateToken({}); /** * A tree node starting point */ -export const TUI_TREE_START = new InjectionToken('[TUI_TREE_START]'); +export const TUI_TREE_START = tuiCreateToken(); /** * A service to load tree progressively */ -export const TUI_TREE_LOADER = new InjectionToken>( - '[TUI_TREE_LOADER]', -); +export const TUI_TREE_LOADER = tuiCreateToken>(); /** * Content for a tree item diff --git a/projects/kit/tokens/calendar-date-stream.ts b/projects/kit/tokens/calendar-date-stream.ts index dd427e1cf6f6..7ea6a04d2d22 100644 --- a/projects/kit/tokens/calendar-date-stream.ts +++ b/projects/kit/tokens/calendar-date-stream.ts @@ -1,18 +1,18 @@ -import type {Provider} from '@angular/core'; -import {InjectionToken, Optional, Self} from '@angular/core'; +import type {InjectionToken, Provider} from '@angular/core'; +import {Optional, Self} from '@angular/core'; import {NgControl} from '@angular/forms'; import type {TuiValueTransformer} from '@taiga-ui/cdk/classes'; import type {TuiDay, TuiDayRange, TuiTime} from '@taiga-ui/cdk/date-time'; import {tuiControlValue} from '@taiga-ui/cdk/observables'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import type {Observable} from 'rxjs'; import {map, of} from 'rxjs'; /** * Stream that emits calendar data change */ -export const TUI_CALENDAR_DATE_STREAM = new InjectionToken< - Observable ->('[TUI_CALENDAR_DATE_STREAM]'); +export const TUI_CALENDAR_DATE_STREAM = + tuiCreateToken>(); export function tuiDateStreamWithTransformer( transformer: InjectionToken>, diff --git a/projects/kit/tokens/date-inputs-value-transformers.ts b/projects/kit/tokens/date-inputs-value-transformers.ts index 5348dacc3477..c6efcb2f20f2 100644 --- a/projects/kit/tokens/date-inputs-value-transformers.ts +++ b/projects/kit/tokens/date-inputs-value-transformers.ts @@ -1,33 +1,29 @@ -import {InjectionToken} from '@angular/core'; import type {TuiValueTransformer} from '@taiga-ui/cdk/classes'; import type {TuiDay, TuiDayRange, TuiTime} from '@taiga-ui/cdk/date-time'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; // TODO: Refactor to use `TuiValueTransformer` and add ability to provide it for all controls /** * Control value transformer of TuiDay to custom value format for InputDate* components */ -export const TUI_DATE_VALUE_TRANSFORMER = new InjectionToken< - TuiValueTransformer ->('[TUI_DATE_VALUE_TRANSFORMER]'); +export const TUI_DATE_VALUE_TRANSFORMER = + tuiCreateToken>(); /** * Control value transformer for InputDateRange component */ -export const TUI_DATE_RANGE_VALUE_TRANSFORMER = new InjectionToken< - TuiValueTransformer ->('[TUI_DATE_RANGE_VALUE_TRANSFORMER]'); +export const TUI_DATE_RANGE_VALUE_TRANSFORMER = + tuiCreateToken>(); /** * Control value transformer for InputDateTime component */ -export const TUI_DATE_TIME_VALUE_TRANSFORMER = new InjectionToken< - TuiValueTransformer<[TuiDay | null, TuiTime | null]> ->('[TUI_DATE_TIME_VALUE_TRANSFORMER]'); +export const TUI_DATE_TIME_VALUE_TRANSFORMER = + tuiCreateToken>(); /** * Control value transformer for InputTime component */ -export const TUI_TIME_VALUE_TRANSFORMER = new InjectionToken< - TuiValueTransformer ->('[TUI_TIME_VALUE_TRANSFORMER]'); +export const TUI_TIME_VALUE_TRANSFORMER = + tuiCreateToken>(); diff --git a/projects/kit/tokens/mobile-calendar.ts b/projects/kit/tokens/mobile-calendar.ts index cf2b1dcc1010..c603b37e9dce 100644 --- a/projects/kit/tokens/mobile-calendar.ts +++ b/projects/kit/tokens/mobile-calendar.ts @@ -1,14 +1,13 @@ import type {FactoryProvider, Type} from '@angular/core'; -import {inject, InjectionToken} from '@angular/core'; +import {inject} from '@angular/core'; import {TUI_IS_MOBILE} from '@taiga-ui/cdk/tokens'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import {TUI_DROPDOWN_COMPONENT} from '@taiga-ui/core/directives/dropdown'; /** * A component for mobile data picker */ -export const TUI_MOBILE_CALENDAR = new InjectionToken>( - '[TUI_MOBILE_CALENDAR]', -); +export const TUI_MOBILE_CALENDAR = tuiCreateToken>(); export const TUI_MOBILE_CALENDAR_PROVIDER: FactoryProvider = { provide: TUI_DROPDOWN_COMPONENT, diff --git a/projects/legacy/components/color-selector/color-selector.options.ts b/projects/legacy/components/color-selector/color-selector.options.ts index 60e8341afd98..3519494a6424 100644 --- a/projects/legacy/components/color-selector/color-selector.options.ts +++ b/projects/legacy/components/color-selector/color-selector.options.ts @@ -1,14 +1,11 @@ import type {Provider} from '@angular/core'; -import {InjectionToken} from '@angular/core'; import type {TuiGradientDirection} from '@taiga-ui/cdk/utils/color'; import {tuiCreateToken, tuiProvideOptions} from '@taiga-ui/cdk/utils/miscellaneous'; -export const TUI_COLOR_SELECTOR_MODE_NAMES = new InjectionToken<[string, string]>( - '[TUI_COLOR_SELECTOR_MODE_NAMES]', - { - factory: () => ['Solid color', 'Gradient'], - }, -); +export const TUI_COLOR_SELECTOR_MODE_NAMES = tuiCreateToken<[string, string]>([ + 'Solid color', + 'Gradient', +]); export const TUI_DEFAULT_INPUT_COLORS = new Map([ ['color-black-100', '#909090'], diff --git a/projects/legacy/components/input-number/input-number.component.ts b/projects/legacy/components/input-number/input-number.component.ts index 5d4342264300..5d1ef410a598 100644 --- a/projects/legacy/components/input-number/input-number.component.ts +++ b/projects/legacy/components/input-number/input-number.component.ts @@ -4,7 +4,6 @@ import { Component, ContentChildren, inject, - InjectionToken, Input, ViewChild, } from '@angular/core'; @@ -20,7 +19,7 @@ import {CHAR_HYPHEN, CHAR_MINUS, EMPTY_QUERY} from '@taiga-ui/cdk/constants'; import {tuiWatch} from '@taiga-ui/cdk/observables'; import {TUI_IS_IOS} from '@taiga-ui/cdk/tokens'; import {tuiClamp} from '@taiga-ui/cdk/utils/math'; -import {tuiPure} from '@taiga-ui/cdk/utils/miscellaneous'; +import {tuiCreateToken, tuiPure} from '@taiga-ui/cdk/utils/miscellaneous'; import type {TuiDecimalMode} from '@taiga-ui/core/tokens'; import {TUI_DEFAULT_NUMBER_FORMAT, TUI_NUMBER_FORMAT} from '@taiga-ui/core/tokens'; import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types'; @@ -41,9 +40,8 @@ import {TUI_INPUT_NUMBER_OPTIONS} from './input-number.options'; const DEFAULT_MAX_LENGTH = 18; -export const TUI_NUMBER_VALUE_TRANSFORMER = new InjectionToken< - TuiValueTransformer ->(''); +export const TUI_NUMBER_VALUE_TRANSFORMER = + tuiCreateToken>(); @Component({ standalone: false, diff --git a/projects/legacy/components/sheet/sheet-tokens.ts b/projects/legacy/components/sheet/sheet-tokens.ts index 3aad3e8438c0..1babe0895262 100644 --- a/projects/legacy/components/sheet/sheet-tokens.ts +++ b/projects/legacy/components/sheet/sheet-tokens.ts @@ -1,4 +1,4 @@ -import {InjectionToken} from '@angular/core'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import type {Observable} from 'rxjs'; import type {TuiSheetRequiredProps} from './sheet'; @@ -7,20 +7,16 @@ import type {TuiSheetRequiredProps} from './sheet'; * @deprecated: drop in v5.0 use {@link TuiSheetDialog} * https://taiga-ui.dev/components/sheet-dialog */ -export const TUI_SHEET = new InjectionToken('[TUI_SHEET]'); +export const TUI_SHEET = tuiCreateToken(); /** * @deprecated: drop in v5.0 use {@link TuiSheetDialog} * https://taiga-ui.dev/components/sheet-dialog */ -export const TUI_SHEET_SCROLL = new InjectionToken>( - '[TUI_SHEET_SCROLL]', -); +export const TUI_SHEET_SCROLL = tuiCreateToken>(); /** * @deprecated: drop in v5.0 use {@link TuiSheetDialog} * https://taiga-ui.dev/components/sheet-dialog */ -export const TUI_SHEET_DRAGGED = new InjectionToken>( - '[TUI_SHEET_DRAGGED]', -); +export const TUI_SHEET_DRAGGED = tuiCreateToken>(); diff --git a/projects/legacy/components/svg/svg-options.ts b/projects/legacy/components/svg/svg-options.ts index 52acb9156f23..ef92a05d80ac 100644 --- a/projects/legacy/components/svg/svg-options.ts +++ b/projects/legacy/components/svg/svg-options.ts @@ -1,7 +1,11 @@ import type {FactoryProvider, Provider} from '@angular/core'; -import {InjectionToken, Optional, SkipSelf} from '@angular/core'; +import {Optional, SkipSelf} from '@angular/core'; import type {TuiHandler, TuiSafeHtml, TuiStringHandler} from '@taiga-ui/cdk/types'; -import {tuiCreateTokenFromFactory, tuiIsString} from '@taiga-ui/cdk/utils/miscellaneous'; +import { + tuiCreateToken, + tuiCreateTokenFromFactory, + tuiIsString, +} from '@taiga-ui/cdk/utils/miscellaneous'; import {tuiIconsPathFactory} from '@taiga-ui/legacy/utils'; import {identity} from 'rxjs'; @@ -69,9 +73,7 @@ export const TUI_SVG_OPTIONS = tuiCreateTokenFromFactory(() => ({ * @deprecated: drop in v5.0 use {@link TuiIcon} * https://taiga-ui.dev/components/icon */ -export const TUI_SVG_SRC_INTERCEPTORS = new InjectionToken( - '[TUI_SVG_SRC_INTERCEPTORS]', -); +export const TUI_SVG_SRC_INTERCEPTORS = tuiCreateToken(); /** * @deprecated: drop in v5.0 use {@link TuiIcon} diff --git a/projects/legacy/directives/textfield-controller/textfield-controller.provider.ts b/projects/legacy/directives/textfield-controller/textfield-controller.provider.ts index f51235b81a89..914439e071c8 100644 --- a/projects/legacy/directives/textfield-controller/textfield-controller.provider.ts +++ b/projects/legacy/directives/textfield-controller/textfield-controller.provider.ts @@ -1,7 +1,8 @@ import type {Provider} from '@angular/core'; -import {ChangeDetectorRef, InjectionToken} from '@angular/core'; +import {ChangeDetectorRef} from '@angular/core'; import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; import {tuiWatch} from '@taiga-ui/cdk/observables'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import {TUI_TEXTFIELD_APPEARANCE} from '@taiga-ui/legacy/tokens'; import {merge, NEVER} from 'rxjs'; @@ -29,8 +30,7 @@ import {TUI_TEXTFIELD_PREFIX} from './textfield-prefix.directive'; import type {TuiTextfieldSizeDirective} from './textfield-size.directive'; import {TUI_TEXTFIELD_SIZE} from './textfield-size.directive'; -export const TUI_TEXTFIELD_WATCHED_CONTROLLER = - new InjectionToken('[TUI_TEXTFIELD_WATCHED_CONTROLLER]'); +export const TUI_TEXTFIELD_WATCHED_CONTROLLER = tuiCreateToken(); export const TEXTFIELD_CONTROLLER_PROVIDER: Provider = [ { diff --git a/projects/legacy/tokens/focusable-item-accessor.ts b/projects/legacy/tokens/focusable-item-accessor.ts index 955e15d1269f..6eff0d099662 100644 --- a/projects/legacy/tokens/focusable-item-accessor.ts +++ b/projects/legacy/tokens/focusable-item-accessor.ts @@ -1,6 +1,5 @@ import type {Provider, Type} from '@angular/core'; -import {InjectionToken} from '@angular/core'; -import {tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; +import {tuiCreateToken, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; import type {Observable} from 'rxjs'; /** @@ -22,8 +21,7 @@ export interface TuiFocusableElementAccessor { * @deprecated: drop in v5.0 * A component that can be focused */ -export const TUI_FOCUSABLE_ITEM_ACCESSOR = - new InjectionToken('[TUI_FOCUSABLE_ITEM_ACCESSOR]'); +export const TUI_FOCUSABLE_ITEM_ACCESSOR = tuiCreateToken(); /** * @deprecated: drop in v5.0 diff --git a/projects/legacy/tokens/fonts-ready.ts b/projects/legacy/tokens/fonts-ready.ts index cc4e289897d9..47f9f1498491 100644 --- a/projects/legacy/tokens/fonts-ready.ts +++ b/projects/legacy/tokens/fonts-ready.ts @@ -1,17 +1,14 @@ import {DOCUMENT} from '@angular/common'; -import {inject, InjectionToken} from '@angular/core'; +import {inject} from '@angular/core'; +import {tuiCreateTokenFromFactory} from '@taiga-ui/cdk/utils/miscellaneous'; import type {Observable} from 'rxjs'; import {EMPTY, from, shareReplay} from 'rxjs'; /** * @deprecated: drop in v5.0 */ -export const TUI_FONTS_READY = new InjectionToken>( - '[TUI_FONTS_READY]', - { - factory: () => - from((inject(DOCUMENT) as any).fonts?.ready || EMPTY).pipe( - shareReplay({bufferSize: 1, refCount: false}), - ), - }, +export const TUI_FONTS_READY = tuiCreateTokenFromFactory>(() => + from((inject(DOCUMENT) as any).fonts?.ready || EMPTY).pipe( + shareReplay({bufferSize: 1, refCount: false}), + ), ); diff --git a/projects/legacy/tokens/month-formatter.ts b/projects/legacy/tokens/month-formatter.ts index df31164276dd..b380edbfd312 100644 --- a/projects/legacy/tokens/month-formatter.ts +++ b/projects/legacy/tokens/month-formatter.ts @@ -1,7 +1,7 @@ import type {FactoryProvider} from '@angular/core'; -import {InjectionToken} from '@angular/core'; import type {TuiMonth} from '@taiga-ui/cdk/date-time'; import type {TuiHandler} from '@taiga-ui/cdk/types'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; import {TuiMonthPipe} from '@taiga-ui/core/pipes/month'; import type {Observable} from 'rxjs'; import {map, of} from 'rxjs'; @@ -10,9 +10,8 @@ import {map, of} from 'rxjs'; * @deprecated: drop in v5.0 * A function to get localized formatted month */ -export const TUI_MONTH_FORMATTER = new InjectionToken< - TuiHandler> ->('[TUI_MONTH_FORMATTER]'); +export const TUI_MONTH_FORMATTER = + tuiCreateToken>>(); export const TUI_MONTH_FORMATTER_PROVIDER: FactoryProvider = { provide: TUI_MONTH_FORMATTER, diff --git a/projects/legacy/tokens/sanitizer.ts b/projects/legacy/tokens/sanitizer.ts index 376ee4fdfd4a..d3e99f6e2466 100644 --- a/projects/legacy/tokens/sanitizer.ts +++ b/projects/legacy/tokens/sanitizer.ts @@ -1,8 +1,8 @@ import type {Sanitizer} from '@angular/core'; -import {InjectionToken} from '@angular/core'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; /** * @deprecated: drop in v5.0 * A custom Sanitizer to sanitize source before inlining */ -export const TUI_SANITIZER = new InjectionToken('[TUI_SANITIZER]'); +export const TUI_SANITIZER = tuiCreateToken(); diff --git a/projects/legacy/tokens/textfield-host.ts b/projects/legacy/tokens/textfield-host.ts index ee740e01c61a..1f113952461b 100644 --- a/projects/legacy/tokens/textfield-host.ts +++ b/projects/legacy/tokens/textfield-host.ts @@ -1,6 +1,5 @@ import type {Provider, Type} from '@angular/core'; -import {InjectionToken} from '@angular/core'; -import {tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; +import {tuiCreateToken, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous'; /** * @deprecated: drop in v5.0 @@ -28,9 +27,7 @@ export interface TuiTextfieldHost { * @deprecated: drop in v5.0 * An interface to communicate with textfield based controls */ -export const TUI_TEXTFIELD_HOST = new InjectionToken( - '[TUI_TEXTFIELD_HOST]', -); +export const TUI_TEXTFIELD_HOST = tuiCreateToken(); /** * @deprecated: drop in v5.0 diff --git a/projects/legacy/tokens/value-accessor.ts b/projects/legacy/tokens/value-accessor.ts index bc5b0ed843a8..77fbf58ea432 100644 --- a/projects/legacy/tokens/value-accessor.ts +++ b/projects/legacy/tokens/value-accessor.ts @@ -1,10 +1,8 @@ -import {InjectionToken} from '@angular/core'; import type {ControlValueAccessor} from '@angular/forms'; +import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; /** * @deprecated: drop in v5.0 * Buffer token to pass NG_VALUE_ACCESSOR to a different Injector */ -export const TUI_VALUE_ACCESSOR = new InjectionToken( - '[TUI_VALUE_ACCESSOR]', -); +export const TUI_VALUE_ACCESSOR = tuiCreateToken();