@webstudio-is/react-sdk 0.60.0 → 0.61.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.
Files changed (83) hide show
  1. package/lib/cjs/components/blockquote.ws.js +36 -48
  2. package/lib/cjs/components/body.ws.js +20 -17
  3. package/lib/cjs/components/button.ws.js +1 -1
  4. package/lib/cjs/components/code.ws.js +20 -28
  5. package/lib/cjs/components/component-meta.js +2 -1
  6. package/lib/cjs/components/form.ws.js +14 -7
  7. package/lib/cjs/components/heading.ws.js +1 -1
  8. package/lib/cjs/components/image.ws.js +8 -9
  9. package/lib/cjs/components/italic.ws.js +5 -5
  10. package/lib/cjs/components/link-block.ws.js +5 -5
  11. package/lib/cjs/components/link.ws.js +9 -10
  12. package/lib/cjs/components/list-item.ws.js +1 -1
  13. package/lib/cjs/components/list.ws.js +22 -22
  14. package/lib/cjs/components/paragraph.ws.js +1 -1
  15. package/lib/cjs/components/separator.ws.js +20 -20
  16. package/lib/cjs/components/text-block.ws.js +6 -7
  17. package/lib/cjs/css/css.js +6 -9
  18. package/lib/cjs/css/normalize.js +166 -185
  19. package/lib/cjs/css/presets.js +14 -34
  20. package/lib/cjs/css/style-rules.js +17 -0
  21. package/lib/cjs/embed-template.js +160 -0
  22. package/lib/cjs/index.js +1 -0
  23. package/lib/components/blockquote.ws.js +36 -48
  24. package/lib/components/body.ws.js +20 -17
  25. package/lib/components/button.ws.js +1 -1
  26. package/lib/components/code.ws.js +20 -28
  27. package/lib/components/component-meta.js +2 -1
  28. package/lib/components/form.ws.js +14 -7
  29. package/lib/components/heading.ws.js +1 -1
  30. package/lib/components/image.ws.js +8 -9
  31. package/lib/components/italic.ws.js +5 -5
  32. package/lib/components/link-block.ws.js +5 -5
  33. package/lib/components/link.ws.js +9 -10
  34. package/lib/components/list-item.ws.js +1 -1
  35. package/lib/components/list.ws.js +22 -22
  36. package/lib/components/paragraph.ws.js +1 -1
  37. package/lib/components/separator.ws.js +20 -20
  38. package/lib/components/text-block.ws.js +6 -7
  39. package/lib/css/css.js +8 -11
  40. package/lib/css/normalize.js +166 -185
  41. package/lib/css/presets.js +14 -34
  42. package/lib/css/style-rules.js +17 -0
  43. package/lib/embed-template.js +140 -0
  44. package/lib/index.js +1 -0
  45. package/lib/types/components/box.stories.d.ts +2 -2
  46. package/lib/types/components/component-meta.d.ts +20 -5
  47. package/lib/types/components/components-utils.d.ts +1 -1
  48. package/lib/types/css/normalize.d.ts +8786 -2286
  49. package/lib/types/css/presets.d.ts +2 -38
  50. package/lib/types/css/style-rules.d.ts +11 -9
  51. package/lib/types/embed-template.d.ts +1725 -0
  52. package/lib/types/embed-template.test.d.ts +1 -0
  53. package/lib/types/index.d.ts +1 -0
  54. package/package.json +14 -13
  55. package/src/components/blockquote.ws.tsx +42 -52
  56. package/src/components/body.ws.tsx +26 -23
  57. package/src/components/bold.ws.tsx +6 -3
  58. package/src/components/box.ws.ts +6 -3
  59. package/src/components/button.ws.tsx +7 -4
  60. package/src/components/code.ws.tsx +26 -32
  61. package/src/components/component-meta.ts +5 -3
  62. package/src/components/form.ws.tsx +19 -9
  63. package/src/components/heading.ws.tsx +7 -4
  64. package/src/components/image.ws.tsx +14 -12
  65. package/src/components/input.ws.tsx +6 -3
  66. package/src/components/italic.ws.tsx +11 -8
  67. package/src/components/link-block.ws.tsx +11 -8
  68. package/src/components/link.ws.tsx +15 -13
  69. package/src/components/list-item.ws.tsx +7 -4
  70. package/src/components/list.ws.tsx +28 -25
  71. package/src/components/paragraph.ws.tsx +7 -4
  72. package/src/components/separator.ws.tsx +26 -25
  73. package/src/components/span.ws.tsx +6 -3
  74. package/src/components/subscript.ws.tsx +6 -3
  75. package/src/components/superscript.ws.tsx +6 -3
  76. package/src/components/text-block.ws.tsx +12 -11
  77. package/src/css/css.ts +8 -11
  78. package/src/css/normalize.ts +165 -188
  79. package/src/css/presets.ts +15 -37
  80. package/src/css/style-rules.ts +24 -0
  81. package/src/embed-template.test.ts +210 -0
  82. package/src/embed-template.ts +187 -0
  83. package/src/index.ts +1 -0
@@ -1,24 +1,26 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { LinkIcon } from "@webstudio-is/icons";
3
2
  import { a } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./link";
6
9
  import { props } from "./__generated__/link.props";
7
10
 
8
11
  const presetStyle = {
9
- a: {
12
+ a: [
10
13
  ...a,
11
- minHeight: {
12
- type: "unit",
13
- unit: "em",
14
- value: 1,
14
+ {
15
+ property: "minHeight",
16
+ value: { type: "unit", unit: "em", value: 1 },
15
17
  },
16
- display: {
17
- type: "keyword",
18
- value: "inline-block",
18
+ {
19
+ property: "display",
20
+ value: { type: "keyword", value: "inline-block" },
19
21
  },
20
- },
21
- } as const satisfies Record<typeof defaultTag, Style>;
22
+ ],
23
+ } satisfies PresetStyle<typeof defaultTag>;
22
24
 
23
25
  export const meta: WsComponentMeta = {
24
26
  category: "general",
@@ -27,7 +29,7 @@ export const meta: WsComponentMeta = {
27
29
  Icon: LinkIcon,
28
30
  presetStyle,
29
31
  states: [{ selector: "[aria-current=page]", label: "Current page" }],
30
- children: ["Link text you can edit"],
32
+ children: [{ type: "text", value: "Link text you can edit" }],
31
33
  };
32
34
 
33
35
  export const propsMeta: WsComponentPropsMeta = {
@@ -1,20 +1,23 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { ListItemIcon } from "@webstudio-is/icons";
3
2
  import { li } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./list-item";
6
9
  import { props } from "./__generated__/list-item.props";
7
10
 
8
11
  const presetStyle = {
9
12
  li,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  category: "typography",
14
17
  type: "rich-text",
15
18
  label: "List Item",
16
19
  Icon: ListItemIcon,
17
- children: ["List Item you can edit"],
20
+ children: [{ type: "text", value: "List Item you can edit" }],
18
21
  presetStyle,
19
22
  };
20
23
 
@@ -1,42 +1,45 @@
1
1
  import { ListIcon } from "@webstudio-is/icons";
2
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
2
+ import type {
3
+ PresetStyle,
4
+ WsComponentMeta,
5
+ WsComponentPropsMeta,
6
+ } from "./component-meta";
3
7
  import { props } from "./__generated__/list.props";
4
8
  import type { ListTag } from "./list";
5
- import type { Style } from "@webstudio-is/css-data";
6
9
  import { ol, ul } from "../css/normalize";
7
10
 
8
11
  const presetStyle = {
9
- ol: {
12
+ ol: [
10
13
  ...ol,
11
- marginTop: {
12
- type: "keyword",
13
- value: "0",
14
+ {
15
+ property: "marginTop",
16
+ value: { type: "keyword", value: "0" },
14
17
  },
15
- marginBottom: {
16
- type: "keyword",
17
- value: "10px",
18
+ {
19
+ property: "marginBottom",
20
+ value: { type: "keyword", value: "10px" },
18
21
  },
19
- paddingLeft: {
20
- type: "keyword",
21
- value: "40px",
22
+ {
23
+ property: "paddingLeft",
24
+ value: { type: "keyword", value: "40px" },
22
25
  },
23
- },
24
- ul: {
26
+ ],
27
+ ul: [
25
28
  ...ul,
26
- marginTop: {
27
- type: "keyword",
28
- value: "0",
29
+ {
30
+ property: "marginTop",
31
+ value: { type: "keyword", value: "0" },
29
32
  },
30
- marginBottom: {
31
- type: "keyword",
32
- value: "10px",
33
+ {
34
+ property: "marginBottom",
35
+ value: { type: "keyword", value: "10px" },
33
36
  },
34
- paddingLeft: {
35
- type: "keyword",
36
- value: "40px",
37
+ {
38
+ property: "paddingLeft",
39
+ value: { type: "keyword", value: "40px" },
37
40
  },
38
- },
39
- } as const satisfies Record<ListTag, Style>;
41
+ ],
42
+ } satisfies PresetStyle<ListTag>;
40
43
 
41
44
  export const meta: WsComponentMeta = {
42
45
  category: "typography",
@@ -1,20 +1,23 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { TextAlignLeftIcon } from "@webstudio-is/icons";
3
2
  import { p } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./paragraph";
6
9
  import { props } from "./__generated__/paragraph.props";
7
10
 
8
11
  const presetStyle = {
9
12
  p,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  category: "typography",
14
17
  type: "rich-text",
15
18
  label: "Paragraph",
16
19
  Icon: TextAlignLeftIcon,
17
- children: ["Pragraph you can edit"],
20
+ children: [{ type: "text", value: "Pragraph you can edit" }],
18
21
  presetStyle,
19
22
  };
20
23
 
@@ -1,42 +1,43 @@
1
1
  import { DashIcon } from "@webstudio-is/icons";
2
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
2
+ import type {
3
+ PresetStyle,
4
+ WsComponentMeta,
5
+ WsComponentPropsMeta,
6
+ } from "./component-meta";
3
7
  import { props } from "./__generated__/separator.props";
4
8
  import type { defaultTag } from "./separator";
5
- import type { Style } from "@webstudio-is/css-data";
6
9
  import { hr } from "../css/normalize";
7
10
 
8
11
  const presetStyle = {
9
- hr: {
12
+ hr: [
10
13
  ...hr,
11
14
 
12
- height: {
13
- type: "keyword",
14
- value: "1px",
15
+ {
16
+ property: "height",
17
+ value: { type: "keyword", value: "1px" },
15
18
  },
16
-
17
- backgroundColor: {
18
- type: "keyword",
19
- value: "gray",
19
+ {
20
+ property: "backgroundColor",
21
+ value: { type: "keyword", value: "gray" },
20
22
  },
21
-
22
- borderTopStyle: {
23
- type: "keyword",
24
- value: "none",
23
+ {
24
+ property: "borderTopStyle",
25
+ value: { type: "keyword", value: "none" },
25
26
  },
26
- borderRightStyle: {
27
- type: "keyword",
28
- value: "none",
27
+ {
28
+ property: "borderRightStyle",
29
+ value: { type: "keyword", value: "none" },
29
30
  },
30
- borderLeftStyle: {
31
- type: "keyword",
32
- value: "none",
31
+ {
32
+ property: "borderLeftStyle",
33
+ value: { type: "keyword", value: "none" },
33
34
  },
34
- borderBottomStyle: {
35
- type: "keyword",
36
- value: "none",
35
+ {
36
+ property: "borderBottomStyle",
37
+ value: { type: "keyword", value: "none" },
37
38
  },
38
- },
39
- } as const satisfies Record<typeof defaultTag, Style>;
39
+ ],
40
+ } satisfies PresetStyle<typeof defaultTag>;
40
41
 
41
42
  export const meta: WsComponentMeta = {
42
43
  category: "general",
@@ -1,13 +1,16 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { PaintBrushIcon } from "@webstudio-is/icons";
3
2
  import { span } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./span";
6
9
  import { props } from "./__generated__/span.props";
7
10
 
8
11
  const presetStyle = {
9
12
  span,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  type: "rich-text-child",
@@ -1,13 +1,16 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { SubscriptIcon } from "@webstudio-is/icons";
3
2
  import { sub } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./subscript";
6
9
  import { props } from "./__generated__/subscript.props";
7
10
 
8
11
  const presetStyle = {
9
12
  sub,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  type: "rich-text-child",
@@ -1,13 +1,16 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { SuperscriptIcon } from "@webstudio-is/icons";
3
2
  import { sup } from "../css/normalize";
4
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
5
8
  import type { defaultTag } from "./superscript";
6
9
  import { props } from "./__generated__/superscript.props";
7
10
 
8
11
  const presetStyle = {
9
12
  sup,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  type: "rich-text-child",
@@ -1,21 +1,22 @@
1
1
  import { TextBlockIcon } from "@webstudio-is/icons";
2
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
2
+ import type {
3
+ PresetStyle,
4
+ WsComponentMeta,
5
+ WsComponentPropsMeta,
6
+ } from "./component-meta";
3
7
  import { props } from "./__generated__/text-block.props";
4
8
  import type { defaultTag } from "./text-block";
5
- import type { Style } from "@webstudio-is/css-data";
6
9
  import { div } from "../css/normalize";
7
10
 
8
11
  const presetStyle = {
9
- div: {
12
+ div: [
10
13
  ...div,
11
-
12
- minHeight: {
13
- type: "unit",
14
- unit: "em",
15
- value: 1,
14
+ {
15
+ property: "minHeight",
16
+ value: { type: "unit", unit: "em", value: 1 },
16
17
  },
17
- },
18
- } as const satisfies Record<typeof defaultTag, Style>;
18
+ ],
19
+ } satisfies PresetStyle<typeof defaultTag>;
19
20
 
20
21
  export const meta: WsComponentMeta = {
21
22
  category: "typography",
@@ -23,7 +24,7 @@ export const meta: WsComponentMeta = {
23
24
  label: "Text Block",
24
25
  Icon: TextBlockIcon,
25
26
  presetStyle,
26
- children: ["Block of text you can edit"],
27
+ children: [{ type: "text", value: "Block of text you can edit" }],
27
28
  };
28
29
 
29
30
  export const propsMeta: WsComponentPropsMeta = {
package/src/css/css.ts CHANGED
@@ -3,9 +3,9 @@ import type { Asset, Assets } from "@webstudio-is/asset-uploader";
3
3
  import type { Build } from "@webstudio-is/project-build";
4
4
  import { getComponentNames } from "../components/components-utils";
5
5
  import { getComponentMeta } from "../components";
6
- import { componentAttribute, idAttribute } from "../tree";
6
+ import { idAttribute } from "../tree";
7
7
  import { addGlobalRules } from "./global-rules";
8
- import { getStyleRules } from "./style-rules";
8
+ import { getPresetStyleRules, getStyleRules } from "./style-rules";
9
9
 
10
10
  type Data = {
11
11
  assets: Asset[];
@@ -64,15 +64,12 @@ export const generateCssText = (data: Data, options: CssOptions) => {
64
64
  for (const component of getComponentNames()) {
65
65
  const meta = getComponentMeta(component);
66
66
  const presetStyle = meta?.presetStyle;
67
- if (presetStyle !== undefined) {
68
- for (const [tag, style] of Object.entries(presetStyle)) {
69
- engine.addStyleRule(
70
- `${tag}:where([${componentAttribute}=${component}])`,
71
- {
72
- style,
73
- }
74
- );
75
- }
67
+ if (presetStyle === undefined) {
68
+ continue;
69
+ }
70
+ const rules = getPresetStyleRules(component, presetStyle);
71
+ for (const [selector, style] of rules) {
72
+ engine.addStyleRule(selector, { style });
76
73
  }
77
74
  }
78
75