@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.
Files changed (161) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -0
  3. package/package.json +43 -0
  4. package/src/components/_utils/button/Button.module.css +25 -0
  5. package/src/components/_utils/button/Button.tsx +48 -0
  6. package/src/components/_utils/directory-list/DirectoryList.module.css +70 -0
  7. package/src/components/_utils/directory-list/DirectoryList.tsx +203 -0
  8. package/src/components/_utils/directory-list/ImagePreview.module.css +19 -0
  9. package/src/components/_utils/directory-list/ImagePreview.tsx +33 -0
  10. package/src/components/_utils/dropdown-button/DropdownButton.module.css +60 -0
  11. package/src/components/_utils/dropdown-button/DropdownButton.tsx +40 -0
  12. package/src/components/_utils/header-menu/HeaderMenu.module.css +8 -0
  13. package/src/components/_utils/header-menu/HeaderMenu.tsx +15 -0
  14. package/src/components/_utils/index.ts +10 -0
  15. package/src/components/_utils/interactable/Interactable.tsx +42 -0
  16. package/src/components/_utils/progress-bar/ProgressBar.module.css +20 -0
  17. package/src/components/_utils/progress-bar/ProgressBar.tsx +22 -0
  18. package/src/components/_utils/web-view/WebView.module.css +15 -0
  19. package/src/components/_utils/web-view/WebView.tsx +47 -0
  20. package/src/components/actions/Actions.module.css +281 -0
  21. package/src/components/actions/Actions.tsx +108 -0
  22. package/src/components/actions/actions/ClickAction.tsx +30 -0
  23. package/src/components/actions/actions/Divider.tsx +5 -0
  24. package/src/components/actions/actions/DropdownAction.tsx +50 -0
  25. package/src/components/actions/actions/RadioAction.tsx +50 -0
  26. package/src/components/actions/actions/TextDisplay.tsx +12 -0
  27. package/src/components/actions/actions/ToggleAction.tsx +31 -0
  28. package/src/components/actions/index.ts +7 -0
  29. package/src/components/desktop/Desktop.module.css +49 -0
  30. package/src/components/desktop/Desktop.tsx +199 -0
  31. package/src/components/index.ts +10 -0
  32. package/src/components/modals/ModalView.module.css +14 -0
  33. package/src/components/modals/ModalView.tsx +54 -0
  34. package/src/components/modals/ModalsView.module.css +4 -0
  35. package/src/components/modals/ModalsView.tsx +32 -0
  36. package/src/components/modals/_utils/WindowedModal.module.css +92 -0
  37. package/src/components/modals/_utils/WindowedModal.tsx +71 -0
  38. package/src/components/modals/dialog-box/DialogBox.module.css +27 -0
  39. package/src/components/modals/dialog-box/DialogBox.tsx +26 -0
  40. package/src/components/modals/file-selector/FileSelector.module.css +25 -0
  41. package/src/components/modals/file-selector/FileSelector.tsx +77 -0
  42. package/src/components/modals/index.ts +7 -0
  43. package/src/components/modals/share/Option.tsx +23 -0
  44. package/src/components/modals/share/Share.module.css +153 -0
  45. package/src/components/modals/share/Share.tsx +197 -0
  46. package/src/components/prozilla-os/ProzillaOS.module.css +14 -0
  47. package/src/components/prozilla-os/ProzillaOS.tsx +76 -0
  48. package/src/components/taskbar/Taskbar.module.css +218 -0
  49. package/src/components/taskbar/Taskbar.tsx +193 -0
  50. package/src/components/taskbar/app-icon/AppIcon.module.css +62 -0
  51. package/src/components/taskbar/app-icon/AppIcon.tsx +76 -0
  52. package/src/components/taskbar/indicators/Battery.module.css +32 -0
  53. package/src/components/taskbar/indicators/Battery.tsx +114 -0
  54. package/src/components/taskbar/indicators/Calendar.module.css +24 -0
  55. package/src/components/taskbar/indicators/Calendar.tsx +67 -0
  56. package/src/components/taskbar/indicators/Network.module.css +17 -0
  57. package/src/components/taskbar/indicators/Network.tsx +38 -0
  58. package/src/components/taskbar/indicators/Volume.module.css +17 -0
  59. package/src/components/taskbar/indicators/Volume.tsx +38 -0
  60. package/src/components/taskbar/indicators/index.ts +4 -0
  61. package/src/components/taskbar/menus/AppList.module.css +33 -0
  62. package/src/components/taskbar/menus/HomeMenu.module.css +47 -0
  63. package/src/components/taskbar/menus/HomeMenu.tsx +118 -0
  64. package/src/components/taskbar/menus/SearchMenu.module.css +68 -0
  65. package/src/components/taskbar/menus/SearchMenu.tsx +100 -0
  66. package/src/components/taskbar/menus/UtilMenu.module.css +41 -0
  67. package/src/components/taskbar/menus/UtilMenu.tsx +23 -0
  68. package/src/components/windows/WindowFallbackView.tsx +38 -0
  69. package/src/components/windows/WindowView.module.css +152 -0
  70. package/src/components/windows/WindowView.tsx +233 -0
  71. package/src/components/windows/WindowsView.tsx +89 -0
  72. package/src/constants/index.ts +3 -0
  73. package/src/constants/modals.const.ts +3 -0
  74. package/src/constants/themes.const.ts +8 -0
  75. package/src/constants/utils.const.ts +19 -0
  76. package/src/constants/virtualDrive.const.ts +20 -0
  77. package/src/features/_utils/array.utils.ts +14 -0
  78. package/src/features/_utils/browser.utils.ts +111 -0
  79. package/src/features/_utils/date.utils.ts +90 -0
  80. package/src/features/_utils/event.utils.ts +39 -0
  81. package/src/features/_utils/index.ts +8 -0
  82. package/src/features/_utils/math.utils.ts +18 -0
  83. package/src/features/_utils/number.utils.ts +3 -0
  84. package/src/features/_utils/string.utils.ts +31 -0
  85. package/src/features/_utils/time.utils.ts +13 -0
  86. package/src/features/actions/actionsManager.ts +7 -0
  87. package/src/features/index.ts +12 -0
  88. package/src/features/math/vector2.ts +75 -0
  89. package/src/features/modals/modal.ts +74 -0
  90. package/src/features/modals/modalsManager.ts +72 -0
  91. package/src/features/settings/settings.ts +109 -0
  92. package/src/features/settings/settingsManager.ts +31 -0
  93. package/src/features/storage/storageManager.ts +35 -0
  94. package/src/features/system/configs/app.tsx +60 -0
  95. package/src/features/system/configs/appsConfig.ts +60 -0
  96. package/src/features/system/configs/desktopConfig.ts +46 -0
  97. package/src/features/system/configs/index.ts +9 -0
  98. package/src/features/system/configs/miscConfig.ts +19 -0
  99. package/src/features/system/configs/modalsConfig.ts +28 -0
  100. package/src/features/system/configs/taskbarConfig.ts +19 -0
  101. package/src/features/system/configs/trackingConfig.ts +24 -0
  102. package/src/features/system/configs/virtualDriveConfig.ts +39 -0
  103. package/src/features/system/configs/windowsConfig.ts +34 -0
  104. package/src/features/system/systemManager.ts +68 -0
  105. package/src/features/tracking/trackingManager.ts +40 -0
  106. package/src/features/virtual-drive/file/index.ts +2 -0
  107. package/src/features/virtual-drive/file/virtualFile.ts +197 -0
  108. package/src/features/virtual-drive/file/virtualFileLink.ts +111 -0
  109. package/src/features/virtual-drive/folder/index.ts +2 -0
  110. package/src/features/virtual-drive/folder/virtualFolder.ts +388 -0
  111. package/src/features/virtual-drive/folder/virtualFolderLink.ts +148 -0
  112. package/src/features/virtual-drive/index.ts +3 -0
  113. package/src/features/virtual-drive/root/defaultData.ts +140 -0
  114. package/src/features/virtual-drive/root/virtualRoot.ts +244 -0
  115. package/src/features/virtual-drive/virtualBase.ts +191 -0
  116. package/src/features/windows/windowsManager.ts +244 -0
  117. package/src/features/z-index/zIndexGroup.ts +40 -0
  118. package/src/features/z-index/zIndexManager.ts +46 -0
  119. package/src/hooks/_utils/history.ts +50 -0
  120. package/src/hooks/_utils/index.ts +6 -0
  121. package/src/hooks/_utils/keyboard.ts +111 -0
  122. package/src/hooks/_utils/mouse.ts +32 -0
  123. package/src/hooks/_utils/outsideClick.tsx +33 -0
  124. package/src/hooks/_utils/screen.ts +61 -0
  125. package/src/hooks/_utils/scrollWithShadows.ts +138 -0
  126. package/src/hooks/apps/appFolder.ts +30 -0
  127. package/src/hooks/index.ts +9 -0
  128. package/src/hooks/modals/alert.tsx +34 -0
  129. package/src/hooks/modals/contextMenu.tsx +47 -0
  130. package/src/hooks/modals/index.ts +4 -0
  131. package/src/hooks/modals/modalsContext.ts +10 -0
  132. package/src/hooks/modals/modalsManagerContext.ts +10 -0
  133. package/src/hooks/modals/modalsManagerProvider.tsx +16 -0
  134. package/src/hooks/modals/modalsProvider.tsx +20 -0
  135. package/src/hooks/modals/windowedModal.ts +47 -0
  136. package/src/hooks/settings/settingsManagerContext.ts +10 -0
  137. package/src/hooks/settings/settingsManagerProvider.tsx +16 -0
  138. package/src/hooks/system/systemManagerContext.ts +8 -0
  139. package/src/hooks/system/systemManagerProvider.tsx +26 -0
  140. package/src/hooks/themes/themes.tsx +22 -0
  141. package/src/hooks/tracking/trackingManagerContext.ts +10 -0
  142. package/src/hooks/tracking/trackingManagerProvider.tsx +13 -0
  143. package/src/hooks/virtual-drive/virtualRootContext.ts +10 -0
  144. package/src/hooks/virtual-drive/virtualRootProvider.tsx +13 -0
  145. package/src/hooks/windows/windowsContext.ts +10 -0
  146. package/src/hooks/windows/windowsManagerContext.ts +10 -0
  147. package/src/hooks/windows/windowsManagerProvider.tsx +24 -0
  148. package/src/hooks/windows/windowsProvider.tsx +20 -0
  149. package/src/hooks/z-index/zIndex.ts +32 -0
  150. package/src/hooks/z-index/zIndexManagerContext.ts +10 -0
  151. package/src/hooks/z-index/zIndexManagerProvider.tsx +11 -0
  152. package/src/index.ts +5 -0
  153. package/src/styles/global/fonts.css +18 -0
  154. package/src/styles/global/scrollbar.css +29 -0
  155. package/src/styles/global/themes.css +67 -0
  156. package/src/styles/global/variables.css +92 -0
  157. package/src/styles/global.css +65 -0
  158. package/src/styles/index.ts +3 -0
  159. package/src/styles/utils.module.css +22 -0
  160. package/src/types/util.d.ts +3 -0
  161. package/src/types/vite-env.d.ts +1 -0
@@ -0,0 +1,46 @@
1
+ import { EventEmitter } from "../_utils/event.utils";
2
+ import { ZIndexGroup } from "./zIndexGroup";
3
+
4
+ const ZIndexManagerEvents = {
5
+ indexChange: "indexChange",
6
+ } as const;
7
+
8
+ export class ZIndexManager extends EventEmitter<typeof ZIndexManagerEvents> {
9
+ static GROUPS = {
10
+ WINDOWS: 0,
11
+ TASKBAR: 1,
12
+ MODALS: 2,
13
+ };
14
+
15
+ static EVENT_NAMES = ZIndexManagerEvents;
16
+
17
+ groups: ZIndexGroup[] = [];
18
+
19
+ constructor() {
20
+ super();
21
+ for (let i = 0; i < Object.keys(ZIndexManager.GROUPS).length; i++) {
22
+ const group = new ZIndexGroup(this);
23
+ this.groups.push(group);
24
+ }
25
+ }
26
+
27
+ update() {
28
+ let offset = 0;
29
+ let changed = false;
30
+ for (let i = 0; i < this.groups.length; i++) {
31
+ const group = this.groups[i];
32
+ if (group.offset !== offset) {
33
+ changed = true;
34
+ group.setOffset(offset);
35
+ }
36
+ offset += group.length;
37
+ }
38
+ if (changed) {
39
+ this.emit("indexChange");
40
+ }
41
+ }
42
+
43
+ getIndex(groupIndex: number, index: number) {
44
+ return this.groups[groupIndex].getIndex(index);
45
+ }
46
+ }
@@ -0,0 +1,50 @@
1
+ import { useState } from "react";
2
+ import { clamp } from "../../features";
3
+
4
+ export function useHistory<Type>(initialState: Type): {
5
+ history: Type[];
6
+ stateIndex: number;
7
+ pushState: Function;
8
+ undo: Function;
9
+ redo: Function;
10
+ undoAvailable: boolean;
11
+ redoAvailable: boolean;
12
+ } {
13
+ const [history, setHistory] = useState<Type[]>(initialState ? [initialState] : []);
14
+ const [stateIndex, setStateIndex] = useState(0);
15
+
16
+ const pushState = (state: Type) => {
17
+ if (state === history[0])
18
+ return;
19
+
20
+ let newHistory = [
21
+ state,
22
+ ...history.slice(stateIndex, history.length)
23
+ ];
24
+
25
+ // Remove repeated states
26
+ newHistory = newHistory.filter((state, index) => {
27
+ return state !== newHistory[index + 1];
28
+ });
29
+
30
+ setHistory(newHistory);
31
+ setStateIndex(0);
32
+ };
33
+
34
+ const updateStateIndex = (delta: number) => {
35
+ const index = clamp(stateIndex + delta, 0, history.length - 1);
36
+
37
+ if (index === stateIndex)
38
+ return;
39
+
40
+ setStateIndex(index);
41
+ };
42
+
43
+ const undo = () => updateStateIndex(1);
44
+ const redo = () => updateStateIndex(-1);
45
+
46
+ const undoAvailable = (stateIndex < history.length - 1);
47
+ const redoAvailable = (stateIndex >= 1);
48
+
49
+ return { history, stateIndex, pushState, undo, redo, undoAvailable, redoAvailable };
50
+ }
@@ -0,0 +1,6 @@
1
+ export { useHistory } from "./history";
2
+ export { useKeyboardListener, useShortcuts } from "./keyboard";
3
+ export { useMouseListener } from "./mouse";
4
+ export { OutsideClickListener } from "./outsideClick";
5
+ export { useScreenBounds, useScreenDimensions } from "./screen";
6
+ export { useScrollWithShadow } from "./scrollWithShadows";
@@ -0,0 +1,111 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { removeFromArray } from "../../features";
3
+
4
+ interface UseKeyboardListenerParams {
5
+ onKeyDown?: (event: KeyboardEvent) => void;
6
+ onKeyUp?: (event: KeyboardEvent) => void;
7
+ };
8
+
9
+ export function useKeyboardListener({ onKeyDown, onKeyUp }: UseKeyboardListenerParams) {
10
+ useEffect(() => {
11
+ if (onKeyDown)
12
+ document.addEventListener("keydown", onKeyDown);
13
+ if (onKeyUp)
14
+ document.addEventListener("keyup", onKeyUp);
15
+
16
+ return () => {
17
+ if (onKeyDown)
18
+ document.removeEventListener("keydown", onKeyDown);
19
+ if (onKeyUp)
20
+ document.removeEventListener("keyup", onKeyUp);
21
+ };
22
+ }, [onKeyDown, onKeyUp]);
23
+ }
24
+
25
+ interface UseShortcutsParams {
26
+ options: Record<string, Record<string, Function>> | Record<string, Function>;
27
+ shortcuts?: Record<string, Record<string, string[]>> | Record<string, string[]>;
28
+ useCategories?: boolean,
29
+ }
30
+
31
+ /**
32
+ * TO DO: rewrite to use a global shortcuts manager instead, to allow certain shortcuts to be prioritized and prevent conflicts
33
+ */
34
+ export function useShortcuts({ options, shortcuts, useCategories = true }: UseShortcutsParams) {
35
+ const [activeKeys, setActiveKeys] = useState<string[]>([]);
36
+
37
+ const checkShortcuts = useCallback((event: KeyboardEvent, allowExecution = true) => {
38
+ if (!shortcuts)
39
+ return;
40
+
41
+ const keys = [...activeKeys];
42
+
43
+ const checkGroup = (group: Record<string, string[]>, category?: string) => {
44
+ for (const [name, shortcut] of Object.entries(group)) {
45
+ let active = true;
46
+
47
+ shortcut.forEach((key) => {
48
+ if (!keys.includes(key) && event.key !== key)
49
+ return active = false;
50
+ });
51
+
52
+ if (!active)
53
+ continue;
54
+
55
+ event.preventDefault();
56
+ event.stopPropagation();
57
+
58
+ if (!shortcut.includes(event.key) || !allowExecution)
59
+ continue;
60
+
61
+ if (category != null) {
62
+ (options as Record<string, Record<string, Function>>)?.[category]?.[name]?.(event);
63
+ } else {
64
+ (options as Record<string, Function>)?.[name]?.(event);
65
+ }
66
+ }
67
+ };
68
+
69
+ if (useCategories) {
70
+ for (const [category, group] of Object.entries(shortcuts)) {
71
+ checkGroup(group as Record<string, string[]>, category);
72
+ }
73
+ } else {
74
+ checkGroup(shortcuts as Record<string, string[]>);
75
+ }
76
+
77
+ setActiveKeys(keys);
78
+ }, [activeKeys, options, shortcuts, useCategories]);
79
+
80
+ useEffect(() => {
81
+ const onBlur = () => {
82
+ setActiveKeys([]);
83
+ };
84
+
85
+ document.addEventListener("blur", onBlur);
86
+
87
+ return () => {
88
+ document.removeEventListener("blur", onBlur);
89
+ };
90
+ }, []);
91
+
92
+ const onKeyDown = (event: KeyboardEvent) => {
93
+ const isRepeated = activeKeys.includes(event.key);
94
+ checkShortcuts(event, isRepeated);
95
+
96
+ if (!isRepeated)
97
+ setActiveKeys(activeKeys.concat([event.key]));
98
+ };
99
+
100
+ const onKeyUp = (event: KeyboardEvent) => {
101
+ checkShortcuts(event);
102
+
103
+ if (activeKeys.includes(event.key)) {
104
+ const keys = [...activeKeys];
105
+ removeFromArray(event.key, keys);
106
+ setActiveKeys(keys);
107
+ }
108
+ };
109
+
110
+ useKeyboardListener({ onKeyDown, onKeyUp });
111
+ }
@@ -0,0 +1,32 @@
1
+ import { useEffect } from "react";
2
+
3
+ interface UseMouseListenerParams {
4
+ onMouseDown: EventListener;
5
+ onMouseUp: EventListener;
6
+ onClick: EventListener;
7
+ onContextMenu: EventListener;
8
+ }
9
+
10
+ export function useMouseListener({ onMouseDown, onMouseUp, onClick, onContextMenu }: UseMouseListenerParams) {
11
+ useEffect(() => {
12
+ if (onMouseDown)
13
+ document.addEventListener("mousedown", onMouseDown);
14
+ if (onMouseUp)
15
+ document.addEventListener("mouseup", onMouseUp);
16
+ if (onClick)
17
+ document.addEventListener("click", onClick);
18
+ if (onContextMenu)
19
+ document.addEventListener("contextmenu", onContextMenu);
20
+
21
+ return () => {
22
+ if (onMouseDown)
23
+ document.removeEventListener("mousedown", onMouseDown);
24
+ if (onMouseUp)
25
+ document.removeEventListener("mouseup", onMouseUp);
26
+ if (onClick)
27
+ document.removeEventListener("click", onClick);
28
+ if (onContextMenu)
29
+ document.removeEventListener("contextmenu", onContextMenu);
30
+ };
31
+ }, [onMouseDown, onMouseUp, onClick, onContextMenu]);
32
+ }
@@ -0,0 +1,33 @@
1
+ import { useRef, useEffect, memo, ReactNode } from "react";
2
+
3
+ /**
4
+ * https://stackoverflow.com/a/42234988
5
+ */
6
+
7
+ function useOutsideClickListener(ref: { current: HTMLElement | null }, callback: (event: Event) => void) {
8
+ useEffect(() => {
9
+ const handleClickOutside = (event: Event) => {
10
+ if (ref.current && !ref.current.contains(event.target as HTMLElement)) {
11
+ callback(event);
12
+ }
13
+ };
14
+
15
+ document.addEventListener("mousedown", handleClickOutside);
16
+
17
+ return () => {
18
+ document.removeEventListener("mousedown", handleClickOutside);
19
+ };
20
+ }, [ref, callback]);
21
+ }
22
+
23
+ interface OutsideClickListenerProps {
24
+ onOutsideClick: (event: Event) => void;
25
+ children: ReactNode;
26
+ }
27
+
28
+ export const OutsideClickListener = memo(({ onOutsideClick, children }: OutsideClickListenerProps) => {
29
+ const wrapperRef = useRef(null);
30
+ useOutsideClickListener(wrapperRef, onOutsideClick);
31
+
32
+ return <div ref={wrapperRef}>{children}</div>;
33
+ });
@@ -0,0 +1,61 @@
1
+ import { Ref, useEffect, useRef, useState } from "react";
2
+ import { useSystemManager } from "../system/systemManagerContext";
3
+
4
+ export function useScreenDimensions(): [screenWidth: number | null, screenHeight: number | null] {
5
+ const [screenWidth, setScreenWidth] = useState<number | null>(null);
6
+ const [screenHeight, setScreenHeight] = useState<number | null>(null);
7
+
8
+ useEffect(() => {
9
+ const resizeObserver = new ResizeObserver((event) => {
10
+ setScreenWidth(event[0].contentBoxSize[0].inlineSize);
11
+ setScreenHeight(event[0].contentBoxSize[0].blockSize);
12
+ });
13
+
14
+ const root = document.getElementById("root");
15
+
16
+ if (root == null)
17
+ throw new Error("Root is null: No element with ID 'root' found");
18
+
19
+ resizeObserver.observe(root);
20
+ }, []);
21
+
22
+ return [screenWidth, screenHeight];
23
+ }
24
+
25
+ export function useScreenBounds({ avoidTaskbar = true }: { avoidTaskbar: boolean; }): {
26
+ ref: Ref<HTMLElement>;
27
+ initiated: boolean;
28
+ alignLeft: boolean;
29
+ alignTop: boolean;
30
+ } {
31
+ const { taskbarConfig } = useSystemManager();
32
+ const ref = useRef(null);
33
+ const [initiated, setInitiated] = useState(false);
34
+ const [alignLeft, setAlignLeft] = useState(false);
35
+ const [alignTop, setAlignTop] = useState(false);
36
+ const [screenWidth, screenHeight] = useScreenDimensions();
37
+
38
+ useEffect(() => {
39
+ if (ref.current == null || screenWidth == null || screenHeight == null)
40
+ return;
41
+
42
+ const rect = (ref.current as HTMLElement).getBoundingClientRect();
43
+ const maxX = screenWidth;
44
+ let maxY = screenHeight;
45
+
46
+ if (avoidTaskbar)
47
+ maxY -= taskbarConfig.height;
48
+
49
+ const isOverflowingRight = (rect.x + rect.width > maxX);
50
+ const isOverflowingBottom = (rect.y + rect.height > maxY);
51
+
52
+ if (isOverflowingRight)
53
+ setAlignLeft(true);
54
+ if (isOverflowingBottom)
55
+ setAlignTop(true);
56
+
57
+ setInitiated(true);
58
+ }, [alignLeft, avoidTaskbar, screenHeight, screenWidth]);
59
+
60
+ return { ref, initiated, alignLeft, alignTop };
61
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * https://medium.com/dfind-consulting/react-scroll-hook-with-shadows-9ba2d47ae32
3
+ */
4
+
5
+
6
+ import { MutableRefObject, useCallback, useEffect } from "react";
7
+ import { useState } from "react";
8
+
9
+ interface UseScrollWithShadowParams {
10
+ ref?: MutableRefObject<HTMLElement>;
11
+ horizontal?: boolean;
12
+ dynamicOffset?: boolean;
13
+ dynamicOffsetFactor?: number;
14
+ shadow?: {
15
+ offset?: number;
16
+ blurRadius?: number;
17
+ spreadRadius?: number;
18
+ color?: {
19
+ r?: number;
20
+ g?: number;
21
+ b?: number;
22
+ a?: number;
23
+ }
24
+ }
25
+ }
26
+
27
+ export function useScrollWithShadow(params: UseScrollWithShadowParams): {
28
+ boxShadow: string;
29
+ onUpdate: (event: Event | { target: HTMLElement }) => void;
30
+ } {
31
+ const [initiated, setInitiated] = useState(false);
32
+ const [scrollStart, setScrollStart] = useState(0);
33
+ const [scrollLength, setScrollLength] = useState(0);
34
+ const [clientLength, setClientLength] = useState(0);
35
+
36
+ if (params == null)
37
+ params = {};
38
+ if (params.shadow == null)
39
+ params.shadow = {};
40
+ if (params.shadow.color == null)
41
+ params.shadow.color = {};
42
+
43
+ const {
44
+ ref,
45
+ horizontal = true,
46
+ dynamicOffset = true,
47
+ dynamicOffsetFactor = 3,
48
+ shadow: {
49
+ offset = 8,
50
+ blurRadius = 5,
51
+ spreadRadius = -5,
52
+ color: {
53
+ r = 0,
54
+ g = 0,
55
+ b = 0,
56
+ a = 50
57
+ }
58
+ }
59
+ } = params;
60
+
61
+ const updateValues = useCallback((element: HTMLElement) => {
62
+ if (!element)
63
+ return;
64
+
65
+ setScrollStart(horizontal ? element.scrollLeft : element.scrollTop);
66
+ setScrollLength(horizontal ? element.scrollWidth : element.scrollHeight);
67
+ setClientLength(horizontal ? element.clientWidth : element.clientHeight);
68
+ }, [horizontal]);
69
+
70
+ const onUpdate = (event: Event | { target: HTMLElement }) => {
71
+ updateValues(event.target as HTMLElement);
72
+ };
73
+
74
+ useEffect(() => {
75
+ const onResize = () => {
76
+ if (ref?.current != null) updateValues(ref.current);
77
+ };
78
+
79
+ if (ref?.current && !initiated) {
80
+ setInitiated(true);
81
+ updateValues(ref.current);
82
+ }
83
+
84
+ window.addEventListener("resize", onResize);
85
+
86
+ return () => {
87
+ window.removeEventListener("resize", onResize);
88
+ };
89
+ }, [ref, updateValues, initiated]);
90
+
91
+ const getBoxShadow = () => {
92
+ const startDistance = scrollStart;
93
+ const endDistance = scrollLength - scrollStart - clientLength;
94
+
95
+ const isStart = startDistance === 0;
96
+ const isEnd = endDistance === 0;
97
+ const isBetween = scrollStart > 0 && clientLength < scrollLength - scrollStart;
98
+
99
+ let startOffset = offset;
100
+ let endOffset = offset;
101
+
102
+ if (dynamicOffset) {
103
+ startOffset = startDistance * dynamicOffsetFactor - offset;
104
+ endOffset = endDistance * dynamicOffsetFactor - offset;
105
+
106
+ if (startOffset > offset) {
107
+ startOffset = offset;
108
+ } else if (startOffset < 0) {
109
+ startOffset = 0;
110
+ }
111
+ if (endOffset > offset) {
112
+ endOffset = offset;
113
+ } else if (endOffset < 0) {
114
+ endOffset = 0;
115
+ }
116
+ }
117
+
118
+ const shadowStartOffset = horizontal ? `${startOffset}px 0` : `0 ${startOffset}px`;
119
+ const shadowEndOffset = horizontal ? `-${endOffset}px 0` : `0 -${endOffset}px`;
120
+
121
+ const start = `inset ${shadowStartOffset} ${blurRadius}px ${spreadRadius}px rgba(${r}, ${g}, ${b}, ${a}%)`;
122
+ const end = `inset ${shadowEndOffset} ${blurRadius}px ${spreadRadius}px rgba(${r}, ${g}, ${b}, ${a}%)`;
123
+
124
+ let boxShadow = "none";
125
+
126
+ if (isStart) {
127
+ boxShadow = end;
128
+ } else if (isBetween) {
129
+ boxShadow = `${start}, ${end}`;
130
+ } else if (isEnd) {
131
+ boxShadow = start;
132
+ }
133
+
134
+ return boxShadow;
135
+ };
136
+
137
+ return { boxShadow: getBoxShadow(), onUpdate };
138
+ }
@@ -0,0 +1,30 @@
1
+ import { useEffect, useState } from "react";
2
+ import { App } from "../../features/system/configs/app";
3
+ import { VirtualFolder } from "../../features/virtual-drive/folder";
4
+ import { useVirtualRoot } from "../virtual-drive/virtualRootContext";
5
+
6
+ export function useAppFolder(app?: App): VirtualFolder | null {
7
+ const virtualRoot = useVirtualRoot();
8
+ const [folder, setFolder] = useState<VirtualFolder | null>(null);
9
+
10
+ useEffect(() => {
11
+ if (folder != null)
12
+ return;
13
+
14
+ const parentFolder = virtualRoot?.navigate("~/Apps") as VirtualFolder;
15
+
16
+ if (parentFolder == null) {
17
+ console.warn("Folder missing: '~/Apps'");
18
+ return;
19
+ }
20
+
21
+ if (app == null)
22
+ return;
23
+
24
+ parentFolder.createFolder(app.id, (newFolder) => {
25
+ setFolder(newFolder);
26
+ });
27
+ }, [virtualRoot]);
28
+
29
+ return folder;
30
+ }
@@ -0,0 +1,9 @@
1
+ export * from "./_utils";
2
+ export { useAppFolder } from "./apps/appFolder";
3
+ export * from "./modals";
4
+ export { useSettingsManager } from "./settings/settingsManagerContext";
5
+ export { useVirtualRoot } from "./virtual-drive/virtualRootContext";
6
+ export { useWindowsManager } from "./windows/windowsManagerContext";
7
+ export { useZIndex } from "./z-index/zIndex";
8
+ export { useSystemManager } from "./system/systemManagerContext";
9
+ export { useTrackingManager } from "./tracking/trackingManagerContext";
@@ -0,0 +1,34 @@
1
+ import { useCallback } from "react";
2
+ import { DialogBox } from "../../components/modals/dialog-box/DialogBox";
3
+ import { DIALOG_CONTENT_TYPES } from "../../constants/modals.const";
4
+ import { useWindowedModal } from "./windowedModal";
5
+ import { ModalProps } from "../../components/modals/ModalView";
6
+ import { Vector2 } from "../../features";
7
+
8
+ interface AlertParams {
9
+ title: string;
10
+ text: string;
11
+ iconUrl?: string;
12
+ size?: Vector2;
13
+ single?: boolean;
14
+ }
15
+
16
+ export function useAlert() {
17
+ const { openWindowedModal } = useWindowedModal();
18
+
19
+ const alert = useCallback(({ title, text, iconUrl, size, single }: AlertParams) => {
20
+ openWindowedModal({
21
+ title: title ?? "Alert",
22
+ iconUrl,
23
+ size: size ?? new Vector2(300, 150),
24
+ single,
25
+ Modal: (props: ModalProps) =>
26
+ <DialogBox {...props}>
27
+ <p>{text}</p>
28
+ <button data-type={DIALOG_CONTENT_TYPES.closeButton}>Ok</button>
29
+ </DialogBox>
30
+ });
31
+ }, [openWindowedModal]);
32
+
33
+ return { alert };
34
+ }
@@ -0,0 +1,47 @@
1
+ import { FC, MouseEvent, useCallback } from "react";
2
+ import { ActionsProps } from "../../components/actions/Actions";
3
+ import { useModalsManager } from "./modalsManagerContext";
4
+ import { ModalProps } from "../../components/modals/ModalView";
5
+ import { Modal } from "../../features/modals/modal";
6
+ import { ActionsManager } from "../../features/actions/actionsManager";
7
+ import { Vector2 } from "../../features";
8
+
9
+ interface UseContextMenuParams {
10
+ Actions: FC<ActionsProps>;
11
+ }
12
+
13
+ export function useContextMenu({ Actions }: UseContextMenuParams) {
14
+ const modalsManager = useModalsManager();
15
+
16
+ // Open a new modal when context menu is triggered
17
+ const onContextMenu = useCallback((event: MouseEvent<HTMLElement, MouseEvent>, params: object = {}) => {
18
+ event.preventDefault();
19
+ event.stopPropagation();
20
+
21
+ let positionX = event?.clientX ?? 0;
22
+ let positionY = event?.clientY ?? 0;
23
+
24
+ if (modalsManager?.containerRef?.current != null) {
25
+ const containerRect = modalsManager.containerRef.current.getBoundingClientRect();
26
+ positionX -= containerRect.x;
27
+ positionY -= containerRect.y / 2;
28
+ }
29
+
30
+ const newModal = new Modal(Actions as unknown as FC<ModalProps>)
31
+ .setPosition(new Vector2(positionX, positionY))
32
+ .setProps({
33
+ triggerParams: params,
34
+ mode: ActionsManager.MODES.contextMenu,
35
+ onAnyTrigger: () => {
36
+ newModal.close();
37
+ }
38
+ });
39
+
40
+ modalsManager?.open(newModal);
41
+ return newModal;
42
+ }, [Actions, modalsManager]);
43
+
44
+ const ShortcutsListener = () => <Actions mode={ActionsManager.MODES.shortcutsListener}/>;
45
+
46
+ return { onContextMenu, ShortcutsListener };
47
+ }
@@ -0,0 +1,4 @@
1
+ export { useAlert } from "./alert";
2
+ export { useContextMenu } from "./contextMenu";
3
+ export { useWindowedModal } from "./windowedModal";
4
+ export { useModalsManager } from "./modalsManagerContext";
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from "react";
2
+ import { Modal } from "../../features/modals/modal";
3
+
4
+ export type ModalsState = Modal[] | undefined;
5
+
6
+ export const ModalsContext = createContext<ModalsState>(undefined);
7
+
8
+ export function useModals(): ModalsState {
9
+ return useContext(ModalsContext);
10
+ }
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from "react";
2
+ import { ModalsManager } from "../../features";
3
+
4
+ type ModalsManagerState = ModalsManager | undefined;
5
+
6
+ export const modalsManagerContext = createContext<ModalsManagerState>(undefined);
7
+
8
+ export function useModalsManager(): ModalsManagerState {
9
+ return useContext(modalsManagerContext);
10
+ }
@@ -0,0 +1,16 @@
1
+ import { FC, ReactNode } from "react";
2
+ import { ModalsProvider } from "./modalsProvider";
3
+ import { modalsManagerContext } from "./modalsManagerContext";
4
+ import { ModalsManager } from "../../features";
5
+
6
+ export const ModalsManagerProvider: FC<{ children: ReactNode }> = ({ children }) => {
7
+ const modalsManager = new ModalsManager();
8
+
9
+ return (
10
+ <modalsManagerContext.Provider value={modalsManager}>
11
+ <ModalsProvider modalsManager={modalsManager}>
12
+ {children}
13
+ </ModalsProvider>
14
+ </modalsManagerContext.Provider>
15
+ );
16
+ };
@@ -0,0 +1,20 @@
1
+ import { FC, ReactNode, useCallback, useState } from "react";
2
+ import { ModalsContext, ModalsState } from "./modalsContext";
3
+ import { ModalsManager } from "../../features";
4
+ import { Modal } from "../../features/modals/modal";
5
+
6
+ export const ModalsProvider: FC<{ children: ReactNode, modalsManager: ModalsManager }> = ({ children, modalsManager }) => {
7
+ const [modals, setModals] = useState<ModalsState>([]);
8
+
9
+ const updateModals = useCallback((updatedModals: Record<string, Modal>) => {
10
+ setModals(Object.values(updatedModals));
11
+ }, []);
12
+
13
+ modalsManager.setUpdateModals(updateModals);
14
+
15
+ return (
16
+ <ModalsContext.Provider value={modals}>
17
+ {children}
18
+ </ModalsContext.Provider>
19
+ );
20
+ };