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

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 (164) hide show
  1. package/dist/admin/blocks/BlockPanel.js +6 -4
  2. package/dist/admin/blocks/inject.js +1 -0
  3. package/dist/admin/blocks/model.d.ts +3 -2
  4. package/dist/admin/blocks/model.js +8 -4
  5. package/dist/admin/copy/blocks.d.ts +3 -2
  6. package/dist/admin/copy/blocks.js +7 -6
  7. package/dist/admin/copy/newTest.d.ts +1 -1
  8. package/dist/admin/copy/newTest.js +1 -1
  9. package/dist/admin/surface/ResultsRoute.js +2 -1
  10. package/dist/admin/surface/TestsHome.d.ts +2 -1
  11. package/dist/admin/surface/TestsHome.js +91 -37
  12. package/dist/admin/surface/TestsSurface.js +3 -0
  13. package/dist/admin/surface/home.model.d.ts +2 -0
  14. package/dist/admin/surface/newTest/NewTest.js +16 -18
  15. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  16. package/dist/admin/surface/newTest/newTest.css +3 -1
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +8 -14
  21. package/dist/blocks/placementLanguages.d.ts +7 -0
  22. package/dist/blocks/placementLanguages.js +27 -0
  23. package/dist/blocks/placementLocale.d.ts +23 -7
  24. package/dist/blocks/placementLocale.js +221 -66
  25. package/dist/db/appends.d.ts +13 -0
  26. package/dist/db/appends.js +49 -0
  27. package/dist/db/bulkPlacementRemoval.js +8 -4
  28. package/dist/endpoints/contentLocale.d.ts +6 -0
  29. package/dist/endpoints/contentLocale.js +15 -0
  30. package/dist/endpoints/deleteImpact.d.ts +6 -0
  31. package/dist/endpoints/deleteImpact.js +206 -0
  32. package/dist/endpoints/index.js +7 -0
  33. package/dist/endpoints/pages.js +7 -3
  34. package/dist/endpoints/placementStatus.js +6 -1
  35. package/dist/endpoints/preflight.d.ts +1 -1
  36. package/dist/endpoints/preflight.js +17 -2
  37. package/dist/exports/adminClient.d.ts +1 -1
  38. package/dist/exports/adminClient.js +1 -1
  39. package/dist/exports/index.d.ts +1 -1
  40. package/dist/goals/fairness.js +43 -34
  41. package/dist/hooks/blockRemovalRule.d.ts +4 -3
  42. package/dist/hooks/blockRemovalRule.js +33 -9
  43. package/dist/hooks/pageGuard.d.ts +3 -0
  44. package/dist/hooks/pageGuard.js +34 -24
  45. package/dist/hooks/puckNestedTests.d.ts +8 -0
  46. package/dist/hooks/puckNestedTests.js +36 -0
  47. package/dist/lib/placementPages.d.ts +2 -1
  48. package/dist/lib/placementPages.js +10 -2
  49. package/dist/manifest/compile.d.ts +2 -1
  50. package/dist/manifest/compile.js +5 -1
  51. package/dist/puck/ExperimentPicker.d.ts +2 -1
  52. package/dist/puck/ExperimentPicker.js +37 -30
  53. package/dist/puck/ExperimentSlot.js +3 -1
  54. package/dist/puck/copy.d.ts +1 -0
  55. package/dist/puck/copy.js +1 -0
  56. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  57. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  58. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  59. package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
  60. package/dist/puck/editor/EditorControls.d.ts +1 -1
  61. package/dist/puck/editor/EditorControls.js +1 -1
  62. package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
  63. package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
  64. package/dist/puck/editor/LeftoverVersions.js +23 -44
  65. package/dist/puck/editor/QuickTestActions.js +2 -2
  66. package/dist/puck/editor/VersionBuilder.d.ts +41 -13
  67. package/dist/puck/editor/VersionBuilder.js +461 -224
  68. package/dist/puck/editor/armWrites.d.ts +9 -2
  69. package/dist/puck/editor/armWrites.js +40 -2
  70. package/dist/puck/editor/armsCache.d.ts +1 -1
  71. package/dist/puck/editor/armsCache.js +2 -1
  72. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  73. package/dist/puck/editor/blockClipboard.js +20 -0
  74. package/dist/puck/editor/copy.d.ts +27 -26
  75. package/dist/puck/editor/copy.js +28 -26
  76. package/dist/puck/editor/createTest.d.ts +3 -0
  77. package/dist/puck/editor/createTest.js +33 -0
  78. package/dist/puck/editor/editor.chrome.css +138 -17
  79. package/dist/puck/editor/editor.css +156 -22
  80. package/dist/puck/editor/editor.model.d.ts +2 -1
  81. package/dist/puck/editor/editor.model.js +3 -3
  82. package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
  83. package/dist/puck/editor/localPlacements.d.ts +5 -2
  84. package/dist/puck/editor/localPlacements.js +32 -18
  85. package/dist/puck/editor/placementsCache.d.ts +18 -12
  86. package/dist/puck/editor/placementsCache.js +52 -47
  87. package/dist/puck/editor/sidebar.d.ts +2 -6
  88. package/dist/puck/editor/sidebar.js +3 -6
  89. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  90. package/dist/puck/editor/usePlacementNotice.js +4 -3
  91. package/dist/puck/experimentSlug.d.ts +2 -0
  92. package/dist/puck/experimentSlug.js +3 -0
  93. package/dist/puck/nestedTestCopy.d.ts +8 -0
  94. package/dist/puck/nestedTestCopy.js +22 -0
  95. package/dist/puck/nestedTests.d.ts +17 -0
  96. package/dist/puck/nestedTests.js +30 -0
  97. package/dist/puck/slotConfig.d.ts +1 -1
  98. package/dist/puck/slotConfig.js +17 -4
  99. package/dist/puck/visibility.d.ts +20 -0
  100. package/dist/puck/visibility.js +81 -0
  101. package/dist/server/recordContentChange.js +37 -20
  102. package/dist/server/resolveExperimentData.js +6 -3
  103. package/dist/testSurface/PreviewLinks.js +6 -2
  104. package/dist/testSurface/api.d.ts +6 -3
  105. package/dist/testSurface/api.js +10 -6
  106. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  107. package/dist/testSurface/contentLocaleURL.js +3 -0
  108. package/dist/testSurface/copy/common.d.ts +4 -0
  109. package/dist/testSurface/copy/common.js +8 -4
  110. package/dist/testSurface/copy/languages.d.ts +11 -0
  111. package/dist/testSurface/copy/languages.js +7 -0
  112. package/dist/testSurface/copy/readiness.d.ts +2 -1
  113. package/dist/testSurface/copy/readiness.js +2 -1
  114. package/dist/testSurface/copy/testPage.d.ts +28 -6
  115. package/dist/testSurface/copy/testPage.js +28 -6
  116. package/dist/testSurface/placementLabel.d.ts +8 -0
  117. package/dist/testSurface/placementLabel.js +24 -0
  118. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  119. package/dist/testSurface/placements/placementLabels.js +2 -1
  120. package/dist/testSurface/results/results.css +1 -1
  121. package/dist/testSurface/results/results.model.d.ts +1 -1
  122. package/dist/testSurface/surface/contracts.d.ts +2 -0
  123. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  124. package/dist/testSurface/surface/editorPlacement.js +18 -0
  125. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  126. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  127. package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
  128. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  129. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  130. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  131. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  132. package/dist/testSurface/surface/test/GoalSection.js +101 -74
  133. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  134. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  135. package/dist/testSurface/surface/test/fields.js +5 -35
  136. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  137. package/dist/testSurface/surface/useTestDocument.js +20 -4
  138. package/dist/testSurface/useApi.d.ts +4 -1
  139. package/dist/transitions/checkStart.d.ts +4 -1
  140. package/dist/transitions/checkStart.js +117 -14
  141. package/dist/transitions/contentFields.js +9 -5
  142. package/dist/transitions/makeContent.js +29 -9
  143. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  144. package/dist/transitions/nestedPlacementNames.js +33 -0
  145. package/dist/transitions/pageVersions.js +3 -1
  146. package/dist/transitions/placementInteractions.js +7 -4
  147. package/dist/transitions/placements.d.ts +26 -1
  148. package/dist/transitions/placements.js +239 -87
  149. package/dist/transitions/preflightData.d.ts +2 -1
  150. package/dist/transitions/preflightData.js +66 -3
  151. package/dist/transitions/start.js +4 -1
  152. package/dist/types/endpoints.d.ts +35 -1
  153. package/dist/types/endpoints.js +1 -1
  154. package/dist/types/puck.d.ts +1 -0
  155. package/dist/types/surface.d.ts +2 -0
  156. package/dist/ui/Button.js +2 -2
  157. package/dist/ui/Inputs.d.ts +4 -3
  158. package/dist/ui/Inputs.js +7 -4
  159. package/dist/ui/SelectControl.d.ts +33 -0
  160. package/dist/ui/SelectControl.js +504 -0
  161. package/dist/ui/Tabs.d.ts +0 -1
  162. package/dist/ui/Tabs.js +28 -40
  163. package/dist/ui/ui.css +18 -5
  164. package/package.json +3 -2
@@ -0,0 +1,504 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Children, isValidElement, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { INPUT_COPY } from '../testSurface/copy/common.js';
6
+ function optionText(children) {
7
+ return Children.toArray(children).map((child)=>/*#__PURE__*/ isValidElement(child) ? optionText(child.props.children) : String(child)).join('');
8
+ }
9
+ /** Keep existing option/optgroup callers while giving new callers a plain options API. */ function childOptions(children, group, disabled = false) {
10
+ return Children.toArray(children).flatMap((child)=>{
11
+ if (!/*#__PURE__*/ isValidElement(child)) return [];
12
+ const p = child.props;
13
+ if (child.type === 'option') return [
14
+ {
15
+ value: String(p.value ?? optionText(p.children)),
16
+ label: p.label ?? optionText(p.children),
17
+ disabled: disabled || p.disabled,
18
+ group
19
+ }
20
+ ];
21
+ return childOptions(p.children, child.type === 'optgroup' ? p.label : group, disabled || Boolean(p.disabled));
22
+ });
23
+ }
24
+ /** Select-only combobox: DOM focus stays on the button while active-descendant
25
+ * focus explores the list. The manual popover lives in the trigger's document
26
+ * and inherits its theme; the browser's top layer escapes scroll/iframe drawers.
27
+ */ export function SelectControl({ id, value, defaultValue, options: supplied, children, onChange, name, form, required, disabled, className = '', onKeyDown, onBlur, ...props }) {
28
+ const options = useMemo(()=>supplied ?? childOptions(children), [
29
+ supplied,
30
+ children
31
+ ]);
32
+ // Derive the native-select default until a value has actually been chosen;
33
+ // asynchronously loaded options then supply the first value too.
34
+ const [local, setLocal] = useState(defaultValue === undefined ? undefined : String(defaultValue));
35
+ const selected = String(value ?? local ?? options[0]?.value ?? '');
36
+ const [open, setOpen] = useState(false);
37
+ const [requiredInvalid, setRequiredInvalid] = useState(false);
38
+ const missingRequired = requiredInvalid && required && !selected;
39
+ const [active, setActive] = useState(-1);
40
+ const trigger = useRef(null);
41
+ const popup = useRef(null);
42
+ const [portalHost, setPortalHost] = useState(null);
43
+ const keyboardActive = useRef(false);
44
+ const typed = useRef({
45
+ text: '',
46
+ at: 0
47
+ });
48
+ const enabled = options.flatMap((option, index)=>option.disabled ? [] : [
49
+ index
50
+ ]);
51
+ const groups = [];
52
+ options.forEach((option, index)=>{
53
+ const last = groups.at(-1);
54
+ if (last && last.label === option.group) last.options.push(option);
55
+ else groups.push({
56
+ label: option.group,
57
+ start: index,
58
+ options: [
59
+ option
60
+ ]
61
+ });
62
+ });
63
+ const selectedIndex = options.findIndex((option)=>option.value === selected);
64
+ const current = enabled.includes(active) ? active : enabled.includes(selectedIndex) ? selectedIndex : enabled[0] ?? -1;
65
+ const listId = `${id}-listbox`;
66
+ const optionId = (index)=>`${id}-option-${index}`;
67
+ function begin(index = enabled.includes(selectedIndex) ? selectedIndex : enabled[0] ?? -1, keyboard = false) {
68
+ if (disabled) return;
69
+ keyboardActive.current = keyboard;
70
+ typed.current = {
71
+ text: '',
72
+ at: 0
73
+ };
74
+ setActive(index);
75
+ setOpen(true);
76
+ }
77
+ function commit(index = current) {
78
+ if (disabled || !options[index] || options[index].disabled) {
79
+ setOpen(false);
80
+ return;
81
+ }
82
+ const next = options[index].value;
83
+ setLocal(next);
84
+ if (next) setRequiredInvalid(false);
85
+ const target = {
86
+ value: next,
87
+ name
88
+ };
89
+ if (next !== selected) onChange?.({
90
+ target,
91
+ currentTarget: target
92
+ });
93
+ setOpen(false);
94
+ }
95
+ function leave() {
96
+ if (keyboardActive.current) commit();
97
+ else setOpen(false);
98
+ }
99
+ useLayoutEffect(()=>{
100
+ const node = trigger.current, menu = popup.current;
101
+ if (!open || !node || !menu || disabled) return;
102
+ const win = node.ownerDocument.defaultView;
103
+ if (!win) return;
104
+ const topLayer = typeof menu.showPopover === 'function';
105
+ // Without popovers, escape transformed/scrolling content through a portal.
106
+ // Keep it in the nearest native modal: a body portal would be inert and
107
+ // painted below that modal. Our Dialog/Drawer root has no transform.
108
+ const host = topLayer ? null : node.closest('dialog[open]') ?? node.ownerDocument.body;
109
+ if (host !== portalHost) {
110
+ setPortalHost(host);
111
+ return;
112
+ }
113
+ let style = win.getComputedStyle(node);
114
+ const copied = new Set();
115
+ const clearTheme = ()=>{
116
+ for (const property of copied)menu.style.removeProperty(property);
117
+ copied.clear();
118
+ menu.style.removeProperty('direction');
119
+ };
120
+ const copyTheme = ()=>{
121
+ style = win.getComputedStyle(node);
122
+ clearTheme();
123
+ // Portals lose inherited tokens. Refresh from the control whenever an
124
+ // ancestor changes theme; remove tokens absent from the new theme too.
125
+ for (const property of Array.from(style))if (property.startsWith('--xp-')) {
126
+ menu.style.setProperty(property, style.getPropertyValue(property));
127
+ copied.add(property);
128
+ }
129
+ menu.style.direction = style.direction;
130
+ };
131
+ if (host) {
132
+ copyTheme();
133
+ menu.style.display = 'block';
134
+ }
135
+ const position = ()=>{
136
+ const rect = node.getBoundingClientRect();
137
+ const viewport = win.visualViewport;
138
+ const left = viewport?.offsetLeft ?? 0, top = viewport?.offsetTop ?? 0;
139
+ const width = viewport?.width ?? win.innerWidth, height = viewport?.height ?? win.innerHeight;
140
+ let clipTop = top, clipBottom = top + height, clipLeft = left, clipRight = left + width;
141
+ for(let parent = node.parentElement; parent && parent !== node.ownerDocument.body; parent = parent.parentElement){
142
+ const css = win.getComputedStyle(parent);
143
+ const bounds = parent.getBoundingClientRect();
144
+ if (/(auto|scroll|hidden|clip)/.test(`${css.overflow} ${css.overflowY}`)) {
145
+ clipTop = Math.max(clipTop, bounds.top);
146
+ clipBottom = Math.min(clipBottom, bounds.bottom);
147
+ }
148
+ if (/(auto|scroll|hidden|clip)/.test(`${css.overflow} ${css.overflowX}`)) {
149
+ clipLeft = Math.max(clipLeft, bounds.left);
150
+ clipRight = Math.min(clipRight, bounds.right);
151
+ }
152
+ }
153
+ if ((rect.width || rect.height) && (rect.bottom <= clipTop || rect.top >= clipBottom || rect.right <= clipLeft || rect.left >= clipRight)) {
154
+ setOpen(false);
155
+ return;
156
+ }
157
+ const minLeft = left + 8, maxRight = left + width - 8;
158
+ const limit = Math.max(0, maxRight - minLeft);
159
+ menu.style.width = 'max-content';
160
+ menu.style.maxWidth = `${limit}px`;
161
+ const menuStyle = win.getComputedStyle(menu);
162
+ const borders = (parseFloat(menuStyle.borderLeftWidth) || 0) + (parseFloat(menuStyle.borderRightWidth) || 0);
163
+ const menuWidth = Math.min(Math.max(rect.width, menu.scrollWidth + borders), limit);
164
+ const below = Math.max(0, top + height - rect.bottom - 8);
165
+ const above = Math.max(0, rect.top - top - 8);
166
+ const menuHeight = Math.min(menu.scrollHeight || 280, 280);
167
+ const flip = below < menuHeight && above > below;
168
+ const rtl = style.direction === 'rtl';
169
+ let x = rtl ? rect.right - menuWidth : rect.left;
170
+ // Prefer logical start, then logical end, then clamp to the viewport.
171
+ if (x < minLeft || x + menuWidth > maxRight) x = rtl ? rect.left : rect.right - menuWidth;
172
+ x = Math.max(minLeft, Math.min(x, maxRight - menuWidth));
173
+ const available = flip ? above : below;
174
+ Object.assign(menu.style, {
175
+ width: `${menuWidth}px`,
176
+ left: `${x}px`,
177
+ top: `${flip ? rect.top - Math.min(menuHeight, available) - 4 : rect.bottom + 4}px`,
178
+ bottom: 'auto',
179
+ maxHeight: `${Math.min(280, available)}px`
180
+ });
181
+ menu.dataset.placement = flip ? 'top' : 'bottom';
182
+ };
183
+ if (topLayer) menu.showPopover();
184
+ position();
185
+ const Resize = win.ResizeObserver;
186
+ const observer = Resize ? new Resize(position) : undefined;
187
+ observer?.observe(node);
188
+ const scroll = (event)=>{
189
+ const target = event.target;
190
+ if (target && 'nodeType' in target && menu.contains(target)) return;
191
+ position();
192
+ };
193
+ const theme = host ? new win.MutationObserver(()=>{
194
+ copyTheme();
195
+ position();
196
+ }) : undefined;
197
+ for(let ancestor = node; theme && ancestor; ancestor = ancestor.parentElement){
198
+ theme.observe(ancestor, {
199
+ attributes: true,
200
+ attributeFilter: [
201
+ 'data-theme',
202
+ 'class',
203
+ 'style',
204
+ 'dir'
205
+ ]
206
+ });
207
+ }
208
+ win.addEventListener('resize', position);
209
+ win.addEventListener('scroll', scroll, true);
210
+ win.visualViewport?.addEventListener('resize', position);
211
+ win.visualViewport?.addEventListener('scroll', position);
212
+ return ()=>{
213
+ if (topLayer) menu.hidePopover?.();
214
+ observer?.disconnect();
215
+ theme?.disconnect();
216
+ clearTheme();
217
+ win.removeEventListener('resize', position);
218
+ win.removeEventListener('scroll', scroll, true);
219
+ win.visualViewport?.removeEventListener('resize', position);
220
+ win.visualViewport?.removeEventListener('scroll', position);
221
+ };
222
+ }, [
223
+ open,
224
+ disabled,
225
+ options,
226
+ portalHost
227
+ ]);
228
+ useLayoutEffect(()=>{
229
+ const menu = popup.current;
230
+ const option = menu?.querySelector(`[data-index="${current}"]`);
231
+ if (!open || !menu || !option) return;
232
+ // Scroll only the popup, without moving the drawer or the page behind it.
233
+ const top = option.offsetTop, bottom = top + option.offsetHeight;
234
+ if (top < menu.scrollTop) menu.scrollTop = top;
235
+ else if (bottom > menu.scrollTop + menu.clientHeight) menu.scrollTop = bottom - menu.clientHeight;
236
+ }, [
237
+ open,
238
+ current,
239
+ portalHost
240
+ ]);
241
+ useEffect(()=>{
242
+ if (!open) return;
243
+ const doc = trigger.current?.ownerDocument;
244
+ const outside = (event)=>{
245
+ const target = event.target;
246
+ if (!trigger.current?.contains(target) && !popup.current?.contains(target)) leave();
247
+ };
248
+ doc?.addEventListener('pointerdown', outside, true);
249
+ return ()=>doc?.removeEventListener('pointerdown', outside, true);
250
+ });
251
+ useEffect(()=>{
252
+ const node = trigger.current;
253
+ if (!node) return;
254
+ // A button is labelable: suppress label activation's synthetic click, while
255
+ // retaining native label association and the expected focus behavior.
256
+ const labelClick = (event)=>{
257
+ const target = event.target;
258
+ const label = target?.closest?.('label');
259
+ if (label?.control === node && !node.contains(target)) {
260
+ event.preventDefault();
261
+ node.focus();
262
+ }
263
+ };
264
+ node.ownerDocument.addEventListener('click', labelClick, true);
265
+ return ()=>node.ownerDocument.removeEventListener('click', labelClick, true);
266
+ }, [
267
+ id
268
+ ]);
269
+ useEffect(()=>{
270
+ if (!open) return;
271
+ const dialog = trigger.current?.closest('dialog');
272
+ // Native cancel is also guarded for browser-generated dialog dismissal.
273
+ const cancel = (event)=>{
274
+ event.preventDefault();
275
+ event.stopImmediatePropagation();
276
+ setOpen(false);
277
+ };
278
+ dialog?.addEventListener('cancel', cancel, true);
279
+ return ()=>dialog?.removeEventListener('cancel', cancel, true);
280
+ }, [
281
+ open
282
+ ]);
283
+ useEffect(()=>{
284
+ if (disabled) setOpen(false);
285
+ }, [
286
+ disabled
287
+ ]);
288
+ function typeAhead(key) {
289
+ keyboardActive.current = true;
290
+ const now = Date.now();
291
+ const text = !open || now - typed.current.at > 700 ? key : typed.current.text + key;
292
+ typed.current = {
293
+ text,
294
+ at: now
295
+ };
296
+ const repeated = [
297
+ ...text
298
+ ].every((letter)=>letter === text[0]);
299
+ const search = (repeated ? key : text).toLocaleLowerCase('en-US');
300
+ const start = repeated ? (open ? current : selectedIndex) + 1 : Math.max(0, current);
301
+ const order = [
302
+ ...enabled.filter((index)=>index >= start),
303
+ ...enabled.filter((index)=>index < start)
304
+ ];
305
+ const match = order.find((index)=>options[index].label.toLocaleLowerCase('en-US').startsWith(search));
306
+ setOpen(true);
307
+ if (match !== undefined) setActive(match);
308
+ }
309
+ const menu = /*#__PURE__*/ _jsx("div", {
310
+ ref: popup,
311
+ hidden: !open || disabled,
312
+ style: {
313
+ position: 'fixed',
314
+ inset: 'auto',
315
+ right: 'auto',
316
+ bottom: 'auto',
317
+ margin: 0,
318
+ background: 'var(--xp-surface, Canvas)',
319
+ color: 'var(--xp-text, CanvasText)',
320
+ overflow: 'auto',
321
+ boxSizing: 'border-box',
322
+ zIndex: 2147483647,
323
+ ...!open || disabled ? {
324
+ display: 'none'
325
+ } : {}
326
+ },
327
+ id: listId,
328
+ role: "listbox",
329
+ "aria-label": props['aria-label'],
330
+ "aria-labelledby": props['aria-labelledby'] ?? (props['aria-label'] ? undefined : `${id}-label`),
331
+ popover: portalHost ? undefined : 'manual',
332
+ className: "xp-ui-combobox-popup",
333
+ onPointerDown: (event)=>{
334
+ event.preventDefault();
335
+ event.stopPropagation();
336
+ },
337
+ children: groups.map((group)=>/*#__PURE__*/ _jsxs("div", {
338
+ role: group.label ? 'group' : undefined,
339
+ "aria-labelledby": group.label ? `${id}-group-${group.start}` : undefined,
340
+ children: [
341
+ group.label ? /*#__PURE__*/ _jsx("div", {
342
+ id: `${id}-group-${group.start}`,
343
+ className: "xp-ui-combobox-group",
344
+ children: group.label
345
+ }) : null,
346
+ group.options.map((option, offset)=>{
347
+ const index = group.start + offset;
348
+ return /*#__PURE__*/ _jsx("div", {
349
+ role: "option",
350
+ id: optionId(index),
351
+ "data-index": index,
352
+ "data-value": option.value,
353
+ "aria-selected": selectedIndex === index,
354
+ "data-active": current === index,
355
+ style: {
356
+ backgroundColor: current === index ? 'var(--xp-surface-3, Highlight)' : undefined,
357
+ color: option.disabled ? 'var(--xp-text-3, GrayText)' : current === index ? 'var(--xp-text, HighlightText)' : undefined,
358
+ fontWeight: selectedIndex === index ? 600 : undefined
359
+ },
360
+ "aria-disabled": option.disabled || undefined,
361
+ className: "xp-ui-combobox-option",
362
+ onPointerMove: ()=>{
363
+ if (!option.disabled) {
364
+ keyboardActive.current = false;
365
+ setActive(index);
366
+ }
367
+ },
368
+ onClick: ()=>{
369
+ if (!option.disabled) {
370
+ commit(index);
371
+ trigger.current?.focus();
372
+ }
373
+ },
374
+ children: option.label
375
+ }, option.value);
376
+ })
377
+ ]
378
+ }, group.start))
379
+ });
380
+ return /*#__PURE__*/ _jsxs("div", {
381
+ className: "xp-ui-combobox-wrap",
382
+ children: [
383
+ /*#__PURE__*/ _jsxs("button", {
384
+ ...props,
385
+ id: id,
386
+ ref: trigger,
387
+ value: selected,
388
+ type: "button",
389
+ role: "combobox",
390
+ disabled: disabled,
391
+ "aria-expanded": open && !disabled,
392
+ "aria-haspopup": "listbox",
393
+ "aria-controls": listId,
394
+ "aria-activedescendant": open && current >= 0 ? optionId(current) : undefined,
395
+ "aria-required": required || undefined,
396
+ "aria-invalid": props['aria-invalid'] || missingRequired || undefined,
397
+ "aria-describedby": [
398
+ props['aria-describedby'],
399
+ missingRequired ? `${id}-required-error` : undefined
400
+ ].filter(Boolean).join(' ') || undefined,
401
+ className: `xp-ui-input xp-ui-combobox ${className}`,
402
+ onClick: ()=>open ? setOpen(false) : begin(),
403
+ onBlur: (event)=>{
404
+ if (open) leave();
405
+ onBlur?.(event);
406
+ },
407
+ onKeyDown: (event)=>{
408
+ onKeyDown?.(event);
409
+ if (event.defaultPrevented || disabled || event.nativeEvent.isComposing) return;
410
+ const key = event.key;
411
+ if (key === 'Tab') {
412
+ if (open) leave();
413
+ return;
414
+ }
415
+ if (key === 'Escape') {
416
+ if (open) {
417
+ event.preventDefault();
418
+ event.stopPropagation();
419
+ event.nativeEvent.stopImmediatePropagation();
420
+ setOpen(false);
421
+ }
422
+ ;
423
+ return;
424
+ }
425
+ if (open && key === ' ' && typed.current.text && Date.now() - typed.current.at <= 700) {
426
+ event.preventDefault();
427
+ typeAhead(key);
428
+ return;
429
+ }
430
+ if (key === 'Enter' || key === ' ') {
431
+ event.preventDefault();
432
+ open ? commit() : begin(undefined, true);
433
+ return;
434
+ }
435
+ if ([
436
+ 'ArrowDown',
437
+ 'ArrowUp',
438
+ 'Home',
439
+ 'End',
440
+ 'PageDown',
441
+ 'PageUp'
442
+ ].includes(key)) {
443
+ event.preventDefault();
444
+ keyboardActive.current = true;
445
+ if (open && event.altKey && key === 'ArrowUp') {
446
+ commit();
447
+ return;
448
+ }
449
+ if (key === 'Home' || !open && key === 'ArrowUp') begin(enabled[0] ?? -1, true);
450
+ else if (key === 'End') begin(enabled.at(-1) ?? -1, true);
451
+ else if (!open) begin(undefined, true);
452
+ else {
453
+ const offset = key === 'ArrowUp' ? -1 : key === 'PageUp' ? -10 : key === 'PageDown' ? 10 : 1;
454
+ setActive(enabled[Math.max(0, Math.min(enabled.length - 1, enabled.indexOf(current) + offset))] ?? -1);
455
+ }
456
+ return;
457
+ }
458
+ if (key.length === 1 && !event.altKey && !event.ctrlKey && !event.metaKey) {
459
+ event.preventDefault();
460
+ typeAhead(key);
461
+ }
462
+ },
463
+ children: [
464
+ /*#__PURE__*/ _jsx("span", {
465
+ children: options[selectedIndex]?.label ?? ''
466
+ }),
467
+ /*#__PURE__*/ _jsx("span", {
468
+ className: "xp-ui-combobox-chevron",
469
+ "aria-hidden": "true"
470
+ })
471
+ ]
472
+ }),
473
+ /*#__PURE__*/ _jsx("input", {
474
+ type: "hidden",
475
+ name: name,
476
+ form: form,
477
+ value: selected,
478
+ disabled: disabled
479
+ }),
480
+ required ? /*#__PURE__*/ _jsx("input", {
481
+ className: "xp-ui-combobox-validation",
482
+ "aria-hidden": "true",
483
+ tabIndex: -1,
484
+ value: selected,
485
+ required: true,
486
+ disabled: disabled,
487
+ form: form,
488
+ onChange: ()=>{},
489
+ onInvalid: (event)=>{
490
+ event.preventDefault();
491
+ setRequiredInvalid(true);
492
+ trigger.current?.focus();
493
+ }
494
+ }) : null,
495
+ missingRequired ? /*#__PURE__*/ _jsx("p", {
496
+ className: "xp-ui-error",
497
+ id: `${id}-required-error`,
498
+ role: "alert",
499
+ children: INPUT_COPY.selectRequired
500
+ }) : null,
501
+ portalHost ? /*#__PURE__*/ createPortal(menu, portalHost) : menu
502
+ ]
503
+ });
504
+ }
package/dist/ui/Tabs.d.ts CHANGED
@@ -4,7 +4,6 @@ export interface Tab {
4
4
  id: string;
5
5
  label: string;
6
6
  content: ReactNode;
7
- actions?: ReactNode;
8
7
  disabled?: boolean;
9
8
  }
10
9
  export declare function Tabs({ items, label, value, onChange, renderHeader, disabled }: {
package/dist/ui/Tabs.js CHANGED
@@ -12,48 +12,36 @@ export function Tabs({ items, label, value, onChange, renderHeader, disabled = f
12
12
  setLocal(id);
13
13
  onChange?.(id);
14
14
  }
15
- const header = /*#__PURE__*/ _jsxs("div", {
15
+ const header = /*#__PURE__*/ _jsx("div", {
16
16
  className: "xp-ui-tabbar",
17
- children: [
18
- /*#__PURE__*/ _jsx("div", {
19
- role: "tablist",
20
- "aria-label": label,
21
- "aria-disabled": disabled || undefined,
22
- className: "xp-ui-tablist",
23
- children: items.map((item, index)=>/*#__PURE__*/ _jsx("button", {
24
- style: {
25
- order: index * 2
26
- },
27
- type: "button",
28
- role: "tab",
29
- id: `${prefix}-tab-${item.id}`,
30
- "aria-controls": `${prefix}-panel-${item.id}`,
31
- "aria-selected": selected === item.id,
32
- tabIndex: selected === item.id ? 0 : -1,
33
- disabled: disabled || item.disabled,
34
- className: "xp-ui-tab",
35
- onClick: ()=>select(item.id),
36
- onKeyDown: (event)=>{
37
- if (disabled) return;
38
- const enabled = items.filter((tab)=>!tab.disabled);
39
- const index = enabled.findIndex((tab)=>tab.id === item.id);
40
- const next = event.key === 'ArrowRight' ? enabled[(index + 1) % enabled.length] : event.key === 'ArrowLeft' ? enabled[(index - 1 + enabled.length) % enabled.length] : event.key === 'Home' ? enabled[0] : event.key === 'End' ? enabled.at(-1) : undefined;
41
- if (!next) return;
42
- event.preventDefault();
43
- select(next.id);
44
- event.currentTarget.ownerDocument.getElementById(`${prefix}-tab-${next.id}`)?.focus();
45
- },
46
- children: item.label
47
- }, item.id))
48
- }),
49
- items.map((item, index)=>item.actions ? /*#__PURE__*/ _jsx("div", {
50
- style: {
51
- order: index * 2 + 1
17
+ children: /*#__PURE__*/ _jsx("div", {
18
+ role: "tablist",
19
+ "aria-label": label,
20
+ "aria-disabled": disabled || undefined,
21
+ className: "xp-ui-tablist",
22
+ children: items.map((item)=>/*#__PURE__*/ _jsx("button", {
23
+ type: "button",
24
+ role: "tab",
25
+ id: `${prefix}-tab-${item.id}`,
26
+ "aria-controls": `${prefix}-panel-${item.id}`,
27
+ "aria-selected": selected === item.id,
28
+ tabIndex: selected === item.id ? 0 : -1,
29
+ disabled: disabled || item.disabled,
30
+ className: "xp-ui-tab",
31
+ onClick: ()=>select(item.id),
32
+ onKeyDown: (event)=>{
33
+ if (disabled) return;
34
+ const enabled = items.filter((tab)=>!tab.disabled);
35
+ const index = enabled.findIndex((tab)=>tab.id === item.id);
36
+ const next = event.key === 'ArrowRight' ? enabled[(index + 1) % enabled.length] : event.key === 'ArrowLeft' ? enabled[(index - 1 + enabled.length) % enabled.length] : event.key === 'Home' ? enabled[0] : event.key === 'End' ? enabled.at(-1) : undefined;
37
+ if (!next) return;
38
+ event.preventDefault();
39
+ select(next.id);
40
+ event.currentTarget.ownerDocument.getElementById(`${prefix}-tab-${next.id}`)?.focus();
52
41
  },
53
- className: "xp-ui-tab-actions",
54
- children: item.actions
55
- }, item.id) : null)
56
- ]
42
+ children: item.label
43
+ }, item.id))
44
+ })
57
45
  });
58
46
  return /*#__PURE__*/ _jsxs("div", {
59
47
  className: "xp-ui-tabs",
package/dist/ui/ui.css CHANGED
@@ -13,7 +13,7 @@
13
13
  .xp-ui-button--sm { height: 30px; padding: 0 10px; font-size: 13px; }
14
14
  .xp-ui-button--link { height: auto; min-height: 0; padding-inline: 0; color: var(--xp-accent-text); text-decoration: var(--xp-accent-text-decoration); }
15
15
  .xp-ui-button--link:hover { text-decoration: underline; }
16
- .xp-ui-button:disabled, .xp-ui-button[aria-disabled='true'], .xp-ui-input:disabled, .xp-ui-toggle:disabled { opacity: .5; cursor: not-allowed; }
16
+ .xp-ui-button:disabled, .xp-ui-button[aria-disabled='true'], .xp-ui-input:disabled, .xp-ui-input[aria-disabled='true'], .xp-ui-toggle:disabled { opacity: .5; cursor: not-allowed; }
17
17
  .xp-ui-button:focus-visible, .xp-ui-input:focus-visible, .xp-ui-toggle:focus-visible, .xp-ui-tab:focus-visible, .xp-ui-tabpanel:focus-visible, .xp-ui-breadcrumb a:focus-visible, .xp-ui-dialog:focus-visible { outline: 2px solid var(--xp-focus); outline-offset: 2px; }
18
18
  .xp-ui-field { min-width: 0; max-width: 100%; display: grid; gap: 6px; color: var(--xp-text); font: var(--xp-text-body); }
19
19
  .xp-ui-field > label { font-weight: 500; }
@@ -21,8 +21,19 @@
21
21
  .xp-ui-input::placeholder { color: var(--xp-text-3); }
22
22
  .xp-ui-input:hover { border-color: var(--xp-text-3); }
23
23
  .xp-ui-input[aria-invalid='true'] { border-color: var(--xp-error); }
24
- .xp-ui-input--number { text-align: right; font-variant-numeric: tabular-nums; }
25
- .xp-ui-select { cursor: pointer; appearance: auto; }
24
+ .xp-ui-input--number { text-align: end; font-variant-numeric: tabular-nums; }
25
+ /* The open menu inherits the control's tokens, even in a dialog or canvas iframe. */
26
+ .xp-ui-combobox-wrap { display: block; position: relative; min-width: 0; max-width: 100%; }
27
+ .xp-ui-combobox { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-2); cursor: pointer; text-align: start; }
28
+ .xp-ui-combobox > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
29
+ .xp-ui-combobox-chevron { flex: 0 0 auto; width: 7px; height: 7px; margin-inline-end: 4px; border-right: 2px solid var(--xp-text-2); border-bottom: 2px solid var(--xp-text-2); transform: translateY(-2px) rotate(45deg); }
30
+ .xp-ui-combobox-popup { box-sizing: border-box; position: fixed; inset: auto; margin: 0; padding: var(--xp-space-1); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--xp-border-strong); border-radius: var(--xp-radius-control); background: var(--xp-surface); color: var(--xp-text); font: var(--xp-text-body); z-index: 2147483647; }
31
+ .xp-ui-combobox-popup:popover-open { display: block; }
32
+ .xp-ui-combobox-option { padding: var(--xp-space-2); border-radius: var(--xp-space-1); cursor: pointer; overflow-wrap: anywhere; }
33
+ .xp-ui-combobox-option[data-active='true'] { background: var(--xp-surface-3); outline: 1px solid var(--xp-border-strong); outline-offset: -1px; }
34
+ .xp-ui-combobox-option[aria-disabled='true'] { color: var(--xp-text-3); cursor: not-allowed; }
35
+ .xp-ui-combobox-group { padding: var(--xp-space-2); color: var(--xp-text-2); font: var(--xp-text-small); }
36
+ .xp-ui-combobox-validation { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
26
37
  .xp-ui-help { margin: 0; color: var(--xp-text-2); font: var(--xp-text-small); }
27
38
  .xp-ui-error { margin: 0; color: var(--xp-error); font: var(--xp-text-small); }
28
39
  .xp-ui-toggle { appearance: none; display: inline-block; width: 32px; height: 20px; margin: 0; padding: 2px; border-radius: 20px; border: 1px solid var(--xp-border-strong); background: var(--xp-surface-3); cursor: pointer; transition: background-color var(--xp-motion); }
@@ -38,7 +49,7 @@
38
49
  .xp-ui-section-body { padding: 20px; }
39
50
  .xp-ui-tabs { color: var(--xp-text); font: var(--xp-text-body); }
40
51
  .xp-ui-tablist { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--xp-border); }
41
- .xp-ui-tab { appearance: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 12px; background: transparent; color: var(--xp-text-2); font: var(--xp-text-body); cursor: pointer; }
52
+ .xp-ui-tab { min-width: 0; max-width: 100%; overflow-wrap: anywhere; white-space: normal; appearance: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 12px; background: transparent; color: var(--xp-text-2); font: var(--xp-text-body); cursor: pointer; }
42
53
  .xp-ui-tab[aria-selected='true'] { color: var(--xp-accent-text); text-decoration: var(--xp-accent-text-decoration); border-bottom-color: var(--xp-accent-text); font-weight: 600; }
43
54
  .xp-ui-tab:disabled { opacity: .5; cursor: not-allowed; }
44
55
  .xp-ui-tabpanel { padding-block: 16px; }
@@ -112,9 +123,11 @@
112
123
  /* Actions sit beside each tab visually and outside the tablist's owned roles. */
113
124
  .xp-ui-tabbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px; border-bottom: 1px solid var(--xp-border); }
114
125
  .xp-ui-tabbar > .xp-ui-tablist { display: contents; }
115
- .xp-ui-tab-actions { display: flex; align-items: center; flex-wrap: wrap; position: relative; }
116
126
 
117
127
  /* One blocker-list format in the admin footer and the Puck sidebar. */
118
128
  .xp-readiness__blockers, .xp-readiness__blockers a { color: var(--xp-error); }
119
129
  .xp-readiness__blockers ul { margin: 0; padding-inline-start: var(--xp-space-4); }
120
130
  .xp-readiness__blockers li { white-space: pre-line; }
131
+
132
+ .xp-other-goals summary { cursor: pointer; font-weight: 600; }
133
+ .xp-other-goal-list { display: grid; gap: var(--xp-space-3); padding-block: var(--xp-space-3); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-experiments",
3
- "version": "0.4.0-rc.5",
3
+ "version": "0.4.0-rc.7",
4
4
  "description": "No-code A/B testing for Payload CMS and Next.js: block, page and flag experiments with holdouts, layers, exposure logging and honest statistics inside the admin — no vendor",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -100,6 +100,7 @@
100
100
  }
101
101
  },
102
102
  "dependencies": {
103
+ "@payloadcms/translations": ">=3.90.0 <4",
103
104
  "@delmaredigital/experiments-stats": "0.1.0"
104
105
  },
105
106
  "keywords": [
@@ -126,7 +127,7 @@
126
127
  },
127
128
  "homepage": "https://delmaredigital.com/developers",
128
129
  "devDependencies": {
129
- "@delmaredigital/payload-puck": "0.10.3",
130
+ "@delmaredigital/payload-puck": "0.12.1",
130
131
  "payload": "^3.90.2",
131
132
  "@payloadcms/db-postgres": "^3.90.2",
132
133
  "@payloadcms/ui": "^3.90.2",