rspress-plugin-file-tree 1.0.0 → 1.0.2

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.
Files changed (47) hide show
  1. package/dist/0~142.js +2 -0
  2. package/dist/0~164.js +2 -0
  3. package/dist/0~2.js +2 -0
  4. package/dist/0~225.js +2 -0
  5. package/dist/0~288.js +2 -0
  6. package/dist/0~299.js +2 -0
  7. package/dist/0~3.js +2 -0
  8. package/dist/0~301.js +2 -0
  9. package/dist/0~311.js +2 -0
  10. package/dist/0~326.js +2 -0
  11. package/dist/0~40.js +2 -0
  12. package/dist/0~43.js +2 -0
  13. package/dist/0~433.js +2 -0
  14. package/dist/0~453.js +2 -0
  15. package/dist/0~457.js +2 -0
  16. package/dist/0~497.js +2 -0
  17. package/dist/0~511.js +2 -0
  18. package/dist/0~603.js +2 -0
  19. package/dist/0~616.js +2 -0
  20. package/dist/0~659.js +2 -0
  21. package/dist/0~670.js +2 -0
  22. package/dist/0~687.js +2 -0
  23. package/dist/0~706.js +2 -0
  24. package/dist/0~729.js +2 -0
  25. package/dist/0~768.js +2 -0
  26. package/dist/0~819.js +2 -0
  27. package/dist/0~830.js +2 -0
  28. package/dist/0~854.js +2 -0
  29. package/dist/0~863.js +2 -0
  30. package/dist/0~879.js +2 -0
  31. package/dist/0~96.js +2 -0
  32. package/dist/0~97.js +2 -0
  33. package/dist/components/FileTree/{FileTreeItem_module.css → FileTree.css} +24 -2
  34. package/dist/components/FileTree/FileTree.js +526 -5
  35. package/dist/components/tree-parser/types.d.ts +1 -0
  36. package/dist/index.js +134 -2
  37. package/package.json +1 -1
  38. package/dist/components/FileTree/FileTree.module.js +0 -5
  39. package/dist/components/FileTree/FileTreeItem.js +0 -80
  40. package/dist/components/FileTree/FileTreeItem.module.js +0 -11
  41. package/dist/components/FileTree/FileTree_module.css +0 -12
  42. package/dist/components/FileTree/RemoteSvgIcon.js +0 -26
  43. package/dist/components/FileTree/index.js +0 -4
  44. package/dist/components/folder-icons.js +0 -177
  45. package/dist/components/languages.js +0 -98
  46. package/dist/components/tree-parser/tree-parser.js +0 -68
  47. package/dist/components/tree-parser/types.js +0 -0
@@ -1,7 +1,527 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import "react";
3
- import FileTree_module from "./FileTree.module.js";
4
- import { FileTreeItem } from "./FileTreeItem.js";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ var __webpack_modules__ = {};
4
+ var __webpack_module_cache__ = {};
5
+ function __webpack_require__(moduleId) {
6
+ var cachedModule = __webpack_module_cache__[moduleId];
7
+ if (void 0 !== cachedModule) return cachedModule.exports;
8
+ var module = __webpack_module_cache__[moduleId] = {
9
+ exports: {}
10
+ };
11
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
12
+ return module.exports;
13
+ }
14
+ __webpack_require__.m = __webpack_modules__;
15
+ (()=>{
16
+ __webpack_require__.add = function(modules) {
17
+ Object.assign(__webpack_require__.m, modules);
18
+ };
19
+ })();
20
+ const FileTree_module = {
21
+ container: "container-ZPDb1C"
22
+ };
23
+ const SUPPORTED_LANGUAGES = [
24
+ {
25
+ id: "javascript",
26
+ icons: [
27
+ {
28
+ name: "javascript",
29
+ content: ()=>import("../../0~311.js").then((mod)=>({
30
+ default: mod.javascriptraw_namespaceObject
31
+ })),
32
+ matcher: /^.*\.js$/
33
+ },
34
+ {
35
+ name: "javascript-beta",
36
+ content: ()=>import("../../0~311.js").then((mod)=>({
37
+ default: mod.javascriptraw_namespaceObject
38
+ })),
39
+ matcher: /^.*\.cjs$/
40
+ },
41
+ {
42
+ name: "javascript-beta",
43
+ content: ()=>import("../../0~311.js").then((mod)=>({
44
+ default: mod.javascriptraw_namespaceObject
45
+ })),
46
+ matcher: /^.*\.mjs$/
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ id: "typescript",
52
+ icons: [
53
+ {
54
+ name: "typescript",
55
+ content: ()=>import("../../0~687.js").then((mod)=>({
56
+ default: mod.typescriptraw_namespaceObject
57
+ })),
58
+ matcher: /^.*\.ts$/
59
+ },
60
+ {
61
+ name: "typescript-beta",
62
+ content: ()=>import("../../0~687.js").then((mod)=>({
63
+ default: mod.typescriptraw_namespaceObject
64
+ })),
65
+ matcher: /^.*\.mts$/
66
+ },
67
+ {
68
+ name: "typescript-beta",
69
+ content: ()=>import("../../0~687.js").then((mod)=>({
70
+ default: mod.typescriptraw_namespaceObject
71
+ })),
72
+ matcher: /^.*\.cts$/
73
+ },
74
+ {
75
+ name: 'react_ts',
76
+ content: ()=>import("../../0~453.js").then((mod)=>({
77
+ default: mod.react_tsraw_namespaceObject
78
+ })),
79
+ matcher: /^.*\.tsx$/
80
+ }
81
+ ]
82
+ },
83
+ {
84
+ id: 'react',
85
+ icons: [
86
+ {
87
+ name: 'react',
88
+ content: ()=>import("../../0~3.js").then((mod)=>({
89
+ default: mod.reactraw_namespaceObject
90
+ })),
91
+ matcher: /^.*\.jsx$/
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ id: 'css',
97
+ icons: [
98
+ {
99
+ name: 'css',
100
+ content: ()=>import("../../0~659.js").then((mod)=>({
101
+ default: mod.cssraw_namespaceObject
102
+ })),
103
+ matcher: /^.*\.css$/
104
+ },
105
+ {
106
+ name: 'less',
107
+ content: ()=>import("../../0~225.js").then((mod)=>({
108
+ default: mod.lessraw_namespaceObject
109
+ })),
110
+ matcher: /^.*\.less$/
111
+ },
112
+ {
113
+ name: 'sass',
114
+ content: ()=>import("../../0~670.js").then((mod)=>({
115
+ default: mod.sassraw_namespaceObject
116
+ })),
117
+ matcher: /^.*\.scss$/
118
+ }
119
+ ]
120
+ },
121
+ {
122
+ id: 'json',
123
+ icons: [
124
+ {
125
+ name: 'json',
126
+ content: ()=>import("../../0~706.js").then((mod)=>({
127
+ default: mod.jsonraw_namespaceObject
128
+ })),
129
+ matcher: /^.*\.json$/
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ id: 'markdown',
135
+ icons: [
136
+ {
137
+ name: 'markdown',
138
+ content: ()=>import("../../0~497.js").then((mod)=>({
139
+ default: mod.markdownraw_namespaceObject
140
+ })),
141
+ matcher: /^.*\.(md|mdx)$/
142
+ }
143
+ ]
144
+ },
145
+ {
146
+ id: 'html',
147
+ icons: [
148
+ {
149
+ name: 'html',
150
+ content: ()=>import("../../0~301.js").then((mod)=>({
151
+ default: mod.htmlraw_namespaceObject
152
+ })),
153
+ matcher: /^.*\.html?$/
154
+ }
155
+ ]
156
+ }
157
+ ];
158
+ const FOLDER_ICONS = {
159
+ src: {
160
+ name: 'folder-src',
161
+ content: ()=>import("../../0~603.js").then((mod)=>({
162
+ default: mod.folder_srcraw_namespaceObject
163
+ }))
164
+ },
165
+ source: {
166
+ name: 'folder-src',
167
+ content: ()=>import("../../0~603.js").then((mod)=>({
168
+ default: mod.folder_srcraw_namespaceObject
169
+ }))
170
+ },
171
+ components: {
172
+ name: 'folder-components',
173
+ content: ()=>import("../../0~299.js").then((mod)=>({
174
+ default: mod.folder_componentsraw_namespaceObject
175
+ }))
176
+ },
177
+ component: {
178
+ name: 'folder-components',
179
+ content: ()=>import("../../0~299.js").then((mod)=>({
180
+ default: mod.folder_componentsraw_namespaceObject
181
+ }))
182
+ },
183
+ hooks: {
184
+ name: 'folder-hook',
185
+ content: ()=>import("../../0~40.js").then((mod)=>({
186
+ default: mod.folder_hookraw_namespaceObject
187
+ }))
188
+ },
189
+ hook: {
190
+ name: 'folder-hook',
191
+ content: ()=>import("../../0~40.js").then((mod)=>({
192
+ default: mod.folder_hookraw_namespaceObject
193
+ }))
194
+ },
195
+ utils: {
196
+ name: 'folder-utils',
197
+ content: ()=>import("../../0~288.js").then((mod)=>({
198
+ default: mod.folder_utilsraw_namespaceObject
199
+ }))
200
+ },
201
+ util: {
202
+ name: 'folder-utils',
203
+ content: ()=>import("../../0~288.js").then((mod)=>({
204
+ default: mod.folder_utilsraw_namespaceObject
205
+ }))
206
+ },
207
+ lib: {
208
+ name: 'folder-lib',
209
+ content: ()=>import("../../0~2.js").then((mod)=>({
210
+ default: mod.folder_libraw_namespaceObject
211
+ }))
212
+ },
213
+ libs: {
214
+ name: 'folder-lib',
215
+ content: ()=>import("../../0~2.js").then((mod)=>({
216
+ default: mod.folder_libraw_namespaceObject
217
+ }))
218
+ },
219
+ core: {
220
+ name: 'folder-core',
221
+ content: ()=>import("../../0~164.js").then((mod)=>({
222
+ default: mod.folder_coreraw_namespaceObject
223
+ }))
224
+ },
225
+ runtime: {
226
+ name: 'folder-core',
227
+ content: ()=>import("../../0~164.js").then((mod)=>({
228
+ default: mod.folder_coreraw_namespaceObject
229
+ }))
230
+ },
231
+ locales: {
232
+ name: 'folder-i18n',
233
+ content: ()=>import("../../0~511.js").then((mod)=>({
234
+ default: mod.folder_i18nraw_namespaceObject
235
+ }))
236
+ },
237
+ locale: {
238
+ name: 'folder-i18n',
239
+ content: ()=>import("../../0~511.js").then((mod)=>({
240
+ default: mod.folder_i18nraw_namespaceObject
241
+ }))
242
+ },
243
+ i18n: {
244
+ name: 'folder-i18n',
245
+ content: ()=>import("../../0~511.js").then((mod)=>({
246
+ default: mod.folder_i18nraw_namespaceObject
247
+ }))
248
+ },
249
+ assets: {
250
+ name: 'folder-images',
251
+ content: ()=>import("../../0~433.js").then((mod)=>({
252
+ default: mod.folder_imagesraw_namespaceObject
253
+ }))
254
+ },
255
+ images: {
256
+ name: 'folder-images',
257
+ content: ()=>import("../../0~433.js").then((mod)=>({
258
+ default: mod.folder_imagesraw_namespaceObject
259
+ }))
260
+ },
261
+ styles: {
262
+ name: 'folder-css',
263
+ content: ()=>import("../../0~854.js").then((mod)=>({
264
+ default: mod.folder_cssraw_namespaceObject
265
+ }))
266
+ },
267
+ css: {
268
+ name: 'folder-css',
269
+ content: ()=>import("../../0~854.js").then((mod)=>({
270
+ default: mod.folder_cssraw_namespaceObject
271
+ }))
272
+ },
273
+ test: {
274
+ name: 'folder-test',
275
+ content: ()=>import("../../0~43.js").then((mod)=>({
276
+ default: mod.folder_testraw_namespaceObject
277
+ }))
278
+ },
279
+ tests: {
280
+ name: 'folder-test',
281
+ content: ()=>import("../../0~43.js").then((mod)=>({
282
+ default: mod.folder_testraw_namespaceObject
283
+ }))
284
+ },
285
+ __tests__: {
286
+ name: 'folder-test',
287
+ content: ()=>import("../../0~43.js").then((mod)=>({
288
+ default: mod.folder_testraw_namespaceObject
289
+ }))
290
+ },
291
+ config: {
292
+ name: 'folder-config',
293
+ content: ()=>import("../../0~729.js").then((mod)=>({
294
+ default: mod.folder_configraw_namespaceObject
295
+ }))
296
+ },
297
+ configs: {
298
+ name: 'folder-config',
299
+ content: ()=>import("../../0~729.js").then((mod)=>({
300
+ default: mod.folder_configraw_namespaceObject
301
+ }))
302
+ },
303
+ api: {
304
+ name: 'folder-api',
305
+ content: ()=>import("../../0~97.js").then((mod)=>({
306
+ default: mod.folder_apiraw_namespaceObject
307
+ }))
308
+ },
309
+ apis: {
310
+ name: 'folder-api',
311
+ content: ()=>import("../../0~97.js").then((mod)=>({
312
+ default: mod.folder_apiraw_namespaceObject
313
+ }))
314
+ },
315
+ public: {
316
+ name: 'folder-public',
317
+ content: ()=>import("../../0~830.js").then((mod)=>({
318
+ default: mod.folder_publicraw_namespaceObject
319
+ }))
320
+ },
321
+ dist: {
322
+ name: 'folder-dist',
323
+ content: ()=>import("../../0~879.js").then((mod)=>({
324
+ default: mod.folder_distraw_namespaceObject
325
+ }))
326
+ },
327
+ build: {
328
+ name: 'folder-dist',
329
+ content: ()=>import("../../0~879.js").then((mod)=>({
330
+ default: mod.folder_distraw_namespaceObject
331
+ }))
332
+ },
333
+ node_modules: {
334
+ name: 'folder-node',
335
+ content: ()=>import("../../0~863.js").then((mod)=>({
336
+ default: mod.folder_noderaw_namespaceObject
337
+ }))
338
+ },
339
+ types: {
340
+ name: "folder-typescript",
341
+ content: ()=>import("../../0~616.js").then((mod)=>({
342
+ default: mod.folder_typescriptraw_namespaceObject
343
+ }))
344
+ },
345
+ typings: {
346
+ name: "folder-typescript",
347
+ content: ()=>import("../../0~616.js").then((mod)=>({
348
+ default: mod.folder_typescriptraw_namespaceObject
349
+ }))
350
+ },
351
+ pages: {
352
+ name: 'folder-views',
353
+ content: ()=>import("../../0~819.js").then((mod)=>({
354
+ default: mod.folder_viewsraw_namespaceObject
355
+ }))
356
+ },
357
+ views: {
358
+ name: 'folder-views',
359
+ content: ()=>import("../../0~819.js").then((mod)=>({
360
+ default: mod.folder_viewsraw_namespaceObject
361
+ }))
362
+ },
363
+ routes: {
364
+ name: 'folder-routes',
365
+ content: ()=>import("../../0~457.js").then((mod)=>({
366
+ default: mod.folder_routesraw_namespaceObject
367
+ }))
368
+ },
369
+ docs: {
370
+ name: 'folder-docs',
371
+ content: ()=>import("../../0~768.js").then((mod)=>({
372
+ default: mod.folder_docsraw_namespaceObject
373
+ }))
374
+ },
375
+ services: {
376
+ name: 'folder-app',
377
+ content: ()=>import("../../0~142.js").then((mod)=>({
378
+ default: mod.folder_appraw_namespaceObject
379
+ }))
380
+ },
381
+ app: {
382
+ name: 'folder-app',
383
+ content: ()=>import("../../0~142.js").then((mod)=>({
384
+ default: mod.folder_appraw_namespaceObject
385
+ }))
386
+ }
387
+ };
388
+ const DEFAULT_FOLDER_ICON = {
389
+ name: 'folder',
390
+ content: ()=>import("../../0~96.js").then((mod)=>({
391
+ default: mod.folderraw_namespaceObject
392
+ }))
393
+ };
394
+ const DEFAULT_FILE_ICON = {
395
+ name: 'file',
396
+ content: ()=>import("../../0~326.js").then((mod)=>({
397
+ default: mod.fileraw_namespaceObject
398
+ })),
399
+ matcher: /^.*$/
400
+ };
401
+ function getFolderIcon(name) {
402
+ const lowerName = name.toLowerCase();
403
+ return FOLDER_ICONS[lowerName] || DEFAULT_FOLDER_ICON;
404
+ }
405
+ function getFileIcon(fileName) {
406
+ for (const language of SUPPORTED_LANGUAGES)for (const icon of language.icons)if (icon.matcher.test(fileName)) return {
407
+ name: icon.name,
408
+ content: icon.content,
409
+ matcher: icon.matcher
410
+ };
411
+ return DEFAULT_FILE_ICON;
412
+ }
413
+ const FileTreeItem_module = {
414
+ item: "item-mfHlfR",
415
+ row: "row-AOLrYw",
416
+ chevron: "chevron-Zi120f",
417
+ iconWrapper: "iconWrapper-SwAXs4",
418
+ name: "name-ItNtUc",
419
+ comment: "comment-_zMtnb",
420
+ children: "children-yp3kEz",
421
+ indentGuide: "indentGuide-bjr2fi"
422
+ };
423
+ const RemoteSvgIcon = ({ content, className })=>{
424
+ const [svgContent, setSvgContent] = useState('');
425
+ useEffect(()=>{
426
+ let cancelled = false;
427
+ content().then((mod)=>{
428
+ if (cancelled) return;
429
+ const svg = 'string' == typeof mod ? mod : mod.default;
430
+ setSvgContent(svg);
431
+ });
432
+ return ()=>{
433
+ cancelled = true;
434
+ };
435
+ }, [
436
+ content
437
+ ]);
438
+ if (!svgContent) return null;
439
+ return /*#__PURE__*/ jsx("span", {
440
+ className: className,
441
+ dangerouslySetInnerHTML: {
442
+ __html: svgContent
443
+ }
444
+ });
445
+ };
446
+ const INDENT_SIZE = 12;
447
+ const FileTreeItem = ({ node, depth })=>{
448
+ const hasChildren = 'directory' === node.type && node.children.length > 0;
449
+ const [expanded, setExpanded] = useState(hasChildren);
450
+ const icon = useMemo(()=>{
451
+ if ('directory' === node.type) return getFolderIcon(node.name);
452
+ return getFileIcon(node.name);
453
+ }, [
454
+ node.name,
455
+ node.type
456
+ ]);
457
+ const isDirectory = 'directory' === node.type;
458
+ const toggle = (e)=>{
459
+ e.stopPropagation();
460
+ if (isDirectory) setExpanded((p)=>!p);
461
+ };
462
+ return /*#__PURE__*/ jsxs("div", {
463
+ className: FileTreeItem_module.item,
464
+ children: [
465
+ /*#__PURE__*/ jsxs("div", {
466
+ className: FileTreeItem_module.row,
467
+ onClick: toggle,
468
+ style: {
469
+ paddingLeft: `${depth * INDENT_SIZE}px`
470
+ },
471
+ children: [
472
+ /*#__PURE__*/ jsx("div", {
473
+ className: FileTreeItem_module.chevron,
474
+ "data-expanded": expanded,
475
+ style: {
476
+ visibility: isDirectory ? 'visible' : 'hidden'
477
+ },
478
+ children: /*#__PURE__*/ jsx("svg", {
479
+ width: "16",
480
+ height: "16",
481
+ viewBox: "0 0 16 16",
482
+ fill: "currentColor",
483
+ children: /*#__PURE__*/ jsx("path", {
484
+ fillRule: "evenodd",
485
+ clipRule: "evenodd",
486
+ d: "M10.072 8.024L5.715 3.667l.618-.62L11 8.024l-4.667 4.977-.618-.62L10.072 8.024z"
487
+ })
488
+ })
489
+ }),
490
+ /*#__PURE__*/ jsx("div", {
491
+ className: FileTreeItem_module.iconWrapper,
492
+ children: /*#__PURE__*/ jsx(RemoteSvgIcon, {
493
+ content: icon.content,
494
+ className: FileTreeItem_module.iconWrapper
495
+ })
496
+ }),
497
+ /*#__PURE__*/ jsx("span", {
498
+ className: FileTreeItem_module.name,
499
+ children: node.name
500
+ }),
501
+ node.comment && /*#__PURE__*/ jsx("span", {
502
+ className: FileTreeItem_module.comment,
503
+ children: node.comment
504
+ })
505
+ ]
506
+ }),
507
+ isDirectory && node.children.length > 0 && expanded && /*#__PURE__*/ jsxs("div", {
508
+ className: FileTreeItem_module.children,
509
+ children: [
510
+ /*#__PURE__*/ jsx("div", {
511
+ className: FileTreeItem_module.indentGuide,
512
+ style: {
513
+ left: `${depth * INDENT_SIZE + 6}px`
514
+ }
515
+ }),
516
+ node.children.map((child, index)=>/*#__PURE__*/ jsx(FileTreeItem, {
517
+ node: child,
518
+ depth: depth + 1
519
+ }, `${child.name}-${index}`))
520
+ ]
521
+ })
522
+ ]
523
+ });
524
+ };
5
525
  const FileTree = ({ nodes })=>/*#__PURE__*/ jsx("div", {
6
526
  className: FileTree_module.container,
7
527
  children: nodes.map((node, index)=>/*#__PURE__*/ jsx(FileTreeItem, {
@@ -10,4 +530,5 @@ const FileTree = ({ nodes })=>/*#__PURE__*/ jsx("div", {
10
530
  }, `${node.name}-${index}`))
11
531
  });
12
532
  const FileTree_FileTree = FileTree;
13
- export { FileTree, FileTree_FileTree as default };
533
+ export default FileTree_FileTree;
534
+ export { __webpack_require__, FileTree };
@@ -3,6 +3,7 @@ export interface TreeNode {
3
3
  type: 'file' | 'directory';
4
4
  children: TreeNode[];
5
5
  extension?: string;
6
+ comment?: string;
6
7
  }
7
8
  export interface ParsedTree {
8
9
  nodes: TreeNode[];
package/dist/index.js CHANGED
@@ -1,6 +1,137 @@
1
1
  import node_path from "node:path";
2
2
  import { RemarkCodeBlockToGlobalComponentPluginFactory } from "rspress-plugin-devkit";
3
- import { parseTreeContent } from "./components/tree-parser/tree-parser.js";
3
+ function parseTreeContent(content) {
4
+ let lines = content.split('\n').filter((line)=>line.trim());
5
+ if (lines.length > 0 && '.' === lines[0].trim()) lines = lines.slice(1);
6
+ const nodes = [];
7
+ const stack = [];
8
+ for (const line of lines){
9
+ const indent = calculateIndent(line);
10
+ const fullName = extractName(line);
11
+ const { name, comment } = extractNameAndComment(fullName);
12
+ if (!name) continue;
13
+ const isDirectory = isDirectoryName(name);
14
+ const node = {
15
+ name: name.replace(/\/$/, ''),
16
+ type: isDirectory ? 'directory' : 'file',
17
+ children: [],
18
+ extension: isDirectory ? void 0 : getExtension(name),
19
+ comment
20
+ };
21
+ while(stack.length > 0 && stack[stack.length - 1].indent >= indent)stack.pop();
22
+ if (0 === stack.length) nodes.push(node);
23
+ else stack[stack.length - 1].node.children.push(node);
24
+ if ('directory' === node.type) stack.push({
25
+ node,
26
+ indent
27
+ });
28
+ }
29
+ return {
30
+ nodes,
31
+ raw: content
32
+ };
33
+ }
34
+ function calculateIndent(line) {
35
+ let indent = 0;
36
+ let i = 0;
37
+ while(i < line.length){
38
+ const char = line[i];
39
+ if ('│' === char && '│ ' === line.substring(i, i + 4)) {
40
+ indent++;
41
+ i += 4;
42
+ continue;
43
+ }
44
+ if ('│' === char && ' ' === line[i + 1]) {
45
+ indent++;
46
+ i += 2;
47
+ continue;
48
+ }
49
+ if (' ' === line.substring(i, i + 4)) {
50
+ indent++;
51
+ i += 4;
52
+ continue;
53
+ }
54
+ if (' ' === line.substring(i, i + 2)) {
55
+ indent++;
56
+ i += 2;
57
+ continue;
58
+ }
59
+ if ('├' === char || '└' === char) {
60
+ if ('├──' === line.substring(i, i + 3) || '└──' === line.substring(i, i + 3)) indent++;
61
+ }
62
+ break;
63
+ }
64
+ return indent;
65
+ }
66
+ function extractName(line) {
67
+ return line.replace(/^[\s│]*/g, '').replace(/^[├└]──\s*/, '').trim();
68
+ }
69
+ function extractNameAndComment(fullName) {
70
+ const trimmed = fullName.trim();
71
+ if (!trimmed) return {
72
+ name: '',
73
+ comment: void 0
74
+ };
75
+ if (/^\.{2,}$/.test(trimmed)) return {
76
+ name: trimmed,
77
+ comment: void 0
78
+ };
79
+ const doubleSpaceMatch = trimmed.match(/^(.+?)\s{2,}(.+)$/);
80
+ if (doubleSpaceMatch) {
81
+ const potentialName = doubleSpaceMatch[1].trim();
82
+ const potentialComment = doubleSpaceMatch[2].trim();
83
+ if (isValidName(potentialName)) return {
84
+ name: potentialName,
85
+ comment: potentialComment
86
+ };
87
+ }
88
+ const singleSpaceMatch = trimmed.match(/^(.+?\.[a-zA-Z0-9]+)\s+([^.].*)$/);
89
+ if (singleSpaceMatch) {
90
+ const potentialName = singleSpaceMatch[1].trim();
91
+ const potentialComment = singleSpaceMatch[2].trim();
92
+ return {
93
+ name: potentialName,
94
+ comment: potentialComment
95
+ };
96
+ }
97
+ const hiddenFileMatch = trimmed.match(/^(\.[^\s]+)\s+(.+)$/);
98
+ if (hiddenFileMatch) return {
99
+ name: hiddenFileMatch[1].trim(),
100
+ comment: hiddenFileMatch[2].trim()
101
+ };
102
+ const dirCommentMatch = trimmed.match(/^([\w][\w.\s-]*?)\s+([^a-zA-Z0-9].*)$/);
103
+ if (dirCommentMatch) {
104
+ const potentialName = dirCommentMatch[1].trim();
105
+ if (!/\.[a-zA-Z0-9]+$/.test(potentialName)) return {
106
+ name: potentialName,
107
+ comment: dirCommentMatch[2].trim()
108
+ };
109
+ }
110
+ return {
111
+ name: trimmed,
112
+ comment: void 0
113
+ };
114
+ }
115
+ function isValidName(name) {
116
+ if (!name) return false;
117
+ if (name.endsWith('/')) return true;
118
+ if (/\.[a-zA-Z0-9]+$/.test(name)) return true;
119
+ if (name.startsWith('.')) return true;
120
+ if (/^[\w\s.-]+$/.test(name)) return true;
121
+ return false;
122
+ }
123
+ function isDirectoryName(name) {
124
+ if (name.endsWith('/')) return true;
125
+ const lastPart = name.split('/').pop() || name;
126
+ if (/^\.{2,}$/.test(lastPart)) return false;
127
+ if (lastPart.startsWith('.')) return false;
128
+ if (/\.[a-zA-Z0-9]+$/.test(lastPart)) return false;
129
+ return true;
130
+ }
131
+ function getExtension(name) {
132
+ const match = name.match(/\.([^.]+)$/);
133
+ return match ? match[1] : '';
134
+ }
4
135
  const PACKAGE_ROOT = node_path.resolve(__dirname, '../');
5
136
  function rspressPluginFileTree(options = {}) {
6
137
  const { initialExpandDepth = 0 } = options;
@@ -26,7 +157,8 @@ function rspressPluginFileTree(options = {}) {
26
157
  ],
27
158
  globalComponents: remarkFileTree.mdxComponents
28
159
  },
160
+ globalStyles: node_path.join(PACKAGE_ROOT, 'dist/components/FileTree/FileTree.css'),
29
161
  builderConfig: remarkFileTree.builderConfig
30
162
  };
31
163
  }
32
- export { rspressPluginFileTree as default };
164
+ export default rspressPluginFileTree;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-file-tree",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Rspress plugin that add support for file tree component.",
5
5
  "files": [
6
6
  "dist"