@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
@@ -25,64 +25,52 @@ module.exports = __toCommonJS(blockquote_ws_exports);
25
25
  var import_icons = require("@webstudio-is/icons");
26
26
  var import_blockquote = require("./__generated__/blockquote.props");
27
27
  const presetStyle = {
28
- blockquote: {
29
- marginTop: {
30
- type: "unit",
31
- value: 0,
32
- unit: "number"
28
+ blockquote: [
29
+ {
30
+ property: "marginTop",
31
+ value: { type: "unit", value: 0, unit: "number" }
33
32
  },
34
- marginRight: {
35
- type: "unit",
36
- value: 0,
37
- unit: "number"
33
+ {
34
+ property: "marginRight",
35
+ value: { type: "unit", value: 0, unit: "number" }
38
36
  },
39
- marginBottom: {
40
- type: "unit",
41
- value: 10,
42
- unit: "px"
37
+ {
38
+ property: "marginBottom",
39
+ value: { type: "unit", value: 10, unit: "px" }
43
40
  },
44
- marginLeft: {
45
- type: "unit",
46
- value: 0,
47
- unit: "number"
41
+ {
42
+ property: "marginLeft",
43
+ value: { type: "unit", value: 0, unit: "number" }
48
44
  },
49
- paddingTop: {
50
- type: "unit",
51
- value: 10,
52
- unit: "px"
45
+ {
46
+ property: "paddingTop",
47
+ value: { type: "unit", value: 10, unit: "px" }
53
48
  },
54
- paddingBottom: {
55
- type: "unit",
56
- value: 10,
57
- unit: "px"
49
+ {
50
+ property: "paddingBottom",
51
+ value: { type: "unit", value: 10, unit: "px" }
58
52
  },
59
- paddingLeft: {
60
- type: "unit",
61
- value: 20,
62
- unit: "px"
53
+ {
54
+ property: "paddingLeft",
55
+ value: { type: "unit", value: 20, unit: "px" }
63
56
  },
64
- paddingRight: {
65
- type: "unit",
66
- value: 20,
67
- unit: "px"
57
+ {
58
+ property: "paddingRight",
59
+ value: { type: "unit", value: 20, unit: "px" }
68
60
  },
69
- borderLeftWidth: {
70
- type: "unit",
71
- value: 5,
72
- unit: "px"
61
+ {
62
+ property: "borderLeftWidth",
63
+ value: { type: "unit", value: 5, unit: "px" }
73
64
  },
74
- borderLeftStyle: {
75
- type: "keyword",
76
- value: "solid"
65
+ {
66
+ property: "borderLeftStyle",
67
+ value: { type: "keyword", value: "solid" }
77
68
  },
78
- borderLeftColor: {
79
- type: "rgb",
80
- r: 226,
81
- g: 226,
82
- b: 226,
83
- alpha: 1
69
+ {
70
+ property: "borderLeftColor",
71
+ value: { type: "rgb", r: 226, g: 226, b: 226, alpha: 1 }
84
72
  }
85
- }
73
+ ]
86
74
  };
87
75
  const meta = {
88
76
  category: "typography",
@@ -90,7 +78,7 @@ const meta = {
90
78
  label: "Blockquote",
91
79
  Icon: import_icons.BlockquoteIcon,
92
80
  presetStyle,
93
- children: ["Blockquote you can edit"]
81
+ children: [{ type: "text", value: "Blockquote you can edit" }]
94
82
  };
95
83
  const propsMeta = {
96
84
  props: import_blockquote.props
@@ -26,28 +26,31 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_normalize = require("../css/normalize");
27
27
  var import_body = require("./__generated__/body.props");
28
28
  const presetStyle = {
29
- body: {
29
+ body: [
30
30
  ...import_normalize.body,
31
- minHeight: {
32
- type: "unit",
33
- unit: "%",
34
- value: 100
31
+ {
32
+ property: "minHeight",
33
+ value: { type: "unit", unit: "%", value: 100 }
35
34
  },
36
- fontFamily: {
37
- type: "keyword",
38
- value: "Arial"
35
+ {
36
+ property: "fontFamily",
37
+ value: { type: "keyword", value: "Arial" }
39
38
  },
40
- fontSize: {
41
- type: "unit",
42
- unit: "px",
43
- value: 14
39
+ {
40
+ property: "fontSize",
41
+ value: { type: "unit", unit: "px", value: 14 }
44
42
  },
45
- lineHeight: {
46
- type: "unit",
47
- unit: "number",
48
- value: 1.5
43
+ {
44
+ property: "lineHeight",
45
+ value: { type: "unit", unit: "number", value: 1.5 }
46
+ },
47
+ // temporary set root color
48
+ // until builder start to fallback "inherit" to black
49
+ {
50
+ property: "color",
51
+ value: { type: "keyword", value: "black" }
49
52
  }
50
- }
53
+ ]
51
54
  };
52
55
  const meta = {
53
56
  type: "container",
@@ -23,8 +23,8 @@ __export(button_ws_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(button_ws_exports);
25
25
  var import_icons = require("@webstudio-is/icons");
26
- var import_button = require("./__generated__/button.props");
27
26
  var import_normalize = require("../css/normalize");
27
+ var import_button = require("./__generated__/button.props");
28
28
  const presetStyle = {
29
29
  button: import_normalize.button
30
30
  };
@@ -26,38 +26,30 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_code = require("./code");
27
27
  var import_code2 = require("./__generated__/code.props");
28
28
  var import_normalize = require("../css/normalize");
29
- const display = {
30
- type: "var",
31
- value: import_code.displayVarNamespace,
32
- fallbacks: [
33
- {
34
- type: "keyword",
35
- value: "inline-block"
36
- }
37
- ]
38
- };
39
29
  const presetStyle = {
40
- code: {
30
+ code: [
41
31
  ...import_normalize.code,
42
- display,
43
- paddingLeft: {
44
- type: "unit",
45
- value: 0.2,
46
- unit: "em"
32
+ {
33
+ property: "display",
34
+ value: {
35
+ type: "var",
36
+ value: import_code.displayVarNamespace,
37
+ fallbacks: [{ type: "keyword", value: "inline-block" }]
38
+ }
47
39
  },
48
- paddingRight: {
49
- type: "unit",
50
- value: 0.2,
51
- unit: "em"
40
+ {
41
+ property: "paddingLeft",
42
+ value: { type: "unit", value: 0.2, unit: "em" }
52
43
  },
53
- backgroundColor: {
54
- type: "rgb",
55
- r: 238,
56
- g: 238,
57
- b: 238,
58
- alpha: 1
44
+ {
45
+ property: "paddingRight",
46
+ value: { type: "unit", value: 0.2, unit: "em" }
47
+ },
48
+ {
49
+ property: "backgroundColor",
50
+ value: { type: "rgb", r: 238, g: 238, b: 238, alpha: 1 }
59
51
  }
60
- }
52
+ ]
61
53
  };
62
54
  const meta = {
63
55
  category: "general",
@@ -65,7 +57,7 @@ const meta = {
65
57
  label: "Code",
66
58
  Icon: import_icons.CodeIcon,
67
59
  presetStyle,
68
- children: ["Code you can edit"]
60
+ children: [{ type: "text", value: "Code you can edit" }]
69
61
  };
70
62
  const propsMeta = {
71
63
  props: import_code2.props,
@@ -24,6 +24,7 @@ __export(component_meta_exports, {
24
24
  module.exports = __toCommonJS(component_meta_exports);
25
25
  var import_zod = require("zod");
26
26
  var import_generate_arg_types = require("@webstudio-is/generate-arg-types");
27
+ var import_embed_template = require("../embed-template");
27
28
  const WsComponentPropsMeta = import_zod.z.object({
28
29
  props: import_zod.z.record(import_generate_arg_types.PropMeta),
29
30
  initialProps: import_zod.z.array(import_zod.z.string()).optional()
@@ -56,5 +57,5 @@ const WsComponentMeta = import_zod.z.object({
56
57
  Icon: import_zod.z.function(),
57
58
  presetStyle: import_zod.z.optional(import_zod.z.any()),
58
59
  states: import_zod.z.optional(import_zod.z.array(ComponentState)),
59
- children: import_zod.z.optional(import_zod.z.array(import_zod.z.string()))
60
+ children: import_zod.z.optional(import_embed_template.WsEmbedTemplate)
60
61
  });
@@ -26,21 +26,28 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_normalize = require("../css/normalize");
27
27
  var import_form = require("./__generated__/form.props");
28
28
  const presetStyle = {
29
- form: {
29
+ form: [
30
30
  ...import_normalize.form,
31
- minHeight: {
32
- type: "unit",
33
- unit: "px",
34
- value: 20
31
+ {
32
+ property: "minHeight",
33
+ value: { type: "unit", unit: "px", value: 20 }
35
34
  }
36
- }
35
+ ]
37
36
  };
38
37
  const meta = {
39
38
  category: "forms",
40
39
  type: "container",
41
40
  label: "Form",
42
41
  Icon: import_icons.FormIcon,
43
- presetStyle
42
+ presetStyle,
43
+ children: [
44
+ { type: "instance", component: "Input", children: [] },
45
+ {
46
+ type: "instance",
47
+ component: "Button",
48
+ children: [{ type: "text", value: "Submit" }]
49
+ }
50
+ ]
44
51
  };
45
52
  const propsMeta = {
46
53
  props: import_form.props
@@ -38,7 +38,7 @@ const meta = {
38
38
  type: "rich-text",
39
39
  label: "Heading",
40
40
  Icon: import_icons.HeadingIcon,
41
- children: ["Heading you can edit"],
41
+ children: [{ type: "text", value: "Heading you can edit" }],
42
42
  presetStyle
43
43
  };
44
44
  const propsMeta = {
@@ -26,21 +26,20 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_normalize = require("../css/normalize");
27
27
  var import_image = require("./__generated__/image.props");
28
28
  const presetStyle = {
29
- img: {
29
+ img: [
30
30
  ...import_normalize.img,
31
31
  // Otherwise on new image insert onto canvas it can overfit screen size multiple times
32
- maxWidth: {
33
- type: "unit",
34
- unit: "%",
35
- value: 100
32
+ {
33
+ property: "maxWidth",
34
+ value: { type: "unit", unit: "%", value: 100 }
36
35
  },
37
36
  // inline | inline-block is not suitable because without line-height: 0 on the parent you get unsuitable spaces/margins
38
37
  // see https://stackoverflow.com/questions/24771194/is-the-margin-of-inline-block-4px-is-static-for-all-browsers
39
- display: {
40
- type: "keyword",
41
- value: "block"
38
+ {
39
+ property: "display",
40
+ value: { type: "keyword", value: "block" }
42
41
  }
43
- }
42
+ ]
44
43
  };
45
44
  const meta = {
46
45
  category: "media",
@@ -26,13 +26,13 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_italic = require("./__generated__/italic.props");
27
27
  var import_normalize = require("../css/normalize");
28
28
  const presetStyle = {
29
- i: {
29
+ i: [
30
30
  ...import_normalize.i,
31
- fontStyle: {
32
- type: "keyword",
33
- value: "italic"
31
+ {
32
+ property: "fontStyle",
33
+ value: { type: "keyword", value: "italic" }
34
34
  }
35
- }
35
+ ]
36
36
  };
37
37
  const meta = {
38
38
  type: "rich-text-child",
@@ -27,13 +27,13 @@ var import_link_block = require("./__generated__/link-block.props");
27
27
  var import_link = require("./link.ws");
28
28
  var import_normalize = require("../css/normalize");
29
29
  const presetStyle = {
30
- a: {
30
+ a: [
31
31
  ...import_normalize.a,
32
- display: {
33
- type: "keyword",
34
- value: "inline-block"
32
+ {
33
+ property: "display",
34
+ value: { type: "keyword", value: "inline-block" }
35
35
  }
36
- }
36
+ ]
37
37
  };
38
38
  const meta = {
39
39
  category: "general",
@@ -26,18 +26,17 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_normalize = require("../css/normalize");
27
27
  var import_link = require("./__generated__/link.props");
28
28
  const presetStyle = {
29
- a: {
29
+ a: [
30
30
  ...import_normalize.a,
31
- minHeight: {
32
- type: "unit",
33
- unit: "em",
34
- value: 1
31
+ {
32
+ property: "minHeight",
33
+ value: { type: "unit", unit: "em", value: 1 }
35
34
  },
36
- display: {
37
- type: "keyword",
38
- value: "inline-block"
35
+ {
36
+ property: "display",
37
+ value: { type: "keyword", value: "inline-block" }
39
38
  }
40
- }
39
+ ]
41
40
  };
42
41
  const meta = {
43
42
  category: "general",
@@ -46,7 +45,7 @@ const meta = {
46
45
  Icon: import_icons.LinkIcon,
47
46
  presetStyle,
48
47
  states: [{ selector: "[aria-current=page]", label: "Current page" }],
49
- children: ["Link text you can edit"]
48
+ children: [{ type: "text", value: "Link text you can edit" }]
50
49
  };
51
50
  const propsMeta = {
52
51
  props: {
@@ -33,7 +33,7 @@ const meta = {
33
33
  type: "rich-text",
34
34
  label: "List Item",
35
35
  Icon: import_icons.ListItemIcon,
36
- children: ["List Item you can edit"],
36
+ children: [{ type: "text", value: "List Item you can edit" }],
37
37
  presetStyle
38
38
  };
39
39
  const propsMeta = {
@@ -26,36 +26,36 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_list = require("./__generated__/list.props");
27
27
  var import_normalize = require("../css/normalize");
28
28
  const presetStyle = {
29
- ol: {
29
+ ol: [
30
30
  ...import_normalize.ol,
31
- marginTop: {
32
- type: "keyword",
33
- value: "0"
31
+ {
32
+ property: "marginTop",
33
+ value: { type: "keyword", value: "0" }
34
34
  },
35
- marginBottom: {
36
- type: "keyword",
37
- value: "10px"
35
+ {
36
+ property: "marginBottom",
37
+ value: { type: "keyword", value: "10px" }
38
38
  },
39
- paddingLeft: {
40
- type: "keyword",
41
- value: "40px"
39
+ {
40
+ property: "paddingLeft",
41
+ value: { type: "keyword", value: "40px" }
42
42
  }
43
- },
44
- ul: {
43
+ ],
44
+ ul: [
45
45
  ...import_normalize.ul,
46
- marginTop: {
47
- type: "keyword",
48
- value: "0"
46
+ {
47
+ property: "marginTop",
48
+ value: { type: "keyword", value: "0" }
49
49
  },
50
- marginBottom: {
51
- type: "keyword",
52
- value: "10px"
50
+ {
51
+ property: "marginBottom",
52
+ value: { type: "keyword", value: "10px" }
53
53
  },
54
- paddingLeft: {
55
- type: "keyword",
56
- value: "40px"
54
+ {
55
+ property: "paddingLeft",
56
+ value: { type: "keyword", value: "40px" }
57
57
  }
58
- }
58
+ ]
59
59
  };
60
60
  const meta = {
61
61
  category: "typography",
@@ -33,7 +33,7 @@ const meta = {
33
33
  type: "rich-text",
34
34
  label: "Paragraph",
35
35
  Icon: import_icons.TextAlignLeftIcon,
36
- children: ["Pragraph you can edit"],
36
+ children: [{ type: "text", value: "Pragraph you can edit" }],
37
37
  presetStyle
38
38
  };
39
39
  const propsMeta = {
@@ -26,33 +26,33 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_separator = require("./__generated__/separator.props");
27
27
  var import_normalize = require("../css/normalize");
28
28
  const presetStyle = {
29
- hr: {
29
+ hr: [
30
30
  ...import_normalize.hr,
31
- height: {
32
- type: "keyword",
33
- value: "1px"
31
+ {
32
+ property: "height",
33
+ value: { type: "keyword", value: "1px" }
34
34
  },
35
- backgroundColor: {
36
- type: "keyword",
37
- value: "gray"
35
+ {
36
+ property: "backgroundColor",
37
+ value: { type: "keyword", value: "gray" }
38
38
  },
39
- borderTopStyle: {
40
- type: "keyword",
41
- value: "none"
39
+ {
40
+ property: "borderTopStyle",
41
+ value: { type: "keyword", value: "none" }
42
42
  },
43
- borderRightStyle: {
44
- type: "keyword",
45
- value: "none"
43
+ {
44
+ property: "borderRightStyle",
45
+ value: { type: "keyword", value: "none" }
46
46
  },
47
- borderLeftStyle: {
48
- type: "keyword",
49
- value: "none"
47
+ {
48
+ property: "borderLeftStyle",
49
+ value: { type: "keyword", value: "none" }
50
50
  },
51
- borderBottomStyle: {
52
- type: "keyword",
53
- value: "none"
51
+ {
52
+ property: "borderBottomStyle",
53
+ value: { type: "keyword", value: "none" }
54
54
  }
55
- }
55
+ ]
56
56
  };
57
57
  const meta = {
58
58
  category: "general",
@@ -26,14 +26,13 @@ var import_icons = require("@webstudio-is/icons");
26
26
  var import_text_block = require("./__generated__/text-block.props");
27
27
  var import_normalize = require("../css/normalize");
28
28
  const presetStyle = {
29
- div: {
29
+ div: [
30
30
  ...import_normalize.div,
31
- minHeight: {
32
- type: "unit",
33
- unit: "em",
34
- value: 1
31
+ {
32
+ property: "minHeight",
33
+ value: { type: "unit", unit: "em", value: 1 }
35
34
  }
36
- }
35
+ ]
37
36
  };
38
37
  const meta = {
39
38
  category: "typography",
@@ -41,7 +40,7 @@ const meta = {
41
40
  label: "Text Block",
42
41
  Icon: import_icons.TextBlockIcon,
43
42
  presetStyle,
44
- children: ["Block of text you can edit"]
43
+ children: [{ type: "text", value: "Block of text you can edit" }]
45
44
  };
46
45
  const propsMeta = {
47
46
  props: import_text_block.props
@@ -64,15 +64,12 @@ const generateCssText = (data, options) => {
64
64
  for (const component of (0, import_components_utils.getComponentNames)()) {
65
65
  const meta = (0, import_components.getComponentMeta)(component);
66
66
  const presetStyle = meta?.presetStyle;
67
- if (presetStyle !== void 0) {
68
- for (const [tag, style] of Object.entries(presetStyle)) {
69
- engine.addStyleRule(
70
- `${tag}:where([${import_tree.componentAttribute}=${component}])`,
71
- {
72
- style
73
- }
74
- );
75
- }
67
+ if (presetStyle === void 0) {
68
+ continue;
69
+ }
70
+ const rules = (0, import_style_rules.getPresetStyleRules)(component, presetStyle);
71
+ for (const [selector, style] of rules) {
72
+ engine.addStyleRule(selector, { style });
76
73
  }
77
74
  }
78
75
  const styleRules = (0, import_style_rules.getStyleRules)(styles, styleSourceSelections);