@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/blocks/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +8 -4
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +7 -6
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +91 -37
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/PageWizard.js +1 -0
- package/dist/admin/surface/newTest/newTest.css +3 -1
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +8 -14
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +23 -7
- package/dist/blocks/placementLocale.js +221 -66
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +206 -0
- package/dist/endpoints/index.js +7 -0
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +6 -1
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/goals/fairness.js +43 -34
- package/dist/hooks/blockRemovalRule.d.ts +4 -3
- package/dist/hooks/blockRemovalRule.js +33 -9
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +34 -24
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +5 -1
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +37 -30
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +1 -0
- package/dist/puck/copy.js +1 -0
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
- package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
- package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
- package/dist/puck/editor/LeftoverVersions.js +23 -44
- package/dist/puck/editor/QuickTestActions.js +2 -2
- package/dist/puck/editor/VersionBuilder.d.ts +41 -13
- package/dist/puck/editor/VersionBuilder.js +461 -224
- package/dist/puck/editor/armWrites.d.ts +9 -2
- package/dist/puck/editor/armWrites.js +40 -2
- package/dist/puck/editor/armsCache.d.ts +1 -1
- package/dist/puck/editor/armsCache.js +2 -1
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +27 -26
- package/dist/puck/editor/copy.js +28 -26
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +138 -17
- package/dist/puck/editor/editor.css +156 -22
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +3 -3
- package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
- package/dist/puck/editor/localPlacements.d.ts +5 -2
- package/dist/puck/editor/localPlacements.js +32 -18
- package/dist/puck/editor/placementsCache.d.ts +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- package/dist/puck/editor/sidebar.d.ts +2 -6
- package/dist/puck/editor/sidebar.js +3 -6
- package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
- package/dist/puck/editor/usePlacementNotice.js +4 -3
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- package/dist/server/recordContentChange.js +37 -20
- package/dist/server/resolveExperimentData.js +6 -3
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/api.d.ts +6 -3
- package/dist/testSurface/api.js +10 -6
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/common.d.ts +4 -0
- package/dist/testSurface/copy/common.js +8 -4
- package/dist/testSurface/copy/languages.d.ts +11 -0
- package/dist/testSurface/copy/languages.js +7 -0
- package/dist/testSurface/copy/readiness.d.ts +2 -1
- package/dist/testSurface/copy/readiness.js +2 -1
- package/dist/testSurface/copy/testPage.d.ts +28 -6
- package/dist/testSurface/copy/testPage.js +28 -6
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/contracts.d.ts +2 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
- package/dist/testSurface/surface/editorPlacement.js +18 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
- package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
- package/dist/testSurface/surface/results/useResults.d.ts +4 -1
- package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
- package/dist/testSurface/surface/test/DeleteTest.js +171 -0
- package/dist/testSurface/surface/test/GoalSection.js +101 -74
- package/dist/testSurface/surface/test/TestSurface.js +29 -9
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
- package/dist/testSurface/surface/useTestDocument.js +20 -4
- package/dist/testSurface/useApi.d.ts +4 -1
- package/dist/transitions/checkStart.d.ts +4 -1
- package/dist/transitions/checkStart.js +117 -14
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/makeContent.js +29 -9
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +33 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/placementInteractions.js +7 -4
- package/dist/transitions/placements.d.ts +26 -1
- package/dist/transitions/placements.js +239 -87
- package/dist/transitions/preflightData.d.ts +2 -1
- package/dist/transitions/preflightData.js +66 -3
- package/dist/transitions/start.js +4 -1
- package/dist/types/endpoints.d.ts +35 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/puck.d.ts +1 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +7 -4
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/Tabs.d.ts +0 -1
- package/dist/ui/Tabs.js +28 -40
- package/dist/ui/ui.css +18 -5
- package/package.json +3 -2
|
@@ -1,48 +1,182 @@
|
|
|
1
1
|
import { sanitizeFallbackLocale } from 'payload';
|
|
2
|
-
import { flattenTopLevelFields } from 'payload/shared';
|
|
3
|
-
import { puckCollections } from '../options.js';
|
|
2
|
+
import { fieldShouldBeLocalized, flattenTopLevelFields } from 'payload/shared';
|
|
3
|
+
import { documentEditor, puckCollections } from '../options.js';
|
|
4
4
|
import { placementSlugs } from './bindings.js';
|
|
5
|
+
import { contentBlocks, hasLocalizedFields } from '../transitions/contentFields.js';
|
|
5
6
|
import { isObject } from './model.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
const locale = req.locale || localization.defaultLocale;
|
|
23
|
-
const fallback = sanitizeFallbackLocale({
|
|
24
|
-
fallbackLocale: req.fallbackLocale ?? null,
|
|
25
|
-
locale,
|
|
26
|
-
localization
|
|
7
|
+
const identity = (data)=>data;
|
|
8
|
+
// Sanitized schemas are immutable. Weak ownership keeps separate Payload configs
|
|
9
|
+
// (and test harnesses) isolated; locale transforms survive individual readers/saves.
|
|
10
|
+
const localeTransforms = new WeakMap();
|
|
11
|
+
/** Compile only schema-marked localized branches. Opaque field values are never traversed.
|
|
12
|
+
* Copy ancestors only when a localized descendant changes; ordinary branches retain identity.
|
|
13
|
+
*/ function localeTransform(payloadConfig, collection, locale, fallback) {
|
|
14
|
+
const config = payloadConfig.collections?.find((entry)=>entry.slug === collection);
|
|
15
|
+
if (!payloadConfig.localization || !config) return identity;
|
|
16
|
+
let collections = localeTransforms.get(payloadConfig);
|
|
17
|
+
if (!collections) localeTransforms.set(payloadConfig, collections = new WeakMap());
|
|
18
|
+
let cached = collections.get(config);
|
|
19
|
+
if (!cached || cached.fields !== config.fields) collections.set(config, cached = {
|
|
20
|
+
fields: config.fields,
|
|
21
|
+
transforms: new Map()
|
|
27
22
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
const key = JSON.stringify([
|
|
24
|
+
locale,
|
|
25
|
+
fallback
|
|
26
|
+
]);
|
|
27
|
+
const existing = cached.transforms.get(key);
|
|
28
|
+
if (existing) return existing;
|
|
29
|
+
const blocks = payloadConfig.blocks ?? [];
|
|
30
|
+
const compiled = new Map();
|
|
31
|
+
function compile(fields, parentIsLocalized = false) {
|
|
32
|
+
if (parentIsLocalized) return (data)=>data;
|
|
33
|
+
const cached = compiled.get(fields);
|
|
34
|
+
if (cached) return cached;
|
|
35
|
+
let project;
|
|
36
|
+
const transform = (data, write, previous)=>project(data, write, previous);
|
|
37
|
+
compiled.set(fields, transform);
|
|
38
|
+
const steps = flattenTopLevelFields(fields).flatMap((field)=>{
|
|
39
|
+
if (!('name' in field) || !field.name) return [];
|
|
40
|
+
const name = field.name;
|
|
41
|
+
const localized = fieldShouldBeLocalized({
|
|
42
|
+
field,
|
|
43
|
+
parentIsLocalized
|
|
44
|
+
});
|
|
45
|
+
const parent = parentIsLocalized || localized;
|
|
46
|
+
const children = 'fields' in field && hasLocalizedFields(field.fields, payloadConfig) && [
|
|
47
|
+
'group',
|
|
48
|
+
'array',
|
|
49
|
+
'tab'
|
|
50
|
+
].includes(field.type) ? compile(field.fields, parent) : undefined;
|
|
51
|
+
const variants = field.type === 'blocks' ? new Map([
|
|
52
|
+
...field.blocks ?? [],
|
|
53
|
+
...field.blockReferences ?? []
|
|
54
|
+
].flatMap((ref)=>{
|
|
55
|
+
const block = typeof ref === 'string' ? blocks.find((block)=>block.slug === ref) : ref;
|
|
56
|
+
return block && hasLocalizedFields(block.fields, payloadConfig) ? [
|
|
57
|
+
[
|
|
58
|
+
block.slug,
|
|
59
|
+
compile(block.fields, parent)
|
|
60
|
+
]
|
|
61
|
+
] : [];
|
|
62
|
+
})) : undefined;
|
|
63
|
+
if (!localized && !children && !variants) return [];
|
|
64
|
+
return [
|
|
65
|
+
(data, write, previous)=>{
|
|
66
|
+
if (!(name in data)) return data;
|
|
67
|
+
let value = data[name];
|
|
68
|
+
const prior = previous?.[name];
|
|
69
|
+
if (localized && write) value = {
|
|
70
|
+
...isObject(prior) ? prior : {},
|
|
71
|
+
[locale]: value
|
|
72
|
+
};
|
|
73
|
+
else {
|
|
74
|
+
if (localized) {
|
|
75
|
+
const values = isObject(value) ? value : {};
|
|
76
|
+
value = values[locale];
|
|
77
|
+
if (fallback && fallback !== locale && (value == null || (field.type === 'text' || field.type === 'textarea') && value === '')) {
|
|
78
|
+
for (const code of Array.isArray(fallback) ? fallback : [
|
|
79
|
+
fallback
|
|
80
|
+
]){
|
|
81
|
+
const candidate = values[code];
|
|
82
|
+
if (candidate != null && candidate !== '') {
|
|
83
|
+
value = candidate;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const visit = (row, old)=>{
|
|
90
|
+
if (!isObject(row)) return row;
|
|
91
|
+
const transform = children ?? (variants && typeof row.blockType === 'string' ? variants.get(row.blockType) : undefined);
|
|
92
|
+
return transform ? transform(row, write, isObject(old) ? old : undefined) : row;
|
|
93
|
+
};
|
|
94
|
+
if (children || variants) {
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
const rows = value.map((row, index)=>visit(row, Array.isArray(prior) ? isObject(row) && row.id != null ? prior.find((old)=>isObject(old) && old.id === row.id) : prior[index] : undefined));
|
|
97
|
+
if (rows.some((row, index)=>row !== value[index])) value = rows;
|
|
98
|
+
} else value = visit(value, prior);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return value === data[name] ? data : {
|
|
102
|
+
...data,
|
|
103
|
+
[name]: value
|
|
104
|
+
};
|
|
40
105
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
106
|
+
];
|
|
107
|
+
});
|
|
108
|
+
project = (data, write = false, previous)=>steps.reduce((result, step)=>step(result, write, previous), data);
|
|
109
|
+
return transform;
|
|
44
110
|
}
|
|
45
|
-
|
|
111
|
+
const transform = hasLocalizedFields(config.fields ?? [], payloadConfig) ? compile(config.fields ?? []) : identity;
|
|
112
|
+
cached.transforms.set(key, transform);
|
|
113
|
+
return transform;
|
|
114
|
+
}
|
|
115
|
+
export function placementLocaleContent(req, collection, doc, input) {
|
|
116
|
+
return placementReader(req, collection).read(doc, input).doc;
|
|
117
|
+
}
|
|
118
|
+
/** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
|
|
119
|
+
* Local API and form documents explicitly bypass all-locale projection.
|
|
120
|
+
*/ export function placementReader(req, collection, options = req.payload.config.custom?.xp) {
|
|
121
|
+
const views = placementLocaleViews(req, collection, options);
|
|
122
|
+
const transforms = new Map();
|
|
123
|
+
return {
|
|
124
|
+
views,
|
|
125
|
+
documentViews: schemaLocaleViews(req, collection),
|
|
126
|
+
read (doc, input, view) {
|
|
127
|
+
const requested = view ?? {
|
|
128
|
+
locale: req.locale ?? '',
|
|
129
|
+
fallbackLocale: req.fallbackLocale ?? false
|
|
130
|
+
};
|
|
131
|
+
const selected = requested.locale === 'all' ? {
|
|
132
|
+
...requested,
|
|
133
|
+
locale: req.payload.config.localization ? req.payload.config.localization.defaultLocale : ''
|
|
134
|
+
} : requested;
|
|
135
|
+
let content, resolved = false;
|
|
136
|
+
const resolve = ()=>{
|
|
137
|
+
if (resolved) return content;
|
|
138
|
+
resolved = true;
|
|
139
|
+
content = doc ?? undefined;
|
|
140
|
+
if (doc && input === 'all-locales' && req.payload.config.localization && selected.locale !== 'all') {
|
|
141
|
+
const locale = selected.locale || req.payload.config.localization.defaultLocale;
|
|
142
|
+
const key = JSON.stringify([
|
|
143
|
+
locale,
|
|
144
|
+
selected.fallbackLocale
|
|
145
|
+
]);
|
|
146
|
+
let transform = transforms.get(key);
|
|
147
|
+
if (!transform) {
|
|
148
|
+
transform = localeTransform(req.payload.config, collection, locale, sanitizeFallbackLocale({
|
|
149
|
+
fallbackLocale: selected.fallbackLocale,
|
|
150
|
+
locale,
|
|
151
|
+
localization: req.payload.config.localization
|
|
152
|
+
}));
|
|
153
|
+
transforms.set(key, transform);
|
|
154
|
+
}
|
|
155
|
+
content = transform(doc);
|
|
156
|
+
}
|
|
157
|
+
return content;
|
|
158
|
+
};
|
|
159
|
+
let editor, slugs;
|
|
160
|
+
return {
|
|
161
|
+
view: selected,
|
|
162
|
+
get doc () {
|
|
163
|
+
return resolve();
|
|
164
|
+
},
|
|
165
|
+
get editor () {
|
|
166
|
+
return editor ??= doc ? documentEditor(options ?? {}, collection, resolve()) : 'page';
|
|
167
|
+
},
|
|
168
|
+
get slugs () {
|
|
169
|
+
return slugs ??= placementSlugs(options ?? {}, collection, resolve());
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function allPlacementSlugs(req, collection, doc, input) {
|
|
176
|
+
const reader = placementReader(req, collection);
|
|
177
|
+
return [
|
|
178
|
+
...new Set(reader.views.flatMap((view)=>reader.read(doc, input, view).slugs))
|
|
179
|
+
];
|
|
46
180
|
}
|
|
47
181
|
export const placementDocumentKey = (collection, id, view)=>JSON.stringify([
|
|
48
182
|
collection,
|
|
@@ -50,21 +184,43 @@ export const placementDocumentKey = (collection, id, view)=>JSON.stringify([
|
|
|
50
184
|
view
|
|
51
185
|
]);
|
|
52
186
|
export function localeRequest(req, view) {
|
|
187
|
+
// Fetch Request properties are prototype getters and disappear in a spread.
|
|
188
|
+
// Local API setup needs headers/url; hooks also retain method and cancellation.
|
|
53
189
|
return {
|
|
54
190
|
...req,
|
|
191
|
+
headers: req.headers,
|
|
192
|
+
url: req.url,
|
|
193
|
+
method: req.method,
|
|
194
|
+
signal: req.signal,
|
|
55
195
|
...view
|
|
56
196
|
};
|
|
57
197
|
}
|
|
58
|
-
/**
|
|
198
|
+
/** Audits may contain localized arm-select tags outside registered editors. */ function schemaLocaleViews(req, collection) {
|
|
199
|
+
const localization = req.payload.config.localization;
|
|
200
|
+
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
201
|
+
return localization && hasLocalizedFields(config?.fields ?? [], req.payload.config) ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
|
|
202
|
+
locale,
|
|
203
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
204
|
+
fallbackLocale: null,
|
|
205
|
+
locale,
|
|
206
|
+
localization
|
|
207
|
+
})
|
|
208
|
+
})) : [
|
|
209
|
+
{
|
|
210
|
+
locale: '',
|
|
211
|
+
fallbackLocale: false
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
/** Canonical views of registered content, without multiplying nonlocalized rows. */ export function placementLocaleViews(req, collection, options = req.payload.config.custom?.xp ?? {}) {
|
|
59
216
|
const localization = req.payload.config.localization;
|
|
60
217
|
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
61
|
-
const options = req.payload.config.custom.xp;
|
|
62
218
|
const names = new Set([
|
|
63
219
|
...puckCollections(options).filter((entry)=>entry.slug === collection).map((entry)=>entry.field),
|
|
64
220
|
...(options.blocks?.collections ?? []).filter((entry)=>entry.slug === collection).map((entry)=>entry.field)
|
|
65
221
|
]);
|
|
66
|
-
const localized = config && flattenTopLevelFields(config.fields).some((field)=>'name' in field && names.has(field.name) && 'localized' in field && field.localized);
|
|
67
|
-
return localization && localized ? localization.localeCodes.map((locale)=>({
|
|
222
|
+
const localized = config && hasLocalizedFields(config.fields ?? [], req.payload.config) && (Boolean(options.blocks?.collections.some((entry)=>entry.slug === collection && entry.appliesTo)) || flattenTopLevelFields(config.fields ?? []).some((field)=>'name' in field && names.has(field.name) && ('localized' in field && field.localized || 'fields' in field && hasLocalizedFields(field.fields, req.payload.config) || field.type === 'blocks' && hasLocalizedFields(contentBlocks(field, req.payload.config.blocks).flatMap((block)=>block.fields), req.payload.config))));
|
|
223
|
+
return localization && localized ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
|
|
68
224
|
locale,
|
|
69
225
|
fallbackLocale: sanitizeFallbackLocale({
|
|
70
226
|
fallbackLocale: null,
|
|
@@ -81,31 +237,14 @@ export function localeRequest(req, view) {
|
|
|
81
237
|
/** Compare every locale view: a localized edit can also change fallback
|
|
82
238
|
* content in another locale. Whole-row removals replace every view with absence.
|
|
83
239
|
* The incoming hook document is already flattened to the writing locale.
|
|
84
|
-
*/ export function removedPlacementViews(req, collection, before, after, removingPage) {
|
|
240
|
+
*/ export function removedPlacementViews(req, collection, before, after, removingPage, input = 'localized') {
|
|
85
241
|
const result = new Map();
|
|
86
242
|
if (!before) return result;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Keep the raw locale maps for unchanged languages when merging a partial,
|
|
93
|
-
// flattened main-row write back into the adapter baseline.
|
|
94
|
-
const rawAfter = {
|
|
95
|
-
...after
|
|
96
|
-
};
|
|
97
|
-
if (localization && req.locale !== 'all') for (const field of localized){
|
|
98
|
-
if (!('name' in field) || typeof field.name !== 'string' || !(field.name in after)) continue;
|
|
99
|
-
const previousValue = before[field.name];
|
|
100
|
-
rawAfter[field.name] = {
|
|
101
|
-
...isObject(previousValue) ? previousValue : {},
|
|
102
|
-
[req.locale || localization.defaultLocale]: after[field.name]
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
for (const view of placementLocaleViews(req, collection)){
|
|
106
|
-
const viewReq = localeRequest(req, view);
|
|
107
|
-
const previous = placementSlugs(options, collection, placementLocaleContent(viewReq, collection, before));
|
|
108
|
-
const next = removingPage ? [] : placementSlugs(options, collection, placementLocaleContent(viewReq, collection, rawAfter));
|
|
243
|
+
const reader = placementReader(req, collection);
|
|
244
|
+
const rawAfter = input === 'all-locales' ? after : mergedPlacementLocales(req, collection, before, after);
|
|
245
|
+
for (const view of reader.views){
|
|
246
|
+
const previous = reader.read(before, 'all-locales', view).slugs;
|
|
247
|
+
const next = removingPage ? [] : reader.read(rawAfter, 'all-locales', view).slugs;
|
|
109
248
|
for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
|
|
110
249
|
...result.get(slug) ?? [],
|
|
111
250
|
view
|
|
@@ -113,3 +252,19 @@ export function localeRequest(req, view) {
|
|
|
113
252
|
}
|
|
114
253
|
return result;
|
|
115
254
|
}
|
|
255
|
+
/** Rebuild unchanged locale maps around a flattened hook write before reading each view. */ export function mergedPlacementLocales(req, collection, before, after) {
|
|
256
|
+
const localization = req.payload.config.localization;
|
|
257
|
+
if (!localization || req.locale === 'all') return after;
|
|
258
|
+
return localeTransform(req.payload.config, collection, req.locale || localization.defaultLocale, false)(after, true, before);
|
|
259
|
+
}
|
|
260
|
+
/** Project host document adapters before they run. Callers own path normalization
|
|
261
|
+
* and use sortLockKeys for the existing experiment → page-path lock ordering. */ export function placementDocumentPaths(req, collection, docs, input, pathOf) {
|
|
262
|
+
const reader = placementReader(req, collection);
|
|
263
|
+
return docs.flatMap((raw)=>reader.documentViews.flatMap((view)=>{
|
|
264
|
+
const doc = reader.read(raw, input, view).doc;
|
|
265
|
+
const path = doc ? pathOf(doc) : null;
|
|
266
|
+
return path === null ? [] : [
|
|
267
|
+
path
|
|
268
|
+
];
|
|
269
|
+
}));
|
|
270
|
+
}
|
package/dist/db/appends.d.ts
CHANGED
|
@@ -24,6 +24,19 @@ type AppendArgs<T> = {
|
|
|
24
24
|
* before the audit savepoint can recover.
|
|
25
25
|
*/
|
|
26
26
|
export declare function storedContent(req: PayloadRequest, collection: string, id: DocId): Promise<Record<string, unknown> | undefined>;
|
|
27
|
+
export interface PlacementSavePath {
|
|
28
|
+
versionId?: DocId;
|
|
29
|
+
bulk?: boolean;
|
|
30
|
+
draft?: boolean;
|
|
31
|
+
trashing?: boolean;
|
|
32
|
+
publishSpecificLocale?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
|
|
35
|
+
* starts from main rows except draft/trash saves. utilities/update then replaces
|
|
36
|
+
* unselected locales with the latest published version (publishSpecificLocale).
|
|
37
|
+
* Localized publication status is refused at init. Restore uses the selected version. */
|
|
38
|
+
export declare function placementMergeBase(path: PlacementSavePath): 'restore' | 'main' | 'published' | 'latest';
|
|
39
|
+
export declare function placementWriteContent(req: PayloadRequest, collection: string, id: DocId, main: Record<string, unknown> | undefined, path?: PlacementSavePath): Promise<Record<string, unknown> | undefined>;
|
|
27
40
|
/** Read the main collection row BEFORE the host write. Draft version retention
|
|
28
41
|
* and unpublishing cannot remove this baseline.
|
|
29
42
|
*/
|
package/dist/db/appends.js
CHANGED
|
@@ -18,6 +18,55 @@ import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
|
|
|
18
18
|
});
|
|
19
19
|
return doc ?? undefined;
|
|
20
20
|
}
|
|
21
|
+
/** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
|
|
22
|
+
* starts from main rows except draft/trash saves. utilities/update then replaces
|
|
23
|
+
* unselected locales with the latest published version (publishSpecificLocale).
|
|
24
|
+
* Localized publication status is refused at init. Restore uses the selected version. */ export function placementMergeBase(path) {
|
|
25
|
+
if (path.versionId != null) return 'restore';
|
|
26
|
+
if (path.publishSpecificLocale) return 'published';
|
|
27
|
+
return path.bulk && !path.draft && !path.trashing ? 'main' : 'latest';
|
|
28
|
+
}
|
|
29
|
+
export async function placementWriteContent(req, collection, id, main, path = {}) {
|
|
30
|
+
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
31
|
+
if (!config?.versions || !config.versions.drafts) return main;
|
|
32
|
+
const base = placementMergeBase(path);
|
|
33
|
+
if (base === 'main') return main;
|
|
34
|
+
// Adapter read on the guarded write's transaction; no Local API hook recursion.
|
|
35
|
+
const latest = await req.payload.db.findVersions({
|
|
36
|
+
collection,
|
|
37
|
+
req,
|
|
38
|
+
limit: 1,
|
|
39
|
+
pagination: false,
|
|
40
|
+
sort: '-updatedAt',
|
|
41
|
+
where: base === 'restore' ? {
|
|
42
|
+
id: {
|
|
43
|
+
equals: path.versionId
|
|
44
|
+
}
|
|
45
|
+
} : {
|
|
46
|
+
and: [
|
|
47
|
+
{
|
|
48
|
+
parent: {
|
|
49
|
+
equals: id
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
base === 'published' ? {
|
|
53
|
+
'version._status': {
|
|
54
|
+
equals: 'published'
|
|
55
|
+
}
|
|
56
|
+
} : {
|
|
57
|
+
latest: {
|
|
58
|
+
equals: true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
overrideAccess: false
|
|
64
|
+
});
|
|
65
|
+
return latest.docs[0] ? {
|
|
66
|
+
...latest.docs[0].version,
|
|
67
|
+
id
|
|
68
|
+
} : base === 'published' ? undefined : main;
|
|
69
|
+
}
|
|
21
70
|
/** Read the main collection row BEFORE the host write. Draft version retention
|
|
22
71
|
* and unpublishing cannot remove this baseline.
|
|
23
72
|
*/ export async function previousPublishedContent(req, collection, id) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removedPlacementViews, placementDocumentKey } from '../blocks/placementLocale.js';
|
|
1
|
+
import { placementLocaleContent, mergedPlacementLocales, removedPlacementViews, placementDocumentKey } from '../blocks/placementLocale.js';
|
|
2
2
|
// Payload starts/ends a transaction per bulk document with this adapter option.
|
|
3
3
|
export function usesBulkDocumentTransactions(req) {
|
|
4
4
|
return req.payload.db.bulkOperationsSingleTransaction === true;
|
|
@@ -98,10 +98,14 @@ const operationRequestState = Symbol('xpPlacementRequestState');
|
|
|
98
98
|
collection,
|
|
99
99
|
String(doc.id)
|
|
100
100
|
]))) return false;
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
// locale=all data and the adapter row share the same all-language shape.
|
|
102
|
+
// A single-locale write instead merges its flattened values once.
|
|
103
|
+
const input = req.locale === 'all' ? 'all-locales' : 'localized';
|
|
104
|
+
const pending = {
|
|
105
|
+
...input === 'all-locales' ? doc : placementLocaleContent(req, collection, doc, 'all-locales'),
|
|
103
106
|
...change.data
|
|
104
107
|
};
|
|
105
|
-
const
|
|
108
|
+
const after = input === 'all-locales' ? pending : mergedPlacementLocales(req, collection, doc, pending);
|
|
109
|
+
const views = removedPlacementViews(req, collection, doc, after, change.deleting || after.deletedAt != null || after._status === 'draft', 'all-locales');
|
|
106
110
|
return (views.get(slug) ?? []).some((removed)=>placementDocumentKey(collection, doc.id, removed) === placementDocumentKey(collection, doc.id, view));
|
|
107
111
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
/** Validate advisory-read metadata language; placement discovery still scans all languages. */
|
|
3
|
+
export declare function contentLocale(req: PayloadRequest): {
|
|
4
|
+
locale: string | null | undefined;
|
|
5
|
+
fallbackLocale: false | "none" | "false" | "null" | ({} & string) | ({} & string)[] | null | undefined;
|
|
6
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sanitizeFallbackLocale } from 'payload';
|
|
2
|
+
/** Validate advisory-read metadata language; placement discovery still scans all languages. */ export function contentLocale(req) {
|
|
3
|
+
const localization = req.payload.config.localization;
|
|
4
|
+
const requested = new URL(req.url ?? 'http://xp.invalid').searchParams.get('locale') ?? req.locale;
|
|
5
|
+
const locale = localization ? localization.localeCodes.includes(requested ?? '') ? requested : localization.defaultLocale : undefined;
|
|
6
|
+
const fallbackLocale = localization ? sanitizeFallbackLocale({
|
|
7
|
+
fallbackLocale: req.fallbackLocale ?? null,
|
|
8
|
+
locale: locale,
|
|
9
|
+
localization
|
|
10
|
+
}) : req.fallbackLocale;
|
|
11
|
+
return {
|
|
12
|
+
locale,
|
|
13
|
+
fallbackLocale
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
import type { EndpointContext } from '../types/endpoints.js';
|
|
3
|
+
/** Advisory read only. Delete keeps its own access check, status guard and transaction. */
|
|
4
|
+
export declare function handleDeleteImpact<TUser extends {
|
|
5
|
+
id: string | number;
|
|
6
|
+
}>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
|