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.

keep schema.ts separate

Roman Pominov6343291d415e
diff --git a/packages/react-sdk/src/css/breakpoints.ts b/packages/react-sdk/src/css/breakpoints.ts
index a87f3bc1fe..d55ee75955 100644
--- a/packages/react-sdk/src/css/breakpoints.ts
+++ b/packages/react-sdk/src/css/breakpoints.ts
@@ -1,4 +1,4 @@
-import { type Breakpoint } from "./types";
+import { type Breakpoint } from "./schema";
export type BaseBreakpoint = Pick<Breakpoint, "label" | "minWidth">;
diff --git a/packages/react-sdk/src/css/get-browser-style.ts b/packages/react-sdk/src/css/get-browser-style.ts
index bd0586e918..9f7d3f8e58 100644
--- a/packages/react-sdk/src/css/get-browser-style.ts
+++ b/packages/react-sdk/src/css/get-browser-style.ts
@@ -1,4 +1,5 @@
-import type { Style, StyleProperty, StyleValue, Unit } from "./types";
+import type { StyleProperty } from "./types";
+import type { Style, StyleValue, Unit } from "./schema";
import { properties } from "./properties";
import { units } from "./units";
diff --git a/packages/react-sdk/src/css/index.ts b/packages/react-sdk/src/css/index.ts
index 73da609888..0465831969 100644
--- a/packages/react-sdk/src/css/index.ts
+++ b/packages/react-sdk/src/css/index.ts
@@ -1,6 +1,7 @@
export * from "./properties";
export * from "./units";
export * from "./types";
+export * from "./schema";
export * from "./get-browser-style";
export * from "./categories";
export * from "./keyword-values";
diff --git a/packages/react-sdk/src/css/schema.ts b/packages/react-sdk/src/css/schema.ts
new file mode 100644
index 0000000000..f3e8072cf8
--- /dev/null
+++ b/packages/react-sdk/src/css/schema.ts
@@ -0,0 +1,53 @@
+import { z } from "zod";
+import { units } from "./units";
+import { StyleProperty } from "./types";
+
+export const Unit = z.union([z.enum(units), z.literal("number")]);
+
+export type Unit = z.infer<typeof Unit>;
+
+const UnitValue = z.object({
+ type: z.literal("unit"),
+ unit: Unit,
+ value: z.number(),
+});
+
+const KeywordValue = z.object({
+ type: z.literal("keyword"),
+ // @todo use exact type
+ value: z.string(),
+});
+
+// We want to be able to render the invalid value
+// and show it is invalid visually, without saving it to the db
+const InvalidValue = z.object({
+ type: z.literal("invalid"),
+ value: z.string(),
+});
+
+export const StyleValue = z.union([UnitValue, KeywordValue, InvalidValue]);
+
+export type StyleValue = z.infer<typeof StyleValue>;
+
+export const Style = z.record(z.string(), StyleValue);
+
+export type Style = {
+ [property in StyleProperty]?: StyleValue;
+};
+
+export const CssRule = z.object({
+ style: Style,
+ breakpoint: z.string(),
+});
+
+export type CssRule = z.infer<typeof CssRule>;
+
+export const Breakpoint = z.object({
+ id: z.string(),
+ label: z.string(),
+ minWidth: z.number(),
+});
+
+export const Breakpoints = z.array(Breakpoint);
+
+export type Breakpoint = z.infer<typeof Breakpoint>;
diff --git a/packages/react-sdk/src/css/types.ts b/packages/react-sdk/src/css/types.ts
index 8079125f9f..7cf39d75e1 100644
--- a/packages/react-sdk/src/css/types.ts
+++ b/packages/react-sdk/src/css/types.ts
@@ -1,59 +1,7 @@
-import { z } from "zod";
import { properties } from "./properties";
-import { units } from "./units";
-
-export const Unit = z.union([z.enum(units), z.literal("number")]);
-
-const UnitValue = z.object({
- type: z.literal("unit"),
- unit: Unit,
- value: z.number(),
-});
-
-const KeywordValue = z.object({
- type: z.literal("keyword"),
- // @todo use exact type
- value: z.string(),
-});
-
-// We want to be able to render the invalid value
-// and show it is invalid visually, without saving it to the db
-const InvalidValue = z.object({
- type: z.literal("invalid"),
- value: z.string(),
-});
-
-export const StyleValue = z.union([UnitValue, KeywordValue, InvalidValue]);
-
-export const Style = z.record(z.string(), StyleValue);
-
-export const CssRule = z.object({
- style: Style,
- breakpoint: z.string(),
-});
-
-export const Breakpoint = z.object({
- id: z.string(),
- label: z.string(),
- minWidth: z.number(),
-});
-
-export const Breakpoints = z.array(Breakpoint);
type Properties = typeof properties;
export type StyleProperty = keyof Properties;
export type AppliesTo = Properties[StyleProperty]["appliesTo"];
-
-export type Style = {
- [property in StyleProperty]?: StyleValue;
-};
-
-export type CssRule = z.infer<typeof CssRule>;
-
-export type Unit = z.infer<typeof Unit>;
-
-export type StyleValue = z.infer<typeof StyleValue>;
-
-export type Breakpoint = z.infer<typeof Breakpoint>;
diff --git a/packages/react-sdk/src/user-props/index.ts b/packages/react-sdk/src/user-props/index.ts
index c40d18919e..d8a42eebec 100644
--- a/packages/react-sdk/src/user-props/index.ts
+++ b/packages/react-sdk/src/user-props/index.ts
@@ -1,3 +1,4 @@
export * from "./all-user-props";
export * from "./use-user-props";
export * from "./types";
+export * from "./schema";
diff --git a/packages/react-sdk/src/user-props/schema.ts b/packages/react-sdk/src/user-props/schema.ts
new file mode 100644
index 0000000000..8e3b66cf64
--- /dev/null
+++ b/packages/react-sdk/src/user-props/schema.ts
@@ -0,0 +1,12 @@
+import { z } from "zod";
+
+export const UserProp = z.object({
+ id: z.string(),
+ prop: z.string(),
+ value: z.union([z.string(), z.boolean()]),
+ required: z.optional(z.boolean()),
+});
+
+export type UserProp = z.infer<typeof UserProp>;
+
+export const UserProps = z.array(UserProp);
diff --git a/packages/react-sdk/src/user-props/types.ts b/packages/react-sdk/src/user-props/types.ts
index e371a6bffe..79175a0e65 100644
--- a/packages/react-sdk/src/user-props/types.ts
+++ b/packages/react-sdk/src/user-props/types.ts
@@ -1,16 +1,5 @@
-import { z } from "zod";
import type { InstanceProps, Instance } from "../db";
-
-export const UserProp = z.object({
- id: z.string(),
- prop: z.string(),
- value: z.union([z.string(), z.boolean()]),
- required: z.optional(z.boolean()),
-});
-
-export const UserProps = z.array(UserProp);
-
-export type UserProp = z.infer<typeof UserProp>;
+import { UserProp } from "./schema";
export type UserPropsUpdates = {
treeId: InstanceProps["treeId"];
diff --git a/packages/react-sdk/src/user-props/use-user-props.ts b/packages/react-sdk/src/user-props/use-user-props.ts
index 50a8bfba5d..1a0389c5a5 100644
--- a/packages/react-sdk/src/user-props/use-user-props.ts
+++ b/packages/react-sdk/src/user-props/use-user-props.ts
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useState } from "react";
import { type Instance } from "../db";
-import { type UserProp } from "./types";
+import { type UserProp } from "./schema";
import { useAllUserProps } from "./all-user-props";
type UserProps = { [prop: UserProp["prop"]]: UserProp["value"] };