@prozilla-os/core 1.0.7
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 +43 -0
- package/src/components/_utils/button/Button.module.css +25 -0
- package/src/components/_utils/button/Button.tsx +48 -0
- package/src/components/_utils/directory-list/DirectoryList.module.css +70 -0
- package/src/components/_utils/directory-list/DirectoryList.tsx +203 -0
- package/src/components/_utils/directory-list/ImagePreview.module.css +19 -0
- package/src/components/_utils/directory-list/ImagePreview.tsx +33 -0
- package/src/components/_utils/dropdown-button/DropdownButton.module.css +60 -0
- package/src/components/_utils/dropdown-button/DropdownButton.tsx +40 -0
- package/src/components/_utils/header-menu/HeaderMenu.module.css +8 -0
- package/src/components/_utils/header-menu/HeaderMenu.tsx +15 -0
- package/src/components/_utils/index.ts +10 -0
- package/src/components/_utils/interactable/Interactable.tsx +42 -0
- package/src/components/_utils/progress-bar/ProgressBar.module.css +20 -0
- package/src/components/_utils/progress-bar/ProgressBar.tsx +22 -0
- package/src/components/_utils/web-view/WebView.module.css +15 -0
- package/src/components/_utils/web-view/WebView.tsx +47 -0
- package/src/components/actions/Actions.module.css +281 -0
- package/src/components/actions/Actions.tsx +108 -0
- package/src/components/actions/actions/ClickAction.tsx +30 -0
- package/src/components/actions/actions/Divider.tsx +5 -0
- package/src/components/actions/actions/DropdownAction.tsx +50 -0
- package/src/components/actions/actions/RadioAction.tsx +50 -0
- package/src/components/actions/actions/TextDisplay.tsx +12 -0
- package/src/components/actions/actions/ToggleAction.tsx +31 -0
- package/src/components/actions/index.ts +7 -0
- package/src/components/desktop/Desktop.module.css +49 -0
- package/src/components/desktop/Desktop.tsx +199 -0
- package/src/components/index.ts +10 -0
- package/src/components/modals/ModalView.module.css +14 -0
- package/src/components/modals/ModalView.tsx +54 -0
- package/src/components/modals/ModalsView.module.css +4 -0
- package/src/components/modals/ModalsView.tsx +32 -0
- package/src/components/modals/_utils/WindowedModal.module.css +92 -0
- package/src/components/modals/_utils/WindowedModal.tsx +71 -0
- package/src/components/modals/dialog-box/DialogBox.module.css +27 -0
- package/src/components/modals/dialog-box/DialogBox.tsx +26 -0
- package/src/components/modals/file-selector/FileSelector.module.css +25 -0
- package/src/components/modals/file-selector/FileSelector.tsx +77 -0
- package/src/components/modals/index.ts +7 -0
- package/src/components/modals/share/Option.tsx +23 -0
- package/src/components/modals/share/Share.module.css +153 -0
- package/src/components/modals/share/Share.tsx +197 -0
- package/src/components/prozilla-os/ProzillaOS.module.css +14 -0
- package/src/components/prozilla-os/ProzillaOS.tsx +76 -0
- package/src/components/taskbar/Taskbar.module.css +218 -0
- package/src/components/taskbar/Taskbar.tsx +193 -0
- package/src/components/taskbar/app-icon/AppIcon.module.css +62 -0
- package/src/components/taskbar/app-icon/AppIcon.tsx +76 -0
- package/src/components/taskbar/indicators/Battery.module.css +32 -0
- package/src/components/taskbar/indicators/Battery.tsx +114 -0
- package/src/components/taskbar/indicators/Calendar.module.css +24 -0
- package/src/components/taskbar/indicators/Calendar.tsx +67 -0
- package/src/components/taskbar/indicators/Network.module.css +17 -0
- package/src/components/taskbar/indicators/Network.tsx +38 -0
- package/src/components/taskbar/indicators/Volume.module.css +17 -0
- package/src/components/taskbar/indicators/Volume.tsx +38 -0
- package/src/components/taskbar/indicators/index.ts +4 -0
- package/src/components/taskbar/menus/AppList.module.css +33 -0
- package/src/components/taskbar/menus/HomeMenu.module.css +47 -0
- package/src/components/taskbar/menus/HomeMenu.tsx +118 -0
- package/src/components/taskbar/menus/SearchMenu.module.css +68 -0
- package/src/components/taskbar/menus/SearchMenu.tsx +100 -0
- package/src/components/taskbar/menus/UtilMenu.module.css +41 -0
- package/src/components/taskbar/menus/UtilMenu.tsx +23 -0
- package/src/components/windows/WindowFallbackView.tsx +38 -0
- package/src/components/windows/WindowView.module.css +152 -0
- package/src/components/windows/WindowView.tsx +233 -0
- package/src/components/windows/WindowsView.tsx +89 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/modals.const.ts +3 -0
- package/src/constants/themes.const.ts +8 -0
- package/src/constants/utils.const.ts +19 -0
- package/src/constants/virtualDrive.const.ts +20 -0
- package/src/features/_utils/array.utils.ts +14 -0
- package/src/features/_utils/browser.utils.ts +111 -0
- package/src/features/_utils/date.utils.ts +90 -0
- package/src/features/_utils/event.utils.ts +39 -0
- package/src/features/_utils/index.ts +8 -0
- package/src/features/_utils/math.utils.ts +18 -0
- package/src/features/_utils/number.utils.ts +3 -0
- package/src/features/_utils/string.utils.ts +31 -0
- package/src/features/_utils/time.utils.ts +13 -0
- package/src/features/actions/actionsManager.ts +7 -0
- package/src/features/index.ts +12 -0
- package/src/features/math/vector2.ts +75 -0
- package/src/features/modals/modal.ts +74 -0
- package/src/features/modals/modalsManager.ts +72 -0
- package/src/features/settings/settings.ts +109 -0
- package/src/features/settings/settingsManager.ts +31 -0
- package/src/features/storage/storageManager.ts +35 -0
- package/src/features/system/configs/app.tsx +60 -0
- package/src/features/system/configs/appsConfig.ts +60 -0
- package/src/features/system/configs/desktopConfig.ts +46 -0
- package/src/features/system/configs/index.ts +9 -0
- package/src/features/system/configs/miscConfig.ts +19 -0
- package/src/features/system/configs/modalsConfig.ts +28 -0
- package/src/features/system/configs/taskbarConfig.ts +19 -0
- package/src/features/system/configs/trackingConfig.ts +24 -0
- package/src/features/system/configs/virtualDriveConfig.ts +39 -0
- package/src/features/system/configs/windowsConfig.ts +34 -0
- package/src/features/system/systemManager.ts +68 -0
- package/src/features/tracking/trackingManager.ts +40 -0
- package/src/features/virtual-drive/file/index.ts +2 -0
- package/src/features/virtual-drive/file/virtualFile.ts +197 -0
- package/src/features/virtual-drive/file/virtualFileLink.ts +111 -0
- package/src/features/virtual-drive/folder/index.ts +2 -0
- package/src/features/virtual-drive/folder/virtualFolder.ts +388 -0
- package/src/features/virtual-drive/folder/virtualFolderLink.ts +148 -0
- package/src/features/virtual-drive/index.ts +3 -0
- package/src/features/virtual-drive/root/defaultData.ts +140 -0
- package/src/features/virtual-drive/root/virtualRoot.ts +244 -0
- package/src/features/virtual-drive/virtualBase.ts +191 -0
- package/src/features/windows/windowsManager.ts +244 -0
- package/src/features/z-index/zIndexGroup.ts +40 -0
- package/src/features/z-index/zIndexManager.ts +46 -0
- package/src/hooks/_utils/history.ts +50 -0
- package/src/hooks/_utils/index.ts +6 -0
- package/src/hooks/_utils/keyboard.ts +111 -0
- package/src/hooks/_utils/mouse.ts +32 -0
- package/src/hooks/_utils/outsideClick.tsx +33 -0
- package/src/hooks/_utils/screen.ts +61 -0
- package/src/hooks/_utils/scrollWithShadows.ts +138 -0
- package/src/hooks/apps/appFolder.ts +30 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/modals/alert.tsx +34 -0
- package/src/hooks/modals/contextMenu.tsx +47 -0
- package/src/hooks/modals/index.ts +4 -0
- package/src/hooks/modals/modalsContext.ts +10 -0
- package/src/hooks/modals/modalsManagerContext.ts +10 -0
- package/src/hooks/modals/modalsManagerProvider.tsx +16 -0
- package/src/hooks/modals/modalsProvider.tsx +20 -0
- package/src/hooks/modals/windowedModal.ts +47 -0
- package/src/hooks/settings/settingsManagerContext.ts +10 -0
- package/src/hooks/settings/settingsManagerProvider.tsx +16 -0
- package/src/hooks/system/systemManagerContext.ts +8 -0
- package/src/hooks/system/systemManagerProvider.tsx +26 -0
- package/src/hooks/themes/themes.tsx +22 -0
- package/src/hooks/tracking/trackingManagerContext.ts +10 -0
- package/src/hooks/tracking/trackingManagerProvider.tsx +13 -0
- package/src/hooks/virtual-drive/virtualRootContext.ts +10 -0
- package/src/hooks/virtual-drive/virtualRootProvider.tsx +13 -0
- package/src/hooks/windows/windowsContext.ts +10 -0
- package/src/hooks/windows/windowsManagerContext.ts +10 -0
- package/src/hooks/windows/windowsManagerProvider.tsx +24 -0
- package/src/hooks/windows/windowsProvider.tsx +20 -0
- package/src/hooks/z-index/zIndex.ts +32 -0
- package/src/hooks/z-index/zIndexManagerContext.ts +10 -0
- package/src/hooks/z-index/zIndexManagerProvider.tsx +11 -0
- package/src/index.ts +5 -0
- package/src/styles/global/fonts.css +18 -0
- package/src/styles/global/scrollbar.css +29 -0
- package/src/styles/global/themes.css +67 -0
- package/src/styles/global/variables.css +92 -0
- package/src/styles/global.css +65 -0
- package/src/styles/index.ts +3 -0
- package/src/styles/utils.module.css +22 -0
- package/src/types/util.d.ts +3 -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/core
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prozilla-os/core",
|
|
3
|
+
"version": "1.0.7",
|
|
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/core"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@fortawesome/fontawesome-svg-core": "^6.5.2",
|
|
19
|
+
"@fortawesome/free-regular-svg-icons": "^6.5.2",
|
|
20
|
+
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
|
21
|
+
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
22
|
+
"react": "^18.3.1",
|
|
23
|
+
"react-draggable": "^4.4.6",
|
|
24
|
+
"react-error-boundary": "^4.0.13",
|
|
25
|
+
"react-ga4": "^2.1.0",
|
|
26
|
+
"react-svg": "^16.1.34",
|
|
27
|
+
"@prozilla-os/file-explorer": "1.0.4"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.14.5",
|
|
31
|
+
"typescript": "^5.4.5"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src/**/*"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"registry": "https://registry.npmjs.org/",
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "tsc --watch"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.Button {
|
|
2
|
+
--text-color: var(--foreground-color-0);
|
|
3
|
+
--normal-color: var(--background-color-0);
|
|
4
|
+
--hover-color: var(--background-color-1);
|
|
5
|
+
|
|
6
|
+
color: var(--text-color);
|
|
7
|
+
background-color: var(--normal-color);
|
|
8
|
+
border: none;
|
|
9
|
+
outline: none;
|
|
10
|
+
font-size: 0.875em;
|
|
11
|
+
transition: background-color 100ms ease-in-out;
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.Button:hover, .Button:focus-visible {
|
|
16
|
+
background-color: var(--hover-color);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ButtonLink {
|
|
20
|
+
text-decoration: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.Button > svg {
|
|
24
|
+
margin-left: 0.5rem;
|
|
25
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
2
|
+
import styles from "./Button.module.css";
|
|
3
|
+
import { faExternalLink } from "@fortawesome/free-solid-svg-icons";
|
|
4
|
+
import { HTMLAttributeAnchorTarget, ReactNode } from "react";
|
|
5
|
+
import { IconProp } from "@fortawesome/fontawesome-svg-core";
|
|
6
|
+
|
|
7
|
+
interface ButtonProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
href?: string;
|
|
10
|
+
icon?: IconProp;
|
|
11
|
+
target?: HTMLAttributeAnchorTarget;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function Button({ className, href, children, icon, target, ...props }: ButtonProps) {
|
|
17
|
+
const classNames = [styles.Button];
|
|
18
|
+
if (className != null)
|
|
19
|
+
classNames.push(className);
|
|
20
|
+
|
|
21
|
+
if (href != null) {
|
|
22
|
+
classNames.push(styles.ButtonLink);
|
|
23
|
+
|
|
24
|
+
return (<a
|
|
25
|
+
{...props}
|
|
26
|
+
href={href}
|
|
27
|
+
target={target ?? "_blank"}
|
|
28
|
+
rel="noreferrer"
|
|
29
|
+
tabIndex={0}
|
|
30
|
+
className={classNames.join(" ")}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
<FontAwesomeIcon icon={icon ?? faExternalLink}/>
|
|
34
|
+
</a>);
|
|
35
|
+
} else {
|
|
36
|
+
return (<button
|
|
37
|
+
{...props}
|
|
38
|
+
tabIndex={0}
|
|
39
|
+
className={classNames.join(" ")}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
{icon != null
|
|
43
|
+
? <FontAwesomeIcon icon={icon}/>
|
|
44
|
+
: null
|
|
45
|
+
}
|
|
46
|
+
</button>);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.DirectoryList {
|
|
2
|
+
--scale: 1rem;
|
|
3
|
+
|
|
4
|
+
position: relative;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.FileButton, .FolderButton {
|
|
10
|
+
--gap: 0.25rem;
|
|
11
|
+
|
|
12
|
+
display: flex;
|
|
13
|
+
gap: var(--gap);
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
width: calc(var(--scale) * 7.5);
|
|
18
|
+
height: calc(var(--scale) * 7.5);
|
|
19
|
+
padding: 0.5rem;
|
|
20
|
+
background: none;
|
|
21
|
+
border: none;
|
|
22
|
+
border-radius: var(--border-radius-1);
|
|
23
|
+
outline: none;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
transition: background-color 100ms ease-in-out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.FileButton[data-selected=true],
|
|
29
|
+
.FolderButton[data-selected=true] {
|
|
30
|
+
background-color: color-mix(in srgb, var(--background-color-0) 40%, transparent) !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.FileButton:hover,
|
|
34
|
+
.FolderButton:hover,
|
|
35
|
+
.FileButton:focus-visible,
|
|
36
|
+
.FolderButton:focus-visible {
|
|
37
|
+
background-color: color-mix(in srgb, var(--background-color-0) 20%, transparent);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.FileButton p, .FolderButton p {
|
|
41
|
+
max-width: 100%;
|
|
42
|
+
margin: 0;
|
|
43
|
+
word-wrap: break-word;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.FileIcon, .FolderIcon {
|
|
47
|
+
max-height: calc(100% - 1rem - var(--gap));
|
|
48
|
+
border-radius: inherit;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.FileIcon div, .FolderIcon div {
|
|
52
|
+
width: 100%;
|
|
53
|
+
height: 100%;
|
|
54
|
+
border-radius: inherit;
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.FileIcon svg, .FolderIcon svg {
|
|
59
|
+
width: 50%;
|
|
60
|
+
height: auto;
|
|
61
|
+
aspect-ratio: 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.SelectionRect {
|
|
65
|
+
opacity: 25%;
|
|
66
|
+
position: absolute;
|
|
67
|
+
border-radius: var(--border-radius-0);
|
|
68
|
+
background-color: var(--blue-1);
|
|
69
|
+
border: 0.25rem solid var(--blue-0);
|
|
70
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { MouseEventHandler, ReactElement, useEffect, useRef, useState } from "react";
|
|
2
|
+
import styles from "./DirectoryList.module.css";
|
|
3
|
+
import { ImagePreview } from "./ImagePreview";
|
|
4
|
+
import { VirtualFile } from "../../../features/virtual-drive/file";
|
|
5
|
+
import { VirtualFolder } from "../../../features/virtual-drive/folder";
|
|
6
|
+
import { Vector2 } from "../../../features";
|
|
7
|
+
import { Interactable } from "../interactable/Interactable";
|
|
8
|
+
|
|
9
|
+
export interface OnSelectionChangeParams {
|
|
10
|
+
files?: string[];
|
|
11
|
+
folders?: string[];
|
|
12
|
+
directory?: VirtualFolder;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type FileEventHandler = (event: Event, file: VirtualFile) => void;
|
|
16
|
+
export type FolderEventHandler = (event: Event, folder: VirtualFolder) => void;
|
|
17
|
+
|
|
18
|
+
interface DirectoryListProps {
|
|
19
|
+
directory: VirtualFolder;
|
|
20
|
+
showHidden?: boolean;
|
|
21
|
+
folderClassName?: string;
|
|
22
|
+
fileClassName?: string;
|
|
23
|
+
className?: string;
|
|
24
|
+
onContextMenuFile?: FileEventHandler;
|
|
25
|
+
onContextMenuFolder?: FolderEventHandler;
|
|
26
|
+
onOpenFile?: FileEventHandler;
|
|
27
|
+
onOpenFolder?: FolderEventHandler;
|
|
28
|
+
allowMultiSelect?: boolean;
|
|
29
|
+
onSelectionChange?: (params: OnSelectionChangeParams) => void;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function DirectoryList({ directory, showHidden = false, folderClassName, fileClassName, className,
|
|
34
|
+
onContextMenuFile, onContextMenuFolder, onOpenFile, onOpenFolder, allowMultiSelect = true, onSelectionChange, ...props }: DirectoryListProps): ReactElement | null {
|
|
35
|
+
const [selectedFolders, setSelectedFolders] = useState<string[]>([]);
|
|
36
|
+
const [selectedFiles, setSelectedFiles] = useState<string[]>([]);
|
|
37
|
+
|
|
38
|
+
const ref = useRef(null);
|
|
39
|
+
const [rectSelectStart, setRectSelectStart] = useState<Vector2 | null>(null);
|
|
40
|
+
const [rectSelectEnd, setRectSelectEnd] = useState<Vector2 | null>(null);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
onSelectionChange?.({ files: selectedFiles, folders: selectedFolders, directory });
|
|
44
|
+
}, [directory, onSelectionChange, selectedFiles, selectedFolders]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
clearSelection();
|
|
48
|
+
}, [directory]);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const onMoveRectSelect = (event: MouseEvent) => {
|
|
52
|
+
if (rectSelectStart == null)
|
|
53
|
+
return;
|
|
54
|
+
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
setRectSelectEnd({ x: event.clientX, y: event.clientY } as Vector2);
|
|
57
|
+
};
|
|
58
|
+
const onStopRectSelect = (event: MouseEvent) => {
|
|
59
|
+
if (rectSelectStart == null || rectSelectEnd == null) {
|
|
60
|
+
setRectSelectStart(null);
|
|
61
|
+
setRectSelectEnd(null);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
setRectSelectStart(null);
|
|
67
|
+
setRectSelectEnd(null);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
document.addEventListener("mousemove", onMoveRectSelect);
|
|
71
|
+
document.addEventListener("mouseup", onStopRectSelect);
|
|
72
|
+
|
|
73
|
+
return () => {
|
|
74
|
+
document.removeEventListener("mousemove", onMoveRectSelect);
|
|
75
|
+
document.removeEventListener("mouseup", onStopRectSelect);
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (!directory)
|
|
80
|
+
return null;
|
|
81
|
+
|
|
82
|
+
const clearSelection = () => {
|
|
83
|
+
setSelectedFolders([]);
|
|
84
|
+
setSelectedFiles([]);
|
|
85
|
+
};
|
|
86
|
+
const selectFolder = (folder: VirtualFolder, exclusive = false) => {
|
|
87
|
+
if (!allowMultiSelect)
|
|
88
|
+
exclusive = true;
|
|
89
|
+
setSelectedFolders(exclusive ? [folder.id] : [...selectedFolders, folder.id]);
|
|
90
|
+
if (exclusive)
|
|
91
|
+
setSelectedFiles([]);
|
|
92
|
+
};
|
|
93
|
+
const selectFile = (file: VirtualFile, exclusive = false) => {
|
|
94
|
+
if (!allowMultiSelect)
|
|
95
|
+
exclusive = true;
|
|
96
|
+
setSelectedFiles(exclusive ? [file.id] : [...selectedFiles, file.id]);
|
|
97
|
+
if (exclusive)
|
|
98
|
+
setSelectedFolders([]);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const onStartRectSelect = (event: MouseEvent) => {
|
|
102
|
+
setRectSelectStart({ x: event.clientX, y: event.clientY } as Vector2);
|
|
103
|
+
};
|
|
104
|
+
const getRectSelectStyle = () => {
|
|
105
|
+
let x: number, y: number, width: number, height: number = 0;
|
|
106
|
+
|
|
107
|
+
if (ref.current == null || rectSelectStart == null || rectSelectEnd == null)
|
|
108
|
+
return { top: 0, left: 0, width: 0, height: 0 };
|
|
109
|
+
|
|
110
|
+
const containerRect = (ref.current as HTMLElement).getBoundingClientRect();
|
|
111
|
+
|
|
112
|
+
if (rectSelectStart.x < rectSelectEnd.x) {
|
|
113
|
+
x = rectSelectStart.x;
|
|
114
|
+
width = rectSelectEnd.x - rectSelectStart.x;
|
|
115
|
+
} else {
|
|
116
|
+
x = rectSelectEnd.x;
|
|
117
|
+
width = rectSelectStart.x - rectSelectEnd.x;
|
|
118
|
+
}
|
|
119
|
+
if (rectSelectStart.y < rectSelectEnd.y) {
|
|
120
|
+
y = rectSelectStart.y;
|
|
121
|
+
height = rectSelectEnd.y - rectSelectStart.y;
|
|
122
|
+
} else {
|
|
123
|
+
y = rectSelectEnd.y;
|
|
124
|
+
height = rectSelectStart.y - rectSelectEnd.y;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (containerRect) {
|
|
128
|
+
x -= containerRect.x;
|
|
129
|
+
y -= containerRect.y;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
return { top: y, left: x, width, height };
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const classNames = [styles.DirectoryList];
|
|
137
|
+
const folderClassNames = [styles.FolderButton];
|
|
138
|
+
const fileClassNames = [styles.FileButton];
|
|
139
|
+
|
|
140
|
+
if (className)
|
|
141
|
+
classNames.push(className);
|
|
142
|
+
if (folderClassName)
|
|
143
|
+
folderClassNames.push(folderClassName);
|
|
144
|
+
if (fileClassName)
|
|
145
|
+
fileClassNames.push(fileClassName);
|
|
146
|
+
|
|
147
|
+
return <div
|
|
148
|
+
ref={ref}
|
|
149
|
+
className={classNames.join(" ")}
|
|
150
|
+
onClick={clearSelection}
|
|
151
|
+
onMouseDown={onStartRectSelect as unknown as MouseEventHandler}
|
|
152
|
+
{...props}
|
|
153
|
+
>
|
|
154
|
+
{rectSelectStart != null && rectSelectEnd != null
|
|
155
|
+
? <div className={styles.SelectionRect} style={getRectSelectStyle()}/>
|
|
156
|
+
: null
|
|
157
|
+
}
|
|
158
|
+
{directory?.getSubFolders(showHidden)?.map((folder) =>
|
|
159
|
+
<Interactable
|
|
160
|
+
key={folder.id}
|
|
161
|
+
tabIndex={0}
|
|
162
|
+
className={folderClassNames.join(" ")}
|
|
163
|
+
data-selected={selectedFolders.includes(folder.id)}
|
|
164
|
+
onContextMenu={(event: MouseEvent) => {
|
|
165
|
+
onContextMenuFolder?.(event, folder);
|
|
166
|
+
}}
|
|
167
|
+
onClick={(event: MouseEvent) => {
|
|
168
|
+
selectFolder(folder, !event.ctrlKey);
|
|
169
|
+
}}
|
|
170
|
+
onDoubleClick={(event: MouseEvent) => {
|
|
171
|
+
onOpenFolder?.(event, folder);
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
<div className={styles.FolderIcon}>
|
|
175
|
+
<ImagePreview source={folder.getIconUrl()} onError={() => { folder.setIconUrl(null); }}/>
|
|
176
|
+
</div>
|
|
177
|
+
<p>{folder.name}</p>
|
|
178
|
+
</Interactable>
|
|
179
|
+
)}
|
|
180
|
+
{directory?.getFiles(showHidden)?.map((file) =>
|
|
181
|
+
<Interactable
|
|
182
|
+
key={file.id}
|
|
183
|
+
tabIndex={0}
|
|
184
|
+
className={fileClassNames.join(" ")}
|
|
185
|
+
data-selected={selectedFiles.includes(file.id)}
|
|
186
|
+
onContextMenu={(event: MouseEvent) => {
|
|
187
|
+
onContextMenuFile?.(event, file);
|
|
188
|
+
}}
|
|
189
|
+
onClick={(event: MouseEvent) => {
|
|
190
|
+
selectFile(file, !event.ctrlKey);
|
|
191
|
+
}}
|
|
192
|
+
onDoubleClick={(event: MouseEvent) => {
|
|
193
|
+
onOpenFile?.(event, file);
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<div className={styles.FileIcon}>
|
|
197
|
+
<ImagePreview source={file.getIconUrl()} onError={() => { file.setIconUrl(null); }}/>
|
|
198
|
+
</div>
|
|
199
|
+
<p>{file.id}</p>
|
|
200
|
+
</Interactable>
|
|
201
|
+
)}
|
|
202
|
+
</div>;
|
|
203
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.ImagePreview {
|
|
2
|
+
height: 100%;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
pointer-events: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.ImagePreview > * {
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
object-fit: contain;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ImagePreview > img {
|
|
14
|
+
height: auto;
|
|
15
|
+
max-height: 100%;
|
|
16
|
+
width: auto;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
border-radius: inherit;
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import styles from "./ImagePreview.module.css";
|
|
3
|
+
import { ReactSVG } from "react-svg";
|
|
4
|
+
import { useSystemManager } from "../../../hooks";
|
|
5
|
+
|
|
6
|
+
interface ImagePreviewProps {
|
|
7
|
+
source: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
onError?: Function;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ImagePreview({ source, className, onError, ...props }: ImagePreviewProps) {
|
|
13
|
+
const { virtualDriveConfig } = useSystemManager();
|
|
14
|
+
const [loadingFailed, setLoadingFailed] = useState(false);
|
|
15
|
+
|
|
16
|
+
const onLoadingError = () => {
|
|
17
|
+
setLoadingFailed(true);
|
|
18
|
+
onError?.();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const classNames = [styles.ImagePreview];
|
|
22
|
+
if (className != null)
|
|
23
|
+
classNames.push(className);
|
|
24
|
+
|
|
25
|
+
return (<div className={classNames.join(" ")} {...props}>
|
|
26
|
+
{loadingFailed
|
|
27
|
+
? <ReactSVG src={virtualDriveConfig.fileIcon}/>
|
|
28
|
+
: source.endsWith(".svg")
|
|
29
|
+
? <ReactSVG src={source} onError={onLoadingError}/>
|
|
30
|
+
: <img src={source} onError={onLoadingError} alt="Preview" draggable="false"/>
|
|
31
|
+
}
|
|
32
|
+
</div>);
|
|
33
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
.DropdownButton {
|
|
2
|
+
position: relative;
|
|
3
|
+
height: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.Button {
|
|
7
|
+
display: block;
|
|
8
|
+
width: auto;
|
|
9
|
+
height: 100%;
|
|
10
|
+
padding: 0 0.5rem;
|
|
11
|
+
background: none;
|
|
12
|
+
border: none;
|
|
13
|
+
outline: none;
|
|
14
|
+
font-size: 0.85rem;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.Button:hover, .Button:focus-visible {
|
|
19
|
+
background-color: rgba(255, 255, 255, 5%);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.Dropdown {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
position: absolute;
|
|
26
|
+
top: 100%;
|
|
27
|
+
left: 0;
|
|
28
|
+
padding: 0.35rem;
|
|
29
|
+
background-color: var(--background-color-1);
|
|
30
|
+
border-bottom-left-radius: 0.5rem;
|
|
31
|
+
border-bottom-right-radius: 0.5rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.Dropdown > button {
|
|
35
|
+
display: flex;
|
|
36
|
+
gap: 0.75rem;
|
|
37
|
+
justify-content: space-between;
|
|
38
|
+
width: 100%;
|
|
39
|
+
padding: 0.25rem 0.5rem;
|
|
40
|
+
background: none;
|
|
41
|
+
border: none;
|
|
42
|
+
border-radius: var(--border-radius-1);
|
|
43
|
+
outline: none;
|
|
44
|
+
font-size: 0.85rem;
|
|
45
|
+
text-align: start;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.Dropdown > button:hover, .Dropdown > button:focus-visible {
|
|
51
|
+
background-color: color-mix(in srgb, var(--background-color-0) 75%, transparent);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.Dropdown > button > p {
|
|
55
|
+
margin: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.Shortcut {
|
|
59
|
+
color: var(--foreground-color-1);
|
|
60
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import styles from "./DropdownButton.module.css";
|
|
3
|
+
import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
|
|
4
|
+
import { formatShortcut } from "../../../features/_utils/string.utils";
|
|
5
|
+
|
|
6
|
+
export function DropdownButton({ label, options, shortcuts }: { label: string; options: { [s: string]: Function; }; shortcuts: { [s: string]: string[]; }; }) {
|
|
7
|
+
const [open, setOpen] = useState(false);
|
|
8
|
+
const [tabIndex, setTabIndex] = useState(-1);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setTabIndex(open ? 0 : -1);
|
|
12
|
+
}, [open]);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<OutsideClickListener onOutsideClick={() => { setOpen(false); }}>
|
|
16
|
+
<div className={styles.DropdownButton}>
|
|
17
|
+
<button className={styles.Button} tabIndex={0} onClick={() => { setOpen(!open); }}>
|
|
18
|
+
{label}
|
|
19
|
+
</button>
|
|
20
|
+
{open && options
|
|
21
|
+
? (<div className={styles.Dropdown}>
|
|
22
|
+
{Object.entries(options).map(([label, callback]: [label: string, callback: Function]) =>
|
|
23
|
+
<button key={label} tabIndex={tabIndex} onClick={() => {
|
|
24
|
+
setOpen(false);
|
|
25
|
+
callback();
|
|
26
|
+
}}>
|
|
27
|
+
<p className={styles.Label}>{label}</p>
|
|
28
|
+
{Object.keys(shortcuts).includes(label)
|
|
29
|
+
? <p className={styles.Shortcut}>{formatShortcut(shortcuts[label])}</p>
|
|
30
|
+
: null
|
|
31
|
+
}
|
|
32
|
+
</button>
|
|
33
|
+
)}
|
|
34
|
+
</div>)
|
|
35
|
+
: null
|
|
36
|
+
}
|
|
37
|
+
</div>
|
|
38
|
+
</OutsideClickListener>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import styles from "./HeaderMenu.module.css";
|
|
2
|
+
import { ActionsProps, Actions } from "../../actions/Actions";
|
|
3
|
+
import { useZIndex } from "../../../hooks/z-index/zIndex";
|
|
4
|
+
import { ZIndexManager } from "../../../features/z-index/zIndexManager";
|
|
5
|
+
import { ActionsManager } from "../../../features/actions/actionsManager";
|
|
6
|
+
|
|
7
|
+
export function HeaderMenu({ children, ...props }: ActionsProps) {
|
|
8
|
+
const zIndex = useZIndex({ groupIndex: ZIndexManager.GROUPS.MODALS, index: 5 });
|
|
9
|
+
|
|
10
|
+
return <div className={styles.HeaderMenu} style={{ zIndex }}>
|
|
11
|
+
<Actions mode={ActionsManager.MODES.headerMenu} {...props}>
|
|
12
|
+
{children}
|
|
13
|
+
</Actions>
|
|
14
|
+
</div>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { Button } from "./button/Button";
|
|
2
|
+
export { DirectoryList } from "./directory-list/DirectoryList";
|
|
3
|
+
export { DropdownButton } from "./dropdown-button/DropdownButton";
|
|
4
|
+
export { Interactable } from "./interactable/Interactable";
|
|
5
|
+
export { ProgressBar } from "./progress-bar/ProgressBar";
|
|
6
|
+
export { HeaderMenu } from "./header-menu/HeaderMenu";
|
|
7
|
+
export { WebView } from "./web-view/WebView";
|
|
8
|
+
export { ImagePreview } from "./directory-list/ImagePreview";
|
|
9
|
+
|
|
10
|
+
export type { OnSelectionChangeParams, FileEventHandler, FolderEventHandler } from "./directory-list/DirectoryList";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MouseEventHandler, ReactNode, useState } from "react";
|
|
2
|
+
import { useSystemManager } from "../../../hooks";
|
|
3
|
+
|
|
4
|
+
let timeoutId: number | null = null;
|
|
5
|
+
|
|
6
|
+
interface InteractableProps {
|
|
7
|
+
onClick: Function;
|
|
8
|
+
onDoubleClick: Function;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Interactable({ onClick, onDoubleClick, children, ...props }: InteractableProps) {
|
|
14
|
+
const { miscConfig } = useSystemManager();
|
|
15
|
+
const [clicked, setClicked] = useState(false);
|
|
16
|
+
|
|
17
|
+
const onButtonClick = (event: MouseEvent) => {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
event.stopPropagation();
|
|
20
|
+
|
|
21
|
+
if (timeoutId != null)
|
|
22
|
+
clearTimeout(timeoutId);
|
|
23
|
+
|
|
24
|
+
if (clicked) {
|
|
25
|
+
setClicked(false);
|
|
26
|
+
onDoubleClick?.(event);
|
|
27
|
+
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setClicked(true);
|
|
32
|
+
onClick?.(event);
|
|
33
|
+
|
|
34
|
+
timeoutId = window.setTimeout(() => {
|
|
35
|
+
setClicked(false);
|
|
36
|
+
}, miscConfig.doubleClickDelay);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return <button {...props} onClick={onButtonClick as unknown as MouseEventHandler}>
|
|
40
|
+
{children}
|
|
41
|
+
</button>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.ProgressBar {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 15rem;
|
|
4
|
+
max-width: 100%;
|
|
5
|
+
min-height: 2rem;
|
|
6
|
+
max-height: 100%;
|
|
7
|
+
background-color: var(--background-color-4);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.Fill {
|
|
11
|
+
--fill: 0%;
|
|
12
|
+
|
|
13
|
+
position: absolute;
|
|
14
|
+
left: 0;
|
|
15
|
+
top: 0;
|
|
16
|
+
width: var(--fill);
|
|
17
|
+
min-width: 1px;
|
|
18
|
+
height: 100%;
|
|
19
|
+
background-color: var(--blue-0);
|
|
20
|
+
}
|