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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Several advanced section fixes (#3211)
Oleg Isonencac97829a590
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.tsxindex 9db4bef928..fd5185f935 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@@ -20,7 +20,7 @@ import { Add } from "./add";import { CollapsibleSection } from "../../shared/collapsible-section";import { sectionsProperties } from "../sections";import { toKebabCase } from "../../shared/keyword-utils";-import type { DeleteProperty, SetProperty } from "../../shared/use-style-data";+import type { DeleteProperty } from "../../shared/use-style-data";const allPropertyNames = Object.keys(propertiesData).sort(Intl.Collator().compare@@ -58,7 +58,7 @@ const usePropertyNames = (currentStyle: StyleInfo) => {}return [- ...recent.current,+ ...Array.from(recent.current).reverse(),...Array.from(names).filter((name) => recent.current.has(name) === false).reverse(),@@ -70,7 +70,11 @@ const usePropertyNames = (currentStyle: StyleInfo) => {// Only here to keep the same section module interfaceexport const properties = [];-export const Section = ({ currentStyle, ...props }: SectionProps) => {+export const Section = ({+ currentStyle,+ setProperty,+ ...props+}: SectionProps) => {const [addingProp, setAddingProp] = useState<StyleProperty | "">();const { propertyNames, recentProperties } = usePropertyNames(currentStyle);const deleteProperty: DeleteProperty = (property, options) => {@@ -79,13 +83,7 @@ export const Section = ({ currentStyle, ...props }: SectionProps) => {}return props.deleteProperty(property, options);};- const setProperty: SetProperty = (property) => {- setAddingProp(undefined);- if (propertyNames.includes(property) === false) {- recentProperties.add(property);- }- return props.setProperty(property);- };+return (<CollapsibleSectionlabel="Advanced"@@ -103,10 +101,14 @@ export const Section = ({ currentStyle, ...props }: SectionProps) => {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);+ }}}}/>@@ -124,14 +126,23 @@ export const Section = ({ currentStyle, ...props }: SectionProps) => {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="1"+ text="mono"fieldSizing="content"- autoFocus={addingProp !== undefined && index === 0}property={property}styleSource={getStyleSource(currentStyle[property])}keywords={keywords}diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsxindex 39a697fa93..8d835a3df7 100644--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx@@ -47,6 +47,7 @@ import {$selectedInstanceUnitSizes,} from "~/shared/nano-states";import { convertUnits } from "./convert-units";+import { mergeRefs } from "@react-aria/utils";// We need to enable scrub on properties that can have numeric value.const canBeNumber = (property: StyleProperty) => {@@ -280,7 +281,14 @@ export type ChangeReason =type CssValueInputProps = Pick<ComponentProps<typeof InputField>,- "variant" | "size" | "autoFocus" | "disabled" | "fieldSizing" | "prefix"+ | "variant"+ | "size"+ | "text"+ | "autoFocus"+ | "disabled"+ | "fieldSizing"+ | "prefix"+ | "inputRef"> & {styleSource: StyleSource;property: StyleProperty;@@ -361,6 +369,7 @@ export const CssValueInput = ({fieldSizing,variant,size,+ text,...props}: CssValueInputProps) => {const value = props.intermediateValue ?? props.value ?? initialValue;@@ -668,12 +677,13 @@ export const CssValueInput = ({onBlur={handleOnBlur}onKeyDown={handleKeyDown}containerRef={disabled ? undefined : scrubRef}- inputRef={inputRef}+ inputRef={mergeRefs(inputRef, props.inputRef ?? null)}name={property}color={value.type === "invalid" ? "error" : undefined}prefix={finalPrefix}suffix={suffix}css={{ cursor: "default", minWidth: "2em" }}+ text={text}/></ComboboxAnchor>{isOpen && (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.tsxindex e91d26aefa..2e0fe1f75e 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,4 +1,9 @@-import { useState, type ReactElement, type ReactNode } from "react";+import {+ useState,+ type ReactElement,+ type ReactNode,+ type ComponentProps,+} from "react";import { useStore } from "@nanostores/react";import type { StyleProperty } from "@webstudio-is/css-engine";import { propertyDescriptions } from "@webstudio-is/css-data";@@ -359,7 +364,10 @@ export const PropertyTooltip = ({);};-type PropertyNameInternalProps = {+type PropertyNameProps = Pick<+ ComponentProps<typeof Label>,+ "text" | "color"+> & {style: StyleInfo;properties: StyleProperty[];label: string | ReactElement;@@ -369,15 +377,17 @@ type PropertyNameInternalProps = {disabled?: boolean;};-const PropertyNameInternal = ({+export const PropertyName = ({style,title,description,properties,label,+ text,+ color,onReset,disabled,-}: PropertyNameInternalProps) => {+}: PropertyNameProps) => {const property = properties[0];// When there are multiple properties. We need to make a consolidated choice.@@ -390,6 +400,13 @@ const PropertyNameInternal = ({getStyleSource(style[property]));+ const styleSource =+ onReset === undefined+ ? "default"+ : styleSourcesList.length === 0+ ? "default"+ : getPriorityStyleSource(styleSourcesList);+return (<Flex align="center"><PropertyTooltip@@ -403,15 +420,10 @@ const PropertyNameInternal = ({<Flex shrink gap={1} align="center">{typeof label === "string" && property ? (<Label- color={- onReset === undefined- ? "default"- : styleSourcesList.length === 0- ? "default"- : getPriorityStyleSource(styleSourcesList)- }+ color={color && styleSource === "default" ? color : styleSource}truncatedisabled={disabled}+ text={text}>{label}</Label>@@ -424,33 +436,6 @@ const PropertyNameInternal = ({);};-type PropertyNameProps = {- style: StyleInfo;- properties: StyleProperty[];- label: string | ReactElement;- title?: string;- description?: ReactNode;- onReset: () => void;-};--export const PropertyName = ({- style,- title,- description,- properties,- label,- onReset,-}: PropertyNameProps) => (- <PropertyNameInternal- style={style}- title={title}- description={description}- properties={properties}- label={label}- onReset={onReset}- />-);-type NonResetablePropertyNameProps = {style: StyleInfo;properties: StyleProperty[];@@ -473,7 +458,7 @@ export const NonResetablePropertyName = ({label,disabled,}: NonResetablePropertyNameProps) => (- <PropertyNameInternal+ <PropertyNamestyle={style}title={title}description={description}diff --git a/packages/design-system/src/components/css-value-list-item.stories.tsx b/packages/design-system/src/components/css-value-list-item.stories.tsxindex 3a09014bdc..4f28991dd3 100644--- a/packages/design-system/src/components/css-value-list-item.stories.tsx+++ b/packages/design-system/src/components/css-value-list-item.stories.tsx@@ -1,3 +1,4 @@+import { useState, type ComponentProps, type ReactNode } from "react";import { css, styled, theme } from "../stitches.config";import {CssValueListArrowFocus,@@ -10,7 +11,6 @@ import {EyeconClosedIcon,SubtractIcon,} from "@webstudio-is/icons";-import * as React from "react";import { SmallIconButton } from "./small-icon-button";import {FloatingPanelPopover,@@ -49,14 +49,14 @@ const Panel = styled("div", {const ListItem = (props: {hidden: boolean;- labelColor: "default" | "preset" | "local" | "overwritten" | "remote";+ labelColor: ComponentProps<typeof Label>["color"];state: undefined | "open";active: boolean;focused: undefined | boolean;- label?: React.ReactNode;+ label?: ReactNode;index: number;}) => {- const [pressed, onPressedChange] = React.useState(false);+ const [pressed, onPressedChange] = useState(false);return (<CssValueListItem@@ -100,7 +100,7 @@ export const Declarative = (props: {focused: boolean;labelColor: "default";}) => {- const [pressed, onPressedChange] = React.useState(false);+ const [pressed, onPressedChange] = useState(false);return (<Panel>diff --git a/packages/design-system/src/components/label.tsx b/packages/design-system/src/components/label.tsxindex 366a95fb18..5b0c608442 100644--- a/packages/design-system/src/components/label.tsx+++ b/packages/design-system/src/components/label.tsx@@ -15,6 +15,7 @@ export const labelColors = ["local","overwritten","remote",+ "code",] as const;const StyledLabel = styled(RadixLabel, {@@ -89,6 +90,12 @@ const StyledLabel = styled(RadixLabel, {backgroundColor: theme.colors.backgroundRemoteHover,},},+ code: {+ color: theme.colors.foregroundLocalMain,+ "&:hover": {+ backgroundColor: theme.colors.backgroundHover,+ },+ },},truncate: {true: {@@ -102,6 +109,7 @@ const StyledLabel = styled(RadixLabel, {text: {title: textVariants.titles,sentence: textVariants.labelsSentenceCase,+ mono: textVariants.mono,},},@@ -112,7 +120,7 @@ const StyledLabel = styled(RadixLabel, {type Props = {color?: (typeof labelColors)[number];- text?: "title" | "sentence";+ text?: "title" | "sentence" | "mono";disabled?: boolean;truncate?: boolean;children: ReactNode;diff --git a/packages/design-system/src/components/nested-icon-label.tsx b/packages/design-system/src/components/nested-icon-label.tsxindex c18892efb7..3058392f7f 100644--- a/packages/design-system/src/components/nested-icon-label.tsx+++ b/packages/design-system/src/components/nested-icon-label.tsx@@ -38,6 +38,12 @@ const colors = {backgroundHover: theme.colors.backgroundRemoteHover,icon: theme.colors.foregroundRemoteMain,},+ code: {+ border: "transparent",+ background: "transparent",+ backgroundHover: theme.colors.backgroundHover,+ icon: theme.colors.foregroundIconMain,+ },} as const;const perColorStyle = (color: (typeof labelColors)[number]) => ({@@ -70,6 +76,7 @@ const style = css({local: perColorStyle("local"),overwritten: perColorStyle("overwritten"),remote: perColorStyle("remote"),+ code: perColorStyle("code"),},},defaultVariants: { color: "default" },