Skip to content

Commit 0f9043f

Browse files
authored
Add style sources schema (#850)
Ref #807 We are gonna consolidate design token styles and local styles. On build (project) level there will be list of styles and list of style sources which are basically a group of styles to be referenced. These style sources can be local with mandatory tree id or token with optional tree id to scope a token on specific page instead of whole project. Tree will get new list of references to style sources. Here resulting types ```ts // Stored as Build.styles type StylesItem = { // same as before but instead of instanceId style is referenced through style source styleSourceId: string, breakpointId, property, value } type StyleSourcesToken = { type: token id: string treeId?: string name: string } type StyleSourcesLocal = { type: local id: string treeId: string name: string } // Stored as Build.styleSources type StyleSourcesItem = StyleSourcesToken | StyleSourcesLocal // Stored as Tree.styleRefs type StyleRefsItem = { instanceId: string, values: StyleSourcesItem['id'] } ```
1 parent a9b2fdb commit 0f9043f

4 files changed

Lines changed: 55 additions & 6 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- AlterTable
2+
ALTER TABLE "Build"
3+
ADD COLUMN "styleSources" TEXT NOT NULL DEFAULT '[]',
4+
ADD COLUMN "styles" TEXT NOT NULL DEFAULT '[]';
5+
6+
-- AlterTable
7+
ALTER TABLE "Tree"
8+
ADD COLUMN "styleSelections" TEXT NOT NULL DEFAULT '[]';

packages/prisma-client/prisma/schema.prisma

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ model Build {
7575
7676
breakpoints Breakpoints?
7777
designTokens DesignTokens?
78+
79+
styles String @default("[]")
80+
styleSources String @default("[]")
7881
}
7982

8083
model Tree {
81-
id String @id @default(uuid())
82-
root String
83-
instances String @default("[]")
84-
props String @default("[]")
85-
presetStyles String @default("[]")
86-
styles String @default("[]")
84+
id String @id @default(uuid())
85+
root String
86+
instances String @default("[]")
87+
props String @default("[]")
88+
presetStyles String @default("[]")
89+
styles String @default("[]")
90+
styleSelections String @default("[]")
8791
}
8892

8993
model InstanceProps {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./schema/instances";
22
export * from "./schema/props";
33
export * from "./schema/styles";
4+
export * from "./schema/style-sources";
45
export * from "./types";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { z } from "zod";
2+
3+
const StyleSourceId = z.string();
4+
5+
const StyleSourceToken = z.object({
6+
type: z.literal("token"),
7+
id: StyleSourceId,
8+
treeId: z.string().optional(),
9+
name: z.string(),
10+
});
11+
12+
const StyleSourceLocal = z.object({
13+
type: z.literal("local"),
14+
id: StyleSourceId,
15+
treeId: z.string(),
16+
name: z.string(),
17+
});
18+
19+
export const StyleSource = z.union([StyleSourceToken, StyleSourceLocal]);
20+
21+
export type StyleSource = z.infer<typeof StyleSource>;
22+
23+
export const StyleSources = z.array(StyleSource);
24+
25+
export type StyleSources = z.infer<typeof StyleSources>;
26+
27+
export const StyleSourceSelection = z.object({
28+
instanceId: z.string(),
29+
values: z.array(StyleSourceId),
30+
});
31+
32+
export type StyleSourceSelection = z.infer<typeof StyleSourceSelection>;
33+
34+
export const StyleSourceSelections = z.array(StyleSourceSelection);
35+
36+
export type StyleSourceSelections = z.infer<typeof StyleSourceSelections>;

0 commit comments

Comments
 (0)