Skip to content

Commit e0660eb

Browse files
Merge pull request #11 from bridgedxyz/react/styled-components
React/styled components
2 parents 45a1e2c + 4eb223f commit e0660eb

22 files changed

Lines changed: 293 additions & 55 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.play.tsx
2+
*.play.jsx
3+
*.play.js
4+
*.play.ts

editor/components/app-runner/app-runner.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export function AppRunner(props: {
1111
h: number | string;
1212
};
1313
src: string;
14+
componentName: string;
1415
}) {
15-
const { platform, sceneSize, src } = props;
16+
const { platform, sceneSize, src, componentName } = props;
1617
switch (platform) {
1718
case "flutter":
1819
return (
@@ -50,6 +51,13 @@ export function AppRunner(props: {
5051
</div>
5152
);
5253
case "web":
53-
return <CodeSandBoxView width="300px" height="100%" src={src} />;
54+
return (
55+
<CodeSandBoxView
56+
width="100%"
57+
height="100%"
58+
src={src}
59+
componentName={componentName}
60+
/>
61+
);
5462
}
5563
}

editor/components/app-runner/code-sandbox-runner.tsx

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,85 @@ import { useAsyncEffect } from "../../hooks";
1111
*/
1212
export function CodeSandBoxView(props: {
1313
src: string;
14+
componentName: string;
1415
width: number | string;
1516
height: number | string;
1617
}) {
1718
const [iframeUrl, setIframeUrl] = useState("");
1819
useAsyncEffect(async () => {
1920
const parameters = getParameters({
2021
files: {
21-
"index.js": {
22+
"App.tsx": {
2223
content: props.src,
2324
isBinary: false,
2425
},
25-
// "package.json": {
26-
// content: "",
27-
// isBinary: false,
28-
// },
26+
"index.tsx": {
27+
content: `
28+
import React from "react";
29+
import { render } from "react-dom";
30+
31+
import ${props.componentName} from "./App";
32+
33+
const rootElement = document.getElementById("root");
34+
render(<${props.componentName} />, rootElement);
35+
`,
36+
isBinary: false,
37+
},
38+
"tsconfig.json": {
39+
content: `{
40+
"include": [
41+
"./src/**/*"
42+
],
43+
"compilerOptions": {
44+
"strict": true,
45+
"esModuleInterop": true,
46+
"lib": [
47+
"dom",
48+
"es2015"
49+
],
50+
"jsx": "react-jsx"
51+
}
52+
}`,
53+
isBinary: false,
54+
},
55+
"package.json": {
56+
content: `{
57+
"name": "react-typescript",
58+
"version": "1.0.0",
59+
"description": "React and TypeScript example starter project",
60+
"keywords": [
61+
"typescript",
62+
"react",
63+
"starter"
64+
],
65+
"main": "src/index.tsx",
66+
"dependencies": {
67+
"react": "17.0.2",
68+
"react-dom": "17.0.2",
69+
"react-scripts": "4.0.0",
70+
"@emotion/react": "^11.1.5",
71+
"@emotion/styled": "^11.1.5"
72+
},
73+
"devDependencies": {
74+
"@types/react": "17.0.0",
75+
"@types/react-dom": "17.0.0",
76+
"typescript": "4.1.3"
77+
},
78+
"scripts": {
79+
"start": "react-scripts start",
80+
"build": "react-scripts build",
81+
"test": "react-scripts test --env=jsdom",
82+
"eject": "react-scripts eject"
83+
},
84+
"browserslist": [
85+
">0.2%",
86+
"not dead",
87+
"not ie <= 11",
88+
"not op_mini all"
89+
]
90+
}`,
91+
isBinary: false,
92+
},
2993
},
3094
template: "create-react-app-typescript",
3195
});

editor/components/app-runner/react-app-runner.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ export function ReactAppRunner(props: {
55
source: string;
66
width: string | number;
77
height: string | number;
8+
componentName;
89
}) {
910
return (
1011
<>
1112
<CodeSandBoxView
13+
componentName={props.componentName}
1214
src={props.source}
1315
width={props.width}
1416
height={props.height}

editor/components/editor-hierarchy/editor-layer-hierarchy/index.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,24 @@ export function LayerHierarchy(props: {
2222
// make mode
2323
const selectionmode = props.onLayerSelect?.multi ? "multi" : "single";
2424
const [selections, setSelections] = useState<string[]>();
25+
const [expanded, setExpanded] = useState<string[]>([]);
26+
const [selected, setSelected] = useState<string[]>([]);
2527

26-
const handleLayerClick = (id: string) => {
28+
const handleToggle = (event: React.ChangeEvent<{}>, nodeIds: string[]) => {
29+
setExpanded(nodeIds);
30+
};
31+
32+
const handleSelect = (event: React.ChangeEvent<{}>, nodeIds: string[]) => {
33+
setSelected(nodeIds);
34+
handleLayerClick(nodeIds);
35+
};
36+
37+
const handleLayerClick = (ids: string[]) => {
2738
if (selectionmode == "single") {
39+
const id = ids[ids.length - 1];
2840
props.onLayerSelect?.single?.(id);
2941
} else {
30-
setSelections([id, ...selections]);
42+
setSelections(ids);
3143
props.onLayerSelect?.multi?.(selections);
3244
}
3345
};
@@ -39,12 +51,7 @@ export function LayerHierarchy(props: {
3951
return <div style={{ padding: 24 }}>empty</div>;
4052
}
4153
return (
42-
<TreeItem
43-
key={nodes.id}
44-
nodeId={nodes.id}
45-
label={nodes.name}
46-
onClick={() => handleLayerClick(nodes.id)}
47-
>
54+
<TreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
4855
{Array.isArray(nodes.children)
4956
? nodes.children.map((node) => renderTree(node))
5057
: null}
@@ -61,8 +68,12 @@ export function LayerHierarchy(props: {
6168
<>
6269
<TreeView
6370
defaultCollapseIcon={<ExpandMoreIcon />}
64-
defaultExpanded={["root"]}
71+
defaultExpanded={[props.data?.id]}
6572
defaultExpandIcon={<ChevronRightIcon />}
73+
expanded={expanded}
74+
selected={selected}
75+
onNodeToggle={handleToggle}
76+
onNodeSelect={handleSelect}
6677
>
6778
{renderTree(data)}
6879
</TreeView>

editor/components/preview-and-run/preview-and-run-panel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface SceneRunnerConfig {
1515
};
1616
src: string | (() => string);
1717
platform: "web" | "flutter";
18+
componentName: string;
1819
}
1920

2021
export function PreviewAndRunPanel(props: { config: SceneRunnerConfig }) {
@@ -51,6 +52,7 @@ export function PreviewAndRunPanel(props: { config: SceneRunnerConfig }) {
5152
case "run":
5253
return (
5354
<AppRunner
55+
componentName={sceneConfig.componentName}
5456
sceneSize={sceneConfig?.sceneSize}
5557
src={loadSource()}
5658
platform={sceneConfig?.platform}

editor/components/visualization/json-visualization/json-tree.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Widget as WebWidget } from "@coli.codes/web-builder-core";
2+
import { Widget as ReflectWidget } from "@reflect-ui/core";
13
import React from "react";
24
import JSONTree from "react-json-tree";
35

@@ -24,5 +26,54 @@ const theme = {
2426
};
2527

2628
export function JsonTree(props: { data: any; hideRoot?: boolean }) {
27-
return <JSONTree data={props.data} theme={theme} hideRoot={props.hideRoot} />;
29+
return (
30+
<JSONTree
31+
data={props.data}
32+
theme={theme}
33+
hideRoot={props.hideRoot}
34+
getItemString={(type, data, itemType, itemString) => {
35+
return (
36+
<span>
37+
{type} {itemType}
38+
</span>
39+
);
40+
}}
41+
/>
42+
);
43+
}
44+
45+
type WidgetDataLike = WebWidget | ReflectWidget;
46+
export function WidgetTree(props: {
47+
data: WidgetDataLike;
48+
hideRoot?: boolean;
49+
}) {
50+
const getname = (data: WidgetDataLike | any): string => {
51+
if (data instanceof WebWidget) {
52+
return data.key.name;
53+
} else if (data instanceof ReflectWidget) {
54+
return data.key.originName;
55+
} else {
56+
return data.constructor?.name ?? undefined;
57+
}
58+
};
59+
60+
const gettype = (data: WidgetDataLike): string => {
61+
return data._type;
62+
};
63+
64+
return (
65+
<JSONTree
66+
data={props.data}
67+
theme={theme}
68+
hideRoot={props.hideRoot}
69+
getItemString={(type, data: WidgetDataLike, itemType, itemString) => {
70+
return (
71+
<span>
72+
{getname(data) && getname(data)} {gettype(data) && gettype(data)}{" "}
73+
{itemType}
74+
</span>
75+
);
76+
}}
77+
/>
78+
);
2879
}

editor/layout/default-editor-workspace-layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const NonMenuContentZoneWrap = styled.div`
5555
const PanelLeftSideWrap = styled.div`
5656
flex-grow: 0;
5757
min-height: 100%;
58+
max-height: 100%;
59+
max-width: 400px;
60+
overflow: auto;
5861
`;
5962

6063
const PanelRightSideWrap = styled.div`

editor/layout/panel/workspace-content-panel-grid-layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const Slot_BottomDockedContent = styled.div`
6161
position: relative;
6262
margin-top: auto;
6363
min-height: 150px;
64+
max-height: 400px;
65+
overflow: auto;
6466
`;
6567

6668
const PanelLayoutItemsContainer = styled.div`

editor/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const withTM = require("next-transpile-modules")([
2525
"coli",
2626
"@coli.codes/web-builder",
2727
"@coli.codes/web-builder-core",
28+
"@coli.codes/nodejs-builder",
2829
"@coli.codes/react-builder",
2930
"@web-builder/styled",
3031
"@bridged.xyz/flutter-builder",

0 commit comments

Comments
 (0)