@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.
- package/lib/app/custom-components/image.js +1 -1
- package/lib/app/custom-components/index.js +1 -6
- package/lib/cjs/app/custom-components/image.cjs +2 -2
- package/lib/cjs/app/custom-components/index.cjs +1 -6
- package/lib/cjs/components/__generated__/blockquote.props.cjs +414 -0
- package/lib/cjs/components/__generated__/body.props.cjs +413 -0
- package/lib/cjs/components/__generated__/bold.props.cjs +413 -0
- package/lib/cjs/components/__generated__/box.props.cjs +431 -0
- package/lib/cjs/components/__generated__/button.props.cjs +430 -0
- package/lib/cjs/components/__generated__/code.props.cjs +420 -0
- package/lib/cjs/components/__generated__/form.props.cjs +421 -0
- package/lib/cjs/components/__generated__/heading.props.cjs +420 -0
- package/lib/cjs/components/__generated__/image.props.cjs +454 -0
- package/lib/cjs/components/__generated__/input.props.cjs +451 -0
- package/lib/cjs/components/__generated__/italic.props.cjs +413 -0
- package/lib/cjs/components/__generated__/link.props.cjs +437 -0
- package/lib/cjs/components/__generated__/list-item.props.cjs +414 -0
- package/lib/cjs/components/__generated__/list.props.cjs +427 -0
- package/lib/cjs/components/__generated__/paragraph.props.cjs +413 -0
- package/lib/cjs/components/__generated__/rich-text-link.props.cjs +437 -0
- package/lib/cjs/components/__generated__/separator.props.cjs +413 -0
- package/lib/cjs/components/__generated__/span.props.cjs +413 -0
- package/lib/cjs/components/__generated__/subscript.props.cjs +413 -0
- package/lib/cjs/components/__generated__/superscript.props.cjs +413 -0
- package/lib/cjs/components/__generated__/text-block.props.cjs +413 -0
- package/lib/cjs/components/blockquote.cjs +31 -0
- package/lib/cjs/components/blockquote.ws.cjs +75 -0
- package/lib/cjs/components/body.ws.cjs +2 -8
- package/lib/cjs/components/bold.ws.cjs +2 -8
- package/lib/cjs/components/box.ws.cjs +2 -8
- package/lib/cjs/components/button.ws.cjs +2 -8
- package/lib/cjs/components/code.cjs +38 -0
- package/lib/cjs/components/code.ws.cjs +66 -0
- package/lib/cjs/components/components-utils.cjs +71 -0
- package/lib/cjs/components/components.cjs +64 -0
- package/lib/cjs/components/form.ws.cjs +2 -8
- package/lib/cjs/components/heading.ws.cjs +2 -8
- package/lib/cjs/components/image.ws.cjs +8 -9
- package/lib/cjs/components/index.cjs +28 -53
- package/lib/cjs/components/input.ws.cjs +2 -8
- package/lib/cjs/components/italic.ws.cjs +2 -8
- package/lib/cjs/components/link.ws.cjs +2 -8
- package/lib/cjs/{css/breakpoints.cjs → components/list-item.cjs} +12 -10
- package/lib/cjs/components/list-item.ws.cjs +35 -0
- package/lib/cjs/components/list.cjs +31 -0
- package/lib/cjs/components/list.ws.cjs +51 -0
- package/lib/cjs/components/paragraph.ws.cjs +2 -8
- package/lib/cjs/components/rich-text-link.ws.cjs +2 -8
- package/lib/cjs/components/separator.cjs +31 -0
- package/lib/cjs/components/separator.ws.cjs +51 -0
- package/lib/cjs/components/span.ws.cjs +2 -8
- package/lib/cjs/components/subscript.ws.cjs +2 -8
- package/lib/cjs/components/superscript.ws.cjs +2 -8
- package/lib/cjs/components/text-block.ws.cjs +2 -8
- package/lib/cjs/css/get-browser-style.cjs +13 -5
- package/lib/cjs/css/index.cjs +0 -1
- package/lib/cjs/index.cjs +2 -0
- package/lib/cjs/tree/create-elements-tree.cjs +10 -9
- package/lib/cjs/tree/index.cjs +1 -1
- package/lib/cjs/tree/root.cjs +28 -4
- package/lib/cjs/tree/{wrapper-component.cjs → webstudio-component.cjs} +12 -11
- package/lib/components/__generated__/blockquote.props.js +394 -0
- package/lib/components/__generated__/body.props.js +393 -0
- package/lib/components/__generated__/bold.props.js +393 -0
- package/lib/components/__generated__/box.props.js +411 -0
- package/lib/components/__generated__/button.props.js +410 -0
- package/lib/components/__generated__/code.props.js +400 -0
- package/lib/components/__generated__/form.props.js +401 -0
- package/lib/components/__generated__/heading.props.js +400 -0
- package/lib/components/__generated__/image.props.js +434 -0
- package/lib/components/__generated__/input.props.js +431 -0
- package/lib/components/__generated__/italic.props.js +393 -0
- package/lib/components/__generated__/link.props.js +417 -0
- package/lib/components/__generated__/list-item.props.js +394 -0
- package/lib/components/__generated__/list.props.js +407 -0
- package/lib/components/__generated__/paragraph.props.js +393 -0
- package/lib/components/__generated__/rich-text-link.props.js +417 -0
- package/lib/components/__generated__/separator.props.js +393 -0
- package/lib/components/__generated__/span.props.js +393 -0
- package/lib/components/__generated__/subscript.props.js +393 -0
- package/lib/components/__generated__/superscript.props.js +393 -0
- package/lib/components/__generated__/text-block.props.js +393 -0
- package/lib/components/blockquote.js +14 -0
- package/lib/components/blockquote.ws.js +55 -0
- package/lib/components/body.ws.js +1 -1
- package/lib/components/bold.ws.js +1 -1
- package/lib/components/box.ws.js +1 -1
- package/lib/components/button.ws.js +1 -1
- package/lib/components/code.js +21 -0
- package/lib/components/code.ws.js +46 -0
- package/lib/components/components-utils.js +45 -0
- package/lib/components/components.js +44 -0
- package/lib/components/form.ws.js +1 -1
- package/lib/components/heading.ws.js +1 -1
- package/lib/components/image.ws.js +7 -2
- package/lib/components/index.js +28 -53
- package/lib/components/input.ws.js +1 -1
- package/lib/components/italic.ws.js +1 -1
- package/lib/components/link.ws.js +1 -1
- package/lib/components/list-item.js +14 -0
- package/lib/components/list-item.ws.js +15 -0
- package/lib/components/list.js +14 -0
- package/lib/components/list.ws.js +31 -0
- package/lib/components/paragraph.ws.js +1 -1
- package/lib/components/rich-text-link.ws.js +1 -1
- package/lib/components/separator.js +14 -0
- package/lib/components/separator.ws.js +31 -0
- package/lib/components/span.ws.js +1 -1
- package/lib/components/subscript.ws.js +1 -1
- package/lib/components/superscript.ws.js +1 -1
- package/lib/components/text-block.ws.js +1 -1
- package/lib/css/get-browser-style.js +9 -1
- package/lib/css/index.js +0 -1
- package/lib/index.js +2 -0
- package/lib/tree/create-elements-tree.js +10 -9
- package/lib/tree/index.js +1 -1
- package/lib/tree/root.js +28 -4
- package/lib/tree/{wrapper-component.js → webstudio-component.js} +8 -7
- package/package.json +14 -11
- package/src/app/custom-components/image.tsx +1 -1
- package/src/app/custom-components/index.ts +2 -7
- package/src/components/__generated__/blockquote.props.ts +439 -0
- package/src/components/__generated__/body.props.ts +438 -0
- package/src/components/__generated__/bold.props.ts +438 -0
- package/src/components/__generated__/box.props.ts +456 -0
- package/src/components/__generated__/button.props.ts +455 -0
- package/src/components/__generated__/code.props.ts +445 -0
- package/src/components/__generated__/form.props.ts +446 -0
- package/src/components/__generated__/heading.props.ts +445 -0
- package/src/components/__generated__/image.props.ts +479 -0
- package/src/components/__generated__/input.props.ts +476 -0
- package/src/components/__generated__/italic.props.ts +438 -0
- package/src/components/__generated__/link.props.ts +462 -0
- package/src/components/__generated__/list-item.props.ts +439 -0
- package/src/components/__generated__/list.props.ts +452 -0
- package/src/components/__generated__/paragraph.props.ts +438 -0
- package/src/components/__generated__/rich-text-link.props.ts +462 -0
- package/src/components/__generated__/separator.props.ts +438 -0
- package/src/components/__generated__/span.props.ts +438 -0
- package/src/components/__generated__/subscript.props.ts +438 -0
- package/src/components/__generated__/superscript.props.ts +438 -0
- package/src/components/__generated__/text-block.props.ts +438 -0
- package/src/components/blockquote.stories.tsx +16 -0
- package/src/components/blockquote.tsx +18 -0
- package/src/components/blockquote.ws.tsx +55 -0
- package/src/components/body.ws.tsx +3 -3
- package/src/components/bold.ws.tsx +3 -3
- package/src/components/box.ws.ts +3 -3
- package/src/components/button.ws.tsx +3 -3
- package/src/components/code.stories.tsx +16 -0
- package/src/components/code.tsx +31 -0
- package/src/components/code.ws.tsx +46 -0
- package/src/components/components-utils.ts +75 -0
- package/src/components/components.ts +28 -0
- package/src/components/form.ws.tsx +3 -3
- package/src/components/heading.ws.tsx +3 -3
- package/src/components/image.ws.tsx +9 -4
- package/src/components/index.ts +28 -63
- package/src/components/input.ws.tsx +3 -3
- package/src/components/italic.ws.tsx +3 -3
- package/src/components/link.ws.tsx +3 -3
- package/src/components/list-item.stories.tsx +16 -0
- package/src/components/list-item.tsx +18 -0
- package/src/components/list-item.ws.tsx +14 -0
- package/src/components/list.stories.tsx +17 -0
- package/src/components/list.tsx +24 -0
- package/src/components/list.ws.tsx +31 -0
- package/src/components/paragraph.ws.tsx +3 -3
- package/src/components/rich-text-link.ws.tsx +3 -3
- package/src/components/separator.stories.tsx +14 -0
- package/src/components/separator.tsx +18 -0
- package/src/components/separator.ws.tsx +31 -0
- package/src/components/span.ws.tsx +3 -3
- package/src/components/subscript.ws.tsx +3 -3
- package/src/components/superscript.ws.tsx +3 -3
- package/src/components/text-block.ws.tsx +3 -3
- package/src/css/get-browser-style.ts +14 -3
- package/src/css/index.ts +0 -1
- package/src/index.ts +2 -0
- package/src/props.ts +1 -1
- package/src/tree/create-elements-tree.tsx +16 -32
- package/src/tree/index.ts +1 -1
- package/src/tree/root.ts +37 -5
- package/src/tree/{wrapper-component.tsx → webstudio-component.tsx} +11 -9
- package/lib/cjs/components/__generated__/body.props.json +0 -743
- package/lib/cjs/components/__generated__/bold.props.json +0 -743
- package/lib/cjs/components/__generated__/box.props.json +0 -765
- package/lib/cjs/components/__generated__/button.props.json +0 -824
- package/lib/cjs/components/__generated__/form.props.json +0 -799
- package/lib/cjs/components/__generated__/heading.props.json +0 -754
- package/lib/cjs/components/__generated__/image.props.json +0 -846
- package/lib/cjs/components/__generated__/input.props.json +0 -977
- package/lib/cjs/components/__generated__/italic.props.json +0 -743
- package/lib/cjs/components/__generated__/link.props.json +0 -820
- package/lib/cjs/components/__generated__/paragraph.props.json +0 -743
- package/lib/cjs/components/__generated__/rich-text-link.props.json +0 -820
- package/lib/cjs/components/__generated__/span.props.json +0 -743
- package/lib/cjs/components/__generated__/subscript.props.json +0 -743
- package/lib/cjs/components/__generated__/superscript.props.json +0 -743
- package/lib/cjs/components/__generated__/text-block.props.json +0 -743
- package/lib/components/__generated__/body.props.json +0 -743
- package/lib/components/__generated__/bold.props.json +0 -743
- package/lib/components/__generated__/box.props.json +0 -765
- package/lib/components/__generated__/button.props.json +0 -824
- package/lib/components/__generated__/form.props.json +0 -799
- package/lib/components/__generated__/heading.props.json +0 -754
- package/lib/components/__generated__/image.props.json +0 -846
- package/lib/components/__generated__/input.props.json +0 -977
- package/lib/components/__generated__/italic.props.json +0 -743
- package/lib/components/__generated__/link.props.json +0 -820
- package/lib/components/__generated__/paragraph.props.json +0 -743
- package/lib/components/__generated__/rich-text-link.props.json +0 -820
- package/lib/components/__generated__/span.props.json +0 -743
- package/lib/components/__generated__/subscript.props.json +0 -743
- package/lib/components/__generated__/superscript.props.json +0 -743
- package/lib/components/__generated__/text-block.props.json +0 -743
- package/lib/css/breakpoints.js +0 -9
- package/src/components/__generated__/body.props.json +0 -743
- package/src/components/__generated__/bold.props.json +0 -743
- package/src/components/__generated__/box.props.json +0 -765
- package/src/components/__generated__/button.props.json +0 -824
- package/src/components/__generated__/form.props.json +0 -799
- package/src/components/__generated__/heading.props.json +0 -754
- package/src/components/__generated__/image.props.json +0 -846
- package/src/components/__generated__/input.props.json +0 -977
- package/src/components/__generated__/italic.props.json +0 -743
- package/src/components/__generated__/link.props.json +0 -820
- package/src/components/__generated__/paragraph.props.json +0 -743
- package/src/components/__generated__/rich-text-link.props.json +0 -820
- package/src/components/__generated__/span.props.json +0 -743
- package/src/components/__generated__/subscript.props.json +0 -743
- package/src/components/__generated__/superscript.props.json +0 -743
- package/src/components/__generated__/text-block.props.json +0 -743
- package/src/css/breakpoints.ts +0 -10
|
@@ -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
|
|
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
|
-
}
|
|
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
|
|
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
|
-
}
|
|
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
|
|
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
|
-
}
|
|
23
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { detectFont } from "detect-font";
|
|
2
|
-
import
|
|
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: "
|
|
21
|
-
value,
|
|
31
|
+
type: "unparsed",
|
|
32
|
+
value: value,
|
|
22
33
|
};
|
|
23
34
|
}
|
|
24
35
|
|
package/src/css/index.ts
CHANGED
package/src/index.ts
CHANGED
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<
|
|
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,48 +2,31 @@ 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 {
|
|
8
|
+
import type { WebstudioComponent } from "./webstudio-component";
|
|
8
9
|
import { SessionStoragePolyfill } from "./session-storage-polyfill";
|
|
9
10
|
|
|
10
|
-
export type ChildrenUpdates = Array<
|
|
11
|
-
| {
|
|
12
|
-
type: "text";
|
|
13
|
-
value: string;
|
|
14
|
-
}
|
|
15
|
-
| {
|
|
16
|
-
type: "instance";
|
|
17
|
-
id: undefined | Instance["id"];
|
|
18
|
-
component: Instance["component"];
|
|
19
|
-
children: ChildrenUpdates;
|
|
20
|
-
}
|
|
21
|
-
>;
|
|
22
|
-
|
|
23
|
-
export type OnChangeChildren = (change: {
|
|
24
|
-
instanceId: Instance["id"];
|
|
25
|
-
updates: ChildrenUpdates;
|
|
26
|
-
}) => void;
|
|
27
|
-
|
|
28
11
|
export const createElementsTree = ({
|
|
29
12
|
sandbox,
|
|
30
13
|
instance,
|
|
31
14
|
propsByInstanceIdStore,
|
|
32
15
|
assetsStore,
|
|
33
16
|
Component,
|
|
34
|
-
|
|
17
|
+
getComponent,
|
|
35
18
|
}: {
|
|
36
19
|
sandbox?: boolean;
|
|
37
20
|
instance: Instance;
|
|
38
21
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
39
22
|
assetsStore: ReadableAtom<Assets>;
|
|
40
|
-
Component: (props: ComponentProps<typeof
|
|
41
|
-
|
|
23
|
+
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
24
|
+
getComponent: GetComponent;
|
|
42
25
|
}) => {
|
|
43
26
|
const children = createInstanceChildrenElements({
|
|
44
27
|
Component,
|
|
45
28
|
children: instance.children,
|
|
46
|
-
|
|
29
|
+
getComponent,
|
|
47
30
|
});
|
|
48
31
|
const body = createInstanceElement({
|
|
49
32
|
Component,
|
|
@@ -56,6 +39,7 @@ export const createElementsTree = ({
|
|
|
56
39
|
<Scripts />
|
|
57
40
|
</Fragment>,
|
|
58
41
|
],
|
|
42
|
+
getComponent,
|
|
59
43
|
});
|
|
60
44
|
return (
|
|
61
45
|
<ReactSdkContext.Provider value={{ propsByInstanceIdStore, assetsStore }}>
|
|
@@ -67,11 +51,11 @@ export const createElementsTree = ({
|
|
|
67
51
|
const createInstanceChildrenElements = ({
|
|
68
52
|
children,
|
|
69
53
|
Component,
|
|
70
|
-
|
|
54
|
+
getComponent,
|
|
71
55
|
}: {
|
|
72
56
|
children: Instance["children"];
|
|
73
|
-
Component: (props: ComponentProps<typeof
|
|
74
|
-
|
|
57
|
+
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
58
|
+
getComponent: GetComponent;
|
|
75
59
|
}) => {
|
|
76
60
|
const elements = [];
|
|
77
61
|
for (const child of children) {
|
|
@@ -82,13 +66,13 @@ const createInstanceChildrenElements = ({
|
|
|
82
66
|
const children = createInstanceChildrenElements({
|
|
83
67
|
children: child.children,
|
|
84
68
|
Component,
|
|
85
|
-
|
|
69
|
+
getComponent,
|
|
86
70
|
});
|
|
87
71
|
const element = createInstanceElement({
|
|
88
72
|
instance: child,
|
|
89
73
|
Component,
|
|
90
|
-
onChangeChildren,
|
|
91
74
|
children,
|
|
75
|
+
getComponent,
|
|
92
76
|
});
|
|
93
77
|
elements.push(element);
|
|
94
78
|
}
|
|
@@ -99,18 +83,18 @@ const createInstanceElement = ({
|
|
|
99
83
|
Component,
|
|
100
84
|
instance,
|
|
101
85
|
children = [],
|
|
102
|
-
|
|
86
|
+
getComponent,
|
|
103
87
|
}: {
|
|
104
88
|
instance: Instance;
|
|
105
|
-
Component: (props: ComponentProps<typeof
|
|
106
|
-
onChangeChildren?: OnChangeChildren;
|
|
89
|
+
Component: (props: ComponentProps<typeof WebstudioComponent>) => JSX.Element;
|
|
107
90
|
children?: Array<JSX.Element | string>;
|
|
91
|
+
getComponent: GetComponent;
|
|
108
92
|
}) => {
|
|
109
93
|
const props = {
|
|
110
94
|
instance,
|
|
111
95
|
children,
|
|
112
96
|
key: instance.id,
|
|
113
|
-
|
|
97
|
+
getComponent,
|
|
114
98
|
};
|
|
115
99
|
|
|
116
100
|
return <Component {...props} />;
|
package/src/tree/index.ts
CHANGED
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 {
|
|
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 {
|
|
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
|
|
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.
|
|
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 ??
|
|
74
|
+
Component: Component ?? WebstudioComponent,
|
|
75
|
+
getComponent,
|
|
44
76
|
});
|
|
45
77
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Fragment } from "react";
|
|
2
2
|
import type { Instance } from "@webstudio-is/project-build";
|
|
3
|
-
import {
|
|
3
|
+
import type { GetComponent } from "../components/components-utils";
|
|
4
4
|
import { useInstanceProps } from "../props";
|
|
5
|
-
import type { OnChangeChildren } from "./create-elements-tree";
|
|
6
5
|
|
|
7
6
|
const renderText = (text: string): Array<JSX.Element> => {
|
|
8
7
|
const lines = text.split("\n");
|
|
@@ -14,7 +13,7 @@ const renderText = (text: string): Array<JSX.Element> => {
|
|
|
14
13
|
));
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
export const
|
|
16
|
+
export const renderWebstudioComponentChildren = (
|
|
18
17
|
children: Array<JSX.Element | string> | undefined
|
|
19
18
|
): Array<JSX.Element | string | Array<JSX.Element | string>> | undefined => {
|
|
20
19
|
// Some elements like input can't have children
|
|
@@ -27,18 +26,18 @@ export const renderWrapperComponentChildren = (
|
|
|
27
26
|
});
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
type
|
|
29
|
+
type WebstudioComponentProps = {
|
|
31
30
|
instance: Instance;
|
|
32
31
|
children: Array<JSX.Element | string>;
|
|
33
|
-
|
|
32
|
+
getComponent: GetComponent;
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
export const
|
|
35
|
+
export const WebstudioComponent = ({
|
|
37
36
|
instance,
|
|
38
|
-
onChangeChildren, // prevent it from passing to sdk component
|
|
39
37
|
children,
|
|
38
|
+
getComponent,
|
|
40
39
|
...rest
|
|
41
|
-
}:
|
|
40
|
+
}: WebstudioComponentProps) => {
|
|
42
41
|
const instanceProps = useInstanceProps(instance.id);
|
|
43
42
|
const props = {
|
|
44
43
|
...instanceProps,
|
|
@@ -51,9 +50,12 @@ export const WrapperComponent = ({
|
|
|
51
50
|
return <></>;
|
|
52
51
|
}
|
|
53
52
|
return (
|
|
54
|
-
<Component {...props}>
|
|
53
|
+
<Component {...props}>
|
|
54
|
+
{renderWebstudioComponentChildren(children)}
|
|
55
|
+
</Component>
|
|
55
56
|
);
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
export const idAttribute = "data-ws-id";
|
|
59
60
|
export const componentAttribute = "data-ws-component";
|
|
61
|
+
export const collapsedAttribute = "data-ws-collapsed";
|