| 1 |
import { |
| 2 |
applyOwnedSection, |
| 3 |
collectOwnedPaths, |
| 4 |
} from '@shared/lib/owned-globals'; |
| 5 |
|
| 6 |
const ownedSettings = ['layout', 'typography', 'custom']; |
| 7 |
// Per-leaf, so clearing a heading size leaves fontFamily to the fonts layer. |
| 8 |
// WordPress reads duotone per block name, never per variation, so blocks is owned here. |
| 9 |
const ownedStyles = ['typography', 'elements', 'blocks']; |
| 10 |
|
| 11 |
// The fonts and palette layers own these; a declaring payload is ignored. |
| 12 |
const isExcludedPath = (section, path) => { |
| 13 |
if (path[path.length - 1] === 'fontFamily') return true; |
| 14 |
if (section !== 'settings') return false; |
| 15 |
if (path[0] === 'color') return true; |
| 16 |
return path[0] === 'typography' && path[1] === 'fontFamilies'; |
| 17 |
}; |
| 18 |
|
| 19 |
export const ownedSettingPaths = (vibes) => |
| 20 |
collectOwnedPaths({ |
| 21 |
payloads: vibes, |
| 22 |
section: 'settings', |
| 23 |
roots: ownedSettings, |
| 24 |
exclude: isExcludedPath, |
| 25 |
}); |
| 26 |
|
| 27 |
export const ownedStylePaths = (vibes) => |
| 28 |
collectOwnedPaths({ |
| 29 |
payloads: vibes, |
| 30 |
section: 'styles', |
| 31 |
roots: ownedStyles, |
| 32 |
exclude: isExcludedPath, |
| 33 |
}); |
| 34 |
|
| 35 |
export const applyVibeGlobals = ({ currentSettings, vibeSettings, vibes }) => |
| 36 |
applyOwnedSection(currentSettings, vibeSettings, ownedSettingPaths(vibes)); |
| 37 |
|
| 38 |
export const applyVibeStyles = ({ currentStyles, vibeStyles, vibes }) => |
| 39 |
applyOwnedSection(currentStyles, vibeStyles, ownedStylePaths(vibes)); |
| 40 |
|
| 41 |
// A fonts or colors write may not move vibe-owned leaves. |
| 42 |
export const preserveVibeSettings = ({ |
| 43 |
mergedSettings, |
| 44 |
currentSettings, |
| 45 |
vibes, |
| 46 |
}) => |
| 47 |
applyOwnedSection(mergedSettings, currentSettings, ownedSettingPaths(vibes)); |
| 48 |
|
| 49 |
export const preserveVibeStyles = ({ mergedStyles, currentStyles, vibes }) => |
| 50 |
applyOwnedSection(mergedStyles, currentStyles, ownedStylePaths(vibes)); |
| 51 |
|
| 52 |
// natural-1 is what the theme ships, so writing it would only restate the theme. |
| 53 |
export const vibeGlobalsEntry = (vibes, selectedVibe) => |
| 54 |
selectedVibe === 'natural-1' ? undefined : vibes?.[selectedVibe]; |
| 55 |
|