| author | |
| committer | |
| log | 8d48a3134f4d789f54128ccbb65919812ffc7921 |
| tree | 262e5c452ed9b2ed83e11074bbee99e52be24b88 |
| parent | 393d1ffc9ee52696e4b5f226a956e9d4c65b2f6a |
| signature | Signed by PGP key B5690EEEBB952194 |
2 files changed, 1 insertions(+), 34 deletions(-)
apps/mobile/src/features/files/fileTree.test.ts+1-9| ... | @@ -1,13 +1,7 @@ | ... | @@ -1,13 +1,7 @@ |
| 1 | import { describe, expect, it } from "vite-plus/test"; | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import type { ProjectEntry } from "@t3tools/contracts"; | 2 | import type { ProjectEntry } from "@t3tools/contracts"; |
| 3 | 3 | ||
| 4 | import { | 4 | import { buildFileTree, defaultExpandedTreePaths, flattenFileTree } from "./fileTree"; |
| 5 | buildFileTree, | ||
| 6 | countFileNodes, | ||
| 7 | defaultExpandedTreePaths, | ||
| 8 | firstFilePath, | ||
| 9 | flattenFileTree, | ||
| 10 | } from "./fileTree"; | ||
| 11 | 5 | ||
| 12 | const entries = [ | 6 | const entries = [ |
| 13 | { kind: "file", path: "README.md" }, | 7 | { kind: "file", path: "README.md" }, |
| ... | @@ -30,8 +24,6 @@ describe("mobile file tree helpers", () => { | ... | @@ -30,8 +24,6 @@ describe("mobile file tree helpers", () => { |
| 30 | "directory:src/components", | 24 | "directory:src/components", |
| 31 | "file:src/index.ts", | 25 | "file:src/index.ts", |
| 32 | ]); | 26 | ]); |
| 33 | expect(countFileNodes(tree)).toBe(4); | ||
| 34 | expect(firstFilePath(tree)).toBe("src/components/App.tsx"); | ||
| 35 | }); | 27 | }); |
| 36 | 28 | ||
| 37 | it("flattens expanded directories and hides collapsed descendants", () => { | 29 | it("flattens expanded directories and hides collapsed descendants", () => { |
apps/mobile/src/features/files/fileTree.ts-25| ... | @@ -117,18 +117,6 @@ export function buildFileTree(entries: ReadonlyArray<ProjectEntry>): ReadonlyArr | ... | @@ -117,18 +117,6 @@ export function buildFileTree(entries: ReadonlyArray<ProjectEntry>): ReadonlyArr |
| 117 | return [...root.children.values()].sort(compareNodes).map(freezeNode); | 117 | return [...root.children.values()].sort(compareNodes).map(freezeNode); |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | export function countFileNodes(nodes: ReadonlyArray<FileTreeNode>): number { | ||
| 121 | let count = 0; | ||
| 122 | for (const node of nodes) { | ||
| 123 | if (node.kind === "file") { | ||
| 124 | count += 1; | ||
| 125 | } else { | ||
| 126 | count += countFileNodes(node.children); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | return count; | ||
| 130 | } | ||
| 131 | |||
| 132 | export function defaultExpandedTreePaths(nodes: ReadonlyArray<FileTreeNode>): ReadonlySet<string> { | 120 | export function defaultExpandedTreePaths(nodes: ReadonlyArray<FileTreeNode>): ReadonlySet<string> { |
| 133 | const expanded = new Set<string>(); | 121 | const expanded = new Set<string>(); |
| 134 | for (const node of nodes) { | 122 | for (const node of nodes) { |
| ... | @@ -205,16 +193,3 @@ export function flattenFileTree(input: { | ... | @@ -205,16 +193,3 @@ export function flattenFileTree(input: { |
| 205 | } | 193 | } |
| 206 | return output; | 194 | return output; |
| 207 | } | 195 | } |
| 208 | |||
| 209 | export function firstFilePath(nodes: ReadonlyArray<FileTreeNode>): string | null { | ||
| 210 | for (const node of nodes) { | ||
| 211 | if (node.kind === "file") { | ||
| 212 | return node.path; | ||
| 213 | } | ||
| 214 | const child = firstFilePath(node.children); | ||
| 215 | if (child !== null) { | ||
| 216 | return child; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | return null; | ||
| 220 | } |