From 920b5abc240761a2248feaa45d8f2fd046177f19 Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 11 Mar 2024 16:10:50 +0800 Subject: [PATCH] refactor(abc:cell): widget `data` type changed to CellTextResult MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Breaking Changes: 为了保持数据处理结果的统一性,将小部件的 `data` 类型由原来的 `CellWidgetData` 变更为 `CellTextResult` 以此来保证数据为处理后的结果。 --- angular.json | 1 + packages/abc/cell/cell-host.directive.ts | 6 +++--- packages/abc/cell/cell.component.ts | 13 +++---------- packages/abc/cell/cell.spec.ts | 6 +++--- packages/abc/cell/cell.types.ts | 7 +------ packages/abc/cell/index.en-US.md | 16 +++++++++------- packages/abc/cell/index.zh-CN.md | 16 +++++++++------- src/app/shared/cell-widget/test.ts | 11 +++++------ 8 files changed, 34 insertions(+), 42 deletions(-) diff --git a/angular.json b/angular.json index 10aa310e6..a52077a6d 100644 --- a/angular.json +++ b/angular.json @@ -155,6 +155,7 @@ "include": [ "./test.ts", // "**/st.spec.ts" + // "**/st/**/*.spec.ts" "**/*.spec.ts" ] } diff --git a/packages/abc/cell/cell-host.directive.ts b/packages/abc/cell/cell-host.directive.ts index 226e0dac3..84627a272 100644 --- a/packages/abc/cell/cell-host.directive.ts +++ b/packages/abc/cell/cell-host.directive.ts @@ -3,7 +3,7 @@ import { Directive, Input, OnInit, Type, ViewContainerRef, inject } from '@angul import { warn } from '@delon/util/other'; import { CellService } from './cell.service'; -import { CellWidgetData } from './cell.types'; +import { CellTextResult } from './cell.types'; @Directive({ selector: '[cell-widget-host]', @@ -13,7 +13,7 @@ export class CellHostDirective implements OnInit { private readonly srv = inject(CellService); private readonly viewContainerRef = inject(ViewContainerRef); - @Input() data!: CellWidgetData; + @Input() data!: CellTextResult; ngOnInit(): void { const widget = this.data.options!.widget!; @@ -27,6 +27,6 @@ export class CellHostDirective implements OnInit { this.viewContainerRef.clear(); const componentRef = this.viewContainerRef.createComponent(componentType); - (componentRef.instance as { data: CellWidgetData }).data = this.data; + (componentRef.instance as { data: CellTextResult }).data = this.data; } } diff --git a/packages/abc/cell/cell.component.ts b/packages/abc/cell/cell.component.ts index 1e9cab8f4..940ca1dd9 100644 --- a/packages/abc/cell/cell.component.ts +++ b/packages/abc/cell/cell.component.ts @@ -33,7 +33,7 @@ import { NzTooltipDirective } from 'ng-zorro-antd/tooltip'; import { CellHostDirective } from './cell-host.directive'; import { CellService } from './cell.service'; -import type { CellDefaultText, CellOptions, CellTextResult, CellValue, CellWidgetData } from './cell.types'; +import type { CellDefaultText, CellOptions, CellTextResult, CellValue } from './cell.types'; @Component({ selector: 'cell, [cell]', @@ -59,10 +59,10 @@ import type { CellDefaultText, CellOptions, CellTextResult, CellValue, CellWidge } @case ('badge') { - + } @case ('widget') { - + } @case ('img') { @for (i of $any(_text); track $index) { @@ -155,13 +155,6 @@ export class CellComponent implements OnChanges, OnDestroy { return this.res?.safeHtml === 'text'; } - get hostData(): CellWidgetData { - return { - value: this.value, - options: this.srv.fixOptions(this.options) - }; - } - private updateValue(): void { this.destroy$?.unsubscribe(); this.destroy$ = this.srv.get(this.value, this.options).subscribe(res => { diff --git a/packages/abc/cell/cell.spec.ts b/packages/abc/cell/cell.spec.ts index c61a163a0..6b36ef8b6 100644 --- a/packages/abc/cell/cell.spec.ts +++ b/packages/abc/cell/cell.spec.ts @@ -15,7 +15,7 @@ import { NzTooltipDirective } from 'ng-zorro-antd/tooltip'; import { CellComponent } from './cell.component'; import { CellModule } from './cell.module'; import { CellService } from './cell.service'; -import { CellFuValue, CellOptions, CellWidgetData } from './cell.types'; +import { CellFuValue, CellOptions, CellTextResult } from './cell.types'; import { provideCellWidgets } from './provide'; const DATE = new Date(2022, 0, 1, 1, 2, 3); @@ -354,12 +354,12 @@ describe('abc: cell', () => { }); @Component({ - template: `{{ data.value }}-{{ data.options.widget.data }}` + template: `{{ data.result.text }}-{{ data.options.widget.data }}` }) class TestWidget { static readonly KEY = 'test'; - data!: CellWidgetData; + data!: CellTextResult; } @Component({ diff --git a/packages/abc/cell/cell.types.ts b/packages/abc/cell/cell.types.ts index 82ef96346..5dc2b440e 100644 --- a/packages/abc/cell/cell.types.ts +++ b/packages/abc/cell/cell.types.ts @@ -297,11 +297,6 @@ export interface CellDefaultText { condition?: unknown; } -export interface CellWidgetData { - value?: unknown; - options?: CellOptions; -} - export interface CellWidgetInstance { - readonly data: CellWidgetData; + readonly data: CellTextResult; } diff --git a/packages/abc/cell/index.en-US.md b/packages/abc/cell/index.en-US.md index be5d0d6bc..4b91b8e9b 100644 --- a/packages/abc/cell/index.en-US.md +++ b/packages/abc/cell/index.en-US.md @@ -67,25 +67,27 @@ Cell formatting is supported for multiple data types, and supports widget mode. Just implement the `CellWidgetInstance` interface, for example: ```ts -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; -import type { CellWidgetData, CellWidgetInstance } from '@delon/abc/cell'; +import type { CellTextResult, CellWidgetInstance } from '@delon/abc/cell'; import { NzMessageService } from 'ng-zorro-antd/message'; +import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; @Component({ selector: 'cell-widget-test', - template: ` `, + template: ` `, host: { '(click)': 'show()' }, - changeDetection: ChangeDetectionStrategy.OnPush + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ NzToolTipModule ] }) export class CellTestWidget implements CellWidgetInstance { + private readonly msg = inject(NzMessageService); static readonly KEY = 'test'; - readonly data!: CellWidgetData; - - constructor(private msg: NzMessageService) {} + readonly data!: CellTextResult; show(): void { this.msg.info(`click`); diff --git a/packages/abc/cell/index.zh-CN.md b/packages/abc/cell/index.zh-CN.md index 5775a6f90..7280d0212 100644 --- a/packages/abc/cell/index.zh-CN.md +++ b/packages/abc/cell/index.zh-CN.md @@ -67,25 +67,27 @@ module: import { CellModule } from '@delon/abc/cell'; 实现 `CellWidgetInstance` 接口即可,例如: ```ts -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; -import type { CellWidgetData, CellWidgetInstance } from '@delon/abc/cell'; +import type { CellTextResult, CellWidgetInstance } from '@delon/abc/cell'; import { NzMessageService } from 'ng-zorro-antd/message'; +import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; @Component({ selector: 'cell-widget-test', - template: ` `, + template: ` `, host: { '(click)': 'show()' }, - changeDetection: ChangeDetectionStrategy.OnPush + changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ NzToolTipModule ] }) export class CellTestWidget implements CellWidgetInstance { + private readonly msg = inject(NzMessageService); static readonly KEY = 'test'; - readonly data!: CellWidgetData; - - constructor(private msg: NzMessageService) {} + readonly data!: CellTextResult; show(): void { this.msg.info(`click`); diff --git a/src/app/shared/cell-widget/test.ts b/src/app/shared/cell-widget/test.ts index 51f337465..b99f58449 100644 --- a/src/app/shared/cell-widget/test.ts +++ b/src/app/shared/cell-widget/test.ts @@ -1,12 +1,12 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; -import type { CellWidgetData, CellWidgetInstance } from '@delon/abc/cell'; +import type { CellTextResult, CellWidgetInstance } from '@delon/abc/cell'; import { NzMessageService } from 'ng-zorro-antd/message'; import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; @Component({ selector: 'cell-widget-test', - template: ` `, + template: ` `, host: { '(click)': 'show()' }, @@ -15,11 +15,10 @@ import { NzToolTipModule } from 'ng-zorro-antd/tooltip'; imports: [ NzToolTipModule ] }) export class CellTestWidget implements CellWidgetInstance { + private readonly msg = inject(NzMessageService); static readonly KEY = 'test'; - readonly data!: CellWidgetData; - - constructor(private msg: NzMessageService) {} + readonly data!: CellTextResult; show(): void { this.msg.info(`click`);