@gravitee/ui-particles-angular 12.11.4 → 12.12.0-conditional-json-schema-5433005

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.
@@ -12,7 +12,7 @@ import { ComponentHarness, HarnessPredicate, parallel, TestKey } from '@angular/
12
12
  import { coerceBooleanProperty } from '@angular/cdk/coercion';
13
13
  import * as i6$1 from '@angular/material/form-field';
14
14
  import { MatFormFieldControl, MatFormFieldModule, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
15
- import { isEmpty, isString, isObject, toLower, dropRight, isNil, isArray, remove, isEqual, cloneDeep, uniqueId, range, set, has, some, filter as filter$1, intersection } from 'lodash';
15
+ import { isEmpty, isString, isObject, toLower, dropRight, isNil, isArray, remove, castArray, get, isEqual, cloneDeep, uniqueId, range, set, has, some, filter as filter$1, intersection } from 'lodash';
16
16
  import { tap, startWith, switchMap, map, distinctUntilChanged, takeUntil, filter, take, delay, debounceTime, shareReplay, catchError, debounce } from 'rxjs/operators';
17
17
  import * as i1$1 from '@angular/forms';
18
18
  import { FormsModule, UntypedFormArray, UntypedFormGroup, UntypedFormControl, Validators, NG_VALUE_ACCESSOR, NG_VALIDATORS, ReactiveFormsModule, NgControl, FormControl } from '@angular/forms';
@@ -2287,9 +2287,10 @@ class GioFormlyJsonSchemaService {
2287
2287
  this.formlyJsonschema = formlyJsonschema;
2288
2288
  this.builder = builder;
2289
2289
  }
2290
- toFormlyFieldConfig(jsonSchema) {
2290
+ toFormlyFieldConfig(jsonSchema, context) {
2291
2291
  return this.formlyJsonschema.toFieldConfig(jsonSchema, {
2292
2292
  map: (mappedField, mapSource) => {
2293
+ mappedField = this.displayOnlyIfMap(mappedField, mapSource, context);
2293
2294
  mappedField = this.uiTypeMap(mappedField, mapSource);
2294
2295
  mappedField = this.formatMap(mappedField, mapSource);
2295
2296
  mappedField = this.bannerMap(mappedField, mapSource);
@@ -2301,6 +2302,37 @@ class GioFormlyJsonSchemaService {
2301
2302
  },
2302
2303
  });
2303
2304
  }
2305
+ displayOnlyIfMap(mappedField, mapSource, context) {
2306
+ const $eq = mapSource.gioConfig?.displayOnlyIf?.$eq;
2307
+ if (!isNil($eq) && isObject($eq)) {
2308
+ const isDisplay = (objectToCheck) => Object.entries($eq)
2309
+ .map(([k, v]) => ({ path: k, eqValue: castArray(v) }))
2310
+ .every(({ path, eqValue }) => {
2311
+ const value = get(objectToCheck, path);
2312
+ return eqValue.includes(value);
2313
+ });
2314
+ mappedField.expressions = {
2315
+ ...mappedField.expressions,
2316
+ hide: field => {
2317
+ let parentField = field;
2318
+ while (parentField.parent) {
2319
+ parentField = parentField.parent;
2320
+ }
2321
+ try {
2322
+ return !isDisplay({
2323
+ value: parentField.model,
2324
+ context,
2325
+ });
2326
+ }
2327
+ catch (e) {
2328
+ // Ignore the error and display the field
2329
+ return false;
2330
+ }
2331
+ },
2332
+ };
2333
+ }
2334
+ return mappedField;
2335
+ }
2304
2336
  uiTypeMap(mappedField, mapSource) {
2305
2337
  if (mapSource.gioConfig?.uiType) {
2306
2338
  // Clean the field to avoid conflict and init simple one with given type
@@ -2365,12 +2397,22 @@ class GioFormlyJsonSchemaService {
2365
2397
  return mappedField;
2366
2398
  }
2367
2399
  enumLabelMap(mappedField, mapSource) {
2368
- if (mapSource.enum && !isEmpty(mapSource.enum) && mapSource.gioConfig?.enumLabelMap && isArray(mappedField.props?.options)) {
2400
+ if (!isArray(mappedField.props?.options)) {
2401
+ return mappedField;
2402
+ }
2403
+ const enumLabelMapInObject = mapSource.enum && !isEmpty(mapSource.enum) && mapSource.gioConfig?.enumLabelMap ? mapSource.gioConfig?.enumLabelMap : null;
2404
+ const enumLabelMapInArrayItem = mapSource.items &&
2405
+ mapSource.type === 'array' &&
2406
+ !isEmpty(mapSource.items.enum) &&
2407
+ mapSource.items?.gioConfig?.enumLabelMap
2408
+ ? mapSource.items?.gioConfig?.enumLabelMap
2409
+ : null;
2410
+ if (enumLabelMapInObject || enumLabelMapInArrayItem) {
2369
2411
  mappedField.props = {
2370
2412
  ...mappedField.props,
2371
2413
  options: mappedField.props?.options?.map(({ value }) => {
2372
2414
  return {
2373
- label: value ? mapSource.gioConfig?.enumLabelMap?.[value] : value,
2415
+ label: (enumLabelMapInObject || enumLabelMapInArrayItem)?.[value] ?? value,
2374
2416
  value: value,
2375
2417
  };
2376
2418
  }),
@@ -2417,11 +2459,6 @@ class GioFormJsonSchemaComponent {
2417
2459
  const properties = ['properties', 'oneOf', 'anyOf', 'allOf', '$ref', 'items'];
2418
2460
  return isObject(jsonSchema) && properties.some(property => !isEmpty(jsonSchema[property]));
2419
2461
  }
2420
- set jsonSchema(jsonSchema) {
2421
- if (isObject(jsonSchema)) {
2422
- this.fields = [this.gioFormlyJsonSchema.toFormlyFieldConfig(jsonSchema)];
2423
- }
2424
- }
2425
2462
  constructor(gioFormlyJsonSchema, elRef, fm, changeDetectorRef, ngControl) {
2426
2463
  this.gioFormlyJsonSchema = gioFormlyJsonSchema;
2427
2464
  this.elRef = elRef;
@@ -2465,6 +2502,9 @@ class GioFormJsonSchemaComponent {
2465
2502
  this.isReady = false;
2466
2503
  this.ready.next(false);
2467
2504
  }
2505
+ if (changes.jsonSchema || changes.context) {
2506
+ this.fields = [this.gioFormlyJsonSchema.toFormlyFieldConfig(this.jsonSchema, this.context)];
2507
+ }
2468
2508
  }
2469
2509
  ngOnInit() {
2470
2510
  // When the parent form is touched, mark all the sub formGroup as touched if not already touched
@@ -2570,7 +2610,7 @@ class GioFormJsonSchemaComponent {
2570
2610
  this.stateChanges$.next();
2571
2611
  }
2572
2612
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioFormJsonSchemaComponent, deps: [{ token: GioFormlyJsonSchemaService }, { token: i0.ElementRef }, { token: i1$2.FocusMonitor }, { token: i0.ChangeDetectorRef }, { token: i1$1.NgControl, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
2573
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.3", type: GioFormJsonSchemaComponent, selector: "gio-form-json-schema", inputs: { jsonSchema: "jsonSchema", options: "options" }, outputs: { ready: "ready" }, host: { properties: { "attr.gioFormFocusInvalidIgnore": "this.gioFormFocusInvalidIgnore" } }, usesOnChanges: true, ngImport: i0, template: `<formly-form *ngIf="formGroup" [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2$3.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2613
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.3", type: GioFormJsonSchemaComponent, selector: "gio-form-json-schema", inputs: { jsonSchema: "jsonSchema", context: "context", options: "options" }, outputs: { ready: "ready" }, host: { properties: { "attr.gioFormFocusInvalidIgnore": "this.gioFormFocusInvalidIgnore" } }, usesOnChanges: true, ngImport: i0, template: `<formly-form *ngIf="formGroup" [fields]="fields" [options]="options" [form]="formGroup" [model]="model"></formly-form>`, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2$3.FormlyForm, selector: "formly-form", inputs: ["form", "model", "fields", "options"], outputs: ["modelChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2574
2614
  }
2575
2615
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioFormJsonSchemaComponent, decorators: [{
2576
2616
  type: Component,
@@ -2583,6 +2623,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
2583
2623
  type: HostBinding,
2584
2624
  args: [`attr.${GIO_FORM_FOCUS_INVALID_IGNORE_SELECTOR}`]
2585
2625
  }], jsonSchema: [{
2626
+ type: Input,
2627
+ args: [{ required: true }]
2628
+ }], context: [{
2586
2629
  type: Input
2587
2630
  }], options: [{
2588
2631
  type: Input
@@ -4625,17 +4668,7 @@ function passwordEyeExtension(field) {
4625
4668
  */
4626
4669
  class GioFjsCodeEditorTypeComponent extends FieldType$1 {
4627
4670
  ngOnInit() {
4628
- const language = this.props.monacoEditorConfig?.language;
4629
- switch (language) {
4630
- case 'json':
4631
- this.languageConfig = {
4632
- language: 'json',
4633
- schemas: [],
4634
- };
4635
- break;
4636
- default:
4637
- this.languageConfig = undefined;
4638
- }
4671
+ this.languageConfig = this.props.monacoEditorConfig;
4639
4672
  }
4640
4673
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: GioFjsCodeEditorTypeComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
4641
4674
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.2.3", type: GioFjsCodeEditorTypeComponent, selector: "gio-fjs-code-editor-type", usesInheritance: true, ngImport: i0, template: `