@sanity/personalization-plugin 2.3.0 → 2.4.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
@@ -6559,7 +6559,7 @@ const useAddExperimentAction = (props) => {
6559
6559
  return props.renderDefault(previewProps);
6560
6560
  };
6561
6561
  function flattenSchemaType(schemaType) {
6562
- return sanity.isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 3) : (console.error("Schema type is not a document"), []);
6562
+ return sanity.isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 5) : (console.error("Schema type is not a document"), []);
6563
6563
  }
6564
6564
  function extractInnerFields(fields, path, maxDepth) {
6565
6565
  return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
@@ -6567,13 +6567,14 @@ function extractInnerFields(fields, path, maxDepth) {
6567
6567
  if (field.type.jsonType === "object") {
6568
6568
  const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth);
6569
6569
  return [...acc, thisFieldWithPath, ...innerFields];
6570
- } else if (field.type.jsonType === "array" && field.type.of.length && field.type.of.some((item) => "fields" in item)) {
6571
- const innerFields = extractInnerFields(
6572
- // @ts-expect-error - Fix TS assertion for array fields
6573
- field.type.of[0].fields,
6574
- [...path, field.name],
6575
- maxDepth
6576
- );
6570
+ } else if (field.type.jsonType === "array") {
6571
+ const innerFields = (field.type.of || []).reduce((arrayAcc, arrayType) => {
6572
+ if ("fields" in arrayType) {
6573
+ const typeFields = extractInnerFields(arrayType.fields, [...path, field.name], maxDepth);
6574
+ return [...arrayAcc, ...typeFields];
6575
+ }
6576
+ return arrayAcc;
6577
+ }, []);
6577
6578
  return [...acc, thisFieldWithPath, ...innerFields];
6578
6579
  }
6579
6580
  return [...acc, thisFieldWithPath];
@@ -6748,10 +6749,8 @@ const createExperimentType = ({
6748
6749
  form: {
6749
6750
  components: {
6750
6751
  input: (props) => {
6751
- if (!(props.id === "root" && sanity.isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).map(
6752
- (field) => field.type.name
6753
- ).some(
6754
- (name) => name.startsWith(experimentNameOverride)
6752
+ if (!(props.id === "root" && sanity.isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).some(
6753
+ (field) => field.type.name.startsWith(experimentNameOverride) || field.name.startsWith(experimentNameOverride)
6755
6754
  ))
6756
6755
  return props.renderDefault(props);
6757
6756
  const providerProps = {