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

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 (87) hide show
  1. package/dist/admin/surface/ResultsRoute.js +2 -10
  2. package/dist/admin/surface/newTest/PageWizard.js +10 -12
  3. package/dist/admin/surface/results/ResultsHeader.js +15 -8
  4. package/dist/goals/fairness.d.ts +1 -1
  5. package/dist/goals/fairness.js +1 -1
  6. package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
  7. package/dist/puck/editor/CreateExperimentDrawer.js +4 -0
  8. package/dist/puck/editor/EditorControls.d.ts +1 -1
  9. package/dist/puck/editor/EditorControls.js +1 -1
  10. package/dist/puck/editor/ExperimentSlotEditor.js +425 -80
  11. package/dist/puck/editor/LeftoverVersions.d.ts +13 -0
  12. package/dist/puck/editor/LeftoverVersions.js +115 -0
  13. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  14. package/dist/puck/editor/PlacementNotice.js +22 -0
  15. package/dist/puck/editor/QuickTestActions.d.ts +3 -0
  16. package/dist/puck/editor/QuickTestActions.js +50 -0
  17. package/dist/puck/editor/ResultsReadout.js +5 -0
  18. package/dist/puck/editor/VersionBuilder.d.ts +20 -6
  19. package/dist/puck/editor/VersionBuilder.js +78 -48
  20. package/dist/puck/editor/armWrites.d.ts +3 -1
  21. package/dist/puck/editor/armWrites.js +2 -1
  22. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  23. package/dist/puck/editor/cloneSlot.js +7 -0
  24. package/dist/puck/editor/copy.d.ts +24 -3
  25. package/dist/puck/editor/copy.js +24 -3
  26. package/dist/puck/editor/editor.chrome.css +11 -0
  27. package/dist/puck/editor/editor.css +29 -0
  28. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  29. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  30. package/dist/puck/editor/outlineVersion.js +36 -0
  31. package/dist/puck/editor/placementsCache.d.ts +33 -2
  32. package/dist/puck/editor/placementsCache.js +208 -33
  33. package/dist/puck/editor/sidebar.d.ts +12 -0
  34. package/dist/puck/editor/sidebar.js +77 -0
  35. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  36. package/dist/puck/editor/usePlacementNotice.js +14 -0
  37. package/dist/testSurface/api.js +1 -1
  38. package/dist/testSurface/copy/common.d.ts +1 -1
  39. package/dist/testSurface/copy/common.js +3 -1
  40. package/dist/testSurface/copy/readiness.d.ts +17 -1
  41. package/dist/testSurface/copy/readiness.js +22 -1
  42. package/dist/testSurface/copy/testPage.d.ts +1 -0
  43. package/dist/testSurface/copy/testPage.js +1 -0
  44. package/dist/testSurface/readPreflight.d.ts +9 -0
  45. package/dist/testSurface/readPreflight.js +38 -0
  46. package/dist/testSurface/readinessRead.d.ts +50 -0
  47. package/dist/testSurface/readinessRead.js +46 -0
  48. package/dist/testSurface/surface/contracts.d.ts +6 -2
  49. package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
  50. package/dist/testSurface/surface/editorPlacement.js +60 -0
  51. package/dist/testSurface/surface/pageBlock/parts.js +13 -3
  52. package/dist/testSurface/surface/readiness/ActionDialogs.js +37 -7
  53. package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
  54. package/dist/testSurface/surface/readiness/Banner.js +106 -68
  55. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  56. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  57. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
  58. package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
  59. package/dist/testSurface/surface/readiness/parts.js +0 -2
  60. package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
  61. package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
  62. package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
  63. package/dist/testSurface/surface/readiness/useTransition.js +69 -7
  64. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  65. package/dist/testSurface/surface/test/GoalSection.js +1 -0
  66. package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
  67. package/dist/testSurface/surface/test/LengthSection.js +2 -1
  68. package/dist/testSurface/surface/test/Rail.js +7 -4
  69. package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
  70. package/dist/testSurface/surface/test/Section.d.ts +3 -1
  71. package/dist/testSurface/surface/test/Section.js +38 -6
  72. package/dist/testSurface/surface/test/TargetingSection.js +5 -0
  73. package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
  74. package/dist/testSurface/surface/test/TestSurface.js +68 -7
  75. package/dist/testSurface/surface/test/VersionsSection.js +1 -0
  76. package/dist/testSurface/surface/test/testPage.css +12 -0
  77. package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
  78. package/dist/testSurface/surface/useTestDocument.js +61 -46
  79. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  80. package/dist/testSurface/useReadinessPolling.js +24 -0
  81. package/dist/transitions/preflightData.js +1 -1
  82. package/dist/ui/Card.d.ts +2 -1
  83. package/dist/ui/Card.js +4 -4
  84. package/dist/ui/Tabs.d.ts +2 -1
  85. package/dist/ui/Tabs.js +19 -6
  86. package/dist/ui/ui.css +18 -0
  87. package/package.json +1 -1
@@ -0,0 +1,77 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createUsePuck, useGetPuck } from '@puckeditor/core';
4
+ import { useEffect, useState, useSyncExternalStore, useRef } from 'react';
5
+ const usePuckSelector = createUsePuck();
6
+ // useGetPuck returns the store's stable getState function (Puck 0.24:7223–7228).
7
+ // A WeakMap keeps separate editors (including their iframes) isolated.
8
+ const bridges = new WeakMap();
9
+ function bridge(session) {
10
+ let entry = bridges.get(session);
11
+ if (!entry) {
12
+ const targets = new Map();
13
+ const listeners = new Set();
14
+ entry = {
15
+ targets,
16
+ listeners,
17
+ removeListener: (notify)=>{
18
+ listeners.delete(notify);
19
+ },
20
+ removeTarget: (id)=>{
21
+ targets.delete(id);
22
+ }
23
+ };
24
+ bridges.set(session, entry);
25
+ }
26
+ return entry;
27
+ }
28
+ export function useSidebarTargets(id) {
29
+ const entry = bridge(useGetPuck());
30
+ return useSyncExternalStore((notify)=>{
31
+ entry.listeners.add(notify);
32
+ return ()=>{
33
+ entry.removeListener(notify);
34
+ };
35
+ }, ()=>entry.targets.get(id), ()=>undefined);
36
+ }
37
+ /** The custom field owns only its portal destinations and binding callback, never another data reader. */ export function TestSidebarField({ onChange }) {
38
+ const getPuck = useGetPuck();
39
+ const change = useRef(onChange);
40
+ change.current = onChange;
41
+ const id = usePuckSelector((state)=>state.selectedItem?.props.id);
42
+ const [test, setTest] = useState(null);
43
+ const [controls, setControls] = useState(null);
44
+ useEffect(()=>{
45
+ if (!id || !test || !controls) return;
46
+ const entry = bridge(getPuck);
47
+ const targets = {
48
+ test,
49
+ controls,
50
+ onChange: (value)=>change.current(value)
51
+ };
52
+ entry.targets.set(id, targets);
53
+ for (const notify of entry.listeners)notify();
54
+ return ()=>{
55
+ if (entry.targets.get(id) === targets) entry.removeTarget(id);
56
+ for (const notify of entry.listeners)notify();
57
+ };
58
+ }, [
59
+ id,
60
+ test,
61
+ controls,
62
+ getPuck
63
+ ]);
64
+ return /*#__PURE__*/ _jsxs("div", {
65
+ className: "xp-slot-root xp-slot-editor xp-puck-field xp-slot-sidebar",
66
+ onClick: (event)=>event.stopPropagation(),
67
+ onKeyDown: (event)=>event.stopPropagation(),
68
+ children: [
69
+ /*#__PURE__*/ _jsx("div", {
70
+ ref: setTest
71
+ }),
72
+ /*#__PURE__*/ _jsx("div", {
73
+ ref: setControls
74
+ })
75
+ ]
76
+ });
77
+ }
@@ -0,0 +1,3 @@
1
+ import type { DocId } from '../../types/contracts.js';
2
+ /** Subscribe only while save/publish guidance or a retryable placement failure is visible. */
3
+ export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined): void;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import { useEffect } from 'react';
3
+ import { watchPlacementNotice } from './placementsCache.js';
4
+ /** Subscribe only while save/publish guidance or a retryable placement failure is visible. */ export function usePlacementNotice(api, id, message) {
5
+ const showing = message !== undefined && id !== undefined;
6
+ useEffect(()=>{
7
+ if (id === undefined || !showing) return;
8
+ return watchPlacementNotice(api, id, document);
9
+ }, [
10
+ api,
11
+ id,
12
+ showing
13
+ ]);
14
+ }
@@ -51,7 +51,7 @@ export function createApi(apiBase) {
51
51
  ...code ? {
52
52
  code
53
53
  } : {},
54
- message: refusalMessage(code, response.status, typeof error?.message === 'string' ? error.message : undefined, options),
54
+ message: refusalMessage(code, response.status, typeof error?.message === 'string' ? error.message : undefined, options, error?.detail),
55
55
  retryable: code === 'page-busy' || code === 'commit-unverified' || response.status >= 500 && response.status !== 501
56
56
  };
57
57
  } catch {
@@ -27,4 +27,4 @@ export declare function refusalMessage(code: string | undefined, status: number,
27
27
  forbidden?: string;
28
28
  codes?: Readonly<Record<string, string>>;
29
29
  fallback?: string;
30
- }): string;
30
+ }, detail?: unknown): string;
@@ -1,3 +1,4 @@
1
+ import { unpublishedPlacementsCopy } from './readiness.js';
1
2
  export const API_MESSAGES = {
2
3
  testAlreadyDeleted: 'This test was already deleted. Reload the page.',
3
4
  testNoLongerDraft: 'This test is no longer a draft. Reload the page.',
@@ -22,7 +23,7 @@ export const LOCKED_MESSAGES = {
22
23
  archived: "Archived tests can't be changed.",
23
24
  other: "Can't be changed in this state."
24
25
  };
25
- export function refusalMessage(code, status, message, options) {
26
+ export function refusalMessage(code, status, message, options, detail) {
26
27
  // A per-call code wins over the status branches: entry-not-found is a 404 that is not "this test no longer exists".
27
28
  const mapped = code && options?.codes && Object.hasOwn(options.codes, code) ? options.codes[code] : undefined;
28
29
  if (mapped !== undefined) return mapped;
@@ -31,5 +32,6 @@ export function refusalMessage(code, status, message, options) {
31
32
  if (code === 'commit-unverified') return API_MESSAGES.commitUnverified;
32
33
  if (code === 'not-implemented' || status === 501) return API_MESSAGES.notImplemented;
33
34
  if (code === 'forbidden' || status === 403) return options?.forbidden ?? API_MESSAGES.forbidden;
35
+ if (code === 'placement-unpublished') return unpublishedPlacementsCopy(detail);
34
36
  return options?.fallback ?? (message || API_MESSAGES.failed);
35
37
  }
@@ -3,16 +3,28 @@ export declare const PLACEMENT_FAILURE_COPY: {
3
3
  readonly forbidden: "You don't have permission to check where this test is used.";
4
4
  readonly 'not-found': "A page used by this test no longer exists. Choose another page.";
5
5
  };
6
+ export declare const SAVE_PAGE = "Save this page to put the test on it.";
7
+ export declare const PUBLISH_PAGE = "Publish this page to start the test.";
8
+ export declare const RUNNING_PUBLISH_PAGE = "This test is running, but visitors won't see it here until this page is published.";
9
+ export declare const RUNNING_SAVE_PAGE = "This test is running, but visitors won't see it here until this page is saved and published.";
6
10
  export declare const READINESS_COPY: {
11
+ readonly beforeStart: "Before you can start:";
7
12
  readonly label: "Readiness";
8
13
  readonly addGoal: "Add a goal";
9
14
  readonly needsAttention: "Needs attention";
15
+ readonly needsAttentionPrefix: "Needs attention: ";
10
16
  readonly missingVersions: "This test is missing its saved versions. Open the test and check its setup before changing this page.";
17
+ readonly saveGeneralError: "Couldn't save. Reload to check the saved test.";
18
+ readonly changing: "Saving this change…";
19
+ readonly reloadAfterError: "Couldn't save the test. Reload to check its saved settings before starting.";
20
+ readonly chooseGoalToAdd: "Choose a goal to add it to this test.";
21
+ readonly reloadFirst: "Reload to see the latest test settings before starting.";
11
22
  readonly ready: "Ready to start.";
12
- readonly saveFirst: "Save your changes first.";
23
+ readonly saveFirst: "Wait for your changes to save.";
13
24
  readonly saving: "Saving…";
14
25
  readonly saved: "Saved";
15
26
  readonly saveError: "Couldn't save — see the highlighted field";
27
+ readonly invalidRequest: "This test's setup couldn't be checked.";
16
28
  readonly checkError: "Couldn't check readiness. Try again.";
17
29
  readonly checking: "Checking readiness…";
18
30
  readonly retry: "Try again";
@@ -56,6 +68,7 @@ export declare const unpublishedPageCopy: (path: string, context?: {
56
68
  }) => string;
57
69
  /** Old responses may include raw host errors; unknown strings use authored copy. */
58
70
  export declare const placementFailureCopy: (reason: unknown) => "Couldn't check where this test is used. Try again." | "You don't have permission to check where this test is used." | "A page used by this test no longer exists. Choose another page.";
71
+ export declare const fixFieldsNext: (name: string) => string;
59
72
  export declare const nextCopy: (sentence: string) => string;
60
73
  export declare const versionsNext: (detail: string) => string;
61
74
  export declare const contentNext: (group: string) => string;
@@ -88,3 +101,6 @@ export declare function interactingTestsCopy(page: string, state: string, name:
88
101
  export declare const goalInSomeVersionsCopy: (name?: string) => string;
89
102
  export declare function asymmetricGoalsCopy(detail: unknown): string;
90
103
  export declare const placementUncheckedCopy: (page: string) => string;
104
+ export declare const moreBlockers: (count: number) => string;
105
+ export declare const unpublishedPlacementsCopy: (detail?: unknown) => string;
106
+ export declare const unpublishedPlacementCopy: (title?: string) => string;
@@ -3,16 +3,28 @@ export const PLACEMENT_FAILURE_COPY = {
3
3
  forbidden: "You don't have permission to check where this test is used.",
4
4
  'not-found': "A page used by this test no longer exists. Choose another page."
5
5
  };
6
+ export const SAVE_PAGE = 'Save this page to put the test on it.';
7
+ export const PUBLISH_PAGE = 'Publish this page to start the test.';
8
+ export const RUNNING_PUBLISH_PAGE = "This test is running, but visitors won't see it here until this page is published.";
9
+ export const RUNNING_SAVE_PAGE = "This test is running, but visitors won't see it here until this page is saved and published.";
6
10
  export const READINESS_COPY = {
11
+ beforeStart: 'Before you can start:',
7
12
  label: 'Readiness',
8
13
  addGoal: 'Add a goal',
9
14
  needsAttention: 'Needs attention',
15
+ needsAttentionPrefix: 'Needs attention: ',
10
16
  missingVersions: 'This test is missing its saved versions. Open the test and check its setup before changing this page.',
17
+ saveGeneralError: "Couldn't save. Reload to check the saved test.",
18
+ changing: 'Saving this change…',
19
+ reloadAfterError: "Couldn't save the test. Reload to check its saved settings before starting.",
20
+ chooseGoalToAdd: 'Choose a goal to add it to this test.',
21
+ reloadFirst: 'Reload to see the latest test settings before starting.',
11
22
  ready: 'Ready to start.',
12
- saveFirst: 'Save your changes first.',
23
+ saveFirst: 'Wait for your changes to save.',
13
24
  saving: 'Saving…',
14
25
  saved: 'Saved',
15
26
  saveError: "Couldn't save — see the highlighted field",
27
+ invalidRequest: "This test's setup couldn't be checked.",
16
28
  checkError: "Couldn't check readiness. Try again.",
17
29
  checking: 'Checking readiness…',
18
30
  retry: 'Try again',
@@ -53,6 +65,7 @@ export const pageInUseCopy = (path, version = false)=>version ? `${path} is alre
53
65
  export const unpublishedPageCopy = (path, context)=>!context ? `${path} isn't a published page yet. Publish it, or choose another page.` : context.original ? `${path} isn't published, so it can't be the Original. Publish it, or choose another page.` : context.found ? `${path} is still a draft. Publish it in ${context.collection}, then start the test.` : `${path} isn't published yet, or no page has that address. Publish it in ${context.collection}, or choose another page.`;
54
66
  /** Old responses may include raw host errors; unknown strings use authored copy. */ export const placementFailureCopy = (reason)=>PLACEMENT_FAILURE_COPY[typeof reason === 'string' && Object.hasOwn(PLACEMENT_FAILURE_COPY, reason) ? reason : 'placements-failed'];
55
67
  const withoutPeriod = (value)=>value.trim().replace(/[.!?]+$/, '');
68
+ export const fixFieldsNext = (name)=>`Fix the highlighted fields in ${name}.`;
56
69
  export const nextCopy = (sentence)=>`Next: ${sentence}`;
57
70
  export const versionsNext = (detail)=>`Fix the versions: ${withoutPeriod(detail)}.`;
58
71
  export const contentNext = (group)=>`Add content for ${group} on the page.`;
@@ -93,3 +106,11 @@ export function asymmetricGoalsCopy(detail) {
93
106
  }).join('\n');
94
107
  }
95
108
  export const placementUncheckedCopy = (page)=>`${page} couldn't be checked, so the test can't confirm every version shows the same goals. Check that you can open it.`;
109
+ export const moreBlockers = (count)=>`and ${count} more`;
110
+ export const unpublishedPlacementsCopy = (detail)=>(Array.isArray(detail) && detail.length ? detail : [
111
+ detail
112
+ ]).map((placement)=>{
113
+ const title = placement && typeof placement === 'object' && typeof placement.title === 'string' && placement.title.trim() ? placement.title.trim() : 'this page';
114
+ return unpublishedPlacementCopy(title);
115
+ }).join('\n');
116
+ export const unpublishedPlacementCopy = (title = 'this page')=>`The block you're testing is only on a draft of ${title}. Publish the page before you start.`;
@@ -1,4 +1,5 @@
1
1
  export declare const TEST_PAGE: {
2
+ readonly noAudienceRules: "No audience choices are available here. Everyone eligible takes part; leave this section as it is.";
2
3
  readonly editVersionsOnCanvas: "Edit version content on the canvas.";
3
4
  readonly clickPageGroup: "On this test's page";
4
5
  readonly clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.";
@@ -1,6 +1,7 @@
1
1
  const guardrailsShort = 'Must not get worse';
2
2
  const secondaryShort = 'Also keep an eye on';
3
3
  export const TEST_PAGE = {
4
+ noAudienceRules: 'No audience choices are available here. Everyone eligible takes part; leave this section as it is.',
4
5
  editVersionsOnCanvas: 'Edit version content on the canvas.',
5
6
  clickPageGroup: "On this test's page",
6
7
  clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.",
@@ -0,0 +1,9 @@
1
+ import type { PreflightResult } from '../types/endpoints.js';
2
+ export declare const PREFLIGHT_TIMEOUT_MS = 15000;
3
+ /** The answer must support both readiness and placement consumers. */
4
+ export declare function isPreflightResult(value: unknown): value is PreflightResult;
5
+ /** Bound the response and body read, even when a producer ignores cancellation. */
6
+ export declare function readPreflight(request: (signal: AbortSignal) => Promise<Response>, signal: AbortSignal): Promise<{
7
+ response: Response;
8
+ body: unknown;
9
+ }>;
@@ -0,0 +1,38 @@
1
+ export const PREFLIGHT_TIMEOUT_MS = 15_000;
2
+ /** The answer must support both readiness and placement consumers. */ export function isPreflightResult(value) {
3
+ const data = value;
4
+ return !!data && Array.isArray(data.placements) && Array.isArray(data.checks) && data.checks.every((check)=>check && typeof check.code === 'string' && typeof check.ok === 'boolean');
5
+ }
6
+ /** Bound the response and body read, even when a producer ignores cancellation. */ export async function readPreflight(request, signal) {
7
+ const controller = new AbortController();
8
+ let timer;
9
+ let cancel;
10
+ const cancelled = new Promise((_, reject)=>{
11
+ cancel = ()=>{
12
+ clearTimeout(timer);
13
+ controller.abort();
14
+ reject(new Error('Readiness read cancelled'));
15
+ };
16
+ timer = setTimeout(cancel, PREFLIGHT_TIMEOUT_MS);
17
+ });
18
+ signal.addEventListener('abort', cancel, {
19
+ once: true
20
+ });
21
+ if (signal.aborted) cancel();
22
+ try {
23
+ return await Promise.race([
24
+ cancelled,
25
+ (async ()=>{
26
+ const response = await request(controller.signal);
27
+ const body = await response.json().catch(()=>undefined);
28
+ return {
29
+ response,
30
+ body
31
+ };
32
+ })()
33
+ ]);
34
+ } finally{
35
+ clearTimeout(timer);
36
+ signal.removeEventListener('abort', cancel);
37
+ }
38
+ }
@@ -0,0 +1,50 @@
1
+ import type { PreflightResult } from '../types/endpoints.js';
2
+ export type ReadinessRead = ReturnType<typeof classifyReadinessRead>;
3
+ /** One read policy for every surface. Pending retains this settled value verbatim. */
4
+ export declare function classifyReadinessRead(status: number, body?: unknown, failures?: number, context?: {
5
+ kind: 'document';
6
+ surface?: 'editor';
7
+ resultsOnly?: boolean;
8
+ } | {
9
+ kind: 'readiness' | 'where-used';
10
+ placementNotice?: boolean;
11
+ }): {
12
+ status: number;
13
+ loadState: "forbidden" | "error" | "missing" | "ready";
14
+ kind: string;
15
+ answer: PreflightResult | undefined;
16
+ message: "Couldn't check where this test is used. Try again." | "You don't have permission to check where this test is used." | "A page used by this test no longer exists. Choose another page." | "This test's setup couldn't be checked." | "Couldn't check readiness. Try again." | "This test no longer exists." | "This isn't available yet." | "Your session has expired. Sign in again." | "Couldn't load this test. Try selecting it again." | "You don't have access to this test." | "Couldn't load this test." | "You don't have access to this test. You can still edit its content." | "This test isn't available to you. You can still edit its content." | "You can view this test's results." | undefined;
17
+ failed: boolean;
18
+ retry: boolean;
19
+ pollDelay: number | null;
20
+ };
21
+ /** Legacy callers can supply an answer; producers always supply the classified read. */
22
+ export declare function readinessRead(test: {
23
+ preflight: PreflightResult | null;
24
+ preflightError: string | null;
25
+ preflightRead?: ReadinessRead;
26
+ }): {
27
+ status: number;
28
+ loadState: "forbidden" | "error" | "missing" | "ready";
29
+ kind: string;
30
+ answer: PreflightResult | undefined;
31
+ message: "Couldn't check where this test is used. Try again." | "You don't have permission to check where this test is used." | "A page used by this test no longer exists. Choose another page." | "This test's setup couldn't be checked." | "Couldn't check readiness. Try again." | "This test no longer exists." | "This isn't available yet." | "Your session has expired. Sign in again." | "Couldn't load this test. Try selecting it again." | "You don't have access to this test." | "Couldn't load this test." | "You don't have access to this test. You can still edit its content." | "This test isn't available to you. You can still edit its content." | "You can view this test's results." | undefined;
32
+ failed: boolean;
33
+ retry: boolean;
34
+ pollDelay: number | null;
35
+ };
36
+ /** Settled display is independent of a refresh in progress. */
37
+ export declare function readyToStart(test: {
38
+ preflight: PreflightResult | null;
39
+ preflightError: string | null;
40
+ preflightRead?: ReadinessRead;
41
+ }, placementMessage?: string): boolean;
42
+ /** Pending changes only the ability to fire Start, never the settled display. */
43
+ export declare function canStartTest(test: {
44
+ preflight: PreflightResult | null;
45
+ preflightError: string | null;
46
+ preflightRead?: ReadinessRead;
47
+ preflightPending: boolean;
48
+ hasUnsaved: boolean;
49
+ saving: string;
50
+ }, placementMessage?: string): boolean;
@@ -0,0 +1,46 @@
1
+ import { API_MESSAGES } from './copy/common.js';
2
+ import { PLACEMENT_FAILURE_COPY, READINESS_COPY, placementFailureCopy } from './copy/readiness.js';
3
+ import { TEST_PAGE } from './copy/testPage.js';
4
+ import { editorCopy } from '../puck/editor/copy.js';
5
+ import { pickerCopy } from '../puck/copy.js';
6
+ import { isPreflightResult } from './readPreflight.js';
7
+ /** One read policy for every surface. Pending retains this settled value verbatim. */ export function classifyReadinessRead(status, body, failures = 1, context = {
8
+ kind: 'readiness'
9
+ }) {
10
+ const document = context.kind === 'document';
11
+ const answer = !document && status === 200 && isPreflightResult(body) ? body : undefined;
12
+ const detail = answer?.checks.find((check)=>!check.ok && (check.code === 'no-placements' && check.detail !== undefined || check.code === 'flag-placement-missing' && typeof check.detail === 'string'))?.detail;
13
+ const kind = status === 401 ? 'signed-out' : status === 404 || detail === 'not-found' ? 'not-found' : status === 403 || detail === 'forbidden' ? 'no-access' : status === 400 || status === 501 ? 'permanent' : answer ? 'answered' : 'failed';
14
+ const failed = kind === 'failed' || kind === 'answered' && detail !== undefined;
15
+ const retry = failed;
16
+ const message = kind === 'signed-out' ? API_MESSAGES.unauthenticated : kind === 'not-found' ? answer ? PLACEMENT_FAILURE_COPY['not-found'] : document && context.surface === 'editor' ? pickerCopy.unavailable : API_MESSAGES.notFound : kind === 'no-access' ? document ? context.surface === 'editor' ? context.resultsOnly ? pickerCopy.resultsOnly : pickerCopy.forbidden : TEST_PAGE.forbidden : PLACEMENT_FAILURE_COPY.forbidden : kind === 'permanent' ? status === 501 ? API_MESSAGES.notImplemented : document ? context.surface === 'editor' ? editorCopy.loadError : TEST_PAGE.error : READINESS_COPY.invalidRequest : kind === 'failed' ? document ? context.surface === 'editor' ? editorCopy.loadError : TEST_PAGE.error : READINESS_COPY.checkError : detail !== undefined ? placementFailureCopy(detail) : undefined;
17
+ // Subscribers determine whether save/publish guidance is displayed. Its polling
18
+ // eligibility is classified here, alongside permanent and temporary failures.
19
+ const placementNotice = !document && (context.placementNotice ?? context.kind === 'where-used');
20
+ const pollDelay = retry ? [
21
+ 4_000,
22
+ 8_000,
23
+ 16_000,
24
+ 30_000
25
+ ][Math.min(Math.max(0, failures - 1), 3)] : kind === 'answered' && placementNotice ? 4_000 : null;
26
+ const loadState = kind === 'not-found' ? 'missing' : kind === 'signed-out' || kind === 'no-access' ? 'forbidden' : kind === 'failed' || kind === 'permanent' ? 'error' : 'ready';
27
+ return {
28
+ status,
29
+ loadState,
30
+ kind,
31
+ answer,
32
+ message,
33
+ failed,
34
+ retry,
35
+ pollDelay
36
+ };
37
+ }
38
+ /** Legacy callers can supply an answer; producers always supply the classified read. */ export function readinessRead(test) {
39
+ return test.preflightRead ?? classifyReadinessRead(test.preflightError ? 0 : 200, test.preflight);
40
+ }
41
+ /** Settled display is independent of a refresh in progress. */ export function readyToStart(test, placementMessage) {
42
+ return !!test.preflight && !placementMessage && readinessRead(test).kind === 'answered' && !test.preflightError && test.preflight.checks.every((check)=>check.ok);
43
+ }
44
+ /** Pending changes only the ability to fire Start, never the settled display. */ export function canStartTest(test, placementMessage) {
45
+ return readyToStart(test, placementMessage) && !test.preflightPending && !test.hasUnsaved && test.saving !== 'saving';
46
+ }
@@ -9,6 +9,12 @@ export declare const SECTION_ORDER: readonly SectionId[];
9
9
  export type TestDocApi = ReturnType<typeof useTestDocument>;
10
10
  /** Serialisable props the server root view passes to the surface (ADM-20). */
11
11
  export interface SurfaceProps {
12
+ /** Present only when configuring a block from its page editor. */
13
+ editorPage?: {
14
+ collection: string;
15
+ id: string;
16
+ };
17
+ editorPlacementMessage?: string;
12
18
  adminRoute: string;
13
19
  apiRoute: string;
14
20
  collectionTitles?: Record<string, string>;
@@ -40,8 +46,6 @@ export interface KindParts {
40
46
  }
41
47
  /** Readiness pieces (ADM-23). */
42
48
  export interface ReadinessParts {
43
- /** Sticky-header banner incl. Start / status sentence. */
44
- Banner: ComponentType<SectionProps>;
45
49
  /** "Saving…" / "Saved" / error indicator for the header. */
46
50
  SaveStatus: ComponentType<{
47
51
  test: TestDocApi;
@@ -0,0 +1,21 @@
1
+ import type { PreflightResult } from '../../types/endpoints.js';
2
+ import type { Status } from '../../types/contracts.js';
3
+ import type { TestDocApi, SurfaceProps } from './contracts.js';
4
+ export { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
5
+ /** Replace only the guidance represented by this page's local notice. */
6
+ export declare function editorPlacementChecks(checks: PreflightResult['checks'], page: NonNullable<SurfaceProps['editorPage']>): PreflightResult['checks'];
7
+ /** Editor context is a hint for guidance only; Start still runs server preflight. */
8
+ export declare function editorPlacementMessage(placements: PreflightResult['placements'] | undefined, page: SurfaceProps['editorPage'], status: Status | undefined): string | undefined;
9
+ /** Replace this page's checks once, retaining every other page's blocker. */
10
+ export declare function editorPreflight(answer: PreflightResult | null, surface: SurfaceProps, includeLocalBlocker?: boolean): PreflightResult | null;
11
+ /** Shared sidebar policy; the bounded list renders these steps verbatim. */
12
+ export declare function sidebarReadinessBlockers(test: TestDocApi, surface: SurfaceProps): ({
13
+ arm?: import("../../types/contracts.js").ArmKey | undefined;
14
+ section: "header" | import("./contracts.js").SectionId;
15
+ sentence: string;
16
+ code: import("../../transitions/checkStart.js").ReadinessCode;
17
+ } | {
18
+ sentence: "Wait for your changes to save.";
19
+ })[] | {
20
+ sentence: "Checking readiness…";
21
+ }[];
@@ -0,0 +1,60 @@
1
+ import { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
2
+ import { blockingSteps, pageReadinessContext } from './readiness/readiness.model.js';
3
+ import { READINESS_COPY } from '../copy/readiness.js';
4
+ export { SAVE_PAGE, PUBLISH_PAGE, RUNNING_PUBLISH_PAGE, RUNNING_SAVE_PAGE } from '../copy/readiness.js';
5
+ /** Replace only the guidance represented by this page's local notice. */ export function editorPlacementChecks(checks, page) {
6
+ return checks.flatMap((check)=>{
7
+ if (check.code === 'no-placements') return [];
8
+ if (check.code !== 'placement-unpublished' || check.ok) return [
9
+ check
10
+ ];
11
+ const detail = (Array.isArray(check.detail) ? check.detail : [
12
+ check.detail
13
+ ]).filter((value)=>{
14
+ if (!value || typeof value !== 'object') return true;
15
+ const row = value;
16
+ return row.collection !== page.collection || String(row.id) !== String(page.id);
17
+ });
18
+ return detail.length ? [
19
+ {
20
+ ...check,
21
+ detail
22
+ }
23
+ ] : [];
24
+ });
25
+ }
26
+ /** Editor context is a hint for guidance only; Start still runs server preflight. */ export function editorPlacementMessage(placements, page, status) {
27
+ if (!page || !placements || !status || status === 'decided' || status === 'archived') return;
28
+ const here = placements.filter((p)=>p.collection === page.collection && String(p.id) === String(page.id));
29
+ if (!here.length) return status === 'running' ? RUNNING_SAVE_PAGE : SAVE_PAGE;
30
+ if (!here.some((p)=>p.detail === 'Published')) return status === 'running' ? RUNNING_PUBLISH_PAGE : PUBLISH_PAGE;
31
+ }
32
+ /** Replace this page's checks once, retaining every other page's blocker. */ export function editorPreflight(answer, surface, includeLocalBlocker = true) {
33
+ return answer && surface.editorPlacementMessage && surface.editorPage ? {
34
+ ...answer,
35
+ checks: [
36
+ ...editorPlacementChecks(answer.checks, surface.editorPage),
37
+ ...includeLocalBlocker ? [
38
+ {
39
+ code: 'no-placements',
40
+ ok: false
41
+ }
42
+ ] : []
43
+ ]
44
+ } : answer;
45
+ }
46
+ /** Shared sidebar policy; the bounded list renders these steps verbatim. */ export function sidebarReadinessBlockers(test, surface) {
47
+ const answer = editorPreflight(test.preflight, surface, false);
48
+ const blockers = test.doc ? blockingSteps(answer, pageReadinessContext(test.doc, test.preflight, surface)) : [];
49
+ const notice = test.preflightRead?.message ?? surface.editorPlacementMessage;
50
+ return test.hasUnsaved ? [
51
+ {
52
+ sentence: READINESS_COPY.saveFirst
53
+ },
54
+ ...blockers
55
+ ] : !answer && !notice ? [
56
+ {
57
+ sentence: READINESS_COPY.checking
58
+ }
59
+ ] : blockers.filter((step)=>step.sentence !== notice);
60
+ }
@@ -1,14 +1,24 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Banner } from '../../../ui/Banner.js';
3
4
  import { Button } from '../../../ui/Button.js';
4
5
  import { placementPages } from '../../../lib/placementPages.js';
5
6
  import { TEST_PAGE as C, placementCount } from '../../copy/testPage.js';
6
7
  import { placementLine, slotReady } from './pageBlock.model.js';
7
- function Binding({ test }) {
8
+ function Binding({ test, surface }) {
8
9
  const placements = test.preflight?.placements ?? [];
9
10
  return /*#__PURE__*/ _jsx("div", {
10
11
  className: "xp-page-binding",
11
- children: placements.length ? /*#__PURE__*/ _jsxs(_Fragment, {
12
+ children: surface.editorPlacementMessage ? test.doc?.status === 'running' ? /*#__PURE__*/ _jsxs(Banner, {
13
+ tone: "warning",
14
+ children: [
15
+ /*#__PURE__*/ _jsx("span", {
16
+ "aria-hidden": "true",
17
+ children: "⚠ "
18
+ }),
19
+ surface.editorPlacementMessage
20
+ ]
21
+ }) : null : placements.length ? /*#__PURE__*/ _jsxs(_Fragment, {
12
22
  children: [
13
23
  placementPages(placements).map((placement)=>/*#__PURE__*/ _jsxs("p", {
14
24
  className: "xp-ui-button-group",
@@ -28,7 +38,7 @@ function Binding({ test }) {
28
38
  children: C.editedOnPage
29
39
  })
30
40
  ]
31
- }) : /*#__PURE__*/ _jsx("p", {
41
+ }) : test.preflight?.checks.some((check)=>!check.ok && check.code === 'no-placements') ? null : /*#__PURE__*/ _jsx("p", {
32
42
  children: C.notPlaced
33
43
  })
34
44
  });