@delmaredigital/payload-experiments 0.4.0-rc.4 → 0.4.0-rc.6

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.
Files changed (123) hide show
  1. package/dist/admin/copy/newTest.d.ts +1 -1
  2. package/dist/admin/copy/newTest.js +1 -1
  3. package/dist/admin/surface/ResultsRoute.js +2 -10
  4. package/dist/admin/surface/newTest/NewTest.js +16 -18
  5. package/dist/admin/surface/newTest/PageWizard.js +10 -12
  6. package/dist/admin/surface/newTest/newTest.css +3 -1
  7. package/dist/admin/surface/results/ResultsHeader.js +15 -8
  8. package/dist/blocks/bindings.js +6 -13
  9. package/dist/blocks/placementLocale.d.ts +2 -0
  10. package/dist/blocks/placementLocale.js +16 -12
  11. package/dist/goals/fairness.d.ts +1 -1
  12. package/dist/goals/fairness.js +9 -7
  13. package/dist/hooks/blockRemovalRule.d.ts +2 -1
  14. package/dist/hooks/blockRemovalRule.js +27 -5
  15. package/dist/hooks/pageGuard.js +2 -2
  16. package/dist/puck/ExperimentPicker.d.ts +2 -1
  17. package/dist/puck/ExperimentPicker.js +34 -30
  18. package/dist/puck/ExperimentSlot.js +3 -1
  19. package/dist/puck/copy.d.ts +1 -0
  20. package/dist/puck/copy.js +1 -0
  21. package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
  22. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  23. package/dist/puck/editor/CreateExperimentDrawer.js +24 -16
  24. package/dist/puck/editor/EditorControls.d.ts +1 -1
  25. package/dist/puck/editor/EditorControls.js +1 -1
  26. package/dist/puck/editor/ExperimentSlotEditor.js +624 -299
  27. package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
  28. package/dist/puck/editor/LeftoverVersions.js +97 -0
  29. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  30. package/dist/puck/editor/PlacementNotice.js +22 -0
  31. package/dist/puck/editor/QuickTestActions.d.ts +3 -0
  32. package/dist/puck/editor/QuickTestActions.js +50 -0
  33. package/dist/puck/editor/ResultsReadout.js +5 -0
  34. package/dist/puck/editor/VersionBuilder.d.ts +37 -12
  35. package/dist/puck/editor/VersionBuilder.js +273 -184
  36. package/dist/puck/editor/armWrites.d.ts +11 -2
  37. package/dist/puck/editor/armWrites.js +42 -3
  38. package/dist/puck/editor/armsCache.d.ts +1 -1
  39. package/dist/puck/editor/armsCache.js +2 -1
  40. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  41. package/dist/puck/editor/cloneSlot.js +7 -0
  42. package/dist/puck/editor/copy.d.ts +35 -20
  43. package/dist/puck/editor/copy.js +35 -20
  44. package/dist/puck/editor/createTest.d.ts +3 -0
  45. package/dist/puck/editor/createTest.js +33 -0
  46. package/dist/puck/editor/editor.chrome.css +32 -14
  47. package/dist/puck/editor/editor.css +58 -17
  48. package/dist/puck/editor/editor.model.d.ts +1 -1
  49. package/dist/puck/editor/editor.model.js +2 -2
  50. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  51. package/dist/puck/editor/localPlacements.d.ts +4 -2
  52. package/dist/puck/editor/localPlacements.js +20 -18
  53. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  54. package/dist/puck/editor/outlineVersion.js +36 -0
  55. package/dist/puck/editor/placementsCache.d.ts +33 -2
  56. package/dist/puck/editor/placementsCache.js +208 -33
  57. package/dist/puck/editor/sidebar.d.ts +8 -0
  58. package/dist/puck/editor/sidebar.js +74 -0
  59. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  60. package/dist/puck/editor/usePlacementNotice.js +14 -0
  61. package/dist/puck/visibility.d.ts +21 -0
  62. package/dist/puck/visibility.js +77 -0
  63. package/dist/server/recordContentChange.js +3 -1
  64. package/dist/server/resolveExperimentData.js +4 -1
  65. package/dist/testSurface/api.js +1 -1
  66. package/dist/testSurface/copy/common.d.ts +1 -1
  67. package/dist/testSurface/copy/common.js +3 -1
  68. package/dist/testSurface/copy/readiness.d.ts +18 -1
  69. package/dist/testSurface/copy/readiness.js +23 -1
  70. package/dist/testSurface/copy/testPage.d.ts +8 -6
  71. package/dist/testSurface/copy/testPage.js +8 -6
  72. package/dist/testSurface/readPreflight.d.ts +9 -0
  73. package/dist/testSurface/readPreflight.js +38 -0
  74. package/dist/testSurface/readinessRead.d.ts +50 -0
  75. package/dist/testSurface/readinessRead.js +46 -0
  76. package/dist/testSurface/results/results.css +1 -1
  77. package/dist/testSurface/results/results.model.d.ts +1 -1
  78. package/dist/testSurface/surface/contracts.d.ts +6 -2
  79. package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
  80. package/dist/testSurface/surface/editorPlacement.js +60 -0
  81. package/dist/testSurface/surface/pageBlock/parts.js +13 -3
  82. package/dist/testSurface/surface/readiness/ActionDialogs.js +65 -41
  83. package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
  84. package/dist/testSurface/surface/readiness/Banner.js +106 -68
  85. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  86. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  87. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
  88. package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
  89. package/dist/testSurface/surface/readiness/parts.js +0 -2
  90. package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
  91. package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
  92. package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
  93. package/dist/testSurface/surface/readiness/useTransition.js +69 -7
  94. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  95. package/dist/testSurface/surface/test/GoalSection.js +102 -74
  96. package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
  97. package/dist/testSurface/surface/test/LengthSection.js +2 -1
  98. package/dist/testSurface/surface/test/Rail.js +7 -4
  99. package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
  100. package/dist/testSurface/surface/test/Section.d.ts +3 -1
  101. package/dist/testSurface/surface/test/Section.js +38 -6
  102. package/dist/testSurface/surface/test/TargetingSection.js +5 -0
  103. package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
  104. package/dist/testSurface/surface/test/TestSurface.js +68 -7
  105. package/dist/testSurface/surface/test/VersionsSection.js +1 -0
  106. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  107. package/dist/testSurface/surface/test/fields.js +5 -35
  108. package/dist/testSurface/surface/test/testPage.css +12 -0
  109. package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
  110. package/dist/testSurface/surface/useTestDocument.js +61 -46
  111. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  112. package/dist/testSurface/useReadinessPolling.js +24 -0
  113. package/dist/transitions/makeContent.js +24 -5
  114. package/dist/transitions/placements.js +23 -34
  115. package/dist/transitions/preflightData.js +1 -1
  116. package/dist/types/puck.d.ts +1 -0
  117. package/dist/ui/Card.d.ts +2 -1
  118. package/dist/ui/Card.js +4 -4
  119. package/dist/ui/Inputs.js +8 -5
  120. package/dist/ui/Tabs.d.ts +2 -2
  121. package/dist/ui/Tabs.js +33 -32
  122. package/dist/ui/ui.css +26 -3
  123. package/package.json +1 -1
@@ -15,7 +15,7 @@ export declare const NEW_TEST_COPY: {
15
15
  readonly blockMeaning: "Compare different versions of content on a page.";
16
16
  readonly settingMeaning: "Compare different choices for a setting on your site.";
17
17
  readonly unavailable: "A developer needs to set up pages or settings before you can create a test.";
18
- readonly handoff: "Open the page, add an Experiment block where you want the test, and choose Test this block.";
18
+ readonly handoff: "Open the page, add an Experiment block where you want it, and choose Set up test.";
19
19
  readonly noPages: "There are no pages yet.";
20
20
  readonly recentPages: "Showing the 50 most recently edited.";
21
21
  readonly open: "Open";
@@ -15,7 +15,7 @@ export const NEW_TEST_COPY = {
15
15
  blockMeaning: 'Compare different versions of content on a page.',
16
16
  settingMeaning: 'Compare different choices for a setting on your site.',
17
17
  unavailable: 'A developer needs to set up pages or settings before you can create a test.',
18
- handoff: 'Open the page, add an Experiment block where you want the test, and choose Test this block.',
18
+ handoff: 'Open the page, add an Experiment block where you want it, and choose Set up test.',
19
19
  noPages: 'There are no pages yet.',
20
20
  recentPages: 'Showing the 50 most recently edited.',
21
21
  open: 'Open',
@@ -60,20 +60,12 @@ function ManagedResults({ id, surface, onTitleChange }) {
60
60
  children: [
61
61
  /*#__PURE__*/ _jsx("p", {
62
62
  role: "status",
63
- children: test.loadState === 'forbidden' ? C.forbidden : test.loadState === 'missing' ? C.missing : test.loadState === 'error' ? C.error : C.loading
63
+ children: test.preflightRead?.message ?? (test.loadState === 'loading' ? C.loading : C.error)
64
64
  }),
65
- test.loadState === 'error' ? /*#__PURE__*/ _jsx(Button, {
65
+ test.preflightRead?.retry ? /*#__PURE__*/ _jsx(Button, {
66
66
  onClick: ()=>void test.reload(),
67
67
  children: C.retry
68
68
  }) : null,
69
- test.errors._section ? /*#__PURE__*/ _jsx("p", {
70
- role: "alert",
71
- children: test.errors._section
72
- }) : null,
73
- test.preflightError ? /*#__PURE__*/ _jsx("p", {
74
- role: "alert",
75
- children: test.preflightError
76
- }) : null,
77
69
  test.loadState !== 'loading' && test.loadState !== 'missing' && test.loadState !== 'forbidden' ? /*#__PURE__*/ _jsx(ResultsBody, {
78
70
  id: id,
79
71
  surface: surface,
@@ -8,6 +8,7 @@ import { formatAdminURL } from 'payload/shared';
8
8
  import { NEW_TEST_COPY as C } from '../../copy/newTest.js';
9
9
  import { CreateRefused, createTest } from '../../../puck/editor/createTest.js';
10
10
  import { PageWizard } from './PageWizard.js';
11
+ import { Select } from '../../../ui/Select.js';
11
12
  import './newTest.css';
12
13
  export function NewTest({ surface, pages }) {
13
14
  const router = useRouter();
@@ -282,25 +283,22 @@ export function NewTest({ surface, pages }) {
282
283
  /*#__PURE__*/ _jsx("summary", {
283
284
  children: C.advanced
284
285
  }),
285
- /*#__PURE__*/ _jsxs("label", {
286
+ /*#__PURE__*/ _jsxs(Select, {
287
+ id: "xp-new-group",
288
+ label: C.group,
289
+ "aria-describedby": "xp-new-group-help",
290
+ disabled: layerState !== 'ready',
291
+ value: layer === undefined ? '' : layers.findIndex((item)=>item.id === layer),
292
+ onChange: (event)=>setLayer(event.currentTarget.value === '' ? undefined : layers[Number(event.currentTarget.value)]?.id),
286
293
  children: [
287
- C.group,
288
- /*#__PURE__*/ _jsxs("select", {
289
- "aria-describedby": "xp-new-group-help",
290
- disabled: layerState !== 'ready',
291
- value: layer === undefined ? '' : layers.findIndex((item)=>item.id === layer),
292
- onChange: (event)=>setLayer(event.currentTarget.value === '' ? undefined : layers[Number(event.currentTarget.value)]?.id),
293
- children: [
294
- /*#__PURE__*/ _jsx("option", {
295
- value: "",
296
- children: C.noGroup
297
- }),
298
- layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
299
- value: index,
300
- children: item.name
301
- }, index))
302
- ]
303
- })
294
+ /*#__PURE__*/ _jsx("option", {
295
+ value: "",
296
+ children: C.noGroup
297
+ }),
298
+ layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
299
+ value: index,
300
+ children: item.name
301
+ }, index))
304
302
  ]
305
303
  }),
306
304
  /*#__PURE__*/ _jsx("p", {
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useRouter } from 'next/navigation.js';
5
5
  import { formatAdminURL } from 'payload/shared';
6
+ import { canStartTest, readyToStart } from '../../../testSurface/readinessRead.js';
6
7
  import { useTestDocument } from '../../../testSurface/surface/useTestDocument.js';
7
8
  import { CopyRoute } from '../../../testSurface/surface/pagePicker/CopyRoute.js';
8
9
  import { PageCombobox } from '../../../testSurface/surface/pagePicker/PageCombobox.js';
@@ -29,7 +30,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
29
30
  adminRoute: surface.adminRoute,
30
31
  path: `/experiments/${encodeURIComponent(String(id))}`
31
32
  });
32
- const transition = useTransition(test, ()=>router.push(testUrl));
33
+ const transition = useTransition(test, ()=>router.push(testUrl), surface);
33
34
  useEffect(()=>{
34
35
  if (step === 'review') void test.refreshPreflight();
35
36
  }, [
@@ -45,13 +46,13 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
45
46
  children: [
46
47
  /*#__PURE__*/ _jsx("p", {
47
48
  role: "alert",
48
- children: test.loadState === 'forbidden' ? TEST_PAGE.forbidden : test.loadState === 'missing' ? TEST_PAGE.missing : TEST_PAGE.error
49
+ children: test.preflightRead?.message ?? TEST_PAGE.error
49
50
  }),
50
- /*#__PURE__*/ _jsx("button", {
51
+ test.preflightRead?.retry ? /*#__PURE__*/ _jsx("button", {
51
52
  type: "button",
52
53
  onClick: ()=>void test.reload(),
53
54
  children: TEST_PAGE.retry
54
- }),
55
+ }) : null,
55
56
  /*#__PURE__*/ _jsx("button", {
56
57
  type: "button",
57
58
  onClick: leave,
@@ -72,7 +73,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
72
73
  const arm = arms.find((item)=>item.key === step);
73
74
  const ctx = pageReadinessContext(doc, test.preflight, surface);
74
75
  const next = nextStep(test.preflight, ctx);
75
- const ready = Boolean(test.preflight && !test.preflightPending && !test.preflightError && test.preflight.checks.every((check)=>check.ok));
76
+ const ready = readyToStart(test);
76
77
  const busy = test.hasUnsaved || test.saving === 'saving' || transition.busy;
77
78
  const jump = (section, key)=>{
78
79
  if (section === 'versions') setStep(key ?? arms.find((item)=>!item.pageTarget)?.key ?? 'control');
@@ -91,7 +92,8 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
91
92
  children: step === 'collection' ? C.collection : step === 'review' ? C.review : arm?.kind === 'control' ? C.original : pageStepCopy(arm?.label ?? '')
92
93
  }),
93
94
  /*#__PURE__*/ _jsx(SaveStatus, {
94
- test: test
95
+ test: test,
96
+ messageInBlockerList: step === 'review' && !!test.preflight && !test.preflightError
95
97
  }),
96
98
  test.errors._section ? /*#__PURE__*/ _jsx("p", {
97
99
  role: "alert",
@@ -122,10 +124,6 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
122
124
  ]
123
125
  }) : step === 'review' ? /*#__PURE__*/ _jsxs(_Fragment, {
124
126
  children: [
125
- test.preflightError ? /*#__PURE__*/ _jsx("p", {
126
- role: "alert",
127
- children: test.preflightError
128
- }) : null,
129
127
  /*#__PURE__*/ _jsx("ul", {
130
128
  children: test.preflight?.checks.map((check, index)=>{
131
129
  if (!Object.hasOwn(READINESS, check.code)) return check.ok ? null : /*#__PURE__*/ _jsx("li", {
@@ -151,9 +149,9 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
151
149
  }) : null,
152
150
  /*#__PURE__*/ _jsx("button", {
153
151
  type: "button",
154
- disabled: busy || test.preflightPending || !test.preflight,
152
+ disabled: busy || test.preflightPending || !test.preflight || ready && (!canStartTest(test) || transition.checking),
155
153
  onClick: ()=>{
156
- if (ready) void transition.run(()=>createApi(surface.apiRoute).start(id));
154
+ if (ready) void transition.run('start', ()=>createApi(surface.apiRoute).start(id));
157
155
  else if (next) jump(next.section, next.arm);
158
156
  },
159
157
  children: ready ? C.start : C.finishSetup
@@ -4,6 +4,8 @@
4
4
  .xp-new-test-card strong { font-size: 1.25rem; }
5
5
  .xp-new-test-card:hover { background: var(--xp-surface-raised); }
6
6
  .xp-new-test label { display: block; margin-block: .75rem; }
7
- .xp-new-test input:not([type=radio]), .xp-new-test textarea, .xp-new-test select { display: block; width: 100%; max-width: 36rem; padding: .5rem; color: var(--xp-text); background: var(--xp-input-bg); border: 1px solid var(--xp-input-border); font: inherit; }
7
+ .xp-new-test input:not([type=radio]), .xp-new-test textarea { display: block; width: 100%; max-width: 36rem; padding: .5rem; color: var(--xp-text); background: var(--xp-input-bg); border: 1px solid var(--xp-input-border); font: inherit; }
8
8
  .xp-new-test-choice span { display: block; margin-left: 1.5rem; }
9
9
  .xp-new-test-actions { display: flex; gap: 1rem; margin-top: var(--xp-space-4); }
10
+
11
+ .xp-new-test .xp-ui-select-wrap { max-width: 36rem; }
@@ -1,5 +1,8 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { canStartTest, readyToStart } from '../../../testSurface/readinessRead.js';
4
+ import { BlockerList } from '../../../testSurface/surface/readiness/BlockerList.js';
5
+ import { ReadinessReadStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
3
6
  import { surfaceUrls } from '../../../testSurface/surfaceUrls.js';
4
7
  import { useEffect, useState } from 'react';
5
8
  import { formatAdminURL } from 'payload/shared';
@@ -9,7 +12,7 @@ import { Banner, StatusChip } from '../../../ui/Feedback.js';
9
12
  import { createApi } from '../../../testSurface/api.js';
10
13
  import { availableActions, actionGroupLabel } from '../../../testSurface/actions/actions.model.js';
11
14
  import { AllocateAction, ConfirmAction } from '../../../testSurface/surface/readiness/ActionDialogs.js';
12
- import { READINESS, daysRemaining, displayDate, nextStep, pageReadinessContext } from '../../../testSurface/surface/readiness/readiness.model.js';
15
+ import { READINESS, daysRemaining, displayDate, blockingSteps, pageReadinessContext } from '../../../testSurface/surface/readiness/readiness.model.js';
13
16
  import { READINESS_COPY as R, runningCopy, stoppedCopy, decidedCopy } from '../../../testSurface/copy/readiness.js';
14
17
  import { RESULTS_COPY as C } from '../../../testSurface/copy/results.js';
15
18
  import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
@@ -55,9 +58,10 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
55
58
  'allocate',
56
59
  'stop'
57
60
  ].indexOf(b.id) : 0);
58
- const next = nextStep(test.preflight, pageReadinessContext(doc, test.preflight, surface));
59
- const ready = Boolean(test.preflight && !test.preflightPending && !test.preflightError && test.preflight.checks.every((check)=>check.ok));
60
- const startReason = next?.sentence ?? (!ready ? test.preflightError ? R.checkError : R.checking : undefined);
61
+ const setup = doc.status === 'draft' || doc.status === 'stopped';
62
+ const blockers = blockingSteps(test.preflight, pageReadinessContext(doc, test.preflight, surface));
63
+ const ready = readyToStart(test);
64
+ const startReason = test.preflightError ?? blockers[0]?.sentence ?? (!ready ? R.checking : undefined);
61
65
  const action = available.find((item)=>item.id === selected);
62
66
  const sentence = doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'stopped' ? stoppedCopy(displayDate(doc.stoppedAt)) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : doc.status === 'archived' ? R.archived : null;
63
67
  const testURL = formatAdminURL({
@@ -114,7 +118,7 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
114
118
  }),
115
119
  available.map((item)=>/*#__PURE__*/ _jsx(Button, {
116
120
  variant: item.tone === 'danger' ? 'danger' : 'secondary',
117
- disabled: item.id === 'start' && !!startReason || !!selected || test.hasUnsaved || test.saving === 'saving' || item.id === 'allocate' && doc.allocation >= 100,
121
+ disabled: item.id === 'start' && !canStartTest(test) || !!selected || test.hasUnsaved || test.saving === 'saving' || item.id === 'allocate' && doc.allocation >= 100,
118
122
  title: item.id === 'start' ? startReason : item.id === 'allocate' && doc.allocation >= 100 ? R.everyone : undefined,
119
123
  onClick: ()=>setSelected(item.id),
120
124
  children: item.id === 'allocate' ? R.allocate : item.label
@@ -127,9 +131,12 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
127
131
  tone: "error",
128
132
  children: test.errors._section
129
133
  }) : null,
130
- test.preflightError ? /*#__PURE__*/ _jsx(Banner, {
131
- tone: "error",
132
- children: test.preflightError
134
+ /*#__PURE__*/ _jsx(ReadinessReadStatus, {
135
+ test: test,
136
+ messageInBlockerList: setup && !!test.preflight && !test.preflightError
137
+ }),
138
+ setup ? /*#__PURE__*/ _jsx(BlockerList, {
139
+ steps: blockers
133
140
  }) : null,
134
141
  children,
135
142
  action?.id === 'allocate' ? /*#__PURE__*/ _jsx(AllocateAction, {
@@ -1,3 +1,4 @@
1
+ import { walkVisiblePuck } from '../puck/visibility.js';
1
2
  import { documentEditor, puckCollections } from '../options.js';
2
3
  import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
3
4
  /** Same document-kind rule as the scan; Payload blocks are top level, Puck is recursive. */ export function placementSlugs(options, collection, doc) {
@@ -15,19 +16,11 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
15
16
  if (editor !== 'puck') return [];
16
17
  const registration = puckCollections(options).find((r)=>r.slug === collection);
17
18
  const found = new Set();
18
- function walk(v) {
19
- if (Array.isArray(v)) {
20
- v.forEach(walk);
21
- return;
22
- }
23
- if (!isObject(v)) return;
24
- if (v.type === 'ExperimentSlot' && isObject(v.props)) {
25
- const ref = v.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
26
- if (typeof slug === 'string') found.add(slug);
27
- }
28
- Object.values(v).forEach(walk);
29
- }
30
- if (registration) walk(doc[registration.field]);
19
+ if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
20
+ if (visibility.hidden || node.type !== 'ExperimentSlot') return;
21
+ const ref = node.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
22
+ if (typeof slug === 'string') found.add(slug);
23
+ });
31
24
  return [
32
25
  ...found
33
26
  ];
@@ -19,3 +19,5 @@ export declare function placementLocaleViews(req: PayloadRequest, collection: st
19
19
  * The incoming hook document is already flattened to the writing locale.
20
20
  */
21
21
  export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean): RemovedPlacementViews;
22
+ /** Rebuild unchanged locale maps around a flattened hook write before reading each view. */
23
+ export declare function mergedPlacementLocales(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>): Record<string, unknown>;
@@ -84,9 +84,22 @@ export function localeRequest(req, view) {
84
84
  */ export function removedPlacementViews(req, collection, before, after, removingPage) {
85
85
  const result = new Map();
86
86
  if (!before) return result;
87
+ const options = req.payload.config.custom.xp;
88
+ const rawAfter = mergedPlacementLocales(req, collection, before, after);
89
+ for (const view of placementLocaleViews(req, collection)){
90
+ const viewReq = localeRequest(req, view);
91
+ const previous = placementSlugs(options, collection, placementLocaleContent(viewReq, collection, before));
92
+ const next = removingPage ? [] : placementSlugs(options, collection, placementLocaleContent(viewReq, collection, rawAfter));
93
+ for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
94
+ ...result.get(slug) ?? [],
95
+ view
96
+ ]);
97
+ }
98
+ return result;
99
+ }
100
+ /** Rebuild unchanged locale maps around a flattened hook write before reading each view. */ export function mergedPlacementLocales(req, collection, before, after) {
87
101
  const localization = req.payload.config.localization;
88
102
  const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
89
- const options = req.payload.config.custom.xp;
90
103
  const fields = config ? flattenTopLevelFields(config.fields) : [];
91
104
  const localized = fields.filter((field)=>'name' in field && 'localized' in field && field.localized);
92
105
  // Keep the raw locale maps for unchanged languages when merging a partial,
@@ -96,20 +109,11 @@ export function localeRequest(req, view) {
96
109
  };
97
110
  if (localization && req.locale !== 'all') for (const field of localized){
98
111
  if (!('name' in field) || typeof field.name !== 'string' || !(field.name in after)) continue;
99
- const previousValue = before[field.name];
112
+ const previousValue = before?.[field.name];
100
113
  rawAfter[field.name] = {
101
114
  ...isObject(previousValue) ? previousValue : {},
102
115
  [req.locale || localization.defaultLocale]: after[field.name]
103
116
  };
104
117
  }
105
- for (const view of placementLocaleViews(req, collection)){
106
- const viewReq = localeRequest(req, view);
107
- const previous = placementSlugs(options, collection, placementLocaleContent(viewReq, collection, before));
108
- const next = removingPage ? [] : placementSlugs(options, collection, placementLocaleContent(viewReq, collection, rawAfter));
109
- for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
110
- ...result.get(slug) ?? [],
111
- view
112
- ]);
113
- }
114
- return result;
118
+ return rawAfter;
115
119
  }
@@ -1,7 +1,7 @@
1
1
  import type { PayloadRequest } from 'payload';
2
2
  import type { Arm, DocId, ResolvedOptions } from '../types/contracts.js';
3
3
  import type { PlacementDoc } from '../db/placements.js';
4
- export declare const OUTSIDE_GOAL = "This goal isn't inside the part being tested, so every version shows it the same way.";
4
+ export declare const OUTSIDE_GOAL: (name?: string, kind?: string) => string;
5
5
  export declare const LEGACY_FAIRNESS = "Goal fairness isn't checked for tests started before this update.";
6
6
  export interface GoalPlacement {
7
7
  collection?: string;
@@ -1,3 +1,4 @@
1
+ import { puckVisibility } from '../puck/visibility.js';
1
2
  import { clickGoalContent } from '../db/clickGoals.js';
2
3
  import { safeError } from '../log.js';
3
4
  import { documentEditor, puckCollections } from '../options.js';
@@ -5,18 +6,18 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject, slotBlocks } from '../bloc
5
6
  import { resolvePageCollection } from '../transitions/pageCollection.js';
6
7
  import { scanPlacements, uniquePlacementDocs } from '../transitions/placementInteractions.js';
7
8
  import { CLICK_KEY } from './key.js';
8
- export const OUTSIDE_GOAL = "This goal isn't inside the part being tested, so every version shows it the same way.";
9
+ export const OUTSIDE_GOAL = (name = 'Selected goal', kind = 'block')=>kind === 'block' ? `Heads up: the click goal “${name}” is outside this test's block, so every version shows the same button. The test can still start. To compare different buttons, move the goal inside each version.` : `Heads up: the click goal “${name}” isn't on any of this test's pages. The test can still start. Add the goal to every version's page to measure those clicks.`;
9
10
  export const LEGACY_FAIRNESS = "Goal fairness isn't checked for tests started before this update.";
10
- /** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels) {
11
+ /** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels, visibility) {
11
12
  if (Array.isArray(value)) {
12
- value.forEach((item)=>collect(item, into, label, labels));
13
+ value.forEach((item)=>collect(item, into, label, labels, visibility));
13
14
  return;
14
15
  }
15
- if (!isObject(value)) return;
16
+ if (!isObject(value) || visibility?.get(value)?.hidden) return;
16
17
  const blockType = typeof value.blockType === 'string' ? value.blockType : typeof value.type === 'string' ? value.type : '';
17
18
  const containing = labels.get(blockType) ?? (blockType || label);
18
19
  if (typeof value.xpGoal === 'string' && CLICK_KEY.test(value.xpGoal)) into.set(value.xpGoal, containing || value.xpGoal);
19
- Object.values(value).forEach((item)=>collect(item, into, containing, labels));
20
+ Object.values(value).forEach((item)=>collect(item, into, containing, labels, visibility));
20
21
  }
21
22
  function blockLabels(req) {
22
23
  const labels = new Map();
@@ -132,16 +133,17 @@ function blockLabels(req) {
132
133
  } else {
133
134
  const registration = puckCollections(options).find((c)=>c.slug === placement.collection);
134
135
  if (!registration) continue;
136
+ const visibility = puckVisibility(doc[registration.field]);
135
137
  const walk = (value)=>{
136
138
  if (Array.isArray(value)) {
137
139
  value.forEach(walk);
138
140
  return;
139
141
  }
140
- if (!isObject(value)) return;
142
+ if (!isObject(value) || visibility.get(value)?.hidden) return;
141
143
  const props = isObject(value.props) ? value.props : undefined;
142
144
  const ref = props?.experiment;
143
145
  if (value.type === 'ExperimentSlot' && props && (typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined) === experiment.slug) {
144
- for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels);
146
+ for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels, visibility);
145
147
  return;
146
148
  }
147
149
  Object.values(value).forEach(walk);
@@ -22,8 +22,9 @@ export declare const blockRemovalRule: {
22
22
  prepare(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, exec?: Executor, tests?: readonly PlacementTest[]): Promise<{
23
23
  views: RemovedPlacementViews;
24
24
  affected: PlacementTest[];
25
+ hidden: Set<string>;
25
26
  }>;
26
27
  discover(exec: Executor, removed: string[], tests?: readonly PlacementTest[]): Promise<PlacementTest[]>;
27
28
  claim(req: PayloadRequest, transaction: unknown, affected: readonly PlacementTest[], collection: string, id: DocId, views: RemovedPlacementViews): RemovalClaims;
28
- check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval): Promise<void>;
29
+ check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval, hidden?: ReadonlySet<string>): Promise<void>;
29
30
  };
@@ -1,9 +1,11 @@
1
+ import { walkVisiblePuck } from '../puck/visibility.js';
2
+ import { documentEditor, puckCollections } from '../options.js';
1
3
  import { removableBlockTests } from '../db/placements.js';
2
4
  import { XpNoTransactionError, XpRefusal } from '../errors.js';
3
- import { lastBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
5
+ import { lastBlockPlacementCopy, hiddenBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
4
6
  import { hasOtherPublishedBlockPlacement } from '../transitions/placements.js';
5
7
  import { bulkRemoves } from '../db/bulkPlacementRemoval.js';
6
- import { localeRequest, placementLocaleContent, removedPlacementViews, placementDocumentKey } from '../blocks/placementLocale.js';
8
+ import { localeRequest, placementLocaleContent, removedPlacementViews, placementDocumentKey, placementLocaleViews, mergedPlacementLocales } from '../blocks/placementLocale.js';
7
9
  import { placementSlugs } from '../blocks/bindings.js';
8
10
  export function releaseRemovalClaim(req, collection, id, ownKeys) {
9
11
  const claims = req.context.xpPlacementRemovals;
@@ -54,9 +56,29 @@ export const blockRemovalRule = {
54
56
  const affected = views.size ? await blockRemovalRule.discover(exec, [
55
57
  ...views.keys()
56
58
  ], tests) : [];
59
+ const hidden = new Set();
60
+ const options = req.payload.config.custom.xp;
61
+ const registration = puckCollections(options).find((entry)=>entry.slug === collection);
62
+ const rawAfter = mergedPlacementLocales(req, collection, before, after);
63
+ if (views.size && !removingPage && registration && documentEditor(options, collection, after) === 'puck') {
64
+ for (const view of placementLocaleViews(req, collection)){
65
+ const viewReq = localeRequest(req, view);
66
+ const visibleBefore = new Set();
67
+ walkVisiblePuck(placementLocaleContent(viewReq, collection, before)?.[registration.field], (block, visibility)=>{
68
+ if (!visibility.hidden && block.type === 'ExperimentSlot') visibleBefore.add(String(block.props.id));
69
+ });
70
+ walkVisiblePuck(placementLocaleContent(viewReq, collection, rawAfter)?.[registration.field], (block, visibility)=>{
71
+ if (!visibility.hidden || block.type !== 'ExperimentSlot' || !visibleBefore.has(String(block.props.id))) return;
72
+ const ref = block.props.experiment;
73
+ const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
74
+ if (typeof slug === 'string') hidden.add(slug);
75
+ });
76
+ }
77
+ }
57
78
  return {
58
79
  views,
59
- affected
80
+ affected,
81
+ hidden
60
82
  };
61
83
  },
62
84
  async discover (exec, removed, tests) {
@@ -101,7 +123,7 @@ export const blockRemovalRule = {
101
123
  }
102
124
  return claims;
103
125
  },
104
- async check (req, current, affected, collection, id, removingPage, views, bulk) {
126
+ async check (req, current, affected, collection, id, removingPage, views, bulk, hidden) {
105
127
  const transaction = await req.transactionID;
106
128
  // Claim only after every earlier guard passed. These claims cover subsequent
107
129
  // writes; the complete bulk selection covers siblings before any can decide.
@@ -127,7 +149,7 @@ export const blockRemovalRule = {
127
149
  if (transaction == null) throw new XpNoTransactionError('Save this page with transactions on.');
128
150
  // Bulk selection is immutable through every sibling's decision, including
129
151
  // earlier rule refusals. afterOperation explains unrelated failed writes.
130
- const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
152
+ const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : hidden?.has(test.slug) ? hiddenBlockPlacementCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
131
153
  if (bulk && excludedSibling) bulk.refusals.set(message, pendingBlockRemovalCopy(test.name));
132
154
  throw new XpRefusal('locked-placement', message, {
133
155
  experimentId: test.id
@@ -287,7 +287,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
287
287
  const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
288
288
  let tests = await placementTests(exec);
289
289
  const trashing = Boolean(collection.trash && after.deletedAt != null);
290
- const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, after, trashing || drafts && after._status !== 'published', exec, tests);
290
+ const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, after, trashing || drafts && after._status !== 'published', exec, tests);
291
291
  const publishes = !drafts || after._status === 'published';
292
292
  const noTransaction = ()=>{
293
293
  if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
@@ -319,7 +319,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
319
319
  if (old != null && (unpublishing || trashing || page.pathOf(after) !== old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
320
320
  }
321
321
  if (publishes) refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection.slug);
322
- if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk);
322
+ if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk, hidden);
323
323
  return data;
324
324
  } catch (error) {
325
325
  mapBusy(error);
@@ -1,5 +1,6 @@
1
1
  import type { ExperimentRef } from '../types/puck.js';
2
- export declare function ExperimentPicker({ value, onChange }: {
2
+ export declare function ExperimentPicker({ value, onChange, allowEmpty }: {
3
+ allowEmpty?: boolean;
3
4
  value: ExperimentRef | null;
4
5
  onChange: (value: ExperimentRef | null) => void;
5
6
  }): import("react").JSX.Element;
@@ -9,7 +9,7 @@ function isExperimentOption(value) {
9
9
  const doc = value;
10
10
  return (typeof doc.id === 'string' || typeof doc.id === 'number') && typeof doc.slug === 'string' && typeof doc.name === 'string' && typeof doc.status === 'string' && Object.hasOwn(pickerCopy.statuses, doc.status);
11
11
  }
12
- export function ExperimentPicker({ value, onChange }) {
12
+ export function ExperimentPicker({ value, onChange, allowEmpty = true }) {
13
13
  const { api } = usePuckRoutes();
14
14
  const id = useId();
15
15
  const [experiments, setExperiments] = useState([]);
@@ -92,35 +92,39 @@ export function ExperimentPicker({ value, onChange }) {
92
92
  htmlFor: id,
93
93
  children: pickerCopy.label
94
94
  }),
95
- /*#__PURE__*/ _jsxs("select", {
96
- id: id,
97
- className: "xp-ui-input xp-ui-select",
98
- value: selected,
99
- onChange: (event)=>{
100
- const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
101
- onChange(experiment ? {
102
- id: experiment.id,
103
- slug: experiment.slug
104
- } : null);
105
- },
106
- children: [
107
- /*#__PURE__*/ _jsx("option", {
108
- value: "",
109
- children: pickerCopy.none
110
- }),
111
- value && !experiments.some((doc)=>String(doc.id) === selected) ? /*#__PURE__*/ _jsx("option", {
112
- value: selected,
113
- children: value.slug
114
- }) : null,
115
- visible.map((doc)=>/*#__PURE__*/ _jsxs("option", {
116
- value: String(doc.id),
117
- children: [
118
- doc.name,
119
- " · ",
120
- pickerCopy.statuses[doc.status]
121
- ]
122
- }, doc.id))
123
- ]
95
+ /*#__PURE__*/ _jsx("span", {
96
+ className: "xp-ui-select-wrap",
97
+ children: /*#__PURE__*/ _jsxs("select", {
98
+ id: id,
99
+ className: "xp-ui-input xp-ui-select",
100
+ value: selected,
101
+ onChange: (event)=>{
102
+ const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
103
+ if (experiment || allowEmpty) onChange(experiment ? {
104
+ id: experiment.id,
105
+ slug: experiment.slug
106
+ } : null);
107
+ },
108
+ children: [
109
+ /*#__PURE__*/ _jsx("option", {
110
+ value: "",
111
+ disabled: !allowEmpty,
112
+ children: allowEmpty ? pickerCopy.none : pickerCopy.choose
113
+ }),
114
+ value && !experiments.some((doc)=>String(doc.id) === selected) ? /*#__PURE__*/ _jsx("option", {
115
+ value: selected,
116
+ children: value.slug
117
+ }) : null,
118
+ visible.map((doc)=>/*#__PURE__*/ _jsxs("option", {
119
+ value: String(doc.id),
120
+ children: [
121
+ doc.name,
122
+ " · ",
123
+ pickerCopy.statuses[doc.status]
124
+ ]
125
+ }, doc.id))
126
+ ]
127
+ })
124
128
  }),
125
129
  state === 'error' ? /*#__PURE__*/ _jsx("div", {
126
130
  className: "xp-ui-banner xp-ui-banner--error",
@@ -1,4 +1,5 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { fullyHidden } from './visibility.js';
2
3
  import { ViewportExposure } from '../client/ViewportExposure.js';
3
4
  import { experimentSlotDefaultProps, experimentSlotFields, experimentSlotLabel } from './slotConfig.js';
4
5
  import { createExperimentSlotField } from './experimentSlotField.js';
@@ -16,6 +17,7 @@ export function createExperimentSlot({ routes: inputRoutes } = {}) {
16
17
  },
17
18
  defaultProps: experimentSlotDefaultProps,
18
19
  render: (props)=>{
20
+ if (fullyHidden(props._visibility)) return /*#__PURE__*/ _jsx(_Fragment, {});
19
21
  const Slot = props[slotToRender(props)];
20
22
  return /*#__PURE__*/ _jsx(ViewportExposure, {
21
23
  expose: props.xpExpose,
@@ -8,6 +8,7 @@ export declare const slotLabels: {
8
8
  export declare const pickerCopy: {
9
9
  readonly label: "Test";
10
10
  readonly none: "No test";
11
+ readonly choose: "Choose a test";
11
12
  readonly search: "Search tests";
12
13
  readonly loading: "Loading tests…";
13
14
  readonly error: "Couldn't load tests.";
package/dist/puck/copy.js CHANGED
@@ -9,6 +9,7 @@ export const slotLabels = {
9
9
  export const pickerCopy = {
10
10
  label: 'Test',
11
11
  none: 'No test',
12
+ choose: 'Choose a test',
12
13
  search: 'Search tests',
13
14
  loading: 'Loading tests…',
14
15
  error: "Couldn't load tests.",