vitepress-plugin-folder-tree 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +445 -0
- package/dist/VpFolderTree.vue +1486 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/config.d.ts +115 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/folder-tree-markdown.d.ts +35 -0
- package/dist/folder-tree-markdown.d.ts.map +1 -0
- package/dist/folder-tree-plugin.d.ts +4 -0
- package/dist/folder-tree-plugin.d.ts.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/vitepress-plugin-folder-tree.es.mjs +326 -0
- package/dist/vitepress-plugin-folder-tree.umd.js +7 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 s00d
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
# vitepress-plugin-folder-tree
|
|
2
|
+
|
|
3
|
+
Interactive file/folder tree diagrams for [VitePress](https://vitepress.dev). Write YAML or paste ASCII — get a beautiful, collapsible Vue component.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/vitepress-plugin-folder-tree)
|
|
6
|
+
[](https://www.npmjs.com/package/vitepress-plugin-folder-tree)
|
|
7
|
+
[](https://github.com/s00d/vitepress-plugin-folder-tree/blob/main/LICENSE)
|
|
8
|
+
[](https://www.donationalerts.com/r/s00d88)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
| Category | What you get |
|
|
15
|
+
|---|---|
|
|
16
|
+
| **Input** | YAML, ASCII (`├── └──`), external URL (YAML/JSON/JS), filesystem scan (`from:`) |
|
|
17
|
+
| **Interaction** | Expand/collapse folders, keyboard nav, search & filter, context menu (right-click) |
|
|
18
|
+
| **Toolbar** | Expand all, Collapse all, Copy as text, Download (.txt/.yaml/.json), Shell script (`mkdir`/`touch`) |
|
|
19
|
+
| **Visual** | Guide lines, hover branch highlight, smooth animations, dark mode |
|
|
20
|
+
| **Metadata** | `description` badge, `note`, `highlight`, `icon` (emoji/Iconify), `href` links |
|
|
21
|
+
| **Git status** | `added` / `modified` / `deleted` indicators with color-coded badges |
|
|
22
|
+
| **Tabs** | `tab` field on root nodes → Chrome-style switchable tabs |
|
|
23
|
+
| **Deep linking** | URL hash → auto-expand, scroll, pulse animation |
|
|
24
|
+
| **Preview** | `preview` field → tooltip on hover (600 ms delay) |
|
|
25
|
+
| **Icons** | Per-extension SVG, custom emoji, Iconify classes, global `iconMap` |
|
|
26
|
+
| **A11y** | ARIA attributes, `prefers-reduced-motion`, keyboard navigation |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# pnpm
|
|
36
|
+
pnpm add vitepress-plugin-folder-tree
|
|
37
|
+
|
|
38
|
+
# npm
|
|
39
|
+
npm install vitepress-plugin-folder-tree
|
|
40
|
+
|
|
41
|
+
# yarn
|
|
42
|
+
yarn add vitepress-plugin-folder-tree
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Configure
|
|
46
|
+
|
|
47
|
+
`.vitepress/config.mts`:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { defineConfig } from 'vitepress'
|
|
51
|
+
import { withFolderTree } from 'vitepress-plugin-folder-tree'
|
|
52
|
+
|
|
53
|
+
export default withFolderTree(
|
|
54
|
+
defineConfig({ title: 'My Docs' })
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Use
|
|
59
|
+
|
|
60
|
+
Write a fenced code block with language `tree` (or `folder-tree` / `file-tree`):
|
|
61
|
+
|
|
62
|
+
````yaml
|
|
63
|
+
```tree
|
|
64
|
+
- name: src
|
|
65
|
+
children:
|
|
66
|
+
- name: components
|
|
67
|
+
children:
|
|
68
|
+
- Button.vue
|
|
69
|
+
- Modal.vue
|
|
70
|
+
- App.vue
|
|
71
|
+
- main.ts
|
|
72
|
+
- package.json
|
|
73
|
+
```
|
|
74
|
+
````
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Input Formats
|
|
79
|
+
|
|
80
|
+
### YAML (structured)
|
|
81
|
+
|
|
82
|
+
Each root item is a **string** (file) or **object** (file/folder with metadata):
|
|
83
|
+
|
|
84
|
+
````yaml
|
|
85
|
+
```tree
|
|
86
|
+
- name: src
|
|
87
|
+
description: "Source code"
|
|
88
|
+
children:
|
|
89
|
+
- name: index.ts
|
|
90
|
+
highlight: true
|
|
91
|
+
- utils.ts
|
|
92
|
+
- README.md
|
|
93
|
+
```
|
|
94
|
+
````
|
|
95
|
+
|
|
96
|
+
### ASCII (paste from terminal)
|
|
97
|
+
|
|
98
|
+
Paste `tree` command output — auto-detected by `├──` / `└──` characters:
|
|
99
|
+
|
|
100
|
+
````
|
|
101
|
+
```tree
|
|
102
|
+
├── src
|
|
103
|
+
│ ├── index.ts
|
|
104
|
+
│ └── utils.ts
|
|
105
|
+
├── package.json
|
|
106
|
+
└── README.md
|
|
107
|
+
```
|
|
108
|
+
````
|
|
109
|
+
|
|
110
|
+
### External URL
|
|
111
|
+
|
|
112
|
+
Load tree from a separate file (YAML, JSON, or JS module):
|
|
113
|
+
|
|
114
|
+
````yaml
|
|
115
|
+
```tree
|
|
116
|
+
url: /trees/my-project.yaml
|
|
117
|
+
```
|
|
118
|
+
````
|
|
119
|
+
|
|
120
|
+
### Filesystem scan
|
|
121
|
+
|
|
122
|
+
Generate tree from a real directory at build time:
|
|
123
|
+
|
|
124
|
+
````yaml
|
|
125
|
+
```tree
|
|
126
|
+
from: ./src
|
|
127
|
+
depth: 3
|
|
128
|
+
exclude:
|
|
129
|
+
- "*.test.ts"
|
|
130
|
+
```
|
|
131
|
+
````
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Node Fields
|
|
136
|
+
|
|
137
|
+
| Field | Type | Default | Description |
|
|
138
|
+
|---|---|---|---|
|
|
139
|
+
| `name` | `string` | *required** | File or folder name |
|
|
140
|
+
| `type` | `'file'` \| `'folder'` | auto | Force node type (auto: has `children` → folder) |
|
|
141
|
+
| `children` | `array` | — | Nested items (makes this node a folder) |
|
|
142
|
+
| `description` | `string` | — | Badge shown next to name |
|
|
143
|
+
| `note` | `string` | — | Right-aligned label |
|
|
144
|
+
| `highlight` | `boolean` | `false` | Accent background on the row |
|
|
145
|
+
| `icon` | `string` | — | Custom emoji or Iconify class |
|
|
146
|
+
| `open` | `boolean` | `defaultOpen` | Initial expanded state |
|
|
147
|
+
| `locked` | `boolean` | `false` | Prevent toggling this folder |
|
|
148
|
+
| `href` | `string` | — | URL — clicking the name navigates here |
|
|
149
|
+
| `status` | `'added'` \| `'modified'` \| `'deleted'` | — | Git-style diff badge (`A`/`M`/`D`) |
|
|
150
|
+
| `preview` | `string` | — | Tooltip text on hover (600 ms delay) |
|
|
151
|
+
| `tab` | `string` | — | Root-level tab grouping |
|
|
152
|
+
|
|
153
|
+
> \* `name` is optional when `tab` is set — the tab label is used as the name.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Diff / Git Status
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
- name: config.ts
|
|
161
|
+
status: modified
|
|
162
|
+
- name: new-feature.ts
|
|
163
|
+
status: added
|
|
164
|
+
- name: old-module.ts
|
|
165
|
+
status: deleted
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Status | Visual |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `added` | Green text + **A** badge |
|
|
171
|
+
| `modified` | Amber text + **M** badge |
|
|
172
|
+
| `deleted` / `removed` | Red text + **D** badge + strikethrough |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Tabs
|
|
177
|
+
|
|
178
|
+
Use `tab` on root-level nodes to create switchable views:
|
|
179
|
+
|
|
180
|
+
````yaml
|
|
181
|
+
```tree
|
|
182
|
+
- tab: "Frontend"
|
|
183
|
+
children:
|
|
184
|
+
- name: src
|
|
185
|
+
children:
|
|
186
|
+
- App.vue
|
|
187
|
+
- main.ts
|
|
188
|
+
- package.json
|
|
189
|
+
- tab: "Backend"
|
|
190
|
+
children:
|
|
191
|
+
- name: src
|
|
192
|
+
children:
|
|
193
|
+
- index.ts
|
|
194
|
+
- server.ts
|
|
195
|
+
- package.json
|
|
196
|
+
```
|
|
197
|
+
````
|
|
198
|
+
|
|
199
|
+
Each tab shows the `children` of its root node. All toolbar operations (search, copy, download, shell script) work within the active tab.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Deep Linking
|
|
204
|
+
|
|
205
|
+
Append `#path/to/file` to the page URL:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
https://example.com/docs/guide.html#src/components/Button.vue
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The tree will:
|
|
212
|
+
1. Switch to the correct tab (if tabs are used)
|
|
213
|
+
2. Expand all ancestor folders
|
|
214
|
+
3. Scroll to the node
|
|
215
|
+
4. Highlight it with a pulse animation
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Preview Tooltip
|
|
220
|
+
|
|
221
|
+
Add `preview` to show code/text in an IDE-style tooltip on hover:
|
|
222
|
+
|
|
223
|
+
```yaml
|
|
224
|
+
- name: index.ts
|
|
225
|
+
preview: "import { createApp } from 'vue'\ncreateApp(App).mount('#app')"
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Tooltip appears after 600 ms, disappears on mouse leave.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Shell Script Generation
|
|
233
|
+
|
|
234
|
+
Click the **`>_`** button in the toolbar to copy a shell script (`mkdir -p` + `touch`) that recreates the tree structure. Paste into your terminal to scaffold a project instantly.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Custom Icons
|
|
239
|
+
|
|
240
|
+
### Per-node icon
|
|
241
|
+
|
|
242
|
+
```yaml
|
|
243
|
+
- name: .env
|
|
244
|
+
icon: "\U0001F510"
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Global `iconMap`
|
|
248
|
+
|
|
249
|
+
Map filenames or extensions to emoji/Iconify classes:
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
export default withFolderTree(
|
|
253
|
+
defineConfig({}),
|
|
254
|
+
{
|
|
255
|
+
iconMap: {
|
|
256
|
+
'vite.config.ts': '\u26A1',
|
|
257
|
+
'ts': 'logos:typescript-icon',
|
|
258
|
+
'vue': 'logos:vue',
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Priority: full filename → extension → default SVG.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Auto-generate from Filesystem
|
|
269
|
+
|
|
270
|
+
| Field | Type | Default | Description |
|
|
271
|
+
|---|---|---|---|
|
|
272
|
+
| `from` | `string` | *required* | Path to scan (relative to project root) |
|
|
273
|
+
| `depth` | `number` | `10` | Max scan depth |
|
|
274
|
+
| `name` | `string` | dir name | Override root folder display name |
|
|
275
|
+
| `showRoot` | `boolean` | `true` | Wrap in root folder |
|
|
276
|
+
| `exclude` | `string[]` | — | Glob patterns to skip |
|
|
277
|
+
| `include` | `string[]` | — | Glob patterns for files (folders always traversed) |
|
|
278
|
+
|
|
279
|
+
**Default excludes:** `node_modules`, `.git`, `.DS_Store`, `dist`, `.cache`, `.vitepress`, `__pycache__`, `.next`, `.nuxt`, `.idea`, `.vscode`, `coverage`, and more.
|
|
280
|
+
|
|
281
|
+
````yaml
|
|
282
|
+
```tree
|
|
283
|
+
from: ./src
|
|
284
|
+
include:
|
|
285
|
+
- "*.ts"
|
|
286
|
+
- "*.tsx"
|
|
287
|
+
exclude:
|
|
288
|
+
- "*.test.ts"
|
|
289
|
+
options:
|
|
290
|
+
defaultOpen: false
|
|
291
|
+
```
|
|
292
|
+
````
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Context Menu
|
|
297
|
+
|
|
298
|
+
Access the context menu on any node:
|
|
299
|
+
|
|
300
|
+
| Method | How |
|
|
301
|
+
|---|---|
|
|
302
|
+
| **Right-click** | Standard right mouse button |
|
|
303
|
+
| **Ctrl + Click** | Hold `Ctrl` (or `Cmd` on Mac) and left-click |
|
|
304
|
+
| **Shift + F10** | Focus a row with arrow keys, then press `Shift + F10` |
|
|
305
|
+
|
|
306
|
+
Menu actions:
|
|
307
|
+
- **Copy Name** — file/folder name (e.g. `Button.vue`)
|
|
308
|
+
- **Copy Path** — full tree path (e.g. `src/components/Button.vue`)
|
|
309
|
+
|
|
310
|
+
Press `Escape` to close.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Plugin Configuration
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
export default withFolderTree(
|
|
318
|
+
defineConfig({}),
|
|
319
|
+
{
|
|
320
|
+
languages: ['tree', 'file-tree', 'folder-tree'], // trigger languages
|
|
321
|
+
defaultOpen: true, // folders expanded by default
|
|
322
|
+
showToolbar: true, // show toolbar
|
|
323
|
+
showBadges: true, // auto file/folder count badges
|
|
324
|
+
interactive: true, // allow expand/collapse
|
|
325
|
+
root: process.cwd(), // base path for `from:` resolution
|
|
326
|
+
iconMap: {}, // global icon overrides
|
|
327
|
+
}
|
|
328
|
+
)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
| Option | Type | Default | Description |
|
|
332
|
+
|---|---|---|---|
|
|
333
|
+
| `languages` | `string[]` | `['folder-tree', 'file-tree', 'tree']` | Code block languages |
|
|
334
|
+
| `defaultOpen` | `boolean` | `true` | Default expand state |
|
|
335
|
+
| `showToolbar` | `boolean` | `true` | Toolbar visibility |
|
|
336
|
+
| `showBadges` | `boolean` | `true` | Auto count badges |
|
|
337
|
+
| `interactive` | `boolean` | `true` | Allow interaction |
|
|
338
|
+
| `root` | `string` | `process.cwd()` | Root for `from:` paths |
|
|
339
|
+
| `iconMap` | `Record<string, string>` | `{}` | Filename/ext → icon mapping |
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Per-block Options
|
|
344
|
+
|
|
345
|
+
Override global settings per code block:
|
|
346
|
+
|
|
347
|
+
````yaml
|
|
348
|
+
```tree
|
|
349
|
+
options:
|
|
350
|
+
defaultOpen: false
|
|
351
|
+
showToolbar: false
|
|
352
|
+
showBadges: false
|
|
353
|
+
interactive: false
|
|
354
|
+
tree:
|
|
355
|
+
- name: src
|
|
356
|
+
children:
|
|
357
|
+
- index.ts
|
|
358
|
+
```
|
|
359
|
+
````
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Keyboard Navigation
|
|
364
|
+
|
|
365
|
+
| Key | Action |
|
|
366
|
+
|---|---|
|
|
367
|
+
| `↓` / `↑` | Move focus between rows |
|
|
368
|
+
| `→` | Expand focused folder |
|
|
369
|
+
| `←` | Collapse focused folder |
|
|
370
|
+
| `Enter` / `Space` | Toggle folder open/close |
|
|
371
|
+
| `Shift + F10` | Open context menu for focused row |
|
|
372
|
+
| `Escape` | Close context menu / tooltip |
|
|
373
|
+
| `Tab` | Enter / exit tree area |
|
|
374
|
+
|
|
375
|
+
### Modifier keys
|
|
376
|
+
|
|
377
|
+
| Modifier | Action |
|
|
378
|
+
|---|---|
|
|
379
|
+
| `Ctrl + Click` | Open context menu (Win/Linux) |
|
|
380
|
+
| `Cmd + Click` | Open context menu (Mac) |
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## Toolbar Buttons
|
|
385
|
+
|
|
386
|
+
| Icon | Action |
|
|
387
|
+
|---|---|
|
|
388
|
+
| `▼` | Expand all folders |
|
|
389
|
+
| `▶` | Collapse all folders |
|
|
390
|
+
| Copy | Copy tree as ASCII text |
|
|
391
|
+
| `↓` | Download as .txt / .yaml / .json |
|
|
392
|
+
| `>_` | Copy shell script (mkdir + touch) |
|
|
393
|
+
| Search | Filter nodes by name/description/note |
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
## Programmatic API
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
import {
|
|
401
|
+
validateTreeInput,
|
|
402
|
+
parseTree,
|
|
403
|
+
parseAsciiTree,
|
|
404
|
+
scanDirectory,
|
|
405
|
+
} from 'vitepress-plugin-folder-tree'
|
|
406
|
+
|
|
407
|
+
// Validate YAML
|
|
408
|
+
const result = validateTreeInput(yamlString)
|
|
409
|
+
// { valid: boolean, errors: string[], warnings: string[] }
|
|
410
|
+
|
|
411
|
+
// Parse YAML → TreeNode[]
|
|
412
|
+
const { tree, options } = parseTree(yamlString)
|
|
413
|
+
|
|
414
|
+
// Parse ASCII → TreeNode[]
|
|
415
|
+
const nodes = parseAsciiTree(asciiString)
|
|
416
|
+
|
|
417
|
+
// Scan filesystem → TreeNode[]
|
|
418
|
+
const tree = scanDirectory('/path', 5, ['node_modules'], ['*.ts'])
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## Development
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
pnpm install
|
|
427
|
+
pnpm build # build plugin
|
|
428
|
+
pnpm dev # dev server with examples
|
|
429
|
+
pnpm docs:build # build example docs
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
|
|
434
|
+
## Links
|
|
435
|
+
|
|
436
|
+
- [GitHub](https://github.com/s00d/vitepress-plugin-folder-tree)
|
|
437
|
+
- [npm](https://www.npmjs.com/package/vitepress-plugin-folder-tree)
|
|
438
|
+
- [Issues](https://github.com/s00d/vitepress-plugin-folder-tree/issues)
|
|
439
|
+
- [Live Demo](https://github.com/s00d/vitepress-plugin-folder-tree#readme)
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## License
|
|
444
|
+
|
|
445
|
+
[MIT](https://github.com/s00d/vitepress-plugin-folder-tree/blob/main/LICENSE) © [s00d](https://github.com/s00d)
|