Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions apps/builder/app/shared/copy-paste/asset-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { nanoid } from "nanoid";
import { produce, enablePatches, type Patch, applyPatches } from "immer";

enablePatches();

type StringProp = Extract<
WebstudioFragment["props"][number],
{ type: "string" }
>;

const extractSrcProps = (
data: WebstudioFragment
): [propId: string, href: string][] => {
Expand All @@ -22,17 +16,20 @@ const extractSrcProps = (
.map((instance) => instance.id)
);

const srcProps = data.props
.filter(
(prop): prop is StringProp =>
prop.type === "string" &&
prop.name === "src" &&
imageComponentsSet.has(prop.instanceId)
)
.map(
(prop) =>
[prop.id, new URL(prop.value).href] as [propId: string, href: string]
);
const srcProps: [propId: string, href: string][] = [];
for (const prop of data.props) {
if (
prop.type === "string" &&
prop.name === "src" &&
imageComponentsSet.has(prop.instanceId)
) {
try {
srcProps.push([prop.id, new URL(prop.value).href]);
} catch {
// ignore when invalid url
}
}
}

return srcProps;
};
Expand Down
Loading