PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
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.0.5, at src/Agent/workflows/theme/tools/update-variation.js

33 lines 933 B
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 apiFetch from '@wordpress/api-fetch';
3
4 const { globalStylesPostID } = window.extSharedData;
5
6 // Will merge into the current variation and preserve block style variations (vibes)
7 export default async ({ variation }) => {
8 const currentTheme = await apiFetch({
9 path: `/wp/v2/global-styles/${globalStylesPostID}?context=edit`,
10 });
11 const currentVariations = await apiFetch({
12 path: '/extendify/v1/agent/block-style-variations',
13 });
14
15 const preservedBlockVibes = Object.keys(currentVariations).reduce(
16 (blocks, blockName) => {
17 blocks[blockName] = { variations: currentVariations[blockName] };
18 return blocks;
19 },
20 {},
21 );
22
23 const final = deepMerge(currentTheme, variation, {
24 styles: { blocks: preservedBlockVibes },
25 });
26
27 return apiFetch({
28 method: 'POST',
29 path: `/wp/v2/global-styles/${globalStylesPostID}`,
30 data: { id: globalStylesPostID, ...final },
31 });
32 };
33