Add workbench recompile, LaTeX assistance, and selectable preview
This commit is contained in:
1 parent
aaf2550c68
commit
e0d9b3a91f
12 files changed
+1059
-28
No files matched your search
@@ -34,6 +34,7 @@ mod preview_socket;
|
||||
mod projects;
|
||||
mod resource_capture;
|
||||
mod saved_project;
|
||||
mod text_layer;
|
||||
mod thread_usage;
|
||||
|
||||
const MAX_EDIT_BODY: u64 = 2 * 1024 * 1024;
|
||||
@@ -348,21 +349,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
for request in server.incoming_requests() {
|
||||
let url = request.url().to_owned();
|
||||
let path = url.as_str();
|
||||
if let (&Method::Get, Some(assets)) = (request.method(), &web) {
|
||||
if let Some((kind, bytes)) = assets.file(path) {
|
||||
if request.method() == &Method::Get {
|
||||
const JS: &str = "text/javascript; charset=utf-8";
|
||||
const CSS: &str = "text/css; charset=utf-8";
|
||||
let editor_asset = match path {
|
||||
"/app.js" => Some((JS, SCRIPT)),
|
||||
"/code_editor.js" => Some((JS, include_str!("code_editor.js"))),
|
||||
"/code_editor.css" => Some((CSS, include_str!("code_editor.css"))),
|
||||
"/preview_view.js" => Some((JS, include_str!("preview_view.js"))),
|
||||
"/preview_view.css" => Some((CSS, include_str!("preview_view.css"))),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((kind, body)) = editor_asset {
|
||||
respond(request, 200, kind, body.into());
|
||||
continue;
|
||||
}
|
||||
if let Some((kind, bytes)) = web.as_ref().and_then(|assets| assets.file(path)) {
|
||||
respond(request, 200, kind, bytes);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if path == "/app.js" && request.method() == &Method::Get {
|
||||
respond(
|
||||
request,
|
||||
200,
|
||||
"text/javascript; charset=utf-8",
|
||||
SCRIPT.into(),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
let mut session_path = path;
|
||||
if let Some(library) = &library {
|
||||
if path == "/" && request.method() == &Method::Get {
|
||||
@@ -492,6 +498,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"name": entry.strip_prefix(run.as_path()).unwrap().to_string_lossy(),
|
||||
"source": std::str::from_utf8(&file.data)?,
|
||||
"files": files,
|
||||
"project_files": declared.iter()
|
||||
.filter_map(|path| path.strip_prefix(run.as_path()).ok()?.to_str())
|
||||
.collect::<Vec<_>>(),
|
||||
"sequence": queue.current.load(Ordering::Acquire),
|
||||
"preview_socket": id.as_deref().map_or_else(
|
||||
|| "/preview-socket".to_owned(), |id| format!("/p/{id}/preview-socket"),
|
||||
@@ -584,6 +593,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
),
|
||||
}
|
||||
}
|
||||
(&Method::Get, path) if path.starts_with("/text-layer?revision=") => {
|
||||
let revision = path["/text-layer?revision=".len()..].parse::<u64>().ok();
|
||||
if let Some(document) = compiler.latest().filter(|doc| Some(doc.revision()) == revision) {
|
||||
std::thread::spawn(move || {
|
||||
reply(request, 200, json!(text_layer::for_document(&document)));
|
||||
});
|
||||
} else {
|
||||
reply(
|
||||
request,
|
||||
409,
|
||||
json!({ "error": "This preview revision is no longer current" }),
|
||||
);
|
||||
}
|
||||
}
|
||||
(&Method::Get, path) if path.starts_with("/source-map?revision=") => {
|
||||
let revision = path["/source-map?revision=".len()..].parse::<u64>().ok();
|
||||
match compiler
|
||||
@@ -615,6 +638,14 @@ impl WebAssets {
|
||||
fn load(path: &Path) -> std::io::Result<Self> {
|
||||
let index = fs::read_to_string(path.join("index.html"))?;
|
||||
let dashboard = index.replace("src=\"/app.js\"", "src=\"/library.js\"");
|
||||
let index = index.replace("src=\"/app.js\"", "type=\"module\" src=\"/app.js\"")
|
||||
.replace(
|
||||
"</head>",
|
||||
concat!(
|
||||
"<link rel=\"stylesheet\" href=\"/code_editor.css\">",
|
||||
"<link rel=\"stylesheet\" href=\"/preview_view.css\"></head>",
|
||||
),
|
||||
);
|
||||
Ok(Self {
|
||||
dashboard: dashboard.into_bytes(),
|
||||
index: index.into_bytes(),
|
||||
@@ -628,7 +659,6 @@ impl WebAssets {
|
||||
"/styles.css" => Some(("text/css; charset=utf-8", self.styles.clone())),
|
||||
"/favicon.svg" => Some(("image/svg+xml", self.favicon.clone())),
|
||||
"/fonts.css" => Some(("text/css; charset=utf-8", Vec::new())),
|
||||
"/app.js" => Some(("text/javascript; charset=utf-8", SCRIPT.into())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user