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
[progress] Naive aspectRatio (#556)
Ivan Starkovbb6a1d28e3ca
diff --git a/apps/designer/app/designer/features/props-panel/control.tsx b/apps/designer/app/designer/features/props-panel/control.tsxindex 4bd0497bb1..94aea842cf 100644--- a/apps/designer/app/designer/features/props-panel/control.tsx+++ b/apps/designer/app/designer/features/props-panel/control.tsx@@ -18,6 +18,8 @@ import { ImageManager } from "~/designer/shared/image-manager";import { Checkbox } from "@webstudio-is/design-system";import { Asset } from "@webstudio-is/asset-uploader";import type { UserPropValue } from "./use-props-logic";+import { type SetProperty } from "../style-panel/shared/use-style-data";+import type { Style } from "@webstudio-is/css-data";const textControlTypes = ["text",@@ -174,6 +176,8 @@ type ControlProps = {component: Instance["component"];userProp: UserProp;onChangePropValue: (value: UserPropValue) => void;+ setCssProperty: SetProperty;+ currentStyle: Style;};// eslint-disable-next-line func-style@@ -181,6 +185,7 @@ export function Control({component,userProp,onChangePropValue,+ setCssProperty,}: ControlProps) {const meta = getComponentMetaProps(component);@@ -215,7 +220,22 @@ export function Control({return (<ImageControlasset={asset}- onChange={(value) => onChangePropValue({ type: "asset", value })}+ onChange={(value) => {+ onChangePropValue({ type: "asset", value });++ const { meta } = value;+ if ("width" in meta && "height" in meta) {+ // @todo: change on own type, pass width/hight separately+ const aspectRatio = meta.width / meta.height;++ // @todo: own type, simlify width/height, until that use unit as before+ setCssProperty("aspectRatio")({+ type: "unit",+ value: aspectRatio,+ unit: "number",+ });+ }+ }}/>);}diff --git a/apps/designer/app/designer/features/props-panel/props-panel.tsx b/apps/designer/app/designer/features/props-panel/props-panel.tsxindex 036b6d66a3..78c7917f0a 100644--- a/apps/designer/app/designer/features/props-panel/props-panel.tsx+++ b/apps/designer/app/designer/features/props-panel/props-panel.tsx@@ -29,6 +29,11 @@ import {ChevronDownIcon,} from "@webstudio-is/icons";import { usePropsLogic, type UserPropValue } from "./use-props-logic";+import {+ useStyleData,+ type SetProperty,+} from "../style-panel/shared/use-style-data";+import type { Style } from "@webstudio-is/css-data";type ComboboxProps = {isReadonly: boolean;@@ -111,6 +116,8 @@ type PropertyProps = {onChangePropName: (name: string) => void;onChangePropValue: (value: UserPropValue) => void;onDelete: (id: UserProp["id"]) => void;+ setCssProperty: SetProperty;+ currentStyle: Style;};const Property = ({@@ -119,6 +126,8 @@ const Property = ({onChangePropName,onChangePropValue,onDelete,+ setCssProperty,+ currentStyle,}: PropertyProps) => {const meta = getComponentMetaProps(component);@@ -156,6 +165,8 @@ const Property = ({component={component}userProp={userProp}onChangePropValue={onChangePropValue}+ setCssProperty={setCssProperty}+ currentStyle={currentStyle}/>)}{userProp.required !== true && (@@ -189,6 +200,11 @@ export const PropsPanel = ({handleDeleteProp,} = usePropsLogic({ selectedInstanceData, publish });+ const { setProperty: setCssProperty, currentStyle } = useStyleData({+ selectedInstanceData,+ publish,+ });+const addButton = (<Buttonghost@@ -229,6 +245,8 @@ export const PropsPanel = ({onChangePropValue={(value) =>handleChangePropValue(userProp.id, value)}+ setCssProperty={setCssProperty}+ currentStyle={currentStyle}onDelete={handleDeleteProp}/>))}diff --git a/packages/react-sdk/src/app/custom-components/image.tsx b/packages/react-sdk/src/app/custom-components/image.tsxindex 6d00288462..cb51385345 100644--- a/packages/react-sdk/src/app/custom-components/image.tsx+++ b/packages/react-sdk/src/app/custom-components/image.tsx@@ -35,10 +35,27 @@ export const Image = forwardRef<ElementRef<typeof defaultTag>, Props>(}if (asset == null || loader == null) {- return <SdkImage {...props} src={src} ref={ref} />;+ return <SdkImage key={src} {...props} src={src} ref={ref} />;}- return <WebstudioImage {...props} loader={loader} src={src} ref={ref} />;+ return (+ <WebstudioImage+ /**+ * `key` is needed to recreate the image in case of asset change in designer,+ * this gives immediate feedback when an asset is changed.+ * Also, it visually fixes image distortion when another asset has a seriously different aspectRatio+ * (we change aspectRatio CSS prop on asset change)+ *+ * In non-designer mode, key on images are usually also a good idea,+ * prevents showing outdated images on route change.+ **/+ key={src}+ {...props}+ loader={loader}+ src={src}+ ref={ref}+ />+ );});