@webstudio-is/react-sdk 0.34.0 → 0.36.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 (234) hide show
  1. package/lib/app/custom-components/image.js +1 -1
  2. package/lib/app/custom-components/index.js +1 -6
  3. package/lib/cjs/app/custom-components/image.cjs +2 -2
  4. package/lib/cjs/app/custom-components/index.cjs +1 -6
  5. package/lib/cjs/components/__generated__/blockquote.props.cjs +414 -0
  6. package/lib/cjs/components/__generated__/body.props.cjs +413 -0
  7. package/lib/cjs/components/__generated__/bold.props.cjs +413 -0
  8. package/lib/cjs/components/__generated__/box.props.cjs +431 -0
  9. package/lib/cjs/components/__generated__/button.props.cjs +430 -0
  10. package/lib/cjs/components/__generated__/code.props.cjs +420 -0
  11. package/lib/cjs/components/__generated__/form.props.cjs +421 -0
  12. package/lib/cjs/components/__generated__/heading.props.cjs +420 -0
  13. package/lib/cjs/components/__generated__/image.props.cjs +454 -0
  14. package/lib/cjs/components/__generated__/input.props.cjs +451 -0
  15. package/lib/cjs/components/__generated__/italic.props.cjs +413 -0
  16. package/lib/cjs/components/__generated__/link.props.cjs +437 -0
  17. package/lib/cjs/components/__generated__/list-item.props.cjs +414 -0
  18. package/lib/cjs/components/__generated__/list.props.cjs +427 -0
  19. package/lib/cjs/components/__generated__/paragraph.props.cjs +413 -0
  20. package/lib/cjs/components/__generated__/rich-text-link.props.cjs +437 -0
  21. package/lib/cjs/components/__generated__/separator.props.cjs +413 -0
  22. package/lib/cjs/components/__generated__/span.props.cjs +413 -0
  23. package/lib/cjs/components/__generated__/subscript.props.cjs +413 -0
  24. package/lib/cjs/components/__generated__/superscript.props.cjs +413 -0
  25. package/lib/cjs/components/__generated__/text-block.props.cjs +413 -0
  26. package/lib/cjs/components/blockquote.cjs +31 -0
  27. package/lib/cjs/components/blockquote.ws.cjs +75 -0
  28. package/lib/cjs/components/body.ws.cjs +2 -8
  29. package/lib/cjs/components/bold.ws.cjs +2 -8
  30. package/lib/cjs/components/box.ws.cjs +2 -8
  31. package/lib/cjs/components/button.ws.cjs +2 -8
  32. package/lib/cjs/components/code.cjs +38 -0
  33. package/lib/cjs/components/code.ws.cjs +66 -0
  34. package/lib/cjs/components/components-utils.cjs +71 -0
  35. package/lib/cjs/components/components.cjs +64 -0
  36. package/lib/cjs/components/form.ws.cjs +2 -8
  37. package/lib/cjs/components/heading.ws.cjs +2 -8
  38. package/lib/cjs/components/image.ws.cjs +8 -9
  39. package/lib/cjs/components/index.cjs +28 -53
  40. package/lib/cjs/components/input.ws.cjs +2 -8
  41. package/lib/cjs/components/italic.ws.cjs +2 -8
  42. package/lib/cjs/components/link.ws.cjs +2 -8
  43. package/lib/cjs/{css/breakpoints.cjs → components/list-item.cjs} +12 -10
  44. package/lib/cjs/components/list-item.ws.cjs +35 -0
  45. package/lib/cjs/components/list.cjs +31 -0
  46. package/lib/cjs/components/list.ws.cjs +51 -0
  47. package/lib/cjs/components/paragraph.ws.cjs +2 -8
  48. package/lib/cjs/components/rich-text-link.ws.cjs +2 -8
  49. package/lib/cjs/components/separator.cjs +31 -0
  50. package/lib/cjs/components/separator.ws.cjs +51 -0
  51. package/lib/cjs/components/span.ws.cjs +2 -8
  52. package/lib/cjs/components/subscript.ws.cjs +2 -8
  53. package/lib/cjs/components/superscript.ws.cjs +2 -8
  54. package/lib/cjs/components/text-block.ws.cjs +2 -8
  55. package/lib/cjs/css/get-browser-style.cjs +13 -5
  56. package/lib/cjs/css/index.cjs +0 -1
  57. package/lib/cjs/index.cjs +2 -0
  58. package/lib/cjs/tree/create-elements-tree.cjs +10 -9
  59. package/lib/cjs/tree/index.cjs +1 -1
  60. package/lib/cjs/tree/root.cjs +28 -4
  61. package/lib/cjs/tree/{wrapper-component.cjs → webstudio-component.cjs} +12 -11
  62. package/lib/components/__generated__/blockquote.props.js +394 -0
  63. package/lib/components/__generated__/body.props.js +393 -0
  64. package/lib/components/__generated__/bold.props.js +393 -0
  65. package/lib/components/__generated__/box.props.js +411 -0
  66. package/lib/components/__generated__/button.props.js +410 -0
  67. package/lib/components/__generated__/code.props.js +400 -0
  68. package/lib/components/__generated__/form.props.js +401 -0
  69. package/lib/components/__generated__/heading.props.js +400 -0
  70. package/lib/components/__generated__/image.props.js +434 -0
  71. package/lib/components/__generated__/input.props.js +431 -0
  72. package/lib/components/__generated__/italic.props.js +393 -0
  73. package/lib/components/__generated__/link.props.js +417 -0
  74. package/lib/components/__generated__/list-item.props.js +394 -0
  75. package/lib/components/__generated__/list.props.js +407 -0
  76. package/lib/components/__generated__/paragraph.props.js +393 -0
  77. package/lib/components/__generated__/rich-text-link.props.js +417 -0
  78. package/lib/components/__generated__/separator.props.js +393 -0
  79. package/lib/components/__generated__/span.props.js +393 -0
  80. package/lib/components/__generated__/subscript.props.js +393 -0
  81. package/lib/components/__generated__/superscript.props.js +393 -0
  82. package/lib/components/__generated__/text-block.props.js +393 -0
  83. package/lib/components/blockquote.js +14 -0
  84. package/lib/components/blockquote.ws.js +55 -0
  85. package/lib/components/body.ws.js +1 -1
  86. package/lib/components/bold.ws.js +1 -1
  87. package/lib/components/box.ws.js +1 -1
  88. package/lib/components/button.ws.js +1 -1
  89. package/lib/components/code.js +21 -0
  90. package/lib/components/code.ws.js +46 -0
  91. package/lib/components/components-utils.js +45 -0
  92. package/lib/components/components.js +44 -0
  93. package/lib/components/form.ws.js +1 -1
  94. package/lib/components/heading.ws.js +1 -1
  95. package/lib/components/image.ws.js +7 -2
  96. package/lib/components/index.js +28 -53
  97. package/lib/components/input.ws.js +1 -1
  98. package/lib/components/italic.ws.js +1 -1
  99. package/lib/components/link.ws.js +1 -1
  100. package/lib/components/list-item.js +14 -0
  101. package/lib/components/list-item.ws.js +15 -0
  102. package/lib/components/list.js +14 -0
  103. package/lib/components/list.ws.js +31 -0
  104. package/lib/components/paragraph.ws.js +1 -1
  105. package/lib/components/rich-text-link.ws.js +1 -1
  106. package/lib/components/separator.js +14 -0
  107. package/lib/components/separator.ws.js +31 -0
  108. package/lib/components/span.ws.js +1 -1
  109. package/lib/components/subscript.ws.js +1 -1
  110. package/lib/components/superscript.ws.js +1 -1
  111. package/lib/components/text-block.ws.js +1 -1
  112. package/lib/css/get-browser-style.js +9 -1
  113. package/lib/css/index.js +0 -1
  114. package/lib/index.js +2 -0
  115. package/lib/tree/create-elements-tree.js +10 -9
  116. package/lib/tree/index.js +1 -1
  117. package/lib/tree/root.js +28 -4
  118. package/lib/tree/{wrapper-component.js → webstudio-component.js} +8 -7
  119. package/package.json +14 -11
  120. package/src/app/custom-components/image.tsx +1 -1
  121. package/src/app/custom-components/index.ts +2 -7
  122. package/src/components/__generated__/blockquote.props.ts +439 -0
  123. package/src/components/__generated__/body.props.ts +438 -0
  124. package/src/components/__generated__/bold.props.ts +438 -0
  125. package/src/components/__generated__/box.props.ts +456 -0
  126. package/src/components/__generated__/button.props.ts +455 -0
  127. package/src/components/__generated__/code.props.ts +445 -0
  128. package/src/components/__generated__/form.props.ts +446 -0
  129. package/src/components/__generated__/heading.props.ts +445 -0
  130. package/src/components/__generated__/image.props.ts +479 -0
  131. package/src/components/__generated__/input.props.ts +476 -0
  132. package/src/components/__generated__/italic.props.ts +438 -0
  133. package/src/components/__generated__/link.props.ts +462 -0
  134. package/src/components/__generated__/list-item.props.ts +439 -0
  135. package/src/components/__generated__/list.props.ts +452 -0
  136. package/src/components/__generated__/paragraph.props.ts +438 -0
  137. package/src/components/__generated__/rich-text-link.props.ts +462 -0
  138. package/src/components/__generated__/separator.props.ts +438 -0
  139. package/src/components/__generated__/span.props.ts +438 -0
  140. package/src/components/__generated__/subscript.props.ts +438 -0
  141. package/src/components/__generated__/superscript.props.ts +438 -0
  142. package/src/components/__generated__/text-block.props.ts +438 -0
  143. package/src/components/blockquote.stories.tsx +16 -0
  144. package/src/components/blockquote.tsx +18 -0
  145. package/src/components/blockquote.ws.tsx +55 -0
  146. package/src/components/body.ws.tsx +3 -3
  147. package/src/components/bold.ws.tsx +3 -3
  148. package/src/components/box.ws.ts +3 -3
  149. package/src/components/button.ws.tsx +3 -3
  150. package/src/components/code.stories.tsx +16 -0
  151. package/src/components/code.tsx +31 -0
  152. package/src/components/code.ws.tsx +46 -0
  153. package/src/components/components-utils.ts +75 -0
  154. package/src/components/components.ts +28 -0
  155. package/src/components/form.ws.tsx +3 -3
  156. package/src/components/heading.ws.tsx +3 -3
  157. package/src/components/image.ws.tsx +9 -4
  158. package/src/components/index.ts +28 -63
  159. package/src/components/input.ws.tsx +3 -3
  160. package/src/components/italic.ws.tsx +3 -3
  161. package/src/components/link.ws.tsx +3 -3
  162. package/src/components/list-item.stories.tsx +16 -0
  163. package/src/components/list-item.tsx +18 -0
  164. package/src/components/list-item.ws.tsx +14 -0
  165. package/src/components/list.stories.tsx +17 -0
  166. package/src/components/list.tsx +24 -0
  167. package/src/components/list.ws.tsx +31 -0
  168. package/src/components/paragraph.ws.tsx +3 -3
  169. package/src/components/rich-text-link.ws.tsx +3 -3
  170. package/src/components/separator.stories.tsx +14 -0
  171. package/src/components/separator.tsx +18 -0
  172. package/src/components/separator.ws.tsx +31 -0
  173. package/src/components/span.ws.tsx +3 -3
  174. package/src/components/subscript.ws.tsx +3 -3
  175. package/src/components/superscript.ws.tsx +3 -3
  176. package/src/components/text-block.ws.tsx +3 -3
  177. package/src/css/get-browser-style.ts +14 -3
  178. package/src/css/index.ts +0 -1
  179. package/src/index.ts +2 -0
  180. package/src/props.ts +1 -1
  181. package/src/tree/create-elements-tree.tsx +16 -32
  182. package/src/tree/index.ts +1 -1
  183. package/src/tree/root.ts +37 -5
  184. package/src/tree/{wrapper-component.tsx → webstudio-component.tsx} +11 -9
  185. package/lib/cjs/components/__generated__/body.props.json +0 -743
  186. package/lib/cjs/components/__generated__/bold.props.json +0 -743
  187. package/lib/cjs/components/__generated__/box.props.json +0 -765
  188. package/lib/cjs/components/__generated__/button.props.json +0 -824
  189. package/lib/cjs/components/__generated__/form.props.json +0 -799
  190. package/lib/cjs/components/__generated__/heading.props.json +0 -754
  191. package/lib/cjs/components/__generated__/image.props.json +0 -846
  192. package/lib/cjs/components/__generated__/input.props.json +0 -977
  193. package/lib/cjs/components/__generated__/italic.props.json +0 -743
  194. package/lib/cjs/components/__generated__/link.props.json +0 -820
  195. package/lib/cjs/components/__generated__/paragraph.props.json +0 -743
  196. package/lib/cjs/components/__generated__/rich-text-link.props.json +0 -820
  197. package/lib/cjs/components/__generated__/span.props.json +0 -743
  198. package/lib/cjs/components/__generated__/subscript.props.json +0 -743
  199. package/lib/cjs/components/__generated__/superscript.props.json +0 -743
  200. package/lib/cjs/components/__generated__/text-block.props.json +0 -743
  201. package/lib/components/__generated__/body.props.json +0 -743
  202. package/lib/components/__generated__/bold.props.json +0 -743
  203. package/lib/components/__generated__/box.props.json +0 -765
  204. package/lib/components/__generated__/button.props.json +0 -824
  205. package/lib/components/__generated__/form.props.json +0 -799
  206. package/lib/components/__generated__/heading.props.json +0 -754
  207. package/lib/components/__generated__/image.props.json +0 -846
  208. package/lib/components/__generated__/input.props.json +0 -977
  209. package/lib/components/__generated__/italic.props.json +0 -743
  210. package/lib/components/__generated__/link.props.json +0 -820
  211. package/lib/components/__generated__/paragraph.props.json +0 -743
  212. package/lib/components/__generated__/rich-text-link.props.json +0 -820
  213. package/lib/components/__generated__/span.props.json +0 -743
  214. package/lib/components/__generated__/subscript.props.json +0 -743
  215. package/lib/components/__generated__/superscript.props.json +0 -743
  216. package/lib/components/__generated__/text-block.props.json +0 -743
  217. package/lib/css/breakpoints.js +0 -9
  218. package/src/components/__generated__/body.props.json +0 -743
  219. package/src/components/__generated__/bold.props.json +0 -743
  220. package/src/components/__generated__/box.props.json +0 -765
  221. package/src/components/__generated__/button.props.json +0 -824
  222. package/src/components/__generated__/form.props.json +0 -799
  223. package/src/components/__generated__/heading.props.json +0 -754
  224. package/src/components/__generated__/image.props.json +0 -846
  225. package/src/components/__generated__/input.props.json +0 -977
  226. package/src/components/__generated__/italic.props.json +0 -743
  227. package/src/components/__generated__/link.props.json +0 -820
  228. package/src/components/__generated__/paragraph.props.json +0 -743
  229. package/src/components/__generated__/rich-text-link.props.json +0 -820
  230. package/src/components/__generated__/span.props.json +0 -743
  231. package/src/components/__generated__/subscript.props.json +0 -743
  232. package/src/components/__generated__/superscript.props.json +0 -743
  233. package/src/components/__generated__/text-block.props.json +0 -743
  234. package/src/css/breakpoints.ts +0 -10
@@ -0,0 +1,46 @@
1
+ import { CodeIcon } from "@webstudio-is/icons";
2
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
+ import { displayVarNamespace } from "./code";
4
+ import { props } from "./__generated__/code.props";
5
+
6
+ const presetStyle: WsComponentMeta["presetStyle"] = {
7
+ display: {
8
+ type: "var",
9
+ value: displayVarNamespace,
10
+ fallbacks: [
11
+ {
12
+ type: "keyword",
13
+ value: "inline-block",
14
+ },
15
+ ],
16
+ },
17
+ paddingLeft: {
18
+ type: "keyword",
19
+ value: "0.2em",
20
+ },
21
+ paddingRight: {
22
+ type: "keyword",
23
+ value: "0.2em",
24
+ },
25
+ backgroundColor: {
26
+ type: "keyword",
27
+ value: "#eee",
28
+ },
29
+ fontFamily: {
30
+ type: "keyword",
31
+ value: "monospace",
32
+ },
33
+ };
34
+
35
+ export const meta: WsComponentMeta = {
36
+ type: "rich-text",
37
+ label: "Code",
38
+ Icon: CodeIcon,
39
+ presetStyle,
40
+ children: ["Code you can edit"],
41
+ };
42
+
43
+ export const propsMeta: WsComponentPropsMeta = {
44
+ props,
45
+ initialProps: ["inline", "lang", "meta"],
46
+ };
@@ -0,0 +1,75 @@
1
+ import * as components from "./components";
2
+ import { registeredComponents } from "./index";
3
+
4
+ export type ComponentName = keyof typeof components;
5
+
6
+ /**
7
+ * We need to define component names manually here, instead of using Object.keys(components)
8
+ * Otherwise every component would be included in the bundle, even if it is not used
9
+ */
10
+ const componentNames = Object.keys({
11
+ Box: 1,
12
+ Body: 1,
13
+ TextBlock: 1,
14
+ Heading: 1,
15
+ Paragraph: 1,
16
+ Link: 1,
17
+ RichTextLink: 1,
18
+ Span: 1,
19
+ Bold: 1,
20
+ Italic: 1,
21
+ Superscript: 1,
22
+ Subscript: 1,
23
+ Button: 1,
24
+ Input: 1,
25
+ Form: 1,
26
+ Image: 1,
27
+ Blockquote: 1,
28
+ List: 1,
29
+ ListItem: 1,
30
+ Separator: 1,
31
+ Code: 1,
32
+ } satisfies { [K in keyof typeof components]: 1 }) as Array<
33
+ keyof typeof components
34
+ >;
35
+
36
+ export const getComponentNames = (): ComponentName[] => {
37
+ const uniqueNames = new Set([
38
+ ...componentNames,
39
+ ...Object.keys(registeredComponents || {}),
40
+ ]);
41
+
42
+ return Array.from(uniqueNames) as ComponentName[];
43
+ };
44
+
45
+ /**
46
+ * Now used only in builder app
47
+ * @todo Consider using the same approach in the builder app as in the published apps . A dynamic import is needed
48
+ */
49
+ export const getComponent = (
50
+ name: string
51
+ ): undefined | (typeof components)[ComponentName] => {
52
+ return registeredComponents != null && name in registeredComponents
53
+ ? (registeredComponents[
54
+ name as ComponentName
55
+ ] as (typeof components)[ComponentName])
56
+ : components[name as ComponentName];
57
+ };
58
+
59
+ /**
60
+ * The application imports only the components it uses, then pass them to createGetComponent i.e.
61
+ * getComponent = createGetComponent({ Box, BlaBla })
62
+ * <RootInstance data={data} getComponent={getComponent} />
63
+ * see example /packages/sdk-size-test/app/routes/$.tsx
64
+ **/
65
+ export const createGetComponent = (comps: Partial<typeof components>) => {
66
+ return (name: string) => {
67
+ return registeredComponents != null && name in registeredComponents
68
+ ? (registeredComponents[
69
+ name as ComponentName
70
+ ] as (typeof components)[ComponentName])
71
+ : comps[name as ComponentName];
72
+ };
73
+ };
74
+
75
+ export type GetComponent = typeof getComponent;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * This file should contain all the components that we use in the builder/production app
3
+ *
4
+ * The application imports only the components it uses and uses
5
+ * getComponent = createGetComponent({ Box, BlaBla })to pass them to RootInstance
6
+ * see example /packages/sdk-size-test/app/routes/$.tsx
7
+ */
8
+ export { Body } from "./body";
9
+ export { Box } from "./box";
10
+ export { TextBlock } from "./text-block";
11
+ export { Heading } from "./heading";
12
+ export { Paragraph } from "./paragraph";
13
+ export { Link } from "./link";
14
+ export { RichTextLink } from "./rich-text-link";
15
+ export { Span } from "./span";
16
+ export { Bold } from "./bold";
17
+ export { Italic } from "./italic";
18
+ export { Superscript } from "./superscript";
19
+ export { Subscript } from "./subscript";
20
+ export { Button } from "./button";
21
+ export { Input } from "./input";
22
+ export { Form } from "./form";
23
+ export { Image } from "./image";
24
+ export { Blockquote } from "./blockquote";
25
+ export { List } from "./list";
26
+ export { ListItem } from "./list-item";
27
+ export { Separator } from "./separator";
28
+ export { Code } from "./code";
@@ -1,6 +1,6 @@
1
1
  import { FormIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/form.props.json";
3
+ import { props } from "./__generated__/form.props";
4
4
 
5
5
  const presetStyle = {
6
6
  minHeight: {
@@ -21,6 +21,6 @@ export const meta: WsComponentMeta = {
21
21
  presetStyle,
22
22
  };
23
23
 
24
- export const propsMeta = {
24
+ export const propsMeta: WsComponentPropsMeta = {
25
25
  props,
26
- } as WsComponentPropsMeta;
26
+ };
@@ -1,6 +1,6 @@
1
1
  import { HeadingIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/heading.props.json";
3
+ import { props } from "./__generated__/heading.props";
4
4
 
5
5
  export const meta: WsComponentMeta = {
6
6
  type: "rich-text",
@@ -9,7 +9,7 @@ export const meta: WsComponentMeta = {
9
9
  children: ["Heading you can edit"],
10
10
  };
11
11
 
12
- export const propsMeta = {
12
+ export const propsMeta: WsComponentPropsMeta = {
13
13
  props,
14
14
  initialProps: ["tag"],
15
- } as WsComponentPropsMeta;
15
+ };
@@ -1,6 +1,6 @@
1
1
  import { ImageIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/image.props.json";
3
+ import { props } from "./__generated__/image.props";
4
4
 
5
5
  const presetStyle = {
6
6
  // Otherwise on new image insert onto canvas it can overfit screen size multiple times
@@ -24,10 +24,15 @@ export const meta: WsComponentMeta = {
24
24
  presetStyle,
25
25
  };
26
26
 
27
- export const propsMeta = {
27
+ export const propsMeta: WsComponentPropsMeta = {
28
28
  props: {
29
29
  ...props,
30
- src: { ...props.src, control: "file-image", name: "Source" },
30
+ src: {
31
+ type: "string",
32
+ control: "file-image",
33
+ label: "Source",
34
+ required: false,
35
+ },
31
36
  },
32
37
  initialProps: ["src", "width", "height", "alt", "loading"],
33
- } as WsComponentPropsMeta;
38
+ };
@@ -1,6 +1,6 @@
1
1
  import { PropMeta } from "@webstudio-is/generate-arg-types";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
-
3
+ import type { ComponentName } from "./components-utils";
4
4
  import { meta as BodyMeta } from "./body.ws";
5
5
  import { meta as BoxMeta } from "./box.ws";
6
6
  import { meta as TextBlockMeta } from "./text-block.ws";
@@ -17,6 +17,11 @@ import { meta as ButtonMeta } from "./button.ws";
17
17
  import { meta as InputMeta } from "./input.ws";
18
18
  import { meta as FormMeta } from "./form.ws";
19
19
  import { meta as ImageMeta } from "./image.ws";
20
+ import { meta as BlockquoteMeta } from "./blockquote.ws";
21
+ import { meta as ListMeta } from "./list.ws";
22
+ import { meta as ListItemMeta } from "./list-item.ws";
23
+ import { meta as SeparatorMeta } from "./separator.ws";
24
+ import { meta as CodeMeta } from "./code.ws";
20
25
 
21
26
  // these are huge JSON objects that we want to be tree-shaken when not used!
22
27
  import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
@@ -35,23 +40,11 @@ import { propsMeta as ButtonMetaPropsMeta } from "./button.ws";
35
40
  import { propsMeta as InputMetaPropsMeta } from "./input.ws";
36
41
  import { propsMeta as FormMetaPropsMeta } from "./form.ws";
37
42
  import { propsMeta as ImageMetaPropsMeta } from "./image.ws";
38
-
39
- import { Body } from "./body";
40
- import { Box } from "./box";
41
- import { TextBlock } from "./text-block";
42
- import { Heading } from "./heading";
43
- import { Paragraph } from "./paragraph";
44
- import { Link } from "./link";
45
- import { RichTextLink } from "./rich-text-link";
46
- import { Span } from "./span";
47
- import { Bold } from "./bold";
48
- import { Italic } from "./italic";
49
- import { Superscript } from "./superscript";
50
- import { Subscript } from "./subscript";
51
- import { Button } from "./button";
52
- import { Input } from "./input";
53
- import { Form } from "./form";
54
- import { Image } from "./image";
43
+ import { propsMeta as BlockquotePropsMeta } from "./blockquote.ws";
44
+ import { propsMeta as ListPropsMeta } from "./list.ws";
45
+ import { propsMeta as ListItemPropsMeta } from "./list-item.ws";
46
+ import { propsMeta as SeparatorPropsMeta } from "./separator.ws";
47
+ import { propsMeta as CodePropsMeta } from "./code.ws";
55
48
 
56
49
  const defaultMetas: Record<string, WsComponentMeta> = {
57
50
  Box: BoxMeta,
@@ -70,6 +63,11 @@ const defaultMetas: Record<string, WsComponentMeta> = {
70
63
  Input: InputMeta,
71
64
  Form: FormMeta,
72
65
  Image: ImageMeta,
66
+ Blockquote: BlockquoteMeta,
67
+ List: ListMeta,
68
+ ListItem: ListItemMeta,
69
+ Separator: SeparatorMeta,
70
+ Code: CodeMeta,
73
71
  };
74
72
 
75
73
  let currentMetas = defaultMetas;
@@ -88,7 +86,7 @@ export const registerComponentMetas = (
88
86
  currentMetas = result;
89
87
  };
90
88
 
91
- const defaultPropsMetas: Record<string, WsComponentPropsMeta> = {
89
+ const defaultPropsMetasRaw = {
92
90
  Box: BoxMetaPropsMeta,
93
91
  Body: BodyMetaPropsMeta,
94
92
  TextBlock: TextBlockMetaPropsMeta,
@@ -105,7 +103,15 @@ const defaultPropsMetas: Record<string, WsComponentPropsMeta> = {
105
103
  Input: InputMetaPropsMeta,
106
104
  Form: FormMetaPropsMeta,
107
105
  Image: ImageMetaPropsMeta,
108
- };
106
+ Blockquote: BlockquotePropsMeta,
107
+ List: ListPropsMeta,
108
+ ListItem: ListItemPropsMeta,
109
+ Separator: SeparatorPropsMeta,
110
+ Code: CodePropsMeta,
111
+ } as const;
112
+
113
+ const defaultPropsMetas: Record<string, WsComponentPropsMeta> =
114
+ defaultPropsMetasRaw;
109
115
 
110
116
  let registeredPropsMetas: Record<string, Partial<WsComponentPropsMeta>> = {};
111
117
 
@@ -142,53 +148,12 @@ export const registerComponentPropsMetas = (
142
148
  currentPropsMetas = undefined;
143
149
  };
144
150
 
145
- const defaultComponents = {
146
- Box,
147
- Body,
148
- TextBlock,
149
- Heading,
150
- Paragraph,
151
- Link,
152
- RichTextLink,
153
- Span,
154
- Bold,
155
- Italic,
156
- Superscript,
157
- Subscript,
158
- Button,
159
- Input,
160
- Form,
161
- Image,
162
- } as const;
163
-
164
- export type ComponentName = keyof typeof defaultComponents;
165
151
  type RegisteredComponents = Partial<{
166
152
  // eslint-disable-next-line @typescript-eslint/ban-types
167
153
  [name in ComponentName]: {};
168
154
  }>;
169
155
 
170
- let registeredComponents: RegisteredComponents | null = null;
171
-
172
- const componentNames = Object.keys(defaultComponents) as ComponentName[];
173
-
174
- export const getComponentNames = (): ComponentName[] => {
175
- const uniqueNames = new Set([
176
- ...componentNames,
177
- ...Object.keys(registeredComponents || {}),
178
- ]);
179
-
180
- return [...uniqueNames.values()] as ComponentName[];
181
- };
182
-
183
- export const getComponent = (
184
- name: string
185
- ): undefined | typeof defaultComponents[ComponentName] => {
186
- return registeredComponents != null && name in registeredComponents
187
- ? (registeredComponents[
188
- name as ComponentName
189
- ] as typeof defaultComponents[ComponentName])
190
- : defaultComponents[name as ComponentName];
191
- };
156
+ export let registeredComponents: RegisteredComponents | undefined;
192
157
 
193
158
  /**
194
159
  * @todo: Allow register any component.
@@ -232,7 +197,7 @@ const computeInitialProps = (
232
197
  ? Object.entries(props)
233
198
  .filter(
234
199
  ([name, value]) =>
235
- value?.type.required && initialProps.includes(name) === false
200
+ value?.required && initialProps.includes(name) === false
236
201
  )
237
202
  .map(([name]) => name)
238
203
  : [];
@@ -1,6 +1,6 @@
1
1
  import { InputIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/input.props.json";
3
+ import { props } from "./__generated__/input.props";
4
4
 
5
5
  export const meta: WsComponentMeta = {
6
6
  type: "control",
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
8
8
  Icon: InputIcon,
9
9
  };
10
10
 
11
- export const propsMeta = {
11
+ export const propsMeta: WsComponentPropsMeta = {
12
12
  props,
13
- } as WsComponentPropsMeta;
13
+ };
@@ -1,6 +1,6 @@
1
1
  import { FontItalicIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/italic.props.json";
3
+ import { props } from "./__generated__/italic.props";
4
4
 
5
5
  const presetStyle = {
6
6
  fontStyle: {
@@ -16,6 +16,6 @@ export const meta: WsComponentMeta = {
16
16
  presetStyle,
17
17
  };
18
18
 
19
- export const propsMeta = {
19
+ export const propsMeta: WsComponentPropsMeta = {
20
20
  props,
21
- } as WsComponentPropsMeta;
21
+ };
@@ -1,6 +1,6 @@
1
1
  import { Link2Icon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/link.props.json";
3
+ import { props } from "./__generated__/link.props";
4
4
 
5
5
  const presetStyle = {
6
6
  minHeight: {
@@ -22,7 +22,7 @@ export const meta: WsComponentMeta = {
22
22
  children: ["Link text you can edit"],
23
23
  };
24
24
 
25
- export const propsMeta = {
25
+ export const propsMeta: WsComponentPropsMeta = {
26
26
  props,
27
27
  initialProps: ["href"],
28
- } as WsComponentPropsMeta;
28
+ };
@@ -0,0 +1,16 @@
1
+ import type { ComponentStory, ComponentMeta } from "@storybook/react";
2
+ import { ListItem as ListItemPrimitive } from "./list-item";
3
+
4
+ export default {
5
+ title: "Components/List Item",
6
+ component: ListItemPrimitive,
7
+ } as ComponentMeta<typeof ListItemPrimitive>;
8
+
9
+ const Template: ComponentStory<typeof ListItemPrimitive> = (args) => (
10
+ <ListItemPrimitive {...args} />
11
+ );
12
+
13
+ export const ListItem = Template.bind({});
14
+ ListItem.args = {
15
+ children: "ListItem",
16
+ };
@@ -0,0 +1,18 @@
1
+ import {
2
+ forwardRef,
3
+ createElement,
4
+ type ElementRef,
5
+ type ComponentProps,
6
+ } from "react";
7
+
8
+ const defaultTag = "li";
9
+
10
+ type Props = ComponentProps<typeof defaultTag>;
11
+
12
+ export const ListItem = forwardRef<ElementRef<typeof defaultTag>, Props>(
13
+ (props, ref) => {
14
+ return createElement(defaultTag, { ...props, ref });
15
+ }
16
+ );
17
+
18
+ ListItem.displayName = "ListItem";
@@ -0,0 +1,14 @@
1
+ import { ListItemIcon } from "@webstudio-is/icons";
2
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
+ import { props } from "./__generated__/list-item.props";
4
+
5
+ export const meta: WsComponentMeta = {
6
+ type: "rich-text",
7
+ label: "List Item",
8
+ Icon: ListItemIcon,
9
+ children: ["List Item you can edit"],
10
+ };
11
+
12
+ export const propsMeta: WsComponentPropsMeta = {
13
+ props,
14
+ };
@@ -0,0 +1,17 @@
1
+ import type { ComponentStory, ComponentMeta } from "@storybook/react";
2
+ import { List as ListPrimitive } from "./list";
3
+ import { ListItem } from "./list-item";
4
+
5
+ export default {
6
+ title: "Components/List",
7
+ component: ListPrimitive,
8
+ } as ComponentMeta<typeof ListPrimitive>;
9
+
10
+ const Template: ComponentStory<typeof ListPrimitive> = (args) => (
11
+ <ListPrimitive {...args} />
12
+ );
13
+
14
+ export const List = Template.bind({});
15
+ List.args = {
16
+ children: <ListItem />,
17
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ forwardRef,
3
+ createElement,
4
+ type ElementRef,
5
+ type ComponentProps,
6
+ } from "react";
7
+
8
+ const unorderedTag = "ul";
9
+ const orderedTag = "ol";
10
+
11
+ type Props = ComponentProps<typeof unorderedTag> &
12
+ ComponentProps<typeof orderedTag> & {
13
+ ordered?: boolean;
14
+ };
15
+
16
+ export const List = forwardRef<
17
+ ElementRef<typeof unorderedTag | typeof orderedTag>,
18
+ Props
19
+ >(({ ordered = false, ...props }, ref) => {
20
+ const tag = ordered ? orderedTag : unorderedTag;
21
+ return createElement(tag, { ...props, ref });
22
+ });
23
+
24
+ List.displayName = "List";
@@ -0,0 +1,31 @@
1
+ import { ListIcon } from "@webstudio-is/icons";
2
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
+ import { props } from "./__generated__/list.props";
4
+
5
+ const presetStyle = {
6
+ marginTop: {
7
+ type: "keyword",
8
+ value: "0",
9
+ },
10
+ marginBottom: {
11
+ type: "keyword",
12
+ value: "10px",
13
+ },
14
+ paddingLeft: {
15
+ type: "keyword",
16
+ value: "40px",
17
+ },
18
+ } as const;
19
+
20
+ export const meta: WsComponentMeta = {
21
+ type: "container",
22
+ label: "List",
23
+ Icon: ListIcon,
24
+ presetStyle,
25
+ children: [],
26
+ };
27
+
28
+ export const propsMeta: WsComponentPropsMeta = {
29
+ props,
30
+ initialProps: ["ordered", "type", "starts", "reversed"],
31
+ };
@@ -1,6 +1,6 @@
1
1
  import { TextAlignLeftIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/paragraph.props.json";
3
+ import { props } from "./__generated__/paragraph.props";
4
4
 
5
5
  export const meta: WsComponentMeta = {
6
6
  type: "rich-text",
@@ -9,6 +9,6 @@ export const meta: WsComponentMeta = {
9
9
  children: ["Pragraph you can edit"],
10
10
  };
11
11
 
12
- export const propsMeta = {
12
+ export const propsMeta: WsComponentPropsMeta = {
13
13
  props,
14
- } as WsComponentPropsMeta;
14
+ };
@@ -1,6 +1,6 @@
1
1
  import { Link2Icon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/rich-text-link.props.json";
3
+ import { props } from "./__generated__/rich-text-link.props";
4
4
 
5
5
  export const meta: WsComponentMeta = {
6
6
  type: "rich-text-child",
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
8
8
  Icon: Link2Icon,
9
9
  };
10
10
 
11
- export const propsMeta = {
11
+ export const propsMeta: WsComponentPropsMeta = {
12
12
  props,
13
- } as WsComponentPropsMeta;
13
+ };
@@ -0,0 +1,14 @@
1
+ import type { ComponentStory, ComponentMeta } from "@storybook/react";
2
+ import { Separator as SeparatorPrimitive } from "./separator";
3
+
4
+ export default {
5
+ title: "Components/Separator",
6
+ component: SeparatorPrimitive,
7
+ } as ComponentMeta<typeof SeparatorPrimitive>;
8
+
9
+ const Template: ComponentStory<typeof SeparatorPrimitive> = (args) => (
10
+ <SeparatorPrimitive {...args} />
11
+ );
12
+
13
+ export const Separator = Template.bind({});
14
+ Separator.args = {};
@@ -0,0 +1,18 @@
1
+ import {
2
+ forwardRef,
3
+ createElement,
4
+ type ElementRef,
5
+ type ComponentProps,
6
+ } from "react";
7
+
8
+ const defaultTag = "hr";
9
+
10
+ type Props = ComponentProps<typeof defaultTag>;
11
+
12
+ export const Separator = forwardRef<ElementRef<typeof defaultTag>, Props>(
13
+ (props, ref) => {
14
+ return createElement(defaultTag, { ...props, ref });
15
+ }
16
+ );
17
+
18
+ Separator.displayName = "Separator";
@@ -0,0 +1,31 @@
1
+ import { DashIcon } from "@webstudio-is/icons";
2
+ import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
+ import { props } from "./__generated__/separator.props";
4
+
5
+ const presetStyle = {
6
+ height: {
7
+ type: "keyword",
8
+ value: "1px",
9
+ },
10
+ backgroundColor: {
11
+ type: "keyword",
12
+ value: "gray",
13
+ },
14
+ border: {
15
+ type: "keyword",
16
+ value: "none",
17
+ },
18
+ } as const;
19
+
20
+ export const meta: WsComponentMeta = {
21
+ type: "embed",
22
+ label: "Separator",
23
+ Icon: DashIcon,
24
+ presetStyle,
25
+ children: [],
26
+ };
27
+
28
+ export const propsMeta: WsComponentPropsMeta = {
29
+ props,
30
+ initialProps: [],
31
+ };
@@ -1,6 +1,6 @@
1
1
  import { BrushIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/span.props.json";
3
+ import { props } from "./__generated__/span.props";
4
4
 
5
5
  export const meta: WsComponentMeta = {
6
6
  type: "rich-text-child",
@@ -8,6 +8,6 @@ export const meta: WsComponentMeta = {
8
8
  Icon: BrushIcon,
9
9
  };
10
10
 
11
- export const propsMeta = {
11
+ export const propsMeta: WsComponentPropsMeta = {
12
12
  props,
13
- } as WsComponentPropsMeta;
13
+ };