@gravitee/ui-particles-angular 5.7.2 → 5.7.3-improve-form-json-compo-db890aa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { trigger, transition, style, animate } from '@angular/animations';
2
2
  import * as i0 from '@angular/core';
3
- import { EventEmitter, Component, HostBinding, Input, Output, HostListener, NgModule, Optional, Self, ViewChild, Directive, Inject, forwardRef, ChangeDetectionStrategy, Injectable, ViewEncapsulation, ContentChildren } from '@angular/core';
3
+ import { EventEmitter, Component, HostBinding, Input, Output, HostListener, NgModule, Optional, Self, ViewChild, Directive, Inject, forwardRef, ChangeDetectionStrategy, Injectable, ViewEncapsulation, ContentChildren, Host } from '@angular/core';
4
4
  import { timer, Subject, fromEvent, of, BehaviorSubject } from 'rxjs';
5
5
  import * as i1 from '@angular/material/card';
6
6
  import { MatCardModule } from '@angular/material/card';
@@ -2779,22 +2779,74 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
2779
2779
  * limitations under the License.
2780
2780
  */
2781
2781
  class GioFormJsonSchemaComponent {
2782
- constructor(formlyJsonschema) {
2782
+ constructor(formlyJsonschema, elRef, fm, ngControl) {
2783
2783
  this.formlyJsonschema = formlyJsonschema;
2784
+ this.elRef = elRef;
2785
+ this.fm = fm;
2786
+ this.ngControl = ngControl;
2787
+ this.unsubscribe$ = new Subject();
2784
2788
  this.formGroup = new FormGroup({});
2785
2789
  this.options = {};
2786
2790
  this.model = {};
2787
2791
  this.fields = [];
2792
+ this._onChange = () => ({});
2793
+ this._onTouched = () => ({});
2794
+ this.touched = false;
2795
+ if (ngControl) {
2796
+ // Setting the value accessor directly (instead of using
2797
+ // the providers `NG_VALUE_ACCESSOR`) to avoid running into a circular import.
2798
+ ngControl.valueAccessor = this;
2799
+ }
2800
+ // When the user interact with the form, mark it as touched
2801
+ fm.monitor(elRef.nativeElement, true)
2802
+ .pipe(takeUntil(this.unsubscribe$))
2803
+ .subscribe(() => {
2804
+ this._onTouched();
2805
+ this.touched = true;
2806
+ });
2788
2807
  }
2789
2808
  set jsonSchema(jsonSchema) {
2790
2809
  if (isObject(jsonSchema)) {
2791
2810
  this.fields = [this.toFormlyFieldConfig(jsonSchema)];
2792
2811
  }
2793
2812
  }
2794
- set initialValue(initialValue) {
2795
- if (initialValue) {
2796
- this.model = cloneDeep(initialValue);
2797
- }
2813
+ ngOnInit() {
2814
+ this.formGroup.statusChanges.pipe(takeUntil(this.unsubscribe$)).subscribe(status => {
2815
+ if (status === 'VALID') {
2816
+ this.ngControl?.control?.setErrors(null);
2817
+ }
2818
+ if (status === 'INVALID') {
2819
+ this.ngControl?.control?.setErrors({ invalid: true });
2820
+ }
2821
+ });
2822
+ // To simulate the behavior of classic form controls, emit value only when the form is touched
2823
+ // Allow to keep the formControl pristine until the user interact with it
2824
+ this.formGroup.valueChanges
2825
+ .pipe(takeUntil(this.unsubscribe$), filter(() => this.touched))
2826
+ .subscribe(value => {
2827
+ this._onChange(value);
2828
+ });
2829
+ }
2830
+ ngOnDestroy() {
2831
+ this.unsubscribe$.next();
2832
+ this.unsubscribe$.unsubscribe();
2833
+ this.fm.stopMonitoring(this.elRef.nativeElement);
2834
+ }
2835
+ // From ControlValueAccessor
2836
+ writeValue(value) {
2837
+ this.model = cloneDeep(value) ?? {};
2838
+ }
2839
+ // From ControlValueAccessor
2840
+ registerOnChange(fn) {
2841
+ this._onChange = fn;
2842
+ }
2843
+ // From ControlValueAccessor
2844
+ registerOnTouched(fn) {
2845
+ this._onTouched = fn;
2846
+ }
2847
+ // From ControlValueAccessor
2848
+ setDisabledState(_isDisabled) {
2849
+ throw new Error('Method not implemented.');
2798
2850
  }
2799
2851
  toFormlyFieldConfig(jsonSchema) {
2800
2852
  return this.formlyJsonschema.toFieldConfig(jsonSchema, {
@@ -2816,22 +2868,23 @@ class GioFormJsonSchemaComponent {
2816
2868
  };
2817
2869
  }
2818
2870
  }
2819
- GioFormJsonSchemaComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFormJsonSchemaComponent, deps: [{ token: i1$3.FormlyJsonschema }], target: i0.ɵɵFactoryTarget.Component });
2820
- GioFormJsonSchemaComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: GioFormJsonSchemaComponent, selector: "gio-form-json-schema", inputs: { jsonSchema: "jsonSchema", formGroup: "formGroup", options: "options", initialValue: "initialValue" }, ngImport: i0, template: `<formly-form [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`, isInline: true, components: [{ type: i1$4.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }] });
2871
+ GioFormJsonSchemaComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFormJsonSchemaComponent, deps: [{ token: i1$3.FormlyJsonschema }, { token: i0.ElementRef }, { token: i2$2.FocusMonitor }, { token: i7.NgControl, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Component });
2872
+ GioFormJsonSchemaComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: GioFormJsonSchemaComponent, selector: "gio-form-json-schema", inputs: { jsonSchema: "jsonSchema", options: "options" }, ngImport: i0, template: `<formly-form *ngIf="formGroup" [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`, isInline: true, components: [{ type: i1$4.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }], directives: [{ type: i2$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2821
2873
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFormJsonSchemaComponent, decorators: [{
2822
2874
  type: Component,
2823
2875
  args: [{
2824
2876
  selector: 'gio-form-json-schema',
2825
- template: `<formly-form [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`,
2877
+ template: `<formly-form *ngIf="formGroup" [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`,
2878
+ changeDetection: ChangeDetectionStrategy.OnPush,
2826
2879
  }]
2827
- }], ctorParameters: function () { return [{ type: i1$3.FormlyJsonschema }]; }, propDecorators: { jsonSchema: [{
2828
- type: Input
2829
- }], formGroup: [{
2880
+ }], ctorParameters: function () { return [{ type: i1$3.FormlyJsonschema }, { type: i0.ElementRef }, { type: i2$2.FocusMonitor }, { type: i7.NgControl, decorators: [{
2881
+ type: Host
2882
+ }, {
2883
+ type: Optional
2884
+ }] }]; }, propDecorators: { jsonSchema: [{
2830
2885
  type: Input
2831
2886
  }], options: [{
2832
2887
  type: Input
2833
- }], initialValue: [{
2834
- type: Input
2835
2888
  }] } });
2836
2889
 
2837
2890
  /*
@@ -3047,6 +3100,55 @@ function bannerExtension(field) {
3047
3100
  }
3048
3101
  }
3049
3102
 
3103
+ /*
3104
+ * Copyright (C) 2023 The Gravitee team (http://gravitee.io)
3105
+ *
3106
+ * Licensed under the Apache License, Version 2.0 (the "License");
3107
+ * you may not use this file except in compliance with the License.
3108
+ * You may obtain a copy of the License at
3109
+ *
3110
+ * http://www.apache.org/licenses/LICENSE-2.0
3111
+ *
3112
+ * Unless required by applicable law or agreed to in writing, software
3113
+ * distributed under the License is distributed on an "AS IS" BASIS,
3114
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3115
+ * See the License for the specific language governing permissions and
3116
+ * limitations under the License.
3117
+ */
3118
+ class GioFjsMultiSchemaTypeComponent extends FieldType {
3119
+ }
3120
+ GioFjsMultiSchemaTypeComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFjsMultiSchemaTypeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
3121
+ GioFjsMultiSchemaTypeComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: GioFjsMultiSchemaTypeComponent, selector: "gio-fjs-multi-schema-type", usesInheritance: true, ngImport: i0, template: `
3122
+ <div class="card mb-3">
3123
+ <div class="card-body">
3124
+ <legend *ngIf="props.label">{{ props.label }}</legend>
3125
+ <p *ngIf="props.description">{{ props.description }}</p>
3126
+ <div class="alert alert-danger" role="alert" *ngIf="showError && formControl.errors">
3127
+ <formly-validation-message [field]="field"></formly-validation-message>
3128
+ </div>
3129
+ <formly-field *ngFor="let f of field.fieldGroup" [field]="f"></formly-field>
3130
+ </div>
3131
+ </div>
3132
+ `, isInline: true, components: [{ type: i1$4.ɵFormlyValidationMessage, selector: "formly-validation-message", inputs: ["field"] }, { type: i1$4.FormlyField, selector: "formly-field", inputs: ["field"] }], directives: [{ type: i2$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2$1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
3133
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFjsMultiSchemaTypeComponent, decorators: [{
3134
+ type: Component,
3135
+ args: [{
3136
+ selector: 'gio-fjs-multi-schema-type',
3137
+ template: `
3138
+ <div class="card mb-3">
3139
+ <div class="card-body">
3140
+ <legend *ngIf="props.label">{{ props.label }}</legend>
3141
+ <p *ngIf="props.description">{{ props.description }}</p>
3142
+ <div class="alert alert-danger" role="alert" *ngIf="showError && formControl.errors">
3143
+ <formly-validation-message [field]="field"></formly-validation-message>
3144
+ </div>
3145
+ <formly-field *ngFor="let f of field.fieldGroup" [field]="f"></formly-field>
3146
+ </div>
3147
+ </div>
3148
+ `,
3149
+ }]
3150
+ }] });
3151
+
3050
3152
  /*
3051
3153
  * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3052
3154
  *
@@ -3068,12 +3170,15 @@ GioFormJsonSchemaModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0",
3068
3170
  GioFormJsonSchemaModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFormJsonSchemaModule, declarations: [GioFormJsonSchemaComponent,
3069
3171
  GioFjsNullTypeComponent,
3070
3172
  GioFjsObjectTypeComponent,
3173
+ GioFjsMultiSchemaTypeComponent,
3071
3174
  GioFjsArrayTypeComponent,
3072
3175
  GioFormFieldWrapperComponent], imports: [CommonModule,
3176
+ A11yModule,
3073
3177
  ReactiveFormsModule, i1$4.FormlyModule, FormlyMaterialModule,
3074
3178
  GioIconsModule], exports: [GioFormJsonSchemaComponent, FormlyModule] });
3075
3179
  GioFormJsonSchemaModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: GioFormJsonSchemaModule, imports: [[
3076
3180
  CommonModule,
3181
+ A11yModule,
3077
3182
  ReactiveFormsModule,
3078
3183
  FormlyModule.forRoot({
3079
3184
  validationMessages: [
@@ -3096,8 +3201,12 @@ GioFormJsonSchemaModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0",
3096
3201
  { name: 'null', component: GioFjsNullTypeComponent, wrappers: ['form-field'] },
3097
3202
  { name: 'array', component: GioFjsArrayTypeComponent },
3098
3203
  { name: 'object', component: GioFjsObjectTypeComponent },
3204
+ { name: 'multischema', component: GioFjsMultiSchemaTypeComponent },
3099
3205
  ],
3100
3206
  extensions: [{ name: 'banner', extension: { onPopulate: bannerExtension } }],
3207
+ extras: {
3208
+ checkExpressionOn: 'changeDetectionCheck',
3209
+ },
3101
3210
  }),
3102
3211
  FormlyMaterialModule,
3103
3212
  GioIconsModule,
@@ -3109,11 +3218,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
3109
3218
  GioFormJsonSchemaComponent,
3110
3219
  GioFjsNullTypeComponent,
3111
3220
  GioFjsObjectTypeComponent,
3221
+ GioFjsMultiSchemaTypeComponent,
3112
3222
  GioFjsArrayTypeComponent,
3113
3223
  GioFormFieldWrapperComponent,
3114
3224
  ],
3115
3225
  imports: [
3116
3226
  CommonModule,
3227
+ A11yModule,
3117
3228
  ReactiveFormsModule,
3118
3229
  FormlyModule.forRoot({
3119
3230
  validationMessages: [
@@ -3136,8 +3247,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
3136
3247
  { name: 'null', component: GioFjsNullTypeComponent, wrappers: ['form-field'] },
3137
3248
  { name: 'array', component: GioFjsArrayTypeComponent },
3138
3249
  { name: 'object', component: GioFjsObjectTypeComponent },
3250
+ { name: 'multischema', component: GioFjsMultiSchemaTypeComponent },
3139
3251
  ],
3140
3252
  extensions: [{ name: 'banner', extension: { onPopulate: bannerExtension } }],
3253
+ extras: {
3254
+ checkExpressionOn: 'changeDetectionCheck',
3255
+ },
3141
3256
  }),
3142
3257
  FormlyMaterialModule,
3143
3258
  GioIconsModule,