Skip to content

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.

wip

Roman Pominovd6ec7b38f24f
diff --git a/apps/designer/app/routes/designer/$id.tsx b/apps/designer/app/routes/designer/$id.tsx
index d065d0d7ff..1bc0df733c 100644
--- a/apps/designer/app/routes/designer/$id.tsx
+++ b/apps/designer/app/routes/designer/$id.tsx
@@ -3,7 +3,6 @@ import { LoaderFunction } from "@remix-run/node";
import { Designer, links } from "~/designer";
import * as db from "~/shared/db";
import config from "~/config";
-import env, { type Env } from "~/env.server";
import { ErrorMessage } from "~/shared/error";
import { action, useAction } from "./_assets";
@@ -18,13 +17,12 @@ export const loader: LoaderFunction = async ({
if (project === null) {
return { errors: `Project "${params.id}" not found` };
}
- return { config, project, env };
+ return { config, project };
};
type Data = {
config: typeof config;
project: db.project.Project;
- env: Env;
};
type Error = {
diff --git a/apps/designer/app/shared/db/build.server.ts b/apps/designer/app/shared/db/build.server.ts
index f40998bd3d..63c3719024 100644
--- a/apps/designer/app/shared/db/build.server.ts
+++ b/apps/designer/app/shared/db/build.server.ts
@@ -47,7 +47,46 @@ export const loadById = async (id: Build["id"]): Promise<Build> => {
return parseBuild(build);
};
-export const create = async (projectId: string) => {
+export const loadDevByProjectId = async (
+ projectId: Build["projectId"]
+): Promise<Build> => {
+ if (typeof projectId !== "string") {
+ throw new Error("Project ID required");
+ }
+
+ const build = await prisma.build.findFirst({
+ where: { projectId, isDev: true },
+ });
+
+ if (build === null) {
+ throw new Error("Build not found");
+ }
+
+ return parseBuild(build);
+};
+
+export const loadProdByProjectId = async (
+ projectId: Build["projectId"]
+): Promise<Build | undefined> => {
+ if (typeof projectId !== "string") {
+ throw new Error("Project ID required");
+ }
+
+ const build = await prisma.build.findFirst({
+ where: { projectId, isProd: true },
+ });
+
+ if (build === null) {
+ return undefined;
+ }
+
+ return parseBuild(build);
+};
+
+// Each project has a mutable dev build.
+// When user edits a project we update the dev build and other objects it references.
+// (As opposed to cloning a build, which we do for production builds)
+export const createDev = async (projectId: Build["projectId"]) => {
const breakpoints = db.breakpoints.getBreakpointsWithId();
const tree = await db.tree.create(db.tree.createRootInstance(breakpoints));
await db.breakpoints.create(tree.id, breakpoints);
@@ -75,3 +114,55 @@ export const create = async (projectId: string) => {
return parseBuild(build);
};
+
+export const clone = async (build: Build) => {
+ // @todo: clone pages other than home page
+
+ const treeId = build.pages.homePage.treeId;
+
+ const tree = await db.tree.clone(treeId);
+ await db.props.clone({ previousTreeId: treeId, nextTreeId: tree.id });
+ await db.breakpoints.clone({ previousTreeId: treeId, nextTreeId: tree.id });
+
+ const pages = PagesSchema.parse({
+ homePage: {
+ ...build.pages.homePage,
+ id: uuid(),
+ treeId: tree.id,
+ },
+ pages: [],
+ });
+
+ const cloneBuild = await prisma.build.create({
+ data: {
+ pages: JSON.stringify(pages),
+ isDev: false,
+ isProd: false,
+ projectId: build.projectId,
+ },
+ });
+
+ return parseBuild(cloneBuild);
+};
+
+export const setAsProd = async (buildId: Build["id"]) => {
+ await prisma.$transaction(async (transaction) => {
+ const build = await transaction.build.findUnique({
+ where: { id: buildId },
+ });
+
+ if (build === null) {
+ throw new Error("Build not found");
+ }
+
+ await transaction.build.updateMany({
+ where: { projectId: build.projectId, isProd: true },
+ data: { isProd: false },
+ });
+
+ await transaction.build.update({
+ where: { id: build.id },
+ data: { isProd: true },
+ });
+ });
+};
diff --git a/apps/designer/app/shared/db/project.server.ts b/apps/designer/app/shared/db/project.server.ts
index 933d253648..a10f7b95e7 100644
--- a/apps/designer/app/shared/db/project.server.ts
+++ b/apps/designer/app/shared/db/project.server.ts
@@ -107,7 +107,7 @@ export const create = async ({
},
});
- await db.build.create(project.id);
+ await db.build.createDev(project.id);
return parseProject(project);
};
@@ -173,14 +173,9 @@ export const update = async ({
}
}
- TreeHistorySchema.parse(data.prodTreeIdHistory);
-
try {
const project = await prisma.project.update({
- data: {
- ...data,
- prodTreeIdHistory: JSON.stringify(data.prodTreeIdHistory),
- },
+ data,
where: { id },
include: {
assets: {
diff --git a/apps/designer/app/shared/db/tree.server.ts b/apps/designer/app/shared/db/tree.server.ts
index da500b9155..71855a326d 100644
--- a/apps/designer/app/shared/db/tree.server.ts
+++ b/apps/designer/app/shared/db/tree.server.ts
@@ -44,22 +44,22 @@ export const loadById = async (treeId: string): Promise<Tree | null> => {
};
};
-export const loadByProject = async (
- project: Project | null,
- env: "production" | "development" = "development"
-) => {
- if (project === null) {
- throw new Error("Project required");
- }
+// export const loadByProject = async (
+// project: Project | null,
+// env: "production" | "development" = "development"
+// ) => {
+// if (project === null) {
+// throw new Error("Project required");
+// }
- const treeId = env === "production" ? project.prodTreeId : project.devTreeId;
+// const treeId = env === "production" ? project.prodTreeId : project.devTreeId;
- if (treeId === null) {
- throw new Error("Site needs to be published, production tree ID is null.");
- }
+// if (treeId === null) {
+// throw new Error("Site needs to be published, production tree ID is null.");
+// }
- return await loadById(treeId);
-};
+// return await loadById(treeId);
+// };
export const clone = async (treeId: string) => {
const tree = await loadById(treeId);