From d6e75a00ec402c4dadbc95fb5f77bb7e41c23c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Sat, 11 Nov 2023 15:42:06 +0800 Subject: [PATCH] perf(*): support standalone (#1694) --- packages/abc/hotkey/hotkey.directive.ts | 2 +- packages/abc/hotkey/hotkey.module.ts | 2 +- packages/abc/let/let.directive.ts | 2 +- packages/abc/let/let.module.ts | 2 +- packages/abc/observers/observer-size.ts | 5 ++-- packages/abc/xlsx/xlsx.directive.ts | 3 ++- packages/abc/xlsx/xlsx.module.ts | 4 +-- packages/abc/zip/index.en-US.md | 1 - packages/abc/zip/index.zh-CN.md | 1 - packages/abc/zip/public_api.ts | 1 - packages/abc/zip/zip.module.ts | 7 ------ packages/abc/zip/zip.spec.ts | 2 -- .../theme/theme-btn/theme-btn.component.html | 4 ++- .../theme/theme-btn/theme-btn.component.ts | 25 ++++++++++++------- packages/theme/theme-btn/theme-btn.module.ts | 11 ++------ packages/util/pipes/currency/cny.pipe.ts | 2 +- packages/util/pipes/currency/mega.pipe.ts | 2 +- packages/util/pipes/currency/module.ts | 2 +- packages/util/pipes/currency/price.pipe.ts | 2 +- packages/util/pipes/filter/filter.pipe.ts | 2 +- packages/util/pipes/filter/module.ts | 2 +- packages/util/pipes/format/mask.pipe.ts | 2 +- packages/util/pipes/format/module.ts | 2 +- src/app/core/code/files/delon-abc.module.ts | 2 -- 24 files changed, 39 insertions(+), 51 deletions(-) delete mode 100644 packages/abc/zip/zip.module.ts diff --git a/packages/abc/hotkey/hotkey.directive.ts b/packages/abc/hotkey/hotkey.directive.ts index 1ca9981d4..914f4d78d 100644 --- a/packages/abc/hotkey/hotkey.directive.ts +++ b/packages/abc/hotkey/hotkey.directive.ts @@ -3,7 +3,7 @@ import { Directive, ElementRef, Input, NgZone, OnDestroy } from '@angular/core'; import { install, uninstall } from '@github/hotkey'; -@Directive({ selector: '[hotkey]' }) +@Directive({ selector: '[hotkey]', standalone: true }) export class HotkeyDirective implements OnDestroy { /** * Specify [hotkey format](https://github.com/github/hotkey#hotkey-string-format) diff --git a/packages/abc/hotkey/hotkey.module.ts b/packages/abc/hotkey/hotkey.module.ts index f63cfc3b1..2aa068362 100644 --- a/packages/abc/hotkey/hotkey.module.ts +++ b/packages/abc/hotkey/hotkey.module.ts @@ -5,7 +5,7 @@ import { HotkeyDirective } from './hotkey.directive'; const DIRECTIVES = [HotkeyDirective]; @NgModule({ - declarations: DIRECTIVES, + imports: DIRECTIVES, exports: DIRECTIVES }) export class HotkeyModule {} diff --git a/packages/abc/let/let.directive.ts b/packages/abc/let/let.directive.ts index a9037f179..24e72a079 100644 --- a/packages/abc/let/let.directive.ts +++ b/packages/abc/let/let.directive.ts @@ -14,7 +14,7 @@ export class LetContext { } } -@Directive({ selector: '[let]' }) +@Directive({ selector: '[let]', standalone: true }) export class LetDirective { @Input({ required: true }) let!: T; diff --git a/packages/abc/let/let.module.ts b/packages/abc/let/let.module.ts index 2aa1707e9..b9199e5f0 100644 --- a/packages/abc/let/let.module.ts +++ b/packages/abc/let/let.module.ts @@ -5,7 +5,7 @@ import { LetDirective } from './let.directive'; const DIRECTIVES = [LetDirective]; @NgModule({ - declarations: DIRECTIVES, + imports: DIRECTIVES, exports: DIRECTIVES }) export class LetModule {} diff --git a/packages/abc/observers/observer-size.ts b/packages/abc/observers/observer-size.ts index a094874bf..3d81d96a9 100644 --- a/packages/abc/observers/observer-size.ts +++ b/packages/abc/observers/observer-size.ts @@ -80,7 +80,8 @@ export class SizeObserver implements OnDestroy { @Directive({ selector: '[observeSize]', - exportAs: 'observeSize' + exportAs: 'observeSize', + standalone: true }) export class ObserverSize implements AfterViewInit, OnDestroy { private _sub$: Subscription | null = null; @@ -117,6 +118,6 @@ export class ObserverSize implements AfterViewInit, OnDestroy { @NgModule({ exports: [ObserverSize], - declarations: [ObserverSize] + imports: [ObserverSize] }) export class ObserversModule {} diff --git a/packages/abc/xlsx/xlsx.directive.ts b/packages/abc/xlsx/xlsx.directive.ts index f3c9e7e43..44babf260 100644 --- a/packages/abc/xlsx/xlsx.directive.ts +++ b/packages/abc/xlsx/xlsx.directive.ts @@ -8,7 +8,8 @@ import { XlsxExportOptions } from './xlsx.types'; exportAs: 'xlsx', host: { '(click)': '_click()' - } + }, + standalone: true }) export class XlsxDirective { @Input('xlsx') data!: XlsxExportOptions; diff --git a/packages/abc/xlsx/xlsx.module.ts b/packages/abc/xlsx/xlsx.module.ts index 1e8cf9487..79c83be82 100644 --- a/packages/abc/xlsx/xlsx.module.ts +++ b/packages/abc/xlsx/xlsx.module.ts @@ -1,4 +1,3 @@ -import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { XlsxDirective } from './xlsx.directive'; @@ -6,8 +5,7 @@ import { XlsxDirective } from './xlsx.directive'; const COMPONENTS = [XlsxDirective]; @NgModule({ - imports: [CommonModule], - declarations: COMPONENTS, + imports: [COMPONENTS], exports: COMPONENTS }) export class XlsxModule {} diff --git a/packages/abc/zip/index.en-US.md b/packages/abc/zip/index.en-US.md index 0eb07913f..8378170db 100644 --- a/packages/abc/zip/index.en-US.md +++ b/packages/abc/zip/index.en-US.md @@ -4,7 +4,6 @@ title: zip order: 7 subtitle: Zip cols: 1 -module: import { ZipModule } from '@delon/abc/zip'; --- A Zip file operation based on [jszip](http://stuk.github.io/jszip/). diff --git a/packages/abc/zip/index.zh-CN.md b/packages/abc/zip/index.zh-CN.md index cc0de91d7..6a673a477 100644 --- a/packages/abc/zip/index.zh-CN.md +++ b/packages/abc/zip/index.zh-CN.md @@ -4,7 +4,6 @@ title: zip order: 7 subtitle: Zip 操作 cols: 1 -module: import { ZipModule } from '@delon/abc/zip'; --- 一个基于 [jszip](http://stuk.github.io/jszip/) 的Zip文件操作。 diff --git a/packages/abc/zip/public_api.ts b/packages/abc/zip/public_api.ts index c8925d45e..2cd151259 100644 --- a/packages/abc/zip/public_api.ts +++ b/packages/abc/zip/public_api.ts @@ -1,3 +1,2 @@ export * from './zip.types'; export { ZipService } from './zip.service'; -export { ZipModule } from './zip.module'; diff --git a/packages/abc/zip/zip.module.ts b/packages/abc/zip/zip.module.ts deleted file mode 100644 index 7ea06b910..000000000 --- a/packages/abc/zip/zip.module.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; - -@NgModule({ - imports: [CommonModule] -}) -export class ZipModule {} diff --git a/packages/abc/zip/zip.spec.ts b/packages/abc/zip/zip.spec.ts index 70001e13e..58fff82c1 100644 --- a/packages/abc/zip/zip.spec.ts +++ b/packages/abc/zip/zip.spec.ts @@ -8,7 +8,6 @@ import * as fs from 'file-saver'; import { LazyService } from '@delon/util/other'; import { NzSafeAny } from 'ng-zorro-antd/core/types'; -import { ZipModule } from './zip.module'; import { ZipService } from './zip.service'; let isErrorRequest = false; @@ -45,7 +44,6 @@ describe('abc: zip', () => { let srv: ZipService; function genModule(): void { TestBed.configureTestingModule({ - imports: [ZipModule], providers: [ { provide: HttpClient, useClass: MockHttpClient }, { provide: LazyService, useClass: MockLazyService } diff --git a/packages/theme/theme-btn/theme-btn.component.html b/packages/theme/theme-btn/theme-btn.component.html index af5186d04..4fa4de482 100644 --- a/packages/theme/theme-btn/theme-btn.component.html +++ b/packages/theme/theme-btn/theme-btn.component.html @@ -24,7 +24,9 @@
    -
  • {{ i.text }}
  • + @for (i of types; track $index) { +
  • {{ i.text }}
  • + }
diff --git a/packages/theme/theme-btn/theme-btn.component.ts b/packages/theme/theme-btn/theme-btn.component.ts index e010f2440..aefa7f4a3 100644 --- a/packages/theme/theme-btn/theme-btn.component.ts +++ b/packages/theme/theme-btn/theme-btn.component.ts @@ -20,6 +20,8 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { AlainConfigService } from '@delon/util/config'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; +import { NzDropDownModule } from 'ng-zorro-antd/dropdown'; +import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; export interface ThemeBtnType { key: string; @@ -35,7 +37,9 @@ export const ALAIN_THEME_BTN_KEYS = new InjectionToken('ALAIN_THEME_BTN_ '[class.theme-btn]': `true`, '[class.theme-btn-rtl]': `dir === 'rtl'` }, - changeDetection: ChangeDetectionStrategy.OnPush + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [NzDropDownModule, NzToolTipModule] }) export class ThemeBtnComponent implements OnInit, OnDestroy { private theme = 'default'; @@ -50,6 +54,7 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { @Output() readonly themeChange = new EventEmitter(); private dir$ = this.directionality.change?.pipe(takeUntilDestroyed()); dir: Direction = 'ltr'; + private key = ''; constructor( private renderer: Renderer2, @@ -57,9 +62,11 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { private platform: Platform, @Inject(DOCUMENT) private doc: NzSafeAny, @Optional() private directionality: Directionality, - @Inject(ALAIN_THEME_BTN_KEYS) private KEYS: string, + @Optional() @Inject(ALAIN_THEME_BTN_KEYS) KEYS: string, private cdr: ChangeDetectorRef - ) {} + ) { + this.key = KEYS ?? 'site-theme'; + } ngOnInit(): void { this.dir = this.directionality.value; @@ -74,7 +81,7 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { if (!this.platform.isBrowser) { return; } - this.theme = localStorage.getItem(this.KEYS) || 'default'; + this.theme = localStorage.getItem(this.key) || 'default'; this.updateChartTheme(); this.onThemeChange(this.theme); } @@ -90,26 +97,26 @@ export class ThemeBtnComponent implements OnInit, OnDestroy { this.theme = theme; this.themeChange.emit(theme); this.renderer.setAttribute(this.doc.body, 'data-theme', theme); - const dom = this.doc.getElementById(this.KEYS); + const dom = this.doc.getElementById(this.key); if (dom) { dom.remove(); } - localStorage.removeItem(this.KEYS); + localStorage.removeItem(this.key); if (theme !== 'default') { const el = this.doc.createElement('link'); el.type = 'text/css'; el.rel = 'stylesheet'; - el.id = this.KEYS; + el.id = this.key; el.href = `${this.deployUrl}assets/style.${theme}.css`; - localStorage.setItem(this.KEYS, theme); + localStorage.setItem(this.key, theme); this.doc.body.append(el); } this.updateChartTheme(); } ngOnDestroy(): void { - const el = this.doc.getElementById(this.KEYS); + const el = this.doc.getElementById(this.key); if (el != null) { this.doc.body.removeChild(el); } diff --git a/packages/theme/theme-btn/theme-btn.module.ts b/packages/theme/theme-btn/theme-btn.module.ts index 9fce3a093..0579c1aed 100644 --- a/packages/theme/theme-btn/theme-btn.module.ts +++ b/packages/theme/theme-btn/theme-btn.module.ts @@ -4,19 +4,12 @@ import { NgModule } from '@angular/core'; import { NzDropDownModule } from 'ng-zorro-antd/dropdown'; import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; -import { ALAIN_THEME_BTN_KEYS, ThemeBtnComponent } from './theme-btn.component'; +import { ThemeBtnComponent } from './theme-btn.component'; const COMPONENTS = [ThemeBtnComponent]; @NgModule({ - imports: [CommonModule, NzDropDownModule, NzToolTipModule], - providers: [ - { - provide: ALAIN_THEME_BTN_KEYS, - useValue: 'site-theme' - } - ], - declarations: COMPONENTS, + imports: [CommonModule, NzDropDownModule, NzToolTipModule, ...COMPONENTS], exports: COMPONENTS }) export class ThemeBtnModule {} diff --git a/packages/util/pipes/currency/cny.pipe.ts b/packages/util/pipes/currency/cny.pipe.ts index 2ac99e22f..7a1b48e96 100644 --- a/packages/util/pipes/currency/cny.pipe.ts +++ b/packages/util/pipes/currency/cny.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { CurrencyCNYOptions, CurrencyService } from '@delon/util/format'; -@Pipe({ name: 'cny' }) +@Pipe({ name: 'cny', standalone: true }) export class CurrencyCNYPipe implements PipeTransform { constructor(private srv: CurrencyService) {} diff --git a/packages/util/pipes/currency/mega.pipe.ts b/packages/util/pipes/currency/mega.pipe.ts index 8ef856feb..02dcfd77d 100644 --- a/packages/util/pipes/currency/mega.pipe.ts +++ b/packages/util/pipes/currency/mega.pipe.ts @@ -2,7 +2,7 @@ import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core'; import { CurrencyMegaOptions, CurrencyService } from '@delon/util/format'; -@Pipe({ name: 'mega' }) +@Pipe({ name: 'mega', standalone: true }) export class CurrencyMegaPipe implements PipeTransform { private isCN = false; constructor( diff --git a/packages/util/pipes/currency/module.ts b/packages/util/pipes/currency/module.ts index 220324265..bc655e359 100644 --- a/packages/util/pipes/currency/module.ts +++ b/packages/util/pipes/currency/module.ts @@ -7,7 +7,7 @@ import { CurrencyPricePipe } from './price.pipe'; const PIPES = [CurrencyMegaPipe, CurrencyPricePipe, CurrencyCNYPipe]; @NgModule({ - declarations: PIPES, + imports: PIPES, exports: PIPES }) export class CurrencyPipeModule {} diff --git a/packages/util/pipes/currency/price.pipe.ts b/packages/util/pipes/currency/price.pipe.ts index a361d7b32..35fafb29b 100644 --- a/packages/util/pipes/currency/price.pipe.ts +++ b/packages/util/pipes/currency/price.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { CurrencyFormatOptions, CurrencyService } from '@delon/util/format'; -@Pipe({ name: 'price' }) +@Pipe({ name: 'price', standalone: true }) export class CurrencyPricePipe implements PipeTransform { constructor(private srv: CurrencyService) {} /** diff --git a/packages/util/pipes/filter/filter.pipe.ts b/packages/util/pipes/filter/filter.pipe.ts index 901e28fab..2e64275a0 100644 --- a/packages/util/pipes/filter/filter.pipe.ts +++ b/packages/util/pipes/filter/filter.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; -@Pipe({ name: 'filter' }) +@Pipe({ name: 'filter', standalone: true }) export class FilterPipe implements PipeTransform { /** * Filter array diff --git a/packages/util/pipes/filter/module.ts b/packages/util/pipes/filter/module.ts index 9c6318a69..78be16e26 100644 --- a/packages/util/pipes/filter/module.ts +++ b/packages/util/pipes/filter/module.ts @@ -5,7 +5,7 @@ import { FilterPipe } from './filter.pipe'; const PIPES = [FilterPipe]; @NgModule({ - declarations: PIPES, + imports: PIPES, exports: PIPES }) export class FilterPipeModule {} diff --git a/packages/util/pipes/format/mask.pipe.ts b/packages/util/pipes/format/mask.pipe.ts index 28a505f6a..86f38ea56 100644 --- a/packages/util/pipes/format/mask.pipe.ts +++ b/packages/util/pipes/format/mask.pipe.ts @@ -2,7 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core'; import { formatMask, FormatMaskOption } from '@delon/util/format'; -@Pipe({ name: 'mask' }) +@Pipe({ name: 'mask', standalone: true }) export class FormatMaskPipe implements PipeTransform { /** * Format mask diff --git a/packages/util/pipes/format/module.ts b/packages/util/pipes/format/module.ts index a27652255..a7490c994 100644 --- a/packages/util/pipes/format/module.ts +++ b/packages/util/pipes/format/module.ts @@ -5,7 +5,7 @@ import { FormatMaskPipe } from './mask.pipe'; const PIPES = [FormatMaskPipe]; @NgModule({ - declarations: PIPES, + imports: PIPES, exports: PIPES }) export class FormatPipeModule {} diff --git a/src/app/core/code/files/delon-abc.module.ts b/src/app/core/code/files/delon-abc.module.ts index 082f6b9f5..d23bf063d 100644 --- a/src/app/core/code/files/delon-abc.module.ts +++ b/src/app/core/code/files/delon-abc.module.ts @@ -28,7 +28,6 @@ import { SVModule } from '@delon/abc/sv'; import { TagSelectModule } from '@delon/abc/tag-select'; import { MediaModule } from '@delon/abc/media'; import { XlsxModule } from '@delon/abc/xlsx'; -import { ZipModule } from '@delon/abc/zip'; import { OnboardingModule } from '@delon/abc/onboarding'; import { LetModule } from '@delon/abc/let'; import { AutoFocusModule } from '@delon/abc/auto-focus'; @@ -52,7 +51,6 @@ const MODULES = [ ReuseTabModule, FullContentModule, XlsxModule, - ZipModule, LodopModule, QuickMenuModule, QRModule,