@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,22 @@
1
+ import { CSSProperties } from "react";
2
+ import styles from "./ProgressBar.module.css";
3
+ import { clamp } from "../../../features/_utils/math.utils";
4
+
5
+ interface ProgressBarProps {
6
+ fillPercentage: number;
7
+ fillColor?: string;
8
+ backgroundColor?: string;
9
+ align?: "left";
10
+ className?: string;
11
+ }
12
+
13
+ export function ProgressBar({ fillPercentage, fillColor, backgroundColor, align = "left", className = "" }: ProgressBarProps) {
14
+ return (
15
+ <div className={`${styles.ProgressBar} ${className}`} style={{ backgroundColor: backgroundColor }}>
16
+ <div
17
+ className={`${styles.Fill} ${align}`}
18
+ style={{ backgroundColor: fillColor, "--fill": `${clamp(fillPercentage, 0.1, 100)}%` } as CSSProperties}
19
+ />
20
+ </div>
21
+ );
22
+ }
@@ -0,0 +1,15 @@
1
+ .WebView {
2
+ display: flex;
3
+ justify-content: center;
4
+ align-items: center;
5
+ width: 100%;
6
+ height: 100%;
7
+ }
8
+
9
+ .WebView > iframe {
10
+ width: 100%;
11
+ height: 100%;
12
+ border: none;
13
+ background: none;
14
+ pointer-events: initial;
15
+ }
@@ -0,0 +1,47 @@
1
+ import { FC, forwardRef, useEffect, useState } from "react";
2
+ import styles from "./WebView.module.css";
3
+ import { WindowProps } from "../../windows/WindowView";
4
+
5
+ interface WebViewProps extends WindowProps {
6
+ source?: string;
7
+ title?: string;
8
+ }
9
+
10
+ export const WebView: FC<WebViewProps> = forwardRef<HTMLIFrameElement>(({ source, focus, ...props }: WebViewProps, ref) => {
11
+ const [hovered, setHovered] = useState(false);
12
+
13
+ useEffect(() => {
14
+ window.focus();
15
+
16
+ const onBlur = (event: Event) => {
17
+ if (hovered) {
18
+ focus?.(event);
19
+ }
20
+ };
21
+
22
+ window.addEventListener("blur", onBlur);
23
+
24
+ return () => {
25
+ window.removeEventListener("blur", onBlur);
26
+ };
27
+ }, [focus, hovered]);
28
+
29
+ const onMouseOver = () => {
30
+ setHovered(true);
31
+ };
32
+
33
+ const onMouseOut = () => {
34
+ window.focus();
35
+ setHovered(false);
36
+ };
37
+
38
+ return <div className={styles.WebView} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
39
+ <iframe
40
+ ref={ref}
41
+ src={source}
42
+ referrerPolicy="no-referrer"
43
+ sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts"
44
+ {...props}
45
+ />
46
+ </div>;
47
+ }) as FC;
@@ -0,0 +1,281 @@
1
+ .Actions {
2
+ /* These variables describe the position of the container relative to top left corner of its parent */
3
+ --left: 0;
4
+ --top: 0;
5
+ --right: calc(1 - var(--left));
6
+ --bottom: calc(1 - var(--top));
7
+
8
+ position: absolute;
9
+ top: 0;
10
+ left: 0;
11
+ opacity: 1;
12
+ transition: opacity 100ms ease-out;
13
+ }
14
+
15
+ .Actions.Uninitiated {
16
+ opacity: 0;
17
+ }
18
+
19
+ .Actions.AlignLeft {
20
+ --left: 1;
21
+
22
+ left: unset;
23
+ right: 0;
24
+ }
25
+
26
+ .Actions.AlignTop {
27
+ --top: 1;
28
+
29
+ top: unset;
30
+ bottom: 0;
31
+ }
32
+
33
+ /* Context menu */
34
+
35
+ .ContextMenu.Actions {
36
+ --border-radius: var(--border-radius-1);
37
+ --padding: 0.375rem;
38
+
39
+ padding: var(--padding);
40
+ border-top-left-radius: calc((1 - var(--right) * var(--bottom)) * var(--border-radius)) !important;
41
+ border-top-right-radius: calc((1 - var(--left) * var(--bottom)) * var(--border-radius)) !important;
42
+ border-bottom-left-radius: calc((1 - var(--right) * var(--top)) * var(--border-radius)) !important;
43
+ border-bottom-right-radius: calc((1 - var(--left) * var(--top)) * var(--border-radius)) !important;
44
+ background-color: var(--background-color-1) !important;
45
+ }
46
+
47
+ .ContextMenu .Button,
48
+ .ContextMenu .Dropdown {
49
+ display: flex;
50
+ gap: 0.75rem;
51
+ justify-content: space-between;
52
+ width: 100%;
53
+ padding: 0.25rem 0.5rem;
54
+ background: none;
55
+ border: none;
56
+ border-radius: var(--border-radius-1);
57
+ outline: none;
58
+ font-size: 0.875rem;
59
+ text-align: start;
60
+ white-space: nowrap;
61
+ cursor: pointer;
62
+ }
63
+
64
+ .ContextMenu .Button:hover,
65
+ .ContextMenu .Button:focus-visible,
66
+ .ContextMenu .Dropdown:hover,
67
+ .ContextMenu .Dropdown:focus-visible {
68
+ background-color: color-mix(in srgb, var(--background-color-0) 75%, transparent);
69
+ }
70
+
71
+ .ContextMenu .Label {
72
+ display: flex;
73
+ gap: 0.5rem;
74
+ justify-content: center;
75
+ align-items: center;
76
+ }
77
+
78
+ .ContextMenu .Label p,
79
+ .ContextMenu .Shortcut {
80
+ margin: 0;
81
+ }
82
+
83
+ .ContextMenu .Icon {
84
+ display: flex;
85
+ justify-content: center;
86
+ align-items: center;
87
+ width: 0.875rem;
88
+ height: 0.875rem;
89
+ }
90
+
91
+ .ContextMenu .Icon > svg {
92
+ width: 100%;
93
+ height: 100%;
94
+ object-fit: contain;
95
+ }
96
+
97
+ .ContextMenu .ImageIcon {
98
+ position: absolute;
99
+ width: 1rem;
100
+ height: auto;
101
+ aspect-ratio: 1;
102
+ }
103
+
104
+ .ContextMenu .ImageIcon div {
105
+ display: flex;
106
+ width: 100%;
107
+ height: 100%;
108
+ }
109
+
110
+ .ContextMenu .ImageIcon div > svg {
111
+ width: 100%;
112
+ height: 100%;
113
+ object-fit: contain;
114
+ }
115
+
116
+ .ContextMenu .Shortcut {
117
+ color: var(--foreground-color-1);
118
+ }
119
+
120
+ .ContextMenu .Dropdown {
121
+ position: relative;
122
+ }
123
+
124
+ .ContextMenu .Dropdown .DropdownContent {
125
+ opacity: 1;
126
+ position: absolute;
127
+ top: calc(var(--padding) * -1);
128
+ left: 100%;
129
+ padding: var(--padding);
130
+ border-radius: var(--border-radius-1);
131
+ border-top-left-radius: 0;
132
+ background-color: var(--background-color-1);
133
+ transition: opacity 100ms ease-out;
134
+ cursor: auto;
135
+ }
136
+
137
+ .ContextMenu .Dropdown:not(.Active) .DropdownContent {
138
+ opacity: 0;
139
+ pointer-events: none;
140
+ }
141
+
142
+ .ContextMenu .Divider {
143
+ width: calc(100% - 0.5rem);
144
+ height: 2px;
145
+ border-radius: var(--border-radius-99);
146
+ background-color: var(--foreground-color-2);
147
+ margin: 0.5rem auto;
148
+ }
149
+
150
+ .ContextMenu .TextDisplay {
151
+ margin: 0;
152
+ padding: 0.25rem 0.75rem;
153
+ color: var(--foreground-color-1);
154
+ font-size: 0.875rem;
155
+ text-align: start;
156
+ white-space: nowrap;
157
+ }
158
+
159
+ /* Header menu */
160
+
161
+ .HeaderMenu {
162
+ display: flex;
163
+ width: inherit;
164
+ height: inherit;
165
+ }
166
+
167
+ .HeaderMenu .Dropdown {
168
+ position: relative;
169
+ display: block;
170
+ width: auto;
171
+ height: 100%;
172
+ padding: 0 0.5rem;
173
+ background: none;
174
+ border: none;
175
+ outline: none;
176
+ font-size: 0.85rem;
177
+ cursor: pointer;
178
+ }
179
+
180
+ .HeaderMenu .Dropdown:hover,
181
+ .HeaderMenu .Dropdown:focus-visible,
182
+ .HeaderMenu .Dropdown.Active {
183
+ background-color: rgba(255, 255, 255, 5%);
184
+ }
185
+
186
+ .HeaderMenu .Dropdown > .Label {
187
+ display: flex;
188
+ justify-content: center;
189
+ align-items: center;
190
+ height: 100%;
191
+ }
192
+
193
+ .HeaderMenu .DropdownArrow {
194
+ display: none;
195
+ }
196
+
197
+ .HeaderMenu .DropdownContent {
198
+ opacity: 1;
199
+ display: flex;
200
+ flex-direction: column;
201
+ position: absolute;
202
+ top: 100%;
203
+ left: 0;
204
+ padding: 0.25rem;
205
+ background-color: var(--background-color-1);
206
+ border-bottom-left-radius: var(--border-radius-1);
207
+ border-bottom-right-radius: var(--border-radius-1);
208
+ transition: opacity 100ms ease-out;
209
+ cursor: default;
210
+ }
211
+
212
+ .HeaderMenu .Dropdown:not(.Active) .DropdownContent {
213
+ opacity: 0;
214
+ pointer-events: none;
215
+ }
216
+
217
+ .HeaderMenu .Button {
218
+ --icon-size: 1.25rem;
219
+ --icon-gap: 0.5rem;
220
+
221
+ display: flex;
222
+ gap: 1.5rem;
223
+ justify-content: space-between;
224
+ align-items: center;
225
+ width: 100%;
226
+ padding: 0.25rem 0.5rem;
227
+ background: none;
228
+ border: none;
229
+ border-radius: var(--border-radius-1);
230
+ outline: none;
231
+ font-size: 0.875rem;
232
+ text-align: start;
233
+ white-space: nowrap;
234
+ cursor: pointer;
235
+ }
236
+
237
+ .HeaderMenu .Button:not(:disabled):hover,
238
+ .HeaderMenu .Button:not(:disabled):focus-visible {
239
+ background-color: color-mix(in srgb, var(--background-color-0) 75%, transparent);
240
+ }
241
+
242
+ .HeaderMenu .Button:disabled {
243
+ cursor: default;
244
+ }
245
+
246
+ .HeaderMenu .Button > .Label {
247
+ display: flex;
248
+ gap: var(--icon-gap);
249
+ flex-direction: row-reverse;
250
+ justify-content: flex-start;
251
+ align-items: center;
252
+ }
253
+
254
+ .HeaderMenu .Button > .Label .Icon div,
255
+ .HeaderMenu .Button > .Label .Icon svg {
256
+ height: var(--icon-size);
257
+ width: var(--icon-size);
258
+ }
259
+
260
+ .HeaderMenu .Dropdown > .Label > p,
261
+ .HeaderMenu .Button > .Label > p {
262
+ margin: 0;
263
+ }
264
+
265
+ .HeaderMenu .Button:disabled > .Label > p {
266
+ color: var(--foreground-color-1);
267
+ }
268
+
269
+ .HeaderMenu .Shortcut {
270
+ color: var(--foreground-color-1);
271
+ margin: 0;
272
+ font-size: 0.875rem;
273
+ }
274
+
275
+ .HeaderMenu .Divider {
276
+ width: calc(100% - 0.5rem);
277
+ height: 2px;
278
+ border-radius: var(--border-radius-99);
279
+ background-color: var(--foreground-color-2);
280
+ margin: 0.25rem auto;
281
+ }
@@ -0,0 +1,108 @@
1
+ import { Children, cloneElement, isValidElement, ReactElement, ReactNode, Ref } from "react";
2
+ import { useShortcuts } from "../../hooks/_utils/keyboard";
3
+ import styles from "./Actions.module.css";
4
+ import { useScreenBounds } from "../../hooks/_utils/screen";
5
+ import { ActionsManager } from "../../features/actions/actionsManager";
6
+
7
+ export interface ActionProps {
8
+ actionId?: string;
9
+ label?: string;
10
+ icon?: string | object;
11
+ shortcut?: string[];
12
+ onTrigger?: (event?: Event, triggerParams?: unknown, ...args: unknown[]) => void;
13
+ children?: ReactNode;
14
+ disabled?: boolean;
15
+ }
16
+
17
+ export interface ActionsProps {
18
+ mode?: string;
19
+ className?: string;
20
+ onAnyTrigger?: (event: Event, triggerParams: unknown, ...args: unknown[]) => void;
21
+ children?: ReactNode;
22
+ triggerParams?: unknown;
23
+ avoidTaskbar?: boolean;
24
+ [key: string]: unknown;
25
+ }
26
+
27
+ /**
28
+ * @example
29
+ * <ClickAction
30
+ * label="Reload"
31
+ * shortcut={["Control", "r"]}
32
+ * icon={faArrowsRotate}
33
+ * onTrigger={() => {
34
+ * reloadViewport();
35
+ * }}
36
+ * />
37
+ */
38
+ export function Actions({ children, mode, className, onAnyTrigger, triggerParams, avoidTaskbar = true }: ActionsProps): ReactElement {
39
+ const isListener = (mode === ActionsManager.MODES.shortcutsListener);
40
+
41
+ const { ref, initiated, alignLeft, alignTop } = useScreenBounds({ avoidTaskbar });
42
+
43
+ const options: Record<number, Function> = {};
44
+ const shortcuts: Record<number, string[]> = {};
45
+
46
+ let actionId = 0;
47
+ const iterateOverChildren = (children: ReactNode): ReactNode => {
48
+ const newChildren = Children.map(children, (child) => {
49
+ if (!isValidElement(child))
50
+ return child;
51
+
52
+ actionId++;
53
+
54
+ const { label, shortcut, disabled, onTrigger } = child.props as ActionProps;
55
+
56
+ const onTriggerOverride = (event: Event, ...args: unknown[]) => {
57
+ if (disabled)
58
+ return;
59
+
60
+ onAnyTrigger?.(event, triggerParams, ...args);
61
+ onTrigger?.(event, triggerParams, ...args);
62
+ };
63
+
64
+ // Register shortcut
65
+ if (!disabled && label != null && onTrigger != null) {
66
+ options[actionId] = onTriggerOverride;
67
+
68
+ if (shortcut != null)
69
+ shortcuts[actionId] = shortcut;
70
+ }
71
+
72
+ // Prevent listener from rendering
73
+ if (isListener)
74
+ return iterateOverChildren((child.props as ActionProps).children);
75
+
76
+ return cloneElement(child, {
77
+ ...child.props,
78
+ actionId,
79
+ children: iterateOverChildren((child.props as ActionProps).children),
80
+ onTrigger: onTriggerOverride,
81
+ disabled
82
+ } as ActionProps);
83
+ });
84
+
85
+ return newChildren;
86
+ };
87
+
88
+ useShortcuts({ options, shortcuts, useCategories: false });
89
+
90
+ if (isListener)
91
+ return iterateOverChildren(children) as ReactElement;
92
+
93
+ const classNames = [styles.Actions];
94
+ if (mode != null)
95
+ classNames.push(styles[mode]);
96
+ if (className != null)
97
+ classNames.push(className);
98
+ if (alignLeft)
99
+ classNames.push(styles.AlignLeft);
100
+ if (alignTop)
101
+ classNames.push(styles.AlignTop);
102
+ if (!initiated)
103
+ classNames.push(styles.Uninitiated);
104
+
105
+ return <div ref={ref as Ref<HTMLDivElement>} className={classNames.join(" ")}>
106
+ {iterateOverChildren(children)}
107
+ </div>;
108
+ }
@@ -0,0 +1,30 @@
1
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2
+ import styles from "../Actions.module.css";
3
+ import { memo, MouseEventHandler } from "react";
4
+ import { IconProp } from "@fortawesome/fontawesome-svg-core";
5
+ import { ActionProps } from "../Actions";
6
+ import { formatShortcut } from "../../../features";
7
+ import { ImagePreview } from "../../_utils/directory-list/ImagePreview";
8
+
9
+ interface ClickActionProps extends ActionProps {
10
+ icon?: string | object;
11
+ }
12
+
13
+ export const ClickAction = memo(({ actionId, label, shortcut, disabled, onTrigger, icon }: ClickActionProps) => {
14
+ const classNames = [styles.Button];
15
+ if (disabled)
16
+ classNames.push(styles.Disabled);
17
+
18
+ return (<button key={actionId} className={classNames.join(" ")} tabIndex={0} disabled={disabled} onClick={onTrigger as unknown as MouseEventHandler}>
19
+ <span className={styles.Label}>
20
+ {icon && <div className={styles.Icon}>
21
+ {typeof icon == "string"
22
+ ? <ImagePreview source={icon} className={styles.ImageIcon}/>
23
+ : <FontAwesomeIcon icon={icon as unknown as IconProp}/>
24
+ }
25
+ </div>}
26
+ <p>{label}</p>
27
+ </span>
28
+ {shortcut && <p className={styles.Shortcut}>{formatShortcut(shortcut)}</p>}
29
+ </button>);
30
+ });
@@ -0,0 +1,5 @@
1
+ import styles from "../Actions.module.css";
2
+
3
+ export function Divider() {
4
+ return <div className={styles.Divider}/>;
5
+ }
@@ -0,0 +1,50 @@
1
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2
+ import styles from "../Actions.module.css";
3
+ import { faCaretRight, IconDefinition } from "@fortawesome/free-solid-svg-icons";
4
+ import { ReactElement, useState } from "react";
5
+ import { ActionProps } from "../Actions";
6
+ import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
7
+
8
+ interface DropdownActionProps extends ActionProps {
9
+ showOnHover?: boolean;
10
+ }
11
+
12
+ export function DropdownAction({ label, icon, children, showOnHover = true }: DropdownActionProps): ReactElement {
13
+ const [showContent, setShowContent] = useState(false);
14
+
15
+ const classNames = [styles.Dropdown];
16
+ if (showContent)
17
+ classNames.push(styles.Active);
18
+
19
+ return <OutsideClickListener onOutsideClick={() => {
20
+ if (!showOnHover)
21
+ setShowContent(false);
22
+ }}>
23
+ <div
24
+ key={label}
25
+ className={classNames.join(" ")}
26
+ tabIndex={0}
27
+ onMouseEnter={() => {
28
+ if (showOnHover)
29
+ setShowContent(true);
30
+ }}
31
+ onMouseLeave={() => {
32
+ if (showOnHover)
33
+ setShowContent(false);
34
+ }}
35
+ onClick={() => {
36
+ if (!showOnHover)
37
+ setShowContent(!showContent);
38
+ }}
39
+ >
40
+ <span className={styles.Label}>
41
+ {icon && <div className={styles.Icon}><FontAwesomeIcon icon={icon as IconDefinition}/></div>}
42
+ <p>{label}</p>
43
+ </span>
44
+ <div className={styles.DropdownArrow}><FontAwesomeIcon icon={faCaretRight}/></div>
45
+ <div className={styles.DropdownContent}>
46
+ {children}
47
+ </div>
48
+ </div>
49
+ </OutsideClickListener>;
50
+ }
@@ -0,0 +1,50 @@
1
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2
+ import { formatShortcut } from "../../../features/_utils/string.utils";
3
+ import styles from "../Actions.module.css";
4
+ import { faCircleDot } from "@fortawesome/free-solid-svg-icons";
5
+ import { ReactElement, useState } from "react";
6
+ import { faCircle } from "@fortawesome/free-regular-svg-icons";
7
+ import { ActionProps } from "../Actions";
8
+
9
+ /**
10
+ * @param {object} props
11
+ * @param {string} props.actionId
12
+ * @param {{
13
+ * label: string,
14
+ * shortcut: string[]
15
+ * }[]} props.options
16
+ * @param {number} props.initialIndex
17
+ * @param {Function} props.onTrigger
18
+ */
19
+
20
+ interface RadioActionProps extends ActionProps {
21
+ options: {
22
+ label: string;
23
+ shortcut?: string[]
24
+ }[];
25
+ initialIndex: number;
26
+ }
27
+
28
+ export function RadioAction({ actionId, options, initialIndex, onTrigger }: RadioActionProps): ReactElement {
29
+ const [activeIndex, setActiveIndex] = useState(initialIndex ?? 0);
30
+
31
+ return (<div key={actionId}>
32
+ {options.map(({ label, shortcut }, index) =>
33
+ <button key={label} className={styles.Button} tabIndex={0} onClick={(event) => {
34
+ setActiveIndex(index);
35
+ onTrigger?.(event as unknown as Event, index);
36
+ }}>
37
+ <span className={styles.Label}>
38
+ <div className={styles.Icon}>
39
+ {activeIndex === index
40
+ ? <FontAwesomeIcon icon={faCircleDot}/>
41
+ : <FontAwesomeIcon icon={faCircle}/>
42
+ }
43
+ </div>
44
+ <p>{label}</p>
45
+ </span>
46
+ {shortcut && <p className={styles.Shortcut}>{formatShortcut(shortcut)}</p>}
47
+ </button>
48
+ )}
49
+ </div>);
50
+ }
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from "react";
2
+ import styles from "../Actions.module.css";
3
+
4
+ interface TextDisplayProps {
5
+ children: ReactNode;
6
+ }
7
+
8
+ export function TextDisplay({ children }: TextDisplayProps) {
9
+ return <p className={styles.TextDisplay}>
10
+ {children}
11
+ </p>;
12
+ }
@@ -0,0 +1,31 @@
1
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2
+ import { formatShortcut } from "../../../features/_utils/string.utils";
3
+ import styles from "../Actions.module.css";
4
+ import { ReactElement, useState } from "react";
5
+ import { faSquare } from "@fortawesome/free-regular-svg-icons";
6
+ import { faSquareCheck } from "@fortawesome/free-solid-svg-icons";
7
+ import { ActionProps } from "../Actions";
8
+
9
+ interface ToggleActionProps extends ActionProps {
10
+ initialValue: boolean;
11
+ }
12
+
13
+ export function ToggleAction({ actionId, label, shortcut, initialValue, onTrigger }: ToggleActionProps): ReactElement {
14
+ const [active, setActive] = useState(initialValue ?? false);
15
+
16
+ return (<button key={actionId} className={styles.Button} tabIndex={0} onClick={(event) => {
17
+ onTrigger?.(event as unknown as Event, !active);
18
+ setActive(!active);
19
+ }}>
20
+ <span className={styles.Label}>
21
+ <div className={styles.Icon}>
22
+ {active
23
+ ? <FontAwesomeIcon icon={faSquareCheck}/>
24
+ : <FontAwesomeIcon icon={faSquare}/>
25
+ }
26
+ </div>
27
+ <p>{label}</p>
28
+ </span>
29
+ {shortcut && <p className={styles.Shortcut}>{formatShortcut(shortcut)}</p>}
30
+ </button>);
31
+ }
@@ -0,0 +1,7 @@
1
+ export { Actions } from "./Actions";
2
+ export { ClickAction } from "./actions/ClickAction";
3
+ export { Divider } from "./actions/Divider";
4
+ export { DropdownAction } from "./actions/DropdownAction";
5
+ export { RadioAction } from "./actions/RadioAction";
6
+ export { TextDisplay } from "./actions/TextDisplay";
7
+ export { ToggleAction } from "./actions/ToggleAction";