Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
9f8302a0
提交
9f8302a0
authored
4月 13, 2025
作者:
Will Chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
very simple nav setup to support sandbox mode
上级
39565ce6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
11 行删除
+43
-11
PreviewIframe.tsx
src/components/preview_panel/PreviewIframe.tsx
+36
-8
static_file_server.js
worker/static_file_server.js
+7
-3
没有找到文件。
src/components/preview_panel/PreviewIframe.tsx
浏览文件 @
9f8302a0
import
{
selectedAppIdAtom
,
appUrlAtom
,
appOutputAtom
}
from
"@/atoms/appAtoms"
;
import
{
useAtomValue
,
useSetAtom
}
from
"jotai"
;
import
{
useAtom
,
useAtom
Value
,
useSetAtom
}
from
"jotai"
;
import
{
useRunApp
}
from
"@/hooks/useRunApp"
;
import
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
{
...
...
@@ -287,6 +287,8 @@ export const PreviewIframe = ({
// Navigate to the URL
iframeRef
.
current
.
contentWindow
.
location
.
href
=
newUrl
;
// iframeRef.current.src = newUrl;
// Update navigation history
const
newHistory
=
[
...
navigationHistory
.
slice
(
0
,
currentHistoryPosition
+
1
),
...
...
@@ -321,14 +323,24 @@ export const PreviewIframe = ({
<
div
className=
"flex space-x-1"
>
<
button
className=
"p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed dark:text-gray-300"
disabled=
{
!
canGoBack
||
loading
||
!
selectedAppId
}
disabled=
{
!
canGoBack
||
loading
||
!
selectedAppId
||
settings
?.
runtimeMode
===
"web-sandbox"
}
onClick=
{
handleNavigateBack
}
>
<
ArrowLeft
size=
{
16
}
/>
</
button
>
<
button
className=
"p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-50 disabled:cursor-not-allowed dark:text-gray-300"
disabled=
{
!
canGoForward
||
loading
||
!
selectedAppId
}
disabled=
{
!
canGoForward
||
loading
||
!
selectedAppId
||
settings
?.
runtimeMode
===
"web-sandbox"
}
onClick=
{
handleNavigateForward
}
>
<
ArrowRight
size=
{
16
}
/>
...
...
@@ -380,6 +392,12 @@ export const PreviewIframe = ({
{
/* Action Buttons */
}
<
div
className=
"flex space-x-1"
>
<
button
title=
{
settings
?.
runtimeMode
===
"web-sandbox"
?
"Open in browser (disabled in sandbox mode)"
:
undefined
}
disabled=
{
settings
?.
runtimeMode
===
"web-sandbox"
}
onClick=
{
()
=>
{
if
(
appUrl
)
{
IpcClient
.
getInstance
().
openExternalUrl
(
appUrl
);
...
...
@@ -402,7 +420,7 @@ export const PreviewIframe = ({
/>
{
settings
?.
runtimeMode
===
"web-sandbox"
?
(
<
SandpackIframe
reloadKey=
{
reloadKey
}
/>
<
SandpackIframe
reloadKey=
{
reloadKey
}
iframeRef=
{
iframeRef
}
/>
)
:
!
appUrl
?
(
<
div
className=
"absolute inset-0 flex flex-col items-center justify-center space-y-4 bg-gray-50 dark:bg-gray-950"
>
<
Loader2
className=
"w-8 h-8 animate-spin text-gray-400 dark:text-gray-500"
/>
...
...
@@ -431,7 +449,14 @@ const parseTailwindConfig = (config: string) => {
return
`{theme:
${
match
[
1
]}
};`
;
};
const
SandpackIframe
=
({
reloadKey
}:
{
reloadKey
:
number
})
=>
{
const
SandpackIframe
=
({
reloadKey
,
iframeRef
,
}:
{
reloadKey
:
number
;
iframeRef
:
React
.
RefObject
<
HTMLIFrameElement
|
null
>
;
})
=>
{
const
[
appUrlObj
,
setAppUrlObj
]
=
useAtom
(
appUrlAtom
);
const
selectedAppId
=
useAtomValue
(
selectedAppIdAtom
);
const
{
app
}
=
useLoadApp
(
selectedAppId
);
const
keyRef
=
useRef
<
number
|
null
>
(
null
);
...
...
@@ -453,9 +478,9 @@ const SandpackIframe = ({ reloadKey }: { reloadKey: number }) => {
if
(
!
iframeRef
.
current
||
!
app
)
return
;
const
sandpackConfig
:
SandboxSetup
=
mapSandpackConfig
(
sandboxConfig
);
const
url
=
"http://localhost:31111"
;
const
options
:
ClientOptions
=
{
bundlerURL
:
"http://localhost:31111"
,
bundlerURL
:
url
,
showOpenInCodeSandbox
:
false
,
showLoadingScreen
:
true
,
showErrorScreen
:
true
,
...
...
@@ -469,6 +494,10 @@ const SandpackIframe = ({ reloadKey }: { reloadKey: number }) => {
sandpackConfig
,
options
);
setAppUrlObj
({
appUrl
:
url
,
appId
:
selectedAppId
,
});
sandpackClientRef
.
current
=
client
;
return
client
;
}
catch
(
error
)
{
...
...
@@ -494,7 +523,6 @@ const SandpackIframe = ({ reloadKey }: { reloadKey: number }) => {
if
(
!
iframeRef
.
current
||
!
app
||
!
selectedAppId
)
return
;
loadSandpack
();
},
[
reloadKey
]);
const
iframeRef
=
useRef
<
HTMLIFrameElement
>
(
null
);
return
(
<
iframe
...
...
worker/static_file_server.js
浏览文件 @
9f8302a0
...
...
@@ -115,9 +115,13 @@ const handleRequest = (config) => async (req, res) => {
path
.
join
(
config
.
rootDir
,
parsedUrl
.
pathname
)
);
// Handle root path or directory paths, serve index.html
if
(
filePath
===
path
.
normalize
(
config
.
rootDir
)
||
filePath
.
endsWith
(
"/"
))
{
filePath
=
path
.
join
(
filePath
,
"index.html"
);
// Handle root path, directory paths, or paths without file extensions by serving index.html
if
(
filePath
===
path
.
normalize
(
config
.
rootDir
)
||
filePath
.
endsWith
(
"/"
)
||
!
path
.
extname
(
filePath
)
)
{
filePath
=
path
.
join
(
config
.
rootDir
,
"index.html"
);
}
// Check if file exists and get its stats
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论