Skip to content

Commit

Permalink
Add style sources schema (#850)
Browse files Browse the repository at this point in the history
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']
}
```
  • Loading branch information
TrySound authored Jan 27, 2023
1 parent a9b2fdb commit 0f9043f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE "Build"
ADD COLUMN "styleSources" TEXT NOT NULL DEFAULT '[]',
ADD COLUMN "styles" TEXT NOT NULL DEFAULT '[]';

-- AlterTable
ALTER TABLE "Tree"
ADD COLUMN "styleSelections" TEXT NOT NULL DEFAULT '[]';
16 changes: 10 additions & 6 deletions packages/prisma-client/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ model Build {
breakpoints Breakpoints?
designTokens DesignTokens?
styles String @default("[]")
styleSources String @default("[]")
}

model Tree {
id String @id @default(uuid())
root String
instances String @default("[]")
props String @default("[]")
presetStyles String @default("[]")
styles String @default("[]")
id String @id @default(uuid())
root String
instances String @default("[]")
props String @default("[]")
presetStyles String @default("[]")
styles String @default("[]")
styleSelections String @default("[]")
}

model InstanceProps {
Expand Down
1 change: 1 addition & 0 deletions packages/project-build/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./schema/instances";
export * from "./schema/props";
export * from "./schema/styles";
export * from "./schema/style-sources";
export * from "./types";
36 changes: 36 additions & 0 deletions packages/project-build/src/schema/style-sources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { z } from "zod";

const StyleSourceId = z.string();

const StyleSourceToken = z.object({
type: z.literal("token"),
id: StyleSourceId,
treeId: z.string().optional(),
name: z.string(),
});

const StyleSourceLocal = z.object({
type: z.literal("local"),
id: StyleSourceId,
treeId: z.string(),
name: z.string(),
});

export const StyleSource = z.union([StyleSourceToken, StyleSourceLocal]);

export type StyleSource = z.infer<typeof StyleSource>;

export const StyleSources = z.array(StyleSource);

export type StyleSources = z.infer<typeof StyleSources>;

export const StyleSourceSelection = z.object({
instanceId: z.string(),
values: z.array(StyleSourceId),
});

export type StyleSourceSelection = z.infer<typeof StyleSourceSelection>;

export const StyleSourceSelections = z.array(StyleSourceSelection);

export type StyleSourceSelections = z.infer<typeof StyleSourceSelections>;

0 comments on commit 0f9043f

Please sign in to comment.