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
Move pages schema to project-build (#1040)
Bogdan Chadkin7bd744c7d942
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsxindex f13c1f1fbe..9a09cdbeb0 100644--- a/apps/builder/app/builder/builder.tsx+++ b/apps/builder/app/builder/builder.tsx@@ -1,11 +1,9 @@import { useCallback, useEffect, useMemo } from "react";import { type Publish, usePublish, useSubscribe } from "~/shared/pubsub";-import {- type Pages,- utils as projectUtils,- type Project,-} from "@webstudio-is/project";+import { utils as projectUtils, type Project } from "@webstudio-is/project";import { theme, Box, type CSS, Flex, Grid } from "@webstudio-is/design-system";+import type { AuthPermit } from "@webstudio-is/trpc-interface";+import type { Pages } from "@webstudio-is/project-build";import { registerContainers, useBuilderStore } from "~/shared/sync";import { useSyncServer } from "./shared/sync/sync-server";// eslint-disable-next-line import/no-internal-modules@@ -39,7 +37,6 @@ import { Navigator } from "./features/sidebar-left";import { getBuildUrl } from "~/shared/router-utils";import { useCopyPasteInstance } from "~/shared/copy-paste";import { AssetsProvider } from "./shared/assets";-import type { AuthPermit } from "@webstudio-is/trpc-interface";registerContainers();export const links = () => {diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsxindex e790aa817a..c613edfc7e 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx@@ -19,7 +19,7 @@ import {NewPageIcon,PageIcon,} from "@webstudio-is/icons";-import type { Page, Pages } from "@webstudio-is/project";+import type { Page, Pages } from "@webstudio-is/project-build";import type { Publish } from "~/shared/pubsub";import {useCurrentPageId,diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsxindex 5705ee712e..7252378db4 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/settings.tsx@@ -4,7 +4,7 @@ import { useDebouncedCallback } from "use-debounce";import { useUnmount } from "react-use";import slugify from "slugify";import { useFetcher } from "@remix-run/react";-import type { Page } from "@webstudio-is/project";+import type { Page, Pages } from "@webstudio-is/project-build";import {theme,Button,@@ -18,7 +18,7 @@ import {Tooltip,} from "@webstudio-is/design-system";import { ChevronDoubleLeftIcon, TrashIcon } from "@webstudio-is/icons";-import { type Pages, utils as projectUtils } from "@webstudio-is/project";+import { utils as projectUtils } from "@webstudio-is/project";import { usePages } from "~/builder/shared/nano-states";import { useOnFetchEnd, usePersistentFetcher } from "~/shared/fetcher";import {diff --git a/apps/builder/app/builder/features/topbar/topbar.tsx b/apps/builder/app/builder/features/topbar/topbar.tsxindex a739e5c862..5fae1bf476 100644--- a/apps/builder/app/builder/features/topbar/topbar.tsx+++ b/apps/builder/app/builder/features/topbar/topbar.tsx@@ -7,15 +7,16 @@ import {ToolbarSeparator,ToolbarToggleGroup,} from "@webstudio-is/design-system";+import type { Page } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";+import { theme } from "@webstudio-is/design-system";+import { isFeatureEnabled } from "@webstudio-is/feature-flags";import { PreviewButton } from "./preview";import { ShareButton } from "./share";import { PublishButton } from "./publish";import { SyncStatus } from "./sync-status";import { Menu } from "./menu";import { Breakpoints } from "../breakpoints";-import type { Page, Project } from "@webstudio-is/project";-import { theme } from "@webstudio-is/design-system";-import { isFeatureEnabled } from "@webstudio-is/feature-flags";import { ViewMode } from "./view-mode";const topbarContainerStyle = css({diff --git a/apps/builder/app/builder/shared/nano-states/index.ts b/apps/builder/app/builder/shared/nano-states/index.tsindex b5e703cdc8..aa2d17e0e8 100644--- a/apps/builder/app/builder/shared/nano-states/index.ts+++ b/apps/builder/app/builder/shared/nano-states/index.ts@@ -1,6 +1,7 @@import { atom, type WritableAtom } from "nanostores";import { useStore } from "@nanostores/react";-import type { Pages, Project } from "@webstudio-is/project";+import type { Pages } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";import type { AssetContainer, DeletingAssetContainer } from "../assets";const useValue = <T>(atom: WritableAtom<T>) => {diff --git a/apps/builder/app/builder/shared/sync/sync-server.ts b/apps/builder/app/builder/shared/sync/sync-server.tsindex 32756e9046..2f59901fb4 100644--- a/apps/builder/app/builder/shared/sync/sync-server.ts+++ b/apps/builder/app/builder/shared/sync/sync-server.ts@@ -1,6 +1,6 @@import { sync } from "immerhin";-import type { Build, Project } from "@webstudio-is/project";-import type { Tree } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";+import type { Build, Tree } from "@webstudio-is/project-build";import { restPatchPath } from "~/shared/router-utils";import { useEffect } from "react";import { enqueue, dequeue, queueStatus } from "./queue";diff --git a/apps/builder/app/routes/rest/pages.$projectId.ts b/apps/builder/app/routes/rest/pages.$projectId.tsindex 0df001592f..e97301a8f6 100644--- a/apps/builder/app/routes/rest/pages.$projectId.ts+++ b/apps/builder/app/routes/rest/pages.$projectId.ts@@ -1,6 +1,7 @@import type { LoaderArgs, ActionArgs } from "@remix-run/node";import { db } from "@webstudio-is/project/server";-import { type Pages, utils, pathValidators } from "@webstudio-is/project";+import { type Pages, pathValidators } from "@webstudio-is/project-build";+import { utils } from "@webstudio-is/project";import { zfd } from "zod-form-data";import { z } from "zod";import { sentryException } from "~/shared/sentry";diff --git a/apps/builder/app/routes/rest/patch.ts b/apps/builder/app/routes/rest/patch.tsindex 9dd8c315d9..65b2f2c474 100644--- a/apps/builder/app/routes/rest/patch.ts+++ b/apps/builder/app/routes/rest/patch.ts@@ -1,8 +1,8 @@import type { ActionArgs } from "@remix-run/node";-import type { Build, Project } from "@webstudio-is/project";-import { db as projectDb } from "@webstudio-is/project/server";import type { SyncItem } from "immerhin";-import type { Tree } from "@webstudio-is/project-build";+import type { Build, Tree } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";+import { db as projectDb } from "@webstudio-is/project/server";import { createContext } from "~/shared/context.server";type PatchData = {diff --git a/apps/builder/app/shared/pages/types.ts b/apps/builder/app/shared/pages/types.tsindex 58d343d0b7..aed176b5f5 100644--- a/apps/builder/app/shared/pages/types.ts+++ b/apps/builder/app/shared/pages/types.ts@@ -1,4 +1,4 @@-import type { Page } from "@webstudio-is/project";+import type { Page } from "@webstudio-is/project-build";import type { FetcherData } from "~/shared/form-utils";export type CreatePageData = FetcherData<{ page: Page }>;diff --git a/apps/builder/app/shared/router-utils/path-utils.ts b/apps/builder/app/shared/router-utils/path-utils.tsindex 4be58d6560..df577a93de 100644--- a/apps/builder/app/shared/router-utils/path-utils.ts+++ b/apps/builder/app/shared/router-utils/path-utils.ts@@ -1,5 +1,6 @@import type { AUTH_PROVIDERS } from "~/shared/session";-import type { Page, Project } from "@webstudio-is/project";+import type { Page } from "@webstudio-is/project-build";+import type { Project } from "@webstudio-is/project";import type { BuildMode } from "./build-params";import type { ThemeSetting } from "~/shared/theme";import env from "~/shared/env";diff --git a/packages/project-build/src/index.ts b/packages/project-build/src/index.tsindex 1f3e21a158..b6cc723335 100644--- a/packages/project-build/src/index.ts+++ b/packages/project-build/src/index.ts@@ -1,3 +1,4 @@+export * from "./schema/pages";export * from "./schema/instances";export * from "./schema/props";export * from "./schema/styles";diff --git a/packages/project-build/src/schema/pages.ts b/packages/project-build/src/schema/pages.tsnew file mode 100644index 0000000000..dfc25e31e5--- /dev/null+++ b/packages/project-build/src/schema/pages.ts@@ -0,0 +1,77 @@+import { z, type ZodType } from "zod";++const MIN_TITLE_LENGTH = 2;++const Title = z+ .string()+ .refine(+ (val) => val.length >= MIN_TITLE_LENGTH,+ `Minimum ${MIN_TITLE_LENGTH} characters required`+ );++const commonPageFields = {+ id: z.string(),+ name: z.string().refine((val) => val !== "", "Can't be empty"),+ title: Title,+ meta: z.record(z.string(), z.string()),+ treeId: z.string(),+} as const;++const HomePage = z.object({+ ...commonPageFields,+ path: z+ .string()+ .refine((path) => path === "", "Home page path must be empty"),+});++export const pathValidators = (+ baseValidator: ZodType<string>+): ZodType<string> =>+ baseValidator+ .refine((path) => path !== "", "Can't be empty")+ .refine((path) => path !== "/", "Can't be just a /")+ .refine(+ (path) => path === "" || path.startsWith("/"),+ "Must start with a /"+ )+ .refine((path) => path.endsWith("/") === false, "Can't end with a /")+ .refine(+ (path) => path.includes("//") === false,+ "Can't contain repeating /"+ )+ .refine(+ (path) => /^[-_a-z0-9\\/]*$/.test(path),+ "Only a-z, 0-9, -, _ and / are allowed"+ )+ .refine(+ // We use /s for our system stuff like /s/css or /s/uploads+ (path) => path !== "/s" && path.startsWith("/s/") === false,+ "/s prefix is reserved for the system"+ )+ .refine(+ // Remix serves build artefacts like JS bundles from /build+ // And we cannot customize it due to bug in Remix: https://github.com/remix-run/remix/issues/2933+ (path) => path !== "/build" && path.startsWith("/build/") === false,+ "/build prefix is reserved for the system"+ );++const Page = z.object({+ ...commonPageFields,+ path: pathValidators(z.string()),+});++export type Page = z.infer<typeof Page>;++export const Pages: z.ZodType<{ homePage: Page; pages: Array<Page> }> =+ z.object({+ homePage: HomePage,+ pages: z+ .array(Page)+ .refine(+ (array) =>+ new Set(array.map((page) => page.path)).size === array.length,+ "All paths must be unique"+ ),+ });++export type Pages = z.infer<typeof Pages>;diff --git a/packages/project-build/src/types.ts b/packages/project-build/src/types.tsindex 6129701acc..6e752494c2 100644--- a/packages/project-build/src/types.ts+++ b/packages/project-build/src/types.ts@@ -1,7 +1,23 @@+import type { Pages } from "./schema/pages";+import type { Breakpoint } from "./schema/breakpoints";+import type { StyleDecl, StyleDeclKey } from "./schema/styles";+import type { StyleSource } from "./schema/style-sources";import type { Instance } from "./schema/instances";import type { Prop } from "./schema/props";import type { StyleSourceSelection } from "./schema/style-source-selections";+export type Build = {+ id: string;+ projectId: string;+ createdAt: string;+ isDev: boolean;+ isProd: boolean;+ pages: Pages;+ breakpoints: [Breakpoint["id"], Breakpoint][];+ styles: [StyleDeclKey, StyleDecl][];+ styleSources: [StyleSource["id"], StyleSource][];+};+export type Tree = {id: string;projectId: string;diff --git a/packages/project/src/db/breakpoints.ts b/packages/project/src/db/breakpoints.tsindex c2cef6292b..e3c519f71e 100644--- a/packages/project/src/db/breakpoints.ts+++ b/packages/project/src/db/breakpoints.ts@@ -1,16 +1,13 @@import { nanoid } from "nanoid";import { applyPatches, type Patch } from "immer";import { initialBreakpoints } from "@webstudio-is/react-sdk";+import { type Project, prisma } from "@webstudio-is/prisma-client";import {- type Breakpoints as DbBreakpoints,- prisma,-} from "@webstudio-is/prisma-client";-import {+ type Build,Breakpoint,Breakpoints,BreakpointsList,} from "@webstudio-is/project-build";-import type { Project } from "../shared/schema";import {authorizeProject,type AppContext,@@ -42,10 +39,7 @@ export const createValues = (): [Breakpoint["id"], Breakpoint][] => {};export const patch = async (- {- buildId,- projectId,- }: { buildId: DbBreakpoints["buildId"]; projectId: Project["id"] },+ { buildId, projectId }: { buildId: Build["id"]; projectId: Project["id"] },patches: Array<Patch>,context: AppContext) => {diff --git a/packages/project/src/db/build.ts b/packages/project/src/db/build.tsindex a869fea3b9..0dff665230 100644--- a/packages/project/src/db/build.ts+++ b/packages/project/src/db/build.ts@@ -6,8 +6,8 @@ import {Project,} from "@webstudio-is/prisma-client";import type { AppContext } from "@webstudio-is/trpc-interface";+import { type Build, type Page, Pages } from "@webstudio-is/project-build";import * as db from ".";-import { Build, Page, Pages } from "../shared/schema";import * as pagesUtils from "../shared/pages";import { parseBreakpoints, serializeBreakpoints } from "./breakpoints";import { parseStyles, serializeStyles } from "./styles";diff --git a/packages/project/src/db/props.ts b/packages/project/src/db/props.tsindex 4e5778ffd2..d6503304aa 100644--- a/packages/project/src/db/props.ts+++ b/packages/project/src/db/props.ts@@ -1,7 +1,6 @@import { type Tree, Props, PropsList } from "@webstudio-is/project-build";import { applyPatches, type Patch } from "immer";-import { prisma } from "@webstudio-is/prisma-client";-import type { Project } from "../shared/schema";+import { type Project, prisma } from "@webstudio-is/prisma-client";import {authorizeProject,type AppContext,diff --git a/packages/project/src/db/style-source-selections.ts b/packages/project/src/db/style-source-selections.tsindex bd6be81160..c7e1ae53b4 100644--- a/packages/project/src/db/style-source-selections.ts+++ b/packages/project/src/db/style-source-selections.ts@@ -1,5 +1,5 @@import { type Patch, applyPatches } from "immer";-import { prisma } from "@webstudio-is/prisma-client";+import { type Project, prisma } from "@webstudio-is/prisma-client";import {authorizeProject,type AppContext,@@ -9,7 +9,6 @@ import {StyleSourceSelections,type Tree,} from "@webstudio-is/project-build";-import type { Project } from "../shared/schema";export const parseStyleSourceSelections = (styleSourceSelectionsString: stringdiff --git a/packages/project/src/db/style-sources.ts b/packages/project/src/db/style-sources.tsindex ba5a40d984..8ba23288da 100644--- a/packages/project/src/db/style-sources.ts+++ b/packages/project/src/db/style-sources.ts@@ -1,11 +1,14 @@import { type Patch, applyPatches } from "immer";-import { prisma } from "@webstudio-is/prisma-client";+import { type Project, prisma } from "@webstudio-is/prisma-client";import {authorizeProject,type AppContext,} from "@webstudio-is/trpc-interface/server";-import { StyleSourcesList, StyleSources } from "@webstudio-is/project-build";-import type { Build, Project } from "../shared/schema";+import {+ type Build,+ StyleSourcesList,+ StyleSources,+} from "@webstudio-is/project-build";export const parseStyleSources = (styleSourceString: string): StyleSources => {const styleSourcesList = StyleSourcesList.parse(diff --git a/packages/project/src/db/styles.ts b/packages/project/src/db/styles.tsindex 04ea941062..a4feae7bf7 100644--- a/packages/project/src/db/styles.ts+++ b/packages/project/src/db/styles.ts@@ -1,16 +1,16 @@import warnOnce from "warn-once";import { type Patch, applyPatches } from "immer";-import { prisma } from "@webstudio-is/prisma-client";+import { type Project, prisma } from "@webstudio-is/prisma-client";import type { Asset } from "@webstudio-is/asset-uploader";import { formatAsset } from "@webstudio-is/asset-uploader/server";import {+ type Build,type StoredStyleDecl,type StyleDecl,getStyleDeclKey,StoredStyles,Styles,} from "@webstudio-is/project-build";-import type { Build, Project } from "../shared/schema";import {authorizeProject,type AppContext,diff --git a/packages/project/src/db/tree.ts b/packages/project/src/db/tree.tsindex e834ea0623..8ddd0321aa 100644--- a/packages/project/src/db/tree.ts+++ b/packages/project/src/db/tree.ts@@ -7,10 +7,9 @@ import {Instance,Instances,} from "@webstudio-is/project-build";-import { prisma, type Prisma } from "@webstudio-is/prisma-client";+import { type Project, type Prisma, prisma } from "@webstudio-is/prisma-client";import { utils } from "../index";import { parseProps, serializeProps } from "./props";-import type { Project } from "../shared/schema";import {authorizeProject,type AppContext,diff --git a/packages/project/src/shared/pages/find-by-id-or-path.ts b/packages/project/src/shared/pages/find-by-id-or-path.tsindex cfbcfd9d2c..1fd934e113 100644--- a/packages/project/src/shared/pages/find-by-id-or-path.ts+++ b/packages/project/src/shared/pages/find-by-id-or-path.ts@@ -1,4 +1,4 @@-import type { Pages, Page } from "../schema";+import type { Pages, Page } from "@webstudio-is/project-build";export const findByIdOrPath = (pages: Pages,diff --git a/packages/project/src/shared/schema.ts b/packages/project/src/shared/schema.tsindex 5143da9574..e693f74543 100644--- a/packages/project/src/shared/schema.ts+++ b/packages/project/src/shared/schema.ts@@ -1,11 +1,6 @@-import { z, type ZodType } from "zod";-import type {- Breakpoint,- StyleDecl,- StyleDeclKey,- StyleSource,-} from "@webstudio-is/project-build";+import { z } from "zod";import type { Data } from "@webstudio-is/react-sdk";+import type { Build, Page } from "@webstudio-is/project-build";const MIN_TITLE_LENGTH = 2;@@ -29,84 +24,6 @@ export type Project = z.infer<typeof Project>;export const Projects = z.array(Project);export type Projects = z.infer<typeof Projects>;-const commonPageFields = {- id: z.string(),- name: z.string().refine((val) => val !== "", "Can't be empty"),- title: Title,- meta: z.record(z.string(), z.string()),- treeId: z.string(),-} as const;--const HomePage = z.object({- ...commonPageFields,- path: z- .string()- .refine((path) => path === "", "Home page path must be empty"),-});--export const pathValidators = (- baseValidator: ZodType<string>-): ZodType<string> =>- baseValidator- .refine((path) => path !== "", "Can't be empty")- .refine((path) => path !== "/", "Can't be just a /")- .refine(- (path) => path === "" || path.startsWith("/"),- "Must start with a /"- )- .refine((path) => path.endsWith("/") === false, "Can't end with a /")- .refine(- (path) => path.includes("//") === false,- "Can't contain repeating /"- )- .refine(- (path) => /^[-_a-z0-9\\/]*$/.test(path),- "Only a-z, 0-9, -, _ and / are allowed"- )- .refine(- // We use /s for our system stuff like /s/css or /s/uploads- (path) => path !== "/s" && path.startsWith("/s/") === false,- "/s prefix is reserved for the system"- )- .refine(- // Remix serves build artefacts like JS bundles from /build- // And we cannot customize it due to bug in Remix: https://github.com/remix-run/remix/issues/2933- (path) => path !== "/build" && path.startsWith("/build/") === false,- "/build prefix is reserved for the system"- );--const Page = z.object({- ...commonPageFields,- path: pathValidators(z.string()),-});--export type Page = z.infer<typeof Page>;--export const Pages: z.ZodType<{ homePage: Page; pages: Array<Page> }> =- z.object({- homePage: HomePage,- pages: z- .array(Page)- .refine(- (array) =>- new Set(array.map((page) => page.path)).size === array.length,- "All paths must be unique"- ),- });-export type Pages = z.infer<typeof Pages>;--export type Build = {- id: string;- projectId: string;- createdAt: string;- isDev: boolean;- isProd: boolean;- pages: Pages;- breakpoints: [Breakpoint["id"], Breakpoint][];- styles: [StyleDeclKey, StyleDecl][];- styleSources: [StyleSource["id"], StyleSource][];-};-export type CanvasData = Data & {build: null | Build;buildId: Build["id"];diff --git a/packages/project/src/shared/styles/css.ts b/packages/project/src/shared/styles/css.tsindex 3e0c031ef3..54681d665a 100644--- a/packages/project/src/shared/styles/css.ts+++ b/packages/project/src/shared/styles/css.ts@@ -1,12 +1,11 @@import { createCssEngine } from "@webstudio-is/css-engine";import type { Asset } from "@webstudio-is/asset-uploader";-import type { Tree } from "@webstudio-is/project-build";+import type { Build, Tree } from "@webstudio-is/project-build";import {getComponentMeta,getComponentNames,idAttribute,} from "@webstudio-is/react-sdk";-import type { Build } from "../schema";import { addGlobalRules } from "./global-rules";import { getStyleRules } from "./style-rules";