ngx-form-designer 0.0.13 → 0.0.14

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.

Potentially problematic release.


This version of ngx-form-designer might be problematic. Click here for more details.

@@ -3919,7 +3919,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImpo
3919
3919
 
3920
3920
  class FormViewerComponent {
3921
3921
  schema;
3922
- data = {};
3922
+ set data(value) {
3923
+ this._data = value ?? {};
3924
+ this.normalizedInitialValues = this.normalizeInitialValues(this._data);
3925
+ }
3926
+ get data() {
3927
+ return this._data;
3928
+ }
3923
3929
  options = {
3924
3930
  showSubmitButton: false,
3925
3931
  submitLabel: 'Submit',
@@ -3936,6 +3942,8 @@ class FormViewerComponent {
3936
3942
  zone = inject(NgZone);
3937
3943
  resizeObserver;
3938
3944
  currentValues = {};
3945
+ _data = {};
3946
+ normalizedInitialValues = {};
3939
3947
  ngOnInit() {
3940
3948
  this.setupResizeObserver();
3941
3949
  }
@@ -4000,6 +4008,74 @@ class FormViewerComponent {
4000
4008
  // Re-emit upwards
4001
4009
  this.submit.emit(result);
4002
4010
  }
4011
+ normalizeInitialValues(input) {
4012
+ if (!this.isRecord(input))
4013
+ return {};
4014
+ if (!this.isOutputShapeCandidate(input))
4015
+ return input;
4016
+ const outputValues = new Map();
4017
+ this.collectOutputShapeFields(input, outputValues);
4018
+ if (outputValues.size === 0)
4019
+ return input;
4020
+ const normalized = {};
4021
+ for (const [fieldName, value] of outputValues.entries()) {
4022
+ normalized[fieldName] = this.deserializeFieldValue(value.fieldValue);
4023
+ }
4024
+ return normalized;
4025
+ }
4026
+ collectOutputShapeFields(value, output) {
4027
+ if (this.isFormFieldValue(value)) {
4028
+ output.set(value.fieldName, value);
4029
+ return;
4030
+ }
4031
+ if (Array.isArray(value)) {
4032
+ return;
4033
+ }
4034
+ if (!this.isRecord(value))
4035
+ return;
4036
+ for (const entry of Object.values(value)) {
4037
+ this.collectOutputShapeFields(entry, output);
4038
+ }
4039
+ }
4040
+ deserializeFieldValue(value) {
4041
+ if (Array.isArray(value)) {
4042
+ if (value.every(item => this.isRecord(item) && this.isFormFieldMap(item))) {
4043
+ return value.map(item => this.formFieldMapToNameMap(item));
4044
+ }
4045
+ return value;
4046
+ }
4047
+ if (this.isRecord(value) && this.isFormFieldMap(value)) {
4048
+ return this.formFieldMapToNameMap(value);
4049
+ }
4050
+ return value;
4051
+ }
4052
+ formFieldMapToNameMap(valueMap) {
4053
+ const normalized = {};
4054
+ for (const entry of Object.values(valueMap)) {
4055
+ if (!this.isFormFieldValue(entry))
4056
+ continue;
4057
+ normalized[entry.fieldName] = this.deserializeFieldValue(entry.fieldValue);
4058
+ }
4059
+ return normalized;
4060
+ }
4061
+ isOutputShapeCandidate(value) {
4062
+ return Object.values(value).some(entry => this.isFormFieldValue(entry) || (this.isRecord(entry) && this.isFormFieldMap(entry)));
4063
+ }
4064
+ isFormFieldMap(value) {
4065
+ const entries = Object.values(value);
4066
+ if (entries.length === 0)
4067
+ return true;
4068
+ return entries.every(entry => this.isFormFieldValue(entry));
4069
+ }
4070
+ isFormFieldValue(value) {
4071
+ if (!this.isRecord(value))
4072
+ return false;
4073
+ return typeof value['fieldName'] === 'string'
4074
+ && Object.hasOwn(value, 'fieldValue');
4075
+ }
4076
+ isRecord(value) {
4077
+ return !!value && typeof value === 'object';
4078
+ }
4003
4079
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: FormViewerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
4004
4080
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.17", type: FormViewerComponent, isStandalone: true, selector: "app-form-viewer", inputs: { schema: "schema", data: "data", options: "options" }, outputs: { formDataChange: "formDataChange", formValidationChange: "formValidationChange", uploadedFilesChange: "uploadedFilesChange", submit: "submit" }, viewQueries: [{ propertyName: "renderer", first: true, predicate: JsonFormRendererComponent, descendants: true }], ngImport: i0, template: `
4005
4081
  <div class="form-viewer-container flex flex-col h-full">
@@ -4007,7 +4083,7 @@ class FormViewerComponent {
4007
4083
  <div class="flex-1 min-h-0 overflow-y-auto">
4008
4084
  <app-json-form-renderer
4009
4085
  [schema]="schema"
4010
- [initialValues]="data"
4086
+ [initialValues]="normalizedInitialValues"
4011
4087
  [mode]="'live'"
4012
4088
  [breakpoint]="breakpoint()"
4013
4089
  [uploadOnSubmit]="true"
@@ -4039,7 +4115,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImpo
4039
4115
  <div class="flex-1 min-h-0 overflow-y-auto">
4040
4116
  <app-json-form-renderer
4041
4117
  [schema]="schema"
4042
- [initialValues]="data"
4118
+ [initialValues]="normalizedInitialValues"
4043
4119
  [mode]="'live'"
4044
4120
  [breakpoint]="breakpoint()"
4045
4121
  [uploadOnSubmit]="true"