Skip to content

Commit

Permalink
shared: Moved utils from core package to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Prozilla committed Oct 3, 2024
1 parent d3fd8ea commit 7a69a2b
Show file tree
Hide file tree
Showing 68 changed files with 6,006 additions and 207 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"homepage": "https://os.prozilla.dev/",
"type": "module",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/file-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions packages/apps/logic-sim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand All @@ -22,6 +23,7 @@
"license": "MIT",
"dependencies": {
"@prozilla-os/core": "workspace:*",
"@prozilla-os/shared": "workspace:*",
"react": "^18.3.1"
},
"devDependencies": {
Expand All @@ -31,8 +33,7 @@
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-lib-inject-css": "^2.1.1",
"@prozilla-os/shared": "workspace:*"
"vite-plugin-lib-inject-css": "^2.1.1"
},
"files": [
"dist"
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/logic-sim/src/core/circuit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { clamp, Vector2 } from "@prozilla-os/core";
import { Vector2 } from "@prozilla-os/core";
import { Chip, ChipJson } from "./chips/chip";
import { ControlledPin } from "./pins/controlledPin";
import { InputHandler } from "./inputHandler";
import { Wire, WireJson } from "./wires/wire";
import { BACKGROUND, COLORS, CONTROLLER, CURSORS, ENABLE_COLOR_CACHING, FONT } from "../constants/logicSim.const";
import { clamp } from "@prozilla-os/shared";

export interface CircuitJson extends ChipJson {
wires: WireJson[];
Expand Down
1 change: 1 addition & 0 deletions packages/apps/media-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand All @@ -26,10 +27,10 @@
"@fortawesome/react-fontawesome": "^0.2.2",
"@prozilla-os/core": "workspace:*",
"@prozilla-os/file-explorer": "workspace:*",
"@prozilla-os/shared": "^1.1.1",
"react": "^18.3.1"
},
"devDependencies": {
"@prozilla-os/shared": "workspace:*",
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"@vitejs/plugin-react-swc": "^3.7.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/settings/src/components/tabs/AppOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import styles from "../Settings.module.css";
import { faEllipsisVertical, faThumbTack } from "@fortawesome/free-solid-svg-icons";
import { MouseEventHandler } from "react";
import { Actions, App, ClickAction, ImagePreview, removeFromArray, SettingsManager, useContextMenu, useSettingsManager, useWindowsManager } from "@prozilla-os/core";
import { Actions, App, ClickAction, ImagePreview, SettingsManager, useContextMenu, useSettingsManager, useWindowsManager } from "@prozilla-os/core";
import { removeFromArray } from "@prozilla-os/shared";

interface AppOptionProps {
app: App;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { round } from "@prozilla-os/shared";
import styles from "../Settings.module.css";
import { Button, ProgressBar, round, StorageManager, useVirtualRoot, utilStyles } from "@prozilla-os/core";
import { Button, ProgressBar, StorageManager, useVirtualRoot, utilStyles } from "@prozilla-os/core";

export function StorageTab() {
const virtualRoot = useVirtualRoot();
Expand Down
5 changes: 3 additions & 2 deletions packages/apps/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand All @@ -22,6 +23,7 @@
"license": "MIT",
"dependencies": {
"@prozilla-os/core": "workspace:*",
"@prozilla-os/shared": "workspace:*",
"anser": "^2.1.1",
"escape-carriage": "^1.3.1",
"react": "^18.3.1"
Expand All @@ -33,8 +35,7 @@
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-lib-inject-css": "^2.1.1",
"@prozilla-os/shared": "workspace:*"
"vite-plugin-lib-inject-css": "^2.1.1"
},
"files": [
"dist"
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/terminal/src/components/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { MouseEventHandler, MutableRefObject, useEffect, useRef, useState } from
import styles from "./Terminal.module.css";
import { OutputLine } from "./OutputLine";
import { InputLine } from "./InputLine";
import { ANSI, App, clamp, removeFromArray, SettingsManager, useSettingsManager, useSystemManager, useVirtualRoot, VirtualFolder, WindowProps } from "@prozilla-os/core";
import { App, SettingsManager, useSettingsManager, useSystemManager, useVirtualRoot, VirtualFolder, WindowProps } from "@prozilla-os/core";
import { HOSTNAME, USERNAME, WELCOME_MESSAGE } from "../constants/terminal.const";
import { Stream } from "../core/stream";
import { CommandResponse } from "../core/command";
import { formatError } from "../core/_utils/terminal.utils";
import { CommandsManager } from "../core/commands";
import { ANSI, clamp, removeFromArray } from "@prozilla-os/shared";

export interface TerminalProps extends WindowProps {
path?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/constants/terminal.const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";

export const USERNAME = "user";
export const HOSTNAME = "prozilla-os";
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/_utils/terminal.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";

export function formatError(commandName: string, error: string): string {
return `${ANSI.fg.red}${commandName}: ${error}${ANSI.reset}`;
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/terminal/src/core/commands/cmatrix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ANSI, randomFromArray, randomRange, removeFromArray, Vector2 } from "@prozilla-os/core";
import { Vector2 } from "@prozilla-os/core";
import { ANSI, randomFromArray, randomRange, removeFromArray } from "@prozilla-os/shared";
import { Command } from "../command";
import { Stream } from "../stream";

Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/commands/fortune.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomFromArray } from "@prozilla-os/core";
import { randomFromArray } from "@prozilla-os/shared";
import { Command } from "../command";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";
import { formatError } from "../_utils/terminal.utils";
import { Command } from "../command";
import { CommandsManager } from "../commands";
Expand Down
18 changes: 18 additions & 0 deletions packages/apps/terminal/src/core/commands/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// import { Command, CommandResponse } from "../command";

// const historyCommand = new Command()
// .setRequireArgs(true)
// .setManual({
// purpose: "Command Line history",
// usage: "history",
// })
// .setRequireArgs(true)
// .setExecute(function(this: Command, args, { history }) {
// if (args == null || args.length == 0)
// return;

// const output = eval(args[0]) as CommandResponse ?? { blank: true };
// return output;
// });

// export { historyCommand as eval };
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/commands/lolcat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";
import { removeAnsi } from "../_utils/terminal.utils";
import { Command, ExecuteParams } from "../command";

Expand Down
3 changes: 2 additions & 1 deletion packages/apps/terminal/src/core/commands/ls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ANSI, VirtualFolder } from "@prozilla-os/core";
import { VirtualFolder } from "@prozilla-os/core";
import { formatError } from "../_utils/terminal.utils";
import { Command, ExecuteParams } from "../command";
import { ANSI } from "@prozilla-os/shared";

export const ls = new Command()
.setManual({
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/commands/man.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";
import { formatError } from "../_utils/terminal.utils";
import { Command, ExecuteParams } from "../command";
import { CommandsManager } from "../commands";
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/terminal/src/core/commands/neofetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ANSI, SettingsManager, THEMES } from "@prozilla-os/core";
import { SettingsManager, THEMES } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";
import { ANSI_ASCII_LOGO, ANSI_LOGO_COLOR } from "../../constants/terminal.const";
import { Command, ExecuteParams } from "../command";

Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/commands/whatis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ANSI } from "@prozilla-os/core";
import { ANSI } from "@prozilla-os/shared";
import { formatError } from "../_utils/terminal.utils";
import { Command } from "../command";
import { CommandsManager } from "../commands";
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/terminal/src/core/stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from "@prozilla-os/core";
import { EventEmitter } from "@prozilla-os/shared";

const StreamEvents = {
new: "new",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/text-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"email": "business@prozilla.dev",
"url": "https://prozilla.dev/"
},
"funding": "https://ko-fi.com/prozilla",
"type": "module",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand All @@ -25,6 +26,7 @@
"@fortawesome/free-regular-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@prozilla-os/shared": "workspace:*",
"@prozilla-os/skins": "workspace:*",
"react": "^18.3.1",
"react-draggable": "^4.4.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import styles from "./DropdownButton.module.css";
import { OutsideClickListener } from "../../../hooks/_utils/outsideClick";
import { formatShortcut } from "../../../features/_utils/string.utils";
import { formatShortcut } from "../../../features/_utils/keyboard.utils";

export function DropdownButton({ label, options, shortcuts }: { label: string; options: { [s: string]: Function; }; shortcuts: { [s: string]: string[]; }; }) {
const [open, setOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CSSProperties } from "react";
import styles from "./ProgressBar.module.css";
import { clamp } from "../../../features/_utils/math.utils";
import { useClassNames } from "../../../hooks";
import { clamp } from "@prozilla-os/shared";

interface ProgressBarProps {
fillPercentage: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { formatShortcut } from "../../../features/_utils/string.utils";
import { formatShortcut } from "../../../features/_utils/keyboard.utils";
import styles from "../Actions.module.css";
import { faCircleDot } from "@fortawesome/free-solid-svg-icons";
import { ReactElement, useState } from "react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { formatShortcut } from "../../../features/_utils/string.utils";
import { formatShortcut } from "../../../features/_utils/keyboard.utils";
import styles from "../Actions.module.css";
import { ReactElement, useState } from "react";
import { faSquare } from "@fortawesome/free-regular-svg-icons";
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/components/desktop/Desktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { RadioAction } from "../actions/actions/RadioAction";
import { Divider } from "../actions/actions/Divider";
import { Share } from "../modals/share/Share";
import { ModalProps } from "../modals/ModalView";
import { SettingsManager, reloadViewport, ModalsManager, Vector2, isValidInteger, AppsConfig } from "../../features";
import { SettingsManager, reloadViewport, ModalsManager, Vector2, AppsConfig } from "../../features";
import { VirtualFile } from "../../features/virtual-drive/file";
import { VirtualFolder, VirtualFolderLink } from "../../features/virtual-drive/folder";
import { useSettingsManager, useWindowsManager, useVirtualRoot, useWindowedModal, useContextMenu, useSystemManager } from "../../hooks";
import { DirectoryList } from "../_utils";
import { FileEventHandler, FolderEventHandler } from "../_utils/directory-list/DirectoryList";
import { useClassNames } from "../../hooks";
import { isValidInteger } from "@prozilla-os/shared";

export const Desktop = memo(() => {
const { desktopConfig, skin, appsConfig } = useSystemManager();
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/components/windows/WindowsView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FC, memo, useEffect, useState } from "react";
import { WindowProps, WindowView } from "./WindowView";
import { setViewportTitle, setViewportIcon, getViewportParams, SettingsManager, removeDuplicatesFromArray } from "../../features";
import { setViewportTitle, setViewportIcon, getViewportParams, SettingsManager } from "../../features";
import { WindowOptions } from "../../features/windows/windowsManager";
import { useClassNames, useSettingsManager, useSystemManager, useWindowsManager } from "../../hooks";
import { useWindows } from "../../hooks/windows/windowsContext";
import { removeDuplicatesFromArray } from "@prozilla-os/shared";

export const WindowsView: FC = memo(() => {
const { systemName, tagLine } = useSystemManager();
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { CODE_EXTENSIONS, IMAGE_EXTENSIONS } from "./virtualDrive.const";
export { ANSI } from "./utils.const";
export { THEMES } from "./themes.const";
7 changes: 1 addition & 6 deletions packages/core/src/features/_utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export * from "./array.utils";
export * from "./browser.utils";
export * from "./date.utils";
export * from "./event.utils";
export * from "./math.utils";
export * from "./number.utils";
export * from "./string.utils";
export * from "./keyboard.utils";
export * from "./time.utils";
2 changes: 1 addition & 1 deletion packages/core/src/features/_utils/time.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatRelativeTime } from "./date.utils";
import { formatRelativeTime } from "@prozilla-os/shared";

export class TimeManager {
static startDate: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/system/systemManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatRelativeTime } from "../_utils";
import { Skin } from "@prozilla-os/skins";
import { VirtualDriveConfig } from "./configs";
import { AppsConfig } from "./configs/appsConfig";
Expand All @@ -8,6 +7,7 @@ import { ModalsConfig } from "./configs/modalsConfig";
import { TaskbarConfig } from "./configs/taskbarConfig";
import { TrackingConfig } from "./configs/trackingConfig";
import { WindowsConfig } from "./configs/windowsConfig";
import { formatRelativeTime } from "@prozilla-os/shared";

export interface SystemManagerParams {
systemName: SystemManager["systemName"] | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { removeFromArray } from "../../_utils/array.utils";
import { WindowsManager } from "../../windows/windowsManager";
import { VirtualFileJson } from "../file/virtualFile";
import { VirtualBase, VirtualBaseJson } from "../virtualBase";
import { VirtualFolderLink } from ".";
import { VirtualFile, VirtualFileLink } from "../file";
import { AppsConfig } from "../../system/configs";
import { removeFromArray } from "@prozilla-os/shared";

export interface VirtualFolderJson extends VirtualBaseJson {
fls?: VirtualFileJson[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/virtual-drive/virtualBase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter, EventNamesMap } from "../_utils/event.utils";
import { VirtualRoot } from "./root/virtualRoot";
import { VirtualFile } from "./file";
import { VirtualFolder } from "./folder";
import { EventEmitter, EventNamesMap } from "@prozilla-os/shared";

export interface VirtualBaseJson {
nam: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/windows/windowsManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomRange } from "../_utils/math.utils";
import { randomRange } from "@prozilla-os/shared";
import { App } from "../";
import { Vector2 } from "../math/vector2";
import { SystemManager } from "../system/systemManager";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/features/z-index/zIndexManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from "../_utils/event.utils";
import { EventEmitter } from "@prozilla-os/shared";
import { ZIndexGroup } from "./zIndexGroup";

const ZIndexManagerEvents = {
Expand Down
Loading

0 comments on commit 7a69a2b

Please sign in to comment.