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.

experimental: migrate advanced section to new style engine (#4114)

Bogdan Chadkin323ac058c9ee
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/add.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/add.tsx
deleted file mode 100644
index 5ef47e8777..0000000000
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/add.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import { useState } from "react";
-import { theme, Combobox, Box } from "@webstudio-is/design-system";
-import { propertyDescriptions } from "@webstudio-is/css-data";
-import type { StyleProperty } from "@webstudio-is/css-engine";
-import { matchSorter } from "match-sorter";
-import { isFeatureEnabled } from "@webstudio-is/feature-flags";
-import { toKebabCase } from "../../shared/keyword-utils";
-
-type Item = { value: string; label: string };
-
-const matchOrSuggestToCreate = (
- search: string,
- items: Array<Item>,
- itemToString: (item: Item) => string
-): Array<Item> => {
- const matched = matchSorter(items, search, {
- keys: [itemToString],
- });
-
- if (isFeatureEnabled("cssVars") === false) {
- return matched;
- }
-
- if (search.trim().startsWith("--")) {
- matched.unshift({
- value: search.trim(),
- label: `Create "${search.trim()}"`,
- });
- }
- return matched;
-};
-
-export const Add = ({
- onSelect,
- propertyNames,
-}: {
- onSelect: (value: string) => void;
- propertyNames: Array<StyleProperty>;
-}) => {
- const [item, setItem] = useState<Item>({ value: "", label: "" });
-
- return (
- <Combobox<Item>
- autoFocus
- placeholder="Find or create a property"
- items={propertyNames.map((value) => ({
- value,
- label: toKebabCase(value),
- }))}
- itemToString={(item) => item?.label ?? ""}
- getItemProps={() => ({ text: "sentence" })}
- onItemSelect={(item) => onSelect(item.value)}
- value={item}
- onChange={(value) => {
- setItem({ value: value ?? "", label: value ?? "" });
- }}
- match={matchOrSuggestToCreate}
- getDescription={(item) => {
- let description = `Unknown CSS property.`;
- if (item && item.value in propertyDescriptions) {
- description =
- propertyDescriptions[
- item.value as keyof typeof propertyDescriptions
- ];
- }
- return <Box css={{ width: theme.spacing[28] }}>{description}</Box>;
- }}
- defaultHighlightedIndex={0}
- />
- );
-};
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx
index 78d12d97c5..a726e041fb 100644
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx
@@ -1,44 +1,40 @@
+import { getStyleDeclKey, type StyleDecl } from "@webstudio-is/sdk";
+import { registerContainers } from "~/shared/sync";
import { Section } from "./advanced";
+import {
+ $breakpoints,
+ $selectedBreakpointId,
+ $selectedInstanceSelector,
+ $styles,
+ $styleSourceSelections,
+} from "~/shared/nano-states";
+import { setProperty } from "../../shared/use-style-data";
-const currentStyle = {
- accentColor: {
- value: {
- type: "keyword",
- value: "red",
- },
- local: {
- type: "keyword",
- value: "red",
- },
+const backgroundImage: StyleDecl = {
+ breakpointId: "base",
+ styleSourceId: "local",
+ property: "backgroundImage",
+ value: {
+ type: "layers",
+ value: [{ type: "keyword", value: "none" }],
},
- alignContent: {
- value: {
- type: "keyword",
- value: "normal",
- },
- local: {
- type: "keyword",
- value: "normal",
- },
- },
- opacity: {
- value: {
- type: "unit",
- unit: "number",
- value: 11.2,
- },
- local: {
- type: "unit",
- unit: "number",
- value: 11.2,
- },
- },
-} as const;
+};
+
+registerContainers();
+$breakpoints.set(new Map([["base", { id: "base", label: "" }]]));
+$selectedBreakpointId.set("base");
+$styles.set(new Map([[getStyleDeclKey(backgroundImage), backgroundImage]]));
+$styleSourceSelections.set(
+ new Map([["box", { instanceId: "box", values: ["local"] }]])
+);
+$selectedInstanceSelector.set(["box"]);
+
+setProperty("accentColor")({ type: "keyword", value: "red" });
+setProperty("alignContent")({ type: "keyword", value: "normal" });
+setProperty("opacity")({ type: "unit", unit: "number", value: 11.2 });
export const Advanced = () => {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- const props = {} as any;
- return <Section currentStyle={currentStyle} {...props} />;
+ return <Section />;
};
export default {
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
index 3f05991d8a..5f310183b3 100644
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
@@ -1,96 +1,44 @@
-import { useMemo, useRef, useState, type ReactNode } from "react";
+import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
+import { computed } from "nanostores";
+import { matchSorter } from "match-sorter";
+import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import { PlusIcon } from "@webstudio-is/icons";
import {
Box,
+ Combobox,
Flex,
+ Label,
SectionTitle,
SectionTitleButton,
SectionTitleLabel,
Text,
+ theme,
+ Tooltip,
} from "@webstudio-is/design-system";
-import { properties as propertiesData } from "@webstudio-is/css-data";
-import { useStore } from "@nanostores/react";
-import type { StyleProperty } from "@webstudio-is/css-engine";
import {
- $selectedInstanceSelector,
- useInstanceStyles,
-} from "~/shared/nano-states";
-import type { SectionProps } from "../shared/section";
-import { CssValueInputContainer } from "../../shared/css-value-input";
-import { styleConfigByName } from "../../shared/configs";
-import { PropertyName } from "../../shared/property-name";
+ properties as propertiesData,
+ propertyDescriptions,
+} from "@webstudio-is/css-data";
+import { useStore } from "@nanostores/react";
import {
- getStyleSource,
- hasInstanceValue,
- type StyleInfo,
-} from "../../shared/style-info";
-import { Add } from "./add";
-import { sections } from "../sections";
-import { toKebabCase } from "../../shared/keyword-utils";
-import type { DeleteProperty } from "../../shared/use-style-data";
+ hyphenateProperty,
+ type StyleProperty,
+} from "@webstudio-is/css-engine";
import {
CollapsibleSectionRoot,
useOpenState,
} from "~/builder/shared/collapsible-section";
-import { useComputedStyles } from "../../shared/model";
+import { CssValueInputContainer } from "../../shared/css-value-input";
+import { styleConfigByName } from "../../shared/configs";
+import { deleteProperty, setProperty } from "../../shared/use-style-data";
+import {
+ $definedStyles,
+ useComputedStyleDecl,
+ useComputedStyles,
+} from "../../shared/model";
import { getDots } from "../../shared/style-section";
-
-const allPropertyNames = Object.keys(propertiesData).sort(
- Intl.Collator().compare
-) as Array<StyleProperty>;
-
-const initialPropertyNames = new Set<StyleProperty>([
- "userSelect",
- "pointerEvents",
- "mixBlendMode",
- "cursor",
- "opacity",
-]);
-
-const usePropertyNames = (currentStyle: StyleInfo) => {
- const selectedInstanceSelector = useStore($selectedInstanceSelector);
- // @todo switch to style object model to show also inherited styles
- const styles = useInstanceStyles(selectedInstanceSelector?.[0]);
- // Ordererd recent properties for sorting.
- const recent = useRef<Set<StyleProperty>>(new Set());
-
- const baseProperties = useMemo(() => {
- // All properties used by the panels except the advanced panel
- const base = new Set<StyleProperty>([]);
- for (const { properties } of sections.values()) {
- for (const property of properties) {
- base.add(property);
- }
- }
- return base;
- }, []);
-
- const propertyNames = useMemo(() => {
- const names = new Set(initialPropertyNames);
- let property: StyleProperty;
- for (property in currentStyle) {
- if (
- hasInstanceValue(currentStyle, property) &&
- baseProperties.has(property) === false
- ) {
- names.add(property);
- }
- }
- for (const style of styles) {
- if (style.listed) {
- names.add(style.property);
- }
- }
-
- return [
- ...Array.from(recent.current).reverse(),
- ...Array.from(names)
- .filter((name) => recent.current.has(name) === false)
- .reverse(),
- ];
- }, [styles, currentStyle, baseProperties]);
- return { propertyNames, recentProperties: recent.current };
-};
+import { PropertyInfo } from "../../property-label";
+import { sections } from "../sections";
// Only here to keep the same section module interface
export const properties = [];
@@ -131,91 +79,231 @@ const AdvancedStyleSection = (props: {
);
};
-export const Section = ({
- currentStyle,
- setProperty,
- ...props
-}: SectionProps) => {
- const [addingProp, setAddingProp] = useState<StyleProperty | "">();
- const { propertyNames, recentProperties } = usePropertyNames(currentStyle);
- const deleteProperty: DeleteProperty = (property, options) => {
- if (options?.isEphemeral !== true) {
- recentProperties.delete(property);
+type SearchItem = { value: string; label: string };
+
+const matchOrSuggestToCreate = (
+ search: string,
+ items: Array<SearchItem>,
+ itemToString: (item: SearchItem) => string
+) => {
+ const matched = matchSorter(items, search, {
+ keys: [itemToString],
+ });
+ if (isFeatureEnabled("cssVars") === false) {
+ return matched;
+ }
+ if (search.trim().startsWith("--")) {
+ matched.unshift({
+ value: search.trim(),
+ label: `Create "${search.trim()}"`,
+ });
+ }
+ return matched;
+};
+
+const AdvancedSearch = ({
+ usedProperties,
+ onSelect,
+}: {
+ usedProperties: string[];
+ onSelect: (value: StyleProperty) => void;
+}) => {
+ const availableProperties = useMemo(() => {
+ const properties = Object.keys(propertiesData).sort(
+ Intl.Collator().compare
+ ) as StyleProperty[];
+ const availableProperties: SearchItem[] = [];
+ for (const property of properties) {
+ if (usedProperties.includes(property) === false) {
+ availableProperties.push({
+ value: property,
+ label: hyphenateProperty(property),
+ });
+ }
+ }
+ return availableProperties;
+ }, [usedProperties]);
+ const [item, setItem] = useState<SearchItem>({
+ value: "",
+ label: "",
+ });
+
+ return (
+ <Combobox
+ autoFocus
+ placeholder="Find or create a property"
+ items={availableProperties}
+ defaultHighlightedIndex={0}
+ value={item}
+ itemToString={(item) => item?.label ?? ""}
+ getItemProps={() => ({ text: "sentence" })}
+ getDescription={(item) => {
+ let description = `Unknown CSS property.`;
+ if (item && item.value in propertyDescriptions) {
+ description =
+ propertyDescriptions[
+ item.value as keyof typeof propertyDescriptions
+ ];
+ }
+ return <Box css={{ width: theme.spacing[28] }}>{description}</Box>;
+ }}
+ match={matchOrSuggestToCreate}
+ onChange={(value) => {
+ setItem({ value: value ?? "", label: value ?? "" });
+ }}
+ onItemSelect={(item) => onSelect(item.value as StyleProperty)}
+ />
+ );
+};
+
+const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
+ const styleDecl = useComputedStyleDecl(property);
+ const label = hyphenateProperty(property);
+ const description =
+ propertyDescriptions[property as keyof typeof propertyDescriptions];
+ const color =
+ styleDecl.source.name === "default" ? "code" : styleDecl.source.name;
+ const [isOpen, setIsOpen] = useState(false);
+ return (
+ <Flex align="center">
+ <Tooltip
+ open={isOpen}
+ onOpenChange={setIsOpen}
+ // prevent closing tooltip on content click
+ onPointerDown={(event) => event.preventDefault()}
+ triggerProps={{
+ onClick: (event) => {
+ if (event.altKey) {
+ event.preventDefault();
+ deleteProperty(property);
+ return;
+ }
+ setIsOpen(true);
+ },
+ }}
+ content={
+ <PropertyInfo
+ title={label}
+ description={description}
+ styles={[styleDecl]}
+ onReset={() => {
+ deleteProperty(property);
+ setIsOpen(false);
+ }}
+ />
+ }
+ >
+ <Flex shrink gap={1} align="center">
+ <Label color={color} text="mono" truncate>
+ {label}
+ </Label>
+ </Flex>
+ </Tooltip>
+ </Flex>
+ );
+};
+
+const AdvancedPropertyValue = ({
+ autoFocus,
+ property,
+}: {
+ autoFocus?: boolean;
+ property: StyleProperty;
+}) => {
+ const styleDecl = useComputedStyleDecl(property);
+ const { items } = styleConfigByName(property);
+ const inputRef = useRef<HTMLInputElement>(null);
+ useEffect(() => {
+ if (autoFocus) {
+ inputRef.current?.focus();
}
- return props.deleteProperty(property, options);
- };
+ }, [autoFocus]);
+ return (
+ <CssValueInputContainer
+ inputRef={inputRef}
+ variant="chromeless"
+ size="2"
+ text="mono"
+ fieldSizing="content"
+ property={property}
+ styleSource={styleDecl.source.name}
+ keywords={items.map((item) => ({
+ type: "keyword",
+ value: item.name,
+ }))}
+ value={styleDecl.cascadedValue}
+ setValue={(styleValue, options) =>
+ setProperty(property)(styleValue, {
+ ...options,
+ listed: true,
+ })
+ }
+ deleteProperty={deleteProperty}
+ />
+ );
+};
+
+const initialProperties = new Set<StyleProperty>([
+ "userSelect",
+ "pointerEvents",
+ "mixBlendMode",
+ "cursor",
+ "opacity",
+]);
+
+const $advancedProperties = computed($definedStyles, (definedStyles) => {
+ // All properties used by the panels except the advanced panel
+ const baseProperties = new Set<StyleProperty>([]);
+ for (const { properties } of sections.values()) {
+ for (const property of properties) {
+ baseProperties.add(property);
+ }
+ }
+ const advancedProperties = new Set<StyleProperty>(initialProperties);
+ for (const { property, listed } of definedStyles) {
+ // exclude properties from style panel UI unless edited in advanced section
+ if (baseProperties.has(property) === false || listed) {
+ advancedProperties.add(property);
+ }
+ }
+ return Array.from(advancedProperties).reverse();
+});
+
+export const Section = () => {
+ const [isAdding, setIsAdding] = useState(false);
+ const advancedProperties = useStore($advancedProperties);
+ const newlyAddedProperty = useRef<undefined | StyleProperty>(undefined);
return (
<AdvancedStyleSection
label="Advanced"
- properties={propertyNames}
- onAdd={() => setAddingProp("")}
+ properties={advancedProperties}
+ onAdd={() => setIsAdding(true)}
>
- {addingProp !== undefined && (
- <Add
- propertyNames={allPropertyNames.filter(
- (property) => propertyNames.includes(property) === false
- )}
- onSelect={(value) => {
- if (value in propertiesData || value.startsWith("--")) {
- const property = value as StyleProperty;
- setAddingProp(property);
- setProperty(property)(
- { type: "guaranteedInvalid" },
- { listed: true }
- );
- if (propertyNames.includes(property) === false) {
- recentProperties.add(property);
- }
- }
+ {isAdding && (
+ <AdvancedSearch
+ usedProperties={advancedProperties}
+ onSelect={(property) => {
+ newlyAddedProperty.current = property;
+ setIsAdding(false);
+ setProperty(property)(
+ { type: "guaranteedInvalid" },
+ { listed: true }
+ );
}}
/>
)}
<Box>
- {propertyNames.map((property) => {
- const { items } = styleConfigByName(property);
- const keywords = items.map((item) => ({
- type: "keyword" as const,
- value: item.name,
- }));
- return (
- <Flex wrap="wrap" align="center" key={property}>
- <PropertyName
- label={toKebabCase(styleConfigByName(property).property)}
- properties={[property]}
- style={currentStyle}
- text="mono"
- color="code"
- onReset={() => deleteProperty(property)}
- />
- <Text>:</Text>
- <CssValueInputContainer
- inputRef={(input) => {
- // We need to focus the added property value and reset the addingProp state.
- if (input && addingProp === property) {
- input.focus();
- setAddingProp(undefined);
- }
- }}
- variant="chromeless"
- size="2"
- text="mono"
- fieldSizing="content"
- property={property}
- styleSource={getStyleSource(currentStyle[property])}
- keywords={keywords}
- value={currentStyle[property]?.value}
- setValue={(styleValue, options) =>
- setProperty(property)(styleValue, {
- ...options,
- listed: true,
- })
- }
- deleteProperty={deleteProperty}
- />
- </Flex>
- );
- })}
+ {advancedProperties.map((property) => (
+ <Flex key={property} wrap="wrap" align="center">
+ <AdvancedPropertyLabel property={property} />
+ <Text>:</Text>
+ <AdvancedPropertyValue
+ autoFocus={newlyAddedProperty.current === property}
+ property={property}
+ />
+ </Flex>
+ ))}
</Box>
</AdvancedStyleSection>
);
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
index aded273f2d..da59e2c149 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
@@ -28,7 +28,7 @@ import {
type UnparsedValue,
} from "@webstudio-is/css-engine";
import { setUnion } from "~/shared/shim";
-import { $definedProperties } from "../../shared/model";
+import { $definedStyles } from "../../shared/model";
type AnimatableProperties = (typeof animatableProperties)[number];
type NameAndLabel = { name: string; label?: string };
@@ -44,10 +44,10 @@ const commonPropertiesSet = new Set(commonTransitionProperties);
* on current breakpoints across all states
*/
const $animatableDefinedProperties = computed(
- [$definedProperties],
- (definedProperties) => {
+ [$definedStyles],
+ (definedStyles) => {
const animatableProperties = new Set<string>();
- for (const property of definedProperties) {
+ for (const { property } of definedStyles) {
const hyphenatedProperty = hyphenateProperty(property);
if (isAnimatableProperty(hyphenatedProperty)) {
animatableProperties.add(hyphenatedProperty);
diff --git a/apps/builder/app/builder/features/style-panel/shared/model.tsx b/apps/builder/app/builder/features/style-panel/shared/model.tsx
index f798d02d69..3119485057 100644
--- a/apps/builder/app/builder/features/style-panel/shared/model.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/model.tsx
@@ -1,5 +1,5 @@
-import { useMemo } from "react";
-import { computed } from "nanostores";
+import { useMemo, useRef } from "react";
+import { computed, type ReadableAtom } from "nanostores";
import { useStore } from "@nanostores/react";
import { properties } from "@webstudio-is/css-data";
import {
@@ -7,7 +7,7 @@ import {
type StyleProperty,
type StyleValue,
} from "@webstudio-is/css-engine";
-import type { Breakpoint, Instance } from "@webstudio-is/sdk";
+import type { Breakpoint, Instance, StyleDecl } from "@webstudio-is/sdk";
import {
$breakpoints,
$instances,
@@ -23,6 +23,7 @@ import {
import {
getComputedStyleDecl,
getPresetStyleDeclKey,
+ type ComputedStyleDecl,
type StyleObjectModel,
} from "~/shared/style-object-model";
@@ -80,7 +81,7 @@ const $matchingBreakpoints = computed(
}
);
-export const $definedProperties = computed(
+export const $definedStyles = computed(
[
$selectedInstanceSelector,
$styleSourceSelections,
@@ -93,7 +94,7 @@ export const $definedProperties = computed(
matchingBreakpointsArray,
styles
) => {
- const definedProperties = new Set<StyleProperty>();
+ const definedProperties = new Set<StyleDecl>();
if (instanceSelector === undefined) {
return definedProperties;
}
@@ -117,14 +118,14 @@ export const $definedProperties = computed(
matchingBreakpoints.has(styleDecl.breakpointId) &&
instanceStyleSources.has(styleDecl.styleSourceId)
) {
- definedProperties.add(styleDecl.property);
+ definedProperties.add(styleDecl);
}
if (
matchingBreakpoints.has(styleDecl.breakpointId) &&
inheritedStyleSources.has(styleDecl.styleSourceId) &&
properties[styleDecl.property as keyof typeof properties].inherited
) {
- definedProperties.add(styleDecl.property);
+ definedProperties.add(styleDecl);
}
}
return definedProperties;
@@ -190,12 +191,23 @@ export const useComputedStyleDecl = (property: StyleProperty) => {
};
export const useComputedStyles = (properties: StyleProperty[]) => {
+ // cache each computed style store
+ const cachedStores = useRef(
+ new Map<StyleProperty, ReadableAtom<ComputedStyleDecl>>()
+ );
+ const stores: ReadableAtom<ComputedStyleDecl>[] = [];
+ for (const property of properties) {
+ let store = cachedStores.current.get(property);
+ if (store === undefined) {
+ store = createComputedStyleDeclStore(property);
+ cachedStores.current.set(property, store);
+ }
+ stores.push(store);
+ }
+ // combine all styles into single list
const $styles = useMemo(() => {
- return computed(
- properties.map(createComputedStyleDeclStore),
- (...computedStyles) => computedStyles
- );
+ return computed(stores, (...computedStyles) => computedStyles);
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, properties);
+ }, [properties.join()]);
return useStore($styles);
};
diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
index 86ef15439b..f099062e46 100644
--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
@@ -1,9 +1,4 @@
-import {
- useState,
- type ReactElement,
- type ReactNode,
- type ComponentProps,
-} from "react";
+import { useState, type ReactElement, type ReactNode } from "react";
import { useStore } from "@nanostores/react";
import type { StyleProperty } from "@webstudio-is/css-engine";
import { propertyDescriptions } from "@webstudio-is/css-data";
@@ -11,7 +6,6 @@ import {
theme,
Button,
Flex,
- Label,
Tooltip,
type TooltipProps,
Text,
@@ -39,7 +33,6 @@ import {
type StyleInfo,
getStyleSource,
type StyleValueInfo,
- getStyleSourceColor,
} from "./style-info";
import { humanizeString } from "~/shared/string-utils";
import { getInstanceLabel } from "~/shared/instance-utils";
@@ -363,67 +356,3 @@ export const PropertyTooltip = ({
</Tooltip>
);
};
-
-type PropertyNameProps = Pick<
- ComponentProps<typeof Label>,
- "text" | "color"
-> & {
- style: StyleInfo;
- properties: Array<StyleProperty>;
- label: string | ReactElement;
- title?: string;
- description?: ReactNode;
- onReset?: () => void;
- disabled?: boolean;
-};
-
-export const PropertyName = ({
- style,
- title,
- description,
- properties,
- label,
- text,
- color,
- onReset,
- disabled,
-}: PropertyNameProps) => {
- const property = properties[0];
- const styleSourceColor = onReset
- ? getStyleSourceColor({
- properties,
- currentStyle: style,
- })
- : "default";
- return (
- <Flex align="center">
- <PropertyTooltip
- openWithClick={true}
- title={title ?? (typeof label === "string" ? label : undefined)}
- description={description}
- properties={properties}
- style={style}
- onReset={onReset}
- >
- <Flex shrink gap={1} align="center">
- {typeof label === "string" && property ? (
- <Label
- color={
- color && styleSourceColor === "default"
- ? color
- : styleSourceColor
- }
- truncate
- disabled={disabled}
- text={text}
- >
- {label}
- </Label>
- ) : (
- label
- )}
- </Flex>
- </PropertyTooltip>
- </Flex>
- );
-};
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
index 2c2296ffa0..11b0eaca62 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
@@ -42,7 +42,7 @@ jest.unstable_mockModule("~/shared/canvas-api", () => ({
},
}));
-const { getPriorityStyleSource, setInstanceToTag } = __testing__;
+const { setInstanceToTag } = __testing__;
const toMap = <T extends { id: string }>(list: T[]) =>
new Map(list.map((item) => [item.id, item]));
@@ -961,19 +961,4 @@ describe("active states", () => {
value: "green",
});
});
-
- test("get the style source from ['local', 'default', 'preset']", () => {
- const result = getPriorityStyleSource(["local", "default", "preset"]);
- expect(result).toBe("local");
- });
-
- test("get the style source from ['local', 'overwritten', 'preset']", () => {
- const result = getPriorityStyleSource(["local", "overwritten", "preset"]);
- expect(result).toBe("overwritten");
- });
-
- test("get the style source from ['default', 'default', 'preset']", () => {
- const result = getPriorityStyleSource(["default", "default", "preset"]);
- expect(result).toBe("preset");
- });
});
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
index 904d5803c0..fe895af6f9 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
@@ -867,67 +867,7 @@ export const useStyleInfoByInstanceId = (
);
};
-const getPriorityStyleSource = (styleSources: StyleSource[]): StyleSource => {
- const customOrder: StyleSource[] = [
- "overwritten",
- "local",
- "remote",
- "preset",
- "default",
- ];
-
- for (const style of customOrder) {
- if (styleSources.includes(style)) {
- return style;
- }
- }
-
- return "default";
-};
-
-export const getStyleSourceColor = ({
- properties,
- currentStyle,
-}: {
- properties: Array<StyleProperty>;
- currentStyle: StyleInfo;
-}) => {
- // When there are multiple properties. We need to make a consolidated choice.
- // As we can't show multiple badges in the property name.
- // Eg: flex-grow, flex-shrink, flex-basis
- // All three managed by single section. If flex-basis is set, but if we pick only flex-grow from the three.
- // The section does't show the badge. So, we need to pick the one which is being used.
-
- const styleSourcesList = properties.map((property) =>
- getStyleSource(currentStyle[property])
- );
-
- return styleSourcesList.length === 0
- ? "default"
- : getPriorityStyleSource(styleSourcesList);
-};
-
-/**
- * Has any value defined on that particular instance,
- * excluding preset and inherited values.
- */
-export const hasInstanceValue = (
- currentStyle: StyleInfo,
- property: StyleProperty
-) => {
- const info = currentStyle[property];
- return Boolean(
- info?.cascaded ??
- info?.local ??
- info?.stateful ??
- info?.stateless ??
- info?.nextSource?.value ??
- info?.previousSource?.value
- );
-};
-
export const __testing__ = {
- getPriorityStyleSource,
instanceToTag: undefined as Map<Instance["id"], HtmlTags> | undefined,
setInstanceToTag: (instanceToTag: Map<Instance["id"], HtmlTags>) => {
__testing__.instanceToTag = instanceToTag;
diff --git a/apps/builder/app/shared/nano-states/misc.ts b/apps/builder/app/shared/nano-states/misc.ts
index 3a7f240a6f..772f028c5a 100644
--- a/apps/builder/app/shared/nano-states/misc.ts
+++ b/apps/builder/app/shared/nano-states/misc.ts
@@ -1,6 +1,4 @@
-import { useMemo } from "react";
import { atom, computed, onSet } from "nanostores";
-import { useStore } from "@nanostores/react";
import { nanoid } from "nanoid";
import type { AuthPermit } from "@webstudio-is/trpc-interface/index.server";
import type { ItemDropTarget, Placement } from "@webstudio-is/design-system";
@@ -23,7 +21,6 @@ import type { MarketplaceProduct } from "@webstudio-is/project-build";
import type { TokenPermissions } from "@webstudio-is/authorization-token";
import { createImageLoader, type ImageLoader } from "@webstudio-is/image";
import type { DragStartPayload } from "~/canvas/shared/use-drag-drop";
-import { shallowComputed } from "../store-utils";
import { type InstanceSelector } from "../tree-utils";
import type { HtmlTags } from "html-tags";
import { $instances, $selectedInstanceSelector } from "./instances";
@@ -81,22 +78,6 @@ export const $propsIndex = computed($props, (props) => {
export const $styles = atom<Styles>(new Map());
-/**
- * @deprecated
- */
-export const useInstanceStyles = (instanceId: undefined | Instance["id"]) => {
- const instance$styles = useMemo(() => {
- return shallowComputed([$stylesIndex], (stylesIndex) => {
- if (instanceId === undefined) {
- return [];
- }
- return stylesIndex.stylesByInstanceId.get(instanceId) ?? [];
- });
- }, [instanceId]);
- const instanceStyles = useStore(instance$styles);
- return instanceStyles;
-};
-
export const $styleSources = atom<StyleSources>(new Map());
export const $styleSourceSelections = atom<StyleSourceSelections>(new Map());