@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/newTest.css +3 -1
- package/dist/blocks/bindings.js +6 -13
- package/dist/blocks/placementLocale.d.ts +2 -0
- package/dist/blocks/placementLocale.js +16 -12
- package/dist/goals/fairness.js +8 -6
- package/dist/hooks/blockRemovalRule.d.ts +2 -1
- package/dist/hooks/blockRemovalRule.js +27 -5
- package/dist/hooks/pageGuard.js +2 -2
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +34 -30
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +1 -0
- package/dist/puck/copy.js +1 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
- package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +354 -374
- package/dist/puck/editor/LeftoverVersions.d.ts +3 -1
- package/dist/puck/editor/LeftoverVersions.js +45 -63
- package/dist/puck/editor/QuickTestActions.js +2 -2
- package/dist/puck/editor/VersionBuilder.d.ts +24 -13
- package/dist/puck/editor/VersionBuilder.js +264 -205
- package/dist/puck/editor/armWrites.d.ts +9 -2
- package/dist/puck/editor/armWrites.js +40 -2
- package/dist/puck/editor/armsCache.d.ts +1 -1
- package/dist/puck/editor/armsCache.js +2 -1
- package/dist/puck/editor/copy.d.ts +19 -25
- package/dist/puck/editor/copy.js +19 -25
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +24 -17
- package/dist/puck/editor/editor.css +33 -21
- package/dist/puck/editor/editor.model.d.ts +1 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
- package/dist/puck/editor/localPlacements.d.ts +4 -2
- package/dist/puck/editor/localPlacements.js +20 -18
- package/dist/puck/editor/sidebar.d.ts +2 -6
- package/dist/puck/editor/sidebar.js +3 -6
- package/dist/puck/visibility.d.ts +21 -0
- package/dist/puck/visibility.js +77 -0
- package/dist/server/recordContentChange.js +3 -1
- package/dist/server/resolveExperimentData.js +4 -1
- package/dist/testSurface/copy/readiness.d.ts +1 -0
- package/dist/testSurface/copy/readiness.js +1 -0
- package/dist/testSurface/copy/testPage.d.ts +7 -6
- package/dist/testSurface/copy/testPage.js +7 -6
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
- package/dist/testSurface/surface/test/GoalSection.js +101 -74
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/transitions/makeContent.js +24 -5
- package/dist/transitions/placements.js +23 -34
- package/dist/types/puck.d.ts +1 -0
- package/dist/ui/Inputs.js +8 -5
- package/dist/ui/Tabs.d.ts +0 -1
- package/dist/ui/Tabs.js +28 -40
- package/dist/ui/ui.css +9 -4
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ export declare const NEW_TEST_COPY: {
|
|
|
15
15
|
readonly blockMeaning: "Compare different versions of content on a page.";
|
|
16
16
|
readonly settingMeaning: "Compare different choices for a setting on your site.";
|
|
17
17
|
readonly unavailable: "A developer needs to set up pages or settings before you can create a test.";
|
|
18
|
-
readonly handoff: "Open the page, add an Experiment block where you want
|
|
18
|
+
readonly handoff: "Open the page, add an Experiment block where you want it, and choose Set up test.";
|
|
19
19
|
readonly noPages: "There are no pages yet.";
|
|
20
20
|
readonly recentPages: "Showing the 50 most recently edited.";
|
|
21
21
|
readonly open: "Open";
|
|
@@ -15,7 +15,7 @@ export const NEW_TEST_COPY = {
|
|
|
15
15
|
blockMeaning: 'Compare different versions of content on a page.',
|
|
16
16
|
settingMeaning: 'Compare different choices for a setting on your site.',
|
|
17
17
|
unavailable: 'A developer needs to set up pages or settings before you can create a test.',
|
|
18
|
-
handoff: 'Open the page, add an Experiment block where you want
|
|
18
|
+
handoff: 'Open the page, add an Experiment block where you want it, and choose Set up test.',
|
|
19
19
|
noPages: 'There are no pages yet.',
|
|
20
20
|
recentPages: 'Showing the 50 most recently edited.',
|
|
21
21
|
open: 'Open',
|
|
@@ -8,6 +8,7 @@ import { formatAdminURL } from 'payload/shared';
|
|
|
8
8
|
import { NEW_TEST_COPY as C } from '../../copy/newTest.js';
|
|
9
9
|
import { CreateRefused, createTest } from '../../../puck/editor/createTest.js';
|
|
10
10
|
import { PageWizard } from './PageWizard.js';
|
|
11
|
+
import { Select } from '../../../ui/Select.js';
|
|
11
12
|
import './newTest.css';
|
|
12
13
|
export function NewTest({ surface, pages }) {
|
|
13
14
|
const router = useRouter();
|
|
@@ -282,25 +283,22 @@ export function NewTest({ surface, pages }) {
|
|
|
282
283
|
/*#__PURE__*/ _jsx("summary", {
|
|
283
284
|
children: C.advanced
|
|
284
285
|
}),
|
|
285
|
-
/*#__PURE__*/ _jsxs(
|
|
286
|
+
/*#__PURE__*/ _jsxs(Select, {
|
|
287
|
+
id: "xp-new-group",
|
|
288
|
+
label: C.group,
|
|
289
|
+
"aria-describedby": "xp-new-group-help",
|
|
290
|
+
disabled: layerState !== 'ready',
|
|
291
|
+
value: layer === undefined ? '' : layers.findIndex((item)=>item.id === layer),
|
|
292
|
+
onChange: (event)=>setLayer(event.currentTarget.value === '' ? undefined : layers[Number(event.currentTarget.value)]?.id),
|
|
286
293
|
children: [
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
value: "",
|
|
296
|
-
children: C.noGroup
|
|
297
|
-
}),
|
|
298
|
-
layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
|
|
299
|
-
value: index,
|
|
300
|
-
children: item.name
|
|
301
|
-
}, index))
|
|
302
|
-
]
|
|
303
|
-
})
|
|
294
|
+
/*#__PURE__*/ _jsx("option", {
|
|
295
|
+
value: "",
|
|
296
|
+
children: C.noGroup
|
|
297
|
+
}),
|
|
298
|
+
layers.map((item, index)=>/*#__PURE__*/ _jsx("option", {
|
|
299
|
+
value: index,
|
|
300
|
+
children: item.name
|
|
301
|
+
}, index))
|
|
304
302
|
]
|
|
305
303
|
}),
|
|
306
304
|
/*#__PURE__*/ _jsx("p", {
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
.xp-new-test-card strong { font-size: 1.25rem; }
|
|
5
5
|
.xp-new-test-card:hover { background: var(--xp-surface-raised); }
|
|
6
6
|
.xp-new-test label { display: block; margin-block: .75rem; }
|
|
7
|
-
.xp-new-test input:not([type=radio]), .xp-new-test textarea
|
|
7
|
+
.xp-new-test input:not([type=radio]), .xp-new-test textarea { display: block; width: 100%; max-width: 36rem; padding: .5rem; color: var(--xp-text); background: var(--xp-input-bg); border: 1px solid var(--xp-input-border); font: inherit; }
|
|
8
8
|
.xp-new-test-choice span { display: block; margin-left: 1.5rem; }
|
|
9
9
|
.xp-new-test-actions { display: flex; gap: 1rem; margin-top: var(--xp-space-4); }
|
|
10
|
+
|
|
11
|
+
.xp-new-test .xp-ui-select-wrap { max-width: 36rem; }
|
package/dist/blocks/bindings.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
1
2
|
import { documentEditor, puckCollections } from '../options.js';
|
|
2
3
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
|
|
3
4
|
/** Same document-kind rule as the scan; Payload blocks are top level, Puck is recursive. */ export function placementSlugs(options, collection, doc) {
|
|
@@ -15,19 +16,11 @@ import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject } from './model.js';
|
|
|
15
16
|
if (editor !== 'puck') return [];
|
|
16
17
|
const registration = puckCollections(options).find((r)=>r.slug === collection);
|
|
17
18
|
const found = new Set();
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!isObject(v)) return;
|
|
24
|
-
if (v.type === 'ExperimentSlot' && isObject(v.props)) {
|
|
25
|
-
const ref = v.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
|
|
26
|
-
if (typeof slug === 'string') found.add(slug);
|
|
27
|
-
}
|
|
28
|
-
Object.values(v).forEach(walk);
|
|
29
|
-
}
|
|
30
|
-
if (registration) walk(doc[registration.field]);
|
|
19
|
+
if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
|
|
20
|
+
if (visibility.hidden || node.type !== 'ExperimentSlot') return;
|
|
21
|
+
const ref = node.props.experiment, slug = typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined;
|
|
22
|
+
if (typeof slug === 'string') found.add(slug);
|
|
23
|
+
});
|
|
31
24
|
return [
|
|
32
25
|
...found
|
|
33
26
|
];
|
|
@@ -19,3 +19,5 @@ export declare function placementLocaleViews(req: PayloadRequest, collection: st
|
|
|
19
19
|
* The incoming hook document is already flattened to the writing locale.
|
|
20
20
|
*/
|
|
21
21
|
export declare function removedPlacementViews(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean): RemovedPlacementViews;
|
|
22
|
+
/** Rebuild unchanged locale maps around a flattened hook write before reading each view. */
|
|
23
|
+
export declare function mergedPlacementLocales(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -84,9 +84,22 @@ export function localeRequest(req, view) {
|
|
|
84
84
|
*/ export function removedPlacementViews(req, collection, before, after, removingPage) {
|
|
85
85
|
const result = new Map();
|
|
86
86
|
if (!before) return result;
|
|
87
|
+
const options = req.payload.config.custom.xp;
|
|
88
|
+
const rawAfter = mergedPlacementLocales(req, collection, before, after);
|
|
89
|
+
for (const view of placementLocaleViews(req, collection)){
|
|
90
|
+
const viewReq = localeRequest(req, view);
|
|
91
|
+
const previous = placementSlugs(options, collection, placementLocaleContent(viewReq, collection, before));
|
|
92
|
+
const next = removingPage ? [] : placementSlugs(options, collection, placementLocaleContent(viewReq, collection, rawAfter));
|
|
93
|
+
for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
|
|
94
|
+
...result.get(slug) ?? [],
|
|
95
|
+
view
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/** Rebuild unchanged locale maps around a flattened hook write before reading each view. */ export function mergedPlacementLocales(req, collection, before, after) {
|
|
87
101
|
const localization = req.payload.config.localization;
|
|
88
102
|
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
89
|
-
const options = req.payload.config.custom.xp;
|
|
90
103
|
const fields = config ? flattenTopLevelFields(config.fields) : [];
|
|
91
104
|
const localized = fields.filter((field)=>'name' in field && 'localized' in field && field.localized);
|
|
92
105
|
// Keep the raw locale maps for unchanged languages when merging a partial,
|
|
@@ -96,20 +109,11 @@ export function localeRequest(req, view) {
|
|
|
96
109
|
};
|
|
97
110
|
if (localization && req.locale !== 'all') for (const field of localized){
|
|
98
111
|
if (!('name' in field) || typeof field.name !== 'string' || !(field.name in after)) continue;
|
|
99
|
-
const previousValue = before[field.name];
|
|
112
|
+
const previousValue = before?.[field.name];
|
|
100
113
|
rawAfter[field.name] = {
|
|
101
114
|
...isObject(previousValue) ? previousValue : {},
|
|
102
115
|
[req.locale || localization.defaultLocale]: after[field.name]
|
|
103
116
|
};
|
|
104
117
|
}
|
|
105
|
-
|
|
106
|
-
const viewReq = localeRequest(req, view);
|
|
107
|
-
const previous = placementSlugs(options, collection, placementLocaleContent(viewReq, collection, before));
|
|
108
|
-
const next = removingPage ? [] : placementSlugs(options, collection, placementLocaleContent(viewReq, collection, rawAfter));
|
|
109
|
-
for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
|
|
110
|
-
...result.get(slug) ?? [],
|
|
111
|
-
view
|
|
112
|
-
]);
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
118
|
+
return rawAfter;
|
|
115
119
|
}
|
package/dist/goals/fairness.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { puckVisibility } from '../puck/visibility.js';
|
|
1
2
|
import { clickGoalContent } from '../db/clickGoals.js';
|
|
2
3
|
import { safeError } from '../log.js';
|
|
3
4
|
import { documentEditor, puckCollections } from '../options.js';
|
|
@@ -7,16 +8,16 @@ import { scanPlacements, uniquePlacementDocs } from '../transitions/placementInt
|
|
|
7
8
|
import { CLICK_KEY } from './key.js';
|
|
8
9
|
export const OUTSIDE_GOAL = (name = 'Selected goal', kind = 'block')=>kind === 'block' ? `Heads up: the click goal “${name}” is outside this test's block, so every version shows the same button. The test can still start. To compare different buttons, move the goal inside each version.` : `Heads up: the click goal “${name}” isn't on any of this test's pages. The test can still start. Add the goal to every version's page to measure those clicks.`;
|
|
9
10
|
export const LEGACY_FAIRNESS = "Goal fairness isn't checked for tests started before this update.";
|
|
10
|
-
/** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels) {
|
|
11
|
+
/** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels, visibility) {
|
|
11
12
|
if (Array.isArray(value)) {
|
|
12
|
-
value.forEach((item)=>collect(item, into, label, labels));
|
|
13
|
+
value.forEach((item)=>collect(item, into, label, labels, visibility));
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
|
-
if (!isObject(value)) return;
|
|
16
|
+
if (!isObject(value) || visibility?.get(value)?.hidden) return;
|
|
16
17
|
const blockType = typeof value.blockType === 'string' ? value.blockType : typeof value.type === 'string' ? value.type : '';
|
|
17
18
|
const containing = labels.get(blockType) ?? (blockType || label);
|
|
18
19
|
if (typeof value.xpGoal === 'string' && CLICK_KEY.test(value.xpGoal)) into.set(value.xpGoal, containing || value.xpGoal);
|
|
19
|
-
Object.values(value).forEach((item)=>collect(item, into, containing, labels));
|
|
20
|
+
Object.values(value).forEach((item)=>collect(item, into, containing, labels, visibility));
|
|
20
21
|
}
|
|
21
22
|
function blockLabels(req) {
|
|
22
23
|
const labels = new Map();
|
|
@@ -132,16 +133,17 @@ function blockLabels(req) {
|
|
|
132
133
|
} else {
|
|
133
134
|
const registration = puckCollections(options).find((c)=>c.slug === placement.collection);
|
|
134
135
|
if (!registration) continue;
|
|
136
|
+
const visibility = puckVisibility(doc[registration.field]);
|
|
135
137
|
const walk = (value)=>{
|
|
136
138
|
if (Array.isArray(value)) {
|
|
137
139
|
value.forEach(walk);
|
|
138
140
|
return;
|
|
139
141
|
}
|
|
140
|
-
if (!isObject(value)) return;
|
|
142
|
+
if (!isObject(value) || visibility.get(value)?.hidden) return;
|
|
141
143
|
const props = isObject(value.props) ? value.props : undefined;
|
|
142
144
|
const ref = props?.experiment;
|
|
143
145
|
if (value.type === 'ExperimentSlot' && props && (typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined) === experiment.slug) {
|
|
144
|
-
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels);
|
|
146
|
+
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels, visibility);
|
|
145
147
|
return;
|
|
146
148
|
}
|
|
147
149
|
Object.values(value).forEach(walk);
|
|
@@ -22,8 +22,9 @@ export declare const blockRemovalRule: {
|
|
|
22
22
|
prepare(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, exec?: Executor, tests?: readonly PlacementTest[]): Promise<{
|
|
23
23
|
views: RemovedPlacementViews;
|
|
24
24
|
affected: PlacementTest[];
|
|
25
|
+
hidden: Set<string>;
|
|
25
26
|
}>;
|
|
26
27
|
discover(exec: Executor, removed: string[], tests?: readonly PlacementTest[]): Promise<PlacementTest[]>;
|
|
27
28
|
claim(req: PayloadRequest, transaction: unknown, affected: readonly PlacementTest[], collection: string, id: DocId, views: RemovedPlacementViews): RemovalClaims;
|
|
28
|
-
check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval): Promise<void>;
|
|
29
|
+
check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval, hidden?: ReadonlySet<string>): Promise<void>;
|
|
29
30
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
2
|
+
import { documentEditor, puckCollections } from '../options.js';
|
|
1
3
|
import { removableBlockTests } from '../db/placements.js';
|
|
2
4
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
3
|
-
import { lastBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
5
|
+
import { lastBlockPlacementCopy, hiddenBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
4
6
|
import { hasOtherPublishedBlockPlacement } from '../transitions/placements.js';
|
|
5
7
|
import { bulkRemoves } from '../db/bulkPlacementRemoval.js';
|
|
6
|
-
import { localeRequest, placementLocaleContent, removedPlacementViews, placementDocumentKey } from '../blocks/placementLocale.js';
|
|
8
|
+
import { localeRequest, placementLocaleContent, removedPlacementViews, placementDocumentKey, placementLocaleViews, mergedPlacementLocales } from '../blocks/placementLocale.js';
|
|
7
9
|
import { placementSlugs } from '../blocks/bindings.js';
|
|
8
10
|
export function releaseRemovalClaim(req, collection, id, ownKeys) {
|
|
9
11
|
const claims = req.context.xpPlacementRemovals;
|
|
@@ -54,9 +56,29 @@ export const blockRemovalRule = {
|
|
|
54
56
|
const affected = views.size ? await blockRemovalRule.discover(exec, [
|
|
55
57
|
...views.keys()
|
|
56
58
|
], tests) : [];
|
|
59
|
+
const hidden = new Set();
|
|
60
|
+
const options = req.payload.config.custom.xp;
|
|
61
|
+
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
62
|
+
const rawAfter = mergedPlacementLocales(req, collection, before, after);
|
|
63
|
+
if (views.size && !removingPage && registration && documentEditor(options, collection, after) === 'puck') {
|
|
64
|
+
for (const view of placementLocaleViews(req, collection)){
|
|
65
|
+
const viewReq = localeRequest(req, view);
|
|
66
|
+
const visibleBefore = new Set();
|
|
67
|
+
walkVisiblePuck(placementLocaleContent(viewReq, collection, before)?.[registration.field], (block, visibility)=>{
|
|
68
|
+
if (!visibility.hidden && block.type === 'ExperimentSlot') visibleBefore.add(String(block.props.id));
|
|
69
|
+
});
|
|
70
|
+
walkVisiblePuck(placementLocaleContent(viewReq, collection, rawAfter)?.[registration.field], (block, visibility)=>{
|
|
71
|
+
if (!visibility.hidden || block.type !== 'ExperimentSlot' || !visibleBefore.has(String(block.props.id))) return;
|
|
72
|
+
const ref = block.props.experiment;
|
|
73
|
+
const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
|
|
74
|
+
if (typeof slug === 'string') hidden.add(slug);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
57
78
|
return {
|
|
58
79
|
views,
|
|
59
|
-
affected
|
|
80
|
+
affected,
|
|
81
|
+
hidden
|
|
60
82
|
};
|
|
61
83
|
},
|
|
62
84
|
async discover (exec, removed, tests) {
|
|
@@ -101,7 +123,7 @@ export const blockRemovalRule = {
|
|
|
101
123
|
}
|
|
102
124
|
return claims;
|
|
103
125
|
},
|
|
104
|
-
async check (req, current, affected, collection, id, removingPage, views, bulk) {
|
|
126
|
+
async check (req, current, affected, collection, id, removingPage, views, bulk, hidden) {
|
|
105
127
|
const transaction = await req.transactionID;
|
|
106
128
|
// Claim only after every earlier guard passed. These claims cover subsequent
|
|
107
129
|
// writes; the complete bulk selection covers siblings before any can decide.
|
|
@@ -127,7 +149,7 @@ export const blockRemovalRule = {
|
|
|
127
149
|
if (transaction == null) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
128
150
|
// Bulk selection is immutable through every sibling's decision, including
|
|
129
151
|
// earlier rule refusals. afterOperation explains unrelated failed writes.
|
|
130
|
-
const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
|
|
152
|
+
const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : hidden?.has(test.slug) ? hiddenBlockPlacementCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
|
|
131
153
|
if (bulk && excludedSibling) bulk.refusals.set(message, pendingBlockRemovalCopy(test.name));
|
|
132
154
|
throw new XpRefusal('locked-placement', message, {
|
|
133
155
|
experimentId: test.id
|
package/dist/hooks/pageGuard.js
CHANGED
|
@@ -287,7 +287,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
287
287
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
288
288
|
let tests = await placementTests(exec);
|
|
289
289
|
const trashing = Boolean(collection.trash && after.deletedAt != null);
|
|
290
|
-
const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, after, trashing || drafts && after._status !== 'published', exec, tests);
|
|
290
|
+
const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, after, trashing || drafts && after._status !== 'published', exec, tests);
|
|
291
291
|
const publishes = !drafts || after._status === 'published';
|
|
292
292
|
const noTransaction = ()=>{
|
|
293
293
|
if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
@@ -319,7 +319,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
319
319
|
if (old != null && (unpublishing || trashing || page.pathOf(after) !== old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
|
|
320
320
|
}
|
|
321
321
|
if (publishes) refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection.slug);
|
|
322
|
-
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk);
|
|
322
|
+
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk, hidden);
|
|
323
323
|
return data;
|
|
324
324
|
} catch (error) {
|
|
325
325
|
mapBusy(error);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExperimentRef } from '../types/puck.js';
|
|
2
|
-
export declare function ExperimentPicker({ value, onChange }: {
|
|
2
|
+
export declare function ExperimentPicker({ value, onChange, allowEmpty }: {
|
|
3
|
+
allowEmpty?: boolean;
|
|
3
4
|
value: ExperimentRef | null;
|
|
4
5
|
onChange: (value: ExperimentRef | null) => void;
|
|
5
6
|
}): import("react").JSX.Element;
|
|
@@ -9,7 +9,7 @@ function isExperimentOption(value) {
|
|
|
9
9
|
const doc = value;
|
|
10
10
|
return (typeof doc.id === 'string' || typeof doc.id === 'number') && typeof doc.slug === 'string' && typeof doc.name === 'string' && typeof doc.status === 'string' && Object.hasOwn(pickerCopy.statuses, doc.status);
|
|
11
11
|
}
|
|
12
|
-
export function ExperimentPicker({ value, onChange }) {
|
|
12
|
+
export function ExperimentPicker({ value, onChange, allowEmpty = true }) {
|
|
13
13
|
const { api } = usePuckRoutes();
|
|
14
14
|
const id = useId();
|
|
15
15
|
const [experiments, setExperiments] = useState([]);
|
|
@@ -92,35 +92,39 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
92
92
|
htmlFor: id,
|
|
93
93
|
children: pickerCopy.label
|
|
94
94
|
}),
|
|
95
|
-
/*#__PURE__*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
onChange(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
95
|
+
/*#__PURE__*/ _jsx("span", {
|
|
96
|
+
className: "xp-ui-select-wrap",
|
|
97
|
+
children: /*#__PURE__*/ _jsxs("select", {
|
|
98
|
+
id: id,
|
|
99
|
+
className: "xp-ui-input xp-ui-select",
|
|
100
|
+
value: selected,
|
|
101
|
+
onChange: (event)=>{
|
|
102
|
+
const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
|
|
103
|
+
if (experiment || allowEmpty) onChange(experiment ? {
|
|
104
|
+
id: experiment.id,
|
|
105
|
+
slug: experiment.slug
|
|
106
|
+
} : null);
|
|
107
|
+
},
|
|
108
|
+
children: [
|
|
109
|
+
/*#__PURE__*/ _jsx("option", {
|
|
110
|
+
value: "",
|
|
111
|
+
disabled: !allowEmpty,
|
|
112
|
+
children: allowEmpty ? pickerCopy.none : pickerCopy.choose
|
|
113
|
+
}),
|
|
114
|
+
value && !experiments.some((doc)=>String(doc.id) === selected) ? /*#__PURE__*/ _jsx("option", {
|
|
115
|
+
value: selected,
|
|
116
|
+
children: value.slug
|
|
117
|
+
}) : null,
|
|
118
|
+
visible.map((doc)=>/*#__PURE__*/ _jsxs("option", {
|
|
119
|
+
value: String(doc.id),
|
|
120
|
+
children: [
|
|
121
|
+
doc.name,
|
|
122
|
+
" · ",
|
|
123
|
+
pickerCopy.statuses[doc.status]
|
|
124
|
+
]
|
|
125
|
+
}, doc.id))
|
|
126
|
+
]
|
|
127
|
+
})
|
|
124
128
|
}),
|
|
125
129
|
state === 'error' ? /*#__PURE__*/ _jsx("div", {
|
|
126
130
|
className: "xp-ui-banner xp-ui-banner--error",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { fullyHidden } from './visibility.js';
|
|
2
3
|
import { ViewportExposure } from '../client/ViewportExposure.js';
|
|
3
4
|
import { experimentSlotDefaultProps, experimentSlotFields, experimentSlotLabel } from './slotConfig.js';
|
|
4
5
|
import { createExperimentSlotField } from './experimentSlotField.js';
|
|
@@ -16,6 +17,7 @@ export function createExperimentSlot({ routes: inputRoutes } = {}) {
|
|
|
16
17
|
},
|
|
17
18
|
defaultProps: experimentSlotDefaultProps,
|
|
18
19
|
render: (props)=>{
|
|
20
|
+
if (fullyHidden(props._visibility)) return /*#__PURE__*/ _jsx(_Fragment, {});
|
|
19
21
|
const Slot = props[slotToRender(props)];
|
|
20
22
|
return /*#__PURE__*/ _jsx(ViewportExposure, {
|
|
21
23
|
expose: props.xpExpose,
|
package/dist/puck/copy.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const slotLabels: {
|
|
|
8
8
|
export declare const pickerCopy: {
|
|
9
9
|
readonly label: "Test";
|
|
10
10
|
readonly none: "No test";
|
|
11
|
+
readonly choose: "Choose a test";
|
|
11
12
|
readonly search: "Search tests";
|
|
12
13
|
readonly loading: "Loading tests…";
|
|
13
14
|
readonly error: "Couldn't load tests.";
|
package/dist/puck/copy.js
CHANGED
|
@@ -2,7 +2,8 @@ import type { resolvePuckRoutes } from '../routes.js';
|
|
|
2
2
|
import type { ExperimentRef } from '../../types/puck.js';
|
|
3
3
|
import type { Arm } from '../../types/contracts.js';
|
|
4
4
|
import './editor.css';
|
|
5
|
-
export declare function CreateExperimentDrawer({ onCreate, onClose, initialName, arms, label, onPendingChange }: {
|
|
5
|
+
export declare function CreateExperimentDrawer({ onCreate, onClose, initialName, arms, label, onPendingChange, created }: {
|
|
6
|
+
created?: ExperimentRef;
|
|
6
7
|
initialName?: string;
|
|
7
8
|
arms?: Arm[] | (() => Promise<Arm[]>);
|
|
8
9
|
label?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useRef, useState } from 'react';
|
|
4
4
|
import { Dialog } from '../../ui/Dialog.js';
|
|
5
5
|
import { TextInput } from '../../ui/TextInput.js';
|
|
@@ -11,14 +11,14 @@ import { CreateRefused, createTest } from './createTest.js';
|
|
|
11
11
|
import { editorCopy } from './copy.js';
|
|
12
12
|
import { invalidatePlacements } from './placementsCache.js';
|
|
13
13
|
import './editor.css';
|
|
14
|
-
export function CreateExperimentDrawer({ onCreate, onClose, initialName = '', arms, label = editorCopy.
|
|
14
|
+
export function CreateExperimentDrawer({ onCreate, onClose, initialName = '', arms, label = editorCopy.createAnother, onPendingChange, created }) {
|
|
15
15
|
const { api, admin } = usePuckRoutes();
|
|
16
16
|
const nameId = useId();
|
|
17
17
|
const [name, setName] = useState(initialName);
|
|
18
18
|
const inFlight = useRef(false);
|
|
19
19
|
const [pending, setPending] = useState(false);
|
|
20
20
|
const [error, setError] = useState('');
|
|
21
|
-
const [unbound, setUnbound] = useState();
|
|
21
|
+
const [unbound, setUnbound] = useState(created);
|
|
22
22
|
async function submitNew() {
|
|
23
23
|
if (inFlight.current || !name.trim()) return;
|
|
24
24
|
inFlight.current = true;
|
|
@@ -64,32 +64,36 @@ export function CreateExperimentDrawer({ onCreate, onClose, initialName = '', ar
|
|
|
64
64
|
})
|
|
65
65
|
]
|
|
66
66
|
}) : null,
|
|
67
|
-
/*#__PURE__*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
!unbound ? /*#__PURE__*/ _jsxs(_Fragment, {
|
|
68
|
+
children: [
|
|
69
|
+
/*#__PURE__*/ _jsx(TextInput, {
|
|
70
|
+
id: nameId,
|
|
71
|
+
label: editorCopy.name,
|
|
72
|
+
value: name,
|
|
73
|
+
disabled: pending,
|
|
74
|
+
onChange: (event)=>setName(event.currentTarget.value)
|
|
75
|
+
}),
|
|
76
|
+
error ? /*#__PURE__*/ _jsx(Banner, {
|
|
77
|
+
tone: "error",
|
|
78
|
+
children: error
|
|
79
|
+
}) : null,
|
|
80
|
+
!name.trim() ? /*#__PURE__*/ _jsx("p", {
|
|
81
|
+
className: "xp-ui-help",
|
|
82
|
+
children: editorCopy.enterName
|
|
83
|
+
}) : null
|
|
84
|
+
]
|
|
81
85
|
}) : null,
|
|
82
86
|
/*#__PURE__*/ _jsxs("div", {
|
|
83
87
|
className: "xp-ui-button-group",
|
|
84
88
|
children: [
|
|
85
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
89
|
+
!unbound ? /*#__PURE__*/ _jsx(Button, {
|
|
86
90
|
variant: "primary",
|
|
87
|
-
disabled: pending ||
|
|
91
|
+
disabled: pending || !name.trim(),
|
|
88
92
|
onClick: ()=>{
|
|
89
93
|
void submitNew();
|
|
90
94
|
},
|
|
91
95
|
children: pending ? editorCopy.creating : label
|
|
92
|
-
}),
|
|
96
|
+
}) : null,
|
|
93
97
|
/*#__PURE__*/ _jsx(Button, {
|
|
94
98
|
disabled: pending,
|
|
95
99
|
onClick: onClose,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
export declare const CONTROL_SELECTOR = "button, a, summary, label, input, select, textarea, [role=\"tab\"], [role=\"menu\"],
|
|
2
|
+
export declare const CONTROL_SELECTOR = "button, a, summary, label, input, select, textarea, [role=\"tab\"], [role=\"menu\"], [role=\"listbox\"], dialog, [role=\"dialog\"], [contenteditable=\"true\"]";
|
|
3
3
|
/** Give React a delegation boundary before Puck's native component click listeners.
|
|
4
4
|
* A normal React onClick runs too late: native child/parent selection already ran.
|
|
5
5
|
* The portal target is this chrome element in the canvas's ownerDocument, so
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { registerOverlayPortal, useGetPuck } from '@puckeditor/core';
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
|
-
export const CONTROL_SELECTOR = 'button, a, summary, label, input, select, textarea, [role="tab"], [role="menu"],
|
|
6
|
+
export const CONTROL_SELECTOR = 'button, a, summary, label, input, select, textarea, [role="tab"], [role="menu"], [role="listbox"], dialog, [role="dialog"], [contenteditable="true"]';
|
|
7
7
|
/** Give React a delegation boundary before Puck's native component click listeners.
|
|
8
8
|
* A normal React onClick runs too late: native child/parent selection already ran.
|
|
9
9
|
* The portal target is this chrome element in the canvas's ownerDocument, so
|