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.

Merge branch 'main' into 54_pages_ui2

Roman Pominov7114a4a4776c
diff --cc apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx
index 0702357926,acd8d6aa08..5d2ac42da0
--- a/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/pages/pages.tsx
@@@ -77,9 -68,8 +77,9 @@@ const staticTreeProps =
},
};
- const Pages = ({
+ const PagesPanel = ({
onClose,
+ onNewPage,
onSelect,
selectedPageId,
}: {
@@@ -145,36 -115,11 +145,36 @@@ export const TabContent = (props: TabCo
}
return (
- <PagesPanel
- onClose={() => props.onSetActiveTab("none")}
- onSelect={handleSelect}
- selectedPageId={currentPageId}
- />
+ <>
- <Pages
++ <PagesPanel
+ onClose={() => props.onSetActiveTab("none")}
+ onNewPage={() => {
+ if (newPageOpen === false) {
+ setNewPageOpen(true);
+ }
+ if (newPageOpen && newPageState === "idle") {
+ setNewPageOpen(false);
+ }
+ }}
+ onSelect={handleSelect}
+ selectedPageId={currentPageId}
+ />
+ <SettingsPanel isOpen={newPageOpen}>
+ <NewPageSettings
+ projectId={project.id}
+ onClose={() => {
+ if (newPageState === "idle") {
+ setNewPageOpen(false);
+ }
+ }}
+ onFetcherStateChange={setNewPageState}
+ onSuccess={(page) => {
+ setNewPageOpen(false);
+ handleSelect(page.id);
+ }}
+ />
+ </SettingsPanel>
+ </>
);
};
diff --cc packages/project/src/db/build.ts
index 6e339baaa3,19877cc298..2af5fbda62
--- a/packages/project/src/db/build.ts
+++ b/packages/project/src/db/build.ts
@@@ -61,43 -61,11 +61,43 @@@ export async function loadByProjectId
return parseBuild(build);
}
+export const addPage = async (
+ buildId: Build["id"],
+ data: { name: string; path: string }
+) => {
+ const build = await loadById(buildId);
+
+ const breakpoints = await db.breakpoints.load(buildId);
+ const tree = await db.tree.create(
+ db.tree.createRootInstance(breakpoints.values)
+ );
+
+ const nextPages = PagesSchema.parse({
+ homePage: build.pages.homePage,
+ pages: [
+ ...build.pages.pages,
+ {
+ id: uuid(),
+ name: data.name,
+ path: data.path,
+ title: data.name,
+ meta: {},
+ treeId: tree.id,
+ },
+ ],
+ });
+
+ const newBuild = await prisma.build.update({
+ where: { id: buildId },
+ data: { pages: JSON.stringify(nextPages) },
+ });
+
+ return parseBuild(newBuild);
+};
+
const createPages = async (breakpoints: Array<Breakpoint>) => {
- // const breakpoints = db.breakpoints.getBreakpointsWithId();
const tree = await db.tree.create(db.tree.createRootInstance(breakpoints));
- return PagesSchema.parse({
- // await db.breakpoints.create(tree.id, breakpoints);
+ return Pages.parse({
homePage: {
id: uuid(),
name: "Home",
diff --cc packages/project/src/db/types.ts
index 8ac459a815,e7f1f543c5..2a6c35d324
--- a/packages/project/src/db/types.ts
+++ b/packages/project/src/db/types.ts
@@@ -15,45 -16,15 +15,45 @@@ const commonPageFields =
title: z.string(),
meta: z.record(z.string(), z.string()),
treeId: z.string(),
+} as const;
+
- const HomePageSchema = z.object({
++const HomePage = z.object({
+ ...commonPageFields,
+ path: z
+ .string()
+ .refine((path) => path === "", "Home page path must be empty"),
+});
+
- const PageSchema = z.object({
++const Page = z.object({
+ ...commonPageFields,
+ path: z
+ .string()
+ .refine((path) => path !== "" && path !== "/", "Can't be empty")
+ .refine((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"
+ ),
});
- export type Page = z.infer<typeof PageSchema>;
+ export type Page = z.infer<typeof Page>;
- export const PagesSchema: z.ZodType<{ homePage: Page; pages: Array<Page> }> =
+ export const Pages: z.ZodType<{ homePage: Page; pages: Array<Page> }> =
z.object({
- homePage: HomePageSchema,
- homePage: Page,
- pages: z.array(Page),
++ homePage: HomePage,
+ pages: z
- .array(PageSchema)
++ .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 PagesSchema>;
+ export type Pages = z.infer<typeof Pages>;
export type Build = Omit<DbBuild, "pages"> & { pages: Pages };