@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
package/dist/puck/editor/copy.js
CHANGED
|
@@ -17,6 +17,10 @@ export const editorCopy = {
|
|
|
17
17
|
decided: (winner)=>`Decided: ${winner}. Use 'Make it the content' on the test to finish.`,
|
|
18
18
|
archived: 'This test is archived; the winning content is shown to everyone.',
|
|
19
19
|
copy: 'Copy Original here',
|
|
20
|
+
copyEmpty: 'Add content to the Original before copying it.',
|
|
21
|
+
enterName: 'Enter a name to create the test.',
|
|
22
|
+
loadingBeforeNew: 'Wait for this test to load before starting a new one.',
|
|
23
|
+
checkingRemoval: 'Checking whether this test can be removed…',
|
|
20
24
|
dropZone: (slot)=>slot === 'control' ? 'Drop the original content here' : `Drop ${editorCopy.labels[slot]} content here`,
|
|
21
25
|
replaceConfirm: (label)=>`${label} already has content. Replace it with a copy of the Original?`,
|
|
22
26
|
replace: 'Replace',
|
|
@@ -35,18 +39,35 @@ export const editorCopy = {
|
|
|
35
39
|
openTest: 'Open the test',
|
|
36
40
|
nameExists: "This name is too close to an existing test. Choose a different name.",
|
|
37
41
|
createError: "Couldn't create the test. Try again.",
|
|
42
|
+
savingVersions: 'Saving version changes…',
|
|
43
|
+
refreshing: 'Refreshing results…',
|
|
38
44
|
loading: 'Loading test…',
|
|
39
45
|
loadError: "Couldn't load this test. Try selecting it again.",
|
|
40
|
-
orphan: (label)=>`${label} has content
|
|
46
|
+
orphan: (label, versions)=>`${label} has content on this page, but the test only has ${versions}. Visitors never see it.`,
|
|
47
|
+
addLeftover: 'Add to the test',
|
|
48
|
+
deleteContent: 'Delete its content',
|
|
49
|
+
deleteContentTitle: (label)=>`Delete ${label} content?`,
|
|
50
|
+
deleteContentHelp: (label, count)=>`This deletes the ${count} ${count === 1 ? 'block' : 'blocks'} in ${label} from this page. Save the page to keep this change.`,
|
|
51
|
+
draftOnly: 'Only draft tests can add this version. Start a new test from this block to include it.',
|
|
52
|
+
leftovers: (labels)=>`3 versions have content outside this test: ${labels}. Visitors never see them.`,
|
|
53
|
+
outsideTest: (label)=>`${label} · not in this test`,
|
|
41
54
|
tabs: 'Test versions',
|
|
42
55
|
add: 'Add variant',
|
|
43
56
|
menu: (label)=>`Options for ${label}`,
|
|
57
|
+
testGroup: 'Test',
|
|
58
|
+
versionsGroup: 'Versions',
|
|
59
|
+
actionsGroup: 'Actions',
|
|
60
|
+
options: 'Options',
|
|
61
|
+
runningVersions: "Versions can't change while the test runs.",
|
|
62
|
+
removeVersion: 'Remove version',
|
|
44
63
|
rename: 'Rename',
|
|
45
64
|
renameLabel: 'Version name',
|
|
46
65
|
emptyLabel: 'Enter a name for this version.',
|
|
47
66
|
remove: 'Remove',
|
|
48
67
|
removeTitle: (label)=>`Remove ${label}?`,
|
|
49
|
-
removeHelp: 'This removes the version from the test and
|
|
68
|
+
removeHelp: (count)=>count === 0 ? 'This removes the version from the test.' : `This removes the version from the test and deletes its ${count} ${count === 1 ? 'block' : 'blocks'} from this page. Save the page to keep this change.`,
|
|
69
|
+
removeShared: 'This test is also used in another place. The version is removed from the test there too.',
|
|
70
|
+
removeScopeUnknown: 'If this test is used on other pages, the version is removed from the test there too.',
|
|
50
71
|
removed: "Save the page to finish removing this version's content.",
|
|
51
72
|
removeUncleared: "The version was removed from the test, but its content couldn't be cleared here. Delete it from the outline, then save the page.",
|
|
52
73
|
lockedGeneric: "This test's versions can't change. View the test page for details.",
|
|
@@ -64,7 +85,7 @@ export const editorCopy = {
|
|
|
64
85
|
writeNetwork: "Couldn't reach the server. Check your connection and try again.",
|
|
65
86
|
writeUnreadable: "Couldn't read the server's response. Reload and try again.",
|
|
66
87
|
collecting: 'Collecting',
|
|
67
|
-
resultsUnavailable: "Results aren't available here.",
|
|
88
|
+
resultsUnavailable: "Results aren't available here. Try Refresh.",
|
|
68
89
|
refresh: 'Refresh',
|
|
69
90
|
people: (label, count)=>`${label}: ${count} people`
|
|
70
91
|
};
|
|
@@ -166,3 +166,14 @@
|
|
|
166
166
|
.xp-configure-panel .xp-version-rows { grid-template-columns: minmax(0, 1fr) var(--xp-version-share-width-mobile); }
|
|
167
167
|
.xp-configure-panel .xp-version-content, .xp-configure-panel .xp-version-remove { grid-column: 1 / -1; }
|
|
168
168
|
.xp-configure-panel .xp-version-grid-head > :nth-child(n+3) { display: none; }
|
|
169
|
+
|
|
170
|
+
.xp-slot-editor .xp-ui-tabbar { flex: 1 1 auto; min-width: 0; }
|
|
171
|
+
|
|
172
|
+
.xp-slot-weight-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--xp-space-2); }
|
|
173
|
+
.xp-slot-sidebar { display: grid; gap: var(--xp-space-4); }
|
|
174
|
+
.xp-slot-sidebar section, .xp-slot-sidebar section > div { display: grid; gap: var(--xp-space-3); }
|
|
175
|
+
.xp-slot-sidebar h4 { margin: 0; font: inherit; font-weight: 600; }
|
|
176
|
+
.xp-slot-sidebar .xp-slot-weight-inputs { display: grid; }
|
|
177
|
+
.xp-slot-sidebar .xp-slot-weight-inputs .xp-ui-field { max-width: none; flex: 1 1 100%; }
|
|
178
|
+
|
|
179
|
+
.xp-slot-sidebar .xp-slot-version-menu { inset-inline-start: 0; inset-inline-end: auto; }
|
|
@@ -361,6 +361,24 @@
|
|
|
361
361
|
.xp-ui-drawer > .xp-ui-dialog-header h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font: var(--xp-text-title); }
|
|
362
362
|
.xp-ui-drawer-body { min-height: 0; overflow: auto; overscroll-behavior: contain; flex: 1; background: var(--xp-bg); }
|
|
363
363
|
|
|
364
|
+
.xp-ui-section--blocked { border-color: var(--xp-error-border); }
|
|
365
|
+
.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); }
|
|
366
|
+
.xp-ui-section--complete .xp-ui-section-complete { color: var(--xp-success); }
|
|
367
|
+
.xp-ui-section--complete .xp-ui-section-number { color: var(--xp-success); border-color: var(--xp-success); }
|
|
368
|
+
.xp-ui-section--blocked h2:focus { outline-color: var(--xp-error); }
|
|
369
|
+
|
|
370
|
+
.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%; }
|
|
371
|
+
|
|
372
|
+
/* Actions sit beside each tab visually and outside the tablist's owned roles. */
|
|
373
|
+
.xp-ui-tabbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px; border-bottom: 1px solid var(--xp-border); }
|
|
374
|
+
.xp-ui-tabbar > .xp-ui-tablist { display: contents; }
|
|
375
|
+
.xp-ui-tab-actions { display: flex; align-items: center; flex-wrap: wrap; position: relative; }
|
|
376
|
+
|
|
377
|
+
/* One blocker-list format in the admin footer and the Puck sidebar. */
|
|
378
|
+
.xp-readiness__blockers, .xp-readiness__blockers a { color: var(--xp-error); }
|
|
379
|
+
.xp-readiness__blockers ul { margin: 0; padding-inline-start: var(--xp-space-4); }
|
|
380
|
+
.xp-readiness__blockers li { white-space: pre-line; }
|
|
381
|
+
|
|
364
382
|
/* Shared UI controls are assembled into editor.css for the isolated canvas. */
|
|
365
383
|
.xp-slot-editor {
|
|
366
384
|
min-width: 0;
|
|
@@ -529,3 +547,14 @@
|
|
|
529
547
|
.xp-configure-panel .xp-version-rows { grid-template-columns: minmax(0, 1fr) var(--xp-version-share-width-mobile); }
|
|
530
548
|
.xp-configure-panel .xp-version-content, .xp-configure-panel .xp-version-remove { grid-column: 1 / -1; }
|
|
531
549
|
.xp-configure-panel .xp-version-grid-head > :nth-child(n+3) { display: none; }
|
|
550
|
+
|
|
551
|
+
.xp-slot-editor .xp-ui-tabbar { flex: 1 1 auto; min-width: 0; }
|
|
552
|
+
|
|
553
|
+
.xp-slot-weight-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--xp-space-2); }
|
|
554
|
+
.xp-slot-sidebar { display: grid; gap: var(--xp-space-4); }
|
|
555
|
+
.xp-slot-sidebar section, .xp-slot-sidebar section > div { display: grid; gap: var(--xp-space-3); }
|
|
556
|
+
.xp-slot-sidebar h4 { margin: 0; font: inherit; font-weight: 600; }
|
|
557
|
+
.xp-slot-sidebar .xp-slot-weight-inputs { display: grid; }
|
|
558
|
+
.xp-slot-sidebar .xp-slot-weight-inputs .xp-ui-field { max-width: none; flex: 1 1 100%; }
|
|
559
|
+
|
|
560
|
+
.xp-slot-sidebar .xp-slot-version-menu { inset-inline-start: 0; inset-inline-end: auto; }
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
3
|
-
import { createUsePuck, walkTree } from '@puckeditor/core';
|
|
4
|
-
import {
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createUsePuck, useGetPuck, walkTree } from '@puckeditor/core';
|
|
4
|
+
import { useId, useLayoutEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { EXPERIMENT_SLOT_TYPE } from '../../types/puck.js';
|
|
6
|
+
import { slotLabels } from '../copy.js';
|
|
7
|
+
import { useOutlineVersion } from './outlineVersion.js';
|
|
6
8
|
import { useArms } from './armsCache.js';
|
|
7
9
|
const usePuckSelector = createUsePuck();
|
|
8
10
|
const slots = [
|
|
@@ -11,35 +13,93 @@ const slots = [
|
|
|
11
13
|
'variantB',
|
|
12
14
|
'variantC'
|
|
13
15
|
];
|
|
14
|
-
// Puck 0.24.0
|
|
15
|
-
//
|
|
16
|
+
// Puck 0.24.0: defaultSlots prepends in field order (chunk-H65MT2JK:15–18),
|
|
17
|
+
// getZonesByParent/buildLayerNode preserve zone order (chunk-DQXMVPVM:8577–8622),
|
|
18
|
+
// and Layer maps it to direct wrappers (8126–8135). Never rely on a module hash.
|
|
16
19
|
const zone = 'div[class*="Layer-zones"]';
|
|
17
20
|
const chain = (count)=>Array(count).fill(zone).join(' ~ ');
|
|
18
|
-
function SlotRules({ item: [id, testId, emptySlots] }) {
|
|
21
|
+
/** Read Puck's DOM only; the plugin owns the wrapper and the emitted style. */ function SlotRules({ item: [id, testId, emptySlots], root, scope }) {
|
|
19
22
|
const known = useArms(testId ?? undefined);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
const active = useOutlineVersion(useGetPuck(), id);
|
|
24
|
+
const dragging = usePuckSelector((state)=>state.appState.ui?.isDragging ?? false);
|
|
25
|
+
const fixedHidden = useRef([]);
|
|
26
|
+
const style = useRef(null);
|
|
27
|
+
useLayoutEffect(()=>{
|
|
28
|
+
const ownedStyle = style.current;
|
|
29
|
+
const host = root.current ?? ownedStyle?.parentElement;
|
|
30
|
+
if (!host || !ownedStyle || typeof CSS === 'undefined' || typeof CSS.escape !== 'function') return;
|
|
31
|
+
const rowSelector = `[data-xp-outline-scope="${CSS.escape(scope)}"] li[data-puck-layer-tree-id="${CSS.escape(id)}"]`;
|
|
32
|
+
const update = ()=>{
|
|
33
|
+
const rows = [
|
|
34
|
+
...host.querySelectorAll(`li[data-puck-layer-tree-id="${CSS.escape(id)}"]`)
|
|
35
|
+
];
|
|
36
|
+
const row = rows.length === 1 ? rows[0] : undefined;
|
|
37
|
+
const zones = row ? [
|
|
38
|
+
...row.children
|
|
39
|
+
].filter((child)=>child.matches(zone)) : [];
|
|
40
|
+
// Exact count and static field labels guard sibling position, including after
|
|
41
|
+
// a Puck upgrade, a host override, collapse/expand, reorder or virtualization.
|
|
42
|
+
const valid = !!row && zones.length === slots.length && [
|
|
43
|
+
...row.children
|
|
44
|
+
].filter((child)=>child.matches('div[class*="Layer-inner"]')).length === 1 && [
|
|
45
|
+
...row.children
|
|
46
|
+
].every((child)=>child.matches(`${zone}, div[class*="Layer-inner"], div[class*="DropLine"]`)) && zones.every((child, index)=>{
|
|
47
|
+
const label = child.firstElementChild;
|
|
48
|
+
const list = label?.nextElementSibling;
|
|
49
|
+
return label?.matches('div[class*="LayerTree-zoneTitle"]') && label.textContent?.trim() === slotLabels[slots[index]] && list?.matches('ul[class*="LayerTree"]') && !list.nextElementSibling;
|
|
50
|
+
});
|
|
51
|
+
const unknown = testId !== null && !known;
|
|
52
|
+
// A drag's collision shapes were measured before it began. Never hide a
|
|
53
|
+
// previously visible target mid-drag; apply the new tab after it finishes.
|
|
54
|
+
if (!valid || unknown) fixedHidden.current = [];
|
|
55
|
+
else if (!dragging) fixedHidden.current = slots.filter((slot, index)=>testId !== null && active ? slot !== active : slot !== active && slot !== 'control' && !known?.arms.includes(slot) && emptySlots[index]);
|
|
56
|
+
const rules = !valid || unknown ? '' : slots.flatMap((slot, index)=>{
|
|
57
|
+
// No canvas tab is mounted: retain the existing empty-unused-slot behavior.
|
|
58
|
+
if (!fixedHidden.current.includes(slot)) return [];
|
|
59
|
+
// The count guard also disables the rule synchronously if wrappers change.
|
|
60
|
+
const guard = `:has(> ${chain(slots.length)}):not(:has(> ${chain(slots.length + 1)}))`;
|
|
61
|
+
const selector = `${rowSelector}${guard} > ${chain(index + 1)}:not(${chain(index + 2)})`;
|
|
62
|
+
// Hidden descendants have no pointer hit area, including zone drop targets.
|
|
63
|
+
return [
|
|
64
|
+
`${selector} { display: none; pointer-events: none; }`
|
|
65
|
+
];
|
|
66
|
+
}).join('\n');
|
|
67
|
+
if (ownedStyle.textContent !== rules) ownedStyle.textContent = rules;
|
|
68
|
+
};
|
|
69
|
+
update();
|
|
70
|
+
const observer = new MutationObserver(update);
|
|
71
|
+
observer.observe(host, {
|
|
72
|
+
childList: true,
|
|
73
|
+
subtree: true,
|
|
74
|
+
characterData: true,
|
|
75
|
+
attributes: true,
|
|
76
|
+
attributeFilter: [
|
|
77
|
+
'class',
|
|
78
|
+
'data-puck-layer-tree-id'
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
return ()=>{
|
|
82
|
+
observer.disconnect();
|
|
83
|
+
ownedStyle.textContent = '';
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
id,
|
|
87
|
+
testId,
|
|
88
|
+
emptySlots,
|
|
89
|
+
known,
|
|
90
|
+
active,
|
|
91
|
+
dragging,
|
|
92
|
+
root,
|
|
93
|
+
scope
|
|
94
|
+
]);
|
|
37
95
|
return /*#__PURE__*/ _jsx("style", {
|
|
38
|
-
|
|
39
|
-
|
|
96
|
+
ref: style,
|
|
97
|
+
"data-xp-outline": id
|
|
40
98
|
});
|
|
41
99
|
}
|
|
42
100
|
function ExperimentOutline({ children }) {
|
|
101
|
+
const root = useRef(null);
|
|
102
|
+
const scope = useId();
|
|
43
103
|
// Public selector API in Puck 0.24, rather than the deprecated usePuck hook.
|
|
44
104
|
const key = usePuckSelector((state)=>{
|
|
45
105
|
const { data } = state.appState;
|
|
@@ -68,11 +128,19 @@ function ExperimentOutline({ children }) {
|
|
|
68
128
|
});
|
|
69
129
|
// Only binding/emptiness changes rebuild the rules, not edits to other page fields.
|
|
70
130
|
const rules = useMemo(()=>JSON.parse(key).map((item)=>/*#__PURE__*/ _jsx(SlotRules, {
|
|
71
|
-
item: item
|
|
131
|
+
item: item,
|
|
132
|
+
root: root,
|
|
133
|
+
scope: scope
|
|
72
134
|
}, item[0])), [
|
|
73
|
-
key
|
|
135
|
+
key,
|
|
136
|
+
scope
|
|
74
137
|
]);
|
|
75
|
-
return /*#__PURE__*/ _jsxs(
|
|
138
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
139
|
+
ref: root,
|
|
140
|
+
"data-xp-outline-scope": scope,
|
|
141
|
+
style: {
|
|
142
|
+
display: 'contents'
|
|
143
|
+
},
|
|
76
144
|
children: [
|
|
77
145
|
children,
|
|
78
146
|
rules
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ArmSlot } from '../../types/puck.js';
|
|
2
|
+
type Editor = object;
|
|
3
|
+
export declare function publishOutlineVersion(editor: Editor, id: string, slot?: ArmSlot): void;
|
|
4
|
+
export declare function useOutlineVersion(editor: Editor, id: string): ArmSlot | undefined;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useSyncExternalStore } from 'react';
|
|
2
|
+
const editors = new WeakMap();
|
|
3
|
+
function entryFor(editor, id) {
|
|
4
|
+
let entries = editors.get(editor);
|
|
5
|
+
if (!entries) {
|
|
6
|
+
entries = new Map();
|
|
7
|
+
editors.set(editor, entries);
|
|
8
|
+
}
|
|
9
|
+
let entry = entries.get(id);
|
|
10
|
+
if (!entry) {
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
entry = {
|
|
13
|
+
listeners,
|
|
14
|
+
removeListener: (notify)=>{
|
|
15
|
+
listeners.delete(notify);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
entries.set(id, entry);
|
|
19
|
+
}
|
|
20
|
+
return entry;
|
|
21
|
+
}
|
|
22
|
+
export function publishOutlineVersion(editor, id, slot) {
|
|
23
|
+
const entry = entryFor(editor, id);
|
|
24
|
+
if (entry.slot === slot) return;
|
|
25
|
+
entry.slot = slot;
|
|
26
|
+
for (const notify of entry.listeners)notify();
|
|
27
|
+
}
|
|
28
|
+
export function useOutlineVersion(editor, id) {
|
|
29
|
+
const entry = entryFor(editor, id);
|
|
30
|
+
return useSyncExternalStore((notify)=>{
|
|
31
|
+
entry.listeners.add(notify);
|
|
32
|
+
return ()=>{
|
|
33
|
+
entry.removeListener(notify);
|
|
34
|
+
};
|
|
35
|
+
}, ()=>entry.slot, ()=>undefined);
|
|
36
|
+
}
|
|
@@ -12,8 +12,39 @@ export declare function refreshPlacements(api: string, id: DocId): Promise<{
|
|
|
12
12
|
ok: boolean;
|
|
13
13
|
detail?: string;
|
|
14
14
|
}[] | undefined>;
|
|
15
|
-
/**
|
|
16
|
-
export declare function
|
|
15
|
+
/** Focus storms share the last attempt (including polling), at most once per ten seconds. */
|
|
16
|
+
export declare function focusPlacements(api: string, id: DocId): Promise<{
|
|
17
|
+
collection: string;
|
|
18
|
+
id: DocId;
|
|
19
|
+
title: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
editorUrl?: string;
|
|
22
|
+
slots?: Record<import("../../types/puck.js").ArmSlot, number>;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
detail?: string;
|
|
25
|
+
}[] | undefined>;
|
|
17
26
|
export declare function invalidatePlacements(api: string, id: DocId): void;
|
|
27
|
+
/** Listen without starting a request; the drawer already owns its initial preflight. */
|
|
28
|
+
export declare function subscribePlacements(api: string, id: DocId, notify: (placements: Placements | undefined) => void): () => void;
|
|
18
29
|
export declare function acquirePlacements(api: string, id: DocId, notify: (placements: Placements | undefined) => void, fresh?: boolean): () => void;
|
|
30
|
+
/** Drawer preflight uses this same producer and follows a superseding post-write read. */
|
|
31
|
+
export declare function readEditorPreflight(api: string, id: DocId, signal: AbortSignal, supersede?: boolean): Promise<Response>;
|
|
32
|
+
/** Current readiness shares the same request and lifetime as placements. */
|
|
33
|
+
export declare function cachedPreflight(api: string, id: DocId): PreflightResult | undefined;
|
|
34
|
+
/** Mandatory post-write/refusal reads guard Start in every shared consumer. */
|
|
35
|
+
export declare function placementsBlocking(api: string, id: DocId): boolean;
|
|
36
|
+
export declare function placementsPending(api: string, id: DocId): boolean;
|
|
37
|
+
/** Pending reads retain the complete settled classification, including terminal outcomes. */
|
|
38
|
+
export declare function cachedReadinessRead(api: string, id: DocId): {
|
|
39
|
+
status: number;
|
|
40
|
+
loadState: "forbidden" | "error" | "missing" | "ready";
|
|
41
|
+
kind: string;
|
|
42
|
+
answer: PreflightResult | undefined;
|
|
43
|
+
message: "Couldn't check where this test is used. Try again." | "You don't have permission to check where this test is used." | "A page used by this test no longer exists. Choose another page." | "This test's setup couldn't be checked." | "Couldn't check readiness. Try again." | "This test no longer exists." | "This isn't available yet." | "Your session has expired. Sign in again." | "Couldn't load this test. Try selecting it again." | "You don't have access to this test." | "Couldn't load this test." | "You don't have access to this test. You can still edit its content." | "This test isn't available to you. You can still edit its content." | "You can view this test's results." | undefined;
|
|
44
|
+
failed: boolean;
|
|
45
|
+
retry: boolean;
|
|
46
|
+
pollDelay: number | null;
|
|
47
|
+
} | undefined;
|
|
48
|
+
export declare function placementReadError(api: string, id: DocId): string | undefined;
|
|
49
|
+
export declare function watchPlacementNotice(api: string, id: DocId, doc: Document): () => void;
|
|
19
50
|
export {};
|
|
@@ -1,39 +1,66 @@
|
|
|
1
|
+
import { isPreflightResult, readPreflight } from '../../testSurface/readPreflight.js';
|
|
2
|
+
import { classifyReadinessRead } from '../../testSurface/readinessRead.js';
|
|
1
3
|
const cache = new Map();
|
|
4
|
+
const latest = new Map();
|
|
2
5
|
const consumers = new Map();
|
|
3
6
|
const keyFor = (api, id)=>JSON.stringify([
|
|
4
7
|
api,
|
|
5
8
|
String(id)
|
|
6
9
|
]);
|
|
7
|
-
function read(api, id, fresh) {
|
|
10
|
+
function read(api, id, fresh, blocking = false) {
|
|
8
11
|
const key = keyFor(api, id);
|
|
9
12
|
const cached = cache.get(key);
|
|
10
13
|
if (cached && (!fresh || cached.pending)) return cached;
|
|
11
14
|
const controller = new AbortController();
|
|
15
|
+
const previous = latest.get(key);
|
|
12
16
|
const entry = {
|
|
13
17
|
controller,
|
|
14
18
|
pending: true,
|
|
19
|
+
blocking,
|
|
20
|
+
startedAt: Date.now(),
|
|
21
|
+
failures: previous?.failures ?? 0,
|
|
22
|
+
value: previous?.value,
|
|
23
|
+
previousPreflight: previous?.preflight ?? (previous?.pending ? previous.previousPreflight : undefined),
|
|
24
|
+
previousRead: previous?.read ?? previous?.previousRead,
|
|
15
25
|
promise: undefined
|
|
16
26
|
};
|
|
17
27
|
cache.set(key, entry);
|
|
18
|
-
|
|
28
|
+
latest.set(key, entry);
|
|
29
|
+
for (const notify of consumers.get(key)?.listeners ?? [])notify(entry.value);
|
|
19
30
|
entry.promise = (async ()=>{
|
|
20
31
|
try {
|
|
21
|
-
const response = await fetch(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
const { response, body: data } = await readPreflight((signal)=>fetch(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, {
|
|
33
|
+
credentials: 'include',
|
|
34
|
+
cache: 'no-store',
|
|
35
|
+
signal
|
|
36
|
+
}), controller.signal);
|
|
37
|
+
entry.read = classifyReadinessRead(response.status, data, entry.failures + 1, {
|
|
38
|
+
kind: 'where-used'
|
|
25
39
|
});
|
|
26
|
-
if (!response.ok)
|
|
27
|
-
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
entry.response = new Response(JSON.stringify(data), {
|
|
42
|
+
status: response.status,
|
|
43
|
+
headers: response.headers
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!isPreflightResult(data)) return;
|
|
48
|
+
entry.preflight = data;
|
|
49
|
+
if (data.checks?.some((check)=>!check.ok && check.code === 'no-placements' && check.detail !== undefined)) return;
|
|
28
50
|
return Array.isArray(data.placements) ? data.placements : undefined;
|
|
29
51
|
} catch {
|
|
30
52
|
return undefined;
|
|
31
53
|
}
|
|
32
54
|
})().then((placements)=>{
|
|
33
55
|
entry.pending = false;
|
|
56
|
+
entry.read ??= classifyReadinessRead(0, undefined, entry.failures + 1, {
|
|
57
|
+
kind: 'where-used'
|
|
58
|
+
});
|
|
59
|
+
entry.failures = entry.read.failed ? entry.failures + 1 : 0;
|
|
60
|
+
entry.value = placements;
|
|
34
61
|
if (cache.get(key) === entry) {
|
|
35
|
-
if (
|
|
36
|
-
for (const notify of consumers.get(key) ?? [])notify(placements);
|
|
62
|
+
if (!entry.preflight) cache.delete(key);
|
|
63
|
+
for (const notify of consumers.get(key)?.listeners ?? [])notify(placements);
|
|
37
64
|
}
|
|
38
65
|
return placements;
|
|
39
66
|
});
|
|
@@ -42,42 +69,190 @@ function read(api, id, fresh) {
|
|
|
42
69
|
/** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id) {
|
|
43
70
|
return read(api, id, true).promise;
|
|
44
71
|
}
|
|
45
|
-
/**
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else cache.set(key, {
|
|
50
|
-
controller: new AbortController(),
|
|
51
|
-
promise: Promise.resolve(placements),
|
|
52
|
-
pending: false
|
|
53
|
-
});
|
|
54
|
-
for (const notify of consumers.get(key) ?? [])notify(placements);
|
|
72
|
+
/** Focus storms share the last attempt (including polling), at most once per ten seconds. */ export function focusPlacements(api, id) {
|
|
73
|
+
const previous = latest.get(keyFor(api, id));
|
|
74
|
+
if (previous && Date.now() - previous.startedAt < 10_000) return previous.promise;
|
|
75
|
+
return read(api, id, true).promise;
|
|
55
76
|
}
|
|
56
77
|
export function invalidatePlacements(api, id) {
|
|
57
78
|
const key = keyFor(api, id);
|
|
58
79
|
cache.get(key)?.controller.abort();
|
|
59
80
|
cache.delete(key);
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
if (consumers.get(key)?.listeners.size) void read(api, id, true, true).promise;
|
|
82
|
+
else latest.delete(key);
|
|
83
|
+
}
|
|
84
|
+
/** Listen without starting a request; the drawer already owns its initial preflight. */ export function subscribePlacements(api, id, notify) {
|
|
85
|
+
const key = keyFor(api, id);
|
|
86
|
+
let group = consumers.get(key);
|
|
87
|
+
if (!group) {
|
|
88
|
+
const listeners = new Set();
|
|
89
|
+
group = {
|
|
90
|
+
listeners,
|
|
91
|
+
removeListener: (notify)=>{
|
|
92
|
+
listeners.delete(notify);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
consumers.set(key, group);
|
|
96
|
+
}
|
|
97
|
+
const current = group;
|
|
98
|
+
current.listeners.add(notify);
|
|
99
|
+
let listening = true;
|
|
100
|
+
return ()=>{
|
|
101
|
+
if (!listening) return;
|
|
102
|
+
listening = false;
|
|
103
|
+
current.removeListener(notify);
|
|
104
|
+
if (!current.listeners.size && consumers.get(key) === current) {
|
|
105
|
+
consumers.delete(key);
|
|
106
|
+
latest.delete(key);
|
|
107
|
+
cache.get(key)?.controller.abort();
|
|
108
|
+
cache.delete(key);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
62
111
|
}
|
|
63
112
|
export function acquirePlacements(api, id, notify, fresh = false) {
|
|
113
|
+
const release = subscribePlacements(api, id, notify);
|
|
64
114
|
const key = keyFor(api, id);
|
|
65
|
-
let listeners = new Set();
|
|
66
|
-
listeners = consumers.get(key) ?? listeners;
|
|
67
|
-
consumers.set(key, listeners);
|
|
68
|
-
listeners.add(notify);
|
|
69
115
|
const entry = read(api, id, fresh);
|
|
116
|
+
if (entry.value !== undefined) notify(entry.value);
|
|
70
117
|
let active = true;
|
|
71
|
-
void entry.promise.then((
|
|
72
|
-
if (active && cache.get(key) === entry) notify(value);
|
|
118
|
+
void entry.promise.then(()=>{
|
|
119
|
+
if (active && cache.get(key) === entry) notify(entry.value);
|
|
73
120
|
});
|
|
74
121
|
return ()=>{
|
|
75
122
|
active = false;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
123
|
+
release();
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Drawer preflight uses this same producer and follows a superseding post-write read. */ export async function readEditorPreflight(api, id, signal, supersede = false) {
|
|
127
|
+
if (signal.aborted) return new Response(null, {
|
|
128
|
+
status: 503
|
|
129
|
+
});
|
|
130
|
+
const release = subscribePlacements(api, id, ()=>{});
|
|
131
|
+
signal.addEventListener('abort', release, {
|
|
132
|
+
once: true
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
if (supersede) invalidatePlacements(api, id);
|
|
136
|
+
const previous = latest.get(keyFor(api, id));
|
|
137
|
+
let entry = previous && Date.now() - previous.startedAt < 10_000 ? previous : read(api, id, true);
|
|
138
|
+
while(!signal.aborted){
|
|
139
|
+
await entry.promise;
|
|
140
|
+
if (signal.aborted) return new Response(null, {
|
|
141
|
+
status: 503
|
|
142
|
+
});
|
|
143
|
+
const current = latest.get(keyFor(api, id));
|
|
144
|
+
if (current && current !== entry) {
|
|
145
|
+
entry = current;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
return entry.preflight ? Response.json(entry.preflight) : entry.response?.clone() ?? new Response(null, {
|
|
149
|
+
status: 503
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return new Response(null, {
|
|
153
|
+
status: 503
|
|
154
|
+
});
|
|
155
|
+
} finally{
|
|
156
|
+
signal.removeEventListener('abort', release);
|
|
157
|
+
release();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Current readiness shares the same request and lifetime as placements. */ export function cachedPreflight(api, id) {
|
|
161
|
+
const entry = latest.get(keyFor(api, id));
|
|
162
|
+
return entry?.preflight ?? (entry?.pending ? entry.previousPreflight : undefined);
|
|
163
|
+
}
|
|
164
|
+
/** Mandatory post-write/refusal reads guard Start in every shared consumer. */ export function placementsBlocking(api, id) {
|
|
165
|
+
const entry = cache.get(keyFor(api, id));
|
|
166
|
+
return entry?.pending === true && entry.blocking;
|
|
167
|
+
}
|
|
168
|
+
export function placementsPending(api, id) {
|
|
169
|
+
return cache.get(keyFor(api, id))?.pending === true;
|
|
170
|
+
}
|
|
171
|
+
/** Pending reads retain the complete settled classification, including terminal outcomes. */ export function cachedReadinessRead(api, id) {
|
|
172
|
+
const entry = latest.get(keyFor(api, id));
|
|
173
|
+
return entry?.pending ? entry.previousRead : entry?.read;
|
|
174
|
+
}
|
|
175
|
+
export function placementReadError(api, id) {
|
|
176
|
+
return cachedReadinessRead(api, id)?.message;
|
|
177
|
+
}
|
|
178
|
+
const notices = new WeakMap();
|
|
179
|
+
const noticeDelay = (api, id)=>cachedReadinessRead(api, id)?.pollDelay ?? null;
|
|
180
|
+
export function watchPlacementNotice(api, id, doc) {
|
|
181
|
+
let session = notices.get(doc);
|
|
182
|
+
if (!session) {
|
|
183
|
+
const requests = new Map();
|
|
184
|
+
const created = {
|
|
185
|
+
requests,
|
|
186
|
+
removeRequest: (key)=>{
|
|
187
|
+
requests.delete(key);
|
|
188
|
+
},
|
|
189
|
+
visibility: ()=>{},
|
|
190
|
+
schedule: ()=>{}
|
|
191
|
+
};
|
|
192
|
+
created.schedule = ()=>{
|
|
193
|
+
if (created.timer !== undefined) {
|
|
194
|
+
clearTimeout(created.timer);
|
|
195
|
+
created.timer = undefined;
|
|
196
|
+
}
|
|
197
|
+
const eligible = [
|
|
198
|
+
...created.requests.values()
|
|
199
|
+
].filter((request)=>!request.pending && noticeDelay(request.api, request.id) !== null);
|
|
200
|
+
if (doc.visibilityState !== 'visible' || !eligible.length) return;
|
|
201
|
+
created.timer = setTimeout(()=>{
|
|
202
|
+
created.timer = undefined;
|
|
203
|
+
if (doc.visibilityState !== 'visible') return;
|
|
204
|
+
const due = eligible.filter((request)=>created.requests.get(keyFor(request.api, request.id)) === request && request.nextAt <= Date.now());
|
|
205
|
+
for (const request of due){
|
|
206
|
+
request.pending = true;
|
|
207
|
+
void refreshPlacements(request.api, request.id).then(()=>{
|
|
208
|
+
request.pending = false;
|
|
209
|
+
request.nextAt = Date.now() + (noticeDelay(request.api, request.id) ?? 0);
|
|
210
|
+
if (notices.get(doc) === created) created.schedule();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
created.schedule();
|
|
214
|
+
}, Math.max(0, Math.min(...eligible.map((request)=>request.nextAt)) - Date.now()));
|
|
215
|
+
};
|
|
216
|
+
created.visibility = ()=>{
|
|
217
|
+
for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request.api, request.id) ?? 0);
|
|
218
|
+
created.schedule();
|
|
219
|
+
};
|
|
220
|
+
session = created;
|
|
221
|
+
notices.set(doc, session);
|
|
222
|
+
doc.addEventListener('visibilitychange', created.visibility);
|
|
223
|
+
}
|
|
224
|
+
const current = session;
|
|
225
|
+
const key = keyFor(api, id);
|
|
226
|
+
const existing = current.requests.get(key);
|
|
227
|
+
const request = existing ?? {
|
|
228
|
+
api,
|
|
229
|
+
id,
|
|
230
|
+
subscribers: 0,
|
|
231
|
+
nextAt: Date.now() + (noticeDelay(api, id) ?? 0),
|
|
232
|
+
pending: false,
|
|
233
|
+
release: ()=>{}
|
|
234
|
+
};
|
|
235
|
+
request.subscribers++;
|
|
236
|
+
current.requests.set(key, request);
|
|
237
|
+
if (!existing) request.release = subscribePlacements(api, id, ()=>{
|
|
238
|
+
if (placementsPending(api, id)) return;
|
|
239
|
+
// Manual/focus retries also reset the backoff after recovery.
|
|
240
|
+
request.nextAt = Date.now() + (noticeDelay(api, id) ?? 0);
|
|
241
|
+
current.schedule();
|
|
242
|
+
});
|
|
243
|
+
if (!existing || current.timer === undefined) current.schedule();
|
|
244
|
+
let active = true;
|
|
245
|
+
return ()=>{
|
|
246
|
+
if (!active) return;
|
|
247
|
+
active = false;
|
|
248
|
+
if (--request.subscribers === 0) {
|
|
249
|
+
current.removeRequest(key);
|
|
250
|
+
request.release();
|
|
251
|
+
}
|
|
252
|
+
if (!current.requests.size) {
|
|
253
|
+
if (current.timer !== undefined) clearTimeout(current.timer);
|
|
254
|
+
doc.removeEventListener('visibilitychange', current.visibility);
|
|
255
|
+
notices.delete(doc);
|
|
81
256
|
}
|
|
82
257
|
};
|
|
83
258
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExperimentRef } from '../../types/puck.js';
|
|
2
|
+
type Targets = {
|
|
3
|
+
test: HTMLElement;
|
|
4
|
+
controls: HTMLElement;
|
|
5
|
+
onChange: (value: ExperimentRef | null) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function useSidebarTargets(id: string): Targets | undefined;
|
|
8
|
+
/** The custom field owns only its portal destinations and binding callback, never another data reader. */
|
|
9
|
+
export declare function TestSidebarField({ onChange }: {
|
|
10
|
+
onChange: (value: ExperimentRef | null) => void;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export {};
|