Collapse folders and zips by default

This commit is contained in:
“Naeel”
2026-09-06 12:37:06 +03:00
parent 860cdd4214
commit 8316e19725
3 changed files with 52 additions and 4 deletions
+48
View File
@@ -0,0 +1,48 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { render } from '../upload/frontend/table/render.js';
function elements() {
return { tableBodyEl: { innerHTML: '' }, countEl: { textContent: '' } };
}
function fileNode() {
return {
id: 'file-1',
kind: 'file',
name: 'document.txt',
path: 'folder/document.txt',
file: { size: 7 },
children: [],
expanded: true,
};
}
test('render: папка по умолчанию скрывает дочерние файлы', () => {
const child = fileNode();
const state = {
nodes: [{
id: 'folder-1',
kind: 'folder',
name: 'folder',
path: 'folder',
children: [child],
expanded: false,
}],
};
const output = elements();
render(state, output);
assert.match(output.tableBodyEl.innerHTML, /data-toggle="folder-1"/);
assert.match(output.tableBodyEl.innerHTML, /aria-expanded="false"/);
assert.doesNotMatch(output.tableBodyEl.innerHTML, /data-path="folder\/document\.txt"/);
assert.equal(output.countEl.textContent, '1 файлов · 7 B');
state.nodes[0].expanded = true;
render(state, output);
assert.match(output.tableBodyEl.innerHTML, /data-path="folder\/document\.txt"/);
assert.match(output.tableBodyEl.innerHTML, /aria-expanded="true"/);
});
+2 -2
View File
@@ -31,7 +31,7 @@ export function onFolderChange(state, cfg, elements) {
if (!roots.has(rootName)) {
// Один root на выбранный каталог позволяет сохранить дерево целиком.
roots.set(rootName, { id: crypto.randomUUID(), kind: 'folder', name: rootName,
path: rootName, children: [], expanded: true });
path: rootName, children: [], expanded: false });
}
const root = roots.get(rootName);
// Вставляет узел по его пути, создавая отсутствующие промежуточные папки.
@@ -44,7 +44,7 @@ export function onFolderChange(state, cfg, elements) {
if (!child) {
child = last ? node : { id: crypto.randomUUID(), kind: 'folder', name: part,
path: `${rootName}/${nodeParts.slice(0, index + 1).join('/')}`,
children: [], expanded: true };
children: [], expanded: false };
current.children.push(child);
}
current = child;
+2 -2
View File
@@ -36,9 +36,9 @@ function safeEntryParts(entryName) {
return parts;
}
/** Создаёт единый узел file, folder или zip с уникальным id и раскрытым состоянием. */
/** Создаёт единый узел file, folder или zip с уникальным id и начальным состоянием раскрытия. */
function node(kind, name, path, children = [], file = null) {
return { id: crypto.randomUUID(), kind, name, path, children, file, expanded: true };
return { id: crypto.randomUUID(), kind, name, path, children, file, expanded: kind === 'file' };
}
/** Вставляет leaf или вложенное дерево по сегментам пути, создавая folder-узлы. */