@delmaredigital/payload-experiments 0.5.2 → 0.20.0-next.2

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.
Files changed (71) hide show
  1. package/README.md +15 -4
  2. package/dist/admin/blocks/formApi.js +17 -15
  3. package/dist/admin/blocks/model.js +1 -1
  4. package/dist/admin/paths.d.ts +0 -4
  5. package/dist/admin/paths.js +0 -4
  6. package/dist/admin/theme.css +43 -49
  7. package/dist/admin/views/renderCollectionList.js +1 -1
  8. package/dist/blocks/formState.d.ts +1 -1
  9. package/dist/blocks/formState.js +2 -5
  10. package/dist/blocks/placementLocale.js +10 -13
  11. package/dist/blocks/placementPublication.d.ts +1 -1
  12. package/dist/blocks/placementPublication.js +6 -5
  13. package/dist/collections/access.d.ts +2 -0
  14. package/dist/collections/access.js +2 -0
  15. package/dist/collections/cohortMembers.js +1 -0
  16. package/dist/collections/events.js +1 -0
  17. package/dist/collections/experiments/config.js +2 -1
  18. package/dist/collections/experiments/createDefaults.js +4 -3
  19. package/dist/collections/experiments/flagControlParams.js +2 -1
  20. package/dist/collections/experiments/lockHook.js +6 -4
  21. package/dist/collections/identities.js +1 -0
  22. package/dist/collections/layers.js +1 -0
  23. package/dist/collections/metrics.js +1 -0
  24. package/dist/collections/phases.js +1 -0
  25. package/dist/collections/snapshots.js +1 -0
  26. package/dist/db/appends.d.ts +4 -7
  27. package/dist/db/appends.js +5 -12
  28. package/dist/db/clickGoals.js +5 -2
  29. package/dist/db/executor.d.ts +1 -5
  30. package/dist/db/names.d.ts +1 -1
  31. package/dist/db/names.js +1 -1
  32. package/dist/db/pageContent.d.ts +1 -1
  33. package/dist/db/pageContent.js +1 -1
  34. package/dist/endpoints/pages.js +12 -7
  35. package/dist/exports/adminClient.d.ts +0 -2
  36. package/dist/exports/adminClient.js +0 -2
  37. package/dist/exports/adminRsc.d.ts +0 -2
  38. package/dist/exports/adminRsc.js +0 -2
  39. package/dist/globals/state.js +2 -0
  40. package/dist/goals/fairness.js +4 -1
  41. package/dist/hooks/pageGuard.d.ts +0 -3
  42. package/dist/hooks/pageGuard.js +14 -12
  43. package/dist/payloadCompat.d.ts +8 -0
  44. package/dist/payloadCompat.js +16 -0
  45. package/dist/puck/editor/editor.css +103 -109
  46. package/dist/server/previewDraft.js +0 -1
  47. package/dist/server/recordContentChange.d.ts +1 -1
  48. package/dist/server/recordContentChange.js +11 -15
  49. package/dist/server/runResults.d.ts +1 -1
  50. package/dist/server/runResults.js +1 -1
  51. package/dist/server/startExperiment.d.ts +1 -1
  52. package/dist/server/startExperiment.js +1 -1
  53. package/dist/testSurface/copy/surface.d.ts +0 -3
  54. package/dist/testSurface/copy/surface.js +0 -3
  55. package/dist/transitions/contentFields.d.ts +3 -6
  56. package/dist/transitions/contentFields.js +3 -9
  57. package/dist/transitions/makeContent.js +34 -16
  58. package/dist/transitions/pageAddress.d.ts +3 -1
  59. package/dist/transitions/pageAddress.js +33 -3
  60. package/dist/ui/accent.d.ts +5 -1
  61. package/dist/ui/accent.js +6 -5
  62. package/package.json +11 -11
  63. package/dist/admin/TestsDashboardCards.d.ts +0 -4
  64. package/dist/admin/TestsDashboardCards.js +0 -48
  65. package/dist/admin/TestsNavLink.d.ts +0 -6
  66. package/dist/admin/TestsNavLink.js +0 -68
  67. package/dist/admin/dashboard.css +0 -35
  68. package/dist/admin/views/CollectionListRedirect.d.ts +0 -3
  69. package/dist/admin/views/CollectionListRedirect.js +0 -8
  70. package/dist/admin/views/TestsNavLinkServer.d.ts +0 -3
  71. package/dist/admin/views/TestsNavLinkServer.js +0 -43
@@ -1,6 +1,6 @@
1
1
  import { flattenTopLevelFields } from 'payload/shared';
2
- import { placementReader } from '../blocks/placementLocale.js';
3
- import { pagePublicationStatus, publicationLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
2
+ import { localeRequest, placementReader } from '../blocks/placementLocale.js';
3
+ import { publicationLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
4
4
  import { hasPublishedPageVersion } from '../db/pageContent.js';
5
5
  import { normalisePath } from '../runtime/normalisePath.js';
6
6
  export const PAGE_ADDRESS_FIELDS = [
@@ -8,6 +8,35 @@ export const PAGE_ADDRESS_FIELDS = [
8
8
  'slug',
9
9
  'pageSegment'
10
10
  ];
11
+ /** Local API output can inherit a fallback locale's status. The filter reads the selected locale's main row. */ export async function findPublishedPageIds(req, collection, ids, locale) {
12
+ if (!ids.length) return new Set();
13
+ const viewReq = localeRequest(req, {
14
+ locale,
15
+ fallbackLocale: false
16
+ });
17
+ const { docs } = await req.payload.find({
18
+ collection,
19
+ req: viewReq,
20
+ fallbackLocale: false,
21
+ overrideAccess: false,
22
+ depth: 0,
23
+ draft: false,
24
+ pagination: false,
25
+ limit: ids.length,
26
+ select: {
27
+ id: true
28
+ },
29
+ where: {
30
+ id: {
31
+ in: ids
32
+ },
33
+ _status: {
34
+ equals: 'published'
35
+ }
36
+ }
37
+ });
38
+ return new Set(docs.map((doc)=>String(doc.id)));
39
+ }
11
40
  /** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
12
41
  * recognizes never-published drafts when a host lookup only sees live pages. */ export async function findDraftPageByPath(req, entry, path) {
13
42
  const config = req.payload.collections?.[entry.slug]?.config ?? req.payload.config.collections?.find((collection)=>collection.slug === entry.slug);
@@ -93,12 +122,13 @@ export const PAGE_ADDRESS_FIELDS = [
93
122
  ]
94
123
  }
95
124
  });
125
+ const published = await findPublishedPageIds(req, entry.slug, main.docs.map((row)=>row.id), locale);
96
126
  const draftById = new Map(candidates.map((row)=>[
97
127
  String(row.id),
98
128
  row
99
129
  ]));
100
130
  const eligible = await Promise.all(main.docs.map(async (row)=>{
101
- if (pagePublicationStatus(row, locale) === 'published') return undefined;
131
+ if (published.has(String(row.id))) return undefined;
102
132
  if (await hasPublishedPageVersion(req, entry.slug, row.id, locale)) return matchesPath(row) ? row : undefined;
103
133
  return draftById.get(String(row.id));
104
134
  }));
@@ -16,7 +16,11 @@ type Floors = {
16
16
  text: number;
17
17
  focus: number;
18
18
  };
19
- /** Pure shared host-accent derivation using theme.css's reference surfaces. */
19
+ export declare const ACCENT_REFERENCE_SURFACES: {
20
+ readonly light: "#ffffff";
21
+ readonly dark: "#2c2c2c";
22
+ };
23
+ /** Pure shared host-accent derivation using Payload 4 reference surfaces. */
20
24
  export declare function deriveAccent(input: string): {
21
25
  light: AccentSet;
22
26
  dark: AccentSet;
package/dist/ui/accent.js CHANGED
@@ -100,11 +100,12 @@ function set(accent, surface, dark = false, floors = FLOORS) {
100
100
  accentTextDecoration: accentText ? 'none' : 'underline'
101
101
  };
102
102
  }
103
- /** Pure shared host-accent derivation using theme.css's reference surfaces. */ export function deriveAccent(input) {
104
- return deriveAccentFor(input, {
105
- light: '#ffffff',
106
- dark: '#222222'
107
- });
103
+ export const ACCENT_REFERENCE_SURFACES = {
104
+ light: '#ffffff',
105
+ dark: '#2c2c2c'
106
+ };
107
+ /** Pure shared host-accent derivation using Payload 4 reference surfaces. */ export function deriveAccent(input) {
108
+ return deriveAccentFor(input, ACCENT_REFERENCE_SURFACES);
108
109
  }
109
110
  /** Module-only surface injection; not a package API. Dark adjustment raises HSL
110
111
  * lightness to 3:1. Interaction steps preserve the foreground and prefer the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-experiments",
3
- "version": "0.5.2",
3
+ "version": "0.20.0-next.2",
4
4
  "description": "No-code A/B testing for Payload CMS and Next.js: block, page and flag experiments with holdouts, layers, exposure logging and honest statistics inside the admin — no vendor",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -84,14 +84,14 @@
84
84
  "README.md"
85
85
  ],
86
86
  "peerDependencies": {
87
- "@payloadcms/next": ">=3.90.0 <4",
88
- "@payloadcms/ui": ">=3.90.0 <4",
87
+ "@payloadcms/next": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
88
+ "@payloadcms/ui": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
89
89
  "@puckeditor/core": ">=0.24.0",
90
90
  "next": ">=16.4.1 <17",
91
- "payload": ">=3.90.0 <4",
91
+ "payload": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
92
92
  "react": ">=19.2.1 <20",
93
93
  "react-dom": ">=19.2.1 <20",
94
- "@payloadcms/db-postgres": ">=3.90.0 <4",
94
+ "@payloadcms/db-postgres": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
95
95
  "pg": ">=8.13.0 <9"
96
96
  },
97
97
  "peerDependenciesMeta": {
@@ -100,7 +100,7 @@
100
100
  }
101
101
  },
102
102
  "dependencies": {
103
- "@payloadcms/translations": ">=3.90.0 <4",
103
+ "@payloadcms/translations": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
104
104
  "@delmaredigital/experiments-stats": "0.1.0"
105
105
  },
106
106
  "keywords": [
@@ -114,7 +114,7 @@
114
114
  "nextjs"
115
115
  ],
116
116
  "engines": {
117
- "node": ">=22.23.4"
117
+ "node": ">=24.22.1"
118
118
  },
119
119
  "author": "Delmare Digital",
120
120
  "repository": {
@@ -128,10 +128,10 @@
128
128
  "homepage": "https://plugins.delmaredigital.com/experiments",
129
129
  "devDependencies": {
130
130
  "@delmaredigital/payload-puck": "0.12.5",
131
- "payload": "^3.90.2",
132
- "@payloadcms/db-postgres": "^3.90.2",
133
- "@payloadcms/ui": "^3.90.2",
134
- "@payloadcms/next": "^3.90.2",
131
+ "payload": "4.0.0-beta.6",
132
+ "@payloadcms/db-postgres": "4.0.0-beta.6",
133
+ "@payloadcms/ui": "4.0.0-beta.6",
134
+ "@payloadcms/next": "4.0.0-beta.6",
135
135
  "next": "^16.4.2",
136
136
  "react": "^19.2.8",
137
137
  "react-dom": "^19.2.8",
@@ -1,4 +0,0 @@
1
- import './theme.css';
2
- import './dashboard.css';
3
- /** @deprecated Retained for existing import maps until 0.5.0. */
4
- export declare function TestsDashboardCards(): import("react").JSX.Element | null;
@@ -1,48 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { surfaceUrls } from '../testSurface/surfaceUrls.js';
4
- import './theme.css';
5
- import './dashboard.css';
6
- import { Card, useAuth, useConfig } from '@payloadcms/ui';
7
- import { SURFACE_COPY } from '../testSurface/copy/surface.js';
8
- /** @deprecated Retained for existing import maps until 0.5.0. */ export function TestsDashboardCards() {
9
- const { config } = useConfig();
10
- const { permissions } = useAuth();
11
- const testPermissions = permissions?.collections?.['xp-experiments'];
12
- const canManage = testPermissions?.update === true;
13
- if (!canManage) return null;
14
- return /*#__PURE__*/ _jsxs("section", {
15
- className: "xp-dash-group",
16
- "aria-labelledby": "xp-dash-title",
17
- children: [
18
- /*#__PURE__*/ _jsx("h2", {
19
- className: "xp-dash-label",
20
- id: "xp-dash-title",
21
- children: SURFACE_COPY.title
22
- }),
23
- /*#__PURE__*/ _jsxs("ul", {
24
- className: "xp-dash-card-list",
25
- children: [
26
- /*#__PURE__*/ _jsx("li", {
27
- children: /*#__PURE__*/ _jsx(Card, {
28
- title: SURFACE_COPY.navAllTests,
29
- titleAs: "h3",
30
- buttonAriaLabel: SURFACE_COPY.dashShowTests,
31
- href: surfaceUrls.home(config.routes.admin),
32
- id: "card-xp-tests"
33
- })
34
- }),
35
- /*#__PURE__*/ _jsx("li", {
36
- children: /*#__PURE__*/ _jsx(Card, {
37
- title: SURFACE_COPY.navGoals,
38
- titleAs: "h3",
39
- buttonAriaLabel: SURFACE_COPY.dashShowGoals,
40
- href: surfaceUrls.goals(config.routes.admin),
41
- id: "card-xp-goals"
42
- })
43
- })
44
- ]
45
- })
46
- ]
47
- });
48
- }
@@ -1,6 +0,0 @@
1
- import './theme.css';
2
- /** @deprecated Retained for existing import maps until 0.5.0. */
3
- declare function TestsNav({ isOpen }: {
4
- isOpen?: boolean;
5
- }): import("react").JSX.Element | null;
6
- export { TestsNav as TestsNavLink };
@@ -1,68 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { surfaceUrls } from '../testSurface/surfaceUrls.js';
4
- import './theme.css';
5
- import { Link, NavGroup, useAuth, useConfig } from '@payloadcms/ui';
6
- import { usePathname } from 'next/navigation.js';
7
- import { SURFACE_COPY } from '../testSurface/copy/surface.js';
8
- /** @deprecated Retained for existing import maps until 0.5.0. */ function TestsNav({ isOpen = true }) {
9
- const { config } = useConfig();
10
- const { permissions } = useAuth();
11
- const pathname = usePathname();
12
- const href = surfaceUrls.home(config.routes.admin);
13
- const goalsHref = surfaceUrls.goals(config.routes.admin);
14
- const base = href.replace(/\/$/, '');
15
- const goalsBase = goalsHref.replace(/\/$/, '');
16
- const goalsActive = pathname === goalsBase || Boolean(pathname?.startsWith(`${goalsBase}/`));
17
- const testsActive = !goalsActive && (pathname === base || Boolean(pathname?.startsWith(`${base}/`)));
18
- const testPermissions = permissions?.collections?.['xp-experiments'];
19
- const canManage = testPermissions?.update === true;
20
- if (!canManage) return null;
21
- const entries = [
22
- {
23
- id: 'nav-xp-tests',
24
- href,
25
- label: SURFACE_COPY.navAllTests,
26
- active: testsActive
27
- },
28
- {
29
- id: 'nav-xp-goals',
30
- href: goalsHref,
31
- label: SURFACE_COPY.navGoals,
32
- active: goalsActive
33
- }
34
- ];
35
- return /*#__PURE__*/ _jsx(NavGroup, {
36
- label: SURFACE_COPY.title,
37
- isOpen: isOpen,
38
- children: entries.map((entry)=>{
39
- const props = {
40
- className: 'nav__link',
41
- id: entry.id,
42
- 'aria-current': entry.active ? 'page' : undefined
43
- };
44
- const content = /*#__PURE__*/ _jsxs(_Fragment, {
45
- children: [
46
- entry.active ? /*#__PURE__*/ _jsx("div", {
47
- className: "nav__link-indicator"
48
- }) : null,
49
- /*#__PURE__*/ _jsx("span", {
50
- className: "nav__link-label",
51
- children: entry.label
52
- })
53
- ]
54
- });
55
- return pathname === entry.href ? /*#__PURE__*/ _jsx("div", {
56
- ...props,
57
- children: content
58
- }, entry.id) : /*#__PURE__*/ _jsx(Link, {
59
- ...props,
60
- href: entry.href,
61
- prefetch: false,
62
- children: content
63
- }, entry.id);
64
- })
65
- });
66
- }
67
- // Preserve the existing import-map key.
68
- export { TestsNav as TestsNavLink };
@@ -1,35 +0,0 @@
1
- .xp-dash-group {
2
- display: flex;
3
- flex-direction: column;
4
- gap: var(--xp-space-4);
5
- margin-bottom: var(--xp-space-4);
6
- }
7
-
8
- .xp-dash-label { margin: 0; }
9
-
10
- .xp-dash-card-list {
11
- padding: 0;
12
- margin: 0;
13
- list-style: none;
14
- display: grid;
15
- grid-template-columns: repeat(5, 1fr);
16
- gap: var(--xp-dash-card-gap);
17
- }
18
-
19
- .xp-dash-card-list .card { height: 100%; }
20
-
21
- @media (max-width: 1440px) {
22
- .xp-dash-card-list { grid-template-columns: repeat(4, 1fr); }
23
- }
24
-
25
- @media (max-width: 1024px) {
26
- .xp-dash-card-list { grid-template-columns: repeat(2, 1fr); }
27
- }
28
-
29
- @media (max-width: 768px) {
30
- .xp-dash-card-list { gap: var(--xp-dash-card-gap-small); }
31
- }
32
-
33
- @media (max-width: 400px) {
34
- .xp-dash-card-list { grid-template-columns: repeat(1, 1fr); }
35
- }
@@ -1,3 +0,0 @@
1
- import type { ListViewServerProps } from 'payload';
2
- /** @deprecated Retained for existing import maps until 0.5.0. */
3
- export declare function CollectionListRedirect({ payload }: Pick<ListViewServerProps, 'payload'>): void;
@@ -1,8 +0,0 @@
1
- import { formatAdminURL } from 'payload/shared';
2
- import { redirect } from 'next/navigation.js';
3
- /** @deprecated Retained for existing import maps until 0.5.0. */ export function CollectionListRedirect({ payload }) {
4
- redirect(formatAdminURL({
5
- adminRoute: payload.config.routes.admin,
6
- path: '/experiments'
7
- }));
8
- }
@@ -1,3 +0,0 @@
1
- import type { ServerProps } from 'payload';
2
- /** @deprecated Retained for existing import maps until 0.5.0. */
3
- export declare function TestsNavLinkServer({ payload, user, permissions }: Pick<ServerProps, 'payload' | 'user' | 'permissions'>): Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined>;
@@ -1,43 +0,0 @@
1
- import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
2
- import { SURFACE_COPY } from '../../testSurface/copy/surface.js';
3
- import { XP_TESTS_NAV_CLIENT } from '../paths.js';
4
- /** @deprecated Retained for existing import maps until 0.5.0. */ export async function TestsNavLinkServer({ payload, user, permissions }) {
5
- const testPermissions = permissions?.collections?.['xp-experiments'];
6
- if (!user?.collection || testPermissions?.update !== true) return null;
7
- const result = await payload.find({
8
- collection: 'payload-preferences',
9
- where: {
10
- and: [
11
- {
12
- key: {
13
- equals: 'nav'
14
- }
15
- },
16
- {
17
- 'user.relationTo': {
18
- equals: user.collection
19
- }
20
- },
21
- {
22
- 'user.value': {
23
- equals: user.id
24
- }
25
- }
26
- ]
27
- },
28
- limit: 1,
29
- pagination: false,
30
- depth: 0,
31
- user,
32
- overrideAccess: false
33
- });
34
- const value = result.docs[0]?.value;
35
- // Resolve the CSS-bearing client boundary through Payload's public import map.
36
- return RenderServerComponent({
37
- Component: XP_TESTS_NAV_CLIENT,
38
- importMap: payload.importMap,
39
- clientProps: {
40
- isOpen: value?.groups?.[SURFACE_COPY.title]?.open ?? true
41
- }
42
- });
43
- }