@prozilla-os/file-explorer 1.0.4
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.md +21 -0
- package/README.md +1 -0
- package/package.json +37 -0
- package/src/components/FileExplorer.module.css +160 -0
- package/src/components/FileExplorer.tsx +278 -0
- package/src/components/ImportButton.tsx +44 -0
- package/src/components/QuickAccessButton.tsx +23 -0
- package/src/components/modals/file-properties/FileProperties.module.css +90 -0
- package/src/components/modals/file-properties/FileProperties.tsx +36 -0
- package/src/constants/fileExplorer.const.ts +5 -0
- package/src/index.ts +10 -0
- package/src/types/index.d.ts +5 -0
- package/src/types/vite-env.d.ts +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Sieben De Beule
|
|
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 @@
|
|
|
1
|
+
# @prozilla-os/file-explorer
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prozilla-os/file-explorer",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Prozilla",
|
|
6
|
+
"email": "business@prozilla.dev",
|
|
7
|
+
"url": "https://prozilla.dev/"
|
|
8
|
+
},
|
|
9
|
+
"main": "src/index.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/Prozilla/ProzillaOS.git",
|
|
14
|
+
"directory": "packages/apps/file-explorer"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
|
19
|
+
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
|
20
|
+
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
21
|
+
"react": "^18.3.1",
|
|
22
|
+
"@prozilla-os/core": "1.0.7"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.4.5"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src/**/*"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"registry": "https://registry.npmjs.org/",
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "tsc --watch"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
.FileExplorer {
|
|
2
|
+
--header-height: 3.5rem;
|
|
3
|
+
--sidebar-width: 10rem;
|
|
4
|
+
--footer-height: 1.75rem;
|
|
5
|
+
--scale: 1.15rem;
|
|
6
|
+
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.Header {
|
|
14
|
+
display: flex;
|
|
15
|
+
gap: 1rem;
|
|
16
|
+
align-items: center;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: var(--header-height);
|
|
19
|
+
padding: 1rem;
|
|
20
|
+
background-color: var(--background-color-0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.IconButton {
|
|
24
|
+
--color: var(--foreground-color-0);
|
|
25
|
+
|
|
26
|
+
position: relative;
|
|
27
|
+
height: 1.25rem;
|
|
28
|
+
width: auto;
|
|
29
|
+
padding: 0;
|
|
30
|
+
background: none;
|
|
31
|
+
border: none;
|
|
32
|
+
outline: none;
|
|
33
|
+
aspect-ratio: 1;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.IconButton::after {
|
|
38
|
+
content: "";
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: 0;
|
|
41
|
+
left: 0;
|
|
42
|
+
width: 100%;
|
|
43
|
+
height: 100%;
|
|
44
|
+
background-color: rgba(255, 255, 255, 0%);
|
|
45
|
+
border-radius: var(--border-radius-99);
|
|
46
|
+
transform: scale(100%);
|
|
47
|
+
transform-origin: center;
|
|
48
|
+
transition: all 200ms ease-in-out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.IconButton:hover::after, .IconButton:focus-visible::after {
|
|
52
|
+
background-color: rgba(255, 255, 255, 10%);
|
|
53
|
+
transform: scale(150%);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.IconButton:disabled {
|
|
57
|
+
--color: var(--background-color-1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.IconButton svg {
|
|
61
|
+
height: 100%;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.IconButton svg path {
|
|
65
|
+
fill: var(--color);
|
|
66
|
+
transition: fill 100ms ease-in-out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.PathInput {
|
|
70
|
+
flex: 1;
|
|
71
|
+
padding: 0.25rem 0.5rem;
|
|
72
|
+
background-color: var(--background-color-2);
|
|
73
|
+
border: none;
|
|
74
|
+
border-radius: var(--border-radius-1);
|
|
75
|
+
outline: none;
|
|
76
|
+
font-family: inherit;
|
|
77
|
+
font-size: inherit;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.Body {
|
|
81
|
+
flex: 1;
|
|
82
|
+
display: flex;
|
|
83
|
+
width: 100%;
|
|
84
|
+
height: calc(100% - var(--header-height));
|
|
85
|
+
background-color: var(--background-color-2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.Sidebar {
|
|
89
|
+
display: flex;
|
|
90
|
+
gap: 0.25rem;
|
|
91
|
+
flex-direction: column;
|
|
92
|
+
min-width: calc(var(--sidebar-width) / 2);
|
|
93
|
+
width: var(--sidebar-width);
|
|
94
|
+
height: 100%;
|
|
95
|
+
max-width: 50%;
|
|
96
|
+
padding: 0.5rem;
|
|
97
|
+
background-color: var(--background-color-1);
|
|
98
|
+
resize: horizontal;
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.NavButton {
|
|
103
|
+
display: flex;
|
|
104
|
+
gap: 0.5rem;
|
|
105
|
+
align-items: center;
|
|
106
|
+
width: 100%;
|
|
107
|
+
padding: 0.5rem;
|
|
108
|
+
background: none;
|
|
109
|
+
border: none;
|
|
110
|
+
border-radius: var(--border-radius-1);
|
|
111
|
+
outline: none;
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
transition: background-color 100ms ease-in-out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.NavButton:hover, .NavButton:focus-visible {
|
|
117
|
+
background-color: color-mix(in srgb, var(--background-color-0) 75%, transparent);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.NavButton svg {
|
|
121
|
+
height: 1.35rem;
|
|
122
|
+
aspect-ratio: 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.Main {
|
|
126
|
+
--scale: inherit !important;
|
|
127
|
+
|
|
128
|
+
position: relative;
|
|
129
|
+
flex: 1;
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-wrap: wrap;
|
|
132
|
+
align-content: flex-start;
|
|
133
|
+
height: 100%;
|
|
134
|
+
padding: 0.5rem;
|
|
135
|
+
padding-bottom: calc(0.5rem + var(--footer-height));
|
|
136
|
+
overflow: auto;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.Footer {
|
|
140
|
+
position: absolute;
|
|
141
|
+
display: flex;
|
|
142
|
+
justify-content: flex-start;
|
|
143
|
+
align-items: center;
|
|
144
|
+
bottom: 0;
|
|
145
|
+
left: 0;
|
|
146
|
+
width: 100%;
|
|
147
|
+
height: var(--footer-height);
|
|
148
|
+
padding: 0 0.75rem;
|
|
149
|
+
border-top: 0.25rem solid var(--background-color-0);
|
|
150
|
+
background-color: var(--background-color-2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.Footer p {
|
|
154
|
+
margin: 0;
|
|
155
|
+
font-size: 0.875em;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.Selector {
|
|
159
|
+
--footer-height: 4rem;
|
|
160
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { ChangeEventHandler, FC, KeyboardEventHandler, useCallback, useEffect, useState } from "react";
|
|
2
|
+
import styles from "./FileExplorer.module.css";
|
|
3
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
4
|
+
import { faArrowUp, faCaretLeft, faCaretRight, faCircleInfo, faCog, faDesktop, faFileLines, faHouse, faImage, faPlus, faSearch, faTrash } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import { QuickAccessButton } from "./QuickAccessButton";
|
|
6
|
+
import { ImportButton } from "./ImportButton";
|
|
7
|
+
import { Actions, ClickAction, CODE_EXTENSIONS, DIALOG_CONTENT_TYPES, DialogBox, DirectoryList, Divider, FileEventHandler, FolderEventHandler, OnSelectionChangeParams, useAlert, useContextMenu, useHistory, useSystemManager, useVirtualRoot, useWindowedModal, useWindowsManager, utilStyles, Vector2, VirtualFile, VirtualFolder, VirtualFolderLink, VirtualRoot, WindowProps } from "@prozilla-os/core";
|
|
8
|
+
import { SELECTOR_MODE } from "../constants/fileExplorer.const";
|
|
9
|
+
import { FileProperties } from "./modals/file-properties/FileProperties";
|
|
10
|
+
|
|
11
|
+
export interface FileExplorerProps extends WindowProps {
|
|
12
|
+
path?: string;
|
|
13
|
+
selectorMode?: number;
|
|
14
|
+
Footer: FC;
|
|
15
|
+
onSelectionChange: (params: OnSelectionChangeParams) => void;
|
|
16
|
+
onSelectionFinish: Function;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function FileExplorer({ app, path: startPath, selectorMode, Footer, onSelectionChange, onSelectionFinish }: FileExplorerProps) {
|
|
20
|
+
const isSelector = (Footer != null && selectorMode != null && selectorMode !== SELECTOR_MODE.NONE);
|
|
21
|
+
|
|
22
|
+
const virtualRoot = useVirtualRoot();
|
|
23
|
+
const windowsManager = useWindowsManager();
|
|
24
|
+
const { windowsConfig } = useSystemManager();
|
|
25
|
+
|
|
26
|
+
const [currentDirectory, setCurrentDirectory] = useState<VirtualFolder>(virtualRoot?.navigate(startPath ?? "~") as VirtualFolder);
|
|
27
|
+
const [path, setPath] = useState<string>(currentDirectory?.path ?? "");
|
|
28
|
+
const [showHidden] = useState(true);
|
|
29
|
+
const { history, stateIndex, pushState, undo, redo, undoAvailable, redoAvailable } = useHistory<string>(currentDirectory.path);
|
|
30
|
+
const { alert } = useAlert();
|
|
31
|
+
|
|
32
|
+
const { openWindowedModal } = useWindowedModal();
|
|
33
|
+
const { onContextMenu: onContextMenuFile } = useContextMenu({ Actions: (props) =>
|
|
34
|
+
<Actions {...props}>
|
|
35
|
+
<ClickAction label={!isSelector ? "Open" : "Select"} onTrigger={(event, file) => {
|
|
36
|
+
if (isSelector) {
|
|
37
|
+
onSelectionChange?.({ files: [(file as VirtualFile).id], directory: currentDirectory });
|
|
38
|
+
onSelectionFinish?.();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (windowsManager != null) (file as VirtualFile).open(windowsManager);
|
|
42
|
+
}}/>
|
|
43
|
+
<ClickAction label="Delete" icon={faTrash} onTrigger={(event, file) => {
|
|
44
|
+
(file as VirtualFile).delete();
|
|
45
|
+
}}/>
|
|
46
|
+
<ClickAction label="Properties" icon={faCircleInfo} onTrigger={(event, file) => {
|
|
47
|
+
openWindowedModal({
|
|
48
|
+
title: `${(file as VirtualFile).id} ${windowsConfig.titleSeparator} Properties`,
|
|
49
|
+
iconUrl: (file as VirtualFile).getIconUrl(),
|
|
50
|
+
size: new Vector2(400, 500),
|
|
51
|
+
Modal: (props: object) => <FileProperties file={file as VirtualFile} {...props}/>
|
|
52
|
+
});
|
|
53
|
+
}}/>
|
|
54
|
+
</Actions>
|
|
55
|
+
});
|
|
56
|
+
const { onContextMenu: onContextMenuFolder } = useContextMenu({ Actions: (props) =>
|
|
57
|
+
<Actions {...props}>
|
|
58
|
+
<ClickAction label="Open" onTrigger={(event, folder) => {
|
|
59
|
+
changeDirectory((folder as VirtualFolderLink).linkedPath ?? (folder as VirtualFolder).name);
|
|
60
|
+
}}/>
|
|
61
|
+
{/* <ClickAction label={`Open in ${APP_NAMES.TERMINAL}`} icon={APP_ICONS.TERMINAL} onTrigger={(event, folder) => {
|
|
62
|
+
windowsManager?.open(APPS.TERMINAL, { startPath: (folder as VirtualFolder).path });
|
|
63
|
+
}}/> */}
|
|
64
|
+
<Divider/>
|
|
65
|
+
<ClickAction label="Delete" icon={faTrash} onTrigger={(event, folder) => {
|
|
66
|
+
(folder as VirtualFolder).delete();
|
|
67
|
+
}}/>
|
|
68
|
+
</Actions>
|
|
69
|
+
});
|
|
70
|
+
// const { onContextMenu: onNew } = useContextMenu({
|
|
71
|
+
// modalsManager,
|
|
72
|
+
// options: {
|
|
73
|
+
// "File": () => { currentDirectory.createFile("New File"); },
|
|
74
|
+
// "Folder": () => { currentDirectory.createFolder("New Folder"); }
|
|
75
|
+
// }
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
const changeDirectory = useCallback((path: string, absolute = false) => {
|
|
79
|
+
if (path == null)
|
|
80
|
+
return;
|
|
81
|
+
|
|
82
|
+
if (currentDirectory == null)
|
|
83
|
+
absolute = true;
|
|
84
|
+
|
|
85
|
+
const directory = absolute ? virtualRoot?.navigate(path) : currentDirectory.navigate(path);
|
|
86
|
+
|
|
87
|
+
if (directory != null) {
|
|
88
|
+
setCurrentDirectory(directory as VirtualFolder);
|
|
89
|
+
setPath(directory.root ? "/" : directory.path);
|
|
90
|
+
pushState(directory.path);
|
|
91
|
+
}
|
|
92
|
+
}, [currentDirectory, pushState, virtualRoot]);
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (history.length === 0)
|
|
96
|
+
return;
|
|
97
|
+
|
|
98
|
+
const path = history[stateIndex];
|
|
99
|
+
const directory = virtualRoot?.navigate(path);
|
|
100
|
+
if (directory != null) {
|
|
101
|
+
setCurrentDirectory(directory as VirtualFolder);
|
|
102
|
+
setPath(directory.root ? "/" : directory.path);
|
|
103
|
+
}
|
|
104
|
+
}, [history, stateIndex, virtualRoot]);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
type Error = { message: string };
|
|
108
|
+
const onError = (error: unknown) => {
|
|
109
|
+
alert({
|
|
110
|
+
title: (error as Error).message,
|
|
111
|
+
text: "You have exceeded the virtual drive capacity. Files and folders will not be saved until more storage is freed.",
|
|
112
|
+
iconUrl: app?.iconUrl as string | undefined,
|
|
113
|
+
size: new Vector2(300, 200),
|
|
114
|
+
single: true,
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
virtualRoot?.on(VirtualRoot.EVENT_NAMES.ERROR, onError);
|
|
119
|
+
|
|
120
|
+
return () => {
|
|
121
|
+
virtualRoot?.off(VirtualRoot.EVENT_NAMES.ERROR, onError);
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
const onPathChange = (event: Event) => {
|
|
126
|
+
setPath((event.target as HTMLInputElement).value);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
130
|
+
let value = (event.target as HTMLInputElement).value;
|
|
131
|
+
|
|
132
|
+
if (event.key === "Enter") {
|
|
133
|
+
if (value === "")
|
|
134
|
+
value = "~";
|
|
135
|
+
|
|
136
|
+
const directory = virtualRoot?.navigate(value);
|
|
137
|
+
|
|
138
|
+
if (directory == null) {
|
|
139
|
+
openWindowedModal({
|
|
140
|
+
title: "Error",
|
|
141
|
+
iconUrl: app?.iconUrl as string | undefined,
|
|
142
|
+
size: new Vector2(300, 150),
|
|
143
|
+
Modal: (props: {}) =>
|
|
144
|
+
<DialogBox {...props}>
|
|
145
|
+
<p>Invalid path: "{value}"</p>
|
|
146
|
+
<button data-type={DIALOG_CONTENT_TYPES.closeButton}>Ok</button>
|
|
147
|
+
</DialogBox>
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setCurrentDirectory(directory as VirtualFolder);
|
|
153
|
+
setPath(directory.root ? "/" : directory.path);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const itemCount = currentDirectory.getItemCount(showHidden);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div className={!isSelector ? styles.FileExplorer : `${styles.FileExplorer} ${styles.Selector}`}>
|
|
161
|
+
<div className={styles.Header}>
|
|
162
|
+
<button
|
|
163
|
+
title="Back"
|
|
164
|
+
tabIndex={0}
|
|
165
|
+
className={styles.IconButton}
|
|
166
|
+
onClick={() => { undo(); }}
|
|
167
|
+
disabled={!undoAvailable}
|
|
168
|
+
>
|
|
169
|
+
<FontAwesomeIcon icon={faCaretLeft}/>
|
|
170
|
+
</button>
|
|
171
|
+
<button
|
|
172
|
+
title="Forward"
|
|
173
|
+
tabIndex={0}
|
|
174
|
+
className={styles.IconButton}
|
|
175
|
+
onClick={() => { redo(); }}
|
|
176
|
+
disabled={!redoAvailable}
|
|
177
|
+
>
|
|
178
|
+
<FontAwesomeIcon icon={faCaretRight}/>
|
|
179
|
+
</button>
|
|
180
|
+
<button
|
|
181
|
+
title="Up"
|
|
182
|
+
tabIndex={0}
|
|
183
|
+
className={styles.IconButton}
|
|
184
|
+
onClick={() => { changeDirectory(".."); }}
|
|
185
|
+
disabled={currentDirectory.isRoot != null && currentDirectory.isRoot}
|
|
186
|
+
>
|
|
187
|
+
<FontAwesomeIcon icon={faArrowUp}/>
|
|
188
|
+
</button>
|
|
189
|
+
<button
|
|
190
|
+
title="New"
|
|
191
|
+
tabIndex={0}
|
|
192
|
+
className={styles.IconButton}
|
|
193
|
+
onClick={() => {
|
|
194
|
+
// openWindowedModal({
|
|
195
|
+
// title: "Error",
|
|
196
|
+
// iconUrl: AppsManager.getAppIconUrl(APPS.FILE_EXPLORER),
|
|
197
|
+
// size: new Vector2(300, 150),
|
|
198
|
+
// Modal: (props) =>
|
|
199
|
+
// <DialogBox {...props}>
|
|
200
|
+
// <p>This folder is protected.</p>
|
|
201
|
+
// <button data-type={DIALOG_CONTENT_TYPES.CloseButton}>Ok</button>
|
|
202
|
+
// </DialogBox>
|
|
203
|
+
// });
|
|
204
|
+
|
|
205
|
+
// if (currentDirectory.canBeEdited) {
|
|
206
|
+
// onNew(event);
|
|
207
|
+
// } else {
|
|
208
|
+
|
|
209
|
+
// }
|
|
210
|
+
}}
|
|
211
|
+
disabled={!currentDirectory.canBeEdited}
|
|
212
|
+
>
|
|
213
|
+
<FontAwesomeIcon icon={faPlus}/>
|
|
214
|
+
</button>
|
|
215
|
+
<input
|
|
216
|
+
value={path}
|
|
217
|
+
type="text"
|
|
218
|
+
aria-label="Path"
|
|
219
|
+
className={styles.PathInput}
|
|
220
|
+
tabIndex={0}
|
|
221
|
+
onChange={onPathChange as unknown as ChangeEventHandler}
|
|
222
|
+
onKeyDown={onKeyDown as unknown as KeyboardEventHandler}
|
|
223
|
+
placeholder="Enter a path..."
|
|
224
|
+
/>
|
|
225
|
+
<ImportButton directory={currentDirectory}/>
|
|
226
|
+
<button title="Search" tabIndex={0} className={styles.IconButton}>
|
|
227
|
+
<FontAwesomeIcon icon={faSearch}/>
|
|
228
|
+
</button>
|
|
229
|
+
<button title="Settings" tabIndex={0} className={styles.IconButton}>
|
|
230
|
+
<FontAwesomeIcon icon={faCog}/>
|
|
231
|
+
</button>
|
|
232
|
+
</div>
|
|
233
|
+
<div className={styles.Body}>
|
|
234
|
+
<div className={styles.Sidebar}>
|
|
235
|
+
<QuickAccessButton name={"Home"} onClick={() => { changeDirectory("~"); }} icon={faHouse}/>
|
|
236
|
+
<QuickAccessButton name={"Desktop"} onClick={() => { changeDirectory("~/Desktop"); }} icon={faDesktop}/>
|
|
237
|
+
<QuickAccessButton name={"Images"} onClick={() => { changeDirectory("~/Pictures"); }} icon={faImage}/>
|
|
238
|
+
<QuickAccessButton name={"Documents"} onClick={() => { changeDirectory("~/Documents"); }} icon={faFileLines}/>
|
|
239
|
+
</div>
|
|
240
|
+
<DirectoryList
|
|
241
|
+
directory={currentDirectory}
|
|
242
|
+
id="main"
|
|
243
|
+
className={styles.Main}
|
|
244
|
+
showHidden={showHidden}
|
|
245
|
+
onOpenFile={(event, file) => {
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
if (isSelector)
|
|
248
|
+
return void onSelectionFinish?.();
|
|
249
|
+
const options: Record<string, string> = {};
|
|
250
|
+
if (file.extension === "md" || (file.extension != null && CODE_EXTENSIONS.includes(file.extension)))
|
|
251
|
+
options.mode = "view";
|
|
252
|
+
windowsManager?.openFile(file, options);
|
|
253
|
+
}}
|
|
254
|
+
onOpenFolder={(event, folder) => {
|
|
255
|
+
changeDirectory((folder as VirtualFolderLink).linkedPath ?? folder.name);
|
|
256
|
+
}}
|
|
257
|
+
onContextMenuFile={onContextMenuFile as unknown as FileEventHandler}
|
|
258
|
+
onContextMenuFolder={onContextMenuFolder as unknown as FolderEventHandler}
|
|
259
|
+
allowMultiSelect={selectorMode !== SELECTOR_MODE.SINGLE}
|
|
260
|
+
onSelectionChange={onSelectionChange}
|
|
261
|
+
/>
|
|
262
|
+
</div>
|
|
263
|
+
{!isSelector
|
|
264
|
+
? <span className={styles.Footer}>
|
|
265
|
+
<p className={utilStyles.TextLight}>
|
|
266
|
+
{itemCount === 1
|
|
267
|
+
? itemCount + " item"
|
|
268
|
+
: itemCount + " items"
|
|
269
|
+
}
|
|
270
|
+
</p>
|
|
271
|
+
</span>
|
|
272
|
+
: <div className={styles.Footer}>
|
|
273
|
+
<Footer/>
|
|
274
|
+
</div>
|
|
275
|
+
}
|
|
276
|
+
</div>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FormEventHandler, ReactElement } from "react";
|
|
2
|
+
import styles from "./FileExplorer.module.css";
|
|
3
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
4
|
+
import { faDownload } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import { VirtualFolder, VirtualFile } from "@prozilla-os/core";
|
|
6
|
+
|
|
7
|
+
interface ImportButtonProps {
|
|
8
|
+
directory: VirtualFolder;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ImportButton({ directory }: ImportButtonProps): ReactElement {
|
|
12
|
+
const onChange = (event: InputEvent) => {
|
|
13
|
+
const files = (event.target as HTMLInputElement).files;
|
|
14
|
+
|
|
15
|
+
if (files == null)
|
|
16
|
+
return;
|
|
17
|
+
|
|
18
|
+
Array.from(files).forEach((file: File) => {
|
|
19
|
+
const { name, extension } = VirtualFile.splitId(file.name);
|
|
20
|
+
|
|
21
|
+
const reader = new FileReader();
|
|
22
|
+
reader.onload = (event: Event) => {
|
|
23
|
+
const { result } = event.target as FileReader;
|
|
24
|
+
|
|
25
|
+
// Create a file with the same name and extension, with a base64 string as a source
|
|
26
|
+
directory.createFile(name, extension as string | undefined, (virtualFile) => {
|
|
27
|
+
virtualFile.setSource(result as string);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
reader.readAsDataURL(file);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return <label title="Import" tabIndex={0} className={styles.IconButton}>
|
|
35
|
+
<input
|
|
36
|
+
type="file"
|
|
37
|
+
id="import"
|
|
38
|
+
multiple
|
|
39
|
+
style={{ display: "none" }}
|
|
40
|
+
onChange={onChange as unknown as FormEventHandler}
|
|
41
|
+
/>
|
|
42
|
+
<FontAwesomeIcon icon={faDownload}/>
|
|
43
|
+
</label>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FontAwesomeIcon, FontAwesomeIconProps } from "@fortawesome/react-fontawesome";
|
|
2
|
+
import styles from "./FileExplorer.module.css";
|
|
3
|
+
import { MouseEventHandler } from "react";
|
|
4
|
+
import { utilStyles } from "@prozilla-os/core";
|
|
5
|
+
|
|
6
|
+
interface QuickAcessButton {
|
|
7
|
+
onClick: MouseEventHandler;
|
|
8
|
+
icon: FontAwesomeIconProps["icon"];
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function QuickAccessButton({ onClick, icon, name }: QuickAcessButton) {
|
|
13
|
+
return (
|
|
14
|
+
<button
|
|
15
|
+
tabIndex={0}
|
|
16
|
+
className={`${styles.NavButton} ${utilStyles.TextSemibold}`}
|
|
17
|
+
onClick={onClick}
|
|
18
|
+
>
|
|
19
|
+
<FontAwesomeIcon icon={icon}/>
|
|
20
|
+
{name}
|
|
21
|
+
</button>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
.FileProperties {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
justify-content: flex-start;
|
|
5
|
+
align-items: flex-start;
|
|
6
|
+
padding: 1rem;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.Icon {
|
|
10
|
+
width: 3rem;
|
|
11
|
+
height: 3rem;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.Icon div {
|
|
15
|
+
width: inherit;
|
|
16
|
+
height: inherit;
|
|
17
|
+
object-fit: contain;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.Icon svg {
|
|
21
|
+
max-width: 100%;
|
|
22
|
+
max-height: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.Section {
|
|
26
|
+
--divider-width: 0.25rem;
|
|
27
|
+
|
|
28
|
+
position: relative;
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: 0.25rem;
|
|
31
|
+
justify-content: flex-start;
|
|
32
|
+
align-items: flex-start;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
width: 100%;
|
|
35
|
+
padding: 1rem 0;
|
|
36
|
+
padding-bottom: calc(1rem + var(--divider-width));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.Section:first-child {
|
|
40
|
+
gap: 0.5rem;
|
|
41
|
+
align-items: center;
|
|
42
|
+
flex-direction: row;
|
|
43
|
+
padding-top: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.Section:first-child .Line {
|
|
47
|
+
font-size: 1.25rem;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.Section:not(:last-child)::after {
|
|
51
|
+
content: "";
|
|
52
|
+
position: absolute;
|
|
53
|
+
bottom: 0;
|
|
54
|
+
left: 0;
|
|
55
|
+
width: 100%;
|
|
56
|
+
height: var(--divider-width);
|
|
57
|
+
border-radius: var(--border-radius-0);
|
|
58
|
+
background-color: var(--background-color-0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.Line {
|
|
62
|
+
margin: 0;
|
|
63
|
+
text-align: left;
|
|
64
|
+
padding-left: 2rem;
|
|
65
|
+
text-indent: -2rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.AppIcon {
|
|
69
|
+
display: inline-block;
|
|
70
|
+
width: 2rem;
|
|
71
|
+
height: 2rem;
|
|
72
|
+
vertical-align: middle;
|
|
73
|
+
margin-left: 0.5rem;
|
|
74
|
+
margin-right: 0.25rem;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.AppIcon div {
|
|
78
|
+
position: relative;
|
|
79
|
+
width: inherit;
|
|
80
|
+
height: inherit;
|
|
81
|
+
object-fit: contain;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.AppIcon svg {
|
|
85
|
+
position: absolute;
|
|
86
|
+
top: 0;
|
|
87
|
+
left: 0;
|
|
88
|
+
max-width: 100%;
|
|
89
|
+
max-height: 100%;
|
|
90
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import styles from "./FileProperties.module.css";
|
|
2
|
+
import { ImagePreview, ModalProps, StorageManager, useSystemManager, utilStyles, VirtualFile, WindowedModal } from "@prozilla-os/core";
|
|
3
|
+
|
|
4
|
+
interface FilePropetiesProps extends ModalProps {
|
|
5
|
+
file: VirtualFile;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function FileProperties({ modal, params, file, ...props }: FilePropetiesProps) {
|
|
9
|
+
const { appsConfig } = useSystemManager();
|
|
10
|
+
const associatedApp = file.extension != null ? appsConfig.getAppByFileExtension(file.extension) : null;
|
|
11
|
+
|
|
12
|
+
return <WindowedModal className={styles.FileProperties} modal={modal} params={params} {...props}>
|
|
13
|
+
<span className={styles.Section}>
|
|
14
|
+
<ImagePreview className={styles.Icon} source={file.getIconUrl()}/>
|
|
15
|
+
<p className={`${styles.Line} ${utilStyles.TextBold}`}>{file.id}</p>
|
|
16
|
+
</span>
|
|
17
|
+
<span className={styles.Section}>
|
|
18
|
+
<p className={styles.Line}>Type: {file.getType()}</p>
|
|
19
|
+
{associatedApp != null &&
|
|
20
|
+
<span className={styles.Line}>
|
|
21
|
+
Opens with:
|
|
22
|
+
<ImagePreview className={styles.AppIcon} source={associatedApp.iconUrl ?? ""}/>
|
|
23
|
+
{associatedApp.name}
|
|
24
|
+
</span>
|
|
25
|
+
}
|
|
26
|
+
</span>
|
|
27
|
+
<span className={styles.Section}>
|
|
28
|
+
<p className={styles.Line}>Location: {file.path}</p>
|
|
29
|
+
<p className={styles.Line}>Size: {StorageManager.getByteSize(file.source ?? file.content as string | null)} bytes</p>
|
|
30
|
+
<p className={styles.Line}>Size on drive: {StorageManager.getByteSize(file.toString())} bytes</p>
|
|
31
|
+
</span>
|
|
32
|
+
<span className={styles.Section}>
|
|
33
|
+
<p className={styles.Line}>Attributes: {file.isProtected ? "Protected" : "N/A"}</p>
|
|
34
|
+
</span>
|
|
35
|
+
</WindowedModal>;
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App } from "@prozilla-os/core";
|
|
2
|
+
import { FileExplorer } from "./components/FileExplorer";
|
|
3
|
+
import { VirtualBase } from "@prozilla-os/core/src/features/virtual-drive/virtualBase";
|
|
4
|
+
|
|
5
|
+
const fileExplorer = new App("File Explorer", "file-explorer", FileExplorer)
|
|
6
|
+
.setIconUrl("https://os.prozilla.dev/assets/apps/icons/file-explorer.svg");
|
|
7
|
+
|
|
8
|
+
export { fileExplorer };
|
|
9
|
+
export { FileSelectorMode } from "./types/index.d";
|
|
10
|
+
VirtualBase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|