PluginProbe
Extendify / 3.1.6
Extendify v3.1.6
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / workflows / theme / tools / update-variation.js

update-variation.js in Extendify 3.1.6, at src/Agent/workflows/theme/tools/update-variation.js

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { deepMerge } from '@shared/lib/utils';
2 import {
3 preserveVibeSettings,
4 preserveVibeStyles,
5 vibeGlobalsEntry,
6 } from '@shared/lib/vibe-globals';
7 import { getVibes, vibesBySlug } from '@shared/lib/vibes';
8 import apiFetch from '@wordpress/api-fetch';
9
10 const { globalStylesPostID } = window.extSharedData;
11
12 // The vibe layer keeps its owned leaves even when the variation declares them.
13 export default async ({ variation }) => {
14 const [current, vibes] = await Promise.all([
15 apiFetch({
16 path: `/wp/v2/global-styles/${globalStylesPostID}?context=edit`,
17 }),
18 getCurrentVibes(),
19 ]);
20
21 const merged = deepMerge(
22 { settings: current.settings, styles: current.styles },
23 variation,
24 );
25
26 return apiFetch({
27 method: 'POST',
28 path: `/wp/v2/global-styles/${globalStylesPostID}`,
29 data: {
30 id: globalStylesPostID,
31 settings: preserveVibeSettings({
32 mergedSettings: merged.settings,
33 currentSettings: current.settings,
34 vibes,
35 }),
36 styles: preserveVibeStyles({
37 mergedStyles: merged.styles,
38 currentStyles: current.styles,
39 vibes,
40 }),
41 },
42 });
43 };
44
45 const getCurrentVibes = async () => {
46 try {
47 const { data } = await apiFetch({
48 path: '/extendify/v1/launch/options?option=extendify_siteStyle',
49 });
50 const selectedVibe = data?.vibe || 'natural-1';
51 const payloads = await getVibes(`agent,${selectedVibe}`);
52 // Widening to the served set purges leaves this vibe never declared.
53 const entry = vibeGlobalsEntry(vibesBySlug(payloads), selectedVibe);
54 return entry ? { [selectedVibe]: entry } : {};
55 } catch {
56 // No payloads means no ownership map; the merged document ships as-is.
57 return {};
58 }
59 };
60