Integrate backend APIs and move review to center editor tab

This commit is contained in:
2026-02-24 14:22:39 +03:00
parent fe67753f74
commit 91a0a50b04
13 changed files with 1010 additions and 152 deletions

View File

@@ -37,6 +37,45 @@ export class FileSaveService {
return { mode: "download", path: normalizedPath };
}
async saveExistingFile(projectStore, path, content) {
const normalizedPath = PathUtils.normalizeRelative(path);
if (projectStore.rootHandle) {
await this.#writeWithRootHandle(projectStore.rootHandle, normalizedPath, content);
return { mode: "inplace", path: normalizedPath };
}
const knownHandle = projectStore.fileHandles.get(normalizedPath) || this.fallbackHandles.get(normalizedPath);
if (knownHandle && typeof knownHandle.createWritable === "function") {
await this.#writeWithFileHandle(knownHandle, content);
return { mode: "inplace", path: normalizedPath };
}
throw new Error("Нет доступа к существующему файлу для записи без выбора новой директории.");
}
async saveNewFileWithPicker(projectStore, suggestedPath, content) {
if (typeof window.showSaveFilePicker !== "function") {
throw new Error("showSaveFilePicker is not supported");
}
const normalizedPath = PathUtils.normalizeRelative(suggestedPath);
const pickerOptions = {
suggestedName: PathUtils.basename(normalizedPath),
id: this.#buildProjectSaveId(projectStore)
};
if (projectStore.rootHandle) pickerOptions.startIn = projectStore.rootHandle;
const handle = await window.showSaveFilePicker(pickerOptions);
await this.#writeWithFileHandle(handle, content);
const resolvedPath = await this.#resolveRelativePath(projectStore.rootHandle, handle);
if (!resolvedPath) {
throw new Error("Выберите путь внутри директории проекта.");
}
this.fallbackHandles.set(resolvedPath, handle);
return { mode: "save_as", path: resolvedPath };
}
async deleteFile(projectStore, path) {
const normalizedPath = PathUtils.normalizeRelative(path);
if (!projectStore.rootHandle) return false;
@@ -89,4 +128,11 @@ export class FileSaveService {
const normalized = projectName.toLowerCase().replaceAll(/[^a-z0-9_-]/g, "-").replaceAll(/-+/g, "-");
return `save-${normalized || "project"}`;
}
async #resolveRelativePath(rootHandle, fileHandle) {
if (!rootHandle || typeof rootHandle.resolve !== "function") return fileHandle?.name || "";
const parts = await rootHandle.resolve(fileHandle);
if (!Array.isArray(parts) || !parts.length) return "";
return PathUtils.normalizeRelative(parts.join("/"));
}
}