@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 +11 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/fieldExperiments.tsx +6 -5
- package/src/utils/flattenSchemaType.ts +11 -14
package/dist/index.mjs
CHANGED
|
@@ -6560,7 +6560,7 @@ const useAddExperimentAction = (props) => {
|
|
|
6560
6560
|
return props.renderDefault(previewProps);
|
|
6561
6561
|
};
|
|
6562
6562
|
function flattenSchemaType(schemaType) {
|
|
6563
|
-
return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [],
|
|
6563
|
+
return isDocumentSchemaType(schemaType) ? extractInnerFields(schemaType.fields, [], 5) : (console.error("Schema type is not a document"), []);
|
|
6564
6564
|
}
|
|
6565
6565
|
function extractInnerFields(fields, path, maxDepth) {
|
|
6566
6566
|
return path.length >= maxDepth ? [] : fields.reduce((acc, field) => {
|
|
@@ -6568,13 +6568,14 @@ function extractInnerFields(fields, path, maxDepth) {
|
|
|
6568
6568
|
if (field.type.jsonType === "object") {
|
|
6569
6569
|
const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth);
|
|
6570
6570
|
return [...acc, thisFieldWithPath, ...innerFields];
|
|
6571
|
-
} else if (field.type.jsonType === "array"
|
|
6572
|
-
const innerFields =
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6571
|
+
} else if (field.type.jsonType === "array") {
|
|
6572
|
+
const innerFields = (field.type.of || []).reduce((arrayAcc, arrayType) => {
|
|
6573
|
+
if ("fields" in arrayType) {
|
|
6574
|
+
const typeFields = extractInnerFields(arrayType.fields, [...path, field.name], maxDepth);
|
|
6575
|
+
return [...arrayAcc, ...typeFields];
|
|
6576
|
+
}
|
|
6577
|
+
return arrayAcc;
|
|
6578
|
+
}, []);
|
|
6578
6579
|
return [...acc, thisFieldWithPath, ...innerFields];
|
|
6579
6580
|
}
|
|
6580
6581
|
return [...acc, thisFieldWithPath];
|
|
@@ -6749,10 +6750,8 @@ const createExperimentType = ({
|
|
|
6749
6750
|
form: {
|
|
6750
6751
|
components: {
|
|
6751
6752
|
input: (props) => {
|
|
6752
|
-
if (!(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).
|
|
6753
|
-
(field) => field.type.name
|
|
6754
|
-
).some(
|
|
6755
|
-
(name) => name.startsWith(experimentNameOverride)
|
|
6753
|
+
if (!(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).some(
|
|
6754
|
+
(field) => field.type.name.startsWith(experimentNameOverride) || field.name.startsWith(experimentNameOverride)
|
|
6756
6755
|
))
|
|
6757
6756
|
return props.renderDefault(props);
|
|
6758
6757
|
const providerProps = {
|