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

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 (305) hide show
  1. package/README.md +283 -775
  2. package/dist/admin/LayerUsage.js +1 -1
  3. package/dist/admin/MetricSourceSelect.js +2 -2
  4. package/dist/admin/PlacementStatus.js +1 -1
  5. package/dist/admin/TestsDashboardCards.js +2 -2
  6. package/dist/admin/TestsNavLink.js +2 -2
  7. package/dist/admin/blocks/BlockPanel.js +3 -3
  8. package/dist/admin/blocks/TestBlockField.js +3 -3
  9. package/dist/admin/blocks/formApi.js +1 -1
  10. package/dist/admin/blocks/model.js +1 -1
  11. package/dist/admin/blocks/statusCache.js +1 -1
  12. package/dist/admin/components/RootViewMessage.js +1 -1
  13. package/dist/admin/copy/blocks.d.ts +2 -2
  14. package/dist/admin/copy/blocks.js +3 -2
  15. package/dist/admin/copy/goals.d.ts +6 -1
  16. package/dist/admin/copy/goals.js +10 -3
  17. package/dist/admin/goals/XpGoalField.js +155 -129
  18. package/dist/admin/goals/xpGoalField.css +2 -3
  19. package/dist/admin/status.model.js +1 -1
  20. package/dist/admin/surface/ResultsRoute.d.ts +2 -1
  21. package/dist/admin/surface/ResultsRoute.js +4 -3
  22. package/dist/admin/surface/SurfaceShell.js +2 -2
  23. package/dist/admin/surface/TestsHome.d.ts +1 -1
  24. package/dist/admin/surface/TestsHome.js +3 -3
  25. package/dist/admin/surface/TestsSurface.js +2 -2
  26. package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
  27. package/dist/admin/surface/goals/GoalForm.js +69 -15
  28. package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
  29. package/dist/admin/surface/goals/GoalsList.js +4 -4
  30. package/dist/admin/surface/goals/data.js +2 -2
  31. package/dist/admin/surface/goals/goals.css +7 -0
  32. package/dist/admin/surface/goals/goals.model.d.ts +11 -1
  33. package/dist/admin/surface/goals/goals.model.js +43 -0
  34. package/dist/admin/surface/home.model.d.ts +1 -1
  35. package/dist/admin/surface/home.model.js +5 -5
  36. package/dist/admin/surface/newTest/NewTest.d.ts +1 -1
  37. package/dist/admin/surface/newTest/NewTest.js +1 -1
  38. package/dist/admin/surface/newTest/PageWizard.d.ts +1 -1
  39. package/dist/admin/surface/newTest/PageWizard.js +13 -13
  40. package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
  41. package/dist/admin/surface/results/ResultsHeader.js +8 -8
  42. package/dist/admin/surface/test/TestPage.d.ts +1 -2
  43. package/dist/admin/surface/test/TestPage.js +45 -156
  44. package/dist/admin/views/ExperimentsRootView.js +1 -1
  45. package/dist/admin/views/TestsNavLinkServer.js +1 -1
  46. package/dist/admin/views/renderCollectionList.js +1 -1
  47. package/dist/admin/views/renderTestsSurface.js +1 -1
  48. package/dist/blocks/placementLocale.d.ts +21 -0
  49. package/dist/blocks/placementLocale.js +115 -0
  50. package/dist/collections/experiments/config.js +1 -1
  51. package/dist/collections/metrics.js +1 -1
  52. package/dist/db/bulkPlacementRemoval.d.ts +30 -0
  53. package/dist/db/bulkPlacementRemoval.js +107 -0
  54. package/dist/db/placements.d.ts +2 -0
  55. package/dist/db/placements.js +8 -0
  56. package/dist/endpoints/editorSurface.d.ts +3 -0
  57. package/dist/endpoints/editorSurface.js +31 -0
  58. package/dist/endpoints/index.js +28 -1
  59. package/dist/errors.d.ts +1 -0
  60. package/dist/errors.js +2 -0
  61. package/dist/fields/xpGoal.js +1 -1
  62. package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
  63. package/dist/goals/picker/clickGoalPicker.model.js +20 -2
  64. package/dist/goals/picker/copy.d.ts +6 -2
  65. package/dist/goals/picker/copy.js +11 -2
  66. package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
  67. package/dist/goals/picker/useClickGoalPicker.js +4 -2
  68. package/dist/goals/validate.js +3 -2
  69. package/dist/hooks/blockRemovalRule.d.ts +29 -0
  70. package/dist/hooks/blockRemovalRule.js +141 -0
  71. package/dist/hooks/pageGuard.d.ts +24 -2
  72. package/dist/hooks/pageGuard.js +178 -24
  73. package/dist/hooks/puckGoals.d.ts +2 -0
  74. package/dist/hooks/puckGoals.js +34 -10
  75. package/dist/lib/placementPages.d.ts +9 -0
  76. package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +1 -4
  77. package/dist/onInit.js +22 -0
  78. package/dist/plugin.js +2 -1
  79. package/dist/puck/ExperimentPicker.js +25 -10
  80. package/dist/puck/copy.d.ts +4 -1
  81. package/dist/puck/copy.js +4 -1
  82. package/dist/puck/editor/ConfigureTestDrawer.d.ts +21 -0
  83. package/dist/puck/editor/ConfigureTestDrawer.js +147 -0
  84. package/dist/puck/editor/CreateExperimentDrawer.d.ts +11 -2
  85. package/dist/puck/editor/CreateExperimentDrawer.js +69 -9
  86. package/dist/puck/editor/EditorControls.d.ts +14 -0
  87. package/dist/puck/editor/EditorControls.js +99 -0
  88. package/dist/puck/editor/ExperimentSlotEditor.js +317 -51
  89. package/dist/puck/editor/ResultsReadout.js +3 -5
  90. package/dist/puck/editor/VersionBuilder.js +2 -2
  91. package/dist/puck/editor/armsCache.d.ts +3 -1
  92. package/dist/puck/editor/armsCache.js +20 -3
  93. package/dist/puck/editor/copy.d.ts +18 -2
  94. package/dist/puck/editor/copy.js +19 -3
  95. package/dist/puck/editor/editor.chrome.css +33 -0
  96. package/dist/puck/editor/editor.css +39 -0
  97. package/dist/puck/editor/editor.model.d.ts +14 -0
  98. package/dist/puck/editor/editor.model.js +58 -1
  99. package/dist/puck/editor/editorSurface.d.ts +10 -0
  100. package/dist/puck/editor/editorSurface.js +65 -0
  101. package/dist/puck/editor/localPlacements.d.ts +2 -0
  102. package/dist/puck/editor/localPlacements.js +29 -0
  103. package/dist/puck/editor/placementsCache.d.ts +19 -0
  104. package/dist/puck/editor/placementsCache.js +83 -0
  105. package/dist/puck/editor/xpGoalPuckEditorField.js +109 -98
  106. package/dist/puck/experimentSlotField.d.ts +3 -0
  107. package/dist/puck/experimentSlotField.js +15 -4
  108. package/dist/{admin → testSurface}/actions/DecideDialog.d.ts +2 -1
  109. package/dist/{admin → testSurface}/actions/DecideDialog.js +6 -4
  110. package/dist/{admin → testSurface}/api.js +4 -5
  111. package/dist/{admin → testSurface}/copy/common.d.ts +2 -0
  112. package/dist/{admin → testSurface}/copy/common.js +2 -0
  113. package/dist/{admin → testSurface}/copy/readiness.d.ts +3 -0
  114. package/dist/{admin → testSurface}/copy/readiness.js +3 -0
  115. package/dist/{admin → testSurface}/copy/testPage.d.ts +3 -0
  116. package/dist/{admin → testSurface}/copy/testPage.js +7 -2
  117. package/dist/testSurface/format/adminURL.d.ts +7 -0
  118. package/dist/testSurface/format/adminURL.js +9 -0
  119. package/dist/{admin → testSurface}/placements/placementLabels.js +1 -1
  120. package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
  121. package/dist/testSurface/previewLinks.model.js +4 -0
  122. package/dist/testSurface/results/results.css +64 -0
  123. package/dist/{admin → testSurface}/surface/contracts.d.ts +1 -0
  124. package/dist/{admin → testSurface}/surface/pageBlock/parts.js +6 -6
  125. package/dist/testSurface/surface/pagePicker/pagePicker.css +10 -0
  126. package/dist/{admin → testSurface}/surface/readiness/useTransition.js +1 -0
  127. package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +2 -2
  128. package/dist/{admin → testSurface}/surface/results/ResultsBody.js +18 -11
  129. package/dist/testSurface/surface/setting/setting.css +17 -0
  130. package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
  131. package/dist/{admin → testSurface}/surface/test/GoalSection.js +3 -2
  132. package/dist/{admin → testSurface}/surface/test/Section.js +9 -8
  133. package/dist/testSurface/surface/test/TestSurface.d.ts +18 -0
  134. package/dist/testSurface/surface/test/TestSurface.js +152 -0
  135. package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
  136. package/dist/{admin → testSurface}/surface/test/VersionsSection.js +12 -6
  137. package/dist/testSurface/surface/test/testPage.css +92 -0
  138. package/dist/{admin → testSurface}/surface/useTestDocument.d.ts +5 -1
  139. package/dist/{admin → testSurface}/surface/useTestDocument.js +34 -3
  140. package/dist/{admin → testSurface}/surfaceUrls.js +1 -1
  141. package/dist/transitions/placementInteractions.js +1 -1
  142. package/dist/transitions/placements.d.ts +27 -8
  143. package/dist/transitions/placements.js +77 -6
  144. package/dist/transitions/start.js +2 -2
  145. package/dist/types/endpoints.d.ts +1 -1
  146. package/dist/ui/Dialog.d.ts +4 -1
  147. package/dist/ui/Dialog.js +41 -3
  148. package/dist/ui/Drawer.d.ts +10 -0
  149. package/dist/ui/Drawer.js +29 -0
  150. package/dist/ui/Tabs.d.ts +3 -3
  151. package/dist/ui/Tabs.js +35 -33
  152. package/dist/ui/ui.css +6 -0
  153. package/package.json +1 -1
  154. package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
  155. package/dist/admin/actions/ConfirmDialog.js +0 -149
  156. package/dist/admin/results/results.css +0 -64
  157. package/dist/admin/styles.css +0 -10
  158. package/dist/admin/styles.d.ts +0 -2
  159. package/dist/admin/styles.js +0 -3
  160. package/dist/admin/surface/pagePicker/pagePicker.css +0 -10
  161. package/dist/admin/surface/setting/setting.css +0 -17
  162. package/dist/admin/surface/test/GoalSection.d.ts +0 -2
  163. package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
  164. package/dist/admin/surface/test/testPage.css +0 -92
  165. /package/dist/{admin → testSurface}/PreviewLinks.d.ts +0 -0
  166. /package/dist/{admin → testSurface}/PreviewLinks.js +0 -0
  167. /package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +0 -0
  168. /package/dist/{admin → testSurface}/actions/MakeContentResult.js +0 -0
  169. /package/dist/{admin → testSurface}/actions/actions.model.d.ts +0 -0
  170. /package/dist/{admin → testSurface}/actions/actions.model.js +0 -0
  171. /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
  172. /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
  173. /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
  174. /package/dist/{admin → testSurface}/allocation.model.js +0 -0
  175. /package/dist/{admin → testSurface}/api.d.ts +0 -0
  176. /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
  177. /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
  178. /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
  179. /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
  180. /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
  181. /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
  182. /package/dist/{admin → testSurface}/copy/actions.d.ts +0 -0
  183. /package/dist/{admin → testSurface}/copy/actions.js +0 -0
  184. /package/dist/{admin → testSurface}/copy/advanced.d.ts +0 -0
  185. /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
  186. /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
  187. /package/dist/{admin → testSurface}/copy/arms.js +0 -0
  188. /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
  189. /package/dist/{admin → testSurface}/copy/audience.js +0 -0
  190. /package/dist/{admin → testSurface}/copy/metrics.d.ts +0 -0
  191. /package/dist/{admin → testSurface}/copy/metrics.js +0 -0
  192. /package/dist/{admin → testSurface}/copy/pages.d.ts +0 -0
  193. /package/dist/{admin → testSurface}/copy/pages.js +0 -0
  194. /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
  195. /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
  196. /package/dist/{admin → testSurface}/copy/results.d.ts +0 -0
  197. /package/dist/{admin → testSurface}/copy/results.js +0 -0
  198. /package/dist/{admin → testSurface}/copy/review.d.ts +0 -0
  199. /package/dist/{admin → testSurface}/copy/review.js +0 -0
  200. /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
  201. /package/dist/{admin → testSurface}/copy/setting.js +0 -0
  202. /package/dist/{admin → testSurface}/copy/surface.d.ts +0 -0
  203. /package/dist/{admin → testSurface}/copy/surface.js +0 -0
  204. /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
  205. /package/dist/{admin → testSurface}/format/date.js +0 -0
  206. /package/dist/{admin → testSurface}/labels.d.ts +0 -0
  207. /package/dist/{admin → testSurface}/labels.js +0 -0
  208. /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
  209. /package/dist/{admin → testSurface}/lockedNotice.model.js +0 -0
  210. /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
  211. /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
  212. /package/dist/{admin → testSurface}/placements/placementLabels.d.ts +0 -0
  213. /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
  214. /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
  215. /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
  216. /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
  217. /package/dist/{admin → testSurface}/reload.d.ts +0 -0
  218. /package/dist/{admin → testSurface}/reload.js +0 -0
  219. /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
  220. /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
  221. /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
  222. /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
  223. /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
  224. /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
  225. /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
  226. /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
  227. /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
  228. /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
  229. /package/dist/{admin → testSurface}/results/VerdictHero.d.ts +0 -0
  230. /package/dist/{admin → testSurface}/results/VerdictHero.js +0 -0
  231. /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
  232. /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
  233. /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
  234. /package/dist/{admin → testSurface}/results/format.js +0 -0
  235. /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
  236. /package/dist/{admin → testSurface}/results/legacy.js +0 -0
  237. /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
  238. /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
  239. /package/dist/{admin → testSurface}/results/results.model.d.ts +0 -0
  240. /package/dist/{admin → testSurface}/results/results.model.js +0 -0
  241. /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
  242. /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
  243. /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
  244. /package/dist/{admin → testSurface}/review/review.model.js +0 -0
  245. /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
  246. /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
  247. /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.js +0 -0
  248. /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
  249. /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.d.ts +0 -0
  250. /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.js +0 -0
  251. /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.d.ts +0 -0
  252. /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.js +0 -0
  253. /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +0 -0
  254. /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +0 -0
  255. /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +0 -0
  256. /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.js +0 -0
  257. /package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +0 -0
  258. /package/dist/{admin → testSurface}/surface/readiness/Banner.js +0 -0
  259. /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.d.ts +0 -0
  260. /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.js +0 -0
  261. /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
  262. /package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -0
  263. /package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +0 -0
  264. /package/dist/{admin → testSurface}/surface/readiness/readiness.model.js +0 -0
  265. /package/dist/{admin → testSurface}/surface/readiness/useTransition.d.ts +0 -0
  266. /package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +0 -0
  267. /package/dist/{admin → testSurface}/surface/results/ReleasePages.js +0 -0
  268. /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
  269. /package/dist/{admin → testSurface}/surface/results/recommendation.model.js +0 -0
  270. /package/dist/{admin → testSurface}/surface/results/useResults.d.ts +0 -0
  271. /package/dist/{admin → testSurface}/surface/results/useResults.js +0 -0
  272. /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
  273. /package/dist/{admin → testSurface}/surface/setting/parts.js +0 -0
  274. /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
  275. /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
  276. /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
  277. /package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +0 -0
  278. /package/dist/{admin → testSurface}/surface/test/LengthSection.d.ts +0 -0
  279. /package/dist/{admin → testSurface}/surface/test/LengthSection.js +0 -0
  280. /package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +0 -0
  281. /package/dist/{admin → testSurface}/surface/test/PageHoldout.js +0 -0
  282. /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
  283. /package/dist/{admin → testSurface}/surface/test/Rail.js +0 -0
  284. /package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +0 -0
  285. /package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +0 -0
  286. /package/dist/{admin → testSurface}/surface/test/Section.d.ts +0 -0
  287. /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
  288. /package/dist/{admin → testSurface}/surface/test/TargetingSection.js +0 -0
  289. /package/dist/{admin → testSurface}/surface/test/fields.d.ts +0 -0
  290. /package/dist/{admin → testSurface}/surface/test/fields.js +0 -0
  291. /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
  292. /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
  293. /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
  294. /package/dist/{admin → testSurface}/surface/test/pageParts.js +0 -0
  295. /package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +0 -0
  296. /package/dist/{admin → testSurface}/surface/test/testPage.model.js +0 -0
  297. /package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +0 -0
  298. /package/dist/{admin → testSurface}/surface/testDocument.model.js +0 -0
  299. /package/dist/{admin → testSurface}/surfaceUrls.d.ts +0 -0
  300. /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
  301. /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
  302. /package/dist/{admin → testSurface}/theme.d.ts +0 -0
  303. /package/dist/{admin → testSurface}/theme.js +0 -0
  304. /package/dist/{admin → testSurface}/useApi.d.ts +0 -0
  305. /package/dist/{admin → testSurface}/useApi.js +0 -0
@@ -1,6 +1,7 @@
1
1
  import type { PayloadRequest } from 'payload';
2
2
  import type { Arm, DocId, FlagPoint, PreviewPlacement, ResolvedOptions } from '../types/contracts.js';
3
3
  import type { ArmSlot } from '../types/puck.js';
4
+ import { type PlacementLocaleView } from '../blocks/placementLocale.js';
4
5
  export interface BlockPlacement extends PreviewPlacement {
5
6
  editor?: 'puck' | 'blocks' | 'page';
6
7
  doc?: Record<string, unknown>;
@@ -11,20 +12,37 @@ export interface BlockPlacement extends PreviewPlacement {
11
12
  localized?: boolean;
12
13
  }
13
14
  export type FlagPlacement = Awaited<ReturnType<NonNullable<FlagPoint['placements']>>>[number];
14
- /** Each matching ExperimentSlot is checked separately, including multiple slots
15
- * in one document: content elsewhere in the document cannot hide an empty slot.
15
+ /** Internal page-guard overlay: simulate the pending write using the same scan as Start.
16
+ * Draft-only writes retain the published view. Publish/unpublish replace both views.
16
17
  */
17
- export declare function scanBlockPlacements(req: PayloadRequest, args: {
18
- slug: string;
18
+ export interface PlacementChange {
19
+ collection: string;
20
+ id: DocId;
21
+ draftOnly?: boolean;
22
+ doc?: Record<string, unknown>;
23
+ }
24
+ interface ScanOptions {
19
25
  puckCollections: NonNullable<ResolvedOptions['puck']>['collections'];
20
26
  blocksCollections: NonNullable<ResolvedOptions['blocks']>['collections'];
21
27
  compareVersions?: boolean;
28
+ /** Hook reads must see every placement and must never invoke nested access checks (CORE-21). */
29
+ pageGuard?: true;
30
+ change?: PlacementChange;
31
+ }
32
+ /** Published rows only, one pass per collection across both editor registrations.
33
+ * The exclusion predicate reads live transaction claims after each awaited page.
34
+ */
35
+ export declare function hasOtherPublishedBlockPlacement(req: PayloadRequest, options: ResolvedOptions, slug: string, excluded: (collection: string, id: DocId, view: PlacementLocaleView, doc: Record<string, unknown> & {
36
+ id: DocId;
37
+ }) => boolean): Promise<boolean>;
38
+ /** Each matching ExperimentSlot is checked separately, including multiple slots
39
+ * in one document: content elsewhere in the document cannot hide an empty slot.
40
+ */
41
+ export declare function scanBlockPlacements(req: PayloadRequest, args: ScanOptions & {
42
+ slug: string;
22
43
  }): Promise<BlockPlacement[]>;
23
- export declare function scanBlockPlacements(req: PayloadRequest, args: {
44
+ export declare function scanBlockPlacements(req: PayloadRequest, args: ScanOptions & {
24
45
  slugs: ReadonlySet<string>;
25
- puckCollections: NonNullable<ResolvedOptions['puck']>['collections'];
26
- blocksCollections: NonNullable<ResolvedOptions['blocks']>['collections'];
27
- compareVersions?: boolean;
28
46
  }): Promise<Map<string, BlockPlacement[]>>;
29
47
  export declare function flagPlacements<TUser extends {
30
48
  id: DocId;
@@ -33,3 +51,4 @@ export declare function flagPlacements<TUser extends {
33
51
  flagPoint?: string | null;
34
52
  arms: Arm[];
35
53
  }, req: PayloadRequest): Promise<FlagPlacement[]>;
54
+ export {};
@@ -4,6 +4,8 @@ import { pageVersionContent } from '../db/pageContent.js';
4
4
  import { comparableContent } from './pageVersions.js';
5
5
  import { isDeepStrictEqual } from 'node:util';
6
6
  import { hasLocalizedFields } from './contentFields.js';
7
+ import { localeRequest, placementLocaleContent, placementLocaleViews } from '../blocks/placementLocale.js';
8
+ import { placementSlugs } from '../blocks/bindings.js';
7
9
  import { documentEditor, puckCollections as normalisePuckCollections } from '../options.js';
8
10
  const slots = [
9
11
  'control',
@@ -11,6 +13,75 @@ const slots = [
11
13
  'variantB',
12
14
  'variantC'
13
15
  ];
16
+ async function placementDocuments(req, query, guard) {
17
+ // §7.8 page guard: the hook must see test placements regardless of the editor's access.
18
+ if (guard) return req.payload.find({
19
+ ...query,
20
+ req,
21
+ overrideAccess: true
22
+ });
23
+ return req.payload.find({
24
+ ...query,
25
+ req,
26
+ overrideAccess: false
27
+ });
28
+ }
29
+ function changedDocuments(docs, change, collection, draft, page, draftsEnabled) {
30
+ if (!change || change.collection !== collection || change.draftOnly && !draft) return docs;
31
+ const kept = docs.filter((doc)=>String(doc.id) !== String(change.id));
32
+ const doc = change.doc;
33
+ if (page === 1 && doc && (draft ? change.draftOnly || doc._status === 'draft' : !draftsEnabled || doc._status === 'published')) {
34
+ kept.push({
35
+ ...doc,
36
+ id: change.id,
37
+ ...change.draftOnly ? {
38
+ _status: 'draft'
39
+ } : {}
40
+ });
41
+ }
42
+ return kept;
43
+ }
44
+ /** Published rows only, one pass per collection across both editor registrations.
45
+ * The exclusion predicate reads live transaction claims after each awaited page.
46
+ */ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded) {
47
+ const scanReq = req.payload.config.localization ? {
48
+ ...req,
49
+ locale: 'all'
50
+ } : req;
51
+ const collections = new Set([
52
+ ...normalisePuckCollections(options).map((entry)=>entry.slug),
53
+ ...(options.blocks?.collections ?? []).map((entry)=>entry.slug)
54
+ ]);
55
+ for (const collection of collections){
56
+ const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
57
+ let page = 1;
58
+ while(true){
59
+ const result = await placementDocuments(scanReq, {
60
+ collection,
61
+ overrideAccess: false,
62
+ limit: 100,
63
+ page,
64
+ depth: 0,
65
+ draft: false,
66
+ ...req.payload.config.localization ? {
67
+ locale: 'all',
68
+ fallbackLocale: false
69
+ } : {},
70
+ ...drafts ? {
71
+ where: {
72
+ _status: {
73
+ equals: 'published'
74
+ }
75
+ }
76
+ } : {}
77
+ }, true);
78
+ 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;
79
+ if (!result.hasNextPage) break;
80
+ page++;
81
+ }
82
+ }
83
+ return false;
84
+ }
14
85
  export async function scanBlockPlacements(req, args) {
15
86
  const { puckCollections } = args;
16
87
  const slugs = args.slugs ?? new Set([
@@ -38,7 +109,7 @@ export async function scanBlockPlacements(req, args) {
38
109
  ]){
39
110
  let page = 1;
40
111
  while(true){
41
- const result = await req.payload.find({
112
+ const result = await placementDocuments(req, {
42
113
  collection,
43
114
  req,
44
115
  overrideAccess: false,
@@ -54,8 +125,8 @@ export async function scanBlockPlacements(req, args) {
54
125
  }
55
126
  }
56
127
  } : {}
57
- });
58
- for (const doc of result.docs){
128
+ }, args.pageGuard);
129
+ for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
59
130
  if (!draft && doc._status === 'draft') continue;
60
131
  if (draft && doc._status !== 'draft' && publishedIds.has(String(doc.id))) continue;
61
132
  if (!draft) {
@@ -164,7 +235,7 @@ export async function scanBlockPlacements(req, args) {
164
235
  ]){
165
236
  let page = 1;
166
237
  while(true){
167
- const result = await req.payload.find({
238
+ const result = await placementDocuments(req, {
168
239
  collection,
169
240
  req,
170
241
  overrideAccess: false,
@@ -180,8 +251,8 @@ export async function scanBlockPlacements(req, args) {
180
251
  }
181
252
  }
182
253
  } : {}
183
- });
184
- for (const doc of result.docs){
254
+ }, args.pageGuard);
255
+ for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
185
256
  if (!draft && doc._status === 'draft') continue;
186
257
  if (!draft) published.set(String(doc.id), doc);
187
258
  else if (doc._status !== 'draft' && published.has(String(doc.id))) continue;
@@ -5,8 +5,8 @@ import { lockPagePaths } from '../db/locks.js';
5
5
  import { lockMetricsForFreeze } from '../db/metricUsage.js';
6
6
  import { DEFAULT_SEQUENTIAL_TUNING_PARAMETER } from '../constants.js';
7
7
  import { claimSlices } from '../db/slices.js';
8
- import { READINESS_COPY, asymmetricGoalsCopy, sameAddressCopy, interactingTestsCopy, pageInUseCopy, unpublishedPageCopy } from '../admin/copy/readiness.js';
9
- import { GROUP_LABELS } from '../admin/copy/arms.js';
8
+ import { READINESS_COPY, asymmetricGoalsCopy, sameAddressCopy, interactingTestsCopy, pageInUseCopy, unpublishedPageCopy } from '../testSurface/copy/readiness.js';
9
+ import { GROUP_LABELS } from '../testSurface/copy/arms.js';
10
10
  import { XpRefusal } from '../errors.js';
11
11
  import { isOpValid } from '../targeting/ops.js';
12
12
  import { newSeed } from '../runtime/seed.js';
@@ -183,7 +183,7 @@ export type EventBody = {
183
183
  attributes?: Record<string, string | number | boolean>;
184
184
  }>;
185
185
  };
186
- export type AccessKind = 'manage' | 'readResults' | 'manifestKey' | 'signedCookie';
186
+ export type AccessKind = 'manage' | 'readResults' | 'surface' | 'manifestKey' | 'signedCookie';
187
187
  export type EndpointContext<TUser extends {
188
188
  id: string | number;
189
189
  } = {
@@ -3,8 +3,11 @@ import './ui.css';
3
3
  /** Native modal stays in its rendering document, including a Puck canvas iframe.
4
4
  * `initialFocus="cancel"` targets the focusable control marked `data-dialog-cancel`.
5
5
  */
6
- export declare function Dialog({ open, title, onClose, children, dismissible, initialFocus }: {
6
+ export declare function Dialog({ open, title, onClose, children, dismissible, initialFocus, className, headerActions, closeOnBackdrop }: {
7
7
  open: boolean;
8
+ className?: string;
9
+ headerActions?: ReactNode;
10
+ closeOnBackdrop?: boolean;
8
11
  dismissible?: boolean;
9
12
  initialFocus?: 'cancel';
10
13
  title: string;
package/dist/ui/Dialog.js CHANGED
@@ -16,9 +16,16 @@ function focusable(node) {
16
16
  }
17
17
  /** Native modal stays in its rendering document, including a Puck canvas iframe.
18
18
  * `initialFocus="cancel"` targets the focusable control marked `data-dialog-cancel`.
19
- */ export function Dialog({ open, title, onClose, children, dismissible = true, initialFocus }) {
19
+ */ export function Dialog({ open, title, onClose, children, dismissible = true, initialFocus, className = '', headerActions, closeOnBackdrop = false }) {
20
20
  const ref = useRef(null);
21
21
  const heading = useId();
22
+ const backdropPress = useRef(false);
23
+ const onBackdrop = (event)=>{
24
+ const node = ref.current;
25
+ if (!node || event.target !== node) return false;
26
+ const rect = node.getBoundingClientRect();
27
+ return event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom;
28
+ };
22
29
  const closeRequested = useRef(false);
23
30
  const requestClose = ()=>{
24
31
  if (!open || !dismissible || closeRequested.current) return;
@@ -31,11 +38,27 @@ function focusable(node) {
31
38
  const doc = node.ownerDocument;
32
39
  const previous = doc.activeElement;
33
40
  closeRequested.current = false;
41
+ // Observe before overlay portals stop pointerdown during ancestor capture.
42
+ const down = (event)=>{
43
+ backdropPress.current = onBackdrop(event);
44
+ };
45
+ const up = (event)=>{
46
+ if (!onBackdrop(event)) backdropPress.current = false;
47
+ };
48
+ const cancel = ()=>{
49
+ backdropPress.current = false;
50
+ };
51
+ doc.addEventListener('pointerdown', down, true);
52
+ doc.addEventListener('pointerup', up, true);
53
+ doc.addEventListener('pointercancel', cancel, true);
34
54
  node.showModal();
35
55
  const elements = focusable(node);
36
56
  const preferred = initialFocus === 'cancel' ? elements.find((element)=>element.hasAttribute('data-dialog-cancel')) : undefined;
37
57
  (preferred ?? elements[0] ?? node).focus();
38
58
  return ()=>{
59
+ doc.removeEventListener('pointerdown', down, true);
60
+ doc.removeEventListener('pointerup', up, true);
61
+ doc.removeEventListener('pointercancel', cancel, true);
39
62
  node.close();
40
63
  if (previous?.isConnected) previous.focus();
41
64
  };
@@ -46,12 +69,18 @@ function focusable(node) {
46
69
  return /*#__PURE__*/ _jsxs("dialog", {
47
70
  ref: ref,
48
71
  "aria-labelledby": heading,
49
- className: "xp-ui-dialog",
72
+ className: `xp-ui-dialog ${className}`,
50
73
  tabIndex: -1,
51
74
  onCancel: (event)=>{
75
+ if (event.target !== event.currentTarget) return;
52
76
  event.preventDefault();
53
77
  requestClose();
54
78
  },
79
+ onClick: (event)=>{
80
+ const startedOnBackdrop = backdropPress.current;
81
+ backdropPress.current = false;
82
+ if (closeOnBackdrop && startedOnBackdrop && onBackdrop(event)) requestClose();
83
+ },
55
84
  onKeyDown: (event)=>{
56
85
  if (event.defaultPrevented) return;
57
86
  if (event.key === 'Escape') {
@@ -75,7 +104,16 @@ function focusable(node) {
75
104
  }
76
105
  },
77
106
  children: [
78
- /*#__PURE__*/ _jsx("h2", {
107
+ headerActions ? /*#__PURE__*/ _jsxs("header", {
108
+ className: "xp-ui-dialog-header",
109
+ children: [
110
+ /*#__PURE__*/ _jsx("h2", {
111
+ id: heading,
112
+ children: title
113
+ }),
114
+ headerActions
115
+ ]
116
+ }) : /*#__PURE__*/ _jsx("h2", {
79
117
  id: heading,
80
118
  children: title
81
119
  }),
@@ -0,0 +1,10 @@
1
+ import type { ReactNode } from 'react';
2
+ import './ui.css';
3
+ /** Native modal drawer: focus trap/restoration and Escape come from Dialog. */
4
+ export declare function Drawer({ title, closeLabel, onClose, children, actions }: {
5
+ title: string;
6
+ closeLabel: string;
7
+ onClose: () => void;
8
+ children: ReactNode;
9
+ actions?: ReactNode;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Button } from './Button.js';
4
+ import { Dialog } from './Dialog.js';
5
+ import './ui.css';
6
+ /** Native modal drawer: focus trap/restoration and Escape come from Dialog. */ export function Drawer({ title, closeLabel, onClose, children, actions }) {
7
+ return /*#__PURE__*/ _jsx(Dialog, {
8
+ open: true,
9
+ title: title,
10
+ onClose: onClose,
11
+ closeOnBackdrop: true,
12
+ className: "xp-ui-drawer",
13
+ headerActions: /*#__PURE__*/ _jsxs("div", {
14
+ className: "xp-ui-button-group",
15
+ children: [
16
+ actions,
17
+ /*#__PURE__*/ _jsx(Button, {
18
+ variant: "quiet",
19
+ onClick: onClose,
20
+ children: closeLabel
21
+ })
22
+ ]
23
+ }),
24
+ children: /*#__PURE__*/ _jsx("div", {
25
+ className: "xp-ui-drawer-body",
26
+ children: children
27
+ })
28
+ });
29
+ }
package/dist/ui/Tabs.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ReactNode, Ref } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
  import './ui.css';
3
3
  export interface Tab {
4
4
  id: string;
@@ -7,10 +7,10 @@ export interface Tab {
7
7
  actions?: ReactNode;
8
8
  disabled?: boolean;
9
9
  }
10
- export declare function Tabs({ items, label, value, onChange, tabListRef }: {
10
+ export declare function Tabs({ items, label, value, onChange, renderHeader }: {
11
11
  items: Tab[];
12
12
  label: string;
13
13
  value?: string;
14
14
  onChange?: (id: string) => void;
15
- tabListRef?: Ref<HTMLDivElement>;
15
+ renderHeader?: (children: ReactNode) => ReactNode;
16
16
  }): import("react").JSX.Element;
package/dist/ui/Tabs.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useId, useState } from 'react';
4
4
  import './ui.css';
5
- export function Tabs({ items, label, value, onChange, tabListRef }) {
5
+ export function Tabs({ items, label, value, onChange, renderHeader }) {
6
6
  const prefix = useId();
7
7
  const [local, setLocal] = useState(()=>items.find((item)=>!item.disabled)?.id);
8
8
  const requested = value ?? local;
@@ -11,41 +11,43 @@ export function Tabs({ items, label, value, onChange, tabListRef }) {
11
11
  setLocal(id);
12
12
  onChange?.(id);
13
13
  }
14
+ const header = /*#__PURE__*/ _jsxs(_Fragment, {
15
+ children: [
16
+ /*#__PURE__*/ _jsx("div", {
17
+ role: "tablist",
18
+ "aria-label": label,
19
+ className: "xp-ui-tablist",
20
+ children: items.map((item)=>/*#__PURE__*/ _jsx("button", {
21
+ type: "button",
22
+ role: "tab",
23
+ id: `${prefix}-tab-${item.id}`,
24
+ "aria-controls": `${prefix}-panel-${item.id}`,
25
+ "aria-selected": selected === item.id,
26
+ tabIndex: selected === item.id ? 0 : -1,
27
+ disabled: item.disabled,
28
+ className: "xp-ui-tab",
29
+ onClick: ()=>select(item.id),
30
+ onKeyDown: (event)=>{
31
+ const enabled = items.filter((tab)=>!tab.disabled);
32
+ const index = enabled.findIndex((tab)=>tab.id === item.id);
33
+ const next = event.key === 'ArrowRight' ? enabled[(index + 1) % enabled.length] : event.key === 'ArrowLeft' ? enabled[(index - 1 + enabled.length) % enabled.length] : event.key === 'Home' ? enabled[0] : event.key === 'End' ? enabled.at(-1) : undefined;
34
+ if (!next) return;
35
+ event.preventDefault();
36
+ select(next.id);
37
+ event.currentTarget.ownerDocument.getElementById(`${prefix}-tab-${next.id}`)?.focus();
38
+ },
39
+ children: item.label
40
+ }, item.id))
41
+ }),
42
+ items.find((item)=>item.id === selected)?.actions
43
+ ]
44
+ });
14
45
  return /*#__PURE__*/ _jsxs("div", {
15
46
  className: "xp-ui-tabs",
16
47
  children: [
17
- /*#__PURE__*/ _jsxs("div", {
18
- ref: tabListRef,
48
+ renderHeader ? renderHeader(header) : /*#__PURE__*/ _jsx("div", {
19
49
  className: "xp-ui-tabs-header",
20
- children: [
21
- /*#__PURE__*/ _jsx("div", {
22
- role: "tablist",
23
- "aria-label": label,
24
- className: "xp-ui-tablist",
25
- children: items.map((item)=>/*#__PURE__*/ _jsx("button", {
26
- type: "button",
27
- role: "tab",
28
- id: `${prefix}-tab-${item.id}`,
29
- "aria-controls": `${prefix}-panel-${item.id}`,
30
- "aria-selected": selected === item.id,
31
- tabIndex: selected === item.id ? 0 : -1,
32
- disabled: item.disabled,
33
- className: "xp-ui-tab",
34
- onClick: ()=>select(item.id),
35
- onKeyDown: (event)=>{
36
- const enabled = items.filter((tab)=>!tab.disabled);
37
- const index = enabled.findIndex((tab)=>tab.id === item.id);
38
- const next = event.key === 'ArrowRight' ? enabled[(index + 1) % enabled.length] : event.key === 'ArrowLeft' ? enabled[(index - 1 + enabled.length) % enabled.length] : event.key === 'Home' ? enabled[0] : event.key === 'End' ? enabled.at(-1) : undefined;
39
- if (!next) return;
40
- event.preventDefault();
41
- select(next.id);
42
- event.currentTarget.ownerDocument.getElementById(`${prefix}-tab-${next.id}`)?.focus();
43
- },
44
- children: item.label
45
- }, item.id))
46
- }),
47
- items.find((item)=>item.id === selected)?.actions
48
- ]
50
+ children: header
49
51
  }),
50
52
  items.map((item)=>/*#__PURE__*/ _jsx("div", {
51
53
  role: "tabpanel",
package/dist/ui/ui.css CHANGED
@@ -94,3 +94,9 @@
94
94
 
95
95
  .xp-ui-field-label { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-3); }
96
96
  .xp-ui-field-label > label { font-weight: 500; }
97
+
98
+ .xp-ui-dialog.xp-ui-drawer { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(720px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border-block: 0; border-inline-end: 0; padding: 0; overflow: hidden; }
99
+ .xp-ui-drawer[open] { display: flex; flex-direction: column; }
100
+ .xp-ui-drawer > .xp-ui-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-4); padding: var(--xp-space-4) var(--xp-space-5); border-bottom: 1px solid var(--xp-border); flex-shrink: 0; background: var(--xp-surface); }
101
+ .xp-ui-drawer > .xp-ui-dialog-header h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font: var(--xp-text-title); }
102
+ .xp-ui-drawer-body { min-height: 0; overflow: auto; overscroll-behavior: contain; flex: 1; background: var(--xp-bg); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-experiments",
3
- "version": "0.4.0-rc.2",
3
+ "version": "0.4.0-rc.4",
4
4
  "description": "No-code A/B testing for Payload CMS and Next.js: block, page and flag experiments with holdouts, layers, exposure logging and honest statistics inside the admin — no vendor",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,19 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { DocId } from '../../types/contracts.js';
3
- import type { ExperimentAction } from './actions.model.js';
4
- export declare function DialogFrame({ title, onClose, children, initialFocus, dismissible }: {
5
- dismissible?: boolean;
6
- initialFocus?: 'cancel';
7
- title: string;
8
- onClose: () => void;
9
- children: ReactNode;
10
- }): import("react").JSX.Element;
11
- export declare function ConfirmDialog({ id, action, winnerLabel, onClose, canManage, isDecided, apiRoute }: {
12
- apiRoute: string;
13
- canManage?: boolean;
14
- isDecided?: boolean;
15
- id: DocId;
16
- action: ExperimentAction;
17
- winnerLabel: string;
18
- onClose: () => void;
19
- }): import("react").JSX.Element;
@@ -1,149 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useRef, useState } from 'react';
4
- import { Button } from '../../ui/Button.js';
5
- import { TextInput } from '../../ui/Inputs.js';
6
- import { Dialog } from '../../ui/Dialog.js';
7
- import { expectedConfirm, matchesConfirm } from '../../transitions/confirmPhrases.js';
8
- import { useApi } from '../useApi.js';
9
- import { reloadPage } from '../reload.js';
10
- import { ACTIONS_COPY as C } from '../copy/actions.js';
11
- import { API_MESSAGES } from '../copy/common.js';
12
- import { MakeContentResult } from './MakeContentResult.js';
13
- export function DialogFrame({ title, onClose, children, initialFocus, dismissible = true }) {
14
- return /*#__PURE__*/ _jsx(Dialog, {
15
- open: true,
16
- dismissible: dismissible,
17
- initialFocus: initialFocus,
18
- title: title,
19
- onClose: onClose,
20
- children: children
21
- });
22
- }
23
- export function ConfirmDialog({ id, action, winnerLabel, onClose, canManage = false, isDecided = false, apiRoute }) {
24
- const api = useApi(apiRoute);
25
- const [typed, setTyped] = useState('');
26
- const [busy, setBusy] = useState(false);
27
- const [reportBusy, setReportBusy] = useState(false);
28
- const inFlight = useRef(false);
29
- const [error, setError] = useState(null);
30
- const [content, setContent] = useState(null);
31
- const phrase = action.confirm.phrase ? expectedConfirm(action.confirm.phrase.action, winnerLabel) : null;
32
- const enabled = !busy && (!phrase || matchesConfirm(phrase, typed));
33
- async function submit(finish = false) {
34
- if (inFlight.current || !enabled) return;
35
- inFlight.current = true;
36
- setBusy(true);
37
- setError(null);
38
- let result;
39
- if (finish) result = await api.archive(id, {
40
- mode: 'after-content'
41
- });
42
- else if (action.archive) result = await api.archive(id, {
43
- ...action.archive,
44
- ...phrase ? {
45
- confirmation: typed.trim()
46
- } : {}
47
- });
48
- else if (action.id === 'start') result = await api.start(id);
49
- else if (action.id === 'stop') result = await api.stop(id);
50
- else if (action.id === 'release-holdout') result = await api.releaseHoldout(id);
51
- else {
52
- const response = await api.makeContent(id);
53
- if (response.ok && response.data) {
54
- setContent(response.data);
55
- inFlight.current = false;
56
- setBusy(false);
57
- return;
58
- }
59
- result = response;
60
- }
61
- if (result.ok && (finish || action.id !== 'make-content')) {
62
- reloadPage();
63
- return;
64
- }
65
- inFlight.current = false;
66
- setBusy(false);
67
- setError(!result.ok ? result : {
68
- ok: false,
69
- status: 0,
70
- message: API_MESSAGES.unreadable,
71
- retryable: true
72
- });
73
- }
74
- function close() {
75
- if (busy || reportBusy) return;
76
- if (content) reloadPage();
77
- onClose();
78
- }
79
- return /*#__PURE__*/ _jsxs(DialogFrame, {
80
- dismissible: !busy && !reportBusy,
81
- initialFocus: action.id === 'start' ? undefined : 'cancel',
82
- title: action.confirm.title,
83
- onClose: close,
84
- children: [
85
- content ? /*#__PURE__*/ _jsx(MakeContentResult, {
86
- result: content,
87
- id: id,
88
- api: api,
89
- canManage: canManage,
90
- isDecided: content.doc?.status ? content.doc.status === 'decided' : isDecided,
91
- onRetry: ()=>submit(),
92
- onFinish: ()=>submit(true),
93
- busy: busy,
94
- onBusyChange: setReportBusy,
95
- onActionStart: ()=>setError(null)
96
- }) : /*#__PURE__*/ _jsxs(_Fragment, {
97
- children: [
98
- /*#__PURE__*/ _jsx("p", {
99
- children: action.confirm.body
100
- }),
101
- phrase ? /*#__PURE__*/ _jsxs(_Fragment, {
102
- children: [
103
- /*#__PURE__*/ _jsxs("p", {
104
- children: [
105
- C.typePhrase,
106
- " ",
107
- /*#__PURE__*/ _jsx("strong", {
108
- children: phrase
109
- })
110
- ]
111
- }),
112
- /*#__PURE__*/ _jsx(TextInput, {
113
- id: "xp-confirmation",
114
- label: C.confirmation,
115
- value: typed,
116
- readOnly: busy,
117
- onChange: (event)=>setTyped(event.target.value)
118
- })
119
- ]
120
- }) : null
121
- ]
122
- }),
123
- error ? /*#__PURE__*/ _jsx("p", {
124
- role: "alert",
125
- children: error.message
126
- }) : null,
127
- content ? null : /*#__PURE__*/ _jsx(Button, {
128
- disabled: !enabled,
129
- onClick: ()=>{
130
- void submit();
131
- },
132
- children: action.label
133
- }),
134
- error?.retryable && !content ? /*#__PURE__*/ _jsx(Button, {
135
- disabled: !enabled,
136
- onClick: ()=>{
137
- void submit();
138
- },
139
- children: C.retry
140
- }) : null,
141
- /*#__PURE__*/ _jsx(Button, {
142
- "data-dialog-cancel": true,
143
- disabled: busy || reportBusy,
144
- onClick: close,
145
- children: content ? C.done : C.cancel
146
- })
147
- ]
148
- });
149
- }