@praxisui/editorial-forms 1.0.0-beta.64 → 1.0.0-beta.65
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.
|
@@ -493,7 +493,7 @@ class EditorialDataCollectionBlockOutletComponent {
|
|
|
493
493
|
}
|
|
494
494
|
mergeFormDataIntoRuntimeContext(payload) {
|
|
495
495
|
const runtimeContext = this.runtimeContext();
|
|
496
|
-
const currentFormData = readRuntimeFormData(runtimeContext);
|
|
496
|
+
const currentFormData = readRuntimeFormData$1(runtimeContext);
|
|
497
497
|
const nextFormData = payload.mode === 'replace'
|
|
498
498
|
? { ...payload.formData }
|
|
499
499
|
: { ...currentFormData, ...payload.formData };
|
|
@@ -653,7 +653,7 @@ function extractFormDataChangeEvent(event) {
|
|
|
653
653
|
: undefined,
|
|
654
654
|
};
|
|
655
655
|
}
|
|
656
|
-
function readRuntimeFormData(runtimeContext) {
|
|
656
|
+
function readRuntimeFormData$1(runtimeContext) {
|
|
657
657
|
const formData = runtimeContext?.['formData'];
|
|
658
658
|
if (!formData || typeof formData !== 'object' || Array.isArray(formData)) {
|
|
659
659
|
return {};
|
|
@@ -3776,6 +3776,54 @@ function formatScopeLabel(labelName, label, id) {
|
|
|
3776
3776
|
}
|
|
3777
3777
|
|
|
3778
3778
|
const REQUIRED_DYNAMIC_FORM_INPUTS = ['config', 'formId', 'editorialContext'];
|
|
3779
|
+
function readRuntimeFormData(runtimeContext) {
|
|
3780
|
+
const formData = runtimeContext?.['formData'];
|
|
3781
|
+
if (!formData || typeof formData !== 'object' || Array.isArray(formData)) {
|
|
3782
|
+
return {};
|
|
3783
|
+
}
|
|
3784
|
+
return formData;
|
|
3785
|
+
}
|
|
3786
|
+
function cloneRuntimeValue(value) {
|
|
3787
|
+
if (Array.isArray(value)) {
|
|
3788
|
+
return value.map((entry) => cloneRuntimeValue(entry));
|
|
3789
|
+
}
|
|
3790
|
+
if (value && typeof value === 'object') {
|
|
3791
|
+
return { ...value };
|
|
3792
|
+
}
|
|
3793
|
+
return value;
|
|
3794
|
+
}
|
|
3795
|
+
function applyRuntimeFormDataDefaults(config, runtimeContext) {
|
|
3796
|
+
if (!config) {
|
|
3797
|
+
return null;
|
|
3798
|
+
}
|
|
3799
|
+
const runtimeFormData = readRuntimeFormData(runtimeContext);
|
|
3800
|
+
const fieldMetadata = config.fieldMetadata ?? [];
|
|
3801
|
+
if (!fieldMetadata.length || !Object.keys(runtimeFormData).length) {
|
|
3802
|
+
return config;
|
|
3803
|
+
}
|
|
3804
|
+
let changed = false;
|
|
3805
|
+
const nextFieldMetadata = fieldMetadata.map((field) => {
|
|
3806
|
+
if (!Object.prototype.hasOwnProperty.call(runtimeFormData, field.name)) {
|
|
3807
|
+
return field;
|
|
3808
|
+
}
|
|
3809
|
+
const runtimeValue = runtimeFormData[field.name];
|
|
3810
|
+
if (field.defaultValue === runtimeValue) {
|
|
3811
|
+
return field;
|
|
3812
|
+
}
|
|
3813
|
+
changed = true;
|
|
3814
|
+
return {
|
|
3815
|
+
...field,
|
|
3816
|
+
defaultValue: cloneRuntimeValue(runtimeValue),
|
|
3817
|
+
};
|
|
3818
|
+
});
|
|
3819
|
+
if (!changed) {
|
|
3820
|
+
return config;
|
|
3821
|
+
}
|
|
3822
|
+
return {
|
|
3823
|
+
...config,
|
|
3824
|
+
fieldMetadata: nextFieldMetadata,
|
|
3825
|
+
};
|
|
3826
|
+
}
|
|
3779
3827
|
function createEditorialDynamicFormAdapter(options) {
|
|
3780
3828
|
return {
|
|
3781
3829
|
adapterId: 'dynamic-form',
|
|
@@ -3788,7 +3836,7 @@ function createEditorialDynamicFormAdapter(options) {
|
|
|
3788
3836
|
},
|
|
3789
3837
|
buildInputs(context) {
|
|
3790
3838
|
return {
|
|
3791
|
-
config: context.resolvedFormConfig,
|
|
3839
|
+
config: applyRuntimeFormDataDefaults(context.resolvedFormConfig, context.runtimeContext),
|
|
3792
3840
|
formId: context.block.formBlockId,
|
|
3793
3841
|
editorialContext: context.runtimeContext,
|
|
3794
3842
|
};
|