@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,19 @@
1
+ import { OptionalInterface } from "../../../types/util";
2
+
3
+ export interface TaskbarConfigOptions {
4
+ /**
5
+ * @description Height of the taskbar in CSS pixels
6
+ * @default 3 * 16
7
+ */
8
+ height: number;
9
+ }
10
+
11
+ export class TaskbarConfig {
12
+ height: TaskbarConfigOptions["height"];
13
+
14
+ constructor(options: OptionalInterface<TaskbarConfigOptions> = {}) {
15
+ const { height } = options as TaskbarConfigOptions;
16
+
17
+ this.height = height ?? 3 * 16;
18
+ }
19
+ }
@@ -0,0 +1,24 @@
1
+ import { OptionalInterface } from "../../../types/util";
2
+
3
+ export interface TrackingConfigOptions {
4
+ /**
5
+ * Enable tracking
6
+ * @default true
7
+ */
8
+ enabled: boolean;
9
+
10
+ /** Google Analytics measurement ID */
11
+ GAMeasurementId: string;
12
+ }
13
+
14
+ export class TrackingConfig {
15
+ enabled: TrackingConfigOptions["enabled"];
16
+ GAMeasurementId: TrackingConfigOptions["GAMeasurementId"];
17
+
18
+ constructor(options: OptionalInterface<TrackingConfigOptions> = {}) {
19
+ const { enabled, GAMeasurementId } = options as TrackingConfigOptions;
20
+
21
+ this.enabled = enabled ?? true;
22
+ this.GAMeasurementId = GAMeasurementId ?? "G-ZFQRR9DP3C";
23
+ }
24
+ }
@@ -0,0 +1,39 @@
1
+ import { OptionalInterface } from "../../../types/util";
2
+
3
+ export interface VirtualDriveConfigOptions {
4
+ fileIcon: string;
5
+ infoFileIcon: string;
6
+ textFileIcon: string;
7
+ codeFileIcon: string;
8
+
9
+ folderIcon: string;
10
+ imagesFolderIcon: string;
11
+ textFolderIcon: string;
12
+ folderLinkIcon: string;
13
+ }
14
+
15
+ export class VirtualDriveConfig {
16
+ fileIcon: VirtualDriveConfigOptions["fileIcon"];
17
+ infoFileIcon: VirtualDriveConfigOptions["infoFileIcon"];
18
+ textFileIcon: VirtualDriveConfigOptions["textFileIcon"];
19
+ codeFileIcon: VirtualDriveConfigOptions["codeFileIcon"];
20
+
21
+ folderIcon: VirtualDriveConfigOptions["folderIcon"];
22
+ imagesFolderIcon: VirtualDriveConfigOptions["imagesFolderIcon"];
23
+ textFolderIcon: VirtualDriveConfigOptions["textFolderIcon"];
24
+ folderLinkIcon: VirtualDriveConfigOptions["folderLinkIcon"];
25
+
26
+ constructor(options: OptionalInterface<VirtualDriveConfigOptions> = {}) {
27
+ const { fileIcon, infoFileIcon, textFileIcon, codeFileIcon, folderIcon, imagesFolderIcon, textFolderIcon, folderLinkIcon } = options as VirtualDriveConfigOptions;
28
+
29
+ this.fileIcon = fileIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/file.svg";
30
+ this.infoFileIcon = infoFileIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/file-info.svg";
31
+ this.textFileIcon = textFileIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/file-text.svg";
32
+ this.codeFileIcon = codeFileIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/file-code.svg";
33
+
34
+ this.folderIcon = folderIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/folder.svg";
35
+ this.imagesFolderIcon = imagesFolderIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/folder-images.svg";
36
+ this.textFolderIcon = textFolderIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/folder-text.svg";
37
+ this.folderLinkIcon = folderLinkIcon ?? "https://os.prozilla.dev/assets/apps/file-explorer/icons/folder-link.svg";
38
+ }
39
+ }
@@ -0,0 +1,34 @@
1
+ import { OptionalInterface } from "../../../types/util";
2
+ import { Vector2 } from "../../math/vector2";
3
+
4
+ export interface WindowsConfigOptions {
5
+ /**
6
+ * @default 32
7
+ */
8
+ screenMargin: number;
9
+
10
+ /**
11
+ * @default "-"
12
+ */
13
+ titleSeparator: string;
14
+
15
+ /**
16
+ * @description If the user's screen is smaller than these values, windows will always be maximized
17
+ * @default new Vector2(350, 350)
18
+ */
19
+ minScreenSize: Vector2;
20
+ }
21
+
22
+ export class WindowsConfig {
23
+ screenMargin: WindowsConfigOptions["screenMargin"];
24
+ titleSeparator: WindowsConfigOptions["titleSeparator"];
25
+ minScreenSize: WindowsConfigOptions["minScreenSize"];
26
+
27
+ constructor(options: OptionalInterface<WindowsConfigOptions> = {}) {
28
+ const { screenMargin, titleSeparator, minScreenSize } = options as WindowsConfigOptions;
29
+
30
+ this.screenMargin = screenMargin ?? 32;
31
+ this.titleSeparator = titleSeparator ?? "-";
32
+ this.minScreenSize = minScreenSize ?? new Vector2(350, 350);
33
+ }
34
+ }
@@ -0,0 +1,68 @@
1
+ import { formatRelativeTime } from "../_utils";
2
+ import { VirtualDriveConfig } from "./configs";
3
+ import { AppsConfig } from "./configs/appsConfig";
4
+ import { DesktopConfig } from "./configs/desktopConfig";
5
+ import { MiscConfig } from "./configs/miscConfig";
6
+ import { ModalsConfig } from "./configs/modalsConfig";
7
+ import { TaskbarConfig } from "./configs/taskbarConfig";
8
+ import { TrackingConfig } from "./configs/trackingConfig";
9
+ import { WindowsConfig } from "./configs/windowsConfig";
10
+
11
+ export interface SystemManagerParams {
12
+ systemName: SystemManager["systemName"] | null;
13
+ tagLine: SystemManager["tagLine"] | null;
14
+ desktopConfig: DesktopConfig;
15
+ appsConfig: AppsConfig;
16
+ miscConfig: MiscConfig;
17
+ modalsConfig: ModalsConfig;
18
+ taskbarConfig: TaskbarConfig;
19
+ trackingConfig: TrackingConfig;
20
+ windowsConfig: WindowsConfig;
21
+ virtualDriveConfig: VirtualDriveConfig;
22
+ };
23
+
24
+ export class SystemManager {
25
+ systemName: string;
26
+ tagLine: string;
27
+ #startDate: Date;
28
+
29
+ appsConfig: AppsConfig;
30
+ desktopConfig: DesktopConfig;
31
+ miscConfig: MiscConfig;
32
+ modalsConfig: ModalsConfig;
33
+ taskbarConfig: TaskbarConfig;
34
+ trackingConfig: TrackingConfig;
35
+ windowsConfig: WindowsConfig;
36
+ virtualDriveConfig: VirtualDriveConfig;
37
+
38
+ constructor({
39
+ systemName,
40
+ tagLine,
41
+ desktopConfig,
42
+ appsConfig,
43
+ miscConfig,
44
+ modalsConfig,
45
+ taskbarConfig,
46
+ trackingConfig,
47
+ windowsConfig,
48
+ virtualDriveConfig
49
+ }: SystemManagerParams) {
50
+ this.systemName = systemName ?? "ProzillaOS";
51
+ this.tagLine = tagLine ?? "Web-based Operating System";
52
+
53
+ this.desktopConfig = desktopConfig;
54
+ this.appsConfig = appsConfig;
55
+ this.miscConfig = miscConfig;
56
+ this.modalsConfig = modalsConfig;
57
+ this.taskbarConfig = taskbarConfig;
58
+ this.trackingConfig = trackingConfig;
59
+ this.windowsConfig = windowsConfig;
60
+ this.virtualDriveConfig = virtualDriveConfig;
61
+
62
+ this.#startDate = new Date();
63
+ }
64
+
65
+ getUptime(precision = 2) {
66
+ return formatRelativeTime(this.#startDate, precision, false);
67
+ }
68
+ }
@@ -0,0 +1,40 @@
1
+ import ReactGA from "react-ga4";
2
+ import { UaEventOptions } from "react-ga4/types/ga4";
3
+ import { SystemManager } from "../system/systemManager";
4
+
5
+ export class TrackingManager {
6
+ #systemManager: SystemManager;
7
+
8
+ measurementId?: string | null;
9
+
10
+ constructor(systemManager: SystemManager) {
11
+ this.#systemManager = systemManager;
12
+ }
13
+
14
+ init(): this {
15
+ const { trackingConfig } = this.#systemManager;
16
+ this.measurementId = trackingConfig.enabled ? trackingConfig.GAMeasurementId : null;
17
+
18
+ try {
19
+ if (this.measurementId != null)
20
+ ReactGA.initialize(this.measurementId);
21
+ } catch (error) {
22
+ console.error(error);
23
+ }
24
+
25
+ return this;
26
+ }
27
+
28
+ event(options: UaEventOptions | string) {
29
+ console.info(options);
30
+
31
+ if (this.measurementId == null)
32
+ return;
33
+
34
+ try {
35
+ ReactGA.event(options);
36
+ } catch (error) {
37
+ console.error(error);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ export { VirtualFile } from "./virtualFile";
2
+ export { VirtualFileLink } from "./virtualFileLink";
@@ -0,0 +1,197 @@
1
+ import { IMAGE_EXTENSIONS } from "../../../constants/virtualDrive.const";
2
+ import { WindowsManager } from "../../windows/windowsManager";
3
+ import { VirtualBase, VirtualBaseJson } from "../virtualBase";
4
+
5
+ export interface VirtualFileJson extends VirtualBaseJson {
6
+ ext?: string;
7
+ cnt?: string;
8
+ src?: string;
9
+ }
10
+
11
+ type OptionalStringProperty = string | null | undefined;
12
+
13
+ /**
14
+ * A virtual file that can be stored inside a folder
15
+ */
16
+ export class VirtualFile extends VirtualBase {
17
+ extension: OptionalStringProperty;
18
+ source: OptionalStringProperty;
19
+ content: OptionalStringProperty;
20
+
21
+ static NON_TEXT_EXTENSIONS = [
22
+ "png"
23
+ ];
24
+
25
+ static EVENT_NAMES = {
26
+ CONTENT_CHANGE: "contentchange"
27
+ };
28
+
29
+ constructor(name: string, extension?: string | undefined) {
30
+ super(name);
31
+ this.extension = extension;
32
+ }
33
+
34
+ setAlias(alias: string): this {
35
+ return super.setAlias(alias);
36
+ }
37
+
38
+ /**
39
+ * Sets the source of this file and removes the content
40
+ */
41
+ setSource(source: string): this {
42
+ if (this.source === source || !this.canBeEdited)
43
+ return this;
44
+
45
+ this.source = source;
46
+ this.content = null;
47
+
48
+ this.emit(VirtualFile.EVENT_NAMES.CONTENT_CHANGE, this);
49
+
50
+ this.confirmChanges();
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Sets the content of this file and removes the source
56
+ */
57
+ setContent(content: string): this {
58
+ if (this.content === content || !this.canBeEdited)
59
+ return this;
60
+
61
+ this.content = content;
62
+ this.source = null;
63
+
64
+ this.emit(VirtualFile.EVENT_NAMES.CONTENT_CHANGE, this);
65
+
66
+ this.confirmChanges();
67
+ return this;
68
+ }
69
+
70
+ get id() {
71
+ if (this.extension == null || this.extension.trim() === "")
72
+ return this.name;
73
+
74
+ return `${this.name}.${this.extension}`;
75
+ }
76
+
77
+ static splitId(id: string): {
78
+ name: string;
79
+ extension: OptionalStringProperty;
80
+ } {
81
+ if (!id.includes("."))
82
+ return { name: id, extension: "" };
83
+
84
+ const sections = id.split(".");
85
+ const extension = sections.pop();
86
+ const name = sections.join(".");
87
+ return { name, extension };
88
+ }
89
+
90
+ /**
91
+ * Opens this file in an app associated with its extension
92
+ */
93
+ open(windowsManager: WindowsManager): object | null {
94
+ return windowsManager.openFile(this);
95
+ }
96
+
97
+ async read(): Promise<OptionalStringProperty | undefined> {
98
+ if (this.content != null) return this.content;
99
+ if (this.source == null) return null;
100
+
101
+ const isText = this.extension == null || !VirtualFile.NON_TEXT_EXTENSIONS.includes(this.extension);
102
+
103
+ if (!isText) return this.source;
104
+
105
+ return await fetch(this.source).then((response) =>
106
+ response.text()
107
+ ).catch((error) => {
108
+ console.error(`Error while reading file with ID: ${this.id}\n`, error);
109
+ return null;
110
+ }) as string;
111
+ }
112
+
113
+ isFile(): boolean {
114
+ return true;
115
+ }
116
+
117
+ getIconUrl(): string {
118
+ if (this.iconUrl != null)
119
+ return this.iconUrl;
120
+
121
+ let iconUrl = null;
122
+
123
+ if (this.source != null && this.extension != null && IMAGE_EXTENSIONS.includes(this.extension))
124
+ return this.source;
125
+
126
+ const { virtualDriveConfig } = this.getRoot().systemManager;
127
+
128
+ switch (this.extension) {
129
+ case "txt":
130
+ case "md":
131
+ iconUrl = virtualDriveConfig.textFileIcon;
132
+ break;
133
+ case "xml":
134
+ case "js":
135
+ case "json":
136
+ case "jsx":
137
+ case "ts":
138
+ case "tsx":
139
+ case "css":
140
+ case "html":
141
+ case "yml":
142
+ iconUrl = virtualDriveConfig.codeFileIcon;
143
+ break;
144
+ default:
145
+ iconUrl = virtualDriveConfig.fileIcon;
146
+ break;
147
+ }
148
+
149
+ return iconUrl;
150
+ }
151
+
152
+ getType(): string {
153
+ let type = "";
154
+
155
+ if (this.extension == null) return "Unknown file";
156
+
157
+ switch (this.extension) {
158
+ case "png":
159
+ type = "PNG Image";
160
+ break;
161
+ case "txt":
162
+ type = "Text";
163
+ break;
164
+ case "md":
165
+ type = "Markdown source";
166
+ break;
167
+ case "xml":
168
+ type = "XML source";
169
+ break;
170
+ }
171
+
172
+ return `${type} file (.${this.extension.toLowerCase()})`.trim();
173
+ }
174
+
175
+ toJSON(): VirtualFileJson | null {
176
+ // Don't return file if it can't or hasn't been edited
177
+ if (!this.canBeEdited || (this.editedByUser == null || !this.editedByUser))
178
+ return null;
179
+
180
+ const object = super.toJSON() as VirtualFileJson;
181
+
182
+ if (object == null)
183
+ return null;
184
+
185
+ if (this.extension != null) {
186
+ object.ext = this.extension;
187
+ }
188
+
189
+ if (this.content != null) {
190
+ object.cnt = this.content;
191
+ } else if (this.source != null) {
192
+ object.src = this.source;
193
+ }
194
+
195
+ return object;
196
+ }
197
+ }
@@ -0,0 +1,111 @@
1
+ import { VirtualFile } from ".";
2
+ import { VirtualFileJson } from "./virtualFile";
3
+
4
+ export interface VirtualFileLinkJson extends VirtualFileJson {
5
+ lnk: string;
6
+ }
7
+
8
+ /**
9
+ * A link that points to a virtual file
10
+ */
11
+ export class VirtualFileLink extends VirtualFile {
12
+ linkedPath?: string;
13
+
14
+ constructor(name: string, linkedFile?: VirtualFile) {
15
+ super(name);
16
+ this.linkedFile = linkedFile;
17
+ }
18
+
19
+ setLinkedFile(file: VirtualFile): VirtualFileLink {
20
+ this.linkedFile = file;
21
+
22
+ if (file) {
23
+ this.linkedPath = file.path;
24
+ this.extension = file.extension;
25
+ this.content = file.content;
26
+ this.source = file.source;
27
+ }
28
+
29
+ return this;
30
+ }
31
+
32
+ setLinkedPath(path: string): VirtualFileLink {
33
+ if (this.linkedFile && this.linkedFile.path === path)
34
+ return this;
35
+
36
+ const target = this.parent?.navigate(path);
37
+
38
+ if (target instanceof VirtualFile) {
39
+ this.setLinkedFile(target);
40
+ } else {
41
+ this.linkedFile = null;
42
+ }
43
+
44
+ return this;
45
+ }
46
+
47
+ isValid(): boolean {
48
+ if (!this.linkedPath)
49
+ return false;
50
+
51
+ this.setLinkedPath(this.linkedPath);
52
+
53
+ return (this.linkedFile != null);
54
+ }
55
+
56
+ toJSON(): VirtualFileLinkJson | null {
57
+ if (this.linkedPath == null)
58
+ return null;
59
+
60
+ const object = {
61
+ nam: this.name,
62
+ lnk: this.linkedPath
63
+ };
64
+
65
+ return object;
66
+ }
67
+
68
+ // Point certain methods to linked file
69
+
70
+ setAlias(...args: Parameters<VirtualFile["setAlias"]>) {
71
+ if (this.isValid())
72
+ this.linkedFile?.setAlias(...args);
73
+ return this;
74
+ }
75
+
76
+ setSource(...args: Parameters<VirtualFile["setSource"]>) {
77
+ if (this.isValid())
78
+ this.linkedFile?.setSource(...args);
79
+ return this;
80
+ }
81
+
82
+ setContent(...args: Parameters<VirtualFile["setContent"]>) {
83
+ if (this.isValid())
84
+ this.linkedFile?.setContent(...args);
85
+ return this;
86
+ }
87
+
88
+ get id() {
89
+ return this.isValid() ? this.linkedFile?.id ?? "" : "";
90
+ }
91
+
92
+ open(...args: Parameters<VirtualFile["open"]>): ReturnType<VirtualFile["open"]> {
93
+ if (this.isValid()) return this.linkedFile?.open(...args) as ReturnType<VirtualFile["open"]>;
94
+ return null;
95
+ }
96
+
97
+ async read(...args: Parameters<VirtualFile["read"]>): Promise<string | null | undefined> {
98
+ if (this.isValid()) return await this.linkedFile?.read(...args);
99
+ }
100
+
101
+ getIconUrl(...args: Parameters<VirtualFile["getIconUrl"]>): ReturnType<VirtualFile["getIconUrl"]> {
102
+ const { virtualDriveConfig } = this.getRoot().systemManager;
103
+ const defaultIconUrl = virtualDriveConfig.fileIcon;
104
+
105
+ if (this.isValid()) {
106
+ return this.iconUrl ?? this.linkedFile?.getIconUrl(...args) ?? defaultIconUrl;
107
+ } else {
108
+ return defaultIconUrl;
109
+ }
110
+ }
111
+ }
@@ -0,0 +1,2 @@
1
+ export { VirtualFolder } from "./virtualFolder";
2
+ export { VirtualFolderLink } from "./virtualFolderLink";