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
WIP WIP WIP
Sultan043c0f882b49
diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex 253dcfac76..fd058154cb 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -23,7 +23,7 @@ import {} from "./shared/nano-states";import { Topbar } from "./features/topbar";import designerStyles from "./designer.css";-import { Breadcrumbs } from "./features/breadcrumbs";+import { Breadcrumbs } from "./features/footer";import { TreePrevew } from "./features/tree-preview";import {useUpdateCanvasWidth,diff --git a/apps/designer/app/designer/features/breadcrumbs/breadcrumbs.tsx b/apps/designer/app/designer/features/footer/breadcrumbs.tsxsimilarity index 100%rename from apps/designer/app/designer/features/breadcrumbs/breadcrumbs.tsxrename to apps/designer/app/designer/features/footer/breadcrumbs.tsxdiff --git a/apps/designer/app/designer/features/breadcrumbs/index.ts b/apps/designer/app/designer/features/footer/index.tssimilarity index 100%rename from apps/designer/app/designer/features/breadcrumbs/index.tsrename to apps/designer/app/designer/features/footer/index.tsdiff --git a/apps/designer/app/designer/features/inspector/inspector.tsx b/apps/designer/app/designer/features/inspector/inspector.tsxindex 02973722b9..31eb3971d3 100644--- a/apps/designer/app/designer/features/inspector/inspector.tsx+++ b/apps/designer/app/designer/features/inspector/inspector.tsx@@ -9,8 +9,8 @@ import {Paragraph,Box,} from "~/shared/design-system";-import { StylePanel } from "~/designer/features/style-panel";-import { PropsPanel } from "~/designer/features/props-panel";+import { StylePanel } from "~/designer/features/sidebar-right/style-panel";+import { PropsPanel } from "~/designer/features/sidebar-right/props-panel";import { useSelectedInstanceData } from "~/designer/shared/nano-states";type InspectorProps = {diff --git a/apps/designer/app/shared/style-panel-configs/configs.ts b/apps/designer/app/designer/features/style-panel/lib/configs.tssimilarity index 70%rename from apps/designer/app/shared/style-panel-configs/configs.tsrename to apps/designer/app/designer/features/style-panel/lib/configs.tsindex e38341f0c7..330561a68a 100644--- a/apps/designer/app/shared/style-panel-configs/configs.ts+++ b/apps/designer/app/designer/features/style-panel/lib/configs.ts@@ -4,9 +4,24 @@ import {keywordValues,type Category,type StyleProperty,+ type AppliesTo,} from "@webstudio-is/react-sdk";-import type { StyleConfig, Control } from "./types";-import { humanizeString } from "../string-utils";+import { humanizeString } from "../../../../shared/string-utils";++type BaseStyleConfig = {+ label: string;+ property: StyleProperty;+ appliesTo: AppliesTo;+};++export type Control = "Spacing" | "Combobox" | "Color" | "Comboicon" | "Select";++type StyleConfigWithItems = BaseStyleConfig & {+ control: Control;+ items: Array<{ label: string; name: string }>;+};++export type StyleConfig = StyleConfigWithItems;type Property = keyof typeof keywordValues;@@ -23,6 +38,20 @@ const getControl = (property: StyleProperty): Control => {return "Spacing";}+ switch (property) {+ case "display": {+ return "Select";+ }+ case "flexDirection":+ case "flexWrap":+ case "alignItems":+ case "justifyItems":+ case "justifyContent":+ case "alignContent": {+ return "Comboicon";+ }+ }+return "Combobox";};diff --git a/apps/designer/app/designer/features/style-panel/dependencies.ts b/apps/designer/app/designer/features/style-panel/lib/dependencies.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/dependencies.tsrename to apps/designer/app/designer/features/style-panel/lib/dependencies.tsdiff --git a/apps/designer/app/designer/features/style-panel/lib/utils/get-css-rule-for-breakpoint.ts b/apps/designer/app/designer/features/style-panel/lib/get-css-rule-for-breakpoint.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/lib/utils/get-css-rule-for-breakpoint.tsrename to apps/designer/app/designer/features/style-panel/lib/get-css-rule-for-breakpoint.tsdiff --git a/apps/designer/app/designer/features/style-panel/get-inherited-style.ts b/apps/designer/app/designer/features/style-panel/lib/get-inherited-style.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/get-inherited-style.tsrename to apps/designer/app/designer/features/style-panel/lib/get-inherited-style.tsdiff --git a/apps/designer/app/designer/features/style-panel/parse-css-value.test.ts b/apps/designer/app/designer/features/style-panel/lib/parse-css-value.test.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/parse-css-value.test.tsrename to apps/designer/app/designer/features/style-panel/lib/parse-css-value.test.tsdiff --git a/apps/designer/app/designer/features/style-panel/parse-css-value.ts b/apps/designer/app/designer/features/style-panel/lib/parse-css-value.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/parse-css-value.tsrename to apps/designer/app/designer/features/style-panel/lib/parse-css-value.tsdiff --git a/apps/designer/app/designer/features/style-panel/lib/spacing-widget.tsx b/apps/designer/app/designer/features/style-panel/lib/spacing-widget.tsxindex 0b95652f29..0b0442a8a4 100644--- a/apps/designer/app/designer/features/style-panel/lib/spacing-widget.tsx+++ b/apps/designer/app/designer/features/style-panel/lib/spacing-widget.tsx@@ -5,8 +5,8 @@ import {type StyleValue,} from "@webstudio-is/react-sdk";import { Box } from "~/shared/design-system";-import { SetProperty } from "../use-style-data";-import { useIsFromCurrentBreakpoint } from "./utils/use-is-from-current-breakpoint";+import { SetProperty } from "./use-style-data";+import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";import { propertyNameColorForSelectedBreakpoint } from "./constants";type SpacingSingularStyle = { [property in SpacingProperty]?: StyleValue };diff --git a/apps/designer/app/designer/features/style-panel/lib/utils/use-is-from-current-breakpoint.ts b/apps/designer/app/designer/features/style-panel/lib/use-is-from-current-breakpoint.tssimilarity index 100%rename from apps/designer/app/designer/features/style-panel/lib/utils/use-is-from-current-breakpoint.tsrename to apps/designer/app/designer/features/style-panel/lib/use-is-from-current-breakpoint.tsdiff --git a/apps/designer/app/designer/features/style-panel/use-style-data.ts b/apps/designer/app/designer/features/style-panel/lib/use-style-data.tssimilarity index 95%rename from apps/designer/app/designer/features/style-panel/use-style-data.tsrename to apps/designer/app/designer/features/style-panel/lib/use-style-data.tsindex 552b10bcbe..5e0a4afa18 100644--- a/apps/designer/app/designer/features/style-panel/use-style-data.ts+++ b/apps/designer/app/designer/features/style-panel/lib/use-style-data.ts@@ -4,10 +4,10 @@ import type {StyleUpdates,} from "~/shared/canvas-components";import { type StyleProperty, type Publish } from "@webstudio-is/react-sdk";-import { useSelectedBreakpoint } from "../../shared/nano-states";+import { useSelectedBreakpoint } from "../../../shared/nano-states";import { parseCssValue } from "./parse-css-value";import { getInheritedStyle } from "./get-inherited-style";-import { getCssRuleForBreakpoint } from "./lib/utils/get-css-rule-for-breakpoint";+import { getCssRuleForBreakpoint } from "./get-css-rule-for-breakpoint";import { useRootInstance } from "~/shared/nano-states";type UseStyleData = {diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsxindex 2795024f0b..c4d5d6c66a 100644--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx@@ -2,8 +2,8 @@ import type { Publish } from "@webstudio-is/react-sdk";import { willRender } from "~/designer/shared/breakpoints";import { Box, Card, Paragraph } from "~/shared/design-system";import type { SelectedInstanceData } from "~/shared/canvas-components";-import { useStyleData } from "./use-style-data";-import { VisualSettings } from "./settings";+import { useStyleData } from "./lib/use-style-data";+import { StyleSettings } from "./style-settings";import { Search } from "./search";import { useState } from "react";import {@@ -61,10 +61,10 @@ export const StylePanel = ({</Box>}<Box css={{ overflow: "auto" }}>- <Box css={{ p: "$3" }}>+ <Box css={{ p: "$3", paddingTop: "$2" }}><Search onSearch={setSearch} /></Box>- <VisualSettings+ <StyleSettingssearch={search}selectedInstanceData={selectedInstanceData}currentStyle={currentStyle}diff --git a/apps/designer/app/designer/features/style-panel/render-property.tsx b/apps/designer/app/designer/features/style-panel/style-section.tsxsimilarity index 57%rename from apps/designer/app/designer/features/style-panel/render-property.tsxrename to apps/designer/app/designer/features/style-panel/style-section.tsxindex 8688b15bee..bc4d4bcc52 100644--- a/apps/designer/app/designer/features/style-panel/render-property.tsx+++ b/apps/designer/app/designer/features/style-panel/style-section.tsx@@ -1,5 +1,24 @@-import { Flex, Grid, Label, Text, Combobox } from "~/shared/design-system";-import type { StyleConfig } from "~/shared/style-panel-configs";+import { useState } from "react";+import {+ Box,+ Flex,+ Grid,+ Label,+ Text,+ Button,+ Collapsible,+ Combobox,+ Comboicon,+ Select,+ TextField,+ IconButton,+} from "~/shared/design-system";+import {+ TriangleRightIcon,+ TriangleDownIcon,+ LockClosedIcon,+} from "~/shared/icons";+import type { StyleConfig } from "./lib/configs";import {categories,type Style,@@ -7,15 +26,15 @@ import {type Category,type StyleValue,} from "@webstudio-is/react-sdk";-import type { SetProperty } from "./use-style-data";-import type { InheritedStyle } from "./get-inherited-style";+import type { SetProperty } from "./lib/use-style-data";+import type { InheritedStyle } from "./lib/get-inherited-style";import { ColorPicker } from "./lib/color-picker";import {SpacingWidget,type SpacingProperty,type SpacingStyles,} from "./lib/spacing-widget";-import { useIsFromCurrentBreakpoint } from "./lib/utils/use-is-from-current-breakpoint";+import { useIsFromCurrentBreakpoint } from "./lib/use-is-from-current-breakpoint";import { propertyNameColorForSelectedBreakpoint } from "./lib/constants";const getFinalValue = ({@@ -174,6 +193,7 @@ const ComboboxControl = ({return (<Grid columns={2} align="center" gapX="1">+ {/* @todo needs icon variant */}<PropertyName property={styleConfig.property} label={styleConfig.label} /><Flex align="center" css={{ gridColumn: "2/4" }} gap="1"><Combobox@@ -203,12 +223,88 @@ const ComboboxControl = ({);};-const controls: {- [key: string]: (props: ControlProps) => JSX.Element | null;-} = {- Color: ColorControl,- Spacing: SpacingControl,- Combobox: ComboboxControl,+const SelectControl = ({+ currentStyle,+ inheritedStyle,+ setProperty,+ styleConfig,+}: ControlProps) => {+ // @todo show which instance we inherited the value from+ const value = getFinalValue({+ currentStyle,+ inheritedStyle,+ property: styleConfig.property,+ });++ if (value === undefined) return null;++ const setValue = setProperty(styleConfig.property);++ return (+ <>+ <PropertyName property={styleConfig.property} label={styleConfig.label} />+ <Select+ options={styleConfig.items.map(({ label }) => label)}+ value={String(value.value)}+ onChange={setValue}+ />+ </>+ );+};++const ComboiconControl = ({+ currentStyle,+ inheritedStyle,+ setProperty,+ styleConfig,+}: ControlProps) => {+ // @todo show which instance we inherited the value from+ const value = getFinalValue({+ currentStyle,+ inheritedStyle,+ property: styleConfig.property,+ });++ if (value === undefined) return null;++ const setValue = setProperty(styleConfig.property);++ return (+ <Comboicon+ id={styleConfig.property}+ items={styleConfig.items}+ value={String(value.value)}+ onChange={(value: any) => {+ console.log(value, styleConfig.property);+ setValue(value);+ }}+ />+ );+};++const GridControl = ({ currentStyle }: any) => {+ return <></>;+};++const ShowMore = ({ styleConfigs }: { styleConfigs: Array<JSX.Element> }) => {+ const [isOpen, setIsOpen] = useState(false);+ if (styleConfigs.length === 0) return null;+ return (+ <Collapsible.Root asChild onOpenChange={setIsOpen}>+ <Flex direction="column" gap="3">+ <Collapsible.Trigger asChild>+ <Button css={{ width: "100%", gap: "$1" }}>+ {isOpen ? <TriangleDownIcon /> : <TriangleRightIcon />}Show more+ </Button>+ </Collapsible.Trigger>+ <Collapsible.Content asChild>+ <Flex direction="column" gap="3">+ {styleConfigs}+ </Flex>+ </Collapsible.Content>+ </Flex>+ </Collapsible.Root>+ );};type RenderPropertyProps = {@@ -227,14 +323,97 @@ export const renderProperty = ({category,}: RenderPropertyProps) => {const Control = controls[styleConfig.control];+ const { property } = styleConfig;+ const key = category + "-" + property;+ return (+ <Box+ key={key}+ data-category={category}+ data-property={property}+ css={{ gridArea: property }}+ >+ <Control+ currentStyle={currentStyle}+ inheritedStyle={inheritedStyle}+ setProperty={setProperty}+ styleConfig={styleConfig}+ />+ </Box>+ );+};++// Categories should render themselves because most Categories will not be dump un-ordered lists with+// the new designs, refactor ColorControl, SpacingControl if needed.+export const renderCategory = ({+ category,+ styleConfigsByCategory,+ moreStyleConfigsByCategory,+}: {+ category: Category;+ styleConfigsByCategory: JSX.Element[];+ moreStyleConfigsByCategory: JSX.Element[];+}) => {+ switch (category) {+ case "layout": {+ styleConfigsByCategory = [+ <Box+ key="grid"+ css={{+ gridArea: "grid",+ border: "1px solid black",+ background: "#CCC",+ }}+ >+ ...+ <br />+ ...+ <br />+ ...+ </Box>,+ <Box key="lock" css={{ gridArea: "lock" }}>+ <IconButton>+ <LockClosedIcon />+ </IconButton>+ ,+ </Box>,+ ...styleConfigsByCategory,+ ];+ return (+ <>+ <Grid+ css={{+ gridTemplateColumns: "repeat(12, 1fr);",+ gridTemplateRows: "auto auto auto auto",+ gridTemplateAreas: `+ "display display display display display display display display display display display display"+ "grid grid grid grid grid grid flexDirection flexDirection flexWrap flexWrap . ."+ "grid grid grid grid grid grid alignItems alignItems justifyContent justifyContent justifyItems justifyItems"+ "rowGap rowGap rowGap rowGap rowGap lock lock columnGap columnGap columnGap columnGap columnGap"+ `,+ }}+ >+ {styleConfigsByCategory}+ </Grid>+ <ShowMore styleConfigs={moreStyleConfigsByCategory} />+ </>+ );+ }+ }return (- <Control- key={category + "-" + styleConfig.property}- currentStyle={currentStyle}- inheritedStyle={inheritedStyle}- setProperty={setProperty}- styleConfig={styleConfig}- />+ <>+ {styleConfigsByCategory}+ <ShowMore styleConfigs={moreStyleConfigsByCategory} />+ </>);};++const controls: {+ [key: string]: (props: ControlProps) => JSX.Element | null;+} = {+ Color: ColorControl,+ Spacing: SpacingControl,+ Combobox: ComboboxControl,+ Comboicon: ComboiconControl,+ Select: SelectControl,+};diff --git a/apps/designer/app/designer/features/style-panel/settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsxsimilarity index 75%rename from apps/designer/app/designer/features/style-panel/settings.tsxrename to apps/designer/app/designer/features/style-panel/style-settings.tsxindex 52170ecf1d..18c2e8b9eb 100644--- a/apps/designer/app/designer/features/style-panel/settings.tsx+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx@@ -1,4 +1,3 @@-import { useState } from "react";import hyphenate from "hyphenate-style-name";import {categories,@@ -6,14 +5,13 @@ import {type Category,type Style,} from "@webstudio-is/react-sdk";-import { Flex, Collapsible, Button } from "~/shared/design-system";-import { TriangleRightIcon, TriangleDownIcon } from "~/shared/icons";-import { styleConfigs, type StyleConfig } from "~/shared/style-panel-configs";++import { type StyleConfig, styleConfigs } from "./lib/configs";import { CollapsibleSection } from "~/designer/shared/inspector";-import { renderProperty } from "./render-property";-import { dependencies } from "./dependencies";-import { type InheritedStyle } from "./get-inherited-style";-import { type SetProperty } from "./use-style-data";+import { renderProperty, renderCategory } from "./style-section";+import { dependencies } from "./lib/dependencies";+import { type InheritedStyle } from "./lib/get-inherited-style";+import { type SetProperty } from "./lib/use-style-data";import { type SelectedInstanceData } from "~/shared/canvas-components";// Finds a property/value by using any available form: property, label, value@@ -66,28 +64,7 @@ const didRender = (category: Category, { property }: StyleConfig): boolean => {return false;};-const ShowMore = ({ styleConfigs }: { styleConfigs: Array<JSX.Element> }) => {- const [isOpen, setIsOpen] = useState(false);- if (styleConfigs.length === 0) return null;- return (- <Collapsible.Root asChild onOpenChange={setIsOpen}>- <Flex direction="column" gap="3">- <Collapsible.Trigger asChild>- <Button css={{ width: "100%", gap: "$1" }}>- {isOpen ? <TriangleDownIcon /> : <TriangleRightIcon />}Show more- </Button>- </Collapsible.Trigger>- <Collapsible.Content asChild>- <Flex direction="column" gap="3">- {styleConfigs}- </Flex>- </Collapsible.Content>- </Flex>- </Collapsible.Root>- );-};--type VisualSettingsProps = {+type StyleSettingsProps = {currentStyle: Style;inheritedStyle: InheritedStyle;cssRule?: CssRule;@@ -96,11 +73,11 @@ type VisualSettingsProps = {search: string;};-export const VisualSettings = ({+export const StyleSettings = ({currentStyle,search,...rest-}: VisualSettingsProps) => {+}: StyleSettingsProps) => {const isSearchMode = search.length !== 0;const all = [];let category: Category;@@ -154,8 +131,11 @@ export const VisualSettings = ({key={category}><>- {styleConfigsByCategory}- <ShowMore styleConfigs={moreStyleConfigsByCategory} />+ {renderCategory({+ category,+ styleConfigsByCategory,+ moreStyleConfigsByCategory,+ })}</></CollapsibleSection>);diff --git a/apps/designer/app/shared/design-system/components/comboicon.tsx b/apps/designer/app/shared/design-system/components/comboicon.tsxnew file mode 100644index 0000000000..30ac10777b--- /dev/null+++ b/apps/designer/app/shared/design-system/components/comboicon.tsx@@ -0,0 +1,89 @@+import React from "react";+import { styled } from "@stitches/react";+import { HamburgerMenuIcon, CheckIcon } from "@radix-ui/react-icons";+import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";++const StyledContent = styled(DropdownMenuPrimitive.Content, {+ minWidth: 220,+ backgroundColor: "white",+ borderRadius: 6,+ padding: 5,+ boxShadow:+ "0px 10px 38px -10px rgba(22, 23, 24, 0.35), 0px 10px 20px -15px rgba(22, 23, 24, 0.2)",+});++const itemStyles = {+ all: "unset",+ fontSize: 13,+ lineHeight: 1,+ color: "$colors$gray12",+ borderRadius: 3,+ display: "flex",+ alignItems: "center",+ height: 25,+ padding: "0 5px",+ position: "relative",+ paddingLeft: 25,+ userSelect: "none",+};++const StyledRadioItem = styled(DropdownMenuPrimitive.RadioItem, {+ ...itemStyles,+});+const StyledItemIndicator = styled(DropdownMenuPrimitive.ItemIndicator, {+ position: "absolute",+ left: 0,+ width: 25,+ display: "inline-flex",+ alignItems: "center",+ justifyContent: "center",+});++const StyledArrow = styled(DropdownMenuPrimitive.Arrow, {+ fill: "white",+});++const IconButton = styled("button", {+ all: "unset",+ fontFamily: "inherit",+ borderRadius: "2px",+ height: "32px",+ width: "32px",+ display: "inline-flex",+ alignItems: "center",+ justifyContent: "center",+ color: "$colors$gray12",+ backgroundColor: "white",+ "&:hover": { backgroundColor: "$colors$gray6" },+});++export const Comboicon = ({ id, value, items, onChange }: any) => {+ return (+ <DropdownMenuPrimitive.Root>+ <DropdownMenuPrimitive.Trigger asChild>+ <IconButton aria-label={id}>+ <HamburgerMenuIcon />+ </IconButton>+ </DropdownMenuPrimitive.Trigger>++ <StyledContent>+ <DropdownMenuPrimitive.RadioGroup+ value={value}+ onValueChange={onChange}+ >+ {items.map(({ name, label }: any) => {+ return (+ <StyledRadioItem key={name} value={label}>+ <StyledItemIndicator>+ <CheckIcon />+ </StyledItemIndicator>+ {label}+ </StyledRadioItem>+ );+ })}+ </DropdownMenuPrimitive.RadioGroup>+ <StyledArrow offset={12} />+ </StyledContent>+ </DropdownMenuPrimitive.Root>+ );+};diff --git a/apps/designer/app/shared/design-system/index.ts b/apps/designer/app/shared/design-system/index.tsindex 8e58533e09..338ad3cd40 100644--- a/apps/designer/app/shared/design-system/index.ts+++ b/apps/designer/app/shared/design-system/index.ts@@ -55,3 +55,4 @@ export * from "./components/slider";export * from "./components/control-group";export * from "./components/radio";export * from "./components/combobox";+export * from "./components/comboicon";diff --git a/apps/designer/app/shared/style-panel-configs/index.ts b/apps/designer/app/shared/style-panel-configs/index.tsdeleted file mode 100644index 4f3b69c215..0000000000--- a/apps/designer/app/shared/style-panel-configs/index.ts+++ /dev/null@@ -1,2 +0,0 @@-export * from "./configs";-export * from "./types";diff --git a/apps/designer/app/shared/style-panel-configs/types.ts b/apps/designer/app/shared/style-panel-configs/types.tsdeleted file mode 100644index 4501ba413a..0000000000--- a/apps/designer/app/shared/style-panel-configs/types.ts+++ /dev/null@@ -1,16 +0,0 @@-import type { StyleProperty, AppliesTo } from "@webstudio-is/react-sdk";--type BaseStyleConfig = {- label: string;- property: StyleProperty;- appliesTo: AppliesTo;-};--export type Control = "Spacing" | "Combobox" | "Color";--type StyleConfigWithItems = BaseStyleConfig & {- control: Control;- items: Array<{ label: string; name: string }>;-};--export type StyleConfig = StyleConfigWithItems;