PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
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
← All changes | src/AutoLaunch/functions/vibes.js +28 -52 3.1.23.2.1 View file →
@@ -1,6 +1,9 @@
1 -import { getGlobalStyles } from '@auto-launch/functions/theme';
1 +import { replaceVibeBlocks } from '@shared/lib/vibe-blocks';
2 +import { applyVibeGlobals, applyVibeStyles } from '@shared/lib/vibe-globals';
3 +import { getVibes, vibesBySlug } from '@shared/lib/vibes';
2 4
5 +// natural-1 is what the theme already ships, so it contributes nothing.
3 6 const isValidVibe = (selectedVibe) =>
4 7 !!selectedVibe &&
5 8 typeof selectedVibe === 'string' &&
6 9 selectedVibe.trim() !== '' &&
@@ -5,61 +8,34 @@
5 8 typeof selectedVibe === 'string' &&
6 9 selectedVibe.trim() !== '' &&
7 10 selectedVibe !== 'natural-1';
8 11
9 -const generateSourceStyleName = (naturalStyleName, targetVibe) =>
10 - naturalStyleName.replace('--natural-1--', `--${targetVibe}--`);
11 -
12 -const processBlockVariations = (variations, targetVibe) =>
13 - Object.fromEntries(
14 - Object.entries(variations).map(([styleName, styleProperties]) => {
15 - if (!styleName.includes('--natural-1--')) {
16 - return [styleName, { ...styleProperties }];
17 - }
18 -
19 - const sourceStyleName = generateSourceStyleName(styleName, targetVibe);
20 - const sourceStyle = variations[sourceStyleName];
21 -
22 - return [
23 - styleName,
24 - sourceStyle ? { ...sourceStyle } : { ...styleProperties },
25 - ];
26 - }),
27 - );
28 -
29 -// Compute the vibe-adjusted blocks from the theme's global styles.
30 -// Returns the blocks object (ready to merge into a variation) without
31 -// POSTing anything. Callers should merge the result into the variation's
32 -// styles before calling updateVariation — doing it this way avoids a
33 -// separate POST that would overwrite the fonts, colors and other style
34 -// overrides already set in the variation.
35 -export const computeVibeAdjustedBlocks = async (selectedVibe) => {
12 +// Layout rides along because WordPress derives fluid type from wideSize.
13 +export const computeVibeAdjustments = async (selectedVibe, variation) => {
36 14 if (!isValidVibe(selectedVibe)) return null;
37 15
38 - const { styles: themeStyles } = await getGlobalStyles();
39 - if (!themeStyles?.blocks) return null;
16 + const vibes = vibesBySlug(await getVibes(selectedVibe));
17 + const vibe = vibes[selectedVibe];
18 + if (!vibe) return null;
40 19
41 - return Object.fromEntries(
42 - Object.entries(themeStyles.blocks).map(([blockName, blockObj]) => {
43 - if (!blockObj?.variations) {
44 - return [blockName, blockObj];
45 - }
20 + const styles = applyVibeStyles({
21 + currentStyles: variation?.styles ?? {},
22 + vibeStyles: vibe.styles,
23 + vibes,
24 + });
46 25
47 - const { variations, ...rest } = blockObj;
48 - const hasNaturalVariations = Object.keys(variations).some((styleName) =>
49 - styleName.includes('--natural-1--'),
50 - );
51 -
52 - if (!hasNaturalVariations) {
53 - return [blockName, blockObj];
54 - }
55 -
56 - return [
57 - blockName,
58 - {
59 - ...rest,
60 - variations: processBlockVariations(variations, selectedVibe),
61 - },
62 - ];
26 + return {
27 + settings: applyVibeGlobals({
28 + currentSettings: variation?.settings ?? {},
29 + vibeSettings: vibe.settings,
30 + vibes,
63 31 }),
64 - );
32 + styles: {
33 + ...styles,
34 + blocks: replaceVibeBlocks({
35 + currentBlocks: styles?.blocks,
36 + vibeBlocks: vibe.blocks,
37 + selectedVibe,
38 + }),
39 + },
40 + };
65 41 };