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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/admin/copy/newTest.d.ts +1 -1
  2. package/dist/admin/copy/newTest.js +1 -1
  3. package/dist/admin/surface/ResultsRoute.js +2 -10
  4. package/dist/admin/surface/newTest/NewTest.js +16 -18
  5. package/dist/admin/surface/newTest/PageWizard.js +10 -12
  6. package/dist/admin/surface/newTest/newTest.css +3 -1
  7. package/dist/admin/surface/results/ResultsHeader.js +15 -8
  8. package/dist/blocks/bindings.js +6 -13
  9. package/dist/blocks/placementLocale.d.ts +2 -0
  10. package/dist/blocks/placementLocale.js +16 -12
  11. package/dist/goals/fairness.d.ts +1 -1
  12. package/dist/goals/fairness.js +9 -7
  13. package/dist/hooks/blockRemovalRule.d.ts +2 -1
  14. package/dist/hooks/blockRemovalRule.js +27 -5
  15. package/dist/hooks/pageGuard.js +2 -2
  16. package/dist/puck/ExperimentPicker.d.ts +2 -1
  17. package/dist/puck/ExperimentPicker.js +34 -30
  18. package/dist/puck/ExperimentSlot.js +3 -1
  19. package/dist/puck/copy.d.ts +1 -0
  20. package/dist/puck/copy.js +1 -0
  21. package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
  22. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  23. package/dist/puck/editor/CreateExperimentDrawer.js +24 -16
  24. package/dist/puck/editor/EditorControls.d.ts +1 -1
  25. package/dist/puck/editor/EditorControls.js +1 -1
  26. package/dist/puck/editor/ExperimentSlotEditor.js +624 -299
  27. package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
  28. package/dist/puck/editor/LeftoverVersions.js +97 -0
  29. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  30. package/dist/puck/editor/PlacementNotice.js +22 -0
  31. package/dist/puck/editor/QuickTestActions.d.ts +3 -0
  32. package/dist/puck/editor/QuickTestActions.js +50 -0
  33. package/dist/puck/editor/ResultsReadout.js +5 -0
  34. package/dist/puck/editor/VersionBuilder.d.ts +37 -12
  35. package/dist/puck/editor/VersionBuilder.js +273 -184
  36. package/dist/puck/editor/armWrites.d.ts +11 -2
  37. package/dist/puck/editor/armWrites.js +42 -3
  38. package/dist/puck/editor/armsCache.d.ts +1 -1
  39. package/dist/puck/editor/armsCache.js +2 -1
  40. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  41. package/dist/puck/editor/cloneSlot.js +7 -0
  42. package/dist/puck/editor/copy.d.ts +35 -20
  43. package/dist/puck/editor/copy.js +35 -20
  44. package/dist/puck/editor/createTest.d.ts +3 -0
  45. package/dist/puck/editor/createTest.js +33 -0
  46. package/dist/puck/editor/editor.chrome.css +32 -14
  47. package/dist/puck/editor/editor.css +58 -17
  48. package/dist/puck/editor/editor.model.d.ts +1 -1
  49. package/dist/puck/editor/editor.model.js +2 -2
  50. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  51. package/dist/puck/editor/localPlacements.d.ts +4 -2
  52. package/dist/puck/editor/localPlacements.js +20 -18
  53. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  54. package/dist/puck/editor/outlineVersion.js +36 -0
  55. package/dist/puck/editor/placementsCache.d.ts +33 -2
  56. package/dist/puck/editor/placementsCache.js +208 -33
  57. package/dist/puck/editor/sidebar.d.ts +8 -0
  58. package/dist/puck/editor/sidebar.js +74 -0
  59. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  60. package/dist/puck/editor/usePlacementNotice.js +14 -0
  61. package/dist/puck/visibility.d.ts +21 -0
  62. package/dist/puck/visibility.js +77 -0
  63. package/dist/server/recordContentChange.js +3 -1
  64. package/dist/server/resolveExperimentData.js +4 -1
  65. package/dist/testSurface/api.js +1 -1
  66. package/dist/testSurface/copy/common.d.ts +1 -1
  67. package/dist/testSurface/copy/common.js +3 -1
  68. package/dist/testSurface/copy/readiness.d.ts +18 -1
  69. package/dist/testSurface/copy/readiness.js +23 -1
  70. package/dist/testSurface/copy/testPage.d.ts +8 -6
  71. package/dist/testSurface/copy/testPage.js +8 -6
  72. package/dist/testSurface/readPreflight.d.ts +9 -0
  73. package/dist/testSurface/readPreflight.js +38 -0
  74. package/dist/testSurface/readinessRead.d.ts +50 -0
  75. package/dist/testSurface/readinessRead.js +46 -0
  76. package/dist/testSurface/results/results.css +1 -1
  77. package/dist/testSurface/results/results.model.d.ts +1 -1
  78. package/dist/testSurface/surface/contracts.d.ts +6 -2
  79. package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
  80. package/dist/testSurface/surface/editorPlacement.js +60 -0
  81. package/dist/testSurface/surface/pageBlock/parts.js +13 -3
  82. package/dist/testSurface/surface/readiness/ActionDialogs.js +65 -41
  83. package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
  84. package/dist/testSurface/surface/readiness/Banner.js +106 -68
  85. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  86. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  87. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
  88. package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
  89. package/dist/testSurface/surface/readiness/parts.js +0 -2
  90. package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
  91. package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
  92. package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
  93. package/dist/testSurface/surface/readiness/useTransition.js +69 -7
  94. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  95. package/dist/testSurface/surface/test/GoalSection.js +102 -74
  96. package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
  97. package/dist/testSurface/surface/test/LengthSection.js +2 -1
  98. package/dist/testSurface/surface/test/Rail.js +7 -4
  99. package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
  100. package/dist/testSurface/surface/test/Section.d.ts +3 -1
  101. package/dist/testSurface/surface/test/Section.js +38 -6
  102. package/dist/testSurface/surface/test/TargetingSection.js +5 -0
  103. package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
  104. package/dist/testSurface/surface/test/TestSurface.js +68 -7
  105. package/dist/testSurface/surface/test/VersionsSection.js +1 -0
  106. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  107. package/dist/testSurface/surface/test/fields.js +5 -35
  108. package/dist/testSurface/surface/test/testPage.css +12 -0
  109. package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
  110. package/dist/testSurface/surface/useTestDocument.js +61 -46
  111. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  112. package/dist/testSurface/useReadinessPolling.js +24 -0
  113. package/dist/transitions/makeContent.js +24 -5
  114. package/dist/transitions/placements.js +23 -34
  115. package/dist/transitions/preflightData.js +1 -1
  116. package/dist/types/puck.d.ts +1 -0
  117. package/dist/ui/Card.d.ts +2 -1
  118. package/dist/ui/Card.js +4 -4
  119. package/dist/ui/Inputs.js +8 -5
  120. package/dist/ui/Tabs.d.ts +2 -2
  121. package/dist/ui/Tabs.js +33 -32
  122. package/dist/ui/ui.css +26 -3
  123. package/package.json +1 -1
@@ -0,0 +1,74 @@
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 } 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 never another data reader. */ export function TestSidebarField() {
38
+ const getPuck = useGetPuck();
39
+ const id = usePuckSelector((state)=>state.selectedItem?.props.id);
40
+ const [test, setTest] = useState(null);
41
+ const [controls, setControls] = useState(null);
42
+ useEffect(()=>{
43
+ if (!id || !test || !controls) return;
44
+ const entry = bridge(getPuck);
45
+ const targets = {
46
+ test,
47
+ controls
48
+ };
49
+ entry.targets.set(id, targets);
50
+ for (const notify of entry.listeners)notify();
51
+ return ()=>{
52
+ if (entry.targets.get(id) === targets) entry.removeTarget(id);
53
+ for (const notify of entry.listeners)notify();
54
+ };
55
+ }, [
56
+ id,
57
+ test,
58
+ controls,
59
+ getPuck
60
+ ]);
61
+ return /*#__PURE__*/ _jsxs("div", {
62
+ className: "xp-slot-root xp-slot-editor xp-puck-field xp-slot-sidebar",
63
+ onClick: (event)=>event.stopPropagation(),
64
+ onKeyDown: (event)=>event.stopPropagation(),
65
+ children: [
66
+ /*#__PURE__*/ _jsx("div", {
67
+ ref: setTest
68
+ }),
69
+ /*#__PURE__*/ _jsx("div", {
70
+ ref: setControls
71
+ })
72
+ ]
73
+ });
74
+ }
@@ -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
+ }
@@ -0,0 +1,21 @@
1
+ /** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */
2
+ export declare const visibilitySizes: readonly ["phone", "tablet", "desktop"];
3
+ export type VisibilitySize = typeof visibilitySizes[number];
4
+ /** Read known sizes only; missing lists and malformed entries add no hiding. */
5
+ export declare function hiddenOnSizes(value: unknown): VisibilitySize[];
6
+ export declare function fullyHidden(value: unknown): boolean;
7
+ export type BlockVisibility = {
8
+ hidden: boolean;
9
+ hideOn: VisibilitySize[];
10
+ };
11
+ type PuckBlock = Record<string, unknown> & {
12
+ type: string;
13
+ props: Record<string, unknown>;
14
+ };
15
+ /** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
16
+ * Orphan zones retain their historical discovery behavior and count as shown.
17
+ */
18
+ export declare function walkVisiblePuck(data: unknown, visit: (block: PuckBlock, visibility: BlockVisibility) => void): void;
19
+ /** Identity-keyed index shared by discovery and the public resolver. */
20
+ export declare function puckVisibility(data: unknown): Map<object, BlockVisibility>;
21
+ export {};
@@ -0,0 +1,77 @@
1
+ /** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */ export const visibilitySizes = [
2
+ 'phone',
3
+ 'tablet',
4
+ 'desktop'
5
+ ];
6
+ const object = (value)=>!!value && typeof value === 'object' && !Array.isArray(value);
7
+ /** Read known sizes only; missing lists and malformed entries add no hiding. */ export function hiddenOnSizes(value) {
8
+ if (!object(value) || !Array.isArray(value.hideOn)) return [];
9
+ const sizes = value.hideOn;
10
+ return visibilitySizes.filter((size)=>sizes.includes(size));
11
+ }
12
+ export function fullyHidden(value) {
13
+ return object(value) && (value.hidden === true || hiddenOnSizes(value).length === visibilitySizes.length);
14
+ }
15
+ /** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
16
+ * Orphan zones retain their historical discovery behavior and count as shown.
17
+ */ export function walkVisiblePuck(data, visit) {
18
+ const owners = new Set();
19
+ const zones = new Map();
20
+ const roots = [];
21
+ function index(value) {
22
+ if (Array.isArray(value)) {
23
+ value.forEach(index);
24
+ return;
25
+ }
26
+ if (!object(value)) return;
27
+ if (typeof value.type === 'string' && object(value.props) && typeof value.props.id === 'string') owners.add(value.props.id);
28
+ for (const [key, child] of Object.entries(value)){
29
+ if (value === data && key === 'zones' && object(child)) {
30
+ for (const [zone, content] of Object.entries(child)){
31
+ const owner = zone.slice(0, zone.lastIndexOf(':'));
32
+ zones.set(owner, [
33
+ ...zones.get(owner) ?? [],
34
+ content
35
+ ]);
36
+ roots.push({
37
+ owner,
38
+ content
39
+ });
40
+ index(content);
41
+ }
42
+ } else index(child);
43
+ }
44
+ }
45
+ index(data);
46
+ const seen = new WeakSet();
47
+ function walk(value, inherited) {
48
+ if (Array.isArray(value)) {
49
+ value.forEach((child)=>walk(child, inherited));
50
+ return;
51
+ }
52
+ if (!object(value) || seen.has(value)) return;
53
+ seen.add(value);
54
+ let visibility = inherited;
55
+ const props = value.props;
56
+ if (typeof value.type === 'string' && object(props)) {
57
+ visibility = {
58
+ hidden: inherited.hidden || fullyHidden(props._visibility),
59
+ hideOn: visibilitySizes.filter((size)=>inherited.hideOn.includes(size) || hiddenOnSizes(props._visibility).includes(size))
60
+ };
61
+ visit(value, visibility);
62
+ if (typeof props.id === 'string') for (const content of zones.get(props.id) ?? [])walk(content, visibility);
63
+ }
64
+ for (const [key, child] of Object.entries(value))if (value !== data || key !== 'zones' || !object(child)) walk(child, visibility);
65
+ }
66
+ const shown = {
67
+ hidden: false,
68
+ hideOn: []
69
+ };
70
+ walk(data, shown);
71
+ for (const root of roots)if (!owners.has(root.owner)) walk(root.content, shown);
72
+ }
73
+ /** Identity-keyed index shared by discovery and the public resolver. */ export function puckVisibility(data) {
74
+ const result = new Map();
75
+ walkVisiblePuck(data, (block, visibility)=>result.set(block, visibility));
76
+ return result;
77
+ }
@@ -1,3 +1,4 @@
1
+ import { puckVisibility } from '../puck/visibility.js';
1
2
  import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from '../blocks/model.js';
2
3
  import { safeError } from '../log.js';
3
4
  import { isDeepStrictEqual } from 'node:util';
@@ -19,6 +20,7 @@ const slots = [
19
20
  const object = (value)=>value !== null && typeof value === 'object' && !Array.isArray(value);
20
21
  function bindings(data, puck) {
21
22
  const found = new Map();
23
+ const visibility = puck ? puckVisibility(data) : undefined;
22
24
  function add(field, value, content) {
23
25
  const key = field + ':' + value;
24
26
  const binding = found.get(key) ?? {
@@ -34,7 +36,7 @@ function bindings(data, puck) {
34
36
  value.forEach(walk);
35
37
  return;
36
38
  }
37
- if (!object(value)) return;
39
+ if (!object(value) || visibility?.get(value)?.hidden) return;
38
40
  if (puck && value.type === 'ExperimentSlot' && object(value.props)) {
39
41
  const props = value.props;
40
42
  const slug = typeof props.experiment === 'string' ? props.experiment : object(props.experiment) ? props.experiment.slug : undefined;
@@ -1,5 +1,7 @@
1
+ import { puckVisibility } from '../puck/visibility.js';
1
2
  import { manifestOf, suppressExposure } from './context.js';
2
3
  export function resolveExperimentData(puckData, assignments) {
4
+ const visibility = puckVisibility(puckData);
3
5
  const rendered = new Map();
4
6
  const slots = [
5
7
  'control',
@@ -9,8 +11,9 @@ export function resolveExperimentData(puckData, assignments) {
9
11
  ];
10
12
  const manifest = manifestOf(assignments);
11
13
  function walk(value) {
12
- if (Array.isArray(value)) return value.map(walk);
14
+ if (Array.isArray(value)) return value.map(walk).filter((item)=>item !== undefined);
13
15
  if (!value || typeof value !== 'object') return value;
16
+ if (visibility.get(value)?.hidden) return undefined;
14
17
  const node = value;
15
18
  if (node.type !== 'ExperimentSlot') return Object.fromEntries(Object.entries(node).map(([key, item])=>[
16
19
  key,
@@ -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;
@@ -68,6 +81,7 @@ export declare const stoppedCopy: (date: string | null) => string;
68
81
  export declare const decidedCopy: (date: string | null, winner: string) => string;
69
82
  export declare const runningCopy: (date: string | null, people: number | null, days: number | null) => string;
70
83
  export declare const lastBlockPlacementCopy: (name: string, removingPage?: boolean) => string;
84
+ export declare const hiddenBlockPlacementCopy: (name: string) => string;
71
85
  export declare const bulkBlockRemovalCopy: (name: string) => string;
72
86
  export declare const pendingBlockRemovalCopy: (name: string) => string;
73
87
  /** After archive the guard protects the winner and the Original; only the winner page is "the winner". */
@@ -88,3 +102,6 @@ export declare function interactingTestsCopy(page: string, state: string, name:
88
102
  export declare const goalInSomeVersionsCopy: (name?: string) => string;
89
103
  export declare function asymmetricGoalsCopy(detail: unknown): string;
90
104
  export declare const placementUncheckedCopy: (page: string) => string;
105
+ export declare const moreBlockers: (count: number) => string;
106
+ export declare const unpublishedPlacementsCopy: (detail?: unknown) => string;
107
+ 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.`;
@@ -69,6 +82,7 @@ export const runningCopy = (date, people, days)=>[
69
82
  days === null ? null : `about ${days} days to go`
70
83
  ].filter(Boolean).join(' · ');
71
84
  export const lastBlockPlacementCopy = (name, removingPage = false)=>removingPage ? `“${name}” is running and this page is the only published place it appears. Stop the test first.` : `“${name}” is running and this is the only published place it appears. Stop the test, or keep its block on this page.`;
85
+ export const hiddenBlockPlacementCopy = (name)=>`“${name}” is running and this is the only published place it appears. Stop the test first, or keep its block visible on this page.`;
72
86
  export const bulkBlockRemovalCopy = (name)=>`“${name}” is running and the pages in this change are the only published places it appears. Stop the test first.`;
73
87
  export const pendingBlockRemovalCopy = (name)=>`“${name}” is running and the pages in this change are the only published places it appears. Stop the test first, or change these pages one at a time.`;
74
88
  /** After archive the guard protects the winner and the Original; only the winner page is "the winner". */ export const pageGuardCopy = (name, status, role = 'winner')=>status === 'archived' ? role === 'original' ? `This page's address now shows the winner of the finished test "${name}". To free it, open the test and choose "Release pages".` : `This page is shown at other addresses because the finished test "${name}" made it the winner. To free it, open the test and choose "Release pages".` : status === 'decided' ? `This page is part of the decided test "${name}". Choose "Make it the content" or "Discard winner" on the test before you delete, rename or unpublish it.` : `This page is part of the running test "${name}". Stop the test before you delete, rename or unpublish it.`;
@@ -93,3 +107,11 @@ export function asymmetricGoalsCopy(detail) {
93
107
  }).join('\n');
94
108
  }
95
109
  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.`;
110
+ export const moreBlockers = (count)=>`and ${count} more`;
111
+ export const unpublishedPlacementsCopy = (detail)=>(Array.isArray(detail) && detail.length ? detail : [
112
+ detail
113
+ ]).map((placement)=>{
114
+ const title = placement && typeof placement === 'object' && typeof placement.title === 'string' && placement.title.trim() ? placement.title.trim() : 'this page';
115
+ return unpublishedPlacementCopy(title);
116
+ }).join('\n');
117
+ 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,7 +1,7 @@
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
- readonly clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.";
5
5
  readonly clickGoalHelp: "A click shows interest, not the result you want.";
6
6
  readonly staleEdit: "Someone else changed this test. Reload to see their changes.";
7
7
  readonly reload: "Reload";
@@ -61,15 +61,17 @@ export declare const TEST_PAGE: {
61
61
  readonly holdoutPrefix: "Holdout: ";
62
62
  readonly allocation: "How many people take part";
63
63
  readonly traffic: "How people are split";
64
+ readonly otherGoals: "Other goals (optional)";
65
+ readonly otherGoalsTitle: "Other goals";
66
+ readonly dontTrack: "Don't track";
67
+ readonly watch: "Watch";
68
+ readonly mustNotWorsen: "Must not get worse";
69
+ readonly otherGoalsHelp: "Watch: shown in results. Must not get worse: you're warned if a version makes it worse.";
64
70
  readonly goal: "Goal";
65
- readonly goalHelp: "The goal decides whether a version wins. Pick the one thing you want more of.";
71
+ readonly goalHelp: "The one thing you want more of. It decides the winner.";
66
72
  readonly guardrailsShort: "Must not get worse";
67
- readonly guardrails: "Must not get worse (optional)";
68
- readonly guardrailHelp: "If a version makes one of these worse, you'll be warned.";
69
73
  readonly secondaryShort: "Also keep an eye on";
70
- readonly secondary: "Also keep an eye on (optional)";
71
74
  readonly manageGoals: "Manage goals";
72
- readonly searchGoals: "Search goals";
73
75
  readonly chooseGoal: "Choose a goal";
74
76
  readonly goalsError: "Couldn't load goals. Try again.";
75
77
  readonly noGoal: "None selected";
@@ -1,9 +1,9 @@
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
- clickGoalsNote: "Goals inside linked documents aren't shown. Goals added in code (data-xp-goal) work but aren't listed here.",
7
7
  clickGoalHelp: 'A click shows interest, not the result you want.',
8
8
  staleEdit: 'Someone else changed this test. Reload to see their changes.',
9
9
  reload: 'Reload',
@@ -63,15 +63,17 @@ export const TEST_PAGE = {
63
63
  holdoutPrefix: 'Holdout: ',
64
64
  allocation: 'How many people take part',
65
65
  traffic: 'How people are split',
66
+ otherGoals: 'Other goals (optional)',
67
+ otherGoalsTitle: 'Other goals',
68
+ dontTrack: "Don't track",
69
+ watch: 'Watch',
70
+ mustNotWorsen: 'Must not get worse',
71
+ otherGoalsHelp: "Watch: shown in results. Must not get worse: you're warned if a version makes it worse.",
66
72
  goal: 'Goal',
67
- goalHelp: 'The goal decides whether a version wins. Pick the one thing you want more of.',
73
+ goalHelp: 'The one thing you want more of. It decides the winner.',
68
74
  guardrailsShort,
69
- guardrails: `${guardrailsShort} (optional)`,
70
- guardrailHelp: "If a version makes one of these worse, you'll be warned.",
71
75
  secondaryShort,
72
- secondary: `${secondaryShort} (optional)`,
73
76
  manageGoals: 'Manage goals',
74
- searchGoals: 'Search goals',
75
77
  chooseGoal: 'Choose a goal',
76
78
  goalsError: "Couldn't load goals. Try again.",
77
79
  noGoal: 'None selected',
@@ -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
+ }
@@ -6,7 +6,7 @@
6
6
  :where(.xp-test-surface) .xp-verdict-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--xp-space-3); margin-top: var(--xp-space-5); padding-top: var(--xp-space-4); border-top: 1px solid var(--xp-border); color: var(--xp-text-3); font: var(--xp-text-small); }
7
7
  :where(.xp-test-surface) .xp-round-meta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--xp-space-2); min-width: 0; }
8
8
  :where(.xp-test-surface) .xp-round-meta .xp-ui-field { display: flex; align-items: center; gap: var(--xp-space-2); margin: 0; min-width: 0; }
9
- :where(.xp-test-surface) .xp-round-meta select { width: auto; max-width: 100%; }
9
+ :where(.xp-test-surface) .xp-round-meta .xp-ui-select-wrap { width: auto; max-width: 100%; }
10
10
  :where(.xp-test-surface) .xp-results-chips { display: flex; flex-wrap: wrap; gap: var(--xp-space-2); list-style: none; padding: 0; margin-bottom: 0; }
11
11
  :where(.xp-test-surface) .xp-stat-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--xp-border); border-radius: var(--xp-radius-card); background: var(--xp-surface); overflow: hidden; }
12
12
  :where(.xp-test-surface) .xp-stat-tile { padding: 20px; min-width: 0; }
@@ -80,7 +80,7 @@ export declare function armRows({ snapshot, phase, metricId }: {
80
80
  }): ArmRow[];
81
81
  export declare function guardrailChips(snapshot: DisplaySnapshot): {
82
82
  name: string;
83
- status: "OK" | "Watch" | "Failing" | "Too little data";
83
+ status: "Watch" | "OK" | "Failing" | "Too little data";
84
84
  }[];
85
85
  interface RoundLineInput {
86
86
  snapshot: DisplaySnapshot;