@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,13 @@
1
+ import type { ArmSlot } from '../../types/puck.js';
2
+ import type { EditorExperiment } from './editor.model.js';
3
+ import type { ArmWrites } from './VersionBuilder.js';
4
+ /** Page content stays editable even when it does not belong to the selected test. */
5
+ export declare function LeftoverVersions({ slots, experiment, writes, canManage, countBlocks, onDelete, onSelect }: {
6
+ slots: ArmSlot[];
7
+ experiment: EditorExperiment;
8
+ writes: ArmWrites;
9
+ canManage: boolean;
10
+ countBlocks: (slot: ArmSlot) => number;
11
+ onDelete: (slot: ArmSlot) => void;
12
+ onSelect: (slot: ArmSlot) => void;
13
+ }): import("react").JSX.Element;
@@ -0,0 +1,115 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useState } from 'react';
4
+ import { Button } from '../../ui/Button.js';
5
+ import { Dialog } from '../../ui/Dialog.js';
6
+ import { slotLabels } from '../copy.js';
7
+ import { editorCopy as C } from './copy.js';
8
+ import { tabsFor } from './editor.model.js';
9
+ /** Page content stays editable even when it does not belong to the selected test. */ export function LeftoverVersions({ slots, experiment, writes, canManage, countBlocks, onDelete, onSelect }) {
10
+ const [deleting, setDeleting] = useState(null);
11
+ const versions = new Intl.ListFormat('en', {
12
+ style: 'long',
13
+ type: 'conjunction'
14
+ }).format(tabsFor(experiment).map((tab)=>tab.label));
15
+ const notice = (slot)=>/*#__PURE__*/ _jsxs("div", {
16
+ children: [
17
+ /*#__PURE__*/ _jsx("p", {
18
+ children: C.orphan(slotLabels[slot], versions)
19
+ }),
20
+ /*#__PURE__*/ _jsxs("div", {
21
+ className: "xp-ui-button-group",
22
+ children: [
23
+ canManage && experiment.status === 'draft' ? /*#__PURE__*/ _jsx(Button, {
24
+ disabled: writes.busy,
25
+ onClick: async ()=>{
26
+ const saved = await writes.write((arms)=>{
27
+ if (arms.some((arm)=>arm.key === slot)) return arms;
28
+ const next = [
29
+ ...arms
30
+ ];
31
+ const holdout = next.findIndex((arm)=>arm.kind === 'holdout');
32
+ next.splice(holdout < 0 ? next.length : holdout, 0, {
33
+ key: slot,
34
+ slot,
35
+ kind: 'variant',
36
+ label: slotLabels[slot],
37
+ weight: 0
38
+ });
39
+ return next;
40
+ }, {
41
+ draftOnly: true
42
+ });
43
+ if (saved) onSelect(slot);
44
+ },
45
+ children: C.addLeftover
46
+ }) : null,
47
+ /*#__PURE__*/ _jsx(Button, {
48
+ onClick: ()=>setDeleting(slot),
49
+ children: C.deleteContent
50
+ })
51
+ ]
52
+ })
53
+ ]
54
+ }, slot);
55
+ return /*#__PURE__*/ _jsxs(_Fragment, {
56
+ children: [
57
+ slots.length > 2 ? /*#__PURE__*/ _jsxs("details", {
58
+ className: "xp-ui-banner xp-ui-banner--warning xp-slot-leftovers",
59
+ children: [
60
+ /*#__PURE__*/ _jsxs("summary", {
61
+ children: [
62
+ /*#__PURE__*/ _jsx("span", {
63
+ "aria-hidden": "true",
64
+ children: "⚠ "
65
+ }),
66
+ C.leftovers(slots.map((slot)=>slotLabels[slot]).join(', '))
67
+ ]
68
+ }),
69
+ slots.map(notice)
70
+ ]
71
+ }) : slots.map((slot)=>/*#__PURE__*/ _jsxs("div", {
72
+ className: "xp-ui-banner xp-ui-banner--warning xp-slot-leftovers",
73
+ children: [
74
+ /*#__PURE__*/ _jsx("span", {
75
+ "aria-hidden": "true",
76
+ children: "⚠"
77
+ }),
78
+ notice(slot)
79
+ ]
80
+ }, slot)),
81
+ deleting ? /*#__PURE__*/ _jsx(Dialog, {
82
+ open: true,
83
+ title: C.deleteContentTitle(slotLabels[deleting]),
84
+ initialFocus: "cancel",
85
+ onClose: ()=>setDeleting(null),
86
+ children: /*#__PURE__*/ _jsxs("div", {
87
+ className: "xp-slot-drawer",
88
+ children: [
89
+ /*#__PURE__*/ _jsx("p", {
90
+ children: C.deleteContentHelp(slotLabels[deleting], countBlocks(deleting))
91
+ }),
92
+ /*#__PURE__*/ _jsxs("div", {
93
+ className: "xp-ui-button-group",
94
+ children: [
95
+ /*#__PURE__*/ _jsx(Button, {
96
+ "data-dialog-cancel": true,
97
+ onClick: ()=>setDeleting(null),
98
+ children: C.cancel
99
+ }),
100
+ /*#__PURE__*/ _jsx(Button, {
101
+ variant: "danger",
102
+ onClick: ()=>{
103
+ onDelete(deleting);
104
+ setDeleting(null);
105
+ },
106
+ children: C.deleteContent
107
+ })
108
+ ]
109
+ })
110
+ ]
111
+ })
112
+ }) : null
113
+ ]
114
+ });
115
+ }
@@ -0,0 +1,8 @@
1
+ import type { ReadinessRead } from '../../testSurface/readinessRead.js';
2
+ /** Chrome and sidebar consume the settled read's sentence and recovery policy. */
3
+ export declare function PlacementNotice({ read, message, running, onRetry }: {
4
+ read?: ReadinessRead;
5
+ message?: string;
6
+ running: boolean;
7
+ onRetry(): void;
8
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Banner } from '../../ui/Banner.js';
4
+ import { Button } from '../../ui/Button.js';
5
+ import { editorCopy } from './copy.js';
6
+ /** Chrome and sidebar consume the settled read's sentence and recovery policy. */ export function PlacementNotice({ read, message, running, onRetry }) {
7
+ const sentence = read?.message ?? message;
8
+ return sentence ? /*#__PURE__*/ _jsxs(Banner, {
9
+ tone: running && !read?.message ? 'warning' : 'error',
10
+ action: read?.retry ? /*#__PURE__*/ _jsx(Button, {
11
+ onClick: onRetry,
12
+ children: editorCopy.retrySetup
13
+ }) : undefined,
14
+ children: [
15
+ running && !read?.message ? /*#__PURE__*/ _jsx("span", {
16
+ "aria-hidden": "true",
17
+ children: "⚠ "
18
+ }) : null,
19
+ sentence
20
+ ]
21
+ }) : null;
22
+ }
@@ -0,0 +1,3 @@
1
+ import type { SectionProps } from '../../testSurface/surface/contracts.js';
2
+ /** Same transition runner and confirmation as the drawer; Decide stays there. */
3
+ export declare function QuickTestActions({ test, surface }: SectionProps): import("react").JSX.Element | null;
@@ -0,0 +1,50 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { READINESS_COPY } from '../../testSurface/copy/readiness.js';
4
+ import { canStartTest, readyToStart } from '../../testSurface/readinessRead.js';
5
+ import { useState } from 'react';
6
+ import { Button } from '../../ui/Button.js';
7
+ import { availableActions } from '../../testSurface/actions/actions.model.js';
8
+ import { ConfirmAction } from '../../testSurface/surface/readiness/ActionDialogs.js';
9
+ import { useTransition } from '../../testSurface/surface/readiness/useTransition.js';
10
+ import { createApi } from '../../testSurface/api.js';
11
+ /** Same transition runner and confirmation as the drawer; Decide stays there. */ export function QuickTestActions({ test, surface }) {
12
+ const [confirm, setConfirm] = useState(false);
13
+ const transition = useTransition(test, undefined, surface);
14
+ const doc = test.doc;
15
+ const action = availableActions({
16
+ ...doc,
17
+ canManage: surface.canManage
18
+ }).find((item)=>doc.status === 'draft' ? item.id === 'start' : doc.status === 'running' && item.id === 'stop');
19
+ if (!action) return null;
20
+ const ready = !transition.checking && canStartTest(test, surface.editorPlacementMessage);
21
+ const showAction = action.id !== 'start' || readyToStart(test, surface.editorPlacementMessage) && !test.hasUnsaved;
22
+ return /*#__PURE__*/ _jsxs(_Fragment, {
23
+ children: [
24
+ showAction && action.id === 'start' ? /*#__PURE__*/ _jsx("p", {
25
+ role: "status",
26
+ children: READINESS_COPY.ready
27
+ }) : null,
28
+ showAction ? /*#__PURE__*/ _jsx(Button, {
29
+ disabled: transition.busy || confirm || test.hasUnsaved || action.id === 'start' && !ready,
30
+ busy: transition.busy,
31
+ onClick: ()=>{
32
+ if (action.id === 'start') void transition.run('start', ()=>createApi(surface.apiRoute).start(doc.id));
33
+ else setConfirm(true);
34
+ },
35
+ children: action.label
36
+ }) : null,
37
+ transition.error ? /*#__PURE__*/ _jsx("p", {
38
+ role: "alert",
39
+ children: transition.error
40
+ }) : null,
41
+ confirm ? /*#__PURE__*/ _jsx(ConfirmAction, {
42
+ test: test,
43
+ surface: surface,
44
+ action: action,
45
+ winnerLabel: "",
46
+ onClose: ()=>setConfirm(false)
47
+ }) : null
48
+ ]
49
+ });
50
+ }
@@ -81,6 +81,11 @@ export function ResultsReadout({ id, api, experiment }) {
81
81
  className: "xp-ui-help",
82
82
  children: C.loading
83
83
  }),
84
+ busy && data ? /*#__PURE__*/ _jsx("p", {
85
+ role: "status",
86
+ className: "xp-ui-help",
87
+ children: C.refreshing
88
+ }) : null,
84
89
  /*#__PURE__*/ _jsx(Button, {
85
90
  variant: "quiet",
86
91
  size: "sm",
@@ -1,8 +1,11 @@
1
- import type { Arm } from '../../types/contracts.js';
1
+ import { type ReactNode, type RefObject } from 'react';
2
+ import type { Arm, ArmKey } from '../../types/contracts.js';
2
3
  import type { ArmSlot } from '../../types/puck.js';
3
4
  import type { EditorExperiment } from './editor.model.js';
4
- export declare function useArmWrites(url: string, publish: (doc: EditorExperiment) => void, isCurrent: () => boolean, onWrite: () => void): {
5
- write: (transform: (arms: Arm[]) => Arm[]) => Promise<Arm[] | undefined>;
5
+ export declare function useArmWrites(url: string, publish: (doc: EditorExperiment) => void, isCurrent: () => boolean, onWrite: () => void, onSaved?: () => void): {
6
+ write: (transform: (arms: Arm[]) => Arm[], options?: {
7
+ draftOnly?: boolean;
8
+ }) => Promise<Arm[] | undefined>;
6
9
  busy: boolean;
7
10
  error: string | null;
8
11
  };
@@ -12,23 +15,34 @@ export declare function AddVariant({ experiment, writes, onSelect }: {
12
15
  writes: ArmWrites;
13
16
  onSelect: (slot: ArmSlot) => void;
14
17
  }): import("react").JSX.Element | null;
15
- export declare function VersionActions({ arm, writes, editable, open, onOpenChange, canCopy, onCopy, onRequestRemove }: {
18
+ export declare function VersionActions({ arm, writes, editable, running, open, onOpenChange, canCopy, onCopy, onRequestRemove }: {
16
19
  arm: EditorExperiment['arms'][number];
17
20
  writes: ArmWrites;
18
21
  editable: boolean;
22
+ running?: boolean;
19
23
  open: boolean;
20
24
  onOpenChange: (open: boolean) => void;
21
25
  canCopy: boolean;
22
26
  onCopy: (slot: ArmSlot) => void;
23
27
  onRequestRemove: () => void;
24
28
  }): import("react").JSX.Element;
25
- export declare function RemoveVersion({ arm, writes, onRemove, onClose }: {
29
+ export declare function RemoveVersion({ arm, writes, count, shared, onRemove, onClose }: {
26
30
  arm: EditorExperiment['arms'][number];
27
31
  writes: ArmWrites;
32
+ count: number;
33
+ shared: boolean | undefined;
28
34
  onRemove: (slot: ArmSlot) => void;
29
35
  onClose: () => void;
30
36
  }): import("react").JSX.Element;
31
- export declare function VersionWeights({ experiment, writes }: {
37
+ export type WeightEdits = Partial<Record<ArmKey, string>>;
38
+ export declare function VersionWeights({ experiment, writes, edits, setEdits, groupId, splitIntent, editable, beforeSplit, actions }: {
32
39
  experiment: EditorExperiment;
33
40
  writes: ArmWrites;
41
+ edits: WeightEdits;
42
+ setEdits: (edits: WeightEdits) => void;
43
+ groupId: string;
44
+ splitIntent: RefObject<boolean>;
45
+ editable?: boolean;
46
+ beforeSplit?: ReactNode;
47
+ actions?: (arm: EditorExperiment['arms'][number]) => ReactNode;
34
48
  }): import("react").JSX.Element;
@@ -9,18 +9,20 @@ import { Dialog } from '../../ui/Dialog.js';
9
9
  import { NumberInput, TextInput } from '../../ui/Inputs.js';
10
10
  import { ArmWriteError, writeArms } from './armWrites.js';
11
11
  import { editorCopy as C } from './copy.js';
12
- export function useArmWrites(url, publish, isCurrent, onWrite) {
12
+ export function useArmWrites(url, publish, isCurrent, onWrite, onSaved) {
13
13
  const guard = useRef(false);
14
14
  const [busy, setBusy] = useState(false);
15
15
  const [error, setError] = useState(null);
16
- async function write(transform) {
16
+ async function write(transform, options) {
17
17
  if (guard.current) return;
18
18
  guard.current = true;
19
19
  onWrite();
20
20
  setBusy(true);
21
21
  setError(null);
22
22
  try {
23
- return await writeArms(url, transform, publish);
23
+ const saved = await writeArms(url, transform, publish, options);
24
+ onSaved?.();
25
+ return saved;
24
26
  } catch (error) {
25
27
  if (isCurrent()) setError(error instanceof ArmWriteError ? error.message : C.writeNetwork);
26
28
  } finally{
@@ -50,7 +52,7 @@ export function AddVariant({ experiment, writes, onSelect }) {
50
52
  children: C.add
51
53
  });
52
54
  }
53
- export function VersionActions({ arm, writes, editable, open, onOpenChange, canCopy, onCopy, onRequestRemove }) {
55
+ export function VersionActions({ arm, writes, editable, running = false, open, onOpenChange, canCopy, onCopy, onRequestRemove }) {
54
56
  const id = useId();
55
57
  const [name, setName] = useState(null);
56
58
  const [invalid, setInvalid] = useState(false);
@@ -125,7 +127,7 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
125
127
  /*#__PURE__*/ _jsxs("div", {
126
128
  className: "xp-slot-version-anchor",
127
129
  children: [
128
- editable || arm.kind !== 'control' ? /*#__PURE__*/ _jsx(Button, {
130
+ editable || arm.kind !== 'control' ? /*#__PURE__*/ _jsxs(Button, {
129
131
  size: "sm",
130
132
  variant: "quiet",
131
133
  "aria-label": C.menu(arm.label),
@@ -133,7 +135,10 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
133
135
  "aria-controls": `${id}-menu`,
134
136
  disabled: writes.busy,
135
137
  onClick: ()=>onOpenChange(!open),
136
- children: "⋯"
138
+ children: [
139
+ C.options,
140
+ " ▾"
141
+ ]
137
142
  }) : null,
138
143
  open ? /*#__PURE__*/ _jsxs("div", {
139
144
  id: `${id}-menu`,
@@ -152,7 +157,7 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
152
157
  },
153
158
  children: C.rename
154
159
  }) : null,
155
- arm.kind !== 'control' ? /*#__PURE__*/ _jsxs(_Fragment, {
160
+ arm.kind === 'variant' ? /*#__PURE__*/ _jsxs(_Fragment, {
156
161
  children: [
157
162
  /*#__PURE__*/ _jsx(Button, {
158
163
  variant: "quiet",
@@ -164,16 +169,24 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
164
169
  },
165
170
  children: C.copy
166
171
  }),
167
- editable ? /*#__PURE__*/ _jsx(Button, {
168
- variant: "quiet",
169
- size: "sm",
170
- onClick: ()=>{
171
- closeMenu();
172
- onRequestRemove();
173
- },
174
- children: C.remove
172
+ !canCopy ? /*#__PURE__*/ _jsx("p", {
173
+ className: "xp-ui-help",
174
+ children: C.copyEmpty
175
175
  }) : null
176
176
  ]
177
+ }) : null,
178
+ arm.kind !== 'control' && editable ? /*#__PURE__*/ _jsx(Button, {
179
+ variant: "quiet",
180
+ size: "sm",
181
+ onClick: ()=>{
182
+ closeMenu();
183
+ onRequestRemove();
184
+ },
185
+ children: C.removeVersion
186
+ }) : null,
187
+ running ? /*#__PURE__*/ _jsx("p", {
188
+ className: "xp-ui-help",
189
+ children: C.runningVersions
177
190
  }) : null
178
191
  ]
179
192
  }) : null
@@ -203,8 +216,8 @@ export function VersionActions({ arm, writes, editable, open, onOpenChange, canC
203
216
  ]
204
217
  });
205
218
  }
206
- export function RemoveVersion({ arm, writes, onRemove, onClose }) {
207
- const slot = arm.key;
219
+ export function RemoveVersion({ arm, writes, count, shared, onRemove, onClose }) {
220
+ const slot = arm.key === 'holdout' ? undefined : arm.key;
208
221
  const [tried, setTried] = useState(false);
209
222
  return /*#__PURE__*/ _jsx(Dialog, {
210
223
  open: true,
@@ -216,8 +229,13 @@ export function RemoveVersion({ arm, writes, onRemove, onClose }) {
216
229
  className: "xp-slot-drawer",
217
230
  children: [
218
231
  /*#__PURE__*/ _jsx("p", {
219
- children: C.removeHelp
232
+ children: C.removeHelp(count)
220
233
  }),
234
+ shared === undefined ? /*#__PURE__*/ _jsx("p", {
235
+ children: C.removeScopeUnknown
236
+ }) : shared ? /*#__PURE__*/ _jsx("p", {
237
+ children: C.removeShared
238
+ }) : null,
221
239
  tried && writes.error ? /*#__PURE__*/ _jsx("p", {
222
240
  role: "alert",
223
241
  className: "xp-ui-error",
@@ -239,7 +257,7 @@ export function RemoveVersion({ arm, writes, onRemove, onClose }) {
239
257
  setTried(true);
240
258
  const saved = await writes.write((arms)=>splitEvenly(removeArm(arms, arm.key)));
241
259
  if (saved) {
242
- onRemove(slot);
260
+ if (slot) onRemove(slot);
243
261
  onClose();
244
262
  }
245
263
  },
@@ -251,10 +269,9 @@ export function RemoveVersion({ arm, writes, onRemove, onClose }) {
251
269
  })
252
270
  });
253
271
  }
254
- export function VersionWeights({ experiment, writes }) {
272
+ export function VersionWeights({ experiment, writes, edits, setEdits, groupId, splitIntent, editable = true, beforeSplit, actions }) {
255
273
  const id = useId();
256
274
  const split = useRef(null);
257
- const [edits, setEdits] = useState({});
258
275
  const invalidKeys = new Set(Object.entries(edits).filter(([, raw])=>raw.trim() === '' || !Number.isInteger(Number(raw)) || Number(raw) < 0 || Number(raw) > 100).map(([key])=>key));
259
276
  const apply = (arms)=>arms.reduce((next, arm)=>edits[arm.key] === undefined ? next : (()=>{
260
277
  const value = edits[arm.key].trim() === '' ? NaN : Number(edits[arm.key]);
@@ -264,35 +281,41 @@ export function VersionWeights({ experiment, writes }) {
264
281
  const issues = checkArms(live, 'block');
265
282
  async function commit() {
266
283
  if (!Object.keys(edits).length || invalidKeys.size || issues.length) return;
267
- const saved = await writes.write(apply);
268
- if (saved) setEdits({});
284
+ await writes.write(apply);
269
285
  }
270
286
  return /*#__PURE__*/ _jsxs("div", {
271
287
  className: "xp-slot-weights",
272
288
  children: [
273
289
  /*#__PURE__*/ _jsx("div", {
274
290
  className: "xp-slot-weight-inputs",
275
- children: experiment.arms.map((arm)=>/*#__PURE__*/ _jsx(NumberInput, {
276
- id: `${id}-${arm.key}`,
277
- label: C.weight(arm.label),
278
- min: 0,
279
- max: 100,
280
- step: 1,
281
- value: edits[arm.key] ?? live.find((current)=>current.key === arm.key)?.weight ?? '',
282
- disabled: writes.busy,
283
- error: invalidKeys.has(arm.key) ? C.invalidShare : undefined,
284
- onChange: (event)=>setEdits({
285
- [arm.key]: event.target.value
291
+ children: experiment.arms.map((arm)=>/*#__PURE__*/ _jsxs("div", {
292
+ className: "xp-slot-weight-row",
293
+ children: [
294
+ /*#__PURE__*/ _jsx(NumberInput, {
295
+ id: `${id}-${arm.key}`,
296
+ label: C.weight(arm.label),
297
+ min: 0,
298
+ max: 100,
299
+ step: 1,
300
+ value: edits[arm.key] ?? live.find((current)=>current.key === arm.key)?.weight ?? '',
301
+ disabled: writes.busy || !editable,
302
+ error: invalidKeys.has(arm.key) ? C.invalidShare : undefined,
303
+ onChange: (event)=>setEdits({
304
+ [arm.key]: event.target.value
305
+ }),
306
+ onBlur: (event)=>{
307
+ const target = event.relatedTarget;
308
+ if (!splitIntent.current && !(typeof target?.closest === 'function' && target.closest('[data-xp-split]')?.getAttribute('data-xp-split') === groupId)) void commit();
309
+ },
310
+ onKeyDown: (event)=>{
311
+ if (event.key === 'Enter') {
312
+ event.preventDefault();
313
+ void commit();
314
+ }
315
+ }
286
316
  }),
287
- onBlur: (event)=>{
288
- if (!split.current?.contains(event.relatedTarget)) void commit();
289
- },
290
- onKeyDown: (event)=>{
291
- if (event.key === 'Enter') {
292
- event.preventDefault();
293
- void commit();
294
- }
295
- }
317
+ actions?.(arm)
318
+ ]
296
319
  }, arm.key))
297
320
  }),
298
321
  Object.keys(edits).length && !invalidKeys.size ? issues.map((issue, i)=>/*#__PURE__*/ _jsx("p", {
@@ -300,18 +323,25 @@ export function VersionWeights({ experiment, writes }) {
300
323
  className: "xp-ui-error",
301
324
  children: issueMessage(issue, totalWeight(live))
302
325
  }, i)) : null,
303
- /*#__PURE__*/ _jsx("div", {
326
+ beforeSplit,
327
+ editable ? /*#__PURE__*/ _jsx("div", {
304
328
  ref: split,
329
+ "data-xp-split": groupId,
330
+ onPointerDownCapture: ()=>{
331
+ // Pointer intent reaches the destination before the source iframe loses focus.
332
+ splitIntent.current = true;
333
+ setTimeout(()=>{
334
+ splitIntent.current = false;
335
+ }, 0);
336
+ },
305
337
  children: /*#__PURE__*/ _jsx(Button, {
306
338
  variant: "quiet",
307
339
  size: "sm",
308
340
  disabled: writes.busy,
309
- onClick: async ()=>{
310
- if (await writes.write(splitEvenly)) setEdits({});
311
- },
341
+ onClick: ()=>void writes.write(splitEvenly),
312
342
  children: C.split
313
343
  })
314
- })
344
+ }) : null
315
345
  ]
316
346
  });
317
347
  }
@@ -4,4 +4,6 @@ export declare class ArmWriteError extends Error {
4
4
  }
5
5
  export declare function readExperiment(url: string, signal?: AbortSignal): Promise<EditorExperiment>;
6
6
  /** Each intent is applied to a fresh document, guarded by the collection's compare-and-set header. */
7
- export declare function writeArms(url: string, transform: (arms: Arm[]) => Arm[], publish: (doc: EditorExperiment) => void): Promise<Arm[]>;
7
+ export declare function writeArms(url: string, transform: (arms: Arm[]) => Arm[], publish: (doc: EditorExperiment) => void, { draftOnly }?: {
8
+ draftOnly?: boolean;
9
+ }): Promise<Arm[]>;
@@ -31,9 +31,10 @@ export async function readExperiment(url, signal) {
31
31
  ].includes(value.status)) throw new ArmWriteError(editorCopy.lockedGeneric);
32
32
  return value;
33
33
  }
34
- /** Each intent is applied to a fresh document, guarded by the collection's compare-and-set header. */ export async function writeArms(url, transform, publish) {
34
+ /** Each intent is applied to a fresh document, guarded by the collection's compare-and-set header. */ export async function writeArms(url, transform, publish, { draftOnly = false } = {}) {
35
35
  const fresh = await readExperiment(`${url}?depth=0`);
36
36
  publish(fresh);
37
+ if (draftOnly && fresh.status !== 'draft') throw new ArmWriteError(editorCopy.draftOnly);
37
38
  if (fresh.status !== 'draft' && fresh.status !== 'stopped') throw new ArmWriteError(editorCopy.locked[fresh.status]);
38
39
  if (!fresh.updatedAt || !Array.isArray(fresh.arms)) throw new ArmWriteError(editorCopy.writeUnreadable);
39
40
  const arms = withSlotsFor(transform(fresh.arms), 'block');
@@ -1,3 +1,5 @@
1
1
  import type { Slot } from '../../types/puck.js';
2
2
  /** Clone JSON Puck slot data, refreshing component ids even inside nested slots. */
3
3
  export declare function cloneSlot(slot: Slot): Slot;
4
+ /** Count the Puck blocks that will be removed, including nested version content. */
5
+ export declare function countSlotBlocks(value: unknown): number;
@@ -39,3 +39,10 @@ function freshId(type, used) {
39
39
  }
40
40
  return clone(slot);
41
41
  }
42
+ /** Count the Puck blocks that will be removed, including nested version content. */ export function countSlotBlocks(value) {
43
+ if (!value || typeof value !== 'object') return 0;
44
+ if (Array.isArray(value)) return value.reduce((total, item)=>total + countSlotBlocks(item), 0);
45
+ const node = value;
46
+ const own = typeof node.type === 'string' && node.props && typeof node.props === 'object' ? 1 : 0;
47
+ return own + Object.values(node).reduce((total, item)=>total + countSlotBlocks(item), 0);
48
+ }
@@ -22,6 +22,10 @@ export declare const editorCopy: {
22
22
  readonly decided: (winner: string) => string;
23
23
  readonly archived: "This test is archived; the winning content is shown to everyone.";
24
24
  readonly copy: "Copy Original here";
25
+ readonly copyEmpty: "Add content to the Original before copying it.";
26
+ readonly enterName: "Enter a name to create the test.";
27
+ readonly loadingBeforeNew: "Wait for this test to load before starting a new one.";
28
+ readonly checkingRemoval: "Checking whether this test can be removed…";
25
29
  readonly dropZone: (slot: "control" | "variantA" | "variantB" | "variantC") => string;
26
30
  readonly replaceConfirm: (label: string) => string;
27
31
  readonly replace: "Replace";
@@ -40,18 +44,35 @@ export declare const editorCopy: {
40
44
  readonly openTest: "Open the test";
41
45
  readonly nameExists: "This name is too close to an existing test. Choose a different name.";
42
46
  readonly createError: "Couldn't create the test. Try again.";
47
+ readonly savingVersions: "Saving version changes…";
48
+ readonly refreshing: "Refreshing results…";
43
49
  readonly loading: "Loading test…";
44
50
  readonly loadError: "Couldn't load this test. Try selecting it again.";
45
- readonly orphan: (label: string) => string;
51
+ readonly orphan: (label: string, versions: string) => string;
52
+ readonly addLeftover: "Add to the test";
53
+ readonly deleteContent: "Delete its content";
54
+ readonly deleteContentTitle: (label: string) => string;
55
+ readonly deleteContentHelp: (label: string, count: number) => string;
56
+ readonly draftOnly: "Only draft tests can add this version. Start a new test from this block to include it.";
57
+ readonly leftovers: (labels: string) => string;
58
+ readonly outsideTest: (label: string) => string;
46
59
  readonly tabs: "Test versions";
47
60
  readonly add: "Add variant";
48
61
  readonly menu: (label: string) => string;
62
+ readonly testGroup: "Test";
63
+ readonly versionsGroup: "Versions";
64
+ readonly actionsGroup: "Actions";
65
+ readonly options: "Options";
66
+ readonly runningVersions: "Versions can't change while the test runs.";
67
+ readonly removeVersion: "Remove version";
49
68
  readonly rename: "Rename";
50
69
  readonly renameLabel: "Version name";
51
70
  readonly emptyLabel: "Enter a name for this version.";
52
71
  readonly remove: "Remove";
53
72
  readonly removeTitle: (label: string) => string;
54
- readonly removeHelp: "This removes the version from the test and clears its content from this page.";
73
+ readonly removeHelp: (count: number) => string;
74
+ readonly removeShared: "This test is also used in another place. The version is removed from the test there too.";
75
+ readonly removeScopeUnknown: "If this test is used on other pages, the version is removed from the test there too.";
55
76
  readonly removed: "Save the page to finish removing this version's content.";
56
77
  readonly removeUncleared: "The version was removed from the test, but its content couldn't be cleared here. Delete it from the outline, then save the page.";
57
78
  readonly lockedGeneric: "This test's versions can't change. View the test page for details.";
@@ -69,7 +90,7 @@ export declare const editorCopy: {
69
90
  readonly writeNetwork: "Couldn't reach the server. Check your connection and try again.";
70
91
  readonly writeUnreadable: "Couldn't read the server's response. Reload and try again.";
71
92
  readonly collecting: "Collecting";
72
- readonly resultsUnavailable: "Results aren't available here.";
93
+ readonly resultsUnavailable: "Results aren't available here. Try Refresh.";
73
94
  readonly refresh: "Refresh";
74
95
  readonly people: (label: string, count: string) => string;
75
96
  };