@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
@@ -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,11 +1,14 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
3
  const Link = forwardRef(
4
- ({ href = "", ...props }, ref) => /* @__PURE__ */ jsx("a", {
5
- ...props,
6
- href,
7
- ref
8
- })
4
+ ({ href = "", target = "self", ...props }, ref) => {
5
+ return /* @__PURE__ */ jsx("a", {
6
+ ...props,
7
+ target: `_${target}`,
8
+ href,
9
+ ref
10
+ });
11
+ }
9
12
  );
10
13
  Link.displayName = "Link";
11
14
  export {
@@ -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",
@@ -20,7 +20,7 @@ const meta = {
20
20
  };
21
21
  const propsMeta = {
22
22
  props,
23
- initialProps: ["href"]
23
+ initialProps: ["href", "target", "prefetch"]
24
24
  };
25
25
  export {
26
26
  meta,
@@ -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,12 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { forwardRef } from "react";
3
- const RichTextLink = forwardRef(
4
- ({ href = "", ...props }, ref) => /* @__PURE__ */ jsx("a", {
5
- ...props,
6
- href,
7
- ref
8
- })
9
- );
3
+ import { Link } from "./link";
4
+ const RichTextLink = forwardRef((props, ref) => /* @__PURE__ */ jsx(Link, {
5
+ ...props,
6
+ ref
7
+ }));
10
8
  RichTextLink.displayName = "RichTextLink";
11
9
  export {
12
10
  RichTextLink
@@ -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/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,
@@ -8,11 +8,13 @@ const createElementsTree = ({
8
8
  instance,
9
9
  propsByInstanceIdStore,
10
10
  assetsStore,
11
- Component
11
+ Component,
12
+ getComponent
12
13
  }) => {
13
14
  const children = createInstanceChildrenElements({
14
15
  Component,
15
- children: instance.children
16
+ children: instance.children,
17
+ getComponent
16
18
  });
17
19
  const body = createInstanceElement({
18
20
  Component,
@@ -26,7 +28,8 @@ const createElementsTree = ({
26
28
  /* @__PURE__ */ jsx(Scripts, {})
27
29
  ]
28
30
  }, "children")
29
- ]
31
+ ],
32
+ getComponent
30
33
  });
31
34
  return /* @__PURE__ */ jsx(ReactSdkContext.Provider, {
32
35
  value: { propsByInstanceIdStore, assetsStore },
@@ -35,7 +38,8 @@ const createElementsTree = ({
35
38
  };
36
39
  const createInstanceChildrenElements = ({
37
40
  children,
38
- Component
41
+ Component,
42
+ getComponent
39
43
  }) => {
40
44
  const elements = [];
41
45
  for (const child of children) {
@@ -45,12 +49,14 @@ const createInstanceChildrenElements = ({
45
49
  }
46
50
  const children2 = createInstanceChildrenElements({
47
51
  children: child.children,
48
- Component
52
+ Component,
53
+ getComponent
49
54
  });
50
55
  const element = createInstanceElement({
51
56
  instance: child,
52
57
  Component,
53
- children: children2
58
+ children: children2,
59
+ getComponent
54
60
  });
55
61
  elements.push(element);
56
62
  }
@@ -59,12 +65,14 @@ const createInstanceChildrenElements = ({
59
65
  const createInstanceElement = ({
60
66
  Component,
61
67
  instance,
62
- children = []
68
+ children = [],
69
+ getComponent
63
70
  }) => {
64
71
  const props = {
65
72
  instance,
66
73
  children,
67
- key: instance.id
74
+ key: instance.id,
75
+ getComponent
68
76
  };
69
77
  return /* @__PURE__ */ jsx(Component, {
70
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,9 +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
23
  children,
24
+ getComponent,
25
25
  ...rest
26
26
  }) => {
27
27
  const instanceProps = useInstanceProps(instance.id);
@@ -37,16 +37,16 @@ const WrapperComponent = ({
37
37
  }
38
38
  return /* @__PURE__ */ jsx(Component, {
39
39
  ...props,
40
- children: renderWrapperComponentChildren(children)
40
+ children: renderWebstudioComponentChildren(children)
41
41
  });
42
42
  };
43
43
  const idAttribute = "data-ws-id";
44
44
  const componentAttribute = "data-ws-component";
45
45
  const collapsedAttribute = "data-ws-collapsed";
46
46
  export {
47
- WrapperComponent,
47
+ WebstudioComponent,
48
48
  collapsedAttribute,
49
49
  componentAttribute,
50
50
  idAttribute,
51
- renderWrapperComponentChildren
51
+ renderWebstudioComponentChildren
52
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.35.0",
3
+ "version": "0.40.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.35.0",
50
- "@webstudio-is/css-data": "^0.35.0",
51
- "@webstudio-is/generate-arg-types": "^0.35.0",
52
- "@webstudio-is/icons": "^0.35.0",
53
- "@webstudio-is/image": "^0.35.0",
54
- "@webstudio-is/prisma-client": "^0.35.0",
55
- "@webstudio-is/project-build": "^0.35.0"
49
+ "@webstudio-is/asset-uploader": "^0.40.0",
50
+ "@webstudio-is/css-data": "^0.40.0",
51
+ "@webstudio-is/css-vars": "^0.40.0",
52
+ "@webstudio-is/generate-arg-types": "^0.40.0",
53
+ "@webstudio-is/icons": "^0.40.0",
54
+ "@webstudio-is/image": "^0.40.0",
55
+ "@webstudio-is/prisma-client": "^0.40.0",
56
+ "@webstudio-is/project-build": "^0.40.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",