Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Drop inherited style from style panel (#698)

Bogdan Chadkinee53b09c326f
diff --git a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
index 1425eaf273..28885f80b0 100644
--- a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
@@ -7,13 +7,11 @@ import { colord } from "colord";
export const ColorControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
let value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
}) ?? {
// provide default value to avoid control hiding
diff --git a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx
index 4101f3be7b..8a200cb23f 100644
--- a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx
@@ -8,14 +8,12 @@ import { toValue } from "@webstudio-is/css-engine";
export const FontFamilyControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
// @todo show which instance we inherited the value from
const value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
const [isOpen, setIsOpen] = useState(false);
diff --git a/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx
index af43e55e57..27986c1458 100644
--- a/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/font-weight/font-weight-control.tsx
@@ -69,21 +69,18 @@ const useLabels = (
export const FontWeightControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
// @todo show which instance we inherited the value from
const fontWeight = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
// We need the font family to determine which font weights are available
const fontFamily = getFinalValue({
currentStyle,
- inheritedStyle,
property: "fontFamily",
});
diff --git a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx b/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx
index 680ab105e6..a4c8e3f0cc 100644
--- a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx
@@ -8,7 +8,6 @@ import { toValue } from "@webstudio-is/css-engine";
export const ImageControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
@@ -16,7 +15,6 @@ export const ImageControl = ({
// @todo show which instance we inherited the value from
const value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
diff --git a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
index 66d50e09b5..58e535ff0e 100644
--- a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
@@ -7,13 +7,11 @@ import { toValue } from "@webstudio-is/css-engine";
export const MenuControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
const value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
const isFromCurrentBreakpoint = useIsFromCurrentBreakpoint(
diff --git a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
index 14e21be4d3..d74075ec44 100644
--- a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
@@ -5,14 +5,12 @@ import type { ControlProps } from "../../style-sections";
export const SelectControl = ({
currentStyle,
- inheritedStyle,
setProperty,
styleConfig,
}: ControlProps) => {
// @todo show which instance we inherited the value from
const value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index 29be0772b3..6565d23394 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -10,7 +10,6 @@ import { Box, EnhancedTooltip } from "@webstudio-is/design-system";
export const TextControl = ({
currentStyle,
- inheritedStyle,
setProperty,
deleteProperty,
styleConfig,
@@ -18,7 +17,6 @@ export const TextControl = ({
}: ControlProps & { icon?: JSX.Element }) => {
const value = getFinalValue({
currentStyle,
- inheritedStyle,
property: styleConfig.property,
});
@@ -59,7 +57,7 @@ export const TextControl = ({
deleteProperty(styleConfig.property, { isEphemeral: true });
}
}}
- onChangeComplete={({ value, reason }) => {
+ onChangeComplete={({ value }) => {
setValue(value);
setIntermediateValue(undefined);
}}
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
index 204d54dc08..e413fdf754 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
@@ -39,7 +39,6 @@ const LayoutSectionFlex = ({
const flexWrapValue = getFinalValue({
currentStyle: flexWrap.currentStyle,
- inheritedStyle: flexWrap.inheritedStyle,
property: flexWrap.styleConfig.property,
});
@@ -168,7 +167,6 @@ export const LayoutSection = ({
<SelectControl
category={display.category}
currentStyle={display.currentStyle}
- inheritedStyle={display.inheritedStyle}
setProperty={display.setProperty}
deleteProperty={display.deleteProperty}
// show only important values first and hide others with scroll
diff --git a/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx b/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx
index 5a5d893840..8c7fa92a80 100644
--- a/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/spacing/scrub.tsx
@@ -13,12 +13,11 @@ type ScrubStatus =
| { isActive: false }
| { isActive: true; property: SpacingStyleProperty; value: UnitValue };
-export const useScrub = (
- props: {
- target: HoverTagret | undefined;
- onChange: StyleChangeHandler;
- } & Pick<RenderCategoryProps, "currentStyle" | "inheritedStyle">
-): ScrubStatus => {
+export const useScrub = (props: {
+ currentStyle: RenderCategoryProps["currentStyle"];
+ target: HoverTagret | undefined;
+ onChange: StyleChangeHandler;
+}): ScrubStatus => {
// we want to hold on to the target while scrub is active even if hover changes
const [activeTarget, setActiveTarget] = useState<HoverTagret>();
const finalTarget = activeTarget ?? props.target;
@@ -44,11 +43,10 @@ export const useScrub = (
? "horizontal"
: "vertical",
getValue() {
- const { currentStyle, inheritedStyle } = latestProps.current;
+ const { currentStyle } = latestProps.current;
const value = getFinalValue({
property: property,
currentStyle,
- inheritedStyle,
});
if (value?.type === "unit") {
unitRef.current = value.unit;
diff --git a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
index 02fa859920..ba593e488b 100644
--- a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
@@ -22,7 +22,6 @@ const Cell = ({
isActive,
scrubStatus,
currentStyle,
- inheritedStyle,
}: {
isPopoverOpen: boolean;
onPopoverClose: () => void;
@@ -31,13 +30,13 @@ const Cell = ({
property: SpacingStyleProperty;
isActive: boolean;
scrubStatus: ReturnType<typeof useScrub>;
-} & Pick<RenderCategoryProps, "currentStyle" | "inheritedStyle">) => {
+ currentStyle: RenderCategoryProps["currentStyle"];
+}) => {
const isFromCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
const styleValue = getFinalValue({
property,
currentStyle,
- inheritedStyle,
});
const finalValue = scrubStatus.isActive ? scrubStatus.value : styleValue;
@@ -85,7 +84,6 @@ export const SpacingSection = ({
setProperty,
deleteProperty,
currentStyle,
- inheritedStyle,
}: RenderCategoryProps) => {
const [hoverTarget, setHoverTarget] = useState<HoverTagret>();
@@ -101,7 +99,6 @@ export const SpacingSection = ({
target: hoverTarget,
onChange: handleChange,
currentStyle,
- inheritedStyle,
});
const [openProperty, setOpenProperty] = useState<SpacingStyleProperty>();
@@ -133,7 +130,6 @@ export const SpacingSection = ({
}
isActive={activeProperty === property}
currentStyle={currentStyle}
- inheritedStyle={inheritedStyle}
/>
)}
/>
diff --git a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts b/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
index 9c88303f23..875cb2a97c 100644
--- a/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/get-final-value.ts
@@ -1,6 +1,5 @@
import type { Style, StyleValue, StyleProperty } from "@webstudio-is/css-data";
import { toValue } from "@webstudio-is/css-engine";
-import type { InheritedStyle } from "./get-inherited-style";
import { isValid } from "./parse-css-value";
export const isNumericString = (input: string) =>
@@ -9,19 +8,12 @@ export const isNumericString = (input: string) =>
// @todo expose which instance we inherited the value from
export const getFinalValue = ({
currentStyle,
- inheritedStyle,
property,
}: {
currentStyle: Style;
- inheritedStyle: InheritedStyle;
property: StyleProperty;
}): StyleValue | undefined => {
const currentValue = currentStyle[property];
- const inheritedValue =
- property in inheritedStyle ? inheritedStyle[property].value : undefined;
- if (toValue(currentValue) === "inherit" && inheritedValue !== undefined) {
- return inheritedValue;
- }
if (currentValue?.type !== "unit" && isNumericString(toValue(currentValue))) {
return {
value: Number(toValue(currentValue)),
diff --git a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts b/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts
deleted file mode 100644
index 5d6e18dd09..0000000000
--- a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import { properties } from "@webstudio-is/css-data";
-import type { StyleValue, StyleProperty } from "@webstudio-is/css-data";
-import { toValue } from "@webstudio-is/css-engine";
-import type { Instance } from "@webstudio-is/react-sdk";
-
-export type InheritedStyle = {
- [property in StyleProperty]: {
- instance: Instance;
- value: StyleValue;
- };
-};
-
-type InheritableProperties = { [property in StyleProperty]: true };
-// Object keys should give `keyof typeof ...` but now it gives string[]
-const propertyNames = Object.keys(properties) as (keyof typeof properties)[];
-// All inheritable properties we support
-const inheritableProperties: InheritableProperties = propertyNames.reduce(
- (acc: InheritableProperties, property) => {
- const config = properties[property];
- if (config.inherited) {
- acc[property as StyleProperty] = true;
- }
- return acc;
- },
- {} as InheritableProperties
-);
-
-const findParents = (
- instance: Instance,
- instanceId: Instance["id"]
-): Array<Instance> => {
- const parents: Array<Instance> = [];
-
- for (const child of instance.children) {
- if (child.type === "text") {
- continue;
- }
- // I am your father
- if (child.id === instanceId) {
- parents.push(instance);
- break;
- }
- const foundParents = findParents(child, instanceId);
- // eslint-disable-next-line prefer-spread
- parents.push.apply(parents, foundParents);
- }
- return parents;
-};
-
-// - Walk down the tree and remember all parent instances until the found instance
-// - Walk back up and find a value for each inheritable property and where value is not "inherit"
-// @todo this also has to match the media query, otheriwse its wrong
-export const getInheritedStyle = (
- rootInstance: Instance,
- instanceId: Instance["id"]
-): InheritedStyle => {
- const parents = findParents(rootInstance, instanceId).reverse();
- const inheritedStyle = {} as InheritedStyle;
- for (const parent of parents) {
- for (const cssRule of parent.cssRules) {
- for (const property in cssRule.style) {
- const isInheritable = property in inheritableProperties;
- const value = cssRule.style[property as StyleProperty];
- const hasValue = value !== undefined && toValue(value) !== "inherit";
- const isFirst = property in inheritedStyle === false;
- if (isInheritable && hasValue && isFirst) {
- inheritedStyle[property as StyleProperty] = {
- instance: parent,
- value,
- };
- }
- }
- }
- }
- return inheritedStyle;
-};
diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
index 74b39503bd..fa76d2922f 100644
--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
@@ -4,9 +4,7 @@ import type { SelectedInstanceData, StyleUpdates } from "@webstudio-is/project";
import type { Style, StyleProperty, StyleValue } from "@webstudio-is/css-data";
import { type Publish } from "~/shared/pubsub";
import { useSelectedBreakpoint } from "~/designer/shared/nano-states";
-import { getInheritedStyle } from "./get-inherited-style";
import { getCssRuleForBreakpoint } from "./get-css-rule-for-breakpoint";
-import { useRootInstance } from "~/shared/nano-states";
// @todo: must be removed, now it's only for compatibility with existing code
import { parseCssValue } from "./parse-css-value";
@@ -46,7 +44,6 @@ export const useStyleData = ({
selectedInstanceData,
publish,
}: UseStyleData) => {
- const [rootInstance] = useRootInstance();
const [selectedBreakpoint] = useSelectedBreakpoint();
const cssRule = useMemo(
() =>
@@ -73,13 +70,6 @@ export const useStyleData = ({
setBreakpointStyle({ ...cssRule?.style });
}, [cssRule?.style]);
- const inheritedStyle = useMemo(() => {
- if (selectedInstanceData === undefined || rootInstance === undefined) {
- return;
- }
- return getInheritedStyle(rootInstance, selectedInstanceData.id);
- }, [selectedInstanceData, rootInstance]);
-
const publishUpdates = useCallback(
(type: "update" | "preview", updates: StyleUpdates["updates"]) => {
if (
@@ -220,7 +210,6 @@ export const useStyleData = ({
return {
currentStyle,
- inheritedStyle,
setProperty,
deleteProperty,
createBatchUpdate,
diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsx
index 885444d839..d97d8c9ad8 100644
--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx
@@ -19,16 +19,11 @@ export const StylePanel = ({
selectedInstanceData,
publish,
}: StylePanelProps) => {
- const {
- currentStyle,
- inheritedStyle,
- setProperty,
- deleteProperty,
- createBatchUpdate,
- } = useStyleData({
- selectedInstanceData,
- publish,
- });
+ const { currentStyle, setProperty, deleteProperty, createBatchUpdate } =
+ useStyleData({
+ selectedInstanceData,
+ publish,
+ });
const [breakpoint] = useSelectedBreakpoint();
const [canvasWidth] = useCanvasWidth();
@@ -36,7 +31,6 @@ export const StylePanel = ({
if (
currentStyle === undefined ||
- inheritedStyle === undefined ||
selectedInstanceData === undefined ||
breakpoint === undefined
) {
@@ -81,7 +75,6 @@ export const StylePanel = ({
search={search}
selectedInstanceData={selectedInstanceData}
currentStyle={currentStyle}
- inheritedStyle={inheritedStyle}
setProperty={setProperty}
deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
diff --git a/apps/designer/app/designer/features/style-panel/style-sections.tsx b/apps/designer/app/designer/features/style-panel/style-sections.tsx
index a9625c4e3c..e6b10c4a1a 100644
--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx
@@ -8,7 +8,6 @@ import type {
DeleteProperty,
CreateBatchUpdate,
} from "./shared/use-style-data";
-import type { InheritedStyle } from "./shared/get-inherited-style";
import * as controls from "./controls";
import {
LayoutSection,
@@ -29,7 +28,6 @@ export type ControlProps = {
setProperty: SetProperty;
deleteProperty: DeleteProperty;
currentStyle: Style;
- inheritedStyle: InheritedStyle;
styleConfig: StyleConfig;
category: Category;
};
@@ -42,7 +40,6 @@ export type RenderCategoryProps = {
sectionStyle: {
[Property in Required<keyof Style>]: RenderPropertyProps;
};
- inheritedStyle: InheritedStyle;
category: Category;
styleConfigsByCategory: Array<RenderPropertyProps>;
moreStyleConfigsByCategory: Array<RenderPropertyProps>;
@@ -52,14 +49,12 @@ export type RenderPropertyProps = {
setProperty: SetProperty;
deleteProperty: DeleteProperty;
currentStyle: Style;
- inheritedStyle: InheritedStyle;
styleConfig: StyleConfig;
category: Category;
};
export const renderProperty = ({
currentStyle,
- inheritedStyle,
setProperty,
deleteProperty,
styleConfig,
@@ -80,7 +75,6 @@ export const renderProperty = ({
/>
<Control
currentStyle={currentStyle}
- inheritedStyle={inheritedStyle}
setProperty={setProperty}
deleteProperty={deleteProperty}
styleConfig={styleConfig}
@@ -96,7 +90,6 @@ export const renderCategory = ({
createBatchUpdate,
currentStyle,
sectionStyle,
- inheritedStyle,
category,
styleConfigsByCategory,
moreStyleConfigsByCategory,
@@ -109,7 +102,6 @@ export const renderCategory = ({
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
sectionStyle={sectionStyle}
- inheritedStyle={inheritedStyle}
category={category}
styleConfigsByCategory={styleConfigsByCategory}
moreStyleConfigsByCategory={moreStyleConfigsByCategory}
diff --git a/apps/designer/app/designer/features/style-panel/style-settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsx
index fa7b8cabb8..c4d3c7a382 100644
--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx
@@ -11,7 +11,6 @@ import {
shouldRenderCategory,
} from "./style-sections";
import { dependencies } from "./shared/dependencies";
-import { type InheritedStyle } from "./shared/get-inherited-style";
import {
type SetProperty,
type CreateBatchUpdate,
@@ -87,7 +86,6 @@ const didRender = (category: Category, { property }: StyleConfig): boolean => {
export type StyleSettingsProps = {
currentStyle: Style;
- inheritedStyle: InheritedStyle;
cssRule?: CssRule;
setProperty: SetProperty;
deleteProperty: (property: StyleProperty) => void;