@webstudio-is/react-sdk 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,7 +29,6 @@ const layout = [
29
29
  "alignItems",
30
30
  "justifyContent",
31
31
  "alignContent",
32
- "placeContent",
33
32
  "justifyItems",
34
33
  "rowGap",
35
34
  "columnGap",
@@ -56,7 +55,7 @@ const gridChild = [
56
55
  "justifySelf",
57
56
  "order"
58
57
  ];
59
- const spacing = [
58
+ const space = [
60
59
  "marginTop",
61
60
  "marginRight",
62
61
  "marginBottom",
@@ -75,6 +74,7 @@ const size = [
75
74
  "maxHeight",
76
75
  "overflow",
77
76
  "objectFit",
77
+ "objectPosition",
78
78
  "aspectRatio"
79
79
  ];
80
80
  const position = [
@@ -214,7 +214,7 @@ const categories = {
214
214
  properties: gridChild,
215
215
  moreFrom: ""
216
216
  },
217
- spacing: { label: "Spacing", properties: spacing, moreFrom: "" },
217
+ space: { label: "Space", properties: space, moreFrom: "" },
218
218
  size: { label: "Size", properties: size, moreFrom: "" },
219
219
  position: { label: "Position", properties: position, moreFrom: "" },
220
220
  typography: {
@@ -23,14 +23,15 @@ __export(get_browser_style_exports, {
23
23
  module.exports = __toCommonJS(get_browser_style_exports);
24
24
  var import_detect_font = require("detect-font");
25
25
  var import_css_data = require("@webstudio-is/css-data");
26
- const unitRegex = new RegExp(`${import_css_data.units.join("|")}`);
26
+ const unitsList = Object.values(import_css_data.units).flat();
27
+ const unitRegex = new RegExp(`${unitsList.join("|")}`);
27
28
  const parseValue = (property, value) => {
28
- const number = parseFloat(value);
29
+ const number = Number.parseFloat(value);
29
30
  const parsedUnit = unitRegex.exec(value);
30
31
  if (value === "rgba(0, 0, 0, 0)") {
31
32
  value = "transparent";
32
33
  }
33
- if (isNaN(number) || parsedUnit === null) {
34
+ if (Number.isNaN(number)) {
34
35
  return {
35
36
  type: "keyword",
36
37
  value
@@ -39,6 +40,13 @@ const parseValue = (property, value) => {
39
40
  if (number === 0 && property in import_css_data.properties) {
40
41
  return import_css_data.properties[property].initial;
41
42
  }
43
+ if (parsedUnit === null) {
44
+ return {
45
+ type: "unit",
46
+ unit: "number",
47
+ value: number
48
+ };
49
+ }
42
50
  return {
43
51
  type: "unit",
44
52
  unit: parsedUnit[0],
@@ -17,3 +17,4 @@ var db_exports = {};
17
17
  module.exports = __toCommonJS(db_exports);
18
18
  __reExport(db_exports, require("./types"), module.exports);
19
19
  __reExport(db_exports, require("./instance"), module.exports);
20
+ __reExport(db_exports, require("./style"), module.exports);
@@ -25,6 +25,7 @@ __export(instance_exports, {
25
25
  module.exports = __toCommonJS(instance_exports);
26
26
  var import_css_data = require("@webstudio-is/css-data");
27
27
  var import_zod = require("zod");
28
+ var import_components = require("../components");
28
29
  const toBaseInstance = (instance) => {
29
30
  return {
30
31
  id: instance.id,
@@ -42,7 +43,7 @@ const Instance = import_zod.z.lazy(
42
43
  () => import_zod.z.object({
43
44
  type: import_zod.z.literal("instance"),
44
45
  id: import_zod.z.string(),
45
- component: import_zod.z.string(),
46
+ component: import_zod.z.enum((0, import_components.getComponentNames)()),
46
47
  children: import_zod.z.array(import_zod.z.union([Instance, Text])),
47
48
  cssRules: import_zod.z.array(import_css_data.CssRule)
48
49
  })
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var style_exports = {};
20
+ __export(style_exports, {
21
+ PresetStyles: () => PresetStyles,
22
+ PresetStylesItem: () => PresetStylesItem,
23
+ Styles: () => Styles,
24
+ StylesItem: () => StylesItem,
25
+ findMissingPresetStyles: () => findMissingPresetStyles
26
+ });
27
+ module.exports = __toCommonJS(style_exports);
28
+ var import_zod = require("zod");
29
+ var import_css_data = require("@webstudio-is/css-data");
30
+ var import_components = require("../components");
31
+ const PresetStylesItem = import_zod.z.object({
32
+ component: import_zod.z.enum((0, import_components.getComponentNames)()),
33
+ property: import_zod.z.string(),
34
+ value: import_css_data.SharedStyleValue
35
+ });
36
+ const PresetStyles = import_zod.z.array(PresetStylesItem);
37
+ const findMissingPresetStyles = (presetStyles, components) => {
38
+ const populatedComponents = /* @__PURE__ */ new Set();
39
+ for (const style of presetStyles) {
40
+ populatedComponents.add(style.component);
41
+ }
42
+ const missingPresetStyles = [];
43
+ for (const component of components) {
44
+ if (populatedComponents.has(component)) {
45
+ continue;
46
+ }
47
+ const meta = (0, import_components.getComponentMeta)(component);
48
+ if (meta.presetStyle === void 0) {
49
+ continue;
50
+ }
51
+ for (const [property, value] of Object.entries(meta.presetStyle)) {
52
+ missingPresetStyles.push({
53
+ component,
54
+ property,
55
+ value
56
+ });
57
+ }
58
+ }
59
+ return missingPresetStyles;
60
+ };
61
+ const StylesItem = import_zod.z.object({
62
+ breakpointId: import_zod.z.string(),
63
+ instanceId: import_zod.z.string(),
64
+ property: import_zod.z.string(),
65
+ value: import_css_data.SharedStyleValue
66
+ });
67
+ const Styles = import_zod.z.array(StylesItem);
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var wrapper_component_exports = {};
20
20
  __export(wrapper_component_exports, {
21
21
  WrapperComponent: () => WrapperComponent,
22
+ componentAttribute: () => componentAttribute,
22
23
  idAttribute: () => idAttribute,
23
24
  renderWrapperComponentChildren: () => renderWrapperComponentChildren
24
25
  });
@@ -52,10 +53,16 @@ const WrapperComponent = ({
52
53
  }) => {
53
54
  const Component = (0, import_components.getComponent)(instance.component);
54
55
  const userProps = (0, import_use_user_props.useUserProps)(instance.id);
55
- const props = { ...userProps, ...rest, [idAttribute]: instance.id };
56
+ const props = {
57
+ ...userProps,
58
+ ...rest,
59
+ [idAttribute]: instance.id,
60
+ [componentAttribute]: instance.component
61
+ };
56
62
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {
57
63
  ...props,
58
64
  children: renderWrapperComponentChildren(children)
59
65
  });
60
66
  };
61
67
  const idAttribute = "data-ws-id";
68
+ const componentAttribute = "data-ws-component";
@@ -5,7 +5,6 @@ const layout = [
5
5
  "alignItems",
6
6
  "justifyContent",
7
7
  "alignContent",
8
- "placeContent",
9
8
  "justifyItems",
10
9
  "rowGap",
11
10
  "columnGap",
@@ -32,7 +31,7 @@ const gridChild = [
32
31
  "justifySelf",
33
32
  "order"
34
33
  ];
35
- const spacing = [
34
+ const space = [
36
35
  "marginTop",
37
36
  "marginRight",
38
37
  "marginBottom",
@@ -51,6 +50,7 @@ const size = [
51
50
  "maxHeight",
52
51
  "overflow",
53
52
  "objectFit",
53
+ "objectPosition",
54
54
  "aspectRatio"
55
55
  ];
56
56
  const position = [
@@ -190,7 +190,7 @@ const categories = {
190
190
  properties: gridChild,
191
191
  moreFrom: ""
192
192
  },
193
- spacing: { label: "Spacing", properties: spacing, moreFrom: "" },
193
+ space: { label: "Space", properties: space, moreFrom: "" },
194
194
  size: { label: "Size", properties: size, moreFrom: "" },
195
195
  position: { label: "Position", properties: position, moreFrom: "" },
196
196
  typography: {
@@ -1,13 +1,14 @@
1
1
  import { detectFont } from "detect-font";
2
2
  import { properties, units } from "@webstudio-is/css-data";
3
- const unitRegex = new RegExp(`${units.join("|")}`);
3
+ const unitsList = Object.values(units).flat();
4
+ const unitRegex = new RegExp(`${unitsList.join("|")}`);
4
5
  const parseValue = (property, value) => {
5
- const number = parseFloat(value);
6
+ const number = Number.parseFloat(value);
6
7
  const parsedUnit = unitRegex.exec(value);
7
8
  if (value === "rgba(0, 0, 0, 0)") {
8
9
  value = "transparent";
9
10
  }
10
- if (isNaN(number) || parsedUnit === null) {
11
+ if (Number.isNaN(number)) {
11
12
  return {
12
13
  type: "keyword",
13
14
  value
@@ -16,6 +17,13 @@ const parseValue = (property, value) => {
16
17
  if (number === 0 && property in properties) {
17
18
  return properties[property].initial;
18
19
  }
20
+ if (parsedUnit === null) {
21
+ return {
22
+ type: "unit",
23
+ unit: "number",
24
+ value: number
25
+ };
26
+ }
19
27
  return {
20
28
  type: "unit",
21
29
  unit: parsedUnit[0],
package/lib/db/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./types";
2
2
  export * from "./instance";
3
+ export * from "./style";
@@ -1,5 +1,6 @@
1
1
  import { CssRule } from "@webstudio-is/css-data";
2
2
  import { z } from "zod";
3
+ import { getComponentNames } from "../components";
3
4
  const toBaseInstance = (instance) => {
4
5
  return {
5
6
  id: instance.id,
@@ -17,7 +18,7 @@ const Instance = z.lazy(
17
18
  () => z.object({
18
19
  type: z.literal("instance"),
19
20
  id: z.string(),
20
- component: z.string(),
21
+ component: z.enum(getComponentNames()),
21
22
  children: z.array(z.union([Instance, Text])),
22
23
  cssRules: z.array(CssRule)
23
24
  })
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { SharedStyleValue } from "@webstudio-is/css-data";
3
+ import {
4
+ getComponentMeta,
5
+ getComponentNames
6
+ } from "../components";
7
+ const PresetStylesItem = z.object({
8
+ component: z.enum(getComponentNames()),
9
+ property: z.string(),
10
+ value: SharedStyleValue
11
+ });
12
+ const PresetStyles = z.array(PresetStylesItem);
13
+ const findMissingPresetStyles = (presetStyles, components) => {
14
+ const populatedComponents = /* @__PURE__ */ new Set();
15
+ for (const style of presetStyles) {
16
+ populatedComponents.add(style.component);
17
+ }
18
+ const missingPresetStyles = [];
19
+ for (const component of components) {
20
+ if (populatedComponents.has(component)) {
21
+ continue;
22
+ }
23
+ const meta = getComponentMeta(component);
24
+ if (meta.presetStyle === void 0) {
25
+ continue;
26
+ }
27
+ for (const [property, value] of Object.entries(meta.presetStyle)) {
28
+ missingPresetStyles.push({
29
+ component,
30
+ property,
31
+ value
32
+ });
33
+ }
34
+ }
35
+ return missingPresetStyles;
36
+ };
37
+ const StylesItem = z.object({
38
+ breakpointId: z.string(),
39
+ instanceId: z.string(),
40
+ property: z.string(),
41
+ value: SharedStyleValue
42
+ });
43
+ const Styles = z.array(StylesItem);
44
+ export {
45
+ PresetStyles,
46
+ PresetStylesItem,
47
+ Styles,
48
+ StylesItem,
49
+ findMissingPresetStyles
50
+ };
@@ -27,15 +27,22 @@ const WrapperComponent = ({
27
27
  }) => {
28
28
  const Component = getComponent(instance.component);
29
29
  const userProps = useUserProps(instance.id);
30
- const props = { ...userProps, ...rest, [idAttribute]: instance.id };
30
+ const props = {
31
+ ...userProps,
32
+ ...rest,
33
+ [idAttribute]: instance.id,
34
+ [componentAttribute]: instance.component
35
+ };
31
36
  return /* @__PURE__ */ jsx(Component, {
32
37
  ...props,
33
38
  children: renderWrapperComponentChildren(children)
34
39
  });
35
40
  };
36
41
  const idAttribute = "data-ws-id";
42
+ const componentAttribute = "data-ws-component";
37
43
  export {
38
44
  WrapperComponent,
45
+ componentAttribute,
39
46
  idAttribute,
40
47
  renderWrapperComponentChildren
41
48
  };
package/package.json CHANGED
@@ -1,40 +1,22 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
7
7
  "type": "module",
8
- "scripts": {
9
- "dev": "build-package --watch",
10
- "build": "build-package",
11
- "build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.json\"",
12
- "typecheck": "tsc --noEmit",
13
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
14
- "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
15
- "checks": "yarn typecheck && yarn lint && yarn test",
16
- "prepublishOnly": "yarn checks && yarn build",
17
- "storybook:run": "start-storybook -p 6006",
18
- "storybook:build": "build-storybook",
19
- "publish-to-npm": "bash ../../bin/publish-to-npm.sh"
20
- },
21
8
  "devDependencies": {
22
9
  "@babel/core": "^7.20.2",
23
10
  "@esbuild-kit/esm-loader": "^2.4.2",
24
11
  "@jest/globals": "^29.3.1",
25
- "@remix-run/node": "^1.6.4",
26
- "@remix-run/react": "^1.2.3",
27
- "@remix-run/server-runtime": "^1.2.3",
12
+ "@remix-run/node": "1.9.0",
13
+ "@remix-run/react": "1.9.0",
14
+ "@remix-run/server-runtime": "1.9.0",
28
15
  "@storybook/react": "^6.5.14",
29
16
  "@storybook/testing-library": "^0.0.11",
30
17
  "@types/node": "^17.0.21",
31
18
  "@types/react": "^17.0.24",
32
19
  "@types/react-dom": "^17.0.9",
33
- "@webstudio-is/generate-arg-types": "*",
34
- "@webstudio-is/jest-config": "*",
35
- "@webstudio-is/scripts": "*",
36
- "@webstudio-is/storybook-config": "*",
37
- "@webstudio-is/tsconfig": "*",
38
20
  "babel-loader": "^8.2.5",
39
21
  "esbuild": "^0.14.25",
40
22
  "esbuild-node-externals": "^1.4.1",
@@ -44,28 +26,33 @@
44
26
  "remix-utils": "^4.1.0",
45
27
  "tsx": "^3.9.0",
46
28
  "typescript": "4.7.4",
47
- "zod": "^3.19.1"
29
+ "zod": "^3.19.1",
30
+ "@webstudio-is/generate-arg-types": "^0.0.1",
31
+ "@webstudio-is/jest-config": "^1.0.2",
32
+ "@webstudio-is/scripts": "^0.0.0",
33
+ "@webstudio-is/storybook-config": "^0.0.0",
34
+ "@webstudio-is/tsconfig": "^1.0.1"
48
35
  },
49
36
  "peerDependencies": {
50
- "@remix-run/react": "^1.2.3",
51
- "@remix-run/server-runtime": "^1.2.3",
37
+ "@remix-run/react": "1.9.0",
38
+ "@remix-run/server-runtime": "1.9.0",
52
39
  "react": "^17.0.2",
53
40
  "react-dom": "^17.0.2",
54
41
  "remix-utils": "^4.1.0",
55
42
  "zod": "^3.19.1"
56
43
  },
57
44
  "dependencies": {
58
- "@webstudio-is/asset-uploader": "^*",
59
- "@webstudio-is/css-data": "*",
60
- "@webstudio-is/design-tokens": "*",
61
- "@webstudio-is/icons": "*",
62
- "@webstudio-is/image": "*",
63
- "@webstudio-is/prisma-client": "*",
64
45
  "detect-font": "^0.1.5",
65
46
  "immer": "^9.0.12",
66
47
  "mitt": "^3.0.0",
67
48
  "react-nano-state": "^0.4.0",
68
- "warn-once": "^0.1.1"
49
+ "warn-once": "^0.1.1",
50
+ "@webstudio-is/asset-uploader": "^0.20.0",
51
+ "@webstudio-is/css-data": "^0.20.0",
52
+ "@webstudio-is/design-tokens": "^0.20.0",
53
+ "@webstudio-is/icons": "^0.20.0",
54
+ "@webstudio-is/image": "^0.20.0",
55
+ "@webstudio-is/prisma-client": "^0.20.0"
69
56
  },
70
57
  "exports": {
71
58
  "import": "./lib/index.js",
@@ -79,5 +66,16 @@
79
66
  ],
80
67
  "license": "MIT",
81
68
  "private": false,
82
- "sideEffects": false
83
- }
69
+ "sideEffects": false,
70
+ "scripts": {
71
+ "dev": "build-package --watch",
72
+ "build": "build-package",
73
+ "build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.json\"",
74
+ "typecheck": "tsc --noEmit",
75
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
76
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
77
+ "checks": "pnpm typecheck && pnpm lint && pnpm test",
78
+ "storybook:run": "start-storybook -p 6006",
79
+ "storybook:build": "build-storybook"
80
+ }
81
+ }
@@ -10,7 +10,6 @@ const layout = [
10
10
  "justifyContent",
11
11
  "alignContent",
12
12
  // Grid
13
- "placeContent",
14
13
  "justifyItems",
15
14
  "rowGap",
16
15
  "columnGap",
@@ -40,7 +39,7 @@ const gridChild = [
40
39
  "order",
41
40
  ] as const;
42
41
 
43
- const spacing = [
42
+ const space = [
44
43
  "marginTop",
45
44
  "marginRight",
46
45
  "marginBottom",
@@ -60,6 +59,7 @@ const size = [
60
59
  "maxHeight",
61
60
  "overflow",
62
61
  "objectFit",
62
+ "objectPosition",
63
63
  "aspectRatio",
64
64
  ] as const;
65
65
 
@@ -217,7 +217,7 @@ export const categories = {
217
217
  properties: gridChild,
218
218
  moreFrom: "",
219
219
  },
220
- spacing: { label: "Spacing", properties: spacing, moreFrom: "" },
220
+ space: { label: "Space", properties: space, moreFrom: "" },
221
221
  size: { label: "Size", properties: size, moreFrom: "" },
222
222
  position: { label: "Position", properties: position, moreFrom: "" },
223
223
  typography: {
@@ -2,19 +2,20 @@ import { detectFont } from "detect-font";
2
2
  import type { Style, StyleValue, Unit } from "@webstudio-is/css-data";
3
3
  import { properties, units } from "@webstudio-is/css-data";
4
4
 
5
- const unitRegex = new RegExp(`${units.join("|")}`);
5
+ const unitsList = Object.values(units).flat();
6
+ const unitRegex = new RegExp(`${unitsList.join("|")}`);
6
7
 
7
8
  // @todo use a parser
8
9
  const parseValue = (
9
10
  property: keyof typeof properties,
10
11
  value: string
11
12
  ): StyleValue => {
12
- const number = parseFloat(value);
13
+ const number = Number.parseFloat(value);
13
14
  const parsedUnit = unitRegex.exec(value);
14
15
  if (value === "rgba(0, 0, 0, 0)") {
15
16
  value = "transparent";
16
17
  }
17
- if (isNaN(number) || parsedUnit === null) {
18
+ if (Number.isNaN(number)) {
18
19
  return {
19
20
  type: "keyword",
20
21
  value,
@@ -25,6 +26,14 @@ const parseValue = (
25
26
  return properties[property].initial;
26
27
  }
27
28
 
29
+ if (parsedUnit === null) {
30
+ return {
31
+ type: "unit",
32
+ unit: "number",
33
+ value: number,
34
+ };
35
+ }
36
+
28
37
  return {
29
38
  type: "unit",
30
39
  unit: parsedUnit[0] as Unit,
package/src/db/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./types";
2
2
  export * from "./instance";
3
+ export * from "./style";
@@ -1,6 +1,6 @@
1
1
  import { CssRule } from "@webstudio-is/css-data";
2
2
  import { z } from "zod";
3
- import { ComponentName } from "../components";
3
+ import { ComponentName, getComponentNames } from "../components";
4
4
 
5
5
  // This should be used when passing a lot of data is potentially costly.
6
6
  // For example, when passing data from an iframe.
@@ -35,14 +35,12 @@ export const Text = z.lazy(() =>
35
35
  })
36
36
  );
37
37
 
38
- export const Instance = z.lazy(
39
- () =>
40
- z.object({
41
- type: z.literal("instance"),
42
- id: z.string(),
43
- component: z.string(),
44
- children: z.array(z.union([Instance, Text])),
45
- cssRules: z.array(CssRule),
46
- })
47
- // @todo can't figure out how to make component to be z.enum(Object.keys(components))
48
- ) as z.ZodType<Instance>;
38
+ export const Instance: z.ZodType<Instance> = z.lazy(() =>
39
+ z.object({
40
+ type: z.literal("instance"),
41
+ id: z.string(),
42
+ component: z.enum(getComponentNames() as [ComponentName]),
43
+ children: z.array(z.union([Instance, Text])),
44
+ cssRules: z.array(CssRule),
45
+ })
46
+ );
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ import type { StyleProperty, StyleValue } from "@webstudio-is/css-data";
3
+ import { SharedStyleValue } from "@webstudio-is/css-data";
4
+ import {
5
+ type ComponentName,
6
+ getComponentMeta,
7
+ getComponentNames,
8
+ } from "../components";
9
+
10
+ export type PresetStylesItem = {
11
+ component: ComponentName;
12
+ property: StyleProperty;
13
+ value: StyleValue;
14
+ };
15
+
16
+ // @todo can't figure out how to make property to be enum
17
+ export const PresetStylesItem = z.object({
18
+ component: z.enum(getComponentNames() as [ComponentName]),
19
+ property: z.string(),
20
+ value: SharedStyleValue,
21
+ }) as z.ZodType<PresetStylesItem>;
22
+
23
+ export const PresetStyles = z.array(PresetStylesItem);
24
+
25
+ export type PresetStyles = z.infer<typeof PresetStyles>;
26
+
27
+ export const findMissingPresetStyles = (
28
+ presetStyles: PresetStyles,
29
+ components: ComponentName[]
30
+ ) => {
31
+ const populatedComponents = new Set();
32
+ for (const style of presetStyles) {
33
+ populatedComponents.add(style.component);
34
+ }
35
+ const missingPresetStyles: PresetStyles = [];
36
+ for (const component of components) {
37
+ if (populatedComponents.has(component)) {
38
+ continue;
39
+ }
40
+ const meta = getComponentMeta(component);
41
+ if (meta.presetStyle === undefined) {
42
+ continue;
43
+ }
44
+ for (const [property, value] of Object.entries(meta.presetStyle)) {
45
+ missingPresetStyles.push({
46
+ component,
47
+ property: property as StyleProperty,
48
+ value,
49
+ });
50
+ }
51
+ }
52
+ return missingPresetStyles;
53
+ };
54
+
55
+ export type StylesItem = {
56
+ breakpointId: string;
57
+ instanceId: string;
58
+ property: StyleProperty;
59
+ value: StyleValue;
60
+ };
61
+
62
+ // @todo can't figure out how to make property to be enum
63
+ export const StylesItem = z.object({
64
+ breakpointId: z.string(),
65
+ instanceId: z.string(),
66
+ property: z.string(),
67
+ value: SharedStyleValue,
68
+ }) as z.ZodType<StylesItem>;
69
+
70
+ export const Styles = z.array(StylesItem);
71
+
72
+ export type Styles = z.infer<typeof Styles>;
package/src/db/types.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import type { InstanceProps as DbInstanceProps } from "@webstudio-is/prisma-client";
2
2
  import type { UserProp } from "../user-props";
3
3
  import type { Instance } from "./instance";
4
+ import type { PresetStyles, Styles } from "./style";
4
5
 
5
6
  export type Tree = {
6
7
  id: string;
7
8
  root: Instance;
9
+ presetStyles: PresetStyles;
10
+ styles: Styles;
8
11
  };
9
12
 
10
13
  export type Props = {
@@ -13,6 +16,7 @@ export type Props = {
13
16
  instanceId: string;
14
17
  treeId: string;
15
18
  };
19
+
16
20
  export type InstanceProps = Omit<DbInstanceProps, "props"> & {
17
21
  props: Array<UserProp>;
18
22
  };
@@ -41,10 +41,16 @@ export const WrapperComponent = ({
41
41
  }: WrapperComponentProps) => {
42
42
  const Component = getComponent(instance.component);
43
43
  const userProps = useUserProps(instance.id);
44
- const props = { ...userProps, ...rest, [idAttribute]: instance.id };
44
+ const props = {
45
+ ...userProps,
46
+ ...rest,
47
+ [idAttribute]: instance.id,
48
+ [componentAttribute]: instance.component,
49
+ };
45
50
  return (
46
51
  <Component {...props}>{renderWrapperComponentChildren(children)}</Component>
47
52
  );
48
53
  };
49
54
 
50
55
  export const idAttribute = "data-ws-id";
56
+ export const componentAttribute = "data-ws-component";