From b0e23ec193026719ea1df945632955026e15328b Mon Sep 17 00:00:00 2001 From: Jan-CoreBunch Date: Tue, 13 Oct 2026 15:32:32 +0200 Subject: [PATCH 1/2] fix(colors): keep RAW variable variants in sync --- CHANGELOG.md | 1 + docs.md | 2 + .../components/ColorAdditionalVariations.tsx | 30 +-- .../components/ColorBodyValues.tsx | 69 +----- .../colorSystem/components/ColorSingleRow.tsx | 8 + .../rawColorVariantPersistence.test.ts | 175 +++++++++++++++ .../__tests__/rawColorVariants.test.ts | 199 ++++++++++++++++++ .../functions/generateColorSystemVariables.ts | 11 +- .../functions/generateShadesTints.ts | 53 +++-- .../modules/colorSystem/functions/getColor.ts | 17 +- .../colorSystem/functions/getColorOnIndex.ts | 8 +- .../functions/refreshColorReferences.ts | 81 +++++++ .../functions/singleColorReducer.ts | 31 +-- .../functions/updateColorVariations.ts | 61 ++++++ .../colorSystem/schema/colorSystem.schema.ts | 1 + .../modules/colorSystem/types/index.d.ts | 10 +- packages/wp/src/components/Side.tsx | 4 - .../wp/src/functions/preparePresetToLoad.ts | 12 ++ packages/wp/src/hooks/useGetColor.ts | 15 +- packages/wp/src/hooks/usePush.ts | 14 +- packages/www/src/components/Side.tsx | 4 - .../www/src/functions/preparePresetToLoad.ts | 12 ++ packages/www/src/hooks/useGetColor.ts | 15 +- packages/www/src/hooks/usePushFigmaSync.ts | 14 +- 24 files changed, 687 insertions(+), 160 deletions(-) create mode 100644 packages/core/src/components/modules/colorSystem/functions/__tests__/rawColorVariantPersistence.test.ts create mode 100644 packages/core/src/components/modules/colorSystem/functions/__tests__/rawColorVariants.test.ts create mode 100644 packages/core/src/components/modules/colorSystem/functions/refreshColorReferences.ts create mode 100644 packages/core/src/components/modules/colorSystem/functions/updateColorVariations.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f665b8f..a225e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +- Fixed transparent variants and shade/tint counts for RAW colors that reference another variable, such as `var(--bg-body)`. Generated variants now follow the current source color, while manually edited swatches are preserved. Older saved swatches without edit history are left unchanged on load; use Reset on a stale swatch to return it to automatic generation, then save to update the site's CSS. - Fixed the block editor going blank with the Core Framework Gutenberg integration enabled. The editor script was loaded with an outdated, hard-coded dependency list that left out WordPress's `react-jsx-runtime`, so rendering the Core Framework class panel threw on an undefined `ReactJSXRuntime` and took the whole editor down. The script now loads the dependencies its build declares. - Fixed saving from the Figma plugin to a connected WordPress site, which waited 15 seconds and then reported "Failed to sync css with Figma" and "Failed to update project" even though the changes had reached the site. The plugin handed WordPress's reply back under the wrong message type, so the editor never recognised it. Builder synchronization now also waits for the stylesheet and project to finish saving, so Bricks global variables, color swatches and the Style Manager show the values you just saved, including on projects that define variables but no classes. An empty class list no longer creates a blank Oxygen selector. - Stopped disabled shades and tints from appearing as variables in the Oxygen and Bricks builders. The generated CSS already left out a color's shades or tints once you switched them off, but the builder variable dropdowns and Oxygen Classic's Alt-click variable panel still listed them, so picking one pointed at a custom property that did not exist. diff --git a/docs.md b/docs.md index b9da13e..0314b55 100644 --- a/docs.md +++ b/docs.md @@ -71,6 +71,8 @@ The project schema is defined in the shared core and describes: - breakpoints and responsive settings - project preferences and version information +Color shade/tint entries support an optional `isCustom` flag: `false` identifies an automatically generated swatch, `true` preserves a manual edit, and an absent flag represents older data with unknown edit history. Reset returns a swatch to automatic generation. Loading a preset refreshes known automatic variants of RAW variable references using the current color data, while preserving custom and unclassified older swatches. This normalization is independent of the existing versioned migrations; older presets remain valid without the new field, and color IDs and variant names are unchanged. + The usual load flow is: 1. Load project data from browser storage, WordPress, or an explicit import. diff --git a/packages/core/src/components/modules/colorSystem/components/ColorAdditionalVariations.tsx b/packages/core/src/components/modules/colorSystem/components/ColorAdditionalVariations.tsx index dbc19d7..03dff37 100644 --- a/packages/core/src/components/modules/colorSystem/components/ColorAdditionalVariations.tsx +++ b/packages/core/src/components/modules/colorSystem/components/ColorAdditionalVariations.tsx @@ -1,7 +1,8 @@ -import { ChangeEvent, memo, useCallback, useMemo, useState } from "react"; +import { ChangeEvent, memo, useCallback, useMemo } from "react"; import { Info } from "assets/icons/Info.icon"; import { NumberInput } from "components/basic/NumberInput"; import { Tooltip } from "components/ui/Tooltip"; +import { useGetColor } from "hooks/useGetColor"; import { getColorOnIndex } from "../functions/getColorOnIndex"; import { ColorFormatValue, ColorItem, DEFAULT_SHADES_COUNT, DEFAULT_TINTS_COUNT, Shade } from "../index"; import { Collapse, Switch } from "@mantine/core"; @@ -12,12 +13,12 @@ const getInitialVariation = (color: ColorItem, variant: Variant): VariantValues if (variant === "shade") { return { isActive: color.isShades ?? false, - number: color.shadesNumber || DEFAULT_SHADES_COUNT, + number: color.shadesNumber || color.shades?.length || DEFAULT_SHADES_COUNT, }; } else { return { isActive: color.isTints ?? false, - number: color.tintsNumber || DEFAULT_TINTS_COUNT, + number: color.tintsNumber || color.tints?.length || DEFAULT_TINTS_COUNT, }; } }; @@ -33,12 +34,13 @@ interface ColorAdditionalVariations { color: ColorItem; variant: Variant; onChange: (value: VariantValues) => void; - onUpdateColor: (value: string, index: number, isDark: boolean) => void; + onUpdateColor: (value: string, index: number, isDark: boolean, reset?: boolean) => void; } export const ColorAdditionalVariations = memo( ({ color, variant, onChange, onUpdateColor }) => { - const [variation, setVariation] = useState(() => getInitialVariation(color, variant)); + const variation = getInitialVariation(color, variant); + const { colorVariables } = useGetColor(); const items = useMemo(() => (variant === "shade" ? color.shades : color.tints), [color, variant]); const darkItems = useMemo(() => (variant === "shade" ? color.darkShades : color.darkTints), [color, variant]); @@ -46,7 +48,6 @@ export const ColorAdditionalVariations = memo( const handleSwitchChange = useCallback( ({ target: { checked } }: ChangeEvent) => { onChange({ ...variation, isActive: checked }); - setVariation((prev) => ({ ...prev, isActive: checked })); }, [onChange, variation], ); @@ -54,7 +55,6 @@ export const ColorAdditionalVariations = memo( const handleNumberChange = useCallback( (value: number | string) => { onChange({ ...variation, number: Number(value) }); - setVariation((prev) => ({ ...prev, number: Number(value) })); }, [onChange, variation], ); @@ -72,7 +72,7 @@ export const ColorAdditionalVariations = memo(