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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
move shared design tokens logic to a separate package
Oleg Isonen8d26bf781b3c
diff --git a/apps/designer/app/canvas/shared/design-tokens.ts b/apps/designer/app/canvas/shared/design-tokens.tsindex ed3637104c..7a0d164b85 100644--- a/apps/designer/app/canvas/shared/design-tokens.ts+++ b/apps/designer/app/canvas/shared/design-tokens.ts@@ -1,4 +1,4 @@-import type { DesignToken } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";import { useEffect, useRef } from "react";import { useDesignTokens } from "~/shared/nano-states";import { publish } from "~/shared/pubsub";diff --git a/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx b/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsxindex 16518e1066..67ee38b2b0 100644--- a/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx+++ b/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx@@ -16,8 +16,8 @@ import {useList,} from "@webstudio-is/design-system";import { CheckIcon, PlusIcon } from "@webstudio-is/icons";-import type { DesignToken } from "@webstudio-is/project";-import { designTokensGroups } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";+import { designTokensGroups } from "@webstudio-is/design-tokens";import { useDesignTokens } from "~/shared/nano-states";import type { Publish } from "~/shared/pubsub";// @todo this is temporary, we need to either make that collapsible reusable or copy it overdiff --git a/apps/designer/app/designer/shared/design-tokens-manager/hooks.ts b/apps/designer/app/designer/shared/design-tokens-manager/hooks.tsindex 33a5bbdf1f..344590f09e 100644--- a/apps/designer/app/designer/shared/design-tokens-manager/hooks.ts+++ b/apps/designer/app/designer/shared/design-tokens-manager/hooks.ts@@ -1,6 +1,6 @@import { useSubscribe } from "~/shared/pubsub";import { useDesignTokens } from "~/shared/nano-states";-import type { DesignToken } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";declare module "~/shared/pubsub" {export interface PubsubMap {diff --git a/apps/designer/app/designer/shared/design-tokens-manager/utils.test.ts b/apps/designer/app/designer/shared/design-tokens-manager/utils.test.tsindex 270e5ae6d5..00b81e82fe 100644--- a/apps/designer/app/designer/shared/design-tokens-manager/utils.test.ts+++ b/apps/designer/app/designer/shared/design-tokens-manager/utils.test.ts@@ -1,4 +1,4 @@-import type { DesignToken } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";import produce from "immer";import {deleteTokenMutable,diff --git a/apps/designer/app/designer/shared/design-tokens-manager/utils.ts b/apps/designer/app/designer/shared/design-tokens-manager/utils.tsindex 583abd6315..7fe9ad78f8 100644--- a/apps/designer/app/designer/shared/design-tokens-manager/utils.ts+++ b/apps/designer/app/designer/shared/design-tokens-manager/utils.ts@@ -1,5 +1,5 @@import type { Style } from "@webstudio-is/css-data";-import type { DesignToken } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";export const filterByType = (tokens: Array<DesignToken>, type: string) =>tokens.filter((token) => token.type === type);diff --git a/apps/designer/app/routes/rest/patch.ts b/apps/designer/app/routes/rest/patch.tsindex 748d694886..5c5a2fa379 100644--- a/apps/designer/app/routes/rest/patch.ts+++ b/apps/designer/app/routes/rest/patch.ts@@ -1,6 +1,7 @@import { type ActionFunction } from "@remix-run/node";import { type Build } from "@webstudio-is/project";-import { db } from "@webstudio-is/project/server";+import { db as projectDb } from "@webstudio-is/project/server";+import { db as designTokensDb } from "@webstudio-is/design-tokens/server";import { type SyncItem } from "immerhin";import { type Tree } from "@webstudio-is/react-sdk";@@ -22,13 +23,13 @@ export const action: ActionFunction = async ({ request }) => {const { namespace, patches } = change;if (namespace === "root") {- await db.tree.patch({ treeId }, patches);+ await projectDb.tree.patch({ treeId }, patches);} else if (namespace === "props") {- await db.props.patch({ treeId }, patches);+ await projectDb.props.patch({ treeId }, patches);} else if (namespace === "breakpoints") {- await db.breakpoints.patch(buildId, patches);+ await projectDb.breakpoints.patch(buildId, patches);} else if (namespace === "designTokens") {- await db.designTokens.patch(buildId, patches);+ await designTokensDb.patch(buildId, patches);} else {return { errors: `Unknown namespace "${namespace}"` };}diff --git a/apps/designer/app/shared/db/canvas.server.ts b/apps/designer/app/shared/db/canvas.server.tsindex d24c6a956c..1b0cc9d61c 100644--- a/apps/designer/app/shared/db/canvas.server.ts+++ b/apps/designer/app/shared/db/canvas.server.ts@@ -1,5 +1,6 @@import type { CanvasData, Project } from "@webstudio-is/project";-import { db } from "@webstudio-is/project/server";+import { db as projectDb } from "@webstudio-is/project/server";+import { db as designTokensDb } from "@webstudio-is/design-tokens/server";import { utils } from "@webstudio-is/project";export const loadCanvasData = async (@@ -9,8 +10,8 @@ export const loadCanvasData = async (): Promise<CanvasData | undefined> => {const build =env === "dev"- ? await db.build.loadByProjectId(project.id, "dev")- : await db.build.loadByProjectId(project.id, "prod");+ ? await projectDb.build.loadByProjectId(project.id, "dev")+ : await projectDb.build.loadByProjectId(project.id, "prod");if (build === undefined) {throw new Error("The project is not published");@@ -23,10 +24,10 @@ export const loadCanvasData = async (}const [tree, props, breakpoints, designTokens] = await Promise.all([- db.tree.loadById(page.treeId),- db.props.loadByTreeId(page.treeId),- db.breakpoints.load(build.id),- db.designTokens.load(build.id),+ projectDb.tree.loadById(page.treeId),+ projectDb.props.loadByTreeId(page.treeId),+ projectDb.breakpoints.load(build.id),+ designTokensDb.load(build.id),]);if (tree === null) {diff --git a/apps/designer/app/shared/nano-states/nano-states.ts b/apps/designer/app/shared/nano-states/nano-states.tsindex ffd6abc5a3..e2b28ee744 100644--- a/apps/designer/app/shared/nano-states/nano-states.ts+++ b/apps/designer/app/shared/nano-states/nano-states.ts@@ -5,7 +5,7 @@ import type {DragStartPayload,} from "~/canvas/shared/use-drag-drop";import type { Breakpoint } from "@webstudio-is/css-data";-import type { DesignToken } from "@webstudio-is/project";+import type { DesignToken } from "@webstudio-is/design-tokens";export const rootInstanceContainer = createValueContainer<Instance | undefineddiff --git a/packages/design-tokens/LICENSE b/packages/design-tokens/LICENSEnew file mode 100644index 0000000000..1f6edad9a7--- /dev/null+++ b/packages/design-tokens/LICENSE@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2022 Webstudio++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.diff --git a/packages/design-tokens/README.md b/packages/design-tokens/README.mdnew file mode 100644index 0000000000..867393882b--- /dev/null+++ b/packages/design-tokens/README.md@@ -0,0 +1,3 @@+# Webstudio Project++Project related functionalities.diff --git a/packages/design-tokens/jest.config.js b/packages/design-tokens/jest.config.jsnew file mode 100644index 0000000000..e7fc137533--- /dev/null+++ b/packages/design-tokens/jest.config.js@@ -0,0 +1 @@+export { default } from "@webstudio-is/jest-config";diff --git a/packages/design-tokens/package.json b/packages/design-tokens/package.jsonnew file mode 100644index 0000000000..72638febb5--- /dev/null+++ b/packages/design-tokens/package.json@@ -0,0 +1,42 @@+{+ "name": "@webstudio-is/design-tokens",+ "version": "0.1.0",+ "description": "Webstudio Design Tokens",+ "author": "Webstudio <[email protected]>",+ "homepage": "https://webstudio.is",+ "type": "module",+ "scripts": {+ "typecheck": "tsc --noEmit",+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",+ "checks": "yarn typecheck && yarn lint && yarn test",+ "dev": "build-package --watch",+ "build": "build-package",+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",+ "publish-to-npm": "bash ../../bin/publish-to-npm.sh"+ },+ "dependencies": {+ "@webstudio-is/prisma-client": "*",+ "immer": "^9.0.12",+ "zod": "^3.19.1"+ },+ "devDependencies": {+ "@webstudio-is/scripts": "*",+ "typescript": "4.7.4"+ },+ "exports": {+ ".": {+ "import": "./lib/index.js",+ "require": "./lib/cjs/index.cjs"+ },+ "./server": "./server.js"+ },+ "types": "src/index.ts",+ "files": [+ "lib/*",+ "src/*",+ "!*.test.*"+ ],+ "license": "MIT",+ "private": false,+ "sideEffects": false+}diff --git a/packages/design-tokens/server.d.ts b/packages/design-tokens/server.d.tsnew file mode 100644index 0000000000..ad6dde9958--- /dev/null+++ b/packages/design-tokens/server.d.ts@@ -0,0 +1 @@+export * from "./src/index.server";diff --git a/packages/design-tokens/server.js b/packages/design-tokens/server.jsnew file mode 100644index 0000000000..a6fbe7c12c--- /dev/null+++ b/packages/design-tokens/server.js@@ -0,0 +1 @@+export * from "./lib/index.server";diff --git a/packages/project/src/db/design-tokens.ts b/packages/design-tokens/src/db.tssimilarity index 94%rename from packages/project/src/db/design-tokens.tsrename to packages/design-tokens/src/db.tsindex bb96926a2d..016e70d74b 100644--- a/packages/project/src/db/design-tokens.ts+++ b/packages/design-tokens/src/db.ts@@ -3,7 +3,7 @@ import {prisma,} from "@webstudio-is/prisma-client";import { applyPatches, Patch } from "immer";-import { DesignToken } from "../shared/design-tokens";+import { DesignToken } from "./schema";export const load = async (buildId: DbDesignTokens["buildId"]) => {const data = await prisma.designTokens.findUnique({diff --git a/packages/project/src/shared/design-tokens/groups.ts b/packages/design-tokens/src/groups.tssimilarity index 100%rename from packages/project/src/shared/design-tokens/groups.tsrename to packages/design-tokens/src/groups.tsdiff --git a/packages/design-tokens/src/index.server.ts b/packages/design-tokens/src/index.server.tsnew file mode 100644index 0000000000..a89f5bdf70--- /dev/null+++ b/packages/design-tokens/src/index.server.ts@@ -0,0 +1,2 @@+import * as dbFunctions from "./db";+export const db = dbFunctions;diff --git a/packages/project/src/shared/design-tokens/index.ts b/packages/design-tokens/src/index.tssimilarity index 100%rename from packages/project/src/shared/design-tokens/index.tsrename to packages/design-tokens/src/index.tsdiff --git a/packages/project/src/shared/design-tokens/schema.ts b/packages/design-tokens/src/schema.tssimilarity index 92%rename from packages/project/src/shared/design-tokens/schema.tsrename to packages/design-tokens/src/schema.tsindex cd40728632..46f2d9f0eb 100644--- a/packages/project/src/shared/design-tokens/schema.ts+++ b/packages/design-tokens/src/schema.ts@@ -1,6 +1,7 @@import { z } from "zod";import { designTokensGroups } from "./groups";+// @todo this doesn't belong here https://github.com/webstudio-is/webstudio-designer/issues/544type UnionToIntersection<U> = (U extends never ? never : (arg: U) => never) extends (arg: infer I) => voiddiff --git a/packages/design-tokens/tsconfig.json b/packages/design-tokens/tsconfig.jsonnew file mode 100644index 0000000000..d2bd726a48--- /dev/null+++ b/packages/design-tokens/tsconfig.json@@ -0,0 +1,13 @@+{+ // Extends can't use node's resolution rn https://github.com/dividab/tsconfig-paths/issues/209#issuecomment-1177261091+ "extends": "../../node_modules/@webstudio-is/tsconfig/base.json",+ "include": ["src", "../../@types/**/*.d.ts"],+ "compilerOptions": {+ "module": "ES2020",+ "target": "ES2020",+ "strict": true,+ "baseUrl": ".",+ "outDir": "./lib",+ "rootDir": "./src"+ }+}diff --git a/packages/project/src/db/index.ts b/packages/project/src/db/index.tsindex f06ea6d859..0c117c9378 100644--- a/packages/project/src/db/index.ts+++ b/packages/project/src/db/index.ts@@ -3,5 +3,4 @@ import * as tree from "./tree";import * as props from "./props";import * as breakpoints from "./breakpoints";import * as build from "./build";-import * as designTokens from "./design-tokens";-export { project, tree, breakpoints, props, build, designTokens };+export { project, tree, breakpoints, props, build };diff --git a/packages/project/src/index.ts b/packages/project/src/index.tsindex 4743b857b5..cb1ae522e2 100644--- a/packages/project/src/index.ts+++ b/packages/project/src/index.ts@@ -13,5 +13,4 @@ export const utils = {export * from "./shared/styles";export * from "./db/schema";export * from "./shared/canvas-components";-export * from "./shared/design-tokens";export type { InstanceInsertionSpec } from "./shared/tree-utils";diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.jsonindex 22c3b4b798..9fc5250072 100644--- a/packages/react-sdk/package.json+++ b/packages/react-sdk/package.json@@ -35,6 +35,7 @@"@webstudio-is/generate-arg-types": "*","@webstudio-is/jest-config": "*","@webstudio-is/scripts": "*",+ "@webstudio-is/design-tokens": "*","babel-loader": "^8.2.5","esbuild": "^0.14.25","esbuild-node-externals": "^1.4.1",diff --git a/packages/react-sdk/src/tree/root.ts b/packages/react-sdk/src/tree/root.tsindex 177e3f06ad..77fbd568ee 100644--- a/packages/react-sdk/src/tree/root.ts+++ b/packages/react-sdk/src/tree/root.ts@@ -8,11 +8,12 @@ import type { Breakpoint } from "@webstudio-is/css-data";import { registerComponents } from "../components";import { customComponents as defaultCustomComponents } from "../app/custom-components";import { setParams, type Params } from "../app/params";+import type { DesignToken } from "@webstudio-is/design-tokens";export type Data = {tree: Tree | null;breakpoints: Array<Breakpoint>;- designTokens: Array<any>;+ designTokens: Array<DesignToken>;props: Array<InstanceProps>;assets: Array<Asset>;params?: Params;