@webstudio-is/react-sdk 0.35.0 → 0.40.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 (238) 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/app/custom-components/shared/remix-link.js +2 -2
  4. package/lib/cjs/app/custom-components/image.cjs +2 -2
  5. package/lib/cjs/app/custom-components/index.cjs +1 -6
  6. package/lib/cjs/app/custom-components/shared/remix-link.cjs +2 -2
  7. package/lib/cjs/components/__generated__/blockquote.props.cjs +414 -0
  8. package/lib/cjs/components/__generated__/body.props.cjs +413 -0
  9. package/lib/cjs/components/__generated__/bold.props.cjs +413 -0
  10. package/lib/cjs/components/__generated__/box.props.cjs +431 -0
  11. package/lib/cjs/components/__generated__/button.props.cjs +430 -0
  12. package/lib/cjs/components/__generated__/code.props.cjs +420 -0
  13. package/lib/cjs/components/__generated__/form.props.cjs +421 -0
  14. package/lib/cjs/components/__generated__/heading.props.cjs +420 -0
  15. package/lib/cjs/components/__generated__/image.props.cjs +454 -0
  16. package/lib/cjs/components/__generated__/input.props.cjs +451 -0
  17. package/lib/cjs/components/__generated__/italic.props.cjs +413 -0
  18. package/lib/cjs/components/__generated__/link.props.cjs +449 -0
  19. package/lib/cjs/components/__generated__/list-item.props.cjs +414 -0
  20. package/lib/cjs/components/__generated__/list.props.cjs +427 -0
  21. package/lib/cjs/components/__generated__/paragraph.props.cjs +413 -0
  22. package/lib/cjs/components/__generated__/rich-text-link.props.cjs +448 -0
  23. package/lib/cjs/components/__generated__/separator.props.cjs +413 -0
  24. package/lib/cjs/components/__generated__/span.props.cjs +413 -0
  25. package/lib/cjs/components/__generated__/subscript.props.cjs +413 -0
  26. package/lib/cjs/components/__generated__/superscript.props.cjs +413 -0
  27. package/lib/cjs/components/__generated__/text-block.props.cjs +413 -0
  28. package/lib/cjs/components/blockquote.cjs +31 -0
  29. package/lib/cjs/components/blockquote.ws.cjs +75 -0
  30. package/lib/cjs/components/body.ws.cjs +2 -8
  31. package/lib/cjs/components/bold.ws.cjs +2 -8
  32. package/lib/cjs/components/box.ws.cjs +2 -8
  33. package/lib/cjs/components/button.ws.cjs +2 -8
  34. package/lib/cjs/components/code.cjs +38 -0
  35. package/lib/cjs/components/code.ws.cjs +66 -0
  36. package/lib/cjs/components/components-utils.cjs +71 -0
  37. package/lib/cjs/components/components.cjs +64 -0
  38. package/lib/cjs/components/form.ws.cjs +2 -8
  39. package/lib/cjs/components/heading.ws.cjs +2 -8
  40. package/lib/cjs/components/image.ws.cjs +8 -9
  41. package/lib/cjs/components/index.cjs +28 -53
  42. package/lib/cjs/components/input.ws.cjs +2 -8
  43. package/lib/cjs/components/italic.ws.cjs +2 -8
  44. package/lib/cjs/components/link.cjs +8 -5
  45. package/lib/cjs/components/link.ws.cjs +3 -9
  46. package/lib/cjs/components/list-item.cjs +31 -0
  47. package/lib/cjs/components/list-item.ws.cjs +35 -0
  48. package/lib/cjs/components/list.cjs +31 -0
  49. package/lib/cjs/components/list.ws.cjs +51 -0
  50. package/lib/cjs/components/paragraph.ws.cjs +2 -8
  51. package/lib/cjs/components/rich-text-link.cjs +5 -7
  52. package/lib/cjs/components/rich-text-link.ws.cjs +2 -8
  53. package/lib/cjs/components/separator.cjs +31 -0
  54. package/lib/cjs/components/separator.ws.cjs +51 -0
  55. package/lib/cjs/components/span.ws.cjs +2 -8
  56. package/lib/cjs/components/subscript.ws.cjs +2 -8
  57. package/lib/cjs/components/superscript.ws.cjs +2 -8
  58. package/lib/cjs/components/text-block.ws.cjs +2 -8
  59. package/lib/cjs/css/get-browser-style.cjs +13 -5
  60. package/lib/cjs/index.cjs +2 -0
  61. package/lib/cjs/tree/create-elements-tree.cjs +16 -8
  62. package/lib/cjs/tree/index.cjs +1 -1
  63. package/lib/cjs/tree/root.cjs +28 -4
  64. package/lib/cjs/tree/{wrapper-component.cjs → webstudio-component.cjs} +10 -10
  65. package/lib/components/__generated__/blockquote.props.js +394 -0
  66. package/lib/components/__generated__/body.props.js +393 -0
  67. package/lib/components/__generated__/bold.props.js +393 -0
  68. package/lib/components/__generated__/box.props.js +411 -0
  69. package/lib/components/__generated__/button.props.js +410 -0
  70. package/lib/components/__generated__/code.props.js +400 -0
  71. package/lib/components/__generated__/form.props.js +401 -0
  72. package/lib/components/__generated__/heading.props.js +400 -0
  73. package/lib/components/__generated__/image.props.js +434 -0
  74. package/lib/components/__generated__/input.props.js +431 -0
  75. package/lib/components/__generated__/italic.props.js +393 -0
  76. package/lib/components/__generated__/link.props.js +429 -0
  77. package/lib/components/__generated__/list-item.props.js +394 -0
  78. package/lib/components/__generated__/list.props.js +407 -0
  79. package/lib/components/__generated__/paragraph.props.js +393 -0
  80. package/lib/components/__generated__/rich-text-link.props.js +428 -0
  81. package/lib/components/__generated__/separator.props.js +393 -0
  82. package/lib/components/__generated__/span.props.js +393 -0
  83. package/lib/components/__generated__/subscript.props.js +393 -0
  84. package/lib/components/__generated__/superscript.props.js +393 -0
  85. package/lib/components/__generated__/text-block.props.js +393 -0
  86. package/lib/components/blockquote.js +14 -0
  87. package/lib/components/blockquote.ws.js +55 -0
  88. package/lib/components/body.ws.js +1 -1
  89. package/lib/components/bold.ws.js +1 -1
  90. package/lib/components/box.ws.js +1 -1
  91. package/lib/components/button.ws.js +1 -1
  92. package/lib/components/code.js +21 -0
  93. package/lib/components/code.ws.js +46 -0
  94. package/lib/components/components-utils.js +45 -0
  95. package/lib/components/components.js +44 -0
  96. package/lib/components/form.ws.js +1 -1
  97. package/lib/components/heading.ws.js +1 -1
  98. package/lib/components/image.ws.js +7 -2
  99. package/lib/components/index.js +28 -53
  100. package/lib/components/input.ws.js +1 -1
  101. package/lib/components/italic.ws.js +1 -1
  102. package/lib/components/link.js +8 -5
  103. package/lib/components/link.ws.js +2 -2
  104. package/lib/components/list-item.js +14 -0
  105. package/lib/components/list-item.ws.js +15 -0
  106. package/lib/components/list.js +14 -0
  107. package/lib/components/list.ws.js +31 -0
  108. package/lib/components/paragraph.ws.js +1 -1
  109. package/lib/components/rich-text-link.js +5 -7
  110. package/lib/components/rich-text-link.ws.js +1 -1
  111. package/lib/components/separator.js +14 -0
  112. package/lib/components/separator.ws.js +31 -0
  113. package/lib/components/span.ws.js +1 -1
  114. package/lib/components/subscript.ws.js +1 -1
  115. package/lib/components/superscript.ws.js +1 -1
  116. package/lib/components/text-block.ws.js +1 -1
  117. package/lib/css/get-browser-style.js +9 -1
  118. package/lib/index.js +2 -0
  119. package/lib/tree/create-elements-tree.js +16 -8
  120. package/lib/tree/index.js +1 -1
  121. package/lib/tree/root.js +28 -4
  122. package/lib/tree/{wrapper-component.js → webstudio-component.js} +6 -6
  123. package/package.json +14 -11
  124. package/src/app/custom-components/image.tsx +1 -1
  125. package/src/app/custom-components/index.ts +2 -7
  126. package/src/app/custom-components/shared/remix-link.tsx +4 -3
  127. package/src/components/__generated__/blockquote.props.ts +439 -0
  128. package/src/components/__generated__/body.props.ts +438 -0
  129. package/src/components/__generated__/bold.props.ts +438 -0
  130. package/src/components/__generated__/box.props.ts +456 -0
  131. package/src/components/__generated__/button.props.ts +455 -0
  132. package/src/components/__generated__/code.props.ts +445 -0
  133. package/src/components/__generated__/form.props.ts +446 -0
  134. package/src/components/__generated__/heading.props.ts +445 -0
  135. package/src/components/__generated__/image.props.ts +479 -0
  136. package/src/components/__generated__/input.props.ts +476 -0
  137. package/src/components/__generated__/italic.props.ts +438 -0
  138. package/src/components/__generated__/link.props.ts +474 -0
  139. package/src/components/__generated__/list-item.props.ts +439 -0
  140. package/src/components/__generated__/list.props.ts +452 -0
  141. package/src/components/__generated__/paragraph.props.ts +438 -0
  142. package/src/components/__generated__/rich-text-link.props.ts +473 -0
  143. package/src/components/__generated__/separator.props.ts +438 -0
  144. package/src/components/__generated__/span.props.ts +438 -0
  145. package/src/components/__generated__/subscript.props.ts +438 -0
  146. package/src/components/__generated__/superscript.props.ts +438 -0
  147. package/src/components/__generated__/text-block.props.ts +438 -0
  148. package/src/components/blockquote.stories.tsx +16 -0
  149. package/src/components/blockquote.tsx +18 -0
  150. package/src/components/blockquote.ws.tsx +55 -0
  151. package/src/components/body.ws.tsx +3 -3
  152. package/src/components/bold.ws.tsx +3 -3
  153. package/src/components/box.ws.ts +3 -3
  154. package/src/components/button.ws.tsx +3 -3
  155. package/src/components/code.stories.tsx +16 -0
  156. package/src/components/code.tsx +31 -0
  157. package/src/components/code.ws.tsx +46 -0
  158. package/src/components/components-utils.ts +75 -0
  159. package/src/components/components.ts +28 -0
  160. package/src/components/form.ws.tsx +3 -3
  161. package/src/components/heading.ws.tsx +3 -3
  162. package/src/components/image.ws.tsx +9 -4
  163. package/src/components/index.ts +28 -63
  164. package/src/components/input.ws.tsx +3 -3
  165. package/src/components/italic.ws.tsx +3 -3
  166. package/src/components/link.tsx +11 -2
  167. package/src/components/link.ws.tsx +4 -4
  168. package/src/components/list-item.stories.tsx +16 -0
  169. package/src/components/list-item.tsx +18 -0
  170. package/src/components/list-item.ws.tsx +14 -0
  171. package/src/components/list.stories.tsx +17 -0
  172. package/src/components/list.tsx +24 -0
  173. package/src/components/list.ws.tsx +31 -0
  174. package/src/components/paragraph.ws.tsx +3 -3
  175. package/src/components/rich-text-link.tsx +5 -4
  176. package/src/components/rich-text-link.ws.tsx +3 -3
  177. package/src/components/separator.stories.tsx +14 -0
  178. package/src/components/separator.tsx +18 -0
  179. package/src/components/separator.ws.tsx +31 -0
  180. package/src/components/span.ws.tsx +3 -3
  181. package/src/components/subscript.ws.tsx +3 -3
  182. package/src/components/superscript.ws.tsx +3 -3
  183. package/src/components/text-block.ws.tsx +3 -3
  184. package/src/css/get-browser-style.ts +14 -3
  185. package/src/index.ts +2 -0
  186. package/src/props.ts +1 -1
  187. package/src/tree/create-elements-tree.tsx +16 -4
  188. package/src/tree/index.ts +1 -1
  189. package/src/tree/root.ts +37 -5
  190. package/src/tree/{wrapper-component.tsx → webstudio-component.tsx} +10 -6
  191. package/lib/cjs/components/__generated__/body.props.json +0 -743
  192. package/lib/cjs/components/__generated__/bold.props.json +0 -743
  193. package/lib/cjs/components/__generated__/box.props.json +0 -765
  194. package/lib/cjs/components/__generated__/button.props.json +0 -824
  195. package/lib/cjs/components/__generated__/form.props.json +0 -799
  196. package/lib/cjs/components/__generated__/heading.props.json +0 -754
  197. package/lib/cjs/components/__generated__/image.props.json +0 -846
  198. package/lib/cjs/components/__generated__/input.props.json +0 -977
  199. package/lib/cjs/components/__generated__/italic.props.json +0 -743
  200. package/lib/cjs/components/__generated__/link.props.json +0 -820
  201. package/lib/cjs/components/__generated__/paragraph.props.json +0 -743
  202. package/lib/cjs/components/__generated__/rich-text-link.props.json +0 -820
  203. package/lib/cjs/components/__generated__/span.props.json +0 -743
  204. package/lib/cjs/components/__generated__/subscript.props.json +0 -743
  205. package/lib/cjs/components/__generated__/superscript.props.json +0 -743
  206. package/lib/cjs/components/__generated__/text-block.props.json +0 -743
  207. package/lib/components/__generated__/body.props.json +0 -743
  208. package/lib/components/__generated__/bold.props.json +0 -743
  209. package/lib/components/__generated__/box.props.json +0 -765
  210. package/lib/components/__generated__/button.props.json +0 -824
  211. package/lib/components/__generated__/form.props.json +0 -799
  212. package/lib/components/__generated__/heading.props.json +0 -754
  213. package/lib/components/__generated__/image.props.json +0 -846
  214. package/lib/components/__generated__/input.props.json +0 -977
  215. package/lib/components/__generated__/italic.props.json +0 -743
  216. package/lib/components/__generated__/link.props.json +0 -820
  217. package/lib/components/__generated__/paragraph.props.json +0 -743
  218. package/lib/components/__generated__/rich-text-link.props.json +0 -820
  219. package/lib/components/__generated__/span.props.json +0 -743
  220. package/lib/components/__generated__/subscript.props.json +0 -743
  221. package/lib/components/__generated__/superscript.props.json +0 -743
  222. package/lib/components/__generated__/text-block.props.json +0 -743
  223. package/src/components/__generated__/body.props.json +0 -743
  224. package/src/components/__generated__/bold.props.json +0 -743
  225. package/src/components/__generated__/box.props.json +0 -765
  226. package/src/components/__generated__/button.props.json +0 -824
  227. package/src/components/__generated__/form.props.json +0 -799
  228. package/src/components/__generated__/heading.props.json +0 -754
  229. package/src/components/__generated__/image.props.json +0 -846
  230. package/src/components/__generated__/input.props.json +0 -977
  231. package/src/components/__generated__/italic.props.json +0 -743
  232. package/src/components/__generated__/link.props.json +0 -820
  233. package/src/components/__generated__/paragraph.props.json +0 -743
  234. package/src/components/__generated__/rich-text-link.props.json +0 -820
  235. package/src/components/__generated__/span.props.json +0 -743
  236. package/src/components/__generated__/subscript.props.json +0 -743
  237. package/src/components/__generated__/superscript.props.json +0 -743
  238. package/src/components/__generated__/text-block.props.json +0 -743
@@ -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,9 +1,18 @@
1
1
  import { forwardRef, type ElementRef, type ComponentProps } from "react";
2
2
 
3
- type Props = Omit<ComponentProps<"a">, "href"> & { href?: string };
3
+ // @todo props that come from remix link, shouldn't be here at all
4
+ // - prefetch should be only on remix component and it already is
5
+ // - props meta should be generated from Remix link
6
+ type Props = Omit<ComponentProps<"a">, "href" | "target"> & {
7
+ href?: string;
8
+ target?: "self" | "blank" | "parent" | "top";
9
+ prefetch?: "none" | "intent" | "render";
10
+ };
4
11
 
5
12
  export const Link = forwardRef<ElementRef<"a">, Props>(
6
- ({ href = "", ...props }, ref) => <a {...props} href={href} ref={ref} />
13
+ ({ href = "", target = "self", ...props }, ref) => {
14
+ return <a {...props} target={`_${target}`} href={href} ref={ref} />;
15
+ }
7
16
  );
8
17
 
9
18
  Link.displayName = "Link";
@@ -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
- initialProps: ["href"],
28
- } as WsComponentPropsMeta;
27
+ initialProps: ["href", "target", "prefetch"],
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,9 +1,10 @@
1
1
  import { forwardRef, type ElementRef, type ComponentProps } from "react";
2
+ import { Link } from "./link";
2
3
 
3
- type Props = Omit<ComponentProps<"a">, "href"> & { href?: string };
4
+ type Props = ComponentProps<typeof Link>;
4
5
 
5
- export const RichTextLink = forwardRef<ElementRef<"a">, Props>(
6
- ({ href = "", ...props }, ref) => <a {...props} href={href} ref={ref} />
7
- );
6
+ export const RichTextLink = forwardRef<ElementRef<"a">, Props>((props, ref) => (
7
+ <Link {...props} ref={ref} />
8
+ ));
8
9
 
9
10
  RichTextLink.displayName = "RichTextLink";
@@ -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";