@webstudio-is/react-sdk 0.35.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 (229) 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/components/list-item.cjs +31 -0
  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/index.cjs +2 -0
  57. package/lib/cjs/tree/create-elements-tree.cjs +16 -8
  58. package/lib/cjs/tree/index.cjs +1 -1
  59. package/lib/cjs/tree/root.cjs +28 -4
  60. package/lib/cjs/tree/{wrapper-component.cjs → webstudio-component.cjs} +10 -10
  61. package/lib/components/__generated__/blockquote.props.js +394 -0
  62. package/lib/components/__generated__/body.props.js +393 -0
  63. package/lib/components/__generated__/bold.props.js +393 -0
  64. package/lib/components/__generated__/box.props.js +411 -0
  65. package/lib/components/__generated__/button.props.js +410 -0
  66. package/lib/components/__generated__/code.props.js +400 -0
  67. package/lib/components/__generated__/form.props.js +401 -0
  68. package/lib/components/__generated__/heading.props.js +400 -0
  69. package/lib/components/__generated__/image.props.js +434 -0
  70. package/lib/components/__generated__/input.props.js +431 -0
  71. package/lib/components/__generated__/italic.props.js +393 -0
  72. package/lib/components/__generated__/link.props.js +417 -0
  73. package/lib/components/__generated__/list-item.props.js +394 -0
  74. package/lib/components/__generated__/list.props.js +407 -0
  75. package/lib/components/__generated__/paragraph.props.js +393 -0
  76. package/lib/components/__generated__/rich-text-link.props.js +417 -0
  77. package/lib/components/__generated__/separator.props.js +393 -0
  78. package/lib/components/__generated__/span.props.js +393 -0
  79. package/lib/components/__generated__/subscript.props.js +393 -0
  80. package/lib/components/__generated__/superscript.props.js +393 -0
  81. package/lib/components/__generated__/text-block.props.js +393 -0
  82. package/lib/components/blockquote.js +14 -0
  83. package/lib/components/blockquote.ws.js +55 -0
  84. package/lib/components/body.ws.js +1 -1
  85. package/lib/components/bold.ws.js +1 -1
  86. package/lib/components/box.ws.js +1 -1
  87. package/lib/components/button.ws.js +1 -1
  88. package/lib/components/code.js +21 -0
  89. package/lib/components/code.ws.js +46 -0
  90. package/lib/components/components-utils.js +45 -0
  91. package/lib/components/components.js +44 -0
  92. package/lib/components/form.ws.js +1 -1
  93. package/lib/components/heading.ws.js +1 -1
  94. package/lib/components/image.ws.js +7 -2
  95. package/lib/components/index.js +28 -53
  96. package/lib/components/input.ws.js +1 -1
  97. package/lib/components/italic.ws.js +1 -1
  98. package/lib/components/link.ws.js +1 -1
  99. package/lib/components/list-item.js +14 -0
  100. package/lib/components/list-item.ws.js +15 -0
  101. package/lib/components/list.js +14 -0
  102. package/lib/components/list.ws.js +31 -0
  103. package/lib/components/paragraph.ws.js +1 -1
  104. package/lib/components/rich-text-link.ws.js +1 -1
  105. package/lib/components/separator.js +14 -0
  106. package/lib/components/separator.ws.js +31 -0
  107. package/lib/components/span.ws.js +1 -1
  108. package/lib/components/subscript.ws.js +1 -1
  109. package/lib/components/superscript.ws.js +1 -1
  110. package/lib/components/text-block.ws.js +1 -1
  111. package/lib/css/get-browser-style.js +9 -1
  112. package/lib/index.js +2 -0
  113. package/lib/tree/create-elements-tree.js +16 -8
  114. package/lib/tree/index.js +1 -1
  115. package/lib/tree/root.js +28 -4
  116. package/lib/tree/{wrapper-component.js → webstudio-component.js} +6 -6
  117. package/package.json +14 -11
  118. package/src/app/custom-components/image.tsx +1 -1
  119. package/src/app/custom-components/index.ts +2 -7
  120. package/src/components/__generated__/blockquote.props.ts +439 -0
  121. package/src/components/__generated__/body.props.ts +438 -0
  122. package/src/components/__generated__/bold.props.ts +438 -0
  123. package/src/components/__generated__/box.props.ts +456 -0
  124. package/src/components/__generated__/button.props.ts +455 -0
  125. package/src/components/__generated__/code.props.ts +445 -0
  126. package/src/components/__generated__/form.props.ts +446 -0
  127. package/src/components/__generated__/heading.props.ts +445 -0
  128. package/src/components/__generated__/image.props.ts +479 -0
  129. package/src/components/__generated__/input.props.ts +476 -0
  130. package/src/components/__generated__/italic.props.ts +438 -0
  131. package/src/components/__generated__/link.props.ts +462 -0
  132. package/src/components/__generated__/list-item.props.ts +439 -0
  133. package/src/components/__generated__/list.props.ts +452 -0
  134. package/src/components/__generated__/paragraph.props.ts +438 -0
  135. package/src/components/__generated__/rich-text-link.props.ts +462 -0
  136. package/src/components/__generated__/separator.props.ts +438 -0
  137. package/src/components/__generated__/span.props.ts +438 -0
  138. package/src/components/__generated__/subscript.props.ts +438 -0
  139. package/src/components/__generated__/superscript.props.ts +438 -0
  140. package/src/components/__generated__/text-block.props.ts +438 -0
  141. package/src/components/blockquote.stories.tsx +16 -0
  142. package/src/components/blockquote.tsx +18 -0
  143. package/src/components/blockquote.ws.tsx +55 -0
  144. package/src/components/body.ws.tsx +3 -3
  145. package/src/components/bold.ws.tsx +3 -3
  146. package/src/components/box.ws.ts +3 -3
  147. package/src/components/button.ws.tsx +3 -3
  148. package/src/components/code.stories.tsx +16 -0
  149. package/src/components/code.tsx +31 -0
  150. package/src/components/code.ws.tsx +46 -0
  151. package/src/components/components-utils.ts +75 -0
  152. package/src/components/components.ts +28 -0
  153. package/src/components/form.ws.tsx +3 -3
  154. package/src/components/heading.ws.tsx +3 -3
  155. package/src/components/image.ws.tsx +9 -4
  156. package/src/components/index.ts +28 -63
  157. package/src/components/input.ws.tsx +3 -3
  158. package/src/components/italic.ws.tsx +3 -3
  159. package/src/components/link.ws.tsx +3 -3
  160. package/src/components/list-item.stories.tsx +16 -0
  161. package/src/components/list-item.tsx +18 -0
  162. package/src/components/list-item.ws.tsx +14 -0
  163. package/src/components/list.stories.tsx +17 -0
  164. package/src/components/list.tsx +24 -0
  165. package/src/components/list.ws.tsx +31 -0
  166. package/src/components/paragraph.ws.tsx +3 -3
  167. package/src/components/rich-text-link.ws.tsx +3 -3
  168. package/src/components/separator.stories.tsx +14 -0
  169. package/src/components/separator.tsx +18 -0
  170. package/src/components/separator.ws.tsx +31 -0
  171. package/src/components/span.ws.tsx +3 -3
  172. package/src/components/subscript.ws.tsx +3 -3
  173. package/src/components/superscript.ws.tsx +3 -3
  174. package/src/components/text-block.ws.tsx +3 -3
  175. package/src/css/get-browser-style.ts +14 -3
  176. package/src/index.ts +2 -0
  177. package/src/props.ts +1 -1
  178. package/src/tree/create-elements-tree.tsx +16 -4
  179. package/src/tree/index.ts +1 -1
  180. package/src/tree/root.ts +37 -5
  181. package/src/tree/{wrapper-component.tsx → webstudio-component.tsx} +10 -6
  182. package/lib/cjs/components/__generated__/body.props.json +0 -743
  183. package/lib/cjs/components/__generated__/bold.props.json +0 -743
  184. package/lib/cjs/components/__generated__/box.props.json +0 -765
  185. package/lib/cjs/components/__generated__/button.props.json +0 -824
  186. package/lib/cjs/components/__generated__/form.props.json +0 -799
  187. package/lib/cjs/components/__generated__/heading.props.json +0 -754
  188. package/lib/cjs/components/__generated__/image.props.json +0 -846
  189. package/lib/cjs/components/__generated__/input.props.json +0 -977
  190. package/lib/cjs/components/__generated__/italic.props.json +0 -743
  191. package/lib/cjs/components/__generated__/link.props.json +0 -820
  192. package/lib/cjs/components/__generated__/paragraph.props.json +0 -743
  193. package/lib/cjs/components/__generated__/rich-text-link.props.json +0 -820
  194. package/lib/cjs/components/__generated__/span.props.json +0 -743
  195. package/lib/cjs/components/__generated__/subscript.props.json +0 -743
  196. package/lib/cjs/components/__generated__/superscript.props.json +0 -743
  197. package/lib/cjs/components/__generated__/text-block.props.json +0 -743
  198. package/lib/components/__generated__/body.props.json +0 -743
  199. package/lib/components/__generated__/bold.props.json +0 -743
  200. package/lib/components/__generated__/box.props.json +0 -765
  201. package/lib/components/__generated__/button.props.json +0 -824
  202. package/lib/components/__generated__/form.props.json +0 -799
  203. package/lib/components/__generated__/heading.props.json +0 -754
  204. package/lib/components/__generated__/image.props.json +0 -846
  205. package/lib/components/__generated__/input.props.json +0 -977
  206. package/lib/components/__generated__/italic.props.json +0 -743
  207. package/lib/components/__generated__/link.props.json +0 -820
  208. package/lib/components/__generated__/paragraph.props.json +0 -743
  209. package/lib/components/__generated__/rich-text-link.props.json +0 -820
  210. package/lib/components/__generated__/span.props.json +0 -743
  211. package/lib/components/__generated__/subscript.props.json +0 -743
  212. package/lib/components/__generated__/superscript.props.json +0 -743
  213. package/lib/components/__generated__/text-block.props.json +0 -743
  214. package/src/components/__generated__/body.props.json +0 -743
  215. package/src/components/__generated__/bold.props.json +0 -743
  216. package/src/components/__generated__/box.props.json +0 -765
  217. package/src/components/__generated__/button.props.json +0 -824
  218. package/src/components/__generated__/form.props.json +0 -799
  219. package/src/components/__generated__/heading.props.json +0 -754
  220. package/src/components/__generated__/image.props.json +0 -846
  221. package/src/components/__generated__/input.props.json +0 -977
  222. package/src/components/__generated__/italic.props.json +0 -743
  223. package/src/components/__generated__/link.props.json +0 -820
  224. package/src/components/__generated__/paragraph.props.json +0 -743
  225. package/src/components/__generated__/rich-text-link.props.json +0 -820
  226. package/src/components/__generated__/span.props.json +0 -743
  227. package/src/components/__generated__/subscript.props.json +0 -743
  228. package/src/components/__generated__/superscript.props.json +0 -743
  229. package/src/components/__generated__/text-block.props.json +0 -743
@@ -1,6 +1,6 @@
1
1
  import { SubscriptIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/subscript.props.json";
3
+ import { props } from "./__generated__/subscript.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: SubscriptIcon,
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 { SuperscriptIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/superscript.props.json";
3
+ import { props } from "./__generated__/superscript.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: SuperscriptIcon,
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 { TextIcon } from "@webstudio-is/icons";
2
2
  import type { WsComponentMeta, WsComponentPropsMeta } from "./component-type";
3
- import props from "./__generated__/text-block.props.json";
3
+ import { props } from "./__generated__/text-block.props";
4
4
 
5
5
  const presetStyle = {
6
6
  minHeight: {
@@ -18,6 +18,6 @@ export const meta: WsComponentMeta = {
18
18
  children: ["Block of text you can edit"],
19
19
  };
20
20
 
21
- export const propsMeta = {
21
+ export const propsMeta: WsComponentPropsMeta = {
22
22
  props,
23
- } as WsComponentPropsMeta;
23
+ };
@@ -1,5 +1,5 @@
1
1
  import { detectFont } from "detect-font";
2
- import type { Style, StyleValue, Unit } from "@webstudio-is/css-data";
2
+ import { keywordValues, Style, StyleValue, Unit } from "@webstudio-is/css-data";
3
3
  import { properties, units } from "@webstudio-is/css-data";
4
4
 
5
5
  const unitsList = Object.values(units).flat();
@@ -16,9 +16,20 @@ const parseValue = (
16
16
  value = "transparent";
17
17
  }
18
18
  if (Number.isNaN(number)) {
19
+ const values = keywordValues[
20
+ property as keyof typeof keywordValues
21
+ ] as ReadonlyArray<string>;
22
+
23
+ if (values?.includes(value)) {
24
+ return {
25
+ type: "keyword",
26
+ value: value,
27
+ };
28
+ }
29
+
19
30
  return {
20
- type: "keyword",
21
- value,
31
+ type: "unparsed",
32
+ value: value,
22
33
  };
23
34
  }
24
35
 
package/src/index.ts 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
  export {
7
9
  customComponents,
8
10
  customComponentMetas,
package/src/props.ts CHANGED
@@ -28,7 +28,7 @@ export const useInstanceProps = (instanceId: Instance["id"]) => {
28
28
  const { propsByInstanceIdStore } = useContext(ReactSdkContext);
29
29
  const propsByInstanceId = useStore(propsByInstanceIdStore);
30
30
  const instanceProps = propsByInstanceId.get(instanceId);
31
- const instancePropsObject: Record<string, number | string | boolean> = {};
31
+ const instancePropsObject: Record<Prop["name"], Prop["value"]> = {};
32
32
  if (instanceProps) {
33
33
  for (const prop of instanceProps) {
34
34
  if (prop.type !== "asset") {
@@ -2,9 +2,10 @@ import { type ComponentProps, Fragment } from "react";
2
2
  import type { ReadableAtom } from "nanostores";
3
3
  import { Scripts, ScrollRestoration } from "@remix-run/react";
4
4
  import type { Instance } from "@webstudio-is/project-build";
5
+ import type { GetComponent } from "../components/components-utils";
5
6
  import { ReactSdkContext } from "../context";
6
7
  import type { Assets, PropsByInstanceId } from "../props";
7
- import type { WrapperComponent } from "./wrapper-component";
8
+ import type { WebstudioComponent } from "./webstudio-component";
8
9
  import { SessionStoragePolyfill } from "./session-storage-polyfill";
9
10
 
10
11
  export const createElementsTree = ({
@@ -13,16 +14,19 @@ export const createElementsTree = ({
13
14
  propsByInstanceIdStore,
14
15
  assetsStore,
15
16
  Component,
17
+ getComponent,
16
18
  }: {
17
19
  sandbox?: boolean;
18
20
  instance: Instance;
19
21
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
20
22
  assetsStore: ReadableAtom<Assets>;
21
- Component: (props: ComponentProps<typeof WrapperComponent>) => JSX.Element;
23
+ Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
24
+ getComponent: GetComponent;
22
25
  }) => {
23
26
  const children = createInstanceChildrenElements({
24
27
  Component,
25
28
  children: instance.children,
29
+ getComponent,
26
30
  });
27
31
  const body = createInstanceElement({
28
32
  Component,
@@ -35,6 +39,7 @@ export const createElementsTree = ({
35
39
  <Scripts />
36
40
  </Fragment>,
37
41
  ],
42
+ getComponent,
38
43
  });
39
44
  return (
40
45
  <ReactSdkContext.Provider value={{ propsByInstanceIdStore, assetsStore }}>
@@ -46,9 +51,11 @@ export const createElementsTree = ({
46
51
  const createInstanceChildrenElements = ({
47
52
  children,
48
53
  Component,
54
+ getComponent,
49
55
  }: {
50
56
  children: Instance["children"];
51
- Component: (props: ComponentProps<typeof WrapperComponent>) => JSX.Element;
57
+ Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
58
+ getComponent: GetComponent;
52
59
  }) => {
53
60
  const elements = [];
54
61
  for (const child of children) {
@@ -59,11 +66,13 @@ const createInstanceChildrenElements = ({
59
66
  const children = createInstanceChildrenElements({
60
67
  children: child.children,
61
68
  Component,
69
+ getComponent,
62
70
  });
63
71
  const element = createInstanceElement({
64
72
  instance: child,
65
73
  Component,
66
74
  children,
75
+ getComponent,
67
76
  });
68
77
  elements.push(element);
69
78
  }
@@ -74,15 +83,18 @@ const createInstanceElement = ({
74
83
  Component,
75
84
  instance,
76
85
  children = [],
86
+ getComponent,
77
87
  }: {
78
88
  instance: Instance;
79
- Component: (props: ComponentProps<typeof WrapperComponent>) => JSX.Element;
89
+ Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
80
90
  children?: Array<JSX.Element | string>;
91
+ getComponent: GetComponent;
81
92
  }) => {
82
93
  const props = {
83
94
  instance,
84
95
  children,
85
96
  key: instance.id,
97
+ getComponent,
86
98
  };
87
99
 
88
100
  return <Component {...props} />;
package/src/tree/index.ts 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/src/tree/root.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  import type { ComponentProps } from "react";
2
2
  import { atom } from "nanostores";
3
- import type { Tree } from "@webstudio-is/project-build";
3
+ import type {
4
+ Instance,
5
+ Instances,
6
+ InstancesItem,
7
+ Tree,
8
+ } from "@webstudio-is/project-build";
4
9
  import type { Asset } from "@webstudio-is/asset-uploader";
5
10
  import { createElementsTree } from "./create-elements-tree";
6
- import { WrapperComponent } from "./wrapper-component";
11
+ import { WebstudioComponent } from "./webstudio-component";
7
12
  import { registerComponents } from "../components";
8
13
  import { customComponents as defaultCustomComponents } from "../app/custom-components";
9
14
  import { setParams, type Params } from "../app/params";
10
15
  import { getPropsByInstanceId } from "../props";
16
+ import type { GetComponent } from "../components/components-utils";
11
17
 
12
18
  export type Data = {
13
19
  tree: Tree | null;
@@ -17,14 +23,39 @@ export type Data = {
17
23
 
18
24
  type RootProps = {
19
25
  data: Data;
20
- Component?: (props: ComponentProps<typeof WrapperComponent>) => JSX.Element;
26
+ Component?: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
21
27
  customComponents?: Parameters<typeof registerComponents>[0];
28
+ getComponent: GetComponent;
29
+ };
30
+
31
+ const denormalizeTree = (instances: Instances) => {
32
+ const convertTree = (instance: InstancesItem) => {
33
+ const legacyInstance: Instance = {
34
+ type: "instance",
35
+ id: instance.id,
36
+ component: instance.component,
37
+ children: [],
38
+ };
39
+ for (const child of instance.children) {
40
+ if (child.type === "id") {
41
+ const childInstance = instances.get(child.value);
42
+ if (childInstance) {
43
+ legacyInstance.children.push(convertTree(childInstance));
44
+ }
45
+ } else {
46
+ legacyInstance.children.push(child);
47
+ }
48
+ }
49
+ return legacyInstance;
50
+ };
51
+ return convertTree(Array.from(instances.values())[0]);
22
52
  };
23
53
 
24
54
  export const InstanceRoot = ({
25
55
  data,
26
56
  Component,
27
57
  customComponents = defaultCustomComponents,
58
+ getComponent,
28
59
  }: RootProps): JSX.Element | null => {
29
60
  if (data.tree === null) {
30
61
  throw new Error("Tree is null");
@@ -35,11 +66,12 @@ export const InstanceRoot = ({
35
66
  registerComponents(customComponents);
36
67
 
37
68
  return createElementsTree({
38
- instance: data.tree.root,
69
+ instance: denormalizeTree(new Map(data.tree.instances)),
39
70
  propsByInstanceIdStore: atom(
40
71
  getPropsByInstanceId(new Map(data.tree.props))
41
72
  ),
42
73
  assetsStore: atom(new Map(data.assets.map((asset) => [asset.id, asset]))),
43
- Component: Component ?? WrapperComponent,
74
+ Component: Component ?? WebstudioComponent,
75
+ getComponent,
44
76
  });
45
77
  };
@@ -1,6 +1,6 @@
1
1
  import { Fragment } from "react";
2
2
  import type { Instance } from "@webstudio-is/project-build";
3
- import { getComponent } from "../components";
3
+ import type { GetComponent } from "../components/components-utils";
4
4
  import { useInstanceProps } from "../props";
5
5
 
6
6
  const renderText = (text: string): Array<JSX.Element> => {
@@ -13,7 +13,7 @@ const renderText = (text: string): Array<JSX.Element> => {
13
13
  ));
14
14
  };
15
15
 
16
- export const renderWrapperComponentChildren = (
16
+ export const renderWebstudioComponentChildren = (
17
17
  children: Array<JSX.Element | string> | undefined
18
18
  ): Array<JSX.Element | string | Array<JSX.Element | string>> | undefined => {
19
19
  // Some elements like input can't have children
@@ -26,16 +26,18 @@ export const renderWrapperComponentChildren = (
26
26
  });
27
27
  };
28
28
 
29
- type WrapperComponentProps = {
29
+ type WebstudioComponentProps = {
30
30
  instance: Instance;
31
31
  children: Array<JSX.Element | string>;
32
+ getComponent: GetComponent;
32
33
  };
33
34
 
34
- export const WrapperComponent = ({
35
+ export const WebstudioComponent = ({
35
36
  instance,
36
37
  children,
38
+ getComponent,
37
39
  ...rest
38
- }: WrapperComponentProps) => {
40
+ }: WebstudioComponentProps) => {
39
41
  const instanceProps = useInstanceProps(instance.id);
40
42
  const props = {
41
43
  ...instanceProps,
@@ -48,7 +50,9 @@ export const WrapperComponent = ({
48
50
  return <></>;
49
51
  }
50
52
  return (
51
- <Component {...props}>{renderWrapperComponentChildren(children)}</Component>
53
+ <Component {...props}>
54
+ {renderWebstudioComponentChildren(children)}
55
+ </Component>
52
56
  );
53
57
  };
54
58