@contentful/experiences-visual-editor-react 3.6.2 → 3.7.0-prerelease-20250915T1724-8825648.0
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.
- package/dist/index.js +258 -8
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +258 -8
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -808,6 +808,25 @@ z.object({
|
|
|
808
808
|
usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
|
|
809
809
|
});
|
|
810
810
|
|
|
811
|
+
function treeVisit$1$1(initialNode, onNode) {
|
|
812
|
+
const _treeVisit = (currentNode) => {
|
|
813
|
+
const children = [...currentNode.children];
|
|
814
|
+
onNode(currentNode);
|
|
815
|
+
for (const child of children) {
|
|
816
|
+
_treeVisit(child);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
if (Array.isArray(initialNode)) {
|
|
820
|
+
for (const node of initialNode) {
|
|
821
|
+
_treeVisit(node);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
_treeVisit(initialNode);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const MAX_ALLOWED_PATHS$1 = 200;
|
|
811
830
|
const THUMBNAIL_IDS$1 = [
|
|
812
831
|
'columns',
|
|
813
832
|
'columnsPlusRight',
|
|
@@ -838,7 +857,17 @@ const THUMBNAIL_IDS$1 = [
|
|
|
838
857
|
const VariableMappingSchema$1 = z.object({
|
|
839
858
|
parameterId: propertyKeySchema$1,
|
|
840
859
|
type: z.literal('ContentTypeMapping'),
|
|
841
|
-
pathsByContentType: z
|
|
860
|
+
pathsByContentType: z
|
|
861
|
+
.record(z.string(), z.object({ path: z.string() }))
|
|
862
|
+
.superRefine((paths, ctx) => {
|
|
863
|
+
const variableId = ctx.path[ctx.path.length - 2];
|
|
864
|
+
if (Object.keys(paths).length > MAX_ALLOWED_PATHS$1) {
|
|
865
|
+
ctx.addIssue({
|
|
866
|
+
code: z.ZodIssueCode.custom,
|
|
867
|
+
message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS$1}`,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
}),
|
|
842
871
|
});
|
|
843
872
|
const PassToNodeSchema$1 = z
|
|
844
873
|
.object({
|
|
@@ -862,7 +891,10 @@ const ParameterDefinitionSchema$1 = z.object({
|
|
|
862
891
|
})
|
|
863
892
|
.optional(),
|
|
864
893
|
contentTypes: z.array(z.string()).min(1),
|
|
865
|
-
passToNodes: z
|
|
894
|
+
passToNodes: z
|
|
895
|
+
.array(PassToNodeSchema$1)
|
|
896
|
+
.max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
|
|
897
|
+
.optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
|
|
866
898
|
});
|
|
867
899
|
const ParameterDefinitionsSchema$1 = z.record(propertyKeySchema$1, ParameterDefinitionSchema$1);
|
|
868
900
|
const VariableMappingsSchema$1 = z.record(propertyKeySchema$1, VariableMappingSchema$1);
|
|
@@ -883,14 +915,107 @@ const ComponentSettingsSchema$1 = z
|
|
|
883
915
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
884
916
|
prebindingDefinitions: z.array(PrebindingDefinitionSchema$1).length(1).optional(),
|
|
885
917
|
})
|
|
886
|
-
.strict()
|
|
887
|
-
|
|
918
|
+
.strict()
|
|
919
|
+
.superRefine((componentSettings, ctx) => {
|
|
920
|
+
const { variableDefinitions, prebindingDefinitions } = componentSettings;
|
|
921
|
+
if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
|
|
925
|
+
validateAtMostOneNativeParameterDefinition$1(parameterDefinitions, ctx);
|
|
926
|
+
validateNoOverlapBetweenMappingAndOverrides$1(variableMappings, allowedVariableOverrides, ctx);
|
|
927
|
+
validateMappingsAgainstVariableDefinitions$1(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
|
|
928
|
+
validateMappingsAgainstParameterDefinitions$1(variableMappings, parameterDefinitions, ctx);
|
|
929
|
+
});
|
|
930
|
+
z
|
|
931
|
+
.object({
|
|
888
932
|
componentTree: localeWrapper$1(ComponentTreeSchema$1),
|
|
889
933
|
dataSource: localeWrapper$1(DataSourceSchema$1),
|
|
890
934
|
unboundValues: localeWrapper$1(UnboundValuesSchema$1),
|
|
891
935
|
usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
|
|
892
936
|
componentSettings: localeWrapper$1(ComponentSettingsSchema$1),
|
|
937
|
+
})
|
|
938
|
+
.superRefine((patternFields, ctx) => {
|
|
939
|
+
const { componentTree, componentSettings } = patternFields;
|
|
940
|
+
// values at this point are wrapped under locale code
|
|
941
|
+
const nonLocalisedComponentTree = Object.values(componentTree)[0];
|
|
942
|
+
const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
|
|
943
|
+
if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
validatePassToNodes$1(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
|
|
893
947
|
});
|
|
948
|
+
const validateAtMostOneNativeParameterDefinition$1 = (parameterDefinitions, ctx) => {
|
|
949
|
+
const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
|
|
950
|
+
if (nativeParamDefinitions.length > 1) {
|
|
951
|
+
ctx.addIssue({
|
|
952
|
+
code: z.ZodIssueCode.custom,
|
|
953
|
+
message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
const validateNoOverlapBetweenMappingAndOverrides$1 = (variableMappings, allowedVariableOverrides, ctx) => {
|
|
958
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
959
|
+
const overlap = variableMappingKeys.filter((key) => allowedVariableOverrides?.includes(key));
|
|
960
|
+
if (overlap.length > 0) {
|
|
961
|
+
ctx.addIssue({
|
|
962
|
+
code: z.ZodIssueCode.custom,
|
|
963
|
+
message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const validateMappingsAgainstVariableDefinitions$1 = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
|
|
968
|
+
const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
|
|
969
|
+
.filter(([_, def]) => def.group !== 'style')
|
|
970
|
+
.map(([key]) => key);
|
|
971
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
972
|
+
const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
|
|
973
|
+
const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
|
|
974
|
+
if (invalidMappings.length > 0) {
|
|
975
|
+
ctx.addIssue({
|
|
976
|
+
code: z.ZodIssueCode.custom,
|
|
977
|
+
message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
const validateMappingsAgainstParameterDefinitions$1 = (variableMappings, parameterDefinitions, ctx) => {
|
|
982
|
+
const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
|
|
983
|
+
for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
|
|
984
|
+
if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
|
|
985
|
+
ctx.addIssue({
|
|
986
|
+
code: z.ZodIssueCode.custom,
|
|
987
|
+
message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
const validatePassToNodes$1 = (rootChildren, componentSettings, ctx) => {
|
|
993
|
+
if (!componentSettings.prebindingDefinitions ||
|
|
994
|
+
componentSettings.prebindingDefinitions.length === 0) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
|
|
998
|
+
let nodeIds = new Set();
|
|
999
|
+
for (const paramDef of Object.values(parameterDefinitions || {})) {
|
|
1000
|
+
paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
|
|
1001
|
+
}
|
|
1002
|
+
treeVisit$1$1(rootChildren, (node) => {
|
|
1003
|
+
if (!node.id)
|
|
1004
|
+
return;
|
|
1005
|
+
if (nodeIds.has(node.id)) {
|
|
1006
|
+
nodeIds.delete(node.id);
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
if (nodeIds.size > 0) {
|
|
1010
|
+
const stringifiedNodeIds = Array.from(nodeIds)
|
|
1011
|
+
.map((id) => `"${id}"`)
|
|
1012
|
+
.join(', ');
|
|
1013
|
+
ctx.addIssue({
|
|
1014
|
+
code: z.ZodIssueCode.custom,
|
|
1015
|
+
message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
894
1019
|
|
|
895
1020
|
z
|
|
896
1021
|
.object({
|
|
@@ -3656,6 +3781,25 @@ z.object({
|
|
|
3656
3781
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
3657
3782
|
});
|
|
3658
3783
|
|
|
3784
|
+
function treeVisit$1(initialNode, onNode) {
|
|
3785
|
+
const _treeVisit = (currentNode) => {
|
|
3786
|
+
const children = [...currentNode.children];
|
|
3787
|
+
onNode(currentNode);
|
|
3788
|
+
for (const child of children) {
|
|
3789
|
+
_treeVisit(child);
|
|
3790
|
+
}
|
|
3791
|
+
};
|
|
3792
|
+
if (Array.isArray(initialNode)) {
|
|
3793
|
+
for (const node of initialNode) {
|
|
3794
|
+
_treeVisit(node);
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
else {
|
|
3798
|
+
_treeVisit(initialNode);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
const MAX_ALLOWED_PATHS = 200;
|
|
3659
3803
|
const THUMBNAIL_IDS = [
|
|
3660
3804
|
'columns',
|
|
3661
3805
|
'columnsPlusRight',
|
|
@@ -3686,7 +3830,17 @@ const THUMBNAIL_IDS = [
|
|
|
3686
3830
|
const VariableMappingSchema = z.object({
|
|
3687
3831
|
parameterId: propertyKeySchema,
|
|
3688
3832
|
type: z.literal('ContentTypeMapping'),
|
|
3689
|
-
pathsByContentType: z
|
|
3833
|
+
pathsByContentType: z
|
|
3834
|
+
.record(z.string(), z.object({ path: z.string() }))
|
|
3835
|
+
.superRefine((paths, ctx) => {
|
|
3836
|
+
const variableId = ctx.path[ctx.path.length - 2];
|
|
3837
|
+
if (Object.keys(paths).length > MAX_ALLOWED_PATHS) {
|
|
3838
|
+
ctx.addIssue({
|
|
3839
|
+
code: z.ZodIssueCode.custom,
|
|
3840
|
+
message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS}`,
|
|
3841
|
+
});
|
|
3842
|
+
}
|
|
3843
|
+
}),
|
|
3690
3844
|
});
|
|
3691
3845
|
const PassToNodeSchema = z
|
|
3692
3846
|
.object({
|
|
@@ -3710,7 +3864,10 @@ const ParameterDefinitionSchema = z.object({
|
|
|
3710
3864
|
})
|
|
3711
3865
|
.optional(),
|
|
3712
3866
|
contentTypes: z.array(z.string()).min(1),
|
|
3713
|
-
passToNodes: z
|
|
3867
|
+
passToNodes: z
|
|
3868
|
+
.array(PassToNodeSchema)
|
|
3869
|
+
.max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
|
|
3870
|
+
.optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
|
|
3714
3871
|
});
|
|
3715
3872
|
const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
|
|
3716
3873
|
const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
|
|
@@ -3731,14 +3888,107 @@ const ComponentSettingsSchema = z
|
|
|
3731
3888
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
3732
3889
|
prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
|
|
3733
3890
|
})
|
|
3734
|
-
.strict()
|
|
3735
|
-
|
|
3891
|
+
.strict()
|
|
3892
|
+
.superRefine((componentSettings, ctx) => {
|
|
3893
|
+
const { variableDefinitions, prebindingDefinitions } = componentSettings;
|
|
3894
|
+
if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
|
|
3898
|
+
validateAtMostOneNativeParameterDefinition(parameterDefinitions, ctx);
|
|
3899
|
+
validateNoOverlapBetweenMappingAndOverrides(variableMappings, allowedVariableOverrides, ctx);
|
|
3900
|
+
validateMappingsAgainstVariableDefinitions(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
|
|
3901
|
+
validateMappingsAgainstParameterDefinitions(variableMappings, parameterDefinitions, ctx);
|
|
3902
|
+
});
|
|
3903
|
+
z
|
|
3904
|
+
.object({
|
|
3736
3905
|
componentTree: localeWrapper(ComponentTreeSchema),
|
|
3737
3906
|
dataSource: localeWrapper(DataSourceSchema),
|
|
3738
3907
|
unboundValues: localeWrapper(UnboundValuesSchema),
|
|
3739
3908
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
3740
3909
|
componentSettings: localeWrapper(ComponentSettingsSchema),
|
|
3910
|
+
})
|
|
3911
|
+
.superRefine((patternFields, ctx) => {
|
|
3912
|
+
const { componentTree, componentSettings } = patternFields;
|
|
3913
|
+
// values at this point are wrapped under locale code
|
|
3914
|
+
const nonLocalisedComponentTree = Object.values(componentTree)[0];
|
|
3915
|
+
const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
|
|
3916
|
+
if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
|
|
3917
|
+
return;
|
|
3918
|
+
}
|
|
3919
|
+
validatePassToNodes(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
|
|
3741
3920
|
});
|
|
3921
|
+
const validateAtMostOneNativeParameterDefinition = (parameterDefinitions, ctx) => {
|
|
3922
|
+
const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
|
|
3923
|
+
if (nativeParamDefinitions.length > 1) {
|
|
3924
|
+
ctx.addIssue({
|
|
3925
|
+
code: z.ZodIssueCode.custom,
|
|
3926
|
+
message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
|
|
3927
|
+
});
|
|
3928
|
+
}
|
|
3929
|
+
};
|
|
3930
|
+
const validateNoOverlapBetweenMappingAndOverrides = (variableMappings, allowedVariableOverrides, ctx) => {
|
|
3931
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
3932
|
+
const overlap = variableMappingKeys.filter((key) => allowedVariableOverrides?.includes(key));
|
|
3933
|
+
if (overlap.length > 0) {
|
|
3934
|
+
ctx.addIssue({
|
|
3935
|
+
code: z.ZodIssueCode.custom,
|
|
3936
|
+
message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
|
|
3937
|
+
});
|
|
3938
|
+
}
|
|
3939
|
+
};
|
|
3940
|
+
const validateMappingsAgainstVariableDefinitions = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
|
|
3941
|
+
const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
|
|
3942
|
+
.filter(([_, def]) => def.group !== 'style')
|
|
3943
|
+
.map(([key]) => key);
|
|
3944
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
3945
|
+
const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
|
|
3946
|
+
const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
|
|
3947
|
+
if (invalidMappings.length > 0) {
|
|
3948
|
+
ctx.addIssue({
|
|
3949
|
+
code: z.ZodIssueCode.custom,
|
|
3950
|
+
message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
|
|
3951
|
+
});
|
|
3952
|
+
}
|
|
3953
|
+
};
|
|
3954
|
+
const validateMappingsAgainstParameterDefinitions = (variableMappings, parameterDefinitions, ctx) => {
|
|
3955
|
+
const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
|
|
3956
|
+
for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
|
|
3957
|
+
if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
|
|
3958
|
+
ctx.addIssue({
|
|
3959
|
+
code: z.ZodIssueCode.custom,
|
|
3960
|
+
message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
|
|
3961
|
+
});
|
|
3962
|
+
}
|
|
3963
|
+
}
|
|
3964
|
+
};
|
|
3965
|
+
const validatePassToNodes = (rootChildren, componentSettings, ctx) => {
|
|
3966
|
+
if (!componentSettings.prebindingDefinitions ||
|
|
3967
|
+
componentSettings.prebindingDefinitions.length === 0) {
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
|
|
3971
|
+
let nodeIds = new Set();
|
|
3972
|
+
for (const paramDef of Object.values(parameterDefinitions || {})) {
|
|
3973
|
+
paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
|
|
3974
|
+
}
|
|
3975
|
+
treeVisit$1(rootChildren, (node) => {
|
|
3976
|
+
if (!node.id)
|
|
3977
|
+
return;
|
|
3978
|
+
if (nodeIds.has(node.id)) {
|
|
3979
|
+
nodeIds.delete(node.id);
|
|
3980
|
+
}
|
|
3981
|
+
});
|
|
3982
|
+
if (nodeIds.size > 0) {
|
|
3983
|
+
const stringifiedNodeIds = Array.from(nodeIds)
|
|
3984
|
+
.map((id) => `"${id}"`)
|
|
3985
|
+
.join(', ');
|
|
3986
|
+
ctx.addIssue({
|
|
3987
|
+
code: z.ZodIssueCode.custom,
|
|
3988
|
+
message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
|
|
3989
|
+
});
|
|
3990
|
+
}
|
|
3991
|
+
};
|
|
3742
3992
|
|
|
3743
3993
|
z
|
|
3744
3994
|
.object({
|