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

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