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: add download asset button (#5417)
Bogdan Chadkin65017634abba
diff --git a/apps/builder/app/builder/shared/image-manager/image-info.tsx b/apps/builder/app/builder/shared/image-manager/image-info.tsxindex 07edea794c..91959932c7 100644--- a/apps/builder/app/builder/shared/image-manager/image-info.tsx+++ b/apps/builder/app/builder/shared/image-manager/image-info.tsx@@ -14,6 +14,7 @@ import {DialogTrigger,Flex,Grid,+ IconButton,InputErrorsTooltip,InputField,Label,@@ -32,6 +33,7 @@ import {AspectRatioIcon,CloudIcon,DimensionsIcon,+ DownloadIcon,GearIcon,InfoCircleIcon,PageIcon,@@ -48,6 +50,7 @@ import {$props,$styles,$styleSourceSelections,+ $userPlanFeatures,} from "~/shared/nano-states";import { $openProjectSettings } from "~/shared/nano-states/project-settings";import {@@ -58,7 +61,7 @@ import {import { updateWebstudioData } from "~/shared/instance-utils";import { deleteAssets, $usagesByAssetId, type AssetUsage } from "../assets";import { $activeInspectorPanel, setActiveSidebarPanel } from "../nano-states";-import { parseAssetName } from "../assets/asset-utils";+import { formatAssetName, parseAssetName } from "../assets/asset-utils";import { getFormattedAspectRatio } from "./utils";const buttonLinkClass = css({@@ -257,6 +260,7 @@ const ImageInfoContent = ({asset: Asset;usages: AssetUsage[];}) => {+ const { hasProPlan } = useStore($userPlanFeatures);const { size, meta, id, name } = asset;const { basename, ext } = parseAssetName(name);const [filenameError, setFilenameError] = useState<string>();@@ -303,6 +307,14 @@ const ImageInfoContent = ({const authPermit = useStore($authPermit);+ let downloadError: undefined | string;+ if (authPermit === "view") {+ downloadError =+ "Unavailable in View mode. Switch to Edit to download assets.";+ } else if (!hasProPlan) {+ downloadError = "Upgrade to Pro to download assets.";+ }+return (<><Box css={{ padding: theme.panel.padding }}>@@ -392,7 +404,7 @@ const ImageInfoContent = ({/></Grid>- <Box css={{ padding: theme.panel.padding }}>+ <Flex justify="between" css={{ padding: theme.panel.padding }}>{authPermit === "view" ? (<Tooltip side="bottom" content="View mode. You can't delete assets."><Button disabled color="destructive" prefix={<TrashIcon />}>@@ -436,7 +448,25 @@ const ImageInfoContent = ({</DialogContent></Dialog>)}- </Box>++ {downloadError ? (+ <Tooltip side="bottom" content={downloadError}>+ <IconButton disabled>+ <DownloadIcon />+ </IconButton>+ </Tooltip>+ ) : (+ <Tooltip side="bottom" content="Download asset">+ <IconButton+ as="a"+ download={formatAssetName(asset)}+ href={`/cgi/image/${asset.name}?format=raw`}+ >+ <DownloadIcon />+ </IconButton>+ </Tooltip>+ )}+ </Flex></>);};diff --git a/packages/icons/icons/download.svg b/packages/icons/icons/download.svgnew file mode 100644index 0000000000..cff86e4f9e--- /dev/null+++ b/packages/icons/icons/download.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-download-icon lucide-download"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsxindex b66ae41f52..7bf0a77a45 100644--- a/packages/icons/src/__generated__/components.tsx+++ b/packages/icons/src/__generated__/components.tsx@@ -2069,6 +2069,31 @@ export const DottedBorderIcon: IconComponent = forwardRef();DottedBorderIcon.displayName = "DottedBorderIcon";+export const DownloadIcon: IconComponent = forwardRef(+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="2"+ className="lucide lucide-download-icon lucide-download"+ viewBox="0 0 24 24"+ width={size}+ height={size}+ fill={fill}+ {...props}+ ref={forwardedRef}+ >+ <path d="M12 15V3M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />+ <path d="m7 10 5 5 5-5" />+ </svg>+ );+ }+);+DownloadIcon.displayName = "DownloadIcon";+export const DragHandleIcon: 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 f2a9393528..de5a3ae07b 100644--- a/packages/icons/src/__generated__/svg.ts+++ b/packages/icons/src/__generated__/svg.ts@@ -154,6 +154,8 @@ export const DotIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewexport const DottedBorderIcon = `<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="M5.464 8a.667.667 0 1 0 1.333 0 .667.667 0 0 0-1.333 0ZM9.202 8a.667.667 0 1 0 1.334 0 .667.667 0 0 0-1.334 0ZM12.94 8a.667.667 0 1 0 1.334 0 .667.667 0 0 0-1.333 0ZM1.726 8a.667.667 0 1 0 1.333 0 .667.667 0 0 0-1.333 0Z"/></svg>`;+export const DownloadIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" class="lucide lucide-download-icon lucide-download" viewBox="0 0 24 24" width="100%" height="100%" style="display: block;"><path d="M12 15V3M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>`;+export const DragHandleIcon = `<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="M6 8.667a.667.667 0 1 0 0-1.334.667.667 0 0 0 0 1.334ZM6 4a.667.667 0 1 0 0-1.333A.667.667 0 0 0 6 4ZM6 13.333A.667.667 0 1 0 6 12a.667.667 0 0 0 0 1.333ZM10 8.667a.667.667 0 1 0 0-1.334.667.667 0 0 0 0 1.334ZM10 4a.667.667 0 1 0 0-1.333A.667.667 0 0 0 10 4ZM10 13.333A.667.667 0 1 0 10 12a.667.667 0 0 0 0 1.333Z"/></svg>`;export const DynamicPageIcon = `<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 12.203H3.855a1.474 1.474 0 0 1-1.473-1.473V2.81a1.474 1.474 0 0 1 1.473-1.474h6.079l3.684 3.683v5.71a1.474 1.474 0 0 1-1.474 1.474H8Zm0 0 .01 2.462m0 0H2.39m5.618 0h5.618"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M9.198 1.888V3.73a1.474 1.474 0 0 0 1.473 1.474h2.947"/></svg>`;