@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/admin/blocks/BlockPanel.js +6 -4
  2. package/dist/admin/blocks/inject.js +1 -0
  3. package/dist/admin/blocks/model.d.ts +3 -2
  4. package/dist/admin/blocks/model.js +8 -4
  5. package/dist/admin/copy/blocks.d.ts +3 -2
  6. package/dist/admin/copy/blocks.js +7 -6
  7. package/dist/admin/copy/newTest.d.ts +1 -1
  8. package/dist/admin/copy/newTest.js +1 -1
  9. package/dist/admin/surface/ResultsRoute.js +2 -1
  10. package/dist/admin/surface/TestsHome.d.ts +2 -1
  11. package/dist/admin/surface/TestsHome.js +91 -37
  12. package/dist/admin/surface/TestsSurface.js +3 -0
  13. package/dist/admin/surface/home.model.d.ts +2 -0
  14. package/dist/admin/surface/newTest/NewTest.js +16 -18
  15. package/dist/admin/surface/newTest/PageWizard.js +1 -0
  16. package/dist/admin/surface/newTest/newTest.css +3 -1
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +8 -14
  21. package/dist/blocks/placementLanguages.d.ts +7 -0
  22. package/dist/blocks/placementLanguages.js +27 -0
  23. package/dist/blocks/placementLocale.d.ts +23 -7
  24. package/dist/blocks/placementLocale.js +221 -66
  25. package/dist/db/appends.d.ts +13 -0
  26. package/dist/db/appends.js +49 -0
  27. package/dist/db/bulkPlacementRemoval.js +8 -4
  28. package/dist/endpoints/contentLocale.d.ts +6 -0
  29. package/dist/endpoints/contentLocale.js +15 -0
  30. package/dist/endpoints/deleteImpact.d.ts +6 -0
  31. package/dist/endpoints/deleteImpact.js +206 -0
  32. package/dist/endpoints/index.js +7 -0
  33. package/dist/endpoints/pages.js +7 -3
  34. package/dist/endpoints/placementStatus.js +6 -1
  35. package/dist/endpoints/preflight.d.ts +1 -1
  36. package/dist/endpoints/preflight.js +17 -2
  37. package/dist/exports/adminClient.d.ts +1 -1
  38. package/dist/exports/adminClient.js +1 -1
  39. package/dist/exports/index.d.ts +1 -1
  40. package/dist/goals/fairness.js +43 -34
  41. package/dist/hooks/blockRemovalRule.d.ts +4 -3
  42. package/dist/hooks/blockRemovalRule.js +33 -9
  43. package/dist/hooks/pageGuard.d.ts +3 -0
  44. package/dist/hooks/pageGuard.js +34 -24
  45. package/dist/hooks/puckNestedTests.d.ts +8 -0
  46. package/dist/hooks/puckNestedTests.js +36 -0
  47. package/dist/lib/placementPages.d.ts +2 -1
  48. package/dist/lib/placementPages.js +10 -2
  49. package/dist/manifest/compile.d.ts +2 -1
  50. package/dist/manifest/compile.js +5 -1
  51. package/dist/puck/ExperimentPicker.d.ts +2 -1
  52. package/dist/puck/ExperimentPicker.js +37 -30
  53. package/dist/puck/ExperimentSlot.js +3 -1
  54. package/dist/puck/copy.d.ts +1 -0
  55. package/dist/puck/copy.js +1 -0
  56. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  57. package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
  58. package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
  59. package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
  60. package/dist/puck/editor/EditorControls.d.ts +1 -1
  61. package/dist/puck/editor/EditorControls.js +1 -1
  62. package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
  63. package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
  64. package/dist/puck/editor/LeftoverVersions.js +23 -44
  65. package/dist/puck/editor/QuickTestActions.js +2 -2
  66. package/dist/puck/editor/VersionBuilder.d.ts +41 -13
  67. package/dist/puck/editor/VersionBuilder.js +461 -224
  68. package/dist/puck/editor/armWrites.d.ts +9 -2
  69. package/dist/puck/editor/armWrites.js +40 -2
  70. package/dist/puck/editor/armsCache.d.ts +1 -1
  71. package/dist/puck/editor/armsCache.js +2 -1
  72. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  73. package/dist/puck/editor/blockClipboard.js +20 -0
  74. package/dist/puck/editor/copy.d.ts +27 -26
  75. package/dist/puck/editor/copy.js +28 -26
  76. package/dist/puck/editor/createTest.d.ts +3 -0
  77. package/dist/puck/editor/createTest.js +33 -0
  78. package/dist/puck/editor/editor.chrome.css +138 -17
  79. package/dist/puck/editor/editor.css +156 -22
  80. package/dist/puck/editor/editor.model.d.ts +2 -1
  81. package/dist/puck/editor/editor.model.js +3 -3
  82. package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
  83. package/dist/puck/editor/localPlacements.d.ts +5 -2
  84. package/dist/puck/editor/localPlacements.js +32 -18
  85. package/dist/puck/editor/placementsCache.d.ts +18 -12
  86. package/dist/puck/editor/placementsCache.js +52 -47
  87. package/dist/puck/editor/sidebar.d.ts +2 -6
  88. package/dist/puck/editor/sidebar.js +3 -6
  89. package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
  90. package/dist/puck/editor/usePlacementNotice.js +4 -3
  91. package/dist/puck/experimentSlug.d.ts +2 -0
  92. package/dist/puck/experimentSlug.js +3 -0
  93. package/dist/puck/nestedTestCopy.d.ts +8 -0
  94. package/dist/puck/nestedTestCopy.js +22 -0
  95. package/dist/puck/nestedTests.d.ts +17 -0
  96. package/dist/puck/nestedTests.js +30 -0
  97. package/dist/puck/slotConfig.d.ts +1 -1
  98. package/dist/puck/slotConfig.js +17 -4
  99. package/dist/puck/visibility.d.ts +20 -0
  100. package/dist/puck/visibility.js +81 -0
  101. package/dist/server/recordContentChange.js +37 -20
  102. package/dist/server/resolveExperimentData.js +6 -3
  103. package/dist/testSurface/PreviewLinks.js +6 -2
  104. package/dist/testSurface/api.d.ts +6 -3
  105. package/dist/testSurface/api.js +10 -6
  106. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  107. package/dist/testSurface/contentLocaleURL.js +3 -0
  108. package/dist/testSurface/copy/common.d.ts +4 -0
  109. package/dist/testSurface/copy/common.js +8 -4
  110. package/dist/testSurface/copy/languages.d.ts +11 -0
  111. package/dist/testSurface/copy/languages.js +7 -0
  112. package/dist/testSurface/copy/readiness.d.ts +2 -1
  113. package/dist/testSurface/copy/readiness.js +2 -1
  114. package/dist/testSurface/copy/testPage.d.ts +28 -6
  115. package/dist/testSurface/copy/testPage.js +28 -6
  116. package/dist/testSurface/placementLabel.d.ts +8 -0
  117. package/dist/testSurface/placementLabel.js +24 -0
  118. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  119. package/dist/testSurface/placements/placementLabels.js +2 -1
  120. package/dist/testSurface/results/results.css +1 -1
  121. package/dist/testSurface/results/results.model.d.ts +1 -1
  122. package/dist/testSurface/surface/contracts.d.ts +2 -0
  123. package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
  124. package/dist/testSurface/surface/editorPlacement.js +18 -0
  125. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
  126. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  127. package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
  128. package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
  129. package/dist/testSurface/surface/results/useResults.d.ts +4 -1
  130. package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
  131. package/dist/testSurface/surface/test/DeleteTest.js +171 -0
  132. package/dist/testSurface/surface/test/GoalSection.js +101 -74
  133. package/dist/testSurface/surface/test/TestSurface.js +29 -9
  134. package/dist/testSurface/surface/test/fields.d.ts +1 -3
  135. package/dist/testSurface/surface/test/fields.js +5 -35
  136. package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
  137. package/dist/testSurface/surface/useTestDocument.js +20 -4
  138. package/dist/testSurface/useApi.d.ts +4 -1
  139. package/dist/transitions/checkStart.d.ts +4 -1
  140. package/dist/transitions/checkStart.js +117 -14
  141. package/dist/transitions/contentFields.js +9 -5
  142. package/dist/transitions/makeContent.js +29 -9
  143. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  144. package/dist/transitions/nestedPlacementNames.js +33 -0
  145. package/dist/transitions/pageVersions.js +3 -1
  146. package/dist/transitions/placementInteractions.js +7 -4
  147. package/dist/transitions/placements.d.ts +26 -1
  148. package/dist/transitions/placements.js +239 -87
  149. package/dist/transitions/preflightData.d.ts +2 -1
  150. package/dist/transitions/preflightData.js +66 -3
  151. package/dist/transitions/start.js +4 -1
  152. package/dist/types/endpoints.d.ts +35 -1
  153. package/dist/types/endpoints.js +1 -1
  154. package/dist/types/puck.d.ts +1 -0
  155. package/dist/types/surface.d.ts +2 -0
  156. package/dist/ui/Button.js +2 -2
  157. package/dist/ui/Inputs.d.ts +4 -3
  158. package/dist/ui/Inputs.js +7 -4
  159. package/dist/ui/SelectControl.d.ts +33 -0
  160. package/dist/ui/SelectControl.js +504 -0
  161. package/dist/ui/Tabs.d.ts +0 -1
  162. package/dist/ui/Tabs.js +28 -40
  163. package/dist/ui/ui.css +18 -5
  164. package/package.json +3 -2
@@ -1,14 +1,18 @@
1
+ import { contentLocaleURL } from '../../testSurface/contentLocaleURL.js';
1
2
  import { isPreflightResult, readPreflight } from '../../testSurface/readPreflight.js';
2
3
  import { classifyReadinessRead } from '../../testSurface/readinessRead.js';
3
4
  const cache = new Map();
4
5
  const latest = new Map();
5
6
  const consumers = new Map();
6
- const keyFor = (api, id)=>JSON.stringify([
7
+ const keyFor = (api, id, contentLocale)=>JSON.stringify([
7
8
  api,
8
- String(id)
9
+ String(id),
10
+ ...contentLocale ? [
11
+ contentLocale
12
+ ] : []
9
13
  ]);
10
- function read(api, id, fresh, blocking = false) {
11
- const key = keyFor(api, id);
14
+ function read(api, id, fresh, blocking = false, contentLocale) {
15
+ const key = keyFor(api, id, contentLocale);
12
16
  const cached = cache.get(key);
13
17
  if (cached && (!fresh || cached.pending)) return cached;
14
18
  const controller = new AbortController();
@@ -29,7 +33,7 @@ function read(api, id, fresh, blocking = false) {
29
33
  for (const notify of consumers.get(key)?.listeners ?? [])notify(entry.value);
30
34
  entry.promise = (async ()=>{
31
35
  try {
32
- const { response, body: data } = await readPreflight((signal)=>fetch(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, {
36
+ const { response, body: data } = await readPreflight((signal)=>fetch(contentLocaleURL(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, contentLocale), {
33
37
  credentials: 'include',
34
38
  cache: 'no-store',
35
39
  signal
@@ -66,23 +70,23 @@ function read(api, id, fresh, blocking = false) {
66
70
  });
67
71
  return entry;
68
72
  }
69
- /** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id) {
70
- return read(api, id, true).promise;
73
+ /** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id, contentLocale) {
74
+ return read(api, id, true, false, contentLocale).promise;
71
75
  }
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));
76
+ /** Focus storms share the last attempt (including polling), at most once per ten seconds. */ export function focusPlacements(api, id, contentLocale) {
77
+ const previous = latest.get(keyFor(api, id, contentLocale));
74
78
  if (previous && Date.now() - previous.startedAt < 10_000) return previous.promise;
75
- return read(api, id, true).promise;
79
+ return read(api, id, true, false, contentLocale).promise;
76
80
  }
77
- export function invalidatePlacements(api, id) {
78
- const key = keyFor(api, id);
81
+ export function invalidatePlacements(api, id, contentLocale) {
82
+ const key = keyFor(api, id, contentLocale);
79
83
  cache.get(key)?.controller.abort();
80
84
  cache.delete(key);
81
- if (consumers.get(key)?.listeners.size) void read(api, id, true, true).promise;
85
+ if (consumers.get(key)?.listeners.size) void read(api, id, true, true, contentLocale).promise;
82
86
  else latest.delete(key);
83
87
  }
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);
88
+ /** Listen without starting a request; the drawer already owns its initial preflight. */ export function subscribePlacements(api, id, notify, contentLocale) {
89
+ const key = keyFor(api, id, contentLocale);
86
90
  let group = consumers.get(key);
87
91
  if (!group) {
88
92
  const listeners = new Set();
@@ -109,10 +113,10 @@ export function invalidatePlacements(api, id) {
109
113
  }
110
114
  };
111
115
  }
112
- export function acquirePlacements(api, id, notify, fresh = false) {
113
- const release = subscribePlacements(api, id, notify);
114
- const key = keyFor(api, id);
115
- const entry = read(api, id, fresh);
116
+ export function acquirePlacements(api, id, notify, fresh = false, contentLocale) {
117
+ const release = subscribePlacements(api, id, notify, contentLocale);
118
+ const key = keyFor(api, id, contentLocale);
119
+ const entry = read(api, id, fresh, false, contentLocale);
116
120
  if (entry.value !== undefined) notify(entry.value);
117
121
  let active = true;
118
122
  void entry.promise.then(()=>{
@@ -123,24 +127,24 @@ export function acquirePlacements(api, id, notify, fresh = false) {
123
127
  release();
124
128
  };
125
129
  }
126
- /** Drawer preflight uses this same producer and follows a superseding post-write read. */ export async function readEditorPreflight(api, id, signal, supersede = false) {
130
+ /** Drawer preflight uses this same producer and follows a superseding post-write read. */ export async function readEditorPreflight(api, id, signal, supersede = false, contentLocale) {
127
131
  if (signal.aborted) return new Response(null, {
128
132
  status: 503
129
133
  });
130
- const release = subscribePlacements(api, id, ()=>{});
134
+ const release = subscribePlacements(api, id, ()=>{}, contentLocale);
131
135
  signal.addEventListener('abort', release, {
132
136
  once: true
133
137
  });
134
138
  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);
139
+ if (supersede) invalidatePlacements(api, id, contentLocale);
140
+ const previous = latest.get(keyFor(api, id, contentLocale));
141
+ let entry = previous && Date.now() - previous.startedAt < 10_000 ? previous : read(api, id, true, false, contentLocale);
138
142
  while(!signal.aborted){
139
143
  await entry.promise;
140
144
  if (signal.aborted) return new Response(null, {
141
145
  status: 503
142
146
  });
143
- const current = latest.get(keyFor(api, id));
147
+ const current = latest.get(keyFor(api, id, contentLocale));
144
148
  if (current && current !== entry) {
145
149
  entry = current;
146
150
  continue;
@@ -157,27 +161,27 @@ export function acquirePlacements(api, id, notify, fresh = false) {
157
161
  release();
158
162
  }
159
163
  }
160
- /** Current readiness shares the same request and lifetime as placements. */ export function cachedPreflight(api, id) {
161
- const entry = latest.get(keyFor(api, id));
164
+ /** Current readiness shares the same request and lifetime as placements. */ export function cachedPreflight(api, id, contentLocale) {
165
+ const entry = latest.get(keyFor(api, id, contentLocale));
162
166
  return entry?.preflight ?? (entry?.pending ? entry.previousPreflight : undefined);
163
167
  }
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));
168
+ /** Mandatory post-write/refusal reads guard Start in every shared consumer. */ export function placementsBlocking(api, id, contentLocale) {
169
+ const entry = cache.get(keyFor(api, id, contentLocale));
166
170
  return entry?.pending === true && entry.blocking;
167
171
  }
168
- export function placementsPending(api, id) {
169
- return cache.get(keyFor(api, id))?.pending === true;
172
+ export function placementsPending(api, id, contentLocale) {
173
+ return cache.get(keyFor(api, id, contentLocale))?.pending === true;
170
174
  }
171
- /** Pending reads retain the complete settled classification, including terminal outcomes. */ export function cachedReadinessRead(api, id) {
172
- const entry = latest.get(keyFor(api, id));
175
+ /** Pending reads retain the complete settled classification, including terminal outcomes. */ export function cachedReadinessRead(api, id, contentLocale) {
176
+ const entry = latest.get(keyFor(api, id, contentLocale));
173
177
  return entry?.pending ? entry.previousRead : entry?.read;
174
178
  }
175
- export function placementReadError(api, id) {
176
- return cachedReadinessRead(api, id)?.message;
179
+ export function placementReadError(api, id, contentLocale) {
180
+ return cachedReadinessRead(api, id, contentLocale)?.message;
177
181
  }
178
182
  const notices = new WeakMap();
179
- const noticeDelay = (api, id)=>cachedReadinessRead(api, id)?.pollDelay ?? null;
180
- export function watchPlacementNotice(api, id, doc) {
183
+ const noticeDelay = (api, id, contentLocale)=>cachedReadinessRead(api, id, contentLocale)?.pollDelay ?? null;
184
+ export function watchPlacementNotice(api, id, doc, contentLocale) {
181
185
  let session = notices.get(doc);
182
186
  if (!session) {
183
187
  const requests = new Map();
@@ -196,17 +200,17 @@ export function watchPlacementNotice(api, id, doc) {
196
200
  }
197
201
  const eligible = [
198
202
  ...created.requests.values()
199
- ].filter((request)=>!request.pending && noticeDelay(request.api, request.id) !== null);
203
+ ].filter((request)=>!request.pending && noticeDelay(request.api, request.id, request.contentLocale) !== null);
200
204
  if (doc.visibilityState !== 'visible' || !eligible.length) return;
201
205
  created.timer = setTimeout(()=>{
202
206
  created.timer = undefined;
203
207
  if (doc.visibilityState !== 'visible') return;
204
- const due = eligible.filter((request)=>created.requests.get(keyFor(request.api, request.id)) === request && request.nextAt <= Date.now());
208
+ const due = eligible.filter((request)=>created.requests.get(keyFor(request.api, request.id, request.contentLocale)) === request && request.nextAt <= Date.now());
205
209
  for (const request of due){
206
210
  request.pending = true;
207
- void refreshPlacements(request.api, request.id).then(()=>{
211
+ void refreshPlacements(request.api, request.id, request.contentLocale).then(()=>{
208
212
  request.pending = false;
209
- request.nextAt = Date.now() + (noticeDelay(request.api, request.id) ?? 0);
213
+ request.nextAt = Date.now() + (noticeDelay(request.api, request.id, request.contentLocale) ?? 0);
210
214
  if (notices.get(doc) === created) created.schedule();
211
215
  });
212
216
  }
@@ -214,7 +218,7 @@ export function watchPlacementNotice(api, id, doc) {
214
218
  }, Math.max(0, Math.min(...eligible.map((request)=>request.nextAt)) - Date.now()));
215
219
  };
216
220
  created.visibility = ()=>{
217
- for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request.api, request.id) ?? 0);
221
+ for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request.api, request.id, request.contentLocale) ?? 0);
218
222
  created.schedule();
219
223
  };
220
224
  session = created;
@@ -222,24 +226,25 @@ export function watchPlacementNotice(api, id, doc) {
222
226
  doc.addEventListener('visibilitychange', created.visibility);
223
227
  }
224
228
  const current = session;
225
- const key = keyFor(api, id);
229
+ const key = keyFor(api, id, contentLocale);
226
230
  const existing = current.requests.get(key);
227
231
  const request = existing ?? {
228
232
  api,
229
233
  id,
234
+ contentLocale,
230
235
  subscribers: 0,
231
- nextAt: Date.now() + (noticeDelay(api, id) ?? 0),
236
+ nextAt: Date.now() + (noticeDelay(api, id, contentLocale) ?? 0),
232
237
  pending: false,
233
238
  release: ()=>{}
234
239
  };
235
240
  request.subscribers++;
236
241
  current.requests.set(key, request);
237
242
  if (!existing) request.release = subscribePlacements(api, id, ()=>{
238
- if (placementsPending(api, id)) return;
243
+ if (placementsPending(api, id, contentLocale)) return;
239
244
  // Manual/focus retries also reset the backoff after recovery.
240
- request.nextAt = Date.now() + (noticeDelay(api, id) ?? 0);
245
+ request.nextAt = Date.now() + (noticeDelay(api, id, contentLocale) ?? 0);
241
246
  current.schedule();
242
- });
247
+ }, contentLocale);
243
248
  if (!existing || current.timer === undefined) current.schedule();
244
249
  let active = true;
245
250
  return ()=>{
@@ -1,12 +1,8 @@
1
- import type { ExperimentRef } from '../../types/puck.js';
2
1
  type Targets = {
3
2
  test: HTMLElement;
4
3
  controls: HTMLElement;
5
- onChange: (value: ExperimentRef | null) => void;
6
4
  };
7
5
  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;
6
+ /** The custom field owns only its portal destinations never another data reader. */
7
+ export declare function TestSidebarField(): import("react").JSX.Element;
12
8
  export {};
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { createUsePuck, useGetPuck } from '@puckeditor/core';
4
- import { useEffect, useState, useSyncExternalStore, useRef } from 'react';
4
+ import { useEffect, useState, useSyncExternalStore } from 'react';
5
5
  const usePuckSelector = createUsePuck();
6
6
  // useGetPuck returns the store's stable getState function (Puck 0.24:7223–7228).
7
7
  // A WeakMap keeps separate editors (including their iframes) isolated.
@@ -34,10 +34,8 @@ export function useSidebarTargets(id) {
34
34
  };
35
35
  }, ()=>entry.targets.get(id), ()=>undefined);
36
36
  }
37
- /** The custom field owns only its portal destinations and binding callback, never another data reader. */ export function TestSidebarField({ onChange }) {
37
+ /** The custom field owns only its portal destinations never another data reader. */ export function TestSidebarField() {
38
38
  const getPuck = useGetPuck();
39
- const change = useRef(onChange);
40
- change.current = onChange;
41
39
  const id = usePuckSelector((state)=>state.selectedItem?.props.id);
42
40
  const [test, setTest] = useState(null);
43
41
  const [controls, setControls] = useState(null);
@@ -46,8 +44,7 @@ export function useSidebarTargets(id) {
46
44
  const entry = bridge(getPuck);
47
45
  const targets = {
48
46
  test,
49
- controls,
50
- onChange: (value)=>change.current(value)
47
+ controls
51
48
  };
52
49
  entry.targets.set(id, targets);
53
50
  for (const notify of entry.listeners)notify();
@@ -1,3 +1,3 @@
1
1
  import type { DocId } from '../../types/contracts.js';
2
2
  /** Subscribe only while save/publish guidance or a retryable placement failure is visible. */
3
- export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined): void;
3
+ export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined, contentLocale?: string): void;
@@ -1,14 +1,15 @@
1
1
  'use client';
2
2
  import { useEffect } from 'react';
3
3
  import { watchPlacementNotice } from './placementsCache.js';
4
- /** Subscribe only while save/publish guidance or a retryable placement failure is visible. */ export function usePlacementNotice(api, id, message) {
4
+ /** Subscribe only while save/publish guidance or a retryable placement failure is visible. */ export function usePlacementNotice(api, id, message, contentLocale) {
5
5
  const showing = message !== undefined && id !== undefined;
6
6
  useEffect(()=>{
7
7
  if (id === undefined || !showing) return;
8
- return watchPlacementNotice(api, id, document);
8
+ return watchPlacementNotice(api, id, document, contentLocale);
9
9
  }, [
10
10
  api,
11
11
  id,
12
- showing
12
+ showing,
13
+ contentLocale
13
14
  ]);
14
15
  }
@@ -0,0 +1,2 @@
1
+ /** Puck bindings use the documented object shape; plain strings are unbound. */
2
+ export declare function puckExperimentSlug(ref: unknown): string | undefined;
@@ -0,0 +1,3 @@
1
+ /** Puck bindings use the documented object shape; plain strings are unbound. */ export function puckExperimentSlug(ref) {
2
+ return ref !== null && typeof ref === 'object' && 'slug' in ref && typeof ref.slug === 'string' ? ref.slug : undefined;
3
+ }
@@ -0,0 +1,8 @@
1
+ export declare const nestedTestCopy: {
2
+ start: (outer?: string, inner?: string) => string;
3
+ readinessFallback: string;
4
+ editor: (outer?: string, inner?: string) => string;
5
+ publish: (outer?: string, inner?: string) => string;
6
+ hidden: (outer?: string) => string;
7
+ readiness: (detail: unknown) => string;
8
+ };
@@ -0,0 +1,22 @@
1
+ const innerLabel = (inner)=>inner ? `“${inner}”` : 'An Experiment block with no test chosen';
2
+ const outerLabel = (outer)=>outer ? `“${outer}”` : 'another test';
3
+ const moveLabel = (inner)=>inner ? `“${inner}”` : 'that block';
4
+ const location = (outer, inner)=>`${innerLabel(inner)} is inside a version of ${outerLabel(outer)}.`;
5
+ const start = (outer, inner)=>`${location(outer, inner)} A test can't go inside another test's version. Move ${moveLabel(inner)} out of that version before you start either test.`;
6
+ const readinessFallback = "A test is inside another test's version on this page. A test can't go inside another test's version. Move the inner test out of that version before you start either test.";
7
+ export const nestedTestCopy = {
8
+ start,
9
+ readinessFallback,
10
+ editor: (outer, inner)=>inner ? start(outer, inner) : `This test is inside a version of ${outerLabel(outer)}. A test can't go inside another test's version. Move this test out of that version before you start either test.`,
11
+ publish: (outer, inner)=>`${location(outer, inner)} A test can't go inside another test's version, so this page can't be published. Move ${moveLabel(inner)} out of that version, then publish.`,
12
+ hidden: (outer)=>`This test is inside a version of ${outerLabel(outer)}. It is hidden, so nothing is blocked now. If you show it again, the page can't be published until you move it out of that version.`,
13
+ readiness: (detail)=>(Array.isArray(detail) && detail.length ? detail : [
14
+ {}
15
+ ]).map((value)=>{
16
+ const pair = value && typeof value === 'object' ? value : {};
17
+ const text = (value)=>typeof value === 'string' && value.trim() ? value.trim() : undefined;
18
+ const message = typeof pair.outer === 'string' && typeof pair.inner === 'string' ? start(text(pair.outer), text(pair.inner)) : readinessFallback;
19
+ const title = text(pair.title);
20
+ return title ? `On ${title}: ${message}` : message;
21
+ }).join('\n')
22
+ };
@@ -0,0 +1,17 @@
1
+ import { type PuckBlock } from './visibility.js';
2
+ export interface NestedTest {
3
+ outer: PuckBlock;
4
+ inner: PuckBlock;
5
+ }
6
+ /** The placement traversal owns block shape, legacy zones and inherited visibility.
7
+ * Paste supplies its destination ancestors and includes hidden/unbound blocks.
8
+ */
9
+ export declare function nestedTests(data: unknown, { includeHidden, ancestors }?: {
10
+ includeHidden?: boolean;
11
+ ancestors?: readonly PuckBlock[];
12
+ }): NestedTest[];
13
+ export declare const nestedTestSlug: (block: PuckBlock) => string | undefined;
14
+ export declare const nestedTestLabel: (block: PuckBlock) => string;
15
+ export declare const nestedTestKey: ({ outer, inner }: NestedTest) => string;
16
+ /** Traversal records all ancestors, from furthest to nearest for each inner block. */
17
+ export declare const nearestOuterTest: (pairs: readonly NestedTest[], innerId: unknown) => PuckBlock | undefined;
@@ -0,0 +1,30 @@
1
+ import { EXPERIMENT_SLOT_TYPE } from '../types/puck.js';
2
+ import { puckExperimentSlug } from './experimentSlug.js';
3
+ import { walkVisiblePuck } from './visibility.js';
4
+ /** The placement traversal owns block shape, legacy zones and inherited visibility.
5
+ * Paste supplies its destination ancestors and includes hidden/unbound blocks.
6
+ */ export function nestedTests(data, { includeHidden = false, ancestors = [] } = {}) {
7
+ const result = [];
8
+ walkVisiblePuck(data, (inner, visibility, parents)=>{
9
+ if (!includeHidden && visibility.hidden || inner.type !== EXPERIMENT_SLOT_TYPE) return;
10
+ for (const outer of [
11
+ ...ancestors,
12
+ ...parents
13
+ ]){
14
+ if (outer.type === EXPERIMENT_SLOT_TYPE) result.push({
15
+ outer,
16
+ inner
17
+ });
18
+ }
19
+ });
20
+ return result;
21
+ }
22
+ export const nestedTestSlug = (block)=>puckExperimentSlug(block.props.experiment);
23
+ export const nestedTestLabel = (block)=>nestedTestSlug(block) ?? '';
24
+ export const nestedTestKey = ({ outer, inner })=>JSON.stringify([
25
+ outer.props.id,
26
+ nestedTestSlug(outer),
27
+ inner.props.id,
28
+ nestedTestSlug(inner)
29
+ ]);
30
+ /** Traversal records all ancestors, from furthest to nearest for each inner block. */ export const nearestOuterTest = (pairs, innerId)=>pairs.filter((pair)=>pair.inner.props.id === innerId).at(-1)?.outer;
@@ -1,5 +1,5 @@
1
1
  import type { ComponentConfig } from '@puckeditor/core';
2
- import type { ExperimentSlotProps } from '../types/puck.js';
2
+ import { type ExperimentSlotProps } from '../types/puck.js';
3
3
  export declare const experimentSlotLabel = "Experiment block";
4
4
  export declare const experimentSlotFields: NonNullable<ComponentConfig<ExperimentSlotProps>['fields']>;
5
5
  export declare const experimentSlotDefaultProps: NonNullable<ComponentConfig<ExperimentSlotProps>['defaultProps']>;
@@ -1,3 +1,4 @@
1
+ import { EXPERIMENT_SLOT_TYPE } from '../types/puck.js';
1
2
  import { createExperimentSlotField } from './experimentSlotField.js';
2
3
  import { slotLabels } from './copy.js';
3
4
  export const experimentSlotLabel = 'Experiment block';
@@ -6,19 +7,31 @@ export const experimentSlotFields = {
6
7
  // Puck 0.24's defaultSlots prepends each slot, reversing declaration order in the outline.
7
8
  variantC: {
8
9
  type: 'slot',
9
- label: slotLabels.variantC
10
+ label: slotLabels.variantC,
11
+ disallow: [
12
+ EXPERIMENT_SLOT_TYPE
13
+ ]
10
14
  },
11
15
  variantB: {
12
16
  type: 'slot',
13
- label: slotLabels.variantB
17
+ label: slotLabels.variantB,
18
+ disallow: [
19
+ EXPERIMENT_SLOT_TYPE
20
+ ]
14
21
  },
15
22
  variantA: {
16
23
  type: 'slot',
17
- label: slotLabels.variantA
24
+ label: slotLabels.variantA,
25
+ disallow: [
26
+ EXPERIMENT_SLOT_TYPE
27
+ ]
18
28
  },
19
29
  control: {
20
30
  type: 'slot',
21
- label: slotLabels.control
31
+ label: slotLabels.control,
32
+ disallow: [
33
+ EXPERIMENT_SLOT_TYPE
34
+ ]
22
35
  }
23
36
  };
24
37
  export const experimentSlotDefaultProps = {
@@ -0,0 +1,20 @@
1
+ /** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */
2
+ export declare const visibilitySizes: readonly ["phone", "tablet", "desktop"];
3
+ export type VisibilitySize = typeof visibilitySizes[number];
4
+ /** Read known sizes only; missing lists and malformed entries add no hiding. */
5
+ export declare function hiddenOnSizes(value: unknown): VisibilitySize[];
6
+ export declare function fullyHidden(value: unknown): boolean;
7
+ export type BlockVisibility = {
8
+ hidden: boolean;
9
+ hideOn: VisibilitySize[];
10
+ };
11
+ export type PuckBlock = Record<string, unknown> & {
12
+ type: string;
13
+ props: Record<string, unknown>;
14
+ };
15
+ /** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
16
+ * Orphan zones retain their historical discovery behavior and count as shown.
17
+ */
18
+ export declare function walkVisiblePuck(data: unknown, visit: (block: PuckBlock, visibility: BlockVisibility, ancestors: readonly PuckBlock[]) => void): void;
19
+ /** Identity-keyed index shared by discovery and the public resolver. */
20
+ export declare function puckVisibility(data: unknown): Map<object, BlockVisibility>;
@@ -0,0 +1,81 @@
1
+ /** payload-puck's stored visibility contract. No runtime dependency on the host plugin. */ export const visibilitySizes = [
2
+ 'phone',
3
+ 'tablet',
4
+ 'desktop'
5
+ ];
6
+ const object = (value)=>!!value && typeof value === 'object' && !Array.isArray(value);
7
+ /** Read known sizes only; missing lists and malformed entries add no hiding. */ export function hiddenOnSizes(value) {
8
+ if (!object(value) || !Array.isArray(value.hideOn)) return [];
9
+ const sizes = value.hideOn;
10
+ return visibilitySizes.filter((size)=>sizes.includes(size));
11
+ }
12
+ export function fullyHidden(value) {
13
+ return object(value) && (value.hidden === true || hiddenOnSizes(value).length === visibilitySizes.length);
14
+ }
15
+ /** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
16
+ * Orphan zones retain their historical discovery behavior and count as shown.
17
+ */ export function walkVisiblePuck(data, visit) {
18
+ const owners = new Set();
19
+ const zones = new Map();
20
+ const roots = [];
21
+ function index(value) {
22
+ if (Array.isArray(value)) {
23
+ value.forEach(index);
24
+ return;
25
+ }
26
+ if (!object(value)) return;
27
+ if (typeof value.type === 'string' && object(value.props) && typeof value.props.id === 'string') owners.add(value.props.id);
28
+ for (const [key, child] of Object.entries(value)){
29
+ if (value === data && key === 'zones' && object(child)) {
30
+ for (const [zone, content] of Object.entries(child)){
31
+ const owner = zone.slice(0, zone.lastIndexOf(':'));
32
+ zones.set(owner, [
33
+ ...zones.get(owner) ?? [],
34
+ content
35
+ ]);
36
+ roots.push({
37
+ owner,
38
+ content
39
+ });
40
+ index(content);
41
+ }
42
+ } else index(child);
43
+ }
44
+ }
45
+ index(data);
46
+ const seen = new WeakSet();
47
+ function walk(value, inherited, ancestors) {
48
+ if (Array.isArray(value)) {
49
+ value.forEach((child)=>walk(child, inherited, ancestors));
50
+ return;
51
+ }
52
+ if (!object(value) || seen.has(value)) return;
53
+ seen.add(value);
54
+ let visibility = inherited;
55
+ const props = value.props;
56
+ if (typeof value.type === 'string' && object(props)) {
57
+ visibility = {
58
+ hidden: inherited.hidden || fullyHidden(props._visibility),
59
+ hideOn: visibilitySizes.filter((size)=>inherited.hideOn.includes(size) || hiddenOnSizes(props._visibility).includes(size))
60
+ };
61
+ visit(value, visibility, ancestors);
62
+ ancestors = [
63
+ ...ancestors,
64
+ value
65
+ ];
66
+ if (typeof props.id === 'string') for (const content of zones.get(props.id) ?? [])walk(content, visibility, ancestors);
67
+ }
68
+ for (const [key, child] of Object.entries(value))if (value !== data || key !== 'zones' || !object(child)) walk(child, visibility, ancestors);
69
+ }
70
+ const shown = {
71
+ hidden: false,
72
+ hideOn: []
73
+ };
74
+ walk(data, shown, []);
75
+ for (const root of roots)if (!owners.has(root.owner)) walk(root.content, shown, []);
76
+ }
77
+ /** Identity-keyed index shared by discovery and the public resolver. */ export function puckVisibility(data) {
78
+ const result = new Map();
79
+ walkVisiblePuck(data, (block, visibility)=>result.set(block, visibility));
80
+ return result;
81
+ }