@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
@@ -1,5 +1,5 @@
1
1
  import { ImageIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/image.props.json";
2
+ import { props } from "./__generated__/image.props";
3
3
  const presetStyle = {
4
4
  maxWidth: {
5
5
  type: "unit",
@@ -20,7 +20,12 @@ const meta = {
20
20
  const propsMeta = {
21
21
  props: {
22
22
  ...props,
23
- src: { ...props.src, control: "file-image", name: "Source" }
23
+ src: {
24
+ type: "string",
25
+ control: "file-image",
26
+ label: "Source",
27
+ required: false
28
+ }
24
29
  },
25
30
  initialProps: ["src", "width", "height", "alt", "loading"]
26
31
  };
@@ -15,6 +15,11 @@ import { meta as ButtonMeta } from "./button.ws";
15
15
  import { meta as InputMeta } from "./input.ws";
16
16
  import { meta as FormMeta } from "./form.ws";
17
17
  import { meta as ImageMeta } from "./image.ws";
18
+ import { meta as BlockquoteMeta } from "./blockquote.ws";
19
+ import { meta as ListMeta } from "./list.ws";
20
+ import { meta as ListItemMeta } from "./list-item.ws";
21
+ import { meta as SeparatorMeta } from "./separator.ws";
22
+ import { meta as CodeMeta } from "./code.ws";
18
23
  import { propsMeta as BodyMetaPropsMeta } from "./body.ws";
19
24
  import { propsMeta as BoxMetaPropsMeta } from "./box.ws";
20
25
  import { propsMeta as TextBlockMetaPropsMeta } from "./text-block.ws";
@@ -31,22 +36,11 @@ import { propsMeta as ButtonMetaPropsMeta } from "./button.ws";
31
36
  import { propsMeta as InputMetaPropsMeta } from "./input.ws";
32
37
  import { propsMeta as FormMetaPropsMeta } from "./form.ws";
33
38
  import { propsMeta as ImageMetaPropsMeta } from "./image.ws";
34
- import { Body } from "./body";
35
- import { Box } from "./box";
36
- import { TextBlock } from "./text-block";
37
- import { Heading } from "./heading";
38
- import { Paragraph } from "./paragraph";
39
- import { Link } from "./link";
40
- import { RichTextLink } from "./rich-text-link";
41
- import { Span } from "./span";
42
- import { Bold } from "./bold";
43
- import { Italic } from "./italic";
44
- import { Superscript } from "./superscript";
45
- import { Subscript } from "./subscript";
46
- import { Button } from "./button";
47
- import { Input } from "./input";
48
- import { Form } from "./form";
49
- import { Image } from "./image";
39
+ import { propsMeta as BlockquotePropsMeta } from "./blockquote.ws";
40
+ import { propsMeta as ListPropsMeta } from "./list.ws";
41
+ import { propsMeta as ListItemPropsMeta } from "./list-item.ws";
42
+ import { propsMeta as SeparatorPropsMeta } from "./separator.ws";
43
+ import { propsMeta as CodePropsMeta } from "./code.ws";
50
44
  const defaultMetas = {
51
45
  Box: BoxMeta,
52
46
  Body: BodyMeta,
@@ -63,7 +57,12 @@ const defaultMetas = {
63
57
  Button: ButtonMeta,
64
58
  Input: InputMeta,
65
59
  Form: FormMeta,
66
- Image: ImageMeta
60
+ Image: ImageMeta,
61
+ Blockquote: BlockquoteMeta,
62
+ List: ListMeta,
63
+ ListItem: ListItemMeta,
64
+ Separator: SeparatorMeta,
65
+ Code: CodeMeta
67
66
  };
68
67
  let currentMetas = defaultMetas;
69
68
  const getComponentMeta = (name) => {
@@ -76,7 +75,7 @@ const registerComponentMetas = (overrides) => {
76
75
  }
77
76
  currentMetas = result;
78
77
  };
79
- const defaultPropsMetas = {
78
+ const defaultPropsMetasRaw = {
80
79
  Box: BoxMetaPropsMeta,
81
80
  Body: BodyMetaPropsMeta,
82
81
  TextBlock: TextBlockMetaPropsMeta,
@@ -92,8 +91,14 @@ const defaultPropsMetas = {
92
91
  Button: ButtonMetaPropsMeta,
93
92
  Input: InputMetaPropsMeta,
94
93
  Form: FormMetaPropsMeta,
95
- Image: ImageMetaPropsMeta
94
+ Image: ImageMetaPropsMeta,
95
+ Blockquote: BlockquotePropsMeta,
96
+ List: ListPropsMeta,
97
+ ListItem: ListItemPropsMeta,
98
+ Separator: SeparatorPropsMeta,
99
+ Code: CodePropsMeta
96
100
  };
101
+ const defaultPropsMetas = defaultPropsMetasRaw;
97
102
  let registeredPropsMetas = {};
98
103
  let currentPropsMetas = void 0;
99
104
  const getComponentPropsMeta = (name) => {
@@ -118,36 +123,7 @@ const registerComponentPropsMetas = (metas) => {
118
123
  registeredPropsMetas = metas;
119
124
  currentPropsMetas = void 0;
120
125
  };
121
- const defaultComponents = {
122
- Box,
123
- Body,
124
- TextBlock,
125
- Heading,
126
- Paragraph,
127
- Link,
128
- RichTextLink,
129
- Span,
130
- Bold,
131
- Italic,
132
- Superscript,
133
- Subscript,
134
- Button,
135
- Input,
136
- Form,
137
- Image
138
- };
139
- let registeredComponents = null;
140
- const componentNames = Object.keys(defaultComponents);
141
- const getComponentNames = () => {
142
- const uniqueNames = /* @__PURE__ */ new Set([
143
- ...componentNames,
144
- ...Object.keys(registeredComponents || {})
145
- ]);
146
- return [...uniqueNames.values()];
147
- };
148
- const getComponent = (name) => {
149
- return registeredComponents != null && name in registeredComponents ? registeredComponents[name] : defaultComponents[name];
150
- };
126
+ let registeredComponents;
151
127
  const registerComponents = (components) => {
152
128
  registeredComponents = components;
153
129
  };
@@ -171,16 +147,15 @@ const computeProps = (defaults, overrides) => {
171
147
  const computeInitialProps = (props, defaults, overrides) => {
172
148
  const initialProps = overrides?.initialProps ?? defaults?.initialProps ?? [];
173
149
  const requiredProps = props ? Object.entries(props).filter(
174
- ([name, value]) => value?.type.required && initialProps.includes(name) === false
150
+ ([name, value]) => value?.required && initialProps.includes(name) === false
175
151
  ).map(([name]) => name) : [];
176
152
  return [...initialProps, ...requiredProps];
177
153
  };
178
154
  export {
179
- getComponent,
180
155
  getComponentMeta,
181
- getComponentNames,
182
156
  getComponentPropsMeta,
183
157
  registerComponentMetas,
184
158
  registerComponentPropsMetas,
185
- registerComponents
159
+ registerComponents,
160
+ registeredComponents
186
161
  };
@@ -1,5 +1,5 @@
1
1
  import { InputIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/input.props.json";
2
+ import { props } from "./__generated__/input.props";
3
3
  const meta = {
4
4
  type: "control",
5
5
  label: "Input",
@@ -1,5 +1,5 @@
1
1
  import { FontItalicIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/italic.props.json";
2
+ import { props } from "./__generated__/italic.props";
3
3
  const presetStyle = {
4
4
  fontStyle: {
5
5
  type: "keyword",
@@ -1,5 +1,5 @@
1
1
  import { Link2Icon } from "@webstudio-is/icons";
2
- import props from "./__generated__/link.props.json";
2
+ import { props } from "./__generated__/link.props";
3
3
  const presetStyle = {
4
4
  minHeight: {
5
5
  type: "unit",
@@ -0,0 +1,14 @@
1
+ import {
2
+ forwardRef,
3
+ createElement
4
+ } from "react";
5
+ const defaultTag = "li";
6
+ const ListItem = forwardRef(
7
+ (props, ref) => {
8
+ return createElement(defaultTag, { ...props, ref });
9
+ }
10
+ );
11
+ ListItem.displayName = "ListItem";
12
+ export {
13
+ ListItem
14
+ };
@@ -0,0 +1,15 @@
1
+ import { ListItemIcon } from "@webstudio-is/icons";
2
+ import { props } from "./__generated__/list-item.props";
3
+ const meta = {
4
+ type: "rich-text",
5
+ label: "List Item",
6
+ Icon: ListItemIcon,
7
+ children: ["List Item you can edit"]
8
+ };
9
+ const propsMeta = {
10
+ props
11
+ };
12
+ export {
13
+ meta,
14
+ propsMeta
15
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ forwardRef,
3
+ createElement
4
+ } from "react";
5
+ const unorderedTag = "ul";
6
+ const orderedTag = "ol";
7
+ const List = forwardRef(({ ordered = false, ...props }, ref) => {
8
+ const tag = ordered ? orderedTag : unorderedTag;
9
+ return createElement(tag, { ...props, ref });
10
+ });
11
+ List.displayName = "List";
12
+ export {
13
+ List
14
+ };
@@ -0,0 +1,31 @@
1
+ import { ListIcon } from "@webstudio-is/icons";
2
+ import { props } from "./__generated__/list.props";
3
+ const presetStyle = {
4
+ marginTop: {
5
+ type: "keyword",
6
+ value: "0"
7
+ },
8
+ marginBottom: {
9
+ type: "keyword",
10
+ value: "10px"
11
+ },
12
+ paddingLeft: {
13
+ type: "keyword",
14
+ value: "40px"
15
+ }
16
+ };
17
+ const meta = {
18
+ type: "container",
19
+ label: "List",
20
+ Icon: ListIcon,
21
+ presetStyle,
22
+ children: []
23
+ };
24
+ const propsMeta = {
25
+ props,
26
+ initialProps: ["ordered", "type", "starts", "reversed"]
27
+ };
28
+ export {
29
+ meta,
30
+ propsMeta
31
+ };
@@ -1,5 +1,5 @@
1
1
  import { TextAlignLeftIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/paragraph.props.json";
2
+ import { props } from "./__generated__/paragraph.props";
3
3
  const meta = {
4
4
  type: "rich-text",
5
5
  label: "Paragraph",
@@ -1,5 +1,5 @@
1
1
  import { Link2Icon } from "@webstudio-is/icons";
2
- import props from "./__generated__/rich-text-link.props.json";
2
+ import { props } from "./__generated__/rich-text-link.props";
3
3
  const meta = {
4
4
  type: "rich-text-child",
5
5
  label: "Link",
@@ -0,0 +1,14 @@
1
+ import {
2
+ forwardRef,
3
+ createElement
4
+ } from "react";
5
+ const defaultTag = "hr";
6
+ const Separator = forwardRef(
7
+ (props, ref) => {
8
+ return createElement(defaultTag, { ...props, ref });
9
+ }
10
+ );
11
+ Separator.displayName = "Separator";
12
+ export {
13
+ Separator
14
+ };
@@ -0,0 +1,31 @@
1
+ import { DashIcon } from "@webstudio-is/icons";
2
+ import { props } from "./__generated__/separator.props";
3
+ const presetStyle = {
4
+ height: {
5
+ type: "keyword",
6
+ value: "1px"
7
+ },
8
+ backgroundColor: {
9
+ type: "keyword",
10
+ value: "gray"
11
+ },
12
+ border: {
13
+ type: "keyword",
14
+ value: "none"
15
+ }
16
+ };
17
+ const meta = {
18
+ type: "embed",
19
+ label: "Separator",
20
+ Icon: DashIcon,
21
+ presetStyle,
22
+ children: []
23
+ };
24
+ const propsMeta = {
25
+ props,
26
+ initialProps: []
27
+ };
28
+ export {
29
+ meta,
30
+ propsMeta
31
+ };
@@ -1,5 +1,5 @@
1
1
  import { BrushIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/span.props.json";
2
+ import { props } from "./__generated__/span.props";
3
3
  const meta = {
4
4
  type: "rich-text-child",
5
5
  label: "Styled Text",
@@ -1,5 +1,5 @@
1
1
  import { SubscriptIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/subscript.props.json";
2
+ import { props } from "./__generated__/subscript.props";
3
3
  const meta = {
4
4
  type: "rich-text-child",
5
5
  label: "Subscript Text",
@@ -1,5 +1,5 @@
1
1
  import { SuperscriptIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/superscript.props.json";
2
+ import { props } from "./__generated__/superscript.props";
3
3
  const meta = {
4
4
  type: "rich-text-child",
5
5
  label: "Superscript Text",
@@ -1,5 +1,5 @@
1
1
  import { TextIcon } from "@webstudio-is/icons";
2
- import props from "./__generated__/text-block.props.json";
2
+ import { props } from "./__generated__/text-block.props";
3
3
  const presetStyle = {
4
4
  minHeight: {
5
5
  type: "unit",
@@ -1,4 +1,5 @@
1
1
  import { detectFont } from "detect-font";
2
+ import { keywordValues } from "@webstudio-is/css-data";
2
3
  import { properties, units } from "@webstudio-is/css-data";
3
4
  const unitsList = Object.values(units).flat();
4
5
  const unitRegex = new RegExp(`${unitsList.join("|")}`);
@@ -9,8 +10,15 @@ const parseValue = (property, value) => {
9
10
  value = "transparent";
10
11
  }
11
12
  if (Number.isNaN(number)) {
13
+ const values = keywordValues[property];
14
+ if (values?.includes(value)) {
15
+ return {
16
+ type: "keyword",
17
+ value
18
+ };
19
+ }
12
20
  return {
13
- type: "keyword",
21
+ type: "unparsed",
14
22
  value
15
23
  };
16
24
  }
package/lib/css/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./get-browser-style";
2
2
  export * from "./categories";
3
- export * from "./breakpoints";
package/lib/index.js CHANGED
@@ -3,6 +3,8 @@ export * from "./tree";
3
3
  export * from "./components";
4
4
  export * from "./pubsub";
5
5
  export * from "./app";
6
+ export * from "./components/components";
7
+ export * from "./components/components-utils";
6
8
  import {
7
9
  customComponents,
8
10
  customComponentMetas,
@@ -9,12 +9,12 @@ const createElementsTree = ({
9
9
  propsByInstanceIdStore,
10
10
  assetsStore,
11
11
  Component,
12
- onChangeChildren
12
+ getComponent
13
13
  }) => {
14
14
  const children = createInstanceChildrenElements({
15
15
  Component,
16
16
  children: instance.children,
17
- onChangeChildren
17
+ getComponent
18
18
  });
19
19
  const body = createInstanceElement({
20
20
  Component,
@@ -28,7 +28,8 @@ const createElementsTree = ({
28
28
  /* @__PURE__ */ jsx(Scripts, {})
29
29
  ]
30
30
  }, "children")
31
- ]
31
+ ],
32
+ getComponent
32
33
  });
33
34
  return /* @__PURE__ */ jsx(ReactSdkContext.Provider, {
34
35
  value: { propsByInstanceIdStore, assetsStore },
@@ -38,7 +39,7 @@ const createElementsTree = ({
38
39
  const createInstanceChildrenElements = ({
39
40
  children,
40
41
  Component,
41
- onChangeChildren
42
+ getComponent
42
43
  }) => {
43
44
  const elements = [];
44
45
  for (const child of children) {
@@ -49,13 +50,13 @@ const createInstanceChildrenElements = ({
49
50
  const children2 = createInstanceChildrenElements({
50
51
  children: child.children,
51
52
  Component,
52
- onChangeChildren
53
+ getComponent
53
54
  });
54
55
  const element = createInstanceElement({
55
56
  instance: child,
56
57
  Component,
57
- onChangeChildren,
58
- children: children2
58
+ children: children2,
59
+ getComponent
59
60
  });
60
61
  elements.push(element);
61
62
  }
@@ -65,13 +66,13 @@ const createInstanceElement = ({
65
66
  Component,
66
67
  instance,
67
68
  children = [],
68
- onChangeChildren
69
+ getComponent
69
70
  }) => {
70
71
  const props = {
71
72
  instance,
72
73
  children,
73
74
  key: instance.id,
74
- onChangeChildren
75
+ getComponent
75
76
  };
76
77
  return /* @__PURE__ */ jsx(Component, {
77
78
  ...props
package/lib/tree/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./create-elements-tree";
2
2
  export * from "./root";
3
- export * from "./wrapper-component";
3
+ export * from "./webstudio-component";
package/lib/tree/root.js CHANGED
@@ -1,14 +1,37 @@
1
1
  import { atom } from "nanostores";
2
2
  import { createElementsTree } from "./create-elements-tree";
3
- import { WrapperComponent } from "./wrapper-component";
3
+ import { WebstudioComponent } from "./webstudio-component";
4
4
  import { registerComponents } from "../components";
5
5
  import { customComponents as defaultCustomComponents } from "../app/custom-components";
6
6
  import { setParams } from "../app/params";
7
7
  import { getPropsByInstanceId } from "../props";
8
+ const denormalizeTree = (instances) => {
9
+ const convertTree = (instance) => {
10
+ const legacyInstance = {
11
+ type: "instance",
12
+ id: instance.id,
13
+ component: instance.component,
14
+ children: []
15
+ };
16
+ for (const child of instance.children) {
17
+ if (child.type === "id") {
18
+ const childInstance = instances.get(child.value);
19
+ if (childInstance) {
20
+ legacyInstance.children.push(convertTree(childInstance));
21
+ }
22
+ } else {
23
+ legacyInstance.children.push(child);
24
+ }
25
+ }
26
+ return legacyInstance;
27
+ };
28
+ return convertTree(Array.from(instances.values())[0]);
29
+ };
8
30
  const InstanceRoot = ({
9
31
  data,
10
32
  Component,
11
- customComponents = defaultCustomComponents
33
+ customComponents = defaultCustomComponents,
34
+ getComponent
12
35
  }) => {
13
36
  if (data.tree === null) {
14
37
  throw new Error("Tree is null");
@@ -16,12 +39,13 @@ const InstanceRoot = ({
16
39
  setParams(data.params ?? null);
17
40
  registerComponents(customComponents);
18
41
  return createElementsTree({
19
- instance: data.tree.root,
42
+ instance: denormalizeTree(new Map(data.tree.instances)),
20
43
  propsByInstanceIdStore: atom(
21
44
  getPropsByInstanceId(new Map(data.tree.props))
22
45
  ),
23
46
  assetsStore: atom(new Map(data.assets.map((asset) => [asset.id, asset]))),
24
- Component: Component ?? WrapperComponent
47
+ Component: Component ?? WebstudioComponent,
48
+ getComponent
25
49
  });
26
50
  };
27
51
  export {
@@ -1,6 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Fragment as Fragment2 } from "react";
3
- import { getComponent } from "../components";
4
3
  import { useInstanceProps } from "../props";
5
4
  const renderText = (text) => {
6
5
  const lines = text.split("\n");
@@ -11,7 +10,7 @@ const renderText = (text) => {
11
10
  ]
12
11
  }, index));
13
12
  };
14
- const renderWrapperComponentChildren = (children) => {
13
+ const renderWebstudioComponentChildren = (children) => {
15
14
  if (children === void 0 || children.length === 0) {
16
15
  return;
17
16
  }
@@ -19,10 +18,10 @@ const renderWrapperComponentChildren = (children) => {
19
18
  return typeof child === "string" ? renderText(child) : child;
20
19
  });
21
20
  };
22
- const WrapperComponent = ({
21
+ const WebstudioComponent = ({
23
22
  instance,
24
- onChangeChildren,
25
23
  children,
24
+ getComponent,
26
25
  ...rest
27
26
  }) => {
28
27
  const instanceProps = useInstanceProps(instance.id);
@@ -38,14 +37,16 @@ const WrapperComponent = ({
38
37
  }
39
38
  return /* @__PURE__ */ jsx(Component, {
40
39
  ...props,
41
- children: renderWrapperComponentChildren(children)
40
+ children: renderWebstudioComponentChildren(children)
42
41
  });
43
42
  };
44
43
  const idAttribute = "data-ws-id";
45
44
  const componentAttribute = "data-ws-component";
45
+ const collapsedAttribute = "data-ws-collapsed";
46
46
  export {
47
- WrapperComponent,
47
+ WebstudioComponent,
48
+ collapsedAttribute,
48
49
  componentAttribute,
49
50
  idAttribute,
50
- renderWrapperComponentChildren
51
+ renderWebstudioComponentChildren
51
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -46,17 +46,20 @@
46
46
  "mitt": "^3.0.0",
47
47
  "nanostores": "^0.7.1",
48
48
  "warn-once": "^0.1.1",
49
- "@webstudio-is/asset-uploader": "^0.34.0",
50
- "@webstudio-is/css-data": "^0.34.0",
51
- "@webstudio-is/generate-arg-types": "^0.34.0",
52
- "@webstudio-is/icons": "^0.34.0",
53
- "@webstudio-is/image": "^0.34.0",
54
- "@webstudio-is/prisma-client": "^0.34.0",
55
- "@webstudio-is/project-build": "^0.34.0"
49
+ "@webstudio-is/asset-uploader": "^0.36.0",
50
+ "@webstudio-is/css-data": "^0.36.0",
51
+ "@webstudio-is/css-vars": "^0.36.0",
52
+ "@webstudio-is/generate-arg-types": "^0.36.0",
53
+ "@webstudio-is/icons": "^0.36.0",
54
+ "@webstudio-is/image": "^0.36.0",
55
+ "@webstudio-is/prisma-client": "^0.36.0",
56
+ "@webstudio-is/project-build": "^0.36.0"
56
57
  },
57
58
  "exports": {
58
- "import": "./lib/index.js",
59
- "require": "./lib/cjs/index.cjs"
59
+ ".": {
60
+ "import": "./lib/index.js",
61
+ "require": "./lib/cjs/index.cjs"
62
+ }
60
63
  },
61
64
  "types": "src/index.ts",
62
65
  "files": [
@@ -70,7 +73,7 @@
70
73
  "scripts": {
71
74
  "dev": "build-package --watch",
72
75
  "build": "build-package",
73
- "build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.json\"",
76
+ "build:args": "generate-arg-types './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx' && prettier --write \"**/*.props.ts\"",
74
77
  "typecheck": "tsc --noEmit",
75
78
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
76
79
  "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
@@ -7,7 +7,7 @@ import {
7
7
  import { Image as WebstudioImage, loaders } from "@webstudio-is/image";
8
8
  import { Image as SdkImage } from "../../components/image";
9
9
  import { usePropAsset } from "../../props";
10
- import { idAttribute } from "../../tree/wrapper-component";
10
+ import { idAttribute } from "../../tree/webstudio-component";
11
11
  import { getParams } from "../params";
12
12
 
13
13
  const defaultTag = "img";
@@ -10,13 +10,8 @@ export const customComponents = {
10
10
  RichTextLink,
11
11
  };
12
12
 
13
- export const customComponentPropsMetas = {
14
- Image: {
15
- props: {
16
- ...imageProps,
17
- src: { ...imageProps.src, control: "file-image", name: "Source" },
18
- },
19
- } as WsComponentPropsMeta,
13
+ export const customComponentPropsMetas: Record<string, WsComponentPropsMeta> = {
14
+ Image: { props: imageProps },
20
15
  };
21
16
 
22
17
  // just for completeness, maybe we add soemthing here later