@delmaredigital/payload-experiments 0.4.0-rc.3 → 0.4.0-rc.4
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/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +2 -2
- package/dist/admin/PlacementStatus.js +1 -1
- package/dist/admin/TestsDashboardCards.js +2 -2
- package/dist/admin/TestsNavLink.js +2 -2
- package/dist/admin/blocks/BlockPanel.js +3 -3
- package/dist/admin/blocks/TestBlockField.js +3 -3
- package/dist/admin/blocks/formApi.js +1 -1
- package/dist/admin/blocks/model.js +1 -1
- package/dist/admin/blocks/statusCache.js +1 -1
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +2 -2
- package/dist/admin/copy/blocks.js +3 -2
- package/dist/admin/copy/goals.d.ts +5 -1
- package/dist/admin/copy/goals.js +9 -3
- package/dist/admin/goals/XpGoalField.js +155 -129
- package/dist/admin/goals/xpGoalField.css +2 -3
- package/dist/admin/status.model.js +1 -1
- package/dist/admin/surface/ResultsRoute.d.ts +2 -1
- package/dist/admin/surface/ResultsRoute.js +4 -3
- package/dist/admin/surface/SurfaceShell.js +2 -2
- package/dist/admin/surface/TestsHome.d.ts +1 -1
- package/dist/admin/surface/TestsHome.js +3 -3
- package/dist/admin/surface/TestsSurface.js +2 -2
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
- package/dist/admin/surface/goals/GoalForm.js +55 -7
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +4 -4
- package/dist/admin/surface/goals/data.js +2 -2
- package/dist/admin/surface/goals/goals.css +7 -0
- package/dist/admin/surface/goals/goals.model.d.ts +11 -1
- package/dist/admin/surface/goals/goals.model.js +43 -0
- package/dist/admin/surface/home.model.d.ts +1 -1
- package/dist/admin/surface/home.model.js +5 -5
- package/dist/admin/surface/newTest/NewTest.d.ts +1 -1
- package/dist/admin/surface/newTest/NewTest.js +1 -1
- package/dist/admin/surface/newTest/PageWizard.d.ts +1 -1
- package/dist/admin/surface/newTest/PageWizard.js +13 -13
- package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
- package/dist/admin/surface/results/ResultsHeader.js +8 -8
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +45 -156
- package/dist/admin/views/ExperimentsRootView.js +1 -1
- package/dist/admin/views/TestsNavLinkServer.js +1 -1
- package/dist/admin/views/renderCollectionList.js +1 -1
- package/dist/admin/views/renderTestsSurface.js +1 -1
- package/dist/blocks/placementLocale.d.ts +21 -0
- package/dist/blocks/placementLocale.js +115 -0
- package/dist/collections/experiments/config.js +1 -1
- package/dist/collections/metrics.js +1 -1
- package/dist/db/bulkPlacementRemoval.d.ts +30 -0
- package/dist/db/bulkPlacementRemoval.js +107 -0
- package/dist/db/placements.d.ts +2 -0
- package/dist/db/placements.js +8 -0
- package/dist/endpoints/editorSurface.d.ts +3 -0
- package/dist/endpoints/editorSurface.js +31 -0
- package/dist/endpoints/index.js +28 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fields/xpGoal.js +1 -1
- package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
- package/dist/goals/picker/clickGoalPicker.model.js +20 -2
- package/dist/goals/picker/copy.d.ts +4 -2
- package/dist/goals/picker/copy.js +4 -2
- package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
- package/dist/goals/picker/useClickGoalPicker.js +4 -2
- package/dist/hooks/blockRemovalRule.d.ts +29 -0
- package/dist/hooks/blockRemovalRule.js +141 -0
- package/dist/hooks/pageGuard.d.ts +24 -2
- package/dist/hooks/pageGuard.js +178 -24
- package/dist/lib/placementPages.d.ts +9 -0
- package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +1 -4
- package/dist/onInit.js +22 -0
- package/dist/plugin.js +2 -1
- package/dist/puck/ExperimentPicker.js +25 -10
- package/dist/puck/copy.d.ts +4 -1
- package/dist/puck/copy.js +4 -1
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +21 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +147 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +11 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +69 -9
- package/dist/puck/editor/EditorControls.d.ts +14 -0
- package/dist/puck/editor/EditorControls.js +99 -0
- package/dist/puck/editor/ExperimentSlotEditor.js +317 -51
- package/dist/puck/editor/ResultsReadout.js +3 -5
- package/dist/puck/editor/VersionBuilder.js +2 -2
- package/dist/puck/editor/armsCache.d.ts +3 -1
- package/dist/puck/editor/armsCache.js +20 -3
- package/dist/puck/editor/copy.d.ts +18 -2
- package/dist/puck/editor/copy.js +19 -3
- package/dist/puck/editor/editor.chrome.css +33 -0
- package/dist/puck/editor/editor.css +39 -0
- package/dist/puck/editor/editor.model.d.ts +14 -0
- package/dist/puck/editor/editor.model.js +58 -1
- package/dist/puck/editor/editorSurface.d.ts +10 -0
- package/dist/puck/editor/editorSurface.js +65 -0
- package/dist/puck/editor/localPlacements.d.ts +2 -0
- package/dist/puck/editor/localPlacements.js +29 -0
- package/dist/puck/editor/placementsCache.d.ts +19 -0
- package/dist/puck/editor/placementsCache.js +83 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +109 -98
- package/dist/puck/experimentSlotField.d.ts +3 -0
- package/dist/puck/experimentSlotField.js +15 -4
- package/dist/{admin → testSurface}/actions/DecideDialog.d.ts +2 -1
- package/dist/{admin → testSurface}/actions/DecideDialog.js +6 -4
- package/dist/{admin → testSurface}/api.js +4 -5
- package/dist/{admin → testSurface}/copy/common.d.ts +2 -0
- package/dist/{admin → testSurface}/copy/common.js +2 -0
- package/dist/{admin → testSurface}/copy/readiness.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/readiness.js +3 -0
- package/dist/{admin → testSurface}/copy/testPage.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/testPage.js +7 -2
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/placements/placementLabels.js +1 -1
- package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
- package/dist/testSurface/previewLinks.model.js +4 -0
- package/dist/testSurface/results/results.css +64 -0
- package/dist/{admin → testSurface}/surface/contracts.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/pageBlock/parts.js +6 -6
- package/dist/testSurface/surface/pagePicker/pagePicker.css +10 -0
- package/dist/{admin → testSurface}/surface/readiness/useTransition.js +1 -0
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +2 -2
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +18 -11
- package/dist/testSurface/surface/setting/setting.css +17 -0
- package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
- package/dist/{admin → testSurface}/surface/test/GoalSection.js +3 -2
- package/dist/testSurface/surface/test/TestSurface.d.ts +18 -0
- package/dist/testSurface/surface/test/TestSurface.js +152 -0
- package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
- package/dist/{admin → testSurface}/surface/test/VersionsSection.js +12 -6
- package/dist/testSurface/surface/test/testPage.css +92 -0
- package/dist/{admin → testSurface}/surface/useTestDocument.d.ts +5 -1
- package/dist/{admin → testSurface}/surface/useTestDocument.js +34 -3
- package/dist/{admin → testSurface}/surfaceUrls.js +1 -1
- package/dist/transitions/placementInteractions.js +1 -1
- package/dist/transitions/placements.d.ts +27 -8
- package/dist/transitions/placements.js +77 -6
- package/dist/transitions/start.js +2 -2
- package/dist/types/endpoints.d.ts +1 -1
- package/dist/ui/Dialog.d.ts +4 -1
- package/dist/ui/Dialog.js +41 -3
- package/dist/ui/Drawer.d.ts +10 -0
- package/dist/ui/Drawer.js +29 -0
- package/dist/ui/Tabs.d.ts +3 -3
- package/dist/ui/Tabs.js +35 -33
- package/dist/ui/ui.css +6 -0
- package/package.json +1 -1
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/results/results.css +0 -64
- package/dist/admin/styles.css +0 -10
- package/dist/admin/styles.d.ts +0 -2
- package/dist/admin/styles.js +0 -3
- package/dist/admin/surface/pagePicker/pagePicker.css +0 -10
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
- package/dist/admin/surface/test/testPage.css +0 -92
- /package/dist/{admin → testSurface}/PreviewLinks.d.ts +0 -0
- /package/dist/{admin → testSurface}/PreviewLinks.js +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.js +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.js +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/allocation.model.js +0 -0
- /package/dist/{admin → testSurface}/api.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
- /package/dist/{admin → testSurface}/copy/actions.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/actions.js +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
- /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/arms.js +0 -0
- /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/audience.js +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.js +0 -0
- /package/dist/{admin → testSurface}/copy/pages.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/pages.js +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
- /package/dist/{admin → testSurface}/copy/results.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/results.js +0 -0
- /package/dist/{admin → testSurface}/copy/review.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/review.js +0 -0
- /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/setting.js +0 -0
- /package/dist/{admin → testSurface}/copy/surface.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/surface.js +0 -0
- /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
- /package/dist/{admin → testSurface}/format/date.js +0 -0
- /package/dist/{admin → testSurface}/labels.d.ts +0 -0
- /package/dist/{admin → testSurface}/labels.js +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.js +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
- /package/dist/{admin → testSurface}/reload.d.ts +0 -0
- /package/dist/{admin → testSurface}/reload.js +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.js +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
- /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/format.js +0 -0
- /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/legacy.js +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
- /package/dist/{admin → testSurface}/results/results.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/results.model.js +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
- /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/review/review.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/useTransition.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Section.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Section.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.js +0 -0
- /package/dist/{admin → testSurface}/surfaceUrls.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
- /package/dist/{admin → testSurface}/theme.d.ts +0 -0
- /package/dist/{admin → testSurface}/theme.js +0 -0
- /package/dist/{admin → testSurface}/useApi.d.ts +0 -0
- /package/dist/{admin → testSurface}/useApi.js +0 -0
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export declare const editorCopy: {
|
|
2
|
+
readonly retrySetup: "Retry";
|
|
3
|
+
readonly controlsUnavailable: "Test controls couldn't load.";
|
|
4
|
+
readonly setupForbidden: "You don't have access to set up tests.";
|
|
5
|
+
readonly setupUnavailable: "Setup isn't available right now.";
|
|
2
6
|
readonly labels: {
|
|
3
7
|
readonly control: "Original";
|
|
4
8
|
readonly variantA: "Variant A";
|
|
@@ -6,6 +10,11 @@ export declare const editorCopy: {
|
|
|
6
10
|
readonly variantC: "Variant C";
|
|
7
11
|
readonly holdout: "Holdout";
|
|
8
12
|
};
|
|
13
|
+
readonly configure: "Configure test";
|
|
14
|
+
readonly openInTab: "Open in a new tab";
|
|
15
|
+
readonly closeConfigure: "Close";
|
|
16
|
+
readonly selectBlock: "Select this test block";
|
|
17
|
+
readonly placementsError: "Couldn't check where this test is used. Try again.";
|
|
9
18
|
readonly notSetUp: "Not set up";
|
|
10
19
|
readonly unbound: "Choose or create a test to show different versions.";
|
|
11
20
|
readonly draft: "This block shows the Original to everyone until the test starts.";
|
|
@@ -17,11 +26,18 @@ export declare const editorCopy: {
|
|
|
17
26
|
readonly replaceConfirm: (label: string) => string;
|
|
18
27
|
readonly replace: "Replace";
|
|
19
28
|
readonly createLabel: "Test this block";
|
|
29
|
+
readonly newTest: "Start a new test from this block";
|
|
30
|
+
readonly sharedTest: "This test is also used in another place. Changes here affect that test.";
|
|
31
|
+
readonly detach: "Remove the test from this block";
|
|
32
|
+
readonly detachTitle: "Remove the test from this block?";
|
|
33
|
+
readonly detachHelp: "Show the Original on this page? All version content stays in this block. The test and its results are kept. Save the page to keep this change.";
|
|
34
|
+
readonly stopToDetach: "Stop the test to remove it from this block.";
|
|
35
|
+
readonly detachRunningHelp: "Show the Original here? The test keeps running in its other place. All version content stays in this block. Save the page to keep this change.";
|
|
36
|
+
readonly createdUnbound: "The test was created, but this block changed or was removed. Open the test to continue.";
|
|
20
37
|
readonly creating: "Creating…";
|
|
21
38
|
readonly cancel: "Cancel";
|
|
22
39
|
readonly name: "Name";
|
|
23
|
-
readonly
|
|
24
|
-
readonly viewResults: "View results";
|
|
40
|
+
readonly openTest: "Open the test";
|
|
25
41
|
readonly nameExists: "This name is too close to an existing test. Choose a different name.";
|
|
26
42
|
readonly createError: "Couldn't create the test. Try again.";
|
|
27
43
|
readonly loading: "Loading test…";
|
package/dist/puck/editor/copy.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { ARM_LABELS } from '../../labels/arms.js';
|
|
2
2
|
export const editorCopy = {
|
|
3
|
+
retrySetup: 'Retry',
|
|
4
|
+
controlsUnavailable: "Test controls couldn't load.",
|
|
5
|
+
setupForbidden: "You don't have access to set up tests.",
|
|
6
|
+
setupUnavailable: "Setup isn't available right now.",
|
|
3
7
|
labels: ARM_LABELS,
|
|
8
|
+
configure: 'Configure test',
|
|
9
|
+
openInTab: 'Open in a new tab',
|
|
10
|
+
closeConfigure: 'Close',
|
|
11
|
+
selectBlock: 'Select this test block',
|
|
12
|
+
placementsError: "Couldn't check where this test is used. Try again.",
|
|
4
13
|
notSetUp: 'Not set up',
|
|
5
14
|
unbound: 'Choose or create a test to show different versions.',
|
|
6
15
|
draft: 'This block shows the Original to everyone until the test starts.',
|
|
@@ -12,11 +21,18 @@ export const editorCopy = {
|
|
|
12
21
|
replaceConfirm: (label)=>`${label} already has content. Replace it with a copy of the Original?`,
|
|
13
22
|
replace: 'Replace',
|
|
14
23
|
createLabel: 'Test this block',
|
|
24
|
+
newTest: 'Start a new test from this block',
|
|
25
|
+
sharedTest: 'This test is also used in another place. Changes here affect that test.',
|
|
26
|
+
detach: 'Remove the test from this block',
|
|
27
|
+
detachTitle: 'Remove the test from this block?',
|
|
28
|
+
detachHelp: 'Show the Original on this page? All version content stays in this block. The test and its results are kept. Save the page to keep this change.',
|
|
29
|
+
stopToDetach: 'Stop the test to remove it from this block.',
|
|
30
|
+
detachRunningHelp: 'Show the Original here? The test keeps running in its other place. All version content stays in this block. Save the page to keep this change.',
|
|
31
|
+
createdUnbound: 'The test was created, but this block changed or was removed. Open the test to continue.',
|
|
15
32
|
creating: 'Creating…',
|
|
16
33
|
cancel: 'Cancel',
|
|
17
34
|
name: 'Name',
|
|
18
|
-
|
|
19
|
-
viewResults: 'View results',
|
|
35
|
+
openTest: 'Open the test',
|
|
20
36
|
nameExists: "This name is too close to an existing test. Choose a different name.",
|
|
21
37
|
createError: "Couldn't create the test. Try again.",
|
|
22
38
|
loading: 'Loading test…',
|
|
@@ -52,7 +68,7 @@ export const editorCopy = {
|
|
|
52
68
|
refresh: 'Refresh',
|
|
53
69
|
people: (label, count)=>`${label}: ${count} people`
|
|
54
70
|
};
|
|
55
|
-
// Minimal editor-side equivalent of
|
|
71
|
+
// Minimal editor-side equivalent of testSurface/copy/common.ts: kept local to the editor creation flow.
|
|
56
72
|
// Never accept server text as a fallback.
|
|
57
73
|
export function writeRefusal(code, status) {
|
|
58
74
|
if (code === 'stale-edit') return editorCopy.staleEdit;
|
|
@@ -21,6 +21,17 @@
|
|
|
21
21
|
flex-wrap: wrap;
|
|
22
22
|
align-items: center;
|
|
23
23
|
gap: var(--xp-space-2);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.xp-slot-chrome[data-selected='true'] {
|
|
28
|
+
border-color: var(--xp-focus);
|
|
29
|
+
box-shadow: inset 0 0 0 2px var(--xp-focus);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.xp-slot-header:focus-visible {
|
|
33
|
+
outline: 2px solid var(--xp-focus);
|
|
34
|
+
outline-offset: 2px;
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
.xp-slot-title {
|
|
@@ -133,3 +144,25 @@
|
|
|
133
144
|
border-color: var(--xp-border-strong);
|
|
134
145
|
color: var(--xp-text-2);
|
|
135
146
|
}
|
|
147
|
+
|
|
148
|
+
.xp-slot-control-events { display: contents; }
|
|
149
|
+
|
|
150
|
+
/* The configure surface is opt-in and always outside the Puck component tree. */
|
|
151
|
+
.xp-slot-editor.xp-configure-host .xp-ui-drawer { margin: 0; }
|
|
152
|
+
.xp-configure-panel { font: var(--xp-text-body); color: var(--xp-text); }
|
|
153
|
+
.xp-configure-panel .xp-test-page { margin: 0; padding: var(--xp-space-5); min-width: 0; }
|
|
154
|
+
.xp-configure-panel .xp-test-layout { grid-template-columns: minmax(0, 1fr); gap: var(--xp-space-5); }
|
|
155
|
+
.xp-configure-panel .xp-test-content { max-width: none; gap: var(--xp-space-5); }
|
|
156
|
+
.xp-configure-panel .xp-test-rail { position: static; }
|
|
157
|
+
.xp-configure-panel .xp-test-rail-list { flex-direction: row; overflow-x: auto; }
|
|
158
|
+
.xp-configure-panel .xp-test-rail-item { white-space: nowrap; }
|
|
159
|
+
.xp-configure-panel .xp-test-rail-item--advanced { margin-top: 0; }
|
|
160
|
+
.xp-configure-panel .xp-test-readiness-bar { position: sticky; bottom: 0; margin: var(--xp-space-5) calc(-1 * var(--xp-space-5)) calc(-1 * var(--xp-space-5)); }
|
|
161
|
+
.xp-configure-panel .xp-readiness--bar { grid-template-columns: minmax(0, 1fr); padding: var(--xp-space-4) var(--xp-space-5); }
|
|
162
|
+
.xp-configure-panel .xp-readiness--bar > .xp-readiness__actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
|
|
163
|
+
.xp-configure-panel .xp-readiness__separator { display: none; }
|
|
164
|
+
.xp-configure-panel .xp-targeting-row { grid-template-columns: minmax(0, 1fr); }
|
|
165
|
+
.xp-configure-panel .xp-targeting-row > * { min-width: 0; }
|
|
166
|
+
.xp-configure-panel .xp-version-rows { grid-template-columns: minmax(0, 1fr) var(--xp-version-share-width-mobile); }
|
|
167
|
+
.xp-configure-panel .xp-version-content, .xp-configure-panel .xp-version-remove { grid-column: 1 / -1; }
|
|
168
|
+
.xp-configure-panel .xp-version-grid-head > :nth-child(n+3) { display: none; }
|
|
@@ -355,6 +355,12 @@
|
|
|
355
355
|
.xp-ui-field-label { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-3); }
|
|
356
356
|
.xp-ui-field-label > label { font-weight: 500; }
|
|
357
357
|
|
|
358
|
+
.xp-ui-dialog.xp-ui-drawer { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(720px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border-block: 0; border-inline-end: 0; padding: 0; overflow: hidden; }
|
|
359
|
+
.xp-ui-drawer[open] { display: flex; flex-direction: column; }
|
|
360
|
+
.xp-ui-drawer > .xp-ui-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: var(--xp-space-4); padding: var(--xp-space-4) var(--xp-space-5); border-bottom: 1px solid var(--xp-border); flex-shrink: 0; background: var(--xp-surface); }
|
|
361
|
+
.xp-ui-drawer > .xp-ui-dialog-header h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font: var(--xp-text-title); }
|
|
362
|
+
.xp-ui-drawer-body { min-height: 0; overflow: auto; overscroll-behavior: contain; flex: 1; background: var(--xp-bg); }
|
|
363
|
+
|
|
358
364
|
/* Shared UI controls are assembled into editor.css for the isolated canvas. */
|
|
359
365
|
.xp-slot-editor {
|
|
360
366
|
min-width: 0;
|
|
@@ -378,6 +384,17 @@
|
|
|
378
384
|
flex-wrap: wrap;
|
|
379
385
|
align-items: center;
|
|
380
386
|
gap: var(--xp-space-2);
|
|
387
|
+
cursor: pointer;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.xp-slot-chrome[data-selected='true'] {
|
|
391
|
+
border-color: var(--xp-focus);
|
|
392
|
+
box-shadow: inset 0 0 0 2px var(--xp-focus);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
.xp-slot-header:focus-visible {
|
|
396
|
+
outline: 2px solid var(--xp-focus);
|
|
397
|
+
outline-offset: 2px;
|
|
381
398
|
}
|
|
382
399
|
|
|
383
400
|
.xp-slot-title {
|
|
@@ -490,3 +507,25 @@
|
|
|
490
507
|
border-color: var(--xp-border-strong);
|
|
491
508
|
color: var(--xp-text-2);
|
|
492
509
|
}
|
|
510
|
+
|
|
511
|
+
.xp-slot-control-events { display: contents; }
|
|
512
|
+
|
|
513
|
+
/* The configure surface is opt-in and always outside the Puck component tree. */
|
|
514
|
+
.xp-slot-editor.xp-configure-host .xp-ui-drawer { margin: 0; }
|
|
515
|
+
.xp-configure-panel { font: var(--xp-text-body); color: var(--xp-text); }
|
|
516
|
+
.xp-configure-panel .xp-test-page { margin: 0; padding: var(--xp-space-5); min-width: 0; }
|
|
517
|
+
.xp-configure-panel .xp-test-layout { grid-template-columns: minmax(0, 1fr); gap: var(--xp-space-5); }
|
|
518
|
+
.xp-configure-panel .xp-test-content { max-width: none; gap: var(--xp-space-5); }
|
|
519
|
+
.xp-configure-panel .xp-test-rail { position: static; }
|
|
520
|
+
.xp-configure-panel .xp-test-rail-list { flex-direction: row; overflow-x: auto; }
|
|
521
|
+
.xp-configure-panel .xp-test-rail-item { white-space: nowrap; }
|
|
522
|
+
.xp-configure-panel .xp-test-rail-item--advanced { margin-top: 0; }
|
|
523
|
+
.xp-configure-panel .xp-test-readiness-bar { position: sticky; bottom: 0; margin: var(--xp-space-5) calc(-1 * var(--xp-space-5)) calc(-1 * var(--xp-space-5)); }
|
|
524
|
+
.xp-configure-panel .xp-readiness--bar { grid-template-columns: minmax(0, 1fr); padding: var(--xp-space-4) var(--xp-space-5); }
|
|
525
|
+
.xp-configure-panel .xp-readiness--bar > .xp-readiness__actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
|
|
526
|
+
.xp-configure-panel .xp-readiness__separator { display: none; }
|
|
527
|
+
.xp-configure-panel .xp-targeting-row { grid-template-columns: minmax(0, 1fr); }
|
|
528
|
+
.xp-configure-panel .xp-targeting-row > * { min-width: 0; }
|
|
529
|
+
.xp-configure-panel .xp-version-rows { grid-template-columns: minmax(0, 1fr) var(--xp-version-share-width-mobile); }
|
|
530
|
+
.xp-configure-panel .xp-version-content, .xp-configure-panel .xp-version-remove { grid-column: 1 / -1; }
|
|
531
|
+
.xp-configure-panel .xp-version-grid-head > :nth-child(n+3) { display: none; }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Arm, DocId, Status, UnitType } from '../../types/contracts.js';
|
|
2
2
|
import type { ArmSlot } from '../../types/puck.js';
|
|
3
|
+
import type { PreflightResult } from '../../types/endpoints.js';
|
|
3
4
|
export type EditorExperiment = {
|
|
4
5
|
name: string;
|
|
5
6
|
updatedAt?: string;
|
|
@@ -14,6 +15,18 @@ export declare function tabsFor(experiment?: Pick<EditorExperiment, 'arms'> | nu
|
|
|
14
15
|
label: string;
|
|
15
16
|
}>;
|
|
16
17
|
export declare function bannerFor(status?: Status | null, winner?: string): string;
|
|
18
|
+
/** Preserve the block's populated slots and the current test's versions, without carrying test settings. */
|
|
19
|
+
export declare function armsFromBlock(experiment: Pick<EditorExperiment, 'arms'>, content: Partial<Record<ArmSlot, unknown>>): Arm[];
|
|
20
|
+
/** The host's Payload Puck editor route identifies the saved document, including in an iframe. */
|
|
21
|
+
export declare function currentPuckDocument(pathname: string, admin: string, placements?: PreflightResult['placements']): {
|
|
22
|
+
collection: string;
|
|
23
|
+
id: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
/** Saved placements elsewhere are shared; current-page multiplicity comes from live Puck data. */
|
|
26
|
+
export declare function isSharedTest(placements: PreflightResult['placements'], current?: {
|
|
27
|
+
collection: string;
|
|
28
|
+
id: DocId;
|
|
29
|
+
}): boolean;
|
|
17
30
|
export declare function slugify(name: string): string;
|
|
18
31
|
/** Complete draft defaults, shared by the page hand-off and setting creation. */
|
|
19
32
|
export declare function newTestBody(input: {
|
|
@@ -25,6 +38,7 @@ export declare function newTestBody(input: {
|
|
|
25
38
|
flagPoint?: string;
|
|
26
39
|
layer?: DocId;
|
|
27
40
|
hypothesis?: string;
|
|
41
|
+
arms?: Arm[];
|
|
28
42
|
}): {
|
|
29
43
|
hypothesis?: string | undefined;
|
|
30
44
|
layer?: DocId | undefined;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { placementPages } from '../../lib/placementPages.js';
|
|
2
|
+
import { splitEvenly } from '../../arms/model.js';
|
|
1
3
|
import { editorCopy } from './copy.js';
|
|
2
4
|
export function tabsFor(experiment) {
|
|
3
5
|
if (!experiment) return [
|
|
@@ -28,12 +30,67 @@ export function bannerFor(status, winner = editorCopy.labels.control) {
|
|
|
28
30
|
return editorCopy.unbound;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
33
|
+
/** Preserve the block's populated slots and the current test's versions, without carrying test settings. */ export function armsFromBlock(experiment, content) {
|
|
34
|
+
const slots = [
|
|
35
|
+
'control',
|
|
36
|
+
'variantA',
|
|
37
|
+
'variantB',
|
|
38
|
+
'variantC'
|
|
39
|
+
];
|
|
40
|
+
return splitEvenly(slots.flatMap((slot)=>{
|
|
41
|
+
const arm = experiment.arms.find((arm)=>arm.key === slot && arm.kind !== 'holdout');
|
|
42
|
+
if (slot !== 'control' && !arm && !(Array.isArray(content[slot]) && content[slot].length > 0)) return [];
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
key: slot,
|
|
46
|
+
slot,
|
|
47
|
+
kind: slot === 'control' ? 'control' : 'variant',
|
|
48
|
+
label: arm?.label.trim() || editorCopy.labels[slot],
|
|
49
|
+
weight: 0
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
/** The host's Payload Puck editor route identifies the saved document, including in an iframe. */ export function currentPuckDocument(pathname, admin, placements = []) {
|
|
55
|
+
const linked = placements.find((page)=>{
|
|
56
|
+
try {
|
|
57
|
+
return page.editorUrl && new URL(page.editorUrl, 'https://puck.local').pathname === pathname;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (linked) return {
|
|
63
|
+
collection: linked.collection,
|
|
64
|
+
id: String(linked.id)
|
|
65
|
+
};
|
|
66
|
+
if (!pathname.startsWith(`${admin}/`)) return;
|
|
67
|
+
let parts;
|
|
68
|
+
try {
|
|
69
|
+
parts = pathname.slice(admin.length + 1).split('/').map(decodeURIComponent);
|
|
70
|
+
} catch {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (![
|
|
74
|
+
'puck',
|
|
75
|
+
'puck-editor',
|
|
76
|
+
'collections'
|
|
77
|
+
].includes(parts[0] ?? '') || !parts[1] || !parts[2] || parts[2] === 'create') return;
|
|
78
|
+
return {
|
|
79
|
+
collection: parts[1],
|
|
80
|
+
id: parts[2]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Saved placements elsewhere are shared; current-page multiplicity comes from live Puck data. */ export function isSharedTest(placements, current) {
|
|
84
|
+
return placementPages(placements).some((page)=>page.collection !== current?.collection || String(page.id) !== String(current.id));
|
|
85
|
+
}
|
|
31
86
|
export function slugify(name) {
|
|
32
87
|
return name.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 64).replace(/-+$/g, '');
|
|
33
88
|
}
|
|
34
89
|
/** Complete draft defaults, shared by the page hand-off and setting creation. */ export function newTestBody(input) {
|
|
35
90
|
const { kind, name, slug, unitType, flagPoint, layer, hypothesis, pageCollection } = input;
|
|
36
|
-
const arms =
|
|
91
|
+
const arms = input.arms?.map((arm)=>({
|
|
92
|
+
...arm
|
|
93
|
+
})) ?? [
|
|
37
94
|
{
|
|
38
95
|
key: 'control',
|
|
39
96
|
kind: 'control',
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SurfaceProps } from '../../testSurface/surface/contracts.js';
|
|
2
|
+
export type SurfaceState = {
|
|
3
|
+
surface?: SurfaceProps;
|
|
4
|
+
error?: 'forbidden' | 'unavailable';
|
|
5
|
+
};
|
|
6
|
+
export declare function readSurface(api: string): Promise<SurfaceState>;
|
|
7
|
+
/** Share only pending requests across canvas blocks and sidebar controls. */
|
|
8
|
+
export declare function useEditorSurface(api: string): SurfaceState & {
|
|
9
|
+
retry: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
const pending = new Map();
|
|
4
|
+
export function readSurface(api) {
|
|
5
|
+
let request = pending.get(api);
|
|
6
|
+
if (!request) {
|
|
7
|
+
request = fetch(`${api}/xp/editor-surface`, {
|
|
8
|
+
credentials: 'include',
|
|
9
|
+
cache: 'no-store'
|
|
10
|
+
}).then(async (response)=>{
|
|
11
|
+
if (response.status === 401 || response.status === 403) return {
|
|
12
|
+
error: 'forbidden'
|
|
13
|
+
};
|
|
14
|
+
if (!response.ok) throw new Error('surface');
|
|
15
|
+
const surface = await response.json();
|
|
16
|
+
if (!surface || typeof surface.canManage !== 'boolean' || typeof surface.canReadResults !== 'boolean') throw new Error('surface');
|
|
17
|
+
return {
|
|
18
|
+
surface
|
|
19
|
+
};
|
|
20
|
+
}).catch(()=>({
|
|
21
|
+
error: 'unavailable'
|
|
22
|
+
}));
|
|
23
|
+
pending.set(api, request);
|
|
24
|
+
const release = ()=>{
|
|
25
|
+
if (pending.get(api) === request) pending.delete(api);
|
|
26
|
+
};
|
|
27
|
+
void request.then(release, release);
|
|
28
|
+
}
|
|
29
|
+
return request;
|
|
30
|
+
}
|
|
31
|
+
/** Share only pending requests across canvas blocks and sidebar controls. */ export function useEditorSurface(api) {
|
|
32
|
+
const [loaded, setLoaded] = useState();
|
|
33
|
+
const [attempt, setAttempt] = useState(0);
|
|
34
|
+
const retry = useCallback(()=>{
|
|
35
|
+
setLoaded(undefined);
|
|
36
|
+
setAttempt((value)=>value + 1);
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(()=>{
|
|
39
|
+
let active = true;
|
|
40
|
+
const load = ()=>{
|
|
41
|
+
void readSurface(api).then((state)=>{
|
|
42
|
+
if (active) setLoaded({
|
|
43
|
+
api,
|
|
44
|
+
state
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
load();
|
|
49
|
+
const onVisible = ()=>{
|
|
50
|
+
if (document.visibilityState === 'visible') load();
|
|
51
|
+
};
|
|
52
|
+
document.addEventListener('visibilitychange', onVisible);
|
|
53
|
+
return ()=>{
|
|
54
|
+
active = false;
|
|
55
|
+
document.removeEventListener('visibilitychange', onVisible);
|
|
56
|
+
};
|
|
57
|
+
}, [
|
|
58
|
+
api,
|
|
59
|
+
attempt
|
|
60
|
+
]);
|
|
61
|
+
return {
|
|
62
|
+
...loaded?.api === api ? loaded.state : {},
|
|
63
|
+
retry
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { walkTree } from '@puckeditor/core';
|
|
2
|
+
// Puck data/config are immutable. Selection, hover and drag state reuse this
|
|
3
|
+
// result, and every block on the page shares a single traversal per data change.
|
|
4
|
+
const pages = new WeakMap();
|
|
5
|
+
export function localPlacements(data, config) {
|
|
6
|
+
let configs = pages.get(data);
|
|
7
|
+
if (!configs) {
|
|
8
|
+
configs = new WeakMap();
|
|
9
|
+
pages.set(data, configs);
|
|
10
|
+
}
|
|
11
|
+
let placements = configs.get(config);
|
|
12
|
+
if (!placements) {
|
|
13
|
+
placements = new Map();
|
|
14
|
+
const collect = (content)=>{
|
|
15
|
+
for (const item of content)if (item.type === 'ExperimentSlot' && item.props.experiment?.id !== undefined) {
|
|
16
|
+
const key = String(item.props.experiment.id);
|
|
17
|
+
const ids = placements.get(key) ?? new Set();
|
|
18
|
+
ids.add(item.props.id);
|
|
19
|
+
placements.set(key, ids);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
walkTree(data, config, (content)=>{
|
|
23
|
+
collect(content);
|
|
24
|
+
});
|
|
25
|
+
for (const content of Object.values(data.zones ?? {}))collect(content);
|
|
26
|
+
configs.set(config, placements);
|
|
27
|
+
}
|
|
28
|
+
return placements;
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
import type { PreflightResult } from '../../types/endpoints.js';
|
|
3
|
+
type Placements = PreflightResult['placements'];
|
|
4
|
+
/** Share mounted reads, but destructive actions always bypass settled cached knowledge. */
|
|
5
|
+
export declare function refreshPlacements(api: string, id: DocId): Promise<{
|
|
6
|
+
collection: string;
|
|
7
|
+
id: DocId;
|
|
8
|
+
title: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
editorUrl?: string;
|
|
11
|
+
slots?: Record<import("../../types/puck.js").ArmSlot, number>;
|
|
12
|
+
ok: boolean;
|
|
13
|
+
detail?: string;
|
|
14
|
+
}[] | undefined>;
|
|
15
|
+
/** Reuse the surface's successful preflight, without another editor request. */
|
|
16
|
+
export declare function publishPlacements(api: string, id: DocId, placements: Placements | undefined): void;
|
|
17
|
+
export declare function invalidatePlacements(api: string, id: DocId): void;
|
|
18
|
+
export declare function acquirePlacements(api: string, id: DocId, notify: (placements: Placements | undefined) => void, fresh?: boolean): () => void;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const cache = new Map();
|
|
2
|
+
const consumers = new Map();
|
|
3
|
+
const keyFor = (api, id)=>JSON.stringify([
|
|
4
|
+
api,
|
|
5
|
+
String(id)
|
|
6
|
+
]);
|
|
7
|
+
function read(api, id, fresh) {
|
|
8
|
+
const key = keyFor(api, id);
|
|
9
|
+
const cached = cache.get(key);
|
|
10
|
+
if (cached && (!fresh || cached.pending)) return cached;
|
|
11
|
+
const controller = new AbortController();
|
|
12
|
+
const entry = {
|
|
13
|
+
controller,
|
|
14
|
+
pending: true,
|
|
15
|
+
promise: undefined
|
|
16
|
+
};
|
|
17
|
+
cache.set(key, entry);
|
|
18
|
+
for (const notify of consumers.get(key) ?? [])notify(undefined);
|
|
19
|
+
entry.promise = (async ()=>{
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, {
|
|
22
|
+
credentials: 'include',
|
|
23
|
+
cache: 'no-store',
|
|
24
|
+
signal: controller.signal
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) return;
|
|
27
|
+
const data = await response.json();
|
|
28
|
+
return Array.isArray(data.placements) ? data.placements : undefined;
|
|
29
|
+
} catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
})().then((placements)=>{
|
|
33
|
+
entry.pending = false;
|
|
34
|
+
if (cache.get(key) === entry) {
|
|
35
|
+
if (placements === undefined) cache.delete(key);
|
|
36
|
+
for (const notify of consumers.get(key) ?? [])notify(placements);
|
|
37
|
+
}
|
|
38
|
+
return placements;
|
|
39
|
+
});
|
|
40
|
+
return entry;
|
|
41
|
+
}
|
|
42
|
+
/** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id) {
|
|
43
|
+
return read(api, id, true).promise;
|
|
44
|
+
}
|
|
45
|
+
/** Reuse the surface's successful preflight, without another editor request. */ export function publishPlacements(api, id, placements) {
|
|
46
|
+
const key = keyFor(api, id);
|
|
47
|
+
cache.get(key)?.controller.abort();
|
|
48
|
+
if (placements === undefined) cache.delete(key);
|
|
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);
|
|
55
|
+
}
|
|
56
|
+
export function invalidatePlacements(api, id) {
|
|
57
|
+
const key = keyFor(api, id);
|
|
58
|
+
cache.get(key)?.controller.abort();
|
|
59
|
+
cache.delete(key);
|
|
60
|
+
for (const notify of consumers.get(key) ?? [])notify(undefined);
|
|
61
|
+
if (consumers.get(key)?.size) void read(api, id, true).promise;
|
|
62
|
+
}
|
|
63
|
+
export function acquirePlacements(api, id, notify, fresh = false) {
|
|
64
|
+
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
|
+
const entry = read(api, id, fresh);
|
|
70
|
+
let active = true;
|
|
71
|
+
void entry.promise.then((value)=>{
|
|
72
|
+
if (active && cache.get(key) === entry) notify(value);
|
|
73
|
+
});
|
|
74
|
+
return ()=>{
|
|
75
|
+
active = false;
|
|
76
|
+
listeners.delete(notify);
|
|
77
|
+
if (!listeners.size) {
|
|
78
|
+
consumers.delete(key);
|
|
79
|
+
cache.get(key)?.controller.abort();
|
|
80
|
+
cache.delete(key);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|