@sanity/personalization-plugin 3.0.10 → 3.1.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 CHANGED
@@ -48,8 +48,6 @@ Once configured you can query the values using the ids of the experiment and var
48
48
  - [Stored Data Structure](#stored-data-structure)
49
49
  - [Querying with Custom Field Names](#querying-with-custom-field-names)
50
50
  - [License](#license)
51
- - [Develop \& test](#develop--test)
52
- - [Release new version](#release-new-version)
53
51
 
54
52
  > For Specific information about the Growthbook FieldLevel export see its [readme](/growthbook.md)
55
53
  >
@@ -892,18 +890,3 @@ const page = await client.fetch(query, {
892
890
  ## License
893
891
 
894
892
  [MIT](LICENSE) © Jon Burbridge
895
-
896
- ## Develop & test
897
-
898
- This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
899
- with default configuration for build & watch scripts.
900
-
901
- See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
902
- on how to run this plugin with hotreload in the studio.
903
-
904
- ### Release new version
905
-
906
- Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-personalization/actions/workflows/main.yml).
907
- Make sure to select the main branch and check "Release new version".
908
-
909
- Semantic release will only release on configured branches, so it is safe to run release on any branch.
@@ -1,14 +1,21 @@
1
1
  import { defineDocumentFieldAction, defineField, definePlugin, defineType, getPublishedId, isDocumentSchemaType, isImage, isObjectInputProps, isReference, set, unset, useClient, useDocumentOperation, useFormValue, useWorkspace } from "sanity";
2
2
  import { c } from "react/compiler-runtime";
3
+ import { createContext, useContext, useEffect, useState } from "react";
3
4
  import { Button, Card, Inline, Select, Stack, Text } from "@sanity/ui";
4
5
  import { uuid } from "@sanity/uuid";
5
- import { createContext, useContext, useEffect, useState } from "react";
6
6
  import equal from "fast-deep-equal";
7
7
  import { suspend } from "suspend-react";
8
8
  import { jsx, jsxs } from "react/jsx-runtime";
9
9
  import { CloseIcon } from "@sanity/icons/Close";
10
10
  import { GiSoapExperiment } from "react-icons/gi";
11
- const CONFIG_DEFAULT = {
11
+ const ArrayItem = (props) => {
12
+ let $ = c(6), { active } = props.value, { onChange } = props.inputProps, t0, t1;
13
+ $[0] !== active || $[1] !== onChange ? (t0 = () => {
14
+ active || onChange(set(!0, ["active"]));
15
+ }, t1 = [active, onChange], $[0] = active, $[1] = onChange, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1);
16
+ let t2;
17
+ return $[4] === props ? t2 = $[5] : (t2 = props.renderDefault(props), $[4] = props, $[5] = t2), t2;
18
+ }, CONFIG_DEFAULT = {
12
19
  fields: [],
13
20
  apiVersion: "2024-11-07",
14
21
  experimentNameOverride: "experiment",
@@ -27,7 +34,7 @@ function ExperimentProvider(props) {
27
34
  let $ = c(14), { experimentFieldPluginConfig } = props, t0;
28
35
  $[0] === experimentFieldPluginConfig.apiVersion ? t0 = $[1] : (t0 = { apiVersion: experimentFieldPluginConfig.apiVersion }, $[0] = experimentFieldPluginConfig.apiVersion, $[1] = t0);
29
36
  let client = useClient(t0), workspace = useWorkspace(), t1;
30
- $[2] !== client || $[3] !== experimentFieldPluginConfig || $[4] !== workspace ? (t1 = Array.isArray(experimentFieldPluginConfig.experiments) ? experimentFieldPluginConfig.experiments : suspend(async () => typeof experimentFieldPluginConfig.experiments == "function" ? experimentFieldPluginConfig.experiments(client) : experimentFieldPluginConfig.experiments, [workspace], { equal }), $[2] = client, $[3] = experimentFieldPluginConfig, $[4] = workspace, $[5] = t1) : t1 = $[5];
37
+ $[2] !== client || $[3] !== experimentFieldPluginConfig || $[4] !== workspace ? (t1 = Array.isArray(experimentFieldPluginConfig.experiments) ? experimentFieldPluginConfig.experiments : suspend(async () => typeof experimentFieldPluginConfig.experiments == "function" ? experimentFieldPluginConfig.experiments(client) : experimentFieldPluginConfig.experiments, [workspace, "field-level-experiments"], { equal }), $[2] = client, $[3] = experimentFieldPluginConfig, $[4] = workspace, $[5] = t1) : t1 = $[5];
31
38
  let experiments = t1, t2;
32
39
  $[6] !== experimentFieldPluginConfig || $[7] !== experiments ? (t2 = {
33
40
  ...experimentFieldPluginConfig,
@@ -84,7 +91,31 @@ const ArrayInput = (props) => {
84
91
  function _temp$2() {
85
92
  return null;
86
93
  }
87
- const useAddExperimentAction = (props) => {
94
+ /**
95
+ * Safely updates deeply nested children props to clear groups array
96
+ * This prevents field grouping UI conflicts in personalization mode
97
+ */
98
+ const clearChildrenGroups = (props) => {
99
+ let children = props.children;
100
+ if (!children || typeof children != "object" || !children.props) return props;
101
+ let innerChild = children.props.children;
102
+ return !innerChild || typeof innerChild != "object" || Array.isArray(innerChild) || !("props" in innerChild) ? props : {
103
+ ...props,
104
+ children: {
105
+ ...children,
106
+ props: {
107
+ ...children.props,
108
+ children: {
109
+ ...innerChild,
110
+ props: {
111
+ ...innerChild.props,
112
+ groups: []
113
+ }
114
+ }
115
+ }
116
+ }
117
+ };
118
+ }, useAddExperimentAction = (props) => {
88
119
  let $ = c(6), { onChange, active, experimentNameOverride } = props, t0;
89
120
  $[0] !== active || $[1] !== onChange ? (t0 = () => {
90
121
  onChange([set(!active, ["active"])]);
@@ -139,8 +170,8 @@ const useAddExperimentAction = (props) => {
139
170
  })
140
171
  });
141
172
  return active ? removeAction : addAction;
142
- }, ExperimentField = (props) => {
143
- let $ = c(20), { onChange } = props.inputProps, { inputId, experimentNameOverride, experimentId, variantNameOverride } = props, active = props.value?.active, t0;
173
+ }, Field = (props) => {
174
+ let $ = c(22), { onChange } = props.inputProps, { inputId, experimentNameOverride, experimentId, variantNameOverride } = props, active = props.value?.active, t0;
144
175
  $[0] !== active || $[1] !== experimentId || $[2] !== experimentNameOverride || $[3] !== inputId || $[4] !== onChange || $[5] !== variantNameOverride ? (t0 = {
145
176
  onChange,
146
177
  inputId,
@@ -156,12 +187,14 @@ const useAddExperimentAction = (props) => {
156
187
  let t3;
157
188
  $[11] !== oldActions || $[12] !== t2 ? (t3 = [t2, ...oldActions], $[11] = oldActions, $[12] = t2, $[13] = t3) : t3 = $[13];
158
189
  let memoizedActions = t3, t4;
159
- $[14] !== memoizedActions || $[15] !== props ? (t4 = {
160
- ...props,
190
+ $[14] === props ? t4 = $[15] : (t4 = clearChildrenGroups(props), $[14] = props, $[15] = t4);
191
+ let propsWithClearedGroups = t4, t5;
192
+ $[16] !== memoizedActions || $[17] !== propsWithClearedGroups ? (t5 = {
193
+ ...propsWithClearedGroups,
161
194
  actions: memoizedActions
162
- }, $[14] = memoizedActions, $[15] = props, $[16] = t4) : t4 = $[16];
163
- let withActionProps = t4, t5;
164
- return $[17] !== props.renderDefault || $[18] !== withActionProps ? (t5 = props.renderDefault(withActionProps), $[17] = props.renderDefault, $[18] = withActionProps, $[19] = t5) : t5 = $[19], t5;
195
+ }, $[16] = memoizedActions, $[17] = propsWithClearedGroups, $[18] = t5) : t5 = $[18];
196
+ let enhancedProps = t5, t6;
197
+ return $[19] !== enhancedProps || $[20] !== props.renderDefault ? (t6 = props.renderDefault(enhancedProps), $[19] = enhancedProps, $[20] = props.renderDefault, $[21] = t6) : t6 = $[21], t6;
165
198
  }, Select$1 = (props) => {
166
199
  let $ = c(12), { value, onChange, elementProps, listOptions, handleChange } = props, t0;
167
200
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [
@@ -199,7 +232,7 @@ function _temp$1(t0) {
199
232
  const formatlistOptions = (experiments) => experiments.map((experiment) => ({
200
233
  title: experiment.label,
201
234
  value: experiment.id
202
- })), ExperimentInput = (props) => {
235
+ })), Input = (props) => {
203
236
  let $ = c(20), { experiments } = useExperimentContext(), t0;
204
237
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = ["_id"], $[0] = t0) : t0 = $[0];
205
238
  let id = useFormValue(t0), t1;
@@ -253,9 +286,6 @@ const formatlistOptions = (experiments) => experiments.map((experiment) => ({
253
286
  listOptions: t4,
254
287
  handleChange
255
288
  }), $[16] = handleChange, $[17] = props, $[18] = t4, $[19] = t5) : t5 = $[19], t5;
256
- }, ExperimentItem = (props) => {
257
- let { active } = props.value;
258
- return active || props.inputProps.onChange(set(!0, ["active"])), props.renderDefault(props);
259
289
  }, VariantInput = (props) => {
260
290
  let $ = c(13), t0, t1;
261
291
  if ($[0] !== props.path) {
@@ -283,54 +313,55 @@ const formatlistOptions = (experiments) => experiments.map((experiment) => ({
283
313
  children: [t3, t4]
284
314
  }), $[10] = t3, $[11] = t4, $[12] = t5) : t5 = $[12], t5;
285
315
  }, VariantPreview = (props) => {
286
- let $ = c(25), [subtitle, setSubtitle] = useState(void 0), [title, setTitle] = useState(void 0), [media, setMedia] = useState(void 0), t0;
287
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: "2025-01-01" }, $[0] = t0) : t0 = $[0];
288
- let client = useClient(t0), { experiments } = useExperimentContext(), { experiment, variant, value } = props, selectedExperiment, t1;
289
- if ($[1] !== experiment || $[2] !== experiments || $[3] !== variant) {
316
+ let $ = c(26), [subtitle, setSubtitle] = useState(void 0), [title, setTitle] = useState(void 0), [media, setMedia] = useState(void 0), { experiments, apiVersion } = useExperimentContext(), t0;
317
+ $[0] === apiVersion ? t0 = $[1] : (t0 = { apiVersion }, $[0] = apiVersion, $[1] = t0);
318
+ let client = useClient(t0), { experiment, variant, value } = props, selectedExperiment, t1;
319
+ if ($[2] !== experiment || $[3] !== experiments || $[4] !== variant) {
290
320
  let t2;
291
- $[6] === experiment ? t2 = $[7] : (t2 = (experimentItem) => experimentItem.id === experiment, $[6] = experiment, $[7] = t2), selectedExperiment = experiments.find(t2), t1 = selectedExperiment?.variants.find((variantItem) => variantItem.id === variant), $[1] = experiment, $[2] = experiments, $[3] = variant, $[4] = selectedExperiment, $[5] = t1;
292
- } else selectedExperiment = $[4], t1 = $[5];
321
+ $[7] === experiment ? t2 = $[8] : (t2 = (experimentItem) => experimentItem.id === experiment, $[7] = experiment, $[8] = t2), selectedExperiment = experiments.find(t2), t1 = selectedExperiment?.variants.find((variantItem) => variantItem.id === variant), $[2] = experiment, $[3] = experiments, $[4] = variant, $[5] = selectedExperiment, $[6] = t1;
322
+ } else selectedExperiment = $[5], t1 = $[6];
293
323
  let selectedVariant = t1, t2;
294
- $[8] !== client || $[9] !== props.schemaType || $[10] !== selectedExperiment?.label || $[11] !== selectedVariant?.label || $[12] !== value ? (t2 = () => {
295
- (async () => {
296
- if (setTitle(`${selectedExperiment?.label} - ${selectedVariant?.label}`), typeof value == "string") return setSubtitle(value);
324
+ $[9] !== client || $[10] !== props.schemaType || $[11] !== selectedExperiment || $[12] !== selectedVariant || $[13] !== value ? (t2 = () => {
325
+ let getSubtitle = async () => {
326
+ if (setTitle(selectedExperiment?.label && selectedVariant?.label ? `${selectedExperiment.label} - ${selectedVariant.label}` : selectedExperiment?.label || selectedVariant?.label), typeof value == "string") return setSubtitle(value);
297
327
  if (isReference(value)) {
298
328
  let doc = await client.getDocument(value._ref), referenceType = (props.schemaType.fields.find(_temp)?.type).to.find((field_0) => field_0.type?.name === doc?._type), selectFields = {}, previewFields = referenceType?.preview?.select || {};
299
329
  Object.keys(previewFields).forEach((key) => {
300
330
  let valueKey = referenceType?.preview?.select?.[key];
301
- selectFields[key] = valueKey && doc ? valueKey?.split(".").reduce(_temp2, doc) : void 0;
331
+ selectFields[key] = valueKey && doc ? valueKey.split(".").reduce(_temp2, doc) : void 0;
302
332
  });
303
333
  let previewContent = referenceType?.preview?.prepare?.(selectFields);
304
334
  return setMedia(previewContent?.media || selectFields.media), setSubtitle(previewContent?.title || selectFields.title);
305
335
  }
306
336
  return isImage(value) && setMedia(value), "";
307
- })();
308
- }, $[8] = client, $[9] = props.schemaType, $[10] = selectedExperiment?.label, $[11] = selectedVariant?.label, $[12] = value, $[13] = t2) : t2 = $[13];
337
+ };
338
+ getSubtitle();
339
+ }, $[9] = client, $[10] = props.schemaType, $[11] = selectedExperiment, $[12] = selectedVariant, $[13] = value, $[14] = t2) : t2 = $[14];
309
340
  let t3 = selectedExperiment?.label, t4 = selectedVariant?.label, t5;
310
- $[14] !== client || $[15] !== props.schemaType || $[16] !== t3 || $[17] !== t4 || $[18] !== value ? (t5 = [
341
+ $[15] !== client || $[16] !== props.schemaType || $[17] !== t3 || $[18] !== t4 || $[19] !== value ? (t5 = [
311
342
  value,
312
343
  client,
313
344
  t3,
314
345
  t4,
315
346
  props.schemaType
316
- ], $[14] = client, $[15] = props.schemaType, $[16] = t3, $[17] = t4, $[18] = value, $[19] = t5) : t5 = $[19], useEffect(t2, t5);
347
+ ], $[15] = client, $[16] = props.schemaType, $[17] = t3, $[18] = t4, $[19] = value, $[20] = t5) : t5 = $[20], useEffect(t2, t5);
317
348
  let t6;
318
- if ($[20] !== media || $[21] !== props || $[22] !== subtitle || $[23] !== title) {
349
+ if ($[21] !== media || $[22] !== props || $[23] !== subtitle || $[24] !== title) {
319
350
  let previewProps = {
320
351
  ...props,
321
352
  title,
322
353
  subtitle,
323
354
  media
324
355
  };
325
- t6 = props.renderDefault(previewProps), $[20] = media, $[21] = props, $[22] = subtitle, $[23] = title, $[24] = t6;
326
- } else t6 = $[24];
356
+ t6 = props.renderDefault(previewProps), $[21] = media, $[22] = props, $[23] = subtitle, $[24] = title, $[25] = t6;
357
+ } else t6 = $[25];
327
358
  return t6;
328
359
  };
329
360
  function _temp(field) {
330
361
  return field.name === "value";
331
362
  }
332
363
  function _temp2(acc, index) {
333
- return acc[index];
364
+ return acc?.[index];
334
365
  }
335
366
  /**
336
367
  * Flattens a document's schema type into a flat array of fields and includes their path
@@ -356,22 +387,41 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
356
387
  return defineType({
357
388
  name: `${experimentNameOverride}${usedName}`,
358
389
  type: "object",
390
+ groups: [
391
+ {
392
+ name: "default",
393
+ title: "Default",
394
+ hidden: ({ parent }) => !Array.isArray(parent)
395
+ },
396
+ {
397
+ name: "experiments",
398
+ title: "Experiments",
399
+ hidden: ({ parent }) => !Array.isArray(parent)
400
+ },
401
+ {
402
+ name: "all-fields",
403
+ title: "All fields",
404
+ hidden: ({ parent }) => Array.isArray(parent)
405
+ }
406
+ ],
359
407
  components: {
360
- field: (props) => /* @__PURE__ */ jsx(ExperimentField, {
408
+ field: (props) => /* @__PURE__ */ jsx(Field, {
361
409
  ...props,
362
410
  experimentId,
363
411
  experimentNameOverride,
364
412
  variantNameOverride
365
413
  }),
366
- item: ExperimentItem
414
+ item: ArrayItem
367
415
  },
368
416
  fields: [
369
417
  typeof field == "string" ? defineField({
370
418
  name: "default",
371
- type: field
419
+ type: field,
420
+ group: "default"
372
421
  }) : {
373
422
  ...field,
374
- name: "default"
423
+ name: "default",
424
+ group: "default"
375
425
  },
376
426
  defineField({
377
427
  name: "active",
@@ -382,7 +432,8 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
382
432
  defineField({
383
433
  name: experimentId,
384
434
  type: "string",
385
- components: { input: (props) => /* @__PURE__ */ jsx(ExperimentInput, {
435
+ group: "experiments",
436
+ components: { input: (props) => /* @__PURE__ */ jsx(Input, {
386
437
  ...props,
387
438
  experimentNameOverride,
388
439
  variantNameOverride
@@ -392,6 +443,7 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
392
443
  defineField({
393
444
  name: variantArrayName,
394
445
  type: "array",
446
+ group: "experiments",
395
447
  hidden: ({ parent }) => !parent?.[experimentId],
396
448
  components: { input: (props) => /* @__PURE__ */ jsx(ArrayInput, {
397
449
  ...props,
@@ -411,7 +463,7 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
411
463
  experiment: experimentId
412
464
  },
413
465
  prepare: ({ base, experiment }) => {
414
- let title = base?.title || base?.name || typeof base == "string" ? base : "", experimentTitle = experiment ? `Experiment: ${experiment}` : "", media = base?.image || base?.photo || base?.media || "";
466
+ let title = typeof base == "string" ? base : base && typeof base == "object" && (base.title || base.name) || "", experimentTitle = experiment ? `Experiment: ${experiment}` : "", media = base && typeof base == "object" && (base.image || base.photo || base.media) || "";
415
467
  return {
416
468
  title: title || experimentTitle,
417
469
  subtitle: title ? experimentTitle : "",
@@ -473,7 +525,7 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
473
525
  ...config
474
526
  }, { fields, experimentNameOverride, variantNameOverride } = pluginConfig, experimentId = `${experimentNameOverride}Id`, variantArrayName = `${variantNameOverride}s`, variantId = `${variantNameOverride}Id`;
475
527
  return {
476
- name: "sanity-personalistaion-plugin-field-level-experiments",
528
+ name: "sanity-personalization-plugin-field-level-experiments",
477
529
  schema: { types: fieldSchema({
478
530
  fields,
479
531
  experimentNameOverride,
@@ -482,7 +534,7 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
482
534
  variantArrayName,
483
535
  experimentId
484
536
  }) },
485
- form: { components: { input: (props) => !(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).some((field) => field.type.name.startsWith(experimentNameOverride) || field.name.startsWith(experimentNameOverride)) ? props.renderDefault(props) : ExperimentProvider({
537
+ form: { components: { input: (props) => !(props.id === "root" && isObjectInputProps(props)) || !flattenSchemaType(props.schemaType).some((field) => field.type.name.startsWith(experimentNameOverride) || field.name.startsWith(experimentNameOverride)) ? props.renderDefault(props) : /* @__PURE__ */ jsx(ExperimentProvider, {
486
538
  ...props,
487
539
  experimentFieldPluginConfig: {
488
540
  ...pluginConfig,
@@ -493,6 +545,6 @@ const createExperimentType = ({ field, experimentNameOverride, variantNameOverri
493
545
  }) } }
494
546
  };
495
547
  });
496
- export { flattenSchemaType as n, fieldLevelExperiments as t };
548
+ export { ArrayItem as i, flattenSchemaType as n, clearChildrenGroups as r, fieldLevelExperiments as t };
497
549
 
498
- //# sourceMappingURL=fieldExperiments-DVb0HN3p.js.map
550
+ //# sourceMappingURL=fieldExperiments-D9NPbCCN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fieldExperiments-D9NPbCCN.js","names":["useEffect","ObjectItem","ObjectItemProps","set","ArrayItem","props","$","_c","active","value","onChange","inputProps","t0","t1","t2","renderDefault","equal","createContext","useContext","useMemo","ObjectInputProps","useClient","useWorkspace","suspend","ExperimentContextProps","ExperimentFieldPluginConfig","CONFIG_DEFAULT","fields","apiVersion","experimentNameOverride","variantNameOverride","variantId","variantArrayName","experimentId","ExperimentContext","experiments","useExperimentContext","ExperimentProps","experimentFieldPluginConfig","Required","ExperimentProvider","props","$","_c","t0","client","workspace","t1","Array","isArray","t2","context","t3","renderDefault","t4","Button","Inline","Stack","uuid","useCallback","useFormValue","ArrayInputProps","VariantType","useExperimentContext","ArrayInput","props","$","_c","experimentId","onItemAppend","t0","t1","variantId","variantName","fieldPath","path","slice","experimentValue","experiments","t2","variant","item","_key","id","_type","handleClick","T0","T1","t3","t4","t5","t6","filteredVariants","find","option","variants","values","value","Value","usedVariants","map","variant_0","renderDefault","arrayFunctions","_temp","variant_1","label","includes","t7","t8","ObjectFieldProps","clearChildrenGroups","props","children","innerChild","Array","isArray","groups","CloseIcon","useCallback","useMemo","GiSoapExperiment","defineDocumentFieldAction","DocumentFieldActionItem","DocumentFieldActionProps","FormPatch","ObjectFieldProps","PatchEvent","set","unset","clearChildrenGroups","PatchStuff","onChange","patch","inputId","useAddExperimentAction","props","$","_c","active","experimentNameOverride","t0","handleAddAction","t1","t2","title","type","icon","onAction","renderAsButton","useRemoveExperimentAction","experimentId","variantNameOverride","activeId","experiment","variants","handleClearAction","createActions","removeAction","name","useAction","addAction","Field","inputProps","value","actionProps","actions","oldActions","t3","memoizedActions","t4","propsWithClearedGroups","t5","enhancedProps","t6","renderDefault","Select","SanitySelect","ChangeEvent","FormPatch","PatchEvent","StringInputProps","SelectOption","props","$","_c","value","onChange","elementProps","listOptions","handleChange","t0","Symbol","for","t1","t2","event","t3","t4","map","_temp","t5","optionValue","title","Card","Text","ChangeEvent","useCallback","useMemo","FormPatch","getPublishedId","PatchEvent","set","StringInputProps","unset","useDocumentOperation","useFormValue","ExperimentType","Select","useExperimentContext","SelectOption","title","value","formatlistOptions","experiments","map","experiment","label","id","Input","props","$","_c","t0","Symbol","for","t1","path","variantNameOverride","slice","additionalChangePath","subValues","t2","patch","schemaType","name","t3","event","onChange","inputValue","currentTarget","patchEvent","join","execute","handleChange","length","t4","t5","t6","experimentNameOverride","Button","Inline","Stack","ObjectInputProps","set","useFormValue","VariantInput","props","$","_c","t0","t1","path","experimentPath","slice","defaultValue","t2","onChange","handleClick","t3","renderDefault","t4","t5","useEffect","useState","isImage","isReference","ObjectSchemaType","PreviewProps","ReferenceSchemaType","useClient","VariantPreviewProps","useExperimentContext","VariantPreview","props","$","_c","subtitle","setSubtitle","undefined","title","setTitle","media","setMedia","experiments","apiVersion","t0","client","experiment","variant","value","selectedExperiment","t1","t2","experimentItem","id","find","variants","variantItem","selectedVariant","schemaType","getSubtitle","label","doc","getDocument","_ref","type","valueField","fields","_temp","referenceField","referenceType","to","field_0","field","name","_type","selectFields","Record","previewFields","preview","select","Object","keys","forEach","key","valueKey","split","reduce","_temp2","previewContent","prepare","t3","t4","t5","t6","previewProps","renderDefault","acc","index","isDocumentSchemaType","ObjectField","Path","SchemaType","ObjectFieldWithPath","flattenSchemaType","schemaType","console","error","extractInnerFields","fields","path","maxDepth","length","result","field","push","name","type","jsonType","arrayTypes","of","arrayType","ArrayOfObjectsInputProps","defineField","definePlugin","defineType","FieldDefinition","isObjectInputProps","ArrayItem","ArrayInput","CONFIG_DEFAULT","ExperimentProvider","Field","Input","VariantInput","VariantPreview","ExperimentFieldPluginConfig","flattenSchemaType","createExperimentType","field","experimentNameOverride","variantNameOverride","variantId","variantArrayName","experimentId","typeName","name","usedName","String","toUpperCase","slice","variantName","type","groups","title","hidden","parent","Array","isArray","components","props","item","fields","group","initialValue","input","active","of","preview","select","base","experiment","prepare","experimentTitle","media","image","photo","subtitle","createVariantType","readOnly","variant","value","fieldSchema","Required","Omit","map","fieldLevelExperiments","config","pluginConfig","fieldSchemaConfig","schema","types","form","isRootInput","id","renderDefault","flatFields","schemaType","hasExperiment","some","startsWith","providerProps","experimentFieldPluginConfig"],"sources":["../src/components/ArrayItem.tsx","../src/components/experiment/Context.tsx","../src/components/experiment/Array.tsx","../src/utils/clearChildGroups.ts","../src/components/experiment/Field.tsx","../src/components/Select.tsx","../src/components/experiment/Input.tsx","../src/components/experiment/VariantInput.tsx","../src/components/experiment/VariantPreview.tsx","../src/utils/flattenSchemaType.ts","../src/fieldExperiments.tsx"],"sourcesContent":["import {useEffect} from 'react'\nimport {type ObjectItem, type ObjectItemProps, set} from 'sanity'\n\nexport const ArrayItem = (props: ObjectItemProps) => {\n const {active} = props.value as ObjectItem & {active: boolean}\n const {onChange} = props.inputProps\n\n useEffect(() => {\n if (!active) {\n onChange(set(true, ['active']))\n }\n }, [active, onChange])\n\n return props.renderDefault(props)\n}\n","import equal from 'fast-deep-equal'\nimport {createContext, useContext, useMemo} from 'react'\nimport {type ObjectInputProps, useClient, useWorkspace} from 'sanity'\nimport {suspend} from 'suspend-react'\n\nimport type {ExperimentContextProps, ExperimentFieldPluginConfig} from '../../types'\n\n// This provider makes the plugin config available to all components in the document form\n// But with experiments resolved\n\nexport const CONFIG_DEFAULT = {\n fields: [],\n apiVersion: '2024-11-07',\n experimentNameOverride: 'experiment',\n variantNameOverride: 'variant',\n variantId: 'variantId',\n variantArrayName: 'variants',\n experimentId: 'experimentId',\n}\n\nconst ExperimentContext = createContext<ExperimentContextProps>({\n ...CONFIG_DEFAULT,\n experiments: [],\n})\n\nexport function useExperimentContext() {\n return useContext(ExperimentContext)\n}\n\ntype ExperimentProps = ObjectInputProps & {\n experimentFieldPluginConfig: Required<ExperimentFieldPluginConfig>\n}\n\nexport function ExperimentProvider(props: ExperimentProps) {\n const {experimentFieldPluginConfig} = props\n\n const client = useClient({apiVersion: experimentFieldPluginConfig.apiVersion})\n const workspace = useWorkspace()\n\n // Fetch or return experiments\n const experiments = Array.isArray(experimentFieldPluginConfig.experiments)\n ? experimentFieldPluginConfig.experiments\n : suspend(\n async () => {\n if (typeof experimentFieldPluginConfig.experiments === 'function') {\n return experimentFieldPluginConfig.experiments(client)\n }\n return experimentFieldPluginConfig.experiments\n },\n [workspace, 'field-level-experiments'],\n {equal},\n )\n\n const context = useMemo(\n () => ({...experimentFieldPluginConfig, experiments}),\n [experimentFieldPluginConfig, experiments],\n )\n\n return (\n <ExperimentContext.Provider value={context}>\n {props.renderDefault(props)}\n </ExperimentContext.Provider>\n )\n}\n","import {Button, Inline, Stack} from '@sanity/ui'\nimport {uuid} from '@sanity/uuid'\nimport {useCallback} from 'react'\nimport {useFormValue} from 'sanity'\n\nimport type {ArrayInputProps, VariantType} from '../../types'\nimport {useExperimentContext} from './Context'\n\nexport const ArrayInput = (props: ArrayInputProps) => {\n const fieldPath = props.path.slice(0, -1)\n const {onItemAppend, variantName, variantId, experimentId} = props\n const experimentValue = useFormValue([...fieldPath, experimentId])\n\n const {experiments} = useExperimentContext()\n\n const handleClick = useCallback(\n async (variant: VariantType) => {\n const item = {\n _key: uuid(),\n [variantId]: variant.id,\n [experimentId]: experimentValue,\n _type: variantName,\n }\n\n // Patch the document\n onItemAppend(item)\n },\n [variantId, experimentId, experimentValue, variantName, onItemAppend],\n )\n\n const filteredVariants =\n experiments.find((option) => {\n return option.id === experimentValue\n })?.variants || []\n\n type Value = {\n value?: unknown\n [key: string]: unknown\n variantId: string\n _key: string\n _type: string\n }\n\n // there is probably some better was of getting the type of this?\n const values = (props.value as Value[]) || []\n\n const usedVariants = values?.map((variant) => variant[variantId])\n\n return (\n <Stack gap={3}>\n {props.renderDefault({...props, arrayFunctions: () => null})}\n\n <Inline gap={1}>\n {filteredVariants.map((variant) => {\n return (\n <Button\n key={`${experimentValue}-${variant.id}`}\n text={`Add ${variant.label}`}\n mode=\"ghost\"\n disabled={usedVariants?.includes(variant.id)}\n onClick={() => handleClick(variant)}\n />\n )\n })}\n </Inline>\n </Stack>\n )\n}\n","import type {ObjectFieldProps} from 'sanity'\n\n/**\n * Safely updates deeply nested children props to clear groups array\n * This prevents field grouping UI conflicts in personalization mode\n */\nexport const clearChildrenGroups = (props: ObjectFieldProps): ObjectFieldProps => {\n // Type assertion is needed here because Sanity's ObjectFieldProps children\n // typing doesn't account for the nested structure we need to manipulate\n const children = props.children as any\n\n if (!children || typeof children !== 'object' || !children.props) {\n return props\n }\n\n const innerChild = children.props.children\n if (\n !innerChild ||\n typeof innerChild !== 'object' ||\n Array.isArray(innerChild) ||\n !('props' in innerChild)\n ) {\n return props\n }\n\n return {\n ...props,\n children: {\n ...children,\n props: {\n ...children.props,\n children: {\n ...innerChild,\n props: {\n ...innerChild.props,\n groups: [],\n },\n },\n },\n },\n }\n}\n","import {CloseIcon} from '@sanity/icons/Close'\nimport {useCallback, useMemo} from 'react'\nimport {GiSoapExperiment} from 'react-icons/gi'\nimport {\n defineDocumentFieldAction,\n type DocumentFieldActionItem,\n type DocumentFieldActionProps,\n type FormPatch,\n type ObjectFieldProps,\n type PatchEvent,\n set,\n unset,\n} from 'sanity'\n\nimport {clearChildrenGroups} from '../../utils/clearChildGroups'\n\ntype PatchStuff = {onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void; inputId: string}\n\nconst useAddExperimentAction = (\n props: DocumentFieldActionProps &\n PatchStuff & {experimentNameOverride: string; experimentId: string; active: boolean},\n): DocumentFieldActionItem => {\n const {onChange, active, experimentNameOverride} = props\n\n const handleAddAction = useCallback(() => {\n onChange([set(!active, ['active'])])\n }, [onChange, active])\n\n return {\n title: `Add ${experimentNameOverride}`,\n type: 'action',\n icon: GiSoapExperiment,\n onAction: handleAddAction,\n renderAsButton: true,\n }\n}\n\nconst useRemoveExperimentAction = (\n props: DocumentFieldActionProps &\n PatchStuff & {\n experimentNameOverride: string\n experimentId: string\n active: boolean\n variantNameOverride: string\n },\n): DocumentFieldActionItem => {\n const {onChange, active, experimentId, experimentNameOverride, variantNameOverride} = props\n const handleClearAction = useCallback(() => {\n const activeId = ['active']\n const experiment = [experimentId]\n const variants = [`${variantNameOverride}s`]\n onChange([set(!active, activeId), unset(experiment), unset(variants)])\n }, [onChange, active, experimentId, variantNameOverride])\n\n return {\n title: `Remove ${experimentNameOverride}`,\n type: 'action',\n icon: CloseIcon,\n onAction: handleClearAction,\n renderAsButton: true,\n }\n}\n\nconst createActions = ({\n onChange,\n inputId,\n active,\n experimentNameOverride,\n experimentId,\n variantNameOverride,\n}: PatchStuff & {\n active?: boolean\n experimentNameOverride: string\n experimentId: string\n variantNameOverride: string\n}) => {\n const removeAction = defineDocumentFieldAction({\n name: `Remove ${experimentNameOverride}`,\n useAction: (props) =>\n useRemoveExperimentAction({\n ...props,\n active: true,\n onChange,\n inputId,\n experimentNameOverride,\n experimentId,\n variantNameOverride,\n }),\n })\n const addAction = defineDocumentFieldAction({\n name: `Add ${experimentNameOverride}`,\n useAction: (props) =>\n useAddExperimentAction({\n ...props,\n active: false,\n onChange,\n inputId,\n experimentNameOverride,\n experimentId,\n }),\n })\n return active ? removeAction : addAction\n}\n\nexport const Field = (\n props: ObjectFieldProps & {\n experimentNameOverride: string\n experimentId: string\n variantNameOverride: string\n },\n) => {\n const {onChange} = props.inputProps\n const {inputId, experimentNameOverride, experimentId, variantNameOverride} = props\n const active = props.value?.['active'] as boolean | undefined\n\n const actionProps = useMemo(\n () => ({\n onChange,\n inputId,\n active,\n experimentNameOverride,\n experimentId,\n variantNameOverride,\n }),\n [onChange, inputId, active, experimentNameOverride, experimentId, variantNameOverride],\n )\n\n const memoizedActions = useMemo(() => {\n const oldActions = props.actions || []\n return [createActions(actionProps), ...oldActions]\n }, [actionProps, props.actions])\n\n const enhancedProps = useMemo(() => {\n const propsWithClearedGroups = clearChildrenGroups(props)\n return {\n ...propsWithClearedGroups,\n actions: memoizedActions,\n }\n }, [props, memoizedActions])\n\n return props.renderDefault(enhancedProps)\n}\n","import {Select as SanitySelect} from '@sanity/ui'\nimport type {ChangeEvent} from 'react'\nimport type {FormPatch, PatchEvent, StringInputProps} from 'sanity'\n\nimport type {SelectOption} from './experiment/Input'\n\nexport const Select = (\n props: StringInputProps & {\n listOptions: SelectOption[]\n handleChange: (\n event: ChangeEvent<HTMLSelectElement>,\n onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void,\n ) => void\n },\n) => {\n const {\n value, // Current field value\n onChange, // Method to handle patch events,\n elementProps,\n listOptions,\n handleChange,\n } = props\n\n return (\n <SanitySelect\n {...elementProps}\n fontSize={2}\n padding={3}\n gap={[3, 3, 4]}\n value={value || ''} // Current field value\n onChange={(event) => handleChange(event, onChange)} // A function to call when the input value changes\n >\n <option value={''}>{'Select an option...'}</option>\n {listOptions.map(({value: optionValue, title}) => (\n <option key={optionValue} value={optionValue}>\n {title}\n </option>\n ))}\n </SanitySelect>\n )\n}\n","import {Card, Text} from '@sanity/ui'\nimport {type ChangeEvent, useCallback, useMemo} from 'react'\nimport {\n type FormPatch,\n getPublishedId,\n type PatchEvent,\n set,\n type StringInputProps,\n unset,\n useDocumentOperation,\n useFormValue,\n} from 'sanity'\n\nimport type {ExperimentType} from '../..'\nimport {Select} from '../Select'\nimport {useExperimentContext} from './Context'\n\nexport type SelectOption = {title: string; value: string}\nconst formatlistOptions = (experiments: ExperimentType[]): SelectOption[] =>\n experiments.map((experiment) => ({\n title: experiment.label,\n value: experiment.id,\n }))\n\nexport const Input = (\n props: StringInputProps & {variantNameOverride: string; experimentNameOverride: string},\n) => {\n const {experiments} = useExperimentContext()\n\n const id = useFormValue(['_id']) as string\n const additionalChangePath = useMemo(\n () => [...props.path.slice(0, -1), `${props.variantNameOverride}s`],\n [props.variantNameOverride, props.path],\n )\n const subValues = useFormValue(additionalChangePath)\n\n const {patch} = useDocumentOperation(getPublishedId(id), props.schemaType.name)\n\n const handleChange = useCallback(\n (\n event: ChangeEvent<HTMLSelectElement>,\n onChange: (patchchange: FormPatch | FormPatch[] | PatchEvent) => void,\n ) => {\n const inputValue = event.currentTarget.value\n\n if (inputValue) {\n onChange(set(inputValue))\n } else {\n onChange(unset())\n }\n\n if (subValues) {\n const patchEvent = {\n unset: [additionalChangePath.join('.')],\n }\n patch.execute([patchEvent])\n }\n },\n [patch, subValues, additionalChangePath],\n )\n\n if (!experiments.length)\n return (\n <Card padding={[3, 3, 4]} radius={2} shadow={1} tone=\"caution\">\n <Text align=\"center\" size={[2, 2, 3]}>\n There are no defined {props.experimentNameOverride}s\n </Text>\n </Card>\n )\n\n return (\n <Select {...props} listOptions={formatlistOptions(experiments)} handleChange={handleChange} />\n )\n}\n","import {Button, Inline, Stack} from '@sanity/ui'\nimport {type ObjectInputProps, set, useFormValue} from 'sanity'\n\nexport const VariantInput = (props: ObjectInputProps) => {\n const experimentPath = props.path.slice(0, -2)\n const defaultValue = useFormValue([...experimentPath, 'default'])\n const handleClick = () => {\n props.onChange(set(defaultValue, ['value']))\n }\n return (\n <Stack gap={3}>\n {props.renderDefault(props)}\n\n <Inline gap={1}>\n <Button text=\"Copy default\" mode=\"ghost\" onClick={() => handleClick()} />\n </Inline>\n </Stack>\n )\n}\n","import {useEffect, useState} from 'react'\nimport {\n isImage,\n isReference,\n type ObjectSchemaType,\n type PreviewProps,\n type ReferenceSchemaType,\n useClient,\n} from 'sanity'\n\nimport type {VariantPreviewProps} from '../../types'\nimport {useExperimentContext} from './Context'\n\nexport const VariantPreview = (props: PreviewProps) => {\n const [subtitle, setSubtitle] = useState<string | undefined>(undefined)\n const [title, setTitle] = useState<string | undefined>(undefined)\n const [media, setMedia] = useState<any>(undefined)\n const {experiments, apiVersion} = useExperimentContext()\n const client = useClient({apiVersion})\n\n const {experiment, variant, value} = props as VariantPreviewProps\n\n const selectedExperiment = experiments.find((experimentItem) => {\n return experimentItem.id === experiment\n })\n\n const selectedVariant = selectedExperiment?.variants.find((variantItem) => {\n return variantItem.id === variant\n })\n\n useEffect(() => {\n const getSubtitle = async () => {\n setTitle(\n selectedExperiment?.label && selectedVariant?.label\n ? `${selectedExperiment.label} - ${selectedVariant.label}`\n : selectedExperiment?.label || selectedVariant?.label,\n )\n if (typeof value === 'string') {\n return setSubtitle(value)\n }\n if (isReference(value)) {\n const doc = await client.getDocument(value._ref)\n const type = props.schemaType as ObjectSchemaType\n const valueField = type.fields.find((field) => field.name === 'value') as ObjectSchemaType\n const referenceField = valueField?.type as ReferenceSchemaType\n const referenceType = referenceField.to.find((field) => field.type?.name === doc?._type)\n\n const selectFields = {} as Record<string, unknown>\n const previewFields = referenceType?.preview?.select || {}\n Object.keys(previewFields).forEach((key) => {\n const valueKey = referenceType?.preview?.select?.[key]\n selectFields[key] =\n valueKey && doc\n ? valueKey.split('.').reduce((acc: any, index) => acc?.[index], doc)\n : undefined\n })\n\n const previewContent = referenceType?.preview?.prepare?.(selectFields)\n setMedia(previewContent?.media || selectFields['media'])\n return setSubtitle(previewContent?.title || (selectFields['title'] as string))\n }\n if (isImage(value)) {\n setMedia(value)\n }\n return ''\n }\n void getSubtitle()\n }, [value, client, selectedExperiment?.label, selectedVariant?.label, props.schemaType])\n\n const previewProps = {\n ...props,\n title: title,\n subtitle: subtitle,\n media: media,\n }\n\n return props.renderDefault(previewProps)\n}\n","import {isDocumentSchemaType, type ObjectField, type Path, type SchemaType} from 'sanity'\n\nimport type {ObjectFieldWithPath} from '../types'\n\n/**\n * Flattens a document's schema type into a flat array of fields and includes their path\n */\nexport function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[] {\n if (!isDocumentSchemaType(schemaType)) {\n console.error(`Schema type is not a document`)\n return []\n }\n\n return extractInnerFields(schemaType.fields, [], 5)\n}\n\nfunction extractInnerFields(\n fields: ObjectField[],\n path: Path,\n maxDepth: number,\n): ObjectFieldWithPath[] {\n if (path.length >= maxDepth) {\n return []\n }\n\n const result: ObjectFieldWithPath[] = []\n\n for (const field of fields) {\n result.push({path: [...path, field.name], ...field})\n\n if (field.type.jsonType === 'object') {\n result.push(...extractInnerFields(field.type.fields, [...path, field.name], maxDepth))\n } else if (field.type.jsonType === 'array') {\n // Handle array types by checking each possible type in the array\n const arrayTypes = field.type.of || []\n for (const arrayType of arrayTypes) {\n if ('fields' in arrayType) {\n result.push(...extractInnerFields(arrayType.fields, [...path, field.name], maxDepth))\n }\n }\n }\n }\n\n return result\n}\n","import {\n type ArrayOfObjectsInputProps,\n defineField,\n definePlugin,\n defineType,\n type FieldDefinition,\n isObjectInputProps,\n} from 'sanity'\n\nimport {ArrayItem} from './components/ArrayItem'\nimport {\n ArrayInput,\n CONFIG_DEFAULT,\n ExperimentProvider,\n Field,\n Input,\n VariantInput,\n VariantPreview,\n} from './components/experiment'\nimport type {ExperimentFieldPluginConfig} from './types'\nimport {flattenSchemaType} from './utils/flattenSchemaType'\n\nconst createExperimentType = ({\n field,\n experimentNameOverride,\n variantNameOverride,\n variantId,\n variantArrayName,\n experimentId,\n}: {\n field: string | FieldDefinition\n experimentNameOverride: string\n variantNameOverride: string\n variantId: string\n variantArrayName: string\n experimentId: string\n}) => {\n const typeName = typeof field === `string` ? field : field.name\n const usedName = String(typeName[0]).toUpperCase() + typeName.slice(1)\n const variantName = `${variantNameOverride}${usedName}`\n\n return defineType({\n name: `${experimentNameOverride}${usedName}`,\n type: 'object',\n groups: [\n {\n name: 'default',\n title: 'Default',\n hidden: ({parent}) => {\n return !Array.isArray(parent)\n },\n },\n {\n name: 'experiments',\n title: 'Experiments',\n hidden: ({parent}) => {\n return !Array.isArray(parent)\n },\n },\n {\n name: 'all-fields',\n title: 'All fields',\n hidden: ({parent}) => {\n return Array.isArray(parent)\n },\n },\n ],\n components: {\n field: (props) => (\n <Field\n {...props}\n experimentId={experimentId}\n experimentNameOverride={experimentNameOverride}\n variantNameOverride={variantNameOverride}\n />\n ),\n item: ArrayItem,\n },\n fields: [\n typeof field === `string`\n ? // Define a simple field if all we have is the name as a string\n defineField({\n name: 'default',\n type: field,\n group: 'default',\n })\n : // Pass in the configured options, but overwrite the name\n {\n ...field,\n name: 'default',\n group: 'default',\n },\n defineField({\n name: 'active',\n type: 'boolean',\n hidden: true,\n initialValue: false,\n }),\n defineField({\n name: experimentId,\n type: 'string',\n group: 'experiments',\n components: {\n input: (props) => (\n <Input\n {...props}\n experimentNameOverride={experimentNameOverride}\n variantNameOverride={variantNameOverride}\n />\n ),\n },\n hidden: ({parent}) => {\n return !parent?.active\n },\n }),\n defineField({\n name: variantArrayName,\n type: 'array',\n group: 'experiments',\n hidden: ({parent}) => {\n return !parent?.[experimentId]\n },\n components: {\n input: (props: ArrayOfObjectsInputProps) => (\n <ArrayInput\n {...props}\n variantName={variantName}\n variantId={variantId}\n experimentId={experimentId}\n />\n ),\n },\n of: [\n defineField({\n name: variantName,\n type: variantName,\n }),\n ],\n }),\n ],\n preview: {\n select: {\n base: 'default',\n experiment: experimentId,\n },\n prepare: ({base, experiment}) => {\n const title =\n typeof base === 'string'\n ? base\n : base && typeof base === 'object'\n ? base.title || base.name || ''\n : ''\n const experimentTitle = experiment ? `Experiment: ${experiment}` : ''\n const media =\n base && typeof base === 'object' ? base.image || base.photo || base.media || '' : ''\n return {\n title: title || experimentTitle,\n subtitle: title ? experimentTitle : '',\n media,\n }\n },\n },\n })\n}\n\nconst createVariantType = ({\n field,\n variantNameOverride,\n variantId,\n experimentId,\n}: {\n field: string | FieldDefinition\n variantNameOverride: string\n variantId: string\n experimentId: string\n}) => {\n const typeName = typeof field === `string` ? field : field.name\n const usedName = String(typeName[0]).toUpperCase() + typeName.slice(1)\n return defineType({\n name: `${variantNameOverride}${usedName}`,\n title: `${variantNameOverride} array ${usedName}`,\n type: 'object',\n components: {\n preview: VariantPreview,\n input: VariantInput,\n },\n fields: [\n {\n type: 'string',\n name: variantId,\n readOnly: true,\n },\n {\n type: 'string',\n name: experimentId,\n hidden: true,\n },\n typeof field === `string`\n ? // Define a simple field if all we have is the name as a string\n defineField({\n name: 'value',\n type: field,\n // hidden: ({parent}) => !parent?.[`${objectNameOverride}Id`],\n })\n : // Pass in the configured options, but overwrite the name\n {\n ...field,\n name: 'value',\n // hidden: ({parent}) => !parent?.[`${objectNameOverride}Id`],\n },\n ],\n preview: {\n select: {\n variant: variantId,\n experiment: experimentId,\n value: 'value',\n },\n },\n })\n}\n\nconst fieldSchema = ({\n fields,\n experimentNameOverride,\n variantNameOverride,\n variantId,\n variantArrayName,\n experimentId,\n}: Required<Omit<ExperimentFieldPluginConfig, 'apiVersion' | 'experiments'>>) => {\n return [\n ...fields.map((field) =>\n createVariantType({field, variantNameOverride, variantId, experimentId}),\n ),\n ...fields.map((field) =>\n createExperimentType({\n field,\n experimentNameOverride,\n variantNameOverride,\n variantId,\n variantArrayName,\n experimentId,\n }),\n ),\n ]\n}\n\nexport const fieldLevelExperiments = definePlugin<ExperimentFieldPluginConfig>((config) => {\n const pluginConfig = {...CONFIG_DEFAULT, ...config}\n const {fields, experimentNameOverride, variantNameOverride} = pluginConfig\n\n const experimentId = `${experimentNameOverride}Id`\n const variantArrayName = `${variantNameOverride}s`\n const variantId = `${variantNameOverride}Id`\n\n const fieldSchemaConfig = fieldSchema({\n fields,\n experimentNameOverride,\n variantNameOverride,\n variantId,\n variantArrayName,\n experimentId,\n })\n return {\n name: 'sanity-personalization-plugin-field-level-experiments',\n schema: {\n types: fieldSchemaConfig,\n },\n form: {\n components: {\n input: (props) => {\n const isRootInput = props.id === 'root' && isObjectInputProps(props)\n\n if (!isRootInput) {\n return props.renderDefault(props)\n }\n\n const flatFields = flattenSchemaType(props.schemaType)\n const hasExperiment = flatFields.some(\n (field) =>\n field.type.name.startsWith(experimentNameOverride) ||\n field.name.startsWith(experimentNameOverride),\n )\n\n if (!hasExperiment) {\n return props.renderDefault(props)\n }\n\n const providerProps = {\n ...props,\n experimentFieldPluginConfig: {\n ...pluginConfig,\n variantId,\n variantArrayName,\n experimentId,\n },\n }\n return <ExperimentProvider {...providerProps} />\n },\n },\n },\n }\n})\n"],"mappings":";;;;;;;;;;AAGA,MAAaI,aAAYC,UAAA;CAAA,IAAAC,IAAAC,EAAA,CAAA,GACvB,EAAAC,WAAiBH,MAAKI,OACtB,EAAAC,aAAmBL,MAAKM,YAAWC,IAAAC;CAEnCb,AAFmCM,EAAA,OAAAE,UAAAF,EAAA,OAAAI,YAEzBE,WAAA;EACR,AAAKJ,UACHE,SAASP,IAAI,IAAM,CAAC,QAAQ,CAAC,CAAC;CAC/B,GACAU,KAA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,KAAKsD,WAAW5D,sBAAsB,KACjDD,MAAMO,KAAKsD,WAAW5D,sBAAsB,CAG3C0D,IACItC,MAAMmC,cAAcnC,KAAK,IAY3B,oBAAC,oBAAD;GARL,GAAGA;GACH0C,6BAA6B;IAC3B,GAAGd;IACH9C;IACAC;IACAC;GACF;EAE2C,CAAA,EAEjD,EACF;CACF;AACF,CAAC"}
@@ -1,4 +1,4 @@
1
- import { n as flattenSchemaType, t as fieldLevelExperiments$1 } from "../fieldExperiments-DVb0HN3p.js";
1
+ import { n as flattenSchemaType, t as fieldLevelExperiments$1 } from "../fieldExperiments-D9NPbCCN.js";
2
2
  import { definePlugin, isObjectInputProps } from "sanity";
3
3
  import { c } from "react/compiler-runtime";
4
4
  import { createContext, useContext, useEffect, useState } from "react";
@@ -90,7 +90,7 @@ const getBooleanConversion = (value) => value === "true" ? "variant" : value ===
90
90
  ...config
91
91
  }, { fields, environment, project, convertBooleans, baseUrl, tags } = pluginConfig;
92
92
  return {
93
- name: "sanity-growthbook-personalistaion-plugin-field-level-experiments",
93
+ name: "sanity-growthbook-personalization-plugin-field-level-experiments",
94
94
  plugins: [fieldLevelExperiments$1({
95
95
  fields,
96
96
  experiments: (client) => getExperiments({
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["SettingsView","useSecrets","useEffect","useState","ObjectInputProps","useGrowthbookContext","namespace","apiKeyName","pluginConfigKeys","key","title","Secrets","props","$","_c","secrets","loading","apiKey","setSecret","showSettings","setShowSettings","t0","t1","undefined","t2","renderDefault","Symbol","for","t3","t4","createContext","useContext","useMemo","useState","ObjectInputProps","GrowthbookContextProps","GrowthbookExperimentFieldPluginConfig","Secrets","GROWTHBOOK_CONFIG_DEFAULT","baseUrl","GrowthbookContext","setSecret","undefined","secret","useGrowthbookContext","GrowthbookProps","growthbookFieldPluginConfig","GrowthbookProvider","props","$","_c","t0","context","t1","t2","SanityClient","ExperimentType","GrowthbookFeature","VariantType","apiKeyName","namespace","GrowthbookExperimentFieldPluginConfig","getBooleanConversion","value","getExperiments","client","environment","baseUrl","project","convertBooleans","tags","Omit","Promise","query","secret","fetch","featureExperiments","hasMore","offset","url","URL","searchParams","set","toString","response","headers","Authorization","features","responseHasMore","nextOffset","json","forEach","feature","archived","undefined","some","tag","includes","experiments","environments","rules","filter","experiment","type","variations","uniqueValues","Set","variant","has","add","push","id","label","variants","sortedFeatureExperiments","sort","a","b","localeCompare","definePlugin","isObjectInputProps","fieldLevelExperiments","baseFieldLevelExperiments","flattenSchemaType","GROWTHBOOK_CONFIG_DEFAULT","GrowthbookProvider","GrowthbookExperimentFieldPluginConfig","getExperiments","config","pluginConfig","fields","environment","project","convertBooleans","baseUrl","tags","name","plugins","experiments","client","form","components","input","props","isRootInput","id","renderDefault","flatFieldTypeNames","schemaType","map","field","type","hasExperiment","some","startsWith","providerProps","growthbookFieldPluginConfig"],"sources":["../../src/growthbook/Components/Secrets.tsx","../../src/growthbook/Components/GrowthbookContext.tsx","../../src/growthbook/utils.ts","../../src/growthbook/index.ts"],"sourcesContent":["import {SettingsView, useSecrets} from '@sanity/studio-secrets'\nimport {useEffect, useState} from 'react'\nimport type {ObjectInputProps} from 'sanity'\n\nimport {useGrowthbookContext} from './GrowthbookContext'\n\nexport const namespace = 'growthbook'\nexport const apiKeyName = 'apiKey'\n\nconst pluginConfigKeys = [\n {\n key: apiKeyName,\n title: 'Your secret API key',\n },\n]\n\nexport const Secrets = (props: ObjectInputProps) => {\n const {secrets, loading} = useSecrets(namespace) as {secrets: {apiKey: string}; loading: boolean}\n const {setSecret} = useGrowthbookContext()\n const [showSettings, setShowSettings] = useState<boolean>(false)\n\n useEffect(() => {\n if (loading) return undefined\n if (!secrets && !loading) {\n setSecret(undefined)\n // oxlint-disable-next-line react/react-compiler\n return setShowSettings(true)\n }\n setSecret(secrets.apiKey)\n return setShowSettings(false)\n }, [secrets, loading, setSecret])\n\n if (!showSettings) {\n return props.renderDefault(props)\n }\n return (\n <>\n <SettingsView\n title={'Growthbook secret'}\n namespace={namespace}\n keys={pluginConfigKeys}\n onClose={() => {\n setShowSettings(false)\n }}\n />\n {props.renderDefault(props)}\n </>\n )\n}\n","import {createContext, useContext, useMemo, useState} from 'react'\nimport type {ObjectInputProps} from 'sanity'\n\nimport type {GrowthbookContextProps, GrowthbookExperimentFieldPluginConfig} from '../types'\nimport {Secrets} from './Secrets'\n\nexport const GROWTHBOOK_CONFIG_DEFAULT = {\n baseUrl: 'https://api.growthbook.io/api/v1',\n}\n\nconst GrowthbookContext = createContext<GrowthbookContextProps>({\n setSecret: () => undefined,\n secret: undefined,\n})\n\nexport function useGrowthbookContext() {\n return useContext(GrowthbookContext)\n}\n\ntype GrowthbookProps = ObjectInputProps & {\n growthbookFieldPluginConfig: GrowthbookExperimentFieldPluginConfig\n}\n\nexport function GrowthbookProvider(props: GrowthbookProps) {\n const {growthbookFieldPluginConfig} = props\n const [secret, setSecret] = useState<string | undefined>()\n\n const context = useMemo(\n () => ({...growthbookFieldPluginConfig, secret, setSecret}),\n [growthbookFieldPluginConfig, secret, setSecret],\n )\n\n return (\n <GrowthbookContext.Provider value={context}>\n <Secrets {...props} />\n </GrowthbookContext.Provider>\n )\n}\n","import type {SanityClient} from 'sanity'\n\nimport type {ExperimentType, GrowthbookFeature, VariantType} from '../types'\nimport {apiKeyName, namespace} from './Components/Secrets'\nimport type {GrowthbookExperimentFieldPluginConfig} from './types'\n\nconst getBooleanConversion = (value: string) => {\n // control is false\n if (value === 'true') {\n return 'variant'\n } else if (value === 'false') {\n return 'control'\n }\n return value\n}\n\nexport const getExperiments = async ({\n client,\n environment,\n baseUrl,\n project,\n convertBooleans,\n tags,\n}: Omit<GrowthbookExperimentFieldPluginConfig, 'fields' | 'baseUrl'> & {\n client: SanityClient\n baseUrl: string\n}): Promise<ExperimentType[]> => {\n const query = `*[_id == 'secrets.${namespace}'][0].secrets.${apiKeyName}`\n\n const secret = await client.fetch(query) // secret is stored in the content lake using @sanity/studio-secrets\n if (!secret) return []\n\n const featureExperiments: ExperimentType[] = []\n let hasMore = true\n let offset = 0\n const url = new URL(`${baseUrl}/features`)\n if (project) {\n url.searchParams.set('projectId', project)\n }\n\n while (hasMore) {\n url.searchParams.set('offset', offset.toString())\n const response = await fetch(url, {\n headers: {\n Authorization: `Bearer ${secret}`,\n },\n })\n\n const {features, hasMore: responseHasMore, nextOffset} = await response.json()\n\n hasMore = responseHasMore\n offset = nextOffset\n if (!features) continue\n\n features.forEach((feature: GrowthbookFeature) => {\n if (feature.archived) {\n return undefined\n }\n if (tags && feature.tags && !feature.tags.some((tag) => tags.includes(tag))) {\n return undefined\n }\n\n const experiments = feature.environments[environment]?.rules.filter(\n (experiment) => experiment.type === 'experiment-ref' || experiment.type === 'experiment',\n )\n\n if (!experiments) {\n return undefined\n }\n\n const variations: VariantType[] = []\n const uniqueValues = new Set<string>()\n\n experiments.forEach((experiment) => {\n experiment?.variations.forEach((variant) => {\n const value = convertBooleans ? getBooleanConversion(variant.value) : variant.value\n if (!uniqueValues.has(value)) {\n uniqueValues.add(value)\n variations.push({\n id: value,\n label: value,\n })\n }\n })\n })\n const value = {id: feature.id, label: feature.id, variants: variations}\n\n featureExperiments.push(value)\n return undefined\n })\n }\n const sortedFeatureExperiments = featureExperiments.sort((a, b) => a.id.localeCompare(b.id))\n return sortedFeatureExperiments\n}\n","import {definePlugin, isObjectInputProps} from 'sanity'\n\nimport {fieldLevelExperiments as baseFieldLevelExperiments} from '../fieldExperiments'\nimport {flattenSchemaType} from '../utils/flattenSchemaType'\nimport {GROWTHBOOK_CONFIG_DEFAULT, GrowthbookProvider} from './Components/GrowthbookContext'\nimport type {GrowthbookExperimentFieldPluginConfig} from './types'\nimport {getExperiments} from './utils'\n\nexport const fieldLevelExperiments = definePlugin<GrowthbookExperimentFieldPluginConfig>(\n (config) => {\n const pluginConfig = {...GROWTHBOOK_CONFIG_DEFAULT, ...config}\n const {fields, environment, project, convertBooleans, baseUrl, tags} = pluginConfig\n return {\n name: 'sanity-growthbook-personalistaion-plugin-field-level-experiments',\n plugins: [\n baseFieldLevelExperiments({\n fields,\n experiments: (client) =>\n getExperiments({client, environment, baseUrl, project, convertBooleans, tags}),\n }),\n ],\n\n form: {\n components: {\n input: (props) => {\n const isRootInput = props.id === 'root' && isObjectInputProps(props)\n\n if (!isRootInput) {\n return props.renderDefault(props)\n }\n\n const flatFieldTypeNames = flattenSchemaType(props.schemaType).map(\n (field) => field.type.name,\n )\n\n const hasExperiment = flatFieldTypeNames.some((name) => name.startsWith('experiment'))\n\n if (!hasExperiment) {\n return props.renderDefault(props)\n }\n\n const providerProps = {\n ...props,\n growthbookFieldPluginConfig: {\n ...pluginConfig,\n },\n }\n return GrowthbookProvider(providerProps)\n },\n },\n },\n }\n },\n)\n"],"mappings":";;;;;;AAMA,MAAaM,YAAY,cACZC,aAAa,UAEpBC,mBAAmB,CACvB;CACEC,KAAKF;CACLG,OAAO;AACT,CAAC,GAGUC,WAAUC,UAAA;CAAA,IAAAC,IAAAC,EAAA,EAAA,GACrB,EAAAC,SAAAC,YAA2Bf,WAAWK,SAAS,GAC/C,EAAAY,cAAoBb,qBAAqB,GACzC,CAAAc,cAAAC,mBAAwCjB,SAAkB,EAAK,GAACkB,IAAAC;CAahE,IAbgET,EAAA,OAAAG,WAAAH,EAAA,OAAAE,WAAAF,EAAA,OAAAK,aAEtDG,WAAA;EACJL,cAMqB,OALrB,CAACD,WAAD,CAAaC,WACfE,UAAUK,KAAAA,CAAS,GAEZH,gBAAgB,EAAI,MAE7BF,UAAUH,QAAOE,MAAO,GACjBG,gBAAgB,EAAK;CAAC,GAC5BE,KAAA;EAACP;EAASC;EAASE;CAAS,GAACL,EAAA,KAAAG,SAAAH,EAAA,KAAAE,SAAAF,EAAA,KAAAK,WAAAL,EAAA,KAAAQ,IAAAR,EAAA,KAAAS,OAAAD,KAAAR,EAAA,IAAAS,KAAAT,EAAA,KAThCX,UAAUmB,IASPC,EAA6B,GAE5B,CAACH,cAAY;EAAA,IAAAK;EACkB,OADlBX,EAAA,OAAAD,Q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,aACL;EAEwB0B,CAAa,EAE3C,EACF;CACF;AACF,CACF"}
1
+ {"version":3,"file":"index.js","names":["SettingsView","useSecrets","useEffect","useState","ObjectInputProps","useGrowthbookContext","namespace","apiKeyName","pluginConfigKeys","key","title","Secrets","props","$","_c","secrets","loading","apiKey","setSecret","showSettings","setShowSettings","t0","t1","undefined","t2","renderDefault","Symbol","for","t3","t4","createContext","useContext","useMemo","useState","ObjectInputProps","GrowthbookContextProps","GrowthbookExperimentFieldPluginConfig","Secrets","GROWTHBOOK_CONFIG_DEFAULT","baseUrl","GrowthbookContext","setSecret","undefined","secret","useGrowthbookContext","GrowthbookProps","growthbookFieldPluginConfig","GrowthbookProvider","props","$","_c","t0","context","t1","t2","SanityClient","ExperimentType","GrowthbookFeature","VariantType","apiKeyName","namespace","GrowthbookExperimentFieldPluginConfig","getBooleanConversion","value","getExperiments","client","environment","baseUrl","project","convertBooleans","tags","Omit","Promise","query","secret","fetch","featureExperiments","hasMore","offset","url","URL","searchParams","set","toString","response","headers","Authorization","features","responseHasMore","nextOffset","json","forEach","feature","archived","undefined","some","tag","includes","experiments","environments","rules","filter","experiment","type","variations","uniqueValues","Set","variant","has","add","push","id","label","variants","sortedFeatureExperiments","sort","a","b","localeCompare","definePlugin","isObjectInputProps","fieldLevelExperiments","baseFieldLevelExperiments","flattenSchemaType","GROWTHBOOK_CONFIG_DEFAULT","GrowthbookProvider","GrowthbookExperimentFieldPluginConfig","getExperiments","config","pluginConfig","fields","environment","project","convertBooleans","baseUrl","tags","name","plugins","experiments","client","form","components","input","props","isRootInput","id","renderDefault","flatFieldTypeNames","schemaType","map","field","type","hasExperiment","some","startsWith","providerProps","growthbookFieldPluginConfig"],"sources":["../../src/growthbook/Components/Secrets.tsx","../../src/growthbook/Components/GrowthbookContext.tsx","../../src/growthbook/utils.ts","../../src/growthbook/index.ts"],"sourcesContent":["import {SettingsView, useSecrets} from '@sanity/studio-secrets'\nimport {useEffect, useState} from 'react'\nimport type {ObjectInputProps} from 'sanity'\n\nimport {useGrowthbookContext} from './GrowthbookContext'\n\nexport const namespace = 'growthbook'\nexport const apiKeyName = 'apiKey'\n\nconst pluginConfigKeys = [\n {\n key: apiKeyName,\n title: 'Your secret API key',\n },\n]\n\nexport const Secrets = (props: ObjectInputProps) => {\n const {secrets, loading} = useSecrets(namespace) as {secrets: {apiKey: string}; loading: boolean}\n const {setSecret} = useGrowthbookContext()\n const [showSettings, setShowSettings] = useState<boolean>(false)\n\n useEffect(() => {\n if (loading) return undefined\n if (!secrets && !loading) {\n setSecret(undefined)\n // oxlint-disable-next-line react/react-compiler\n return setShowSettings(true)\n }\n setSecret(secrets.apiKey)\n return setShowSettings(false)\n }, [secrets, loading, setSecret])\n\n if (!showSettings) {\n return props.renderDefault(props)\n }\n return (\n <>\n <SettingsView\n title={'Growthbook secret'}\n namespace={namespace}\n keys={pluginConfigKeys}\n onClose={() => {\n setShowSettings(false)\n }}\n />\n {props.renderDefault(props)}\n </>\n )\n}\n","import {createContext, useContext, useMemo, useState} from 'react'\nimport type {ObjectInputProps} from 'sanity'\n\nimport type {GrowthbookContextProps, GrowthbookExperimentFieldPluginConfig} from '../types'\nimport {Secrets} from './Secrets'\n\nexport const GROWTHBOOK_CONFIG_DEFAULT = {\n baseUrl: 'https://api.growthbook.io/api/v1',\n}\n\nconst GrowthbookContext = createContext<GrowthbookContextProps>({\n setSecret: () => undefined,\n secret: undefined,\n})\n\nexport function useGrowthbookContext() {\n return useContext(GrowthbookContext)\n}\n\ntype GrowthbookProps = ObjectInputProps & {\n growthbookFieldPluginConfig: GrowthbookExperimentFieldPluginConfig\n}\n\nexport function GrowthbookProvider(props: GrowthbookProps) {\n const {growthbookFieldPluginConfig} = props\n const [secret, setSecret] = useState<string | undefined>()\n\n const context = useMemo(\n () => ({...growthbookFieldPluginConfig, secret, setSecret}),\n [growthbookFieldPluginConfig, secret, setSecret],\n )\n\n return (\n <GrowthbookContext.Provider value={context}>\n <Secrets {...props} />\n </GrowthbookContext.Provider>\n )\n}\n","import type {SanityClient} from 'sanity'\n\nimport type {ExperimentType, GrowthbookFeature, VariantType} from '../types'\nimport {apiKeyName, namespace} from './Components/Secrets'\nimport type {GrowthbookExperimentFieldPluginConfig} from './types'\n\nconst getBooleanConversion = (value: string) => {\n // control is false\n if (value === 'true') {\n return 'variant'\n } else if (value === 'false') {\n return 'control'\n }\n return value\n}\n\nexport const getExperiments = async ({\n client,\n environment,\n baseUrl,\n project,\n convertBooleans,\n tags,\n}: Omit<GrowthbookExperimentFieldPluginConfig, 'fields' | 'baseUrl'> & {\n client: SanityClient\n baseUrl: string\n}): Promise<ExperimentType[]> => {\n const query = `*[_id == 'secrets.${namespace}'][0].secrets.${apiKeyName}`\n\n const secret = await client.fetch(query) // secret is stored in the content lake using @sanity/studio-secrets\n if (!secret) return []\n\n const featureExperiments: ExperimentType[] = []\n let hasMore = true\n let offset = 0\n const url = new URL(`${baseUrl}/features`)\n if (project) {\n url.searchParams.set('projectId', project)\n }\n\n while (hasMore) {\n url.searchParams.set('offset', offset.toString())\n const response = await fetch(url, {\n headers: {\n Authorization: `Bearer ${secret}`,\n },\n })\n\n const {features, hasMore: responseHasMore, nextOffset} = await response.json()\n\n hasMore = responseHasMore\n offset = nextOffset\n if (!features) continue\n\n features.forEach((feature: GrowthbookFeature) => {\n if (feature.archived) {\n return undefined\n }\n if (tags && feature.tags && !feature.tags.some((tag) => tags.includes(tag))) {\n return undefined\n }\n\n const experiments = feature.environments[environment]?.rules.filter(\n (experiment) => experiment.type === 'experiment-ref' || experiment.type === 'experiment',\n )\n\n if (!experiments) {\n return undefined\n }\n\n const variations: VariantType[] = []\n const uniqueValues = new Set<string>()\n\n experiments.forEach((experiment) => {\n experiment?.variations.forEach((variant) => {\n const value = convertBooleans ? getBooleanConversion(variant.value) : variant.value\n if (!uniqueValues.has(value)) {\n uniqueValues.add(value)\n variations.push({\n id: value,\n label: value,\n })\n }\n })\n })\n const value = {id: feature.id, label: feature.id, variants: variations}\n\n featureExperiments.push(value)\n return undefined\n })\n }\n const sortedFeatureExperiments = featureExperiments.sort((a, b) => a.id.localeCompare(b.id))\n return sortedFeatureExperiments\n}\n","import {definePlugin, isObjectInputProps} from 'sanity'\n\nimport {fieldLevelExperiments as baseFieldLevelExperiments} from '../fieldExperiments'\nimport {flattenSchemaType} from '../utils/flattenSchemaType'\nimport {GROWTHBOOK_CONFIG_DEFAULT, GrowthbookProvider} from './Components/GrowthbookContext'\nimport type {GrowthbookExperimentFieldPluginConfig} from './types'\nimport {getExperiments} from './utils'\n\nexport const fieldLevelExperiments = definePlugin<GrowthbookExperimentFieldPluginConfig>(\n (config) => {\n const pluginConfig = {...GROWTHBOOK_CONFIG_DEFAULT, ...config}\n const {fields, environment, project, convertBooleans, baseUrl, tags} = pluginConfig\n return {\n name: 'sanity-growthbook-personalization-plugin-field-level-experiments',\n plugins: [\n baseFieldLevelExperiments({\n fields,\n experiments: (client) =>\n getExperiments({client, environment, baseUrl, project, convertBooleans, tags}),\n }),\n ],\n\n form: {\n components: {\n input: (props) => {\n const isRootInput = props.id === 'root' && isObjectInputProps(props)\n\n if (!isRootInput) {\n return props.renderDefault(props)\n }\n\n const flatFieldTypeNames = flattenSchemaType(props.schemaType).map(\n (field) => field.type.name,\n )\n\n const hasExperiment = flatFieldTypeNames.some((name) => name.startsWith('experiment'))\n\n if (!hasExperiment) {\n return props.renderDefault(props)\n }\n\n const providerProps = {\n ...props,\n growthbookFieldPluginConfig: {\n ...pluginConfig,\n },\n }\n return GrowthbookProvider(providerProps)\n },\n },\n },\n }\n },\n)\n"],"mappings":";;;;;;AAMA,MAAaM,YAAY,cACZC,aAAa,UAEpBC,mBAAmB,CACvB;CACEC,KAAKF;CACLG,OAAO;AACT,CAAC,GAGUC,WAAUC,UAAA;CAAA,IAAAC,IAAAC,EAAA,EAAA,GACrB,EAAAC,SAAAC,YAA2Bf,WAAWK,SAAS,GAC/C,EAAAY,cAAoBb,qBAAqB,GACzC,CAAAc,cAAAC,mBAAwCjB,SAAkB,EA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,SAASC,iBAAiBC,SAASC,SAAQN;CACvE,OAAO;EACLO,MAAM;EACNC,SAAS,CACPf,wBAA0B;GACxBQ;GACAQ,cAAcC,WACZZ,eAAe;IAACY;IAAQR;IAAaG;IAASF;IAASC;IAAiBE;GAAI,CAAC;EACjF,CAAC,CAAC;EAGJK,MAAM,EACJC,YAAY,EACVC,QAAQC,UAGF,EAFgBA,MAAME,OAAO,UAAUzB,mBAAmBuB,KAAK,MAY/D,CANuBpB,kBAAkBoB,MAAMK,UAAU,CAAC,CAACC,KAC5DC,UAAUA,MAAMC,KAAKf,IAGFW,CAAkB,CAACM,MAAMjB,SAASA,KAAKkB,WAAW,YAAY,CAE/EF,IACIT,MAAMG,cAAcH,KAAK,IAS3BlB,mBAAmB8B;GALxB,GAAGZ;GACHa,6BAA6B,EAC3B,GAAG3B,aACL;EAEwB0B,CAAa,EAE3C,EACF;CACF;AACF,CACF"}
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ type ExperimentType = {
8
8
  label: string;
9
9
  variants: VariantType[];
10
10
  };
11
- type FieldPluginConfig = {
11
+ type ExperimentFieldPluginConfig = {
12
12
  fields: (string | FieldDefinition)[];
13
13
  experiments: ExperimentType[] | ((client: SanityClient) => Promise<ExperimentType[]>);
14
14
  apiVersion?: string;
@@ -18,18 +18,36 @@ type FieldPluginConfig = {
18
18
  variantArrayName?: string;
19
19
  experimentId?: string;
20
20
  };
21
+ /** @deprecated Use {@link ExperimentFieldPluginConfig} instead. */
22
+ type FieldPluginConfig = ExperimentFieldPluginConfig;
23
+ type PersonalizationFieldPluginConfig = {
24
+ fields: (string | FieldDefinition)[];
25
+ segments: VariantType[] | ((client: SanityClient) => Promise<VariantType[]>);
26
+ apiVersion?: string;
27
+ personalizationNameOverride?: string;
28
+ segmentNameOverride?: string;
29
+ segmentId?: string;
30
+ segmentArrayName?: string;
31
+ };
21
32
  type VariantPreviewProps = Omit<PreviewProps, 'SchemaType'> & {
22
33
  [key: string]: string;
23
34
  value: any;
24
35
  };
25
- type ExperimentContextProps = Required<FieldPluginConfig> & {
36
+ type ExperimentContextProps = Required<ExperimentFieldPluginConfig> & {
26
37
  experiments: ExperimentType[];
27
38
  };
39
+ type PersonalizationContextProps = Required<PersonalizationFieldPluginConfig> & {
40
+ segments: VariantType[];
41
+ };
28
42
  type ArrayInputProps = ArrayOfObjectsInputProps & {
29
43
  variantName: string;
30
44
  variantId: string;
31
45
  experimentId: string;
32
46
  };
47
+ type PersonalizationArrayInputProps = ArrayOfObjectsInputProps & {
48
+ segmentName: string;
49
+ segmentId: string;
50
+ };
33
51
  type ObjectFieldWithPath = ObjectField & {
34
52
  path: Path;
35
53
  };
@@ -218,10 +236,11 @@ type GrowthbookFeature = {
218
236
  publishedBy: string;
219
237
  };
220
238
  };
221
- declare const fieldLevelExperiments: import("sanity").Plugin<FieldPluginConfig>;
239
+ declare const fieldLevelExperiments: import("sanity").Plugin<ExperimentFieldPluginConfig>;
240
+ declare const fieldLevelPersonalization: import("sanity").Plugin<PersonalizationFieldPluginConfig>;
222
241
  /**
223
242
  * Flattens a document's schema type into a flat array of fields and includes their path
224
243
  */
225
244
  declare function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[];
226
- export { ArrayInputProps, ExperimentContextProps, ExperimentGeneric, ExperimentType, FieldPluginConfig, GrowthbookExperiment, GrowthbookFeature, ObjectFieldWithPath, VariantGeneric, VariantPreviewProps, VariantType, fieldLevelExperiments, flattenSchemaType };
245
+ export { ArrayInputProps, ExperimentContextProps, ExperimentFieldPluginConfig, ExperimentGeneric, ExperimentType, FieldPluginConfig, GrowthbookExperiment, GrowthbookFeature, ObjectFieldWithPath, PersonalizationArrayInputProps, PersonalizationContextProps, PersonalizationFieldPluginConfig, VariantGeneric, VariantPreviewProps, VariantType, fieldLevelExperiments, fieldLevelPersonalization, flattenSchemaType };
227
246
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/fieldExperiments.tsx","../src/utils/flattenSchemaType.ts"],"mappings":";KASY;EACV;EACA;;KAEU;EACV;EACA;EACA,UAAU;;KAGA;EACV,kBAAkB;EAClB,aAAa,qBAAqB,QAAQ,iBAAiB,QAAQ;EACnE;EACA;EACA;EACA;EACA;EACA;;KAGU,sBAAsB,KAAK;GACpC;EACD;;KAGU,yBAAyB,SAAS;EAC5C,aAAa;;KAGH,kBAAkB;EAC5B;EACA;EACA;;KAGU,sBAAsB;EAAe,MAAM;;KAE3C,eAAe;GACxB,uBAAuB;EACxB;EACA,QAAQ;;KAGE,kBAAkB;EAC5B;EACA,UAAU;EACV;GACC,cACG;IAEI;MACE,eAAe,eAGrB;;KAIM;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAEI;IACA;IACA;IACA;IACA;;EAGJ;IAEI;IACA;IACA;IACA;IACA;IACA;IACA;MAEI;MACA;;IAGJ;MACE;MACA;;IAEF;IACA;MAEI;MACA;;;EAKR;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MACE;MACA;QACE;QACA;QACA;QACA;QACA;;;;EAIN;IACE;IACA;IACA;IACA;IACA;;;KAIQ;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;KACG;MACC;MACA;MACA;QACE;QACA;QACA;UAAsB;UAAmB;;QACzC;QACA;QACA;QACA;QACA;UAAa;UAAe;;;MAE9B;MACA;QACE;QACA;QACA;UACE;UACA;UACA;YAAsB;YAAmB;;UACzC;UACA;UACA;UACA;UACA;YAAa;YAAe;;;QAE9B;;;;EAIN;IACE;IACA;;EAEF;IACE;IACA;IACA;IACA;;;cC9BS,wCAAqB,OAAA;;;;iBC3MlB,kBAAkB,YAAY,aAAa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/fieldExperiments.tsx","../src/fieldPersonalization.tsx","../src/utils/flattenSchemaType.ts"],"mappings":";KASY;EACV;EACA;;KAEU;EACV;EACA;EACA,UAAU;;KAGA;EACV,kBAAkB;EAClB,aAAa,qBAAqB,QAAQ,iBAAiB,QAAQ;EACnE;EACA;EACA;EACA;EACA;EACA;;;KAIU,oBAAoB;KAEpB;EACV,kBAAkB;EAClB,UAAU,kBAAkB,QAAQ,iBAAiB,QAAQ;EAC7D;EACA;EACA;EACA;EACA;;KAGU,sBAAsB,KAAK;GACpC;EACD;;KAGU,yBAAyB,SAAS;EAC5C,aAAa;;KAGH,8BAA8B,SAAS;EACjD,UAAU;;KAGA,kBAAkB;EAC5B;EACA;EACA;;KAGU,iCAAiC;EAC3C;EACA;;KAGU,sBAAsB;EAAe,MAAM;;KAE3C,eAAe;GACxB,uBAAuB;EACxB;EACA,QAAQ;;KAGE,kBAAkB;EAC5B;EACA,UAAU;EACV;GACC,cACG;IAEI;MACE,eAAe,eAGrB;;KAIM;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAEI;IACA;IACA;IACA;IACA;;EAGJ;IAEI;IACA;IACA;IACA;IACA;IACA;IACA;MAEI;MACA;;IAGJ;MACE;MACA;;IAEF;IACA;MAEI;MACA;;;EAKR;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MAEI;MACA;QACE;QACA;QACA;QACA;QACA;;;IAIN;MACE;MACA;QACE;QACA;QACA;QACA;QACA;;;;EAIN;IACE;IACA;IACA;IACA;IACA;;;KAIQ;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;KACG;MACC;MACA;MACA;QACE;QACA;QACA;UAAsB;UAAmB;;QACzC;QACA;QACA;QACA;QACA;UAAa;UAAe;;;MAE9B;MACA;QACE;QACA;QACA;UACE;UACA;UACA;YAAsB;YAAmB;;UACzC;UACA;UACA;UACA;UACA;YAAa;YAAe;;;QAE9B;;;;EAIN;IACE;IACA;;EAEF;IACE;IACA;IACA;IACA;;;cChBS,wCAAqB,OAAA;cC3CrB,4CAAyB,OAAA;;;;iBCpMtB,kBAAkB,YAAY,aAAa"}