@contentful/experiences-visual-editor-react 3.7.0-prerelease-20250915T1724-8825648.0 → 3.7.0-prerelease-20250917T1034-42f0486.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 CHANGED
@@ -791,6 +791,19 @@ const ComponentVariableSchema$1 = z.object({
791
791
  });
792
792
  const ComponentTreeNodeSchema$1 = BaseComponentTreeNodeSchema$1.extend({
793
793
  children: z.lazy(() => ComponentTreeNodeSchema$1.array()),
794
+ }).superRefine(({ id, prebindingId, parameters }, ctx) => {
795
+ if (prebindingId && !parameters) {
796
+ ctx.addIssue({
797
+ code: z.ZodIssueCode.custom,
798
+ message: `Found "prebindingId" but no "parameters" for node with id: "${id}"`,
799
+ });
800
+ }
801
+ if (parameters && !prebindingId) {
802
+ ctx.addIssue({
803
+ code: z.ZodIssueCode.custom,
804
+ message: `Found "parameters" but no "prebindingId" for node with id: "${id}"`,
805
+ });
806
+ }
794
807
  });
795
808
  const ComponentTreeSchema$1 = z
796
809
  .object({
@@ -808,25 +821,6 @@ z.object({
808
821
  usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
809
822
  });
810
823
 
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;
830
824
  const THUMBNAIL_IDS$1 = [
831
825
  'columns',
832
826
  'columnsPlusRight',
@@ -857,17 +851,7 @@ const THUMBNAIL_IDS$1 = [
857
851
  const VariableMappingSchema$1 = z.object({
858
852
  parameterId: propertyKeySchema$1,
859
853
  type: z.literal('ContentTypeMapping'),
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
- }),
854
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
871
855
  });
872
856
  const PassToNodeSchema$1 = z
873
857
  .object({
@@ -891,10 +875,7 @@ const ParameterDefinitionSchema$1 = z.object({
891
875
  })
892
876
  .optional(),
893
877
  contentTypes: z.array(z.string()).min(1),
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)
878
+ passToNodes: z.array(PassToNodeSchema$1).optional(),
898
879
  });
899
880
  const ParameterDefinitionsSchema$1 = z.record(propertyKeySchema$1, ParameterDefinitionSchema$1);
900
881
  const VariableMappingsSchema$1 = z.record(propertyKeySchema$1, VariableMappingSchema$1);
@@ -915,107 +896,14 @@ const ComponentSettingsSchema$1 = z
915
896
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
916
897
  prebindingDefinitions: z.array(PrebindingDefinitionSchema$1).length(1).optional(),
917
898
  })
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({
899
+ .strict();
900
+ z.object({
932
901
  componentTree: localeWrapper$1(ComponentTreeSchema$1),
933
902
  dataSource: localeWrapper$1(DataSourceSchema$1),
934
903
  unboundValues: localeWrapper$1(UnboundValuesSchema$1),
935
904
  usedComponents: localeWrapper$1(UsedComponentsSchema$1).optional(),
936
905
  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);
947
906
  });
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
- };
1019
907
 
1020
908
  z
1021
909
  .object({
@@ -3764,6 +3652,19 @@ const ComponentVariableSchema = z.object({
3764
3652
  });
3765
3653
  const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
3766
3654
  children: z.lazy(() => ComponentTreeNodeSchema.array()),
3655
+ }).superRefine(({ id, prebindingId, parameters }, ctx) => {
3656
+ if (prebindingId && !parameters) {
3657
+ ctx.addIssue({
3658
+ code: z.ZodIssueCode.custom,
3659
+ message: `Found "prebindingId" but no "parameters" for node with id: "${id}"`,
3660
+ });
3661
+ }
3662
+ if (parameters && !prebindingId) {
3663
+ ctx.addIssue({
3664
+ code: z.ZodIssueCode.custom,
3665
+ message: `Found "parameters" but no "prebindingId" for node with id: "${id}"`,
3666
+ });
3667
+ }
3767
3668
  });
3768
3669
  const ComponentTreeSchema = z
3769
3670
  .object({
@@ -3781,25 +3682,6 @@ z.object({
3781
3682
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
3782
3683
  });
3783
3684
 
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;
3803
3685
  const THUMBNAIL_IDS = [
3804
3686
  'columns',
3805
3687
  'columnsPlusRight',
@@ -3830,17 +3712,7 @@ const THUMBNAIL_IDS = [
3830
3712
  const VariableMappingSchema = z.object({
3831
3713
  parameterId: propertyKeySchema,
3832
3714
  type: z.literal('ContentTypeMapping'),
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
- }),
3715
+ pathsByContentType: z.record(z.string(), z.object({ path: z.string() })),
3844
3716
  });
3845
3717
  const PassToNodeSchema = z
3846
3718
  .object({
@@ -3864,10 +3736,7 @@ const ParameterDefinitionSchema = z.object({
3864
3736
  })
3865
3737
  .optional(),
3866
3738
  contentTypes: z.array(z.string()).min(1),
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)
3739
+ passToNodes: z.array(PassToNodeSchema).optional(),
3871
3740
  });
3872
3741
  const ParameterDefinitionsSchema = z.record(propertyKeySchema, ParameterDefinitionSchema);
3873
3742
  const VariableMappingsSchema = z.record(propertyKeySchema, VariableMappingSchema);
@@ -3888,107 +3757,14 @@ const ComponentSettingsSchema = z
3888
3757
  category: z.string().max(50, 'Category must contain at most 50 characters').optional(),
3889
3758
  prebindingDefinitions: z.array(PrebindingDefinitionSchema).length(1).optional(),
3890
3759
  })
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({
3760
+ .strict();
3761
+ z.object({
3905
3762
  componentTree: localeWrapper(ComponentTreeSchema),
3906
3763
  dataSource: localeWrapper(DataSourceSchema),
3907
3764
  unboundValues: localeWrapper(UnboundValuesSchema),
3908
3765
  usedComponents: localeWrapper(UsedComponentsSchema).optional(),
3909
3766
  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);
3920
3767
  });
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
- };
3992
3768
 
3993
3769
  z
3994
3770
  .object({