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
wip Build
Oleg Isonen20d904482b6c
diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex b1f71ac06f..1313ef0225 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -42,6 +42,7 @@ import {import { useClientSettings } from "./shared/client-settings";import { Navigator } from "./features/sidebar-left";import { PANEL_WIDTH } from "./shared/constants";+import * as db from "~/shared/db";export const links = () => {return [@@ -219,7 +220,7 @@ const NavigatorPanel = ({ publish, isPreviewMode }: NavigatorPanelProps) => {type DesignerProps = {config: Config;- project: Project;+ project: db.project.Project;assets: Array<Asset>;};diff --git a/apps/designer/app/designer/features/topbar/publish.tsx b/apps/designer/app/designer/features/topbar/publish.tsxindex b9767998cd..ebc64d3cda 100644--- a/apps/designer/app/designer/features/topbar/publish.tsx+++ b/apps/designer/app/designer/features/topbar/publish.tsx@@ -1,7 +1,6 @@import { useState, useEffect } from "react";import { useFetcher } from "@remix-run/react";import { RocketIcon, ExternalLinkIcon } from "@webstudio-is/icons";-import { type Project } from "@webstudio-is/prisma-client";import {Button,Flex,@@ -16,8 +15,9 @@ import {} from "@webstudio-is/design-system";import { useIsPublishDialogOpen } from "../../shared/nano-states";import env from "~/shared/env";+import * as db from "~/shared/db";-type PublishButtonProps = { project: Project };+type PublishButtonProps = { project: db.project.Project };const getHost = () => {if (env.PUBLISHER_ENDPOINT && env.PUBLISHER_HOST) {diff --git a/apps/designer/app/designer/features/topbar/share.tsx b/apps/designer/app/designer/features/topbar/share.tsxindex 6581e792d3..ca998a54ec 100644--- a/apps/designer/app/designer/features/topbar/share.tsx+++ b/apps/designer/app/designer/features/topbar/share.tsx@@ -8,10 +8,10 @@ import {TextField,} from "@webstudio-is/design-system";import { Share1Icon } from "@webstudio-is/icons";-import { type Project } from "@webstudio-is/prisma-client";import { useIsShareDialogOpen } from "../../shared/nano-states";+import * as db from "~/shared/db";-type ShareButtonProps = { path: string; project: Project };+type ShareButtonProps = { path: string; project: db.project.Project };const Content = ({ path, project }: ShareButtonProps) => {if (typeof location === "undefined") {diff --git a/apps/designer/app/designer/features/topbar/topbar.tsx b/apps/designer/app/designer/features/topbar/topbar.tsxindex 123b7cbba0..ecee191fe3 100644--- a/apps/designer/app/designer/features/topbar/topbar.tsx+++ b/apps/designer/app/designer/features/topbar/topbar.tsx@@ -1,5 +1,4 @@import type { Publish } from "@webstudio-is/react-sdk";-import type { Project } from "@webstudio-is/prisma-client";import { darkTheme, Flex, type CSS } from "@webstudio-is/design-system";import type { Config } from "~/config";import { PreviewButton } from "./preview";@@ -8,11 +7,12 @@ import { PublishButton } from "./publish";import { SyncStatus } from "./sync-status";import { Menu } from "./menu";import { Breakpoints } from "../breakpoints";+import * as db from "~/shared/db";type TopbarProps = {config: Config;css: CSS;- project: Project;+ project: db.project.Project;publish: Publish;};export const Topbar = ({ config, css, project, publish }: TopbarProps) => {diff --git a/apps/designer/app/routes/designer/$id.tsx b/apps/designer/app/routes/designer/$id.tsxindex 0dfe516950..d7e81695a1 100644--- a/apps/designer/app/routes/designer/$id.tsx+++ b/apps/designer/app/routes/designer/$id.tsx@@ -1,42 +1,46 @@import { useActionData, useLoaderData } from "@remix-run/react";import { ActionFunction, LoaderFunction } from "@remix-run/node";-import type { Project, Asset } from "@webstudio-is/prisma-client";+import type { Asset } from "@webstudio-is/prisma-client";import { toast } from "@webstudio-is/design-system";import { Designer, links } from "~/designer";import * as db from "~/shared/db";import config from "~/config";-import env from "~/env.server";+import env, { type Env } from "~/env.server";import { uploadAssets } from "~/shared/db/misc.server";import { ErrorMessage } from "~/shared/error";// if this file does not end in .server remix will not build// since it only allows node code in those filesimport {deleteAsset,- loadByProject,+ loadByProject as loadAssetByProject,} from "@webstudio-is/asset-uploader/index.server";import { zfd } from "zod-form-data";import { useEffect } from "react";export { links };-export const loader: LoaderFunction = async ({ params }) => {- if (params.id === undefined) throw new Error("Project id undefined");- const project = await db.project.loadById(params.id);- const assets = await loadByProject(params.id);- if (project === null) {- return { errors: `Project "${params.id}" not found` };- }- return { config, assets, project, env };-};-type Data = {config: typeof config;- project: Project;+ project: db.project.Project;assets: Asset[];+ env: Env;};type Error = {- errors: "string";+ errors: string;+};++export const loader: LoaderFunction = async ({+ params,+}): Promise<Data | Error> => {+ if (params.id === undefined) throw new Error("Project id undefined");+ const project = await db.project.loadById(params.id);+ const assets = await loadAssetByProject(params.id);++ if (project === null) {+ return { errors: `Project "${params.id}" not found` };+ }+ return { config, assets, project, env };};const deleteAssetSchema = zfd.formData({diff --git a/apps/designer/app/shared/db/build.server.ts b/apps/designer/app/shared/db/build.server.tsnew file mode 100644index 0000000000..aada1fdd77--- /dev/null+++ b/apps/designer/app/shared/db/build.server.ts@@ -0,0 +1,34 @@+import { prisma, Build as DbBuild } from "@webstudio-is/prisma-client";+import { z } from "zod";++const Page = z.object({+ id: z.string(),+ name: z.string(),+ path: z.string(),+ title: z.string(),+ meta: z.record(z.string(), z.string()),+});+const Pages = z.array(Page);+type Pages = z.infer<typeof Pages>;++type Build = {+ id: DbBuild["id"];+ pages: Pages;+};++export const load = async (id: Build["id"]): Promise<Build> => {+ if (typeof id !== "string") {+ throw new Error("Build ID required");+ }++ const build = await prisma.build.findUnique({+ where: { id },+ });++ if (build === null) {+ throw new Error("Build not found");+ }++ const pages = Pages.parse(JSON.parse(build.pages));+ return { id, pages };+};diff --git a/apps/designer/app/shared/db/index.ts b/apps/designer/app/shared/db/index.tsindex 8e5524eaa7..21a7c26a97 100644--- a/apps/designer/app/shared/db/index.ts+++ b/apps/designer/app/shared/db/index.ts@@ -3,5 +3,7 @@ export * as project from "./project.server";export * as props from "./props.server";export * as misc from "./misc.server";export * as user from "./user.server";+// @todo make the export consistent with the restexport * from "./canvas.server";export * as breakpoints from "./breakpoints.server";+export * as build from "./build.server";diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prismaindex e6cd47389d..5c4d40ad1c 100644--- a/packages/prisma-client/prisma/schema.prisma+++ b/packages/prisma-client/prisma/schema.prisma@@ -47,15 +47,28 @@ model User {}model Project {- id String @id @default(uuid())- title String- domain String @unique+ id String @id @default(uuid())+ title String+ domain String @unique+ User User? @relation(fields: [userId], references: [id])+ userId String?+ Asset Asset[]+ build Build @relation(fields: [buildIdDev], references [id])+ buildIdDev String+ buildIdProd String? // exists when published+ buildIdHistory String @default("[]")++ // Migrating away fromprodTreeId String? // exists when publisheddevTreeId StringprodTreeIdHistory String @default("[]")- User User? @relation(fields: [userId], references: [id])- userId String?- Asset Asset[]+}++model Build {+ id String @id @default(uuid())+ createdAt DateTime @default(now())+ pages String @default("[]") // Each page can be a tree of folders and pages+ Project}model Tree {diff --git a/packages/prisma-client/src/types.ts b/packages/prisma-client/src/types.tsindex fbaabd8d76..f18bc53ee3 100644--- a/packages/prisma-client/src/types.ts+++ b/packages/prisma-client/src/types.ts@@ -1,6 +1,12 @@import type { Asset as DbAsset } from "@prisma/client";export { Location } from "@prisma/client";-export type { InstanceProps, Project, User, Breakpoints } from "@prisma/client";+export type {+ InstanceProps,+ Project,+ User,+ Breakpoints,+ Build,+} from "@prisma/client";export type Asset = DbAsset & {path: string;