@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.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, [],
|
|
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"
|
|
6571
|
-
const innerFields =
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
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).
|
|
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 = {
|