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
reuse asset manager layout
Oleg Isonen092ba12726b6
diff --git a/apps/designer/app/designer/shared/assets/assets-shell.tsx b/apps/designer/app/designer/shared/assets/assets-shell.tsxnew file mode 100644index 0000000000..d0b14c9d1e--- /dev/null+++ b/apps/designer/app/designer/shared/assets/assets-shell.tsx@@ -0,0 +1,43 @@+import { type ComponentProps } from "react";+import type { AssetType } from "@webstudio-is/asset-uploader";+import { Flex, SearchField } from "@webstudio-is/design-system";+import { AssetUpload } from "./asset-upload";+import { NotFound } from "./not-found";+import { Separator } from "./separator";++type AssetsShellProps = {+ searchProps: ComponentProps<typeof SearchField>;+ children: JSX.Element;+ type: AssetType;+ isEmpty: boolean;+};++export const AssetsShell = ({+ searchProps,+ isEmpty,+ children,+ type,+}: AssetsShellProps) => {+ return (+ <Flex+ direction="column"+ css={{ overflow: "hidden", paddingTop: "$1", paddingBottom: "$3" }}+ >+ <Flex css={{ py: "$2", px: "$3" }} gap="2" direction="column">+ <AssetUpload type={type} />+ <SearchField {...searchProps} autoFocus placeholder="Search" />+ </Flex>+ <Separator />+ {isEmpty && <NotFound />}+ <Flex+ css={{+ flexDirection: "column",+ gap: "$3",+ px: "$3",+ }}+ >+ {children}+ </Flex>+ </Flex>+ );+};diff --git a/apps/designer/app/designer/shared/assets/index.ts b/apps/designer/app/designer/shared/assets/index.tsindex 79e7479e04..f55e12259a 100644--- a/apps/designer/app/designer/shared/assets/index.ts+++ b/apps/designer/app/designer/shared/assets/index.ts@@ -1,4 +1,6 @@-export * from "./asset-upload";export * from "./use-assets";export * from "./types";export * from "./use-set-assets";+export * from "./separator";+export * from "./use-search";+export * from "./assets-shell";diff --git a/apps/designer/app/designer/shared/assets/not-found.tsx b/apps/designer/app/designer/shared/assets/not-found.tsxnew file mode 100644index 0000000000..a925e74ce3--- /dev/null+++ b/apps/designer/app/designer/shared/assets/not-found.tsx@@ -0,0 +1,9 @@+import { Flex } from "@webstudio-is/design-system";++export const NotFound = () => {+ return (+ <Flex align="center" justify="center" css={{ height: 100 }}>+ Nothing found+ </Flex>+ );+};diff --git a/apps/designer/app/designer/shared/assets/separator.tsx b/apps/designer/app/designer/shared/assets/separator.tsxnew file mode 100644index 0000000000..34ba22c805--- /dev/null+++ b/apps/designer/app/designer/shared/assets/separator.tsx@@ -0,0 +1,9 @@+import {+ Separator as SeparatorPrimitive,+ styled,+} from "@webstudio-is/design-system";++export const Separator = styled(SeparatorPrimitive, {+ marginTop: "$1",+ marginBottom: "$2",+});diff --git a/apps/designer/app/designer/shared/fonts-manager/use-search.tsx b/apps/designer/app/designer/shared/assets/use-search.tsxsimilarity index 100%rename from apps/designer/app/designer/shared/fonts-manager/use-search.tsxrename to apps/designer/app/designer/shared/assets/use-search.tsxdiff --git a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsxindex 83e1281cf2..48a4561445 100644--- a/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx+++ b/apps/designer/app/designer/shared/fonts-manager/fonts-manager.tsx@@ -1,14 +1,15 @@import {- Flex,- Separator as SeparatorPrimitive,- SearchField,List,ListItem,useList,findNextListIndex,- styled,} from "@webstudio-is/design-system";-import { AssetUpload, useAssets } from "~/designer/shared/assets";+import {+ AssetsShell,+ Separator,+ useAssets,+ useSearch,+} from "~/designer/shared/assets";import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { useMenu } from "./item-menu";import { CheckIcon } from "@webstudio-is/icons";@@ -19,15 +20,6 @@ import {groupItemsByType,toItems,} from "./item-utils";-import { useSearch } from "./use-search";--const NotFound = () => {- return (- <Flex align="center" justify="center" css={{ height: 100 }}>- Font not found- </Flex>- );-};const useFilteredItems = ({ onReset }: { onReset: () => void }) => {const { assets } = useAssets("font");@@ -136,11 +128,6 @@ const useLogic = ({};};-const Separator = styled(SeparatorPrimitive, {- marginTop: "$1",- marginBottom: "$2",-});-type FontsManagerProps = {value: string;onChange: (value: string) => void;@@ -180,46 +167,33 @@ export const FontsManager = ({ value, onChange }: FontsManagerProps) => {};return (- <Flex- direction="column"- css={{ overflow: "hidden", paddingTop: "$1", paddingBottom: "$3" }}+ <AssetsShell+ searchProps={searchProps}+ type="font"+ isEmpty={groupedItems.length === 0}>- <Flex css={{ py: "$2", px: "$3" }} gap="2" direction="column">- <AssetUpload type="font" />- <SearchField {...searchProps} autoFocus placeholder="Search" />- </Flex>- <Separator />- {groupedItems.length === 0 && <NotFound />}- <Flex- css={{- flexDirection: "column",- gap: "$3",- px: "$3",+ <List+ {...listProps}+ onBlur={(event) => {+ if (isMenuOpen === false) {+ listProps.onBlur(event);+ }}}>- <List- {...listProps}- onBlur={(event) => {- if (isMenuOpen === false) {- listProps.onBlur(event);- }- }}- >- {uploadedItems.length !== 0 && (- <ListItem state="disabled">{"Uploaded"}</ListItem>- )}- {uploadedItems.map(renderItem)}- {systemItems.length !== 0 && (- <>- {uploadedItems.length !== 0 && <Separator />}- <ListItem state="disabled">{"System"}</ListItem>- </>- )}- {systemItems.map((item, index) =>- renderItem(item, index + uploadedItems.length)- )}- </List>- </Flex>- </Flex>+ {uploadedItems.length !== 0 && (+ <ListItem state="disabled">{"Uploaded"}</ListItem>+ )}+ {uploadedItems.map(renderItem)}+ {systemItems.length !== 0 && (+ <>+ {uploadedItems.length !== 0 && <Separator />}+ <ListItem state="disabled">{"System"}</ListItem>+ </>+ )}+ {systemItems.map((item, index) =>+ renderItem(item, index + uploadedItems.length)+ )}+ </List>+ </AssetsShell>);};diff --git a/apps/designer/app/designer/shared/image-manager/image-manager.tsx b/apps/designer/app/designer/shared/image-manager/image-manager.tsxindex 860b56ccdd..2a11d9f544 100644--- a/apps/designer/app/designer/shared/image-manager/image-manager.tsx+++ b/apps/designer/app/designer/shared/image-manager/image-manager.tsx@@ -1,7 +1,7 @@-import { Box, Flex, Grid } from "@webstudio-is/design-system";+import { Grid } from "@webstudio-is/design-system";import type { Asset } from "@webstudio-is/asset-uploader";import { ImageThumbnail } from "./image-thumbnail";-import { AssetUpload, useAssets } from "../assets";+import { AssetsShell, useAssets } from "../assets";type ImageManagerProps = {onSelect?: (asset: Asset) => void;@@ -10,10 +10,7 @@ type ImageManagerProps = {export const ImageManager = ({ onSelect }: ImageManagerProps) => {const { assets, handleDelete } = useAssets("image");return (- <Flex gap="3" direction="column" css={{ padding: "$1", paddingTop: "$2" }}>- <Box css={{ padding: "$2" }}>- <AssetUpload type="image" />- </Box>+ <AssetsShell searchProps={{}} isEmpty={assets.length === 0} type="image"><Grid columns={2} gap={2}>{assets.map((asset) => (<ImageThumbnail@@ -24,6 +21,6 @@ export const ImageManager = ({ onSelect }: ImageManagerProps) => {/>))}</Grid>- </Flex>+ </AssetsShell>);};