Skip to content

Commit

Permalink
chore: chore form
Browse files Browse the repository at this point in the history
  • Loading branch information
devcui committed Jul 3, 2024
1 parent 3c74551 commit f117443
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 39 deletions.
19 changes: 7 additions & 12 deletions packages/form/spec/base.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { Component, DebugElement, ViewChild } from '@angular/core';
import { ComponentFixture, discardPeriodicTasks, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
Expand All @@ -13,7 +14,7 @@ import { SFWidgetProvideConfig, provideSFConfig } from '../src';
import { SF_SEQ } from '../src/const';
import { SFButton } from '../src/interface';
import { FormProperty } from '../src/model/form.property';
import { YelonFormModule } from '../src/module';
import { DelonFormModule } from '../src/module';
import { SFSchema } from '../src/schema';
import { SFUISchema } from '../src/schema/ui';
import { SFComponent } from '../src/sf.component';
Expand All @@ -38,7 +39,7 @@ let context: TestFormComponent;
export function builder(options?: {
detectChanges?: boolean;
template?: string;
ignoreAntd?: boolean;
ingoreAntd?: boolean;
imports?: NzSafeAny[];
}): {
fixture: ComponentFixture<TestFormComponent>;
Expand All @@ -48,7 +49,7 @@ export function builder(options?: {
} {
options = { detectChanges: true, ...options };
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, YunzaiThemeModule, YelonFormModule.forRoot()].concat(options.imports || []),
imports: [NoopAnimationsModule, YunzaiThemeModule, DelonFormModule.forRoot()].concat(options.imports || []),
declarations: [TestFormComponent]
});
if (options.template) {
Expand Down Expand Up @@ -77,15 +78,9 @@ export function builder(options?: {
export function configureSFTestSuite(options?: { imports?: NzSafeAny[]; widgets?: SFWidgetProvideConfig[] }): void {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
YunzaiThemeModule,
YelonFormModule,
HttpClientTestingModule,
...(options?.imports ?? [])
],
imports: [NoopAnimationsModule, YunzaiThemeModule, DelonFormModule, ...(options?.imports ?? [])],
declarations: [TestFormComponent],
providers: [provideSFConfig({ widgets: options?.widgets })]
providers: [provideHttpClient(), provideHttpClientTesting(), provideSFConfig({ widgets: options?.widgets })]
});
});
}
Expand Down
34 changes: 14 additions & 20 deletions packages/form/src/sf.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { DomSanitizer } from '@angular/platform-browser';
import { merge, Observable, filter } from 'rxjs';
import { merge, filter } from 'rxjs';

import { ACLService } from '@yelon/acl';
import { YUNZAI_I18N_TOKEN, YelonLocaleService, LocaleData } from '@yelon/theme';
import { ALAIN_I18N_TOKEN, DelonLocaleService, LocaleData } from '@yelon/theme';
import { YunzaiConfigService, YunzaiSFConfig } from '@yelon/util/config';
import { deepCopy } from '@yelon/util/other';
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
Expand Down Expand Up @@ -81,9 +81,9 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
private readonly terminator = inject(TerminatorService);
private readonly dom = inject(DomSanitizer);
private readonly cdr = inject(ChangeDetectorRef);
private readonly localeSrv = inject(YelonLocaleService);
private readonly aclSrv = inject(ACLService, { optional: true });
private readonly i18nSrv = inject(YUNZAI_I18N_TOKEN, { optional: true });
private readonly localeSrv = inject(DelonLocaleService);
private readonly aclSrv = inject(ACLService);
private readonly i18nSrv = inject(ALAIN_I18N_TOKEN);
private readonly platform = inject(Platform);

private _renders = new Map<string, TemplateRef<void>>();
Expand Down Expand Up @@ -317,22 +317,16 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
this.cdr.markForCheck();
}
});
const refSchemas: Array<Observable<NzSafeAny> | null> = [
this.aclSrv ? this.aclSrv.change : null,
this.i18nSrv ? this.i18nSrv.change : null
].filter(o => o != null);
if (refSchemas.length > 0) {
merge(...(refSchemas as Array<Observable<NzSafeAny>>))
.pipe(
filter(() => this._inited),
takeUntilDestroyed()
)
.subscribe(() => this.refreshSchema());
}
merge(this.aclSrv.change, this.i18nSrv.change)
.pipe(
filter(() => this._inited),
takeUntilDestroyed()
)
.subscribe(() => this.refreshSchema());
}

protected fanyi(key: string): string {
return (this.i18nSrv ? this.i18nSrv.fanyi(key) : '') || key;
return this.i18nSrv.fanyi(key) || key;
}

private inheritUI(ui: SFUISchemaItemRun): void {
Expand Down Expand Up @@ -565,8 +559,8 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
if (!this.platform.isBrowser) {
return;
}
const ignoreRender = ['disabled', 'loading'];
if (Object.keys(changes).every(key => ignoreRender.includes(key))) {
const ingoreRender = ['disabled', 'loading'];
if (Object.keys(changes).every(key => ingoreRender.includes(key))) {
this.cdr.detectChanges();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/widgets/date/date.widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import { ControlUIWidget } from '../../widget';
[nzShowTime]="ui.showTime"
[nzSeparator]="ui.separator"
[nzShowWeekNumber]="ui.showWeekNumber || false"
[nzMode]="ui.rangeMode"
[nzMode]="$any(ui.rangeMode)"
[nzInputReadOnly]="ui.inputReadOnly"
[nzInline]="ui.inline!"
(nzOnOk)="_ok($event)"
Expand Down
3 changes: 0 additions & 3 deletions packages/form/widgets/color/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Used when the user needs to customize the color selection.

## How to use

**Installation dependencies**

`yarn add ng-antd-color-picker`

Non-built-in modules need to additionally register `withColorWidget` in [json-schema](https://github.com/hbyunzai/ng-yunzai/blob/master/src/app/shared/json-schema/index.ts#L9).

Expand Down
3 changes: 0 additions & 3 deletions packages/form/widgets/color/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ type: Non-built-in widgets

## 如何使用

**安装依赖**

`yarn add ng-antd-color-picker`

非内置模块,需要额外在 [json-schema](https://github.com/hbyunzai/ng-yunzai/blob/master/src/app/shared/json-schema/index.ts#L9) 注册 `withColorWidget`

Expand Down

0 comments on commit f117443

Please sign in to comment.