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
Primitive tokens (#507)
Oleg Isonen4c8989784b77
diff --git a/apps/designer/app/canvas/shared/immerhin.ts b/apps/designer/app/canvas/shared/immerhin.tsindex da576cdbdb..d9f5e355a1 100644--- a/apps/designer/app/canvas/shared/immerhin.ts+++ b/apps/designer/app/canvas/shared/immerhin.ts@@ -3,10 +3,12 @@ import store from "immerhin";import {rootInstanceContainer,breakpointsContainer,+ designTokensContainer,} from "~/shared/nano-states";export const registerContainers = () => {store.register("breakpoints", breakpointsContainer);store.register("root", rootInstanceContainer);store.register("props", allUserPropsContainer);+ store.register("designTokens", designTokensContainer);};diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.tsindex 4391ce93eb..9e7fac2c34 100644--- a/apps/designer/app/canvas/shared/styles.ts+++ b/apps/designer/app/canvas/shared/styles.ts@@ -2,7 +2,11 @@ import store from "immerhin";import { useSubscribe } from "~/shared/pubsub";import { addGlobalRules, utils } from "@webstudio-is/project";import { useSelectedInstance } from "./nano-states";-import { rootInstanceContainer } from "~/shared/nano-states";+import {+ designTokensContainer,+ rootInstanceContainer,+ useDesignTokens,+} from "~/shared/nano-states";import { idAttribute } from "@webstudio-is/react-sdk";import {validStaticValueTypes,@@ -22,6 +26,10 @@ import {} from "@webstudio-is/css-engine";import { useIsomorphicLayoutEffect } from "react-use";import type { Asset } from "@webstudio-is/asset-uploader";+import {+ tokensToStyle,+ updateOrAddTokenMutable,+} from "~/designer/shared/design-tokens-manager";const cssEngine = createCssEngine();@@ -53,27 +61,48 @@ const helperStyles = [];export const useManageDesignModeStyles = () => {+ useUpdateTokens();useUpdateStyle();usePreviewStyle();useRemoveSsrStyles();};-const globalStylesCssEngine = createCssEngine();+const helpersCssEngine = createCssEngine();+const fontsAndDefaultsCssEngine = createCssEngine();+const tokensCssEngine = createCssEngine();export const GlobalStyles = ({ assets }: { assets: Array<Asset> }) => {useIsomorphicLayoutEffect(() => {- globalStylesCssEngine.clear();+ for (const style of helperStyles) {+ helpersCssEngine.addPlaintextRule(style);+ }+ if (typeof document !== "undefined") {+ helpersCssEngine.render();+ }+ }, []);- addGlobalRules(globalStylesCssEngine, { assets });+ useIsomorphicLayoutEffect(() => {+ fontsAndDefaultsCssEngine.clear();+ addGlobalRules(fontsAndDefaultsCssEngine, { assets });+ if (typeof document !== "undefined") {+ fontsAndDefaultsCssEngine.render();+ }+ }, [assets]);- for (const style of helperStyles) {- globalStylesCssEngine.addPlaintextRule(style);+ const [tokens] = useDesignTokens();++ useIsomorphicLayoutEffect(() => {+ tokensCssEngine.clear();+ if (tokens.length !== 0) {+ const style = tokensToStyle(tokens);+ tokensCssEngine.addStyleRule(`:root`, { style });}if (typeof document !== "undefined") {- globalStylesCssEngine.render();+ tokensCssEngine.render();}- });+ }, [tokens]);+return null;};@@ -190,6 +219,14 @@ const useUpdateStyle = () => {});};+const useUpdateTokens = () => {+ useSubscribe("updateToken", (updatedToken) => {+ store.createTransaction([designTokensContainer], (tokens) => {+ updateOrAddTokenMutable(tokens, updatedToken);+ });+ });+};+const usePreviewStyle = () => {useSubscribe("previewStyle", ({ id, updates, breakpoint }) => {if (getRule(id, breakpoint.id) === undefined) {diff --git a/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsx b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsxnew file mode 100644index 0000000000..36b9d439b8--- /dev/null+++ b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsx@@ -0,0 +1,25 @@+import { TokensIcon } from "@webstudio-is/icons";+import { DesignTokensManager } from "~/designer/shared/design-tokens-manager";+import type { Publish } from "~/shared/pubsub";+import { TabName } from "../../types";+import { Header, CloseButton } from "../../lib/header";++export const TabContent = ({+ onSetActiveTab,+ publish,+}: {+ onSetActiveTab: (tabName: TabName) => void;+ publish: Publish;+}) => {+ return (+ <>+ <Header+ title="Design Tokens"+ suffix={<CloseButton onClick={() => onSetActiveTab("none")} />}+ />+ <DesignTokensManager publish={publish} />+ </>+ );+};++export const icon = <TokensIcon />;diff --git a/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.ts b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.tsnew file mode 100644index 0000000000..531913bc9a--- /dev/null+++ b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.ts@@ -0,0 +1 @@+export * from "./design-tokens";diff --git a/apps/designer/app/designer/features/sidebar-left/panels/index.ts b/apps/designer/app/designer/features/sidebar-left/panels/index.tsindex 72410a298c..8fcdad47d3 100644--- a/apps/designer/app/designer/features/sidebar-left/panels/index.ts+++ b/apps/designer/app/designer/features/sidebar-left/panels/index.ts@@ -2,5 +2,12 @@ import * as components from "./components";import * as navigator from "./navigator";import * as assets from "./assets";import * as pages from "./pages";+import * as designTokens from "./design-tokens";-export const panels = { components, navigator, assets, pages } as const;+export const panels = {+ components,+ navigator,+ assets,+ pages,+ designTokens,+} as const;diff --git a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsxindex e52f4ae750..7a86f14ec5 100644--- a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx+++ b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx@@ -35,6 +35,8 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {const enabledPanels = (Object.keys(panels) as Array<TabName>).filter((panel) => {switch (panel) {+ case "designTokens":+ return isFeatureEnabled("designTokens");case "assets":return isFeatureEnabled("assets");case "navigator":diff --git a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts b/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.tsindex 62e7202223..67810914af 100644--- a/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts+++ b/apps/designer/app/designer/features/style-panel/shared/get-inherited-style.ts@@ -10,10 +10,12 @@ export type InheritedStyle = {};type InheritableProperties = { [property in StyleProperty]: true };-const propertyNames = Object.keys(properties) as Array<StyleProperty>;+// Object keys should give `keyof typeof ...` but now it gives string[]+const propertyNames = Object.keys(properties) as (keyof typeof properties)[];// All inheritable properties we supportconst inheritableProperties: InheritableProperties = propertyNames.reduce(- (acc: InheritableProperties, property: StyleProperty) => {+ (acc: InheritableProperties, property) => {+ // @todoconst config = properties[property];if (config.inherited) {acc[property as StyleProperty] = true;diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.tsindex e24e632ddf..942716ed3c 100644--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts@@ -1,6 +1,6 @@import { useState, useMemo, useEffect, useCallback } from "react";import type { SelectedInstanceData, StyleUpdates } from "@webstudio-is/project";-import type { StyleProperty } from "@webstudio-is/css-data";+import type { Style, StyleProperty } from "@webstudio-is/css-data";import { type Publish } from "~/shared/pubsub";import { useSelectedBreakpoint } from "~/designer/shared/nano-states";import { parseCssValue } from "./parse-css-value";@@ -46,7 +46,7 @@ export const useStyleData = ({[selectedInstanceData?.cssRules, selectedBreakpoint]);- const getCurrentStyle = useCallback(+ const getCurrentStyle = useCallback<() => Style>(() => ({...selectedInstanceData?.browserStyle,...cssRule?.style,@@ -135,6 +135,7 @@ export const useStyleData = ({publishUpdates("update", updates);const nextStyle = updates.reduce((currentStyle, { property, value }) => {+ // @todocurrentStyle[property] = value;return currentStyle;},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.tsxnew file mode 100644index 0000000000..159ae5fee5--- /dev/null+++ b/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx@@ -0,0 +1,186 @@+import {+ Button,+ Flex,+ InputErrorsTooltip,+ Label,+ Popover,+ PopoverContent,+ PopoverHeader,+ PopoverPortal,+ PopoverTrigger,+ TextArea,+ TextField,+} from "@webstudio-is/design-system";+import { PlusIcon } from "@webstudio-is/icons";+import { type FormEvent, useState, useEffect } from "react";+import { useDesignTokens } from "~/shared/nano-states";+import type { Publish } from "~/shared/pubsub";+import { CollapsibleSection } from "../inspector";+import { groups } from "./groups";+import type { DesignToken } from "./schema";+import { filterByType, findByName } from "./utils";++declare module "~/shared/pubsub" {+ export interface PubsubMap {+ updateToken: DesignToken;+ }+}++const validate = (+ tokens: Array<DesignToken>,+ data: Partial<DesignToken>+): { name: Array<string>; value: Array<string>; hasErrors: boolean } => {+ const name = [];+ const value = [];++ if (String(data.name).trim() === "") name.push("Name is required");+ if (findByName(tokens, data?.name)) name.push("Name is already taken");+ if (String(data.value).trim() === "") value.push("Value is required");++ return {+ name,+ value,+ hasErrors: name.length !== 0 || value.length !== 0,+ };+};++const initialErrors = {+ name: [],+ value: [],+ hasErrors: false,+};++const getData = (event: FormEvent<HTMLFormElement>) => {+ const formData = new FormData(event.currentTarget);+ return Object.fromEntries(formData);+};++const TokenEditor = ({+ group,+ name,+ type,+ onChangeComplete,+}: {+ group: string;+ type: string;+ name?: string;+ onChangeComplete: (token: DesignToken) => void;+}) => {+ const [tokens] = useDesignTokens();+ const [isOpen, setIsOpen] = useState(false);+ const [errors, setErrors] =+ useState<ReturnType<typeof validate>>(initialErrors);+ const isNew = name === undefined;++ useEffect(() => {+ if (isOpen === false && errors.hasErrors) {+ setErrors(initialErrors);+ }+ }, [isOpen, errors.hasErrors]);++ const handleChange = (event: FormEvent<HTMLFormElement>) => {+ if (errors.hasErrors === false) return;+ const data = getData(event);+ const nextErrors = validate(tokens, data);+ setErrors(nextErrors);+ };++ const handleSubmit = (event: FormEvent<HTMLFormElement>) => {+ event.preventDefault();+ const data = getData(event);+ const nextErrors = validate(tokens, data);+ setErrors(nextErrors);++ if (nextErrors.hasErrors === false) {+ onChangeComplete({ ...data, group, type } as DesignToken);+ setIsOpen(false);+ }+ };++ return (+ <Popover modal open={isOpen} onOpenChange={setIsOpen}>+ <PopoverTrigger+ asChild+ aria-label={isNew ? "Create Token" : "Edit Token"}+ >+ <Button+ ghost+ onClick={(event) => {+ event.preventDefault();+ setIsOpen(true);+ }}+ >+ <PlusIcon />+ </Button>+ </PopoverTrigger>+ <PopoverPortal>+ <PopoverContent align="end" css={{ zIndex: "$zIndices$1" }}>+ <form onChange={handleChange} onSubmit={handleSubmit}>+ <Flex direction="column" gap="2" css={{ padding: "$spacing$7" }}>+ <Label htmlFor="name">Name</Label>+ <InputErrorsTooltip+ errors={errors.name}+ css={{ zIndex: "$zIndices$2" }}+ >+ <TextField id="name" name="name" />+ </InputErrorsTooltip>+ <Label htmlFor="value">Value</Label>+ <InputErrorsTooltip+ errors={errors.value}+ css={{ zIndex: "$zIndices$2" }}+ >+ <TextField id="value" name="value" />+ </InputErrorsTooltip>+ <Label htmlFor="description">Description</Label>+ <TextArea id="description" name="description" />+ {isNew && (+ <Button type="submit" variant="blue">+ Create+ </Button>+ )}+ </Flex>+ </form>+ <PopoverHeader title={isNew ? "New Token" : name} />+ </PopoverContent>+ </PopoverPortal>+ </Popover>+ );+};++const TokenItem = ({ token }: { token: DesignToken }) => {+ return <div>{token.value}</div>;+};++export const DesignTokensManager = ({ publish }: { publish: Publish }) => {+ const [tokens, setTokens] = useDesignTokens();++ return (+ <>+ {groups.map(({ group, type }) => {+ return (+ <CollapsibleSection+ label={group}+ key={group}+ rightSlot={+ <TokenEditor+ group={group}+ type={type}+ onChangeComplete={(token) => {+ publish({ type: "updateToken", payload: token });+ // @todo update token when its an existing one+ setTokens([...tokens, token]);+ }}+ />+ }+ >+ <>+ {filterByType(tokens, type).map((token) => {+ return <TokenItem token={token} key={token.name} />;+ })}+ </>+ </CollapsibleSection>+ );+ })}+ </>+ );+};diff --git a/apps/designer/app/designer/shared/design-tokens-manager/groups.ts b/apps/designer/app/designer/shared/design-tokens-manager/groups.tsnew file mode 100644index 0000000000..df9de4c06c--- /dev/null+++ b/apps/designer/app/designer/shared/design-tokens-manager/groups.ts@@ -0,0 +1,19 @@+// Copied from https://docs.tokens.studio/available-tokens/available-tokens++export const groups = [+ { type: "sizing", group: "Sizing" },+ { type: "spacing", group: "Spacing" },+ { type: "color", group: "Color" },+ { type: "borderRadius", group: "Border Radius" },+ { type: "borderWidth", group: "Border Width" },+ { type: "boxShadow", group: "Box Shadow" },+ { type: "opacity", group: "Opacity" },+ { type: "fontFamilies", group: "Font Families" },+ { type: "fontSizes", group: "Font Size" },+ { type: "fontWeights", group: "Font Weight" },+ { type: "lineHeight", group: "Line Height" },+ { type: "letterSpacing", group: "Letter Spacing" },+ { type: "paragraphSpacing", group: "Paragraph Spacing" },+ { type: "textCase", group: "Text Case" },+ { type: "textDecoration", group: "Text Decoration" },+] as const;diff --git a/apps/designer/app/designer/shared/design-tokens-manager/index.ts b/apps/designer/app/designer/shared/design-tokens-manager/index.tsnew file mode 100644index 0000000000..181f36c29d--- /dev/null+++ b/apps/designer/app/designer/shared/design-tokens-manager/index.ts@@ -0,0 +1,3 @@+export * from "./design-tokens-manager";+export * from "./schema";+export { tokensToStyle, updateOrAddTokenMutable } from "./utils";diff --git a/apps/designer/app/designer/shared/design-tokens-manager/schema.ts b/apps/designer/app/designer/shared/design-tokens-manager/schema.tsnew file mode 100644index 0000000000..d720c6d6a6--- /dev/null+++ b/apps/designer/app/designer/shared/design-tokens-manager/schema.ts@@ -0,0 +1,35 @@+import { z } from "zod";+import { groups } from "./groups";++type UnionToIntersection<U> = (+ U extends never ? never : (arg: U) => never+) extends (arg: infer I) => void+ ? I+ : never;++type UnionToTuple<T> = UnionToIntersection<+ T extends never ? never : (t: T) => T+> extends (_: never) => infer W+ ? [...UnionToTuple<Exclude<T, W>>, W]+ : [];++type Type = typeof groups[number]["type"];+type Group = typeof groups[number]["group"];++// zod is super restrictive on enum type https://github.com/colinhacks/zod/issues/1118+// so we convert union to tuple here its seriously safer than any as it will break on things like+// ['a', 'b'] as UnionToTuple<Type> etc+const types = groups.map((group) => group.type) as UnionToTuple<Type>;+const groupNames = groups.map((group) => group.group) as UnionToTuple<Group>;++export const DesignToken = z.object({+ name: z.string(),+ // @todo if https://github.com/colinhacks/zod/issues/1118+ type: z.enum(types),+ value: z.string(),+ description: z.optional(z.string()),+ // @todo if https://github.com/colinhacks/zod/issues/1118+ group: z.enum(groupNames),+});++export type DesignToken = z.infer<typeof DesignToken>;diff --git a/apps/designer/app/designer/shared/design-tokens-manager/utils.ts b/apps/designer/app/designer/shared/design-tokens-manager/utils.tsnew file mode 100644index 0000000000..90a77eb240--- /dev/null+++ b/apps/designer/app/designer/shared/design-tokens-manager/utils.ts@@ -0,0 +1,31 @@+import type { Style } from "@webstudio-is/css-data";+import type { DesignToken } from "./schema";++export const filterByType = (tokens: Array<DesignToken>, type: string) =>+ tokens.filter((token) => token.type === type);++export const findByName = (tokens: Array<DesignToken>, name?: string) =>+ tokens.find((token) => token.name === name);++export const tokensToStyle = (tokens: Array<DesignToken>) => {+ const style: Style = {};+ for (const token of tokens) {+ style[`--token-${token.name}`] = {+ type: "keyword",+ value: token.value,+ };+ }+ return style;+};++export const updateOrAddTokenMutable = (+ tokens: Array<DesignToken>,+ token: DesignToken+) => {+ const found = findByName(tokens, token.name);+ if (found) {+ Object.assign(found, token);+ return;+ }+ tokens.push(token);+};diff --git a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx b/apps/designer/app/designer/shared/inspector/collapsible-section.tsxindex 12cc8c4ffd..eedb7cd8a6 100644--- a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx+++ b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx@@ -60,9 +60,9 @@ export const CollapsibleSection = ({justify="center"css={{ marginRight: "-$spacing$3", color: "$slate9" }}>+ {rightSlot}{isOpenFinal ? <ChevronLeftIcon /> : <ChevronRightIcon />}</Flex>- {rightSlot}</Flex></Collapsible.Trigger><Collapsible.Content asChild>diff --git a/apps/designer/app/shared/feature-flags/flags.ts b/apps/designer/app/shared/feature-flags/flags.tsindex 12dd85ea82..9a1c3089a9 100644--- a/apps/designer/app/shared/feature-flags/flags.ts+++ b/apps/designer/app/shared/feature-flags/flags.ts@@ -1,3 +1,3 @@export const assets = false;-export const fonts = false;+export const designTokens = false;export const example = false;diff --git a/apps/designer/app/shared/nano-states/nano-states.ts b/apps/designer/app/shared/nano-states/nano-states.tsindex 6978a660da..ec155098a5 100644--- a/apps/designer/app/shared/nano-states/nano-states.ts+++ b/apps/designer/app/shared/nano-states/nano-states.ts@@ -5,6 +5,7 @@ import type {DragStartPayload,} from "~/canvas/shared/use-drag-drop";import type { Breakpoint } from "@webstudio-is/css-data";+import { DesignToken } from "~/designer/shared/design-tokens-manager";export const rootInstanceContainer = createValueContainer<Instance | undefined@@ -49,3 +50,8 @@ const dragAndDropStateContainer = createValueContainer<DragAndDropState>({isDragging: false,});export const useDragAndDropState = () => useValue(dragAndDropStateContainer);++export const designTokensContainer = createValueContainer<Array<DesignToken>>(+ []+);+export const useDesignTokens = () => useValue(designTokensContainer);diff --git a/packages/css-data/src/schema.ts b/packages/css-data/src/schema.tsindex 97d1872450..ab96274004 100644--- a/packages/css-data/src/schema.ts+++ b/packages/css-data/src/schema.ts@@ -2,10 +2,18 @@ import { units } from "./__generated__/units";import { properties } from "./__generated__/properties";import { z } from "zod";-type Properties = typeof properties;+type Properties = typeof properties & {+ [custom: CustomProperty]: {+ appliesTo: "allElements";+ initial: string;+ inherited: boolean;+ };+};export type StyleProperty = keyof Properties;+type CustomProperty = `--${string}`;+export type AppliesTo = Properties[StyleProperty]["appliesTo"];export const Unit = z.union([z.enum(units), z.literal("number")]);@@ -75,11 +83,11 @@ export const Style = z.record(z.string(), StyleValue);export type Style = {[property in StyleProperty]?: StyleValue;-};+} & { [property: CustomProperty]: StyleValue };export const CssRule = z.object({style: Style,- breakpoint: z.string(),+ breakpoint: z.optional(z.string()),});export type CssRule = z.infer<typeof CssRule>;diff --git a/packages/css-engine/src/core/css-engine.test.ts b/packages/css-engine/src/core/css-engine.test.tsindex 6ba8452d5f..32a2bb24a5 100644--- a/packages/css-engine/src/core/css-engine.test.ts+++ b/packages/css-engine/src/core/css-engine.test.ts@@ -17,7 +17,7 @@ describe("CssEngine", () => {test("use default media rule when there is no matching one registrered", () => {engine.addStyleRule(".c", {style: style0,- breakpoint: "0",+ breakpoint: "x",});expect(engine.cssText).toMatchInlineSnapshot(`"@media all {@@ -26,7 +26,7 @@ describe("CssEngine", () => {`);engine.addStyleRule(".c1", {style: { color: { type: "keyword", value: "red" } },- breakpoint: "0",+ breakpoint: "x",});expect(engine.cssText).toMatchInlineSnapshot(`"@media all {@@ -38,7 +38,7 @@ describe("CssEngine", () => {engine.addMediaRule(mediaId, mediaRuleOptions0);engine.addStyleRule(".c1", {style: { color: { type: "keyword", value: "blue" } },- breakpoint: "0",+ breakpoint: mediaId,});// Default media query should allways be the first to have the lowest source order specificityexpect(engine.cssText).toMatchInlineSnapshot(`diff --git a/packages/css-engine/src/core/css-engine.ts b/packages/css-engine/src/core/css-engine.tsindex d68e538f30..37fa98ba19 100644--- a/packages/css-engine/src/core/css-engine.ts+++ b/packages/css-engine/src/core/css-engine.ts@@ -23,7 +23,6 @@ export class CssEngine {constructor() {this.#element = new StyleElement();this.#sheet = new StyleSheet(this.#element);- this.addMediaRule(defaultMediaRuleId);}addMediaRule(id: string, options?: MediaRuleOptions) {let mediaRule = this.#mediaRules.get(id);@@ -35,9 +34,7 @@ export class CssEngine {return mediaRule;}addStyleRule(selectorText: string, rule: CssRule) {- const mediaRule =- this.#mediaRules.get(rule.breakpoint) ??- this.#mediaRules.get(defaultMediaRuleId);+ const mediaRule = this.addMediaRule(rule.breakpoint || defaultMediaRuleId);this.#isDirty = true;const styleRule = new StyleRule(selectorText, rule.style);styleRule.onChange = this.#onChangeRule;@@ -45,14 +42,17 @@ export class CssEngine {// Should be impossible to reach.throw new Error("No media rule found");}- return mediaRule.insertRule(styleRule);+ mediaRule.insertRule(styleRule);+ return styleRule;}addPlaintextRule(cssText: string) {const rule = this.#plainRules.get(cssText);if (rule !== undefined) return rule;+ this.#isDirty = true;return this.#plainRules.set(cssText, new PlaintextRule(cssText));}addFontFaceRule(options: FontFaceOptions) {+ this.#isDirty = true;return this.#fontFaceRules.push(new FontFaceRule(options));}clear() {diff --git a/packages/css-engine/src/core/rules.ts b/packages/css-engine/src/core/rules.tsindex 59a407d329..bf1ccd49f2 100644--- a/packages/css-engine/src/core/rules.ts+++ b/packages/css-engine/src/core/rules.ts@@ -12,6 +12,11 @@ class StylePropertyMap {this.#isDirty = true;this.onChange?.();}+ clear() {+ this.#styleMap.clear();+ this.#isDirty = true;+ this.onChange?.();+ }toString() {if (this.#isDirty === false) {return this.#string;diff --git a/packages/design-system/src/components/button.tsx b/packages/design-system/src/components/button.tsxindex 32171f8d8c..31154684c6 100644--- a/packages/design-system/src/components/button.tsx+++ b/packages/design-system/src/components/button.tsx@@ -205,16 +205,10 @@ export const Button = styled("button", {waiting: {backgroundColor: "$slate4",boxShadow: "inset 0 0 0 1px $colors$slate8",- color: "transparent",- pointerEvents: "none",- "@hover": {- "&:hover": {- backgroundColor: "$slate6",- boxShadow: "inset 0 0 0 1px $colors$slate8",- },- },- "&:active": {- backgroundColor: "$slate6",+ color: "$colors$slate9",+ cursor: "wait",+ "&:hover, &:active": {+ color: "$colors$slate9",},"&:focus": {boxShadow: "inset 0 0 0 1px $colors$slate8",diff --git a/packages/design-system/src/components/text-area.tsx b/packages/design-system/src/components/text-area.tsxindex 817601156a..4b0295a779 100644--- a/packages/design-system/src/components/text-area.tsx+++ b/packages/design-system/src/components/text-area.tsx@@ -8,7 +8,6 @@ export const TextArea = styled("textarea", {margin: "0",outline: "none",padding: "$spacing$3",- width: "100%",WebkitTapHighlightColor: "rgba(0,0,0,0)",backgroundColor: "$loContrast",boxShadow: "inset 0 0 0 1px $colors$muted",diff --git a/packages/design-system/src/components/tooltip.tsx b/packages/design-system/src/components/tooltip.tsxindex 50ad81338d..ea31955db5 100644--- a/packages/design-system/src/components/tooltip.tsx+++ b/packages/design-system/src/components/tooltip.tsx@@ -86,7 +86,8 @@ export const Tooltip = React.forwardRef(function TooltipWrapper(export const InputErrorsTooltip = ({errors,children,-}: {+ ...rest+}: Omit<TooltipProps, "content"> & {errors?: string[];children: ComponentProps<typeof Tooltip>["children"];}) => {@@ -102,6 +103,7 @@ export const InputErrorsTooltip = ({// If this optimization accur, the input will remount which will cause focus loss// and current value loss.<Tooltip+ {...rest}content={content || " "}open={errors !== undefined && errors.length !== 0}side="right"diff --git a/packages/icons/src/legacy.ts b/packages/icons/src/legacy.tsindex 1cae8ef769..8d221b609d 100644--- a/packages/icons/src/legacy.ts+++ b/packages/icons/src/legacy.ts@@ -27,4 +27,5 @@ export {InfoCircledIcon,CrossCircledIcon,CheckCircledIcon,+ TokensIcon,} from "@radix-ui/react-icons";diff --git a/packages/react-sdk/src/css/get-browser-style.ts b/packages/react-sdk/src/css/get-browser-style.tsindex b38391e123..41635fbc3d 100644--- a/packages/react-sdk/src/css/get-browser-style.ts+++ b/packages/react-sdk/src/css/get-browser-style.ts@@ -1,16 +1,14 @@import { detectFont } from "detect-font";-import type {- StyleProperty,- Style,- StyleValue,- Unit,-} from "@webstudio-is/css-data";+import type { Style, StyleValue, Unit } from "@webstudio-is/css-data";import { properties, units } from "@webstudio-is/css-data";const unitRegex = new RegExp(`${units.join("|")}`);// @todo use a parser-const parseValue = (property: StyleProperty, value: string): StyleValue => {+const parseValue = (+ property: keyof typeof properties,+ value: string+): StyleValue => {const number = parseFloat(value);const parsedUnit = unitRegex.exec(value);if (value === "rgba(0, 0, 0, 0)") value = "transparent";@@ -21,7 +19,8 @@ const parseValue = (property: StyleProperty, value: string): StyleValue => {};}- if (number === 0) {+ if (number === 0 && property in properties) {+ // @todoreturn properties[property].initial;}@@ -35,7 +34,7 @@ const parseValue = (property: StyleProperty, value: string): StyleValue => {export const getBrowserStyle = (element?: Element): Style => {const browserStyle: Style = {};if (element === undefined) return browserStyle;- let knownProperty: StyleProperty;+ let knownProperty: keyof typeof properties;const computedStyle = getComputedStyle(element);for (knownProperty in properties) {if (knownProperty in computedStyle === false) continue;