@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.
- package/dist/admin/surface/ResultsRoute.js +2 -10
- package/dist/admin/surface/newTest/PageWizard.js +10 -12
- package/dist/admin/surface/results/ResultsHeader.js +15 -8
- package/dist/goals/fairness.d.ts +1 -1
- package/dist/goals/fairness.js +1 -1
- package/dist/puck/editor/ConfigureTestDrawer.js +2 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +4 -0
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +425 -80
- package/dist/puck/editor/LeftoverVersions.d.ts +13 -0
- package/dist/puck/editor/LeftoverVersions.js +115 -0
- package/dist/puck/editor/PlacementNotice.d.ts +8 -0
- package/dist/puck/editor/PlacementNotice.js +22 -0
- package/dist/puck/editor/QuickTestActions.d.ts +3 -0
- package/dist/puck/editor/QuickTestActions.js +50 -0
- package/dist/puck/editor/ResultsReadout.js +5 -0
- package/dist/puck/editor/VersionBuilder.d.ts +20 -6
- package/dist/puck/editor/VersionBuilder.js +78 -48
- package/dist/puck/editor/armWrites.d.ts +3 -1
- package/dist/puck/editor/armWrites.js +2 -1
- package/dist/puck/editor/cloneSlot.d.ts +2 -0
- package/dist/puck/editor/cloneSlot.js +7 -0
- package/dist/puck/editor/copy.d.ts +24 -3
- package/dist/puck/editor/copy.js +24 -3
- package/dist/puck/editor/editor.chrome.css +11 -0
- package/dist/puck/editor/editor.css +29 -0
- package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
- package/dist/puck/editor/outlineVersion.d.ts +5 -0
- package/dist/puck/editor/outlineVersion.js +36 -0
- package/dist/puck/editor/placementsCache.d.ts +33 -2
- package/dist/puck/editor/placementsCache.js +208 -33
- package/dist/puck/editor/sidebar.d.ts +12 -0
- package/dist/puck/editor/sidebar.js +77 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
- package/dist/puck/editor/usePlacementNotice.js +14 -0
- package/dist/testSurface/api.js +1 -1
- package/dist/testSurface/copy/common.d.ts +1 -1
- package/dist/testSurface/copy/common.js +3 -1
- package/dist/testSurface/copy/readiness.d.ts +17 -1
- package/dist/testSurface/copy/readiness.js +22 -1
- package/dist/testSurface/copy/testPage.d.ts +1 -0
- package/dist/testSurface/copy/testPage.js +1 -0
- package/dist/testSurface/readPreflight.d.ts +9 -0
- package/dist/testSurface/readPreflight.js +38 -0
- package/dist/testSurface/readinessRead.d.ts +50 -0
- package/dist/testSurface/readinessRead.js +46 -0
- package/dist/testSurface/surface/contracts.d.ts +6 -2
- package/dist/testSurface/surface/editorPlacement.d.ts +21 -0
- package/dist/testSurface/surface/editorPlacement.js +60 -0
- package/dist/testSurface/surface/pageBlock/parts.js +13 -3
- package/dist/testSurface/surface/readiness/ActionDialogs.js +37 -7
- package/dist/testSurface/surface/readiness/Banner.d.ts +1 -4
- package/dist/testSurface/surface/readiness/Banner.js +106 -68
- package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
- package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +6 -2
- package/dist/testSurface/surface/readiness/SaveStatus.js +35 -22
- package/dist/testSurface/surface/readiness/parts.js +0 -2
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +13 -0
- package/dist/testSurface/surface/readiness/readiness.model.js +51 -36
- package/dist/testSurface/surface/readiness/useTransition.d.ts +5 -2
- package/dist/testSurface/surface/readiness/useTransition.js +69 -7
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/GoalSection.js +1 -0
- package/dist/testSurface/surface/test/LengthSection.d.ts +1 -1
- package/dist/testSurface/surface/test/LengthSection.js +2 -1
- package/dist/testSurface/surface/test/Rail.js +7 -4
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -2
- package/dist/testSurface/surface/test/Section.d.ts +3 -1
- package/dist/testSurface/surface/test/Section.js +38 -6
- package/dist/testSurface/surface/test/TargetingSection.js +5 -0
- package/dist/testSurface/surface/test/TestSurface.d.ts +2 -1
- package/dist/testSurface/surface/test/TestSurface.js +68 -7
- package/dist/testSurface/surface/test/VersionsSection.js +1 -0
- package/dist/testSurface/surface/test/testPage.css +12 -0
- package/dist/testSurface/surface/useTestDocument.d.ts +5 -2
- package/dist/testSurface/surface/useTestDocument.js +61 -46
- package/dist/testSurface/useReadinessPolling.d.ts +3 -0
- package/dist/testSurface/useReadinessPolling.js +24 -0
- package/dist/transitions/preflightData.js +1 -1
- package/dist/ui/Card.d.ts +2 -1
- package/dist/ui/Card.js +4 -4
- package/dist/ui/Tabs.d.ts +2 -1
- package/dist/ui/Tabs.js +19 -6
- package/dist/ui/ui.css +18 -0
- package/package.json +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { API_MESSAGES
|
|
3
|
+
import { API_MESSAGES } from '../copy/common.js';
|
|
4
|
+
import { readPreflight } from '../readPreflight.js';
|
|
4
5
|
import { XP_IF_UPDATED_AT_HEADER } from '../../constants.js';
|
|
6
|
+
import { useReadinessPolling } from '../useReadinessPolling.js';
|
|
7
|
+
import { classifyReadinessRead } from '../readinessRead.js';
|
|
5
8
|
import { TEST_PAGE } from '../copy/testPage.js';
|
|
6
9
|
import { changedPatch, editablePatch, payloadFieldErrors } from './testDocument.model.js';
|
|
7
10
|
// Saves outlive their mounted reader. Reopening the same document must wait for its queue.
|
|
@@ -65,14 +68,16 @@ function stage(session, partial) {
|
|
|
65
68
|
if (!session.queue.length) session.view.saving = 'idle';
|
|
66
69
|
session.publish();
|
|
67
70
|
}
|
|
68
|
-
/** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, refetchPreflightOnFocus = false, enabled = true, onDocument, onPreflight }) {
|
|
71
|
+
/** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, refetchPreflightOnFocus = false, enabled = true, onDocument, onPreflight, requestPreflight }) {
|
|
69
72
|
const observers = useRef({
|
|
70
73
|
onDocument,
|
|
71
|
-
onPreflight
|
|
74
|
+
onPreflight,
|
|
75
|
+
requestPreflight
|
|
72
76
|
});
|
|
73
77
|
observers.current = {
|
|
74
78
|
onDocument,
|
|
75
|
-
onPreflight
|
|
79
|
+
onPreflight,
|
|
80
|
+
requestPreflight
|
|
76
81
|
};
|
|
77
82
|
const base = apiRoute.replace(/\/$/, '');
|
|
78
83
|
const documentId = String(id);
|
|
@@ -93,15 +98,18 @@ function stage(session, partial) {
|
|
|
93
98
|
const controller = new AbortController();
|
|
94
99
|
const session = {
|
|
95
100
|
key,
|
|
96
|
-
saved: null,
|
|
101
|
+
saved: current.current?.key === key ? current.current.saved : null,
|
|
97
102
|
pending: {},
|
|
98
103
|
queue: [],
|
|
99
104
|
tail: Promise.resolve(),
|
|
100
|
-
view:
|
|
105
|
+
view: reloadCount && current.current?.key === key ? {
|
|
106
|
+
...current.current.view
|
|
107
|
+
} : initialView(),
|
|
101
108
|
controller,
|
|
102
109
|
reloading: false,
|
|
103
110
|
preflightReads: 0,
|
|
104
|
-
preflightLoading:
|
|
111
|
+
preflightLoading: true,
|
|
112
|
+
preflightFailures: current.current?.key === key ? current.current.preflightFailures : 0,
|
|
105
113
|
publish () {
|
|
106
114
|
if (controller.signal.aborted) return;
|
|
107
115
|
session.view.doc = session.view.loadState === 'ready' ? optimistic(session) : null;
|
|
@@ -118,50 +126,39 @@ function stage(session, partial) {
|
|
|
118
126
|
current.current = session;
|
|
119
127
|
const url = `${base}/xp-experiments/${encodeURIComponent(documentId)}?depth=0`;
|
|
120
128
|
let preflightRevision = 0;
|
|
121
|
-
async function refreshPreflight(initial = false) {
|
|
129
|
+
async function refreshPreflight(initial = false, supersede = false) {
|
|
122
130
|
if (controller.signal.aborted) return;
|
|
123
131
|
const revision = ++preflightRevision;
|
|
124
132
|
session.preflightLoading = true;
|
|
125
133
|
session.publish();
|
|
126
134
|
// createApi has no signal option; this read must abort without cancelling submitted PATCHes.
|
|
127
|
-
let
|
|
135
|
+
let body;
|
|
128
136
|
let status = 0;
|
|
129
|
-
let message = API_MESSAGES.network;
|
|
130
137
|
try {
|
|
131
|
-
const response = await fetch(`${base}/xp/experiments/${encodeURIComponent(documentId)}/preflight`, {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
const { response, body: answerBody } = await readPreflight((signal)=>observers.current.requestPreflight?.(signal, supersede || initial && reloadCount > 0) ?? fetch(`${base}/xp/experiments/${encodeURIComponent(documentId)}/preflight`, {
|
|
139
|
+
method: 'GET',
|
|
140
|
+
credentials: 'include',
|
|
141
|
+
cache: 'no-store',
|
|
142
|
+
signal
|
|
143
|
+
}), controller.signal);
|
|
136
144
|
status = response.status;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
data = body;
|
|
140
|
-
message = API_MESSAGES.unreadable;
|
|
141
|
-
} else {
|
|
142
|
-
const envelope = body;
|
|
143
|
-
const error = Array.isArray(envelope?.errors) ? envelope.errors[0] : undefined;
|
|
144
|
-
message = refusalMessage(status === 501 ? 'not-implemented' : error?.code, status, typeof error?.message === 'string' ? error.message : undefined);
|
|
145
|
-
}
|
|
146
|
-
} catch {
|
|
147
|
-
message = API_MESSAGES.network;
|
|
148
|
-
}
|
|
145
|
+
body = answerBody;
|
|
146
|
+
} catch {}
|
|
149
147
|
if (controller.signal.aborted) return;
|
|
150
148
|
if (revision !== preflightRevision) return;
|
|
151
149
|
session.preflightLoading = false;
|
|
150
|
+
session.view.preflightRead = classifyReadinessRead(status, body, session.preflightFailures + 1);
|
|
151
|
+
session.preflightFailures = session.view.preflightRead.failed ? session.preflightFailures + 1 : 0;
|
|
152
|
+
const data = session.view.preflightRead.answer;
|
|
152
153
|
if (data) {
|
|
153
154
|
observers.current.onPreflight?.(data);
|
|
154
155
|
session.view.preflight = data;
|
|
155
156
|
session.view.preflightError = null;
|
|
156
157
|
if (initial) session.view.loadState = 'ready';
|
|
157
158
|
} else {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
...session.view.errors,
|
|
162
|
-
_section: message
|
|
163
|
-
};
|
|
164
|
-
} else session.view.preflightError = message;
|
|
159
|
+
session.view.preflight = null;
|
|
160
|
+
session.view.preflightError = session.view.preflightRead.message ?? null;
|
|
161
|
+
if (initial) session.view.loadState = session.view.preflightRead.loadState === 'error' ? 'ready' : session.view.preflightRead.loadState;
|
|
165
162
|
}
|
|
166
163
|
session.publish();
|
|
167
164
|
}
|
|
@@ -273,7 +270,7 @@ function stage(session, partial) {
|
|
|
273
270
|
if (saved) {
|
|
274
271
|
// Recovery is complete; readiness now belongs to the latest preflight read.
|
|
275
272
|
session.preflightReads--;
|
|
276
|
-
await refreshPreflight();
|
|
273
|
+
await refreshPreflight(false, true);
|
|
277
274
|
}
|
|
278
275
|
};
|
|
279
276
|
// Recover both the preceding tail and this step: unexpected throws must not strand later saves.
|
|
@@ -291,28 +288,37 @@ function stage(session, partial) {
|
|
|
291
288
|
commitRef.current = {
|
|
292
289
|
session,
|
|
293
290
|
commit,
|
|
294
|
-
refreshPreflight: ()=>refreshPreflight()
|
|
291
|
+
refreshPreflight: (supersede)=>refreshPreflight(false, supersede)
|
|
295
292
|
};
|
|
296
293
|
session.publish();
|
|
297
294
|
void (async ()=>{
|
|
298
295
|
try {
|
|
299
296
|
await waitForDrain(drainingSaves.get(key), controller.signal);
|
|
300
297
|
if (controller.signal.aborted) return;
|
|
301
|
-
const response = await fetch(url, {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
298
|
+
const { response, body } = await readPreflight((signal)=>fetch(url, {
|
|
299
|
+
method: 'GET',
|
|
300
|
+
credentials: 'include',
|
|
301
|
+
signal
|
|
302
|
+
}), controller.signal);
|
|
306
303
|
if (controller.signal.aborted) return;
|
|
307
304
|
if (!response.ok) {
|
|
308
|
-
session.
|
|
305
|
+
session.preflightLoading = false;
|
|
306
|
+
session.view.preflightRead = classifyReadinessRead(response.status, undefined, session.preflightFailures + 1, {
|
|
307
|
+
kind: 'document'
|
|
308
|
+
});
|
|
309
|
+
session.preflightFailures = session.view.preflightRead.failed ? session.preflightFailures + 1 : 0;
|
|
310
|
+
session.view.loadState = session.view.preflightRead.loadState;
|
|
309
311
|
session.publish();
|
|
310
312
|
return;
|
|
311
313
|
}
|
|
312
|
-
const doc =
|
|
314
|
+
const doc = body;
|
|
313
315
|
if (controller.signal.aborted) return;
|
|
314
|
-
if (doc.id == null || !doc.status) throw new Error(API_MESSAGES.unreadable);
|
|
316
|
+
if (!doc || doc.id == null || !doc.status) throw new Error(API_MESSAGES.unreadable);
|
|
315
317
|
session.saved = doc;
|
|
318
|
+
session.view.errors = {};
|
|
319
|
+
session.view.chosenPages = {};
|
|
320
|
+
session.view.stale = false;
|
|
321
|
+
session.view.saving = 'idle';
|
|
316
322
|
observers.current.onDocument?.(doc);
|
|
317
323
|
await refreshPreflight(true);
|
|
318
324
|
if (controller.signal.aborted) return;
|
|
@@ -329,6 +335,10 @@ function stage(session, partial) {
|
|
|
329
335
|
}
|
|
330
336
|
} catch {
|
|
331
337
|
if (controller.signal.aborted) return;
|
|
338
|
+
session.preflightLoading = false;
|
|
339
|
+
session.view.preflightRead = classifyReadinessRead(0, undefined, ++session.preflightFailures, {
|
|
340
|
+
kind: 'document'
|
|
341
|
+
});
|
|
332
342
|
session.view.loadState = 'error';
|
|
333
343
|
session.view.errors = {
|
|
334
344
|
_section: API_MESSAGES.unreadable
|
|
@@ -374,12 +384,17 @@ function stage(session, partial) {
|
|
|
374
384
|
}, [
|
|
375
385
|
key
|
|
376
386
|
]);
|
|
377
|
-
const refreshPreflight = useCallback(()=>{
|
|
387
|
+
const refreshPreflight = useCallback((supersede = false)=>{
|
|
378
388
|
const entry = commitRef.current;
|
|
379
|
-
return entry?.session.key === key && entry.session.view.loadState === 'ready' && !entry.session.reloading ? entry.refreshPreflight() : Promise.resolve();
|
|
389
|
+
return entry?.session.key === key && entry.session.view.loadState === 'ready' && !entry.session.reloading ? entry.refreshPreflight(supersede) : Promise.resolve();
|
|
380
390
|
}, [
|
|
381
391
|
key
|
|
382
392
|
]);
|
|
393
|
+
const settledRead = state.key === key ? state.view.preflightRead : undefined;
|
|
394
|
+
useReadinessPolling(settledRead, ()=>{
|
|
395
|
+
if (state.view.loadState === 'ready') void refreshPreflight();
|
|
396
|
+
else void reload();
|
|
397
|
+
}, !requestPreflight || state.view.loadState === 'error', state.view.preflightPending);
|
|
383
398
|
useEffect(()=>{
|
|
384
399
|
if (!refetchPreflightOnFocus) return;
|
|
385
400
|
let lastReturn = -Infinity;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ReadinessRead } from './readinessRead.js';
|
|
2
|
+
/** Non-shared reads use the same visible-only delay policy as editor cache reads. */
|
|
3
|
+
export declare function useReadinessPolling(read: ReadinessRead | undefined, refresh: () => void, enabled?: boolean, pending?: boolean): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
/** Non-shared reads use the same visible-only delay policy as editor cache reads. */ export function useReadinessPolling(read, refresh, enabled = true, pending = false) {
|
|
4
|
+
const action = useRef(refresh);
|
|
5
|
+
action.current = refresh;
|
|
6
|
+
useEffect(()=>{
|
|
7
|
+
if (!enabled || pending || !read?.pollDelay) return;
|
|
8
|
+
let timer;
|
|
9
|
+
const schedule = ()=>{
|
|
10
|
+
clearTimeout(timer);
|
|
11
|
+
if (document.visibilityState === 'visible') timer = setTimeout(()=>action.current(), read.pollDelay);
|
|
12
|
+
};
|
|
13
|
+
schedule();
|
|
14
|
+
document.addEventListener('visibilitychange', schedule);
|
|
15
|
+
return ()=>{
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
document.removeEventListener('visibilitychange', schedule);
|
|
18
|
+
};
|
|
19
|
+
}, [
|
|
20
|
+
read,
|
|
21
|
+
enabled,
|
|
22
|
+
pending
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
@@ -604,7 +604,7 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
604
604
|
...input.goalContent ? {
|
|
605
605
|
goalNotes: input.metrics.filter((m)=>m.source.startsWith('click:') && input.goalContent && !input.goalContent.skipped && !input.goalContent.unchecked.length && !input.goalContent.keys.some((k)=>`click:${k.key}` === m.source)).map((m)=>({
|
|
606
606
|
metricId: m.id,
|
|
607
|
-
message: OUTSIDE_GOAL
|
|
607
|
+
message: OUTSIDE_GOAL(m.name, e.kind)
|
|
608
608
|
}))
|
|
609
609
|
} : {},
|
|
610
610
|
placements,
|
package/dist/ui/Card.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
import './ui.css';
|
|
3
3
|
export declare function Card({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
|
|
4
|
-
export declare function SectionCard({ number, title, complete, children, id, headingId, className }: {
|
|
4
|
+
export declare function SectionCard({ number, title, complete, blocked, children, id, headingId, className }: {
|
|
5
5
|
number: number;
|
|
6
6
|
title: string;
|
|
7
7
|
complete?: boolean;
|
|
8
|
+
blocked?: boolean;
|
|
8
9
|
children: ReactNode;
|
|
9
10
|
id?: string;
|
|
10
11
|
headingId?: string;
|
package/dist/ui/Card.js
CHANGED
|
@@ -6,11 +6,11 @@ export function Card({ className = '', ...props }) {
|
|
|
6
6
|
className: `xp-ui-card ${className}`
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
export function SectionCard({ number, title, complete = false, children, id, headingId, className = '' }) {
|
|
9
|
+
export function SectionCard({ number, title, complete = false, blocked = false, children, id, headingId, className = '' }) {
|
|
10
10
|
return /*#__PURE__*/ _jsxs("section", {
|
|
11
11
|
id: id,
|
|
12
12
|
"aria-labelledby": headingId,
|
|
13
|
-
className: `xp-ui-card xp-ui-section ${className}`,
|
|
13
|
+
className: `xp-ui-card xp-ui-section ${blocked ? 'xp-ui-section--blocked' : complete ? 'xp-ui-section--complete' : ''} ${className}`,
|
|
14
14
|
children: [
|
|
15
15
|
/*#__PURE__*/ _jsxs("header", {
|
|
16
16
|
className: "xp-ui-section-head",
|
|
@@ -26,8 +26,8 @@ export function SectionCard({ number, title, complete = false, children, id, hea
|
|
|
26
26
|
}),
|
|
27
27
|
/*#__PURE__*/ _jsx("span", {
|
|
28
28
|
className: "xp-ui-section-complete",
|
|
29
|
-
"aria-label": complete ? 'Complete' : 'Incomplete',
|
|
30
|
-
children: complete ? '✓' : '○'
|
|
29
|
+
"aria-label": blocked ? 'Needs attention' : complete ? 'Complete' : 'Incomplete',
|
|
30
|
+
children: blocked ? '!' : complete ? '✓' : '○'
|
|
31
31
|
})
|
|
32
32
|
]
|
|
33
33
|
}),
|
package/dist/ui/Tabs.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export interface Tab {
|
|
|
7
7
|
actions?: ReactNode;
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
}
|
|
10
|
-
export declare function Tabs({ items, label, value, onChange, renderHeader }: {
|
|
10
|
+
export declare function Tabs({ items, label, value, onChange, renderHeader, disabled }: {
|
|
11
11
|
items: Tab[];
|
|
12
12
|
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
13
14
|
value?: string;
|
|
14
15
|
onChange?: (id: string) => void;
|
|
15
16
|
renderHeader?: (children: ReactNode) => ReactNode;
|
package/dist/ui/Tabs.js
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useState } from 'react';
|
|
4
4
|
import './ui.css';
|
|
5
|
-
export function Tabs({ items, label, value, onChange, renderHeader }) {
|
|
5
|
+
export function Tabs({ items, label, value, onChange, renderHeader, disabled = false }) {
|
|
6
6
|
const prefix = useId();
|
|
7
7
|
const [local, setLocal] = useState(()=>items.find((item)=>!item.disabled)?.id);
|
|
8
8
|
const requested = value ?? local;
|
|
9
9
|
const selected = items.find((item)=>item.id === requested && !item.disabled)?.id ?? items.find((item)=>!item.disabled)?.id;
|
|
10
10
|
function select(id) {
|
|
11
|
+
if (disabled) return;
|
|
11
12
|
setLocal(id);
|
|
12
13
|
onChange?.(id);
|
|
13
14
|
}
|
|
14
|
-
const header = /*#__PURE__*/ _jsxs(
|
|
15
|
+
const header = /*#__PURE__*/ _jsxs("div", {
|
|
16
|
+
className: "xp-ui-tabbar",
|
|
15
17
|
children: [
|
|
16
18
|
/*#__PURE__*/ _jsx("div", {
|
|
17
19
|
role: "tablist",
|
|
18
20
|
"aria-label": label,
|
|
21
|
+
"aria-disabled": disabled || undefined,
|
|
19
22
|
className: "xp-ui-tablist",
|
|
20
|
-
children: items.map((item)=>/*#__PURE__*/ _jsx("button", {
|
|
23
|
+
children: items.map((item, index)=>/*#__PURE__*/ _jsx("button", {
|
|
24
|
+
style: {
|
|
25
|
+
order: index * 2
|
|
26
|
+
},
|
|
21
27
|
type: "button",
|
|
22
28
|
role: "tab",
|
|
23
29
|
id: `${prefix}-tab-${item.id}`,
|
|
24
30
|
"aria-controls": `${prefix}-panel-${item.id}`,
|
|
25
31
|
"aria-selected": selected === item.id,
|
|
26
32
|
tabIndex: selected === item.id ? 0 : -1,
|
|
27
|
-
disabled: item.disabled,
|
|
33
|
+
disabled: disabled || item.disabled,
|
|
28
34
|
className: "xp-ui-tab",
|
|
29
35
|
onClick: ()=>select(item.id),
|
|
30
36
|
onKeyDown: (event)=>{
|
|
37
|
+
if (disabled) return;
|
|
31
38
|
const enabled = items.filter((tab)=>!tab.disabled);
|
|
32
39
|
const index = enabled.findIndex((tab)=>tab.id === item.id);
|
|
33
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;
|
|
@@ -39,7 +46,13 @@ export function Tabs({ items, label, value, onChange, renderHeader }) {
|
|
|
39
46
|
children: item.label
|
|
40
47
|
}, item.id))
|
|
41
48
|
}),
|
|
42
|
-
items.
|
|
49
|
+
items.map((item, index)=>item.actions ? /*#__PURE__*/ _jsx("div", {
|
|
50
|
+
style: {
|
|
51
|
+
order: index * 2 + 1
|
|
52
|
+
},
|
|
53
|
+
className: "xp-ui-tab-actions",
|
|
54
|
+
children: item.actions
|
|
55
|
+
}, item.id) : null)
|
|
43
56
|
]
|
|
44
57
|
});
|
|
45
58
|
return /*#__PURE__*/ _jsxs("div", {
|
package/dist/ui/ui.css
CHANGED
|
@@ -100,3 +100,21 @@
|
|
|
100
100
|
.xp-ui-drawer > .xp-ui-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-4); padding: var(--xp-space-4) var(--xp-space-5); border-bottom: 1px solid var(--xp-border); flex-shrink: 0; background: var(--xp-surface); }
|
|
101
101
|
.xp-ui-drawer > .xp-ui-dialog-header h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font: var(--xp-text-title); }
|
|
102
102
|
.xp-ui-drawer-body { min-height: 0; overflow: auto; overscroll-behavior: contain; flex: 1; background: var(--xp-bg); }
|
|
103
|
+
|
|
104
|
+
.xp-ui-section--blocked { border-color: var(--xp-error-border); }
|
|
105
|
+
.xp-ui-section--blocked .xp-ui-section-number, .xp-ui-section--blocked .xp-ui-section-complete { color: var(--xp-error); border-color: var(--xp-error-border); }
|
|
106
|
+
.xp-ui-section--complete .xp-ui-section-complete { color: var(--xp-success); }
|
|
107
|
+
.xp-ui-section--complete .xp-ui-section-number { color: var(--xp-success); border-color: var(--xp-success); }
|
|
108
|
+
.xp-ui-section--blocked h2:focus { outline-color: var(--xp-error); }
|
|
109
|
+
|
|
110
|
+
.xp-ui-section--blocked .xp-ui-section-complete { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--xp-error-border); border-radius: 50%; }
|
|
111
|
+
|
|
112
|
+
/* Actions sit beside each tab visually and outside the tablist's owned roles. */
|
|
113
|
+
.xp-ui-tabbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px; border-bottom: 1px solid var(--xp-border); }
|
|
114
|
+
.xp-ui-tabbar > .xp-ui-tablist { display: contents; }
|
|
115
|
+
.xp-ui-tab-actions { display: flex; align-items: center; flex-wrap: wrap; position: relative; }
|
|
116
|
+
|
|
117
|
+
/* One blocker-list format in the admin footer and the Puck sidebar. */
|
|
118
|
+
.xp-readiness__blockers, .xp-readiness__blockers a { color: var(--xp-error); }
|
|
119
|
+
.xp-readiness__blockers ul { margin: 0; padding-inline-start: var(--xp-space-4); }
|
|
120
|
+
.xp-readiness__blockers li { white-space: pre-line; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delmaredigital/payload-experiments",
|
|
3
|
-
"version": "0.4.0-rc.
|
|
3
|
+
"version": "0.4.0-rc.5",
|
|
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",
|