/* * fstree.ts * Copyright (C) 2024 veypi * 2024-11-04 17:18 * Distributed under terms of the GPL license. */ import v, { proxy, vfor } from "../v2dom" import fs, { FileStat } from '../fs' import { vif } from "../v2dom/v2dom" const dirTree = (url: string) => { let treeItems = proxy.Watch([] as FileStat[]) let expand = proxy.Watch({ value: false }) let child = v('', () => expand.value && treeItems.length ? vfor(treeItems, (item) => v('div', item.basename), undefined, '123') : []) return v('fsdir', [ v({ class: 'fsdir-header', children: [v('div', () => expand.value + ''), v('div', url)], onclick: () => { expand.value = !expand.value if (expand.value) { fs.user.getDirectoryContents(url).then((e: any) => { treeItems.splice(0) treeItems.push(...e) }) } } }), vif([() => expand.value && treeItems.length, () => child], [1, () => v('div', 123)]) ]) } export default dirTree