@webstudio-is/react-sdk 0.60.0 → 0.62.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 (233) hide show
  1. package/lib/app/custom-components/__generated__/form.props.js +412 -0
  2. package/lib/app/custom-components/__generated__/image.props.js +442 -0
  3. package/lib/app/custom-components/__generated__/link-block.props.js +432 -0
  4. package/lib/app/custom-components/__generated__/link.props.js +432 -0
  5. package/lib/app/custom-components/__generated__/rich-text-link.props.js +432 -0
  6. package/lib/app/custom-components/form.js +54 -0
  7. package/lib/app/custom-components/form.ws.js +81 -0
  8. package/lib/app/custom-components/index.js +10 -4
  9. package/lib/cjs/app/custom-components/__generated__/form.props.js +432 -0
  10. package/lib/cjs/app/custom-components/__generated__/image.props.js +462 -0
  11. package/lib/cjs/app/custom-components/__generated__/link-block.props.js +452 -0
  12. package/lib/cjs/app/custom-components/__generated__/link.props.js +452 -0
  13. package/lib/cjs/app/custom-components/__generated__/rich-text-link.props.js +452 -0
  14. package/lib/cjs/app/custom-components/form.js +70 -0
  15. package/lib/cjs/app/custom-components/form.ws.js +101 -0
  16. package/lib/cjs/app/custom-components/index.js +12 -6
  17. package/lib/cjs/components/__generated__/checkbox-field.props.js +419 -0
  18. package/lib/cjs/components/__generated__/checkbox.props.js +459 -0
  19. package/lib/cjs/components/__generated__/error-message.props.js +418 -0
  20. package/lib/cjs/components/__generated__/input.props.js +8 -3
  21. package/lib/cjs/components/__generated__/label.props.js +420 -0
  22. package/lib/cjs/components/__generated__/radio-button-field.props.js +419 -0
  23. package/lib/cjs/components/__generated__/radio-button.props.js +459 -0
  24. package/lib/cjs/components/__generated__/success-message.props.js +418 -0
  25. package/lib/cjs/components/__generated__/textarea.props.js +432 -0
  26. package/lib/cjs/components/blockquote.ws.js +36 -48
  27. package/lib/cjs/components/body.ws.js +20 -17
  28. package/lib/cjs/components/button.ws.js +8 -3
  29. package/lib/cjs/components/checkbox-field.js +29 -0
  30. package/lib/cjs/components/checkbox-field.ws.js +53 -0
  31. package/lib/cjs/components/checkbox.js +29 -0
  32. package/lib/cjs/components/checkbox.ws.js +55 -0
  33. package/lib/cjs/components/code.ws.js +20 -28
  34. package/lib/cjs/components/component-meta.js +3 -1
  35. package/lib/cjs/components/components-utils.js +9 -1
  36. package/lib/cjs/components/components.js +17 -1
  37. package/lib/cjs/components/error-message.js +29 -0
  38. package/lib/cjs/components/error-message.ws.js +40 -0
  39. package/lib/cjs/components/form.js +1 -1
  40. package/lib/cjs/components/form.ws.js +35 -9
  41. package/lib/cjs/components/heading.ws.js +1 -1
  42. package/lib/cjs/components/image.ws.js +8 -9
  43. package/lib/cjs/components/index.js +43 -2
  44. package/lib/cjs/components/input.ws.js +15 -3
  45. package/lib/cjs/components/italic.ws.js +5 -5
  46. package/lib/cjs/components/label.js +29 -0
  47. package/lib/cjs/components/label.ws.js +54 -0
  48. package/lib/cjs/components/link-block.ws.js +6 -6
  49. package/lib/cjs/components/link.ws.js +9 -10
  50. package/lib/cjs/components/list-item.ws.js +2 -1
  51. package/lib/cjs/components/list.ws.js +22 -22
  52. package/lib/cjs/components/paragraph.ws.js +1 -1
  53. package/lib/cjs/components/radio-button-field.js +29 -0
  54. package/lib/cjs/components/radio-button-field.ws.js +53 -0
  55. package/lib/cjs/components/radio-button.js +29 -0
  56. package/lib/cjs/components/radio-button.ws.js +55 -0
  57. package/lib/cjs/components/separator.ws.js +20 -20
  58. package/lib/cjs/components/success-message.js +29 -0
  59. package/lib/cjs/components/success-message.ws.js +40 -0
  60. package/lib/cjs/components/text-block.ws.js +6 -7
  61. package/lib/cjs/components/textarea.js +29 -0
  62. package/lib/cjs/components/textarea.ws.js +56 -0
  63. package/lib/cjs/css/css.js +6 -9
  64. package/lib/cjs/css/normalize.js +168 -185
  65. package/lib/cjs/css/presets.js +14 -34
  66. package/lib/cjs/css/style-rules.js +17 -0
  67. package/lib/cjs/embed-template.js +160 -0
  68. package/lib/cjs/index.js +1 -0
  69. package/lib/components/__generated__/checkbox-field.props.js +399 -0
  70. package/lib/components/__generated__/checkbox.props.js +439 -0
  71. package/lib/components/__generated__/error-message.props.js +398 -0
  72. package/lib/components/__generated__/input.props.js +8 -3
  73. package/lib/components/__generated__/label.props.js +400 -0
  74. package/lib/components/__generated__/radio-button-field.props.js +399 -0
  75. package/lib/components/__generated__/radio-button.props.js +439 -0
  76. package/lib/components/__generated__/success-message.props.js +398 -0
  77. package/lib/components/__generated__/textarea.props.js +412 -0
  78. package/lib/components/blockquote.ws.js +36 -48
  79. package/lib/components/body.ws.js +20 -17
  80. package/lib/components/button.ws.js +8 -3
  81. package/lib/components/checkbox-field.js +9 -0
  82. package/lib/components/checkbox-field.ws.js +33 -0
  83. package/lib/components/checkbox.js +9 -0
  84. package/lib/components/checkbox.ws.js +35 -0
  85. package/lib/components/code.ws.js +20 -28
  86. package/lib/components/component-meta.js +3 -1
  87. package/lib/components/components-utils.js +9 -1
  88. package/lib/components/components.js +17 -1
  89. package/lib/components/error-message.js +9 -0
  90. package/lib/components/error-message.ws.js +20 -0
  91. package/lib/components/form.js +1 -1
  92. package/lib/components/form.ws.js +35 -9
  93. package/lib/components/heading.ws.js +1 -1
  94. package/lib/components/image.ws.js +8 -9
  95. package/lib/components/index.js +43 -2
  96. package/lib/components/input.ws.js +15 -3
  97. package/lib/components/italic.ws.js +5 -5
  98. package/lib/components/label.js +9 -0
  99. package/lib/components/label.ws.js +34 -0
  100. package/lib/components/link-block.ws.js +7 -7
  101. package/lib/components/link.ws.js +9 -10
  102. package/lib/components/list-item.ws.js +2 -1
  103. package/lib/components/list.ws.js +22 -22
  104. package/lib/components/paragraph.ws.js +1 -1
  105. package/lib/components/radio-button-field.js +9 -0
  106. package/lib/components/radio-button-field.ws.js +33 -0
  107. package/lib/components/radio-button.js +9 -0
  108. package/lib/components/radio-button.ws.js +35 -0
  109. package/lib/components/separator.ws.js +20 -20
  110. package/lib/components/success-message.js +9 -0
  111. package/lib/components/success-message.ws.js +20 -0
  112. package/lib/components/text-block.ws.js +6 -7
  113. package/lib/components/textarea.js +9 -0
  114. package/lib/components/textarea.ws.js +36 -0
  115. package/lib/css/css.js +8 -11
  116. package/lib/css/normalize.js +168 -185
  117. package/lib/css/presets.js +14 -34
  118. package/lib/css/style-rules.js +17 -0
  119. package/lib/embed-template.js +140 -0
  120. package/lib/index.js +1 -0
  121. package/lib/types/app/custom-components/__generated__/form.props.d.ts +2 -0
  122. package/lib/types/app/custom-components/__generated__/image.props.d.ts +2 -0
  123. package/lib/types/app/custom-components/__generated__/link-block.props.d.ts +2 -0
  124. package/lib/types/app/custom-components/__generated__/link.props.d.ts +2 -0
  125. package/lib/types/app/custom-components/__generated__/rich-text-link.props.d.ts +2 -0
  126. package/lib/types/app/custom-components/form.d.ts +5 -0
  127. package/lib/types/app/custom-components/form.ws.d.ts +3 -0
  128. package/lib/types/app/custom-components/index.d.ts +6 -1
  129. package/lib/types/components/__generated__/checkbox-field.props.d.ts +2 -0
  130. package/lib/types/components/__generated__/checkbox.props.d.ts +2 -0
  131. package/lib/types/components/__generated__/error-message.props.d.ts +2 -0
  132. package/lib/types/components/__generated__/label.props.d.ts +2 -0
  133. package/lib/types/components/__generated__/radio-button-field.props.d.ts +2 -0
  134. package/lib/types/components/__generated__/radio-button.props.d.ts +2 -0
  135. package/lib/types/components/__generated__/success-message.props.d.ts +2 -0
  136. package/lib/types/components/__generated__/textarea.props.d.ts +2 -0
  137. package/lib/types/components/box.stories.d.ts +2 -2
  138. package/lib/types/components/checkbox-field.d.ts +3 -0
  139. package/lib/types/components/checkbox-field.ws.d.ts +3 -0
  140. package/lib/types/components/checkbox.d.ts +3 -0
  141. package/lib/types/components/checkbox.ws.d.ts +3 -0
  142. package/lib/types/components/component-meta.d.ts +23 -5
  143. package/lib/types/components/components-utils.d.ts +5 -20
  144. package/lib/types/components/components.d.ts +8 -0
  145. package/lib/types/components/error-message.d.ts +3 -0
  146. package/lib/types/components/error-message.ws.d.ts +3 -0
  147. package/lib/types/components/index.d.ts +1 -0
  148. package/lib/types/components/input.d.ts +3 -1
  149. package/lib/types/components/input.stories.d.ts +6 -2
  150. package/lib/types/components/label.d.ts +3 -0
  151. package/lib/types/components/label.ws.d.ts +3 -0
  152. package/lib/types/components/radio-button-field.d.ts +3 -0
  153. package/lib/types/components/radio-button-field.ws.d.ts +3 -0
  154. package/lib/types/components/radio-button.d.ts +3 -0
  155. package/lib/types/components/radio-button.ws.d.ts +3 -0
  156. package/lib/types/components/success-message.d.ts +3 -0
  157. package/lib/types/components/success-message.ws.d.ts +3 -0
  158. package/lib/types/components/textarea.d.ts +3 -0
  159. package/lib/types/components/textarea.ws.d.ts +3 -0
  160. package/lib/types/css/normalize.d.ts +8977 -2286
  161. package/lib/types/css/presets.d.ts +2 -38
  162. package/lib/types/css/style-rules.d.ts +11 -9
  163. package/lib/types/embed-template.d.ts +1725 -0
  164. package/lib/types/embed-template.test.d.ts +1 -0
  165. package/lib/types/index.d.ts +1 -0
  166. package/package.json +15 -14
  167. package/src/app/custom-components/__generated__/form.props.ts +457 -0
  168. package/src/app/custom-components/__generated__/image.props.ts +487 -0
  169. package/src/app/custom-components/__generated__/link-block.props.ts +477 -0
  170. package/src/app/custom-components/__generated__/link.props.ts +477 -0
  171. package/src/app/custom-components/__generated__/rich-text-link.props.ts +477 -0
  172. package/src/app/custom-components/form.tsx +94 -0
  173. package/src/app/custom-components/form.ws.tsx +86 -0
  174. package/src/app/custom-components/index.ts +9 -4
  175. package/src/components/__generated__/checkbox-field.props.ts +444 -0
  176. package/src/components/__generated__/checkbox.props.ts +484 -0
  177. package/src/components/__generated__/error-message.props.ts +443 -0
  178. package/src/components/__generated__/input.props.ts +8 -3
  179. package/src/components/__generated__/label.props.ts +445 -0
  180. package/src/components/__generated__/radio-button-field.props.ts +444 -0
  181. package/src/components/__generated__/radio-button.props.ts +484 -0
  182. package/src/components/__generated__/success-message.props.ts +443 -0
  183. package/src/components/__generated__/textarea.props.ts +457 -0
  184. package/src/components/blockquote.ws.tsx +42 -52
  185. package/src/components/body.ws.tsx +26 -23
  186. package/src/components/bold.ws.tsx +6 -3
  187. package/src/components/box.ws.ts +6 -3
  188. package/src/components/button.ws.tsx +13 -5
  189. package/src/components/checkbox-field.tsx +10 -0
  190. package/src/components/checkbox-field.ws.tsx +38 -0
  191. package/src/components/checkbox.tsx +13 -0
  192. package/src/components/checkbox.ws.tsx +40 -0
  193. package/src/components/code.ws.tsx +26 -32
  194. package/src/components/component-meta.ts +6 -3
  195. package/src/components/components-utils.ts +16 -10
  196. package/src/components/components.ts +8 -0
  197. package/src/components/error-message.tsx +10 -0
  198. package/src/components/error-message.ws.tsx +24 -0
  199. package/src/components/form.tsx +5 -1
  200. package/src/components/form.ws.tsx +39 -10
  201. package/src/components/heading.ws.tsx +7 -4
  202. package/src/components/image.ws.tsx +14 -12
  203. package/src/components/index.ts +47 -0
  204. package/src/components/input.tsx +3 -1
  205. package/src/components/input.ws.tsx +19 -4
  206. package/src/components/italic.ws.tsx +11 -8
  207. package/src/components/label.tsx +10 -0
  208. package/src/components/label.ws.tsx +39 -0
  209. package/src/components/link-block.ws.tsx +13 -10
  210. package/src/components/link.ws.tsx +15 -13
  211. package/src/components/list-item.ws.tsx +8 -4
  212. package/src/components/list.ws.tsx +28 -25
  213. package/src/components/paragraph.ws.tsx +7 -4
  214. package/src/components/radio-button-field.tsx +10 -0
  215. package/src/components/radio-button-field.ws.tsx +38 -0
  216. package/src/components/radio-button.tsx +13 -0
  217. package/src/components/radio-button.ws.tsx +40 -0
  218. package/src/components/separator.ws.tsx +26 -25
  219. package/src/components/span.ws.tsx +6 -3
  220. package/src/components/subscript.ws.tsx +6 -3
  221. package/src/components/success-message.tsx +10 -0
  222. package/src/components/success-message.ws.tsx +24 -0
  223. package/src/components/superscript.ws.tsx +6 -3
  224. package/src/components/text-block.ws.tsx +12 -11
  225. package/src/components/textarea.tsx +13 -0
  226. package/src/components/textarea.ws.tsx +41 -0
  227. package/src/css/css.ts +8 -11
  228. package/src/css/normalize.ts +166 -188
  229. package/src/css/presets.ts +15 -37
  230. package/src/css/style-rules.ts +24 -0
  231. package/src/embed-template.test.ts +210 -0
  232. package/src/embed-template.ts +187 -0
  233. package/src/index.ts +1 -0
@@ -1,20 +1,28 @@
1
1
  import { ButtonElementIcon } from "@webstudio-is/icons";
2
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
3
- import { props } from "./__generated__/button.props";
4
2
  import { button } from "../css/normalize";
3
+ import type {
4
+ PresetStyle,
5
+ WsComponentMeta,
6
+ WsComponentPropsMeta,
7
+ } from "./component-meta";
8
+ import { props } from "./__generated__/button.props";
5
9
  import type { defaultTag } from "./button";
6
- import type { Style } from "@webstudio-is/css-data";
7
10
 
8
11
  const presetStyle = {
9
12
  button,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
- category: "forms",
16
+ category: "general",
14
17
  type: "container",
15
18
  label: "Button",
16
19
  Icon: ButtonElementIcon,
17
20
  presetStyle,
21
+ states: [
22
+ { selector: ":active", label: "Active" },
23
+ { selector: ":disabled", label: "Disabled" },
24
+ { selector: ":enabled", label: "Enabled" },
25
+ ],
18
26
  };
19
27
 
20
28
  export const propsMeta: WsComponentPropsMeta = {
@@ -0,0 +1,10 @@
1
+ import { forwardRef, type ElementRef, type ComponentProps } from "react";
2
+
3
+ export const defaultTag = "label";
4
+
5
+ export const CheckboxField = forwardRef<
6
+ ElementRef<typeof defaultTag>,
7
+ Omit<ComponentProps<typeof defaultTag>, "htmlFor">
8
+ >((props, ref) => <label {...props} ref={ref} />);
9
+
10
+ CheckboxField.displayName = "CheckboxField";
@@ -0,0 +1,38 @@
1
+ import { CheckboxCheckedIcon } from "@webstudio-is/icons";
2
+ import type {
3
+ WsComponentMeta,
4
+ WsComponentPropsMeta,
5
+ PresetStyle,
6
+ } from "./component-meta";
7
+ import { props } from "./__generated__/checkbox-field.props";
8
+ import type { defaultTag } from "./checkbox-field";
9
+ import { label } from "../css/normalize";
10
+
11
+ const presetStyle = {
12
+ label: [
13
+ ...label,
14
+ { property: "display", value: { type: "keyword", value: "flex" } },
15
+ ],
16
+ } satisfies PresetStyle<typeof defaultTag>;
17
+
18
+ export const meta: WsComponentMeta = {
19
+ category: "forms",
20
+ type: "container",
21
+ label: "Checkbox Field",
22
+ Icon: CheckboxCheckedIcon,
23
+ presetStyle,
24
+ children: [
25
+ { type: "instance", component: "Checkbox", props: [], children: [] },
26
+ {
27
+ type: "instance",
28
+ component: "TextBlock",
29
+ props: [],
30
+ children: [{ type: "text", value: "Checkbox" }],
31
+ },
32
+ ],
33
+ };
34
+
35
+ export const propsMeta: WsComponentPropsMeta = {
36
+ props,
37
+ initialProps: [],
38
+ };
@@ -0,0 +1,13 @@
1
+ import { forwardRef, type ElementRef, type ComponentProps } from "react";
2
+
3
+ export const defaultTag = "input";
4
+
5
+ export const Checkbox = forwardRef<
6
+ ElementRef<typeof defaultTag>,
7
+ Omit<ComponentProps<typeof defaultTag>, "type">
8
+ // Make sure children are not passed down to an input, because this will result in error.
9
+ >(({ children: _children, ...props }, ref) => (
10
+ <input {...props} type="checkbox" ref={ref} />
11
+ ));
12
+
13
+ Checkbox.displayName = "Checkbox";
@@ -0,0 +1,40 @@
1
+ import { CheckboxCheckedIcon } from "@webstudio-is/icons";
2
+ import type {
3
+ WsComponentMeta,
4
+ WsComponentPropsMeta,
5
+ PresetStyle,
6
+ } from "./component-meta";
7
+ import type { defaultTag } from "./checkbox";
8
+ import { input } from "../css/normalize";
9
+ import { props } from "./__generated__/checkbox.props";
10
+
11
+ const presetStyle = {
12
+ input: [
13
+ ...input,
14
+ {
15
+ property: "marginRight",
16
+ value: { type: "unit", unit: "em", value: 0.5 },
17
+ },
18
+ ],
19
+ } satisfies PresetStyle<typeof defaultTag>;
20
+
21
+ export const meta: WsComponentMeta = {
22
+ type: "control",
23
+ label: "Checkbox",
24
+ Icon: CheckboxCheckedIcon,
25
+ presetStyle,
26
+ states: [
27
+ { selector: ":checked", label: "Checked" },
28
+ { selector: ":required", label: "Required" },
29
+ { selector: ":optional", label: "Optional" },
30
+ { selector: ":disabled", label: "Disabled" },
31
+ { selector: ":enabled", label: "Enabled" },
32
+ { selector: ":read-only", label: "Read Only" },
33
+ { selector: ":read-write", label: "Read Write" },
34
+ ],
35
+ };
36
+
37
+ export const propsMeta: WsComponentPropsMeta = {
38
+ props,
39
+ initialProps: ["name"],
40
+ };
@@ -1,44 +1,38 @@
1
1
  import { CodeIcon } 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 { type defaultTag, displayVarNamespace } from "./code";
4
8
  import { props } from "./__generated__/code.props";
5
- import type { Style, StyleValue } from "@webstudio-is/css-data";
6
9
  import { code } from "../css/normalize";
7
10
 
8
- const display: StyleValue = {
9
- type: "var",
10
- value: displayVarNamespace,
11
- fallbacks: [
12
- {
13
- type: "keyword",
14
- value: "inline-block",
15
- },
16
- ],
17
- };
18
-
19
11
  const presetStyle = {
20
- code: {
12
+ code: [
21
13
  ...code,
22
- display,
23
- paddingLeft: {
24
- type: "unit",
25
- value: 0.2,
26
- unit: "em",
14
+ {
15
+ property: "display",
16
+ value: {
17
+ type: "var",
18
+ value: displayVarNamespace,
19
+ fallbacks: [{ type: "keyword", value: "inline-block" }],
20
+ },
27
21
  },
28
- paddingRight: {
29
- type: "unit",
30
- value: 0.2,
31
- unit: "em",
22
+ {
23
+ property: "paddingLeft",
24
+ value: { type: "unit", value: 0.2, unit: "em" },
32
25
  },
33
- backgroundColor: {
34
- type: "rgb",
35
- r: 238,
36
- g: 238,
37
- b: 238,
38
- alpha: 1,
26
+ {
27
+ property: "paddingRight",
28
+ value: { type: "unit", value: 0.2, unit: "em" },
39
29
  },
40
- },
41
- } as const satisfies Record<typeof defaultTag, Style>;
30
+ {
31
+ property: "backgroundColor",
32
+ value: { type: "rgb", r: 238, g: 238, b: 238, alpha: 1 },
33
+ },
34
+ ],
35
+ } satisfies PresetStyle<typeof defaultTag>;
42
36
 
43
37
  export const meta: WsComponentMeta = {
44
38
  category: "general",
@@ -46,7 +40,7 @@ export const meta: WsComponentMeta = {
46
40
  label: "Code",
47
41
  Icon: CodeIcon,
48
42
  presetStyle,
49
- children: ["Code you can edit"],
43
+ children: [{ type: "text", value: "Code you can edit" }],
50
44
  };
51
45
 
52
46
  export const propsMeta: WsComponentPropsMeta = {
@@ -1,11 +1,13 @@
1
1
  import { z } from "zod";
2
2
  import type { FunctionComponent } from "react";
3
3
  import type { IconProps } from "@webstudio-is/icons";
4
- import type { Style } from "@webstudio-is/css-data";
5
4
  import { PropMeta } from "@webstudio-is/generate-arg-types";
6
5
  import type { htmlTags as HtmlTags } from "html-tags";
6
+ import { EmbedTemplateStyleDecl, WsEmbedTemplate } from "../embed-template";
7
7
 
8
- type PresetStyle = Partial<Record<HtmlTags, Style>>;
8
+ export type PresetStyle<Tag extends HtmlTags = HtmlTags> = Partial<
9
+ Record<Tag, EmbedTemplateStyleDecl[]>
10
+ >;
9
11
 
10
12
  // props are separated from the rest of the meta
11
13
  // so they can be exported separately and potentially tree-shaken
@@ -44,11 +46,12 @@ const WsComponentMeta = z.object({
44
46
  "rich-text",
45
47
  "rich-text-child",
46
48
  ]),
49
+ acceptedParents: z.optional(z.array(z.string())),
47
50
  label: z.string(),
48
51
  Icon: z.function(),
49
52
  presetStyle: z.optional(z.any()),
50
53
  states: z.optional(z.array(ComponentState)),
51
- children: z.optional(z.array(z.string())),
54
+ children: z.optional(WsEmbedTemplate),
52
55
  });
53
56
 
54
57
  export type WsComponentMeta = Omit<
@@ -1,3 +1,4 @@
1
+ import type { forwardRef } from "react";
1
2
  import * as components from "./components";
2
3
  import { registeredComponents } from "./index";
3
4
 
@@ -34,6 +35,14 @@ const componentNames = Object.keys({
34
35
  ListItem: 1,
35
36
  Separator: 1,
36
37
  Code: 1,
38
+ Label: 1,
39
+ SuccessMessage: 1,
40
+ ErrorMessage: 1,
41
+ Textarea: 1,
42
+ RadioButtonField: 1,
43
+ RadioButton: 1,
44
+ CheckboxField: 1,
45
+ Checkbox: 1,
37
46
  } satisfies { [K in keyof typeof components]: 1 }) as Array<
38
47
  keyof typeof components
39
48
  >;
@@ -47,17 +56,16 @@ export const getComponentNames = (): ComponentName[] => {
47
56
  return Array.from(uniqueNames) as ComponentName[];
48
57
  };
49
58
 
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ type AnyComponent = ReturnType<typeof forwardRef<any, any>>;
61
+
50
62
  /**
51
63
  * Now used only in builder app
52
64
  * @todo Consider using the same approach in the builder app as in the published apps . A dynamic import is needed
53
65
  */
54
- export const getComponent = (
55
- name: string
56
- ): undefined | (typeof components)[ComponentName] => {
66
+ export const getComponent = (name: string): undefined | AnyComponent => {
57
67
  return registeredComponents != null && name in registeredComponents
58
- ? (registeredComponents[
59
- name as ComponentName
60
- ] as (typeof components)[ComponentName])
68
+ ? (registeredComponents[name as ComponentName] as AnyComponent)
61
69
  : components[name as ComponentName];
62
70
  };
63
71
 
@@ -68,11 +76,9 @@ export const getComponent = (
68
76
  * see example /packages/sdk-size-test/app/routes/$.tsx
69
77
  **/
70
78
  export const createGetComponent = (comps: Partial<typeof components>) => {
71
- return (name: string) => {
79
+ return (name: string): undefined | AnyComponent => {
72
80
  return registeredComponents != null && name in registeredComponents
73
- ? (registeredComponents[
74
- name as ComponentName
75
- ] as (typeof components)[ComponentName])
81
+ ? (registeredComponents[name as ComponentName] as AnyComponent)
76
82
  : comps[name as ComponentName];
77
83
  };
78
84
  };
@@ -29,3 +29,11 @@ export { List } from "./list";
29
29
  export { ListItem } from "./list-item";
30
30
  export { Separator } from "./separator";
31
31
  export { Code } from "./code";
32
+ export { Label } from "./label";
33
+ export { SuccessMessage } from "./success-message";
34
+ export { ErrorMessage } from "./error-message";
35
+ export { Textarea } from "./textarea";
36
+ export { RadioButtonField } from "./radio-button-field";
37
+ export { RadioButton } from "./radio-button";
38
+ export { CheckboxField } from "./checkbox-field";
39
+ export { Checkbox } from "./checkbox";
@@ -0,0 +1,10 @@
1
+ import { forwardRef, type ElementRef, type ComponentProps } from "react";
2
+
3
+ export const defaultTag = "div";
4
+
5
+ export const ErrorMessage = forwardRef<
6
+ ElementRef<typeof defaultTag>,
7
+ ComponentProps<typeof defaultTag>
8
+ >((props, ref) => <div {...props} ref={ref} />);
9
+
10
+ ErrorMessage.displayName = "ErrorMessage";
@@ -0,0 +1,24 @@
1
+ import { BoxIcon } from "@webstudio-is/icons";
2
+ import type {
3
+ WsComponentMeta,
4
+ WsComponentPropsMeta,
5
+ PresetStyle,
6
+ } from "./component-meta";
7
+ import { props } from "./__generated__/error-message.props";
8
+ import { div } from "../css/normalize";
9
+
10
+ const presetStyle = {
11
+ div,
12
+ } satisfies PresetStyle<"div">;
13
+
14
+ export const meta: WsComponentMeta = {
15
+ type: "container",
16
+ label: "Error Message",
17
+ Icon: BoxIcon,
18
+ presetStyle,
19
+ };
20
+
21
+ export const propsMeta: WsComponentPropsMeta = {
22
+ props,
23
+ initialProps: [],
24
+ };
@@ -5,6 +5,10 @@ export const defaultTag = "form";
5
5
  export const Form = forwardRef<
6
6
  ElementRef<typeof defaultTag>,
7
7
  ComponentProps<typeof defaultTag>
8
- >((props, ref) => <form {...props} ref={ref} />);
8
+ >(({ children, ...props }, ref) => (
9
+ <form {...props} ref={ref}>
10
+ {children}
11
+ </form>
12
+ ));
9
13
 
10
14
  Form.displayName = "Form";
@@ -1,20 +1,19 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { FormIcon } from "@webstudio-is/icons";
3
2
  import { form } 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 "./form";
6
9
  import { props } from "./__generated__/form.props";
7
10
 
8
11
  const presetStyle = {
9
- form: {
12
+ form: [
10
13
  ...form,
11
- minHeight: {
12
- type: "unit",
13
- unit: "px",
14
- value: 20,
15
- },
16
- },
17
- } as const satisfies Record<typeof defaultTag, Style>;
14
+ { property: "minHeight", value: { type: "unit", unit: "px", value: 20 } },
15
+ ],
16
+ } satisfies PresetStyle<typeof defaultTag>;
18
17
 
19
18
  export const meta: WsComponentMeta = {
20
19
  category: "forms",
@@ -22,8 +21,38 @@ export const meta: WsComponentMeta = {
22
21
  label: "Form",
23
22
  Icon: FormIcon,
24
23
  presetStyle,
24
+ children: [
25
+ {
26
+ type: "instance",
27
+ component: "Label",
28
+ children: [{ type: "text", value: "Name" }],
29
+ },
30
+ {
31
+ type: "instance",
32
+ component: "Input",
33
+ props: [{ type: "string", name: "name", value: "name" }],
34
+ children: [],
35
+ },
36
+ {
37
+ type: "instance",
38
+ component: "Label",
39
+ children: [{ type: "text", value: "Email" }],
40
+ },
41
+ {
42
+ type: "instance",
43
+ component: "Input",
44
+ props: [{ type: "string", name: "email", value: "email" }],
45
+ children: [],
46
+ },
47
+ {
48
+ type: "instance",
49
+ component: "Button",
50
+ children: [{ type: "text", value: "Submit" }],
51
+ },
52
+ ],
25
53
  };
26
54
 
27
55
  export const propsMeta: WsComponentPropsMeta = {
28
56
  props,
57
+ initialProps: [],
29
58
  };
@@ -1,8 +1,11 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { HeadingIcon } from "@webstudio-is/icons";
3
2
  import type { ComponentProps } from "react";
4
3
  import { h1, h2, h3, h4, h5, h6 } from "../css/normalize";
5
- import type { WsComponentMeta, WsComponentPropsMeta } from "./component-meta";
4
+ import type {
5
+ PresetStyle,
6
+ WsComponentMeta,
7
+ WsComponentPropsMeta,
8
+ } from "./component-meta";
6
9
  import type { Heading } from "./heading";
7
10
  import { props } from "./__generated__/heading.props";
8
11
 
@@ -15,14 +18,14 @@ const presetStyle = {
15
18
  h4,
16
19
  h5,
17
20
  h6,
18
- } as const satisfies Record<HeadingTags, Style>;
21
+ } satisfies PresetStyle<HeadingTags>;
19
22
 
20
23
  export const meta: WsComponentMeta = {
21
24
  category: "typography",
22
25
  type: "rich-text",
23
26
  label: "Heading",
24
27
  Icon: HeadingIcon,
25
- children: ["Heading you can edit"],
28
+ children: [{ type: "text", value: "Heading you can edit" }],
26
29
  presetStyle,
27
30
  };
28
31
 
@@ -1,28 +1,30 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { ImageIcon } from "@webstudio-is/icons";
3
2
  import { img } 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 "./image";
6
9
  import { props } from "./__generated__/image.props";
7
10
 
8
11
  const presetStyle = {
9
- img: {
12
+ img: [
10
13
  ...img,
11
14
 
12
15
  // Otherwise on new image insert onto canvas it can overfit screen size multiple times
13
- maxWidth: {
14
- type: "unit",
15
- unit: "%",
16
- value: 100,
16
+ {
17
+ property: "maxWidth",
18
+ value: { type: "unit", unit: "%", value: 100 },
17
19
  },
18
20
  // inline | inline-block is not suitable because without line-height: 0 on the parent you get unsuitable spaces/margins
19
21
  // see https://stackoverflow.com/questions/24771194/is-the-margin-of-inline-block-4px-is-static-for-all-browsers
20
- display: {
21
- type: "keyword",
22
- value: "block",
22
+ {
23
+ property: "display",
24
+ value: { type: "keyword", value: "block" },
23
25
  },
24
- },
25
- } as const satisfies Record<typeof defaultTag, Style>;
26
+ ],
27
+ } satisfies PresetStyle<typeof defaultTag>;
26
28
 
27
29
  export const meta: WsComponentMeta = {
28
30
  category: "media",
@@ -25,6 +25,14 @@ import { meta as ListMeta } from "./list.ws";
25
25
  import { meta as ListItemMeta } from "./list-item.ws";
26
26
  import { meta as SeparatorMeta } from "./separator.ws";
27
27
  import { meta as CodeMeta } from "./code.ws";
28
+ import { meta as LabelMeta } from "./label.ws";
29
+ import { meta as SuccessMessageMeta } from "./success-message.ws";
30
+ import { meta as ErrorMessageMeta } from "./error-message.ws";
31
+ import { meta as TextareaMeta } from "./textarea.ws";
32
+ import { meta as RadioButtonFieldMeta } from "./radio-button-field.ws";
33
+ import { meta as RadioButtonMeta } from "./radio-button.ws";
34
+ import { meta as CheckboxFieldMeta } from "./checkbox-field.ws";
35
+ import { meta as CheckboxMeta } from "./checkbox.ws";
28
36
 
29
37
  // these are huge JSON objects that we want to be tree-shaken when not used!
30
38
  import { propsMeta as SlotMetaPropsMeta } from "./slot.ws";
@@ -51,6 +59,14 @@ import { propsMeta as ListPropsMeta } from "./list.ws";
51
59
  import { propsMeta as ListItemPropsMeta } from "./list-item.ws";
52
60
  import { propsMeta as SeparatorPropsMeta } from "./separator.ws";
53
61
  import { propsMeta as CodePropsMeta } from "./code.ws";
62
+ import { propsMeta as LabelPropsMeta } from "./label.ws";
63
+ import { propsMeta as SuccessMessagePropsMeta } from "./success-message.ws";
64
+ import { propsMeta as ErrorMessagePropsMeta } from "./error-message.ws";
65
+ import { propsMeta as TextareaPropsMeta } from "./textarea.ws";
66
+ import { propsMeta as RadioButtonFieldPropsMeta } from "./radio-button-field.ws";
67
+ import { propsMeta as RadioButtonPropsMeta } from "./radio-button.ws";
68
+ import { propsMeta as CheckboxFieldPropsMeta } from "./checkbox-field.ws";
69
+ import { propsMeta as CheckboxPropsMeta } from "./checkbox.ws";
54
70
 
55
71
  // @todo this list should not be hardcoded!
56
72
  const defaultMetas: Record<string, WsComponentMeta> = {
@@ -78,6 +94,14 @@ const defaultMetas: Record<string, WsComponentMeta> = {
78
94
  ListItem: ListItemMeta,
79
95
  Separator: SeparatorMeta,
80
96
  Code: CodeMeta,
97
+ Label: LabelMeta,
98
+ SuccessMessage: SuccessMessageMeta,
99
+ ErrorMessage: ErrorMessageMeta,
100
+ Textarea: TextareaMeta,
101
+ RadioButtonField: RadioButtonFieldMeta,
102
+ RadioButton: RadioButtonMeta,
103
+ CheckboxField: CheckboxFieldMeta,
104
+ Checkbox: CheckboxMeta,
81
105
  };
82
106
 
83
107
  let currentMetas = defaultMetas;
@@ -122,6 +146,14 @@ const defaultPropsMetasRaw = {
122
146
  ListItem: ListItemPropsMeta,
123
147
  Separator: SeparatorPropsMeta,
124
148
  Code: CodePropsMeta,
149
+ Label: LabelPropsMeta,
150
+ SuccessMessage: SuccessMessagePropsMeta,
151
+ ErrorMessage: ErrorMessagePropsMeta,
152
+ Textarea: TextareaPropsMeta,
153
+ RadioButtonField: RadioButtonFieldPropsMeta,
154
+ RadioButton: RadioButtonPropsMeta,
155
+ CheckboxField: CheckboxFieldPropsMeta,
156
+ Checkbox: CheckboxPropsMeta,
125
157
  } as const;
126
158
 
127
159
  const defaultPropsMetas: Record<string, WsComponentPropsMeta> =
@@ -219,3 +251,18 @@ const computeInitialProps = (
219
251
  // order of initialProps must be preserved
220
252
  return [...initialProps, ...requiredProps];
221
253
  };
254
+
255
+ export const canAcceptComponent = (
256
+ parentComponent: string,
257
+ childComponent: string
258
+ ) => {
259
+ const parentMeta = getComponentMeta(parentComponent);
260
+ const childMeta = getComponentMeta(childComponent);
261
+ if (parentMeta?.type !== "container" || childMeta === undefined) {
262
+ return false;
263
+ }
264
+ return (
265
+ childMeta.acceptedParents === undefined ||
266
+ childMeta.acceptedParents.includes(parentComponent)
267
+ );
268
+ };
@@ -4,7 +4,9 @@ export const defaultTag = "input";
4
4
 
5
5
  export const Input = forwardRef<
6
6
  ElementRef<typeof defaultTag>,
7
- ComponentProps<typeof defaultTag>
7
+ ComponentProps<typeof defaultTag> & {
8
+ type?: "text" | "email" | "password" | "number" | "tel" | "url";
9
+ }
8
10
  // Make sure children are not passed down to an input, because this will result in error.
9
11
  >(({ children: _children, ...props }, ref) => <input {...props} ref={ref} />);
10
12
 
@@ -1,22 +1,37 @@
1
- import type { Style } from "@webstudio-is/css-data";
2
1
  import { FormTextFieldIcon } from "@webstudio-is/icons";
3
2
  import { input } 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 "./input";
6
9
  import { props } from "./__generated__/input.props";
7
10
 
8
11
  const presetStyle = {
9
12
  input,
10
- } as const satisfies Record<typeof defaultTag, Style>;
13
+ } satisfies PresetStyle<typeof defaultTag>;
11
14
 
12
15
  export const meta: WsComponentMeta = {
13
16
  category: "forms",
14
17
  type: "control",
15
- label: "Input",
18
+ label: "Text Field",
16
19
  Icon: FormTextFieldIcon,
17
20
  presetStyle,
21
+ states: [
22
+ { selector: "::placeholder", label: "Placeholder" },
23
+ { selector: ":valid", label: "Valid" },
24
+ { selector: ":invalid", label: "Invalid" },
25
+ { selector: ":required", label: "Required" },
26
+ { selector: ":optional", label: "Optional" },
27
+ { selector: ":disabled", label: "Disabled" },
28
+ { selector: ":enabled", label: "Enabled" },
29
+ { selector: ":read-only", label: "Read Only" },
30
+ { selector: ":read-write", label: "Read Write" },
31
+ ],
18
32
  };
19
33
 
20
34
  export const propsMeta: WsComponentPropsMeta = {
21
35
  props,
36
+ initialProps: ["name", "type", "placeholder", "required", "autoFocus"],
22
37
  };