rspress-plugin-file-tree 0.4.0 → 1.0.1

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 (59) 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~311.js +2 -0
  9. package/dist/0~326.js +2 -0
  10. package/dist/0~40.js +2 -0
  11. package/dist/0~43.js +2 -0
  12. package/dist/0~433.js +2 -0
  13. package/dist/0~453.js +2 -0
  14. package/dist/0~457.js +2 -0
  15. package/dist/0~497.js +2 -0
  16. package/dist/0~511.js +2 -0
  17. package/dist/0~603.js +2 -0
  18. package/dist/0~616.js +2 -0
  19. package/dist/0~659.js +2 -0
  20. package/dist/0~670.js +2 -0
  21. package/dist/0~687.js +2 -0
  22. package/dist/0~706.js +2 -0
  23. package/dist/0~729.js +2 -0
  24. package/dist/0~768.js +2 -0
  25. package/dist/0~819.js +2 -0
  26. package/dist/0~830.js +2 -0
  27. package/dist/0~854.js +2 -0
  28. package/dist/0~863.js +2 -0
  29. package/dist/0~879.js +2 -0
  30. package/dist/0~96.js +2 -0
  31. package/dist/0~97.js +2 -0
  32. package/dist/components/FileTree/FileTree.css +83 -0
  33. package/dist/components/FileTree/FileTree.d.ts +7 -0
  34. package/dist/components/FileTree/FileTree.js +516 -0
  35. package/dist/components/FileTree/FileTreeItem.d.ts +8 -0
  36. package/dist/components/FileTree/RemoteSvgIcon.d.ts +11 -0
  37. package/dist/components/FileTree/index.d.ts +4 -0
  38. package/dist/components/folder-icons.d.ts +32 -0
  39. package/dist/components/languages.d.ts +7 -0
  40. package/dist/components/tree-parser/tree-parser.d.ts +12 -0
  41. package/dist/components/tree-parser/types.d.ts +10 -0
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +85 -17
  44. package/package.json +11 -8
  45. package/components/Tree/Expand.tsx +0 -149
  46. package/components/Tree/FileIcon.tsx +0 -41
  47. package/components/Tree/FileTreeRender.tsx +0 -16
  48. package/components/Tree/Tree.tsx +0 -112
  49. package/components/Tree/TreeContext.tsx +0 -18
  50. package/components/Tree/TreeFile.tsx +0 -69
  51. package/components/Tree/TreeFolder.tsx +0 -108
  52. package/components/Tree/TreeFolderIcon.tsx +0 -40
  53. package/components/Tree/TreeIndents.tsx +0 -26
  54. package/components/Tree/TreeStatusIcon.tsx +0 -45
  55. package/components/Tree/index.less +0 -178
  56. package/components/helpers.ts +0 -42
  57. package/components/presets.ts +0 -5
  58. package/dist/parser.d.ts +0 -8
  59. package/dist/parser.js +0 -40
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import { buildClassName } from '../presets';
3
-
4
- export interface TreeFolderIconProps {
5
- color?: string;
6
- width?: number;
7
- height?: number;
8
- }
9
-
10
- const defaultProps = {
11
- width: 22,
12
- height: 22,
13
- };
14
-
15
- const TreeFolderIcon: React.FC<TreeFolderIconProps> = ({
16
- color,
17
- width,
18
- height,
19
- }: TreeFolderIconProps & typeof defaultProps) => {
20
- return (
21
- <svg
22
- className={buildClassName('folder-icon')}
23
- viewBox="0 0 24 24"
24
- width={width}
25
- height={height}
26
- stroke="currentColor"
27
- strokeWidth="1"
28
- strokeLinecap="round"
29
- strokeLinejoin="round"
30
- fill="none"
31
- shapeRendering="geometricPrecision"
32
- >
33
- <path d="M2.707 7.454V5.62C2.707 4.725 3.469 4 4.409 4h4.843c.451 0 .884.17 1.204.474l.49.467c.126.12.296.186.473.186h8.399c.94 0 1.55.695 1.55 1.59v.737m-18.661 0h-.354a.344.344 0 00-.353.35l.508 11.587c.015.34.31.609.668.609h17.283c.358 0 .652-.269.667-.61L22 7.805a.344.344 0 00-.353-.35h-.278m-18.662 0h18.662" />
34
- </svg>
35
- );
36
- };
37
-
38
- TreeFolderIcon.defaultProps = defaultProps;
39
- TreeFolderIcon.displayName = 'GeistTreeFolderIcon';
40
- export default TreeFolderIcon;
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import { buildClassName } from '../presets';
3
-
4
- interface Props {
5
- count: number;
6
- }
7
-
8
- const TreeIndents: React.FC<Props> = ({ count }) => {
9
- if (count === 0) return null;
10
-
11
- return (
12
- <>
13
- {[...new Array(count)].map((_, index) => (
14
- <span
15
- className={buildClassName('indent')}
16
- key={`indent-${index}`}
17
- style={{
18
- left: `calc(-1.875rem * ${index + 1} + 0.75rem)`,
19
- }}
20
- ></span>
21
- ))}
22
- </>
23
- );
24
- };
25
-
26
- export default TreeIndents;
@@ -1,45 +0,0 @@
1
- import React from 'react';
2
- import { buildClassName } from '../presets';
3
-
4
- export interface TreeStatusIconProps {
5
- color?: string;
6
- width?: number;
7
- height?: number;
8
- active?: boolean;
9
- }
10
-
11
- const defaultProps = {
12
- width: 12,
13
- height: 12,
14
- active: false,
15
- };
16
-
17
- const TreeStatusIcon: React.FC<TreeStatusIconProps> = ({
18
- color,
19
- width,
20
- height,
21
- active,
22
- }: TreeStatusIconProps & typeof defaultProps) => {
23
- return (
24
- <svg
25
- className={buildClassName('folder-status-icon')}
26
- viewBox="0 0 24 24"
27
- width={width}
28
- height={height}
29
- stroke="currentColor"
30
- strokeWidth="1.5"
31
- strokeLinecap="round"
32
- strokeLinejoin="round"
33
- fill="none"
34
- shapeRendering="geometricPrecision"
35
- >
36
- <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
37
- {!active && <path d="M12 8v8" />}
38
- <path d="M8 12h8" />
39
- </svg>
40
- );
41
- };
42
-
43
- TreeStatusIcon.defaultProps = defaultProps;
44
- TreeStatusIcon.displayName = 'GeistTreeStatusIcon';
45
- export default TreeStatusIcon;
@@ -1,178 +0,0 @@
1
- @rp-file-tree: ~'rp-file-tree';
2
-
3
- @rp-tree-color-light: #000;
4
- @rp-tree-color-dark: #fafafa;
5
-
6
- @rp-tree-status-bg-light: #fff;
7
- @rp-tree-status-bg-dark: #000;
8
-
9
- @rp-tree-indent-bg-light: #eaeaea;
10
- @rp-tree-indent-bg-dark: #333;
11
-
12
- .@{rp-file-tree} {
13
- &[data-dark='true'] {
14
- --rp-tree-color: @rp-tree-color-dark;
15
- --rp-tree-status-bg: @rp-tree-status-bg-dark;
16
- --rp-tree-indent-bg: @rp-tree-indent-bg-dark;
17
- }
18
-
19
- &[data-dark='false'] {
20
- --rp-tree-color: @rp-tree-color-light;
21
- --rp-tree-status-bg: @rp-tree-status-bg-light;
22
- --rp-tree-indent-bg: @rp-tree-indent-bg-light;
23
- }
24
-
25
- padding-left: 1.625rem;
26
-
27
- &-expand {
28
- &-container {
29
- padding: 0;
30
- margin: 0;
31
- overflow: hidden;
32
-
33
- &-expanded {
34
- height: auto;
35
- visibility: visible;
36
- }
37
- }
38
- }
39
-
40
- &-indent {
41
- position: absolute;
42
- top: 50%;
43
- transform: translateY(-50%);
44
- width: 1px;
45
- height: 100%;
46
- background-color: var(--rp-tree-indent-bg);
47
- margin-left: -1px;
48
- }
49
-
50
- &-folder {
51
- cursor: pointer;
52
- line-height: 1;
53
- user-select: none;
54
-
55
- &-names {
56
- display: flex;
57
- height: 1.75rem;
58
- align-items: center;
59
- position: relative;
60
-
61
- & > :global(.@{rp-file-tree}-indent) {
62
- position: absolute;
63
- top: 50%;
64
- transform: translateY(-50%);
65
- width: 1px;
66
- height: 100%;
67
- background-color: var(--rp-tree-indent-bg);
68
- margin-left: -1px;
69
- }
70
- }
71
-
72
- &-icon {
73
- margin-right: 0.3rem;
74
-
75
- & > svg {
76
- color: var(--rp-tree-color);
77
- }
78
- }
79
-
80
- &-status {
81
- position: absolute;
82
- left: calc(-1.125rem);
83
- top: 50%;
84
- transform: translate(-50%, -50%);
85
- width: 0.875rem;
86
- height: 0.875rem;
87
- z-index: 10;
88
- background-color: var(--rp-tree-status-bg);
89
-
90
- & > svg {
91
- color: var(--rp-tree-color);
92
- }
93
- }
94
-
95
- &-status,
96
- &-icon {
97
- display: inline-flex;
98
- align-items: center;
99
- justify-content: center;
100
- }
101
-
102
- &-name {
103
- transition: opacity 100ms ease 0ms;
104
- white-space: nowrap;
105
- font-size: 0.875rem;
106
- color: var(--rp-tree-color);
107
-
108
- &:hover {
109
- opacity: 0.7;
110
- }
111
- }
112
-
113
- &-extra {
114
- font-size: 0.75rem;
115
- align-self: baseline;
116
- padding-left: 4px;
117
- color: #888;
118
- }
119
-
120
- &-content {
121
- display: flex;
122
- flex-direction: column;
123
- height: auto;
124
- }
125
- }
126
-
127
- &-file {
128
- cursor: pointer;
129
- line-height: 1;
130
- user-select: none;
131
-
132
- &-names {
133
- display: flex;
134
- height: 1.75rem;
135
- align-items: center;
136
- position: relative;
137
-
138
- & > :global(.@{rp-file-tree}-indent) {
139
- position: absolute;
140
- top: 50%;
141
- transform: translateY(-50%);
142
- width: 1px;
143
- height: 100%;
144
- background-color: var(--rp-tree-indent-bg);
145
-
146
- margin-left: -1px;
147
- }
148
- }
149
-
150
- &-icon {
151
- display: inline-flex;
152
- align-items: center;
153
- margin-right: 0.3rem;
154
-
155
- & > svg {
156
- color: var(--rp-tree-color);
157
- }
158
- }
159
-
160
- &-name {
161
- transition: opacity 100ms ease 0ms;
162
- color: var(--rp-tree-color);
163
- white-space: nowrap;
164
- font-size: 0.875rem;
165
-
166
- &:hover {
167
- opacity: 0.7;
168
- }
169
- }
170
-
171
- &-extra {
172
- font-size: 0.75rem;
173
- align-self: baseline;
174
- padding-left: 4px;
175
- color: #888;
176
- }
177
- }
178
- }
@@ -1,42 +0,0 @@
1
- import React, { type ReactNode } from 'react';
2
-
3
- export const sortChildren = (
4
- children: ReactNode | undefined,
5
- folderComponentType: React.ElementType,
6
- ) => {
7
- return React.Children.toArray(children).sort((a, b) => {
8
- if (!React.isValidElement(a) || !React.isValidElement(b)) return 0;
9
- if (a.type !== b.type) return a.type !== folderComponentType ? 1 : -1;
10
- return `${a.props.name}`.charCodeAt(0) - `${b.props.name}`.charCodeAt(0);
11
- });
12
- };
13
-
14
- export const makeChildPath = (name: string, parentPath?: string) => {
15
- if (!parentPath) return name;
16
- return `${parentPath}/${name}`;
17
- };
18
-
19
- export const stopPropagation = (event: React.MouseEvent) => {
20
- event.stopPropagation();
21
- event.nativeEvent.stopImmediatePropagation();
22
- };
23
-
24
- export const setChildrenProps = (
25
- children: ReactNode | undefined,
26
- props: Record<string, unknown>,
27
- targetComponents: Array<React.ElementType> = [],
28
- ): ReactNode | undefined => {
29
- if (React.Children.count(children) === 0) return [];
30
- const allowAll = targetComponents.length === 0;
31
- const clone = (child: React.ReactElement, props = {}) =>
32
- React.cloneElement(child, props);
33
-
34
- return React.Children.map(children, (item) => {
35
- if (!React.isValidElement(item)) return item;
36
- if (allowAll) return clone(item, props);
37
-
38
- const isAllowed = targetComponents.find((child) => child === item.type);
39
- if (isAllowed) return clone(item, props);
40
- return item;
41
- });
42
- };
@@ -1,5 +0,0 @@
1
- export const presetClassName = 'rp-file-tree';
2
-
3
- export function buildClassName(fragment?: string) {
4
- return fragment?.length ? `${presetClassName}-${fragment}` : presetClassName;
5
- }
package/dist/parser.d.ts DELETED
@@ -1,8 +0,0 @@
1
- type TreeItem = {
2
- type: 'file' | 'directory';
3
- name: string;
4
- extra?: string;
5
- files?: TreeItem[];
6
- };
7
- export declare function parseInput(input: string): TreeItem[];
8
- export {};
package/dist/parser.js DELETED
@@ -1,40 +0,0 @@
1
- function countLeadingSpaces(line) {
2
- const matches = line.match(/^(\s*\│\s*)*/);
3
- if (!matches)
4
- return 0;
5
- return matches[0].length;
6
- }
7
- export function parseInput(input) {
8
- var _a, _b;
9
- const lines = input.split('\n').filter((line) => line.trim());
10
- const tree = [];
11
- const stack = [];
12
- for (let i = 0; i < lines.length; i++) {
13
- const line = lines[i];
14
- if (line === '.')
15
- continue;
16
- const level = countLeadingSpaces(line);
17
- const normalizedLine = line.split('─').slice(-1)[0].trimStart();
18
- const [_, name, extra = ''] = (_a = normalizedLine.match(/^(.*?)(?:\s*\/\/\s*(.*))?$/)) !== null && _a !== void 0 ? _a : [];
19
- const nextLine = lines[i + 1] || '';
20
- const nextLineLevel = countLeadingSpaces(nextLine);
21
- const type = nextLineLevel > level ? 'directory' : 'file';
22
- const item = type === 'directory'
23
- ? { type, name, files: [], extra }
24
- : { type, name, extra };
25
- while (stack.length > 0 && stack[stack.length - 1].level >= level) {
26
- stack.pop();
27
- }
28
- if (stack.length === 0) {
29
- tree.push(item);
30
- }
31
- else {
32
- const parentItem = stack[stack.length - 1].item;
33
- (_b = parentItem.files) === null || _b === void 0 ? void 0 : _b.push(item);
34
- }
35
- if (item.type === 'directory') {
36
- stack.push({ level, item });
37
- }
38
- }
39
- return tree;
40
- }