freestyle-sandboxes 0.0.45 → 0.0.47

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.
@@ -0,0 +1,111 @@
1
+ import {
2
+ QueryClient,
3
+ QueryClientProvider,
4
+ useQuery,
5
+ } from "@tanstack/react-query";
6
+ import { RequestDevServerActions } from "./types";
7
+ import React from "react";
8
+
9
+ const queryClient = new QueryClient();
10
+
11
+ export function DefaultLoadingComponent({
12
+ installCommandRunning,
13
+ }: {
14
+ devCommandRunning: boolean;
15
+ installCommandRunning: boolean;
16
+ serverStarting: boolean;
17
+ }) {
18
+ let loadingText = "Starting container...";
19
+
20
+ if (installCommandRunning) {
21
+ loadingText = "Installing dependencies...";
22
+ } else {
23
+ loadingText = "Starting dev server...";
24
+ }
25
+
26
+ return (
27
+ <div
28
+ style={{
29
+ display: "flex",
30
+ flexDirection: "column",
31
+ alignItems: "center",
32
+ justifyContent: "center",
33
+ height: "100%",
34
+ }}
35
+ >
36
+ {loadingText}
37
+ </div>
38
+ );
39
+ }
40
+
41
+ export function FreestyleDevServer({
42
+ repoUrl,
43
+ loadingComponent,
44
+ actions,
45
+ }: {
46
+ repoUrl: string;
47
+ loadingComponent?: (props: {
48
+ devCommandRunning: boolean;
49
+ installCommandRunning: boolean;
50
+ serverStarting: boolean;
51
+ }) => React.ReactNode;
52
+ actions: RequestDevServerActions;
53
+ }) {
54
+ return (
55
+ <QueryClientProvider client={queryClient}>
56
+ <FreestyleDevServerInner
57
+ loadingComponent={loadingComponent ?? DefaultLoadingComponent}
58
+ repoUrl={repoUrl}
59
+ actions={actions}
60
+ />
61
+ </QueryClientProvider>
62
+ );
63
+ }
64
+
65
+ function FreestyleDevServerInner({
66
+ repoUrl,
67
+ loadingComponent,
68
+ actions: { requestDevServer },
69
+ }: {
70
+ repoUrl: string;
71
+ loadingComponent: (props: {
72
+ devCommandRunning: boolean;
73
+ installCommandRunning: boolean;
74
+ serverStarting: boolean;
75
+ }) => React.ReactNode;
76
+ actions: RequestDevServerActions;
77
+ }) {
78
+ const { data, isLoading } = useQuery({
79
+ queryKey: ["dev-server", repoUrl],
80
+ queryFn: async () => await requestDevServer({ repoUrl: repoUrl }),
81
+ refetchInterval: 1000,
82
+ });
83
+
84
+ if (isLoading) {
85
+ return loadingComponent({
86
+ devCommandRunning: false,
87
+ installCommandRunning: false,
88
+ serverStarting: true,
89
+ });
90
+ }
91
+
92
+ if (!data?.devCommandRunning) {
93
+ return loadingComponent({
94
+ devCommandRunning: data?.devCommandRunning ?? false,
95
+ installCommandRunning: data?.installCommandRunning ?? false,
96
+ serverStarting: false,
97
+ });
98
+ }
99
+
100
+ return (
101
+ <iframe
102
+ sandbox="allow-scripts allow-same-origin allow-forms"
103
+ src={data.ephemeralUrl}
104
+ style={{
105
+ width: "100%",
106
+ height: "100%",
107
+ border: "none",
108
+ }}
109
+ />
110
+ );
111
+ }
@@ -0,0 +1,5 @@
1
+ export type RequestDevServerActions = {
2
+ requestDevServer: (args: {
3
+ repoUrl: string;
4
+ }) => Promise<{ ephemeralUrl: string; devCommandRunning: boolean; installCommandRunning: boolean; }>;
5
+ };
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "allowImportingTsExtensions": true,
4
-
4
+ "jsx": "react",
5
5
  "lib": ["ESNext", "DOM"]
6
6
  }
7
7
  }