@webstudio-is/react-sdk 0.54.0 → 0.56.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.
- package/lib/cjs/components/blockquote.ws.js +1 -2
- package/lib/cjs/tree/create-elements-tree.js +19 -7
- package/lib/cjs/tree/root.js +2 -34
- package/lib/components/blockquote.ws.js +1 -2
- package/lib/tree/create-elements-tree.js +19 -7
- package/lib/tree/root.js +2 -34
- package/lib/types/tree/create-elements-tree.d.ts +17 -4
- package/lib/types/tree/webstudio-component.d.ts +2 -2
- package/package.json +11 -11
- package/src/components/blockquote.ws.tsx +0 -1
- package/src/tree/create-elements-tree.tsx +30 -11
- package/src/tree/root.ts +3 -46
- package/src/tree/webstudio-component.tsx +2 -2
|
@@ -27,24 +27,30 @@ var import_react2 = require("@remix-run/react");
|
|
|
27
27
|
var import_context = require("../context");
|
|
28
28
|
var import_session_storage_polyfill = require("./session-storage-polyfill");
|
|
29
29
|
const createElementsTree = ({
|
|
30
|
+
instances,
|
|
31
|
+
rootInstanceId,
|
|
30
32
|
sandbox,
|
|
31
|
-
instance,
|
|
32
33
|
propsByInstanceIdStore,
|
|
33
34
|
assetsStore,
|
|
34
35
|
pagesStore,
|
|
35
36
|
Component,
|
|
36
37
|
getComponent
|
|
37
38
|
}) => {
|
|
38
|
-
const
|
|
39
|
+
const rootInstance = instances.get(rootInstanceId);
|
|
40
|
+
if (rootInstance === void 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const rootInstanceSelector = [rootInstanceId];
|
|
39
44
|
const children = createInstanceChildrenElements({
|
|
45
|
+
instances,
|
|
40
46
|
instanceSelector: rootInstanceSelector,
|
|
41
47
|
Component,
|
|
42
|
-
children:
|
|
48
|
+
children: rootInstance.children,
|
|
43
49
|
getComponent
|
|
44
50
|
});
|
|
45
51
|
const root = createInstanceElement({
|
|
46
52
|
Component,
|
|
47
|
-
instance,
|
|
53
|
+
instance: rootInstance,
|
|
48
54
|
instanceSelector: rootInstanceSelector,
|
|
49
55
|
children: [
|
|
50
56
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
|
|
@@ -65,6 +71,7 @@ const createElementsTree = ({
|
|
|
65
71
|
);
|
|
66
72
|
};
|
|
67
73
|
const createInstanceChildrenElements = ({
|
|
74
|
+
instances,
|
|
68
75
|
instanceSelector,
|
|
69
76
|
children,
|
|
70
77
|
Component,
|
|
@@ -76,15 +83,20 @@ const createInstanceChildrenElements = ({
|
|
|
76
83
|
elements.push(child.value);
|
|
77
84
|
continue;
|
|
78
85
|
}
|
|
79
|
-
const
|
|
86
|
+
const childInstance = instances.get(child.value);
|
|
87
|
+
if (childInstance === void 0) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const childInstanceSelector = [child.value, ...instanceSelector];
|
|
80
91
|
const children2 = createInstanceChildrenElements({
|
|
92
|
+
instances,
|
|
81
93
|
instanceSelector: childInstanceSelector,
|
|
82
|
-
children:
|
|
94
|
+
children: childInstance.children,
|
|
83
95
|
Component,
|
|
84
96
|
getComponent
|
|
85
97
|
});
|
|
86
98
|
const element = createInstanceElement({
|
|
87
|
-
instance:
|
|
99
|
+
instance: childInstance,
|
|
88
100
|
instanceSelector: childInstanceSelector,
|
|
89
101
|
Component,
|
|
90
102
|
children: children2,
|
package/lib/cjs/tree/root.js
CHANGED
|
@@ -28,32 +28,6 @@ var import_components = require("../components");
|
|
|
28
28
|
var import_custom_components = require("../app/custom-components");
|
|
29
29
|
var import_params = require("../app/params");
|
|
30
30
|
var import_props = require("../props");
|
|
31
|
-
const denormalizeTree = (instances, rootInstanceId) => {
|
|
32
|
-
const convertTree = (instance) => {
|
|
33
|
-
const legacyInstance = {
|
|
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
|
-
const rootInstance = instances.get(rootInstanceId);
|
|
52
|
-
if (rootInstance === void 0) {
|
|
53
|
-
return void 0;
|
|
54
|
-
}
|
|
55
|
-
return convertTree(rootInstance);
|
|
56
|
-
};
|
|
57
31
|
const InstanceRoot = ({
|
|
58
32
|
data,
|
|
59
33
|
Component,
|
|
@@ -62,15 +36,9 @@ const InstanceRoot = ({
|
|
|
62
36
|
}) => {
|
|
63
37
|
(0, import_params.setParams)(data.params ?? null);
|
|
64
38
|
(0, import_components.registerComponents)(customComponents);
|
|
65
|
-
const instance = denormalizeTree(
|
|
66
|
-
new Map(data.build.instances),
|
|
67
|
-
data.page.rootInstanceId
|
|
68
|
-
);
|
|
69
|
-
if (instance === void 0) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
39
|
return (0, import_create_elements_tree.createElementsTree)({
|
|
73
|
-
|
|
40
|
+
instances: new Map(data.build.instances),
|
|
41
|
+
rootInstanceId: data.page.rootInstanceId,
|
|
74
42
|
propsByInstanceIdStore: (0, import_nanostores.atom)(
|
|
75
43
|
(0, import_props.getPropsByInstanceId)(new Map(data.build.props))
|
|
76
44
|
),
|
|
@@ -4,24 +4,30 @@ import { Scripts, ScrollRestoration } from "@remix-run/react";
|
|
|
4
4
|
import { ReactSdkContext } from "../context";
|
|
5
5
|
import { SessionStoragePolyfill } from "./session-storage-polyfill";
|
|
6
6
|
const createElementsTree = ({
|
|
7
|
+
instances,
|
|
8
|
+
rootInstanceId,
|
|
7
9
|
sandbox,
|
|
8
|
-
instance,
|
|
9
10
|
propsByInstanceIdStore,
|
|
10
11
|
assetsStore,
|
|
11
12
|
pagesStore,
|
|
12
13
|
Component,
|
|
13
14
|
getComponent
|
|
14
15
|
}) => {
|
|
15
|
-
const
|
|
16
|
+
const rootInstance = instances.get(rootInstanceId);
|
|
17
|
+
if (rootInstance === void 0) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const rootInstanceSelector = [rootInstanceId];
|
|
16
21
|
const children = createInstanceChildrenElements({
|
|
22
|
+
instances,
|
|
17
23
|
instanceSelector: rootInstanceSelector,
|
|
18
24
|
Component,
|
|
19
|
-
children:
|
|
25
|
+
children: rootInstance.children,
|
|
20
26
|
getComponent
|
|
21
27
|
});
|
|
22
28
|
const root = createInstanceElement({
|
|
23
29
|
Component,
|
|
24
|
-
instance,
|
|
30
|
+
instance: rootInstance,
|
|
25
31
|
instanceSelector: rootInstanceSelector,
|
|
26
32
|
children: [
|
|
27
33
|
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -42,6 +48,7 @@ const createElementsTree = ({
|
|
|
42
48
|
);
|
|
43
49
|
};
|
|
44
50
|
const createInstanceChildrenElements = ({
|
|
51
|
+
instances,
|
|
45
52
|
instanceSelector,
|
|
46
53
|
children,
|
|
47
54
|
Component,
|
|
@@ -53,15 +60,20 @@ const createInstanceChildrenElements = ({
|
|
|
53
60
|
elements.push(child.value);
|
|
54
61
|
continue;
|
|
55
62
|
}
|
|
56
|
-
const
|
|
63
|
+
const childInstance = instances.get(child.value);
|
|
64
|
+
if (childInstance === void 0) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const childInstanceSelector = [child.value, ...instanceSelector];
|
|
57
68
|
const children2 = createInstanceChildrenElements({
|
|
69
|
+
instances,
|
|
58
70
|
instanceSelector: childInstanceSelector,
|
|
59
|
-
children:
|
|
71
|
+
children: childInstance.children,
|
|
60
72
|
Component,
|
|
61
73
|
getComponent
|
|
62
74
|
});
|
|
63
75
|
const element = createInstanceElement({
|
|
64
|
-
instance:
|
|
76
|
+
instance: childInstance,
|
|
65
77
|
instanceSelector: childInstanceSelector,
|
|
66
78
|
Component,
|
|
67
79
|
children: children2,
|
package/lib/tree/root.js
CHANGED
|
@@ -5,32 +5,6 @@ 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, rootInstanceId) => {
|
|
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
|
-
const rootInstance = instances.get(rootInstanceId);
|
|
29
|
-
if (rootInstance === void 0) {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
return convertTree(rootInstance);
|
|
33
|
-
};
|
|
34
8
|
const InstanceRoot = ({
|
|
35
9
|
data,
|
|
36
10
|
Component,
|
|
@@ -39,15 +13,9 @@ const InstanceRoot = ({
|
|
|
39
13
|
}) => {
|
|
40
14
|
setParams(data.params ?? null);
|
|
41
15
|
registerComponents(customComponents);
|
|
42
|
-
const instance = denormalizeTree(
|
|
43
|
-
new Map(data.build.instances),
|
|
44
|
-
data.page.rootInstanceId
|
|
45
|
-
);
|
|
46
|
-
if (instance === void 0) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
16
|
return createElementsTree({
|
|
50
|
-
|
|
17
|
+
instances: new Map(data.build.instances),
|
|
18
|
+
rootInstanceId: data.page.rootInstanceId,
|
|
51
19
|
propsByInstanceIdStore: atom(
|
|
52
20
|
getPropsByInstanceId(new Map(data.build.props))
|
|
53
21
|
),
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import { type ComponentProps } from "react";
|
|
2
2
|
import type { ReadableAtom } from "nanostores";
|
|
3
3
|
import type { Assets } from "@webstudio-is/asset-uploader";
|
|
4
|
-
import type { Instance } from "@webstudio-is/project-build";
|
|
4
|
+
import type { Instance, Instances } from "@webstudio-is/project-build";
|
|
5
5
|
import type { GetComponent } from "../components/components-utils";
|
|
6
6
|
import type { Pages, PropsByInstanceId } from "../props";
|
|
7
7
|
import type { WebstudioComponent } from "./webstudio-component";
|
|
8
|
-
export declare const createElementsTree: ({
|
|
8
|
+
export declare const createElementsTree: ({ instances, rootInstanceId, sandbox, propsByInstanceIdStore, assetsStore, pagesStore, Component, getComponent, }: {
|
|
9
|
+
instances: Map<string, {
|
|
10
|
+
label?: string | undefined;
|
|
11
|
+
type: "instance";
|
|
12
|
+
id: string;
|
|
13
|
+
component: string;
|
|
14
|
+
children: ({
|
|
15
|
+
type: "text";
|
|
16
|
+
value: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: "id";
|
|
19
|
+
value: string;
|
|
20
|
+
})[];
|
|
21
|
+
}>;
|
|
22
|
+
rootInstanceId: Instance["id"];
|
|
9
23
|
sandbox?: boolean | undefined;
|
|
10
|
-
instance: Instance;
|
|
11
24
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
12
25
|
assetsStore: ReadableAtom<Assets>;
|
|
13
26
|
pagesStore: ReadableAtom<Pages>;
|
|
14
27
|
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
15
28
|
getComponent: GetComponent;
|
|
16
|
-
}) => JSX.Element;
|
|
29
|
+
}) => JSX.Element | null;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { Instance } from "@webstudio-is/project-build";
|
|
2
|
+
import type { Instance, InstancesItem } from "@webstudio-is/project-build";
|
|
3
3
|
import type { GetComponent } from "../components/components-utils";
|
|
4
4
|
export declare const renderWebstudioComponentChildren: (children: Array<JSX.Element | string> | undefined) => Array<JSX.Element | string | Array<JSX.Element | string>> | undefined;
|
|
5
5
|
type WebstudioComponentProps = {
|
|
6
|
-
instance:
|
|
6
|
+
instance: InstancesItem;
|
|
7
7
|
instanceSelector: Instance["id"][];
|
|
8
8
|
children: Array<JSX.Element | string>;
|
|
9
9
|
getComponent: GetComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"html-tags": "^3.2.0",
|
|
39
39
|
"nanoevents": "^7.0.1",
|
|
40
40
|
"nanostores": "^0.7.1",
|
|
41
|
-
"@webstudio-is/asset-uploader": "^0.
|
|
42
|
-
"@webstudio-is/css-data": "^0.
|
|
43
|
-
"@webstudio-is/css-engine": "^0.
|
|
44
|
-
"@webstudio-is/css-vars": "^0.
|
|
45
|
-
"@webstudio-is/fonts": "^0.
|
|
46
|
-
"@webstudio-is/generate-arg-types": "^0.
|
|
47
|
-
"@webstudio-is/icons": "^0.
|
|
48
|
-
"@webstudio-is/image": "^0.
|
|
49
|
-
"@webstudio-is/prisma-client": "^0.
|
|
50
|
-
"@webstudio-is/project-build": "^0.
|
|
41
|
+
"@webstudio-is/asset-uploader": "^0.56.0",
|
|
42
|
+
"@webstudio-is/css-data": "^0.56.0",
|
|
43
|
+
"@webstudio-is/css-engine": "^0.56.0",
|
|
44
|
+
"@webstudio-is/css-vars": "^0.56.0",
|
|
45
|
+
"@webstudio-is/fonts": "^0.56.0",
|
|
46
|
+
"@webstudio-is/generate-arg-types": "^0.56.0",
|
|
47
|
+
"@webstudio-is/icons": "^0.56.0",
|
|
48
|
+
"@webstudio-is/image": "^0.56.0",
|
|
49
|
+
"@webstudio-is/prisma-client": "^0.56.0",
|
|
50
|
+
"@webstudio-is/project-build": "^0.56.0"
|
|
51
51
|
},
|
|
52
52
|
"exports": {
|
|
53
53
|
".": {
|
|
@@ -2,7 +2,11 @@ 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 { Assets } from "@webstudio-is/asset-uploader";
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
Instance,
|
|
7
|
+
Instances,
|
|
8
|
+
InstancesItem,
|
|
9
|
+
} from "@webstudio-is/project-build";
|
|
6
10
|
import type { GetComponent } from "../components/components-utils";
|
|
7
11
|
import { ReactSdkContext } from "../context";
|
|
8
12
|
import type { Pages, PropsByInstanceId } from "../props";
|
|
@@ -12,32 +16,40 @@ import { SessionStoragePolyfill } from "./session-storage-polyfill";
|
|
|
12
16
|
type InstanceSelector = Instance["id"][];
|
|
13
17
|
|
|
14
18
|
export const createElementsTree = ({
|
|
19
|
+
instances,
|
|
20
|
+
rootInstanceId,
|
|
15
21
|
sandbox,
|
|
16
|
-
instance,
|
|
17
22
|
propsByInstanceIdStore,
|
|
18
23
|
assetsStore,
|
|
19
24
|
pagesStore,
|
|
20
25
|
Component,
|
|
21
26
|
getComponent,
|
|
22
27
|
}: {
|
|
28
|
+
instances: Instances;
|
|
29
|
+
rootInstanceId: Instance["id"];
|
|
23
30
|
sandbox?: boolean;
|
|
24
|
-
instance: Instance;
|
|
25
31
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
26
32
|
assetsStore: ReadableAtom<Assets>;
|
|
27
33
|
pagesStore: ReadableAtom<Pages>;
|
|
28
34
|
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
29
35
|
getComponent: GetComponent;
|
|
30
36
|
}) => {
|
|
31
|
-
const
|
|
37
|
+
const rootInstance = instances.get(rootInstanceId);
|
|
38
|
+
if (rootInstance === undefined) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const rootInstanceSelector = [rootInstanceId];
|
|
32
43
|
const children = createInstanceChildrenElements({
|
|
44
|
+
instances,
|
|
33
45
|
instanceSelector: rootInstanceSelector,
|
|
34
46
|
Component,
|
|
35
|
-
children:
|
|
47
|
+
children: rootInstance.children,
|
|
36
48
|
getComponent,
|
|
37
49
|
});
|
|
38
50
|
const root = createInstanceElement({
|
|
39
51
|
Component,
|
|
40
|
-
instance,
|
|
52
|
+
instance: rootInstance,
|
|
41
53
|
instanceSelector: rootInstanceSelector,
|
|
42
54
|
children: [
|
|
43
55
|
<Fragment key="children">
|
|
@@ -59,13 +71,15 @@ export const createElementsTree = ({
|
|
|
59
71
|
};
|
|
60
72
|
|
|
61
73
|
const createInstanceChildrenElements = ({
|
|
74
|
+
instances,
|
|
62
75
|
instanceSelector,
|
|
63
76
|
children,
|
|
64
77
|
Component,
|
|
65
78
|
getComponent,
|
|
66
79
|
}: {
|
|
80
|
+
instances: Instances;
|
|
67
81
|
instanceSelector: InstanceSelector;
|
|
68
|
-
children:
|
|
82
|
+
children: InstancesItem["children"];
|
|
69
83
|
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
70
84
|
getComponent: GetComponent;
|
|
71
85
|
}) => {
|
|
@@ -75,15 +89,20 @@ const createInstanceChildrenElements = ({
|
|
|
75
89
|
elements.push(child.value);
|
|
76
90
|
continue;
|
|
77
91
|
}
|
|
78
|
-
const
|
|
92
|
+
const childInstance = instances.get(child.value);
|
|
93
|
+
if (childInstance === undefined) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const childInstanceSelector = [child.value, ...instanceSelector];
|
|
79
97
|
const children = createInstanceChildrenElements({
|
|
98
|
+
instances,
|
|
80
99
|
instanceSelector: childInstanceSelector,
|
|
81
|
-
children:
|
|
100
|
+
children: childInstance.children,
|
|
82
101
|
Component,
|
|
83
102
|
getComponent,
|
|
84
103
|
});
|
|
85
104
|
const element = createInstanceElement({
|
|
86
|
-
instance:
|
|
105
|
+
instance: childInstance,
|
|
87
106
|
instanceSelector: childInstanceSelector,
|
|
88
107
|
Component,
|
|
89
108
|
children,
|
|
@@ -101,7 +120,7 @@ const createInstanceElement = ({
|
|
|
101
120
|
children = [],
|
|
102
121
|
getComponent,
|
|
103
122
|
}: {
|
|
104
|
-
instance:
|
|
123
|
+
instance: InstancesItem;
|
|
105
124
|
instanceSelector: InstanceSelector;
|
|
106
125
|
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
107
126
|
children?: Array<JSX.Element | string>;
|
package/src/tree/root.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type { ComponentProps } from "react";
|
|
2
2
|
import { atom } from "nanostores";
|
|
3
|
-
import type {
|
|
4
|
-
Build,
|
|
5
|
-
Instance,
|
|
6
|
-
Instances,
|
|
7
|
-
InstancesItem,
|
|
8
|
-
Page,
|
|
9
|
-
} from "@webstudio-is/project-build";
|
|
3
|
+
import type { Build, Page } from "@webstudio-is/project-build";
|
|
10
4
|
import type { Asset } from "@webstudio-is/asset-uploader";
|
|
11
5
|
import { createElementsTree } from "./create-elements-tree";
|
|
12
6
|
import { WebstudioComponent } from "./webstudio-component";
|
|
@@ -35,36 +29,6 @@ type RootProps = {
|
|
|
35
29
|
getComponent: GetComponent;
|
|
36
30
|
};
|
|
37
31
|
|
|
38
|
-
const denormalizeTree = (
|
|
39
|
-
instances: Instances,
|
|
40
|
-
rootInstanceId: Instance["id"]
|
|
41
|
-
) => {
|
|
42
|
-
const convertTree = (instance: InstancesItem) => {
|
|
43
|
-
const legacyInstance: Instance = {
|
|
44
|
-
type: "instance",
|
|
45
|
-
id: instance.id,
|
|
46
|
-
component: instance.component,
|
|
47
|
-
children: [],
|
|
48
|
-
};
|
|
49
|
-
for (const child of instance.children) {
|
|
50
|
-
if (child.type === "id") {
|
|
51
|
-
const childInstance = instances.get(child.value);
|
|
52
|
-
if (childInstance) {
|
|
53
|
-
legacyInstance.children.push(convertTree(childInstance));
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
legacyInstance.children.push(child);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return legacyInstance;
|
|
60
|
-
};
|
|
61
|
-
const rootInstance = instances.get(rootInstanceId);
|
|
62
|
-
if (rootInstance === undefined) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
return convertTree(rootInstance);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
32
|
export const InstanceRoot = ({
|
|
69
33
|
data,
|
|
70
34
|
Component,
|
|
@@ -72,17 +36,10 @@ export const InstanceRoot = ({
|
|
|
72
36
|
getComponent,
|
|
73
37
|
}: RootProps): JSX.Element | null => {
|
|
74
38
|
setParams(data.params ?? null);
|
|
75
|
-
|
|
76
39
|
registerComponents(customComponents);
|
|
77
|
-
const instance = denormalizeTree(
|
|
78
|
-
new Map(data.build.instances),
|
|
79
|
-
data.page.rootInstanceId
|
|
80
|
-
);
|
|
81
|
-
if (instance === undefined) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
40
|
return createElementsTree({
|
|
85
|
-
|
|
41
|
+
instances: new Map(data.build.instances),
|
|
42
|
+
rootInstanceId: data.page.rootInstanceId,
|
|
86
43
|
propsByInstanceIdStore: atom(
|
|
87
44
|
getPropsByInstanceId(new Map(data.build.props))
|
|
88
45
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment } from "react";
|
|
2
|
-
import type { Instance } from "@webstudio-is/project-build";
|
|
2
|
+
import type { Instance, InstancesItem } from "@webstudio-is/project-build";
|
|
3
3
|
import type { GetComponent } from "../components/components-utils";
|
|
4
4
|
import { useInstanceProps } from "../props";
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ export const renderWebstudioComponentChildren = (
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
type WebstudioComponentProps = {
|
|
30
|
-
instance:
|
|
30
|
+
instance: InstancesItem;
|
|
31
31
|
instanceSelector: Instance["id"][];
|
|
32
32
|
children: Array<JSX.Element | string>;
|
|
33
33
|
getComponent: GetComponent;
|