-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
173 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TuiCodeEditor>( | ||
'[TUI_DOC_CODE_EDITOR]', | ||
); | ||
export const TUI_DOC_CODE_EDITOR = tuiCreateToken<TuiCodeEditor>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Observable<DOMRect>>( | ||
'[TUI_WINDOW_SIZE]', | ||
{ | ||
factory: () => { | ||
const w = inject(WA_WINDOW); | ||
export const TUI_WINDOW_SIZE = tuiCreateTokenFromFactory<Observable<DOMRect>>(() => { | ||
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}), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean> & {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); | ||
}, | ||
}); | ||
}); |
7 changes: 2 additions & 5 deletions
7
projects/demo/src/modules/app/version-manager/version-manager.providers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
projects/demo/src/modules/components/abstract/abstract-props-accessor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TuiSupportingDocumentationComponent>( | ||
'[ABSTRACT_PROPS_ACCESSOR]: Component extends AbstractExample class', | ||
); | ||
tuiCreateToken<TuiSupportingDocumentationComponent>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {tuiCreateToken} from '@taiga-ui/cdk/utils/miscellaneous'; | ||
import type {TuiLanguageLoader} from '@taiga-ui/i18n/types'; | ||
|
||
/** | ||
* Webpack chunk loader for Taiga UI libraries i18n | ||
* @note: cannot be transferred to a shared file | ||
* ReferenceError: Cannot access 'TUI_LANGUAGE_LOADER' before initialization | ||
*/ | ||
export const TUI_LANGUAGE_LOADER = new InjectionToken<TuiLanguageLoader>( | ||
'[TUI_LANGUAGE_LOADER]', | ||
); | ||
export const TUI_LANGUAGE_LOADER = tuiCreateToken<TuiLanguageLoader>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>( | ||
'[TUI_LANGUAGE_STORAGE_KEY]', | ||
{ | ||
factory: () => 'tuiLanguage', | ||
}, | ||
); | ||
export const TUI_LANGUAGE_STORAGE_KEY = tuiCreateToken<string>('tuiLanguage'); |
Oops, something went wrong.