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
design updates
Roman Pominov7d7e295bac45
diff --git a/apps/designer/app/canvas/features/wrapper-component/use-ensure-focus.ts b/apps/designer/app/canvas/features/wrapper-component/use-ensure-focus.tsindex f1ee74ddca..11a2f6566e 100644--- a/apps/designer/app/canvas/features/wrapper-component/use-ensure-focus.ts+++ b/apps/designer/app/canvas/features/wrapper-component/use-ensure-focus.ts@@ -14,7 +14,8 @@ export const useEnsureFocus = () => {getInstanceIdFromElement(element) === selectedInstance?.id &&document.activeElement !== element) {- element.focus();+ // @todo: uncomment+ // element.focus();}},[selectedInstance]diff --git a/apps/designer/app/canvas/shared/use-track-selected-element.ts b/apps/designer/app/canvas/shared/use-track-selected-element.tsindex 592830f82a..186370ab02 100644--- a/apps/designer/app/canvas/shared/use-track-selected-element.ts+++ b/apps/designer/app/canvas/shared/use-track-selected-element.ts@@ -50,7 +50,8 @@ export const useTrackSelectedElement = () => {) {const element = getInstanceElementById(selectedInstance.id);if (element === null) return;- element.focus();+ // @todo: uncomment+ // element.focus();setSelectedElement(element);}}, [selectedInstance, selectedElement, setSelectedElement]);diff --git a/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsx b/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsxindex 1f2d5b40b1..ccf56587d1 100644--- a/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsx+++ b/apps/designer/app/designer/features/sidebar-left/lib/navigator/navigator.tsx@@ -1,4 +1,4 @@-import { Box, Flex } from "@webstudio-is/design-system";+import { Flex } from "@webstudio-is/design-system";import type { Instance, Publish } from "@webstudio-is/react-sdk";import { useSelectedInstanceData } from "~/designer/shared/nano-states";import { SortableTree } from "~/designer/shared/tree";@@ -19,7 +19,7 @@ export const Navigator = ({ publish, isClosable, onClose }: NavigatorProps) => {return (<Flex css={{ height: "100%", flexDirection: "column" }}><Header title="Navigator" onClose={onClose} isClosable={isClosable} />- <Box css={{ flexGrow: 1, position: "relative" }}>+ <Flex css={{ flexGrow: 1, flexDirection: "column" }}><SortableTreeroot={rootInstance}selectedInstanceId={selectedInstanceData?.id}@@ -42,7 +42,7 @@ export const Navigator = ({ publish, isClosable, onClose }: NavigatorProps) => {>({ type: "reparentInstance", payload });}}/>- </Box>+ </Flex></Flex>);};diff --git a/apps/designer/app/designer/shared/tree/sortable-tree.stories.tsx b/apps/designer/app/designer/shared/tree/sortable-tree.stories.tsxindex 2a6b4ae125..34fce907cd 100644--- a/apps/designer/app/designer/shared/tree/sortable-tree.stories.tsx+++ b/apps/designer/app/designer/shared/tree/sortable-tree.stories.tsx@@ -4,7 +4,7 @@ import { useState } from "react";import produce from "immer";import { createInstance, reparentInstanceMutable } from "~/shared/tree-utils";import { SortableTree } from "./sortable-tree";-import { Box } from "@webstudio-is/design-system";+import { Flex } from "@webstudio-is/design-system";export const StressTest = ({ animate }: { animate: boolean }) => {const [root, setRoot] = useState<Instance>(() => {@@ -45,7 +45,7 @@ export const StressTest = ({ animate }: { animate: boolean }) => {>();return (- <Box css={{ width: 300, height: 500, position: "relative" }}>+ <Flex css={{ width: 300, height: 500, flexDirection: "column" }}><SortableTreeanimate={animate}root={root}@@ -64,7 +64,7 @@ export const StressTest = ({ animate }: { animate: boolean }) => {)}/>- </Box>+ </Flex>);};diff --git a/apps/designer/app/designer/shared/tree/sortable-tree.tsx b/apps/designer/app/designer/shared/tree/sortable-tree.tsxindex 6a6bc3b1fa..8936007b9a 100644--- a/apps/designer/app/designer/shared/tree/sortable-tree.tsx+++ b/apps/designer/app/designer/shared/tree/sortable-tree.tsx@@ -41,6 +41,7 @@ export const SortableTree = ({const { getIsExpanded, setIsExpanded } = useExpandState({root,selectedInstanceId,+ onSelect,});const rootNodeRef = useRef<HTMLElement | null>(null);@@ -199,7 +200,7 @@ export const SortableTree = ({getIsExpandable(dropTarget.data) &&getIsExpanded(dropTarget.data) === false) {- setIsExpanded(dropTarget.data.id, true);+ setIsExpanded(dropTarget.data, true);}},});@@ -265,7 +266,6 @@ export const SortableTree = ({getValidChildren: (element) => {return Array.from(- // @todo: if this works as expected, we need a selector that assumes less about the DOM structureelement.querySelectorAll(":scope > div > [data-drop-target-id]"));},@@ -284,7 +284,18 @@ export const SortableTree = ({if (id === undefined || id === root.id) {return false;}- return findInstanceById(root, id) || false;++ const instance = findInstanceById(root, id);++ if (instance === undefined) {+ return false;+ }++ if (components[instance.component].isInlineOnly) {+ return false;+ }++ return instance;},onStart: ({ data }) => {setDragItem(data);@@ -327,13 +338,13 @@ export const SortableTree = ({return (<Boxcss={{- position: "absolute",- top: 0,- left: 0,- right: 0,- bottom: 0,+ width: "100%",overflowY: "auto",- padding: "$1 0 $1 $1",+ overflowX: "hidden",+ flexBasis: 0,+ flexGrow: 1,+ pt: 2,+ pb: 2,}}ref={autoScrollHandlers.targetRef}onScroll={dropHandlers.handleScroll}@@ -341,12 +352,15 @@ export const SortableTree = ({<TreeNodeanimate={animate}onSelect={onSelect}- selectedInstanceId={selectedInstanceId}+ selectedInstanceId={+ dragItem === undefined ? selectedInstanceId : dragItem.id+ }instance={root}level={0}getIsExpanded={getIsExpanded}setIsExpanded={setIsExpanded}onExpandTransitionEnd={dropHandlers.handleDomMutation}+ disableHoverStates={dragItem !== undefined}ref={(element) => {rootNodeRef.current = element;dragHandlers.rootRef(element);@@ -405,15 +419,17 @@ const PlacementIndicatorOutline = ({ rect }: { rect: Rect }) => {<Boxstyle={{top: rect.top,- left: rect.left,- width: rect.width,+ left: rect.left + 2,+ width: rect.width - 4,height: rect.height,}}css={{position: "absolute",pointerEvents: "none",- outline: "2px solid #f531b3",- borderRadius: 6,+ boxSizing: "border-box",+ // @todo: add color to theme+ border: "2px solid #f531b3",+ borderRadius: "$2",}}/>);diff --git a/apps/designer/app/designer/shared/tree/tree-node.tsx b/apps/designer/app/designer/shared/tree/tree-node.tsxindex de01af3a0d..798b7dfb02 100644--- a/apps/designer/app/designer/shared/tree/tree-node.tsx+++ b/apps/designer/app/designer/shared/tree/tree-node.tsx@@ -4,13 +4,17 @@ import {Flex,Text,Collapsible,- Button,keyframes,styled,+ Box,} from "@webstudio-is/design-system";import { TriangleRightIcon, TriangleDownIcon } from "@webstudio-is/icons";import noop from "lodash.noop";+export const INDENT = 16;+const ITEM_HEIGHT = 32;+const ICONS_SIZE = 15;+export const getIsExpandable = (instance: Instance) => {return (// Text nodes have only one child which is a string.@@ -18,6 +22,84 @@ export const getIsExpandable = (instance: Instance) => {);};+const CustomButton = styled("button", {+ all: "unset",+ display: "flex",+ alignItems: "center",+ gap: "$1",+ boxSizing: "border-box",+ userSelect: "none",+ height: ITEM_HEIGHT,+ margin: 0,+ padding: 0,+ flexBasis: 0,+ flexGrow: 1,+ variants: {+ enableHoverState: {+ true: {+ "&:hover :before": {+ content: "''",+ display: "block",+ position: "absolute",+ top: 0,+ left: 2,+ right: 2,+ bottom: 0,+ boxSizing: "border-box",+ border: "2px solid $blue10",+ borderRadius: "$2",+ pointerEvents: "none",+ },+ },+ },+ },+});++const nestingLineStyles = {+ width: Math.ceil(INDENT / 2),+ height: ITEM_HEIGHT,+ borderRight: "1px solid",+ borderColor: "$slate9",+};+const nestingLineStylesSelected = {+ ...nestingLineStyles,+ borderColor: "$blue7",+};++const NestingLines = ({+ isSelected,+ level,+ followedByExpandButton,+}: {+ isSelected: boolean;+ level: number;+ followedByExpandButton: boolean;+}) => {+ if (level === 0) {+ return null;+ }++ if (level === 1) {+ return followedByExpandButton ? null : <Box css={{ width: INDENT }} />;+ }++ return (+ <>+ {Array.from({ length: level - 1 }, (_, i) => (+ <Box+ key={i}+ style={{+ marginRight:+ Math.floor(INDENT / 2) ++ (!followedByExpandButton && i === level - 2 ? INDENT : 0),+ }}+ css={isSelected ? nestingLineStylesSelected : nestingLineStyles}+ />+ ))}+ </>+ );+};+const openKeyframes = keyframes({from: { height: 0 },to: { height: "var(--radix-collapsible-content-height)" },@@ -43,18 +125,20 @@ const CollapsibleContentUnanimated = styled(Collapsible.Content, {});type TreeNodeProps = {+ disableHoverStates?: boolean;instance: Instance;selectedInstanceId: Instance["id"] | undefined;+ parentIsSelected?: boolean;level: number;onSelect?: (instance: Instance) => void;animate?: boolean;getIsExpanded: (instance: Instance) => boolean;- setIsExpanded: (instanceId: Instance["id"], expanded: boolean) => void;+ setIsExpanded: (instance: Instance, expanded: boolean) => void;onExpandTransitionEnd?: () => void;};export const TreeNode = forwardRef<HTMLDivElement, TreeNodeProps>(- ({ instance, level, ...commonProps }, ref) => {+ ({ instance, level, parentIsSelected, ...commonProps }, ref) => {const {getIsExpanded,animate = true,@@ -62,14 +146,24 @@ export const TreeNode = forwardRef<HTMLDivElement, TreeNodeProps>(selectedInstanceId,onSelect = noop,onExpandTransitionEnd = noop,+ disableHoverStates = false,} = commonProps;const collapsibleContentRef = useRef<HTMLDivElement>(null);+ const isAlwaysExpanded = level === 0;const isExpandable = getIsExpandable(instance);- const isExpanded = getIsExpanded(instance);+ const isExpanded = getIsExpanded(instance) || isAlwaysExpanded;const isSelected = instance.id === selectedInstanceId;+ const makeSelected = () => {+ if (isSelected === false) {+ onSelect(instance);+ }+ };++ const shouldRenderExpandButton = isExpandable && isAlwaysExpanded === false;+const { Icon, label } = components[instance.component];const CollapsibleContent = animate@@ -98,31 +192,71 @@ export const TreeNode = forwardRef<HTMLDivElement, TreeNodeProps>(<Collapsible.Rootref={ref}open={isExpanded}- onOpenChange={(isOpen: boolean) => setIsExpanded(instance.id, isOpen)}+ onOpenChange={(isOpen) => setIsExpanded(instance, isOpen)}data-drop-target-id={instance.id}><Flexcss={{- // @todo don't hardcode the padding- paddingLeft: level * 15 + (isExpandable ? 0 : 15),- color: "$hiContrast",+ color: isSelected ? "$loContrast" : "$hiContrast",alignItems: "center",+ pr: "$2",+ pl: "$2",+ backgroundColor: isSelected+ ? "$blue10"+ : parentIsSelected+ ? "$blue4"+ : "transparent",+ position: "relative",}}>- {isExpandable && (+ <NestingLines+ isSelected={isSelected}+ level={level}+ followedByExpandButton={shouldRenderExpandButton}+ />+ {shouldRenderExpandButton && (<Collapsible.Trigger asChild>- {isExpanded ? <TriangleDownIcon /> : <TriangleRightIcon />}+ <Flex+ css={{+ pr: INDENT - ICONS_SIZE,+ height: ITEM_HEIGHT,+ alignItems: "center",++ // We want the button to take extra space so it's easier to hit+ ml: "-$2",+ pl: "$2",+ }}+ >+ {isExpanded ? <TriangleDownIcon /> : <TriangleRightIcon />}+ </Flex></Collapsible.Trigger>)}- <Button- {...(isSelected ? { state: "active" } : { ghost: true })}- css={{ display: "flex", gap: "$1", padding: "$1" }}+ <CustomButtondata-drag-item-id={instance.id}- onFocus={() => onSelect(instance)}+ onFocus={makeSelected}+ onClick={makeSelected}+ enableHoverState={disableHoverStates === false}><Icon />- <Text size="1">{label}</Text>- </Button>+ <Text+ size="1"+ variant={isSelected ? "loContrast" : "contrast"}+ css={{+ whiteSpace: "nowrap",+ overflow: "hidden",+ textOverflow: "ellipsis",+ lineHeight: 1.4,+ flexBasis: 0,+ flexGrow: 1,++ // For some reason flexBasis:0 is not anough+ // to stop it growing past the container+ width: 0,+ }}+ >+ {label}+ </Text>+ </CustomButton></Flex>{isExpandable && (<CollapsibleContent@@ -140,6 +274,7 @@ export const TreeNode = forwardRef<HTMLDivElement, TreeNodeProps>(key={child.id}instance={child}level={level + 1}+ parentIsSelected={isSelected || parentIsSelected}{...commonProps}/>,]diff --git a/apps/designer/app/designer/shared/tree/tree.tsx b/apps/designer/app/designer/shared/tree/tree.tsxindex b8e5753e77..111f09f29c 100644--- a/apps/designer/app/designer/shared/tree/tree.tsx+++ b/apps/designer/app/designer/shared/tree/tree.tsx@@ -2,13 +2,16 @@ import { useState, useMemo, useCallback } from "react";import { type Instance } from "@webstudio-is/react-sdk";import { getInstancePath } from "~/shared/tree-utils";import { TreeNode, getIsExpandable } from "./tree-node";+import noop from "lodash.noop";export const useExpandState = ({selectedInstanceId,root,+ onSelect = noop,}: {root: Instance;selectedInstanceId?: Instance["id"];+ onSelect?: (instance: Instance) => void;}) => {const [record, setRecord] = useState<Record<Instance["id"], boolean>>({});@@ -23,18 +26,35 @@ export const useExpandState = ({);const getIsExpanded = useCallback(- (instance: Instance) =>- getIsExpandable(instance) &&- (record[instance.id] === true ||- selectedInstancePath.includes(instance.id)),- [record, selectedInstancePath]+ (instance: Instance) => {+ const isParentOfSelectedInstance =+ selectedInstancePath.includes(instance.id) &&+ selectedInstanceId !== instance.id;++ return (+ getIsExpandable(instance) &&+ (record[instance.id] === true || isParentOfSelectedInstance)+ );+ },+ [record, selectedInstanceId, selectedInstancePath]);const setIsExpanded = useCallback(- (instanceId: Instance["id"], expanded: boolean) => {- setRecord((record) => ({ ...record, [instanceId]: expanded }));+ (instance: Instance, expanded: boolean) => {+ setRecord((record) => ({ ...record, [instance.id]: expanded }));++ // To allow user to collapse a parent of a selected instance+ // We need to change the selected instance to the parent+ if (expanded === false) {+ const isParentOfSelectedInstance =+ selectedInstancePath.includes(instance.id) &&+ selectedInstanceId !== instance.id;+ if (isParentOfSelectedInstance) {+ onSelect(instance);+ }+ }},- []+ [onSelect, selectedInstanceId, selectedInstancePath]);return { getIsExpanded, setIsExpanded };@@ -47,13 +67,19 @@ export type TreeProps = {animate?: boolean;};-export const Tree = ({ root, selectedInstanceId, ...rest }: TreeProps) => {- const expandState = useExpandState({ root, selectedInstanceId });+export const Tree = ({+ root,+ selectedInstanceId,+ onSelect,+ ...rest+}: TreeProps) => {+ const expandState = useExpandState({ root, selectedInstanceId, onSelect });return (<TreeNodelevel={0}instance={root}selectedInstanceId={selectedInstanceId}+ onSelect={onSelect}{...rest}{...expandState}/>