|
1 | | -import {treeData} from './tree-data.mjs'; |
| 1 | +import {treeData, vaultData} from './tree-data.mjs'; |
2 | 2 | import * as icons from './icons.mjs'; |
3 | 3 |
|
4 | 4 | const processTree = (tree, valuePrefix = '') => { |
5 | 5 | tree.forEach((item) => { |
6 | | - item.value = valuePrefix ? `${valuePrefix} / ${item.title}` : item.title; |
| 6 | + const title = item.title.replace(/<[^>]+>/g, ''); |
| 7 | + item.value = valuePrefix ? `${valuePrefix}/${title}` : title; |
7 | 8 | if (item.children === undefined) { |
8 | | - const [, extension] = item.title.split('.'); |
| 9 | + const [, extension] = title.split('.'); |
9 | 10 | item.icon = (extension in icons) ? icons[extension] : icons.file; |
10 | 11 | return; |
11 | 12 | } |
12 | | - item.icon = icons.folder; |
| 13 | + item.icon = item.children ? icons.folder : icons.safe; |
13 | 14 | item.collapsed = true; |
14 | | - processTree(item.children, item.value); |
| 15 | + if (item.children !== null) { |
| 16 | + processTree(item.children, item.value); |
| 17 | + } |
15 | 18 | }); |
16 | 19 | }; |
17 | 20 |
|
18 | 21 | const fileStructure = structuredClone(treeData); |
19 | 22 | processTree(fileStructure); |
| 23 | +const valutStructure = structuredClone(vaultData); |
| 24 | +processTree(valutStructure, 'vault [remote]'); |
20 | 25 |
|
21 | 26 | customElements.whenDefined('cbx-tree').then(() => { |
22 | 27 | const tree = document.getElementById('file-tree'); |
23 | 28 | tree.setData(fileStructure); |
| 29 | + tree.subtreeProvider = async (value) => { |
| 30 | + await new Promise((resolve) => setTimeout(resolve, 1000 + Math.round(Math.random() * 2000))); |
| 31 | + const [, valutSubdir] = value.split('/'); |
| 32 | + return valutSubdir ? |
| 33 | + valutStructure.find(({title}) => title === valutSubdir).children : |
| 34 | + valutStructure.map((subdir) => ({...subdir, children: null})); |
| 35 | + }; |
24 | 36 |
|
25 | 37 | const setValidity = (isValid) => tree.setValidity({valueMissing: !isValid}, 'At least one file must be selected'); |
26 | 38 | setValidity(false); |
|
0 commit comments