Load new math resources in the native Web editor

This commit is contained in:
gloamxun committed 2026-11-29 14:01:40 +08:00
1 parent 8b6dab8d52
commit fe86163767
12 files changed
+838 -106

No files matched your search

+9 -6
View File
@@ -19,6 +19,7 @@ let sequence = 0;
let publishedRevision = null;
let draft = null;
let frame;
const projectPrefix = location.pathname.startsWith("/p/") ? location.pathname.slice(0, -1) : "";
const previewDraft = new URLSearchParams(location.hash.slice(1)).get("preview") !== "published";
function attachWebControls() {
@@ -38,7 +39,9 @@ function attachWebControls() {
download.textContent = "下载 PDF";
document.querySelector("#export-pdf").replaceWith(download);
document.querySelector("#back-button").hidden = true;
const back = document.querySelector("#back-button");
back.hidden = !location.pathname.startsWith("/p/");
back.addEventListener("click", () => { location.href = "/"; });
document.querySelector("#toggle-engine").hidden = true;
document.querySelector("#header-actions").textContent = "原生 Beta";
document.querySelector("footer").textContent = "Ctrl/Cmd+S 保存源码副本";
@@ -115,14 +118,14 @@ function restorePublishedPages() {
function acceptPublication(revision, previous) {
revokeDetached(previous);
publishedRevision = revision;
pdf.href = `/pdf?revision=${revision}`;
pdf.href = projectPrefix + `/pdf?revision=${revision}`;
pdf.hidden = false;
draft = null;
}
async function publicationStatus(edit, revision) {
while (edit === sequence) {
const response = await fetch(`/publication?revision=${revision}`);
const response = await fetch(projectPrefix + `/publication?revision=${revision}`);
const result = await response.json();
if (!response.ok || result.state === "failed") throw new Error(result.error);
if (result.state === "published") return result;
@@ -134,7 +137,7 @@ async function publicationStatus(edit, revision) {
async function compile(edit, submitted, changes) {
const replacements = [];
try {
const response = await fetch("/preview", {
const response = await fetch(projectPrefix + "/preview", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -227,7 +230,7 @@ async function saveSources() {
saved.hidden = false;
saved.textContent = "正在保存源文件";
try {
const response = await fetch("/save", {
const response = await fetch(projectPrefix + "/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sequence, files: Object.fromEntries(edits) }),
@@ -244,7 +247,7 @@ async function saveSources() {
async function openProject() {
try {
const response = await fetch("/project");
const response = await fetch(projectPrefix + "/project");
if (!response.ok) throw new Error("无法打开源文件");
const project = await response.json();
files = new Map(Object.entries(project.files));