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
feat: Mark empty style sources (#4685)
Oleg Isonen874db0e08ad8
diff --git a/apps/builder/app/builder/features/style-panel/style-source-section.tsx b/apps/builder/app/builder/features/style-panel/style-source-section.tsxindex dd36856d67..6171499d48 100644--- a/apps/builder/app/builder/features/style-panel/style-source-section.tsx+++ b/apps/builder/app/builder/features/style-panel/style-source-section.tsx@@ -335,7 +335,7 @@ const $componentStates = computed();type StyleSourceInputItem = {- id: string;+ id: StyleSource["id"];label: string;disabled: boolean;source: ItemSource;diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsxindex 436a1aeb07..a3b9374b64 100644--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx@@ -241,6 +241,28 @@ const StyleSourceState = styled(Text, {},});+const LocalStyleIcon = ({ size = 16, showDot = true }) => {+ return (+ <svg viewBox="0 0 16 16" width={size} height={size} fill="none">+ <path+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ d="M8 14.5a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13Z"+ />+ {showDot && (+ <path+ fill="currentColor"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ d="M8 9.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666Z"+ />+ )}+ </svg>+ );+};+const errors = {minlength: "Token must be at least 1 character long",duplicate: "Token already exists",@@ -254,7 +276,7 @@ export type StyleSourceError = {type StyleSourceControlProps = {id: StyleSource["id"];error?: StyleSourceError;- children: ReactNode;+ label: string;menuItems: ReactNode;selected: boolean;state: undefined | string;@@ -262,6 +284,7 @@ type StyleSourceControlProps = {disabled: boolean;isEditing: boolean;isDragging: boolean;+ hasStyles: boolean;source: ItemSource;onSelect: () => void;onChangeValue: (value: string) => void;@@ -278,14 +301,14 @@ export const StyleSourceControl = ({disabled,isEditing,isDragging,+ hasStyles,source,- children,+ label,onChangeValue,onChangeEditing,onSelect,}: StyleSourceControlProps) => {const showMenu = isEditing === false && isDragging === false;-return (<Tooltipcontent={error ? errors[error.type] : ""}@@ -300,23 +323,37 @@ export const StyleSourceControl = ({role="button"hasError={error !== undefined}>- <Flex grow css={{ py: theme.spacing[2], px: theme.spacing[3] }}>+ <Flex+ grow+ css={{+ position: "relative",+ paddingBlock: theme.spacing[3],+ paddingInline: theme.spacing[4],+ }}+ ><StyleSourceButtondisabled={disabled || isEditing}isEditing={isEditing}onClick={onSelect}tabIndex={-1}>- {typeof children === "string" ? (- <EditableText- isEditing={isEditing}- onChangeEditing={onChangeEditing}- onChangeValue={onChangeValue}- value={children}- />- ) : (- children- )}+ <Flex align="center" justify="center" gap="1">+ {source === "local" ? (+ <LocalStyleIcon showDot={hasStyles} />+ ) : (+ <>+ <EditableText+ isEditing={isEditing}+ onChangeEditing={onChangeEditing}+ onChangeValue={onChangeValue}+ value={label}+ />+ {hasStyles === false && isEditing === false && (+ <LocalStyleIcon showDot={hasStyles} />+ )}+ </>+ )}+ </Flex></StyleSourceButton></Flex>{stateLabel !== undefined && (diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsxindex 11963bd9da..a8fb25ac81 100644--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx@@ -30,11 +30,12 @@ import {rawTheme,theme,styled,- Flex,ComboboxScrollArea,InputField,+ Flex,+ Text,} from "@webstudio-is/design-system";-import { CheckMarkIcon, DotIcon, LocalStyleIcon } from "@webstudio-is/icons";+import { CheckMarkIcon, DotIcon } from "@webstudio-is/icons";import {forwardRef,useState,@@ -58,9 +59,12 @@ import { useSortable } from "./use-sortable";import { matchSorter } from "match-sorter";import { StyleSourceBadge } from "./style-source-badge";import { humanizeString } from "~/shared/string-utils";+import { $definedStyles } from "../shared/model";+import type { StyleDecl, StyleSource } from "@webstudio-is/sdk";+import { useStore } from "@nanostores/react";type IntermediateItem = {- id: string;+ id: StyleSource["id"];label: string;disabled: boolean;source: ItemSource;@@ -69,7 +73,7 @@ type IntermediateItem = {};export type ItemSelector = {- styleSourceId: IntermediateItem["id"];+ styleSourceId: StyleSource["id"];state?: string;};@@ -102,7 +106,7 @@ type TextFieldBaseWrapperProps<Item extends IntermediateItem> = Omit<label: string;containerRef?: RefObject<HTMLDivElement>;inputRef?: RefObject<HTMLInputElement>;- renderStyleSourceMenuItems: (item: Item) => ReactNode;+ renderStyleSourceMenuItems: (item: Item, hasStyles: boolean) => ReactNode;onChangeItem?: (item: Item) => void;onSort?: (items: Array<Item>) => void;onSelectItem?: (itemSelector: ItemSelector) => void;@@ -112,6 +116,27 @@ type TextFieldBaseWrapperProps<Item extends IntermediateItem> = Omit<error?: StyleSourceError;};+// Returns true if style source has defined styles including on the states.+const getHasStylesMap = <Item extends IntermediateItem>(+ styleSourceItems: Array<Item>,+ definedStyles: Set<Partial<StyleDecl>>+) => {+ const map = new Map<Item["id"], boolean>();+ for (const item of styleSourceItems) {+ // Style source has styles on states.+ if (item.states.length > 0) {+ map.set(item.id, true);+ }+ for (const style of definedStyles) {+ if (item.id === style.styleSourceId) {+ map.set(item.id, true);+ break;+ }+ }+ }+ return map;+};+const TextFieldBase: ForwardRefRenderFunction<HTMLDivElement,TextFieldBaseWrapperProps<IntermediateItem>@@ -152,6 +177,16 @@ const TextFieldBase: ForwardRefRenderFunction<internalInputRef.current?.focus();}, [internalInputRef]);+ const definedStyles = useStore($definedStyles);++ const hasStyles = useCallback(+ (styleSourceId: string) => {+ const hasStylesMap = getHasStylesMap(value, definedStyles);+ return hasStylesMap.get(styleSourceId) ?? false;+ },+ [value, definedStyles]+ );+return (<TextFieldContainer{...focusWithinProps}@@ -194,7 +229,7 @@ const TextFieldBase: ForwardRefRenderFunction<{value.map((item) => (<StyleSourceControlkey={item.id}- menuItems={renderStyleSourceMenuItems(item)}+ menuItems={renderStyleSourceMenuItems(item, hasStyles(item.id))}id={item.id}selected={item.id === selectedItemSelector?.styleSourceId}state={@@ -202,6 +237,7 @@ const TextFieldBase: ForwardRefRenderFunction<? selectedItemSelector.state: undefined}+ label={item.label}stateLabel={item.id === selectedItemSelector?.styleSourceId? states.find(@@ -213,6 +249,7 @@ const TextFieldBase: ForwardRefRenderFunction<disabled={item.disabled}isDragging={item.id === dragItemId}isEditing={item.id === editingItemId}+ hasStyles={hasStyles(item.id)}source={item.source}onChangeEditing={(isEditing) => {onEditItem?.(isEditing ? item.id : undefined);@@ -222,15 +259,7 @@ const TextFieldBase: ForwardRefRenderFunction<onEditItem?.();onChangeItem?.({ ...item, label });}}- >- {item.source === "local" ? (- <Flex align="center" justify="center">- <LocalStyleIcon />- </Flex>- ) : (- item.label- )}- </StyleSourceControl>+ />))}{placementIndicator}</TextFieldContainer>@@ -314,6 +343,7 @@ const markAddedValues = <Item extends IntermediateItem>(const renderMenuItems = (props: {selectedItemSelector: undefined | ItemSelector;item: IntermediateItem;+ hasStyles: boolean;states: ComponentState[];onSelect?: (itemSelector: ItemSelector) => void;onEdit?: (itemId: IntermediateItem["id"]) => void;@@ -327,7 +357,16 @@ const renderMenuItems = (props: {}) => {return (<>- <DropdownMenuLabel>{props.item.label}</DropdownMenuLabel>+ <DropdownMenuLabel>+ <Flex gap="1" justify="between" align="center">+ <Text css={{ fontWeight: "bold" }} truncate>+ {props.item.label}+ </Text>+ {props.hasStyles && (+ <DotIcon size="12" color={rawTheme.colors.foregroundPrimary} />+ )}+ </Flex>+ </DropdownMenuLabel>{props.item.source !== "local" && (<DropdownMenuItem onSelect={() => props.onEdit?.(props.item.id)}>Rename@@ -398,7 +437,7 @@ const renderMenuItems = (props: {withIndicator={true}icon={props.item.id === props.selectedItemSelector?.styleSourceId &&- selector === props.selectedItemSelector.state ? (+ selector === props.selectedItemSelector.state && (<CheckMarkIconcolor={props.item.states.includes(selector)@@ -407,9 +446,7 @@ const renderMenuItems = (props: {}size={12}/>- ) : props.item.states.includes(selector) ? (- <DotIcon color={rawTheme.colors.foregroundPrimary} />- ) : null+ )}onSelect={() =>props.onSelect?.({@@ -422,7 +459,15 @@ const renderMenuItems = (props: {})}>- {label}+ <Flex justify="between" align="center" grow>+ {label}+ {props.item.states.includes(selector) && (+ <DotIcon+ size="12"+ color={rawTheme.colors.foregroundPrimary}+ />+ )}+ </Flex></DropdownMenuItem>))}</Fragment>@@ -511,10 +556,11 @@ export const StyleSourceInput = (// @todo inputProps is any which breaks all types passed to TextField{...inputProps}error={props.error}- renderStyleSourceMenuItems={(item) =>+ renderStyleSourceMenuItems={(item, hasStyles) =>renderMenuItems({selectedItemSelector: props.selectedItemSelector,item,+ hasStyles,states,onSelect: props.onSelectItem,onDuplicate: props.onDuplicateItem,diff --git a/packages/design-system/src/components/menu.tsx b/packages/design-system/src/components/menu.tsxindex d2753eefd2..e27046596c 100644--- a/packages/design-system/src/components/menu.tsx+++ b/packages/design-system/src/components/menu.tsx@@ -24,12 +24,14 @@ import {} from "@radix-ui/react-dropdown-menu";import { CheckMarkIcon, DotIcon } from "@webstudio-is/icons";import type { ComponentProps } from "react";+import { truncate } from "../utilities";export const labelCss = css(textVariants.titles, {color: theme.colors.foregroundMain,mx: theme.spacing[3],padding: theme.spacing[3],order: 1,+ ...truncate(),});const indicatorSize = theme.spacing[9];diff --git a/packages/icons/icons/local-style.svg b/packages/icons/icons/local-style.svgdeleted file mode 100644index 6d8dc35412..0000000000--- a/packages/icons/icons/local-style.svg+++ /dev/null@@ -1,21 +0,0 @@-<svg- width="16"- height="16"- viewBox="0 0 16 16"- fill="none"- xmlns="http://www.w3.org/2000/svg"->- <path- d="M8 14.5C11.5899 14.5 14.5 11.5899 14.5 8C14.5 4.41015 11.5899 1.5 8 1.5C4.41015 1.5 1.5 4.41015 1.5 8C1.5 11.5899 4.41015 14.5 8 14.5Z"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- />- <path- d="M7.99996 9.33333C8.73634 9.33333 9.33329 8.73638 9.33329 8C9.33329 7.26362 8.73634 6.66667 7.99996 6.66667C7.26358 6.66667 6.66663 7.26362 6.66663 8C6.66663 8.73638 7.26358 9.33333 7.99996 9.33333Z"- fill="currentColor"- stroke="currentColor"- stroke-linecap="round"- stroke-linejoin="round"- />-</svg>diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsxindex 8c0bac7f16..7a5c7ebe4f 100644--- a/packages/icons/src/__generated__/components.tsx+++ b/packages/icons/src/__generated__/components.tsx@@ -3111,37 +3111,6 @@ export const LoadingDotsIcon: IconComponent = forwardRef();LoadingDotsIcon.displayName = "LoadingDotsIcon";-export const LocalStyleIcon: IconComponent = forwardRef(- ({ fill = "none", size = 16, ...props }, forwardedRef) => {- return (- <svg- xmlns="http://www.w3.org/2000/svg"- viewBox="0 0 16 16"- width={size}- height={size}- fill={fill}- {...props}- ref={forwardedRef}- >- <path- stroke="currentColor"- strokeLinecap="round"- strokeLinejoin="round"- d="M8 14.5a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13Z"- />- <path- fill="currentColor"- stroke="currentColor"- strokeLinecap="round"- strokeLinejoin="round"- d="M8 9.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666Z"- />- </svg>- );- }-);-LocalStyleIcon.displayName = "LocalStyleIcon";-export const MarkdownEmbedIcon: IconComponent = forwardRef(({ fill = "none", size = 16, ...props }, forwardedRef) => {return (diff --git a/packages/icons/src/__generated__/svg.ts b/packages/icons/src/__generated__/svg.tsindex efc9d30988..a291aa947d 100644--- a/packages/icons/src/__generated__/svg.ts+++ b/packages/icons/src/__generated__/svg.ts@@ -230,8 +230,6 @@ export const ListIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16export const LoadingDotsIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="eEMFTOz1Zbw1" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 300 300" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}</style><circle id="eEMFTOz1Zbw12_to" r="20" stroke-width="0" transform="translate(150,180) translate(0,0)"/><circle id="eEMFTOz1Zbw13_to" r="20" stroke-width="0" transform="translate(80,180) translate(0,0)"/><circle id="eEMFTOz1Zbw14_to" r="20" stroke-width="0" transform="translate(220,180) translate(0,0)"/></svg>`;-export const LocalStyleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 14.5a6.5 6.5 0 1 0 0-13 6.5 6.5 0 0 0 0 13Z"/><path fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 9.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666Z"/></svg>`;-export const MarkdownEmbedIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.667 5.333h4M4.667 8H10M14 8.75V3.5A1.5 1.5 0 0 0 12.5 2h-9A1.5 1.5 0 0 0 2 3.5v9.191c0 .725.588 1.313 1.313 1.313h4.691"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M11 14.314v-3l1.5 1.523 1.5-1.523v3"/></svg>`;export const MaximizeIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10 2h4v4M6 14H2v-4M14 2 9.334 6.667M2 14l4.667-4.667"/></svg>`;