@contentful/experiences-visual-editor-react 3.7.0-dev-20250917T1203-0e23897.0 → 3.7.0-dev-20250917T1357-4fbbff5.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 +260 -8
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +260 -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,108 @@ 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 overridesSet = new Set(allowedVariableOverrides || []);
|
|
960
|
+
const overlap = variableMappingKeys.filter((key) => overridesSet.has(key));
|
|
961
|
+
if (overlap.length > 0) {
|
|
962
|
+
ctx.addIssue({
|
|
963
|
+
code: z.ZodIssueCode.custom,
|
|
964
|
+
message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
const validateMappingsAgainstVariableDefinitions$1 = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
|
|
969
|
+
const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
|
|
970
|
+
.filter(([_, def]) => def.group !== 'style')
|
|
971
|
+
.map(([key]) => key);
|
|
972
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
973
|
+
const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
|
|
974
|
+
const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
|
|
975
|
+
if (invalidMappings.length > 0) {
|
|
976
|
+
ctx.addIssue({
|
|
977
|
+
code: z.ZodIssueCode.custom,
|
|
978
|
+
message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
const validateMappingsAgainstParameterDefinitions$1 = (variableMappings, parameterDefinitions, ctx) => {
|
|
983
|
+
const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
|
|
984
|
+
for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
|
|
985
|
+
if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
|
|
986
|
+
ctx.addIssue({
|
|
987
|
+
code: z.ZodIssueCode.custom,
|
|
988
|
+
message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
const validatePassToNodes$1 = (rootChildren, componentSettings, ctx) => {
|
|
994
|
+
if (!componentSettings.prebindingDefinitions ||
|
|
995
|
+
componentSettings.prebindingDefinitions.length === 0) {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
|
|
999
|
+
let nodeIds = new Set();
|
|
1000
|
+
for (const paramDef of Object.values(parameterDefinitions || {})) {
|
|
1001
|
+
paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
|
|
1002
|
+
}
|
|
1003
|
+
treeVisit$1$1(rootChildren, (node) => {
|
|
1004
|
+
if (!node.id)
|
|
1005
|
+
return;
|
|
1006
|
+
if (nodeIds.has(node.id)) {
|
|
1007
|
+
nodeIds.delete(node.id);
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
if (nodeIds.size > 0) {
|
|
1011
|
+
const stringifiedNodeIds = Array.from(nodeIds)
|
|
1012
|
+
.map((id) => `"${id}"`)
|
|
1013
|
+
.join(', ');
|
|
1014
|
+
ctx.addIssue({
|
|
1015
|
+
code: z.ZodIssueCode.custom,
|
|
1016
|
+
message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
894
1020
|
|
|
895
1021
|
z
|
|
896
1022
|
.object({
|
|
@@ -3659,6 +3785,25 @@ z.object({
|
|
|
3659
3785
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
3660
3786
|
});
|
|
3661
3787
|
|
|
3788
|
+
function treeVisit$1(initialNode, onNode) {
|
|
3789
|
+
const _treeVisit = (currentNode) => {
|
|
3790
|
+
const children = [...currentNode.children];
|
|
3791
|
+
onNode(currentNode);
|
|
3792
|
+
for (const child of children) {
|
|
3793
|
+
_treeVisit(child);
|
|
3794
|
+
}
|
|
3795
|
+
};
|
|
3796
|
+
if (Array.isArray(initialNode)) {
|
|
3797
|
+
for (const node of initialNode) {
|
|
3798
|
+
_treeVisit(node);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
else {
|
|
3802
|
+
_treeVisit(initialNode);
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
const MAX_ALLOWED_PATHS = 200;
|
|
3662
3807
|
const THUMBNAIL_IDS = [
|
|
3663
3808
|
'columns',
|
|
3664
3809
|
'columnsPlusRight',
|
|
@@ -3689,7 +3834,17 @@ const THUMBNAIL_IDS = [
|
|
|
3689
3834
|
const VariableMappingSchema = z.object({
|
|
3690
3835
|
parameterId: propertyKeySchema,
|
|
3691
3836
|
type: z.literal('ContentTypeMapping'),
|
|
3692
|
-
pathsByContentType: z
|
|
3837
|
+
pathsByContentType: z
|
|
3838
|
+
.record(z.string(), z.object({ path: z.string() }))
|
|
3839
|
+
.superRefine((paths, ctx) => {
|
|
3840
|
+
const variableId = ctx.path[ctx.path.length - 2];
|
|
3841
|
+
if (Object.keys(paths).length > MAX_ALLOWED_PATHS) {
|
|
3842
|
+
ctx.addIssue({
|
|
3843
|
+
code: z.ZodIssueCode.custom,
|
|
3844
|
+
message: `Too many paths defined for variable mapping with id "${variableId}", maximum allowed is ${MAX_ALLOWED_PATHS}`,
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
}),
|
|
3693
3848
|
});
|
|
3694
3849
|
const PassToNodeSchema = z
|
|
3695
3850
|
.object({
|
|
@@ -3713,7 +3868,10 @@ const ParameterDefinitionSchema = z.object({
|
|
|
3713
3868
|
})
|
|
3714
3869
|
.optional(),
|
|
3715
3870
|
contentTypes: z.array(z.string()).min(1),
|
|
3716
|
-
passToNodes: z
|
|
3871
|
+
passToNodes: z
|
|
3872
|
+
.array(PassToNodeSchema)
|
|
3873
|
+
.max(1, 'At most one "passToNodes" element is allowed per parameter definition.')
|
|
3874
|
+
.optional(), // we might change this to be empty array for native parameter definitions, that's why we don't use .length(1)
|
|
3717
3875
|
});
|
|
3718
3876
|
const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
|
|
3719
3877
|
const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
|
|
@@ -3734,14 +3892,108 @@ const ComponentSettingsSchema = z
|
|
|
3734
3892
|
category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
|
|
3735
3893
|
prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
|
|
3736
3894
|
})
|
|
3737
|
-
.strict()
|
|
3738
|
-
|
|
3895
|
+
.strict()
|
|
3896
|
+
.superRefine((componentSettings, ctx) => {
|
|
3897
|
+
const { variableDefinitions, prebindingDefinitions } = componentSettings;
|
|
3898
|
+
if (!prebindingDefinitions || prebindingDefinitions.length === 0) {
|
|
3899
|
+
return;
|
|
3900
|
+
}
|
|
3901
|
+
const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions[0];
|
|
3902
|
+
validateAtMostOneNativeParameterDefinition(parameterDefinitions, ctx);
|
|
3903
|
+
validateNoOverlapBetweenMappingAndOverrides(variableMappings, allowedVariableOverrides, ctx);
|
|
3904
|
+
validateMappingsAgainstVariableDefinitions(variableMappings, allowedVariableOverrides, variableDefinitions, ctx);
|
|
3905
|
+
validateMappingsAgainstParameterDefinitions(variableMappings, parameterDefinitions, ctx);
|
|
3906
|
+
});
|
|
3907
|
+
z
|
|
3908
|
+
.object({
|
|
3739
3909
|
componentTree: localeWrapper(ComponentTreeSchema),
|
|
3740
3910
|
dataSource: localeWrapper(DataSourceSchema),
|
|
3741
3911
|
unboundValues: localeWrapper(UnboundValuesSchema),
|
|
3742
3912
|
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
3743
3913
|
componentSettings: localeWrapper(ComponentSettingsSchema),
|
|
3914
|
+
})
|
|
3915
|
+
.superRefine((patternFields, ctx) => {
|
|
3916
|
+
const { componentTree, componentSettings } = patternFields;
|
|
3917
|
+
// values at this point are wrapped under locale code
|
|
3918
|
+
const nonLocalisedComponentTree = Object.values(componentTree)[0];
|
|
3919
|
+
const nonLocalisedComponentSettings = Object.values(componentSettings)[0];
|
|
3920
|
+
if (!nonLocalisedComponentSettings || !nonLocalisedComponentTree) {
|
|
3921
|
+
return;
|
|
3922
|
+
}
|
|
3923
|
+
validatePassToNodes(nonLocalisedComponentTree.children || [], nonLocalisedComponentSettings || {}, ctx);
|
|
3744
3924
|
});
|
|
3925
|
+
const validateAtMostOneNativeParameterDefinition = (parameterDefinitions, ctx) => {
|
|
3926
|
+
const nativeParamDefinitions = Object.values(parameterDefinitions).filter((paramDefinition) => !(paramDefinition.passToNodes && paramDefinition.passToNodes.length > 0));
|
|
3927
|
+
if (nativeParamDefinitions.length > 1) {
|
|
3928
|
+
ctx.addIssue({
|
|
3929
|
+
code: z.ZodIssueCode.custom,
|
|
3930
|
+
message: `Only one native parameter definition (parameter definition without passToNodes) is allowed per prebinding definition.`,
|
|
3931
|
+
});
|
|
3932
|
+
}
|
|
3933
|
+
};
|
|
3934
|
+
const validateNoOverlapBetweenMappingAndOverrides = (variableMappings, allowedVariableOverrides, ctx) => {
|
|
3935
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
3936
|
+
const overridesSet = new Set(allowedVariableOverrides || []);
|
|
3937
|
+
const overlap = variableMappingKeys.filter((key) => overridesSet.has(key));
|
|
3938
|
+
if (overlap.length > 0) {
|
|
3939
|
+
ctx.addIssue({
|
|
3940
|
+
code: z.ZodIssueCode.custom,
|
|
3941
|
+
message: `Found both variable mapping and allowed override for the following keys: ${overlap.map((key) => `"${key}"`).join(', ')}.`,
|
|
3942
|
+
});
|
|
3943
|
+
}
|
|
3944
|
+
};
|
|
3945
|
+
const validateMappingsAgainstVariableDefinitions = (variableMappings, allowedVariableOverrides, variableDefinitions, ctx) => {
|
|
3946
|
+
const nonDesignVariableDefinitionKeys = Object.entries(variableDefinitions)
|
|
3947
|
+
.filter(([_, def]) => def.group !== 'style')
|
|
3948
|
+
.map(([key]) => key);
|
|
3949
|
+
const variableMappingKeys = Object.keys(variableMappings || {});
|
|
3950
|
+
const allKeys = [...variableMappingKeys, ...(allowedVariableOverrides || [])];
|
|
3951
|
+
const invalidMappings = allKeys.filter((key) => !nonDesignVariableDefinitionKeys.includes(key));
|
|
3952
|
+
if (invalidMappings.length > 0) {
|
|
3953
|
+
ctx.addIssue({
|
|
3954
|
+
code: z.ZodIssueCode.custom,
|
|
3955
|
+
message: `The following variable mappings or overrides are missing from the variable definitions: ${invalidMappings.map((key) => `"${key}"`).join(', ')}.`,
|
|
3956
|
+
});
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
const validateMappingsAgainstParameterDefinitions = (variableMappings, parameterDefinitions, ctx) => {
|
|
3960
|
+
const parameterDefinitionKeys = Object.keys(parameterDefinitions || {});
|
|
3961
|
+
for (const [mappingKey, mappingValue] of Object.entries(variableMappings || {})) {
|
|
3962
|
+
if (!parameterDefinitionKeys.includes(mappingValue.parameterId)) {
|
|
3963
|
+
ctx.addIssue({
|
|
3964
|
+
code: z.ZodIssueCode.custom,
|
|
3965
|
+
message: `The variable mapping with id "${mappingKey}" references a non-existing parameterId "${mappingValue.parameterId}".`,
|
|
3966
|
+
});
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
};
|
|
3970
|
+
const validatePassToNodes = (rootChildren, componentSettings, ctx) => {
|
|
3971
|
+
if (!componentSettings.prebindingDefinitions ||
|
|
3972
|
+
componentSettings.prebindingDefinitions.length === 0) {
|
|
3973
|
+
return;
|
|
3974
|
+
}
|
|
3975
|
+
const { parameterDefinitions } = componentSettings.prebindingDefinitions[0];
|
|
3976
|
+
let nodeIds = new Set();
|
|
3977
|
+
for (const paramDef of Object.values(parameterDefinitions || {})) {
|
|
3978
|
+
paramDef.passToNodes?.forEach((n) => nodeIds.add(n.nodeId));
|
|
3979
|
+
}
|
|
3980
|
+
treeVisit$1(rootChildren, (node) => {
|
|
3981
|
+
if (!node.id)
|
|
3982
|
+
return;
|
|
3983
|
+
if (nodeIds.has(node.id)) {
|
|
3984
|
+
nodeIds.delete(node.id);
|
|
3985
|
+
}
|
|
3986
|
+
});
|
|
3987
|
+
if (nodeIds.size > 0) {
|
|
3988
|
+
const stringifiedNodeIds = Array.from(nodeIds)
|
|
3989
|
+
.map((id) => `"${id}"`)
|
|
3990
|
+
.join(', ');
|
|
3991
|
+
ctx.addIssue({
|
|
3992
|
+
code: z.ZodIssueCode.custom,
|
|
3993
|
+
message: `The following node IDs referenced in passToNodes are not present in the component tree: ${stringifiedNodeIds}.`,
|
|
3994
|
+
});
|
|
3995
|
+
}
|
|
3996
|
+
};
|
|
3745
3997
|
|
|
3746
3998
|
z
|
|
3747
3999
|
.object({
|