Skip to content
Merged
Changes from all commits
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
18 changes: 9 additions & 9 deletions apps/builder/app/builder/features/marketplace/templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { ChevronLeftIcon, ExternalLinkIcon } from "@webstudio-is/icons";
import {
elementComponent,
Instance,
ROOT_FOLDER_ID,
type Asset,
type Page,
Expand All @@ -33,6 +34,10 @@ import { Card } from "./card";
import type { MarketplaceOverviewItem } from "~/shared/marketplace/types";
import { selectPage } from "~/shared/awareness";

const isBody = (instance: Instance) =>
instance.component === "Body" ||
(instance.component === elementComponent && instance.tag === "body");

/**
* Insert page as a template.
* - Currently only supports inserting everything from the body
Expand All @@ -46,17 +51,12 @@ const insertSection = ({
instanceId: string;
}) => {
const fragment = extractWebstudioFragment(data, instanceId);
const body = fragment.instances.find(
(instance) => instance.component === "Body"
);
const body = fragment.instances.find(isBody);
// remove body and use its children as root insrances
if (body) {
fragment.instances = fragment.instances.filter((instance) => {
const isBody =
instance.component === "Body" ||
(instance.component === elementComponent && instance.tag === "body");
return !isBody;
});
fragment.instances = fragment.instances.filter(
(instance) => !isBody(instance)
);
fragment.children = body.children;
}
const insertable = findClosestInsertable(fragment);
Expand Down