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

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 (135) hide show
  1. package/dist/admin/blocks/BlockPanel.js +6 -4
  2. package/dist/admin/blocks/inject.js +1 -0
  3. package/dist/admin/blocks/model.d.ts +3 -2
  4. package/dist/admin/blocks/model.js +8 -4
  5. package/dist/admin/copy/blocks.d.ts +3 -2
  6. package/dist/admin/copy/blocks.js +7 -6
  7. package/dist/admin/surface/ResultsRoute.js +2 -1
  8. package/dist/admin/surface/TestsHome.d.ts +2 -1
  9. package/dist/admin/surface/TestsHome.js +91 -37
  10. package/dist/admin/surface/TestsSurface.js +3 -0
  11. package/dist/admin/surface/home.model.d.ts +2 -0
  12. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  13. package/dist/admin/surface/newTest/newTest.css +1 -1
  14. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  15. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  16. package/dist/admin/views/buildSurfaceProps.js +10 -3
  17. package/dist/blocks/bindings.js +3 -2
  18. package/dist/blocks/placementLanguages.d.ts +7 -0
  19. package/dist/blocks/placementLanguages.js +27 -0
  20. package/dist/blocks/placementLocale.d.ts +21 -7
  21. package/dist/blocks/placementLocale.js +218 -67
  22. package/dist/db/appends.d.ts +13 -0
  23. package/dist/db/appends.js +49 -0
  24. package/dist/db/bulkPlacementRemoval.js +8 -4
  25. package/dist/endpoints/contentLocale.d.ts +6 -0
  26. package/dist/endpoints/contentLocale.js +15 -0
  27. package/dist/endpoints/deleteImpact.d.ts +6 -0
  28. package/dist/endpoints/deleteImpact.js +206 -0
  29. package/dist/endpoints/index.js +7 -0
  30. package/dist/endpoints/pages.js +7 -3
  31. package/dist/endpoints/placementStatus.js +6 -1
  32. package/dist/endpoints/preflight.d.ts +1 -1
  33. package/dist/endpoints/preflight.js +17 -2
  34. package/dist/exports/adminClient.d.ts +1 -1
  35. package/dist/exports/adminClient.js +1 -1
  36. package/dist/exports/index.d.ts +1 -1
  37. package/dist/goals/fairness.js +38 -31
  38. package/dist/hooks/blockRemovalRule.d.ts +2 -2
  39. package/dist/hooks/blockRemovalRule.js +16 -14
  40. package/dist/hooks/pageGuard.d.ts +3 -0
  41. package/dist/hooks/pageGuard.js +33 -23
  42. package/dist/hooks/puckNestedTests.d.ts +8 -0
  43. package/dist/hooks/puckNestedTests.js +36 -0
  44. package/dist/lib/placementPages.d.ts +2 -1
  45. package/dist/lib/placementPages.js +10 -2
  46. package/dist/manifest/compile.d.ts +2 -1
  47. package/dist/manifest/compile.js +5 -1
  48. package/dist/puck/ExperimentPicker.js +40 -37
  49. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  50. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  51. package/dist/puck/editor/ExperimentSlotEditor.js +135 -104
  52. package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
  53. package/dist/puck/editor/LeftoverVersions.js +40 -43
  54. package/dist/puck/editor/VersionBuilder.d.ts +18 -1
  55. package/dist/puck/editor/VersionBuilder.js +217 -39
  56. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  57. package/dist/puck/editor/blockClipboard.js +20 -0
  58. package/dist/puck/editor/copy.d.ts +8 -1
  59. package/dist/puck/editor/copy.js +9 -1
  60. package/dist/puck/editor/editor.chrome.css +117 -3
  61. package/dist/puck/editor/editor.css +130 -8
  62. package/dist/puck/editor/editor.model.d.ts +2 -1
  63. package/dist/puck/editor/editor.model.js +2 -2
  64. package/dist/puck/editor/localPlacements.d.ts +1 -0
  65. package/dist/puck/editor/localPlacements.js +12 -0
  66. package/dist/puck/editor/placementsCache.d.ts +18 -12
  67. package/dist/puck/editor/placementsCache.js +52 -47
  68. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  69. package/dist/puck/editor/usePlacementNotice.js +4 -3
  70. package/dist/puck/experimentSlug.d.ts +2 -0
  71. package/dist/puck/experimentSlug.js +3 -0
  72. package/dist/puck/nestedTestCopy.d.ts +8 -0
  73. package/dist/puck/nestedTestCopy.js +22 -0
  74. package/dist/puck/nestedTests.d.ts +17 -0
  75. package/dist/puck/nestedTests.js +30 -0
  76. package/dist/puck/slotConfig.d.ts +1 -1
  77. package/dist/puck/slotConfig.js +17 -4
  78. package/dist/puck/visibility.d.ts +2 -3
  79. package/dist/puck/visibility.js +11 -7
  80. package/dist/server/recordContentChange.js +34 -19
  81. package/dist/server/resolveExperimentData.js +2 -2
  82. package/dist/testSurface/PreviewLinks.js +6 -2
  83. package/dist/testSurface/api.d.ts +6 -3
  84. package/dist/testSurface/api.js +10 -6
  85. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  86. package/dist/testSurface/contentLocaleURL.js +3 -0
  87. package/dist/testSurface/copy/common.d.ts +4 -0
  88. package/dist/testSurface/copy/common.js +8 -4
  89. package/dist/testSurface/copy/languages.d.ts +11 -0
  90. package/dist/testSurface/copy/languages.js +7 -0
  91. package/dist/testSurface/copy/readiness.d.ts +1 -1
  92. package/dist/testSurface/copy/readiness.js +1 -1
  93. package/dist/testSurface/copy/testPage.d.ts +21 -0
  94. package/dist/testSurface/copy/testPage.js +21 -0
  95. package/dist/testSurface/placementLabel.d.ts +8 -0
  96. package/dist/testSurface/placementLabel.js +24 -0
  97. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  98. package/dist/testSurface/placements/placementLabels.js +2 -1
  99. package/dist/testSurface/results/results.css +1 -1
  100. package/dist/testSurface/surface/contracts.d.ts +2 -0
  101. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  102. package/dist/testSurface/surface/editorPlacement.js +18 -0
  103. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  104. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  105. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  106. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  107. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  108. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  109. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  110. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  111. package/dist/testSurface/surface/useTestDocument.js +20 -4
  112. package/dist/testSurface/useApi.d.ts +4 -1
  113. package/dist/transitions/checkStart.d.ts +4 -1
  114. package/dist/transitions/checkStart.js +117 -14
  115. package/dist/transitions/contentFields.js +9 -5
  116. package/dist/transitions/makeContent.js +5 -4
  117. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  118. package/dist/transitions/nestedPlacementNames.js +33 -0
  119. package/dist/transitions/pageVersions.js +3 -1
  120. package/dist/transitions/placementInteractions.js +7 -4
  121. package/dist/transitions/placements.d.ts +26 -1
  122. package/dist/transitions/placements.js +219 -56
  123. package/dist/transitions/preflightData.d.ts +2 -1
  124. package/dist/transitions/preflightData.js +66 -3
  125. package/dist/transitions/start.js +4 -1
  126. package/dist/types/endpoints.d.ts +35 -1
  127. package/dist/types/endpoints.js +1 -1
  128. package/dist/types/surface.d.ts +2 -0
  129. package/dist/ui/Button.js +2 -2
  130. package/dist/ui/Inputs.d.ts +4 -3
  131. package/dist/ui/Inputs.js +9 -9
  132. package/dist/ui/SelectControl.d.ts +33 -0
  133. package/dist/ui/SelectControl.js +504 -0
  134. package/dist/ui/ui.css +13 -5
  135. package/package.json +3 -2
@@ -1,3 +1,6 @@
1
+ import { placementLanguages } from '../blocks/placementLanguages.js';
2
+ import { puckExperimentSlug } from '../puck/experimentSlug.js';
3
+ import { nestedTests, nestedTestLabel, nestedTestSlug } from '../puck/nestedTests.js';
1
4
  import { walkVisiblePuck } from '../puck/visibility.js';
2
5
  import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
3
6
  import { safeError } from '../log.js';
@@ -5,9 +8,8 @@ import { pageVersionContent } from '../db/pageContent.js';
5
8
  import { comparableContent } from './pageVersions.js';
6
9
  import { isDeepStrictEqual } from 'node:util';
7
10
  import { hasLocalizedFields } from './contentFields.js';
8
- import { localeRequest, placementLocaleContent, placementLocaleViews } from '../blocks/placementLocale.js';
9
- import { placementSlugs } from '../blocks/bindings.js';
10
- import { documentEditor, puckCollections as normalisePuckCollections } from '../options.js';
11
+ import { localeRequest, placementReader } from '../blocks/placementLocale.js';
12
+ import { puckCollections as normalisePuckCollections } from '../options.js';
11
13
  const slots = [
12
14
  'control',
13
15
  'variantA',
@@ -15,7 +17,7 @@ const slots = [
15
17
  'variantC'
16
18
  ];
17
19
  async function placementDocuments(req, query, guard) {
18
- // §7.8 page guard: the hook must see test placements regardless of the editor's access.
20
+ // §7.8 page guard / visitor impact: count all placements regardless of the editor's access; impact details are checked separately.
19
21
  if (guard) return req.payload.find({
20
22
  ...query,
21
23
  req,
@@ -45,16 +47,17 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
45
47
  /** Published rows only, one pass per collection across both editor registrations.
46
48
  * The exclusion predicate reads live transaction claims after each awaited page.
47
49
  */ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded) {
48
- const scanReq = req.payload.config.localization ? {
49
- ...req,
50
- locale: 'all'
51
- } : req;
50
+ const scanReq = localeRequest(req, {
51
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
52
+ fallbackLocale: false
53
+ });
52
54
  const collections = new Set([
53
55
  ...normalisePuckCollections(options).map((entry)=>entry.slug),
54
56
  ...(options.blocks?.collections ?? []).map((entry)=>entry.slug)
55
57
  ]);
56
58
  for (const collection of collections){
57
59
  const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
60
+ const reader = placementReader(req, collection, options);
58
61
  let page = 1;
59
62
  while(true){
60
63
  const result = await placementDocuments(scanReq, {
@@ -76,15 +79,116 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
76
79
  }
77
80
  } : {}
78
81
  }, true);
79
- if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && placementLocaleViews(req, collection).some((view)=>placementSlugs(options, collection, placementLocaleContent(localeRequest(req, view), collection, doc)).includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
82
+ if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && reader.views.some((view)=>reader.read(doc, 'all-locales', view).slugs.includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
80
83
  if (!result.hasNextPage) break;
81
84
  page++;
82
85
  }
83
86
  }
84
87
  return false;
85
88
  }
89
+ /** Visitor-impact scan: one published read per collection page. Resolve every
90
+ * visitor locale, including configured fallbacks; the endpoint groups by page.
91
+ */ export async function* publishedBlockPlacementPages(req, options, slug) {
92
+ const scanReq = localeRequest(req, {
93
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
94
+ fallbackLocale: false
95
+ });
96
+ const puck = options.puck?.enabled ? normalisePuckCollections(options) : [], blocks = options.blocks?.collections ?? [];
97
+ for (const collection of new Set([
98
+ ...puck,
99
+ ...blocks
100
+ ].map((entry)=>entry.slug))){
101
+ const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
102
+ const reader = placementReader(req, collection, options);
103
+ let page = 1;
104
+ while(true){
105
+ req.signal?.throwIfAborted();
106
+ const result = await placementDocuments(scanReq, {
107
+ collection,
108
+ overrideAccess: false,
109
+ limit: 100,
110
+ page,
111
+ depth: 0,
112
+ draft: false,
113
+ ...req.payload.config.localization ? {
114
+ locale: 'all',
115
+ fallbackLocale: false
116
+ } : {},
117
+ ...drafts ? {
118
+ where: {
119
+ _status: {
120
+ equals: 'published'
121
+ }
122
+ }
123
+ } : {}
124
+ }, true);
125
+ req.signal?.throwIfAborted();
126
+ const placements = [];
127
+ for (const raw of result.docs){
128
+ if (raw._status === 'draft' || raw.deletedAt != null) continue;
129
+ for (const view of reader.views){
130
+ const placement = reader.read(raw, 'all-locales', view);
131
+ const doc = placement.doc;
132
+ const add = (contents, editor)=>placements.push({
133
+ id: raw.id,
134
+ editor,
135
+ slots: contents,
136
+ ...view.locale ? {
137
+ locale: view.locale
138
+ } : {}
139
+ });
140
+ if (placement.editor === 'puck') {
141
+ const registration = puck.find((entry)=>entry.slug === collection);
142
+ if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
143
+ if (!visibility.hidden && node.type === 'ExperimentSlot' && puckExperimentSlug(node.props.experiment) === slug) {
144
+ add(Object.fromEntries(slots.map((slot)=>[
145
+ slot,
146
+ Array.isArray(node.props[slot]) ? node.props[slot].length : 0
147
+ ])), 'puck');
148
+ }
149
+ });
150
+ } else {
151
+ const registration = blocks.find((entry)=>entry.slug === collection);
152
+ if (registration) for (const block of hostBlocks(doc[registration.field])){
153
+ if (block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && block.experiment === slug) {
154
+ add(Object.fromEntries(BLOCK_SLOTS.map((slot)=>[
155
+ slot,
156
+ slotBlocks(block, slot).length
157
+ ])), 'blocks');
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ yield {
164
+ collection,
165
+ placements
166
+ };
167
+ if (!result.hasNextPage) break;
168
+ page++;
169
+ }
170
+ }
171
+ }
86
172
  export async function scanBlockPlacements(req, args) {
87
173
  const { puckCollections } = args;
174
+ const scanReq = localeRequest(req, {
175
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
176
+ fallbackLocale: req.payload.config.localization ? false : req.fallbackLocale ?? false
177
+ });
178
+ const comparisons = new Map();
179
+ const comparison = (collection, id)=>{
180
+ if (!req.payload.config.localization) return comparisonContent(req, collection, id);
181
+ const key = JSON.stringify([
182
+ collection,
183
+ String(id)
184
+ ]);
185
+ let pending = comparisons.get(key);
186
+ if (!pending) {
187
+ pending = comparisonContent(req, collection, id);
188
+ comparisons.set(key, pending);
189
+ }
190
+ return pending;
191
+ };
88
192
  const slugs = args.slugs ?? new Set([
89
193
  args.slug
90
194
  ]);
@@ -100,17 +204,28 @@ export async function scanBlockPlacements(req, args) {
100
204
  collections: puckCollections
101
205
  }
102
206
  })){
207
+ const reader = placementReader(req, collection, {
208
+ puck: {
209
+ enabled: true,
210
+ collections: puckCollections
211
+ },
212
+ blocks: {
213
+ collections: args.blocksCollections
214
+ }
215
+ });
103
216
  const editors = new Map();
104
217
  const publishedIds = new Set();
105
218
  const publishedSlugs = new Map();
106
219
  const draftsEnabled = req.payload.config.collections?.some((config)=>config.slug === collection && config.versions && config.versions.drafts);
107
- for (const draft of [
220
+ for (const draft of args.publishedOnly ? [
221
+ false
222
+ ] : [
108
223
  false,
109
224
  true
110
225
  ]){
111
226
  let page = 1;
112
227
  while(true){
113
- const result = await placementDocuments(req, {
228
+ const result = await placementDocuments(scanReq, {
114
229
  collection,
115
230
  req,
116
231
  overrideAccess: false,
@@ -119,6 +234,10 @@ export async function scanBlockPlacements(req, args) {
119
234
  depth: 0,
120
235
  draft,
121
236
  includeLockStatus: true,
237
+ ...req.payload.config.localization ? {
238
+ locale: 'all',
239
+ fallbackLocale: false
240
+ } : {},
122
241
  ...!draft && draftsEnabled ? {
123
242
  where: {
124
243
  _status: {
@@ -127,32 +246,33 @@ export async function scanBlockPlacements(req, args) {
127
246
  }
128
247
  } : {}
129
248
  }, args.pageGuard);
130
- for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
249
+ for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
250
+ const doc = reader.read(localized, 'all-locales', view).doc;
251
+ const documentKey = JSON.stringify([
252
+ String(doc.id),
253
+ view.locale
254
+ ]);
131
255
  if (!draft && doc._status === 'draft') continue;
132
- if (draft && doc._status !== 'draft' && publishedIds.has(String(doc.id))) continue;
256
+ if (draft && doc._status !== 'draft' && publishedIds.has(documentKey)) continue;
133
257
  if (!draft) {
134
- editors.set(String(doc.id), documentEditor({
135
- puck: {
136
- enabled: true,
137
- collections: puckCollections
138
- },
139
- blocks: {
140
- collections: args.blocksCollections
141
- }
142
- }, collection, doc));
143
- publishedIds.add(String(doc.id));
144
- if (typeof doc.slug === 'string') publishedSlugs.set(String(doc.id), doc.slug);
258
+ editors.set(documentKey, reader.read(doc, 'localized').editor);
259
+ publishedIds.add(documentKey);
260
+ if (typeof doc.slug === 'string') publishedSlugs.set(documentKey, doc.slug);
145
261
  }
146
- const editor = editors.get(String(doc.id)) ?? documentEditor({
147
- puck: {
148
- enabled: true,
149
- collections: puckCollections
150
- },
151
- blocks: {
152
- collections: args.blocksCollections
153
- }
154
- }, collection, doc);
262
+ const editor = editors.get(documentKey) ?? reader.read(doc, 'localized').editor;
155
263
  if (editor !== 'puck') continue;
264
+ const nearest = new Map(nestedTests(doc[field]).map((pair)=>[
265
+ pair.inner,
266
+ pair
267
+ ]));
268
+ const nested = [
269
+ ...nearest.values()
270
+ ].map(({ outer, inner })=>({
271
+ outer: nestedTestLabel(outer),
272
+ inner: nestedTestLabel(inner),
273
+ outerSlug: nestedTestSlug(outer),
274
+ innerSlug: nestedTestSlug(inner)
275
+ }));
156
276
  const offsets = new Map([
157
277
  ...placements
158
278
  ].map(([slug, list])=>[
@@ -162,18 +282,26 @@ export async function scanBlockPlacements(req, args) {
162
282
  walkVisiblePuck(doc[field], (node, visibility)=>{
163
283
  if (visibility.hidden) return;
164
284
  const props = node.props;
165
- const ref = props.experiment;
166
- const experiment = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : null;
285
+ const experiment = puckExperimentSlug(props.experiment);
167
286
  if (node.type === 'ExperimentSlot' && typeof experiment === 'string' && slugs.has(experiment)) {
168
287
  placements.get(experiment).push({
169
288
  collection,
170
289
  id: doc.id,
171
290
  editor: 'puck',
172
291
  doc,
292
+ nestedTests: nested.filter((pair)=>pair.outerSlug === experiment || pair.innerSlug === experiment).map(({ outer, inner, outerSlug, innerSlug })=>({
293
+ outer,
294
+ inner,
295
+ outerSlug: outerSlug ?? '',
296
+ innerSlug: innerSlug ?? ''
297
+ })),
298
+ ...view.locale ? {
299
+ locale: view.locale
300
+ } : {},
173
301
  title: String(doc.title ?? doc.name ?? doc.id),
174
302
  published: !draft || doc._status === 'published',
175
- ...publishedSlugs.has(String(doc.id)) ? {
176
- slug: publishedSlugs.get(String(doc.id))
303
+ ...publishedSlugs.has(documentKey) ? {
304
+ slug: publishedSlugs.get(documentKey)
177
305
  } : {},
178
306
  slots: Object.fromEntries(slots.map((slot)=>[
179
307
  slot,
@@ -189,13 +317,12 @@ export async function scanBlockPlacements(req, args) {
189
317
  if (args.compareVersions && !draft && [
190
318
  ...placements
191
319
  ].some(([slug, list])=>list.length > offsets.get(slug))) {
192
- const raw = await comparisonContent(req, collection, doc.id);
320
+ const raw = reader.read(await comparison(collection, doc.id), 'all-locales', view).doc;
193
321
  const rawSlots = new Map();
194
322
  const collect = (value)=>walkVisiblePuck(value, (node, visibility)=>{
195
323
  if (visibility.hidden) return;
196
324
  const props = node.props;
197
- const ref = props?.experiment;
198
- const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
325
+ const slug = puckExperimentSlug(props?.experiment);
199
326
  if (node.type === 'ExperimentSlot' && props && typeof slug === 'string') {
200
327
  const list = rawSlots.get(slug) ?? [];
201
328
  list.push(props);
@@ -216,15 +343,26 @@ export async function scanBlockPlacements(req, args) {
216
343
  }
217
344
  for (const registration of args.blocksCollections){
218
345
  const { slug: collection, field } = registration;
346
+ const reader = placementReader(req, collection, {
347
+ puck: {
348
+ enabled: true,
349
+ collections: puckCollections
350
+ },
351
+ blocks: {
352
+ collections: args.blocksCollections
353
+ }
354
+ });
219
355
  const published = new Map();
220
356
  const draftsEnabled = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
221
- for (const draft of [
357
+ for (const draft of args.publishedOnly ? [
358
+ false
359
+ ] : [
222
360
  false,
223
361
  true
224
362
  ]){
225
363
  let page = 1;
226
364
  while(true){
227
- const result = await placementDocuments(req, {
365
+ const result = await placementDocuments(scanReq, {
228
366
  collection,
229
367
  req,
230
368
  overrideAccess: false,
@@ -233,6 +371,10 @@ export async function scanBlockPlacements(req, args) {
233
371
  page,
234
372
  draft,
235
373
  includeLockStatus: true,
374
+ ...req.payload.config.localization ? {
375
+ locale: 'all',
376
+ fallbackLocale: false
377
+ } : {},
236
378
  ...!draft && draftsEnabled ? {
237
379
  where: {
238
380
  _status: {
@@ -241,21 +383,18 @@ export async function scanBlockPlacements(req, args) {
241
383
  }
242
384
  } : {}
243
385
  }, args.pageGuard);
244
- for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
386
+ for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
387
+ const doc = reader.read(localized, 'all-locales', view).doc;
388
+ const documentKey = JSON.stringify([
389
+ String(doc.id),
390
+ view.locale
391
+ ]);
245
392
  if (!draft && doc._status === 'draft') continue;
246
- if (!draft) published.set(String(doc.id), doc);
247
- else if (doc._status !== 'draft' && published.has(String(doc.id))) continue;
248
- const baseline = published.get(String(doc.id)) ?? doc;
249
- if (documentEditor({
250
- blocks: {
251
- collections: args.blocksCollections
252
- },
253
- puck: {
254
- enabled: true,
255
- collections: puckCollections
256
- }
257
- }, collection, baseline) !== 'blocks') continue;
258
- const raw = args.compareVersions && !draft && hostBlocks(doc[field]).some((block)=>block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && typeof block.experiment === 'string' && slugs.has(block.experiment)) ? await comparisonContent(req, collection, doc.id) : undefined;
393
+ if (!draft) published.set(documentKey, doc);
394
+ else if (doc._status !== 'draft' && published.has(documentKey)) continue;
395
+ const baseline = published.get(documentKey) ?? doc;
396
+ if (reader.read(baseline, 'localized').editor !== 'blocks') continue;
397
+ const raw = args.compareVersions && !draft && hostBlocks(doc[field]).some((block)=>block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && typeof block.experiment === 'string' && slugs.has(block.experiment)) ? reader.read(await comparison(collection, doc.id), 'all-locales', view).doc : undefined;
259
398
  for (const [index, block] of hostBlocks(doc[field]).entries()){
260
399
  if (block.blockType !== (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || typeof block.experiment !== 'string' || !slugs.has(block.experiment)) continue;
261
400
  const stored = raw ? hostBlocks(raw[field]).find((row)=>row.id === block.id) ?? hostBlocks(raw[field])[index] ?? block : block;
@@ -266,6 +405,9 @@ export async function scanBlockPlacements(req, args) {
266
405
  id: doc.id,
267
406
  editor: 'blocks',
268
407
  doc,
408
+ ...view.locale ? {
409
+ locale: view.locale
410
+ } : {},
269
411
  title: String(doc.title ?? doc.name ?? doc.id),
270
412
  published: !draft || doc._status === 'published',
271
413
  ...typeof baseline.slug === 'string' ? {
@@ -289,6 +431,27 @@ export async function scanBlockPlacements(req, args) {
289
431
  }
290
432
  }
291
433
  }
434
+ for (const list of placements.values()){
435
+ const groups = new Map();
436
+ for (const placement of list)if (placement.locale) {
437
+ const key = JSON.stringify([
438
+ placement.collection,
439
+ String(placement.id),
440
+ placement.published
441
+ ]);
442
+ const group = groups.get(key) ?? [];
443
+ group.push(placement);
444
+ groups.set(key, group);
445
+ }
446
+ for (const group of groups.values()){
447
+ const languages = placementLanguages(req, group.map((placement)=>placement.locale));
448
+ for (const placement of group)Object.assign(placement, languages, {
449
+ localeLabel: placementLanguages(req, [
450
+ placement.locale
451
+ ]).locales?.[0] ?? placement.locale
452
+ });
453
+ }
454
+ }
292
455
  return args.slugs ? placements : placements.get(args.slug);
293
456
  }
294
457
  export async function flagPlacements(options, experiment, req) {
@@ -29,7 +29,8 @@ export declare function loadStartInputsBatch<TUser extends {
29
29
  }>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean): Promise<Map<string, CheckStartInput | null>>;
30
30
  export declare function preflightData<TUser extends {
31
31
  id: DocId;
32
- }>(req: PayloadRequest, { experimentId, options }: {
32
+ }>(req: PayloadRequest, { experimentId, options, placementLocale }: {
33
33
  experimentId: DocId;
34
34
  options: ResolvedOptions<TUser>;
35
+ placementLocale?: string;
35
36
  }, { now, estimate }?: PreflightDependencies): Promise<PreflightResult | null>;
@@ -1,3 +1,6 @@
1
+ import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
2
+ import { placementReader } from '../blocks/placementLocale.js';
3
+ import { placementLanguages } from '../blocks/placementLanguages.js';
1
4
  import { goalContent, OUTSIDE_GOAL } from '../goals/fairness.js';
2
5
  import { placementInteractions, placementPaths, uniquePlacementDocs } from './placementInteractions.js';
3
6
  import { Forbidden, NotFound } from 'payload';
@@ -96,6 +99,7 @@ const metricIds = (experiment)=>[
96
99
  // Lazy promises prevent unhandled rejections and share failed reads as well as successful ones.
97
100
  let pageTestsInUse;
98
101
  let blocks;
102
+ let nestedNames;
99
103
  let state;
100
104
  const busyPoints = new Map();
101
105
  const layers = new Map();
@@ -103,7 +107,11 @@ const metricIds = (experiment)=>[
103
107
  for (const experiment of experiments){
104
108
  try {
105
109
  const ownIds = new Set(metricIds(experiment).map(String));
110
+ const localization = req.payload.config.localization;
106
111
  const input = {
112
+ placementLocaleCodes: localization ? localization.localeCodes : undefined,
113
+ placementLocale: req.locale ?? undefined,
114
+ placementDefaultLocale: localization ? localization.defaultLocale : undefined,
107
115
  experiment,
108
116
  metrics: (await metrics).filter((metric)=>ownIds.has(String(metric.id))),
109
117
  metricSources: options.metricSources,
@@ -139,6 +147,12 @@ const metricIds = (experiment)=>[
139
147
  blocksCollections: options.blocks?.collections ?? []
140
148
  });
141
149
  input.placements = (await blocks).get(experiment.slug) ?? [];
150
+ if (input.placements.some((p)=>p.nestedTests?.length)) {
151
+ nestedNames ??= nestedPlacementNames(req, [
152
+ ...(await blocks).values()
153
+ ].flat());
154
+ input.placements = nameNestedPlacements(input.placements, await nestedNames);
155
+ }
142
156
  } catch (cause) {
143
157
  input.placementError = placementFailure(cause);
144
158
  }
@@ -292,7 +306,10 @@ async function placementUrls(options, placement, pendingPreviews, onFailure, pre
292
306
  const key = JSON.stringify([
293
307
  collection,
294
308
  String(id),
295
- published
309
+ published,
310
+ ...placement.locale ? [
311
+ placement.locale
312
+ ] : []
296
313
  ]);
297
314
  let preview = previews.get(key);
298
315
  if (!preview) previews.set(key, preview = previewLookup(options, placement, pendingPreviews, onFailure));
@@ -376,9 +393,11 @@ async function primaryHistory(source, now) {
376
393
  return null;
377
394
  }
378
395
  }
379
- export async function preflightData(req, { experimentId, options }, { now = new Date(), estimate = powerMetricWeeks } = {}) {
396
+ export async function preflightData(req, { experimentId, options, placementLocale }, { now = new Date(), estimate = powerMetricWeeks } = {}) {
380
397
  const input = await loadStartInputs(req, options, experimentId);
381
398
  if (!input) return null;
399
+ // Advisory title selection never changes the request used by scans or host adapters.
400
+ if (placementLocale !== undefined) input.placementLocale = placementLocale;
382
401
  const { experiment: e } = input;
383
402
  const primaryId = relationshipId(e.metrics?.primary);
384
403
  const metric = input.metrics.find((metric)=>String(metric.id) === String(primaryId));
@@ -458,7 +477,7 @@ export async function preflightData(req, { experimentId, options }, { now = new
458
477
  }
459
478
  const requiredSlots = e.arms.filter((arm)=>arm.kind !== 'holdout').map((arm)=>arm.slot);
460
479
  const blocks = input.placements ?? [];
461
- const placements = new Array(blocks.length);
480
+ let placements = new Array(blocks.length);
462
481
  let nextPlacement = 0;
463
482
  const pendingPreviews = {
464
483
  count: 0
@@ -492,6 +511,49 @@ export async function preflightData(req, { experimentId, options }, { now = new
492
511
  };
493
512
  }
494
513
  }));
514
+ if (blocks.some((placement)=>placement.locale)) {
515
+ // Summarize occurrences within one language and publication state first.
516
+ // Combine languages only when the complete displayed row agrees.
517
+ const languageRows = new Map();
518
+ blocks.forEach((placement, index)=>{
519
+ const key = JSON.stringify([
520
+ placement.collection,
521
+ String(placement.id),
522
+ placement.published,
523
+ placement.locale
524
+ ]);
525
+ const group = languageRows.get(key) ?? [];
526
+ group.push(index);
527
+ languageRows.set(key, group);
528
+ });
529
+ const groups = new Map();
530
+ for (const indices of languageRows.values()){
531
+ const rows = indices.map((index)=>placements[index]), first = rows[0];
532
+ const row = {
533
+ ...first,
534
+ slotCount: rows.length,
535
+ ok: rows.every((row)=>row.ok),
536
+ slots: Object.fromEntries(Object.keys(first.slots).map((slot)=>[
537
+ slot,
538
+ Math.min(...rows.map((row)=>row.slots[slot]))
539
+ ]))
540
+ };
541
+ const key = JSON.stringify(row);
542
+ const group = groups.get(key) ?? {
543
+ row,
544
+ codes: []
545
+ };
546
+ const locale = blocks[indices[0]].locale;
547
+ if (locale) group.codes.push(locale);
548
+ groups.set(key, group);
549
+ }
550
+ placements = [
551
+ ...groups.values()
552
+ ].map(({ row, codes })=>({
553
+ ...row,
554
+ ...placementLanguages(req, codes)
555
+ }));
556
+ }
495
557
  for (const placement of input.flagPlacements ?? [])placements.push({
496
558
  collection: e.flagPoint ?? '',
497
559
  id: placement.arm,
@@ -567,6 +629,7 @@ export async function preflightData(req, { experimentId, options }, { now = new
567
629
  });
568
630
  continue;
569
631
  }
632
+ doc = placementReader(req, collection.slug, options).read(doc, req.locale === 'all' ? 'all-locales' : 'localized').doc;
570
633
  const titleField = req.payload.config.collections?.find((entry)=>entry.slug === collection.slug)?.admin.useAsTitle ?? 'title';
571
634
  const placement = {
572
635
  collection: collection.slug,
@@ -1,3 +1,5 @@
1
+ import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
2
+ import { nestedTestCopy } from '../puck/nestedTestCopy.js';
1
3
  import { goalContent } from '../goals/fairness.js';
2
4
  import { detached } from './placementInteractions.js';
3
5
  import { lockAndRescanPlacements, placementInteractions } from './placementInteractions.js';
@@ -35,6 +37,7 @@ export async function readExperiment(req, id) {
35
37
  }
36
38
  export function refuse(code, detail) {
37
39
  const messages = {
40
+ 'nested-tests': nestedTestCopy.readiness(detail),
38
41
  'goal-in-some-versions': asymmetricGoalsCopy(detail),
39
42
  'placements-changed': "This test's pages changed while it was starting. Try again.",
40
43
  'page-busy': "One of this test's pages is being saved right now. Try again in a moment.",
@@ -137,7 +140,7 @@ export async function start(req, { experimentId, options }) {
137
140
  const failure = checkStart({
138
141
  ...input,
139
142
  experiment: current,
140
- placements: rescan.placements
143
+ placements: nameNestedPlacements(rescan.placements, await nestedPlacementNames(req, rescan.placements))
141
144
  }).find((check)=>!check.ok);
142
145
  if (failure && failure.code !== 'page-targets-unchecked' && failure.code !== 'make-content-unsupported') refuse(failure.code, failure.detail);
143
146
  }
@@ -7,7 +7,7 @@ import type { Snapshot, VerdictCode } from './snapshot.js';
7
7
  export type ArmIssueCode = 'weights-total' | 'control-count' | 'control-first' | 'holdout-last' | 'holdout-count' | 'variant-count' | 'duplicate-key' | 'duplicate-slot' | 'slot-required' | 'invalid-key';
8
8
  /** Content-report dismiss/restore refusals (CORE-44). */
9
9
  export type ContentEntryRefusal = 'not-decided' | 'entry-not-found' | 'entry-ok' | 'entry-dismissed' | 'entry-not-dismissed';
10
- export type RefusalCode = ArmIssueCode | 'goal-in-some-versions' | 'placement-unchecked' | 'placement-unpublished' | 'duplicate-version-row' | 'interacting-tests' | 'placements-changed' | 'page-busy' | 'wrap-target-missing' | 'version-identical' | 'version-same-address' | 'unknown-collection' | 'not-found' | ContentEntryRefusal | 'no-planned-duration' | 'no-primary-metric' | 'no-placements' | 'placement-removed' | 'empty-slot' | 'page-in-use' | 'page-no-targets' | 'page-target-unpublished' | 'page-user-unit' | 'version-page-unavailable' | 'version-page-unchecked' | 'flag-no-point' | 'flag-params-invalid' | 'flag-point-busy' | 'flag-placement-missing' | 'layer-full' | 'layer-unit-mismatch' | 'unknown-metric-source' | 'unit-source-mismatch' | 'no-reach-per-day' | 'invalid-status' | 'stale-draft' | 'stale-edit' | 'commit-unverified' | 'allocation-lower' | 'confirmation-required' | 'invalid-winner' | 'slices-taken' | 'locked-placement' | 'not-implemented' | 'forbidden' | 'unauthenticated' | 'body-too-large' | 'invalid-body' | 'too-many-ids' | 'invalid-phase' | 'invalid-ids' | 'recompute-failed' | 'analysis-failed' | 'undeclared-targeting-key' | 'invalid-targeting-rule' | 'block-path-rule' | 'duplicate-metric';
10
+ export type RefusalCode = ArmIssueCode | 'nested-tests' | 'goal-in-some-versions' | 'placement-unchecked' | 'placement-unpublished' | 'duplicate-version-row' | 'interacting-tests' | 'placements-changed' | 'page-busy' | 'wrap-target-missing' | 'version-identical' | 'version-same-address' | 'unknown-collection' | 'not-found' | ContentEntryRefusal | 'no-planned-duration' | 'no-primary-metric' | 'no-placements' | 'placement-removed' | 'empty-slot' | 'page-in-use' | 'page-no-targets' | 'page-target-unpublished' | 'page-user-unit' | 'version-page-unavailable' | 'version-page-unchecked' | 'flag-no-point' | 'flag-params-invalid' | 'flag-point-busy' | 'flag-placement-missing' | 'layer-full' | 'layer-unit-mismatch' | 'unknown-metric-source' | 'unit-source-mismatch' | 'no-reach-per-day' | 'invalid-status' | 'stale-draft' | 'stale-edit' | 'commit-unverified' | 'allocation-lower' | 'confirmation-required' | 'invalid-winner' | 'slices-taken' | 'locked-placement' | 'not-implemented' | 'forbidden' | 'unauthenticated' | 'body-too-large' | 'invalid-body' | 'too-many-ids' | 'invalid-phase' | 'invalid-ids' | 'recompute-failed' | 'analysis-failed' | 'undeclared-targeting-key' | 'invalid-targeting-rule' | 'block-path-rule' | 'duplicate-metric';
11
11
  export type ErrorEnvelope = {
12
12
  errors: Array<{
13
13
  code: RefusalCode;
@@ -89,6 +89,9 @@ export type PreflightResult = {
89
89
  collection: string;
90
90
  id: DocId;
91
91
  title: string;
92
+ locales?: string[];
93
+ allLocales?: true;
94
+ slotCount?: number;
92
95
  url?: string;
93
96
  editorUrl?: string;
94
97
  slots?: Record<ArmSlot, number>;
@@ -251,6 +254,7 @@ export type PlacementStatusResult = {
251
254
  slot?: string;
252
255
  }>;
253
256
  winnerArm?: string;
257
+ discarded?: boolean;
254
258
  rollout: boolean;
255
259
  }>;
256
260
  };
@@ -261,3 +265,33 @@ export type WrapBlockBody = {
261
265
  blockId: string;
262
266
  experiment: string;
263
267
  };
268
+ /** Current visitor effect of deleting a draft or archived test; independent of its stored content report. */
269
+ export type DeleteImpactResult = {
270
+ effect: 'none';
271
+ } | {
272
+ effect: 'block';
273
+ controlLabel: string;
274
+ unreadablePages: number;
275
+ pageCount: number;
276
+ placements: Array<{
277
+ collection: string;
278
+ id: DocId;
279
+ title: string;
280
+ path: string | null;
281
+ locales?: string[];
282
+ allLocales?: true;
283
+ before: {
284
+ key: string;
285
+ label: string;
286
+ };
287
+ after: {
288
+ key: string;
289
+ label: string;
290
+ };
291
+ }>;
292
+ } | {
293
+ effect: 'page';
294
+ winnerPath: string;
295
+ addresses: string[];
296
+ afterPaths?: Record<string, string>;
297
+ };
@@ -1 +1 @@
1
- export { };
1
+ /** Current visitor effect of deleting a draft or archived test; independent of its stored content report. */ export { };
@@ -7,6 +7,8 @@ export interface TestsSurfaceProps {
7
7
  returnToTest?: string;
8
8
  adminRoute: string;
9
9
  apiRoute: string;
10
+ contentLanguageLabels?: string[];
11
+ contentLocale?: string;
10
12
  collectionTitles?: Record<string, string>;
11
13
  userId?: string | number;
12
14
  userCollection?: string;