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
extendify / src / Shared / lib / vibe-blocks.js

vibe-blocks.js in Extendify 3.2.1, at src/Shared/lib/vibe-blocks.js

59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { isObject } from '@shared/lib/utils';
2
3 // Patterns are authored against natural-1 class names, so each payload node is
4 // re-keyed from the vibe's own slug to its natural-1 name.
5 export const rekeyVibeBlocks = (vibeBlocks, selectedVibe) =>
6 Object.fromEntries(
7 Object.entries(vibeBlocks ?? {})
8 .filter(([, variations]) => isObject(variations))
9 .map(([blockName, variations]) => [
10 blockName,
11 {
12 variations: Object.fromEntries(
13 Object.entries(variations).map(([styleName, styleProperties]) => [
14 styleName.replace(`--${selectedVibe}--`, '--natural-1--'),
15 { ...styleProperties },
16 ]),
17 ),
18 },
19 ]),
20 );
21
22 // ext-preset-- variations belong to the outgoing vibe; user variations stay.
23 // natural-1 is written too: a theme with no presets has nothing to fall back on.
24 export const replaceVibeBlocks = ({
25 currentBlocks = {},
26 vibeBlocks = {},
27 selectedVibe,
28 }) => {
29 const updatedBlocks = Object.fromEntries(
30 Object.entries(currentBlocks).map(([blockName, blockObj]) => {
31 const { variations = {}, ...rest } = blockObj;
32 const userVariations = Object.fromEntries(
33 Object.entries(variations).filter(
34 ([styleName]) => !styleName.startsWith('ext-preset--'),
35 ),
36 );
37
38 return [
39 blockName,
40 Object.keys(userVariations).length > 0
41 ? { ...rest, variations: userVariations }
42 : rest,
43 ];
44 }),
45 );
46
47 for (const [blockName, { variations }] of Object.entries(
48 rekeyVibeBlocks(vibeBlocks, selectedVibe),
49 )) {
50 const currentBlock = updatedBlocks[blockName] || {};
51 updatedBlocks[blockName] = {
52 ...currentBlock,
53 variations: { ...currentBlock.variations, ...variations },
54 };
55 }
56
57 return updatedBlocks;
58 };
59