// folderManager.js import { loadFileList } from './fileManager.js'; import { showToast, escapeHTML } from './domUtils.js'; // ---------------------- // Helper Functions (Data/State) // ---------------------- // Formats a folder name for display (e.g. adding indentations). export function formatFolderName(folder) { if (typeof folder !== "string") return ""; if (folder.indexOf("/") !== -1) { let parts = folder.split("/"); let indent = ""; for (let i = 1; i < parts.length; i++) { indent += "\u00A0\u00A0\u00A0\u00A0"; // 4 non-breaking spaces per level } return indent + parts[parts.length - 1]; } else { return folder; } } // Build a tree structure from a flat array of folder paths. function buildFolderTree(folders) { const tree = {}; folders.forEach(folderPath => { // Ensure folderPath is a string if (typeof folderPath !== "string") return; const parts = folderPath.split('/'); let current = tree; parts.forEach(part => { if (!current[part]) { current[part] = {}; } current = current[part]; }); }); return tree; } // ---------------------- // Folder Tree State (Save/Load) // ---------------------- function loadFolderTreeState() { const state = localStorage.getItem("folderTreeState"); return state ? JSON.parse(state) : {}; } function saveFolderTreeState(state) { localStorage.setItem("folderTreeState", JSON.stringify(state)); } // Helper for getting the parent folder. function getParentFolder(folder) { if (folder === "root") return "root"; const lastSlash = folder.lastIndexOf("/"); return lastSlash === -1 ? "root" : folder.substring(0, lastSlash); } // ---------------------- // DOM Building Functions // ---------------------- // Recursively builds HTML for the folder tree as nested