Skip to content

Commit 535fce9

Browse files
add dynamic vanilla preview renderer
1 parent 1c4c2be commit 535fce9

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

editor/components/app-runner/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from "./flutter-app-runner";
44
export * from "./react-app-runner";
55
export * from "./loading-indicator";
66
export * from "./vanilla-esbuild-app-runner";
7+
export * from "./vanilla-dedicated-preview-renderer";

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React, { ReactEventHandler, useEffect, useRef } from "react";
22

33
export const VanillaRunner = React.forwardRef(function (
44
{
5-
width,
6-
height,
5+
width = "100%",
6+
height = "100%",
77
source,
88
onLoad,
99
enableInspector = true,
1010
style,
1111
}: {
12-
width: string;
13-
height: string;
12+
width?: React.CSSProperties["width"];
13+
height?: React.CSSProperties["height"];
1414
source: string;
1515
onLoad?: ReactEventHandler<HTMLIFrameElement>;
1616
componentName: string;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import { VanillaRunner } from "components/app-runner/vanilla-app-runner";
3+
import { ScenePreviewData } from "core/states";
4+
import { VanillaESBuildAppRunner } from "components/app-runner";
5+
6+
export function VanillaDedicatedPreviewRenderer({
7+
loader,
8+
componentName,
9+
source,
10+
}: ScenePreviewData) {
11+
return (
12+
<>
13+
{loader === "vanilla-esbuild-template" ? (
14+
<VanillaESBuildAppRunner
15+
componentName={componentName}
16+
doc={{
17+
html: source.html,
18+
javascript: source.javascript,
19+
}}
20+
/>
21+
) : (
22+
<VanillaRunner
23+
key={source}
24+
style={{
25+
borderRadius: 4,
26+
boxShadow: "0px 0px 48px #00000020",
27+
}}
28+
source={source}
29+
componentName={componentName}
30+
/>
31+
)}
32+
</>
33+
);
34+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { VanillaRunner } from "components/app-runner/vanilla-app-runner";
33

44
export function VanillaESBuildAppRunner({
55
doc,
6+
componentName,
67
}: {
8+
componentName: string;
79
doc?: {
810
html: string;
911
css?: string;
@@ -39,7 +41,7 @@ export function VanillaESBuildAppRunner({
3941
source={_html}
4042
width="100%"
4143
height="100%"
42-
componentName={"preview"}
44+
componentName={componentName}
4345
/>
4446
);
4547
}

0 commit comments

Comments
 (0)