@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.
- package/dist/admin/blocks/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +8 -4
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +7 -6
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +91 -37
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/PageWizard.js +1 -0
- package/dist/admin/surface/newTest/newTest.css +3 -1
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +8 -14
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +23 -7
- package/dist/blocks/placementLocale.js +221 -66
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +206 -0
- package/dist/endpoints/index.js +7 -0
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +6 -1
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/goals/fairness.js +43 -34
- package/dist/hooks/blockRemovalRule.d.ts +4 -3
- package/dist/hooks/blockRemovalRule.js +33 -9
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +34 -24
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +5 -1
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +37 -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/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- 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 +405 -394
- package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
- package/dist/puck/editor/LeftoverVersions.js +23 -44
- package/dist/puck/editor/QuickTestActions.js +2 -2
- package/dist/puck/editor/VersionBuilder.d.ts +41 -13
- package/dist/puck/editor/VersionBuilder.js +461 -224
- 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/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +27 -26
- package/dist/puck/editor/copy.js +28 -26
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +138 -17
- package/dist/puck/editor/editor.css +156 -22
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +3 -3
- package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
- package/dist/puck/editor/localPlacements.d.ts +5 -2
- package/dist/puck/editor/localPlacements.js +32 -18
- package/dist/puck/editor/placementsCache.d.ts +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- package/dist/puck/editor/sidebar.d.ts +2 -6
- package/dist/puck/editor/sidebar.js +3 -6
- package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
- package/dist/puck/editor/usePlacementNotice.js +4 -3
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- package/dist/server/recordContentChange.js +37 -20
- package/dist/server/resolveExperimentData.js +6 -3
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/api.d.ts +6 -3
- package/dist/testSurface/api.js +10 -6
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/common.d.ts +4 -0
- package/dist/testSurface/copy/common.js +8 -4
- package/dist/testSurface/copy/languages.d.ts +11 -0
- package/dist/testSurface/copy/languages.js +7 -0
- package/dist/testSurface/copy/readiness.d.ts +2 -1
- package/dist/testSurface/copy/readiness.js +2 -1
- package/dist/testSurface/copy/testPage.d.ts +28 -6
- package/dist/testSurface/copy/testPage.js +28 -6
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/contracts.d.ts +2 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
- package/dist/testSurface/surface/editorPlacement.js +18 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
- package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
- package/dist/testSurface/surface/results/useResults.d.ts +4 -1
- package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
- package/dist/testSurface/surface/test/DeleteTest.js +171 -0
- package/dist/testSurface/surface/test/GoalSection.js +101 -74
- package/dist/testSurface/surface/test/TestSurface.js +29 -9
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
- package/dist/testSurface/surface/useTestDocument.js +20 -4
- package/dist/testSurface/useApi.d.ts +4 -1
- package/dist/transitions/checkStart.d.ts +4 -1
- package/dist/transitions/checkStart.js +117 -14
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/makeContent.js +29 -9
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +33 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/placementInteractions.js +7 -4
- package/dist/transitions/placements.d.ts +26 -1
- package/dist/transitions/placements.js +239 -87
- package/dist/transitions/preflightData.d.ts +2 -1
- package/dist/transitions/preflightData.js +66 -3
- package/dist/transitions/start.js +4 -1
- package/dist/types/endpoints.d.ts +35 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/puck.d.ts +1 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +7 -4
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/Tabs.d.ts +0 -1
- package/dist/ui/Tabs.js +28 -40
- package/dist/ui/ui.css +18 -5
- package/package.json +3 -2
package/dist/hooks/pageGuard.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { refuseNewNestedTests } from './puckNestedTests.js';
|
|
2
|
+
import { hasLocalizedFields } from '../transitions/contentFields.js';
|
|
1
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { previousPublishedContent, storedContent } from '../db/appends.js';
|
|
4
|
+
import { previousPublishedContent, storedContent, placementWriteContent } from '../db/appends.js';
|
|
3
5
|
import { lockPlacementScope, sortLockKeys } from '../db/locks.js';
|
|
4
6
|
import { txExecutor, pooledExecutor } from '../db/executor.js';
|
|
5
7
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
6
8
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
7
9
|
import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../testSurface/copy/readiness.js';
|
|
8
|
-
import {
|
|
10
|
+
import { allPlacementSlugs, mergedPlacementLocales, placementDocumentPaths } from '../blocks/placementLocale.js';
|
|
9
11
|
import { isObject } from '../blocks/model.js';
|
|
10
12
|
import { placementTests, removableBlockTests, appendPlacementDoc } from '../db/placements.js';
|
|
11
13
|
import { isPageBusy } from '../db/pageBusy.js';
|
|
@@ -86,6 +88,9 @@ export const pageGuardBeforeOperation = ({ args, operation })=>{
|
|
|
86
88
|
request: req,
|
|
87
89
|
draft: call.draft === true,
|
|
88
90
|
restore: operation === 'restoreVersion',
|
|
91
|
+
versionId: operation === 'restoreVersion' ? call.id : undefined,
|
|
92
|
+
isBulk,
|
|
93
|
+
publishSpecificLocale: call.publishSpecificLocale,
|
|
89
94
|
bulk,
|
|
90
95
|
pending: false
|
|
91
96
|
});
|
|
@@ -165,14 +170,9 @@ function registration(req, slug) {
|
|
|
165
170
|
return optionsOf(req).pages?.collections.find((entry)=>entry.slug === slug);
|
|
166
171
|
}
|
|
167
172
|
const active = (test)=>test.status === 'running' || test.status === 'decided';
|
|
168
|
-
const
|
|
173
|
+
const documentPathsOf = (req, collection, rows)=>{
|
|
169
174
|
const page = registration(req, collection);
|
|
170
|
-
return page ?
|
|
171
|
-
const path = row ? page.pathOf(row) : null;
|
|
172
|
-
return path === null ? [] : [
|
|
173
|
-
normalisePath(path)
|
|
174
|
-
];
|
|
175
|
-
})) : [];
|
|
175
|
+
return page ? placementDocumentPaths(req, collection, rows, 'all-locales', (doc)=>page.pathOf(doc)) : [];
|
|
176
176
|
};
|
|
177
177
|
/** The later audit also recognises arm-select tags; include those ids in its lock superset. */ function taggedIds(value, ids = new Set()) {
|
|
178
178
|
if (Array.isArray(value)) value.forEach((v)=>taggedIds(v, ids));
|
|
@@ -233,9 +233,9 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
233
233
|
// Keep the earlier page guard's baseline read and every refusal intact.
|
|
234
234
|
const published = page ? await previousPublishedContent(req, collection.slug, id) : await storedContent(req, collection.slug, id);
|
|
235
235
|
if (!published || published._status === 'draft') return;
|
|
236
|
-
const paths =
|
|
236
|
+
const paths = sortLockKeys(documentPathsOf(req, collection.slug, [
|
|
237
237
|
published
|
|
238
|
-
]);
|
|
238
|
+
]).map(normalisePath));
|
|
239
239
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
240
240
|
let tests = page ? await placementTests(exec) : undefined;
|
|
241
241
|
const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && published.deletedAt != null ? undefined : published, {}, true, exec, tests);
|
|
@@ -249,7 +249,7 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
249
249
|
}));
|
|
250
250
|
} else tests = affected;
|
|
251
251
|
} else if (await req.transactionID != null) {
|
|
252
|
-
await lockPlacementScope(exec, guardExperimentIds(tests,
|
|
252
|
+
await lockPlacementScope(exec, guardExperimentIds(tests, allPlacementSlugs(req, collection.slug, published, 'all-locales'), collection.slug, paths, req.context.xpHeldExperiments, taggedIds(published), affected.map((test)=>test.id)), paths);
|
|
253
253
|
tests = await placementTests(exec);
|
|
254
254
|
}
|
|
255
255
|
for (const path of paths)protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), path);
|
|
@@ -272,14 +272,25 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
272
272
|
const options = optionsOf(req);
|
|
273
273
|
try {
|
|
274
274
|
const published = operation === 'create' ? undefined : await previousPublishedContent(req, collection.slug, originalDoc.id);
|
|
275
|
+
// Preserve the localization-off path and its IO. Localized writes mirror
|
|
276
|
+
// the base Payload uses for this operation's unselected languages.
|
|
277
|
+
const stored = operation === 'create' || !hasLocalizedFields(req.payload.config.collections?.find((entry)=>entry.slug === collection.slug)?.fields ?? [], req.payload.config) ? published : await placementWriteContent(req, collection.slug, originalDoc.id, published ?? await storedContent(req, collection.slug, originalDoc.id), {
|
|
278
|
+
versionId: call?.versionId,
|
|
279
|
+
bulk: call?.isBulk,
|
|
280
|
+
draft: call?.draft,
|
|
281
|
+
publishSpecificLocale: call?.publishSpecificLocale,
|
|
282
|
+
trashing: Boolean(collection.trash && data.deletedAt != null)
|
|
283
|
+
});
|
|
275
284
|
const before = published?._status === 'draft' ? undefined : published;
|
|
276
|
-
const beforeSlugs =
|
|
277
|
-
const
|
|
278
|
-
const
|
|
285
|
+
const beforeSlugs = allPlacementSlugs(req, collection.slug, before, 'all-locales');
|
|
286
|
+
const rawAfter = mergedPlacementLocales(req, collection.slug, stored, after);
|
|
287
|
+
const afterSlugs = allPlacementSlugs(req, collection.slug, rawAfter, 'all-locales');
|
|
288
|
+
const oldPaths = documentPathsOf(req, collection.slug, [
|
|
279
289
|
before
|
|
280
|
-
]),
|
|
281
|
-
|
|
290
|
+
]), newPaths = documentPathsOf(req, collection.slug, [
|
|
291
|
+
rawAfter
|
|
282
292
|
]);
|
|
293
|
+
const beforePaths = sortLockKeys(oldPaths.map(normalisePath)), afterPaths = sortLockKeys(newPaths.map(normalisePath));
|
|
283
294
|
const paths = sortLockKeys([
|
|
284
295
|
...beforePaths,
|
|
285
296
|
...afterPaths
|
|
@@ -287,7 +298,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
287
298
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
288
299
|
let tests = await placementTests(exec);
|
|
289
300
|
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,
|
|
301
|
+
const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, rawAfter, trashing || drafts && after._status !== 'published', exec, tests, 'all-locales');
|
|
291
302
|
const publishes = !drafts || after._status === 'published';
|
|
292
303
|
const noTransaction = ()=>{
|
|
293
304
|
if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
@@ -300,7 +311,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
300
311
|
...afterSlugs
|
|
301
312
|
], collection.slug, paths, req.context.xpHeldExperiments, taggedIds([
|
|
302
313
|
before,
|
|
303
|
-
|
|
314
|
+
rawAfter
|
|
304
315
|
]), affected.map((test)=>test.id)), paths);
|
|
305
316
|
tests = await placementTests(exec);
|
|
306
317
|
} catch (error) {
|
|
@@ -312,14 +323,13 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
312
323
|
}
|
|
313
324
|
}
|
|
314
325
|
if (operation === 'update' && before) {
|
|
315
|
-
const page = registration(req, collection.slug);
|
|
316
|
-
const old = page?.pathOf(before);
|
|
317
326
|
const unpublishing = drafts && data._status === 'draft';
|
|
318
327
|
const trashing = collection.trash && data.deletedAt != null && !originalDoc.deletedAt;
|
|
319
|
-
|
|
328
|
+
for (const old of oldPaths)if (unpublishing || trashing || !newPaths.includes(old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
|
|
320
329
|
}
|
|
330
|
+
if (publishes) refuseNewNestedTests(req, collection.slug, before, rawAfter, tests);
|
|
321
331
|
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);
|
|
332
|
+
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk, hidden);
|
|
323
333
|
return data;
|
|
324
334
|
} catch (error) {
|
|
325
335
|
mapBusy(error);
|
|
@@ -334,7 +344,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
334
344
|
try {
|
|
335
345
|
const stored = await storedContent(req, collection.slug, doc.id);
|
|
336
346
|
if (!stored) throw new Error('The saved placement row was not found.');
|
|
337
|
-
const slugs =
|
|
347
|
+
const slugs = allPlacementSlugs(req, collection.slug, stored, 'all-locales');
|
|
338
348
|
// A later publish in this transaction can restore an earlier removal. Only
|
|
339
349
|
// clear its claim once the stored published row actually contains the block.
|
|
340
350
|
const claims = req.context.xpPlacementRemovals;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
/** Called by the page guard with its published baseline and merged write, only on publish.
|
|
3
|
+
* Puck's public reducer bypasses slot disallow; this server check covers that path.
|
|
4
|
+
*/
|
|
5
|
+
export declare function refuseNewNestedTests(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, tests: readonly {
|
|
6
|
+
slug: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}[]): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ValidationError } from 'payload';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { puckCollections } from '../options.js';
|
|
4
|
+
import { nestedTests, nestedTestKey, nestedTestLabel, nestedTestSlug, nearestOuterTest } from '../puck/nestedTests.js';
|
|
5
|
+
import { nestedTestCopy } from '../puck/nestedTestCopy.js';
|
|
6
|
+
/** Called by the page guard with its published baseline and merged write, only on publish.
|
|
7
|
+
* Puck's public reducer bypasses slot disallow; this server check covers that path.
|
|
8
|
+
*/ export function refuseNewNestedTests(req, collection, before, after, tests) {
|
|
9
|
+
const options = req.payload.config.custom?.xp;
|
|
10
|
+
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
11
|
+
if (!registration) return;
|
|
12
|
+
const reader = placementReader(req, collection, options);
|
|
13
|
+
for (const view of reader.views){
|
|
14
|
+
const read = (doc)=>{
|
|
15
|
+
const content = reader.read(doc, 'all-locales', view);
|
|
16
|
+
return content.editor === 'puck' ? nestedTests(content.doc?.[registration.field]) : [];
|
|
17
|
+
};
|
|
18
|
+
const existing = new Set(read(before).map(nestedTestKey));
|
|
19
|
+
const additions = read(after).filter((pair)=>!existing.has(nestedTestKey(pair)));
|
|
20
|
+
const added = additions[0];
|
|
21
|
+
if (!added) continue;
|
|
22
|
+
const name = (block)=>tests.find((test)=>test.slug === nestedTestSlug(block))?.name ?? nestedTestLabel(block);
|
|
23
|
+
const message = nestedTestCopy.publish(name(nearestOuterTest(additions, added.inner.props.id)), name(added.inner));
|
|
24
|
+
const error = new ValidationError({
|
|
25
|
+
collection,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
path: registration.field,
|
|
29
|
+
message
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
error.message = message;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -4,6 +4,7 @@ export type PreviewPage = Placement & {
|
|
|
4
4
|
key: string;
|
|
5
5
|
slotCount: number;
|
|
6
6
|
};
|
|
7
|
-
/**
|
|
7
|
+
/** Localized responses are already grouped by the server. Legacy single-language
|
|
8
|
+
* responses contain occurrences; preserve their page grouping and version counts. */
|
|
8
9
|
export declare function placementPages(placements: readonly Placement[], flagPoint?: string): PreviewPage[];
|
|
9
10
|
export {};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Localized responses are already grouped by the server. Legacy single-language
|
|
2
|
+
* responses contain occurrences; preserve their page grouping and version counts. */ export function placementPages(placements, flagPoint) {
|
|
3
|
+
if (placements.some((placement)=>placement.allLocales || placement.locales?.length)) {
|
|
4
|
+
return placements.map((placement, index)=>({
|
|
5
|
+
...placement,
|
|
6
|
+
key: String(index),
|
|
7
|
+
slotCount: placement.slotCount ?? 1
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
2
10
|
const pages = new Map();
|
|
3
11
|
for (const [index, placement] of placements.entries()){
|
|
4
12
|
const key = `${placement.collection}\u0000${String(placement.id)}${placement.collection === flagPoint ? `\u0000${index}` : ''}`;
|
|
@@ -15,7 +23,7 @@
|
|
|
15
23
|
page: {
|
|
16
24
|
...placement,
|
|
17
25
|
key,
|
|
18
|
-
slotCount: 1
|
|
26
|
+
slotCount: placement.slotCount ?? 1
|
|
19
27
|
},
|
|
20
28
|
versions: new Map([
|
|
21
29
|
[
|
|
@@ -46,9 +46,10 @@ export interface ManifestInputs {
|
|
|
46
46
|
excludeIds?: DocId[];
|
|
47
47
|
pruneFlagDefaultIds?: DocId[];
|
|
48
48
|
}
|
|
49
|
-
export declare function loadManifestInputs(req: PayloadRequest, { excludeIds, pruneFlagDefaultIds }?: {
|
|
49
|
+
export declare function loadManifestInputs(req: PayloadRequest, { excludeIds, pruneFlagDefaultIds, signal }?: {
|
|
50
50
|
excludeIds?: DocId[];
|
|
51
51
|
pruneFlagDefaultIds?: DocId[];
|
|
52
|
+
signal?: AbortSignal;
|
|
52
53
|
}): Promise<ManifestInputs>;
|
|
53
54
|
/** Pure compiler. Assignment config comes exclusively from the frozen phase. */
|
|
54
55
|
/**
|
package/dist/manifest/compile.js
CHANGED
|
@@ -2,7 +2,8 @@ import { txExecutor } from '../db/executor.js';
|
|
|
2
2
|
import { bumpRevision, writeManifest } from '../db/state.js';
|
|
3
3
|
import { XpRefusal } from '../errors.js';
|
|
4
4
|
import { xpOptionsFromReq } from '../options/fromReq.js';
|
|
5
|
-
export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaultIds = [] } = {}) {
|
|
5
|
+
export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaultIds = [], signal } = {}) {
|
|
6
|
+
signal?.throwIfAborted();
|
|
6
7
|
// §7.8 manifest reads: transitions compile all live/archived routing state.
|
|
7
8
|
const result = await req.payload.find({
|
|
8
9
|
collection: 'xp-experiments',
|
|
@@ -20,6 +21,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
});
|
|
24
|
+
signal?.throwIfAborted();
|
|
23
25
|
const excluded = new Set(excludeIds.map(String));
|
|
24
26
|
const experiments = [];
|
|
25
27
|
for (const doc of result.docs){
|
|
@@ -44,6 +46,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
44
46
|
},
|
|
45
47
|
sort: '-phase'
|
|
46
48
|
});
|
|
49
|
+
signal?.throwIfAborted();
|
|
47
50
|
const rollout = phases.docs[0]?.phaseKind === 'rollout';
|
|
48
51
|
// §7.8 manifest reads: runtime rollout ranges use the test's full weights (including their exact
|
|
49
52
|
// floating-point sum) and its control content. The rollout record has only
|
|
@@ -64,6 +67,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
64
67
|
},
|
|
65
68
|
sort: '-phase'
|
|
66
69
|
}) : null;
|
|
70
|
+
signal?.throwIfAborted();
|
|
67
71
|
if (rollout && !test?.docs[0]) throw new Error('Missing test phase for rollout ' + doc.id);
|
|
68
72
|
experiments.push({
|
|
69
73
|
...doc,
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { SelectControl } from '../ui/SelectControl.js';
|
|
3
4
|
import { useEffect, useId, useState } from 'react';
|
|
4
5
|
import { fetchAllDocs } from '../lib/fetchAllDocs.js';
|
|
5
6
|
import { usePuckRoutes } from './hostContext.js';
|
|
@@ -9,7 +10,7 @@ function isExperimentOption(value) {
|
|
|
9
10
|
const doc = value;
|
|
10
11
|
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
12
|
}
|
|
12
|
-
export function ExperimentPicker({ value, onChange }) {
|
|
13
|
+
export function ExperimentPicker({ value, onChange, allowEmpty = true }) {
|
|
13
14
|
const { api } = usePuckRoutes();
|
|
14
15
|
const id = useId();
|
|
15
16
|
const [experiments, setExperiments] = useState([]);
|
|
@@ -88,38 +89,44 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
88
89
|
})
|
|
89
90
|
]
|
|
90
91
|
}) : null,
|
|
91
|
-
/*#__PURE__*/
|
|
92
|
-
|
|
93
|
-
children: pickerCopy.label
|
|
94
|
-
}),
|
|
95
|
-
/*#__PURE__*/ _jsxs("select", {
|
|
96
|
-
id: id,
|
|
97
|
-
className: "xp-ui-input xp-ui-select",
|
|
98
|
-
value: selected,
|
|
99
|
-
onChange: (event)=>{
|
|
100
|
-
const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
|
|
101
|
-
onChange(experiment ? {
|
|
102
|
-
id: experiment.id,
|
|
103
|
-
slug: experiment.slug
|
|
104
|
-
} : null);
|
|
105
|
-
},
|
|
92
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
93
|
+
className: "xp-ui-field",
|
|
106
94
|
children: [
|
|
107
|
-
/*#__PURE__*/ _jsx("
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
/*#__PURE__*/ _jsx("label", {
|
|
96
|
+
id: `${id}-label`,
|
|
97
|
+
htmlFor: id,
|
|
98
|
+
children: pickerCopy.label
|
|
110
99
|
}),
|
|
111
|
-
|
|
100
|
+
/*#__PURE__*/ _jsxs(SelectControl, {
|
|
101
|
+
id: id,
|
|
112
102
|
value: selected,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
onChange: (event)=>{
|
|
104
|
+
const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
|
|
105
|
+
if (experiment || allowEmpty) onChange(experiment ? {
|
|
106
|
+
id: experiment.id,
|
|
107
|
+
slug: experiment.slug
|
|
108
|
+
} : null);
|
|
109
|
+
},
|
|
110
|
+
children: [
|
|
111
|
+
/*#__PURE__*/ _jsx("option", {
|
|
112
|
+
value: "",
|
|
113
|
+
disabled: !allowEmpty,
|
|
114
|
+
children: allowEmpty ? pickerCopy.none : pickerCopy.choose
|
|
115
|
+
}),
|
|
116
|
+
value && !experiments.some((doc)=>String(doc.id) === selected) ? /*#__PURE__*/ _jsx("option", {
|
|
117
|
+
value: selected,
|
|
118
|
+
children: value.slug
|
|
119
|
+
}) : null,
|
|
120
|
+
visible.map((doc)=>/*#__PURE__*/ _jsxs("option", {
|
|
121
|
+
value: String(doc.id),
|
|
122
|
+
children: [
|
|
123
|
+
doc.name,
|
|
124
|
+
" · ",
|
|
125
|
+
pickerCopy.statuses[doc.status]
|
|
126
|
+
]
|
|
127
|
+
}, doc.id))
|
|
128
|
+
]
|
|
129
|
+
})
|
|
123
130
|
]
|
|
124
131
|
}),
|
|
125
132
|
state === 'error' ? /*#__PURE__*/ _jsx("div", {
|
|
@@ -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
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import type { DocId } from '../../types/contracts.js';
|
|
2
2
|
import type { resolvePuckRoutes } from '../routes.js';
|
|
3
3
|
import './editor.css';
|
|
4
|
+
type ConfigureRoutes = ReturnType<typeof resolvePuckRoutes> & {
|
|
5
|
+
contentLocale?: string;
|
|
6
|
+
};
|
|
4
7
|
export declare function ConfigureTestDrawer({ id, routes, onClose }: {
|
|
5
8
|
id: DocId;
|
|
6
|
-
routes:
|
|
9
|
+
routes: ConfigureRoutes;
|
|
7
10
|
onClose: () => void;
|
|
8
11
|
}): import("react").JSX.Element;
|
|
9
12
|
/** Separate document root, like the creation dialog: Puck has no ancestor handlers here. */
|
|
10
|
-
export declare function openConfigureTestDrawer(source: HTMLElement, routes:
|
|
13
|
+
export declare function openConfigureTestDrawer(source: HTMLElement, routes: ConfigureRoutes, id: DocId): {
|
|
11
14
|
close: () => void;
|
|
12
15
|
};
|
|
13
16
|
/** The canvas already has current permissions; use them without a second read. */
|
|
14
17
|
export declare function ConfigureTestControl({ id, routes }: {
|
|
15
18
|
id: DocId;
|
|
16
|
-
routes:
|
|
19
|
+
routes: ConfigureRoutes;
|
|
17
20
|
}): import("react").JSX.Element;
|
|
18
21
|
export declare function ConfigureTestButton({ id, routes }: {
|
|
19
22
|
id: DocId;
|
|
20
|
-
routes:
|
|
23
|
+
routes: ConfigureRoutes;
|
|
21
24
|
}): import("react").JSX.Element | null;
|
|
25
|
+
export {};
|
|
@@ -24,7 +24,8 @@ export function ConfigureTestDrawer({ id, routes, onClose }) {
|
|
|
24
24
|
surface: {
|
|
25
25
|
...result.surface,
|
|
26
26
|
adminRoute: routes.admin,
|
|
27
|
-
apiRoute: routes.api
|
|
27
|
+
apiRoute: routes.api,
|
|
28
|
+
contentLocale: routes.contentLocale
|
|
28
29
|
}
|
|
29
30
|
} : result);
|
|
30
31
|
});
|
|
@@ -34,6 +35,7 @@ export function ConfigureTestDrawer({ id, routes, onClose }) {
|
|
|
34
35
|
}, [
|
|
35
36
|
routes.api,
|
|
36
37
|
routes.admin,
|
|
38
|
+
routes.contentLocale,
|
|
37
39
|
attempt
|
|
38
40
|
]);
|
|
39
41
|
// Unknown permissions use the test page's authoritative admin access check.
|
|
@@ -67,7 +69,7 @@ export function ConfigureTestDrawer({ id, routes, onClose }) {
|
|
|
67
69
|
embedded: true,
|
|
68
70
|
onTitleChange: setTitle,
|
|
69
71
|
onDocument: (doc)=>publishExperiment(id, doc),
|
|
70
|
-
requestPreflight: (signal, supersede)=>readEditorPreflight(routes.api, id, signal, supersede)
|
|
72
|
+
requestPreflight: (signal, supersede)=>readEditorPreflight(routes.api, id, signal, supersede, routes.contentLocale)
|
|
71
73
|
}) : /*#__PURE__*/ _jsxs("div", {
|
|
72
74
|
role: state.error ? 'alert' : 'status',
|
|
73
75
|
children: [
|
|
@@ -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
|