rspress-plugin-file-tree 0.4.0 → 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/dist/components/FileTree/FileTree.d.ts +7 -0
- package/dist/components/FileTree/FileTree.js +13 -0
- package/dist/components/FileTree/FileTree.module.js +5 -0
- package/dist/components/FileTree/FileTreeItem.d.ts +8 -0
- package/dist/components/FileTree/FileTreeItem.js +80 -0
- package/dist/components/FileTree/FileTreeItem.module.js +11 -0
- package/dist/components/FileTree/FileTreeItem_module.css +71 -0
- package/dist/components/FileTree/FileTree_module.css +12 -0
- package/dist/components/FileTree/RemoteSvgIcon.d.ts +11 -0
- package/dist/components/FileTree/RemoteSvgIcon.js +26 -0
- package/dist/components/FileTree/index.d.ts +4 -0
- package/dist/components/FileTree/index.js +4 -0
- package/dist/components/folder-icons.d.ts +32 -0
- package/dist/components/folder-icons.js +177 -0
- package/dist/components/languages.d.ts +7 -0
- package/dist/components/languages.js +98 -0
- package/dist/components/tree-parser/tree-parser.d.ts +12 -0
- package/dist/components/tree-parser/tree-parser.js +68 -0
- package/dist/components/tree-parser/types.d.ts +10 -0
- package/dist/components/tree-parser/types.js +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -17
- package/package.json +11 -8
- package/components/Tree/Expand.tsx +0 -149
- package/components/Tree/FileIcon.tsx +0 -41
- package/components/Tree/FileTreeRender.tsx +0 -16
- package/components/Tree/Tree.tsx +0 -112
- package/components/Tree/TreeContext.tsx +0 -18
- package/components/Tree/TreeFile.tsx +0 -69
- package/components/Tree/TreeFolder.tsx +0 -108
- package/components/Tree/TreeFolderIcon.tsx +0 -40
- package/components/Tree/TreeIndents.tsx +0 -26
- package/components/Tree/TreeStatusIcon.tsx +0 -45
- package/components/Tree/index.less +0 -178
- package/components/helpers.ts +0 -42
- package/components/presets.ts +0 -5
- package/dist/parser.d.ts +0 -8
- package/dist/parser.js +0 -40
|
@@ -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
|
-
}
|
package/components/helpers.ts
DELETED
|
@@ -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
|
-
};
|
package/components/presets.ts
DELETED
package/dist/parser.d.ts
DELETED
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
|
-
}
|