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

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 (294) hide show
  1. package/README.md +12 -12
  2. package/dist/admin/blocks/BlockPanel.js +6 -4
  3. package/dist/admin/blocks/inject.js +1 -0
  4. package/dist/admin/blocks/model.d.ts +3 -2
  5. package/dist/admin/blocks/model.js +9 -5
  6. package/dist/admin/copy/blocks.d.ts +3 -2
  7. package/dist/admin/copy/blocks.js +8 -7
  8. package/dist/admin/surface/ResultsRoute.js +18 -11
  9. package/dist/admin/surface/TestsHome.d.ts +2 -1
  10. package/dist/admin/surface/TestsHome.js +131 -44
  11. package/dist/admin/surface/TestsSurface.js +3 -0
  12. package/dist/admin/surface/home.model.d.ts +2 -0
  13. package/dist/admin/surface/newTest/PageWizard.js +9 -2
  14. package/dist/admin/surface/newTest/newTest.css +1 -1
  15. package/dist/admin/surface/results/ResultsHeader.js +11 -6
  16. package/dist/admin/surface/test/TestPage.js +3 -3
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +3 -2
  21. package/dist/blocks/formState.js +1 -1
  22. package/dist/blocks/placementLanguages.d.ts +7 -0
  23. package/dist/blocks/placementLanguages.js +27 -0
  24. package/dist/blocks/placementLocale.d.ts +21 -7
  25. package/dist/blocks/placementLocale.js +218 -67
  26. package/dist/collections/experiments/config.js +8 -3
  27. package/dist/collections/experiments/deleteGuard.js +2 -2
  28. package/dist/collections/experiments/lockHook.js +21 -2
  29. package/dist/collections/experiments/pickSlug.js +2 -0
  30. package/dist/collections/metricsGuards.js +2 -0
  31. package/dist/collections/serialize.js +5 -4
  32. package/dist/constants.d.ts +1 -0
  33. package/dist/constants.js +1 -0
  34. package/dist/db/adapter.d.ts +9 -1
  35. package/dist/db/adapter.js +77 -1
  36. package/dist/db/appends.d.ts +13 -0
  37. package/dist/db/appends.js +49 -0
  38. package/dist/db/bulkPlacementRemoval.js +8 -4
  39. package/dist/db/delete.d.ts +1 -1
  40. package/dist/db/delete.js +2 -4
  41. package/dist/db/events.d.ts +9 -0
  42. package/dist/db/events.js +42 -8
  43. package/dist/db/executor.d.ts +7 -1
  44. package/dist/db/executor.js +7 -3
  45. package/dist/db/results.d.ts +5 -1
  46. package/dist/db/results.js +21 -5
  47. package/dist/db/snapshots.d.ts +1 -0
  48. package/dist/endpoints/contentLocale.d.ts +6 -0
  49. package/dist/endpoints/contentLocale.js +15 -0
  50. package/dist/endpoints/deleteImpact.d.ts +6 -0
  51. package/dist/endpoints/deleteImpact.js +207 -0
  52. package/dist/endpoints/events.js +103 -39
  53. package/dist/endpoints/index.js +9 -8
  54. package/dist/endpoints/pages.js +7 -3
  55. package/dist/endpoints/placementStatus.js +13 -5
  56. package/dist/endpoints/preflight.d.ts +1 -1
  57. package/dist/endpoints/preflight.js +17 -2
  58. package/dist/endpoints/results.d.ts +1 -1
  59. package/dist/endpoints/results.js +6 -2
  60. package/dist/endpoints/routeId.d.ts +2 -2
  61. package/dist/endpoints/routeId.js +11 -5
  62. package/dist/endpoints/summary.js +46 -12
  63. package/dist/endpoints/transitions.js +37 -24
  64. package/dist/errors.d.ts +4 -0
  65. package/dist/errors.js +6 -0
  66. package/dist/events/request.d.ts +6 -2
  67. package/dist/events/request.js +35 -8
  68. package/dist/events/rows.d.ts +1 -1
  69. package/dist/events/rows.js +24 -8
  70. package/dist/events/writable.d.ts +9 -0
  71. package/dist/events/writable.js +13 -0
  72. package/dist/exports/adminClient.d.ts +1 -1
  73. package/dist/exports/adminClient.js +1 -1
  74. package/dist/exports/index.d.ts +1 -1
  75. package/dist/exports/rsc.d.ts +1 -0
  76. package/dist/exports/rsc.js +1 -0
  77. package/dist/goals/fairness.js +38 -31
  78. package/dist/hooks/blockRemovalRule.d.ts +2 -2
  79. package/dist/hooks/blockRemovalRule.js +16 -14
  80. package/dist/hooks/hostHook.js +6 -2
  81. package/dist/hooks/pageGuard.d.ts +3 -0
  82. package/dist/hooks/pageGuard.js +37 -23
  83. package/dist/hooks/puckNestedTests.d.ts +8 -0
  84. package/dist/hooks/puckNestedTests.js +36 -0
  85. package/dist/lib/fetchAllDocs.d.ts +1 -1
  86. package/dist/lib/placementPages.d.ts +2 -1
  87. package/dist/lib/placementPages.js +10 -2
  88. package/dist/manifest/compile.d.ts +2 -1
  89. package/dist/manifest/compile.js +13 -6
  90. package/dist/onInit.js +14 -0
  91. package/dist/options.js +5 -0
  92. package/dist/proxy/pageNavigation.d.ts +4 -0
  93. package/dist/proxy/pageNavigation.js +28 -0
  94. package/dist/proxy/resolve.js +52 -25
  95. package/dist/puck/ExperimentPicker.js +40 -37
  96. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  97. package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
  98. package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
  99. package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
  100. package/dist/puck/editor/LeftoverVersions.js +40 -43
  101. package/dist/puck/editor/QuickTestActions.d.ts +5 -2
  102. package/dist/puck/editor/QuickTestActions.js +16 -4
  103. package/dist/puck/editor/ResultsReadout.d.ts +2 -1
  104. package/dist/puck/editor/ResultsReadout.js +2 -1
  105. package/dist/puck/editor/VersionBuilder.d.ts +31 -3
  106. package/dist/puck/editor/VersionBuilder.js +336 -74
  107. package/dist/puck/editor/armWrites.js +1 -1
  108. package/dist/puck/editor/armsCache.js +1 -3
  109. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  110. package/dist/puck/editor/blockClipboard.js +20 -0
  111. package/dist/puck/editor/copy.d.ts +12 -2
  112. package/dist/puck/editor/copy.js +13 -2
  113. package/dist/puck/editor/editor.chrome.css +118 -3
  114. package/dist/puck/editor/editor.css +131 -8
  115. package/dist/puck/editor/editor.model.d.ts +3 -1
  116. package/dist/puck/editor/editor.model.js +2 -2
  117. package/dist/puck/editor/localPlacements.d.ts +1 -0
  118. package/dist/puck/editor/localPlacements.js +12 -0
  119. package/dist/puck/editor/placementsCache.d.ts +22 -12
  120. package/dist/puck/editor/placementsCache.js +62 -49
  121. package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
  122. package/dist/puck/editor/usePageSaveReadiness.js +34 -0
  123. package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
  124. package/dist/puck/editor/usePlacementNotice.js +6 -4
  125. package/dist/puck/experimentSlug.d.ts +2 -0
  126. package/dist/puck/experimentSlug.js +3 -0
  127. package/dist/puck/nestedTestCopy.d.ts +8 -0
  128. package/dist/puck/nestedTestCopy.js +22 -0
  129. package/dist/puck/nestedTests.d.ts +17 -0
  130. package/dist/puck/nestedTests.js +30 -0
  131. package/dist/puck/slotConfig.d.ts +1 -1
  132. package/dist/puck/slotConfig.js +17 -4
  133. package/dist/puck/visibility.d.ts +2 -3
  134. package/dist/puck/visibility.js +11 -7
  135. package/dist/results/aggregate.d.ts +6 -3
  136. package/dist/results/aggregate.js +9 -9
  137. package/dist/results/health.d.ts +8 -0
  138. package/dist/results/health.js +28 -0
  139. package/dist/results/identityCredit.d.ts +1 -0
  140. package/dist/results/identityCredit.js +4 -1
  141. package/dist/results/verdict.js +2 -1
  142. package/dist/runtime/cookie.d.ts +10 -2
  143. package/dist/runtime/cookie.js +38 -6
  144. package/dist/runtime/cookieOptions.d.ts +6 -0
  145. package/dist/runtime/cookieOptions.js +14 -0
  146. package/dist/runtime/proxyRuntime.d.ts +1 -0
  147. package/dist/runtime/proxyRuntime.js +18 -8
  148. package/dist/runtime/signing.d.ts +1 -0
  149. package/dist/runtime/signing.js +5 -0
  150. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  151. package/dist/sanitizeReadinessDetail.js +20 -2
  152. package/dist/server/getAssignments.js +11 -10
  153. package/dist/server/recordContentChange.d.ts +1 -1
  154. package/dist/server/recordContentChange.js +45 -21
  155. package/dist/server/resolveExperimentBlocks.js +2 -4
  156. package/dist/server/resolveExperimentData.js +4 -7
  157. package/dist/server/runResults.js +52 -14
  158. package/dist/server/startExperiment.d.ts +20 -0
  159. package/dist/server/startExperiment.js +70 -0
  160. package/dist/server/trackConversion.js +10 -13
  161. package/dist/testSurface/PreviewLinks.js +6 -2
  162. package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
  163. package/dist/testSurface/actions/DecideDialog.js +32 -14
  164. package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
  165. package/dist/testSurface/actions/MakeContentResult.js +9 -1
  166. package/dist/testSurface/api.d.ts +11 -8
  167. package/dist/testSurface/api.js +27 -11
  168. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  169. package/dist/testSurface/contentLocaleURL.js +3 -0
  170. package/dist/testSurface/copy/actions.d.ts +1 -0
  171. package/dist/testSurface/copy/actions.js +1 -0
  172. package/dist/testSurface/copy/common.d.ts +6 -0
  173. package/dist/testSurface/copy/common.js +11 -5
  174. package/dist/testSurface/copy/languages.d.ts +12 -0
  175. package/dist/testSurface/copy/languages.js +8 -0
  176. package/dist/testSurface/copy/metrics.d.ts +1 -0
  177. package/dist/testSurface/copy/metrics.js +1 -0
  178. package/dist/testSurface/copy/readiness.d.ts +13 -2
  179. package/dist/testSurface/copy/readiness.js +19 -2
  180. package/dist/testSurface/copy/results.d.ts +5 -2
  181. package/dist/testSurface/copy/results.js +5 -2
  182. package/dist/testSurface/copy/testPage.d.ts +40 -1
  183. package/dist/testSurface/copy/testPage.js +53 -1
  184. package/dist/testSurface/placementLabel.d.ts +8 -0
  185. package/dist/testSurface/placementLabel.js +24 -0
  186. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  187. package/dist/testSurface/placements/placementLabels.js +2 -1
  188. package/dist/testSurface/readPreflight.d.ts +5 -0
  189. package/dist/testSurface/readPreflight.js +7 -0
  190. package/dist/testSurface/readinessRead.d.ts +3 -0
  191. package/dist/testSurface/readinessRead.js +4 -0
  192. package/dist/testSurface/results/VerdictHero.d.ts +2 -1
  193. package/dist/testSurface/results/VerdictHero.js +5 -1
  194. package/dist/testSurface/results/results.css +1 -1
  195. package/dist/testSurface/results/results.model.d.ts +1 -1
  196. package/dist/testSurface/results/results.model.js +6 -2
  197. package/dist/testSurface/surface/contracts.d.ts +10 -1
  198. package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
  199. package/dist/testSurface/surface/editorPlacement.js +19 -1
  200. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
  201. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  202. package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
  203. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
  204. package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
  205. package/dist/testSurface/surface/readiness/Banner.js +23 -12
  206. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
  207. package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
  208. package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
  209. package/dist/testSurface/surface/readiness/readiness.model.js +116 -12
  210. package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
  211. package/dist/testSurface/surface/readiness/useTransition.js +12 -10
  212. package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
  213. package/dist/testSurface/surface/results/ReleasePages.js +5 -4
  214. package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
  215. package/dist/testSurface/surface/results/ResultsBody.js +86 -43
  216. package/dist/testSurface/surface/results/useResults.d.ts +11 -7
  217. package/dist/testSurface/surface/results/useResults.js +3 -2
  218. package/dist/testSurface/surface/setting/parts.js +58 -18
  219. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  220. package/dist/testSurface/surface/test/DeleteTest.d.ts +19 -0
  221. package/dist/testSurface/surface/test/DeleteTest.js +262 -0
  222. package/dist/testSurface/surface/test/GoalSection.js +7 -3
  223. package/dist/testSurface/surface/test/LengthSection.js +3 -0
  224. package/dist/testSurface/surface/test/PageHoldout.js +4 -1
  225. package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
  226. package/dist/testSurface/surface/test/TargetingSection.js +77 -12
  227. package/dist/testSurface/surface/test/TestSurface.js +97 -15
  228. package/dist/testSurface/surface/test/VersionsSection.js +56 -29
  229. package/dist/testSurface/surface/test/fields.d.ts +29 -4
  230. package/dist/testSurface/surface/test/fields.js +159 -39
  231. package/dist/testSurface/surface/test/pageParts.js +14 -5
  232. package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
  233. package/dist/testSurface/surface/test/testPage.model.js +6 -0
  234. package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
  235. package/dist/testSurface/surface/testDocument.model.js +4 -1
  236. package/dist/testSurface/surface/useTestDocument.d.ts +23 -4
  237. package/dist/testSurface/surface/useTestDocument.js +425 -162
  238. package/dist/testSurface/useApi.d.ts +9 -6
  239. package/dist/testSurface/useOnTestReturn.d.ts +2 -0
  240. package/dist/testSurface/useOnTestReturn.js +27 -0
  241. package/dist/testSurface/useReadinessPolling.js +3 -1
  242. package/dist/transitions/addMetric.d.ts +1 -4
  243. package/dist/transitions/allocate.d.ts +2 -2
  244. package/dist/transitions/allocate.js +3 -1
  245. package/dist/transitions/archive.d.ts +1 -1
  246. package/dist/transitions/archive.js +3 -2
  247. package/dist/transitions/checkStart.d.ts +5 -1
  248. package/dist/transitions/checkStart.js +130 -16
  249. package/dist/transitions/contentFields.js +9 -5
  250. package/dist/transitions/decide.d.ts +1 -1
  251. package/dist/transitions/decide.js +5 -3
  252. package/dist/transitions/deleteExperiment.d.ts +2 -2
  253. package/dist/transitions/deleteExperiment.js +17 -7
  254. package/dist/transitions/kernel.d.ts +2 -0
  255. package/dist/transitions/kernel.js +9 -4
  256. package/dist/transitions/makeContent.d.ts +2 -1
  257. package/dist/transitions/makeContent.js +17 -12
  258. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  259. package/dist/transitions/nestedPlacementNames.js +32 -0
  260. package/dist/transitions/pageVersions.js +3 -1
  261. package/dist/transitions/phaseRecord.d.ts +2 -0
  262. package/dist/transitions/phaseRecord.js +5 -0
  263. package/dist/transitions/placementInteractions.d.ts +3 -3
  264. package/dist/transitions/placementInteractions.js +15 -11
  265. package/dist/transitions/placements.d.ts +28 -1
  266. package/dist/transitions/placements.js +223 -60
  267. package/dist/transitions/preflightData.d.ts +5 -3
  268. package/dist/transitions/preflightData.js +126 -37
  269. package/dist/transitions/releaseHoldout.d.ts +2 -1
  270. package/dist/transitions/releaseHoldout.js +3 -1
  271. package/dist/transitions/releasePages.d.ts +2 -1
  272. package/dist/transitions/releasePages.js +3 -1
  273. package/dist/transitions/resolveCaps.d.ts +2 -4
  274. package/dist/transitions/start.d.ts +6 -8
  275. package/dist/transitions/start.js +70 -34
  276. package/dist/transitions/startReads.d.ts +7 -0
  277. package/dist/transitions/startReads.js +28 -0
  278. package/dist/transitions/stop.d.ts +2 -1
  279. package/dist/transitions/stop.js +3 -2
  280. package/dist/types/contracts.d.ts +6 -3
  281. package/dist/types/endpoints.d.ts +86 -9
  282. package/dist/types/endpoints.js +1 -1
  283. package/dist/types/runtime.d.ts +15 -9
  284. package/dist/types/snapshot.d.ts +2 -0
  285. package/dist/types/surface.d.ts +2 -0
  286. package/dist/ui/Button.js +2 -2
  287. package/dist/ui/ChipsInput.d.ts +8 -1
  288. package/dist/ui/ChipsInput.js +17 -4
  289. package/dist/ui/Inputs.d.ts +4 -3
  290. package/dist/ui/Inputs.js +9 -9
  291. package/dist/ui/SelectControl.d.ts +33 -0
  292. package/dist/ui/SelectControl.js +504 -0
  293. package/dist/ui/ui.css +13 -5
  294. package/package.json +3 -2
@@ -3,13 +3,14 @@ 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
+ import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../../testSurface/readinessRead.js';
7
7
  import { useTestDocument } from '../../../testSurface/surface/useTestDocument.js';
8
8
  import { CopyRoute } from '../../../testSurface/surface/pagePicker/CopyRoute.js';
9
9
  import { PageCombobox } from '../../../testSurface/surface/pagePicker/PageCombobox.js';
10
10
  import { testPageCollection, controlFirst } from '../../../testSurface/surface/pagePicker/pagePicker.model.js';
11
11
  import { NEW_TEST_COPY as C } from '../../copy/newTest.js';
12
12
  import { READINESS_COPY } from '../../../testSurface/copy/readiness.js';
13
+ import { METRICS_COPY } from '../../../testSurface/copy/metrics.js';
13
14
  import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
14
15
  import { SURFACE_COPY } from '../../../testSurface/copy/surface.js';
15
16
  import { pageStepCopy } from '../../../testSurface/copy/pages.js';
@@ -18,12 +19,14 @@ import { FieldErrors } from '../../../testSurface/surface/test/fields.js';
18
19
  import { SaveStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
19
20
  import { createApi } from '../../../testSurface/api.js';
20
21
  import { useTransition } from '../../../testSurface/surface/readiness/useTransition.js';
22
+ import { Banner } from '../../../ui/Feedback.js';
21
23
  /** One session stays mounted across Collection, all page steps and Review. */ export function PageWizard({ id, surface }) {
22
24
  const router = useRouter();
23
25
  const collections = surface.pageCollections ?? [];
24
26
  const [step, setStep] = useState(collections.length > 1 ? 'collection' : 'control');
25
27
  const test = useTestDocument(id, {
26
28
  apiRoute: surface.apiRoute,
29
+ contentLocale: surface.contentLocale,
27
30
  refetchPreflightOnFocus: step === 'review'
28
31
  });
29
32
  const testUrl = formatAdminURL({
@@ -144,6 +147,10 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
144
147
  }, `${check.code}/${index}`) : null;
145
148
  })
146
149
  }),
150
+ hasBrowserWritablePrimary(test.preflight, doc.metrics?.primary) ? /*#__PURE__*/ _jsx(Banner, {
151
+ tone: "warning",
152
+ children: METRICS_COPY.browserWritablePrimary
153
+ }) : null,
147
154
  ready ? /*#__PURE__*/ _jsx("p", {
148
155
  children: READINESS_COPY.ready
149
156
  }) : null,
@@ -151,7 +158,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
151
158
  type: "button",
152
159
  disabled: busy || test.preflightPending || !test.preflight || ready && (!canStartTest(test) || transition.checking),
153
160
  onClick: ()=>{
154
- if (ready) void transition.run('start', ()=>createApi(surface.apiRoute).start(id));
161
+ if (ready) void transition.run('start', ()=>createApi(surface.apiRoute).start(id, doc.phase));
155
162
  else if (next) jump(next.section, next.arm);
156
163
  },
157
164
  children: ready ? C.start : C.finishSetup
@@ -8,4 +8,4 @@
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
10
 
11
- .xp-new-test .xp-ui-select-wrap { max-width: 36rem; }
11
+ .xp-new-test .xp-ui-combobox-wrap { max-width: 36rem; }
@@ -1,6 +1,6 @@
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';
3
+ import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../../testSurface/readinessRead.js';
4
4
  import { BlockerList } from '../../../testSurface/surface/readiness/BlockerList.js';
5
5
  import { ReadinessReadStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
6
6
  import { surfaceUrls } from '../../../testSurface/surfaceUrls.js';
@@ -15,6 +15,7 @@ import { AllocateAction, ConfirmAction } from '../../../testSurface/surface/read
15
15
  import { READINESS, daysRemaining, displayDate, blockingSteps, pageReadinessContext } from '../../../testSurface/surface/readiness/readiness.model.js';
16
16
  import { READINESS_COPY as R, runningCopy, stoppedCopy, decidedCopy } from '../../../testSurface/copy/readiness.js';
17
17
  import { RESULTS_COPY as C } from '../../../testSurface/copy/results.js';
18
+ import { METRICS_COPY } from '../../../testSurface/copy/metrics.js';
18
19
  import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
19
20
  export function ResultsHeader({ test, surface, resultsVersion, children, actions, released }) {
20
21
  const doc = test.doc;
@@ -63,7 +64,7 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
63
64
  const ready = readyToStart(test);
64
65
  const startReason = test.preflightError ?? blockers[0]?.sentence ?? (!ready ? R.checking : undefined);
65
66
  const action = available.find((item)=>item.id === selected);
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;
67
+ const sentence = test.statusReadPending ? R.checking : 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;
67
68
  const testURL = formatAdminURL({
68
69
  adminRoute: surface.adminRoute,
69
70
  path: `/experiments/${encodeURIComponent(String(doc.id))}`
@@ -90,9 +91,9 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
90
91
  className: "xp-tests-kind",
91
92
  children: TEST_PAGE.kinds[doc.kind]
92
93
  }),
93
- /*#__PURE__*/ _jsx(StatusChip, {
94
+ !test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
94
95
  status: doc.status
95
- })
96
+ }) : null
96
97
  ]
97
98
  }),
98
99
  subtitle: /*#__PURE__*/ _jsxs(_Fragment, {
@@ -116,9 +117,9 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
116
117
  href: testURL,
117
118
  children: C.backToSetup
118
119
  }),
119
- available.map((item)=>/*#__PURE__*/ _jsx(Button, {
120
+ !test.statusReadPending && available.map((item)=>/*#__PURE__*/ _jsx(Button, {
120
121
  variant: item.tone === 'danger' ? 'danger' : 'secondary',
121
- disabled: item.id === 'start' && !canStartTest(test) || !!selected || test.hasUnsaved || test.saving === 'saving' || item.id === 'allocate' && doc.allocation >= 100,
122
+ disabled: item.id === 'start' && !canStartTest(test) || !!selected || item.id === 'allocate' && doc.allocation >= 100,
122
123
  title: item.id === 'start' ? startReason : item.id === 'allocate' && doc.allocation >= 100 ? R.everyone : undefined,
123
124
  onClick: ()=>setSelected(item.id),
124
125
  children: item.id === 'allocate' ? R.allocate : item.label
@@ -138,6 +139,10 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
138
139
  setup ? /*#__PURE__*/ _jsx(BlockerList, {
139
140
  steps: blockers
140
141
  }) : null,
142
+ !test.statusReadPending && setup && hasBrowserWritablePrimary(test.preflight, doc.metrics?.primary) ? /*#__PURE__*/ _jsx(Banner, {
143
+ tone: "warning",
144
+ children: METRICS_COPY.browserWritablePrimary
145
+ }) : null,
141
146
  children,
142
147
  action?.id === 'allocate' ? /*#__PURE__*/ _jsx(AllocateAction, {
143
148
  test: test,
@@ -32,12 +32,12 @@ export function TestPage({ id, surface, onTitleChange }) {
32
32
  className: "xp-tests-kind",
33
33
  children: C.kinds[doc.kind]
34
34
  }),
35
- /*#__PURE__*/ _jsx(StatusChip, {
35
+ !test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
36
36
  status: doc.status
37
- })
37
+ }) : null
38
38
  ]
39
39
  }) : undefined,
40
- actions: doc && surface.canReadResults && [
40
+ actions: doc && !test.statusReadPending && surface.canReadResults && [
41
41
  'running',
42
42
  'stopped',
43
43
  'decided'
@@ -0,0 +1,3 @@
1
+ import type { TestsSurfaceProps } from '../../types/surface.js';
2
+ /** Payload context stays at the admin entry; the mountable surface stays neutral. */
3
+ export declare function TestsSurface(props: TestsSurfaceProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useLocale } from '@payloadcms/ui';
4
+ import { TestsSurface as Surface } from '../surface/TestsSurface.js';
5
+ /** Payload context stays at the admin entry; the mountable surface stays neutral. */ export function TestsSurface(props) {
6
+ const locale = useLocale();
7
+ return /*#__PURE__*/ _jsx(Surface, {
8
+ ...props,
9
+ contentLocale: locale?.code
10
+ });
11
+ }
@@ -1,8 +1,10 @@
1
+ import { placementLanguageNames } from '../../blocks/placementLanguages.js';
2
+ import { placementReader } from '../../blocks/placementLocale.js';
1
3
  import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
2
4
  import { serializeAttributeKeys, serializeFlagPoints, serializeMetricSources } from '../../collections/serialize.js';
3
5
  import { serializePageCollections } from '../pageCollections.js';
4
6
  import { collectionLabel as resolveLabel } from '../../collections/labels.js';
5
- import { documentEditor, puckCollections } from '../../options.js';
7
+ import { puckCollections } from '../../options.js';
6
8
  import { xpOptionsFromReq } from '../../options/fromReq.js';
7
9
  import { routeAccess } from './access.model.js';
8
10
  export async function buildSurfaceProps({ req, route, id, searchParams }) {
@@ -71,8 +73,10 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
71
73
  }
72
74
  });
73
75
  // The new-test list uses the latest draft's editing intent, as the "Test a block" field condition does (§4.1).
74
- return result.docs.map((doc)=>{
75
- const editor = documentEditor(options, collection, doc);
76
+ return result.docs.map((row)=>{
77
+ const placement = placementReader(req, collection, options).read(row, req.locale === 'all' ? 'all-locales' : 'localized');
78
+ const doc = placement.doc;
79
+ const editor = placement.editor;
76
80
  if (editor !== 'puck' && editor !== 'blocks') return null;
77
81
  const id = doc.id;
78
82
  const customUrl = options.admin?.editorUrl?.({
@@ -111,6 +115,9 @@ export async function buildSurfaceProps({ req, route, id, searchParams }) {
111
115
  },
112
116
  adminRoute,
113
117
  apiRoute: req.payload.config.routes.api,
118
+ ...req.payload.config.localization ? {
119
+ contentLanguageLabels: placementLanguageNames(req, req.payload.config.localization.localeCodes)
120
+ } : {},
114
121
  canManage,
115
122
  canReadResults,
116
123
  isAdmin,
@@ -1,6 +1,7 @@
1
+ import { puckExperimentSlug } from '../puck/experimentSlug.js';
1
2
  import { walkVisiblePuck } from '../puck/visibility.js';
2
3
  import { documentEditor, puckCollections } from '../options.js';
3
- import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
4
+ import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from './model.js';
4
5
  /** Same document-kind rule as the scan; Payload blocks are top level, Puck is recursive. */ export function placementSlugs(options, collection, doc) {
5
6
  if (!doc) return [];
6
7
  const editor = documentEditor(options, collection, doc);
@@ -18,7 +19,7 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
18
19
  const found = new Set();
19
20
  if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
20
21
  if (visibility.hidden || node.type !== 'ExperimentSlot') return;
21
- const ref = node.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
22
+ const slug = puckExperimentSlug(node.props.experiment);
22
23
  if (typeof slug === 'string') found.add(slug);
23
24
  });
24
25
  return [
@@ -86,7 +86,7 @@ function copySlotBlocks(block, slot, field, config) {
86
86
  ], field, config)[0], slot);
87
87
  }
88
88
  export function syncExperimentSlots(block, arms, field, config = {}) {
89
- const wanted = arms.filter((a)=>a.kind !== 'holdout' && a.key !== 'holdout').map((a)=>a.slot ?? a.key).filter((slot)=>BLOCK_SLOTS.includes(slot));
89
+ const wanted = arms.filter((a)=>a.kind !== 'holdout' && a.key !== 'holdout').map((a)=>a.key).filter((slot)=>BLOCK_SLOTS.includes(slot));
90
90
  const slots = [
91
91
  ...new Set(wanted)
92
92
  ].map((slot)=>block.slots.find((row)=>row.slot === slot) ?? {
@@ -0,0 +1,7 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ /** One language naming rule for placement lists and visitor-impact details. */
3
+ export declare function placementLanguages(req: PayloadRequest, codes: readonly string[]): {
4
+ locales?: string[];
5
+ allLocales?: true;
6
+ };
7
+ export declare function placementLanguageNames(req: PayloadRequest, codes: readonly string[]): string[];
@@ -0,0 +1,27 @@
1
+ import { getTranslation } from '@payloadcms/translations';
2
+ /** One language naming rule for placement lists and visitor-impact details. */ export function placementLanguages(req, codes) {
3
+ const localization = req.payload.config.localization;
4
+ const unique = [
5
+ ...new Set(codes.filter(Boolean))
6
+ ];
7
+ if (localization && unique.length === localization.localeCodes.length) return {
8
+ allLocales: true
9
+ };
10
+ const locales = placementLanguageNames(req, unique);
11
+ return locales.length ? {
12
+ locales
13
+ } : {};
14
+ }
15
+ export function placementLanguageNames(req, codes) {
16
+ const localization = req.payload.config.localization;
17
+ const unique = [
18
+ ...new Set(codes.filter(Boolean))
19
+ ];
20
+ return unique.map((code)=>{
21
+ const label = localization && localization.locales.find((entry)=>entry.code === code)?.label;
22
+ return label ? getTranslation(label, req.i18n ?? {
23
+ language: 'en',
24
+ fallbackLanguage: 'en'
25
+ }) || code : code;
26
+ });
27
+ }
@@ -1,10 +1,21 @@
1
1
  import { type PayloadRequest } from 'payload';
2
- import type { DocId } from '../types/contracts.js';
3
- /** Adapter rows retain locale maps; Start's Local API scan flattens these fields
4
- * to req.locale (and req.fallbackLocale). Registrations name top-level fields.
5
- * Match Payload afterRead/promise.js:50-89: [] is present, not a fallback.
2
+ import type { DocId, ResolvedOptions } from '../types/contracts.js';
3
+ export type PlacementInput = 'all-locales' | 'localized';
4
+ export declare function placementLocaleContent(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): Record<string, unknown> | undefined;
5
+ /** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
6
+ * Local API and form documents explicitly bypass all-locale projection.
6
7
  */
7
- export declare function placementLocaleContent(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
8
+ export declare function placementReader(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): {
9
+ views: PlacementLocaleView[];
10
+ documentViews: PlacementLocaleView[];
11
+ read(doc: Record<string, unknown> | null | undefined, input: PlacementInput, view?: PlacementLocaleView): {
12
+ view: PlacementLocaleView;
13
+ readonly doc: Record<string, unknown> | undefined;
14
+ readonly editor: "page" | "puck" | "blocks";
15
+ readonly slugs: string[];
16
+ };
17
+ };
18
+ export declare function allPlacementSlugs(req: PayloadRequest, collection: string, doc: Record<string, unknown> | undefined, input: PlacementInput): string[];
8
19
  export interface PlacementLocaleView {
9
20
  locale: string;
10
21
  fallbackLocale: import('payload').TypedFallbackLocale;
@@ -13,11 +24,14 @@ export declare const placementDocumentKey: (collection: string, id: DocId, view:
13
24
  export type RemovedPlacementViews = Map<string, PlacementLocaleView[]>;
14
25
  export declare function localeRequest(req: PayloadRequest, view: PlacementLocaleView): PayloadRequest;
15
26
  /** Canonical views of registered content, without multiplying nonlocalized rows. */
16
- export declare function placementLocaleViews(req: PayloadRequest, collection: string): PlacementLocaleView[];
27
+ export declare function placementLocaleViews(req: PayloadRequest, collection: string, options?: Pick<ResolvedOptions, "puck" | "blocks">): PlacementLocaleView[];
17
28
  /** Compare every locale view: a localized edit can also change fallback
18
29
  * content in another locale. Whole-row removals replace every view with absence.
19
30
  * The incoming hook document is already flattened to the writing locale.
20
31
  */
21
- export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean): RemovedPlacementViews;
32
+ export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, input?: PlacementInput): RemovedPlacementViews;
22
33
  /** Rebuild unchanged locale maps around a flattened hook write before reading each view. */
23
34
  export declare function mergedPlacementLocales(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>): Record<string, unknown>;
35
+ /** Project host document adapters before they run. Callers own path normalization
36
+ * and use sortLockKeys for the existing experiment → page-path lock ordering. */
37
+ export declare function placementDocumentPaths(req: PayloadRequest, collection: string, docs: Array<Record<string, unknown> | undefined>, input: PlacementInput, pathOf: (doc: Record<string, unknown>) => string | null): string[];
@@ -1,48 +1,182 @@
1
1
  import { sanitizeFallbackLocale } from 'payload';
2
- import { flattenTopLevelFields } from 'payload/shared';
3
- import { puckCollections } from '../options.js';
2
+ import { fieldShouldBeLocalized, flattenTopLevelFields } from 'payload/shared';
3
+ import { documentEditor, puckCollections } from '../options.js';
4
4
  import { placementSlugs } from './bindings.js';
5
+ import { contentBlocks, hasLocalizedFields } from '../transitions/contentFields.js';
5
6
  import { isObject } from './model.js';
6
- /** Adapter rows retain locale maps; Start's Local API scan flattens these fields
7
- * to req.locale (and req.fallbackLocale). Registrations name top-level fields.
8
- * Match Payload afterRead/promise.js:50-89: [] is present, not a fallback.
9
- */ export function placementLocaleContent(req, collection, doc) {
10
- const localization = req.payload.config.localization;
11
- if (!doc || !localization || req.locale === 'all') return doc;
12
- const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
13
- if (!config) return doc;
14
- const options = req.payload.config.custom.xp;
15
- const names = new Set([
16
- ...puckCollections(options).filter((entry)=>entry.slug === collection).map((entry)=>entry.field),
17
- ...(options.blocks?.collections ?? []).filter((entry)=>entry.slug === collection).map((entry)=>entry.field)
18
- ]);
19
- const result = {
20
- ...doc
21
- };
22
- const locale = req.locale || localization.defaultLocale;
23
- const fallback = sanitizeFallbackLocale({
24
- fallbackLocale: req.fallbackLocale ?? null,
25
- locale,
26
- localization
7
+ const identity = (data)=>data;
8
+ // Sanitized schemas are immutable. Weak ownership keeps separate Payload configs
9
+ // (and test harnesses) isolated; locale transforms survive individual readers/saves.
10
+ const localeTransforms = new WeakMap();
11
+ /** Compile only schema-marked localized branches. Opaque field values are never traversed.
12
+ * Copy ancestors only when a localized descendant changes; ordinary branches retain identity.
13
+ */ function localeTransform(payloadConfig, collection, locale, fallback) {
14
+ const config = payloadConfig.collections?.find((entry)=>entry.slug === collection);
15
+ if (!payloadConfig.localization || !config) return identity;
16
+ let collections = localeTransforms.get(payloadConfig);
17
+ if (!collections) localeTransforms.set(payloadConfig, collections = new WeakMap());
18
+ let cached = collections.get(config);
19
+ if (!cached || cached.fields !== config.fields) collections.set(config, cached = {
20
+ fields: config.fields,
21
+ transforms: new Map()
27
22
  });
28
- for (const field of flattenTopLevelFields(config.fields)){
29
- if (!('name' in field) || typeof field.name !== 'string' || !names.has(field.name) || !('localized' in field) || !field.localized) continue;
30
- const values = doc[field.name];
31
- if (!isObject(values)) continue;
32
- let value = values[locale];
33
- if (value == null && fallback && fallback !== locale) {
34
- for (const code of Array.isArray(fallback) ? fallback : [
35
- fallback
36
- ]){
37
- if (values[code] != null && values[code] !== '') {
38
- value = values[code];
39
- break;
23
+ const key = JSON.stringify([
24
+ locale,
25
+ fallback
26
+ ]);
27
+ const existing = cached.transforms.get(key);
28
+ if (existing) return existing;
29
+ const blocks = payloadConfig.blocks ?? [];
30
+ const compiled = new Map();
31
+ function compile(fields, parentIsLocalized = false) {
32
+ if (parentIsLocalized) return (data)=>data;
33
+ const cached = compiled.get(fields);
34
+ if (cached) return cached;
35
+ let project;
36
+ const transform = (data, write, previous)=>project(data, write, previous);
37
+ compiled.set(fields, transform);
38
+ const steps = flattenTopLevelFields(fields).flatMap((field)=>{
39
+ if (!('name' in field) || !field.name) return [];
40
+ const name = field.name;
41
+ const localized = fieldShouldBeLocalized({
42
+ field,
43
+ parentIsLocalized
44
+ });
45
+ const parent = parentIsLocalized || localized;
46
+ const children = 'fields' in field && hasLocalizedFields(field.fields, payloadConfig) && [
47
+ 'group',
48
+ 'array',
49
+ 'tab'
50
+ ].includes(field.type) ? compile(field.fields, parent) : undefined;
51
+ const variants = field.type === 'blocks' ? new Map([
52
+ ...field.blocks ?? [],
53
+ ...field.blockReferences ?? []
54
+ ].flatMap((ref)=>{
55
+ const block = typeof ref === 'string' ? blocks.find((block)=>block.slug === ref) : ref;
56
+ return block && hasLocalizedFields(block.fields, payloadConfig) ? [
57
+ [
58
+ block.slug,
59
+ compile(block.fields, parent)
60
+ ]
61
+ ] : [];
62
+ })) : undefined;
63
+ if (!localized && !children && !variants) return [];
64
+ return [
65
+ (data, write, previous)=>{
66
+ if (!(name in data)) return data;
67
+ let value = data[name];
68
+ const prior = previous?.[name];
69
+ if (localized && write) value = {
70
+ ...isObject(prior) ? prior : {},
71
+ [locale]: value
72
+ };
73
+ else {
74
+ if (localized) {
75
+ const values = isObject(value) ? value : {};
76
+ value = values[locale];
77
+ if (fallback && fallback !== locale && (value == null || (field.type === 'text' || field.type === 'textarea') && value === '')) {
78
+ for (const code of Array.isArray(fallback) ? fallback : [
79
+ fallback
80
+ ]){
81
+ const candidate = values[code];
82
+ if (candidate != null && candidate !== '') {
83
+ value = candidate;
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ const visit = (row, old)=>{
90
+ if (!isObject(row)) return row;
91
+ const transform = children ?? (variants && typeof row.blockType === 'string' ? variants.get(row.blockType) : undefined);
92
+ return transform ? transform(row, write, isObject(old) ? old : undefined) : row;
93
+ };
94
+ if (children || variants) {
95
+ if (Array.isArray(value)) {
96
+ const rows = value.map((row, index)=>visit(row, Array.isArray(prior) ? isObject(row) && row.id != null ? prior.find((old)=>isObject(old) && old.id === row.id) : prior[index] : undefined));
97
+ if (rows.some((row, index)=>row !== value[index])) value = rows;
98
+ } else value = visit(value, prior);
99
+ }
100
+ }
101
+ return value === data[name] ? data : {
102
+ ...data,
103
+ [name]: value
104
+ };
40
105
  }
41
- }
42
- }
43
- result[field.name] = value;
106
+ ];
107
+ });
108
+ project = (data, write = false, previous)=>steps.reduce((result, step)=>step(result, write, previous), data);
109
+ return transform;
44
110
  }
45
- return result;
111
+ const transform = hasLocalizedFields(config.fields ?? [], payloadConfig) ? compile(config.fields ?? []) : identity;
112
+ cached.transforms.set(key, transform);
113
+ return transform;
114
+ }
115
+ export function placementLocaleContent(req, collection, doc, input) {
116
+ return placementReader(req, collection).read(doc, input).doc;
117
+ }
118
+ /** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
119
+ * Local API and form documents explicitly bypass all-locale projection.
120
+ */ export function placementReader(req, collection, options = req.payload.config.custom?.xp) {
121
+ const views = placementLocaleViews(req, collection, options);
122
+ const transforms = new Map();
123
+ return {
124
+ views,
125
+ documentViews: schemaLocaleViews(req, collection),
126
+ read (doc, input, view) {
127
+ const requested = view ?? {
128
+ locale: req.locale ?? '',
129
+ fallbackLocale: req.fallbackLocale ?? false
130
+ };
131
+ const selected = requested.locale === 'all' ? {
132
+ ...requested,
133
+ locale: req.payload.config.localization ? req.payload.config.localization.defaultLocale : ''
134
+ } : requested;
135
+ let content, resolved = false;
136
+ const resolve = ()=>{
137
+ if (resolved) return content;
138
+ resolved = true;
139
+ content = doc ?? undefined;
140
+ if (doc && input === 'all-locales' && req.payload.config.localization && selected.locale !== 'all') {
141
+ const locale = selected.locale || req.payload.config.localization.defaultLocale;
142
+ const key = JSON.stringify([
143
+ locale,
144
+ selected.fallbackLocale
145
+ ]);
146
+ let transform = transforms.get(key);
147
+ if (!transform) {
148
+ transform = localeTransform(req.payload.config, collection, locale, sanitizeFallbackLocale({
149
+ fallbackLocale: selected.fallbackLocale,
150
+ locale,
151
+ localization: req.payload.config.localization
152
+ }));
153
+ transforms.set(key, transform);
154
+ }
155
+ content = transform(doc);
156
+ }
157
+ return content;
158
+ };
159
+ let editor, slugs;
160
+ return {
161
+ view: selected,
162
+ get doc () {
163
+ return resolve();
164
+ },
165
+ get editor () {
166
+ return editor ??= doc ? documentEditor(options ?? {}, collection, resolve()) : 'page';
167
+ },
168
+ get slugs () {
169
+ return slugs ??= placementSlugs(options ?? {}, collection, resolve());
170
+ }
171
+ };
172
+ }
173
+ };
174
+ }
175
+ export function allPlacementSlugs(req, collection, doc, input) {
176
+ const reader = placementReader(req, collection);
177
+ return [
178
+ ...new Set(reader.views.flatMap((view)=>reader.read(doc, input, view).slugs))
179
+ ];
46
180
  }
47
181
  export const placementDocumentKey = (collection, id, view)=>JSON.stringify([
48
182
  collection,
@@ -50,21 +184,43 @@ export const placementDocumentKey = (collection, id, view)=>JSON.stringify([
50
184
  view
51
185
  ]);
52
186
  export function localeRequest(req, view) {
187
+ // Fetch Request properties are prototype getters and disappear in a spread.
188
+ // Local API setup needs headers/url; hooks also retain method and cancellation.
53
189
  return {
54
190
  ...req,
191
+ headers: req.headers,
192
+ url: req.url,
193
+ method: req.method,
194
+ signal: req.signal,
55
195
  ...view
56
196
  };
57
197
  }
58
- /** Canonical views of registered content, without multiplying nonlocalized rows. */ export function placementLocaleViews(req, collection) {
198
+ /** Audits may contain localized arm-select tags outside registered editors. */ function schemaLocaleViews(req, collection) {
199
+ const localization = req.payload.config.localization;
200
+ const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
201
+ return localization && hasLocalizedFields(config?.fields ?? [], req.payload.config) ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
202
+ locale,
203
+ fallbackLocale: sanitizeFallbackLocale({
204
+ fallbackLocale: null,
205
+ locale,
206
+ localization
207
+ })
208
+ })) : [
209
+ {
210
+ locale: '',
211
+ fallbackLocale: false
212
+ }
213
+ ];
214
+ }
215
+ /** Canonical views of registered content, without multiplying nonlocalized rows. */ export function placementLocaleViews(req, collection, options = req.payload.config.custom?.xp ?? {}) {
59
216
  const localization = req.payload.config.localization;
60
217
  const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
61
- const options = req.payload.config.custom.xp;
62
218
  const names = new Set([
63
219
  ...puckCollections(options).filter((entry)=>entry.slug === collection).map((entry)=>entry.field),
64
220
  ...(options.blocks?.collections ?? []).filter((entry)=>entry.slug === collection).map((entry)=>entry.field)
65
221
  ]);
66
- const localized = config && flattenTopLevelFields(config.fields).some((field)=>'name' in field && names.has(field.name) && 'localized' in field && field.localized);
67
- return localization && localized ? localization.localeCodes.map((locale)=>({
222
+ const localized = config && hasLocalizedFields(config.fields ?? [], req.payload.config) && (Boolean(options.blocks?.collections.some((entry)=>entry.slug === collection && entry.appliesTo)) || flattenTopLevelFields(config.fields ?? []).some((field)=>'name' in field && names.has(field.name) && ('localized' in field && field.localized || 'fields' in field && hasLocalizedFields(field.fields, req.payload.config) || field.type === 'blocks' && hasLocalizedFields(contentBlocks(field, req.payload.config.blocks).flatMap((block)=>block.fields), req.payload.config))));
223
+ return localization && localized ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
68
224
  locale,
69
225
  fallbackLocale: sanitizeFallbackLocale({
70
226
  fallbackLocale: null,
@@ -81,15 +237,14 @@ export function localeRequest(req, view) {
81
237
  /** Compare every locale view: a localized edit can also change fallback
82
238
  * content in another locale. Whole-row removals replace every view with absence.
83
239
  * The incoming hook document is already flattened to the writing locale.
84
- */ export function removedPlacementViews(req, collection, before, after, removingPage) {
240
+ */ export function removedPlacementViews(req, collection, before, after, removingPage, input = 'localized') {
85
241
  const result = new Map();
86
242
  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));
243
+ const reader = placementReader(req, collection);
244
+ const rawAfter = input === 'all-locales' ? after : mergedPlacementLocales(req, collection, before, after);
245
+ for (const view of reader.views){
246
+ const previous = reader.read(before, 'all-locales', view).slugs;
247
+ const next = removingPage ? [] : reader.read(rawAfter, 'all-locales', view).slugs;
93
248
  for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
94
249
  ...result.get(slug) ?? [],
95
250
  view
@@ -99,21 +254,17 @@ export function localeRequest(req, view) {
99
254
  }
100
255
  /** Rebuild unchanged locale maps around a flattened hook write before reading each view. */ export function mergedPlacementLocales(req, collection, before, after) {
101
256
  const localization = req.payload.config.localization;
102
- const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
103
- const fields = config ? flattenTopLevelFields(config.fields) : [];
104
- const localized = fields.filter((field)=>'name' in field && 'localized' in field && field.localized);
105
- // Keep the raw locale maps for unchanged languages when merging a partial,
106
- // flattened main-row write back into the adapter baseline.
107
- const rawAfter = {
108
- ...after
109
- };
110
- if (localization && req.locale !== 'all') for (const field of localized){
111
- if (!('name' in field) || typeof field.name !== 'string' || !(field.name in after)) continue;
112
- const previousValue = before?.[field.name];
113
- rawAfter[field.name] = {
114
- ...isObject(previousValue) ? previousValue : {},
115
- [req.locale || localization.defaultLocale]: after[field.name]
116
- };
117
- }
118
- return rawAfter;
257
+ if (!localization || req.locale === 'all') return after;
258
+ return localeTransform(req.payload.config, collection, req.locale || localization.defaultLocale, false)(after, true, before);
259
+ }
260
+ /** Project host document adapters before they run. Callers own path normalization
261
+ * and use sortLockKeys for the existing experiment → page-path lock ordering. */ export function placementDocumentPaths(req, collection, docs, input, pathOf) {
262
+ const reader = placementReader(req, collection);
263
+ return docs.flatMap((raw)=>reader.documentViews.flatMap((view)=>{
264
+ const doc = reader.read(raw, input, view).doc;
265
+ const path = doc ? pathOf(doc) : null;
266
+ return path === null ? [] : [
267
+ path
268
+ ];
269
+ }));
119
270
  }