PluginProbe
Extendify / 3.1.3
Extendify v3.1.3
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 / change-site-design.js

change-site-design.js in Extendify 3.1.3, at src/Agent/workflows/theme/tools/change-site-design.js

49 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import changeHeroSection from '@agent/workflows/theme/tools/change-hero-section';
2 import updateSiteVibes from '@agent/workflows/theme/tools/update-site-vibes';
3 import { deepMerge } from '@shared/lib/utils';
4 import apiFetch from '@wordpress/api-fetch';
5
6 const { globalStylesPostID } = window.extSharedData;
7
8 // Apply the selected variation as authoritative, preserving only block style variations (vibes)
9 const updateVariation = async ({ variation }) => {
10 const currentVariations = await apiFetch({
11 path: '/extendify/v1/agent/block-style-variations',
12 });
13
14 const preservedBlockVibes = Object.keys(currentVariations).reduce(
15 (blocks, blockName) => {
16 blocks[blockName] = { variations: currentVariations[blockName] };
17 return blocks;
18 },
19 {},
20 );
21
22 const final = deepMerge(variation, {
23 styles: { blocks: preservedBlockVibes },
24 });
25
26 return apiFetch({
27 method: 'POST',
28 path: `/wp/v2/global-styles/${globalStylesPostID}`,
29 data: { id: globalStylesPostID, ...final },
30 });
31 };
32
33 export default async ({
34 updatedPageBlocks,
35 postId,
36 vibeSlug,
37 colorAndFontsVariation,
38 }) => {
39 if (!updatedPageBlocks || !vibeSlug || !colorAndFontsVariation) return;
40
41 await Promise.all([
42 changeHeroSection({ updatedPageBlocks, postId }),
43 (async () => {
44 await updateSiteVibes({ selectedVibe: vibeSlug });
45 await updateVariation({ variation: colorAndFontsVariation });
46 })(),
47 ]);
48 };
49