Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve vfs ui #802

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/dev/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export function createVFSHandler(nitro: Nitro) {
: "hover:bg-gray-800 text-gray-200";
return `<li class="flex flex-nowrap"><a href="/_vfs/${encodeURIComponent(
key
)}" class="w-full text-sm px-2 py-1 border-b border-gray-500 ${linkClass}">${key.replace(
)}" class="w-full text-sm px-2 py-1 border-b border-gray-10 ${linkClass}">${key.replace(
nitro.options.rootDir,
""
)}</a></li>`;
})
.join("\n");

const files = `
<div>
<p class="bg-gray-700 text-white text-bold border-b border-gray-500 text-center">virtual files</p>
<div class="h-full overflow-auto border-r border-gray:10">
<p class="text-white text-bold text-center py-1 opacity-50">Virtual Files</p>
<ul class="flex flex-col">${items}</ul>
</div>
`;
Expand All @@ -71,8 +71,8 @@ export function createVFSHandler(nitro: Nitro) {
wordWrapColumn: 80,
})
: `
<div class="m-2">
<h1 class="text-white">Select a virtual file to inspect</h1>
<div class="w-full h-full flex opacity-50">
<h1 class="text-white m-auto">Select a virtual file to inspect</h1>
</div>
`;

Expand All @@ -83,9 +83,18 @@ export function createVFSHandler(nitro: Nitro) {
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unocss/reset/tailwind.min.css" />
<link rel="stylesheet" data-name="vs/editor/editor.main" href="${vsUrl}/editor/editor.main.min.css">
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"></script>
<style>
html {
background: #1E1E1E;
color: white;
}
[un-cloak] {
display: none;
}
</style>
</head>
<body class="bg-[#1E1E1E]">
<div class="flex">
<div un-cloak class="h-screen h-screen grid grid-cols-[300px_1fr]">
${files}
${file}
</div>
Expand All @@ -99,7 +108,7 @@ const monacoUrl = `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${monaco
const vsUrl = `${monacoUrl}/vs`;

const editorTemplate = (options: Record<string, any>) => `
<div id="editor" class="min-h-screen flex-1"></div>
<div id="editor" class="min-h-screen w-full h-full"></div>
<script src="${vsUrl}/loader.min.js"></script>
<script>
require.config({ paths: { vs: '${vsUrl}' } })
Expand All @@ -110,10 +119,12 @@ const editorTemplate = (options: Record<string, any>) => `
\`], { type: 'text/javascript' }))
window.MonacoEnvironment = { getWorkerUrl: () => proxy }

require(['vs/editor/editor.main'], function () {
monaco.editor.create(document.getElementById('editor'), ${JSON.stringify(
options
)})
})
setTimeout(() => {
require(['vs/editor/editor.main'], function () {
monaco.editor.create(document.getElementById('editor'), ${JSON.stringify(
options
)})
})
}, 0);
</script>
`;