@sanity/personalization-plugin 2.4.0 → 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/README.md +143 -4
- package/dist/growthbook/index.js.map +1 -1
- package/dist/growthbook/index.mjs.map +1 -1
- package/dist/index.js +27 -6331
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -6331
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
- package/src/components/ExperimentItem.tsx +10 -0
- package/src/components/VariantInput.tsx +2 -1
- package/src/fieldExperiments.tsx +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/personalization-plugin",
|
|
3
|
-
"version": "2.4.
|
|
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,43 +49,43 @@
|
|
|
49
49
|
"prepare": "husky"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sanity/incompatible-plugin": "^1.0.
|
|
53
|
-
"@sanity/studio-secrets": "^3.0.
|
|
54
|
-
"@sanity/ui": "^2.
|
|
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.
|
|
57
|
+
"react-icons": "^5.5.0",
|
|
58
58
|
"suspend-react": "^0.1.3"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@commitlint/cli": "^19.
|
|
62
|
-
"@commitlint/config-conventional": "^19.
|
|
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.
|
|
67
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
68
|
-
"@typescript-eslint/parser": "^8.
|
|
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.
|
|
70
|
+
"eslint-config-prettier": "^9.1.2",
|
|
71
71
|
"eslint-config-sanity": "^7.1.4",
|
|
72
|
-
"eslint-plugin-prettier": "^5.
|
|
73
|
-
"eslint-plugin-react": "^7.37.
|
|
74
|
-
"eslint-plugin-react-hooks": "^5.
|
|
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.
|
|
78
|
-
"prettier-plugin-packagejson": "^2.5.
|
|
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.
|
|
82
|
-
"semantic-release": "^24.2.
|
|
83
|
-
"styled-components": "^6.1.
|
|
84
|
-
"typescript": "^5.
|
|
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",
|
|
88
|
-
"sanity": "^3"
|
|
88
|
+
"sanity": "^3 || ^4.0.0-0"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=18"
|
|
@@ -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
|
|
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
|
}
|
package/src/fieldExperiments.tsx
CHANGED
|
@@ -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`
|
|
@@ -64,6 +66,7 @@ const createExperimentType = ({
|
|
|
64
66
|
name: 'active',
|
|
65
67
|
type: 'boolean',
|
|
66
68
|
hidden: true,
|
|
69
|
+
initialValue: false,
|
|
67
70
|
}),
|
|
68
71
|
defineField({
|
|
69
72
|
name: experimentId,
|
|
@@ -105,6 +108,22 @@ const createExperimentType = ({
|
|
|
105
108
|
],
|
|
106
109
|
}),
|
|
107
110
|
],
|
|
111
|
+
preview: {
|
|
112
|
+
select: {
|
|
113
|
+
base: 'default',
|
|
114
|
+
experiment: experimentId,
|
|
115
|
+
},
|
|
116
|
+
prepare: ({base, experiment}) => {
|
|
117
|
+
const title = base?.title || base?.name || typeof base === 'string' ? base : ''
|
|
118
|
+
const experimentTitle = experiment ? `Experiment: ${experiment}` : ''
|
|
119
|
+
const media = base?.image || base?.photo || base?.media || ''
|
|
120
|
+
return {
|
|
121
|
+
title: title || experimentTitle,
|
|
122
|
+
subtitle: title ? experimentTitle : '',
|
|
123
|
+
media,
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
108
127
|
})
|
|
109
128
|
}
|
|
110
129
|
|