@sanity/personalization-plugin 2.4.1 → 2.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/personalization-plugin",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Plugin to help with personalization, a/b testing when using Sanity",
5
5
  "keywords": [
6
6
  "sanity",
@@ -49,39 +49,39 @@
49
49
  "prepare": "husky"
50
50
  },
51
51
  "dependencies": {
52
- "@sanity/incompatible-plugin": "^1.0.4",
53
- "@sanity/studio-secrets": "^3.0.0",
54
- "@sanity/ui": "^2.8.19",
52
+ "@sanity/incompatible-plugin": "^1.0.5",
53
+ "@sanity/studio-secrets": "^3.0.2",
54
+ "@sanity/ui": "^2.16.12",
55
55
  "@sanity/uuid": "^3.0.2",
56
56
  "fast-deep-equal": "^3.1.3",
57
- "react-icons": "^5.4.0",
57
+ "react-icons": "^5.5.0",
58
58
  "suspend-react": "^0.1.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@commitlint/cli": "^19.7.1",
62
- "@commitlint/config-conventional": "^19.7.1",
61
+ "@commitlint/cli": "^19.8.1",
62
+ "@commitlint/config-conventional": "^19.8.1",
63
63
  "@sanity/pkg-utils": "^6.13.4",
64
64
  "@sanity/plugin-kit": "^4.0.19",
65
65
  "@sanity/semantic-release-preset": "^5.0.0",
66
- "@types/react": "^18.3.18",
67
- "@typescript-eslint/eslint-plugin": "^8.23.0",
68
- "@typescript-eslint/parser": "^8.23.0",
66
+ "@types/react": "^18.3.23",
67
+ "@typescript-eslint/eslint-plugin": "^8.39.1",
68
+ "@typescript-eslint/parser": "^8.39.1",
69
69
  "eslint": "^8.57.1",
70
- "eslint-config-prettier": "^9.1.0",
70
+ "eslint-config-prettier": "^9.1.2",
71
71
  "eslint-config-sanity": "^7.1.4",
72
- "eslint-plugin-prettier": "^5.2.3",
73
- "eslint-plugin-react": "^7.37.4",
74
- "eslint-plugin-react-hooks": "^5.1.0",
72
+ "eslint-plugin-prettier": "^5.5.4",
73
+ "eslint-plugin-react": "^7.37.5",
74
+ "eslint-plugin-react-hooks": "^5.2.0",
75
75
  "husky": "^9.1.7",
76
76
  "lint-staged": "^15.2.10",
77
- "prettier": "^3.4.2",
78
- "prettier-plugin-packagejson": "^2.5.8",
77
+ "prettier": "^3.6.2",
78
+ "prettier-plugin-packagejson": "^2.5.19",
79
79
  "react": "^18.3.1",
80
80
  "react-dom": "^18.3.1",
81
- "sanity": "^3.74.1",
82
- "semantic-release": "^24.2.1",
83
- "styled-components": "^6.1.15",
84
- "typescript": "^5.7.3"
81
+ "sanity": "^3.99.0",
82
+ "semantic-release": "^24.2.7",
83
+ "styled-components": "^6.1.19",
84
+ "typescript": "^5.9.2"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "react": "^18 || ^19",
@@ -0,0 +1,10 @@
1
+ import {ObjectItem, ObjectItemProps, set} from 'sanity'
2
+
3
+ export const ExperimentItem = (props: ObjectItemProps) => {
4
+ const {active} = props.value as ObjectItem & {active: boolean}
5
+ if (!active) {
6
+ props.inputProps.onChange(set(true, ['active']))
7
+ }
8
+
9
+ return props.renderDefault(props)
10
+ }
@@ -2,7 +2,8 @@ import {Button, Inline, Stack} from '@sanity/ui'
2
2
  import {ObjectInputProps, set, useFormValue} from 'sanity'
3
3
 
4
4
  export const VariantInput = (props: ObjectInputProps) => {
5
- const defaultValue = useFormValue([props.path[0], 'default'])
5
+ const experimentPath = props.path.slice(0, -2)
6
+ const defaultValue = useFormValue([...experimentPath, 'default'])
6
7
  const handleClick = () => {
7
8
  props.onChange(set(defaultValue, ['value']))
8
9
  }
@@ -11,6 +11,7 @@ import {ArrayInput} from './components/Array'
11
11
  import {CONFIG_DEFAULT, ExperimentProvider} from './components/ExperimentContext'
12
12
  import {ExperimentField} from './components/ExperimentField'
13
13
  import {ExperimentInput} from './components/ExperimentInput'
14
+ import {ExperimentItem} from './components/ExperimentItem'
14
15
  import {VariantInput} from './components/VariantInput'
15
16
  import {VariantPreview} from './components/VariantPreview'
16
17
  import {FieldPluginConfig} from './types'
@@ -47,6 +48,7 @@ const createExperimentType = ({
47
48
  variantNameOverride={variantNameOverride}
48
49
  />
49
50
  ),
51
+ item: ExperimentItem,
50
52
  },
51
53
  fields: [
52
54
  typeof field === `string`
@@ -112,7 +114,7 @@ const createExperimentType = ({
112
114
  experiment: experimentId,
113
115
  },
114
116
  prepare: ({base, experiment}) => {
115
- const title = base?.title || base?.name || ''
117
+ const title = base?.title || base?.name || typeof base === 'string' ? base : ''
116
118
  const experimentTitle = experiment ? `Experiment: ${experiment}` : ''
117
119
  const media = base?.image || base?.photo || base?.media || ''
118
120
  return {