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
Merge branch 'main' of github.com:webstudio-is/webstudio-designer into remove-asset
Sara Vieirafc48f7383b7e
diff --cc apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsxindex ad67f96b24,5cd97686ea..df64934c85--- a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager.tsx@@@ -1,21 -1,26 +1,21 @@@- import { ImageIcon } from "~/shared/icons";- import { Flex, Grid, Heading } from "~/shared/design-system";+ import { ImageIcon } from "@webstudio-is/icons";+ import { Flex, Grid, Heading } from "@webstudio-is/design-system";import { useEffect, useState } from "react";import { useActionData } from "@remix-run/react";-import { Asset } from "@webstudio-is/prisma-client";-import { AssetManagerImage } from "./components/image";+import { AssetManagerThumbnail } from "./components/thumbnail";import { AddAnAssetForm } from "./components/add-an-asset-form";-import { UploadingAsset } from "../types";+import { Asset } from "../types";-export const TabContent = ({- assets: baseAssets,-}: {- assets: Array<Asset | UploadingAsset>;-}) => {- const newImages = useActionData();+export const useAssetsState = (baseAssets: Array<Asset>) => {+ const imageChanges = useActionData();- const [assets, setAssets] = useState(baseAssets);+ const [assets, setAssets] = useState<Asset[]>(baseAssets);useEffect(() => {- if (newImages?.length) {+ if (imageChanges?.uploadedAssets?.length) {setAssets((currentAssets) => [- ...newImages,+ ...imageChanges.uploadedAssets,...currentAssets.filter((asset) => asset.status !== "uploading"),]);}diff --cc apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsxindex e4109c2cce,0000000000..894f95ea71mode 100644,000000..100644--- a/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx+++ b/apps/designer/app/designer/features/sidebar-left/panels/components/thumbnail.tsx@@@ -1,142 -1,0 +1,142 @@@+import { useEffect, useState } from "react";+import {+ Box,+ Button,+ Flex,+ ProgressBar,+ Tooltip,- } from "~/shared/design-system";++} from "@webstudio-is/design-system";+import { useInterval } from "react-use";+import placeholderImage from "~/shared/images/image-placeholder.svg";+import brokenImage from "~/shared/images/broken-image-placeholder.svg";+import { useSubmit } from "@remix-run/react";+import { Asset } from "~/designer/features/sidebar-left/types";+import { Cross2Icon } from "@radix-ui/react-icons";++const useImageWithFallback = ({ path }: { path: string }) => {+ const [src, setSrc] = useState(placeholderImage);++ useEffect(() => {+ const newImage = new Image();+ newImage.onload = () => setSrc(path);+ newImage.onerror = () => setSrc(brokenImage);+ newImage.src = path;+ }, [path]);++ return src;+};++const useFakeProgress = ({+ isUploading,+ isDeleting,+}: {+ isUploading: boolean;+ isDeleting: boolean;+}) => {+ const [progressBarPercentage, setProgressBarPercentage] = useState(0);++ // @todo rewrite this fake indication to show real progress+ useInterval(+ () => {+ setProgressBarPercentage((percentage) =>+ percentage < 60 ? percentage + 1 : percentage+ );+ },+ isUploading || isDeleting ? 100 : null+ );++ return progressBarPercentage;+};++export const AssetManagerThumbnail = ({+ path,+ alt,+ status,+ name,+ id,+}: Asset) => {+ const submit = useSubmit();+ const [isDeleting, setIsDeleting] = useState(false);+ const isUploading = status === "uploading";+ const src = useImageWithFallback({ path });+ const [isTooltipOpen, setTolltipOpen] = useState(false);+ const progressBarPercentage = useFakeProgress({ isUploading, isDeleting });++ const closeTooltip = () => setTolltipOpen(false);++ const deleteAsset = () => {+ const formData = new FormData();+ formData.append("assetId", id);+ formData.append("assetName", name);+ closeTooltip();+ setIsDeleting(true);+ submit(formData, { method: "delete" });+ };++ return (+ <Box+ title={alt || name}+ css={{+ aspectRatio: "1/1",+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ padding: "0 $2",+ position: "relative",+ }}+ >+ <Box+ css={{+ backgroundImage: `url("${src}")`,+ width: "100%",+ height: "100%",+ backgroundSize: "contain",+ backgroundRepeat: "no-repeat",+ backgroundPosition: "center",+ position: "absolute",+ left: 0,+ top: 0,+ ...(isUploading ? { filter: "blur(1px)", opacity: 0.7 } : {}),+ }}+ ></Box>+ {!isUploading && (+ <Tooltip+ open={isTooltipOpen}+ multiline+ onEscapeKeyDown={closeTooltip}+ onPointerDownOutside={closeTooltip}+ content={+ <Flex direction="column" gap={1} align="center" justify="center">+ Are you sure you want to delete this asset?+ <Button variant="red" onClick={deleteAsset}>+ Delete+ </Button>+ </Flex>+ }+ >+ <Button+ variant="raw"+ title="Delete asset"+ onClick={() => setTolltipOpen(true)}+ css={{+ position: "absolute",+ top: "$1",+ right: "$1",+ cursor: "pointer",+ color: "$highContrast",+ }}+ >+ <Cross2Icon />+ </Button>+ </Tooltip>+ )}+ {(isUploading || isDeleting) && (+ <ProgressBar+ value={progressBarPercentage}+ max={60}+ css={{ width: "100%", height: "$1" }}+ />+ )}+ </Box>+ );+};diff --cc apps/designer/package.jsonindex 5ed6e196e5,c5956ff7c5..8d8b1720d3--- a/apps/designer/package.json+++ b/apps/designer/package.json@@@ -54,8 -26,10 +26,10 @@@"@stitches/react": "^1.2.7","@vercel/node": "^2.4.1","@webstudio-is/asset-uploader": "*",- "@webstudio-is/react-sdk": "*","@webstudio-is/prisma-client": "*",+ "@webstudio-is/react-sdk": "*",+ "@webstudio-is/design-system": "*",+ "@webstudio-is/icons": "*","bson-objectid": "^2.0.2","camelcase": "^6.3.0","debug": "^4.3.4",