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 fonts-manager after merge problems
Oleg Isonena775b90f9a11
diff --git a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsxindex 46deacc0fb..20b8af6320 100644--- a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx@@ -1,8 +1,7 @@-import { Grid, TextField } from "@webstudio-is/design-system";+import { TextField } from "@webstudio-is/design-system";import { FontsManager } from "~/designer/shared/fonts-manager";import type { ControlProps } from "../../style-sections";import { getFinalValue } from "../../shared/get-final-value";-import { PropertyName } from "../../shared/property-name";import { ValuePickerPopover } from "../../shared/value-picker-popover";export const FontFamilyControl = ({diff --git a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsxindex e170a9cf06..83639d8b0f 100644--- a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx+++ b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx@@ -2,7 +2,6 @@ import type { Asset } from "@webstudio-is/asset-uploader";import {Flex,Box,- Combobox,ComboboxListboxItem,TextField,DropdownMenu,@@ -13,12 +12,11 @@ import {Text,DropdownMenuPortal,useCombobox,- comboboxStateChangeTypes,} from "@webstudio-is/design-system";import { AssetUpload, PreviewAsset, useAssets } from "~/designer/shared/assets";import { SYSTEM_FONTS } from "@webstudio-is/fonts";import { DotsHorizontalIcon, MagnifyingGlassIcon } from "@webstudio-is/icons";-import { useCallback, useState } from "react";+import { useMemo } from "react";const getItems = (assets: Array<Asset | PreviewAsset>@@ -80,41 +78,15 @@ export const FontsManager = ({ value, onChange }: FontsManagerProps) => {onDelete(ids);};- const stateReducer = useCallback((state, actionAndChanges) => {- const { type, changes } = actionAndChanges;- switch (type) {- // on item selection.- case comboboxStateChangeTypes.ItemClick:- case comboboxStateChangeTypes.InputKeyDownEnter:- case comboboxStateChangeTypes.InputBlur:- case comboboxStateChangeTypes.ControlledPropUpdatedSelectedItem:- return {- ...changes,- // if we have a selected item.- ...(changes.selectedItem && {- // we will set the input value to "" (empty string).- inputValue: "",- }),- };-- // Remove "reset" action- case comboboxStateChangeTypes.InputKeyDownEscape: {- return {- ...state,- };- }-- default:- return changes; // otherwise business as usual.- }- }, []);+ const fontItems = useMemo(() => getItems(assets), [assets]);+ const selectedItem =+ fontItems.find((item) => item.label === value) ?? fontItems[0];const { items, getComboboxProps, getMenuProps, getItemProps, getInputProps } =useCombobox({- items: getItems(assets),- value: { label: value },+ items: fontItems,+ value: selectedItem,itemToString: (item) => item?.label ?? "",- stateReducer,onItemSelect: (value) => {if (value !== null) {onChange(value.label);@@ -122,6 +94,8 @@ export const FontsManager = ({ value, onChange }: FontsManagerProps) => {},});+ const { isEmpty, ...menuProps } = getMenuProps();+return (<Flexgap="3"@@ -143,18 +117,23 @@ export const FontsManager = ({ value, onChange }: FontsManagerProps) => {<TextFieldtype="search"prefix={<MagnifyingGlassIcon />}- {...getInputProps({})}+ {...getInputProps()}/><fieldset><legend>Choose an item</legend>- <Flex {...getMenuProps()} css={{ flexDirection: "column" }}>+ <Flex {...menuProps} css={{ flexDirection: "column" }}>{items.map((item, index) => {return (<ComboboxListboxItem- key={index}{...getItemProps({ item, index })}+ key={index}>{item.label}+ <ItemMenu+ onDelete={() => {+ handleDelete(item.label);+ }}+ /></ComboboxListboxItem>);})}