这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: ensure compatibility with object keys minification #4036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/core/json-schema/src/formly-json-schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class FormlyJsonschema {
}

if (schema.hasOwnProperty('exclusiveMinimum')) {
field.props.exclusiveMinimum = schema.exclusiveMinimum;
field.props['exclusiveMinimum'] = schema.exclusiveMinimum;
this.addValidator(
field,
'exclusiveMinimum',
Expand All @@ -244,7 +244,7 @@ export class FormlyJsonschema {
}

if (schema.hasOwnProperty('exclusiveMaximum')) {
field.props.exclusiveMaximum = schema.exclusiveMaximum;
field.props['exclusiveMaximum'] = schema.exclusiveMaximum;
this.addValidator(
field,
'exclusiveMaximum',
Expand Down Expand Up @@ -371,7 +371,7 @@ export class FormlyJsonschema {
}
case 'array': {
if (schema.hasOwnProperty('minItems')) {
field.props.minItems = schema.minItems;
field.props['minItems'] = schema.minItems;
this.addValidator(field, 'minItems', ({ value }: AbstractControl) => {
return isEmpty(value) || value.length >= schema.minItems;
});
Expand All @@ -380,13 +380,13 @@ export class FormlyJsonschema {
}
}
if (schema.hasOwnProperty('maxItems')) {
field.props.maxItems = schema.maxItems;
field.props['maxItems'] = schema.maxItems;
this.addValidator(field, 'maxItems', ({ value }: AbstractControl) => {
return isEmpty(value) || value.length <= schema.maxItems;
});
}
if (schema.hasOwnProperty('uniqueItems')) {
field.props.uniqueItems = schema.uniqueItems;
field.props['uniqueItems'] = schema.uniqueItems;
this.addValidator(field, 'uniqueItems', ({ value }: AbstractControl) => {
if (isEmpty(value) || !schema.uniqueItems) {
return true;
Expand Down Expand Up @@ -451,7 +451,7 @@ export class FormlyJsonschema {
f.props.required = true;
}
if (items[length]) {
f.props.removable = false;
f.props['removable'] = false;
}

return f;
Expand All @@ -462,7 +462,7 @@ export class FormlyJsonschema {
}

if (schema.hasOwnProperty('const')) {
field.props.const = schema.const;
field.props['const'] = schema.const;
this.addValidator(field, 'const', ({ value }: AbstractControl) => value === schema.const);
if (!field.type) {
field.defaultValue = schema.const;
Expand All @@ -474,7 +474,7 @@ export class FormlyJsonschema {
const multiple = field.type === 'array';

field.type = 'enum';
field.props.multiple = multiple;
field.props['multiple'] = multiple;
field.props.options = enumOptions;

const enumValues = enumOptions.map((o) => o.value);
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/lib/components/formly.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ export class FormlyField implements DoCheck, OnInit, OnChanges, AfterContentInit
}

private triggerHook(name: keyof FormlyHookConfig, changes?: SimpleChanges) {
if (name === 'onInit' || (name === 'onChanges' && changes.field && !changes.field.firstChange)) {
if (name === 'onInit' || (name === 'onChanges' && changes['field'] && !changes['field'].firstChange)) {
this.valueChangesUnsubscribe();
this.valueChangesUnsubscribe = this.fieldChanges(this.field);
}

if (this.field?.hooks?.[name]) {
if (!changes || changes.field) {
if (!changes || changes['field']) {
const r = this.field.hooks[name](this.field);
if (isObservable(r) && ['onInit', 'afterContentInit', 'afterViewInit'].indexOf(name) !== -1) {
const sub = r.subscribe();
Expand All @@ -176,8 +176,8 @@ export class FormlyField implements DoCheck, OnInit, OnChanges, AfterContentInit
}
}

if (name === 'onChanges' && changes.field) {
this.resetRefs(changes.field.previousValue);
if (name === 'onChanges' && changes['field']) {
this.resetRefs(changes['field'].previousValue);
this.render();
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/core/src/lib/components/formly.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ export class FormlyForm implements DoCheck, OnChanges, OnDestroy {
}

ngOnChanges(changes: SimpleChanges) {
if (changes.fields && this.form) {
if (changes['fields'] && this.form) {
clearControl(this.form);
}

if (changes.fields || changes.form || (changes.model && this._modelChangeValue !== changes.model.currentValue)) {
if (
changes['fields'] ||
changes['form'] ||
(changes['model'] && this._modelChangeValue !== changes['model'].currentValue)
) {
this.valueChangesUnsubscribe();
this.builder.build(this.field);
this.valueChangesUnsubscribe = this.valueChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/extensions/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class CoreExtension implements FormlyExtension {

if (
field.type !== 'formly-template' &&
(field.template || field.expressions?.template || field.expressionProperties?.template)
(field.template || field.expressions?.['template'] || field.expressionProperties?.['template'])
) {
field.type = 'formly-template';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class FieldExpressionExtension implements FormlyExtension {

if (field.hideExpression) {
observe(field, ['hideExpression'], ({ currentValue: expr }) => {
field._expressions.hide = this.parseExpressions(field, 'hide', typeof expr === 'boolean' ? () => expr : expr);
field._expressions['hide'] = this.parseExpressions(
field,
'hide',
typeof expr === 'boolean' ? () => expr : expr,
);
});
}

Expand Down Expand Up @@ -185,7 +189,7 @@ export class FieldExpressionExtension implements FormlyExtension {
private changeHideState(field: FormlyFieldConfigCache, hide: boolean, resetOnHide: boolean) {
if (field.fieldGroup) {
field.fieldGroup
.filter((f: FormlyFieldConfigCache) => f && !f._expressions.hide)
.filter((f: FormlyFieldConfigCache) => f && !f._expressions['hide'])
.forEach((f) => this.changeHideState(f, hide, resetOnHide));
}

Expand Down
8 changes: 6 additions & 2 deletions src/core/src/lib/models/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Type } from '@angular/core';
import { ComponentRef, Type } from '@angular/core';
import { ValidationErrors, AbstractControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { FormlyFieldConfig } from './fieldconfig';
import { FieldType } from './../templates/field.type';
import { FieldWrapper } from '../templates/field.wrapper';

export declare interface FormlyFieldComponentRef {
_componentRef?: ComponentRef<any>;
}

export interface FormlyExtension<F extends FormlyFieldConfig = FormlyFieldConfig> {
priority?: number;

Expand All @@ -13,7 +17,7 @@ export interface FormlyExtension<F extends FormlyFieldConfig = FormlyFieldConfig
postPopulate?(field: F): void;
}

export interface TypeOption {
export declare interface TypeOption {
name: string;
component?: Type<FieldType>;
wrappers?: string[];
Expand Down
11 changes: 8 additions & 3 deletions src/core/src/lib/models/fieldconfig.cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { FieldType } from '../templates/field.type';
import { FormlyExtension } from './config';
import { FormlyFieldConfig, FormlyFormOptions } from './fieldconfig';

export interface FormlyFieldConfigCache extends FormlyFieldConfig {
export declare interface FieldConfigWithErrors {
_fields?: FormlyFieldConfigCache[];
_childrenErrors?: { [id: string]: Function };
}

export declare interface FormlyFieldConfigCache extends FormlyFieldConfig {
form?: FormGroup | FormArray;
model?: any;
formControl?: AbstractControl & { _fields?: FormlyFieldConfigCache[]; _childrenErrors?: { [id: string]: Function } };
formControl?: AbstractControl & FieldConfigWithErrors;
parent?: FormlyFieldConfigCache;
options?: FormlyFormOptionsCache;
shareFormControl?: boolean;
Expand All @@ -34,7 +39,7 @@ export interface FormlyFieldConfigCache extends FormlyFieldConfig {
};
}

export interface FormlyFormOptionsCache extends FormlyFormOptions {
export declare interface FormlyFormOptionsCache extends FormlyFormOptions {
checkExpressions?: (field: FormlyFieldConfig, ingoreCache?: boolean) => void;
_viewContainerRef?: ViewContainerRef;
_injector?: Injector;
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/lib/models/fieldconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type FieldExpressions = { [property: string]: FieldExpression } & {
'props.required'?: FieldExpression<boolean>;
};

export interface FormlyFieldConfig<Props = FormlyFieldProps & { [additionalProperties: string]: any }> {
export declare interface FormlyFieldConfig<Props = FormlyFieldProps & { [additionalProperties: string]: any }> {
/**
* The key that relates to the model. This will link the field value to the model
*/
Expand Down Expand Up @@ -256,7 +256,7 @@ export interface FormlyHookConfig {
onDestroy?: FormlyHookFn;
}

export interface FormlyFormOptions {
export declare interface FormlyFormOptions {
updateInitialValue?: (model?: any) => void;
resetModel?: (model?: any) => void;
formState?: any;
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/services/formly.builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
disableTreeValidityCall,
isHiddenField,
isSignalRequired,
isUndefined,

Check warning on line 11 in src/core/src/lib/services/formly.builder.ts

View workflow job for this annotation

GitHub Actions / build

'isUndefined' is defined but never used. Allowed unused vars must match /^_/u
} from '../utils';

@Injectable({ providedIn: 'root' })
Expand All @@ -25,7 +25,7 @@
}

build(field: FormlyFieldConfig) {
if (!this.config.extensions.core) {
if (!this.config.extensions['core']) {
throw new Error('NgxFormly: missing `forRoot()` call. use `forRoot()` when registering the `FormlyModule`.');
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/src/lib/services/formly.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ValidatorOption,
WrapperOption,
FormlyExtension,
FormlyFieldComponentRef,
ValidationMessageOption,
ExtensionOption,
FormlyFieldConfigPresetProvider,
Expand Down Expand Up @@ -152,7 +153,7 @@ export class FormlyConfig {

/** @ignore @internal */
resolveFieldTypeRef(field: FormlyFieldConfigCache = {}): ComponentRef<FieldType> {
const type: TypeOption & { _componentRef?: ComponentRef<any> } = this.getType(field.type);
const type: TypeOption & FormlyFieldComponentRef = this.getType(field.type);
if (!type) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/templates/field-template.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class FormlyTemplateType extends FieldType {
if (this.field && this.field.template !== this.innerHtml.template) {
this.innerHtml = {
template: this.field.template,
content: this.props.safeHtml
content: this.props['safeHtml']
? this.sanitizer.bypassSecurityTrustHtml(this.field.template)
: this.field.template,
};
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/lib/templates/formly.attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@Directive({
selector: '[formlyAttributes]',
host: {

Check warning on line 21 in src/core/src/lib/templates/formly.attributes.ts

View workflow job for this annotation

GitHub Actions / build

Use @HostBinding or @HostListener rather than the `host` metadata property (https://angular.io/styleguide#style-06-03)
'(change)': 'onHostChange($event)',
},
})
Expand Down Expand Up @@ -67,7 +67,7 @@
}

ngOnChanges(changes: SimpleChanges) {
if (changes.field) {
if (changes['field']) {
this.field.name && this.setAttribute('name', this.field.name);
this.uiEvents.listeners.forEach((listener) => listener());
this.uiEvents.events.forEach((eventName) => {
Expand All @@ -94,8 +94,8 @@
});
}

this.detachElementRef(changes.field.previousValue);
this.attachElementRef(changes.field.currentValue);
this.detachElementRef(changes['field'].previousValue);
this.attachElementRef(changes['field'].currentValue);
if (this.fieldAttrElements.length === 1) {
!this.id && this.field.id && this.setAttribute('id', this.field.id);
this.focusObserver = observe<boolean>(this.field, ['focus'], ({ currentValue }) => {
Expand All @@ -104,7 +104,7 @@
}
}

if (changes.id) {
if (changes['id']) {
this.setAttribute('id', this.id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export interface IObserver<T> {
setValue: (value: T, emitEvent?: boolean) => void;
unsubscribe: Function;
}
interface IObserveTarget<T> {
declare interface IObserveTarget<T> {
[prop: string]: any;
_observers?: {
[prop: string]: {
Expand Down
Loading