@sanity/personalization-plugin 2.3.0-launch-darkly.2 → 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/README.md +2 -0
- package/dist/growthbook/index.d.mts +15 -0
- package/dist/growthbook/index.d.ts +15 -0
- package/dist/growthbook/index.js +120 -0
- package/dist/growthbook/index.js.map +1 -0
- package/dist/growthbook/index.mjs +124 -0
- package/dist/growthbook/index.mjs.map +1 -0
- package/dist/index.d.mts +188 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.js +15 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/components/ExperimentField.tsx +1 -5
- package/src/components/ExperimentInput.tsx +6 -5
- package/src/fieldExperiments.tsx +6 -5
- package/src/growthbook/Components/GrowthbookContext.tsx +38 -0
- package/src/{launchDarkly/components → growthbook/Components}/Secrets.tsx +6 -5
- package/src/growthbook/index.ts +54 -0
- package/src/growthbook/types.ts +15 -0
- package/src/growthbook/utils.ts +94 -0
- package/src/types.ts +176 -0
- package/src/utils/flattenSchemaType.ts +11 -14
- package/dist/launchDarkly/index.d.mts +0 -12
- package/dist/launchDarkly/index.d.ts +0 -12
- package/dist/launchDarkly/index.js +0 -103
- package/dist/launchDarkly/index.js.map +0 -1
- package/dist/launchDarkly/index.mjs +0 -107
- package/dist/launchDarkly/index.mjs.map +0 -1
- package/src/launchDarkly/components/LaunchDarklyContext.tsx +0 -36
- package/src/launchDarkly/index.ts +0 -52
- package/src/launchDarkly/types.ts +0 -193
- package/src/launchDarkly/utils.ts +0 -54
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useClient, useWorkspace, useFormValue, defineDocumentFieldAction, set, unset, useDocumentOperation, isReference, isImage, isDocumentSchemaType, definePlugin, isObjectInputProps, defineType, defineField } from "sanity";
|
|
2
|
+
import { useClient, useWorkspace, useFormValue, defineDocumentFieldAction, set, unset, useDocumentOperation, getPublishedId, isReference, isImage, isDocumentSchemaType, definePlugin, isObjectInputProps, defineType, defineField } from "sanity";
|
|
3
3
|
import { Stack, Inline, Button, Select as Select$1, Card, Text } from "@sanity/ui";
|
|
4
4
|
import { uuid } from "@sanity/uuid";
|
|
5
5
|
import { createContext, useMemo, useContext, useCallback, forwardRef, useState, useEffect } from "react";
|
|
@@ -6505,20 +6505,20 @@ const useAddExperimentAction = (props) => {
|
|
|
6505
6505
|
title: experiment.label,
|
|
6506
6506
|
value: experiment.id
|
|
6507
6507
|
})), ExperimentInput = (props) => {
|
|
6508
|
-
const { experiments } = useExperimentContext(), id = useFormValue(["_id"]),
|
|
6508
|
+
const { experiments } = useExperimentContext(), id = useFormValue(["_id"]), additionalChangePath = useMemo(
|
|
6509
6509
|
() => [...props.path.slice(0, -1), `${props.variantNameOverride}s`],
|
|
6510
6510
|
[props.variantNameOverride, props.path]
|
|
6511
|
-
), subValues = useFormValue(
|
|
6511
|
+
), subValues = useFormValue(additionalChangePath), { patch } = useDocumentOperation(getPublishedId(id), props.schemaType.name), handleChange = useCallback(
|
|
6512
6512
|
(event, onChange) => {
|
|
6513
6513
|
const inputValue = event.currentTarget.value;
|
|
6514
6514
|
if (onChange(inputValue ? set(inputValue) : unset()), subValues) {
|
|
6515
6515
|
const patchEvent = {
|
|
6516
|
-
unset: [
|
|
6516
|
+
unset: [additionalChangePath.join(".")]
|
|
6517
6517
|
};
|
|
6518
6518
|
patch.execute([patchEvent]);
|
|
6519
6519
|
}
|
|
6520
6520
|
},
|
|
6521
|
-
[patch, subValues,
|
|
6521
|
+
[patch, subValues, additionalChangePath]
|
|
6522
6522
|
);
|
|
6523
6523
|
return experiments.length ? /* @__PURE__ */ jsx(Select, { ...props, listOptions: formatlistOptions(experiments), handleChange }) : /* @__PURE__ */ jsx(Card, { padding: [3, 3, 4], radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxs(Text, { align: "center", size: [2, 2, 3], children: [
|
|
6524
6524
|
"There are no defined ",
|
|
@@ -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 = {
|