PluginProbe
Extendify / 3.1.5
Extendify v3.1.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 / select-generated-palette.js

select-generated-palette.js in Extendify 3.1.5, at src/Agent/workflows/theme/tools/select-generated-palette.js

65 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2
3 const id = window.extSharedData.globalStylesPostID;
4
5 export default async ({ palette, duotone }) => {
6 const currentStyles = await apiFetch({
7 path: `/wp/v2/global-styles/${id}`,
8 });
9
10 const currentVibes = await apiFetch({
11 path: '/extendify/v1/agent/block-style-variations',
12 });
13
14 const preservedBlocks = Object.keys(currentVibes).reduce(
15 (blocks, blockName) => {
16 blocks[blockName] = {
17 ...currentStyles.styles?.blocks?.[blockName],
18 variations: currentVibes[blockName],
19 };
20 return blocks;
21 },
22 {},
23 );
24
25 const newPalette = palette.colors.map(({ slug, color, name }) => ({
26 slug,
27 color,
28 name,
29 }));
30
31 const colorSettings = {
32 ...currentStyles.settings?.color,
33 palette: {
34 ...currentStyles.settings?.color?.palette,
35 theme: newPalette,
36 },
37 };
38
39 if (duotone) {
40 colorSettings.duotone = {
41 ...currentStyles.settings?.color?.duotone,
42 theme: duotone,
43 };
44 }
45
46 return apiFetch({
47 method: 'POST',
48 path: `/wp/v2/global-styles/${id}`,
49 data: {
50 id,
51 settings: {
52 ...currentStyles.settings,
53 color: colorSettings,
54 },
55 styles: {
56 ...currentStyles.styles,
57 blocks: {
58 ...currentStyles.styles?.blocks,
59 ...preservedBlocks,
60 },
61 },
62 },
63 });
64 };
65