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.

feat: Add Publish Settings section to Project settings (#2720)

Ivan Starkov7bffdc095486
diff --git a/apps/builder/app/builder/features/seo/project-settings.tsx b/apps/builder/app/builder/features/seo/project-settings.tsx
index 2670e0f673..203c290575 100644
--- a/apps/builder/app/builder/features/seo/project-settings.tsx
+++ b/apps/builder/app/builder/features/seo/project-settings.tsx
@@ -12,6 +12,8 @@ import {
Separator,
Button,
css,
+ CheckboxAndLabel,
+ Checkbox,
} from "@webstudio-is/design-system";
import { useEffect, useState } from "react";
import { $isProjectSettingsOpen } from "~/shared/nano-states/seo";
@@ -24,12 +26,8 @@ import { serverSyncStore } from "~/shared/sync";
import { useEffectEvent } from "../ai/hooks/effect-event";
import type { Pages } from "@webstudio-is/sdk";
-type Value = NonNullable<Pages["meta"]>;
-
-type Props = {
- value: Value;
- onChange: (value: Value) => void;
-};
+type ProjectMeta = NonNullable<Pages["meta"]>;
+type ProjectSettings = NonNullable<Pages["settings"]>;
const imgStyle = css({
width: 72,
@@ -40,19 +38,22 @@ const imgStyle = css({
borderColor: theme.colors.borderMain,
});
-const ProjectSettingsContent = (props: Props) => {
+const ProjectSettingsContentMeta = (props: {
+ meta: ProjectMeta;
+ onMetaChange: (value: ProjectMeta) => void;
+}) => {
const ids = useIds(["siteName", "favicon", "code"]);
const handleChange =
- <T extends keyof Value>(name: T) =>
- (val: Value[T]) => {
- props.onChange({
- ...props.value,
- [name]: val,
+ <T extends keyof ProjectMeta>(name: T) =>
+ (value: ProjectMeta[T]) => {
+ props.onMetaChange({
+ ...props.meta,
+ [name]: value,
});
};
const assets = useStore(assetsStore);
- const asset = assets.get(props.value.faviconAssetId ?? "");
+ const asset = assets.get(props.meta.faviconAssetId ?? "");
const favIconUrl = asset ? `${asset.name}` : undefined;
@@ -61,12 +62,7 @@ const ProjectSettingsContent = (props: Props) => {
});
return (
- <Grid
- gap={2}
- css={{
- my: theme.spacing[5],
- }}
- >
+ <>
<Grid
gap={1}
css={{
@@ -78,7 +74,7 @@ const ProjectSettingsContent = (props: Props) => {
<Label htmlFor={ids.siteName}>Project Name</Label>
<InputField
id={ids.siteName}
- value={props.value.siteName ?? ""}
+ value={props.meta.siteName ?? ""}
onChange={(event) => handleChange("siteName")(event.target.value)}
placeholder="Current Project Name"
name="Name"
@@ -106,7 +102,7 @@ const ProjectSettingsContent = (props: Props) => {
Upload a 32 x 32 px image to display in browser tabs.
</Text>
<ImageControl
- assetId={props.value.faviconAssetId ?? ""}
+ assetId={props.meta.faviconAssetId ?? ""}
onAssetIdChange={handleChange("faviconAssetId")}
>
<Button id={ids.favicon} css={{ justifySelf: "start" }}>
@@ -132,17 +128,55 @@ const ProjectSettingsContent = (props: Props) => {
rows={5}
autoGrow
maxRows={10}
- value={props.value.code ?? ""}
+ value={props.meta.code ?? ""}
onChange={handleChange("code")}
/>
</Grid>
- <div />
- </Grid>
+ </>
+ );
+};
+
+const ProjectAdvancedSettings = (props: {
+ settings: ProjectSettings;
+ onSettingsChange: (settings: ProjectSettings) => void;
+}) => {
+ const ids = useIds(["atomicStyles"]);
+
+ const handleChange =
+ <T extends keyof ProjectSettings>(name: T) =>
+ (val: ProjectSettings[T]) => {
+ props.onSettingsChange({
+ ...props.settings,
+ [name]: val,
+ });
+ };
+
+ return (
+ <>
+ <Separator />
+ <Grid gap={2} css={{ mx: theme.spacing[5], px: theme.spacing[5] }}>
+ <Label sectionTitle>Publish Settings</Label>
+ <CheckboxAndLabel>
+ <Checkbox
+ checked={props.settings.atomicStyles ?? true}
+ id={ids.atomicStyles}
+ onCheckedChange={(checked) => {
+ if (typeof checked === "boolean") {
+ handleChange("atomicStyles")(checked);
+ }
+ }}
+ />
+ <Label htmlFor={ids.atomicStyles}>
+ Generate atomic CSS when publishing
+ </Label>
+ </CheckboxAndLabel>
+ </Grid>
+ </>
);
};
const ProjectSettingsView = () => {
- const [value, setValue] = useState(
+ const [meta, setMeta] = useState(
pagesStore.get()?.meta ?? {
siteName: "",
faviconAssetId: "",
@@ -150,6 +184,12 @@ const ProjectSettingsView = () => {
}
);
+ const [settings, setSettings] = useState(
+ pagesStore.get()?.settings ?? {
+ atomicStyles: true,
+ }
+ );
+
const isOpen = useStore($isProjectSettingsOpen);
const handleSave = useEffectEvent(() => {
@@ -158,7 +198,8 @@ const ProjectSettingsView = () => {
return;
}
- pages.meta = value;
+ pages.meta = meta;
+ pages.settings = settings;
});
});
@@ -181,7 +222,19 @@ const ProjectSettingsView = () => {
zIndex: theme.zIndices[1],
}}
>
- <ProjectSettingsContent value={value} onChange={setValue} />
+ <Grid
+ gap={2}
+ css={{
+ my: theme.spacing[5],
+ }}
+ >
+ <ProjectSettingsContentMeta meta={meta} onMetaChange={setMeta} />
+ <ProjectAdvancedSettings
+ settings={settings}
+ onSettingsChange={setSettings}
+ />
+ <div />
+ </Grid>
{/* Title is at the end intentionally,
* to make the close button last in the tab order
*/}
diff --git a/packages/sdk/src/schema/pages.ts b/packages/sdk/src/schema/pages.ts
index 75410e8232..b3f5b7188e 100644
--- a/packages/sdk/src/schema/pages.ts
+++ b/packages/sdk/src/schema/pages.ts
@@ -73,16 +73,24 @@ const Page = z.object({
});
const ProjectMeta = z.object({
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
siteName: z.string().optional(),
faviconAssetId: z.string().optional(),
code: z.string().optional(),
});
+
+const ProjectSettings = z.object({
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
+ atomicStyles: z.boolean().optional(),
+});
+
export type ProjectMeta = z.infer<typeof ProjectMeta>;
export type Page = z.infer<typeof Page>;
export const Pages = z.object({
meta: ProjectMeta.optional(),
+ settings: ProjectSettings.optional(),
homePage: HomePage,
pages: z
.array(Page)