From 160d80c1fb0eacfdfe97791278bb83d71feff085 Mon Sep 17 00:00:00 2001 From: Maksim Ivanov Date: Thu, 20 Jun 2024 12:51:38 +0300 Subject: [PATCH] refactor: cleanup addon-doc (#7855) --- projects/addon-doc/README.md | 8 ++--- projects/addon-doc/addon-doc.module.ts | 33 ----------------- .../components/internal/header/index.ts | 2 +- .../components/internal/see-also/index.ts | 2 +- .../source-code/source-code.component.ts | 2 +- .../components/language-switcher/index.ts | 6 ++-- .../tests/language-switcher.component.spec.ts | 14 ++++---- .../components/main/main.component.ts | 4 +-- .../components/page/page.component.ts | 8 ++--- projects/addon-doc/index.ts | 35 ++++++++++++++++++- .../demo/src/modules/app/app.component.ts | 4 +-- .../src/modules/customization/i18n/index.ts | 4 +-- .../switch/language-switcher.providers.ts | 4 +-- .../i18n/switch/language-switcher.service.ts | 6 ++-- 14 files changed, 67 insertions(+), 65 deletions(-) delete mode 100644 projects/addon-doc/addon-doc.module.ts diff --git a/projects/addon-doc/README.md b/projects/addon-doc/README.md index ee639af91f1d..ef8bf0d16bff 100644 --- a/projects/addon-doc/README.md +++ b/projects/addon-doc/README.md @@ -57,7 +57,7 @@ npm i @taiga-ui/addon-doc }, ], }) - export class AppComponent {} + export class App {} ``` 3. Configure documentation providers: @@ -103,7 +103,7 @@ npm i @taiga-ui/addon-doc standalone: true, imports: [TuiAddonDoc, SuperComponent], }) - export class AppComponent {} + export class App {} ``` _Component:_ @@ -113,10 +113,10 @@ npm i @taiga-ui/addon-doc @Component({ standalone: true, - selector: 'super-component', + selector: 'super', templateUrl: './super.component.html', }) - export class SuperComponent { + export class Super { // Keys would be used as tabs for code example readonly example = { // import a file as a string diff --git a/projects/addon-doc/addon-doc.module.ts b/projects/addon-doc/addon-doc.module.ts deleted file mode 100644 index 758369efe466..000000000000 --- a/projects/addon-doc/addon-doc.module.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - TuiDocCode, - TuiDocCopy, - TuiDocDemo, - TuiDocDocumentation, - TuiDocDocumentationPropertyConnector, - TuiDocExample, - TuiDocExampleGetTabsPipe, - TuiDocMain, - TuiDocNavigation, - TuiDocPage, - TuiDocPageTabConnector, - TuiDocTab, - TuiDocTypeReferencePipe, -} from '@taiga-ui/addon-doc/components'; -import {TuiTextCode} from '@taiga-ui/addon-doc/directives'; - -export const TuiAddonDoc = [ - TuiDocCopy, - TuiDocTab, - TuiDocDemo, - TuiDocCode, - TuiDocExample, - TuiDocExampleGetTabsPipe, - TuiDocTypeReferencePipe, - TuiDocDocumentation, - TuiDocDocumentationPropertyConnector, - TuiDocPage, - TuiDocPageTabConnector, - TuiDocNavigation, - TuiDocMain, - TuiTextCode, -] as const; diff --git a/projects/addon-doc/components/internal/header/index.ts b/projects/addon-doc/components/internal/header/index.ts index 5ab3f05c4025..30dd460bf72b 100644 --- a/projects/addon-doc/components/internal/header/index.ts +++ b/projects/addon-doc/components/internal/header/index.ts @@ -26,7 +26,7 @@ import {TuiDocNavigation} from '../../navigation/navigation.component'; styleUrls: ['./index.less'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class TuiDocHeaderComponent { +export class TuiDocHeader { private readonly stream$ = new Subject(); private readonly router = inject(Router); protected readonly icons = inject(TUI_DOC_ICONS); diff --git a/projects/addon-doc/components/internal/see-also/index.ts b/projects/addon-doc/components/internal/see-also/index.ts index 3620ee7126e3..b98691997ffd 100644 --- a/projects/addon-doc/components/internal/see-also/index.ts +++ b/projects/addon-doc/components/internal/see-also/index.ts @@ -12,7 +12,7 @@ import {TuiLink} from '@taiga-ui/core'; styleUrls: ['./index.less'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class TuiDocSeeAlsoComponent { +export class TuiDocSeeAlso { private readonly pages = inject(TUI_DOC_MAP_PAGES); protected readonly text = inject(TUI_DOC_SEE_ALSO_TEXT); diff --git a/projects/addon-doc/components/internal/source-code/source-code.component.ts b/projects/addon-doc/components/internal/source-code/source-code.component.ts index 9616a8c72452..d0f4cf058562 100644 --- a/projects/addon-doc/components/internal/source-code/source-code.component.ts +++ b/projects/addon-doc/components/internal/source-code/source-code.component.ts @@ -16,7 +16,7 @@ import {PolymorpheusOutlet, PolymorpheusTemplate} from '@taiga-ui/polymorpheus'; templateUrl: './source-code.template.html', changeDetection: ChangeDetectionStrategy.OnPush, }) -export class TuiDocSourceCodeComponent { +export class TuiDocSourceCode { protected readonly icons = inject(TUI_DOC_ICONS); protected readonly sourceCode = inject(TUI_DOC_SOURCE_CODE); protected readonly text = inject(TUI_DOC_SOURCE_CODE_TEXT); diff --git a/projects/addon-doc/components/language-switcher/index.ts b/projects/addon-doc/components/language-switcher/index.ts index 027e51fa5f83..22e5420b8418 100644 --- a/projects/addon-doc/components/language-switcher/index.ts +++ b/projects/addon-doc/components/language-switcher/index.ts @@ -3,7 +3,7 @@ import {ChangeDetectionStrategy, Component, inject} from '@angular/core'; import {FormControl, ReactiveFormsModule} from '@angular/forms'; import {TuiDataList, TuiFlagPipe} from '@taiga-ui/core'; import type {TuiCountryIsoCode, TuiLanguageName} from '@taiga-ui/i18n'; -import {TuiLanguageSwitcher} from '@taiga-ui/i18n'; +import {TuiLanguageSwitcherService} from '@taiga-ui/i18n'; import {TuiSelectModule} from '@taiga-ui/legacy'; @Component({ @@ -21,8 +21,8 @@ import {TuiSelectModule} from '@taiga-ui/legacy'; styleUrls: ['./index.less'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class TuiLanguageSwitcherComponent { - protected readonly switcher = inject(TuiLanguageSwitcher); +export class TuiLanguageSwitcher { + protected readonly switcher = inject(TuiLanguageSwitcherService); protected readonly language = new FormControl(capitalize(this.switcher.language)); public readonly flags = new Map([ diff --git a/projects/addon-doc/components/language-switcher/tests/language-switcher.component.spec.ts b/projects/addon-doc/components/language-switcher/tests/language-switcher.component.spec.ts index 0071189e151b..5c681331a8c3 100644 --- a/projects/addon-doc/components/language-switcher/tests/language-switcher.component.spec.ts +++ b/projects/addon-doc/components/language-switcher/tests/language-switcher.component.spec.ts @@ -1,14 +1,14 @@ import type {ComponentFixture} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing'; import {ReactiveFormsModule} from '@angular/forms'; -import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc'; +import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc'; import {TuiDataList, TuiFlagPipe} from '@taiga-ui/core'; -import {TuiLanguageSwitcher} from '@taiga-ui/i18n'; +import {TuiLanguageSwitcherService} from '@taiga-ui/i18n'; import {TuiSelectModule} from '@taiga-ui/legacy'; describe('TuiLanguageSwitcherComponent', () => { - let component: TuiLanguageSwitcherComponent; - let fixture: ComponentFixture; + let component: TuiLanguageSwitcher; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ @@ -16,12 +16,12 @@ describe('TuiLanguageSwitcherComponent', () => { ReactiveFormsModule, TuiSelectModule, TuiDataList, - TuiLanguageSwitcherComponent, + TuiLanguageSwitcher, ], - providers: [TuiLanguageSwitcher], + providers: [TuiLanguageSwitcherService], }).compileComponents(); - fixture = TestBed.createComponent(TuiLanguageSwitcherComponent); + fixture = TestBed.createComponent(TuiLanguageSwitcher); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/projects/addon-doc/components/main/main.component.ts b/projects/addon-doc/components/main/main.component.ts index 7818023aaac2..afbd1fb14798 100644 --- a/projects/addon-doc/components/main/main.component.ts +++ b/projects/addon-doc/components/main/main.component.ts @@ -11,7 +11,7 @@ import {TUI_DOC_ICONS} from '@taiga-ui/addon-doc/tokens'; import {TuiSwipeService} from '@taiga-ui/cdk'; import {TuiButton, TuiRoot} from '@taiga-ui/core'; -import {TuiDocHeaderComponent} from '../internal/header'; +import {TuiDocHeader} from '../internal/header'; import {TuiDocNavigation} from '../navigation/navigation.component'; @Component({ @@ -22,7 +22,7 @@ import {TuiDocNavigation} from '../navigation/navigation.component'; AsyncPipe, RouterOutlet, TuiButton, - TuiDocHeaderComponent, + TuiDocHeader, TuiDocNavigation, ], templateUrl: './main.template.html', diff --git a/projects/addon-doc/components/page/page.component.ts b/projects/addon-doc/components/page/page.component.ts index ea4cb1573330..18fbf898ad81 100644 --- a/projects/addon-doc/components/page/page.component.ts +++ b/projects/addon-doc/components/page/page.component.ts @@ -13,8 +13,8 @@ import {EMPTY_QUERY, TuiItem, TuiReplacePipe} from '@taiga-ui/cdk'; import {TuiAutoColorPipe} from '@taiga-ui/core'; import {TuiChip, TuiTabDirective, TuiTabsWithMoreComponent} from '@taiga-ui/kit'; -import {TuiDocSeeAlsoComponent} from '../internal/see-also'; -import {TuiDocSourceCodeComponent} from '../internal/source-code/source-code.component'; +import {TuiDocSeeAlso} from '../internal/see-also'; +import {TuiDocSourceCode} from '../internal/source-code/source-code.component'; import {PAGE_PROVIDERS, PAGE_SEE_ALSO} from './page.providers'; import {TuiDocPageTabConnector} from './page-tab.directive'; @@ -32,8 +32,8 @@ import {TuiDocPageTabConnector} from './page-tab.directive'; RouterLink, RouterLinkActive, TuiReplacePipe, - TuiDocSourceCodeComponent, - TuiDocSeeAlsoComponent, + TuiDocSourceCode, + TuiDocSeeAlso, NgTemplateOutlet, ], templateUrl: './page.template.html', diff --git a/projects/addon-doc/index.ts b/projects/addon-doc/index.ts index 10135b07b112..24bf8bf64b23 100644 --- a/projects/addon-doc/index.ts +++ b/projects/addon-doc/index.ts @@ -1,4 +1,37 @@ -export * from './addon-doc.module'; +import { + TuiDocCode, + TuiDocCopy, + TuiDocDemo, + TuiDocDocumentation, + TuiDocDocumentationPropertyConnector, + TuiDocExample, + TuiDocExampleGetTabsPipe, + TuiDocMain, + TuiDocNavigation, + TuiDocPage, + TuiDocPageTabConnector, + TuiDocTab, + TuiDocTypeReferencePipe, +} from '@taiga-ui/addon-doc/components'; +import {TuiTextCode} from '@taiga-ui/addon-doc/directives'; + +export const TuiAddonDoc = [ + TuiDocCopy, + TuiDocTab, + TuiDocDemo, + TuiDocCode, + TuiDocExample, + TuiDocExampleGetTabsPipe, + TuiDocTypeReferencePipe, + TuiDocDocumentation, + TuiDocDocumentationPropertyConnector, + TuiDocPage, + TuiDocPageTabConnector, + TuiDocNavigation, + TuiDocMain, + TuiTextCode, +] as const; + export * from '@taiga-ui/addon-doc/components'; export * from '@taiga-ui/addon-doc/directives'; export * from '@taiga-ui/addon-doc/pipes'; diff --git a/projects/demo/src/modules/app/app.component.ts b/projects/demo/src/modules/app/app.component.ts index 3ce2c8248fdb..41a84adcae8e 100644 --- a/projects/demo/src/modules/app/app.component.ts +++ b/projects/demo/src/modules/app/app.component.ts @@ -7,7 +7,7 @@ import {DemoRoute} from '@demo/routes'; import {TuiDemo} from '@demo/utils'; import {LOCAL_STORAGE} from '@ng-web-apis/common'; import {ResizeObserverService} from '@ng-web-apis/resize-observer'; -import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc'; +import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc'; import {TuiSheetModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy'; import {distinctUntilChanged, filter, map} from 'rxjs'; @@ -22,7 +22,7 @@ import {TUI_VERSION_MANAGER_PROVIDERS} from './version-manager/version-manager.p selector: 'app', imports: [ TuiDemo, - TuiLanguageSwitcherComponent, + TuiLanguageSwitcher, VersionManager, CustomHost, TuiTextfieldControllerModule, diff --git a/projects/demo/src/modules/customization/i18n/index.ts b/projects/demo/src/modules/customization/i18n/index.ts index 232987d204fb..79203135c63b 100644 --- a/projects/demo/src/modules/customization/i18n/index.ts +++ b/projects/demo/src/modules/customization/i18n/index.ts @@ -1,13 +1,13 @@ import {Component} from '@angular/core'; import {changeDetection} from '@demo/emulate/change-detection'; import {TuiDemo} from '@demo/utils'; -import {TuiLanguageSwitcherComponent} from '@taiga-ui/addon-doc'; +import {TuiLanguageSwitcher} from '@taiga-ui/addon-doc'; import {TuiLink} from '@taiga-ui/core'; import {from, map} from 'rxjs'; @Component({ standalone: true, - imports: [TuiDemo, TuiLink, TuiLanguageSwitcherComponent], + imports: [TuiDemo, TuiLink, TuiLanguageSwitcher], templateUrl: './index.html', changeDetection, }) diff --git a/projects/i18n/switch/language-switcher.providers.ts b/projects/i18n/switch/language-switcher.providers.ts index e49fbc5dad18..686ca12af388 100644 --- a/projects/i18n/switch/language-switcher.providers.ts +++ b/projects/i18n/switch/language-switcher.providers.ts @@ -2,7 +2,7 @@ import type {Provider} from '@angular/core'; import type {TuiLanguageLoader} from '@taiga-ui/i18n/interfaces'; import {TUI_LANGUAGE, TUI_LANGUAGE_LOADER} from '@taiga-ui/i18n/tokens'; -import {TuiLanguageSwitcher} from './language-switcher.service'; +import {TuiLanguageSwitcherService} from './language-switcher.service'; export function tuiLanguageSwitcher(loader: TuiLanguageLoader): Provider[] { return [ @@ -12,7 +12,7 @@ export function tuiLanguageSwitcher(loader: TuiLanguageLoader): Provider[] { }, { provide: TUI_LANGUAGE, - useExisting: TuiLanguageSwitcher, + useExisting: TuiLanguageSwitcherService, }, ]; } diff --git a/projects/i18n/switch/language-switcher.service.ts b/projects/i18n/switch/language-switcher.service.ts index 4eb48cf3ce44..5f7285d27a79 100644 --- a/projects/i18n/switch/language-switcher.service.ts +++ b/projects/i18n/switch/language-switcher.service.ts @@ -11,8 +11,10 @@ import {BehaviorSubject, of} from 'rxjs'; import {tuiAsyncLoadLanguage} from './utils'; -@Injectable({providedIn: 'root'}) -export class TuiLanguageSwitcher extends BehaviorSubject> { +@Injectable({ + providedIn: 'root', +}) +export class TuiLanguageSwitcherService extends BehaviorSubject> { private readonly fallback = inject(TUI_DEFAULT_LANGUAGE); private readonly key = inject(TUI_LANGUAGE_STORAGE_KEY); private readonly storage = inject(LOCAL_STORAGE);